at91sam9261.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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/pm.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 <mach/at91_shdwc.h>
  22. #include "soc.h"
  23. #include "generic.h"
  24. #include "clock.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. static struct clk *periph_clocks[] __initdata = {
  127. &pioA_clk,
  128. &pioB_clk,
  129. &pioC_clk,
  130. &usart0_clk,
  131. &usart1_clk,
  132. &usart2_clk,
  133. &mmc_clk,
  134. &udc_clk,
  135. &twi_clk,
  136. &spi0_clk,
  137. &spi1_clk,
  138. &ssc0_clk,
  139. &ssc1_clk,
  140. &ssc2_clk,
  141. &tc0_clk,
  142. &tc1_clk,
  143. &tc2_clk,
  144. &ohci_clk,
  145. &lcdc_clk,
  146. // irq0 .. irq2
  147. };
  148. static struct clk_lookup periph_clocks_lookups[] = {
  149. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
  150. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
  151. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
  152. CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
  153. CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc1_clk),
  154. CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
  155. CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
  156. CLKDEV_CON_DEV_ID("pclk", "ssc.2", &ssc2_clk),
  157. };
  158. static struct clk_lookup usart_clocks_lookups[] = {
  159. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  160. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  161. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  162. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  163. };
  164. /*
  165. * The four programmable clocks.
  166. * You must configure pin multiplexing to bring these signals out.
  167. */
  168. static struct clk pck0 = {
  169. .name = "pck0",
  170. .pmc_mask = AT91_PMC_PCK0,
  171. .type = CLK_TYPE_PROGRAMMABLE,
  172. .id = 0,
  173. };
  174. static struct clk pck1 = {
  175. .name = "pck1",
  176. .pmc_mask = AT91_PMC_PCK1,
  177. .type = CLK_TYPE_PROGRAMMABLE,
  178. .id = 1,
  179. };
  180. static struct clk pck2 = {
  181. .name = "pck2",
  182. .pmc_mask = AT91_PMC_PCK2,
  183. .type = CLK_TYPE_PROGRAMMABLE,
  184. .id = 2,
  185. };
  186. static struct clk pck3 = {
  187. .name = "pck3",
  188. .pmc_mask = AT91_PMC_PCK3,
  189. .type = CLK_TYPE_PROGRAMMABLE,
  190. .id = 3,
  191. };
  192. /* HClocks */
  193. static struct clk hck0 = {
  194. .name = "hck0",
  195. .pmc_mask = AT91_PMC_HCK0,
  196. .type = CLK_TYPE_SYSTEM,
  197. .id = 0,
  198. };
  199. static struct clk hck1 = {
  200. .name = "hck1",
  201. .pmc_mask = AT91_PMC_HCK1,
  202. .type = CLK_TYPE_SYSTEM,
  203. .id = 1,
  204. };
  205. static void __init at91sam9261_register_clocks(void)
  206. {
  207. int i;
  208. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  209. clk_register(periph_clocks[i]);
  210. clkdev_add_table(periph_clocks_lookups,
  211. ARRAY_SIZE(periph_clocks_lookups));
  212. clkdev_add_table(usart_clocks_lookups,
  213. ARRAY_SIZE(usart_clocks_lookups));
  214. clk_register(&pck0);
  215. clk_register(&pck1);
  216. clk_register(&pck2);
  217. clk_register(&pck3);
  218. clk_register(&hck0);
  219. clk_register(&hck1);
  220. }
  221. static struct clk_lookup console_clock_lookup;
  222. void __init at91sam9261_set_console_clock(int id)
  223. {
  224. if (id >= ARRAY_SIZE(usart_clocks_lookups))
  225. return;
  226. console_clock_lookup.con_id = "usart";
  227. console_clock_lookup.clk = usart_clocks_lookups[id].clk;
  228. clkdev_add(&console_clock_lookup);
  229. }
  230. /* --------------------------------------------------------------------
  231. * GPIO
  232. * -------------------------------------------------------------------- */
  233. static struct at91_gpio_bank at91sam9261_gpio[] = {
  234. {
  235. .id = AT91SAM9261_ID_PIOA,
  236. .offset = AT91_PIOA,
  237. .clock = &pioA_clk,
  238. }, {
  239. .id = AT91SAM9261_ID_PIOB,
  240. .offset = AT91_PIOB,
  241. .clock = &pioB_clk,
  242. }, {
  243. .id = AT91SAM9261_ID_PIOC,
  244. .offset = AT91_PIOC,
  245. .clock = &pioC_clk,
  246. }
  247. };
  248. static void at91sam9261_poweroff(void)
  249. {
  250. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  251. }
  252. /* --------------------------------------------------------------------
  253. * AT91SAM9261 processor initialization
  254. * -------------------------------------------------------------------- */
  255. static void __init at91sam9261_map_io(void)
  256. {
  257. if (cpu_is_at91sam9g10())
  258. at91_init_sram(0, AT91SAM9G10_SRAM_BASE, AT91SAM9G10_SRAM_SIZE);
  259. else
  260. at91_init_sram(0, AT91SAM9261_SRAM_BASE, AT91SAM9261_SRAM_SIZE);
  261. }
  262. static void __init at91sam9261_initialize(void)
  263. {
  264. at91_arch_reset = at91sam9_alt_reset;
  265. pm_power_off = at91sam9261_poweroff;
  266. at91_extern_irq = (1 << AT91SAM9261_ID_IRQ0) | (1 << AT91SAM9261_ID_IRQ1)
  267. | (1 << AT91SAM9261_ID_IRQ2);
  268. /* Register GPIO subsystem */
  269. at91_gpio_init(at91sam9261_gpio, 3);
  270. }
  271. /* --------------------------------------------------------------------
  272. * Interrupt initialization
  273. * -------------------------------------------------------------------- */
  274. /*
  275. * The default interrupt priority levels (0 = lowest, 7 = highest).
  276. */
  277. static unsigned int at91sam9261_default_irq_priority[NR_AIC_IRQS] __initdata = {
  278. 7, /* Advanced Interrupt Controller */
  279. 7, /* System Peripherals */
  280. 1, /* Parallel IO Controller A */
  281. 1, /* Parallel IO Controller B */
  282. 1, /* Parallel IO Controller C */
  283. 0,
  284. 5, /* USART 0 */
  285. 5, /* USART 1 */
  286. 5, /* USART 2 */
  287. 0, /* Multimedia Card Interface */
  288. 2, /* USB Device Port */
  289. 6, /* Two-Wire Interface */
  290. 5, /* Serial Peripheral Interface 0 */
  291. 5, /* Serial Peripheral Interface 1 */
  292. 4, /* Serial Synchronous Controller 0 */
  293. 4, /* Serial Synchronous Controller 1 */
  294. 4, /* Serial Synchronous Controller 2 */
  295. 0, /* Timer Counter 0 */
  296. 0, /* Timer Counter 1 */
  297. 0, /* Timer Counter 2 */
  298. 2, /* USB Host port */
  299. 3, /* LCD Controller */
  300. 0,
  301. 0,
  302. 0,
  303. 0,
  304. 0,
  305. 0,
  306. 0,
  307. 0, /* Advanced Interrupt Controller */
  308. 0, /* Advanced Interrupt Controller */
  309. 0, /* Advanced Interrupt Controller */
  310. };
  311. struct at91_init_soc __initdata at91sam9261_soc = {
  312. .map_io = at91sam9261_map_io,
  313. .default_irq_priority = at91sam9261_default_irq_priority,
  314. .register_clocks = at91sam9261_register_clocks,
  315. .init = at91sam9261_initialize,
  316. };