zd_rf.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. [AL2230S_RF] = "AL2230S_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. /* default to update channel integration, as almost all RF's do want
  51. * this */
  52. rf->update_channel_int = 1;
  53. }
  54. void zd_rf_clear(struct zd_rf *rf)
  55. {
  56. if (rf->clear)
  57. rf->clear(rf);
  58. ZD_MEMCLEAR(rf, sizeof(*rf));
  59. }
  60. int zd_rf_init_hw(struct zd_rf *rf, u8 type)
  61. {
  62. int r = 0;
  63. int t;
  64. struct zd_chip *chip = zd_rf_to_chip(rf);
  65. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  66. switch (type) {
  67. case RF2959_RF:
  68. r = zd_rf_init_rf2959(rf);
  69. break;
  70. case AL2230_RF:
  71. case AL2230S_RF:
  72. r = zd_rf_init_al2230(rf);
  73. break;
  74. case AL7230B_RF:
  75. r = zd_rf_init_al7230b(rf);
  76. break;
  77. case UW2453_RF:
  78. r = zd_rf_init_uw2453(rf);
  79. break;
  80. default:
  81. dev_err(zd_chip_dev(chip),
  82. "RF %s %#x is not supported\n", zd_rf_name(type), type);
  83. rf->type = 0;
  84. return -ENODEV;
  85. }
  86. if (r)
  87. return r;
  88. rf->type = type;
  89. r = zd_chip_lock_phy_regs(chip);
  90. if (r)
  91. return r;
  92. t = rf->init_hw(rf);
  93. r = zd_chip_unlock_phy_regs(chip);
  94. if (t)
  95. r = t;
  96. return r;
  97. }
  98. int zd_rf_scnprint_id(struct zd_rf *rf, char *buffer, size_t size)
  99. {
  100. return scnprintf(buffer, size, "%s", zd_rf_name(rf->type));
  101. }
  102. int zd_rf_set_channel(struct zd_rf *rf, u8 channel)
  103. {
  104. int r;
  105. ZD_ASSERT(mutex_is_locked(&zd_rf_to_chip(rf)->mutex));
  106. if (channel < MIN_CHANNEL24)
  107. return -EINVAL;
  108. if (channel > MAX_CHANNEL24)
  109. return -EINVAL;
  110. dev_dbg_f(zd_chip_dev(zd_rf_to_chip(rf)), "channel: %d\n", channel);
  111. r = rf->set_channel(rf, channel);
  112. if (r >= 0)
  113. rf->channel = channel;
  114. return r;
  115. }
  116. int zd_switch_radio_on(struct zd_rf *rf)
  117. {
  118. int r, t;
  119. struct zd_chip *chip = zd_rf_to_chip(rf);
  120. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  121. r = zd_chip_lock_phy_regs(chip);
  122. if (r)
  123. return r;
  124. t = rf->switch_radio_on(rf);
  125. r = zd_chip_unlock_phy_regs(chip);
  126. if (t)
  127. r = t;
  128. return r;
  129. }
  130. int zd_switch_radio_off(struct zd_rf *rf)
  131. {
  132. int r, t;
  133. struct zd_chip *chip = zd_rf_to_chip(rf);
  134. /* TODO: move phy regs handling to zd_chip */
  135. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  136. r = zd_chip_lock_phy_regs(chip);
  137. if (r)
  138. return r;
  139. t = rf->switch_radio_off(rf);
  140. r = zd_chip_unlock_phy_regs(chip);
  141. if (t)
  142. r = t;
  143. return r;
  144. }
  145. int zd_rf_patch_6m_band_edge(struct zd_rf *rf, u8 channel)
  146. {
  147. if (!rf->patch_6m_band_edge)
  148. return 0;
  149. return rf->patch_6m_band_edge(rf, channel);
  150. }
  151. int zd_rf_generic_patch_6m(struct zd_rf *rf, u8 channel)
  152. {
  153. return zd_chip_generic_patch_6m_band(zd_rf_to_chip(rf), channel);
  154. }