diff options
Diffstat (limited to 'drivers/net/wireless/zd1211rw/zd_chip.c')
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_chip.c | 137 |
1 files changed, 55 insertions, 82 deletions
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c index 7c4e32cf0d47..aa661b2b76c7 100644 --- a/drivers/net/wireless/zd1211rw/zd_chip.c +++ b/drivers/net/wireless/zd1211rw/zd_chip.c | |||
@@ -249,7 +249,6 @@ int zd_ioread16(struct zd_chip *chip, zd_addr_t addr, u16 *value) | |||
249 | { | 249 | { |
250 | int r; | 250 | int r; |
251 | 251 | ||
252 | ZD_ASSERT(!mutex_is_locked(&chip->mutex)); | ||
253 | mutex_lock(&chip->mutex); | 252 | mutex_lock(&chip->mutex); |
254 | r = zd_ioread16_locked(chip, value, addr); | 253 | r = zd_ioread16_locked(chip, value, addr); |
255 | mutex_unlock(&chip->mutex); | 254 | mutex_unlock(&chip->mutex); |
@@ -260,7 +259,6 @@ int zd_ioread32(struct zd_chip *chip, zd_addr_t addr, u32 *value) | |||
260 | { | 259 | { |
261 | int r; | 260 | int r; |
262 | 261 | ||
263 | ZD_ASSERT(!mutex_is_locked(&chip->mutex)); | ||
264 | mutex_lock(&chip->mutex); | 262 | mutex_lock(&chip->mutex); |
265 | r = zd_ioread32_locked(chip, value, addr); | 263 | r = zd_ioread32_locked(chip, value, addr); |
266 | mutex_unlock(&chip->mutex); | 264 | mutex_unlock(&chip->mutex); |
@@ -271,7 +269,6 @@ int zd_iowrite16(struct zd_chip *chip, zd_addr_t addr, u16 value) | |||
271 | { | 269 | { |
272 | int r; | 270 | int r; |
273 | 271 | ||
274 | ZD_ASSERT(!mutex_is_locked(&chip->mutex)); | ||
275 | mutex_lock(&chip->mutex); | 272 | mutex_lock(&chip->mutex); |
276 | r = zd_iowrite16_locked(chip, value, addr); | 273 | r = zd_iowrite16_locked(chip, value, addr); |
277 | mutex_unlock(&chip->mutex); | 274 | mutex_unlock(&chip->mutex); |
@@ -282,7 +279,6 @@ int zd_iowrite32(struct zd_chip *chip, zd_addr_t addr, u32 value) | |||
282 | { | 279 | { |
283 | int r; | 280 | int r; |
284 | 281 | ||
285 | ZD_ASSERT(!mutex_is_locked(&chip->mutex)); | ||
286 | mutex_lock(&chip->mutex); | 282 | mutex_lock(&chip->mutex); |
287 | r = zd_iowrite32_locked(chip, value, addr); | 283 | r = zd_iowrite32_locked(chip, value, addr); |
288 | mutex_unlock(&chip->mutex); | 284 | mutex_unlock(&chip->mutex); |
@@ -294,7 +290,6 @@ int zd_ioread32v(struct zd_chip *chip, const zd_addr_t *addresses, | |||
294 | { | 290 | { |
295 | int r; | 291 | int r; |
296 | 292 | ||
297 | ZD_ASSERT(!mutex_is_locked(&chip->mutex)); | ||
298 | mutex_lock(&chip->mutex); | 293 | mutex_lock(&chip->mutex); |
299 | r = zd_ioread32v_locked(chip, values, addresses, count); | 294 | r = zd_ioread32v_locked(chip, values, addresses, count); |
300 | mutex_unlock(&chip->mutex); | 295 | mutex_unlock(&chip->mutex); |
@@ -306,7 +301,6 @@ int zd_iowrite32a(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs, | |||
306 | { | 301 | { |
307 | int r; | 302 | int r; |
308 | 303 | ||
309 | ZD_ASSERT(!mutex_is_locked(&chip->mutex)); | ||
310 | mutex_lock(&chip->mutex); | 304 | mutex_lock(&chip->mutex); |
311 | r = zd_iowrite32a_locked(chip, ioreqs, count); | 305 | r = zd_iowrite32a_locked(chip, ioreqs, count); |
312 | mutex_unlock(&chip->mutex); | 306 | mutex_unlock(&chip->mutex); |
@@ -331,13 +325,22 @@ static int read_pod(struct zd_chip *chip, u8 *rf_type) | |||
331 | chip->patch_cr157 = (value >> 13) & 0x1; | 325 | chip->patch_cr157 = (value >> 13) & 0x1; |
332 | chip->patch_6m_band_edge = (value >> 21) & 0x1; | 326 | chip->patch_6m_band_edge = (value >> 21) & 0x1; |
333 | chip->new_phy_layout = (value >> 31) & 0x1; | 327 | chip->new_phy_layout = (value >> 31) & 0x1; |
328 | chip->link_led = ((value >> 4) & 1) ? LED1 : LED2; | ||
329 | chip->supports_tx_led = 1; | ||
330 | if (value & (1 << 24)) { /* LED scenario */ | ||
331 | if (value & (1 << 29)) | ||
332 | chip->supports_tx_led = 0; | ||
333 | } | ||
334 | 334 | ||
335 | dev_dbg_f(zd_chip_dev(chip), | 335 | dev_dbg_f(zd_chip_dev(chip), |
336 | "RF %s %#01x PA type %#01x patch CCK %d patch CR157 %d " | 336 | "RF %s %#01x PA type %#01x patch CCK %d patch CR157 %d " |
337 | "patch 6M %d new PHY %d\n", | 337 | "patch 6M %d new PHY %d link LED%d tx led %d\n", |
338 | zd_rf_name(*rf_type), *rf_type, | 338 | zd_rf_name(*rf_type), *rf_type, |
339 | chip->pa_type, chip->patch_cck_gain, | 339 | chip->pa_type, chip->patch_cck_gain, |
340 | chip->patch_cr157, chip->patch_6m_band_edge, chip->new_phy_layout); | 340 | chip->patch_cr157, chip->patch_6m_band_edge, |
341 | chip->new_phy_layout, | ||
342 | chip->link_led == LED1 ? 1 : 2, | ||
343 | chip->supports_tx_led); | ||
341 | return 0; | 344 | return 0; |
342 | error: | 345 | error: |
343 | *rf_type = 0; | 346 | *rf_type = 0; |
@@ -1181,7 +1184,7 @@ static int update_pwr_int(struct zd_chip *chip, u8 channel) | |||
1181 | u8 value = chip->pwr_int_values[channel - 1]; | 1184 | u8 value = chip->pwr_int_values[channel - 1]; |
1182 | dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_int %#04x\n", | 1185 | dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_int %#04x\n", |
1183 | channel, value); | 1186 | channel, value); |
1184 | return zd_iowrite32_locked(chip, value, CR31); | 1187 | return zd_iowrite16_locked(chip, value, CR31); |
1185 | } | 1188 | } |
1186 | 1189 | ||
1187 | static int update_pwr_cal(struct zd_chip *chip, u8 channel) | 1190 | static int update_pwr_cal(struct zd_chip *chip, u8 channel) |
@@ -1189,12 +1192,12 @@ static int update_pwr_cal(struct zd_chip *chip, u8 channel) | |||
1189 | u8 value = chip->pwr_cal_values[channel-1]; | 1192 | u8 value = chip->pwr_cal_values[channel-1]; |
1190 | dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_cal %#04x\n", | 1193 | dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_cal %#04x\n", |
1191 | channel, value); | 1194 | channel, value); |
1192 | return zd_iowrite32_locked(chip, value, CR68); | 1195 | return zd_iowrite16_locked(chip, value, CR68); |
1193 | } | 1196 | } |
1194 | 1197 | ||
1195 | static int update_ofdm_cal(struct zd_chip *chip, u8 channel) | 1198 | static int update_ofdm_cal(struct zd_chip *chip, u8 channel) |
1196 | { | 1199 | { |
1197 | struct zd_ioreq32 ioreqs[3]; | 1200 | struct zd_ioreq16 ioreqs[3]; |
1198 | 1201 | ||
1199 | ioreqs[0].addr = CR67; | 1202 | ioreqs[0].addr = CR67; |
1200 | ioreqs[0].value = chip->ofdm_cal_values[OFDM_36M_INDEX][channel-1]; | 1203 | ioreqs[0].value = chip->ofdm_cal_values[OFDM_36M_INDEX][channel-1]; |
@@ -1206,7 +1209,7 @@ static int update_ofdm_cal(struct zd_chip *chip, u8 channel) | |||
1206 | dev_dbg_f(zd_chip_dev(chip), | 1209 | dev_dbg_f(zd_chip_dev(chip), |
1207 | "channel %d ofdm_cal 36M %#04x 48M %#04x 54M %#04x\n", | 1210 | "channel %d ofdm_cal 36M %#04x 48M %#04x 54M %#04x\n", |
1208 | channel, ioreqs[0].value, ioreqs[1].value, ioreqs[2].value); | 1211 | channel, ioreqs[0].value, ioreqs[1].value, ioreqs[2].value); |
1209 | return zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); | 1212 | return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); |
1210 | } | 1213 | } |
1211 | 1214 | ||
1212 | static int update_channel_integration_and_calibration(struct zd_chip *chip, | 1215 | static int update_channel_integration_and_calibration(struct zd_chip *chip, |
@@ -1218,7 +1221,7 @@ static int update_channel_integration_and_calibration(struct zd_chip *chip, | |||
1218 | if (r) | 1221 | if (r) |
1219 | return r; | 1222 | return r; |
1220 | if (chip->is_zd1211b) { | 1223 | if (chip->is_zd1211b) { |
1221 | static const struct zd_ioreq32 ioreqs[] = { | 1224 | static const struct zd_ioreq16 ioreqs[] = { |
1222 | { CR69, 0x28 }, | 1225 | { CR69, 0x28 }, |
1223 | {}, | 1226 | {}, |
1224 | { CR69, 0x2a }, | 1227 | { CR69, 0x2a }, |
@@ -1230,7 +1233,7 @@ static int update_channel_integration_and_calibration(struct zd_chip *chip, | |||
1230 | r = update_pwr_cal(chip, channel); | 1233 | r = update_pwr_cal(chip, channel); |
1231 | if (r) | 1234 | if (r) |
1232 | return r; | 1235 | return r; |
1233 | r = zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); | 1236 | r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); |
1234 | if (r) | 1237 | if (r) |
1235 | return r; | 1238 | return r; |
1236 | } | 1239 | } |
@@ -1252,7 +1255,7 @@ static int patch_cck_gain(struct zd_chip *chip) | |||
1252 | if (r) | 1255 | if (r) |
1253 | return r; | 1256 | return r; |
1254 | dev_dbg_f(zd_chip_dev(chip), "patching value %x\n", value & 0xff); | 1257 | dev_dbg_f(zd_chip_dev(chip), "patching value %x\n", value & 0xff); |
1255 | return zd_iowrite32_locked(chip, value & 0xff, CR47); | 1258 | return zd_iowrite16_locked(chip, value & 0xff, CR47); |
1256 | } | 1259 | } |
1257 | 1260 | ||
1258 | int zd_chip_set_channel(struct zd_chip *chip, u8 channel) | 1261 | int zd_chip_set_channel(struct zd_chip *chip, u8 channel) |
@@ -1295,89 +1298,60 @@ u8 zd_chip_get_channel(struct zd_chip *chip) | |||
1295 | return channel; | 1298 | return channel; |
1296 | } | 1299 | } |
1297 | 1300 | ||
1298 | static u16 led_mask(int led) | 1301 | int zd_chip_control_leds(struct zd_chip *chip, enum led_status status) |
1299 | { | 1302 | { |
1300 | switch (led) { | 1303 | static const zd_addr_t a[] = { |
1301 | case 1: | 1304 | FW_LINK_STATUS, |
1302 | return LED1; | 1305 | CR_LED, |
1303 | case 2: | 1306 | }; |
1304 | return LED2; | ||
1305 | default: | ||
1306 | return 0; | ||
1307 | } | ||
1308 | } | ||
1309 | |||
1310 | static int read_led_reg(struct zd_chip *chip, u16 *status) | ||
1311 | { | ||
1312 | ZD_ASSERT(mutex_is_locked(&chip->mutex)); | ||
1313 | return zd_ioread16_locked(chip, status, CR_LED); | ||
1314 | } | ||
1315 | |||
1316 | static int write_led_reg(struct zd_chip *chip, u16 status) | ||
1317 | { | ||
1318 | ZD_ASSERT(mutex_is_locked(&chip->mutex)); | ||
1319 | return zd_iowrite16_locked(chip, status, CR_LED); | ||
1320 | } | ||
1321 | 1307 | ||
1322 | int zd_chip_led_status(struct zd_chip *chip, int led, enum led_status status) | 1308 | int r; |
1323 | { | 1309 | u16 v[ARRAY_SIZE(a)]; |
1324 | int r, ret; | 1310 | struct zd_ioreq16 ioreqs[ARRAY_SIZE(a)] = { |
1325 | u16 mask = led_mask(led); | 1311 | [0] = { FW_LINK_STATUS }, |
1326 | u16 reg; | 1312 | [1] = { CR_LED }, |
1313 | }; | ||
1314 | u16 other_led; | ||
1327 | 1315 | ||
1328 | if (!mask) | ||
1329 | return -EINVAL; | ||
1330 | mutex_lock(&chip->mutex); | 1316 | mutex_lock(&chip->mutex); |
1331 | r = read_led_reg(chip, ®); | 1317 | r = zd_ioread16v_locked(chip, v, (const zd_addr_t *)a, ARRAY_SIZE(a)); |
1332 | if (r) | 1318 | if (r) |
1333 | return r; | 1319 | goto out; |
1320 | |||
1321 | other_led = chip->link_led == LED1 ? LED2 : LED1; | ||
1322 | |||
1334 | switch (status) { | 1323 | switch (status) { |
1335 | case LED_STATUS: | ||
1336 | return (reg & mask) ? LED_ON : LED_OFF; | ||
1337 | case LED_OFF: | 1324 | case LED_OFF: |
1338 | reg &= ~mask; | 1325 | ioreqs[0].value = FW_LINK_OFF; |
1339 | ret = LED_OFF; | 1326 | ioreqs[1].value = v[1] & ~(LED1|LED2); |
1340 | break; | 1327 | break; |
1341 | case LED_FLIP: | 1328 | case LED_SCANNING: |
1342 | reg ^= mask; | 1329 | ioreqs[0].value = FW_LINK_OFF; |
1343 | ret = (reg&mask) ? LED_ON : LED_OFF; | 1330 | ioreqs[1].value = v[1] & ~other_led; |
1331 | if (get_seconds() % 3 == 0) { | ||
1332 | ioreqs[1].value &= ~chip->link_led; | ||
1333 | } else { | ||
1334 | ioreqs[1].value |= chip->link_led; | ||
1335 | } | ||
1344 | break; | 1336 | break; |
1345 | case LED_ON: | 1337 | case LED_ASSOCIATED: |
1346 | reg |= mask; | 1338 | ioreqs[0].value = FW_LINK_TX; |
1347 | ret = LED_ON; | 1339 | ioreqs[1].value = v[1] & ~other_led; |
1340 | ioreqs[1].value |= chip->link_led; | ||
1348 | break; | 1341 | break; |
1349 | default: | 1342 | default: |
1350 | return -EINVAL; | 1343 | r = -EINVAL; |
1351 | } | ||
1352 | r = write_led_reg(chip, reg); | ||
1353 | if (r) { | ||
1354 | ret = r; | ||
1355 | goto out; | 1344 | goto out; |
1356 | } | 1345 | } |
1357 | out: | ||
1358 | mutex_unlock(&chip->mutex); | ||
1359 | return r; | ||
1360 | } | ||
1361 | |||
1362 | int zd_chip_led_flip(struct zd_chip *chip, int led, | ||
1363 | const unsigned int *phases_msecs, unsigned int count) | ||
1364 | { | ||
1365 | int i, r; | ||
1366 | enum led_status status; | ||
1367 | 1346 | ||
1368 | r = zd_chip_led_status(chip, led, LED_STATUS); | 1347 | if (v[0] != ioreqs[0].value || v[1] != ioreqs[1].value) { |
1369 | if (r) | 1348 | r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); |
1370 | return r; | 1349 | if (r) |
1371 | status = r; | ||
1372 | for (i = 0; i < count; i++) { | ||
1373 | r = zd_chip_led_status(chip, led, LED_FLIP); | ||
1374 | if (r < 0) | ||
1375 | goto out; | 1350 | goto out; |
1376 | msleep(phases_msecs[i]); | ||
1377 | } | 1351 | } |
1378 | 1352 | r = 0; | |
1379 | out: | 1353 | out: |
1380 | zd_chip_led_status(chip, led, status); | 1354 | mutex_unlock(&chip->mutex); |
1381 | return r; | 1355 | return r; |
1382 | } | 1356 | } |
1383 | 1357 | ||
@@ -1679,4 +1653,3 @@ int zd_rfwritev_cr_locked(struct zd_chip *chip, | |||
1679 | 1653 | ||
1680 | return 0; | 1654 | return 0; |
1681 | } | 1655 | } |
1682 | |||