gxbb.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. /*
  2. * AmLogic S905 / GXBB Clock Controller Driver
  3. *
  4. * Copyright (c) 2016 AmLogic, Inc.
  5. * Michael Turquette <mturquette@baylibre.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/clk.h>
  20. #include <linux/clk-provider.h>
  21. #include <linux/of_address.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/init.h>
  24. #include "clkc.h"
  25. #include "gxbb.h"
  26. static DEFINE_SPINLOCK(clk_lock);
  27. static const struct pll_rate_table sys_pll_rate_table[] = {
  28. PLL_RATE(24000000, 56, 1, 2),
  29. PLL_RATE(48000000, 64, 1, 2),
  30. PLL_RATE(72000000, 72, 1, 2),
  31. PLL_RATE(96000000, 64, 1, 2),
  32. PLL_RATE(120000000, 80, 1, 2),
  33. PLL_RATE(144000000, 96, 1, 2),
  34. PLL_RATE(168000000, 56, 1, 1),
  35. PLL_RATE(192000000, 64, 1, 1),
  36. PLL_RATE(216000000, 72, 1, 1),
  37. PLL_RATE(240000000, 80, 1, 1),
  38. PLL_RATE(264000000, 88, 1, 1),
  39. PLL_RATE(288000000, 96, 1, 1),
  40. PLL_RATE(312000000, 52, 1, 2),
  41. PLL_RATE(336000000, 56, 1, 2),
  42. PLL_RATE(360000000, 60, 1, 2),
  43. PLL_RATE(384000000, 64, 1, 2),
  44. PLL_RATE(408000000, 68, 1, 2),
  45. PLL_RATE(432000000, 72, 1, 2),
  46. PLL_RATE(456000000, 76, 1, 2),
  47. PLL_RATE(480000000, 80, 1, 2),
  48. PLL_RATE(504000000, 84, 1, 2),
  49. PLL_RATE(528000000, 88, 1, 2),
  50. PLL_RATE(552000000, 92, 1, 2),
  51. PLL_RATE(576000000, 96, 1, 2),
  52. PLL_RATE(600000000, 50, 1, 1),
  53. PLL_RATE(624000000, 52, 1, 1),
  54. PLL_RATE(648000000, 54, 1, 1),
  55. PLL_RATE(672000000, 56, 1, 1),
  56. PLL_RATE(696000000, 58, 1, 1),
  57. PLL_RATE(720000000, 60, 1, 1),
  58. PLL_RATE(744000000, 62, 1, 1),
  59. PLL_RATE(768000000, 64, 1, 1),
  60. PLL_RATE(792000000, 66, 1, 1),
  61. PLL_RATE(816000000, 68, 1, 1),
  62. PLL_RATE(840000000, 70, 1, 1),
  63. PLL_RATE(864000000, 72, 1, 1),
  64. PLL_RATE(888000000, 74, 1, 1),
  65. PLL_RATE(912000000, 76, 1, 1),
  66. PLL_RATE(936000000, 78, 1, 1),
  67. PLL_RATE(960000000, 80, 1, 1),
  68. PLL_RATE(984000000, 82, 1, 1),
  69. PLL_RATE(1008000000, 84, 1, 1),
  70. PLL_RATE(1032000000, 86, 1, 1),
  71. PLL_RATE(1056000000, 88, 1, 1),
  72. PLL_RATE(1080000000, 90, 1, 1),
  73. PLL_RATE(1104000000, 92, 1, 1),
  74. PLL_RATE(1128000000, 94, 1, 1),
  75. PLL_RATE(1152000000, 96, 1, 1),
  76. PLL_RATE(1176000000, 98, 1, 1),
  77. PLL_RATE(1200000000, 50, 1, 0),
  78. PLL_RATE(1224000000, 51, 1, 0),
  79. PLL_RATE(1248000000, 52, 1, 0),
  80. PLL_RATE(1272000000, 53, 1, 0),
  81. PLL_RATE(1296000000, 54, 1, 0),
  82. PLL_RATE(1320000000, 55, 1, 0),
  83. PLL_RATE(1344000000, 56, 1, 0),
  84. PLL_RATE(1368000000, 57, 1, 0),
  85. PLL_RATE(1392000000, 58, 1, 0),
  86. PLL_RATE(1416000000, 59, 1, 0),
  87. PLL_RATE(1440000000, 60, 1, 0),
  88. PLL_RATE(1464000000, 61, 1, 0),
  89. PLL_RATE(1488000000, 62, 1, 0),
  90. PLL_RATE(1512000000, 63, 1, 0),
  91. PLL_RATE(1536000000, 64, 1, 0),
  92. PLL_RATE(1560000000, 65, 1, 0),
  93. PLL_RATE(1584000000, 66, 1, 0),
  94. PLL_RATE(1608000000, 67, 1, 0),
  95. PLL_RATE(1632000000, 68, 1, 0),
  96. PLL_RATE(1656000000, 68, 1, 0),
  97. PLL_RATE(1680000000, 68, 1, 0),
  98. PLL_RATE(1704000000, 68, 1, 0),
  99. PLL_RATE(1728000000, 69, 1, 0),
  100. PLL_RATE(1752000000, 69, 1, 0),
  101. PLL_RATE(1776000000, 69, 1, 0),
  102. PLL_RATE(1800000000, 69, 1, 0),
  103. PLL_RATE(1824000000, 70, 1, 0),
  104. PLL_RATE(1848000000, 70, 1, 0),
  105. PLL_RATE(1872000000, 70, 1, 0),
  106. PLL_RATE(1896000000, 70, 1, 0),
  107. PLL_RATE(1920000000, 71, 1, 0),
  108. PLL_RATE(1944000000, 71, 1, 0),
  109. PLL_RATE(1968000000, 71, 1, 0),
  110. PLL_RATE(1992000000, 71, 1, 0),
  111. PLL_RATE(2016000000, 72, 1, 0),
  112. PLL_RATE(2040000000, 72, 1, 0),
  113. PLL_RATE(2064000000, 72, 1, 0),
  114. PLL_RATE(2088000000, 72, 1, 0),
  115. PLL_RATE(2112000000, 73, 1, 0),
  116. { /* sentinel */ },
  117. };
  118. static const struct pll_rate_table gp0_pll_rate_table[] = {
  119. PLL_RATE(96000000, 32, 1, 3),
  120. PLL_RATE(99000000, 33, 1, 3),
  121. PLL_RATE(102000000, 34, 1, 3),
  122. PLL_RATE(105000000, 35, 1, 3),
  123. PLL_RATE(108000000, 36, 1, 3),
  124. PLL_RATE(111000000, 37, 1, 3),
  125. PLL_RATE(114000000, 38, 1, 3),
  126. PLL_RATE(117000000, 39, 1, 3),
  127. PLL_RATE(120000000, 40, 1, 3),
  128. PLL_RATE(123000000, 41, 1, 3),
  129. PLL_RATE(126000000, 42, 1, 3),
  130. PLL_RATE(129000000, 43, 1, 3),
  131. PLL_RATE(132000000, 44, 1, 3),
  132. PLL_RATE(135000000, 45, 1, 3),
  133. PLL_RATE(138000000, 46, 1, 3),
  134. PLL_RATE(141000000, 47, 1, 3),
  135. PLL_RATE(144000000, 48, 1, 3),
  136. PLL_RATE(147000000, 49, 1, 3),
  137. PLL_RATE(150000000, 50, 1, 3),
  138. PLL_RATE(153000000, 51, 1, 3),
  139. PLL_RATE(156000000, 52, 1, 3),
  140. PLL_RATE(159000000, 53, 1, 3),
  141. PLL_RATE(162000000, 54, 1, 3),
  142. PLL_RATE(165000000, 55, 1, 3),
  143. PLL_RATE(168000000, 56, 1, 3),
  144. PLL_RATE(171000000, 57, 1, 3),
  145. PLL_RATE(174000000, 58, 1, 3),
  146. PLL_RATE(177000000, 59, 1, 3),
  147. PLL_RATE(180000000, 60, 1, 3),
  148. PLL_RATE(183000000, 61, 1, 3),
  149. PLL_RATE(186000000, 62, 1, 3),
  150. PLL_RATE(192000000, 32, 1, 2),
  151. PLL_RATE(198000000, 33, 1, 2),
  152. PLL_RATE(204000000, 34, 1, 2),
  153. PLL_RATE(210000000, 35, 1, 2),
  154. PLL_RATE(216000000, 36, 1, 2),
  155. PLL_RATE(222000000, 37, 1, 2),
  156. PLL_RATE(228000000, 38, 1, 2),
  157. PLL_RATE(234000000, 39, 1, 2),
  158. PLL_RATE(240000000, 40, 1, 2),
  159. PLL_RATE(246000000, 41, 1, 2),
  160. PLL_RATE(252000000, 42, 1, 2),
  161. PLL_RATE(258000000, 43, 1, 2),
  162. PLL_RATE(264000000, 44, 1, 2),
  163. PLL_RATE(270000000, 45, 1, 2),
  164. PLL_RATE(276000000, 46, 1, 2),
  165. PLL_RATE(282000000, 47, 1, 2),
  166. PLL_RATE(288000000, 48, 1, 2),
  167. PLL_RATE(294000000, 49, 1, 2),
  168. PLL_RATE(300000000, 50, 1, 2),
  169. PLL_RATE(306000000, 51, 1, 2),
  170. PLL_RATE(312000000, 52, 1, 2),
  171. PLL_RATE(318000000, 53, 1, 2),
  172. PLL_RATE(324000000, 54, 1, 2),
  173. PLL_RATE(330000000, 55, 1, 2),
  174. PLL_RATE(336000000, 56, 1, 2),
  175. PLL_RATE(342000000, 57, 1, 2),
  176. PLL_RATE(348000000, 58, 1, 2),
  177. PLL_RATE(354000000, 59, 1, 2),
  178. PLL_RATE(360000000, 60, 1, 2),
  179. PLL_RATE(366000000, 61, 1, 2),
  180. PLL_RATE(372000000, 62, 1, 2),
  181. PLL_RATE(384000000, 32, 1, 1),
  182. PLL_RATE(396000000, 33, 1, 1),
  183. PLL_RATE(408000000, 34, 1, 1),
  184. PLL_RATE(420000000, 35, 1, 1),
  185. PLL_RATE(432000000, 36, 1, 1),
  186. PLL_RATE(444000000, 37, 1, 1),
  187. PLL_RATE(456000000, 38, 1, 1),
  188. PLL_RATE(468000000, 39, 1, 1),
  189. PLL_RATE(480000000, 40, 1, 1),
  190. PLL_RATE(492000000, 41, 1, 1),
  191. PLL_RATE(504000000, 42, 1, 1),
  192. PLL_RATE(516000000, 43, 1, 1),
  193. PLL_RATE(528000000, 44, 1, 1),
  194. PLL_RATE(540000000, 45, 1, 1),
  195. PLL_RATE(552000000, 46, 1, 1),
  196. PLL_RATE(564000000, 47, 1, 1),
  197. PLL_RATE(576000000, 48, 1, 1),
  198. PLL_RATE(588000000, 49, 1, 1),
  199. PLL_RATE(600000000, 50, 1, 1),
  200. PLL_RATE(612000000, 51, 1, 1),
  201. PLL_RATE(624000000, 52, 1, 1),
  202. PLL_RATE(636000000, 53, 1, 1),
  203. PLL_RATE(648000000, 54, 1, 1),
  204. PLL_RATE(660000000, 55, 1, 1),
  205. PLL_RATE(672000000, 56, 1, 1),
  206. PLL_RATE(684000000, 57, 1, 1),
  207. PLL_RATE(696000000, 58, 1, 1),
  208. PLL_RATE(708000000, 59, 1, 1),
  209. PLL_RATE(720000000, 60, 1, 1),
  210. PLL_RATE(732000000, 61, 1, 1),
  211. PLL_RATE(744000000, 62, 1, 1),
  212. PLL_RATE(768000000, 32, 1, 0),
  213. PLL_RATE(792000000, 33, 1, 0),
  214. PLL_RATE(816000000, 34, 1, 0),
  215. PLL_RATE(840000000, 35, 1, 0),
  216. PLL_RATE(864000000, 36, 1, 0),
  217. PLL_RATE(888000000, 37, 1, 0),
  218. PLL_RATE(912000000, 38, 1, 0),
  219. PLL_RATE(936000000, 39, 1, 0),
  220. PLL_RATE(960000000, 40, 1, 0),
  221. PLL_RATE(984000000, 41, 1, 0),
  222. PLL_RATE(1008000000, 42, 1, 0),
  223. PLL_RATE(1032000000, 43, 1, 0),
  224. PLL_RATE(1056000000, 44, 1, 0),
  225. PLL_RATE(1080000000, 45, 1, 0),
  226. PLL_RATE(1104000000, 46, 1, 0),
  227. PLL_RATE(1128000000, 47, 1, 0),
  228. PLL_RATE(1152000000, 48, 1, 0),
  229. PLL_RATE(1176000000, 49, 1, 0),
  230. PLL_RATE(1200000000, 50, 1, 0),
  231. PLL_RATE(1224000000, 51, 1, 0),
  232. PLL_RATE(1248000000, 52, 1, 0),
  233. PLL_RATE(1272000000, 53, 1, 0),
  234. PLL_RATE(1296000000, 54, 1, 0),
  235. PLL_RATE(1320000000, 55, 1, 0),
  236. PLL_RATE(1344000000, 56, 1, 0),
  237. PLL_RATE(1368000000, 57, 1, 0),
  238. PLL_RATE(1392000000, 58, 1, 0),
  239. PLL_RATE(1416000000, 59, 1, 0),
  240. PLL_RATE(1440000000, 60, 1, 0),
  241. PLL_RATE(1464000000, 61, 1, 0),
  242. PLL_RATE(1488000000, 62, 1, 0),
  243. { /* sentinel */ },
  244. };
  245. static const struct clk_div_table cpu_div_table[] = {
  246. { .val = 1, .div = 1 },
  247. { .val = 2, .div = 2 },
  248. { .val = 3, .div = 3 },
  249. { .val = 2, .div = 4 },
  250. { .val = 3, .div = 6 },
  251. { .val = 4, .div = 8 },
  252. { .val = 5, .div = 10 },
  253. { .val = 6, .div = 12 },
  254. { .val = 7, .div = 14 },
  255. { .val = 8, .div = 16 },
  256. { /* sentinel */ },
  257. };
  258. static struct meson_clk_pll gxbb_fixed_pll = {
  259. .m = {
  260. .reg_off = HHI_MPLL_CNTL,
  261. .shift = 0,
  262. .width = 9,
  263. },
  264. .n = {
  265. .reg_off = HHI_MPLL_CNTL,
  266. .shift = 9,
  267. .width = 5,
  268. },
  269. .od = {
  270. .reg_off = HHI_MPLL_CNTL,
  271. .shift = 16,
  272. .width = 2,
  273. },
  274. .lock = &clk_lock,
  275. .hw.init = &(struct clk_init_data){
  276. .name = "fixed_pll",
  277. .ops = &meson_clk_pll_ro_ops,
  278. .parent_names = (const char *[]){ "xtal" },
  279. .num_parents = 1,
  280. .flags = CLK_GET_RATE_NOCACHE,
  281. },
  282. };
  283. static struct meson_clk_pll gxbb_hdmi_pll = {
  284. .m = {
  285. .reg_off = HHI_HDMI_PLL_CNTL,
  286. .shift = 0,
  287. .width = 9,
  288. },
  289. .n = {
  290. .reg_off = HHI_HDMI_PLL_CNTL,
  291. .shift = 9,
  292. .width = 5,
  293. },
  294. .frac = {
  295. .reg_off = HHI_HDMI_PLL_CNTL2,
  296. .shift = 0,
  297. .width = 12,
  298. },
  299. .od = {
  300. .reg_off = HHI_HDMI_PLL_CNTL2,
  301. .shift = 16,
  302. .width = 2,
  303. },
  304. .od2 = {
  305. .reg_off = HHI_HDMI_PLL_CNTL2,
  306. .shift = 22,
  307. .width = 2,
  308. },
  309. .lock = &clk_lock,
  310. .hw.init = &(struct clk_init_data){
  311. .name = "hdmi_pll",
  312. .ops = &meson_clk_pll_ro_ops,
  313. .parent_names = (const char *[]){ "xtal" },
  314. .num_parents = 1,
  315. .flags = CLK_GET_RATE_NOCACHE,
  316. },
  317. };
  318. static struct meson_clk_pll gxbb_sys_pll = {
  319. .m = {
  320. .reg_off = HHI_SYS_PLL_CNTL,
  321. .shift = 0,
  322. .width = 9,
  323. },
  324. .n = {
  325. .reg_off = HHI_SYS_PLL_CNTL,
  326. .shift = 9,
  327. .width = 5,
  328. },
  329. .od = {
  330. .reg_off = HHI_SYS_PLL_CNTL,
  331. .shift = 10,
  332. .width = 2,
  333. },
  334. .rate_table = sys_pll_rate_table,
  335. .rate_count = ARRAY_SIZE(sys_pll_rate_table),
  336. .lock = &clk_lock,
  337. .hw.init = &(struct clk_init_data){
  338. .name = "sys_pll",
  339. .ops = &meson_clk_pll_ro_ops,
  340. .parent_names = (const char *[]){ "xtal" },
  341. .num_parents = 1,
  342. .flags = CLK_GET_RATE_NOCACHE,
  343. },
  344. };
  345. static struct meson_clk_pll gxbb_gp0_pll = {
  346. .m = {
  347. .reg_off = HHI_GP0_PLL_CNTL,
  348. .shift = 0,
  349. .width = 9,
  350. },
  351. .n = {
  352. .reg_off = HHI_GP0_PLL_CNTL,
  353. .shift = 9,
  354. .width = 5,
  355. },
  356. .od = {
  357. .reg_off = HHI_GP0_PLL_CNTL,
  358. .shift = 16,
  359. .width = 2,
  360. },
  361. .rate_table = gp0_pll_rate_table,
  362. .rate_count = ARRAY_SIZE(gp0_pll_rate_table),
  363. .lock = &clk_lock,
  364. .hw.init = &(struct clk_init_data){
  365. .name = "gp0_pll",
  366. .ops = &meson_clk_pll_ops,
  367. .parent_names = (const char *[]){ "xtal" },
  368. .num_parents = 1,
  369. .flags = CLK_GET_RATE_NOCACHE,
  370. },
  371. };
  372. static struct clk_fixed_factor gxbb_fclk_div2 = {
  373. .mult = 1,
  374. .div = 2,
  375. .hw.init = &(struct clk_init_data){
  376. .name = "fclk_div2",
  377. .ops = &clk_fixed_factor_ops,
  378. .parent_names = (const char *[]){ "fixed_pll" },
  379. .num_parents = 1,
  380. },
  381. };
  382. static struct clk_fixed_factor gxbb_fclk_div3 = {
  383. .mult = 1,
  384. .div = 3,
  385. .hw.init = &(struct clk_init_data){
  386. .name = "fclk_div3",
  387. .ops = &clk_fixed_factor_ops,
  388. .parent_names = (const char *[]){ "fixed_pll" },
  389. .num_parents = 1,
  390. },
  391. };
  392. static struct clk_fixed_factor gxbb_fclk_div4 = {
  393. .mult = 1,
  394. .div = 4,
  395. .hw.init = &(struct clk_init_data){
  396. .name = "fclk_div4",
  397. .ops = &clk_fixed_factor_ops,
  398. .parent_names = (const char *[]){ "fixed_pll" },
  399. .num_parents = 1,
  400. },
  401. };
  402. static struct clk_fixed_factor gxbb_fclk_div5 = {
  403. .mult = 1,
  404. .div = 5,
  405. .hw.init = &(struct clk_init_data){
  406. .name = "fclk_div5",
  407. .ops = &clk_fixed_factor_ops,
  408. .parent_names = (const char *[]){ "fixed_pll" },
  409. .num_parents = 1,
  410. },
  411. };
  412. static struct clk_fixed_factor gxbb_fclk_div7 = {
  413. .mult = 1,
  414. .div = 7,
  415. .hw.init = &(struct clk_init_data){
  416. .name = "fclk_div7",
  417. .ops = &clk_fixed_factor_ops,
  418. .parent_names = (const char *[]){ "fixed_pll" },
  419. .num_parents = 1,
  420. },
  421. };
  422. static struct meson_clk_mpll gxbb_mpll0 = {
  423. .sdm = {
  424. .reg_off = HHI_MPLL_CNTL7,
  425. .shift = 0,
  426. .width = 14,
  427. },
  428. .n2 = {
  429. .reg_off = HHI_MPLL_CNTL7,
  430. .shift = 16,
  431. .width = 9,
  432. },
  433. .lock = &clk_lock,
  434. .hw.init = &(struct clk_init_data){
  435. .name = "mpll0",
  436. .ops = &meson_clk_mpll_ro_ops,
  437. .parent_names = (const char *[]){ "fixed_pll" },
  438. .num_parents = 1,
  439. },
  440. };
  441. static struct meson_clk_mpll gxbb_mpll1 = {
  442. .sdm = {
  443. .reg_off = HHI_MPLL_CNTL8,
  444. .shift = 0,
  445. .width = 14,
  446. },
  447. .n2 = {
  448. .reg_off = HHI_MPLL_CNTL8,
  449. .shift = 16,
  450. .width = 9,
  451. },
  452. .lock = &clk_lock,
  453. .hw.init = &(struct clk_init_data){
  454. .name = "mpll1",
  455. .ops = &meson_clk_mpll_ro_ops,
  456. .parent_names = (const char *[]){ "fixed_pll" },
  457. .num_parents = 1,
  458. },
  459. };
  460. static struct meson_clk_mpll gxbb_mpll2 = {
  461. .sdm = {
  462. .reg_off = HHI_MPLL_CNTL9,
  463. .shift = 0,
  464. .width = 14,
  465. },
  466. .n2 = {
  467. .reg_off = HHI_MPLL_CNTL9,
  468. .shift = 16,
  469. .width = 9,
  470. },
  471. .lock = &clk_lock,
  472. .hw.init = &(struct clk_init_data){
  473. .name = "mpll2",
  474. .ops = &meson_clk_mpll_ro_ops,
  475. .parent_names = (const char *[]){ "fixed_pll" },
  476. .num_parents = 1,
  477. },
  478. };
  479. /*
  480. * FIXME cpu clocks and the legacy composite clocks (e.g. clk81) are both PLL
  481. * post-dividers and should be modeled with their respective PLLs via the
  482. * forthcoming coordinated clock rates feature
  483. */
  484. static struct meson_clk_cpu gxbb_cpu_clk = {
  485. .reg_off = HHI_SYS_CPU_CLK_CNTL1,
  486. .div_table = cpu_div_table,
  487. .clk_nb.notifier_call = meson_clk_cpu_notifier_cb,
  488. .hw.init = &(struct clk_init_data){
  489. .name = "cpu_clk",
  490. .ops = &meson_clk_cpu_ops,
  491. .parent_names = (const char *[]){ "sys_pll" },
  492. .num_parents = 1,
  493. },
  494. };
  495. static u32 mux_table_clk81[] = { 6, 5, 7 };
  496. static struct clk_mux gxbb_mpeg_clk_sel = {
  497. .reg = (void *)HHI_MPEG_CLK_CNTL,
  498. .mask = 0x7,
  499. .shift = 12,
  500. .flags = CLK_MUX_READ_ONLY,
  501. .table = mux_table_clk81,
  502. .lock = &clk_lock,
  503. .hw.init = &(struct clk_init_data){
  504. .name = "mpeg_clk_sel",
  505. .ops = &clk_mux_ro_ops,
  506. /*
  507. * FIXME bits 14:12 selects from 8 possible parents:
  508. * xtal, 1'b0 (wtf), fclk_div7, mpll_clkout1, mpll_clkout2,
  509. * fclk_div4, fclk_div3, fclk_div5
  510. */
  511. .parent_names = (const char *[]){ "fclk_div3", "fclk_div4",
  512. "fclk_div5" },
  513. .num_parents = 3,
  514. .flags = (CLK_SET_RATE_NO_REPARENT | CLK_IGNORE_UNUSED),
  515. },
  516. };
  517. static struct clk_divider gxbb_mpeg_clk_div = {
  518. .reg = (void *)HHI_MPEG_CLK_CNTL,
  519. .shift = 0,
  520. .width = 7,
  521. .lock = &clk_lock,
  522. .hw.init = &(struct clk_init_data){
  523. .name = "mpeg_clk_div",
  524. .ops = &clk_divider_ops,
  525. .parent_names = (const char *[]){ "mpeg_clk_sel" },
  526. .num_parents = 1,
  527. .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED),
  528. },
  529. };
  530. /* the mother of dragons^W gates */
  531. static struct clk_gate gxbb_clk81 = {
  532. .reg = (void *)HHI_MPEG_CLK_CNTL,
  533. .bit_idx = 7,
  534. .lock = &clk_lock,
  535. .hw.init = &(struct clk_init_data){
  536. .name = "clk81",
  537. .ops = &clk_gate_ops,
  538. .parent_names = (const char *[]){ "mpeg_clk_div" },
  539. .num_parents = 1,
  540. .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED | CLK_IS_CRITICAL),
  541. },
  542. };
  543. /* Everything Else (EE) domain gates */
  544. static MESON_GATE(gxbb_ddr, HHI_GCLK_MPEG0, 0);
  545. static MESON_GATE(gxbb_dos, HHI_GCLK_MPEG0, 1);
  546. static MESON_GATE(gxbb_isa, HHI_GCLK_MPEG0, 5);
  547. static MESON_GATE(gxbb_pl301, HHI_GCLK_MPEG0, 6);
  548. static MESON_GATE(gxbb_periphs, HHI_GCLK_MPEG0, 7);
  549. static MESON_GATE(gxbb_spicc, HHI_GCLK_MPEG0, 8);
  550. static MESON_GATE(gxbb_i2c, HHI_GCLK_MPEG0, 9);
  551. static MESON_GATE(gxbb_sana, HHI_GCLK_MPEG0, 10);
  552. static MESON_GATE(gxbb_smart_card, HHI_GCLK_MPEG0, 11);
  553. static MESON_GATE(gxbb_rng0, HHI_GCLK_MPEG0, 12);
  554. static MESON_GATE(gxbb_uart0, HHI_GCLK_MPEG0, 13);
  555. static MESON_GATE(gxbb_sdhc, HHI_GCLK_MPEG0, 14);
  556. static MESON_GATE(gxbb_stream, HHI_GCLK_MPEG0, 15);
  557. static MESON_GATE(gxbb_async_fifo, HHI_GCLK_MPEG0, 16);
  558. static MESON_GATE(gxbb_sdio, HHI_GCLK_MPEG0, 17);
  559. static MESON_GATE(gxbb_abuf, HHI_GCLK_MPEG0, 18);
  560. static MESON_GATE(gxbb_hiu_iface, HHI_GCLK_MPEG0, 19);
  561. static MESON_GATE(gxbb_assist_misc, HHI_GCLK_MPEG0, 23);
  562. static MESON_GATE(gxbb_emmc_a, HHI_GCLK_MPEG0, 24);
  563. static MESON_GATE(gxbb_emmc_b, HHI_GCLK_MPEG0, 25);
  564. static MESON_GATE(gxbb_emmc_c, HHI_GCLK_MPEG0, 26);
  565. static MESON_GATE(gxbb_spi, HHI_GCLK_MPEG0, 30);
  566. static MESON_GATE(gxbb_i2s_spdif, HHI_GCLK_MPEG1, 2);
  567. static MESON_GATE(gxbb_eth, HHI_GCLK_MPEG1, 3);
  568. static MESON_GATE(gxbb_demux, HHI_GCLK_MPEG1, 4);
  569. static MESON_GATE(gxbb_aiu_glue, HHI_GCLK_MPEG1, 6);
  570. static MESON_GATE(gxbb_iec958, HHI_GCLK_MPEG1, 7);
  571. static MESON_GATE(gxbb_i2s_out, HHI_GCLK_MPEG1, 8);
  572. static MESON_GATE(gxbb_amclk, HHI_GCLK_MPEG1, 9);
  573. static MESON_GATE(gxbb_aififo2, HHI_GCLK_MPEG1, 10);
  574. static MESON_GATE(gxbb_mixer, HHI_GCLK_MPEG1, 11);
  575. static MESON_GATE(gxbb_mixer_iface, HHI_GCLK_MPEG1, 12);
  576. static MESON_GATE(gxbb_adc, HHI_GCLK_MPEG1, 13);
  577. static MESON_GATE(gxbb_blkmv, HHI_GCLK_MPEG1, 14);
  578. static MESON_GATE(gxbb_aiu, HHI_GCLK_MPEG1, 15);
  579. static MESON_GATE(gxbb_uart1, HHI_GCLK_MPEG1, 16);
  580. static MESON_GATE(gxbb_g2d, HHI_GCLK_MPEG1, 20);
  581. static MESON_GATE(gxbb_usb0, HHI_GCLK_MPEG1, 21);
  582. static MESON_GATE(gxbb_usb1, HHI_GCLK_MPEG1, 22);
  583. static MESON_GATE(gxbb_reset, HHI_GCLK_MPEG1, 23);
  584. static MESON_GATE(gxbb_nand, HHI_GCLK_MPEG1, 24);
  585. static MESON_GATE(gxbb_dos_parser, HHI_GCLK_MPEG1, 25);
  586. static MESON_GATE(gxbb_usb, HHI_GCLK_MPEG1, 26);
  587. static MESON_GATE(gxbb_vdin1, HHI_GCLK_MPEG1, 28);
  588. static MESON_GATE(gxbb_ahb_arb0, HHI_GCLK_MPEG1, 29);
  589. static MESON_GATE(gxbb_efuse, HHI_GCLK_MPEG1, 30);
  590. static MESON_GATE(gxbb_boot_rom, HHI_GCLK_MPEG1, 31);
  591. static MESON_GATE(gxbb_ahb_data_bus, HHI_GCLK_MPEG2, 1);
  592. static MESON_GATE(gxbb_ahb_ctrl_bus, HHI_GCLK_MPEG2, 2);
  593. static MESON_GATE(gxbb_hdmi_intr_sync, HHI_GCLK_MPEG2, 3);
  594. static MESON_GATE(gxbb_hdmi_pclk, HHI_GCLK_MPEG2, 4);
  595. static MESON_GATE(gxbb_usb1_ddr_bridge, HHI_GCLK_MPEG2, 8);
  596. static MESON_GATE(gxbb_usb0_ddr_bridge, HHI_GCLK_MPEG2, 9);
  597. static MESON_GATE(gxbb_mmc_pclk, HHI_GCLK_MPEG2, 11);
  598. static MESON_GATE(gxbb_dvin, HHI_GCLK_MPEG2, 12);
  599. static MESON_GATE(gxbb_uart2, HHI_GCLK_MPEG2, 15);
  600. static MESON_GATE(gxbb_sar_adc, HHI_GCLK_MPEG2, 22);
  601. static MESON_GATE(gxbb_vpu_intr, HHI_GCLK_MPEG2, 25);
  602. static MESON_GATE(gxbb_sec_ahb_ahb3_bridge, HHI_GCLK_MPEG2, 26);
  603. static MESON_GATE(gxbb_clk81_a53, HHI_GCLK_MPEG2, 29);
  604. static MESON_GATE(gxbb_vclk2_venci0, HHI_GCLK_OTHER, 1);
  605. static MESON_GATE(gxbb_vclk2_venci1, HHI_GCLK_OTHER, 2);
  606. static MESON_GATE(gxbb_vclk2_vencp0, HHI_GCLK_OTHER, 3);
  607. static MESON_GATE(gxbb_vclk2_vencp1, HHI_GCLK_OTHER, 4);
  608. static MESON_GATE(gxbb_gclk_venci_int0, HHI_GCLK_OTHER, 8);
  609. static MESON_GATE(gxbb_gclk_vencp_int, HHI_GCLK_OTHER, 9);
  610. static MESON_GATE(gxbb_dac_clk, HHI_GCLK_OTHER, 10);
  611. static MESON_GATE(gxbb_aoclk_gate, HHI_GCLK_OTHER, 14);
  612. static MESON_GATE(gxbb_iec958_gate, HHI_GCLK_OTHER, 16);
  613. static MESON_GATE(gxbb_enc480p, HHI_GCLK_OTHER, 20);
  614. static MESON_GATE(gxbb_rng1, HHI_GCLK_OTHER, 21);
  615. static MESON_GATE(gxbb_gclk_venci_int1, HHI_GCLK_OTHER, 22);
  616. static MESON_GATE(gxbb_vclk2_venclmcc, HHI_GCLK_OTHER, 24);
  617. static MESON_GATE(gxbb_vclk2_vencl, HHI_GCLK_OTHER, 25);
  618. static MESON_GATE(gxbb_vclk_other, HHI_GCLK_OTHER, 26);
  619. static MESON_GATE(gxbb_edp, HHI_GCLK_OTHER, 31);
  620. /* Always On (AO) domain gates */
  621. static MESON_GATE(gxbb_ao_media_cpu, HHI_GCLK_AO, 0);
  622. static MESON_GATE(gxbb_ao_ahb_sram, HHI_GCLK_AO, 1);
  623. static MESON_GATE(gxbb_ao_ahb_bus, HHI_GCLK_AO, 2);
  624. static MESON_GATE(gxbb_ao_iface, HHI_GCLK_AO, 3);
  625. static MESON_GATE(gxbb_ao_i2c, HHI_GCLK_AO, 4);
  626. /* Array of all clocks provided by this provider */
  627. static struct clk_hw_onecell_data gxbb_hw_onecell_data = {
  628. .hws = {
  629. [CLKID_SYS_PLL] = &gxbb_sys_pll.hw,
  630. [CLKID_CPUCLK] = &gxbb_cpu_clk.hw,
  631. [CLKID_HDMI_PLL] = &gxbb_hdmi_pll.hw,
  632. [CLKID_FIXED_PLL] = &gxbb_fixed_pll.hw,
  633. [CLKID_FCLK_DIV2] = &gxbb_fclk_div2.hw,
  634. [CLKID_FCLK_DIV3] = &gxbb_fclk_div3.hw,
  635. [CLKID_FCLK_DIV4] = &gxbb_fclk_div4.hw,
  636. [CLKID_FCLK_DIV5] = &gxbb_fclk_div5.hw,
  637. [CLKID_FCLK_DIV7] = &gxbb_fclk_div7.hw,
  638. [CLKID_GP0_PLL] = &gxbb_gp0_pll.hw,
  639. [CLKID_MPEG_SEL] = &gxbb_mpeg_clk_sel.hw,
  640. [CLKID_MPEG_DIV] = &gxbb_mpeg_clk_div.hw,
  641. [CLKID_CLK81] = &gxbb_clk81.hw,
  642. [CLKID_MPLL0] = &gxbb_mpll0.hw,
  643. [CLKID_MPLL1] = &gxbb_mpll1.hw,
  644. [CLKID_MPLL2] = &gxbb_mpll2.hw,
  645. [CLKID_DDR] = &gxbb_ddr.hw,
  646. [CLKID_DOS] = &gxbb_dos.hw,
  647. [CLKID_ISA] = &gxbb_isa.hw,
  648. [CLKID_PL301] = &gxbb_pl301.hw,
  649. [CLKID_PERIPHS] = &gxbb_periphs.hw,
  650. [CLKID_SPICC] = &gxbb_spicc.hw,
  651. [CLKID_I2C] = &gxbb_i2c.hw,
  652. [CLKID_SAR_ADC] = &gxbb_sar_adc.hw,
  653. [CLKID_SMART_CARD] = &gxbb_smart_card.hw,
  654. [CLKID_RNG0] = &gxbb_rng0.hw,
  655. [CLKID_UART0] = &gxbb_uart0.hw,
  656. [CLKID_SDHC] = &gxbb_sdhc.hw,
  657. [CLKID_STREAM] = &gxbb_stream.hw,
  658. [CLKID_ASYNC_FIFO] = &gxbb_async_fifo.hw,
  659. [CLKID_SDIO] = &gxbb_sdio.hw,
  660. [CLKID_ABUF] = &gxbb_abuf.hw,
  661. [CLKID_HIU_IFACE] = &gxbb_hiu_iface.hw,
  662. [CLKID_ASSIST_MISC] = &gxbb_assist_misc.hw,
  663. [CLKID_SPI] = &gxbb_spi.hw,
  664. [CLKID_I2S_SPDIF] = &gxbb_i2s_spdif.hw,
  665. [CLKID_ETH] = &gxbb_eth.hw,
  666. [CLKID_DEMUX] = &gxbb_demux.hw,
  667. [CLKID_AIU_GLUE] = &gxbb_aiu_glue.hw,
  668. [CLKID_IEC958] = &gxbb_iec958.hw,
  669. [CLKID_I2S_OUT] = &gxbb_i2s_out.hw,
  670. [CLKID_AMCLK] = &gxbb_amclk.hw,
  671. [CLKID_AIFIFO2] = &gxbb_aififo2.hw,
  672. [CLKID_MIXER] = &gxbb_mixer.hw,
  673. [CLKID_MIXER_IFACE] = &gxbb_mixer_iface.hw,
  674. [CLKID_ADC] = &gxbb_adc.hw,
  675. [CLKID_BLKMV] = &gxbb_blkmv.hw,
  676. [CLKID_AIU] = &gxbb_aiu.hw,
  677. [CLKID_UART1] = &gxbb_uart1.hw,
  678. [CLKID_G2D] = &gxbb_g2d.hw,
  679. [CLKID_USB0] = &gxbb_usb0.hw,
  680. [CLKID_USB1] = &gxbb_usb1.hw,
  681. [CLKID_RESET] = &gxbb_reset.hw,
  682. [CLKID_NAND] = &gxbb_nand.hw,
  683. [CLKID_DOS_PARSER] = &gxbb_dos_parser.hw,
  684. [CLKID_USB] = &gxbb_usb.hw,
  685. [CLKID_VDIN1] = &gxbb_vdin1.hw,
  686. [CLKID_AHB_ARB0] = &gxbb_ahb_arb0.hw,
  687. [CLKID_EFUSE] = &gxbb_efuse.hw,
  688. [CLKID_BOOT_ROM] = &gxbb_boot_rom.hw,
  689. [CLKID_AHB_DATA_BUS] = &gxbb_ahb_data_bus.hw,
  690. [CLKID_AHB_CTRL_BUS] = &gxbb_ahb_ctrl_bus.hw,
  691. [CLKID_HDMI_INTR_SYNC] = &gxbb_hdmi_intr_sync.hw,
  692. [CLKID_HDMI_PCLK] = &gxbb_hdmi_pclk.hw,
  693. [CLKID_USB1_DDR_BRIDGE] = &gxbb_usb1_ddr_bridge.hw,
  694. [CLKID_USB0_DDR_BRIDGE] = &gxbb_usb0_ddr_bridge.hw,
  695. [CLKID_MMC_PCLK] = &gxbb_mmc_pclk.hw,
  696. [CLKID_DVIN] = &gxbb_dvin.hw,
  697. [CLKID_UART2] = &gxbb_uart2.hw,
  698. [CLKID_SANA] = &gxbb_sana.hw,
  699. [CLKID_VPU_INTR] = &gxbb_vpu_intr.hw,
  700. [CLKID_SEC_AHB_AHB3_BRIDGE] = &gxbb_sec_ahb_ahb3_bridge.hw,
  701. [CLKID_CLK81_A53] = &gxbb_clk81_a53.hw,
  702. [CLKID_VCLK2_VENCI0] = &gxbb_vclk2_venci0.hw,
  703. [CLKID_VCLK2_VENCI1] = &gxbb_vclk2_venci1.hw,
  704. [CLKID_VCLK2_VENCP0] = &gxbb_vclk2_vencp0.hw,
  705. [CLKID_VCLK2_VENCP1] = &gxbb_vclk2_vencp1.hw,
  706. [CLKID_GCLK_VENCI_INT0] = &gxbb_gclk_venci_int0.hw,
  707. [CLKID_GCLK_VENCI_INT] = &gxbb_gclk_vencp_int.hw,
  708. [CLKID_DAC_CLK] = &gxbb_dac_clk.hw,
  709. [CLKID_AOCLK_GATE] = &gxbb_aoclk_gate.hw,
  710. [CLKID_IEC958_GATE] = &gxbb_iec958_gate.hw,
  711. [CLKID_ENC480P] = &gxbb_enc480p.hw,
  712. [CLKID_RNG1] = &gxbb_rng1.hw,
  713. [CLKID_GCLK_VENCI_INT1] = &gxbb_gclk_venci_int1.hw,
  714. [CLKID_VCLK2_VENCLMCC] = &gxbb_vclk2_venclmcc.hw,
  715. [CLKID_VCLK2_VENCL] = &gxbb_vclk2_vencl.hw,
  716. [CLKID_VCLK_OTHER] = &gxbb_vclk_other.hw,
  717. [CLKID_EDP] = &gxbb_edp.hw,
  718. [CLKID_AO_MEDIA_CPU] = &gxbb_ao_media_cpu.hw,
  719. [CLKID_AO_AHB_SRAM] = &gxbb_ao_ahb_sram.hw,
  720. [CLKID_AO_AHB_BUS] = &gxbb_ao_ahb_bus.hw,
  721. [CLKID_AO_IFACE] = &gxbb_ao_iface.hw,
  722. [CLKID_AO_I2C] = &gxbb_ao_i2c.hw,
  723. [CLKID_SD_EMMC_A] = &gxbb_emmc_a.hw,
  724. [CLKID_SD_EMMC_B] = &gxbb_emmc_b.hw,
  725. [CLKID_SD_EMMC_C] = &gxbb_emmc_c.hw,
  726. },
  727. .num = NR_CLKS,
  728. };
  729. /* Convenience tables to populate base addresses in .probe */
  730. static struct meson_clk_pll *const gxbb_clk_plls[] = {
  731. &gxbb_fixed_pll,
  732. &gxbb_hdmi_pll,
  733. &gxbb_sys_pll,
  734. &gxbb_gp0_pll,
  735. };
  736. static struct meson_clk_mpll *const gxbb_clk_mplls[] = {
  737. &gxbb_mpll0,
  738. &gxbb_mpll1,
  739. &gxbb_mpll2,
  740. };
  741. static struct clk_gate *gxbb_clk_gates[] = {
  742. &gxbb_clk81,
  743. &gxbb_ddr,
  744. &gxbb_dos,
  745. &gxbb_isa,
  746. &gxbb_pl301,
  747. &gxbb_periphs,
  748. &gxbb_spicc,
  749. &gxbb_i2c,
  750. &gxbb_sar_adc,
  751. &gxbb_smart_card,
  752. &gxbb_rng0,
  753. &gxbb_uart0,
  754. &gxbb_sdhc,
  755. &gxbb_stream,
  756. &gxbb_async_fifo,
  757. &gxbb_sdio,
  758. &gxbb_abuf,
  759. &gxbb_hiu_iface,
  760. &gxbb_assist_misc,
  761. &gxbb_spi,
  762. &gxbb_i2s_spdif,
  763. &gxbb_eth,
  764. &gxbb_demux,
  765. &gxbb_aiu_glue,
  766. &gxbb_iec958,
  767. &gxbb_i2s_out,
  768. &gxbb_amclk,
  769. &gxbb_aififo2,
  770. &gxbb_mixer,
  771. &gxbb_mixer_iface,
  772. &gxbb_adc,
  773. &gxbb_blkmv,
  774. &gxbb_aiu,
  775. &gxbb_uart1,
  776. &gxbb_g2d,
  777. &gxbb_usb0,
  778. &gxbb_usb1,
  779. &gxbb_reset,
  780. &gxbb_nand,
  781. &gxbb_dos_parser,
  782. &gxbb_usb,
  783. &gxbb_vdin1,
  784. &gxbb_ahb_arb0,
  785. &gxbb_efuse,
  786. &gxbb_boot_rom,
  787. &gxbb_ahb_data_bus,
  788. &gxbb_ahb_ctrl_bus,
  789. &gxbb_hdmi_intr_sync,
  790. &gxbb_hdmi_pclk,
  791. &gxbb_usb1_ddr_bridge,
  792. &gxbb_usb0_ddr_bridge,
  793. &gxbb_mmc_pclk,
  794. &gxbb_dvin,
  795. &gxbb_uart2,
  796. &gxbb_sana,
  797. &gxbb_vpu_intr,
  798. &gxbb_sec_ahb_ahb3_bridge,
  799. &gxbb_clk81_a53,
  800. &gxbb_vclk2_venci0,
  801. &gxbb_vclk2_venci1,
  802. &gxbb_vclk2_vencp0,
  803. &gxbb_vclk2_vencp1,
  804. &gxbb_gclk_venci_int0,
  805. &gxbb_gclk_vencp_int,
  806. &gxbb_dac_clk,
  807. &gxbb_aoclk_gate,
  808. &gxbb_iec958_gate,
  809. &gxbb_enc480p,
  810. &gxbb_rng1,
  811. &gxbb_gclk_venci_int1,
  812. &gxbb_vclk2_venclmcc,
  813. &gxbb_vclk2_vencl,
  814. &gxbb_vclk_other,
  815. &gxbb_edp,
  816. &gxbb_ao_media_cpu,
  817. &gxbb_ao_ahb_sram,
  818. &gxbb_ao_ahb_bus,
  819. &gxbb_ao_iface,
  820. &gxbb_ao_i2c,
  821. &gxbb_emmc_a,
  822. &gxbb_emmc_b,
  823. &gxbb_emmc_c,
  824. };
  825. static int gxbb_clkc_probe(struct platform_device *pdev)
  826. {
  827. void __iomem *clk_base;
  828. int ret, clkid, i;
  829. struct clk_hw *parent_hw;
  830. struct clk *parent_clk;
  831. struct device *dev = &pdev->dev;
  832. /* Generic clocks and PLLs */
  833. clk_base = of_iomap(dev->of_node, 0);
  834. if (!clk_base) {
  835. pr_err("%s: Unable to map clk base\n", __func__);
  836. return -ENXIO;
  837. }
  838. /* Populate base address for PLLs */
  839. for (i = 0; i < ARRAY_SIZE(gxbb_clk_plls); i++)
  840. gxbb_clk_plls[i]->base = clk_base;
  841. /* Populate base address for MPLLs */
  842. for (i = 0; i < ARRAY_SIZE(gxbb_clk_mplls); i++)
  843. gxbb_clk_mplls[i]->base = clk_base;
  844. /* Populate the base address for CPU clk */
  845. gxbb_cpu_clk.base = clk_base;
  846. /* Populate the base address for the MPEG clks */
  847. gxbb_mpeg_clk_sel.reg = clk_base + (u64)gxbb_mpeg_clk_sel.reg;
  848. gxbb_mpeg_clk_div.reg = clk_base + (u64)gxbb_mpeg_clk_div.reg;
  849. /* Populate base address for gates */
  850. for (i = 0; i < ARRAY_SIZE(gxbb_clk_gates); i++)
  851. gxbb_clk_gates[i]->reg = clk_base +
  852. (u64)gxbb_clk_gates[i]->reg;
  853. /*
  854. * register all clks
  855. */
  856. for (clkid = 0; clkid < NR_CLKS; clkid++) {
  857. ret = devm_clk_hw_register(dev, gxbb_hw_onecell_data.hws[clkid]);
  858. if (ret)
  859. goto iounmap;
  860. }
  861. /*
  862. * Register CPU clk notifier
  863. *
  864. * FIXME this is wrong for a lot of reasons. First, the muxes should be
  865. * struct clk_hw objects. Second, we shouldn't program the muxes in
  866. * notifier handlers. The tricky programming sequence will be handled
  867. * by the forthcoming coordinated clock rates mechanism once that
  868. * feature is released.
  869. *
  870. * Furthermore, looking up the parent this way is terrible. At some
  871. * point we will stop allocating a default struct clk when registering
  872. * a new clk_hw, and this hack will no longer work. Releasing the ccr
  873. * feature before that time solves the problem :-)
  874. */
  875. parent_hw = clk_hw_get_parent(&gxbb_cpu_clk.hw);
  876. parent_clk = parent_hw->clk;
  877. ret = clk_notifier_register(parent_clk, &gxbb_cpu_clk.clk_nb);
  878. if (ret) {
  879. pr_err("%s: failed to register clock notifier for cpu_clk\n",
  880. __func__);
  881. goto iounmap;
  882. }
  883. return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
  884. &gxbb_hw_onecell_data);
  885. iounmap:
  886. iounmap(clk_base);
  887. return ret;
  888. }
  889. static const struct of_device_id gxbb_clkc_match_table[] = {
  890. { .compatible = "amlogic,gxbb-clkc" },
  891. { }
  892. };
  893. static struct platform_driver gxbb_driver = {
  894. .probe = gxbb_clkc_probe,
  895. .driver = {
  896. .name = "gxbb-clkc",
  897. .of_match_table = gxbb_clkc_match_table,
  898. },
  899. };
  900. builtin_platform_driver(gxbb_driver);