zd_rf.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 UW2453_RF:
  81. r = zd_rf_init_uw2453(rf);
  82. break;
  83. default:
  84. dev_err(zd_chip_dev(chip),
  85. "RF %s %#x is not supported\n", zd_rf_name(type), type);
  86. rf->type = 0;
  87. return -ENODEV;
  88. }
  89. if (r)
  90. return r;
  91. rf->type = type;
  92. r = zd_chip_lock_phy_regs(chip);
  93. if (r)
  94. return r;
  95. t = rf->init_hw(rf);
  96. r = zd_chip_unlock_phy_regs(chip);
  97. if (t)
  98. r = t;
  99. return r;
  100. }
  101. int zd_rf_scnprint_id(struct zd_rf *rf, char *buffer, size_t size)
  102. {
  103. return scnprintf(buffer, size, "%s", zd_rf_name(rf->type));
  104. }
  105. int zd_rf_set_channel(struct zd_rf *rf, u8 channel)
  106. {
  107. int r;
  108. ZD_ASSERT(mutex_is_locked(&zd_rf_to_chip(rf)->mutex));
  109. if (channel < MIN_CHANNEL24)
  110. return -EINVAL;
  111. if (channel > MAX_CHANNEL24)
  112. return -EINVAL;
  113. dev_dbg_f(zd_chip_dev(zd_rf_to_chip(rf)), "channel: %d\n", channel);
  114. r = rf->set_channel(rf, channel);
  115. if (r >= 0)
  116. rf->channel = channel;
  117. return r;
  118. }
  119. int zd_switch_radio_on(struct zd_rf *rf)
  120. {
  121. int r, t;
  122. struct zd_chip *chip = zd_rf_to_chip(rf);
  123. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  124. r = zd_chip_lock_phy_regs(chip);
  125. if (r)
  126. return r;
  127. t = rf->switch_radio_on(rf);
  128. r = zd_chip_unlock_phy_regs(chip);
  129. if (t)
  130. r = t;
  131. return r;
  132. }
  133. int zd_switch_radio_off(struct zd_rf *rf)
  134. {
  135. int r, t;
  136. struct zd_chip *chip = zd_rf_to_chip(rf);
  137. /* TODO: move phy regs handling to zd_chip */
  138. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  139. r = zd_chip_lock_phy_regs(chip);
  140. if (r)
  141. return r;
  142. t = rf->switch_radio_off(rf);
  143. r = zd_chip_unlock_phy_regs(chip);
  144. if (t)
  145. r = t;
  146. return r;
  147. }
  148. int zd_rf_patch_6m_band_edge(struct zd_rf *rf, u8 channel)
  149. {
  150. if (!rf->patch_6m_band_edge)
  151. return 0;
  152. return rf->patch_6m_band_edge(rf, channel);
  153. }
  154. int zd_rf_generic_patch_6m(struct zd_rf *rf, u8 channel)
  155. {
  156. return zd_chip_generic_patch_6m_band(zd_rf_to_chip(rf), channel);
  157. }