at91sam9263.c 8.5 KB

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