at91sam9261.c 7.6 KB

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