[ltp] [Patch 1/3] ibm-acpi: Uncouple led and light setting from proc interface.
linux-thinkpad@linux-thinkpad.org
linux-thinkpad@linux-thinkpad.org
Thu, 26 Oct 2006 01:54:38 +0200
This patch adds a set_light() and a set_led() function. This way setting led
and light is uncoupled from the proc interface.
Both interfaces, proc and sysfs, will use this functions. Removing the proc
interface at a later point is easy with this change.
Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
---
Index: linux/drivers/acpi/ibm_acpi.c
===================================================================
--- linux.orig/drivers/acpi/ibm_acpi.c 2006-10-25 23:42:49.000000000 +0200
+++ linux/drivers/acpi/ibm_acpi.c 2006-10-26 01:03:44.000000000 +0200
@@ -105,6 +105,9 @@
#define __unused __attribute__ ((unused))
+static int set_led(int lednum, int ledstate);
+static int set_light(int lightstate);
+
static int experimental;
module_param(experimental, int, 0);
@@ -871,33 +874,49 @@
static int light_write(char *buf)
{
- int cmos_cmd, lght_cmd;
char *cmd;
- int success;
if (!light_supported)
return -ENODEV;
while ((cmd = next_cmd(&buf))) {
- if (strlencmp(cmd, "on") == 0) {
- cmos_cmd = 0x0c;
- lght_cmd = 1;
- } else if (strlencmp(cmd, "off") == 0) {
- cmos_cmd = 0x0d;
- lght_cmd = 0;
- } else
+ if (strlencmp(cmd, "on") == 0)
+ set_light(1);
+ else if (strlencmp(cmd, "off") == 0)
+ set_light(0);
+ else
return -EINVAL;
-
- success = cmos_handle ?
- acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
- acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
- if (!success)
- return -EIO;
}
return 0;
}
+int set_light(int lightstate)
+{
+ int cmos_cmd, lght_cmd;
+ int success;
+
+ if (!light_supported)
+ return -ENODEV;
+
+ if (lightstatei == 1) {
+ cmos_cmd = 0x0c;
+ lght_cmd = 1;
+ } else if (lightstate == 0) {
+ cmos_cmd = 0x0d;
+ lght_cmd = 0;
+ } else
+ return -EINVAL;
+
+ success = cmos_handle ?
+ acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
+ acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
+ if (!success)
+ return -EIO;
+
+ return 0;
+}
+
static int _sta(acpi_handle handle)
{
int status;
@@ -1161,7 +1180,7 @@
static int led_write(char *buf)
{
char *cmd;
- int led, ind, ret;
+ int led;
if (!led_supported)
return -ENODEV;
@@ -1170,39 +1189,57 @@
if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
return -EINVAL;
- if (strstr(cmd, "off")) {
- ind = 0;
- } else if (strstr(cmd, "on")) {
- ind = 1;
- } else if (strstr(cmd, "blink")) {
- ind = 2;
- } else
+ if (strstr(cmd, "off"))
+ set_led(led, 0);
+ else if (strstr(cmd, "on"))
+ set_led(led, 1);
+ else if (strstr(cmd, "blink"))
+ set_led(led, 2);
+ else
return -EINVAL;
+ }
- if (led_supported == LED_570) {
- /* 570 */
- led = 1 << led;
- if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
- led, led_sled_arg1[ind]))
- return -EIO;
- } else if (led_supported == LED_OLD) {
- /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
- led = 1 << led;
- ret = ec_write(EC_HLMS, led);
- if (ret >= 0)
- ret =
- ec_write(EC_HLBL, led * led_exp_hlbl[ind]);
- if (ret >= 0)
- ret =
- ec_write(EC_HLCL, led * led_exp_hlcl[ind]);
- if (ret < 0)
- return ret;
- } else {
- /* all others */
- if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
- led, led_led_arg1[ind]))
- return -EIO;
- }
+ return 0;
+}
+
+/* lednum: 0-7, ledstate: 0 = off, 1 = on, 2 = blink */
+
+int set_led(int lednum, int ledstate)
+{
+ int ret;
+
+ if (!led_supported)
+ return -ENODEV;
+
+ if (lednum < 0 || lednum > 7)
+ return -EINVAL;
+
+ if (ledstate < 0 || ledstate > 2)
+ return -EINVAL;
+
+ if (led_supported == LED_570) {
+ /* 570 */
+ lednum = 1 << lednum;
+ if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
+ lednum, led_sled_arg1[ledstate]))
+ return -EIO;
+ } else if (led_supported == LED_OLD) {
+ /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
+ lednum = 1 << lednum;
+ ret = ec_write(EC_HLMS, lednum);
+ if (ret >= 0)
+ ret =
+ ec_write(EC_HLBL, lednum * led_exp_hlbl[ledstate]);
+ if (ret >= 0)
+ ret =
+ ec_write(EC_HLCL, lednum * led_exp_hlcl[ledstate]);
+ if (ret < 0)
+ return ret;
+ } else {
+ /* all others */
+ if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
+ lednum, led_led_arg1[ledstate]))
+ return -EIO;
}
return 0;
--