at91sam9rl.c 7.9 KB

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