dev-wmac.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Atheros AR913X/AR933X SoC built-in WMAC device support
  3. *
  4. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/delay.h>
  13. #include <linux/irq.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/ath9k_platform.h>
  16. #include <asm/mach-ath79/ath79.h>
  17. #include <asm/mach-ath79/ar71xx_regs.h>
  18. #include "dev-wmac.h"
  19. static struct ath9k_platform_data ath79_wmac_data;
  20. static struct resource ath79_wmac_resources[] = {
  21. {
  22. /* .start and .end fields are filled dynamically */
  23. .flags = IORESOURCE_MEM,
  24. }, {
  25. .start = ATH79_CPU_IRQ_IP2,
  26. .end = ATH79_CPU_IRQ_IP2,
  27. .flags = IORESOURCE_IRQ,
  28. },
  29. };
  30. static struct platform_device ath79_wmac_device = {
  31. .name = "ath9k",
  32. .id = -1,
  33. .resource = ath79_wmac_resources,
  34. .num_resources = ARRAY_SIZE(ath79_wmac_resources),
  35. .dev = {
  36. .platform_data = &ath79_wmac_data,
  37. },
  38. };
  39. static void __init ar913x_wmac_setup(void)
  40. {
  41. /* reset the WMAC */
  42. ath79_device_reset_set(AR913X_RESET_AMBA2WMAC);
  43. mdelay(10);
  44. ath79_device_reset_clear(AR913X_RESET_AMBA2WMAC);
  45. mdelay(10);
  46. ath79_wmac_resources[0].start = AR913X_WMAC_BASE;
  47. ath79_wmac_resources[0].end = AR913X_WMAC_BASE + AR913X_WMAC_SIZE - 1;
  48. }
  49. static int ar933x_wmac_reset(void)
  50. {
  51. ath79_device_reset_clear(AR933X_RESET_WMAC);
  52. ath79_device_reset_set(AR933X_RESET_WMAC);
  53. return 0;
  54. }
  55. static int ar933x_r1_get_wmac_revision(void)
  56. {
  57. return ath79_soc_rev;
  58. }
  59. static void __init ar933x_wmac_setup(void)
  60. {
  61. u32 t;
  62. ar933x_wmac_reset();
  63. ath79_wmac_device.name = "ar933x_wmac";
  64. ath79_wmac_resources[0].start = AR933X_WMAC_BASE;
  65. ath79_wmac_resources[0].end = AR933X_WMAC_BASE + AR933X_WMAC_SIZE - 1;
  66. t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  67. if (t & AR933X_BOOTSTRAP_REF_CLK_40)
  68. ath79_wmac_data.is_clk_25mhz = false;
  69. else
  70. ath79_wmac_data.is_clk_25mhz = true;
  71. if (ath79_soc_rev == 1)
  72. ath79_wmac_data.get_mac_revision = ar933x_r1_get_wmac_revision;
  73. ath79_wmac_data.external_reset = ar933x_wmac_reset;
  74. }
  75. void __init ath79_register_wmac(u8 *cal_data)
  76. {
  77. if (soc_is_ar913x())
  78. ar913x_wmac_setup();
  79. else if (soc_is_ar933x())
  80. ar933x_wmac_setup();
  81. else
  82. BUG();
  83. if (cal_data)
  84. memcpy(ath79_wmac_data.eeprom_data, cal_data,
  85. sizeof(ath79_wmac_data.eeprom_data));
  86. platform_device_register(&ath79_wmac_device);
  87. }