commandProcessing.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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/delay.h>
  10. #include <linux/dw_dmac.h>
  11. #include <linux/fb.h>
  12. #include <linux/init.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/slab.h>
  16. #include <linux/gpio.h>
  17. #include <linux/spi/spi.h>
  18. #include <linux/usb/atmel_usba_udc.h>
  19. #include <mach/atmel-mci.h>
  20. #include <linux/atmel-mci.h>
  21. #include <asm/io.h>
  22. #include <asm/irq.h>
  23. #include <mach/at32ap700x.h>
  24. #include <mach/board.h>
  25. #include <mach/hmatrix.h>
  26. #include <mach/portmux.h>
  27. #include <mach/sram.h>
  28. #include <sound/atmel-abdac.h>
  29. #include <sound/atmel-ac97c.h>
  30. #include <video/atmel_lcdc.h>
  31. #include "clock.h"
  32. #include "pio.h"
  33. #include "pm.h"
  34. #define PBMEM(base) \
  35. { \
  36. .start = base, \
  37. .end = base + 0x3ff, \
  38. .flags = IORESOURCE_MEM, \
  39. }
  40. #define IRQ(num) \
  41. { \
  42. .start = num, \
  43. .end = num, \
  44. .flags = IORESOURCE_IRQ, \
  45. }
  46. #define NAMED_IRQ(num, _name) \
  47. { \
  48. .start = num, \
  49. .end = num, \
  50. .name = _name, \
  51. .flags = IORESOURCE_IRQ, \
  52. }
  53. /* REVISIT these assume *every* device supports DMA, but several
  54. * don't ... tc, smc, pio, rtc, watchdog, pwm, ps2, and more.
  55. */
  56. #define DEFINE_DEV(_name, _id) \
  57. static u64 _name##_id##_dma_mask = DMA_BIT_MASK(32); \
  58. static struct platform_device _name##_id##_device = { \
  59. .name = #_name, \
  60. .id = _id, \
  61. .dev = { \
  62. .dma_mask = &_name##_id##_dma_mask, \
  63. .coherent_dma_mask = DMA_BIT_MASK(32), \
  64. }, \
  65. .resource = _name##_id##_resource, \
  66. .num_resources = ARRAY_SIZE(_name##_id##_resource), \
  67. }
  68. #define DEFINE_DEV_DATA(_name, _id) \
  69. static u64 _name##_id##_dma_mask = DMA_BIT_MASK(32); \
  70. static struct platform_device _name##_id##_device = { \
  71. .name = #_name, \
  72. .id = _id, \
  73. .dev = { \
  74. .dma_mask = &_name##_id##_dma_mask, \
  75. .platform_data = &_name##_id##_data, \
  76. .coherent_dma_mask = DMA_BIT_MASK(32), \
  77. }, \
  78. .resource = _name##_id##_resource, \
  79. .num_resources = ARRAY_SIZE(_name##_id##_resource), \
  80. }
  81. #define select_peripheral(port, pin_mask, periph, flags) \
  82. at32_select_periph(GPIO_##port##_BASE, pin_mask, \
  83. GPIO_##periph, flags)
  84. #define DEV_CLK(_name, devname, bus, _index) \
  85. static struct clk devname##_##_name = { \
  86. .name = #_name, \
  87. .dev = &devname##_device.dev, \
  88. .parent = &bus##_clk, \
  89. .mode = bus##_clk_mode, \
  90. .get_rate = bus##_clk_get_rate, \
  91. .index = _index, \
  92. }
  93. static DEFINE_SPINLOCK(pm_lock);
  94. static struct clk osc0;
  95. static struct clk osc1;
  96. static unsigned long osc_get_rate(struct clk *clk)
  97. {
  98. return at32_board_osc_rates[clk->index];
  99. }
  100. static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
  101. {
  102. unsigned long div, mul, rate;
  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 long pll_set_rate(struct clk *clk, unsigned long rate,
  111. u32 *pll_ctrl)
  112. {
  113. unsigned long mul;
  114. unsigned long mul_best_fit = 0;
  115. unsigned long div;
  116. unsigned long div_min;
  117. unsigned long div_max;
  118. unsigned long div_best_fit = 0;
  119. unsigned long base;
  120. unsigned long pll_in;
  121. unsigned long actual = 0;
  122. unsigned long rate_error;
  123. unsigned long rate_error_prev = ~0UL;
  124. u32 ctrl;
  125. /* Rate must be between 80 MHz and 200 Mhz. */
  126. if (rate < 80000000UL || rate > 200000000UL)
  127. return -EINVAL;
  128. ctrl = PM_BF(PLLOPT, 4);
  129. base = clk->parent->get_rate(clk->parent);
  130. /* PLL input frequency must be between 6 MHz and 32 MHz. */
  131. div_min = DIV_ROUND_UP(base, 32000000UL);
  132. div_max = base / 6000000UL;
  133. if (div_max < div_min)
  134. return -EINVAL;
  135. for (div = div_min; div <= div_max; div++) {
  136. pll_in = (base + div / 2) / div;
  137. mul = (rate + pll_in / 2) / pll_in;
  138. if (mul == 0)
  139. continue;
  140. actual = pll_in * mul;
  141. rate_error = abs(actual - rate);
  142. if (rate_error < rate_error_prev) {
  143. mul_best_fit = mul;
  144. div_best_fit = div;
  145. rate_error_prev = rate_error;
  146. }
  147. if (rate_error == 0)
  148. break;
  149. }
  150. if (div_best_fit == 0)
  151. return -EINVAL;
  152. ctrl |= PM_BF(PLLMUL, mul_best_fit - 1);
  153. ctrl |= PM_BF(PLLDIV, div_best_fit - 1);
  154. ctrl |= PM_BF(PLLCOUNT, 16);
  155. if (clk->parent == &osc1)
  156. ctrl |= PM_BIT(PLLOSC);
  157. *pll_ctrl = ctrl;
  158. return actual;
  159. }
  160. static unsigned long pll0_get_rate(struct clk *clk)
  161. {
  162. u32 control;
  163. control = pm_readl(PLL0);
  164. return pll_get_rate(clk, control);
  165. }
  166. static void pll1_mode(struct clk *clk, int enabled)
  167. {
  168. unsigned long timeout;
  169. u32 status;
  170. u32 ctrl;
  171. ctrl = pm_readl(PLL1);
  172. if (enabled) {
  173. if (!PM_BFEXT(PLLMUL, ctrl) && !PM_BFEXT(PLLDIV, ctrl)) {
  174. pr_debug("clk %s: failed to enable, rate not set\n",
  175. clk->name);
  176. return;
  177. }
  178. ctrl |= PM_BIT(PLLEN);
  179. pm_writel(PLL1, ctrl);
  180. /* Wait for PLL lock. */
  181. for (timeout = 10000; timeout; timeout--) {
  182. status = pm_readl(ISR);
  183. if (status & PM_BIT(LOCK1))
  184. break;
  185. udelay(10);
  186. }
  187. if (!(status & PM_BIT(LOCK1)))
  188. printk(KERN_ERR "clk %s: timeout waiting for lock\n",
  189. clk->name);
  190. } else {
  191. ctrl &= ~PM_BIT(PLLEN);
  192. pm_writel(PLL1, ctrl);
  193. }
  194. }
  195. static unsigned long pll1_get_rate(struct clk *clk)
  196. {
  197. u32 control;
  198. control = pm_readl(PLL1);
  199. return pll_get_rate(clk, control);
  200. }
  201. static long pll1_set_rate(struct clk *clk, unsigned long rate, int apply)
  202. {
  203. u32 ctrl = 0;
  204. unsigned long actual_rate;
  205. actual_rate = pll_set_rate(clk, rate, &ctrl);
  206. if (apply) {
  207. if (actual_rate != rate)
  208. return -EINVAL;
  209. if (clk->users > 0)
  210. return -EBUSY;
  211. pr_debug(KERN_INFO "clk %s: new rate %lu (actual rate %lu)\n",
  212. clk->name, rate, actual_rate);
  213. pm_writel(PLL1, ctrl);
  214. }
  215. return actual_rate;
  216. }
  217. static int pll1_set_parent(struct clk *clk, struct clk *parent)
  218. {
  219. u32 ctrl;
  220. if (clk->users > 0)
  221. return -EBUSY;
  222. ctrl = pm_readl(PLL1);
  223. WARN_ON(ctrl & PM_BIT(PLLEN));
  224. if (parent == &osc0)
  225. ctrl &= ~PM_BIT(PLLOSC);
  226. else if (parent == &osc1)
  227. ctrl |= PM_BIT(PLLOSC);
  228. else
  229. return -EINVAL;
  230. pm_writel(PLL1, ctrl);
  231. clk->parent = parent;
  232. return 0;
  233. }
  234. /*
  235. * The AT32AP7000 has five primary clock sources: One 32kHz
  236. * oscillator, two crystal oscillators and two PLLs.
  237. */
  238. static struct clk osc32k = {
  239. .name = "osc32k",
  240. .get_rate = osc_get_rate,
  241. .users = 1,
  242. .index = 0,
  243. };
  244. static struct clk osc0 = {
  245. .name = "osc0",
  246. .get_rate = osc_get_rate,
  247. .users = 1,
  248. .index = 1,
  249. };
  250. static struct clk osc1 = {
  251. .name = "osc1",
  252. .get_rate = osc_get_rate,
  253. .index = 2,
  254. };
  255. static struct clk pll0 = {
  256. .name = "pll0",
  257. .get_rate = pll0_get_rate,
  258. .parent = &osc0,
  259. };
  260. static struct clk pll1 = {
  261. .name = "pll1",
  262. .mode = pll1_mode,
  263. .get_rate = pll1_get_rate,
  264. .set_rate = pll1_set_rate,
  265. .set_parent = pll1_set_parent,
  266. .parent = &osc0,
  267. };
  268. /*
  269. * The main clock can be either osc0 or pll0. The boot loader may
  270. * have chosen one for us, so we don't really know which one until we
  271. * have a look at the SM.
  272. */
  273. static struct clk *main_clock;
  274. /*
  275. * Synchronous clocks are generated from the main clock. The clocks
  276. * must satisfy the constraint
  277. * fCPU >= fHSB >= fPB
  278. * i.e. each clock must not be faster than its parent.
  279. */
  280. static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift)
  281. {
  282. return main_clock->get_rate(main_clock) >> shift;
  283. };
  284. static void cpu_clk_mode(struct clk *clk, int enabled)
  285. {
  286. unsigned long flags;
  287. u32 mask;
  288. spin_lock_irqsave(&pm_lock, flags);
  289. mask = pm_readl(CPU_MASK);
  290. if (enabled)
  291. mask |= 1 << clk->index;
  292. else
  293. mask &= ~(1 << clk->index);
  294. pm_writel(CPU_MASK, mask);
  295. spin_unlock_irqrestore(&pm_lock, flags);
  296. }
  297. static unsigned long cpu_clk_get_rate(struct clk *clk)
  298. {
  299. unsigned long cksel, shift = 0;
  300. cksel = pm_readl(CKSEL);
  301. if (cksel & PM_BIT(CPUDIV))
  302. shift = PM_BFEXT(CPUSEL, cksel) + 1;
  303. return bus_clk_get_rate(clk, shift);
  304. }
  305. static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
  306. {
  307. u32 control;
  308. unsigned long parent_rate, child_div, actual_rate, div;
  309. parent_rate = clk->parent->get_rate(clk->parent);
  310. control = pm_readl(CKSEL);
  311. if (control & PM_BIT(HSBDIV))
  312. child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
  313. else
  314. child_div = 1;
  315. if (rate > 3 * (parent_rate / 4) || child_div == 1) {
  316. actual_rate = parent_rate;
  317. control &= ~PM_BIT(CPUDIV);
  318. } else {
  319. unsigned int cpusel;
  320. div = (parent_rate + rate / 2) / rate;
  321. if (div > child_div)
  322. div = child_div;
  323. cpusel = (div > 1) ? (fls(div) - 2) : 0;
  324. control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control);
  325. actual_rate = parent_rate / (1 << (cpusel + 1));
  326. }
  327. pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
  328. clk->name, rate, actual_rate);
  329. if (apply)
  330. pm_writel(CKSEL, control);
  331. return actual_rate;
  332. }
  333. static void hsb_clk_mode(struct clk *clk, int enabled)
  334. {
  335. unsigned long flags;
  336. u32 mask;
  337. spin_lock_irqsave(&pm_lock, flags);
  338. mask = pm_readl(HSB_MASK);
  339. if (enabled)
  340. mask |= 1 << clk->index;
  341. else
  342. mask &= ~(1 << clk->index);
  343. pm_writel(HSB_MASK, mask);
  344. spin_unlock_irqrestore(&pm_lock, flags);
  345. }
  346. static unsigned long hsb_clk_get_rate(struct clk *clk)
  347. {
  348. unsigned long cksel, shift = 0;
  349. cksel = pm_readl(CKSEL);
  350. if (cksel & PM_BIT(HSBDIV))
  351. shift = PM_BFEXT(HSBSEL, cksel) + 1;
  352. return bus_clk_get_rate(clk, shift);
  353. }
  354. void pba_clk_mode(struct clk *clk, int enabled)
  355. {
  356. unsigned long flags;
  357. u32 mask;
  358. spin_lock_irqsave(&pm_lock, flags);
  359. mask = pm_readl(PBA_MASK);
  360. if (enabled)
  361. mask |= 1 << clk->index;
  362. else
  363. mask &= ~(1 << clk->index);
  364. pm_writel(PBA_MASK, mask);
  365. spin_unlock_irqrestore(&pm_lock, flags);
  366. }
  367. unsigned long pba_clk_get_rate(struct clk *clk)
  368. {
  369. unsigned long cksel, shift = 0;
  370. cksel = pm_readl(CKSEL);
  371. if (cksel & PM_BIT(PBADIV))
  372. shift = PM_BFEXT(PBASEL, cksel) + 1;
  373. return bus_clk_get_rate(clk, shift);
  374. }
  375. static void pbb_clk_mode(struct clk *clk, int enabled)
  376. {
  377. unsigned long flags;
  378. u32 mask;
  379. spin_lock_irqsave(&pm_lock, flags);
  380. mask = pm_readl(PBB_MASK);
  381. if (enabled)
  382. mask |= 1 << clk->index;
  383. else
  384. mask &= ~(1 << clk->index);
  385. pm_writel(PBB_MASK, mask);
  386. spin_unlock_irqrestore(&pm_lock, flags);
  387. }
  388. static unsigned long pbb_clk_get_rate(struct clk *clk)
  389. {
  390. unsigned long cksel, shift = 0;
  391. cksel = pm_readl(CKSEL);
  392. if (cksel & PM_BIT(PBBDIV))
  393. shift = PM_BFEXT(PBBSEL, cksel) + 1;
  394. return bus_clk_get_rate(clk, shift);
  395. }
  396. static struct clk cpu_clk = {
  397. .name = "cpu",
  398. .get_rate = cpu_clk_get_rate,
  399. .set_rate = cpu_clk_set_rate,
  400. .users = 1,
  401. };
  402. static struct clk hsb_clk = {
  403. .name = "hsb",
  404. .parent = &cpu_clk,
  405. .get_rate = hsb_clk_get_rate,
  406. };
  407. static struct clk pba_clk = {
  408. .name = "pba",
  409. .parent = &hsb_clk,
  410. .mode = hsb_clk_mode,
  411. .get_rate = pba_clk_get_rate,
  412. .index = 1,
  413. };
  414. static struct clk pbb_clk = {
  415. .name = "pbb",
  416. .parent = &hsb_clk,
  417. .mode = hsb_clk_mode,
  418. .get_rate = pbb_clk_get_rate,
  419. .users = 1,
  420. .index = 2,
  421. };
  422. /* --------------------------------------------------------------------
  423. * Generic Clock operations
  424. * -------------------------------------------------------------------- */
  425. static void genclk_mode(struct clk *clk, int enabled)
  426. {
  427. u32 control;
  428. control = pm_readl(GCCTRL(clk->index));
  429. if (enabled)
  430. control |= PM_BIT(CEN);
  431. else
  432. control &= ~PM_BIT(CEN);
  433. pm_writel(GCCTRL(clk->index), control);
  434. }
  435. static unsigned long genclk_get_rate(struct clk *clk)
  436. {
  437. u32 control;
  438. unsigned long div = 1;
  439. control = pm_readl(GCCTRL(clk->index));
  440. if (control & PM_BIT(DIVEN))
  441. div = 2 * (PM_BFEXT(DIV, control) + 1);
  442. return clk->parent->get_rate(clk->parent) / div;
  443. }
  444. static long genclk_set_rate(struct clk *clk, unsigned long rate, int apply)
  445. {
  446. u32 control;
  447. unsigned long parent_rate, actual_rate, div;
  448. parent_rate = clk->parent->get_rate(clk->parent);
  449. control = pm_readl(GCCTRL(clk->index));
  450. if (rate > 3 * parent_rate / 4) {
  451. actual_rate = parent_rate;
  452. control &= ~PM_BIT(DIVEN);
  453. } else {
  454. div = (parent_rate + rate) / (2 * rate) - 1;
  455. control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN);
  456. actual_rate = parent_rate / (2 * (div + 1));
  457. }
  458. dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n",
  459. clk->name, rate, actual_rate);
  460. if (apply)
  461. pm_writel(GCCTRL(clk->index), control);
  462. return actual_rate;
  463. }
  464. int genclk_set_parent(struct clk *clk, struct clk *parent)
  465. {
  466. u32 control;
  467. dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n",
  468. clk->name, parent->name, clk->parent->name);
  469. control = pm_readl(GCCTRL(clk->index));
  470. if (parent == &osc1 || parent == &pll1)
  471. control |= PM_BIT(OSCSEL);
  472. else if (parent == &osc0 || parent == &pll0)
  473. control &= ~PM_BIT(OSCSEL);
  474. else
  475. return -EINVAL;
  476. if (parent == &pll0 || parent == &pll1)
  477. control |= PM_BIT(PLLSEL);
  478. else
  479. control &= ~PM_BIT(PLLSEL);
  480. pm_writel(GCCTRL(clk->index), control);
  481. clk->parent = parent;
  482. return 0;
  483. }
  484. static void __init genclk_init_parent(struct clk *clk)
  485. {
  486. u32 control;
  487. struct clk *parent;
  488. BUG_ON(clk->index > 7);
  489. control = pm_readl(GCCTRL(clk->index));
  490. if (control & PM_BIT(OSCSEL))
  491. parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1;
  492. else
  493. parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
  494. clk->parent = parent;
  495. }
  496. static struct dw_dma_platform_data dw_dmac0_data = {
  497. .nr_channels = 3,
  498. .block_size = 4095U,
  499. .nr_masters = 2,
  500. .data_width = { 2, 2, 0, 0 },
  501. };
  502. static struct resource dw_dmac0_resource[] = {
  503. PBMEM(0xff200000),
  504. IRQ(2),
  505. };
  506. DEFINE_DEV_DATA(dw_dmac, 0);
  507. DEV_CLK(hclk, dw_dmac0, hsb, 10);
  508. /* --------------------------------------------------------------------
  509. * System peripherals
  510. * -------------------------------------------------------------------- */
  511. static struct resource at32_pm0_resource[] = {
  512. {
  513. .start = 0xfff00000,
  514. .end = 0xfff0007f,
  515. .flags = IORESOURCE_MEM,
  516. },
  517. IRQ(20),
  518. };
  519. static struct resource at32ap700x_rtc0_resource[] = {
  520. {
  521. .start = 0xfff00080,
  522. .end = 0xfff000af,
  523. .flags = IORESOURCE_MEM,
  524. },
  525. IRQ(21),
  526. };
  527. static struct resource at32_wdt0_resource[] = {
  528. {
  529. .start = 0xfff000b0,
  530. .end = 0xfff000cf,
  531. .flags = IORESOURCE_MEM,
  532. },
  533. };
  534. static struct resource at32_eic0_resource[] = {
  535. {
  536. .start = 0xfff00100,
  537. .end = 0xfff0013f,
  538. .flags = IORESOURCE_MEM,
  539. },
  540. IRQ(19),
  541. };
  542. DEFINE_DEV(at32_pm, 0);
  543. DEFINE_DEV(at32ap700x_rtc, 0);
  544. DEFINE_DEV(at32_wdt, 0);
  545. DEFINE_DEV(at32_eic, 0);
  546. /*
  547. * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
  548. * is always running.
  549. */
  550. static struct clk at32_pm_pclk = {
  551. .name = "pclk",
  552. .dev = &at32_pm0_device.dev,
  553. .parent = &pbb_clk,
  554. .mode = pbb_clk_mode,
  555. .get_rate = pbb_clk_get_rate,
  556. .users = 1,
  557. .index = 0,
  558. };
  559. static struct resource intc0_resource[] = {
  560. PBMEM(0xfff00400),
  561. };
  562. struct platform_device at32_intc0_device = {
  563. .name = "intc",
  564. .id = 0,
  565. .resource = intc0_resource,
  566. .num_resources = ARRAY_SIZE(intc0_resource),
  567. };
  568. DEV_CLK(pclk, at32_intc0, pbb, 1);
  569. static struct clk ebi_clk = {
  570. .name = "ebi",
  571. .parent = &hsb_clk,
  572. .mode = hsb_clk_mode,
  573. .get_rate = hsb_clk_get_rate,
  574. .users = 1,
  575. };
  576. static struct clk hramc_clk = {
  577. .name = "hramc",
  578. .parent = &hsb_clk,
  579. .mode = hsb_clk_mode,
  580. .get_rate = hsb_clk_get_rate,
  581. .users = 1,
  582. .index = 3,
  583. };
  584. static struct clk sdramc_clk = {
  585. .name = "sdramc_clk",
  586. .parent = &pbb_clk,
  587. .mode = pbb_clk_mode,
  588. .get_rate = pbb_clk_get_rate,
  589. .users = 1,
  590. .index = 14,
  591. };
  592. static struct resource smc0_resource[] = {
  593. PBMEM(0xfff03400),
  594. };
  595. DEFINE_DEV(smc, 0);
  596. DEV_CLK(pclk, smc0, pbb, 13);
  597. DEV_CLK(mck, smc0, hsb, 0);
  598. static struct platform_device pdc_device = {
  599. .name = "pdc",
  600. .id = 0,
  601. };
  602. DEV_CLK(hclk, pdc, hsb, 4);
  603. DEV_CLK(pclk, pdc, pba, 16);
  604. static struct clk pico_clk = {
  605. .name = "pico",
  606. .parent = &cpu_clk,
  607. .mode = cpu_clk_mode,
  608. .get_rate = cpu_clk_get_rate,
  609. .users = 1,
  610. };
  611. /* --------------------------------------------------------------------
  612. * HMATRIX
  613. * -------------------------------------------------------------------- */
  614. struct clk at32_hmatrix_clk = {
  615. .name = "hmatrix_clk",
  616. .parent = &pbb_clk,
  617. .mode = pbb_clk_mode,
  618. .get_rate = pbb_clk_get_rate,
  619. .index = 2,
  620. .users = 1,
  621. };
  622. /*
  623. * Set bits in the HMATRIX Special Function Register (SFR) used by the
  624. * External Bus Interface (EBI). This can be used to enable special
  625. * features like CompactFlash support, NAND Flash support, etc. on
  626. * certain chipselects.
  627. */
  628. static inline void set_ebi_sfr_bits(u32 mask)
  629. {
  630. hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, mask);
  631. }
  632. /* --------------------------------------------------------------------
  633. * Timer/Counter (TC)
  634. * -------------------------------------------------------------------- */
  635. static struct resource at32_tcb0_resource[] = {
  636. PBMEM(0xfff00c00),
  637. IRQ(22),
  638. };
  639. static struct platform_device at32_tcb0_device = {
  640. .name = "atmel_tcb",
  641. .id = 0,
  642. .resource = at32_tcb0_resource,
  643. .num_resources = ARRAY_SIZE(at32_tcb0_resource),
  644. };
  645. DEV_CLK(t0_clk, at32_tcb0, pbb, 3);
  646. static struct resource at32_tcb1_resource[] = {
  647. PBMEM(0xfff01000),
  648. IRQ(23),
  649. };
  650. static struct platform_device at32_tcb1_device = {
  651. .name = "atmel_tcb",
  652. .id = 1,
  653. .resource = at32_tcb1_resource,
  654. .num_resources = ARRAY_SIZE(at32_tcb1_resource),
  655. };
  656. DEV_CLK(t0_clk, at32_tcb1, pbb, 4);
  657. /* --------------------------------------------------------------------
  658. * PIO
  659. * -------------------------------------------------------------------- */
  660. static struct resource pio0_resource[] = {
  661. PBMEM(0xffe02800),
  662. IRQ(13),
  663. };
  664. DEFINE_DEV(pio, 0);
  665. DEV_CLK(mck, pio0, pba, 10);
  666. static struct resource pio1_resource[] = {
  667. PBMEM(0xffe02c00),
  668. IRQ(14),
  669. };
  670. DEFINE_DEV(pio, 1);
  671. DEV_CLK(mck, pio1, pba, 11);
  672. static struct resource pio2_resource[] = {
  673. PBMEM(0xffe03000),
  674. IRQ(15),
  675. };
  676. DEFINE_DEV(pio, 2);
  677. DEV_CLK(mck, pio2, pba, 12);
  678. static struct resource pio3_resource[] = {
  679. PBMEM(0xffe03400),
  680. IRQ(16),
  681. };
  682. DEFINE_DEV(pio, 3);
  683. DEV_CLK(mck, pio3, pba, 13);
  684. static struct resource pio4_resource[] = {
  685. PBMEM(0xffe03800),
  686. IRQ(17),
  687. };
  688. DEFINE_DEV(pio, 4);
  689. DEV_CLK(mck, pio4, pba, 14);
  690. static int __init system_device_init(void)
  691. {
  692. platform_device_register(&at32_pm0_device);
  693. platform_device_register(&at32_intc0_device);
  694. platform_device_register(&at32ap700x_rtc0_device);
  695. platform_device_register(&at32_wdt0_device);
  696. platform_device_register(&at32_eic0_device);
  697. platform_device_register(&smc0_device);
  698. platform_device_register(&pdc_device);
  699. platform_device_register(&dw_dmac0_device);
  700. platform_device_register(&at32_tcb0_device);
  701. platform_device_register(&at32_tcb1_device);
  702. platform_device_register(&pio0_device);
  703. platform_device_register(&pio1_device);
  704. platform_device_register(&pio2_device);
  705. platform_device_register(&pio3_device);
  706. platform_device_register(&pio4_device);
  707. return 0;
  708. }
  709. core_initcall(system_device_init);
  710. /* --------------------------------------------------------------------
  711. * PSIF
  712. * -------------------------------------------------------------------- */
  713. static struct resource atmel_psif0_resource[] __initdata = {
  714. {
  715. .start = 0xffe03c00,
  716. .end = 0xffe03cff,
  717. .flags = IORESOURCE_MEM,
  718. },
  719. IRQ(18),
  720. };
  721. static struct clk atmel_psif0_pclk = {
  722. .name = "pclk",
  723. .parent = &pba_clk,
  724. .mode = pba_clk_mode,
  725. .get_rate = pba_clk_get_rate,
  726. .index = 15,
  727. };
  728. static struct resource atmel_psif1_resource[] __initdata = {
  729. {
  730. .start = 0xffe03d00,
  731. .end = 0xffe03dff,
  732. .flags = IORESOURCE_MEM,
  733. },
  734. IRQ(18),
  735. };
  736. static struct clk atmel_psif1_pclk = {
  737. .name = "pclk",
  738. .parent = &pba_clk,
  739. .mode = pba_clk_mode,
  740. .get_rate = pba_clk_get_rate,
  741. .index = 15,
  742. };
  743. struct platform_device *__init at32_add_device_psif(unsigned int id)
  744. {
  745. struct platform_device *pdev;
  746. u32 pin_mask;
  747. if (!(id == 0 || id == 1))
  748. return NULL;
  749. pdev = platform_device_alloc("atmel_psif", id);
  750. if (!pdev)
  751. return NULL;
  752. switch (id) {
  753. case 0:
  754. pin_mask = (1 << 8) | (1 << 9); /* CLOCK & DATA */
  755. if (platform_device_add_resources(pdev, atmel_psif0_resource,
  756. ARRAY_SIZE(atmel_psif0_resource)))
  757. goto err_add_resources;
  758. atmel_psif0_pclk.dev = &pdev->dev;
  759. select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
  760. break;
  761. case 1:
  762. pin_mask = (1 << 11) | (1 << 12); /* CLOCK & DATA */
  763. if (platform_device_add_resources(pdev, atmel_psif1_resource,
  764. ARRAY_SIZE(atmel_psif1_resource)))
  765. goto err_add_resources;
  766. atmel_psif1_pclk.dev = &pdev->dev;
  767. select_peripheral(PIOB, pin_mask, PERIPH_A, 0);
  768. break;
  769. default:
  770. return NULL;
  771. }
  772. platform_device_add(pdev);
  773. return pdev;
  774. err_add_resources:
  775. platform_device_put(pdev);
  776. return NULL;
  777. }
  778. /* --------------------------------------------------------------------
  779. * USART
  780. * -------------------------------------------------------------------- */
  781. static struct atmel_uart_data atmel_usart0_data = {
  782. .use_dma_tx = 1,
  783. .use_dma_rx = 1,
  784. };
  785. static struct resource atmel_usart0_resource[] = {
  786. PBMEM(0xffe00c00),
  787. IRQ(6),
  788. };
  789. DEFINE_DEV_DATA(atmel_usart, 0);
  790. DEV_CLK(usart, atmel_usart0, pba, 3);
  791. static struct atmel_uart_data atmel_usart1_data = {
  792. .use_dma_tx = 1,
  793. .use_dma_rx = 1,
  794. };
  795. static struct resource atmel_usart1_resource[] = {
  796. PBMEM(0xffe01000),
  797. IRQ(7),
  798. };
  799. DEFINE_DEV_DATA(atmel_usart, 1);
  800. DEV_CLK(usart, atmel_usart1, pba, 4);
  801. static struct atmel_uart_data atmel_usart2_data = {
  802. .use_dma_tx = 1,
  803. .use_dma_rx = 1,
  804. };
  805. static struct resource atmel_usart2_resource[] = {
  806. PBMEM(0xffe01400),
  807. IRQ(8),
  808. };
  809. DEFINE_DEV_DATA(atmel_usart, 2);
  810. DEV_CLK(usart, atmel_usart2, pba, 5);
  811. static struct atmel_uart_data atmel_usart3_data = {
  812. .use_dma_tx = 1,