diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2009-11-08 08:39:01 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-11-11 17:09:14 -0500 |
commit | 38bd7b8a0f485ba5ad514fcd621a1842ebadf9e6 (patch) | |
tree | 115e9fd1f31efbf826531b2ff88c7addd442984c /drivers/net/wireless/rt2x00/rt2800pci.c | |
parent | 7ab71325cf0940099c376799aca6de7bc86ad2d0 (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/net/wireless/rt2x00/rt2800pci.c')
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2800pci.c | 183 |
1 files changed, 1 insertions, 182 deletions
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 | */ |
1094 | static 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 | |||
1197 | static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev) | 1094 | static 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 | ||
1218 | static 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, ®); | ||
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 | ||