setup.c 3.7 KB

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