54 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
56 #include <linux/module.h>
57 #include <linux/kernel.h>
63 #include <linux/rfkill.h>
65 #include <linux/input.h>
68 #define MSI_DRIVER_VERSION "0.5"
70 #define MSI_LCD_LEVEL_MAX 9
72 #define MSI_EC_COMMAND_WIRELESS 0x10
73 #define MSI_EC_COMMAND_LCD_LEVEL 0x11
75 #define MSI_STANDARD_EC_COMMAND_ADDRESS 0x2e
76 #define MSI_STANDARD_EC_BLUETOOTH_MASK (1 << 0)
77 #define MSI_STANDARD_EC_WEBCAM_MASK (1 << 1)
78 #define MSI_STANDARD_EC_WLAN_MASK (1 << 3)
79 #define MSI_STANDARD_EC_3G_MASK (1 << 4)
82 #define MSI_STANDARD_EC_SCM_LOAD_ADDRESS 0x2d
83 #define MSI_STANDARD_EC_SCM_LOAD_MASK (1 << 0)
85 #define MSI_STANDARD_EC_TOUCHPAD_ADDRESS 0xe4
86 #define MSI_STANDARD_EC_TOUCHPAD_MASK (1 << 4)
88 #ifdef CONFIG_PM_SLEEP
93 #define MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS 0x2f
99 static int auto_brightness;
101 MODULE_PARM_DESC(auto_brightness,
"Enable automatic brightness control (0: disabled; 1: enabled; 2: don't touch)");
103 static const struct key_entry msi_laptop_keymap[] = {
109 static struct input_dev *msi_laptop_input_dev;
111 static bool old_ec_model;
112 static int wlan_s, bluetooth_s, threeg_s;
113 static int threeg_exists;
125 static bool load_scm_model;
126 static struct rfkill *rfk_wlan, *rfk_bluetooth, *rfk_threeg;
130 static int set_lcd_level(
int level)
138 buf[1] = (
u8) (level*31);
144 static int get_lcd_level(
void)
154 return (
int) rdata / 31;
157 static int get_auto_brightness(
void)
167 return !!(rdata & 8);
170 static int set_auto_brightness(
int enable)
183 wdata[1] = (rdata & 0xF7) | (enable ? 8 : 0);
203 if (!!(rdata & mask) != status) {
206 wdata = rdata & ~mask;
208 wdata = rdata |
mask;
218 static int get_wireless_state(
int *wlan,
int *
bluetooth)
228 *wlan = !!(rdata & 8);
231 *bluetooth = !!(rdata & 128);
236 static int get_wireless_state_ec_standard(
void)
254 static int get_threeg_exists(
void)
272 return get_lcd_level();
278 return set_lcd_level(b->
props.brightness);
282 .get_brightness = bl_get_brightness,
283 .update_status = bl_update_status,
297 ret = get_wireless_state(&enabled,
NULL);
299 ret = get_wireless_state_ec_standard();
305 return sprintf(buf,
"%i\n", enabled);
321 ret = get_wireless_state(
NULL, &enabled);
323 ret = get_wireless_state_ec_standard();
324 enabled = bluetooth_s;
329 return sprintf(buf,
"%i\n", enabled);
348 ret = get_wireless_state_ec_standard();
352 return sprintf(buf,
"%i\n", threeg_s);
367 ret = get_lcd_level();
371 return sprintf(buf,
"%i\n", ret);
380 if (
sscanf(buf,
"%i", &level) != 1 ||
384 ret = set_lcd_level(level);
397 ret = get_auto_brightness();
401 return sprintf(buf,
"%i\n", ret);
410 if (
sscanf(buf,
"%i", &enable) != 1 || (enable != (enable & 1)))
413 ret = set_auto_brightness(enable);
420 static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
421 static DEVICE_ATTR(auto_brightness, 0644, show_auto_brightness,
422 store_auto_brightness);
427 static struct attribute *msipf_attributes[] = {
428 &dev_attr_lcd_level.attr,
429 &dev_attr_auto_brightness.attr,
430 &dev_attr_bluetooth.attr,
436 .attrs = msipf_attributes
441 .name =
"msi-laptop-pf",
443 .pm = &msi_laptop_pm,
465 "MICRO-STAR INT'L CO.,LTD")
467 .callback = dmi_check_cb
477 .callback = dmi_check_cb
487 .callback = dmi_check_cb
490 .ident =
"Medion MD96100",
496 "MICRO-STAR INT'L CO.,LTD")
498 .callback = dmi_check_cb
508 "MICRO-STAR INTERNATIONAL CO., LTD"),
511 "MICRO-STAR INTERNATIONAL CO., LTD")
513 .callback = dmi_check_cb
519 "MICRO-STAR INTERNATIONAL CO., LTD"),
522 "MICRO-STAR INTERNATIONAL CO., LTD")
524 .callback = dmi_check_cb
530 "MICRO-STAR INTERNATIONAL CO., LTD"),
533 .callback = dmi_check_cb
536 .ident =
"MSI CR620",
539 "Micro-Star International"),
542 .callback = dmi_check_cb
548 "Micro-Star International Co., Ltd."),
551 .callback = dmi_check_cb
556 static int rfkill_bluetooth_set(
void *
data,
bool blocked)
571 static int rfkill_wlan_set(
void *data,
bool blocked)
581 static int rfkill_threeg_set(
void *data,
bool blocked)
591 static const struct rfkill_ops rfkill_bluetooth_ops = {
592 .set_block = rfkill_bluetooth_set
595 static const struct rfkill_ops rfkill_wlan_ops = {
596 .set_block = rfkill_wlan_set
599 static const struct rfkill_ops rfkill_threeg_ops = {
600 .set_block = rfkill_threeg_set
603 static void rfkill_cleanup(
void)
623 get_wireless_state_ec_standard();
634 static void msi_send_touchpad_key(
struct work_struct *ignored)
643 sparse_keymap_report_event(msi_laptop_input_dev,
649 static bool msi_laptop_i8042_filter(
unsigned char data,
unsigned char str,
652 static bool extended;
680 static void msi_init_rfkill(
struct work_struct *ignored)
684 rfkill_wlan_set(
NULL, !wlan_s);
688 rfkill_bluetooth_set(
NULL, !bluetooth_s);
692 rfkill_threeg_set(
NULL, !threeg_s);
703 get_wireless_state_ec_standard();
707 &rfkill_bluetooth_ops,
NULL);
708 if (!rfk_bluetooth) {
717 &rfkill_wlan_ops,
NULL);
758 #ifdef CONFIG_PM_SLEEP
781 static int __init msi_laptop_input_setup(
void)
785 msi_laptop_input_dev = input_allocate_device();
786 if (!msi_laptop_input_dev)
789 msi_laptop_input_dev->name =
"MSI Laptop hotkeys";
790 msi_laptop_input_dev->phys =
"msi-laptop/input0";
791 msi_laptop_input_dev->id.bustype =
BUS_HOST;
793 err = sparse_keymap_setup(msi_laptop_input_dev,
794 msi_laptop_keymap,
NULL);
798 err = input_register_device(msi_laptop_input_dev);
800 goto err_free_keymap;
805 sparse_keymap_free(msi_laptop_input_dev);
807 input_free_device(msi_laptop_input_dev);
811 static void msi_laptop_input_destroy(
void)
813 sparse_keymap_free(msi_laptop_input_dev);
814 input_unregister_device(msi_laptop_input_dev);
823 dev_attr_bluetooth.store = store_bluetooth;
824 dev_attr_wlan.store = store_wlan;
825 dev_attr_threeg.store = store_threeg;
826 dev_attr_bluetooth.attr.mode |=
S_IWUSR;
827 dev_attr_wlan.attr.mode |=
S_IWUSR;
828 dev_attr_threeg.attr.mode |=
S_IWUSR;
841 result = rfkill_init(sdev);
846 result = msi_laptop_input_setup();
852 pr_err(
"Unable to install key filter\n");
859 msi_laptop_input_destroy();
870 static int __init msi_init(
void)
886 if (auto_brightness < 0 || auto_brightness > 2)
892 pr_info(
"Brightness ignored, must be controlled by ACPI video driver\n");
901 if (IS_ERR(msibl_device))
902 return PTR_ERR(msibl_device);
914 goto fail_platform_driver;
919 goto fail_platform_device1;
921 if (load_scm_model && (load_scm_model_init(msipf_device) < 0)) {
923 goto fail_platform_device1;
927 &msipf_attribute_group);
929 goto fail_platform_device2;
936 goto fail_platform_device2;
943 if (auto_brightness != 2)
944 set_auto_brightness(auto_brightness);
950 fail_platform_device2:
952 if (load_scm_model) {
959 fail_platform_device1:
963 fail_platform_driver:
974 static void __exit msi_cleanup(
void)
976 if (load_scm_model) {
978 msi_laptop_input_destroy();
984 if (!old_ec_model && threeg_exists)
991 if (auto_brightness != 2)
992 set_auto_brightness(1);
1005 MODULE_ALIAS(
"dmi:*:svnMICRO-STARINT'LCO.,LTD:pnMS-1013:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
1006 MODULE_ALIAS(
"dmi:*:svnMicro-StarInternational:pnMS-1058:pvr0581:rvnMSI:rnMS-1058:*:ct10:*");
1007 MODULE_ALIAS(
"dmi:*:svnMicro-StarInternational:pnMS-1412:*:rvnMSI:rnMS-1412:*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
1008 MODULE_ALIAS(
"dmi:*:svnNOTEBOOK:pnSAM2000:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
1009 MODULE_ALIAS(
"dmi:*:svnMICRO-STARINTERNATIONAL*:pnMS-N034:*");
1010 MODULE_ALIAS(
"dmi:*:svnMICRO-STARINTERNATIONAL*:pnMS-N051:*");
1011 MODULE_ALIAS(
"dmi:*:svnMICRO-STARINTERNATIONAL*:pnMS-N014:*");
1012 MODULE_ALIAS(
"dmi:*:svnMicro-StarInternational*:pnCR620:*");
1013 MODULE_ALIAS(
"dmi:*:svnMicro-StarInternational*:pnU270series:*");