@@ -119,41 +119,47 @@ MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
*/
#define IDEAPAD_EC_TIMEOUT (200) /* in ms */
-static int read_method_int(acpi_handle handle, const char *method, int *val)
+static int eval_int(acpi_handle handle, const char *method, unsigned long *val)
{
- acpi_status status;
+ acpi_status acpi_err;
unsigned long long result;
- status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
- if (ACPI_FAILURE(status)) {
- *val = -1;
+ acpi_err = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
+ if (ACPI_FAILURE(acpi_err))
return -EIO;
- }
*val = result;
return 0;
+}
+static int eval_simple_method(acpi_handle handle, char *method, u64 arg)
+{
+ acpi_status acpi_err = acpi_execute_simple_method(handle, method, arg);
+ return ACPI_FAILURE(acpi_err) ? -EIO : 0;
}
-static int method_gbmd(acpi_handle handle, unsigned long *ret)
+static int eval_gbmd(acpi_handle handle, unsigned long *val)
{
- int result, val;
+ return eval_int(handle, "GBMD", val);
+}
- result = read_method_int(handle, "GBMD", &val);
- *ret = val;
- return result;
+static int eval_smbc(acpi_handle handle, unsigned long arg)
+{
+ return eval_simple_method(handle, "SMBC", arg);
}
-static int method_int1(acpi_handle handle, char *method, int cmd)
+static int eval_hals(acpi_handle handle, unsigned long *val)
{
- acpi_status status;
+ return eval_int(handle, "HALS", val);
+}
- status = acpi_execute_simple_method(handle, method, cmd);
- return ACPI_FAILURE(status) ? -EIO : 0;
+static int eval_sals(acpi_handle handle, unsigned long arg)
+{
+ return eval_simple_method(handle, "SALS", arg);
}
-static int method_vpcr(acpi_handle handle, int cmd, int *ret)
+static int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *val)
{
- acpi_status status;
+ acpi_status acpi_err;
unsigned long long result;
struct acpi_object_list params;
union acpi_object in_obj;
@@ -163,22 +169,20 @@ static int method_vpcr(acpi_handle handle, int cmd, int *ret)
in_obj.type = ACPI_TYPE_INTEGER;
in_obj.integer.value = cmd;
- status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result);
+ acpi_err = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result);
- if (ACPI_FAILURE(status)) {
- *ret = -1;
+ if (ACPI_FAILURE(acpi_err))
return -EIO;
- }
- *ret = result;
+ *val = result;
return 0;
}
-static int method_vpcw(acpi_handle handle, int cmd, int data)
+static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data)
{
struct acpi_object_list params;
union acpi_object in_obj[2];
- acpi_status status;
+ acpi_status acpi_err;
params.count = 2;
params.pointer = in_obj;
@@ -187,55 +191,50 @@ static int method_vpcw(acpi_handle handle, int cmd, int data)
in_obj[1].type = ACPI_TYPE_INTEGER;
in_obj[1].integer.value = data;
- status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL);
- if (status != AE_OK)
+ acpi_err = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL);
+ if (ACPI_FAILURE(acpi_err))
return -EIO;
return 0;
}
-static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data)
+static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data)
{
- int val, err;
- unsigned long int end_jiffies;
+ int err;
+ unsigned long int end_jiffies, val;
- err = method_vpcw(handle, 1, cmd);
+ err = eval_vpcw(handle, 1, cmd);
if (err)
return err;
for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
time_before(jiffies, end_jiffies);) {
schedule();
- err = method_vpcr(handle, 1, &val);
+ err = eval_vpcr(handle, 1, &val);
if (err)
return err;
- if (val == 0) {
- err = method_vpcr(handle, 0, &val);
- if (err)
- return err;
- *data = val;
- return 0;
- }
+ if (val == 0)
+ return eval_vpcr(handle, 0, data);
}
acpi_handle_err(handle, "timeout in %s\n", __func__);
return -ETIMEDOUT;
}
-static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data)
+static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data)
{
- int val, err;
- unsigned long int end_jiffies;
+ int err;
+ unsigned long end_jiffies, val;
- err = method_vpcw(handle, 0, data);
+ err = eval_vpcw(handle, 0, data);
if (err)
return err;
- err = method_vpcw(handle, 1, cmd);
+ err = eval_vpcw(handle, 1, cmd);
if (err)
return err;
for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
time_before(jiffies, end_jiffies);) {
schedule();
- err = method_vpcr(handle, 1, &val);
+ err = eval_vpcr(handle, 1, &val);
if (err)
return err;
if (val == 0)
@@ -286,7 +285,7 @@ static int debugfs_status_show(struct seq_file *s, void *data)
value ? "On" : "Off", value);
seq_puts(s, "=====================\n");
- if (!method_gbmd(priv->adev->handle, &value)) {
+ if (!eval_gbmd(priv->adev->handle, &value)) {
seq_printf(s, "Conservation mode:\t%s(%lu)\n",
test_bit(GBMD_CONSERVATION_STATE_BIT, &value) ? "On" : "Off",
value);
@@ -468,7 +467,7 @@ static ssize_t conservation_mode_show(struct device *dev,
unsigned long result;
int err;
- err = method_gbmd(priv->adev->handle, &result);
+ err = eval_gbmd(priv->adev->handle, &result);
if (err)
return err;
return sysfs_emit(buf, "%u\n", test_bit(GBMD_CONSERVATION_STATE_BIT, &result));
@@ -486,9 +485,8 @@ static ssize_t conservation_mode_store(struct device *dev,
if (ret)
return ret;
- ret = method_int1(priv->adev->handle, "SBMC", state ?
- SMBC_CONSERVATION_ON :
- SMBC_CONSERVATION_OFF);
+ ret = eval_smbc(priv->adev->handle,
+ state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF);
if (ret)
return ret;
return count;
@@ -501,15 +499,13 @@ static ssize_t fn_lock_show(struct device *dev,
char *buf)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
- unsigned long result;
- int hals;
- int fail = read_method_int(priv->adev->handle, "HALS", &hals);
+ unsigned long hals;
+ int fail = eval_hals(priv->adev->handle, &hals);
if (fail)
return fail;
- result = hals;
- return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &result));
+ return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &hals));
}
static ssize_t fn_lock_store(struct device *dev,
@@ -524,9 +520,8 @@ static ssize_t fn_lock_store(struct device *dev,
if (ret)
return ret;
- ret = method_int1(priv->adev->handle, "SALS", state ?
- SALS_FNLOCK_ON :
- SALS_FNLOCK_OFF);
+ ret = eval_sals(priv->adev->handle,
+ state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF);
if (ret)
return ret;
return count;
@@ -1016,7 +1011,7 @@ static const struct dmi_system_id hw_rfkill_list[] = {
static int ideapad_acpi_add(struct platform_device *pdev)
{
int ret, i;
- int cfg;
+ unsigned long cfg;
struct ideapad_private *priv;
struct acpi_device *adev;
acpi_status acpi_err;
@@ -1025,7 +1020,7 @@ static int ideapad_acpi_add(struct platform_device *pdev)
if (ret)
return -ENODEV;
- if (read_method_int(adev->handle, "_CFG", &cfg))
+ if (eval_int(adev->handle, "_CFG", &cfg))
return -ENODEV;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);