at91sam9rl.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. * arch/arm/mach-at91/at91sam9rl.c
  3. *
  4. * Copyright (C) 2005 SAN People
  5. * Copyright (C) 2007 Atmel Corporation
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive for
  9. * more details.
  10. */
  11. #include <linux/module.h>
  12. #include <asm/mach/arch.h>
  13. #include <asm/mach/map.h>
  14. #include <asm/arch/cpu.h>
  15. #include <asm/arch/at91sam9rl.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 at91sam9rl_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. };
  28. static struct map_desc at91sam9rl_sram_desc[] __initdata = {
  29. {
  30. .pfn = __phys_to_pfn(AT91SAM9RL_SRAM_BASE),
  31. .type = MT_DEVICE,
  32. }
  33. };
  34. /* --------------------------------------------------------------------
  35. * Clocks
  36. * -------------------------------------------------------------------- */
  37. /*
  38. * The peripheral clocks.
  39. */
  40. static struct clk pioA_clk = {
  41. .name = "pioA_clk",
  42. .pmc_mask = 1 << AT91SAM9RL_ID_PIOA,
  43. .type = CLK_TYPE_PERIPHERAL,
  44. };
  45. static struct clk pioB_clk = {
  46. .name = "pioB_clk",
  47. .pmc_mask = 1 << AT91SAM9RL_ID_PIOB,
  48. .type = CLK_TYPE_PERIPHERAL,
  49. };
  50. static struct clk pioC_clk = {
  51. .name = "pioC_clk",
  52. .pmc_mask = 1 << AT91SAM9RL_ID_PIOC,
  53. .type = CLK_TYPE_PERIPHERAL,
  54. };
  55. static struct clk pioD_clk = {
  56. .name = "pioD_clk",
  57. .pmc_mask = 1 << AT91SAM9RL_ID_PIOD,
  58. .type = CLK_TYPE_PERIPHERAL,
  59. };
  60. static struct clk usart0_clk = {
  61. .name = "usart0_clk",
  62. .pmc_mask = 1 << AT91SAM9RL_ID_US0,
  63. .type = CLK_TYPE_PERIPHERAL,
  64. };
  65. static struct clk usart1_clk = {
  66. .name = "usart1_clk",
  67. .pmc_mask = 1 << AT91SAM9RL_ID_US1,
  68. .type = CLK_TYPE_PERIPHERAL,
  69. };
  70. static struct clk usart2_clk = {
  71. .name = "usart2_clk",
  72. .pmc_mask = 1 << AT91SAM9RL_ID_US2,
  73. .type = CLK_TYPE_PERIPHERAL,
  74. };
  75. static struct clk usart3_clk = {
  76. .name = "usart3_clk",
  77. .pmc_mask = 1 << AT91SAM9RL_ID_US3,
  78. .type = CLK_TYPE_PERIPHERAL,
  79. };
  80. static struct clk mmc_clk = {
  81. .name = "mci_clk",
  82. .pmc_mask = 1 << AT91SAM9RL_ID_MCI,
  83. .type = CLK_TYPE_PERIPHERAL,
  84. };
  85. static struct clk twi0_clk = {
  86. .name = "twi0_clk",
  87. .pmc_mask = 1 << AT91SAM9RL_ID_TWI0,
  88. .type = CLK_TYPE_PERIPHERAL,
  89. };
  90. static struct clk twi1_clk = {
  91. .name = "twi1_clk",
  92. .pmc_mask = 1 << AT91SAM9RL_ID_TWI1,
  93. .type = CLK_TYPE_PERIPHERAL,
  94. };
  95. static struct clk spi_clk = {
  96. .name = "spi_clk",
  97. .pmc_mask = 1 << AT91SAM9RL_ID_SPI,
  98. .type = CLK_TYPE_PERIPHERAL,
  99. };
  100. static struct clk ssc0_clk = {
  101. .name = "ssc0_clk",
  102. .pmc_mask = 1 << AT91SAM9RL_ID_SSC0,
  103. .type = CLK_TYPE_PERIPHERAL,
  104. };
  105. static struct clk ssc1_clk = {
  106. .name = "ssc1_clk",
  107. .pmc_mask = 1 << AT91SAM9RL_ID_SSC1,
  108. .type = CLK_TYPE_PERIPHERAL,
  109. };
  110. static struct clk tc0_clk = {
  111. .name = "tc0_clk",
  112. .pmc_mask = 1 << AT91SAM9RL_ID_TC0,
  113. .type = CLK_TYPE_PERIPHERAL,
  114. };
  115. static struct clk tc1_clk = {
  116. .name = "tc1_clk",
  117. .pmc_mask = 1 << AT91SAM9RL_ID_TC1,
  118. .type = CLK_TYPE_PERIPHERAL,
  119. };
  120. static struct clk tc2_clk = {
  121. .name = "tc2_clk",
  122. .pmc_mask = 1 << AT91SAM9RL_ID_TC2,
  123. .type = CLK_TYPE_PERIPHERAL,
  124. };
  125. static struct clk pwmc_clk = {
  126. .name = "pwmc_clk",
  127. .pmc_mask = 1 << AT91SAM9RL_ID_PWMC,
  128. .type = CLK_TYPE_PERIPHERAL,
  129. };
  130. static struct clk tsc_clk = {
  131. .name = "tsc_clk",
  132. .pmc_mask = 1 << AT91SAM9RL_ID_TSC,
  133. .type = CLK_TYPE_PERIPHERAL,
  134. };
  135. static struct clk dma_clk = {
  136. .name = "dma_clk",
  137. .pmc_mask = 1 << AT91SAM9RL_ID_DMA,
  138. .type = CLK_TYPE_PERIPHERAL,
  139. };
  140. static struct clk udphs_clk = {
  141. .name = "udphs_clk",
  142. .pmc_mask = 1 << AT91SAM9RL_ID_UDPHS,
  143. .type = CLK_TYPE_PERIPHERAL,
  144. };
  145. static struct clk lcdc_clk = {
  146. .name = "lcdc_clk",
  147. .pmc_mask = 1 << AT91SAM9RL_ID_LCDC,
  148. .type = CLK_TYPE_PERIPHERAL,
  149. };
  150. static struct clk ac97_clk = {
  151. .name = "ac97_clk",
  152. .pmc_mask = 1 << AT91SAM9RL_ID_AC97C,
  153. .type = CLK_TYPE_PERIPHERAL,
  154. };
  155. static struct clk *periph_clocks[] __initdata = {
  156. &pioA_clk,
  157. &pioB_clk,
  158. &pioC_clk,
  159. &pioD_clk,
  160. &usart0_clk,
  161. &usart1_clk,
  162. &usart2_clk,
  163. &usart3_clk,
  164. &mmc_clk,
  165. &twi0_clk,
  166. &twi1_clk,
  167. &spi_clk,
  168. &ssc0_clk,
  169. &ssc1_clk,
  170. &tc0_clk,
  171. &tc1_clk,
  172. &tc2_clk,
  173. &pwmc_clk,
  174. &tsc_clk,
  175. &dma_clk,
  176. &udphs_clk,
  177. &lcdc_clk,
  178. &ac97_clk,
  179. // irq0
  180. };
  181. /*
  182. * The two programmable clocks.
  183. * You must configure pin multiplexing to bring these signals out.
  184. */
  185. static struct clk pck0 = {
  186. .name = "pck0",
  187. .pmc_mask = AT91_PMC_PCK0,
  188. .type = CLK_TYPE_PROGRAMMABLE,
  189. .id = 0,
  190. };
  191. static struct clk pck1 = {
  192. .name = "pck1",
  193. .pmc_mask = AT91_PMC_PCK1,
  194. .type = CLK_TYPE_PROGRAMMABLE,
  195. .id = 1,
  196. };
  197. static void __init at91sam9rl_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. }
  205. /* --------------------------------------------------------------------
  206. * GPIO
  207. * -------------------------------------------------------------------- */
  208. static struct at91_gpio_bank at91sam9rl_gpio[] = {
  209. {
  210. .id = AT91SAM9RL_ID_PIOA,
  211. .offset = AT91_PIOA,
  212. .clock = &pioA_clk,
  213. }, {
  214. .id = AT91SAM9RL_ID_PIOB,
  215. .offset = AT91_PIOB,
  216. .clock = &pioB_clk,
  217. }, {
  218. .id = AT91SAM9RL_ID_PIOC,
  219. .offset = AT91_PIOC,
  220. .clock = &pioC_clk,
  221. }, {
  222. .id = AT91SAM9RL_ID_PIOD,
  223. .offset = AT91_PIOD,
  224. .clock = &pioD_clk,
  225. }
  226. };
  227. static void at91sam9rl_reset(void)
  228. {
  229. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  230. }
  231. /* --------------------------------------------------------------------
  232. * AT91SAM9RL processor initialization
  233. * -------------------------------------------------------------------- */
  234. void __init at91sam9rl_initialize(unsigned long main_clock)
  235. {
  236. unsigned long cidr, sram_size;
  237. /* Map peripherals */
  238. iotable_init(at91sam9rl_io_desc, ARRAY_SIZE(at91sam9rl_io_desc));
  239. cidr = at91_sys_read(AT91_DBGU_CIDR);
  240. switch (cidr & AT91_CIDR_SRAMSIZ) {
  241. case AT91_CIDR_SRAMSIZ_32K:
  242. sram_size = 2 * SZ_16K;
  243. break;
  244. case AT91_CIDR_SRAMSIZ_16K:
  245. default:
  246. sram_size = SZ_16K;
  247. }
  248. at91sam9rl_sram_desc->virtual = AT91_IO_VIRT_BASE - sram_size;
  249. at91sam9rl_sram_desc->length = sram_size;
  250. /* Map SRAM */
  251. iotable_init(at91sam9rl_sram_desc, ARRAY_SIZE(at91sam9rl_sram_desc));
  252. at91_arch_reset = at91sam9rl_reset;
  253. at91_extern_irq = (1 << AT91SAM9RL_ID_IRQ0);
  254. /* Init clock subsystem */
  255. at91_clock_init(main_clock);
  256. /* Register the processor-specific clocks */
  257. at91sam9rl_register_clocks();
  258. /* Register GPIO subsystem */
  259. at91_gpio_init(at91sam9rl_gpio, 4);
  260. }
  261. /* --------------------------------------------------------------------
  262. * Interrupt initialization
  263. * -------------------------------------------------------------------- */
  264. /*
  265. * The default interrupt priority levels (0 = lowest, 7 = highest).
  266. */
  267. static unsigned int at91sam9rl_default_irq_priority[NR_AIC_IRQS] __initdata = {
  268. 7, /* Advanced Interrupt Controller */
  269. 7, /* System Peripherals */
  270. 1, /* Parallel IO Controller A */
  271. 1, /* Parallel IO Controller B */
  272. 1, /* Parallel IO Controller C */
  273. 1, /* Parallel IO Controller D */
  274. 5, /* USART 0 */
  275. 5, /* USART 1 */
  276. 5, /* USART 2 */
  277. 5, /* USART 3 */
  278. 0, /* Multimedia Card Interface */
  279. 6, /* Two-Wire Interface 0 */
  280. 6, /* Two-Wire Interface 1 */
  281. 5, /* Serial Peripheral Interface */
  282. 4, /* Serial Synchronous Controller 0 */
  283. 4, /* Serial Synchronous Controller 1 */
  284. 0, /* Timer Counter 0 */
  285. 0, /* Timer Counter 1 */
  286. 0, /* Timer Counter 2 */
  287. 0,
  288. 0, /* Touch Screen Controller */
  289. 0, /* DMA Controller */
  290. 2, /* USB Device High speed port */
  291. 2, /* LCD Controller */
  292. 6, /* AC97 Controller */
  293. 0,
  294. 0,
  295. 0,
  296. 0,
  297. 0,
  298. 0,
  299. 0, /* Advanced Interrupt Controller */
  300. };
  301. void __init at91sam9rl_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  302. {
  303. if (!priority)
  304. priority = at91sam9rl_default_irq_priority;
  305. /* Initialize the AIC interrupt controller */
  306. at91_aic_init(priority);
  307. /* Enable GPIO interrupts */
  308. at91_gpio_irq_setup();
  309. }