Change the toshiba_illumination_* code to use the newly
introduced sci_read and sci_write functions, and in the
process fix toshiba_illumination_available code, since
it was only opening the SCI and the return value was
never checked for errors or actual illumination support.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 drivers/platform/x86/toshiba_acpi.c | 91 ++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 58 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 1e580dd..d7ecef3 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -111,6 +111,7 @@ MODULE_LICENSE("GPL");
 #define HCI_HOTKEY_EVENT               0x001e
 #define HCI_LCD_BRIGHTNESS             0x002a
 #define HCI_WIRELESS                   0x0056
+#define SCI_ILLUMINATION               0x014e
 
 /* field definitions */
 #define HCI_HOTKEY_DISABLE             0x0b
@@ -369,18 +370,23 @@ static acpi_status sci_write(struct toshiba_acpi_dev 
*dev, u32 reg,
 /* Illumination support */
 static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
 {
-       u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
+       u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
        u32 out[HCI_WORDS];
        acpi_status status;
 
-       in[0] = 0xf100;
+       if (!sci_open(dev))
+               return 0;
+
        status = hci_raw(dev, in, out);
-       if (ACPI_FAILURE(status)) {
+       if (ACPI_FAILURE(status) || out[0] == FAILURE) {
+               pr_err("ACPI call to query Illumination support failed\n");
+               return 0;
+       } else if (out[0] == NOT_SUPPORTED || out[1] != 1) {
                pr_info("Illumination device not available\n");
                return 0;
        }
-       in[0] = 0xf400;
-       status = hci_raw(dev, in, out);
+       sci_close(dev);
+
        return 1;
 }
 
@@ -391,43 +397,23 @@ static void toshiba_illumination_set(struct led_classdev 
*cdev,
                        struct toshiba_acpi_dev, led_dev);
        u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
        u32 out[HCI_WORDS];
+       u32 state, result;
        acpi_status status;
 
-       /* First request : initialize communication. */
-       in[0] = 0xf100;
-       status = hci_raw(dev, in, out);
-       if (ACPI_FAILURE(status)) {
-               pr_info("Illumination device not available\n");
+       if (!sci_open(dev))
                return;
-       }
 
-       if (brightness) {
-               /* Switch the illumination on */
-               in[0] = 0xf400;
-               in[1] = 0x14e;
-               in[2] = 1;
-               status = hci_raw(dev, in, out);
-               if (ACPI_FAILURE(status)) {
-                       pr_info("ACPI call for illumination failed\n");
-                       return;
-               }
-       } else {
-               /* Switch the illumination off */
-               in[0] = 0xf400;
-               in[1] = 0x14e;
-               in[2] = 0;
-               status = hci_raw(dev, in, out);
-               if (ACPI_FAILURE(status)) {
-                       pr_info("ACPI call for illumination failed.\n");
-                       return;
-               }
+       /* Switch the illumination on/off */
+       state = brightness ? 1 : 0;
+       status = sci_write(dev, SCI_ILLUMINATION, state, &result);
+       if (ACPI_FAILURE(status)) {
+               pr_err("ACPI call for illumination failed\n");
+               return;
+       } else if (result == NOT_SUPPORTED) {
+               pr_info("Illumination not supported\n");
+               return;
        }
-
-       /* Last request : close communication. */
-       in[0] = 0xf200;
-       in[1] = 0;
-       in[2] = 0;
-       hci_raw(dev, in, out);
+       sci_close(dev);
 }
 
 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
@@ -436,35 +422,24 @@ static enum led_brightness 
toshiba_illumination_get(struct led_classdev *cdev)
                        struct toshiba_acpi_dev, led_dev);
        u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
        u32 out[HCI_WORDS];
+       u32 state, result;
        acpi_status status;
-       enum led_brightness result;
 
-       /* First request : initialize communication. */
-       in[0] = 0xf100;
-       status = hci_raw(dev, in, out);
-       if (ACPI_FAILURE(status)) {
-               pr_info("Illumination device not available\n");
+       if (!sci_open(dev))
                return LED_OFF;
-       }
 
        /* Check the illumination */
-       in[0] = 0xf300;
-       in[1] = 0x14e;
-       status = hci_raw(dev, in, out);
-       if (ACPI_FAILURE(status)) {
-               pr_info("ACPI call for illumination failed.\n");
+       status = sci_read(dev, SCI_ILLUMINATION, &state, &result);
+       if (ACPI_FAILURE(status) || result == INPUT_DATA_ERROR) {
+               pr_err("ACPI call for illumination failed\n");
+               return LED_OFF;
+       } else if (result == NOT_SUPPORTED) {
+               pr_info("Illumination not supported\n");
                return LED_OFF;
        }
+       sci_close(dev);
 
-       result = out[2] ? LED_FULL : LED_OFF;
-
-       /* Last request : close communication. */
-       in[0] = 0xf200;
-       in[1] = 0;
-       in[2] = 0;
-       hci_raw(dev, in, out);
-
-       return result;
+       return state ? LED_FULL : LED_OFF;
 }
 
 /* Bluetooth rfkill handlers */
-- 
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to