at91rm9200.c 8.3 KB

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