clk-qoriq.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  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 pct80_rate,
  623. const char *fmt, int idx)
  624. {
  625. struct clk_init_data init = {};
  626. struct clk *clk;
  627. const struct clockgen_pll_div *div;
  628. const char *parent_names[NUM_MUX_PARENTS];
  629. char name[32];
  630. int i, j;
  631. snprintf(name, sizeof(name), fmt, idx);
  632. for (i = 0, j = 0; i < NUM_MUX_PARENTS; i++) {
  633. unsigned long rate;
  634. hwc->clksel_to_parent[i] = -1;
  635. div = get_pll_div(cg, hwc, i);
  636. if (!div)
  637. continue;
  638. rate = clk_get_rate(div->clk);
  639. if (hwc->info->clksel[i].flags & CLKSEL_80PCT &&
  640. rate > pct80_rate)
  641. continue;
  642. if (rate < min_rate)
  643. continue;
  644. parent_names[j] = div->name;
  645. hwc->parent_to_clksel[j] = i;
  646. hwc->clksel_to_parent[i] = j;
  647. j++;
  648. }
  649. init.name = name;
  650. init.ops = ops;
  651. init.parent_names = parent_names;
  652. init.num_parents = hwc->num_parents = j;
  653. init.flags = 0;
  654. hwc->hw.init = &init;
  655. hwc->cg = cg;
  656. clk = clk_register(NULL, &hwc->hw);
  657. if (IS_ERR(clk)) {
  658. pr_err("%s: Couldn't register %s: %ld\n", __func__, name,
  659. PTR_ERR(clk));
  660. kfree(hwc);
  661. return NULL;
  662. }
  663. return clk;
  664. }
  665. static struct clk * __init create_one_cmux(struct clockgen *cg, int idx)
  666. {
  667. struct mux_hwclock *hwc;
  668. const struct clockgen_pll_div *div;
  669. unsigned long plat_rate, min_rate;
  670. u64 pct80_rate;
  671. u32 clksel;
  672. hwc = kzalloc(sizeof(*hwc), GFP_KERNEL);
  673. if (!hwc)
  674. return NULL;
  675. hwc->reg = cg->regs + 0x20 * idx;
  676. hwc->info = cg->info.cmux_groups[cg->info.cmux_to_group[idx]];
  677. /*
  678. * Find the rate for the default clksel, and treat it as the
  679. * maximum rated core frequency. If this is an incorrect
  680. * assumption, certain clock options (possibly including the
  681. * default clksel) may be inappropriately excluded on certain
  682. * chips.
  683. */
  684. clksel = (cg_in(cg, hwc->reg) & CLKSEL_MASK) >> CLKSEL_SHIFT;
  685. div = get_pll_div(cg, hwc, clksel);
  686. if (!div) {
  687. kfree(hwc);
  688. return NULL;
  689. }
  690. pct80_rate = clk_get_rate(div->clk);
  691. pct80_rate *= 8;
  692. do_div(pct80_rate, 10);
  693. plat_rate = clk_get_rate(cg->pll[PLATFORM_PLL].div[PLL_DIV1].clk);
  694. if (cg->info.flags & CG_CMUX_GE_PLAT)
  695. min_rate = plat_rate;
  696. else
  697. min_rate = plat_rate / 2;
  698. return create_mux_common(cg, hwc, &cmux_ops, min_rate,
  699. pct80_rate, "cg-cmux%d", idx);
  700. }
  701. static struct clk * __init create_one_hwaccel(struct clockgen *cg, int idx)
  702. {
  703. struct mux_hwclock *hwc;
  704. hwc = kzalloc(sizeof(*hwc), GFP_KERNEL);
  705. if (!hwc)
  706. return NULL;
  707. hwc->reg = cg->regs + 0x20 * idx + 0x10;
  708. hwc->info = cg->info.hwaccel[idx];
  709. return create_mux_common(cg, hwc, &hwaccel_ops, 0, 0,
  710. "cg-hwaccel%d", idx);
  711. }
  712. static void __init create_muxes(struct clockgen *cg)
  713. {
  714. int i;
  715. for (i = 0; i < ARRAY_SIZE(cg->cmux); i++) {
  716. if (cg->info.cmux_to_group[i] < 0)
  717. break;
  718. if (cg->info.cmux_to_group[i] >=
  719. ARRAY_SIZE(cg->info.cmux_groups)) {
  720. WARN_ON_ONCE(1);
  721. continue;
  722. }
  723. cg->cmux[i] = create_one_cmux(cg, i);
  724. }
  725. for (i = 0; i < ARRAY_SIZE(cg->hwaccel); i++) {
  726. if (!cg->info.hwaccel[i])
  727. continue;
  728. cg->hwaccel[i] = create_one_hwaccel(cg, i);
  729. }
  730. }
  731. static void __init clockgen_init(struct device_node *np);
  732. /* Legacy nodes may get probed before the parent clockgen node */
  733. static void __init legacy_init_clockgen(struct device_node *np)
  734. {
  735. if (!clockgen.node)
  736. clockgen_init(of_get_parent(np));
  737. }
  738. /* Legacy node */
  739. static void __init core_mux_init(struct device_node *np)
  740. {
  741. struct clk *clk;
  742. struct resource res;
  743. int idx, rc;
  744. legacy_init_clockgen(np);
  745. if (of_address_to_resource(np, 0, &res))
  746. return;
  747. idx = (res.start & 0xf0) >> 5;
  748. clk = clockgen.cmux[idx];
  749. rc = of_clk_add_provider(np, of_clk_src_simple_get, clk);
  750. if (rc) {
  751. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  752. __func__, np->name, rc);
  753. return;
  754. }
  755. }
  756. static struct clk __init
  757. *sysclk_from_fixed(struct device_node *node, const char *name)
  758. {
  759. u32 rate;
  760. if (of_property_read_u32(node, "clock-frequency", &rate))
  761. return ERR_PTR(-ENODEV);
  762. return clk_register_fixed_rate(NULL, name, NULL, 0, rate);
  763. }
  764. static struct clk *sysclk_from_parent(const char *name)
  765. {
  766. struct clk *clk;
  767. const char *parent_name;
  768. clk = of_clk_get(clockgen.node, 0);
  769. if (IS_ERR(clk))
  770. return clk;
  771. /* Register the input clock under the desired name. */
  772. parent_name = __clk_get_name(clk);
  773. clk = clk_register_fixed_factor(NULL, name, parent_name,
  774. 0, 1, 1);
  775. if (IS_ERR(clk))
  776. pr_err("%s: Couldn't register %s: %ld\n", __func__, name,
  777. PTR_ERR(clk));
  778. return clk;
  779. }
  780. static struct clk * __init create_sysclk(const char *name)
  781. {
  782. struct device_node *sysclk;
  783. struct clk *clk;
  784. clk = sysclk_from_fixed(clockgen.node, name);
  785. if (!IS_ERR(clk))
  786. return clk;
  787. clk = sysclk_from_parent(name);
  788. if (!IS_ERR(clk))
  789. return clk;
  790. sysclk = of_get_child_by_name(clockgen.node, "sysclk");
  791. if (sysclk) {
  792. clk = sysclk_from_fixed(sysclk, name);
  793. if (!IS_ERR(clk))
  794. return clk;
  795. }
  796. pr_err("%s: No input clock\n", __func__);
  797. return NULL;
  798. }
  799. /* Legacy node */
  800. static void __init sysclk_init(struct device_node *node)
  801. {
  802. struct clk *clk;
  803. legacy_init_clockgen(node);
  804. clk = clockgen.sysclk;
  805. if (clk)
  806. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  807. }
  808. #define PLL_KILL BIT(31)
  809. static void __init create_one_pll(struct clockgen *cg, int idx)
  810. {
  811. u32 __iomem *reg;
  812. u32 mult;
  813. struct clockgen_pll *pll = &cg->pll[idx];
  814. int i;
  815. if (!(cg->info.pll_mask & (1 << idx)))
  816. return;
  817. if (cg->info.flags & CG_VER3) {
  818. switch (idx) {
  819. case PLATFORM_PLL:
  820. reg = cg->regs + 0x60080;
  821. break;
  822. case CGA_PLL1:
  823. reg = cg->regs + 0x80;
  824. break;
  825. case CGA_PLL2:
  826. reg = cg->regs + 0xa0;
  827. break;
  828. case CGB_PLL1:
  829. reg = cg->regs + 0x10080;
  830. break;
  831. case CGB_PLL2:
  832. reg = cg->regs + 0x100a0;
  833. break;
  834. default:
  835. WARN_ONCE(1, "index %d\n", idx);
  836. return;
  837. }
  838. } else {
  839. if (idx == PLATFORM_PLL)
  840. reg = cg->regs + 0xc00;
  841. else
  842. reg = cg->regs + 0x800 + 0x20 * (idx - 1);
  843. }
  844. /* Get the multiple of PLL */
  845. mult = cg_in(cg, reg);
  846. /* Check if this PLL is disabled */
  847. if (mult & PLL_KILL) {
  848. pr_debug("%s(): pll %p disabled\n", __func__, reg);
  849. return;
  850. }
  851. if ((cg->info.flags & CG_VER3) ||
  852. ((cg->info.flags & CG_PLL_8BIT) && idx != PLATFORM_PLL))
  853. mult = (mult & GENMASK(8, 1)) >> 1;
  854. else
  855. mult = (mult & GENMASK(6, 1)) >> 1;
  856. for (i = 0; i < ARRAY_SIZE(pll->div); i++) {
  857. struct clk *clk;
  858. snprintf(pll->div[i].name, sizeof(pll->div[i].name),
  859. "cg-pll%d-div%d", idx, i + 1);
  860. clk = clk_register_fixed_factor(NULL,
  861. pll->div[i].name, "cg-sysclk", 0, mult, i + 1);
  862. if (IS_ERR(clk)) {
  863. pr_err("%s: %s: register failed %ld\n",
  864. __func__, pll->div[i].name, PTR_ERR(clk));
  865. continue;
  866. }
  867. pll->div[i].clk = clk;
  868. }
  869. }
  870. static void __init create_plls(struct clockgen *cg)
  871. {
  872. int i;
  873. for (i = 0; i < ARRAY_SIZE(cg->pll); i++)
  874. create_one_pll(cg, i);
  875. }
  876. static void __init legacy_pll_init(struct device_node *np, int idx)
  877. {
  878. struct clockgen_pll *pll;
  879. struct clk_onecell_data *onecell_data;
  880. struct clk **subclks;
  881. int count, rc;
  882. legacy_init_clockgen(np);
  883. pll = &clockgen.pll[idx];
  884. count = of_property_count_strings(np, "clock-output-names");
  885. BUILD_BUG_ON(ARRAY_SIZE(pll->div) < 4);
  886. subclks = kcalloc(4, sizeof(struct clk *), GFP_KERNEL);
  887. if (!subclks)
  888. return;
  889. onecell_data = kmalloc(sizeof(*onecell_data), GFP_KERNEL);
  890. if (!onecell_data)
  891. goto err_clks;
  892. if (count <= 3) {
  893. subclks[0] = pll->div[0].clk;
  894. subclks[1] = pll->div[1].clk;
  895. subclks[2] = pll->div[3].clk;
  896. } else {
  897. subclks[0] = pll->div[0].clk;
  898. subclks[1] = pll->div[1].clk;
  899. subclks[2] = pll->div[2].clk;
  900. subclks[3] = pll->div[3].clk;
  901. }
  902. onecell_data->clks = subclks;
  903. onecell_data->clk_num = count;
  904. rc = of_clk_add_provider(np, of_clk_src_onecell_get, onecell_data);
  905. if (rc) {
  906. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  907. __func__, np->name, rc);
  908. goto err_cell;
  909. }
  910. return;
  911. err_cell:
  912. kfree(onecell_data);
  913. err_clks:
  914. kfree(subclks);
  915. }
  916. /* Legacy node */
  917. static void __init pltfrm_pll_init(struct device_node *np)
  918. {
  919. legacy_pll_init(np, PLATFORM_PLL);
  920. }
  921. /* Legacy node */
  922. static void __init core_pll_init(struct device_node *np)
  923. {
  924. struct resource res;
  925. int idx;
  926. if (of_address_to_resource(np, 0, &res))
  927. return;
  928. if ((res.start & 0xfff) == 0xc00) {
  929. /*
  930. * ls1021a devtree labels the platform PLL
  931. * with the core PLL compatible
  932. */
  933. pltfrm_pll_init(np);
  934. } else {
  935. idx = (res.start & 0xf0) >> 5;
  936. legacy_pll_init(np, CGA_PLL1 + idx);
  937. }
  938. }
  939. static struct clk *clockgen_clk_get(struct of_phandle_args *clkspec, void *data)
  940. {
  941. struct clockgen *cg = data;
  942. struct clk *clk;
  943. struct clockgen_pll *pll;
  944. u32 type, idx;
  945. if (clkspec->args_count < 2) {
  946. pr_err("%s: insufficient phandle args\n", __func__);
  947. return ERR_PTR(-EINVAL);
  948. }
  949. type = clkspec->args[0];
  950. idx = clkspec->args[1];
  951. switch (type) {
  952. case 0:
  953. if (idx != 0)
  954. goto bad_args;
  955. clk = cg->sysclk;
  956. break;
  957. case 1:
  958. if (idx >= ARRAY_SIZE(cg->cmux))
  959. goto bad_args;
  960. clk = cg->cmux[idx];
  961. break;
  962. case 2:
  963. if (idx >= ARRAY_SIZE(cg->hwaccel))
  964. goto bad_args;
  965. clk = cg->hwaccel[idx];
  966. break;
  967. case 3:
  968. if (idx >= ARRAY_SIZE(cg->fman))
  969. goto bad_args;
  970. clk = cg->fman[idx];
  971. break;
  972. case 4:
  973. pll = &cg->pll[PLATFORM_PLL];
  974. if (idx >= ARRAY_SIZE(pll->div))
  975. goto bad_args;
  976. clk = pll->div[idx].clk;
  977. break;
  978. default:
  979. goto bad_args;
  980. }
  981. if (!clk)
  982. return ERR_PTR(-ENOENT);
  983. return clk;
  984. bad_args:
  985. pr_err("%s: Bad phandle args %u %u\n", __func__, type, idx);
  986. return ERR_PTR(-EINVAL);
  987. }
  988. #ifdef CONFIG_PPC
  989. #include <asm/mpc85xx.h>
  990. static const u32 a4510_svrs[] __initconst = {
  991. (SVR_P2040 << 8) | 0x10, /* P2040 1.0 */
  992. (SVR_P2040 << 8) | 0x11, /* P2040 1.1 */
  993. (SVR_P2041 << 8) | 0x10, /* P2041 1.0 */
  994. (SVR_P2041 << 8) | 0x11, /* P2041 1.1 */
  995. (SVR_P3041 << 8) | 0x10, /* P3041 1.0 */
  996. (SVR_P3041 << 8) | 0x11, /* P3041 1.1 */
  997. (SVR_P4040 << 8) | 0x20, /* P4040 2.0 */
  998. (SVR_P4080 << 8) | 0x20, /* P4080 2.0 */
  999. (SVR_P5010 << 8) | 0x10, /* P5010 1.0 */
  1000. (SVR_P5010 << 8) | 0x20, /* P5010 2.0 */
  1001. (SVR_P5020 << 8) | 0x10, /* P5020 1.0 */
  1002. (SVR_P5021 << 8) | 0x10, /* P5021 1.0 */
  1003. (SVR_P5040 << 8) | 0x10, /* P5040 1.0 */
  1004. };
  1005. #define SVR_SECURITY 0x80000 /* The Security (E) bit */
  1006. static bool __init has_erratum_a4510(void)
  1007. {
  1008. u32 svr = mfspr(SPRN_SVR);
  1009. int i;
  1010. svr &= ~SVR_SECURITY;
  1011. for (i = 0; i < ARRAY_SIZE(a4510_svrs); i++) {
  1012. if (svr == a4510_svrs[i])
  1013. return true;
  1014. }
  1015. return false;
  1016. }
  1017. #else
  1018. static bool __init has_erratum_a4510(void)
  1019. {
  1020. return false;
  1021. }
  1022. #endif
  1023. static void __init clockgen_init(struct device_node *np)
  1024. {
  1025. int i, ret;
  1026. bool is_old_ls1021a = false;
  1027. /* May have already been called by a legacy probe */
  1028. if (clockgen.node)
  1029. return;
  1030. clockgen.node = np;
  1031. clockgen.regs = of_iomap(np, 0);
  1032. if (!clockgen.regs &&
  1033. of_device_is_compatible(of_root, "fsl,ls1021a")) {
  1034. /* Compatibility hack for old, broken device trees */
  1035. clockgen.regs = ioremap(0x1ee1000, 0x1000);
  1036. is_old_ls1021a = true;
  1037. }
  1038. if (!clockgen.regs) {
  1039. pr_err("%s(): %s: of_iomap() failed\n", __func__, np->name);
  1040. return;
  1041. }
  1042. for (i = 0; i < ARRAY_SIZE(chipinfo); i++) {
  1043. if (of_device_is_compatible(np, chipinfo[i].compat))
  1044. break;
  1045. if (is_old_ls1021a &&
  1046. !strcmp(chipinfo[i].compat, "fsl,ls1021a-clockgen"))
  1047. break;
  1048. }
  1049. if (i == ARRAY_SIZE(chipinfo)) {
  1050. pr_err("%s: unknown clockgen node %s\n", __func__,
  1051. np->full_name);
  1052. goto err;
  1053. }
  1054. clockgen.info = chipinfo[i];
  1055. if (clockgen.info.guts_compat) {
  1056. struct device_node *guts;
  1057. guts = of_find_compatible_node(NULL, NULL,
  1058. clockgen.info.guts_compat);
  1059. if (guts) {
  1060. clockgen.guts = of_iomap(guts, 0);
  1061. if (!clockgen.guts) {
  1062. pr_err("%s: Couldn't map %s regs\n", __func__,
  1063. guts->full_name);
  1064. }
  1065. }
  1066. }
  1067. if (has_erratum_a4510())
  1068. clockgen.info.flags |= CG_CMUX_GE_PLAT;
  1069. clockgen.sysclk = create_sysclk("cg-sysclk");
  1070. create_plls(&clockgen);
  1071. create_muxes(&clockgen);
  1072. if (clockgen.info.init_periph)
  1073. clockgen.info.init_periph(&clockgen);
  1074. ret = of_clk_add_provider(np, clockgen_clk_get, &clockgen);
  1075. if (ret) {
  1076. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  1077. __func__, np->name, ret);
  1078. }
  1079. return;
  1080. err:
  1081. iounmap(clockgen.regs);
  1082. clockgen.regs = NULL;
  1083. }
  1084. CLK_OF_DECLARE(qoriq_clockgen_1, "fsl,qoriq-clockgen-1.0", clockgen_init);
  1085. CLK_OF_DECLARE(qoriq_clockgen_2, "fsl,qoriq-clockgen-2.0", clockgen_init);
  1086. CLK_OF_DECLARE(qoriq_clockgen_ls1021a, "fsl,ls1021a-clockgen", clockgen_init);
  1087. CLK_OF_DECLARE(qoriq_clockgen_ls1043a, "fsl,ls1043a-clockgen", clockgen_init);
  1088. CLK_OF_DECLARE(qoriq_clockgen_ls2080a, "fsl,ls2080a-clockgen", clockgen_init);
  1089. /* Legacy nodes */
  1090. CLK_OF_DECLARE(qoriq_sysclk_1, "fsl,qoriq-sysclk-1.0", sysclk_init);
  1091. CLK_OF_DECLARE(qoriq_sysclk_2, "fsl,qoriq-sysclk-2.0", sysclk_init);
  1092. CLK_OF_DECLARE(qoriq_core_pll_1, "fsl,qoriq-core-pll-1.0", core_pll_init);
  1093. CLK_OF_DECLARE(qoriq_core_pll_2, "fsl,qoriq-core-pll-2.0", core_pll_init);
  1094. CLK_OF_DECLARE(qoriq_core_mux_1, "fsl,qoriq-core-mux-1.0", core_mux_init);
  1095. CLK_OF_DECLARE(qoriq_core_mux_2, "fsl,qoriq-core-mux-2.0", core_mux_init);
  1096. CLK_OF_DECLARE(qoriq_pltfrm_pll_1, "fsl,qoriq-platform-pll-1.0", pltfrm_pll_init);
  1097. CLK_OF_DECLARE(qoriq_pltfrm_pll_2, "fsl,qoriq-platform-pll-2.0", pltfrm_pll_init);