zd_rf.c 4.0 KB

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