at91cap9.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /*
  2. * arch/arm/mach-at91/at91cap9.c
  3. *
  4. * Copyright (C) 2007 Stelian Pop <stelian.pop@leadtechdesign.com>
  5. * Copyright (C) 2007 Lead Tech Design <www.leadtechdesign.com>
  6. * Copyright (C) 2007 Atmel Corporation.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/pm.h>
  16. #include <asm/irq.h>
  17. #include <asm/mach/arch.h>
  18. #include <asm/mach/map.h>
  19. #include <mach/cpu.h>
  20. #include <mach/at91cap9.h>
  21. #include <mach/at91_pmc.h>
  22. #include <mach/at91_rstc.h>
  23. #include <mach/at91_shdwc.h>
  24. #include "soc.h"
  25. #include "generic.h"
  26. #include "clock.h"
  27. #include "sam9_smc.h"
  28. /* --------------------------------------------------------------------
  29. * Clocks
  30. * -------------------------------------------------------------------- */
  31. /*
  32. * The peripheral clocks.
  33. */
  34. static struct clk pioABCD_clk = {
  35. .name = "pioABCD_clk",
  36. .pmc_mask = 1 << AT91CAP9_ID_PIOABCD,
  37. .type = CLK_TYPE_PERIPHERAL,
  38. };
  39. static struct clk mpb0_clk = {
  40. .name = "mpb0_clk",
  41. .pmc_mask = 1 << AT91CAP9_ID_MPB0,
  42. .type = CLK_TYPE_PERIPHERAL,
  43. };
  44. static struct clk mpb1_clk = {
  45. .name = "mpb1_clk",
  46. .pmc_mask = 1 << AT91CAP9_ID_MPB1,
  47. .type = CLK_TYPE_PERIPHERAL,
  48. };
  49. static struct clk mpb2_clk = {
  50. .name = "mpb2_clk",
  51. .pmc_mask = 1 << AT91CAP9_ID_MPB2,
  52. .type = CLK_TYPE_PERIPHERAL,
  53. };
  54. static struct clk mpb3_clk = {
  55. .name = "mpb3_clk",
  56. .pmc_mask = 1 << AT91CAP9_ID_MPB3,
  57. .type = CLK_TYPE_PERIPHERAL,
  58. };
  59. static struct clk mpb4_clk = {
  60. .name = "mpb4_clk",
  61. .pmc_mask = 1 << AT91CAP9_ID_MPB4,
  62. .type = CLK_TYPE_PERIPHERAL,
  63. };
  64. static struct clk usart0_clk = {
  65. .name = "usart0_clk",
  66. .pmc_mask = 1 << AT91CAP9_ID_US0,
  67. .type = CLK_TYPE_PERIPHERAL,
  68. };
  69. static struct clk usart1_clk = {
  70. .name = "usart1_clk",
  71. .pmc_mask = 1 << AT91CAP9_ID_US1,
  72. .type = CLK_TYPE_PERIPHERAL,
  73. };
  74. static struct clk usart2_clk = {
  75. .name = "usart2_clk",
  76. .pmc_mask = 1 << AT91CAP9_ID_US2,
  77. .type = CLK_TYPE_PERIPHERAL,
  78. };
  79. static struct clk mmc0_clk = {
  80. .name = "mci0_clk",
  81. .pmc_mask = 1 << AT91CAP9_ID_MCI0,
  82. .type = CLK_TYPE_PERIPHERAL,
  83. };
  84. static struct clk mmc1_clk = {
  85. .name = "mci1_clk",
  86. .pmc_mask = 1 << AT91CAP9_ID_MCI1,
  87. .type = CLK_TYPE_PERIPHERAL,
  88. };
  89. static struct clk can_clk = {
  90. .name = "can_clk",
  91. .pmc_mask = 1 << AT91CAP9_ID_CAN,
  92. .type = CLK_TYPE_PERIPHERAL,
  93. };
  94. static struct clk twi_clk = {
  95. .name = "twi_clk",
  96. .pmc_mask = 1 << AT91CAP9_ID_TWI,
  97. .type = CLK_TYPE_PERIPHERAL,
  98. };
  99. static struct clk spi0_clk = {
  100. .name = "spi0_clk",
  101. .pmc_mask = 1 << AT91CAP9_ID_SPI0,
  102. .type = CLK_TYPE_PERIPHERAL,
  103. };
  104. static struct clk spi1_clk = {
  105. .name = "spi1_clk",
  106. .pmc_mask = 1 << AT91CAP9_ID_SPI1,
  107. .type = CLK_TYPE_PERIPHERAL,
  108. };
  109. static struct clk ssc0_clk = {
  110. .name = "ssc0_clk",
  111. .pmc_mask = 1 << AT91CAP9_ID_SSC0,
  112. .type = CLK_TYPE_PERIPHERAL,
  113. };
  114. static struct clk ssc1_clk = {
  115. .name = "ssc1_clk",
  116. .pmc_mask = 1 << AT91CAP9_ID_SSC1,
  117. .type = CLK_TYPE_PERIPHERAL,
  118. };
  119. static struct clk ac97_clk = {
  120. .name = "ac97_clk",
  121. .pmc_mask = 1 << AT91CAP9_ID_AC97C,
  122. .type = CLK_TYPE_PERIPHERAL,
  123. };
  124. static struct clk tcb_clk = {
  125. .name = "tcb_clk",
  126. .pmc_mask = 1 << AT91CAP9_ID_TCB,
  127. .type = CLK_TYPE_PERIPHERAL,
  128. };
  129. static struct clk pwm_clk = {
  130. .name = "pwm_clk",
  131. .pmc_mask = 1 << AT91CAP9_ID_PWMC,
  132. .type = CLK_TYPE_PERIPHERAL,
  133. };
  134. static struct clk macb_clk = {
  135. .name = "macb_clk",
  136. .pmc_mask = 1 << AT91CAP9_ID_EMAC,
  137. .type = CLK_TYPE_PERIPHERAL,
  138. };
  139. static struct clk aestdes_clk = {
  140. .name = "aestdes_clk",
  141. .pmc_mask = 1 << AT91CAP9_ID_AESTDES,
  142. .type = CLK_TYPE_PERIPHERAL,
  143. };
  144. static struct clk adc_clk = {
  145. .name = "adc_clk",
  146. .pmc_mask = 1 << AT91CAP9_ID_ADC,
  147. .type = CLK_TYPE_PERIPHERAL,
  148. };
  149. static struct clk isi_clk = {
  150. .name = "isi_clk",
  151. .pmc_mask = 1 << AT91CAP9_ID_ISI,
  152. .type = CLK_TYPE_PERIPHERAL,
  153. };
  154. static struct clk lcdc_clk = {
  155. .name = "lcdc_clk",
  156. .pmc_mask = 1 << AT91CAP9_ID_LCDC,
  157. .type = CLK_TYPE_PERIPHERAL,
  158. };
  159. static struct clk dma_clk = {
  160. .name = "dma_clk",
  161. .pmc_mask = 1 << AT91CAP9_ID_DMA,
  162. .type = CLK_TYPE_PERIPHERAL,
  163. };
  164. static struct clk udphs_clk = {
  165. .name = "udphs_clk",
  166. .pmc_mask = 1 << AT91CAP9_ID_UDPHS,
  167. .type = CLK_TYPE_PERIPHERAL,
  168. };
  169. static struct clk ohci_clk = {
  170. .name = "ohci_clk",
  171. .pmc_mask = 1 << AT91CAP9_ID_UHP,
  172. .type = CLK_TYPE_PERIPHERAL,
  173. };
  174. static struct clk *periph_clocks[] __initdata = {
  175. &pioABCD_clk,
  176. &mpb0_clk,
  177. &mpb1_clk,
  178. &mpb2_clk,
  179. &mpb3_clk,
  180. &mpb4_clk,
  181. &usart0_clk,
  182. &usart1_clk,
  183. &usart2_clk,
  184. &mmc0_clk,
  185. &mmc1_clk,
  186. &can_clk,
  187. &twi_clk,
  188. &spi0_clk,
  189. &spi1_clk,
  190. &ssc0_clk,
  191. &ssc1_clk,
  192. &ac97_clk,
  193. &tcb_clk,
  194. &pwm_clk,
  195. &macb_clk,
  196. &aestdes_clk,
  197. &adc_clk,
  198. &isi_clk,
  199. &lcdc_clk,
  200. &dma_clk,
  201. &udphs_clk,
  202. &ohci_clk,
  203. // irq0 .. irq1
  204. };
  205. static struct clk_lookup periph_clocks_lookups[] = {
  206. CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc", &utmi_clk),
  207. CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc", &udphs_clk),
  208. CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.0", &mmc0_clk),
  209. CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.1", &mmc1_clk),
  210. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
  211. CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
  212. CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
  213. CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
  214. CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
  215. /* fake hclk clock */
  216. CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
  217. };
  218. static struct clk_lookup usart_clocks_lookups[] = {
  219. CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
  220. CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
  221. CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
  222. CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
  223. };
  224. /*
  225. * The four 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 struct clk pck2 = {
  241. .name = "pck2",
  242. .pmc_mask = AT91_PMC_PCK2,
  243. .type = CLK_TYPE_PROGRAMMABLE,
  244. .id = 2,
  245. };
  246. static struct clk pck3 = {
  247. .name = "pck3",
  248. .pmc_mask = AT91_PMC_PCK3,
  249. .type = CLK_TYPE_PROGRAMMABLE,
  250. .id = 3,
  251. };
  252. static void __init at91cap9_register_clocks(void)
  253. {
  254. int i;
  255. for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
  256. clk_register(periph_clocks[i]);
  257. clkdev_add_table(periph_clocks_lookups,
  258. ARRAY_SIZE(periph_clocks_lookups));
  259. clkdev_add_table(usart_clocks_lookups,
  260. ARRAY_SIZE(usart_clocks_lookups));
  261. clk_register(&pck0);
  262. clk_register(&pck1);
  263. clk_register(&pck2);
  264. clk_register(&pck3);
  265. }
  266. static struct clk_lookup console_clock_lookup;
  267. void __init at91cap9_set_console_clock(int id)
  268. {
  269. if (id >= ARRAY_SIZE(usart_clocks_lookups))
  270. return;
  271. console_clock_lookup.con_id = "usart";
  272. console_clock_lookup.clk = usart_clocks_lookups[id].clk;
  273. clkdev_add(&console_clock_lookup);
  274. }
  275. /* --------------------------------------------------------------------
  276. * GPIO
  277. * -------------------------------------------------------------------- */
  278. static struct at91_gpio_bank at91cap9_gpio[] = {
  279. {
  280. .id = AT91CAP9_ID_PIOABCD,
  281. .regbase = AT91CAP9_BASE_PIOA,
  282. .clock = &pioABCD_clk,
  283. }, {
  284. .id = AT91CAP9_ID_PIOABCD,
  285. .regbase = AT91CAP9_BASE_PIOB,
  286. .clock = &pioABCD_clk,
  287. }, {
  288. .id = AT91CAP9_ID_PIOABCD,
  289. .regbase = AT91CAP9_BASE_PIOC,
  290. .clock = &pioABCD_clk,
  291. }, {
  292. .id = AT91CAP9_ID_PIOABCD,
  293. .regbase = AT91CAP9_BASE_PIOD,
  294. .clock = &pioABCD_clk,
  295. }
  296. };
  297. static void at91cap9_reset(void)
  298. {
  299. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  300. }
  301. static void at91cap9_poweroff(void)
  302. {
  303. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  304. }
  305. /* --------------------------------------------------------------------
  306. * AT91CAP9 processor initialization
  307. * -------------------------------------------------------------------- */
  308. static void __init at91cap9_map_io(void)
  309. {
  310. at91_init_sram(0, AT91CAP9_SRAM_BASE, AT91CAP9_SRAM_SIZE);
  311. }
  312. static void __init at91cap9_ioremap_registers(void)
  313. {
  314. at91sam926x_ioremap_pit(AT91CAP9_BASE_PIT);
  315. at91sam9_ioremap_smc(0, AT91CAP9_BASE_SMC);
  316. }
  317. static void __init at91cap9_initialize(void)
  318. {
  319. at91_arch_reset = at91cap9_reset;
  320. pm_power_off = at91cap9_poweroff;
  321. at91_extern_irq = (1 << AT91CAP9_ID_IRQ0) | (1 << AT91CAP9_ID_IRQ1);
  322. /* Register GPIO subsystem */
  323. at91_gpio_init(at91cap9_gpio, 4);
  324. /* Remember the silicon revision */
  325. if (cpu_is_at91cap9_revB())
  326. system_rev = 0xB;
  327. else if (cpu_is_at91cap9_revC())
  328. system_rev = 0xC;
  329. }
  330. /* --------------------------------------------------------------------
  331. * Interrupt initialization
  332. * -------------------------------------------------------------------- */
  333. /*
  334. * The default interrupt priority levels (0 = lowest, 7 = highest).
  335. */
  336. static unsigned int at91cap9_default_irq_priority[NR_AIC_IRQS] __initdata = {
  337. 7, /* Advanced Interrupt Controller (FIQ) */
  338. 7, /* System Peripherals */
  339. 1, /* Parallel IO Controller A, B, C and D */
  340. 0, /* MP Block Peripheral 0 */
  341. 0, /* MP Block Peripheral 1 */
  342. 0, /* MP Block Peripheral 2 */
  343. 0, /* MP Block Peripheral 3 */
  344. 0, /* MP Block Peripheral 4 */
  345. 5, /* USART 0 */
  346. 5, /* USART 1 */
  347. 5, /* USART 2 */
  348. 0, /* Multimedia Card Interface 0 */
  349. 0, /* Multimedia Card Interface 1 */
  350. 3, /* CAN */
  351. 6, /* Two-Wire Interface */
  352. 5, /* Serial Peripheral Interface 0 */
  353. 5, /* Serial Peripheral Interface 1 */
  354. 4, /* Serial Synchronous Controller 0 */
  355. 4, /* Serial Synchronous Controller 1 */
  356. 5, /* AC97 Controller */
  357. 0, /* Timer Counter 0, 1 and 2 */
  358. 0, /* Pulse Width Modulation Controller */
  359. 3, /* Ethernet */
  360. 0, /* Advanced Encryption Standard, Triple DES*/
  361. 0, /* Analog-to-Digital Converter */
  362. 0, /* Image Sensor Interface */
  363. 3, /* LCD Controller */
  364. 0, /* DMA Controller */
  365. 2, /* USB Device Port */
  366. 2, /* USB Host port */
  367. 0, /* Advanced Interrupt Controller (IRQ0) */
  368. 0, /* Advanced Interrupt Controller (IRQ1) */
  369. };
  370. struct at91_init_soc __initdata at91cap9_soc = {
  371. .map_io = at91cap9_map_io,
  372. .default_irq_priority = at91cap9_default_irq_priority,
  373. .ioremap_registers = at91cap9_ioremap_registers,
  374. .register_clocks = at91cap9_register_clocks,
  375. .init = at91cap9_initialize,
  376. };