at91sam9g45.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 tcb_clk = {
  119. .name = "tcb_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. /* One additional fake clock for ohci */
  180. static struct clk ohci_clk = {
  181. .name = "ohci_clk",
  182. .pmc_mask = 0,
  183. .type = CLK_TYPE_PERIPHERAL,
  184. .parent = &uhphs_clk,
  185. };
  186. static struct clk *periph_clocks[] __initdata = {
  187. &pioA_clk,
  188. &pioB_clk,
  189. &pioC_clk,
  190. &pioDE_clk,
  191. &usart0_clk,
  192. &usart1_clk,
  193. &usart2_clk,
  194. &usart3_clk,
  195. &mmc0_clk,
  196. &twi0_clk,
  197. &twi1_clk,
  198. &spi0_clk,
  199. &spi1_clk,
  200. &ssc0_clk,
  201. &ssc1_clk,
  202. &tcb_clk,
  203. &pwm_clk,
  204. &tsc_clk,
  205. &dma_clk,
  206. &uhphs_clk,
  207. &lcdc_clk,
  208. &ac97_clk,
  209. &macb_clk,
  210. &isi_clk,
  211. &udphs_clk,
  212. &mmc1_clk,
  213. // irq0
  214. &ohci_clk,
  215. };
  216. /*
  217. * The two programmable clocks.
  218. * You must configure pin multiplexing to bring these signals out.
  219. */
  220. static struct clk pck0 = {
  221. .name = "pck0",
  222. .pmc_mask = AT91_PMC_PCK0,
  223. .type = CLK_TYPE_PROGRAMMABLE,
  224. .id = 0,
  225. };
  226. static struct clk pck1 = {
  227. .name = "pck1",
  228. .pmc_mask = AT91_PMC_PCK1,
  229. .type = CLK_TYPE_PROGRAMMABLE,
  230. .id = 1,
  231. };
  232. static void __init at91sam9g45_register_clocks(void)
  233. {
  234. int i;
  235. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  236. clk_register(periph_clocks[i]);
  237. if (cpu_is_at91sam9m10() || cpu_is_at91sam9m11())
  238. clk_register(&vdec_clk);
  239. clk_register(&pck0);
  240. clk_register(&pck1);
  241. }
  242. /* --------------------------------------------------------------------
  243. * GPIO
  244. * -------------------------------------------------------------------- */
  245. static struct at91_gpio_bank at91sam9g45_gpio[] = {
  246. {
  247. .id = AT91SAM9G45_ID_PIOA,
  248. .offset = AT91_PIOA,
  249. .clock = &pioA_clk,
  250. }, {
  251. .id = AT91SAM9G45_ID_PIOB,
  252. .offset = AT91_PIOB,
  253. .clock = &pioB_clk,
  254. }, {
  255. .id = AT91SAM9G45_ID_PIOC,
  256. .offset = AT91_PIOC,
  257. .clock = &pioC_clk,
  258. }, {
  259. .id = AT91SAM9G45_ID_PIODE,
  260. .offset = AT91_PIOD,
  261. .clock = &pioDE_clk,
  262. }, {
  263. .id = AT91SAM9G45_ID_PIODE,
  264. .offset = AT91_PIOE,
  265. .clock = &pioDE_clk,
  266. }
  267. };
  268. static void at91sam9g45_reset(void)
  269. {
  270. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  271. }
  272. static void at91sam9g45_poweroff(void)
  273. {
  274. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  275. }
  276. /* --------------------------------------------------------------------
  277. * AT91SAM9G45 processor initialization
  278. * -------------------------------------------------------------------- */
  279. void __init at91sam9g45_initialize(unsigned long main_clock)
  280. {
  281. /* Map peripherals */
  282. iotable_init(at91sam9g45_io_desc, ARRAY_SIZE(at91sam9g45_io_desc));
  283. at91_arch_reset = at91sam9g45_reset;
  284. pm_power_off = at91sam9g45_poweroff;
  285. at91_extern_irq = (1 << AT91SAM9G45_ID_IRQ0);
  286. /* Init clock subsystem */
  287. at91_clock_init(main_clock);
  288. /* Register the processor-specific clocks */
  289. at91sam9g45_register_clocks();
  290. /* Register GPIO subsystem */
  291. at91_gpio_init(at91sam9g45_gpio, 5);
  292. }
  293. /* --------------------------------------------------------------------
  294. * Interrupt initialization
  295. * -------------------------------------------------------------------- */
  296. /*
  297. * The default interrupt priority levels (0 = lowest, 7 = highest).
  298. */
  299. static unsigned int at91sam9g45_default_irq_priority[NR_AIC_IRQS] __initdata = {
  300. 7, /* Advanced Interrupt Controller (FIQ) */
  301. 7, /* System Peripherals */
  302. 1, /* Parallel IO Controller A */
  303. 1, /* Parallel IO Controller B */
  304. 1, /* Parallel IO Controller C */
  305. 1, /* Parallel IO Controller D and E */
  306. 0,
  307. 5, /* USART 0 */
  308. 5, /* USART 1 */
  309. 5, /* USART 2 */
  310. 5, /* USART 3 */
  311. 0, /* Multimedia Card Interface 0 */
  312. 6, /* Two-Wire Interface 0 */
  313. 6, /* Two-Wire Interface 1 */
  314. 5, /* Serial Peripheral Interface 0 */
  315. 5, /* Serial Peripheral Interface 1 */
  316. 4, /* Serial Synchronous Controller 0 */
  317. 4, /* Serial Synchronous Controller 1 */
  318. 0, /* Timer Counter 0, 1, 2, 3, 4 and 5 */
  319. 0, /* Pulse Width Modulation Controller */
  320. 0, /* Touch Screen Controller */
  321. 0, /* DMA Controller */
  322. 2, /* USB Host High Speed port */
  323. 3, /* LDC Controller */
  324. 5, /* AC97 Controller */
  325. 3, /* Ethernet */
  326. 0, /* Image Sensor Interface */
  327. 2, /* USB Device High speed port */
  328. 0,
  329. 0, /* Multimedia Card Interface 1 */
  330. 0,
  331. 0, /* Advanced Interrupt Controller (IRQ0) */
  332. };
  333. void __init at91sam9g45_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  334. {
  335. if (!priority)
  336. priority = at91sam9g45_default_irq_priority;
  337. /* Initialize the AIC interrupt controller */
  338. at91_aic_init(priority);
  339. /* Enable GPIO interrupts */
  340. at91_gpio_irq_setup();
  341. }