at91sam9260.c 9.6 KB

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