at91sam9261.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. /* 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. };
  172. static struct clk_lookup usart_clocks_lookups[] = {
  173. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  174. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  175. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  176. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  177. };
  178. /*
  179. * The four programmable clocks.
  180. * You must configure pin multiplexing to bring these signals out.
  181. */
  182. static struct clk pck0 = {
  183. .name = "pck0",
  184. .pmc_mask = AT91_PMC_PCK0,
  185. .type = CLK_TYPE_PROGRAMMABLE,
  186. .id = 0,
  187. };
  188. static struct clk pck1 = {
  189. .name = "pck1",
  190. .pmc_mask = AT91_PMC_PCK1,
  191. .type = CLK_TYPE_PROGRAMMABLE,
  192. .id = 1,
  193. };
  194. static struct clk pck2 = {
  195. .name = "pck2",
  196. .pmc_mask = AT91_PMC_PCK2,
  197. .type = CLK_TYPE_PROGRAMMABLE,
  198. .id = 2,
  199. };
  200. static struct clk pck3 = {
  201. .name = "pck3",
  202. .pmc_mask = AT91_PMC_PCK3,
  203. .type = CLK_TYPE_PROGRAMMABLE,
  204. .id = 3,
  205. };
  206. static void __init at91sam9261_register_clocks(void)
  207. {
  208. int i;
  209. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  210. clk_register(periph_clocks[i]);
  211. clkdev_add_table(periph_clocks_lookups,
  212. ARRAY_SIZE(periph_clocks_lookups));
  213. clkdev_add_table(usart_clocks_lookups,
  214. ARRAY_SIZE(usart_clocks_lookups));
  215. clk_register(&pck0);
  216. clk_register(&pck1);
  217. clk_register(&pck2);
  218. clk_register(&pck3);
  219. clk_register(&hck0);
  220. clk_register(&hck1);
  221. }
  222. static struct clk_lookup console_clock_lookup;
  223. void __init at91sam9261_set_console_clock(int id)
  224. {
  225. if (id >= ARRAY_SIZE(usart_clocks_lookups))
  226. return;
  227. console_clock_lookup.con_id = "usart";
  228. console_clock_lookup.clk = usart_clocks_lookups[id].clk;
  229. clkdev_add(&console_clock_lookup);
  230. }
  231. /* --------------------------------------------------------------------
  232. * GPIO
  233. * -------------------------------------------------------------------- */
  234. static struct at91_gpio_bank at91sam9261_gpio[] = {
  235. {
  236. .id = AT91SAM9261_ID_PIOA,
  237. .offset = AT91_PIOA,
  238. .clock = &pioA_clk,
  239. }, {
  240. .id = AT91SAM9261_ID_PIOB,
  241. .offset = AT91_PIOB,
  242. .clock = &pioB_clk,
  243. }, {
  244. .id = AT91SAM9261_ID_PIOC,
  245. .offset = AT91_PIOC,
  246. .clock = &pioC_clk,
  247. }
  248. };
  249. static void at91sam9261_poweroff(void)
  250. {
  251. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  252. }
  253. /* --------------------------------------------------------------------
  254. * AT91SAM9261 processor initialization
  255. * -------------------------------------------------------------------- */
  256. static void __init at91sam9261_map_io(void)
  257. {
  258. if (cpu_is_at91sam9g10())
  259. at91_init_sram(0, AT91SAM9G10_SRAM_BASE, AT91SAM9G10_SRAM_SIZE);
  260. else
  261. at91_init_sram(0, AT91SAM9261_SRAM_BASE, AT91SAM9261_SRAM_SIZE);
  262. }
  263. static void __init at91sam9261_initialize(void)
  264. {
  265. arm_pm_restart = at91sam9_alt_restart;
  266. pm_power_off = at91sam9261_poweroff;
  267. at91_extern_irq = (1 << AT91SAM9261_ID_IRQ0) | (1 << AT91SAM9261_ID_IRQ1)
  268. | (1 << AT91SAM9261_ID_IRQ2);
  269. /* Register GPIO subsystem */
  270. at91_gpio_init(at91sam9261_gpio, 3);
  271. }
  272. /* --------------------------------------------------------------------
  273. * Interrupt initialization
  274. * -------------------------------------------------------------------- */
  275. /*
  276. * The default interrupt priority levels (0 = lowest, 7 = highest).
  277. */
  278. static unsigned int at91sam9261_default_irq_priority[NR_AIC_IRQS] __initdata = {
  279. 7, /* Advanced Interrupt Controller */
  280. 7, /* System Peripherals */
  281. 1, /* Parallel IO Controller A */
  282. 1, /* Parallel IO Controller B */
  283. 1, /* Parallel IO Controller C */
  284. 0,
  285. 5, /* USART 0 */
  286. 5, /* USART 1 */
  287. 5, /* USART 2 */
  288. 0, /* Multimedia Card Interface */
  289. 2, /* USB Device Port */
  290. 6, /* Two-Wire Interface */
  291. 5, /* Serial Peripheral Interface 0 */
  292. 5, /* Serial Peripheral Interface 1 */
  293. 4, /* Serial Synchronous Controller 0 */
  294. 4, /* Serial Synchronous Controller 1 */
  295. 4, /* Serial Synchronous Controller 2 */
  296. 0, /* Timer Counter 0 */
  297. 0, /* Timer Counter 1 */
  298. 0, /* Timer Counter 2 */
  299. 2, /* USB Host port */
  300. 3, /* LCD Controller */
  301. 0,
  302. 0,
  303. 0,
  304. 0,
  305. 0,
  306. 0,
  307. 0,
  308. 0, /* Advanced Interrupt Controller */
  309. 0, /* Advanced Interrupt Controller */
  310. 0, /* Advanced Interrupt Controller */
  311. };
  312. struct at91_init_soc __initdata at91sam9261_soc = {
  313. .map_io = at91sam9261_map_io,
  314. .default_irq_priority = at91sam9261_default_irq_priority,
  315. .register_clocks = at91sam9261_register_clocks,
  316. .init = at91sam9261_initialize,
  317. };