at91sam9x5.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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_clk",
  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_ID("pioA", &pioAB_clk),
  220. CLKDEV_CON_ID("pioB", &pioAB_clk),
  221. CLKDEV_CON_ID("pioC", &pioCD_clk),
  222. CLKDEV_CON_ID("pioD", &pioCD_clk),
  223. /* additional fake clock for macb_hclk */
  224. CLKDEV_CON_DEV_ID("hclk", "f802c000.ethernet", &macb0_clk),
  225. CLKDEV_CON_DEV_ID("hclk", "f8030000.ethernet", &macb1_clk),
  226. };
  227. /*
  228. * The two programmable clocks.
  229. * You must configure pin multiplexing to bring these signals out.
  230. */
  231. static struct clk pck0 = {
  232. .name = "pck0",
  233. .pmc_mask = AT91_PMC_PCK0,
  234. .type = CLK_TYPE_PROGRAMMABLE,
  235. .id = 0,
  236. };
  237. static struct clk pck1 = {
  238. .name = "pck1",
  239. .pmc_mask = AT91_PMC_PCK1,
  240. .type = CLK_TYPE_PROGRAMMABLE,
  241. .id = 1,
  242. };
  243. static void __init at91sam9x5_register_clocks(void)
  244. {
  245. int i;
  246. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  247. clk_register(periph_clocks[i]);
  248. clkdev_add_table(periph_clocks_lookups,
  249. ARRAY_SIZE(periph_clocks_lookups));
  250. if (cpu_is_at91sam9g25()
  251. || cpu_is_at91sam9x25())
  252. clk_register(&usart3_clk);
  253. if (cpu_is_at91sam9g25()
  254. || cpu_is_at91sam9x25()
  255. || cpu_is_at91sam9g35()
  256. || cpu_is_at91sam9x35())
  257. clk_register(&macb0_clk);
  258. if (cpu_is_at91sam9g15()
  259. || cpu_is_at91sam9g35()
  260. || cpu_is_at91sam9x35())
  261. clk_register(&lcdc_clk);
  262. if (cpu_is_at91sam9g25())
  263. clk_register(&isi_clk);
  264. if (cpu_is_at91sam9x25())
  265. clk_register(&macb1_clk);
  266. if (cpu_is_at91sam9x25()
  267. || cpu_is_at91sam9x35()) {
  268. clk_register(&can0_clk);
  269. clk_register(&can1_clk);
  270. }
  271. clk_register(&pck0);
  272. clk_register(&pck1);
  273. }
  274. /* --------------------------------------------------------------------
  275. * AT91SAM9x5 processor initialization
  276. * -------------------------------------------------------------------- */
  277. static void __init at91sam9x5_map_io(void)
  278. {
  279. at91_init_sram(0, AT91SAM9X5_SRAM_BASE, AT91SAM9X5_SRAM_SIZE);
  280. }
  281. static void __init at91sam9x5_ioremap_registers(void)
  282. {
  283. if (of_at91sam926x_pit_init() < 0)
  284. panic("Impossible to find PIT\n");
  285. at91_ioremap_ramc(0, AT91SAM9X5_BASE_DDRSDRC0, 512);
  286. }
  287. void __init at91sam9x5_initialize(void)
  288. {
  289. arm_pm_restart = at91sam9g45_restart;
  290. at91_extern_irq = (1 << AT91SAM9X5_ID_IRQ0);
  291. /* Register GPIO subsystem (using DT) */
  292. at91_gpio_init(NULL, 0);
  293. }
  294. /* --------------------------------------------------------------------
  295. * AT91SAM9x5 devices (temporary before modification of code)
  296. * -------------------------------------------------------------------- */
  297. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  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. .ioremap_registers = at91sam9x5_ioremap_registers,
  342. .register_clocks = at91sam9x5_register_clocks,
  343. .init = at91sam9x5_initialize,
  344. };