atstk1002.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 <video/atmel_lcdc.h>
  20. #include <asm/io.h>
  21. #include <asm/setup.h>
  22. #include <asm/arch/at32ap7000.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. #ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
  45. static struct spi_board_info spi0_board_info[] __initdata = {
  46. {
  47. /* QVGA display */
  48. .modalias = "ltv350qv",
  49. .max_speed_hz = 16000000,
  50. .chip_select = 1,
  51. .mode = SPI_MODE_3,
  52. },
  53. };
  54. #endif
  55. #ifdef CONFIG_BOARD_ATSTK1002_SPI1
  56. static struct spi_board_info spi1_board_info[] __initdata = { {
  57. /* patch in custom entries here */
  58. } };
  59. #endif
  60. /*
  61. * The next two functions should go away as the boot loader is
  62. * supposed to initialize the macb address registers with a valid
  63. * ethernet address. But we need to keep it around for a while until
  64. * we can be reasonably sure the boot loader does this.
  65. *
  66. * The phy_id is ignored as the driver will probe for it.
  67. */
  68. static int __init parse_tag_ethernet(struct tag *tag)
  69. {
  70. int i;
  71. i = tag->u.ethernet.mac_index;
  72. if (i < ARRAY_SIZE(hw_addr))
  73. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  74. sizeof(hw_addr[i].addr));
  75. return 0;
  76. }
  77. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  78. static void __init set_hw_addr(struct platform_device *pdev)
  79. {
  80. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  81. const u8 *addr;
  82. void __iomem *regs;
  83. struct clk *pclk;
  84. if (!res)
  85. return;
  86. if (pdev->id >= ARRAY_SIZE(hw_addr))
  87. return;
  88. addr = hw_addr[pdev->id].addr;
  89. if (!is_valid_ether_addr(addr))
  90. return;
  91. /*
  92. * Since this is board-specific code, we'll cheat and use the
  93. * physical address directly as we happen to know that it's
  94. * the same as the virtual address.
  95. */
  96. regs = (void __iomem __force *)res->start;
  97. pclk = clk_get(&pdev->dev, "pclk");
  98. if (!pclk)
  99. return;
  100. clk_enable(pclk);
  101. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  102. | (addr[1] << 8) | addr[0], regs + 0x98);
  103. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  104. clk_disable(pclk);
  105. clk_put(pclk);
  106. }
  107. #ifdef CONFIG_BOARD_ATSTK1002_J2_LED
  108. static struct gpio_led stk_j2_led[] = {
  109. #ifdef CONFIG_BOARD_ATSTK1002_J2_LED8
  110. #define LEDSTRING "J2 jumpered to LED8"
  111. { .name = "led0:amber", .gpio = GPIO_PIN_PB( 8), },
  112. { .name = "led1:amber", .gpio = GPIO_PIN_PB( 9), },
  113. { .name = "led2:amber", .gpio = GPIO_PIN_PB(10), },
  114. { .name = "led3:amber", .gpio = GPIO_PIN_PB(13), },
  115. { .name = "led4:amber", .gpio = GPIO_PIN_PB(14), },
  116. { .name = "led5:amber", .gpio = GPIO_PIN_PB(15), },
  117. { .name = "led6:amber", .gpio = GPIO_PIN_PB(16), },
  118. { .name = "led7:amber", .gpio = GPIO_PIN_PB(30),
  119. .default_trigger = "heartbeat", },
  120. #else /* RGB */
  121. #define LEDSTRING "J2 jumpered to RGB LEDs"
  122. { .name = "r1:red", .gpio = GPIO_PIN_PB( 8), },
  123. { .name = "g1:green", .gpio = GPIO_PIN_PB(10), },
  124. { .name = "b1:blue", .gpio = GPIO_PIN_PB(14), },
  125. { .name = "r2:red", .gpio = GPIO_PIN_PB( 9),
  126. .default_trigger = "heartbeat", },
  127. { .name = "g2:green", .gpio = GPIO_PIN_PB(13), },
  128. { .name = "b2:blue", .gpio = GPIO_PIN_PB(15),
  129. .default_trigger = "heartbeat", },
  130. /* PB16, PB30 unused */
  131. #endif
  132. };
  133. static struct gpio_led_platform_data stk_j2_led_data = {
  134. .num_leds = ARRAY_SIZE(stk_j2_led),
  135. .leds = stk_j2_led,
  136. };
  137. static struct platform_device stk_j2_led_dev = {
  138. .name = "leds-gpio",
  139. .id = 2, /* gpio block J2 */
  140. .dev = {
  141. .platform_data = &stk_j2_led_data,
  142. },
  143. };
  144. static void setup_j2_leds(void)
  145. {
  146. unsigned i;
  147. for (i = 0; i < ARRAY_SIZE(stk_j2_led); i++)
  148. at32_select_gpio(stk_j2_led[i].gpio, AT32_GPIOF_OUTPUT);
  149. printk("STK1002: " LEDSTRING "\n");
  150. platform_device_register(&stk_j2_led_dev);
  151. }
  152. #else
  153. static void setup_j2_leds(void)
  154. {
  155. }
  156. #endif
  157. void __init setup_board(void)
  158. {
  159. #ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
  160. at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
  161. #else
  162. at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
  163. #endif
  164. /* USART 2/unused: expansion connector */
  165. at32_map_usart(3, 2); /* USART 3/C: /dev/ttyS2, DB9 */
  166. at32_setup_serial_console(0);
  167. }
  168. static int __init atstk1002_init(void)
  169. {
  170. /*
  171. * ATSTK1000 uses 32-bit SDRAM interface. Reserve the
  172. * SDRAM-specific pins so that nobody messes with them.
  173. */
  174. at32_reserve_pin(GPIO_PIN_PE(0)); /* DATA[16] */
  175. at32_reserve_pin(GPIO_PIN_PE(1)); /* DATA[17] */
  176. at32_reserve_pin(GPIO_PIN_PE(2)); /* DATA[18] */
  177. at32_reserve_pin(GPIO_PIN_PE(3)); /* DATA[19] */
  178. at32_reserve_pin(GPIO_PIN_PE(4)); /* DATA[20] */
  179. at32_reserve_pin(GPIO_PIN_PE(5)); /* DATA[21] */
  180. at32_reserve_pin(GPIO_PIN_PE(6)); /* DATA[22] */
  181. at32_reserve_pin(GPIO_PIN_PE(7)); /* DATA[23] */
  182. at32_reserve_pin(GPIO_PIN_PE(8)); /* DATA[24] */
  183. at32_reserve_pin(GPIO_PIN_PE(9)); /* DATA[25] */
  184. at32_reserve_pin(GPIO_PIN_PE(10)); /* DATA[26] */
  185. at32_reserve_pin(GPIO_PIN_PE(11)); /* DATA[27] */
  186. at32_reserve_pin(GPIO_PIN_PE(12)); /* DATA[28] */
  187. at32_reserve_pin(GPIO_PIN_PE(13)); /* DATA[29] */
  188. at32_reserve_pin(GPIO_PIN_PE(14)); /* DATA[30] */
  189. at32_reserve_pin(GPIO_PIN_PE(15)); /* DATA[31] */
  190. at32_reserve_pin(GPIO_PIN_PE(26)); /* SDCS */
  191. at32_add_system_devices();
  192. #ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
  193. at32_add_device_usart(1);
  194. #else
  195. at32_add_device_usart(0);
  196. #endif
  197. at32_add_device_usart(2);
  198. #ifndef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
  199. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  200. #endif
  201. #ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
  202. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  203. #endif
  204. #ifdef CONFIG_BOARD_ATSTK1002_SPI1
  205. at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
  206. #endif
  207. #ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
  208. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  209. #else
  210. at32_add_device_lcdc(0, &atstk1000_lcdc_data,
  211. fbmem_start, fbmem_size);
  212. #endif
  213. at32_add_device_usba(0, NULL);
  214. #ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
  215. at32_add_device_ssc(0, ATMEL_SSC_TX);
  216. #endif
  217. setup_j2_leds();
  218. return 0;
  219. }
  220. postcore_initcall(atstk1002_init);