rzg2l-cpg.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * RZ/G2L Clock Pulse Generator
  4. *
  5. * Copyright (C) 2021 Renesas Electronics Corp.
  6. *
  7. */
  8. #ifndef __RENESAS_RZG2L_CPG_H__
  9. #define __RENESAS_RZG2L_CPG_H__
  10. #define CPG_SIPLL5_STBY (0x140)
  11. #define CPG_SIPLL5_CLK1 (0x144)
  12. #define CPG_SIPLL5_CLK3 (0x14C)
  13. #define CPG_SIPLL5_CLK4 (0x150)
  14. #define CPG_SIPLL5_CLK5 (0x154)
  15. #define CPG_SIPLL5_MON (0x15C)
  16. #define CPG_PL1_DDIV (0x200)
  17. #define CPG_PL2_DDIV (0x204)
  18. #define CPG_PL3A_DDIV (0x208)
  19. #define CPG_PL6_DDIV (0x210)
  20. #define CPG_PL2SDHI_DSEL (0x218)
  21. #define CPG_CLKSTATUS (0x280)
  22. #define CPG_PL3_SSEL (0x408)
  23. #define CPG_PL6_SSEL (0x414)
  24. #define CPG_PL6_ETH_SSEL (0x418)
  25. #define CPG_PL5_SDIV (0x420)
  26. #define CPG_RST_MON (0x680)
  27. #define CPG_OTHERFUNC1_REG (0xBE8)
  28. #define CPG_SIPLL5_STBY_RESETB BIT(0)
  29. #define CPG_SIPLL5_STBY_RESETB_WEN BIT(16)
  30. #define CPG_SIPLL5_STBY_SSCG_EN_WEN BIT(18)
  31. #define CPG_SIPLL5_STBY_DOWNSPREAD_WEN BIT(20)
  32. #define CPG_SIPLL5_CLK4_RESV_LSB (0xFF)
  33. #define CPG_SIPLL5_MON_PLL5_LOCK BIT(4)
  34. #define CPG_OTHERFUNC1_REG_RES0_ON_WEN BIT(16)
  35. #define CPG_PL5_SDIV_DIV_DSI_A_WEN BIT(16)
  36. #define CPG_PL5_SDIV_DIV_DSI_B_WEN BIT(24)
  37. #define CPG_CLKSTATUS_SELSDHI0_STS BIT(28)
  38. #define CPG_CLKSTATUS_SELSDHI1_STS BIT(29)
  39. #define CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US 200
  40. /* n = 0/1/2 for PLL1/4/6 */
  41. #define CPG_SAMPLL_CLK1(n) (0x04 + (16 * n))
  42. #define CPG_SAMPLL_CLK2(n) (0x08 + (16 * n))
  43. #define PLL146_CONF(n) (CPG_SAMPLL_CLK1(n) << 22 | CPG_SAMPLL_CLK2(n) << 12)
  44. #define DDIV_PACK(offset, bitpos, size) \
  45. (((offset) << 20) | ((bitpos) << 12) | ((size) << 8))
  46. #define DIVPL1A DDIV_PACK(CPG_PL1_DDIV, 0, 2)
  47. #define DIVPL2A DDIV_PACK(CPG_PL2_DDIV, 0, 3)
  48. #define DIVDSILPCLK DDIV_PACK(CPG_PL2_DDIV, 12, 2)
  49. #define DIVPL3A DDIV_PACK(CPG_PL3A_DDIV, 0, 3)
  50. #define DIVPL3B DDIV_PACK(CPG_PL3A_DDIV, 4, 3)
  51. #define DIVPL3C DDIV_PACK(CPG_PL3A_DDIV, 8, 3)
  52. #define DIVGPU DDIV_PACK(CPG_PL6_DDIV, 0, 2)
  53. #define SEL_PLL_PACK(offset, bitpos, size) \
  54. (((offset) << 20) | ((bitpos) << 12) | ((size) << 8))
  55. #define SEL_PLL3_3 SEL_PLL_PACK(CPG_PL3_SSEL, 8, 1)
  56. #define SEL_PLL5_4 SEL_PLL_PACK(CPG_OTHERFUNC1_REG, 0, 1)
  57. #define SEL_PLL6_2 SEL_PLL_PACK(CPG_PL6_ETH_SSEL, 0, 1)
  58. #define SEL_GPU2 SEL_PLL_PACK(CPG_PL6_SSEL, 12, 1)
  59. #define SEL_SDHI0 DDIV_PACK(CPG_PL2SDHI_DSEL, 0, 2)
  60. #define SEL_SDHI1 DDIV_PACK(CPG_PL2SDHI_DSEL, 4, 2)
  61. #define EXTAL_FREQ_IN_MEGA_HZ (24)
  62. /**
  63. * Definitions of CPG Core Clocks
  64. *
  65. * These include:
  66. * - Clock outputs exported to DT
  67. * - External input clocks
  68. * - Internal CPG clocks
  69. */
  70. struct cpg_core_clk {
  71. const char *name;
  72. unsigned int id;
  73. unsigned int parent;
  74. unsigned int div;
  75. unsigned int mult;
  76. unsigned int type;
  77. unsigned int conf;
  78. const struct clk_div_table *dtable;
  79. const char * const *parent_names;
  80. int flag;
  81. int mux_flags;
  82. int num_parents;
  83. };
  84. enum clk_types {
  85. /* Generic */
  86. CLK_TYPE_IN, /* External Clock Input */
  87. CLK_TYPE_FF, /* Fixed Factor Clock */
  88. CLK_TYPE_SAM_PLL,
  89. /* Clock with divider */
  90. CLK_TYPE_DIV,
  91. /* Clock with clock source selector */
  92. CLK_TYPE_MUX,
  93. /* Clock with SD clock source selector */
  94. CLK_TYPE_SD_MUX,
  95. /* Clock for SIPLL5 */
  96. CLK_TYPE_SIPLL5,
  97. /* Clock for PLL5_4 clock source selector */
  98. CLK_TYPE_PLL5_4_MUX,
  99. /* Clock for DSI divider */
  100. CLK_TYPE_DSI_DIV,
  101. };
  102. #define DEF_TYPE(_name, _id, _type...) \
  103. { .name = _name, .id = _id, .type = _type }
  104. #define DEF_BASE(_name, _id, _type, _parent...) \
  105. DEF_TYPE(_name, _id, _type, .parent = _parent)
  106. #define DEF_SAMPLL(_name, _id, _parent, _conf) \
  107. DEF_TYPE(_name, _id, CLK_TYPE_SAM_PLL, .parent = _parent, .conf = _conf)
  108. #define DEF_INPUT(_name, _id) \
  109. DEF_TYPE(_name, _id, CLK_TYPE_IN)
  110. #define DEF_FIXED(_name, _id, _parent, _mult, _div) \
  111. DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
  112. #define DEF_DIV(_name, _id, _parent, _conf, _dtable) \
  113. DEF_TYPE(_name, _id, CLK_TYPE_DIV, .conf = _conf, \
  114. .parent = _parent, .dtable = _dtable, \
  115. .flag = CLK_DIVIDER_HIWORD_MASK)
  116. #define DEF_DIV_RO(_name, _id, _parent, _conf, _dtable) \
  117. DEF_TYPE(_name, _id, CLK_TYPE_DIV, .conf = _conf, \
  118. .parent = _parent, .dtable = _dtable, \
  119. .flag = CLK_DIVIDER_READ_ONLY)
  120. #define DEF_MUX(_name, _id, _conf, _parent_names) \
  121. DEF_TYPE(_name, _id, CLK_TYPE_MUX, .conf = _conf, \
  122. .parent_names = _parent_names, \
  123. .num_parents = ARRAY_SIZE(_parent_names), \
  124. .mux_flags = CLK_MUX_HIWORD_MASK)
  125. #define DEF_MUX_RO(_name, _id, _conf, _parent_names) \
  126. DEF_TYPE(_name, _id, CLK_TYPE_MUX, .conf = _conf, \
  127. .parent_names = _parent_names, \
  128. .num_parents = ARRAY_SIZE(_parent_names), \
  129. .mux_flags = CLK_MUX_READ_ONLY)
  130. #define DEF_SD_MUX(_name, _id, _conf, _parent_names) \
  131. DEF_TYPE(_name, _id, CLK_TYPE_SD_MUX, .conf = _conf, \
  132. .parent_names = _parent_names, \
  133. .num_parents = ARRAY_SIZE(_parent_names))
  134. #define DEF_PLL5_FOUTPOSTDIV(_name, _id, _parent) \
  135. DEF_TYPE(_name, _id, CLK_TYPE_SIPLL5, .parent = _parent)
  136. #define DEF_PLL5_4_MUX(_name, _id, _conf, _parent_names) \
  137. DEF_TYPE(_name, _id, CLK_TYPE_PLL5_4_MUX, .conf = _conf, \
  138. .parent_names = _parent_names, \
  139. .num_parents = ARRAY_SIZE(_parent_names))
  140. #define DEF_DSI_DIV(_name, _id, _parent, _flag) \
  141. DEF_TYPE(_name, _id, CLK_TYPE_DSI_DIV, .parent = _parent, .flag = _flag)
  142. /**
  143. * struct rzg2l_mod_clk - Module Clocks definitions
  144. *
  145. * @name: handle between common and hardware-specific interfaces
  146. * @id: clock index in array containing all Core and Module Clocks
  147. * @parent: id of parent clock
  148. * @off: register offset
  149. * @bit: ON/MON bit
  150. * @is_coupled: flag to indicate coupled clock
  151. */
  152. struct rzg2l_mod_clk {
  153. const char *name;
  154. unsigned int id;
  155. unsigned int parent;
  156. u16 off;
  157. u8 bit;
  158. bool is_coupled;
  159. };
  160. #define DEF_MOD_BASE(_name, _id, _parent, _off, _bit, _is_coupled) \
  161. { \
  162. .name = _name, \
  163. .id = MOD_CLK_BASE + (_id), \
  164. .parent = (_parent), \
  165. .off = (_off), \
  166. .bit = (_bit), \
  167. .is_coupled = (_is_coupled), \
  168. }
  169. #define DEF_MOD(_name, _id, _parent, _off, _bit) \
  170. DEF_MOD_BASE(_name, _id, _parent, _off, _bit, false)
  171. #define DEF_COUPLED(_name, _id, _parent, _off, _bit) \
  172. DEF_MOD_BASE(_name, _id, _parent, _off, _bit, true)
  173. /**
  174. * struct rzg2l_reset - Reset definitions
  175. *
  176. * @off: register offset
  177. * @bit: reset bit
  178. * @monbit: monitor bit in CPG_RST_MON register, -1 if none
  179. */
  180. struct rzg2l_reset {
  181. u16 off;
  182. u8 bit;
  183. s8 monbit;
  184. };
  185. #define DEF_RST_MON(_id, _off, _bit, _monbit) \
  186. [_id] = { \
  187. .off = (_off), \
  188. .bit = (_bit), \
  189. .monbit = (_monbit) \
  190. }
  191. #define DEF_RST(_id, _off, _bit) \
  192. DEF_RST_MON(_id, _off, _bit, -1)
  193. /**
  194. * struct rzg2l_cpg_info - SoC-specific CPG Description
  195. *
  196. * @core_clks: Array of Core Clock definitions
  197. * @num_core_clks: Number of entries in core_clks[]
  198. * @last_dt_core_clk: ID of the last Core Clock exported to DT
  199. * @num_total_core_clks: Total number of Core Clocks (exported + internal)
  200. *
  201. * @mod_clks: Array of Module Clock definitions
  202. * @num_mod_clks: Number of entries in mod_clks[]
  203. * @num_hw_mod_clks: Number of Module Clocks supported by the hardware
  204. *
  205. * @resets: Array of Module Reset definitions
  206. * @num_resets: Number of entries in resets[]
  207. *
  208. * @crit_mod_clks: Array with Module Clock IDs of critical clocks that
  209. * should not be disabled without a knowledgeable driver
  210. * @num_crit_mod_clks: Number of entries in crit_mod_clks[]
  211. * @has_clk_mon_regs: Flag indicating whether the SoC has CLK_MON registers
  212. */
  213. struct rzg2l_cpg_info {
  214. /* Core Clocks */
  215. const struct cpg_core_clk *core_clks;
  216. unsigned int num_core_clks;
  217. unsigned int last_dt_core_clk;
  218. unsigned int num_total_core_clks;
  219. /* Module Clocks */
  220. const struct rzg2l_mod_clk *mod_clks;
  221. unsigned int num_mod_clks;
  222. unsigned int num_hw_mod_clks;
  223. /* Resets */
  224. const struct rzg2l_reset *resets;
  225. unsigned int num_resets;
  226. /* Critical Module Clocks that should not be disabled */
  227. const unsigned int *crit_mod_clks;
  228. unsigned int num_crit_mod_clks;
  229. bool has_clk_mon_regs;
  230. };
  231. extern const struct rzg2l_cpg_info r9a07g043_cpg_info;
  232. extern const struct rzg2l_cpg_info r9a07g044_cpg_info;
  233. extern const struct rzg2l_cpg_info r9a07g054_cpg_info;
  234. extern const struct rzg2l_cpg_info r9a09g011_cpg_info;
  235. #endif