1 --- a/arch/mips/lantiq/falcon/Makefile
2 +++ b/arch/mips/lantiq/falcon/Makefile
3 @@ -2,3 +2,4 @@ obj-y := clk-falcon.o devices.o gpio.o p
5 obj-$(CONFIG_LANTIQ_MACH_EASY98000) += addon-easy98000.o
6 obj-$(CONFIG_LANTIQ_MACH_EASY98000) += mach-easy98000.o
7 +obj-$(CONFIG_LANTIQ_MACH_EASY98000) += dev-leds-easy98000-cpld.o
9 +++ b/arch/mips/lantiq/falcon/dev-leds-easy98000-cpld.c
12 + * EASY98000 CPLD LED driver
14 + * Copyright (C) 2010 Ralph Hempel <ralph.hempel@lantiq.com>
16 + * This program is free software; you can redistribute it and/or modify it
17 + * under the terms of the GNU General Public License version 2 as published
18 + * by the Free Software Foundation.
22 +#include <linux/kernel.h>
23 +#include <linux/version.h>
24 +#include <linux/types.h>
25 +#include <linux/init.h>
26 +#include <linux/platform_device.h>
27 +#include <linux/errno.h>
28 +#include <linux/leds.h>
29 +#include <linux/slab.h>
31 +#include "dev-leds-easy98000-cpld.h"
33 +const char *led_name[8] = {
44 +#define cpld_base7 ((u16 *)(KSEG1 | 0x17c0000c))
45 +#define cpld_base8 ((u16 *)(KSEG1 | 0x17c00012))
47 +#define ltq_r16(reg) __raw_readw(reg)
48 +#define ltq_w16(val, reg) __raw_writew(val, reg)
50 +struct cpld_led_dev {
51 + struct led_classdev cdev;
56 +struct cpld_led_drvdata {
57 + struct cpld_led_dev *led_devs;
61 +void led_set(u8 mask, u16 *base)
63 + ltq_w16(ltq_r16(base) | mask, base);
66 +void led_clear(u8 mask, u16 *base)
68 + ltq_w16(ltq_r16(base) & (~mask), base);
71 +void led_blink_clear(u8 mask, u16 *base)
73 + led_clear(mask, base);
76 +static void led_brightness(struct led_classdev *led_cdev,
77 + enum led_brightness value)
79 + struct cpld_led_dev *led_dev =
80 + container_of(led_cdev, struct cpld_led_dev, cdev);
83 + led_set(led_dev->mask, led_dev->base);
85 + led_clear(led_dev->mask, led_dev->base);
88 +static int led_probe(struct platform_device *pdev)
92 + struct cpld_led_drvdata *drvdata;
95 + drvdata = kzalloc(sizeof(struct cpld_led_drvdata) +
96 + sizeof(struct cpld_led_dev) * MAX_LED,
101 + drvdata->led_devs = (struct cpld_led_dev *) &drvdata[1];
103 + for (i = 0; i < MAX_LED; i++) {
104 + struct cpld_led_dev *led_dev = &drvdata->led_devs[i];
105 + led_dev->cdev.brightness_set = led_brightness;
106 + led_dev->cdev.default_trigger = NULL;
107 + led_dev->mask = 1 << (i % 8);
109 + sprintf(name, "easy98000-cpld:%s", led_name[i]);
110 + led_dev->base = cpld_base8;
112 + sprintf(name, "easy98000-cpld:red:%d", i-8);
113 + led_dev->base = cpld_base7;
115 + led_dev->cdev.name = name;
116 + ret = led_classdev_register(&pdev->dev, &led_dev->cdev);
120 + platform_set_drvdata(pdev, drvdata);
124 + printk("led_probe: 3\n");
125 + for (i = i - 1; i >= 0; i--)
126 + led_classdev_unregister(&drvdata->led_devs[i].cdev);
132 +static int led_remove(struct platform_device *pdev)
135 + struct cpld_led_drvdata *drvdata = platform_get_drvdata(pdev);
136 + for (i = 0; i < MAX_LED; i++)
137 + led_classdev_unregister(&drvdata->led_devs[i].cdev);
142 +static struct platform_driver led_driver = {
143 + .probe = led_probe,
144 + .remove = __devexit_p(led_remove),
147 + .owner = THIS_MODULE,
151 +int __init easy98000_cpld_led_init(void)
153 + pr_info(LED_DESC ", Version " LED_VERSION
154 + " (c) Copyright 2011, Lantiq Deutschland GmbH\n");
155 + return platform_driver_register(&led_driver);
158 +void __exit easy98000_cpld_led_exit(void)
160 + platform_driver_unregister(&led_driver);
163 +module_init(easy98000_cpld_led_init);
164 +module_exit(easy98000_cpld_led_exit);
166 +MODULE_DESCRIPTION(LED_NAME);
167 +MODULE_DESCRIPTION(LED_DESC);
168 +MODULE_AUTHOR("Ralph Hempel <ralph.hempel@lantiq.com>");
169 +MODULE_LICENSE("GPL v2");
172 +++ b/arch/mips/lantiq/falcon/dev-leds-easy98000-cpld.h
175 + * EASY98000 CPLD LED driver
177 + * Copyright (C) 2010 Ralph Hempel <ralph.hempel@lantiq.com>
179 + * This program is free software; you can redistribute it and/or modify it
180 + * under the terms of the GNU General Public License version 2 as published
181 + * by the Free Software Foundation.
184 +#ifndef _INCLUDE_EASY98000_CPLD_LED_H_
185 +#define _INCLUDE_EASY98000_CPLD_LED_H_
187 +#define LED_NAME "easy98000_cpld_led"
188 +#define LED_DESC "EASY98000 LED driver"
189 +#define LED_VERSION "1.0.0"
193 +#endif /* _INCLUDE_EASY98000_CPLD_LED_H_ */