Paul Barker | 132d7ea | 2023-10-16 10:25:29 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * RZ/G2L Clock Pulse Generator |
| 4 | * |
| 5 | * Copyright (C) 2021-2023 Renesas Electronics Corp. |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #ifndef __RENESAS_RZG2L_CPG_H__ |
| 10 | #define __RENESAS_RZG2L_CPG_H__ |
| 11 | |
| 12 | #define CPG_SIPLL5_STBY 0x140 |
| 13 | #define CPG_SIPLL5_CLK1 0x144 |
| 14 | #define CPG_SIPLL5_CLK3 0x14C |
| 15 | #define CPG_SIPLL5_CLK4 0x150 |
| 16 | #define CPG_SIPLL5_CLK5 0x154 |
| 17 | #define CPG_SIPLL5_MON 0x15C |
| 18 | #define CPG_PL1_DDIV 0x200 |
| 19 | #define CPG_PL2_DDIV 0x204 |
| 20 | #define CPG_PL3A_DDIV 0x208 |
| 21 | #define CPG_PL6_DDIV 0x210 |
| 22 | #define CPG_PL2SDHI_DSEL 0x218 |
| 23 | #define CPG_CLKSTATUS 0x280 |
| 24 | #define CPG_PL3_SSEL 0x408 |
| 25 | #define CPG_PL6_SSEL 0x414 |
| 26 | #define CPG_PL6_ETH_SSEL 0x418 |
| 27 | #define CPG_PL5_SDIV 0x420 |
| 28 | #define CPG_RST_MON 0x680 |
| 29 | #define CPG_OTHERFUNC1_REG 0xBE8 |
| 30 | |
| 31 | #define CPG_SIPLL5_STBY_RESETB BIT(0) |
| 32 | #define CPG_SIPLL5_STBY_RESETB_WEN BIT(16) |
| 33 | #define CPG_SIPLL5_STBY_SSCG_EN_WEN BIT(18) |
| 34 | #define CPG_SIPLL5_STBY_DOWNSPREAD_WEN BIT(20) |
| 35 | #define CPG_SIPLL5_CLK4_RESV_LSB 0xFF |
| 36 | #define CPG_SIPLL5_MON_PLL5_LOCK BIT(4) |
| 37 | |
| 38 | #define CPG_OTHERFUNC1_REG_RES0_ON_WEN BIT(16) |
| 39 | |
| 40 | #define CPG_PL5_SDIV_DIV_DSI_A_WEN BIT(16) |
| 41 | #define CPG_PL5_SDIV_DIV_DSI_B_WEN BIT(24) |
| 42 | |
| 43 | #define CPG_CLKSTATUS_SELSDHI0_STS BIT(28) |
| 44 | #define CPG_CLKSTATUS_SELSDHI1_STS BIT(29) |
| 45 | |
| 46 | #define CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US 20000 |
| 47 | |
| 48 | /* n = 0/1/2 for PLL1/4/6 */ |
| 49 | #define CPG_SAMPLL_CLK1(n) (0x04 + (16 * (n))) |
| 50 | #define CPG_SAMPLL_CLK2(n) (0x08 + (16 * (n))) |
| 51 | |
| 52 | #define PLL146_CONF(n) (CPG_SAMPLL_CLK1(n) << 22 | CPG_SAMPLL_CLK2(n) << 12) |
| 53 | |
| 54 | #define DDIV_PACK(offset, bitpos, size) \ |
| 55 | (((offset) << 20) | ((bitpos) << 12) | ((size) << 8)) |
| 56 | #define DIVPL1A DDIV_PACK(CPG_PL1_DDIV, 0, 2) |
| 57 | #define DIVPL2A DDIV_PACK(CPG_PL2_DDIV, 0, 3) |
| 58 | #define DIVDSILPCLK DDIV_PACK(CPG_PL2_DDIV, 12, 2) |
| 59 | #define DIVPL3A DDIV_PACK(CPG_PL3A_DDIV, 0, 3) |
| 60 | #define DIVPL3B DDIV_PACK(CPG_PL3A_DDIV, 4, 3) |
| 61 | #define DIVPL3C DDIV_PACK(CPG_PL3A_DDIV, 8, 3) |
| 62 | #define DIVGPU DDIV_PACK(CPG_PL6_DDIV, 0, 2) |
| 63 | |
| 64 | #define SEL_PLL_PACK(offset, bitpos, size) \ |
| 65 | (((offset) << 20) | ((bitpos) << 12) | ((size) << 8)) |
| 66 | |
| 67 | #define SEL_PLL3_3 SEL_PLL_PACK(CPG_PL3_SSEL, 8, 1) |
| 68 | #define SEL_PLL5_4 SEL_PLL_PACK(CPG_OTHERFUNC1_REG, 0, 1) |
| 69 | #define SEL_PLL6_2 SEL_PLL_PACK(CPG_PL6_ETH_SSEL, 0, 1) |
| 70 | #define SEL_GPU2 SEL_PLL_PACK(CPG_PL6_SSEL, 12, 1) |
| 71 | |
| 72 | #define SEL_SDHI0 DDIV_PACK(CPG_PL2SDHI_DSEL, 0, 2) |
| 73 | #define SEL_SDHI1 DDIV_PACK(CPG_PL2SDHI_DSEL, 4, 2) |
| 74 | |
| 75 | #define SEL_SDHI_533MHz 1 |
| 76 | #define SEL_SDHI_400MHz 2 |
| 77 | #define SEL_SDHI_266MHz 3 |
| 78 | #define SEL_SDHI_WRITE_ENABLE 0x10000 |
| 79 | |
| 80 | /* Unpack CPG conf value create by DDIV_PACK() or SEL_PLL_PACK(). */ |
| 81 | #define CPG_CONF_OFFSET(x) ((x) >> 20) |
| 82 | #define CPG_CONF_BITPOS(x) (((x) >> 12) & 0xff) |
| 83 | #define CPG_CONF_SIZE(x) (((x) >> 8) & 0xf) |
| 84 | #define CPG_CONF_BITMASK(x) GENMASK(CPG_CONF_SIZE(x) - 1, 0) |
| 85 | |
| 86 | #define EXTAL_FREQ_IN_MEGA_HZ 24 |
| 87 | |
| 88 | /** |
| 89 | * Definitions of CPG Core Clocks |
| 90 | * |
| 91 | * These include: |
| 92 | * - Clock outputs exported to DT |
| 93 | * - External input clocks |
| 94 | * - Internal CPG clocks |
| 95 | */ |
| 96 | struct cpg_core_clk { |
| 97 | const char *name; |
| 98 | unsigned int id; |
| 99 | unsigned int parent; |
| 100 | unsigned int div; |
| 101 | unsigned int mult; |
| 102 | unsigned int type; |
| 103 | unsigned int conf; |
| 104 | const struct clk_div_table *dtable; |
| 105 | const char * const *parent_names; |
| 106 | int flag; |
| 107 | int mux_flags; |
| 108 | int num_parents; |
| 109 | }; |
| 110 | |
| 111 | enum clk_types { |
| 112 | /* Generic */ |
| 113 | CLK_TYPE_IN, /* External Clock Input */ |
| 114 | CLK_TYPE_FF, /* Fixed Factor Clock */ |
| 115 | CLK_TYPE_SAM_PLL, |
| 116 | |
| 117 | /* Clock with divider */ |
| 118 | CLK_TYPE_DIV, |
| 119 | |
| 120 | /* Clock with clock source selector */ |
| 121 | CLK_TYPE_MUX, |
| 122 | |
| 123 | /* Clock with SD clock source selector */ |
| 124 | CLK_TYPE_SD_MUX, |
| 125 | |
| 126 | /* Clock for SIPLL5 */ |
| 127 | CLK_TYPE_SIPLL5, |
| 128 | |
| 129 | /* Clock for PLL5_4 clock source selector */ |
| 130 | CLK_TYPE_PLL5_4_MUX, |
| 131 | |
| 132 | /* Clock for DSI divider */ |
| 133 | CLK_TYPE_DSI_DIV, |
| 134 | |
| 135 | }; |
| 136 | |
| 137 | #define DEF_TYPE(_name, _id, _type...) \ |
| 138 | { .name = _name, .id = _id, .type = _type } |
| 139 | #define DEF_BASE(_name, _id, _type, _parent...) \ |
| 140 | DEF_TYPE(_name, _id, _type, .parent = _parent) |
| 141 | #define DEF_SAMPLL(_name, _id, _parent, _conf) \ |
| 142 | DEF_TYPE(_name, _id, CLK_TYPE_SAM_PLL, .parent = _parent, .conf = _conf) |
| 143 | #define DEF_INPUT(_name, _id) \ |
| 144 | DEF_TYPE(_name, _id, CLK_TYPE_IN) |
| 145 | #define DEF_FIXED(_name, _id, _parent, _mult, _div) \ |
| 146 | DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult) |
| 147 | #define DEF_DIV(_name, _id, _parent, _conf, _dtable) \ |
| 148 | DEF_TYPE(_name, _id, CLK_TYPE_DIV, .conf = _conf, \ |
| 149 | .parent = _parent, .dtable = _dtable, \ |
| 150 | .flag = CLK_DIVIDER_HIWORD_MASK) |
| 151 | #define DEF_DIV_RO(_name, _id, _parent, _conf, _dtable) \ |
| 152 | DEF_TYPE(_name, _id, CLK_TYPE_DIV, .conf = _conf, \ |
| 153 | .parent = _parent, .dtable = _dtable, \ |
| 154 | .flag = CLK_DIVIDER_READ_ONLY) |
| 155 | #define DEF_MUX(_name, _id, _conf, _parent_names) \ |
| 156 | DEF_TYPE(_name, _id, CLK_TYPE_MUX, .conf = _conf, \ |
| 157 | .parent_names = _parent_names, \ |
| 158 | .num_parents = ARRAY_SIZE(_parent_names), \ |
| 159 | .mux_flags = CLK_MUX_HIWORD_MASK) |
| 160 | #define DEF_MUX_RO(_name, _id, _conf, _parent_names) \ |
| 161 | DEF_TYPE(_name, _id, CLK_TYPE_MUX, .conf = _conf, \ |
| 162 | .parent_names = _parent_names, \ |
| 163 | .num_parents = ARRAY_SIZE(_parent_names), \ |
| 164 | .mux_flags = CLK_MUX_READ_ONLY) |
| 165 | #define DEF_SD_MUX(_name, _id, _conf, _parent_names) \ |
| 166 | DEF_TYPE(_name, _id, CLK_TYPE_SD_MUX, .conf = _conf, \ |
| 167 | .parent_names = _parent_names, \ |
| 168 | .num_parents = ARRAY_SIZE(_parent_names)) |
| 169 | #define DEF_PLL5_FOUTPOSTDIV(_name, _id, _parent) \ |
| 170 | DEF_TYPE(_name, _id, CLK_TYPE_SIPLL5, .parent = _parent) |
| 171 | #define DEF_PLL5_4_MUX(_name, _id, _conf, _parent_names) \ |
| 172 | DEF_TYPE(_name, _id, CLK_TYPE_PLL5_4_MUX, .conf = _conf, \ |
| 173 | .parent_names = _parent_names, \ |
| 174 | .num_parents = ARRAY_SIZE(_parent_names)) |
| 175 | #define DEF_DSI_DIV(_name, _id, _parent, _flag) \ |
| 176 | DEF_TYPE(_name, _id, CLK_TYPE_DSI_DIV, .parent = _parent, .flag = _flag) |
| 177 | |
| 178 | /** |
| 179 | * struct rzg2l_mod_clk - Module Clocks definitions |
| 180 | * |
| 181 | * @name: handle between common and hardware-specific interfaces |
| 182 | * @id: clock index in array containing all Core and Module Clocks |
| 183 | * @parent: id of parent clock |
| 184 | * @off: register offset |
| 185 | * @bit: ON/MON bit |
| 186 | * @is_coupled: flag to indicate coupled clock |
| 187 | */ |
| 188 | struct rzg2l_mod_clk { |
| 189 | const char *name; |
| 190 | unsigned int id; |
| 191 | unsigned int parent; |
| 192 | u16 off; |
| 193 | u8 bit; |
| 194 | bool is_coupled; |
| 195 | }; |
| 196 | |
| 197 | #define DEF_MOD_BASE(_name, _id, _parent, _off, _bit, _is_coupled) \ |
| 198 | { \ |
| 199 | .name = (_name), \ |
| 200 | .id = (_id), \ |
| 201 | .parent = (_parent), \ |
| 202 | .off = (_off), \ |
| 203 | .bit = (_bit), \ |
| 204 | .is_coupled = (_is_coupled), \ |
| 205 | } |
| 206 | |
| 207 | #define DEF_MOD(_name, _id, _parent, _off, _bit) \ |
| 208 | DEF_MOD_BASE(_name, _id, _parent, _off, _bit, false) |
| 209 | |
| 210 | #define DEF_COUPLED(_name, _id, _parent, _off, _bit) \ |
| 211 | DEF_MOD_BASE(_name, _id, _parent, _off, _bit, true) |
| 212 | |
| 213 | /** |
| 214 | * struct rzg2l_reset - Reset definitions |
| 215 | * |
| 216 | * @off: register offset |
| 217 | * @bit: reset bit |
| 218 | * @monbit: monitor bit in CPG_RST_MON register, -1 if none |
| 219 | */ |
| 220 | struct rzg2l_reset { |
| 221 | u16 off; |
| 222 | u8 bit; |
| 223 | s8 monbit; |
| 224 | }; |
| 225 | |
| 226 | #define DEF_RST_MON(_id, _off, _bit, _monbit) \ |
| 227 | [_id] = { \ |
| 228 | .off = (_off), \ |
| 229 | .bit = (_bit), \ |
| 230 | .monbit = (_monbit) \ |
| 231 | } |
| 232 | #define DEF_RST(_id, _off, _bit) \ |
| 233 | DEF_RST_MON(_id, _off, _bit, -1) |
| 234 | |
| 235 | /** |
| 236 | * struct rzg2l_cpg_info - SoC-specific CPG Description |
| 237 | * |
| 238 | * @core_clks: Array of Core Clock definitions |
| 239 | * @num_core_clks: Number of entries in core_clks[] |
| 240 | * |
| 241 | * @mod_clks: Array of Module Clock definitions |
| 242 | * @num_mod_clks: Number of entries in mod_clks[] |
| 243 | * @num_hw_mod_clks: Number of Module Clocks supported by the hardware |
| 244 | * |
| 245 | * @resets: Array of Module Reset definitions |
| 246 | * @num_resets: Number of entries in resets[] |
| 247 | * |
| 248 | * @has_clk_mon_regs: Flag indicating whether the SoC has CLK_MON registers |
| 249 | */ |
| 250 | struct rzg2l_cpg_info { |
| 251 | /* Core Clocks */ |
| 252 | const struct cpg_core_clk *core_clks; |
| 253 | unsigned int num_core_clks; |
| 254 | |
| 255 | /* Module Clocks */ |
| 256 | const struct rzg2l_mod_clk *mod_clks; |
| 257 | unsigned int num_mod_clks; |
| 258 | unsigned int num_hw_mod_clks; |
| 259 | |
| 260 | /* Resets */ |
| 261 | const struct rzg2l_reset *resets; |
| 262 | unsigned int num_resets; |
| 263 | |
| 264 | bool has_clk_mon_regs; |
| 265 | }; |
| 266 | |
| 267 | extern const struct rzg2l_cpg_info r9a07g044_cpg_info; |
| 268 | |
| 269 | int rzg2l_cpg_bind(struct udevice *parent); |
| 270 | |
| 271 | /* |
| 272 | * Clock IDs start at an offset to avoid overlapping with core & module clock |
| 273 | * IDs defined in the dt-bindings headers. |
| 274 | */ |
| 275 | enum clk_ids { |
| 276 | /* External Input Clocks */ |
| 277 | CLK_EXTAL = 0x100, |
| 278 | |
| 279 | /* Internal Core Clocks */ |
| 280 | CLK_OSC_DIV1000 = 0x200, |
| 281 | CLK_PLL1, |
| 282 | CLK_PLL2, |
| 283 | CLK_PLL2_DIV2, |
| 284 | CLK_PLL2_DIV2_8, |
| 285 | CLK_PLL2_DIV2_10, |
| 286 | CLK_PLL3, |
| 287 | CLK_PLL3_400, |
| 288 | CLK_PLL3_533, |
| 289 | CLK_M2_DIV2, |
| 290 | CLK_PLL3_DIV2, |
| 291 | CLK_PLL3_DIV2_2, |
| 292 | CLK_PLL3_DIV2_4, |
| 293 | CLK_PLL3_DIV2_4_2, |
| 294 | CLK_SEL_PLL3_3, |
| 295 | CLK_DIV_PLL3_C, |
| 296 | CLK_PLL4, |
| 297 | CLK_PLL5, |
| 298 | CLK_PLL5_FOUTPOSTDIV, |
| 299 | CLK_PLL5_FOUT1PH0, |
| 300 | CLK_PLL5_FOUT3, |
| 301 | CLK_PLL5_250, |
| 302 | CLK_PLL6, |
| 303 | CLK_PLL6_250, |
| 304 | CLK_P1_DIV2, |
| 305 | CLK_PLL2_800, |
| 306 | CLK_PLL2_SDHI_533, |
| 307 | CLK_PLL2_SDHI_400, |
| 308 | CLK_PLL2_SDHI_266, |
| 309 | CLK_SD0_DIV4, |
| 310 | CLK_SD1_DIV4, |
| 311 | CLK_SEL_GPU2, |
| 312 | CLK_SEL_PLL5_4, |
| 313 | CLK_DSI_DIV, |
| 314 | CLK_PLL2_533, |
| 315 | CLK_PLL2_533_DIV2, |
| 316 | CLK_DIV_DSI_LPCLK, |
| 317 | }; |
| 318 | |
| 319 | #endif |