at91cap9.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. /*
  217. * The four programmable clocks.
  218. * You must configure pin multiplexing to bring these signals out.
  219. */
  220. static struct clk pck0 = {
  221. .name = "pck0",
  222. .pmc_mask = AT91_PMC_PCK0,
  223. .type = CLK_TYPE_PROGRAMMABLE,
  224. .id = 0,
  225. };
  226. static struct clk pck1 = {
  227. .name = "pck1",
  228. .pmc_mask = AT91_PMC_PCK1,
  229. .type = CLK_TYPE_PROGRAMMABLE,
  230. .id = 1,
  231. };
  232. static struct clk pck2 = {
  233. .name = "pck2",
  234. .pmc_mask = AT91_PMC_PCK2,
  235. .type = CLK_TYPE_PROGRAMMABLE,
  236. .id = 2,
  237. };
  238. static struct clk pck3 = {
  239. .name = "pck3",
  240. .pmc_mask = AT91_PMC_PCK3,
  241. .type = CLK_TYPE_PROGRAMMABLE,
  242. .id = 3,
  243. };
  244. static void __init at91cap9_register_clocks(void)
  245. {
  246. int i;
  247. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  248. clk_register(periph_clocks[i]);
  249. clk_register(&pck0);
  250. clk_register(&pck1);
  251. clk_register(&pck2);
  252. clk_register(&pck3);
  253. }
  254. /* --------------------------------------------------------------------
  255. * GPIO
  256. * -------------------------------------------------------------------- */
  257. static struct at91_gpio_bank at91cap9_gpio[] = {
  258. {
  259. .id = AT91CAP9_ID_PIOABCD,
  260. .offset = AT91_PIOA,
  261. .clock = &pioABCD_clk,
  262. }, {
  263. .id = AT91CAP9_ID_PIOABCD,
  264. .offset = AT91_PIOB,
  265. .clock = &pioABCD_clk,
  266. }, {
  267. .id = AT91CAP9_ID_PIOABCD,
  268. .offset = AT91_PIOC,
  269. .clock = &pioABCD_clk,
  270. }, {
  271. .id = AT91CAP9_ID_PIOABCD,
  272. .offset = AT91_PIOD,
  273. .clock = &pioABCD_clk,
  274. }
  275. };
  276. static void at91cap9_reset(void)
  277. {
  278. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  279. }
  280. static void at91cap9_poweroff(void)
  281. {
  282. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  283. }
  284. /* --------------------------------------------------------------------
  285. * AT91CAP9 processor initialization
  286. * -------------------------------------------------------------------- */
  287. void __init at91cap9_initialize(unsigned long main_clock)
  288. {
  289. /* Map peripherals */
  290. iotable_init(at91cap9_io_desc, ARRAY_SIZE(at91cap9_io_desc));
  291. at91_arch_reset = at91cap9_reset;
  292. pm_power_off = at91cap9_poweroff;
  293. at91_extern_irq = (1 << AT91CAP9_ID_IRQ0) | (1 << AT91CAP9_ID_IRQ1);
  294. /* Init clock subsystem */
  295. at91_clock_init(main_clock);
  296. /* Register the processor-specific clocks */
  297. at91cap9_register_clocks();
  298. /* Register GPIO subsystem */
  299. at91_gpio_init(at91cap9_gpio, 4);
  300. /* Remember the silicon revision */
  301. if (cpu_is_at91cap9_revB())
  302. system_rev = 0xB;
  303. else if (cpu_is_at91cap9_revC())
  304. system_rev = 0xC;
  305. }
  306. /* --------------------------------------------------------------------
  307. * Interrupt initialization
  308. * -------------------------------------------------------------------- */
  309. /*
  310. * The default interrupt priority levels (0 = lowest, 7 = highest).
  311. */
  312. static unsigned int at91cap9_default_irq_priority[NR_AIC_IRQS] __initdata = {
  313. 7, /* Advanced Interrupt Controller (FIQ) */
  314. 7, /* System Peripherals */
  315. 1, /* Parallel IO Controller A, B, C and D */
  316. 0, /* MP Block Peripheral 0 */
  317. 0, /* MP Block Peripheral 1 */
  318. 0, /* MP Block Peripheral 2 */
  319. 0, /* MP Block Peripheral 3 */
  320. 0, /* MP Block Peripheral 4 */
  321. 5, /* USART 0 */
  322. 5, /* USART 1 */
  323. 5, /* USART 2 */
  324. 0, /* Multimedia Card Interface 0 */
  325. 0, /* Multimedia Card Interface 1 */
  326. 3, /* CAN */
  327. 6, /* Two-Wire Interface */
  328. 5, /* Serial Peripheral Interface 0 */
  329. 5, /* Serial Peripheral Interface 1 */
  330. 4, /* Serial Synchronous Controller 0 */
  331. 4, /* Serial Synchronous Controller 1 */
  332. 5, /* AC97 Controller */
  333. 0, /* Timer Counter 0, 1 and 2 */
  334. 0, /* Pulse Width Modulation Controller */
  335. 3, /* Ethernet */
  336. 0, /* Advanced Encryption Standard, Triple DES*/
  337. 0, /* Analog-to-Digital Converter */
  338. 0, /* Image Sensor Interface */
  339. 3, /* LCD Controller */
  340. 0, /* DMA Controller */
  341. 2, /* USB Device Port */
  342. 2, /* USB Host port */
  343. 0, /* Advanced Interrupt Controller (IRQ0) */
  344. 0, /* Advanced Interrupt Controller (IRQ1) */
  345. };
  346. void __init at91cap9_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  347. {
  348. if (!priority)
  349. priority = at91cap9_default_irq_priority;
  350. /* Initialize the AIC interrupt controller */
  351. at91_aic_init(priority);
  352. /* Enable GPIO interrupts */
  353. at91_gpio_irq_setup();
  354. }