rt2x00: Simplify rt2x00_check_rev
PATCH 1/1 rt2x00: Simplify rt2x00_check_rev
rt2x00_check_rev() was too specific for rt2500usb and rt73usb, by adding the mask argument (instead of hardcoding it into the function itself) we can use the function in rt2800usb as well.
--- drivers/net/wireless/rt2x00/rt2500usb.c | 2 +- drivers/net/wireless/rt2x00/rt2800usb.c | 7 ++++--- drivers/net/wireless/rt2x00/rt2x00.h | 7 +++---- drivers/net/wireless/rt2x00/rt73usb.c | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-)
drivers/net/wireless/rt2x00/rt2500usb.c +1 -1
@@ -1559,7 +1559,7 @@ static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)rt2500usb_register_read (rt2x00dev,MAC_CSR0 , ®);rt2x00_set_chip (rt2x00dev,RT2570 , value, reg); -if (!rt2x00_check_rev (&rt2x00dev->chip,0 )) { +if (!rt2x00_check_rev (&rt2x00dev->chip,0x000ffff0 ,0 )) {ERROR (rt2x00dev,"Invalid RT chipset detected.\n" );return -ENODEV ; }
drivers/net/wireless/rt2x00/rt2800usb.c +4 -3
@@ -2348,9 +2348,10 @@ static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)* The check for rt2860 is not a typo, some rt2870 hardware * identifies itself as rt2860 in the CSR register. */ -if ((rt2x00_get_field32 (reg,MAC_CSR0_ASIC_VER ) !=0x2860 ) && - (rt2x00_get_field32 (reg,MAC_CSR0_ASIC_VER ) !=0x2870 ) && - (rt2x00_get_field32 (reg,MAC_CSR0_ASIC_VER ) !=0x3070 )) { +if (!rt2x00_check_rev (&rt2x00dev->chip,0xfff00000 ,0x286 ) && + !rt2x00_check_rev (&rt2x00dev->chip,0xfff00000 ,0x287 ) && + !rt2x00_check_rev (&rt2x00dev->chip,0xfff00000 ,0x288 ) && + !rt2x00_check_rev (&rt2x00dev->chip,0xffff0000 ,0x3070 )) {ERROR (rt2x00dev,"Invalid RT chipset detected.\n" );return -ENODEV ; }
drivers/net/wireless/rt2x00/rt2x00.h +3 -4
@@ -921,11 +921,10 @@ static inline u32 rt2x00_rev(const struct rt2x00_chip *chipset)return chipset->rev; } -static inline u16 rt2x00_check_rev (const struct rt2x00_chip *chipset, -const u32 rev) +static inline bool rt2x00_check_rev (const struct rt2x00_chip *chipset, +const u32 mask,const u32 rev) { -return (((chipset->rev &0xffff0 ) == rev) && - !!(chipset->rev &0x0000f )); +return ((chipset->rev & mask) == rev); }/**
drivers/net/wireless/rt2x00/rt73usb.c +2 -1
@@ -1846,7 +1846,8 @@ static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)rt2x00usb_register_read (rt2x00dev,MAC_CSR0 , ®);rt2x00_set_chip (rt2x00dev,RT2571 , value, reg); -if (!rt2x00_check_rev (&rt2x00dev->chip,0x25730 )) { +if (!rt2x00_check_rev (&rt2x00dev->chip,0x000ffff0 ,0x25730 ) || + !rt2x00_check_rev (&rt2x00dev->chip,0x0000000f ,0 )) {ERROR (rt2x00dev,"Invalid RT chipset detected.\n" );return -ENODEV ; }
Signature · 1 line
1.6.2.3
Quoted 6 lines · Ivo van Doorn
rt2x00_check_rev()was too specific for rt2500usb and rt73usb, by adding the mask argument (instead of hardcoding it into the function itself) we can use the function in rt2800usb as well.Signed-off-by Ivo van Doorn <[email protected]>---
Please drop this patch. I'll send the correct version in a few minutes.
Quoted 70 lines
drivers/net/wireless/rt2x00/rt2500usb.c | 2 +- drivers/net/wireless/rt2x00/rt2800usb.c | 7 ++++--- drivers/net/wireless/rt2x00/rt2x00.h | 7 +++---- drivers/net/wireless/rt2x00/rt73usb.c | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-)drivers/net/wireless/rt2x00/rt2500usb.c +1
-1@@ -1559,7 +1559,7 @@ static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)rt2500usb_register_read (rt2x00dev,MAC_CSR0 , ®);rt2x00_set_chip (rt2x00dev,RT2570 , value, reg); -if (!rt2x00_check_rev (&rt2x00dev->chip,0 )) { +if (!rt2x00_check_rev (&rt2x00dev->chip,0x000ffff0 ,0 )) {ERROR (rt2x00dev,"Invalid RT chipset detected.\n" );return -ENODEV ; }drivers/net/wireless/rt2x00/rt2800usb.c +4
-3@@ -2348,9 +2348,10 @@ static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)* The check for rt2860 is not a typo, some rt2870 hardware * identifies itself as rt2860 in the CSR register. */ -if ((rt2x00_get_field32 (reg,MAC_CSR0_ASIC_VER ) !=0x2860 ) && - (rt2x00_get_field32 (reg,MAC_CSR0_ASIC_VER ) !=0x2870 ) && - (rt2x00_get_field32 (reg,MAC_CSR0_ASIC_VER ) !=0x3070 )) { +if (!rt2x00_check_rev (&rt2x00dev->chip,0xfff00000 ,0x286 ) && + !rt2x00_check_rev (&rt2x00dev->chip,0xfff00000 ,0x287 ) && + !rt2x00_check_rev (&rt2x00dev->chip,0xfff00000 ,0x288 ) && + !rt2x00_check_rev (&rt2x00dev->chip,0xffff0000 ,0x3070 )) {ERROR (rt2x00dev,"Invalid RT chipset detected.\n" );return -ENODEV ; }drivers/net/wireless/rt2x00/rt2x00.h +3
-4@@ -921,11 +921,10 @@ static inline u32 rt2x00_rev(const struct rt2x00_chip *chipset)return chipset->rev; } -static inline u16 rt2x00_check_rev (const struct rt2x00_chip *chipset, -const u32 rev) +static inline bool rt2x00_check_rev (const struct rt2x00_chip *chipset, +const u32 mask,const u32 rev) { -return (((chipset->rev &0xffff0 ) == rev) && - !!(chipset->rev &0x0000f )); +return ((chipset->rev & mask) == rev); }/** drivers/net/wireless/rt2x00/rt73usb.c +2
-1@@ -1846,7 +1846,8 @@ static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)rt2x00usb_register_read (rt2x00dev,MAC_CSR0 , ®);rt2x00_set_chip (rt2x00dev,RT2571 , value, reg); -if (!rt2x00_check_rev (&rt2x00dev->chip,0x25730 )) { +if (!rt2x00_check_rev (&rt2x00dev->chip,0x000ffff0 ,0x25730 ) || + !rt2x00_check_rev (&rt2x00dev->chip,0x0000000f ,0 )) {ERROR (rt2x00dev,"Invalid RT chipset detected.\n" );return -ENODEV ; }
PATCH v2 1/1 rt2x00: Simplify rt2x00_check_rev
In reply to Ivo van Doornrt2x00_check_rev() was too specific for rt2500usb and rt73usb, by adding the mask argument (instead of hardcoding it into the function itself) we can use the function in rt2800usb as well.
v2: Fix revision mask for rt2800usb
--- drivers/net/wireless/rt2x00/rt2500usb.c | 2 +- drivers/net/wireless/rt2x00/rt2800usb.c | 7 ++++--- drivers/net/wireless/rt2x00/rt2x00.h | 7 +++---- drivers/net/wireless/rt2x00/rt73usb.c | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-)
drivers/net/wireless/rt2x00/rt2500usb.c +1 -1
@@ -1559,7 +1559,7 @@ static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)rt2500usb_register_read (rt2x00dev,MAC_CSR0 , ®);rt2x00_set_chip (rt2x00dev,RT2570 , value, reg); -if (!rt2x00_check_rev (&rt2x00dev->chip,0 )) { +if (!rt2x00_check_rev (&rt2x00dev->chip,0x000ffff0 ,0 )) {ERROR (rt2x00dev,"Invalid RT chipset detected.\n" );return -ENODEV ; }
drivers/net/wireless/rt2x00/rt2800usb.c +4 -3
@@ -2348,9 +2348,10 @@ static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)* The check for rt2860 is not a typo, some rt2870 hardware * identifies itself as rt2860 in the CSR register. */ -if ((rt2x00_get_field32 (reg,MAC_CSR0_ASIC_VER ) !=0x2860 ) && - (rt2x00_get_field32 (reg,MAC_CSR0_ASIC_VER ) !=0x2870 ) && - (rt2x00_get_field32 (reg,MAC_CSR0_ASIC_VER ) !=0x3070 )) { +if (!rt2x00_check_rev (&rt2x00dev->chip,0xfff00000 ,0x28600000 ) && + !rt2x00_check_rev (&rt2x00dev->chip,0xfff00000 ,0x28700000 ) && + !rt2x00_check_rev (&rt2x00dev->chip,0xfff00000 ,0x28800000 ) && + !rt2x00_check_rev (&rt2x00dev->chip,0xffff0000 ,0x30700000 )) {ERROR (rt2x00dev,"Invalid RT chipset detected.\n" );return -ENODEV ; }
drivers/net/wireless/rt2x00/rt2x00.h +3 -4
@@ -921,11 +921,10 @@ static inline u32 rt2x00_rev(const struct rt2x00_chip *chipset)return chipset->rev; } -static inline u16 rt2x00_check_rev (const struct rt2x00_chip *chipset, -const u32 rev) +static inline bool rt2x00_check_rev (const struct rt2x00_chip *chipset, +const u32 mask,const u32 rev) { -return (((chipset->rev &0xffff0 ) == rev) && - !!(chipset->rev &0x0000f )); +return ((chipset->rev & mask) == rev); }/**
drivers/net/wireless/rt2x00/rt73usb.c +2 -1
@@ -1846,7 +1846,8 @@ static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)rt2x00usb_register_read (rt2x00dev,MAC_CSR0 , ®);rt2x00_set_chip (rt2x00dev,RT2571 , value, reg); -if (!rt2x00_check_rev (&rt2x00dev->chip,0x25730 )) { +if (!rt2x00_check_rev (&rt2x00dev->chip,0x000ffff0 ,0x25730 ) || + !rt2x00_check_rev (&rt2x00dev->chip,0x0000000f ,0 )) {ERROR (rt2x00dev,"Invalid RT chipset detected.\n" );return -ENODEV ; }
Signature · 1 line
1.6.2.3