iwlwifi: introduce host commands callbacks
[linux/fpc-iii.git] / drivers / leds / leds-clevo-mail.c
blob6c3d33b8e3830f892afefa7045b71945b55192c7
2 #include <linux/module.h>
4 #include <linux/platform_device.h>
5 #include <linux/err.h>
6 #include <linux/leds.h>
8 #include <linux/io.h>
9 #include <linux/dmi.h>
11 #include <linux/i8042.h>
13 #define CLEVO_MAIL_LED_OFF 0x0084
14 #define CLEVO_MAIL_LED_BLINK_1HZ 0x008A
15 #define CLEVO_MAIL_LED_BLINK_0_5HZ 0x0083
17 MODULE_AUTHOR("Márton Németh <nm127@freemail.hu>");
18 MODULE_DESCRIPTION("Clevo mail LED driver");
19 MODULE_LICENSE("GPL");
21 static unsigned int __initdata nodetect;
22 module_param_named(nodetect, nodetect, bool, 0);
23 MODULE_PARM_DESC(nodetect, "Skip DMI hardware detection");
25 static struct platform_device *pdev;
27 static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
29 printk(KERN_INFO KBUILD_MODNAME ": '%s' found\n", id->ident);
30 return 1;
34 * struct mail_led_whitelist - List of known good models
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.
42 static struct dmi_system_id __initdata mail_led_whitelist[] = {
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")
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")
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")
71 .callback = clevo_mail_led_dmi_callback,
72 .ident = "Clevo D410V",
73 .matches = {
74 DMI_MATCH(DMI_BOARD_VENDOR, "Clevo, Co."),
75 DMI_MATCH(DMI_BOARD_NAME, "D400V/D470V"),
76 DMI_MATCH(DMI_BOARD_VERSION, "SS78B"),
77 DMI_MATCH(DMI_PRODUCT_VERSION, "Rev. A1")
80 { }
83 static void clevo_mail_led_set(struct led_classdev *led_cdev,
84 enum led_brightness value)
86 if (value == LED_OFF)
87 i8042_command(NULL, CLEVO_MAIL_LED_OFF);
88 else if (value <= LED_HALF)
89 i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
90 else
91 i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ);
95 static int clevo_mail_led_blink(struct led_classdev *led_cdev,
96 unsigned long* delay_on,
97 unsigned long* delay_off)
99 int status = -EINVAL;
101 if (*delay_on == 0 /* ms */ && *delay_off == 0 /* ms */) {
102 /* Special case: the leds subsystem requested us to
103 * chose one user friendly blinking of the LED, and
104 * start it. Let's blink the led slowly (0.5Hz).
106 *delay_on = 1000; /* ms */
107 *delay_off = 1000; /* ms */
108 i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
109 status = 0;
111 } else if (*delay_on == 500 /* ms */ && *delay_off == 500 /* ms */) {
112 /* blink the led with 1Hz */
113 i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ);
114 status = 0;
116 } else if (*delay_on == 1000 /* ms */ && *delay_off == 1000 /* ms */) {
117 /* blink the led with 0.5Hz */
118 i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
119 status = 0;
121 } else {
122 printk(KERN_DEBUG KBUILD_MODNAME
123 ": clevo_mail_led_blink(..., %lu, %lu),"
124 " returning -EINVAL (unsupported)\n",
125 *delay_on, *delay_off);
128 return status;
131 static struct led_classdev clevo_mail_led = {
132 .name = "clevo::mail",
133 .brightness_set = clevo_mail_led_set,
134 .blink_set = clevo_mail_led_blink,
137 static int __init clevo_mail_led_probe(struct platform_device *pdev)
139 return led_classdev_register(&pdev->dev, &clevo_mail_led);
142 static int clevo_mail_led_remove(struct platform_device *pdev)
144 led_classdev_unregister(&clevo_mail_led);
145 return 0;
148 #ifdef CONFIG_PM
149 static int clevo_mail_led_suspend(struct platform_device *dev,
150 pm_message_t state)
152 led_classdev_suspend(&clevo_mail_led);
153 return 0;
156 static int clevo_mail_led_resume(struct platform_device *dev)
158 led_classdev_resume(&clevo_mail_led);
159 return 0;
161 #else
162 #define clevo_mail_led_suspend NULL
163 #define clevo_mail_led_resume NULL
164 #endif
166 static struct platform_driver clevo_mail_led_driver = {
167 .probe = clevo_mail_led_probe,
168 .remove = clevo_mail_led_remove,
169 .suspend = clevo_mail_led_suspend,
170 .resume = clevo_mail_led_resume,
171 .driver = {
172 .name = KBUILD_MODNAME,
176 static int __init clevo_mail_led_init(void)
178 int error = 0;
179 int count = 0;
181 /* Check with the help of DMI if we are running on supported hardware */
182 if (!nodetect) {
183 count = dmi_check_system(mail_led_whitelist);
184 } else {
185 count = 1;
186 printk(KERN_ERR KBUILD_MODNAME ": Skipping DMI detection. "
187 "If the driver works on your hardware please "
188 "report model and the output of dmidecode in tracker "
189 "at http://sourceforge.net/projects/clevo-mailled/\n");
192 if (!count)
193 return -ENODEV;
195 pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
196 if (!IS_ERR(pdev)) {
197 error = platform_driver_probe(&clevo_mail_led_driver,
198 clevo_mail_led_probe);
199 if (error) {
200 printk(KERN_ERR KBUILD_MODNAME
201 ": Can't probe platform driver\n");
202 platform_device_unregister(pdev);
204 } else
205 error = PTR_ERR(pdev);
207 return error;
210 static void __exit clevo_mail_led_exit(void)
212 platform_device_unregister(pdev);
213 platform_driver_unregister(&clevo_mail_led_driver);
215 clevo_mail_led_set(NULL, LED_OFF);
218 module_init(clevo_mail_led_init);
219 module_exit(clevo_mail_led_exit);