[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Hard Drive light



According to Benjamin Herrenschmidt, on Sat, 04 Dec 2004 09:22:36 +1100, 
>On Fri, 2004-12-03 at 10:53 +0100, Jens Schmalzing wrote:
>> Hi,
>> 
>> Benjamin Herrenschmidt writes:
>> 
>> > Any reason why it's disabled ?
>> 
>> When it was off, people asked for it to be on.  When it was on, others
>> asked for it to be off.  Eventually, we even got a bug report and then
>> turned it off for good and put an entry into the changelog.
>> 
>
>Oh well, I'd gladly accept a patch adding some entry in sysfs to control
>the behaviour :)
>
>Ben.
>

I attach a very small patch doing that. This a patch only for drivers/ide/ppc/pmac.c file,
with respect to a pure kernel 2.6.9 from kernel.org

It adds an entry in /sys/devices/ide-pmac/blinking_led
echo 1 > /sys/devices/ide-pmac/blinking_led
activates the led

echo 0 > /sys/devices/ide-pmac/blinking_led
disactivates it

It starts disactivated.

I could not find any place to put the code for removing the sysfs entry. Anyway I guess,
this file cannot be compiled as a module, and so cannot be removed. So this should not be
a problem.

Regards,
-- 
Cedric Pradalier
--- pmac.c.old	2004-12-05 23:58:25.274167448 +1100
+++ pmac.c	2004-12-05 23:55:29.458895432 +1100
@@ -35,6 +35,11 @@
 #include <linux/adb.h>
 #include <linux/pmu.h>
 
+#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK
+#include <linux/device.h>
+#include <asm/of_device.h>
+#endif
+
 #include <asm/prom.h>
 #include <asm/io.h>
 #include <asm/dbdma.h>
@@ -381,8 +386,9 @@
 static spinlock_t pmu_blink_lock;
 static unsigned long pmu_blink_stoptime;
 static int pmu_blink_ledstate;
+static int pmu_blink_led_activated = 0;
 static struct timer_list pmu_blink_timer;
-static int pmu_ide_blink_enabled;
+static int pmu_ide_blink_enabled = 0;
 
 
 static void
@@ -413,6 +419,8 @@
 pmu_hd_kick_blink(void *data, int rw)
 {
 	unsigned long flags;
+	if (!pmu_blink_led_activated)
+		return;
 	
 	pmu_blink_stoptime = jiffies + PMU_HD_BLINK_TIME;
 	wmb();
@@ -428,9 +436,32 @@
 	spin_unlock_irqrestore(&pmu_blink_lock, flags);
 }
 
+static ssize_t show_blinkingled_activity(struct device *dev, char *buf)\
+{  
+	return sprintf(buf, "%c\n", pmu_blink_led_activated?'1':'0'); 
+}
+
+static ssize_t set_blinkingled_activity(struct device *dev, 
+		const char *buf, size_t count)
+{
+	int newact;
+	if (sscanf (buf, "%d", &newact) != 1)
+		return -EINVAL;
+	pmu_blink_led_activated = newact?1:0;
+	printk (KERN_INFO 
+			"pmac blinking led has been %sactivated\n", 
+			pmu_blink_led_activated?"":"dis");
+	return count;
+}
+
+static DEVICE_ATTR (blinking_led, S_IRUGO | S_IWUSR, 
+		show_blinkingled_activity, set_blinkingled_activity);
+
 static int
 pmu_hd_blink_init(void)
 {
+	struct device_node *np;
+	static struct of_device *of_hd_dev;
 	struct device_node *dt;
 	const char *model;
 
@@ -458,6 +489,21 @@
 	init_timer(&pmu_blink_timer);
 	pmu_blink_timer.function = pmu_hd_blink_timeout;
 
+	np = of_find_node_by_name (NULL, "disk");
+	if (!np) return 1;
+	of_hd_dev = of_platform_device_create (np, "ide-pmac");
+	if (!of_hd_dev) return 1;
+	device_create_file (&of_hd_dev->dev, &dev_attr_blinking_led);
+	
+	/****** Should be used to remove sysfs entry ******
+	 * Don't know where though...                      *
+	if (of_hd_dev) {
+		device_remove_file (&of_hd_dev->dev, &dev_attr_blinking_led);
+		of_device_unregister (of_hd_dev);
+	}
+	 * */
+
+
 	return 1;
 }
 

Reply to: