at91cap9.c 9.0 KB

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