rendered paste bodyIndex: target/linux/ar7-2.6/files/drivers/leds/leds-avm.c
===================================================================
--- target/linux/ar7-2.6/files/drivers/leds/leds-avm.c (revision 0)
+++ target/linux/ar7-2.6/files/drivers/leds/leds-avm.c (revision 0)
@@ -0,0 +1,152 @@
+/*
+ * linux/drivers/leds/leds-avm.c
+ *
+ * Copyright (C) 2007 OpenWrt.org
+ *
+ * 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. 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/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <linux/err.h>
+#include <asm/io.h>
+#include <gpio.h>
+
+// Module information
+#define DRVNAME "avm-leds"
+#define LONGNAME "AVM Fritz!Box LEDs driver"
+MODULE_AUTHOR("Axel Gembe <ago@bastart.eu.org>");
+MODULE_DESCRIPTION(LONGNAME);
+MODULE_LICENSE("GPL");
+
+// Number of LEDs in devs
+#define NUM_LEDS 5
+
+// Structure for GPIO port definition
+typedef struct led_gpio_s { int num; int invert; } led_gpio;
+
+#if 1 // Fritz!Box SL
+led_gpio gpios[] = { { 7, 0 }, { 10, 1 }, { 12, 1 }, { 13, 1 }, { 9, 1 } };
+#endif // 0
+
+#if 0 // Fritz!Box Fon ATA
+led_gpio gpios[] = { { 8, 0 }, { 3, 1 }, { 5, 0 }, { 4, 1 }, { 11, 1 } };
+#endif // 0
+
+// Function for implementing LED setters
+#define IMPLEMENT_LED(x) static void avm_led_set_##x(struct led_classdev *pled, enum led_brightness value) { \
+ gpio_set_value(gpios[x].num, value ? (gpios[x].invert ? 0 : 1) : (gpios[x].invert ? 1 : 0)); } \
+ static struct led_classdev avm_led_##x = { .name = "avm:led" #x, .brightness_set = avm_led_set_##x }
+
+// Implement the LED setter code
+IMPLEMENT_LED(0); IMPLEMENT_LED(1); IMPLEMENT_LED(2); IMPLEMENT_LED(3); IMPLEMENT_LED(4);
+
+// Array of all the LED devices
+struct led_classdev *devs[] = { &avm_led_0, &avm_led_1, &avm_led_2, &avm_led_3, &avm_led_4 };
+
+#ifdef CONFIG_PM
+static int avm_leds_suspend(struct platform_device *dev, pm_message_t state)
+{
+ for(int i = 0; i < NUM_LEDS; i++)
+ led_classdev_suspend(devs[i]);
+ return 0;
+}
+
+static int avm_leds_resume(struct platform_device *dev)
+{
+ for(int i = 0; i < NUM_LEDS; i++)
+ led_classdev_resume(devs[i]);
+ return 0;
+}
+#else /* CONFIG_PM */
+#define avm_leds_suspend NULL
+#define avm_leds_resume NULL
+#endif /* CONFIG_PM */
+
+static int avm_leds_probe(struct platform_device *pdev)
+{
+ int rc, i;
+
+ for(i = 0; i < NUM_LEDS; i++)
+ {
+ rc = led_classdev_register(&pdev->dev, devs[i]);
+ if( rc < 0 ) goto out;
+
+ ar7_gpio_enable(gpios[i].num);
+ gpio_direction_output(gpios[i].num);
+ }
+
+out:
+ return rc;
+}
+
+static int avm_leds_remove(struct platform_device *pdev)
+{
+ int i;
+
+ for(i = 0; i < NUM_LEDS; i++)
+ {
+ led_classdev_unregister(devs[i]);
+ }
+
+ return 0;
+}
+
+static struct platform_device *avm_leds_device;
+
+static struct platform_driver avm_leds_driver = {
+ .probe = avm_leds_probe,
+ .remove = avm_leds_remove,
+ .suspend = avm_leds_suspend,
+ .resume = avm_leds_resume,
+ .driver = {
+ .name = DRVNAME,
+ },
+};
+
+static int __init avm_leds_init(void)
+{
+ int rc;
+
+ avm_leds_device = platform_device_alloc(DRVNAME, -1);
+ if (!avm_leds_device)
+ return -ENOMEM;
+
+ rc = platform_device_add(avm_leds_device);
+ if (rc < 0)
+ goto out_put;
+
+ rc = platform_driver_register(&avm_leds_driver);
+ if (rc < 0)
+ goto out_put;
+
+ goto out;
+
+out_put:
+ platform_device_put(avm_leds_device);
+out:
+ return rc;
+}
+
+static void __exit avm_leds_exit(void)
+{
+ platform_driver_unregister(&avm_leds_driver);
+ platform_device_unregister(avm_leds_device);
+}
+
+module_init(avm_leds_init);
+module_exit(avm_leds_exit);
Index: target/linux/ar7-2.6/patches/131-leds-avm.patch
===================================================================
--- target/linux/ar7-2.6/patches/131-leds-avm.patch (revision 0)
+++ target/linux/ar7-2.6/patches/131-leds-avm.patch (revision 0)
@@ -0,0 +1,25 @@
+--- linux-old/drivers/leds/Kconfig 2007-06-23 16:49:13.000000000 +0200
++++ linux-new/drivers/leds/Kconfig 2007-06-23 16:50:00.000000000 +0200
+@@ -25,6 +25,12 @@
+ help
+ This option enables support for the LEDs on TI AR7.
+
++config LEDS_AVM
++ tristate "LED Support for the AVM Fritz!Box"
++ depends LEDS_CLASS && AR7
++ help
++ This option enables support for the LEDs on the AVM Fritz!Box.
++
+ config LEDS_CORGI
+ tristate "LED Support for the Sharp SL-C7x0 series"
+ depends on LEDS_CLASS && PXA_SHARP_C7xx
+--- linux-old/drivers/leds/Makefile 2007-06-23 16:50:40.000000000 +0200
++++ linux-new/drivers/leds/Makefile 2007-06-23 16:50:58.000000000 +0200
+@@ -6,6 +6,7 @@
+
+ # LED Platform Drivers
+ obj-$(CONFIG_LEDS_AR7) += leds-ar7.o
++obj-$(CONFIG_LEDS_AVM) += leds-avm.o
+ obj-$(CONFIG_LEDS_CORGI) += leds-corgi.o
+ obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o
+ obj-$(CONFIG_LEDS_SPITZ) += leds-spitz.o