]>
Commit | Line | Data |
---|---|---|
cec035de MN |
1 | |
2 | #include <linux/module.h> | |
3 | ||
4 | #include <linux/platform_device.h> | |
5 | #include <linux/err.h> | |
6 | #include <linux/leds.h> | |
7 | ||
8 | #include <linux/io.h> | |
9 | #include <linux/dmi.h> | |
10 | ||
11 | #include <linux/i8042.h> | |
12 | ||
13 | #define CLEVO_MAIL_LED_OFF 0x0084 | |
14 | #define CLEVO_MAIL_LED_BLINK_1HZ 0x008A | |
15 | #define CLEVO_MAIL_LED_BLINK_0_5HZ 0x0083 | |
16 | ||
4d404fd5 | 17 | MODULE_AUTHOR("Márton Németh <nm127@freemail.hu>"); |
cec035de MN |
18 | MODULE_DESCRIPTION("Clevo mail LED driver"); |
19 | MODULE_LICENSE("GPL"); | |
20 | ||
90ab5ee9 | 21 | static bool __initdata nodetect; |
cec035de MN |
22 | module_param_named(nodetect, nodetect, bool, 0); |
23 | MODULE_PARM_DESC(nodetect, "Skip DMI hardware detection"); | |
24 | ||
25 | static struct platform_device *pdev; | |
26 | ||
27 | static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id) | |
28 | { | |
29 | printk(KERN_INFO KBUILD_MODNAME ": '%s' found\n", id->ident); | |
30 | return 1; | |
31 | } | |
32 | ||
33 | /* | |
96f09791 | 34 | * struct clevo_mail_led_dmi_table - List of known good models |
cec035de MN |
35 | * |
36 | * Contains the known good models this driver is compatible with. | |
37 | * When adding a new model try to be as strict as possible. This | |
38 | * makes it possible to keep the false positives (the model is | |
39 | * detected as working, but in reality it is not) as low as | |
40 | * possible. | |
41 | */ | |
96f09791 | 42 | static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = { |
cec035de MN |
43 | { |
44 | .callback = clevo_mail_led_dmi_callback, | |
45 | .ident = "Clevo D410J", | |
46 | .matches = { | |
47 | DMI_MATCH(DMI_SYS_VENDOR, "VIA"), | |
48 | DMI_MATCH(DMI_PRODUCT_NAME, "K8N800"), | |
49 | DMI_MATCH(DMI_PRODUCT_VERSION, "VT8204B") | |
50 | } | |
51 | }, | |
52 | { | |
53 | .callback = clevo_mail_led_dmi_callback, | |
54 | .ident = "Clevo M5x0N", | |
55 | .matches = { | |
56 | DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."), | |
57 | DMI_MATCH(DMI_PRODUCT_NAME, "M5x0N") | |
58 | } | |
59 | }, | |
60 | { | |
61 | .callback = clevo_mail_led_dmi_callback, | |
62 | .ident = "Positivo Mobile", | |
63 | .matches = { | |
64 | DMI_MATCH(DMI_BOARD_VENDOR, "CLEVO Co. "), | |
65 | DMI_MATCH(DMI_BOARD_NAME, "M5X0V "), | |
66 | DMI_MATCH(DMI_PRODUCT_NAME, "Positivo Mobile"), | |
67 | DMI_MATCH(DMI_PRODUCT_VERSION, "VT6198") | |
68 | } | |
69 | }, | |
b3ba31f8 MN |
70 | { |
71 | .callback = clevo_mail_led_dmi_callback, | |
72 | .ident = "Clevo D400P", | |
73 | .matches = { | |
74 | DMI_MATCH(DMI_BOARD_VENDOR, "Clevo"), | |
75 | DMI_MATCH(DMI_BOARD_NAME, "D400P"), | |
76 | DMI_MATCH(DMI_BOARD_VERSION, "Rev.A"), | |
77 | DMI_MATCH(DMI_PRODUCT_VERSION, "0106") | |
78 | } | |
79 | }, | |
cec035de MN |
80 | { |
81 | .callback = clevo_mail_led_dmi_callback, | |
82 | .ident = "Clevo D410V", | |
83 | .matches = { | |
84 | DMI_MATCH(DMI_BOARD_VENDOR, "Clevo, Co."), | |
85 | DMI_MATCH(DMI_BOARD_NAME, "D400V/D470V"), | |
86 | DMI_MATCH(DMI_BOARD_VERSION, "SS78B"), | |
87 | DMI_MATCH(DMI_PRODUCT_VERSION, "Rev. A1") | |
88 | } | |
89 | }, | |
90 | { } | |
91 | }; | |
96f09791 | 92 | MODULE_DEVICE_TABLE(dmi, clevo_mail_led_dmi_table); |
cec035de MN |
93 | |
94 | static void clevo_mail_led_set(struct led_classdev *led_cdev, | |
95 | enum led_brightness value) | |
96 | { | |
181d683d DT |
97 | i8042_lock_chip(); |
98 | ||
cec035de MN |
99 | if (value == LED_OFF) |
100 | i8042_command(NULL, CLEVO_MAIL_LED_OFF); | |
101 | else if (value <= LED_HALF) | |
102 | i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ); | |
103 | else | |
104 | i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ); | |
105 | ||
181d683d DT |
106 | i8042_unlock_chip(); |
107 | ||
cec035de MN |
108 | } |
109 | ||
92e015cb | 110 | static int clevo_mail_led_blink(struct led_classdev *led_cdev, |
4d404fd5 NM |
111 | unsigned long *delay_on, |
112 | unsigned long *delay_off) | |
92e015cb MN |
113 | { |
114 | int status = -EINVAL; | |
115 | ||
181d683d DT |
116 | i8042_lock_chip(); |
117 | ||
92e015cb MN |
118 | if (*delay_on == 0 /* ms */ && *delay_off == 0 /* ms */) { |
119 | /* Special case: the leds subsystem requested us to | |
120 | * chose one user friendly blinking of the LED, and | |
121 | * start it. Let's blink the led slowly (0.5Hz). | |
122 | */ | |
123 | *delay_on = 1000; /* ms */ | |
124 | *delay_off = 1000; /* ms */ | |
125 | i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ); | |
126 | status = 0; | |
127 | ||
128 | } else if (*delay_on == 500 /* ms */ && *delay_off == 500 /* ms */) { | |
129 | /* blink the led with 1Hz */ | |
130 | i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ); | |
131 | status = 0; | |
132 | ||
133 | } else if (*delay_on == 1000 /* ms */ && *delay_off == 1000 /* ms */) { | |
134 | /* blink the led with 0.5Hz */ | |
135 | i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ); | |
136 | status = 0; | |
137 | ||
138 | } else { | |
139 | printk(KERN_DEBUG KBUILD_MODNAME | |
140 | ": clevo_mail_led_blink(..., %lu, %lu)," | |
141 | " returning -EINVAL (unsupported)\n", | |
142 | *delay_on, *delay_off); | |
143 | } | |
144 | ||
181d683d DT |
145 | i8042_unlock_chip(); |
146 | ||
92e015cb MN |
147 | return status; |
148 | } | |
149 | ||
cec035de | 150 | static struct led_classdev clevo_mail_led = { |
6c152bee | 151 | .name = "clevo::mail", |
cec035de | 152 | .brightness_set = clevo_mail_led_set, |
92e015cb | 153 | .blink_set = clevo_mail_led_blink, |
859cb7f2 | 154 | .flags = LED_CORE_SUSPENDRESUME, |
cec035de MN |
155 | }; |
156 | ||
f16a5dba | 157 | static int __devinit clevo_mail_led_probe(struct platform_device *pdev) |
cec035de MN |
158 | { |
159 | return led_classdev_register(&pdev->dev, &clevo_mail_led); | |
160 | } | |
161 | ||
162 | static int clevo_mail_led_remove(struct platform_device *pdev) | |
163 | { | |
164 | led_classdev_unregister(&clevo_mail_led); | |
165 | return 0; | |
166 | } | |
167 | ||
cec035de MN |
168 | static struct platform_driver clevo_mail_led_driver = { |
169 | .probe = clevo_mail_led_probe, | |
170 | .remove = clevo_mail_led_remove, | |
cec035de MN |
171 | .driver = { |
172 | .name = KBUILD_MODNAME, | |
3c4ded97 | 173 | .owner = THIS_MODULE, |
cec035de MN |
174 | }, |
175 | }; | |
176 | ||
177 | static int __init clevo_mail_led_init(void) | |
178 | { | |
179 | int error = 0; | |
180 | int count = 0; | |
181 | ||
182 | /* Check with the help of DMI if we are running on supported hardware */ | |
183 | if (!nodetect) { | |
96f09791 | 184 | count = dmi_check_system(clevo_mail_led_dmi_table); |
cec035de MN |
185 | } else { |
186 | count = 1; | |
187 | printk(KERN_ERR KBUILD_MODNAME ": Skipping DMI detection. " | |
188 | "If the driver works on your hardware please " | |
189 | "report model and the output of dmidecode in tracker " | |
190 | "at http://sourceforge.net/projects/clevo-mailled/\n"); | |
191 | } | |
192 | ||
193 | if (!count) | |
194 | return -ENODEV; | |
195 | ||
196 | pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0); | |
197 | if (!IS_ERR(pdev)) { | |
198 | error = platform_driver_probe(&clevo_mail_led_driver, | |
199 | clevo_mail_led_probe); | |
200 | if (error) { | |
201 | printk(KERN_ERR KBUILD_MODNAME | |
202 | ": Can't probe platform driver\n"); | |
203 | platform_device_unregister(pdev); | |
204 | } | |
205 | } else | |
206 | error = PTR_ERR(pdev); | |
207 | ||
208 | return error; | |
209 | } | |
210 | ||
211 | static void __exit clevo_mail_led_exit(void) | |
212 | { | |
213 | platform_device_unregister(pdev); | |
214 | platform_driver_unregister(&clevo_mail_led_driver); | |
215 | ||
216 | clevo_mail_led_set(NULL, LED_OFF); | |
217 | } | |
218 | ||
219 | module_init(clevo_mail_led_init); | |
220 | module_exit(clevo_mail_led_exit); |