Skip to content

Commit

Permalink
ACPI: thinkpad-acpi: add sysfs support to the cmos command subdriver
Browse files Browse the repository at this point in the history
Add sysfs attributes to send ThinkPad CMOS commands.

Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Signed-off-by: Len Brown <len.brown@intel.com>
  • Loading branch information
Henrique de Moraes Holschuh authored and Len Brown committed Apr 25, 2007
1 parent eaa7571 commit b616004
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Documentation/thinkpad-acpi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -378,23 +378,19 @@ supported. Use "eject2" instead of "eject" for the second bay.
Note: the UltraBay eject support on the 600e/x, A22p and A3x is
EXPERIMENTAL and may not work as expected. USE WITH CAUTION!

CMOS control -- /proc/acpi/ibm/cmos
-----------------------------------
CMOS control
------------

procfs: /proc/acpi/ibm/cmos
sysfs device attribute: cmos_command

This feature is used internally by the ACPI firmware to control the
ThinkLight on most newer ThinkPad models. It may also control LCD
brightness, sounds volume and more, but only on some models.

The commands are non-negative integer numbers:

echo 0 >/proc/acpi/ibm/cmos
echo 1 >/proc/acpi/ibm/cmos
echo 2 >/proc/acpi/ibm/cmos
...

The range of valid numbers is 0 to 21, but not all have an effect and
the behavior varies from model to model. Here is the behavior on the
X40 (tpb is the ThinkPad Buttons utility):
The range of valid cmos command numbers is 0 to 21, but not all have an
effect and the behavior varies from model to model. Here is the behavior
on the X40 (tpb is the ThinkPad Buttons utility):

0 - no effect but tpb reports "Volume down"
1 - no effect but tpb reports "Volume up"
Expand All @@ -407,6 +403,9 @@ X40 (tpb is the ThinkPad Buttons utility):
13 - ThinkLight off
14 - no effect but tpb reports ThinkLight status change

The cmos command interface is prone to firmware split-brain problems, as
in newer ThinkPads it is just a compatibility layer.

LED control -- /proc/acpi/ibm/led
---------------------------------

Expand Down
33 changes: 33 additions & 0 deletions drivers/misc/thinkpad_acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,18 +1743,50 @@ static struct ibm_struct bay_driver_data = {
* CMOS subdriver
*/

/* sysfs cmos_command -------------------------------------------------- */
static ssize_t cmos_command_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned long cmos_cmd;
int res;

if (parse_strtoul(buf, 21, &cmos_cmd))
return -EINVAL;

res = issue_thinkpad_cmos_command(cmos_cmd);
return (res)? res : count;
}

static struct device_attribute dev_attr_cmos_command =
__ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store);

/* --------------------------------------------------------------------- */

static int __init cmos_init(struct ibm_init_struct *iibm)
{
int res;

vdbg_printk(TPACPI_DBG_INIT,
"initializing cmos commands subdriver\n");

IBM_ACPIHANDLE_INIT(cmos);

vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
str_supported(cmos_handle != NULL));

res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
if (res)
return res;

return (cmos_handle)? 0 : 1;
}

static void cmos_exit(void)
{
device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
}

static int cmos_read(char *p)
{
int len = 0;
Expand Down Expand Up @@ -1795,6 +1827,7 @@ static struct ibm_struct cmos_driver_data = {
.name = "cmos",
.read = cmos_read,
.write = cmos_write,
.exit = cmos_exit,
};

/*************************************************************************
Expand Down

0 comments on commit b616004

Please sign in to comment.