at91sam9263.c 9.6 KB

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