1 /* zd_rf_al2230.c: Functions for the AL2230 RF controller
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.
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.
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
18 #include <linux/kernel.h>
24 static const u32 zd1211_al2230_table[][3] = {
25 RF_CHANNEL( 1) = { 0x03f790, 0x033331, 0x00000d, },
26 RF_CHANNEL( 2) = { 0x03f790, 0x0b3331, 0x00000d, },
27 RF_CHANNEL( 3) = { 0x03e790, 0x033331, 0x00000d, },
28 RF_CHANNEL( 4) = { 0x03e790, 0x0b3331, 0x00000d, },
29 RF_CHANNEL( 5) = { 0x03f7a0, 0x033331, 0x00000d, },
30 RF_CHANNEL( 6) = { 0x03f7a0, 0x0b3331, 0x00000d, },
31 RF_CHANNEL( 7) = { 0x03e7a0, 0x033331, 0x00000d, },
32 RF_CHANNEL( 8) = { 0x03e7a0, 0x0b3331, 0x00000d, },
33 RF_CHANNEL( 9) = { 0x03f7b0, 0x033331, 0x00000d, },
34 RF_CHANNEL(10) = { 0x03f7b0, 0x0b3331, 0x00000d, },
35 RF_CHANNEL(11) = { 0x03e7b0, 0x033331, 0x00000d, },
36 RF_CHANNEL(12) = { 0x03e7b0, 0x0b3331, 0x00000d, },
37 RF_CHANNEL(13) = { 0x03f7c0, 0x033331, 0x00000d, },
38 RF_CHANNEL(14) = { 0x03e7c0, 0x066661, 0x00000d, },
41 static const u32 zd1211b_al2230_table[][3] = {
42 RF_CHANNEL( 1) = { 0x09efc0, 0x8cccc0, 0xb00000, },
43 RF_CHANNEL( 2) = { 0x09efc0, 0x8cccd0, 0xb00000, },
44 RF_CHANNEL( 3) = { 0x09e7c0, 0x8cccc0, 0xb00000, },
45 RF_CHANNEL( 4) = { 0x09e7c0, 0x8cccd0, 0xb00000, },
46 RF_CHANNEL( 5) = { 0x05efc0, 0x8cccc0, 0xb00000, },
47 RF_CHANNEL( 6) = { 0x05efc0, 0x8cccd0, 0xb00000, },
48 RF_CHANNEL( 7) = { 0x05e7c0, 0x8cccc0, 0xb00000, },
49 RF_CHANNEL( 8) = { 0x05e7c0, 0x8cccd0, 0xb00000, },
50 RF_CHANNEL( 9) = { 0x0defc0, 0x8cccc0, 0xb00000, },
51 RF_CHANNEL(10) = { 0x0defc0, 0x8cccd0, 0xb00000, },
52 RF_CHANNEL(11) = { 0x0de7c0, 0x8cccc0, 0xb00000, },
53 RF_CHANNEL(12) = { 0x0de7c0, 0x8cccd0, 0xb00000, },
54 RF_CHANNEL(13) = { 0x03efc0, 0x8cccc0, 0xb00000, },
55 RF_CHANNEL(14) = { 0x03e7c0, 0x866660, 0xb00000, },
58 static const struct zd_ioreq16 zd1211b_ioreqs_shared_1[] = {
59 { CR240, 0x57 }, { CR9, 0xe0 },
62 static const struct zd_ioreq16 ioreqs_init_al2230s[] = {
63 { CR47, 0x1e }, /* MARK_002 */
65 { CR107, 0x2a }, /* MARK_002 */
66 { CR109, 0x13 }, /* MARK_002 */
67 { CR118, 0xf8 }, /* MARK_002 */
68 { CR119, 0x12 }, { CR122, 0xe0 },
69 { CR128, 0x10 }, /* MARK_001 from 0xe->0x10 */
70 { CR129, 0x0e }, /* MARK_001 from 0xd->0x0e */
71 { CR130, 0x10 }, /* MARK_001 from 0xb->0x0d */
74 static int zd1211b_al2230_finalize_rf(struct zd_chip *chip)
77 static const struct zd_ioreq16 ioreqs[] = {
78 { CR80, 0x30 }, { CR81, 0x30 }, { CR79, 0x58 },
79 { CR12, 0xf0 }, { CR77, 0x1b }, { CR78, 0x58 },
86 r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
90 /* related to antenna selection? */
91 if (chip->new_phy_layout) {
92 r = zd_iowrite16_locked(chip, 0xe1, CR9);
97 return zd_iowrite16_locked(chip, 0x06, CR203);
100 static int zd1211_al2230_init_hw(struct zd_rf *rf)
103 struct zd_chip *chip = zd_rf_to_chip(rf);
105 static const struct zd_ioreq16 ioreqs_init[] = {
106 { CR15, 0x20 }, { CR23, 0x40 }, { CR24, 0x20 },
107 { CR26, 0x11 }, { CR28, 0x3e }, { CR29, 0x00 },
108 { CR44, 0x33 }, { CR106, 0x2a }, { CR107, 0x1a },
109 { CR109, 0x09 }, { CR110, 0x27 }, { CR111, 0x2b },
110 { CR112, 0x2b }, { CR119, 0x0a }, { CR10, 0x89 },
111 /* for newest (3rd cut) AL2300 */
113 { CR26, 0x93 }, { CR34, 0x30 },
114 /* for newest (3rd cut) AL2300 */
116 { CR41, 0x24 }, { CR44, 0x32 },
117 /* for newest (3rd cut) AL2300 */
119 { CR47, 0x1e }, { CR79, 0x58 }, { CR80, 0x30 },
120 { CR81, 0x30 }, { CR87, 0x0a }, { CR89, 0x04 },
121 { CR92, 0x0a }, { CR99, 0x28 }, { CR100, 0x00 },
122 { CR101, 0x13 }, { CR102, 0x27 }, { CR106, 0x24 },
123 { CR107, 0x2a }, { CR109, 0x09 }, { CR110, 0x13 },
124 { CR111, 0x1f }, { CR112, 0x1f }, { CR113, 0x27 },
126 /* for newest (3rd cut) AL2300 */
128 { CR116, 0x24 }, { CR117, 0xf4 }, { CR118, 0xfc },
129 { CR119, 0x10 }, { CR120, 0x4f }, { CR121, 0x77 },
130 { CR122, 0xe0 }, { CR137, 0x88 }, { CR252, 0xff },
134 static const struct zd_ioreq16 ioreqs_pll[] = {
135 /* shdnb(PLL_ON)=0 */
137 /* shdnb(PLL_ON)=1 */
139 { CR138, 0x28 }, { CR203, 0x06 },
142 static const u32 rv1[] = {
153 static const u32 rv2[] = {
155 0x0f4dc5, /* fix freq shift, 0x04edc5 */
159 0x0403b9, /* external control TX power (CR31) */
167 static const u32 rv3[] = {
175 r = zd_iowrite16a_locked(chip, ioreqs_init, ARRAY_SIZE(ioreqs_init));
179 if (chip->al2230s_bit) {
180 r = zd_iowrite16a_locked(chip, ioreqs_init_al2230s,
181 ARRAY_SIZE(ioreqs_init_al2230s));
186 r = zd_rfwritev_locked(chip, rv1, ARRAY_SIZE(rv1), RF_RV_BITS);
190 /* improve band edge for AL2230S */
191 if (chip->al2230s_bit)
192 r = zd_rfwrite_locked(chip, 0x000824, RF_RV_BITS);
194 r = zd_rfwrite_locked(chip, 0x0005a4, RF_RV_BITS);
198 r = zd_rfwritev_locked(chip, rv2, ARRAY_SIZE(rv2), RF_RV_BITS);
202 r = zd_iowrite16a_locked(chip, ioreqs_pll, ARRAY_SIZE(ioreqs_pll));
206 r = zd_rfwritev_locked(chip, rv3, ARRAY_SIZE(rv3), RF_RV_BITS);
213 static int zd1211b_al2230_init_hw(struct zd_rf *rf)
216 struct zd_chip *chip = zd_rf_to_chip(rf);
218 static const struct zd_ioreq16 ioreqs1[] = {
219 { CR10, 0x89 }, { CR15, 0x20 },
220 { CR17, 0x2B }, /* for newest(3rd cut) AL2230 */
221 { CR23, 0x40 }, { CR24, 0x20 }, { CR26, 0x93 },
222 { CR28, 0x3e }, { CR29, 0x00 },
223 { CR33, 0x28 }, /* 5621 */
225 { CR35, 0x3e }, /* for newest(3rd cut) AL2230 */
226 { CR41, 0x24 }, { CR44, 0x32 },
227 { CR46, 0x99 }, /* for newest(3rd cut) AL2230 */
230 /* ZD1211B 05.06.10 */
231 { CR48, 0x06 }, { CR49, 0xf9 }, { CR51, 0x01 },
232 { CR52, 0x80 }, { CR53, 0x7e }, { CR65, 0x00 },
233 { CR66, 0x00 }, { CR67, 0x00 }, { CR68, 0x00 },
236 { CR79, 0x58 }, { CR80, 0x30 }, { CR81, 0x30 },
237 { CR87, 0x0a }, { CR89, 0x04 },
238 { CR91, 0x00 }, /* 5621 */
240 { CR98, 0x8d }, /* 4804, for 1212 new algorithm */
241 { CR99, 0x00 }, /* 5621 */
242 { CR101, 0x13 }, { CR102, 0x27 },
243 { CR106, 0x24 }, /* for newest(3rd cut) AL2230 */
245 { CR109, 0x13 }, /* 4804, for 1212 new algorithm */
246 { CR110, 0x1f }, /* 4804, for 1212 new algorithm */
247 { CR111, 0x1f }, { CR112, 0x1f }, { CR113, 0x27 },
249 { CR115, 0x26 }, /* 24->26 at 4902 for newest(3rd cut) AL2230 */
251 { CR117, 0xfa }, /* for 1211b */
252 { CR118, 0xfa }, /* for 1211b */
255 { CR121, 0x6c }, /* for 1211b */
256 { CR122, 0xfc }, /* E0->FC at 4902 */
257 { CR123, 0x57 }, /* 5623 */
258 { CR125, 0xad }, /* 4804, for 1212 new algorithm */
259 { CR126, 0x6c }, /* 5614 */
260 { CR127, 0x03 }, /* 4804, for 1212 new algorithm */
261 { CR137, 0x50 }, /* 5614 */
263 { CR144, 0xac }, /* 5621 */
264 { CR150, 0x0d }, { CR252, 0x34 }, { CR253, 0x34 },
267 static const u32 rv1[] = {
274 static const u32 rv2[] = {
275 /* To improve AL2230 yield, improve phase noise, 4713 */
279 0x6da010, /* Reg6 update for MP versio */
280 0xe36280, /* Modified by jxiao for Bor-Chin on 2004/08/02 */
282 0x9dc020, /* External control TX power (CR31) */
283 0x5ddb00, /* RegA update for MP version */
284 0xd99000, /* RegB update for MP version */
285 0x3ffbd0, /* RegC update for MP version */
286 0xb00000, /* RegD update for MP version */
288 /* improve phase noise and remove phase calibration,4713 */
292 static const struct zd_ioreq16 ioreqs2[] = {
293 { CR251, 0x2f }, /* shdnb(PLL_ON)=0 */
294 { CR251, 0x7f }, /* shdnb(PLL_ON)=1 */
297 static const u32 rv3[] = {
298 /* To improve AL2230 yield, 4713 */
304 static const struct zd_ioreq16 ioreqs3[] = {
305 /* related to 6M band edge patching, happens unconditionally */
306 { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
309 r = zd_iowrite16a_locked(chip, zd1211b_ioreqs_shared_1,
310 ARRAY_SIZE(zd1211b_ioreqs_shared_1));
313 r = zd_iowrite16a_locked(chip, ioreqs1, ARRAY_SIZE(ioreqs1));
317 if (chip->al2230s_bit) {
318 r = zd_iowrite16a_locked(chip, ioreqs_init_al2230s,
319 ARRAY_SIZE(ioreqs_init_al2230s));
324 r = zd_rfwritev_cr_locked(chip, zd1211b_al2230_table[0], 3);
327 r = zd_rfwritev_cr_locked(chip, rv1, ARRAY_SIZE(rv1));
331 if (chip->al2230s_bit)
332 r = zd_rfwrite_locked(chip, 0x241000, RF_RV_BITS);
334 r = zd_rfwrite_locked(chip, 0x25a000, RF_RV_BITS);
338 r = zd_rfwritev_cr_locked(chip, rv2, ARRAY_SIZE(rv2));
341 r = zd_iowrite16a_locked(chip, ioreqs2, ARRAY_SIZE(ioreqs2));
344 r = zd_rfwritev_cr_locked(chip, rv3, ARRAY_SIZE(rv3));
347 r = zd_iowrite16a_locked(chip, ioreqs3, ARRAY_SIZE(ioreqs3));
350 return zd1211b_al2230_finalize_rf(chip);
353 static int zd1211_al2230_set_channel(struct zd_rf *rf, u8 channel)
356 const u32 *rv = zd1211_al2230_table[channel-1];
357 struct zd_chip *chip = zd_rf_to_chip(rf);
358 static const struct zd_ioreq16 ioreqs[] = {
363 r = zd_rfwritev_locked(chip, rv, 3, RF_RV_BITS);
366 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
369 static int zd1211b_al2230_set_channel(struct zd_rf *rf, u8 channel)
372 const u32 *rv = zd1211b_al2230_table[channel-1];
373 struct zd_chip *chip = zd_rf_to_chip(rf);
375 r = zd_iowrite16a_locked(chip, zd1211b_ioreqs_shared_1,
376 ARRAY_SIZE(zd1211b_ioreqs_shared_1));
380 r = zd_rfwritev_cr_locked(chip, rv, 3);
384 return zd1211b_al2230_finalize_rf(chip);
387 static int zd1211_al2230_switch_radio_on(struct zd_rf *rf)
389 struct zd_chip *chip = zd_rf_to_chip(rf);
390 static const struct zd_ioreq16 ioreqs[] = {
395 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
398 static int zd1211b_al2230_switch_radio_on(struct zd_rf *rf)
400 struct zd_chip *chip = zd_rf_to_chip(rf);
401 static const struct zd_ioreq16 ioreqs[] = {
406 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
409 static int al2230_switch_radio_off(struct zd_rf *rf)
411 struct zd_chip *chip = zd_rf_to_chip(rf);
412 static const struct zd_ioreq16 ioreqs[] = {
417 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
420 int zd_rf_init_al2230(struct zd_rf *rf)
422 struct zd_chip *chip = zd_rf_to_chip(rf);
424 rf->switch_radio_off = al2230_switch_radio_off;
425 if (chip->is_zd1211b) {
426 rf->init_hw = zd1211b_al2230_init_hw;
427 rf->set_channel = zd1211b_al2230_set_channel;
428 rf->switch_radio_on = zd1211b_al2230_switch_radio_on;
430 rf->init_hw = zd1211_al2230_init_hw;
431 rf->set_channel = zd1211_al2230_set_channel;
432 rf->switch_radio_on = zd1211_al2230_switch_radio_on;
434 rf->patch_6m_band_edge = zd_rf_generic_patch_6m;