at91sam9rl.c 8.0 KB

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