at91sam9260.c 11 KB

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