diff options
author | Henrique de Moraes Holschuh <hmh@hmh.eng.br> | 2007-04-21 10:08:42 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2007-04-21 23:30:34 -0400 |
commit | c9bea99c1a712548db3437cbca52b0da8f30069c (patch) | |
tree | 8d88d7787dc93e569e1c098c9c269955953e1fbf /drivers/misc/thinkpad_acpi.c | |
parent | 83f34724643a3b0ec9322490b9ad9f1b60170a6c (diff) |
ACPI: thinkpad-acpi: clean up CMOS commands subdriver
Some ThinkPad CMOS commands subdriver cleanups, and also rename/promote
cmos_eval to a ACPI helper function, as it is used by many other
subdrivers.
Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/misc/thinkpad_acpi.c')
-rw-r--r-- | drivers/misc/thinkpad_acpi.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 19c14bbe8b29..8829d3c6b444 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c | |||
@@ -273,6 +273,17 @@ static int _sta(acpi_handle handle) | |||
273 | return status; | 273 | return status; |
274 | } | 274 | } |
275 | 275 | ||
276 | static int issue_thinkpad_cmos_command(int cmos_cmd) | ||
277 | { | ||
278 | if (!cmos_handle) | ||
279 | return -ENXIO; | ||
280 | |||
281 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) | ||
282 | return -EIO; | ||
283 | |||
284 | return 0; | ||
285 | } | ||
286 | |||
276 | /************************************************************************* | 287 | /************************************************************************* |
277 | * ACPI device model | 288 | * ACPI device model |
278 | */ | 289 | */ |
@@ -1550,14 +1561,6 @@ static int __init cmos_init(struct ibm_init_struct *iibm) | |||
1550 | return (cmos_handle)? 0 : 1; | 1561 | return (cmos_handle)? 0 : 1; |
1551 | } | 1562 | } |
1552 | 1563 | ||
1553 | static int cmos_eval(int cmos_cmd) | ||
1554 | { | ||
1555 | if (cmos_handle) | ||
1556 | return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd); | ||
1557 | else | ||
1558 | return 1; | ||
1559 | } | ||
1560 | |||
1561 | static int cmos_read(char *p) | 1564 | static int cmos_read(char *p) |
1562 | { | 1565 | { |
1563 | int len = 0; | 1566 | int len = 0; |
@@ -1577,10 +1580,7 @@ static int cmos_read(char *p) | |||
1577 | static int cmos_write(char *buf) | 1580 | static int cmos_write(char *buf) |
1578 | { | 1581 | { |
1579 | char *cmd; | 1582 | char *cmd; |
1580 | int cmos_cmd; | 1583 | int cmos_cmd, res; |
1581 | |||
1582 | if (!cmos_handle) | ||
1583 | return -EINVAL; | ||
1584 | 1584 | ||
1585 | while ((cmd = next_cmd(&buf))) { | 1585 | while ((cmd = next_cmd(&buf))) { |
1586 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && | 1586 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
@@ -1589,8 +1589,9 @@ static int cmos_write(char *buf) | |||
1589 | } else | 1589 | } else |
1590 | return -EINVAL; | 1590 | return -EINVAL; |
1591 | 1591 | ||
1592 | if (!cmos_eval(cmos_cmd)) | 1592 | res = issue_thinkpad_cmos_command(cmos_cmd); |
1593 | return -EIO; | 1593 | if (res) |
1594 | return res; | ||
1594 | } | 1595 | } |
1595 | 1596 | ||
1596 | return 0; | 1597 | return 0; |
@@ -2093,7 +2094,7 @@ static int brightness_set(int value) | |||
2093 | cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN; | 2094 | cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN; |
2094 | inc = value > current_value ? 1 : -1; | 2095 | inc = value > current_value ? 1 : -1; |
2095 | for (i = current_value; i != value; i += inc) { | 2096 | for (i = current_value; i != value; i += inc) { |
2096 | if (!cmos_eval(cmos_cmd)) | 2097 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
2097 | return -EIO; | 2098 | return -EIO; |
2098 | if (!acpi_ec_write(brightness_offset, i + inc)) | 2099 | if (!acpi_ec_write(brightness_offset, i + inc)) |
2099 | return -EIO; | 2100 | return -EIO; |
@@ -2210,16 +2211,16 @@ static int volume_write(char *buf) | |||
2210 | cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; | 2211 | cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
2211 | inc = new_level > level ? 1 : -1; | 2212 | inc = new_level > level ? 1 : -1; |
2212 | 2213 | ||
2213 | if (mute && (!cmos_eval(cmos_cmd) || | 2214 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
2214 | !acpi_ec_write(volume_offset, level))) | 2215 | !acpi_ec_write(volume_offset, level))) |
2215 | return -EIO; | 2216 | return -EIO; |
2216 | 2217 | ||
2217 | for (i = level; i != new_level; i += inc) | 2218 | for (i = level; i != new_level; i += inc) |
2218 | if (!cmos_eval(cmos_cmd) || | 2219 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
2219 | !acpi_ec_write(volume_offset, i + inc)) | 2220 | !acpi_ec_write(volume_offset, i + inc)) |
2220 | return -EIO; | 2221 | return -EIO; |
2221 | 2222 | ||
2222 | if (mute && (!cmos_eval(TP_CMOS_VOLUME_MUTE) || | 2223 | if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
2223 | !acpi_ec_write(volume_offset, | 2224 | !acpi_ec_write(volume_offset, |
2224 | new_level + mute))) | 2225 | new_level + mute))) |
2225 | return -EIO; | 2226 | return -EIO; |
@@ -2228,7 +2229,7 @@ static int volume_write(char *buf) | |||
2228 | if (new_mute != mute) { /* level doesn't change */ | 2229 | if (new_mute != mute) { /* level doesn't change */ |
2229 | cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; | 2230 | cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
2230 | 2231 | ||
2231 | if (!cmos_eval(cmos_cmd) || | 2232 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
2232 | !acpi_ec_write(volume_offset, level + new_mute)) | 2233 | !acpi_ec_write(volume_offset, level + new_mute)) |
2233 | return -EIO; | 2234 | return -EIO; |
2234 | } | 2235 | } |