meson8b.c 23 KB

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