atstk1002.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * ATSTK1002 daughterboard-specific init code
  3. *
  4. * Copyright (C) 2005-2006 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 <video/atmel_lcdc.h>
  20. #include <asm/io.h>
  21. #include <asm/setup.h>
  22. #include <asm/arch/at32ap700x.h>
  23. #include <asm/arch/board.h>
  24. #include <asm/arch/init.h>
  25. #include <asm/arch/portmux.h>
  26. #include "atstk1000.h"
  27. struct eth_addr {
  28. u8 addr[6];
  29. };
  30. static struct eth_addr __initdata hw_addr[2];
  31. static struct eth_platform_data __initdata eth_data[2] = {
  32. {
  33. /*
  34. * The MDIO pullups on STK1000 are a bit too weak for
  35. * the autodetection to work properly, so we have to
  36. * mask out everything but the correct address.
  37. */
  38. .phy_mask = ~(1U << 16),
  39. },
  40. {
  41. .phy_mask = ~(1U << 17),
  42. },
  43. };
  44. #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
  45. static struct at73c213_board_info at73c213_data = {
  46. .ssc_id = 0,
  47. .shortname = "AVR32 STK1000 external DAC",
  48. };
  49. #endif
  50. #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
  51. static struct spi_board_info spi0_board_info[] __initdata = {
  52. #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
  53. {
  54. /* AT73C213 */
  55. .modalias = "at73c213",
  56. .max_speed_hz = 200000,
  57. .chip_select = 0,
  58. .mode = SPI_MODE_1,
  59. .platform_data = &at73c213_data,
  60. },
  61. #endif
  62. {
  63. /* QVGA display */
  64. .modalias = "ltv350qv",
  65. .max_speed_hz = 16000000,
  66. .chip_select = 1,
  67. .mode = SPI_MODE_3,
  68. },
  69. };
  70. #endif
  71. #ifdef CONFIG_BOARD_ATSTK100X_SPI1
  72. static struct spi_board_info spi1_board_info[] __initdata = { {
  73. /* patch in custom entries here */
  74. } };
  75. #endif
  76. /*
  77. * The next two functions should go away as the boot loader is
  78. * supposed to initialize the macb address registers with a valid
  79. * ethernet address. But we need to keep it around for a while until
  80. * we can be reasonably sure the boot loader does this.
  81. *
  82. * The phy_id is ignored as the driver will probe for it.
  83. */
  84. static int __init parse_tag_ethernet(struct tag *tag)
  85. {
  86. int i;
  87. i = tag->u.ethernet.mac_index;
  88. if (i < ARRAY_SIZE(hw_addr))
  89. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  90. sizeof(hw_addr[i].addr));
  91. return 0;
  92. }
  93. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  94. static void __init set_hw_addr(struct platform_device *pdev)
  95. {
  96. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  97. const u8 *addr;
  98. void __iomem *regs;
  99. struct clk *pclk;
  100. if (!res)
  101. return;
  102. if (pdev->id >= ARRAY_SIZE(hw_addr))
  103. return;
  104. addr = hw_addr[pdev->id].addr;
  105. if (!is_valid_ether_addr(addr))
  106. return;
  107. /*
  108. * Since this is board-specific code, we'll cheat and use the
  109. * physical address directly as we happen to know that it's
  110. * the same as the virtual address.
  111. */
  112. regs = (void __iomem __force *)res->start;
  113. pclk = clk_get(&pdev->dev, "pclk");
  114. if (!pclk)
  115. return;
  116. clk_enable(pclk);
  117. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  118. | (addr[1] << 8) | addr[0], regs + 0x98);
  119. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  120. clk_disable(pclk);
  121. clk_put(pclk);
  122. }
  123. #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
  124. static void __init atstk1002_setup_extdac(void)
  125. {
  126. struct clk *gclk;
  127. struct clk *pll;
  128. gclk = clk_get(NULL, "gclk0");
  129. if (IS_ERR(gclk))
  130. goto err_gclk;
  131. pll = clk_get(NULL, "pll0");
  132. if (IS_ERR(pll))
  133. goto err_pll;
  134. if (clk_set_parent(gclk, pll)) {
  135. pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
  136. goto err_set_clk;
  137. }
  138. at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
  139. at73c213_data.dac_clk = gclk;
  140. err_set_clk:
  141. clk_put(pll);
  142. err_pll:
  143. clk_put(gclk);
  144. err_gclk:
  145. return;
  146. }
  147. #else
  148. static void __init atstk1002_setup_extdac(void)
  149. {
  150. }
  151. #endif /* CONFIG_BOARD_ATSTK1000_EXTDAC */
  152. void __init setup_board(void)
  153. {
  154. #ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  155. at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
  156. #else
  157. at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
  158. #endif
  159. /* USART 2/unused: expansion connector */
  160. at32_map_usart(3, 2); /* USART 3/C: /dev/ttyS2, DB9 */
  161. at32_setup_serial_console(0);
  162. }
  163. static int __init atstk1002_init(void)
  164. {
  165. /*
  166. * ATSTK1000 uses 32-bit SDRAM interface. Reserve the
  167. * SDRAM-specific pins so that nobody messes with them.
  168. */
  169. at32_reserve_pin(GPIO_PIN_PE(0)); /* DATA[16] */
  170. at32_reserve_pin(GPIO_PIN_PE(1)); /* DATA[17] */
  171. at32_reserve_pin(GPIO_PIN_PE(2)); /* DATA[18] */
  172. at32_reserve_pin(GPIO_PIN_PE(3)); /* DATA[19] */
  173. at32_reserve_pin(GPIO_PIN_PE(4)); /* DATA[20] */
  174. at32_reserve_pin(GPIO_PIN_PE(5)); /* DATA[21] */
  175. at32_reserve_pin(GPIO_PIN_PE(6)); /* DATA[22] */
  176. at32_reserve_pin(GPIO_PIN_PE(7)); /* DATA[23] */
  177. at32_reserve_pin(GPIO_PIN_PE(8)); /* DATA[24] */
  178. at32_reserve_pin(GPIO_PIN_PE(9)); /* DATA[25] */
  179. at32_reserve_pin(GPIO_PIN_PE(10)); /* DATA[26] */
  180. at32_reserve_pin(GPIO_PIN_PE(11)); /* DATA[27] */
  181. at32_reserve_pin(GPIO_PIN_PE(12)); /* DATA[28] */
  182. at32_reserve_pin(GPIO_PIN_PE(13)); /* DATA[29] */
  183. at32_reserve_pin(GPIO_PIN_PE(14)); /* DATA[30] */
  184. at32_reserve_pin(GPIO_PIN_PE(15)); /* DATA[31] */
  185. at32_reserve_pin(GPIO_PIN_PE(26)); /* SDCS */
  186. at32_add_system_devices();
  187. #ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
  188. at32_add_device_usart(1);
  189. #else
  190. at32_add_device_usart(0);
  191. #endif
  192. at32_add_device_usart(2);
  193. #ifndef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
  194. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  195. #endif
  196. #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
  197. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  198. #endif
  199. #ifdef CONFIG_BOARD_ATSTK100X_SPI1
  200. at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
  201. #endif
  202. #ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
  203. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  204. #else
  205. at32_add_device_lcdc(0, &atstk1000_lcdc_data,
  206. fbmem_start, fbmem_size);
  207. #endif
  208. at32_add_device_usba(0, NULL);
  209. #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM
  210. at32_add_device_ssc(0, ATMEL_SSC_TX);
  211. #endif
  212. atstk1000_setup_j2_leds();
  213. atstk1002_setup_extdac();
  214. return 0;
  215. }
  216. postcore_initcall(atstk1002_init);