at91sam9260.c 8.8 KB

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