diff options
| author | John Bowler <jbowler@acm.org> | 2006-03-31 05:31:11 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-31 15:18:57 -0500 |
| commit | 6a0c51bfce5ae4058366017d861aea6564d25aee (patch) | |
| tree | d8ba880b4b4da416382fffd386e8e62db92cf9d3 /drivers | |
| parent | 4d3cb35476903768541f79e61f171e79e6065098 (diff) | |
[PATCH] LED: add LED device support for ixp4xx devices
NEW_LEDS support for ixp4xx boards where LEDs are connected to the GPIO lines.
This includes a new generic ixp4xx driver (leds-ixp4xx-gpio.c name
"IXP4XX-GPIO-LED")
Signed-off-by: John Bowler <jbowler@acm.org>
Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/leds/Kconfig | 9 | ||||
| -rw-r--r-- | drivers/leds/Makefile | 1 | ||||
| -rw-r--r-- | drivers/leds/leds-ixp4xx-gpio.c | 215 |
3 files changed, 225 insertions, 0 deletions
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 6099e32985aa..d9e2f9853b9d 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig | |||
| @@ -43,6 +43,15 @@ config LEDS_SPITZ | |||
| 43 | This option enables support for the LEDs on Sharp Zaurus | 43 | This option enables support for the LEDs on Sharp Zaurus |
| 44 | SL-Cxx00 series (C1000, C3000, C3100). | 44 | SL-Cxx00 series (C1000, C3000, C3100). |
| 45 | 45 | ||
| 46 | config LEDS_IXP4XX | ||
| 47 | tristate "LED Support for GPIO connected LEDs on IXP4XX processors" | ||
| 48 | depends LEDS_CLASS && ARCH_IXP4XX | ||
| 49 | help | ||
| 50 | This option enables support for the LEDs connected to GPIO | ||
| 51 | outputs of the Intel IXP4XX processors. To be useful the | ||
| 52 | particular board must have LEDs and they must be connected | ||
| 53 | to the GPIO lines. If unsure, say Y. | ||
| 54 | |||
| 46 | config LEDS_TRIGGER_TIMER | 55 | config LEDS_TRIGGER_TIMER |
| 47 | tristate "LED Timer Trigger" | 56 | tristate "LED Timer Trigger" |
| 48 | depends LEDS_TRIGGERS | 57 | depends LEDS_TRIGGERS |
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index d60e12b8af24..b1187c0b36ce 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile | |||
| @@ -8,6 +8,7 @@ obj-$(CONFIG_LEDS_TRIGGERS) += led-triggers.o | |||
| 8 | obj-$(CONFIG_LEDS_CORGI) += leds-corgi.o | 8 | obj-$(CONFIG_LEDS_CORGI) += leds-corgi.o |
| 9 | obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o | 9 | obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o |
| 10 | obj-$(CONFIG_LEDS_SPITZ) += leds-spitz.o | 10 | obj-$(CONFIG_LEDS_SPITZ) += leds-spitz.o |
| 11 | obj-$(CONFIG_LEDS_IXP4XX) += leds-ixp4xx-gpio.o | ||
| 11 | 12 | ||
| 12 | # LED Triggers | 13 | # LED Triggers |
| 13 | obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o | 14 | obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o |
diff --git a/drivers/leds/leds-ixp4xx-gpio.c b/drivers/leds/leds-ixp4xx-gpio.c new file mode 100644 index 000000000000..30ced150e4cf --- /dev/null +++ b/drivers/leds/leds-ixp4xx-gpio.c | |||
| @@ -0,0 +1,215 @@ | |||
| 1 | /* | ||
| 2 | * IXP4XX GPIO driver LED driver | ||
| 3 | * | ||
| 4 | * Author: John Bowler <jbowler@acm.org> | ||
| 5 | * | ||
| 6 | * Copyright (c) 2006 John Bowler | ||
| 7 | * | ||
| 8 | * Permission is hereby granted, free of charge, to any | ||
| 9 | * person obtaining a copy of this software and associated | ||
| 10 | * documentation files (the "Software"), to deal in the | ||
| 11 | * Software without restriction, including without | ||
| 12 | * limitation the rights to use, copy, modify, merge, | ||
| 13 | * publish, distribute, sublicense, and/or sell copies of | ||
| 14 | * the Software, and to permit persons to whom the | ||
| 15 | * Software is furnished to do so, subject to the | ||
| 16 | * following conditions: | ||
| 17 | * | ||
| 18 | * The above copyright notice and this permission notice | ||
| 19 | * shall be included in all copies or substantial portions | ||
| 20 | * of the Software. | ||
| 21 | * | ||
| 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
| 23 | * ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
| 26 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR | ||
| 27 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| 30 | * OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | * | ||
| 32 | */ | ||
| 33 | |||
| 34 | #include <linux/config.h> | ||
| 35 | #include <linux/kernel.h> | ||
| 36 | #include <linux/init.h> | ||
| 37 | #include <linux/platform_device.h> | ||
| 38 | #include <linux/spinlock.h> | ||
| 39 | #include <linux/leds.h> | ||
| 40 | #include <asm/arch/hardware.h> | ||
| 41 | |||
| 42 | extern spinlock_t gpio_lock; | ||
| 43 | |||
| 44 | /* Up to 16 gpio lines are possible. */ | ||
| 45 | #define GPIO_MAX 16 | ||
| 46 | static struct ixp4xxgpioled_device { | ||
| 47 | struct led_classdev ancestor; | ||
| 48 | int flags; | ||
| 49 | } ixp4xxgpioled_devices[GPIO_MAX]; | ||
| 50 | |||
| 51 | void ixp4xxgpioled_brightness_set(struct led_classdev *pled, | ||
| 52 | enum led_brightness value) | ||
| 53 | { | ||
| 54 | const struct ixp4xxgpioled_device *const ixp4xx_dev = | ||
| 55 | container_of(pled, struct ixp4xxgpioled_device, ancestor); | ||
| 56 | const u32 gpio_pin = ixp4xx_dev - ixp4xxgpioled_devices; | ||
| 57 | |||
| 58 | if (gpio_pin < GPIO_MAX && ixp4xx_dev->ancestor.name != 0) { | ||
| 59 | /* Set or clear the 'gpio_pin' bit according to the style | ||
| 60 | * and the required setting (value > 0 == on) | ||
| 61 | */ | ||
| 62 | const int gpio_value = | ||
| 63 | (value > 0) == (ixp4xx_dev->flags != IXP4XX_GPIO_LOW) ? | ||
| 64 | IXP4XX_GPIO_HIGH : IXP4XX_GPIO_LOW; | ||
| 65 | |||
| 66 | { | ||
| 67 | unsigned long flags; | ||
| 68 | spin_lock_irqsave(&gpio_lock, flags); | ||
| 69 | gpio_line_set(gpio_pin, gpio_value); | ||
| 70 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | /* LEDs are described in resources, the following iterates over the valid | ||
| 76 | * LED resources. | ||
| 77 | */ | ||
| 78 | #define for_all_leds(i, pdev) \ | ||
| 79 | for (i=0; i<pdev->num_resources; ++i) \ | ||
| 80 | if (pdev->resource[i].start < GPIO_MAX && \ | ||
| 81 | pdev->resource[i].name != 0) | ||
| 82 | |||
| 83 | /* The following applies 'operation' to each LED from the given platform, | ||
| 84 | * the function always returns 0 to allow tail call elimination. | ||
| 85 | */ | ||
| 86 | static int apply_to_all_leds(struct platform_device *pdev, | ||
| 87 | void (*operation)(struct led_classdev *pled)) | ||
| 88 | { | ||
| 89 | int i; | ||
| 90 | |||
| 91 | for_all_leds(i, pdev) | ||
| 92 | operation(&ixp4xxgpioled_devices[pdev->resource[i].start].ancestor); | ||
| 93 | return 0; | ||
| 94 | } | ||
| 95 | |||
| 96 | #ifdef CONFIG_PM | ||
| 97 | static int ixp4xxgpioled_suspend(struct platform_device *pdev, | ||
| 98 | pm_message_t state) | ||
| 99 | { | ||
| 100 | return apply_to_all_leds(pdev, led_classdev_suspend); | ||
| 101 | } | ||
| 102 | |||
| 103 | static int ixp4xxgpioled_resume(struct platform_device *pdev) | ||
| 104 | { | ||
| 105 | return apply_to_all_leds(pdev, led_classdev_resume); | ||
| 106 | } | ||
| 107 | #endif | ||
| 108 | |||
| 109 | static void ixp4xxgpioled_remove_one_led(struct led_classdev *pled) | ||
| 110 | { | ||
| 111 | led_classdev_unregister(pled); | ||
| 112 | pled->name = 0; | ||
| 113 | } | ||
| 114 | |||
| 115 | static int ixp4xxgpioled_remove(struct platform_device *pdev) | ||
| 116 | { | ||
| 117 | return apply_to_all_leds(pdev, ixp4xxgpioled_remove_one_led); | ||
| 118 | } | ||
| 119 | |||
| 120 | static int ixp4xxgpioled_probe(struct platform_device *pdev) | ||
| 121 | { | ||
| 122 | /* The board level has to tell the driver where the | ||
| 123 | * LEDs are connected - there is no way to find out | ||
| 124 | * electrically. It must also say whether the GPIO | ||
| 125 | * lines are active high or active low. | ||
| 126 | * | ||
| 127 | * To do this read the num_resources (the number of | ||
| 128 | * LEDs) and the struct resource (the data for each | ||
| 129 | * LED). The name comes from the resource, and it | ||
| 130 | * isn't copied. | ||
| 131 | */ | ||
| 132 | int i; | ||
| 133 | |||
| 134 | for_all_leds(i, pdev) { | ||
| 135 | const u8 gpio_pin = pdev->resource[i].start; | ||
| 136 | int rc; | ||
| 137 | |||
| 138 | if (ixp4xxgpioled_devices[gpio_pin].ancestor.name == 0) { | ||
| 139 | unsigned long flags; | ||
| 140 | |||
| 141 | spin_lock_irqsave(&gpio_lock, flags); | ||
| 142 | gpio_line_config(gpio_pin, IXP4XX_GPIO_OUT); | ||
| 143 | /* The config can, apparently, reset the state, | ||
| 144 | * I suspect the gpio line may be an input and | ||
| 145 | * the config may cause the line to be latched, | ||
| 146 | * so the setting depends on how the LED is | ||
| 147 | * connected to the line (which affects how it | ||
| 148 | * floats if not driven). | ||
| 149 | */ | ||
| 150 | gpio_line_set(gpio_pin, IXP4XX_GPIO_HIGH); | ||
| 151 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
| 152 | |||
| 153 | ixp4xxgpioled_devices[gpio_pin].flags = | ||
| 154 | pdev->resource[i].flags & IORESOURCE_BITS; | ||
| 155 | |||
| 156 | ixp4xxgpioled_devices[gpio_pin].ancestor.name = | ||
| 157 | pdev->resource[i].name; | ||
| 158 | |||
| 159 | /* This is how a board manufacturer makes the LED | ||
| 160 | * come on on reset - the GPIO line will be high, so | ||
| 161 | * make the LED light when the line is low... | ||
| 162 | */ | ||
| 163 | if (ixp4xxgpioled_devices[gpio_pin].flags != IXP4XX_GPIO_LOW) | ||
| 164 | ixp4xxgpioled_devices[gpio_pin].ancestor.brightness = 100; | ||
| 165 | else | ||
| 166 | ixp4xxgpioled_devices[gpio_pin].ancestor.brightness = 0; | ||
| 167 | |||
| 168 | ixp4xxgpioled_devices[gpio_pin].ancestor.flags = 0; | ||
| 169 | |||
| 170 | ixp4xxgpioled_devices[gpio_pin].ancestor.brightness_set = | ||
| 171 | ixp4xxgpioled_brightness_set; | ||
| 172 | |||
| 173 | ixp4xxgpioled_devices[gpio_pin].ancestor.default_trigger = 0; | ||
| 174 | } | ||
| 175 | |||
| 176 | rc = led_classdev_register(&pdev->dev, | ||
| 177 | &ixp4xxgpioled_devices[gpio_pin].ancestor); | ||
| 178 | if (rc < 0) { | ||
| 179 | ixp4xxgpioled_devices[gpio_pin].ancestor.name = 0; | ||
| 180 | ixp4xxgpioled_remove(pdev); | ||
| 181 | return rc; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | return 0; | ||
| 186 | } | ||
| 187 | |||
| 188 | static struct platform_driver ixp4xxgpioled_driver = { | ||
| 189 | .probe = ixp4xxgpioled_probe, | ||
| 190 | .remove = ixp4xxgpioled_remove, | ||
| 191 | #ifdef CONFIG_PM | ||
| 192 | .suspend = ixp4xxgpioled_suspend, | ||
| 193 | .resume = ixp4xxgpioled_resume, | ||
| 194 | #endif | ||
| 195 | .driver = { | ||
| 196 | .name = "IXP4XX-GPIO-LED", | ||
| 197 | }, | ||
| 198 | }; | ||
| 199 | |||
| 200 | static int __init ixp4xxgpioled_init(void) | ||
| 201 | { | ||
| 202 | return platform_driver_register(&ixp4xxgpioled_driver); | ||
| 203 | } | ||
| 204 | |||
| 205 | static void __exit ixp4xxgpioled_exit(void) | ||
| 206 | { | ||
| 207 | platform_driver_unregister(&ixp4xxgpioled_driver); | ||
| 208 | } | ||
| 209 | |||
| 210 | module_init(ixp4xxgpioled_init); | ||
| 211 | module_exit(ixp4xxgpioled_exit); | ||
| 212 | |||
| 213 | MODULE_AUTHOR("John Bowler <jbowler@acm.org>"); | ||
| 214 | MODULE_DESCRIPTION("IXP4XX GPIO LED driver"); | ||
| 215 | MODULE_LICENSE("Dual MIT/GPL"); | ||
