/product/rcar/module/rcar_sd_clock/include/mod_rcar_sd_clock.h

https://github.com/ARM-software/SCP-firmware · C Header · 272 lines · 189 code · 32 blank · 51 comment · 0 complexity · 6b1c495568c0d132876850d9adb1d985 MD5 · raw file

  1. /*
  2. * Renesas SCP/MCP Software
  3. * Copyright (c) 2020-2021, Renesas Electronics Corporation. All rights
  4. * reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef MOD_RCAR_SD_CLOCK_H
  9. #define MOD_RCAR_SD_CLOCK_H
  10. #include <clock_sd_devices.h>
  11. #include <rcar_mmap.h>
  12. #include <mod_clock.h>
  13. #include <mod_rcar_clock.h>
  14. #include <fwk_element.h>
  15. #include <stdint.h>
  16. /*!
  17. * \addtogroup GroupRCARModule RCAR Product Modules
  18. * @{
  19. */
  20. /*!
  21. * \defgroup GroupRCARSdClock SD clock
  22. * @{
  23. */
  24. /*!
  25. * \brief Rate lookup entry.
  26. */
  27. struct mod_rcar_sd_clock_rate {
  28. /*! Divider used to obtain the rate value. */
  29. uint32_t divider_num;
  30. /*! Value to be set for the divider. */
  31. uint32_t divider;
  32. /*! Divider maskbit value. */
  33. uint32_t divider_mask;
  34. };
  35. /*!
  36. * \brief Subsystem clock device configuration.
  37. */
  38. struct mod_rcar_sd_clock_dev_config {
  39. /*! The type of the clock device. */
  40. enum mod_rcar_clock_type type;
  41. /*! Pointer to the clock's control register. */
  42. volatile uint32_t const control_reg;
  43. /*! enable / disable bit position. */
  44. volatile bool stop_clk;
  45. /*! enable / disable bit position. */
  46. volatile uint32_t const stop_clk_bit;
  47. /*! Parent clock id. */
  48. uint32_t parent;
  49. /*! Required initialization Clock divider. */
  50. bool need_hardware_init;
  51. /*! Fixed Clock divider. */
  52. uint32_t div;
  53. /*! Fixed Clock divider. */
  54. uint32_t multi;
  55. /*! The type of rates the clock provides (discrete or continuous) */
  56. enum mod_clock_rate_type rate_type;
  57. /*! Pointer to the clock's rate lookup table. */
  58. const struct mod_rcar_sd_clock_rate *rate_table;
  59. /*! The number of rates in the rate lookup table. */
  60. uint32_t rate_count;
  61. };
  62. /*!
  63. * @cond
  64. */
  65. /* Device context */
  66. struct rcar_sd_clock_dev_ctx {
  67. bool initialized;
  68. uint64_t current_rate;
  69. uint64_t *rate_table;
  70. enum mod_clock_state current_state;
  71. const struct mod_rcar_sd_clock_dev_config *config;
  72. };
  73. /* Module context */
  74. struct rcar_sd_clock_ctx {
  75. struct rcar_sd_clock_dev_ctx *dev_ctx_table;
  76. unsigned int dev_count;
  77. uint32_t parent_clk[CLOCK_PARENT_IDX_COUNT];
  78. };
  79. struct rcar_gen3_cpg_pll_config {
  80. char extal_div;
  81. char pll1_mult;
  82. char pll1_div;
  83. char pll3_mult;
  84. char pll3_div;
  85. char osc_prediv;
  86. };
  87. /* control register */
  88. #define CPG_SD0CKCR (CPG_BASE + 0x0074)
  89. #define CPG_SD1CKCR (CPG_BASE + 0x0078)
  90. #define CPG_SD2CKCR (CPG_BASE + 0x0268)
  91. #define CPG_SD3CKCR (CPG_BASE + 0x026C)
  92. #define CPG_SDNCKCR_MASK 0x1F
  93. #define CPG_SDNCKCR_SD_64 0x11
  94. #define CPG_SDNCKCR_SD_32 0xD
  95. #define CPG_SDNCKCR_SD_16 0x9
  96. #define CPG_SDNCKCR_SD_8 0x5
  97. #define CPG_SDNCKCR_SD_4 0x1
  98. #define CPG_SDNCKCR_SD_2 0x0
  99. #define CPG_CANFDCKCR (CPG_BASE + 0x0244)
  100. #define CPG_CSI0CKCR (CPG_BASE + 0x000C)
  101. #define CPG_MSOCKCR (CPG_BASE + 0x0014)
  102. #define CPG_HDMICKCR (CPG_BASE + 0x0250)
  103. #define CPG_CON_MASK 0x3F
  104. #define CPG_CON_MAX 64
  105. #define CPG_FRQCRB_ZTRFC_MASK 0xF00000
  106. #define CPG_FRQCRB_ZTRFC_24 0x800000
  107. #define CPG_FRQCRB_ZTRFC_18 0x700000
  108. #define CPG_FRQCRB_ZTRFC_16 0x600000
  109. #define CPG_FRQCRB_ZTRFC_12 0x500000
  110. #define CPG_FRQCRB_ZTRFC_8 0x400000
  111. #define CPG_FRQCRB_ZTRFC_6 0x300000
  112. #define CPG_FRQCRB_ZTFC_MASK 0xF0000
  113. #define CPG_FRQCRB_ZTFC_24 0x80000
  114. #define CPG_FRQCRB_ZTFC_18 0x70000
  115. #define CPG_FRQCRB_ZTFC_16 0x60000
  116. #define CPG_FRQCRB_ZTFC_12 0x50000
  117. #define CPG_FRQCRB_ZTFC_8 0x40000
  118. #define CPG_FRQCRB_ZTFC_6 0x30000
  119. #define CPG_FRQCRB_ZTFC_4 0x20000
  120. #define CPG_FRQCRB_ZTRD2FC_MASK 0xF
  121. #define CPG_FRQCRB_ZTRD2FC_24 0x8
  122. #define CPG_FRQCRB_ZTRD2FC_18 0x7
  123. #define CPG_FRQCRB_ZTRD2FC_16 0x6
  124. #define CPG_FRQCRB_ZTRD2FC_12 0x5
  125. #define CPG_PLL_CONFIG_INDEX(md) \
  126. ((((md)&BIT(14)) >> 11) | (((md)&BIT(13)) >> 11) | \
  127. (((md)&BIT(19)) >> 18) | (((md)&BIT(17)) >> 17))
  128. static const struct rcar_gen3_cpg_pll_config cpg_pll_configs[16] = {
  129. /* EXTAL div PLL1 mult/div PLL3 mult/div OSC prediv */
  130. {
  131. 1,
  132. 192,
  133. 1,
  134. 192,
  135. 1,
  136. 16,
  137. },
  138. {
  139. 1,
  140. 192,
  141. 1,
  142. 128,
  143. 1,
  144. 16,
  145. },
  146. { 0, /* Prohibited setting */ },
  147. {
  148. 1,
  149. 192,
  150. 1,
  151. 192,
  152. 1,
  153. 16,
  154. },
  155. {
  156. 1,
  157. 160,
  158. 1,
  159. 160,
  160. 1,
  161. 19,
  162. },
  163. {
  164. 1,
  165. 160,
  166. 1,
  167. 106,
  168. 1,
  169. 19,
  170. },
  171. { 0, /* Prohibited setting */ },
  172. {
  173. 1,
  174. 160,
  175. 1,
  176. 160,
  177. 1,
  178. 19,
  179. },
  180. {
  181. 1,
  182. 128,
  183. 1,
  184. 128,
  185. 1,
  186. 24,
  187. },
  188. {
  189. 1,
  190. 128,
  191. 1,
  192. 84,
  193. 1,
  194. 24,
  195. },
  196. { 0, /* Prohibited setting */ },
  197. {
  198. 1,
  199. 128,
  200. 1,
  201. 128,
  202. 1,
  203. 24,
  204. },
  205. {
  206. 2,
  207. 192,
  208. 1,
  209. 192,
  210. 1,
  211. 32,
  212. },
  213. {
  214. 2,
  215. 192,
  216. 1,
  217. 128,
  218. 1,
  219. 32,
  220. },
  221. { 0, /* Prohibited setting */ },
  222. {
  223. 2,
  224. 192,
  225. 1,
  226. 192,
  227. 1,
  228. 32,
  229. },
  230. };
  231. /*!
  232. * @endcond
  233. */
  234. /*!
  235. * @}
  236. */
  237. /*!
  238. * @}
  239. */
  240. #endif /* MOD_RCAR_SD_CLOCK_H */