| .. | .. |
|---|
| 21 | 21 | * |
|---|
| 22 | 22 | */ |
|---|
| 23 | 23 | |
|---|
| 24 | +#include <linux/errno.h> |
|---|
| 24 | 25 | #include "mac.h" |
|---|
| 25 | 26 | #include "rf.h" |
|---|
| 26 | 27 | #include "baseband.h" |
|---|
| 27 | 28 | #include "usbpipe.h" |
|---|
| 28 | 29 | |
|---|
| 29 | 30 | #define CB_AL2230_INIT_SEQ 15 |
|---|
| 30 | | -#define AL2230_PWR_IDX_LEN 64 |
|---|
| 31 | | - |
|---|
| 32 | 31 | #define CB_AL7230_INIT_SEQ 16 |
|---|
| 33 | | -#define AL7230_PWR_IDX_LEN 64 |
|---|
| 34 | | - |
|---|
| 35 | 32 | #define CB_VT3226_INIT_SEQ 11 |
|---|
| 36 | | -#define VT3226_PWR_IDX_LEN 64 |
|---|
| 37 | | - |
|---|
| 38 | 33 | #define CB_VT3342_INIT_SEQ 13 |
|---|
| 39 | | -#define VT3342_PWR_IDX_LEN 64 |
|---|
| 40 | 34 | |
|---|
| 41 | 35 | static u8 al2230_init_table[CB_AL2230_INIT_SEQ][3] = { |
|---|
| 42 | 36 | {0x03, 0xf7, 0x90}, |
|---|
| .. | .. |
|---|
| 518 | 512 | {0x03, 0x00, 0x04} |
|---|
| 519 | 513 | }; |
|---|
| 520 | 514 | |
|---|
| 521 | | -/* Power Table */ |
|---|
| 522 | | -static const u32 al2230_power_table[AL2230_PWR_IDX_LEN] = { |
|---|
| 523 | | - 0x04040900, |
|---|
| 524 | | - 0x04041900, |
|---|
| 525 | | - 0x04042900, |
|---|
| 526 | | - 0x04043900, |
|---|
| 527 | | - 0x04044900, |
|---|
| 528 | | - 0x04045900, |
|---|
| 529 | | - 0x04046900, |
|---|
| 530 | | - 0x04047900, |
|---|
| 531 | | - 0x04048900, |
|---|
| 532 | | - 0x04049900, |
|---|
| 533 | | - 0x0404a900, |
|---|
| 534 | | - 0x0404b900, |
|---|
| 535 | | - 0x0404c900, |
|---|
| 536 | | - 0x0404d900, |
|---|
| 537 | | - 0x0404e900, |
|---|
| 538 | | - 0x0404f900, |
|---|
| 539 | | - 0x04050900, |
|---|
| 540 | | - 0x04051900, |
|---|
| 541 | | - 0x04052900, |
|---|
| 542 | | - 0x04053900, |
|---|
| 543 | | - 0x04054900, |
|---|
| 544 | | - 0x04055900, |
|---|
| 545 | | - 0x04056900, |
|---|
| 546 | | - 0x04057900, |
|---|
| 547 | | - 0x04058900, |
|---|
| 548 | | - 0x04059900, |
|---|
| 549 | | - 0x0405a900, |
|---|
| 550 | | - 0x0405b900, |
|---|
| 551 | | - 0x0405c900, |
|---|
| 552 | | - 0x0405d900, |
|---|
| 553 | | - 0x0405e900, |
|---|
| 554 | | - 0x0405f900, |
|---|
| 555 | | - 0x04060900, |
|---|
| 556 | | - 0x04061900, |
|---|
| 557 | | - 0x04062900, |
|---|
| 558 | | - 0x04063900, |
|---|
| 559 | | - 0x04064900, |
|---|
| 560 | | - 0x04065900, |
|---|
| 561 | | - 0x04066900, |
|---|
| 562 | | - 0x04067900, |
|---|
| 563 | | - 0x04068900, |
|---|
| 564 | | - 0x04069900, |
|---|
| 565 | | - 0x0406a900, |
|---|
| 566 | | - 0x0406b900, |
|---|
| 567 | | - 0x0406c900, |
|---|
| 568 | | - 0x0406d900, |
|---|
| 569 | | - 0x0406e900, |
|---|
| 570 | | - 0x0406f900, |
|---|
| 571 | | - 0x04070900, |
|---|
| 572 | | - 0x04071900, |
|---|
| 573 | | - 0x04072900, |
|---|
| 574 | | - 0x04073900, |
|---|
| 575 | | - 0x04074900, |
|---|
| 576 | | - 0x04075900, |
|---|
| 577 | | - 0x04076900, |
|---|
| 578 | | - 0x04077900, |
|---|
| 579 | | - 0x04078900, |
|---|
| 580 | | - 0x04079900, |
|---|
| 581 | | - 0x0407a900, |
|---|
| 582 | | - 0x0407b900, |
|---|
| 583 | | - 0x0407c900, |
|---|
| 584 | | - 0x0407d900, |
|---|
| 585 | | - 0x0407e900, |
|---|
| 586 | | - 0x0407f900 |
|---|
| 515 | +enum { |
|---|
| 516 | + VNT_TABLE_INIT = 0, |
|---|
| 517 | + VNT_TABLE_INIT_2 = 0, |
|---|
| 518 | + VNT_TABLE_0 = 1, |
|---|
| 519 | + VNT_TABLE_1 = 2, |
|---|
| 520 | + VNT_TABLE_2 = 1 |
|---|
| 521 | +}; |
|---|
| 522 | + |
|---|
| 523 | +struct vnt_table_info { |
|---|
| 524 | + u8 *addr; |
|---|
| 525 | + int length; |
|---|
| 526 | +}; |
|---|
| 527 | + |
|---|
| 528 | +static const struct vnt_table_info vnt_table_seq[][3] = { |
|---|
| 529 | + { /* RF_AL2230, RF_AL2230S init table, channel table 0 and 1 */ |
|---|
| 530 | + {&al2230_init_table[0][0], CB_AL2230_INIT_SEQ * 3}, |
|---|
| 531 | + {&al2230_channel_table0[0][0], CB_MAX_CHANNEL_24G * 3}, |
|---|
| 532 | + {&al2230_channel_table1[0][0], CB_MAX_CHANNEL_24G * 3} |
|---|
| 533 | + }, { /* RF_AIROHA7230 init table, channel table 0 and 1 */ |
|---|
| 534 | + {&al7230_init_table[0][0], CB_AL7230_INIT_SEQ * 3}, |
|---|
| 535 | + {&al7230_channel_table0[0][0], CB_MAX_CHANNEL * 3}, |
|---|
| 536 | + {&al7230_channel_table1[0][0], CB_MAX_CHANNEL * 3} |
|---|
| 537 | + }, { /* RF_VT3226 init table, channel table 0 and 1 */ |
|---|
| 538 | + {&vt3226_init_table[0][0], CB_VT3226_INIT_SEQ * 3}, |
|---|
| 539 | + {&vt3226_channel_table0[0][0], CB_MAX_CHANNEL_24G * 3}, |
|---|
| 540 | + {&vt3226_channel_table1[0][0], CB_MAX_CHANNEL_24G * 3} |
|---|
| 541 | + }, { /* RF_VT3226D0 init table, channel table 0 and 1 */ |
|---|
| 542 | + {&vt3226d0_init_table[0][0], CB_VT3226_INIT_SEQ * 3}, |
|---|
| 543 | + {&vt3226_channel_table0[0][0], CB_MAX_CHANNEL_24G * 3}, |
|---|
| 544 | + {&vt3226_channel_table1[0][0], CB_MAX_CHANNEL_24G * 3} |
|---|
| 545 | + }, { /* RF_VT3342A0 init table, channel table 0 and 1 */ |
|---|
| 546 | + {&vt3342a0_init_table[0][0], CB_VT3342_INIT_SEQ * 3}, |
|---|
| 547 | + {&vt3342_channel_table0[0][0], CB_MAX_CHANNEL * 3}, |
|---|
| 548 | + {&vt3342_channel_table1[0][0], CB_MAX_CHANNEL * 3} |
|---|
| 549 | + }, { /* RF_AIROHA7230 init table 2 and channel table 2 */ |
|---|
| 550 | + {&al7230_init_table_amode[0][0], CB_AL7230_INIT_SEQ * 3}, |
|---|
| 551 | + {&al7230_channel_table2[0][0], CB_MAX_CHANNEL * 3}, |
|---|
| 552 | + {NULL, 0} |
|---|
| 553 | + } |
|---|
| 587 | 554 | }; |
|---|
| 588 | 555 | |
|---|
| 589 | 556 | /* |
|---|
| .. | .. |
|---|
| 600 | 567 | reg_data[2] = (u8)(data >> 16); |
|---|
| 601 | 568 | reg_data[3] = (u8)(data >> 24); |
|---|
| 602 | 569 | |
|---|
| 603 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF, |
|---|
| 604 | | - 0, 0, ARRAY_SIZE(reg_data), reg_data); |
|---|
| 605 | | - |
|---|
| 606 | | - return true; |
|---|
| 607 | | -} |
|---|
| 608 | | - |
|---|
| 609 | | -/* Set Tx power by rate and channel number */ |
|---|
| 610 | | -int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel) |
|---|
| 611 | | -{ |
|---|
| 612 | | - u8 power = priv->cck_pwr; |
|---|
| 613 | | - |
|---|
| 614 | | - if (channel == 0) |
|---|
| 615 | | - return -EINVAL; |
|---|
| 616 | | - |
|---|
| 617 | | - switch (rate) { |
|---|
| 618 | | - case RATE_1M: |
|---|
| 619 | | - case RATE_2M: |
|---|
| 620 | | - case RATE_5M: |
|---|
| 621 | | - case RATE_11M: |
|---|
| 622 | | - channel--; |
|---|
| 623 | | - |
|---|
| 624 | | - if (channel < sizeof(priv->cck_pwr_tbl)) |
|---|
| 625 | | - power = priv->cck_pwr_tbl[channel]; |
|---|
| 626 | | - break; |
|---|
| 627 | | - case RATE_6M: |
|---|
| 628 | | - case RATE_9M: |
|---|
| 629 | | - case RATE_12M: |
|---|
| 630 | | - case RATE_18M: |
|---|
| 631 | | - case RATE_24M: |
|---|
| 632 | | - case RATE_36M: |
|---|
| 633 | | - case RATE_48M: |
|---|
| 634 | | - case RATE_54M: |
|---|
| 635 | | - if (channel > CB_MAX_CHANNEL_24G) |
|---|
| 636 | | - power = priv->ofdm_a_pwr_tbl[channel - 15]; |
|---|
| 637 | | - else |
|---|
| 638 | | - power = priv->ofdm_pwr_tbl[channel - 1]; |
|---|
| 639 | | - break; |
|---|
| 640 | | - } |
|---|
| 641 | | - |
|---|
| 642 | | - return vnt_rf_set_txpower(priv, power, rate); |
|---|
| 570 | + return vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF, 0, 0, |
|---|
| 571 | + ARRAY_SIZE(reg_data), reg_data); |
|---|
| 643 | 572 | } |
|---|
| 644 | 573 | |
|---|
| 645 | 574 | static u8 vnt_rf_addpower(struct vnt_private *priv) |
|---|
| 646 | 575 | { |
|---|
| 576 | + int base; |
|---|
| 647 | 577 | s32 rssi = -priv->current_rssi; |
|---|
| 648 | 578 | |
|---|
| 649 | 579 | if (!rssi) |
|---|
| 650 | 580 | return 7; |
|---|
| 651 | 581 | |
|---|
| 652 | | - if (priv->rf_type == RF_VT3226D0) { |
|---|
| 653 | | - if (rssi < -70) |
|---|
| 654 | | - return 9; |
|---|
| 655 | | - else if (rssi < -65) |
|---|
| 656 | | - return 7; |
|---|
| 657 | | - else if (rssi < -60) |
|---|
| 658 | | - return 5; |
|---|
| 659 | | - } else { |
|---|
| 660 | | - if (rssi < -80) |
|---|
| 661 | | - return 9; |
|---|
| 662 | | - else if (rssi < -75) |
|---|
| 663 | | - return 7; |
|---|
| 664 | | - else if (rssi < -70) |
|---|
| 665 | | - return 5; |
|---|
| 666 | | - } |
|---|
| 582 | + if (priv->rf_type == RF_VT3226D0) |
|---|
| 583 | + base = -60; |
|---|
| 584 | + else |
|---|
| 585 | + base = -70; |
|---|
| 586 | + |
|---|
| 587 | + if (rssi < base) |
|---|
| 588 | + return ((rssi - base + 1) / -5) * 2 + 5; |
|---|
| 667 | 589 | |
|---|
| 668 | 590 | return 0; |
|---|
| 669 | 591 | } |
|---|
| 670 | 592 | |
|---|
| 671 | 593 | /* Set Tx power by power level and rate */ |
|---|
| 672 | | -int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate) |
|---|
| 594 | +static int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, |
|---|
| 595 | + struct ieee80211_channel *ch) |
|---|
| 673 | 596 | { |
|---|
| 674 | 597 | u32 power_setting = 0; |
|---|
| 675 | | - int ret = true; |
|---|
| 598 | + int ret = 0; |
|---|
| 676 | 599 | |
|---|
| 677 | 600 | power += vnt_rf_addpower(priv); |
|---|
| 678 | 601 | if (power > VNT_RF_MAX_POWER) |
|---|
| 679 | 602 | power = VNT_RF_MAX_POWER; |
|---|
| 680 | 603 | |
|---|
| 681 | 604 | if (priv->power == power) |
|---|
| 682 | | - return true; |
|---|
| 605 | + return 0; |
|---|
| 683 | 606 | |
|---|
| 684 | 607 | priv->power = power; |
|---|
| 685 | 608 | |
|---|
| 686 | 609 | switch (priv->rf_type) { |
|---|
| 687 | 610 | case RF_AL2230: |
|---|
| 688 | | - if (power >= AL2230_PWR_IDX_LEN) |
|---|
| 689 | | - return false; |
|---|
| 611 | + power_setting = 0x0404090 | (power << 12); |
|---|
| 690 | 612 | |
|---|
| 691 | | - ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]); |
|---|
| 613 | + ret = vnt_rf_write_embedded(priv, power_setting); |
|---|
| 614 | + if (ret) |
|---|
| 615 | + return ret; |
|---|
| 692 | 616 | |
|---|
| 693 | | - if (rate <= RATE_11M) |
|---|
| 694 | | - ret &= vnt_rf_write_embedded(priv, 0x0001b400); |
|---|
| 617 | + if (ch->flags & IEEE80211_CHAN_NO_OFDM) |
|---|
| 618 | + ret = vnt_rf_write_embedded(priv, 0x0001b400); |
|---|
| 695 | 619 | else |
|---|
| 696 | | - ret &= vnt_rf_write_embedded(priv, 0x0005a400); |
|---|
| 620 | + ret = vnt_rf_write_embedded(priv, 0x0005a400); |
|---|
| 621 | + |
|---|
| 697 | 622 | break; |
|---|
| 698 | 623 | case RF_AL2230S: |
|---|
| 699 | | - if (power >= AL2230_PWR_IDX_LEN) |
|---|
| 700 | | - return false; |
|---|
| 624 | + power_setting = 0x0404090 | (power << 12); |
|---|
| 701 | 625 | |
|---|
| 702 | | - ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]); |
|---|
| 626 | + ret = vnt_rf_write_embedded(priv, power_setting); |
|---|
| 627 | + if (ret) |
|---|
| 628 | + return ret; |
|---|
| 703 | 629 | |
|---|
| 704 | | - if (rate <= RATE_11M) { |
|---|
| 705 | | - ret &= vnt_rf_write_embedded(priv, 0x040c1400); |
|---|
| 706 | | - ret &= vnt_rf_write_embedded(priv, 0x00299b00); |
|---|
| 630 | + if (ch->flags & IEEE80211_CHAN_NO_OFDM) { |
|---|
| 631 | + ret = vnt_rf_write_embedded(priv, 0x040c1400); |
|---|
| 632 | + if (ret) |
|---|
| 633 | + return ret; |
|---|
| 634 | + |
|---|
| 635 | + ret = vnt_rf_write_embedded(priv, 0x00299b00); |
|---|
| 707 | 636 | } else { |
|---|
| 708 | | - ret &= vnt_rf_write_embedded(priv, 0x0005a400); |
|---|
| 709 | | - ret &= vnt_rf_write_embedded(priv, 0x00099b00); |
|---|
| 637 | + ret = vnt_rf_write_embedded(priv, 0x0005a400); |
|---|
| 638 | + if (ret) |
|---|
| 639 | + return ret; |
|---|
| 640 | + |
|---|
| 641 | + ret = vnt_rf_write_embedded(priv, 0x00099b00); |
|---|
| 710 | 642 | } |
|---|
| 643 | + |
|---|
| 711 | 644 | break; |
|---|
| 712 | 645 | |
|---|
| 713 | 646 | case RF_AIROHA7230: |
|---|
| 714 | | - if (rate <= RATE_11M) |
|---|
| 715 | | - ret &= vnt_rf_write_embedded(priv, 0x111bb900); |
|---|
| 647 | + if (ch->flags & IEEE80211_CHAN_NO_OFDM) |
|---|
| 648 | + ret = vnt_rf_write_embedded(priv, 0x111bb900); |
|---|
| 716 | 649 | else |
|---|
| 717 | | - ret &= vnt_rf_write_embedded(priv, 0x221bb900); |
|---|
| 650 | + ret = vnt_rf_write_embedded(priv, 0x221bb900); |
|---|
| 718 | 651 | |
|---|
| 719 | | - if (power >= AL7230_PWR_IDX_LEN) |
|---|
| 720 | | - return false; |
|---|
| 652 | + if (ret) |
|---|
| 653 | + return ret; |
|---|
| 721 | 654 | |
|---|
| 722 | 655 | /* |
|---|
| 723 | 656 | * 0x080F1B00 for 3 wire control TxGain(D10) |
|---|
| .. | .. |
|---|
| 725 | 658 | */ |
|---|
| 726 | 659 | power_setting = 0x080c0b00 | (power << 12); |
|---|
| 727 | 660 | |
|---|
| 728 | | - ret &= vnt_rf_write_embedded(priv, power_setting); |
|---|
| 729 | | - |
|---|
| 661 | + ret = vnt_rf_write_embedded(priv, power_setting); |
|---|
| 730 | 662 | break; |
|---|
| 731 | 663 | |
|---|
| 732 | 664 | case RF_VT3226: |
|---|
| 733 | | - if (power >= VT3226_PWR_IDX_LEN) |
|---|
| 734 | | - return false; |
|---|
| 735 | 665 | power_setting = ((0x3f - power) << 20) | (0x17 << 8); |
|---|
| 736 | 666 | |
|---|
| 737 | | - ret &= vnt_rf_write_embedded(priv, power_setting); |
|---|
| 738 | | - |
|---|
| 667 | + ret = vnt_rf_write_embedded(priv, power_setting); |
|---|
| 739 | 668 | break; |
|---|
| 740 | 669 | case RF_VT3226D0: |
|---|
| 741 | | - if (power >= VT3226_PWR_IDX_LEN) |
|---|
| 742 | | - return false; |
|---|
| 743 | | - |
|---|
| 744 | | - if (rate <= RATE_11M) { |
|---|
| 745 | | - u16 hw_value = priv->hw->conf.chandef.chan->hw_value; |
|---|
| 670 | + if (ch->flags & IEEE80211_CHAN_NO_OFDM) { |
|---|
| 671 | + u16 hw_value = ch->hw_value; |
|---|
| 746 | 672 | |
|---|
| 747 | 673 | power_setting = ((0x3f - power) << 20) | (0xe07 << 8); |
|---|
| 748 | 674 | |
|---|
| 749 | | - ret &= vnt_rf_write_embedded(priv, power_setting); |
|---|
| 750 | | - ret &= vnt_rf_write_embedded(priv, 0x03c6a200); |
|---|
| 675 | + ret = vnt_rf_write_embedded(priv, power_setting); |
|---|
| 676 | + if (ret) |
|---|
| 677 | + return ret; |
|---|
| 678 | + |
|---|
| 679 | + ret = vnt_rf_write_embedded(priv, 0x03c6a200); |
|---|
| 680 | + if (ret) |
|---|
| 681 | + return ret; |
|---|
| 751 | 682 | |
|---|
| 752 | 683 | dev_dbg(&priv->usb->dev, |
|---|
| 753 | 684 | "%s 11b channel [%d]\n", __func__, hw_value); |
|---|
| 754 | 685 | |
|---|
| 755 | 686 | hw_value--; |
|---|
| 756 | 687 | |
|---|
| 757 | | - if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table)) |
|---|
| 758 | | - ret &= vnt_rf_write_embedded(priv, |
|---|
| 688 | + if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table)) { |
|---|
| 689 | + ret = vnt_rf_write_embedded(priv, |
|---|
| 759 | 690 | vt3226d0_lo_current_table[hw_value]); |
|---|
| 691 | + if (ret) |
|---|
| 692 | + return ret; |
|---|
| 693 | + } |
|---|
| 760 | 694 | |
|---|
| 761 | | - ret &= vnt_rf_write_embedded(priv, 0x015C0800); |
|---|
| 695 | + ret = vnt_rf_write_embedded(priv, 0x015C0800); |
|---|
| 762 | 696 | } else { |
|---|
| 763 | 697 | dev_dbg(&priv->usb->dev, |
|---|
| 764 | 698 | "@@@@ %s> 11G mode\n", __func__); |
|---|
| 765 | 699 | |
|---|
| 766 | 700 | power_setting = ((0x3f - power) << 20) | (0x7 << 8); |
|---|
| 767 | 701 | |
|---|
| 768 | | - ret &= vnt_rf_write_embedded(priv, power_setting); |
|---|
| 769 | | - ret &= vnt_rf_write_embedded(priv, 0x00C6A200); |
|---|
| 770 | | - ret &= vnt_rf_write_embedded(priv, 0x016BC600); |
|---|
| 771 | | - ret &= vnt_rf_write_embedded(priv, 0x00900800); |
|---|
| 702 | + ret = vnt_rf_write_embedded(priv, power_setting); |
|---|
| 703 | + if (ret) |
|---|
| 704 | + return ret; |
|---|
| 705 | + |
|---|
| 706 | + ret = vnt_rf_write_embedded(priv, 0x00C6A200); |
|---|
| 707 | + if (ret) |
|---|
| 708 | + return ret; |
|---|
| 709 | + |
|---|
| 710 | + ret = vnt_rf_write_embedded(priv, 0x016BC600); |
|---|
| 711 | + if (ret) |
|---|
| 712 | + return ret; |
|---|
| 713 | + |
|---|
| 714 | + ret = vnt_rf_write_embedded(priv, 0x00900800); |
|---|
| 772 | 715 | } |
|---|
| 716 | + |
|---|
| 773 | 717 | break; |
|---|
| 774 | 718 | |
|---|
| 775 | 719 | case RF_VT3342A0: |
|---|
| 776 | | - if (power >= VT3342_PWR_IDX_LEN) |
|---|
| 777 | | - return false; |
|---|
| 778 | | - |
|---|
| 779 | 720 | power_setting = ((0x3f - power) << 20) | (0x27 << 8); |
|---|
| 780 | 721 | |
|---|
| 781 | | - ret &= vnt_rf_write_embedded(priv, power_setting); |
|---|
| 782 | | - |
|---|
| 722 | + ret = vnt_rf_write_embedded(priv, power_setting); |
|---|
| 783 | 723 | break; |
|---|
| 784 | 724 | default: |
|---|
| 785 | 725 | break; |
|---|
| 786 | 726 | } |
|---|
| 787 | 727 | return ret; |
|---|
| 728 | +} |
|---|
| 729 | + |
|---|
| 730 | +/* Set Tx power by channel number type */ |
|---|
| 731 | +int vnt_rf_setpower(struct vnt_private *priv, |
|---|
| 732 | + struct ieee80211_channel *ch) |
|---|
| 733 | +{ |
|---|
| 734 | + u16 channel; |
|---|
| 735 | + u8 power = priv->cck_pwr; |
|---|
| 736 | + |
|---|
| 737 | + if (!ch) |
|---|
| 738 | + return -EINVAL; |
|---|
| 739 | + |
|---|
| 740 | + /* set channel number to array number */ |
|---|
| 741 | + channel = ch->hw_value - 1; |
|---|
| 742 | + |
|---|
| 743 | + if (ch->flags & IEEE80211_CHAN_NO_OFDM) { |
|---|
| 744 | + if (channel < ARRAY_SIZE(priv->cck_pwr_tbl)) |
|---|
| 745 | + power = priv->cck_pwr_tbl[channel]; |
|---|
| 746 | + } else if (ch->band == NL80211_BAND_5GHZ) { |
|---|
| 747 | + /* remove 14 channels to array size */ |
|---|
| 748 | + channel -= 14; |
|---|
| 749 | + |
|---|
| 750 | + if (channel < ARRAY_SIZE(priv->ofdm_a_pwr_tbl)) |
|---|
| 751 | + power = priv->ofdm_a_pwr_tbl[channel]; |
|---|
| 752 | + } else { |
|---|
| 753 | + if (channel < ARRAY_SIZE(priv->ofdm_pwr_tbl)) |
|---|
| 754 | + power = priv->ofdm_pwr_tbl[channel]; |
|---|
| 755 | + } |
|---|
| 756 | + |
|---|
| 757 | + return vnt_rf_set_txpower(priv, power, ch); |
|---|
| 788 | 758 | } |
|---|
| 789 | 759 | |
|---|
| 790 | 760 | /* Convert rssi to dbm */ |
|---|
| .. | .. |
|---|
| 811 | 781 | *dbm = -1 * (a + b * 2); |
|---|
| 812 | 782 | } |
|---|
| 813 | 783 | |
|---|
| 814 | | -void vnt_rf_table_download(struct vnt_private *priv) |
|---|
| 784 | +int vnt_rf_table_download(struct vnt_private *priv) |
|---|
| 815 | 785 | { |
|---|
| 816 | | - u16 length1 = 0, length2 = 0, length3 = 0; |
|---|
| 817 | | - u8 *addr1 = NULL, *addr2 = NULL, *addr3 = NULL; |
|---|
| 818 | | - u16 length, value; |
|---|
| 819 | | - u8 array[256]; |
|---|
| 786 | + int ret; |
|---|
| 787 | + int idx = -1; |
|---|
| 788 | + const struct vnt_table_info *table_seq; |
|---|
| 820 | 789 | |
|---|
| 821 | 790 | switch (priv->rf_type) { |
|---|
| 822 | 791 | case RF_AL2230: |
|---|
| 823 | 792 | case RF_AL2230S: |
|---|
| 824 | | - length1 = CB_AL2230_INIT_SEQ * 3; |
|---|
| 825 | | - length2 = CB_MAX_CHANNEL_24G * 3; |
|---|
| 826 | | - length3 = CB_MAX_CHANNEL_24G * 3; |
|---|
| 827 | | - addr1 = &al2230_init_table[0][0]; |
|---|
| 828 | | - addr2 = &al2230_channel_table0[0][0]; |
|---|
| 829 | | - addr3 = &al2230_channel_table1[0][0]; |
|---|
| 793 | + idx = 0; |
|---|
| 830 | 794 | break; |
|---|
| 831 | 795 | case RF_AIROHA7230: |
|---|
| 832 | | - length1 = CB_AL7230_INIT_SEQ * 3; |
|---|
| 833 | | - length2 = CB_MAX_CHANNEL * 3; |
|---|
| 834 | | - length3 = CB_MAX_CHANNEL * 3; |
|---|
| 835 | | - addr1 = &al7230_init_table[0][0]; |
|---|
| 836 | | - addr2 = &al7230_channel_table0[0][0]; |
|---|
| 837 | | - addr3 = &al7230_channel_table1[0][0]; |
|---|
| 796 | + idx = 1; |
|---|
| 838 | 797 | break; |
|---|
| 839 | 798 | case RF_VT3226: |
|---|
| 840 | | - length1 = CB_VT3226_INIT_SEQ * 3; |
|---|
| 841 | | - length2 = CB_MAX_CHANNEL_24G * 3; |
|---|
| 842 | | - length3 = CB_MAX_CHANNEL_24G * 3; |
|---|
| 843 | | - addr1 = &vt3226_init_table[0][0]; |
|---|
| 844 | | - addr2 = &vt3226_channel_table0[0][0]; |
|---|
| 845 | | - addr3 = &vt3226_channel_table1[0][0]; |
|---|
| 799 | + idx = 2; |
|---|
| 846 | 800 | break; |
|---|
| 847 | 801 | case RF_VT3226D0: |
|---|
| 848 | | - length1 = CB_VT3226_INIT_SEQ * 3; |
|---|
| 849 | | - length2 = CB_MAX_CHANNEL_24G * 3; |
|---|
| 850 | | - length3 = CB_MAX_CHANNEL_24G * 3; |
|---|
| 851 | | - addr1 = &vt3226d0_init_table[0][0]; |
|---|
| 852 | | - addr2 = &vt3226_channel_table0[0][0]; |
|---|
| 853 | | - addr3 = &vt3226_channel_table1[0][0]; |
|---|
| 802 | + idx = 3; |
|---|
| 854 | 803 | break; |
|---|
| 855 | 804 | case RF_VT3342A0: |
|---|
| 856 | | - length1 = CB_VT3342_INIT_SEQ * 3; |
|---|
| 857 | | - length2 = CB_MAX_CHANNEL * 3; |
|---|
| 858 | | - length3 = CB_MAX_CHANNEL * 3; |
|---|
| 859 | | - addr1 = &vt3342a0_init_table[0][0]; |
|---|
| 860 | | - addr2 = &vt3342_channel_table0[0][0]; |
|---|
| 861 | | - addr3 = &vt3342_channel_table1[0][0]; |
|---|
| 805 | + idx = 4; |
|---|
| 862 | 806 | break; |
|---|
| 863 | 807 | } |
|---|
| 864 | 808 | |
|---|
| 865 | | - /* Init Table */ |
|---|
| 866 | | - memcpy(array, addr1, length1); |
|---|
| 809 | + if (idx < 0) |
|---|
| 810 | + return 0; |
|---|
| 867 | 811 | |
|---|
| 868 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, |
|---|
| 869 | | - MESSAGE_REQUEST_RF_INIT, length1, array); |
|---|
| 812 | + table_seq = &vnt_table_seq[idx][0]; |
|---|
| 813 | + |
|---|
| 814 | + /* Init Table */ |
|---|
| 815 | + ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, |
|---|
| 816 | + MESSAGE_REQUEST_RF_INIT, |
|---|
| 817 | + table_seq[VNT_TABLE_INIT].length, |
|---|
| 818 | + table_seq[VNT_TABLE_INIT].addr); |
|---|
| 819 | + if (ret) |
|---|
| 820 | + return ret; |
|---|
| 870 | 821 | |
|---|
| 871 | 822 | /* Channel Table 0 */ |
|---|
| 872 | | - value = 0; |
|---|
| 873 | | - while (length2 > 0) { |
|---|
| 874 | | - if (length2 >= 64) |
|---|
| 875 | | - length = 64; |
|---|
| 876 | | - else |
|---|
| 877 | | - length = length2; |
|---|
| 823 | + ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE, |
|---|
| 824 | + MESSAGE_REQUEST_RF_CH0, |
|---|
| 825 | + table_seq[VNT_TABLE_0].length, |
|---|
| 826 | + table_seq[VNT_TABLE_0].addr); |
|---|
| 827 | + if (ret) |
|---|
| 828 | + return ret; |
|---|
| 878 | 829 | |
|---|
| 879 | | - memcpy(array, addr2, length); |
|---|
| 880 | | - |
|---|
| 881 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, |
|---|
| 882 | | - value, MESSAGE_REQUEST_RF_CH0, length, array); |
|---|
| 883 | | - |
|---|
| 884 | | - length2 -= length; |
|---|
| 885 | | - value += length; |
|---|
| 886 | | - addr2 += length; |
|---|
| 887 | | - } |
|---|
| 888 | | - |
|---|
| 889 | | - /* Channel table 1 */ |
|---|
| 890 | | - value = 0; |
|---|
| 891 | | - while (length3 > 0) { |
|---|
| 892 | | - if (length3 >= 64) |
|---|
| 893 | | - length = 64; |
|---|
| 894 | | - else |
|---|
| 895 | | - length = length3; |
|---|
| 896 | | - |
|---|
| 897 | | - memcpy(array, addr3, length); |
|---|
| 898 | | - |
|---|
| 899 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, |
|---|
| 900 | | - value, MESSAGE_REQUEST_RF_CH1, length, array); |
|---|
| 901 | | - |
|---|
| 902 | | - length3 -= length; |
|---|
| 903 | | - value += length; |
|---|
| 904 | | - addr3 += length; |
|---|
| 905 | | - } |
|---|
| 830 | + /* Channel Table 1 */ |
|---|
| 831 | + ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE, |
|---|
| 832 | + MESSAGE_REQUEST_RF_CH1, |
|---|
| 833 | + table_seq[VNT_TABLE_1].length, |
|---|
| 834 | + table_seq[VNT_TABLE_1].addr); |
|---|
| 906 | 835 | |
|---|
| 907 | 836 | if (priv->rf_type == RF_AIROHA7230) { |
|---|
| 908 | | - length1 = CB_AL7230_INIT_SEQ * 3; |
|---|
| 909 | | - length2 = CB_MAX_CHANNEL * 3; |
|---|
| 910 | | - addr1 = &al7230_init_table_amode[0][0]; |
|---|
| 911 | | - addr2 = &al7230_channel_table2[0][0]; |
|---|
| 912 | | - |
|---|
| 913 | | - memcpy(array, addr1, length1); |
|---|
| 837 | + table_seq = &vnt_table_seq[5][0]; |
|---|
| 914 | 838 | |
|---|
| 915 | 839 | /* Init Table 2 */ |
|---|
| 916 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, |
|---|
| 917 | | - 0, MESSAGE_REQUEST_RF_INIT2, length1, array); |
|---|
| 840 | + ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, |
|---|
| 841 | + MESSAGE_REQUEST_RF_INIT2, |
|---|
| 842 | + table_seq[VNT_TABLE_INIT_2].length, |
|---|
| 843 | + table_seq[VNT_TABLE_INIT_2].addr); |
|---|
| 844 | + if (ret) |
|---|
| 845 | + return ret; |
|---|
| 918 | 846 | |
|---|
| 919 | | - /* Channel Table 0 */ |
|---|
| 920 | | - value = 0; |
|---|
| 921 | | - while (length2 > 0) { |
|---|
| 922 | | - if (length2 >= 64) |
|---|
| 923 | | - length = 64; |
|---|
| 924 | | - else |
|---|
| 925 | | - length = length2; |
|---|
| 926 | | - |
|---|
| 927 | | - memcpy(array, addr2, length); |
|---|
| 928 | | - |
|---|
| 929 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, |
|---|
| 930 | | - value, MESSAGE_REQUEST_RF_CH2, |
|---|
| 931 | | - length, array); |
|---|
| 932 | | - |
|---|
| 933 | | - length2 -= length; |
|---|
| 934 | | - value += length; |
|---|
| 935 | | - addr2 += length; |
|---|
| 936 | | - } |
|---|
| 847 | + /* Channel Table 2 */ |
|---|
| 848 | + ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE, |
|---|
| 849 | + MESSAGE_REQUEST_RF_CH2, |
|---|
| 850 | + table_seq[VNT_TABLE_2].length, |
|---|
| 851 | + table_seq[VNT_TABLE_2].addr); |
|---|
| 937 | 852 | } |
|---|
| 853 | + |
|---|
| 854 | + return ret; |
|---|
| 938 | 855 | } |
|---|