[PATCH 1/8] toshiba_acpi: Add System Configuration Interface (SCI)

2013-11-04 Thread Azael Avalos
The SCI stands for System Configuration Interface and
it is supposed to be uniform across all their
models.

This patch introduces four new calls, sci_open, sci_close
sci_read and sci_write, along with its definitions and
return codes.

The HCI_ prefix has been removed from all return codes,
since they are shared among the HCI and the SCI.

More information about the SCI can be found at
Jonathan Buzzard's website [1].

[1] http://www.buzzard.me.uk/toshiba/docs.html

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 146 +++-
 1 file changed, 112 insertions(+), 34 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index eb3467e..1e580dd 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -71,27 +71,37 @@ MODULE_LICENSE("GPL");
 /* Toshiba ACPI method paths */
 #define METHOD_VIDEO_OUT   "\\_SB_.VALX.DSSX"
 
-/* Toshiba HCI interface definitions
+/* TCI - Toshiba Configuration Interface definitions
  *
- * HCI is Toshiba's "Hardware Control Interface" which is supposed to
- * be uniform across all their models.  Ideally we would just call
- * dedicated ACPI methods instead of using this primitive interface.
- * However the ACPI methods seem to be incomplete in some areas (for
- * example they allow setting, but not reading, the LCD brightness value),
+ * This configuration interface is composed by the HCI (Hardware Configuration
+ * Interface) and the SCI (Software Configuration Interface), which are
+ * supposed to be uniform across all their models.  Ideally we would just call
+ * dedicated ACPI methods instead of using these primitive interfaces.
+ * However the ACPI methods seem to be incomplete in some areas (for example
+ * they allow setting, but not reading, the LCD brightness value),
  * so this is still useful.
  */
 
 #define HCI_WORDS  6
 
 /* operations */
-#define HCI_SET0xff00
+#define SCI_OPEN   0xf100
+#define SCI_CLOSE  0xf200
+#define SCI_GET0xf300
+#define SCI_SET0xf400
 #define HCI_GET0xfe00
+#define HCI_SET0xff00
 
 /* return codes */
-#define HCI_SUCCESS0x
-#define HCI_FAILURE0x1000
-#define HCI_NOT_SUPPORTED  0x8000
-#define HCI_EMPTY  0x8c00
+#define SUCCESS0x
+#define OPEN_CLOSE_SUCCESS 0x0044
+#define FAILURE0x1000
+#define NOT_SUPPORTED  0x8000
+#define ALREADY_OPEN   0x8100
+#define NOT_OPENED 0x8200
+#define INPUT_DATA_ERROR   0x8300
+#define NOT_PRESENT0x8600
+#define FIFO_EMPTY 0x8c00
 
 /* registers */
 #define HCI_FAN0x0004
@@ -251,7 +261,7 @@ static acpi_status hci_write1(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = hci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : FAILURE;
return status;
 }
 
@@ -262,7 +272,7 @@ static acpi_status hci_read1(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 out[HCI_WORDS];
acpi_status status = hci_raw(dev, in, out);
*out1 = out[2];
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : FAILURE;
return status;
 }
 
@@ -272,7 +282,7 @@ static acpi_status hci_write2(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = hci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : FAILURE;
return status;
 }
 
@@ -284,7 +294,75 @@ static acpi_status hci_read2(struct toshiba_acpi_dev *dev, 
u32 reg,
acpi_status status = hci_raw(dev, in, out);
*out1 = out[2];
*out2 = out[3];
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : FAILURE;
+   return status;
+}
+
+/* common sci tasks
+ */
+
+static int sci_open(struct toshiba_acpi_dev *dev)
+{
+   u32 in[HCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
+   u32 out[HCI_WORDS];
+   acpi_status status;
+
+   status = hci_raw(dev, in, out);
+   if  (ACPI_FAILURE(status) || out[0] == FAILURE) {
+   pr_err("ACPI call to open SCI failed\n");
+   return 0;
+   }
+
+   if (out[0] == OPEN_CLOSE_SUCCESS) {
+   return 1;
+   } else if (out[0] == ALREADY_OPEN) {
+   

[PATCH 1/8] toshiba_acpi: Add System Configuration Interface (SCI)

2013-11-04 Thread Azael Avalos
The SCI stands for System Configuration Interface and
it is supposed to be uniform across all their
models.

This patch introduces four new calls, sci_open, sci_close
sci_read and sci_write, along with its definitions and
return codes.

The HCI_ prefix has been removed from all return codes,
since they are shared among the HCI and the SCI.

More information about the SCI can be found at
Jonathan Buzzard's website [1].

[1] http://www.buzzard.me.uk/toshiba/docs.html

Signed-off-by: Azael Avalos coproscef...@gmail.com
---
 drivers/platform/x86/toshiba_acpi.c | 146 +++-
 1 file changed, 112 insertions(+), 34 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index eb3467e..1e580dd 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -71,27 +71,37 @@ MODULE_LICENSE(GPL);
 /* Toshiba ACPI method paths */
 #define METHOD_VIDEO_OUT   \\_SB_.VALX.DSSX
 
-/* Toshiba HCI interface definitions
+/* TCI - Toshiba Configuration Interface definitions
  *
- * HCI is Toshiba's Hardware Control Interface which is supposed to
- * be uniform across all their models.  Ideally we would just call
- * dedicated ACPI methods instead of using this primitive interface.
- * However the ACPI methods seem to be incomplete in some areas (for
- * example they allow setting, but not reading, the LCD brightness value),
+ * This configuration interface is composed by the HCI (Hardware Configuration
+ * Interface) and the SCI (Software Configuration Interface), which are
+ * supposed to be uniform across all their models.  Ideally we would just call
+ * dedicated ACPI methods instead of using these primitive interfaces.
+ * However the ACPI methods seem to be incomplete in some areas (for example
+ * they allow setting, but not reading, the LCD brightness value),
  * so this is still useful.
  */
 
 #define HCI_WORDS  6
 
 /* operations */
-#define HCI_SET0xff00
+#define SCI_OPEN   0xf100
+#define SCI_CLOSE  0xf200
+#define SCI_GET0xf300
+#define SCI_SET0xf400
 #define HCI_GET0xfe00
+#define HCI_SET0xff00
 
 /* return codes */
-#define HCI_SUCCESS0x
-#define HCI_FAILURE0x1000
-#define HCI_NOT_SUPPORTED  0x8000
-#define HCI_EMPTY  0x8c00
+#define SUCCESS0x
+#define OPEN_CLOSE_SUCCESS 0x0044
+#define FAILURE0x1000
+#define NOT_SUPPORTED  0x8000
+#define ALREADY_OPEN   0x8100
+#define NOT_OPENED 0x8200
+#define INPUT_DATA_ERROR   0x8300
+#define NOT_PRESENT0x8600
+#define FIFO_EMPTY 0x8c00
 
 /* registers */
 #define HCI_FAN0x0004
@@ -251,7 +261,7 @@ static acpi_status hci_write1(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = hci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : FAILURE;
return status;
 }
 
@@ -262,7 +272,7 @@ static acpi_status hci_read1(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 out[HCI_WORDS];
acpi_status status = hci_raw(dev, in, out);
*out1 = out[2];
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : FAILURE;
return status;
 }
 
@@ -272,7 +282,7 @@ static acpi_status hci_write2(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = hci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : FAILURE;
return status;
 }
 
@@ -284,7 +294,75 @@ static acpi_status hci_read2(struct toshiba_acpi_dev *dev, 
u32 reg,
acpi_status status = hci_raw(dev, in, out);
*out1 = out[2];
*out2 = out[3];
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : FAILURE;
+   return status;
+}
+
+/* common sci tasks
+ */
+
+static int sci_open(struct toshiba_acpi_dev *dev)
+{
+   u32 in[HCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
+   u32 out[HCI_WORDS];
+   acpi_status status;
+
+   status = hci_raw(dev, in, out);
+   if  (ACPI_FAILURE(status) || out[0] == FAILURE) {
+   pr_err(ACPI call to open SCI failed\n);
+   return 0;
+   }
+
+   if (out[0] == OPEN_CLOSE_SUCCESS) {
+   return 1;
+   } else if (out[0] == ALREADY_OPEN)