at91sam9rl.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. static struct clk_lookup periph_clocks_lookups[] = {
  185. CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc", &utmi_clk),
  186. CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc", &udphs_clk),
  187. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
  188. CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
  189. CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
  190. CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
  191. CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
  192. };
  193. static struct clk_lookup usart_clocks_lookups[] = {
  194. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  195. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  196. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  197. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  198. CLKDEV_CON_DEV_ID("usart", "atmel_usart.4", &usart3_clk),
  199. };
  200. /*
  201. * The two programmable clocks.
  202. * You must configure pin multiplexing to bring these signals out.
  203. */
  204. static struct clk pck0 = {
  205. .name = "pck0",
  206. .pmc_mask = AT91_PMC_PCK0,
  207. .type = CLK_TYPE_PROGRAMMABLE,
  208. .id = 0,
  209. };
  210. static struct clk pck1 = {
  211. .name = "pck1",
  212. .pmc_mask = AT91_PMC_PCK1,
  213. .type = CLK_TYPE_PROGRAMMABLE,
  214. .id = 1,
  215. };
  216. static void __init at91sam9rl_register_clocks(void)
  217. {
  218. int i;
  219. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  220. clk_register(periph_clocks[i]);
  221. clkdev_add_table(periph_clocks_lookups,
  222. ARRAY_SIZE(periph_clocks_lookups));
  223. clkdev_add_table(usart_clocks_lookups,
  224. ARRAY_SIZE(usart_clocks_lookups));
  225. clk_register(&pck0);
  226. clk_register(&pck1);
  227. }
  228. static struct clk_lookup console_clock_lookup;
  229. void __init at91sam9rl_set_console_clock(int id)
  230. {
  231. if (id >= ARRAY_SIZE(usart_clocks_lookups))
  232. return;
  233. console_clock_lookup.con_id = "usart";
  234. console_clock_lookup.clk = usart_clocks_lookups[id].clk;
  235. clkdev_add(&console_clock_lookup);
  236. }
  237. /* --------------------------------------------------------------------
  238. * GPIO
  239. * -------------------------------------------------------------------- */
  240. static struct at91_gpio_bank at91sam9rl_gpio[] = {
  241. {
  242. .id = AT91SAM9RL_ID_PIOA,
  243. .offset = AT91_PIOA,
  244. .clock = &pioA_clk,
  245. }, {
  246. .id = AT91SAM9RL_ID_PIOB,
  247. .offset = AT91_PIOB,
  248. .clock = &pioB_clk,
  249. }, {
  250. .id = AT91SAM9RL_ID_PIOC,
  251. .offset = AT91_PIOC,
  252. .clock = &pioC_clk,
  253. }, {
  254. .id = AT91SAM9RL_ID_PIOD,
  255. .offset = AT91_PIOD,
  256. .clock = &pioD_clk,
  257. }
  258. };
  259. static void at91sam9rl_poweroff(void)
  260. {
  261. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  262. }
  263. /* --------------------------------------------------------------------
  264. * AT91SAM9RL processor initialization
  265. * -------------------------------------------------------------------- */
  266. void __init at91sam9rl_map_io(void)
  267. {
  268. unsigned long cidr, sram_size;
  269. /* Map peripherals */
  270. iotable_init(at91sam9rl_io_desc, ARRAY_SIZE(at91sam9rl_io_desc));
  271. cidr = at91_sys_read(AT91_DBGU_CIDR);
  272. switch (cidr & AT91_CIDR_SRAMSIZ) {
  273. case AT91_CIDR_SRAMSIZ_32K:
  274. sram_size = 2 * SZ_16K;
  275. break;
  276. case AT91_CIDR_SRAMSIZ_16K:
  277. default:
  278. sram_size = SZ_16K;
  279. }
  280. at91sam9rl_sram_desc->virtual = AT91_IO_VIRT_BASE - sram_size;
  281. at91sam9rl_sram_desc->length = sram_size;
  282. /* Map SRAM */
  283. iotable_init(at91sam9rl_sram_desc, ARRAY_SIZE(at91sam9rl_sram_desc));
  284. }
  285. void __init at91sam9rl_initialize(unsigned long main_clock)
  286. {
  287. at91_arch_reset = at91sam9_alt_reset;
  288. pm_power_off = at91sam9rl_poweroff;
  289. at91_extern_irq = (1 << AT91SAM9RL_ID_IRQ0);
  290. /* Init clock subsystem */
  291. at91_clock_init(main_clock);
  292. /* Register the processor-specific clocks */
  293. at91sam9rl_register_clocks();
  294. /* Register GPIO subsystem */
  295. at91_gpio_init(at91sam9rl_gpio, 4);
  296. }
  297. /* --------------------------------------------------------------------
  298. * Interrupt initialization
  299. * -------------------------------------------------------------------- */
  300. /*
  301. * The default interrupt priority levels (0 = lowest, 7 = highest).
  302. */
  303. static unsigned int at91sam9rl_default_irq_priority[NR_AIC_IRQS] __initdata = {
  304. 7, /* Advanced Interrupt Controller */
  305. 7, /* System Peripherals */
  306. 1, /* Parallel IO Controller A */
  307. 1, /* Parallel IO Controller B */
  308. 1, /* Parallel IO Controller C */
  309. 1, /* Parallel IO Controller D */
  310. 5, /* USART 0 */
  311. 5, /* USART 1 */
  312. 5, /* USART 2 */
  313. 5, /* USART 3 */
  314. 0, /* Multimedia Card Interface */
  315. 6, /* Two-Wire Interface 0 */
  316. 6, /* Two-Wire Interface 1 */
  317. 5, /* Serial Peripheral Interface */
  318. 4, /* Serial Synchronous Controller 0 */
  319. 4, /* Serial Synchronous Controller 1 */
  320. 0, /* Timer Counter 0 */
  321. 0, /* Timer Counter 1 */
  322. 0, /* Timer Counter 2 */
  323. 0,
  324. 0, /* Touch Screen Controller */
  325. 0, /* DMA Controller */
  326. 2, /* USB Device High speed port */
  327. 2, /* LCD Controller */
  328. 6, /* AC97 Controller */
  329. 0,
  330. 0,
  331. 0,
  332. 0,
  333. 0,
  334. 0,
  335. 0, /* Advanced Interrupt Controller */
  336. };
  337. void __init at91sam9rl_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  338. {
  339. if (!priority)
  340. priority = at91sam9rl_default_irq_priority;
  341. /* Initialize the AIC interrupt controller */
  342. at91_aic_init(priority);
  343. /* Enable GPIO interrupts */
  344. at91_gpio_irq_setup();
  345. }