automatically mount sd-card as it's possible (might be done via hotplug later)
[openwrt.git] / target / linux / generic-2.6 / files-2.6.30 / drivers / leds / leds-alix.c
1 /*
2 * LEDs driver for PCEngines ALIX 2/3 series
3 *
4 * Copyright (C) 2007 Petr Liebman
5 *
6 * Based on leds-wrap.c
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/leds.h>
17 #include <linux/err.h>
18 #include <asm/io.h>
19
20 #define DRVNAME "alix-led"
21
22 #define ALIX_LED1_PORT (0x6100)
23 #define ALIX_LED1_ON (1<<22)
24 #define ALIX_LED1_OFF (1<<6)
25
26 #define ALIX_LED2_PORT (0x6180)
27 #define ALIX_LED2_ON (1<<25)
28 #define ALIX_LED2_OFF (1<<9)
29
30 #define ALIX_LED3_PORT (0x6180)
31 #define ALIX_LED3_ON (1<<27)
32 #define ALIX_LED3_OFF (1<<11)
33
34
35 static struct platform_device *pdev;
36
37 static void alix_led_set_1(struct led_classdev *led_cdev,
38 enum led_brightness value)
39 {
40 if (value)
41 outl(ALIX_LED1_ON, ALIX_LED1_PORT);
42 else
43 outl(ALIX_LED1_OFF, ALIX_LED1_PORT);
44 }
45
46 static void alix_led_set_2(struct led_classdev *led_cdev,
47 enum led_brightness value)
48 {
49 if (value)
50 outl(ALIX_LED2_ON, ALIX_LED2_PORT);
51 else
52 outl(ALIX_LED2_OFF, ALIX_LED2_PORT);
53 }
54
55 static void alix_led_set_3(struct led_classdev *led_cdev,
56 enum led_brightness value)
57 {
58 if (value)
59 outl(ALIX_LED3_ON, ALIX_LED3_PORT);
60 else
61 outl(ALIX_LED3_OFF, ALIX_LED3_PORT);
62 }
63
64 static struct led_classdev alix_led_1 = {
65 .name = "alix:1",
66 .brightness_set = alix_led_set_1,
67 };
68
69 static struct led_classdev alix_led_2 = {
70 .name = "alix:2",
71 .brightness_set = alix_led_set_2,
72 };
73
74 static struct led_classdev alix_led_3 = {
75 .name = "alix:3",
76 .brightness_set = alix_led_set_3,
77 };
78
79
80 #ifdef CONFIG_PM
81 static int alix_led_suspend(struct platform_device *dev,
82 pm_message_t state)
83 {
84 led_classdev_suspend(&alix_led_1);
85 led_classdev_suspend(&alix_led_2);
86 led_classdev_suspend(&alix_led_3);
87 return 0;
88 }
89
90 static int alix_led_resume(struct platform_device *dev)
91 {
92 led_classdev_resume(&alix_led_1);
93 led_classdev_resume(&alix_led_2);
94 led_classdev_resume(&alix_led_3);
95 return 0;
96 }
97 #else
98 #define alix_led_suspend NULL
99 #define alix_led_resume NULL
100 #endif
101
102 static int alix_led_probe(struct platform_device *pdev)
103 {
104 int ret;
105
106 ret = led_classdev_register(&pdev->dev, &alix_led_1);
107 if (ret >= 0)
108 {
109 ret = led_classdev_register(&pdev->dev, &alix_led_2);
110 if (ret >= 0)
111 {
112 ret = led_classdev_register(&pdev->dev, &alix_led_3);
113 if (ret < 0)
114 led_classdev_unregister(&alix_led_2);
115 }
116 if (ret < 0)
117 led_classdev_unregister(&alix_led_1);
118 }
119 return ret;
120 }
121
122 static int alix_led_remove(struct platform_device *pdev)
123 {
124 led_classdev_unregister(&alix_led_1);
125 led_classdev_unregister(&alix_led_2);
126 led_classdev_unregister(&alix_led_3);
127 return 0;
128 }
129
130 static struct platform_driver alix_led_driver = {
131 .probe = alix_led_probe,
132 .remove = alix_led_remove,
133 .suspend = alix_led_suspend,
134 .resume = alix_led_resume,
135 .driver = {
136 .name = DRVNAME,
137 .owner = THIS_MODULE,
138 },
139 };
140
141 static int __init alix_led_init(void)
142 {
143 int ret;
144
145 ret = platform_driver_register(&alix_led_driver);
146 if (ret < 0)
147 goto out;
148
149 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
150 if (IS_ERR(pdev)) {
151 ret = PTR_ERR(pdev);
152 platform_driver_unregister(&alix_led_driver);
153 goto out;
154 }
155
156 out:
157 return ret;
158 }
159
160 static void __exit alix_led_exit(void)
161 {
162 platform_device_unregister(pdev);
163 platform_driver_unregister(&alix_led_driver);
164 }
165
166 module_init(alix_led_init);
167 module_exit(alix_led_exit);
168
169 MODULE_AUTHOR("Petr Liebman");
170 MODULE_DESCRIPTION("PCEngines ALIX LED driver");
171 MODULE_LICENSE("GPL");
172
This page took 0.054868 seconds and 5 git commands to generate.