aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2009-11-08 08:39:01 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-11-11 17:09:14 -0500
commit38bd7b8a0f485ba5ad514fcd621a1842ebadf9e6 (patch)
tree115e9fd1f31efbf826531b2ff88c7addd442984c /drivers
parent7ab71325cf0940099c376799aca6de7bc86ad2d0 (diff)
rt2800: unify EEPROM support code
Add rt2800_validate_eeprom() and rt2800_init_eeprom() to rt2800lib. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Acked-by: Ivo van Doorn <IvDoorn@gmail.com> Acked-by: Gertjan van Wingerde <gwingerde@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c199
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.h3
-rw-r--r--drivers/net/wireless/rt2x00/rt2800pci.c183
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c195
4 files changed, 204 insertions, 376 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index 5c7d74a6f16e..2c211199e569 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -1659,6 +1659,205 @@ int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
1659} 1659}
1660EXPORT_SYMBOL_GPL(rt2800_init_rfcsr); 1660EXPORT_SYMBOL_GPL(rt2800_init_rfcsr);
1661 1661
1662int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1663{
1664 u16 word;
1665 u8 *mac;
1666 u8 default_lna_gain;
1667
1668 /*
1669 * Start validation of the data that has been read.
1670 */
1671 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
1672 if (!is_valid_ether_addr(mac)) {
1673 random_ether_addr(mac);
1674 EEPROM(rt2x00dev, "MAC: %pM\n", mac);
1675 }
1676
1677 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
1678 if (word == 0xffff) {
1679 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
1680 rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
1681 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
1682 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1683 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
1684 } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
1685 /*
1686 * There is a max of 2 RX streams for RT28x0 series
1687 */
1688 if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
1689 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
1690 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1691 }
1692
1693 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
1694 if (word == 0xffff) {
1695 rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
1696 rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
1697 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
1698 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
1699 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
1700 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
1701 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
1702 rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
1703 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
1704 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
1705 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
1706 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
1707 }
1708
1709 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
1710 if ((word & 0x00ff) == 0x00ff) {
1711 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
1712 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
1713 LED_MODE_TXRX_ACTIVITY);
1714 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
1715 rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
1716 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
1717 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
1718 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
1719 EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
1720 }
1721
1722 /*
1723 * During the LNA validation we are going to use
1724 * lna0 as correct value. Note that EEPROM_LNA
1725 * is never validated.
1726 */
1727 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
1728 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
1729
1730 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
1731 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
1732 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
1733 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
1734 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
1735 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
1736
1737 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
1738 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
1739 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
1740 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
1741 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
1742 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
1743 default_lna_gain);
1744 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
1745
1746 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
1747 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
1748 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
1749 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
1750 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
1751 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
1752
1753 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
1754 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
1755 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
1756 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
1757 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
1758 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
1759 default_lna_gain);
1760 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
1761
1762 return 0;
1763}
1764EXPORT_SYMBOL_GPL(rt2800_validate_eeprom);
1765
1766int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
1767{
1768 u32 reg;
1769 u16 value;
1770 u16 eeprom;
1771
1772 /*
1773 * Read EEPROM word for configuration.
1774 */
1775 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
1776
1777 /*
1778 * Identify RF chipset.
1779 */
1780 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1781 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
1782
1783 if (rt2x00_intf_is_usb(rt2x00dev)) {
1784 struct rt2x00_chip *chip = &rt2x00dev->chip;
1785
1786 rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
1787
1788 /*
1789 * The check for rt2860 is not a typo, some rt2870 hardware
1790 * identifies itself as rt2860 in the CSR register.
1791 */
1792 if (!rt2x00_check_rev(chip, 0xfff00000, 0x28600000) &&
1793 !rt2x00_check_rev(chip, 0xfff00000, 0x28700000) &&
1794 !rt2x00_check_rev(chip, 0xfff00000, 0x28800000) &&
1795 !rt2x00_check_rev(chip, 0xffff0000, 0x30700000)) {
1796 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
1797 return -ENODEV;
1798 }
1799 } else if (rt2x00_intf_is_pci(rt2x00dev))
1800 rt2x00_set_chip_rf(rt2x00dev, value, reg);
1801
1802 if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
1803 !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
1804 !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
1805 !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
1806 !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
1807 !rt2x00_rf(&rt2x00dev->chip, RF2020) &&
1808 (rt2x00_intf_is_usb(rt2x00dev) ||
1809 (rt2x00_intf_is_pci(rt2x00dev) &&
1810 !rt2x00_rf(&rt2x00dev->chip, RF3021) &&
1811 !rt2x00_rf(&rt2x00dev->chip, RF3022)))) {
1812 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
1813 return -ENODEV;
1814 }
1815
1816 /*
1817 * Identify default antenna configuration.
1818 */
1819 rt2x00dev->default_ant.tx =
1820 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
1821 rt2x00dev->default_ant.rx =
1822 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
1823
1824 /*
1825 * Read frequency offset and RF programming sequence.
1826 */
1827 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
1828 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
1829
1830 /*
1831 * Read external LNA informations.
1832 */
1833 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
1834
1835 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
1836 __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
1837 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
1838 __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
1839
1840 /*
1841 * Detect if this device has an hardware controlled radio.
1842 */
1843 if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
1844 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1845
1846 /*
1847 * Store led settings, for correct led behaviour.
1848 */
1849#ifdef CONFIG_RT2X00_LIB_LEDS
1850 rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
1851 rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
1852 rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
1853
1854 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &rt2x00dev->led_mcu_reg);
1855#endif /* CONFIG_RT2X00_LIB_LEDS */
1856
1857 return 0;
1858}
1859EXPORT_SYMBOL_GPL(rt2800_init_eeprom);
1860
1662/* 1861/*
1663 * IEEE80211 stack callback functions. 1862 * IEEE80211 stack callback functions.
1664 */ 1863 */
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.h b/drivers/net/wireless/rt2x00/rt2800lib.h
index 5eea8fcba6cc..da447114c83b 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.h
+++ b/drivers/net/wireless/rt2x00/rt2800lib.h
@@ -129,6 +129,9 @@ int rt2800_init_registers(struct rt2x00_dev *rt2x00dev);
129int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev); 129int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev);
130int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev); 130int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev);
131 131
132int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev);
133int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev);
134
132extern const struct ieee80211_ops rt2800_mac80211_ops; 135extern const struct ieee80211_ops rt2800_mac80211_ops;
133 136
134#endif /* RT2800LIB_H */ 137#endif /* RT2800LIB_H */
diff --git a/drivers/net/wireless/rt2x00/rt2800pci.c b/drivers/net/wireless/rt2x00/rt2800pci.c
index 67081a4f04bd..06d9835bbc56 100644
--- a/drivers/net/wireless/rt2x00/rt2800pci.c
+++ b/drivers/net/wireless/rt2x00/rt2800pci.c
@@ -1091,109 +1091,6 @@ static irqreturn_t rt2800pci_interrupt(int irq, void *dev_instance)
1091/* 1091/*
1092 * Device probe functions. 1092 * Device probe functions.
1093 */ 1093 */
1094static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1095{
1096 u16 word;
1097 u8 *mac;
1098 u8 default_lna_gain;
1099
1100 /*
1101 * Start validation of the data that has been read.
1102 */
1103 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
1104 if (!is_valid_ether_addr(mac)) {
1105 random_ether_addr(mac);
1106 EEPROM(rt2x00dev, "MAC: %pM\n", mac);
1107 }
1108
1109 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
1110 if (word == 0xffff) {
1111 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
1112 rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
1113 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
1114 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1115 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
1116 } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
1117 /*
1118 * There is a max of 2 RX streams for RT28x0 series
1119 */
1120 if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
1121 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
1122 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1123 }
1124
1125 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
1126 if (word == 0xffff) {
1127 rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
1128 rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
1129 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
1130 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
1131 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
1132 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
1133 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
1134 rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
1135 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
1136 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
1137 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
1138 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
1139 }
1140
1141 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
1142 if ((word & 0x00ff) == 0x00ff) {
1143 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
1144 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
1145 LED_MODE_TXRX_ACTIVITY);
1146 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
1147 rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
1148 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
1149 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
1150 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
1151 EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
1152 }
1153
1154 /*
1155 * During the LNA validation we are going to use
1156 * lna0 as correct value. Note that EEPROM_LNA
1157 * is never validated.
1158 */
1159 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
1160 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
1161
1162 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
1163 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
1164 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
1165 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
1166 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
1167 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
1168
1169 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
1170 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
1171 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
1172 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
1173 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
1174 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
1175 default_lna_gain);
1176 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
1177
1178 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
1179 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
1180 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
1181 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
1182 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
1183 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
1184
1185 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
1186 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
1187 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
1188 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
1189 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
1190 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
1191 default_lna_gain);
1192 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
1193
1194 return 0;
1195}
1196
1197static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev) 1094static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1198{ 1095{
1199 /* 1096 /*
@@ -1215,84 +1112,6 @@ static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1215 return rt2800_validate_eeprom(rt2x00dev); 1112 return rt2800_validate_eeprom(rt2x00dev);
1216} 1113}
1217 1114
1218static int rt2800pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1219{
1220 u32 reg;
1221 u16 value;
1222 u16 eeprom;
1223
1224 /*
1225 * Read EEPROM word for configuration.
1226 */
1227 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
1228
1229 /*
1230 * Identify RF chipset.
1231 */
1232 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1233 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
1234
1235 if (rt2x00_intf_is_pci(rt2x00dev))
1236 rt2x00_set_chip_rf(rt2x00dev, value, reg);
1237
1238 if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
1239 !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
1240 !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
1241 !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
1242 !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
1243 !rt2x00_rf(&rt2x00dev->chip, RF2020) &&
1244 (rt2x00_intf_is_usb(rt2x00dev) ||
1245 (rt2x00_intf_is_pci(rt2x00dev) &&
1246 !rt2x00_rf(&rt2x00dev->chip, RF3021) &&
1247 !rt2x00_rf(&rt2x00dev->chip, RF3022)))) {
1248 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
1249 return -ENODEV;
1250 }
1251
1252 /*
1253 * Identify default antenna configuration.
1254 */
1255 rt2x00dev->default_ant.tx =
1256 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
1257 rt2x00dev->default_ant.rx =
1258 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
1259
1260 /*
1261 * Read frequency offset and RF programming sequence.
1262 */
1263 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
1264 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
1265
1266 /*
1267 * Read external LNA informations.
1268 */
1269 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
1270
1271 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
1272 __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
1273 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
1274 __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
1275
1276 /*
1277 * Detect if this device has an hardware controlled radio.
1278 */
1279 if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
1280 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1281
1282 /*
1283 * Store led settings, for correct led behaviour.
1284 */
1285#ifdef CONFIG_RT2X00_LIB_LEDS
1286 rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
1287 rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
1288 rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
1289
1290 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &rt2x00dev->led_mcu_reg);
1291#endif /* CONFIG_RT2X00_LIB_LEDS */
1292
1293 return 0;
1294}
1295
1296/* 1115/*
1297 * RF value list for rt2860 1116 * RF value list for rt2860
1298 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750) 1117 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
@@ -1497,7 +1316,7 @@ static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
1497 if (retval) 1316 if (retval)
1498 return retval; 1317 return retval;
1499 1318
1500 retval = rt2800pci_init_eeprom(rt2x00dev); 1319 retval = rt2800_init_eeprom(rt2x00dev);
1501 if (retval) 1320 if (retval)
1502 return retval; 1321 return retval;
1503 1322
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index 080947cc5d6b..347c14df63c8 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -665,109 +665,6 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry,
665/* 665/*
666 * Device probe functions. 666 * Device probe functions.
667 */ 667 */
668static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
669{
670 u16 word;
671 u8 *mac;
672 u8 default_lna_gain;
673
674 /*
675 * Start validation of the data that has been read.
676 */
677 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
678 if (!is_valid_ether_addr(mac)) {
679 random_ether_addr(mac);
680 EEPROM(rt2x00dev, "MAC: %pM\n", mac);
681 }
682
683 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
684 if (word == 0xffff) {
685 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
686 rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
687 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
688 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
689 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
690 } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
691 /*
692 * There is a max of 2 RX streams for RT28x0 series
693 */
694 if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
695 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
696 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
697 }
698
699 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
700 if (word == 0xffff) {
701 rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
702 rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
703 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
704 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
705 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
706 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
707 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
708 rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
709 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
710 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
711 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
712 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
713 }
714
715 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
716 if ((word & 0x00ff) == 0x00ff) {
717 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
718 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
719 LED_MODE_TXRX_ACTIVITY);
720 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
721 rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
722 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
723 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
724 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
725 EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
726 }
727
728 /*
729 * During the LNA validation we are going to use
730 * lna0 as correct value. Note that EEPROM_LNA
731 * is never validated.
732 */
733 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
734 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
735
736 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
737 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
738 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
739 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
740 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
741 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
742
743 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
744 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
745 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
746 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
747 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
748 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
749 default_lna_gain);
750 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
751
752 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
753 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
754 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
755 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
756 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
757 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
758
759 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
760 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
761 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
762 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
763 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
764 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
765 default_lna_gain);
766 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
767
768 return 0;
769}
770
771static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev) 668static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
772{ 669{
773 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE); 670 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
@@ -775,96 +672,6 @@ static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
775 return rt2800_validate_eeprom(rt2x00dev); 672 return rt2800_validate_eeprom(rt2x00dev);
776} 673}
777 674
778static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
779{
780 u32 reg;
781 u16 value;
782 u16 eeprom;
783
784 /*
785 * Read EEPROM word for configuration.
786 */
787 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
788
789 /*
790 * Identify RF chipset.
791 */
792 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
793 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
794
795 if (rt2x00_intf_is_usb(rt2x00dev)) {
796 struct rt2x00_chip *chip = &rt2x00dev->chip;
797
798 rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
799
800 /*
801 * The check for rt2860 is not a typo, some rt2870 hardware
802 * identifies itself as rt2860 in the CSR register.
803 */
804 if (!rt2x00_check_rev(chip, 0xfff00000, 0x28600000) &&
805 !rt2x00_check_rev(chip, 0xfff00000, 0x28700000) &&
806 !rt2x00_check_rev(chip, 0xfff00000, 0x28800000) &&
807 !rt2x00_check_rev(chip, 0xffff0000, 0x30700000)) {
808 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
809 return -ENODEV;
810 }
811 }
812
813 if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
814 !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
815 !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
816 !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
817 !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
818 !rt2x00_rf(&rt2x00dev->chip, RF2020)) {
819 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
820 return -ENODEV;
821 }
822
823 /*
824 * Identify default antenna configuration.
825 */
826 rt2x00dev->default_ant.tx =
827 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
828 rt2x00dev->default_ant.rx =
829 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
830
831 /*
832 * Read frequency offset and RF programming sequence.
833 */
834 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
835 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
836
837 /*
838 * Read external LNA informations.
839 */
840 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
841
842 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
843 __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
844 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
845 __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
846
847 /*
848 * Detect if this device has an hardware controlled radio.
849 */
850 if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
851 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
852
853 /*
854 * Store led settings, for correct led behaviour.
855 */
856#ifdef CONFIG_RT2X00_LIB_LEDS
857 rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
858 rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
859 rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
860
861 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ,
862 &rt2x00dev->led_mcu_reg);
863#endif /* CONFIG_RT2X00_LIB_LEDS */
864
865 return 0;
866}
867
868/* 675/*
869 * RF value list for rt2870 676 * RF value list for rt2870
870 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750) 677 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
@@ -1093,7 +900,7 @@ static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1093 if (retval) 900 if (retval)
1094 return retval; 901 return retval;
1095 902
1096 retval = rt2800usb_init_eeprom(rt2x00dev); 903 retval = rt2800_init_eeprom(rt2x00dev);
1097 if (retval) 904 if (retval)
1098 return retval; 905 return retval;
1099 906