at91sam9261.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. * arch/arm/mach-at91/at91sam9261.c
  3. *
  4. * Copyright (C) 2005 SAN People
  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/platform_device.h>
  14. #include <linux/clk/at91_pmc.h>
  15. #include <asm/proc-fns.h>
  16. #include <asm/irq.h>
  17. #include <asm/mach/arch.h>
  18. #include <asm/mach/map.h>
  19. #include <asm/system_misc.h>
  20. #include <mach/cpu.h>
  21. #include <mach/at91sam9261.h>
  22. #include <mach/hardware.h>
  23. #include "at91_aic.h"
  24. #include "soc.h"
  25. #include "generic.h"
  26. #include "sam9_smc.h"
  27. #include "pm.h"
  28. #if defined(CONFIG_OLD_CLK_AT91)
  29. #include "clock.h"
  30. /* --------------------------------------------------------------------
  31. * Clocks
  32. * -------------------------------------------------------------------- */
  33. /*
  34. * The peripheral clocks.
  35. */
  36. static struct clk pioA_clk = {
  37. .name = "pioA_clk",
  38. .pmc_mask = 1 << AT91SAM9261_ID_PIOA,
  39. .type = CLK_TYPE_PERIPHERAL,
  40. };
  41. static struct clk pioB_clk = {
  42. .name = "pioB_clk",
  43. .pmc_mask = 1 << AT91SAM9261_ID_PIOB,
  44. .type = CLK_TYPE_PERIPHERAL,
  45. };
  46. static struct clk pioC_clk = {
  47. .name = "pioC_clk",
  48. .pmc_mask = 1 << AT91SAM9261_ID_PIOC,
  49. .type = CLK_TYPE_PERIPHERAL,
  50. };
  51. static struct clk usart0_clk = {
  52. .name = "usart0_clk",
  53. .pmc_mask = 1 << AT91SAM9261_ID_US0,
  54. .type = CLK_TYPE_PERIPHERAL,
  55. };
  56. static struct clk usart1_clk = {
  57. .name = "usart1_clk",
  58. .pmc_mask = 1 << AT91SAM9261_ID_US1,
  59. .type = CLK_TYPE_PERIPHERAL,
  60. };
  61. static struct clk usart2_clk = {
  62. .name = "usart2_clk",
  63. .pmc_mask = 1 << AT91SAM9261_ID_US2,
  64. .type = CLK_TYPE_PERIPHERAL,
  65. };
  66. static struct clk mmc_clk = {
  67. .name = "mci_clk",
  68. .pmc_mask = 1 << AT91SAM9261_ID_MCI,
  69. .type = CLK_TYPE_PERIPHERAL,
  70. };
  71. static struct clk udc_clk = {
  72. .name = "udc_clk",
  73. .pmc_mask = 1 << AT91SAM9261_ID_UDP,
  74. .type = CLK_TYPE_PERIPHERAL,
  75. };
  76. static struct clk twi_clk = {
  77. .name = "twi_clk",
  78. .pmc_mask = 1 << AT91SAM9261_ID_TWI,
  79. .type = CLK_TYPE_PERIPHERAL,
  80. };
  81. static struct clk spi0_clk = {
  82. .name = "spi0_clk",
  83. .pmc_mask = 1 << AT91SAM9261_ID_SPI0,
  84. .type = CLK_TYPE_PERIPHERAL,
  85. };
  86. static struct clk spi1_clk = {
  87. .name = "spi1_clk",
  88. .pmc_mask = 1 << AT91SAM9261_ID_SPI1,
  89. .type = CLK_TYPE_PERIPHERAL,
  90. };
  91. static struct clk ssc0_clk = {
  92. .name = "ssc0_clk",
  93. .pmc_mask = 1 << AT91SAM9261_ID_SSC0,
  94. .type = CLK_TYPE_PERIPHERAL,
  95. };
  96. static struct clk ssc1_clk = {
  97. .name = "ssc1_clk",
  98. .pmc_mask = 1 << AT91SAM9261_ID_SSC1,
  99. .type = CLK_TYPE_PERIPHERAL,
  100. };
  101. static struct clk ssc2_clk = {
  102. .name = "ssc2_clk",
  103. .pmc_mask = 1 << AT91SAM9261_ID_SSC2,
  104. .type = CLK_TYPE_PERIPHERAL,
  105. };
  106. static struct clk tc0_clk = {
  107. .name = "tc0_clk",
  108. .pmc_mask = 1 << AT91SAM9261_ID_TC0,
  109. .type = CLK_TYPE_PERIPHERAL,
  110. };
  111. static struct clk tc1_clk = {
  112. .name = "tc1_clk",
  113. .pmc_mask = 1 << AT91SAM9261_ID_TC1,
  114. .type = CLK_TYPE_PERIPHERAL,
  115. };
  116. static struct clk tc2_clk = {
  117. .name = "tc2_clk",
  118. .pmc_mask = 1 << AT91SAM9261_ID_TC2,
  119. .type = CLK_TYPE_PERIPHERAL,
  120. };
  121. static struct clk ohci_clk = {
  122. .name = "ohci_clk",
  123. .pmc_mask = 1 << AT91SAM9261_ID_UHP,
  124. .type = CLK_TYPE_PERIPHERAL,
  125. };
  126. static struct clk lcdc_clk = {
  127. .name = "lcdc_clk",
  128. .pmc_mask = 1 << AT91SAM9261_ID_LCDC,
  129. .type = CLK_TYPE_PERIPHERAL,
  130. };
  131. /* HClocks */
  132. static struct clk hck0 = {
  133. .name = "hck0",
  134. .pmc_mask = AT91_PMC_HCK0,
  135. .type = CLK_TYPE_SYSTEM,
  136. .id = 0,
  137. };
  138. static struct clk hck1 = {
  139. .name = "hck1",
  140. .pmc_mask = AT91_PMC_HCK1,
  141. .type = CLK_TYPE_SYSTEM,
  142. .id = 1,
  143. };
  144. static struct clk *periph_clocks[] __initdata = {
  145. &pioA_clk,
  146. &pioB_clk,
  147. &pioC_clk,
  148. &usart0_clk,
  149. &usart1_clk,
  150. &usart2_clk,
  151. &mmc_clk,
  152. &udc_clk,
  153. &twi_clk,
  154. &spi0_clk,
  155. &spi1_clk,
  156. &ssc0_clk,
  157. &ssc1_clk,
  158. &ssc2_clk,
  159. &tc0_clk,
  160. &tc1_clk,
  161. &tc2_clk,
  162. &ohci_clk,
  163. &lcdc_clk,
  164. // irq0 .. irq2
  165. };
  166. static struct clk_lookup periph_clocks_lookups[] = {
  167. CLKDEV_CON_DEV_ID("hclk", "at91sam9261-lcdfb.0", &hck1),
  168. CLKDEV_CON_DEV_ID("hclk", "at91sam9g10-lcdfb.0", &hck1),
  169. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
  170. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
  171. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
  172. CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
  173. CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
  174. CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.0", &ssc0_clk),
  175. CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.1", &ssc1_clk),
  176. CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.2", &ssc2_clk),
  177. CLKDEV_CON_DEV_ID("pclk", "fffbc000.ssc", &ssc0_clk),
  178. CLKDEV_CON_DEV_ID("pclk", "fffc0000.ssc", &ssc1_clk),
  179. CLKDEV_CON_DEV_ID("pclk", "fffc4000.ssc", &ssc2_clk),
  180. CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &hck0),
  181. CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9261.0", &twi_clk),
  182. CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9g10.0", &twi_clk),
  183. CLKDEV_CON_ID("pioA", &pioA_clk),
  184. CLKDEV_CON_ID("pioB", &pioB_clk),
  185. CLKDEV_CON_ID("pioC", &pioC_clk),
  186. /* more lookup table for DT entries */
  187. CLKDEV_CON_DEV_ID("usart", "fffff200.serial", &mck),
  188. CLKDEV_CON_DEV_ID("usart", "fffb0000.serial", &usart0_clk),
  189. CLKDEV_CON_DEV_ID("usart", "ffffb400.serial", &usart1_clk),
  190. CLKDEV_CON_DEV_ID("usart", "fff94000.serial", &usart2_clk),
  191. CLKDEV_CON_DEV_ID("t0_clk", "fffa0000.timer", &tc0_clk),
  192. CLKDEV_CON_DEV_ID("t1_clk", "fffa0000.timer", &tc1_clk),
  193. CLKDEV_CON_DEV_ID("t2_clk", "fffa0000.timer", &tc2_clk),
  194. CLKDEV_CON_DEV_ID("hclk", "500000.ohci", &hck0),
  195. CLKDEV_CON_DEV_ID("hclk", "600000.fb", &hck1),
  196. CLKDEV_CON_DEV_ID("spi_clk", "fffc8000.spi", &spi0_clk),
  197. CLKDEV_CON_DEV_ID("spi_clk", "fffcc000.spi", &spi1_clk),
  198. CLKDEV_CON_DEV_ID("mci_clk", "fffa8000.mmc", &mmc_clk),
  199. CLKDEV_CON_DEV_ID(NULL, "fffac000.i2c", &twi_clk),
  200. CLKDEV_CON_DEV_ID(NULL, "fffff400.gpio", &pioA_clk),
  201. CLKDEV_CON_DEV_ID(NULL, "fffff600.gpio", &pioB_clk),
  202. CLKDEV_CON_DEV_ID(NULL, "fffff800.gpio", &pioC_clk),
  203. };
  204. static struct clk_lookup usart_clocks_lookups[] = {
  205. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  206. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  207. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  208. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  209. };
  210. /*
  211. * The four programmable clocks.
  212. * You must configure pin multiplexing to bring these signals out.
  213. */
  214. static struct clk pck0 = {
  215. .name = "pck0",
  216. .pmc_mask = AT91_PMC_PCK0,
  217. .type = CLK_TYPE_PROGRAMMABLE,
  218. .id = 0,
  219. };
  220. static struct clk pck1 = {
  221. .name = "pck1",
  222. .pmc_mask = AT91_PMC_PCK1,
  223. .type = CLK_TYPE_PROGRAMMABLE,
  224. .id = 1,
  225. };
  226. static struct clk pck2 = {
  227. .name = "pck2",
  228. .pmc_mask = AT91_PMC_PCK2,
  229. .type = CLK_TYPE_PROGRAMMABLE,
  230. .id = 2,
  231. };
  232. static struct clk pck3 = {
  233. .name = "pck3",
  234. .pmc_mask = AT91_PMC_PCK3,
  235. .type = CLK_TYPE_PROGRAMMABLE,
  236. .id = 3,
  237. };
  238. static void __init at91sam9261_register_clocks(void)
  239. {
  240. int i;
  241. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  242. clk_register(periph_clocks[i]);
  243. clkdev_add_table(periph_clocks_lookups,
  244. ARRAY_SIZE(periph_clocks_lookups));
  245. clkdev_add_table(usart_clocks_lookups,
  246. ARRAY_SIZE(usart_clocks_lookups));
  247. clk_register(&pck0);
  248. clk_register(&pck1);
  249. clk_register(&pck2);
  250. clk_register(&pck3);
  251. clk_register(&hck0);
  252. clk_register(&hck1);
  253. }
  254. #else
  255. #define at91sam9261_register_clocks NULL
  256. #endif
  257. /* --------------------------------------------------------------------
  258. * GPIO
  259. * -------------------------------------------------------------------- */
  260. static struct at91_gpio_bank at91sam9261_gpio[] __initdata = {
  261. {
  262. .id = AT91SAM9261_ID_PIOA,
  263. .regbase = AT91SAM9261_BASE_PIOA,
  264. }, {
  265. .id = AT91SAM9261_ID_PIOB,
  266. .regbase = AT91SAM9261_BASE_PIOB,
  267. }, {
  268. .id = AT91SAM9261_ID_PIOC,
  269. .regbase = AT91SAM9261_BASE_PIOC,
  270. }
  271. };
  272. /* --------------------------------------------------------------------
  273. * AT91SAM9261 processor initialization
  274. * -------------------------------------------------------------------- */
  275. static void __init at91sam9261_map_io(void)
  276. {
  277. if (cpu_is_at91sam9g10())
  278. at91_init_sram(0, AT91SAM9G10_SRAM_BASE, AT91SAM9G10_SRAM_SIZE);
  279. else
  280. at91_init_sram(0, AT91SAM9261_SRAM_BASE, AT91SAM9261_SRAM_SIZE);
  281. }
  282. static void __init at91sam9261_ioremap_registers(void)
  283. {
  284. at91_ioremap_ramc(0, AT91SAM9261_BASE_SDRAMC, 512);
  285. at91sam926x_ioremap_pit(AT91SAM9261_BASE_PIT);
  286. at91sam9_ioremap_smc(0, AT91SAM9261_BASE_SMC);
  287. at91_ioremap_matrix(AT91SAM9261_BASE_MATRIX);
  288. at91_pm_set_standby(at91sam9_sdram_standby);
  289. }
  290. static void __init at91sam9261_initialize(void)
  291. {
  292. arm_pm_idle = at91sam9_idle;
  293. at91_sysirq_mask_rtt(AT91SAM9261_BASE_RTT);
  294. /* Register GPIO subsystem */
  295. at91_gpio_init(at91sam9261_gpio, 3);
  296. }
  297. static struct resource rstc_resources[] = {
  298. [0] = {
  299. .start = AT91SAM9261_BASE_RSTC,
  300. .end = AT91SAM9261_BASE_RSTC + SZ_16 - 1,
  301. .flags = IORESOURCE_MEM,
  302. },
  303. [1] = {
  304. .start = AT91SAM9261_BASE_SDRAMC,
  305. .end = AT91SAM9261_BASE_SDRAMC + SZ_512 - 1,
  306. .flags = IORESOURCE_MEM,
  307. },
  308. };
  309. static struct platform_device rstc_device = {
  310. .name = "at91-sam9260-reset",
  311. .resource = rstc_resources,
  312. .num_resources = ARRAY_SIZE(rstc_resources),
  313. };
  314. static struct resource shdwc_resources[] = {
  315. [0] = {
  316. .start = AT91SAM9261_BASE_SHDWC,
  317. .end = AT91SAM9261_BASE_SHDWC + SZ_16 - 1,
  318. .flags = IORESOURCE_MEM,
  319. },
  320. };
  321. static struct platform_device shdwc_device = {
  322. .name = "at91-poweroff",
  323. .resource = shdwc_resources,
  324. .num_resources = ARRAY_SIZE(shdwc_resources),
  325. };
  326. static void __init at91sam9261_register_devices(void)
  327. {
  328. platform_device_register(&rstc_device);
  329. platform_device_register(&shdwc_device);
  330. }
  331. /* --------------------------------------------------------------------
  332. * Interrupt initialization
  333. * -------------------------------------------------------------------- */
  334. /*
  335. * The default interrupt priority levels (0 = lowest, 7 = highest).
  336. */
  337. static unsigned int at91sam9261_default_irq_priority[NR_AIC_IRQS] __initdata = {
  338. 7, /* Advanced Interrupt Controller */
  339. 7, /* System Peripherals */
  340. 1, /* Parallel IO Controller A */
  341. 1, /* Parallel IO Controller B */
  342. 1, /* Parallel IO Controller C */
  343. 0,
  344. 5, /* USART 0 */
  345. 5, /* USART 1 */
  346. 5, /* USART 2 */
  347. 0, /* Multimedia Card Interface */
  348. 2, /* USB Device Port */
  349. 6, /* Two-Wire Interface */
  350. 5, /* Serial Peripheral Interface 0 */
  351. 5, /* Serial Peripheral Interface 1 */
  352. 4, /* Serial Synchronous Controller 0 */
  353. 4, /* Serial Synchronous Controller 1 */
  354. 4, /* Serial Synchronous Controller 2 */
  355. 0, /* Timer Counter 0 */
  356. 0, /* Timer Counter 1 */
  357. 0, /* Timer Counter 2 */
  358. 2, /* USB Host port */
  359. 3, /* LCD Controller */
  360. 0,
  361. 0,
  362. 0,
  363. 0,
  364. 0,
  365. 0,
  366. 0,
  367. 0, /* Advanced Interrupt Controller */
  368. 0, /* Advanced Interrupt Controller */
  369. 0, /* Advanced Interrupt Controller */
  370. };
  371. static void __init at91sam9261_init_time(void)
  372. {
  373. at91sam926x_pit_init(NR_IRQS_LEGACY + AT91_ID_SYS);
  374. }
  375. AT91_SOC_START(at91sam9261)
  376. .map_io = at91sam9261_map_io,
  377. .default_irq_priority = at91sam9261_default_irq_priority,
  378. .extern_irq = (1 << AT91SAM9261_ID_IRQ0) | (1 << AT91SAM9261_ID_IRQ1)
  379. | (1 << AT91SAM9261_ID_IRQ2),
  380. .ioremap_registers = at91sam9261_ioremap_registers,
  381. .register_clocks = at91sam9261_register_clocks,
  382. .register_devices = at91sam9261_register_devices,
  383. .init = at91sam9261_initialize,
  384. .init_time = at91sam9261_init_time,
  385. AT91_SOC_END