* [PATCH] convert powermac ide blink to new led infrastructure
@ 2006-04-28 14:49 Johannes Berg
2006-04-28 15:15 ` Johannes Berg
0 siblings, 1 reply; 19+ messages in thread
From: Johannes Berg @ 2006-04-28 14:49 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev list, debian-powerpc
This patch removes the old pmac ide led blink code and adds generic LED
subsystem support for the LED.
Ben: I removed the retry code that was present in the original. I guess
LEDs aren't really too important but if it really is necessary please
tell me and I'll add it back.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
--- linux-2.6.orig/drivers/ide/Kconfig 2006-04-28 13:13:38.777288704 +0200
+++ linux-2.6/drivers/ide/Kconfig 2006-04-28 13:13:48.797288704 +0200
@@ -773,13 +773,6 @@ config BLK_DEV_IDEDMA_PMAC
to transfer data to and from memory. Saying Y is safe and improves
performance.
-config BLK_DEV_IDE_PMAC_BLINK
- bool "Blink laptop LED on drive activity"
- depends on BLK_DEV_IDE_PMAC && ADB_PMU
- help
- This option enables the use of the sleep LED as a hard drive
- activity LED.
-
config BLK_DEV_IDE_SWARM
tristate "IDE for Sibyte evaluation boards"
depends on SIBYTE_SB1xxx_SOC
--- linux-2.6.orig/drivers/ide/ppc/pmac.c 2006-04-28 13:13:58.967288704 +0200
+++ linux-2.6/drivers/ide/ppc/pmac.c 2006-04-28 13:17:01.657288704 +0200
@@ -421,107 +421,6 @@ static void pmac_ide_kauai_selectproc(id
#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
/*
- * Below is the code for blinking the laptop LED along with hard
- * disk activity.
- */
-
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
-
-/* Set to 50ms minimum led-on time (also used to limit frequency
- * of requests sent to the PMU
- */
-#define PMU_HD_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_ide_blink_enabled;
-
-
-static void
-pmu_hd_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_HD_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_hd_kick_blink(void *data, int rw)
-{
- unsigned long flags;
-
- pmu_blink_stoptime = jiffies + PMU_HD_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_hd_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 = of_find_node_by_path("/");
- 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) {
- of_node_put(dt);
- return 0;
- }
- of_node_put(dt);
-
- 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_hd_blink_timeout;
-
- return 1;
-}
-
-#endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
-/*
* N.B. this can't be an initfunc, because the media-bay task can
* call ide_[un]register at any time.
*/
@@ -1190,23 +1089,6 @@ pmac_ide_do_suspend(ide_hwif_t *hwif)
pmif->timings[0] = 0;
pmif->timings[1] = 0;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- /* Note: This code will be called for every hwif, thus we'll
- * try several time to stop the LED blinker timer, but that
- * should be harmless
- */
- if (pmu_ide_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 /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
disable_irq(pmif->irq);
/* The media bay will handle itself just fine */
@@ -1374,13 +1256,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *p
hwif->selectproc = pmac_ide_selectproc;
hwif->speedproc = pmac_ide_tune_chipset;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- pmu_ide_blink_enabled = pmu_hd_blink_init();
-
- if (pmu_ide_blink_enabled)
- hwif->led_act = pmu_hd_kick_blink;
-#endif
-
printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
pmif->mediabay ? " (mediabay)" : "", hwif->irq);
--- linux-2.6.orig/drivers/macintosh/Kconfig 2006-04-28 13:31:24.347288704 +0200
+++ linux-2.6/drivers/macintosh/Kconfig 2006-04-28 13:31:43.677288704 +0200
@@ -78,6 +78,16 @@ config ADB_PMU
this device; you should do so if your machine is one of those
mentioned above.
+config ADB_PMU_LED
+ bool "Support for the Power/iBook front LED"
+ depends on LEDS_CLASS && ADB_PMU
+ help
+ Support the front LED on Power/iBooks as a generic LED that can
+ be triggered by any of the supported triggers. To get the
+ behaviour of the old CONFIG_BLK_DEV_IDE_PMAC_BLINK, select this
+ and the ide-disk LED trigger and configure appropriately through
+ sysfs.
+
config PMAC_SMU
bool "Support for SMU based PowerMacs"
depends on PPC_PMAC64
--- linux-2.6.orig/drivers/macintosh/Makefile 2006-04-28 13:35:17.977288704 +0200
+++ linux-2.6/drivers/macintosh/Makefile 2006-04-28 13:46:44.887288704 +0200
@@ -12,6 +12,7 @@ obj-$(CONFIG_INPUT_ADBHID) += adbhid.o
obj-$(CONFIG_ANSLCD) += ans-lcd.o
obj-$(CONFIG_ADB_PMU) += via-pmu.o
+obj-$(CONFIG_ADB_PMU_LED) += via-pmu-led.o
obj-$(CONFIG_ADB_CUDA) += via-cuda.o
obj-$(CONFIG_PMAC_APM_EMU) += apm_emu.o
obj-$(CONFIG_PMAC_SMU) += smu.o
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/drivers/macintosh/via-pmu-led.c 2006-04-28 13:56:28.537288704 +0200
@@ -0,0 +1,80 @@
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/leds.h>
+#include <linux/adb.h>
+#include <linux/pmu.h>
+#include <asm/prom.h>
+#include "via-pmu-led.h"
+
+static spinlock_t pmu_blink_lock;
+static struct adb_request pmu_blink_req;
+
+static void pmu_led_off(void)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ /* I currently ignore the result of this request */
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, 0);
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static void pmu_led_on(void)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, 1);
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static void pmu_led_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ switch (brightness) {
+ case LED_OFF:
+ pmu_led_off();
+ break;
+ case LED_FULL:
+ pmu_led_on();
+ break;
+ default:
+ /* ignore other levels */
+ break;
+ }
+}
+
+static struct led_classdev pmu_led = {
+ .name = "pmu-front-led",
+ .brightness_set = pmu_led_set,
+};
+
+int pmu_led_init(void)
+{
+ /* this is only called for keylargo based systems */
+ struct device_node *dt;
+ const char *model;
+
+ dt = of_find_node_by_path("/");
+ if (dt == NULL)
+ return -ENODEV;
+ model = (const char *)get_property(dt, "model", NULL);
+ if (model == NULL)
+ return -ENODEV;
+ if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
+ strncmp(model, "iBook", strlen("iBook")) != 0) {
+ of_node_put(dt);
+ /* silently ignore */
+ return 0;
+ }
+ of_node_put(dt);
+
+ spin_lock_init(&pmu_blink_lock);
+ return led_classdev_register(NULL, &pmu_led);
+}
+
+void pmu_led_exit(void)
+{
+ led_classdev_unregister(&pmu_led);
+}
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/drivers/macintosh/via-pmu-led.h 2006-04-28 13:48:19.177288704 +0200
@@ -0,0 +1,18 @@
+#ifndef __VIA_PMU_LED_H
+#define __VIA_PMU_LED_H
+#include <config/adb/pmu/led.h>
+
+#ifdef CONFIG_ADB_PMU_LED
+extern int pmu_led_init(void);
+extern void pmu_led_exit(void);
+#else
+static inline int pmu_led_init(void)
+{
+ return 0;
+}
+static inline void pmu_led_exit(void)
+{
+}
+#endif /* CONFIG_ADB_PMU_LED */
+
+#endif /* __VIA_PMU_LED_H */
--- linux-2.6.orig/drivers/macintosh/via-pmu.c 2006-04-28 13:09:02.197288704 +0200
+++ linux-2.6/drivers/macintosh/via-pmu.c 2006-04-28 15:58:45.497288704 +0200
@@ -69,6 +69,8 @@
#include <asm/open_pic.h>
#endif
+#include "via-pmu-led.h"
+
/* Some compile options */
#undef SUSPEND_USES_PMU
#define DEBUG_SLEEP
@@ -2896,11 +2898,25 @@ static int __init init_pmu_sysfs(void)
printk(KERN_ERR "Failed registering PMU sys driver\n");
return -ENODEV;
}
+
return 0;
}
subsys_initcall(init_pmu_sysfs);
+static int __init init_pmu_led(void)
+{
+ if (pmu_kind == PMU_KEYLARGO_BASED) {
+ if (pmu_led_init()) {
+ printk(KERN_WARNING "via-pmu: LED failed to init\n");
+ }
+ }
+
+ return 0;
+}
+
+late_initcall(init_pmu_led);
+
EXPORT_SYMBOL(pmu_request);
EXPORT_SYMBOL(pmu_queue_request);
EXPORT_SYMBOL(pmu_poll);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-04-28 14:49 Johannes Berg
@ 2006-04-28 15:15 ` Johannes Berg
2006-04-29 9:27 ` Johannes Berg
2006-05-01 6:56 ` Benjamin Herrenschmidt
0 siblings, 2 replies; 19+ messages in thread
From: Johannes Berg @ 2006-04-28 15:15 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev list, debian-powerpc
[resent slightly different patch that adds a comment over the original
version]
This patch removes the old pmac ide led blink code and
adds generic LED subsystem support for the LED.
Ben: I removed the retry code that was present in the original. I guess
LEDs aren't really too important but if it really is necessary please
tell me and I'll add it back.
Also, I don't have any suspend handling things. It doesn't appear to be
necessary, how do I find out?
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
--- linux-2.6.orig/drivers/ide/Kconfig 2006-04-28 13:13:38.777288704 +0200
+++ linux-2.6/drivers/ide/Kconfig 2006-04-28 13:13:48.797288704 +0200
@@ -773,13 +773,6 @@ config BLK_DEV_IDEDMA_PMAC
to transfer data to and from memory. Saying Y is safe and improves
performance.
-config BLK_DEV_IDE_PMAC_BLINK
- bool "Blink laptop LED on drive activity"
- depends on BLK_DEV_IDE_PMAC && ADB_PMU
- help
- This option enables the use of the sleep LED as a hard drive
- activity LED.
-
config BLK_DEV_IDE_SWARM
tristate "IDE for Sibyte evaluation boards"
depends on SIBYTE_SB1xxx_SOC
--- linux-2.6.orig/drivers/ide/ppc/pmac.c 2006-04-28 13:13:58.967288704 +0200
+++ linux-2.6/drivers/ide/ppc/pmac.c 2006-04-28 13:17:01.657288704 +0200
@@ -421,107 +421,6 @@ static void pmac_ide_kauai_selectproc(id
#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
/*
- * Below is the code for blinking the laptop LED along with hard
- * disk activity.
- */
-
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
-
-/* Set to 50ms minimum led-on time (also used to limit frequency
- * of requests sent to the PMU
- */
-#define PMU_HD_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_ide_blink_enabled;
-
-
-static void
-pmu_hd_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_HD_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_hd_kick_blink(void *data, int rw)
-{
- unsigned long flags;
-
- pmu_blink_stoptime = jiffies + PMU_HD_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_hd_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 = of_find_node_by_path("/");
- 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) {
- of_node_put(dt);
- return 0;
- }
- of_node_put(dt);
-
- 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_hd_blink_timeout;
-
- return 1;
-}
-
-#endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
-/*
* N.B. this can't be an initfunc, because the media-bay task can
* call ide_[un]register at any time.
*/
@@ -1190,23 +1089,6 @@ pmac_ide_do_suspend(ide_hwif_t *hwif)
pmif->timings[0] = 0;
pmif->timings[1] = 0;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- /* Note: This code will be called for every hwif, thus we'll
- * try several time to stop the LED blinker timer, but that
- * should be harmless
- */
- if (pmu_ide_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 /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
disable_irq(pmif->irq);
/* The media bay will handle itself just fine */
@@ -1374,13 +1256,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *p
hwif->selectproc = pmac_ide_selectproc;
hwif->speedproc = pmac_ide_tune_chipset;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- pmu_ide_blink_enabled = pmu_hd_blink_init();
-
- if (pmu_ide_blink_enabled)
- hwif->led_act = pmu_hd_kick_blink;
-#endif
-
printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
pmif->mediabay ? " (mediabay)" : "", hwif->irq);
--- linux-2.6.orig/drivers/macintosh/Kconfig 2006-04-28 13:31:24.347288704 +0200
+++ linux-2.6/drivers/macintosh/Kconfig 2006-04-28 13:31:43.677288704 +0200
@@ -78,6 +78,16 @@ config ADB_PMU
this device; you should do so if your machine is one of those
mentioned above.
+config ADB_PMU_LED
+ bool "Support for the Power/iBook front LED"
+ depends on LEDS_CLASS && ADB_PMU
+ help
+ Support the front LED on Power/iBooks as a generic LED that can
+ be triggered by any of the supported triggers. To get the
+ behaviour of the old CONFIG_BLK_DEV_IDE_PMAC_BLINK, select this
+ and the ide-disk LED trigger and configure appropriately through
+ sysfs.
+
config PMAC_SMU
bool "Support for SMU based PowerMacs"
depends on PPC_PMAC64
--- linux-2.6.orig/drivers/macintosh/Makefile 2006-04-28 13:35:17.977288704 +0200
+++ linux-2.6/drivers/macintosh/Makefile 2006-04-28 13:46:44.887288704 +0200
@@ -12,6 +12,7 @@ obj-$(CONFIG_INPUT_ADBHID) += adbhid.o
obj-$(CONFIG_ANSLCD) += ans-lcd.o
obj-$(CONFIG_ADB_PMU) += via-pmu.o
+obj-$(CONFIG_ADB_PMU_LED) += via-pmu-led.o
obj-$(CONFIG_ADB_CUDA) += via-cuda.o
obj-$(CONFIG_PMAC_APM_EMU) += apm_emu.o
obj-$(CONFIG_PMAC_SMU) += smu.o
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/drivers/macintosh/via-pmu-led.c 2006-04-28 13:56:28.537288704 +0200
@@ -0,0 +1,80 @@
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/leds.h>
+#include <linux/adb.h>
+#include <linux/pmu.h>
+#include <asm/prom.h>
+#include "via-pmu-led.h"
+
+static spinlock_t pmu_blink_lock;
+static struct adb_request pmu_blink_req;
+
+static void pmu_led_off(void)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ /* I currently ignore the result of this request */
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, 0);
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static void pmu_led_on(void)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, 1);
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static void pmu_led_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ switch (brightness) {
+ case LED_OFF:
+ pmu_led_off();
+ break;
+ case LED_FULL:
+ pmu_led_on();
+ break;
+ default:
+ /* ignore other levels */
+ break;
+ }
+}
+
+static struct led_classdev pmu_led = {
+ .name = "pmu-front-led",
+ .brightness_set = pmu_led_set,
+};
+
+int pmu_led_init(void)
+{
+ /* this is only called for keylargo based systems */
+ struct device_node *dt;
+ const char *model;
+
+ dt = of_find_node_by_path("/");
+ if (dt == NULL)
+ return -ENODEV;
+ model = (const char *)get_property(dt, "model", NULL);
+ if (model == NULL)
+ return -ENODEV;
+ if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
+ strncmp(model, "iBook", strlen("iBook")) != 0) {
+ of_node_put(dt);
+ /* silently ignore */
+ return 0;
+ }
+ of_node_put(dt);
+
+ spin_lock_init(&pmu_blink_lock);
+ return led_classdev_register(NULL, &pmu_led);
+}
+
+void pmu_led_exit(void)
+{
+ led_classdev_unregister(&pmu_led);
+}
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/drivers/macintosh/via-pmu-led.h 2006-04-28 13:48:19.177288704 +0200
@@ -0,0 +1,18 @@
+#ifndef __VIA_PMU_LED_H
+#define __VIA_PMU_LED_H
+#include <config/adb/pmu/led.h>
+
+#ifdef CONFIG_ADB_PMU_LED
+extern int pmu_led_init(void);
+extern void pmu_led_exit(void);
+#else
+static inline int pmu_led_init(void)
+{
+ return 0;
+}
+static inline void pmu_led_exit(void)
+{
+}
+#endif /* CONFIG_ADB_PMU_LED */
+
+#endif /* __VIA_PMU_LED_H */
--- linux-2.6.orig/drivers/macintosh/via-pmu.c 2006-04-28 13:09:02.197288704 +0200
+++ linux-2.6/drivers/macintosh/via-pmu.c 2006-04-28 16:55:57.877288704 +0200
@@ -69,6 +69,8 @@
#include <asm/open_pic.h>
#endif
+#include "via-pmu-led.h"
+
/* Some compile options */
#undef SUSPEND_USES_PMU
#define DEBUG_SLEEP
@@ -2896,11 +2898,30 @@ static int __init init_pmu_sysfs(void)
printk(KERN_ERR "Failed registering PMU sys driver\n");
return -ENODEV;
}
+
return 0;
}
subsys_initcall(init_pmu_sysfs);
+static int __init init_pmu_led(void)
+{
+ /* 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_kind == PMU_KEYLARGO_BASED) {
+ if (pmu_led_init()) {
+ printk(KERN_WARNING "via-pmu: LED failed to init\n");
+ }
+ }
+
+ return 0;
+}
+
+late_initcall(init_pmu_led);
+
EXPORT_SYMBOL(pmu_request);
EXPORT_SYMBOL(pmu_queue_request);
EXPORT_SYMBOL(pmu_poll);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-04-28 15:15 ` Johannes Berg
@ 2006-04-29 9:27 ` Johannes Berg
2006-05-01 6:56 ` Benjamin Herrenschmidt
1 sibling, 0 replies; 19+ messages in thread
From: Johannes Berg @ 2006-04-29 9:27 UTC (permalink / raw)
To: Benjamin Herrenschmidt
Cc: linuxppc-dev list, Richard Purdie, debian-powerpc, John Lenz
[-- Attachment #1: Type: text/plain, Size: 367 bytes --]
On Fri, 2006-04-28 at 17:15 +0200, Johannes Berg wrote:
>
> +config ADB_PMU_LED
> + bool "Support for the Power/iBook front LED"
> + depends on LEDS_CLASS && ADB_PMU
come to think of it, that should probably be
depends on ADB_PMU
select LEDS_CLASS
since we should imho consider the led stuff as infrastructure for other
stuff. Opinions?
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 793 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-04-28 15:15 ` Johannes Berg
2006-04-29 9:27 ` Johannes Berg
@ 2006-05-01 6:56 ` Benjamin Herrenschmidt
2006-05-01 8:59 ` Johannes Berg
1 sibling, 1 reply; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2006-05-01 6:56 UTC (permalink / raw)
To: Johannes Berg; +Cc: linuxppc-dev list, debian-powerpc
On Fri, 2006-04-28 at 17:15 +0200, Johannes Berg wrote:
> [resent slightly different patch that adds a comment over the original
> version]
>
> This patch removes the old pmac ide led blink code and
> adds generic LED subsystem support for the LED.
>
> Ben: I removed the retry code that was present in the original. I guess
> LEDs aren't really too important but if it really is necessary please
> tell me and I'll add it back.
>
> Also, I don't have any suspend handling things. It doesn't appear to be
> necessary, how do I find out?
Hrm... you find out the hard way in general ... we'll have to be careful
with this one, maybe have the PMU driver stop the LED after the device
suspend dance or do a sysdev with a suspend/resume and make sure that
any pending LED request is complete. Also, your code isn't testing if
the PMU request is still in progress before possibly sending another
one ... that's a bit dangerous (and may cause the LED to get "stuck").
You can re-use a request once it's complete though. In addition, my PMU
code was written to minimize spinlock usage in the hot path... There
might be a way to do the same here.
Ben.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-05-01 6:56 ` Benjamin Herrenschmidt
@ 2006-05-01 8:59 ` Johannes Berg
2006-05-01 9:10 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 19+ messages in thread
From: Johannes Berg @ 2006-05-01 8:59 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev list
[-- Attachment #1: Type: text/plain, Size: 1047 bytes --]
On Mon, 2006-05-01 at 16:56 +1000, Benjamin Herrenschmidt wrote:
> Hrm... you find out the hard way in general ... we'll have to be careful
> with this one, maybe have the PMU driver stop the LED after the device
> suspend dance or do a sysdev with a suspend/resume and make sure that
> any pending LED request is complete. Also, your code isn't testing if
> the PMU request is still in progress before possibly sending another
> one ... that's a bit dangerous (and may cause the LED to get "stuck").
> You can re-use a request once it's complete though. In addition, my PMU
> code was written to minimize spinlock usage in the hot path... There
> might be a way to do the same here.
I don't really understand how the PMU works hence wasn't really sure
what the whole request thing does. Do we get an interrupt when it
completes or something? If so, could I get at that notification via the
request structure?
I'll take a closer look and rework this, I think it's worthwhile even if
it requires some more effort.
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 793 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-05-01 8:59 ` Johannes Berg
@ 2006-05-01 9:10 ` Benjamin Herrenschmidt
2006-05-01 9:25 ` Johannes Berg
0 siblings, 1 reply; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2006-05-01 9:10 UTC (permalink / raw)
To: Johannes Berg; +Cc: linuxppc-dev list
On Mon, 2006-05-01 at 10:59 +0200, Johannes Berg wrote:
> On Mon, 2006-05-01 at 16:56 +1000, Benjamin Herrenschmidt wrote:
>
> > Hrm... you find out the hard way in general ... we'll have to be careful
> > with this one, maybe have the PMU driver stop the LED after the device
> > suspend dance or do a sysdev with a suspend/resume and make sure that
> > any pending LED request is complete. Also, your code isn't testing if
> > the PMU request is still in progress before possibly sending another
> > one ... that's a bit dangerous (and may cause the LED to get "stuck").
> > You can re-use a request once it's complete though. In addition, my PMU
> > code was written to minimize spinlock usage in the hot path... There
> > might be a way to do the same here.
>
> I don't really understand how the PMU works hence wasn't really sure
> what the whole request thing does. Do we get an interrupt when it
> completes or something? If so, could I get at that notification via the
> request structure?
Yes, there is a callback, that's the "done" function, but you can also
poll/check on request->complete though in this case, polling is not
recommended, the LED stuff should be as low latency as possible.
> I'll take a closer look and rework this, I think it's worthwhile even if
> it requires some more effort.
>
> johannes
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-05-01 9:10 ` Benjamin Herrenschmidt
@ 2006-05-01 9:25 ` Johannes Berg
2006-05-01 9:35 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 19+ messages in thread
From: Johannes Berg @ 2006-05-01 9:25 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev list
[-- Attachment #1: Type: text/plain, Size: 686 bytes --]
On Mon, 2006-05-01 at 19:10 +1000, Benjamin Herrenschmidt wrote:
> Yes, there is a callback, that's the "done" function, but you can also
> poll/check on request->complete though in this case, polling is not
> recommended, the LED stuff should be as low latency as possible.
I suppose then what I'll do is request a done callback, and when an LED
update comes in while not done, just save it into a new 'next state
should be' variable, which is compared when done so that at worst I
loose events, but not the final status.
Can I use pmu_request from within the done callback with the same
structure? Probably not a good idea right? I can schedule_work then.
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 793 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-05-01 9:25 ` Johannes Berg
@ 2006-05-01 9:35 ` Benjamin Herrenschmidt
2006-05-01 21:19 ` Johannes Berg
0 siblings, 1 reply; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2006-05-01 9:35 UTC (permalink / raw)
To: Johannes Berg; +Cc: linuxppc-dev list
On Mon, 2006-05-01 at 11:25 +0200, Johannes Berg wrote:
> On Mon, 2006-05-01 at 19:10 +1000, Benjamin Herrenschmidt wrote:
>
> > Yes, there is a callback, that's the "done" function, but you can also
> > poll/check on request->complete though in this case, polling is not
> > recommended, the LED stuff should be as low latency as possible.
>
> I suppose then what I'll do is request a done callback, and when an LED
> update comes in while not done, just save it into a new 'next state
> should be' variable, which is compared when done so that at worst I
> loose events, but not the final status.
>
> Can I use pmu_request from within the done callback with the same
> structure? Probably not a good idea right? I can schedule_work then.
No need to schedule work, it should work fine to re-queue
Ben.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-05-01 9:35 ` Benjamin Herrenschmidt
@ 2006-05-01 21:19 ` Johannes Berg
0 siblings, 0 replies; 19+ messages in thread
From: Johannes Berg @ 2006-05-01 21:19 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev list
On Mon, 2006-05-01 at 19:35 +1000, Benjamin Herrenschmidt wrote:
> No need to schedule work, it should work fine to re-queue
Untested because I haven't rebooted. Does this look good to you?
I don't see how I could get away without locking, especially with
handling the outstanding requests (though loosing one there might not be
too bad).
johannes
Index: wireless-dev/drivers/ide/Kconfig
===================================================================
--- wireless-dev.orig/drivers/ide/Kconfig 2006-04-30 22:17:49.201535187 +0200
+++ wireless-dev/drivers/ide/Kconfig 2006-04-30 22:17:51.911535187 +0200
@@ -773,13 +773,6 @@ config BLK_DEV_IDEDMA_PMAC
to transfer data to and from memory. Saying Y is safe and improves
performance.
-config BLK_DEV_IDE_PMAC_BLINK
- bool "Blink laptop LED on drive activity"
- depends on BLK_DEV_IDE_PMAC && ADB_PMU
- help
- This option enables the use of the sleep LED as a hard drive
- activity LED.
-
config BLK_DEV_IDE_SWARM
tristate "IDE for Sibyte evaluation boards"
depends on SIBYTE_SB1xxx_SOC
Index: wireless-dev/drivers/ide/ppc/pmac.c
===================================================================
--- wireless-dev.orig/drivers/ide/ppc/pmac.c 2006-04-30 22:17:49.221535187 +0200
+++ wireless-dev/drivers/ide/ppc/pmac.c 2006-04-30 22:17:51.911535187 +0200
@@ -421,107 +421,6 @@ static void pmac_ide_kauai_selectproc(id
#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
/*
- * Below is the code for blinking the laptop LED along with hard
- * disk activity.
- */
-
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
-
-/* Set to 50ms minimum led-on time (also used to limit frequency
- * of requests sent to the PMU
- */
-#define PMU_HD_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_ide_blink_enabled;
-
-
-static void
-pmu_hd_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_HD_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_hd_kick_blink(void *data, int rw)
-{
- unsigned long flags;
-
- pmu_blink_stoptime = jiffies + PMU_HD_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_hd_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 = of_find_node_by_path("/");
- 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) {
- of_node_put(dt);
- return 0;
- }
- of_node_put(dt);
-
- 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_hd_blink_timeout;
-
- return 1;
-}
-
-#endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
-/*
* N.B. this can't be an initfunc, because the media-bay task can
* call ide_[un]register at any time.
*/
@@ -1190,23 +1089,6 @@ pmac_ide_do_suspend(ide_hwif_t *hwif)
pmif->timings[0] = 0;
pmif->timings[1] = 0;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- /* Note: This code will be called for every hwif, thus we'll
- * try several time to stop the LED blinker timer, but that
- * should be harmless
- */
- if (pmu_ide_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 /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
disable_irq(pmif->irq);
/* The media bay will handle itself just fine */
@@ -1374,13 +1256,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *p
hwif->selectproc = pmac_ide_selectproc;
hwif->speedproc = pmac_ide_tune_chipset;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- pmu_ide_blink_enabled = pmu_hd_blink_init();
-
- if (pmu_ide_blink_enabled)
- hwif->led_act = pmu_hd_kick_blink;
-#endif
-
printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
pmif->mediabay ? " (mediabay)" : "", hwif->irq);
Index: wireless-dev/drivers/macintosh/Kconfig
===================================================================
--- wireless-dev.orig/drivers/macintosh/Kconfig 2006-04-30 22:17:49.301535187 +0200
+++ wireless-dev/drivers/macintosh/Kconfig 2006-05-01 22:39:34.951534234 +0200
@@ -78,6 +78,17 @@ config ADB_PMU
this device; you should do so if your machine is one of those
mentioned above.
+config ADB_PMU_LED
+ bool "Support for the Power/iBook front LED"
+ depends on ADB_PMU
+ select LEDS_CLASS
+ help
+ Support the front LED on Power/iBooks as a generic LED that can
+ be triggered by any of the supported triggers. To get the
+ behaviour of the old CONFIG_BLK_DEV_IDE_PMAC_BLINK, select this
+ and the ide-disk LED trigger and configure appropriately through
+ sysfs.
+
config PMAC_SMU
bool "Support for SMU based PowerMacs"
depends on PPC_PMAC64
Index: wireless-dev/drivers/macintosh/Makefile
===================================================================
--- wireless-dev.orig/drivers/macintosh/Makefile 2006-04-30 22:17:49.311535187 +0200
+++ wireless-dev/drivers/macintosh/Makefile 2006-05-01 22:36:32.871534234 +0200
@@ -12,6 +12,7 @@ obj-$(CONFIG_INPUT_ADBHID) += adbhid.o
obj-$(CONFIG_ANSLCD) += ans-lcd.o
obj-$(CONFIG_ADB_PMU) += via-pmu.o
+obj-$(CONFIG_ADB_PMU_LED) += via-pmu-led.o
obj-$(CONFIG_ADB_CUDA) += via-cuda.o
obj-$(CONFIG_PMAC_APM_EMU) += apm_emu.o
obj-$(CONFIG_PMAC_SMU) += smu.o
Index: wireless-dev/drivers/macintosh/via-pmu-led.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ wireless-dev/drivers/macintosh/via-pmu-led.c 2006-05-01 23:18:41.001534234 +0200
@@ -0,0 +1,120 @@
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/leds.h>
+#include <linux/adb.h>
+#include <linux/pmu.h>
+#include <asm/prom.h>
+
+static spinlock_t pmu_blink_lock;
+static struct adb_request pmu_blink_req;
+/* -1: no change, 0: request off, 1: request on */
+static int requested_change;
+static int sleeping;
+
+static void pmu_req_done(struct adb_request * req)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ /* if someone requested a change in the meantime
+ * (we only see the last one which is fine)
+ * then apply it now */
+ if (requested_change != -1 && !sleeping)
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
+ /* reset requested change */
+ requested_change = -1;
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static void pmu_led_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ switch (brightness) {
+ case LED_OFF:
+ requested_change = 0;
+ break;
+ case LED_FULL:
+ requested_change = 1;
+ break;
+ default:
+ goto out;
+ break;
+ }
+ /* if request isn't done, then don't do anything */
+ if (pmu_blink_req.complete && !sleeping)
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
+ out:
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static struct led_classdev pmu_led = {
+ .name = "pmu-front-led",
+ .brightness_set = pmu_led_set,
+};
+
+#ifdef CONFIG_PM
+static int pmu_led_sleep_call(struct pmu_sleep_notifier *self, int when)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+
+ switch (when) {
+ case PBOOK_SLEEP_REQUEST:
+ sleeping = 1;
+ break;
+ case PBOOK_WAKE:
+ sleeping = 0;
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+
+ return PBOOK_SLEEP_OK;
+}
+
+static struct pmu_sleep_notifier pmu_led_sleep_notif = {
+ .notifier_call = pmu_led_sleep_call,
+};
+#endif
+
+static __init int pmu_led_init(void)
+{
+ struct device_node *dt;
+ const char *model;
+
+ /* only do this on keylargo based models */
+ if (pmu_get_model() != PMU_KEYLARGO_BASED)
+ return -ENODEV;
+
+ dt = of_find_node_by_path("/");
+ if (dt == NULL)
+ return -ENODEV;
+ model = (const char *)get_property(dt, "model", NULL);
+ if (model == NULL)
+ return -ENODEV;
+ if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
+ strncmp(model, "iBook", strlen("iBook")) != 0) {
+ of_node_put(dt);
+ /* silently ignore */
+ return 0;
+ }
+ of_node_put(dt);
+
+ spin_lock_init(&pmu_blink_lock);
+ /* no outstanding req */
+ pmu_blink_req.complete = 1;
+ pmu_blink_req.done = pmu_req_done;
+#ifdef CONFIG_PM
+ pmu_register_sleep_notifier(&pmu_led_sleep_notif);
+#endif
+ return led_classdev_register(NULL, &pmu_led);
+}
+
+late_initcall(pmu_led_init);
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH] convert powermac ide blink to new led infrastructure
@ 2006-06-06 23:05 Johannes Berg
2006-06-08 0:28 ` Benjamin Herrenschmidt
2006-06-21 10:11 ` Johannes Berg
0 siblings, 2 replies; 19+ messages in thread
From: Johannes Berg @ 2006-06-06 23:05 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev list
Ben, all, do you have any further objections to this patch? Otherwise,
I'd like to see it queued for 2.6.18 through whoever should do that.
---
This patch removes the old pmac ide led blink code and adds generic LED
subsystem support for the LED.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
--- wireless-dev.orig/drivers/ide/Kconfig 2006-05-26 15:42:45.292052079 +0200
+++ wireless-dev/drivers/ide/Kconfig 2006-06-07 00:50:11.021517067 +0200
@@ -773,13 +773,6 @@ config BLK_DEV_IDEDMA_PMAC
to transfer data to and from memory. Saying Y is safe and improves
performance.
-config BLK_DEV_IDE_PMAC_BLINK
- bool "Blink laptop LED on drive activity"
- depends on BLK_DEV_IDE_PMAC && ADB_PMU
- help
- This option enables the use of the sleep LED as a hard drive
- activity LED.
-
config BLK_DEV_IDE_SWARM
tristate "IDE for Sibyte evaluation boards"
depends on SIBYTE_SB1xxx_SOC
--- wireless-dev.orig/drivers/ide/ppc/pmac.c 2006-05-26 15:42:45.322052079 +0200
+++ wireless-dev/drivers/ide/ppc/pmac.c 2006-06-07 00:50:11.231517067 +0200
@@ -421,107 +421,6 @@ static void pmac_ide_kauai_selectproc(id
#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
/*
- * Below is the code for blinking the laptop LED along with hard
- * disk activity.
- */
-
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
-
-/* Set to 50ms minimum led-on time (also used to limit frequency
- * of requests sent to the PMU
- */
-#define PMU_HD_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_ide_blink_enabled;
-
-
-static void
-pmu_hd_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_HD_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_hd_kick_blink(void *data, int rw)
-{
- unsigned long flags;
-
- pmu_blink_stoptime = jiffies + PMU_HD_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_hd_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 = of_find_node_by_path("/");
- 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) {
- of_node_put(dt);
- return 0;
- }
- of_node_put(dt);
-
- 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_hd_blink_timeout;
-
- return 1;
-}
-
-#endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
-/*
* N.B. this can't be an initfunc, because the media-bay task can
* call ide_[un]register at any time.
*/
@@ -1190,23 +1089,6 @@ pmac_ide_do_suspend(ide_hwif_t *hwif)
pmif->timings[0] = 0;
pmif->timings[1] = 0;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- /* Note: This code will be called for every hwif, thus we'll
- * try several time to stop the LED blinker timer, but that
- * should be harmless
- */
- if (pmu_ide_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 /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
disable_irq(pmif->irq);
/* The media bay will handle itself just fine */
@@ -1374,13 +1256,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *p
hwif->selectproc = pmac_ide_selectproc;
hwif->speedproc = pmac_ide_tune_chipset;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- pmu_ide_blink_enabled = pmu_hd_blink_init();
-
- if (pmu_ide_blink_enabled)
- hwif->led_act = pmu_hd_kick_blink;
-#endif
-
printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
pmif->mediabay ? " (mediabay)" : "", hwif->irq);
--- wireless-dev.orig/drivers/macintosh/Kconfig 2006-05-26 15:42:45.382052079 +0200
+++ wireless-dev/drivers/macintosh/Kconfig 2006-06-07 00:50:11.341517067 +0200
@@ -78,6 +78,17 @@ config ADB_PMU
this device; you should do so if your machine is one of those
mentioned above.
+config ADB_PMU_LED
+ bool "Support for the Power/iBook front LED"
+ depends on ADB_PMU
+ select LEDS_CLASS
+ help
+ Support the front LED on Power/iBooks as a generic LED that can
+ be triggered by any of the supported triggers. To get the
+ behaviour of the old CONFIG_BLK_DEV_IDE_PMAC_BLINK, select this
+ and the ide-disk LED trigger and configure appropriately through
+ sysfs.
+
config PMAC_SMU
bool "Support for SMU based PowerMacs"
depends on PPC_PMAC64
--- wireless-dev.orig/drivers/macintosh/Makefile 2006-05-26 15:42:45.442052079 +0200
+++ wireless-dev/drivers/macintosh/Makefile 2006-06-07 00:58:49.861517067 +0200
@@ -12,6 +12,7 @@ obj-$(CONFIG_INPUT_ADBHID) += adbhid.o
obj-$(CONFIG_ANSLCD) += ans-lcd.o
obj-$(CONFIG_ADB_PMU) += via-pmu.o
+obj-$(CONFIG_ADB_PMU_LED) += via-pmu-led.o
obj-$(CONFIG_ADB_CUDA) += via-cuda.o
obj-$(CONFIG_PMAC_APM_EMU) += apm_emu.o
obj-$(CONFIG_PMAC_SMU) += smu.o
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ wireless-dev/drivers/macintosh/via-pmu-led.c 2006-06-07 01:01:15.521517067 +0200
@@ -0,0 +1,141 @@
+/*
+ * via-pmu LED class device
+ *
+ * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/leds.h>
+#include <linux/adb.h>
+#include <linux/pmu.h>
+#include <asm/prom.h>
+
+static spinlock_t pmu_blink_lock;
+static struct adb_request pmu_blink_req;
+/* -1: no change, 0: request off, 1: request on */
+static int requested_change;
+static int sleeping;
+
+static void pmu_req_done(struct adb_request * req)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ /* if someone requested a change in the meantime
+ * (we only see the last one which is fine)
+ * then apply it now */
+ if (requested_change != -1 && !sleeping)
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
+ /* reset requested change */
+ requested_change = -1;
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static void pmu_led_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ switch (brightness) {
+ case LED_OFF:
+ requested_change = 0;
+ break;
+ case LED_FULL:
+ requested_change = 1;
+ break;
+ default:
+ goto out;
+ break;
+ }
+ /* if request isn't done, then don't do anything */
+ if (pmu_blink_req.complete && !sleeping)
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
+ out:
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static struct led_classdev pmu_led = {
+ .name = "pmu-front-led",
+ .brightness_set = pmu_led_set,
+};
+
+#ifdef CONFIG_PM
+static int pmu_led_sleep_call(struct pmu_sleep_notifier *self, int when)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+
+ switch (when) {
+ case PBOOK_SLEEP_REQUEST:
+ sleeping = 1;
+ break;
+ case PBOOK_WAKE:
+ sleeping = 0;
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+
+ return PBOOK_SLEEP_OK;
+}
+
+static struct pmu_sleep_notifier via_pmu_led_sleep_notif = {
+ .notifier_call = pmu_led_sleep_call,
+};
+#endif
+
+static int __init via_pmu_led_init(void)
+{
+ struct device_node *dt;
+ const char *model;
+
+ /* only do this on keylargo based models */
+ if (pmu_get_model() != PMU_KEYLARGO_BASED)
+ return -ENODEV;
+
+ dt = of_find_node_by_path("/");
+ if (dt == NULL)
+ return -ENODEV;
+ model = (const char *)get_property(dt, "model", NULL);
+ if (model == NULL)
+ return -ENODEV;
+ if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
+ strncmp(model, "iBook", strlen("iBook")) != 0) {
+ of_node_put(dt);
+ /* silently ignore */
+ return 0;
+ }
+ of_node_put(dt);
+
+ spin_lock_init(&pmu_blink_lock);
+ /* no outstanding req */
+ pmu_blink_req.complete = 1;
+ pmu_blink_req.done = pmu_req_done;
+#ifdef CONFIG_PM
+ pmu_register_sleep_notifier(&via_pmu_led_sleep_notif);
+#endif
+ return led_classdev_register(NULL, &pmu_led);
+}
+
+late_initcall(via_pmu_led_init);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-06-06 23:05 [PATCH] convert powermac ide blink to new led infrastructure Johannes Berg
@ 2006-06-08 0:28 ` Benjamin Herrenschmidt
2006-06-09 11:47 ` Johannes Berg
2006-06-21 10:11 ` Johannes Berg
1 sibling, 1 reply; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2006-06-08 0:28 UTC (permalink / raw)
To: Johannes Berg; +Cc: linuxppc-dev list
On Wed, 2006-06-07 at 01:05 +0200, Johannes Berg wrote:
> Ben, all, do you have any further objections to this patch? Otherwise,
> I'd like to see it queued for 2.6.18 through whoever should do that.
No objection, but a question: how do you bind the led to the hard disk
by default ? some userland stuff ? can't be automatic at boot by
default ?
Ben.
> ---
>
> This patch removes the old pmac ide led blink code and adds generic LED
> subsystem support for the LED.
>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
>
> --- wireless-dev.orig/drivers/ide/Kconfig 2006-05-26 15:42:45.292052079 +0200
> +++ wireless-dev/drivers/ide/Kconfig 2006-06-07 00:50:11.021517067 +0200
> @@ -773,13 +773,6 @@ config BLK_DEV_IDEDMA_PMAC
> to transfer data to and from memory. Saying Y is safe and improves
> performance.
>
> -config BLK_DEV_IDE_PMAC_BLINK
> - bool "Blink laptop LED on drive activity"
> - depends on BLK_DEV_IDE_PMAC && ADB_PMU
> - help
> - This option enables the use of the sleep LED as a hard drive
> - activity LED.
> -
> config BLK_DEV_IDE_SWARM
> tristate "IDE for Sibyte evaluation boards"
> depends on SIBYTE_SB1xxx_SOC
> --- wireless-dev.orig/drivers/ide/ppc/pmac.c 2006-05-26 15:42:45.322052079 +0200
> +++ wireless-dev/drivers/ide/ppc/pmac.c 2006-06-07 00:50:11.231517067 +0200
> @@ -421,107 +421,6 @@ static void pmac_ide_kauai_selectproc(id
> #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
>
> /*
> - * Below is the code for blinking the laptop LED along with hard
> - * disk activity.
> - */
> -
> -#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
> -
> -/* Set to 50ms minimum led-on time (also used to limit frequency
> - * of requests sent to the PMU
> - */
> -#define PMU_HD_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_ide_blink_enabled;
> -
> -
> -static void
> -pmu_hd_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_HD_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_hd_kick_blink(void *data, int rw)
> -{
> - unsigned long flags;
> -
> - pmu_blink_stoptime = jiffies + PMU_HD_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_hd_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 = of_find_node_by_path("/");
> - 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) {
> - of_node_put(dt);
> - return 0;
> - }
> - of_node_put(dt);
> -
> - 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_hd_blink_timeout;
> -
> - return 1;
> -}
> -
> -#endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
> -
> -/*
> * N.B. this can't be an initfunc, because the media-bay task can
> * call ide_[un]register at any time.
> */
> @@ -1190,23 +1089,6 @@ pmac_ide_do_suspend(ide_hwif_t *hwif)
> pmif->timings[0] = 0;
> pmif->timings[1] = 0;
>
> -#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
> - /* Note: This code will be called for every hwif, thus we'll
> - * try several time to stop the LED blinker timer, but that
> - * should be harmless
> - */
> - if (pmu_ide_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 /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
> -
> disable_irq(pmif->irq);
>
> /* The media bay will handle itself just fine */
> @@ -1374,13 +1256,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *p
> hwif->selectproc = pmac_ide_selectproc;
> hwif->speedproc = pmac_ide_tune_chipset;
>
> -#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
> - pmu_ide_blink_enabled = pmu_hd_blink_init();
> -
> - if (pmu_ide_blink_enabled)
> - hwif->led_act = pmu_hd_kick_blink;
> -#endif
> -
> printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
> hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
> pmif->mediabay ? " (mediabay)" : "", hwif->irq);
> --- wireless-dev.orig/drivers/macintosh/Kconfig 2006-05-26 15:42:45.382052079 +0200
> +++ wireless-dev/drivers/macintosh/Kconfig 2006-06-07 00:50:11.341517067 +0200
> @@ -78,6 +78,17 @@ config ADB_PMU
> this device; you should do so if your machine is one of those
> mentioned above.
>
> +config ADB_PMU_LED
> + bool "Support for the Power/iBook front LED"
> + depends on ADB_PMU
> + select LEDS_CLASS
> + help
> + Support the front LED on Power/iBooks as a generic LED that can
> + be triggered by any of the supported triggers. To get the
> + behaviour of the old CONFIG_BLK_DEV_IDE_PMAC_BLINK, select this
> + and the ide-disk LED trigger and configure appropriately through
> + sysfs.
> +
> config PMAC_SMU
> bool "Support for SMU based PowerMacs"
> depends on PPC_PMAC64
> --- wireless-dev.orig/drivers/macintosh/Makefile 2006-05-26 15:42:45.442052079 +0200
> +++ wireless-dev/drivers/macintosh/Makefile 2006-06-07 00:58:49.861517067 +0200
> @@ -12,6 +12,7 @@ obj-$(CONFIG_INPUT_ADBHID) += adbhid.o
> obj-$(CONFIG_ANSLCD) += ans-lcd.o
>
> obj-$(CONFIG_ADB_PMU) += via-pmu.o
> +obj-$(CONFIG_ADB_PMU_LED) += via-pmu-led.o
> obj-$(CONFIG_ADB_CUDA) += via-cuda.o
> obj-$(CONFIG_PMAC_APM_EMU) += apm_emu.o
> obj-$(CONFIG_PMAC_SMU) += smu.o
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ wireless-dev/drivers/macintosh/via-pmu-led.c 2006-06-07 01:01:15.521517067 +0200
> @@ -0,0 +1,141 @@
> +/*
> + * via-pmu LED class device
> + *
> + * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
> + * NON INFRINGEMENT. See the GNU General Public License for more
> + * details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + *
> + */
> +#include <linux/types.h>
> +#include <linux/kernel.h>
> +#include <linux/device.h>
> +#include <linux/leds.h>
> +#include <linux/adb.h>
> +#include <linux/pmu.h>
> +#include <asm/prom.h>
> +
> +static spinlock_t pmu_blink_lock;
> +static struct adb_request pmu_blink_req;
> +/* -1: no change, 0: request off, 1: request on */
> +static int requested_change;
> +static int sleeping;
> +
> +static void pmu_req_done(struct adb_request * req)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&pmu_blink_lock, flags);
> + /* if someone requested a change in the meantime
> + * (we only see the last one which is fine)
> + * then apply it now */
> + if (requested_change != -1 && !sleeping)
> + pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
> + /* reset requested change */
> + requested_change = -1;
> + spin_unlock_irqrestore(&pmu_blink_lock, flags);
> +}
> +
> +static void pmu_led_set(struct led_classdev *led_cdev,
> + enum led_brightness brightness)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&pmu_blink_lock, flags);
> + switch (brightness) {
> + case LED_OFF:
> + requested_change = 0;
> + break;
> + case LED_FULL:
> + requested_change = 1;
> + break;
> + default:
> + goto out;
> + break;
> + }
> + /* if request isn't done, then don't do anything */
> + if (pmu_blink_req.complete && !sleeping)
> + pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
> + out:
> + spin_unlock_irqrestore(&pmu_blink_lock, flags);
> +}
> +
> +static struct led_classdev pmu_led = {
> + .name = "pmu-front-led",
> + .brightness_set = pmu_led_set,
> +};
> +
> +#ifdef CONFIG_PM
> +static int pmu_led_sleep_call(struct pmu_sleep_notifier *self, int when)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&pmu_blink_lock, flags);
> +
> + switch (when) {
> + case PBOOK_SLEEP_REQUEST:
> + sleeping = 1;
> + break;
> + case PBOOK_WAKE:
> + sleeping = 0;
> + break;
> + default:
> + /* do nothing */
> + break;
> + }
> + spin_unlock_irqrestore(&pmu_blink_lock, flags);
> +
> + return PBOOK_SLEEP_OK;
> +}
> +
> +static struct pmu_sleep_notifier via_pmu_led_sleep_notif = {
> + .notifier_call = pmu_led_sleep_call,
> +};
> +#endif
> +
> +static int __init via_pmu_led_init(void)
> +{
> + struct device_node *dt;
> + const char *model;
> +
> + /* only do this on keylargo based models */
> + if (pmu_get_model() != PMU_KEYLARGO_BASED)
> + return -ENODEV;
> +
> + dt = of_find_node_by_path("/");
> + if (dt == NULL)
> + return -ENODEV;
> + model = (const char *)get_property(dt, "model", NULL);
> + if (model == NULL)
> + return -ENODEV;
> + if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
> + strncmp(model, "iBook", strlen("iBook")) != 0) {
> + of_node_put(dt);
> + /* silently ignore */
> + return 0;
> + }
> + of_node_put(dt);
> +
> + spin_lock_init(&pmu_blink_lock);
> + /* no outstanding req */
> + pmu_blink_req.complete = 1;
> + pmu_blink_req.done = pmu_req_done;
> +#ifdef CONFIG_PM
> + pmu_register_sleep_notifier(&via_pmu_led_sleep_notif);
> +#endif
> + return led_classdev_register(NULL, &pmu_led);
> +}
> +
> +late_initcall(via_pmu_led_init);
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-06-08 0:28 ` Benjamin Herrenschmidt
@ 2006-06-09 11:47 ` Johannes Berg
2006-06-09 11:56 ` Anton Blanchard
0 siblings, 1 reply; 19+ messages in thread
From: Johannes Berg @ 2006-06-09 11:47 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev list
[-- Attachment #1: Type: text/plain, Size: 591 bytes --]
On Thu, 2006-06-08 at 10:28 +1000, Benjamin Herrenschmidt wrote:
> No objection, but a question: how do you bind the led to the hard disk
> by default ? some userland stuff ? can't be automatic at boot by
> default ?
The way it usually works is via sysfs. Automatic at boot could be
default by assigning a default name somewhere IIRC, but since I don't
use the LED I optimised for that case ;)
I'd say having a script that *enables* it at boot is probably cleaner
than having one that *disables* it, and having a Kconfig option just for
the default seems overkill.
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 793 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-06-09 11:47 ` Johannes Berg
@ 2006-06-09 11:56 ` Anton Blanchard
2006-06-09 12:01 ` Johannes Berg
0 siblings, 1 reply; 19+ messages in thread
From: Anton Blanchard @ 2006-06-09 11:56 UTC (permalink / raw)
To: Johannes Berg; +Cc: linuxppc-dev list
> The way it usually works is via sysfs. Automatic at boot could be
> default by assigning a default name somewhere IIRC, but since I don't
> use the LED I optimised for that case ;)
> I'd say having a script that *enables* it at boot is probably cleaner
> than having one that *disables* it, and having a Kconfig option just for
> the default seems overkill.
On the other hand, Ive come to expect it on my laptop :)
Anton
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-06-09 11:56 ` Anton Blanchard
@ 2006-06-09 12:01 ` Johannes Berg
0 siblings, 0 replies; 19+ messages in thread
From: Johannes Berg @ 2006-06-09 12:01 UTC (permalink / raw)
To: Anton Blanchard; +Cc: linuxppc-dev list
[-- Attachment #1: Type: text/plain, Size: 441 bytes --]
On Fri, 2006-06-09 at 21:56 +1000, Anton Blanchard wrote:
> On the other hand, Ive come to expect it on my laptop :)
With my patch, just put
echo -n ide-disk > /sys/class/leds/pmu-front-led/trigger
into some startup script then :)
Do we really want the old Kconfig option in there selecting the new led
option, the ide-disk trigger and modifying the code to make this the
default trigger for the LED? I mean...
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 793 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH] convert powermac ide blink to new led infrastructure
2006-06-06 23:05 [PATCH] convert powermac ide blink to new led infrastructure Johannes Berg
2006-06-08 0:28 ` Benjamin Herrenschmidt
@ 2006-06-21 10:11 ` Johannes Berg
2006-06-27 7:50 ` Benjamin Herrenschmidt
1 sibling, 1 reply; 19+ messages in thread
From: Johannes Berg @ 2006-06-21 10:11 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev list
This should address all the objections you voiced: it now is backward
compatible with the old (and now deprecated) Kconfig option by using a
bunch of select Kconfig statements and adding a single line of code in
#ifdef :)
Please pass on for 2.6.18.
---
This patch removes the old pmac ide led blink code and
adds generic LED subsystem support for the LED.
It maintains backward compatibility with the old
BLK_DEV_IDE_PMAC_BLINK Kconfig option which now
simply selects the new code and influences the
default trigger.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
--- linux-2.6.orig/drivers/ide/Kconfig 2006-06-20 16:56:01.589161721 +0200
+++ linux-2.6/drivers/ide/Kconfig 2006-06-21 12:02:08.878721123 +0200
@@ -774,11 +774,18 @@ config BLK_DEV_IDEDMA_PMAC
performance.
config BLK_DEV_IDE_PMAC_BLINK
- bool "Blink laptop LED on drive activity"
+ bool "Blink laptop LED on drive activity (DEPRECATED)"
depends on BLK_DEV_IDE_PMAC && ADB_PMU
+ select ADB_PMU_LED
+ select LEDS_TRIGGERS
+ select LEDS_TRIGGER_IDE_DISK
help
This option enables the use of the sleep LED as a hard drive
activity LED.
+ This option is deprecated, it only selects ADB_PMU_LED and
+ LEDS_TRIGGER_IDE_DISK and changes the code in the new led class
+ device to default to the ide-disk trigger (which should be set
+ from userspace via sysfs).
config BLK_DEV_IDE_SWARM
tristate "IDE for Sibyte evaluation boards"
--- linux-2.6.orig/drivers/ide/ppc/pmac.c 2006-06-20 16:56:01.659161721 +0200
+++ linux-2.6/drivers/ide/ppc/pmac.c 2006-06-20 16:56:03.219161721 +0200
@@ -421,107 +421,6 @@ static void pmac_ide_kauai_selectproc(id
#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
/*
- * Below is the code for blinking the laptop LED along with hard
- * disk activity.
- */
-
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
-
-/* Set to 50ms minimum led-on time (also used to limit frequency
- * of requests sent to the PMU
- */
-#define PMU_HD_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_ide_blink_enabled;
-
-
-static void
-pmu_hd_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_HD_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_hd_kick_blink(void *data, int rw)
-{
- unsigned long flags;
-
- pmu_blink_stoptime = jiffies + PMU_HD_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_hd_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 = of_find_node_by_path("/");
- 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) {
- of_node_put(dt);
- return 0;
- }
- of_node_put(dt);
-
- 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_hd_blink_timeout;
-
- return 1;
-}
-
-#endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
-/*
* N.B. this can't be an initfunc, because the media-bay task can
* call ide_[un]register at any time.
*/
@@ -1192,23 +1091,6 @@ pmac_ide_do_suspend(ide_hwif_t *hwif)
pmif->timings[0] = 0;
pmif->timings[1] = 0;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- /* Note: This code will be called for every hwif, thus we'll
- * try several time to stop the LED blinker timer, but that
- * should be harmless
- */
- if (pmu_ide_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 /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
-
disable_irq(pmif->irq);
/* The media bay will handle itself just fine */
@@ -1376,13 +1258,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *p
hwif->selectproc = pmac_ide_selectproc;
hwif->speedproc = pmac_ide_tune_chipset;
-#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
- pmu_ide_blink_enabled = pmu_hd_blink_init();
-
- if (pmu_ide_blink_enabled)
- hwif->led_act = pmu_hd_kick_blink;
-#endif
-
printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
pmif->mediabay ? " (mediabay)" : "", hwif->irq);
--- linux-2.6.orig/drivers/macintosh/Kconfig 2006-06-20 16:56:01.689161721 +0200
+++ linux-2.6/drivers/macintosh/Kconfig 2006-06-20 16:56:03.219161721 +0200
@@ -78,6 +78,17 @@ config ADB_PMU
this device; you should do so if your machine is one of those
mentioned above.
+config ADB_PMU_LED
+ bool "Support for the Power/iBook front LED"
+ depends on ADB_PMU
+ select LEDS_CLASS
+ help
+ Support the front LED on Power/iBooks as a generic LED that can
+ be triggered by any of the supported triggers. To get the
+ behaviour of the old CONFIG_BLK_DEV_IDE_PMAC_BLINK, select this
+ and the ide-disk LED trigger and configure appropriately through
+ sysfs.
+
config PMAC_SMU
bool "Support for SMU based PowerMacs"
depends on PPC_PMAC64
--- linux-2.6.orig/drivers/macintosh/Makefile 2006-06-20 16:56:01.729161721 +0200
+++ linux-2.6/drivers/macintosh/Makefile 2006-06-21 11:49:11.698721123 +0200
@@ -12,6 +12,7 @@ obj-$(CONFIG_INPUT_ADBHID) += adbhid.o
obj-$(CONFIG_ANSLCD) += ans-lcd.o
obj-$(CONFIG_ADB_PMU) += via-pmu.o
+obj-$(CONFIG_ADB_PMU_LED) += via-pmu-led.o
obj-$(CONFIG_ADB_CUDA) += via-cuda.o
obj-$(CONFIG_PMAC_APM_EMU) += apm_emu.o
obj-$(CONFIG_PMAC_SMU) += smu.o
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/drivers/macintosh/via-pmu-led.c 2006-06-21 12:09:50.778721123 +0200
@@ -0,0 +1,144 @@
+/*
+ * via-pmu LED class device
+ *
+ * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/leds.h>
+#include <linux/adb.h>
+#include <linux/pmu.h>
+#include <asm/prom.h>
+
+static spinlock_t pmu_blink_lock;
+static struct adb_request pmu_blink_req;
+/* -1: no change, 0: request off, 1: request on */
+static int requested_change;
+static int sleeping;
+
+static void pmu_req_done(struct adb_request * req)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ /* if someone requested a change in the meantime
+ * (we only see the last one which is fine)
+ * then apply it now */
+ if (requested_change != -1 && !sleeping)
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
+ /* reset requested change */
+ requested_change = -1;
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static void pmu_led_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+ switch (brightness) {
+ case LED_OFF:
+ requested_change = 0;
+ break;
+ case LED_FULL:
+ requested_change = 1;
+ break;
+ default:
+ goto out;
+ break;
+ }
+ /* if request isn't done, then don't do anything */
+ if (pmu_blink_req.complete && !sleeping)
+ pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
+ out:
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+}
+
+static struct led_classdev pmu_led = {
+ .name = "pmu-front-led",
+#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
+ .default_trigger = "ide-disk",
+#endif
+ .brightness_set = pmu_led_set,
+};
+
+#ifdef CONFIG_PM
+static int pmu_led_sleep_call(struct pmu_sleep_notifier *self, int when)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&pmu_blink_lock, flags);
+
+ switch (when) {
+ case PBOOK_SLEEP_REQUEST:
+ sleeping = 1;
+ break;
+ case PBOOK_WAKE:
+ sleeping = 0;
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
+ spin_unlock_irqrestore(&pmu_blink_lock, flags);
+
+ return PBOOK_SLEEP_OK;
+}
+
+static struct pmu_sleep_notifier via_pmu_led_sleep_notif = {
+ .notifier_call = pmu_led_sleep_call,
+};
+#endif
+
+static int __init via_pmu_led_init(void)
+{
+ struct device_node *dt;
+ const char *model;
+
+ /* only do this on keylargo based models */
+ if (pmu_get_model() != PMU_KEYLARGO_BASED)
+ return -ENODEV;
+
+ dt = of_find_node_by_path("/");
+ if (dt == NULL)
+ return -ENODEV;
+ model = (const char *)get_property(dt, "model", NULL);
+ if (model == NULL)
+ return -ENODEV;
+ if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
+ strncmp(model, "iBook", strlen("iBook")) != 0) {
+ of_node_put(dt);
+ /* ignore */
+ return -ENODEV;
+ }
+ of_node_put(dt);
+
+ spin_lock_init(&pmu_blink_lock);
+ /* no outstanding req */
+ pmu_blink_req.complete = 1;
+ pmu_blink_req.done = pmu_req_done;
+#ifdef CONFIG_PM
+ pmu_register_sleep_notifier(&via_pmu_led_sleep_notif);
+#endif
+ return led_classdev_register(NULL, &pmu_led);
+}
+
+late_initcall(via_pmu_led_init);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-06-21 10:11 ` Johannes Berg
@ 2006-06-27 7:50 ` Benjamin Herrenschmidt
2006-06-27 17:31 ` Johannes Berg
0 siblings, 1 reply; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2006-06-27 7:50 UTC (permalink / raw)
To: Johannes Berg; +Cc: linuxppc-dev list
On Wed, 2006-06-21 at 12:11 +0200, Johannes Berg wrote:
> This should address all the objections you voiced: it now is backward
> compatible with the old (and now deprecated) Kconfig option by using a
> bunch of select Kconfig statements and adding a single line of code in
> #ifdef :)
>
> Please pass on for 2.6.18.
Looks good. Only one nit: in pmu_led_set(), you should be able to test
if the requested state is identical to the current one and do nothing
without taking the lock no ?
Or does the upper level LED infrastructure takes care of it ?
Ben.
> ---
> This patch removes the old pmac ide led blink code and
> adds generic LED subsystem support for the LED.
>
> It maintains backward compatibility with the old
> BLK_DEV_IDE_PMAC_BLINK Kconfig option which now
> simply selects the new code and influences the
> default trigger.
>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
>
> --- linux-2.6.orig/drivers/ide/Kconfig 2006-06-20 16:56:01.589161721 +0200
> +++ linux-2.6/drivers/ide/Kconfig 2006-06-21 12:02:08.878721123 +0200
> @@ -774,11 +774,18 @@ config BLK_DEV_IDEDMA_PMAC
> performance.
>
> config BLK_DEV_IDE_PMAC_BLINK
> - bool "Blink laptop LED on drive activity"
> + bool "Blink laptop LED on drive activity (DEPRECATED)"
> depends on BLK_DEV_IDE_PMAC && ADB_PMU
> + select ADB_PMU_LED
> + select LEDS_TRIGGERS
> + select LEDS_TRIGGER_IDE_DISK
> help
> This option enables the use of the sleep LED as a hard drive
> activity LED.
> + This option is deprecated, it only selects ADB_PMU_LED and
> + LEDS_TRIGGER_IDE_DISK and changes the code in the new led class
> + device to default to the ide-disk trigger (which should be set
> + from userspace via sysfs).
>
> config BLK_DEV_IDE_SWARM
> tristate "IDE for Sibyte evaluation boards"
> --- linux-2.6.orig/drivers/ide/ppc/pmac.c 2006-06-20 16:56:01.659161721 +0200
> +++ linux-2.6/drivers/ide/ppc/pmac.c 2006-06-20 16:56:03.219161721 +0200
> @@ -421,107 +421,6 @@ static void pmac_ide_kauai_selectproc(id
> #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
>
> /*
> - * Below is the code for blinking the laptop LED along with hard
> - * disk activity.
> - */
> -
> -#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
> -
> -/* Set to 50ms minimum led-on time (also used to limit frequency
> - * of requests sent to the PMU
> - */
> -#define PMU_HD_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_ide_blink_enabled;
> -
> -
> -static void
> -pmu_hd_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_HD_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_hd_kick_blink(void *data, int rw)
> -{
> - unsigned long flags;
> -
> - pmu_blink_stoptime = jiffies + PMU_HD_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_hd_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 = of_find_node_by_path("/");
> - 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) {
> - of_node_put(dt);
> - return 0;
> - }
> - of_node_put(dt);
> -
> - 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_hd_blink_timeout;
> -
> - return 1;
> -}
> -
> -#endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
> -
> -/*
> * N.B. this can't be an initfunc, because the media-bay task can
> * call ide_[un]register at any time.
> */
> @@ -1192,23 +1091,6 @@ pmac_ide_do_suspend(ide_hwif_t *hwif)
> pmif->timings[0] = 0;
> pmif->timings[1] = 0;
>
> -#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
> - /* Note: This code will be called for every hwif, thus we'll
> - * try several time to stop the LED blinker timer, but that
> - * should be harmless
> - */
> - if (pmu_ide_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 /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
> -
> disable_irq(pmif->irq);
>
> /* The media bay will handle itself just fine */
> @@ -1376,13 +1258,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *p
> hwif->selectproc = pmac_ide_selectproc;
> hwif->speedproc = pmac_ide_tune_chipset;
>
> -#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
> - pmu_ide_blink_enabled = pmu_hd_blink_init();
> -
> - if (pmu_ide_blink_enabled)
> - hwif->led_act = pmu_hd_kick_blink;
> -#endif
> -
> printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
> hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
> pmif->mediabay ? " (mediabay)" : "", hwif->irq);
> --- linux-2.6.orig/drivers/macintosh/Kconfig 2006-06-20 16:56:01.689161721 +0200
> +++ linux-2.6/drivers/macintosh/Kconfig 2006-06-20 16:56:03.219161721 +0200
> @@ -78,6 +78,17 @@ config ADB_PMU
> this device; you should do so if your machine is one of those
> mentioned above.
>
> +config ADB_PMU_LED
> + bool "Support for the Power/iBook front LED"
> + depends on ADB_PMU
> + select LEDS_CLASS
> + help
> + Support the front LED on Power/iBooks as a generic LED that can
> + be triggered by any of the supported triggers. To get the
> + behaviour of the old CONFIG_BLK_DEV_IDE_PMAC_BLINK, select this
> + and the ide-disk LED trigger and configure appropriately through
> + sysfs.
> +
> config PMAC_SMU
> bool "Support for SMU based PowerMacs"
> depends on PPC_PMAC64
> --- linux-2.6.orig/drivers/macintosh/Makefile 2006-06-20 16:56:01.729161721 +0200
> +++ linux-2.6/drivers/macintosh/Makefile 2006-06-21 11:49:11.698721123 +0200
> @@ -12,6 +12,7 @@ obj-$(CONFIG_INPUT_ADBHID) += adbhid.o
> obj-$(CONFIG_ANSLCD) += ans-lcd.o
>
> obj-$(CONFIG_ADB_PMU) += via-pmu.o
> +obj-$(CONFIG_ADB_PMU_LED) += via-pmu-led.o
> obj-$(CONFIG_ADB_CUDA) += via-cuda.o
> obj-$(CONFIG_PMAC_APM_EMU) += apm_emu.o
> obj-$(CONFIG_PMAC_SMU) += smu.o
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ linux-2.6/drivers/macintosh/via-pmu-led.c 2006-06-21 12:09:50.778721123 +0200
> @@ -0,0 +1,144 @@
> +/*
> + * via-pmu LED class device
> + *
> + * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
> + * NON INFRINGEMENT. See the GNU General Public License for more
> + * details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + *
> + */
> +#include <linux/types.h>
> +#include <linux/kernel.h>
> +#include <linux/device.h>
> +#include <linux/leds.h>
> +#include <linux/adb.h>
> +#include <linux/pmu.h>
> +#include <asm/prom.h>
> +
> +static spinlock_t pmu_blink_lock;
> +static struct adb_request pmu_blink_req;
> +/* -1: no change, 0: request off, 1: request on */
> +static int requested_change;
> +static int sleeping;
> +
> +static void pmu_req_done(struct adb_request * req)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&pmu_blink_lock, flags);
> + /* if someone requested a change in the meantime
> + * (we only see the last one which is fine)
> + * then apply it now */
> + if (requested_change != -1 && !sleeping)
> + pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
> + /* reset requested change */
> + requested_change = -1;
> + spin_unlock_irqrestore(&pmu_blink_lock, flags);
> +}
> +
> +static void pmu_led_set(struct led_classdev *led_cdev,
> + enum led_brightness brightness)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&pmu_blink_lock, flags);
> + switch (brightness) {
> + case LED_OFF:
> + requested_change = 0;
> + break;
> + case LED_FULL:
> + requested_change = 1;
> + break;
> + default:
> + goto out;
> + break;
> + }
> + /* if request isn't done, then don't do anything */
> + if (pmu_blink_req.complete && !sleeping)
> + pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
> + out:
> + spin_unlock_irqrestore(&pmu_blink_lock, flags);
> +}
> +
> +static struct led_classdev pmu_led = {
> + .name = "pmu-front-led",
> +#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
> + .default_trigger = "ide-disk",
> +#endif
> + .brightness_set = pmu_led_set,
> +};
> +
> +#ifdef CONFIG_PM
> +static int pmu_led_sleep_call(struct pmu_sleep_notifier *self, int when)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&pmu_blink_lock, flags);
> +
> + switch (when) {
> + case PBOOK_SLEEP_REQUEST:
> + sleeping = 1;
> + break;
> + case PBOOK_WAKE:
> + sleeping = 0;
> + break;
> + default:
> + /* do nothing */
> + break;
> + }
> + spin_unlock_irqrestore(&pmu_blink_lock, flags);
> +
> + return PBOOK_SLEEP_OK;
> +}
> +
> +static struct pmu_sleep_notifier via_pmu_led_sleep_notif = {
> + .notifier_call = pmu_led_sleep_call,
> +};
> +#endif
> +
> +static int __init via_pmu_led_init(void)
> +{
> + struct device_node *dt;
> + const char *model;
> +
> + /* only do this on keylargo based models */
> + if (pmu_get_model() != PMU_KEYLARGO_BASED)
> + return -ENODEV;
> +
> + dt = of_find_node_by_path("/");
> + if (dt == NULL)
> + return -ENODEV;
> + model = (const char *)get_property(dt, "model", NULL);
> + if (model == NULL)
> + return -ENODEV;
> + if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
> + strncmp(model, "iBook", strlen("iBook")) != 0) {
> + of_node_put(dt);
> + /* ignore */
> + return -ENODEV;
> + }
> + of_node_put(dt);
> +
> + spin_lock_init(&pmu_blink_lock);
> + /* no outstanding req */
> + pmu_blink_req.complete = 1;
> + pmu_blink_req.done = pmu_req_done;
> +#ifdef CONFIG_PM
> + pmu_register_sleep_notifier(&via_pmu_led_sleep_notif);
> +#endif
> + return led_classdev_register(NULL, &pmu_led);
> +}
> +
> +late_initcall(via_pmu_led_init);
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-06-27 7:50 ` Benjamin Herrenschmidt
@ 2006-06-27 17:31 ` Johannes Berg
2006-06-28 9:38 ` Richard Purdie
0 siblings, 1 reply; 19+ messages in thread
From: Johannes Berg @ 2006-06-27 17:31 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev list, Richard Purdie
[-- Attachment #1: Type: text/plain, Size: 317 bytes --]
> Looks good. Only one nit: in pmu_led_set(), you should be able to test
> if the requested state is identical to the current one and do nothing
> without taking the lock no ?
>
> Or does the upper level LED infrastructure takes care of it ?
I don't know, Richard? But yeah, I can do that too.
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 793 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-06-27 17:31 ` Johannes Berg
@ 2006-06-28 9:38 ` Richard Purdie
2006-06-28 9:43 ` Johannes Berg
0 siblings, 1 reply; 19+ messages in thread
From: Richard Purdie @ 2006-06-28 9:38 UTC (permalink / raw)
To: Johannes Berg; +Cc: linuxppc-dev list
On Tue, 2006-06-27 at 19:31 +0200, Johannes Berg wrote:
> > Looks good. Only one nit: in pmu_led_set(), you should be able to test
> > if the requested state is identical to the current one and do nothing
> > without taking the lock no ?
> >
> > Or does the upper level LED infrastructure takes care of it ?
>
> I don't know, Richard? But yeah, I can do that too.
The core doesn't do that. In some cases setting the LED is easier and
cheaper than checking a cached value. If setting the LED state is
expensive, it would be simple enough to implement value caching in the
driver.
Part of the problem is also that we provide several values to the driver
(brightness, power, blanking, device specific parameters) and it needs
to combine those values in a way that is only meaningful to the specific
driver.
Richard
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] convert powermac ide blink to new led infrastructure
2006-06-28 9:38 ` Richard Purdie
@ 2006-06-28 9:43 ` Johannes Berg
0 siblings, 0 replies; 19+ messages in thread
From: Johannes Berg @ 2006-06-28 9:43 UTC (permalink / raw)
To: Richard Purdie; +Cc: linuxppc-dev list
[-- Attachment #1: Type: text/plain, Size: 97 bytes --]
Richard,
Thanks for the explanation. I'll respin the patch to implement caching.
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 793 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2006-06-28 9:56 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-06 23:05 [PATCH] convert powermac ide blink to new led infrastructure Johannes Berg
2006-06-08 0:28 ` Benjamin Herrenschmidt
2006-06-09 11:47 ` Johannes Berg
2006-06-09 11:56 ` Anton Blanchard
2006-06-09 12:01 ` Johannes Berg
2006-06-21 10:11 ` Johannes Berg
2006-06-27 7:50 ` Benjamin Herrenschmidt
2006-06-27 17:31 ` Johannes Berg
2006-06-28 9:38 ` Richard Purdie
2006-06-28 9:43 ` Johannes Berg
-- strict thread matches above, loose matches on Subject: below --
2006-04-28 14:49 Johannes Berg
2006-04-28 15:15 ` Johannes Berg
2006-04-29 9:27 ` Johannes Berg
2006-05-01 6:56 ` Benjamin Herrenschmidt
2006-05-01 8:59 ` Johannes Berg
2006-05-01 9:10 ` Benjamin Herrenschmidt
2006-05-01 9:25 ` Johannes Berg
2006-05-01 9:35 ` Benjamin Herrenschmidt
2006-05-01 21:19 ` Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).