at91sam9261.c 7.4 KB

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