1 From 18ad7996e17649d81c15a2c9dae03c75050a05a8 Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Fri, 24 Nov 2006 11:47:11 -0200
4 Subject: [PATCH 11/28] ACPI: ibm-acpi: cleanup fan_write
6 This patch cleans up fan_write so that it is much easier to read and
7 extend. It separates the proc api handling from the operations themselves.
9 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
11 drivers/acpi/ibm_acpi.c | 147 ++++++++++++++++++++++++++++++++++++++++-------
12 1 files changed, 125 insertions(+), 22 deletions(-)
14 diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
15 index 9275dfc..187af1b 100644
16 --- a/drivers/acpi/ibm_acpi.c
17 +++ b/drivers/acpi/ibm_acpi.c
18 @@ -1843,40 +1843,143 @@ static int fan_read(char *p)
22 -static int fan_write(char *buf)
23 +static int fan_set_level(int level)
28 - while ((cmd = next_cmd(&buf))) {
30 - sscanf(cmd, "level %d", &level) == 1 &&
31 - level >= 0 && level <= 7) {
33 + switch (fan_control_access_mode) {
34 + case IBMACPI_FAN_WR_ACPI_SFAN:
35 + if (level >= 0 && level <= 7) {
36 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
38 - } else if (!gfan_handle && strlencmp(cmd, "enable") == 0) {
39 - /* all except 570, 600e/x, 770e, 770x */
40 - if (!acpi_ec_write(fan_status_offset, 0x80))
42 - } else if (!gfan_handle && strlencmp(cmd, "disable") == 0) {
43 - /* all except 570, 600e/x, 770e, 770x */
44 - if (!acpi_ec_write(fan_status_offset, 0x00))
46 - } else if (fans_handle &&
47 - sscanf(cmd, "speed %d", &speed) == 1 &&
48 - speed >= 0 && speed <= 65535) {
60 +static int fan_set_enable(void)
62 + switch (fan_control_access_mode) {
63 + case IBMACPI_FAN_WR_ACPI_FANS:
64 + case IBMACPI_FAN_WR_TPEC:
65 + if (!acpi_ec_write(fan_status_offset, 0x80))
75 +static int fan_set_disable(void)
77 + switch (fan_control_access_mode) {
78 + case IBMACPI_FAN_WR_ACPI_FANS:
79 + case IBMACPI_FAN_WR_TPEC:
80 + if (!acpi_ec_write(fan_status_offset, 0x00))
90 +static int fan_set_speed(int speed)
92 + switch (fan_control_access_mode) {
93 + case IBMACPI_FAN_WR_ACPI_FANS:
94 + if (speed >= 0 && speed <= 65535) {
95 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
109 +static int fan_write_cmd_level(const char *cmd, int *rc)
113 + if (sscanf(cmd, "level %d", &level) != 1)
116 + if ((*rc = fan_set_level(level)) == -ENXIO)
117 + printk(IBM_ERR "level command accepted for unsupported "
118 + "access mode %d", fan_control_access_mode);
123 +static int fan_write_cmd_enable(const char *cmd, int *rc)
125 + if (strlencmp(cmd, "enable") != 0)
128 + if ((*rc = fan_set_enable()) == -ENXIO)
129 + printk(IBM_ERR "enable command accepted for unsupported "
130 + "access mode %d", fan_control_access_mode);
135 +static int fan_write_cmd_disable(const char *cmd, int *rc)
137 + if (strlencmp(cmd, "disable") != 0)
140 + if ((*rc = fan_set_disable()) == -ENXIO)
141 + printk(IBM_ERR "disable command accepted for unsupported "
142 + "access mode %d", fan_control_access_mode);
147 +static int fan_write_cmd_speed(const char *cmd, int *rc)
151 + if (sscanf(cmd, "speed %d", &speed) != 1)
154 + if ((*rc = fan_set_speed(speed)) == -ENXIO)
155 + printk(IBM_ERR "speed command accepted for unsupported "
156 + "access mode %d", fan_control_access_mode);
161 +static int fan_write(char *buf)
166 + while (!rc && (cmd = next_cmd(&buf))) {
167 + if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) &&
168 + fan_write_cmd_level(cmd, &rc)) &&
169 + !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) &&
170 + (fan_write_cmd_enable(cmd, &rc) ||
171 + fan_write_cmd_disable(cmd, &rc))) &&
172 + !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) &&
173 + fan_write_cmd_speed(cmd, &rc))
181 static struct ibm_struct ibms[] = {