at32ap700x.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855
  1. /*
  2. * Copyright (C) 2005-2006 Atmel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/clk.h>
  9. #include <linux/fb.h>
  10. #include <linux/init.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/dma-mapping.h>
  13. #include <linux/spi/spi.h>
  14. #include <linux/usb/atmel_usba_udc.h>
  15. #include <asm/io.h>
  16. #include <asm/irq.h>
  17. #include <asm/arch/at32ap700x.h>
  18. #include <asm/arch/board.h>
  19. #include <asm/arch/portmux.h>
  20. #include <video/atmel_lcdc.h>
  21. #include "clock.h"
  22. #include "hmatrix.h"
  23. #include "pio.h"
  24. #include "pm.h"
  25. #define PBMEM(base) \
  26. { \
  27. .start = base, \
  28. .end = base + 0x3ff, \
  29. .flags = IORESOURCE_MEM, \
  30. }
  31. #define IRQ(num) \
  32. { \
  33. .start = num, \
  34. .end = num, \
  35. .flags = IORESOURCE_IRQ, \
  36. }
  37. #define NAMED_IRQ(num, _name) \
  38. { \
  39. .start = num, \
  40. .end = num, \
  41. .name = _name, \
  42. .flags = IORESOURCE_IRQ, \
  43. }
  44. /* REVISIT these assume *every* device supports DMA, but several
  45. * don't ... tc, smc, pio, rtc, watchdog, pwm, ps2, and more.
  46. */
  47. #define DEFINE_DEV(_name, _id) \
  48. static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \
  49. static struct platform_device _name##_id##_device = { \
  50. .name = #_name, \
  51. .id = _id, \
  52. .dev = { \
  53. .dma_mask = &_name##_id##_dma_mask, \
  54. .coherent_dma_mask = DMA_32BIT_MASK, \
  55. }, \
  56. .resource = _name##_id##_resource, \
  57. .num_resources = ARRAY_SIZE(_name##_id##_resource), \
  58. }
  59. #define DEFINE_DEV_DATA(_name, _id) \
  60. static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \
  61. static struct platform_device _name##_id##_device = { \
  62. .name = #_name, \
  63. .id = _id, \
  64. .dev = { \
  65. .dma_mask = &_name##_id##_dma_mask, \
  66. .platform_data = &_name##_id##_data, \
  67. .coherent_dma_mask = DMA_32BIT_MASK, \
  68. }, \
  69. .resource = _name##_id##_resource, \
  70. .num_resources = ARRAY_SIZE(_name##_id##_resource), \
  71. }
  72. #define select_peripheral(pin, periph, flags) \
  73. at32_select_periph(GPIO_PIN_##pin, GPIO_##periph, flags)
  74. #define DEV_CLK(_name, devname, bus, _index) \
  75. static struct clk devname##_##_name = { \
  76. .name = #_name, \
  77. .dev = &devname##_device.dev, \
  78. .parent = &bus##_clk, \
  79. .mode = bus##_clk_mode, \
  80. .get_rate = bus##_clk_get_rate, \
  81. .index = _index, \
  82. }
  83. static DEFINE_SPINLOCK(pm_lock);
  84. unsigned long at32ap7000_osc_rates[3] = {
  85. [0] = 32768,
  86. /* FIXME: these are ATSTK1002-specific */
  87. [1] = 20000000,
  88. [2] = 12000000,
  89. };
  90. static unsigned long osc_get_rate(struct clk *clk)
  91. {
  92. return at32ap7000_osc_rates[clk->index];
  93. }
  94. static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
  95. {
  96. unsigned long div, mul, rate;
  97. if (!(control & PM_BIT(PLLEN)))
  98. return 0;
  99. div = PM_BFEXT(PLLDIV, control) + 1;
  100. mul = PM_BFEXT(PLLMUL, control) + 1;
  101. rate = clk->parent->get_rate(clk->parent);
  102. rate = (rate + div / 2) / div;
  103. rate *= mul;
  104. return rate;
  105. }
  106. static unsigned long pll0_get_rate(struct clk *clk)
  107. {
  108. u32 control;
  109. control = pm_readl(PLL0);
  110. return pll_get_rate(clk, control);
  111. }
  112. static unsigned long pll1_get_rate(struct clk *clk)
  113. {
  114. u32 control;
  115. control = pm_readl(PLL1);
  116. return pll_get_rate(clk, control);
  117. }
  118. /*
  119. * The AT32AP7000 has five primary clock sources: One 32kHz
  120. * oscillator, two crystal oscillators and two PLLs.
  121. */
  122. static struct clk osc32k = {
  123. .name = "osc32k",
  124. .get_rate = osc_get_rate,
  125. .users = 1,
  126. .index = 0,
  127. };
  128. static struct clk osc0 = {
  129. .name = "osc0",
  130. .get_rate = osc_get_rate,
  131. .users = 1,
  132. .index = 1,
  133. };
  134. static struct clk osc1 = {
  135. .name = "osc1",
  136. .get_rate = osc_get_rate,
  137. .index = 2,
  138. };
  139. static struct clk pll0 = {
  140. .name = "pll0",
  141. .get_rate = pll0_get_rate,
  142. .parent = &osc0,
  143. };
  144. static struct clk pll1 = {
  145. .name = "pll1",
  146. .get_rate = pll1_get_rate,
  147. .parent = &osc0,
  148. };
  149. /*
  150. * The main clock can be either osc0 or pll0. The boot loader may
  151. * have chosen one for us, so we don't really know which one until we
  152. * have a look at the SM.
  153. */
  154. static struct clk *main_clock;
  155. /*
  156. * Synchronous clocks are generated from the main clock. The clocks
  157. * must satisfy the constraint
  158. * fCPU >= fHSB >= fPB
  159. * i.e. each clock must not be faster than its parent.
  160. */
  161. static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift)
  162. {
  163. return main_clock->get_rate(main_clock) >> shift;
  164. };
  165. static void cpu_clk_mode(struct clk *clk, int enabled)
  166. {
  167. unsigned long flags;
  168. u32 mask;
  169. spin_lock_irqsave(&pm_lock, flags);
  170. mask = pm_readl(CPU_MASK);
  171. if (enabled)
  172. mask |= 1 << clk->index;
  173. else
  174. mask &= ~(1 << clk->index);
  175. pm_writel(CPU_MASK, mask);
  176. spin_unlock_irqrestore(&pm_lock, flags);
  177. }
  178. static unsigned long cpu_clk_get_rate(struct clk *clk)
  179. {
  180. unsigned long cksel, shift = 0;
  181. cksel = pm_readl(CKSEL);
  182. if (cksel & PM_BIT(CPUDIV))
  183. shift = PM_BFEXT(CPUSEL, cksel) + 1;
  184. return bus_clk_get_rate(clk, shift);
  185. }
  186. static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
  187. {
  188. u32 control;
  189. unsigned long parent_rate, child_div, actual_rate, div;
  190. parent_rate = clk->parent->get_rate(clk->parent);
  191. control = pm_readl(CKSEL);
  192. if (control & PM_BIT(HSBDIV))
  193. child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
  194. else
  195. child_div = 1;
  196. if (rate > 3 * (parent_rate / 4) || child_div == 1) {
  197. actual_rate = parent_rate;
  198. control &= ~PM_BIT(CPUDIV);
  199. } else {
  200. unsigned int cpusel;
  201. div = (parent_rate + rate / 2) / rate;
  202. if (div > child_div)
  203. div = child_div;
  204. cpusel = (div > 1) ? (fls(div) - 2) : 0;
  205. control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control);
  206. actual_rate = parent_rate / (1 << (cpusel + 1));
  207. }
  208. pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
  209. clk->name, rate, actual_rate);
  210. if (apply)
  211. pm_writel(CKSEL, control);
  212. return actual_rate;
  213. }
  214. static void hsb_clk_mode(struct clk *clk, int enabled)
  215. {
  216. unsigned long flags;
  217. u32 mask;
  218. spin_lock_irqsave(&pm_lock, flags);
  219. mask = pm_readl(HSB_MASK);
  220. if (enabled)
  221. mask |= 1 << clk->index;
  222. else
  223. mask &= ~(1 << clk->index);
  224. pm_writel(HSB_MASK, mask);
  225. spin_unlock_irqrestore(&pm_lock, flags);
  226. }
  227. static unsigned long hsb_clk_get_rate(struct clk *clk)
  228. {
  229. unsigned long cksel, shift = 0;
  230. cksel = pm_readl(CKSEL);
  231. if (cksel & PM_BIT(HSBDIV))
  232. shift = PM_BFEXT(HSBSEL, cksel) + 1;
  233. return bus_clk_get_rate(clk, shift);
  234. }
  235. static void pba_clk_mode(struct clk *clk, int enabled)
  236. {
  237. unsigned long flags;
  238. u32 mask;
  239. spin_lock_irqsave(&pm_lock, flags);
  240. mask = pm_readl(PBA_MASK);
  241. if (enabled)
  242. mask |= 1 << clk->index;
  243. else
  244. mask &= ~(1 << clk->index);
  245. pm_writel(PBA_MASK, mask);
  246. spin_unlock_irqrestore(&pm_lock, flags);
  247. }
  248. static unsigned long pba_clk_get_rate(struct clk *clk)
  249. {
  250. unsigned long cksel, shift = 0;
  251. cksel = pm_readl(CKSEL);
  252. if (cksel & PM_BIT(PBADIV))
  253. shift = PM_BFEXT(PBASEL, cksel) + 1;
  254. return bus_clk_get_rate(clk, shift);
  255. }
  256. static void pbb_clk_mode(struct clk *clk, int enabled)
  257. {
  258. unsigned long flags;
  259. u32 mask;
  260. spin_lock_irqsave(&pm_lock, flags);
  261. mask = pm_readl(PBB_MASK);
  262. if (enabled)
  263. mask |= 1 << clk->index;
  264. else
  265. mask &= ~(1 << clk->index);
  266. pm_writel(PBB_MASK, mask);
  267. spin_unlock_irqrestore(&pm_lock, flags);
  268. }
  269. static unsigned long pbb_clk_get_rate(struct clk *clk)
  270. {
  271. unsigned long cksel, shift = 0;
  272. cksel = pm_readl(CKSEL);
  273. if (cksel & PM_BIT(PBBDIV))
  274. shift = PM_BFEXT(PBBSEL, cksel) + 1;
  275. return bus_clk_get_rate(clk, shift);
  276. }
  277. static struct clk cpu_clk = {
  278. .name = "cpu",
  279. .get_rate = cpu_clk_get_rate,
  280. .set_rate = cpu_clk_set_rate,
  281. .users = 1,
  282. };
  283. static struct clk hsb_clk = {
  284. .name = "hsb",
  285. .parent = &cpu_clk,
  286. .get_rate = hsb_clk_get_rate,
  287. };
  288. static struct clk pba_clk = {
  289. .name = "pba",
  290. .parent = &hsb_clk,
  291. .mode = hsb_clk_mode,
  292. .get_rate = pba_clk_get_rate,
  293. .index = 1,
  294. };
  295. static struct clk pbb_clk = {
  296. .name = "pbb",
  297. .parent = &hsb_clk,
  298. .mode = hsb_clk_mode,
  299. .get_rate = pbb_clk_get_rate,
  300. .users = 1,
  301. .index = 2,
  302. };
  303. /* --------------------------------------------------------------------
  304. * Generic Clock operations
  305. * -------------------------------------------------------------------- */
  306. static void genclk_mode(struct clk *clk, int enabled)
  307. {
  308. u32 control;
  309. control = pm_readl(GCCTRL(clk->index));
  310. if (enabled)
  311. control |= PM_BIT(CEN);
  312. else
  313. control &= ~PM_BIT(CEN);
  314. pm_writel(GCCTRL(clk->index), control);
  315. }
  316. static unsigned long genclk_get_rate(struct clk *clk)
  317. {
  318. u32 control;
  319. unsigned long div = 1;
  320. control = pm_readl(GCCTRL(clk->index));
  321. if (control & PM_BIT(DIVEN))
  322. div = 2 * (PM_BFEXT(DIV, control) + 1);
  323. return clk->parent->get_rate(clk->parent) / div;
  324. }
  325. static long genclk_set_rate(struct clk *clk, unsigned long rate, int apply)
  326. {
  327. u32 control;
  328. unsigned long parent_rate, actual_rate, div;
  329. parent_rate = clk->parent->get_rate(clk->parent);
  330. control = pm_readl(GCCTRL(clk->index));
  331. if (rate > 3 * parent_rate / 4) {
  332. actual_rate = parent_rate;
  333. control &= ~PM_BIT(DIVEN);
  334. } else {
  335. div = (parent_rate + rate) / (2 * rate) - 1;
  336. control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN);
  337. actual_rate = parent_rate / (2 * (div + 1));
  338. }
  339. dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n",
  340. clk->name, rate, actual_rate);
  341. if (apply)
  342. pm_writel(GCCTRL(clk->index), control);
  343. return actual_rate;
  344. }
  345. int genclk_set_parent(struct clk *clk, struct clk *parent)
  346. {
  347. u32 control;
  348. dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n",
  349. clk->name, parent->name, clk->parent->name);
  350. control = pm_readl(GCCTRL(clk->index));
  351. if (parent == &osc1 || parent == &pll1)
  352. control |= PM_BIT(OSCSEL);
  353. else if (parent == &osc0 || parent == &pll0)
  354. control &= ~PM_BIT(OSCSEL);
  355. else
  356. return -EINVAL;
  357. if (parent == &pll0 || parent == &pll1)
  358. control |= PM_BIT(PLLSEL);
  359. else
  360. control &= ~PM_BIT(PLLSEL);
  361. pm_writel(GCCTRL(clk->index), control);
  362. clk->parent = parent;
  363. return 0;
  364. }
  365. static void __init genclk_init_parent(struct clk *clk)
  366. {
  367. u32 control;
  368. struct clk *parent;
  369. BUG_ON(clk->index > 7);
  370. control = pm_readl(GCCTRL(clk->index));
  371. if (control & PM_BIT(OSCSEL))
  372. parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1;
  373. else
  374. parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
  375. clk->parent = parent;
  376. }
  377. /* --------------------------------------------------------------------
  378. * System peripherals
  379. * -------------------------------------------------------------------- */
  380. static struct resource at32_pm0_resource[] = {
  381. {
  382. .start = 0xfff00000,
  383. .end = 0xfff0007f,
  384. .flags = IORESOURCE_MEM,
  385. },
  386. IRQ(20),
  387. };
  388. static struct resource at32ap700x_rtc0_resource[] = {
  389. {
  390. .start = 0xfff00080,
  391. .end = 0xfff000af,
  392. .flags = IORESOURCE_MEM,
  393. },
  394. IRQ(21),
  395. };
  396. static struct resource at32_wdt0_resource[] = {
  397. {
  398. .start = 0xfff000b0,
  399. .end = 0xfff000cf,
  400. .flags = IORESOURCE_MEM,
  401. },
  402. };
  403. static struct resource at32_eic0_resource[] = {
  404. {
  405. .start = 0xfff00100,
  406. .end = 0xfff0013f,
  407. .flags = IORESOURCE_MEM,
  408. },
  409. IRQ(19),
  410. };
  411. DEFINE_DEV(at32_pm, 0);
  412. DEFINE_DEV(at32ap700x_rtc, 0);
  413. DEFINE_DEV(at32_wdt, 0);
  414. DEFINE_DEV(at32_eic, 0);
  415. /*
  416. * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
  417. * is always running.
  418. */
  419. static struct clk at32_pm_pclk = {
  420. .name = "pclk",
  421. .dev = &at32_pm0_device.dev,
  422. .parent = &pbb_clk,
  423. .mode = pbb_clk_mode,
  424. .get_rate = pbb_clk_get_rate,
  425. .users = 1,
  426. .index = 0,
  427. };
  428. static struct resource intc0_resource[] = {
  429. PBMEM(0xfff00400),
  430. };
  431. struct platform_device at32_intc0_device = {
  432. .name = "intc",
  433. .id = 0,
  434. .resource = intc0_resource,
  435. .num_resources = ARRAY_SIZE(intc0_resource),
  436. };
  437. DEV_CLK(pclk, at32_intc0, pbb, 1);
  438. static struct clk ebi_clk = {
  439. .name = "ebi",
  440. .parent = &hsb_clk,
  441. .mode = hsb_clk_mode,
  442. .get_rate = hsb_clk_get_rate,
  443. .users = 1,
  444. };
  445. static struct clk hramc_clk = {
  446. .name = "hramc",
  447. .parent = &hsb_clk,
  448. .mode = hsb_clk_mode,
  449. .get_rate = hsb_clk_get_rate,
  450. .users = 1,
  451. .index = 3,
  452. };
  453. static struct resource smc0_resource[] = {
  454. PBMEM(0xfff03400),
  455. };
  456. DEFINE_DEV(smc, 0);
  457. DEV_CLK(pclk, smc0, pbb, 13);
  458. DEV_CLK(mck, smc0, hsb, 0);
  459. static struct platform_device pdc_device = {
  460. .name = "pdc",
  461. .id = 0,
  462. };
  463. DEV_CLK(hclk, pdc, hsb, 4);
  464. DEV_CLK(pclk, pdc, pba, 16);
  465. static struct clk pico_clk = {
  466. .name = "pico",
  467. .parent = &cpu_clk,
  468. .mode = cpu_clk_mode,
  469. .get_rate = cpu_clk_get_rate,
  470. .users = 1,
  471. };
  472. static struct resource dmaca0_resource[] = {
  473. {
  474. .start = 0xff200000,
  475. .end = 0xff20ffff,
  476. .flags = IORESOURCE_MEM,
  477. },
  478. IRQ(2),
  479. };
  480. DEFINE_DEV(dmaca, 0);
  481. DEV_CLK(hclk, dmaca0, hsb, 10);
  482. /* --------------------------------------------------------------------
  483. * HMATRIX
  484. * -------------------------------------------------------------------- */
  485. static struct clk hmatrix_clk = {
  486. .name = "hmatrix_clk",
  487. .parent = &pbb_clk,
  488. .mode = pbb_clk_mode,
  489. .get_rate = pbb_clk_get_rate,
  490. .index = 2,
  491. .users = 1,
  492. };
  493. #define HMATRIX_BASE ((void __iomem *)0xfff00800)
  494. #define hmatrix_readl(reg) \
  495. __raw_readl((HMATRIX_BASE) + HMATRIX_##reg)
  496. #define hmatrix_writel(reg,value) \
  497. __raw_writel((value), (HMATRIX_BASE) + HMATRIX_##reg)
  498. /*
  499. * Set bits in the HMATRIX Special Function Register (SFR) used by the
  500. * External Bus Interface (EBI). This can be used to enable special
  501. * features like CompactFlash support, NAND Flash support, etc. on
  502. * certain chipselects.
  503. */
  504. static inline void set_ebi_sfr_bits(u32 mask)
  505. {
  506. u32 sfr;
  507. clk_enable(&hmatrix_clk);
  508. sfr = hmatrix_readl(SFR4);
  509. sfr |= mask;
  510. hmatrix_writel(SFR4, sfr);
  511. clk_disable(&hmatrix_clk);
  512. }
  513. /* --------------------------------------------------------------------
  514. * Timer/Counter (TC)
  515. * -------------------------------------------------------------------- */
  516. static struct resource at32_tcb0_resource[] = {
  517. PBMEM(0xfff00c00),
  518. IRQ(22),
  519. };
  520. static struct platform_device at32_tcb0_device = {
  521. .name = "atmel_tcb",
  522. .id = 0,
  523. .resource = at32_tcb0_resource,
  524. .num_resources = ARRAY_SIZE(at32_tcb0_resource),
  525. };
  526. DEV_CLK(t0_clk, at32_tcb0, pbb, 3);
  527. static struct resource at32_tcb1_resource[] = {
  528. PBMEM(0xfff01000),
  529. IRQ(23),
  530. };
  531. static struct platform_device at32_tcb1_device = {
  532. .name = "atmel_tcb",
  533. .id = 1,
  534. .resource = at32_tcb1_resource,
  535. .num_resources = ARRAY_SIZE(at32_tcb1_resource),
  536. };
  537. DEV_CLK(t0_clk, at32_tcb1, pbb, 4);
  538. /* --------------------------------------------------------------------
  539. * PIO
  540. * -------------------------------------------------------------------- */
  541. static struct resource pio0_resource[] = {
  542. PBMEM(0xffe02800),
  543. IRQ(13),
  544. };
  545. DEFINE_DEV(pio, 0);
  546. DEV_CLK(mck, pio0, pba, 10);
  547. static struct resource pio1_resource[] = {
  548. PBMEM(0xffe02c00),
  549. IRQ(14),
  550. };
  551. DEFINE_DEV(pio, 1);
  552. DEV_CLK(mck, pio1, pba, 11);
  553. static struct resource pio2_resource[] = {
  554. PBMEM(0xffe03000),
  555. IRQ(15),
  556. };
  557. DEFINE_DEV(pio, 2);
  558. DEV_CLK(mck, pio2, pba, 12);
  559. static struct resource pio3_resource[] = {
  560. PBMEM(0xffe03400),
  561. IRQ(16),
  562. };
  563. DEFINE_DEV(pio, 3);
  564. DEV_CLK(mck, pio3, pba, 13);
  565. static struct resource pio4_resource[] = {
  566. PBMEM(0xffe03800),
  567. IRQ(17),
  568. };
  569. DEFINE_DEV(pio, 4);
  570. DEV_CLK(mck, pio4, pba, 14);
  571. void __init at32_add_system_devices(void)
  572. {
  573. platform_device_register(&at32_pm0_device);
  574. platform_device_register(&at32_intc0_device);
  575. platform_device_register(&at32ap700x_rtc0_device);
  576. platform_device_register(&at32_wdt0_device);
  577. platform_device_register(&at32_eic0_device);
  578. platform_device_register(&smc0_device);
  579. platform_device_register(&pdc_device);
  580. platform_device_register(&dmaca0_device);
  581. platform_device_register(&at32_tcb0_device);
  582. platform_device_register(&at32_tcb1_device);
  583. platform_device_register(&pio0_device);
  584. platform_device_register(&pio1_device);
  585. platform_device_register(&pio2_device);
  586. platform_device_register(&pio3_device);
  587. platform_device_register(&pio4_device);
  588. }
  589. /* --------------------------------------------------------------------
  590. * USART
  591. * -------------------------------------------------------------------- */
  592. static struct atmel_uart_data atmel_usart0_data = {
  593. .use_dma_tx = 1,
  594. .use_dma_rx = 1,
  595. };
  596. static struct resource atmel_usart0_resource[] = {
  597. PBMEM(0xffe00c00),
  598. IRQ(6),
  599. };
  600. DEFINE_DEV_DATA(atmel_usart, 0);
  601. DEV_CLK(usart, atmel_usart0, pba, 3);
  602. static struct atmel_uart_data atmel_usart1_data = {
  603. .use_dma_tx = 1,
  604. .use_dma_rx = 1,
  605. };
  606. static struct resource atmel_usart1_resource[] = {
  607. PBMEM(0xffe01000),
  608. IRQ(7),
  609. };
  610. DEFINE_DEV_DATA(atmel_usart, 1);
  611. DEV_CLK(usart, atmel_usart1, pba, 4);
  612. static struct atmel_uart_data atmel_usart2_data = {
  613. .use_dma_tx = 1,
  614. .use_dma_rx = 1,
  615. };
  616. static struct resource atmel_usart2_resource[] = {
  617. PBMEM(0xffe01400),
  618. IRQ(8),
  619. };
  620. DEFINE_DEV_DATA(atmel_usart, 2);
  621. DEV_CLK(usart, atmel_usart2, pba, 5);
  622. static struct atmel_uart_data atmel_usart3_data = {
  623. .use_dma_tx = 1,
  624. .use_dma_rx = 1,
  625. };
  626. static struct resource atmel_usart3_resource[] = {
  627. PBMEM(0xffe01800),
  628. IRQ(9),
  629. };
  630. DEFINE_DEV_DATA(atmel_usart, 3);
  631. DEV_CLK(usart, atmel_usart3, pba, 6);
  632. static inline void configure_usart0_pins(void)
  633. {
  634. select_peripheral(PA(8), PERIPH_B, 0); /* RXD */
  635. select_peripheral(PA(9), PERIPH_B, 0); /* TXD */
  636. }
  637. static inline void configure_usart1_pins(void)
  638. {
  639. select_peripheral(PA(17), PERIPH_A, 0); /* RXD */
  640. select_peripheral(PA(18), PERIPH_A, 0); /* TXD */
  641. }
  642. static inline void configure_usart2_pins(void)
  643. {
  644. select_peripheral(PB(26), PERIPH_B, 0); /* RXD */
  645. select_peripheral(PB(27), PERIPH_B, 0); /* TXD */
  646. }
  647. static inline void configure_usart3_pins(void)
  648. {
  649. select_peripheral(PB(18), PERIPH_B, 0); /* RXD */
  650. select_peripheral(PB(17), PERIPH_B, 0); /* TXD */
  651. }
  652. static struct platform_device *__initdata at32_usarts[4];
  653. void __init at32_map_usart(unsigned int hw_id, unsigned int line)
  654. {
  655. struct platform_device *pdev;
  656. switch (hw_id) {
  657. case 0:
  658. pdev = &atmel_usart0_device;
  659. configure_usart0_pins();
  660. break;
  661. case 1:
  662. pdev = &atmel_usart1_device;
  663. configure_usart1_pins();
  664. break;
  665. case 2:
  666. pdev = &atmel_usart2_device;
  667. configure_usart2_pins();
  668. break;
  669. case 3:
  670. pdev = &atmel_usart3_device;
  671. configure_usart3_pins();
  672. break;
  673. default:
  674. return;
  675. }
  676. if (PXSEG(pdev->resource[0].start) == P4SEG) {
  677. /* Addresses in the P4 segment are permanently mapped 1:1 */
  678. struct atmel_uart_data *data = pdev->dev.platform_data;
  679. data->regs = (void __iomem *)pdev->resource[0].start;
  680. }
  681. pdev->id = line;
  682. at32_usarts[line] = pdev;
  683. }
  684. struct platform_device *__init at32_add_device_usart(unsigned int id)
  685. {
  686. platform_device_register(at32_usarts[id]);
  687. return at32_usarts[id];
  688. }
  689. struct platform_device *atmel_default_console_device;
  690. void __init at32_setup_serial_console(unsigned int usart_id)
  691. {
  692. atmel_default_console_device = at32_usarts[usart_id];
  693. }
  694. /* --------------------------------------------------------------------
  695. * Ethernet
  696. * -------------------------------------------------------------------- */
  697. #ifdef CONFIG_CPU_AT32AP7000
  698. static struct eth_platform_data macb0_data;
  699. static struct resource macb0_resource[] = {
  700. PBMEM(0xfff01800),
  701. IRQ(25),
  702. };
  703. DEFINE_DEV_DATA(macb, 0);
  704. DEV_CLK(hclk, macb0, hsb, 8);
  705. DEV_CLK(pclk, macb0, pbb, 6);
  706. static struct eth_platform_data macb1_data;
  707. static struct resource macb1_resource[] = {
  708. PBMEM(0xfff01c00),
  709. IRQ(26),
  710. };
  711. DEFINE_DEV_DATA(macb, 1);
  712. DEV_CLK(hclk, macb1, hsb, 9);
  713. DEV_CLK(pclk, macb1, pbb, 7);
  714. struct platform_device *__init
  715. at32_add_device_eth(unsigned int id, struct eth_platform_data *data)
  716. {
  717. struct platform_device *pdev;
  718. switch (id) {
  719. case 0:
  720. pdev = &macb0_device;
  721. select_peripheral(PC(3), PERIPH_A, 0); /* TXD0 */
  722. select_peripheral(PC(4), PERIPH_A, 0); /* TXD1 */
  723. select_peripheral(PC(7), PERIPH_A, 0); /* TXEN */
  724. select_peripheral(PC(8), PERIPH_A, 0); /* TXCK */
  725. select_peripheral(PC(9), PERIPH_A, 0); /* RXD0 */
  726. select_peripheral(PC(10), PERIPH_A, 0); /* RXD1 */
  727. select_peripheral(PC(13), PERIPH_A, 0); /* RXER */
  728. select_peripheral(PC(15), PERIPH_A, 0); /* RXDV */
  729. select_peripheral(PC(16), PERIPH_A, 0); /* MDC */
  730. select_peripheral(PC(17), PERIPH_A, 0); /* MDIO */
  731. if (!data->is_rmii) {
  732. select_peripheral(PC(0), PERIPH_A, 0); /* COL */
  733. select_peripheral(PC(1), PERIPH_A, 0); /* CRS */
  734. select_peripheral(PC(2), PERIPH_A, 0); /* TXER */
  735. select_peripheral(PC(5), PERIPH_A, 0); /* TXD2 */
  736. select_peripheral(PC(6), PERIPH_A, 0); /* TXD3 */
  737. select_peripheral(PC(11), PERIPH_A, 0); /* RXD2 */
  738. select_peripheral(PC(12), PERIPH_A, 0); /* RXD3 */
  739. select_peripheral(PC(14), PERIPH_A, 0); /* RXCK */
  740. select_peripheral(PC(18), PERIPH_A, 0); /* SPD */
  741. }
  742. break;
  743. case 1:
  744. pdev = &macb1_device;
  745. select_peripheral(PD(13), PERIPH_B, 0); /* TXD0 */
  746. select_peripheral(PD(14), PERIPH_B, 0); /* TXD1 */
  747. select_peripheral(PD(11), PERIPH_B, 0); /* TXEN */
  748. select_peripheral(PD(12), PERIPH_B, 0); /* TXCK */
  749. select_peripheral(PD(10), PERIPH_B, 0); /* RXD0 */
  750. select_peripheral(PD(6), PERIPH_B, 0); /* RXD1 */
  751. select_peripheral(PD(5), PERIPH_B, 0); /* RXER */
  752. select_peripheral(PD(4), PERIPH_B, 0); /* RXDV */
  753. select_peripheral(PD(3), PERIPH_B, 0); /* MDC */
  754. select_peripheral(PD(2), PERIPH_B, 0); /* MDIO */
  755. if (!data->is_rmii) {
  756. select_peripheral(PC(19), PERIPH_B, 0); /* COL */
  757. select_peripheral(PC(23), PERIPH_B, 0); /* CRS */
  758. select_peripheral(PC(26), PERIPH_B, 0); /* TXER */
  759. select_peripheral(PC(27), PERIPH_B, 0); /* TXD2 */
  760. select_peripheral(PC(28), PERIPH_B, 0); /* TXD3 */
  761. select_peripheral(PC(29), PERIPH_B, 0); /* RXD2 */
  762. select_peripheral(PC(30), PERIPH_B, 0); /* RXD3 */
  763. select_peripheral(PC(24), PERIPH_B, 0); /* RXCK */
  764. select_peripheral(PD(15), PERIPH_B, 0); /* SPD */
  765. }
  766. break;
  767. default:
  768. return NULL;
  769. }
  770. memcpy(pdev->dev.platform_data, data, sizeof(struct eth_platform_data));
  771. platform_device_register(pdev);
  772. return pdev;
  773. }
  774. #endif
  775. /* --------------------------------------------------------------------
  776. * SPI
  777. * -------------------------------------------------------------------- */
  778. static struct resource atmel_spi0_resource[] = {
  779. PBMEM(0xffe00000),
  780. IRQ(3),
  781. };
  782. DEFINE_DEV(atmel_spi, 0);
  783. DEV_CLK(spi_clk, atmel_spi0, pba, 0);
  784. static struct resource atmel_spi1_resource[] = {
  785. PBMEM(0xffe00400),
  786. IRQ(4),
  787. };
  788. DEFINE_DEV(atmel_spi, 1);
  789. DEV_CLK(spi_clk, atmel_spi1, pba, 1);
  790. static void __init
  791. at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b,
  792. unsigned int n, const u8 *pins)
  793. {
  794. unsigned int pin, mode;
  795. for (; n; n--, b++) {
  796. b->bus_num = bus_num;
  797. if (b->chip_select >= 4)
  798. continue;
  799. pin = (unsigned)b->controller_data;
  800. if (!pin) {
  801. pin = pins[b->chip_select];
  802. b->controller_data = (void *)pin;
  803. }
  804. mode = AT32_GPIOF_OUTPUT;
  805. if (!(b->mode & SPI_CS_HIGH))
  806. mode |= AT32_GPIOF_HIGH;
  807. at32_select_gpio(pin, mode);
  808. }
  809. }
  810. struct platform_device *__init
  811. at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
  812. {
  813. /*
  814. * Manage the chipselects as GPIOs, normally using the same pins
  815. * the SPI controller expects; but boards can use other pins.
  816. */
  817. static u8 __initdata spi0_pins[] =
  818. { GPIO_PIN_PA(3), GPIO_PIN_PA(4),
  819. GPIO_PIN_PA(5), GPIO_PIN_PA(20), };
  820. static u8 __initdata spi1_pins[] =
  821. { GPIO_PIN_PB(2), GPIO_PIN_PB(3),
  822. GPIO_PIN_PB(4), GPIO_PIN_PA(27), };
  823. struct platform_device *pdev;
  824. switch (id) {
  825. case 0:
  826. pdev = &atmel_spi0_device;
  827. select_peripheral(PA(0), PERIPH_A, 0); /* MISO */
  828. select_peripheral(PA(1), PERIPH_A, 0); /* MOSI */
  829. select_peripheral(PA(2), PERIPH_A, 0); /* SCK */
  830. at32_spi_setup_slaves(0, b, n, spi0_pins);
  831. break;
  832. case 1:
  833. pdev = &atmel_spi1_device;
  834. select_peripheral(PB(0), PERIPH_B, 0); /* MISO */
  835. select_peripheral(PB(1), PERIPH_B, 0); /* MOSI */
  836. select_peripheral(PB(5), PERIPH_B, 0); /* SCK */
  837. at32_spi_setup_slaves(1, b, n, spi1_pins);
  838. break;
  839. default:
  840. return NULL;
  841. }
  842. spi_register_board_info(b, n);
  843. platform_device_register(pdev);
  844. return pdev;
  845. }
  846. /* --------------------------------------------------------------------
  847. * TWI
  848. * -------------------------------------------------------------------- */
  849. static struct resource atmel_twi0_resource[] __initdata = {
  850. PBMEM(0xffe00800),
  851. IRQ(5),
  852. };
  853. static struct clk atmel_twi0_pclk = {
  854. .name = "twi_pclk",
  855. .parent = &pba_clk,
  856. .mode = pba_clk_mode,
  857. .get_rate = pba_clk_get_rate,
  858. .index = 2,
  859. };
  860. struct platform_device *__init at32_add_device_twi(unsigned int id,
  861. struct i2c_board_info *b,
  862. unsigned int n)
  863. {
  864. struct platform_device *pdev;
  865. if (id != 0)
  866. return NULL;
  867. pdev = platform_device_alloc("atmel_twi", id);
  868. if (!pdev)
  869. return NULL;
  870. if (platform_device_add_resources(pdev, atmel_twi0_resource,
  871. ARRAY_SIZE(atmel_twi0_resource)))
  872. goto err_add_resources;
  873. select_peripheral(PA(6), PERIPH_A, 0); /* SDA */
  874. select_peripheral(PA(7), PERIPH_A, 0); /* SDL */
  875. atmel_twi0_pclk.dev = &pdev->dev;
  876. if (b)
  877. i2c_register_board_info(id, b, n);
  878. platform_device_add(pdev);
  879. return pdev;
  880. err_add_resources:
  881. platform_device_put(pdev);
  882. return NULL;
  883. }
  884. /* --------------------------------------------------------------------
  885. * MMC
  886. * -------------------------------------------------------------------- */
  887. static struct resource atmel_mci0_resource[] __initdata = {
  888. PBMEM(0xfff02400),
  889. IRQ(28),
  890. };
  891. static struct clk atmel_mci0_pclk = {
  892. .name = "mci_clk",
  893. .parent = &pbb_clk,
  894. .mode = pbb_clk_mode,
  895. .get_rate = pbb_clk_get_rate,
  896. .index = 9,
  897. };
  898. struct platform_device *__init at32_add_device_mci(unsigned int id)
  899. {
  900. struct platform_device *pdev;
  901. if (id != 0)
  902. return NULL;
  903. pdev = platform_device_alloc("atmel_mci", id);
  904. if (!pdev)
  905. return NULL;
  906. if (platform_device_add_resources(pdev, atmel_mci0_resource,
  907. ARRAY_SIZE(atmel_mci0_resource)))
  908. goto err_add_resources;
  909. select_peripheral(PA(10), PERIPH_A, 0); /* CLK */
  910. select_peripheral(PA(11), PERIPH_A, 0); /* CMD */
  911. select_peripheral(PA(12), PERIPH_A, 0); /* DATA0 */
  912. select_peripheral(PA(13), PERIPH_A, 0); /* DATA1 */
  913. select_peripheral(PA(14), PERIPH_A, 0); /* DATA2 */
  914. select_peripheral(PA(15), PERIPH_A, 0); /* DATA3 */
  915. atmel_mci0_pclk.dev = &pdev->dev;
  916. platform_device_add(pdev);
  917. return pdev;
  918. err_add_resources:
  919. platform_device_put(pdev);
  920. return NULL;
  921. }
  922. /* --------------------------------------------------------------------
  923. * LCDC
  924. * -------------------------------------------------------------------- */
  925. #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
  926. static struct atmel_lcdfb_info atmel_lcdfb0_data;
  927. static struct resource atmel_lcdfb0_resource[] = {
  928. {
  929. .start = 0xff000000,
  930. .end = 0xff000fff,
  931. .flags = IORESOURCE_MEM,
  932. },
  933. IRQ(1),
  934. {
  935. /* Placeholder for pre-allocated fb memory */
  936. .start = 0x00000000,
  937. .end = 0x00000000,
  938. .flags = 0,
  939. },
  940. };
  941. DEFINE_DEV_DATA(atmel_lcdfb, 0);
  942. DEV_CLK(hck1, atmel_lcdfb0, hsb, 7);
  943. static struct clk atmel_lcdfb0_pixclk = {
  944. .name = "lcdc_clk",
  945. .dev = &atmel_lcdfb0_device.dev,
  946. .mode = genclk_mode,
  947. .get_rate = genclk_get_rate,
  948. .set_rate = genclk_set_rate,
  949. .set_parent = genclk_set_parent,
  950. .index = 7,
  951. };
  952. struct platform_device *__init
  953. at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
  954. unsigned long fbmem_start, unsigned long fbmem_len)
  955. {
  956. struct platform_device *pdev;
  957. struct atmel_lcdfb_info *info;
  958. struct fb_monspecs *monspecs;
  959. struct fb_videomode *modedb;
  960. unsigned int modedb_size;
  961. /*
  962. * Do a deep copy of the fb data, monspecs and modedb. Make
  963. * sure all allocations are done before setting up the
  964. * portmux.
  965. */
  966. monspecs = kmemdup(data->default_monspecs,
  967. sizeof(struct fb_monspecs), GFP_KERNEL);
  968. if (!monspecs)
  969. return NULL;
  970. modedb_size = sizeof(struct fb_videomode) * monspecs->modedb_len;
  971. modedb = kmemdup(monspecs->modedb, modedb_size, GFP_KERNEL);
  972. if (!modedb)
  973. goto err_dup_modedb;
  974. monspecs->modedb = modedb;
  975. switch (id) {
  976. case 0:
  977. pdev = &atmel_lcdfb0_device;
  978. select_peripheral(PC(19), PERIPH_A, 0); /* CC */
  979. select_peripheral(PC(20), PERIPH_A, 0); /* HSYNC */
  980. select_peripheral(PC(21), PERIPH_A, 0); /* PCLK */
  981. select_peripheral(PC(22), PERIPH_A, 0); /* VSYNC */
  982. select_peripheral(PC(23), PERIPH_A, 0); /* DVAL */
  983. select_peripheral(PC(24), PERIPH_A, 0); /* MODE */
  984. select_peripheral(PC(25), PERIPH_A, 0); /* PWR */
  985. select_peripheral(PC(26), PERIPH_A, 0); /* DATA0 */
  986. select_peripheral(PC(27), PERIPH_A, 0); /* DATA1 */
  987. select_peripheral(PC(28), PERIPH_A, 0); /* DATA2 */
  988. select_peripheral(PC(29), PERIPH_A, 0); /* DATA3 */
  989. select_peripheral(PC(30), PERIPH_A, 0); /* DATA4 */
  990. select_peripheral(PC(31), PERIPH_A, 0); /* DATA5 */
  991. select_peripheral(PD(0), PERIPH_A, 0); /* DATA6 */
  992. select_peripheral(PD(1), PERIPH_A, 0); /* DATA7 */
  993. select_peripheral(PD(2), PERIPH_A, 0); /* DATA8 */
  994. select_peripheral(PD(3), PERIPH_A, 0); /* DATA9 */
  995. select_peripheral(PD(4), PERIPH_A, 0); /* DATA10 */
  996. select_peripheral(PD(5), PERIPH_A, 0); /* DATA11 */
  997. select_peripheral(PD(6), PERIPH_A, 0); /* DATA12 */
  998. select_peripheral(PD(7), PERIPH_A, 0); /* DATA13 */
  999. select_peripheral(PD(8), PERIPH_A, 0); /* DATA14 */
  1000. select_peripheral(PD(9), PERIPH_A, 0); /* DATA15 */
  1001. select_peripheral(PD(10), PERIPH_A, 0); /* DATA16 */
  1002. select_peripheral(PD(11), PERIPH_A, 0); /* DATA17 */
  1003. select_peripheral(PD(12), PERIPH_A, 0); /* DATA18 */
  1004. select_peripheral(PD(13), PERIPH_A, 0); /* DATA19 */
  1005. select_peripheral(PD(14), PERIPH_A, 0); /* DATA20 */
  1006. select_peripheral(PD(15), PERIPH_A, 0); /* DATA21 */
  1007. select_peripheral(PD(16), PERIPH_A, 0); /* DATA22 */
  1008. select_peripheral(PD(17), PERIPH_A, 0); /* DATA23 */
  1009. clk_set_parent(&atmel_lcdfb0_pixclk, &pll0);
  1010. clk_set_rate(&atmel_lcdfb0_pixclk, clk_get_rate(&pll0));
  1011. break;
  1012. default:
  1013. goto err_invalid_id;
  1014. }
  1015. if (fbmem_len) {
  1016. pdev->resource[2].start = fbmem_start;
  1017. pdev->resource[2].end = fbmem_start + fbmem_len - 1;
  1018. pdev->resource[2].flags = IORESOURCE_MEM;
  1019. }
  1020. info = pdev->dev.platform_data;
  1021. memcpy(info, data, sizeof(struct atmel_lcdfb_info));
  1022. info->default_monspecs = monspecs;
  1023. platform_device_register(pdev);
  1024. return pdev;
  1025. err_invalid_id:
  1026. kfree(modedb);
  1027. err_dup_modedb:
  1028. kfree(monspecs);
  1029. return NULL;
  1030. }
  1031. #endif
  1032. /* --------------------------------------------------------------------
  1033. * PWM
  1034. * -------------------------------------------------------------------- */
  1035. static struct resource atmel_pwm0_resource[] __initdata = {
  1036. PBMEM(0xfff01400),
  1037. IRQ(24),
  1038. };
  1039. static struct clk atmel_pwm0_mck = {
  1040. .name = "mck",
  1041. .parent = &pbb_clk,
  1042. .mode = pbb_clk_mode,
  1043. .get_rate = pbb_clk_get_rate,
  1044. .index = 5,
  1045. };
  1046. struct platform_device *__init at32_add_device_pwm(u32 mask)
  1047. {
  1048. struct platform_device *pdev;
  1049. if (!mask)
  1050. return NULL;
  1051. pdev = platform_device_alloc("atmel_pwm", 0);
  1052. if (!pdev)
  1053. return NULL;
  1054. if (platform_device_add_resources(pdev, atmel_pwm0_resource,
  1055. ARRAY_SIZE(atmel_pwm0_resource)))
  1056. goto out_free_pdev;
  1057. if (platform_device_add_data(pdev, &mask, sizeof(mask)))
  1058. goto out_free_pdev;
  1059. if (mask & (1 << 0))
  1060. select_peripheral(PA(28), PERIPH_A, 0);
  1061. if (mask & (1 << 1))
  1062. select_peripheral(PA(29), PERIPH_A, 0);
  1063. if (mask & (1 << 2))
  1064. select_peripheral(PA(21), PERIPH_B, 0);
  1065. if (mask & (1 << 3))
  1066. select_peripheral(PA(22), PERIPH_B, 0);
  1067. atmel_pwm0_mck.dev = &pdev->dev;
  1068. platform_device_add(pdev);
  1069. return pdev;
  1070. out_free_pdev:
  1071. platform_device_put(pdev);
  1072. return NULL;
  1073. }
  1074. /* --------------------------------------------------------------------
  1075. * SSC
  1076. * -------------------------------------------------------------------- */
  1077. static struct resource ssc0_resource[] = {
  1078. PBMEM(0xffe01c00),
  1079. IRQ(10),
  1080. };
  1081. DEFINE_DEV(ssc, 0);
  1082. DEV_CLK(pclk, ssc0, pba, 7);
  1083. static struct resource ssc1_resource[] = {
  1084. PBMEM(0xffe02000),
  1085. IRQ(11),
  1086. };
  1087. DEFINE_DEV(ssc, 1);
  1088. DEV_CLK(pclk, ssc1, pba, 8);
  1089. static struct resource ssc2_resource[] = {
  1090. PBMEM(0xffe02400),
  1091. IRQ(12),
  1092. };
  1093. DEFINE_DEV(ssc, 2);
  1094. DEV_CLK(pclk, ssc2, pba, 9);
  1095. struct platform_device *__init
  1096. at32_add_device_ssc(unsigned int id, unsigned int flags)
  1097. {
  1098. struct platform_device *pdev;
  1099. switch (id) {
  1100. case 0:
  1101. pdev = &ssc0_device;
  1102. if (flags & ATMEL_SSC_RF)
  1103. select_peripheral(PA(21), PERIPH_A, 0); /* RF */
  1104. if (flags & ATMEL_SSC_RK)
  1105. select_peripheral(PA(22), PERIPH_A, 0); /* RK */
  1106. if (flags & ATMEL_SSC_TK)
  1107. select_peripheral(PA(23), PERIPH_A, 0); /* TK */
  1108. if (flags & ATMEL_SSC_TF)
  1109. select_peripheral(PA(24), PERIPH_A, 0); /* TF */
  1110. if (flags & ATMEL_SSC_TD)
  1111. select_peripheral(PA(25), PERIPH_A, 0); /* TD */
  1112. if (flags & ATMEL_SSC_RD)
  1113. select_peripheral(PA(26), PERIPH_A, 0); /* RD */
  1114. break;
  1115. case 1:
  1116. pdev = &ssc1_device;
  1117. if (flags & ATMEL_SSC_RF)
  1118. select_peripheral(PA(0), PERIPH_B, 0); /* RF */
  1119. if (flags & ATMEL_SSC_RK)
  1120. select_peripheral(PA(1), PERIPH_B, 0); /* RK */
  1121. if (flags & ATMEL_SSC_TK)
  1122. select_peripheral(PA(2), PERIPH_B, 0); /* TK */
  1123. if (flags & ATMEL_SSC_TF)
  1124. select_peripheral(PA(3), PERIPH_B, 0); /* TF */
  1125. if (flags & ATMEL_SSC_TD)
  1126. select_peripheral(PA(4), PERIPH_B, 0); /* TD */
  1127. if (flags & ATMEL_SSC_RD)
  1128. select_peripheral(PA(5), PERIPH_B, 0); /* RD */
  1129. break;
  1130. case 2:
  1131. pdev = &ssc2_device;
  1132. if (flags & ATMEL_SSC_TD)
  1133. select_peripheral(PB(13), PERIPH_A, 0); /* TD */
  1134. if (flags & ATMEL_SSC_RD)
  1135. select_peripheral(PB(14), PERIPH_A, 0); /* RD */
  1136. if (flags & ATMEL_SSC_TK)
  1137. select_peripheral(PB(15), PERIPH_A, 0); /* TK */
  1138. if (flags & ATMEL_SSC_TF)
  1139. select_peripheral(PB(16), PERIPH_A, 0); /* TF */
  1140. if (flags & ATMEL_SSC_RF)
  1141. select_peripheral(PB(17), PERIPH_A, 0); /* RF */
  1142. if (flags & ATMEL_SSC_RK)
  1143. select_peripheral(PB(18), PERIPH_A, 0); /* RK */
  1144. break;
  1145. default:
  1146. return NULL;
  1147. }
  1148. platform_device_register(pdev);
  1149. return pdev;
  1150. }
  1151. /* --------------------------------------------------------------------
  1152. * USB Device Controller
  1153. * -------------------------------------------------------------------- */
  1154. static struct resource usba0_resource[] __initdata = {
  1155. {
  1156. .start = 0xff300000,
  1157. .end = 0xff3fffff,
  1158. .flags = IORESOURCE_MEM,
  1159. }, {
  1160. .start = 0xfff03000,
  1161. .end = 0xfff033ff,
  1162. .flags = IORESOURCE_MEM,
  1163. },
  1164. IRQ(31),
  1165. };
  1166. static struct clk usba0_pclk = {
  1167. .name = "pclk",
  1168. .parent = &pbb_clk,
  1169. .mode = pbb_clk_mode,
  1170. .get_rate = pbb_clk_get_rate,
  1171. .index = 12,
  1172. };
  1173. static struct clk usba0_hclk = {
  1174. .name = "hclk",
  1175. .parent = &hsb_clk,
  1176. .mode = hsb_clk_mode,
  1177. .get_rate = hsb_clk_get_rate,
  1178. .index = 6,
  1179. };
  1180. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  1181. [idx] = { \
  1182. .name = nam, \
  1183. .index = idx, \
  1184. .fifo_size = maxpkt, \
  1185. .nr_banks = maxbk, \
  1186. .can_dma = dma, \
  1187. .can_isoc = isoc, \
  1188. }
  1189. static struct usba_ep_data at32_usba_ep[] __initdata = {
  1190. EP("ep0", 0, 64, 1, 0, 0),
  1191. EP("ep1", 1, 512, 2, 1, 1),
  1192. EP("ep2", 2, 512, 2, 1, 1),
  1193. EP("ep3-int", 3, 64, 3, 1, 0),
  1194. EP("ep4-int", 4, 64, 3, 1, 0),
  1195. EP("ep5", 5, 1024, 3, 1, 1),
  1196. EP("ep6", 6, 1024, 3, 1, 1),
  1197. };
  1198. #undef EP
  1199. struct platform_device *__init
  1200. at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
  1201. {
  1202. /*
  1203. * pdata doesn't have room for any endpoints, so we need to
  1204. * append room for the ones we need right after it.
  1205. */
  1206. struct {
  1207. struct usba_platform_data pdata;
  1208. struct usba_ep_data ep[7];
  1209. } usba_data;
  1210. struct platform_device *pdev;
  1211. if (id != 0)
  1212. return NULL;
  1213. pdev = platform_device_alloc("atmel_usba_udc", 0);
  1214. if (!pdev)
  1215. return NULL;
  1216. if (platform_device_add_resources(pdev, usba0_resource,
  1217. ARRAY_SIZE(usba0_resource)))
  1218. goto out_free_pdev;
  1219. if (data)
  1220. usba_data.pdata.vbus_pin = data->vbus_pin;
  1221. else
  1222. usba_data.pdata.vbus_pin = -EINVAL;
  1223. data = &usba_data.pdata;
  1224. data->num_ep = ARRAY_SIZE(at32_usba_ep);
  1225. memcpy(data->ep, at32_usba_ep, sizeof(at32_usba_ep));
  1226. if (platform_device_add_data(pdev, data, sizeof(usba_data)))
  1227. goto out_free_pdev;
  1228. if (data->vbus_pin >= 0)
  1229. at32_select_gpio(data->vbus_pin, 0);
  1230. usba0_pclk.dev = &pdev->dev;
  1231. usba0_hclk.dev = &pdev->dev;
  1232. platform_device_add(pdev);
  1233. return pdev;
  1234. out_free_pdev:
  1235. platform_device_put(pdev);
  1236. return NULL;
  1237. }
  1238. /* --------------------------------------------------------------------
  1239. * IDE / CompactFlash
  1240. * -------------------------------------------------------------------- */
  1241. #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7001)
  1242. static struct resource at32_smc_cs4_resource[] __initdata = {
  1243. {
  1244. .start = 0x04000000,
  1245. .end = 0x07ffffff,
  1246. .flags = IORESOURCE_MEM,
  1247. },
  1248. IRQ(~0UL), /* Magic IRQ will be overridden */
  1249. };
  1250. static struct resource at32_smc_cs5_resource[] __initdata = {
  1251. {
  1252. .start = 0x20000000,
  1253. .end = 0x23ffffff,
  1254. .flags = IORESOURCE_MEM,
  1255. },
  1256. IRQ(~0UL), /* Magic IRQ will be overridden */
  1257. };
  1258. static int __init at32_init_ide_or_cf(struct platform_device *pdev,
  1259. unsigned int cs, unsigned int extint)
  1260. {
  1261. static unsigned int extint_pin_map[4] __initdata = {
  1262. GPIO_PIN_PB(25),
  1263. GPIO_PIN_PB(26),
  1264. GPIO_PIN_PB(27),
  1265. GPIO_PIN_PB(28),
  1266. };
  1267. static bool common_pins_initialized __initdata = false;
  1268. unsigned int extint_pin;
  1269. int ret;
  1270. if (extint >= ARRAY_SIZE(extint_pin_map))
  1271. return -EINVAL;
  1272. extint_pin = extint_pin_map[extint];
  1273. switch (cs) {
  1274. case 4:
  1275. ret = platform_device_add_resources(pdev,
  1276. at32_smc_cs4_resource,
  1277. ARRAY_SIZE(at32_smc_cs4_resource));
  1278. if (ret)
  1279. return ret;
  1280. select_peripheral(PE(21), PERIPH_A, 0); /* NCS4 -> OE_N */
  1281. set_ebi_sfr_bits(HMATRIX_BIT(CS4A));
  1282. break;
  1283. case 5:
  1284. ret = platform_device_add_resources(pdev,
  1285. at32_smc_cs5_resource,
  1286. ARRAY_SIZE(at32_smc_cs5_resource));
  1287. if (ret)
  1288. return ret;
  1289. select_peripheral(PE(22), PERIPH_A, 0); /* NCS5 -> OE_N */
  1290. set_ebi_sfr_bits(HMATRIX_BIT(CS5A));
  1291. break;
  1292. default:
  1293. return -EINVAL;
  1294. }
  1295. if (!common_pins_initialized) {
  1296. select_peripheral(PE(19), PERIPH_A, 0); /* CFCE1 -> CS0_N */
  1297. select_peripheral(PE(20), PERIPH_A, 0); /* CFCE2 -> CS1_N */
  1298. select_peripheral(PE(23), PERIPH_A, 0); /* CFRNW -> DIR */
  1299. select_peripheral(PE(24), PERIPH_A, 0); /* NWAIT <- IORDY */
  1300. common_pins_initialized = true;
  1301. }
  1302. at32_select_periph(extint_pin, GPIO_PERIPH_A, AT32_GPIOF_DEGLITCH);
  1303. pdev->resource[1].start = EIM_IRQ_BASE + extint;
  1304. pdev->resource[1].end = pdev->resource[1].start;
  1305. return 0;
  1306. }
  1307. struct platform_device *__init
  1308. at32_add_device_ide(unsigned int id, unsigned int extint,
  1309. struct ide_platform_data *data)
  1310. {
  1311. struct platform_device *pdev;
  1312. pdev = platform_device_alloc("at32_ide", id);
  1313. if (!pdev)
  1314. goto fail;
  1315. if (platform_device_add_data(pdev, data,
  1316. sizeof(struct ide_platform_data)))
  1317. goto fail;
  1318. if (at32_init_ide_or_cf(pdev, data->cs, extint))
  1319. goto fail;
  1320. platform_device_add(pdev);
  1321. return pdev;
  1322. fail:
  1323. platform_device_put(pdev);
  1324. return NULL;
  1325. }
  1326. struct platform_device *__init
  1327. at32_add_device_cf(unsigned int id, unsigned int extint,
  1328. struct cf_platform_data *data)
  1329. {
  1330. struct platform_device *pdev;
  1331. pdev = platform_device_alloc("at32_cf", id);
  1332. if (!pdev)
  1333. goto fail;
  1334. if (platform_device_add_data(pdev, data,
  1335. sizeof(struct cf_platform_data)))
  1336. goto fail;
  1337. if (at32_init_ide_or_cf(pdev, data->cs, extint))
  1338. goto fail;
  1339. if (data->detect_pin != GPIO_PIN_NONE)
  1340. at32_select_gpio(data->detect_pin, AT32_GPIOF_DEGLITCH);
  1341. if (data->reset_pin != GPIO_PIN_NONE)
  1342. at32_select_gpio(data->reset_pin, 0);
  1343. if (data->vcc_pin != GPIO_PIN_NONE)
  1344. at32_select_gpio(data->vcc_pin, 0);
  1345. /* READY is used as extint, so we can't select it as gpio */
  1346. platform_device_add(pdev);
  1347. return pdev;
  1348. fail:
  1349. platform_device_put(pdev);
  1350. return NULL;
  1351. }
  1352. #endif
  1353. /* --------------------------------------------------------------------
  1354. * AC97C
  1355. * -------------------------------------------------------------------- */
  1356. static struct resource atmel_ac97c0_resource[] __initdata = {
  1357. PBMEM(0xfff02800),
  1358. IRQ(29),
  1359. };
  1360. static struct clk atmel_ac97c0_pclk = {
  1361. .name = "pclk",
  1362. .parent = &pbb_clk,
  1363. .mode = pbb_clk_mode,
  1364. .get_rate = pbb_clk_get_rate,
  1365. .index = 10,
  1366. };
  1367. struct platform_device *__init at32_add_device_ac97c(unsigned int id)
  1368. {
  1369. struct platform_device *pdev;
  1370. if (id != 0)
  1371. return NULL;
  1372. pdev = platform_device_alloc("atmel_ac97c", id);
  1373. if (!pdev)
  1374. return NULL;
  1375. if (platform_device_add_resources(pdev, atmel_ac97c0_resource,
  1376. ARRAY_SIZE(atmel_ac97c0_resource)))
  1377. goto err_add_resources;
  1378. select_peripheral(PB(20), PERIPH_B, 0); /* SYNC */
  1379. select_peripheral(PB(21), PERIPH_B, 0); /* SDO */
  1380. select_peripheral(PB(22), PERIPH_B, 0); /* SDI */
  1381. select_peripheral(PB(23), PERIPH_B, 0); /* SCLK */
  1382. atmel_ac97c0_pclk.dev = &pdev->dev;
  1383. platform_device_add(pdev);
  1384. return pdev;
  1385. err_add_resources:
  1386. platform_device_put(pdev);
  1387. return NULL;
  1388. }
  1389. /* --------------------------------------------------------------------
  1390. * ABDAC
  1391. * -------------------------------------------------------------------- */
  1392. static struct resource abdac0_resource[] __initdata = {
  1393. PBMEM(0xfff02000),
  1394. IRQ(27),
  1395. };
  1396. static struct clk abdac0_pclk = {
  1397. .name = "pclk",
  1398. .parent = &pbb_clk,
  1399. .mode = pbb_clk_mode,
  1400. .get_rate = pbb_clk_get_rate,
  1401. .index = 8,
  1402. };
  1403. static struct clk abdac0_sample_clk = {
  1404. .name = "sample_clk",
  1405. .mode = genclk_mode,
  1406. .get_rate = genclk_get_rate,
  1407. .set_rate = genclk_set_rate,
  1408. .set_parent = genclk_set_parent,
  1409. .index = 6,
  1410. };
  1411. struct platform_device *__init at32_add_device_abdac(unsigned int id)
  1412. {
  1413. struct platform_device *pdev;
  1414. if (id != 0)
  1415. return NULL;
  1416. pdev = platform_device_alloc("abdac", id);
  1417. if (!pdev)
  1418. return NULL;
  1419. if (platform_device_add_resources(pdev, abdac0_resource,
  1420. ARRAY_SIZE(abdac0_resource)))
  1421. goto err_add_resources;
  1422. select_peripheral(PB(20), PERIPH_A, 0); /* DATA1 */
  1423. select_peripheral(PB(21), PERIPH_A, 0); /* DATA0 */
  1424. select_peripheral(PB(22), PERIPH_A, 0); /* DATAN1 */
  1425. select_peripheral(PB(23), PERIPH_A, 0); /* DATAN0 */
  1426. abdac0_pclk.dev = &pdev->dev;
  1427. abdac0_sample_clk.dev = &pdev->dev;
  1428. platform_device_add(pdev);
  1429. return pdev;
  1430. err_add_resources:
  1431. platform_device_put(pdev);
  1432. return NULL;
  1433. }
  1434. /* --------------------------------------------------------------------
  1435. * GCLK
  1436. * -------------------------------------------------------------------- */
  1437. static struct clk gclk0 = {
  1438. .name = "gclk0",
  1439. .mode = genclk_mode,
  1440. .get_rate = genclk_get_rate,
  1441. .set_rate = genclk_set_rate,
  1442. .set_parent = genclk_set_parent,
  1443. .index = 0,
  1444. };
  1445. static struct clk gclk1 = {
  1446. .name = "gclk1",
  1447. .mode = genclk_mode,
  1448. .get_rate = genclk_get_rate,
  1449. .set_rate = genclk_set_rate,
  1450. .set_parent = genclk_set_parent,
  1451. .index = 1,
  1452. };
  1453. static struct clk gclk2 = {
  1454. .name = "gclk2",
  1455. .mode = genclk_mode,
  1456. .get_rate = genclk_get_rate,
  1457. .set_rate = genclk_set_rate,
  1458. .set_parent = genclk_set_parent,
  1459. .index = 2,
  1460. };
  1461. static struct clk gclk3 = {
  1462. .name = "gclk3",
  1463. .mode = genclk_mode,
  1464. .get_rate = genclk_get_rate,
  1465. .set_rate = genclk_set_rate,
  1466. .set_parent = genclk_set_parent,
  1467. .index = 3,
  1468. };
  1469. static struct clk gclk4 = {
  1470. .name = "gclk4",
  1471. .mode = genclk_mode,
  1472. .get_rate = genclk_get_rate,
  1473. .set_rate = genclk_set_rate,
  1474. .set_parent = genclk_set_parent,
  1475. .index = 4,
  1476. };
  1477. struct clk *at32_clock_list[] = {
  1478. &osc32k,
  1479. &osc0,
  1480. &osc1,
  1481. &pll0,
  1482. &pll1,
  1483. &cpu_clk,
  1484. &hsb_clk,
  1485. &pba_clk,
  1486. &pbb_clk,
  1487. &at32_pm_pclk,
  1488. &at32_intc0_pclk,
  1489. &hmatrix_clk,
  1490. &ebi_clk,
  1491. &hramc_clk,
  1492. &smc0_pclk,
  1493. &smc0_mck,
  1494. &pdc_hclk,
  1495. &pdc_pclk,
  1496. &dmaca0_hclk,
  1497. &pico_clk,
  1498. &pio0_mck,
  1499. &pio1_mck,
  1500. &pio2_mck,
  1501. &pio3_mck,
  1502. &pio4_mck,
  1503. &at32_tcb0_t0_clk,
  1504. &at32_tcb1_t0_clk,
  1505. &atmel_usart0_usart,
  1506. &atmel_usart1_usart,
  1507. &atmel_usart2_usart,
  1508. &atmel_usart3_usart,
  1509. &atmel_pwm0_mck,
  1510. #if defined(CONFIG_CPU_AT32AP7000)
  1511. &macb0_hclk,
  1512. &macb0_pclk,
  1513. &macb1_hclk,
  1514. &macb1_pclk,
  1515. #endif
  1516. &atmel_spi0_spi_clk,
  1517. &atmel_spi1_spi_clk,
  1518. &atmel_twi0_pclk,
  1519. &atmel_mci0_pclk,
  1520. #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
  1521. &atmel_lcdfb0_hck1,
  1522. &atmel_lcdfb0_pixclk,
  1523. #endif
  1524. &ssc0_pclk,
  1525. &ssc1_pclk,
  1526. &ssc2_pclk,
  1527. &usba0_hclk,
  1528. &usba0_pclk,
  1529. &atmel_ac97c0_pclk,
  1530. &abdac0_pclk,
  1531. &abdac0_sample_clk,
  1532. &gclk0,
  1533. &gclk1,
  1534. &gclk2,
  1535. &gclk3,
  1536. &gclk4,
  1537. };
  1538. unsigned int at32_nr_clocks = ARRAY_SIZE(at32_clock_list);
  1539. void __init at32_portmux_init(void)
  1540. {
  1541. at32_init_pio(&pio0_device);
  1542. at32_init_pio(&pio1_device);
  1543. at32_init_pio(&pio2_device);
  1544. at32_init_pio(&pio3_device);
  1545. at32_init_pio(&pio4_device);
  1546. }
  1547. void __init at32_clock_init(void)
  1548. {
  1549. u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
  1550. int i;
  1551. if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) {
  1552. main_clock = &pll0;
  1553. cpu_clk.parent = &pll0;
  1554. } else {
  1555. main_clock = &osc0;
  1556. cpu_clk.parent = &osc0;
  1557. }
  1558. if (pm_readl(PLL0) & PM_BIT(PLLOSC))
  1559. pll0.parent = &osc1;
  1560. if (pm_readl(PLL1) & PM_BIT(PLLOSC))
  1561. pll1.parent = &osc1;
  1562. genclk_init_parent(&gclk0);
  1563. genclk_init_parent(&gclk1);
  1564. genclk_init_parent(&gclk2);
  1565. genclk_init_parent(&gclk3);
  1566. genclk_init_parent(&gclk4);
  1567. #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
  1568. genclk_init_parent(&atmel_lcdfb0_pixclk);
  1569. #endif
  1570. genclk_init_parent(&abdac0_sample_clk);
  1571. /*
  1572. * Turn on all clocks that have at least one user already, and
  1573. * turn off everything else. We only do this for module
  1574. * clocks, and even though it isn't particularly pretty to
  1575. * check the address of the mode function, it should do the
  1576. * trick...
  1577. */
  1578. for (i = 0; i < ARRAY_SIZE(at32_clock_list); i++) {
  1579. struct clk *clk = at32_clock_list[i];
  1580. if (clk->users == 0)
  1581. continue;
  1582. if (clk->mode == &cpu_clk_mode)
  1583. cpu_mask |= 1 << clk->index;
  1584. else if (clk->mode == &hsb_clk_mode)
  1585. hsb_mask |= 1 << clk->index;
  1586. else if (clk->mode == &pba_clk_mode)
  1587. pba_mask |= 1 << clk->index;
  1588. else if (clk->mode == &pbb_clk_mode)
  1589. pbb_mask |= 1 << clk->index;
  1590. }
  1591. pm_writel(CPU_MASK, cpu_mask);
  1592. pm_writel(HSB_MASK, hsb_mask);
  1593. pm_writel(PBA_MASK, pba_mask);
  1594. pm_writel(PBB_MASK, pbb_mask);
  1595. }