clock.c 18 KB

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