clock.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. /*
  2. *
  3. * arch/arm/mach-u300/clock.c
  4. *
  5. *
  6. * Copyright (C) 2007-2009 ST-Ericsson AB
  7. * License terms: GNU General Public License (GPL) version 2
  8. * Define clocks in the app platform.
  9. * Author: Linus Walleij <linus.walleij@stericsson.com>
  10. * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/list.h>
  16. #include <linux/errno.h>
  17. #include <linux/err.h>
  18. #include <linux/string.h>
  19. #include <linux/clk.h>
  20. #include <linux/mutex.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/debugfs.h>
  23. #include <linux/device.h>
  24. #include <linux/init.h>
  25. #include <linux/timer.h>
  26. #include <linux/io.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/clkdev.h>
  29. #include <mach/hardware.h>
  30. #include <mach/syscon.h>
  31. #include "clock.h"
  32. /*
  33. * TODO:
  34. * - move all handling of the CCR register into this file and create
  35. * a spinlock for the CCR register
  36. * - switch to the clkdevice lookup mechanism that maps clocks to
  37. * device ID:s instead when it becomes available in kernel 2.6.29.
  38. * - implement rate get/set for all clocks that need it.
  39. */
  40. /*
  41. * Syscon clock I/O registers lock so clock requests don't collide
  42. * NOTE: this is a local lock only used to lock access to clock and
  43. * reset registers in syscon.
  44. */
  45. static DEFINE_SPINLOCK(syscon_clkreg_lock);
  46. static DEFINE_SPINLOCK(syscon_resetreg_lock);
  47. /*
  48. * The clocking hierarchy currently looks like this.
  49. * NOTE: the idea is NOT to show how the clocks are routed on the chip!
  50. * The ideas is to show dependencies, so a clock higher up in the
  51. * hierarchy has to be on in order for another clock to be on. Now,
  52. * both CPU and DMA can actually be on top of the hierarchy, and that
  53. * is not modeled currently. Instead we have the backbone AMBA bus on
  54. * top. This bus cannot be programmed in any way but conceptually it
  55. * needs to be active for the bridges and devices to transport data.
  56. *
  57. * Please be aware that a few clocks are hw controlled, which mean that
  58. * the hw itself can turn on/off or change the rate of the clock when
  59. * needed!
  60. *
  61. * AMBA bus
  62. * |
  63. * +- CPU
  64. * +- FSMC NANDIF NAND Flash interface
  65. * +- SEMI Shared Memory interface
  66. * +- ISP Image Signal Processor (U335 only)
  67. * +- CDS (U335 only)
  68. * +- DMA Direct Memory Access Controller
  69. * +- AAIF APP/ACC Inteface (Mobile Scalable Link, MSL)
  70. * +- APEX
  71. * +- VIDEO_ENC AVE2/3 Video Encoder
  72. * +- XGAM Graphics Accelerator Controller
  73. * +- AHB
  74. * |
  75. * +- ahb:0 AHB Bridge
  76. * | |
  77. * | +- ahb:1 INTCON Interrupt controller
  78. * | +- ahb:3 MSPRO Memory Stick Pro controller
  79. * | +- ahb:4 EMIF External Memory interface
  80. * |
  81. * +- fast:0 FAST bridge
  82. * | |
  83. * | +- fast:1 MMCSD MMC/SD card reader controller
  84. * | +- fast:2 I2S0 PCM I2S channel 0 controller
  85. * | +- fast:3 I2S1 PCM I2S channel 1 controller
  86. * | +- fast:4 I2C0 I2C channel 0 controller
  87. * | +- fast:5 I2C1 I2C channel 1 controller
  88. * | +- fast:6 SPI SPI controller
  89. * | +- fast:7 UART1 Secondary UART (U335 only)
  90. * |
  91. * +- slow:0 SLOW bridge
  92. * |
  93. * +- slow:1 SYSCON (not possible to control)
  94. * +- slow:2 WDOG Watchdog
  95. * +- slow:3 UART0 primary UART
  96. * +- slow:4 TIMER_APP Application timer - used in Linux
  97. * +- slow:5 KEYPAD controller
  98. * +- slow:6 GPIO controller
  99. * +- slow:7 RTC controller
  100. * +- slow:8 BT Bus Tracer (not used currently)
  101. * +- slow:9 EH Event Handler (not used currently)
  102. * +- slow:a TIMER_ACC Access style timer (not used currently)
  103. * +- slow:b PPM (U335 only, what is that?)
  104. */
  105. /*
  106. * Reset control functions. We remember if a block has been
  107. * taken out of reset and don't remove the reset assertion again
  108. * and vice versa. Currently we only remove resets so the
  109. * enablement function is defined out.
  110. */
  111. static void syscon_block_reset_enable(struct clk *clk)
  112. {
  113. u16 val;
  114. unsigned long iflags;
  115. /* Not all blocks support resetting */
  116. if (!clk->res_reg || !clk->res_mask)
  117. return;
  118. spin_lock_irqsave(&syscon_resetreg_lock, iflags);
  119. val = readw(clk->res_reg);
  120. val |= clk->res_mask;
  121. writew(val, clk->res_reg);
  122. spin_unlock_irqrestore(&syscon_resetreg_lock, iflags);
  123. clk->reset = true;
  124. }
  125. static void syscon_block_reset_disable(struct clk *clk)
  126. {
  127. u16 val;
  128. unsigned long iflags;
  129. /* Not all blocks support resetting */
  130. if (!clk->res_reg || !clk->res_mask)
  131. return;
  132. spin_lock_irqsave(&syscon_resetreg_lock, iflags);
  133. val = readw(clk->res_reg);
  134. val &= ~clk->res_mask;
  135. writew(val, clk->res_reg);
  136. spin_unlock_irqrestore(&syscon_resetreg_lock, iflags);
  137. clk->reset = false;
  138. }
  139. int __clk_get(struct clk *clk)
  140. {
  141. u16 val;
  142. /* The MMC and MSPRO clocks need some special set-up */
  143. if (!strcmp(clk->name, "MCLK")) {
  144. /* Set default MMC clock divisor to 18.9 MHz */
  145. writew(0x0054U, U300_SYSCON_VBASE + U300_SYSCON_MMF0R);
  146. val = readw(U300_SYSCON_VBASE + U300_SYSCON_MMCR);
  147. /* Disable the MMC feedback clock */
  148. val &= ~U300_SYSCON_MMCR_MMC_FB_CLK_SEL_ENABLE;
  149. /* Disable MSPRO frequency */
  150. val &= ~U300_SYSCON_MMCR_MSPRO_FREQSEL_ENABLE;
  151. writew(val, U300_SYSCON_VBASE + U300_SYSCON_MMCR);
  152. }
  153. if (!strcmp(clk->name, "MSPRO")) {
  154. val = readw(U300_SYSCON_VBASE + U300_SYSCON_MMCR);
  155. /* Disable the MMC feedback clock */
  156. val &= ~U300_SYSCON_MMCR_MMC_FB_CLK_SEL_ENABLE;
  157. /* Enable MSPRO frequency */
  158. val |= U300_SYSCON_MMCR_MSPRO_FREQSEL_ENABLE;
  159. writew(val, U300_SYSCON_VBASE + U300_SYSCON_MMCR);
  160. }
  161. return 1;
  162. }
  163. EXPORT_SYMBOL(__clk_get);
  164. void __clk_put(struct clk *clk)
  165. {
  166. }
  167. EXPORT_SYMBOL(__clk_put);
  168. static void syscon_clk_disable(struct clk *clk)
  169. {
  170. unsigned long iflags;
  171. /* Don't touch the hardware controlled clocks */
  172. if (clk->hw_ctrld)
  173. return;
  174. spin_lock_irqsave(&syscon_clkreg_lock, iflags);
  175. writew(clk->clk_val, U300_SYSCON_VBASE + U300_SYSCON_SBCDR);
  176. spin_unlock_irqrestore(&syscon_clkreg_lock, iflags);
  177. }
  178. static void syscon_clk_enable(struct clk *clk)
  179. {
  180. unsigned long iflags;
  181. /* Don't touch the hardware controlled clocks */
  182. if (clk->hw_ctrld)
  183. return;
  184. spin_lock_irqsave(&syscon_clkreg_lock, iflags);
  185. writew(clk->clk_val, U300_SYSCON_VBASE + U300_SYSCON_SBCER);
  186. spin_unlock_irqrestore(&syscon_clkreg_lock, iflags);
  187. }
  188. static u16 syscon_clk_get_rate(void)
  189. {
  190. u16 val;
  191. unsigned long iflags;
  192. spin_lock_irqsave(&syscon_clkreg_lock, iflags);
  193. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CCR);
  194. val &= U300_SYSCON_CCR_CLKING_PERFORMANCE_MASK;
  195. spin_unlock_irqrestore(&syscon_clkreg_lock, iflags);
  196. return val;
  197. }
  198. #ifdef CONFIG_MACH_U300_USE_I2S_AS_MASTER
  199. static void enable_i2s0_vcxo(void)
  200. {
  201. u16 val;
  202. unsigned long iflags;
  203. spin_lock_irqsave(&syscon_clkreg_lock, iflags);
  204. /* Set I2S0 to use the VCXO 26 MHz clock */
  205. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CCR);
  206. val |= U300_SYSCON_CCR_TURN_VCXO_ON;
  207. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  208. val |= U300_SYSCON_CCR_I2S0_USE_VCXO;
  209. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  210. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CEFR);
  211. val |= U300_SYSCON_CEFR_I2S0_CLK_EN;
  212. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CEFR);
  213. spin_unlock_irqrestore(&syscon_clkreg_lock, iflags);
  214. }
  215. static void enable_i2s1_vcxo(void)
  216. {
  217. u16 val;
  218. unsigned long iflags;
  219. spin_lock_irqsave(&syscon_clkreg_lock, iflags);
  220. /* Set I2S1 to use the VCXO 26 MHz clock */
  221. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CCR);
  222. val |= U300_SYSCON_CCR_TURN_VCXO_ON;
  223. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  224. val |= U300_SYSCON_CCR_I2S1_USE_VCXO;
  225. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  226. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CEFR);
  227. val |= U300_SYSCON_CEFR_I2S1_CLK_EN;
  228. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CEFR);
  229. spin_unlock_irqrestore(&syscon_clkreg_lock, iflags);
  230. }
  231. static void disable_i2s0_vcxo(void)
  232. {
  233. u16 val;
  234. unsigned long iflags;
  235. spin_lock_irqsave(&syscon_clkreg_lock, iflags);
  236. /* Disable I2S0 use of the VCXO 26 MHz clock */
  237. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CCR);
  238. val &= ~U300_SYSCON_CCR_I2S0_USE_VCXO;
  239. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  240. /* Deactivate VCXO if no one else is using VCXO */
  241. if (!(val & U300_SYSCON_CCR_I2S1_USE_VCXO))
  242. val &= ~U300_SYSCON_CCR_TURN_VCXO_ON;
  243. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  244. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CEFR);
  245. val &= ~U300_SYSCON_CEFR_I2S0_CLK_EN;
  246. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CEFR);
  247. spin_unlock_irqrestore(&syscon_clkreg_lock, iflags);
  248. }
  249. static void disable_i2s1_vcxo(void)
  250. {
  251. u16 val;
  252. unsigned long iflags;
  253. spin_lock_irqsave(&syscon_clkreg_lock, iflags);
  254. /* Disable I2S1 use of the VCXO 26 MHz clock */
  255. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CCR);
  256. val &= ~U300_SYSCON_CCR_I2S1_USE_VCXO;
  257. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  258. /* Deactivate VCXO if no one else is using VCXO */
  259. if (!(val & U300_SYSCON_CCR_I2S0_USE_VCXO))
  260. val &= ~U300_SYSCON_CCR_TURN_VCXO_ON;
  261. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  262. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CEFR);
  263. val &= ~U300_SYSCON_CEFR_I2S0_CLK_EN;
  264. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CEFR);
  265. spin_unlock_irqrestore(&syscon_clkreg_lock, iflags);
  266. }
  267. #endif /* CONFIG_MACH_U300_USE_I2S_AS_MASTER */
  268. static void syscon_clk_rate_set_mclk(unsigned long rate)
  269. {
  270. u16 val;
  271. u32 reg;
  272. unsigned long iflags;
  273. switch (rate) {
  274. case 18900000:
  275. val = 0x0054;
  276. break;
  277. case 20800000:
  278. val = 0x0044;
  279. break;
  280. case 23100000:
  281. val = 0x0043;
  282. break;
  283. case 26000000:
  284. val = 0x0033;
  285. break;
  286. case 29700000:
  287. val = 0x0032;
  288. break;
  289. case 34700000:
  290. val = 0x0022;
  291. break;
  292. case 41600000:
  293. val = 0x0021;
  294. break;
  295. case 52000000:
  296. val = 0x0011;
  297. break;
  298. case 104000000:
  299. val = 0x0000;
  300. break;
  301. default:
  302. printk(KERN_ERR "Trying to set MCLK to unknown speed! %ld\n",
  303. rate);
  304. return;
  305. }
  306. spin_lock_irqsave(&syscon_clkreg_lock, iflags);
  307. reg = readw(U300_SYSCON_VBASE + U300_SYSCON_MMF0R) &
  308. ~U300_SYSCON_MMF0R_MASK;
  309. writew(reg | val, U300_SYSCON_VBASE + U300_SYSCON_MMF0R);
  310. spin_unlock_irqrestore(&syscon_clkreg_lock, iflags);
  311. }
  312. void syscon_clk_rate_set_cpuclk(unsigned long rate)
  313. {
  314. u16 val;
  315. unsigned long iflags;
  316. switch (rate) {
  317. case 13000000:
  318. val = U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW_POWER;
  319. break;
  320. case 52000000:
  321. val = U300_SYSCON_CCR_CLKING_PERFORMANCE_INTERMEDIATE;
  322. break;
  323. case 104000000:
  324. val = U300_SYSCON_CCR_CLKING_PERFORMANCE_HIGH;
  325. break;
  326. case 208000000:
  327. val = U300_SYSCON_CCR_CLKING_PERFORMANCE_BEST;
  328. break;
  329. default:
  330. return;
  331. }
  332. spin_lock_irqsave(&syscon_clkreg_lock, iflags);
  333. val |= readw(U300_SYSCON_VBASE + U300_SYSCON_CCR) &
  334. ~U300_SYSCON_CCR_CLKING_PERFORMANCE_MASK ;
  335. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  336. spin_unlock_irqrestore(&syscon_clkreg_lock, iflags);
  337. }
  338. EXPORT_SYMBOL(syscon_clk_rate_set_cpuclk);
  339. void clk_disable(struct clk *clk)
  340. {
  341. unsigned long iflags;
  342. spin_lock_irqsave(&clk->lock, iflags);
  343. if (clk->usecount > 0 && !(--clk->usecount)) {
  344. /* some blocks lack clocking registers and cannot be disabled */
  345. if (clk->disable)
  346. clk->disable(clk);
  347. if (likely((u32)clk->parent))
  348. clk_disable(clk->parent);
  349. }
  350. #ifdef CONFIG_MACH_U300_USE_I2S_AS_MASTER
  351. if (unlikely(!strcmp(clk->name, "I2S0")))
  352. disable_i2s0_vcxo();
  353. if (unlikely(!strcmp(clk->name, "I2S1")))
  354. disable_i2s1_vcxo();
  355. #endif
  356. spin_unlock_irqrestore(&clk->lock, iflags);
  357. }
  358. EXPORT_SYMBOL(clk_disable);
  359. int clk_enable(struct clk *clk)
  360. {
  361. int ret = 0;
  362. unsigned long iflags;
  363. spin_lock_irqsave(&clk->lock, iflags);
  364. if (clk->usecount++ == 0) {
  365. if (likely((u32)clk->parent))
  366. ret = clk_enable(clk->parent);
  367. if (unlikely(ret != 0))
  368. clk->usecount--;
  369. else {
  370. /* remove reset line (we never enable reset again) */
  371. syscon_block_reset_disable(clk);
  372. /* clocks without enable function are always on */
  373. if (clk->enable)
  374. clk->enable(clk);
  375. #ifdef CONFIG_MACH_U300_USE_I2S_AS_MASTER
  376. if (unlikely(!strcmp(clk->name, "I2S0")))
  377. enable_i2s0_vcxo();
  378. if (unlikely(!strcmp(clk->name, "I2S1")))
  379. enable_i2s1_vcxo();
  380. #endif
  381. }
  382. }
  383. spin_unlock_irqrestore(&clk->lock, iflags);
  384. return ret;
  385. }
  386. EXPORT_SYMBOL(clk_enable);
  387. /* Returns the clock rate in Hz */
  388. static unsigned long clk_get_rate_cpuclk(struct clk *clk)
  389. {
  390. u16 val;
  391. val = syscon_clk_get_rate();
  392. switch (val) {
  393. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW_POWER:
  394. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW:
  395. return 13000000;
  396. case U300_SYSCON_CCR_CLKING_PERFORMANCE_INTERMEDIATE:
  397. return 52000000;
  398. case U300_SYSCON_CCR_CLKING_PERFORMANCE_HIGH:
  399. return 104000000;
  400. case U300_SYSCON_CCR_CLKING_PERFORMANCE_BEST:
  401. return 208000000;
  402. default:
  403. break;
  404. }
  405. return clk->rate;
  406. }
  407. static unsigned long clk_get_rate_ahb_clk(struct clk *clk)
  408. {
  409. u16 val;
  410. val = syscon_clk_get_rate();
  411. switch (val) {
  412. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW_POWER:
  413. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW:
  414. return 6500000;
  415. case U300_SYSCON_CCR_CLKING_PERFORMANCE_INTERMEDIATE:
  416. return 26000000;
  417. case U300_SYSCON_CCR_CLKING_PERFORMANCE_HIGH:
  418. case U300_SYSCON_CCR_CLKING_PERFORMANCE_BEST:
  419. return 52000000;
  420. default:
  421. break;
  422. }
  423. return clk->rate;
  424. }
  425. static unsigned long clk_get_rate_emif_clk(struct clk *clk)
  426. {
  427. u16 val;
  428. val = syscon_clk_get_rate();
  429. switch (val) {
  430. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW_POWER:
  431. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW:
  432. return 13000000;
  433. case U300_SYSCON_CCR_CLKING_PERFORMANCE_INTERMEDIATE:
  434. return 52000000;
  435. case U300_SYSCON_CCR_CLKING_PERFORMANCE_HIGH:
  436. case U300_SYSCON_CCR_CLKING_PERFORMANCE_BEST:
  437. return 104000000;
  438. default:
  439. break;
  440. }
  441. return clk->rate;
  442. }
  443. static unsigned long clk_get_rate_xgamclk(struct clk *clk)
  444. {
  445. u16 val;
  446. val = syscon_clk_get_rate();
  447. switch (val) {
  448. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW_POWER:
  449. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW:
  450. return 6500000;
  451. case U300_SYSCON_CCR_CLKING_PERFORMANCE_INTERMEDIATE:
  452. return 26000000;
  453. case U300_SYSCON_CCR_CLKING_PERFORMANCE_HIGH:
  454. case U300_SYSCON_CCR_CLKING_PERFORMANCE_BEST:
  455. return 52000000;
  456. default:
  457. break;
  458. }
  459. return clk->rate;
  460. }
  461. static unsigned long clk_get_rate_mclk(struct clk *clk)
  462. {
  463. u16 val;
  464. val = syscon_clk_get_rate();
  465. switch (val) {
  466. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW_POWER:
  467. /*
  468. * Here, the 208 MHz PLL gets shut down and the always
  469. * on 13 MHz PLL used for RTC etc kicks into use
  470. * instead.
  471. */
  472. return 13000000;
  473. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW:
  474. case U300_SYSCON_CCR_CLKING_PERFORMANCE_INTERMEDIATE:
  475. case U300_SYSCON_CCR_CLKING_PERFORMANCE_HIGH:
  476. case U300_SYSCON_CCR_CLKING_PERFORMANCE_BEST:
  477. {
  478. /*
  479. * This clock is under program control. The register is
  480. * divided in two nybbles, bit 7-4 gives cycles-1 to count
  481. * high, bit 3-0 gives cycles-1 to count low. Distribute
  482. * these with no more than 1 cycle difference between
  483. * low and high and add low and high to get the actual
  484. * divisor. The base PLL is 208 MHz. Writing 0x00 will
  485. * divide by 1 and 1 so the highest frequency possible
  486. * is 104 MHz.
  487. *
  488. * e.g. 0x54 =>
  489. * f = 208 / ((5+1) + (4+1)) = 208 / 11 = 18.9 MHz
  490. */
  491. u16 val = readw(U300_SYSCON_VBASE + U300_SYSCON_MMF0R) &
  492. U300_SYSCON_MMF0R_MASK;
  493. switch (val) {
  494. case 0x0054:
  495. return 18900000;
  496. case 0x0044:
  497. return 20800000;
  498. case 0x0043:
  499. return 23100000;
  500. case 0x0033:
  501. return 26000000;
  502. case 0x0032:
  503. return 29700000;
  504. case 0x0022:
  505. return 34700000;
  506. case 0x0021:
  507. return 41600000;
  508. case 0x0011:
  509. return 52000000;
  510. case 0x0000:
  511. return 104000000;
  512. default:
  513. break;
  514. }
  515. }
  516. default:
  517. break;
  518. }
  519. return clk->rate;
  520. }
  521. static unsigned long clk_get_rate_i2s_i2c_spi(struct clk *clk)
  522. {
  523. u16 val;
  524. val = syscon_clk_get_rate();
  525. switch (val) {
  526. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW_POWER:
  527. case U300_SYSCON_CCR_CLKING_PERFORMANCE_LOW:
  528. return 13000000;
  529. case U300_SYSCON_CCR_CLKING_PERFORMANCE_INTERMEDIATE:
  530. case U300_SYSCON_CCR_CLKING_PERFORMANCE_HIGH:
  531. case U300_SYSCON_CCR_CLKING_PERFORMANCE_BEST:
  532. return 26000000;
  533. default:
  534. break;
  535. }
  536. return clk->rate;
  537. }
  538. unsigned long clk_get_rate(struct clk *clk)
  539. {
  540. if (clk->get_rate)
  541. return clk->get_rate(clk);
  542. else
  543. return clk->rate;
  544. }
  545. EXPORT_SYMBOL(clk_get_rate);
  546. static unsigned long clk_round_rate_mclk(struct clk *clk, unsigned long rate)
  547. {
  548. if (rate <= 18900000)
  549. return 18900000;
  550. if (rate <= 20800000)
  551. return 20800000;
  552. if (rate <= 23100000)
  553. return 23100000;
  554. if (rate <= 26000000)
  555. return 26000000;
  556. if (rate <= 29700000)
  557. return 29700000;
  558. if (rate <= 34700000)
  559. return 34700000;
  560. if (rate <= 41600000)
  561. return 41600000;
  562. if (rate <= 52000000)
  563. return 52000000;
  564. return -EINVAL;
  565. }
  566. static unsigned long clk_round_rate_cpuclk(struct clk *clk, unsigned long rate)
  567. {
  568. if (rate <= 13000000)
  569. return 13000000;
  570. if (rate <= 52000000)
  571. return 52000000;
  572. if (rate <= 104000000)
  573. return 104000000;
  574. if (rate <= 208000000)
  575. return 208000000;
  576. return -EINVAL;
  577. }
  578. /*
  579. * This adjusts a requested rate to the closest exact rate
  580. * a certain clock can provide. For a fixed clock it's
  581. * mostly clk->rate.
  582. */
  583. long clk_round_rate(struct clk *clk, unsigned long rate)
  584. {
  585. /* TODO: get appropriate switches for EMIFCLK, AHBCLK and MCLK */
  586. /* Else default to fixed value */
  587. if (clk->round_rate) {
  588. return (long) clk->round_rate(clk, rate);
  589. } else {
  590. printk(KERN_ERR "clock: Failed to round rate of %s\n",
  591. clk->name);
  592. }
  593. return (long) clk->rate;
  594. }
  595. EXPORT_SYMBOL(clk_round_rate);
  596. static int clk_set_rate_mclk(struct clk *clk, unsigned long rate)
  597. {
  598. syscon_clk_rate_set_mclk(clk_round_rate(clk, rate));
  599. return 0;
  600. }
  601. static int clk_set_rate_cpuclk(struct clk *clk, unsigned long rate)
  602. {
  603. syscon_clk_rate_set_cpuclk(clk_round_rate(clk, rate));
  604. return 0;
  605. }
  606. int clk_set_rate(struct clk *clk, unsigned long rate)
  607. {
  608. /* TODO: set for EMIFCLK and AHBCLK */
  609. /* Else assume the clock is fixed and fail */
  610. if (clk->set_rate) {
  611. return clk->set_rate(clk, rate);
  612. } else {
  613. printk(KERN_ERR "clock: Failed to set %s to %ld hz\n",
  614. clk->name, rate);
  615. return -EINVAL;
  616. }
  617. }
  618. EXPORT_SYMBOL(clk_set_rate);
  619. /*
  620. * Clock definitions. The clock parents are set to respective
  621. * bridge and the clock framework makes sure that the clocks have
  622. * parents activated and are brought out of reset when in use.
  623. *
  624. * Clocks that have hw_ctrld = true are hw controlled, and the hw
  625. * can by itself turn these clocks on and off.
  626. * So in other words, we don't really have to care about them.
  627. */
  628. static struct clk amba_clk = {
  629. .name = "AMBA",
  630. .rate = 52000000, /* this varies! */
  631. .hw_ctrld = true,
  632. .reset = false,
  633. .lock = __SPIN_LOCK_UNLOCKED(amba_clk.lock),
  634. };
  635. /*
  636. * These blocks are connected directly to the AMBA bus
  637. * with no bridge.
  638. */
  639. static struct clk cpu_clk = {
  640. .name = "CPU",
  641. .parent = &amba_clk,
  642. .rate = 208000000, /* this varies! */
  643. .hw_ctrld = true,
  644. .reset = true,
  645. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  646. .res_mask = U300_SYSCON_RRR_CPU_RESET_EN,
  647. .set_rate = clk_set_rate_cpuclk,
  648. .get_rate = clk_get_rate_cpuclk,
  649. .round_rate = clk_round_rate_cpuclk,
  650. .lock = __SPIN_LOCK_UNLOCKED(cpu_clk.lock),
  651. };
  652. static struct clk nandif_clk = {
  653. .name = "FSMC",
  654. .parent = &amba_clk,
  655. .hw_ctrld = false,
  656. .reset = true,
  657. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  658. .res_mask = U300_SYSCON_RRR_NANDIF_RESET_EN,
  659. .clk_val = U300_SYSCON_SBCER_NANDIF_CLK_EN,
  660. .enable = syscon_clk_enable,
  661. .disable = syscon_clk_disable,
  662. .lock = __SPIN_LOCK_UNLOCKED(nandif_clk.lock),
  663. };
  664. static struct clk semi_clk = {
  665. .name = "SEMI",
  666. .parent = &amba_clk,
  667. .rate = 0, /* FIXME */
  668. /* It is not possible to reset SEMI */
  669. .hw_ctrld = false,
  670. .reset = false,
  671. .clk_val = U300_SYSCON_SBCER_SEMI_CLK_EN,
  672. .enable = syscon_clk_enable,
  673. .disable = syscon_clk_disable,
  674. .lock = __SPIN_LOCK_UNLOCKED(semi_clk.lock),
  675. };
  676. #ifdef CONFIG_MACH_U300_BS335
  677. static struct clk isp_clk = {
  678. .name = "ISP",
  679. .parent = &amba_clk,
  680. .rate = 0, /* FIXME */
  681. .hw_ctrld = false,
  682. .reset = true,
  683. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  684. .res_mask = U300_SYSCON_RRR_ISP_RESET_EN,
  685. .clk_val = U300_SYSCON_SBCER_ISP_CLK_EN,
  686. .enable = syscon_clk_enable,
  687. .disable = syscon_clk_disable,
  688. .lock = __SPIN_LOCK_UNLOCKED(isp_clk.lock),
  689. };
  690. static struct clk cds_clk = {
  691. .name = "CDS",
  692. .parent = &amba_clk,
  693. .rate = 0, /* FIXME */
  694. .hw_ctrld = false,
  695. .reset = true,
  696. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  697. .res_mask = U300_SYSCON_RRR_CDS_RESET_EN,
  698. .clk_val = U300_SYSCON_SBCER_CDS_CLK_EN,
  699. .enable = syscon_clk_enable,
  700. .disable = syscon_clk_disable,
  701. .lock = __SPIN_LOCK_UNLOCKED(cds_clk.lock),
  702. };
  703. #endif
  704. static struct clk dma_clk = {
  705. .name = "DMA",
  706. .parent = &amba_clk,
  707. .rate = 52000000, /* this varies! */
  708. .hw_ctrld = true,
  709. .reset = true,
  710. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  711. .res_mask = U300_SYSCON_RRR_DMAC_RESET_EN,
  712. .clk_val = U300_SYSCON_SBCER_DMAC_CLK_EN,
  713. .enable = syscon_clk_enable,
  714. .disable = syscon_clk_disable,
  715. .lock = __SPIN_LOCK_UNLOCKED(dma_clk.lock),
  716. };
  717. static struct clk aaif_clk = {
  718. .name = "AAIF",
  719. .parent = &amba_clk,
  720. .rate = 52000000, /* this varies! */
  721. .hw_ctrld = true,
  722. .reset = true,
  723. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  724. .res_mask = U300_SYSCON_RRR_AAIF_RESET_EN,
  725. .clk_val = U300_SYSCON_SBCER_AAIF_CLK_EN,
  726. .enable = syscon_clk_enable,
  727. .disable = syscon_clk_disable,
  728. .lock = __SPIN_LOCK_UNLOCKED(aaif_clk.lock),
  729. };
  730. static struct clk apex_clk = {
  731. .name = "APEX",
  732. .parent = &amba_clk,
  733. .rate = 0, /* FIXME */
  734. .hw_ctrld = true,
  735. .reset = true,
  736. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  737. .res_mask = U300_SYSCON_RRR_APEX_RESET_EN,
  738. .clk_val = U300_SYSCON_SBCER_APEX_CLK_EN,
  739. .enable = syscon_clk_enable,
  740. .disable = syscon_clk_disable,
  741. .lock = __SPIN_LOCK_UNLOCKED(apex_clk.lock),
  742. };
  743. static struct clk video_enc_clk = {
  744. .name = "VIDEO_ENC",
  745. .parent = &amba_clk,
  746. .rate = 208000000, /* this varies! */
  747. .hw_ctrld = false,
  748. .reset = false,
  749. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  750. /* This has XGAM in the name but refers to the video encoder */
  751. .res_mask = U300_SYSCON_RRR_XGAM_VC_SYNC_RESET_EN,
  752. .clk_val = U300_SYSCON_SBCER_VIDEO_ENC_CLK_EN,
  753. .enable = syscon_clk_enable,
  754. .disable = syscon_clk_disable,
  755. .lock = __SPIN_LOCK_UNLOCKED(video_enc_clk.lock),
  756. };
  757. static struct clk xgam_clk = {
  758. .name = "XGAMCLK",
  759. .parent = &amba_clk,
  760. .rate = 52000000, /* this varies! */
  761. .hw_ctrld = false,
  762. .reset = true,
  763. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  764. .res_mask = U300_SYSCON_RRR_XGAM_RESET_EN,
  765. .clk_val = U300_SYSCON_SBCER_XGAM_CLK_EN,
  766. .get_rate = clk_get_rate_xgamclk,
  767. .enable = syscon_clk_enable,
  768. .disable = syscon_clk_disable,
  769. .lock = __SPIN_LOCK_UNLOCKED(xgam_clk.lock),
  770. };
  771. /* This clock is used to activate the video encoder */
  772. static struct clk ahb_clk = {
  773. .name = "AHB",
  774. .parent = &amba_clk,
  775. .rate = 52000000, /* this varies! */
  776. .hw_ctrld = false, /* This one is set to false due to HW bug */
  777. .reset = true,
  778. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  779. .res_mask = U300_SYSCON_RRR_AHB_RESET_EN,
  780. .clk_val = U300_SYSCON_SBCER_AHB_CLK_EN,
  781. .enable = syscon_clk_enable,
  782. .disable = syscon_clk_disable,
  783. .get_rate = clk_get_rate_ahb_clk,
  784. .lock = __SPIN_LOCK_UNLOCKED(ahb_clk.lock),
  785. };
  786. /*
  787. * Clocks on the AHB bridge
  788. */
  789. static struct clk ahb_subsys_clk = {
  790. .name = "AHB_SUBSYS",
  791. .parent = &amba_clk,
  792. .rate = 52000000, /* this varies! */
  793. .hw_ctrld = true,
  794. .reset = false,
  795. .clk_val = U300_SYSCON_SBCER_AHB_SUBSYS_BRIDGE_CLK_EN,
  796. .enable = syscon_clk_enable,
  797. .disable = syscon_clk_disable,
  798. .get_rate = clk_get_rate_ahb_clk,
  799. .lock = __SPIN_LOCK_UNLOCKED(ahb_subsys_clk.lock),
  800. };
  801. static struct clk intcon_clk = {
  802. .name = "INTCON",
  803. .parent = &ahb_subsys_clk,
  804. .rate = 52000000, /* this varies! */
  805. .hw_ctrld = false,
  806. .reset = true,
  807. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  808. .res_mask = U300_SYSCON_RRR_INTCON_RESET_EN,
  809. /* INTCON can be reset but not clock-gated */
  810. .lock = __SPIN_LOCK_UNLOCKED(intcon_clk.lock),
  811. };
  812. static struct clk mspro_clk = {
  813. .name = "MSPRO",
  814. .parent = &ahb_subsys_clk,
  815. .rate = 0, /* FIXME */
  816. .hw_ctrld = false,
  817. .reset = true,
  818. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  819. .res_mask = U300_SYSCON_RRR_MSPRO_RESET_EN,
  820. .clk_val = U300_SYSCON_SBCER_MSPRO_CLK_EN,
  821. .enable = syscon_clk_enable,
  822. .disable = syscon_clk_disable,
  823. .lock = __SPIN_LOCK_UNLOCKED(mspro_clk.lock),
  824. };
  825. static struct clk emif_clk = {
  826. .name = "EMIF",
  827. .parent = &ahb_subsys_clk,
  828. .rate = 104000000, /* this varies! */
  829. .hw_ctrld = false,
  830. .reset = true,
  831. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RRR,
  832. .res_mask = U300_SYSCON_RRR_EMIF_RESET_EN,
  833. .clk_val = U300_SYSCON_SBCER_EMIF_CLK_EN,
  834. .enable = syscon_clk_enable,
  835. .disable = syscon_clk_disable,
  836. .get_rate = clk_get_rate_emif_clk,
  837. .lock = __SPIN_LOCK_UNLOCKED(emif_clk.lock),
  838. };
  839. /*
  840. * Clocks on the FAST bridge
  841. */
  842. static struct clk fast_clk = {
  843. .name = "FAST_BRIDGE",
  844. .parent = &amba_clk,
  845. .rate = 13000000, /* this varies! */
  846. .hw_ctrld = true,
  847. .reset = true,
  848. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR,
  849. .res_mask = U300_SYSCON_RFR_FAST_BRIDGE_RESET_ENABLE,
  850. .clk_val = U300_SYSCON_SBCER_FAST_BRIDGE_CLK_EN,
  851. .enable = syscon_clk_enable,
  852. .disable = syscon_clk_disable,
  853. .lock = __SPIN_LOCK_UNLOCKED(fast_clk.lock),
  854. };
  855. /*
  856. * The MMCI apb_pclk is hardwired to the same terminal as the
  857. * external MCI clock. Thus this will be referenced twice.
  858. */
  859. static struct clk mmcsd_clk = {
  860. .name = "MCLK",
  861. .parent = &fast_clk,
  862. .rate = 18900000, /* this varies! */
  863. .hw_ctrld = false,
  864. .reset = true,
  865. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR,
  866. .res_mask = U300_SYSCON_RFR_MMC_RESET_ENABLE,
  867. .clk_val = U300_SYSCON_SBCER_MMC_CLK_EN,
  868. .get_rate = clk_get_rate_mclk,
  869. .set_rate = clk_set_rate_mclk,
  870. .round_rate = clk_round_rate_mclk,
  871. .disable = syscon_clk_disable,
  872. .enable = syscon_clk_enable,
  873. .lock = __SPIN_LOCK_UNLOCKED(mmcsd_clk.lock),
  874. };
  875. static struct clk i2s0_clk = {
  876. .name = "i2s0",
  877. .parent = &fast_clk,
  878. .rate = 26000000, /* this varies! */
  879. .hw_ctrld = true,
  880. .reset = true,
  881. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR,
  882. .res_mask = U300_SYSCON_RFR_PCM_I2S0_RESET_ENABLE,
  883. .clk_val = U300_SYSCON_SBCER_I2S0_CORE_CLK_EN,
  884. .enable = syscon_clk_enable,
  885. .disable = syscon_clk_disable,
  886. .get_rate = clk_get_rate_i2s_i2c_spi,
  887. .lock = __SPIN_LOCK_UNLOCKED(i2s0_clk.lock),
  888. };
  889. static struct clk i2s1_clk = {
  890. .name = "i2s1",
  891. .parent = &fast_clk,
  892. .rate = 26000000, /* this varies! */
  893. .hw_ctrld = true,
  894. .reset = true,
  895. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR,
  896. .res_mask = U300_SYSCON_RFR_PCM_I2S1_RESET_ENABLE,
  897. .clk_val = U300_SYSCON_SBCER_I2S1_CORE_CLK_EN,
  898. .enable = syscon_clk_enable,
  899. .disable = syscon_clk_disable,
  900. .get_rate = clk_get_rate_i2s_i2c_spi,
  901. .lock = __SPIN_LOCK_UNLOCKED(i2s1_clk.lock),
  902. };
  903. static struct clk i2c0_clk = {
  904. .name = "I2C0",
  905. .parent = &fast_clk,
  906. .rate = 26000000, /* this varies! */
  907. .hw_ctrld = false,
  908. .reset = true,
  909. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR,
  910. .res_mask = U300_SYSCON_RFR_I2C0_RESET_ENABLE,
  911. .clk_val = U300_SYSCON_SBCER_I2C0_CLK_EN,
  912. .enable = syscon_clk_enable,
  913. .disable = syscon_clk_disable,
  914. .get_rate = clk_get_rate_i2s_i2c_spi,
  915. .lock = __SPIN_LOCK_UNLOCKED(i2c0_clk.lock),
  916. };
  917. static struct clk i2c1_clk = {
  918. .name = "I2C1",
  919. .parent = &fast_clk,
  920. .rate = 26000000, /* this varies! */
  921. .hw_ctrld = false,
  922. .reset = true,
  923. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR,
  924. .res_mask = U300_SYSCON_RFR_I2C1_RESET_ENABLE,
  925. .clk_val = U300_SYSCON_SBCER_I2C1_CLK_EN,
  926. .enable = syscon_clk_enable,
  927. .disable = syscon_clk_disable,
  928. .get_rate = clk_get_rate_i2s_i2c_spi,
  929. .lock = __SPIN_LOCK_UNLOCKED(i2c1_clk.lock),
  930. };
  931. /*
  932. * The SPI apb_pclk is hardwired to the same terminal as the
  933. * external SPI clock. Thus this will be referenced twice.
  934. */
  935. static struct clk spi_clk = {
  936. .name = "SPI",
  937. .parent = &fast_clk,
  938. .rate = 26000000, /* this varies! */
  939. .hw_ctrld = false,
  940. .reset = true,
  941. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR,
  942. .res_mask = U300_SYSCON_RFR_SPI_RESET_ENABLE,
  943. .clk_val = U300_SYSCON_SBCER_SPI_CLK_EN,
  944. .enable = syscon_clk_enable,
  945. .disable = syscon_clk_disable,
  946. .get_rate = clk_get_rate_i2s_i2c_spi,
  947. .lock = __SPIN_LOCK_UNLOCKED(spi_clk.lock),
  948. };
  949. #ifdef CONFIG_MACH_U300_BS335
  950. static struct clk uart1_pclk = {
  951. .name = "UART1_PCLK",
  952. .parent = &fast_clk,
  953. .hw_ctrld = false,
  954. .reset = true,
  955. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR,
  956. .res_mask = U300_SYSCON_RFR_UART1_RESET_ENABLE,
  957. .clk_val = U300_SYSCON_SBCER_UART1_CLK_EN,
  958. .enable = syscon_clk_enable,
  959. .disable = syscon_clk_disable,
  960. .lock = __SPIN_LOCK_UNLOCKED(uart1_pclk.lock),
  961. };
  962. /* This one is hardwired to PLL13 */
  963. static struct clk uart1_clk = {
  964. .name = "UART1_CLK",
  965. .rate = 13000000,
  966. .hw_ctrld = true,
  967. .lock = __SPIN_LOCK_UNLOCKED(uart1_clk.lock),
  968. };
  969. #endif
  970. /*
  971. * Clocks on the SLOW bridge
  972. */
  973. static struct clk slow_clk = {
  974. .name = "SLOW_BRIDGE",
  975. .parent = &amba_clk,
  976. .rate = 13000000,
  977. .hw_ctrld = true,
  978. .reset = true,
  979. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  980. .res_mask = U300_SYSCON_RSR_SLOW_BRIDGE_RESET_EN,
  981. .clk_val = U300_SYSCON_SBCER_SLOW_BRIDGE_CLK_EN,
  982. .enable = syscon_clk_enable,
  983. .disable = syscon_clk_disable,
  984. .lock = __SPIN_LOCK_UNLOCKED(slow_clk.lock),
  985. };
  986. /* TODO: implement SYSCON clock? */
  987. static struct clk wdog_clk = {
  988. .name = "WDOG",
  989. .parent = &slow_clk,
  990. .hw_ctrld = false,
  991. .rate = 32768,
  992. .reset = false,
  993. /* This is always on, cannot be enabled/disabled or reset */
  994. .lock = __SPIN_LOCK_UNLOCKED(wdog_clk.lock),
  995. };
  996. static struct clk uart0_pclk = {
  997. .name = "UART0_PCLK",
  998. .parent = &slow_clk,
  999. .hw_ctrld = false,
  1000. .reset = true,
  1001. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  1002. .res_mask = U300_SYSCON_RSR_UART_RESET_EN,
  1003. .clk_val = U300_SYSCON_SBCER_UART_CLK_EN,
  1004. .enable = syscon_clk_enable,
  1005. .disable = syscon_clk_disable,
  1006. .lock = __SPIN_LOCK_UNLOCKED(uart0_pclk.lock),
  1007. };
  1008. /* This one is hardwired to PLL13 */
  1009. static struct clk uart0_clk = {
  1010. .name = "UART0_CLK",
  1011. .parent = &slow_clk,
  1012. .rate = 13000000,
  1013. .hw_ctrld = true,
  1014. .lock = __SPIN_LOCK_UNLOCKED(uart0_clk.lock),
  1015. };
  1016. static struct clk keypad_clk = {
  1017. .name = "KEYPAD",
  1018. .parent = &slow_clk,
  1019. .rate = 32768,
  1020. .hw_ctrld = false,
  1021. .reset = true,
  1022. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  1023. .res_mask = U300_SYSCON_RSR_KEYPAD_RESET_EN,
  1024. .clk_val = U300_SYSCON_SBCER_KEYPAD_CLK_EN,
  1025. .enable = syscon_clk_enable,
  1026. .disable = syscon_clk_disable,
  1027. .lock = __SPIN_LOCK_UNLOCKED(keypad_clk.lock),
  1028. };
  1029. static struct clk gpio_clk = {
  1030. .name = "GPIO",
  1031. .parent = &slow_clk,
  1032. .rate = 13000000,
  1033. .hw_ctrld = true,
  1034. .reset = true,
  1035. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  1036. .res_mask = U300_SYSCON_RSR_GPIO_RESET_EN,
  1037. .clk_val = U300_SYSCON_SBCER_GPIO_CLK_EN,
  1038. .enable = syscon_clk_enable,
  1039. .disable = syscon_clk_disable,
  1040. .lock = __SPIN_LOCK_UNLOCKED(gpio_clk.lock),
  1041. };
  1042. static struct clk rtc_clk = {
  1043. .name = "RTC",
  1044. .parent = &slow_clk,
  1045. .rate = 32768,
  1046. .hw_ctrld = true,
  1047. .reset = true,
  1048. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  1049. .res_mask = U300_SYSCON_RSR_RTC_RESET_EN,
  1050. /* This clock is always on, cannot be enabled/disabled */
  1051. .lock = __SPIN_LOCK_UNLOCKED(rtc_clk.lock),
  1052. };
  1053. static struct clk bustr_clk = {
  1054. .name = "BUSTR",
  1055. .parent = &slow_clk,
  1056. .rate = 13000000,
  1057. .hw_ctrld = true,
  1058. .reset = true,
  1059. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  1060. .res_mask = U300_SYSCON_RSR_BTR_RESET_EN,
  1061. .clk_val = U300_SYSCON_SBCER_BTR_CLK_EN,
  1062. .enable = syscon_clk_enable,
  1063. .disable = syscon_clk_disable,
  1064. .lock = __SPIN_LOCK_UNLOCKED(bustr_clk.lock),
  1065. };
  1066. static struct clk evhist_clk = {
  1067. .name = "EVHIST",
  1068. .parent = &slow_clk,
  1069. .rate = 13000000,
  1070. .hw_ctrld = true,
  1071. .reset = true,
  1072. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  1073. .res_mask = U300_SYSCON_RSR_EH_RESET_EN,
  1074. .clk_val = U300_SYSCON_SBCER_EH_CLK_EN,
  1075. .enable = syscon_clk_enable,
  1076. .disable = syscon_clk_disable,
  1077. .lock = __SPIN_LOCK_UNLOCKED(evhist_clk.lock),
  1078. };
  1079. static struct clk timer_clk = {
  1080. .name = "TIMER",
  1081. .parent = &slow_clk,
  1082. .rate = 13000000,
  1083. .hw_ctrld = true,
  1084. .reset = true,
  1085. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  1086. .res_mask = U300_SYSCON_RSR_ACC_TMR_RESET_EN,
  1087. .clk_val = U300_SYSCON_SBCER_ACC_TMR_CLK_EN,
  1088. .enable = syscon_clk_enable,
  1089. .disable = syscon_clk_disable,
  1090. .lock = __SPIN_LOCK_UNLOCKED(timer_clk.lock),
  1091. };
  1092. /*
  1093. * There is a binary divider in the hardware that divides
  1094. * the 13MHz PLL by 13 down to 1 MHz.
  1095. */
  1096. static struct clk app_timer_clk = {
  1097. .name = "TIMER_APP",
  1098. .parent = &slow_clk,
  1099. .rate = 1000000,
  1100. .hw_ctrld = true,
  1101. .reset = true,
  1102. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  1103. .res_mask = U300_SYSCON_RSR_APP_TMR_RESET_EN,
  1104. .clk_val = U300_SYSCON_SBCER_APP_TMR_CLK_EN,
  1105. .enable = syscon_clk_enable,
  1106. .disable = syscon_clk_disable,
  1107. .lock = __SPIN_LOCK_UNLOCKED(app_timer_clk.lock),
  1108. };
  1109. #ifdef CONFIG_MACH_U300_BS335
  1110. static struct clk ppm_clk = {
  1111. .name = "PPM",
  1112. .parent = &slow_clk,
  1113. .rate = 0, /* FIXME */
  1114. .hw_ctrld = true, /* TODO: Look up if it is hw ctrld or not */
  1115. .reset = true,
  1116. .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
  1117. .res_mask = U300_SYSCON_RSR_PPM_RESET_EN,
  1118. .clk_val = U300_SYSCON_SBCER_PPM_CLK_EN,
  1119. .enable = syscon_clk_enable,
  1120. .disable = syscon_clk_disable,
  1121. .lock = __SPIN_LOCK_UNLOCKED(ppm_clk.lock),
  1122. };
  1123. #endif
  1124. #define DEF_LOOKUP(devid, clkref) \
  1125. { \
  1126. .dev_id = devid, \
  1127. .clk = clkref, \
  1128. }
  1129. #define DEF_LOOKUP_CON(devid, conid, clkref) \
  1130. { \
  1131. .dev_id = devid, \
  1132. .con_id = conid, \
  1133. .clk = clkref, \
  1134. }
  1135. /*
  1136. * Here we only define clocks that are meaningful to
  1137. * look up through clockdevice.
  1138. */
  1139. static struct clk_lookup lookups[] = {
  1140. /* Connected directly to the AMBA bus */
  1141. DEF_LOOKUP("amba", &amba_clk),
  1142. DEF_LOOKUP("cpu", &cpu_clk),
  1143. DEF_LOOKUP("fsmc-nand", &nandif_clk),
  1144. DEF_LOOKUP("semi", &semi_clk),
  1145. #ifdef CONFIG_MACH_U300_BS335
  1146. DEF_LOOKUP("isp", &isp_clk),
  1147. DEF_LOOKUP("cds", &cds_clk),
  1148. #endif
  1149. DEF_LOOKUP("dma", &dma_clk),
  1150. DEF_LOOKUP("msl", &aaif_clk),
  1151. DEF_LOOKUP("apex", &apex_clk),
  1152. DEF_LOOKUP("video_enc", &video_enc_clk),
  1153. DEF_LOOKUP("xgam", &xgam_clk),
  1154. DEF_LOOKUP("ahb", &ahb_clk),
  1155. /* AHB bridge clocks */
  1156. DEF_LOOKUP("ahb_subsys", &ahb_subsys_clk),
  1157. DEF_LOOKUP("intcon", &intcon_clk),
  1158. DEF_LOOKUP_CON("intcon", "apb_pclk", &intcon_clk),
  1159. DEF_LOOKUP("mspro", &mspro_clk),
  1160. DEF_LOOKUP("pl172", &emif_clk),
  1161. DEF_LOOKUP_CON("pl172", "apb_pclk", &emif_clk),
  1162. /* FAST bridge clocks */
  1163. DEF_LOOKUP("fast", &fast_clk),
  1164. DEF_LOOKUP("mmci", &mmcsd_clk),
  1165. DEF_LOOKUP_CON("mmci", "apb_pclk", &mmcsd_clk),
  1166. /*
  1167. * The .0 and .1 identifiers on these comes from the platform device
  1168. * .id field and are assigned when the platform devices are registered.
  1169. */
  1170. DEF_LOOKUP("i2s.0", &i2s0_clk),
  1171. DEF_LOOKUP("i2s.1", &i2s1_clk),
  1172. DEF_LOOKUP("stu300.0", &i2c0_clk),
  1173. DEF_LOOKUP("stu300.1", &i2c1_clk),
  1174. DEF_LOOKUP("pl022", &spi_clk),
  1175. DEF_LOOKUP_CON("pl022", "apb_pclk", &spi_clk),
  1176. #ifdef CONFIG_MACH_U300_BS335
  1177. DEF_LOOKUP("uart1", &uart1_clk),
  1178. DEF_LOOKUP_CON("uart1", "apb_pclk", &uart1_pclk),
  1179. #endif
  1180. /* SLOW bridge clocks */
  1181. DEF_LOOKUP("slow", &slow_clk),
  1182. DEF_LOOKUP("coh901327_wdog", &wdog_clk),
  1183. DEF_LOOKUP("uart0", &uart0_clk),
  1184. DEF_LOOKUP_CON("uart0", "apb_pclk", &uart0_pclk),
  1185. DEF_LOOKUP("apptimer", &app_timer_clk),
  1186. DEF_LOOKUP("coh901461-keypad", &keypad_clk),
  1187. DEF_LOOKUP("u300-gpio", &gpio_clk),
  1188. DEF_LOOKUP("rtc-coh901331", &rtc_clk),
  1189. DEF_LOOKUP("bustr", &bustr_clk),
  1190. DEF_LOOKUP("evhist", &evhist_clk),
  1191. DEF_LOOKUP("timer", &timer_clk),
  1192. #ifdef CONFIG_MACH_U300_BS335
  1193. DEF_LOOKUP("ppm", &ppm_clk),
  1194. #endif
  1195. };
  1196. static void __init clk_register(void)
  1197. {
  1198. /* Register the lookups */
  1199. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  1200. }
  1201. #if (defined(CONFIG_DEBUG_FS) && defined(CONFIG_U300_DEBUG))
  1202. /*
  1203. * The following makes it possible to view the status (especially
  1204. * reference count and reset status) for the clocks in the platform
  1205. * by looking into the special file <debugfs>/u300_clocks
  1206. */
  1207. /* A list of all clocks in the platform */
  1208. static struct clk *clks[] = {
  1209. /* Top node clock for the AMBA bus */
  1210. &amba_clk,
  1211. /* Connected directly to the AMBA bus */
  1212. &cpu_clk,
  1213. &nandif_clk,
  1214. &semi_clk,
  1215. #ifdef CONFIG_MACH_U300_BS335
  1216. &isp_clk,
  1217. &cds_clk,
  1218. #endif
  1219. &dma_clk,
  1220. &aaif_clk,
  1221. &apex_clk,
  1222. &video_enc_clk,
  1223. &xgam_clk,
  1224. &ahb_clk,
  1225. /* AHB bridge clocks */
  1226. &ahb_subsys_clk,
  1227. &intcon_clk,
  1228. &mspro_clk,
  1229. &emif_clk,
  1230. /* FAST bridge clocks */
  1231. &fast_clk,
  1232. &mmcsd_clk,
  1233. &i2s0_clk,
  1234. &i2s1_clk,
  1235. &i2c0_clk,
  1236. &i2c1_clk,
  1237. &spi_clk,
  1238. #ifdef CONFIG_MACH_U300_BS335
  1239. &uart1_clk,
  1240. &uart1_pclk,
  1241. #endif
  1242. /* SLOW bridge clocks */
  1243. &slow_clk,
  1244. &wdog_clk,
  1245. &uart0_clk,
  1246. &uart0_pclk,
  1247. &app_timer_clk,
  1248. &keypad_clk,
  1249. &gpio_clk,
  1250. &rtc_clk,
  1251. &bustr_clk,
  1252. &evhist_clk,
  1253. &timer_clk,
  1254. #ifdef CONFIG_MACH_U300_BS335
  1255. &ppm_clk,
  1256. #endif
  1257. };
  1258. static int u300_clocks_show(struct seq_file *s, void *data)
  1259. {
  1260. struct clk *clk;
  1261. int i;
  1262. seq_printf(s, "CLOCK DEVICE RESET STATE\t" \
  1263. "ACTIVE\tUSERS\tHW CTRL FREQ\n");
  1264. seq_printf(s, "---------------------------------------------" \
  1265. "-----------------------------------------\n");
  1266. for (i = 0; i < ARRAY_SIZE(clks); i++) {
  1267. clk = clks[i];
  1268. if (clk != ERR_PTR(-ENOENT)) {
  1269. /* Format clock and device name nicely */
  1270. char cdp[33];
  1271. int chars;
  1272. chars = snprintf(&cdp[0], 17, "%s", clk->name);
  1273. while (chars < 16) {
  1274. cdp[chars] = ' ';
  1275. chars++;
  1276. }
  1277. chars = snprintf(&cdp[16], 17, "%s", clk->dev ?
  1278. dev_name(clk->dev) : "N/A");
  1279. while (chars < 16) {
  1280. cdp[chars+16] = ' ';
  1281. chars++;
  1282. }
  1283. cdp[32] = '\0';
  1284. if (clk->get_rate || clk->rate != 0)
  1285. seq_printf(s,
  1286. "%s%s\t%s\t%d\t%s\t%lu Hz\n",
  1287. &cdp[0],
  1288. clk->reset ?
  1289. "ASSERTED" : "RELEASED",
  1290. clk->usecount ? "ON" : "OFF",
  1291. clk->usecount,
  1292. clk->hw_ctrld ? "YES" : "NO ",
  1293. clk_get_rate(clk));
  1294. else
  1295. seq_printf(s,
  1296. "%s%s\t%s\t%d\t%s\t" \
  1297. "(unknown rate)\n",
  1298. &cdp[0],
  1299. clk->reset ?
  1300. "ASSERTED" : "RELEASED",
  1301. clk->usecount ? "ON" : "OFF",
  1302. clk->usecount,
  1303. clk->hw_ctrld ? "YES" : "NO ");
  1304. }
  1305. }
  1306. return 0;
  1307. }
  1308. static int u300_clocks_open(struct inode *inode, struct file *file)
  1309. {
  1310. return single_open(file, u300_clocks_show, NULL);
  1311. }
  1312. static const struct file_operations u300_clocks_operations = {
  1313. .open = u300_clocks_open,
  1314. .read = seq_read,
  1315. .llseek = seq_lseek,
  1316. .release = single_release,
  1317. };
  1318. static int __init init_clk_read_debugfs(void)
  1319. {
  1320. /* Expose a simple debugfs interface to view all clocks */
  1321. (void) debugfs_create_file("u300_clocks", S_IFREG | S_IRUGO,
  1322. NULL, NULL,
  1323. &u300_clocks_operations);
  1324. return 0;
  1325. }
  1326. /*
  1327. * This needs to come in after the core_initcall() for the
  1328. * overall clocks, because debugfs is not available until
  1329. * the subsystems come up.
  1330. */
  1331. module_init(init_clk_read_debugfs);
  1332. #endif
  1333. int __init u300_clock_init(void)
  1334. {
  1335. u16 val;
  1336. /*
  1337. * FIXME: shall all this powermanagement stuff really live here???
  1338. */
  1339. /* Set system to run at PLL208, max performance, a known state. */
  1340. val = readw(U300_SYSCON_VBASE + U300_SYSCON_CCR);
  1341. val &= ~U300_SYSCON_CCR_CLKING_PERFORMANCE_MASK;
  1342. writew(val, U300_SYSCON_VBASE + U300_SYSCON_CCR);
  1343. /* Wait for the PLL208 to lock if not locked in yet */
  1344. while (!(readw(U300_SYSCON_VBASE + U300_SYSCON_CSR) &
  1345. U300_SYSCON_CSR_PLL208_LOCK_IND));
  1346. /* Power management enable */
  1347. val = readw(U300_SYSCON_VBASE + U300_SYSCON_PMCR);
  1348. val |= U300_SYSCON_PMCR_PWR_MGNT_ENABLE;
  1349. writew(val, U300_SYSCON_VBASE + U300_SYSCON_PMCR);
  1350. clk_register();
  1351. /*
  1352. * Some of these may be on when we boot the system so make sure they
  1353. * are turned OFF.
  1354. */
  1355. syscon_block_reset_enable(&timer_clk);
  1356. timer_clk.disable(&timer_clk);
  1357. /*
  1358. * These shall be turned on by default when we boot the system
  1359. * so make sure they are ON. (Adding CPU here is a bit too much.)
  1360. * These clocks will be claimed by drivers later.
  1361. */
  1362. syscon_block_reset_disable(&semi_clk);
  1363. syscon_block_reset_disable(&emif_clk);
  1364. clk_enable(&semi_clk);
  1365. clk_enable(&emif_clk);
  1366. return 0;
  1367. }