setup.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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/i2c-gpio.h>
  13. #include <linux/init.h>
  14. #include <linux/linkage.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/types.h>
  17. #include <linux/leds.h>
  18. #include <linux/spi/spi.h>
  19. #include <asm/io.h>
  20. #include <asm/setup.h>
  21. #include <asm/arch/at32ap700x.h>
  22. #include <asm/arch/board.h>
  23. #include <asm/arch/init.h>
  24. #include <asm/arch/portmux.h>
  25. /* Oscillator frequencies. These are board-specific */
  26. unsigned long at32_board_osc_rates[3] = {
  27. [0] = 32768, /* 32.768 kHz on RTC osc */
  28. [1] = 20000000, /* 20 MHz on osc0 */
  29. [2] = 12000000, /* 12 MHz on osc1 */
  30. };
  31. /* Initialized by bootloader-specific startup code. */
  32. struct tag *bootloader_tags __initdata;
  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. static struct spi_board_info spi0_board_info[] __initdata = {
  39. {
  40. .modalias = "mtd_dataflash",
  41. .max_speed_hz = 10000000,
  42. .chip_select = 0,
  43. },
  44. };
  45. /*
  46. * The next two functions should go away as the boot loader is
  47. * supposed to initialize the macb address registers with a valid
  48. * ethernet address. But we need to keep it around for a while until
  49. * we can be reasonably sure the boot loader does this.
  50. *
  51. * The phy_id is ignored as the driver will probe for it.
  52. */
  53. static int __init parse_tag_ethernet(struct tag *tag)
  54. {
  55. int i;
  56. i = tag->u.ethernet.mac_index;
  57. if (i < ARRAY_SIZE(hw_addr))
  58. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  59. sizeof(hw_addr[i].addr));
  60. return 0;
  61. }
  62. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  63. static void __init set_hw_addr(struct platform_device *pdev)
  64. {
  65. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  66. const u8 *addr;
  67. void __iomem *regs;
  68. struct clk *pclk;
  69. if (!res)
  70. return;
  71. if (pdev->id >= ARRAY_SIZE(hw_addr))
  72. return;
  73. addr = hw_addr[pdev->id].addr;
  74. if (!is_valid_ether_addr(addr))
  75. return;
  76. /*
  77. * Since this is board-specific code, we'll cheat and use the
  78. * physical address directly as we happen to know that it's
  79. * the same as the virtual address.
  80. */
  81. regs = (void __iomem __force *)res->start;
  82. pclk = clk_get(&pdev->dev, "pclk");
  83. if (!pclk)
  84. return;
  85. clk_enable(pclk);
  86. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  87. | (addr[1] << 8) | addr[0], regs + 0x98);
  88. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  89. clk_disable(pclk);
  90. clk_put(pclk);
  91. }
  92. void __init setup_board(void)
  93. {
  94. at32_map_usart(1, 0); /* USART 1: /dev/ttyS0, DB9 */
  95. at32_setup_serial_console(0);
  96. }
  97. static const struct gpio_led ngw_leds[] = {
  98. { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
  99. .default_trigger = "heartbeat",
  100. },
  101. { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
  102. { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
  103. };
  104. static const struct gpio_led_platform_data ngw_led_data = {
  105. .num_leds = ARRAY_SIZE(ngw_leds),
  106. .leds = (void *) ngw_leds,
  107. };
  108. static struct platform_device ngw_gpio_leds = {
  109. .name = "leds-gpio",
  110. .id = -1,
  111. .dev = {
  112. .platform_data = (void *) &ngw_led_data,
  113. }
  114. };
  115. static struct i2c_gpio_platform_data i2c_gpio_data = {
  116. .sda_pin = GPIO_PIN_PA(6),
  117. .scl_pin = GPIO_PIN_PA(7),
  118. .sda_is_open_drain = 1,
  119. .scl_is_open_drain = 1,
  120. .udelay = 2, /* close to 100 kHz */
  121. };
  122. static struct platform_device i2c_gpio_device = {
  123. .name = "i2c-gpio",
  124. .id = 0,
  125. .dev = {
  126. .platform_data = &i2c_gpio_data,
  127. },
  128. };
  129. static int __init atngw100_init(void)
  130. {
  131. unsigned i;
  132. /*
  133. * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
  134. * reserve any pins for it.
  135. */
  136. at32_add_system_devices();
  137. at32_add_device_usart(0);
  138. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  139. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  140. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  141. at32_add_device_usba(0, NULL);
  142. for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
  143. at32_select_gpio(ngw_leds[i].gpio,
  144. AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  145. }
  146. platform_device_register(&ngw_gpio_leds);
  147. at32_select_gpio(i2c_gpio_data.sda_pin,
  148. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  149. at32_select_gpio(i2c_gpio_data.scl_pin,
  150. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  151. platform_device_register(&i2c_gpio_device);
  152. return 0;
  153. }
  154. postcore_initcall(atngw100_init);