gxbb-aoclk.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
  2. /*
  3. * Copyright (c) 2016 BayLibre, SAS.
  4. * Author: Neil Armstrong <[email protected]>
  5. */
  6. #include <linux/platform_device.h>
  7. #include <linux/mfd/syscon.h>
  8. #include <linux/module.h>
  9. #include "meson-aoclk.h"
  10. #include "gxbb-aoclk.h"
  11. #include "clk-regmap.h"
  12. #include "clk-dualdiv.h"
  13. /* AO Configuration Clock registers offsets */
  14. #define AO_RTI_PWR_CNTL_REG1 0x0c
  15. #define AO_RTI_PWR_CNTL_REG0 0x10
  16. #define AO_RTI_GEN_CNTL_REG0 0x40
  17. #define AO_OSCIN_CNTL 0x58
  18. #define AO_CRT_CLK_CNTL1 0x68
  19. #define AO_RTC_ALT_CLK_CNTL0 0x94
  20. #define AO_RTC_ALT_CLK_CNTL1 0x98
  21. #define GXBB_AO_GATE(_name, _bit) \
  22. static struct clk_regmap _name##_ao = { \
  23. .data = &(struct clk_regmap_gate_data) { \
  24. .offset = AO_RTI_GEN_CNTL_REG0, \
  25. .bit_idx = (_bit), \
  26. }, \
  27. .hw.init = &(struct clk_init_data) { \
  28. .name = #_name "_ao", \
  29. .ops = &clk_regmap_gate_ops, \
  30. .parent_data = &(const struct clk_parent_data) { \
  31. .fw_name = "mpeg-clk", \
  32. }, \
  33. .num_parents = 1, \
  34. .flags = CLK_IGNORE_UNUSED, \
  35. }, \
  36. }
  37. GXBB_AO_GATE(remote, 0);
  38. GXBB_AO_GATE(i2c_master, 1);
  39. GXBB_AO_GATE(i2c_slave, 2);
  40. GXBB_AO_GATE(uart1, 3);
  41. GXBB_AO_GATE(uart2, 5);
  42. GXBB_AO_GATE(ir_blaster, 6);
  43. static struct clk_regmap ao_cts_oscin = {
  44. .data = &(struct clk_regmap_gate_data){
  45. .offset = AO_RTI_PWR_CNTL_REG0,
  46. .bit_idx = 6,
  47. },
  48. .hw.init = &(struct clk_init_data){
  49. .name = "ao_cts_oscin",
  50. .ops = &clk_regmap_gate_ro_ops,
  51. .parent_data = &(const struct clk_parent_data) {
  52. .fw_name = "xtal",
  53. },
  54. .num_parents = 1,
  55. },
  56. };
  57. static struct clk_regmap ao_32k_pre = {
  58. .data = &(struct clk_regmap_gate_data){
  59. .offset = AO_RTC_ALT_CLK_CNTL0,
  60. .bit_idx = 31,
  61. },
  62. .hw.init = &(struct clk_init_data){
  63. .name = "ao_32k_pre",
  64. .ops = &clk_regmap_gate_ops,
  65. .parent_hws = (const struct clk_hw *[]) { &ao_cts_oscin.hw },
  66. .num_parents = 1,
  67. },
  68. };
  69. static const struct meson_clk_dualdiv_param gxbb_32k_div_table[] = {
  70. {
  71. .dual = 1,
  72. .n1 = 733,
  73. .m1 = 8,
  74. .n2 = 732,
  75. .m2 = 11,
  76. }, {}
  77. };
  78. static struct clk_regmap ao_32k_div = {
  79. .data = &(struct meson_clk_dualdiv_data){
  80. .n1 = {
  81. .reg_off = AO_RTC_ALT_CLK_CNTL0,
  82. .shift = 0,
  83. .width = 12,
  84. },
  85. .n2 = {
  86. .reg_off = AO_RTC_ALT_CLK_CNTL0,
  87. .shift = 12,
  88. .width = 12,
  89. },
  90. .m1 = {
  91. .reg_off = AO_RTC_ALT_CLK_CNTL1,
  92. .shift = 0,
  93. .width = 12,
  94. },
  95. .m2 = {
  96. .reg_off = AO_RTC_ALT_CLK_CNTL1,
  97. .shift = 12,
  98. .width = 12,
  99. },
  100. .dual = {
  101. .reg_off = AO_RTC_ALT_CLK_CNTL0,
  102. .shift = 28,
  103. .width = 1,
  104. },
  105. .table = gxbb_32k_div_table,
  106. },
  107. .hw.init = &(struct clk_init_data){
  108. .name = "ao_32k_div",
  109. .ops = &meson_clk_dualdiv_ops,
  110. .parent_hws = (const struct clk_hw *[]) { &ao_32k_pre.hw },
  111. .num_parents = 1,
  112. },
  113. };
  114. static struct clk_regmap ao_32k_sel = {
  115. .data = &(struct clk_regmap_mux_data) {
  116. .offset = AO_RTC_ALT_CLK_CNTL1,
  117. .mask = 0x1,
  118. .shift = 24,
  119. .flags = CLK_MUX_ROUND_CLOSEST,
  120. },
  121. .hw.init = &(struct clk_init_data){
  122. .name = "ao_32k_sel",
  123. .ops = &clk_regmap_mux_ops,
  124. .parent_hws = (const struct clk_hw *[]) {
  125. &ao_32k_div.hw,
  126. &ao_32k_pre.hw
  127. },
  128. .num_parents = 2,
  129. .flags = CLK_SET_RATE_PARENT,
  130. },
  131. };
  132. static struct clk_regmap ao_32k = {
  133. .data = &(struct clk_regmap_gate_data){
  134. .offset = AO_RTC_ALT_CLK_CNTL0,
  135. .bit_idx = 30,
  136. },
  137. .hw.init = &(struct clk_init_data){
  138. .name = "ao_32k",
  139. .ops = &clk_regmap_gate_ops,
  140. .parent_hws = (const struct clk_hw *[]) { &ao_32k_sel.hw },
  141. .num_parents = 1,
  142. .flags = CLK_SET_RATE_PARENT,
  143. },
  144. };
  145. static struct clk_regmap ao_cts_rtc_oscin = {
  146. .data = &(struct clk_regmap_mux_data) {
  147. .offset = AO_RTI_PWR_CNTL_REG0,
  148. .mask = 0x7,
  149. .shift = 10,
  150. .table = (u32[]){ 1, 2, 3, 4 },
  151. .flags = CLK_MUX_ROUND_CLOSEST,
  152. },
  153. .hw.init = &(struct clk_init_data){
  154. .name = "ao_cts_rtc_oscin",
  155. .ops = &clk_regmap_mux_ops,
  156. .parent_data = (const struct clk_parent_data []) {
  157. { .fw_name = "ext-32k-0", },
  158. { .fw_name = "ext-32k-1", },
  159. { .fw_name = "ext-32k-2", },
  160. { .hw = &ao_32k.hw },
  161. },
  162. .num_parents = 4,
  163. .flags = CLK_SET_RATE_PARENT,
  164. },
  165. };
  166. static struct clk_regmap ao_clk81 = {
  167. .data = &(struct clk_regmap_mux_data) {
  168. .offset = AO_RTI_PWR_CNTL_REG0,
  169. .mask = 0x1,
  170. .shift = 0,
  171. .flags = CLK_MUX_ROUND_CLOSEST,
  172. },
  173. .hw.init = &(struct clk_init_data){
  174. .name = "ao_clk81",
  175. .ops = &clk_regmap_mux_ro_ops,
  176. .parent_data = (const struct clk_parent_data []) {
  177. { .fw_name = "mpeg-clk", },
  178. { .hw = &ao_cts_rtc_oscin.hw },
  179. },
  180. .num_parents = 2,
  181. .flags = CLK_SET_RATE_PARENT,
  182. },
  183. };
  184. static struct clk_regmap ao_cts_cec = {
  185. .data = &(struct clk_regmap_mux_data) {
  186. .offset = AO_CRT_CLK_CNTL1,
  187. .mask = 0x1,
  188. .shift = 27,
  189. .flags = CLK_MUX_ROUND_CLOSEST,
  190. },
  191. .hw.init = &(struct clk_init_data){
  192. .name = "ao_cts_cec",
  193. .ops = &clk_regmap_mux_ops,
  194. /*
  195. * FIXME: The 'fixme' parent obviously does not exist.
  196. *
  197. * ATM, CCF won't call get_parent() if num_parents is 1. It
  198. * does not allow NULL as a parent name either.
  199. *
  200. * On this particular mux, we only know the input #1 parent
  201. * but, on boot, unknown input #0 is set, so it is critical
  202. * to call .get_parent() on it
  203. *
  204. * Until CCF gets fixed, adding this fake parent that won't
  205. * ever be registered should work around the problem
  206. */
  207. .parent_data = (const struct clk_parent_data []) {
  208. { .name = "fixme", .index = -1, },
  209. { .hw = &ao_cts_rtc_oscin.hw },
  210. },
  211. .num_parents = 2,
  212. .flags = CLK_SET_RATE_PARENT,
  213. },
  214. };
  215. static const unsigned int gxbb_aoclk_reset[] = {
  216. [RESET_AO_REMOTE] = 16,
  217. [RESET_AO_I2C_MASTER] = 18,
  218. [RESET_AO_I2C_SLAVE] = 19,
  219. [RESET_AO_UART1] = 17,
  220. [RESET_AO_UART2] = 22,
  221. [RESET_AO_IR_BLASTER] = 23,
  222. };
  223. static struct clk_regmap *gxbb_aoclk[] = {
  224. &remote_ao,
  225. &i2c_master_ao,
  226. &i2c_slave_ao,
  227. &uart1_ao,
  228. &uart2_ao,
  229. &ir_blaster_ao,
  230. &ao_cts_oscin,
  231. &ao_32k_pre,
  232. &ao_32k_div,
  233. &ao_32k_sel,
  234. &ao_32k,
  235. &ao_cts_rtc_oscin,
  236. &ao_clk81,
  237. &ao_cts_cec,
  238. };
  239. static const struct clk_hw_onecell_data gxbb_aoclk_onecell_data = {
  240. .hws = {
  241. [CLKID_AO_REMOTE] = &remote_ao.hw,
  242. [CLKID_AO_I2C_MASTER] = &i2c_master_ao.hw,
  243. [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao.hw,
  244. [CLKID_AO_UART1] = &uart1_ao.hw,
  245. [CLKID_AO_UART2] = &uart2_ao.hw,
  246. [CLKID_AO_IR_BLASTER] = &ir_blaster_ao.hw,
  247. [CLKID_AO_CEC_32K] = &ao_cts_cec.hw,
  248. [CLKID_AO_CTS_OSCIN] = &ao_cts_oscin.hw,
  249. [CLKID_AO_32K_PRE] = &ao_32k_pre.hw,
  250. [CLKID_AO_32K_DIV] = &ao_32k_div.hw,
  251. [CLKID_AO_32K_SEL] = &ao_32k_sel.hw,
  252. [CLKID_AO_32K] = &ao_32k.hw,
  253. [CLKID_AO_CTS_RTC_OSCIN] = &ao_cts_rtc_oscin.hw,
  254. [CLKID_AO_CLK81] = &ao_clk81.hw,
  255. },
  256. .num = NR_CLKS,
  257. };
  258. static const struct meson_aoclk_data gxbb_aoclkc_data = {
  259. .reset_reg = AO_RTI_GEN_CNTL_REG0,
  260. .num_reset = ARRAY_SIZE(gxbb_aoclk_reset),
  261. .reset = gxbb_aoclk_reset,
  262. .num_clks = ARRAY_SIZE(gxbb_aoclk),
  263. .clks = gxbb_aoclk,
  264. .hw_data = &gxbb_aoclk_onecell_data,
  265. };
  266. static const struct of_device_id gxbb_aoclkc_match_table[] = {
  267. {
  268. .compatible = "amlogic,meson-gx-aoclkc",
  269. .data = &gxbb_aoclkc_data,
  270. },
  271. { }
  272. };
  273. MODULE_DEVICE_TABLE(of, gxbb_aoclkc_match_table);
  274. static struct platform_driver gxbb_aoclkc_driver = {
  275. .probe = meson_aoclkc_probe,
  276. .driver = {
  277. .name = "gxbb-aoclkc",
  278. .of_match_table = gxbb_aoclkc_match_table,
  279. },
  280. };
  281. module_platform_driver(gxbb_aoclkc_driver);
  282. MODULE_LICENSE("GPL v2");