aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/platform/x86')
-rw-r--r--drivers/platform/x86/Kconfig1
-rw-r--r--drivers/platform/x86/hp-wmi.c4
-rw-r--r--drivers/platform/x86/msi-laptop.c360
3 files changed, 358 insertions, 7 deletions
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index cd2ee6fce1b4..e631dbeafd79 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -150,6 +150,7 @@ config MSI_LAPTOP
150 tristate "MSI Laptop Extras" 150 tristate "MSI Laptop Extras"
151 depends on ACPI 151 depends on ACPI
152 depends on BACKLIGHT_CLASS_DEVICE 152 depends on BACKLIGHT_CLASS_DEVICE
153 depends on RFKILL
153 ---help--- 154 ---help---
154 This is a driver for laptops built by MSI (MICRO-STAR 155 This is a driver for laptops built by MSI (MICRO-STAR
155 INTERNATIONAL): 156 INTERNATIONAL):
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index 3aa57da8b43b..7ccf33c08967 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -57,7 +57,7 @@ enum hp_wmi_radio {
57 HPWMI_WWAN = 2, 57 HPWMI_WWAN = 2,
58}; 58};
59 59
60static int __init hp_wmi_bios_setup(struct platform_device *device); 60static int __devinit hp_wmi_bios_setup(struct platform_device *device);
61static int __exit hp_wmi_bios_remove(struct platform_device *device); 61static int __exit hp_wmi_bios_remove(struct platform_device *device);
62static int hp_wmi_resume_handler(struct device *device); 62static int hp_wmi_resume_handler(struct device *device);
63 63
@@ -447,7 +447,7 @@ static void cleanup_sysfs(struct platform_device *device)
447 device_remove_file(&device->dev, &dev_attr_tablet); 447 device_remove_file(&device->dev, &dev_attr_tablet);
448} 448}
449 449
450static int __init hp_wmi_bios_setup(struct platform_device *device) 450static int __devinit hp_wmi_bios_setup(struct platform_device *device)
451{ 451{
452 int err; 452 int err;
453 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); 453 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
index 759763d18e4c..c2b05da4289a 100644
--- a/drivers/platform/x86/msi-laptop.c
+++ b/drivers/platform/x86/msi-laptop.c
@@ -58,6 +58,7 @@
58#include <linux/dmi.h> 58#include <linux/dmi.h>
59#include <linux/backlight.h> 59#include <linux/backlight.h>
60#include <linux/platform_device.h> 60#include <linux/platform_device.h>
61#include <linux/rfkill.h>
61 62
62#define MSI_DRIVER_VERSION "0.5" 63#define MSI_DRIVER_VERSION "0.5"
63 64
@@ -66,6 +67,20 @@
66#define MSI_EC_COMMAND_WIRELESS 0x10 67#define MSI_EC_COMMAND_WIRELESS 0x10
67#define MSI_EC_COMMAND_LCD_LEVEL 0x11 68#define MSI_EC_COMMAND_LCD_LEVEL 0x11
68 69
70#define MSI_STANDARD_EC_COMMAND_ADDRESS 0x2e
71#define MSI_STANDARD_EC_BLUETOOTH_MASK (1 << 0)
72#define MSI_STANDARD_EC_WEBCAM_MASK (1 << 1)
73#define MSI_STANDARD_EC_WLAN_MASK (1 << 3)
74#define MSI_STANDARD_EC_3G_MASK (1 << 4)
75
76/* For set SCM load flag to disable BIOS fn key */
77#define MSI_STANDARD_EC_SCM_LOAD_ADDRESS 0x2d
78#define MSI_STANDARD_EC_SCM_LOAD_MASK (1 << 0)
79
80static int msi_laptop_resume(struct platform_device *device);
81
82#define MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS 0x2f
83
69static int force; 84static int force;
70module_param(force, bool, 0); 85module_param(force, bool, 0);
71MODULE_PARM_DESC(force, "Force driver load, ignore DMI data"); 86MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
@@ -74,6 +89,23 @@ static int auto_brightness;
74module_param(auto_brightness, int, 0); 89module_param(auto_brightness, int, 0);
75MODULE_PARM_DESC(auto_brightness, "Enable automatic brightness control (0: disabled; 1: enabled; 2: don't touch)"); 90MODULE_PARM_DESC(auto_brightness, "Enable automatic brightness control (0: disabled; 1: enabled; 2: don't touch)");
76 91
92static bool old_ec_model;
93static int wlan_s, bluetooth_s, threeg_s;
94static int threeg_exists;
95
96/* Some MSI 3G netbook only have one fn key to control Wlan/Bluetooth/3G,
97 * those netbook will load the SCM (windows app) to disable the original
98 * Wlan/Bluetooth control by BIOS when user press fn key, then control
99 * Wlan/Bluetooth/3G by SCM (software control by OS). Without SCM, user
100 * cann't on/off 3G module on those 3G netbook.
101 * On Linux, msi-laptop driver will do the same thing to disable the
102 * original BIOS control, then might need use HAL or other userland
103 * application to do the software control that simulate with SCM.
104 * e.g. MSI N034 netbook
105 */
106static bool load_scm_model;
107static struct rfkill *rfk_wlan, *rfk_bluetooth, *rfk_threeg;
108
77/* Hardware access */ 109/* Hardware access */
78 110
79static int set_lcd_level(int level) 111static int set_lcd_level(int level)
@@ -130,6 +162,35 @@ static int set_auto_brightness(int enable)
130 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0, 1); 162 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0, 1);
131} 163}
132 164
165static ssize_t set_device_state(const char *buf, size_t count, u8 mask)
166{
167 int status;
168 u8 wdata = 0, rdata;
169 int result;
170
171 if (sscanf(buf, "%i", &status) != 1 || (status < 0 || status > 1))
172 return -EINVAL;
173
174 /* read current device state */
175 result = ec_read(MSI_STANDARD_EC_COMMAND_ADDRESS, &rdata);
176 if (result < 0)
177 return -EINVAL;
178
179 if (!!(rdata & mask) != status) {
180 /* reverse device bit */
181 if (rdata & mask)
182 wdata = rdata & ~mask;
183 else
184 wdata = rdata | mask;
185
186 result = ec_write(MSI_STANDARD_EC_COMMAND_ADDRESS, wdata);
187 if (result < 0)
188 return -EINVAL;
189 }
190
191 return count;
192}
193
133static int get_wireless_state(int *wlan, int *bluetooth) 194static int get_wireless_state(int *wlan, int *bluetooth)
134{ 195{
135 u8 wdata = 0, rdata; 196 u8 wdata = 0, rdata;
@@ -148,6 +209,38 @@ static int get_wireless_state(int *wlan, int *bluetooth)
148 return 0; 209 return 0;
149} 210}
150 211
212static int get_wireless_state_ec_standard(void)
213{
214 u8 rdata;
215 int result;
216
217 result = ec_read(MSI_STANDARD_EC_COMMAND_ADDRESS, &rdata);
218 if (result < 0)
219 return -1;
220
221 wlan_s = !!(rdata & MSI_STANDARD_EC_WLAN_MASK);
222
223 bluetooth_s = !!(rdata & MSI_STANDARD_EC_BLUETOOTH_MASK);
224
225 threeg_s = !!(rdata & MSI_STANDARD_EC_3G_MASK);
226
227 return 0;
228}
229
230static int get_threeg_exists(void)
231{
232 u8 rdata;
233 int result;
234
235 result = ec_read(MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS, &rdata);
236 if (result < 0)
237 return -1;
238
239 threeg_exists = !!(rdata & MSI_STANDARD_EC_3G_MASK);
240
241 return 0;
242}
243
151/* Backlight device stuff */ 244/* Backlight device stuff */
152 245
153static int bl_get_brightness(struct backlight_device *b) 246static int bl_get_brightness(struct backlight_device *b)
@@ -176,26 +269,71 @@ static ssize_t show_wlan(struct device *dev,
176 269
177 int ret, enabled; 270 int ret, enabled;
178 271
179 ret = get_wireless_state(&enabled, NULL); 272 if (old_ec_model) {
273 ret = get_wireless_state(&enabled, NULL);
274 } else {
275 ret = get_wireless_state_ec_standard();
276 enabled = wlan_s;
277 }
180 if (ret < 0) 278 if (ret < 0)
181 return ret; 279 return ret;
182 280
183 return sprintf(buf, "%i\n", enabled); 281 return sprintf(buf, "%i\n", enabled);
184} 282}
185 283
284static ssize_t store_wlan(struct device *dev,
285 struct device_attribute *attr, const char *buf, size_t count)
286{
287 return set_device_state(buf, count, MSI_STANDARD_EC_WLAN_MASK);
288}
289
186static ssize_t show_bluetooth(struct device *dev, 290static ssize_t show_bluetooth(struct device *dev,
187 struct device_attribute *attr, char *buf) 291 struct device_attribute *attr, char *buf)
188{ 292{
189 293
190 int ret, enabled; 294 int ret, enabled;
191 295
192 ret = get_wireless_state(NULL, &enabled); 296 if (old_ec_model) {
297 ret = get_wireless_state(NULL, &enabled);
298 } else {
299 ret = get_wireless_state_ec_standard();
300 enabled = bluetooth_s;
301 }
193 if (ret < 0) 302 if (ret < 0)
194 return ret; 303 return ret;
195 304
196 return sprintf(buf, "%i\n", enabled); 305 return sprintf(buf, "%i\n", enabled);
197} 306}
198 307
308static ssize_t store_bluetooth(struct device *dev,
309 struct device_attribute *attr, const char *buf, size_t count)
310{
311 return set_device_state(buf, count, MSI_STANDARD_EC_BLUETOOTH_MASK);
312}
313
314static ssize_t show_threeg(struct device *dev,
315 struct device_attribute *attr, char *buf)
316{
317
318 int ret;
319
320 /* old msi ec not support 3G */
321 if (old_ec_model)
322 return -1;
323
324 ret = get_wireless_state_ec_standard();
325 if (ret < 0)
326 return ret;
327
328 return sprintf(buf, "%i\n", threeg_s);
329}
330
331static ssize_t store_threeg(struct device *dev,
332 struct device_attribute *attr, const char *buf, size_t count)
333{
334 return set_device_state(buf, count, MSI_STANDARD_EC_3G_MASK);
335}
336
199static ssize_t show_lcd_level(struct device *dev, 337static ssize_t show_lcd_level(struct device *dev,
200 struct device_attribute *attr, char *buf) 338 struct device_attribute *attr, char *buf)
201{ 339{
@@ -258,6 +396,7 @@ static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
258static DEVICE_ATTR(auto_brightness, 0644, show_auto_brightness, store_auto_brightness); 396static DEVICE_ATTR(auto_brightness, 0644, show_auto_brightness, store_auto_brightness);
259static DEVICE_ATTR(bluetooth, 0444, show_bluetooth, NULL); 397static DEVICE_ATTR(bluetooth, 0444, show_bluetooth, NULL);
260static DEVICE_ATTR(wlan, 0444, show_wlan, NULL); 398static DEVICE_ATTR(wlan, 0444, show_wlan, NULL);
399static DEVICE_ATTR(threeg, 0444, show_threeg, NULL);
261 400
262static struct attribute *msipf_attributes[] = { 401static struct attribute *msipf_attributes[] = {
263 &dev_attr_lcd_level.attr, 402 &dev_attr_lcd_level.attr,
@@ -275,7 +414,8 @@ static struct platform_driver msipf_driver = {
275 .driver = { 414 .driver = {
276 .name = "msi-laptop-pf", 415 .name = "msi-laptop-pf",
277 .owner = THIS_MODULE, 416 .owner = THIS_MODULE,
278 } 417 },
418 .resume = msi_laptop_resume,
279}; 419};
280 420
281static struct platform_device *msipf_device; 421static struct platform_device *msipf_device;
@@ -332,6 +472,192 @@ static struct dmi_system_id __initdata msi_dmi_table[] = {
332 { } 472 { }
333}; 473};
334 474
475static struct dmi_system_id __initdata msi_load_scm_models_dmi_table[] = {
476 {
477 .ident = "MSI N034",
478 .matches = {
479 DMI_MATCH(DMI_SYS_VENDOR,
480 "MICRO-STAR INTERNATIONAL CO., LTD"),
481 DMI_MATCH(DMI_PRODUCT_NAME, "MS-N034"),
482 DMI_MATCH(DMI_CHASSIS_VENDOR,
483 "MICRO-STAR INTERNATIONAL CO., LTD")
484 },
485 .callback = dmi_check_cb
486 },
487 { }
488};
489
490static int rfkill_bluetooth_set(void *data, bool blocked)
491{
492 /* Do something with blocked...*/
493 /*
494 * blocked == false is on
495 * blocked == true is off
496 */
497 if (blocked)
498 set_device_state("0", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
499 else
500 set_device_state("1", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
501
502 return 0;
503}
504
505static int rfkill_wlan_set(void *data, bool blocked)
506{
507 if (blocked)
508 set_device_state("0", 0, MSI_STANDARD_EC_WLAN_MASK);
509 else
510 set_device_state("1", 0, MSI_STANDARD_EC_WLAN_MASK);
511
512 return 0;
513}
514
515static int rfkill_threeg_set(void *data, bool blocked)
516{
517 if (blocked)
518 set_device_state("0", 0, MSI_STANDARD_EC_3G_MASK);
519 else
520 set_device_state("1", 0, MSI_STANDARD_EC_3G_MASK);
521
522 return 0;
523}
524
525static struct rfkill_ops rfkill_bluetooth_ops = {
526 .set_block = rfkill_bluetooth_set
527};
528
529static struct rfkill_ops rfkill_wlan_ops = {
530 .set_block = rfkill_wlan_set
531};
532
533static struct rfkill_ops rfkill_threeg_ops = {
534 .set_block = rfkill_threeg_set
535};
536
537static void rfkill_cleanup(void)
538{
539 if (rfk_bluetooth) {
540 rfkill_unregister(rfk_bluetooth);
541 rfkill_destroy(rfk_bluetooth);
542 }
543
544 if (rfk_threeg) {
545 rfkill_unregister(rfk_threeg);
546 rfkill_destroy(rfk_threeg);
547 }
548
549 if (rfk_wlan) {
550 rfkill_unregister(rfk_wlan);
551 rfkill_destroy(rfk_wlan);
552 }
553}
554
555static int rfkill_init(struct platform_device *sdev)
556{
557 /* add rfkill */
558 int retval;
559
560 rfk_bluetooth = rfkill_alloc("msi-bluetooth", &sdev->dev,
561 RFKILL_TYPE_BLUETOOTH,
562 &rfkill_bluetooth_ops, NULL);
563 if (!rfk_bluetooth) {
564 retval = -ENOMEM;
565 goto err_bluetooth;
566 }
567 retval = rfkill_register(rfk_bluetooth);
568 if (retval)
569 goto err_bluetooth;
570
571 rfk_wlan = rfkill_alloc("msi-wlan", &sdev->dev, RFKILL_TYPE_WLAN,
572 &rfkill_wlan_ops, NULL);
573 if (!rfk_wlan) {
574 retval = -ENOMEM;
575 goto err_wlan;
576 }
577 retval = rfkill_register(rfk_wlan);
578 if (retval)
579 goto err_wlan;
580
581 if (threeg_exists) {
582 rfk_threeg = rfkill_alloc("msi-threeg", &sdev->dev,
583 RFKILL_TYPE_WWAN, &rfkill_threeg_ops, NULL);
584 if (!rfk_threeg) {
585 retval = -ENOMEM;
586 goto err_threeg;
587 }
588 retval = rfkill_register(rfk_threeg);
589 if (retval)
590 goto err_threeg;
591 }
592
593 return 0;
594
595err_threeg:
596 rfkill_destroy(rfk_threeg);
597 if (rfk_wlan)
598 rfkill_unregister(rfk_wlan);
599err_wlan:
600 rfkill_destroy(rfk_wlan);
601 if (rfk_bluetooth)
602 rfkill_unregister(rfk_bluetooth);
603err_bluetooth:
604 rfkill_destroy(rfk_bluetooth);
605
606 return retval;
607}
608
609static int msi_laptop_resume(struct platform_device *device)
610{
611 u8 data;
612 int result;
613
614 if (!load_scm_model)
615 return 0;
616
617 /* set load SCM to disable hardware control by fn key */
618 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
619 if (result < 0)
620 return result;
621
622 result = ec_write(MSI_STANDARD_EC_SCM_LOAD_ADDRESS,
623 data | MSI_STANDARD_EC_SCM_LOAD_MASK);
624 if (result < 0)
625 return result;
626
627 return 0;
628}
629
630static int load_scm_model_init(struct platform_device *sdev)
631{
632 u8 data;
633 int result;
634
635 /* allow userland write sysfs file */
636 dev_attr_bluetooth.store = store_bluetooth;
637 dev_attr_wlan.store = store_wlan;
638 dev_attr_threeg.store = store_threeg;
639 dev_attr_bluetooth.attr.mode |= S_IWUSR;
640 dev_attr_wlan.attr.mode |= S_IWUSR;
641 dev_attr_threeg.attr.mode |= S_IWUSR;
642
643 /* disable hardware control by fn key */
644 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
645 if (result < 0)
646 return result;
647
648 result = ec_write(MSI_STANDARD_EC_SCM_LOAD_ADDRESS,
649 data | MSI_STANDARD_EC_SCM_LOAD_MASK);
650 if (result < 0)
651 return result;
652
653 /* initial rfkill */
654 result = rfkill_init(sdev);
655 if (result < 0)
656 return result;
657
658 return 0;
659}
660
335static int __init msi_init(void) 661static int __init msi_init(void)
336{ 662{
337 int ret; 663 int ret;
@@ -339,8 +665,14 @@ static int __init msi_init(void)
339 if (acpi_disabled) 665 if (acpi_disabled)
340 return -ENODEV; 666 return -ENODEV;
341 667
342 if (!force && !dmi_check_system(msi_dmi_table)) 668 if (force || dmi_check_system(msi_dmi_table))
343 return -ENODEV; 669 old_ec_model = 1;
670
671 if (!old_ec_model)
672 get_threeg_exists();
673
674 if (!old_ec_model && dmi_check_system(msi_load_scm_models_dmi_table))
675 load_scm_model = 1;
344 676
345 if (auto_brightness < 0 || auto_brightness > 2) 677 if (auto_brightness < 0 || auto_brightness > 2)
346 return -EINVAL; 678 return -EINVAL;
@@ -374,10 +706,23 @@ static int __init msi_init(void)
374 if (ret) 706 if (ret)
375 goto fail_platform_device1; 707 goto fail_platform_device1;
376 708
709 if (load_scm_model && (load_scm_model_init(msipf_device) < 0)) {
710 ret = -EINVAL;
711 goto fail_platform_device1;
712 }
713
377 ret = sysfs_create_group(&msipf_device->dev.kobj, &msipf_attribute_group); 714 ret = sysfs_create_group(&msipf_device->dev.kobj, &msipf_attribute_group);
378 if (ret) 715 if (ret)
379 goto fail_platform_device2; 716 goto fail_platform_device2;
380 717
718 if (!old_ec_model) {
719 if (threeg_exists)
720 ret = device_create_file(&msipf_device->dev,
721 &dev_attr_threeg);
722 if (ret)
723 goto fail_platform_device2;
724 }
725
381 /* Disable automatic brightness control by default because 726 /* Disable automatic brightness control by default because
382 * this module was probably loaded to do brightness control in 727 * this module was probably loaded to do brightness control in
383 * software. */ 728 * software. */
@@ -412,10 +757,14 @@ static void __exit msi_cleanup(void)
412{ 757{
413 758
414 sysfs_remove_group(&msipf_device->dev.kobj, &msipf_attribute_group); 759 sysfs_remove_group(&msipf_device->dev.kobj, &msipf_attribute_group);
760 if (!old_ec_model && threeg_exists)
761 device_remove_file(&msipf_device->dev, &dev_attr_threeg);
415 platform_device_unregister(msipf_device); 762 platform_device_unregister(msipf_device);
416 platform_driver_unregister(&msipf_driver); 763 platform_driver_unregister(&msipf_driver);
417 backlight_device_unregister(msibl_device); 764 backlight_device_unregister(msibl_device);
418 765
766 rfkill_cleanup();
767
419 /* Enable automatic brightness control again */ 768 /* Enable automatic brightness control again */
420 if (auto_brightness != 2) 769 if (auto_brightness != 2)
421 set_auto_brightness(1); 770 set_auto_brightness(1);
@@ -435,3 +784,4 @@ MODULE_ALIAS("dmi:*:svnMICRO-STARINT'LCO.,LTD:pnMS-1013:pvr0131*:cvnMICRO-STARIN
435MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1058:pvr0581:rvnMSI:rnMS-1058:*:ct10:*"); 784MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1058:pvr0581:rvnMSI:rnMS-1058:*:ct10:*");
436MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1412:*:rvnMSI:rnMS-1412:*:cvnMICRO-STARINT'LCO.,LTD:ct10:*"); 785MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1412:*:rvnMSI:rnMS-1412:*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
437MODULE_ALIAS("dmi:*:svnNOTEBOOK:pnSAM2000:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*"); 786MODULE_ALIAS("dmi:*:svnNOTEBOOK:pnSAM2000:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
787MODULE_ALIAS("dmi:*:svnMICRO-STARINTERNATIONAL*:pnMS-N034:*");