atstk1002.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * ATSTK1002/ATSTK1006 daughterboard-specific init code
  3. *
  4. * Copyright (C) 2005-2007 Atmel Corporation
  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 version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/etherdevice.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/string.h>
  16. #include <linux/types.h>
  17. #include <linux/spi/spi.h>
  18. #include <linux/spi/at73c213.h>
  19. #include <linux/atmel-mci.h>
  20. #include <video/atmel_lcdc.h>
  21. #include <asm/io.h>
  22. #include <asm/setup.h>
  23. #include <mach/at32ap700x.h>
  24. #include <mach/board.h>
  25. #include <mach/init.h>
  26. #include <mach/portmux.h>
  27. #include "atstk1000.h"
  28. /* Oscillator frequencies. These are board specific */
  29. unsigned long at32_board_osc_rates[3] = {
  30. [0] = 32768, /* 32.768 kHz on RTC osc */
  31. [1] = 20000000, /* 20 MHz on osc0 */
  32. [2] = 12000000, /* 12 MHz on osc1 */
  33. };
  34. /*
  35. * The ATSTK1006 daughterboard is very similar to the ATSTK1002. Both
  36. * have the AT32AP7000 chip on board; the difference is that the
  37. * STK1006 has 128 MB SDRAM (the STK1002 uses the 8 MB SDRAM chip on
  38. * the STK1000 motherboard) and 256 MB NAND flash (the STK1002 has
  39. * none.)
  40. *
  41. * The RAM difference is handled by the boot loader, so the only
  42. * difference we end up handling here is the NAND flash.
  43. */
  44. #ifdef CONFIG_BOARD_ATSTK1006
  45. #include <linux/mtd/partitions.h>
  46. #include <mach/smc.h>
  47. static struct smc_timing nand_timing __initdata = {
  48. .ncs_read_setup = 0,
  49. .nrd_setup = 10,
  50. .ncs_write_setup = 0,
  51. .nwe_setup = 10,
  52. .ncs_read_pulse = 30,
  53. .nrd_pulse = 15,
  54. .ncs_write_pulse = 30,
  55. .nwe_pulse = 15,
  56. .read_cycle = 30,
  57. .write_cycle = 30,
  58. .ncs_read_recover = 0,
  59. .nrd_recover = 15,
  60. .ncs_write_recover = 0,
  61. /* WE# high -> RE# low min 60 ns */
  62. .nwe_recover = 50,
  63. };
  64. static struct smc_config nand_config __initdata = {
  65. .bus_width = 1,
  66. .nrd_controlled = 1,
  67. .nwe_controlled = 1,
  68. .nwait_mode = 0,
  69. .byte_write = 0,
  70. .tdf_cycles = 2,
  71. .tdf_mode = 0,
  72. };
  73. static struct mtd_partition nand_partitions[] = {
  74. {
  75. .name = "main",
  76. .offset = 0x00000000,
  77. .size = MTDPART_SIZ_FULL,
  78. },
  79. };
  80. static struct atmel_nand_data atstk1006_nand_data __initdata = {
  81. .cle = 21,
  82. .ale = 22,
  83. .rdy_pin = GPIO_PIN_PB(30),
  84. .enable_pin = GPIO_PIN_PB(29),
  85. .ecc_mode = NAND_ECC_SOFT,
  86. .parts = nand_partitions,
  87. .num_parts = ARRAY_SIZE(nand_partitions),
  88. };
  89. #endif
  90. struct eth_addr {
  91. u8 addr[6];
  92. };
  93. static struct eth_addr __initdata hw_addr[2];
  94. static struct macb_platform_data __initdata eth_data[2] = {
  95. {
  96. /*
  97. * The MDIO pullups on STK1000 are a bit too weak for
  98. * the autodetection to work properly, so we have to
  99. * mask out everything but the correct address.
  100. */
  101. .phy_mask = ~(1U << 16),
  102. },
  103. {
  104. .phy_mask = ~(1U << 17),
  105. },
  106. };
  107. #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
  108. static struct at73c213_board_info at73c213_data = {
  109. .ssc_id = 0,
  110. .shortname = "AVR32 STK1000 external DAC",
  111. };
  112. #endif
  113. #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
  114. static struct spi_board_info spi0_board_info[] __initdata = {
  115. #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
  116. {
  117. /* AT73C213 */
  118. .modalias = "at73c213",
  119. .max_speed_hz = 200000,
  120. .chip_select = 0,
  121. .mode = SPI_MODE_1,
  122. .platform_data = &at73c213_data,
  123. },
  124. #endif
  125. {
  126. /* QVGA display */
  127. .modalias = "ltv350qv",
  128. .max_speed_hz = 16000000,
  129. .chip_select = 1,
  130. .mode = SPI_MODE_3,
  131. },
  132. };
  133. #endif
  134. #ifdef CONFIG_BOARD_ATSTK100X_SPI1
  135. static struct spi_board_info spi1_board_info[] __initdata = { {
  136. /* patch in custom entries here */
  137. } };
  138. #endif
  139. /*
  140. * The next two functions should go away as the boot loader is
  141. * supposed to initialize the macb address registers with a valid
  142. * ethernet address. But we need to keep it around for a while until
  143. * we can be reasonably sure the boot loader does this.
  144. *
  145. * The phy_id is ignored as the driver will probe for it.
  146. */
  147. static int __init parse_tag_ethernet(struct tag *tag)
  148. {
  149. int i;
  150. i = tag->u.ethernet.mac_index;
  151. if (i < ARRAY_SIZE(hw_addr))
  152. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  153. sizeof(hw_addr[i].addr));
  154. return 0;
  155. }
  156. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  157. static void __init set_hw_addr(struct platform_device *pdev)
  158. {
  159. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  160. const u8 *addr;
  161. void __iomem *regs;
  162. struct clk *pclk;
  163. if (!res)
  164. return;
  165. if (pdev->id >= ARRAY_SIZE(hw_addr))
  166. return;
  167. addr = hw_addr[pdev->id].addr;
  168. if (!is_valid_ether_addr(addr))
  169. return;
  170. /*
  171. * Since this is board-specific code, we'll cheat and use the
  172. * physical address directly as we happen to know that it's
  173. * the same as the virtual address.
  174. */
  175. regs = (void __iomem __force *)res->start;
  176. pclk = clk_get(&pdev->dev, "pclk");
  177. if (IS_ERR(pclk))
  178. return;
  179. clk_enable(pclk);
  180. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  181. | (addr[1] << 8) | addr[0], regs + 0x98);
  182. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  183. clk_disable(pclk);
  184. clk_put(pclk);
  185. }
  186. #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
  187. static void __init atstk1002_setup_extdac(void)
  188. {
  189. struct clk *gclk;
  190. struct clk *pll;
  191. gclk = clk_get(NULL, "gclk0");
  192. if (IS_ERR(gclk))
  193. goto err_gclk;
  194. pll = clk_get(NULL, "pll0");
  195. if (IS_ERR(pll))
  196. goto err_pll;
  197. if (clk_set_parent(gclk, pll)) {
  198. pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
  199. goto err_set_clk;
  200. }
  201. at32_select_periph(GPIO_PIOA_BASE, (1 << 30), GPIO_PERIPH_A, 0);
  202. at73c213_data.dac_clk = gclk;
  203. err_set_clk:
  204. clk_put(pll);
  205. err_pll:
  206. clk_put(gclk);
  207. err_gclk:
  208. return;
  209. }
  210. #else
  211. static void __init atstk1002_setup_extdac(void)
  212. {
  213. }
  214. #endif /* CONFIG_BOARD_ATSTK1000_EXTDAC */
  215. void __init setup_board(void)
  216. {
  217. #ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  218. at32_map_usart(0, 1, 0); /* USART 0/B: /dev/ttyS1, IRDA */
  219. #else
  220. at32_map_usart(1, 0, 0); /* USART 1/A: /dev/ttyS0, DB9 */
  221. #endif
  222. /* USART 2/unused: expansion connector */
  223. at32_map_usart(3, 2, 0); /* USART 3/C: /dev/ttyS2, DB9 */
  224. at32_setup_serial_console(0);
  225. }
  226. #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  227. static struct mci_platform_data __initdata mci0_data = {
  228. .slot[0] = {
  229. .bus_width = 4,
  230. /* MMC card detect requires MACB0 *NOT* be used */
  231. #ifdef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
  232. .detect_pin = GPIO_PIN_PC(14), /* gpio30/sdcd */
  233. .wp_pin = GPIO_PIN_PC(15), /* gpio31/sdwp */
  234. #else
  235. .detect_pin = -ENODEV,
  236. .wp_pin = -ENODEV,
  237. #endif /* SW6 for sd{cd,wp} routing */
  238. },
  239. };
  240. #endif /* SW2 for MMC signal routing */
  241. static int __init atstk1002_init(void)
  242. {
  243. /*
  244. * ATSTK1000 uses 32-bit SDRAM interface. Reserve the
  245. * SDRAM-specific pins so that nobody messes with them.
  246. */
  247. at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);
  248. #ifdef CONFIG_BOARD_ATSTK1006
  249. smc_set_timing(&nand_config, &nand_timing);
  250. smc_set_configuration(3, &nand_config);
  251. at32_add_device_nand(0, &atstk1006_nand_data);
  252. #endif
  253. #ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  254. at32_add_device_usart(1);
  255. #else
  256. at32_add_device_usart(0);
  257. #endif
  258. at32_add_device_usart(2);
  259. #ifndef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
  260. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  261. #endif
  262. #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
  263. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  264. #endif
  265. #ifdef CONFIG_BOARD_ATSTK100X_SPI1
  266. at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
  267. #endif
  268. #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  269. at32_add_device_mci(0, &mci0_data);
  270. #endif
  271. #ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
  272. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  273. #else
  274. at32_add_device_lcdc(0, &atstk1000_lcdc_data,
  275. fbmem_start, fbmem_size,
  276. ATMEL_LCDC_PRI_24BIT | ATMEL_LCDC_PRI_CONTROL);
  277. #endif
  278. at32_add_device_usba(0, NULL);
  279. #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM
  280. at32_add_device_ssc(0, ATMEL_SSC_TX);
  281. #endif
  282. atstk1000_setup_j2_leds();
  283. atstk1002_setup_extdac();
  284. return 0;
  285. }
  286. postcore_initcall(atstk1002_init);