diff options
-rw-r--r-- | drivers/misc/thinkpad_acpi.c | 39 | ||||
-rw-r--r-- | drivers/misc/thinkpad_acpi.h | 4 |
2 files changed, 23 insertions, 20 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 | } |
diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h index 3a8718a08116..fb0abb02a016 100644 --- a/drivers/misc/thinkpad_acpi.h +++ b/drivers/misc/thinkpad_acpi.h | |||
@@ -116,6 +116,9 @@ static void drv_acpi_handle_init(char *name, | |||
116 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ | 116 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
117 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) | 117 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
118 | 118 | ||
119 | /* ThinkPad ACPI helpers */ | ||
120 | static int issue_thinkpad_cmos_command(int cmos_cmd); | ||
121 | |||
119 | /* procfs support */ | 122 | /* procfs support */ |
120 | static struct proc_dir_entry *proc_dir; | 123 | static struct proc_dir_entry *proc_dir; |
121 | 124 | ||
@@ -275,7 +278,6 @@ static int brightness_write(char *buf); | |||
275 | * CMOS subdriver | 278 | * CMOS subdriver |
276 | */ | 279 | */ |
277 | 280 | ||
278 | static int cmos_eval(int cmos_cmd); | ||
279 | static int cmos_read(char *p); | 281 | static int cmos_read(char *p); |
280 | static int cmos_write(char *buf); | 282 | static int cmos_write(char *buf); |
281 | 283 | ||