axg-aoclk.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Amlogic Meson-AXG Clock Controller Driver
  4. *
  5. * Copyright (c) 2016 Baylibre SAS.
  6. * Author: Michael Turquette <[email protected]>
  7. *
  8. * Copyright (c) 2018 Amlogic, inc.
  9. * Author: Qiufang Dai <[email protected]>
  10. */
  11. #include <linux/clk-provider.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/reset-controller.h>
  14. #include <linux/mfd/syscon.h>
  15. #include <linux/module.h>
  16. #include "meson-aoclk.h"
  17. #include "axg-aoclk.h"
  18. #include "clk-regmap.h"
  19. #include "clk-dualdiv.h"
  20. /*
  21. * AO Configuration Clock registers offsets
  22. * Register offsets from the data sheet must be multiplied by 4.
  23. */
  24. #define AO_RTI_PWR_CNTL_REG1 0x0C
  25. #define AO_RTI_PWR_CNTL_REG0 0x10
  26. #define AO_RTI_GEN_CNTL_REG0 0x40
  27. #define AO_OSCIN_CNTL 0x58
  28. #define AO_CRT_CLK_CNTL1 0x68
  29. #define AO_SAR_CLK 0x90
  30. #define AO_RTC_ALT_CLK_CNTL0 0x94
  31. #define AO_RTC_ALT_CLK_CNTL1 0x98
  32. #define AXG_AO_GATE(_name, _bit) \
  33. static struct clk_regmap axg_aoclk_##_name = { \
  34. .data = &(struct clk_regmap_gate_data) { \
  35. .offset = (AO_RTI_GEN_CNTL_REG0), \
  36. .bit_idx = (_bit), \
  37. }, \
  38. .hw.init = &(struct clk_init_data) { \
  39. .name = "axg_ao_" #_name, \
  40. .ops = &clk_regmap_gate_ops, \
  41. .parent_data = &(const struct clk_parent_data) { \
  42. .fw_name = "mpeg-clk", \
  43. }, \
  44. .num_parents = 1, \
  45. .flags = CLK_IGNORE_UNUSED, \
  46. }, \
  47. }
  48. AXG_AO_GATE(remote, 0);
  49. AXG_AO_GATE(i2c_master, 1);
  50. AXG_AO_GATE(i2c_slave, 2);
  51. AXG_AO_GATE(uart1, 3);
  52. AXG_AO_GATE(uart2, 5);
  53. AXG_AO_GATE(ir_blaster, 6);
  54. AXG_AO_GATE(saradc, 7);
  55. static struct clk_regmap axg_aoclk_cts_oscin = {
  56. .data = &(struct clk_regmap_gate_data){
  57. .offset = AO_RTI_PWR_CNTL_REG0,
  58. .bit_idx = 14,
  59. },
  60. .hw.init = &(struct clk_init_data){
  61. .name = "cts_oscin",
  62. .ops = &clk_regmap_gate_ro_ops,
  63. .parent_data = &(const struct clk_parent_data) {
  64. .fw_name = "xtal",
  65. },
  66. .num_parents = 1,
  67. },
  68. };
  69. static struct clk_regmap axg_aoclk_32k_pre = {
  70. .data = &(struct clk_regmap_gate_data){
  71. .offset = AO_RTC_ALT_CLK_CNTL0,
  72. .bit_idx = 31,
  73. },
  74. .hw.init = &(struct clk_init_data){
  75. .name = "axg_ao_32k_pre",
  76. .ops = &clk_regmap_gate_ops,
  77. .parent_hws = (const struct clk_hw *[]) {
  78. &axg_aoclk_cts_oscin.hw
  79. },
  80. .num_parents = 1,
  81. },
  82. };
  83. static const struct meson_clk_dualdiv_param axg_32k_div_table[] = {
  84. {
  85. .dual = 1,
  86. .n1 = 733,
  87. .m1 = 8,
  88. .n2 = 732,
  89. .m2 = 11,
  90. }, {}
  91. };
  92. static struct clk_regmap axg_aoclk_32k_div = {
  93. .data = &(struct meson_clk_dualdiv_data){
  94. .n1 = {
  95. .reg_off = AO_RTC_ALT_CLK_CNTL0,
  96. .shift = 0,
  97. .width = 12,
  98. },
  99. .n2 = {
  100. .reg_off = AO_RTC_ALT_CLK_CNTL0,
  101. .shift = 12,
  102. .width = 12,
  103. },
  104. .m1 = {
  105. .reg_off = AO_RTC_ALT_CLK_CNTL1,
  106. .shift = 0,
  107. .width = 12,
  108. },
  109. .m2 = {
  110. .reg_off = AO_RTC_ALT_CLK_CNTL1,
  111. .shift = 12,
  112. .width = 12,
  113. },
  114. .dual = {
  115. .reg_off = AO_RTC_ALT_CLK_CNTL0,
  116. .shift = 28,
  117. .width = 1,
  118. },
  119. .table = axg_32k_div_table,
  120. },
  121. .hw.init = &(struct clk_init_data){
  122. .name = "axg_ao_32k_div",
  123. .ops = &meson_clk_dualdiv_ops,
  124. .parent_hws = (const struct clk_hw *[]) {
  125. &axg_aoclk_32k_pre.hw
  126. },
  127. .num_parents = 1,
  128. },
  129. };
  130. static struct clk_regmap axg_aoclk_32k_sel = {
  131. .data = &(struct clk_regmap_mux_data) {
  132. .offset = AO_RTC_ALT_CLK_CNTL1,
  133. .mask = 0x1,
  134. .shift = 24,
  135. .flags = CLK_MUX_ROUND_CLOSEST,
  136. },
  137. .hw.init = &(struct clk_init_data){
  138. .name = "axg_ao_32k_sel",
  139. .ops = &clk_regmap_mux_ops,
  140. .parent_hws = (const struct clk_hw *[]) {
  141. &axg_aoclk_32k_div.hw,
  142. &axg_aoclk_32k_pre.hw,
  143. },
  144. .num_parents = 2,
  145. .flags = CLK_SET_RATE_PARENT,
  146. },
  147. };
  148. static struct clk_regmap axg_aoclk_32k = {
  149. .data = &(struct clk_regmap_gate_data){
  150. .offset = AO_RTC_ALT_CLK_CNTL0,
  151. .bit_idx = 30,
  152. },
  153. .hw.init = &(struct clk_init_data){
  154. .name = "axg_ao_32k",
  155. .ops = &clk_regmap_gate_ops,
  156. .parent_hws = (const struct clk_hw *[]) {
  157. &axg_aoclk_32k_sel.hw
  158. },
  159. .num_parents = 1,
  160. .flags = CLK_SET_RATE_PARENT,
  161. },
  162. };
  163. static struct clk_regmap axg_aoclk_cts_rtc_oscin = {
  164. .data = &(struct clk_regmap_mux_data) {
  165. .offset = AO_RTI_PWR_CNTL_REG0,
  166. .mask = 0x1,
  167. .shift = 10,
  168. .flags = CLK_MUX_ROUND_CLOSEST,
  169. },
  170. .hw.init = &(struct clk_init_data){
  171. .name = "axg_ao_cts_rtc_oscin",
  172. .ops = &clk_regmap_mux_ops,
  173. .parent_data = (const struct clk_parent_data []) {
  174. { .hw = &axg_aoclk_32k.hw },
  175. { .fw_name = "ext_32k-0", },
  176. },
  177. .num_parents = 2,
  178. .flags = CLK_SET_RATE_PARENT,
  179. },
  180. };
  181. static struct clk_regmap axg_aoclk_clk81 = {
  182. .data = &(struct clk_regmap_mux_data) {
  183. .offset = AO_RTI_PWR_CNTL_REG0,
  184. .mask = 0x1,
  185. .shift = 8,
  186. .flags = CLK_MUX_ROUND_CLOSEST,
  187. },
  188. .hw.init = &(struct clk_init_data){
  189. .name = "axg_ao_clk81",
  190. .ops = &clk_regmap_mux_ro_ops,
  191. .parent_data = (const struct clk_parent_data []) {
  192. { .fw_name = "mpeg-clk", },
  193. { .hw = &axg_aoclk_cts_rtc_oscin.hw },
  194. },
  195. .num_parents = 2,
  196. .flags = CLK_SET_RATE_PARENT,
  197. },
  198. };
  199. static struct clk_regmap axg_aoclk_saradc_mux = {
  200. .data = &(struct clk_regmap_mux_data) {
  201. .offset = AO_SAR_CLK,
  202. .mask = 0x3,
  203. .shift = 9,
  204. },
  205. .hw.init = &(struct clk_init_data){
  206. .name = "axg_ao_saradc_mux",
  207. .ops = &clk_regmap_mux_ops,
  208. .parent_data = (const struct clk_parent_data []) {
  209. { .fw_name = "xtal", },
  210. { .hw = &axg_aoclk_clk81.hw },
  211. },
  212. .num_parents = 2,
  213. },
  214. };
  215. static struct clk_regmap axg_aoclk_saradc_div = {
  216. .data = &(struct clk_regmap_div_data) {
  217. .offset = AO_SAR_CLK,
  218. .shift = 0,
  219. .width = 8,
  220. },
  221. .hw.init = &(struct clk_init_data){
  222. .name = "axg_ao_saradc_div",
  223. .ops = &clk_regmap_divider_ops,
  224. .parent_hws = (const struct clk_hw *[]) {
  225. &axg_aoclk_saradc_mux.hw
  226. },
  227. .num_parents = 1,
  228. .flags = CLK_SET_RATE_PARENT,
  229. },
  230. };
  231. static struct clk_regmap axg_aoclk_saradc_gate = {
  232. .data = &(struct clk_regmap_gate_data) {
  233. .offset = AO_SAR_CLK,
  234. .bit_idx = 8,
  235. },
  236. .hw.init = &(struct clk_init_data){
  237. .name = "axg_ao_saradc_gate",
  238. .ops = &clk_regmap_gate_ops,
  239. .parent_hws = (const struct clk_hw *[]) {
  240. &axg_aoclk_saradc_div.hw
  241. },
  242. .num_parents = 1,
  243. .flags = CLK_SET_RATE_PARENT,
  244. },
  245. };
  246. static const unsigned int axg_aoclk_reset[] = {
  247. [RESET_AO_REMOTE] = 16,
  248. [RESET_AO_I2C_MASTER] = 18,
  249. [RESET_AO_I2C_SLAVE] = 19,
  250. [RESET_AO_UART1] = 17,
  251. [RESET_AO_UART2] = 22,
  252. [RESET_AO_IR_BLASTER] = 23,
  253. };
  254. static struct clk_regmap *axg_aoclk_regmap[] = {
  255. &axg_aoclk_remote,
  256. &axg_aoclk_i2c_master,
  257. &axg_aoclk_i2c_slave,
  258. &axg_aoclk_uart1,
  259. &axg_aoclk_uart2,
  260. &axg_aoclk_ir_blaster,
  261. &axg_aoclk_saradc,
  262. &axg_aoclk_cts_oscin,
  263. &axg_aoclk_32k_pre,
  264. &axg_aoclk_32k_div,
  265. &axg_aoclk_32k_sel,
  266. &axg_aoclk_32k,
  267. &axg_aoclk_cts_rtc_oscin,
  268. &axg_aoclk_clk81,
  269. &axg_aoclk_saradc_mux,
  270. &axg_aoclk_saradc_div,
  271. &axg_aoclk_saradc_gate,
  272. };
  273. static const struct clk_hw_onecell_data axg_aoclk_onecell_data = {
  274. .hws = {
  275. [CLKID_AO_REMOTE] = &axg_aoclk_remote.hw,
  276. [CLKID_AO_I2C_MASTER] = &axg_aoclk_i2c_master.hw,
  277. [CLKID_AO_I2C_SLAVE] = &axg_aoclk_i2c_slave.hw,
  278. [CLKID_AO_UART1] = &axg_aoclk_uart1.hw,
  279. [CLKID_AO_UART2] = &axg_aoclk_uart2.hw,
  280. [CLKID_AO_IR_BLASTER] = &axg_aoclk_ir_blaster.hw,
  281. [CLKID_AO_SAR_ADC] = &axg_aoclk_saradc.hw,
  282. [CLKID_AO_CLK81] = &axg_aoclk_clk81.hw,
  283. [CLKID_AO_SAR_ADC_SEL] = &axg_aoclk_saradc_mux.hw,
  284. [CLKID_AO_SAR_ADC_DIV] = &axg_aoclk_saradc_div.hw,
  285. [CLKID_AO_SAR_ADC_CLK] = &axg_aoclk_saradc_gate.hw,
  286. [CLKID_AO_CTS_OSCIN] = &axg_aoclk_cts_oscin.hw,
  287. [CLKID_AO_32K_PRE] = &axg_aoclk_32k_pre.hw,
  288. [CLKID_AO_32K_DIV] = &axg_aoclk_32k_div.hw,
  289. [CLKID_AO_32K_SEL] = &axg_aoclk_32k_sel.hw,
  290. [CLKID_AO_32K] = &axg_aoclk_32k.hw,
  291. [CLKID_AO_CTS_RTC_OSCIN] = &axg_aoclk_cts_rtc_oscin.hw,
  292. },
  293. .num = NR_CLKS,
  294. };
  295. static const struct meson_aoclk_data axg_aoclkc_data = {
  296. .reset_reg = AO_RTI_GEN_CNTL_REG0,
  297. .num_reset = ARRAY_SIZE(axg_aoclk_reset),
  298. .reset = axg_aoclk_reset,
  299. .num_clks = ARRAY_SIZE(axg_aoclk_regmap),
  300. .clks = axg_aoclk_regmap,
  301. .hw_data = &axg_aoclk_onecell_data,
  302. };
  303. static const struct of_device_id axg_aoclkc_match_table[] = {
  304. {
  305. .compatible = "amlogic,meson-axg-aoclkc",
  306. .data = &axg_aoclkc_data,
  307. },
  308. { }
  309. };
  310. MODULE_DEVICE_TABLE(of, axg_aoclkc_match_table);
  311. static struct platform_driver axg_aoclkc_driver = {
  312. .probe = meson_aoclkc_probe,
  313. .driver = {
  314. .name = "axg-aoclkc",
  315. .of_match_table = axg_aoclkc_match_table,
  316. },
  317. };
  318. module_platform_driver(axg_aoclkc_driver);
  319. MODULE_LICENSE("GPL v2");