fix athn(4) rfkill switch detection for ar9003
As reported a while ago (see http://marc.info/?l=openbsd-miscm=132911890531492w=2) athn(4) attaches to some ar9003 chips but fails to get past the hardware rfkill switch. It always reports radio is disabled by hardware switch regardless of the actual state of the switch. I've got an ar9485 which the in-tree athn(4) does not yet attach to. It belongs to the same chip family and also has the rfkill switch problem so I could diagnose it. The bug is that the ar9003 gpio support code reads the wrong register to obtain the value of an gpio input pin. This diff makes gpio read code match the Linux driver and fixes rfkill switch state detection. I doubt that ar9300 cards will work properly with this patch. In my case the driver now fails a little later while trying to perform TX calibration. Will try looking into that next... ok? Index: ar9003.c === RCS file: /cvs/src/sys/dev/ic/ar9003.c,v retrieving revision 1.23 diff -u -p -r1.23 ar9003.c --- ar9003.c25 Aug 2012 12:14:31 - 1.23 +++ ar9003.c7 Oct 2012 14:56:18 - @@ -503,7 +506,7 @@ int ar9003_gpio_read(struct athn_softc *sc, int pin) { KASSERT(pin sc-ngpiopins); - return ((AR_READ(sc, AR_GPIO_IN_OUT) pin) 1); + return ((AR_READ(sc, AR_GPIO_IN) (1 pin)) != 0); } void Index: ar9003reg.h === RCS file: /cvs/src/sys/dev/ic/ar9003reg.h,v retrieving revision 1.7 diff -u -p -r1.7 ar9003reg.h --- ar9003reg.h 1 Jan 2011 13:44:42 - 1.7 +++ ar9003reg.h 7 Oct 2012 14:49:25 - @@ -25,6 +25,8 @@ #define AR_ISR_S4_S0x00d8 #define AR_ISR_S5_S0x00dc #define AR_GPIO_IN_OUT 0x4048 +#define AR_GPIO_IN 0x404c +#define AR9300_GPIO_IN_VAL 0x0001 #define AR_GPIO_OE_OUT 0x4050 #define AR_GPIO_INTR_POL 0x4058 #define AR_GPIO_INPUT_EN_VAL 0x405c Index: ar9380.c === RCS file: /cvs/src/sys/dev/ic/ar9380.c,v retrieving revision 1.15 diff -u -p -r1.15 ar9380.c --- ar9380.c10 Jun 2012 21:23:36 - 1.15 +++ ar9380.c6 Oct 2012 18:21:33 - @@ -148,7 +150,11 @@ ar9380_setup(struct athn_softc *sc) if (base-rfSilent AR_EEP_RFSILENT_ENABLED) { sc-flags |= ATHN_FLAG_RFSILENT; /* Get GPIO pin used by hardware radio switch. */ - sc-rfsilent_pin = base-wlanDisableGpio; + sc-rfsilent_pin = MS(base-rfSilent, + AR_EEP_RFSILENT_GPIO_SEL); + /* Get polarity of hardware radio switch. */ + if (base-rfSilent AR_EEP_RFSILENT_POLARITY) + sc-flags |= ATHN_FLAG_RFSILENT_REVERSED; } /* Set the number of HW key cache entries. */ Index: ar9380reg.h === RCS file: /cvs/src/sys/dev/ic/ar9380reg.h,v retrieving revision 1.17 diff -u -p -r1.17 ar9380reg.h --- ar9380reg.h 10 Jun 2012 21:23:36 - 1.17 +++ ar9380reg.h 6 Oct 2012 18:21:07 - @@ -75,6 +75,8 @@ struct ar9380_base_eep_hdr { uint8_t eepMisc; uint8_t rfSilent; #define AR_EEP_RFSILENT_ENABLED0x0001 +#define AR_EEP_RFSILENT_GPIO_SEL_M 0x001c +#define AR_EEP_RFSILENT_GPIO_SEL_S 2 #define AR_EEP_RFSILENT_POLARITY 0x0002 uint8_t blueToothOptions;
Re: fix athn(4) rfkill switch detection for ar9003
Date: Sun, 7 Oct 2012 18:02:23 +0200 From: Stefan Sperling s...@openbsd.org As reported a while ago (see http://marc.info/?l=openbsd-miscm=132911890531492w=2) athn(4) attaches to some ar9003 chips but fails to get past the hardware rfkill switch. It always reports radio is disabled by hardware switch regardless of the actual state of the switch. I've got an ar9485 which the in-tree athn(4) does not yet attach to. It belongs to the same chip family and also has the rfkill switch problem so I could diagnose it. The bug is that the ar9003 gpio support code reads the wrong register to obtain the value of an gpio input pin. This diff makes gpio read code match the Linux driver and fixes rfkill switch state detection. I doubt that ar9300 cards will work properly with this patch. In my case the driver now fails a little later while trying to perform TX calibration. Will try looking into that next... ok? Hmm, the AR9300_GPIO_IN_VAL define you introduce isn't actually used. Not terribly important, but you could leave that one out. Either way: ok kettenis@ Index: ar9003.c === RCS file: /cvs/src/sys/dev/ic/ar9003.c,v retrieving revision 1.23 diff -u -p -r1.23 ar9003.c --- ar9003.c 25 Aug 2012 12:14:31 - 1.23 +++ ar9003.c 7 Oct 2012 14:56:18 - @@ -503,7 +506,7 @@ int ar9003_gpio_read(struct athn_softc *sc, int pin) { KASSERT(pin sc-ngpiopins); - return ((AR_READ(sc, AR_GPIO_IN_OUT) pin) 1); + return ((AR_READ(sc, AR_GPIO_IN) (1 pin)) != 0); } void Index: ar9003reg.h === RCS file: /cvs/src/sys/dev/ic/ar9003reg.h,v retrieving revision 1.7 diff -u -p -r1.7 ar9003reg.h --- ar9003reg.h 1 Jan 2011 13:44:42 - 1.7 +++ ar9003reg.h 7 Oct 2012 14:49:25 - @@ -25,6 +25,8 @@ #define AR_ISR_S4_S 0x00d8 #define AR_ISR_S5_S 0x00dc #define AR_GPIO_IN_OUT 0x4048 +#define AR_GPIO_IN 0x404c +#define AR9300_GPIO_IN_VAL 0x0001 #define AR_GPIO_OE_OUT 0x4050 #define AR_GPIO_INTR_POL 0x4058 #define AR_GPIO_INPUT_EN_VAL 0x405c Index: ar9380.c === RCS file: /cvs/src/sys/dev/ic/ar9380.c,v retrieving revision 1.15 diff -u -p -r1.15 ar9380.c --- ar9380.c 10 Jun 2012 21:23:36 - 1.15 +++ ar9380.c 6 Oct 2012 18:21:33 - @@ -148,7 +150,11 @@ ar9380_setup(struct athn_softc *sc) if (base-rfSilent AR_EEP_RFSILENT_ENABLED) { sc-flags |= ATHN_FLAG_RFSILENT; /* Get GPIO pin used by hardware radio switch. */ - sc-rfsilent_pin = base-wlanDisableGpio; + sc-rfsilent_pin = MS(base-rfSilent, + AR_EEP_RFSILENT_GPIO_SEL); + /* Get polarity of hardware radio switch. */ + if (base-rfSilent AR_EEP_RFSILENT_POLARITY) + sc-flags |= ATHN_FLAG_RFSILENT_REVERSED; } /* Set the number of HW key cache entries. */ Index: ar9380reg.h === RCS file: /cvs/src/sys/dev/ic/ar9380reg.h,v retrieving revision 1.17 diff -u -p -r1.17 ar9380reg.h --- ar9380reg.h 10 Jun 2012 21:23:36 - 1.17 +++ ar9380reg.h 6 Oct 2012 18:21:07 - @@ -75,6 +75,8 @@ struct ar9380_base_eep_hdr { uint8_t eepMisc; uint8_t rfSilent; #define AR_EEP_RFSILENT_ENABLED 0x0001 +#define AR_EEP_RFSILENT_GPIO_SEL_M 0x001c +#define AR_EEP_RFSILENT_GPIO_SEL_S 2 #define AR_EEP_RFSILENT_POLARITY 0x0002 uint8_t blueToothOptions;
Re: fix athn(4) rfkill switch detection for ar9003
On Sun, Oct 07, 2012 at 07:41:58PM +0200, Mark Kettenis wrote: Hmm, the AR9300_GPIO_IN_VAL define you introduce isn't actually used. Thanks, I forgot about using it. Not sure if it is important though maybe the upper bits of the register aren't always stable? In any case we should just use the bit mask like Linux does. Index: ar9003.c === RCS file: /cvs/src/sys/dev/ic/ar9003.c,v retrieving revision 1.23 diff -u -p -r1.23 ar9003.c --- ar9003.c25 Aug 2012 12:14:31 - 1.23 +++ ar9003.c7 Oct 2012 21:26:18 - @@ -503,7 +503,8 @@ int ar9003_gpio_read(struct athn_softc *sc, int pin) { KASSERT(pin sc-ngpiopins); - return ((AR_READ(sc, AR_GPIO_IN_OUT) pin) 1); + return (((AR_READ(sc, AR_GPIO_IN) AR9300_GPIO_IN_VAL) + (1 pin)) != 0); } void Index: ar9003reg.h === RCS file: /cvs/src/sys/dev/ic/ar9003reg.h,v retrieving revision 1.7 diff -u -p -r1.7 ar9003reg.h --- ar9003reg.h 1 Jan 2011 13:44:42 - 1.7 +++ ar9003reg.h 7 Oct 2012 21:26:18 - @@ -25,6 +25,8 @@ #define AR_ISR_S4_S0x00d8 #define AR_ISR_S5_S0x00dc #define AR_GPIO_IN_OUT 0x4048 +#define AR_GPIO_IN 0x404c +#define AR9300_GPIO_IN_VAL 0x0001 #define AR_GPIO_OE_OUT 0x4050 #define AR_GPIO_INTR_POL 0x4058 #define AR_GPIO_INPUT_EN_VAL 0x405c Index: ar9380.c === RCS file: /cvs/src/sys/dev/ic/ar9380.c,v retrieving revision 1.15 diff -u -p -r1.15 ar9380.c --- ar9380.c10 Jun 2012 21:23:36 - 1.15 +++ ar9380.c7 Oct 2012 21:26:18 - @@ -148,7 +148,11 @@ ar9380_setup(struct athn_softc *sc) if (base-rfSilent AR_EEP_RFSILENT_ENABLED) { sc-flags |= ATHN_FLAG_RFSILENT; /* Get GPIO pin used by hardware radio switch. */ - sc-rfsilent_pin = base-wlanDisableGpio; + sc-rfsilent_pin = MS(base-rfSilent, + AR_EEP_RFSILENT_GPIO_SEL); + /* Get polarity of hardware radio switch. */ + if (base-rfSilent AR_EEP_RFSILENT_POLARITY) + sc-flags |= ATHN_FLAG_RFSILENT_REVERSED; } /* Set the number of HW key cache entries. */ Index: ar9380reg.h === RCS file: /cvs/src/sys/dev/ic/ar9380reg.h,v retrieving revision 1.17 diff -u -p -r1.17 ar9380reg.h --- ar9380reg.h 10 Jun 2012 21:23:36 - 1.17 +++ ar9380reg.h 7 Oct 2012 21:26:18 - @@ -75,6 +75,8 @@ struct ar9380_base_eep_hdr { uint8_t eepMisc; uint8_t rfSilent; #define AR_EEP_RFSILENT_ENABLED0x0001 +#define AR_EEP_RFSILENT_GPIO_SEL_M 0x001c +#define AR_EEP_RFSILENT_GPIO_SEL_S 2 #define AR_EEP_RFSILENT_POLARITY 0x0002 uint8_t blueToothOptions;