phy.c 74.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 105 106 107 108 109 110 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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 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 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
/*
 * PHY functions
 *
 * Copyright (c) 2004, 2005, 2006, 2007 Reyk Floeter <reyk@openbsd.org>
 * Copyright (c) 2006, 2007 Nick Kossifidis <mickflemm@gmail.com>
 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include <linux/delay.h>

#include "ath5k.h"
#include "reg.h"
#include "base.h"

/* Struct to hold initial RF register values (RF Banks) */
struct ath5k_ini_rf {
	u8	rf_bank;	/* check out ath5k_reg.h */
	u16	rf_register;	/* register address */
	u32	rf_value[5];	/* register value for different modes (above) */
};

/*
 * Mode-specific RF Gain table (64bytes) for RF5111/5112
 * (RF5110 only comes with AR5210 and only supports a/turbo a mode so initial
 * RF Gain values are included in AR5K_AR5210_INI)
 */
struct ath5k_ini_rfgain {
	u16	rfg_register;	/* RF Gain register address */
	u32	rfg_value[2];	/* [freq (see below)] */
};

struct ath5k_gain_opt {
	u32			go_default;
	u32			go_steps_count;
	const struct ath5k_gain_opt_step	go_step[AR5K_GAIN_STEP_COUNT];
};

/* RF5111 mode-specific init registers */
static const struct ath5k_ini_rf rfregs_5111[] = {
	{ 0, 0x989c,
	/*    mode a/XR   mode aTurbo mode b      mode g      mode gTurbo */
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00380000, 0x00380000, 0x00380000, 0x00380000, 0x00380000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 0, 0x989c,
	    { 0x00000000, 0x00000000, 0x000000c0, 0x00000080, 0x00000080 } },
	{ 0, 0x989c,
	    { 0x000400f9, 0x000400f9, 0x000400ff, 0x000400fd, 0x000400fd } },
	{ 0, 0x98d4,
	    { 0x00000000, 0x00000000, 0x00000004, 0x00000004, 0x00000004 } },
	{ 1, 0x98d4,
	    { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
	{ 2, 0x98d4,
	    { 0x00000010, 0x00000014, 0x00000010, 0x00000010, 0x00000014 } },
	{ 3, 0x98d8,
	    { 0x00601068, 0x00601068, 0x00601068, 0x00601068, 0x00601068 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x10000000, 0x10000000, 0x10000000, 0x10000000, 0x10000000 } },
	{ 6, 0x989c,
	    { 0x04000000, 0x04000000, 0x04000000, 0x04000000, 0x04000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x0a000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x003800c0, 0x00380080, 0x023800c0, 0x003800c0, 0x003800c0 } },
	{ 6, 0x989c,
	    { 0x00020006, 0x00020006, 0x00000006, 0x00020006, 0x00020006 } },
	{ 6, 0x989c,
	    { 0x00000089, 0x00000089, 0x00000089, 0x00000089, 0x00000089 } },
	{ 6, 0x989c,
	    { 0x000000a0, 0x000000a0, 0x000000a0, 0x000000a0, 0x000000a0 } },
	{ 6, 0x989c,
	    { 0x00040007, 0x00040007, 0x00040007, 0x00040007, 0x00040007 } },
	{ 6, 0x98d4,
	    { 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a } },
	{ 7, 0x989c,
	    { 0x00000040, 0x00000048, 0x00000040, 0x00000040, 0x00000040 } },
	{ 7, 0x989c,
	    { 0x00000010, 0x00000010, 0x00000010, 0x00000010, 0x00000010 } },
	{ 7, 0x989c,
	    { 0x00000008, 0x00000008, 0x00000008, 0x00000008, 0x00000008 } },
	{ 7, 0x989c,
	    { 0x0000004f, 0x0000004f, 0x0000004f, 0x0000004f, 0x0000004f } },
	{ 7, 0x989c,
	    { 0x000000f1, 0x000000f1, 0x00000061, 0x000000f1, 0x000000f1 } },
	{ 7, 0x989c,
	    { 0x0000904f, 0x0000904f, 0x0000904c, 0x0000904f, 0x0000904f } },
	{ 7, 0x989c,
	    { 0x0000125a, 0x0000125a, 0x0000129a, 0x0000125a, 0x0000125a } },
	{ 7, 0x98cc,
	    { 0x0000000e, 0x0000000e, 0x0000000f, 0x0000000e, 0x0000000e } },
};

/* Initial RF Gain settings for RF5111 */
static const struct ath5k_ini_rfgain rfgain_5111[] = {
	/*			      5Ghz	2Ghz	*/
	{ AR5K_RF_GAIN(0),	{ 0x000001a9, 0x00000000 } },
	{ AR5K_RF_GAIN(1),	{ 0x000001e9, 0x00000040 } },
	{ AR5K_RF_GAIN(2),	{ 0x00000029, 0x00000080 } },
	{ AR5K_RF_GAIN(3),	{ 0x00000069, 0x00000150 } },
	{ AR5K_RF_GAIN(4),	{ 0x00000199, 0x00000190 } },
	{ AR5K_RF_GAIN(5),	{ 0x000001d9, 0x000001d0 } },
	{ AR5K_RF_GAIN(6),	{ 0x00000019, 0x00000010 } },
	{ AR5K_RF_GAIN(7),	{ 0x00000059, 0x00000044 } },
	{ AR5K_RF_GAIN(8),	{ 0x00000099, 0x00000084 } },
	{ AR5K_RF_GAIN(9),	{ 0x000001a5, 0x00000148 } },
	{ AR5K_RF_GAIN(10),	{ 0x000001e5, 0x00000188 } },
	{ AR5K_RF_GAIN(11),	{ 0x00000025, 0x000001c8 } },
	{ AR5K_RF_GAIN(12),	{ 0x000001c8, 0x00000014 } },
	{ AR5K_RF_GAIN(13),	{ 0x00000008, 0x00000042 } },
	{ AR5K_RF_GAIN(14),	{ 0x00000048, 0x00000082 } },
	{ AR5K_RF_GAIN(15),	{ 0x00000088, 0x00000178 } },
	{ AR5K_RF_GAIN(16),	{ 0x00000198, 0x000001b8 } },
	{ AR5K_RF_GAIN(17),	{ 0x000001d8, 0x000001f8 } },
	{ AR5K_RF_GAIN(18),	{ 0x00000018, 0x00000012 } },
	{ AR5K_RF_GAIN(19),	{ 0x00000058, 0x00000052 } },
	{ AR5K_RF_GAIN(20),	{ 0x00000098, 0x00000092 } },
	{ AR5K_RF_GAIN(21),	{ 0x000001a4, 0x0000017c } },
	{ AR5K_RF_GAIN(22),	{ 0x000001e4, 0x000001bc } },
	{ AR5K_RF_GAIN(23),	{ 0x00000024, 0x000001fc } },
	{ AR5K_RF_GAIN(24),	{ 0x00000064, 0x0000000a } },
	{ AR5K_RF_GAIN(25),	{ 0x000000a4, 0x0000004a } },
	{ AR5K_RF_GAIN(26),	{ 0x000000e4, 0x0000008a } },
	{ AR5K_RF_GAIN(27),	{ 0x0000010a, 0x0000015a } },
	{ AR5K_RF_GAIN(28),	{ 0x0000014a, 0x0000019a } },
	{ AR5K_RF_GAIN(29),	{ 0x0000018a, 0x000001da } },
	{ AR5K_RF_GAIN(30),	{ 0x000001ca, 0x0000000e } },
	{ AR5K_RF_GAIN(31),	{ 0x0000000a, 0x0000004e } },
	{ AR5K_RF_GAIN(32),	{ 0x0000004a, 0x0000008e } },
	{ AR5K_RF_GAIN(33),	{ 0x0000008a, 0x0000015e } },
	{ AR5K_RF_GAIN(34),	{ 0x000001ba, 0x0000019e } },
	{ AR5K_RF_GAIN(35),	{ 0x000001fa, 0x000001de } },
	{ AR5K_RF_GAIN(36),	{ 0x0000003a, 0x00000009 } },
	{ AR5K_RF_GAIN(37),	{ 0x0000007a, 0x00000049 } },
	{ AR5K_RF_GAIN(38),	{ 0x00000186, 0x00000089 } },
	{ AR5K_RF_GAIN(39),	{ 0x000001c6, 0x00000179 } },
	{ AR5K_RF_GAIN(40),	{ 0x00000006, 0x000001b9 } },
	{ AR5K_RF_GAIN(41),	{ 0x00000046, 0x000001f9 } },
	{ AR5K_RF_GAIN(42),	{ 0x00000086, 0x00000039 } },
	{ AR5K_RF_GAIN(43),	{ 0x000000c6, 0x00000079 } },
	{ AR5K_RF_GAIN(44),	{ 0x000000c6, 0x000000b9 } },
	{ AR5K_RF_GAIN(45),	{ 0x000000c6, 0x000001bd } },
	{ AR5K_RF_GAIN(46),	{ 0x000000c6, 0x000001fd } },
	{ AR5K_RF_GAIN(47),	{ 0x000000c6, 0x0000003d } },
	{ AR5K_RF_GAIN(48),	{ 0x000000c6, 0x0000007d } },
	{ AR5K_RF_GAIN(49),	{ 0x000000c6, 0x000000bd } },
	{ AR5K_RF_GAIN(50),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(51),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(52),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(53),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(54),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(55),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(56),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(57),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(58),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(59),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(60),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(61),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(62),	{ 0x000000c6, 0x000000fd } },
	{ AR5K_RF_GAIN(63),	{ 0x000000c6, 0x000000fd } },
};

static const struct ath5k_gain_opt rfgain_opt_5111 = {
	4,
	9,
	{
		{ { 4, 1, 1, 1 }, 6 },
		{ { 4, 0, 1, 1 }, 4 },
		{ { 3, 1, 1, 1 }, 3 },
		{ { 4, 0, 0, 1 }, 1 },
		{ { 4, 1, 1, 0 }, 0 },
		{ { 4, 0, 1, 0 }, -2 },
		{ { 3, 1, 1, 0 }, -3 },
		{ { 4, 0, 0, 0 }, -4 },
		{ { 2, 1, 1, 0 }, -6 }
	}
};

/* RF5112 mode-specific init registers */
static const struct ath5k_ini_rf rfregs_5112[] = {
	{ 1, 0x98d4,
	/*    mode a/XR   mode aTurbo mode b      mode g      mode gTurbo */
	    { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
	{ 2, 0x98d0,
	    { 0x03060408, 0x03070408, 0x03060408, 0x03060408, 0x03070408 } },
	{ 3, 0x98dc,
	    { 0x00a0c0c0, 0x00a0c0c0, 0x00e0c0c0, 0x00e0c0c0, 0x00e0c0c0 } },
	{ 6, 0x989c,
	    { 0x00a00000, 0x00a00000, 0x00a00000, 0x00a00000, 0x00a00000 } },
	{ 6, 0x989c,
	    { 0x000a0000, 0x000a0000, 0x000a0000, 0x000a0000, 0x000a0000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00660000, 0x00660000, 0x00660000, 0x00660000, 0x00660000 } },
	{ 6, 0x989c,
	    { 0x00db0000, 0x00db0000, 0x00db0000, 0x00db0000, 0x00db0000 } },
	{ 6, 0x989c,
	    { 0x00f10000, 0x00f10000, 0x00f10000, 0x00f10000, 0x00f10000 } },
	{ 6, 0x989c,
	    { 0x00120000, 0x00120000, 0x00120000, 0x00120000, 0x00120000 } },
	{ 6, 0x989c,
	    { 0x00120000, 0x00120000, 0x00120000, 0x00120000, 0x00120000 } },
	{ 6, 0x989c,
	    { 0x00730000, 0x00730000, 0x00730000, 0x00730000, 0x00730000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000 } },
	{ 6, 0x989c,
	    { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
	{ 6, 0x989c,
	    { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
	{ 6, 0x989c,
	    { 0x008b0000, 0x008b0000, 0x008b0000, 0x008b0000, 0x008b0000 } },
	{ 6, 0x989c,
	    { 0x00600000, 0x00600000, 0x00600000, 0x00600000, 0x00600000 } },
	{ 6, 0x989c,
	    { 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000 } },
	{ 6, 0x989c,
	    { 0x00840000, 0x00840000, 0x00840000, 0x00840000, 0x00840000 } },
	{ 6, 0x989c,
	    { 0x00640000, 0x00640000, 0x00640000, 0x00640000, 0x00640000 } },
	{ 6, 0x989c,
	    { 0x00200000, 0x00200000, 0x00200000, 0x00200000, 0x00200000 } },
	{ 6, 0x989c,
	    { 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000 } },
	{ 6, 0x989c,
	    { 0x00250000, 0x00250000, 0x00250000, 0x00250000, 0x00250000 } },
	{ 6, 0x989c,
	    { 0x00110000, 0x00110000, 0x00110000, 0x00110000, 0x00110000 } },
	{ 6, 0x989c,
	    { 0x00110000, 0x00110000, 0x00110000, 0x00110000, 0x00110000 } },
	{ 6, 0x989c,
	    { 0x00510000, 0x00510000, 0x00510000, 0x00510000, 0x00510000 } },
	{ 6, 0x989c,
	    { 0x1c040000, 0x1c040000, 0x1c040000, 0x1c040000, 0x1c040000 } },
	{ 6, 0x989c,
	    { 0x000a0000, 0x000a0000, 0x000a0000, 0x000a0000, 0x000a0000 } },
	{ 6, 0x989c,
	    { 0x00a10000, 0x00a10000, 0x00a10000, 0x00a10000, 0x00a10000 } },
	{ 6, 0x989c,
	    { 0x00400000, 0x00400000, 0x00400000, 0x00400000, 0x00400000 } },
	{ 6, 0x989c,
	    { 0x03090000, 0x03090000, 0x03090000, 0x03090000, 0x03090000 } },
	{ 6, 0x989c,
	    { 0x06000000, 0x06000000, 0x06000000, 0x06000000, 0x06000000 } },
	{ 6, 0x989c,
	    { 0x000000b0, 0x000000b0, 0x000000a8, 0x000000a8, 0x000000a8 } },
	{ 6, 0x989c,
	    { 0x0000002e, 0x0000002e, 0x0000002e, 0x0000002e, 0x0000002e } },
	{ 6, 0x989c,
	    { 0x006c4a41, 0x006c4a41, 0x006c4af1, 0x006c4a61, 0x006c4a61 } },
	{ 6, 0x989c,
	    { 0x0050892a, 0x0050892a, 0x0050892b, 0x0050892b, 0x0050892b } },
	{ 6, 0x989c,
	    { 0x00842400, 0x00842400, 0x00842400, 0x00842400, 0x00842400 } },
	{ 6, 0x989c,
	    { 0x00c69200, 0x00c69200, 0x00c69200, 0x00c69200, 0x00c69200 } },
	{ 6, 0x98d0,
	    { 0x0002000c, 0x0002000c, 0x0002000c, 0x0002000c, 0x0002000c } },
	{ 7, 0x989c,
	    { 0x00000094, 0x00000094, 0x00000094, 0x00000094, 0x00000094 } },
	{ 7, 0x989c,
	    { 0x00000091, 0x00000091, 0x00000091, 0x00000091, 0x00000091 } },
	{ 7, 0x989c,
	    { 0x0000000a, 0x0000000a, 0x00000012, 0x00000012, 0x00000012 } },
	{ 7, 0x989c,
	    { 0x00000080, 0x00000080, 0x00000080, 0x00000080, 0x00000080 } },
	{ 7, 0x989c,
	    { 0x000000c1, 0x000000c1, 0x000000c1, 0x000000c1, 0x000000c1 } },
	{ 7, 0x989c,
	    { 0x00000060, 0x00000060, 0x00000060, 0x00000060, 0x00000060 } },
	{ 7, 0x989c,
	    { 0x000000f0, 0x000000f0, 0x000000f0, 0x000000f0, 0x000000f0 } },
	{ 7, 0x989c,
	    { 0x00000022, 0x00000022, 0x00000022, 0x00000022, 0x00000022 } },
	{ 7, 0x989c,
	    { 0x00000092, 0x00000092, 0x00000092, 0x00000092, 0x00000092 } },
	{ 7, 0x989c,
	    { 0x000000d4, 0x000000d4, 0x000000d4, 0x000000d4, 0x000000d4 } },
	{ 7, 0x989c,
	    { 0x000014cc, 0x000014cc, 0x000014cc, 0x000014cc, 0x000014cc } },
	{ 7, 0x989c,
	    { 0x0000048c, 0x0000048c, 0x0000048c, 0x0000048c, 0x0000048c } },
	{ 7, 0x98c4,
	    { 0x00000003, 0x00000003, 0x00000003, 0x00000003, 0x00000003 } },
};

/* RF5112A mode-specific init registers */
static const struct ath5k_ini_rf rfregs_5112a[] = {
	{ 1, 0x98d4,
	/*    mode a/XR   mode aTurbo mode b      mode g      mode gTurbo */
	    { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
	{ 2, 0x98d0,
	    { 0x03060408, 0x03070408, 0x03060408, 0x03060408, 0x03070408 } },
	{ 3, 0x98dc,
	    { 0x00a0c0c0, 0x00a0c0c0, 0x00e0c0c0, 0x00e0c0c0, 0x00e0c0c0 } },
	{ 6, 0x989c,
	    { 0x0f000000, 0x0f000000, 0x0f000000, 0x0f000000, 0x0f000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00800000, 0x00800000, 0x00800000, 0x00800000, 0x00800000 } },
	{ 6, 0x989c,
	    { 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000 } },
	{ 6, 0x989c,
	    { 0x00010000, 0x00010000, 0x00010000, 0x00010000, 0x00010000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00180000, 0x00180000, 0x00180000, 0x00180000, 0x00180000 } },
	{ 6, 0x989c,
	    { 0x00600000, 0x00600000, 0x006e0000, 0x006e0000, 0x006e0000 } },
	{ 6, 0x989c,
	    { 0x00c70000, 0x00c70000, 0x00c70000, 0x00c70000, 0x00c70000 } },
	{ 6, 0x989c,
	    { 0x004b0000, 0x004b0000, 0x004b0000, 0x004b0000, 0x004b0000 } },
	{ 6, 0x989c,
	    { 0x04480000, 0x04480000, 0x04480000, 0x04480000, 0x04480000 } },
	{ 6, 0x989c,
	    { 0x00220000, 0x00220000, 0x00220000, 0x00220000, 0x00220000 } },
	{ 6, 0x989c,
	    { 0x00e40000, 0x00e40000, 0x00e40000, 0x00e40000, 0x00e40000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00fc0000, 0x00fc0000, 0x00fc0000, 0x00fc0000, 0x00fc0000 } },
	{ 6, 0x989c,
	    { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
	{ 6, 0x989c,
	    { 0x043f0000, 0x043f0000, 0x043f0000, 0x043f0000, 0x043f0000 } },
	{ 6, 0x989c,
	    { 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000, 0x000c0000 } },
	{ 6, 0x989c,
	    { 0x00190000, 0x00190000, 0x00190000, 0x00190000, 0x00190000 } },
	{ 6, 0x989c,
	    { 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000 } },
	{ 6, 0x989c,
	    { 0x00b40000, 0x00b40000, 0x00b40000, 0x00b40000, 0x00b40000 } },
	{ 6, 0x989c,
	    { 0x00990000, 0x00990000, 0x00990000, 0x00990000, 0x00990000 } },
	{ 6, 0x989c,
	    { 0x00500000, 0x00500000, 0x00500000, 0x00500000, 0x00500000 } },
	{ 6, 0x989c,
	    { 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000, 0x002a0000 } },
	{ 6, 0x989c,
	    { 0x00120000, 0x00120000, 0x00120000, 0x00120000, 0x00120000 } },
	{ 6, 0x989c,
	    { 0xc0320000, 0xc0320000, 0xc0320000, 0xc0320000, 0xc0320000 } },
	{ 6, 0x989c,
	    { 0x01740000, 0x01740000, 0x01740000, 0x01740000, 0x01740000 } },
	{ 6, 0x989c,
	    { 0x00110000, 0x00110000, 0x00110000, 0x00110000, 0x00110000 } },
	{ 6, 0x989c,
	    { 0x86280000, 0x86280000, 0x86280000, 0x86280000, 0x86280000 } },
	{ 6, 0x989c,
	    { 0x31840000, 0x31840000, 0x31840000, 0x31840000, 0x31840000 } },
	{ 6, 0x989c,
	    { 0x00020080, 0x00020080, 0x00020080, 0x00020080, 0x00020080 } },
	{ 6, 0x989c,
	    { 0x00080009, 0x00080009, 0x00080009, 0x00080009, 0x00080009 } },
	{ 6, 0x989c,
	    { 0x00000003, 0x00000003, 0x00000003, 0x00000003, 0x00000003 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x000000b2, 0x000000b2, 0x000000b2, 0x000000b2, 0x000000b2 } },
	{ 6, 0x989c,
	    { 0x00b02084, 0x00b02084, 0x00b02084, 0x00b02084, 0x00b02084 } },
	{ 6, 0x989c,
	    { 0x004125a4, 0x004125a4, 0x004125a4, 0x004125a4, 0x004125a4 } },
	{ 6, 0x989c,
	    { 0x00119220, 0x00119220, 0x00119220, 0x00119220, 0x00119220 } },
	{ 6, 0x989c,
	    { 0x001a4800, 0x001a4800, 0x001a4800, 0x001a4800, 0x001a4800 } },
	{ 6, 0x98d8,
	    { 0x000b0230, 0x000b0230, 0x000b0230, 0x000b0230, 0x000b0230 } },
	{ 7, 0x989c,
	    { 0x00000094, 0x00000094, 0x00000094, 0x00000094, 0x00000094 } },
	{ 7, 0x989c,
	    { 0x00000091, 0x00000091, 0x00000091, 0x00000091, 0x00000091 } },
	{ 7, 0x989c,
	    { 0x00000012, 0x00000012, 0x00000012, 0x00000012, 0x00000012 } },
	{ 7, 0x989c,
	    { 0x00000080, 0x00000080, 0x00000080, 0x00000080, 0x00000080 } },
	{ 7, 0x989c,
	    { 0x000000d9, 0x000000d9, 0x000000d9, 0x000000d9, 0x000000d9 } },
	{ 7, 0x989c,
	    { 0x00000060, 0x00000060, 0x00000060, 0x00000060, 0x00000060 } },
	{ 7, 0x989c,
	    { 0x000000f0, 0x000000f0, 0x000000f0, 0x000000f0, 0x000000f0 } },
	{ 7, 0x989c,
	    { 0x000000a2, 0x000000a2, 0x000000a2, 0x000000a2, 0x000000a2 } },
	{ 7, 0x989c,
	    { 0x00000052, 0x00000052, 0x00000052, 0x00000052, 0x00000052 } },
	{ 7, 0x989c,
	    { 0x000000d4, 0x000000d4, 0x000000d4, 0x000000d4, 0x000000d4 } },
	{ 7, 0x989c,
	    { 0x000014cc, 0x000014cc, 0x000014cc, 0x000014cc, 0x000014cc } },
	{ 7, 0x989c,
	    { 0x0000048c, 0x0000048c, 0x0000048c, 0x0000048c, 0x0000048c } },
	{ 7, 0x98c4,
	    { 0x00000003, 0x00000003, 0x00000003, 0x00000003, 0x00000003 } },
};


static const struct ath5k_ini_rf rfregs_2112a[] = {
	{ 1, AR5K_RF_BUFFER_CONTROL_4,
	/*	   mode b	mode g	  mode gTurbo */
		{ 0x00000020, 0x00000020, 0x00000020 } },
	{ 2, AR5K_RF_BUFFER_CONTROL_3,
		{ 0x03060408, 0x03060408, 0x03070408 } },
	{ 3, AR5K_RF_BUFFER_CONTROL_6,
		{ 0x00e020c0, 0x00e020c0, 0x00e020c0 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x0a000000, 0x0a000000, 0x0a000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00800000, 0x00800000, 0x00800000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x002a0000, 0x002a0000, 0x002a0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00010000, 0x00010000, 0x00010000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00180000, 0x00180000, 0x00180000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x006e0000, 0x006e0000, 0x006e0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00c70000, 0x00c70000, 0x00c70000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x004b0000, 0x004b0000, 0x004b0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x04480000, 0x04480000, 0x04480000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x002a0000, 0x002a0000, 0x002a0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00e40000, 0x00e40000, 0x00e40000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00fc0000, 0x00fc0000, 0x00fc0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x043f0000, 0x043f0000, 0x043f0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x0c0c0000, 0x0c0c0000, 0x0c0c0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x02190000, 0x02190000, 0x02190000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00240000, 0x00240000, 0x00240000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00b40000, 0x00b40000, 0x00b40000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00990000, 0x00990000, 0x00990000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00500000, 0x00500000, 0x00500000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x002a0000, 0x002a0000, 0x002a0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00120000, 0x00120000, 0x00120000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0xc0320000, 0xc0320000, 0xc0320000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x01740000, 0x01740000, 0x01740000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00110000, 0x00110000, 0x00110000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x86280000, 0x86280000, 0x86280000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x31840000, 0x31840000, 0x31840000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00f20080, 0x00f20080, 0x00f20080 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00070019, 0x00070019, 0x00070019 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x000000b2, 0x000000b2, 0x000000b2 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00b02184, 0x00b02184, 0x00b02184 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x004125a4, 0x004125a4, 0x004125a4 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00119220, 0x00119220, 0x00119220 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x001a4800, 0x001a4800, 0x001a4800 } },
	{ 6, AR5K_RF_BUFFER_CONTROL_5,
		{ 0x000b0230, 0x000b0230, 0x000b0230 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00000094, 0x00000094, 0x00000094 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00000091, 0x00000091, 0x00000091 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00000012, 0x00000012, 0x00000012 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00000080, 0x00000080, 0x00000080 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x000000d9, 0x000000d9, 0x000000d9 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00000060, 0x00000060, 0x00000060 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x000000f0, 0x000000f0, 0x000000f0 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x000000a2, 0x000000a2, 0x000000a2 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00000052, 0x00000052, 0x00000052 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x000000d4, 0x000000d4, 0x000000d4 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x000014cc, 0x000014cc, 0x000014cc } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x0000048c, 0x0000048c, 0x0000048c } },
	{ 7, AR5K_RF_BUFFER_CONTROL_1,
		{ 0x00000003, 0x00000003, 0x00000003 } },
};

/* RF5413/5414 mode-specific init registers */
static const struct ath5k_ini_rf rfregs_5413[] = {
	{ 1, 0x98d4,
	/*    mode a/XR   mode aTurbo mode b      mode g      mode gTurbo */
	    { 0x00000020, 0x00000020, 0x00000020, 0x00000020, 0x00000020 } },
	{ 2, 0x98d0,
	    { 0x00000008, 0x00000008, 0x00000008, 0x00000008, 0x00000008 } },
	{ 3, 0x98dc,
	    { 0x00a000c0, 0x00a000c0, 0x00e000c0, 0x00e000c0, 0x00e000c0 } },
	{ 6, 0x989c,
	    { 0x33000000, 0x33000000, 0x33000000, 0x33000000, 0x33000000 } },
	{ 6, 0x989c,
	    { 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x1f000000, 0x1f000000, 0x1f000000, 0x1f000000, 0x1f000000 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00b80000, 0x00b80000, 0x00b80000, 0x00b80000, 0x00b80000 } },
	{ 6, 0x989c,
	    { 0x00b70000, 0x00b70000, 0x00b70000, 0x00b70000, 0x00b70000 } },
	{ 6, 0x989c,
	    { 0x00840000, 0x00840000, 0x00840000, 0x00840000, 0x00840000 } },
	{ 6, 0x989c,
	    { 0x00980000, 0x00980000, 0x00980000, 0x00980000, 0x00980000 } },
	{ 6, 0x989c,
	    { 0x00c00000, 0x00c00000, 0x00c00000, 0x00c00000, 0x00c00000 } },
	{ 6, 0x989c,
	    { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
	{ 6, 0x989c,
	    { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
	{ 6, 0x989c,
	    { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
	{ 6, 0x989c,
	    { 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000 } },
	{ 6, 0x989c,
	    { 0x00d70000, 0x00d70000, 0x00d70000, 0x00d70000, 0x00d70000 } },
	{ 6, 0x989c,
	    { 0x00610000, 0x00610000, 0x00610000, 0x00610000, 0x00610000 } },
	{ 6, 0x989c,
	    { 0x00fe0000, 0x00fe0000, 0x00fe0000, 0x00fe0000, 0x00fe0000 } },
	{ 6, 0x989c,
	    { 0x00de0000, 0x00de0000, 0x00de0000, 0x00de0000, 0x00de0000 } },
	{ 6, 0x989c,
	    { 0x007f0000, 0x007f0000, 0x007f0000, 0x007f0000, 0x007f0000 } },
	{ 6, 0x989c,
	    { 0x043d0000, 0x043d0000, 0x043d0000, 0x043d0000, 0x043d0000 } },
	{ 6, 0x989c,
	    { 0x00770000, 0x00770000, 0x00770000, 0x00770000, 0x00770000 } },
	{ 6, 0x989c,
	    { 0x00440000, 0x00440000, 0x00440000, 0x00440000, 0x00440000 } },
	{ 6, 0x989c,
	    { 0x00980000, 0x00980000, 0x00980000, 0x00980000, 0x00980000 } },
	{ 6, 0x989c,
	    { 0x00100080, 0x00100080, 0x00100080, 0x00100080, 0x00100080 } },
	{ 6, 0x989c,
	    { 0x0005c034, 0x0005c034, 0x0005c034, 0x0005c034, 0x0005c034 } },
	{ 6, 0x989c,
	    { 0x003100f0, 0x003100f0, 0x003100f0, 0x003100f0, 0x003100f0 } },
	{ 6, 0x989c,
	    { 0x000c011f, 0x000c011f, 0x000c011f, 0x000c011f, 0x000c011f } },
	{ 6, 0x989c,
	    { 0x00510040, 0x00510040, 0x005100a0, 0x005100a0, 0x005100a0 } },
	{ 6, 0x989c,
	    { 0x0050006a, 0x0050006a, 0x005000dd, 0x005000dd, 0x005000dd } },
	{ 6, 0x989c,
	    { 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x00004044, 0x00004044, 0x00004044, 0x00004044, 0x00004044 } },
	{ 6, 0x989c,
	    { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, 0x989c,
	    { 0x000060c0, 0x000060c0, 0x000060c0, 0x000060c0, 0x000060c0 } },
	{ 6, 0x989c,
	    { 0x00002c00, 0x00002c00, 0x00003600, 0x00003600, 0x00003600 } },
	{ 6, 0x98c8,
	    { 0x00000403, 0x00000403, 0x00040403, 0x00040403, 0x00040403 } },
	{ 7, 0x989c,
	    { 0x00006400, 0x00006400, 0x00006400, 0x00006400, 0x00006400 } },
	{ 7, 0x989c,
	    { 0x00000800, 0x00000800, 0x00000800, 0x00000800, 0x00000800 } },
	{ 7, 0x98cc,
	    { 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e, 0x0000000e } },
};

669 670 671
/* RF2413/2414 mode-specific init registers */
static const struct ath5k_ini_rf rfregs_2413[] = {
	{ 1, AR5K_RF_BUFFER_CONTROL_4,
N
Nick Kossifidis 已提交
672
	/* 	   mode b      mode g     mode gTurbo */
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
		{ 0x00000020, 0x00000020, 0x00000020 } },
	{ 2, AR5K_RF_BUFFER_CONTROL_3,
		{ 0x02001408, 0x02001408, 0x02001408 } },
	{ 3, AR5K_RF_BUFFER_CONTROL_6,
		{ 0x00e020c0, 0x00e020c0, 0x00e020c0 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0xf0000000, 0xf0000000, 0xf0000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x03000000, 0x03000000, 0x03000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x40400000, 0x40400000, 0x40400000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x65050000, 0x65050000, 0x65050000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00420000, 0x00420000, 0x00420000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00b50000, 0x00b50000, 0x00b50000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00030000, 0x00030000, 0x00030000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00f70000, 0x00f70000, 0x00f70000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x009d0000, 0x009d0000, 0x009d0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00220000, 0x00220000, 0x00220000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x04220000, 0x04220000, 0x04220000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00230018, 0x00230018, 0x00230018 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00280050, 0x00280050, 0x00280050 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x005000c3, 0x005000c3, 0x005000c3 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x0004007f, 0x0004007f, 0x0004007f } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000458, 0x00000458, 0x00000458 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x0000c000, 0x0000c000, 0x0000c000 } },
	{ 6, AR5K_RF_BUFFER_CONTROL_5,
		{ 0x00400230, 0x00400230, 0x00400230 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00006400, 0x00006400, 0x00006400 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00000800, 0x00000800, 0x00000800 } },
	{ 7, AR5K_RF_BUFFER_CONTROL_2,
		{ 0x0000000e, 0x0000000e, 0x0000000e } },
};
739

N
Nick Kossifidis 已提交
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
/* RF2425 mode-specific init registers */
static const struct ath5k_ini_rf rfregs_2425[] = {
	{ 1, AR5K_RF_BUFFER_CONTROL_4,
	/* 	   mode g     mode gTurbo */
		{ 0x00000020, 0x00000020 } },
	{ 2, AR5K_RF_BUFFER_CONTROL_3,
		{ 0x02001408, 0x02001408 } },
	{ 3, AR5K_RF_BUFFER_CONTROL_6,
		{ 0x00e020c0, 0x00e020c0 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x10000000, 0x10000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x002a0000, 0x002a0000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00100000, 0x00100000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00020000, 0x00020000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00730000, 0x00730000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00f80000, 0x00f80000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00e70000, 0x00e70000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00140000, 0x00140000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00910040, 0x00910040 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x0007001a, 0x0007001a } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00410000, 0x00410000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00810060, 0x00810060 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00020803, 0x00020803 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00000000, 0x00000000 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00001660, 0x00001660 } },
	{ 6, AR5K_RF_BUFFER,
		{ 0x00001688, 0x00001688 } },
	{ 6, AR5K_RF_BUFFER_CONTROL_1,
		{ 0x00000001, 0x00000001 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00006400, 0x00006400 } },
	{ 7, AR5K_RF_BUFFER,
		{ 0x00000800, 0x00000800 } },
	{ 7, AR5K_RF_BUFFER_CONTROL_2,
		{ 0x0000000e, 0x0000000e } },
};

817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
/* Initial RF Gain settings for RF5112 */
static const struct ath5k_ini_rfgain rfgain_5112[] = {
	/*			      5Ghz	2Ghz	*/
	{ AR5K_RF_GAIN(0),	{ 0x00000007, 0x00000007 } },
	{ AR5K_RF_GAIN(1),	{ 0x00000047, 0x00000047 } },
	{ AR5K_RF_GAIN(2),	{ 0x00000087, 0x00000087 } },
	{ AR5K_RF_GAIN(3),	{ 0x000001a0, 0x000001a0 } },
	{ AR5K_RF_GAIN(4),	{ 0x000001e0, 0x000001e0 } },
	{ AR5K_RF_GAIN(5),	{ 0x00000020, 0x00000020 } },
	{ AR5K_RF_GAIN(6),	{ 0x00000060, 0x00000060 } },
	{ AR5K_RF_GAIN(7),	{ 0x000001a1, 0x000001a1 } },
	{ AR5K_RF_GAIN(8),	{ 0x000001e1, 0x000001e1 } },
	{ AR5K_RF_GAIN(9),	{ 0x00000021, 0x00000021 } },
	{ AR5K_RF_GAIN(10),	{ 0x00000061, 0x00000061 } },
	{ AR5K_RF_GAIN(11),	{ 0x00000162, 0x00000162 } },
	{ AR5K_RF_GAIN(12),	{ 0x000001a2, 0x000001a2 } },
	{ AR5K_RF_GAIN(13),	{ 0x000001e2, 0x000001e2 } },
	{ AR5K_RF_GAIN(14),	{ 0x00000022, 0x00000022 } },
	{ AR5K_RF_GAIN(15),	{ 0x00000062, 0x00000062 } },
	{ AR5K_RF_GAIN(16),	{ 0x00000163, 0x00000163 } },
	{ AR5K_RF_GAIN(17),	{ 0x000001a3, 0x000001a3 } },
	{ AR5K_RF_GAIN(18),	{ 0x000001e3, 0x000001e3 } },
	{ AR5K_RF_GAIN(19),	{ 0x00000023, 0x00000023 } },
	{ AR5K_RF_GAIN(20),	{ 0x00000063, 0x00000063 } },
	{ AR5K_RF_GAIN(21),	{ 0x00000184, 0x00000184 } },
	{ AR5K_RF_GAIN(22),	{ 0x000001c4, 0x000001c4 } },
	{ AR5K_RF_GAIN(23),	{ 0x00000004, 0x00000004 } },
	{ AR5K_RF_GAIN(24),	{ 0x000001ea, 0x0000000b } },
	{ AR5K_RF_GAIN(25),	{ 0x0000002a, 0x0000004b } },
	{ AR5K_RF_GAIN(26),	{ 0x0000006a, 0x0000008b } },
	{ AR5K_RF_GAIN(27),	{ 0x000000aa, 0x000001ac } },
	{ AR5K_RF_GAIN(28),	{ 0x000001ab, 0x000001ec } },
	{ AR5K_RF_GAIN(29),	{ 0x000001eb, 0x0000002c } },
	{ AR5K_RF_GAIN(30),	{ 0x0000002b, 0x00000012 } },
	{ AR5K_RF_GAIN(31),	{ 0x0000006b, 0x00000052 } },
	{ AR5K_RF_GAIN(32),	{ 0x000000ab, 0x00000092 } },
	{ AR5K_RF_GAIN(33),	{ 0x000001ac, 0x00000193 } },
	{ AR5K_RF_GAIN(34),	{ 0x000001ec, 0x000001d3 } },
	{ AR5K_RF_GAIN(35),	{ 0x0000002c, 0x00000013 } },
	{ AR5K_RF_GAIN(36),	{ 0x0000003a, 0x00000053 } },
	{ AR5K_RF_GAIN(37),	{ 0x0000007a, 0x00000093 } },
	{ AR5K_RF_GAIN(38),	{ 0x000000ba, 0x00000194 } },
	{ AR5K_RF_GAIN(39),	{ 0x000001bb, 0x000001d4 } },
	{ AR5K_RF_GAIN(40),	{ 0x000001fb, 0x00000014 } },
	{ AR5K_RF_GAIN(41),	{ 0x0000003b, 0x0000003a } },
	{ AR5K_RF_GAIN(42),	{ 0x0000007b, 0x0000007a } },
	{ AR5K_RF_GAIN(43),	{ 0x000000bb, 0x000000ba } },
	{ AR5K_RF_GAIN(44),	{ 0x000001bc, 0x000001bb } },
	{ AR5K_RF_GAIN(45),	{ 0x000001fc, 0x000001fb } },
	{ AR5K_RF_GAIN(46),	{ 0x0000003c, 0x0000003b } },
	{ AR5K_RF_GAIN(47),	{ 0x0000007c, 0x0000007b } },
	{ AR5K_RF_GAIN(48),	{ 0x000000bc, 0x000000bb } },
	{ AR5K_RF_GAIN(49),	{ 0x000000fc, 0x000001bc } },
	{ AR5K_RF_GAIN(50),	{ 0x000000fc, 0x000001fc } },
	{ AR5K_RF_GAIN(51),	{ 0x000000fc, 0x0000003c } },
	{ AR5K_RF_GAIN(52),	{ 0x000000fc, 0x0000007c } },
	{ AR5K_RF_GAIN(53),	{ 0x000000fc, 0x000000bc } },
	{ AR5K_RF_GAIN(54),	{ 0x000000fc, 0x000000fc } },
	{ AR5K_RF_GAIN(55),	{ 0x000000fc, 0x000000fc } },
	{ AR5K_RF_GAIN(56),	{ 0x000000fc, 0x000000fc } },
	{ AR5K_RF_GAIN(57),	{ 0x000000fc, 0x000000fc } },
	{ AR5K_RF_GAIN(58),	{ 0x000000fc, 0x000000fc } },
	{ AR5K_RF_GAIN(59),	{ 0x000000fc, 0x000000fc } },
	{ AR5K_RF_GAIN(60),	{ 0x000000fc, 0x000000fc } },
	{ AR5K_RF_GAIN(61),	{ 0x000000fc, 0x000000fc } },
	{ AR5K_RF_GAIN(62),	{ 0x000000fc, 0x000000fc } },
	{ AR5K_RF_GAIN(63),	{ 0x000000fc, 0x000000fc } },
};

/* Initial RF Gain settings for RF5413 */
static const struct ath5k_ini_rfgain rfgain_5413[] = {
	/*			      5Ghz	2Ghz	*/
	{ AR5K_RF_GAIN(0),	{ 0x00000000, 0x00000000 } },
	{ AR5K_RF_GAIN(1),	{ 0x00000040, 0x00000040 } },
	{ AR5K_RF_GAIN(2),	{ 0x00000080, 0x00000080 } },
	{ AR5K_RF_GAIN(3),	{ 0x000001a1, 0x00000161 } },
	{ AR5K_RF_GAIN(4),	{ 0x000001e1, 0x000001a1 } },
	{ AR5K_RF_GAIN(5),	{ 0x00000021, 0x000001e1 } },
	{ AR5K_RF_GAIN(6),	{ 0x00000061, 0x00000021 } },
	{ AR5K_RF_GAIN(7),	{ 0x00000188, 0x00000061 } },
	{ AR5K_RF_GAIN(8),	{ 0x000001c8, 0x00000188 } },
	{ AR5K_RF_GAIN(9),	{ 0x00000008, 0x000001c8 } },
	{ AR5K_RF_GAIN(10),	{ 0x00000048, 0x00000008 } },
	{ AR5K_RF_GAIN(11),	{ 0x00000088, 0x00000048 } },
	{ AR5K_RF_GAIN(12),	{ 0x000001a9, 0x00000088 } },
	{ AR5K_RF_GAIN(13),	{ 0x000001e9, 0x00000169 } },
	{ AR5K_RF_GAIN(14),	{ 0x00000029, 0x000001a9 } },
	{ AR5K_RF_GAIN(15),	{ 0x00000069, 0x000001e9 } },
	{ AR5K_RF_GAIN(16),	{ 0x000001d0, 0x00000029 } },
	{ AR5K_RF_GAIN(17),	{ 0x00000010, 0x00000069 } },
	{ AR5K_RF_GAIN(18),	{ 0x00000050, 0x00000190 } },
	{ AR5K_RF_GAIN(19),	{ 0x00000090, 0x000001d0 } },
	{ AR5K_RF_GAIN(20),	{ 0x000001b1, 0x00000010 } },
	{ AR5K_RF_GAIN(21),	{ 0x000001f1, 0x00000050 } },
	{ AR5K_RF_GAIN(22),	{ 0x00000031, 0x00000090 } },
	{ AR5K_RF_GAIN(23),	{ 0x00000071, 0x00000171 } },
	{ AR5K_RF_GAIN(24),	{ 0x000001b8, 0x000001b1 } },
	{ AR5K_RF_GAIN(25),	{ 0x000001f8, 0x000001f1 } },
	{ AR5K_RF_GAIN(26),	{ 0x00000038, 0x00000031 } },
	{ AR5K_RF_GAIN(27),	{ 0x00000078, 0x00000071 } },
	{ AR5K_RF_GAIN(28),	{ 0x00000199, 0x00000198 } },
	{ AR5K_RF_GAIN(29),	{ 0x000001d9, 0x000001d8 } },
	{ AR5K_RF_GAIN(30),	{ 0x00000019, 0x00000018 } },
	{ AR5K_RF_GAIN(31),	{ 0x00000059, 0x00000058 } },
	{ AR5K_RF_GAIN(32),	{ 0x00000099, 0x00000098 } },
	{ AR5K_RF_GAIN(33),	{ 0x000000d9, 0x00000179 } },
	{ AR5K_RF_GAIN(34),	{ 0x000000f9, 0x000001b9 } },
	{ AR5K_RF_GAIN(35),	{ 0x000000f9, 0x000001f9 } },
	{ AR5K_RF_GAIN(36),	{ 0x000000f9, 0x00000039 } },
	{ AR5K_RF_GAIN(37),	{ 0x000000f9, 0x00000079 } },
	{ AR5K_RF_GAIN(38),	{ 0x000000f9, 0x000000b9 } },
	{ AR5K_RF_GAIN(39),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(40),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(41),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(42),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(43),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(44),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(45),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(46),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(47),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(48),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(49),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(50),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(51),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(52),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(53),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(54),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(55),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(56),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(57),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(58),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(59),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(60),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(61),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(62),	{ 0x000000f9, 0x000000f9 } },
	{ AR5K_RF_GAIN(63),	{ 0x000000f9, 0x000000f9 } },
};

955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
/* Initial RF Gain settings for RF2413 */
static const struct ath5k_ini_rfgain rfgain_2413[] = {
	{ AR5K_RF_GAIN(0), { 0x00000000 } },
	{ AR5K_RF_GAIN(1), { 0x00000040 } },
	{ AR5K_RF_GAIN(2), { 0x00000080 } },
	{ AR5K_RF_GAIN(3), { 0x00000181 } },
	{ AR5K_RF_GAIN(4), { 0x000001c1 } },
	{ AR5K_RF_GAIN(5), { 0x00000001 } },
	{ AR5K_RF_GAIN(6), { 0x00000041 } },
	{ AR5K_RF_GAIN(7), { 0x00000081 } },
	{ AR5K_RF_GAIN(8), { 0x00000168 } },
	{ AR5K_RF_GAIN(9), { 0x000001a8 } },
	{ AR5K_RF_GAIN(10), { 0x000001e8 } },
	{ AR5K_RF_GAIN(11), { 0x00000028 } },
	{ AR5K_RF_GAIN(12), { 0x00000068 } },
	{ AR5K_RF_GAIN(13), { 0x00000189 } },
	{ AR5K_RF_GAIN(14), { 0x000001c9 } },
	{ AR5K_RF_GAIN(15), { 0x00000009 } },
	{ AR5K_RF_GAIN(16), { 0x00000049 } },
	{ AR5K_RF_GAIN(17), { 0x00000089 } },
	{ AR5K_RF_GAIN(18), { 0x00000190 } },
	{ AR5K_RF_GAIN(19), { 0x000001d0 } },
	{ AR5K_RF_GAIN(20), { 0x00000010 } },
	{ AR5K_RF_GAIN(21), { 0x00000050 } },
	{ AR5K_RF_GAIN(22), { 0x00000090 } },
	{ AR5K_RF_GAIN(23), { 0x00000191 } },
	{ AR5K_RF_GAIN(24), { 0x000001d1 } },
	{ AR5K_RF_GAIN(25), { 0x00000011 } },
	{ AR5K_RF_GAIN(26), { 0x00000051 } },
	{ AR5K_RF_GAIN(27), { 0x00000091 } },
	{ AR5K_RF_GAIN(28), { 0x00000178 } },
	{ AR5K_RF_GAIN(29), { 0x000001b8 } },
	{ AR5K_RF_GAIN(30), { 0x000001f8 } },
	{ AR5K_RF_GAIN(31), { 0x00000038 } },
	{ AR5K_RF_GAIN(32), { 0x00000078 } },
	{ AR5K_RF_GAIN(33), { 0x00000199 } },
	{ AR5K_RF_GAIN(34), { 0x000001d9 } },
	{ AR5K_RF_GAIN(35), { 0x00000019 } },
	{ AR5K_RF_GAIN(36), { 0x00000059 } },
	{ AR5K_RF_GAIN(37), { 0x00000099 } },
	{ AR5K_RF_GAIN(38), { 0x000000d9 } },
	{ AR5K_RF_GAIN(39), { 0x000000f9 } },
	{ AR5K_RF_GAIN(40), { 0x000000f9 } },
	{ AR5K_RF_GAIN(41), { 0x000000f9 } },
	{ AR5K_RF_GAIN(42), { 0x000000f9 } },
	{ AR5K_RF_GAIN(43), { 0x000000f9 } },
	{ AR5K_RF_GAIN(44), { 0x000000f9 } },
	{ AR5K_RF_GAIN(45), { 0x000000f9 } },
	{ AR5K_RF_GAIN(46), { 0x000000f9 } },
	{ AR5K_RF_GAIN(47), { 0x000000f9 } },
	{ AR5K_RF_GAIN(48), { 0x000000f9 } },
	{ AR5K_RF_GAIN(49), { 0x000000f9 } },
	{ AR5K_RF_GAIN(50), { 0x000000f9 } },
	{ AR5K_RF_GAIN(51), { 0x000000f9 } },
	{ AR5K_RF_GAIN(52), { 0x000000f9 } },
	{ AR5K_RF_GAIN(53), { 0x000000f9 } },
	{ AR5K_RF_GAIN(54), { 0x000000f9 } },
	{ AR5K_RF_GAIN(55), { 0x000000f9 } },
	{ AR5K_RF_GAIN(56), { 0x000000f9 } },
	{ AR5K_RF_GAIN(57), { 0x000000f9 } },
	{ AR5K_RF_GAIN(58), { 0x000000f9 } },
	{ AR5K_RF_GAIN(59), { 0x000000f9 } },
	{ AR5K_RF_GAIN(60), { 0x000000f9 } },
	{ AR5K_RF_GAIN(61), { 0x000000f9 } },
	{ AR5K_RF_GAIN(62), { 0x000000f9 } },
	{ AR5K_RF_GAIN(63), { 0x000000f9 } },
};

1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
/* Initial RF Gain settings for RF2425 */
static const struct ath5k_ini_rfgain rfgain_2425[] = {
	{ AR5K_RF_GAIN(0), { 0x00000000 } },
	{ AR5K_RF_GAIN(1), { 0x00000040 } },
	{ AR5K_RF_GAIN(2), { 0x00000080 } },
	{ AR5K_RF_GAIN(3), { 0x00000181 } },
	{ AR5K_RF_GAIN(4), { 0x000001c1 } },
	{ AR5K_RF_GAIN(5), { 0x00000001 } },
	{ AR5K_RF_GAIN(6), { 0x00000041 } },
	{ AR5K_RF_GAIN(7), { 0x00000081 } },
	{ AR5K_RF_GAIN(8), { 0x00000188 } },
	{ AR5K_RF_GAIN(9), { 0x000001c8 } },
	{ AR5K_RF_GAIN(10), { 0x00000008 } },
	{ AR5K_RF_GAIN(11), { 0x00000048 } },
	{ AR5K_RF_GAIN(12), { 0x00000088 } },
	{ AR5K_RF_GAIN(13), { 0x00000189 } },
	{ AR5K_RF_GAIN(14), { 0x000001c9 } },
	{ AR5K_RF_GAIN(15), { 0x00000009 } },
	{ AR5K_RF_GAIN(16), { 0x00000049 } },
	{ AR5K_RF_GAIN(17), { 0x00000089 } },
	{ AR5K_RF_GAIN(18), { 0x000001b0 } },
	{ AR5K_RF_GAIN(19), { 0x000001f0 } },
	{ AR5K_RF_GAIN(20), { 0x00000030 } },
	{ AR5K_RF_GAIN(21), { 0x00000070 } },
	{ AR5K_RF_GAIN(22), { 0x00000171 } },
	{ AR5K_RF_GAIN(23), { 0x000001b1 } },
	{ AR5K_RF_GAIN(24), { 0x000001f1 } },
	{ AR5K_RF_GAIN(25), { 0x00000031 } },
	{ AR5K_RF_GAIN(26), { 0x00000071 } },
	{ AR5K_RF_GAIN(27), { 0x000001b8 } },
	{ AR5K_RF_GAIN(28), { 0x000001f8 } },
	{ AR5K_RF_GAIN(29), { 0x00000038 } },
	{ AR5K_RF_GAIN(30), { 0x00000078 } },
	{ AR5K_RF_GAIN(31), { 0x000000b8 } },
	{ AR5K_RF_GAIN(32), { 0x000001b9 } },
	{ AR5K_RF_GAIN(33), { 0x000001f9 } },
	{ AR5K_RF_GAIN(34), { 0x00000039 } },
	{ AR5K_RF_GAIN(35), { 0x00000079 } },
	{ AR5K_RF_GAIN(36), { 0x000000b9 } },
	{ AR5K_RF_GAIN(37), { 0x000000f9 } },
	{ AR5K_RF_GAIN(38), { 0x000000f9 } },
	{ AR5K_RF_GAIN(39), { 0x000000f9 } },
	{ AR5K_RF_GAIN(40), { 0x000000f9 } },
	{ AR5K_RF_GAIN(41), { 0x000000f9 } },
	{ AR5K_RF_GAIN(42), { 0x000000f9 } },
	{ AR5K_RF_GAIN(43), { 0x000000f9 } },
	{ AR5K_RF_GAIN(44), { 0x000000f9 } },
	{ AR5K_RF_GAIN(45), { 0x000000f9 } },
	{ AR5K_RF_GAIN(46), { 0x000000f9 } },
	{ AR5K_RF_GAIN(47), { 0x000000f9 } },
	{ AR5K_RF_GAIN(48), { 0x000000f9 } },
	{ AR5K_RF_GAIN(49), { 0x000000f9 } },
	{ AR5K_RF_GAIN(50), { 0x000000f9 } },
	{ AR5K_RF_GAIN(51), { 0x000000f9 } },
	{ AR5K_RF_GAIN(52), { 0x000000f9 } },
	{ AR5K_RF_GAIN(53), { 0x000000f9 } },
	{ AR5K_RF_GAIN(54), { 0x000000f9 } },
	{ AR5K_RF_GAIN(55), { 0x000000f9 } },
	{ AR5K_RF_GAIN(56), { 0x000000f9 } },
	{ AR5K_RF_GAIN(57), { 0x000000f9 } },
	{ AR5K_RF_GAIN(58), { 0x000000f9 } },
	{ AR5K_RF_GAIN(59), { 0x000000f9 } },
	{ AR5K_RF_GAIN(60), { 0x000000f9 } },
	{ AR5K_RF_GAIN(61), { 0x000000f9 } },
	{ AR5K_RF_GAIN(62), { 0x000000f9 } },
	{ AR5K_RF_GAIN(63), { 0x000000f9 } },
};

1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
static const struct ath5k_gain_opt rfgain_opt_5112 = {
	1,
	8,
	{
		{ { 3, 0, 0, 0, 0, 0, 0 }, 6 },
		{ { 2, 0, 0, 0, 0, 0, 0 }, 0 },
		{ { 1, 0, 0, 0, 0, 0, 0 }, -3 },
		{ { 0, 0, 0, 0, 0, 0, 0 }, -6 },
		{ { 0, 1, 1, 0, 0, 0, 0 }, -8 },
		{ { 0, 1, 1, 0, 1, 1, 0 }, -10 },
		{ { 0, 1, 0, 1, 1, 1, 0 }, -13 },
		{ { 0, 1, 0, 1, 1, 0, 1 }, -16 },
	}
};

/*
 * Used to modify RF Banks before writing them to AR5K_RF_BUFFER
 */
static unsigned int ath5k_hw_rfregs_op(u32 *rf, u32 offset, u32 reg, u32 bits,
		u32 first, u32 col, bool set)
{
	u32 mask, entry, last, data, shift, position;
	s32 left;
	int i;

	data = 0;

	if (rf == NULL)
		/* should not happen */
		return 0;

	if (!(col <= 3 && bits <= 32 && first + bits <= 319)) {
		ATH5K_PRINTF("invalid values at offset %u\n", offset);
		return 0;
	}

	entry = ((first - 1) / 8) + offset;
	position = (first - 1) % 8;

1130
	if (set)
1131 1132 1133 1134 1135 1136
		data = ath5k_hw_bitswap(reg, bits);

	for (i = shift = 0, left = bits; left > 0; position = 0, entry++, i++) {
		last = (position + left > 8) ? 8 : position + left;
		mask = (((1 << last) - 1) ^ ((1 << position) - 1)) << (col * 8);

1137
		if (set) {
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
			rf[entry] &= ~mask;
			rf[entry] |= ((data << position) << (col * 8)) & mask;
			data >>= (8 - position);
		} else {
			data = (((rf[entry] & mask) >> (col * 8)) >> position)
				<< shift;
			shift += last - position;
		}

		left -= 8 - position;
	}

1150
	data = set ? 1 : ath5k_hw_bitswap(data, bits);
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302

	return data;
}

static u32 ath5k_hw_rfregs_gainf_corr(struct ath5k_hw *ah)
{
	u32 mix, step;
	u32 *rf;

	if (ah->ah_rf_banks == NULL)
		return 0;

	rf = ah->ah_rf_banks;
	ah->ah_gain.g_f_corr = 0;

	if (ath5k_hw_rfregs_op(rf, ah->ah_offset[7], 0, 1, 36, 0, false) != 1)
		return 0;

	step = ath5k_hw_rfregs_op(rf, ah->ah_offset[7], 0, 4, 32, 0, false);
	mix = ah->ah_gain.g_step->gos_param[0];

	switch (mix) {
	case 3:
		ah->ah_gain.g_f_corr = step * 2;
		break;
	case 2:
		ah->ah_gain.g_f_corr = (step - 5) * 2;
		break;
	case 1:
		ah->ah_gain.g_f_corr = step;
		break;
	default:
		ah->ah_gain.g_f_corr = 0;
		break;
	}

	return ah->ah_gain.g_f_corr;
}

static bool ath5k_hw_rfregs_gain_readback(struct ath5k_hw *ah)
{
	u32 step, mix, level[4];
	u32 *rf;

	if (ah->ah_rf_banks == NULL)
		return false;

	rf = ah->ah_rf_banks;

	if (ah->ah_radio == AR5K_RF5111) {
		step = ath5k_hw_rfregs_op(rf, ah->ah_offset[7], 0, 6, 37, 0,
				false);
		level[0] = 0;
		level[1] = (step == 0x3f) ? 0x32 : step + 4;
		level[2] = (step != 0x3f) ? 0x40 : level[0];
		level[3] = level[2] + 0x32;

		ah->ah_gain.g_high = level[3] -
			(step == 0x3f ? AR5K_GAIN_DYN_ADJUST_HI_MARGIN : -5);
		ah->ah_gain.g_low = level[0] +
			(step == 0x3f ? AR5K_GAIN_DYN_ADJUST_LO_MARGIN : 0);
	} else {
		mix = ath5k_hw_rfregs_op(rf, ah->ah_offset[7], 0, 1, 36, 0,
				false);
		level[0] = level[2] = 0;

		if (mix == 1) {
			level[1] = level[3] = 83;
		} else {
			level[1] = level[3] = 107;
			ah->ah_gain.g_high = 55;
		}
	}

	return (ah->ah_gain.g_current >= level[0] &&
			ah->ah_gain.g_current <= level[1]) ||
		(ah->ah_gain.g_current >= level[2] &&
			ah->ah_gain.g_current <= level[3]);
}

static s32 ath5k_hw_rfregs_gain_adjust(struct ath5k_hw *ah)
{
	const struct ath5k_gain_opt *go;
	int ret = 0;

	switch (ah->ah_radio) {
	case AR5K_RF5111:
		go = &rfgain_opt_5111;
		break;
	case AR5K_RF5112:
		go = &rfgain_opt_5112;
		break;
	default:
		return 0;
	}

	ah->ah_gain.g_step = &go->go_step[ah->ah_gain.g_step_idx];

	if (ah->ah_gain.g_current >= ah->ah_gain.g_high) {
		if (ah->ah_gain.g_step_idx == 0)
			return -1;
		for (ah->ah_gain.g_target = ah->ah_gain.g_current;
				ah->ah_gain.g_target >=  ah->ah_gain.g_high &&
				ah->ah_gain.g_step_idx > 0;
				ah->ah_gain.g_step =
					&go->go_step[ah->ah_gain.g_step_idx])
			ah->ah_gain.g_target -= 2 *
			    (go->go_step[--(ah->ah_gain.g_step_idx)].gos_gain -
			    ah->ah_gain.g_step->gos_gain);

		ret = 1;
		goto done;
	}

	if (ah->ah_gain.g_current <= ah->ah_gain.g_low) {
		if (ah->ah_gain.g_step_idx == (go->go_steps_count - 1))
			return -2;
		for (ah->ah_gain.g_target = ah->ah_gain.g_current;
				ah->ah_gain.g_target <= ah->ah_gain.g_low &&
				ah->ah_gain.g_step_idx < go->go_steps_count-1;
				ah->ah_gain.g_step =
					&go->go_step[ah->ah_gain.g_step_idx])
			ah->ah_gain.g_target -= 2 *
			    (go->go_step[++ah->ah_gain.g_step_idx].gos_gain -
			    ah->ah_gain.g_step->gos_gain);

		ret = 2;
		goto done;
	}

done:
	ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_CALIBRATE,
		"ret %d, gain step %u, current gain %u, target gain %u\n",
		ret, ah->ah_gain.g_step_idx, ah->ah_gain.g_current,
		ah->ah_gain.g_target);

	return ret;
}

/*
 * Read EEPROM Calibration data, modify RF Banks and Initialize RF5111
 */
static int ath5k_hw_rf5111_rfregs(struct ath5k_hw *ah,
		struct ieee80211_channel *channel, unsigned int mode)
{
	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
	u32 *rf;
	const unsigned int rf_size = ARRAY_SIZE(rfregs_5111);
	unsigned int i;
	int obdb = -1, bank = -1;
	u32 ee_mode;

1303
	AR5K_ASSERT_ENTRY(mode, AR5K_MODE_MAX);
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322

	rf = ah->ah_rf_banks;

	/* Copy values to modify them */
	for (i = 0; i < rf_size; i++) {
		if (rfregs_5111[i].rf_bank >= AR5K_RF5111_INI_RF_MAX_BANKS) {
			ATH5K_ERR(ah->ah_sc, "invalid bank\n");
			return -EINVAL;
		}

		if (bank != rfregs_5111[i].rf_bank) {
			bank = rfregs_5111[i].rf_bank;
			ah->ah_offset[bank] = i;
		}

		rf[i] = rfregs_5111[i].rf_value[mode];
	}

	/* Modify bank 0 */
1323 1324
	if (channel->hw_value & CHANNEL_2GHZ) {
		if (channel->hw_value & CHANNEL_CCK)
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
			ee_mode = AR5K_EEPROM_MODE_11B;
		else
			ee_mode = AR5K_EEPROM_MODE_11G;
		obdb = 0;

		if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[0],
				ee->ee_ob[ee_mode][obdb], 3, 119, 0, true))
			return -EINVAL;

		if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[0],
				ee->ee_ob[ee_mode][obdb], 3, 122, 0, true))
			return -EINVAL;

		obdb = 1;
	/* Modify bank 6 */
	} else {
		/* For 11a, Turbo and XR */
		ee_mode = AR5K_EEPROM_MODE_11A;
1343 1344 1345 1346
		obdb =	 channel->center_freq >= 5725 ? 3 :
			(channel->center_freq >= 5500 ? 2 :
			(channel->center_freq >= 5260 ? 1 :
			 (channel->center_freq > 4000 ? 0 : -1)));
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403

		if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
				ee->ee_pwd_84, 1, 51, 3, true))
			return -EINVAL;

		if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
				ee->ee_pwd_90, 1, 45, 3, true))
			return -EINVAL;
	}

	if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
			!ee->ee_xpd[ee_mode], 1, 95, 0, true))
		return -EINVAL;

	if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
			ee->ee_x_gain[ee_mode], 4, 96, 0, true))
		return -EINVAL;

	if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6], obdb >= 0 ?
			ee->ee_ob[ee_mode][obdb] : 0, 3, 104, 0, true))
		return -EINVAL;

	if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6], obdb >= 0 ?
			ee->ee_db[ee_mode][obdb] : 0, 3, 107, 0, true))
		return -EINVAL;

	/* Modify bank 7 */
	if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[7],
			ee->ee_i_gain[ee_mode], 6, 29, 0, true))
		return -EINVAL;

	if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[7],
			ee->ee_xpd[ee_mode], 1, 4, 0, true))
		return -EINVAL;

	/* Write RF values */
	for (i = 0; i < rf_size; i++) {
		AR5K_REG_WAIT(i);
		ath5k_hw_reg_write(ah, rf[i], rfregs_5111[i].rf_register);
	}

	return 0;
}

/*
 * Read EEPROM Calibration data, modify RF Banks and Initialize RF5112
 */
static int ath5k_hw_rf5112_rfregs(struct ath5k_hw *ah,
		struct ieee80211_channel *channel, unsigned int mode)
{
	const struct ath5k_ini_rf *rf_ini;
	struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
	u32 *rf;
	unsigned int rf_size, i;
	int obdb = -1, bank = -1;
	u32 ee_mode;

1404
	AR5K_ASSERT_ENTRY(mode, AR5K_MODE_MAX);
1405 1406 1407 1408

	rf = ah->ah_rf_banks;

	if (ah->ah_radio_5ghz_revision >= AR5K_SREV_RAD_2112A
1409
		&& !test_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode)) {
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
		rf_ini = rfregs_2112a;
		rf_size = ARRAY_SIZE(rfregs_5112a);
		if (mode < 2) {
			ATH5K_ERR(ah->ah_sc,"invalid channel mode: %i\n",mode);
			return -EINVAL;
		}
		mode = mode - 2; /*no a/turboa modes for 2112*/
	} else if (ah->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A) {
		rf_ini = rfregs_5112a;
		rf_size = ARRAY_SIZE(rfregs_5112a);
	} else {
		rf_ini = rfregs_5112;
		rf_size = ARRAY_SIZE(rfregs_5112);
	}

	/* Copy values to modify them */
	for (i = 0; i < rf_size; i++) {
		if (rf_ini[i].rf_bank >= AR5K_RF5112_INI_RF_MAX_BANKS) {
			ATH5K_ERR(ah->ah_sc, "invalid bank\n");
			return -EINVAL;
		}

		if (bank != rf_ini[i].rf_bank) {
			bank = rf_ini[i].rf_bank;
			ah->ah_offset[bank] = i;
		}

		rf[i] = rf_ini[i].rf_value[mode];
	}

	/* Modify bank 6 */
1441 1442
	if (channel->hw_value & CHANNEL_2GHZ) {
		if (channel->hw_value & CHANNEL_OFDM)
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
			ee_mode = AR5K_EEPROM_MODE_11G;
		else
			ee_mode = AR5K_EEPROM_MODE_11B;
		obdb = 0;

		if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
				ee->ee_ob[ee_mode][obdb], 3, 287, 0, true))
			return -EINVAL;

		if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
				ee->ee_ob[ee_mode][obdb], 3, 290, 0, true))
			return -EINVAL;
	} else {
		/* For 11a, Turbo and XR */
		ee_mode = AR5K_EEPROM_MODE_11A;
1458 1459 1460 1461
		obdb = channel->center_freq >= 5725 ? 3 :
		    (channel->center_freq >= 5500 ? 2 :
			(channel->center_freq >= 5260 ? 1 :
			    (channel->center_freq > 4000 ? 0 : -1)));
1462

1463 1464 1465
		if (obdb == -1)
			return -EINVAL;

1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
		if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
				ee->ee_ob[ee_mode][obdb], 3, 279, 0, true))
			return -EINVAL;

		if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
				ee->ee_ob[ee_mode][obdb], 3, 282, 0, true))
			return -EINVAL;
	}

	ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
	    ee->ee_x_gain[ee_mode], 2, 270, 0, true);
	ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
	    ee->ee_x_gain[ee_mode], 2, 257, 0, true);

	if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[6],
			ee->ee_xpd[ee_mode], 1, 302, 0, true))
		return -EINVAL;

	/* Modify bank 7 */
	if (!ath5k_hw_rfregs_op(rf, ah->ah_offset[7],
			ee->ee_i_gain[ee_mode], 6, 14, 0, true))
		return -EINVAL;

	/* Write RF values */
	for (i = 0; i < rf_size; i++)
		ath5k_hw_reg_write(ah, rf[i], rf_ini[i].rf_register);

	return 0;
}

/*
N
Nick Kossifidis 已提交
1497 1498
 * Initialize RF5413/5414 and future chips
 * (until we come up with a better solution)
1499 1500 1501 1502 1503 1504 1505 1506 1507
 */
static int ath5k_hw_rf5413_rfregs(struct ath5k_hw *ah,
		struct ieee80211_channel *channel, unsigned int mode)
{
	const struct ath5k_ini_rf *rf_ini;
	u32 *rf;
	unsigned int rf_size, i;
	int bank = -1;

1508
	AR5K_ASSERT_ENTRY(mode, AR5K_MODE_MAX);
1509 1510 1511

	rf = ah->ah_rf_banks;

N
Nick Kossifidis 已提交
1512 1513
	switch (ah->ah_radio) {
	case AR5K_RF5413:
1514 1515
		rf_ini = rfregs_5413;
		rf_size = ARRAY_SIZE(rfregs_5413);
N
Nick Kossifidis 已提交
1516 1517
		break;
	case AR5K_RF2413:
1518 1519
		rf_ini = rfregs_2413;
		rf_size = ARRAY_SIZE(rfregs_2413);
N
Nick Kossifidis 已提交
1520

1521 1522 1523 1524 1525
		if (mode < 2) {
			ATH5K_ERR(ah->ah_sc,
				"invalid channel mode: %i\n", mode);
			return -EINVAL;
		}
N
Nick Kossifidis 已提交
1526

1527
		mode = mode - 2;
N
Nick Kossifidis 已提交
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546
		break;
	case AR5K_RF2425:
		rf_ini = rfregs_2425;
		rf_size = ARRAY_SIZE(rfregs_2425);

		if (mode < 2) {
			ATH5K_ERR(ah->ah_sc,
				"invalid channel mode: %i\n", mode);
			return -EINVAL;
		}

		/* Map b to g */
		if (mode == 2)
			mode = 0;
		else
			mode = mode - 3;

		break;
	default:
1547 1548
		return -EINVAL;
	}
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606

	/* Copy values to modify them */
	for (i = 0; i < rf_size; i++) {
		if (rf_ini[i].rf_bank >= AR5K_RF5112_INI_RF_MAX_BANKS) {
			ATH5K_ERR(ah->ah_sc, "invalid bank\n");
			return -EINVAL;
		}

		if (bank != rf_ini[i].rf_bank) {
			bank = rf_ini[i].rf_bank;
			ah->ah_offset[bank] = i;
		}

		rf[i] = rf_ini[i].rf_value[mode];
	}

	/*
	 * After compairing dumps from different cards
	 * we get the same RF_BUFFER settings (diff returns
	 * 0 lines). It seems that RF_BUFFER settings are static
	 * and are written unmodified (no EEPROM stuff
	 * is used because calibration data would be
	 * different between different cards and would result
	 * different RF_BUFFER settings)
	 */

	/* Write RF values */
	for (i = 0; i < rf_size; i++)
		ath5k_hw_reg_write(ah, rf[i], rf_ini[i].rf_register);

	return 0;
}

/*
 * Initialize RF
 */
int ath5k_hw_rfregs(struct ath5k_hw *ah, struct ieee80211_channel *channel,
		unsigned int mode)
{
	int (*func)(struct ath5k_hw *, struct ieee80211_channel *, unsigned int);
	int ret;

	switch (ah->ah_radio) {
	case AR5K_RF5111:
		ah->ah_rf_banks_size = sizeof(rfregs_5111);
		func = ath5k_hw_rf5111_rfregs;
		break;
	case AR5K_RF5112:
		if (ah->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A)
			ah->ah_rf_banks_size = sizeof(rfregs_5112a);
		else
			ah->ah_rf_banks_size = sizeof(rfregs_5112);
		func = ath5k_hw_rf5112_rfregs;
		break;
	case AR5K_RF5413:
		ah->ah_rf_banks_size = sizeof(rfregs_5413);
		func = ath5k_hw_rf5413_rfregs;
		break;
1607 1608 1609 1610
	case AR5K_RF2413:
		ah->ah_rf_banks_size = sizeof(rfregs_2413);
		func = ath5k_hw_rf5413_rfregs;
		break;
N
Nick Kossifidis 已提交
1611 1612 1613 1614
	case AR5K_RF2425:
		ah->ah_rf_banks_size = sizeof(rfregs_2425);
		func = ath5k_hw_rf5413_rfregs;
		break;
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652
	default:
		return -EINVAL;
	}

	if (ah->ah_rf_banks == NULL) {
		/* XXX do extra checks? */
		ah->ah_rf_banks = kmalloc(ah->ah_rf_banks_size, GFP_KERNEL);
		if (ah->ah_rf_banks == NULL) {
			ATH5K_ERR(ah->ah_sc, "out of memory\n");
			return -ENOMEM;
		}
	}

	ret = func(ah, channel, mode);
	if (!ret)
		ah->ah_rf_gain = AR5K_RFGAIN_INACTIVE;

	return ret;
}

int ath5k_hw_rfgain(struct ath5k_hw *ah, unsigned int freq)
{
	const struct ath5k_ini_rfgain *ath5k_rfg;
	unsigned int i, size;

	switch (ah->ah_radio) {
	case AR5K_RF5111:
		ath5k_rfg = rfgain_5111;
		size = ARRAY_SIZE(rfgain_5111);
		break;
	case AR5K_RF5112:
		ath5k_rfg = rfgain_5112;
		size = ARRAY_SIZE(rfgain_5112);
		break;
	case AR5K_RF5413:
		ath5k_rfg = rfgain_5413;
		size = ARRAY_SIZE(rfgain_5413);
		break;
1653 1654 1655 1656 1657
	case AR5K_RF2413:
		ath5k_rfg = rfgain_2413;
		size = ARRAY_SIZE(rfgain_2413);
		freq = 0; /* only 2Ghz */
		break;
N
Nick Kossifidis 已提交
1658
	case AR5K_RF2425:
1659 1660
		ath5k_rfg = rfgain_2425;
		size = ARRAY_SIZE(rfgain_2425);
N
Nick Kossifidis 已提交
1661 1662
		freq = 0; /* only 2Ghz */
		break;
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
	default:
		return -EINVAL;
	}

	switch (freq) {
	case AR5K_INI_RFGAIN_2GHZ:
	case AR5K_INI_RFGAIN_5GHZ:
		break;
	default:
		return -EINVAL;
	}

	for (i = 0; i < size; i++) {
		AR5K_REG_WAIT(i);
		ath5k_hw_reg_write(ah, ath5k_rfg[i].rfg_value[freq],
			(u32)ath5k_rfg[i].rfg_register);
	}

	return 0;
}

enum ath5k_rfgain ath5k_hw_get_rf_gain(struct ath5k_hw *ah)
{
	u32 data, type;

	ATH5K_TRACE(ah->ah_sc);

	if (ah->ah_rf_banks == NULL || !ah->ah_gain.g_active ||
			ah->ah_version <= AR5K_AR5211)
		return AR5K_RFGAIN_INACTIVE;

	if (ah->ah_rf_gain != AR5K_RFGAIN_READ_REQUESTED)
		goto done;

	data = ath5k_hw_reg_read(ah, AR5K_PHY_PAPD_PROBE);

	if (!(data & AR5K_PHY_PAPD_PROBE_TX_NEXT)) {
		ah->ah_gain.g_current = data >> AR5K_PHY_PAPD_PROBE_GAINF_S;
		type = AR5K_REG_MS(data, AR5K_PHY_PAPD_PROBE_TYPE);

		if (type == AR5K_PHY_PAPD_PROBE_TYPE_CCK)
			ah->ah_gain.g_current += AR5K_GAIN_CCK_PROBE_CORR;

		if (ah->ah_radio >= AR5K_RF5112) {
			ath5k_hw_rfregs_gainf_corr(ah);
			ah->ah_gain.g_current =
				ah->ah_gain.g_current>=ah->ah_gain.g_f_corr ?
				(ah->ah_gain.g_current-ah->ah_gain.g_f_corr) :
				0;
		}

		if (ath5k_hw_rfregs_gain_readback(ah) &&
				AR5K_GAIN_CHECK_ADJUST(&ah->ah_gain) &&
				ath5k_hw_rfregs_gain_adjust(ah))
			ah->ah_rf_gain = AR5K_RFGAIN_NEED_CHANGE;
	}

done:
	return ah->ah_rf_gain;
}

int ath5k_hw_set_rfgain_opt(struct ath5k_hw *ah)
{
	/* Initialize the gain optimization values */
	switch (ah->ah_radio) {
	case AR5K_RF5111:
		ah->ah_gain.g_step_idx = rfgain_opt_5111.go_default;
		ah->ah_gain.g_step =
		    &rfgain_opt_5111.go_step[ah->ah_gain.g_step_idx];
		ah->ah_gain.g_low = 20;
		ah->ah_gain.g_high = 35;
		ah->ah_gain.g_active = 1;
		break;
	case AR5K_RF5112:
		ah->ah_gain.g_step_idx = rfgain_opt_5112.go_default;
		ah->ah_gain.g_step =
		    &rfgain_opt_5112.go_step[ah->ah_gain.g_step_idx];
		ah->ah_gain.g_low = 20;
		ah->ah_gain.g_high = 85;
		ah->ah_gain.g_active = 1;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

/**************************\
  PHY/RF channel functions
\**************************/

/*
 * Check if a channel is supported
 */
bool ath5k_channel_ok(struct ath5k_hw *ah, u16 freq, unsigned int flags)
{
	/* Check if the channel is in our supported range */
	if (flags & CHANNEL_2GHZ) {
		if ((freq >= ah->ah_capabilities.cap_range.range_2ghz_min) &&
		    (freq <= ah->ah_capabilities.cap_range.range_2ghz_max))
			return true;
	} else if (flags & CHANNEL_5GHZ)
		if ((freq >= ah->ah_capabilities.cap_range.range_5ghz_min) &&
		    (freq <= ah->ah_capabilities.cap_range.range_5ghz_max))
			return true;

	return false;
}

/*
 * Convertion needed for RF5110
 */
static u32 ath5k_hw_rf5110_chan2athchan(struct ieee80211_channel *channel)
{
	u32 athchan;

	/*
	 * Convert IEEE channel/MHz to an internal channel value used
	 * by the AR5210 chipset. This has not been verified with
	 * newer chipsets like the AR5212A who have a completely
	 * different RF/PHY part.
	 */
1786 1787 1788 1789
	athchan = (ath5k_hw_bitswap(
			(ieee80211_frequency_to_channel(
				channel->center_freq) - 24) / 2, 5)
				<< 1) | (1 << 6) | 0x1;
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847
	return athchan;
}

/*
 * Set channel on RF5110
 */
static int ath5k_hw_rf5110_channel(struct ath5k_hw *ah,
		struct ieee80211_channel *channel)
{
	u32 data;

	/*
	 * Set the channel and wait
	 */
	data = ath5k_hw_rf5110_chan2athchan(channel);
	ath5k_hw_reg_write(ah, data, AR5K_RF_BUFFER);
	ath5k_hw_reg_write(ah, 0, AR5K_RF_BUFFER_CONTROL_0);
	mdelay(1);

	return 0;
}

/*
 * Convertion needed for 5111
 */
static int ath5k_hw_rf5111_chan2athchan(unsigned int ieee,
		struct ath5k_athchan_2ghz *athchan)
{
	int channel;

	/* Cast this value to catch negative channel numbers (>= -19) */
	channel = (int)ieee;

	/*
	 * Map 2GHz IEEE channel to 5GHz Atheros channel
	 */
	if (channel <= 13) {
		athchan->a2_athchan = 115 + channel;
		athchan->a2_flags = 0x46;
	} else if (channel == 14) {
		athchan->a2_athchan = 124;
		athchan->a2_flags = 0x44;
	} else if (channel >= 15 && channel <= 26) {
		athchan->a2_athchan = ((channel - 14) * 4) + 132;
		athchan->a2_flags = 0x46;
	} else
		return -EINVAL;

	return 0;
}

/*
 * Set channel on 5111
 */
static int ath5k_hw_rf5111_channel(struct ath5k_hw *ah,
		struct ieee80211_channel *channel)
{
	struct ath5k_athchan_2ghz ath5k_channel_2ghz;
1848 1849
	unsigned int ath5k_channel =
		ieee80211_frequency_to_channel(channel->center_freq);
1850 1851 1852 1853 1854 1855 1856 1857
	u32 data0, data1, clock;
	int ret;

	/*
	 * Set the channel on the RF5111 radio
	 */
	data0 = data1 = 0;

1858
	if (channel->hw_value & CHANNEL_2GHZ) {
1859
		/* Map 2GHz channel to 5GHz Atheros channel ID */
1860 1861 1862
		ret = ath5k_hw_rf5111_chan2athchan(
			ieee80211_frequency_to_channel(channel->center_freq),
			&ath5k_channel_2ghz);
1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
		if (ret)
			return ret;

		ath5k_channel = ath5k_channel_2ghz.a2_athchan;
		data0 = ((ath5k_hw_bitswap(ath5k_channel_2ghz.a2_flags, 8) & 0xff)
		    << 5) | (1 << 4);
	}

	if (ath5k_channel < 145 || !(ath5k_channel & 1)) {
		clock = 1;
		data1 = ((ath5k_hw_bitswap(ath5k_channel - 24, 8) & 0xff) << 2) |
			(clock << 1) | (1 << 10) | 1;
	} else {
		clock = 0;
		data1 = ((ath5k_hw_bitswap((ath5k_channel - 24) / 2, 8) & 0xff)
			<< 2) | (clock << 1) | (1 << 10) | 1;
	}

	ath5k_hw_reg_write(ah, (data1 & 0xff) | ((data0 & 0xff) << 8),
			AR5K_RF_BUFFER);
	ath5k_hw_reg_write(ah, ((data1 >> 8) & 0xff) | (data0 & 0xff00),
			AR5K_RF_BUFFER_CONTROL_3);

	return 0;
}

/*
 * Set channel on 5112 and newer
 */
static int ath5k_hw_rf5112_channel(struct ath5k_hw *ah,
		struct ieee80211_channel *channel)
{
	u32 data, data0, data1, data2;
	u16 c;

	data = data0 = data1 = data2 = 0;
1899
	c = channel->center_freq;
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943

	/*
	 * Set the channel on the RF5112 or newer
	 */
	if (c < 4800) {
		if (!((c - 2224) % 5)) {
			data0 = ((2 * (c - 704)) - 3040) / 10;
			data1 = 1;
		} else if (!((c - 2192) % 5)) {
			data0 = ((2 * (c - 672)) - 3040) / 10;
			data1 = 0;
		} else
			return -EINVAL;

		data0 = ath5k_hw_bitswap((data0 << 2) & 0xff, 8);
	} else {
		if (!(c % 20) && c >= 5120) {
			data0 = ath5k_hw_bitswap(((c - 4800) / 20 << 2), 8);
			data2 = ath5k_hw_bitswap(3, 2);
		} else if (!(c % 10)) {
			data0 = ath5k_hw_bitswap(((c - 4800) / 10 << 1), 8);
			data2 = ath5k_hw_bitswap(2, 2);
		} else if (!(c % 5)) {
			data0 = ath5k_hw_bitswap((c - 4800) / 5, 8);
			data2 = ath5k_hw_bitswap(1, 2);
		} else
			return -EINVAL;
	}

	data = (data0 << 4) | (data1 << 1) | (data2 << 2) | 0x1001;

	ath5k_hw_reg_write(ah, data & 0xff, AR5K_RF_BUFFER);
	ath5k_hw_reg_write(ah, (data >> 8) & 0x7f, AR5K_RF_BUFFER_CONTROL_5);

	return 0;
}

/*
 * Set a channel on the radio chip
 */
int ath5k_hw_channel(struct ath5k_hw *ah, struct ieee80211_channel *channel)
{
	int ret;
	/*
1944 1945 1946 1947 1948
	 * Check bounds supported by the PHY (we don't care about regultory
	 * restrictions at this point). Note: hw_value already has the band
	 * (CHANNEL_2GHZ, or CHANNEL_5GHZ) so we inform ath5k_channel_ok()
	 * of the band by that */
	if (!ath5k_channel_ok(ah, channel->center_freq, channel->hw_value)) {
1949
		ATH5K_ERR(ah->ah_sc,
1950 1951
			"channel frequency (%u MHz) out of supported "
			"band range\n",
1952
			channel->center_freq);
1953
			return -EINVAL;
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973
	}

	/*
	 * Set the channel and wait
	 */
	switch (ah->ah_radio) {
	case AR5K_RF5110:
		ret = ath5k_hw_rf5110_channel(ah, channel);
		break;
	case AR5K_RF5111:
		ret = ath5k_hw_rf5111_channel(ah, channel);
		break;
	default:
		ret = ath5k_hw_rf5112_channel(ah, channel);
		break;
	}

	if (ret)
		return ret;

1974 1975 1976
	ah->ah_current_channel.center_freq = channel->center_freq;
	ah->ah_current_channel.hw_value = channel->hw_value;
	ah->ah_turbo = channel->hw_value == CHANNEL_T ? true : false;
1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138

	return 0;
}

/*****************\
  PHY calibration
\*****************/

/**
 * ath5k_hw_noise_floor_calibration - perform PHY noise floor calibration
 *
 * @ah: struct ath5k_hw pointer we are operating on
 * @freq: the channel frequency, just used for error logging
 *
 * This function performs a noise floor calibration of the PHY and waits for
 * it to complete. Then the noise floor value is compared to some maximum
 * noise floor we consider valid.
 *
 * Note that this is different from what the madwifi HAL does: it reads the
 * noise floor and afterwards initiates the calibration. Since the noise floor
 * calibration can take some time to finish, depending on the current channel
 * use, that avoids the occasional timeout warnings we are seeing now.
 *
 * See the following link for an Atheros patent on noise floor calibration:
 * http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PALL \
 * &p=1&u=%2Fnetahtml%2FPTO%2Fsrchnum.htm&r=1&f=G&l=50&s1=7245893.PN.&OS=PN/7
 *
 */
int
ath5k_hw_noise_floor_calibration(struct ath5k_hw *ah, short freq)
{
	int ret;
	unsigned int i;
	s32 noise_floor;

	/*
	 * Enable noise floor calibration and wait until completion
	 */
	AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
				AR5K_PHY_AGCCTL_NF);

	ret = ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
			AR5K_PHY_AGCCTL_NF, 0, false);
	if (ret) {
		ATH5K_ERR(ah->ah_sc,
			"noise floor calibration timeout (%uMHz)\n", freq);
		return ret;
	}

	/* Wait until the noise floor is calibrated and read the value */
	for (i = 20; i > 0; i--) {
		mdelay(1);
		noise_floor = ath5k_hw_reg_read(ah, AR5K_PHY_NF);
		noise_floor = AR5K_PHY_NF_RVAL(noise_floor);
		if (noise_floor & AR5K_PHY_NF_ACTIVE) {
			noise_floor = AR5K_PHY_NF_AVAL(noise_floor);

			if (noise_floor <= AR5K_TUNE_NOISE_FLOOR)
				break;
		}
	}

	ATH5K_DBG_UNLIMIT(ah->ah_sc, ATH5K_DEBUG_CALIBRATE,
		"noise floor %d\n", noise_floor);

	if (noise_floor > AR5K_TUNE_NOISE_FLOOR) {
		ATH5K_ERR(ah->ah_sc,
			"noise floor calibration failed (%uMHz)\n", freq);
		return -EIO;
	}

	ah->ah_noise_floor = noise_floor;

	return 0;
}

/*
 * Perform a PHY calibration on RF5110
 * -Fix BPSK/QAM Constellation (I/Q correction)
 * -Calculate Noise Floor
 */
static int ath5k_hw_rf5110_calibrate(struct ath5k_hw *ah,
		struct ieee80211_channel *channel)
{
	u32 phy_sig, phy_agc, phy_sat, beacon;
	int ret;

	/*
	 * Disable beacons and RX/TX queues, wait
	 */
	AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5210,
		AR5K_DIAG_SW_DIS_TX | AR5K_DIAG_SW_DIS_RX_5210);
	beacon = ath5k_hw_reg_read(ah, AR5K_BEACON_5210);
	ath5k_hw_reg_write(ah, beacon & ~AR5K_BEACON_ENABLE, AR5K_BEACON_5210);

	udelay(2300);

	/*
	 * Set the channel (with AGC turned off)
	 */
	AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
	udelay(10);
	ret = ath5k_hw_channel(ah, channel);

	/*
	 * Activate PHY and wait
	 */
	ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
	mdelay(1);

	AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);

	if (ret)
		return ret;

	/*
	 * Calibrate the radio chip
	 */

	/* Remember normal state */
	phy_sig = ath5k_hw_reg_read(ah, AR5K_PHY_SIG);
	phy_agc = ath5k_hw_reg_read(ah, AR5K_PHY_AGCCOARSE);
	phy_sat = ath5k_hw_reg_read(ah, AR5K_PHY_ADCSAT);

	/* Update radio registers */
	ath5k_hw_reg_write(ah, (phy_sig & ~(AR5K_PHY_SIG_FIRPWR)) |
		AR5K_REG_SM(-1, AR5K_PHY_SIG_FIRPWR), AR5K_PHY_SIG);

	ath5k_hw_reg_write(ah, (phy_agc & ~(AR5K_PHY_AGCCOARSE_HI |
			AR5K_PHY_AGCCOARSE_LO)) |
		AR5K_REG_SM(-1, AR5K_PHY_AGCCOARSE_HI) |
		AR5K_REG_SM(-127, AR5K_PHY_AGCCOARSE_LO), AR5K_PHY_AGCCOARSE);

	ath5k_hw_reg_write(ah, (phy_sat & ~(AR5K_PHY_ADCSAT_ICNT |
			AR5K_PHY_ADCSAT_THR)) |
		AR5K_REG_SM(2, AR5K_PHY_ADCSAT_ICNT) |
		AR5K_REG_SM(12, AR5K_PHY_ADCSAT_THR), AR5K_PHY_ADCSAT);

	udelay(20);

	AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
	udelay(10);
	ath5k_hw_reg_write(ah, AR5K_PHY_RFSTG_DISABLE, AR5K_PHY_RFSTG);
	AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);

	mdelay(1);

	/*
	 * Enable calibration and wait until completion
	 */
	AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL, AR5K_PHY_AGCCTL_CAL);

	ret = ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
			AR5K_PHY_AGCCTL_CAL, 0, false);

	/* Reset to normal state */
	ath5k_hw_reg_write(ah, phy_sig, AR5K_PHY_SIG);
	ath5k_hw_reg_write(ah, phy_agc, AR5K_PHY_AGCCOARSE);
	ath5k_hw_reg_write(ah, phy_sat, AR5K_PHY_ADCSAT);

	if (ret) {
		ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
2139
				channel->center_freq);
2140 2141 2142
		return ret;
	}

2143
	ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166
	if (ret)
		return ret;

	/*
	 * Re-enable RX/TX and beacons
	 */
	AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW_5210,
		AR5K_DIAG_SW_DIS_TX | AR5K_DIAG_SW_DIS_RX_5210);
	ath5k_hw_reg_write(ah, beacon, AR5K_BEACON_5210);

	return 0;
}

/*
 * Perform a PHY calibration on RF5111/5112
 */
static int ath5k_hw_rf511x_calibrate(struct ath5k_hw *ah,
		struct ieee80211_channel *channel)
{
	u32 i_pwr, q_pwr;
	s32 iq_corr, i_coff, i_coffd, q_coff, q_coffd;
	ATH5K_TRACE(ah->ah_sc);

2167
	if (!ah->ah_calibration ||
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189
			ath5k_hw_reg_read(ah, AR5K_PHY_IQ) & AR5K_PHY_IQ_RUN)
		goto done;

	ah->ah_calibration = false;

	iq_corr = ath5k_hw_reg_read(ah, AR5K_PHY_IQRES_CAL_CORR);
	i_pwr = ath5k_hw_reg_read(ah, AR5K_PHY_IQRES_CAL_PWR_I);
	q_pwr = ath5k_hw_reg_read(ah, AR5K_PHY_IQRES_CAL_PWR_Q);
	i_coffd = ((i_pwr >> 1) + (q_pwr >> 1)) >> 7;
	q_coffd = q_pwr >> 6;

	if (i_coffd == 0 || q_coffd == 0)
		goto done;

	i_coff = ((-iq_corr) / i_coffd) & 0x3f;
	q_coff = (((s32)i_pwr / q_coffd) - 64) & 0x1f;

	/* Commit new IQ value */
	AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_CORR_ENABLE |
		((u32)q_coff) | ((u32)i_coff << AR5K_PHY_IQ_CORR_Q_I_COFF_S));

done:
2190
	ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
2191 2192

	/* Request RF gain */
2193
	if (channel->hw_value & CHANNEL_5GHZ) {
2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356
		ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txpower.txp_max,
			AR5K_PHY_PAPD_PROBE_TXPOWER) |
			AR5K_PHY_PAPD_PROBE_TX_NEXT, AR5K_PHY_PAPD_PROBE);
		ah->ah_rf_gain = AR5K_RFGAIN_READ_REQUESTED;
	}

	return 0;
}

/*
 * Perform a PHY calibration
 */
int ath5k_hw_phy_calibrate(struct ath5k_hw *ah,
		struct ieee80211_channel *channel)
{
	int ret;

	if (ah->ah_radio == AR5K_RF5110)
		ret = ath5k_hw_rf5110_calibrate(ah, channel);
	else
		ret = ath5k_hw_rf511x_calibrate(ah, channel);

	return ret;
}

int ath5k_hw_phy_disable(struct ath5k_hw *ah)
{
	ATH5K_TRACE(ah->ah_sc);
	/*Just a try M.F.*/
	ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);

	return 0;
}

/********************\
  Misc PHY functions
\********************/

/*
 * Get the PHY Chip revision
 */
u16 ath5k_hw_radio_revision(struct ath5k_hw *ah, unsigned int chan)
{
	unsigned int i;
	u32 srev;
	u16 ret;

	ATH5K_TRACE(ah->ah_sc);

	/*
	 * Set the radio chip access register
	 */
	switch (chan) {
	case CHANNEL_2GHZ:
		ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_2GHZ, AR5K_PHY(0));
		break;
	case CHANNEL_5GHZ:
		ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
		break;
	default:
		return 0;
	}

	mdelay(2);

	/* ...wait until PHY is ready and read the selected radio revision */
	ath5k_hw_reg_write(ah, 0x00001c16, AR5K_PHY(0x34));

	for (i = 0; i < 8; i++)
		ath5k_hw_reg_write(ah, 0x00010000, AR5K_PHY(0x20));

	if (ah->ah_version == AR5K_AR5210) {
		srev = ath5k_hw_reg_read(ah, AR5K_PHY(256) >> 28) & 0xf;
		ret = (u16)ath5k_hw_bitswap(srev, 4) + 1;
	} else {
		srev = (ath5k_hw_reg_read(ah, AR5K_PHY(0x100)) >> 24) & 0xff;
		ret = (u16)ath5k_hw_bitswap(((srev & 0xf0) >> 4) |
				((srev & 0x0f) << 4), 8);
	}

	/* Reset to the 5GHz mode */
	ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));

	return ret;
}

void /*TODO:Boundary check*/
ath5k_hw_set_def_antenna(struct ath5k_hw *ah, unsigned int ant)
{
	ATH5K_TRACE(ah->ah_sc);
	/*Just a try M.F.*/
	if (ah->ah_version != AR5K_AR5210)
		ath5k_hw_reg_write(ah, ant, AR5K_DEFAULT_ANTENNA);
}

unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah)
{
	ATH5K_TRACE(ah->ah_sc);
	/*Just a try M.F.*/
	if (ah->ah_version != AR5K_AR5210)
		return ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);

	return false; /*XXX: What do we return for 5210 ?*/
}

/*
 * TX power setup
 */

/*
 * Initialize the tx power table (not fully implemented)
 */
static void ath5k_txpower_table(struct ath5k_hw *ah,
		struct ieee80211_channel *channel, s16 max_power)
{
	unsigned int i, min, max, n;
	u16 txpower, *rates;

	rates = ah->ah_txpower.txp_rates;

	txpower = AR5K_TUNE_DEFAULT_TXPOWER * 2;
	if (max_power > txpower)
		txpower = max_power > AR5K_TUNE_MAX_TXPOWER ?
		    AR5K_TUNE_MAX_TXPOWER : max_power;

	for (i = 0; i < AR5K_MAX_RATES; i++)
		rates[i] = txpower;

	/* XXX setup target powers by rate */

	ah->ah_txpower.txp_min = rates[7];
	ah->ah_txpower.txp_max = rates[0];
	ah->ah_txpower.txp_ofdm = rates[0];

	/* Calculate the power table */
	n = ARRAY_SIZE(ah->ah_txpower.txp_pcdac);
	min = AR5K_EEPROM_PCDAC_START;
	max = AR5K_EEPROM_PCDAC_STOP;
	for (i = 0; i < n; i += AR5K_EEPROM_PCDAC_STEP)
		ah->ah_txpower.txp_pcdac[i] =
#ifdef notyet
		min + ((i * (max - min)) / n);
#else
		min;
#endif
}

/*
 * Set transmition power
 */
int /*O.K. - txpower_table is unimplemented so this doesn't work*/
ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel,
		unsigned int txpower)
{
	bool tpc = ah->ah_txpower.txp_tpc;
	unsigned int i;

	ATH5K_TRACE(ah->ah_sc);
	if (txpower > AR5K_TUNE_MAX_TXPOWER) {
		ATH5K_ERR(ah->ah_sc, "invalid tx power: %u\n", txpower);
		return -EINVAL;
	}

N
Nick Kossifidis 已提交
2357 2358 2359 2360 2361
	/*
	 * RF2413 for some reason can't
	 * transmit anything if we call
	 * this funtion, so we skip it
	 * until we fix txpower.
N
Nick Kossifidis 已提交
2362 2363 2364
	 *
	 * XXX: Assume same for RF2425
	 * to be safe.
N
Nick Kossifidis 已提交
2365
	 */
N
Nick Kossifidis 已提交
2366
	if ((ah->ah_radio == AR5K_RF2413) || (ah->ah_radio == AR5K_RF2425))
N
Nick Kossifidis 已提交
2367 2368
		return 0;

2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401
	/* Reset TX power values */
	memset(&ah->ah_txpower, 0, sizeof(ah->ah_txpower));
	ah->ah_txpower.txp_tpc = tpc;

	/* Initialize TX power table */
	ath5k_txpower_table(ah, channel, txpower);

	/*
	 * Write TX power values
	 */
	for (i = 0; i < (AR5K_EEPROM_POWER_TABLE_SIZE / 2); i++) {
		ath5k_hw_reg_write(ah,
			((((ah->ah_txpower.txp_pcdac[(i << 1) + 1] << 8) | 0xff) & 0xffff) << 16) |
			(((ah->ah_txpower.txp_pcdac[(i << 1)    ] << 8) | 0xff) & 0xffff),
			AR5K_PHY_PCDAC_TXPOWER(i));
	}

	ath5k_hw_reg_write(ah, AR5K_TXPOWER_OFDM(3, 24) |
		AR5K_TXPOWER_OFDM(2, 16) | AR5K_TXPOWER_OFDM(1, 8) |
		AR5K_TXPOWER_OFDM(0, 0), AR5K_PHY_TXPOWER_RATE1);

	ath5k_hw_reg_write(ah, AR5K_TXPOWER_OFDM(7, 24) |
		AR5K_TXPOWER_OFDM(6, 16) | AR5K_TXPOWER_OFDM(5, 8) |
		AR5K_TXPOWER_OFDM(4, 0), AR5K_PHY_TXPOWER_RATE2);

	ath5k_hw_reg_write(ah, AR5K_TXPOWER_CCK(10, 24) |
		AR5K_TXPOWER_CCK(9, 16) | AR5K_TXPOWER_CCK(15, 8) |
		AR5K_TXPOWER_CCK(8, 0), AR5K_PHY_TXPOWER_RATE3);

	ath5k_hw_reg_write(ah, AR5K_TXPOWER_CCK(14, 24) |
		AR5K_TXPOWER_CCK(13, 16) | AR5K_TXPOWER_CCK(12, 8) |
		AR5K_TXPOWER_CCK(11, 0), AR5K_PHY_TXPOWER_RATE4);

2402
	if (ah->ah_txpower.txp_tpc)
2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422
		ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX_TPC_ENABLE |
			AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX);
	else
		ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX |
			AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX);

	return 0;
}

int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, unsigned int power)
{
	/*Just a try M.F.*/
	struct ieee80211_channel *channel = &ah->ah_current_channel;

	ATH5K_TRACE(ah->ah_sc);
	ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_TXPOWER,
		"changing txpower to %d\n", power);

	return ath5k_hw_txpower(ah, channel, power);
}