at91sam9x5.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 adc_op_clk = {
  119. .name = "adc_op_clk",
  120. .type = CLK_TYPE_PERIPHERAL,
  121. .rate_hz = 5000000,
  122. };
  123. static struct clk dma0_clk = {
  124. .name = "dma0_clk",
  125. .pmc_mask = 1 << AT91SAM9X5_ID_DMA0,
  126. .type = CLK_TYPE_PERIPHERAL,
  127. };
  128. static struct clk dma1_clk = {
  129. .name = "dma1_clk",
  130. .pmc_mask = 1 << AT91SAM9X5_ID_DMA1,
  131. .type = CLK_TYPE_PERIPHERAL,
  132. };
  133. static struct clk uhphs_clk = {
  134. .name = "uhphs",
  135. .pmc_mask = 1 << AT91SAM9X5_ID_UHPHS,
  136. .type = CLK_TYPE_PERIPHERAL,
  137. };
  138. static struct clk udphs_clk = {
  139. .name = "udphs_clk",
  140. .pmc_mask = 1 << AT91SAM9X5_ID_UDPHS,
  141. .type = CLK_TYPE_PERIPHERAL,
  142. };
  143. /* emac0 clock - Only for sam9g25/sam9x25/sam9g35/sam9x35 */
  144. static struct clk macb0_clk = {
  145. .name = "pclk",
  146. .pmc_mask = 1 << AT91SAM9X5_ID_EMAC0,
  147. .type = CLK_TYPE_PERIPHERAL,
  148. };
  149. /* lcd clock - Only for sam9g15/sam9g35/sam9x35 */
  150. static struct clk lcdc_clk = {
  151. .name = "lcdc_clk",
  152. .pmc_mask = 1 << AT91SAM9X5_ID_LCDC,
  153. .type = CLK_TYPE_PERIPHERAL,
  154. };
  155. /* isi clock - Only for sam9g25 */
  156. static struct clk isi_clk = {
  157. .name = "isi_clk",
  158. .pmc_mask = 1 << AT91SAM9X5_ID_ISI,
  159. .type = CLK_TYPE_PERIPHERAL,
  160. };
  161. static struct clk mmc1_clk = {
  162. .name = "mci1_clk",
  163. .pmc_mask = 1 << AT91SAM9X5_ID_MCI1,
  164. .type = CLK_TYPE_PERIPHERAL,
  165. };
  166. /* emac1 clock - Only for sam9x25 */
  167. static struct clk macb1_clk = {
  168. .name = "pclk",
  169. .pmc_mask = 1 << AT91SAM9X5_ID_EMAC1,
  170. .type = CLK_TYPE_PERIPHERAL,
  171. };
  172. static struct clk ssc_clk = {
  173. .name = "ssc_clk",
  174. .pmc_mask = 1 << AT91SAM9X5_ID_SSC,
  175. .type = CLK_TYPE_PERIPHERAL,
  176. };
  177. /* can0 clock - Only for sam9x35 */
  178. static struct clk can0_clk = {
  179. .name = "can0_clk",
  180. .pmc_mask = 1 << AT91SAM9X5_ID_CAN0,
  181. .type = CLK_TYPE_PERIPHERAL,
  182. };
  183. /* can1 clock - Only for sam9x35 */
  184. static struct clk can1_clk = {
  185. .name = "can1_clk",
  186. .pmc_mask = 1 << AT91SAM9X5_ID_CAN1,
  187. .type = CLK_TYPE_PERIPHERAL,
  188. };
  189. static struct clk *periph_clocks[] __initdata = {
  190. &pioAB_clk,
  191. &pioCD_clk,
  192. &smd_clk,
  193. &usart0_clk,
  194. &usart1_clk,
  195. &usart2_clk,
  196. &twi0_clk,
  197. &twi1_clk,
  198. &twi2_clk,
  199. &mmc0_clk,
  200. &spi0_clk,
  201. &spi1_clk,
  202. &uart0_clk,
  203. &uart1_clk,
  204. &tcb0_clk,
  205. &pwm_clk,
  206. &adc_clk,
  207. &adc_op_clk,
  208. &dma0_clk,
  209. &dma1_clk,
  210. &uhphs_clk,
  211. &udphs_clk,
  212. &mmc1_clk,
  213. &ssc_clk,
  214. // irq0
  215. };
  216. static struct clk_lookup periph_clocks_lookups[] = {
  217. /* lookup table for DT entries */
  218. CLKDEV_CON_DEV_ID("usart", "fffff200.serial", &mck),
  219. CLKDEV_CON_DEV_ID("usart", "f801c000.serial", &usart0_clk),
  220. CLKDEV_CON_DEV_ID("usart", "f8020000.serial", &usart1_clk),
  221. CLKDEV_CON_DEV_ID("usart", "f8024000.serial", &usart2_clk),
  222. CLKDEV_CON_DEV_ID("usart", "f8028000.serial", &usart3_clk),
  223. CLKDEV_CON_DEV_ID("t0_clk", "f8008000.timer", &tcb0_clk),
  224. CLKDEV_CON_DEV_ID("t0_clk", "f800c000.timer", &tcb0_clk),
  225. CLKDEV_CON_DEV_ID("dma_clk", "ffffec00.dma-controller", &dma0_clk),
  226. CLKDEV_CON_DEV_ID("dma_clk", "ffffee00.dma-controller", &dma1_clk),
  227. CLKDEV_CON_ID("pioA", &pioAB_clk),
  228. CLKDEV_CON_ID("pioB", &pioAB_clk),
  229. CLKDEV_CON_ID("pioC", &pioCD_clk),
  230. CLKDEV_CON_ID("pioD", &pioCD_clk),
  231. /* additional fake clock for macb_hclk */
  232. CLKDEV_CON_DEV_ID("hclk", "f802c000.ethernet", &macb0_clk),
  233. CLKDEV_CON_DEV_ID("hclk", "f8030000.ethernet", &macb1_clk),
  234. CLKDEV_CON_DEV_ID("hclk", "600000.ohci", &uhphs_clk),
  235. CLKDEV_CON_DEV_ID("ohci_clk", "600000.ohci", &uhphs_clk),
  236. CLKDEV_CON_DEV_ID("ehci_clk", "700000.ehci", &uhphs_clk),
  237. };
  238. /*
  239. * The two programmable clocks.
  240. * You must configure pin multiplexing to bring these signals out.
  241. */
  242. static struct clk pck0 = {
  243. .name = "pck0",
  244. .pmc_mask = AT91_PMC_PCK0,
  245. .type = CLK_TYPE_PROGRAMMABLE,
  246. .id = 0,
  247. };
  248. static struct clk pck1 = {
  249. .name = "pck1",
  250. .pmc_mask = AT91_PMC_PCK1,
  251. .type = CLK_TYPE_PROGRAMMABLE,
  252. .id = 1,
  253. };
  254. static void __init at91sam9x5_register_clocks(void)
  255. {
  256. int i;
  257. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  258. clk_register(periph_clocks[i]);
  259. clkdev_add_table(periph_clocks_lookups,
  260. ARRAY_SIZE(periph_clocks_lookups));
  261. if (cpu_is_at91sam9g25()
  262. || cpu_is_at91sam9x25())
  263. clk_register(&usart3_clk);
  264. if (cpu_is_at91sam9g25()
  265. || cpu_is_at91sam9x25()
  266. || cpu_is_at91sam9g35()
  267. || cpu_is_at91sam9x35())
  268. clk_register(&macb0_clk);
  269. if (cpu_is_at91sam9g15()
  270. || cpu_is_at91sam9g35()
  271. || cpu_is_at91sam9x35())
  272. clk_register(&lcdc_clk);
  273. if (cpu_is_at91sam9g25())
  274. clk_register(&isi_clk);
  275. if (cpu_is_at91sam9x25())
  276. clk_register(&macb1_clk);
  277. if (cpu_is_at91sam9x25()
  278. || cpu_is_at91sam9x35()) {
  279. clk_register(&can0_clk);
  280. clk_register(&can1_clk);
  281. }
  282. clk_register(&pck0);
  283. clk_register(&pck1);
  284. }
  285. /* --------------------------------------------------------------------
  286. * AT91SAM9x5 processor initialization
  287. * -------------------------------------------------------------------- */
  288. static void __init at91sam9x5_map_io(void)
  289. {
  290. at91_init_sram(0, AT91SAM9X5_SRAM_BASE, AT91SAM9X5_SRAM_SIZE);
  291. }
  292. void __init at91sam9x5_initialize(void)
  293. {
  294. at91_extern_irq = (1 << AT91SAM9X5_ID_IRQ0);
  295. /* Register GPIO subsystem (using DT) */
  296. at91_gpio_init(NULL, 0);
  297. }
  298. /* --------------------------------------------------------------------
  299. * Interrupt initialization
  300. * -------------------------------------------------------------------- */
  301. /*
  302. * The default interrupt priority levels (0 = lowest, 7 = highest).
  303. */
  304. static unsigned int at91sam9x5_default_irq_priority[NR_AIC_IRQS] __initdata = {
  305. 7, /* Advanced Interrupt Controller (FIQ) */
  306. 7, /* System Peripherals */
  307. 1, /* Parallel IO Controller A and B */
  308. 1, /* Parallel IO Controller C and D */
  309. 4, /* Soft Modem */
  310. 5, /* USART 0 */
  311. 5, /* USART 1 */
  312. 5, /* USART 2 */
  313. 5, /* USART 3 */
  314. 6, /* Two-Wire Interface 0 */
  315. 6, /* Two-Wire Interface 1 */
  316. 6, /* Two-Wire Interface 2 */
  317. 0, /* Multimedia Card Interface 0 */
  318. 5, /* Serial Peripheral Interface 0 */
  319. 5, /* Serial Peripheral Interface 1 */
  320. 5, /* UART 0 */
  321. 5, /* UART 1 */
  322. 0, /* Timer Counter 0, 1, 2, 3, 4 and 5 */
  323. 0, /* Pulse Width Modulation Controller */
  324. 0, /* ADC Controller */
  325. 0, /* DMA Controller 0 */
  326. 0, /* DMA Controller 1 */
  327. 2, /* USB Host High Speed port */
  328. 2, /* USB Device High speed port */
  329. 3, /* Ethernet MAC 0 */
  330. 3, /* LDC Controller or Image Sensor Interface */
  331. 0, /* Multimedia Card Interface 1 */
  332. 3, /* Ethernet MAC 1 */
  333. 4, /* Synchronous Serial Interface */
  334. 4, /* CAN Controller 0 */
  335. 4, /* CAN Controller 1 */
  336. 0, /* Advanced Interrupt Controller (IRQ0) */
  337. };
  338. struct at91_init_soc __initdata at91sam9x5_soc = {
  339. .map_io = at91sam9x5_map_io,
  340. .default_irq_priority = at91sam9x5_default_irq_priority,
  341. .register_clocks = at91sam9x5_register_clocks,
  342. .init = at91sam9x5_initialize,
  343. };