26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/slab.h>
39 memset(chip, 0,
sizeof(*chip));
56 u8 *
addr = zd_mac_get_perm_addr(zd_chip_to_mac(chip));
57 return scnprintf(buffer, size,
"%02x-%02x-%02x",
58 addr[0], addr[1], addr[2]);
62 static int scnprint_id(
struct zd_chip *chip,
char *buffer,
size_t size)
66 i =
scnprintf(buffer, size,
"zd1211%s chip ",
67 zd_chip_is_zd1211b(chip) ?
"b" :
"");
70 i += scnprint_mac_oui(chip, buffer+i, size-i);
86 scnprint_id(chip, buffer,
sizeof(buffer));
87 buffer[
sizeof(
buffer)-1] = 0;
113 unsigned int count16;
121 BUG_ON(count16 *
sizeof(
u16) >
sizeof(v16));
123 for (i = 0; i <
count; i++) {
126 a16[
j] = inc_addr(addr[i]);
130 r = zd_ioread16v_locked(chip, v16, a16, count16);
133 "error: zd_ioread16v_locked. Error number %d\n", r);
137 for (i = 0; i <
count; i++) {
139 values[
i] = (v16[
j] << 16) | v16[j+1];
145 static int _zd_iowrite32v_async_locked(
struct zd_chip *chip,
151 unsigned int count16;
165 for (i = 0; i <
count; i++) {
168 ioreqs16[
j].value = ioreqs[
i].
value >> 16;
169 ioreqs16[
j].addr = inc_addr(ioreqs[i].addr);
170 ioreqs16[j+1].value = ioreqs[
i].
value;
171 ioreqs16[j+1].addr = ioreqs[
i].
addr;
178 "error %d in zd_usb_write16v\n", r);
190 r = _zd_iowrite32v_async_locked(chip, ioreqs, count);
199 const struct zd_ioreq16 *ioreqs,
unsigned int count)
202 unsigned int i,
j,
t,
max;
207 for (i = 0; i <
count; i += j +
t) {
212 for (j = 0; j <
max; j++) {
213 if (!ioreqs[i+j].addr) {
223 "error zd_usb_iowrite16v. Error number %d\n",
237 const struct zd_ioreq32 *ioreqs,
unsigned int count)
240 unsigned int i,
j,
t,
max;
244 for (i = 0; i <
count; i += j +
t) {
249 for (j = 0; j <
max; j++) {
250 if (!ioreqs[i+j].addr) {
256 r = _zd_iowrite32v_async_locked(chip, &ioreqs[i], j);
260 "error _zd_iowrite32v_locked."
261 " Error number %d\n", r);
274 r = zd_ioread16_locked(chip, value, addr);
284 r = zd_ioread32_locked(chip, value, addr);
294 r = zd_iowrite16_locked(chip, value, addr);
304 r = zd_iowrite32_locked(chip, value, addr);
337 r = zd_ioread32_locked(chip, &value,
E2P_POD);
343 *rf_type = value & 0x0f;
344 chip->
pa_type = (value >> 16) & 0x0f;
352 if (value & (1 << 24)) {
353 if (value & (1 << 29))
358 "RF %s %#01x PA type %#01x patch CCK %d patch CR157 %d "
359 "patch 6M %d new PHY %d link LED%d tx led %d\n",
382 struct zd_ioreq32 reqs[2] = {in_reqs[0], in_reqs[1]};
385 reqs[0].
value = (mac_addr[3] << 24)
386 | (mac_addr[2] << 16)
389 reqs[1].
value = (mac_addr[5] << 8)
412 return zd_write_mac_addr_common(chip, mac_addr, reqs,
"mac");
422 return zd_write_mac_addr_common(chip, bssid, reqs,
"bssid");
431 r = zd_ioread32_locked(chip, &value,
E2P_SUBID);
436 *regdomain = value >> 16;
451 r = zd_ioread32_locked(chip, &v,
458 values[i++] = v >> 8;
459 values[i++] = v >> 16;
460 values[i++] = v >> 24;
463 for (;i <
count; i++)
464 values[i] = v >> (8*(i%3));
469 static int read_pwr_cal_values(
struct zd_chip *chip)
476 static int read_pwr_int_values(
struct zd_chip *chip)
483 static int read_ofdm_cal_values(
struct zd_chip *chip)
493 for (i = 0; i < 3; i++) {
502 static int read_cal_int_tables(
struct zd_chip *chip)
506 r = read_pwr_cal_values(chip);
509 r = read_pwr_int_values(chip);
512 r = read_ofdm_cal_values(chip);
525 r = zd_ioread32_locked(chip, &tmp,
CR_REG1);
533 r = zd_iowrite32_locked(chip, tmp,
CR_REG1);
545 r = zd_ioread32_locked(chip, &tmp,
CR_REG1);
548 "error ioread32(CR_REG1): %d\n", r);
554 r = zd_iowrite32_locked(chip, tmp,
CR_REG1);
561 static int patch_cr157(
struct zd_chip *chip)
574 return zd_iowrite32_locked(chip, value >> 8,
ZD_CR157);
601 if (channel == 1 || channel == 11)
602 ioreqs[0].
value = 0x12;
608 static int zd1211_hw_reset_phy(
struct zd_chip *chip)
688 r = patch_cr157(chip);
697 static int zd1211b_hw_reset_phy(
struct zd_chip *chip)
774 static int hw_reset_phy(
struct zd_chip *chip)
776 return zd_chip_is_zd1211b(chip) ? zd1211b_hw_reset_phy(chip) :
777 zd1211_hw_reset_phy(chip);
780 static int zd1211_hw_init_hmac(
struct zd_chip *chip)
792 static int zd1211b_hw_init_hmac(
struct zd_chip *chip)
811 static int hw_init_hmac(
struct zd_chip *chip)
842 return zd_chip_is_zd1211b(chip) ?
843 zd1211b_hw_init_hmac(chip) : zd1211_hw_init_hmac(chip);
900 u32 b_interval, mode_flag;
922 b_interval = mode_flag | (dtim_period << 16) | interval;
927 r = get_aw_pt_bi(chip, &s);
930 return set_aw_pt_bi(chip, &s);
939 r = set_beacon_interval(chip, interval, dtim_period, type);
944 static int hw_init(
struct zd_chip *chip)
950 r = hw_reset_phy(chip);
954 r = hw_init_hmac(chip);
968 const char *addr_string)
973 r = zd_ioread32_locked(chip, &value, addr);
976 "error reading %s. Error number %d\n", addr_string, r);
981 addr_string, (
unsigned int)value);
985 static int test_init(
struct zd_chip *chip)
992 r = dump_cr(chip,
CR_GPI_EN,
"CR_GPI_EN");
998 static void dump_fw_registers(
struct zd_chip *chip)
1010 r = zd_ioread16v_locked(chip, values, (
const zd_addr_t*)addr,
1025 static int print_fw_version(
struct zd_chip *chip)
1027 struct wiphy *
wiphy = zd_chip_to_mac(chip)->hw->wiphy;
1031 r = zd_ioread16_locked(chip, &version,
1044 static int set_mandatory_rates(
struct zd_chip *chip,
int gmode)
1089 static int disable_hwint(
struct zd_chip *chip)
1099 r = disable_hwint(chip);
1104 static int read_fw_regs_offset(
struct zd_chip *chip)
1137 r = test_init(chip);
1145 r = read_fw_regs_offset(chip);
1151 r = zd_iowrite32_locked(chip, 0,
CR_GPI_EN);
1161 r = set_mandatory_rates(chip, 1);
1166 r = disable_hwint(chip);
1169 r = read_pod(chip, &rf_type);
1179 r = print_fw_version(chip);
1184 dump_fw_registers(chip);
1185 r = test_init(chip);
1190 r = read_cal_int_tables(chip);
1200 static int update_pwr_int(
struct zd_chip *chip,
u8 channel)
1203 return zd_iowrite16_locked(chip, value,
ZD_CR31);
1206 static int update_pwr_cal(
struct zd_chip *chip,
u8 channel)
1209 return zd_iowrite16_locked(chip, value,
ZD_CR68);
1212 static int update_ofdm_cal(
struct zd_chip *chip,
u8 channel)
1226 static int update_channel_integration_and_calibration(
struct zd_chip *chip,
1231 if (!zd_rf_should_update_pwr_int(&chip->
rf))
1234 r = update_pwr_int(chip, channel);
1237 if (zd_chip_is_zd1211b(chip)) {
1244 r = update_ofdm_cal(chip, channel);
1247 r = update_pwr_cal(chip, channel);
1259 static int patch_cck_gain(
struct zd_chip *chip)
1268 r = zd_ioread32_locked(chip, &value,
E2P_PHY_REG);
1272 return zd_iowrite16_locked(chip, value & 0xff,
ZD_CR47);
1286 r = update_channel_integration_and_calibration(chip, channel);
1289 r = patch_cck_gain(chip);
1292 r = patch_6m_band_edge(chip, channel);
1310 channel = chip->
rf.channel;
1344 ioreqs[1].
value = v[1] & ~other_led;
1353 ioreqs[1].
value = v[1] & ~other_led;
1361 if (v[0] != ioreqs[0].value || v[1] != ioreqs[1].value) {
1385 static inline u8 zd_rate_from_ofdm_plcp_header(
const void *rx_frame)
1387 return ZD_OFDM | zd_ofdm_plcp_header_rate(rx_frame);
1402 zd_rate = zd_rate_from_ofdm_plcp_header(rx_frame);
1404 switch (zd_cck_plcp_header_signal(rx_frame)) {
1487 const u32* values,
unsigned int count,
u8 bits)
1492 for (i = 0; i <
count; i++) {
1493 r = zd_rfwrite_locked(chip, values[i], bits);
1508 {
ZD_CR244, (value >> 16) & 0xff },
1517 const u32 *values,
unsigned int count)
1522 for (i = 0; i <
count; i++) {
1545 static const zd_addr_t aw_pt_bi_addr[] =
1558 tsf = (tsf << 32) | values[0];