at91sam9260.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /*
  2. * arch/arm/mach-at91/at91sam9260.c
  3. *
  4. * Copyright (C) 2006 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/at91_dbgu.h>
  19. #include <mach/at91sam9260.h>
  20. #include <mach/at91_pmc.h>
  21. #include <mach/at91_rstc.h>
  22. #include <mach/at91_shdwc.h>
  23. #include "soc.h"
  24. #include "generic.h"
  25. #include "clock.h"
  26. static struct map_desc at91sam9260_sram_desc[] __initdata = {
  27. {
  28. .virtual = AT91_IO_VIRT_BASE - AT91SAM9260_SRAM0_SIZE,
  29. .pfn = __phys_to_pfn(AT91SAM9260_SRAM0_BASE),
  30. .length = AT91SAM9260_SRAM0_SIZE,
  31. .type = MT_DEVICE,
  32. }, {
  33. .virtual = AT91_IO_VIRT_BASE - AT91SAM9260_SRAM0_SIZE - AT91SAM9260_SRAM1_SIZE,
  34. .pfn = __phys_to_pfn(AT91SAM9260_SRAM1_BASE),
  35. .length = AT91SAM9260_SRAM1_SIZE,
  36. .type = MT_DEVICE,
  37. }
  38. };
  39. static struct map_desc at91sam9g20_sram_desc[] __initdata = {
  40. {
  41. .virtual = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE,
  42. .pfn = __phys_to_pfn(AT91SAM9G20_SRAM0_BASE),
  43. .length = AT91SAM9G20_SRAM0_SIZE,
  44. .type = MT_DEVICE,
  45. }, {
  46. .virtual = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE - AT91SAM9G20_SRAM1_SIZE,
  47. .pfn = __phys_to_pfn(AT91SAM9G20_SRAM1_BASE),
  48. .length = AT91SAM9G20_SRAM1_SIZE,
  49. .type = MT_DEVICE,
  50. }
  51. };
  52. static struct map_desc at91sam9xe_sram_desc[] __initdata = {
  53. {
  54. .pfn = __phys_to_pfn(AT91SAM9XE_SRAM_BASE),
  55. .type = MT_DEVICE,
  56. }
  57. };
  58. /* --------------------------------------------------------------------
  59. * Clocks
  60. * -------------------------------------------------------------------- */
  61. /*
  62. * The peripheral clocks.
  63. */
  64. static struct clk pioA_clk = {
  65. .name = "pioA_clk",
  66. .pmc_mask = 1 << AT91SAM9260_ID_PIOA,
  67. .type = CLK_TYPE_PERIPHERAL,
  68. };
  69. static struct clk pioB_clk = {
  70. .name = "pioB_clk",
  71. .pmc_mask = 1 << AT91SAM9260_ID_PIOB,
  72. .type = CLK_TYPE_PERIPHERAL,
  73. };
  74. static struct clk pioC_clk = {
  75. .name = "pioC_clk",
  76. .pmc_mask = 1 << AT91SAM9260_ID_PIOC,
  77. .type = CLK_TYPE_PERIPHERAL,
  78. };
  79. static struct clk adc_clk = {
  80. .name = "adc_clk",
  81. .pmc_mask = 1 << AT91SAM9260_ID_ADC,
  82. .type = CLK_TYPE_PERIPHERAL,
  83. };
  84. static struct clk usart0_clk = {
  85. .name = "usart0_clk",
  86. .pmc_mask = 1 << AT91SAM9260_ID_US0,
  87. .type = CLK_TYPE_PERIPHERAL,
  88. };
  89. static struct clk usart1_clk = {
  90. .name = "usart1_clk",
  91. .pmc_mask = 1 << AT91SAM9260_ID_US1,
  92. .type = CLK_TYPE_PERIPHERAL,
  93. };
  94. static struct clk usart2_clk = {
  95. .name = "usart2_clk",
  96. .pmc_mask = 1 << AT91SAM9260_ID_US2,
  97. .type = CLK_TYPE_PERIPHERAL,
  98. };
  99. static struct clk mmc_clk = {
  100. .name = "mci_clk",
  101. .pmc_mask = 1 << AT91SAM9260_ID_MCI,
  102. .type = CLK_TYPE_PERIPHERAL,
  103. };
  104. static struct clk udc_clk = {
  105. .name = "udc_clk",
  106. .pmc_mask = 1 << AT91SAM9260_ID_UDP,
  107. .type = CLK_TYPE_PERIPHERAL,
  108. };
  109. static struct clk twi_clk = {
  110. .name = "twi_clk",
  111. .pmc_mask = 1 << AT91SAM9260_ID_TWI,
  112. .type = CLK_TYPE_PERIPHERAL,
  113. };
  114. static struct clk spi0_clk = {
  115. .name = "spi0_clk",
  116. .pmc_mask = 1 << AT91SAM9260_ID_SPI0,
  117. .type = CLK_TYPE_PERIPHERAL,
  118. };
  119. static struct clk spi1_clk = {
  120. .name = "spi1_clk",
  121. .pmc_mask = 1 << AT91SAM9260_ID_SPI1,
  122. .type = CLK_TYPE_PERIPHERAL,
  123. };
  124. static struct clk ssc_clk = {
  125. .name = "ssc_clk",
  126. .pmc_mask = 1 << AT91SAM9260_ID_SSC,
  127. .type = CLK_TYPE_PERIPHERAL,
  128. };
  129. static struct clk tc0_clk = {
  130. .name = "tc0_clk",
  131. .pmc_mask = 1 << AT91SAM9260_ID_TC0,
  132. .type = CLK_TYPE_PERIPHERAL,
  133. };
  134. static struct clk tc1_clk = {
  135. .name = "tc1_clk",
  136. .pmc_mask = 1 << AT91SAM9260_ID_TC1,
  137. .type = CLK_TYPE_PERIPHERAL,
  138. };
  139. static struct clk tc2_clk = {
  140. .name = "tc2_clk",
  141. .pmc_mask = 1 << AT91SAM9260_ID_TC2,
  142. .type = CLK_TYPE_PERIPHERAL,
  143. };
  144. static struct clk ohci_clk = {
  145. .name = "ohci_clk",
  146. .pmc_mask = 1 << AT91SAM9260_ID_UHP,
  147. .type = CLK_TYPE_PERIPHERAL,
  148. };
  149. static struct clk macb_clk = {
  150. .name = "macb_clk",
  151. .pmc_mask = 1 << AT91SAM9260_ID_EMAC,
  152. .type = CLK_TYPE_PERIPHERAL,
  153. };
  154. static struct clk isi_clk = {
  155. .name = "isi_clk",
  156. .pmc_mask = 1 << AT91SAM9260_ID_ISI,
  157. .type = CLK_TYPE_PERIPHERAL,
  158. };
  159. static struct clk usart3_clk = {
  160. .name = "usart3_clk",
  161. .pmc_mask = 1 << AT91SAM9260_ID_US3,
  162. .type = CLK_TYPE_PERIPHERAL,
  163. };
  164. static struct clk usart4_clk = {
  165. .name = "usart4_clk",
  166. .pmc_mask = 1 << AT91SAM9260_ID_US4,
  167. .type = CLK_TYPE_PERIPHERAL,
  168. };
  169. static struct clk usart5_clk = {
  170. .name = "usart5_clk",
  171. .pmc_mask = 1 << AT91SAM9260_ID_US5,
  172. .type = CLK_TYPE_PERIPHERAL,
  173. };
  174. static struct clk tc3_clk = {
  175. .name = "tc3_clk",
  176. .pmc_mask = 1 << AT91SAM9260_ID_TC3,
  177. .type = CLK_TYPE_PERIPHERAL,
  178. };
  179. static struct clk tc4_clk = {
  180. .name = "tc4_clk",
  181. .pmc_mask = 1 << AT91SAM9260_ID_TC4,
  182. .type = CLK_TYPE_PERIPHERAL,
  183. };
  184. static struct clk tc5_clk = {
  185. .name = "tc5_clk",
  186. .pmc_mask = 1 << AT91SAM9260_ID_TC5,
  187. .type = CLK_TYPE_PERIPHERAL,
  188. };
  189. static struct clk *periph_clocks[] __initdata = {
  190. &pioA_clk,
  191. &pioB_clk,
  192. &pioC_clk,
  193. &adc_clk,
  194. &usart0_clk,
  195. &usart1_clk,
  196. &usart2_clk,
  197. &mmc_clk,
  198. &udc_clk,
  199. &twi_clk,
  200. &spi0_clk,
  201. &spi1_clk,
  202. &ssc_clk,
  203. &tc0_clk,
  204. &tc1_clk,
  205. &tc2_clk,
  206. &ohci_clk,
  207. &macb_clk,
  208. &isi_clk,
  209. &usart3_clk,
  210. &usart4_clk,
  211. &usart5_clk,
  212. &tc3_clk,
  213. &tc4_clk,
  214. &tc5_clk,
  215. // irq0 .. irq2
  216. };
  217. static struct clk_lookup periph_clocks_lookups[] = {
  218. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
  219. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
  220. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
  221. CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
  222. CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
  223. CLKDEV_CON_DEV_ID("t3_clk", "atmel_tcb.1", &tc3_clk),
  224. CLKDEV_CON_DEV_ID("t4_clk", "atmel_tcb.1", &tc4_clk),
  225. CLKDEV_CON_DEV_ID("t5_clk", "atmel_tcb.1", &tc5_clk),
  226. CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc_clk),
  227. };
  228. static struct clk_lookup usart_clocks_lookups[] = {
  229. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  230. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  231. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  232. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  233. CLKDEV_CON_DEV_ID("usart", "atmel_usart.4", &usart3_clk),
  234. CLKDEV_CON_DEV_ID("usart", "atmel_usart.5", &usart4_clk),
  235. CLKDEV_CON_DEV_ID("usart", "atmel_usart.6", &usart5_clk),
  236. };
  237. /*
  238. * The two programmable clocks.
  239. * You must configure pin multiplexing to bring these signals out.
  240. */
  241. static struct clk pck0 = {
  242. .name = "pck0",
  243. .pmc_mask = AT91_PMC_PCK0,
  244. .type = CLK_TYPE_PROGRAMMABLE,
  245. .id = 0,
  246. };
  247. static struct clk pck1 = {
  248. .name = "pck1",
  249. .pmc_mask = AT91_PMC_PCK1,
  250. .type = CLK_TYPE_PROGRAMMABLE,
  251. .id = 1,
  252. };
  253. static void __init at91sam9260_register_clocks(void)
  254. {
  255. int i;
  256. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  257. clk_register(periph_clocks[i]);
  258. clkdev_add_table(periph_clocks_lookups,
  259. ARRAY_SIZE(periph_clocks_lookups));
  260. clkdev_add_table(usart_clocks_lookups,
  261. ARRAY_SIZE(usart_clocks_lookups));
  262. clk_register(&pck0);
  263. clk_register(&pck1);
  264. }
  265. static struct clk_lookup console_clock_lookup;
  266. void __init at91sam9260_set_console_clock(int id)
  267. {
  268. if (id >= ARRAY_SIZE(usart_clocks_lookups))
  269. return;
  270. console_clock_lookup.con_id = "usart";
  271. console_clock_lookup.clk = usart_clocks_lookups[id].clk;
  272. clkdev_add(&console_clock_lookup);
  273. }
  274. /* --------------------------------------------------------------------
  275. * GPIO
  276. * -------------------------------------------------------------------- */
  277. static struct at91_gpio_bank at91sam9260_gpio[] = {
  278. {
  279. .id = AT91SAM9260_ID_PIOA,
  280. .offset = AT91_PIOA,
  281. .clock = &pioA_clk,
  282. }, {
  283. .id = AT91SAM9260_ID_PIOB,
  284. .offset = AT91_PIOB,
  285. .clock = &pioB_clk,
  286. }, {
  287. .id = AT91SAM9260_ID_PIOC,
  288. .offset = AT91_PIOC,
  289. .clock = &pioC_clk,
  290. }
  291. };
  292. static void at91sam9260_poweroff(void)
  293. {
  294. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  295. }
  296. /* --------------------------------------------------------------------
  297. * AT91SAM9260 processor initialization
  298. * -------------------------------------------------------------------- */
  299. static void __init at91sam9xe_map_io(void)
  300. {
  301. unsigned long sram_size;
  302. switch (at91_soc_initdata.cidr & AT91_CIDR_SRAMSIZ) {
  303. case AT91_CIDR_SRAMSIZ_32K:
  304. sram_size = 2 * SZ_16K;
  305. break;
  306. case AT91_CIDR_SRAMSIZ_16K:
  307. default:
  308. sram_size = SZ_16K;
  309. }
  310. at91sam9xe_sram_desc->virtual = AT91_IO_VIRT_BASE - sram_size;
  311. at91sam9xe_sram_desc->length = sram_size;
  312. iotable_init(at91sam9xe_sram_desc, ARRAY_SIZE(at91sam9xe_sram_desc));
  313. }
  314. static void __init at91sam9260_map_io(void)
  315. {
  316. if (cpu_is_at91sam9xe())
  317. at91sam9xe_map_io();
  318. else if (cpu_is_at91sam9g20())
  319. iotable_init(at91sam9g20_sram_desc, ARRAY_SIZE(at91sam9g20_sram_desc));
  320. else
  321. iotable_init(at91sam9260_sram_desc, ARRAY_SIZE(at91sam9260_sram_desc));
  322. }
  323. static void __init at91sam9260_initialize(unsigned long main_clock)
  324. {
  325. at91_arch_reset = at91sam9_alt_reset;
  326. pm_power_off = at91sam9260_poweroff;
  327. at91_extern_irq = (1 << AT91SAM9260_ID_IRQ0) | (1 << AT91SAM9260_ID_IRQ1)
  328. | (1 << AT91SAM9260_ID_IRQ2);
  329. /* Init clock subsystem */
  330. at91_clock_init(main_clock);
  331. /* Register the processor-specific clocks */
  332. at91sam9260_register_clocks();
  333. /* Register GPIO subsystem */
  334. at91_gpio_init(at91sam9260_gpio, 3);
  335. }
  336. /* --------------------------------------------------------------------
  337. * Interrupt initialization
  338. * -------------------------------------------------------------------- */
  339. /*
  340. * The default interrupt priority levels (0 = lowest, 7 = highest).
  341. */
  342. static unsigned int at91sam9260_default_irq_priority[NR_AIC_IRQS] __initdata = {
  343. 7, /* Advanced Interrupt Controller */
  344. 7, /* System Peripherals */
  345. 1, /* Parallel IO Controller A */
  346. 1, /* Parallel IO Controller B */
  347. 1, /* Parallel IO Controller C */
  348. 0, /* Analog-to-Digital Converter */
  349. 5, /* USART 0 */
  350. 5, /* USART 1 */
  351. 5, /* USART 2 */
  352. 0, /* Multimedia Card Interface */
  353. 2, /* USB Device Port */
  354. 6, /* Two-Wire Interface */
  355. 5, /* Serial Peripheral Interface 0 */
  356. 5, /* Serial Peripheral Interface 1 */
  357. 5, /* Serial Synchronous Controller */
  358. 0,
  359. 0,
  360. 0, /* Timer Counter 0 */
  361. 0, /* Timer Counter 1 */
  362. 0, /* Timer Counter 2 */
  363. 2, /* USB Host port */
  364. 3, /* Ethernet */
  365. 0, /* Image Sensor Interface */
  366. 5, /* USART 3 */
  367. 5, /* USART 4 */
  368. 5, /* USART 5 */
  369. 0, /* Timer Counter 3 */
  370. 0, /* Timer Counter 4 */
  371. 0, /* Timer Counter 5 */
  372. 0, /* Advanced Interrupt Controller */
  373. 0, /* Advanced Interrupt Controller */
  374. 0, /* Advanced Interrupt Controller */
  375. };
  376. struct at91_init_soc __initdata at91sam9260_soc = {
  377. .map_io = at91sam9260_map_io,
  378. .default_irq_priority = at91sam9260_default_irq_priority,
  379. .init = at91sam9260_initialize,
  380. };