at91sam9g45.c 9.0 KB

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