setup.c 2.9 KB

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