atstk1002.c 2.9 KB

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