at91sam9g45.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /*
  2. * Chip-specific setup code for the AT91SAM9G45 family
  3. *
  4. * Copyright (C) 2009 Atmel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/pm.h>
  14. #include <asm/irq.h>
  15. #include <asm/mach/arch.h>
  16. #include <asm/mach/map.h>
  17. #include <mach/at91sam9g45.h>
  18. #include <mach/at91_pmc.h>
  19. #include <mach/at91_rstc.h>
  20. #include <mach/at91_shdwc.h>
  21. #include <mach/cpu.h>
  22. #include "generic.h"
  23. #include "clock.h"
  24. static struct map_desc at91sam9g45_io_desc[] __initdata = {
  25. {
  26. .virtual = AT91_VA_BASE_SYS,
  27. .pfn = __phys_to_pfn(AT91_BASE_SYS),
  28. .length = SZ_16K,
  29. .type = MT_DEVICE,
  30. }, {
  31. .virtual = AT91_IO_VIRT_BASE - AT91SAM9G45_SRAM_SIZE,
  32. .pfn = __phys_to_pfn(AT91SAM9G45_SRAM_BASE),
  33. .length = AT91SAM9G45_SRAM_SIZE,
  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 << AT91SAM9G45_ID_PIOA,
  46. .type = CLK_TYPE_PERIPHERAL,
  47. };
  48. static struct clk pioB_clk = {
  49. .name = "pioB_clk",
  50. .pmc_mask = 1 << AT91SAM9G45_ID_PIOB,
  51. .type = CLK_TYPE_PERIPHERAL,
  52. };
  53. static struct clk pioC_clk = {
  54. .name = "pioC_clk",
  55. .pmc_mask = 1 << AT91SAM9G45_ID_PIOC,
  56. .type = CLK_TYPE_PERIPHERAL,
  57. };
  58. static struct clk pioDE_clk = {
  59. .name = "pioDE_clk",
  60. .pmc_mask = 1 << AT91SAM9G45_ID_PIODE,
  61. .type = CLK_TYPE_PERIPHERAL,
  62. };
  63. static struct clk usart0_clk = {
  64. .name = "usart0_clk",
  65. .pmc_mask = 1 << AT91SAM9G45_ID_US0,
  66. .type = CLK_TYPE_PERIPHERAL,
  67. };
  68. static struct clk usart1_clk = {
  69. .name = "usart1_clk",
  70. .pmc_mask = 1 << AT91SAM9G45_ID_US1,
  71. .type = CLK_TYPE_PERIPHERAL,
  72. };
  73. static struct clk usart2_clk = {
  74. .name = "usart2_clk",
  75. .pmc_mask = 1 << AT91SAM9G45_ID_US2,
  76. .type = CLK_TYPE_PERIPHERAL,
  77. };
  78. static struct clk usart3_clk = {
  79. .name = "usart3_clk",
  80. .pmc_mask = 1 << AT91SAM9G45_ID_US3,
  81. .type = CLK_TYPE_PERIPHERAL,
  82. };
  83. static struct clk mmc0_clk = {
  84. .name = "mci0_clk",
  85. .pmc_mask = 1 << AT91SAM9G45_ID_MCI0,
  86. .type = CLK_TYPE_PERIPHERAL,
  87. };
  88. static struct clk twi0_clk = {
  89. .name = "twi0_clk",
  90. .pmc_mask = 1 << AT91SAM9G45_ID_TWI0,
  91. .type = CLK_TYPE_PERIPHERAL,
  92. };
  93. static struct clk twi1_clk = {
  94. .name = "twi1_clk",
  95. .pmc_mask = 1 << AT91SAM9G45_ID_TWI1,
  96. .type = CLK_TYPE_PERIPHERAL,
  97. };
  98. static struct clk spi0_clk = {
  99. .name = "spi0_clk",
  100. .pmc_mask = 1 << AT91SAM9G45_ID_SPI0,
  101. .type = CLK_TYPE_PERIPHERAL,
  102. };
  103. static struct clk spi1_clk = {
  104. .name = "spi1_clk",
  105. .pmc_mask = 1 << AT91SAM9G45_ID_SPI1,
  106. .type = CLK_TYPE_PERIPHERAL,
  107. };
  108. static struct clk ssc0_clk = {
  109. .name = "ssc0_clk",
  110. .pmc_mask = 1 << AT91SAM9G45_ID_SSC0,
  111. .type = CLK_TYPE_PERIPHERAL,
  112. };
  113. static struct clk ssc1_clk = {
  114. .name = "ssc1_clk",
  115. .pmc_mask = 1 << AT91SAM9G45_ID_SSC1,
  116. .type = CLK_TYPE_PERIPHERAL,
  117. };
  118. static struct clk tcb0_clk = {
  119. .name = "tcb0_clk",
  120. .pmc_mask = 1 << AT91SAM9G45_ID_TCB,
  121. .type = CLK_TYPE_PERIPHERAL,
  122. };
  123. static struct clk pwm_clk = {
  124. .name = "pwm_clk",
  125. .pmc_mask = 1 << AT91SAM9G45_ID_PWMC,
  126. .type = CLK_TYPE_PERIPHERAL,
  127. };
  128. static struct clk tsc_clk = {
  129. .name = "tsc_clk",
  130. .pmc_mask = 1 << AT91SAM9G45_ID_TSC,
  131. .type = CLK_TYPE_PERIPHERAL,
  132. };
  133. static struct clk dma_clk = {
  134. .name = "dma_clk",
  135. .pmc_mask = 1 << AT91SAM9G45_ID_DMA,
  136. .type = CLK_TYPE_PERIPHERAL,
  137. };
  138. static struct clk uhphs_clk = {
  139. .name = "uhphs_clk",
  140. .pmc_mask = 1 << AT91SAM9G45_ID_UHPHS,
  141. .type = CLK_TYPE_PERIPHERAL,
  142. };
  143. static struct clk lcdc_clk = {
  144. .name = "lcdc_clk",
  145. .pmc_mask = 1 << AT91SAM9G45_ID_LCDC,
  146. .type = CLK_TYPE_PERIPHERAL,
  147. };
  148. static struct clk ac97_clk = {
  149. .name = "ac97_clk",
  150. .pmc_mask = 1 << AT91SAM9G45_ID_AC97C,
  151. .type = CLK_TYPE_PERIPHERAL,
  152. };
  153. static struct clk macb_clk = {
  154. .name = "macb_clk",
  155. .pmc_mask = 1 << AT91SAM9G45_ID_EMAC,
  156. .type = CLK_TYPE_PERIPHERAL,
  157. };
  158. static struct clk isi_clk = {
  159. .name = "isi_clk",
  160. .pmc_mask = 1 << AT91SAM9G45_ID_ISI,
  161. .type = CLK_TYPE_PERIPHERAL,
  162. };
  163. static struct clk udphs_clk = {
  164. .name = "udphs_clk",
  165. .pmc_mask = 1 << AT91SAM9G45_ID_UDPHS,
  166. .type = CLK_TYPE_PERIPHERAL,
  167. };
  168. static struct clk mmc1_clk = {
  169. .name = "mci1_clk",
  170. .pmc_mask = 1 << AT91SAM9G45_ID_MCI1,
  171. .type = CLK_TYPE_PERIPHERAL,
  172. };
  173. /* Video decoder clock - Only for sam9m10/sam9m11 */
  174. static struct clk vdec_clk = {
  175. .name = "vdec_clk",
  176. .pmc_mask = 1 << AT91SAM9G45_ID_VDEC,
  177. .type = CLK_TYPE_PERIPHERAL,
  178. };
  179. static struct clk *periph_clocks[] __initdata = {
  180. &pioA_clk,
  181. &pioB_clk,
  182. &pioC_clk,
  183. &pioDE_clk,
  184. &usart0_clk,
  185. &usart1_clk,
  186. &usart2_clk,
  187. &usart3_clk,
  188. &mmc0_clk,
  189. &twi0_clk,
  190. &twi1_clk,
  191. &spi0_clk,
  192. &spi1_clk,
  193. &ssc0_clk,
  194. &ssc1_clk,
  195. &tcb0_clk,
  196. &pwm_clk,
  197. &tsc_clk,
  198. &dma_clk,
  199. &uhphs_clk,
  200. &lcdc_clk,
  201. &ac97_clk,
  202. &macb_clk,
  203. &isi_clk,
  204. &udphs_clk,
  205. &mmc1_clk,
  206. // irq0
  207. };
  208. static struct clk_lookup periph_clocks_lookups[] = {
  209. /* One additional fake clock for ohci */
  210. CLKDEV_CON_ID("ohci_clk", &uhphs_clk),
  211. CLKDEV_CON_DEV_ID("ehci_clk", "atmel-ehci.0", &uhphs_clk),
  212. CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc.0", &utmi_clk),
  213. CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc.0", &udphs_clk),
  214. CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.0", &mmc0_clk),
  215. CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.1", &mmc1_clk),
  216. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
  217. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
  218. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb0_clk),
  219. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.1", &tcb0_clk),
  220. CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
  221. CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
  222. };
  223. static struct clk_lookup usart_clocks_lookups[] = {
  224. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  225. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  226. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  227. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  228. CLKDEV_CON_DEV_ID("usart", "atmel_usart.4", &usart3_clk),
  229. };
  230. /*
  231. * The two programmable clocks.
  232. * You must configure pin multiplexing to bring these signals out.
  233. */
  234. static struct clk pck0 = {
  235. .name = "pck0",
  236. .pmc_mask = AT91_PMC_PCK0,
  237. .type = CLK_TYPE_PROGRAMMABLE,
  238. .id = 0,
  239. };
  240. static struct clk pck1 = {
  241. .name = "pck1",
  242. .pmc_mask = AT91_PMC_PCK1,
  243. .type = CLK_TYPE_PROGRAMMABLE,
  244. .id = 1,
  245. };
  246. static void __init at91sam9g45_register_clocks(void)
  247. {
  248. int i;
  249. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  250. clk_register(periph_clocks[i]);
  251. clkdev_add_table(periph_clocks_lookups,
  252. ARRAY_SIZE(periph_clocks_lookups));
  253. clkdev_add_table(usart_clocks_lookups,
  254. ARRAY_SIZE(usart_clocks_lookups));
  255. if (cpu_is_at91sam9m10() || cpu_is_at91sam9m11())
  256. clk_register(&vdec_clk);
  257. clk_register(&pck0);
  258. clk_register(&pck1);
  259. }
  260. static struct clk_lookup console_clock_lookup;
  261. void __init at91sam9g45_set_console_clock(int id)
  262. {
  263. if (id >= ARRAY_SIZE(usart_clocks_lookups))
  264. return;
  265. console_clock_lookup.con_id = "usart";
  266. console_clock_lookup.clk = usart_clocks_lookups[id].clk;
  267. clkdev_add(&console_clock_lookup);
  268. }
  269. /* --------------------------------------------------------------------
  270. * GPIO
  271. * -------------------------------------------------------------------- */
  272. static struct at91_gpio_bank at91sam9g45_gpio[] = {
  273. {
  274. .id = AT91SAM9G45_ID_PIOA,
  275. .offset = AT91_PIOA,
  276. .clock = &pioA_clk,
  277. }, {
  278. .id = AT91SAM9G45_ID_PIOB,
  279. .offset = AT91_PIOB,
  280. .clock = &pioB_clk,
  281. }, {
  282. .id = AT91SAM9G45_ID_PIOC,
  283. .offset = AT91_PIOC,
  284. .clock = &pioC_clk,
  285. }, {
  286. .id = AT91SAM9G45_ID_PIODE,
  287. .offset = AT91_PIOD,
  288. .clock = &pioDE_clk,
  289. }, {
  290. .id = AT91SAM9G45_ID_PIODE,
  291. .offset = AT91_PIOE,
  292. .clock = &pioDE_clk,
  293. }
  294. };
  295. static void at91sam9g45_reset(void)
  296. {
  297. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  298. }
  299. static void at91sam9g45_poweroff(void)
  300. {
  301. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  302. }
  303. /* --------------------------------------------------------------------
  304. * AT91SAM9G45 processor initialization
  305. * -------------------------------------------------------------------- */
  306. void __init at91sam9g45_map_io(void)
  307. {
  308. /* Map peripherals */
  309. iotable_init(at91sam9g45_io_desc, ARRAY_SIZE(at91sam9g45_io_desc));
  310. }
  311. void __init at91sam9g45_initialize(unsigned long main_clock)
  312. {
  313. at91_arch_reset = at91sam9g45_reset;
  314. pm_power_off = at91sam9g45_poweroff;
  315. at91_extern_irq = (1 << AT91SAM9G45_ID_IRQ0);
  316. /* Init clock subsystem */
  317. at91_clock_init(main_clock);
  318. /* Register the processor-specific clocks */
  319. at91sam9g45_register_clocks();
  320. /* Register GPIO subsystem */
  321. at91_gpio_init(at91sam9g45_gpio, 5);
  322. }
  323. /* --------------------------------------------------------------------
  324. * Interrupt initialization
  325. * -------------------------------------------------------------------- */
  326. /*
  327. * The default interrupt priority levels (0 = lowest, 7 = highest).
  328. */
  329. static unsigned int at91sam9g45_default_irq_priority[NR_AIC_IRQS] __initdata = {
  330. 7, /* Advanced Interrupt Controller (FIQ) */
  331. 7, /* System Peripherals */
  332. 1, /* Parallel IO Controller A */
  333. 1, /* Parallel IO Controller B */
  334. 1, /* Parallel IO Controller C */
  335. 1, /* Parallel IO Controller D and E */
  336. 0,
  337. 5, /* USART 0 */
  338. 5, /* USART 1 */
  339. 5, /* USART 2 */
  340. 5, /* USART 3 */
  341. 0, /* Multimedia Card Interface 0 */
  342. 6, /* Two-Wire Interface 0 */
  343. 6, /* Two-Wire Interface 1 */
  344. 5, /* Serial Peripheral Interface 0 */
  345. 5, /* Serial Peripheral Interface 1 */
  346. 4, /* Serial Synchronous Controller 0 */
  347. 4, /* Serial Synchronous Controller 1 */
  348. 0, /* Timer Counter 0, 1, 2, 3, 4 and 5 */
  349. 0, /* Pulse Width Modulation Controller */
  350. 0, /* Touch Screen Controller */
  351. 0, /* DMA Controller */
  352. 2, /* USB Host High Speed port */
  353. 3, /* LDC Controller */
  354. 5, /* AC97 Controller */
  355. 3, /* Ethernet */
  356. 0, /* Image Sensor Interface */
  357. 2, /* USB Device High speed port */
  358. 0,
  359. 0, /* Multimedia Card Interface 1 */
  360. 0,
  361. 0, /* Advanced Interrupt Controller (IRQ0) */
  362. };
  363. void __init at91sam9g45_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  364. {
  365. if (!priority)
  366. priority = at91sam9g45_default_irq_priority;
  367. /* Initialize the AIC interrupt controller */
  368. at91_aic_init(priority);
  369. /* Enable GPIO interrupts */
  370. at91_gpio_irq_setup();
  371. }