diff options
author | Daniel Drake <dsd@gentoo.org> | 2006-12-11 20:26:11 -0500 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-02-05 16:58:42 -0500 |
commit | 0ce34bc8f7d906d66ce6803f63399ef9bbe54012 (patch) | |
tree | 1326f9105842fc81f89bf8ab1a435ab13a4d72d5 | |
parent | ee30276774451d657407855d95d9393ee8bc0bac (diff) |
[PATCH] zd1211rw: Remove addressing abstraction
Instead of passing our own custom 32-bit addresses around and
translating them, this patch makes all our register address constants
absolute and removes the translation.
There are two ugly parts:
- fw_reg_addr() is needed to compute addresses of firmware registers, as this
is dynamic based upon firmware
- inc_addr() needs a small hack to handle byte vs word addressing
However, both of those are only small, and we don't use fw_regs a whole
lot anyway.
The bonuses here include simplicity and improved driver readability. Also, the
fact that registers are now referenced by 16-bit absolute addresses (as
opposed to 32-bit pseudo addresses) means that over 2kb compiled code size has
been shaved off.
Includes some touchups and sparse fixes from Ulrich Kunitz.
Signed-off-by: Daniel Drake <dsd@gentoo.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_chip.c | 59 | ||||
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_chip.h | 89 | ||||
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_def.h | 2 | ||||
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_ieee80211.h | 1 | ||||
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_rf.h | 2 | ||||
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_types.h | 71 | ||||
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_usb.c | 112 | ||||
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_usb.h | 6 |
8 files changed, 104 insertions, 238 deletions
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c index cc5151683fa1..12dfc0b6efe6 100644 --- a/drivers/net/wireless/zd1211rw/zd_chip.c +++ b/drivers/net/wireless/zd1211rw/zd_chip.c | |||
@@ -84,6 +84,18 @@ static void print_id(struct zd_chip *chip) | |||
84 | dev_info(zd_chip_dev(chip), "%s\n", buffer); | 84 | dev_info(zd_chip_dev(chip), "%s\n", buffer); |
85 | } | 85 | } |
86 | 86 | ||
87 | static zd_addr_t inc_addr(zd_addr_t addr) | ||
88 | { | ||
89 | u16 a = (u16)addr; | ||
90 | /* Control registers use byte addressing, but everything else uses word | ||
91 | * addressing. */ | ||
92 | if ((a & 0xf000) == CR_START) | ||
93 | a += 2; | ||
94 | else | ||
95 | a += 1; | ||
96 | return (zd_addr_t)a; | ||
97 | } | ||
98 | |||
87 | /* Read a variable number of 32-bit values. Parameter count is not allowed to | 99 | /* Read a variable number of 32-bit values. Parameter count is not allowed to |
88 | * exceed USB_MAX_IOREAD32_COUNT. | 100 | * exceed USB_MAX_IOREAD32_COUNT. |
89 | */ | 101 | */ |
@@ -114,7 +126,7 @@ int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr | |||
114 | for (i = 0; i < count; i++) { | 126 | for (i = 0; i < count; i++) { |
115 | int j = 2*i; | 127 | int j = 2*i; |
116 | /* We read the high word always first. */ | 128 | /* We read the high word always first. */ |
117 | a16[j] = zd_inc_word(addr[i]); | 129 | a16[j] = inc_addr(addr[i]); |
118 | a16[j+1] = addr[i]; | 130 | a16[j+1] = addr[i]; |
119 | } | 131 | } |
120 | 132 | ||
@@ -163,7 +175,7 @@ int _zd_iowrite32v_locked(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs, | |||
163 | j = 2*i; | 175 | j = 2*i; |
164 | /* We write the high word always first. */ | 176 | /* We write the high word always first. */ |
165 | ioreqs16[j].value = ioreqs[i].value >> 16; | 177 | ioreqs16[j].value = ioreqs[i].value >> 16; |
166 | ioreqs16[j].addr = zd_inc_word(ioreqs[i].addr); | 178 | ioreqs16[j].addr = inc_addr(ioreqs[i].addr); |
167 | ioreqs16[j+1].value = ioreqs[i].value; | 179 | ioreqs16[j+1].value = ioreqs[i].value; |
168 | ioreqs16[j+1].addr = ioreqs[i].addr; | 180 | ioreqs16[j+1].addr = ioreqs[i].addr; |
169 | } | 181 | } |
@@ -466,7 +478,8 @@ static int read_values(struct zd_chip *chip, u8 *values, size_t count, | |||
466 | 478 | ||
467 | ZD_ASSERT(mutex_is_locked(&chip->mutex)); | 479 | ZD_ASSERT(mutex_is_locked(&chip->mutex)); |
468 | for (i = 0;;) { | 480 | for (i = 0;;) { |
469 | r = zd_ioread32_locked(chip, &v, e2p_addr+i/2); | 481 | r = zd_ioread32_locked(chip, &v, |
482 | (zd_addr_t)((u16)e2p_addr+i/2)); | ||
470 | if (r) | 483 | if (r) |
471 | return r; | 484 | return r; |
472 | v -= guard; | 485 | v -= guard; |
@@ -953,6 +966,11 @@ static int hw_init(struct zd_chip *chip) | |||
953 | return set_beacon_interval(chip, 100); | 966 | return set_beacon_interval(chip, 100); |
954 | } | 967 | } |
955 | 968 | ||
969 | static zd_addr_t fw_reg_addr(struct zd_chip *chip, u16 offset) | ||
970 | { | ||
971 | return (zd_addr_t)((u16)chip->fw_regs_base + offset); | ||
972 | } | ||
973 | |||
956 | #ifdef DEBUG | 974 | #ifdef DEBUG |
957 | static int dump_cr(struct zd_chip *chip, const zd_addr_t addr, | 975 | static int dump_cr(struct zd_chip *chip, const zd_addr_t addr, |
958 | const char *addr_string) | 976 | const char *addr_string) |
@@ -987,9 +1005,11 @@ static int test_init(struct zd_chip *chip) | |||
987 | 1005 | ||
988 | static void dump_fw_registers(struct zd_chip *chip) | 1006 | static void dump_fw_registers(struct zd_chip *chip) |
989 | { | 1007 | { |
990 | static const zd_addr_t addr[4] = { | 1008 | const zd_addr_t addr[4] = { |
991 | FW_FIRMWARE_VER, FW_USB_SPEED, FW_FIX_TX_RATE, | 1009 | fw_reg_addr(chip, FW_REG_FIRMWARE_VER), |
992 | FW_LINK_STATUS | 1010 | fw_reg_addr(chip, FW_REG_USB_SPEED), |
1011 | fw_reg_addr(chip, FW_REG_FIX_TX_RATE), | ||
1012 | fw_reg_addr(chip, FW_REG_LED_LINK_STATUS), | ||
993 | }; | 1013 | }; |
994 | 1014 | ||
995 | int r; | 1015 | int r; |
@@ -1015,7 +1035,8 @@ static int print_fw_version(struct zd_chip *chip) | |||
1015 | int r; | 1035 | int r; |
1016 | u16 version; | 1036 | u16 version; |
1017 | 1037 | ||
1018 | r = zd_ioread16_locked(chip, &version, FW_FIRMWARE_VER); | 1038 | r = zd_ioread16_locked(chip, &version, |
1039 | fw_reg_addr(chip, FW_REG_FIRMWARE_VER)); | ||
1019 | if (r) | 1040 | if (r) |
1020 | return r; | 1041 | return r; |
1021 | 1042 | ||
@@ -1095,6 +1116,22 @@ int zd_chip_disable_hwint(struct zd_chip *chip) | |||
1095 | return r; | 1116 | return r; |
1096 | } | 1117 | } |
1097 | 1118 | ||
1119 | static int read_fw_regs_offset(struct zd_chip *chip) | ||
1120 | { | ||
1121 | int r; | ||
1122 | |||
1123 | ZD_ASSERT(mutex_is_locked(&chip->mutex)); | ||
1124 | r = zd_ioread16_locked(chip, (u16*)&chip->fw_regs_base, | ||
1125 | FWRAW_REGS_ADDR); | ||
1126 | if (r) | ||
1127 | return r; | ||
1128 | dev_dbg_f(zd_chip_dev(chip), "fw_regs_base: %#06hx\n", | ||
1129 | (u16)chip->fw_regs_base); | ||
1130 | |||
1131 | return 0; | ||
1132 | } | ||
1133 | |||
1134 | |||
1098 | int zd_chip_init_hw(struct zd_chip *chip, u8 device_type) | 1135 | int zd_chip_init_hw(struct zd_chip *chip, u8 device_type) |
1099 | { | 1136 | { |
1100 | int r; | 1137 | int r; |
@@ -1114,7 +1151,7 @@ int zd_chip_init_hw(struct zd_chip *chip, u8 device_type) | |||
1114 | if (r) | 1151 | if (r) |
1115 | goto out; | 1152 | goto out; |
1116 | 1153 | ||
1117 | r = zd_usb_init_hw(&chip->usb); | 1154 | r = read_fw_regs_offset(chip); |
1118 | if (r) | 1155 | if (r) |
1119 | goto out; | 1156 | goto out; |
1120 | 1157 | ||
@@ -1294,15 +1331,15 @@ u8 zd_chip_get_channel(struct zd_chip *chip) | |||
1294 | 1331 | ||
1295 | int zd_chip_control_leds(struct zd_chip *chip, enum led_status status) | 1332 | int zd_chip_control_leds(struct zd_chip *chip, enum led_status status) |
1296 | { | 1333 | { |
1297 | static const zd_addr_t a[] = { | 1334 | const zd_addr_t a[] = { |
1298 | FW_LINK_STATUS, | 1335 | fw_reg_addr(chip, FW_REG_LED_LINK_STATUS), |
1299 | CR_LED, | 1336 | CR_LED, |
1300 | }; | 1337 | }; |
1301 | 1338 | ||
1302 | int r; | 1339 | int r; |
1303 | u16 v[ARRAY_SIZE(a)]; | 1340 | u16 v[ARRAY_SIZE(a)]; |
1304 | struct zd_ioreq16 ioreqs[ARRAY_SIZE(a)] = { | 1341 | struct zd_ioreq16 ioreqs[ARRAY_SIZE(a)] = { |
1305 | [0] = { FW_LINK_STATUS }, | 1342 | [0] = { fw_reg_addr(chip, FW_REG_LED_LINK_STATUS) }, |
1306 | [1] = { CR_LED }, | 1343 | [1] = { CR_LED }, |
1307 | }; | 1344 | }; |
1308 | u16 other_led; | 1345 | u16 other_led; |
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.h b/drivers/net/wireless/zd1211rw/zd_chip.h index fa3437d6d742..b07569e391ee 100644 --- a/drivers/net/wireless/zd1211rw/zd_chip.h +++ b/drivers/net/wireless/zd1211rw/zd_chip.h | |||
@@ -18,7 +18,6 @@ | |||
18 | #ifndef _ZD_CHIP_H | 18 | #ifndef _ZD_CHIP_H |
19 | #define _ZD_CHIP_H | 19 | #define _ZD_CHIP_H |
20 | 20 | ||
21 | #include "zd_types.h" | ||
22 | #include "zd_rf.h" | 21 | #include "zd_rf.h" |
23 | #include "zd_usb.h" | 22 | #include "zd_usb.h" |
24 | 23 | ||
@@ -27,6 +26,37 @@ | |||
27 | * adds a processor for handling the USB protocol. | 26 | * adds a processor for handling the USB protocol. |
28 | */ | 27 | */ |
29 | 28 | ||
29 | /* Address space */ | ||
30 | enum { | ||
31 | /* CONTROL REGISTERS */ | ||
32 | CR_START = 0x9000, | ||
33 | |||
34 | |||
35 | /* FIRMWARE */ | ||
36 | FW_START = 0xee00, | ||
37 | |||
38 | |||
39 | /* EEPROM */ | ||
40 | E2P_START = 0xf800, | ||
41 | E2P_LEN = 0x800, | ||
42 | |||
43 | /* EEPROM layout */ | ||
44 | E2P_LOAD_CODE_LEN = 0xe, /* base 0xf800 */ | ||
45 | E2P_LOAD_VECT_LEN = 0x9, /* base 0xf80e */ | ||
46 | /* E2P_DATA indexes into this */ | ||
47 | E2P_DATA_LEN = 0x7e, /* base 0xf817 */ | ||
48 | E2P_BOOT_CODE_LEN = 0x760, /* base 0xf895 */ | ||
49 | E2P_INTR_VECT_LEN = 0xb, /* base 0xfff5 */ | ||
50 | |||
51 | /* Some precomputed offsets into the EEPROM */ | ||
52 | E2P_DATA_OFFSET = E2P_LOAD_CODE_LEN + E2P_LOAD_VECT_LEN, | ||
53 | E2P_BOOT_CODE_OFFSET = E2P_DATA_OFFSET + E2P_DATA_LEN, | ||
54 | }; | ||
55 | |||
56 | #define CTL_REG(offset) ((zd_addr_t)(CR_START + (offset))) | ||
57 | #define E2P_DATA(offset) ((zd_addr_t)(E2P_START + E2P_DATA_OFFSET + (offset))) | ||
58 | #define FWRAW_DATA(offset) ((zd_addr_t)(FW_START + (offset))) | ||
59 | |||
30 | /* 8-bit hardware registers */ | 60 | /* 8-bit hardware registers */ |
31 | #define CR0 CTL_REG(0x0000) | 61 | #define CR0 CTL_REG(0x0000) |
32 | #define CR1 CTL_REG(0x0004) | 62 | #define CR1 CTL_REG(0x0004) |
@@ -302,7 +332,7 @@ | |||
302 | 332 | ||
303 | #define CR_MAX_PHY_REG 255 | 333 | #define CR_MAX_PHY_REG 255 |
304 | 334 | ||
305 | /* Taken from the ZYDAS driver, not all of them are relevant for the ZSD1211 | 335 | /* Taken from the ZYDAS driver, not all of them are relevant for the ZD1211 |
306 | * driver. | 336 | * driver. |
307 | */ | 337 | */ |
308 | 338 | ||
@@ -638,50 +668,27 @@ | |||
638 | #define E2P_54M_INT_VALUE3 E2P_DATA(0x54) | 668 | #define E2P_54M_INT_VALUE3 E2P_DATA(0x54) |
639 | #define E2P_54M_INT_VALUE4 E2P_DATA(0x56) | 669 | #define E2P_54M_INT_VALUE4 E2P_DATA(0x56) |
640 | 670 | ||
641 | /* All 16 bit values */ | 671 | /* This word contains the base address of the FW_REG_ registers below */ |
642 | #define FW_FIRMWARE_VER FW_REG(0) | 672 | #define FWRAW_REGS_ADDR FWRAW_DATA(0x1d) |
643 | /* non-zero if USB high speed connection */ | 673 | |
644 | #define FW_USB_SPEED FW_REG(1) | 674 | /* All 16 bit values, offset from the address in FWRAW_REGS_ADDR */ |
645 | #define FW_FIX_TX_RATE FW_REG(2) | 675 | enum { |
646 | /* Seems to be able to control LEDs over the firmware */ | 676 | FW_REG_FIRMWARE_VER = 0, |
647 | #define FW_LINK_STATUS FW_REG(3) | 677 | /* non-zero if USB high speed connection */ |
648 | #define FW_SOFT_RESET FW_REG(4) | 678 | FW_REG_USB_SPEED = 1, |
649 | #define FW_FLASH_CHK FW_REG(5) | 679 | FW_REG_FIX_TX_RATE = 2, |
680 | /* Seems to be able to control LEDs over the firmware */ | ||
681 | FW_REG_LED_LINK_STATUS = 3, | ||
682 | FW_REG_SOFT_RESET = 4, | ||
683 | FW_REG_FLASH_CHK = 5, | ||
684 | }; | ||
650 | 685 | ||
686 | /* Values for FW_LINK_STATUS */ | ||
651 | #define FW_LINK_OFF 0x0 | 687 | #define FW_LINK_OFF 0x0 |
652 | #define FW_LINK_TX 0x1 | 688 | #define FW_LINK_TX 0x1 |
653 | /* 0x2 - link led on? */ | 689 | /* 0x2 - link led on? */ |
654 | 690 | ||
655 | enum { | 691 | enum { |
656 | /* CONTROL REGISTERS */ | ||
657 | CR_START = 0x9000, | ||
658 | |||
659 | /* FIRMWARE */ | ||
660 | FW_START = 0xee00, | ||
661 | |||
662 | /* The word at this offset contains the base address of the FW_REG | ||
663 | * registers */ | ||
664 | FW_REGS_ADDR_OFFSET = 0x1d, | ||
665 | |||
666 | |||
667 | /* EEPROM */ | ||
668 | E2P_START = 0xf800, | ||
669 | E2P_LEN = 0x800, | ||
670 | |||
671 | /* EEPROM layout */ | ||
672 | E2P_LOAD_CODE_LEN = 0xe, /* base 0xf800 */ | ||
673 | E2P_LOAD_VECT_LEN = 0x9, /* base 0xf80e */ | ||
674 | /* E2P_DATA indexes into this */ | ||
675 | E2P_DATA_LEN = 0x7e, /* base 0xf817 */ | ||
676 | E2P_BOOT_CODE_LEN = 0x760, /* base 0xf895 */ | ||
677 | E2P_INTR_VECT_LEN = 0xb, /* base 0xfff5 */ | ||
678 | |||
679 | /* Some precomputed offsets into the EEPROM */ | ||
680 | E2P_DATA_OFFSET = E2P_LOAD_CODE_LEN + E2P_LOAD_VECT_LEN, | ||
681 | E2P_BOOT_CODE_OFFSET = E2P_DATA_OFFSET + E2P_DATA_LEN, | ||
682 | }; | ||
683 | |||
684 | enum { | ||
685 | /* indices for ofdm_cal_values */ | 692 | /* indices for ofdm_cal_values */ |
686 | OFDM_36M_INDEX = 0, | 693 | OFDM_36M_INDEX = 0, |
687 | OFDM_48M_INDEX = 1, | 694 | OFDM_48M_INDEX = 1, |
@@ -692,6 +699,8 @@ struct zd_chip { | |||
692 | struct zd_usb usb; | 699 | struct zd_usb usb; |
693 | struct zd_rf rf; | 700 | struct zd_rf rf; |
694 | struct mutex mutex; | 701 | struct mutex mutex; |
702 | /* Base address of FW_REG_ registers */ | ||
703 | zd_addr_t fw_regs_base; | ||
695 | u8 e2p_mac[ETH_ALEN]; | 704 | u8 e2p_mac[ETH_ALEN]; |
696 | /* EepSetPoint in the vendor driver */ | 705 | /* EepSetPoint in the vendor driver */ |
697 | u8 pwr_cal_values[E2P_CHANNEL_COUNT]; | 706 | u8 pwr_cal_values[E2P_CHANNEL_COUNT]; |
diff --git a/drivers/net/wireless/zd1211rw/zd_def.h b/drivers/net/wireless/zd1211rw/zd_def.h index fb22f62cf1f3..deb99d1eaa77 100644 --- a/drivers/net/wireless/zd1211rw/zd_def.h +++ b/drivers/net/wireless/zd1211rw/zd_def.h | |||
@@ -23,6 +23,8 @@ | |||
23 | #include <linux/device.h> | 23 | #include <linux/device.h> |
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | 25 | ||
26 | typedef u16 __nocast zd_addr_t; | ||
27 | |||
26 | #define dev_printk_f(level, dev, fmt, args...) \ | 28 | #define dev_printk_f(level, dev, fmt, args...) \ |
27 | dev_printk(level, dev, "%s() " fmt, __func__, ##args) | 29 | dev_printk(level, dev, "%s() " fmt, __func__, ##args) |
28 | 30 | ||
diff --git a/drivers/net/wireless/zd1211rw/zd_ieee80211.h b/drivers/net/wireless/zd1211rw/zd_ieee80211.h index 26b8298dff8c..c4f36d39642b 100644 --- a/drivers/net/wireless/zd1211rw/zd_ieee80211.h +++ b/drivers/net/wireless/zd1211rw/zd_ieee80211.h | |||
@@ -2,7 +2,6 @@ | |||
2 | #define _ZD_IEEE80211_H | 2 | #define _ZD_IEEE80211_H |
3 | 3 | ||
4 | #include <net/ieee80211.h> | 4 | #include <net/ieee80211.h> |
5 | #include "zd_types.h" | ||
6 | 5 | ||
7 | /* Additional definitions from the standards. | 6 | /* Additional definitions from the standards. |
8 | */ | 7 | */ |
diff --git a/drivers/net/wireless/zd1211rw/zd_rf.h b/drivers/net/wireless/zd1211rw/zd_rf.h index 676b3734f1ed..a57732eb69e1 100644 --- a/drivers/net/wireless/zd1211rw/zd_rf.h +++ b/drivers/net/wireless/zd1211rw/zd_rf.h | |||
@@ -18,8 +18,6 @@ | |||
18 | #ifndef _ZD_RF_H | 18 | #ifndef _ZD_RF_H |
19 | #define _ZD_RF_H | 19 | #define _ZD_RF_H |
20 | 20 | ||
21 | #include "zd_types.h" | ||
22 | |||
23 | #define UW2451_RF 0x2 | 21 | #define UW2451_RF 0x2 |
24 | #define UCHIP_RF 0x3 | 22 | #define UCHIP_RF 0x3 |
25 | #define AL2230_RF 0x4 | 23 | #define AL2230_RF 0x4 |
diff --git a/drivers/net/wireless/zd1211rw/zd_types.h b/drivers/net/wireless/zd1211rw/zd_types.h deleted file mode 100644 index b3d642833e2c..000000000000 --- a/drivers/net/wireless/zd1211rw/zd_types.h +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* zd_types.h | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation; either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software | ||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
16 | */ | ||
17 | |||
18 | #ifndef _ZD_TYPES_H | ||
19 | #define _ZD_TYPES_H | ||
20 | |||
21 | #include <linux/types.h> | ||
22 | |||
23 | /* We have three register spaces mapped into the overall USB address space of | ||
24 | * 64K words (16-bit values). There is the control register space of | ||
25 | * double-word registers, the eeprom register space and the firmware register | ||
26 | * space. The control register space is byte mapped, the others are word | ||
27 | * mapped. | ||
28 | * | ||
29 | * For that reason, we are using byte offsets for control registers and word | ||
30 | * offsets for everything else. | ||
31 | */ | ||
32 | |||
33 | typedef u32 __nocast zd_addr_t; | ||
34 | |||
35 | enum { | ||
36 | ADDR_BASE_MASK = 0xff000000, | ||
37 | ADDR_OFFSET_MASK = 0x0000ffff, | ||
38 | ADDR_ZERO_MASK = 0x00ff0000, | ||
39 | NULL_BASE = 0x00000000, | ||
40 | USB_BASE = 0x01000000, | ||
41 | CR_BASE = 0x02000000, | ||
42 | CR_MAX_OFFSET = 0x0b30, | ||
43 | E2P_BASE = 0x03000000, | ||
44 | E2P_MAX_OFFSET = 0x007e, | ||
45 | FW_BASE = 0x04000000, | ||
46 | FW_MAX_OFFSET = 0x0005, | ||
47 | }; | ||
48 | |||
49 | #define ZD_ADDR_BASE(addr) ((u32)(addr) & ADDR_BASE_MASK) | ||
50 | #define ZD_OFFSET(addr) ((u32)(addr) & ADDR_OFFSET_MASK) | ||
51 | |||
52 | #define ZD_ADDR(base, offset) \ | ||
53 | ((zd_addr_t)(((base) & ADDR_BASE_MASK) | ((offset) & ADDR_OFFSET_MASK))) | ||
54 | |||
55 | #define ZD_NULL_ADDR ((zd_addr_t)0) | ||
56 | #define USB_REG(offset) ZD_ADDR(USB_BASE, offset) /* word addressing */ | ||
57 | #define CTL_REG(offset) ZD_ADDR(CR_BASE, offset) /* byte addressing */ | ||
58 | #define E2P_DATA(offset) ZD_ADDR(E2P_BASE, offset) /* word addressing */ | ||
59 | #define FW_REG(offset) ZD_ADDR(FW_BASE, offset) /* word addressing */ | ||
60 | |||
61 | static inline zd_addr_t zd_inc_word(zd_addr_t addr) | ||
62 | { | ||
63 | u32 base = ZD_ADDR_BASE(addr); | ||
64 | u32 offset = ZD_OFFSET(addr); | ||
65 | |||
66 | offset += base == CR_BASE ? 2 : 1; | ||
67 | |||
68 | return base | offset; | ||
69 | } | ||
70 | |||
71 | #endif /* _ZD_TYPES_H */ | ||
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c index 6a524409aeac..9025ad9e9d34 100644 --- a/drivers/net/wireless/zd1211rw/zd_usb.c +++ b/drivers/net/wireless/zd1211rw/zd_usb.c | |||
@@ -75,96 +75,6 @@ MODULE_DEVICE_TABLE(usb, usb_ids); | |||
75 | #define FW_ZD1211_PREFIX "zd1211/zd1211_" | 75 | #define FW_ZD1211_PREFIX "zd1211/zd1211_" |
76 | #define FW_ZD1211B_PREFIX "zd1211/zd1211b_" | 76 | #define FW_ZD1211B_PREFIX "zd1211/zd1211b_" |
77 | 77 | ||
78 | /* register address handling */ | ||
79 | |||
80 | #ifdef DEBUG | ||
81 | static int check_addr(struct zd_usb *usb, zd_addr_t addr) | ||
82 | { | ||
83 | u32 base = ZD_ADDR_BASE(addr); | ||
84 | u32 offset = ZD_OFFSET(addr); | ||
85 | |||
86 | if ((u32)addr & ADDR_ZERO_MASK) | ||
87 | goto invalid_address; | ||
88 | switch (base) { | ||
89 | case USB_BASE: | ||
90 | break; | ||
91 | case CR_BASE: | ||
92 | if (offset > CR_MAX_OFFSET) { | ||
93 | dev_dbg(zd_usb_dev(usb), | ||
94 | "CR offset %#010x larger than" | ||
95 | " CR_MAX_OFFSET %#10x\n", | ||
96 | offset, CR_MAX_OFFSET); | ||
97 | goto invalid_address; | ||
98 | } | ||
99 | if (offset & 1) { | ||
100 | dev_dbg(zd_usb_dev(usb), | ||
101 | "CR offset %#010x is not a multiple of 2\n", | ||
102 | offset); | ||
103 | goto invalid_address; | ||
104 | } | ||
105 | break; | ||
106 | case E2P_BASE: | ||
107 | if (offset > E2P_MAX_OFFSET) { | ||
108 | dev_dbg(zd_usb_dev(usb), | ||
109 | "E2P offset %#010x larger than" | ||
110 | " E2P_MAX_OFFSET %#010x\n", | ||
111 | offset, E2P_MAX_OFFSET); | ||
112 | goto invalid_address; | ||
113 | } | ||
114 | break; | ||
115 | case FW_BASE: | ||
116 | if (!usb->fw_base_offset) { | ||
117 | dev_dbg(zd_usb_dev(usb), | ||
118 | "ERROR: fw base offset has not been set\n"); | ||
119 | return -EAGAIN; | ||
120 | } | ||
121 | if (offset > FW_MAX_OFFSET) { | ||
122 | dev_dbg(zd_usb_dev(usb), | ||
123 | "FW offset %#10x is larger than" | ||
124 | " FW_MAX_OFFSET %#010x\n", | ||
125 | offset, FW_MAX_OFFSET); | ||
126 | goto invalid_address; | ||
127 | } | ||
128 | break; | ||
129 | default: | ||
130 | dev_dbg(zd_usb_dev(usb), | ||
131 | "address has unsupported base %#010x\n", addr); | ||
132 | goto invalid_address; | ||
133 | } | ||
134 | |||
135 | return 0; | ||
136 | invalid_address: | ||
137 | dev_dbg(zd_usb_dev(usb), | ||
138 | "ERROR: invalid address: %#010x\n", addr); | ||
139 | return -EINVAL; | ||
140 | } | ||
141 | #endif /* DEBUG */ | ||
142 | |||
143 | static u16 usb_addr(struct zd_usb *usb, zd_addr_t addr) | ||
144 | { | ||
145 | u32 base; | ||
146 | u16 offset; | ||
147 | |||
148 | base = ZD_ADDR_BASE(addr); | ||
149 | offset = ZD_OFFSET(addr); | ||
150 | |||
151 | ZD_ASSERT(check_addr(usb, addr) == 0); | ||
152 | |||
153 | switch (base) { | ||
154 | case CR_BASE: | ||
155 | offset += CR_START; | ||
156 | break; | ||
157 | case E2P_BASE: | ||
158 | offset += E2P_START + E2P_DATA_OFFSET; | ||
159 | break; | ||
160 | case FW_BASE: | ||
161 | offset += usb->fw_base_offset; | ||
162 | break; | ||
163 | } | ||
164 | |||
165 | return offset; | ||
166 | } | ||
167 | |||
168 | /* USB device initialization */ | 78 | /* USB device initialization */ |
169 | 79 | ||
170 | static int request_fw_file( | 80 | static int request_fw_file( |
@@ -858,7 +768,7 @@ static inline void init_usb_interrupt(struct zd_usb *usb) | |||
858 | spin_lock_init(&intr->lock); | 768 | spin_lock_init(&intr->lock); |
859 | intr->interval = int_urb_interval(zd_usb_to_usbdev(usb)); | 769 | intr->interval = int_urb_interval(zd_usb_to_usbdev(usb)); |
860 | init_completion(&intr->read_regs.completion); | 770 | init_completion(&intr->read_regs.completion); |
861 | intr->read_regs.cr_int_addr = cpu_to_le16(usb_addr(usb, CR_INTERRUPT)); | 771 | intr->read_regs.cr_int_addr = cpu_to_le16((u16)CR_INTERRUPT); |
862 | } | 772 | } |
863 | 773 | ||
864 | static inline void init_usb_rx(struct zd_usb *usb) | 774 | static inline void init_usb_rx(struct zd_usb *usb) |
@@ -890,22 +800,6 @@ void zd_usb_init(struct zd_usb *usb, struct net_device *netdev, | |||
890 | init_usb_rx(usb); | 800 | init_usb_rx(usb); |
891 | } | 801 | } |
892 | 802 | ||
893 | int zd_usb_init_hw(struct zd_usb *usb) | ||
894 | { | ||
895 | int r; | ||
896 | struct zd_chip *chip = zd_usb_to_chip(usb); | ||
897 | |||
898 | ZD_ASSERT(mutex_is_locked(&chip->mutex)); | ||
899 | r = zd_ioread16_locked(chip, &usb->fw_base_offset, | ||
900 | USB_REG(FW_START + FW_REGS_ADDR_OFFSET)); | ||
901 | if (r) | ||
902 | return r; | ||
903 | dev_dbg_f(zd_usb_dev(usb), "fw_base_offset: %#06hx\n", | ||
904 | usb->fw_base_offset); | ||
905 | |||
906 | return 0; | ||
907 | } | ||
908 | |||
909 | void zd_usb_clear(struct zd_usb *usb) | 803 | void zd_usb_clear(struct zd_usb *usb) |
910 | { | 804 | { |
911 | usb_set_intfdata(usb->intf, NULL); | 805 | usb_set_intfdata(usb->intf, NULL); |
@@ -1253,7 +1147,7 @@ int zd_usb_ioread16v(struct zd_usb *usb, u16 *values, | |||
1253 | return -ENOMEM; | 1147 | return -ENOMEM; |
1254 | req->id = cpu_to_le16(USB_REQ_READ_REGS); | 1148 | req->id = cpu_to_le16(USB_REQ_READ_REGS); |
1255 | for (i = 0; i < count; i++) | 1149 | for (i = 0; i < count; i++) |
1256 | req->addr[i] = cpu_to_le16(usb_addr(usb, addresses[i])); | 1150 | req->addr[i] = cpu_to_le16((u16)addresses[i]); |
1257 | 1151 | ||
1258 | udev = zd_usb_to_usbdev(usb); | 1152 | udev = zd_usb_to_usbdev(usb); |
1259 | prepare_read_regs_int(usb); | 1153 | prepare_read_regs_int(usb); |
@@ -1318,7 +1212,7 @@ int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs, | |||
1318 | req->id = cpu_to_le16(USB_REQ_WRITE_REGS); | 1212 | req->id = cpu_to_le16(USB_REQ_WRITE_REGS); |
1319 | for (i = 0; i < count; i++) { | 1213 | for (i = 0; i < count; i++) { |
1320 | struct reg_data *rw = &req->reg_writes[i]; | 1214 | struct reg_data *rw = &req->reg_writes[i]; |
1321 | rw->addr = cpu_to_le16(usb_addr(usb, ioreqs[i].addr)); | 1215 | rw->addr = cpu_to_le16((u16)ioreqs[i].addr); |
1322 | rw->value = cpu_to_le16(ioreqs[i].value); | 1216 | rw->value = cpu_to_le16(ioreqs[i].value); |
1323 | } | 1217 | } |
1324 | 1218 | ||
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.h b/drivers/net/wireless/zd1211rw/zd_usb.h index 317d37c36679..506ea6a74393 100644 --- a/drivers/net/wireless/zd1211rw/zd_usb.h +++ b/drivers/net/wireless/zd1211rw/zd_usb.h | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <linux/usb.h> | 25 | #include <linux/usb.h> |
26 | 26 | ||
27 | #include "zd_def.h" | 27 | #include "zd_def.h" |
28 | #include "zd_types.h" | ||
29 | 28 | ||
30 | enum devicetype { | 29 | enum devicetype { |
31 | DEVICE_ZD1211 = 0, | 30 | DEVICE_ZD1211 = 0, |
@@ -181,15 +180,14 @@ struct zd_usb_tx { | |||
181 | spinlock_t lock; | 180 | spinlock_t lock; |
182 | }; | 181 | }; |
183 | 182 | ||
184 | /* Contains the usb parts. The structure doesn't require a lock, because intf | 183 | /* Contains the usb parts. The structure doesn't require a lock because intf |
185 | * and fw_base_offset, will not be changed after initialization. | 184 | * will not be changed after initialization. |
186 | */ | 185 | */ |
187 | struct zd_usb { | 186 | struct zd_usb { |
188 | struct zd_usb_interrupt intr; | 187 | struct zd_usb_interrupt intr; |
189 | struct zd_usb_rx rx; | 188 | struct zd_usb_rx rx; |
190 | struct zd_usb_tx tx; | 189 | struct zd_usb_tx tx; |
191 | struct usb_interface *intf; | 190 | struct usb_interface *intf; |
192 | u16 fw_base_offset; | ||
193 | }; | 191 | }; |
194 | 192 | ||
195 | #define zd_usb_dev(usb) (&usb->intf->dev) | 193 | #define zd_usb_dev(usb) (&usb->intf->dev) |