atstk1002.c 7.8 KB

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