提交 3e07e5ba 编写于 作者: A Azael Avalos 提交者: Darren Hart

toshiba_acpi: Add set_fan_status function

This patch adds a new function named "set_fan_status" to complement
its get* counterpart, as well as to avoid code duplication between
"fan_proc_write" and "fan_store".

Also, both functions (get*, set*) are now checking for TOS_FAILURE,
TOS_NOT_SUPPORTED and TOS_SUCCESS (to be on par with the rest of the
HCI/SCI functions), printing an error message, returning -ENODEV and
zero respectively.

The proc and sysfs functions were updated to reflect these changes as
well, returning -EIO for proc, and propagating the error value on the
sysfs functions.
Signed-off-by: NAzael Avalos <coproscefalo@gmail.com>
Signed-off-by: NDarren Hart <dvhart@linux.intel.com>
上级 1e574dbf
...@@ -1422,27 +1422,47 @@ static const struct file_operations video_proc_fops = { ...@@ -1422,27 +1422,47 @@ static const struct file_operations video_proc_fops = {
.write = video_proc_write, .write = video_proc_write,
}; };
/* Fan status */
static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
{ {
u32 hci_result; u32 result = hci_read(dev, HCI_FAN, status);
hci_result = hci_read(dev, HCI_FAN, status); if (result == TOS_FAILURE)
return hci_result == TOS_SUCCESS ? 0 : -EIO; pr_err("ACPI call to get Fan status failed\n");
else if (result == TOS_NOT_SUPPORTED)
return -ENODEV;
else if (result == TOS_SUCCESS)
return 0;
return -EIO;
}
static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
{
u32 result = hci_write(dev, HCI_FAN, status);
if (result == TOS_FAILURE)
pr_err("ACPI call to set Fan status failed\n");
else if (result == TOS_NOT_SUPPORTED)
return -ENODEV;
else if (result == TOS_SUCCESS)
return 0;
return -EIO;
} }
static int fan_proc_show(struct seq_file *m, void *v) static int fan_proc_show(struct seq_file *m, void *v)
{ {
struct toshiba_acpi_dev *dev = m->private; struct toshiba_acpi_dev *dev = m->private;
int ret;
u32 value; u32 value;
ret = get_fan_status(dev, &value); if (get_fan_status(dev, &value))
if (!ret) { return -EIO;
seq_printf(m, "running: %d\n", (value > 0));
seq_printf(m, "force_on: %d\n", dev->force_fan);
}
return ret; seq_printf(m, "running: %d\n", (value > 0));
seq_printf(m, "force_on: %d\n", dev->force_fan);
return 0;
} }
static int fan_proc_open(struct inode *inode, struct file *file) static int fan_proc_open(struct inode *inode, struct file *file)
...@@ -1457,23 +1477,20 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf, ...@@ -1457,23 +1477,20 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf,
char cmd[42]; char cmd[42];
size_t len; size_t len;
int value; int value;
u32 hci_result;
len = min(count, sizeof(cmd) - 1); len = min(count, sizeof(cmd) - 1);
if (copy_from_user(cmd, buf, len)) if (copy_from_user(cmd, buf, len))
return -EFAULT; return -EFAULT;
cmd[len] = '\0'; cmd[len] = '\0';
if (sscanf(cmd, " force_on : %i", &value) == 1 && if (sscanf(cmd, " force_on : %i", &value) != 1 &&
value >= 0 && value <= 1) { value != 0 && value != 1)
hci_result = hci_write(dev, HCI_FAN, value);
if (hci_result == TOS_SUCCESS)
dev->force_fan = value;
else
return -EIO;
} else {
return -EINVAL; return -EINVAL;
}
if (set_fan_status(dev, value))
return -EIO;
dev->force_fan = value;
return count; return count;
} }
...@@ -1610,7 +1627,6 @@ static ssize_t fan_store(struct device *dev, ...@@ -1610,7 +1627,6 @@ static ssize_t fan_store(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
u32 result;
int state; int state;
int ret; int ret;
...@@ -1621,11 +1637,9 @@ static ssize_t fan_store(struct device *dev, ...@@ -1621,11 +1637,9 @@ static ssize_t fan_store(struct device *dev,
if (state != 0 && state != 1) if (state != 0 && state != 1)
return -EINVAL; return -EINVAL;
result = hci_write(toshiba, HCI_FAN, state); ret = set_fan_status(toshiba, state);
if (result == TOS_FAILURE) if (ret)
return -EIO; return ret;
else if (result == TOS_NOT_SUPPORTED)
return -ENODEV;
return count; return count;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册