at91sam9260.c 9.5 KB

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