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 --- a/arch/x86/Kconfig
37 +++ b/arch/x86/Kconfig
38 @@ -2087,6 +2087,20 @@ config OLPC_XO1
40 Add support for non-essential features of the OLPC XO-1 laptop.
43 + bool "PCEngines ALIX System Support (LED setup)"
46 + This option enables system support for the PCEngines ALIX.
47 + At present this just sets up LEDs for GPIO control on
48 + ALIX2/3/6 boards. However, other system specific setup should
51 + Note: You must still enable the drivers for GPIO and LED support
52 + (GPIO_CS5535 & LEDS_GPIO) to actually use the LEDs
54 + Note: You have to set alix.force=1 for boards with Award BIOS.
59 --- a/arch/x86/platform/Makefile
60 +++ b/arch/x86/platform/Makefile
62 # Platform specific code goes here
70 +++ b/arch/x86/platform/geode/Makefile
72 +obj-$(CONFIG_ALIX) += alix.o
74 +++ b/arch/x86/platform/geode/alix.c
77 + * System Specific setup for PCEngines ALIX.
78 + * At the moment this means setup of GPIO control of LEDs
79 + * on Alix.2/3/6 boards.
82 + * Copyright (C) 2008 Constantin Baranov <const@mimas.ru>
83 + * Copyright (C) 2011 Ed Wildgoose <kernel@wildgooses.com>
85 + * TODO: There are large similarities with leds-net5501.c
86 + * by Alessandro Zummo <a.zummo@towertech.it>
87 + * In the future leds-net5501.c should be migrated over to platform
89 + * This program is free software; you can redistribute it and/or modify
90 + * it under the terms of the GNU General Public License version 2
91 + * as published by the Free Software Foundation.
94 +#include <linux/kernel.h>
95 +#include <linux/init.h>
96 +#include <linux/io.h>
97 +#include <linux/string.h>
98 +#include <linux/leds.h>
99 +#include <linux/platform_device.h>
100 +#include <linux/gpio.h>
102 +#include <asm/geode.h>
104 +static int force = 0;
105 +module_param(force, bool, 0444);
106 +/* FIXME: Award bios is not automatically detected as Alix platform */
107 +MODULE_PARM_DESC(force, "Force detection as ALIX.2/ALIX.3 platform");
109 +static struct gpio_led alix_leds[] = {
113 + .default_trigger = "default-on",
119 + .default_trigger = "default-off",
125 + .default_trigger = "default-off",
130 +static struct gpio_led_platform_data alix_leds_data = {
131 + .num_leds = ARRAY_SIZE(alix_leds),
135 +static struct platform_device alix_leds_dev = {
136 + .name = "leds-gpio",
138 + .dev.platform_data = &alix_leds_data,
141 +static void __init register_alix(void)
143 + /* Setup LED control through leds-gpio driver */
144 + platform_device_register(&alix_leds_dev);
147 +static int __init alix_present(unsigned long bios_phys,
148 + const char *alix_sig,
149 + size_t alix_sig_len)
151 + const size_t bios_len = 0x00010000;
152 + const char *bios_virt;
153 + const char *scan_end;
158 + printk(KERN_NOTICE "%s: forced to skip BIOS test, "
159 + "assume system is ALIX.2/ALIX.3\n",
164 + bios_virt = phys_to_virt(bios_phys);
165 + scan_end = bios_virt + bios_len - (alix_sig_len + 2);
166 + for (p = bios_virt; p < scan_end; p++) {
170 + if (memcmp(p, alix_sig, alix_sig_len) != 0)
173 + memcpy(name, p, sizeof(name));
175 + /* remove the first \0 character from string */
176 + a = strchr(name, '\0');
180 + /* cut the string at a newline */
181 + a = strchr(name, '\r');
185 + tail = p + alix_sig_len;
186 + if ((tail[0] == '2' || tail[0] == '3')) {
188 + "%s: system is recognized as \"%s\"\n",
189 + KBUILD_MODNAME, name);
197 +static int __init alix_init(void)
199 + const char tinybios_sig[] = "PC Engines ALIX.";
200 + const char coreboot_sig[] = "PC Engines\0ALIX.";
205 + if (alix_present(0xf0000, tinybios_sig, sizeof(tinybios_sig) - 1) ||
206 + alix_present(0x500, coreboot_sig, sizeof(coreboot_sig) - 1))
212 +module_init(alix_init);
214 +MODULE_AUTHOR("Ed Wildgoose <kernel@wildgooses.com>");
215 +MODULE_DESCRIPTION("PCEngines ALIX System Setup");
216 +MODULE_LICENSE("GPL");
217 --- a/drivers/leds/Kconfig
218 +++ b/drivers/leds/Kconfig
219 @@ -107,14 +107,6 @@ config LEDS_WRAP
221 This option enables support for the PCEngines WRAP programmable LEDs.
224 - tristate "LED Support for ALIX.2 and ALIX.3 series"
225 - depends on LEDS_CLASS
226 - depends on X86 && !GPIO_CS5535 && !CS5535_GPIO
228 - This option enables support for the PCEngines ALIX.2 and ALIX.3 LEDs.
229 - You have to set leds-alix2.force=1 for boards with Award BIOS.
232 tristate "LED Support for iPAQ H1940 device"
233 depends on LEDS_CLASS
234 --- a/drivers/leds/Makefile
235 +++ b/drivers/leds/Makefile
236 @@ -16,7 +16,6 @@ obj-$(CONFIG_LEDS_AMS_DELTA) += leds-am
237 obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o
238 obj-$(CONFIG_LEDS_NET5501) += leds-net5501.o
239 obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
240 -obj-$(CONFIG_LEDS_ALIX2) += leds-alix2.o
241 obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
242 obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o
243 obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o
244 --- a/drivers/leds/leds-alix2.c
248 - * LEDs driver for PCEngines ALIX.2 and ALIX.3
250 - * Copyright (C) 2008 Constantin Baranov <const@mimas.ru>
253 -#include <linux/err.h>
254 -#include <linux/io.h>
255 -#include <linux/kernel.h>
256 -#include <linux/leds.h>
257 -#include <linux/module.h>
258 -#include <linux/platform_device.h>
259 -#include <linux/string.h>
260 -#include <linux/pci.h>
262 -static int force = 0;
263 -module_param(force, bool, 0444);
264 -MODULE_PARM_DESC(force, "Assume system has ALIX.2/ALIX.3 style LEDs");
266 -#define MSR_LBAR_GPIO 0x5140000C
267 -#define CS5535_GPIO_SIZE 256
269 -static u32 gpio_base;
271 -static struct pci_device_id divil_pci[] = {
272 - { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
273 - { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
274 - { } /* NULL entry */
276 -MODULE_DEVICE_TABLE(pci, divil_pci);
279 - struct led_classdev cdev;
280 - unsigned short port;
281 - unsigned int on_value;
282 - unsigned int off_value;
285 -static void alix_led_set(struct led_classdev *led_cdev,
286 - enum led_brightness brightness)
288 - struct alix_led *led_dev =
289 - container_of(led_cdev, struct alix_led, cdev);
292 - outl(led_dev->on_value, gpio_base + led_dev->port);
294 - outl(led_dev->off_value, gpio_base + led_dev->port);
297 -static struct alix_led alix_leds[] = {
301 - .brightness_set = alix_led_set,
304 - .on_value = 1 << 22,
305 - .off_value = 1 << 6,
310 - .brightness_set = alix_led_set,
313 - .on_value = 1 << 25,
314 - .off_value = 1 << 9,
319 - .brightness_set = alix_led_set,
322 - .on_value = 1 << 27,
323 - .off_value = 1 << 11,
327 -static int __init alix_led_probe(struct platform_device *pdev)
332 - for (i = 0; i < ARRAY_SIZE(alix_leds); i++) {
333 - alix_leds[i].cdev.flags |= LED_CORE_SUSPENDRESUME;
334 - ret = led_classdev_register(&pdev->dev, &alix_leds[i].cdev);
342 - led_classdev_unregister(&alix_leds[i].cdev);
346 -static int alix_led_remove(struct platform_device *pdev)
350 - for (i = 0; i < ARRAY_SIZE(alix_leds); i++)
351 - led_classdev_unregister(&alix_leds[i].cdev);
355 -static struct platform_driver alix_led_driver = {
356 - .remove = alix_led_remove,
358 - .name = KBUILD_MODNAME,
359 - .owner = THIS_MODULE,
363 -static int __init alix_present(unsigned long bios_phys,
364 - const char *alix_sig,
365 - size_t alix_sig_len)
367 - const size_t bios_len = 0x00010000;
368 - const char *bios_virt;
369 - const char *scan_end;
374 - printk(KERN_NOTICE "%s: forced to skip BIOS test, "
375 - "assume system has ALIX.2 style LEDs\n",
380 - bios_virt = phys_to_virt(bios_phys);
381 - scan_end = bios_virt + bios_len - (alix_sig_len + 2);
382 - for (p = bios_virt; p < scan_end; p++) {
386 - if (memcmp(p, alix_sig, alix_sig_len) != 0)
389 - memcpy(name, p, sizeof(name));
391 - /* remove the first \0 character from string */
392 - a = strchr(name, '\0');
396 - /* cut the string at a newline */
397 - a = strchr(name, '\r');
401 - tail = p + alix_sig_len;
402 - if ((tail[0] == '2' || tail[0] == '3')) {
404 - "%s: system is recognized as \"%s\"\n",
405 - KBUILD_MODNAME, name);
413 -static struct platform_device *pdev;
415 -static int __init alix_pci_led_init(void)
419 - if (pci_dev_present(divil_pci) == 0) {
420 - printk(KERN_WARNING KBUILD_MODNAME": DIVIL not found\n");
424 - /* Grab the GPIO I/O range */
425 - rdmsr(MSR_LBAR_GPIO, low, hi);
427 - /* Check the mask and whether GPIO is enabled (sanity check) */
428 - if (hi != 0x0000f001) {
429 - printk(KERN_WARNING KBUILD_MODNAME": GPIO not enabled\n");
433 - /* Mask off the IO base address */
434 - gpio_base = low & 0x0000ff00;
436 - if (!request_region(gpio_base, CS5535_GPIO_SIZE, KBUILD_MODNAME)) {
437 - printk(KERN_ERR KBUILD_MODNAME": can't allocate I/O for GPIO\n");
441 - /* Set GPIO function to output */
442 - outl(1 << 6, gpio_base + 0x04);
443 - outl(1 << 9, gpio_base + 0x84);
444 - outl(1 << 11, gpio_base + 0x84);
449 -static int __init alix_led_init(void)
452 - const char tinybios_sig[] = "PC Engines ALIX.";
453 - const char coreboot_sig[] = "PC Engines\0ALIX.";
455 - if (alix_present(0xf0000, tinybios_sig, sizeof(tinybios_sig) - 1) ||
456 - alix_present(0x500, coreboot_sig, sizeof(coreboot_sig) - 1))
457 - ret = alix_pci_led_init();
462 - pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
463 - if (!IS_ERR(pdev)) {
464 - ret = platform_driver_probe(&alix_led_driver, alix_led_probe);
466 - platform_device_unregister(pdev);
468 - ret = PTR_ERR(pdev);
473 -static void __exit alix_led_exit(void)
475 - platform_device_unregister(pdev);
476 - platform_driver_unregister(&alix_led_driver);
477 - release_region(gpio_base, CS5535_GPIO_SIZE);
480 -module_init(alix_led_init);
481 -module_exit(alix_led_exit);
483 -MODULE_AUTHOR("Constantin Baranov <const@mimas.ru>");
484 -MODULE_DESCRIPTION("PCEngines ALIX.2 and ALIX.3 LED driver");
485 -MODULE_LICENSE("GPL");