zd_rf_al2230.c 12.1 KB
Newer Older
D
Daniel Drake 已提交
1 2 3 4
/* ZD1211 USB-WLAN driver for Linux
 *
 * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
 * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <linux/kernel.h>

#include "zd_rf.h"
#include "zd_usb.h"
#include "zd_chip.h"

27 28
#define IS_AL2230S(chip) ((chip)->al2230s_bit || (chip)->rf.type == AL2230S_RF)

29
static const u32 zd1211_al2230_table[][3] = {
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
	RF_CHANNEL( 1) = { 0x03f790, 0x033331, 0x00000d, },
	RF_CHANNEL( 2) = { 0x03f790, 0x0b3331, 0x00000d, },
	RF_CHANNEL( 3) = { 0x03e790, 0x033331, 0x00000d, },
	RF_CHANNEL( 4) = { 0x03e790, 0x0b3331, 0x00000d, },
	RF_CHANNEL( 5) = { 0x03f7a0, 0x033331, 0x00000d, },
	RF_CHANNEL( 6) = { 0x03f7a0, 0x0b3331, 0x00000d, },
	RF_CHANNEL( 7) = { 0x03e7a0, 0x033331, 0x00000d, },
	RF_CHANNEL( 8) = { 0x03e7a0, 0x0b3331, 0x00000d, },
	RF_CHANNEL( 9) = { 0x03f7b0, 0x033331, 0x00000d, },
	RF_CHANNEL(10) = { 0x03f7b0, 0x0b3331, 0x00000d, },
	RF_CHANNEL(11) = { 0x03e7b0, 0x033331, 0x00000d, },
	RF_CHANNEL(12) = { 0x03e7b0, 0x0b3331, 0x00000d, },
	RF_CHANNEL(13) = { 0x03f7c0, 0x033331, 0x00000d, },
	RF_CHANNEL(14) = { 0x03e7c0, 0x066661, 0x00000d, },
};

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
static const u32 zd1211b_al2230_table[][3] = {
	RF_CHANNEL( 1) = { 0x09efc0, 0x8cccc0, 0xb00000, },
	RF_CHANNEL( 2) = { 0x09efc0, 0x8cccd0, 0xb00000, },
	RF_CHANNEL( 3) = { 0x09e7c0, 0x8cccc0, 0xb00000, },
	RF_CHANNEL( 4) = { 0x09e7c0, 0x8cccd0, 0xb00000, },
	RF_CHANNEL( 5) = { 0x05efc0, 0x8cccc0, 0xb00000, },
	RF_CHANNEL( 6) = { 0x05efc0, 0x8cccd0, 0xb00000, },
	RF_CHANNEL( 7) = { 0x05e7c0, 0x8cccc0, 0xb00000, },
	RF_CHANNEL( 8) = { 0x05e7c0, 0x8cccd0, 0xb00000, },
	RF_CHANNEL( 9) = { 0x0defc0, 0x8cccc0, 0xb00000, },
	RF_CHANNEL(10) = { 0x0defc0, 0x8cccd0, 0xb00000, },
	RF_CHANNEL(11) = { 0x0de7c0, 0x8cccc0, 0xb00000, },
	RF_CHANNEL(12) = { 0x0de7c0, 0x8cccd0, 0xb00000, },
	RF_CHANNEL(13) = { 0x03efc0, 0x8cccc0, 0xb00000, },
	RF_CHANNEL(14) = { 0x03e7c0, 0x866660, 0xb00000, },
};

static const struct zd_ioreq16 zd1211b_ioreqs_shared_1[] = {
	{ CR240, 0x57 }, { CR9,   0xe0 },
};

67 68 69 70 71 72 73 74 75 76 77 78
static const struct zd_ioreq16 ioreqs_init_al2230s[] = {
	{ CR47,   0x1e }, /* MARK_002 */
	{ CR106,  0x22 },
	{ CR107,  0x2a }, /* MARK_002 */
	{ CR109,  0x13 }, /* MARK_002 */
	{ CR118,  0xf8 }, /* MARK_002 */
	{ CR119,  0x12 }, { CR122,  0xe0 },
	{ CR128,  0x10 }, /* MARK_001 from 0xe->0x10 */
	{ CR129,  0x0e }, /* MARK_001 from 0xd->0x0e */
	{ CR130,  0x10 }, /* MARK_001 from 0xb->0x0d */
};

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
static int zd1211b_al2230_finalize_rf(struct zd_chip *chip)
{
	int r;
	static const struct zd_ioreq16 ioreqs[] = {
		{ CR80,  0x30 }, { CR81,  0x30 }, { CR79,  0x58 },
		{ CR12,  0xf0 }, { CR77,  0x1b }, { CR78,  0x58 },
		{ CR203, 0x06 },
		{ },

		{ CR240, 0x80 },
	};

	r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
	if (r)
		return r;

	/* related to antenna selection? */
	if (chip->new_phy_layout) {
		r = zd_iowrite16_locked(chip, 0xe1, CR9);
		if (r)
			return r;
	}

	return zd_iowrite16_locked(chip, 0x06, CR203);
}

105 106 107 108 109
static int zd1211_al2230_init_hw(struct zd_rf *rf)
{
	int r;
	struct zd_chip *chip = zd_rf_to_chip(rf);

110
	static const struct zd_ioreq16 ioreqs_init[] = {
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
		{ CR15,   0x20 }, { CR23,   0x40 }, { CR24,  0x20 },
		{ CR26,   0x11 }, { CR28,   0x3e }, { CR29,  0x00 },
		{ CR44,   0x33 }, { CR106,  0x2a }, { CR107, 0x1a },
		{ CR109,  0x09 }, { CR110,  0x27 }, { CR111, 0x2b },
		{ CR112,  0x2b }, { CR119,  0x0a }, { CR10,  0x89 },
		/* for newest (3rd cut) AL2300 */
		{ CR17,   0x28 },
		{ CR26,   0x93 }, { CR34,   0x30 },
		/* for newest (3rd cut) AL2300 */
		{ CR35,   0x3e },
		{ CR41,   0x24 }, { CR44,   0x32 },
		/* for newest (3rd cut) AL2300 */
		{ CR46,   0x96 },
		{ CR47,   0x1e }, { CR79,   0x58 }, { CR80,  0x30 },
		{ CR81,   0x30 }, { CR87,   0x0a }, { CR89,  0x04 },
		{ CR92,   0x0a }, { CR99,   0x28 }, { CR100, 0x00 },
		{ CR101,  0x13 }, { CR102,  0x27 }, { CR106, 0x24 },
		{ CR107,  0x2a }, { CR109,  0x09 }, { CR110, 0x13 },
		{ CR111,  0x1f }, { CR112,  0x1f }, { CR113, 0x27 },
		{ CR114,  0x27 },
		/* for newest (3rd cut) AL2300 */
		{ CR115,  0x24 },
		{ CR116,  0x24 }, { CR117,  0xf4 }, { CR118, 0xfc },
		{ CR119,  0x10 }, { CR120,  0x4f }, { CR121, 0x77 },
		{ CR122,  0xe0 }, { CR137,  0x88 }, { CR252, 0xff },
		{ CR253,  0xff },
137
	};
138

139
	static const struct zd_ioreq16 ioreqs_pll[] = {
140 141 142 143 144 145 146
		/* shdnb(PLL_ON)=0 */
		{ CR251,  0x2f },
		/* shdnb(PLL_ON)=1 */
		{ CR251,  0x3f },
		{ CR138,  0x28 }, { CR203,  0x06 },
	};

147
	static const u32 rv1[] = {
148 149 150 151 152 153 154 155
		/* Channel 1 */
		0x03f790,
		0x033331,
		0x00000d,

		0x0b3331,
		0x03b812,
		0x00fff3,
156 157 158
	};

	static const u32 rv2[] = {
159 160 161 162 163 164 165 166 167 168 169
		0x000da4,
		0x0f4dc5, /* fix freq shift, 0x04edc5 */
		0x0805b6,
		0x011687,
		0x000688,
		0x0403b9, /* external control TX power (CR31) */
		0x00dbba,
		0x00099b,
		0x0bdffc,
		0x00000d,
		0x00500f,
170
	};
171

172
	static const u32 rv3[] = {
173 174 175 176 177 178 179
		0x00d00f,
		0x004c0f,
		0x00540f,
		0x00700f,
		0x00500f,
	};

180
	r = zd_iowrite16a_locked(chip, ioreqs_init, ARRAY_SIZE(ioreqs_init));
181 182 183
	if (r)
		return r;

184
	if (IS_AL2230S(chip)) {
185 186 187 188 189 190 191 192 193 194 195
		r = zd_iowrite16a_locked(chip, ioreqs_init_al2230s,
			ARRAY_SIZE(ioreqs_init_al2230s));
		if (r)
			return r;
	}

	r = zd_rfwritev_locked(chip, rv1, ARRAY_SIZE(rv1), RF_RV_BITS);
	if (r)
		return r;

	/* improve band edge for AL2230S */
196
	if (IS_AL2230S(chip))
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
		r = zd_rfwrite_locked(chip, 0x000824, RF_RV_BITS);
	else
		r = zd_rfwrite_locked(chip, 0x0005a4, RF_RV_BITS);
	if (r)
		return r;

	r = zd_rfwritev_locked(chip, rv2, ARRAY_SIZE(rv2), RF_RV_BITS);
	if (r)
		return r;

	r = zd_iowrite16a_locked(chip, ioreqs_pll, ARRAY_SIZE(ioreqs_pll));
	if (r)
		return r;

	r = zd_rfwritev_locked(chip, rv3, ARRAY_SIZE(rv3), RF_RV_BITS);
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
	if (r)
		return r;

	return 0;
}

static int zd1211b_al2230_init_hw(struct zd_rf *rf)
{
	int r;
	struct zd_chip *chip = zd_rf_to_chip(rf);

	static const struct zd_ioreq16 ioreqs1[] = {
		{ CR10,  0x89 }, { CR15,  0x20 },
		{ CR17,  0x2B }, /* for newest(3rd cut) AL2230 */
		{ CR23,  0x40 }, { CR24,  0x20 }, { CR26,  0x93 },
		{ CR28,  0x3e }, { CR29,  0x00 },
		{ CR33,  0x28 }, /* 5621 */
		{ CR34,  0x30 },
		{ CR35,  0x3e }, /* for newest(3rd cut) AL2230 */
		{ CR41,  0x24 }, { CR44,  0x32 },
		{ CR46,  0x99 }, /* for newest(3rd cut) AL2230 */
		{ CR47,  0x1e },

		/* ZD1211B 05.06.10 */
236
		{ CR48,  0x06 }, { CR49,  0xf9 }, { CR51,  0x01 },
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
		{ CR52,  0x80 }, { CR53,  0x7e }, { CR65,  0x00 },
		{ CR66,  0x00 }, { CR67,  0x00 }, { CR68,  0x00 },
		{ CR69,  0x28 },

		{ CR79,  0x58 }, { CR80,  0x30 }, { CR81,  0x30 },
		{ CR87,  0x0a }, { CR89,  0x04 },
		{ CR91,  0x00 }, /* 5621 */
		{ CR92,  0x0a },
		{ CR98,  0x8d }, /* 4804,  for 1212 new algorithm */
		{ CR99,  0x00 }, /* 5621 */
		{ CR101, 0x13 }, { CR102, 0x27 },
		{ CR106, 0x24 }, /* for newest(3rd cut) AL2230 */
		{ CR107, 0x2a },
		{ CR109, 0x13 }, /* 4804, for 1212 new algorithm */
		{ CR110, 0x1f }, /* 4804, for 1212 new algorithm */
		{ CR111, 0x1f }, { CR112, 0x1f }, { CR113, 0x27 },
		{ CR114, 0x27 },
		{ CR115, 0x26 }, /* 24->26 at 4902 for newest(3rd cut) AL2230 */
		{ CR116, 0x24 },
		{ CR117, 0xfa }, /* for 1211b */
		{ CR118, 0xfa }, /* for 1211b */
		{ CR119, 0x10 },
		{ CR120, 0x4f },
		{ CR121, 0x6c }, /* for 1211b */
		{ CR122, 0xfc }, /* E0->FC at 4902 */
		{ CR123, 0x57 }, /* 5623 */
		{ CR125, 0xad }, /* 4804, for 1212 new algorithm */
		{ CR126, 0x6c }, /* 5614 */
		{ CR127, 0x03 }, /* 4804, for 1212 new algorithm */
		{ CR137, 0x50 }, /* 5614 */
		{ CR138, 0xa8 },
		{ CR144, 0xac }, /* 5621 */
269
		{ CR150, 0x0d }, { CR252, 0x34 }, { CR253, 0x34 },
270 271 272
	};

	static const u32 rv1[] = {
273 274 275 276
		0x8cccd0,
		0x481dc0,
		0xcfff00,
		0x25a000,
277
	};
278

279
	static const u32 rv2[] = {
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
		/* To improve AL2230 yield, improve phase noise, 4713 */
		0x25a000,
		0xa3b2f0,

		0x6da010, /* Reg6 update for MP versio */
		0xe36280, /* Modified by jxiao for Bor-Chin on 2004/08/02 */
		0x116000,
		0x9dc020, /* External control TX power (CR31) */
		0x5ddb00, /* RegA update for MP version */
		0xd99000, /* RegB update for MP version */
		0x3ffbd0, /* RegC update for MP version */
		0xb00000, /* RegD update for MP version */

		/* improve phase noise and remove phase calibration,4713 */
		0xf01a00,
295 296 297
	};

	static const struct zd_ioreq16 ioreqs2[] = {
298 299
		{ CR251, 0x2f }, /* shdnb(PLL_ON)=0 */
		{ CR251, 0x7f }, /* shdnb(PLL_ON)=1 */
300 301
	};

302
	static const u32 rv3[] = {
303 304 305 306
		/* To improve AL2230 yield, 4713 */
		0xf01b00,
		0xf01e00,
		0xf01a00,
307 308 309
	};

	static const struct zd_ioreq16 ioreqs3[] = {
310 311
		/* related to 6M band edge patching, happens unconditionally */
		{ CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
312 313
	};

314 315 316 317
	r = zd_iowrite16a_locked(chip, zd1211b_ioreqs_shared_1,
		ARRAY_SIZE(zd1211b_ioreqs_shared_1));
	if (r)
		return r;
318 319 320
	r = zd_iowrite16a_locked(chip, ioreqs1, ARRAY_SIZE(ioreqs1));
	if (r)
		return r;
321

322
	if (IS_AL2230S(chip)) {
323 324 325 326 327 328
		r = zd_iowrite16a_locked(chip, ioreqs_init_al2230s,
			ARRAY_SIZE(ioreqs_init_al2230s));
		if (r)
			return r;
	}

329
	r = zd_rfwritev_cr_locked(chip, zd1211b_al2230_table[0], 3);
330 331
	if (r)
		return r;
332
	r = zd_rfwritev_cr_locked(chip, rv1, ARRAY_SIZE(rv1));
333 334
	if (r)
		return r;
335

336
	if (IS_AL2230S(chip))
337 338 339
		r = zd_rfwrite_locked(chip, 0x241000, RF_RV_BITS);
	else
		r = zd_rfwrite_locked(chip, 0x25a000, RF_RV_BITS);
340 341
	if (r)
		return r;
342

343
	r = zd_rfwritev_cr_locked(chip, rv2, ARRAY_SIZE(rv2));
344 345 346 347 348 349
	if (r)
		return r;
	r = zd_iowrite16a_locked(chip, ioreqs2, ARRAY_SIZE(ioreqs2));
	if (r)
		return r;
	r = zd_rfwritev_cr_locked(chip, rv3, ARRAY_SIZE(rv3));
350 351
	if (r)
		return r;
352
	r = zd_iowrite16a_locked(chip, ioreqs3, ARRAY_SIZE(ioreqs3));
353 354
	if (r)
		return r;
355
	return zd1211b_al2230_finalize_rf(chip);
356 357
}

358
static int zd1211_al2230_set_channel(struct zd_rf *rf, u8 channel)
359 360
{
	int r;
361
	const u32 *rv = zd1211_al2230_table[channel-1];
362 363 364 365 366 367 368 369 370 371 372 373
	struct zd_chip *chip = zd_rf_to_chip(rf);
	static const struct zd_ioreq16 ioreqs[] = {
		{ CR138, 0x28 },
		{ CR203, 0x06 },
	};

	r = zd_rfwritev_locked(chip, rv, 3, RF_RV_BITS);
	if (r)
		return r;
	return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
}

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
static int zd1211b_al2230_set_channel(struct zd_rf *rf, u8 channel)
{
	int r;
	const u32 *rv = zd1211b_al2230_table[channel-1];
	struct zd_chip *chip = zd_rf_to_chip(rf);

	r = zd_iowrite16a_locked(chip, zd1211b_ioreqs_shared_1,
		ARRAY_SIZE(zd1211b_ioreqs_shared_1));
	if (r)
		return r;

	r = zd_rfwritev_cr_locked(chip, rv, 3);
	if (r)
		return r;

	return zd1211b_al2230_finalize_rf(chip);
}

392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
static int zd1211_al2230_switch_radio_on(struct zd_rf *rf)
{
	struct zd_chip *chip = zd_rf_to_chip(rf);
	static const struct zd_ioreq16 ioreqs[] = {
		{ CR11,  0x00 },
		{ CR251, 0x3f },
	};

	return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
}

static int zd1211b_al2230_switch_radio_on(struct zd_rf *rf)
{
	struct zd_chip *chip = zd_rf_to_chip(rf);
	static const struct zd_ioreq16 ioreqs[] = {
		{ CR11,  0x00 },
		{ CR251, 0x7f },
	};

	return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
}

static int al2230_switch_radio_off(struct zd_rf *rf)
{
	struct zd_chip *chip = zd_rf_to_chip(rf);
	static const struct zd_ioreq16 ioreqs[] = {
		{ CR11,  0x04 },
		{ CR251, 0x2f },
	};

	return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
}

int zd_rf_init_al2230(struct zd_rf *rf)
{
	struct zd_chip *chip = zd_rf_to_chip(rf);

	rf->switch_radio_off = al2230_switch_radio_off;
430
	if (zd_chip_is_zd1211b(chip)) {
431
		rf->init_hw = zd1211b_al2230_init_hw;
432
		rf->set_channel = zd1211b_al2230_set_channel;
433 434 435
		rf->switch_radio_on = zd1211b_al2230_switch_radio_on;
	} else {
		rf->init_hw = zd1211_al2230_init_hw;
436
		rf->set_channel = zd1211_al2230_set_channel;
437 438
		rf->switch_radio_on = zd1211_al2230_switch_radio_on;
	}
439
	rf->patch_6m_band_edge = zd_rf_generic_patch_6m;
440
	rf->patch_cck_gain = 1;
441 442
	return 0;
}