aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2800lib.c
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2011-02-22 15:10:22 -0500
committerJohn W. Linville <linville@tuxdriver.com>2011-02-22 15:10:22 -0500
commit5db5e44cdcdc5ee9cc821bd4d63445af0bb34bce (patch)
treeb5e5787a6d5c15e589d275c7434ebbf341257234 /drivers/net/wireless/rt2x00/rt2800lib.c
parentdb62983a1e4b2af9e79c97af768f0c8b80bd93f0 (diff)
parent320d6c1b56de5f461c6062625b9664095f90ee95 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6 into for-davem
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2800lib.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c747
1 files changed, 613 insertions, 134 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index c9bf074342ba..3da78bf0ca26 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -400,8 +400,15 @@ int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
400 if (rt2800_wait_csr_ready(rt2x00dev)) 400 if (rt2800_wait_csr_ready(rt2x00dev))
401 return -EBUSY; 401 return -EBUSY;
402 402
403 if (rt2x00_is_pci(rt2x00dev)) 403 if (rt2x00_is_pci(rt2x00dev)) {
404 if (rt2x00_rt(rt2x00dev, RT5390)) {
405 rt2800_register_read(rt2x00dev, AUX_CTRL, &reg);
406 rt2x00_set_field32(&reg, AUX_CTRL_FORCE_PCIE_CLK, 1);
407 rt2x00_set_field32(&reg, AUX_CTRL_WAKE_PCIE_EN, 1);
408 rt2800_register_write(rt2x00dev, AUX_CTRL, reg);
409 }
404 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002); 410 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
411 }
405 412
406 /* 413 /*
407 * Disable DMA, will be reenabled later when enabling 414 * Disable DMA, will be reenabled later when enabling
@@ -773,13 +780,14 @@ void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc)
773 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 780 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
774 unsigned int beacon_base; 781 unsigned int beacon_base;
775 unsigned int padding_len; 782 unsigned int padding_len;
776 u32 reg; 783 u32 orig_reg, reg;
777 784
778 /* 785 /*
779 * Disable beaconing while we are reloading the beacon data, 786 * Disable beaconing while we are reloading the beacon data,
780 * otherwise we might be sending out invalid data. 787 * otherwise we might be sending out invalid data.
781 */ 788 */
782 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg); 789 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
790 orig_reg = reg;
783 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0); 791 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
784 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); 792 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
785 793
@@ -810,7 +818,14 @@ void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc)
810 * Write entire beacon with TXWI and padding to register. 818 * Write entire beacon with TXWI and padding to register.
811 */ 819 */
812 padding_len = roundup(entry->skb->len, 4) - entry->skb->len; 820 padding_len = roundup(entry->skb->len, 4) - entry->skb->len;
813 skb_pad(entry->skb, padding_len); 821 if (padding_len && skb_pad(entry->skb, padding_len)) {
822 ERROR(rt2x00dev, "Failure padding beacon, aborting\n");
823 /* skb freed by skb_pad() on failure */
824 entry->skb = NULL;
825 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
826 return;
827 }
828
814 beacon_base = HW_BEACON_OFFSET(entry->entry_idx); 829 beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
815 rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data, 830 rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data,
816 entry->skb->len + padding_len); 831 entry->skb->len + padding_len);
@@ -1368,10 +1383,32 @@ void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
1368} 1383}
1369EXPORT_SYMBOL_GPL(rt2800_config_erp); 1384EXPORT_SYMBOL_GPL(rt2800_config_erp);
1370 1385
1386static void rt2800_set_ant_diversity(struct rt2x00_dev *rt2x00dev,
1387 enum antenna ant)
1388{
1389 u32 reg;
1390 u8 eesk_pin = (ant == ANTENNA_A) ? 1 : 0;
1391 u8 gpio_bit3 = (ant == ANTENNA_A) ? 0 : 1;
1392
1393 if (rt2x00_is_pci(rt2x00dev)) {
1394 rt2800_register_read(rt2x00dev, E2PROM_CSR, &reg);
1395 rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK, eesk_pin);
1396 rt2800_register_write(rt2x00dev, E2PROM_CSR, reg);
1397 } else if (rt2x00_is_usb(rt2x00dev))
1398 rt2800_mcu_request(rt2x00dev, MCU_ANT_SELECT, 0xff,
1399 eesk_pin, 0);
1400
1401 rt2800_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
1402 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_GPIOD_BIT3, 0);
1403 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_BIT3, gpio_bit3);
1404 rt2800_register_write(rt2x00dev, GPIO_CTRL_CFG, reg);
1405}
1406
1371void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant) 1407void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant)
1372{ 1408{
1373 u8 r1; 1409 u8 r1;
1374 u8 r3; 1410 u8 r3;
1411 u16 eeprom;
1375 1412
1376 rt2800_bbp_read(rt2x00dev, 1, &r1); 1413 rt2800_bbp_read(rt2x00dev, 1, &r1);
1377 rt2800_bbp_read(rt2x00dev, 3, &r3); 1414 rt2800_bbp_read(rt2x00dev, 3, &r3);
@@ -1379,7 +1416,7 @@ void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant)
1379 /* 1416 /*
1380 * Configure the TX antenna. 1417 * Configure the TX antenna.
1381 */ 1418 */
1382 switch ((int)ant->tx) { 1419 switch (ant->tx_chain_num) {
1383 case 1: 1420 case 1:
1384 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0); 1421 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
1385 break; 1422 break;
@@ -1394,8 +1431,18 @@ void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant)
1394 /* 1431 /*
1395 * Configure the RX antenna. 1432 * Configure the RX antenna.
1396 */ 1433 */
1397 switch ((int)ant->rx) { 1434 switch (ant->rx_chain_num) {
1398 case 1: 1435 case 1:
1436 if (rt2x00_rt(rt2x00dev, RT3070) ||
1437 rt2x00_rt(rt2x00dev, RT3090) ||
1438 rt2x00_rt(rt2x00dev, RT3390)) {
1439 rt2x00_eeprom_read(rt2x00dev,
1440 EEPROM_NIC_CONF1, &eeprom);
1441 if (rt2x00_get_field16(eeprom,
1442 EEPROM_NIC_CONF1_ANT_DIVERSITY))
1443 rt2800_set_ant_diversity(rt2x00dev,
1444 rt2x00dev->default_ant.rx);
1445 }
1399 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0); 1446 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
1400 break; 1447 break;
1401 case 2: 1448 case 2:
@@ -1441,13 +1488,13 @@ static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev,
1441{ 1488{
1442 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset); 1489 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
1443 1490
1444 if (rt2x00dev->default_ant.tx == 1) 1491 if (rt2x00dev->default_ant.tx_chain_num == 1)
1445 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1); 1492 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
1446 1493
1447 if (rt2x00dev->default_ant.rx == 1) { 1494 if (rt2x00dev->default_ant.rx_chain_num == 1) {
1448 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1); 1495 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
1449 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); 1496 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
1450 } else if (rt2x00dev->default_ant.rx == 2) 1497 } else if (rt2x00dev->default_ant.rx_chain_num == 2)
1451 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); 1498 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
1452 1499
1453 if (rf->channel > 14) { 1500 if (rf->channel > 14) {
@@ -1533,6 +1580,99 @@ static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev,
1533 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); 1580 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
1534} 1581}
1535 1582
1583
1584#define RT5390_POWER_BOUND 0x27
1585#define RT5390_FREQ_OFFSET_BOUND 0x5f
1586
1587static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
1588 struct ieee80211_conf *conf,
1589 struct rf_channel *rf,
1590 struct channel_info *info)
1591{
1592 u8 rfcsr;
1593 u16 eeprom;
1594
1595 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
1596 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
1597 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
1598 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
1599 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
1600
1601 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
1602 if (info->default_power1 > RT5390_POWER_BOUND)
1603 rt2x00_set_field8(&rfcsr, RFCSR49_TX, RT5390_POWER_BOUND);
1604 else
1605 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
1606 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
1607
1608 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
1609 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
1610 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
1611 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
1612 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
1613 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
1614
1615 rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
1616 if (rt2x00dev->freq_offset > RT5390_FREQ_OFFSET_BOUND)
1617 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, RT5390_FREQ_OFFSET_BOUND);
1618 else
1619 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, rt2x00dev->freq_offset);
1620 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
1621
1622 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
1623 if (rf->channel <= 14) {
1624 int idx = rf->channel-1;
1625
1626 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST)) {
1627 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
1628 /* r55/r59 value array of channel 1~14 */
1629 static const char r55_bt_rev[] = {0x83, 0x83,
1630 0x83, 0x73, 0x73, 0x63, 0x53, 0x53,
1631 0x53, 0x43, 0x43, 0x43, 0x43, 0x43};
1632 static const char r59_bt_rev[] = {0x0e, 0x0e,
1633 0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09,
1634 0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
1635
1636 rt2800_rfcsr_write(rt2x00dev, 55, r55_bt_rev[idx]);
1637 rt2800_rfcsr_write(rt2x00dev, 59, r59_bt_rev[idx]);
1638 } else {
1639 static const char r59_bt[] = {0x8b, 0x8b, 0x8b,
1640 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89,
1641 0x88, 0x88, 0x86, 0x85, 0x84};
1642
1643 rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]);
1644 }
1645 } else {
1646 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
1647 static const char r55_nonbt_rev[] = {0x23, 0x23,
1648 0x23, 0x23, 0x13, 0x13, 0x03, 0x03,
1649 0x03, 0x03, 0x03, 0x03, 0x03, 0x03};
1650 static const char r59_nonbt_rev[] = {0x07, 0x07,
1651 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
1652 0x07, 0x07, 0x06, 0x05, 0x04, 0x04};
1653
1654 rt2800_rfcsr_write(rt2x00dev, 55, r55_nonbt_rev[idx]);
1655 rt2800_rfcsr_write(rt2x00dev, 59, r59_nonbt_rev[idx]);
1656 } else if (rt2x00_rt(rt2x00dev, RT5390)) {
1657 static const char r59_non_bt[] = {0x8f, 0x8f,
1658 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d,
1659 0x8a, 0x88, 0x88, 0x87, 0x87, 0x86};
1660
1661 rt2800_rfcsr_write(rt2x00dev, 59, r59_non_bt[idx]);
1662 }
1663 }
1664 }
1665
1666 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
1667 rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, 0);
1668 rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, 0);
1669 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
1670
1671 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
1672 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
1673 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
1674}
1675
1536static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev, 1676static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
1537 struct ieee80211_conf *conf, 1677 struct ieee80211_conf *conf,
1538 struct rf_channel *rf, 1678 struct rf_channel *rf,
@@ -1557,6 +1697,8 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
1557 rt2x00_rf(rt2x00dev, RF3052) || 1697 rt2x00_rf(rt2x00dev, RF3052) ||
1558 rt2x00_rf(rt2x00dev, RF3320)) 1698 rt2x00_rf(rt2x00dev, RF3320))
1559 rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info); 1699 rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info);
1700 else if (rt2x00_rf(rt2x00dev, RF5390))
1701 rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info);
1560 else 1702 else
1561 rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info); 1703 rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info);
1562 1704
@@ -1569,12 +1711,14 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
1569 rt2800_bbp_write(rt2x00dev, 86, 0); 1711 rt2800_bbp_write(rt2x00dev, 86, 0);
1570 1712
1571 if (rf->channel <= 14) { 1713 if (rf->channel <= 14) {
1572 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) { 1714 if (!rt2x00_rt(rt2x00dev, RT5390)) {
1573 rt2800_bbp_write(rt2x00dev, 82, 0x62); 1715 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
1574 rt2800_bbp_write(rt2x00dev, 75, 0x46); 1716 rt2800_bbp_write(rt2x00dev, 82, 0x62);
1575 } else { 1717 rt2800_bbp_write(rt2x00dev, 75, 0x46);
1576 rt2800_bbp_write(rt2x00dev, 82, 0x84); 1718 } else {
1577 rt2800_bbp_write(rt2x00dev, 75, 0x50); 1719 rt2800_bbp_write(rt2x00dev, 82, 0x84);
1720 rt2800_bbp_write(rt2x00dev, 75, 0x50);
1721 }
1578 } 1722 }
1579 } else { 1723 } else {
1580 rt2800_bbp_write(rt2x00dev, 82, 0xf2); 1724 rt2800_bbp_write(rt2x00dev, 82, 0xf2);
@@ -1594,13 +1738,13 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
1594 tx_pin = 0; 1738 tx_pin = 0;
1595 1739
1596 /* Turn on unused PA or LNA when not using 1T or 1R */ 1740 /* Turn on unused PA or LNA when not using 1T or 1R */
1597 if (rt2x00dev->default_ant.tx != 1) { 1741 if (rt2x00dev->default_ant.tx_chain_num == 2) {
1598 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1); 1742 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
1599 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1); 1743 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
1600 } 1744 }
1601 1745
1602 /* Turn on unused PA or LNA when not using 1T or 1R */ 1746 /* Turn on unused PA or LNA when not using 1T or 1R */
1603 if (rt2x00dev->default_ant.rx != 1) { 1747 if (rt2x00dev->default_ant.rx_chain_num == 2) {
1604 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1); 1748 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
1605 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1); 1749 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
1606 } 1750 }
@@ -1644,30 +1788,116 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
1644 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &reg); 1788 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &reg);
1645} 1789}
1646 1790
1791static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev,
1792 enum ieee80211_band band)
1793{
1794 u16 eeprom;
1795 u8 comp_en;
1796 u8 comp_type;
1797 int comp_value;
1798
1799 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom);
1800
1801 if (eeprom == 0xffff)
1802 return 0;
1803
1804 if (band == IEEE80211_BAND_2GHZ) {
1805 comp_en = rt2x00_get_field16(eeprom,
1806 EEPROM_TXPOWER_DELTA_ENABLE_2G);
1807 if (comp_en) {
1808 comp_type = rt2x00_get_field16(eeprom,
1809 EEPROM_TXPOWER_DELTA_TYPE_2G);
1810 comp_value = rt2x00_get_field16(eeprom,
1811 EEPROM_TXPOWER_DELTA_VALUE_2G);
1812 if (!comp_type)
1813 comp_value = -comp_value;
1814 }
1815 } else {
1816 comp_en = rt2x00_get_field16(eeprom,
1817 EEPROM_TXPOWER_DELTA_ENABLE_5G);
1818 if (comp_en) {
1819 comp_type = rt2x00_get_field16(eeprom,
1820 EEPROM_TXPOWER_DELTA_TYPE_5G);
1821 comp_value = rt2x00_get_field16(eeprom,
1822 EEPROM_TXPOWER_DELTA_VALUE_5G);
1823 if (!comp_type)
1824 comp_value = -comp_value;
1825 }
1826 }
1827
1828 return comp_value;
1829}
1830
1831static u8 rt2800_compesate_txpower(struct rt2x00_dev *rt2x00dev,
1832 int is_rate_b,
1833 enum ieee80211_band band,
1834 int power_level,
1835 u8 txpower)
1836{
1837 u32 reg;
1838 u16 eeprom;
1839 u8 criterion;
1840 u8 eirp_txpower;
1841 u8 eirp_txpower_criterion;
1842 u8 reg_limit;
1843 int bw_comp = 0;
1844
1845 if (!((band == IEEE80211_BAND_5GHZ) && is_rate_b))
1846 return txpower;
1847
1848 if (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
1849 bw_comp = rt2800_get_txpower_bw_comp(rt2x00dev, band);
1850
1851 if (test_bit(CONFIG_SUPPORT_POWER_LIMIT, &rt2x00dev->flags)) {
1852 /*
1853 * Check if eirp txpower exceed txpower_limit.
1854 * We use OFDM 6M as criterion and its eirp txpower
1855 * is stored at EEPROM_EIRP_MAX_TX_POWER.
1856 * .11b data rate need add additional 4dbm
1857 * when calculating eirp txpower.
1858 */
1859 rt2800_register_read(rt2x00dev, TX_PWR_CFG_0, &reg);
1860 criterion = rt2x00_get_field32(reg, TX_PWR_CFG_0_6MBS);
1861
1862 rt2x00_eeprom_read(rt2x00dev,
1863 EEPROM_EIRP_MAX_TX_POWER, &eeprom);
1864
1865 if (band == IEEE80211_BAND_2GHZ)
1866 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
1867 EEPROM_EIRP_MAX_TX_POWER_2GHZ);
1868 else
1869 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
1870 EEPROM_EIRP_MAX_TX_POWER_5GHZ);
1871
1872 eirp_txpower = eirp_txpower_criterion + (txpower - criterion) +
1873 (is_rate_b ? 4 : 0) + bw_comp;
1874
1875 reg_limit = (eirp_txpower > power_level) ?
1876 (eirp_txpower - power_level) : 0;
1877 } else
1878 reg_limit = 0;
1879
1880 return txpower + bw_comp - reg_limit;
1881}
1882
1647static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev, 1883static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
1648 const int max_txpower) 1884 struct ieee80211_conf *conf)
1649{ 1885{
1650 u8 txpower; 1886 u8 txpower;
1651 u8 max_value = (u8)max_txpower;
1652 u16 eeprom; 1887 u16 eeprom;
1653 int i; 1888 int i, is_rate_b;
1654 u32 reg; 1889 u32 reg;
1655 u8 r1; 1890 u8 r1;
1656 u32 offset; 1891 u32 offset;
1892 enum ieee80211_band band = conf->channel->band;
1893 int power_level = conf->power_level;
1657 1894
1658 /* 1895 /*
1659 * set to normal tx power mode: +/- 0dBm 1896 * set to normal bbp tx power control mode: +/- 0dBm
1660 */ 1897 */
1661 rt2800_bbp_read(rt2x00dev, 1, &r1); 1898 rt2800_bbp_read(rt2x00dev, 1, &r1);
1662 rt2x00_set_field8(&r1, BBP1_TX_POWER, 0); 1899 rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, 0);
1663 rt2800_bbp_write(rt2x00dev, 1, r1); 1900 rt2800_bbp_write(rt2x00dev, 1, r1);
1664
1665 /*
1666 * The eeprom contains the tx power values for each rate. These
1667 * values map to 100% tx power. Each 16bit word contains four tx
1668 * power values and the order is the same as used in the TX_PWR_CFG
1669 * registers.
1670 */
1671 offset = TX_PWR_CFG_0; 1901 offset = TX_PWR_CFG_0;
1672 1902
1673 for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) { 1903 for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) {
@@ -1681,73 +1911,99 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
1681 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i, 1911 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i,
1682 &eeprom); 1912 &eeprom);
1683 1913
1684 /* TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS, 1914 is_rate_b = i ? 0 : 1;
1915 /*
1916 * TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS,
1685 * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12, 1917 * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12,
1686 * TX_PWR_CFG_4: unknown */ 1918 * TX_PWR_CFG_4: unknown
1919 */
1687 txpower = rt2x00_get_field16(eeprom, 1920 txpower = rt2x00_get_field16(eeprom,
1688 EEPROM_TXPOWER_BYRATE_RATE0); 1921 EEPROM_TXPOWER_BYRATE_RATE0);
1689 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE0, 1922 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band,
1690 min(txpower, max_value)); 1923 power_level, txpower);
1924 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE0, txpower);
1691 1925
1692 /* TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS, 1926 /*
1927 * TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS,
1693 * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13, 1928 * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13,
1694 * TX_PWR_CFG_4: unknown */ 1929 * TX_PWR_CFG_4: unknown
1930 */
1695 txpower = rt2x00_get_field16(eeprom, 1931 txpower = rt2x00_get_field16(eeprom,
1696 EEPROM_TXPOWER_BYRATE_RATE1); 1932 EEPROM_TXPOWER_BYRATE_RATE1);
1697 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE1, 1933 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band,
1698 min(txpower, max_value)); 1934 power_level, txpower);
1935 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE1, txpower);
1699 1936
1700 /* TX_PWR_CFG_0: 55MBS, TX_PWR_CFG_1: 48MBS, 1937 /*
1938 * TX_PWR_CFG_0: 5.5MBS, TX_PWR_CFG_1: 48MBS,
1701 * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14, 1939 * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14,
1702 * TX_PWR_CFG_4: unknown */ 1940 * TX_PWR_CFG_4: unknown
1941 */
1703 txpower = rt2x00_get_field16(eeprom, 1942 txpower = rt2x00_get_field16(eeprom,
1704 EEPROM_TXPOWER_BYRATE_RATE2); 1943 EEPROM_TXPOWER_BYRATE_RATE2);
1705 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE2, 1944 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band,
1706 min(txpower, max_value)); 1945 power_level, txpower);
1946 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE2, txpower);
1707 1947
1708 /* TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS, 1948 /*
1949 * TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS,
1709 * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15, 1950 * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15,
1710 * TX_PWR_CFG_4: unknown */ 1951 * TX_PWR_CFG_4: unknown
1952 */
1711 txpower = rt2x00_get_field16(eeprom, 1953 txpower = rt2x00_get_field16(eeprom,
1712 EEPROM_TXPOWER_BYRATE_RATE3); 1954 EEPROM_TXPOWER_BYRATE_RATE3);
1713 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE3, 1955 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band,
1714 min(txpower, max_value)); 1956 power_level, txpower);
1957 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE3, txpower);
1715 1958
1716 /* read the next four txpower values */ 1959 /* read the next four txpower values */
1717 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i + 1, 1960 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i + 1,
1718 &eeprom); 1961 &eeprom);
1719 1962
1720 /* TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0, 1963 is_rate_b = 0;
1964 /*
1965 * TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0,
1721 * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown, 1966 * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown,
1722 * TX_PWR_CFG_4: unknown */ 1967 * TX_PWR_CFG_4: unknown
1968 */
1723 txpower = rt2x00_get_field16(eeprom, 1969 txpower = rt2x00_get_field16(eeprom,
1724 EEPROM_TXPOWER_BYRATE_RATE0); 1970 EEPROM_TXPOWER_BYRATE_RATE0);
1725 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE4, 1971 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band,
1726 min(txpower, max_value)); 1972 power_level, txpower);
1973 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE4, txpower);
1727 1974
1728 /* TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1, 1975 /*
1976 * TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1,
1729 * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown, 1977 * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown,
1730 * TX_PWR_CFG_4: unknown */ 1978 * TX_PWR_CFG_4: unknown
1979 */
1731 txpower = rt2x00_get_field16(eeprom, 1980 txpower = rt2x00_get_field16(eeprom,
1732 EEPROM_TXPOWER_BYRATE_RATE1); 1981 EEPROM_TXPOWER_BYRATE_RATE1);
1733 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE5, 1982 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band,
1734 min(txpower, max_value)); 1983 power_level, txpower);
1984 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE5, txpower);
1735 1985
1736 /* TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2, 1986 /*
1987 * TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2,
1737 * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown, 1988 * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown,
1738 * TX_PWR_CFG_4: unknown */ 1989 * TX_PWR_CFG_4: unknown
1990 */
1739 txpower = rt2x00_get_field16(eeprom, 1991 txpower = rt2x00_get_field16(eeprom,
1740 EEPROM_TXPOWER_BYRATE_RATE2); 1992 EEPROM_TXPOWER_BYRATE_RATE2);
1741 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE6, 1993 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band,
1742 min(txpower, max_value)); 1994 power_level, txpower);
1995 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE6, txpower);
1743 1996
1744 /* TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3, 1997 /*
1998 * TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3,
1745 * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown, 1999 * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown,
1746 * TX_PWR_CFG_4: unknown */ 2000 * TX_PWR_CFG_4: unknown
2001 */
1747 txpower = rt2x00_get_field16(eeprom, 2002 txpower = rt2x00_get_field16(eeprom,
1748 EEPROM_TXPOWER_BYRATE_RATE3); 2003 EEPROM_TXPOWER_BYRATE_RATE3);
1749 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE7, 2004 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band,
1750 min(txpower, max_value)); 2005 power_level, txpower);
2006 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE7, txpower);
1751 2007
1752 rt2800_register_write(rt2x00dev, offset, reg); 2008 rt2800_register_write(rt2x00dev, offset, reg);
1753 2009
@@ -1806,11 +2062,13 @@ void rt2800_config(struct rt2x00_dev *rt2x00dev,
1806 /* Always recalculate LNA gain before changing configuration */ 2062 /* Always recalculate LNA gain before changing configuration */
1807 rt2800_config_lna_gain(rt2x00dev, libconf); 2063 rt2800_config_lna_gain(rt2x00dev, libconf);
1808 2064
1809 if (flags & IEEE80211_CONF_CHANGE_CHANNEL) 2065 if (flags & IEEE80211_CONF_CHANGE_CHANNEL) {
1810 rt2800_config_channel(rt2x00dev, libconf->conf, 2066 rt2800_config_channel(rt2x00dev, libconf->conf,
1811 &libconf->rf, &libconf->channel); 2067 &libconf->rf, &libconf->channel);
2068 rt2800_config_txpower(rt2x00dev, libconf->conf);
2069 }
1812 if (flags & IEEE80211_CONF_CHANGE_POWER) 2070 if (flags & IEEE80211_CONF_CHANGE_POWER)
1813 rt2800_config_txpower(rt2x00dev, libconf->conf->power_level); 2071 rt2800_config_txpower(rt2x00dev, libconf->conf);
1814 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS) 2072 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
1815 rt2800_config_retry_limit(rt2x00dev, libconf); 2073 rt2800_config_retry_limit(rt2x00dev, libconf);
1816 if (flags & IEEE80211_CONF_CHANGE_PS) 2074 if (flags & IEEE80211_CONF_CHANGE_PS)
@@ -1839,7 +2097,8 @@ static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev)
1839 if (rt2x00_rt(rt2x00dev, RT3070) || 2097 if (rt2x00_rt(rt2x00dev, RT3070) ||
1840 rt2x00_rt(rt2x00dev, RT3071) || 2098 rt2x00_rt(rt2x00dev, RT3071) ||
1841 rt2x00_rt(rt2x00dev, RT3090) || 2099 rt2x00_rt(rt2x00dev, RT3090) ||
1842 rt2x00_rt(rt2x00dev, RT3390)) 2100 rt2x00_rt(rt2x00dev, RT3390) ||
2101 rt2x00_rt(rt2x00dev, RT5390))
1843 return 0x1c + (2 * rt2x00dev->lna_gain); 2102 return 0x1c + (2 * rt2x00dev->lna_gain);
1844 else 2103 else
1845 return 0x2e + rt2x00dev->lna_gain; 2104 return 0x2e + rt2x00dev->lna_gain;
@@ -1971,6 +2230,10 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
1971 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); 2230 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
1972 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); 2231 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
1973 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000001f); 2232 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000001f);
2233 } else if (rt2x00_rt(rt2x00dev, RT5390)) {
2234 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
2235 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
2236 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
1974 } else { 2237 } else {
1975 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000); 2238 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
1976 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); 2239 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
@@ -2039,7 +2302,7 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
2039 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg); 2302 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
2040 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 3); 2303 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 3);
2041 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0); 2304 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
2042 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1); 2305 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV_SHORT, 1);
2043 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1); 2306 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
2044 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1); 2307 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
2045 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1); 2308 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
@@ -2052,7 +2315,7 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
2052 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg); 2315 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
2053 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 3); 2316 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 3);
2054 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0); 2317 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
2055 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1); 2318 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV_SHORT, 1);
2056 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1); 2319 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
2057 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1); 2320 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
2058 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1); 2321 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
@@ -2065,7 +2328,7 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
2065 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg); 2328 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
2066 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004); 2329 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
2067 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0); 2330 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
2068 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1); 2331 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV_SHORT, 1);
2069 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1); 2332 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
2070 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); 2333 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
2071 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1); 2334 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
@@ -2078,7 +2341,7 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
2078 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg); 2341 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
2079 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084); 2342 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
2080 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0); 2343 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
2081 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1); 2344 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV_SHORT, 1);
2082 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1); 2345 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
2083 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); 2346 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
2084 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1); 2347 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
@@ -2091,7 +2354,7 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
2091 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg); 2354 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
2092 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004); 2355 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
2093 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0); 2356 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
2094 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1); 2357 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV_SHORT, 1);
2095 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1); 2358 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
2096 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); 2359 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
2097 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1); 2360 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
@@ -2104,7 +2367,7 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
2104 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg); 2367 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
2105 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084); 2368 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
2106 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0); 2369 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
2107 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1); 2370 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV_SHORT, 1);
2108 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1); 2371 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
2109 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); 2372 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
2110 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1); 2373 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
@@ -2346,15 +2609,31 @@ static int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
2346 rt2800_wait_bbp_ready(rt2x00dev))) 2609 rt2800_wait_bbp_ready(rt2x00dev)))
2347 return -EACCES; 2610 return -EACCES;
2348 2611
2349 if (rt2800_is_305x_soc(rt2x00dev)) 2612 if (rt2x00_rt(rt2x00dev, RT5390)) {
2613 rt2800_bbp_read(rt2x00dev, 4, &value);
2614 rt2x00_set_field8(&value, BBP4_MAC_IF_CTRL, 1);
2615 rt2800_bbp_write(rt2x00dev, 4, value);
2616 }
2617
2618 if (rt2800_is_305x_soc(rt2x00dev) ||
2619 rt2x00_rt(rt2x00dev, RT5390))
2350 rt2800_bbp_write(rt2x00dev, 31, 0x08); 2620 rt2800_bbp_write(rt2x00dev, 31, 0x08);
2351 2621
2352 rt2800_bbp_write(rt2x00dev, 65, 0x2c); 2622 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
2353 rt2800_bbp_write(rt2x00dev, 66, 0x38); 2623 rt2800_bbp_write(rt2x00dev, 66, 0x38);
2354 2624
2625 if (rt2x00_rt(rt2x00dev, RT5390))
2626 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
2627
2355 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) { 2628 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
2356 rt2800_bbp_write(rt2x00dev, 69, 0x16); 2629 rt2800_bbp_write(rt2x00dev, 69, 0x16);
2357 rt2800_bbp_write(rt2x00dev, 73, 0x12); 2630 rt2800_bbp_write(rt2x00dev, 73, 0x12);
2631 } else if (rt2x00_rt(rt2x00dev, RT5390)) {
2632 rt2800_bbp_write(rt2x00dev, 69, 0x12);
2633 rt2800_bbp_write(rt2x00dev, 73, 0x13);
2634 rt2800_bbp_write(rt2x00dev, 75, 0x46);
2635 rt2800_bbp_write(rt2x00dev, 76, 0x28);
2636 rt2800_bbp_write(rt2x00dev, 77, 0x59);
2358 } else { 2637 } else {
2359 rt2800_bbp_write(rt2x00dev, 69, 0x12); 2638 rt2800_bbp_write(rt2x00dev, 69, 0x12);
2360 rt2800_bbp_write(rt2x00dev, 73, 0x10); 2639 rt2800_bbp_write(rt2x00dev, 73, 0x10);
@@ -2365,7 +2644,8 @@ static int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
2365 if (rt2x00_rt(rt2x00dev, RT3070) || 2644 if (rt2x00_rt(rt2x00dev, RT3070) ||
2366 rt2x00_rt(rt2x00dev, RT3071) || 2645 rt2x00_rt(rt2x00dev, RT3071) ||
2367 rt2x00_rt(rt2x00dev, RT3090) || 2646 rt2x00_rt(rt2x00dev, RT3090) ||
2368 rt2x00_rt(rt2x00dev, RT3390)) { 2647 rt2x00_rt(rt2x00dev, RT3390) ||
2648 rt2x00_rt(rt2x00dev, RT5390)) {
2369 rt2800_bbp_write(rt2x00dev, 79, 0x13); 2649 rt2800_bbp_write(rt2x00dev, 79, 0x13);
2370 rt2800_bbp_write(rt2x00dev, 80, 0x05); 2650 rt2800_bbp_write(rt2x00dev, 80, 0x05);
2371 rt2800_bbp_write(rt2x00dev, 81, 0x33); 2651 rt2800_bbp_write(rt2x00dev, 81, 0x33);
@@ -2377,35 +2657,62 @@ static int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
2377 } 2657 }
2378 2658
2379 rt2800_bbp_write(rt2x00dev, 82, 0x62); 2659 rt2800_bbp_write(rt2x00dev, 82, 0x62);
2380 rt2800_bbp_write(rt2x00dev, 83, 0x6a); 2660 if (rt2x00_rt(rt2x00dev, RT5390))
2661 rt2800_bbp_write(rt2x00dev, 83, 0x7a);
2662 else
2663 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
2381 2664
2382 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D)) 2665 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D))
2383 rt2800_bbp_write(rt2x00dev, 84, 0x19); 2666 rt2800_bbp_write(rt2x00dev, 84, 0x19);
2667 else if (rt2x00_rt(rt2x00dev, RT5390))
2668 rt2800_bbp_write(rt2x00dev, 84, 0x9a);
2384 else 2669 else
2385 rt2800_bbp_write(rt2x00dev, 84, 0x99); 2670 rt2800_bbp_write(rt2x00dev, 84, 0x99);
2386 2671
2387 rt2800_bbp_write(rt2x00dev, 86, 0x00); 2672 if (rt2x00_rt(rt2x00dev, RT5390))
2673 rt2800_bbp_write(rt2x00dev, 86, 0x38);
2674 else
2675 rt2800_bbp_write(rt2x00dev, 86, 0x00);
2676
2388 rt2800_bbp_write(rt2x00dev, 91, 0x04); 2677 rt2800_bbp_write(rt2x00dev, 91, 0x04);
2389 rt2800_bbp_write(rt2x00dev, 92, 0x00); 2678
2679 if (rt2x00_rt(rt2x00dev, RT5390))
2680 rt2800_bbp_write(rt2x00dev, 92, 0x02);
2681 else
2682 rt2800_bbp_write(rt2x00dev, 92, 0x00);
2390 2683
2391 if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) || 2684 if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) ||
2392 rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) || 2685 rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) ||
2393 rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E) || 2686 rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E) ||
2394 rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E) || 2687 rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E) ||
2688 rt2x00_rt(rt2x00dev, RT5390) ||
2395 rt2800_is_305x_soc(rt2x00dev)) 2689 rt2800_is_305x_soc(rt2x00dev))
2396 rt2800_bbp_write(rt2x00dev, 103, 0xc0); 2690 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
2397 else 2691 else
2398 rt2800_bbp_write(rt2x00dev, 103, 0x00); 2692 rt2800_bbp_write(rt2x00dev, 103, 0x00);
2399 2693
2694 if (rt2x00_rt(rt2x00dev, RT5390))
2695 rt2800_bbp_write(rt2x00dev, 104, 0x92);
2696
2400 if (rt2800_is_305x_soc(rt2x00dev)) 2697 if (rt2800_is_305x_soc(rt2x00dev))
2401 rt2800_bbp_write(rt2x00dev, 105, 0x01); 2698 rt2800_bbp_write(rt2x00dev, 105, 0x01);
2699 else if (rt2x00_rt(rt2x00dev, RT5390))
2700 rt2800_bbp_write(rt2x00dev, 105, 0x3c);
2402 else 2701 else
2403 rt2800_bbp_write(rt2x00dev, 105, 0x05); 2702 rt2800_bbp_write(rt2x00dev, 105, 0x05);
2404 rt2800_bbp_write(rt2x00dev, 106, 0x35); 2703
2704 if (rt2x00_rt(rt2x00dev, RT5390))
2705 rt2800_bbp_write(rt2x00dev, 106, 0x03);
2706 else
2707 rt2800_bbp_write(rt2x00dev, 106, 0x35);
2708
2709 if (rt2x00_rt(rt2x00dev, RT5390))
2710 rt2800_bbp_write(rt2x00dev, 128, 0x12);
2405 2711
2406 if (rt2x00_rt(rt2x00dev, RT3071) || 2712 if (rt2x00_rt(rt2x00dev, RT3071) ||
2407 rt2x00_rt(rt2x00dev, RT3090) || 2713 rt2x00_rt(rt2x00dev, RT3090) ||
2408 rt2x00_rt(rt2x00dev, RT3390)) { 2714 rt2x00_rt(rt2x00dev, RT3390) ||
2715 rt2x00_rt(rt2x00dev, RT5390)) {
2409 rt2800_bbp_read(rt2x00dev, 138, &value); 2716 rt2800_bbp_read(rt2x00dev, 138, &value);
2410 2717
2411 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); 2718 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
@@ -2417,6 +2724,41 @@ static int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
2417 rt2800_bbp_write(rt2x00dev, 138, value); 2724 rt2800_bbp_write(rt2x00dev, 138, value);
2418 } 2725 }
2419 2726
2727 if (rt2x00_rt(rt2x00dev, RT5390)) {
2728 int ant, div_mode;
2729
2730 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
2731 div_mode = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_ANT_DIVERSITY);
2732 ant = (div_mode == 3) ? 1 : 0;
2733
2734 /* check if this is a Bluetooth combo card */
2735 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
2736 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST)) {
2737 u32 reg;
2738
2739 rt2800_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
2740 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_GPIOD_BIT3, 0);
2741 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_GPIOD_BIT6, 0);
2742 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_BIT3, 0);
2743 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_BIT6, 0);
2744 if (ant == 0)
2745 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_BIT3, 1);
2746 else if (ant == 1)
2747 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_BIT6, 1);
2748 rt2800_register_write(rt2x00dev, GPIO_CTRL_CFG, reg);
2749 }
2750
2751 rt2800_bbp_read(rt2x00dev, 152, &value);
2752 if (ant == 0)
2753 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
2754 else
2755 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
2756 rt2800_bbp_write(rt2x00dev, 152, value);
2757
2758 /* Init frequency calibration */
2759 rt2800_bbp_write(rt2x00dev, 142, 1);
2760 rt2800_bbp_write(rt2x00dev, 143, 57);
2761 }
2420 2762
2421 for (i = 0; i < EEPROM_BBP_SIZE; i++) { 2763 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
2422 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom); 2764 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
@@ -2506,18 +2848,28 @@ static int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
2506 !rt2x00_rt(rt2x00dev, RT3071) && 2848 !rt2x00_rt(rt2x00dev, RT3071) &&
2507 !rt2x00_rt(rt2x00dev, RT3090) && 2849 !rt2x00_rt(rt2x00dev, RT3090) &&
2508 !rt2x00_rt(rt2x00dev, RT3390) && 2850 !rt2x00_rt(rt2x00dev, RT3390) &&
2851 !rt2x00_rt(rt2x00dev, RT5390) &&
2509 !rt2800_is_305x_soc(rt2x00dev)) 2852 !rt2800_is_305x_soc(rt2x00dev))
2510 return 0; 2853 return 0;
2511 2854
2512 /* 2855 /*
2513 * Init RF calibration. 2856 * Init RF calibration.
2514 */ 2857 */
2515 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); 2858 if (rt2x00_rt(rt2x00dev, RT5390)) {
2516 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1); 2859 rt2800_rfcsr_read(rt2x00dev, 2, &rfcsr);
2517 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); 2860 rt2x00_set_field8(&rfcsr, RFCSR2_RESCAL_EN, 1);
2518 msleep(1); 2861 rt2800_rfcsr_write(rt2x00dev, 2, rfcsr);
2519 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0); 2862 msleep(1);
2520 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); 2863 rt2x00_set_field8(&rfcsr, RFCSR2_RESCAL_EN, 0);
2864 rt2800_rfcsr_write(rt2x00dev, 2, rfcsr);
2865 } else {
2866 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
2867 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
2868 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2869 msleep(1);
2870 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
2871 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2872 }
2521 2873
2522 if (rt2x00_rt(rt2x00dev, RT3070) || 2874 if (rt2x00_rt(rt2x00dev, RT3070) ||
2523 rt2x00_rt(rt2x00dev, RT3071) || 2875 rt2x00_rt(rt2x00dev, RT3071) ||
@@ -2608,6 +2960,87 @@ static int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
2608 rt2800_rfcsr_write(rt2x00dev, 30, 0x00); 2960 rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
2609 rt2800_rfcsr_write(rt2x00dev, 31, 0x00); 2961 rt2800_rfcsr_write(rt2x00dev, 31, 0x00);
2610 return 0; 2962 return 0;
2963 } else if (rt2x00_rt(rt2x00dev, RT5390)) {
2964 rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
2965 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
2966 rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
2967 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
2968 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
2969 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
2970 else
2971 rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
2972 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
2973 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
2974 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
2975 rt2800_rfcsr_write(rt2x00dev, 12, 0xc6);
2976 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
2977 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
2978 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
2979 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
2980 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
2981 rt2800_rfcsr_write(rt2x00dev, 19, 0x00);
2982
2983 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
2984 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
2985 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
2986 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
2987 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
2988 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
2989 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
2990 else
2991 rt2800_rfcsr_write(rt2x00dev, 25, 0xc0);
2992 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
2993 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
2994 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
2995 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
2996
2997 rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
2998 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
2999 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
3000 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
3001 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
3002 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
3003 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
3004 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
3005 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
3006 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
3007
3008 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
3009 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
3010 else
3011 rt2800_rfcsr_write(rt2x00dev, 40, 0x4b);
3012 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
3013 rt2800_rfcsr_write(rt2x00dev, 42, 0xd2);
3014 rt2800_rfcsr_write(rt2x00dev, 43, 0x9a);
3015 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
3016 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
3017 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
3018 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
3019 else
3020 rt2800_rfcsr_write(rt2x00dev, 46, 0x7b);
3021 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
3022 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
3023 rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
3024
3025 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
3026 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
3027 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
3028 else
3029 rt2800_rfcsr_write(rt2x00dev, 53, 0x84);
3030 rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
3031 rt2800_rfcsr_write(rt2x00dev, 55, 0x44);
3032 rt2800_rfcsr_write(rt2x00dev, 56, 0x22);
3033 rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
3034 rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
3035 rt2800_rfcsr_write(rt2x00dev, 59, 0x63);
3036
3037 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
3038 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
3039 rt2800_rfcsr_write(rt2x00dev, 61, 0xd1);
3040 else
3041 rt2800_rfcsr_write(rt2x00dev, 61, 0xdd);
3042 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
3043 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
2611 } 3044 }
2612 3045
2613 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { 3046 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
@@ -2661,21 +3094,23 @@ static int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
2661 rt2800_init_rx_filter(rt2x00dev, true, 0x27, 0x15); 3094 rt2800_init_rx_filter(rt2x00dev, true, 0x27, 0x15);
2662 } 3095 }
2663 3096
2664 /* 3097 if (!rt2x00_rt(rt2x00dev, RT5390)) {
2665 * Set back to initial state 3098 /*
2666 */ 3099 * Set back to initial state
2667 rt2800_bbp_write(rt2x00dev, 24, 0); 3100 */
3101 rt2800_bbp_write(rt2x00dev, 24, 0);
2668 3102
2669 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr); 3103 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
2670 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0); 3104 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
2671 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr); 3105 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
2672 3106
2673 /* 3107 /*
2674 * set BBP back to BW20 3108 * Set BBP back to BW20
2675 */ 3109 */
2676 rt2800_bbp_read(rt2x00dev, 4, &bbp); 3110 rt2800_bbp_read(rt2x00dev, 4, &bbp);
2677 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0); 3111 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
2678 rt2800_bbp_write(rt2x00dev, 4, bbp); 3112 rt2800_bbp_write(rt2x00dev, 4, bbp);
3113 }
2679 3114
2680 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) || 3115 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) ||
2681 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || 3116 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
@@ -2687,21 +3122,23 @@ static int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
2687 rt2x00_set_field32(&reg, OPT_14_CSR_BIT0, 1); 3122 rt2x00_set_field32(&reg, OPT_14_CSR_BIT0, 1);
2688 rt2800_register_write(rt2x00dev, OPT_14_CSR, reg); 3123 rt2800_register_write(rt2x00dev, OPT_14_CSR, reg);
2689 3124
2690 rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr); 3125 if (!rt2x00_rt(rt2x00dev, RT5390)) {
2691 rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0); 3126 rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
2692 if (rt2x00_rt(rt2x00dev, RT3070) || 3127 rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0);
2693 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || 3128 if (rt2x00_rt(rt2x00dev, RT3070) ||
2694 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || 3129 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
2695 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) { 3130 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
2696 if (!test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) 3131 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
2697 rt2x00_set_field8(&rfcsr, RFCSR17_R, 1); 3132 if (!test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
2698 } 3133 rt2x00_set_field8(&rfcsr, RFCSR17_R, 1);
2699 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &eeprom); 3134 }
2700 if (rt2x00_get_field16(eeprom, EEPROM_TXMIXER_GAIN_BG_VAL) >= 1) 3135 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &eeprom);
2701 rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN, 3136 if (rt2x00_get_field16(eeprom, EEPROM_TXMIXER_GAIN_BG_VAL) >= 1)
2702 rt2x00_get_field16(eeprom, 3137 rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN,
2703 EEPROM_TXMIXER_GAIN_BG_VAL)); 3138 rt2x00_get_field16(eeprom,
2704 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr); 3139 EEPROM_TXMIXER_GAIN_BG_VAL));
3140 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
3141 }
2705 3142
2706 if (rt2x00_rt(rt2x00dev, RT3090)) { 3143 if (rt2x00_rt(rt2x00dev, RT3090)) {
2707 rt2800_bbp_read(rt2x00dev, 138, &bbp); 3144 rt2800_bbp_read(rt2x00dev, 138, &bbp);
@@ -2752,6 +3189,20 @@ static int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
2752 rt2800_rfcsr_write(rt2x00dev, 27, rfcsr); 3189 rt2800_rfcsr_write(rt2x00dev, 27, rfcsr);
2753 } 3190 }
2754 3191
3192 if (rt2x00_rt(rt2x00dev, RT5390)) {
3193 rt2800_rfcsr_read(rt2x00dev, 38, &rfcsr);
3194 rt2x00_set_field8(&rfcsr, RFCSR38_RX_LO1_EN, 0);
3195 rt2800_rfcsr_write(rt2x00dev, 38, rfcsr);
3196
3197 rt2800_rfcsr_read(rt2x00dev, 39, &rfcsr);
3198 rt2x00_set_field8(&rfcsr, RFCSR39_RX_LO2_EN, 0);
3199 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
3200
3201 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
3202 rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2);
3203 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
3204 }
3205
2755 return 0; 3206 return 0;
2756} 3207}
2757 3208
@@ -3000,13 +3451,6 @@ int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
3000 default_lna_gain); 3451 default_lna_gain);
3001 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word); 3452 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
3002 3453
3003 rt2x00_eeprom_read(rt2x00dev, EEPROM_MAX_TX_POWER, &word);
3004 if (rt2x00_get_field16(word, EEPROM_MAX_TX_POWER_24GHZ) == 0xff)
3005 rt2x00_set_field16(&word, EEPROM_MAX_TX_POWER_24GHZ, MAX_G_TXPOWER);
3006 if (rt2x00_get_field16(word, EEPROM_MAX_TX_POWER_5GHZ) == 0xff)
3007 rt2x00_set_field16(&word, EEPROM_MAX_TX_POWER_5GHZ, MAX_A_TXPOWER);
3008 rt2x00_eeprom_write(rt2x00dev, EEPROM_MAX_TX_POWER, word);
3009
3010 return 0; 3454 return 0;
3011} 3455}
3012EXPORT_SYMBOL_GPL(rt2800_validate_eeprom); 3456EXPORT_SYMBOL_GPL(rt2800_validate_eeprom);
@@ -3023,10 +3467,15 @@ int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
3023 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); 3467 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
3024 3468
3025 /* 3469 /*
3026 * Identify RF chipset. 3470 * Identify RF chipset by EEPROM value
3471 * RT28xx/RT30xx: defined in "EEPROM_NIC_CONF0_RF_TYPE" field
3472 * RT53xx: defined in "EEPROM_CHIP_ID" field
3027 */ 3473 */
3028 value = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE);
3029 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg); 3474 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
3475 if (rt2x00_get_field32(reg, MAC_CSR0_CHIPSET) == RT5390)
3476 rt2x00_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &value);
3477 else
3478 value = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE);
3030 3479
3031 rt2x00_set_chip(rt2x00dev, rt2x00_get_field32(reg, MAC_CSR0_CHIPSET), 3480 rt2x00_set_chip(rt2x00dev, rt2x00_get_field32(reg, MAC_CSR0_CHIPSET),
3032 value, rt2x00_get_field32(reg, MAC_CSR0_REVISION)); 3481 value, rt2x00_get_field32(reg, MAC_CSR0_REVISION));
@@ -3038,7 +3487,8 @@ int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
3038 !rt2x00_rt(rt2x00dev, RT3071) && 3487 !rt2x00_rt(rt2x00dev, RT3071) &&
3039 !rt2x00_rt(rt2x00dev, RT3090) && 3488 !rt2x00_rt(rt2x00dev, RT3090) &&
3040 !rt2x00_rt(rt2x00dev, RT3390) && 3489 !rt2x00_rt(rt2x00dev, RT3390) &&
3041 !rt2x00_rt(rt2x00dev, RT3572)) { 3490 !rt2x00_rt(rt2x00dev, RT3572) &&
3491 !rt2x00_rt(rt2x00dev, RT5390)) {
3042 ERROR(rt2x00dev, "Invalid RT chipset detected.\n"); 3492 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
3043 return -ENODEV; 3493 return -ENODEV;
3044 } 3494 }
@@ -3052,7 +3502,8 @@ int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
3052 !rt2x00_rf(rt2x00dev, RF3021) && 3502 !rt2x00_rf(rt2x00dev, RF3021) &&
3053 !rt2x00_rf(rt2x00dev, RF3022) && 3503 !rt2x00_rf(rt2x00dev, RF3022) &&
3054 !rt2x00_rf(rt2x00dev, RF3052) && 3504 !rt2x00_rf(rt2x00dev, RF3052) &&
3055 !rt2x00_rf(rt2x00dev, RF3320)) { 3505 !rt2x00_rf(rt2x00dev, RF3320) &&
3506 !rt2x00_rf(rt2x00dev, RF5390)) {
3056 ERROR(rt2x00dev, "Invalid RF chipset detected.\n"); 3507 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
3057 return -ENODEV; 3508 return -ENODEV;
3058 } 3509 }
@@ -3060,11 +3511,35 @@ int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
3060 /* 3511 /*
3061 * Identify default antenna configuration. 3512 * Identify default antenna configuration.
3062 */ 3513 */
3063 rt2x00dev->default_ant.tx = 3514 rt2x00dev->default_ant.tx_chain_num =
3064 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH); 3515 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH);
3065 rt2x00dev->default_ant.rx = 3516 rt2x00dev->default_ant.rx_chain_num =
3066 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH); 3517 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH);
3067 3518
3519 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
3520
3521 if (rt2x00_rt(rt2x00dev, RT3070) ||
3522 rt2x00_rt(rt2x00dev, RT3090) ||
3523 rt2x00_rt(rt2x00dev, RT3390)) {
3524 value = rt2x00_get_field16(eeprom,
3525 EEPROM_NIC_CONF1_ANT_DIVERSITY);
3526 switch (value) {
3527 case 0:
3528 case 1:
3529 case 2:
3530 rt2x00dev->default_ant.tx = ANTENNA_A;
3531 rt2x00dev->default_ant.rx = ANTENNA_A;
3532 break;
3533 case 3:
3534 rt2x00dev->default_ant.tx = ANTENNA_A;
3535 rt2x00dev->default_ant.rx = ANTENNA_B;
3536 break;
3537 }
3538 } else {
3539 rt2x00dev->default_ant.tx = ANTENNA_A;
3540 rt2x00dev->default_ant.rx = ANTENNA_A;
3541 }
3542
3068 /* 3543 /*
3069 * Read frequency offset and RF programming sequence. 3544 * Read frequency offset and RF programming sequence.
3070 */ 3545 */
@@ -3098,6 +3573,15 @@ int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
3098 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &rt2x00dev->led_mcu_reg); 3573 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &rt2x00dev->led_mcu_reg);
3099#endif /* CONFIG_RT2X00_LIB_LEDS */ 3574#endif /* CONFIG_RT2X00_LIB_LEDS */
3100 3575
3576 /*
3577 * Check if support EIRP tx power limit feature.
3578 */
3579 rt2x00_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, &eeprom);
3580
3581 if (rt2x00_get_field16(eeprom, EEPROM_EIRP_MAX_TX_POWER_2GHZ) <
3582 EIRP_MAX_TX_POWER_LIMIT)
3583 __set_bit(CONFIG_SUPPORT_POWER_LIMIT, &rt2x00dev->flags);
3584
3101 return 0; 3585 return 0;
3102} 3586}
3103EXPORT_SYMBOL_GPL(rt2800_init_eeprom); 3587EXPORT_SYMBOL_GPL(rt2800_init_eeprom);
@@ -3250,7 +3734,6 @@ int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
3250 char *default_power1; 3734 char *default_power1;
3251 char *default_power2; 3735 char *default_power2;
3252 unsigned int i; 3736 unsigned int i;
3253 unsigned short max_power;
3254 u16 eeprom; 3737 u16 eeprom;
3255 3738
3256 /* 3739 /*
@@ -3317,7 +3800,8 @@ int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
3317 rt2x00_rf(rt2x00dev, RF2020) || 3800 rt2x00_rf(rt2x00dev, RF2020) ||
3318 rt2x00_rf(rt2x00dev, RF3021) || 3801 rt2x00_rf(rt2x00dev, RF3021) ||
3319 rt2x00_rf(rt2x00dev, RF3022) || 3802 rt2x00_rf(rt2x00dev, RF3022) ||
3320 rt2x00_rf(rt2x00dev, RF3320)) { 3803 rt2x00_rf(rt2x00dev, RF3320) ||
3804 rt2x00_rf(rt2x00dev, RF5390)) {
3321 spec->num_channels = 14; 3805 spec->num_channels = 14;
3322 spec->channels = rf_vals_3x; 3806 spec->channels = rf_vals_3x;
3323 } else if (rt2x00_rf(rt2x00dev, RF3052)) { 3807 } else if (rt2x00_rf(rt2x00dev, RF3052)) {
@@ -3375,26 +3859,21 @@ int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
3375 3859
3376 spec->channels_info = info; 3860 spec->channels_info = info;
3377 3861
3378 rt2x00_eeprom_read(rt2x00dev, EEPROM_MAX_TX_POWER, &eeprom);
3379 max_power = rt2x00_get_field16(eeprom, EEPROM_MAX_TX_POWER_24GHZ);
3380 default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1); 3862 default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
3381 default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2); 3863 default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
3382 3864
3383 for (i = 0; i < 14; i++) { 3865 for (i = 0; i < 14; i++) {
3384 info[i].max_power = max_power; 3866 info[i].default_power1 = default_power1[i];
3385 info[i].default_power1 = TXPOWER_G_FROM_DEV(default_power1[i]); 3867 info[i].default_power2 = default_power2[i];
3386 info[i].default_power2 = TXPOWER_G_FROM_DEV(default_power2[i]);
3387 } 3868 }
3388 3869
3389 if (spec->num_channels > 14) { 3870 if (spec->num_channels > 14) {
3390 max_power = rt2x00_get_field16(eeprom, EEPROM_MAX_TX_POWER_5GHZ);
3391 default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1); 3871 default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
3392 default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2); 3872 default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
3393 3873
3394 for (i = 14; i < spec->num_channels; i++) { 3874 for (i = 14; i < spec->num_channels; i++) {
3395 info[i].max_power = max_power; 3875 info[i].default_power1 = default_power1[i];
3396 info[i].default_power1 = TXPOWER_A_FROM_DEV(default_power1[i]); 3876 info[i].default_power2 = default_power2[i];
3397 info[i].default_power2 = TXPOWER_A_FROM_DEV(default_power2[i]);
3398 } 3877 }
3399 } 3878 }
3400 3879