clk-qoriq.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  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 ls1046a_hwa1 = {
  232. {
  233. {},
  234. {},
  235. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  236. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  237. { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 },
  238. { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 },
  239. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  240. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  241. },
  242. };
  243. static const struct clockgen_muxinfo ls1046a_hwa2 = {
  244. {
  245. {},
  246. { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  247. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  248. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  249. {},
  250. {},
  251. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  252. },
  253. };
  254. static const struct clockgen_muxinfo ls1012a_cmux = {
  255. {
  256. [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  257. {},
  258. [2] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  259. }
  260. };
  261. static const struct clockgen_muxinfo t1023_hwa1 = {
  262. {
  263. {},
  264. { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  265. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  266. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  267. },
  268. };
  269. static const struct clockgen_muxinfo t1023_hwa2 = {
  270. {
  271. [6] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  272. },
  273. };
  274. static const struct clockgen_muxinfo t2080_hwa1 = {
  275. {
  276. {},
  277. { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  278. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  279. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  280. { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 },
  281. { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 },
  282. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  283. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  284. },
  285. };
  286. static const struct clockgen_muxinfo t2080_hwa2 = {
  287. {
  288. {},
  289. { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 },
  290. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  291. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  292. { CLKSEL_VALID, CGA_PLL2, PLL_DIV4 },
  293. { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 },
  294. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  295. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  296. },
  297. };
  298. static const struct clockgen_muxinfo t4240_hwa1 = {
  299. {
  300. { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV2 },
  301. { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 },
  302. { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 },
  303. { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 },
  304. { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 },
  305. {},
  306. { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 },
  307. { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 },
  308. },
  309. };
  310. static const struct clockgen_muxinfo t4240_hwa4 = {
  311. {
  312. [2] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV2 },
  313. [3] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV3 },
  314. [4] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV4 },
  315. [5] = { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 },
  316. [6] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV2 },
  317. },
  318. };
  319. static const struct clockgen_muxinfo t4240_hwa5 = {
  320. {
  321. [2] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV2 },
  322. [3] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV3 },
  323. [4] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV4 },
  324. [5] = { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 },
  325. [6] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV2 },
  326. [7] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV3 },
  327. },
  328. };
  329. #define RCWSR7_FM1_CLK_SEL 0x40000000
  330. #define RCWSR7_FM2_CLK_SEL 0x20000000
  331. #define RCWSR7_HWA_ASYNC_DIV 0x04000000
  332. static void __init p2041_init_periph(struct clockgen *cg)
  333. {
  334. u32 reg;
  335. reg = ioread32be(&cg->guts->rcwsr[7]);
  336. if (reg & RCWSR7_FM1_CLK_SEL)
  337. cg->fman[0] = cg->pll[CGA_PLL2].div[PLL_DIV2].clk;
  338. else
  339. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  340. }
  341. static void __init p4080_init_periph(struct clockgen *cg)
  342. {
  343. u32 reg;
  344. reg = ioread32be(&cg->guts->rcwsr[7]);
  345. if (reg & RCWSR7_FM1_CLK_SEL)
  346. cg->fman[0] = cg->pll[CGA_PLL3].div[PLL_DIV2].clk;
  347. else
  348. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  349. if (reg & RCWSR7_FM2_CLK_SEL)
  350. cg->fman[1] = cg->pll[CGA_PLL3].div[PLL_DIV2].clk;
  351. else
  352. cg->fman[1] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  353. }
  354. static void __init p5020_init_periph(struct clockgen *cg)
  355. {
  356. u32 reg;
  357. int div = PLL_DIV2;
  358. reg = ioread32be(&cg->guts->rcwsr[7]);
  359. if (reg & RCWSR7_HWA_ASYNC_DIV)
  360. div = PLL_DIV4;
  361. if (reg & RCWSR7_FM1_CLK_SEL)
  362. cg->fman[0] = cg->pll[CGA_PLL2].div[div].clk;
  363. else
  364. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  365. }
  366. static void __init p5040_init_periph(struct clockgen *cg)
  367. {
  368. u32 reg;
  369. int div = PLL_DIV2;
  370. reg = ioread32be(&cg->guts->rcwsr[7]);
  371. if (reg & RCWSR7_HWA_ASYNC_DIV)
  372. div = PLL_DIV4;
  373. if (reg & RCWSR7_FM1_CLK_SEL)
  374. cg->fman[0] = cg->pll[CGA_PLL3].div[div].clk;
  375. else
  376. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  377. if (reg & RCWSR7_FM2_CLK_SEL)
  378. cg->fman[1] = cg->pll[CGA_PLL3].div[div].clk;
  379. else
  380. cg->fman[1] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk;
  381. }
  382. static void __init t1023_init_periph(struct clockgen *cg)
  383. {
  384. cg->fman[0] = cg->hwaccel[1];
  385. }
  386. static void __init t1040_init_periph(struct clockgen *cg)
  387. {
  388. cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV1].clk;
  389. }
  390. static void __init t2080_init_periph(struct clockgen *cg)
  391. {
  392. cg->fman[0] = cg->hwaccel[0];
  393. }
  394. static void __init t4240_init_periph(struct clockgen *cg)
  395. {
  396. cg->fman[0] = cg->hwaccel[3];
  397. cg->fman[1] = cg->hwaccel[4];
  398. }
  399. static const struct clockgen_chipinfo chipinfo[] = {
  400. {
  401. .compat = "fsl,b4420-clockgen",
  402. .guts_compat = "fsl,b4860-device-config",
  403. .init_periph = t2080_init_periph,
  404. .cmux_groups = {
  405. &clockgen2_cmux_cga12, &clockgen2_cmux_cgb
  406. },
  407. .hwaccel = {
  408. &t2080_hwa1
  409. },
  410. .cmux_to_group = {
  411. 0, 1, 1, 1, -1
  412. },
  413. .pll_mask = 0x3f,
  414. .flags = CG_PLL_8BIT,
  415. },
  416. {
  417. .compat = "fsl,b4860-clockgen",
  418. .guts_compat = "fsl,b4860-device-config",
  419. .init_periph = t2080_init_periph,
  420. .cmux_groups = {
  421. &clockgen2_cmux_cga12, &clockgen2_cmux_cgb
  422. },
  423. .hwaccel = {
  424. &t2080_hwa1
  425. },
  426. .cmux_to_group = {
  427. 0, 1, 1, 1, -1
  428. },
  429. .pll_mask = 0x3f,
  430. .flags = CG_PLL_8BIT,
  431. },
  432. {
  433. .compat = "fsl,ls1021a-clockgen",
  434. .cmux_groups = {
  435. &t1023_cmux
  436. },
  437. .cmux_to_group = {
  438. 0, -1
  439. },
  440. .pll_mask = 0x03,
  441. },
  442. {
  443. .compat = "fsl,ls1043a-clockgen",
  444. .init_periph = t2080_init_periph,
  445. .cmux_groups = {
  446. &t1040_cmux
  447. },
  448. .hwaccel = {
  449. &ls1043a_hwa1, &ls1043a_hwa2
  450. },
  451. .cmux_to_group = {
  452. 0, -1
  453. },
  454. .pll_mask = 0x07,
  455. .flags = CG_PLL_8BIT,
  456. },
  457. {
  458. .compat = "fsl,ls1046a-clockgen",
  459. .init_periph = t2080_init_periph,
  460. .cmux_groups = {
  461. &t1040_cmux
  462. },
  463. .hwaccel = {
  464. &ls1046a_hwa1, &ls1046a_hwa2
  465. },
  466. .cmux_to_group = {
  467. 0, -1
  468. },
  469. .pll_mask = 0x07,
  470. .flags = CG_PLL_8BIT,
  471. },
  472. {
  473. .compat = "fsl,ls1012a-clockgen",
  474. .cmux_groups = {
  475. &ls1012a_cmux
  476. },
  477. .cmux_to_group = {
  478. 0, -1
  479. },
  480. .pll_mask = 0x03,
  481. },
  482. {
  483. .compat = "fsl,ls2080a-clockgen",
  484. .cmux_groups = {
  485. &clockgen2_cmux_cga12, &clockgen2_cmux_cgb
  486. },
  487. .cmux_to_group = {
  488. 0, 0, 1, 1, -1
  489. },
  490. .pll_mask = 0x37,
  491. .flags = CG_VER3 | CG_LITTLE_ENDIAN,
  492. },
  493. {
  494. .compat = "fsl,p2041-clockgen",
  495. .guts_compat = "fsl,qoriq-device-config-1.0",
  496. .init_periph = p2041_init_periph,
  497. .cmux_groups = {
  498. &p2041_cmux_grp1, &p2041_cmux_grp2
  499. },
  500. .cmux_to_group = {
  501. 0, 0, 1, 1, -1
  502. },
  503. .pll_mask = 0x07,
  504. },
  505. {
  506. .compat = "fsl,p3041-clockgen",
  507. .guts_compat = "fsl,qoriq-device-config-1.0",
  508. .init_periph = p2041_init_periph,
  509. .cmux_groups = {
  510. &p2041_cmux_grp1, &p2041_cmux_grp2
  511. },
  512. .cmux_to_group = {
  513. 0, 0, 1, 1, -1
  514. },
  515. .pll_mask = 0x07,
  516. },
  517. {
  518. .compat = "fsl,p4080-clockgen",
  519. .guts_compat = "fsl,qoriq-device-config-1.0",
  520. .init_periph = p4080_init_periph,
  521. .cmux_groups = {
  522. &p4080_cmux_grp1, &p4080_cmux_grp2
  523. },
  524. .cmux_to_group = {
  525. 0, 0, 0, 0, 1, 1, 1, 1
  526. },
  527. .pll_mask = 0x1f,
  528. },
  529. {
  530. .compat = "fsl,p5020-clockgen",
  531. .guts_compat = "fsl,qoriq-device-config-1.0",
  532. .init_periph = p5020_init_periph,
  533. .cmux_groups = {
  534. &p2041_cmux_grp1, &p2041_cmux_grp2
  535. },
  536. .cmux_to_group = {
  537. 0, 1, -1
  538. },
  539. .pll_mask = 0x07,
  540. },
  541. {
  542. .compat = "fsl,p5040-clockgen",
  543. .guts_compat = "fsl,p5040-device-config",
  544. .init_periph = p5040_init_periph,
  545. .cmux_groups = {
  546. &p5040_cmux_grp1, &p5040_cmux_grp2
  547. },
  548. .cmux_to_group = {
  549. 0, 0, 1, 1, -1
  550. },
  551. .pll_mask = 0x0f,
  552. },
  553. {
  554. .compat = "fsl,t1023-clockgen",
  555. .guts_compat = "fsl,t1023-device-config",
  556. .init_periph = t1023_init_periph,
  557. .cmux_groups = {
  558. &t1023_cmux
  559. },
  560. .hwaccel = {
  561. &t1023_hwa1, &t1023_hwa2
  562. },
  563. .cmux_to_group = {
  564. 0, 0, -1
  565. },
  566. .pll_mask = 0x03,
  567. .flags = CG_PLL_8BIT,
  568. },
  569. {
  570. .compat = "fsl,t1040-clockgen",
  571. .guts_compat = "fsl,t1040-device-config",
  572. .init_periph = t1040_init_periph,
  573. .cmux_groups = {
  574. &t1040_cmux
  575. },
  576. .cmux_to_group = {
  577. 0, 0, 0, 0, -1
  578. },
  579. .pll_mask = 0x07,
  580. .flags = CG_PLL_8BIT,
  581. },
  582. {
  583. .compat = "fsl,t2080-clockgen",
  584. .guts_compat = "fsl,t2080-device-config",
  585. .init_periph = t2080_init_periph,
  586. .cmux_groups = {
  587. &clockgen2_cmux_cga12
  588. },
  589. .hwaccel = {
  590. &t2080_hwa1, &t2080_hwa2
  591. },
  592. .cmux_to_group = {
  593. 0, -1
  594. },
  595. .pll_mask = 0x07,
  596. .flags = CG_PLL_8BIT,
  597. },
  598. {
  599. .compat = "fsl,t4240-clockgen",
  600. .guts_compat = "fsl,t4240-device-config",
  601. .init_periph = t4240_init_periph,
  602. .cmux_groups = {
  603. &clockgen2_cmux_cga, &clockgen2_cmux_cgb
  604. },
  605. .hwaccel = {
  606. &t4240_hwa1, NULL, NULL, &t4240_hwa4, &t4240_hwa5
  607. },
  608. .cmux_to_group = {
  609. 0, 0, 1, -1
  610. },
  611. .pll_mask = 0x3f,
  612. .flags = CG_PLL_8BIT,
  613. },
  614. {},
  615. };
  616. struct mux_hwclock {
  617. struct clk_hw hw;
  618. struct clockgen *cg;
  619. const struct clockgen_muxinfo *info;
  620. u32 __iomem *reg;
  621. u8 parent_to_clksel[NUM_MUX_PARENTS];
  622. s8 clksel_to_parent[NUM_MUX_PARENTS];
  623. int num_parents;
  624. };
  625. #define to_mux_hwclock(p) container_of(p, struct mux_hwclock, hw)
  626. #define CLKSEL_MASK 0x78000000
  627. #define CLKSEL_SHIFT 27
  628. static int mux_set_parent(struct clk_hw *hw, u8 idx)
  629. {
  630. struct mux_hwclock *hwc = to_mux_hwclock(hw);
  631. u32 clksel;
  632. if (idx >= hwc->num_parents)
  633. return -EINVAL;
  634. clksel = hwc->parent_to_clksel[idx];
  635. cg_out(hwc->cg, (clksel << CLKSEL_SHIFT) & CLKSEL_MASK, hwc->reg);
  636. return 0;
  637. }
  638. static u8 mux_get_parent(struct clk_hw *hw)
  639. {
  640. struct mux_hwclock *hwc = to_mux_hwclock(hw);
  641. u32 clksel;
  642. s8 ret;
  643. clksel = (cg_in(hwc->cg, hwc->reg) & CLKSEL_MASK) >> CLKSEL_SHIFT;
  644. ret = hwc->clksel_to_parent[clksel];
  645. if (ret < 0) {
  646. pr_err("%s: mux at %p has bad clksel\n", __func__, hwc->reg);
  647. return 0;
  648. }
  649. return ret;
  650. }
  651. static const struct clk_ops cmux_ops = {
  652. .get_parent = mux_get_parent,
  653. .set_parent = mux_set_parent,
  654. };
  655. /*
  656. * Don't allow setting for now, as the clock options haven't been
  657. * sanitized for additional restrictions.
  658. */
  659. static const struct clk_ops hwaccel_ops = {
  660. .get_parent = mux_get_parent,
  661. };
  662. static const struct clockgen_pll_div *get_pll_div(struct clockgen *cg,
  663. struct mux_hwclock *hwc,
  664. int idx)
  665. {
  666. int pll, div;
  667. if (!(hwc->info->clksel[idx].flags & CLKSEL_VALID))
  668. return NULL;
  669. pll = hwc->info->clksel[idx].pll;
  670. div = hwc->info->clksel[idx].div;
  671. return &cg->pll[pll].div[div];
  672. }
  673. static struct clk * __init create_mux_common(struct clockgen *cg,
  674. struct mux_hwclock *hwc,
  675. const struct clk_ops *ops,
  676. unsigned long min_rate,
  677. unsigned long max_rate,
  678. unsigned long pct80_rate,
  679. const char *fmt, int idx)
  680. {
  681. struct clk_init_data init = {};
  682. struct clk *clk;
  683. const struct clockgen_pll_div *div;
  684. const char *parent_names[NUM_MUX_PARENTS];
  685. char name[32];
  686. int i, j;
  687. snprintf(name, sizeof(name), fmt, idx);
  688. for (i = 0, j = 0; i < NUM_MUX_PARENTS; i++) {
  689. unsigned long rate;
  690. hwc->clksel_to_parent[i] = -1;
  691. div = get_pll_div(cg, hwc, i);
  692. if (!div)
  693. continue;
  694. rate = clk_get_rate(div->clk);
  695. if (hwc->info->clksel[i].flags & CLKSEL_80PCT &&
  696. rate > pct80_rate)
  697. continue;
  698. if (rate < min_rate)
  699. continue;
  700. if (rate > max_rate)
  701. continue;
  702. parent_names[j] = div->name;
  703. hwc->parent_to_clksel[j] = i;
  704. hwc->clksel_to_parent[i] = j;
  705. j++;
  706. }
  707. init.name = name;
  708. init.ops = ops;
  709. init.parent_names = parent_names;
  710. init.num_parents = hwc->num_parents = j;
  711. init.flags = 0;
  712. hwc->hw.init = &init;
  713. hwc->cg = cg;
  714. clk = clk_register(NULL, &hwc->hw);
  715. if (IS_ERR(clk)) {
  716. pr_err("%s: Couldn't register %s: %ld\n", __func__, name,
  717. PTR_ERR(clk));
  718. kfree(hwc);
  719. return NULL;
  720. }
  721. return clk;
  722. }
  723. static struct clk * __init create_one_cmux(struct clockgen *cg, int idx)
  724. {
  725. struct mux_hwclock *hwc;
  726. const struct clockgen_pll_div *div;
  727. unsigned long plat_rate, min_rate;
  728. u64 max_rate, pct80_rate;
  729. u32 clksel;
  730. hwc = kzalloc(sizeof(*hwc), GFP_KERNEL);
  731. if (!hwc)
  732. return NULL;
  733. if (cg->info.flags & CG_VER3)
  734. hwc->reg = cg->regs + 0x70000 + 0x20 * idx;
  735. else
  736. hwc->reg = cg->regs + 0x20 * idx;
  737. hwc->info = cg->info.cmux_groups[cg->info.cmux_to_group[idx]];
  738. /*
  739. * Find the rate for the default clksel, and treat it as the
  740. * maximum rated core frequency. If this is an incorrect
  741. * assumption, certain clock options (possibly including the
  742. * default clksel) may be inappropriately excluded on certain
  743. * chips.
  744. */
  745. clksel = (cg_in(cg, hwc->reg) & CLKSEL_MASK) >> CLKSEL_SHIFT;
  746. div = get_pll_div(cg, hwc, clksel);
  747. if (!div) {
  748. kfree(hwc);
  749. return NULL;
  750. }
  751. max_rate = clk_get_rate(div->clk);
  752. pct80_rate = max_rate * 8;
  753. do_div(pct80_rate, 10);
  754. plat_rate = clk_get_rate(cg->pll[PLATFORM_PLL].div[PLL_DIV1].clk);
  755. if (cg->info.flags & CG_CMUX_GE_PLAT)
  756. min_rate = plat_rate;
  757. else
  758. min_rate = plat_rate / 2;
  759. return create_mux_common(cg, hwc, &cmux_ops, min_rate, max_rate,
  760. pct80_rate, "cg-cmux%d", idx);
  761. }
  762. static struct clk * __init create_one_hwaccel(struct clockgen *cg, int idx)
  763. {
  764. struct mux_hwclock *hwc;
  765. hwc = kzalloc(sizeof(*hwc), GFP_KERNEL);
  766. if (!hwc)
  767. return NULL;
  768. hwc->reg = cg->regs + 0x20 * idx + 0x10;
  769. hwc->info = cg->info.hwaccel[idx];
  770. return create_mux_common(cg, hwc, &hwaccel_ops, 0, ULONG_MAX, 0,
  771. "cg-hwaccel%d", idx);
  772. }
  773. static void __init create_muxes(struct clockgen *cg)
  774. {
  775. int i;
  776. for (i = 0; i < ARRAY_SIZE(cg->cmux); i++) {
  777. if (cg->info.cmux_to_group[i] < 0)
  778. break;
  779. if (cg->info.cmux_to_group[i] >=
  780. ARRAY_SIZE(cg->info.cmux_groups)) {
  781. WARN_ON_ONCE(1);
  782. continue;
  783. }
  784. cg->cmux[i] = create_one_cmux(cg, i);
  785. }
  786. for (i = 0; i < ARRAY_SIZE(cg->hwaccel); i++) {
  787. if (!cg->info.hwaccel[i])
  788. continue;
  789. cg->hwaccel[i] = create_one_hwaccel(cg, i);
  790. }
  791. }
  792. static void __init clockgen_init(struct device_node *np);
  793. /* Legacy nodes may get probed before the parent clockgen node */
  794. static void __init legacy_init_clockgen(struct device_node *np)
  795. {
  796. if (!clockgen.node)
  797. clockgen_init(of_get_parent(np));
  798. }
  799. /* Legacy node */
  800. static void __init core_mux_init(struct device_node *np)
  801. {
  802. struct clk *clk;
  803. struct resource res;
  804. int idx, rc;
  805. legacy_init_clockgen(np);
  806. if (of_address_to_resource(np, 0, &res))
  807. return;
  808. idx = (res.start & 0xf0) >> 5;
  809. clk = clockgen.cmux[idx];
  810. rc = of_clk_add_provider(np, of_clk_src_simple_get, clk);
  811. if (rc) {
  812. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  813. __func__, np->name, rc);
  814. return;
  815. }
  816. }
  817. static struct clk __init
  818. *sysclk_from_fixed(struct device_node *node, const char *name)
  819. {
  820. u32 rate;
  821. if (of_property_read_u32(node, "clock-frequency", &rate))
  822. return ERR_PTR(-ENODEV);
  823. return clk_register_fixed_rate(NULL, name, NULL, 0, rate);
  824. }
  825. static struct clk *sysclk_from_parent(const char *name)
  826. {
  827. struct clk *clk;
  828. const char *parent_name;
  829. clk = of_clk_get(clockgen.node, 0);
  830. if (IS_ERR(clk))
  831. return clk;
  832. /* Register the input clock under the desired name. */
  833. parent_name = __clk_get_name(clk);
  834. clk = clk_register_fixed_factor(NULL, name, parent_name,
  835. 0, 1, 1);
  836. if (IS_ERR(clk))
  837. pr_err("%s: Couldn't register %s: %ld\n", __func__, name,
  838. PTR_ERR(clk));
  839. return clk;
  840. }
  841. static struct clk * __init create_sysclk(const char *name)
  842. {
  843. struct device_node *sysclk;
  844. struct clk *clk;
  845. clk = sysclk_from_fixed(clockgen.node, name);
  846. if (!IS_ERR(clk))
  847. return clk;
  848. clk = sysclk_from_parent(name);
  849. if (!IS_ERR(clk))
  850. return clk;
  851. sysclk = of_get_child_by_name(clockgen.node, "sysclk");
  852. if (sysclk) {
  853. clk = sysclk_from_fixed(sysclk, name);
  854. if (!IS_ERR(clk))
  855. return clk;
  856. }
  857. pr_err("%s: No input clock\n", __func__);
  858. return NULL;
  859. }
  860. /* Legacy node */
  861. static void __init sysclk_init(struct device_node *node)
  862. {
  863. struct clk *clk;
  864. legacy_init_clockgen(node);
  865. clk = clockgen.sysclk;
  866. if (clk)
  867. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  868. }
  869. #define PLL_KILL BIT(31)
  870. static void __init create_one_pll(struct clockgen *cg, int idx)
  871. {
  872. u32 __iomem *reg;
  873. u32 mult;
  874. struct clockgen_pll *pll = &cg->pll[idx];
  875. int i;
  876. if (!(cg->info.pll_mask & (1 << idx)))
  877. return;
  878. if (cg->info.flags & CG_VER3) {
  879. switch (idx) {
  880. case PLATFORM_PLL:
  881. reg = cg->regs + 0x60080;
  882. break;
  883. case CGA_PLL1:
  884. reg = cg->regs + 0x80;
  885. break;
  886. case CGA_PLL2:
  887. reg = cg->regs + 0xa0;
  888. break;
  889. case CGB_PLL1:
  890. reg = cg->regs + 0x10080;
  891. break;
  892. case CGB_PLL2:
  893. reg = cg->regs + 0x100a0;
  894. break;
  895. default:
  896. WARN_ONCE(1, "index %d\n", idx);
  897. return;
  898. }
  899. } else {
  900. if (idx == PLATFORM_PLL)
  901. reg = cg->regs + 0xc00;
  902. else
  903. reg = cg->regs + 0x800 + 0x20 * (idx - 1);
  904. }
  905. /* Get the multiple of PLL */
  906. mult = cg_in(cg, reg);
  907. /* Check if this PLL is disabled */
  908. if (mult & PLL_KILL) {
  909. pr_debug("%s(): pll %p disabled\n", __func__, reg);
  910. return;
  911. }
  912. if ((cg->info.flags & CG_VER3) ||
  913. ((cg->info.flags & CG_PLL_8BIT) && idx != PLATFORM_PLL))
  914. mult = (mult & GENMASK(8, 1)) >> 1;
  915. else
  916. mult = (mult & GENMASK(6, 1)) >> 1;
  917. for (i = 0; i < ARRAY_SIZE(pll->div); i++) {
  918. struct clk *clk;
  919. snprintf(pll->div[i].name, sizeof(pll->div[i].name),
  920. "cg-pll%d-div%d", idx, i + 1);
  921. clk = clk_register_fixed_factor(NULL,
  922. pll->div[i].name, "cg-sysclk", 0, mult, i + 1);
  923. if (IS_ERR(clk)) {
  924. pr_err("%s: %s: register failed %ld\n",
  925. __func__, pll->div[i].name, PTR_ERR(clk));
  926. continue;
  927. }
  928. pll->div[i].clk = clk;
  929. }
  930. }
  931. static void __init create_plls(struct clockgen *cg)
  932. {
  933. int i;
  934. for (i = 0; i < ARRAY_SIZE(cg->pll); i++)
  935. create_one_pll(cg, i);
  936. }
  937. static void __init legacy_pll_init(struct device_node *np, int idx)
  938. {
  939. struct clockgen_pll *pll;
  940. struct clk_onecell_data *onecell_data;
  941. struct clk **subclks;
  942. int count, rc;
  943. legacy_init_clockgen(np);
  944. pll = &clockgen.pll[idx];
  945. count = of_property_count_strings(np, "clock-output-names");
  946. BUILD_BUG_ON(ARRAY_SIZE(pll->div) < 4);
  947. subclks = kcalloc(4, sizeof(struct clk *), GFP_KERNEL);
  948. if (!subclks)
  949. return;
  950. onecell_data = kmalloc(sizeof(*onecell_data), GFP_KERNEL);
  951. if (!onecell_data)
  952. goto err_clks;
  953. if (count <= 3) {
  954. subclks[0] = pll->div[0].clk;
  955. subclks[1] = pll->div[1].clk;
  956. subclks[2] = pll->div[3].clk;
  957. } else {
  958. subclks[0] = pll->div[0].clk;
  959. subclks[1] = pll->div[1].clk;
  960. subclks[2] = pll->div[2].clk;
  961. subclks[3] = pll->div[3].clk;
  962. }
  963. onecell_data->clks = subclks;
  964. onecell_data->clk_num = count;
  965. rc = of_clk_add_provider(np, of_clk_src_onecell_get, onecell_data);
  966. if (rc) {
  967. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  968. __func__, np->name, rc);
  969. goto err_cell;
  970. }
  971. return;
  972. err_cell:
  973. kfree(onecell_data);
  974. err_clks:
  975. kfree(subclks);
  976. }
  977. /* Legacy node */
  978. static void __init pltfrm_pll_init(struct device_node *np)
  979. {
  980. legacy_pll_init(np, PLATFORM_PLL);
  981. }
  982. /* Legacy node */
  983. static void __init core_pll_init(struct device_node *np)
  984. {
  985. struct resource res;
  986. int idx;
  987. if (of_address_to_resource(np, 0, &res))
  988. return;
  989. if ((res.start & 0xfff) == 0xc00) {
  990. /*
  991. * ls1021a devtree labels the platform PLL
  992. * with the core PLL compatible
  993. */
  994. pltfrm_pll_init(np);
  995. } else {
  996. idx = (res.start & 0xf0) >> 5;
  997. legacy_pll_init(np, CGA_PLL1 + idx);
  998. }
  999. }
  1000. static struct clk *clockgen_clk_get(struct of_phandle_args *clkspec, void *data)
  1001. {
  1002. struct clockgen *cg = data;
  1003. struct clk *clk;
  1004. struct clockgen_pll *pll;
  1005. u32 type, idx;
  1006. if (clkspec->args_count < 2) {
  1007. pr_err("%s: insufficient phandle args\n", __func__);
  1008. return ERR_PTR(-EINVAL);
  1009. }
  1010. type = clkspec->args[0];
  1011. idx = clkspec->args[1];
  1012. switch (type) {
  1013. case 0:
  1014. if (idx != 0)
  1015. goto bad_args;
  1016. clk = cg->sysclk;
  1017. break;
  1018. case 1:
  1019. if (idx >= ARRAY_SIZE(cg->cmux))
  1020. goto bad_args;
  1021. clk = cg->cmux[idx];
  1022. break;
  1023. case 2:
  1024. if (idx >= ARRAY_SIZE(cg->hwaccel))
  1025. goto bad_args;
  1026. clk = cg->hwaccel[idx];
  1027. break;
  1028. case 3:
  1029. if (idx >= ARRAY_SIZE(cg->fman))
  1030. goto bad_args;
  1031. clk = cg->fman[idx];
  1032. break;
  1033. case 4:
  1034. pll = &cg->pll[PLATFORM_PLL];
  1035. if (idx >= ARRAY_SIZE(pll->div))
  1036. goto bad_args;
  1037. clk = pll->div[idx].clk;
  1038. break;
  1039. default:
  1040. goto bad_args;
  1041. }
  1042. if (!clk)
  1043. return ERR_PTR(-ENOENT);
  1044. return clk;
  1045. bad_args:
  1046. pr_err("%s: Bad phandle args %u %u\n", __func__, type, idx);
  1047. return ERR_PTR(-EINVAL);
  1048. }
  1049. #ifdef CONFIG_PPC
  1050. #include <asm/mpc85xx.h>
  1051. static const u32 a4510_svrs[] __initconst = {
  1052. (SVR_P2040 << 8) | 0x10, /* P2040 1.0 */
  1053. (SVR_P2040 << 8) | 0x11, /* P2040 1.1 */
  1054. (SVR_P2041 << 8) | 0x10, /* P2041 1.0 */
  1055. (SVR_P2041 << 8) | 0x11, /* P2041 1.1 */
  1056. (SVR_P3041 << 8) | 0x10, /* P3041 1.0 */
  1057. (SVR_P3041 << 8) | 0x11, /* P3041 1.1 */
  1058. (SVR_P4040 << 8) | 0x20, /* P4040 2.0 */
  1059. (SVR_P4080 << 8) | 0x20, /* P4080 2.0 */
  1060. (SVR_P5010 << 8) | 0x10, /* P5010 1.0 */
  1061. (SVR_P5010 << 8) | 0x20, /* P5010 2.0 */
  1062. (SVR_P5020 << 8) | 0x10, /* P5020 1.0 */
  1063. (SVR_P5021 << 8) | 0x10, /* P5021 1.0 */
  1064. (SVR_P5040 << 8) | 0x10, /* P5040 1.0 */
  1065. };
  1066. #define SVR_SECURITY 0x80000 /* The Security (E) bit */
  1067. static bool __init has_erratum_a4510(void)
  1068. {
  1069. u32 svr = mfspr(SPRN_SVR);
  1070. int i;
  1071. svr &= ~SVR_SECURITY;
  1072. for (i = 0; i < ARRAY_SIZE(a4510_svrs); i++) {
  1073. if (svr == a4510_svrs[i])
  1074. return true;
  1075. }
  1076. return false;
  1077. }
  1078. #else
  1079. static bool __init has_erratum_a4510(void)
  1080. {
  1081. return false;
  1082. }
  1083. #endif
  1084. static void __init clockgen_init(struct device_node *np)
  1085. {
  1086. int i, ret;
  1087. bool is_old_ls1021a = false;
  1088. /* May have already been called by a legacy probe */
  1089. if (clockgen.node)
  1090. return;
  1091. clockgen.node = np;
  1092. clockgen.regs = of_iomap(np, 0);
  1093. if (!clockgen.regs &&
  1094. of_device_is_compatible(of_root, "fsl,ls1021a")) {
  1095. /* Compatibility hack for old, broken device trees */
  1096. clockgen.regs = ioremap(0x1ee1000, 0x1000);
  1097. is_old_ls1021a = true;
  1098. }
  1099. if (!clockgen.regs) {
  1100. pr_err("%s(): %s: of_iomap() failed\n", __func__, np->name);
  1101. return;
  1102. }
  1103. for (i = 0; i < ARRAY_SIZE(chipinfo); i++) {
  1104. if (of_device_is_compatible(np, chipinfo[i].compat))
  1105. break;
  1106. if (is_old_ls1021a &&
  1107. !strcmp(chipinfo[i].compat, "fsl,ls1021a-clockgen"))
  1108. break;
  1109. }
  1110. if (i == ARRAY_SIZE(chipinfo)) {
  1111. pr_err("%s: unknown clockgen node %s\n", __func__,
  1112. np->full_name);
  1113. goto err;
  1114. }
  1115. clockgen.info = chipinfo[i];
  1116. if (clockgen.info.guts_compat) {
  1117. struct device_node *guts;
  1118. guts = of_find_compatible_node(NULL, NULL,
  1119. clockgen.info.guts_compat);
  1120. if (guts) {
  1121. clockgen.guts = of_iomap(guts, 0);
  1122. if (!clockgen.guts) {
  1123. pr_err("%s: Couldn't map %s regs\n", __func__,
  1124. guts->full_name);
  1125. }
  1126. }
  1127. }
  1128. if (has_erratum_a4510())
  1129. clockgen.info.flags |= CG_CMUX_GE_PLAT;
  1130. clockgen.sysclk = create_sysclk("cg-sysclk");
  1131. create_plls(&clockgen);
  1132. create_muxes(&clockgen);
  1133. if (clockgen.info.init_periph)
  1134. clockgen.info.init_periph(&clockgen);
  1135. ret = of_clk_add_provider(np, clockgen_clk_get, &clockgen);
  1136. if (ret) {
  1137. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  1138. __func__, np->name, ret);
  1139. }
  1140. return;
  1141. err:
  1142. iounmap(clockgen.regs);
  1143. clockgen.regs = NULL;
  1144. }
  1145. CLK_OF_DECLARE(qoriq_clockgen_1, "fsl,qoriq-clockgen-1.0", clockgen_init);
  1146. CLK_OF_DECLARE(qoriq_clockgen_2, "fsl,qoriq-clockgen-2.0", clockgen_init);
  1147. CLK_OF_DECLARE(qoriq_clockgen_ls1012a, "fsl,ls1012a-clockgen", clockgen_init);
  1148. CLK_OF_DECLARE(qoriq_clockgen_ls1021a, "fsl,ls1021a-clockgen", clockgen_init);
  1149. CLK_OF_DECLARE(qoriq_clockgen_ls1043a, "fsl,ls1043a-clockgen", clockgen_init);
  1150. CLK_OF_DECLARE(qoriq_clockgen_ls1046a, "fsl,ls1046a-clockgen", clockgen_init);
  1151. CLK_OF_DECLARE(qoriq_clockgen_ls2080a, "fsl,ls2080a-clockgen", clockgen_init);
  1152. /* Legacy nodes */
  1153. CLK_OF_DECLARE(qoriq_sysclk_1, "fsl,qoriq-sysclk-1.0", sysclk_init);
  1154. CLK_OF_DECLARE(qoriq_sysclk_2, "fsl,qoriq-sysclk-2.0", sysclk_init);
  1155. CLK_OF_DECLARE(qoriq_core_pll_1, "fsl,qoriq-core-pll-1.0", core_pll_init);
  1156. CLK_OF_DECLARE(qoriq_core_pll_2, "fsl,qoriq-core-pll-2.0", core_pll_init);
  1157. CLK_OF_DECLARE(qoriq_core_mux_1, "fsl,qoriq-core-mux-1.0", core_mux_init);
  1158. CLK_OF_DECLARE(qoriq_core_mux_2, "fsl,qoriq-core-mux-2.0", core_mux_init);
  1159. CLK_OF_DECLARE(qoriq_pltfrm_pll_1, "fsl,qoriq-platform-pll-1.0", pltfrm_pll_init);
  1160. CLK_OF_DECLARE(qoriq_pltfrm_pll_2, "fsl,qoriq-platform-pll-2.0", pltfrm_pll_init);