at32ap7000.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  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 <asm/io.h>
  15. #include <asm/arch/at32ap7000.h>
  16. #include <asm/arch/board.h>
  17. #include <asm/arch/portmux.h>
  18. #include <video/atmel_lcdc.h>
  19. #include "clock.h"
  20. #include "hmatrix.h"
  21. #include "pio.h"
  22. #include "pm.h"
  23. /*
  24. * We can reduce the code size a bit by using a constant here. Since
  25. * this file is completely chip-specific, it's safe to not use
  26. * ioremap. Generic drivers should of course never do this.
  27. */
  28. #define AT32_PM_BASE 0xfff00000
  29. #define PBMEM(base) \
  30. { \
  31. .start = base, \
  32. .end = base + 0x3ff, \
  33. .flags = IORESOURCE_MEM, \
  34. }
  35. #define IRQ(num) \
  36. { \
  37. .start = num, \
  38. .end = num, \
  39. .flags = IORESOURCE_IRQ, \
  40. }
  41. #define NAMED_IRQ(num, _name) \
  42. { \
  43. .start = num, \
  44. .end = num, \
  45. .name = _name, \
  46. .flags = IORESOURCE_IRQ, \
  47. }
  48. /* REVISIT these assume *every* device supports DMA, but several
  49. * don't ... tc, smc, pio, rtc, watchdog, pwm, ps2, and more.
  50. */
  51. #define DEFINE_DEV(_name, _id) \
  52. static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \
  53. static struct platform_device _name##_id##_device = { \
  54. .name = #_name, \
  55. .id = _id, \
  56. .dev = { \
  57. .dma_mask = &_name##_id##_dma_mask, \
  58. .coherent_dma_mask = DMA_32BIT_MASK, \
  59. }, \
  60. .resource = _name##_id##_resource, \
  61. .num_resources = ARRAY_SIZE(_name##_id##_resource), \
  62. }
  63. #define DEFINE_DEV_DATA(_name, _id) \
  64. static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \
  65. static struct platform_device _name##_id##_device = { \
  66. .name = #_name, \
  67. .id = _id, \
  68. .dev = { \
  69. .dma_mask = &_name##_id##_dma_mask, \
  70. .platform_data = &_name##_id##_data, \
  71. .coherent_dma_mask = DMA_32BIT_MASK, \
  72. }, \
  73. .resource = _name##_id##_resource, \
  74. .num_resources = ARRAY_SIZE(_name##_id##_resource), \
  75. }
  76. #define select_peripheral(pin, periph, flags) \
  77. at32_select_periph(GPIO_PIN_##pin, GPIO_##periph, flags)
  78. #define DEV_CLK(_name, devname, bus, _index) \
  79. static struct clk devname##_##_name = { \
  80. .name = #_name, \
  81. .dev = &devname##_device.dev, \
  82. .parent = &bus##_clk, \
  83. .mode = bus##_clk_mode, \
  84. .get_rate = bus##_clk_get_rate, \
  85. .index = _index, \
  86. }
  87. static DEFINE_SPINLOCK(pm_lock);
  88. unsigned long at32ap7000_osc_rates[3] = {
  89. [0] = 32768,
  90. /* FIXME: these are ATSTK1002-specific */
  91. [1] = 20000000,
  92. [2] = 12000000,
  93. };
  94. static unsigned long osc_get_rate(struct clk *clk)
  95. {
  96. return at32ap7000_osc_rates[clk->index];
  97. }
  98. static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
  99. {
  100. unsigned long div, mul, rate;
  101. if (!(control & PM_BIT(PLLEN)))
  102. return 0;
  103. div = PM_BFEXT(PLLDIV, control) + 1;
  104. mul = PM_BFEXT(PLLMUL, control) + 1;
  105. rate = clk->parent->get_rate(clk->parent);
  106. rate = (rate + div / 2) / div;
  107. rate *= mul;
  108. return rate;
  109. }
  110. static unsigned long pll0_get_rate(struct clk *clk)
  111. {
  112. u32 control;
  113. control = pm_readl(PLL0);
  114. return pll_get_rate(clk, control);
  115. }
  116. static unsigned long pll1_get_rate(struct clk *clk)
  117. {
  118. u32 control;
  119. control = pm_readl(PLL1);
  120. return pll_get_rate(clk, control);
  121. }
  122. /*
  123. * The AT32AP7000 has five primary clock sources: One 32kHz
  124. * oscillator, two crystal oscillators and two PLLs.
  125. */
  126. static struct clk osc32k = {
  127. .name = "osc32k",
  128. .get_rate = osc_get_rate,
  129. .users = 1,
  130. .index = 0,
  131. };
  132. static struct clk osc0 = {
  133. .name = "osc0",
  134. .get_rate = osc_get_rate,
  135. .users = 1,
  136. .index = 1,
  137. };
  138. static struct clk osc1 = {
  139. .name = "osc1",
  140. .get_rate = osc_get_rate,
  141. .index = 2,
  142. };
  143. static struct clk pll0 = {
  144. .name = "pll0",
  145. .get_rate = pll0_get_rate,
  146. .parent = &osc0,
  147. };
  148. static struct clk pll1 = {
  149. .name = "pll1",
  150. .get_rate = pll1_get_rate,
  151. .parent = &osc0,
  152. };
  153. /*
  154. * The main clock can be either osc0 or pll0. The boot loader may
  155. * have chosen one for us, so we don't really know which one until we
  156. * have a look at the SM.
  157. */
  158. static struct clk *main_clock;
  159. /*
  160. * Synchronous clocks are generated from the main clock. The clocks
  161. * must satisfy the constraint
  162. * fCPU >= fHSB >= fPB
  163. * i.e. each clock must not be faster than its parent.
  164. */
  165. static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift)
  166. {
  167. return main_clock->get_rate(main_clock) >> shift;
  168. };
  169. static void cpu_clk_mode(struct clk *clk, int enabled)
  170. {
  171. unsigned long flags;
  172. u32 mask;
  173. spin_lock_irqsave(&pm_lock, flags);
  174. mask = pm_readl(CPU_MASK);
  175. if (enabled)
  176. mask |= 1 << clk->index;
  177. else
  178. mask &= ~(1 << clk->index);
  179. pm_writel(CPU_MASK, mask);
  180. spin_unlock_irqrestore(&pm_lock, flags);
  181. }
  182. static unsigned long cpu_clk_get_rate(struct clk *clk)
  183. {
  184. unsigned long cksel, shift = 0;
  185. cksel = pm_readl(CKSEL);
  186. if (cksel & PM_BIT(CPUDIV))
  187. shift = PM_BFEXT(CPUSEL, cksel) + 1;
  188. return bus_clk_get_rate(clk, shift);
  189. }
  190. static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
  191. {
  192. u32 control;
  193. unsigned long parent_rate, child_div, actual_rate, div;
  194. parent_rate = clk->parent->get_rate(clk->parent);
  195. control = pm_readl(CKSEL);
  196. if (control & PM_BIT(HSBDIV))
  197. child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
  198. else
  199. child_div = 1;
  200. if (rate > 3 * (parent_rate / 4) || child_div == 1) {
  201. actual_rate = parent_rate;
  202. control &= ~PM_BIT(CPUDIV);
  203. } else {
  204. unsigned int cpusel;
  205. div = (parent_rate + rate / 2) / rate;
  206. if (div > child_div)
  207. div = child_div;
  208. cpusel = (div > 1) ? (fls(div) - 2) : 0;
  209. control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control);
  210. actual_rate = parent_rate / (1 << (cpusel + 1));
  211. }
  212. pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
  213. clk->name, rate, actual_rate);
  214. if (apply)
  215. pm_writel(CKSEL, control);
  216. return actual_rate;
  217. }
  218. static void hsb_clk_mode(struct clk *clk, int enabled)
  219. {
  220. unsigned long flags;
  221. u32 mask;
  222. spin_lock_irqsave(&pm_lock, flags);
  223. mask = pm_readl(HSB_MASK);
  224. if (enabled)
  225. mask |= 1 << clk->index;
  226. else
  227. mask &= ~(1 << clk->index);
  228. pm_writel(HSB_MASK, mask);
  229. spin_unlock_irqrestore(&pm_lock, flags);
  230. }
  231. static unsigned long hsb_clk_get_rate(struct clk *clk)
  232. {
  233. unsigned long cksel, shift = 0;
  234. cksel = pm_readl(CKSEL);
  235. if (cksel & PM_BIT(HSBDIV))
  236. shift = PM_BFEXT(HSBSEL, cksel) + 1;
  237. return bus_clk_get_rate(clk, shift);
  238. }
  239. static void pba_clk_mode(struct clk *clk, int enabled)
  240. {
  241. unsigned long flags;
  242. u32 mask;
  243. spin_lock_irqsave(&pm_lock, flags);
  244. mask = pm_readl(PBA_MASK);
  245. if (enabled)
  246. mask |= 1 << clk->index;
  247. else
  248. mask &= ~(1 << clk->index);
  249. pm_writel(PBA_MASK, mask);
  250. spin_unlock_irqrestore(&pm_lock, flags);
  251. }
  252. static unsigned long pba_clk_get_rate(struct clk *clk)
  253. {
  254. unsigned long cksel, shift = 0;
  255. cksel = pm_readl(CKSEL);
  256. if (cksel & PM_BIT(PBADIV))
  257. shift = PM_BFEXT(PBASEL, cksel) + 1;
  258. return bus_clk_get_rate(clk, shift);
  259. }
  260. static void pbb_clk_mode(struct clk *clk, int enabled)
  261. {
  262. unsigned long flags;
  263. u32 mask;
  264. spin_lock_irqsave(&pm_lock, flags);
  265. mask = pm_readl(PBB_MASK);
  266. if (enabled)
  267. mask |= 1 << clk->index;
  268. else
  269. mask &= ~(1 << clk->index);
  270. pm_writel(PBB_MASK, mask);
  271. spin_unlock_irqrestore(&pm_lock, flags);
  272. }
  273. static unsigned long pbb_clk_get_rate(struct clk *clk)
  274. {
  275. unsigned long cksel, shift = 0;
  276. cksel = pm_readl(CKSEL);
  277. if (cksel & PM_BIT(PBBDIV))
  278. shift = PM_BFEXT(PBBSEL, cksel) + 1;
  279. return bus_clk_get_rate(clk, shift);
  280. }
  281. static struct clk cpu_clk = {
  282. .name = "cpu",
  283. .get_rate = cpu_clk_get_rate,
  284. .set_rate = cpu_clk_set_rate,
  285. .users = 1,
  286. };
  287. static struct clk hsb_clk = {
  288. .name = "hsb",
  289. .parent = &cpu_clk,
  290. .get_rate = hsb_clk_get_rate,
  291. };
  292. static struct clk pba_clk = {
  293. .name = "pba",
  294. .parent = &hsb_clk,
  295. .mode = hsb_clk_mode,
  296. .get_rate = pba_clk_get_rate,
  297. .index = 1,
  298. };
  299. static struct clk pbb_clk = {
  300. .name = "pbb",
  301. .parent = &hsb_clk,
  302. .mode = hsb_clk_mode,
  303. .get_rate = pbb_clk_get_rate,
  304. .users = 1,
  305. .index = 2,
  306. };
  307. /* --------------------------------------------------------------------
  308. * Generic Clock operations
  309. * -------------------------------------------------------------------- */
  310. static void genclk_mode(struct clk *clk, int enabled)
  311. {
  312. u32 control;
  313. control = pm_readl(GCCTRL(clk->index));
  314. if (enabled)
  315. control |= PM_BIT(CEN);
  316. else
  317. control &= ~PM_BIT(CEN);
  318. pm_writel(GCCTRL(clk->index), control);
  319. }
  320. static unsigned long genclk_get_rate(struct clk *clk)
  321. {
  322. u32 control;
  323. unsigned long div = 1;
  324. control = pm_readl(GCCTRL(clk->index));
  325. if (control & PM_BIT(DIVEN))
  326. div = 2 * (PM_BFEXT(DIV, control) + 1);
  327. return clk->parent->get_rate(clk->parent) / div;
  328. }
  329. static long genclk_set_rate(struct clk *clk, unsigned long rate, int apply)
  330. {
  331. u32 control;
  332. unsigned long parent_rate, actual_rate, div;
  333. parent_rate = clk->parent->get_rate(clk->parent);
  334. control = pm_readl(GCCTRL(clk->index));
  335. if (rate > 3 * parent_rate / 4) {
  336. actual_rate = parent_rate;
  337. control &= ~PM_BIT(DIVEN);
  338. } else {
  339. div = (parent_rate + rate) / (2 * rate) - 1;
  340. control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN);
  341. actual_rate = parent_rate / (2 * (div + 1));
  342. }
  343. dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n",
  344. clk->name, rate, actual_rate);
  345. if (apply)
  346. pm_writel(GCCTRL(clk->index), control);
  347. return actual_rate;
  348. }
  349. int genclk_set_parent(struct clk *clk, struct clk *parent)
  350. {
  351. u32 control;
  352. dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n",
  353. clk->name, parent->name, clk->parent->name);
  354. control = pm_readl(GCCTRL(clk->index));
  355. if (parent == &osc1 || parent == &pll1)
  356. control |= PM_BIT(OSCSEL);
  357. else if (parent == &osc0 || parent == &pll0)
  358. control &= ~PM_BIT(OSCSEL);
  359. else
  360. return -EINVAL;
  361. if (parent == &pll0 || parent == &pll1)
  362. control |= PM_BIT(PLLSEL);
  363. else
  364. control &= ~PM_BIT(PLLSEL);
  365. pm_writel(GCCTRL(clk->index), control);
  366. clk->parent = parent;
  367. return 0;
  368. }
  369. static void __init genclk_init_parent(struct clk *clk)
  370. {
  371. u32 control;
  372. struct clk *parent;
  373. BUG_ON(clk->index > 7);
  374. control = pm_readl(GCCTRL(clk->index));
  375. if (control & PM_BIT(OSCSEL))
  376. parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1;
  377. else
  378. parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
  379. clk->parent = parent;
  380. }
  381. /* --------------------------------------------------------------------
  382. * System peripherals
  383. * -------------------------------------------------------------------- */
  384. static struct resource at32_pm0_resource[] = {
  385. {
  386. .start = 0xfff00000,
  387. .end = 0xfff0007f,
  388. .flags = IORESOURCE_MEM,
  389. },
  390. IRQ(20),
  391. };
  392. static struct resource at32ap700x_rtc0_resource[] = {
  393. {
  394. .start = 0xfff00080,
  395. .end = 0xfff000af,
  396. .flags = IORESOURCE_MEM,
  397. },
  398. IRQ(21),
  399. };
  400. static struct resource at32_wdt0_resource[] = {
  401. {
  402. .start = 0xfff000b0,
  403. .end = 0xfff000bf,
  404. .flags = IORESOURCE_MEM,
  405. },
  406. };
  407. static struct resource at32_eic0_resource[] = {
  408. {
  409. .start = 0xfff00100,
  410. .end = 0xfff0013f,
  411. .flags = IORESOURCE_MEM,
  412. },
  413. IRQ(19),
  414. };
  415. DEFINE_DEV(at32_pm, 0);
  416. DEFINE_DEV(at32ap700x_rtc, 0);
  417. DEFINE_DEV(at32_wdt, 0);
  418. DEFINE_DEV(at32_eic, 0);
  419. /*
  420. * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
  421. * is always running.
  422. */
  423. static struct clk at32_pm_pclk = {
  424. .name = "pclk",
  425. .dev = &at32_pm0_device.dev,
  426. .parent = &pbb_clk,
  427. .mode = pbb_clk_mode,
  428. .get_rate = pbb_clk_get_rate,
  429. .users = 1,
  430. .index = 0,
  431. };
  432. static struct resource intc0_resource[] = {
  433. PBMEM(0xfff00400),
  434. };
  435. struct platform_device at32_intc0_device = {
  436. .name = "intc",
  437. .id = 0,
  438. .resource = intc0_resource,
  439. .num_resources = ARRAY_SIZE(intc0_resource),
  440. };
  441. DEV_CLK(pclk, at32_intc0, pbb, 1);
  442. static struct clk ebi_clk = {
  443. .name = "ebi",
  444. .parent = &hsb_clk,
  445. .mode = hsb_clk_mode,
  446. .get_rate = hsb_clk_get_rate,
  447. .users = 1,
  448. };
  449. static struct clk hramc_clk = {
  450. .name = "hramc",
  451. .parent = &hsb_clk,
  452. .mode = hsb_clk_mode,
  453. .get_rate = hsb_clk_get_rate,
  454. .users = 1,
  455. .index = 3,
  456. };
  457. static struct resource smc0_resource[] = {
  458. PBMEM(0xfff03400),
  459. };
  460. DEFINE_DEV(smc, 0);
  461. DEV_CLK(pclk, smc0, pbb, 13);
  462. DEV_CLK(mck, smc0, hsb, 0);
  463. static struct platform_device pdc_device = {
  464. .name = "pdc",
  465. .id = 0,
  466. };
  467. DEV_CLK(hclk, pdc, hsb, 4);
  468. DEV_CLK(pclk, pdc, pba, 16);
  469. static struct clk pico_clk = {
  470. .name = "pico",
  471. .parent = &cpu_clk,
  472. .mode = cpu_clk_mode,
  473. .get_rate = cpu_clk_get_rate,
  474. .users = 1,
  475. };
  476. /* --------------------------------------------------------------------
  477. * HMATRIX
  478. * -------------------------------------------------------------------- */
  479. static struct clk hmatrix_clk = {
  480. .name = "hmatrix_clk",
  481. .parent = &pbb_clk,
  482. .mode = pbb_clk_mode,
  483. .get_rate = pbb_clk_get_rate,
  484. .index = 2,
  485. .users = 1,
  486. };
  487. #define HMATRIX_BASE ((void __iomem *)0xfff00800)
  488. #define hmatrix_readl(reg) \
  489. __raw_readl((HMATRIX_BASE) + HMATRIX_##reg)
  490. #define hmatrix_writel(reg,value) \
  491. __raw_writel((value), (HMATRIX_BASE) + HMATRIX_##reg)
  492. /*
  493. * Set bits in the HMATRIX Special Function Register (SFR) used by the
  494. * External Bus Interface (EBI). This can be used to enable special
  495. * features like CompactFlash support, NAND Flash support, etc. on
  496. * certain chipselects.
  497. */
  498. static inline void set_ebi_sfr_bits(u32 mask)
  499. {
  500. u32 sfr;
  501. clk_enable(&hmatrix_clk);
  502. sfr = hmatrix_readl(SFR4);
  503. sfr |= mask;
  504. hmatrix_writel(SFR4, sfr);
  505. clk_disable(&hmatrix_clk);
  506. }
  507. /* --------------------------------------------------------------------
  508. * System Timer/Counter (TC)
  509. * -------------------------------------------------------------------- */
  510. static struct resource at32_systc0_resource[] = {
  511. PBMEM(0xfff00c00),
  512. IRQ(22),
  513. };
  514. struct platform_device at32_systc0_device = {
  515. .name = "systc",
  516. .id = 0,
  517. .resource = at32_systc0_resource,
  518. .num_resources = ARRAY_SIZE(at32_systc0_resource),
  519. };
  520. DEV_CLK(pclk, at32_systc0, pbb, 3);
  521. /* --------------------------------------------------------------------
  522. * PIO
  523. * -------------------------------------------------------------------- */
  524. static struct resource pio0_resource[] = {
  525. PBMEM(0xffe02800),
  526. IRQ(13),
  527. };
  528. DEFINE_DEV(pio, 0);
  529. DEV_CLK(mck, pio0, pba, 10);
  530. static struct resource pio1_resource[] = {
  531. PBMEM(0xffe02c00),
  532. IRQ(14),
  533. };
  534. DEFINE_DEV(pio, 1);
  535. DEV_CLK(mck, pio1, pba, 11);
  536. static struct resource pio2_resource[] = {
  537. PBMEM(0xffe03000),
  538. IRQ(15),
  539. };
  540. DEFINE_DEV(pio, 2);
  541. DEV_CLK(mck, pio2, pba, 12);
  542. static struct resource pio3_resource[] = {
  543. PBMEM(0xffe03400),
  544. IRQ(16),
  545. };
  546. DEFINE_DEV(pio, 3);
  547. DEV_CLK(mck, pio3, pba, 13);
  548. static struct resource pio4_resource[] = {
  549. PBMEM(0xffe03800),
  550. IRQ(17),
  551. };
  552. DEFINE_DEV(pio, 4);
  553. DEV_CLK(mck, pio4, pba, 14);
  554. void __init at32_add_system_devices(void)
  555. {
  556. platform_device_register(&at32_pm0_device);
  557. platform_device_register(&at32_intc0_device);
  558. platform_device_register(&at32ap700x_rtc0_device);
  559. platform_device_register(&at32_wdt0_device);
  560. platform_device_register(&at32_eic0_device);
  561. platform_device_register(&smc0_device);
  562. platform_device_register(&pdc_device);
  563. platform_device_register(&at32_systc0_device);
  564. platform_device_register(&pio0_device);
  565. platform_device_register(&pio1_device);
  566. platform_device_register(&pio2_device);
  567. platform_device_register(&pio3_device);
  568. platform_device_register(&pio4_device);
  569. }
  570. /* --------------------------------------------------------------------
  571. * USART
  572. * -------------------------------------------------------------------- */
  573. static struct atmel_uart_data atmel_usart0_data = {
  574. .use_dma_tx = 1,
  575. .use_dma_rx = 1,
  576. };
  577. static struct resource atmel_usart0_resource[] = {
  578. PBMEM(0xffe00c00),
  579. IRQ(6),
  580. };
  581. DEFINE_DEV_DATA(atmel_usart, 0);
  582. DEV_CLK(usart, atmel_usart0, pba, 4);
  583. static struct atmel_uart_data atmel_usart1_data = {
  584. .use_dma_tx = 1,
  585. .use_dma_rx = 1,
  586. };
  587. static struct resource atmel_usart1_resource[] = {
  588. PBMEM(0xffe01000),
  589. IRQ(7),
  590. };
  591. DEFINE_DEV_DATA(atmel_usart, 1);
  592. DEV_CLK(usart, atmel_usart1, pba, 4);
  593. static struct atmel_uart_data atmel_usart2_data = {
  594. .use_dma_tx = 1,
  595. .use_dma_rx = 1,
  596. };
  597. static struct resource atmel_usart2_resource[] = {
  598. PBMEM(0xffe01400),
  599. IRQ(8),
  600. };
  601. DEFINE_DEV_DATA(atmel_usart, 2);
  602. DEV_CLK(usart, atmel_usart2, pba, 5);
  603. static struct atmel_uart_data atmel_usart3_data = {
  604. .use_dma_tx = 1,
  605. .use_dma_rx = 1,
  606. };
  607. static struct resource atmel_usart3_resource[] = {
  608. PBMEM(0xffe01800),
  609. IRQ(9),
  610. };
  611. DEFINE_DEV_DATA(atmel_usart, 3);
  612. DEV_CLK(usart, atmel_usart3, pba, 6);
  613. static inline void configure_usart0_pins(void)
  614. {
  615. select_peripheral(PA(8), PERIPH_B, 0); /* RXD */
  616. select_peripheral(PA(9), PERIPH_B, 0); /* TXD */
  617. }
  618. static inline void configure_usart1_pins(void)
  619. {
  620. select_peripheral(PA(17), PERIPH_A, 0); /* RXD */
  621. select_peripheral(PA(18), PERIPH_A, 0); /* TXD */
  622. }
  623. static inline void configure_usart2_pins(void)
  624. {
  625. select_peripheral(PB(26), PERIPH_B, 0); /* RXD */
  626. select_peripheral(PB(27), PERIPH_B, 0); /* TXD */
  627. }
  628. static inline void configure_usart3_pins(void)
  629. {
  630. select_peripheral(PB(18), PERIPH_B, 0); /* RXD */
  631. select_peripheral(PB(17), PERIPH_B, 0); /* TXD */
  632. }
  633. static struct platform_device *__initdata at32_usarts[4];
  634. void __init at32_map_usart(unsigned int hw_id, unsigned int line)
  635. {
  636. struct platform_device *pdev;
  637. switch (hw_id) {
  638. case 0:
  639. pdev = &atmel_usart0_device;
  640. configure_usart0_pins();
  641. break;
  642. case 1:
  643. pdev = &atmel_usart1_device;
  644. configure_usart1_pins();
  645. break;
  646. case 2:
  647. pdev = &atmel_usart2_device;
  648. configure_usart2_pins();
  649. break;
  650. case 3:
  651. pdev = &atmel_usart3_device;
  652. configure_usart3_pins();
  653. break;
  654. default:
  655. return;
  656. }
  657. if (PXSEG(pdev->resource[0].start) == P4SEG) {
  658. /* Addresses in the P4 segment are permanently mapped 1:1 */
  659. struct atmel_uart_data *data = pdev->dev.platform_data;
  660. data->regs = (void __iomem *)pdev->resource[0].start;
  661. }
  662. pdev->id = line;
  663. at32_usarts[line] = pdev;
  664. }
  665. struct platform_device *__init at32_add_device_usart(unsigned int id)
  666. {
  667. platform_device_register(at32_usarts[id]);
  668. return at32_usarts[id];
  669. }
  670. struct platform_device *atmel_default_console_device;
  671. void __init at32_setup_serial_console(unsigned int usart_id)
  672. {
  673. atmel_default_console_device = at32_usarts[usart_id];
  674. }
  675. /* --------------------------------------------------------------------
  676. * Ethernet
  677. * -------------------------------------------------------------------- */
  678. static struct eth_platform_data macb0_data;
  679. static struct resource macb0_resource[] = {
  680. PBMEM(0xfff01800),
  681. IRQ(25),
  682. };
  683. DEFINE_DEV_DATA(macb, 0);
  684. DEV_CLK(hclk, macb0, hsb, 8);
  685. DEV_CLK(pclk, macb0, pbb, 6);
  686. static struct eth_platform_data macb1_data;
  687. static struct resource macb1_resource[] = {
  688. PBMEM(0xfff01c00),
  689. IRQ(26),
  690. };
  691. DEFINE_DEV_DATA(macb, 1);
  692. DEV_CLK(hclk, macb1, hsb, 9);
  693. DEV_CLK(pclk, macb1, pbb, 7);
  694. struct platform_device *__init
  695. at32_add_device_eth(unsigned int id, struct eth_platform_data *data)
  696. {
  697. struct platform_device *pdev;
  698. switch (id) {
  699. case 0:
  700. pdev = &macb0_device;
  701. select_peripheral(PC(3), PERIPH_A, 0); /* TXD0 */
  702. select_peripheral(PC(4), PERIPH_A, 0); /* TXD1 */
  703. select_peripheral(PC(7), PERIPH_A, 0); /* TXEN */
  704. select_peripheral(PC(8), PERIPH_A, 0); /* TXCK */
  705. select_peripheral(PC(9), PERIPH_A, 0); /* RXD0 */
  706. select_peripheral(PC(10), PERIPH_A, 0); /* RXD1 */
  707. select_peripheral(PC(13), PERIPH_A, 0); /* RXER */
  708. select_peripheral(PC(15), PERIPH_A, 0); /* RXDV */
  709. select_peripheral(PC(16), PERIPH_A, 0); /* MDC */
  710. select_peripheral(PC(17), PERIPH_A, 0); /* MDIO */
  711. if (!data->is_rmii) {
  712. select_peripheral(PC(0), PERIPH_A, 0); /* COL */
  713. select_peripheral(PC(1), PERIPH_A, 0); /* CRS */
  714. select_peripheral(PC(2), PERIPH_A, 0); /* TXER */
  715. select_peripheral(PC(5), PERIPH_A, 0); /* TXD2 */
  716. select_peripheral(PC(6), PERIPH_A, 0); /* TXD3 */
  717. select_peripheral(PC(11), PERIPH_A, 0); /* RXD2 */
  718. select_peripheral(PC(12), PERIPH_A, 0); /* RXD3 */
  719. select_peripheral(PC(14), PERIPH_A, 0); /* RXCK */
  720. select_peripheral(PC(18), PERIPH_A, 0); /* SPD */
  721. }
  722. break;
  723. case 1:
  724. pdev = &macb1_device;
  725. select_peripheral(PD(13), PERIPH_B, 0); /* TXD0 */
  726. select_peripheral(PD(14), PERIPH_B, 0); /* TXD1 */
  727. select_peripheral(PD(11), PERIPH_B, 0); /* TXEN */
  728. select_peripheral(PD(12), PERIPH_B, 0); /* TXCK */
  729. select_peripheral(PD(10), PERIPH_B, 0); /* RXD0 */
  730. select_peripheral(PD(6), PERIPH_B, 0); /* RXD1 */
  731. select_peripheral(PD(5), PERIPH_B, 0); /* RXER */
  732. select_peripheral(PD(4), PERIPH_B, 0); /* RXDV */
  733. select_peripheral(PD(3), PERIPH_B, 0); /* MDC */
  734. select_peripheral(PD(2), PERIPH_B, 0); /* MDIO */
  735. if (!data->is_rmii) {
  736. select_peripheral(PC(19), PERIPH_B, 0); /* COL */
  737. select_peripheral(PC(23), PERIPH_B, 0); /* CRS */
  738. select_peripheral(PC(26), PERIPH_B, 0); /* TXER */
  739. select_peripheral(PC(27), PERIPH_B, 0); /* TXD2 */
  740. select_peripheral(PC(28), PERIPH_B, 0); /* TXD3 */
  741. select_peripheral(PC(29), PERIPH_B, 0); /* RXD2 */
  742. select_peripheral(PC(30), PERIPH_B, 0); /* RXD3 */
  743. select_peripheral(PC(24), PERIPH_B, 0); /* RXCK */
  744. select_peripheral(PD(15), PERIPH_B, 0); /* SPD */
  745. }
  746. break;
  747. default:
  748. return NULL;
  749. }
  750. memcpy(pdev->dev.platform_data, data, sizeof(struct eth_platform_data));
  751. platform_device_register(pdev);
  752. return pdev;
  753. }
  754. /* --------------------------------------------------------------------
  755. * SPI
  756. * -------------------------------------------------------------------- */
  757. static struct resource atmel_spi0_resource[] = {
  758. PBMEM(0xffe00000),
  759. IRQ(3),
  760. };
  761. DEFINE_DEV(atmel_spi, 0);
  762. DEV_CLK(spi_clk, atmel_spi0, pba, 0);
  763. static struct resource atmel_spi1_resource[] = {
  764. PBMEM(0xffe00400),
  765. IRQ(4),
  766. };
  767. DEFINE_DEV(atmel_spi, 1);
  768. DEV_CLK(spi_clk, atmel_spi1, pba, 1);
  769. static void __init
  770. at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b,
  771. unsigned int n, const u8 *pins)
  772. {
  773. unsigned int pin, mode;
  774. for (; n; n--, b++) {
  775. b->bus_num = bus_num;
  776. if (b->chip_select >= 4)
  777. continue;
  778. pin = (unsigned)b->controller_data;
  779. if (!pin) {
  780. pin = pins[b->chip_select];
  781. b->controller_data = (void *)pin;
  782. }
  783. mode = AT32_GPIOF_OUTPUT;
  784. if (!(b->mode & SPI_CS_HIGH))
  785. mode |= AT32_GPIOF_HIGH;
  786. at32_select_gpio(pin, mode);
  787. }
  788. }
  789. struct platform_device *__init
  790. at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
  791. {
  792. /*
  793. * Manage the chipselects as GPIOs, normally using the same pins
  794. * the SPI controller expects; but boards can use other pins.
  795. */
  796. static u8 __initdata spi0_pins[] =
  797. { GPIO_PIN_PA(3), GPIO_PIN_PA(4),
  798. GPIO_PIN_PA(5), GPIO_PIN_PA(20), };
  799. static u8 __initdata spi1_pins[] =
  800. { GPIO_PIN_PB(2), GPIO_PIN_PB(3),
  801. GPIO_PIN_PB(4), GPIO_PIN_PA(27), };
  802. struct platform_device *pdev;
  803. switch (id) {
  804. case 0:
  805. pdev = &atmel_spi0_device;
  806. select_peripheral(PA(0), PERIPH_A, 0); /* MISO */
  807. select_peripheral(PA(1), PERIPH_A, 0); /* MOSI */
  808. select_peripheral(PA(2), PERIPH_A, 0); /* SCK */
  809. at32_spi_setup_slaves(0, b, n, spi0_pins);
  810. break;
  811. case 1:
  812. pdev = &atmel_spi1_device;
  813. select_peripheral(PB(0), PERIPH_B, 0); /* MISO */
  814. select_peripheral(PB(1), PERIPH_B, 0); /* MOSI */
  815. select_peripheral(PB(5), PERIPH_B, 0); /* SCK */
  816. at32_spi_setup_slaves(1, b, n, spi1_pins);
  817. break;
  818. default:
  819. return NULL;
  820. }
  821. spi_register_board_info(b, n);
  822. platform_device_register(pdev);
  823. return pdev;
  824. }
  825. /* --------------------------------------------------------------------
  826. * LCDC
  827. * -------------------------------------------------------------------- */
  828. static struct atmel_lcdfb_info atmel_lcdfb0_data;
  829. static struct resource atmel_lcdfb0_resource[] = {
  830. {
  831. .start = 0xff000000,
  832. .end = 0xff000fff,
  833. .flags = IORESOURCE_MEM,
  834. },
  835. IRQ(1),
  836. {
  837. /* Placeholder for pre-allocated fb memory */
  838. .start = 0x00000000,
  839. .end = 0x00000000,
  840. .flags = 0,
  841. },
  842. };
  843. DEFINE_DEV_DATA(atmel_lcdfb, 0);
  844. DEV_CLK(hck1, atmel_lcdfb0, hsb, 7);
  845. static struct clk atmel_lcdfb0_pixclk = {
  846. .name = "lcdc_clk",
  847. .dev = &atmel_lcdfb0_device.dev,
  848. .mode = genclk_mode,
  849. .get_rate = genclk_get_rate,
  850. .set_rate = genclk_set_rate,
  851. .set_parent = genclk_set_parent,
  852. .index = 7,
  853. };
  854. struct platform_device *__init
  855. at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
  856. unsigned long fbmem_start, unsigned long fbmem_len)
  857. {
  858. struct platform_device *pdev;
  859. struct atmel_lcdfb_info *info;
  860. struct fb_monspecs *monspecs;
  861. struct fb_videomode *modedb;
  862. unsigned int modedb_size;
  863. /*
  864. * Do a deep copy of the fb data, monspecs and modedb. Make
  865. * sure all allocations are done before setting up the
  866. * portmux.
  867. */
  868. monspecs = kmemdup(data->default_monspecs,
  869. sizeof(struct fb_monspecs), GFP_KERNEL);
  870. if (!monspecs)
  871. return NULL;
  872. modedb_size = sizeof(struct fb_videomode) * monspecs->modedb_len;
  873. modedb = kmemdup(monspecs->modedb, modedb_size, GFP_KERNEL);
  874. if (!modedb)
  875. goto err_dup_modedb;
  876. monspecs->modedb = modedb;
  877. switch (id) {
  878. case 0:
  879. pdev = &atmel_lcdfb0_device;
  880. select_peripheral(PC(19), PERIPH_A, 0); /* CC */
  881. select_peripheral(PC(20), PERIPH_A, 0); /* HSYNC */
  882. select_peripheral(PC(21), PERIPH_A, 0); /* PCLK */
  883. select_peripheral(PC(22), PERIPH_A, 0); /* VSYNC */
  884. select_peripheral(PC(23), PERIPH_A, 0); /* DVAL */
  885. select_peripheral(PC(24), PERIPH_A, 0); /* MODE */
  886. select_peripheral(PC(25), PERIPH_A, 0); /* PWR */
  887. select_peripheral(PC(26), PERIPH_A, 0); /* DATA0 */
  888. select_peripheral(PC(27), PERIPH_A, 0); /* DATA1 */
  889. select_peripheral(PC(28), PERIPH_A, 0); /* DATA2 */
  890. select_peripheral(PC(29), PERIPH_A, 0); /* DATA3 */
  891. select_peripheral(PC(30), PERIPH_A, 0); /* DATA4 */
  892. select_peripheral(PC(31), PERIPH_A, 0); /* DATA5 */
  893. select_peripheral(PD(0), PERIPH_A, 0); /* DATA6 */
  894. select_peripheral(PD(1), PERIPH_A, 0); /* DATA7 */
  895. select_peripheral(PD(2), PERIPH_A, 0); /* DATA8 */
  896. select_peripheral(PD(3), PERIPH_A, 0); /* DATA9 */
  897. select_peripheral(PD(4), PERIPH_A, 0); /* DATA10 */
  898. select_peripheral(PD(5), PERIPH_A, 0); /* DATA11 */
  899. select_peripheral(PD(6), PERIPH_A, 0); /* DATA12 */
  900. select_peripheral(PD(7), PERIPH_A, 0); /* DATA13 */
  901. select_peripheral(PD(8), PERIPH_A, 0); /* DATA14 */
  902. select_peripheral(PD(9), PERIPH_A, 0); /* DATA15 */
  903. select_peripheral(PD(10), PERIPH_A, 0); /* DATA16 */
  904. select_peripheral(PD(11), PERIPH_A, 0); /* DATA17 */
  905. select_peripheral(PD(12), PERIPH_A, 0); /* DATA18 */
  906. select_peripheral(PD(13), PERIPH_A, 0); /* DATA19 */
  907. select_peripheral(PD(14), PERIPH_A, 0); /* DATA20 */
  908. select_peripheral(PD(15), PERIPH_A, 0); /* DATA21 */
  909. select_peripheral(PD(16), PERIPH_A, 0); /* DATA22 */
  910. select_peripheral(PD(17), PERIPH_A, 0); /* DATA23 */
  911. clk_set_parent(&atmel_lcdfb0_pixclk, &pll0);
  912. clk_set_rate(&atmel_lcdfb0_pixclk, clk_get_rate(&pll0));
  913. break;
  914. default:
  915. goto err_invalid_id;
  916. }
  917. if (fbmem_len) {
  918. pdev->resource[2].start = fbmem_start;
  919. pdev->resource[2].end = fbmem_start + fbmem_len - 1;
  920. pdev->resource[2].flags = IORESOURCE_MEM;
  921. }
  922. info = pdev->dev.platform_data;
  923. memcpy(info, data, sizeof(struct atmel_lcdfb_info));
  924. info->default_monspecs = monspecs;
  925. platform_device_register(pdev);
  926. return pdev;
  927. err_invalid_id:
  928. kfree(modedb);
  929. err_dup_modedb:
  930. kfree(monspecs);
  931. return NULL;
  932. }
  933. /* --------------------------------------------------------------------
  934. * SSC
  935. * -------------------------------------------------------------------- */
  936. static struct resource ssc0_resource[] = {
  937. PBMEM(0xffe01c00),
  938. IRQ(10),
  939. };
  940. DEFINE_DEV(ssc, 0);
  941. DEV_CLK(pclk, ssc0, pba, 7);
  942. static struct resource ssc1_resource[] = {
  943. PBMEM(0xffe02000),
  944. IRQ(11),
  945. };
  946. DEFINE_DEV(ssc, 1);
  947. DEV_CLK(pclk, ssc1, pba, 8);
  948. static struct resource ssc2_resource[] = {
  949. PBMEM(0xffe02400),
  950. IRQ(12),
  951. };
  952. DEFINE_DEV(ssc, 2);
  953. DEV_CLK(pclk, ssc2, pba, 9);
  954. struct platform_device *__init
  955. at32_add_device_ssc(unsigned int id, unsigned int flags)
  956. {
  957. struct platform_device *pdev;
  958. switch (id) {
  959. case 0:
  960. pdev = &ssc0_device;
  961. if (flags & ATMEL_SSC_RF)
  962. select_peripheral(PA(21), PERIPH_A, 0); /* RF */
  963. if (flags & ATMEL_SSC_RK)
  964. select_peripheral(PA(22), PERIPH_A, 0); /* RK */
  965. if (flags & ATMEL_SSC_TK)
  966. select_peripheral(PA(23), PERIPH_A, 0); /* TK */
  967. if (flags & ATMEL_SSC_TF)
  968. select_peripheral(PA(24), PERIPH_A, 0); /* TF */
  969. if (flags & ATMEL_SSC_TD)
  970. select_peripheral(PA(25), PERIPH_A, 0); /* TD */
  971. if (flags & ATMEL_SSC_RD)
  972. select_peripheral(PA(26), PERIPH_A, 0); /* RD */
  973. break;
  974. case 1:
  975. pdev = &ssc1_device;
  976. if (flags & ATMEL_SSC_RF)
  977. select_peripheral(PA(0), PERIPH_B, 0); /* RF */
  978. if (flags & ATMEL_SSC_RK)
  979. select_peripheral(PA(1), PERIPH_B, 0); /* RK */
  980. if (flags & ATMEL_SSC_TK)
  981. select_peripheral(PA(2), PERIPH_B, 0); /* TK */
  982. if (flags & ATMEL_SSC_TF)
  983. select_peripheral(PA(3), PERIPH_B, 0); /* TF */
  984. if (flags & ATMEL_SSC_TD)
  985. select_peripheral(PA(4), PERIPH_B, 0); /* TD */
  986. if (flags & ATMEL_SSC_RD)
  987. select_peripheral(PA(5), PERIPH_B, 0); /* RD */
  988. break;
  989. case 2:
  990. pdev = &ssc2_device;
  991. if (flags & ATMEL_SSC_TD)
  992. select_peripheral(PB(13), PERIPH_A, 0); /* TD */
  993. if (flags & ATMEL_SSC_RD)
  994. select_peripheral(PB(14), PERIPH_A, 0); /* RD */
  995. if (flags & ATMEL_SSC_TK)
  996. select_peripheral(PB(15), PERIPH_A, 0); /* TK */
  997. if (flags & ATMEL_SSC_TF)
  998. select_peripheral(PB(16), PERIPH_A, 0); /* TF */
  999. if (flags & ATMEL_SSC_RF)
  1000. select_peripheral(PB(17), PERIPH_A, 0); /* RF */
  1001. if (flags & ATMEL_SSC_RK)
  1002. select_peripheral(PB(18), PERIPH_A, 0); /* RK */
  1003. break;
  1004. default:
  1005. return NULL;
  1006. }
  1007. platform_device_register(pdev);
  1008. return pdev;
  1009. }
  1010. /* --------------------------------------------------------------------
  1011. * GCLK
  1012. * -------------------------------------------------------------------- */
  1013. static struct clk gclk0 = {
  1014. .name = "gclk0",
  1015. .mode = genclk_mode,
  1016. .get_rate = genclk_get_rate,
  1017. .set_rate = genclk_set_rate,
  1018. .set_parent = genclk_set_parent,
  1019. .index = 0,
  1020. };
  1021. static struct clk gclk1 = {
  1022. .name = "gclk1",
  1023. .mode = genclk_mode,
  1024. .get_rate = genclk_get_rate,
  1025. .set_rate = genclk_set_rate,
  1026. .set_parent = genclk_set_parent,
  1027. .index = 1,
  1028. };
  1029. static struct clk gclk2 = {
  1030. .name = "gclk2",
  1031. .mode = genclk_mode,
  1032. .get_rate = genclk_get_rate,
  1033. .set_rate = genclk_set_rate,
  1034. .set_parent = genclk_set_parent,
  1035. .index = 2,
  1036. };
  1037. static struct clk gclk3 = {
  1038. .name = "gclk3",
  1039. .mode = genclk_mode,
  1040. .get_rate = genclk_get_rate,
  1041. .set_rate = genclk_set_rate,
  1042. .set_parent = genclk_set_parent,
  1043. .index = 3,
  1044. };
  1045. static struct clk gclk4 = {
  1046. .name = "gclk4",
  1047. .mode = genclk_mode,
  1048. .get_rate = genclk_get_rate,
  1049. .set_rate = genclk_set_rate,
  1050. .set_parent = genclk_set_parent,
  1051. .index = 4,
  1052. };
  1053. struct clk *at32_clock_list[] = {
  1054. &osc32k,
  1055. &osc0,
  1056. &osc1,
  1057. &pll0,
  1058. &pll1,
  1059. &cpu_clk,
  1060. &hsb_clk,
  1061. &pba_clk,
  1062. &pbb_clk,
  1063. &at32_pm_pclk,
  1064. &at32_intc0_pclk,
  1065. &hmatrix_clk,
  1066. &ebi_clk,
  1067. &hramc_clk,
  1068. &smc0_pclk,
  1069. &smc0_mck,
  1070. &pdc_hclk,
  1071. &pdc_pclk,
  1072. &pico_clk,
  1073. &pio0_mck,
  1074. &pio1_mck,
  1075. &pio2_mck,
  1076. &pio3_mck,
  1077. &pio4_mck,
  1078. &at32_systc0_pclk,
  1079. &atmel_usart0_usart,
  1080. &atmel_usart1_usart,
  1081. &atmel_usart2_usart,
  1082. &atmel_usart3_usart,
  1083. &macb0_hclk,
  1084. &macb0_pclk,
  1085. &macb1_hclk,
  1086. &macb1_pclk,
  1087. &atmel_spi0_spi_clk,
  1088. &atmel_spi1_spi_clk,
  1089. &atmel_lcdfb0_hck1,
  1090. &atmel_lcdfb0_pixclk,
  1091. &ssc0_pclk,
  1092. &ssc1_pclk,
  1093. &ssc2_pclk,
  1094. &gclk0,
  1095. &gclk1,
  1096. &gclk2,
  1097. &gclk3,
  1098. &gclk4,
  1099. };
  1100. unsigned int at32_nr_clocks = ARRAY_SIZE(at32_clock_list);
  1101. void __init at32_portmux_init(void)
  1102. {
  1103. at32_init_pio(&pio0_device);
  1104. at32_init_pio(&pio1_device);
  1105. at32_init_pio(&pio2_device);
  1106. at32_init_pio(&pio3_device);
  1107. at32_init_pio(&pio4_device);
  1108. }
  1109. void __init at32_clock_init(void)
  1110. {
  1111. u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
  1112. int i;
  1113. if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) {
  1114. main_clock = &pll0;
  1115. cpu_clk.parent = &pll0;
  1116. } else {
  1117. main_clock = &osc0;
  1118. cpu_clk.parent = &osc0;
  1119. }
  1120. if (pm_readl(PLL0) & PM_BIT(PLLOSC))
  1121. pll0.parent = &osc1;
  1122. if (pm_readl(PLL1) & PM_BIT(PLLOSC))
  1123. pll1.parent = &osc1;
  1124. genclk_init_parent(&gclk0);
  1125. genclk_init_parent(&gclk1);
  1126. genclk_init_parent(&gclk2);
  1127. genclk_init_parent(&gclk3);
  1128. genclk_init_parent(&gclk4);
  1129. genclk_init_parent(&atmel_lcdfb0_pixclk);
  1130. /*
  1131. * Turn on all clocks that have at least one user already, and
  1132. * turn off everything else. We only do this for module
  1133. * clocks, and even though it isn't particularly pretty to
  1134. * check the address of the mode function, it should do the
  1135. * trick...
  1136. */
  1137. for (i = 0; i < ARRAY_SIZE(at32_clock_list); i++) {
  1138. struct clk *clk = at32_clock_list[i];
  1139. if (clk->users == 0)
  1140. continue;
  1141. if (clk->mode == &cpu_clk_mode)
  1142. cpu_mask |= 1 << clk->index;
  1143. else if (clk->mode == &hsb_clk_mode)
  1144. hsb_mask |= 1 << clk->index;
  1145. else if (clk->mode == &pba_clk_mode)
  1146. pba_mask |= 1 << clk->index;
  1147. else if (clk->mode == &pbb_clk_mode)
  1148. pbb_mask |= 1 << clk->index;
  1149. }
  1150. pm_writel(CPU_MASK, cpu_mask);
  1151. pm_writel(HSB_MASK, hsb_mask);
  1152. pm_writel(PBA_MASK, pba_mask);
  1153. pm_writel(PBB_MASK, pbb_mask);
  1154. }