atstk1002.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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/leds.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/string.h>
  17. #include <linux/types.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/spi/at73c213.h>
  20. #include <video/atmel_lcdc.h>
  21. #include <asm/io.h>
  22. #include <asm/setup.h>
  23. #include <asm/arch/at32ap7000.h>
  24. #include <asm/arch/board.h>
  25. #include <asm/arch/init.h>
  26. #include <asm/arch/portmux.h>
  27. #include "atstk1000.h"
  28. struct eth_addr {
  29. u8 addr[6];
  30. };
  31. static struct eth_addr __initdata hw_addr[2];
  32. static struct eth_platform_data __initdata eth_data[2] = {
  33. {
  34. /*
  35. * The MDIO pullups on STK1000 are a bit too weak for
  36. * the autodetection to work properly, so we have to
  37. * mask out everything but the correct address.
  38. */
  39. .phy_mask = ~(1U << 16),
  40. },
  41. {
  42. .phy_mask = ~(1U << 17),
  43. },
  44. };
  45. #ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
  46. #ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
  47. static struct at73c213_board_info at73c213_data = {
  48. .ssc_id = 0,
  49. .shortname = "AVR32 STK1000 external DAC",
  50. };
  51. #endif
  52. #endif
  53. #ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
  54. static struct spi_board_info spi0_board_info[] __initdata = {
  55. #ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
  56. {
  57. /* AT73C213 */
  58. .modalias = "at73c213",
  59. .max_speed_hz = 200000,
  60. .chip_select = 0,
  61. .mode = SPI_MODE_1,
  62. .platform_data = &at73c213_data,
  63. },
  64. #endif
  65. {
  66. /* QVGA display */
  67. .modalias = "ltv350qv",
  68. .max_speed_hz = 16000000,
  69. .chip_select = 1,
  70. .mode = SPI_MODE_3,
  71. },
  72. };
  73. #endif
  74. #ifdef CONFIG_BOARD_ATSTK1002_SPI1
  75. static struct spi_board_info spi1_board_info[] __initdata = { {
  76. /* patch in custom entries here */
  77. } };
  78. #endif
  79. /*
  80. * The next two functions should go away as the boot loader is
  81. * supposed to initialize the macb address registers with a valid
  82. * ethernet address. But we need to keep it around for a while until
  83. * we can be reasonably sure the boot loader does this.
  84. *
  85. * The phy_id is ignored as the driver will probe for it.
  86. */
  87. static int __init parse_tag_ethernet(struct tag *tag)
  88. {
  89. int i;
  90. i = tag->u.ethernet.mac_index;
  91. if (i < ARRAY_SIZE(hw_addr))
  92. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  93. sizeof(hw_addr[i].addr));
  94. return 0;
  95. }
  96. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  97. static void __init set_hw_addr(struct platform_device *pdev)
  98. {
  99. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  100. const u8 *addr;
  101. void __iomem *regs;
  102. struct clk *pclk;
  103. if (!res)
  104. return;
  105. if (pdev->id >= ARRAY_SIZE(hw_addr))
  106. return;
  107. addr = hw_addr[pdev->id].addr;
  108. if (!is_valid_ether_addr(addr))
  109. return;
  110. /*
  111. * Since this is board-specific code, we'll cheat and use the
  112. * physical address directly as we happen to know that it's
  113. * the same as the virtual address.
  114. */
  115. regs = (void __iomem __force *)res->start;
  116. pclk = clk_get(&pdev->dev, "pclk");
  117. if (!pclk)
  118. return;
  119. clk_enable(pclk);
  120. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  121. | (addr[1] << 8) | addr[0], regs + 0x98);
  122. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  123. clk_disable(pclk);
  124. clk_put(pclk);
  125. }
  126. #ifdef CONFIG_BOARD_ATSTK1002_J2_LED
  127. static struct gpio_led stk_j2_led[] = {
  128. #ifdef CONFIG_BOARD_ATSTK1002_J2_LED8
  129. #define LEDSTRING "J2 jumpered to LED8"
  130. { .name = "led0:amber", .gpio = GPIO_PIN_PB( 8), },
  131. { .name = "led1:amber", .gpio = GPIO_PIN_PB( 9), },
  132. { .name = "led2:amber", .gpio = GPIO_PIN_PB(10), },
  133. { .name = "led3:amber", .gpio = GPIO_PIN_PB(13), },
  134. { .name = "led4:amber", .gpio = GPIO_PIN_PB(14), },
  135. { .name = "led5:amber", .gpio = GPIO_PIN_PB(15), },
  136. { .name = "led6:amber", .gpio = GPIO_PIN_PB(16), },
  137. { .name = "led7:amber", .gpio = GPIO_PIN_PB(30),
  138. .default_trigger = "heartbeat", },
  139. #else /* RGB */
  140. #define LEDSTRING "J2 jumpered to RGB LEDs"
  141. { .name = "r1:red", .gpio = GPIO_PIN_PB( 8), },
  142. { .name = "g1:green", .gpio = GPIO_PIN_PB(10), },
  143. { .name = "b1:blue", .gpio = GPIO_PIN_PB(14), },
  144. { .name = "r2:red", .gpio = GPIO_PIN_PB( 9),
  145. .default_trigger = "heartbeat", },
  146. { .name = "g2:green", .gpio = GPIO_PIN_PB(13), },
  147. { .name = "b2:blue", .gpio = GPIO_PIN_PB(15),
  148. .default_trigger = "heartbeat", },
  149. /* PB16, PB30 unused */
  150. #endif
  151. };
  152. static struct gpio_led_platform_data stk_j2_led_data = {
  153. .num_leds = ARRAY_SIZE(stk_j2_led),
  154. .leds = stk_j2_led,
  155. };
  156. static struct platform_device stk_j2_led_dev = {
  157. .name = "leds-gpio",
  158. .id = 2, /* gpio block J2 */
  159. .dev = {
  160. .platform_data = &stk_j2_led_data,
  161. },
  162. };
  163. static void setup_j2_leds(void)
  164. {
  165. unsigned i;
  166. for (i = 0; i < ARRAY_SIZE(stk_j2_led); i++)
  167. at32_select_gpio(stk_j2_led[i].gpio, AT32_GPIOF_OUTPUT);
  168. printk("STK1002: " LEDSTRING "\n");
  169. platform_device_register(&stk_j2_led_dev);
  170. }
  171. #else
  172. static void setup_j2_leds(void)
  173. {
  174. }
  175. #endif
  176. #ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
  177. #ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
  178. static void __init at73c213_set_clk(struct at73c213_board_info *info)
  179. {
  180. struct clk *gclk;
  181. struct clk *pll;
  182. gclk = clk_get(NULL, "gclk0");
  183. if (IS_ERR(gclk))
  184. goto err_gclk;
  185. pll = clk_get(NULL, "pll0");
  186. if (IS_ERR(pll))
  187. goto err_pll;
  188. if (clk_set_parent(gclk, pll)) {
  189. pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
  190. goto err_set_clk;
  191. }
  192. at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
  193. info->dac_clk = gclk;
  194. err_set_clk:
  195. clk_put(pll);
  196. err_pll:
  197. clk_put(gclk);
  198. err_gclk:
  199. return;
  200. }
  201. #endif
  202. #endif
  203. void __init setup_board(void)
  204. {
  205. #ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
  206. at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
  207. #else
  208. at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
  209. #endif
  210. /* USART 2/unused: expansion connector */
  211. at32_map_usart(3, 2); /* USART 3/C: /dev/ttyS2, DB9 */
  212. at32_setup_serial_console(0);
  213. }
  214. static int __init atstk1002_init(void)
  215. {
  216. /*
  217. * ATSTK1000 uses 32-bit SDRAM interface. Reserve the
  218. * SDRAM-specific pins so that nobody messes with them.
  219. */
  220. at32_reserve_pin(GPIO_PIN_PE(0)); /* DATA[16] */
  221. at32_reserve_pin(GPIO_PIN_PE(1)); /* DATA[17] */
  222. at32_reserve_pin(GPIO_PIN_PE(2)); /* DATA[18] */
  223. at32_reserve_pin(GPIO_PIN_PE(3)); /* DATA[19] */
  224. at32_reserve_pin(GPIO_PIN_PE(4)); /* DATA[20] */
  225. at32_reserve_pin(GPIO_PIN_PE(5)); /* DATA[21] */
  226. at32_reserve_pin(GPIO_PIN_PE(6)); /* DATA[22] */
  227. at32_reserve_pin(GPIO_PIN_PE(7)); /* DATA[23] */
  228. at32_reserve_pin(GPIO_PIN_PE(8)); /* DATA[24] */
  229. at32_reserve_pin(GPIO_PIN_PE(9)); /* DATA[25] */
  230. at32_reserve_pin(GPIO_PIN_PE(10)); /* DATA[26] */
  231. at32_reserve_pin(GPIO_PIN_PE(11)); /* DATA[27] */
  232. at32_reserve_pin(GPIO_PIN_PE(12)); /* DATA[28] */
  233. at32_reserve_pin(GPIO_PIN_PE(13)); /* DATA[29] */
  234. at32_reserve_pin(GPIO_PIN_PE(14)); /* DATA[30] */
  235. at32_reserve_pin(GPIO_PIN_PE(15)); /* DATA[31] */
  236. at32_reserve_pin(GPIO_PIN_PE(26)); /* SDCS */
  237. at32_add_system_devices();
  238. #ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
  239. at32_add_device_usart(1);
  240. #else
  241. at32_add_device_usart(0);
  242. #endif
  243. at32_add_device_usart(2);
  244. #ifndef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
  245. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  246. #endif
  247. #ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
  248. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  249. #endif
  250. #ifdef CONFIG_BOARD_ATSTK1002_SPI1
  251. at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
  252. #endif
  253. #ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
  254. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  255. #else
  256. at32_add_device_lcdc(0, &atstk1000_lcdc_data,
  257. fbmem_start, fbmem_size);
  258. #endif
  259. at32_add_device_usba(0, NULL);
  260. #ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
  261. at32_add_device_ssc(0, ATMEL_SSC_TX);
  262. #endif
  263. setup_j2_leds();
  264. #ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
  265. #ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
  266. at73c213_set_clk(&at73c213_data);
  267. #endif
  268. #endif
  269. return 0;
  270. }
  271. postcore_initcall(atstk1002_init);