mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "kogiidena" <kogiidena@eggplant.ddo.jp>
To: rpurdie@rpsys.net
Cc: linux-kernel@vger.kernel.org, lethal@linux-sh.org
Subject: Re: [PATCH 2/2] leds:arch/sh/boards/landisk LEDs supports
Date: Sat, 12 May 2007 13:01:47 +0900 (JST)	[thread overview]
Message-ID: <1283.192.168.1.10.1178942507.squirrel@eggplant.ddo.jp> (raw)
In-Reply-To: <1185.192.168.1.10.1178895776.squirrel@eggplant.ddo.jp>

To: Richard-san

I'm sorry. The patch sent yesterday is corrected, too.
Because the source had not been read easily, it cleaned it.
There is no change for the basic function.

Add Bitpattern Trigger.
Bitpattern continuously turns LED on and off according to
the value directed "bitdata". "bitdata" is composed of
the character string that consists of the following three
characters. '0' turn off LED. '1' turn on  LED. 'R' is
repeated from the head of the "bitdata".
In addition, the character string of "on", "off", and "blink"
can be set to "bitdata".
The transition time of "bitdata" is set by "delay".

Signed-off-by: kogiidena <kogiidena@eggplant.ddo.jp>
---
diff -urpN OLD/drivers/leds/Kconfig NEW/drivers/leds/Kconfig
--- OLD/drivers/leds/Kconfig	2007-04-28 06:49:26.000000000 +0900
+++ NEW/drivers/leds/Kconfig	2007-05-11 21:15:28.000000000 +0900
@@ -127,5 +133,19 @@ config LEDS_TRIGGER_HEARTBEAT
 	  load average.
 	  If unsure, say Y.

+config LEDS_TRIGGER_BITPAT
+	tristate "LED Bitpattern Trigger"
+	depends on LEDS_TRIGGERS
+	help
+	  Bitpattern continuously turns LED on and off according to
+	  the value directed "bitdata". "bitdata" is composed of
+	  the character string that consists of the following three
+	  characters. '0' turn off LED. '1' turn on  LED. 'R' is
+	  repeated from the head of the "bitdata".
+	  In addition, the character string of "on", "off", and "blink"
+	  can be set to "bitdata".
+	  The transition time of "bitdata" is set by "delay".
+	  If unsure, say Y.
+
 endmenu

diff -urpN OLD/drivers/leds/Makefile NEW/drivers/leds/Makefile
--- OLD/drivers/leds/Makefile	2007-05-11 23:44:12.000000000 +0900
+++ NEW/drivers/leds/Makefile	2007-05-11 23:46:47.000000000 +0900
@@ -22,3 +22,4 @@ obj-$(CONFIG_LEDS_LANDISK)		+= leds-land
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
 obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK)	+= ledtrig-ide-disk.o
 obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT)	+= ledtrig-heartbeat.o
+obj-$(CONFIG_LEDS_TRIGGER_BITPAT)	+= ledtrig-bitpat.o
diff -urpN OLD/drivers/leds/ledtrig-bitpat.c NEW/drivers/leds/ledtrig-bitpat.c
--- OLD/drivers/leds/ledtrig-bitpat.c	1970-01-01 09:00:00.000000000 +0900
+++ NEW/drivers/leds/ledtrig-bitpat.c	2007-05-12 11:29:34.000000000 +0900
@@ -0,0 +1,231 @@
+/*
+ * LED Bitpattern Trigger
+ *
+ * Copyright (C) 2007 kogiidena
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/module.h>
+#include <linux/jiffies.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/sched.h>
+#include <linux/leds.h>
+#include <linux/device.h>
+#include <linux/ctype.h>
+#include "leds.h"
+
+#define BITDATA_LEN 18
+
+struct bitpat_trig_data {
+	char bitdata[BITDATA_LEN + 2];
+	int cnt;
+	unsigned long delay;
+	struct timer_list timer;
+};
+
+void __attribute__ ((weak))
+ledtrig_bitpat_default(struct led_classdev *led_cdev,
+		       unsigned long *delay, char *bitdata)
+{
+	/* Nothing to do. */
+}
+
+static void led_bitpat_function(unsigned long data)
+{
+	struct led_classdev *led_cdev = (struct led_classdev *)data;
+	struct bitpat_trig_data *bitpat_data = led_cdev->trigger_data;
+	unsigned long delay = bitpat_data->delay;
+	char bitpat;
+
+	bitpat = bitpat_data->bitdata[bitpat_data->cnt++];
+
+	if (bitpat == '0' || bitpat == '1') {
+		led_set_brightness(led_cdev,
+				   (bitpat == '1') ? LED_FULL : LED_OFF);
+	} else {
+		bitpat_data->cnt = 0;
+		return;
+	}
+
+	if (bitpat_data->bitdata[bitpat_data->cnt] == 'R')
+		bitpat_data->cnt = 0;
+
+	mod_timer(&bitpat_data->timer, jiffies + msecs_to_jiffies(delay));
+}
+
+static ssize_t led_delay_show(struct class_device *dev, char *buf)
+{
+	struct led_classdev *led_cdev = class_get_devdata(dev);
+	struct bitpat_trig_data *bitpat_data = led_cdev->trigger_data;
+
+	sprintf(buf, "%lu\n", bitpat_data->delay);
+
+	return strlen(buf) + 1;
+}
+
+static ssize_t led_delay_store(struct class_device *dev, const char *buf,
+			       size_t size)
+{
+	struct led_classdev *led_cdev = class_get_devdata(dev);
+	struct bitpat_trig_data *bitpat_data = led_cdev->trigger_data;
+	int ret = -EINVAL;
+	char *after;
+	unsigned long state = simple_strtoul(buf, &after, 10);
+	size_t count = after - buf;
+
+	if (*after && isspace(*after))
+		count++;
+
+	if (count == size) {
+		bitpat_data->delay = state;
+		mod_timer(&bitpat_data->timer, jiffies + 1);
+		ret = count;
+	}
+	return ret;
+}
+
+static void led_bitdata_update(struct bitpat_trig_data *bitpat_data,
+			       const char *buf)
+{
+	int i;
+	const char *s;
+
+	if (!strncmp("on", buf, 2)) {
+		s = "1";
+	} else if (!strncmp("off", buf, 2)) {
+		s = "0";
+	} else if (!strncmp("blink", buf, 5)) {
+		s = "01R";
+	} else {
+		s = buf;
+	}
+
+	for (i = 0; i < BITDATA_LEN; i++) {
+		if ((s[i] == '0') || (s[i] == '1')) {
+			bitpat_data->bitdata[i] = s[i];
+		} else if ((i != 0) && ((s[i] == 'R') || (s[i] == 'r'))) {
+			bitpat_data->bitdata[i] = 'R';
+			bitpat_data->bitdata[i + 1] = '\0';
+			break;
+		} else {
+			bitpat_data->bitdata[i] = '\0';
+			break;
+		}
+	}
+	bitpat_data->cnt = 0;
+}
+
+static ssize_t led_bitdata_show(struct class_device *dev, char *buf)
+{
+	struct led_classdev *led_cdev = class_get_devdata(dev);
+	struct bitpat_trig_data *bitpat_data = led_cdev->trigger_data;
+
+	sprintf(buf,
+		"bitdata : %s\n"
+		"meaning : 0=OFF, 1=ON, R=Repeat\n",
+		(bitpat_data->bitdata[0]) ? bitpat_data->bitdata : "(null)");
+
+	return strlen(buf) + 1;
+}
+
+static ssize_t led_bitdata_store(struct class_device *dev, const char *buf,
+				 size_t size)
+{
+	struct led_classdev *led_cdev = class_get_devdata(dev);
+	struct bitpat_trig_data *bitpat_data = led_cdev->trigger_data;
+
+	if (size > BITDATA_LEN)
+		return -EINVAL;
+
+	led_bitdata_update(bitpat_data, buf);
+	mod_timer(&bitpat_data->timer, jiffies + 1);
+
+	return size;
+}
+
+static CLASS_DEVICE_ATTR(delay,   0644, led_delay_show,   led_delay_store);
+static CLASS_DEVICE_ATTR(bitdata, 0644, led_bitdata_show, led_bitdata_store);
+
+static void bitpat_trig_activate(struct led_classdev *led_cdev)
+{
+	struct bitpat_trig_data *bitpat_data;
+	int rc;
+
+	bitpat_data = kzalloc(sizeof(*bitpat_data), GFP_KERNEL);
+	if (!bitpat_data)
+		return;
+
+	led_cdev->trigger_data = bitpat_data;
+
+	/* initial value */
+	bitpat_data->delay      = 500;
+	bitpat_data->bitdata[0] = '\0';
+
+	ledtrig_bitpat_default(led_cdev,
+			       &bitpat_data->delay, &bitpat_data->bitdata[0]);
+	led_bitdata_update(bitpat_data, bitpat_data->bitdata);
+
+	rc = class_device_create_file(led_cdev->class_dev,
+				      &class_device_attr_delay);
+	if (rc)
+		goto err_out;
+	rc = class_device_create_file(led_cdev->class_dev,
+				      &class_device_attr_bitdata);
+	if (rc)
+		goto err_out_delay;
+
+	setup_timer(&bitpat_data->timer,
+		    led_bitpat_function, (unsigned long)led_cdev);
+	led_bitpat_function(bitpat_data->timer.data);
+
+	return;
+
+err_out_delay:
+	class_device_remove_file(led_cdev->class_dev, &class_device_attr_delay);
+err_out:
+	led_cdev->trigger_data = NULL;
+	kfree(bitpat_data);
+}
+
+static void bitpat_trig_deactivate(struct led_classdev *led_cdev)
+{
+	struct bitpat_trig_data *bitpat_data = led_cdev->trigger_data;
+
+	if (bitpat_data) {
+		class_device_remove_file(led_cdev->class_dev,
+					 &class_device_attr_delay);
+		class_device_remove_file(led_cdev->class_dev,
+					 &class_device_attr_bitdata);
+		del_timer_sync(&bitpat_data->timer);
+		kfree(bitpat_data);
+	}
+}
+
+static struct led_trigger bitpat_led_trigger = {
+	.name = "bitpat",
+	.activate = bitpat_trig_activate,
+	.deactivate = bitpat_trig_deactivate,
+};
+
+static int __init bitpat_trig_init(void)
+{
+	led_trigger_register(&bitpat_led_trigger);
+	return 0;
+}
+
+static void __exit bitpat_trig_exit(void)
+{
+	led_trigger_unregister(&bitpat_led_trigger);
+}
+
+module_init(bitpat_trig_init);
+module_exit(bitpat_trig_exit);
+
+MODULE_AUTHOR("kogiidena <kogiidena@eggplant.ddo.jp>");
+MODULE_DESCRIPTION("Bitpattern LED trigger");
+MODULE_LICENSE("GPL");





      reply	other threads:[~2007-05-12  4:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-08 12:27 kogiidena
2007-05-08 12:46 ` Richard Purdie
2007-05-09 11:42   ` kogiidena
2007-05-09 12:14     ` Richard Purdie
2007-05-09 13:45       ` kogiidena
2007-05-09 15:06         ` Richard Purdie
2007-05-09 22:18           ` kogiidena
2007-05-11 15:02             ` kogiidena
2007-05-12  4:01               ` kogiidena [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1283.192.168.1.10.1178942507.squirrel@eggplant.ddo.jp \
    --to=kogiidena@eggplant.ddo.jp \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpurdie@rpsys.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®