Rewrite LED driver, enable PCMCIA modules
[openwrt/svn-archive/archive.git] / target / linux / rdc-2.6 / files / drivers / leds / leds-rdc3211.c
1 /*
2 * LED driver for RDC3211 boards
3 *
4 * Copyright 2007 Florian Fainelli <florian@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
15 #include <linux/leds.h>
16 #include <linux/err.h>
17
18 #include <asm/io.h>
19
20 #define LED_VAL 0x8000384C // the data ofset of gpio 0~30
21
22 static struct platform_device *pdev;
23
24 static void rdc3211_led_set(struct led_classdev *led_cdev, enum led_brightness brightness)
25 {
26 unsigned long ul_ledstat = 0xffffffff;
27 unsigned long led_bit = 1 << (led_cdev->flags);
28
29 if (brightness)
30 ul_ledstat &= ~led_bit;
31 else
32 ul_ledstat|= led_bit;
33
34 outl(LED_VAL, 0xcf8);
35 outl(ul_ledstat, 0xcfc);
36 }
37
38 static struct led_classdev rdc3211_power_led = {
39 .name = "rdc3211:power",
40 .flags = 15,
41 .brightness_set = rdc3211_led_set,
42 };
43
44 static struct led_classdev rdc3211_dmz_led = {
45 .name = "rdc3211:dmz",
46 .flags = 16,
47 .brightness_set = rdc3211_led_set,
48 };
49
50 static int rdc3211_leds_probe(struct platform_device *pdev)
51 {
52 int ret;
53
54 ret = led_classdev_register(&pdev->dev, &rdc3211_power_led);
55 if (ret < 0)
56 return ret;
57
58 ret = led_classdev_register(&pdev->dev, &rdc3211_dmz_led);
59 if (ret < 0)
60 led_classdev_unregister(&rdc3211_power_led);
61
62 return ret;
63 }
64
65 static int rdc3211_leds_remove(struct platform_device *pdev)
66 {
67 led_classdev_unregister(&rdc3211_power_led);
68 led_classdev_unregister(&rdc3211_dmz_led);
69 return 0;
70 }
71
72 static struct platform_driver rdc3211_leds_driver = {
73 .probe = rdc3211_leds_probe,
74 .remove = rdc3211_leds_remove,
75 .driver = {
76 .name = "rdc3211-leds",
77 }
78 };
79
80 static int __init rdc3211_leds_init(void)
81 {
82 int ret;
83
84 ret = platform_driver_register(&rdc3211_leds_driver);
85 if (ret < 0)
86 goto out;
87
88 pdev = platform_device_register_simple("rdc3211-leds", -1, NULL, 0);
89 if (IS_ERR(pdev)) {
90 ret = PTR_ERR(pdev);
91 platform_driver_unregister(&rdc3211_leds_driver);
92 goto out;
93 }
94
95 out:
96 return ret;
97 }
98
99 static void __exit rdc3211_leds_exit(void)
100 {
101 platform_driver_unregister(&rdc3211_leds_driver);
102 }
103
104 module_init(rdc3211_leds_init);
105 module_exit(rdc3211_leds_exit);
106
107 MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
108 MODULE_DESCRIPTION("RDC3211 LED driver");
109 MODULE_LICENSE("GPL");