atstk1002.c 2.6 KB

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