1596c5ea4SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */ 2596c5ea4SNishad Kamdar /* 3b3a33077SSimon Horman * Renesas Clock Pulse Generator / Module Standby and Software Reset 4b3a33077SSimon Horman * 5b3a33077SSimon Horman * Copyright (C) 2015 Glider bvba 6b3a33077SSimon Horman */ 7b3a33077SSimon Horman 8b3a33077SSimon Horman #ifndef __CLK_RENESAS_CPG_MSSR_H__ 9b3a33077SSimon Horman #define __CLK_RENESAS_CPG_MSSR_H__ 10b3a33077SSimon Horman 11b3a33077SSimon Horman /* 12b3a33077SSimon Horman * Definitions of CPG Core Clocks 13b3a33077SSimon Horman * 14b3a33077SSimon Horman * These include: 15b3a33077SSimon Horman * - Clock outputs exported to DT 16b3a33077SSimon Horman * - External input clocks 17b3a33077SSimon Horman * - Internal CPG clocks 18b3a33077SSimon Horman */ 19b3a33077SSimon Horman 20b3a33077SSimon Horman struct cpg_core_clk { 21b3a33077SSimon Horman /* Common */ 22b3a33077SSimon Horman const char *name; 23b3a33077SSimon Horman unsigned int id; 24b3a33077SSimon Horman unsigned int type; 25b3a33077SSimon Horman /* Depending on type */ 26b3a33077SSimon Horman unsigned int parent; /* Core Clocks only */ 27b3a33077SSimon Horman unsigned int div; 28b3a33077SSimon Horman unsigned int mult; 29b3a33077SSimon Horman unsigned int offset; 30b3a33077SSimon Horman }; 31b3a33077SSimon Horman 32b3a33077SSimon Horman enum clk_types { 33b3a33077SSimon Horman /* Generic */ 34b3a33077SSimon Horman CLK_TYPE_IN, /* External Clock Input */ 35b3a33077SSimon Horman CLK_TYPE_FF, /* Fixed Factor Clock */ 36b3a33077SSimon Horman CLK_TYPE_DIV6P1, /* DIV6 Clock with 1 parent clock */ 375d3927f6SWolfram Sang CLK_TYPE_DIV6_RO, /* DIV6 Clock read only with extra divisor */ 380d2602d7SGeert Uytterhoeven CLK_TYPE_FR, /* Fixed Rate Clock */ 39b3a33077SSimon Horman 40b3a33077SSimon Horman /* Custom definitions start here */ 41b3a33077SSimon Horman CLK_TYPE_CUSTOM, 42b3a33077SSimon Horman }; 43b3a33077SSimon Horman 44b3a33077SSimon Horman #define DEF_TYPE(_name, _id, _type...) \ 45b3a33077SSimon Horman { .name = _name, .id = _id, .type = _type } 46b3a33077SSimon Horman #define DEF_BASE(_name, _id, _type, _parent...) \ 47b3a33077SSimon Horman DEF_TYPE(_name, _id, _type, .parent = _parent) 48b3a33077SSimon Horman 49b3a33077SSimon Horman #define DEF_INPUT(_name, _id) \ 50b3a33077SSimon Horman DEF_TYPE(_name, _id, CLK_TYPE_IN) 51b3a33077SSimon Horman #define DEF_FIXED(_name, _id, _parent, _div, _mult) \ 52b3a33077SSimon Horman DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult) 53b3a33077SSimon Horman #define DEF_DIV6P1(_name, _id, _parent, _offset) \ 54b3a33077SSimon Horman DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset) 555d3927f6SWolfram Sang #define DEF_DIV6_RO(_name, _id, _parent, _offset, _div) \ 565d3927f6SWolfram Sang DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1) 570d2602d7SGeert Uytterhoeven #define DEF_RATE(_name, _id, _rate) \ 580d2602d7SGeert Uytterhoeven DEF_TYPE(_name, _id, CLK_TYPE_FR, .mult = _rate) 59b3a33077SSimon Horman 60b3a33077SSimon Horman /* 61b3a33077SSimon Horman * Definitions of Module Clocks 62b3a33077SSimon Horman */ 63b3a33077SSimon Horman 64b3a33077SSimon Horman struct mssr_mod_clk { 65b3a33077SSimon Horman const char *name; 66b3a33077SSimon Horman unsigned int id; 67b3a33077SSimon Horman unsigned int parent; /* Add MOD_CLK_BASE for Module Clocks */ 68b3a33077SSimon Horman }; 69b3a33077SSimon Horman 70b3a33077SSimon Horman /* Convert from sparse base-100 to packed index space */ 71b3a33077SSimon Horman #define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32)) 72b3a33077SSimon Horman 73b3a33077SSimon Horman #define MOD_CLK_ID(x) (MOD_CLK_BASE + MOD_CLK_PACK(x)) 74b3a33077SSimon Horman 75b3a33077SSimon Horman #define DEF_MOD(_name, _mod, _parent...) \ 76b3a33077SSimon Horman { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent } 77b3a33077SSimon Horman 78fde35c9cSChris Brandt /* Convert from sparse base-10 to packed index space */ 79fde35c9cSChris Brandt #define MOD_CLK_PACK_10(x) ((x / 10) * 32 + (x % 10)) 80fde35c9cSChris Brandt 81fde35c9cSChris Brandt #define MOD_CLK_ID_10(x) (MOD_CLK_BASE + MOD_CLK_PACK_10(x)) 82fde35c9cSChris Brandt 83fde35c9cSChris Brandt #define DEF_MOD_STB(_name, _mod, _parent...) \ 84fde35c9cSChris Brandt { .name = _name, .id = MOD_CLK_ID_10(_mod), .parent = _parent } 85b3a33077SSimon Horman 86b3a33077SSimon Horman struct device_node; 87b3a33077SSimon Horman 88ffbf9cf3SYoshihiro Shimoda enum clk_reg_layout { 89ffbf9cf3SYoshihiro Shimoda CLK_REG_LAYOUT_RCAR_GEN2_AND_GEN3 = 0, 90ffbf9cf3SYoshihiro Shimoda CLK_REG_LAYOUT_RZ_A, 91470e3f0dSYoshihiro Shimoda CLK_REG_LAYOUT_RCAR_GEN4, 92ffbf9cf3SYoshihiro Shimoda }; 93ffbf9cf3SYoshihiro Shimoda 94b3a33077SSimon Horman /** 95b3a33077SSimon Horman * SoC-specific CPG/MSSR Description 96b3a33077SSimon Horman * 971f7db7bbSChris Brandt * @early_core_clks: Array of Early Core Clock definitions 981f7db7bbSChris Brandt * @num_early_core_clks: Number of entries in early_core_clks[] 991f7db7bbSChris Brandt * @early_mod_clks: Array of Early Module Clock definitions 1001f7db7bbSChris Brandt * @num_early_mod_clks: Number of entries in early_mod_clks[] 1011f7db7bbSChris Brandt * 102b3a33077SSimon Horman * @core_clks: Array of Core Clock definitions 103b3a33077SSimon Horman * @num_core_clks: Number of entries in core_clks[] 104b3a33077SSimon Horman * @last_dt_core_clk: ID of the last Core Clock exported to DT 105b3a33077SSimon Horman * @num_total_core_clks: Total number of Core Clocks (exported + internal) 106b3a33077SSimon Horman * 107b3a33077SSimon Horman * @mod_clks: Array of Module Clock definitions 108b3a33077SSimon Horman * @num_mod_clks: Number of entries in mod_clks[] 109b3a33077SSimon Horman * @num_hw_mod_clks: Number of Module Clocks supported by the hardware 110b3a33077SSimon Horman * 111b3a33077SSimon Horman * @crit_mod_clks: Array with Module Clock IDs of critical clocks that 112b3a33077SSimon Horman * should not be disabled without a knowledgeable driver 113b3a33077SSimon Horman * @num_crit_mod_clks: Number of entries in crit_mod_clks[] 114ffbf9cf3SYoshihiro Shimoda * @reg_layout: CPG/MSSR register layout from enum clk_reg_layout 115b3a33077SSimon Horman * 116b3a33077SSimon Horman * @core_pm_clks: Array with IDs of Core Clocks that are suitable for Power 117b3a33077SSimon Horman * Management, in addition to Module Clocks 118b3a33077SSimon Horman * @num_core_pm_clks: Number of entries in core_pm_clks[] 119b3a33077SSimon Horman * 120b3a33077SSimon Horman * @init: Optional callback to perform SoC-specific initialization 121b3a33077SSimon Horman * @cpg_clk_register: Optional callback to handle special Core Clock types 122b3a33077SSimon Horman */ 123b3a33077SSimon Horman 124b3a33077SSimon Horman struct cpg_mssr_info { 1251f7db7bbSChris Brandt /* Early Clocks */ 1261f7db7bbSChris Brandt const struct cpg_core_clk *early_core_clks; 1271f7db7bbSChris Brandt unsigned int num_early_core_clks; 1281f7db7bbSChris Brandt const struct mssr_mod_clk *early_mod_clks; 1291f7db7bbSChris Brandt unsigned int num_early_mod_clks; 1301f7db7bbSChris Brandt 131b3a33077SSimon Horman /* Core Clocks */ 132b3a33077SSimon Horman const struct cpg_core_clk *core_clks; 133b3a33077SSimon Horman unsigned int num_core_clks; 134b3a33077SSimon Horman unsigned int last_dt_core_clk; 135b3a33077SSimon Horman unsigned int num_total_core_clks; 136ffbf9cf3SYoshihiro Shimoda enum clk_reg_layout reg_layout; 137b3a33077SSimon Horman 138b3a33077SSimon Horman /* Module Clocks */ 139b3a33077SSimon Horman const struct mssr_mod_clk *mod_clks; 140b3a33077SSimon Horman unsigned int num_mod_clks; 141b3a33077SSimon Horman unsigned int num_hw_mod_clks; 142b3a33077SSimon Horman 143b3a33077SSimon Horman /* Critical Module Clocks that should not be disabled */ 144b3a33077SSimon Horman const unsigned int *crit_mod_clks; 145b3a33077SSimon Horman unsigned int num_crit_mod_clks; 146b3a33077SSimon Horman 147b3a33077SSimon Horman /* Core Clocks suitable for PM, in addition to the Module Clocks */ 148b3a33077SSimon Horman const unsigned int *core_pm_clks; 149b3a33077SSimon Horman unsigned int num_core_pm_clks; 150b3a33077SSimon Horman 151b3a33077SSimon Horman /* Callbacks */ 152b3a33077SSimon Horman int (*init)(struct device *dev); 153b3a33077SSimon Horman struct clk *(*cpg_clk_register)(struct device *dev, 154b3a33077SSimon Horman const struct cpg_core_clk *core, 155b3a33077SSimon Horman const struct cpg_mssr_info *info, 1561f4023cdSGeert Uytterhoeven struct clk **clks, void __iomem *base, 1571f4023cdSGeert Uytterhoeven struct raw_notifier_head *notifiers); 158b3a33077SSimon Horman }; 159b3a33077SSimon Horman 160fde35c9cSChris Brandt extern const struct cpg_mssr_info r7s9210_cpg_mssr_info; 161e8208a71SLad Prabhakar extern const struct cpg_mssr_info r8a7742_cpg_mssr_info; 162c0b2d75dSSergei Shtylyov extern const struct cpg_mssr_info r8a7743_cpg_mssr_info; 1639127d54bSSergei Shtylyov extern const struct cpg_mssr_info r8a7745_cpg_mssr_info; 1645bf2fbbeSBiju Das extern const struct cpg_mssr_info r8a77470_cpg_mssr_info; 165331a53e0SBiju Das extern const struct cpg_mssr_info r8a774a1_cpg_mssr_info; 1660b9f1c2cSBiju Das extern const struct cpg_mssr_info r8a774b1_cpg_mssr_info; 167906e0a4aSFabrizio Castro extern const struct cpg_mssr_info r8a774c0_cpg_mssr_info; 168c8a53fa1SMarian-Cristian Rotariu extern const struct cpg_mssr_info r8a774e1_cpg_mssr_info; 169d4e59f10SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7790_cpg_mssr_info; 1706449ab81SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7791_cpg_mssr_info; 171fd3c2f38SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7792_cpg_mssr_info; 1722d75588aSGeert Uytterhoeven extern const struct cpg_mssr_info r8a7794_cpg_mssr_info; 173b3a33077SSimon Horman extern const struct cpg_mssr_info r8a7795_cpg_mssr_info; 174e4e2d7c3SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7796_cpg_mssr_info; 1757ce36da9SJacopo Mondi extern const struct cpg_mssr_info r8a77965_cpg_mssr_info; 1768d46e28fSSergei Shtylyov extern const struct cpg_mssr_info r8a77970_cpg_mssr_info; 177ce15783cSSergei Shtylyov extern const struct cpg_mssr_info r8a77980_cpg_mssr_info; 1783570a2afSYoshihiro Shimoda extern const struct cpg_mssr_info r8a77990_cpg_mssr_info; 179d71e851dSGeert Uytterhoeven extern const struct cpg_mssr_info r8a77995_cpg_mssr_info; 18017bcc803SYoshihiro Shimoda extern const struct cpg_mssr_info r8a779a0_cpg_mssr_info; 18124aaff6aSYoshihiro Shimoda extern const struct cpg_mssr_info r8a779f0_cpg_mssr_info; 182*0ab55cf1SYoshihiro Shimoda extern const struct cpg_mssr_info r8a779g0_cpg_mssr_info; 18348d0341eSGeert Uytterhoeven 1841f7db7bbSChris Brandt void __init cpg_mssr_early_init(struct device_node *np, 1851f7db7bbSChris Brandt const struct cpg_mssr_info *info); 18648d0341eSGeert Uytterhoeven 18748d0341eSGeert Uytterhoeven /* 18848d0341eSGeert Uytterhoeven * Helpers for fixing up clock tables depending on SoC revision 18948d0341eSGeert Uytterhoeven */ 19048d0341eSGeert Uytterhoeven extern void mssr_mod_nullify(struct mssr_mod_clk *mod_clks, 19148d0341eSGeert Uytterhoeven unsigned int num_mod_clks, 19248d0341eSGeert Uytterhoeven const unsigned int *clks, unsigned int n); 193b3a33077SSimon Horman #endif 194