4 Copyright (C) 2008 Cezary Jackiewicz <cezary.jackiewicz (at) gmail.com>
8 Copyright (C) 2006 Lennart Poettering <mzxreary (at) 0pointer (dot) de>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 * comapl-laptop.c - Compal laptop support.
29 * This driver exports a few files in /sys/devices/platform/compal-laptop/:
31 * lcd_level - Screen brightness: contains a single integer in the
34 * wlan - wlan subsystem state: contains 0 or 1 (rw)
36 * bluetooth - Bluetooth subsystem state: contains 0 or 1 (rw)
38 * raw - raw value taken from embedded controller register (ro)
40 * In addition to these platform device attributes the driver
41 * registers itself in the Linux backlight control subsystem and is
42 * available to userspace under /sys/class/backlight/compal-laptop/.
44 * This driver might work on other laptops produced by Compal. If you
45 * want to try it you can pass force=1 as argument to the module which
46 * will force it to load even when the DMI data doesn't identify the
50 #include <linux/module.h>
51 #include <linux/kernel.h>
52 #include <linux/init.h>
53 #include <linux/acpi.h>
54 #include <linux/dmi.h>
55 #include <linux/backlight.h>
56 #include <linux/platform_device.h>
57 #include <linux/autoconf.h>
59 #define COMPAL_DRIVER_VERSION "0.2.5"
61 #define COMPAL_LCD_LEVEL_MAX 8
63 #define COMPAL_EC_COMMAND_WIRELESS 0xBB
64 #define COMPAL_EC_COMMAND_LCD_LEVEL 0xB9
66 #define KILLSWITCH_MASK 0x10
67 #define WLAN_MASK 0x01
71 module_param(force, bool, 0);
72 MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
76 static int set_lcd_level(int level)
78 if (level < 0 || level >= COMPAL_LCD_LEVEL_MAX)
81 ec_write(COMPAL_EC_COMMAND_LCD_LEVEL, level);
86 static int get_lcd_level(void)
90 ec_read(COMPAL_EC_COMMAND_LCD_LEVEL, &result);
95 static int set_wlan_state(int state)
99 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
101 if ((result & KILLSWITCH_MASK) == 0)
105 value = (u8) (result | WLAN_MASK);
107 value = (u8) (result & ~WLAN_MASK);
108 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
114 static int set_bluetooth_state(int state)
118 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
120 if ((result & KILLSWITCH_MASK) == 0)
124 value = (u8) (result | BT_MASK);
126 value = (u8) (result & ~BT_MASK);
127 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
133 static int get_wireless_state(int *wlan, int *bluetooth)
137 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
140 if ((result & KILLSWITCH_MASK) == 0)
143 *wlan = result & WLAN_MASK;
147 if ((result & KILLSWITCH_MASK) == 0)
150 *bluetooth = (result & BT_MASK) >> 1;
156 /* Backlight device stuff */
158 static int bl_get_brightness(struct backlight_device *b)
160 return get_lcd_level();
164 static int bl_update_status(struct backlight_device *b)
166 return set_lcd_level(b->props.brightness);
169 static struct backlight_ops compalbl_ops = {
170 .get_brightness = bl_get_brightness,
171 .update_status = bl_update_status,
174 static struct backlight_device *compalbl_device;
176 /* Platform device */
178 static ssize_t show_wlan(struct device *dev,
179 struct device_attribute *attr, char *buf)
183 ret = get_wireless_state(&enabled, NULL);
187 return sprintf(buf, "%i\n", enabled);
190 static ssize_t show_raw(struct device *dev,
191 struct device_attribute *attr, char *buf)
195 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
197 return sprintf(buf, "%i\n", result);
200 static ssize_t show_bluetooth(struct device *dev,
201 struct device_attribute *attr, char *buf)
205 ret = get_wireless_state(NULL, &enabled);
209 return sprintf(buf, "%i\n", enabled);
212 static ssize_t show_lcd_level(struct device *dev,
213 struct device_attribute *attr, char *buf)
217 ret = get_lcd_level();
221 return sprintf(buf, "%i\n", ret);
224 static ssize_t store_lcd_level(struct device *dev,
225 struct device_attribute *attr, const char *buf, size_t count)
229 if (sscanf(buf, "%i", &level) != 1 ||
230 (level < 0 || level >= COMPAL_LCD_LEVEL_MAX))
233 ret = set_lcd_level(level);
240 static ssize_t store_wlan_state(struct device *dev,
241 struct device_attribute *attr, const char *buf, size_t count)
245 if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
248 ret = set_wlan_state(state);
255 static ssize_t store_bluetooth_state(struct device *dev,
256 struct device_attribute *attr, const char *buf, size_t count)
260 if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
263 ret = set_bluetooth_state(state);
270 static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
271 static DEVICE_ATTR(bluetooth, 0644, show_bluetooth, store_bluetooth_state);
272 static DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan_state);
273 static DEVICE_ATTR(raw, 0444, show_raw, NULL);
275 static struct attribute *compal_attributes[] = {
276 &dev_attr_lcd_level.attr,
277 &dev_attr_bluetooth.attr,
283 static struct attribute_group compal_attribute_group = {
284 .attrs = compal_attributes
287 static struct platform_driver compal_driver = {
289 .name = "compal-laptop",
290 .owner = THIS_MODULE,
294 static struct platform_device *compal_device;
298 static int dmi_check_cb(const struct dmi_system_id *id)
300 printk(KERN_INFO "compal-laptop: Identified laptop model '%s'.\n",
306 static struct dmi_system_id __initdata compal_dmi_table[] = {
308 .ident = "FL90/IFL90",
310 DMI_MATCH(DMI_BOARD_NAME, "IFL90"),
311 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
313 .callback = dmi_check_cb
316 .ident = "FL90/IFL90",
318 DMI_MATCH(DMI_BOARD_NAME, "IFL90"),
319 DMI_MATCH(DMI_BOARD_VERSION, "REFERENCE"),
321 .callback = dmi_check_cb
324 .ident = "FL91/IFL91",
326 DMI_MATCH(DMI_BOARD_NAME, "IFL91"),
327 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
329 .callback = dmi_check_cb
332 .ident = "FL92/JFL92",
334 DMI_MATCH(DMI_BOARD_NAME, "JFL92"),
335 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
337 .callback = dmi_check_cb
340 .ident = "FT00/IFT00",
342 DMI_MATCH(DMI_BOARD_NAME, "IFT00"),
343 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
345 .callback = dmi_check_cb
350 static int __init compal_init(void)
357 if (!force && !dmi_check_system(compal_dmi_table))
360 /* Register backlight stuff */
362 compalbl_device = backlight_device_register("compal-laptop", NULL, NULL,
364 if (IS_ERR(compalbl_device))
365 return PTR_ERR(compalbl_device);
367 compalbl_device->props.max_brightness = COMPAL_LCD_LEVEL_MAX-1;
369 ret = platform_driver_register(&compal_driver);
373 /* Register platform stuff */
375 compal_device = platform_device_alloc("compal-laptop", -1);
376 if (!compal_device) {
378 goto fail_platform_driver;
381 ret = platform_device_add(compal_device);
383 goto fail_platform_device1;
385 ret = sysfs_create_group(&compal_device->dev.kobj,
386 &compal_attribute_group);
388 goto fail_platform_device2;
390 printk(KERN_INFO "compal-laptop: driver "COMPAL_DRIVER_VERSION
391 " successfully loaded.\n");
395 fail_platform_device2:
397 platform_device_del(compal_device);
399 fail_platform_device1:
401 platform_device_put(compal_device);
403 fail_platform_driver:
405 platform_driver_unregister(&compal_driver);
409 backlight_device_unregister(compalbl_device);
414 static void __exit compal_cleanup(void)
417 sysfs_remove_group(&compal_device->dev.kobj, &compal_attribute_group);
418 platform_device_unregister(compal_device);
419 platform_driver_unregister(&compal_driver);
420 backlight_device_unregister(compalbl_device);
422 printk(KERN_INFO "compal-laptop: driver unloaded.\n");
425 module_init(compal_init);
426 module_exit(compal_cleanup);
428 MODULE_AUTHOR("Cezary Jackiewicz");
429 MODULE_DESCRIPTION("Compal Laptop Support");
430 MODULE_VERSION(COMPAL_DRIVER_VERSION);
431 MODULE_LICENSE("GPL");
433 MODULE_ALIAS("dmi:*:rnIFL90:rvrIFT00:*");
434 MODULE_ALIAS("dmi:*:rnIFL90:rvrREFERENCE:*");
435 MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*");
436 MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*");
437 MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*");