at91sam9263.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*
  2. * arch/arm/mach-at91/at91sam9263.c
  3. *
  4. * Copyright (C) 2007 Atmel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/pm.h>
  14. #include <asm/irq.h>
  15. #include <asm/mach/arch.h>
  16. #include <asm/mach/map.h>
  17. #include <mach/at91sam9263.h>
  18. #include <mach/at91_pmc.h>
  19. #include <mach/at91_rstc.h>
  20. #include <mach/at91_shdwc.h>
  21. #include "generic.h"
  22. #include "clock.h"
  23. static struct map_desc at91sam9263_io_desc[] __initdata = {
  24. {
  25. .virtual = AT91_VA_BASE_SYS,
  26. .pfn = __phys_to_pfn(AT91_BASE_SYS),
  27. .length = SZ_16K,
  28. .type = MT_DEVICE,
  29. }, {
  30. .virtual = AT91_IO_VIRT_BASE - AT91SAM9263_SRAM0_SIZE,
  31. .pfn = __phys_to_pfn(AT91SAM9263_SRAM0_BASE),
  32. .length = AT91SAM9263_SRAM0_SIZE,
  33. .type = MT_DEVICE,
  34. }, {
  35. .virtual = AT91_IO_VIRT_BASE - AT91SAM9263_SRAM0_SIZE - AT91SAM9263_SRAM1_SIZE,
  36. .pfn = __phys_to_pfn(AT91SAM9263_SRAM1_BASE),
  37. .length = AT91SAM9263_SRAM1_SIZE,
  38. .type = MT_DEVICE,
  39. },
  40. };
  41. /* --------------------------------------------------------------------
  42. * Clocks
  43. * -------------------------------------------------------------------- */
  44. /*
  45. * The peripheral clocks.
  46. */
  47. static struct clk pioA_clk = {
  48. .name = "pioA_clk",
  49. .pmc_mask = 1 << AT91SAM9263_ID_PIOA,
  50. .type = CLK_TYPE_PERIPHERAL,
  51. };
  52. static struct clk pioB_clk = {
  53. .name = "pioB_clk",
  54. .pmc_mask = 1 << AT91SAM9263_ID_PIOB,
  55. .type = CLK_TYPE_PERIPHERAL,
  56. };
  57. static struct clk pioCDE_clk = {
  58. .name = "pioCDE_clk",
  59. .pmc_mask = 1 << AT91SAM9263_ID_PIOCDE,
  60. .type = CLK_TYPE_PERIPHERAL,
  61. };
  62. static struct clk usart0_clk = {
  63. .name = "usart0_clk",
  64. .pmc_mask = 1 << AT91SAM9263_ID_US0,
  65. .type = CLK_TYPE_PERIPHERAL,
  66. };
  67. static struct clk usart1_clk = {
  68. .name = "usart1_clk",
  69. .pmc_mask = 1 << AT91SAM9263_ID_US1,
  70. .type = CLK_TYPE_PERIPHERAL,
  71. };
  72. static struct clk usart2_clk = {
  73. .name = "usart2_clk",
  74. .pmc_mask = 1 << AT91SAM9263_ID_US2,
  75. .type = CLK_TYPE_PERIPHERAL,
  76. };
  77. static struct clk mmc0_clk = {
  78. .name = "mci0_clk",
  79. .pmc_mask = 1 << AT91SAM9263_ID_MCI0,
  80. .type = CLK_TYPE_PERIPHERAL,
  81. };
  82. static struct clk mmc1_clk = {
  83. .name = "mci1_clk",
  84. .pmc_mask = 1 << AT91SAM9263_ID_MCI1,
  85. .type = CLK_TYPE_PERIPHERAL,
  86. };
  87. static struct clk can_clk = {
  88. .name = "can_clk",
  89. .pmc_mask = 1 << AT91SAM9263_ID_CAN,
  90. .type = CLK_TYPE_PERIPHERAL,
  91. };
  92. static struct clk twi_clk = {
  93. .name = "twi_clk",
  94. .pmc_mask = 1 << AT91SAM9263_ID_TWI,
  95. .type = CLK_TYPE_PERIPHERAL,
  96. };
  97. static struct clk spi0_clk = {
  98. .name = "spi0_clk",
  99. .pmc_mask = 1 << AT91SAM9263_ID_SPI0,
  100. .type = CLK_TYPE_PERIPHERAL,
  101. };
  102. static struct clk spi1_clk = {
  103. .name = "spi1_clk",
  104. .pmc_mask = 1 << AT91SAM9263_ID_SPI1,
  105. .type = CLK_TYPE_PERIPHERAL,
  106. };
  107. static struct clk ssc0_clk = {
  108. .name = "ssc0_clk",
  109. .pmc_mask = 1 << AT91SAM9263_ID_SSC0,
  110. .type = CLK_TYPE_PERIPHERAL,
  111. };
  112. static struct clk ssc1_clk = {
  113. .name = "ssc1_clk",
  114. .pmc_mask = 1 << AT91SAM9263_ID_SSC1,
  115. .type = CLK_TYPE_PERIPHERAL,
  116. };
  117. static struct clk ac97_clk = {
  118. .name = "ac97_clk",
  119. .pmc_mask = 1 << AT91SAM9263_ID_AC97C,
  120. .type = CLK_TYPE_PERIPHERAL,
  121. };
  122. static struct clk tcb_clk = {
  123. .name = "tcb_clk",
  124. .pmc_mask = 1 << AT91SAM9263_ID_TCB,
  125. .type = CLK_TYPE_PERIPHERAL,
  126. };
  127. static struct clk pwm_clk = {
  128. .name = "pwm_clk",
  129. .pmc_mask = 1 << AT91SAM9263_ID_PWMC,
  130. .type = CLK_TYPE_PERIPHERAL,
  131. };
  132. static struct clk macb_clk = {
  133. .name = "macb_clk",
  134. .pmc_mask = 1 << AT91SAM9263_ID_EMAC,
  135. .type = CLK_TYPE_PERIPHERAL,
  136. };
  137. static struct clk dma_clk = {
  138. .name = "dma_clk",
  139. .pmc_mask = 1 << AT91SAM9263_ID_DMA,
  140. .type = CLK_TYPE_PERIPHERAL,
  141. };
  142. static struct clk twodge_clk = {
  143. .name = "2dge_clk",
  144. .pmc_mask = 1 << AT91SAM9263_ID_2DGE,
  145. .type = CLK_TYPE_PERIPHERAL,
  146. };
  147. static struct clk udc_clk = {
  148. .name = "udc_clk",
  149. .pmc_mask = 1 << AT91SAM9263_ID_UDP,
  150. .type = CLK_TYPE_PERIPHERAL,
  151. };
  152. static struct clk isi_clk = {
  153. .name = "isi_clk",
  154. .pmc_mask = 1 << AT91SAM9263_ID_ISI,
  155. .type = CLK_TYPE_PERIPHERAL,
  156. };
  157. static struct clk lcdc_clk = {
  158. .name = "lcdc_clk",
  159. .pmc_mask = 1 << AT91SAM9263_ID_LCDC,
  160. .type = CLK_TYPE_PERIPHERAL,
  161. };
  162. static struct clk ohci_clk = {
  163. .name = "ohci_clk",
  164. .pmc_mask = 1 << AT91SAM9263_ID_UHP,
  165. .type = CLK_TYPE_PERIPHERAL,
  166. };
  167. static struct clk *periph_clocks[] __initdata = {
  168. &pioA_clk,
  169. &pioB_clk,
  170. &pioCDE_clk,
  171. &usart0_clk,
  172. &usart1_clk,
  173. &usart2_clk,
  174. &mmc0_clk,
  175. &mmc1_clk,
  176. &can_clk,
  177. &twi_clk,
  178. &spi0_clk,
  179. &spi1_clk,
  180. &ssc0_clk,
  181. &ssc1_clk,
  182. &ac97_clk,
  183. &tcb_clk,
  184. &pwm_clk,
  185. &macb_clk,
  186. &twodge_clk,
  187. &udc_clk,
  188. &isi_clk,
  189. &lcdc_clk,
  190. &dma_clk,
  191. &ohci_clk,
  192. // irq0 .. irq1
  193. };
  194. /*
  195. * The four programmable clocks.
  196. * You must configure pin multiplexing to bring these signals out.
  197. */
  198. static struct clk pck0 = {
  199. .name = "pck0",
  200. .pmc_mask = AT91_PMC_PCK0,
  201. .type = CLK_TYPE_PROGRAMMABLE,
  202. .id = 0,
  203. };
  204. static struct clk pck1 = {
  205. .name = "pck1",
  206. .pmc_mask = AT91_PMC_PCK1,
  207. .type = CLK_TYPE_PROGRAMMABLE,
  208. .id = 1,
  209. };
  210. static struct clk pck2 = {
  211. .name = "pck2",
  212. .pmc_mask = AT91_PMC_PCK2,
  213. .type = CLK_TYPE_PROGRAMMABLE,
  214. .id = 2,
  215. };
  216. static struct clk pck3 = {
  217. .name = "pck3",
  218. .pmc_mask = AT91_PMC_PCK3,
  219. .type = CLK_TYPE_PROGRAMMABLE,
  220. .id = 3,
  221. };
  222. static void __init at91sam9263_register_clocks(void)
  223. {
  224. int i;
  225. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  226. clk_register(periph_clocks[i]);
  227. clk_register(&pck0);
  228. clk_register(&pck1);
  229. clk_register(&pck2);
  230. clk_register(&pck3);
  231. }
  232. /* --------------------------------------------------------------------
  233. * GPIO
  234. * -------------------------------------------------------------------- */
  235. static struct at91_gpio_bank at91sam9263_gpio[] = {
  236. {
  237. .id = AT91SAM9263_ID_PIOA,
  238. .offset = AT91_PIOA,
  239. .clock = &pioA_clk,
  240. }, {
  241. .id = AT91SAM9263_ID_PIOB,
  242. .offset = AT91_PIOB,
  243. .clock = &pioB_clk,
  244. }, {
  245. .id = AT91SAM9263_ID_PIOCDE,
  246. .offset = AT91_PIOC,
  247. .clock = &pioCDE_clk,
  248. }, {
  249. .id = AT91SAM9263_ID_PIOCDE,
  250. .offset = AT91_PIOD,
  251. .clock = &pioCDE_clk,
  252. }, {
  253. .id = AT91SAM9263_ID_PIOCDE,
  254. .offset = AT91_PIOE,
  255. .clock = &pioCDE_clk,
  256. }
  257. };
  258. static void at91sam9263_reset(void)
  259. {
  260. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  261. }
  262. static void at91sam9263_poweroff(void)
  263. {
  264. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  265. }
  266. /* --------------------------------------------------------------------
  267. * AT91SAM9263 processor initialization
  268. * -------------------------------------------------------------------- */
  269. void __init at91sam9263_initialize(unsigned long main_clock)
  270. {
  271. /* Map peripherals */
  272. iotable_init(at91sam9263_io_desc, ARRAY_SIZE(at91sam9263_io_desc));
  273. at91_arch_reset = at91sam9263_reset;
  274. pm_power_off = at91sam9263_poweroff;
  275. at91_extern_irq = (1 << AT91SAM9263_ID_IRQ0) | (1 << AT91SAM9263_ID_IRQ1);
  276. /* Init clock subsystem */
  277. at91_clock_init(main_clock);
  278. /* Register the processor-specific clocks */
  279. at91sam9263_register_clocks();
  280. /* Register GPIO subsystem */
  281. at91_gpio_init(at91sam9263_gpio, 5);
  282. }
  283. /* --------------------------------------------------------------------
  284. * Interrupt initialization
  285. * -------------------------------------------------------------------- */
  286. /*
  287. * The default interrupt priority levels (0 = lowest, 7 = highest).
  288. */
  289. static unsigned int at91sam9263_default_irq_priority[NR_AIC_IRQS] __initdata = {
  290. 7, /* Advanced Interrupt Controller (FIQ) */
  291. 7, /* System Peripherals */
  292. 1, /* Parallel IO Controller A */
  293. 1, /* Parallel IO Controller B */
  294. 1, /* Parallel IO Controller C, D and E */
  295. 0,
  296. 0,
  297. 5, /* USART 0 */
  298. 5, /* USART 1 */
  299. 5, /* USART 2 */
  300. 0, /* Multimedia Card Interface 0 */
  301. 0, /* Multimedia Card Interface 1 */
  302. 3, /* CAN */
  303. 6, /* Two-Wire Interface */
  304. 5, /* Serial Peripheral Interface 0 */
  305. 5, /* Serial Peripheral Interface 1 */
  306. 4, /* Serial Synchronous Controller 0 */
  307. 4, /* Serial Synchronous Controller 1 */
  308. 5, /* AC97 Controller */
  309. 0, /* Timer Counter 0, 1 and 2 */
  310. 0, /* Pulse Width Modulation Controller */
  311. 3, /* Ethernet */
  312. 0,
  313. 0, /* 2D Graphic Engine */
  314. 2, /* USB Device Port */
  315. 0, /* Image Sensor Interface */
  316. 3, /* LDC Controller */
  317. 0, /* DMA Controller */
  318. 0,
  319. 2, /* USB Host port */
  320. 0, /* Advanced Interrupt Controller (IRQ0) */
  321. 0, /* Advanced Interrupt Controller (IRQ1) */
  322. };
  323. void __init at91sam9263_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  324. {
  325. if (!priority)
  326. priority = at91sam9263_default_irq_priority;
  327. /* Initialize the AIC interrupt controller */
  328. at91_aic_init(priority);
  329. /* Enable GPIO interrupts */
  330. at91_gpio_irq_setup();
  331. }