aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2007-10-20 07:45:08 +0000
committerGabor Juhos <juhosg@openwrt.org>2007-10-20 07:45:08 +0000
commitd2cfb2934f7f93ddf102b16eeeaf35a1324016bf (patch)
treed589abbc8095d2dab50ae9212a10b093db207536
parent4c093ed622ac073ace448abfcc13d96ebf18e091 (diff)
downloadupstream-d2cfb2934f7f93ddf102b16eeeaf35a1324016bf.tar.gz
upstream-d2cfb2934f7f93ddf102b16eeeaf35a1324016bf.tar.bz2
upstream-d2cfb2934f7f93ddf102b16eeeaf35a1324016bf.zip
add LEDs trigger for switch port states, thanks to Bernhard Held (closes: #2153)
SVN-Revision: 9362
-rw-r--r--package/kernel/modules/other.mk19
-rw-r--r--target/linux/adm5120/files/drivers/leds/ledtrig-adm5120-switch.c149
-rw-r--r--target/linux/adm5120/patches-2.6.23/009-adm5120_leds_switch_trigger.patch26
-rw-r--r--target/linux/adm5120/router_be/config-2.6.231
-rw-r--r--target/linux/adm5120/router_le/config-2.6.231
5 files changed, 195 insertions, 1 deletions
diff --git a/package/kernel/modules/other.mk b/package/kernel/modules/other.mk
index 5961369840..ca454a1c6e 100644
--- a/package/kernel/modules/other.mk
+++ b/package/kernel/modules/other.mk
@@ -279,12 +279,29 @@ define KernelPackage/leds-adm5120
endef
define KernelPackage/leds-adm5120/description
- Kernel module for LEDs on ADM5120 based boards
+ Kernel module for LEDs on ADM5120 based boards.
endef
$(eval $(call KernelPackage,leds-adm5120))
+define KernelPackage/ledtrig-adm5120-switch
+ SUBMENU:=$(OTHER_MENU)
+ TITLE:=LED ADM5120 Switch Port Status Trigger
+ DEPENDS:=@TARGET_adm5120
+ KCONFIG:=CONFIG_LEDS_TRIGGER_ADM5120_SWITCH
+ FILES:=$(LINUX_DIR)/drivers/leds/ledtrig-adm5120-switch.$(LINUX_KMOD_SUFFIX)
+ AUTOLOAD:=$(call AutoLoad,50,ledtrig-adm5120-switch)
+endef
+
+define KernelPackage/ledtrig-adm5120-switch/description
+ Kernel module to allow LEDs to be controlled by the port states
+ of the ADM5120 built-in ethernet switch.
+endef
+
+$(eval $(call KernelPackage,ledtrig-adm5120-switch))
+
+
define KernelPackage/leds-net48xx
SUBMENU:=$(OTHER_MENU)
TITLE:=Soekris Net48xx LED support
diff --git a/target/linux/adm5120/files/drivers/leds/ledtrig-adm5120-switch.c b/target/linux/adm5120/files/drivers/leds/ledtrig-adm5120-switch.c
new file mode 100644
index 0000000000..345909d231
--- /dev/null
+++ b/target/linux/adm5120/files/drivers/leds/ledtrig-adm5120-switch.c
@@ -0,0 +1,149 @@
+/*
+ * LED ADM5120 Switch Port State Trigger
+ *
+ * Copyright (C) 2007 Bernhard Held <bernhard at bernhardheld.de>
+ * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
+ *
+ * This file was based on: drivers/leds/ledtrig-timer.c
+ * Copyright 2005-2006 Openedhand Ltd.
+ * Author: Richard Purdie
+ *
+ * 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/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+
+#include <asm/gpio.h>
+
+#include "leds.h"
+
+#define DRV_NAME "port_state"
+#define DRV_DESC "LED ADM5120 Switch Port State Trigger"
+
+struct port_state {
+ char *name;
+ unsigned int value;
+};
+
+#define PORT_STATE(n,v) {.name = (n), .value = (v)}
+
+static struct port_state port_states[] = {
+ PORT_STATE("off", LED_OFF),
+ PORT_STATE("on", LED_FULL),
+ PORT_STATE("flash", ADM5120_GPIO_FLASH),
+ PORT_STATE("link", ADM5120_GPIO_LINK),
+ PORT_STATE("speed", ADM5120_GPIO_SPEED),
+ PORT_STATE("duplex", ADM5120_GPIO_DUPLEX),
+ PORT_STATE("act", ADM5120_GPIO_ACT),
+ PORT_STATE("coll", ADM5120_GPIO_COLL),
+ PORT_STATE("link_act", ADM5120_GPIO_LINK_ACT),
+ PORT_STATE("duplex_coll", ADM5120_GPIO_DUPLEX_COLL),
+ PORT_STATE("10M_act", ADM5120_GPIO_10M_ACT),
+ PORT_STATE("100M_act", ADM5120_GPIO_100M_ACT),
+};
+
+static ssize_t led_port_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct led_classdev *led_cdev = dev_get_drvdata(dev);
+ struct port_state *state = led_cdev->trigger_data;
+ int len = 0;
+ int i;
+
+ *buf = '\0';
+ for (i = 0; i < ARRAY_SIZE(port_states); i++) {
+ if (&port_states[i] == state)
+ len += sprintf(buf+len, "[%s] ", port_states[i].name);
+ else
+ len += sprintf(buf+len, "%s ", port_states[i].name);
+ }
+ len += sprintf(buf+len, "\n");
+
+ return len;
+}
+
+static ssize_t led_port_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ struct led_classdev *led_cdev = dev_get_drvdata(dev);
+ size_t len;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(port_states); i++) {
+ len = strlen(port_states[i].name);
+ if (strncmp(port_states[i].name, buf, len) != 0)
+ continue;
+
+ if (buf[len] != '\0' && buf[len] != '\n')
+ continue;
+
+ led_cdev->trigger_data = &port_states[i];
+ led_set_brightness(led_cdev, port_states[i].value);
+ return size;
+ }
+
+ return -EINVAL;
+}
+
+static DEVICE_ATTR(port_state, 0644, led_port_state_show,
+ led_port_state_store);
+
+static void adm5120_switch_trig_activate(struct led_classdev *led_cdev)
+{
+ struct port_state *state = port_states;
+ int rc;
+
+ led_cdev->trigger_data = state;
+
+ rc = device_create_file(led_cdev->dev, &dev_attr_port_state);
+ if (rc)
+ goto err;
+
+ led_set_brightness(led_cdev, state->value);
+
+ return;
+err:
+ led_cdev->trigger_data = NULL;
+}
+
+static void adm5120_switch_trig_deactivate(struct led_classdev *led_cdev)
+{
+ struct port_state *state = led_cdev->trigger_data;
+
+ if (!state)
+ return;
+
+ device_remove_file(led_cdev->dev, &dev_attr_port_state);
+
+}
+
+static struct led_trigger adm5120_switch_led_trigger = {
+ .name = DRV_NAME,
+ .activate = adm5120_switch_trig_activate,
+ .deactivate = adm5120_switch_trig_deactivate,
+};
+
+static int __init adm5120_switch_trig_init(void)
+{
+ led_trigger_register(&adm5120_switch_led_trigger);
+ return 0;
+}
+
+static void __exit adm5120_switch_trig_exit(void)
+{
+ led_trigger_unregister(&adm5120_switch_led_trigger);
+}
+
+module_init(adm5120_switch_trig_init);
+module_exit(adm5120_switch_trig_exit);
+
+MODULE_AUTHOR("Bernhard Held <bernhard at bernhardheld.de>, "
+ "Gabor Juhos <juhosg at openwrt.org>");
+MODULE_DESCRIPTION(DRV_DESC);
+MODULE_LICENSE("GPL");
diff --git a/target/linux/adm5120/patches-2.6.23/009-adm5120_leds_switch_trigger.patch b/target/linux/adm5120/patches-2.6.23/009-adm5120_leds_switch_trigger.patch
new file mode 100644
index 0000000000..088b6223a1
--- /dev/null
+++ b/target/linux/adm5120/patches-2.6.23/009-adm5120_leds_switch_trigger.patch
@@ -0,0 +1,26 @@
+Index: linux-2.6.23/drivers/leds/Kconfig
+===================================================================
+--- linux-2.6.23.orig/drivers/leds/Kconfig
++++ linux-2.6.23/drivers/leds/Kconfig
+@@ -152,4 +152,12 @@ config LEDS_TRIGGER_MORSE
+ tristate "LED Morse Trigger"
+ depends on LEDS_TRIGGERS
+
++config LEDS_TRIGGER_ADM5120_SWITCH
++ tristate "LED ADM5120 Switch Port Status Trigger"
++ depends on LEDS_TRIGGERS && LEDS_ADM5120
++ help
++ This allows LEDs to be controlled by the port states of
++ the ADM5120 built-in Ethernet Switch
++ If unsure, say N.
++
+ endif # NEW_LEDS
+Index: linux-2.6.23/drivers/leds/Makefile
+===================================================================
+--- linux-2.6.23.orig/drivers/leds/Makefile
++++ linux-2.6.23/drivers/leds/Makefile
+@@ -24,3 +24,4 @@ obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledt
+ obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
+ obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
+ obj-$(CONFIG_LEDS_TRIGGER_MORSE) += ledtrig-morse.o
++obj-$(CONFIG_LEDS_TRIGGER_ADM5120_SWITCH) += ledtrig-adm5120-switch.o
diff --git a/target/linux/adm5120/router_be/config-2.6.23 b/target/linux/adm5120/router_be/config-2.6.23
index 7cf0fb4e72..224c0ff786 100644
--- a/target/linux/adm5120/router_be/config-2.6.23
+++ b/target/linux/adm5120/router_be/config-2.6.23
@@ -92,6 +92,7 @@ CONFIG_LEDS_ADM5120=m
CONFIG_LEDS_ADM5120_DIAG=y
# CONFIG_LEDS_ADM5120_EXPERIMENTAL is not set
CONFIG_LEDS_GPIO=m
+CONFIG_LEDS_TRIGGER_ADM5120_SWITCH=m
CONFIG_LEGACY_PTYS=y
CONFIG_LEGACY_PTY_COUNT=256
# CONFIG_LEMOTE_FULONG is not set
diff --git a/target/linux/adm5120/router_le/config-2.6.23 b/target/linux/adm5120/router_le/config-2.6.23
index a1bee45827..da96c7306f 100644
--- a/target/linux/adm5120/router_le/config-2.6.23
+++ b/target/linux/adm5120/router_le/config-2.6.23
@@ -92,6 +92,7 @@ CONFIG_LEDS_ADM5120=m
CONFIG_LEDS_ADM5120_DIAG=y
# CONFIG_LEDS_ADM5120_EXPERIMENTAL is not set
CONFIG_LEDS_GPIO=m
+CONFIG_LEDS_TRIGGER_ADM5120_SWITCH=m
CONFIG_LEGACY_PTYS=y
CONFIG_LEGACY_PTY_COUNT=256
# CONFIG_LEMOTE_FULONG is not set