clk-prima2.c 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. /*
  2. * Clock tree for CSR SiRFprimaII
  3. *
  4. * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/bitops.h>
  10. #include <linux/io.h>
  11. #include <linux/clk.h>
  12. #include <linux/clkdev.h>
  13. #include <linux/clk-provider.h>
  14. #include <linux/of_address.h>
  15. #include <linux/syscore_ops.h>
  16. #define SIRFSOC_CLKC_CLK_EN0 0x0000
  17. #define SIRFSOC_CLKC_CLK_EN1 0x0004
  18. #define SIRFSOC_CLKC_REF_CFG 0x0014
  19. #define SIRFSOC_CLKC_CPU_CFG 0x0018
  20. #define SIRFSOC_CLKC_MEM_CFG 0x001c
  21. #define SIRFSOC_CLKC_SYS_CFG 0x0020
  22. #define SIRFSOC_CLKC_IO_CFG 0x0024
  23. #define SIRFSOC_CLKC_DSP_CFG 0x0028
  24. #define SIRFSOC_CLKC_GFX_CFG 0x002c
  25. #define SIRFSOC_CLKC_MM_CFG 0x0030
  26. #define SIRFSOC_CLKC_LCD_CFG 0x0034
  27. #define SIRFSOC_CLKC_MMC_CFG 0x0038
  28. #define SIRFSOC_CLKC_PLL1_CFG0 0x0040
  29. #define SIRFSOC_CLKC_PLL2_CFG0 0x0044
  30. #define SIRFSOC_CLKC_PLL3_CFG0 0x0048
  31. #define SIRFSOC_CLKC_PLL1_CFG1 0x004c
  32. #define SIRFSOC_CLKC_PLL2_CFG1 0x0050
  33. #define SIRFSOC_CLKC_PLL3_CFG1 0x0054
  34. #define SIRFSOC_CLKC_PLL1_CFG2 0x0058
  35. #define SIRFSOC_CLKC_PLL2_CFG2 0x005c
  36. #define SIRFSOC_CLKC_PLL3_CFG2 0x0060
  37. #define SIRFSOC_USBPHY_PLL_CTRL 0x0008
  38. #define SIRFSOC_USBPHY_PLL_POWERDOWN BIT(1)
  39. #define SIRFSOC_USBPHY_PLL_BYPASS BIT(2)
  40. #define SIRFSOC_USBPHY_PLL_LOCK BIT(3)
  41. static void *sirfsoc_clk_vbase, *sirfsoc_rsc_vbase;
  42. #define KHZ 1000
  43. #define MHZ (KHZ * KHZ)
  44. /*
  45. * SiRFprimaII clock controller
  46. * - 2 oscillators: osc-26MHz, rtc-32.768KHz
  47. * - 3 standard configurable plls: pll1, pll2 & pll3
  48. * - 2 exclusive plls: usb phy pll and sata phy pll
  49. * - 8 clock domains: cpu/cpudiv, mem/memdiv, sys/io, dsp, graphic, multimedia,
  50. * display and sdphy.
  51. * Each clock domain can select its own clock source from five clock sources,
  52. * X_XIN, X_XINW, PLL1, PLL2 and PLL3. The domain clock is used as the source
  53. * clock of the group clock.
  54. * - dsp domain: gps, mf
  55. * - io domain: dmac, nand, audio, uart, i2c, spi, usp, pwm, pulse
  56. * - sys domain: security
  57. */
  58. struct clk_pll {
  59. struct clk_hw hw;
  60. unsigned short regofs; /* register offset */
  61. };
  62. #define to_pllclk(_hw) container_of(_hw, struct clk_pll, hw)
  63. struct clk_dmn {
  64. struct clk_hw hw;
  65. signed char enable_bit; /* enable bit: 0 ~ 63 */
  66. unsigned short regofs; /* register offset */
  67. };
  68. #define to_dmnclk(_hw) container_of(_hw, struct clk_dmn, hw)
  69. struct clk_std {
  70. struct clk_hw hw;
  71. signed char enable_bit; /* enable bit: 0 ~ 63 */
  72. };
  73. #define to_stdclk(_hw) container_of(_hw, struct clk_std, hw)
  74. static int std_clk_is_enabled(struct clk_hw *hw);
  75. static int std_clk_enable(struct clk_hw *hw);
  76. static void std_clk_disable(struct clk_hw *hw);
  77. static inline unsigned long clkc_readl(unsigned reg)
  78. {
  79. return readl(sirfsoc_clk_vbase + reg);
  80. }
  81. static inline void clkc_writel(u32 val, unsigned reg)
  82. {
  83. writel(val, sirfsoc_clk_vbase + reg);
  84. }
  85. /*
  86. * std pll
  87. */
  88. static unsigned long pll_clk_recalc_rate(struct clk_hw *hw,
  89. unsigned long parent_rate)
  90. {
  91. unsigned long fin = parent_rate;
  92. struct clk_pll *clk = to_pllclk(hw);
  93. u32 regcfg2 = clk->regofs + SIRFSOC_CLKC_PLL1_CFG2 -
  94. SIRFSOC_CLKC_PLL1_CFG0;
  95. if (clkc_readl(regcfg2) & BIT(2)) {
  96. /* pll bypass mode */
  97. return fin;
  98. } else {
  99. /* fout = fin * nf / nr / od */
  100. u32 cfg0 = clkc_readl(clk->regofs);
  101. u32 nf = (cfg0 & (BIT(13) - 1)) + 1;
  102. u32 nr = ((cfg0 >> 13) & (BIT(6) - 1)) + 1;
  103. u32 od = ((cfg0 >> 19) & (BIT(4) - 1)) + 1;
  104. WARN_ON(fin % MHZ);
  105. return fin / MHZ * nf / nr / od * MHZ;
  106. }
  107. }
  108. static long pll_clk_round_rate(struct clk_hw *hw, unsigned long rate,
  109. unsigned long *parent_rate)
  110. {
  111. unsigned long fin, nf, nr, od;
  112. /*
  113. * fout = fin * nf / (nr * od);
  114. * set od = 1, nr = fin/MHz, so fout = nf * MHz
  115. */
  116. rate = rate - rate % MHZ;
  117. nf = rate / MHZ;
  118. if (nf > BIT(13))
  119. nf = BIT(13);
  120. if (nf < 1)
  121. nf = 1;
  122. fin = *parent_rate;
  123. nr = fin / MHZ;
  124. if (nr > BIT(6))
  125. nr = BIT(6);
  126. od = 1;
  127. return fin * nf / (nr * od);
  128. }
  129. static int pll_clk_set_rate(struct clk_hw *hw, unsigned long rate,
  130. unsigned long parent_rate)
  131. {
  132. struct clk_pll *clk = to_pllclk(hw);
  133. unsigned long fin, nf, nr, od, reg;
  134. /*
  135. * fout = fin * nf / (nr * od);
  136. * set od = 1, nr = fin/MHz, so fout = nf * MHz
  137. */
  138. nf = rate / MHZ;
  139. if (unlikely((rate % MHZ) || nf > BIT(13) || nf < 1))
  140. return -EINVAL;
  141. fin = parent_rate;
  142. BUG_ON(fin < MHZ);
  143. nr = fin / MHZ;
  144. BUG_ON((fin % MHZ) || nr > BIT(6));
  145. od = 1;
  146. reg = (nf - 1) | ((nr - 1) << 13) | ((od - 1) << 19);
  147. clkc_writel(reg, clk->regofs);
  148. reg = clk->regofs + SIRFSOC_CLKC_PLL1_CFG1 - SIRFSOC_CLKC_PLL1_CFG0;
  149. clkc_writel((nf >> 1) - 1, reg);
  150. reg = clk->regofs + SIRFSOC_CLKC_PLL1_CFG2 - SIRFSOC_CLKC_PLL1_CFG0;
  151. while (!(clkc_readl(reg) & BIT(6)))
  152. cpu_relax();
  153. return 0;
  154. }
  155. static struct clk_ops std_pll_ops = {
  156. .recalc_rate = pll_clk_recalc_rate,
  157. .round_rate = pll_clk_round_rate,
  158. .set_rate = pll_clk_set_rate,
  159. };
  160. static const char *pll_clk_parents[] = {
  161. "osc",
  162. };
  163. static struct clk_init_data clk_pll1_init = {
  164. .name = "pll1",
  165. .ops = &std_pll_ops,
  166. .parent_names = pll_clk_parents,
  167. .num_parents = ARRAY_SIZE(pll_clk_parents),
  168. };
  169. static struct clk_init_data clk_pll2_init = {
  170. .name = "pll2",
  171. .ops = &std_pll_ops,
  172. .parent_names = pll_clk_parents,
  173. .num_parents = ARRAY_SIZE(pll_clk_parents),
  174. };
  175. static struct clk_init_data clk_pll3_init = {
  176. .name = "pll3",
  177. .ops = &std_pll_ops,
  178. .parent_names = pll_clk_parents,
  179. .num_parents = ARRAY_SIZE(pll_clk_parents),
  180. };
  181. static struct clk_pll clk_pll1 = {
  182. .regofs = SIRFSOC_CLKC_PLL1_CFG0,
  183. .hw = {
  184. .init = &clk_pll1_init,
  185. },
  186. };
  187. static struct clk_pll clk_pll2 = {
  188. .regofs = SIRFSOC_CLKC_PLL2_CFG0,
  189. .hw = {
  190. .init = &clk_pll2_init,
  191. },
  192. };
  193. static struct clk_pll clk_pll3 = {
  194. .regofs = SIRFSOC_CLKC_PLL3_CFG0,
  195. .hw = {
  196. .init = &clk_pll3_init,
  197. },
  198. };
  199. /*
  200. * usb uses specified pll
  201. */
  202. static int usb_pll_clk_enable(struct clk_hw *hw)
  203. {
  204. u32 reg = readl(sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  205. reg &= ~(SIRFSOC_USBPHY_PLL_POWERDOWN | SIRFSOC_USBPHY_PLL_BYPASS);
  206. writel(reg, sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  207. while (!(readl(sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL) &
  208. SIRFSOC_USBPHY_PLL_LOCK))
  209. cpu_relax();
  210. return 0;
  211. }
  212. static void usb_pll_clk_disable(struct clk_hw *clk)
  213. {
  214. u32 reg = readl(sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  215. reg |= (SIRFSOC_USBPHY_PLL_POWERDOWN | SIRFSOC_USBPHY_PLL_BYPASS);
  216. writel(reg, sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  217. }
  218. static unsigned long usb_pll_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
  219. {
  220. u32 reg = readl(sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  221. return (reg & SIRFSOC_USBPHY_PLL_BYPASS) ? parent_rate : 48*MHZ;
  222. }
  223. static struct clk_ops usb_pll_ops = {
  224. .enable = usb_pll_clk_enable,
  225. .disable = usb_pll_clk_disable,
  226. .recalc_rate = usb_pll_clk_recalc_rate,
  227. };
  228. static struct clk_init_data clk_usb_pll_init = {
  229. .name = "usb_pll",
  230. .ops = &usb_pll_ops,
  231. .parent_names = pll_clk_parents,
  232. .num_parents = ARRAY_SIZE(pll_clk_parents),
  233. };
  234. static struct clk_hw usb_pll_clk_hw = {
  235. .init = &clk_usb_pll_init,
  236. };
  237. /*
  238. * clock domains - cpu, mem, sys/io, dsp, gfx
  239. */
  240. static const char *dmn_clk_parents[] = {
  241. "rtc",
  242. "osc",
  243. "pll1",
  244. "pll2",
  245. "pll3",
  246. };
  247. static u8 dmn_clk_get_parent(struct clk_hw *hw)
  248. {
  249. struct clk_dmn *clk = to_dmnclk(hw);
  250. u32 cfg = clkc_readl(clk->regofs);
  251. /* parent of io domain can only be pll3 */
  252. if (strcmp(hw->init->name, "io") == 0)
  253. return 4;
  254. WARN_ON((cfg & (BIT(3) - 1)) > 4);
  255. return cfg & (BIT(3) - 1);
  256. }
  257. static int dmn_clk_set_parent(struct clk_hw *hw, u8 parent)
  258. {
  259. struct clk_dmn *clk = to_dmnclk(hw);
  260. u32 cfg = clkc_readl(clk->regofs);
  261. /* parent of io domain can only be pll3 */
  262. if (strcmp(hw->init->name, "io") == 0)
  263. return -EINVAL;
  264. cfg &= ~(BIT(3) - 1);
  265. clkc_writel(cfg | parent, clk->regofs);
  266. /* BIT(3) - switching status: 1 - busy, 0 - done */
  267. while (clkc_readl(clk->regofs) & BIT(3))
  268. cpu_relax();
  269. return 0;
  270. }
  271. static unsigned long dmn_clk_recalc_rate(struct clk_hw *hw,
  272. unsigned long parent_rate)
  273. {
  274. unsigned long fin = parent_rate;
  275. struct clk_dmn *clk = to_dmnclk(hw);
  276. u32 cfg = clkc_readl(clk->regofs);
  277. if (cfg & BIT(24)) {
  278. /* fcd bypass mode */
  279. return fin;
  280. } else {
  281. /*
  282. * wait count: bit[19:16], hold count: bit[23:20]
  283. */
  284. u32 wait = (cfg >> 16) & (BIT(4) - 1);
  285. u32 hold = (cfg >> 20) & (BIT(4) - 1);
  286. return fin / (wait + hold + 2);
  287. }
  288. }
  289. static long dmn_clk_round_rate(struct clk_hw *hw, unsigned long rate,
  290. unsigned long *parent_rate)
  291. {
  292. unsigned long fin;
  293. unsigned ratio, wait, hold;
  294. unsigned bits = (strcmp(hw->init->name, "mem") == 0) ? 3 : 4;
  295. fin = *parent_rate;
  296. ratio = fin / rate;
  297. if (ratio < 2)
  298. ratio = 2;
  299. if (ratio > BIT(bits + 1))
  300. ratio = BIT(bits + 1);
  301. wait = (ratio >> 1) - 1;
  302. hold = ratio - wait - 2;
  303. return fin / (wait + hold + 2);
  304. }
  305. static int dmn_clk_set_rate(struct clk_hw *hw, unsigned long rate,
  306. unsigned long parent_rate)
  307. {
  308. struct clk_dmn *clk = to_dmnclk(hw);
  309. unsigned long fin;
  310. unsigned ratio, wait, hold, reg;
  311. unsigned bits = (strcmp(hw->init->name, "mem") == 0) ? 3 : 4;
  312. fin = parent_rate;
  313. ratio = fin / rate;
  314. if (unlikely(ratio < 2 || ratio > BIT(bits + 1)))
  315. return -EINVAL;
  316. WARN_ON(fin % rate);
  317. wait = (ratio >> 1) - 1;
  318. hold = ratio - wait - 2;
  319. reg = clkc_readl(clk->regofs);
  320. reg &= ~(((BIT(bits) - 1) << 16) | ((BIT(bits) - 1) << 20));
  321. reg |= (wait << 16) | (hold << 20) | BIT(25);
  322. clkc_writel(reg, clk->regofs);
  323. /* waiting FCD been effective */
  324. while (clkc_readl(clk->regofs) & BIT(25))
  325. cpu_relax();
  326. return 0;
  327. }
  328. static struct clk_ops msi_ops = {
  329. .set_rate = dmn_clk_set_rate,
  330. .round_rate = dmn_clk_round_rate,
  331. .recalc_rate = dmn_clk_recalc_rate,
  332. .set_parent = dmn_clk_set_parent,
  333. .get_parent = dmn_clk_get_parent,
  334. };
  335. static struct clk_init_data clk_mem_init = {
  336. .name = "mem",
  337. .ops = &msi_ops,
  338. .parent_names = dmn_clk_parents,
  339. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  340. };
  341. static struct clk_dmn clk_mem = {
  342. .regofs = SIRFSOC_CLKC_MEM_CFG,
  343. .hw = {
  344. .init = &clk_mem_init,
  345. },
  346. };
  347. static struct clk_init_data clk_sys_init = {
  348. .name = "sys",
  349. .ops = &msi_ops,
  350. .parent_names = dmn_clk_parents,
  351. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  352. .flags = CLK_SET_RATE_GATE,
  353. };
  354. static struct clk_dmn clk_sys = {
  355. .regofs = SIRFSOC_CLKC_SYS_CFG,
  356. .hw = {
  357. .init = &clk_sys_init,
  358. },
  359. };
  360. static struct clk_init_data clk_io_init = {
  361. .name = "io",
  362. .ops = &msi_ops,
  363. .parent_names = dmn_clk_parents,
  364. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  365. };
  366. static struct clk_dmn clk_io = {
  367. .regofs = SIRFSOC_CLKC_IO_CFG,
  368. .hw = {
  369. .init = &clk_io_init,
  370. },
  371. };
  372. static struct clk_ops cpu_ops = {
  373. .set_parent = dmn_clk_set_parent,
  374. .get_parent = dmn_clk_get_parent,
  375. };
  376. static struct clk_init_data clk_cpu_init = {
  377. .name = "cpu",
  378. .ops = &cpu_ops,
  379. .parent_names = dmn_clk_parents,
  380. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  381. .flags = CLK_SET_RATE_PARENT,
  382. };
  383. static struct clk_dmn clk_cpu = {
  384. .regofs = SIRFSOC_CLKC_CPU_CFG,
  385. .hw = {
  386. .init = &clk_cpu_init,
  387. },
  388. };
  389. static struct clk_ops dmn_ops = {
  390. .is_enabled = std_clk_is_enabled,
  391. .enable = std_clk_enable,
  392. .disable = std_clk_disable,
  393. .set_rate = dmn_clk_set_rate,
  394. .round_rate = dmn_clk_round_rate,
  395. .recalc_rate = dmn_clk_recalc_rate,
  396. .set_parent = dmn_clk_set_parent,
  397. .get_parent = dmn_clk_get_parent,
  398. };
  399. /* dsp, gfx, mm, lcd and vpp domain */
  400. static struct clk_init_data clk_dsp_init = {
  401. .name = "dsp",
  402. .ops = &dmn_ops,
  403. .parent_names = dmn_clk_parents,
  404. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  405. };
  406. static struct clk_dmn clk_dsp = {
  407. .regofs = SIRFSOC_CLKC_DSP_CFG,
  408. .enable_bit = 0,
  409. .hw = {
  410. .init = &clk_dsp_init,
  411. },
  412. };
  413. static struct clk_init_data clk_gfx_init = {
  414. .name = "gfx",
  415. .ops = &dmn_ops,
  416. .parent_names = dmn_clk_parents,
  417. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  418. };
  419. static struct clk_dmn clk_gfx = {
  420. .regofs = SIRFSOC_CLKC_GFX_CFG,
  421. .enable_bit = 8,
  422. .hw = {
  423. .init = &clk_gfx_init,
  424. },
  425. };
  426. static struct clk_init_data clk_mm_init = {
  427. .name = "mm",
  428. .ops = &dmn_ops,
  429. .parent_names = dmn_clk_parents,
  430. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  431. };
  432. static struct clk_dmn clk_mm = {
  433. .regofs = SIRFSOC_CLKC_MM_CFG,
  434. .enable_bit = 9,
  435. .hw = {
  436. .init = &clk_mm_init,
  437. },
  438. };
  439. static struct clk_init_data clk_lcd_init = {
  440. .name = "lcd",
  441. .ops = &dmn_ops,
  442. .parent_names = dmn_clk_parents,
  443. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  444. };
  445. static struct clk_dmn clk_lcd = {
  446. .regofs = SIRFSOC_CLKC_LCD_CFG,
  447. .enable_bit = 10,
  448. .hw = {
  449. .init = &clk_lcd_init,
  450. },
  451. };
  452. static struct clk_init_data clk_vpp_init = {
  453. .name = "vpp",
  454. .ops = &dmn_ops,
  455. .parent_names = dmn_clk_parents,
  456. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  457. };
  458. static struct clk_dmn clk_vpp = {
  459. .regofs = SIRFSOC_CLKC_LCD_CFG,
  460. .enable_bit = 11,
  461. .hw = {
  462. .init = &clk_vpp_init,
  463. },
  464. };
  465. static struct clk_init_data clk_mmc01_init = {
  466. .name = "mmc01",
  467. .ops = &dmn_ops,
  468. .parent_names = dmn_clk_parents,
  469. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  470. };
  471. static struct clk_dmn clk_mmc01 = {
  472. .regofs = SIRFSOC_CLKC_MMC_CFG,
  473. .enable_bit = 59,
  474. .hw = {
  475. .init = &clk_mmc01_init,
  476. },
  477. };
  478. static struct clk_init_data clk_mmc23_init = {
  479. .name = "mmc23",
  480. .ops = &dmn_ops,
  481. .parent_names = dmn_clk_parents,
  482. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  483. };
  484. static struct clk_dmn clk_mmc23 = {
  485. .regofs = SIRFSOC_CLKC_MMC_CFG,
  486. .enable_bit = 60,
  487. .hw = {
  488. .init = &clk_mmc23_init,
  489. },
  490. };
  491. static struct clk_init_data clk_mmc45_init = {
  492. .name = "mmc45",
  493. .ops = &dmn_ops,
  494. .parent_names = dmn_clk_parents,
  495. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  496. };
  497. static struct clk_dmn clk_mmc45 = {
  498. .regofs = SIRFSOC_CLKC_MMC_CFG,
  499. .enable_bit = 61,
  500. .hw = {
  501. .init = &clk_mmc45_init,
  502. },
  503. };
  504. /*
  505. * peripheral controllers in io domain
  506. */
  507. static int std_clk_is_enabled(struct clk_hw *hw)
  508. {
  509. u32 reg;
  510. int bit;
  511. struct clk_std *clk = to_stdclk(hw);
  512. bit = clk->enable_bit % 32;
  513. reg = clk->enable_bit / 32;
  514. reg = SIRFSOC_CLKC_CLK_EN0 + reg * sizeof(reg);
  515. return !!(clkc_readl(reg) & BIT(bit));
  516. }
  517. static int std_clk_enable(struct clk_hw *hw)
  518. {
  519. u32 val, reg;
  520. int bit;
  521. struct clk_std *clk = to_stdclk(hw);
  522. BUG_ON(clk->enable_bit < 0 || clk->enable_bit > 63);
  523. bit = clk->enable_bit % 32;
  524. reg = clk->enable_bit / 32;
  525. reg = SIRFSOC_CLKC_CLK_EN0 + reg * sizeof(reg);
  526. val = clkc_readl(reg) | BIT(bit);
  527. clkc_writel(val, reg);
  528. return 0;
  529. }
  530. static void std_clk_disable(struct clk_hw *hw)
  531. {
  532. u32 val, reg;
  533. int bit;
  534. struct clk_std *clk = to_stdclk(hw);
  535. BUG_ON(clk->enable_bit < 0 || clk->enable_bit > 63);
  536. bit = clk->enable_bit % 32;
  537. reg = clk->enable_bit / 32;
  538. reg = SIRFSOC_CLKC_CLK_EN0 + reg * sizeof(reg);
  539. val = clkc_readl(reg) & ~BIT(bit);
  540. clkc_writel(val, reg);
  541. }
  542. static const char *std_clk_io_parents[] = {
  543. "io",
  544. };
  545. static struct clk_ops ios_ops = {
  546. .is_enabled = std_clk_is_enabled,
  547. .enable = std_clk_enable,
  548. .disable = std_clk_disable,
  549. };
  550. static struct clk_init_data clk_dmac0_init = {
  551. .name = "dmac0",
  552. .ops = &ios_ops,
  553. .parent_names = std_clk_io_parents,
  554. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  555. };
  556. static struct clk_std clk_dmac0 = {
  557. .enable_bit = 32,
  558. .hw = {
  559. .init = &clk_dmac0_init,
  560. },
  561. };
  562. static struct clk_init_data clk_dmac1_init = {
  563. .name = "dmac1",
  564. .ops = &ios_ops,
  565. .parent_names = std_clk_io_parents,
  566. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  567. };
  568. static struct clk_std clk_dmac1 = {
  569. .enable_bit = 33,
  570. .hw = {
  571. .init = &clk_dmac1_init,
  572. },
  573. };
  574. static struct clk_init_data clk_nand_init = {
  575. .name = "nand",
  576. .ops = &ios_ops,
  577. .parent_names = std_clk_io_parents,
  578. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  579. };
  580. static struct clk_std clk_nand = {
  581. .enable_bit = 34,
  582. .hw = {
  583. .init = &clk_nand_init,
  584. },
  585. };
  586. static struct clk_init_data clk_audio_init = {
  587. .name = "audio",
  588. .ops = &ios_ops,
  589. .parent_names = std_clk_io_parents,
  590. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  591. };
  592. static struct clk_std clk_audio = {
  593. .enable_bit = 35,
  594. .hw = {
  595. .init = &clk_audio_init,
  596. },
  597. };
  598. static struct clk_init_data clk_uart0_init = {
  599. .name = "uart0",
  600. .ops = &ios_ops,
  601. .parent_names = std_clk_io_parents,
  602. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  603. };
  604. static struct clk_std clk_uart0 = {
  605. .enable_bit = 36,
  606. .hw = {
  607. .init = &clk_uart0_init,
  608. },
  609. };
  610. static struct clk_init_data clk_uart1_init = {
  611. .name = "uart1",
  612. .ops = &ios_ops,
  613. .parent_names = std_clk_io_parents,
  614. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  615. };
  616. static struct clk_std clk_uart1 = {
  617. .enable_bit = 37,
  618. .hw = {
  619. .init = &clk_uart1_init,
  620. },
  621. };
  622. static struct clk_init_data clk_uart2_init = {
  623. .name = "uart2",
  624. .ops = &ios_ops,
  625. .parent_names = std_clk_io_parents,
  626. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  627. };
  628. static struct clk_std clk_uart2 = {
  629. .enable_bit = 38,
  630. .hw = {
  631. .init = &clk_uart2_init,
  632. },
  633. };
  634. static struct clk_init_data clk_usp0_init = {
  635. .name = "usp0",
  636. .ops = &ios_ops,
  637. .parent_names = std_clk_io_parents,
  638. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  639. };
  640. static struct clk_std clk_usp0 = {
  641. .enable_bit = 39,
  642. .hw = {
  643. .init = &clk_usp0_init,
  644. },
  645. };
  646. static struct clk_init_data clk_usp1_init = {
  647. .name = "usp1",
  648. .ops = &ios_ops,
  649. .parent_names = std_clk_io_parents,
  650. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  651. };
  652. static struct clk_std clk_usp1 = {
  653. .enable_bit = 40,
  654. .hw = {
  655. .init = &clk_usp1_init,
  656. },
  657. };
  658. static struct clk_init_data clk_usp2_init = {
  659. .name = "usp2",
  660. .ops = &ios_ops,
  661. .parent_names = std_clk_io_parents,
  662. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  663. };
  664. static struct clk_std clk_usp2 = {
  665. .enable_bit = 41,
  666. .hw = {
  667. .init = &clk_usp2_init,
  668. },
  669. };
  670. static struct clk_init_data clk_vip_init = {
  671. .name = "vip",
  672. .ops = &ios_ops,
  673. .parent_names = std_clk_io_parents,
  674. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  675. };
  676. static struct clk_std clk_vip = {
  677. .enable_bit = 42,
  678. .hw = {
  679. .init = &clk_vip_init,
  680. },
  681. };
  682. static struct clk_init_data clk_spi0_init = {
  683. .name = "spi0",
  684. .ops = &ios_ops,
  685. .parent_names = std_clk_io_parents,
  686. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  687. };
  688. static struct clk_std clk_spi0 = {
  689. .enable_bit = 43,
  690. .hw = {
  691. .init = &clk_spi0_init,
  692. },
  693. };
  694. static struct clk_init_data clk_spi1_init = {
  695. .name = "spi1",
  696. .ops = &ios_ops,
  697. .parent_names = std_clk_io_parents,
  698. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  699. };
  700. static struct clk_std clk_spi1 = {
  701. .enable_bit = 44,
  702. .hw = {
  703. .init = &clk_spi1_init,
  704. },
  705. };
  706. static struct clk_init_data clk_tsc_init = {
  707. .name = "tsc",
  708. .ops = &ios_ops,
  709. .parent_names = std_clk_io_parents,
  710. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  711. };
  712. static struct clk_std clk_tsc = {
  713. .enable_bit = 45,
  714. .hw = {
  715. .init = &clk_tsc_init,
  716. },
  717. };
  718. static struct clk_init_data clk_i2c0_init = {
  719. .name = "i2c0",
  720. .ops = &ios_ops,
  721. .parent_names = std_clk_io_parents,
  722. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  723. };
  724. static struct clk_std clk_i2c0 = {
  725. .enable_bit = 46,
  726. .hw = {
  727. .init = &clk_i2c0_init,
  728. },
  729. };
  730. static struct clk_init_data clk_i2c1_init = {
  731. .name = "i2c1",
  732. .ops = &ios_ops,
  733. .parent_names = std_clk_io_parents,
  734. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  735. };
  736. static struct clk_std clk_i2c1 = {
  737. .enable_bit = 47,
  738. .hw = {
  739. .init = &clk_i2c1_init,
  740. },
  741. };
  742. static struct clk_init_data clk_pwmc_init = {
  743. .name = "pwmc",
  744. .ops = &ios_ops,
  745. .parent_names = std_clk_io_parents,
  746. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  747. };
  748. static struct clk_std clk_pwmc = {
  749. .enable_bit = 48,
  750. .hw = {
  751. .init = &clk_pwmc_init,
  752. },
  753. };
  754. static struct clk_init_data clk_efuse_init = {
  755. .name = "efuse",
  756. .ops = &ios_ops,
  757. .parent_names = std_clk_io_parents,
  758. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  759. };
  760. static struct clk_std clk_efuse = {
  761. .enable_bit = 49,
  762. .hw = {
  763. .init = &clk_efuse_init,
  764. },
  765. };
  766. static struct clk_init_data clk_pulse_init = {
  767. .name = "pulse",
  768. .ops = &ios_ops,
  769. .parent_names = std_clk_io_parents,
  770. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  771. };
  772. static struct clk_std clk_pulse = {
  773. .enable_bit = 50,
  774. .hw = {
  775. .init = &clk_pulse_init,
  776. },
  777. };
  778. static const char *std_clk_dsp_parents[] = {
  779. "dsp",
  780. };
  781. static struct clk_init_data clk_gps_init = {
  782. .name = "gps",
  783. .ops = &ios_ops,
  784. .parent_names = std_clk_dsp_parents,
  785. .num_parents = ARRAY_SIZE(std_clk_dsp_parents),
  786. };
  787. static struct clk_std clk_gps = {
  788. .enable_bit = 1,
  789. .hw = {
  790. .init = &clk_gps_init,
  791. },
  792. };
  793. static struct clk_init_data clk_mf_init = {
  794. .name = "mf",
  795. .ops = &ios_ops,
  796. .parent_names = std_clk_io_parents,
  797. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  798. };
  799. static struct clk_std clk_mf = {
  800. .enable_bit = 2,
  801. .hw = {
  802. .init = &clk_mf_init,
  803. },
  804. };
  805. static const char *std_clk_sys_parents[] = {
  806. "sys",
  807. };
  808. static struct clk_init_data clk_security_init = {
  809. .name = "mf",
  810. .ops = &ios_ops,
  811. .parent_names = std_clk_sys_parents,
  812. .num_parents = ARRAY_SIZE(std_clk_sys_parents),
  813. };
  814. static struct clk_std clk_security = {
  815. .enable_bit = 19,
  816. .hw = {
  817. .init = &clk_security_init,
  818. },
  819. };
  820. static const char *std_clk_usb_parents[] = {
  821. "usb_pll",
  822. };
  823. static struct clk_init_data clk_usb0_init = {
  824. .name = "usb0",
  825. .ops = &ios_ops,
  826. .parent_names = std_clk_usb_parents,
  827. .num_parents = ARRAY_SIZE(std_clk_usb_parents),
  828. };
  829. static struct clk_std clk_usb0 = {
  830. .enable_bit = 16,
  831. .hw = {
  832. .init = &clk_usb0_init,
  833. },
  834. };
  835. static struct clk_init_data clk_usb1_init = {
  836. .name = "usb1",
  837. .ops = &ios_ops,
  838. .parent_names = std_clk_usb_parents,
  839. .num_parents = ARRAY_SIZE(std_clk_usb_parents),
  840. };
  841. static struct clk_std clk_usb1 = {
  842. .enable_bit = 17,
  843. .hw = {
  844. .init = &clk_usb1_init,
  845. },
  846. };
  847. enum prima2_clk_index {
  848. /* 0 1 2 3 4 5 6 7 8 9 */
  849. rtc, osc, pll1, pll2, pll3, mem, sys, security, dsp, gps,
  850. mf, io, cpu, uart0, uart1, uart2, tsc, i2c0, i2c1, spi0,
  851. spi1, pwmc, efuse, pulse, dmac0, dmac1, nand, audio, usp0, usp1,
  852. usp2, vip, gfx, mm, lcd, vpp, mmc01, mmc23, mmc45, usbpll,
  853. usb0, usb1, maxclk,
  854. };
  855. static struct clk_hw *prima2_clk_hw_array[maxclk] __initdata = {
  856. NULL, /* dummy */
  857. NULL,
  858. &clk_pll1.hw,
  859. &clk_pll2.hw,
  860. &clk_pll3.hw,
  861. &clk_mem.hw,
  862. &clk_sys.hw,
  863. &clk_security.hw,
  864. &clk_dsp.hw,
  865. &clk_gps.hw,
  866. &clk_mf.hw,
  867. &clk_io.hw,
  868. &clk_cpu.hw,
  869. &clk_uart0.hw,
  870. &clk_uart1.hw,
  871. &clk_uart2.hw,
  872. &clk_tsc.hw,
  873. &clk_i2c0.hw,
  874. &clk_i2c1.hw,
  875. &clk_spi0.hw,
  876. &clk_spi1.hw,
  877. &clk_pwmc.hw,
  878. &clk_efuse.hw,
  879. &clk_pulse.hw,
  880. &clk_dmac0.hw,
  881. &clk_dmac1.hw,
  882. &clk_nand.hw,
  883. &clk_audio.hw,
  884. &clk_usp0.hw,
  885. &clk_usp1.hw,
  886. &clk_usp2.hw,
  887. &clk_vip.hw,
  888. &clk_gfx.hw,
  889. &clk_mm.hw,
  890. &clk_lcd.hw,
  891. &clk_vpp.hw,
  892. &clk_mmc01.hw,
  893. &clk_mmc23.hw,
  894. &clk_mmc45.hw,
  895. &usb_pll_clk_hw,
  896. &clk_usb0.hw,
  897. &clk_usb1.hw,
  898. };
  899. static struct clk *prima2_clks[maxclk];
  900. static struct clk_onecell_data clk_data;
  901. static void __init sirfsoc_clk_init(struct device_node *np)
  902. {
  903. struct device_node *rscnp;
  904. int i;
  905. rscnp = of_find_compatible_node(NULL, NULL, "sirf,prima2-rsc");
  906. sirfsoc_rsc_vbase = of_iomap(rscnp, 0);
  907. if (!sirfsoc_rsc_vbase)
  908. panic("unable to map rsc registers\n");
  909. of_node_put(rscnp);
  910. sirfsoc_clk_vbase = of_iomap(np, 0);
  911. if (!sirfsoc_clk_vbase)
  912. panic("unable to map clkc registers\n");
  913. /* These are always available (RTC and 26MHz OSC)*/
  914. prima2_clks[rtc] = clk_register_fixed_rate(NULL, "rtc", NULL,
  915. CLK_IS_ROOT, 32768);
  916. prima2_clks[osc]= clk_register_fixed_rate(NULL, "osc", NULL,
  917. CLK_IS_ROOT, 26000000);
  918. for (i = pll1; i < maxclk; i++) {
  919. prima2_clks[i] = clk_register(NULL, prima2_clk_hw_array[i]);
  920. BUG_ON(IS_ERR(prima2_clks[i]));
  921. }
  922. clk_register_clkdev(prima2_clks[cpu], NULL, "cpu");
  923. clk_register_clkdev(prima2_clks[io], NULL, "io");
  924. clk_register_clkdev(prima2_clks[mem], NULL, "mem");
  925. clk_data.clks = prima2_clks;
  926. clk_data.clk_num = maxclk;
  927. of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
  928. }
  929. CLK_OF_DECLARE(sirfsoc_clk, "sirf,prima2-clkc", sirfsoc_clk_init);