clk-qoriq.c 29 KB

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