atstk1002.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. .parts = nand_partitions,
  86. .num_parts = ARRAY_SIZE(num_partitions),
  87. };
  88. #endif
  89. struct eth_addr {
  90. u8 addr[6];
  91. };
  92. static struct eth_addr __initdata hw_addr[2];
  93. static struct eth_platform_data __initdata eth_data[2] = {
  94. {
  95. /*
  96. * The MDIO pullups on STK1000 are a bit too weak for
  97. * the autodetection to work properly, so we have to
  98. * mask out everything but the correct address.
  99. */
  100. .phy_mask = ~(1U << 16),
  101. },
  102. {
  103. .phy_mask = ~(1U << 17),
  104. },
  105. };
  106. #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
  107. static struct at73c213_board_info at73c213_data = {
  108. .ssc_id = 0,
  109. .shortname = "AVR32 STK1000 external DAC",
  110. };
  111. #endif
  112. #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
  113. static struct spi_board_info spi0_board_info[] __initdata = {
  114. #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
  115. {
  116. /* AT73C213 */
  117. .modalias = "at73c213",
  118. .max_speed_hz = 200000,
  119. .chip_select = 0,
  120. .mode = SPI_MODE_1,
  121. .platform_data = &at73c213_data,
  122. },
  123. #endif
  124. {
  125. /* QVGA display */
  126. .modalias = "ltv350qv",
  127. .max_speed_hz = 16000000,
  128. .chip_select = 1,
  129. .mode = SPI_MODE_3,
  130. },
  131. };
  132. #endif
  133. #ifdef CONFIG_BOARD_ATSTK100X_SPI1
  134. static struct spi_board_info spi1_board_info[] __initdata = { {
  135. /* patch in custom entries here */
  136. } };
  137. #endif
  138. /*
  139. * The next two functions should go away as the boot loader is
  140. * supposed to initialize the macb address registers with a valid
  141. * ethernet address. But we need to keep it around for a while until
  142. * we can be reasonably sure the boot loader does this.
  143. *
  144. * The phy_id is ignored as the driver will probe for it.
  145. */
  146. static int __init parse_tag_ethernet(struct tag *tag)
  147. {
  148. int i;
  149. i = tag->u.ethernet.mac_index;
  150. if (i < ARRAY_SIZE(hw_addr))
  151. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  152. sizeof(hw_addr[i].addr));
  153. return 0;
  154. }
  155. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  156. static void __init set_hw_addr(struct platform_device *pdev)
  157. {
  158. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  159. const u8 *addr;
  160. void __iomem *regs;
  161. struct clk *pclk;
  162. if (!res)
  163. return;
  164. if (pdev->id >= ARRAY_SIZE(hw_addr))
  165. return;
  166. addr = hw_addr[pdev->id].addr;
  167. if (!is_valid_ether_addr(addr))
  168. return;
  169. /*
  170. * Since this is board-specific code, we'll cheat and use the
  171. * physical address directly as we happen to know that it's
  172. * the same as the virtual address.
  173. */
  174. regs = (void __iomem __force *)res->start;
  175. pclk = clk_get(&pdev->dev, "pclk");
  176. if (IS_ERR(pclk))
  177. return;
  178. clk_enable(pclk);
  179. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  180. | (addr[1] << 8) | addr[0], regs + 0x98);
  181. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  182. clk_disable(pclk);
  183. clk_put(pclk);
  184. }
  185. #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
  186. static void __init atstk1002_setup_extdac(void)
  187. {
  188. struct clk *gclk;
  189. struct clk *pll;
  190. gclk = clk_get(NULL, "gclk0");
  191. if (IS_ERR(gclk))
  192. goto err_gclk;
  193. pll = clk_get(NULL, "pll0");
  194. if (IS_ERR(pll))
  195. goto err_pll;
  196. if (clk_set_parent(gclk, pll)) {
  197. pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
  198. goto err_set_clk;
  199. }
  200. at32_select_periph(GPIO_PIOA_BASE, (1 << 30), GPIO_PERIPH_A, 0);
  201. at73c213_data.dac_clk = gclk;
  202. err_set_clk:
  203. clk_put(pll);
  204. err_pll:
  205. clk_put(gclk);
  206. err_gclk:
  207. return;
  208. }
  209. #else
  210. static void __init atstk1002_setup_extdac(void)
  211. {
  212. }
  213. #endif /* CONFIG_BOARD_ATSTK1000_EXTDAC */
  214. void __init setup_board(void)
  215. {
  216. #ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  217. at32_map_usart(0, 1, 0); /* USART 0/B: /dev/ttyS1, IRDA */
  218. #else
  219. at32_map_usart(1, 0, 0); /* USART 1/A: /dev/ttyS0, DB9 */
  220. #endif
  221. /* USART 2/unused: expansion connector */
  222. at32_map_usart(3, 2, 0); /* USART 3/C: /dev/ttyS2, DB9 */
  223. at32_setup_serial_console(0);
  224. }
  225. #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  226. static struct mci_platform_data __initdata mci0_data = {
  227. .slot[0] = {
  228. .bus_width = 4,
  229. /* MMC card detect requires MACB0 *NOT* be used */
  230. #ifdef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
  231. .detect_pin = GPIO_PIN_PC(14), /* gpio30/sdcd */
  232. .wp_pin = GPIO_PIN_PC(15), /* gpio31/sdwp */
  233. #else
  234. .detect_pin = -ENODEV,
  235. .wp_pin = -ENODEV,
  236. #endif /* SW6 for sd{cd,wp} routing */
  237. },
  238. };
  239. #endif /* SW2 for MMC signal routing */
  240. static int __init atstk1002_init(void)
  241. {
  242. /*
  243. * ATSTK1000 uses 32-bit SDRAM interface. Reserve the
  244. * SDRAM-specific pins so that nobody messes with them.
  245. */
  246. at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);
  247. #ifdef CONFIG_BOARD_ATSTK1006
  248. smc_set_timing(&nand_config, &nand_timing);
  249. smc_set_configuration(3, &nand_config);
  250. at32_add_device_nand(0, &atstk1006_nand_data);
  251. #endif
  252. #ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  253. at32_add_device_usart(1);
  254. #else
  255. at32_add_device_usart(0);
  256. #endif
  257. at32_add_device_usart(2);
  258. #ifndef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
  259. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  260. #endif
  261. #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
  262. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  263. #endif
  264. #ifdef CONFIG_BOARD_ATSTK100X_SPI1
  265. at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
  266. #endif
  267. #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  268. at32_add_device_mci(0, &mci0_data);
  269. #endif
  270. #ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
  271. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  272. #else
  273. at32_add_device_lcdc(0, &atstk1000_lcdc_data,
  274. fbmem_start, fbmem_size,
  275. ATMEL_LCDC_PRI_24BIT | ATMEL_LCDC_PRI_CONTROL);
  276. #endif
  277. at32_add_device_usba(0, NULL);
  278. #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM
  279. at32_add_device_ssc(0, ATMEL_SSC_TX);
  280. #endif
  281. atstk1000_setup_j2_leds();
  282. atstk1002_setup_extdac();
  283. return 0;
  284. }
  285. postcore_initcall(atstk1002_init);