zd_rf.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* zd_rf.c
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/string.h>
  19. #include "zd_def.h"
  20. #include "zd_rf.h"
  21. #include "zd_ieee80211.h"
  22. #include "zd_chip.h"
  23. static const char * const rfs[] = {
  24. [0] = "unknown RF0",
  25. [1] = "unknown RF1",
  26. [UW2451_RF] = "UW2451_RF",
  27. [UCHIP_RF] = "UCHIP_RF",
  28. [AL2230_RF] = "AL2230_RF",
  29. [AL7230B_RF] = "AL7230B_RF",
  30. [THETA_RF] = "THETA_RF",
  31. [AL2210_RF] = "AL2210_RF",
  32. [MAXIM_NEW_RF] = "MAXIM_NEW_RF",
  33. [UW2453_RF] = "UW2453_RF",
  34. [UNKNOWN_A_RF] = "UNKNOWN_A_RF",
  35. [RALINK_RF] = "RALINK_RF",
  36. [INTERSIL_RF] = "INTERSIL_RF",
  37. [RF2959_RF] = "RF2959_RF",
  38. [MAXIM_NEW2_RF] = "MAXIM_NEW2_RF",
  39. [PHILIPS_RF] = "PHILIPS_RF",
  40. };
  41. const char *zd_rf_name(u8 type)
  42. {
  43. if (type & 0xf0)
  44. type = 0;
  45. return rfs[type];
  46. }
  47. void zd_rf_init(struct zd_rf *rf)
  48. {
  49. memset(rf, 0, sizeof(*rf));
  50. }
  51. void zd_rf_clear(struct zd_rf *rf)
  52. {
  53. ZD_MEMCLEAR(rf, sizeof(*rf));
  54. }
  55. int zd_rf_init_hw(struct zd_rf *rf, u8 type)
  56. {
  57. int r, t;
  58. struct zd_chip *chip = zd_rf_to_chip(rf);
  59. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  60. switch (type) {
  61. case RF2959_RF:
  62. r = zd_rf_init_rf2959(rf);
  63. if (r)
  64. return r;
  65. break;
  66. case AL2230_RF:
  67. r = zd_rf_init_al2230(rf);
  68. if (r)
  69. return r;
  70. break;
  71. case AL7230B_RF:
  72. r = zd_rf_init_al7230b(rf);
  73. if (r)
  74. return r;
  75. break;
  76. default:
  77. dev_err(zd_chip_dev(chip),
  78. "RF %s %#x is not supported\n", zd_rf_name(type), type);
  79. rf->type = 0;
  80. return -ENODEV;
  81. }
  82. rf->type = type;
  83. r = zd_chip_lock_phy_regs(chip);
  84. if (r)
  85. return r;
  86. t = rf->init_hw(rf);
  87. r = zd_chip_unlock_phy_regs(chip);
  88. if (t)
  89. r = t;
  90. return r;
  91. }
  92. int zd_rf_scnprint_id(struct zd_rf *rf, char *buffer, size_t size)
  93. {
  94. return scnprintf(buffer, size, "%s", zd_rf_name(rf->type));
  95. }
  96. int zd_rf_set_channel(struct zd_rf *rf, u8 channel)
  97. {
  98. int r;
  99. ZD_ASSERT(mutex_is_locked(&zd_rf_to_chip(rf)->mutex));
  100. if (channel < MIN_CHANNEL24)
  101. return -EINVAL;
  102. if (channel > MAX_CHANNEL24)
  103. return -EINVAL;
  104. dev_dbg_f(zd_chip_dev(zd_rf_to_chip(rf)), "channel: %d\n", channel);
  105. r = rf->set_channel(rf, channel);
  106. if (r >= 0)
  107. rf->channel = channel;
  108. return r;
  109. }
  110. int zd_switch_radio_on(struct zd_rf *rf)
  111. {
  112. int r, t;
  113. struct zd_chip *chip = zd_rf_to_chip(rf);
  114. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  115. r = zd_chip_lock_phy_regs(chip);
  116. if (r)
  117. return r;
  118. t = rf->switch_radio_on(rf);
  119. r = zd_chip_unlock_phy_regs(chip);
  120. if (t)
  121. r = t;
  122. return r;
  123. }
  124. int zd_switch_radio_off(struct zd_rf *rf)
  125. {
  126. int r, t;
  127. struct zd_chip *chip = zd_rf_to_chip(rf);
  128. /* TODO: move phy regs handling to zd_chip */
  129. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  130. r = zd_chip_lock_phy_regs(chip);
  131. if (r)
  132. return r;
  133. t = rf->switch_radio_off(rf);
  134. r = zd_chip_unlock_phy_regs(chip);
  135. if (t)
  136. r = t;
  137. return r;
  138. }
  139. int zd_rf_patch_6m_band_edge(struct zd_rf *rf, u8 channel)
  140. {
  141. if (!rf->patch_6m_band_edge)
  142. return 0;
  143. return rf->patch_6m_band_edge(rf, channel);
  144. }
  145. int zd_rf_generic_patch_6m(struct zd_rf *rf, u8 channel)
  146. {
  147. return zd_chip_generic_patch_6m_band(zd_rf_to_chip(rf), channel);
  148. }