clk-qoriq.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. /*
  2. * Copyright 2013 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * clock driver for Freescale QorIQ SoCs.
  9. */
  10. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #include <linux/clk.h>
  12. #include <linux/clk-provider.h>
  13. #include <linux/fsl/guts.h>
  14. #include <linux/io.h>
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/of.h>
  20. #include <linux/slab.h>
  21. #define PLL_DIV1 0
  22. #define PLL_DIV2 1
  23. #define PLL_DIV3 2
  24. #define PLL_DIV4 3
  25. #define PLATFORM_PLL 0
  26. #define CGA_PLL1 1
  27. #define CGA_PLL2 2
  28. #define CGA_PLL3 3
  29. #define CGA_PLL4 4 /* only on clockgen-1.0, which lacks CGB */
  30. #define CGB_PLL1 4
  31. #define CGB_PLL2 5
  32. struct clockgen_pll_div {
  33. struct clk *clk;
  34. char name[32];
  35. };
  36. struct clockgen_pll {
  37. struct clockgen_pll_div div[4];
  38. };
  39. #define CLKSEL_VALID 1
  40. #define CLKSEL_80PCT 2 /* Only allowed if PLL <= 80% of max cpu freq */
  41. struct clockgen_sourceinfo {
  42. u32 flags; /* CLKSEL_xxx */
  43. int pll; /* CGx_PLLn */
  44. int div; /* PLL_DIVn */
  45. };
  46. #define NUM_MUX_PARENTS 16
  47. struct clockgen_muxinfo {
  48. struct clockgen_sourceinfo clksel[NUM_MUX_PARENTS];
  49. };
  50. #define NUM_HWACCEL 5
  51. #define NUM_CMUX 8
  52. struct clockgen;
  53. /*
  54. * cmux freq must be >= platform pll.
  55. * If not set, cmux freq must be >= platform pll/2
  56. */
  57. #define CG_CMUX_GE_PLAT 1
  58. #define CG_PLL_8BIT 2 /* PLLCnGSR[CFG] is 8 bits, not 6 */
  59. #define CG_VER3 4 /* version 3 cg: reg layout different */
  60. #define CG_LITTLE_ENDIAN 8
  61. struct clockgen_chipinfo {
  62. const char *compat, *guts_compat;
  63. const struct clockgen_muxinfo *cmux_groups[2];
  64. const struct clockgen_muxinfo *hwaccel[NUM_HWACCEL];
  65. void (*init_periph)(struct clockgen *cg);
  66. int cmux_to_group[NUM_CMUX]; /* -1 terminates if fewer than NUM_CMUX */
  67. u32 pll_mask; /* 1 << n bit set if PLL n is valid */
  68. u32 flags; /* CG_xxx */
  69. };
  70. struct clockgen {
  71. struct device_node *node;
  72. void __iomem *regs;
  73. struct clockgen_chipinfo info; /* mutable copy */
  74. struct clk *sysclk;
  75. struct clockgen_pll pll[6];
  76. struct clk *cmux[NUM_CMUX];
  77. struct clk *hwaccel[NUM_HWACCEL];
  78. struct clk *fman[2];
  79. struct ccsr_guts __iomem *guts;
  80. };
  81. static struct clockgen clockgen;
  82. static void cg_out(struct clockgen *cg, u32 val, u32 __iomem *reg)
  83. {
  84. if (cg->info.flags & CG_LITTLE_ENDIAN)
  85. iowrite32(val, reg);
  86. else
  87. iowrite32be(val, reg);
  88. }
  89. static u32 cg_in(struct clockgen *cg, u32 __iomem *reg)
  90. {
  91. u32 val;
  92. if (cg->info.flags & CG_LITTLE_ENDIAN)
  93. val = ioread32(reg);
  94. else
  95. val = ioread32be(reg);
  96. return val;
  97. }
  98. static const struct clockgen_muxinfo p2041_cmux_grp1 = {
  99. {
  100. [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  101. [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  102. [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  103. }
  104. };
  105. static const struct clockgen_muxinfo p2041_cmux_grp2 = {
  106. {
  107. [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  108. [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  109. [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  110. }
  111. };
  112. static const struct clockgen_muxinfo p5020_cmux_grp1 = {
  113. {
  114. [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  115. [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  116. [4] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL2, PLL_DIV1 },
  117. }
  118. };
  119. static const struct clockgen_muxinfo p5020_cmux_grp2 = {
  120. {
  121. [0] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL1, PLL_DIV1 },
  122. [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  123. [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  124. }
  125. };
  126. static const struct clockgen_muxinfo p5040_cmux_grp1 = {
  127. {
  128. [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  129. [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  130. [4] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL2, PLL_DIV1 },
  131. [5] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL2, PLL_DIV2 },
  132. }
  133. };
  134. static const struct clockgen_muxinfo p5040_cmux_grp2 = {
  135. {
  136. [0] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL1, PLL_DIV1 },
  137. [1] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL1, PLL_DIV2 },
  138. [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  139. [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  140. }
  141. };
  142. static const struct clockgen_muxinfo p4080_cmux_grp1 = {
  143. {
  144. [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  145. [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  146. [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  147. [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  148. [8] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL3, PLL_DIV1 },
  149. }
  150. };
  151. static const struct clockgen_muxinfo p4080_cmux_grp2 = {
  152. {
  153. [0] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL1, PLL_DIV1 },
  154. [8] = { CLKSEL_VALID, CGA_PLL3, PLL_DIV1 },
  155. [9] = { CLKSEL_VALID, CGA_PLL3, PLL_DIV2 },
  156. [12] = { CLKSEL_VALID, CGA_PLL4, PLL_DIV1 },
  157. [13] = { CLKSEL_VALID, CGA_PLL4, PLL_DIV2 },
  158. }
  159. };
  160. static const struct clockgen_muxinfo t1023_cmux = {
  161. {
  162. [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  163. [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  164. }
  165. };
  166. static const struct clockgen_muxinfo t1040_cmux = {
  167. {
  168. [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  169. [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  170. [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  171. [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  172. }
  173. };
  174. static const struct clockgen_muxinfo clockgen2_cmux_cga = {
  175. {
  176. { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  177. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  178. { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 },
  179. {},
  180. { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  181. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  182. { CLKSEL_VALID, CGA_PLL2, PLL_DIV4 },
  183. {},
  184. { CLKSEL_VALID, CGA_PLL3, PLL_DIV1 },
  185. { CLKSEL_VALID, CGA_PLL3, PLL_DIV2 },
  186. { CLKSEL_VALID, CGA_PLL3, PLL_DIV4 },
  187. },
  188. };
  189. static const struct clockgen_muxinfo clockgen2_cmux_cga12 = {
  190. {
  191. { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  192. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  193. { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 },
  194. {},
  195. { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  196. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  197. { CLKSEL_VALID, CGA_PLL2, PLL_DIV4 },
  198. },
  199. };
  200. static const struct clockgen_muxinfo clockgen2_cmux_cgb = {
  201. {
  202. { CLKSEL_VALID, CGB_PLL1, PLL_DIV1 },
  203. { CLKSEL_VALID, CGB_PLL1, PLL_DIV2 },
  204. { CLKSEL_VALID, CGB_PLL1, PLL_DIV4 },
  205. {},
  206. { CLKSEL_VALID, CGB_PLL2, PLL_DIV1 },
  207. { CLKSEL_VALID, CGB_PLL2, PLL_DIV2 },
  208. { CLKSEL_VALID, CGB_PLL2, PLL_DIV4 },
  209. },
  210. };
  211. static const struct clockgen_muxinfo ls1043a_hwa1 = {
  212. {
  213. {},
  214. {},
  215. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  216. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  217. {},
  218. {},
  219. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  220. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  221. },
  222. };
  223. static const struct clockgen_muxinfo ls1043a_hwa2 = {
  224. {
  225. {},
  226. { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  227. {},
  228. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  229. },
  230. };
  231. static const struct clockgen_muxinfo t1023_hwa1 = {
  232. {
  233. {},
  234. { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  235. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  236. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  237. },
  238. };
  239. static const struct clockgen_muxinfo t1023_hwa2 = {
  240. {
  241. [6] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  242. },
  243. };
  244. static const struct clockgen_muxinfo t2080_hwa1 = {
  245. {
  246. {},
  247. { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  248. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  249. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  250. { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 },
  251. { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 },
  252. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  253. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  254. },
  255. };
  256. static const struct clockgen_muxinfo t2080_hwa2 = {
  257. {
  258. {},
  259. { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  260. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  261. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  262. { CLKSEL_VALID, CGA_PLL2, PLL_DIV4 },
  263. { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 },
  264. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  265. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  266. },
  267. };
  268. static const struct clockgen_muxinfo t4240_hwa1 = {
  269. {
  270. { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV2 },
  271. { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  272. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  273. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  274. { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 },
  275. {},
  276. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  277. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  278. },
  279. };
  280. static const struct clockgen_muxinfo t4240_hwa4 = {
  281. {
  282. [2] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV2 },
  283. [3] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV3 },
  284. [4] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV4 },
  285. [5] = { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 },
  286. [6] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV2 },
  287. },
  288. };
  289. static const struct clockgen_muxinfo t4240_hwa5 = {
  290. {
  291. [2] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV2 },
  292. [3] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV3 },
  293. [4] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV4 },
  294. [5] = { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 },
  295. [6] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV2 },
  296. [7] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV3 },
  297. },
  298. };
  299. #define RCWSR7_FM1_CLK_SEL 0x40000000
  300. #define RCWSR7_FM2_CLK_SEL 0x20000000
  301. #define RCWSR7_HWA_ASYNC_DIV 0x04000000
  302. static void __init p2041_init_periph(struct clockgen *cg)
  303. {
  304. u32 reg;
  305. reg = ioread32be(&cg->guts->rcwsr[7]);
  306. if (reg & RCWSR7_FM1_CLK_SEL)
  307. cg->fman[0] = cg->pll[CGA_PLL2].div[PLL_DIV2].clk;
  308. else
  309. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  310. }
  311. static void __init p4080_init_periph(struct clockgen *cg)
  312. {
  313. u32 reg;
  314. reg = ioread32be(&cg->guts->rcwsr[7]);
  315. if (reg & RCWSR7_FM1_CLK_SEL)
  316. cg->fman[0] = cg->pll[CGA_PLL3].div[PLL_DIV2].clk;
  317. else
  318. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  319. if (reg & RCWSR7_FM2_CLK_SEL)
  320. cg->fman[1] = cg->pll[CGA_PLL3].div[PLL_DIV2].clk;
  321. else
  322. cg->fman[1] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  323. }
  324. static void __init p5020_init_periph(struct clockgen *cg)
  325. {
  326. u32 reg;
  327. int div = PLL_DIV2;
  328. reg = ioread32be(&cg->guts->rcwsr[7]);
  329. if (reg & RCWSR7_HWA_ASYNC_DIV)
  330. div = PLL_DIV4;
  331. if (reg & RCWSR7_FM1_CLK_SEL)
  332. cg->fman[0] = cg->pll[CGA_PLL2].div[div].clk;
  333. else
  334. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  335. }
  336. static void __init p5040_init_periph(struct clockgen *cg)
  337. {
  338. u32 reg;
  339. int div = PLL_DIV2;
  340. reg = ioread32be(&cg->guts->rcwsr[7]);
  341. if (reg & RCWSR7_HWA_ASYNC_DIV)
  342. div = PLL_DIV4;
  343. if (reg & RCWSR7_FM1_CLK_SEL)
  344. cg->fman[0] = cg->pll[CGA_PLL3].div[div].clk;
  345. else
  346. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  347. if (reg & RCWSR7_FM2_CLK_SEL)
  348. cg->fman[1] = cg->pll[CGA_PLL3].div[div].clk;
  349. else
  350. cg->fman[1] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  351. }
  352. static void __init t1023_init_periph(struct clockgen *cg)
  353. {
  354. cg->fman[0] = cg->hwaccel[1];
  355. }
  356. static void __init t1040_init_periph(struct clockgen *cg)
  357. {
  358. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV1].clk;
  359. }
  360. static void __init t2080_init_periph(struct clockgen *cg)
  361. {
  362. cg->fman[0] = cg->hwaccel[0];
  363. }
  364. static void __init t4240_init_periph(struct clockgen *cg)
  365. {
  366. cg->fman[0] = cg->hwaccel[3];
  367. cg->fman[1] = cg->hwaccel[4];
  368. }
  369. static const struct clockgen_chipinfo chipinfo[] = {
  370. {
  371. .compat = "fsl,b4420-clockgen",
  372. .guts_compat = "fsl,b4860-device-config",
  373. .init_periph = t2080_init_periph,
  374. .cmux_groups = {
  375. &clockgen2_cmux_cga12, &clockgen2_cmux_cgb
  376. },
  377. .hwaccel = {
  378. &t2080_hwa1
  379. },
  380. .cmux_to_group = {
  381. 0, 1, 1, 1, -1
  382. },
  383. .pll_mask = 0x3f,
  384. .flags = CG_PLL_8BIT,
  385. },
  386. {
  387. .compat = "fsl,b4860-clockgen",
  388. .guts_compat = "fsl,b4860-device-config",
  389. .init_periph = t2080_init_periph,
  390. .cmux_groups = {
  391. &clockgen2_cmux_cga12, &clockgen2_cmux_cgb
  392. },
  393. .hwaccel = {
  394. &t2080_hwa1
  395. },
  396. .cmux_to_group = {
  397. 0, 1, 1, 1, -1
  398. },
  399. .pll_mask = 0x3f,
  400. .flags = CG_PLL_8BIT,
  401. },
  402. {
  403. .compat = "fsl,ls1021a-clockgen",
  404. .cmux_groups = {
  405. &t1023_cmux
  406. },
  407. .cmux_to_group = {
  408. 0, -1
  409. },
  410. .pll_mask = 0x03,
  411. },
  412. {
  413. .compat = "fsl,ls1043a-clockgen",
  414. .init_periph = t2080_init_periph,
  415. .cmux_groups = {
  416. &t1040_cmux
  417. },
  418. .hwaccel = {
  419. &ls1043a_hwa1, &ls1043a_hwa2
  420. },
  421. .cmux_to_group = {
  422. 0, -1
  423. },
  424. .pll_mask = 0x07,
  425. .flags = CG_PLL_8BIT,
  426. },
  427. {
  428. .compat = "fsl,ls2080a-clockgen",
  429. .cmux_groups = {
  430. &clockgen2_cmux_cga12, &clockgen2_cmux_cgb
  431. },
  432. .cmux_to_group = {
  433. 0, 0, 1, 1, -1
  434. },
  435. .pll_mask = 0x37,
  436. .flags = CG_VER3 | CG_LITTLE_ENDIAN,
  437. },
  438. {
  439. .compat = "fsl,p2041-clockgen",
  440. .guts_compat = "fsl,qoriq-device-config-1.0",
  441. .init_periph = p2041_init_periph,
  442. .cmux_groups = {
  443. &p2041_cmux_grp1, &p2041_cmux_grp2
  444. },
  445. .cmux_to_group = {
  446. 0, 0, 1, 1, -1
  447. },
  448. .pll_mask = 0x07,
  449. },
  450. {
  451. .compat = "fsl,p3041-clockgen",
  452. .guts_compat = "fsl,qoriq-device-config-1.0",
  453. .init_periph = p2041_init_periph,
  454. .cmux_groups = {
  455. &p2041_cmux_grp1, &p2041_cmux_grp2
  456. },
  457. .cmux_to_group = {
  458. 0, 0, 1, 1, -1
  459. },
  460. .pll_mask = 0x07,
  461. },
  462. {
  463. .compat = "fsl,p4080-clockgen",
  464. .guts_compat = "fsl,qoriq-device-config-1.0",
  465. .init_periph = p4080_init_periph,
  466. .cmux_groups = {
  467. &p4080_cmux_grp1, &p4080_cmux_grp2
  468. },
  469. .cmux_to_group = {
  470. 0, 0, 0, 0, 1, 1, 1, 1
  471. },
  472. .pll_mask = 0x1f,
  473. },
  474. {
  475. .compat = "fsl,p5020-clockgen",
  476. .guts_compat = "fsl,qoriq-device-config-1.0",
  477. .init_periph = p5020_init_periph,
  478. .cmux_groups = {
  479. &p2041_cmux_grp1, &p2041_cmux_grp2
  480. },
  481. .cmux_to_group = {
  482. 0, 1, -1
  483. },
  484. .pll_mask = 0x07,
  485. },
  486. {
  487. .compat = "fsl,p5040-clockgen",
  488. .guts_compat = "fsl,p5040-device-config",
  489. .init_periph = p5040_init_periph,
  490. .cmux_groups = {
  491. &p5040_cmux_grp1, &p5040_cmux_grp2
  492. },
  493. .cmux_to_group = {
  494. 0, 0, 1, 1, -1
  495. },
  496. .pll_mask = 0x0f,
  497. },
  498. {
  499. .compat = "fsl,t1023-clockgen",
  500. .guts_compat = "fsl,t1023-device-config",
  501. .init_periph = t1023_init_periph,
  502. .cmux_groups = {
  503. &t1023_cmux
  504. },
  505. .hwaccel = {
  506. &t1023_hwa1, &t1023_hwa2
  507. },
  508. .cmux_to_group = {
  509. 0, 0, -1
  510. },
  511. .pll_mask = 0x03,
  512. .flags = CG_PLL_8BIT,
  513. },
  514. {
  515. .compat = "fsl,t1040-clockgen",
  516. .guts_compat = "fsl,t1040-device-config",
  517. .init_periph = t1040_init_periph,
  518. .cmux_groups = {
  519. &t1040_cmux
  520. },
  521. .cmux_to_group = {
  522. 0, 0, 0, 0, -1
  523. },
  524. .pll_mask = 0x07,
  525. .flags = CG_PLL_8BIT,
  526. },
  527. {
  528. .compat = "fsl,t2080-clockgen",
  529. .guts_compat = "fsl,t2080-device-config",
  530. .init_periph = t2080_init_periph,
  531. .cmux_groups = {
  532. &clockgen2_cmux_cga12
  533. },
  534. .hwaccel = {
  535. &t2080_hwa1, &t2080_hwa2
  536. },
  537. .cmux_to_group = {
  538. 0, -1
  539. },
  540. .pll_mask = 0x07,
  541. .flags = CG_PLL_8BIT,
  542. },
  543. {
  544. .compat = "fsl,t4240-clockgen",
  545. .guts_compat = "fsl,t4240-device-config",
  546. .init_periph = t4240_init_periph,
  547. .cmux_groups = {
  548. &clockgen2_cmux_cga, &clockgen2_cmux_cgb
  549. },
  550. .hwaccel = {
  551. &t4240_hwa1, NULL, NULL, &t4240_hwa4, &t4240_hwa5
  552. },
  553. .cmux_to_group = {
  554. 0, 0, 1, -1
  555. },
  556. .pll_mask = 0x3f,
  557. .flags = CG_PLL_8BIT,
  558. },
  559. {},
  560. };
  561. struct mux_hwclock {
  562. struct clk_hw hw;
  563. struct clockgen *cg;
  564. const struct clockgen_muxinfo *info;
  565. u32 __iomem *reg;
  566. u8 parent_to_clksel[NUM_MUX_PARENTS];
  567. s8 clksel_to_parent[NUM_MUX_PARENTS];
  568. int num_parents;
  569. };
  570. #define to_mux_hwclock(p) container_of(p, struct mux_hwclock, hw)
  571. #define CLKSEL_MASK 0x78000000
  572. #define CLKSEL_SHIFT 27
  573. static int mux_set_parent(struct clk_hw *hw, u8 idx)
  574. {
  575. struct mux_hwclock *hwc = to_mux_hwclock(hw);
  576. u32 clksel;
  577. if (idx >= hwc->num_parents)
  578. return -EINVAL;
  579. clksel = hwc->parent_to_clksel[idx];
  580. cg_out(hwc->cg, (clksel << CLKSEL_SHIFT) & CLKSEL_MASK, hwc->reg);
  581. return 0;
  582. }
  583. static u8 mux_get_parent(struct clk_hw *hw)
  584. {
  585. struct mux_hwclock *hwc = to_mux_hwclock(hw);
  586. u32 clksel;
  587. s8 ret;
  588. clksel = (cg_in(hwc->cg, hwc->reg) & CLKSEL_MASK) >> CLKSEL_SHIFT;
  589. ret = hwc->clksel_to_parent[clksel];
  590. if (ret < 0) {
  591. pr_err("%s: mux at %p has bad clksel\n", __func__, hwc->reg);
  592. return 0;
  593. }
  594. return ret;
  595. }
  596. static const struct clk_ops cmux_ops = {
  597. .get_parent = mux_get_parent,
  598. .set_parent = mux_set_parent,
  599. };
  600. /*
  601. * Don't allow setting for now, as the clock options haven't been
  602. * sanitized for additional restrictions.
  603. */
  604. static const struct clk_ops hwaccel_ops = {
  605. .get_parent = mux_get_parent,
  606. };
  607. static const struct clockgen_pll_div *get_pll_div(struct clockgen *cg,
  608. struct mux_hwclock *hwc,
  609. int idx)
  610. {
  611. int pll, div;
  612. if (!(hwc->info->clksel[idx].flags & CLKSEL_VALID))
  613. return NULL;
  614. pll = hwc->info->clksel[idx].pll;
  615. div = hwc->info->clksel[idx].div;
  616. return &cg->pll[pll].div[div];
  617. }
  618. static struct clk * __init create_mux_common(struct clockgen *cg,
  619. struct mux_hwclock *hwc,
  620. const struct clk_ops *ops,
  621. unsigned long min_rate,
  622. unsigned long max_rate,
  623. unsigned long pct80_rate,
  624. const char *fmt, int idx)
  625. {
  626. struct clk_init_data init = {};
  627. struct clk *clk;
  628. const struct clockgen_pll_div *div;
  629. const char *parent_names[NUM_MUX_PARENTS];
  630. char name[32];
  631. int i, j;
  632. snprintf(name, sizeof(name), fmt, idx);
  633. for (i = 0, j = 0; i < NUM_MUX_PARENTS; i++) {
  634. unsigned long rate;
  635. hwc->clksel_to_parent[i] = -1;
  636. div = get_pll_div(cg, hwc, i);
  637. if (!div)
  638. continue;
  639. rate = clk_get_rate(div->clk);
  640. if (hwc->info->clksel[i].flags & CLKSEL_80PCT &&
  641. rate > pct80_rate)
  642. continue;
  643. if (rate < min_rate)
  644. continue;
  645. if (rate > max_rate)
  646. continue;
  647. parent_names[j] = div->name;
  648. hwc->parent_to_clksel[j] = i;
  649. hwc->clksel_to_parent[i] = j;
  650. j++;
  651. }
  652. init.name = name;
  653. init.ops = ops;
  654. init.parent_names = parent_names;
  655. init.num_parents = hwc->num_parents = j;
  656. init.flags = 0;
  657. hwc->hw.init = &init;
  658. hwc->cg = cg;
  659. clk = clk_register(NULL, &hwc->hw);
  660. if (IS_ERR(clk)) {
  661. pr_err("%s: Couldn't register %s: %ld\n", __func__, name,
  662. PTR_ERR(clk));
  663. kfree(hwc);
  664. return NULL;
  665. }
  666. return clk;
  667. }
  668. static struct clk * __init create_one_cmux(struct clockgen *cg, int idx)
  669. {
  670. struct mux_hwclock *hwc;
  671. const struct clockgen_pll_div *div;
  672. unsigned long plat_rate, min_rate;
  673. u64 max_rate, pct80_rate;
  674. u32 clksel;
  675. hwc = kzalloc(sizeof(*hwc), GFP_KERNEL);
  676. if (!hwc)
  677. return NULL;
  678. if (cg->info.flags & CG_VER3)
  679. hwc->reg = cg->regs + 0x70000 + 0x20 * idx;
  680. else
  681. hwc->reg = cg->regs + 0x20 * idx;
  682. hwc->info = cg->info.cmux_groups[cg->info.cmux_to_group[idx]];
  683. /*
  684. * Find the rate for the default clksel, and treat it as the
  685. * maximum rated core frequency. If this is an incorrect
  686. * assumption, certain clock options (possibly including the
  687. * default clksel) may be inappropriately excluded on certain
  688. * chips.
  689. */
  690. clksel = (cg_in(cg, hwc->reg) & CLKSEL_MASK) >> CLKSEL_SHIFT;
  691. div = get_pll_div(cg, hwc, clksel);
  692. if (!div) {
  693. kfree(hwc);
  694. return NULL;
  695. }
  696. max_rate = clk_get_rate(div->clk);
  697. pct80_rate = max_rate * 8;
  698. do_div(pct80_rate, 10);
  699. plat_rate = clk_get_rate(cg->pll[PLATFORM_PLL].div[PLL_DIV1].clk);
  700. if (cg->info.flags & CG_CMUX_GE_PLAT)
  701. min_rate = plat_rate;
  702. else
  703. min_rate = plat_rate / 2;
  704. return create_mux_common(cg, hwc, &cmux_ops, min_rate, max_rate,
  705. pct80_rate, "cg-cmux%d", idx);
  706. }
  707. static struct clk * __init create_one_hwaccel(struct clockgen *cg, int idx)
  708. {
  709. struct mux_hwclock *hwc;
  710. hwc = kzalloc(sizeof(*hwc), GFP_KERNEL);
  711. if (!hwc)
  712. return NULL;
  713. hwc->reg = cg->regs + 0x20 * idx + 0x10;
  714. hwc->info = cg->info.hwaccel[idx];
  715. return create_mux_common(cg, hwc, &hwaccel_ops, 0, ULONG_MAX, 0,
  716. "cg-hwaccel%d", idx);
  717. }
  718. static void __init create_muxes(struct clockgen *cg)
  719. {
  720. int i;
  721. for (i = 0; i < ARRAY_SIZE(cg->cmux); i++) {
  722. if (cg->info.cmux_to_group[i] < 0)
  723. break;
  724. if (cg->info.cmux_to_group[i] >=
  725. ARRAY_SIZE(cg->info.cmux_groups)) {
  726. WARN_ON_ONCE(1);
  727. continue;
  728. }
  729. cg->cmux[i] = create_one_cmux(cg, i);
  730. }
  731. for (i = 0; i < ARRAY_SIZE(cg->hwaccel); i++) {
  732. if (!cg->info.hwaccel[i])
  733. continue;
  734. cg->hwaccel[i] = create_one_hwaccel(cg, i);
  735. }
  736. }
  737. static void __init clockgen_init(struct device_node *np);
  738. /* Legacy nodes may get probed before the parent clockgen node */
  739. static void __init legacy_init_clockgen(struct device_node *np)
  740. {
  741. if (!clockgen.node)
  742. clockgen_init(of_get_parent(np));
  743. }
  744. /* Legacy node */
  745. static void __init core_mux_init(struct device_node *np)
  746. {
  747. struct clk *clk;
  748. struct resource res;
  749. int idx, rc;
  750. legacy_init_clockgen(np);
  751. if (of_address_to_resource(np, 0, &res))
  752. return;
  753. idx = (res.start & 0xf0) >> 5;
  754. clk = clockgen.cmux[idx];
  755. rc = of_clk_add_provider(np, of_clk_src_simple_get, clk);
  756. if (rc) {
  757. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  758. __func__, np->name, rc);
  759. return;
  760. }
  761. }
  762. static struct clk __init
  763. *sysclk_from_fixed(struct device_node *node, const char *name)
  764. {
  765. u32 rate;
  766. if (of_property_read_u32(node, "clock-frequency", &rate))
  767. return ERR_PTR(-ENODEV);
  768. return clk_register_fixed_rate(NULL, name, NULL, 0, rate);
  769. }
  770. static struct clk *sysclk_from_parent(const char *name)
  771. {
  772. struct clk *clk;
  773. const char *parent_name;
  774. clk = of_clk_get(clockgen.node, 0);
  775. if (IS_ERR(clk))
  776. return clk;
  777. /* Register the input clock under the desired name. */
  778. parent_name = __clk_get_name(clk);
  779. clk = clk_register_fixed_factor(NULL, name, parent_name,
  780. 0, 1, 1);
  781. if (IS_ERR(clk))
  782. pr_err("%s: Couldn't register %s: %ld\n", __func__, name,
  783. PTR_ERR(clk));
  784. return clk;
  785. }
  786. static struct clk * __init create_sysclk(const char *name)
  787. {
  788. struct device_node *sysclk;
  789. struct clk *clk;
  790. clk = sysclk_from_fixed(clockgen.node, name);
  791. if (!IS_ERR(clk))
  792. return clk;
  793. clk = sysclk_from_parent(name);
  794. if (!IS_ERR(clk))
  795. return clk;
  796. sysclk = of_get_child_by_name(clockgen.node, "sysclk");
  797. if (sysclk) {
  798. clk = sysclk_from_fixed(sysclk, name);
  799. if (!IS_ERR(clk))
  800. return clk;
  801. }
  802. pr_err("%s: No input clock\n", __func__);
  803. return NULL;
  804. }
  805. /* Legacy node */
  806. static void __init sysclk_init(struct device_node *node)
  807. {
  808. struct clk *clk;
  809. legacy_init_clockgen(node);
  810. clk = clockgen.sysclk;
  811. if (clk)
  812. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  813. }
  814. #define PLL_KILL BIT(31)
  815. static void __init create_one_pll(struct clockgen *cg, int idx)
  816. {
  817. u32 __iomem *reg;
  818. u32 mult;
  819. struct clockgen_pll *pll = &cg->pll[idx];
  820. int i;
  821. if (!(cg->info.pll_mask & (1 << idx)))
  822. return;
  823. if (cg->info.flags & CG_VER3) {
  824. switch (idx) {
  825. case PLATFORM_PLL:
  826. reg = cg->regs + 0x60080;
  827. break;
  828. case CGA_PLL1:
  829. reg = cg->regs + 0x80;
  830. break;
  831. case CGA_PLL2:
  832. reg = cg->regs + 0xa0;
  833. break;
  834. case CGB_PLL1:
  835. reg = cg->regs + 0x10080;
  836. break;
  837. case CGB_PLL2:
  838. reg = cg->regs + 0x100a0;
  839. break;
  840. default:
  841. WARN_ONCE(1, "index %d\n", idx);
  842. return;
  843. }
  844. } else {
  845. if (idx == PLATFORM_PLL)
  846. reg = cg->regs + 0xc00;
  847. else
  848. reg = cg->regs + 0x800 + 0x20 * (idx - 1);
  849. }
  850. /* Get the multiple of PLL */
  851. mult = cg_in(cg, reg);
  852. /* Check if this PLL is disabled */
  853. if (mult & PLL_KILL) {
  854. pr_debug("%s(): pll %p disabled\n", __func__, reg);
  855. return;
  856. }
  857. if ((cg->info.flags & CG_VER3) ||
  858. ((cg->info.flags & CG_PLL_8BIT) && idx != PLATFORM_PLL))
  859. mult = (mult & GENMASK(8, 1)) >> 1;
  860. else
  861. mult = (mult & GENMASK(6, 1)) >> 1;
  862. for (i = 0; i < ARRAY_SIZE(pll->div); i++) {
  863. struct clk *clk;
  864. snprintf(pll->div[i].name, sizeof(pll->div[i].name),
  865. "cg-pll%d-div%d", idx, i + 1);
  866. clk = clk_register_fixed_factor(NULL,
  867. pll->div[i].name, "cg-sysclk", 0, mult, i + 1);
  868. if (IS_ERR(clk)) {
  869. pr_err("%s: %s: register failed %ld\n",
  870. __func__, pll->div[i].name, PTR_ERR(clk));
  871. continue;
  872. }
  873. pll->div[i].clk = clk;
  874. }
  875. }
  876. static void __init create_plls(struct clockgen *cg)
  877. {
  878. int i;
  879. for (i = 0; i < ARRAY_SIZE(cg->pll); i++)
  880. create_one_pll(cg, i);
  881. }
  882. static void __init legacy_pll_init(struct device_node *np, int idx)
  883. {
  884. struct clockgen_pll *pll;
  885. struct clk_onecell_data *onecell_data;
  886. struct clk **subclks;
  887. int count, rc;
  888. legacy_init_clockgen(np);
  889. pll = &clockgen.pll[idx];
  890. count = of_property_count_strings(np, "clock-output-names");
  891. BUILD_BUG_ON(ARRAY_SIZE(pll->div) < 4);
  892. subclks = kcalloc(4, sizeof(struct clk *), GFP_KERNEL);
  893. if (!subclks)
  894. return;
  895. onecell_data = kmalloc(sizeof(*onecell_data), GFP_KERNEL);
  896. if (!onecell_data)
  897. goto err_clks;
  898. if (count <= 3) {
  899. subclks[0] = pll->div[0].clk;
  900. subclks[1] = pll->div[1].clk;
  901. subclks[2] = pll->div[3].clk;
  902. } else {
  903. subclks[0] = pll->div[0].clk;
  904. subclks[1] = pll->div[1].clk;
  905. subclks[2] = pll->div[2].clk;
  906. subclks[3] = pll->div[3].clk;
  907. }
  908. onecell_data->clks = subclks;
  909. onecell_data->clk_num = count;
  910. rc = of_clk_add_provider(np, of_clk_src_onecell_get, onecell_data);
  911. if (rc) {
  912. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  913. __func__, np->name, rc);
  914. goto err_cell;
  915. }
  916. return;
  917. err_cell:
  918. kfree(onecell_data);
  919. err_clks:
  920. kfree(subclks);
  921. }
  922. /* Legacy node */
  923. static void __init pltfrm_pll_init(struct device_node *np)
  924. {
  925. legacy_pll_init(np, PLATFORM_PLL);
  926. }
  927. /* Legacy node */
  928. static void __init core_pll_init(struct device_node *np)
  929. {
  930. struct resource res;
  931. int idx;
  932. if (of_address_to_resource(np, 0, &res))
  933. return;
  934. if ((res.start & 0xfff) == 0xc00) {
  935. /*
  936. * ls1021a devtree labels the platform PLL
  937. * with the core PLL compatible
  938. */
  939. pltfrm_pll_init(np);
  940. } else {
  941. idx = (res.start & 0xf0) >> 5;
  942. legacy_pll_init(np, CGA_PLL1 + idx);
  943. }
  944. }
  945. static struct clk *clockgen_clk_get(struct of_phandle_args *clkspec, void *data)
  946. {
  947. struct clockgen *cg = data;
  948. struct clk *clk;
  949. struct clockgen_pll *pll;
  950. u32 type, idx;
  951. if (clkspec->args_count < 2) {
  952. pr_err("%s: insufficient phandle args\n", __func__);
  953. return ERR_PTR(-EINVAL);
  954. }
  955. type = clkspec->args[0];
  956. idx = clkspec->args[1];
  957. switch (type) {
  958. case 0:
  959. if (idx != 0)
  960. goto bad_args;
  961. clk = cg->sysclk;
  962. break;
  963. case 1:
  964. if (idx >= ARRAY_SIZE(cg->cmux))
  965. goto bad_args;
  966. clk = cg->cmux[idx];
  967. break;
  968. case 2:
  969. if (idx >= ARRAY_SIZE(cg->hwaccel))
  970. goto bad_args;
  971. clk = cg->hwaccel[idx];
  972. break;
  973. case 3:
  974. if (idx >= ARRAY_SIZE(cg->fman))
  975. goto bad_args;
  976. clk = cg->fman[idx];
  977. break;
  978. case 4:
  979. pll = &cg->pll[PLATFORM_PLL];
  980. if (idx >= ARRAY_SIZE(pll->div))
  981. goto bad_args;
  982. clk = pll->div[idx].clk;
  983. break;
  984. default:
  985. goto bad_args;
  986. }
  987. if (!clk)
  988. return ERR_PTR(-ENOENT);
  989. return clk;
  990. bad_args:
  991. pr_err("%s: Bad phandle args %u %u\n", __func__, type, idx);
  992. return ERR_PTR(-EINVAL);
  993. }
  994. #ifdef CONFIG_PPC
  995. #include <asm/mpc85xx.h>
  996. static const u32 a4510_svrs[] __initconst = {
  997. (SVR_P2040 << 8) | 0x10, /* P2040 1.0 */
  998. (SVR_P2040 << 8) | 0x11, /* P2040 1.1 */
  999. (SVR_P2041 << 8) | 0x10, /* P2041 1.0 */
  1000. (SVR_P2041 << 8) | 0x11, /* P2041 1.1 */
  1001. (SVR_P3041 << 8) | 0x10, /* P3041 1.0 */
  1002. (SVR_P3041 << 8) | 0x11, /* P3041 1.1 */
  1003. (SVR_P4040 << 8) | 0x20, /* P4040 2.0 */
  1004. (SVR_P4080 << 8) | 0x20, /* P4080 2.0 */
  1005. (SVR_P5010 << 8) | 0x10, /* P5010 1.0 */
  1006. (SVR_P5010 << 8) | 0x20, /* P5010 2.0 */
  1007. (SVR_P5020 << 8) | 0x10, /* P5020 1.0 */
  1008. (SVR_P5021 << 8) | 0x10, /* P5021 1.0 */
  1009. (SVR_P5040 << 8) | 0x10, /* P5040 1.0 */
  1010. };
  1011. #define SVR_SECURITY 0x80000 /* The Security (E) bit */
  1012. static bool __init has_erratum_a4510(void)
  1013. {
  1014. u32 svr = mfspr(SPRN_SVR);
  1015. int i;
  1016. svr &= ~SVR_SECURITY;
  1017. for (i = 0; i < ARRAY_SIZE(a4510_svrs); i++) {
  1018. if (svr == a4510_svrs[i])
  1019. return true;
  1020. }
  1021. return false;
  1022. }
  1023. #else
  1024. static bool __init has_erratum_a4510(void)
  1025. {
  1026. return false;
  1027. }
  1028. #endif
  1029. static void __init clockgen_init(struct device_node *np)
  1030. {
  1031. int i, ret;
  1032. bool is_old_ls1021a = false;
  1033. /* May have already been called by a legacy probe */
  1034. if (clockgen.node)
  1035. return;
  1036. clockgen.node = np;
  1037. clockgen.regs = of_iomap(np, 0);
  1038. if (!clockgen.regs &&
  1039. of_device_is_compatible(of_root, "fsl,ls1021a")) {
  1040. /* Compatibility hack for old, broken device trees */
  1041. clockgen.regs = ioremap(0x1ee1000, 0x1000);
  1042. is_old_ls1021a = true;
  1043. }
  1044. if (!clockgen.regs) {
  1045. pr_err("%s(): %s: of_iomap() failed\n", __func__, np->name);
  1046. return;
  1047. }
  1048. for (i = 0; i < ARRAY_SIZE(chipinfo); i++) {
  1049. if (of_device_is_compatible(np, chipinfo[i].compat))
  1050. break;
  1051. if (is_old_ls1021a &&
  1052. !strcmp(chipinfo[i].compat, "fsl,ls1021a-clockgen"))
  1053. break;
  1054. }
  1055. if (i == ARRAY_SIZE(chipinfo)) {
  1056. pr_err("%s: unknown clockgen node %s\n", __func__,
  1057. np->full_name);
  1058. goto err;
  1059. }
  1060. clockgen.info = chipinfo[i];
  1061. if (clockgen.info.guts_compat) {
  1062. struct device_node *guts;
  1063. guts = of_find_compatible_node(NULL, NULL,
  1064. clockgen.info.guts_compat);
  1065. if (guts) {
  1066. clockgen.guts = of_iomap(guts, 0);
  1067. if (!clockgen.guts) {
  1068. pr_err("%s: Couldn't map %s regs\n", __func__,
  1069. guts->full_name);
  1070. }
  1071. }
  1072. }
  1073. if (has_erratum_a4510())
  1074. clockgen.info.flags |= CG_CMUX_GE_PLAT;
  1075. clockgen.sysclk = create_sysclk("cg-sysclk");
  1076. create_plls(&clockgen);
  1077. create_muxes(&clockgen);
  1078. if (clockgen.info.init_periph)
  1079. clockgen.info.init_periph(&clockgen);
  1080. ret = of_clk_add_provider(np, clockgen_clk_get, &clockgen);
  1081. if (ret) {
  1082. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  1083. __func__, np->name, ret);
  1084. }
  1085. return;
  1086. err:
  1087. iounmap(clockgen.regs);
  1088. clockgen.regs = NULL;
  1089. }
  1090. CLK_OF_DECLARE(qoriq_clockgen_1, "fsl,qoriq-clockgen-1.0", clockgen_init);
  1091. CLK_OF_DECLARE(qoriq_clockgen_2, "fsl,qoriq-clockgen-2.0", clockgen_init);
  1092. CLK_OF_DECLARE(qoriq_clockgen_ls1021a, "fsl,ls1021a-clockgen", clockgen_init);
  1093. CLK_OF_DECLARE(qoriq_clockgen_ls1043a, "fsl,ls1043a-clockgen", clockgen_init);
  1094. CLK_OF_DECLARE(qoriq_clockgen_ls2080a, "fsl,ls2080a-clockgen", clockgen_init);
  1095. /* Legacy nodes */
  1096. CLK_OF_DECLARE(qoriq_sysclk_1, "fsl,qoriq-sysclk-1.0", sysclk_init);
  1097. CLK_OF_DECLARE(qoriq_sysclk_2, "fsl,qoriq-sysclk-2.0", sysclk_init);
  1098. CLK_OF_DECLARE(qoriq_core_pll_1, "fsl,qoriq-core-pll-1.0", core_pll_init);
  1099. CLK_OF_DECLARE(qoriq_core_pll_2, "fsl,qoriq-core-pll-2.0", core_pll_init);
  1100. CLK_OF_DECLARE(qoriq_core_mux_1, "fsl,qoriq-core-mux-1.0", core_mux_init);
  1101. CLK_OF_DECLARE(qoriq_core_mux_2, "fsl,qoriq-core-mux-2.0", core_mux_init);
  1102. CLK_OF_DECLARE(qoriq_pltfrm_pll_1, "fsl,qoriq-platform-pll-1.0", pltfrm_pll_init);
  1103. CLK_OF_DECLARE(qoriq_pltfrm_pll_2, "fsl,qoriq-platform-pll-2.0", pltfrm_pll_init);