aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <mzxreary@0pointer.de>2006-10-06 01:27:02 -0400
committerLen Brown <len.brown@intel.com>2006-10-14 01:48:29 -0400
commit8c4c731a89ea6458001f48033f8988447736fb38 (patch)
treedd1f7533539e373a60627a6e0d7290365d1fb9db
parentab9e43c640b2b7d6e296fc39dd8cbcb96f9ae393 (diff)
MSI S270 Laptop support: backlight, wlan, bluetooth states
Create a driver to support the platform-specific features of MSI S270 laptops (and maybe other MSI laptops). This driver implements a backlight device for controlling LCD brightness (/sys/class/backlight/msi-laptop-bl/). In addition it allows access to the WLAN and Bluetooth states through a platform driver (/sys/devices/platform/msi-laptop-pf/). Signed-off-by: Lennart Poettering <mzxreary@0pointer.de> Cc: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r--MAINTAINERS7
-rw-r--r--drivers/misc/Kconfig19
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/msi-laptop.c395
4 files changed, 422 insertions, 0 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index 1b5430a49fdd..a2b6d9fa3502 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1998,6 +1998,13 @@ M: rubini@ipvvis.unipv.it
1998L: linux-kernel@vger.kernel.org 1998L: linux-kernel@vger.kernel.org
1999S: Maintained 1999S: Maintained
2000 2000
2001MSI LAPTOP SUPPORT
2002P: Lennart Poettering
2003M: mzxreary@0pointer.de
2004L: https://tango.0pointer.de/mailman/listinfo/s270-linux
2005W: http://0pointer.de/lennart/tchibo.html
2006S: Maintained
2007
2001MTRR AND SIMILAR SUPPORT [i386] 2008MTRR AND SIMILAR SUPPORT [i386]
2002P: Richard Gooch 2009P: Richard Gooch
2003M: rgooch@atnf.csiro.au 2010M: rgooch@atnf.csiro.au
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 3df0e7a07c46..fa7acc2c5c6d 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -57,4 +57,23 @@ config TIFM_7XX1
57 To compile this driver as a module, choose M here: the module will 57 To compile this driver as a module, choose M here: the module will
58 be called tifm_7xx1. 58 be called tifm_7xx1.
59 59
60config MSI_LAPTOP
61 tristate "MSI Laptop Extras"
62 depends on X86
63 depends on ACPI_EC
64 depends on BACKLIGHT_CLASS_DEVICE
65 ---help---
66 This is a driver for laptops built by MSI (MICRO-STAR
67 INTERNATIONAL):
68
69 MSI MegaBook S270 (MS-1013)
70 Cytron/TCM/Medion/Tchibo MD96100/SAM2000
71
72 It adds support for Bluetooth, WLAN and LCD brightness control.
73
74 More information about this driver is available at
75 <http://0pointer.de/lennart/tchibo.html>.
76
77 If you have an MSI S270 laptop, say Y or M here.
78
60endmenu 79endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index d65ece76095a..9a91c1ee8497 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -5,6 +5,7 @@ obj- := misc.o # Dummy rule to force built-in.o to be made
5 5
6obj-$(CONFIG_IBM_ASM) += ibmasm/ 6obj-$(CONFIG_IBM_ASM) += ibmasm/
7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/ 7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/
8obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o
8obj-$(CONFIG_LKDTM) += lkdtm.o 9obj-$(CONFIG_LKDTM) += lkdtm.o
9obj-$(CONFIG_TIFM_CORE) += tifm_core.o 10obj-$(CONFIG_TIFM_CORE) += tifm_core.o
10obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o 11obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o
diff --git a/drivers/misc/msi-laptop.c b/drivers/misc/msi-laptop.c
new file mode 100644
index 000000000000..fdb7153f4426
--- /dev/null
+++ b/drivers/misc/msi-laptop.c
@@ -0,0 +1,395 @@
1/*-*-linux-c-*-*/
2
3/*
4 Copyright (C) 2006 Lennart Poettering <mzxreary (at) 0pointer (dot) de>
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 as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20 */
21
22/*
23 * msi-laptop.c - MSI S270 laptop support. This laptop is sold under
24 * various brands, including "Cytron/TCM/Medion/Tchibo MD96100".
25 *
26 * This driver exports a few files in /sys/devices/platform/msi-laptop-pf/:
27 *
28 * lcd_level - Screen brightness: contains a single integer in the
29 * range 0..8. (rw)
30 *
31 * auto_brightness - Enable automatic brightness control: contains
32 * either 0 or 1. If set to 1 the hardware adjusts the screen
33 * brightness automatically when the power cord is
34 * plugged/unplugged. (rw)
35 *
36 * wlan - WLAN subsystem enabled: contains either 0 or 1. (ro)
37 *
38 * bluetooth - Bluetooth subsystem enabled: contains either 0 or 1
39 * Please note that this file is constantly 0 if no Bluetooth
40 * hardware is available. (ro)
41 *
42 * In addition to these platform device attributes the driver
43 * registers itself in the Linux backlight control subsystem and is
44 * available to userspace under /sys/class/backlight/msi-laptop-bl/.
45 *
46 * This driver might work on other laptops produced by MSI. If you
47 * want to try it you can pass force=1 as argument to the module which
48 * will force it to load even when the DMI data doesn't identify the
49 * laptop as MSI S270. YMMV.
50 */
51
52#include <linux/module.h>
53#include <linux/kernel.h>
54#include <linux/init.h>
55#include <linux/acpi.h>
56#include <linux/dmi.h>
57#include <linux/backlight.h>
58#include <linux/platform_device.h>
59#include <linux/autoconf.h>
60
61#define MSI_DRIVER_VERSION "0.5"
62
63#define MSI_LCD_LEVEL_MAX 9
64
65#define MSI_EC_COMMAND_WIRELESS 0x10
66#define MSI_EC_COMMAND_LCD_LEVEL 0x11
67
68static int force;
69module_param(force, bool, 0);
70MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
71
72static int auto_brightness;
73module_param(auto_brightness, int, 0);
74MODULE_PARM_DESC(auto_brightness, "Enable automatic brightness control (0: disabled; 1: enabled; 2: don't touch)");
75
76/* Hardware access */
77
78static int set_lcd_level(int level)
79{
80 u8 buf[2];
81
82 if (level < 0 || level >= MSI_LCD_LEVEL_MAX)
83 return -EINVAL;
84
85 buf[0] = 0x80;
86 buf[1] = (u8) (level*31);
87
88 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, buf, sizeof(buf), NULL, 0);
89}
90
91static int get_lcd_level(void)
92{
93 u8 wdata = 0, rdata;
94 int result;
95
96 result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1);
97 if (result < 0)
98 return result;
99
100 return (int) rdata / 31;
101}
102
103static int get_auto_brightness(void)
104{
105 u8 wdata = 4, rdata;
106 int result;
107
108 result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1);
109 if (result < 0)
110 return result;
111
112 return !!(rdata & 8);
113}
114
115static int set_auto_brightness(int enable)
116{
117 u8 wdata[2], rdata;
118 int result;
119
120 wdata[0] = 4;
121
122 result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 1, &rdata, 1);
123 if (result < 0)
124 return result;
125
126 wdata[0] = 0x84;
127 wdata[1] = (rdata & 0xF7) | (enable ? 8 : 0);
128
129 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0);
130}
131
132static int get_wireless_state(int *wlan, int *bluetooth)
133{
134 u8 wdata = 0, rdata;
135 int result;
136
137 result = ec_transaction(MSI_EC_COMMAND_WIRELESS, &wdata, 1, &rdata, 1);
138 if (result < 0)
139 return -1;
140
141 if (wlan)
142 *wlan = !!(rdata & 8);
143
144 if (bluetooth)
145 *bluetooth = !!(rdata & 128);
146
147 return 0;
148}
149
150/* Backlight device stuff */
151
152static int bl_get_brightness(struct backlight_device *b)
153{
154 return get_lcd_level();
155}
156
157
158static int bl_update_status(struct backlight_device *b)
159{
160 return set_lcd_level(b->props->brightness);
161}
162
163static struct backlight_properties msibl_props = {
164 .owner = THIS_MODULE,
165 .get_brightness = bl_get_brightness,
166 .update_status = bl_update_status,
167 .max_brightness = MSI_LCD_LEVEL_MAX-1,
168};
169
170static struct backlight_device *msibl_device;
171
172/* Platform device */
173
174static ssize_t show_wlan(struct device *dev,
175 struct device_attribute *attr, char *buf)
176{
177
178 int ret, enabled;
179
180 ret = get_wireless_state(&enabled, NULL);
181 if (ret < 0)
182 return ret;
183
184 return sprintf(buf, "%i\n", enabled);
185}
186
187static ssize_t show_bluetooth(struct device *dev,
188 struct device_attribute *attr, char *buf)
189{
190
191 int ret, enabled;
192
193 ret = get_wireless_state(NULL, &enabled);
194 if (ret < 0)
195 return ret;
196
197 return sprintf(buf, "%i\n", enabled);
198}
199
200static ssize_t show_lcd_level(struct device *dev,
201 struct device_attribute *attr, char *buf)
202{
203
204 int ret;
205
206 ret = get_lcd_level();
207 if (ret < 0)
208 return ret;
209
210 return sprintf(buf, "%i\n", ret);
211}
212
213static ssize_t store_lcd_level(struct device *dev,
214 struct device_attribute *attr, const char *buf, size_t count)
215{
216
217 int level, ret;
218
219 if (sscanf(buf, "%i", &level) != 1 || (level < 0 || level >= MSI_LCD_LEVEL_MAX))
220 return -EINVAL;
221
222 ret = set_lcd_level(level);
223 if (ret < 0)
224 return ret;
225
226 return count;
227}
228
229static ssize_t show_auto_brightness(struct device *dev,
230 struct device_attribute *attr, char *buf)
231{
232
233 int ret;
234
235 ret = get_auto_brightness();
236 if (ret < 0)
237 return ret;
238
239 return sprintf(buf, "%i\n", ret);
240}
241
242static ssize_t store_auto_brightness(struct device *dev,
243 struct device_attribute *attr, const char *buf, size_t count)
244{
245
246 int enable, ret;
247
248 if (sscanf(buf, "%i", &enable) != 1 || (enable != (enable & 1)))
249 return -EINVAL;
250
251 ret = set_auto_brightness(enable);
252 if (ret < 0)
253 return ret;
254
255 return count;
256}
257
258static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
259static DEVICE_ATTR(auto_brightness, 0644, show_auto_brightness, store_auto_brightness);
260static DEVICE_ATTR(bluetooth, 0444, show_bluetooth, NULL);
261static DEVICE_ATTR(wlan, 0444, show_wlan, NULL);
262
263static struct attribute *msipf_attributes[] = {
264 &dev_attr_lcd_level.attr,
265 &dev_attr_auto_brightness.attr,
266 &dev_attr_bluetooth.attr,
267 &dev_attr_wlan.attr,
268 NULL
269};
270
271static struct attribute_group msipf_attribute_group = {
272 .attrs = msipf_attributes
273};
274
275static struct platform_driver msipf_driver = {
276 .driver = {
277 .name = "msi-laptop-pf",
278 .owner = THIS_MODULE,
279 }
280};
281
282static struct platform_device *msipf_device;
283
284/* Initialization */
285
286static struct dmi_system_id __initdata msi_dmi_table[] = {
287 {
288 .ident = "MSI S270",
289 .matches = {
290 DMI_MATCH(DMI_SYS_VENDOR, "MICRO-STAR INT'L CO.,LTD"),
291 DMI_MATCH(DMI_PRODUCT_NAME, "MS-1013"),
292 }
293 },
294 {
295 .ident = "Medion MD96100",
296 .matches = {
297 DMI_MATCH(DMI_SYS_VENDOR, "NOTEBOOK"),
298 DMI_MATCH(DMI_PRODUCT_NAME, "SAM2000"),
299 }
300 },
301 { }
302};
303
304
305static int __init msi_init(void)
306{
307 int ret;
308
309 if (acpi_disabled)
310 return -ENODEV;
311
312 if (!force && !dmi_check_system(msi_dmi_table))
313 return -ENODEV;
314
315 if (auto_brightness < 0 || auto_brightness > 2)
316 return -EINVAL;
317
318 /* Register backlight stuff */
319
320 msibl_device = backlight_device_register("msi-laptop-bl", NULL, &msibl_props);
321 if (IS_ERR(msibl_device))
322 return PTR_ERR(msibl_device);
323
324 ret = platform_driver_register(&msipf_driver);
325 if (ret)
326 goto fail_backlight;
327
328 /* Register platform stuff */
329
330 msipf_device = platform_device_alloc("msi-laptop-pf", -1);
331 if (!msipf_device) {
332 ret = -ENOMEM;
333 goto fail_platform_driver;
334 }
335
336 ret = platform_device_add(msipf_device);
337 if (ret)
338 goto fail_platform_device1;
339
340 ret = sysfs_create_group(&msipf_device->dev.kobj, &msipf_attribute_group);
341 if (ret)
342 goto fail_platform_device2;
343
344 /* Disable automatic brightness control by default because
345 * this module was probably loaded to do brightness control in
346 * software. */
347
348 if (auto_brightness != 2)
349 set_auto_brightness(auto_brightness);
350
351 printk(KERN_INFO "msi-laptop: driver "MSI_DRIVER_VERSION" successfully loaded.\n");
352
353 return 0;
354
355fail_platform_device2:
356
357 platform_device_del(msipf_device);
358
359fail_platform_device1:
360
361 platform_device_put(msipf_device);
362
363fail_platform_driver:
364
365 platform_driver_unregister(&msipf_driver);
366
367fail_backlight:
368
369 backlight_device_unregister(msibl_device);
370
371 return ret;
372}
373
374static void __exit msi_cleanup(void)
375{
376
377 sysfs_remove_group(&msipf_device->dev.kobj, &msipf_attribute_group);
378 platform_device_unregister(msipf_device);
379 platform_driver_unregister(&msipf_driver);
380 backlight_device_unregister(msibl_device);
381
382 /* Enable automatic brightness control again */
383 if (auto_brightness != 2)
384 set_auto_brightness(1);
385
386 printk(KERN_INFO "msi-laptop: driver unloaded.\n");
387}
388
389module_init(msi_init);
390module_exit(msi_cleanup);
391
392MODULE_AUTHOR("Lennart Poettering");
393MODULE_DESCRIPTION("MSI Laptop Support");
394MODULE_VERSION(MSI_DRIVER_VERSION);
395MODULE_LICENSE("GPL");