setup.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Board-specific setup code for the ATNGW100 Network Gateway
  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/irq.h>
  13. #include <linux/i2c.h>
  14. #include <linux/i2c-gpio.h>
  15. #include <linux/init.h>
  16. #include <linux/linkage.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/types.h>
  19. #include <linux/leds.h>
  20. #include <linux/spi/spi.h>
  21. #include <asm/atmel-mci.h>
  22. #include <asm/io.h>
  23. #include <asm/setup.h>
  24. #include <mach/at32ap700x.h>
  25. #include <mach/board.h>
  26. #include <mach/init.h>
  27. #include <mach/portmux.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. /* Initialized by bootloader-specific startup code. */
  35. struct tag *bootloader_tags __initdata;
  36. struct eth_addr {
  37. u8 addr[6];
  38. };
  39. static struct eth_addr __initdata hw_addr[2];
  40. static struct eth_platform_data __initdata eth_data[2];
  41. static struct spi_board_info spi0_board_info[] __initdata = {
  42. {
  43. .modalias = "mtd_dataflash",
  44. .max_speed_hz = 8000000,
  45. .chip_select = 0,
  46. },
  47. };
  48. static struct mci_platform_data __initdata mci0_data = {
  49. .detect_pin = GPIO_PIN_PC(25),
  50. .wp_pin = GPIO_PIN_PE(0),
  51. };
  52. /*
  53. * The next two functions should go away as the boot loader is
  54. * supposed to initialize the macb address registers with a valid
  55. * ethernet address. But we need to keep it around for a while until
  56. * we can be reasonably sure the boot loader does this.
  57. *
  58. * The phy_id is ignored as the driver will probe for it.
  59. */
  60. static int __init parse_tag_ethernet(struct tag *tag)
  61. {
  62. int i;
  63. i = tag->u.ethernet.mac_index;
  64. if (i < ARRAY_SIZE(hw_addr))
  65. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  66. sizeof(hw_addr[i].addr));
  67. return 0;
  68. }
  69. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  70. static void __init set_hw_addr(struct platform_device *pdev)
  71. {
  72. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  73. const u8 *addr;
  74. void __iomem *regs;
  75. struct clk *pclk;
  76. if (!res)
  77. return;
  78. if (pdev->id >= ARRAY_SIZE(hw_addr))
  79. return;
  80. addr = hw_addr[pdev->id].addr;
  81. if (!is_valid_ether_addr(addr))
  82. return;
  83. /*
  84. * Since this is board-specific code, we'll cheat and use the
  85. * physical address directly as we happen to know that it's
  86. * the same as the virtual address.
  87. */
  88. regs = (void __iomem __force *)res->start;
  89. pclk = clk_get(&pdev->dev, "pclk");
  90. if (!pclk)
  91. return;
  92. clk_enable(pclk);
  93. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  94. | (addr[1] << 8) | addr[0], regs + 0x98);
  95. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  96. clk_disable(pclk);
  97. clk_put(pclk);
  98. }
  99. void __init setup_board(void)
  100. {
  101. at32_map_usart(1, 0); /* USART 1: /dev/ttyS0, DB9 */
  102. at32_setup_serial_console(0);
  103. }
  104. static const struct gpio_led ngw_leds[] = {
  105. { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
  106. .default_trigger = "heartbeat",
  107. },
  108. { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
  109. { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
  110. };
  111. static const struct gpio_led_platform_data ngw_led_data = {
  112. .num_leds = ARRAY_SIZE(ngw_leds),
  113. .leds = (void *) ngw_leds,
  114. };
  115. static struct platform_device ngw_gpio_leds = {
  116. .name = "leds-gpio",
  117. .id = -1,
  118. .dev = {
  119. .platform_data = (void *) &ngw_led_data,
  120. }
  121. };
  122. static struct i2c_gpio_platform_data i2c_gpio_data = {
  123. .sda_pin = GPIO_PIN_PA(6),
  124. .scl_pin = GPIO_PIN_PA(7),
  125. .sda_is_open_drain = 1,
  126. .scl_is_open_drain = 1,
  127. .udelay = 2, /* close to 100 kHz */
  128. };
  129. static struct platform_device i2c_gpio_device = {
  130. .name = "i2c-gpio",
  131. .id = 0,
  132. .dev = {
  133. .platform_data = &i2c_gpio_data,
  134. },
  135. };
  136. static struct i2c_board_info __initdata i2c_info[] = {
  137. /* NOTE: original ATtiny24 firmware is at address 0x0b */
  138. };
  139. static int __init atngw100_init(void)
  140. {
  141. unsigned i;
  142. /*
  143. * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
  144. * reserve any pins for it.
  145. */
  146. at32_add_system_devices();
  147. at32_add_device_usart(0);
  148. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  149. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  150. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  151. at32_add_device_mci(0, &mci0_data);
  152. at32_add_device_usba(0, NULL);
  153. for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
  154. at32_select_gpio(ngw_leds[i].gpio,
  155. AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  156. }
  157. platform_device_register(&ngw_gpio_leds);
  158. /* all these i2c/smbus pins should have external pullups for
  159. * open-drain sharing among all I2C devices. SDA and SCL do;
  160. * PB28/EXTINT3 doesn't; it should be SMBALERT# (for PMBus),
  161. * but it's not available off-board.
  162. */
  163. at32_select_periph(GPIO_PIN_PB(28), 0, AT32_GPIOF_PULLUP);
  164. at32_select_gpio(i2c_gpio_data.sda_pin,
  165. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  166. at32_select_gpio(i2c_gpio_data.scl_pin,
  167. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  168. platform_device_register(&i2c_gpio_device);
  169. i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
  170. return 0;
  171. }
  172. postcore_initcall(atngw100_init);
  173. static int __init atngw100_arch_init(void)
  174. {
  175. /* set_irq_type() after the arch_initcall for EIC has run, and
  176. * before the I2C subsystem could try using this IRQ.
  177. */
  178. return set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING);
  179. }
  180. arch_initcall(atngw100_arch_init);