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