diff --git a/drivers/platform/x86/samsung-laptop.c b/drivers/platform/x86/samsung-laptop.c index 359163011044d4..12b12c60d67baf 100644 --- a/drivers/platform/x86/samsung-laptop.c +++ b/drivers/platform/x86/samsung-laptop.c @@ -10,7 +10,7 @@ * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - + #include #include #include @@ -21,31 +21,31 @@ #include #include #include - + /* * This driver is needed because a number of Samsung laptops do not hook * their control settings through ACPI. So we have to poke around in the * BIOS to do things like brightness values, and "special" key controls. */ - + /* * We have 0 - 8 as valid brightness levels. The specs say that level 0 should * be reserved by the BIOS (which really doesn't make much sense), we tell * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8 */ -#define MAX_BRIGHT 0x07 - - -#define SABI_IFACE_MAIN 0x00 -#define SABI_IFACE_SUB 0x02 -#define SABI_IFACE_COMPLETE 0x04 -#define SABI_IFACE_DATA 0x05 - +#define MAX_BRIGHT 0x07 + + +#define SABI_IFACE_MAIN 0x00 +#define SABI_IFACE_SUB 0x02 +#define SABI_IFACE_COMPLETE 0x04 +#define SABI_IFACE_DATA 0x05 + /* Structure to get data back to the calling function */ struct sabi_retval { u8 retval[20]; }; - + struct sabi_header_offsets { u8 port; u8 re_mem; @@ -54,7 +54,7 @@ struct sabi_header_offsets { u8 data_offset; u8 data_segment; }; - + struct sabi_commands { /* * Brightness is 0 - 8, as described above. @@ -62,7 +62,7 @@ struct sabi_commands { */ u8 get_brightness; u8 set_brightness; - + /* * first byte: * 0x00 - wireless is off @@ -74,37 +74,37 @@ struct sabi_commands { */ u8 get_wireless_button; u8 set_wireless_button; - + /* 0 is off, 1 is on */ u8 get_backlight; u8 set_backlight; - + /* * 0x80 or 0x00 - no action * 0x81 - recovery key pressed */ u8 get_recovery_mode; u8 set_recovery_mode; - + /* * on seclinux: 0 is low, 1 is high, * on swsmi: 0 is normal, 1 is silent, 2 is turbo */ u8 get_performance_level; u8 set_performance_level; - + /* * Tell the BIOS that Linux is running on this machine. * 81 is on, 80 is off */ u8 set_linux; }; - + struct sabi_performance_level { const char *name; u8 value; }; - + struct sabi_config { const char *test_string; u16 main_function; @@ -114,13 +114,13 @@ struct sabi_config { u8 min_brightness; u8 max_brightness; }; - + static const struct sabi_config sabi_configs[] = { { .test_string = "SECLINUX", - + .main_function = 0x4c49, - + .header_offsets = { .port = 0x00, .re_mem = 0x02, @@ -129,26 +129,26 @@ static const struct sabi_config sabi_configs[] = { .data_offset = 0x05, .data_segment = 0x07, }, - + .commands = { .get_brightness = 0x00, .set_brightness = 0x01, - + .get_wireless_button = 0x02, .set_wireless_button = 0x03, - + .get_backlight = 0x04, .set_backlight = 0x05, - + .get_recovery_mode = 0x06, .set_recovery_mode = 0x07, - + .get_performance_level = 0x08, .set_performance_level = 0x09, - + .set_linux = 0x0a, }, - + .performance_levels = { { .name = "silent", @@ -165,9 +165,9 @@ static const struct sabi_config sabi_configs[] = { }, { .test_string = "SwSmi@", - + .main_function = 0x5843, - + .header_offsets = { .port = 0x00, .re_mem = 0x04, @@ -176,26 +176,26 @@ static const struct sabi_config sabi_configs[] = { .data_offset = 0x05, .data_segment = 0x07, }, - + .commands = { .get_brightness = 0x10, .set_brightness = 0x11, - + .get_wireless_button = 0x12, .set_wireless_button = 0x13, - + .get_backlight = 0x2d, .set_backlight = 0x2e, - + .get_recovery_mode = 0xff, .set_recovery_mode = 0xff, - + .get_performance_level = 0x31, .set_performance_level = 0x32, - + .set_linux = 0xff, }, - + .performance_levels = { { .name = "normal", @@ -216,9 +216,9 @@ static const struct sabi_config sabi_configs[] = { }, { }, }; - + static const struct sabi_config *sabi_config; - + static void __iomem *sabi; static void __iomem *sabi_iface; static void __iomem *f0000_segment; @@ -226,42 +226,42 @@ static struct backlight_device *backlight_device; static struct mutex sabi_mutex; static struct platform_device *sdev; static struct rfkill *rfk; - + static int force; module_param(force, bool, 0); MODULE_PARM_DESC(force, "Disable the DMI check and forces the driver to be loaded"); - + static int debug; module_param(debug, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(debug, "Debug enabled or not"); - + static int sabi_get_command(u8 command, struct sabi_retval *sretval) { int retval = 0; u16 port = readw(sabi + sabi_config->header_offsets.port); u8 complete, iface_data; - + mutex_lock(&sabi_mutex); - + /* enable memory to be able to write to it */ outb(readb(sabi + sabi_config->header_offsets.en_mem), port); - + /* write out the command */ writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN); writew(command, sabi_iface + SABI_IFACE_SUB); writeb(0, sabi_iface + SABI_IFACE_COMPLETE); outb(readb(sabi + sabi_config->header_offsets.iface_func), port); - + /* write protect memory to make it safe */ outb(readb(sabi + sabi_config->header_offsets.re_mem), port); - + /* see if the command actually succeeded */ complete = readb(sabi_iface + SABI_IFACE_COMPLETE); iface_data = readb(sabi_iface + SABI_IFACE_DATA); if (complete != 0xaa || iface_data == 0xff) { pr_warn("SABI get command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n", - command, complete, iface_data); + command, complete, iface_data); retval = -EINVAL; goto exit; } @@ -275,97 +275,97 @@ static int sabi_get_command(u8 command, struct sabi_retval *sretval) sretval->retval[1] = readb(sabi_iface + SABI_IFACE_DATA + 1); sretval->retval[2] = readb(sabi_iface + SABI_IFACE_DATA + 2); sretval->retval[3] = readb(sabi_iface + SABI_IFACE_DATA + 3); - + exit: mutex_unlock(&sabi_mutex); return retval; - + } - + static int sabi_set_command(u8 command, u8 data) { int retval = 0; u16 port = readw(sabi + sabi_config->header_offsets.port); u8 complete, iface_data; - + mutex_lock(&sabi_mutex); - + /* enable memory to be able to write to it */ outb(readb(sabi + sabi_config->header_offsets.en_mem), port); - + /* write out the command */ writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN); writew(command, sabi_iface + SABI_IFACE_SUB); writeb(0, sabi_iface + SABI_IFACE_COMPLETE); writeb(data, sabi_iface + SABI_IFACE_DATA); outb(readb(sabi + sabi_config->header_offsets.iface_func), port); - + /* write protect memory to make it safe */ outb(readb(sabi + sabi_config->header_offsets.re_mem), port); - + /* see if the command actually succeeded */ complete = readb(sabi_iface + SABI_IFACE_COMPLETE); iface_data = readb(sabi_iface + SABI_IFACE_DATA); if (complete != 0xaa || iface_data == 0xff) { pr_warn("SABI set command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n", - command, complete, iface_data); + command, complete, iface_data); retval = -EINVAL; } - + mutex_unlock(&sabi_mutex); return retval; } - + static void test_backlight(void) { struct sabi_retval sretval; - + sabi_get_command(sabi_config->commands.get_backlight, &sretval); printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]); - + sabi_set_command(sabi_config->commands.set_backlight, 0); printk(KERN_DEBUG "backlight should be off\n"); - + sabi_get_command(sabi_config->commands.get_backlight, &sretval); printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]); - + msleep(1000); - + sabi_set_command(sabi_config->commands.set_backlight, 1); printk(KERN_DEBUG "backlight should be on\n"); - + sabi_get_command(sabi_config->commands.get_backlight, &sretval); printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]); } - + static void test_wireless(void) { struct sabi_retval sretval; - + sabi_get_command(sabi_config->commands.get_wireless_button, &sretval); printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]); - + sabi_set_command(sabi_config->commands.set_wireless_button, 0); printk(KERN_DEBUG "wireless led should be off\n"); - + sabi_get_command(sabi_config->commands.get_wireless_button, &sretval); printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]); - + msleep(1000); - + sabi_set_command(sabi_config->commands.set_wireless_button, 1); printk(KERN_DEBUG "wireless led should be on\n"); - + sabi_get_command(sabi_config->commands.get_wireless_button, &sretval); printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]); } - + static u8 read_brightness(void) { struct sabi_retval sretval; int user_brightness = 0; int retval; - + retval = sabi_get_command(sabi_config->commands.get_brightness, &sretval); if (!retval) { @@ -375,35 +375,35 @@ static u8 read_brightness(void) } return user_brightness; } - + static void set_brightness(u8 user_brightness) { u8 user_level = user_brightness - sabi_config->min_brightness; - + sabi_set_command(sabi_config->commands.set_brightness, user_level); } - + static int get_brightness(struct backlight_device *bd) { return (int)read_brightness(); } - + static int update_status(struct backlight_device *bd) { set_brightness(bd->props.brightness); - + if (bd->props.power == FB_BLANK_UNBLANK) sabi_set_command(sabi_config->commands.set_backlight, 1); else sabi_set_command(sabi_config->commands.set_backlight, 0); return 0; } - + static const struct backlight_ops backlight_ops = { - .get_brightness = get_brightness, - .update_status = update_status, + .get_brightness = get_brightness, + .update_status = update_status, }; - + static int rfkill_set(void *data, bool blocked) { /* Do something with blocked...*/ @@ -415,51 +415,51 @@ static int rfkill_set(void *data, bool blocked) sabi_set_command(sabi_config->commands.set_wireless_button, 0); else sabi_set_command(sabi_config->commands.set_wireless_button, 1); - + return 0; } - + static struct rfkill_ops rfkill_ops = { .set_block = rfkill_set, }; - + static int init_wireless(struct platform_device *sdev) { int retval; - + rfk = rfkill_alloc("samsung-wifi", &sdev->dev, RFKILL_TYPE_WLAN, &rfkill_ops, NULL); if (!rfk) return -ENOMEM; - + retval = rfkill_register(rfk); if (retval) { rfkill_destroy(rfk); return -ENODEV; } - + return 0; } - + static void destroy_wireless(void) { rfkill_unregister(rfk); rfkill_destroy(rfk); } - + static ssize_t get_performance_level(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct sabi_retval sretval; int retval; int i; - + /* Read the state */ retval = sabi_get_command(sabi_config->commands.get_performance_level, &sretval); if (retval) return retval; - + /* The logic is backwards, yeah, lots of fun... */ for (i = 0; sabi_config->performance_levels[i].name; ++i) { if (sretval.retval[0] == sabi_config->performance_levels[i].value) @@ -467,7 +467,7 @@ static ssize_t get_performance_level(struct device *dev, } return sprintf(buf, "%s\n", "unknown"); } - + static ssize_t set_performance_level(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -490,15 +490,15 @@ static ssize_t set_performance_level(struct device *dev, } static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO, get_performance_level, set_performance_level); - - + + static int __init dmi_check_cb(const struct dmi_system_id *id) { pr_info("found laptop model '%s'\n", id->ident); return 1; } - + static struct dmi_system_id __initdata samsung_dmi_table[] = { { .ident = "N128", @@ -560,7 +560,7 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = { }, .callback = dmi_check_cb, }, - { + { .ident = "NP-Q45", .matches = { DMI_MATCH(DMI_SYS_VENDOR, @@ -569,7 +569,7 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = { DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"), }, .callback = dmi_check_cb, - }, + }, { .ident = "X360", .matches = { @@ -643,9 +643,9 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = { { .ident = "R530/R730", .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"), - DMI_MATCH(DMI_BOARD_NAME, "R530/R730"), + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"), + DMI_MATCH(DMI_BOARD_NAME, "R530/R730"), }, .callback = dmi_check_cb, }, @@ -686,18 +686,90 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = { }, .callback = dmi_check_cb, }, + { + .ident = "N120", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "N120"), + DMI_MATCH(DMI_BOARD_NAME, "N120"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "R468/R418", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R468/R418"), + DMI_MATCH(DMI_BOARD_NAME, "R468/R418"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "X320/X420/X520", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "X320/X420/X520"), + DMI_MATCH(DMI_BOARD_NAME, "X320/X420/X520"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "R510/P510", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R510/P510"), + DMI_MATCH(DMI_BOARD_NAME, "R510/P510"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "N350", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "N350"), + DMI_MATCH(DMI_BOARD_NAME, "N350"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "R470/R420", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R470/R420"), + DMI_MATCH(DMI_BOARD_NAME, "R470/R420"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "R528/R728", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"), + DMI_MATCH(DMI_BOARD_NAME, "R528/R728"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "SQ1S", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO.,LTD"), + DMI_MATCH(DMI_PRODUCT_NAME, "SQ1S"), + DMI_MATCH(DMI_BOARD_NAME, "SQ1S"), + }, + .callback = dmi_check_cb, + }, { }, }; MODULE_DEVICE_TABLE(dmi, samsung_dmi_table); - + static int find_signature(void __iomem *memcheck, const char *testStr) { int i = 0; int loca; - + for (loca = 0; loca < 0xffff; loca++) { char temp = readb(memcheck + loca); - + if (temp == testStr[i]) { if (i == strlen(testStr)-1) break; @@ -708,7 +780,7 @@ static int find_signature(void __iomem *memcheck, const char *testStr) } return loca; } - + static int __init samsung_init(void) { struct backlight_properties props; @@ -717,18 +789,18 @@ static int __init samsung_init(void) int i; int loca; int retval; - + mutex_init(&sabi_mutex); - + if (!force && !dmi_check_system(samsung_dmi_table)) return -ENODEV; - + f0000_segment = ioremap_nocache(0xf0000, 0xffff); if (!f0000_segment) { pr_err("Can't map the segment at 0xf0000\n"); return -EINVAL; } - + /* Try to find one of the signatures in memory to find the header */ for (i = 0; sabi_configs[i].test_string != 0; ++i) { sabi_config = &sabi_configs[i]; @@ -736,16 +808,16 @@ static int __init samsung_init(void) if (loca != 0xffff) break; } - + if (loca == 0xffff) { pr_err("This computer does not support SABI\n"); goto error_no_signature; } - + /* point to the SMI port Number */ loca += 1; sabi = (f0000_segment + loca); - + if (debug) { printk(KERN_DEBUG "This computer supports SABI==%x\n", loca + 0xf0000 - 6); @@ -763,7 +835,7 @@ static int __init samsung_init(void) printk(KERN_DEBUG " SABI data segment = 0x%04x\n", readw(sabi + sabi_config->header_offsets.data_segment)); } - + /* Get a pointer to the SABI Interface */ ifaceP = (readw(sabi + sabi_config->header_offsets.data_segment) & 0x0ffff) << 4; ifaceP += readw(sabi + sabi_config->header_offsets.data_offset) & 0x0ffff; @@ -775,15 +847,15 @@ static int __init samsung_init(void) if (debug) { printk(KERN_DEBUG "ifaceP = 0x%08x\n", ifaceP); printk(KERN_DEBUG "sabi_iface = %p\n", sabi_iface); - + test_backlight(); test_wireless(); - + retval = sabi_get_command(sabi_config->commands.get_brightness, &sretval); printk(KERN_DEBUG "brightness = 0x%02x\n", sretval.retval[0]); } - + /* Turn on "Linux" mode in the BIOS */ if (sabi_config->commands.set_linux != 0xff) { retval = sabi_set_command(sabi_config->commands.set_linux, @@ -793,60 +865,60 @@ static int __init samsung_init(void) goto error_no_platform; } } - + /* knock up a platform device to hang stuff off of */ sdev = platform_device_register_simple("samsung", -1, NULL, 0); if (IS_ERR(sdev)) goto error_no_platform; - + /* create a backlight device to talk to this one */ memset(&props, 0, sizeof(struct backlight_properties)); props.type = BACKLIGHT_PLATFORM; props.max_brightness = sabi_config->max_brightness; backlight_device = backlight_device_register("samsung", &sdev->dev, - NULL, &backlight_ops, - &props); + NULL, &backlight_ops, + &props); if (IS_ERR(backlight_device)) goto error_no_backlight; - + backlight_device->props.brightness = read_brightness(); backlight_device->props.power = FB_BLANK_UNBLANK; backlight_update_status(backlight_device); - + retval = init_wireless(sdev); if (retval) goto error_no_rfk; - + retval = device_create_file(&sdev->dev, &dev_attr_performance_level); if (retval) goto error_file_create; - + exit: return 0; - + error_file_create: destroy_wireless(); - + error_no_rfk: backlight_device_unregister(backlight_device); - + error_no_backlight: platform_device_unregister(sdev); - + error_no_platform: iounmap(sabi_iface); - + error_no_signature: iounmap(f0000_segment); return -EINVAL; } - + static void __exit samsung_exit(void) { /* Turn off "Linux" mode in the BIOS */ if (sabi_config->commands.set_linux != 0xff) sabi_set_command(sabi_config->commands.set_linux, 0x80); - + device_remove_file(&sdev->dev, &dev_attr_performance_level); backlight_device_unregister(backlight_device); destroy_wireless(); @@ -854,10 +926,10 @@ static void __exit samsung_exit(void) iounmap(f0000_segment); platform_device_unregister(sdev); } - + module_init(samsung_init); module_exit(samsung_exit); - + MODULE_AUTHOR("Greg Kroah-Hartman "); MODULE_DESCRIPTION("Samsung Backlight driver"); MODULE_LICENSE("GPL");