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>
This commit is contained in:
committed by
Len Brown
parent
83f3472464
commit
c9bea99c1a
@@ -273,6 +273,17 @@ static int _sta(acpi_handle handle)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int issue_thinkpad_cmos_command(int cmos_cmd)
|
||||||
|
{
|
||||||
|
if (!cmos_handle)
|
||||||
|
return -ENXIO;
|
||||||
|
|
||||||
|
if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
|
||||||
|
return -EIO;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* ACPI device model
|
* ACPI device model
|
||||||
*/
|
*/
|
||||||
@@ -1550,14 +1561,6 @@ static int __init cmos_init(struct ibm_init_struct *iibm)
|
|||||||
return (cmos_handle)? 0 : 1;
|
return (cmos_handle)? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmos_eval(int cmos_cmd)
|
|
||||||
{
|
|
||||||
if (cmos_handle)
|
|
||||||
return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd);
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cmos_read(char *p)
|
static int cmos_read(char *p)
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@@ -1577,10 +1580,7 @@ static int cmos_read(char *p)
|
|||||||
static int cmos_write(char *buf)
|
static int cmos_write(char *buf)
|
||||||
{
|
{
|
||||||
char *cmd;
|
char *cmd;
|
||||||
int cmos_cmd;
|
int cmos_cmd, res;
|
||||||
|
|
||||||
if (!cmos_handle)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
while ((cmd = next_cmd(&buf))) {
|
while ((cmd = next_cmd(&buf))) {
|
||||||
if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
|
if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
|
||||||
@@ -1589,8 +1589,9 @@ static int cmos_write(char *buf)
|
|||||||
} else
|
} else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (!cmos_eval(cmos_cmd))
|
res = issue_thinkpad_cmos_command(cmos_cmd);
|
||||||
return -EIO;
|
if (res)
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2093,7 +2094,7 @@ static int brightness_set(int value)
|
|||||||
cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
|
cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
|
||||||
inc = value > current_value ? 1 : -1;
|
inc = value > current_value ? 1 : -1;
|
||||||
for (i = current_value; i != value; i += inc) {
|
for (i = current_value; i != value; i += inc) {
|
||||||
if (!cmos_eval(cmos_cmd))
|
if (issue_thinkpad_cmos_command(cmos_cmd))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
if (!acpi_ec_write(brightness_offset, i + inc))
|
if (!acpi_ec_write(brightness_offset, i + inc))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
@@ -2210,16 +2211,16 @@ static int volume_write(char *buf)
|
|||||||
cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
|
cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
|
||||||
inc = new_level > level ? 1 : -1;
|
inc = new_level > level ? 1 : -1;
|
||||||
|
|
||||||
if (mute && (!cmos_eval(cmos_cmd) ||
|
if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
|
||||||
!acpi_ec_write(volume_offset, level)))
|
!acpi_ec_write(volume_offset, level)))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
for (i = level; i != new_level; i += inc)
|
for (i = level; i != new_level; i += inc)
|
||||||
if (!cmos_eval(cmos_cmd) ||
|
if (issue_thinkpad_cmos_command(cmos_cmd) ||
|
||||||
!acpi_ec_write(volume_offset, i + inc))
|
!acpi_ec_write(volume_offset, i + inc))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
if (mute && (!cmos_eval(TP_CMOS_VOLUME_MUTE) ||
|
if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
|
||||||
!acpi_ec_write(volume_offset,
|
!acpi_ec_write(volume_offset,
|
||||||
new_level + mute)))
|
new_level + mute)))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
@@ -2228,7 +2229,7 @@ static int volume_write(char *buf)
|
|||||||
if (new_mute != mute) { /* level doesn't change */
|
if (new_mute != mute) { /* level doesn't change */
|
||||||
cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
|
cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
|
||||||
|
|
||||||
if (!cmos_eval(cmos_cmd) ||
|
if (issue_thinkpad_cmos_command(cmos_cmd) ||
|
||||||
!acpi_ec_write(volume_offset, level + new_mute))
|
!acpi_ec_write(volume_offset, level + new_mute))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@@ -116,6 +116,9 @@ static void drv_acpi_handle_init(char *name,
|
|||||||
drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
|
drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
|
||||||
object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
|
object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
|
||||||
|
|
||||||
|
/* ThinkPad ACPI helpers */
|
||||||
|
static int issue_thinkpad_cmos_command(int cmos_cmd);
|
||||||
|
|
||||||
/* procfs support */
|
/* procfs support */
|
||||||
static struct proc_dir_entry *proc_dir;
|
static struct proc_dir_entry *proc_dir;
|
||||||
|
|
||||||
@@ -275,7 +278,6 @@ static int brightness_write(char *buf);
|
|||||||
* CMOS subdriver
|
* CMOS subdriver
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int cmos_eval(int cmos_cmd);
|
|
||||||
static int cmos_read(char *p);
|
static int cmos_read(char *p);
|
||||||
static int cmos_write(char *buf);
|
static int cmos_write(char *buf);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user