clk-qoriq.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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 *sysclk_from_fixed(struct device_node *node, const char *name)
  763. {
  764. u32 rate;
  765. if (of_property_read_u32(node, "clock-frequency", &rate))
  766. return ERR_PTR(-ENODEV);
  767. return clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT, rate);
  768. }
  769. static struct clk *sysclk_from_parent(const char *name)
  770. {
  771. struct clk *clk;
  772. const char *parent_name;
  773. clk = of_clk_get(clockgen.node, 0);
  774. if (IS_ERR(clk))
  775. return clk;
  776. /* Register the input clock under the desired name. */
  777. parent_name = __clk_get_name(clk);
  778. clk = clk_register_fixed_factor(NULL, name, parent_name,
  779. 0, 1, 1);
  780. if (IS_ERR(clk))
  781. pr_err("%s: Couldn't register %s: %ld\n", __func__, name,
  782. PTR_ERR(clk));
  783. return clk;
  784. }
  785. static struct clk * __init create_sysclk(const char *name)
  786. {
  787. struct device_node *sysclk;
  788. struct clk *clk;
  789. clk = sysclk_from_fixed(clockgen.node, name);
  790. if (!IS_ERR(clk))
  791. return clk;
  792. clk = sysclk_from_parent(name);
  793. if (!IS_ERR(clk))
  794. return clk;
  795. sysclk = of_get_child_by_name(clockgen.node, "sysclk");
  796. if (sysclk) {
  797. clk = sysclk_from_fixed(sysclk, name);
  798. if (!IS_ERR(clk))
  799. return clk;
  800. }
  801. pr_err("%s: No input clock\n", __func__);
  802. return NULL;
  803. }
  804. /* Legacy node */
  805. static void __init sysclk_init(struct device_node *node)
  806. {
  807. struct clk *clk;
  808. legacy_init_clockgen(node);
  809. clk = clockgen.sysclk;
  810. if (clk)
  811. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  812. }
  813. #define PLL_KILL BIT(31)
  814. static void __init create_one_pll(struct clockgen *cg, int idx)
  815. {
  816. u32 __iomem *reg;
  817. u32 mult;
  818. struct clockgen_pll *pll = &cg->pll[idx];
  819. int i;
  820. if (!(cg->info.pll_mask & (1 << idx)))
  821. return;
  822. if (cg->info.flags & CG_VER3) {
  823. switch (idx) {
  824. case PLATFORM_PLL:
  825. reg = cg->regs + 0x60080;
  826. break;
  827. case CGA_PLL1:
  828. reg = cg->regs + 0x80;
  829. break;
  830. case CGA_PLL2:
  831. reg = cg->regs + 0xa0;
  832. break;
  833. case CGB_PLL1:
  834. reg = cg->regs + 0x10080;
  835. break;
  836. case CGB_PLL2:
  837. reg = cg->regs + 0x100a0;
  838. break;
  839. default:
  840. WARN_ONCE(1, "index %d\n", idx);
  841. return;
  842. }
  843. } else {
  844. if (idx == PLATFORM_PLL)
  845. reg = cg->regs + 0xc00;
  846. else
  847. reg = cg->regs + 0x800 + 0x20 * (idx - 1);
  848. }
  849. /* Get the multiple of PLL */
  850. mult = cg_in(cg, reg);
  851. /* Check if this PLL is disabled */
  852. if (mult & PLL_KILL) {
  853. pr_debug("%s(): pll %p disabled\n", __func__, reg);
  854. return;
  855. }
  856. if ((cg->info.flags & CG_VER3) ||
  857. ((cg->info.flags & CG_PLL_8BIT) && idx != PLATFORM_PLL))
  858. mult = (mult & GENMASK(8, 1)) >> 1;
  859. else
  860. mult = (mult & GENMASK(6, 1)) >> 1;
  861. for (i = 0; i < ARRAY_SIZE(pll->div); i++) {
  862. struct clk *clk;
  863. snprintf(pll->div[i].name, sizeof(pll->div[i].name),
  864. "cg-pll%d-div%d", idx, i + 1);
  865. clk = clk_register_fixed_factor(NULL,
  866. pll->div[i].name, "cg-sysclk", 0, mult, i + 1);
  867. if (IS_ERR(clk)) {
  868. pr_err("%s: %s: register failed %ld\n",
  869. __func__, pll->div[i].name, PTR_ERR(clk));
  870. continue;
  871. }
  872. pll->div[i].clk = clk;
  873. }
  874. }
  875. static void __init create_plls(struct clockgen *cg)
  876. {
  877. int i;
  878. for (i = 0; i < ARRAY_SIZE(cg->pll); i++)
  879. create_one_pll(cg, i);
  880. }
  881. static void __init legacy_pll_init(struct device_node *np, int idx)
  882. {
  883. struct clockgen_pll *pll;
  884. struct clk_onecell_data *onecell_data;
  885. struct clk **subclks;
  886. int count, rc;
  887. legacy_init_clockgen(np);
  888. pll = &clockgen.pll[idx];
  889. count = of_property_count_strings(np, "clock-output-names");
  890. BUILD_BUG_ON(ARRAY_SIZE(pll->div) < 4);
  891. subclks = kcalloc(4, sizeof(struct clk *), GFP_KERNEL);
  892. if (!subclks)
  893. return;
  894. onecell_data = kmalloc(sizeof(*onecell_data), GFP_KERNEL);
  895. if (!onecell_data)
  896. goto err_clks;
  897. if (count <= 3) {
  898. subclks[0] = pll->div[0].clk;
  899. subclks[1] = pll->div[1].clk;
  900. subclks[2] = pll->div[3].clk;
  901. } else {
  902. subclks[0] = pll->div[0].clk;
  903. subclks[1] = pll->div[1].clk;
  904. subclks[2] = pll->div[2].clk;
  905. subclks[3] = pll->div[3].clk;
  906. }
  907. onecell_data->clks = subclks;
  908. onecell_data->clk_num = count;
  909. rc = of_clk_add_provider(np, of_clk_src_onecell_get, onecell_data);
  910. if (rc) {
  911. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  912. __func__, np->name, rc);
  913. goto err_cell;
  914. }
  915. return;
  916. err_cell:
  917. kfree(onecell_data);
  918. err_clks:
  919. kfree(subclks);
  920. }
  921. /* Legacy node */
  922. static void __init pltfrm_pll_init(struct device_node *np)
  923. {
  924. legacy_pll_init(np, PLATFORM_PLL);
  925. }
  926. /* Legacy node */
  927. static void __init core_pll_init(struct device_node *np)
  928. {
  929. struct resource res;
  930. int idx;
  931. if (of_address_to_resource(np, 0, &res))
  932. return;
  933. if ((res.start & 0xfff) == 0xc00) {
  934. /*
  935. * ls1021a devtree labels the platform PLL
  936. * with the core PLL compatible
  937. */
  938. pltfrm_pll_init(np);
  939. } else {
  940. idx = (res.start & 0xf0) >> 5;
  941. legacy_pll_init(np, CGA_PLL1 + idx);
  942. }
  943. }
  944. static struct clk *clockgen_clk_get(struct of_phandle_args *clkspec, void *data)
  945. {
  946. struct clockgen *cg = data;
  947. struct clk *clk;
  948. struct clockgen_pll *pll;
  949. u32 type, idx;
  950. if (clkspec->args_count < 2) {
  951. pr_err("%s: insufficient phandle args\n", __func__);
  952. return ERR_PTR(-EINVAL);
  953. }
  954. type = clkspec->args[0];
  955. idx = clkspec->args[1];
  956. switch (type) {
  957. case 0:
  958. if (idx != 0)
  959. goto bad_args;
  960. clk = cg->sysclk;
  961. break;
  962. case 1:
  963. if (idx >= ARRAY_SIZE(cg->cmux))
  964. goto bad_args;
  965. clk = cg->cmux[idx];
  966. break;
  967. case 2:
  968. if (idx >= ARRAY_SIZE(cg->hwaccel))
  969. goto bad_args;
  970. clk = cg->hwaccel[idx];
  971. break;
  972. case 3:
  973. if (idx >= ARRAY_SIZE(cg->fman))
  974. goto bad_args;
  975. clk = cg->fman[idx];
  976. break;
  977. case 4:
  978. pll = &cg->pll[PLATFORM_PLL];
  979. if (idx >= ARRAY_SIZE(pll->div))
  980. goto bad_args;
  981. clk = pll->div[idx].clk;
  982. break;
  983. default:
  984. goto bad_args;
  985. }
  986. if (!clk)
  987. return ERR_PTR(-ENOENT);
  988. return clk;
  989. bad_args:
  990. pr_err("%s: Bad phandle args %u %u\n", __func__, type, idx);
  991. return ERR_PTR(-EINVAL);
  992. }
  993. #ifdef CONFIG_PPC
  994. #include <asm/mpc85xx.h>
  995. static const u32 a4510_svrs[] __initconst = {
  996. (SVR_P2040 << 8) | 0x10, /* P2040 1.0 */
  997. (SVR_P2040 << 8) | 0x11, /* P2040 1.1 */
  998. (SVR_P2041 << 8) | 0x10, /* P2041 1.0 */
  999. (SVR_P2041 << 8) | 0x11, /* P2041 1.1 */
  1000. (SVR_P3041 << 8) | 0x10, /* P3041 1.0 */
  1001. (SVR_P3041 << 8) | 0x11, /* P3041 1.1 */
  1002. (SVR_P4040 << 8) | 0x20, /* P4040 2.0 */
  1003. (SVR_P4080 << 8) | 0x20, /* P4080 2.0 */
  1004. (SVR_P5010 << 8) | 0x10, /* P5010 1.0 */
  1005. (SVR_P5010 << 8) | 0x20, /* P5010 2.0 */
  1006. (SVR_P5020 << 8) | 0x10, /* P5020 1.0 */
  1007. (SVR_P5021 << 8) | 0x10, /* P5021 1.0 */
  1008. (SVR_P5040 << 8) | 0x10, /* P5040 1.0 */
  1009. };
  1010. #define SVR_SECURITY 0x80000 /* The Security (E) bit */
  1011. static bool __init has_erratum_a4510(void)
  1012. {
  1013. u32 svr = mfspr(SPRN_SVR);
  1014. int i;
  1015. svr &= ~SVR_SECURITY;
  1016. for (i = 0; i < ARRAY_SIZE(a4510_svrs); i++) {
  1017. if (svr == a4510_svrs[i])
  1018. return true;
  1019. }
  1020. return false;
  1021. }
  1022. #else
  1023. static bool __init has_erratum_a4510(void)
  1024. {
  1025. return false;
  1026. }
  1027. #endif
  1028. static void __init clockgen_init(struct device_node *np)
  1029. {
  1030. int i, ret;
  1031. bool is_old_ls1021a = false;
  1032. /* May have already been called by a legacy probe */
  1033. if (clockgen.node)
  1034. return;
  1035. clockgen.node = np;
  1036. clockgen.regs = of_iomap(np, 0);
  1037. if (!clockgen.regs &&
  1038. of_device_is_compatible(of_root, "fsl,ls1021a")) {
  1039. /* Compatibility hack for old, broken device trees */
  1040. clockgen.regs = ioremap(0x1ee1000, 0x1000);
  1041. is_old_ls1021a = true;
  1042. }
  1043. if (!clockgen.regs) {
  1044. pr_err("%s(): %s: of_iomap() failed\n", __func__, np->name);
  1045. return;
  1046. }
  1047. for (i = 0; i < ARRAY_SIZE(chipinfo); i++) {
  1048. if (of_device_is_compatible(np, chipinfo[i].compat))
  1049. break;
  1050. if (is_old_ls1021a &&
  1051. !strcmp(chipinfo[i].compat, "fsl,ls1021a-clockgen"))
  1052. break;
  1053. }
  1054. if (i == ARRAY_SIZE(chipinfo)) {
  1055. pr_err("%s: unknown clockgen node %s\n", __func__,
  1056. np->full_name);
  1057. goto err;
  1058. }
  1059. clockgen.info = chipinfo[i];
  1060. if (clockgen.info.guts_compat) {
  1061. struct device_node *guts;
  1062. guts = of_find_compatible_node(NULL, NULL,
  1063. clockgen.info.guts_compat);
  1064. if (guts) {
  1065. clockgen.guts = of_iomap(guts, 0);
  1066. if (!clockgen.guts) {
  1067. pr_err("%s: Couldn't map %s regs\n", __func__,
  1068. guts->full_name);
  1069. }
  1070. }
  1071. }
  1072. if (has_erratum_a4510())
  1073. clockgen.info.flags |= CG_CMUX_GE_PLAT;
  1074. clockgen.sysclk = create_sysclk("cg-sysclk");
  1075. create_plls(&clockgen);
  1076. create_muxes(&clockgen);
  1077. if (clockgen.info.init_periph)
  1078. clockgen.info.init_periph(&clockgen);
  1079. ret = of_clk_add_provider(np, clockgen_clk_get, &clockgen);
  1080. if (ret) {
  1081. pr_err("%s: Couldn't register clk provider for node %s: %d\n",
  1082. __func__, np->name, ret);
  1083. }
  1084. return;
  1085. err:
  1086. iounmap(clockgen.regs);
  1087. clockgen.regs = NULL;
  1088. }
  1089. CLK_OF_DECLARE(qoriq_clockgen_1, "fsl,qoriq-clockgen-1.0", clockgen_init);
  1090. CLK_OF_DECLARE(qoriq_clockgen_2, "fsl,qoriq-clockgen-2.0", clockgen_init);
  1091. CLK_OF_DECLARE(qoriq_clockgen_ls1021a, "fsl,ls1021a-clockgen", clockgen_init);
  1092. CLK_OF_DECLARE(qoriq_clockgen_ls1043a, "fsl,ls1043a-clockgen", clockgen_init);
  1093. CLK_OF_DECLARE(qoriq_clockgen_ls2080a, "fsl,ls2080a-clockgen", clockgen_init);
  1094. /* Legacy nodes */
  1095. CLK_OF_DECLARE(qoriq_sysclk_1, "fsl,qoriq-sysclk-1.0", sysclk_init);
  1096. CLK_OF_DECLARE(qoriq_sysclk_2, "fsl,qoriq-sysclk-2.0", sysclk_init);
  1097. CLK_OF_DECLARE(qoriq_core_pll_1, "fsl,qoriq-core-pll-1.0", core_pll_init);
  1098. CLK_OF_DECLARE(qoriq_core_pll_2, "fsl,qoriq-core-pll-2.0", core_pll_init);
  1099. CLK_OF_DECLARE(qoriq_core_mux_1, "fsl,qoriq-core-mux-1.0", core_mux_init);
  1100. CLK_OF_DECLARE(qoriq_core_mux_2, "fsl,qoriq-core-mux-2.0", core_mux_init);
  1101. CLK_OF_DECLARE(qoriq_pltfrm_pll_1, "fsl,qoriq-platform-pll-1.0", pltfrm_pll_init);
  1102. CLK_OF_DECLARE(qoriq_pltfrm_pll_2, "fsl,qoriq-platform-pll-2.0", pltfrm_pll_init);