at91rm9200.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /*
  2. * arch/arm/mach-at91/at91rm9200.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/irq.h>
  14. #include <asm/mach/arch.h>
  15. #include <asm/mach/map.h>
  16. #include <mach/at91rm9200.h>
  17. #include <mach/at91_pmc.h>
  18. #include <mach/at91_st.h>
  19. #include "generic.h"
  20. #include "clock.h"
  21. static struct map_desc at91rm9200_io_desc[] __initdata = {
  22. {
  23. .virtual = AT91_VA_BASE_SYS,
  24. .pfn = __phys_to_pfn(AT91_BASE_SYS),
  25. .length = SZ_4K,
  26. .type = MT_DEVICE,
  27. }, {
  28. .virtual = AT91_VA_BASE_EMAC,
  29. .pfn = __phys_to_pfn(AT91RM9200_BASE_EMAC),
  30. .length = SZ_16K,
  31. .type = MT_DEVICE,
  32. }, {
  33. .virtual = AT91_IO_VIRT_BASE - AT91RM9200_SRAM_SIZE,
  34. .pfn = __phys_to_pfn(AT91RM9200_SRAM_BASE),
  35. .length = AT91RM9200_SRAM_SIZE,
  36. .type = MT_DEVICE,
  37. },
  38. };
  39. /* --------------------------------------------------------------------
  40. * Clocks
  41. * -------------------------------------------------------------------- */
  42. /*
  43. * The peripheral clocks.
  44. */
  45. static struct clk udc_clk = {
  46. .name = "udc_clk",
  47. .pmc_mask = 1 << AT91RM9200_ID_UDP,
  48. .type = CLK_TYPE_PERIPHERAL,
  49. };
  50. static struct clk ohci_clk = {
  51. .name = "ohci_clk",
  52. .pmc_mask = 1 << AT91RM9200_ID_UHP,
  53. .type = CLK_TYPE_PERIPHERAL,
  54. };
  55. static struct clk ether_clk = {
  56. .name = "ether_clk",
  57. .pmc_mask = 1 << AT91RM9200_ID_EMAC,
  58. .type = CLK_TYPE_PERIPHERAL,
  59. };
  60. static struct clk mmc_clk = {
  61. .name = "mci_clk",
  62. .pmc_mask = 1 << AT91RM9200_ID_MCI,
  63. .type = CLK_TYPE_PERIPHERAL,
  64. };
  65. static struct clk twi_clk = {
  66. .name = "twi_clk",
  67. .pmc_mask = 1 << AT91RM9200_ID_TWI,
  68. .type = CLK_TYPE_PERIPHERAL,
  69. };
  70. static struct clk usart0_clk = {
  71. .name = "usart0_clk",
  72. .pmc_mask = 1 << AT91RM9200_ID_US0,
  73. .type = CLK_TYPE_PERIPHERAL,
  74. };
  75. static struct clk usart1_clk = {
  76. .name = "usart1_clk",
  77. .pmc_mask = 1 << AT91RM9200_ID_US1,
  78. .type = CLK_TYPE_PERIPHERAL,
  79. };
  80. static struct clk usart2_clk = {
  81. .name = "usart2_clk",
  82. .pmc_mask = 1 << AT91RM9200_ID_US2,
  83. .type = CLK_TYPE_PERIPHERAL,
  84. };
  85. static struct clk usart3_clk = {
  86. .name = "usart3_clk",
  87. .pmc_mask = 1 << AT91RM9200_ID_US3,
  88. .type = CLK_TYPE_PERIPHERAL,
  89. };
  90. static struct clk spi_clk = {
  91. .name = "spi_clk",
  92. .pmc_mask = 1 << AT91RM9200_ID_SPI,
  93. .type = CLK_TYPE_PERIPHERAL,
  94. };
  95. static struct clk pioA_clk = {
  96. .name = "pioA_clk",
  97. .pmc_mask = 1 << AT91RM9200_ID_PIOA,
  98. .type = CLK_TYPE_PERIPHERAL,
  99. };
  100. static struct clk pioB_clk = {
  101. .name = "pioB_clk",
  102. .pmc_mask = 1 << AT91RM9200_ID_PIOB,
  103. .type = CLK_TYPE_PERIPHERAL,
  104. };
  105. static struct clk pioC_clk = {
  106. .name = "pioC_clk",
  107. .pmc_mask = 1 << AT91RM9200_ID_PIOC,
  108. .type = CLK_TYPE_PERIPHERAL,
  109. };
  110. static struct clk pioD_clk = {
  111. .name = "pioD_clk",
  112. .pmc_mask = 1 << AT91RM9200_ID_PIOD,
  113. .type = CLK_TYPE_PERIPHERAL,
  114. };
  115. static struct clk ssc0_clk = {
  116. .name = "ssc0_clk",
  117. .pmc_mask = 1 << AT91RM9200_ID_SSC0,
  118. .type = CLK_TYPE_PERIPHERAL,
  119. };
  120. static struct clk ssc1_clk = {
  121. .name = "ssc1_clk",
  122. .pmc_mask = 1 << AT91RM9200_ID_SSC1,
  123. .type = CLK_TYPE_PERIPHERAL,
  124. };
  125. static struct clk ssc2_clk = {
  126. .name = "ssc2_clk",
  127. .pmc_mask = 1 << AT91RM9200_ID_SSC2,
  128. .type = CLK_TYPE_PERIPHERAL,
  129. };
  130. static struct clk tc0_clk = {
  131. .name = "tc0_clk",
  132. .pmc_mask = 1 << AT91RM9200_ID_TC0,
  133. .type = CLK_TYPE_PERIPHERAL,
  134. };
  135. static struct clk tc1_clk = {
  136. .name = "tc1_clk",
  137. .pmc_mask = 1 << AT91RM9200_ID_TC1,
  138. .type = CLK_TYPE_PERIPHERAL,
  139. };
  140. static struct clk tc2_clk = {
  141. .name = "tc2_clk",
  142. .pmc_mask = 1 << AT91RM9200_ID_TC2,
  143. .type = CLK_TYPE_PERIPHERAL,
  144. };
  145. static struct clk tc3_clk = {
  146. .name = "tc3_clk",
  147. .pmc_mask = 1 << AT91RM9200_ID_TC3,
  148. .type = CLK_TYPE_PERIPHERAL,
  149. };
  150. static struct clk tc4_clk = {
  151. .name = "tc4_clk",
  152. .pmc_mask = 1 << AT91RM9200_ID_TC4,
  153. .type = CLK_TYPE_PERIPHERAL,
  154. };
  155. static struct clk tc5_clk = {
  156. .name = "tc5_clk",
  157. .pmc_mask = 1 << AT91RM9200_ID_TC5,
  158. .type = CLK_TYPE_PERIPHERAL,
  159. };
  160. static struct clk *periph_clocks[] __initdata = {
  161. &pioA_clk,
  162. &pioB_clk,
  163. &pioC_clk,
  164. &pioD_clk,
  165. &usart0_clk,
  166. &usart1_clk,
  167. &usart2_clk,
  168. &usart3_clk,
  169. &mmc_clk,
  170. &udc_clk,
  171. &twi_clk,
  172. &spi_clk,
  173. &ssc0_clk,
  174. &ssc1_clk,
  175. &ssc2_clk,
  176. &tc0_clk,
  177. &tc1_clk,
  178. &tc2_clk,
  179. &tc3_clk,
  180. &tc4_clk,
  181. &tc5_clk,
  182. &ohci_clk,
  183. &ether_clk,
  184. // irq0 .. irq6
  185. };
  186. /*
  187. * The four programmable clocks.
  188. * You must configure pin multiplexing to bring these signals out.
  189. */
  190. static struct clk pck0 = {
  191. .name = "pck0",
  192. .pmc_mask = AT91_PMC_PCK0,
  193. .type = CLK_TYPE_PROGRAMMABLE,
  194. .id = 0,
  195. };
  196. static struct clk pck1 = {
  197. .name = "pck1",
  198. .pmc_mask = AT91_PMC_PCK1,
  199. .type = CLK_TYPE_PROGRAMMABLE,
  200. .id = 1,
  201. };
  202. static struct clk pck2 = {
  203. .name = "pck2",
  204. .pmc_mask = AT91_PMC_PCK2,
  205. .type = CLK_TYPE_PROGRAMMABLE,
  206. .id = 2,
  207. };
  208. static struct clk pck3 = {
  209. .name = "pck3",
  210. .pmc_mask = AT91_PMC_PCK3,
  211. .type = CLK_TYPE_PROGRAMMABLE,
  212. .id = 3,
  213. };
  214. static void __init at91rm9200_register_clocks(void)
  215. {
  216. int i;
  217. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  218. clk_register(periph_clocks[i]);
  219. clk_register(&pck0);
  220. clk_register(&pck1);
  221. clk_register(&pck2);
  222. clk_register(&pck3);
  223. }
  224. /* --------------------------------------------------------------------
  225. * GPIO
  226. * -------------------------------------------------------------------- */
  227. static struct at91_gpio_bank at91rm9200_gpio[] = {
  228. {
  229. .id = AT91RM9200_ID_PIOA,
  230. .offset = AT91_PIOA,
  231. .clock = &pioA_clk,
  232. }, {
  233. .id = AT91RM9200_ID_PIOB,
  234. .offset = AT91_PIOB,
  235. .clock = &pioB_clk,
  236. }, {
  237. .id = AT91RM9200_ID_PIOC,
  238. .offset = AT91_PIOC,
  239. .clock = &pioC_clk,
  240. }, {
  241. .id = AT91RM9200_ID_PIOD,
  242. .offset = AT91_PIOD,
  243. .clock = &pioD_clk,
  244. }
  245. };
  246. static void at91rm9200_reset(void)
  247. {
  248. /*
  249. * Perform a hardware reset with the use of the Watchdog timer.
  250. */
  251. at91_sys_write(AT91_ST_WDMR, AT91_ST_RSTEN | AT91_ST_EXTEN | 1);
  252. at91_sys_write(AT91_ST_CR, AT91_ST_WDRST);
  253. }
  254. /* --------------------------------------------------------------------
  255. * AT91RM9200 processor initialization
  256. * -------------------------------------------------------------------- */
  257. void __init at91rm9200_initialize(unsigned long main_clock, unsigned short banks)
  258. {
  259. /* Map peripherals */
  260. iotable_init(at91rm9200_io_desc, ARRAY_SIZE(at91rm9200_io_desc));
  261. at91_arch_reset = at91rm9200_reset;
  262. at91_extern_irq = (1 << AT91RM9200_ID_IRQ0) | (1 << AT91RM9200_ID_IRQ1)
  263. | (1 << AT91RM9200_ID_IRQ2) | (1 << AT91RM9200_ID_IRQ3)
  264. | (1 << AT91RM9200_ID_IRQ4) | (1 << AT91RM9200_ID_IRQ5)
  265. | (1 << AT91RM9200_ID_IRQ6);
  266. /* Init clock subsystem */
  267. at91_clock_init(main_clock);
  268. /* Register the processor-specific clocks */
  269. at91rm9200_register_clocks();
  270. /* Initialize GPIO subsystem */
  271. at91_gpio_init(at91rm9200_gpio, banks);
  272. }
  273. /* --------------------------------------------------------------------
  274. * Interrupt initialization
  275. * -------------------------------------------------------------------- */
  276. /*
  277. * The default interrupt priority levels (0 = lowest, 7 = highest).
  278. */
  279. static unsigned int at91rm9200_default_irq_priority[NR_AIC_IRQS] __initdata = {
  280. 7, /* Advanced Interrupt Controller (FIQ) */
  281. 7, /* System Peripherals */
  282. 1, /* Parallel IO Controller A */
  283. 1, /* Parallel IO Controller B */
  284. 1, /* Parallel IO Controller C */
  285. 1, /* Parallel IO Controller D */
  286. 5, /* USART 0 */
  287. 5, /* USART 1 */
  288. 5, /* USART 2 */
  289. 5, /* USART 3 */
  290. 0, /* Multimedia Card Interface */
  291. 2, /* USB Device Port */
  292. 6, /* Two-Wire Interface */
  293. 5, /* Serial Peripheral Interface */
  294. 4, /* Serial Synchronous Controller 0 */
  295. 4, /* Serial Synchronous Controller 1 */
  296. 4, /* Serial Synchronous Controller 2 */
  297. 0, /* Timer Counter 0 */
  298. 0, /* Timer Counter 1 */
  299. 0, /* Timer Counter 2 */
  300. 0, /* Timer Counter 3 */
  301. 0, /* Timer Counter 4 */
  302. 0, /* Timer Counter 5 */
  303. 2, /* USB Host port */
  304. 3, /* Ethernet MAC */
  305. 0, /* Advanced Interrupt Controller (IRQ0) */
  306. 0, /* Advanced Interrupt Controller (IRQ1) */
  307. 0, /* Advanced Interrupt Controller (IRQ2) */
  308. 0, /* Advanced Interrupt Controller (IRQ3) */
  309. 0, /* Advanced Interrupt Controller (IRQ4) */
  310. 0, /* Advanced Interrupt Controller (IRQ5) */
  311. 0 /* Advanced Interrupt Controller (IRQ6) */
  312. };
  313. void __init at91rm9200_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  314. {
  315. if (!priority)
  316. priority = at91rm9200_default_irq_priority;
  317. /* Initialize the AIC interrupt controller */
  318. at91_aic_init(priority);
  319. /* Enable GPIO interrupts */
  320. at91_gpio_irq_setup();
  321. }