meson8b.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * AmLogic S802 (Meson8) / S805 (Meson8b) / S812 (Meson8m2) Clock Controller
  3. * Driver
  4. *
  5. * Copyright (c) 2015 Endless Mobile, Inc.
  6. * Author: Carlo Caione <carlo@endlessm.com>
  7. *
  8. * Copyright (c) 2016 BayLibre, Inc.
  9. * Michael Turquette <mturquette@baylibre.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms and conditions of the GNU General Public License,
  13. * version 2, as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  18. * more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along with
  21. * this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. #include <linux/clk.h>
  24. #include <linux/clk-provider.h>
  25. #include <linux/of_address.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/init.h>
  28. #include "clkc.h"
  29. #include "meson8b.h"
  30. static DEFINE_SPINLOCK(clk_lock);
  31. static const struct pll_rate_table sys_pll_rate_table[] = {
  32. PLL_RATE(312000000, 52, 1, 2),
  33. PLL_RATE(336000000, 56, 1, 2),
  34. PLL_RATE(360000000, 60, 1, 2),
  35. PLL_RATE(384000000, 64, 1, 2),
  36. PLL_RATE(408000000, 68, 1, 2),
  37. PLL_RATE(432000000, 72, 1, 2),
  38. PLL_RATE(456000000, 76, 1, 2),
  39. PLL_RATE(480000000, 80, 1, 2),
  40. PLL_RATE(504000000, 84, 1, 2),
  41. PLL_RATE(528000000, 88, 1, 2),
  42. PLL_RATE(552000000, 92, 1, 2),
  43. PLL_RATE(576000000, 96, 1, 2),
  44. PLL_RATE(600000000, 50, 1, 1),
  45. PLL_RATE(624000000, 52, 1, 1),
  46. PLL_RATE(648000000, 54, 1, 1),
  47. PLL_RATE(672000000, 56, 1, 1),
  48. PLL_RATE(696000000, 58, 1, 1),
  49. PLL_RATE(720000000, 60, 1, 1),
  50. PLL_RATE(744000000, 62, 1, 1),
  51. PLL_RATE(768000000, 64, 1, 1),
  52. PLL_RATE(792000000, 66, 1, 1),
  53. PLL_RATE(816000000, 68, 1, 1),
  54. PLL_RATE(840000000, 70, 1, 1),
  55. PLL_RATE(864000000, 72, 1, 1),
  56. PLL_RATE(888000000, 74, 1, 1),
  57. PLL_RATE(912000000, 76, 1, 1),
  58. PLL_RATE(936000000, 78, 1, 1),
  59. PLL_RATE(960000000, 80, 1, 1),
  60. PLL_RATE(984000000, 82, 1, 1),
  61. PLL_RATE(1008000000, 84, 1, 1),
  62. PLL_RATE(1032000000, 86, 1, 1),
  63. PLL_RATE(1056000000, 88, 1, 1),
  64. PLL_RATE(1080000000, 90, 1, 1),
  65. PLL_RATE(1104000000, 92, 1, 1),
  66. PLL_RATE(1128000000, 94, 1, 1),
  67. PLL_RATE(1152000000, 96, 1, 1),
  68. PLL_RATE(1176000000, 98, 1, 1),
  69. PLL_RATE(1200000000, 50, 1, 0),
  70. PLL_RATE(1224000000, 51, 1, 0),
  71. PLL_RATE(1248000000, 52, 1, 0),
  72. PLL_RATE(1272000000, 53, 1, 0),
  73. PLL_RATE(1296000000, 54, 1, 0),
  74. PLL_RATE(1320000000, 55, 1, 0),
  75. PLL_RATE(1344000000, 56, 1, 0),
  76. PLL_RATE(1368000000, 57, 1, 0),
  77. PLL_RATE(1392000000, 58, 1, 0),
  78. PLL_RATE(1416000000, 59, 1, 0),
  79. PLL_RATE(1440000000, 60, 1, 0),
  80. PLL_RATE(1464000000, 61, 1, 0),
  81. PLL_RATE(1488000000, 62, 1, 0),
  82. PLL_RATE(1512000000, 63, 1, 0),
  83. PLL_RATE(1536000000, 64, 1, 0),
  84. { /* sentinel */ },
  85. };
  86. static const struct clk_div_table cpu_div_table[] = {
  87. { .val = 1, .div = 1 },
  88. { .val = 2, .div = 2 },
  89. { .val = 3, .div = 3 },
  90. { .val = 2, .div = 4 },
  91. { .val = 3, .div = 6 },
  92. { .val = 4, .div = 8 },
  93. { .val = 5, .div = 10 },
  94. { .val = 6, .div = 12 },
  95. { .val = 7, .div = 14 },
  96. { .val = 8, .div = 16 },
  97. { /* sentinel */ },
  98. };
  99. static struct clk_fixed_rate meson8b_xtal = {
  100. .fixed_rate = 24000000,
  101. .hw.init = &(struct clk_init_data){
  102. .name = "xtal",
  103. .num_parents = 0,
  104. .ops = &clk_fixed_rate_ops,
  105. },
  106. };
  107. static struct meson_clk_pll meson8b_fixed_pll = {
  108. .m = {
  109. .reg_off = HHI_MPLL_CNTL,
  110. .shift = 0,
  111. .width = 9,
  112. },
  113. .n = {
  114. .reg_off = HHI_MPLL_CNTL,
  115. .shift = 9,
  116. .width = 5,
  117. },
  118. .od = {
  119. .reg_off = HHI_MPLL_CNTL,
  120. .shift = 16,
  121. .width = 2,
  122. },
  123. .lock = &clk_lock,
  124. .hw.init = &(struct clk_init_data){
  125. .name = "fixed_pll",
  126. .ops = &meson_clk_pll_ro_ops,
  127. .parent_names = (const char *[]){ "xtal" },
  128. .num_parents = 1,
  129. .flags = CLK_GET_RATE_NOCACHE,
  130. },
  131. };
  132. static struct meson_clk_pll meson8b_vid_pll = {
  133. .m = {
  134. .reg_off = HHI_VID_PLL_CNTL,
  135. .shift = 0,
  136. .width = 9,
  137. },
  138. .n = {
  139. .reg_off = HHI_VID_PLL_CNTL,
  140. .shift = 9,
  141. .width = 5,
  142. },
  143. .od = {
  144. .reg_off = HHI_VID_PLL_CNTL,
  145. .shift = 16,
  146. .width = 2,
  147. },
  148. .lock = &clk_lock,
  149. .hw.init = &(struct clk_init_data){
  150. .name = "vid_pll",
  151. .ops = &meson_clk_pll_ro_ops,
  152. .parent_names = (const char *[]){ "xtal" },
  153. .num_parents = 1,
  154. .flags = CLK_GET_RATE_NOCACHE,
  155. },
  156. };
  157. static struct meson_clk_pll meson8b_sys_pll = {
  158. .m = {
  159. .reg_off = HHI_SYS_PLL_CNTL,
  160. .shift = 0,
  161. .width = 9,
  162. },
  163. .n = {
  164. .reg_off = HHI_SYS_PLL_CNTL,
  165. .shift = 9,
  166. .width = 5,
  167. },
  168. .od = {
  169. .reg_off = HHI_SYS_PLL_CNTL,
  170. .shift = 16,
  171. .width = 2,
  172. },
  173. .rate_table = sys_pll_rate_table,
  174. .rate_count = ARRAY_SIZE(sys_pll_rate_table),
  175. .lock = &clk_lock,
  176. .hw.init = &(struct clk_init_data){
  177. .name = "sys_pll",
  178. .ops = &meson_clk_pll_ops,
  179. .parent_names = (const char *[]){ "xtal" },
  180. .num_parents = 1,
  181. .flags = CLK_GET_RATE_NOCACHE,
  182. },
  183. };
  184. static struct clk_fixed_factor meson8b_fclk_div2 = {
  185. .mult = 1,
  186. .div = 2,
  187. .hw.init = &(struct clk_init_data){
  188. .name = "fclk_div2",
  189. .ops = &clk_fixed_factor_ops,
  190. .parent_names = (const char *[]){ "fixed_pll" },
  191. .num_parents = 1,
  192. },
  193. };
  194. static struct clk_fixed_factor meson8b_fclk_div3 = {
  195. .mult = 1,
  196. .div = 3,
  197. .hw.init = &(struct clk_init_data){
  198. .name = "fclk_div3",
  199. .ops = &clk_fixed_factor_ops,
  200. .parent_names = (const char *[]){ "fixed_pll" },
  201. .num_parents = 1,
  202. },
  203. };
  204. static struct clk_fixed_factor meson8b_fclk_div4 = {
  205. .mult = 1,
  206. .div = 4,
  207. .hw.init = &(struct clk_init_data){
  208. .name = "fclk_div4",
  209. .ops = &clk_fixed_factor_ops,
  210. .parent_names = (const char *[]){ "fixed_pll" },
  211. .num_parents = 1,
  212. },
  213. };
  214. static struct clk_fixed_factor meson8b_fclk_div5 = {
  215. .mult = 1,
  216. .div = 5,
  217. .hw.init = &(struct clk_init_data){
  218. .name = "fclk_div5",
  219. .ops = &clk_fixed_factor_ops,
  220. .parent_names = (const char *[]){ "fixed_pll" },
  221. .num_parents = 1,
  222. },
  223. };
  224. static struct clk_fixed_factor meson8b_fclk_div7 = {
  225. .mult = 1,
  226. .div = 7,
  227. .hw.init = &(struct clk_init_data){
  228. .name = "fclk_div7",
  229. .ops = &clk_fixed_factor_ops,
  230. .parent_names = (const char *[]){ "fixed_pll" },
  231. .num_parents = 1,
  232. },
  233. };
  234. /*
  235. * FIXME cpu clocks and the legacy composite clocks (e.g. clk81) are both PLL
  236. * post-dividers and should be modeled with their respective PLLs via the
  237. * forthcoming coordinated clock rates feature
  238. */
  239. static struct meson_clk_cpu meson8b_cpu_clk = {
  240. .reg_off = HHI_SYS_CPU_CLK_CNTL1,
  241. .div_table = cpu_div_table,
  242. .clk_nb.notifier_call = meson_clk_cpu_notifier_cb,
  243. .hw.init = &(struct clk_init_data){
  244. .name = "cpu_clk",
  245. .ops = &meson_clk_cpu_ops,
  246. .parent_names = (const char *[]){ "sys_pll" },
  247. .num_parents = 1,
  248. },
  249. };
  250. static u32 mux_table_clk81[] = { 6, 5, 7 };
  251. struct clk_mux meson8b_mpeg_clk_sel = {
  252. .reg = (void *)HHI_MPEG_CLK_CNTL,
  253. .mask = 0x7,
  254. .shift = 12,
  255. .flags = CLK_MUX_READ_ONLY,
  256. .table = mux_table_clk81,
  257. .lock = &clk_lock,
  258. .hw.init = &(struct clk_init_data){
  259. .name = "mpeg_clk_sel",
  260. .ops = &clk_mux_ro_ops,
  261. /*
  262. * FIXME bits 14:12 selects from 8 possible parents:
  263. * xtal, 1'b0 (wtf), fclk_div7, mpll_clkout1, mpll_clkout2,
  264. * fclk_div4, fclk_div3, fclk_div5
  265. */
  266. .parent_names = (const char *[]){ "fclk_div3", "fclk_div4",
  267. "fclk_div5" },
  268. .num_parents = 3,
  269. .flags = (CLK_SET_RATE_NO_REPARENT | CLK_IGNORE_UNUSED),
  270. },
  271. };
  272. struct clk_divider meson8b_mpeg_clk_div = {
  273. .reg = (void *)HHI_MPEG_CLK_CNTL,
  274. .shift = 0,
  275. .width = 7,
  276. .lock = &clk_lock,
  277. .hw.init = &(struct clk_init_data){
  278. .name = "mpeg_clk_div",
  279. .ops = &clk_divider_ops,
  280. .parent_names = (const char *[]){ "mpeg_clk_sel" },
  281. .num_parents = 1,
  282. .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED),
  283. },
  284. };
  285. struct clk_gate meson8b_clk81 = {
  286. .reg = (void *)HHI_MPEG_CLK_CNTL,
  287. .bit_idx = 7,
  288. .lock = &clk_lock,
  289. .hw.init = &(struct clk_init_data){
  290. .name = "clk81",
  291. .ops = &clk_gate_ops,
  292. .parent_names = (const char *[]){ "mpeg_clk_div" },
  293. .num_parents = 1,
  294. .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED),
  295. },
  296. };
  297. /* Everything Else (EE) domain gates */
  298. static MESON_GATE(meson8b_ddr, HHI_GCLK_MPEG0, 0);
  299. static MESON_GATE(meson8b_dos, HHI_GCLK_MPEG0, 1);
  300. static MESON_GATE(meson8b_isa, HHI_GCLK_MPEG0, 5);
  301. static MESON_GATE(meson8b_pl301, HHI_GCLK_MPEG0, 6);
  302. static MESON_GATE(meson8b_periphs, HHI_GCLK_MPEG0, 7);
  303. static MESON_GATE(meson8b_spicc, HHI_GCLK_MPEG0, 8);
  304. static MESON_GATE(meson8b_i2c, HHI_GCLK_MPEG0, 9);
  305. static MESON_GATE(meson8b_sar_adc, HHI_GCLK_MPEG0, 10);
  306. static MESON_GATE(meson8b_smart_card, HHI_GCLK_MPEG0, 11);
  307. static MESON_GATE(meson8b_rng0, HHI_GCLK_MPEG0, 12);
  308. static MESON_GATE(meson8b_uart0, HHI_GCLK_MPEG0, 13);
  309. static MESON_GATE(meson8b_sdhc, HHI_GCLK_MPEG0, 14);
  310. static MESON_GATE(meson8b_stream, HHI_GCLK_MPEG0, 15);
  311. static MESON_GATE(meson8b_async_fifo, HHI_GCLK_MPEG0, 16);
  312. static MESON_GATE(meson8b_sdio, HHI_GCLK_MPEG0, 17);
  313. static MESON_GATE(meson8b_abuf, HHI_GCLK_MPEG0, 18);
  314. static MESON_GATE(meson8b_hiu_iface, HHI_GCLK_MPEG0, 19);
  315. static MESON_GATE(meson8b_assist_misc, HHI_GCLK_MPEG0, 23);
  316. static MESON_GATE(meson8b_spi, HHI_GCLK_MPEG0, 30);
  317. static MESON_GATE(meson8b_i2s_spdif, HHI_GCLK_MPEG1, 2);
  318. static MESON_GATE(meson8b_eth, HHI_GCLK_MPEG1, 3);
  319. static MESON_GATE(meson8b_demux, HHI_GCLK_MPEG1, 4);
  320. static MESON_GATE(meson8b_aiu_glue, HHI_GCLK_MPEG1, 6);
  321. static MESON_GATE(meson8b_iec958, HHI_GCLK_MPEG1, 7);
  322. static MESON_GATE(meson8b_i2s_out, HHI_GCLK_MPEG1, 8);
  323. static MESON_GATE(meson8b_amclk, HHI_GCLK_MPEG1, 9);
  324. static MESON_GATE(meson8b_aififo2, HHI_GCLK_MPEG1, 10);
  325. static MESON_GATE(meson8b_mixer, HHI_GCLK_MPEG1, 11);
  326. static MESON_GATE(meson8b_mixer_iface, HHI_GCLK_MPEG1, 12);
  327. static MESON_GATE(meson8b_adc, HHI_GCLK_MPEG1, 13);
  328. static MESON_GATE(meson8b_blkmv, HHI_GCLK_MPEG1, 14);
  329. static MESON_GATE(meson8b_aiu, HHI_GCLK_MPEG1, 15);
  330. static MESON_GATE(meson8b_uart1, HHI_GCLK_MPEG1, 16);
  331. static MESON_GATE(meson8b_g2d, HHI_GCLK_MPEG1, 20);
  332. static MESON_GATE(meson8b_usb0, HHI_GCLK_MPEG1, 21);
  333. static MESON_GATE(meson8b_usb1, HHI_GCLK_MPEG1, 22);
  334. static MESON_GATE(meson8b_reset, HHI_GCLK_MPEG1, 23);
  335. static MESON_GATE(meson8b_nand, HHI_GCLK_MPEG1, 24);
  336. static MESON_GATE(meson8b_dos_parser, HHI_GCLK_MPEG1, 25);
  337. static MESON_GATE(meson8b_usb, HHI_GCLK_MPEG1, 26);
  338. static MESON_GATE(meson8b_vdin1, HHI_GCLK_MPEG1, 28);
  339. static MESON_GATE(meson8b_ahb_arb0, HHI_GCLK_MPEG1, 29);
  340. static MESON_GATE(meson8b_efuse, HHI_GCLK_MPEG1, 30);
  341. static MESON_GATE(meson8b_boot_rom, HHI_GCLK_MPEG1, 31);
  342. static MESON_GATE(meson8b_ahb_data_bus, HHI_GCLK_MPEG2, 1);
  343. static MESON_GATE(meson8b_ahb_ctrl_bus, HHI_GCLK_MPEG2, 2);
  344. static MESON_GATE(meson8b_hdmi_intr_sync, HHI_GCLK_MPEG2, 3);
  345. static MESON_GATE(meson8b_hdmi_pclk, HHI_GCLK_MPEG2, 4);
  346. static MESON_GATE(meson8b_usb1_ddr_bridge, HHI_GCLK_MPEG2, 8);
  347. static MESON_GATE(meson8b_usb0_ddr_bridge, HHI_GCLK_MPEG2, 9);
  348. static MESON_GATE(meson8b_mmc_pclk, HHI_GCLK_MPEG2, 11);
  349. static MESON_GATE(meson8b_dvin, HHI_GCLK_MPEG2, 12);
  350. static MESON_GATE(meson8b_uart2, HHI_GCLK_MPEG2, 15);
  351. static MESON_GATE(meson8b_sana, HHI_GCLK_MPEG2, 22);
  352. static MESON_GATE(meson8b_vpu_intr, HHI_GCLK_MPEG2, 25);
  353. static MESON_GATE(meson8b_sec_ahb_ahb3_bridge, HHI_GCLK_MPEG2, 26);
  354. static MESON_GATE(meson8b_clk81_a9, HHI_GCLK_MPEG2, 29);
  355. static MESON_GATE(meson8b_vclk2_venci0, HHI_GCLK_OTHER, 1);
  356. static MESON_GATE(meson8b_vclk2_venci1, HHI_GCLK_OTHER, 2);
  357. static MESON_GATE(meson8b_vclk2_vencp0, HHI_GCLK_OTHER, 3);
  358. static MESON_GATE(meson8b_vclk2_vencp1, HHI_GCLK_OTHER, 4);
  359. static MESON_GATE(meson8b_gclk_venci_int, HHI_GCLK_OTHER, 8);
  360. static MESON_GATE(meson8b_gclk_vencp_int, HHI_GCLK_OTHER, 9);
  361. static MESON_GATE(meson8b_dac_clk, HHI_GCLK_OTHER, 10);
  362. static MESON_GATE(meson8b_aoclk_gate, HHI_GCLK_OTHER, 14);
  363. static MESON_GATE(meson8b_iec958_gate, HHI_GCLK_OTHER, 16);
  364. static MESON_GATE(meson8b_enc480p, HHI_GCLK_OTHER, 20);
  365. static MESON_GATE(meson8b_rng1, HHI_GCLK_OTHER, 21);
  366. static MESON_GATE(meson8b_gclk_vencl_int, HHI_GCLK_OTHER, 22);
  367. static MESON_GATE(meson8b_vclk2_venclmcc, HHI_GCLK_OTHER, 24);
  368. static MESON_GATE(meson8b_vclk2_vencl, HHI_GCLK_OTHER, 25);
  369. static MESON_GATE(meson8b_vclk2_other, HHI_GCLK_OTHER, 26);
  370. static MESON_GATE(meson8b_edp, HHI_GCLK_OTHER, 31);
  371. /* Always On (AO) domain gates */
  372. static MESON_GATE(meson8b_ao_media_cpu, HHI_GCLK_AO, 0);
  373. static MESON_GATE(meson8b_ao_ahb_sram, HHI_GCLK_AO, 1);
  374. static MESON_GATE(meson8b_ao_ahb_bus, HHI_GCLK_AO, 2);
  375. static MESON_GATE(meson8b_ao_iface, HHI_GCLK_AO, 3);
  376. static struct clk_hw_onecell_data meson8b_hw_onecell_data = {
  377. .hws = {
  378. [CLKID_XTAL] = &meson8b_xtal.hw,
  379. [CLKID_PLL_FIXED] = &meson8b_fixed_pll.hw,
  380. [CLKID_PLL_VID] = &meson8b_vid_pll.hw,
  381. [CLKID_PLL_SYS] = &meson8b_sys_pll.hw,
  382. [CLKID_FCLK_DIV2] = &meson8b_fclk_div2.hw,
  383. [CLKID_FCLK_DIV3] = &meson8b_fclk_div3.hw,
  384. [CLKID_FCLK_DIV4] = &meson8b_fclk_div4.hw,
  385. [CLKID_FCLK_DIV5] = &meson8b_fclk_div5.hw,
  386. [CLKID_FCLK_DIV7] = &meson8b_fclk_div7.hw,
  387. [CLKID_CPUCLK] = &meson8b_cpu_clk.hw,
  388. [CLKID_MPEG_SEL] = &meson8b_mpeg_clk_sel.hw,
  389. [CLKID_MPEG_DIV] = &meson8b_mpeg_clk_div.hw,
  390. [CLKID_CLK81] = &meson8b_clk81.hw,
  391. [CLKID_DDR] = &meson8b_ddr.hw,
  392. [CLKID_DOS] = &meson8b_dos.hw,
  393. [CLKID_ISA] = &meson8b_isa.hw,
  394. [CLKID_PL301] = &meson8b_pl301.hw,
  395. [CLKID_PERIPHS] = &meson8b_periphs.hw,
  396. [CLKID_SPICC] = &meson8b_spicc.hw,
  397. [CLKID_I2C] = &meson8b_i2c.hw,
  398. [CLKID_SAR_ADC] = &meson8b_sar_adc.hw,
  399. [CLKID_SMART_CARD] = &meson8b_smart_card.hw,
  400. [CLKID_RNG0] = &meson8b_rng0.hw,
  401. [CLKID_UART0] = &meson8b_uart0.hw,
  402. [CLKID_SDHC] = &meson8b_sdhc.hw,
  403. [CLKID_STREAM] = &meson8b_stream.hw,
  404. [CLKID_ASYNC_FIFO] = &meson8b_async_fifo.hw,
  405. [CLKID_SDIO] = &meson8b_sdio.hw,
  406. [CLKID_ABUF] = &meson8b_abuf.hw,
  407. [CLKID_HIU_IFACE] = &meson8b_hiu_iface.hw,
  408. [CLKID_ASSIST_MISC] = &meson8b_assist_misc.hw,
  409. [CLKID_SPI] = &meson8b_spi.hw,
  410. [CLKID_I2S_SPDIF] = &meson8b_i2s_spdif.hw,
  411. [CLKID_ETH] = &meson8b_eth.hw,
  412. [CLKID_DEMUX] = &meson8b_demux.hw,
  413. [CLKID_AIU_GLUE] = &meson8b_aiu_glue.hw,
  414. [CLKID_IEC958] = &meson8b_iec958.hw,
  415. [CLKID_I2S_OUT] = &meson8b_i2s_out.hw,
  416. [CLKID_AMCLK] = &meson8b_amclk.hw,
  417. [CLKID_AIFIFO2] = &meson8b_aififo2.hw,
  418. [CLKID_MIXER] = &meson8b_mixer.hw,
  419. [CLKID_MIXER_IFACE] = &meson8b_mixer_iface.hw,
  420. [CLKID_ADC] = &meson8b_adc.hw,
  421. [CLKID_BLKMV] = &meson8b_blkmv.hw,
  422. [CLKID_AIU] = &meson8b_aiu.hw,
  423. [CLKID_UART1] = &meson8b_uart1.hw,
  424. [CLKID_G2D] = &meson8b_g2d.hw,
  425. [CLKID_USB0] = &meson8b_usb0.hw,
  426. [CLKID_USB1] = &meson8b_usb1.hw,
  427. [CLKID_RESET] = &meson8b_reset.hw,
  428. [CLKID_NAND] = &meson8b_nand.hw,
  429. [CLKID_DOS_PARSER] = &meson8b_dos_parser.hw,
  430. [CLKID_USB] = &meson8b_usb.hw,
  431. [CLKID_VDIN1] = &meson8b_vdin1.hw,
  432. [CLKID_AHB_ARB0] = &meson8b_ahb_arb0.hw,
  433. [CLKID_EFUSE] = &meson8b_efuse.hw,
  434. [CLKID_BOOT_ROM] = &meson8b_boot_rom.hw,
  435. [CLKID_AHB_DATA_BUS] = &meson8b_ahb_data_bus.hw,
  436. [CLKID_AHB_CTRL_BUS] = &meson8b_ahb_ctrl_bus.hw,
  437. [CLKID_HDMI_INTR_SYNC] = &meson8b_hdmi_intr_sync.hw,
  438. [CLKID_HDMI_PCLK] = &meson8b_hdmi_pclk.hw,
  439. [CLKID_USB1_DDR_BRIDGE] = &meson8b_usb1_ddr_bridge.hw,
  440. [CLKID_USB0_DDR_BRIDGE] = &meson8b_usb0_ddr_bridge.hw,
  441. [CLKID_MMC_PCLK] = &meson8b_mmc_pclk.hw,
  442. [CLKID_DVIN] = &meson8b_dvin.hw,
  443. [CLKID_UART2] = &meson8b_uart2.hw,
  444. [CLKID_SANA] = &meson8b_sana.hw,
  445. [CLKID_VPU_INTR] = &meson8b_vpu_intr.hw,
  446. [CLKID_SEC_AHB_AHB3_BRIDGE] = &meson8b_sec_ahb_ahb3_bridge.hw,
  447. [CLKID_CLK81_A9] = &meson8b_clk81_a9.hw,
  448. [CLKID_VCLK2_VENCI0] = &meson8b_vclk2_venci0.hw,
  449. [CLKID_VCLK2_VENCI1] = &meson8b_vclk2_venci1.hw,
  450. [CLKID_VCLK2_VENCP0] = &meson8b_vclk2_vencp0.hw,
  451. [CLKID_VCLK2_VENCP1] = &meson8b_vclk2_vencp1.hw,
  452. [CLKID_GCLK_VENCI_INT] = &meson8b_gclk_venci_int.hw,
  453. [CLKID_GCLK_VENCP_INT] = &meson8b_gclk_vencp_int.hw,
  454. [CLKID_DAC_CLK] = &meson8b_dac_clk.hw,
  455. [CLKID_AOCLK_GATE] = &meson8b_aoclk_gate.hw,
  456. [CLKID_IEC958_GATE] = &meson8b_iec958_gate.hw,
  457. [CLKID_ENC480P] = &meson8b_enc480p.hw,
  458. [CLKID_RNG1] = &meson8b_rng1.hw,
  459. [CLKID_GCLK_VENCL_INT] = &meson8b_gclk_vencl_int.hw,
  460. [CLKID_VCLK2_VENCLMCC] = &meson8b_vclk2_venclmcc.hw,
  461. [CLKID_VCLK2_VENCL] = &meson8b_vclk2_vencl.hw,
  462. [CLKID_VCLK2_OTHER] = &meson8b_vclk2_other.hw,
  463. [CLKID_EDP] = &meson8b_edp.hw,
  464. [CLKID_AO_MEDIA_CPU] = &meson8b_ao_media_cpu.hw,
  465. [CLKID_AO_AHB_SRAM] = &meson8b_ao_ahb_sram.hw,
  466. [CLKID_AO_AHB_BUS] = &meson8b_ao_ahb_bus.hw,
  467. [CLKID_AO_IFACE] = &meson8b_ao_iface.hw,
  468. },
  469. .num = CLK_NR_CLKS,
  470. };
  471. static struct meson_clk_pll *const meson8b_clk_plls[] = {
  472. &meson8b_fixed_pll,
  473. &meson8b_vid_pll,
  474. &meson8b_sys_pll,
  475. };
  476. static struct clk_gate *meson8b_clk_gates[] = {
  477. &meson8b_clk81,
  478. &meson8b_ddr,
  479. &meson8b_dos,
  480. &meson8b_isa,
  481. &meson8b_pl301,
  482. &meson8b_periphs,
  483. &meson8b_spicc,
  484. &meson8b_i2c,
  485. &meson8b_sar_adc,
  486. &meson8b_smart_card,
  487. &meson8b_rng0,
  488. &meson8b_uart0,
  489. &meson8b_sdhc,
  490. &meson8b_stream,
  491. &meson8b_async_fifo,
  492. &meson8b_sdio,
  493. &meson8b_abuf,
  494. &meson8b_hiu_iface,
  495. &meson8b_assist_misc,
  496. &meson8b_spi,
  497. &meson8b_i2s_spdif,
  498. &meson8b_eth,
  499. &meson8b_demux,
  500. &meson8b_aiu_glue,
  501. &meson8b_iec958,
  502. &meson8b_i2s_out,
  503. &meson8b_amclk,
  504. &meson8b_aififo2,
  505. &meson8b_mixer,
  506. &meson8b_mixer_iface,
  507. &meson8b_adc,
  508. &meson8b_blkmv,
  509. &meson8b_aiu,
  510. &meson8b_uart1,
  511. &meson8b_g2d,
  512. &meson8b_usb0,
  513. &meson8b_usb1,
  514. &meson8b_reset,
  515. &meson8b_nand,
  516. &meson8b_dos_parser,
  517. &meson8b_usb,
  518. &meson8b_vdin1,
  519. &meson8b_ahb_arb0,
  520. &meson8b_efuse,
  521. &meson8b_boot_rom,
  522. &meson8b_ahb_data_bus,
  523. &meson8b_ahb_ctrl_bus,
  524. &meson8b_hdmi_intr_sync,
  525. &meson8b_hdmi_pclk,
  526. &meson8b_usb1_ddr_bridge,
  527. &meson8b_usb0_ddr_bridge,
  528. &meson8b_mmc_pclk,
  529. &meson8b_dvin,
  530. &meson8b_uart2,
  531. &meson8b_sana,
  532. &meson8b_vpu_intr,
  533. &meson8b_sec_ahb_ahb3_bridge,
  534. &meson8b_clk81_a9,
  535. &meson8b_vclk2_venci0,
  536. &meson8b_vclk2_venci1,
  537. &meson8b_vclk2_vencp0,
  538. &meson8b_vclk2_vencp1,
  539. &meson8b_gclk_venci_int,
  540. &meson8b_gclk_vencp_int,
  541. &meson8b_dac_clk,
  542. &meson8b_aoclk_gate,
  543. &meson8b_iec958_gate,
  544. &meson8b_enc480p,
  545. &meson8b_rng1,
  546. &meson8b_gclk_vencl_int,
  547. &meson8b_vclk2_venclmcc,
  548. &meson8b_vclk2_vencl,
  549. &meson8b_vclk2_other,
  550. &meson8b_edp,
  551. &meson8b_ao_media_cpu,
  552. &meson8b_ao_ahb_sram,
  553. &meson8b_ao_ahb_bus,
  554. &meson8b_ao_iface,
  555. };
  556. static int meson8b_clkc_probe(struct platform_device *pdev)
  557. {
  558. void __iomem *clk_base;
  559. int ret, clkid, i;
  560. struct clk_hw *parent_hw;
  561. struct clk *parent_clk;
  562. struct device *dev = &pdev->dev;
  563. /* Generic clocks and PLLs */
  564. clk_base = of_iomap(dev->of_node, 1);
  565. if (!clk_base) {
  566. pr_err("%s: Unable to map clk base\n", __func__);
  567. return -ENXIO;
  568. }
  569. /* Populate base address for PLLs */
  570. for (i = 0; i < ARRAY_SIZE(meson8b_clk_plls); i++)
  571. meson8b_clk_plls[i]->base = clk_base;
  572. /* Populate the base address for CPU clk */
  573. meson8b_cpu_clk.base = clk_base;
  574. /* Populate the base address for the MPEG clks */
  575. meson8b_mpeg_clk_sel.reg = clk_base + (u32)meson8b_mpeg_clk_sel.reg;
  576. meson8b_mpeg_clk_div.reg = clk_base + (u32)meson8b_mpeg_clk_div.reg;
  577. meson8b_clk81.reg = clk_base + (u32)meson8b_clk81.reg;
  578. /* Populate base address for gates */
  579. for (i = 0; i < ARRAY_SIZE(meson8b_clk_gates); i++)
  580. meson8b_clk_gates[i]->reg = clk_base +
  581. (u32)meson8b_clk_gates[i]->reg;
  582. /*
  583. * register all clks
  584. * CLKID_UNUSED = 0, so skip it and start with CLKID_XTAL = 1
  585. */
  586. for (clkid = CLKID_XTAL; clkid < CLK_NR_CLKS; clkid++) {
  587. /* array might be sparse */
  588. if (!meson8b_hw_onecell_data.hws[clkid])
  589. continue;
  590. /* FIXME convert to devm_clk_register */
  591. ret = devm_clk_hw_register(dev, meson8b_hw_onecell_data.hws[clkid]);
  592. if (ret)
  593. goto iounmap;
  594. }
  595. /*
  596. * Register CPU clk notifier
  597. *
  598. * FIXME this is wrong for a lot of reasons. First, the muxes should be
  599. * struct clk_hw objects. Second, we shouldn't program the muxes in
  600. * notifier handlers. The tricky programming sequence will be handled
  601. * by the forthcoming coordinated clock rates mechanism once that
  602. * feature is released.
  603. *
  604. * Furthermore, looking up the parent this way is terrible. At some
  605. * point we will stop allocating a default struct clk when registering
  606. * a new clk_hw, and this hack will no longer work. Releasing the ccr
  607. * feature before that time solves the problem :-)
  608. */
  609. parent_hw = clk_hw_get_parent(&meson8b_cpu_clk.hw);
  610. parent_clk = parent_hw->clk;
  611. ret = clk_notifier_register(parent_clk, &meson8b_cpu_clk.clk_nb);
  612. if (ret) {
  613. pr_err("%s: failed to register clock notifier for cpu_clk\n",
  614. __func__);
  615. goto iounmap;
  616. }
  617. return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
  618. &meson8b_hw_onecell_data);
  619. iounmap:
  620. iounmap(clk_base);
  621. return ret;
  622. }
  623. static const struct of_device_id meson8b_clkc_match_table[] = {
  624. { .compatible = "amlogic,meson8-clkc" },
  625. { .compatible = "amlogic,meson8b-clkc" },
  626. { .compatible = "amlogic,meson8m2-clkc" },
  627. { }
  628. };
  629. static struct platform_driver meson8b_driver = {
  630. .probe = meson8b_clkc_probe,
  631. .driver = {
  632. .name = "meson8b-clkc",
  633. .of_match_table = meson8b_clkc_match_table,
  634. },
  635. };
  636. builtin_platform_driver(meson8b_driver);