at91sam9261.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 <asm/proc-fns.h>
  14. #include <asm/irq.h>
  15. #include <asm/mach/arch.h>
  16. #include <asm/mach/map.h>
  17. #include <mach/cpu.h>
  18. #include <mach/at91sam9261.h>
  19. #include <mach/at91_pmc.h>
  20. #include <mach/at91_rstc.h>
  21. #include "soc.h"
  22. #include "generic.h"
  23. #include "clock.h"
  24. #include "sam9_smc.h"
  25. /* --------------------------------------------------------------------
  26. * Clocks
  27. * -------------------------------------------------------------------- */
  28. /*
  29. * The peripheral clocks.
  30. */
  31. static struct clk pioA_clk = {
  32. .name = "pioA_clk",
  33. .pmc_mask = 1 << AT91SAM9261_ID_PIOA,
  34. .type = CLK_TYPE_PERIPHERAL,
  35. };
  36. static struct clk pioB_clk = {
  37. .name = "pioB_clk",
  38. .pmc_mask = 1 << AT91SAM9261_ID_PIOB,
  39. .type = CLK_TYPE_PERIPHERAL,
  40. };
  41. static struct clk pioC_clk = {
  42. .name = "pioC_clk",
  43. .pmc_mask = 1 << AT91SAM9261_ID_PIOC,
  44. .type = CLK_TYPE_PERIPHERAL,
  45. };
  46. static struct clk usart0_clk = {
  47. .name = "usart0_clk",
  48. .pmc_mask = 1 << AT91SAM9261_ID_US0,
  49. .type = CLK_TYPE_PERIPHERAL,
  50. };
  51. static struct clk usart1_clk = {
  52. .name = "usart1_clk",
  53. .pmc_mask = 1 << AT91SAM9261_ID_US1,
  54. .type = CLK_TYPE_PERIPHERAL,
  55. };
  56. static struct clk usart2_clk = {
  57. .name = "usart2_clk",
  58. .pmc_mask = 1 << AT91SAM9261_ID_US2,
  59. .type = CLK_TYPE_PERIPHERAL,
  60. };
  61. static struct clk mmc_clk = {
  62. .name = "mci_clk",
  63. .pmc_mask = 1 << AT91SAM9261_ID_MCI,
  64. .type = CLK_TYPE_PERIPHERAL,
  65. };
  66. static struct clk udc_clk = {
  67. .name = "udc_clk",
  68. .pmc_mask = 1 << AT91SAM9261_ID_UDP,
  69. .type = CLK_TYPE_PERIPHERAL,
  70. };
  71. static struct clk twi_clk = {
  72. .name = "twi_clk",
  73. .pmc_mask = 1 << AT91SAM9261_ID_TWI,
  74. .type = CLK_TYPE_PERIPHERAL,
  75. };
  76. static struct clk spi0_clk = {
  77. .name = "spi0_clk",
  78. .pmc_mask = 1 << AT91SAM9261_ID_SPI0,
  79. .type = CLK_TYPE_PERIPHERAL,
  80. };
  81. static struct clk spi1_clk = {
  82. .name = "spi1_clk",
  83. .pmc_mask = 1 << AT91SAM9261_ID_SPI1,
  84. .type = CLK_TYPE_PERIPHERAL,
  85. };
  86. static struct clk ssc0_clk = {
  87. .name = "ssc0_clk",
  88. .pmc_mask = 1 << AT91SAM9261_ID_SSC0,
  89. .type = CLK_TYPE_PERIPHERAL,
  90. };
  91. static struct clk ssc1_clk = {
  92. .name = "ssc1_clk",
  93. .pmc_mask = 1 << AT91SAM9261_ID_SSC1,
  94. .type = CLK_TYPE_PERIPHERAL,
  95. };
  96. static struct clk ssc2_clk = {
  97. .name = "ssc2_clk",
  98. .pmc_mask = 1 << AT91SAM9261_ID_SSC2,
  99. .type = CLK_TYPE_PERIPHERAL,
  100. };
  101. static struct clk tc0_clk = {
  102. .name = "tc0_clk",
  103. .pmc_mask = 1 << AT91SAM9261_ID_TC0,
  104. .type = CLK_TYPE_PERIPHERAL,
  105. };
  106. static struct clk tc1_clk = {
  107. .name = "tc1_clk",
  108. .pmc_mask = 1 << AT91SAM9261_ID_TC1,
  109. .type = CLK_TYPE_PERIPHERAL,
  110. };
  111. static struct clk tc2_clk = {
  112. .name = "tc2_clk",
  113. .pmc_mask = 1 << AT91SAM9261_ID_TC2,
  114. .type = CLK_TYPE_PERIPHERAL,
  115. };
  116. static struct clk ohci_clk = {
  117. .name = "ohci_clk",
  118. .pmc_mask = 1 << AT91SAM9261_ID_UHP,
  119. .type = CLK_TYPE_PERIPHERAL,
  120. };
  121. static struct clk lcdc_clk = {
  122. .name = "lcdc_clk",
  123. .pmc_mask = 1 << AT91SAM9261_ID_LCDC,
  124. .type = CLK_TYPE_PERIPHERAL,
  125. };
  126. /* HClocks */
  127. static struct clk hck0 = {
  128. .name = "hck0",
  129. .pmc_mask = AT91_PMC_HCK0,
  130. .type = CLK_TYPE_SYSTEM,
  131. .id = 0,
  132. };
  133. static struct clk hck1 = {
  134. .name = "hck1",
  135. .pmc_mask = AT91_PMC_HCK1,
  136. .type = CLK_TYPE_SYSTEM,
  137. .id = 1,
  138. };
  139. static struct clk *periph_clocks[] __initdata = {
  140. &pioA_clk,
  141. &pioB_clk,
  142. &pioC_clk,
  143. &usart0_clk,
  144. &usart1_clk,
  145. &usart2_clk,
  146. &mmc_clk,
  147. &udc_clk,
  148. &twi_clk,
  149. &spi0_clk,
  150. &spi1_clk,
  151. &ssc0_clk,
  152. &ssc1_clk,
  153. &ssc2_clk,
  154. &tc0_clk,
  155. &tc1_clk,
  156. &tc2_clk,
  157. &ohci_clk,
  158. &lcdc_clk,
  159. // irq0 .. irq2
  160. };
  161. static struct clk_lookup periph_clocks_lookups[] = {
  162. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
  163. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
  164. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
  165. CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
  166. CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
  167. CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
  168. CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
  169. CLKDEV_CON_DEV_ID("pclk", "ssc.2", &ssc2_clk),
  170. CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &hck0),
  171. CLKDEV_CON_ID("pioA", &pioA_clk),
  172. CLKDEV_CON_ID("pioB", &pioB_clk),
  173. CLKDEV_CON_ID("pioC", &pioC_clk),
  174. };
  175. static struct clk_lookup usart_clocks_lookups[] = {
  176. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  177. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  178. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  179. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  180. };
  181. /*
  182. * The four programmable clocks.
  183. * You must configure pin multiplexing to bring these signals out.
  184. */
  185. static struct clk pck0 = {
  186. .name = "pck0",
  187. .pmc_mask = AT91_PMC_PCK0,
  188. .type = CLK_TYPE_PROGRAMMABLE,
  189. .id = 0,
  190. };
  191. static struct clk pck1 = {
  192. .name = "pck1",
  193. .pmc_mask = AT91_PMC_PCK1,
  194. .type = CLK_TYPE_PROGRAMMABLE,
  195. .id = 1,
  196. };
  197. static struct clk pck2 = {
  198. .name = "pck2",
  199. .pmc_mask = AT91_PMC_PCK2,
  200. .type = CLK_TYPE_PROGRAMMABLE,
  201. .id = 2,
  202. };
  203. static struct clk pck3 = {
  204. .name = "pck3",
  205. .pmc_mask = AT91_PMC_PCK3,
  206. .type = CLK_TYPE_PROGRAMMABLE,
  207. .id = 3,
  208. };
  209. static void __init at91sam9261_register_clocks(void)
  210. {
  211. int i;
  212. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  213. clk_register(periph_clocks[i]);
  214. clkdev_add_table(periph_clocks_lookups,
  215. ARRAY_SIZE(periph_clocks_lookups));
  216. clkdev_add_table(usart_clocks_lookups,
  217. ARRAY_SIZE(usart_clocks_lookups));
  218. clk_register(&pck0);
  219. clk_register(&pck1);
  220. clk_register(&pck2);
  221. clk_register(&pck3);
  222. clk_register(&hck0);
  223. clk_register(&hck1);
  224. }
  225. static struct clk_lookup console_clock_lookup;
  226. void __init at91sam9261_set_console_clock(int id)
  227. {
  228. if (id >= ARRAY_SIZE(usart_clocks_lookups))
  229. return;
  230. console_clock_lookup.con_id = "usart";
  231. console_clock_lookup.clk = usart_clocks_lookups[id].clk;
  232. clkdev_add(&console_clock_lookup);
  233. }
  234. /* --------------------------------------------------------------------
  235. * GPIO
  236. * -------------------------------------------------------------------- */
  237. static struct at91_gpio_bank at91sam9261_gpio[] __initdata = {
  238. {
  239. .id = AT91SAM9261_ID_PIOA,
  240. .regbase = AT91SAM9261_BASE_PIOA,
  241. }, {
  242. .id = AT91SAM9261_ID_PIOB,
  243. .regbase = AT91SAM9261_BASE_PIOB,
  244. }, {
  245. .id = AT91SAM9261_ID_PIOC,
  246. .regbase = AT91SAM9261_BASE_PIOC,
  247. }
  248. };
  249. /* --------------------------------------------------------------------
  250. * AT91SAM9261 processor initialization
  251. * -------------------------------------------------------------------- */
  252. static void __init at91sam9261_map_io(void)
  253. {
  254. if (cpu_is_at91sam9g10())
  255. at91_init_sram(0, AT91SAM9G10_SRAM_BASE, AT91SAM9G10_SRAM_SIZE);
  256. else
  257. at91_init_sram(0, AT91SAM9261_SRAM_BASE, AT91SAM9261_SRAM_SIZE);
  258. }
  259. static void __init at91sam9261_ioremap_registers(void)
  260. {
  261. at91_ioremap_shdwc(AT91SAM9261_BASE_SHDWC);
  262. at91_ioremap_rstc(AT91SAM9261_BASE_RSTC);
  263. at91sam926x_ioremap_pit(AT91SAM9261_BASE_PIT);
  264. at91sam9_ioremap_smc(0, AT91SAM9261_BASE_SMC);
  265. }
  266. static void at91sam9261_idle(void)
  267. {
  268. at91_sys_write(AT91_PMC_SCDR, AT91_PMC_PCK);
  269. cpu_do_idle();
  270. }
  271. static void __init at91sam9261_initialize(void)
  272. {
  273. arm_pm_idle = at91sam9261_idle;
  274. arm_pm_restart = at91sam9_alt_restart;
  275. at91_extern_irq = (1 << AT91SAM9261_ID_IRQ0) | (1 << AT91SAM9261_ID_IRQ1)
  276. | (1 << AT91SAM9261_ID_IRQ2);
  277. /* Register GPIO subsystem */
  278. at91_gpio_init(at91sam9261_gpio, 3);
  279. }
  280. /* --------------------------------------------------------------------
  281. * Interrupt initialization
  282. * -------------------------------------------------------------------- */
  283. /*
  284. * The default interrupt priority levels (0 = lowest, 7 = highest).
  285. */
  286. static unsigned int at91sam9261_default_irq_priority[NR_AIC_IRQS] __initdata = {
  287. 7, /* Advanced Interrupt Controller */
  288. 7, /* System Peripherals */
  289. 1, /* Parallel IO Controller A */
  290. 1, /* Parallel IO Controller B */
  291. 1, /* Parallel IO Controller C */
  292. 0,
  293. 5, /* USART 0 */
  294. 5, /* USART 1 */
  295. 5, /* USART 2 */
  296. 0, /* Multimedia Card Interface */
  297. 2, /* USB Device Port */
  298. 6, /* Two-Wire Interface */
  299. 5, /* Serial Peripheral Interface 0 */
  300. 5, /* Serial Peripheral Interface 1 */
  301. 4, /* Serial Synchronous Controller 0 */
  302. 4, /* Serial Synchronous Controller 1 */
  303. 4, /* Serial Synchronous Controller 2 */
  304. 0, /* Timer Counter 0 */
  305. 0, /* Timer Counter 1 */
  306. 0, /* Timer Counter 2 */
  307. 2, /* USB Host port */
  308. 3, /* LCD Controller */
  309. 0,
  310. 0,
  311. 0,
  312. 0,
  313. 0,
  314. 0,
  315. 0,
  316. 0, /* Advanced Interrupt Controller */
  317. 0, /* Advanced Interrupt Controller */
  318. 0, /* Advanced Interrupt Controller */
  319. };
  320. struct at91_init_soc __initdata at91sam9261_soc = {
  321. .map_io = at91sam9261_map_io,
  322. .default_irq_priority = at91sam9261_default_irq_priority,
  323. .ioremap_registers = at91sam9261_ioremap_registers,
  324. .register_clocks = at91sam9261_register_clocks,
  325. .init = at91sam9261_initialize,
  326. };