atstk1002.c 6.4 KB

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