This version of the LED patch takes into account the inverse mapping of the
SOFTLED on IBM devices.

diff -uNr madwifi-orig/driver/if_ath.c madwifi-gpio-proc/driver/if_ath.c
--- madwifi-orig/driver/if_ath.c	2004-05-27 01:39:12.000000000 +0200
+++ madwifi-gpio-proc/driver/if_ath.c	2004-06-03 01:59:53.000000000 +0200
@@ -139,6 +139,12 @@
 static  int     ath_xchanmode = AH_TRUE;        /* enable extended channels */
 static  int     ath_ctlpkt_type=-1;             /* Control pkt type to filter */
 
+#ifdef SOFTLED
+void
+ath_update_LED (struct net_device *dev, struct ath_hal *ah, 
+                struct ieee80211com *ic, u_int32_t event);
+#endif /* SOFTLED */
+
 #ifdef AR_DEBUG
 int	ath_debug = 0;
 #define	IFF_DUMPPKTS(_ic)	(ath_debug || netif_msg_dumppkts(_ic))
@@ -385,8 +391,9 @@
 
 	DPRINTF(("ath_detach flags %x\n", dev->flags));
 #ifdef SOFTLED 
+	/* turn off LED */
 	sc->sc_ic.ic_beaconCnt = 0;
-	ath_hal_gpioSet(sc->sc_ah,sc->sc_ic.ic_ledPin,1);
+	ath_hal_gpioSet(sc->sc_ah,sc->sc_ic.ic_ledPin,sc->sc_ic.ic_ledInverse);
 #endif
 	ath_stop(dev);
 	sc->sc_invalid = 1;
@@ -440,6 +447,12 @@
 	}
 	if (!ath_hal_intrpend(ah))		/* shared irq, not for us */
 		return IRQ_NONE;
+#ifdef SOFTLED
+	/* XXX WARNING: this is a very ugly hack! XXX */
+	if (sc->sc_ic.ic_caps & IEEE80211_C_SOFTLED) {
+		ath_update_LED(dev, ah, &sc->sc_ic, POLL_EVENT);
+	}
+#endif
 	if ((dev->flags & (IFF_RUNNING|IFF_UP)) != (IFF_RUNNING|IFF_UP)) {
 		DPRINTF(("ath_intr: flags 0x%x\n", dev->flags));
 		ath_hal_getisr(ah, &status);	/* clear ISR */
@@ -1678,37 +1691,49 @@
 ath_update_LED (struct net_device *dev, struct ath_hal *ah, 
                 struct ieee80211com *ic, u_int32_t event)
 {
+	static unsigned int nextjiffies=0;
 	static unsigned int state=1;
-	int rateOn, rateOff, diff;
+	static unsigned int rfkillstate=1;
+	int rfkill, ifup;
+	//int rateOn, rateOff, diff;
 	
-	if (ic->ic_state != IEEE80211_S_RUN) {
-		// Device is in scan mode, searching for AP
-		/* We flash the LED on for 5s and off for 200ms */
-		if (ic->ic_beaconCnt >= (2+state*48)) {
+	ath_hal_gpioCfgInput(ah,ic->ic_rfKillPin);
+	rfkill = ath_hal_gpioGet(ah,ic->ic_rfKillPin);
+	if (rfkill != rfkillstate) {
+		printk("%s: rfKill state changed to %i\n", dev->name, rfkill);
+		rfkillstate = rfkill;
+		if (rfkill == 0) {
+			/* turn off LED */
 			ath_hal_gpioCfgOutput(ah,ic->ic_ledPin);
-			ath_hal_gpioSet(ah,ic->ic_ledPin,state);
-			state ^= 1;
-			ic->ic_beaconCnt = 0;
+			ath_hal_gpioSet(ah,ic->ic_ledPin, ic->ic_ledInverse);
+			return;
 		}
 	}
+	
+	if (jiffies < nextjiffies) return;
+
+	if (ic->ic_state != IEEE80211_S_RUN) {
+		/* Device is in scan mode, searching for AP */
+		nextjiffies = jiffies + (66 - state*20)*HZ/100;
+		state ^= 1;
+	}
 	else {
 		switch(event) {
 		case TRANSMIT_EVENT:
-		case RECEIVE_EVENT:
-			rateOn = 20;
-			rateOff = 2;
-			diff = rateOn-rateOff;
-			if (ic->ic_beaconCnt >= (rateOff + state*diff)) {
-				ath_hal_gpioCfgOutput(ah,ic->ic_ledPin);
-				ath_hal_gpioSet(ah,ic->ic_ledPin,state);
-				state ^= 1;
-				ic->ic_beaconCnt = 0;
-			}
+			state ^= 1;
+			nextjiffies = jiffies + 5*HZ/100;
 			break;
+		case RECEIVE_EVENT:
 		default:
+			nextjiffies = jiffies + 5*HZ/100;
+			state = 1;
 			break;
 		}
 	}
+	ifup = ((dev->flags & (IFF_RUNNING|IFF_UP)) == (IFF_RUNNING|IFF_UP));
+
+	ath_hal_gpioCfgOutput(ah,ic->ic_ledPin);
+	ath_hal_gpioSet(ah,ic->ic_ledPin,(state & ifup) ^ ic->ic_ledInverse);
 }
 #endif
 
diff -uNr madwifi-orig/driver/if_ath_pci.c madwifi-gpio-proc/driver/if_ath_pci.c
--- madwifi-orig/driver/if_ath_pci.c	2004-05-27 01:39:12.000000000 +0200
+++ madwifi-gpio-proc/driver/if_ath_pci.c	2004-06-01 17:03:44.000000000 +0200
@@ -167,9 +167,11 @@
 	if ((id->vendor == 0x168c) && 
 	    ((id->device == 0x1014) || (id->device==0x12))) {
 		ath_sc->sc_ic.ic_ledPin = 0;
+		ath_sc->sc_ic.ic_ledInverse = 1;
 		ath_sc->sc_ic.ic_rfKillPin = 1;
 	} else {
 		ath_sc->sc_ic.ic_ledPin = 1;
+		ath_sc->sc_ic.ic_ledInverse = 0;
 		ath_sc->sc_ic.ic_rfKillPin = 0;
 	}
 	ath_hal_gpioCfgOutput(ath_sc->sc_ah, ath_sc->sc_ic.ic_ledPin);
diff -uNr madwifi-orig/wlan/if_ieee80211.h madwifi-gpio-proc/wlan/if_ieee80211.h
--- madwifi-orig/wlan/if_ieee80211.h	2004-05-27 01:39:51.000000000 +0200
+++ madwifi-gpio-proc/wlan/if_ieee80211.h	2004-06-01 17:00:04.000000000 +0200
@@ -753,6 +753,7 @@
 #ifdef SOFTLED
         u_int16_t               ic_beaconCnt;   /* becaon Count for LEDs */
         u_int16_t               ic_ledPin;      /* GPIO pin for soft LED */
+        u_int8_t                ic_ledInverse;  /* Is LED pin inverse? */
         u_int16_t               ic_rfKillPin;   /* GPIO pin for RF Kill */
 #endif
 #ifdef CONFIG_PROC_FS
