at91sam9263.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * arch/arm/mach-at91/at91sam9263.c
  3. *
  4. * Copyright (C) 2007 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 <asm/irq.h>
  14. #include <asm/mach/arch.h>
  15. #include <asm/mach/map.h>
  16. #include <mach/at91sam9263.h>
  17. #include <mach/at91_pmc.h>
  18. #include <mach/at91_rstc.h>
  19. #include "soc.h"
  20. #include "generic.h"
  21. #include "clock.h"
  22. #include "sam9_smc.h"
  23. /* --------------------------------------------------------------------
  24. * Clocks
  25. * -------------------------------------------------------------------- */
  26. /*
  27. * The peripheral clocks.
  28. */
  29. static struct clk pioA_clk = {
  30. .name = "pioA_clk",
  31. .pmc_mask = 1 << AT91SAM9263_ID_PIOA,
  32. .type = CLK_TYPE_PERIPHERAL,
  33. };
  34. static struct clk pioB_clk = {
  35. .name = "pioB_clk",
  36. .pmc_mask = 1 << AT91SAM9263_ID_PIOB,
  37. .type = CLK_TYPE_PERIPHERAL,
  38. };
  39. static struct clk pioCDE_clk = {
  40. .name = "pioCDE_clk",
  41. .pmc_mask = 1 << AT91SAM9263_ID_PIOCDE,
  42. .type = CLK_TYPE_PERIPHERAL,
  43. };
  44. static struct clk usart0_clk = {
  45. .name = "usart0_clk",
  46. .pmc_mask = 1 << AT91SAM9263_ID_US0,
  47. .type = CLK_TYPE_PERIPHERAL,
  48. };
  49. static struct clk usart1_clk = {
  50. .name = "usart1_clk",
  51. .pmc_mask = 1 << AT91SAM9263_ID_US1,
  52. .type = CLK_TYPE_PERIPHERAL,
  53. };
  54. static struct clk usart2_clk = {
  55. .name = "usart2_clk",
  56. .pmc_mask = 1 << AT91SAM9263_ID_US2,
  57. .type = CLK_TYPE_PERIPHERAL,
  58. };
  59. static struct clk mmc0_clk = {
  60. .name = "mci0_clk",
  61. .pmc_mask = 1 << AT91SAM9263_ID_MCI0,
  62. .type = CLK_TYPE_PERIPHERAL,
  63. };
  64. static struct clk mmc1_clk = {
  65. .name = "mci1_clk",
  66. .pmc_mask = 1 << AT91SAM9263_ID_MCI1,
  67. .type = CLK_TYPE_PERIPHERAL,
  68. };
  69. static struct clk can_clk = {
  70. .name = "can_clk",
  71. .pmc_mask = 1 << AT91SAM9263_ID_CAN,
  72. .type = CLK_TYPE_PERIPHERAL,
  73. };
  74. static struct clk twi_clk = {
  75. .name = "twi_clk",
  76. .pmc_mask = 1 << AT91SAM9263_ID_TWI,
  77. .type = CLK_TYPE_PERIPHERAL,
  78. };
  79. static struct clk spi0_clk = {
  80. .name = "spi0_clk",
  81. .pmc_mask = 1 << AT91SAM9263_ID_SPI0,
  82. .type = CLK_TYPE_PERIPHERAL,
  83. };
  84. static struct clk spi1_clk = {
  85. .name = "spi1_clk",
  86. .pmc_mask = 1 << AT91SAM9263_ID_SPI1,
  87. .type = CLK_TYPE_PERIPHERAL,
  88. };
  89. static struct clk ssc0_clk = {
  90. .name = "ssc0_clk",
  91. .pmc_mask = 1 << AT91SAM9263_ID_SSC0,
  92. .type = CLK_TYPE_PERIPHERAL,
  93. };
  94. static struct clk ssc1_clk = {
  95. .name = "ssc1_clk",
  96. .pmc_mask = 1 << AT91SAM9263_ID_SSC1,
  97. .type = CLK_TYPE_PERIPHERAL,
  98. };
  99. static struct clk ac97_clk = {
  100. .name = "ac97_clk",
  101. .pmc_mask = 1 << AT91SAM9263_ID_AC97C,
  102. .type = CLK_TYPE_PERIPHERAL,
  103. };
  104. static struct clk tcb_clk = {
  105. .name = "tcb_clk",
  106. .pmc_mask = 1 << AT91SAM9263_ID_TCB,
  107. .type = CLK_TYPE_PERIPHERAL,
  108. };
  109. static struct clk pwm_clk = {
  110. .name = "pwm_clk",
  111. .pmc_mask = 1 << AT91SAM9263_ID_PWMC,
  112. .type = CLK_TYPE_PERIPHERAL,
  113. };
  114. static struct clk macb_clk = {
  115. .name = "pclk",
  116. .pmc_mask = 1 << AT91SAM9263_ID_EMAC,
  117. .type = CLK_TYPE_PERIPHERAL,
  118. };
  119. static struct clk dma_clk = {
  120. .name = "dma_clk",
  121. .pmc_mask = 1 << AT91SAM9263_ID_DMA,
  122. .type = CLK_TYPE_PERIPHERAL,
  123. };
  124. static struct clk twodge_clk = {
  125. .name = "2dge_clk",
  126. .pmc_mask = 1 << AT91SAM9263_ID_2DGE,
  127. .type = CLK_TYPE_PERIPHERAL,
  128. };
  129. static struct clk udc_clk = {
  130. .name = "udc_clk",
  131. .pmc_mask = 1 << AT91SAM9263_ID_UDP,
  132. .type = CLK_TYPE_PERIPHERAL,
  133. };
  134. static struct clk isi_clk = {
  135. .name = "isi_clk",
  136. .pmc_mask = 1 << AT91SAM9263_ID_ISI,
  137. .type = CLK_TYPE_PERIPHERAL,
  138. };
  139. static struct clk lcdc_clk = {
  140. .name = "lcdc_clk",
  141. .pmc_mask = 1 << AT91SAM9263_ID_LCDC,
  142. .type = CLK_TYPE_PERIPHERAL,
  143. };
  144. static struct clk ohci_clk = {
  145. .name = "ohci_clk",
  146. .pmc_mask = 1 << AT91SAM9263_ID_UHP,
  147. .type = CLK_TYPE_PERIPHERAL,
  148. };
  149. static struct clk *periph_clocks[] __initdata = {
  150. &pioA_clk,
  151. &pioB_clk,
  152. &pioCDE_clk,
  153. &usart0_clk,
  154. &usart1_clk,
  155. &usart2_clk,
  156. &mmc0_clk,
  157. &mmc1_clk,
  158. &can_clk,
  159. &twi_clk,
  160. &spi0_clk,
  161. &spi1_clk,
  162. &ssc0_clk,
  163. &ssc1_clk,
  164. &ac97_clk,
  165. &tcb_clk,
  166. &pwm_clk,
  167. &macb_clk,
  168. &twodge_clk,
  169. &udc_clk,
  170. &isi_clk,
  171. &lcdc_clk,
  172. &dma_clk,
  173. &ohci_clk,
  174. // irq0 .. irq1
  175. };
  176. static struct clk_lookup periph_clocks_lookups[] = {
  177. /* One additional fake clock for macb_hclk */
  178. CLKDEV_CON_ID("hclk", &macb_clk),
  179. CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
  180. CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
  181. CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.0", &mmc0_clk),
  182. CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.1", &mmc1_clk),
  183. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
  184. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
  185. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
  186. /* fake hclk clock */
  187. CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
  188. CLKDEV_CON_ID("pioA", &pioA_clk),
  189. CLKDEV_CON_ID("pioB", &pioB_clk),
  190. CLKDEV_CON_ID("pioC", &pioCDE_clk),
  191. CLKDEV_CON_ID("pioD", &pioCDE_clk),
  192. CLKDEV_CON_ID("pioE", &pioCDE_clk),
  193. };
  194. static struct clk_lookup usart_clocks_lookups[] = {
  195. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  196. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  197. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  198. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  199. };
  200. /*
  201. * The four programmable clocks.
  202. * You must configure pin multiplexing to bring these signals out.
  203. */
  204. static struct clk pck0 = {
  205. .name = "pck0",
  206. .pmc_mask = AT91_PMC_PCK0,
  207. .type = CLK_TYPE_PROGRAMMABLE,
  208. .id = 0,
  209. };
  210. static struct clk pck1 = {
  211. .name = "pck1",
  212. .pmc_mask = AT91_PMC_PCK1,
  213. .type = CLK_TYPE_PROGRAMMABLE,
  214. .id = 1,
  215. };
  216. static struct clk pck2 = {
  217. .name = "pck2",
  218. .pmc_mask = AT91_PMC_PCK2,
  219. .type = CLK_TYPE_PROGRAMMABLE,
  220. .id = 2,
  221. };
  222. static struct clk pck3 = {
  223. .name = "pck3",
  224. .pmc_mask = AT91_PMC_PCK3,
  225. .type = CLK_TYPE_PROGRAMMABLE,
  226. .id = 3,
  227. };
  228. static void __init at91sam9263_register_clocks(void)
  229. {
  230. int i;
  231. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  232. clk_register(periph_clocks[i]);
  233. clkdev_add_table(periph_clocks_lookups,
  234. ARRAY_SIZE(periph_clocks_lookups));
  235. clkdev_add_table(usart_clocks_lookups,
  236. ARRAY_SIZE(usart_clocks_lookups));
  237. clk_register(&pck0);
  238. clk_register(&pck1);
  239. clk_register(&pck2);
  240. clk_register(&pck3);
  241. }
  242. static struct clk_lookup console_clock_lookup;
  243. void __init at91sam9263_set_console_clock(int id)
  244. {
  245. if (id >= ARRAY_SIZE(usart_clocks_lookups))
  246. return;
  247. console_clock_lookup.con_id = "usart";
  248. console_clock_lookup.clk = usart_clocks_lookups[id].clk;
  249. clkdev_add(&console_clock_lookup);
  250. }
  251. /* --------------------------------------------------------------------
  252. * GPIO
  253. * -------------------------------------------------------------------- */
  254. static struct at91_gpio_bank at91sam9263_gpio[] __initdata = {
  255. {
  256. .id = AT91SAM9263_ID_PIOA,
  257. .regbase = AT91SAM9263_BASE_PIOA,
  258. }, {
  259. .id = AT91SAM9263_ID_PIOB,
  260. .regbase = AT91SAM9263_BASE_PIOB,
  261. }, {
  262. .id = AT91SAM9263_ID_PIOCDE,
  263. .regbase = AT91SAM9263_BASE_PIOC,
  264. }, {
  265. .id = AT91SAM9263_ID_PIOCDE,
  266. .regbase = AT91SAM9263_BASE_PIOD,
  267. }, {
  268. .id = AT91SAM9263_ID_PIOCDE,
  269. .regbase = AT91SAM9263_BASE_PIOE,
  270. }
  271. };
  272. /* --------------------------------------------------------------------
  273. * AT91SAM9263 processor initialization
  274. * -------------------------------------------------------------------- */
  275. static void __init at91sam9263_map_io(void)
  276. {
  277. at91_init_sram(0, AT91SAM9263_SRAM0_BASE, AT91SAM9263_SRAM0_SIZE);
  278. at91_init_sram(1, AT91SAM9263_SRAM1_BASE, AT91SAM9263_SRAM1_SIZE);
  279. }
  280. static void __init at91sam9263_ioremap_registers(void)
  281. {
  282. at91_ioremap_shdwc(AT91SAM9263_BASE_SHDWC);
  283. at91sam926x_ioremap_pit(AT91SAM9263_BASE_PIT);
  284. at91sam9_ioremap_smc(0, AT91SAM9263_BASE_SMC0);
  285. at91sam9_ioremap_smc(1, AT91SAM9263_BASE_SMC1);
  286. }
  287. static void __init at91sam9263_initialize(void)
  288. {
  289. arm_pm_restart = at91sam9_alt_restart;
  290. at91_extern_irq = (1 << AT91SAM9263_ID_IRQ0) | (1 << AT91SAM9263_ID_IRQ1);
  291. /* Register GPIO subsystem */
  292. at91_gpio_init(at91sam9263_gpio, 5);
  293. }
  294. /* --------------------------------------------------------------------
  295. * Interrupt initialization
  296. * -------------------------------------------------------------------- */
  297. /*
  298. * The default interrupt priority levels (0 = lowest, 7 = highest).
  299. */
  300. static unsigned int at91sam9263_default_irq_priority[NR_AIC_IRQS] __initdata = {
  301. 7, /* Advanced Interrupt Controller (FIQ) */
  302. 7, /* System Peripherals */
  303. 1, /* Parallel IO Controller A */
  304. 1, /* Parallel IO Controller B */
  305. 1, /* Parallel IO Controller C, D and E */
  306. 0,
  307. 0,
  308. 5, /* USART 0 */
  309. 5, /* USART 1 */
  310. 5, /* USART 2 */
  311. 0, /* Multimedia Card Interface 0 */
  312. 0, /* Multimedia Card Interface 1 */
  313. 3, /* CAN */
  314. 6, /* Two-Wire Interface */
  315. 5, /* Serial Peripheral Interface 0 */
  316. 5, /* Serial Peripheral Interface 1 */
  317. 4, /* Serial Synchronous Controller 0 */
  318. 4, /* Serial Synchronous Controller 1 */
  319. 5, /* AC97 Controller */
  320. 0, /* Timer Counter 0, 1 and 2 */
  321. 0, /* Pulse Width Modulation Controller */
  322. 3, /* Ethernet */
  323. 0,
  324. 0, /* 2D Graphic Engine */
  325. 2, /* USB Device Port */
  326. 0, /* Image Sensor Interface */
  327. 3, /* LDC Controller */
  328. 0, /* DMA Controller */
  329. 0,
  330. 2, /* USB Host port */
  331. 0, /* Advanced Interrupt Controller (IRQ0) */
  332. 0, /* Advanced Interrupt Controller (IRQ1) */
  333. };
  334. struct at91_init_soc __initdata at91sam9263_soc = {
  335. .map_io = at91sam9263_map_io,
  336. .default_irq_priority = at91sam9263_default_irq_priority,
  337. .ioremap_registers = at91sam9263_ioremap_registers,
  338. .register_clocks = at91sam9263_register_clocks,
  339. .init = at91sam9263_initialize,
  340. };