at91cap9.c 9.8 KB

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