bg2.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * Copyright (c) 2014 Marvell Technology Group Ltd.
  3. *
  4. * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
  5. * Alexandre Belloni <alexandre.belloni@free-electrons.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/kernel.h>
  22. #include <linux/of.h>
  23. #include <linux/of_address.h>
  24. #include <linux/slab.h>
  25. #include <dt-bindings/clock/berlin2.h>
  26. #include "berlin2-avpll.h"
  27. #include "berlin2-div.h"
  28. #include "berlin2-pll.h"
  29. #include "common.h"
  30. #define REG_PINMUX0 0x0000
  31. #define REG_PINMUX1 0x0004
  32. #define REG_SYSPLLCTL0 0x0014
  33. #define REG_SYSPLLCTL4 0x0024
  34. #define REG_MEMPLLCTL0 0x0028
  35. #define REG_MEMPLLCTL4 0x0038
  36. #define REG_CPUPLLCTL0 0x003c
  37. #define REG_CPUPLLCTL4 0x004c
  38. #define REG_AVPLLCTL0 0x0050
  39. #define REG_AVPLLCTL31 0x00cc
  40. #define REG_AVPLLCTL62 0x0148
  41. #define REG_PLLSTATUS 0x014c
  42. #define REG_CLKENABLE 0x0150
  43. #define REG_CLKSELECT0 0x0154
  44. #define REG_CLKSELECT1 0x0158
  45. #define REG_CLKSELECT2 0x015c
  46. #define REG_CLKSELECT3 0x0160
  47. #define REG_CLKSWITCH0 0x0164
  48. #define REG_CLKSWITCH1 0x0168
  49. #define REG_RESET_TRIGGER 0x0178
  50. #define REG_RESET_STATUS0 0x017c
  51. #define REG_RESET_STATUS1 0x0180
  52. #define REG_SW_GENERIC0 0x0184
  53. #define REG_SW_GENERIC3 0x0190
  54. #define REG_PRODUCTID 0x01cc
  55. #define REG_PRODUCTID_EXT 0x01d0
  56. #define REG_GFX3DCORE_CLKCTL 0x022c
  57. #define REG_GFX3DSYS_CLKCTL 0x0230
  58. #define REG_ARC_CLKCTL 0x0234
  59. #define REG_VIP_CLKCTL 0x0238
  60. #define REG_SDIO0XIN_CLKCTL 0x023c
  61. #define REG_SDIO1XIN_CLKCTL 0x0240
  62. #define REG_GFX3DEXTRA_CLKCTL 0x0244
  63. #define REG_GFX3D_RESET 0x0248
  64. #define REG_GC360_CLKCTL 0x024c
  65. #define REG_SDIO_DLLMST_CLKCTL 0x0250
  66. /*
  67. * BG2/BG2CD SoCs have the following audio/video I/O units:
  68. *
  69. * audiohd: HDMI TX audio
  70. * audio0: 7.1ch TX
  71. * audio1: 2ch TX
  72. * audio2: 2ch RX
  73. * audio3: SPDIF TX
  74. * video0: HDMI video
  75. * video1: Secondary video
  76. * video2: SD auxiliary video
  77. *
  78. * There are no external audio clocks (ACLKI0, ACLKI1) and
  79. * only one external video clock (VCLKI0).
  80. *
  81. * Currently missing bits and pieces:
  82. * - audio_fast_pll is unknown
  83. * - audiohd_pll is unknown
  84. * - video0_pll is unknown
  85. * - audio[023], audiohd parent pll is assumed to be audio_fast_pll
  86. *
  87. */
  88. #define MAX_CLKS 41
  89. static struct clk_hw_onecell_data *clk_data;
  90. static DEFINE_SPINLOCK(lock);
  91. static void __iomem *gbase;
  92. enum {
  93. REFCLK, VIDEO_EXT0,
  94. SYSPLL, MEMPLL, CPUPLL,
  95. AVPLL_A1, AVPLL_A2, AVPLL_A3, AVPLL_A4,
  96. AVPLL_A5, AVPLL_A6, AVPLL_A7, AVPLL_A8,
  97. AVPLL_B1, AVPLL_B2, AVPLL_B3, AVPLL_B4,
  98. AVPLL_B5, AVPLL_B6, AVPLL_B7, AVPLL_B8,
  99. AUDIO1_PLL, AUDIO_FAST_PLL,
  100. VIDEO0_PLL, VIDEO0_IN,
  101. VIDEO1_PLL, VIDEO1_IN,
  102. VIDEO2_PLL, VIDEO2_IN,
  103. };
  104. static const char *clk_names[] = {
  105. [REFCLK] = "refclk",
  106. [VIDEO_EXT0] = "video_ext0",
  107. [SYSPLL] = "syspll",
  108. [MEMPLL] = "mempll",
  109. [CPUPLL] = "cpupll",
  110. [AVPLL_A1] = "avpll_a1",
  111. [AVPLL_A2] = "avpll_a2",
  112. [AVPLL_A3] = "avpll_a3",
  113. [AVPLL_A4] = "avpll_a4",
  114. [AVPLL_A5] = "avpll_a5",
  115. [AVPLL_A6] = "avpll_a6",
  116. [AVPLL_A7] = "avpll_a7",
  117. [AVPLL_A8] = "avpll_a8",
  118. [AVPLL_B1] = "avpll_b1",
  119. [AVPLL_B2] = "avpll_b2",
  120. [AVPLL_B3] = "avpll_b3",
  121. [AVPLL_B4] = "avpll_b4",
  122. [AVPLL_B5] = "avpll_b5",
  123. [AVPLL_B6] = "avpll_b6",
  124. [AVPLL_B7] = "avpll_b7",
  125. [AVPLL_B8] = "avpll_b8",
  126. [AUDIO1_PLL] = "audio1_pll",
  127. [AUDIO_FAST_PLL] = "audio_fast_pll",
  128. [VIDEO0_PLL] = "video0_pll",
  129. [VIDEO0_IN] = "video0_in",
  130. [VIDEO1_PLL] = "video1_pll",
  131. [VIDEO1_IN] = "video1_in",
  132. [VIDEO2_PLL] = "video2_pll",
  133. [VIDEO2_IN] = "video2_in",
  134. };
  135. static const struct berlin2_pll_map bg2_pll_map __initconst = {
  136. .vcodiv = {10, 15, 20, 25, 30, 40, 50, 60, 80},
  137. .mult = 10,
  138. .fbdiv_shift = 6,
  139. .rfdiv_shift = 1,
  140. .divsel_shift = 7,
  141. };
  142. static const u8 default_parent_ids[] = {
  143. SYSPLL, AVPLL_B4, AVPLL_A5, AVPLL_B6, AVPLL_B7, SYSPLL
  144. };
  145. static const struct berlin2_div_data bg2_divs[] __initconst = {
  146. {
  147. .name = "sys",
  148. .parent_ids = (const u8 []){
  149. SYSPLL, AVPLL_B4, AVPLL_B5, AVPLL_B6, AVPLL_B7, SYSPLL
  150. },
  151. .num_parents = 6,
  152. .map = {
  153. BERLIN2_DIV_GATE(REG_CLKENABLE, 0),
  154. BERLIN2_PLL_SELECT(REG_CLKSELECT0, 0),
  155. BERLIN2_DIV_SELECT(REG_CLKSELECT0, 3),
  156. BERLIN2_PLL_SWITCH(REG_CLKSWITCH0, 3),
  157. BERLIN2_DIV_SWITCH(REG_CLKSWITCH0, 4),
  158. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH0, 5),
  159. },
  160. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  161. .flags = CLK_IGNORE_UNUSED,
  162. },
  163. {
  164. .name = "cpu",
  165. .parent_ids = (const u8 []){
  166. CPUPLL, MEMPLL, MEMPLL, MEMPLL, MEMPLL
  167. },
  168. .num_parents = 5,
  169. .map = {
  170. BERLIN2_PLL_SELECT(REG_CLKSELECT0, 6),
  171. BERLIN2_DIV_SELECT(REG_CLKSELECT0, 9),
  172. BERLIN2_PLL_SWITCH(REG_CLKSWITCH0, 6),
  173. BERLIN2_DIV_SWITCH(REG_CLKSWITCH0, 7),
  174. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH0, 8),
  175. },
  176. .div_flags = BERLIN2_DIV_HAS_MUX,
  177. .flags = 0,
  178. },
  179. {
  180. .name = "drmfigo",
  181. .parent_ids = default_parent_ids,
  182. .num_parents = ARRAY_SIZE(default_parent_ids),
  183. .map = {
  184. BERLIN2_DIV_GATE(REG_CLKENABLE, 16),
  185. BERLIN2_PLL_SELECT(REG_CLKSELECT0, 17),
  186. BERLIN2_DIV_SELECT(REG_CLKSELECT0, 20),
  187. BERLIN2_PLL_SWITCH(REG_CLKSWITCH0, 12),
  188. BERLIN2_DIV_SWITCH(REG_CLKSWITCH0, 13),
  189. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH0, 14),
  190. },
  191. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  192. .flags = 0,
  193. },
  194. {
  195. .name = "cfg",
  196. .parent_ids = default_parent_ids,
  197. .num_parents = ARRAY_SIZE(default_parent_ids),
  198. .map = {
  199. BERLIN2_DIV_GATE(REG_CLKENABLE, 1),
  200. BERLIN2_PLL_SELECT(REG_CLKSELECT0, 23),
  201. BERLIN2_DIV_SELECT(REG_CLKSELECT0, 26),
  202. BERLIN2_PLL_SWITCH(REG_CLKSWITCH0, 15),
  203. BERLIN2_DIV_SWITCH(REG_CLKSWITCH0, 16),
  204. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH0, 17),
  205. },
  206. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  207. .flags = 0,
  208. },
  209. {
  210. .name = "gfx",
  211. .parent_ids = default_parent_ids,
  212. .num_parents = ARRAY_SIZE(default_parent_ids),
  213. .map = {
  214. BERLIN2_DIV_GATE(REG_CLKENABLE, 4),
  215. BERLIN2_PLL_SELECT(REG_CLKSELECT0, 29),
  216. BERLIN2_DIV_SELECT(REG_CLKSELECT1, 0),
  217. BERLIN2_PLL_SWITCH(REG_CLKSWITCH0, 18),
  218. BERLIN2_DIV_SWITCH(REG_CLKSWITCH0, 19),
  219. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH0, 20),
  220. },
  221. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  222. .flags = 0,
  223. },
  224. {
  225. .name = "zsp",
  226. .parent_ids = default_parent_ids,
  227. .num_parents = ARRAY_SIZE(default_parent_ids),
  228. .map = {
  229. BERLIN2_DIV_GATE(REG_CLKENABLE, 5),
  230. BERLIN2_PLL_SELECT(REG_CLKSELECT1, 3),
  231. BERLIN2_DIV_SELECT(REG_CLKSELECT1, 6),
  232. BERLIN2_PLL_SWITCH(REG_CLKSWITCH0, 21),
  233. BERLIN2_DIV_SWITCH(REG_CLKSWITCH0, 22),
  234. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH0, 23),
  235. },
  236. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  237. .flags = 0,
  238. },
  239. {
  240. .name = "perif",
  241. .parent_ids = default_parent_ids,
  242. .num_parents = ARRAY_SIZE(default_parent_ids),
  243. .map = {
  244. BERLIN2_DIV_GATE(REG_CLKENABLE, 6),
  245. BERLIN2_PLL_SELECT(REG_CLKSELECT1, 9),
  246. BERLIN2_DIV_SELECT(REG_CLKSELECT1, 12),
  247. BERLIN2_PLL_SWITCH(REG_CLKSWITCH0, 24),
  248. BERLIN2_DIV_SWITCH(REG_CLKSWITCH0, 25),
  249. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH0, 26),
  250. },
  251. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  252. .flags = CLK_IGNORE_UNUSED,
  253. },
  254. {
  255. .name = "pcube",
  256. .parent_ids = default_parent_ids,
  257. .num_parents = ARRAY_SIZE(default_parent_ids),
  258. .map = {
  259. BERLIN2_DIV_GATE(REG_CLKENABLE, 2),
  260. BERLIN2_PLL_SELECT(REG_CLKSELECT1, 15),
  261. BERLIN2_DIV_SELECT(REG_CLKSELECT1, 18),
  262. BERLIN2_PLL_SWITCH(REG_CLKSWITCH0, 27),
  263. BERLIN2_DIV_SWITCH(REG_CLKSWITCH0, 28),
  264. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH0, 29),
  265. },
  266. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  267. .flags = 0,
  268. },
  269. {
  270. .name = "vscope",
  271. .parent_ids = default_parent_ids,
  272. .num_parents = ARRAY_SIZE(default_parent_ids),
  273. .map = {
  274. BERLIN2_DIV_GATE(REG_CLKENABLE, 3),
  275. BERLIN2_PLL_SELECT(REG_CLKSELECT1, 21),
  276. BERLIN2_DIV_SELECT(REG_CLKSELECT1, 24),
  277. BERLIN2_PLL_SWITCH(REG_CLKSWITCH0, 30),
  278. BERLIN2_DIV_SWITCH(REG_CLKSWITCH0, 31),
  279. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH1, 0),
  280. },
  281. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  282. .flags = 0,
  283. },
  284. {
  285. .name = "nfc_ecc",
  286. .parent_ids = default_parent_ids,
  287. .num_parents = ARRAY_SIZE(default_parent_ids),
  288. .map = {
  289. BERLIN2_DIV_GATE(REG_CLKENABLE, 18),
  290. BERLIN2_PLL_SELECT(REG_CLKSELECT1, 27),
  291. BERLIN2_DIV_SELECT(REG_CLKSELECT2, 0),
  292. BERLIN2_PLL_SWITCH(REG_CLKSWITCH1, 1),
  293. BERLIN2_DIV_SWITCH(REG_CLKSWITCH1, 2),
  294. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH1, 3),
  295. },
  296. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  297. .flags = 0,
  298. },
  299. {
  300. .name = "vpp",
  301. .parent_ids = default_parent_ids,
  302. .num_parents = ARRAY_SIZE(default_parent_ids),
  303. .map = {
  304. BERLIN2_DIV_GATE(REG_CLKENABLE, 21),
  305. BERLIN2_PLL_SELECT(REG_CLKSELECT2, 3),
  306. BERLIN2_DIV_SELECT(REG_CLKSELECT2, 6),
  307. BERLIN2_PLL_SWITCH(REG_CLKSWITCH1, 4),
  308. BERLIN2_DIV_SWITCH(REG_CLKSWITCH1, 5),
  309. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH1, 6),
  310. },
  311. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  312. .flags = 0,
  313. },
  314. {
  315. .name = "app",
  316. .parent_ids = default_parent_ids,
  317. .num_parents = ARRAY_SIZE(default_parent_ids),
  318. .map = {
  319. BERLIN2_DIV_GATE(REG_CLKENABLE, 20),
  320. BERLIN2_PLL_SELECT(REG_CLKSELECT2, 9),
  321. BERLIN2_DIV_SELECT(REG_CLKSELECT2, 12),
  322. BERLIN2_PLL_SWITCH(REG_CLKSWITCH1, 7),
  323. BERLIN2_DIV_SWITCH(REG_CLKSWITCH1, 8),
  324. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH1, 9),
  325. },
  326. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  327. .flags = 0,
  328. },
  329. {
  330. .name = "audio0",
  331. .parent_ids = (const u8 []){ AUDIO_FAST_PLL },
  332. .num_parents = 1,
  333. .map = {
  334. BERLIN2_DIV_GATE(REG_CLKENABLE, 22),
  335. BERLIN2_DIV_SELECT(REG_CLKSELECT2, 17),
  336. BERLIN2_DIV_SWITCH(REG_CLKSWITCH1, 10),
  337. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH1, 11),
  338. },
  339. .div_flags = BERLIN2_DIV_HAS_GATE,
  340. .flags = 0,
  341. },
  342. {
  343. .name = "audio2",
  344. .parent_ids = (const u8 []){ AUDIO_FAST_PLL },
  345. .num_parents = 1,
  346. .map = {
  347. BERLIN2_DIV_GATE(REG_CLKENABLE, 24),
  348. BERLIN2_DIV_SELECT(REG_CLKSELECT2, 20),
  349. BERLIN2_DIV_SWITCH(REG_CLKSWITCH1, 14),
  350. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH1, 15),
  351. },
  352. .div_flags = BERLIN2_DIV_HAS_GATE,
  353. .flags = 0,
  354. },
  355. {
  356. .name = "audio3",
  357. .parent_ids = (const u8 []){ AUDIO_FAST_PLL },
  358. .num_parents = 1,
  359. .map = {
  360. BERLIN2_DIV_GATE(REG_CLKENABLE, 25),
  361. BERLIN2_DIV_SELECT(REG_CLKSELECT2, 23),
  362. BERLIN2_DIV_SWITCH(REG_CLKSWITCH1, 16),
  363. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH1, 17),
  364. },
  365. .div_flags = BERLIN2_DIV_HAS_GATE,
  366. .flags = 0,
  367. },
  368. {
  369. .name = "audio1",
  370. .parent_ids = (const u8 []){ AUDIO1_PLL },
  371. .num_parents = 1,
  372. .map = {
  373. BERLIN2_DIV_GATE(REG_CLKENABLE, 23),
  374. BERLIN2_DIV_SELECT(REG_CLKSELECT3, 0),
  375. BERLIN2_DIV_SWITCH(REG_CLKSWITCH1, 12),
  376. BERLIN2_DIV_D3SWITCH(REG_CLKSWITCH1, 13),
  377. },
  378. .div_flags = BERLIN2_DIV_HAS_GATE,
  379. .flags = 0,
  380. },
  381. {
  382. .name = "gfx3d_core",
  383. .parent_ids = default_parent_ids,
  384. .num_parents = ARRAY_SIZE(default_parent_ids),
  385. .map = {
  386. BERLIN2_SINGLE_DIV(REG_GFX3DCORE_CLKCTL),
  387. },
  388. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  389. .flags = 0,
  390. },
  391. {
  392. .name = "gfx3d_sys",
  393. .parent_ids = default_parent_ids,
  394. .num_parents = ARRAY_SIZE(default_parent_ids),
  395. .map = {
  396. BERLIN2_SINGLE_DIV(REG_GFX3DSYS_CLKCTL),
  397. },
  398. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  399. .flags = 0,
  400. },
  401. {
  402. .name = "arc",
  403. .parent_ids = default_parent_ids,
  404. .num_parents = ARRAY_SIZE(default_parent_ids),
  405. .map = {
  406. BERLIN2_SINGLE_DIV(REG_ARC_CLKCTL),
  407. },
  408. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  409. .flags = 0,
  410. },
  411. {
  412. .name = "vip",
  413. .parent_ids = default_parent_ids,
  414. .num_parents = ARRAY_SIZE(default_parent_ids),
  415. .map = {
  416. BERLIN2_SINGLE_DIV(REG_VIP_CLKCTL),
  417. },
  418. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  419. .flags = 0,
  420. },
  421. {
  422. .name = "sdio0xin",
  423. .parent_ids = default_parent_ids,
  424. .num_parents = ARRAY_SIZE(default_parent_ids),
  425. .map = {
  426. BERLIN2_SINGLE_DIV(REG_SDIO0XIN_CLKCTL),
  427. },
  428. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  429. .flags = 0,
  430. },
  431. {
  432. .name = "sdio1xin",
  433. .parent_ids = default_parent_ids,
  434. .num_parents = ARRAY_SIZE(default_parent_ids),
  435. .map = {
  436. BERLIN2_SINGLE_DIV(REG_SDIO1XIN_CLKCTL),
  437. },
  438. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  439. .flags = 0,
  440. },
  441. {
  442. .name = "gfx3d_extra",
  443. .parent_ids = default_parent_ids,
  444. .num_parents = ARRAY_SIZE(default_parent_ids),
  445. .map = {
  446. BERLIN2_SINGLE_DIV(REG_GFX3DEXTRA_CLKCTL),
  447. },
  448. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  449. .flags = 0,
  450. },
  451. {
  452. .name = "gc360",
  453. .parent_ids = default_parent_ids,
  454. .num_parents = ARRAY_SIZE(default_parent_ids),
  455. .map = {
  456. BERLIN2_SINGLE_DIV(REG_GC360_CLKCTL),
  457. },
  458. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  459. .flags = 0,
  460. },
  461. {
  462. .name = "sdio_dllmst",
  463. .parent_ids = default_parent_ids,
  464. .num_parents = ARRAY_SIZE(default_parent_ids),
  465. .map = {
  466. BERLIN2_SINGLE_DIV(REG_SDIO_DLLMST_CLKCTL),
  467. },
  468. .div_flags = BERLIN2_DIV_HAS_GATE | BERLIN2_DIV_HAS_MUX,
  469. .flags = 0,
  470. },
  471. };
  472. static const struct berlin2_gate_data bg2_gates[] __initconst = {
  473. { "geth0", "perif", 7 },
  474. { "geth1", "perif", 8 },
  475. { "sata", "perif", 9 },
  476. { "ahbapb", "perif", 10, CLK_IGNORE_UNUSED },
  477. { "usb0", "perif", 11 },
  478. { "usb1", "perif", 12 },
  479. { "pbridge", "perif", 13, CLK_IGNORE_UNUSED },
  480. { "sdio0", "perif", 14 },
  481. { "sdio1", "perif", 15 },
  482. { "nfc", "perif", 17 },
  483. { "smemc", "perif", 19 },
  484. { "audiohd", "audiohd_pll", 26 },
  485. { "video0", "video0_in", 27 },
  486. { "video1", "video1_in", 28 },
  487. { "video2", "video2_in", 29 },
  488. };
  489. static void __init berlin2_clock_setup(struct device_node *np)
  490. {
  491. struct device_node *parent_np = of_get_parent(np);
  492. const char *parent_names[9];
  493. struct clk *clk;
  494. struct clk_hw *hw;
  495. struct clk_hw **hws;
  496. u8 avpll_flags = 0;
  497. int n, ret;
  498. clk_data = kzalloc(sizeof(*clk_data) +
  499. sizeof(*clk_data->hws) * MAX_CLKS, GFP_KERNEL);
  500. if (!clk_data)
  501. return;
  502. clk_data->num = MAX_CLKS;
  503. hws = clk_data->hws;
  504. gbase = of_iomap(parent_np, 0);
  505. if (!gbase)
  506. return;
  507. /* overwrite default clock names with DT provided ones */
  508. clk = of_clk_get_by_name(np, clk_names[REFCLK]);
  509. if (!IS_ERR(clk)) {
  510. clk_names[REFCLK] = __clk_get_name(clk);
  511. clk_put(clk);
  512. }
  513. clk = of_clk_get_by_name(np, clk_names[VIDEO_EXT0]);
  514. if (!IS_ERR(clk)) {
  515. clk_names[VIDEO_EXT0] = __clk_get_name(clk);
  516. clk_put(clk);
  517. }
  518. /* simple register PLLs */
  519. ret = berlin2_pll_register(&bg2_pll_map, gbase + REG_SYSPLLCTL0,
  520. clk_names[SYSPLL], clk_names[REFCLK], 0);
  521. if (ret)
  522. goto bg2_fail;
  523. ret = berlin2_pll_register(&bg2_pll_map, gbase + REG_MEMPLLCTL0,
  524. clk_names[MEMPLL], clk_names[REFCLK], 0);
  525. if (ret)
  526. goto bg2_fail;
  527. ret = berlin2_pll_register(&bg2_pll_map, gbase + REG_CPUPLLCTL0,
  528. clk_names[CPUPLL], clk_names[REFCLK], 0);
  529. if (ret)
  530. goto bg2_fail;
  531. if (of_device_is_compatible(np, "marvell,berlin2-global-register"))
  532. avpll_flags |= BERLIN2_AVPLL_SCRAMBLE_QUIRK;
  533. /* audio/video VCOs */
  534. ret = berlin2_avpll_vco_register(gbase + REG_AVPLLCTL0, "avpll_vcoA",
  535. clk_names[REFCLK], avpll_flags, 0);
  536. if (ret)
  537. goto bg2_fail;
  538. for (n = 0; n < 8; n++) {
  539. ret = berlin2_avpll_channel_register(gbase + REG_AVPLLCTL0,
  540. clk_names[AVPLL_A1 + n], n, "avpll_vcoA",
  541. avpll_flags, 0);
  542. if (ret)
  543. goto bg2_fail;
  544. }
  545. ret = berlin2_avpll_vco_register(gbase + REG_AVPLLCTL31, "avpll_vcoB",
  546. clk_names[REFCLK], BERLIN2_AVPLL_BIT_QUIRK |
  547. avpll_flags, 0);
  548. if (ret)
  549. goto bg2_fail;
  550. for (n = 0; n < 8; n++) {
  551. ret = berlin2_avpll_channel_register(gbase + REG_AVPLLCTL31,
  552. clk_names[AVPLL_B1 + n], n, "avpll_vcoB",
  553. BERLIN2_AVPLL_BIT_QUIRK | avpll_flags, 0);
  554. if (ret)
  555. goto bg2_fail;
  556. }
  557. /* reference clock bypass switches */
  558. parent_names[0] = clk_names[SYSPLL];
  559. parent_names[1] = clk_names[REFCLK];
  560. hw = clk_hw_register_mux(NULL, "syspll_byp", parent_names, 2,
  561. 0, gbase + REG_CLKSWITCH0, 0, 1, 0, &lock);
  562. if (IS_ERR(hw))
  563. goto bg2_fail;
  564. clk_names[SYSPLL] = clk_hw_get_name(hw);
  565. parent_names[0] = clk_names[MEMPLL];
  566. parent_names[1] = clk_names[REFCLK];
  567. hw = clk_hw_register_mux(NULL, "mempll_byp", parent_names, 2,
  568. 0, gbase + REG_CLKSWITCH0, 1, 1, 0, &lock);
  569. if (IS_ERR(hw))
  570. goto bg2_fail;
  571. clk_names[MEMPLL] = clk_hw_get_name(hw);
  572. parent_names[0] = clk_names[CPUPLL];
  573. parent_names[1] = clk_names[REFCLK];
  574. hw = clk_hw_register_mux(NULL, "cpupll_byp", parent_names, 2,
  575. 0, gbase + REG_CLKSWITCH0, 2, 1, 0, &lock);
  576. if (IS_ERR(hw))
  577. goto bg2_fail;
  578. clk_names[CPUPLL] = clk_hw_get_name(hw);
  579. /* clock muxes */
  580. parent_names[0] = clk_names[AVPLL_B3];
  581. parent_names[1] = clk_names[AVPLL_A3];
  582. hw = clk_hw_register_mux(NULL, clk_names[AUDIO1_PLL], parent_names, 2,
  583. 0, gbase + REG_CLKSELECT2, 29, 1, 0, &lock);
  584. if (IS_ERR(hw))
  585. goto bg2_fail;
  586. parent_names[0] = clk_names[VIDEO0_PLL];
  587. parent_names[1] = clk_names[VIDEO_EXT0];
  588. hw = clk_hw_register_mux(NULL, clk_names[VIDEO0_IN], parent_names, 2,
  589. 0, gbase + REG_CLKSELECT3, 4, 1, 0, &lock);
  590. if (IS_ERR(hw))
  591. goto bg2_fail;
  592. parent_names[0] = clk_names[VIDEO1_PLL];
  593. parent_names[1] = clk_names[VIDEO_EXT0];
  594. hw = clk_hw_register_mux(NULL, clk_names[VIDEO1_IN], parent_names, 2,
  595. 0, gbase + REG_CLKSELECT3, 6, 1, 0, &lock);
  596. if (IS_ERR(hw))
  597. goto bg2_fail;
  598. parent_names[0] = clk_names[AVPLL_A2];
  599. parent_names[1] = clk_names[AVPLL_B2];
  600. hw = clk_hw_register_mux(NULL, clk_names[VIDEO1_PLL], parent_names, 2,
  601. 0, gbase + REG_CLKSELECT3, 7, 1, 0, &lock);
  602. if (IS_ERR(hw))
  603. goto bg2_fail;
  604. parent_names[0] = clk_names[VIDEO2_PLL];
  605. parent_names[1] = clk_names[VIDEO_EXT0];
  606. hw = clk_hw_register_mux(NULL, clk_names[VIDEO2_IN], parent_names, 2,
  607. 0, gbase + REG_CLKSELECT3, 9, 1, 0, &lock);
  608. if (IS_ERR(hw))
  609. goto bg2_fail;
  610. parent_names[0] = clk_names[AVPLL_B1];
  611. parent_names[1] = clk_names[AVPLL_A5];
  612. hw = clk_hw_register_mux(NULL, clk_names[VIDEO2_PLL], parent_names, 2,
  613. 0, gbase + REG_CLKSELECT3, 10, 1, 0, &lock);
  614. if (IS_ERR(hw))
  615. goto bg2_fail;
  616. /* clock divider cells */
  617. for (n = 0; n < ARRAY_SIZE(bg2_divs); n++) {
  618. const struct berlin2_div_data *dd = &bg2_divs[n];
  619. int k;
  620. for (k = 0; k < dd->num_parents; k++)
  621. parent_names[k] = clk_names[dd->parent_ids[k]];
  622. hws[CLKID_SYS + n] = berlin2_div_register(&dd->map, gbase,
  623. dd->name, dd->div_flags, parent_names,
  624. dd->num_parents, dd->flags, &lock);
  625. }
  626. /* clock gate cells */
  627. for (n = 0; n < ARRAY_SIZE(bg2_gates); n++) {
  628. const struct berlin2_gate_data *gd = &bg2_gates[n];
  629. hws[CLKID_GETH0 + n] = clk_hw_register_gate(NULL, gd->name,
  630. gd->parent_name, gd->flags, gbase + REG_CLKENABLE,
  631. gd->bit_idx, 0, &lock);
  632. }
  633. /* twdclk is derived from cpu/3 */
  634. hws[CLKID_TWD] =
  635. clk_hw_register_fixed_factor(NULL, "twd", "cpu", 0, 1, 3);
  636. /* check for errors on leaf clocks */
  637. for (n = 0; n < MAX_CLKS; n++) {
  638. if (!IS_ERR(hws[n]))
  639. continue;
  640. pr_err("%pOF: Unable to register leaf clock %d\n", np, n);
  641. goto bg2_fail;
  642. }
  643. /* register clk-provider */
  644. of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
  645. return;
  646. bg2_fail:
  647. iounmap(gbase);
  648. }
  649. CLK_OF_DECLARE(berlin2_clk, "marvell,berlin2-clk",
  650. berlin2_clock_setup);