at91cap9.c 8.9 KB

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