clock.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. /*
  2. * Copyright (C) 2009 ST-Ericsson
  3. * Copyright (C) 2009 STMicroelectronics
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/list.h>
  12. #include <linux/errno.h>
  13. #include <linux/err.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/clkdev.h>
  17. #include <plat/mtu.h>
  18. #include <mach/hardware.h>
  19. #include "clock.h"
  20. #ifdef CONFIG_DEBUG_FS
  21. #include <linux/debugfs.h>
  22. #include <linux/uaccess.h> /* for copy_from_user */
  23. static LIST_HEAD(clk_list);
  24. #endif
  25. #define PRCC_PCKEN 0x00
  26. #define PRCC_PCKDIS 0x04
  27. #define PRCC_KCKEN 0x08
  28. #define PRCC_KCKDIS 0x0C
  29. #define PRCM_YYCLKEN0_MGT_SET 0x510
  30. #define PRCM_YYCLKEN1_MGT_SET 0x514
  31. #define PRCM_YYCLKEN0_MGT_CLR 0x518
  32. #define PRCM_YYCLKEN1_MGT_CLR 0x51C
  33. #define PRCM_YYCLKEN0_MGT_VAL 0x520
  34. #define PRCM_YYCLKEN1_MGT_VAL 0x524
  35. #define PRCM_SVAMMDSPCLK_MGT 0x008
  36. #define PRCM_SIAMMDSPCLK_MGT 0x00C
  37. #define PRCM_SGACLK_MGT 0x014
  38. #define PRCM_UARTCLK_MGT 0x018
  39. #define PRCM_MSP02CLK_MGT 0x01C
  40. #define PRCM_MSP1CLK_MGT 0x288
  41. #define PRCM_I2CCLK_MGT 0x020
  42. #define PRCM_SDMMCCLK_MGT 0x024
  43. #define PRCM_SLIMCLK_MGT 0x028
  44. #define PRCM_PER1CLK_MGT 0x02C
  45. #define PRCM_PER2CLK_MGT 0x030
  46. #define PRCM_PER3CLK_MGT 0x034
  47. #define PRCM_PER5CLK_MGT 0x038
  48. #define PRCM_PER6CLK_MGT 0x03C
  49. #define PRCM_PER7CLK_MGT 0x040
  50. #define PRCM_LCDCLK_MGT 0x044
  51. #define PRCM_BMLCLK_MGT 0x04C
  52. #define PRCM_HSITXCLK_MGT 0x050
  53. #define PRCM_HSIRXCLK_MGT 0x054
  54. #define PRCM_HDMICLK_MGT 0x058
  55. #define PRCM_APEATCLK_MGT 0x05C
  56. #define PRCM_APETRACECLK_MGT 0x060
  57. #define PRCM_MCDECLK_MGT 0x064
  58. #define PRCM_IPI2CCLK_MGT 0x068
  59. #define PRCM_DSIALTCLK_MGT 0x06C
  60. #define PRCM_DMACLK_MGT 0x074
  61. #define PRCM_B2R2CLK_MGT 0x078
  62. #define PRCM_TVCLK_MGT 0x07C
  63. #define PRCM_TCR 0x1C8
  64. #define PRCM_TCR_STOPPED (1 << 16)
  65. #define PRCM_TCR_DOZE_MODE (1 << 17)
  66. #define PRCM_UNIPROCLK_MGT 0x278
  67. #define PRCM_SSPCLK_MGT 0x280
  68. #define PRCM_RNGCLK_MGT 0x284
  69. #define PRCM_UICCCLK_MGT 0x27C
  70. #define PRCM_MGT_ENABLE (1 << 8)
  71. static DEFINE_SPINLOCK(clocks_lock);
  72. static void __clk_enable(struct clk *clk)
  73. {
  74. if (clk->enabled++ == 0) {
  75. if (clk->parent_cluster)
  76. __clk_enable(clk->parent_cluster);
  77. if (clk->parent_periph)
  78. __clk_enable(clk->parent_periph);
  79. if (clk->ops && clk->ops->enable)
  80. clk->ops->enable(clk);
  81. }
  82. }
  83. int clk_enable(struct clk *clk)
  84. {
  85. unsigned long flags;
  86. spin_lock_irqsave(&clocks_lock, flags);
  87. __clk_enable(clk);
  88. spin_unlock_irqrestore(&clocks_lock, flags);
  89. return 0;
  90. }
  91. EXPORT_SYMBOL(clk_enable);
  92. static void __clk_disable(struct clk *clk)
  93. {
  94. if (--clk->enabled == 0) {
  95. if (clk->ops && clk->ops->disable)
  96. clk->ops->disable(clk);
  97. if (clk->parent_periph)
  98. __clk_disable(clk->parent_periph);
  99. if (clk->parent_cluster)
  100. __clk_disable(clk->parent_cluster);
  101. }
  102. }
  103. void clk_disable(struct clk *clk)
  104. {
  105. unsigned long flags;
  106. WARN_ON(!clk->enabled);
  107. spin_lock_irqsave(&clocks_lock, flags);
  108. __clk_disable(clk);
  109. spin_unlock_irqrestore(&clocks_lock, flags);
  110. }
  111. EXPORT_SYMBOL(clk_disable);
  112. /*
  113. * The MTU has a separate, rather complex muxing setup
  114. * with alternative parents (peripheral cluster or
  115. * ULP or fixed 32768 Hz) depending on settings
  116. */
  117. static unsigned long clk_mtu_get_rate(struct clk *clk)
  118. {
  119. void __iomem *addr;
  120. u32 tcr;
  121. int mtu = (int) clk->data;
  122. /*
  123. * One of these is selected eventually
  124. * TODO: Replace the constant with a reference
  125. * to the ULP source once this is modeled.
  126. */
  127. unsigned long clk32k = 32768;
  128. unsigned long mturate;
  129. unsigned long retclk;
  130. if (cpu_is_u5500())
  131. addr = __io_address(U5500_PRCMU_BASE);
  132. else if (cpu_is_u8500())
  133. addr = __io_address(U8500_PRCMU_BASE);
  134. else
  135. ux500_unknown_soc();
  136. /*
  137. * On a startup, always conifgure the TCR to the doze mode;
  138. * bootloaders do it for us. Do this in the kernel too.
  139. */
  140. writel(PRCM_TCR_DOZE_MODE, addr + PRCM_TCR);
  141. tcr = readl(addr + PRCM_TCR);
  142. /* Get the rate from the parent as a default */
  143. if (clk->parent_periph)
  144. mturate = clk_get_rate(clk->parent_periph);
  145. else if (clk->parent_cluster)
  146. mturate = clk_get_rate(clk->parent_cluster);
  147. else
  148. /* We need to be connected SOMEWHERE */
  149. BUG();
  150. /* Return the clock selected for this MTU */
  151. if (tcr & (1 << mtu))
  152. retclk = clk32k;
  153. else
  154. retclk = mturate;
  155. pr_info("MTU%d clock rate: %lu Hz\n", mtu, retclk);
  156. return retclk;
  157. }
  158. unsigned long clk_get_rate(struct clk *clk)
  159. {
  160. unsigned long rate;
  161. /*
  162. * If there is a custom getrate callback for this clock,
  163. * it will take precedence.
  164. */
  165. if (clk->get_rate)
  166. return clk->get_rate(clk);
  167. if (clk->ops && clk->ops->get_rate)
  168. return clk->ops->get_rate(clk);
  169. rate = clk->rate;
  170. if (!rate) {
  171. if (clk->parent_periph)
  172. rate = clk_get_rate(clk->parent_periph);
  173. else if (clk->parent_cluster)
  174. rate = clk_get_rate(clk->parent_cluster);
  175. }
  176. return rate;
  177. }
  178. EXPORT_SYMBOL(clk_get_rate);
  179. long clk_round_rate(struct clk *clk, unsigned long rate)
  180. {
  181. /*TODO*/
  182. return rate;
  183. }
  184. EXPORT_SYMBOL(clk_round_rate);
  185. int clk_set_rate(struct clk *clk, unsigned long rate)
  186. {
  187. clk->rate = rate;
  188. return 0;
  189. }
  190. EXPORT_SYMBOL(clk_set_rate);
  191. static void clk_prcmu_enable(struct clk *clk)
  192. {
  193. void __iomem *cg_set_reg = __io_address(U8500_PRCMU_BASE)
  194. + PRCM_YYCLKEN0_MGT_SET + clk->prcmu_cg_off;
  195. writel(1 << clk->prcmu_cg_bit, cg_set_reg);
  196. }
  197. static void clk_prcmu_disable(struct clk *clk)
  198. {
  199. void __iomem *cg_clr_reg = __io_address(U8500_PRCMU_BASE)
  200. + PRCM_YYCLKEN0_MGT_CLR + clk->prcmu_cg_off;
  201. writel(1 << clk->prcmu_cg_bit, cg_clr_reg);
  202. }
  203. /* ED doesn't have the combined set/clr registers */
  204. static void clk_prcmu_ed_enable(struct clk *clk)
  205. {
  206. void __iomem *addr = __io_address(U8500_PRCMU_BASE)
  207. + clk->prcmu_cg_mgt;
  208. writel(readl(addr) | PRCM_MGT_ENABLE, addr);
  209. }
  210. static void clk_prcmu_ed_disable(struct clk *clk)
  211. {
  212. void __iomem *addr = __io_address(U8500_PRCMU_BASE)
  213. + clk->prcmu_cg_mgt;
  214. writel(readl(addr) & ~PRCM_MGT_ENABLE, addr);
  215. }
  216. static struct clkops clk_prcmu_ops = {
  217. .enable = clk_prcmu_enable,
  218. .disable = clk_prcmu_disable,
  219. };
  220. static unsigned int clkrst_base[] = {
  221. [1] = U8500_CLKRST1_BASE,
  222. [2] = U8500_CLKRST2_BASE,
  223. [3] = U8500_CLKRST3_BASE,
  224. [5] = U8500_CLKRST5_BASE,
  225. [6] = U8500_CLKRST6_BASE,
  226. [7] = U8500_CLKRST7_BASE_ED,
  227. };
  228. static void clk_prcc_enable(struct clk *clk)
  229. {
  230. void __iomem *addr = __io_address(clkrst_base[clk->cluster]);
  231. if (clk->prcc_kernel != -1)
  232. writel(1 << clk->prcc_kernel, addr + PRCC_KCKEN);
  233. if (clk->prcc_bus != -1)
  234. writel(1 << clk->prcc_bus, addr + PRCC_PCKEN);
  235. }
  236. static void clk_prcc_disable(struct clk *clk)
  237. {
  238. void __iomem *addr = __io_address(clkrst_base[clk->cluster]);
  239. if (clk->prcc_bus != -1)
  240. writel(1 << clk->prcc_bus, addr + PRCC_PCKDIS);
  241. if (clk->prcc_kernel != -1)
  242. writel(1 << clk->prcc_kernel, addr + PRCC_KCKDIS);
  243. }
  244. static struct clkops clk_prcc_ops = {
  245. .enable = clk_prcc_enable,
  246. .disable = clk_prcc_disable,
  247. };
  248. static struct clk clk_32khz = {
  249. .name = "clk_32khz",
  250. .rate = 32000,
  251. };
  252. /*
  253. * PRCMU level clock gating
  254. */
  255. /* Bank 0 */
  256. static DEFINE_PRCMU_CLK(svaclk, 0x0, 2, SVAMMDSPCLK);
  257. static DEFINE_PRCMU_CLK(siaclk, 0x0, 3, SIAMMDSPCLK);
  258. static DEFINE_PRCMU_CLK(sgaclk, 0x0, 4, SGACLK);
  259. static DEFINE_PRCMU_CLK_RATE(uartclk, 0x0, 5, UARTCLK, 38400000);
  260. static DEFINE_PRCMU_CLK(msp02clk, 0x0, 6, MSP02CLK);
  261. static DEFINE_PRCMU_CLK(msp1clk, 0x0, 7, MSP1CLK); /* v1 */
  262. static DEFINE_PRCMU_CLK_RATE(i2cclk, 0x0, 8, I2CCLK, 48000000);
  263. static DEFINE_PRCMU_CLK_RATE(sdmmcclk, 0x0, 9, SDMMCCLK, 100000000);
  264. static DEFINE_PRCMU_CLK(slimclk, 0x0, 10, SLIMCLK);
  265. static DEFINE_PRCMU_CLK(per1clk, 0x0, 11, PER1CLK);
  266. static DEFINE_PRCMU_CLK(per2clk, 0x0, 12, PER2CLK);
  267. static DEFINE_PRCMU_CLK(per3clk, 0x0, 13, PER3CLK);
  268. static DEFINE_PRCMU_CLK(per5clk, 0x0, 14, PER5CLK);
  269. static DEFINE_PRCMU_CLK_RATE(per6clk, 0x0, 15, PER6CLK, 133330000);
  270. static DEFINE_PRCMU_CLK_RATE(per7clk, 0x0, 16, PER7CLK, 100000000);
  271. static DEFINE_PRCMU_CLK(lcdclk, 0x0, 17, LCDCLK);
  272. static DEFINE_PRCMU_CLK(bmlclk, 0x0, 18, BMLCLK);
  273. static DEFINE_PRCMU_CLK(hsitxclk, 0x0, 19, HSITXCLK);
  274. static DEFINE_PRCMU_CLK(hsirxclk, 0x0, 20, HSIRXCLK);
  275. static DEFINE_PRCMU_CLK(hdmiclk, 0x0, 21, HDMICLK);
  276. static DEFINE_PRCMU_CLK(apeatclk, 0x0, 22, APEATCLK);
  277. static DEFINE_PRCMU_CLK(apetraceclk, 0x0, 23, APETRACECLK);
  278. static DEFINE_PRCMU_CLK(mcdeclk, 0x0, 24, MCDECLK);
  279. static DEFINE_PRCMU_CLK(ipi2clk, 0x0, 25, IPI2CCLK);
  280. static DEFINE_PRCMU_CLK(dsialtclk, 0x0, 26, DSIALTCLK); /* v1 */
  281. static DEFINE_PRCMU_CLK(dmaclk, 0x0, 27, DMACLK);
  282. static DEFINE_PRCMU_CLK(b2r2clk, 0x0, 28, B2R2CLK);
  283. static DEFINE_PRCMU_CLK(tvclk, 0x0, 29, TVCLK);
  284. static DEFINE_PRCMU_CLK(uniproclk, 0x0, 30, UNIPROCLK); /* v1 */
  285. static DEFINE_PRCMU_CLK_RATE(sspclk, 0x0, 31, SSPCLK, 48000000); /* v1 */
  286. /* Bank 1 */
  287. static DEFINE_PRCMU_CLK(rngclk, 0x4, 0, RNGCLK); /* v1 */
  288. static DEFINE_PRCMU_CLK(uiccclk, 0x4, 1, UICCCLK); /* v1 */
  289. /*
  290. * PRCC level clock gating
  291. * Format: per#, clk, PCKEN bit, KCKEN bit, parent
  292. */
  293. /* Peripheral Cluster #1 */
  294. static DEFINE_PRCC_CLK(1, i2c4, 10, 9, &clk_i2cclk);
  295. static DEFINE_PRCC_CLK(1, gpio0, 9, -1, NULL);
  296. static DEFINE_PRCC_CLK(1, slimbus0, 8, 8, &clk_slimclk);
  297. static DEFINE_PRCC_CLK(1, spi3_ed, 7, 7, NULL);
  298. static DEFINE_PRCC_CLK(1, spi3_v1, 7, -1, NULL);
  299. static DEFINE_PRCC_CLK(1, i2c2, 6, 6, &clk_i2cclk);
  300. static DEFINE_PRCC_CLK(1, sdi0, 5, 5, &clk_sdmmcclk);
  301. static DEFINE_PRCC_CLK(1, msp1_ed, 4, 4, &clk_msp02clk);
  302. static DEFINE_PRCC_CLK(1, msp1_v1, 4, 4, &clk_msp1clk);
  303. static DEFINE_PRCC_CLK(1, msp0, 3, 3, &clk_msp02clk);
  304. static DEFINE_PRCC_CLK(1, i2c1, 2, 2, &clk_i2cclk);
  305. static DEFINE_PRCC_CLK(1, uart1, 1, 1, &clk_uartclk);
  306. static DEFINE_PRCC_CLK(1, uart0, 0, 0, &clk_uartclk);
  307. /* Peripheral Cluster #2 */
  308. static DEFINE_PRCC_CLK(2, gpio1_ed, 12, -1, NULL);
  309. static DEFINE_PRCC_CLK(2, ssitx_ed, 11, -1, NULL);
  310. static DEFINE_PRCC_CLK(2, ssirx_ed, 10, -1, NULL);
  311. static DEFINE_PRCC_CLK(2, spi0_ed, 9, -1, NULL);
  312. static DEFINE_PRCC_CLK(2, sdi3_ed, 8, 6, &clk_sdmmcclk);
  313. static DEFINE_PRCC_CLK(2, sdi1_ed, 7, 5, &clk_sdmmcclk);
  314. static DEFINE_PRCC_CLK(2, msp2_ed, 6, 4, &clk_msp02clk);
  315. static DEFINE_PRCC_CLK(2, sdi4_ed, 4, 2, &clk_sdmmcclk);
  316. static DEFINE_PRCC_CLK(2, pwl_ed, 3, 1, NULL);
  317. static DEFINE_PRCC_CLK(2, spi1_ed, 2, -1, NULL);
  318. static DEFINE_PRCC_CLK(2, spi2_ed, 1, -1, NULL);
  319. static DEFINE_PRCC_CLK(2, i2c3_ed, 0, 0, &clk_i2cclk);
  320. static DEFINE_PRCC_CLK(2, gpio1_v1, 11, -1, NULL);
  321. static DEFINE_PRCC_CLK(2, ssitx_v1, 10, 7, NULL);
  322. static DEFINE_PRCC_CLK(2, ssirx_v1, 9, 6, NULL);
  323. static DEFINE_PRCC_CLK(2, spi0_v1, 8, -1, NULL);
  324. static DEFINE_PRCC_CLK(2, sdi3_v1, 7, 5, &clk_sdmmcclk);
  325. static DEFINE_PRCC_CLK(2, sdi1_v1, 6, 4, &clk_sdmmcclk);
  326. static DEFINE_PRCC_CLK(2, msp2_v1, 5, 3, &clk_msp02clk);
  327. static DEFINE_PRCC_CLK(2, sdi4_v1, 4, 2, &clk_sdmmcclk);
  328. static DEFINE_PRCC_CLK(2, pwl_v1, 3, 1, NULL);
  329. static DEFINE_PRCC_CLK(2, spi1_v1, 2, -1, NULL);
  330. static DEFINE_PRCC_CLK(2, spi2_v1, 1, -1, NULL);
  331. static DEFINE_PRCC_CLK(2, i2c3_v1, 0, 0, &clk_i2cclk);
  332. /* Peripheral Cluster #3 */
  333. static DEFINE_PRCC_CLK(3, gpio2, 8, -1, NULL);
  334. static DEFINE_PRCC_CLK(3, sdi5, 7, 7, &clk_sdmmcclk);
  335. static DEFINE_PRCC_CLK(3, uart2, 6, 6, &clk_uartclk);
  336. static DEFINE_PRCC_CLK(3, ske, 5, 5, &clk_32khz);
  337. static DEFINE_PRCC_CLK(3, sdi2, 4, 4, &clk_sdmmcclk);
  338. static DEFINE_PRCC_CLK(3, i2c0, 3, 3, &clk_i2cclk);
  339. static DEFINE_PRCC_CLK(3, ssp1_ed, 2, 2, &clk_i2cclk);
  340. static DEFINE_PRCC_CLK(3, ssp0_ed, 1, 1, &clk_i2cclk);
  341. static DEFINE_PRCC_CLK(3, ssp1_v1, 2, 2, &clk_sspclk);
  342. static DEFINE_PRCC_CLK(3, ssp0_v1, 1, 1, &clk_sspclk);
  343. static DEFINE_PRCC_CLK(3, fsmc, 0, -1, NULL);
  344. /* Peripheral Cluster #4 is in the always on domain */
  345. /* Peripheral Cluster #5 */
  346. static DEFINE_PRCC_CLK(5, gpio3, 1, -1, NULL);
  347. static DEFINE_PRCC_CLK(5, usb_ed, 0, 0, &clk_i2cclk);
  348. static DEFINE_PRCC_CLK(5, usb_v1, 0, 0, NULL);
  349. /* Peripheral Cluster #6 */
  350. /* MTU ID in data */
  351. static DEFINE_PRCC_CLK_CUSTOM(6, mtu1_v1, 8, -1, NULL, clk_mtu_get_rate, 1);
  352. static DEFINE_PRCC_CLK_CUSTOM(6, mtu0_v1, 7, -1, NULL, clk_mtu_get_rate, 0);
  353. static DEFINE_PRCC_CLK(6, cfgreg_v1, 6, 6, NULL);
  354. static DEFINE_PRCC_CLK(6, dmc_ed, 6, 6, NULL);
  355. static DEFINE_PRCC_CLK(6, hash1, 5, -1, NULL);
  356. static DEFINE_PRCC_CLK(6, unipro_v1, 4, 1, &clk_uniproclk);
  357. static DEFINE_PRCC_CLK(6, cryp1_ed, 4, -1, NULL);
  358. static DEFINE_PRCC_CLK(6, pka, 3, -1, NULL);
  359. static DEFINE_PRCC_CLK(6, hash0, 2, -1, NULL);
  360. static DEFINE_PRCC_CLK(6, cryp0, 1, -1, NULL);
  361. static DEFINE_PRCC_CLK(6, rng_ed, 0, 0, &clk_i2cclk);
  362. static DEFINE_PRCC_CLK(6, rng_v1, 0, 0, &clk_rngclk);
  363. /* Peripheral Cluster #7 */
  364. static DEFINE_PRCC_CLK(7, tzpc0_ed, 4, -1, NULL);
  365. /* MTU ID in data */
  366. static DEFINE_PRCC_CLK_CUSTOM(7, mtu1_ed, 3, -1, NULL, clk_mtu_get_rate, 1);
  367. static DEFINE_PRCC_CLK_CUSTOM(7, mtu0_ed, 2, -1, NULL, clk_mtu_get_rate, 0);
  368. static DEFINE_PRCC_CLK(7, wdg_ed, 1, -1, NULL);
  369. static DEFINE_PRCC_CLK(7, cfgreg_ed, 0, -1, NULL);
  370. static struct clk clk_dummy_apb_pclk = {
  371. .name = "apb_pclk",
  372. };
  373. static struct clk_lookup u8500_common_clks[] = {
  374. CLK(dummy_apb_pclk, NULL, "apb_pclk"),
  375. /* Peripheral Cluster #1 */
  376. CLK(gpio0, "gpio.0", NULL),
  377. CLK(gpio0, "gpio.1", NULL),
  378. CLK(slimbus0, "slimbus0", NULL),
  379. CLK(i2c2, "nmk-i2c.2", NULL),
  380. CLK(sdi0, "sdi0", NULL),
  381. CLK(msp0, "msp0", NULL),
  382. CLK(i2c1, "nmk-i2c.1", NULL),
  383. CLK(uart1, "uart1", NULL),
  384. CLK(uart0, "uart0", NULL),
  385. /* Peripheral Cluster #3 */
  386. CLK(gpio2, "gpio.2", NULL),
  387. CLK(gpio2, "gpio.3", NULL),
  388. CLK(gpio2, "gpio.4", NULL),
  389. CLK(gpio2, "gpio.5", NULL),
  390. CLK(sdi5, "sdi5", NULL),
  391. CLK(uart2, "uart2", NULL),
  392. CLK(ske, "ske", NULL),
  393. CLK(ske, "nmk-ske-keypad", NULL),
  394. CLK(sdi2, "sdi2", NULL),
  395. CLK(i2c0, "nmk-i2c.0", NULL),
  396. CLK(fsmc, "fsmc", NULL),
  397. /* Peripheral Cluster #5 */
  398. CLK(gpio3, "gpio.8", NULL),
  399. /* Peripheral Cluster #6 */
  400. CLK(hash1, "hash1", NULL),
  401. CLK(pka, "pka", NULL),
  402. CLK(hash0, "hash0", NULL),
  403. CLK(cryp0, "cryp0", NULL),
  404. /* PRCMU level clock gating */
  405. /* Bank 0 */
  406. CLK(svaclk, "sva", NULL),
  407. CLK(siaclk, "sia", NULL),
  408. CLK(sgaclk, "sga", NULL),
  409. CLK(slimclk, "slim", NULL),
  410. CLK(lcdclk, "lcd", NULL),
  411. CLK(bmlclk, "bml", NULL),
  412. CLK(hsitxclk, "stm-hsi.0", NULL),
  413. CLK(hsirxclk, "stm-hsi.1", NULL),
  414. CLK(hdmiclk, "hdmi", NULL),
  415. CLK(apeatclk, "apeat", NULL),
  416. CLK(apetraceclk, "apetrace", NULL),
  417. CLK(mcdeclk, "mcde", NULL),
  418. CLK(ipi2clk, "ipi2", NULL),
  419. CLK(dmaclk, "dma40.0", NULL),
  420. CLK(b2r2clk, "b2r2", NULL),
  421. CLK(tvclk, "tv", NULL),
  422. };
  423. static struct clk_lookup u8500_ed_clks[] = {
  424. /* Peripheral Cluster #1 */
  425. CLK(spi3_ed, "spi3", NULL),
  426. CLK(msp1_ed, "msp1", NULL),
  427. /* Peripheral Cluster #2 */
  428. CLK(gpio1_ed, "gpio.6", NULL),
  429. CLK(gpio1_ed, "gpio.7", NULL),
  430. CLK(ssitx_ed, "ssitx", NULL),
  431. CLK(ssirx_ed, "ssirx", NULL),
  432. CLK(spi0_ed, "spi0", NULL),
  433. CLK(sdi3_ed, "sdi3", NULL),
  434. CLK(sdi1_ed, "sdi1", NULL),
  435. CLK(msp2_ed, "msp2", NULL),
  436. CLK(sdi4_ed, "sdi4", NULL),
  437. CLK(pwl_ed, "pwl", NULL),
  438. CLK(spi1_ed, "spi1", NULL),
  439. CLK(spi2_ed, "spi2", NULL),
  440. CLK(i2c3_ed, "nmk-i2c.3", NULL),
  441. /* Peripheral Cluster #3 */
  442. CLK(ssp1_ed, "ssp1", NULL),
  443. CLK(ssp0_ed, "ssp0", NULL),
  444. /* Peripheral Cluster #5 */
  445. CLK(usb_ed, "musb-ux500.0", "usb"),
  446. /* Peripheral Cluster #6 */
  447. CLK(dmc_ed, "dmc", NULL),
  448. CLK(cryp1_ed, "cryp1", NULL),
  449. CLK(rng_ed, "rng", NULL),
  450. /* Peripheral Cluster #7 */
  451. CLK(tzpc0_ed, "tzpc0", NULL),
  452. CLK(mtu1_ed, "mtu1", NULL),
  453. CLK(mtu0_ed, "mtu0", NULL),
  454. CLK(wdg_ed, "wdg", NULL),
  455. CLK(cfgreg_ed, "cfgreg", NULL),
  456. };
  457. static struct clk_lookup u8500_v1_clks[] = {
  458. /* Peripheral Cluster #1 */
  459. CLK(i2c4, "nmk-i2c.4", NULL),
  460. CLK(spi3_v1, "spi3", NULL),
  461. CLK(msp1_v1, "msp1", NULL),
  462. /* Peripheral Cluster #2 */
  463. CLK(gpio1_v1, "gpio.6", NULL),
  464. CLK(gpio1_v1, "gpio.7", NULL),
  465. CLK(ssitx_v1, "ssitx", NULL),
  466. CLK(ssirx_v1, "ssirx", NULL),
  467. CLK(spi0_v1, "spi0", NULL),
  468. CLK(sdi3_v1, "sdi3", NULL),
  469. CLK(sdi1_v1, "sdi1", NULL),
  470. CLK(msp2_v1, "msp2", NULL),
  471. CLK(sdi4_v1, "sdi4", NULL),
  472. CLK(pwl_v1, "pwl", NULL),
  473. CLK(spi1_v1, "spi1", NULL),
  474. CLK(spi2_v1, "spi2", NULL),
  475. CLK(i2c3_v1, "nmk-i2c.3", NULL),
  476. /* Peripheral Cluster #3 */
  477. CLK(ssp1_v1, "ssp1", NULL),
  478. CLK(ssp0_v1, "ssp0", NULL),
  479. /* Peripheral Cluster #5 */
  480. CLK(usb_v1, "musb-ux500.0", "usb"),
  481. /* Peripheral Cluster #6 */
  482. CLK(mtu1_v1, "mtu1", NULL),
  483. CLK(mtu0_v1, "mtu0", NULL),
  484. CLK(cfgreg_v1, "cfgreg", NULL),
  485. CLK(hash1, "hash1", NULL),
  486. CLK(unipro_v1, "unipro", NULL),
  487. CLK(rng_v1, "rng", NULL),
  488. /* PRCMU level clock gating */
  489. /* Bank 0 */
  490. CLK(uniproclk, "uniproclk", NULL),
  491. CLK(dsialtclk, "dsialt", NULL),
  492. /* Bank 1 */
  493. CLK(rngclk, "rng", NULL),
  494. CLK(uiccclk, "uicc", NULL),
  495. };
  496. #ifdef CONFIG_DEBUG_FS
  497. /*
  498. * debugfs support to trace clock tree hierarchy and attributes with
  499. * powerdebug
  500. */
  501. static struct dentry *clk_debugfs_root;
  502. void __init clk_debugfs_add_table(struct clk_lookup *cl, size_t num)
  503. {
  504. while (num--) {
  505. /* Check that the clock has not been already registered */
  506. if (!(cl->clk->list.prev != cl->clk->list.next))
  507. list_add_tail(&cl->clk->list, &clk_list);
  508. cl++;
  509. }
  510. }
  511. static ssize_t usecount_dbg_read(struct file *file, char __user *buf,
  512. size_t size, loff_t *off)
  513. {
  514. struct clk *clk = file->f_dentry->d_inode->i_private;
  515. char cusecount[128];
  516. unsigned int len;
  517. len = sprintf(cusecount, "%u\n", clk->enabled);
  518. return simple_read_from_buffer(buf, size, off, cusecount, len);
  519. }
  520. static ssize_t rate_dbg_read(struct file *file, char __user *buf,
  521. size_t size, loff_t *off)
  522. {
  523. struct clk *clk = file->f_dentry->d_inode->i_private;
  524. char crate[128];
  525. unsigned int rate;
  526. unsigned int len;
  527. rate = clk_get_rate(clk);
  528. len = sprintf(crate, "%u\n", rate);
  529. return simple_read_from_buffer(buf, size, off, crate, len);
  530. }
  531. static const struct file_operations usecount_fops = {
  532. .read = usecount_dbg_read,
  533. };
  534. static const struct file_operations set_rate_fops = {
  535. .read = rate_dbg_read,
  536. };
  537. static struct dentry *clk_debugfs_register_dir(struct clk *c,
  538. struct dentry *p_dentry)
  539. {
  540. struct dentry *d, *clk_d, *child, *child_tmp;
  541. char s[255];
  542. char *p = s;
  543. if (c->name == NULL)
  544. p += sprintf(p, "BUG");
  545. else
  546. p += sprintf(p, "%s", c->name);
  547. clk_d = debugfs_create_dir(s, p_dentry);
  548. if (!clk_d)
  549. return NULL;
  550. d = debugfs_create_file("usecount", S_IRUGO,
  551. clk_d, c, &usecount_fops);
  552. if (!d)
  553. goto err_out;
  554. d = debugfs_create_file("rate", S_IRUGO,
  555. clk_d, c, &set_rate_fops);
  556. if (!d)
  557. goto err_out;
  558. /*
  559. * TODO : not currently available in ux500
  560. * d = debugfs_create_x32("flags", S_IRUGO, clk_d, (u32 *)&c->flags);
  561. * if (!d)
  562. * goto err_out;
  563. */
  564. return clk_d;
  565. err_out:
  566. d = clk_d;
  567. list_for_each_entry_safe(child, child_tmp, &d->d_subdirs, d_u.d_child)
  568. debugfs_remove(child);
  569. debugfs_remove(clk_d);
  570. return NULL;
  571. }
  572. static void clk_debugfs_remove_dir(struct dentry *cdentry)
  573. {
  574. struct dentry *d, *child, *child_tmp;
  575. d = cdentry;
  576. list_for_each_entry_safe(child, child_tmp, &d->d_subdirs, d_u.d_child)
  577. debugfs_remove(child);
  578. debugfs_remove(cdentry);
  579. return ;
  580. }
  581. static int clk_debugfs_register_one(struct clk *c)
  582. {
  583. struct clk *pa = c->parent_periph;
  584. struct clk *bpa = c->parent_cluster;
  585. if (!(bpa && !pa)) {
  586. c->dent = clk_debugfs_register_dir(c,
  587. pa ? pa->dent : clk_debugfs_root);
  588. if (!c->dent)
  589. return -ENOMEM;
  590. }
  591. if (bpa) {
  592. c->dent_bus = clk_debugfs_register_dir(c,
  593. bpa->dent_bus ? bpa->dent_bus : bpa->dent);
  594. if ((!c->dent_bus) && (c->dent)) {
  595. clk_debugfs_remove_dir(c->dent);
  596. c->dent = NULL;
  597. return -ENOMEM;
  598. }
  599. }
  600. return 0;
  601. }
  602. static int clk_debugfs_register(struct clk *c)
  603. {
  604. int err;
  605. struct clk *pa = c->parent_periph;
  606. struct clk *bpa = c->parent_cluster;
  607. if (pa && (!pa->dent && !pa->dent_bus)) {
  608. err = clk_debugfs_register(pa);
  609. if (err)
  610. return err;
  611. }
  612. if (bpa && (!bpa->dent && !bpa->dent_bus)) {
  613. err = clk_debugfs_register(bpa);
  614. if (err)
  615. return err;
  616. }
  617. if ((!c->dent) && (!c->dent_bus)) {
  618. err = clk_debugfs_register_one(c);
  619. if (err)
  620. return err;
  621. }
  622. return 0;
  623. }
  624. static int __init clk_debugfs_init(void)
  625. {
  626. struct clk *c;
  627. struct dentry *d;
  628. int err;
  629. d = debugfs_create_dir("clock", NULL);
  630. if (!d)
  631. return -ENOMEM;
  632. clk_debugfs_root = d;
  633. list_for_each_entry(c, &clk_list, list) {
  634. err = clk_debugfs_register(c);
  635. if (err)
  636. goto err_out;
  637. }
  638. return 0;
  639. err_out:
  640. debugfs_remove_recursive(clk_debugfs_root);
  641. return err;
  642. }
  643. late_initcall(clk_debugfs_init);
  644. #endif /* defined(CONFIG_DEBUG_FS) */
  645. int __init clk_init(void)
  646. {
  647. if (cpu_is_u8500ed()) {
  648. clk_prcmu_ops.enable = clk_prcmu_ed_enable;
  649. clk_prcmu_ops.disable = clk_prcmu_ed_disable;
  650. clk_per6clk.rate = 100000000;
  651. } else if (cpu_is_u5500()) {
  652. /* Clock tree for U5500 not implemented yet */
  653. clk_prcc_ops.enable = clk_prcc_ops.disable = NULL;
  654. clk_prcmu_ops.enable = clk_prcmu_ops.disable = NULL;
  655. clk_uartclk.rate = 36360000;
  656. clk_sdmmcclk.rate = 99900000;
  657. }
  658. clkdev_add_table(u8500_common_clks, ARRAY_SIZE(u8500_common_clks));
  659. if (cpu_is_u8500ed())
  660. clkdev_add_table(u8500_ed_clks, ARRAY_SIZE(u8500_ed_clks));
  661. else
  662. clkdev_add_table(u8500_v1_clks, ARRAY_SIZE(u8500_v1_clks));
  663. #ifdef CONFIG_DEBUG_FS
  664. clk_debugfs_add_table(u8500_common_clks, ARRAY_SIZE(u8500_common_clks));
  665. if (cpu_is_u8500ed())
  666. clk_debugfs_add_table(u8500_ed_clks, ARRAY_SIZE(u8500_ed_clks));
  667. else
  668. clk_debugfs_add_table(u8500_v1_clks, ARRAY_SIZE(u8500_v1_clks));
  669. #endif
  670. return 0;
  671. }