at91sam9260.c 9.0 KB

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