1 /* ZD1211 USB-WLAN driver for Linux
3 * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
4 * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
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.
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.
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
21 #include <linux/kernel.h>
27 static const u32 chan_rv[][2] = {
28 RF_CHANNEL( 1) = { 0x09ec00, 0x8cccc8 },
29 RF_CHANNEL( 2) = { 0x09ec00, 0x8cccd8 },
30 RF_CHANNEL( 3) = { 0x09ec00, 0x8cccc0 },
31 RF_CHANNEL( 4) = { 0x09ec00, 0x8cccd0 },
32 RF_CHANNEL( 5) = { 0x05ec00, 0x8cccc8 },
33 RF_CHANNEL( 6) = { 0x05ec00, 0x8cccd8 },
34 RF_CHANNEL( 7) = { 0x05ec00, 0x8cccc0 },
35 RF_CHANNEL( 8) = { 0x05ec00, 0x8cccd0 },
36 RF_CHANNEL( 9) = { 0x0dec00, 0x8cccc8 },
37 RF_CHANNEL(10) = { 0x0dec00, 0x8cccd8 },
38 RF_CHANNEL(11) = { 0x0dec00, 0x8cccc0 },
39 RF_CHANNEL(12) = { 0x0dec00, 0x8cccd0 },
40 RF_CHANNEL(13) = { 0x03ec00, 0x8cccc8 },
41 RF_CHANNEL(14) = { 0x03ec00, 0x866660 },
44 static const u32 std_rv[] = {
48 0xafd401, /* freq shift 0xaad401 */
57 static const u32 rv_init1[] = {
64 static const u32 rv_init2[] = {
70 static const struct zd_ioreq16 ioreqs_sw[] = {
71 { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
72 { CR38, 0x38 }, { CR136, 0xdf },
75 static int zd1211b_al7230b_finalize(struct zd_chip *chip)
78 static const struct zd_ioreq16 ioreqs[] = {
79 { CR80, 0x30 }, { CR81, 0x30 }, { CR79, 0x58 },
80 { CR12, 0xf0 }, { CR77, 0x1b }, { CR78, 0x58 },
86 r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
90 if (chip->new_phy_layout) {
91 /* antenna selection? */
92 r = zd_iowrite16_locked(chip, 0xe5, CR9);
97 return zd_iowrite16_locked(chip, 0x04, CR203);
100 static int zd1211_al7230b_init_hw(struct zd_rf *rf)
103 struct zd_chip *chip = zd_rf_to_chip(rf);
105 /* All of these writes are identical to AL2230 unless otherwise
107 static const struct zd_ioreq16 ioreqs_1[] = {
108 /* This one is 7230-specific, and happens before the rest */
112 { CR15, 0x20 }, { CR23, 0x40 }, { CR24, 0x20 },
113 { CR26, 0x11 }, { CR28, 0x3e }, { CR29, 0x00 },
115 /* This value is different for 7230 (was: 0x2a) */
117 { CR107, 0x1a }, { CR109, 0x09 }, { CR110, 0x27 },
118 { CR111, 0x2b }, { CR112, 0x2b }, { CR119, 0x0a },
119 /* This happened further down in AL2230,
120 * and the value changed (was: 0xe0) */
123 /* for newest (3rd cut) AL2300 */
125 { CR26, 0x93 }, { CR34, 0x30 },
126 /* for newest (3rd cut) AL2300 */
128 { CR41, 0x24 }, { CR44, 0x32 },
129 /* for newest (3rd cut) AL2300 */
131 { CR47, 0x1e }, { CR79, 0x58 }, { CR80, 0x30 },
132 { CR81, 0x30 }, { CR87, 0x0a }, { CR89, 0x04 },
133 { CR92, 0x0a }, { CR99, 0x28 },
134 /* This value is different for 7230 (was: 0x00) */
136 { CR101, 0x13 }, { CR102, 0x27 },
137 /* This value is different for 7230 (was: 0x24) */
139 /* This value is different for 7230 (was: 0x2a) */
142 /* This value is different for 7230 (was: 0x13) */
144 { CR111, 0x1f }, { CR112, 0x1f }, { CR113, 0x27 },
146 /* for newest (3rd cut) AL2300 */
148 /* This value is different for 7230 (was: 0x24) */
150 /* This value is different for 7230 (was: 0xf4) */
152 { CR118, 0xfc }, { CR119, 0x10 }, { CR120, 0x4f },
153 { CR121, 0x77 }, { CR137, 0x88 },
154 /* This one is 7230-specific */
156 /* This value is different for 7230 (was: 0xff) */
158 /* This value is different for 7230 (was: 0xff) */
165 static const struct zd_ioreq16 ioreqs_2[] = {
166 { CR251, 0x3f }, /* PLL_ON */
167 { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
168 { CR38, 0x38 }, { CR136, 0xdf },
171 r = zd_iowrite16a_locked(chip, ioreqs_1, ARRAY_SIZE(ioreqs_1));
175 r = zd_rfwritev_cr_locked(chip, chan_rv[0], ARRAY_SIZE(chan_rv[0]));
179 r = zd_rfwritev_cr_locked(chip, std_rv, ARRAY_SIZE(std_rv));
183 r = zd_rfwritev_cr_locked(chip, rv_init1, ARRAY_SIZE(rv_init1));
187 r = zd_iowrite16a_locked(chip, ioreqs_2, ARRAY_SIZE(ioreqs_2));
191 r = zd_rfwritev_cr_locked(chip, rv_init2, ARRAY_SIZE(rv_init2));
195 r = zd_iowrite16_locked(chip, 0x06, CR203);
198 r = zd_iowrite16_locked(chip, 0x80, CR240);
205 static int zd1211b_al7230b_init_hw(struct zd_rf *rf)
208 struct zd_chip *chip = zd_rf_to_chip(rf);
210 static const struct zd_ioreq16 ioreqs_1[] = {
211 { CR240, 0x57 }, { CR9, 0x9 },
213 { CR10, 0x8b }, { CR15, 0x20 },
214 { CR17, 0x2B }, /* for newest (3rd cut) AL2230 */
215 { CR20, 0x10 }, /* 4N25->Stone Request */
216 { CR23, 0x40 }, { CR24, 0x20 }, { CR26, 0x93 },
217 { CR28, 0x3e }, { CR29, 0x00 },
218 { CR33, 0x28 }, /* 5613 */
220 { CR35, 0x3e }, /* for newest (3rd cut) AL2230 */
221 { CR41, 0x24 }, { CR44, 0x32 },
222 { CR46, 0x99 }, /* for newest (3rd cut) AL2230 */
226 { CR48, 0x00 }, { CR49, 0x00 }, { CR51, 0x01 },
227 { CR52, 0x80 }, { CR53, 0x7e }, { CR65, 0x00 },
228 { CR66, 0x00 }, { CR67, 0x00 }, { CR68, 0x00 },
231 { CR79, 0x58 }, { CR80, 0x30 }, { CR81, 0x30 },
232 { CR87, 0x0A }, { CR89, 0x04 },
233 { CR90, 0x58 }, /* 5112 */
234 { CR91, 0x00 }, /* 5613 */
236 { CR98, 0x8d }, /* 4804, for 1212 new algorithm */
237 { CR99, 0x00 }, { CR100, 0x02 }, { CR101, 0x13 },
239 { CR106, 0x20 }, /* change to 0x24 for AL7230B */
240 { CR109, 0x13 }, /* 4804, for 1212 new algorithm */
244 static const struct zd_ioreq16 ioreqs_new_phy[] = {
246 { CR110, 0x1f }, /* 5127, 0x13->0x1f */
247 { CR111, 0x1f }, /* 0x13 to 0x1f for AL7230B */
248 { CR116, 0x2a }, { CR118, 0xfa }, { CR119, 0x12 },
249 { CR121, 0x6c }, /* 5613 */
252 static const struct zd_ioreq16 ioreqs_old_phy[] = {
254 { CR110, 0x13 }, /* 5127, 0x13->0x1f */
255 { CR111, 0x13 }, /* 0x13 to 0x1f for AL7230B */
256 { CR116, 0x24 }, { CR118, 0xfc }, { CR119, 0x11 },
257 { CR121, 0x6a }, /* 5613 */
260 static const struct zd_ioreq16 ioreqs_2[] = {
261 { CR113, 0x27 }, { CR114, 0x27 }, { CR115, 0x24 },
262 { CR117, 0xfa }, { CR120, 0x4f },
263 { CR122, 0xfc }, /* E0->FCh at 4901 */
264 { CR123, 0x57 }, /* 5613 */
265 { CR125, 0xad }, /* 4804, for 1212 new algorithm */
266 { CR126, 0x6c }, /* 5613 */
267 { CR127, 0x03 }, /* 4804, for 1212 new algorithm */
269 { CR131, 0x00 }, /* 5112 */
270 { CR137, 0x50 }, /* 5613 */
271 { CR138, 0xa8 }, /* 5112 */
272 { CR144, 0xac }, /* 5613 */
273 { CR148, 0x40 }, /* 5112 */
274 { CR149, 0x40 }, /* 4O07, 50->40 */
275 { CR150, 0x1a }, /* 5112, 0C->1A */
276 { CR252, 0x34 }, { CR253, 0x34 },
277 { CR251, 0x2f }, /* PLL_OFF */
280 static const struct zd_ioreq16 ioreqs_3[] = {
281 { CR251, 0x7f }, /* PLL_ON */
282 { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
283 { CR38, 0x38 }, { CR136, 0xdf },
286 r = zd_iowrite16a_locked(chip, ioreqs_1, ARRAY_SIZE(ioreqs_1));
290 if (chip->new_phy_layout)
291 r = zd_iowrite16a_locked(chip, ioreqs_new_phy,
292 ARRAY_SIZE(ioreqs_new_phy));
294 r = zd_iowrite16a_locked(chip, ioreqs_old_phy,
295 ARRAY_SIZE(ioreqs_old_phy));
299 r = zd_iowrite16a_locked(chip, ioreqs_2, ARRAY_SIZE(ioreqs_2));
303 r = zd_rfwritev_cr_locked(chip, chan_rv[0], ARRAY_SIZE(chan_rv[0]));
307 r = zd_rfwritev_cr_locked(chip, std_rv, ARRAY_SIZE(std_rv));
311 r = zd_rfwritev_cr_locked(chip, rv_init1, ARRAY_SIZE(rv_init1));
315 r = zd_iowrite16a_locked(chip, ioreqs_3, ARRAY_SIZE(ioreqs_3));
319 r = zd_rfwritev_cr_locked(chip, rv_init2, ARRAY_SIZE(rv_init2));
323 return zd1211b_al7230b_finalize(chip);
326 static int zd1211_al7230b_set_channel(struct zd_rf *rf, u8 channel)
329 const u32 *rv = chan_rv[channel-1];
330 struct zd_chip *chip = zd_rf_to_chip(rf);
332 static const struct zd_ioreq16 ioreqs[] = {
335 { CR203, 0x06 }, { CR240, 0x08 },
338 r = zd_iowrite16_locked(chip, 0x57, CR240);
343 r = zd_iowrite16_locked(chip, 0x2f, CR251);
347 r = zd_rfwritev_cr_locked(chip, std_rv, ARRAY_SIZE(std_rv));
351 r = zd_rfwrite_cr_locked(chip, 0x3c9000);
354 r = zd_rfwrite_cr_locked(chip, 0xf15d58);
358 r = zd_iowrite16a_locked(chip, ioreqs_sw, ARRAY_SIZE(ioreqs_sw));
362 r = zd_rfwritev_cr_locked(chip, rv, 2);
366 r = zd_rfwrite_cr_locked(chip, 0x3c9000);
370 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
373 static int zd1211b_al7230b_set_channel(struct zd_rf *rf, u8 channel)
376 const u32 *rv = chan_rv[channel-1];
377 struct zd_chip *chip = zd_rf_to_chip(rf);
379 r = zd_iowrite16_locked(chip, 0x57, CR240);
382 r = zd_iowrite16_locked(chip, 0xe4, CR9);
387 r = zd_iowrite16_locked(chip, 0x2f, CR251);
390 r = zd_rfwritev_cr_locked(chip, std_rv, ARRAY_SIZE(std_rv));
394 r = zd_rfwrite_cr_locked(chip, 0x3c9000);
397 r = zd_rfwrite_cr_locked(chip, 0xf15d58);
401 r = zd_iowrite16a_locked(chip, ioreqs_sw, ARRAY_SIZE(ioreqs_sw));
405 r = zd_rfwritev_cr_locked(chip, rv, 2);
409 r = zd_rfwrite_cr_locked(chip, 0x3c9000);
413 r = zd_iowrite16_locked(chip, 0x7f, CR251);
417 return zd1211b_al7230b_finalize(chip);
420 static int zd1211_al7230b_switch_radio_on(struct zd_rf *rf)
422 struct zd_chip *chip = zd_rf_to_chip(rf);
423 static const struct zd_ioreq16 ioreqs[] = {
428 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
431 static int zd1211b_al7230b_switch_radio_on(struct zd_rf *rf)
433 struct zd_chip *chip = zd_rf_to_chip(rf);
434 static const struct zd_ioreq16 ioreqs[] = {
439 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
442 static int al7230b_switch_radio_off(struct zd_rf *rf)
444 struct zd_chip *chip = zd_rf_to_chip(rf);
445 static const struct zd_ioreq16 ioreqs[] = {
450 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
453 /* ZD1211B+AL7230B 6m band edge patching differs slightly from other
455 static int zd1211b_al7230b_patch_6m(struct zd_rf *rf, u8 channel)
457 struct zd_chip *chip = zd_rf_to_chip(rf);
458 struct zd_ioreq16 ioreqs[] = {
459 { CR128, 0x14 }, { CR129, 0x12 },
462 /* FIXME: Channel 11 is not the edge for all regulatory domains. */
464 ioreqs[0].value = 0x0e;
465 ioreqs[1].value = 0x10;
466 } else if (channel == 11) {
467 ioreqs[0].value = 0x10;
468 ioreqs[1].value = 0x10;
471 dev_dbg_f(zd_chip_dev(chip), "patching for channel %d\n", channel);
472 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
475 int zd_rf_init_al7230b(struct zd_rf *rf)
477 struct zd_chip *chip = zd_rf_to_chip(rf);
479 if (zd_chip_is_zd1211b(chip)) {
480 rf->init_hw = zd1211b_al7230b_init_hw;
481 rf->switch_radio_on = zd1211b_al7230b_switch_radio_on;
482 rf->set_channel = zd1211b_al7230b_set_channel;
483 rf->patch_6m_band_edge = zd1211b_al7230b_patch_6m;
485 rf->init_hw = zd1211_al7230b_init_hw;
486 rf->switch_radio_on = zd1211_al7230b_switch_radio_on;
487 rf->set_channel = zd1211_al7230b_set_channel;
488 rf->patch_6m_band_edge = zd_rf_generic_patch_6m;
489 rf->patch_cck_gain = 1;
492 rf->switch_radio_off = al7230b_switch_radio_off;