at91sam9260.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. /*
  224. * The two programmable clocks.
  225. * You must configure pin multiplexing to bring these signals out.
  226. */
  227. static struct clk pck0 = {
  228. .name = "pck0",
  229. .pmc_mask = AT91_PMC_PCK0,
  230. .type = CLK_TYPE_PROGRAMMABLE,
  231. .id = 0,
  232. };
  233. static struct clk pck1 = {
  234. .name = "pck1",
  235. .pmc_mask = AT91_PMC_PCK1,
  236. .type = CLK_TYPE_PROGRAMMABLE,
  237. .id = 1,
  238. };
  239. static void __init at91sam9260_register_clocks(void)
  240. {
  241. int i;
  242. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  243. clk_register(periph_clocks[i]);
  244. clk_register(&pck0);
  245. clk_register(&pck1);
  246. }
  247. /* --------------------------------------------------------------------
  248. * GPIO
  249. * -------------------------------------------------------------------- */
  250. static struct at91_gpio_bank at91sam9260_gpio[] = {
  251. {
  252. .id = AT91SAM9260_ID_PIOA,
  253. .offset = AT91_PIOA,
  254. .clock = &pioA_clk,
  255. }, {
  256. .id = AT91SAM9260_ID_PIOB,
  257. .offset = AT91_PIOB,
  258. .clock = &pioB_clk,
  259. }, {
  260. .id = AT91SAM9260_ID_PIOC,
  261. .offset = AT91_PIOC,
  262. .clock = &pioC_clk,
  263. }
  264. };
  265. static void at91sam9260_reset(void)
  266. {
  267. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  268. }
  269. static void at91sam9260_poweroff(void)
  270. {
  271. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  272. }
  273. /* --------------------------------------------------------------------
  274. * AT91SAM9260 processor initialization
  275. * -------------------------------------------------------------------- */
  276. static void __init at91sam9xe_initialize(void)
  277. {
  278. unsigned long cidr, sram_size;
  279. cidr = at91_sys_read(AT91_DBGU_CIDR);
  280. switch (cidr & AT91_CIDR_SRAMSIZ) {
  281. case AT91_CIDR_SRAMSIZ_32K:
  282. sram_size = 2 * SZ_16K;
  283. break;
  284. case AT91_CIDR_SRAMSIZ_16K:
  285. default:
  286. sram_size = SZ_16K;
  287. }
  288. at91sam9xe_sram_desc->virtual = AT91_IO_VIRT_BASE - sram_size;
  289. at91sam9xe_sram_desc->length = sram_size;
  290. iotable_init(at91sam9xe_sram_desc, ARRAY_SIZE(at91sam9xe_sram_desc));
  291. }
  292. void __init at91sam9260_initialize(unsigned long main_clock)
  293. {
  294. /* Map peripherals */
  295. iotable_init(at91sam9260_io_desc, ARRAY_SIZE(at91sam9260_io_desc));
  296. if (cpu_is_at91sam9xe())
  297. at91sam9xe_initialize();
  298. else if (cpu_is_at91sam9g20())
  299. iotable_init(at91sam9g20_sram_desc, ARRAY_SIZE(at91sam9g20_sram_desc));
  300. else
  301. iotable_init(at91sam9260_sram_desc, ARRAY_SIZE(at91sam9260_sram_desc));
  302. at91_arch_reset = at91sam9260_reset;
  303. pm_power_off = at91sam9260_poweroff;
  304. at91_extern_irq = (1 << AT91SAM9260_ID_IRQ0) | (1 << AT91SAM9260_ID_IRQ1)
  305. | (1 << AT91SAM9260_ID_IRQ2);
  306. /* Init clock subsystem */
  307. at91_clock_init(main_clock);
  308. /* Register the processor-specific clocks */
  309. at91sam9260_register_clocks();
  310. /* Register GPIO subsystem */
  311. at91_gpio_init(at91sam9260_gpio, 3);
  312. }
  313. /* --------------------------------------------------------------------
  314. * Interrupt initialization
  315. * -------------------------------------------------------------------- */
  316. /*
  317. * The default interrupt priority levels (0 = lowest, 7 = highest).
  318. */
  319. static unsigned int at91sam9260_default_irq_priority[NR_AIC_IRQS] __initdata = {
  320. 7, /* Advanced Interrupt Controller */
  321. 7, /* System Peripherals */
  322. 1, /* Parallel IO Controller A */
  323. 1, /* Parallel IO Controller B */
  324. 1, /* Parallel IO Controller C */
  325. 0, /* Analog-to-Digital Converter */
  326. 5, /* USART 0 */
  327. 5, /* USART 1 */
  328. 5, /* USART 2 */
  329. 0, /* Multimedia Card Interface */
  330. 2, /* USB Device Port */
  331. 6, /* Two-Wire Interface */
  332. 5, /* Serial Peripheral Interface 0 */
  333. 5, /* Serial Peripheral Interface 1 */
  334. 5, /* Serial Synchronous Controller */
  335. 0,
  336. 0,
  337. 0, /* Timer Counter 0 */
  338. 0, /* Timer Counter 1 */
  339. 0, /* Timer Counter 2 */
  340. 2, /* USB Host port */
  341. 3, /* Ethernet */
  342. 0, /* Image Sensor Interface */
  343. 5, /* USART 3 */
  344. 5, /* USART 4 */
  345. 5, /* USART 5 */
  346. 0, /* Timer Counter 3 */
  347. 0, /* Timer Counter 4 */
  348. 0, /* Timer Counter 5 */
  349. 0, /* Advanced Interrupt Controller */
  350. 0, /* Advanced Interrupt Controller */
  351. 0, /* Advanced Interrupt Controller */
  352. };
  353. void __init at91sam9260_init_interrupts(unsigned int priority[NR_AIC_IRQS])
  354. {
  355. if (!priority)
  356. priority = at91sam9260_default_irq_priority;
  357. /* Initialize the AIC interrupt controller */
  358. at91_aic_init(priority);
  359. /* Enable GPIO interrupts */
  360. at91_gpio_irq_setup();
  361. }