at91sam9x5.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * Chip-specific setup code for the AT91SAM9x5 family
  3. *
  4. * Copyright (C) 2010-2012 Atmel Corporation.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/dma-mapping.h>
  10. #include <asm/irq.h>
  11. #include <asm/mach/arch.h>
  12. #include <asm/mach/map.h>
  13. #include <mach/at91sam9x5.h>
  14. #include <mach/at91_pmc.h>
  15. #include <mach/cpu.h>
  16. #include <mach/board.h>
  17. #include "soc.h"
  18. #include "generic.h"
  19. #include "clock.h"
  20. #include "sam9_smc.h"
  21. /* --------------------------------------------------------------------
  22. * Clocks
  23. * -------------------------------------------------------------------- */
  24. /*
  25. * The peripheral clocks.
  26. */
  27. static struct clk pioAB_clk = {
  28. .name = "pioAB_clk",
  29. .pmc_mask = 1 << AT91SAM9X5_ID_PIOAB,
  30. .type = CLK_TYPE_PERIPHERAL,
  31. };
  32. static struct clk pioCD_clk = {
  33. .name = "pioCD_clk",
  34. .pmc_mask = 1 << AT91SAM9X5_ID_PIOCD,
  35. .type = CLK_TYPE_PERIPHERAL,
  36. };
  37. static struct clk smd_clk = {
  38. .name = "smd_clk",
  39. .pmc_mask = 1 << AT91SAM9X5_ID_SMD,
  40. .type = CLK_TYPE_PERIPHERAL,
  41. };
  42. static struct clk usart0_clk = {
  43. .name = "usart0_clk",
  44. .pmc_mask = 1 << AT91SAM9X5_ID_USART0,
  45. .type = CLK_TYPE_PERIPHERAL,
  46. };
  47. static struct clk usart1_clk = {
  48. .name = "usart1_clk",
  49. .pmc_mask = 1 << AT91SAM9X5_ID_USART1,
  50. .type = CLK_TYPE_PERIPHERAL,
  51. };
  52. static struct clk usart2_clk = {
  53. .name = "usart2_clk",
  54. .pmc_mask = 1 << AT91SAM9X5_ID_USART2,
  55. .type = CLK_TYPE_PERIPHERAL,
  56. };
  57. /* USART3 clock - Only for sam9g25/sam9x25 */
  58. static struct clk usart3_clk = {
  59. .name = "usart3_clk",
  60. .pmc_mask = 1 << AT91SAM9X5_ID_USART3,
  61. .type = CLK_TYPE_PERIPHERAL,
  62. };
  63. static struct clk twi0_clk = {
  64. .name = "twi0_clk",
  65. .pmc_mask = 1 << AT91SAM9X5_ID_TWI0,
  66. .type = CLK_TYPE_PERIPHERAL,
  67. };
  68. static struct clk twi1_clk = {
  69. .name = "twi1_clk",
  70. .pmc_mask = 1 << AT91SAM9X5_ID_TWI1,
  71. .type = CLK_TYPE_PERIPHERAL,
  72. };
  73. static struct clk twi2_clk = {
  74. .name = "twi2_clk",
  75. .pmc_mask = 1 << AT91SAM9X5_ID_TWI2,
  76. .type = CLK_TYPE_PERIPHERAL,
  77. };
  78. static struct clk mmc0_clk = {
  79. .name = "mci0_clk",
  80. .pmc_mask = 1 << AT91SAM9X5_ID_MCI0,
  81. .type = CLK_TYPE_PERIPHERAL,
  82. };
  83. static struct clk spi0_clk = {
  84. .name = "spi0_clk",
  85. .pmc_mask = 1 << AT91SAM9X5_ID_SPI0,
  86. .type = CLK_TYPE_PERIPHERAL,
  87. };
  88. static struct clk spi1_clk = {
  89. .name = "spi1_clk",
  90. .pmc_mask = 1 << AT91SAM9X5_ID_SPI1,
  91. .type = CLK_TYPE_PERIPHERAL,
  92. };
  93. static struct clk uart0_clk = {
  94. .name = "uart0_clk",
  95. .pmc_mask = 1 << AT91SAM9X5_ID_UART0,
  96. .type = CLK_TYPE_PERIPHERAL,
  97. };
  98. static struct clk uart1_clk = {
  99. .name = "uart1_clk",
  100. .pmc_mask = 1 << AT91SAM9X5_ID_UART1,
  101. .type = CLK_TYPE_PERIPHERAL,
  102. };
  103. static struct clk tcb0_clk = {
  104. .name = "tcb0_clk",
  105. .pmc_mask = 1 << AT91SAM9X5_ID_TCB,
  106. .type = CLK_TYPE_PERIPHERAL,
  107. };
  108. static struct clk pwm_clk = {
  109. .name = "pwm_clk",
  110. .pmc_mask = 1 << AT91SAM9X5_ID_PWM,
  111. .type = CLK_TYPE_PERIPHERAL,
  112. };
  113. static struct clk adc_clk = {
  114. .name = "adc_clk",
  115. .pmc_mask = 1 << AT91SAM9X5_ID_ADC,
  116. .type = CLK_TYPE_PERIPHERAL,
  117. };
  118. static struct clk dma0_clk = {
  119. .name = "dma0_clk",
  120. .pmc_mask = 1 << AT91SAM9X5_ID_DMA0,
  121. .type = CLK_TYPE_PERIPHERAL,
  122. };
  123. static struct clk dma1_clk = {
  124. .name = "dma1_clk",
  125. .pmc_mask = 1 << AT91SAM9X5_ID_DMA1,
  126. .type = CLK_TYPE_PERIPHERAL,
  127. };
  128. static struct clk uhphs_clk = {
  129. .name = "uhphs",
  130. .pmc_mask = 1 << AT91SAM9X5_ID_UHPHS,
  131. .type = CLK_TYPE_PERIPHERAL,
  132. };
  133. static struct clk udphs_clk = {
  134. .name = "udphs_clk",
  135. .pmc_mask = 1 << AT91SAM9X5_ID_UDPHS,
  136. .type = CLK_TYPE_PERIPHERAL,
  137. };
  138. /* emac0 clock - Only for sam9g25/sam9x25/sam9g35/sam9x35 */
  139. static struct clk macb0_clk = {
  140. .name = "pclk",
  141. .pmc_mask = 1 << AT91SAM9X5_ID_EMAC0,
  142. .type = CLK_TYPE_PERIPHERAL,
  143. };
  144. /* lcd clock - Only for sam9g15/sam9g35/sam9x35 */
  145. static struct clk lcdc_clk = {
  146. .name = "lcdc_clk",
  147. .pmc_mask = 1 << AT91SAM9X5_ID_LCDC,
  148. .type = CLK_TYPE_PERIPHERAL,
  149. };
  150. /* isi clock - Only for sam9g25 */
  151. static struct clk isi_clk = {
  152. .name = "isi_clk",
  153. .pmc_mask = 1 << AT91SAM9X5_ID_ISI,
  154. .type = CLK_TYPE_PERIPHERAL,
  155. };
  156. static struct clk mmc1_clk = {
  157. .name = "mci1_clk",
  158. .pmc_mask = 1 << AT91SAM9X5_ID_MCI1,
  159. .type = CLK_TYPE_PERIPHERAL,
  160. };
  161. /* emac1 clock - Only for sam9x25 */
  162. static struct clk macb1_clk = {
  163. .name = "pclk",
  164. .pmc_mask = 1 << AT91SAM9X5_ID_EMAC1,
  165. .type = CLK_TYPE_PERIPHERAL,
  166. };
  167. static struct clk ssc_clk = {
  168. .name = "ssc_clk",
  169. .pmc_mask = 1 << AT91SAM9X5_ID_SSC,
  170. .type = CLK_TYPE_PERIPHERAL,
  171. };
  172. /* can0 clock - Only for sam9x35 */
  173. static struct clk can0_clk = {
  174. .name = "can0_clk",
  175. .pmc_mask = 1 << AT91SAM9X5_ID_CAN0,
  176. .type = CLK_TYPE_PERIPHERAL,
  177. };
  178. /* can1 clock - Only for sam9x35 */
  179. static struct clk can1_clk = {
  180. .name = "can1_clk",
  181. .pmc_mask = 1 << AT91SAM9X5_ID_CAN1,
  182. .type = CLK_TYPE_PERIPHERAL,
  183. };
  184. static struct clk *periph_clocks[] __initdata = {
  185. &pioAB_clk,
  186. &pioCD_clk,
  187. &smd_clk,
  188. &usart0_clk,
  189. &usart1_clk,
  190. &usart2_clk,
  191. &twi0_clk,
  192. &twi1_clk,
  193. &twi2_clk,
  194. &mmc0_clk,
  195. &spi0_clk,
  196. &spi1_clk,
  197. &uart0_clk,
  198. &uart1_clk,
  199. &tcb0_clk,
  200. &pwm_clk,
  201. &adc_clk,
  202. &dma0_clk,
  203. &dma1_clk,
  204. &uhphs_clk,
  205. &udphs_clk,
  206. &mmc1_clk,
  207. &ssc_clk,
  208. // irq0
  209. };
  210. static struct clk_lookup periph_clocks_lookups[] = {
  211. /* lookup table for DT entries */
  212. CLKDEV_CON_DEV_ID("usart", "fffff200.serial", &mck),
  213. CLKDEV_CON_DEV_ID("usart", "f801c000.serial", &usart0_clk),
  214. CLKDEV_CON_DEV_ID("usart", "f8020000.serial", &usart1_clk),
  215. CLKDEV_CON_DEV_ID("usart", "f8024000.serial", &usart2_clk),
  216. CLKDEV_CON_DEV_ID("usart", "f8028000.serial", &usart3_clk),
  217. CLKDEV_CON_DEV_ID("t0_clk", "f8008000.timer", &tcb0_clk),
  218. CLKDEV_CON_DEV_ID("t0_clk", "f800c000.timer", &tcb0_clk),
  219. CLKDEV_CON_DEV_ID("dma_clk", "ffffec00.dma-controller", &dma0_clk),
  220. CLKDEV_CON_DEV_ID("dma_clk", "ffffee00.dma-controller", &dma1_clk),
  221. CLKDEV_CON_ID("pioA", &pioAB_clk),
  222. CLKDEV_CON_ID("pioB", &pioAB_clk),
  223. CLKDEV_CON_ID("pioC", &pioCD_clk),
  224. CLKDEV_CON_ID("pioD", &pioCD_clk),
  225. /* additional fake clock for macb_hclk */
  226. CLKDEV_CON_DEV_ID("hclk", "f802c000.ethernet", &macb0_clk),
  227. CLKDEV_CON_DEV_ID("hclk", "f8030000.ethernet", &macb1_clk),
  228. CLKDEV_CON_DEV_ID("hclk", "600000.ohci", &uhphs_clk),
  229. CLKDEV_CON_DEV_ID("ohci_clk", "600000.ohci", &uhphs_clk),
  230. CLKDEV_CON_DEV_ID("ehci_clk", "700000.ehci", &uhphs_clk),
  231. };
  232. /*
  233. * The two programmable clocks.
  234. * You must configure pin multiplexing to bring these signals out.
  235. */
  236. static struct clk pck0 = {
  237. .name = "pck0",
  238. .pmc_mask = AT91_PMC_PCK0,
  239. .type = CLK_TYPE_PROGRAMMABLE,
  240. .id = 0,
  241. };
  242. static struct clk pck1 = {
  243. .name = "pck1",
  244. .pmc_mask = AT91_PMC_PCK1,
  245. .type = CLK_TYPE_PROGRAMMABLE,
  246. .id = 1,
  247. };
  248. static void __init at91sam9x5_register_clocks(void)
  249. {
  250. int i;
  251. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  252. clk_register(periph_clocks[i]);
  253. clkdev_add_table(periph_clocks_lookups,
  254. ARRAY_SIZE(periph_clocks_lookups));
  255. if (cpu_is_at91sam9g25()
  256. || cpu_is_at91sam9x25())
  257. clk_register(&usart3_clk);
  258. if (cpu_is_at91sam9g25()
  259. || cpu_is_at91sam9x25()
  260. || cpu_is_at91sam9g35()
  261. || cpu_is_at91sam9x35())
  262. clk_register(&macb0_clk);
  263. if (cpu_is_at91sam9g15()
  264. || cpu_is_at91sam9g35()
  265. || cpu_is_at91sam9x35())
  266. clk_register(&lcdc_clk);
  267. if (cpu_is_at91sam9g25())
  268. clk_register(&isi_clk);
  269. if (cpu_is_at91sam9x25())
  270. clk_register(&macb1_clk);
  271. if (cpu_is_at91sam9x25()
  272. || cpu_is_at91sam9x35()) {
  273. clk_register(&can0_clk);
  274. clk_register(&can1_clk);
  275. }
  276. clk_register(&pck0);
  277. clk_register(&pck1);
  278. }
  279. /* --------------------------------------------------------------------
  280. * AT91SAM9x5 processor initialization
  281. * -------------------------------------------------------------------- */
  282. static void __init at91sam9x5_map_io(void)
  283. {
  284. at91_init_sram(0, AT91SAM9X5_SRAM_BASE, AT91SAM9X5_SRAM_SIZE);
  285. }
  286. void __init at91sam9x5_initialize(void)
  287. {
  288. at91_extern_irq = (1 << AT91SAM9X5_ID_IRQ0);
  289. /* Register GPIO subsystem (using DT) */
  290. at91_gpio_init(NULL, 0);
  291. }
  292. /* --------------------------------------------------------------------
  293. * Interrupt initialization
  294. * -------------------------------------------------------------------- */
  295. /*
  296. * The default interrupt priority levels (0 = lowest, 7 = highest).
  297. */
  298. static unsigned int at91sam9x5_default_irq_priority[NR_AIC_IRQS] __initdata = {
  299. 7, /* Advanced Interrupt Controller (FIQ) */
  300. 7, /* System Peripherals */
  301. 1, /* Parallel IO Controller A and B */
  302. 1, /* Parallel IO Controller C and D */
  303. 4, /* Soft Modem */
  304. 5, /* USART 0 */
  305. 5, /* USART 1 */
  306. 5, /* USART 2 */
  307. 5, /* USART 3 */
  308. 6, /* Two-Wire Interface 0 */
  309. 6, /* Two-Wire Interface 1 */
  310. 6, /* Two-Wire Interface 2 */
  311. 0, /* Multimedia Card Interface 0 */
  312. 5, /* Serial Peripheral Interface 0 */
  313. 5, /* Serial Peripheral Interface 1 */
  314. 5, /* UART 0 */
  315. 5, /* UART 1 */
  316. 0, /* Timer Counter 0, 1, 2, 3, 4 and 5 */
  317. 0, /* Pulse Width Modulation Controller */
  318. 0, /* ADC Controller */
  319. 0, /* DMA Controller 0 */
  320. 0, /* DMA Controller 1 */
  321. 2, /* USB Host High Speed port */
  322. 2, /* USB Device High speed port */
  323. 3, /* Ethernet MAC 0 */
  324. 3, /* LDC Controller or Image Sensor Interface */
  325. 0, /* Multimedia Card Interface 1 */
  326. 3, /* Ethernet MAC 1 */
  327. 4, /* Synchronous Serial Interface */
  328. 4, /* CAN Controller 0 */
  329. 4, /* CAN Controller 1 */
  330. 0, /* Advanced Interrupt Controller (IRQ0) */
  331. };
  332. struct at91_init_soc __initdata at91sam9x5_soc = {
  333. .map_io = at91sam9x5_map_io,
  334. .default_irq_priority = at91sam9x5_default_irq_priority,
  335. .register_clocks = at91sam9x5_register_clocks,
  336. .init = at91sam9x5_initialize,
  337. };