platform/x86: ideapad-laptop: fix checkpatch warnings, more consistent style

Fix all checkpatch warnings. Reorder variable definitions from
longest to shortest. Add more whitespaces for better readability.
Rename variables named `ret` to `err` where appropriate. Reorder
sysfs attributes show/store callbacks and the `ideapad_attributes`
array in lexicographic order. And other minor formatting changes.
No significant functional changes are intended.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-25-pobrn@protonmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Barnabás Pőcze 2021-02-03 21:56:56 +00:00 committed by Hans de Goede
parent 921f70ffe8
commit 65c7713a50

View File

@ -31,7 +31,7 @@
#include <acpi/video.h> #include <acpi/video.h>
#define IDEAPAD_RFKILL_DEV_NUM (3) #define IDEAPAD_RFKILL_DEV_NUM 3
#if IS_ENABLED(CONFIG_ACPI_WMI) #if IS_ENABLED(CONFIG_ACPI_WMI)
static const char *const ideapad_wmi_fnesc_events[] = { static const char *const ideapad_wmi_fnesc_events[] = {
@ -98,7 +98,7 @@ enum {
struct ideapad_dytc_priv { struct ideapad_dytc_priv {
enum platform_profile_option current_profile; enum platform_profile_option current_profile;
struct platform_profile_handler pprof; struct platform_profile_handler pprof;
struct mutex mutex; struct mutex mutex; /* protects the DYTC interface */
struct ideapad_private *priv; struct ideapad_private *priv;
}; };
@ -135,7 +135,7 @@ MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
/* /*
* ACPI Helpers * ACPI Helpers
*/ */
#define IDEAPAD_EC_TIMEOUT (200) /* in ms */ #define IDEAPAD_EC_TIMEOUT 200 /* in ms */
static int eval_int(acpi_handle handle, const char *name, unsigned long *res) static int eval_int(acpi_handle handle, const char *name, unsigned long *res)
{ {
@ -145,7 +145,9 @@ static int eval_int(acpi_handle handle, const char *name, unsigned long *res)
status = acpi_evaluate_integer(handle, (char *)name, NULL, &result); status = acpi_evaluate_integer(handle, (char *)name, NULL, &result);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -EIO; return -EIO;
*res = result; *res = result;
return 0; return 0;
} }
@ -224,6 +226,7 @@ static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data)
status = acpi_evaluate_object(handle, "VPCW", &params, NULL); status = acpi_evaluate_object(handle, "VPCW", &params, NULL);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -EIO; return -EIO;
return 0; return 0;
} }
@ -240,13 +243,17 @@ static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *da
while (time_before(jiffies, end_jiffies)) { while (time_before(jiffies, end_jiffies)) {
schedule(); schedule();
err = eval_vpcr(handle, 1, &val); err = eval_vpcr(handle, 1, &val);
if (err) if (err)
return err; return err;
if (val == 0) if (val == 0)
return eval_vpcr(handle, 0, data); return eval_vpcr(handle, 0, data);
} }
acpi_handle_err(handle, "timeout in %s\n", __func__); acpi_handle_err(handle, "timeout in %s\n", __func__);
return -ETIMEDOUT; return -ETIMEDOUT;
} }
@ -258,6 +265,7 @@ static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long dat
err = eval_vpcw(handle, 0, data); err = eval_vpcw(handle, 0, data);
if (err) if (err)
return err; return err;
err = eval_vpcw(handle, 1, cmd); err = eval_vpcw(handle, 1, cmd);
if (err) if (err)
return err; return err;
@ -266,13 +274,17 @@ static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long dat
while (time_before(jiffies, end_jiffies)) { while (time_before(jiffies, end_jiffies)) {
schedule(); schedule();
err = eval_vpcr(handle, 1, &val); err = eval_vpcr(handle, 1, &val);
if (err) if (err)
return err; return err;
if (val == 0) if (val == 0)
return 0; return 0;
} }
acpi_handle_err(handle, "timeout in %s\n", __func__); acpi_handle_err(handle, "timeout in %s\n", __func__);
return -ETIMEDOUT; return -ETIMEDOUT;
} }
@ -290,6 +302,7 @@ static int debugfs_status_show(struct seq_file *s, void *data)
seq_printf(s, "Backlight now: %lu\n", value); seq_printf(s, "Backlight now: %lu\n", value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value)) if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value))
seq_printf(s, "BL power value: %s (%lu)\n", value ? "on" : "off", value); seq_printf(s, "BL power value: %s (%lu)\n", value ? "on" : "off", value);
seq_puts(s, "=====================\n"); seq_puts(s, "=====================\n");
if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value)) if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value))
@ -300,12 +313,14 @@ static int debugfs_status_show(struct seq_file *s, void *data)
seq_printf(s, "BT status: %s (%lu)\n", value ? "on" : "off", value); seq_printf(s, "BT status: %s (%lu)\n", value ? "on" : "off", value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value)) if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value))
seq_printf(s, "3G status: %s (%lu)\n", value ? "on" : "off", value); seq_printf(s, "3G status: %s (%lu)\n", value ? "on" : "off", value);
seq_puts(s, "=====================\n"); seq_puts(s, "=====================\n");
if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value))
seq_printf(s, "Touchpad status: %s (%lu)\n", value ? "on" : "off", value); seq_printf(s, "Touchpad status: %s (%lu)\n", value ? "on" : "off", value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value)) if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value))
seq_printf(s, "Camera status: %s (%lu)\n", value ? "on" : "off", value); seq_printf(s, "Camera status: %s (%lu)\n", value ? "on" : "off", value);
seq_puts(s, "=====================\n"); seq_puts(s, "=====================\n");
if (!eval_gbmd(priv->adev->handle, &value)) if (!eval_gbmd(priv->adev->handle, &value))
@ -367,8 +382,8 @@ static void ideapad_debugfs_init(struct ideapad_private *priv)
dir = debugfs_create_dir("ideapad", NULL); dir = debugfs_create_dir("ideapad", NULL);
priv->debug = dir; priv->debug = dir;
debugfs_create_file("cfg", S_IRUGO, dir, priv, &debugfs_cfg_fops); debugfs_create_file("cfg", 0444, dir, priv, &debugfs_cfg_fops);
debugfs_create_file("status", S_IRUGO, dir, priv, &debugfs_status_fops); debugfs_create_file("status", 0444, dir, priv, &debugfs_status_fops);
} }
static void ideapad_debugfs_exit(struct ideapad_private *priv) static void ideapad_debugfs_exit(struct ideapad_private *priv)
@ -380,73 +395,152 @@ static void ideapad_debugfs_exit(struct ideapad_private *priv)
/* /*
* sysfs * sysfs
*/ */
static ssize_t show_ideapad_cam(struct device *dev, static ssize_t camera_power_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
unsigned long result;
struct ideapad_private *priv = dev_get_drvdata(dev); struct ideapad_private *priv = dev_get_drvdata(dev);
unsigned long result;
int err; int err;
err = read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result); err = read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result);
if (err) if (err)
return err; return err;
return sysfs_emit(buf, "%d\n", !!result); return sysfs_emit(buf, "%d\n", !!result);
} }
static ssize_t store_ideapad_cam(struct device *dev, static ssize_t camera_power_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct ideapad_private *priv = dev_get_drvdata(dev); struct ideapad_private *priv = dev_get_drvdata(dev);
bool state; bool state;
int ret; int err;
err = kstrtobool(buf, &state);
if (err)
return err;
err = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state);
if (err)
return err;
ret = kstrtobool(buf, &state);
if (ret)
return ret;
ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state);
if (ret)
return ret;
return count; return count;
} }
static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam); static DEVICE_ATTR_RW(camera_power);
static ssize_t show_ideapad_fan(struct device *dev, static ssize_t conservation_mode_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
unsigned long result;
struct ideapad_private *priv = dev_get_drvdata(dev); struct ideapad_private *priv = dev_get_drvdata(dev);
unsigned long result;
int err;
err = eval_gbmd(priv->adev->handle, &result);
if (err)
return err;
return sysfs_emit(buf, "%d\n", !!test_bit(GBMD_CONSERVATION_STATE_BIT, &result));
}
static ssize_t conservation_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
bool state;
int err;
err = kstrtobool(buf, &state);
if (err)
return err;
err = exec_smbc(priv->adev->handle, state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF);
if (err)
return err;
return count;
}
static DEVICE_ATTR_RW(conservation_mode);
static ssize_t fan_mode_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
unsigned long result;
int err; int err;
err = read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result); err = read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result);
if (err) if (err)
return err; return err;
return sysfs_emit(buf, "%lu\n", result); return sysfs_emit(buf, "%lu\n", result);
} }
static ssize_t store_ideapad_fan(struct device *dev, static ssize_t fan_mode_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct ideapad_private *priv = dev_get_drvdata(dev); struct ideapad_private *priv = dev_get_drvdata(dev);
unsigned int state; unsigned int state;
int ret; int err;
err = kstrtouint(buf, 0, &state);
if (err)
return err;
ret = kstrtouint(buf, 0, &state);
if (ret)
return ret;
if (state > 4 || state == 3) if (state > 4 || state == 3)
return -EINVAL; return -EINVAL;
ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state);
if (ret) err = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state);
return ret; if (err)
return err;
return count; return count;
} }
static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan); static DEVICE_ATTR_RW(fan_mode);
static ssize_t fn_lock_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
unsigned long hals;
int err;
err = eval_hals(priv->adev->handle, &hals);
if (err)
return err;
return sysfs_emit(buf, "%d\n", !!test_bit(HALS_FNLOCK_STATE_BIT, &hals));
}
static ssize_t fn_lock_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
bool state;
int err;
err = kstrtobool(buf, &state);
if (err)
return err;
err = exec_sals(priv->adev->handle, state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF);
if (err)
return err;
return count;
}
static DEVICE_ATTR_RW(fn_lock);
static ssize_t touchpad_show(struct device *dev, static ssize_t touchpad_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
@ -459,6 +553,7 @@ static ssize_t touchpad_show(struct device *dev,
err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result); err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result);
if (err) if (err)
return err; return err;
return sysfs_emit(buf, "%d\n", !!result); return sysfs_emit(buf, "%d\n", !!result);
} }
@ -468,101 +563,33 @@ static ssize_t touchpad_store(struct device *dev,
{ {
struct ideapad_private *priv = dev_get_drvdata(dev); struct ideapad_private *priv = dev_get_drvdata(dev);
bool state; bool state;
int ret; int err;
ret = kstrtobool(buf, &state); err = kstrtobool(buf, &state);
if (ret) if (err)
return ret; return err;
err = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state);
if (err)
return err;
ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state);
if (ret)
return ret;
return count; return count;
} }
static DEVICE_ATTR_RW(touchpad); static DEVICE_ATTR_RW(touchpad);
static ssize_t conservation_mode_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
unsigned long result;
int err;
err = eval_gbmd(priv->adev->handle, &result);
if (err)
return err;
return sysfs_emit(buf, "%d\n", !!test_bit(GBMD_CONSERVATION_STATE_BIT, &result));
}
static ssize_t conservation_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
bool state;
int ret;
ret = kstrtobool(buf, &state);
if (ret)
return ret;
ret = exec_smbc(priv->adev->handle, state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF);
if (ret)
return ret;
return count;
}
static DEVICE_ATTR_RW(conservation_mode);
static ssize_t fn_lock_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
unsigned long hals;
int fail = eval_hals(priv->adev->handle, &hals);
if (fail)
return fail;
return sysfs_emit(buf, "%d\n", !!test_bit(HALS_FNLOCK_STATE_BIT, &hals));
}
static ssize_t fn_lock_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
bool state;
int ret;
ret = kstrtobool(buf, &state);
if (ret)
return ret;
ret = exec_sals(priv->adev->handle, state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF);
if (ret)
return ret;
return count;
}
static DEVICE_ATTR_RW(fn_lock);
static struct attribute *ideapad_attributes[] = { static struct attribute *ideapad_attributes[] = {
&dev_attr_camera_power.attr, &dev_attr_camera_power.attr,
&dev_attr_fan_mode.attr,
&dev_attr_touchpad.attr,
&dev_attr_conservation_mode.attr, &dev_attr_conservation_mode.attr,
&dev_attr_fan_mode.attr,
&dev_attr_fn_lock.attr, &dev_attr_fn_lock.attr,
&dev_attr_touchpad.attr,
NULL NULL
}; };
static umode_t ideapad_is_visible(struct kobject *kobj, static umode_t ideapad_is_visible(struct kobject *kobj,
struct attribute *attr, struct attribute *attr,
int idx) int idx)
{ {
struct device *dev = kobj_to_dev(kobj); struct device *dev = kobj_to_dev(kobj);
struct ideapad_private *priv = dev_get_drvdata(dev); struct ideapad_private *priv = dev_get_drvdata(dev);
@ -639,6 +666,7 @@ static int convert_dytc_to_profile(int dytcmode, enum platform_profile_option *p
default: /* Unknown mode */ default: /* Unknown mode */
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
} }
@ -657,6 +685,7 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe
default: /* Unknown profile */ default: /* Unknown profile */
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
return 0; return 0;
} }
@ -664,24 +693,24 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe
* dytc_profile_get: Function to register with platform_profile * dytc_profile_get: Function to register with platform_profile
* handler. Returns current platform profile. * handler. Returns current platform profile.
*/ */
int dytc_profile_get(struct platform_profile_handler *pprof, static int dytc_profile_get(struct platform_profile_handler *pprof,
enum platform_profile_option *profile) enum platform_profile_option *profile)
{ {
struct ideapad_dytc_priv *dytc; struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof);
dytc = container_of(pprof, struct ideapad_dytc_priv, pprof);
*profile = dytc->current_profile; *profile = dytc->current_profile;
return 0; return 0;
} }
/* /*
* Helper function - check if we are in CQL mode and if we are * Helper function - check if we are in CQL mode and if we are
* - disable CQL, * - disable CQL,
* - run the command * - run the command
* - enable CQL * - enable CQL
* If not in CQL mode, just run the command * If not in CQL mode, just run the command
*/ */
int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd, unsigned long *output) static int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd,
unsigned long *output)
{ {
int err, cmd_err, cur_funcmode; int err, cmd_err, cur_funcmode;
@ -717,16 +746,13 @@ int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd, unsigned l
* dytc_profile_set: Function to register with platform_profile * dytc_profile_set: Function to register with platform_profile
* handler. Sets current platform profile. * handler. Sets current platform profile.
*/ */
int dytc_profile_set(struct platform_profile_handler *pprof, static int dytc_profile_set(struct platform_profile_handler *pprof,
enum platform_profile_option profile) enum platform_profile_option profile)
{ {
struct ideapad_dytc_priv *dytc; struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof);
struct ideapad_private *priv; struct ideapad_private *priv = dytc->priv;
int err; int err;
dytc = container_of(pprof, struct ideapad_dytc_priv, pprof);
priv = dytc->priv;
err = mutex_lock_interruptible(&dytc->mutex); err = mutex_lock_interruptible(&dytc->mutex);
if (err) if (err)
return err; return err;
@ -744,16 +770,18 @@ int dytc_profile_set(struct platform_profile_handler *pprof,
goto unlock; goto unlock;
/* Determine if we are in CQL mode. This alters the commands we do */ /* Determine if we are in CQL mode. This alters the commands we do */
err = dytc_cql_command(priv, err = dytc_cql_command(priv, DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1),
DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1), NULL);
NULL);
if (err) if (err)
goto unlock; goto unlock;
} }
/* Success - update current profile */ /* Success - update current profile */
dytc->current_profile = profile; dytc->current_profile = profile;
unlock: unlock:
mutex_unlock(&dytc->mutex); mutex_unlock(&dytc->mutex);
return err; return err;
} }
@ -770,7 +798,10 @@ static void dytc_profile_refresh(struct ideapad_private *priv)
return; return;
perfmode = (output >> DYTC_GET_MODE_BIT) & 0xF; perfmode = (output >> DYTC_GET_MODE_BIT) & 0xF;
convert_dytc_to_profile(perfmode, &profile);
if (convert_dytc_to_profile(perfmode, &profile))
return;
if (profile != priv->dytc->current_profile) { if (profile != priv->dytc->current_profile) {
priv->dytc->current_profile = profile; priv->dytc->current_profile = profile;
platform_profile_notify(); platform_profile_notify();
@ -791,14 +822,14 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
return err; return err;
/* Check DYTC is enabled and supports mode setting */ /* Check DYTC is enabled and supports mode setting */
if (!(output & BIT(DYTC_QUERY_ENABLE_BIT))) if (!test_bit(DYTC_QUERY_ENABLE_BIT, &output))
return -ENODEV; return -ENODEV;
dytc_version = (output >> DYTC_QUERY_REV_BIT) & 0xF; dytc_version = (output >> DYTC_QUERY_REV_BIT) & 0xF;
if (dytc_version < 5) if (dytc_version < 5)
return -ENODEV; return -ENODEV;
priv->dytc = kzalloc(sizeof(struct ideapad_dytc_priv), GFP_KERNEL); priv->dytc = kzalloc(sizeof(*priv->dytc), GFP_KERNEL);
if (!priv->dytc) if (!priv->dytc)
return -ENOMEM; return -ENOMEM;
@ -816,17 +847,18 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
/* Create platform_profile structure and register */ /* Create platform_profile structure and register */
err = platform_profile_register(&priv->dytc->pprof); err = platform_profile_register(&priv->dytc->pprof);
if (err) if (err)
goto mutex_destroy; goto pp_reg_failed;
/* Ensure initial values are correct */ /* Ensure initial values are correct */
dytc_profile_refresh(priv); dytc_profile_refresh(priv);
return 0; return 0;
mutex_destroy: pp_reg_failed:
mutex_destroy(&priv->dytc->mutex); mutex_destroy(&priv->dytc->mutex);
kfree(priv->dytc); kfree(priv->dytc);
priv->dytc = NULL; priv->dytc = NULL;
return err; return err;
} }
@ -838,6 +870,7 @@ static void ideapad_dytc_profile_exit(struct ideapad_private *priv)
platform_profile_remove(); platform_profile_remove();
mutex_destroy(&priv->dytc->mutex); mutex_destroy(&priv->dytc->mutex);
kfree(priv->dytc); kfree(priv->dytc);
priv->dytc = NULL; priv->dytc = NULL;
} }
@ -887,16 +920,15 @@ static void ideapad_sync_rfk_state(struct ideapad_private *priv)
static int ideapad_register_rfkill(struct ideapad_private *priv, int dev) static int ideapad_register_rfkill(struct ideapad_private *priv, int dev)
{ {
int ret; unsigned long rf_enabled;
unsigned long sw_blocked; int err;
if (no_bt_rfkill && if (no_bt_rfkill && ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH) {
(ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) {
/* Force to enable bluetooth when no_bt_rfkill=1 */ /* Force to enable bluetooth when no_bt_rfkill=1 */
write_ec_cmd(priv->adev->handle, write_ec_cmd(priv->adev->handle, ideapad_rfk_data[dev].opcode, 1);
ideapad_rfk_data[dev].opcode, 1);
return 0; return 0;
} }
priv->rfk_priv[dev].dev = dev; priv->rfk_priv[dev].dev = dev;
priv->rfk_priv[dev].priv = priv; priv->rfk_priv[dev].priv = priv;
@ -908,20 +940,17 @@ static int ideapad_register_rfkill(struct ideapad_private *priv, int dev)
if (!priv->rfk[dev]) if (!priv->rfk[dev])
return -ENOMEM; return -ENOMEM;
if (read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode-1, err = read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode - 1, &rf_enabled);
&sw_blocked)) { if (err)
rfkill_init_sw_state(priv->rfk[dev], 0); rf_enabled = 1;
} else {
sw_blocked = !sw_blocked;
rfkill_init_sw_state(priv->rfk[dev], sw_blocked);
}
ret = rfkill_register(priv->rfk[dev]); rfkill_init_sw_state(priv->rfk[dev], !rf_enabled);
if (ret) {
err = rfkill_register(priv->rfk[dev]);
if (err)
rfkill_destroy(priv->rfk[dev]); rfkill_destroy(priv->rfk[dev]);
return ret;
} return err;
return 0;
} }
static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev) static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev)
@ -952,26 +981,25 @@ static void ideapad_sysfs_exit(struct ideapad_private *priv)
* input device * input device
*/ */
static const struct key_entry ideapad_keymap[] = { static const struct key_entry ideapad_keymap[] = {
{ KE_KEY, 6, { KEY_SWITCHVIDEOMODE } }, { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } },
{ KE_KEY, 7, { KEY_CAMERA } }, { KE_KEY, 7, { KEY_CAMERA } },
{ KE_KEY, 8, { KEY_MICMUTE } }, { KE_KEY, 8, { KEY_MICMUTE } },
{ KE_KEY, 11, { KEY_F16 } }, { KE_KEY, 11, { KEY_F16 } },
{ KE_KEY, 13, { KEY_WLAN } }, { KE_KEY, 13, { KEY_WLAN } },
{ KE_KEY, 16, { KEY_PROG1 } }, { KE_KEY, 16, { KEY_PROG1 } },
{ KE_KEY, 17, { KEY_PROG2 } }, { KE_KEY, 17, { KEY_PROG2 } },
{ KE_KEY, 64, { KEY_PROG3 } }, { KE_KEY, 64, { KEY_PROG3 } },
{ KE_KEY, 65, { KEY_PROG4 } }, { KE_KEY, 65, { KEY_PROG4 } },
{ KE_KEY, 66, { KEY_TOUCHPAD_OFF } }, { KE_KEY, 66, { KEY_TOUCHPAD_OFF } },
{ KE_KEY, 67, { KEY_TOUCHPAD_ON } }, { KE_KEY, 67, { KEY_TOUCHPAD_ON } },
{ KE_KEY, 128, { KEY_ESC } }, { KE_KEY, 128, { KEY_ESC } },
{ KE_END },
{ KE_END, 0 },
}; };
static int ideapad_input_init(struct ideapad_private *priv) static int ideapad_input_init(struct ideapad_private *priv)
{ {
struct input_dev *inputdev; struct input_dev *inputdev;
int error; int err;
inputdev = input_allocate_device(); inputdev = input_allocate_device();
if (!inputdev) if (!inputdev)
@ -982,26 +1010,28 @@ static int ideapad_input_init(struct ideapad_private *priv)
inputdev->id.bustype = BUS_HOST; inputdev->id.bustype = BUS_HOST;
inputdev->dev.parent = &priv->platform_device->dev; inputdev->dev.parent = &priv->platform_device->dev;
error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL); err = sparse_keymap_setup(inputdev, ideapad_keymap, NULL);
if (error) { if (err) {
dev_err(&priv->platform_device->dev, dev_err(&priv->platform_device->dev,
"Unable to setup input device keymap\n"); "Could not set up input device keymap: %d\n", err);
goto err_free_dev; goto err_free_dev;
} }
error = input_register_device(inputdev); err = input_register_device(inputdev);
if (error) { if (err) {
dev_err(&priv->platform_device->dev, dev_err(&priv->platform_device->dev,
"Unable to register input device\n"); "Could not register input device: %d\n", err);
goto err_free_dev; goto err_free_dev;
} }
priv->inputdev = inputdev; priv->inputdev = inputdev;
return 0; return 0;
err_free_dev: err_free_dev:
input_free_device(inputdev); input_free_device(inputdev);
return error;
return err;
} }
static void ideapad_input_exit(struct ideapad_private *priv) static void ideapad_input_exit(struct ideapad_private *priv)
@ -1022,6 +1052,7 @@ static void ideapad_input_novokey(struct ideapad_private *priv)
if (read_ec_data(priv->adev->handle, VPCCMD_R_NOVO, &long_pressed)) if (read_ec_data(priv->adev->handle, VPCCMD_R_NOVO, &long_pressed))
return; return;
if (long_pressed) if (long_pressed)
ideapad_input_report(priv, 17); ideapad_input_report(priv, 17);
else else
@ -1037,8 +1068,8 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv)
for_each_set_bit (bit, &value, 16) { for_each_set_bit (bit, &value, 16) {
switch (bit) { switch (bit) {
case 0: /* Z580 */
case 6: /* Z570 */ case 6: /* Z570 */
case 0: /* Z580 */
/* Thermal Management button */ /* Thermal Management button */
ideapad_input_report(priv, 65); ideapad_input_report(priv, 65);
break; break;
@ -1066,6 +1097,7 @@ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev)
err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now);
if (err) if (err)
return err; return err;
return now; return now;
} }
@ -1078,6 +1110,7 @@ static int ideapad_backlight_update_status(struct backlight_device *blightdev)
blightdev->props.brightness); blightdev->props.brightness);
if (err) if (err)
return err; return err;
err = write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER, err = write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER,
blightdev->props.power != FB_BLANK_POWERDOWN); blightdev->props.power != FB_BLANK_POWERDOWN);
if (err) if (err)
@ -1101,30 +1134,36 @@ static int ideapad_backlight_init(struct ideapad_private *priv)
err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max); err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max);
if (err) if (err)
return err; return err;
err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now);
if (err) if (err)
return err; return err;
err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power); err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power);
if (err) if (err)
return err; return err;
memset(&props, 0, sizeof(struct backlight_properties)); memset(&props, 0, sizeof(props));
props.max_brightness = max; props.max_brightness = max;
props.type = BACKLIGHT_PLATFORM; props.type = BACKLIGHT_PLATFORM;
blightdev = backlight_device_register("ideapad", blightdev = backlight_device_register("ideapad",
&priv->platform_device->dev, &priv->platform_device->dev,
priv, priv,
&ideapad_backlight_ops, &ideapad_backlight_ops,
&props); &props);
if (IS_ERR(blightdev)) { if (IS_ERR(blightdev)) {
err = PTR_ERR(blightdev);
dev_err(&priv->platform_device->dev, dev_err(&priv->platform_device->dev,
"Could not register backlight device\n"); "Could not register backlight device: %d\n", err);
return PTR_ERR(blightdev); return err;
} }
priv->blightdev = blightdev; priv->blightdev = blightdev;
blightdev->props.brightness = now; blightdev->props.brightness = now;
blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
backlight_update_status(blightdev); backlight_update_status(blightdev);
return 0; return 0;
@ -1138,13 +1177,15 @@ static void ideapad_backlight_exit(struct ideapad_private *priv)
static void ideapad_backlight_notify_power(struct ideapad_private *priv) static void ideapad_backlight_notify_power(struct ideapad_private *priv)
{ {
unsigned long power;
struct backlight_device *blightdev = priv->blightdev; struct backlight_device *blightdev = priv->blightdev;
unsigned long power;
if (!blightdev) if (!blightdev)
return; return;
if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power)) if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power))
return; return;
blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
} }
@ -1153,12 +1194,10 @@ static void ideapad_backlight_notify_brightness(struct ideapad_private *priv)
unsigned long now; unsigned long now;
/* if we control brightness via acpi video driver */ /* if we control brightness via acpi video driver */
if (priv->blightdev == NULL) { if (!priv->blightdev)
read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now);
return; else
} backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY);
backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY);
} }
/* /*
@ -1173,13 +1212,14 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv)
/* Without reading from EC touchpad LED doesn't switch state */ /* Without reading from EC touchpad LED doesn't switch state */
if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) { if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) {
/* Some IdeaPads don't really turn off touchpad - they only unsigned char param;
/*
* Some IdeaPads don't really turn off touchpad - they only
* switch the LED state. We (de)activate KBC AUX port to turn * switch the LED state. We (de)activate KBC AUX port to turn
* touchpad off and on. We send KEY_TOUCHPAD_OFF and * touchpad off and on. We send KEY_TOUCHPAD_OFF and
* KEY_TOUCHPAD_ON to not to get out of sync with LED */ * KEY_TOUCHPAD_ON to not to get out of sync with LED
unsigned char param; */
i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
I8042_CMD_AUX_DISABLE);
ideapad_input_report(priv, value ? 67 : 66); ideapad_input_report(priv, value ? 67 : 66);
} }
} }
@ -1191,6 +1231,7 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1)) if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1))
return; return;
if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2)) if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2))
return; return;
@ -1198,9 +1239,6 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
for_each_set_bit (bit, &vpc1, 16) { for_each_set_bit (bit, &vpc1, 16) {
switch (bit) { switch (bit) {
case 9:
ideapad_sync_rfk_state(priv);
break;
case 13: case 13:
case 11: case 11:
case 8: case 8:
@ -1208,6 +1246,9 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
case 6: case 6:
ideapad_input_report(priv, bit); ideapad_input_report(priv, bit);
break; break;
case 9:
ideapad_sync_rfk_state(priv);
break;
case 5: case 5:
ideapad_sync_touchpad_state(priv); ideapad_sync_touchpad_state(priv);
break; break;
@ -1220,16 +1261,17 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
case 2: case 2:
ideapad_backlight_notify_power(priv); ideapad_backlight_notify_power(priv);
break; break;
case 0:
ideapad_check_special_buttons(priv);
break;
case 1: case 1:
/* Some IdeaPads report event 1 every ~20 /*
* Some IdeaPads report event 1 every ~20
* seconds while on battery power; some * seconds while on battery power; some
* report this when changing to/from tablet * report this when changing to/from tablet
* mode. Squelch this event. * mode. Squelch this event.
*/ */
break; break;
case 0:
ideapad_check_special_buttons(priv);
break;
default: default:
dev_info(&priv->platform_device->dev, dev_info(&priv->platform_device->dev,
"Unknown event: %lu\n", bit); "Unknown event: %lu\n", bit);
@ -1301,14 +1343,14 @@ static void ideapad_check_features(struct ideapad_private *priv)
static int ideapad_acpi_add(struct platform_device *pdev) static int ideapad_acpi_add(struct platform_device *pdev)
{ {
int ret, i;
struct ideapad_private *priv; struct ideapad_private *priv;
struct acpi_device *adev; struct acpi_device *adev;
acpi_status status; acpi_status status;
unsigned long cfg; unsigned long cfg;
int err, i;
ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); err = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
if (ret) if (err)
return -ENODEV; return -ENODEV;
if (eval_int(adev->handle, "_CFG", &cfg)) if (eval_int(adev->handle, "_CFG", &cfg))
@ -1319,20 +1361,21 @@ static int ideapad_acpi_add(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
dev_set_drvdata(&pdev->dev, priv); dev_set_drvdata(&pdev->dev, priv);
priv->cfg = cfg; priv->cfg = cfg;
priv->adev = adev; priv->adev = adev;
priv->platform_device = pdev; priv->platform_device = pdev;
ideapad_check_features(priv); ideapad_check_features(priv);
ret = ideapad_sysfs_init(priv); err = ideapad_sysfs_init(priv);
if (ret) if (err)
return ret; return err;
ideapad_debugfs_init(priv); ideapad_debugfs_init(priv);
ret = ideapad_input_init(priv); err = ideapad_input_init(priv);
if (ret) if (err)
goto input_failed; goto input_failed;
/* /*
@ -1353,24 +1396,25 @@ static int ideapad_acpi_add(struct platform_device *pdev)
ideapad_sync_rfk_state(priv); ideapad_sync_rfk_state(priv);
ideapad_sync_touchpad_state(priv); ideapad_sync_touchpad_state(priv);
ret = ideapad_dytc_profile_init(priv); err = ideapad_dytc_profile_init(priv);
if (ret) { if (err) {
if (ret != -ENODEV) if (err != -ENODEV)
dev_warn(&pdev->dev, "Could not set up DYTC interface: %d\n", ret); dev_warn(&pdev->dev, "Could not set up DYTC interface: %d\n", err);
else else
dev_info(&pdev->dev, "DYTC interface is not available\n"); dev_info(&pdev->dev, "DYTC interface is not available\n");
} }
if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
ret = ideapad_backlight_init(priv); err = ideapad_backlight_init(priv);
if (ret && ret != -ENODEV) if (err && err != -ENODEV)
goto backlight_failed; goto backlight_failed;
} }
status = acpi_install_notify_handler(adev->handle, status = acpi_install_notify_handler(adev->handle,
ACPI_DEVICE_NOTIFY, ACPI_DEVICE_NOTIFY,
ideapad_acpi_notify, priv); ideapad_acpi_notify, priv);
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
ret = -EIO; err = -EIO;
goto notification_failed; goto notification_failed;
} }
@ -1383,29 +1427,38 @@ static int ideapad_acpi_add(struct platform_device *pdev)
break; break;
} }
} }
if (ACPI_FAILURE(status) && status != AE_NOT_EXIST) { if (ACPI_FAILURE(status) && status != AE_NOT_EXIST) {
ret = -EIO; err = -EIO;
goto notification_failed_wmi; goto notification_failed_wmi;
} }
#endif #endif
return 0; return 0;
#if IS_ENABLED(CONFIG_ACPI_WMI) #if IS_ENABLED(CONFIG_ACPI_WMI)
notification_failed_wmi: notification_failed_wmi:
acpi_remove_notify_handler(priv->adev->handle, acpi_remove_notify_handler(priv->adev->handle,
ACPI_DEVICE_NOTIFY, ideapad_acpi_notify); ACPI_DEVICE_NOTIFY,
ideapad_acpi_notify);
#endif #endif
notification_failed: notification_failed:
ideapad_backlight_exit(priv); ideapad_backlight_exit(priv);
backlight_failed: backlight_failed:
ideapad_dytc_profile_exit(priv); ideapad_dytc_profile_exit(priv);
for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
ideapad_unregister_rfkill(priv, i); ideapad_unregister_rfkill(priv, i);
ideapad_input_exit(priv); ideapad_input_exit(priv);
input_failed: input_failed:
ideapad_debugfs_exit(priv); ideapad_debugfs_exit(priv);
ideapad_sysfs_exit(priv); ideapad_sysfs_exit(priv);
return ret;
return err;
} }
static int ideapad_acpi_remove(struct platform_device *pdev) static int ideapad_acpi_remove(struct platform_device *pdev)
@ -1417,12 +1470,17 @@ static int ideapad_acpi_remove(struct platform_device *pdev)
if (priv->fnesc_guid) if (priv->fnesc_guid)
wmi_remove_notify_handler(priv->fnesc_guid); wmi_remove_notify_handler(priv->fnesc_guid);
#endif #endif
acpi_remove_notify_handler(priv->adev->handle, acpi_remove_notify_handler(priv->adev->handle,
ACPI_DEVICE_NOTIFY, ideapad_acpi_notify); ACPI_DEVICE_NOTIFY,
ideapad_acpi_notify);
ideapad_backlight_exit(priv); ideapad_backlight_exit(priv);
ideapad_dytc_profile_exit(priv); ideapad_dytc_profile_exit(priv);
for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
ideapad_unregister_rfkill(priv, i); ideapad_unregister_rfkill(priv, i);
ideapad_input_exit(priv); ideapad_input_exit(priv);
ideapad_debugfs_exit(priv); ideapad_debugfs_exit(priv);
ideapad_sysfs_exit(priv); ideapad_sysfs_exit(priv);
@ -1447,8 +1505,8 @@ static int ideapad_acpi_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume); static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume);
static const struct acpi_device_id ideapad_device_ids[] = { static const struct acpi_device_id ideapad_device_ids[] = {
{ "VPC2004", 0}, {"VPC2004", 0},
{ "", 0}, {"", 0},
}; };
MODULE_DEVICE_TABLE(acpi, ideapad_device_ids); MODULE_DEVICE_TABLE(acpi, ideapad_device_ids);