at91cap9.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * arch/arm/mach-at91/at91cap9.c
  3. *
  4. * Copyright (C) 2007 Stelian Pop <stelian.pop@leadtechdesign.com>
  5. * Copyright (C) 2007 Lead Tech Design <www.leadtechdesign.com>
  6. * Copyright (C) 2007 Atmel Corporation.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/pm.h>
  16. #include <asm/irq.h>
  17. #include <asm/mach/arch.h>
  18. #include <asm/mach/map.h>
  19. #include <mach/cpu.h>
  20. #include <mach/at91cap9.h>
  21. #include <mach/at91_pmc.h>
  22. #include <mach/at91_rstc.h>
  23. #include <mach/at91_shdwc.h>
  24. #include "generic.h"
  25. #include "clock.h"
  26. static struct map_desc at91cap9_io_desc[] __initdata = {
  27. {
  28. .virtual = AT91_VA_BASE_SYS,
  29. .pfn = __phys_to_pfn(AT91_BASE_SYS),
  30. .length = SZ_16K,
  31. .type = MT_DEVICE,
  32. }, {
  33. .virtual = AT91_IO_VIRT_BASE - AT91CAP9_SRAM_SIZE,
  34. .pfn = __phys_to_pfn(AT91CAP9_SRAM_BASE),
  35. .length = AT91CAP9_SRAM_SIZE,
  36. .type = MT_DEVICE,
  37. },
  38. };
  39. /* --------------------------------------------------------------------
  40. * Clocks
  41. * -------------------------------------------------------------------- */
  42. /*
  43. * The peripheral clocks.
  44. */
  45. static struct clk pioABCD_clk = {
  46. .name = "pioABCD_clk",
  47. .pmc_mask = 1 << AT91CAP9_ID_PIOABCD,
  48. .type = CLK_TYPE_PERIPHERAL,
  49. };
  50. static struct clk mpb0_clk = {
  51. .name = "mpb0_clk",
  52. .pmc_mask = 1 << AT91CAP9_ID_MPB0,
  53. .type = CLK_TYPE_PERIPHERAL,
  54. };
  55. static struct clk mpb1_clk = {
  56. .name = "mpb1_clk",
  57. .pmc_mask = 1 << AT91CAP9_ID_MPB1,
  58. .type = CLK_TYPE_PERIPHERAL,
  59. };
  60. static struct clk mpb2_clk = {
  61. .name = "mpb2_clk",
  62. .pmc_mask = 1 << AT91CAP9_ID_MPB2,
  63. .type = CLK_TYPE_PERIPHERAL,
  64. };
  65. static struct clk mpb3_clk = {
  66. .name = "mpb3_clk",
  67. .pmc_mask = 1 << AT91CAP9_ID_MPB3,
  68. .type = CLK_TYPE_PERIPHERAL,
  69. };
  70. static struct clk mpb4_clk = {
  71. .name = "mpb4_clk",
  72. .pmc_mask = 1 << AT91CAP9_ID_MPB4,
  73. .type = CLK_TYPE_PERIPHERAL,
  74. };
  75. static struct clk usart0_clk = {
  76. .name = "usart0_clk",
  77. .pmc_mask = 1 << AT91CAP9_ID_US0,
  78. .type = CLK_TYPE_PERIPHERAL,
  79. };
  80. static struct clk usart1_clk = {
  81. .name = "usart1_clk",
  82. .pmc_mask = 1 << AT91CAP9_ID_US1,
  83. .type = CLK_TYPE_PERIPHERAL,
  84. };
  85. static struct clk usart2_clk = {
  86. .name = "usart2_clk",
  87. .pmc_mask = 1 << AT91CAP9_ID_US2,
  88. .type = CLK_TYPE_PERIPHERAL,
  89. };
  90. static struct clk mmc0_clk = {
  91. .name = "mci0_clk",
  92. .pmc_mask = 1 << AT91CAP9_ID_MCI0,
  93. .type = CLK_TYPE_PERIPHERAL,
  94. };
  95. static struct clk mmc1_clk = {
  96. .name = "mci1_clk",
  97. .pmc_mask = 1 << AT91CAP9_ID_MCI1,
  98. .type = CLK_TYPE_PERIPHERAL,
  99. };
  100. static struct clk can_clk = {
  101. .name = "can_clk",
  102. .pmc_mask = 1 << AT91CAP9_ID_CAN,
  103. .type = CLK_TYPE_PERIPHERAL,
  104. };
  105. static struct clk twi_clk = {
  106. .name = "twi_clk",
  107. .pmc_mask = 1 << AT91CAP9_ID_TWI,
  108. .type = CLK_TYPE_PERIPHERAL,
  109. };
  110. static struct clk spi0_clk = {
  111. .name = "spi0_clk",
  112. .pmc_mask = 1 << AT91CAP9_ID_SPI0,
  113. .type = CLK_TYPE_PERIPHERAL,
  114. };
  115. static struct clk spi1_clk = {
  116. .name = "spi1_clk",
  117. .pmc_mask = 1 << AT91CAP9_ID_SPI1,
  118. .type = CLK_TYPE_PERIPHERAL,
  119. };
  120. static struct clk ssc0_clk = {
  121. .name = "ssc0_clk",
  122. .pmc_mask = 1 << AT91CAP9_ID_SSC0,
  123. .type = CLK_TYPE_PERIPHERAL,
  124. };
  125. static struct clk ssc1_clk = {
  126. .name = "ssc1_clk",
  127. .pmc_mask = 1 << AT91CAP9_ID_SSC1,
  128. .type = CLK_TYPE_PERIPHERAL,
  129. };
  130. static struct clk ac97_clk = {
  131. .name = "ac97_clk",
  132. .pmc_mask = 1 << AT91CAP9_ID_AC97C,
  133. .type = CLK_TYPE_PERIPHERAL,
  134. };
  135. static struct clk tcb_clk = {
  136. .name = "tcb_clk",
  137. .pmc_mask = 1 << AT91CAP9_ID_TCB,
  138. .type = CLK_TYPE_PERIPHERAL,
  139. };
  140. static struct clk pwm_clk = {
  141. .name = "pwm_clk",
  142. .pmc_mask = 1 << AT91CAP9_ID_PWMC,
  143. .type = CLK_TYPE_PERIPHERAL,
  144. };
  145. static struct clk macb_clk = {
  146. .name = "macb_clk",
  147. .pmc_mask = 1 << AT91CAP9_ID_EMAC,
  148. .type = CLK_TYPE_PERIPHERAL,
  149. };
  150. static struct clk aestdes_clk = {
  151. .name = "aestdes_clk",
  152. .pmc_mask = 1 << AT91CAP9_ID_AESTDES,
  153. .type = CLK_TYPE_PERIPHERAL,
  154. };
  155. static struct clk adc_clk = {
  156. .name = "adc_clk",
  157. .pmc_mask = 1 << AT91CAP9_ID_ADC,
  158. .type = CLK_TYPE_PERIPHERAL,
  159. };
  160. static struct clk isi_clk = {
  161. .name = "isi_clk",
  162. .pmc_mask = 1 << AT91CAP9_ID_ISI,
  163. .type = CLK_TYPE_PERIPHERAL,
  164. };
  165. static struct clk lcdc_clk = {
  166. .name = "lcdc_clk",
  167. .pmc_mask = 1 << AT91CAP9_ID_LCDC,
  168. .type = CLK_TYPE_PERIPHERAL,
  169. };
  170. static struct clk dma_clk = {
  171. .name = "dma_clk",
  172. .pmc_mask = 1 << AT91CAP9_ID_DMA,
  173. .type = CLK_TYPE_PERIPHERAL,
  174. };
  175. static struct clk udphs_clk = {
  176. .name = "udphs_clk",
  177. .pmc_mask = 1 << AT91CAP9_ID_UDPHS,
  178. .type = CLK_TYPE_PERIPHERAL,
  179. };
  180. static struct clk ohci_clk = {
  181. .name = "ohci_clk",
  182. .pmc_mask = 1 << AT91CAP9_ID_UHP,
  183. .type = CLK_TYPE_PERIPHERAL,
  184. };
  185. static struct clk *periph_clocks[] __initdata = {
  186. &pioABCD_clk,
  187. &mpb0_clk,
  188. &mpb1_clk,
  189. &mpb2_clk,
  190. &mpb3_clk,
  191. &mpb4_clk,
  192. &usart0_clk,
  193. &usart1_clk,
  194. &usart2_clk,
  195. &mmc0_clk,
  196. &mmc1_clk,
  197. &can_clk,
  198. &twi_clk,
  199. &spi0_clk,
  200. &spi1_clk,
  201. &ssc0_clk,
  202. &ssc1_clk,
  203. &ac97_clk,
  204. &tcb_clk,
  205. &pwm_clk,
  206. &macb_clk,
  207. &aestdes_clk,
  208. &adc_clk,
  209. &isi_clk,
  210. &lcdc_clk,
  211. &dma_clk,
  212. &udphs_clk,
  213. &ohci_clk,
  214. // irq0 .. irq1
  215. };
  216. static struct clk_lookup periph_clocks_lookups[] = {
  217. CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc.0", &utmi_clk),
  218. CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc.0", &udphs_clk),
  219. CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.0", &mmc0_clk),
  220. CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.1", &mmc1_clk),
  221. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
  222. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
  223. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
  224. CLKDEV_CON_DEV_ID("ssc", "ssc.0", &ssc0_clk),
  225. CLKDEV_CON_DEV_ID("ssc", "ssc.1", &ssc1_clk),
  226. };
  227. static struct clk_lookup usart_clocks_lookups[] = {
  228. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  229. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  230. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  231. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  232. };
  233. /*
  234. * The four programmable clocks.
  235. * You must configure pin multiplexing to bring these signals out.
  236. */
  237. static struct clk pck0 = {
  238. .name = "pck0",
  239. .pmc_mask = AT91_PMC_PCK0,
  240. .type = CLK_TYPE_PROGRAMMABLE,
  241. .id = 0,
  242. };
  243. static struct clk pck1 = {
  244. .name = "pck1",
  245. .pmc_mask = AT91_PMC_PCK1,
  246. .type = CLK_TYPE_PROGRAMMABLE,
  247. .id = 1,
  248. };
  249. static struct clk pck2 = {
  250. .name = "pck2",
  251. .pmc_mask = AT91_PMC_PCK2,
  252. .type = CLK_TYPE_PROGRAMMABLE,
  253. .id = 2,
  254. };
  255. static struct clk pck3 = {
  256. .name = "pck3",
  257. .pmc_mask = AT91_PMC_PCK3,
  258. .type = CLK_TYPE_PROGRAMMABLE,
  259. .id = 3,
  260. };
  261. static void __init at91cap9_register_clocks(void)
  262. {
  263. int i;
  264. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  265. clk_register(periph_clocks[i]);
  266. clkdev_add_table(periph_clocks_lookups,
  267. ARRAY_SIZE(periph_clocks_lookups));
  268. clkdev_add_table(usart_clocks_lookups,
  269. ARRAY_SIZE(usart_clocks_lookups));
  270. clk_register(&pck0);
  271. clk_register(&pck1);
  272. clk_register(&pck2);
  273. clk_register(&pck3);
  274. }
  275. static struct clk_lookup console_clock_lookup;
  276. void __init at91cap9_set_console_clock(int id)
  277. {
  278. if (id >= ARRAY_SIZE(usart_clocks_lookups))
  279. return;
  280. console_clock_lookup.con_id = "usart";
  281. console_clock_lookup.clk = usart_clocks_lookups[id].clk;
  282. clkdev_add(&console_clock_lookup);
  283. }
  284. /* --------------------------------------------------------------------
  285. * GPIO
  286. * -------------------------------------------------------------------- */
  287. static struct at91_gpio_bank at91cap9_gpio[] = {
  288. {
  289. .id = AT91CAP9_ID_PIOABCD,
  290. .offset = AT91_PIOA,
  291. .clock = &pioABCD_clk,
  292. }, {
  293. .id = AT91CAP9_ID_PIOABCD,
  294. .offset = AT91_PIOB,
  295. .clock = &pioABCD_clk,
  296. }, {
  297. .id = AT91CAP9_ID_PIOABCD,
  298. .offset = AT91_PIOC,
  299. .clock = &pioABCD_clk,
  300. }, {
  301. .id = AT91CAP9_ID_PIOABCD,
  302. .offset = AT91_PIOD,
  303. .clock = &pioABCD_clk,
  304. }
  305. };
  306. static void at91cap9_reset(void)
  307. {
  308. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  309. }
  310. static void at91cap9_poweroff(void)
  311. {
  312. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  313. }
  314. /* --------------------------------------------------------------------
  315. * AT91CAP9 processor initialization
  316. * -------------------------------------------------------------------- */
  317. void __init at91cap9_map_io(void)
  318. {
  319. /* Map peripherals */
  320. iotable_init(at91cap9_io_desc, ARRAY_SIZE(at91cap9_io_desc));
  321. }
  322. void __init at91cap9_initialize(unsigned long main_clock)
  323. {
  324. at91_arch_reset = at91cap9_reset;
  325. pm_power_off = at91cap9_poweroff;
  326. at91_extern_irq = (1 << AT91CAP9_ID_IRQ0) | (1 << AT91CAP9_ID_IRQ1);
  327. /* Init clock subsystem */
  328. at91_clock_init(main_clock);
  329. /* Register the processor-specific clocks */
  330. at91cap9_register_clocks();
  331. /* Register GPIO subsystem */
  332. at91_gpio_init(at91cap9_gpio, 4);
  333. /* Remember the silicon revision */
  334. if (cpu_is_at91cap9_revB())
  335. system_rev = 0xB;
  336. else if (cpu_is_at91cap9_revC())
  337. system_rev = 0xC;
  338. }
  339. /* --------------------------------------------------------------------
  340. * Interrupt initialization
  341. * -------------------------------------------------------------------- */
  342. /*
  343. * The default interrupt priority levels (0 = lowest, 7 = highest).
  344. */
  345. static unsigned int at91cap9_default_irq_priority[NR_AIC_IRQS] __initdata = {
  346. 7, /* Advanced Interrupt Controller (FIQ) */
  347. 7, /* System Peripherals */
  348. 1, /* Parallel IO Controller A, B, C and D */
  349. 0, /* MP Block Peripheral 0 */
  350. 0, /* MP Block Peripheral 1 */
  351. 0, /* MP Block Peripheral 2 */
  352. 0, /* MP Block Peripheral 3 */
  353. 0, /* MP Block Peripheral 4 */
  354. 5, /* USART 0 */
  355. 5, /* USART 1 */
  356. 5, /* USART 2 */
  357. 0, /* Multimedia Card Interface 0 */
  358. 0, /* Multimedia Card Interface 1 */
  359. 3, /* CAN */
  360. 6, /* Two-Wire Interface */
  361. 5, /* Serial Peripheral Interface 0 */
  362. 5, /* Serial Peripheral Interface 1 */
  363. 4, /* Serial Synchronous Controller 0 */
  364. 4, /* Serial Synchronous Controller 1 */
  365. 5, /* AC97 Controller */
  366. 0, /* Timer Counter 0, 1 and 2 */
  367. 0, /* Pulse Width Modulation Controller */
  368. 3, /* Ethernet */
  369. 0, /* Advanced Encryption Standard, Triple DES*/
  370. 0, /* Analog-to-Digital Converter */
  371. 0, /* Image Sensor Interface */
  372. 3, /* LCD Controller */
  373. 0, /* DMA Controller */
  374. 2, /* USB Device Port */
  375. 2, /* USB Host port */
  376. 0, /* Advanced Interrupt Controller (IRQ0) */
  377. 0, /* Advanced Interrupt Controller (IRQ1) */
  378. };
  379. void __init at91cap9_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  380. {
  381. if (!priority)
  382. priority = at91cap9_default_irq_priority;
  383. /* Initialize the AIC interrupt controller */
  384. at91_aic_init(priority);
  385. /* Enable GPIO interrupts */
  386. at91_gpio_irq_setup();
  387. }