From 408a5d136b84f5fb43c9441153403d18255cb79c Mon Sep 17 00:00:00 2001 From: Azael Avalos Date: Fri, 5 Sep 2014 11:14:03 -0600 Subject: toshiba_acpi: Additional hotkey scancodes Appart from reporting hotkeys, the INFO method is used as a system wide event notifier for hardware or software changes. This patch adds additional "events" to the keymap list, ignored by now, until we find them a good use. Signed-off-by: Azael Avalos Signed-off-by: Darren Hart --- drivers/platform/x86/toshiba_acpi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index d0dce734b2ed..bad9f12a6720 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -190,6 +190,7 @@ static const struct key_entry toshiba_acpi_keymap[] = { { KE_KEY, 0x101, { KEY_MUTE } }, { KE_KEY, 0x102, { KEY_ZOOMOUT } }, { KE_KEY, 0x103, { KEY_ZOOMIN } }, + { KE_KEY, 0x10f, { KEY_TAB } }, { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, { KE_KEY, 0x139, { KEY_ZOOMRESET } }, { KE_KEY, 0x13b, { KEY_COFFEE } }, @@ -210,7 +211,11 @@ static const struct key_entry toshiba_acpi_keymap[] = { { KE_KEY, 0xb32, { KEY_NEXTSONG } }, { KE_KEY, 0xb33, { KEY_PLAYPAUSE } }, { KE_KEY, 0xb5a, { KEY_MEDIA } }, - { KE_IGNORE, 0x1430, { KEY_RESERVED } }, + { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */ + { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */ + { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */ + { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */ + { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */ { KE_END, 0 }, }; -- cgit v1.2.3 From 12962878fbf9578b3d30ee4d8a5cd6632f26324c Mon Sep 17 00:00:00 2001 From: Azael Avalos Date: Fri, 5 Sep 2014 11:14:04 -0600 Subject: toshiba_acpi: Fix illumination not available on certain models Some Toshiba models with illumination support set a different value on the returned codes, thus not allowing the illumination LED to be registered, where it should be. This patch removes a check from toshiba_illumination_available function to allow such models to register the illumination LED. Signed-off-by: Azael Avalos Signed-off-by: Darren Hart --- drivers/platform/x86/toshiba_acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index bad9f12a6720..4c8fa7b72891 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -436,7 +436,7 @@ static int toshiba_illumination_available(struct toshiba_acpi_dev *dev) if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) { pr_err("ACPI call to query Illumination support failed\n"); return 0; - } else if (out[0] == HCI_NOT_SUPPORTED || out[1] != 1) { + } else if (out[0] == HCI_NOT_SUPPORTED) { pr_info("Illumination device not available\n"); return 0; } -- cgit v1.2.3 From c8a41669a76381f655f5567d3ccd8449a53f9a7f Mon Sep 17 00:00:00 2001 From: Azael Avalos Date: Wed, 10 Sep 2014 21:01:57 -0600 Subject: toshiba_acpi: Change touchpad store to check for invalid values The function toshiba_touchpad_store is not checking for invalid values and simply returns silently. This patch checks for invalid values and returns accordingly. Signed-off-by: Azael Avalos Signed-off-by: Darren Hart --- drivers/platform/x86/toshiba_acpi.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 4c8fa7b72891..2a84652a4f0e 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -1343,12 +1343,18 @@ static ssize_t toshiba_touchpad_store(struct device *dev, { struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); int state; + int ret; /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */ - if (sscanf(buf, "%i", &state) == 1 && (state == 0 || state == 1)) { - if (toshiba_touchpad_set(toshiba, state) < 0) - return -EIO; - } + ret = kstrtoint(buf, 0, &state); + if (ret) + return ret; + if (state != 0 && state != 1) + return -EINVAL; + + ret = toshiba_touchpad_set(toshiba, state); + if (ret) + return ret; return count; } -- cgit v1.2.3 From 93f8c16d635e6b1e3ea978e38e110391ce28b26f Mon Sep 17 00:00:00 2001 From: Azael Avalos Date: Fri, 12 Sep 2014 18:50:36 -0600 Subject: toshiba_acpi: Support new keyboard backlight type Newer Toshiba models now come with a new (and different) keyboard backlight implementation with three modes of operation: TIMER, ON and OFF, and the LED is now controlled internally by the firmware. This patch adds support for that type of backlight, changing the existing code to accomodate the new implementation. The timeout value range is now 1-60 seconds, and the accepted modes are now: 1 (FN-Z), 2 (AUTO or TIMER), 8 (ON) and 10 (OFF), this adds two new entries kbd_type and available_kbd_modes, the first shows the keyboard type and the latter shows the supported modes depending on the keyboard type. Signed-off-by: Azael Avalos Signed-off-by: Darren Hart --- drivers/platform/x86/toshiba_acpi.c | 188 ++++++++++++++++++++++++++++++------ 1 file changed, 156 insertions(+), 32 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 2a84652a4f0e..edd8f3dad6b4 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -138,8 +138,12 @@ MODULE_LICENSE("GPL"); #define HCI_WIRELESS_BT_PRESENT 0x0f #define HCI_WIRELESS_BT_ATTACH 0x40 #define HCI_WIRELESS_BT_POWER 0x80 +#define SCI_KBD_MODE_MASK 0x1f #define SCI_KBD_MODE_FNZ 0x1 #define SCI_KBD_MODE_AUTO 0x2 +#define SCI_KBD_MODE_ON 0x8 +#define SCI_KBD_MODE_OFF 0x10 +#define SCI_KBD_TIME_MAX 0x3c001a struct toshiba_acpi_dev { struct acpi_device *acpi_dev; @@ -155,6 +159,7 @@ struct toshiba_acpi_dev { int force_fan; int last_key_event; int key_event_valid; + int kbd_type; int kbd_mode; int kbd_time; @@ -495,6 +500,42 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) } /* KBD Illumination */ +static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) +{ + u32 in[HCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 }; + u32 out[HCI_WORDS]; + acpi_status status; + + if (!sci_open(dev)) + return 0; + + status = hci_raw(dev, in, out); + sci_close(dev); + if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { + pr_err("ACPI call to query kbd illumination support failed\n"); + return 0; + } else if (out[0] == HCI_NOT_SUPPORTED) { + pr_info("Keyboard illumination not available\n"); + return 0; + } + + /* Check for keyboard backlight timeout max value, + * previous kbd backlight implementation set this to + * 0x3c0003, and now the new implementation set this + * to 0x3c001a, use this to distinguish between them + */ + if (out[3] == SCI_KBD_TIME_MAX) + dev->kbd_type = 2; + else + dev->kbd_type = 1; + /* Get the current keyboard backlight mode */ + dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK; + /* Get the current time (1-60 seconds) */ + dev->kbd_time = out[2] >> HCI_MISC_SHIFT; + + return 1; +} + static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time) { u32 result; @@ -1254,6 +1295,62 @@ static const struct backlight_ops toshiba_backlight_data = { /* * Sysfs files */ +static ssize_t toshiba_kbd_bl_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count); +static ssize_t toshiba_kbd_bl_mode_show(struct device *dev, + struct device_attribute *attr, + char *buf); +static ssize_t toshiba_kbd_type_show(struct device *dev, + struct device_attribute *attr, + char *buf); +static ssize_t toshiba_available_kbd_modes_show(struct device *dev, + struct device_attribute *attr, + char *buf); +static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count); +static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev, + struct device_attribute *attr, + char *buf); +static ssize_t toshiba_touchpad_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count); +static ssize_t toshiba_touchpad_show(struct device *dev, + struct device_attribute *attr, + char *buf); +static ssize_t toshiba_position_show(struct device *dev, + struct device_attribute *attr, + char *buf); + +static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR, + toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store); +static DEVICE_ATTR(kbd_type, S_IRUGO, toshiba_kbd_type_show, NULL); +static DEVICE_ATTR(available_kbd_modes, S_IRUGO, + toshiba_available_kbd_modes_show, NULL); +static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR, + toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store); +static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR, + toshiba_touchpad_show, toshiba_touchpad_store); +static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL); + +static struct attribute *toshiba_attributes[] = { + &dev_attr_kbd_backlight_mode.attr, + &dev_attr_kbd_type.attr, + &dev_attr_available_kbd_modes.attr, + &dev_attr_kbd_backlight_timeout.attr, + &dev_attr_touchpad.attr, + &dev_attr_position.attr, + NULL, +}; + +static umode_t toshiba_sysfs_is_visible(struct kobject *, + struct attribute *, int); + +static struct attribute_group toshiba_attr_group = { + .is_visible = toshiba_sysfs_is_visible, + .attrs = toshiba_attributes, +}; static ssize_t toshiba_kbd_bl_mode_store(struct device *dev, struct device_attribute *attr, @@ -1268,20 +1365,50 @@ static ssize_t toshiba_kbd_bl_mode_store(struct device *dev, ret = kstrtoint(buf, 0, &mode); if (ret) return ret; - if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO) - return -EINVAL; + + /* Check for supported modes depending on keyboard backlight type */ + if (toshiba->kbd_type == 1) { + /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */ + if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO) + return -EINVAL; + } else if (toshiba->kbd_type == 2) { + /* Type 2 doesn't support SCI_KBD_MODE_FNZ */ + if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON && + mode != SCI_KBD_MODE_OFF) + return -EINVAL; + } /* Set the Keyboard Backlight Mode where: - * Mode - Auto (2) | FN-Z (1) * Auto - KBD backlight turns off automatically in given time * FN-Z - KBD backlight "toggles" when hotkey pressed + * ON - KBD backlight is always on + * OFF - KBD backlight is always off */ + + /* Only make a change if the actual mode has changed */ if (toshiba->kbd_mode != mode) { + /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ time = toshiba->kbd_time << HCI_MISC_SHIFT; - time = time + toshiba->kbd_mode; + + /* OR the "base time" to the actual method format */ + if (toshiba->kbd_type == 1) { + /* Type 1 requires the current mode */ + time |= toshiba->kbd_mode; + } else if (toshiba->kbd_type == 2) { + /* Type 2 requires the desired mode */ + time |= mode; + } + ret = toshiba_kbd_illum_status_set(toshiba, time); if (ret) return ret; + + /* Update sysfs entries on successful mode change*/ + ret = sysfs_update_group(&toshiba->acpi_dev->dev.kobj, + &toshiba_attr_group); + if (ret) + return ret; + toshiba->kbd_mode = mode; } @@ -1298,7 +1425,30 @@ static ssize_t toshiba_kbd_bl_mode_show(struct device *dev, if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) return -EIO; - return sprintf(buf, "%i\n", time & 0x07); + return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK); +} + +static ssize_t toshiba_kbd_type_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", toshiba->kbd_type); +} + +static ssize_t toshiba_available_kbd_modes_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); + + if (toshiba->kbd_type == 1) + return sprintf(buf, "%x %x\n", + SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO); + + return sprintf(buf, "%x %x %x\n", + SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF); } static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev, @@ -1394,22 +1544,6 @@ static ssize_t toshiba_position_show(struct device *dev, return sprintf(buf, "%d %d %d\n", x, y, z); } -static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR, - toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store); -static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR, - toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store); -static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR, - toshiba_touchpad_show, toshiba_touchpad_store); -static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL); - -static struct attribute *toshiba_attributes[] = { - &dev_attr_kbd_backlight_mode.attr, - &dev_attr_kbd_backlight_timeout.attr, - &dev_attr_touchpad.attr, - &dev_attr_position.attr, - NULL, -}; - static umode_t toshiba_sysfs_is_visible(struct kobject *kobj, struct attribute *attr, int idx) { @@ -1429,11 +1563,6 @@ static umode_t toshiba_sysfs_is_visible(struct kobject *kobj, return exists ? attr->mode : 0; } -static struct attribute_group toshiba_attr_group = { - .is_visible = toshiba_sysfs_is_visible, - .attrs = toshiba_attributes, -}; - static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str, struct serio *port) { @@ -1765,12 +1894,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) dev->eco_supported = 1; } - ret = toshiba_kbd_illum_status_get(dev, &dummy); - if (!ret) { - dev->kbd_time = dummy >> HCI_MISC_SHIFT; - dev->kbd_mode = dummy & 0x07; - } - dev->kbd_illum_supported = !ret; + dev->kbd_illum_supported = toshiba_kbd_illum_available(dev); /* * Only register the LED if KBD illumination is supported * and the keyboard backlight operation mode is set to FN-Z -- cgit v1.2.3 From 72a979f09fa9111fd6be8326e5f21319ff6918fb Mon Sep 17 00:00:00 2001 From: Jan van den Berg Date: Wed, 17 Sep 2014 00:01:08 +0200 Subject: x86: thinkpad_acpi.c: fixed spacing coding style issue Fixed 22 similar coding style issues: "ERROR: spaces required around that '?'" Signed-off-by: Jan van den Berg Signed-off-by: Darren Hart --- drivers/platform/x86/thinkpad_acpi.c | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 3bbc6eb60de5..f959978c7aac 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -3440,7 +3440,7 @@ err_exit: delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); hotkey_dev_attributes = NULL; - return (res < 0)? res : 1; + return (res < 0) ? res : 1; } /* Thinkpad X1 Carbon support 5 modes including Home mode, Web browser @@ -4576,7 +4576,7 @@ static int __init video_init(struct ibm_init_struct *iibm) str_supported(video_supported != TPACPI_VIDEO_NONE), video_supported); - return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; + return (video_supported != TPACPI_VIDEO_NONE) ? 0 : 1; } static void video_exit(void) @@ -4669,7 +4669,7 @@ static int video_outputsw_set(int status) return -ENOSYS; } - return (res)? 0 : -EIO; + return (res) ? 0 : -EIO; } static int video_autosw_get(void) @@ -4695,7 +4695,7 @@ static int video_autosw_get(void) static int video_autosw_set(int enable) { - if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) + if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable) ? 1 : 0)) return -EIO; return 0; } @@ -4730,20 +4730,20 @@ static int video_outputsw_cycle(void) return -EIO; } - return (res)? 0 : -EIO; + return (res) ? 0 : -EIO; } static int video_expand_toggle(void) { switch (video_supported) { case TPACPI_VIDEO_570: - return acpi_evalf(ec_handle, NULL, "_Q17", "v")? + return acpi_evalf(ec_handle, NULL, "_Q17", "v") ? 0 : -EIO; case TPACPI_VIDEO_770: - return acpi_evalf(vid_handle, NULL, "VEXP", "v")? + return acpi_evalf(vid_handle, NULL, "VEXP", "v") ? 0 : -EIO; case TPACPI_VIDEO_NEW: - return acpi_evalf(NULL, NULL, "\\VEXP", "v")? + return acpi_evalf(NULL, NULL, "\\VEXP", "v") ? 0 : -EIO; default: return -ENOSYS; @@ -4887,14 +4887,14 @@ static int light_set_status(int status) if (tp_features.light) { if (cmos_handle) { rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", - (status)? + (status) ? TP_CMOS_THINKLIGHT_ON : TP_CMOS_THINKLIGHT_OFF); } else { rc = acpi_evalf(lght_handle, NULL, NULL, "vd", - (status)? 1 : 0); + (status) ? 1 : 0); } - return (rc)? 0 : -EIO; + return (rc) ? 0 : -EIO; } return -ENXIO; @@ -4923,7 +4923,7 @@ static void light_sysfs_set(struct led_classdev *led_cdev, static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) { - return (light_get_status() == 1)? LED_FULL : LED_OFF; + return (light_get_status() == 1) ? LED_FULL : LED_OFF; } static struct tpacpi_led_classdev tpacpi_led_thinklight = { @@ -5045,7 +5045,7 @@ static ssize_t cmos_command_store(struct device *dev, return -EINVAL; res = issue_thinkpad_cmos_command(cmos_cmd); - return (res)? res : count; + return (res) ? res : count; } static struct device_attribute dev_attr_cmos_command = @@ -5069,7 +5069,7 @@ static int __init cmos_init(struct ibm_init_struct *iibm) if (res) return res; - return (cmos_handle)? 0 : 1; + return (cmos_handle) ? 0 : 1; } static void cmos_exit(void) @@ -5179,9 +5179,9 @@ static int led_get_status(const unsigned int led) if (!acpi_evalf(ec_handle, &status, "GLED", "dd", 1 << led)) return -EIO; - led_s = (status == 0)? + led_s = (status == 0) ? TPACPI_LED_OFF : - ((status == 1)? + ((status == 1) ? TPACPI_LED_ON : TPACPI_LED_BLINK); tpacpi_led_state_cache[led] = led_s; @@ -5578,7 +5578,7 @@ static int __init beep_init(struct ibm_init_struct *iibm) tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); - return (beep_handle)? 0 : 1; + return (beep_handle) ? 0 : 1; } static int beep_read(struct seq_file *m) @@ -6527,7 +6527,7 @@ static int brightness_write(char *buf) if (!rc && ibm_backlight_device) backlight_force_update(ibm_backlight_device, BACKLIGHT_UPDATE_SYSFS); - return (rc == -EINTR)? -ERESTARTSYS : rc; + return (rc == -EINTR) ? -ERESTARTSYS : rc; } static struct ibm_struct brightness_driver_data = { @@ -7984,7 +7984,7 @@ static ssize_t fan_pwm1_store(struct device *dev, } mutex_unlock(&fan_mutex); - return (rc)? rc : count; + return (rc) ? rc : count; } static struct device_attribute dev_attr_fan_pwm1 = @@ -8662,7 +8662,7 @@ static const char * __init str_supported(int is_supported) { static char text_unsupported[] __initdata = "not supported"; - return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; + return (is_supported) ? &text_unsupported[4] : &text_unsupported[0]; } #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ @@ -8783,7 +8783,7 @@ err_out: ibm->name, ret); ibm_exit(ibm); - return (ret < 0)? ret : 0; + return (ret < 0) ? ret : 0; } /* Probing */ @@ -8794,7 +8794,7 @@ static bool __pure __init tpacpi_is_fw_digit(const char c) } /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ -static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, +static bool __pure __init tpacpi_is_valid_fw_id(const char * const s, const char t) { return s && strlen(s) >= 8 && -- cgit v1.2.3 From d46a76405fad48a7efc3faf07545fa886a3b271a Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Wed, 17 Sep 2014 00:13:55 +0300 Subject: intel-rst: Use ACPI_FAILURE() macro instead !ACPI_SUCCESS() for error checking ACPI_SUCCESS is defined as: #define ACPI_SUCCESS(a) (!(a)) There is no need for the the double ! since there is already a macro defined for failures: ACPI_FAILURE() Signed-off-by: Peter Ujfalusi Signed-off-by: Darren Hart --- drivers/platform/x86/intel-rst.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/intel-rst.c b/drivers/platform/x86/intel-rst.c index d45bca34bf1b..8c6a8fed8a08 100644 --- a/drivers/platform/x86/intel-rst.c +++ b/drivers/platform/x86/intel-rst.c @@ -35,7 +35,7 @@ static ssize_t irst_show_wakeup_events(struct device *dev, acpi = to_acpi_device(dev); status = acpi_evaluate_integer(acpi->handle, "GFFS", NULL, &value); - if (!ACPI_SUCCESS(status)) + if (ACPI_FAILURE(status)) return -EINVAL; return sprintf(buf, "%lld\n", value); @@ -59,7 +59,7 @@ static ssize_t irst_store_wakeup_events(struct device *dev, status = acpi_execute_simple_method(acpi->handle, "SFFS", value); - if (!ACPI_SUCCESS(status)) + if (ACPI_FAILURE(status)) return -EINVAL; return count; @@ -81,7 +81,7 @@ static ssize_t irst_show_wakeup_time(struct device *dev, acpi = to_acpi_device(dev); status = acpi_evaluate_integer(acpi->handle, "GFTV", NULL, &value); - if (!ACPI_SUCCESS(status)) + if (ACPI_FAILURE(status)) return -EINVAL; return sprintf(buf, "%lld\n", value); @@ -105,7 +105,7 @@ static ssize_t irst_store_wakeup_time(struct device *dev, status = acpi_execute_simple_method(acpi->handle, "SFTV", value); - if (!ACPI_SUCCESS(status)) + if (ACPI_FAILURE(status)) return -EINVAL; return count; -- cgit v1.2.3 From a3d3c53f738bb931e15b20d3dc5d23722b9ede6a Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Wed, 17 Sep 2014 00:13:56 +0300 Subject: intel-rst: Clean up ACPI add function There is no need to initialize the error since it is going to be assigned with the return status of at least on of the device_create_file() call. We can return directly in case the first file creation fails. All the labels for goto can be removed (along with the gotos) as well. Tell the compiler that the failures are unlikely so it can create better binaries. Signed-off-by: Peter Ujfalusi Signed-off-by: Darren Hart --- drivers/platform/x86/intel-rst.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/intel-rst.c b/drivers/platform/x86/intel-rst.c index 8c6a8fed8a08..7344d841f4d9 100644 --- a/drivers/platform/x86/intel-rst.c +++ b/drivers/platform/x86/intel-rst.c @@ -119,21 +119,16 @@ static struct device_attribute irst_timeout_attr = { static int irst_add(struct acpi_device *acpi) { - int error = 0; + int error; error = device_create_file(&acpi->dev, &irst_timeout_attr); - if (error) - goto out; + if (unlikely(error)) + return error; error = device_create_file(&acpi->dev, &irst_wakeup_attr); - if (error) - goto out_timeout; + if (unlikely(error)) + device_remove_file(&acpi->dev, &irst_timeout_attr); - return 0; - -out_timeout: - device_remove_file(&acpi->dev, &irst_timeout_attr); -out: return error; } -- cgit v1.2.3 From 95369a73a957ad221f1d6b8f11a63a376f38c544 Mon Sep 17 00:00:00 2001 From: Paul Bolle Date: Wed, 17 Sep 2014 21:02:51 +0200 Subject: eeepc-laptop: simplify parse_arg() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit parse_arg() has three possible return values: -EINVAL if sscanf(), in short, fails; zero if "count" is zero; and "count" in all other cases But "count" will never be zero. See, parse_arg() is called by the various store functions. And the callchain of these functions starts with sysfs_kf_write(). And that function checks for a zero "count". So we can stop checking for a zero "count", drop the "count" argument entirely, and transform parse_arg() into a function that returns zero on success or a negative error. That, in turn, allows to make those store functions just return "count" on success. The net effect is that the code becomes a bit easier to understand. A nice side effect is that this GCC warning is silenced too: drivers/platform/x86/eeepc-laptop.c: In function ‘store_sys_acpi’: drivers/platform/x86/eeepc-laptop.c:279:10: warning: ‘value’ may be used uninitialized in this function [-Wmaybe-uninitialized] int rv, value; Which is, of course, the reason to have a look at parse_arg(). Signed-off-by: Paul Bolle Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index bd533c22be57..3095d386c7f4 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -263,13 +263,11 @@ static int acpi_setter_handle(struct eeepc_laptop *eeepc, int cm, /* * Sys helpers */ -static int parse_arg(const char *buf, unsigned long count, int *val) +static int parse_arg(const char *buf, int *val) { - if (!count) - return 0; if (sscanf(buf, "%i", val) != 1) return -EINVAL; - return count; + return 0; } static ssize_t store_sys_acpi(struct device *dev, int cm, @@ -278,12 +276,13 @@ static ssize_t store_sys_acpi(struct device *dev, int cm, struct eeepc_laptop *eeepc = dev_get_drvdata(dev); int rv, value; - rv = parse_arg(buf, count, &value); - if (rv > 0) - value = set_acpi(eeepc, cm, value); - if (value < 0) + rv = parse_arg(buf, &value); + if (rv < 0) + return rv; + rv = set_acpi(eeepc, cm, value); + if (rv < 0) return -EIO; - return rv; + return count; } static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf) @@ -377,13 +376,13 @@ static ssize_t store_cpufv(struct device *dev, return -EPERM; if (get_cpufv(eeepc, &c)) return -ENODEV; - rv = parse_arg(buf, count, &value); + rv = parse_arg(buf, &value); if (rv < 0) return rv; - if (!rv || value < 0 || value >= c.num) + if (value < 0 || value >= c.num) return -EINVAL; set_acpi(eeepc, CM_ASL_CPUFV, value); - return rv; + return count; } static ssize_t show_cpufv_disabled(struct device *dev, @@ -402,7 +401,7 @@ static ssize_t store_cpufv_disabled(struct device *dev, struct eeepc_laptop *eeepc = dev_get_drvdata(dev); int rv, value; - rv = parse_arg(buf, count, &value); + rv = parse_arg(buf, &value); if (rv < 0) return rv; @@ -412,7 +411,7 @@ static ssize_t store_cpufv_disabled(struct device *dev, pr_warn("cpufv enabled (not officially supported " "on this model)\n"); eeepc->cpufv_disabled = false; - return rv; + return count; case 1: return -EPERM; default: @@ -1042,10 +1041,11 @@ static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count) { int rv, value; - rv = parse_arg(buf, count, &value); - if (rv > 0) - set(value); - return rv; + rv = parse_arg(buf, &value); + if (rv < 0) + return rv; + set(value); + return count; } static ssize_t show_sys_hwmon(int (*get)(void), char *buf) -- cgit v1.2.3 From 39a3e17e0d5c50e382992eeed6bb62668c31ded7 Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Wed, 17 Sep 2014 23:47:19 +0200 Subject: eeepc-laptop: clean up coding style Correct indentation and brace usage to comply with Documentation/CodingStyle. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index 3095d386c7f4..653999ee33fe 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -544,7 +544,7 @@ static int eeepc_led_init(struct eeepc_laptop *eeepc) eeepc->tpd_led.name = "eeepc::touchpad"; eeepc->tpd_led.brightness_set = tpd_led_set; if (get_acpi(eeepc, CM_ASL_TPD) >= 0) /* if method is available */ - eeepc->tpd_led.brightness_get = tpd_led_get; + eeepc->tpd_led.brightness_get = tpd_led_get; eeepc->tpd_led.max_brightness = 1; rv = led_classdev_register(&eeepc->platform_device->dev, @@ -692,8 +692,9 @@ static int eeepc_register_rfkill_notifier(struct eeepc_laptop *eeepc, * changed during setup. */ eeepc_rfkill_hotplug(eeepc, handle); - } else + } else { return -ENODEV; + } return 0; } @@ -1424,8 +1425,9 @@ static int eeepc_acpi_add(struct acpi_device *device) result = eeepc_backlight_init(eeepc); if (result) goto fail_backlight; - } else + } else { pr_info("Backlight controlled by ACPI video driver\n"); + } result = eeepc_input_init(eeepc); if (result) -- cgit v1.2.3 From 8c72fc8bd7c698d7b5c99b83e187fda0d1538e1a Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Wed, 17 Sep 2014 23:47:20 +0200 Subject: eeepc-laptop: change sysfs function names to API expectations The eeepc-laptop driver follows the function naming convention _(), while the sysfs macros are built around the convention _(). Rename the sysfs functions to the convention used by sysfs. This makes it easier to use the available API later on. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index 653999ee33fe..009444982070 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -296,13 +296,13 @@ static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf) } #define EEEPC_CREATE_DEVICE_ATTR(_name, _mode, _cm) \ - static ssize_t show_##_name(struct device *dev, \ + static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ return show_sys_acpi(dev, _cm, buf); \ } \ - static ssize_t store_##_name(struct device *dev, \ + static ssize_t _name##_store(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t count) \ { \ @@ -312,8 +312,8 @@ static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf) .attr = { \ .name = __stringify(_name), \ .mode = _mode }, \ - .show = show_##_name, \ - .store = store_##_name, \ + .show = _name##_show, \ + .store = _name##_store, \ } EEEPC_CREATE_DEVICE_ATTR(camera, 0644, CM_ASL_CAMERA); @@ -335,7 +335,7 @@ static int get_cpufv(struct eeepc_laptop *eeepc, struct eeepc_cpufv *c) return 0; } -static ssize_t show_available_cpufv(struct device *dev, +static ssize_t available_cpufv_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -352,7 +352,7 @@ static ssize_t show_available_cpufv(struct device *dev, return len; } -static ssize_t show_cpufv(struct device *dev, +static ssize_t cpufv_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -364,7 +364,7 @@ static ssize_t show_cpufv(struct device *dev, return sprintf(buf, "%#x\n", (c.num << 8) | c.cur); } -static ssize_t store_cpufv(struct device *dev, +static ssize_t cpufv_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -385,7 +385,7 @@ static ssize_t store_cpufv(struct device *dev, return count; } -static ssize_t show_cpufv_disabled(struct device *dev, +static ssize_t cpufv_disabled_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -394,7 +394,7 @@ static ssize_t show_cpufv_disabled(struct device *dev, return sprintf(buf, "%d\n", eeepc->cpufv_disabled); } -static ssize_t store_cpufv_disabled(struct device *dev, +static ssize_t cpufv_disabled_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -424,23 +424,23 @@ static struct device_attribute dev_attr_cpufv = { .attr = { .name = "cpufv", .mode = 0644 }, - .show = show_cpufv, - .store = store_cpufv + .show = cpufv_show, + .store = cpufv_store }; static struct device_attribute dev_attr_available_cpufv = { .attr = { .name = "available_cpufv", .mode = 0444 }, - .show = show_available_cpufv + .show = available_cpufv_show }; static struct device_attribute dev_attr_cpufv_disabled = { .attr = { .name = "cpufv_disabled", .mode = 0644 }, - .show = show_cpufv_disabled, - .store = store_cpufv_disabled + .show = cpufv_disabled_show, + .store = cpufv_disabled_store }; -- cgit v1.2.3 From bb382dbaba09e74d728160f398391960dda3faf1 Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Wed, 17 Sep 2014 23:47:21 +0200 Subject: eeepc-laptop: use DEVICE_ATTR* to instantiate device_attributes Device attributes are instantiated manually, while we have DEVICE_ATTR* macros available to do much of the work for us. Let's use them. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index 009444982070..db26f78cfc41 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -308,13 +308,7 @@ static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf) { \ return store_sys_acpi(dev, _cm, buf, count); \ } \ - static struct device_attribute dev_attr_##_name = { \ - .attr = { \ - .name = __stringify(_name), \ - .mode = _mode }, \ - .show = _name##_show, \ - .store = _name##_store, \ - } + static DEVICE_ATTR(_name, _mode, _name##_show, _name##_store) EEEPC_CREATE_DEVICE_ATTR(camera, 0644, CM_ASL_CAMERA); EEEPC_CREATE_DEVICE_ATTR(cardr, 0644, CM_ASL_CARDREADER); @@ -420,29 +414,9 @@ static ssize_t cpufv_disabled_store(struct device *dev, } -static struct device_attribute dev_attr_cpufv = { - .attr = { - .name = "cpufv", - .mode = 0644 }, - .show = cpufv_show, - .store = cpufv_store -}; - -static struct device_attribute dev_attr_available_cpufv = { - .attr = { - .name = "available_cpufv", - .mode = 0444 }, - .show = available_cpufv_show -}; - -static struct device_attribute dev_attr_cpufv_disabled = { - .attr = { - .name = "cpufv_disabled", - .mode = 0644 }, - .show = cpufv_disabled_show, - .store = cpufv_disabled_store -}; - +static DEVICE_ATTR_RW(cpufv); +static DEVICE_ATTR_RO(available_cpufv); +static DEVICE_ATTR_RW(cpufv_disabled); static struct attribute *platform_attributes[] = { &dev_attr_camera.attr, -- cgit v1.2.3 From 9797132577aa53734f4e980f9008f617947fddc9 Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Wed, 17 Sep 2014 23:47:22 +0200 Subject: eeepc-laptop: pull out ACPI_STORE_FUNC and ACPI_SHOW_FUNC macros Pull out macros EEEPC_ACPI_STORE_FUNC and EEEPC_ACPI_SHOW_FUNC. These macros define functions that call store_sys_acpi() and show_sys_acpi() respectively. This helps prevent duplication later on. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index db26f78cfc41..c6d765fec8e9 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -295,19 +295,25 @@ static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf) return sprintf(buf, "%d\n", value); } -#define EEEPC_CREATE_DEVICE_ATTR(_name, _mode, _cm) \ +#define EEEPC_ACPI_SHOW_FUNC(_name, _cm) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ return show_sys_acpi(dev, _cm, buf); \ - } \ + } + +#define EEEPC_ACPI_STORE_FUNC(_name, _cm) \ static ssize_t _name##_store(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t count) \ { \ return store_sys_acpi(dev, _cm, buf, count); \ - } \ + } + +#define EEEPC_CREATE_DEVICE_ATTR(_name, _mode, _cm) \ + EEEPC_ACPI_SHOW_FUNC(_name, _cm) \ + EEEPC_ACPI_STORE_FUNC(_name, _cm) \ static DEVICE_ATTR(_name, _mode, _name##_show, _name##_store) EEEPC_CREATE_DEVICE_ATTR(camera, 0644, CM_ASL_CAMERA); -- cgit v1.2.3 From 6fe3a77f6296a6c995eb08d564bafec028c15a18 Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Wed, 17 Sep 2014 23:47:23 +0200 Subject: eeepc-laptop: tell sysfs that the disp attribute is write-only The disp attribute is write-only, but sysfs doesn't know this. Currently show_sys_acpi() is mimicking sysfs behavior, if the underlying acpi call should fail. This was introduced in 6dff29b63a5bf2eaf3 "eeepc-laptop: disp attribute should be write-only". This is not ideal; behaving like sysfs is better left to sysfs. Introduce EEEPC_CREATE_DEVICE_ATTR_WO() to instantiate a write-only attribute, and declare the disp attribute with it. Sysfs makes sure userspace can only write to disp at all times. This removes the need for mimicking the sysfs behavior in show_sys_acpi() and store_sys_acpi(), but we'll stick with -EIO, as changing sysfs return values should not be taken lightly. This change also causes EEEPC_CREATE_DEVICE_ATTR() to be used only for R/W attributes. This enables us to drop the _mode argument from the macro and use DEVICE_ATTR_RW() internally while we're at it. Append _RW to the name for readability. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index c6d765fec8e9..a85da4f837e6 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -311,14 +311,18 @@ static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf) return store_sys_acpi(dev, _cm, buf, count); \ } -#define EEEPC_CREATE_DEVICE_ATTR(_name, _mode, _cm) \ +#define EEEPC_CREATE_DEVICE_ATTR_RW(_name, _cm) \ EEEPC_ACPI_SHOW_FUNC(_name, _cm) \ EEEPC_ACPI_STORE_FUNC(_name, _cm) \ - static DEVICE_ATTR(_name, _mode, _name##_show, _name##_store) + static DEVICE_ATTR_RW(_name) -EEEPC_CREATE_DEVICE_ATTR(camera, 0644, CM_ASL_CAMERA); -EEEPC_CREATE_DEVICE_ATTR(cardr, 0644, CM_ASL_CARDREADER); -EEEPC_CREATE_DEVICE_ATTR(disp, 0200, CM_ASL_DISPLAYSWITCH); +#define EEEPC_CREATE_DEVICE_ATTR_WO(_name, _cm) \ + EEEPC_ACPI_STORE_FUNC(_name, _cm) \ + static DEVICE_ATTR_WO(_name) + +EEEPC_CREATE_DEVICE_ATTR_RW(camera, CM_ASL_CAMERA); +EEEPC_CREATE_DEVICE_ATTR_RW(cardr, CM_ASL_CARDREADER); +EEEPC_CREATE_DEVICE_ATTR_WO(disp, CM_ASL_DISPLAYSWITCH); struct eeepc_cpufv { int num; -- cgit v1.2.3 From 28ac85f71ad1e55199302a59757ed21e082b88b1 Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Wed, 17 Sep 2014 23:47:24 +0200 Subject: eeepc-laptop: pull out SENSOR_STORE_FUNC and SENSOR_SHOW_FUNC macros Pull out EEEPC_SENSOR_STORE_FUNC and EEEPC_SENSOR_SHOW_FUNC. These macros define functions that call store_sys_hwmon() and show_sys_hwmon() respectively. This helps prevent duplication later on. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index a85da4f837e6..ba251bb0d495 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -1038,19 +1038,25 @@ static ssize_t show_sys_hwmon(int (*get)(void), char *buf) return sprintf(buf, "%d\n", get()); } -#define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _get, _set) \ +#define EEEPC_SENSOR_SHOW_FUNC(_name, _get) \ static ssize_t show_##_name(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ return show_sys_hwmon(_get, buf); \ - } \ + } + +#define EEEPC_SENSOR_STORE_FUNC(_name, _set) \ static ssize_t store_##_name(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t count) \ { \ return store_sys_hwmon(_set, buf, count); \ - } \ + } + +#define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _get, _set) \ + EEEPC_SENSOR_SHOW_FUNC(_name, _get) \ + EEEPC_SENSOR_STORE_FUNC(_name, _set) \ static DEVICE_ATTR(_name, _mode, show_##_name, store_##_name) EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL); -- cgit v1.2.3 From 48d4a5b29c8d0cf544ffe96f5855452446b6f20d Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Wed, 17 Sep 2014 23:47:25 +0200 Subject: eeepc-laptop: make fan1_input really read-only In the instantiation of the fan1_input device attribute, NULL is passed as set function to store_sys_hwmon. The function pointer is never checked before dereferencing it. This is fine if we can guarantee that it will never be called with an invalid pointer, but we can't. If someone from user space decides to change the permissions on this attribute and write to it, kernel will crash. Introduce EEEPC_CREATE_SENSOR_ATTR_RO() to instantiate a read-only attribute, and declare fan1_input with it. This ensures store_sys_hwmon is never called with NULL parameters. If someone tries to write the attribute, the system will at least keep its sanity. This also causes EEEPC_CREATE_SENSOR_ATTR() to be only used for R/W attributes.This enables us to drop the _mode argument from the macro and use DEVICE_ATTR_RW() internally while we're at it. Append _RW to the name for readability. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index ba251bb0d495..e93a54edb17a 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -1039,7 +1039,7 @@ static ssize_t show_sys_hwmon(int (*get)(void), char *buf) } #define EEEPC_SENSOR_SHOW_FUNC(_name, _get) \ - static ssize_t show_##_name(struct device *dev, \ + static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ @@ -1047,23 +1047,27 @@ static ssize_t show_sys_hwmon(int (*get)(void), char *buf) } #define EEEPC_SENSOR_STORE_FUNC(_name, _set) \ - static ssize_t store_##_name(struct device *dev, \ + static ssize_t _name##_store(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t count) \ { \ return store_sys_hwmon(_set, buf, count); \ } -#define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _get, _set) \ +#define EEEPC_CREATE_SENSOR_ATTR_RW(_name, _get, _set) \ EEEPC_SENSOR_SHOW_FUNC(_name, _get) \ EEEPC_SENSOR_STORE_FUNC(_name, _set) \ - static DEVICE_ATTR(_name, _mode, show_##_name, store_##_name) + static DEVICE_ATTR_RW(_name) + +#define EEEPC_CREATE_SENSOR_ATTR_RO(_name, _get) \ + EEEPC_SENSOR_SHOW_FUNC(_name, _get) \ + static DEVICE_ATTR_RO(_name) -EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL); -EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR, - eeepc_get_fan_pwm, eeepc_set_fan_pwm); -EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, - eeepc_get_fan_ctrl, eeepc_set_fan_ctrl); +EEEPC_CREATE_SENSOR_ATTR_RO(fan1_input, eeepc_get_fan_rpm); +EEEPC_CREATE_SENSOR_ATTR_RW(pwm1, eeepc_get_fan_pwm, + eeepc_set_fan_pwm); +EEEPC_CREATE_SENSOR_ATTR_RW(pwm1_enable, eeepc_get_fan_ctrl, + eeepc_set_fan_ctrl); static struct attribute *hwmon_attrs[] = { &dev_attr_pwm1.attr, -- cgit v1.2.3 From a5c155b16f4c170d96d41fc6066f245f2d53604d Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Wed, 17 Sep 2014 23:47:26 +0200 Subject: eeepc-laptop: check proper return values in get_cpufv In get_cpufv the return value of get_acpi is stored in the cpufv struct. Right before this value is checked for errors, it is and'ed with 0xff. This means c->cur can never be less than zero. Besides that, the actual error value is ignored. c->num is also and'ed with 0xff, which means we can ignore values below zero. Check the result of get_acpi() right away. While at it, propagate the error if we got one. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index e93a54edb17a..875a43fcaa86 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -332,9 +332,12 @@ struct eeepc_cpufv { static int get_cpufv(struct eeepc_laptop *eeepc, struct eeepc_cpufv *c) { c->cur = get_acpi(eeepc, CM_ASL_CPUFV); + if (c->cur < 0) + return -ENODEV; + c->num = (c->cur >> 8) & 0xff; c->cur &= 0xff; - if (c->cur < 0 || c->num <= 0 || c->num > 12) + if (c->num == 0 || c->num > 12) return -ENODEV; return 0; } -- cgit v1.2.3 From d48690383febbf17d958e909ff8f0d15f4497325 Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Wed, 17 Sep 2014 23:47:27 +0200 Subject: eeepc-laptop: store_cpufv: return error if set_acpi fails The result of set_acpi is left unchecked, but it may return errors. If one occurs, send the error to the caller. There's no reason to lie about it, if set_acpi fails. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index 875a43fcaa86..3f6c762fb560 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -388,7 +388,9 @@ static ssize_t cpufv_store(struct device *dev, return rv; if (value < 0 || value >= c.num) return -EINVAL; - set_acpi(eeepc, CM_ASL_CPUFV, value); + rv = set_acpi(eeepc, CM_ASL_CPUFV, value); + if (rv) + return rv; return count; } -- cgit v1.2.3 From 557b4549714536b161522960a36f0aa7f527418c Mon Sep 17 00:00:00 2001 From: Frans Klaver Date: Sun, 21 Sep 2014 00:22:17 +0200 Subject: eeepc-laptop: clean up control flow in *_rfkill_notifier Handle errors immediately in eeepc_register_rfkill_notifier and eeepc_unregister_rfkill_notifier. This clears up the control flow for the reader. It also removes unnecessary indentation. Signed-off-by: Frans Klaver Signed-off-by: Darren Hart --- drivers/platform/x86/eeepc-laptop.c | 57 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 29 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index 3f6c762fb560..db79902c4a8e 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -668,23 +668,21 @@ static int eeepc_register_rfkill_notifier(struct eeepc_laptop *eeepc, status = acpi_get_handle(NULL, node, &handle); - if (ACPI_SUCCESS(status)) { - status = acpi_install_notify_handler(handle, - ACPI_SYSTEM_NOTIFY, - eeepc_rfkill_notify, - eeepc); - if (ACPI_FAILURE(status)) - pr_warn("Failed to register notify on %s\n", node); - - /* - * Refresh pci hotplug in case the rfkill state was - * changed during setup. - */ - eeepc_rfkill_hotplug(eeepc, handle); - } else { + if (ACPI_FAILURE(status)) return -ENODEV; - } + status = acpi_install_notify_handler(handle, + ACPI_SYSTEM_NOTIFY, + eeepc_rfkill_notify, + eeepc); + if (ACPI_FAILURE(status)) + pr_warn("Failed to register notify on %s\n", node); + + /* + * Refresh pci hotplug in case the rfkill state was + * changed during setup. + */ + eeepc_rfkill_hotplug(eeepc, handle); return 0; } @@ -696,20 +694,21 @@ static void eeepc_unregister_rfkill_notifier(struct eeepc_laptop *eeepc, status = acpi_get_handle(NULL, node, &handle); - if (ACPI_SUCCESS(status)) { - status = acpi_remove_notify_handler(handle, - ACPI_SYSTEM_NOTIFY, - eeepc_rfkill_notify); - if (ACPI_FAILURE(status)) - pr_err("Error removing rfkill notify handler %s\n", - node); - /* - * Refresh pci hotplug in case the rfkill - * state was changed after - * eeepc_unregister_rfkill_notifier() - */ - eeepc_rfkill_hotplug(eeepc, handle); - } + if (ACPI_FAILURE(status)) + return; + + status = acpi_remove_notify_handler(handle, + ACPI_SYSTEM_NOTIFY, + eeepc_rfkill_notify); + if (ACPI_FAILURE(status)) + pr_err("Error removing rfkill notify handler %s\n", + node); + /* + * Refresh pci hotplug in case the rfkill + * state was changed after + * eeepc_unregister_rfkill_notifier() + */ + eeepc_rfkill_hotplug(eeepc, handle); } static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot, -- cgit v1.2.3 From a666b6ffbc9b6705a3ced704f52c3fe9ea8bf959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 29 Sep 2014 15:10:51 +0200 Subject: dell-wmi: Fix access out of memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this patch, dell-wmi is trying to access elements of dynamically allocated array without checking the array size. This can lead to memory corruption or a kernel panic. This patch adds the missing checks for array size. Signed-off-by: Pali Rohár Signed-off-by: Darren Hart --- drivers/platform/x86/dell-wmi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell-wmi.c index 390e8e33d5e3..25721bf20092 100644 --- a/drivers/platform/x86/dell-wmi.c +++ b/drivers/platform/x86/dell-wmi.c @@ -163,18 +163,24 @@ static void dell_wmi_notify(u32 value, void *context) const struct key_entry *key; int reported_key; u16 *buffer_entry = (u16 *)obj->buffer.pointer; + int buffer_size = obj->buffer.length/2; - if (dell_new_hk_type && (buffer_entry[1] != 0x10)) { + if (buffer_size >= 2 && dell_new_hk_type && buffer_entry[1] != 0x10) { pr_info("Received unknown WMI event (0x%x)\n", buffer_entry[1]); kfree(obj); return; } - if (dell_new_hk_type || buffer_entry[1] == 0x0) + if (buffer_size >= 3 && (dell_new_hk_type || buffer_entry[1] == 0x0)) reported_key = (int)buffer_entry[2]; - else + else if (buffer_size >= 2) reported_key = (int)buffer_entry[1] & 0xffff; + else { + pr_info("Received unknown WMI event\n"); + kfree(obj); + return; + } key = sparse_keymap_entry_from_scancode(dell_wmi_input_dev, reported_key); -- cgit v1.2.3 From 258c590326a9340bc63a46f890e8601d37bde4d7 Mon Sep 17 00:00:00 2001 From: Azael Avalos Date: Mon, 29 Sep 2014 20:40:07 -0600 Subject: toshiba_acpi: Rename hci_raw to tci_raw The function name hci_raw was used before to reflect a raw (read/write) call to Toshiba's Hardware Configuration Interface (HCI), however, since the introduction of the System Configuration Interface (SCI), that "name" no longer applies. This patch changes the name of that function to tci_raw (for Toshiba Configuration Interface), and change the comments about it. Also, the HCI_WORDS definition was changed to TCI_RAW, to better reflect that we're no longer using pure HCI calls, but a combination of HCI and SCI, which form part of the Toshiba Configuration Interface. Signed-off-by: Azael Avalos Signed-off-by: Darren Hart --- drivers/platform/x86/toshiba_acpi.c | 119 ++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 59 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index edd8f3dad6b4..ed3671cfddab 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -71,7 +71,8 @@ MODULE_LICENSE("GPL"); /* Toshiba ACPI method paths */ #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" -/* Toshiba HCI interface definitions +/* The Toshiba configuration interface is composed of the HCI and the SCI, + * which are defined as follows: * * HCI is Toshiba's "Hardware Control Interface" which is supposed to * be uniform across all their models. Ideally we would just call @@ -84,7 +85,7 @@ MODULE_LICENSE("GPL"); * conceal differences in hardware between different models. */ -#define HCI_WORDS 6 +#define TCI_WORDS 6 /* operations */ #define HCI_SET 0xff00 @@ -274,22 +275,22 @@ static int write_acpi_int(const char *methodName, int val) return (status == AE_OK) ? 0 : -EIO; } -/* Perform a raw HCI call. Here we don't care about input or output buffer - * format. +/* Perform a raw configuration call. Here we don't care about input or output + * buffer format. */ -static acpi_status hci_raw(struct toshiba_acpi_dev *dev, - const u32 in[HCI_WORDS], u32 out[HCI_WORDS]) +static acpi_status tci_raw(struct toshiba_acpi_dev *dev, + const u32 in[TCI_WORDS], u32 out[TCI_WORDS]) { struct acpi_object_list params; - union acpi_object in_objs[HCI_WORDS]; + union acpi_object in_objs[TCI_WORDS]; struct acpi_buffer results; - union acpi_object out_objs[HCI_WORDS + 1]; + union acpi_object out_objs[TCI_WORDS + 1]; acpi_status status; int i; - params.count = HCI_WORDS; + params.count = TCI_WORDS; params.pointer = in_objs; - for (i = 0; i < HCI_WORDS; ++i) { + for (i = 0; i < TCI_WORDS; ++i) { in_objs[i].type = ACPI_TYPE_INTEGER; in_objs[i].integer.value = in[i]; } @@ -300,7 +301,7 @@ static acpi_status hci_raw(struct toshiba_acpi_dev *dev, status = acpi_evaluate_object(dev->acpi_dev->handle, (char *)dev->method_hci, ¶ms, &results); - if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) { + if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) { for (i = 0; i < out_objs->package.count; ++i) { out[i] = out_objs->package.elements[i].integer.value; } @@ -318,9 +319,9 @@ static acpi_status hci_raw(struct toshiba_acpi_dev *dev, static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 *result) { - u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; - u32 out[HCI_WORDS]; - acpi_status status = hci_raw(dev, in, out); + u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; + u32 out[TCI_WORDS]; + acpi_status status = tci_raw(dev, in, out); *result = (status == AE_OK) ? out[0] : HCI_FAILURE; return status; } @@ -328,9 +329,9 @@ static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg, static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 *result) { - u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; - u32 out[HCI_WORDS]; - acpi_status status = hci_raw(dev, in, out); + u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; + u32 out[TCI_WORDS]; + acpi_status status = tci_raw(dev, in, out); *out1 = out[2]; *result = (status == AE_OK) ? out[0] : HCI_FAILURE; return status; @@ -339,9 +340,9 @@ static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg, static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2, u32 *result) { - u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 }; - u32 out[HCI_WORDS]; - acpi_status status = hci_raw(dev, in, out); + u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 }; + u32 out[TCI_WORDS]; + acpi_status status = tci_raw(dev, in, out); *result = (status == AE_OK) ? out[0] : HCI_FAILURE; return status; } @@ -349,9 +350,9 @@ static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg, static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 *out2, u32 *result) { - u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 }; - u32 out[HCI_WORDS]; - acpi_status status = hci_raw(dev, in, out); + u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 }; + u32 out[TCI_WORDS]; + acpi_status status = tci_raw(dev, in, out); *out1 = out[2]; *out2 = out[3]; *result = (status == AE_OK) ? out[0] : HCI_FAILURE; @@ -363,11 +364,11 @@ static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg, static int sci_open(struct toshiba_acpi_dev *dev) { - u32 in[HCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 }; + u32 out[TCI_WORDS]; acpi_status status; - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) { pr_err("ACPI call to open SCI failed\n"); return 0; @@ -387,11 +388,11 @@ static int sci_open(struct toshiba_acpi_dev *dev) static void sci_close(struct toshiba_acpi_dev *dev) { - u32 in[HCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 }; + u32 out[TCI_WORDS]; acpi_status status; - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) { pr_err("ACPI call to close SCI failed\n"); return; @@ -408,9 +409,9 @@ static void sci_close(struct toshiba_acpi_dev *dev) static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 *result) { - u32 in[HCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 }; - u32 out[HCI_WORDS]; - acpi_status status = hci_raw(dev, in, out); + u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 }; + u32 out[TCI_WORDS]; + acpi_status status = tci_raw(dev, in, out); *out1 = out[2]; *result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE; return status; @@ -419,9 +420,9 @@ static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg, static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 *result) { - u32 in[HCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 }; - u32 out[HCI_WORDS]; - acpi_status status = hci_raw(dev, in, out); + u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 }; + u32 out[TCI_WORDS]; + acpi_status status = tci_raw(dev, in, out); *result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE; return status; } @@ -429,14 +430,14 @@ static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg, /* Illumination support */ static int toshiba_illumination_available(struct toshiba_acpi_dev *dev) { - u32 in[HCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 }; + u32 out[TCI_WORDS]; acpi_status status; if (!sci_open(dev)) return 0; - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); sci_close(dev); if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) { pr_err("ACPI call to query Illumination support failed\n"); @@ -502,14 +503,14 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) /* KBD Illumination */ static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) { - u32 in[HCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 }; + u32 out[TCI_WORDS]; acpi_status status; if (!sci_open(dev)) return 0; - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); sci_close(dev); if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { pr_err("ACPI call to query kbd illumination support failed\n"); @@ -663,10 +664,10 @@ static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state) static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev) { acpi_status status; - u32 in[HCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; + u32 out[TCI_WORDS]; - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { pr_info("ACPI call to get ECO led failed\n"); return 0; @@ -679,11 +680,11 @@ static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev { struct toshiba_acpi_dev *dev = container_of(cdev, struct toshiba_acpi_dev, eco_led); - u32 in[HCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; + u32 out[TCI_WORDS]; acpi_status status; - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { pr_err("ACPI call to get ECO led failed\n"); return LED_OFF; @@ -697,13 +698,13 @@ static void toshiba_eco_mode_set_status(struct led_classdev *cdev, { struct toshiba_acpi_dev *dev = container_of(cdev, struct toshiba_acpi_dev, eco_led); - u32 in[HCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 }; + u32 out[TCI_WORDS]; acpi_status status; /* Switch the Eco Mode led on/off */ in[2] = (brightness) ? 1 : 0; - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { pr_err("ACPI call to set ECO led failed\n"); return; @@ -713,14 +714,14 @@ static void toshiba_eco_mode_set_status(struct led_classdev *cdev, /* Accelerometer support */ static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev) { - u32 in[HCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 }; + u32 out[TCI_WORDS]; acpi_status status; /* Check if the accelerometer call exists, * this call also serves as initialization */ - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { pr_err("ACPI call to query the accelerometer failed\n"); return -EIO; @@ -739,12 +740,12 @@ static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev) static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, u32 *xy, u32 *z) { - u32 in[HCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 }; + u32 out[TCI_WORDS]; acpi_status status; /* Check the Accelerometer status */ - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { pr_err("ACPI call to query the accelerometer failed\n"); return -EIO; @@ -925,8 +926,8 @@ static int lcd_proc_open(struct inode *inode, struct file *file) static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value) { - u32 in[HCI_WORDS] = { HCI_SET, HCI_LCD_BRIGHTNESS, 0, 0, 0, 0 }; - u32 out[HCI_WORDS]; + u32 in[TCI_WORDS] = { HCI_SET, HCI_LCD_BRIGHTNESS, 0, 0, 0, 0 }; + u32 out[TCI_WORDS]; acpi_status status; if (dev->tr_backlight_supported) { @@ -939,7 +940,7 @@ static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value) } in[2] = value << HCI_LCD_BRIGHTNESS_SHIFT; - status = hci_raw(dev, in, out); + status = tci_raw(dev, in, out); if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) { pr_err("ACPI call to set brightness failed"); return -EIO; -- cgit v1.2.3 From 1864bbc207756c8a3e6e3fe585c11853d28a579a Mon Sep 17 00:00:00 2001 From: Azael Avalos Date: Mon, 29 Sep 2014 20:40:08 -0600 Subject: toshiba_acpi: Unify return codes prefix from HCI/SCI to TOS The return codes are split in between HCI/SCI prefixes, but they are shared (used) by both interfaces, mixing hci_read/write calls with SCI_* return codes, and sci_read/write calls with HCI_* ones. This patch changes the prefix of the return codes definitions, dropping the HCI/SCI naming and instead replacing it with TOS (for TOShiba). Signed-off-by: Azael Avalos Signed-off-by: Darren Hart --- drivers/platform/x86/toshiba_acpi.c | 143 ++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 71 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index ed3671cfddab..589a85836c1a 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -96,17 +96,18 @@ MODULE_LICENSE("GPL"); #define SCI_SET 0xf400 /* return codes */ -#define HCI_SUCCESS 0x0000 -#define HCI_FAILURE 0x1000 -#define HCI_NOT_SUPPORTED 0x8000 -#define HCI_EMPTY 0x8c00 -#define HCI_DATA_NOT_AVAILABLE 0x8d20 -#define HCI_NOT_INITIALIZED 0x8d50 -#define SCI_OPEN_CLOSE_OK 0x0044 -#define SCI_ALREADY_OPEN 0x8100 -#define SCI_NOT_OPENED 0x8200 -#define SCI_INPUT_DATA_ERROR 0x8300 -#define SCI_NOT_PRESENT 0x8600 +#define TOS_SUCCESS 0x0000 +#define TOS_OPEN_CLOSE_OK 0x0044 +#define TOS_FAILURE 0x1000 +#define TOS_NOT_SUPPORTED 0x8000 +#define TOS_ALREADY_OPEN 0x8100 +#define TOS_NOT_OPENED 0x8200 +#define TOS_INPUT_DATA_ERROR 0x8300 +#define TOS_WRITE_PROTECTED 0x8400 +#define TOS_NOT_PRESENT 0x8600 +#define TOS_FIFO_EMPTY 0x8c00 +#define TOS_DATA_NOT_AVAILABLE 0x8d20 +#define TOS_NOT_INITIALIZED 0x8d50 /* registers */ #define HCI_FAN 0x0004 @@ -322,7 +323,7 @@ static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); - *result = (status == AE_OK) ? out[0] : HCI_FAILURE; + *result = (status == AE_OK) ? out[0] : TOS_FAILURE; return status; } @@ -333,7 +334,7 @@ static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); *out1 = out[2]; - *result = (status == AE_OK) ? out[0] : HCI_FAILURE; + *result = (status == AE_OK) ? out[0] : TOS_FAILURE; return status; } @@ -343,7 +344,7 @@ static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 }; u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); - *result = (status == AE_OK) ? out[0] : HCI_FAILURE; + *result = (status == AE_OK) ? out[0] : TOS_FAILURE; return status; } @@ -355,7 +356,7 @@ static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg, acpi_status status = tci_raw(dev, in, out); *out1 = out[2]; *out2 = out[3]; - *result = (status == AE_OK) ? out[0] : HCI_FAILURE; + *result = (status == AE_OK) ? out[0] : TOS_FAILURE; return status; } @@ -369,17 +370,17 @@ static int sci_open(struct toshiba_acpi_dev *dev) acpi_status status; status = tci_raw(dev, in, out); - if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) { + if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { pr_err("ACPI call to open SCI failed\n"); return 0; } - if (out[0] == SCI_OPEN_CLOSE_OK) { + if (out[0] == TOS_OPEN_CLOSE_OK) { return 1; - } else if (out[0] == SCI_ALREADY_OPEN) { + } else if (out[0] == TOS_ALREADY_OPEN) { pr_info("Toshiba SCI already opened\n"); return 1; - } else if (out[0] == SCI_NOT_PRESENT) { + } else if (out[0] == TOS_NOT_PRESENT) { pr_info("Toshiba SCI is not present\n"); } @@ -393,16 +394,16 @@ static void sci_close(struct toshiba_acpi_dev *dev) acpi_status status; status = tci_raw(dev, in, out); - if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) { + if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { pr_err("ACPI call to close SCI failed\n"); return; } - if (out[0] == SCI_OPEN_CLOSE_OK) + if (out[0] == TOS_OPEN_CLOSE_OK) return; - else if (out[0] == SCI_NOT_OPENED) + else if (out[0] == TOS_NOT_OPENED) pr_info("Toshiba SCI not opened\n"); - else if (out[0] == SCI_NOT_PRESENT) + else if (out[0] == TOS_NOT_PRESENT) pr_info("Toshiba SCI is not present\n"); } @@ -413,7 +414,7 @@ static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); *out1 = out[2]; - *result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE; + *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE; return status; } @@ -423,7 +424,7 @@ static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 }; u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); - *result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE; + *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE; return status; } @@ -439,10 +440,10 @@ static int toshiba_illumination_available(struct toshiba_acpi_dev *dev) status = tci_raw(dev, in, out); sci_close(dev); - if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) { + if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { pr_err("ACPI call to query Illumination support failed\n"); return 0; - } else if (out[0] == HCI_NOT_SUPPORTED) { + } else if (out[0] == TOS_NOT_SUPPORTED) { pr_info("Illumination device not available\n"); return 0; } @@ -469,7 +470,7 @@ static void toshiba_illumination_set(struct led_classdev *cdev, if (ACPI_FAILURE(status)) { pr_err("ACPI call for illumination failed\n"); return; - } else if (result == HCI_NOT_SUPPORTED) { + } else if (result == TOS_NOT_SUPPORTED) { pr_info("Illumination not supported\n"); return; } @@ -489,10 +490,10 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) /* Check the illumination */ status = sci_read(dev, SCI_ILLUMINATION, &state, &result); sci_close(dev); - if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call for illumination failed\n"); return LED_OFF; - } else if (result == HCI_NOT_SUPPORTED) { + } else if (result == TOS_NOT_SUPPORTED) { pr_info("Illumination not supported\n"); return LED_OFF; } @@ -512,10 +513,10 @@ static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) status = tci_raw(dev, in, out); sci_close(dev); - if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to query kbd illumination support failed\n"); return 0; - } else if (out[0] == HCI_NOT_SUPPORTED) { + } else if (out[0] == TOS_NOT_SUPPORTED) { pr_info("Keyboard illumination not available\n"); return 0; } @@ -547,10 +548,10 @@ static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time) status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result); sci_close(dev); - if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to set KBD backlight status failed\n"); return -EIO; - } else if (result == HCI_NOT_SUPPORTED) { + } else if (result == TOS_NOT_SUPPORTED) { pr_info("Keyboard backlight status not supported\n"); return -ENODEV; } @@ -568,10 +569,10 @@ static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time) status = sci_read(dev, SCI_KBD_ILLUM_STATUS, time, &result); sci_close(dev); - if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to get KBD backlight status failed\n"); return -EIO; - } else if (result == HCI_NOT_SUPPORTED) { + } else if (result == TOS_NOT_SUPPORTED) { pr_info("Keyboard backlight status not supported\n"); return -ENODEV; } @@ -588,10 +589,10 @@ static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev) /* Check the keyboard backlight state */ status = hci_read1(dev, HCI_KBD_ILLUMINATION, &state, &result); - if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to get the keyboard backlight failed\n"); return LED_OFF; - } else if (result == HCI_NOT_SUPPORTED) { + } else if (result == TOS_NOT_SUPPORTED) { pr_info("Keyboard backlight not supported\n"); return LED_OFF; } @@ -610,10 +611,10 @@ static void toshiba_kbd_backlight_set(struct led_classdev *cdev, /* Set the keyboard backlight state */ state = brightness ? 1 : 0; status = hci_write1(dev, HCI_KBD_ILLUMINATION, state, &result); - if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to set KBD Illumination mode failed\n"); return; - } else if (result == HCI_NOT_SUPPORTED) { + } else if (result == TOS_NOT_SUPPORTED) { pr_info("Keyboard backlight not supported\n"); return; } @@ -633,7 +634,7 @@ static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state) if (ACPI_FAILURE(status)) { pr_err("ACPI call to set the touchpad failed\n"); return -EIO; - } else if (result == HCI_NOT_SUPPORTED) { + } else if (result == TOS_NOT_SUPPORTED) { return -ENODEV; } @@ -653,7 +654,7 @@ static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state) if (ACPI_FAILURE(status)) { pr_err("ACPI call to query the touchpad failed\n"); return -EIO; - } else if (result == HCI_NOT_SUPPORTED) { + } else if (result == TOS_NOT_SUPPORTED) { return -ENODEV; } @@ -668,7 +669,7 @@ static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev) u32 out[TCI_WORDS]; status = tci_raw(dev, in, out); - if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { pr_info("ACPI call to get ECO led failed\n"); return 0; } @@ -685,7 +686,7 @@ static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev acpi_status status; status = tci_raw(dev, in, out); - if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to get ECO led failed\n"); return LED_OFF; } @@ -705,7 +706,7 @@ static void toshiba_eco_mode_set_status(struct led_classdev *cdev, /* Switch the Eco Mode led on/off */ in[2] = (brightness) ? 1 : 0; status = tci_raw(dev, in, out); - if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to set ECO led failed\n"); return; } @@ -722,14 +723,14 @@ static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev) * this call also serves as initialization */ status = tci_raw(dev, in, out); - if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to query the accelerometer failed\n"); return -EIO; - } else if (out[0] == HCI_DATA_NOT_AVAILABLE || - out[0] == HCI_NOT_INITIALIZED) { + } else if (out[0] == TOS_DATA_NOT_AVAILABLE || + out[0] == TOS_NOT_INITIALIZED) { pr_err("Accelerometer not initialized\n"); return -EIO; - } else if (out[0] == HCI_NOT_SUPPORTED) { + } else if (out[0] == TOS_NOT_SUPPORTED) { pr_info("Accelerometer not supported\n"); return -ENODEV; } @@ -746,7 +747,7 @@ static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, /* Check the Accelerometer status */ status = tci_raw(dev, in, out); - if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) { + if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to query the accelerometer failed\n"); return -EIO; } @@ -767,7 +768,7 @@ static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present) value = 0; value2 = 0; hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result); - if (hci_result == HCI_SUCCESS) + if (hci_result == TOS_SUCCESS) *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false; return hci_result; @@ -797,7 +798,7 @@ static int bt_rfkill_set_block(void *data, bool blocked) value = (blocked == false); mutex_lock(&dev->mutex); - if (hci_get_radio_state(dev, &radio_state) != HCI_SUCCESS) { + if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) { err = -EIO; goto out; } @@ -810,7 +811,7 @@ static int bt_rfkill_set_block(void *data, bool blocked) hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1); hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2); - if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS) + if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS) err = -EIO; else err = 0; @@ -829,7 +830,7 @@ static void bt_rfkill_poll(struct rfkill *rfkill, void *data) mutex_lock(&dev->mutex); hci_result = hci_get_radio_state(dev, &value); - if (hci_result != HCI_SUCCESS) { + if (hci_result != TOS_SUCCESS) { /* Can't do anything useful */ mutex_unlock(&dev->mutex); return; @@ -855,7 +856,7 @@ static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled) hci_read1(dev, HCI_TR_BACKLIGHT, &status, &hci_result); *enabled = !status; - return hci_result == HCI_SUCCESS ? 0 : -EIO; + return hci_result == TOS_SUCCESS ? 0 : -EIO; } static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable) @@ -864,7 +865,7 @@ static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable) u32 value = !enable; hci_write1(dev, HCI_TR_BACKLIGHT, value, &hci_result); - return hci_result == HCI_SUCCESS ? 0 : -EIO; + return hci_result == TOS_SUCCESS ? 0 : -EIO; } static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; @@ -886,7 +887,7 @@ static int __get_lcd_brightness(struct toshiba_acpi_dev *dev) } hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result); - if (hci_result == HCI_SUCCESS) + if (hci_result == TOS_SUCCESS) return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT); return -EIO; @@ -941,18 +942,18 @@ static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value) in[2] = value << HCI_LCD_BRIGHTNESS_SHIFT; status = tci_raw(dev, in, out); - if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) { + if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { pr_err("ACPI call to set brightness failed"); return -EIO; } /* Extra check for "incomplete" backlight method, where the AML code - * doesn't check for HCI_SET or HCI_GET and returns HCI_SUCCESS, + * doesn't check for HCI_SET or HCI_GET and returns TOS_SUCCESS, * the actual brightness, and in some cases the max brightness. */ if (out[2] > 0 || out[3] == 0xE000) return -ENODEV; - return out[0] == HCI_SUCCESS ? 0 : -EIO; + return out[0] == TOS_SUCCESS ? 0 : -EIO; } static int set_lcd_status(struct backlight_device *bd) @@ -1001,7 +1002,7 @@ static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status) u32 hci_result; hci_read1(dev, HCI_VIDEO_OUT, status, &hci_result); - return hci_result == HCI_SUCCESS ? 0 : -EIO; + return hci_result == TOS_SUCCESS ? 0 : -EIO; } static int video_proc_show(struct seq_file *m, void *v) @@ -1105,7 +1106,7 @@ static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) u32 hci_result; hci_read1(dev, HCI_FAN, status, &hci_result); - return hci_result == HCI_SUCCESS ? 0 : -EIO; + return hci_result == TOS_SUCCESS ? 0 : -EIO; } static int fan_proc_show(struct seq_file *m, void *v) @@ -1145,7 +1146,7 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf, if (sscanf(cmd, " force_on : %i", &value) == 1 && value >= 0 && value <= 1) { hci_write1(dev, HCI_FAN, value, &hci_result); - if (hci_result != HCI_SUCCESS) + if (hci_result != TOS_SUCCESS) return -EIO; else dev->force_fan = value; @@ -1173,12 +1174,12 @@ static int keys_proc_show(struct seq_file *m, void *v) if (!dev->key_event_valid && dev->system_event_supported) { hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result); - if (hci_result == HCI_SUCCESS) { + if (hci_result == TOS_SUCCESS) { dev->key_event_valid = 1; dev->last_key_event = value; - } else if (hci_result == HCI_EMPTY) { + } else if (hci_result == TOS_FIFO_EMPTY) { /* better luck next time */ - } else if (hci_result == HCI_NOT_SUPPORTED) { + } else if (hci_result == TOS_NOT_SUPPORTED) { /* This is a workaround for an unresolved issue on * some machines where system events sporadically * become disabled. */ @@ -1677,7 +1678,7 @@ static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) dev->info_supported = 1; else { hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result); - if (hci_result == HCI_SUCCESS) + if (hci_result == TOS_SUCCESS) dev->system_event_supported = 1; } @@ -1857,7 +1858,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) goto error; /* Register rfkill switch for Bluetooth */ - if (hci_get_bt_present(dev, &bt_present) == HCI_SUCCESS && bt_present) { + if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) { dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth", &acpi_dev->dev, RFKILL_TYPE_BLUETOOTH, @@ -1962,10 +1963,10 @@ static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) do { hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result); switch (hci_result) { - case HCI_SUCCESS: + case TOS_SUCCESS: toshiba_acpi_report_hotkey(dev, (int)value); break; - case HCI_NOT_SUPPORTED: + case TOS_NOT_SUPPORTED: /* * This is a workaround for an unresolved * issue on some machines where system events @@ -1979,7 +1980,7 @@ static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) retries--; break; } - } while (retries && hci_result != HCI_EMPTY); + } while (retries && hci_result != TOS_FIFO_EMPTY); } } -- cgit v1.2.3 From 893f3f62dc7ade3700cdceed23ce38bb92e3966b Mon Sep 17 00:00:00 2001 From: Azael Avalos Date: Mon, 29 Sep 2014 20:40:09 -0600 Subject: toshiba_acpi: Change HCI/SCI functions return code type Currently the HCI/SCI read/write functions are returning the status of the ACPI call and also assigning the returned value of the HCI/SCI function, however, only the HCI/SCI status is being checked. This patch changes such functions, returning the value of the HCI/SCI function instead of the ACPI call status, eliminating one parameter, and returning something useful that indeed is being checked. Signed-off-by: Azael Avalos Signed-off-by: Darren Hart --- drivers/platform/x86/toshiba_acpi.c | 129 +++++++++++++++++------------------- 1 file changed, 62 insertions(+), 67 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 589a85836c1a..5d509eac8ce6 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -317,47 +317,49 @@ static acpi_status tci_raw(struct toshiba_acpi_dev *dev, * may be useful (such as "not supported"). */ -static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg, - u32 in1, u32 *result) +static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) { u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); - *result = (status == AE_OK) ? out[0] : TOS_FAILURE; - return status; + + return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; } -static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg, - u32 *out1, u32 *result) +static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) { u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); + if (ACPI_FAILURE(status)) + return TOS_FAILURE; + *out1 = out[2]; - *result = (status == AE_OK) ? out[0] : TOS_FAILURE; - return status; + + return out[0]; } -static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg, - u32 in1, u32 in2, u32 *result) +static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2) { u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 }; u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); - *result = (status == AE_OK) ? out[0] : TOS_FAILURE; - return status; + + return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; } -static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg, - u32 *out1, u32 *out2, u32 *result) +static u32 hci_read2(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 *out2) { u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 }; u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); + if (ACPI_FAILURE(status)) + return TOS_FAILURE; + *out1 = out[2]; *out2 = out[3]; - *result = (status == AE_OK) ? out[0] : TOS_FAILURE; - return status; + + return out[0]; } /* common sci tasks @@ -407,25 +409,26 @@ static void sci_close(struct toshiba_acpi_dev *dev) pr_info("Toshiba SCI is not present\n"); } -static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg, - u32 *out1, u32 *result) +static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) { u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 }; u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); + if (ACPI_FAILURE(status)) + return TOS_FAILURE; + *out1 = out[2]; - *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE; - return status; + + return out[0]; } -static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg, - u32 in1, u32 *result) +static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) { u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 }; u32 out[TCI_WORDS]; acpi_status status = tci_raw(dev, in, out); - *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE; - return status; + + return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; } /* Illumination support */ @@ -457,7 +460,6 @@ static void toshiba_illumination_set(struct led_classdev *cdev, struct toshiba_acpi_dev *dev = container_of(cdev, struct toshiba_acpi_dev, led_dev); u32 state, result; - acpi_status status; /* First request : initialize communication. */ if (!sci_open(dev)) @@ -465,9 +467,9 @@ static void toshiba_illumination_set(struct led_classdev *cdev, /* Switch the illumination on/off */ state = brightness ? 1 : 0; - status = sci_write(dev, SCI_ILLUMINATION, state, &result); + result = sci_write(dev, SCI_ILLUMINATION, state); sci_close(dev); - if (ACPI_FAILURE(status)) { + if (result == TOS_FAILURE) { pr_err("ACPI call for illumination failed\n"); return; } else if (result == TOS_NOT_SUPPORTED) { @@ -481,16 +483,15 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) struct toshiba_acpi_dev *dev = container_of(cdev, struct toshiba_acpi_dev, led_dev); u32 state, result; - acpi_status status; /* First request : initialize communication. */ if (!sci_open(dev)) return LED_OFF; /* Check the illumination */ - status = sci_read(dev, SCI_ILLUMINATION, &state, &result); + result = sci_read(dev, SCI_ILLUMINATION, &state); sci_close(dev); - if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { + if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call for illumination failed\n"); return LED_OFF; } else if (result == TOS_NOT_SUPPORTED) { @@ -541,14 +542,13 @@ static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time) { u32 result; - acpi_status status; if (!sci_open(dev)) return -EIO; - status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result); + result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time); sci_close(dev); - if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { + if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to set KBD backlight status failed\n"); return -EIO; } else if (result == TOS_NOT_SUPPORTED) { @@ -562,14 +562,13 @@ static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time) static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time) { u32 result; - acpi_status status; if (!sci_open(dev)) return -EIO; - status = sci_read(dev, SCI_KBD_ILLUM_STATUS, time, &result); + result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time); sci_close(dev); - if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { + if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to get KBD backlight status failed\n"); return -EIO; } else if (result == TOS_NOT_SUPPORTED) { @@ -585,11 +584,10 @@ static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev) struct toshiba_acpi_dev *dev = container_of(cdev, struct toshiba_acpi_dev, kbd_led); u32 state, result; - acpi_status status; /* Check the keyboard backlight state */ - status = hci_read1(dev, HCI_KBD_ILLUMINATION, &state, &result); - if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { + result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state); + if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to get the keyboard backlight failed\n"); return LED_OFF; } else if (result == TOS_NOT_SUPPORTED) { @@ -606,12 +604,11 @@ static void toshiba_kbd_backlight_set(struct led_classdev *cdev, struct toshiba_acpi_dev *dev = container_of(cdev, struct toshiba_acpi_dev, kbd_led); u32 state, result; - acpi_status status; /* Set the keyboard backlight state */ state = brightness ? 1 : 0; - status = hci_write1(dev, HCI_KBD_ILLUMINATION, state, &result); - if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) { + result = hci_write1(dev, HCI_KBD_ILLUMINATION, state); + if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { pr_err("ACPI call to set KBD Illumination mode failed\n"); return; } else if (result == TOS_NOT_SUPPORTED) { @@ -624,14 +621,13 @@ static void toshiba_kbd_backlight_set(struct led_classdev *cdev, static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state) { u32 result; - acpi_status status; if (!sci_open(dev)) return -EIO; - status = sci_write(dev, SCI_TOUCHPAD, state, &result); + result = sci_write(dev, SCI_TOUCHPAD, state); sci_close(dev); - if (ACPI_FAILURE(status)) { + if (result == TOS_FAILURE) { pr_err("ACPI call to set the touchpad failed\n"); return -EIO; } else if (result == TOS_NOT_SUPPORTED) { @@ -644,14 +640,13 @@ static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state) static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state) { u32 result; - acpi_status status; if (!sci_open(dev)) return -EIO; - status = sci_read(dev, SCI_TOUCHPAD, state, &result); + result = sci_read(dev, SCI_TOUCHPAD, state); sci_close(dev); - if (ACPI_FAILURE(status)) { + if (result == TOS_FAILURE) { pr_err("ACPI call to query the touchpad failed\n"); return -EIO; } else if (result == TOS_NOT_SUPPORTED) { @@ -767,7 +762,7 @@ static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present) value = 0; value2 = 0; - hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result); + hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2); if (hci_result == TOS_SUCCESS) *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false; @@ -781,7 +776,7 @@ static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state) value = 0; value2 = 0x0001; - hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result); + hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2); *radio_state = value & HCI_WIRELESS_KILL_SWITCH; return hci_result; @@ -808,8 +803,8 @@ static int bt_rfkill_set_block(void *data, bool blocked) goto out; } - hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1); - hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2); + result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER); + result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH); if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS) err = -EIO; @@ -854,7 +849,7 @@ static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled) u32 hci_result; u32 status; - hci_read1(dev, HCI_TR_BACKLIGHT, &status, &hci_result); + hci_result = hci_read1(dev, HCI_TR_BACKLIGHT, &status); *enabled = !status; return hci_result == TOS_SUCCESS ? 0 : -EIO; } @@ -864,7 +859,7 @@ static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable) u32 hci_result; u32 value = !enable; - hci_write1(dev, HCI_TR_BACKLIGHT, value, &hci_result); + hci_result = hci_write1(dev, HCI_TR_BACKLIGHT, value); return hci_result == TOS_SUCCESS ? 0 : -EIO; } @@ -886,7 +881,7 @@ static int __get_lcd_brightness(struct toshiba_acpi_dev *dev) brightness++; } - hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result); + hci_result = hci_read1(dev, HCI_LCD_BRIGHTNESS, &value); if (hci_result == TOS_SUCCESS) return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT); @@ -1001,7 +996,7 @@ static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status) { u32 hci_result; - hci_read1(dev, HCI_VIDEO_OUT, status, &hci_result); + hci_result = hci_read1(dev, HCI_VIDEO_OUT, status); return hci_result == TOS_SUCCESS ? 0 : -EIO; } @@ -1105,7 +1100,7 @@ static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) { u32 hci_result; - hci_read1(dev, HCI_FAN, status, &hci_result); + hci_result = hci_read1(dev, HCI_FAN, status); return hci_result == TOS_SUCCESS ? 0 : -EIO; } @@ -1145,7 +1140,7 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf, if (sscanf(cmd, " force_on : %i", &value) == 1 && value >= 0 && value <= 1) { - hci_write1(dev, HCI_FAN, value, &hci_result); + hci_result = hci_write1(dev, HCI_FAN, value); if (hci_result != TOS_SUCCESS) return -EIO; else @@ -1173,7 +1168,7 @@ static int keys_proc_show(struct seq_file *m, void *v) u32 value; if (!dev->key_event_valid && dev->system_event_supported) { - hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result); + hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value); if (hci_result == TOS_SUCCESS) { dev->key_event_valid = 1; dev->last_key_event = value; @@ -1183,7 +1178,7 @@ static int keys_proc_show(struct seq_file *m, void *v) /* This is a workaround for an unresolved issue on * some machines where system events sporadically * become disabled. */ - hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result); + hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1); pr_notice("Re-enabled hotkeys\n"); } else { pr_err("Error reading hotkey status\n"); @@ -1677,7 +1672,7 @@ static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) if (acpi_has_method(dev->acpi_dev->handle, "INFO")) dev->info_supported = 1; else { - hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result); + hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1); if (hci_result == TOS_SUCCESS) dev->system_event_supported = 1; } @@ -1700,7 +1695,7 @@ static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) goto err_remove_filter; } - hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &hci_result); + hci_result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE); return 0; err_remove_filter: @@ -1961,7 +1956,7 @@ static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) toshiba_acpi_report_hotkey(dev, scancode); } else if (dev->system_event_supported) { do { - hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result); + hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value); switch (hci_result) { case TOS_SUCCESS: toshiba_acpi_report_hotkey(dev, (int)value); @@ -1972,8 +1967,8 @@ static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) * issue on some machines where system events * sporadically become disabled. */ - hci_write1(dev, HCI_SYSTEM_EVENT, 1, - &hci_result); + hci_result = + hci_write1(dev, HCI_SYSTEM_EVENT, 1); pr_notice("Re-enabled hotkeys\n"); /* fall through */ default: @@ -1991,7 +1986,7 @@ static int toshiba_acpi_suspend(struct device *device) u32 result; if (dev->hotkey_dev) - hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE, &result); + result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE); return 0; } @@ -2008,7 +2003,7 @@ static int toshiba_acpi_resume(struct device *device) if (ACPI_FAILURE(status)) pr_info("Unable to re-enable hotkeys\n"); - hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &result); + result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE); } return 0; -- cgit v1.2.3 From eabde0fa967052df12bdd8e8a72f0af799e1e704 Mon Sep 17 00:00:00 2001 From: Azael Avalos Date: Sat, 4 Oct 2014 12:02:21 -0600 Subject: toshiba_acpi: Adapt kbd_bl_timeout_store to the new kbd type With the introduction of the new keyboard backlight implementation, the *_timeout_store function is broken, as it only supports the first kbd_type. This patch adapts such function for the new kbd_type, as well as converts from using sscanf to kstrtoint. Signed-off-by: Azael Avalos Signed-off-by: Darren Hart --- drivers/platform/x86/toshiba_acpi.c | 38 ++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 5d509eac8ce6..ef3a1904e92f 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -1453,18 +1453,38 @@ static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev, const char *buf, size_t count) { struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); - int time = -1; + int time; + int ret; - if (sscanf(buf, "%i", &time) != 1 && (time < 0 || time > 60)) - return -EINVAL; + ret = kstrtoint(buf, 0, &time); + if (ret) + return ret; + + /* Check for supported values depending on kbd_type */ + if (toshiba->kbd_type == 1) { + if (time < 0 || time > 60) + return -EINVAL; + } else if (toshiba->kbd_type == 2) { + if (time < 1 || time > 60) + return -EINVAL; + } + + /* Set the Keyboard Backlight Timeout */ - /* Set the Keyboard Backlight Timeout: 0-60 seconds */ - if (time != -1 && toshiba->kbd_time != time) { + /* Only make a change if the actual timeout has changed */ + if (toshiba->kbd_time != time) { + /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ time = time << HCI_MISC_SHIFT; - time = (toshiba->kbd_mode == SCI_KBD_MODE_AUTO) ? - time + 1 : time + 2; - if (toshiba_kbd_illum_status_set(toshiba, time) < 0) - return -EIO; + /* OR the "base time" to the actual method format */ + if (toshiba->kbd_type == 1) + time |= SCI_KBD_MODE_FNZ; + else if (toshiba->kbd_type == 2) + time |= SCI_KBD_MODE_AUTO; + + ret = toshiba_kbd_illum_status_set(toshiba, time); + if (ret) + return ret; + toshiba->kbd_time = time >> HCI_MISC_SHIFT; } -- cgit v1.2.3