--- trunk/driver/bcm43xx_main.c	2006-01-16 12:02:51.768866000 +0100
+++ trunk_ptt/driver/bcm43xx_main.c	2006-01-17 15:15:04.784000000 +0100
@@ -57,6 +57,108 @@
 MODULE_AUTHOR("Michael Buesch");
 MODULE_LICENSE("GPL");
 
+/**********************************************
+ * PTT BLINK LED ON RX
+ **********************************************/
+
+#define CONFIG_AIRPORT_BLINK 1
+
+#ifdef CONFIG_AIRPORT_BLINK 
+#include <linux/adb.h>
+#include <linux/pmu.h>
+#include <asm/prom.h>
+
+/* Set to 50ms minimum led-on time (also used to limit frequency
+ * of requests sent to the PMU
+ */
+#define PMU_AIRPORT_BLINK_TIME	(HZ/50)
+
+static struct adb_request pmu_blink_on, pmu_blink_off;
+static spinlock_t pmu_blink_lock;
+static unsigned long pmu_blink_stoptime;
+static int pmu_blink_ledstate;
+static struct timer_list pmu_blink_timer;
+static int pmu_airport_blink_enabled;
+
+
+static void
+pmu_rx_blink_timeout(unsigned long data)
+{
+	unsigned long flags;
+	
+	spin_lock_irqsave(&pmu_blink_lock, flags);
+
+	/* We may have been triggered again in a racy way, check
+	 * that we really want to switch it off
+	 */
+	if (time_after(pmu_blink_stoptime, jiffies))
+		goto done;
+
+	/* Previous req. not complete, try 100ms more */
+	if (pmu_blink_off.complete == 0)
+		mod_timer(&pmu_blink_timer, jiffies + PMU_AIRPORT_BLINK_TIME);
+	else if (pmu_blink_ledstate) {
+		pmu_request(&pmu_blink_off, NULL, 4, 0xee, 4, 0, 0);
+		pmu_blink_ledstate = 0;
+	}
+done:
+	spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static void
+pmu_rx_kick_blink(void)
+{
+	unsigned long flags;
+	
+	pmu_blink_stoptime = jiffies + PMU_AIRPORT_BLINK_TIME;
+	wmb();
+	mod_timer(&pmu_blink_timer, pmu_blink_stoptime);
+	/* Fast path when LED is already ON */
+	if (pmu_blink_ledstate == 1)
+		return;
+	spin_lock_irqsave(&pmu_blink_lock, flags);
+	if (pmu_blink_on.complete && !pmu_blink_ledstate) {
+		pmu_request(&pmu_blink_on, NULL, 4, 0xee, 4, 0, 1);
+		pmu_blink_ledstate = 1;
+	}
+	spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static int
+pmu_rx_blink_init(void)
+{
+	struct device_node *dt;
+	const char *model;
+
+	/* Currently, I only enable this feature on KeyLargo based laptops,
+	 * older laptops may support it (at least heathrow/paddington) but
+	 * I don't feel like loading those venerable old machines with so
+	 * much additional interrupt & PMU activity...
+	 */
+/*	if (pmu_get_model() != PMU_KEYLARGO_BASED)
+		return 0;*/
+	
+	dt = find_devices("device-tree");
+	if (dt == NULL)
+		return 0;
+	model = (const char *)get_property(dt, "model", NULL);
+	if (model == NULL)
+		return 0;
+	if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
+	    strncmp(model, "iBook", strlen("iBook")) != 0)
+	    	return 0;
+	
+	pmu_blink_on.complete = 1;
+	pmu_blink_off.complete = 1;
+	spin_lock_init(&pmu_blink_lock);
+	init_timer(&pmu_blink_timer);
+	pmu_blink_timer.function = pmu_rx_blink_timeout;
+
+	return 1;
+}
+
+#endif /* CONFIG_AIRPORT_BLINK  */
+
 #ifdef CONFIG_BCM947XX
 extern char *nvram_get(char *name);
 #endif
@@ -4017,6 +4119,11 @@
 {
 	int err;
 
+#ifdef CONFIG_AIRPORT_BLINK 
+	if (pmu_airport_blink_enabled)
+		pmu_rx_kick_blink();
+#endif /* CONFIG_AIRPORT_BLINK  */
+
 	err = ieee80211_rx(bcm->ieee, skb, stats);
 	if (unlikely(err == 0))
 		return -EINVAL;
@@ -4587,12 +4694,32 @@
 {
 	printk(KERN_INFO BCM43xx_DRIVER_NAME "\n");
 	bcm43xx_debugfs_init();
+	
+#ifdef CONFIG_AIRPORT_BLINK 
+	pmu_airport_blink_enabled = pmu_rx_blink_init();
+#endif
+
 	return pci_register_driver(&bcm43xx_pci_driver);
+
 }
 
 static void __exit bcm43xx_exit(void)
 {
 	pci_unregister_driver(&bcm43xx_pci_driver);
+
+#ifdef CONFIG_AIRPORT_BLINK 
+	if (pmu_airport_blink_enabled) {
+		unsigned long flags;
+
+		/* Make sure we don't hit the PMU blink */
+		spin_lock_irqsave(&pmu_blink_lock, flags);
+		if (pmu_blink_ledstate)
+			del_timer(&pmu_blink_timer);
+		pmu_blink_ledstate = 0;
+		spin_unlock_irqrestore(&pmu_blink_lock, flags);
+	}
+#endif
+
 	bcm43xx_debugfs_exit();
 }
 
