at91sam9261.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. * arch/arm/mach-at91/at91sam9261.c
  3. *
  4. * Copyright (C) 2005 SAN People
  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/at91sam9261.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 at91sam9261_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 - AT91SAM9261_SRAM_SIZE,
  31. .pfn = __phys_to_pfn(AT91SAM9261_SRAM_BASE),
  32. .length = AT91SAM9261_SRAM_SIZE,
  33. .type = MT_DEVICE,
  34. },
  35. };
  36. /* --------------------------------------------------------------------
  37. * Clocks
  38. * -------------------------------------------------------------------- */
  39. /*
  40. * The peripheral clocks.
  41. */
  42. static struct clk pioA_clk = {
  43. .name = "pioA_clk",
  44. .pmc_mask = 1 << AT91SAM9261_ID_PIOA,
  45. .type = CLK_TYPE_PERIPHERAL,
  46. };
  47. static struct clk pioB_clk = {
  48. .name = "pioB_clk",
  49. .pmc_mask = 1 << AT91SAM9261_ID_PIOB,
  50. .type = CLK_TYPE_PERIPHERAL,
  51. };
  52. static struct clk pioC_clk = {
  53. .name = "pioC_clk",
  54. .pmc_mask = 1 << AT91SAM9261_ID_PIOC,
  55. .type = CLK_TYPE_PERIPHERAL,
  56. };
  57. static struct clk usart0_clk = {
  58. .name = "usart0_clk",
  59. .pmc_mask = 1 << AT91SAM9261_ID_US0,
  60. .type = CLK_TYPE_PERIPHERAL,
  61. };
  62. static struct clk usart1_clk = {
  63. .name = "usart1_clk",
  64. .pmc_mask = 1 << AT91SAM9261_ID_US1,
  65. .type = CLK_TYPE_PERIPHERAL,
  66. };
  67. static struct clk usart2_clk = {
  68. .name = "usart2_clk",
  69. .pmc_mask = 1 << AT91SAM9261_ID_US2,
  70. .type = CLK_TYPE_PERIPHERAL,
  71. };
  72. static struct clk mmc_clk = {
  73. .name = "mci_clk",
  74. .pmc_mask = 1 << AT91SAM9261_ID_MCI,
  75. .type = CLK_TYPE_PERIPHERAL,
  76. };
  77. static struct clk udc_clk = {
  78. .name = "udc_clk",
  79. .pmc_mask = 1 << AT91SAM9261_ID_UDP,
  80. .type = CLK_TYPE_PERIPHERAL,
  81. };
  82. static struct clk twi_clk = {
  83. .name = "twi_clk",
  84. .pmc_mask = 1 << AT91SAM9261_ID_TWI,
  85. .type = CLK_TYPE_PERIPHERAL,
  86. };
  87. static struct clk spi0_clk = {
  88. .name = "spi0_clk",
  89. .pmc_mask = 1 << AT91SAM9261_ID_SPI0,
  90. .type = CLK_TYPE_PERIPHERAL,
  91. };
  92. static struct clk spi1_clk = {
  93. .name = "spi1_clk",
  94. .pmc_mask = 1 << AT91SAM9261_ID_SPI1,
  95. .type = CLK_TYPE_PERIPHERAL,
  96. };
  97. static struct clk ssc0_clk = {
  98. .name = "ssc0_clk",
  99. .pmc_mask = 1 << AT91SAM9261_ID_SSC0,
  100. .type = CLK_TYPE_PERIPHERAL,
  101. };
  102. static struct clk ssc1_clk = {
  103. .name = "ssc1_clk",
  104. .pmc_mask = 1 << AT91SAM9261_ID_SSC1,
  105. .type = CLK_TYPE_PERIPHERAL,
  106. };
  107. static struct clk ssc2_clk = {
  108. .name = "ssc2_clk",
  109. .pmc_mask = 1 << AT91SAM9261_ID_SSC2,
  110. .type = CLK_TYPE_PERIPHERAL,
  111. };
  112. static struct clk tc0_clk = {
  113. .name = "tc0_clk",
  114. .pmc_mask = 1 << AT91SAM9261_ID_TC0,
  115. .type = CLK_TYPE_PERIPHERAL,
  116. };
  117. static struct clk tc1_clk = {
  118. .name = "tc1_clk",
  119. .pmc_mask = 1 << AT91SAM9261_ID_TC1,
  120. .type = CLK_TYPE_PERIPHERAL,
  121. };
  122. static struct clk tc2_clk = {
  123. .name = "tc2_clk",
  124. .pmc_mask = 1 << AT91SAM9261_ID_TC2,
  125. .type = CLK_TYPE_PERIPHERAL,
  126. };
  127. static struct clk ohci_clk = {
  128. .name = "ohci_clk",
  129. .pmc_mask = 1 << AT91SAM9261_ID_UHP,
  130. .type = CLK_TYPE_PERIPHERAL,
  131. };
  132. static struct clk lcdc_clk = {
  133. .name = "lcdc_clk",
  134. .pmc_mask = 1 << AT91SAM9261_ID_LCDC,
  135. .type = CLK_TYPE_PERIPHERAL,
  136. };
  137. static struct clk *periph_clocks[] __initdata = {
  138. &pioA_clk,
  139. &pioB_clk,
  140. &pioC_clk,
  141. &usart0_clk,
  142. &usart1_clk,
  143. &usart2_clk,
  144. &mmc_clk,
  145. &udc_clk,
  146. &twi_clk,
  147. &spi0_clk,
  148. &spi1_clk,
  149. &ssc0_clk,
  150. &ssc1_clk,
  151. &ssc2_clk,
  152. &tc0_clk,
  153. &tc1_clk,
  154. &tc2_clk,
  155. &ohci_clk,
  156. &lcdc_clk,
  157. // irq0 .. irq2
  158. };
  159. /*
  160. * The four programmable clocks.
  161. * You must configure pin multiplexing to bring these signals out.
  162. */
  163. static struct clk pck0 = {
  164. .name = "pck0",
  165. .pmc_mask = AT91_PMC_PCK0,
  166. .type = CLK_TYPE_PROGRAMMABLE,
  167. .id = 0,
  168. };
  169. static struct clk pck1 = {
  170. .name = "pck1",
  171. .pmc_mask = AT91_PMC_PCK1,
  172. .type = CLK_TYPE_PROGRAMMABLE,
  173. .id = 1,
  174. };
  175. static struct clk pck2 = {
  176. .name = "pck2",
  177. .pmc_mask = AT91_PMC_PCK2,
  178. .type = CLK_TYPE_PROGRAMMABLE,
  179. .id = 2,
  180. };
  181. static struct clk pck3 = {
  182. .name = "pck3",
  183. .pmc_mask = AT91_PMC_PCK3,
  184. .type = CLK_TYPE_PROGRAMMABLE,
  185. .id = 3,
  186. };
  187. /* HClocks */
  188. static struct clk hck0 = {
  189. .name = "hck0",
  190. .pmc_mask = AT91_PMC_HCK0,
  191. .type = CLK_TYPE_SYSTEM,
  192. .id = 0,
  193. };
  194. static struct clk hck1 = {
  195. .name = "hck1",
  196. .pmc_mask = AT91_PMC_HCK1,
  197. .type = CLK_TYPE_SYSTEM,
  198. .id = 1,
  199. };
  200. static void __init at91sam9261_register_clocks(void)
  201. {
  202. int i;
  203. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  204. clk_register(periph_clocks[i]);
  205. clk_register(&pck0);
  206. clk_register(&pck1);
  207. clk_register(&pck2);
  208. clk_register(&pck3);
  209. clk_register(&hck0);
  210. clk_register(&hck1);
  211. }
  212. /* --------------------------------------------------------------------
  213. * GPIO
  214. * -------------------------------------------------------------------- */
  215. static struct at91_gpio_bank at91sam9261_gpio[] = {
  216. {
  217. .id = AT91SAM9261_ID_PIOA,
  218. .offset = AT91_PIOA,
  219. .clock = &pioA_clk,
  220. }, {
  221. .id = AT91SAM9261_ID_PIOB,
  222. .offset = AT91_PIOB,
  223. .clock = &pioB_clk,
  224. }, {
  225. .id = AT91SAM9261_ID_PIOC,
  226. .offset = AT91_PIOC,
  227. .clock = &pioC_clk,
  228. }
  229. };
  230. static void at91sam9261_reset(void)
  231. {
  232. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  233. }
  234. static void at91sam9261_poweroff(void)
  235. {
  236. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  237. }
  238. /* --------------------------------------------------------------------
  239. * AT91SAM9261 processor initialization
  240. * -------------------------------------------------------------------- */
  241. void __init at91sam9261_initialize(unsigned long main_clock)
  242. {
  243. /* Map peripherals */
  244. iotable_init(at91sam9261_io_desc, ARRAY_SIZE(at91sam9261_io_desc));
  245. at91_arch_reset = at91sam9261_reset;
  246. pm_power_off = at91sam9261_poweroff;
  247. at91_extern_irq = (1 << AT91SAM9261_ID_IRQ0) | (1 << AT91SAM9261_ID_IRQ1)
  248. | (1 << AT91SAM9261_ID_IRQ2);
  249. /* Init clock subsystem */
  250. at91_clock_init(main_clock);
  251. /* Register the processor-specific clocks */
  252. at91sam9261_register_clocks();
  253. /* Register GPIO subsystem */
  254. at91_gpio_init(at91sam9261_gpio, 3);
  255. }
  256. /* --------------------------------------------------------------------
  257. * Interrupt initialization
  258. * -------------------------------------------------------------------- */
  259. /*
  260. * The default interrupt priority levels (0 = lowest, 7 = highest).
  261. */
  262. static unsigned int at91sam9261_default_irq_priority[NR_AIC_IRQS] __initdata = {
  263. 7, /* Advanced Interrupt Controller */
  264. 7, /* System Peripherals */
  265. 1, /* Parallel IO Controller A */
  266. 1, /* Parallel IO Controller B */
  267. 1, /* Parallel IO Controller C */
  268. 0,
  269. 5, /* USART 0 */
  270. 5, /* USART 1 */
  271. 5, /* USART 2 */
  272. 0, /* Multimedia Card Interface */
  273. 2, /* USB Device Port */
  274. 6, /* Two-Wire Interface */
  275. 5, /* Serial Peripheral Interface 0 */
  276. 5, /* Serial Peripheral Interface 1 */
  277. 4, /* Serial Synchronous Controller 0 */
  278. 4, /* Serial Synchronous Controller 1 */
  279. 4, /* Serial Synchronous Controller 2 */
  280. 0, /* Timer Counter 0 */
  281. 0, /* Timer Counter 1 */
  282. 0, /* Timer Counter 2 */
  283. 2, /* USB Host port */
  284. 3, /* LCD Controller */
  285. 0,
  286. 0,
  287. 0,
  288. 0,
  289. 0,
  290. 0,
  291. 0,
  292. 0, /* Advanced Interrupt Controller */
  293. 0, /* Advanced Interrupt Controller */
  294. 0, /* Advanced Interrupt Controller */
  295. };
  296. void __init at91sam9261_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  297. {
  298. if (!priority)
  299. priority = at91sam9261_default_irq_priority;
  300. /* Initialize the AIC interrupt controller */
  301. at91_aic_init(priority);
  302. /* Enable GPIO interrupts */
  303. at91_gpio_irq_setup();
  304. }