dev-wmac.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Atheros AR913X/AR933X SoC built-in WMAC device support
  3. *
  4. * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  5. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7. *
  8. * Parts of this file are based on Atheros 2.6.15/2.6.31 BSP
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published
  12. * by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/delay.h>
  16. #include <linux/irq.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/ath9k_platform.h>
  19. #include <asm/mach-ath79/ath79.h>
  20. #include <asm/mach-ath79/ar71xx_regs.h>
  21. #include "dev-wmac.h"
  22. static struct ath9k_platform_data ath79_wmac_data;
  23. static struct resource ath79_wmac_resources[] = {
  24. {
  25. /* .start and .end fields are filled dynamically */
  26. .flags = IORESOURCE_MEM,
  27. }, {
  28. /* .start and .end fields are filled dynamically */
  29. .flags = IORESOURCE_IRQ,
  30. },
  31. };
  32. static struct platform_device ath79_wmac_device = {
  33. .name = "ath9k",
  34. .id = -1,
  35. .resource = ath79_wmac_resources,
  36. .num_resources = ARRAY_SIZE(ath79_wmac_resources),
  37. .dev = {
  38. .platform_data = &ath79_wmac_data,
  39. },
  40. };
  41. static void __init ar913x_wmac_setup(void)
  42. {
  43. /* reset the WMAC */
  44. ath79_device_reset_set(AR913X_RESET_AMBA2WMAC);
  45. mdelay(10);
  46. ath79_device_reset_clear(AR913X_RESET_AMBA2WMAC);
  47. mdelay(10);
  48. ath79_wmac_resources[0].start = AR913X_WMAC_BASE;
  49. ath79_wmac_resources[0].end = AR913X_WMAC_BASE + AR913X_WMAC_SIZE - 1;
  50. ath79_wmac_resources[1].start = ATH79_CPU_IRQ(2);
  51. ath79_wmac_resources[1].end = ATH79_CPU_IRQ(2);
  52. }
  53. static int ar933x_wmac_reset(void)
  54. {
  55. ath79_device_reset_set(AR933X_RESET_WMAC);
  56. ath79_device_reset_clear(AR933X_RESET_WMAC);
  57. return 0;
  58. }
  59. static int ar933x_r1_get_wmac_revision(void)
  60. {
  61. return ath79_soc_rev;
  62. }
  63. static void __init ar933x_wmac_setup(void)
  64. {
  65. u32 t;
  66. ar933x_wmac_reset();
  67. ath79_wmac_device.name = "ar933x_wmac";
  68. ath79_wmac_resources[0].start = AR933X_WMAC_BASE;
  69. ath79_wmac_resources[0].end = AR933X_WMAC_BASE + AR933X_WMAC_SIZE - 1;
  70. ath79_wmac_resources[1].start = ATH79_CPU_IRQ(2);
  71. ath79_wmac_resources[1].end = ATH79_CPU_IRQ(2);
  72. t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  73. if (t & AR933X_BOOTSTRAP_REF_CLK_40)
  74. ath79_wmac_data.is_clk_25mhz = false;
  75. else
  76. ath79_wmac_data.is_clk_25mhz = true;
  77. if (ath79_soc_rev == 1)
  78. ath79_wmac_data.get_mac_revision = ar933x_r1_get_wmac_revision;
  79. ath79_wmac_data.external_reset = ar933x_wmac_reset;
  80. }
  81. static void ar934x_wmac_setup(void)
  82. {
  83. u32 t;
  84. ath79_wmac_device.name = "ar934x_wmac";
  85. ath79_wmac_resources[0].start = AR934X_WMAC_BASE;
  86. ath79_wmac_resources[0].end = AR934X_WMAC_BASE + AR934X_WMAC_SIZE - 1;
  87. ath79_wmac_resources[1].start = ATH79_IP2_IRQ(1);
  88. ath79_wmac_resources[1].end = ATH79_IP2_IRQ(1);
  89. t = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP);
  90. if (t & AR934X_BOOTSTRAP_REF_CLK_40)
  91. ath79_wmac_data.is_clk_25mhz = false;
  92. else
  93. ath79_wmac_data.is_clk_25mhz = true;
  94. }
  95. static void qca955x_wmac_setup(void)
  96. {
  97. u32 t;
  98. ath79_wmac_device.name = "qca955x_wmac";
  99. ath79_wmac_resources[0].start = QCA955X_WMAC_BASE;
  100. ath79_wmac_resources[0].end = QCA955X_WMAC_BASE + QCA955X_WMAC_SIZE - 1;
  101. ath79_wmac_resources[1].start = ATH79_IP2_IRQ(1);
  102. ath79_wmac_resources[1].end = ATH79_IP2_IRQ(1);
  103. t = ath79_reset_rr(QCA955X_RESET_REG_BOOTSTRAP);
  104. if (t & QCA955X_BOOTSTRAP_REF_CLK_40)
  105. ath79_wmac_data.is_clk_25mhz = false;
  106. else
  107. ath79_wmac_data.is_clk_25mhz = true;
  108. }
  109. void __init ath79_register_wmac(u8 *cal_data)
  110. {
  111. if (soc_is_ar913x())
  112. ar913x_wmac_setup();
  113. else if (soc_is_ar933x())
  114. ar933x_wmac_setup();
  115. else if (soc_is_ar934x())
  116. ar934x_wmac_setup();
  117. else if (soc_is_qca955x())
  118. qca955x_wmac_setup();
  119. else
  120. BUG();
  121. if (cal_data)
  122. memcpy(ath79_wmac_data.eeprom_data, cal_data,
  123. sizeof(ath79_wmac_data.eeprom_data));
  124. platform_device_register(&ath79_wmac_device);
  125. }