zd_rf_al7230b.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* zd_rf_al7230b.c: Functions for the AL7230B RF controller
  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/kernel.h>
  18. #include "zd_rf.h"
  19. #include "zd_usb.h"
  20. #include "zd_chip.h"
  21. static const u32 chan_rv[][2] = {
  22. RF_CHANNEL( 1) = { 0x09ec00, 0x8cccc8 },
  23. RF_CHANNEL( 2) = { 0x09ec00, 0x8cccd8 },
  24. RF_CHANNEL( 3) = { 0x09ec00, 0x8cccc0 },
  25. RF_CHANNEL( 4) = { 0x09ec00, 0x8cccd0 },
  26. RF_CHANNEL( 5) = { 0x05ec00, 0x8cccc8 },
  27. RF_CHANNEL( 6) = { 0x05ec00, 0x8cccd8 },
  28. RF_CHANNEL( 7) = { 0x05ec00, 0x8cccc0 },
  29. RF_CHANNEL( 8) = { 0x05ec00, 0x8cccd0 },
  30. RF_CHANNEL( 9) = { 0x0dec00, 0x8cccc8 },
  31. RF_CHANNEL(10) = { 0x0dec00, 0x8cccd8 },
  32. RF_CHANNEL(11) = { 0x0dec00, 0x8cccc0 },
  33. RF_CHANNEL(12) = { 0x0dec00, 0x8cccd0 },
  34. RF_CHANNEL(13) = { 0x03ec00, 0x8cccc8 },
  35. RF_CHANNEL(14) = { 0x03ec00, 0x866660 },
  36. };
  37. static const u32 std_rv[] = {
  38. 0x4ff821,
  39. 0xc5fbfc,
  40. 0x21ebfe,
  41. 0xafd401, /* freq shift 0xaad401 */
  42. 0x6cf56a,
  43. 0xe04073,
  44. 0x193d76,
  45. 0x9dd844,
  46. 0x500007,
  47. 0xd8c010,
  48. };
  49. static int al7230b_init_hw(struct zd_rf *rf)
  50. {
  51. int i, r;
  52. struct zd_chip *chip = zd_rf_to_chip(rf);
  53. /* All of these writes are identical to AL2230 unless otherwise
  54. * specified */
  55. static const struct zd_ioreq16 ioreqs_1[] = {
  56. /* This one is 7230-specific, and happens before the rest */
  57. { CR240, 0x57 },
  58. { },
  59. { CR15, 0x20 }, { CR23, 0x40 }, { CR24, 0x20 },
  60. { CR26, 0x11 }, { CR28, 0x3e }, { CR29, 0x00 },
  61. { CR44, 0x33 },
  62. /* This value is different for 7230 (was: 0x2a) */
  63. { CR106, 0x22 },
  64. { CR107, 0x1a }, { CR109, 0x09 }, { CR110, 0x27 },
  65. { CR111, 0x2b }, { CR112, 0x2b }, { CR119, 0x0a },
  66. /* This happened further down in AL2230,
  67. * and the value changed (was: 0xe0) */
  68. { CR122, 0xfc },
  69. { CR10, 0x89 },
  70. /* for newest (3rd cut) AL2300 */
  71. { CR17, 0x28 },
  72. { CR26, 0x93 }, { CR34, 0x30 },
  73. /* for newest (3rd cut) AL2300 */
  74. { CR35, 0x3e },
  75. { CR41, 0x24 }, { CR44, 0x32 },
  76. /* for newest (3rd cut) AL2300 */
  77. { CR46, 0x96 },
  78. { CR47, 0x1e }, { CR79, 0x58 }, { CR80, 0x30 },
  79. { CR81, 0x30 }, { CR87, 0x0a }, { CR89, 0x04 },
  80. { CR92, 0x0a }, { CR99, 0x28 },
  81. /* This value is different for 7230 (was: 0x00) */
  82. { CR100, 0x02 },
  83. { CR101, 0x13 }, { CR102, 0x27 },
  84. /* This value is different for 7230 (was: 0x24) */
  85. { CR106, 0x22 },
  86. /* This value is different for 7230 (was: 0x2a) */
  87. { CR107, 0x3f },
  88. { CR109, 0x09 },
  89. /* This value is different for 7230 (was: 0x13) */
  90. { CR110, 0x1f },
  91. { CR111, 0x1f }, { CR112, 0x1f }, { CR113, 0x27 },
  92. { CR114, 0x27 },
  93. /* for newest (3rd cut) AL2300 */
  94. { CR115, 0x24 },
  95. /* This value is different for 7230 (was: 0x24) */
  96. { CR116, 0x3f },
  97. /* This value is different for 7230 (was: 0xf4) */
  98. { CR117, 0xfa },
  99. { CR118, 0xfc }, { CR119, 0x10 }, { CR120, 0x4f },
  100. { CR121, 0x77 }, { CR137, 0x88 },
  101. /* This one is 7230-specific */
  102. { CR138, 0xa8 },
  103. /* This value is different for 7230 (was: 0xff) */
  104. { CR252, 0x34 },
  105. /* This value is different for 7230 (was: 0xff) */
  106. { CR253, 0x34 },
  107. /* PLL_OFF */
  108. { CR251, 0x2f },
  109. };
  110. static const struct zd_ioreq16 ioreqs_2[] = {
  111. /* PLL_ON */
  112. { CR251, 0x3f },
  113. { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
  114. { CR38, 0x38 }, { CR136, 0xdf },
  115. };
  116. r = zd_iowrite16a_locked(chip, ioreqs_1, ARRAY_SIZE(ioreqs_1));
  117. if (r)
  118. return r;
  119. r = zd_rfwrite_cr_locked(chip, 0x09ec04);
  120. if (r)
  121. return r;
  122. r = zd_rfwrite_cr_locked(chip, 0x8cccc8);
  123. if (r)
  124. return r;
  125. for (i = 0; i < ARRAY_SIZE(std_rv); i++) {
  126. r = zd_rfwrite_cr_locked(chip, std_rv[i]);
  127. if (r)
  128. return r;
  129. }
  130. r = zd_rfwrite_cr_locked(chip, 0x3c9000);
  131. if (r)
  132. return r;
  133. r = zd_rfwrite_cr_locked(chip, 0xbfffff);
  134. if (r)
  135. return r;
  136. r = zd_rfwrite_cr_locked(chip, 0x700000);
  137. if (r)
  138. return r;
  139. r = zd_rfwrite_cr_locked(chip, 0xf15d58);
  140. if (r)
  141. return r;
  142. r = zd_iowrite16a_locked(chip, ioreqs_2, ARRAY_SIZE(ioreqs_2));
  143. if (r)
  144. return r;
  145. r = zd_rfwrite_cr_locked(chip, 0xf15d59);
  146. if (r)
  147. return r;
  148. r = zd_rfwrite_cr_locked(chip, 0xf15d5c);
  149. if (r)
  150. return r;
  151. r = zd_rfwrite_cr_locked(chip, 0xf15d58);
  152. if (r)
  153. return r;
  154. r = zd_iowrite16_locked(chip, 0x06, CR203);
  155. if (r)
  156. return r;
  157. r = zd_iowrite16_locked(chip, 0x80, CR240);
  158. if (r)
  159. return r;
  160. return 0;
  161. }
  162. static int al7230b_set_channel(struct zd_rf *rf, u8 channel)
  163. {
  164. int i, r;
  165. const u32 *rv = chan_rv[channel-1];
  166. struct zd_chip *chip = zd_rf_to_chip(rf);
  167. struct zd_ioreq16 ioreqs_1[] = {
  168. { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
  169. { CR38, 0x38 }, { CR136, 0xdf },
  170. };
  171. struct zd_ioreq16 ioreqs_2[] = {
  172. /* PLL_ON */
  173. { CR251, 0x3f },
  174. { CR203, 0x06 }, { CR240, 0x08 },
  175. };
  176. r = zd_iowrite16_locked(chip, 0x57, CR240);
  177. if (r)
  178. return r;
  179. /* PLL_OFF */
  180. r = zd_iowrite16_locked(chip, 0x2f, CR251);
  181. if (r)
  182. return r;
  183. for (i = 0; i < ARRAY_SIZE(std_rv); i++) {
  184. r = zd_rfwrite_cr_locked(chip, std_rv[i]);
  185. if (r)
  186. return r;
  187. }
  188. r = zd_rfwrite_cr_locked(chip, 0x3c9000);
  189. if (r)
  190. return r;
  191. r = zd_rfwrite_cr_locked(chip, 0xf15d58);
  192. if (r)
  193. return r;
  194. r = zd_iowrite16a_locked(chip, ioreqs_1, ARRAY_SIZE(ioreqs_1));
  195. if (r)
  196. return r;
  197. for (i = 0; i < 2; i++) {
  198. r = zd_rfwrite_cr_locked(chip, rv[i]);
  199. if (r)
  200. return r;
  201. }
  202. r = zd_rfwrite_cr_locked(chip, 0x3c9000);
  203. if (r)
  204. return r;
  205. return zd_iowrite16a_locked(chip, ioreqs_2, ARRAY_SIZE(ioreqs_2));
  206. }
  207. static int al7230b_switch_radio_on(struct zd_rf *rf)
  208. {
  209. struct zd_chip *chip = zd_rf_to_chip(rf);
  210. static const struct zd_ioreq16 ioreqs[] = {
  211. { CR11, 0x00 },
  212. { CR251, 0x3f },
  213. };
  214. return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  215. }
  216. static int al7230b_switch_radio_off(struct zd_rf *rf)
  217. {
  218. struct zd_chip *chip = zd_rf_to_chip(rf);
  219. static const struct zd_ioreq16 ioreqs[] = {
  220. { CR11, 0x04 },
  221. { CR251, 0x2f },
  222. };
  223. return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  224. }
  225. int zd_rf_init_al7230b(struct zd_rf *rf)
  226. {
  227. struct zd_chip *chip = zd_rf_to_chip(rf);
  228. if (chip->is_zd1211b) {
  229. dev_err(zd_chip_dev(chip), "AL7230B is currently not "
  230. "supported for ZD1211B devices\n");
  231. return -ENODEV;
  232. }
  233. rf->init_hw = al7230b_init_hw;
  234. rf->set_channel = al7230b_set_channel;
  235. rf->switch_radio_on = al7230b_switch_radio_on;
  236. rf->switch_radio_off = al7230b_switch_radio_off;
  237. rf->patch_6m_band_edge = 1;
  238. return 0;
  239. }