clk-qoriq.c 29 KB

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