1 From: Ed Wildgoose <git@wildgooses.com>
2 Date: Wed, 3 Aug 2011 00:52:36 +0000 (+1000)
3 Subject: This new driver replaces the old PCEngines Alix 2/3 LED driver with a new
4 X-Git-Tag: next-20110812~1^2~75
5 X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Fnext%2Flinux-next.git;a=commitdiff_plain;h=2cd7b3e8f8078c214c93a2c60cb845500c92df4a;hp=dc849eae35bbf651ab3ee459f5683e1ff780413d
7 This new driver replaces the old PCEngines Alix 2/3 LED driver with a new
8 driver that controls the LEDs through the leds-gpio driver. The old
9 driver accessed GPIOs directly, which created a conflict and prevented
10 also loading the cs5535-gpio driver to read other GPIOs on the Alix board.
11 With this new driver, we hook into leds-gpio which in turn uses GPIO to
12 control the LEDs and therefore it's possible to control both the LEDs and
15 Driver is moved to platform/geode and any other geode initialisation
16 modules should move here also.
18 This driver is inspired by leds-net5501.c by Alessandro Zummo.
20 Ideally, leds-net5501.c should also be moved to platform/geode.
21 Additionally the driver relies on parts of the patch: 7f131cf3ed ("leds:
22 leds-alix2c - take port address from MSR) by Daniel Mack to perform
23 detection of the Alix board.
25 Signed-off-by: Ed Wildgoose <kernel@wildgooses.com>
26 Cc: Alessandro Zummo <a.zummo@towertech.it>
27 Cc: Daniel Mack <daniel@caiaq.de>
28 Reviewed-by: Grant Likely <grant.likely@secretlab.ca>
29 Cc: Ingo Molnar <mingo@elte.hu>
30 Cc: Thomas Gleixner <tglx@linutronix.de>
31 Cc: "H. Peter Anvin" <hpa@zytor.com>
32 Cc: Richard Purdie <rpurdie@rpsys.net>
33 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
36 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
37 index f1833e3..d18e7a2 100644
38 --- a/arch/x86/Kconfig
39 +++ b/arch/x86/Kconfig
40 @@ -2073,6 +2073,20 @@ config OLPC_XO15_SCI
41 - AC adapter status updates
42 - Battery status updates
45 + bool "PCEngines ALIX System Support (LED setup)"
48 + This option enables system support for the PCEngines ALIX.
49 + At present this just sets up LEDs for GPIO control on
50 + ALIX2/3/6 boards. However, other system specific setup should
53 + Note: You must still enable the drivers for GPIO and LED support
54 + (GPIO_CS5535 & LEDS_GPIO) to actually use the LEDs
56 + Note: You have to set alix.force=1 for boards with Award BIOS.
61 diff --git a/arch/x86/platform/Makefile b/arch/x86/platform/Makefile
62 index 021eee9..8d87439 100644
63 --- a/arch/x86/platform/Makefile
64 +++ b/arch/x86/platform/Makefile
66 # Platform specific code goes here
73 diff --git a/arch/x86/platform/geode/Makefile b/arch/x86/platform/geode/Makefile
75 index 0000000..07c9cd0
77 +++ b/arch/x86/platform/geode/Makefile
79 +obj-$(CONFIG_ALIX) += alix.o
80 diff --git a/arch/x86/platform/geode/alix.c b/arch/x86/platform/geode/alix.c
82 index 0000000..f3f01e2
84 +++ b/arch/x86/platform/geode/alix.c
87 + * System Specific setup for PCEngines ALIX.
88 + * At the moment this means setup of GPIO control of LEDs
89 + * on Alix.2/3/6 boards.
92 + * Copyright (C) 2008 Constantin Baranov <const@mimas.ru>
93 + * Copyright (C) 2011 Ed Wildgoose <kernel@wildgooses.com>
95 + * TODO: There are large similarities with leds-net5501.c
96 + * by Alessandro Zummo <a.zummo@towertech.it>
97 + * In the future leds-net5501.c should be migrated over to platform
99 + * This program is free software; you can redistribute it and/or modify
100 + * it under the terms of the GNU General Public License version 2
101 + * as published by the Free Software Foundation.
104 +#include <linux/kernel.h>
105 +#include <linux/init.h>
106 +#include <linux/io.h>
107 +#include <linux/string.h>
108 +#include <linux/leds.h>
109 +#include <linux/platform_device.h>
110 +#include <linux/gpio.h>
112 +#include <asm/geode.h>
114 +static int force = 0;
115 +module_param(force, bool, 0444);
116 +/* FIXME: Award bios is not automatically detected as Alix platform */
117 +MODULE_PARM_DESC(force, "Force detection as ALIX.2/ALIX.3 platform");
119 +static struct gpio_led alix_leds[] = {
123 + .default_trigger = "default-on",
129 + .default_trigger = "default-off",
135 + .default_trigger = "default-off",
140 +static struct gpio_led_platform_data alix_leds_data = {
141 + .num_leds = ARRAY_SIZE(alix_leds),
145 +static struct platform_device alix_leds_dev = {
146 + .name = "leds-gpio",
148 + .dev.platform_data = &alix_leds_data,
151 +static void __init register_alix(void)
153 + /* Setup LED control through leds-gpio driver */
154 + platform_device_register(&alix_leds_dev);
157 +static int __init alix_present(unsigned long bios_phys,
158 + const char *alix_sig,
159 + size_t alix_sig_len)
161 + const size_t bios_len = 0x00010000;
162 + const char *bios_virt;
163 + const char *scan_end;
168 + printk(KERN_NOTICE "%s: forced to skip BIOS test, "
169 + "assume system is ALIX.2/ALIX.3\n",
174 + bios_virt = phys_to_virt(bios_phys);
175 + scan_end = bios_virt + bios_len - (alix_sig_len + 2);
176 + for (p = bios_virt; p < scan_end; p++) {
180 + if (memcmp(p, alix_sig, alix_sig_len) != 0)
183 + memcpy(name, p, sizeof(name));
185 + /* remove the first \0 character from string */
186 + a = strchr(name, '\0');
190 + /* cut the string at a newline */
191 + a = strchr(name, '\r');
195 + tail = p + alix_sig_len;
196 + if ((tail[0] == '2' || tail[0] == '3')) {
198 + "%s: system is recognized as \"%s\"\n",
199 + KBUILD_MODNAME, name);
207 +static int __init alix_init(void)
209 + const char tinybios_sig[] = "PC Engines ALIX.";
210 + const char coreboot_sig[] = "PC Engines\0ALIX.";
215 + if (alix_present(0xf0000, tinybios_sig, sizeof(tinybios_sig) - 1) ||
216 + alix_present(0x500, coreboot_sig, sizeof(coreboot_sig) - 1))
222 +module_init(alix_init);
224 +MODULE_AUTHOR("Ed Wildgoose <kernel@wildgooses.com>");
225 +MODULE_DESCRIPTION("PCEngines ALIX System Setup");
226 +MODULE_LICENSE("GPL");
227 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
228 index b591e72..8974d27 100644
229 --- a/drivers/leds/Kconfig
230 +++ b/drivers/leds/Kconfig
233 This option enables support for the PCEngines WRAP programmable LEDs.
236 - tristate "LED Support for ALIX.2 and ALIX.3 series"
237 - depends on LEDS_CLASS
238 - depends on X86 && !GPIO_CS5535 && !CS5535_GPIO
240 - This option enables support for the PCEngines ALIX.2 and ALIX.3 LEDs.
241 - You have to set leds-alix2.force=1 for boards with Award BIOS.
244 tristate "LED Support for iPAQ H1940 device"
245 depends on LEDS_CLASS
246 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
247 index bbfd2e3..a0a1b89 100644
248 --- a/drivers/leds/Makefile
249 +++ b/drivers/leds/Makefile
250 @@ -16,7 +16,6 @@ obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o
251 obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o
252 obj-$(CONFIG_LEDS_NET5501) += leds-net5501.o
253 obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
254 -obj-$(CONFIG_LEDS_ALIX2) += leds-alix2.o
255 obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
256 obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o
257 obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o
258 diff --git a/drivers/leds/leds-alix2.c b/drivers/leds/leds-alix2.c
259 deleted file mode 100644
260 index f59ffad..0000000
261 --- a/drivers/leds/leds-alix2.c
265 - * LEDs driver for PCEngines ALIX.2 and ALIX.3
267 - * Copyright (C) 2008 Constantin Baranov <const@mimas.ru>
270 -#include <linux/err.h>
271 -#include <linux/io.h>
272 -#include <linux/kernel.h>
273 -#include <linux/leds.h>
274 -#include <linux/module.h>
275 -#include <linux/platform_device.h>
276 -#include <linux/string.h>
277 -#include <linux/pci.h>
279 -static int force = 0;
280 -module_param(force, bool, 0444);
281 -MODULE_PARM_DESC(force, "Assume system has ALIX.2/ALIX.3 style LEDs");
283 -#define MSR_LBAR_GPIO 0x5140000C
284 -#define CS5535_GPIO_SIZE 256
286 -static u32 gpio_base;
288 -static struct pci_device_id divil_pci[] = {
289 - { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
290 - { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
291 - { } /* NULL entry */
293 -MODULE_DEVICE_TABLE(pci, divil_pci);
296 - struct led_classdev cdev;
297 - unsigned short port;
298 - unsigned int on_value;
299 - unsigned int off_value;
302 -static void alix_led_set(struct led_classdev *led_cdev,
303 - enum led_brightness brightness)
305 - struct alix_led *led_dev =
306 - container_of(led_cdev, struct alix_led, cdev);
309 - outl(led_dev->on_value, gpio_base + led_dev->port);
311 - outl(led_dev->off_value, gpio_base + led_dev->port);
314 -static struct alix_led alix_leds[] = {
318 - .brightness_set = alix_led_set,
321 - .on_value = 1 << 22,
322 - .off_value = 1 << 6,
327 - .brightness_set = alix_led_set,
330 - .on_value = 1 << 25,
331 - .off_value = 1 << 9,
336 - .brightness_set = alix_led_set,
339 - .on_value = 1 << 27,
340 - .off_value = 1 << 11,
344 -static int __init alix_led_probe(struct platform_device *pdev)
349 - for (i = 0; i < ARRAY_SIZE(alix_leds); i++) {
350 - alix_leds[i].cdev.flags |= LED_CORE_SUSPENDRESUME;
351 - ret = led_classdev_register(&pdev->dev, &alix_leds[i].cdev);
359 - led_classdev_unregister(&alix_leds[i].cdev);
363 -static int alix_led_remove(struct platform_device *pdev)
367 - for (i = 0; i < ARRAY_SIZE(alix_leds); i++)
368 - led_classdev_unregister(&alix_leds[i].cdev);
372 -static struct platform_driver alix_led_driver = {
373 - .remove = alix_led_remove,
375 - .name = KBUILD_MODNAME,
376 - .owner = THIS_MODULE,
380 -static int __init alix_present(unsigned long bios_phys,
381 - const char *alix_sig,
382 - size_t alix_sig_len)
384 - const size_t bios_len = 0x00010000;
385 - const char *bios_virt;
386 - const char *scan_end;
391 - printk(KERN_NOTICE "%s: forced to skip BIOS test, "
392 - "assume system has ALIX.2 style LEDs\n",
397 - bios_virt = phys_to_virt(bios_phys);
398 - scan_end = bios_virt + bios_len - (alix_sig_len + 2);
399 - for (p = bios_virt; p < scan_end; p++) {
403 - if (memcmp(p, alix_sig, alix_sig_len) != 0)
406 - memcpy(name, p, sizeof(name));
408 - /* remove the first \0 character from string */
409 - a = strchr(name, '\0');
413 - /* cut the string at a newline */
414 - a = strchr(name, '\r');
418 - tail = p + alix_sig_len;
419 - if ((tail[0] == '2' || tail[0] == '3')) {
421 - "%s: system is recognized as \"%s\"\n",
422 - KBUILD_MODNAME, name);
430 -static struct platform_device *pdev;
432 -static int __init alix_pci_led_init(void)
436 - if (pci_dev_present(divil_pci) == 0) {
437 - printk(KERN_WARNING KBUILD_MODNAME": DIVIL not found\n");
441 - /* Grab the GPIO I/O range */
442 - rdmsr(MSR_LBAR_GPIO, low, hi);
444 - /* Check the mask and whether GPIO is enabled (sanity check) */
445 - if (hi != 0x0000f001) {
446 - printk(KERN_WARNING KBUILD_MODNAME": GPIO not enabled\n");
450 - /* Mask off the IO base address */
451 - gpio_base = low & 0x0000ff00;
453 - if (!request_region(gpio_base, CS5535_GPIO_SIZE, KBUILD_MODNAME)) {
454 - printk(KERN_ERR KBUILD_MODNAME": can't allocate I/O for GPIO\n");
458 - /* Set GPIO function to output */
459 - outl(1 << 6, gpio_base + 0x04);
460 - outl(1 << 9, gpio_base + 0x84);
461 - outl(1 << 11, gpio_base + 0x84);
466 -static int __init alix_led_init(void)
469 - const char tinybios_sig[] = "PC Engines ALIX.";
470 - const char coreboot_sig[] = "PC Engines\0ALIX.";
472 - if (alix_present(0xf0000, tinybios_sig, sizeof(tinybios_sig) - 1) ||
473 - alix_present(0x500, coreboot_sig, sizeof(coreboot_sig) - 1))
474 - ret = alix_pci_led_init();
479 - pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
480 - if (!IS_ERR(pdev)) {
481 - ret = platform_driver_probe(&alix_led_driver, alix_led_probe);
483 - platform_device_unregister(pdev);
485 - ret = PTR_ERR(pdev);
490 -static void __exit alix_led_exit(void)
492 - platform_device_unregister(pdev);
493 - platform_driver_unregister(&alix_led_driver);
494 - release_region(gpio_base, CS5535_GPIO_SIZE);
497 -module_init(alix_led_init);
498 -module_exit(alix_led_exit);
500 -MODULE_AUTHOR("Constantin Baranov <const@mimas.ru>");
501 -MODULE_DESCRIPTION("PCEngines ALIX.2 and ALIX.3 LED driver");
502 -MODULE_LICENSE("GPL");