[PATCH 1/2] toshiba_haps: Split ACPI status error check from HDD protection support

2016-09-07 Thread Azael Avalos
Currently the code checking for the ACPI status is mixed along with
the actual HDD protection status check.

This patch splits those two checks are they are not related, printing
an error string in case the ACPI call failed, and then check for
actual HDD protection status.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_haps.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/toshiba_haps.c 
b/drivers/platform/x86/toshiba_haps.c
index 7f2afc6..094f3a8 100644
--- a/drivers/platform/x86/toshiba_haps.c
+++ b/drivers/platform/x86/toshiba_haps.c
@@ -168,9 +168,13 @@ static int toshiba_haps_available(acpi_handle handle)
 * A non existent device as well as having (only)
 * Solid State Drives can cause the call to fail.
 */
-   status = acpi_evaluate_integer(handle, "_STA", NULL,
-  &hdd_present);
-   if (ACPI_FAILURE(status) || !hdd_present) {
+   status = acpi_evaluate_integer(handle, "_STA", NULL, &hdd_present);
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to query HDD protection failed\n");
+   return 0;
+   }
+
+   if (!hdd_present) {
pr_info("HDD protection not available or using SSD\n");
return 0;
}
-- 
2.9.3



[PATCH 0/2] toshiba_haps: Small updates to driver code

2016-09-07 Thread Azael Avalos
These two patches make some small changes to the driver code, the first
splits the error check fro the ACPI status and the HDD protection, and
the second simply changes the printing level of two strings from info
to debug.

Azael Avalos (2):
  toshiba_haps: Split ACPI status error check from HDD protection
support
  toshiba_haps: Change the error logging level from info to debug

 drivers/platform/x86/toshiba_haps.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

-- 
2.9.3



[PATCH 2/2] toshiba_haps: Change the error logging level from info to debug

2016-09-07 Thread Azael Avalos
Two of the internal functions are printing an info message, one
whenever the HDD protection level changes, and another when the
driver receives an ACPI event.

This patch changes those two prints to debug, as that information
is more pertaining to debuging purposes.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_haps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/toshiba_haps.c 
b/drivers/platform/x86/toshiba_haps.c
index 094f3a8..b3dec52 100644
--- a/drivers/platform/x86/toshiba_haps.c
+++ b/drivers/platform/x86/toshiba_haps.c
@@ -59,7 +59,7 @@ static int toshiba_haps_protection_level(acpi_handle handle, 
int level)
return -EIO;
}
 
-   pr_info("HDD protection level set to: %d\n", level);
+   pr_debug("HDD protection level set to: %d\n", level);
 
return 0;
 }
@@ -141,7 +141,7 @@ static struct attribute_group haps_attr_group = {
  */
 static void toshiba_haps_notify(struct acpi_device *device, u32 event)
 {
-   pr_info("Received event: 0x%x", event);
+   pr_debug("Received event: 0x%x", event);
 
acpi_bus_generate_netlink_event(device->pnp.device_class,
dev_name(&device->dev),
-- 
2.9.3



[PATCH] toshiba_bluetooth: Decouple an error checking status code

2016-09-07 Thread Azael Avalos
This patch simply decouples te error checking of the ACPI status and
the actual BT status, as those two were nested in an if/else check,
but are completely unrelated.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_bluetooth.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_bluetooth.c 
b/drivers/platform/x86/toshiba_bluetooth.c
index 5db495dd..be1d137 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -80,7 +80,9 @@ static int toshiba_bluetooth_present(acpi_handle handle)
if (ACPI_FAILURE(result)) {
pr_err("ACPI call to query Bluetooth presence failed\n");
return -ENXIO;
-   } else if (!bt_present) {
+   }
+
+   if (!bt_present) {
pr_info("Bluetooth device not present\n");
return -ENODEV;
}
-- 
2.9.3



[PATCH] toshiba-wmi: Fix loading the driver on non Toshiba laptops

2016-08-25 Thread Azael Avalos
Bug 150611 uncovered that the WMI ID used by the toshiba-wmi driver
is not Toshiba specific, and as such, the driver was being loaded
on non Toshiba laptops too.

This patch adds a DMI matching list checking for TOSHIBA as the
vendor, refusing to load if it is not.

Also the WMI GUID was renamed, dropping the TOSHIBA_ prefix, to
better reflect that such GUID is not a Toshiba specific one.

Cc:  # 4.4+
Signed-off-by: Azael Avalos 
---
Hi Darren,

I was waiting on input from the bug above, but haven't received an
answer (as of yet), so I decided to send this to the mailing list
for feedback as to whether this is the correct approach for this
issue.

 drivers/platform/x86/toshiba-wmi.c | 26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/x86/toshiba-wmi.c 
b/drivers/platform/x86/toshiba-wmi.c
index feac457..0c92887 100644
--- a/drivers/platform/x86/toshiba-wmi.c
+++ b/drivers/platform/x86/toshiba-wmi.c
@@ -24,14 +24,15 @@
 #include 
 #include 
 #include 
+#include 
 
 MODULE_AUTHOR("Azael Avalos");
 MODULE_DESCRIPTION("Toshiba WMI Hotkey Driver");
 MODULE_LICENSE("GPL");
 
-#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
+#define WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
 
-MODULE_ALIAS("wmi:"TOSHIBA_WMI_EVENT_GUID);
+MODULE_ALIAS("wmi:"WMI_EVENT_GUID);
 
 static struct input_dev *toshiba_wmi_input_dev;
 
@@ -63,6 +64,16 @@ static void toshiba_wmi_notify(u32 value, void *context)
kfree(response.pointer);
 }
 
+static struct dmi_system_id toshiba_wmi_dmi_table[] __initdata = {
+   {
+   .ident = "Toshiba laptop",
+   .matches = {
+   DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
+   },
+   },
+   {}
+};
+
 static int __init toshiba_wmi_input_setup(void)
 {
acpi_status status;
@@ -81,7 +92,7 @@ static int __init toshiba_wmi_input_setup(void)
if (err)
goto err_free_dev;
 
-   status = wmi_install_notify_handler(TOSHIBA_WMI_EVENT_GUID,
+   status = wmi_install_notify_handler(WMI_EVENT_GUID,
toshiba_wmi_notify, NULL);
if (ACPI_FAILURE(status)) {
err = -EIO;
@@ -95,7 +106,7 @@ static int __init toshiba_wmi_input_setup(void)
return 0;
 
  err_remove_notifier:
-   wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID);
+   wmi_remove_notify_handler(WMI_EVENT_GUID);
  err_free_keymap:
sparse_keymap_free(toshiba_wmi_input_dev);
  err_free_dev:
@@ -105,7 +116,7 @@ static int __init toshiba_wmi_input_setup(void)
 
 static void toshiba_wmi_input_destroy(void)
 {
-   wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID);
+   wmi_remove_notify_handler(WMI_EVENT_GUID);
sparse_keymap_free(toshiba_wmi_input_dev);
input_unregister_device(toshiba_wmi_input_dev);
 }
@@ -114,7 +125,8 @@ static int __init toshiba_wmi_init(void)
 {
int ret;
 
-   if (!wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
+   if (!wmi_has_guid(WMI_EVENT_GUID) ||
+   !dmi_check_system(toshiba_wmi_dmi_table))
return -ENODEV;
 
ret = toshiba_wmi_input_setup();
@@ -130,7 +142,7 @@ static int __init toshiba_wmi_init(void)
 
 static void __exit toshiba_wmi_exit(void)
 {
-   if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
+   if (wmi_has_guid(WMI_EVENT_GUID))
toshiba_wmi_input_destroy();
 }
 
-- 
2.9.3



[PATCH] toshiba_acpi: Fix hotkeys registration on some toshiba models

2015-09-09 Thread Azael Avalos
Commit a2b3471b5b13 ("toshiba_acpi: Use the Hotkey Event Type function
for keymap choosing") changed the *setup_keyboard function to query for
the Hotkey Event Type to help choose the correct keymap, but turns out
that here are certain Toshiba models out there not implementing this
feature, and thus, failing to continue the input device registration and
leaving such laptops without hotkey support.

This patch changes such check, and instead of returning an error if
the Hotkey Event Type is not present, we simply inform userspace about it,
changing the message printed from err to notice, making the function
responsible for registering the input device to continue.

This issue was found on a Toshiba Portege Z30-B, but there might be
some other models out there affected by this regression as well.

Cc:  # 4.1+
Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index c434b53..f2372f4 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -2398,11 +2398,9 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
if (error)
return error;
 
-   error = toshiba_hotkey_event_type_get(dev, &events_type);
-   if (error) {
-   pr_err("Unable to query Hotkey Event Type\n");
-   return error;
-   }
+   if (toshiba_hotkey_event_type_get(dev, &events_type))
+   pr_notice("Unable to query Hotkey Event Type\n");
+
dev->hotkey_event_type = events_type;
 
dev->hotkey_dev = input_allocate_device();
-- 
2.5.1

--
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/


[PATCH] toshiba_acpi: Fix USB Sleep and Music always disabled

2015-09-09 Thread Azael Avalos
Commit e1a949c1b988 ("toshiba_acpi: Refactor *{get, set} functions return
value") made changes on the return type of the HCI/SCI functions, but a
typo on the USB Sleep and Music code is always reporting non existent
support for such feature.

This patch corrects the typo, changing an assignment to a comparison,
making the laptops with actual support for such feature to work again.

Signed-off-by: Azael Avalos 
---
Darren,

Hopefully this patch can go into one of the 4.3 RCs, as the changes are
there and to avoid shipping a broken feature support.

 drivers/platform/x86/toshiba_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 6740c51..c434b53 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -938,7 +938,7 @@ static int toshiba_usb_sleep_music_get(struct 
toshiba_acpi_dev *dev, u32 *state)
else if (result == TOS_NOT_SUPPORTED)
return -ENODEV;
 
-   return result = TOS_SUCCESS ? 0 : -EIO;
+   return result == TOS_SUCCESS ? 0 : -EIO;
 }
 
 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
-- 
2.5.1

--
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/


[PATCH 0/2] toshiba_acpi: Hotkey updates

2015-09-09 Thread Azael Avalos
These two patches make some changes to the hotkeys code, the first
patch unify the hotkey enabling code, and the second changes the default
hotkey enabling parameter.

Azael Avalos (2):
  toshiba_acpi: Unify hotkey enabling functions
  toshiba_acpi: Change default Hotkey enabling value

 drivers/platform/x86/toshiba_acpi.c | 38 +
 1 file changed, 13 insertions(+), 25 deletions(-)

-- 
2.5.1

--
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/


[PATCH 1/2] toshiba_acpi: Unify hotkey enabling functions

2015-09-09 Thread Azael Avalos
Currently the driver has two functions enabling hotkeys support,
but these two functions can be merged into one.

This patch merges these two functions, moving some checks to the
*enable_hotkeys function, simplifying code in the process.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index f2372f4..5510d3f 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -198,6 +198,7 @@ struct toshiba_acpi_dev {
unsigned int panel_power_on_supported:1;
unsigned int usb_three_supported:1;
unsigned int sysfs_created:1;
+   unsigned int special_functions;
 
bool kbd_led_registered;
bool illumination_led_registered;
@@ -2253,7 +2254,16 @@ static int toshiba_acpi_enable_hotkeys(struct 
toshiba_acpi_dev *dev)
if (ACPI_FAILURE(status))
return -ENODEV;
 
-   result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
+   /*
+* Enable the "Special Functions" mode only if they are
+* supported and if they are activated.
+*/
+   if (dev->kbd_function_keys_supported && dev->special_functions)
+   result = hci_write(dev, HCI_HOTKEY_EVENT,
+  HCI_HOTKEY_SPECIAL_FUNCTIONS);
+   else
+   result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
+
if (result == TOS_FAILURE)
return -EIO;
else if (result == TOS_NOT_SUPPORTED)
@@ -2262,20 +2272,6 @@ static int toshiba_acpi_enable_hotkeys(struct 
toshiba_acpi_dev *dev)
return 0;
 }
 
-static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev)
-{
-   u32 result;
-
-   /*
-* Re-activate the hotkeys, but this time, we are using the
-* "Special Functions" mode.
-*/
-   result = hci_write(dev, HCI_HOTKEY_EVENT,
-  HCI_HOTKEY_SPECIAL_FUNCTIONS);
-   if (result != TOS_SUCCESS)
-   pr_err("Could not enable the Special Function mode\n");
-}
-
 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
  struct serio *port)
 {
@@ -2631,7 +2627,6 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 {
struct toshiba_acpi_dev *dev;
const char *hci_method;
-   u32 special_functions;
u32 dummy;
int ret = 0;
 
@@ -2673,7 +2668,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 * with the new keyboard layout, query for its presence to help
 * determine the keymap layout to use.
 */
-   ret = toshiba_function_keys_get(dev, &special_functions);
+   ret = toshiba_function_keys_get(dev, &dev->special_functions);
dev->kbd_function_keys_supported = !ret;
 
if (toshiba_acpi_setup_keyboard(dev))
@@ -2748,13 +2743,6 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 
print_supported_features(dev);
 
-   /*
-* Enable the "Special Functions" mode only if they are
-* supported and if they are activated.
-*/
-   if (dev->kbd_function_keys_supported && special_functions)
-   toshiba_acpi_enable_special_functions(dev);
-
ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
 &toshiba_attr_group);
if (ret) {
-- 
2.5.1

--
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/


[PATCH] platform/x86: Toshiba WMI Hotkey Driver

2015-09-09 Thread Azael Avalos
Toshiba laptops that feature WMI events for hotkeys were left unsupported
by the toshiba_acpi driver, however, commit a88bc06e5aec ("toshiba_acpi:
Avoid registering input device on WMI event laptops") added hardware
support for such laptops, but the hotkeys are not handled there.

This driver adds support for hotkey monitoring on certain Toshiba laptops
that manage the hotkeys via WMI events instead of the Toshiba
Configuration Interface (TCI).

The toshiba_acpi driver and this one can co-exist, as this only takes
care of hotkeys, while the propper takes care of hardware related stuff.

Currently the driver is under the EXPERIMENTAL flag, as the keymap
and the notify function are incomplete (due to lack of hardware to test).

Signed-off-by: Azael Avalos 
---
 MAINTAINERS|   6 ++
 drivers/platform/x86/Kconfig   |  18 +
 drivers/platform/x86/Makefile  |   1 +
 drivers/platform/x86/toshiba-wmi.c | 138 +
 4 files changed, 163 insertions(+)
 create mode 100644 drivers/platform/x86/toshiba-wmi.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 884d398..07f4446 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10318,6 +10318,12 @@ L: platform-driver-...@vger.kernel.org
 S: Maintained
 F: drivers/platform/x86/toshiba_haps.c
 
+TOSHIBA WMI HOTKEYS DRIVER
+M: Azael Avalos 
+L: platform-driver-...@vger.kernel.org
+S: Maintained
+F: drivers/platform/x86/toshiba-wmi.c
+
 TOSHIBA SMM DRIVER
 M: Jonathan Buzzard 
 W: http://www.buzzard.org.uk/toshiba/
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index c69bb70..9ae1e89 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -700,6 +700,24 @@ config TOSHIBA_HAPS
  If you have a recent Toshiba laptop with a built-in accelerometer
  device, say Y.
 
+config TOSHIBA_WMI
+   tristate "Toshiba WMI Hotkeys Driver (EXPERIMENTAL)"
+   default n
+   depends on ACPI_WMI
+   depends on INPUT
+   select INPUT_SPARSEKMAP
+   ---help---
+ This driver adds hotkey monitoring support to some Toshiba models
+ that manage the hotkeys via WMI events.
+
+ WARNING: This driver is incomplete as it lacks a propper keymap and 
the
+ *notify function only prints the ACPI event type value. Be warned that
+ you will need to provide some information if you have a Toshiba model
+ with WMI event hotkeys and want to help with the develpment of this
+ driver.
+
+ If you have a WMI-based hotkeys Toshiba laptop, say Y or M here.
+
 config ACPI_CMPC
tristate "CMPC Laptop Extras"
depends on X86 && ACPI
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index ada5128..8f077cb 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_ACPI_TOSHIBA)+= toshiba_acpi.o
 
 obj-$(CONFIG_TOSHIBA_BT_RFKILL)+= toshiba_bluetooth.o
 obj-$(CONFIG_TOSHIBA_HAPS) += toshiba_haps.o
+obj-$(CONFIG_TOSHIBA_HAPS) += toshiba-wmi.o
 obj-$(CONFIG_INTEL_SCU_IPC)+= intel_scu_ipc.o
 obj-$(CONFIG_INTEL_SCU_IPC_UTIL) += intel_scu_ipcutil.o
 obj-$(CONFIG_INTEL_MFLD_THERMAL) += intel_mid_thermal.o
diff --git a/drivers/platform/x86/toshiba-wmi.c 
b/drivers/platform/x86/toshiba-wmi.c
new file mode 100644
index 000..8cf62a1
--- /dev/null
+++ b/drivers/platform/x86/toshiba-wmi.c
@@ -0,0 +1,138 @@
+/*
+ * toshiba_wmi.c - Toshiba WMI Hotkey Driver
+ *
+ * Copyright (C) 2015 Azael Avalos 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+MODULE_AUTHOR("Azael Avalos");
+MODULE_DESCRIPTION("Toshiba WMI Hotkey Driver");
+MODULE_LICENSE("GPL");
+
+#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
+
+MODULE_ALIAS("wmi:"TOSHIBA_WMI_EVENT_GUID);
+
+struct input_dev *toshiba_wmi_input_dev;
+
+static const struct key_entry toshiba_wmi_keymap[] __initconst = {
+   /* TODO: Add keymap values once found... */
+   /*{ KE_KEY, 0x00, { KEY_ } },*/
+   { KE_END, 0 }
+};
+
+static void toshiba_wmi_notify(u32 value, void *context)
+{
+   struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
+   union acpi_object *obj;
+   acpi_statu

[PATCH 1/1] toshiba_acpi: Remove unneeded u32 variables from *setup_keyboard

2015-09-09 Thread Azael Avalos
The function toshiba_acpi_setup_keyboard currently has two u32 variables
used to store the Hotkey Event Type and the result of the HCI_SYSTEM_EVENT
query.

This patch removes those two variables, as we already have a global
variable named "hotkey_event_type" and the result of the HCI_SYSTEM_EVENT
query can be checked directly from the function.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 803e967..9f7ced1 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -2381,8 +2381,6 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
 {
const struct key_entry *keymap = toshiba_acpi_keymap;
acpi_handle ec_handle;
-   u32 events_type;
-   u32 hci_result;
int error;
 
if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
@@ -2394,11 +2392,9 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
if (error)
return error;
 
-   if (toshiba_hotkey_event_type_get(dev, &events_type))
+   if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type))
pr_notice("Unable to query Hotkey Event Type\n");
 
-   dev->hotkey_event_type = events_type;
-
dev->hotkey_dev = input_allocate_device();
if (!dev->hotkey_dev)
return -ENOMEM;
@@ -2407,14 +2403,15 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
dev->hotkey_dev->phys = "toshiba_acpi/input0";
dev->hotkey_dev->id.bustype = BUS_HOST;
 
-   if (events_type == HCI_SYSTEM_TYPE1 ||
+   if (dev->hotkey_event_type == HCI_SYSTEM_TYPE1 ||
!dev->kbd_function_keys_supported)
keymap = toshiba_acpi_keymap;
-   else if (events_type == HCI_SYSTEM_TYPE2 ||
+   else if (dev->hotkey_event_type == HCI_SYSTEM_TYPE2 ||
 dev->kbd_function_keys_supported)
keymap = toshiba_acpi_alt_keymap;
else
-   pr_info("Unknown event type received %x\n", events_type);
+   pr_info("Unknown event type received %x\n",
+   dev->hotkey_event_type);
error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
if (error)
goto err_free_dev;
@@ -2443,12 +2440,10 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
 * Determine hotkey query interface. Prefer using the INFO
 * method when it is available.
 */
-   if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
+   if (acpi_has_method(dev->acpi_dev->handle, "INFO")) {
dev->info_supported = 1;
-   else {
-   hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
-   if (hci_result == TOS_SUCCESS)
-   dev->system_event_supported = 1;
+   } else if (hci_write(dev, HCI_SYSTEM_EVENT, 1) == TOS_SUCCESS)
+   dev->system_event_supported = 1;
}
 
if (!dev->info_supported && !dev->system_event_supported) {
-- 
2.5.1

--
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/


[PATCH 1/1] toshiba_acpi: Add 0x prefix to available_kbd_modes_show funtion

2015-09-09 Thread Azael Avalos
This patch adds the 0x prefix to the values printed by such function, the
values are already being printed in hex, but without the prefix, causing
confussion, even though the file under Documentation/ABI clearly states
that hey are hex values.

Simply add the 0x prefix to avoid such confussion.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 9f7ced1..50a2116 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1669,10 +1669,10 @@ static ssize_t available_kbd_modes_show(struct device 
*dev,
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
 
if (toshiba->kbd_type == 1)
-   return sprintf(buf, "%x %x\n",
+   return sprintf(buf, "0x%x 0x%x\n",
   SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
 
-   return sprintf(buf, "%x %x %x\n",
+   return sprintf(buf, "0x%x 0x%x 0x%x\n",
   SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
 }
 static DEVICE_ATTR_RO(available_kbd_modes);
-- 
2.5.1

--
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/


[PATCH 2/2] toshiba_acpi: Change default Hotkey enabling value

2015-09-09 Thread Azael Avalos
The driver currently uses the hotkey enabling value of 0x09 to enable
hotkey events, but windows uses a different value (0x01).

All Toshiba laptops accept the following "hotkey" parameters:
0x01 - Enable hotkey and system events.
0x03 - Enable system events only.
0x09 - Enable hotkey events only.
0x0b - Disable (hotkey and system) events.

This patch changes the default hotkey enabling value from 0x09 to 0x01,
enabling both the hotkey and system events.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 5510d3f..803e967 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -131,7 +131,7 @@ MODULE_LICENSE("GPL");
 /* Field definitions */
 #define HCI_ACCEL_MASK 0x7fff
 #define HCI_HOTKEY_DISABLE 0x0b
-#define HCI_HOTKEY_ENABLE  0x09
+#define HCI_HOTKEY_ENABLE  0x01
 #define HCI_HOTKEY_SPECIAL_FUNCTIONS   0x10
 #define HCI_LCD_BRIGHTNESS_BITS3
 #define HCI_LCD_BRIGHTNESS_SHIFT   (16-HCI_LCD_BRIGHTNESS_BITS)
-- 
2.5.1

--
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/


Re: [PATCH 4.2 022/258] toshiba_acpi: Fix hotkeys registration on some toshiba models

2015-10-26 Thread Azael Avalos
Hi there,

Sorry for the late reply :-(

2015-10-21 2:48 GMT-06:00 Darren Hart :
> On Tue, Oct 20, 2015 at 12:32:45AM +0100, Ben Hutchings wrote:
>> On Sat, 2015-10-17 at 18:55 -0700, Greg Kroah-Hartman wrote:
>> > 4.2-stable review patch.  If anyone has any objections, please let me know.
>> >
>> > ------
>> >
>> > From: Azael Avalos 
>> >
>> > commit 53147b6cabee5e8d1997b5682fcc0c3b72ddf9c2 upstream.
>> >
>> > Commit a2b3471b5b13 ("toshiba_acpi: Use the Hotkey Event Type function
>> > for keymap choosing") changed the *setup_keyboard function to query for
>> > the Hotkey Event Type to help choose the correct keymap, but turns out
>> > that here are certain Toshiba models out there not implementing this
>> > feature, and thus, failing to continue the input device registration and
>> > leaving such laptops without hotkey support.
>> >
>> > This patch changes such check, and instead of returning an error if
>> > the Hotkey Event Type is not present, we simply inform userspace about it,
>> > changing the message printed from err to notice, making the function
>> > responsible for registering the input device to continue.
>> [...]
>>
>> But then this function proceeds without events_type being initialised
>> at all, with unpredictable results.  This doesn't look like a proper
>>  fix.
>
> Azael, Ben has a point. Even after later patches, dev->hotkey_event_type 
> doesn't
> have a default value, so the later check for HCI_SYSTEM_TYPE1 or
> HCI_SYSTEM_TYPE2 or failure is unpredictable.

Yes, I see the issue here.
Since the function was returning before the variable value didin't matter,
and when "fixing" the issue on the mentioned model I never took the
variable initialization into account.

I'll send a patch probably later today addressing this issue.

>
> --
> Darren Hart
> Intel Open Source Technology Center


Cheers
Azael


-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


Re: [PATCH v2 2/3] toshiba_acpi: Change notify funtion to handle more events

2014-12-04 Thread Azael Avalos
Hi Darren,

2014-12-03 6:12 GMT-07:00 Darren Hart :
> On Wed, Dec 03, 2014 at 11:42:04PM -0700, Azael Avalos wrote:
>> @@ -1971,41 +2008,22 @@ error:
>>  static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
>>  {
>>   struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
>> - u32 hci_result, value;
>> - int retries = 3;
>> - int scancode;
>> -
>> - if (event != 0x80)
>> - return;
>> + int ret;
>
>   CC  drivers/platform/x86/toshiba_acpi.o
> drivers/platform/x86/toshiba_acpi.c: In function ‘toshiba_acpi_notify’:
> drivers/platform/x86/toshiba_acpi.c:2012:6: warning: unused variable ‘ret’ 
> [-Wunused-variable]
> int ret;
>   ^
>
> Please compile check each patch.

Sorry about that, was a left over from the split.
Want me to send a V3? I can send them in few minutes.

>
> --
> Darren Hart
> Intel Open Source Technology Center



-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


[PATCH v3 3/3] toshiba_acpi: Add keyboard backlight mode change event

2014-12-04 Thread Azael Avalos
A previous patch added support to handle more events.

This patch adds support to update the sysfs group whenever we receive
a 0x92 event, which indicates a change in the keyboard backlight mode,
removing the update group code from toshiba_kbd_bl_mode_store, as it is
no longer needed there.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 99db763..5e9b298 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1393,12 +1393,6 @@ static ssize_t toshiba_kbd_bl_mode_store(struct device 
*dev,
if (ret)
return ret;
 
-   /* Update sysfs entries on successful mode change*/
-   ret = sysfs_update_group(&toshiba->acpi_dev->dev.kobj,
-&toshiba_attr_group);
-   if (ret)
-   return ret;
-
toshiba->kbd_mode = mode;
}
 
@@ -2008,11 +2002,19 @@ error:
 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
 {
struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
+   int ret;
 
switch (event) {
case 0x80: /* Hotkeys and some system events */
toshiba_acpi_process_hotkeys(dev);
break;
+   case 0x92: /* Keyboard backlight mode changed */
+   /* Update sysfs entries */
+   ret = sysfs_update_group(&acpi_dev->dev.kobj,
+&toshiba_attr_group);
+   if (ret)
+   pr_err("Unable to update sysfs entries\n");
+   break;
case 0x81: /* Unknown */
case 0x82: /* Unknown */
case 0x83: /* Unknown */
-- 
2.1.2

--
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/


[PATCH v3 0/3] toshiba_acpi: Hotkeys and event handling changes

2014-12-04 Thread Azael Avalos
These patches change the current code to accomodate the handling
of more events, since so far, it only handles hotkey events (0x80),
move the hotkey enabling code to a sub function to avoid duplication,
and add event 0x92 which indicates a change in the keyboard backlight
mode.

Changes since V3:
- Removed a left over variable from the split in patch 02 and
  moved it to patch 03 (where it belongs)
- A bit more verbose description on patch 03

Azael Avalos (3):
  toshiba_acpi: Move hotkey enabling code to own function
  toshiba_acpi: Change notify funtion to handle more events
  toshiba_acpi: Add keyboard backlight mode change event

 drivers/platform/x86/toshiba_acpi.c | 139 ++--
 1 file changed, 86 insertions(+), 53 deletions(-)

-- 
2.1.2

--
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/


[PATCH v3 2/3] toshiba_acpi: Change notify funtion to handle more events

2014-12-04 Thread Azael Avalos
Currently the function toshiba_acpi_notify only takes care of hotkeys,
however, the TOS devices receive more events that can be useful.

This patch changes the function to be able to handle more events,
and in the process, move all hotkey related code residing in it to
a new function called toshiba_acpi_process_hotkeys.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 8bb07c7..99db763 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1657,6 +1657,43 @@ static void toshiba_acpi_report_hotkey(struct 
toshiba_acpi_dev *dev,
pr_info("Unknown key %x\n", scancode);
 }
 
+static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
+{
+   u32 hci_result, value;
+   int retries = 3;
+   int scancode;
+
+   if (dev->info_supported) {
+   scancode = toshiba_acpi_query_hotkey(dev);
+   if (scancode < 0)
+   pr_err("Failed to query hotkey event\n");
+   else if (scancode != 0)
+   toshiba_acpi_report_hotkey(dev, scancode);
+   } else if (dev->system_event_supported) {
+   do {
+   hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
+   switch (hci_result) {
+   case TOS_SUCCESS:
+   toshiba_acpi_report_hotkey(dev, (int)value);
+   break;
+   case TOS_NOT_SUPPORTED:
+   /*
+* This is a workaround for an unresolved
+* issue on some machines where system events
+* sporadically become disabled.
+*/
+   hci_result =
+   hci_write1(dev, HCI_SYSTEM_EVENT, 1);
+   pr_notice("Re-enabled hotkeys\n");
+   /* fall through */
+   default:
+   retries--;
+   break;
+   }
+   } while (retries && hci_result != TOS_FIFO_EMPTY);
+   }
+}
+
 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
 {
acpi_handle ec_handle;
@@ -1971,41 +2008,21 @@ error:
 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
 {
struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
-   u32 hci_result, value;
-   int retries = 3;
-   int scancode;
 
-   if (event != 0x80)
-   return;
-
-   if (dev->info_supported) {
-   scancode = toshiba_acpi_query_hotkey(dev);
-   if (scancode < 0)
-   pr_err("Failed to query hotkey event\n");
-   else if (scancode != 0)
-   toshiba_acpi_report_hotkey(dev, scancode);
-   } else if (dev->system_event_supported) {
-   do {
-   hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
-   switch (hci_result) {
-   case TOS_SUCCESS:
-   toshiba_acpi_report_hotkey(dev, (int)value);
-   break;
-   case TOS_NOT_SUPPORTED:
-   /*
-* This is a workaround for an unresolved
-* issue on some machines where system events
-* sporadically become disabled.
-*/
-   hci_result =
-   hci_write1(dev, HCI_SYSTEM_EVENT, 1);
-   pr_notice("Re-enabled hotkeys\n");
-   /* fall through */
-   default:
-   retries--;
-   break;
-   }
-   } while (retries && hci_result != TOS_FIFO_EMPTY);
+   switch (event) {
+   case 0x80: /* Hotkeys and some system events */
+   toshiba_acpi_process_hotkeys(dev);
+   break;
+   case 0x81: /* Unknown */
+   case 0x82: /* Unknown */
+   case 0x83: /* Unknown */
+   case 0x8c: /* Unknown */
+   case 0x8e: /* Unknown */
+   case 0x8f: /* Unknown */
+   case 0x90: /* Unknown */
+   default:
+   pr_info("Unknown event received %x\n", event);
+   break;
}
 }
 
-- 
2.1.2

--
To unsubscribe from this list: send the line "u

[PATCH v3 1/3] toshiba_acpi: Move hotkey enabling code to own function

2014-12-04 Thread Azael Avalos
The hotkey enabling code is being used by
*_setup_keyboard and also by *_resume.

This patch creates a new function called
toshiba_acpi_enable_hotkeys to be used by
these two functions to avoid duplicating
code.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index a329469..8bb07c7 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1573,6 +1573,28 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
return exists ? attr->mode : 0;
 }
 
+/*
+ * Hotkeys
+ */
+static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
+{
+   acpi_status status;
+   u32 result;
+
+   status = acpi_evaluate_object(dev->acpi_dev->handle,
+ "ENAB", NULL, NULL);
+   if (ACPI_FAILURE(status))
+   return -ENODEV;
+
+   result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
+   if (result == TOS_FAILURE)
+   return -EIO;
+   else if (result == TOS_NOT_SUPPORTED)
+   return -ENODEV;
+
+   return 0;
+}
+
 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
  struct serio *port)
 {
@@ -1637,7 +1659,6 @@ static void toshiba_acpi_report_hotkey(struct 
toshiba_acpi_dev *dev,
 
 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
 {
-   acpi_status status;
acpi_handle ec_handle;
int error;
u32 hci_result;
@@ -1664,7 +1685,6 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
 * supported, so if it's present set up an i8042 key filter
 * for this purpose.
 */
-   status = AE_ERROR;
ec_handle = ec_get_handle();
if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
@@ -1695,10 +1715,9 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
goto err_remove_filter;
}
 
-   status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, 
NULL);
-   if (ACPI_FAILURE(status)) {
+   error = toshiba_acpi_enable_hotkeys(dev);
+   if (error) {
pr_info("Unable to enable hotkeys\n");
-   error = -ENODEV;
goto err_remove_filter;
}
 
@@ -1708,7 +1727,6 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
goto err_remove_filter;
}
 
-   hci_result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
return 0;
 
  err_remove_filter:
@@ -2006,16 +2024,12 @@ static int toshiba_acpi_suspend(struct device *device)
 static int toshiba_acpi_resume(struct device *device)
 {
struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
-   u32 result;
-   acpi_status status;
+   int error;
 
if (dev->hotkey_dev) {
-   status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB",
-   NULL, NULL);
-   if (ACPI_FAILURE(status))
+   error = toshiba_acpi_enable_hotkeys(dev);
+   if (error)
pr_info("Unable to re-enable hotkeys\n");
-
-   result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
}
 
return 0;
-- 
2.1.2

--
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/


[PATCH] toshiba_acpi: Change sci_open function return value

2015-01-14 Thread Azael Avalos
Some Toshiba laptops have "poorly implemented" SCI calls on their
BIOSes and are not checking for sci_{open, close} calls, therefore,
the sci_open function is failing and making some of the supported
features unavailable (kbd backlight, touchpad and illumination).

This patch changes the default return code of the sci_open function
to return one instead of zero, making all those faulty laptops load
all the supported features.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index fc34a71..71ac7c12 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -391,9 +391,10 @@ static int sci_open(struct toshiba_acpi_dev *dev)
return 1;
} else if (out[0] == TOS_NOT_PRESENT) {
pr_info("Toshiba SCI is not present\n");
+   return 0;
}
 
-   return 0;
+   return 1;
 }
 
 static void sci_close(struct toshiba_acpi_dev *dev)
-- 
2.2.1

--
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/


[PATCH 3/4] toshiba_acpi: Add support for USB Rapid Charge

2015-01-14 Thread Azael Avalos
Newer Toshiba laptops equipped with USB 3.0 ports now have the
functionality of rapid charging devices connected to their USB hubs.

This patch adds support to use such feature by creating a sysfs entry
named "usb_rapid_charge", accepting only two values, 0 to disable and
one to enable, however, the machine needs a restart everytime the
function is toggled.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 9e054c5..eba5f9e 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -155,6 +155,7 @@ MODULE_LICENSE("GPL");
 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
 #define SCI_USB_CHARGE_BAT_LVL_ON  0x4
 #define SCI_USB_CHARGE_BAT_LVL 0x0200
+#define SCI_USB_CHARGE_RAPID_DSP   0x0300
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -188,6 +189,7 @@ struct toshiba_acpi_dev {
unsigned int eco_supported:1;
unsigned int accelerometer_supported:1;
unsigned int usb_sleep_charge_supported:1;
+   unsigned int usb_rapid_charge_supported:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -874,6 +876,60 @@ static int toshiba_sleep_functions_status_set(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
+static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
+   u32 *state)
+{
+   u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   in[5] = SCI_USB_CHARGE_RAPID_DSP;
+   status = tci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to get USB S&C battery level failed\n");
+   return -EIO;
+   } else if (out[0] == TOS_NOT_SUPPORTED ||
+  out[0] == TOS_INPUT_DATA_ERROR) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   }
+
+   *state = out[2];
+
+   return 0;
+}
+
+static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
+   u32 state)
+{
+   u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   in[2] = state;
+   in[5] = SCI_USB_CHARGE_RAPID_DSP;
+   status = tci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C battery level failed\n");
+   return -EIO;
+   } else if (out[0] == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1439,6 +1495,12 @@ static ssize_t sleep_functions_on_battery_show(struct 
device *dev,
 static ssize_t sleep_functions_on_battery_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count);
+static ssize_t toshiba_usb_rapid_charge_show(struct device *dev,
+struct device_attribute *attr,
+char *buf);
+static ssize_t toshiba_usb_rapid_charge_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count);
 
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
@@ -1456,6 +1518,9 @@ static DEVICE_ATTR(usb_sleep_charge, S_IRUGO | S_IWUSR,
 static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | S_IWUSR,
   sleep_functions_on_battery_show,
   sleep_functions_on_battery_store);
+static DEVICE_ATTR(usb_rapid_charge, S_IRUGO | S_IWUSR,
+  toshiba_usb_rapid_charge_show,
+  toshiba_usb_rapid_charge_store);
 
 static struct attribute *toshiba_attributes[] = {
&dev_attr_kbd_backlight_mode.attr,
@@ -1466,6 +1531,7 @@ static struct attribute *toshiba_attributes[] = {
&dev_attr_position.attr,
&dev_attr_usb_sleep_charge.attr,
&dev_attr_sleep_functions_on_battery.attr,
+   &dev_attr_usb_rapid_charge.attr,
NULL,
 };
 
@@

[PATCH 4/4] toshiba_acpi: Add support for USB Sleep and Music

2015-01-14 Thread Azael Avalos
Newer Toshiba laptops now come with a feature called USB Sleep and
Charge, where the laptop speakers remain powered and the line-in jack
is used to connect an external device to use the laptop speakers.

This patchs adds support to such feature, by creating a sysfs entry
named "usb_sleep_music", accepting parameters zero and one, where
zero disables the feature and one enables it respectively.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index eba5f9e..d107f38 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -124,6 +124,7 @@ MODULE_LICENSE("GPL");
 #define SCI_ILLUMINATION   0x014e
 #define SCI_USB_SLEEP_CHARGE   0x0150
 #define SCI_KBD_ILLUM_STATUS   0x015c
+#define SCI_USB_SLEEP_MUSIC0x015e
 #define SCI_TOUCHPAD   0x050e
 
 /* field definitions */
@@ -190,6 +191,7 @@ struct toshiba_acpi_dev {
unsigned int accelerometer_supported:1;
unsigned int usb_sleep_charge_supported:1;
unsigned int usb_rapid_charge_supported:1;
+   unsigned int usb_sleep_music_supported:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -930,6 +932,50 @@ static int toshiba_usb_rapid_charge_set(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
+static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 
*state)
+{
+   u32 result;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
+   sci_close(dev);
+   if (result == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C mode failed\n");
+   return -EIO;
+   } else if (result == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (result == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
+{
+   u32 result;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
+   sci_close(dev);
+   if (result == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C mode failed\n");
+   return -EIO;
+   } else if (result == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (result == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1501,6 +1547,12 @@ static ssize_t toshiba_usb_rapid_charge_show(struct 
device *dev,
 static ssize_t toshiba_usb_rapid_charge_store(struct device *dev,
  struct device_attribute *attr,
  const char *buf, size_t count);
+static ssize_t toshiba_usb_sleep_music_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf);
+static ssize_t toshiba_usb_sleep_music_store(struct device *dev,
+struct device_attribute *attr,
+const char *buf, size_t count);
 
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
@@ -1521,6 +1573,9 @@ static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | 
S_IWUSR,
 static DEVICE_ATTR(usb_rapid_charge, S_IRUGO | S_IWUSR,
   toshiba_usb_rapid_charge_show,
   toshiba_usb_rapid_charge_store);
+static DEVICE_ATTR(usb_sleep_music, S_IRUGO | S_IWUSR,
+  toshiba_usb_sleep_music_show,
+  toshiba_usb_sleep_music_store);
 
 static struct attribute *toshiba_attributes[] = {
&dev_attr_kbd_backlight_mode.attr,
@@ -1532,6 +1587,7 @@ static struct attribute *toshiba_attributes[] = {
&dev_attr_usb_sleep_charge.attr,
&dev_attr_sleep_functions_on_battery.attr,
&dev_attr_usb_rapid_charge.attr,
+   &dev_attr_usb_sleep_music.attr,
NULL,
 };
 
@@ -1890,6 +1946,42 @@ static ssize_t toshiba_usb_rapid_charge_store(struct 
device *dev,
return count;
 }
 
+static ssize_t toshiba_usb_sleep_music_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
+  

[PATCH 1/4] toshiba_acpi: Add support for USB Sleep and Charge function

2015-01-14 Thread Azael Avalos
Newer Toshiba models now come with a feature called Sleep and Charge,
where the computer USB ports remain powered when the computer is
asleep or turned off.

This patch adds support to such feature, creating a sysfs entry
called "usb_sleep_charge" to set the desired charging mode or to
disable it.

The sysfs entry accepts three parameters, 0x0, 0x9 and 0x21, beign
disabled, alternate and auto respectively.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 71ac7c12..b03129d 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -122,6 +122,7 @@ MODULE_LICENSE("GPL");
 #define HCI_ECO_MODE   0x0097
 #define HCI_ACCELEROMETER2 0x00a6
 #define SCI_ILLUMINATION   0x014e
+#define SCI_USB_SLEEP_CHARGE   0x0150
 #define SCI_KBD_ILLUM_STATUS   0x015c
 #define SCI_TOUCHPAD   0x050e
 
@@ -146,6 +147,10 @@ MODULE_LICENSE("GPL");
 #define SCI_KBD_MODE_ON0x8
 #define SCI_KBD_MODE_OFF   0x10
 #define SCI_KBD_TIME_MAX   0x3c001a
+#define SCI_USB_CHARGE_MODE_MASK   0xff
+#define SCI_USB_CHARGE_DISABLED0x3
+#define SCI_USB_CHARGE_ALTERNATE   0x30009
+#define SCI_USB_CHARGE_AUTO0x30021
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -177,6 +182,7 @@ struct toshiba_acpi_dev {
unsigned int touchpad_supported:1;
unsigned int eco_supported:1;
unsigned int accelerometer_supported:1;
+   unsigned int usb_sleep_charge_supported:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -761,6 +767,53 @@ static int toshiba_accelerometer_get(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
+/* Sleep (Charge and Music) utilities support */
+static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
+   u32 *mode)
+{
+   u32 result;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
+   sci_close(dev);
+   if (result == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C mode failed\n");
+   return -EIO;
+   } else if (result == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (result == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
+   u32 mode)
+{
+   u32 result;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
+   sci_close(dev);
+   if (result == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C mode failed\n");
+   return -EIO;
+   } else if (result == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (result == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1314,6 +1367,12 @@ static ssize_t toshiba_touchpad_show(struct device *dev,
 static ssize_t toshiba_position_show(struct device *dev,
 struct device_attribute *attr,
 char *buf);
+static ssize_t toshiba_usb_sleep_charge_show(struct device *dev,
+struct device_attribute *attr,
+char *buf);
+static ssize_t toshiba_usb_sleep_charge_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count);
 
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
@@ -1325,6 +1384,9 @@ static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | 
S_IWUSR,
 static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
   toshiba_touchpad_show, toshiba_touchpad_store);
 static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
+static DEVICE_ATTR(usb_sleep_charge, S_IRUGO | S_IWUSR,
+  toshiba_usb_sleep_charge_show,
+  toshiba_usb_sleep_charge_store);
 
 static struct attribute *toshiba_attributes[] = {
&dev_attr_kbd_backlight_mode.attr,
@@ -1333,6 +1395,7 @@ static struct attribute *toshiba_attributes[]

[PATCH 2/4] toshiba_acpi: Add support for USB Sleep functions under battery

2015-01-14 Thread Azael Avalos
Toshiba laptops supporting USB Sleep and Charge also come with a
feature called "USB functions under battery", which what it does when
enabled, is allows the USB Sleep functions when the computer is under
battery power.

This patch adds support to that function, creating a sysfs entry
named "sleep_functions_on_battery", accepting values from 0-100,
where zero disables the function and 1-100 sets the battery level at
which point the USB Sleep functions will be disabled, and printing
the current state of the functon and also the battery level currently
set.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index b03129d..9e054c5 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -151,6 +151,10 @@ MODULE_LICENSE("GPL");
 #define SCI_USB_CHARGE_DISABLED0x3
 #define SCI_USB_CHARGE_ALTERNATE   0x30009
 #define SCI_USB_CHARGE_AUTO0x30021
+#define SCI_USB_CHARGE_BAT_MASK0x7
+#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
+#define SCI_USB_CHARGE_BAT_LVL_ON  0x4
+#define SCI_USB_CHARGE_BAT_LVL 0x0200
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -169,6 +173,7 @@ struct toshiba_acpi_dev {
int kbd_type;
int kbd_mode;
int kbd_time;
+   int usbsc_bat_level;
 
unsigned int illumination_supported:1;
unsigned int video_supported:1;
@@ -814,6 +819,61 @@ static int toshiba_usb_sleep_charge_set(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
+static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
+ u32 *mode)
+{
+   u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   in[5] = SCI_USB_CHARGE_BAT_LVL;
+   status = tci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to get USB S&C battery level failed\n");
+   return -EIO;
+   } else if (out[0] == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   *mode = out[2];
+
+   return 0;
+}
+
+static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
+ u32 mode)
+{
+   u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   in[2] = mode;
+   in[5] = SCI_USB_CHARGE_BAT_LVL;
+   status = tci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C battery level failed\n");
+   return -EIO;
+   } else if (out[0] == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1373,6 +1433,12 @@ static ssize_t toshiba_usb_sleep_charge_show(struct 
device *dev,
 static ssize_t toshiba_usb_sleep_charge_store(struct device *dev,
  struct device_attribute *attr,
  const char *buf, size_t count);
+static ssize_t sleep_functions_on_battery_show(struct device *dev,
+  struct device_attribute *attr,
+  char *buf);
+static ssize_t sleep_functions_on_battery_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count);
 
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
@@ -1387,6 +1453,9 @@ static DEVICE_ATTR(position, S_IRUGO, 
toshiba_position_show, NULL);
 static DEVICE_ATTR(usb_sleep_charge, S_IRUGO | S_IWUSR,
   toshiba_usb_sleep_charge_show,
   toshiba_usb_sleep_charge_store);
+static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | S_IWUSR,
+  sleep_functions_on_battery_show,
+  sleep_functions_on_battery_store);
 
 static struct attribute *

[PATCH 0/4] toshiba_acpi: Add support for USB Sleep functions

2015-01-14 Thread Azael Avalos
The following patches add support to several USB Sleep functions
found on newer Toshiba laptops, allowing to use th USB ports while
the laptop is asleep or turned off.

Azael Avalos (4):
  toshiba_acpi: Add support for USB Sleep and Charge function
  toshiba_acpi: Add support for USB Sleep functions under battery
  toshiba_acpi: Add support for USB Rapid Charge
  toshiba_acpi: Add support for USB Sleep and Music

 drivers/platform/x86/toshiba_acpi.c | 449 
 1 file changed, 449 insertions(+)

-- 
2.2.1

--
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/


[PATCH v2 0/4] toshiba_acpi: Add support for USB Sleep functions

2015-01-18 Thread Azael Avalos
The following patches add support to several USB Sleep functions
found on newer Toshiba laptops, allowing to use the USB ports while
the laptop is asleep or turned off.

Changes since v1:
- Changed accepted parameters on first patch and added a short
  description of what the auto and alternate charging modes mean
- Some misc format and typo changes

Azael Avalos (4):
  toshiba_acpi: Add support for USB Sleep and Charge function
  toshiba_acpi: Add support for USB Sleep functions under battery
  toshiba_acpi: Add support for USB Rapid Charge
  toshiba_acpi: Add support for USB Sleep and Music

 drivers/platform/x86/toshiba_acpi.c | 455 
 1 file changed, 455 insertions(+)

-- 
2.2.1

--
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/


[PATCH v2 1/4] toshiba_acpi: Add support for USB Sleep and Charge function

2015-01-18 Thread Azael Avalos
Newer Toshiba models now come with a feature called Sleep and Charge,
where the computer USB ports remain powered when the computer is
asleep or turned off.

This patch adds support to such feature, creating a sysfs entry
called "usb_sleep_charge" to set the desired charging mode or to
disable it.

The sysfs entry accepts three parameters, 0, 1 and 2, beign disabled,
alternate and auto respectively.

The auto mode stands for USB conformant devices (which most are), and
the alternate mode stands for those non USB conformant devices that
require more power.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 71ac7c12..cf2faca 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -122,6 +122,7 @@ MODULE_LICENSE("GPL");
 #define HCI_ECO_MODE   0x0097
 #define HCI_ACCELEROMETER2 0x00a6
 #define SCI_ILLUMINATION   0x014e
+#define SCI_USB_SLEEP_CHARGE   0x0150
 #define SCI_KBD_ILLUM_STATUS   0x015c
 #define SCI_TOUCHPAD   0x050e
 
@@ -146,6 +147,10 @@ MODULE_LICENSE("GPL");
 #define SCI_KBD_MODE_ON0x8
 #define SCI_KBD_MODE_OFF   0x10
 #define SCI_KBD_TIME_MAX   0x3c001a
+#define SCI_USB_CHARGE_MODE_MASK   0xff
+#define SCI_USB_CHARGE_DISABLED0x3
+#define SCI_USB_CHARGE_ALTERNATE   0x30009
+#define SCI_USB_CHARGE_AUTO0x30021
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -177,6 +182,7 @@ struct toshiba_acpi_dev {
unsigned int touchpad_supported:1;
unsigned int eco_supported:1;
unsigned int accelerometer_supported:1;
+   unsigned int usb_sleep_charge_supported:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -761,6 +767,53 @@ static int toshiba_accelerometer_get(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
+/* Sleep (Charge and Music) utilities support */
+static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
+   u32 *mode)
+{
+   u32 result;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
+   sci_close(dev);
+   if (result == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C mode failed\n");
+   return -EIO;
+   } else if (result == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (result == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
+   u32 mode)
+{
+   u32 result;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
+   sci_close(dev);
+   if (result == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C mode failed\n");
+   return -EIO;
+   } else if (result == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (result == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1314,6 +1367,12 @@ static ssize_t toshiba_touchpad_show(struct device *dev,
 static ssize_t toshiba_position_show(struct device *dev,
 struct device_attribute *attr,
 char *buf);
+static ssize_t toshiba_usb_sleep_charge_show(struct device *dev,
+struct device_attribute *attr,
+char *buf);
+static ssize_t toshiba_usb_sleep_charge_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count);
 
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
@@ -1325,6 +1384,9 @@ static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | 
S_IWUSR,
 static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
   toshiba_touchpad_show, toshiba_touchpad_store);
 static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
+static DEVICE_ATTR(usb_sleep_charge, S_IRUGO | S_IWUSR,
+  toshiba_usb_sleep_charge_show,
+  toshiba_usb_sleep_charge_store);
 
 static struct attribute *toshiba_attributes

[PATCH v2 3/4] toshiba_acpi: Add support for USB Rapid Charge

2015-01-18 Thread Azael Avalos
Newer Toshiba laptops equipped with USB 3.0 ports now have the
functionality of rapid charging devices connected to their USB hubs.

This patch adds support to use such feature by creating a sysfs entry
named "usb_rapid_charge", accepting only two values, 0 to disable and
1 to enable, however, the machine needs a restart everytime the
function is toggled.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 3b6e952..ab08d00 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -155,6 +155,7 @@ MODULE_LICENSE("GPL");
 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
 #define SCI_USB_CHARGE_BAT_LVL_ON  0x4
 #define SCI_USB_CHARGE_BAT_LVL 0x0200
+#define SCI_USB_CHARGE_RAPID_DSP   0x0300
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -188,6 +189,7 @@ struct toshiba_acpi_dev {
unsigned int eco_supported:1;
unsigned int accelerometer_supported:1;
unsigned int usb_sleep_charge_supported:1;
+   unsigned int usb_rapid_charge_supported:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -874,6 +876,60 @@ static int toshiba_sleep_functions_status_set(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
+static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
+   u32 *state)
+{
+   u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   in[5] = SCI_USB_CHARGE_RAPID_DSP;
+   status = tci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to get USB S&C battery level failed\n");
+   return -EIO;
+   } else if (out[0] == TOS_NOT_SUPPORTED ||
+  out[0] == TOS_INPUT_DATA_ERROR) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   }
+
+   *state = out[2];
+
+   return 0;
+}
+
+static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
+   u32 state)
+{
+   u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   in[2] = state;
+   in[5] = SCI_USB_CHARGE_RAPID_DSP;
+   status = tci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C battery level failed\n");
+   return -EIO;
+   } else if (out[0] == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1439,6 +1495,12 @@ static ssize_t sleep_functions_on_battery_show(struct 
device *dev,
 static ssize_t sleep_functions_on_battery_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count);
+static ssize_t toshiba_usb_rapid_charge_show(struct device *dev,
+struct device_attribute *attr,
+char *buf);
+static ssize_t toshiba_usb_rapid_charge_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count);
 
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
@@ -1456,6 +1518,9 @@ static DEVICE_ATTR(usb_sleep_charge, S_IRUGO | S_IWUSR,
 static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | S_IWUSR,
   sleep_functions_on_battery_show,
   sleep_functions_on_battery_store);
+static DEVICE_ATTR(usb_rapid_charge, S_IRUGO | S_IWUSR,
+  toshiba_usb_rapid_charge_show,
+  toshiba_usb_rapid_charge_store);
 
 static struct attribute *toshiba_attributes[] = {
&dev_attr_kbd_backlight_mode.attr,
@@ -1466,6 +1531,7 @@ static struct attribute *toshiba_attributes[] = {
&dev_attr_position.attr,
&dev_attr_usb_sleep_charge.attr,
&dev_attr_sleep_functions_on_battery.attr,
+   &dev_attr_usb_rapid_charge.attr,
NULL,
 };
 
@@

[PATCH v2 4/4] toshiba_acpi: Add support for USB Sleep and Music

2015-01-18 Thread Azael Avalos
Newer Toshiba laptops now come with a feature called USB Sleep and
Music, where the laptop speakers remain powered and the line-in jack
is used to connect an external device to use the laptop speakers when
the computer is asleep or turned off.

This patchs adds support to such feature, by creating a sysfs entry
named "usb_sleep_music", accepting only two values, 0 to disable and
1 to enable.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index ab08d00..4811a90 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -124,6 +124,7 @@ MODULE_LICENSE("GPL");
 #define SCI_ILLUMINATION   0x014e
 #define SCI_USB_SLEEP_CHARGE   0x0150
 #define SCI_KBD_ILLUM_STATUS   0x015c
+#define SCI_USB_SLEEP_MUSIC0x015e
 #define SCI_TOUCHPAD   0x050e
 
 /* field definitions */
@@ -190,6 +191,7 @@ struct toshiba_acpi_dev {
unsigned int accelerometer_supported:1;
unsigned int usb_sleep_charge_supported:1;
unsigned int usb_rapid_charge_supported:1;
+   unsigned int usb_sleep_music_supported:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -930,6 +932,50 @@ static int toshiba_usb_rapid_charge_set(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
+static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 
*state)
+{
+   u32 result;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
+   sci_close(dev);
+   if (result == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C mode failed\n");
+   return -EIO;
+   } else if (result == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (result == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
+{
+   u32 result;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
+   sci_close(dev);
+   if (result == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C mode failed\n");
+   return -EIO;
+   } else if (result == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (result == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1501,6 +1547,12 @@ static ssize_t toshiba_usb_rapid_charge_show(struct 
device *dev,
 static ssize_t toshiba_usb_rapid_charge_store(struct device *dev,
  struct device_attribute *attr,
  const char *buf, size_t count);
+static ssize_t toshiba_usb_sleep_music_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf);
+static ssize_t toshiba_usb_sleep_music_store(struct device *dev,
+struct device_attribute *attr,
+const char *buf, size_t count);
 
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
@@ -1521,6 +1573,9 @@ static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | 
S_IWUSR,
 static DEVICE_ATTR(usb_rapid_charge, S_IRUGO | S_IWUSR,
   toshiba_usb_rapid_charge_show,
   toshiba_usb_rapid_charge_store);
+static DEVICE_ATTR(usb_sleep_music, S_IRUGO | S_IWUSR,
+  toshiba_usb_sleep_music_show,
+  toshiba_usb_sleep_music_store);
 
 static struct attribute *toshiba_attributes[] = {
&dev_attr_kbd_backlight_mode.attr,
@@ -1532,6 +1587,7 @@ static struct attribute *toshiba_attributes[] = {
&dev_attr_usb_sleep_charge.attr,
&dev_attr_sleep_functions_on_battery.attr,
&dev_attr_usb_rapid_charge.attr,
+   &dev_attr_usb_sleep_music.attr,
NULL,
 };
 
@@ -1896,6 +1952,42 @@ static ssize_t toshiba_usb_rapid_charge_store(struct 
device *dev,
return count;
 }
 
+static ssize_t toshiba_usb_sleep_music_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
+   u32 state;
+

[PATCH v2 2/4] toshiba_acpi: Add support for USB Sleep functions under battery

2015-01-18 Thread Azael Avalos
Toshiba laptops supporting USB Sleep and Charge also come with a
feature called "USB functions under battery", which what it does when
enabled, is allows the USB Sleep functions when the computer is under
battery power.

This patch adds support to that function, creating a sysfs entry
named "sleep_functions_on_battery", accepting values from 0-100,
where zero disables the function and 1-100 sets the battery level at
which point the USB Sleep functions will be disabled, and printing
the current state of the functon and also the battery level currently
set.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index cf2faca..3b6e952 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -151,6 +151,10 @@ MODULE_LICENSE("GPL");
 #define SCI_USB_CHARGE_DISABLED0x3
 #define SCI_USB_CHARGE_ALTERNATE   0x30009
 #define SCI_USB_CHARGE_AUTO0x30021
+#define SCI_USB_CHARGE_BAT_MASK0x7
+#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
+#define SCI_USB_CHARGE_BAT_LVL_ON  0x4
+#define SCI_USB_CHARGE_BAT_LVL 0x0200
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -169,6 +173,7 @@ struct toshiba_acpi_dev {
int kbd_type;
int kbd_mode;
int kbd_time;
+   int usbsc_bat_level;
 
unsigned int illumination_supported:1;
unsigned int video_supported:1;
@@ -814,6 +819,61 @@ static int toshiba_usb_sleep_charge_set(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
+static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
+ u32 *mode)
+{
+   u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   in[5] = SCI_USB_CHARGE_BAT_LVL;
+   status = tci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to get USB S&C battery level failed\n");
+   return -EIO;
+   } else if (out[0] == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   *mode = out[2];
+
+   return 0;
+}
+
+static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
+ u32 mode)
+{
+   u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   in[2] = mode;
+   in[5] = SCI_USB_CHARGE_BAT_LVL;
+   status = tci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to set USB S&C battery level failed\n");
+   return -EIO;
+   } else if (out[0] == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   return -ENODEV;
+   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return -EIO;
+   }
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1373,6 +1433,12 @@ static ssize_t toshiba_usb_sleep_charge_show(struct 
device *dev,
 static ssize_t toshiba_usb_sleep_charge_store(struct device *dev,
  struct device_attribute *attr,
  const char *buf, size_t count);
+static ssize_t sleep_functions_on_battery_show(struct device *dev,
+  struct device_attribute *attr,
+  char *buf);
+static ssize_t sleep_functions_on_battery_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count);
 
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
@@ -1387,6 +1453,9 @@ static DEVICE_ATTR(position, S_IRUGO, 
toshiba_position_show, NULL);
 static DEVICE_ATTR(usb_sleep_charge, S_IRUGO | S_IWUSR,
   toshiba_usb_sleep_charge_show,
   toshiba_usb_sleep_charge_store);
+static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | S_IWUSR,
+  sleep_functions_on_battery_show,
+  sleep_functions_on_battery_store);
 
 static struct attribute *

[PATCH] toshiba_acpi: Add a check for TOS_NOT_SUPPORTED in the sci_open function

2015-01-18 Thread Azael Avalos
This was "toshiba_acpi: Change sci_open function return value"

Some Toshiba laptops have "poorly implemented" SCI calls on their
BIOSes and are not checking for sci_{open, close} calls, therefore,
the sci_open function is failing and making some of the supported
features unavailable (kbd backlight, touchpad, illumination, etc.).

This patch checks wheter we receive TOS_NOT_SUPPORTED and returns
1, making the supported features work on such laptops.

In the case that some laptops really do not support the SCI, all the
SCI dependent functions check for TOS_NOT_SUPPORTED, and thus, not
registering support for the queried feature.

Signed-off-by: Azael Avalos 
---
Darren,

Hopefully this new patch eases some of the concerns of the previous
patch, and this time I added a comment block explaining a bit, but of
course, let me know if there is something else that needs change.

Cheers
Azael

 drivers/platform/x86/toshiba_acpi.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index fc34a71..899ead6b 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -389,6 +389,19 @@ static int sci_open(struct toshiba_acpi_dev *dev)
} else if (out[0] == TOS_ALREADY_OPEN) {
pr_info("Toshiba SCI already opened\n");
return 1;
+   } else if (out[0] == TOS_NOT_SUPPORTED) {
+   /* Some BIOSes do not have the SCI open/close functions
+* implemented and return 0x8000 (Not Supported), failing to
+* register some supported features.
+*
+* Simply return 1 if we hit those affected laptops to make the
+* supported features work.
+*
+* In the case that some laptops really do not support the SCI,
+* all the SCI dependent functions check for TOS_NOT_SUPPORTED,
+* and thus, not registering support for the queried feature.
+*/
+   return 1;
} else if (out[0] == TOS_NOT_PRESENT) {
pr_info("Toshiba SCI is not present\n");
}
-- 
2.2.1

--
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/


Re: [PATCH] toshiba_acpi: Add a check for TOS_NOT_SUPPORTED in the sci_open function

2015-01-26 Thread Azael Avalos
Hi Darren,

Any input on this patch?

2015-01-18 19:17 GMT-07:00 Azael Avalos :
> This was "toshiba_acpi: Change sci_open function return value"
>
> Some Toshiba laptops have "poorly implemented" SCI calls on their
> BIOSes and are not checking for sci_{open, close} calls, therefore,
> the sci_open function is failing and making some of the supported
> features unavailable (kbd backlight, touchpad, illumination, etc.).
>
> This patch checks wheter we receive TOS_NOT_SUPPORTED and returns
> 1, making the supported features work on such laptops.
>
> In the case that some laptops really do not support the SCI, all the
> SCI dependent functions check for TOS_NOT_SUPPORTED, and thus, not
> registering support for the queried feature.
>
> Signed-off-by: Azael Avalos 
> ---
> Darren,
>
> Hopefully this new patch eases some of the concerns of the previous
> patch, and this time I added a comment block explaining a bit, but of
> course, let me know if there is something else that needs change.
>
> Cheers
> Azael
>
>  drivers/platform/x86/toshiba_acpi.c | 13 +
>  1 file changed, 13 insertions(+)
>
> diff --git a/drivers/platform/x86/toshiba_acpi.c 
> b/drivers/platform/x86/toshiba_acpi.c
> index fc34a71..899ead6b 100644
> --- a/drivers/platform/x86/toshiba_acpi.c
> +++ b/drivers/platform/x86/toshiba_acpi.c
> @@ -389,6 +389,19 @@ static int sci_open(struct toshiba_acpi_dev *dev)
> } else if (out[0] == TOS_ALREADY_OPEN) {
> pr_info("Toshiba SCI already opened\n");
> return 1;
> +   } else if (out[0] == TOS_NOT_SUPPORTED) {
> +   /* Some BIOSes do not have the SCI open/close functions
> +* implemented and return 0x8000 (Not Supported), failing to
> +* register some supported features.
> +*
> +* Simply return 1 if we hit those affected laptops to make 
> the
> +* supported features work.
> +*
> +* In the case that some laptops really do not support the 
> SCI,
> +* all the SCI dependent functions check for 
> TOS_NOT_SUPPORTED,
> +* and thus, not registering support for the queried feature.
> +*/
> +   return 1;
> } else if (out[0] == TOS_NOT_PRESENT) {
> pr_info("Toshiba SCI is not present\n");
> }
> --
> 2.2.1
>



-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


[PATCH v2 1/3] toshiba_acpi: Add Hotkey Event Type function and definitions

2015-03-20 Thread Azael Avalos
This patch adds support to query the "Hotkey Event Type" the system
supports.

There are two main event types (so far), 0x10 and 0x11, with the
first being all those laptops that have the old keyboard layout, and
the latter all those new laptops with the new keyboard layout.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index dbcb7a8..c4edae3 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -116,6 +116,7 @@ MODULE_LICENSE("GPL");
 #define HCI_KBD_ILLUMINATION   0x0095
 #define HCI_ECO_MODE   0x0097
 #define HCI_ACCELEROMETER2 0x00a6
+#define HCI_SYSTEM_INFO0xc000
 #define SCI_PANEL_POWER_ON 0x010d
 #define SCI_ILLUMINATION   0x014e
 #define SCI_USB_SLEEP_CHARGE   0x0150
@@ -133,6 +134,8 @@ MODULE_LICENSE("GPL");
 #define HCI_LCD_BRIGHTNESS_SHIFT   (16-HCI_LCD_BRIGHTNESS_BITS)
 #define HCI_LCD_BRIGHTNESS_LEVELS  (1 << HCI_LCD_BRIGHTNESS_BITS)
 #define HCI_MISC_SHIFT 0x10
+#define HCI_SYSTEM_TYPE1   0x10
+#define HCI_SYSTEM_TYPE2   0x11
 #define HCI_VIDEO_OUT_LCD  0x1
 #define HCI_VIDEO_OUT_CRT  0x2
 #define HCI_VIDEO_OUT_TV   0x4
@@ -1149,6 +1152,28 @@ static int toshiba_usb_three_set(struct toshiba_acpi_dev 
*dev, u32 state)
return 0;
 }
 
+/* Hotkey Event type */
+static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
+u32 *type)
+{
+   u32 val1 = 0x03;
+   u32 val2 = 0;
+   u32 result;
+
+   result = hci_read2(dev, HCI_SYSTEM_INFO, &val1, &val2);
+   if (result == TOS_FAILURE) {
+   pr_err("ACPI call to get System type failed\n");
+   return -EIO;
+   } else if (result == TOS_NOT_SUPPORTED) {
+   pr_info("System type not supported\n");
+   return -ENODEV;
+   }
+
+   *type = val2;
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
-- 
2.2.2

--
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/


[PATCH v2 0/3] toshiba_acpi: Hotkey handling and keymap updates

2015-03-20 Thread Azael Avalos
These patches add support to a new function that queries the supported Hotkey
Event Type, making the use of the DMI matching unnecessary and also fixes
the "Special Functions" mode on some laptops.

Changes since v1:
- Renamed HCI_HOTKEY_EVENT_TYPE to HCI_SYSTEM_INFO definition to
  better reflect what the call does, and also the HCI_HOTKEY_EVENT_*
  types
- Fixed a typo in the error description
- Added a comment block explaining a bit why we also use the "Special
  Functions" as a check for keymap selection

Azael Avalos (3):
  toshiba_acpi: Add Hotkey Event Type function and definitions
  toshiba_acpi: Use the Hotkey Event Type function for keymap choosing
  toshiba_acpi: Fix the enabling of the Special Functions

 drivers/platform/x86/toshiba_acpi.c | 118 
 1 file changed, 80 insertions(+), 38 deletions(-)

-- 
2.2.2

--
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/


[PATCH v2 2/3] toshiba_acpi: Use the Hotkey Event Type function for keymap choosing

2015-03-20 Thread Azael Avalos
With the previous patch adding support to "Hotkey Event Type", we can
now use the type to distinguish which keymap to use.

This patch changes the toshiba_acpi_setup_keyboard function to make
use of the hotkey event type to choose the correct keymap without the
need to use the DMI matching list.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index c4edae3..d7dac48 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -49,7 +49,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 MODULE_AUTHOR("John Belmonte");
@@ -177,6 +176,7 @@ struct toshiba_acpi_dev {
int kbd_mode;
int kbd_time;
int usbsc_bat_level;
+   int hotkey_event_type;
 
unsigned int illumination_supported:1;
unsigned int video_supported:1;
@@ -246,29 +246,6 @@ static const struct key_entry toshiba_acpi_keymap[] = {
{ KE_END, 0 },
 };
 
-/* alternative keymap */
-static const struct dmi_system_id toshiba_alt_keymap_dmi[] = {
-   {
-   .matches = {
-   DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
-   DMI_MATCH(DMI_PRODUCT_NAME, "Satellite M840"),
-   },
-   },
-   {
-   .matches = {
-   DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
-   DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"),
-   },
-   },
-   {
-   .matches = {
-   DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
-   DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A50-A"),
-   },
-   },
-   {}
-};
-
 static const struct key_entry toshiba_acpi_alt_keymap[] = {
{ KE_KEY, 0x157, { KEY_MUTE } },
{ KE_KEY, 0x102, { KEY_ZOOMOUT } },
@@ -2459,10 +2436,22 @@ static void toshiba_acpi_process_hotkeys(struct 
toshiba_acpi_dev *dev)
 
 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
 {
+   const struct key_entry *keymap = toshiba_acpi_keymap;
acpi_handle ec_handle;
-   int error;
+   u32 events_type;
u32 hci_result;
-   const struct key_entry *keymap = toshiba_acpi_keymap;
+   int error;
+
+   error = toshiba_acpi_enable_hotkeys(dev);
+   if (error)
+   return error;
+
+   error = toshiba_hotkey_event_type_get(dev, &events_type);
+   if (error) {
+   pr_err("Unable to query Hotkey Event Type\n");
+   return error;
+   }
+   dev->hotkey_event_type = events_type;
 
dev->hotkey_dev = input_allocate_device();
if (!dev->hotkey_dev)
@@ -2472,8 +2461,14 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
dev->hotkey_dev->phys = "toshiba_acpi/input0";
dev->hotkey_dev->id.bustype = BUS_HOST;
 
-   if (dmi_check_system(toshiba_alt_keymap_dmi))
+   if (events_type == HCI_SYSTEM_TYPE1 ||
+   !dev->kbd_function_keys_supported)
+   keymap = toshiba_acpi_keymap;
+   else if (events_type == HCI_SYSTEM_TYPE2 ||
+dev->kbd_function_keys_supported)
keymap = toshiba_acpi_alt_keymap;
+   else
+   pr_info("Unknown event type received %x\n", events_type);
error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
if (error)
goto err_free_dev;
@@ -2515,12 +2510,6 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
goto err_remove_filter;
}
 
-   error = toshiba_acpi_enable_hotkeys(dev);
-   if (error) {
-   pr_info("Unable to enable hotkeys\n");
-   goto err_remove_filter;
-   }
-
error = input_register_device(dev->hotkey_dev);
if (error) {
pr_info("Unable to register input device\n");
@@ -2673,6 +2662,16 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
acpi_dev->driver_data = dev;
dev_set_drvdata(&acpi_dev->dev, dev);
 
+   /* Query the BIOS for supported features */
+
+   /*
+* The "Special Functions" are always supported by the laptops
+* with the new keyboard layout, query for its presence to help
+* determine the keymap layout to use.
+*/
+   ret = toshiba_function_keys_get(dev, &dummy);
+   dev->kbd_function_keys_supported = !ret;
+
if (toshiba_acpi_setup_keyboard(dev))
pr_info("Unable to activate hotkeys\n");
 
@@ -2750,17 +2749,12 @@ static int toshiba_acpi_add(struct acpi_device 
*acpi_dev)
ret = tos

[PATCH v2 3/3] toshiba_acpi: Fix the enabling of the Special Functions

2015-03-20 Thread Azael Avalos
Some Toshiba laptops with the "Special Functions" feature enabled
fail to properly enable such feature unless a specific value is
used to enable the hotkey events.

This patch adds a new function called "*_enable_special_functions",
that simply makes a call to the HCI_HOTKEY_EVENT call, but this time
we are using a different parameter to make the "Special Functions"
mode work as expected.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index d7dac48..49ac73a 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -129,6 +129,7 @@ MODULE_LICENSE("GPL");
 #define HCI_ACCEL_MASK 0x7fff
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
+#define HCI_HOTKEY_SPECIAL_FUNCTIONS   0x10
 #define HCI_LCD_BRIGHTNESS_BITS3
 #define HCI_LCD_BRIGHTNESS_SHIFT   (16-HCI_LCD_BRIGHTNESS_BITS)
 #define HCI_LCD_BRIGHTNESS_LEVELS  (1 << HCI_LCD_BRIGHTNESS_BITS)
@@ -2334,6 +2335,20 @@ static int toshiba_acpi_enable_hotkeys(struct 
toshiba_acpi_dev *dev)
 
return 0;
 }
+
+static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev)
+{
+   u32 result;
+
+   /*
+* Re-activate the hotkeys, but this time, we are using the
+* "Special Functions" mode.
+*/
+   result = hci_write1(dev, HCI_HOTKEY_EVENT,
+   HCI_HOTKEY_SPECIAL_FUNCTIONS);
+   if (result != TOS_SUCCESS)
+   pr_err("Could not enable the Special Function mode\n");
+}
 
 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
  struct serio *port)
@@ -2638,6 +2653,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 {
struct toshiba_acpi_dev *dev;
const char *hci_method;
+   u32 special_functions;
u32 dummy;
bool bt_present;
int ret = 0;
@@ -2669,7 +2685,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 * with the new keyboard layout, query for its presence to help
 * determine the keymap layout to use.
 */
-   ret = toshiba_function_keys_get(dev, &dummy);
+   ret = toshiba_function_keys_get(dev, &special_functions);
dev->kbd_function_keys_supported = !ret;
 
if (toshiba_acpi_setup_keyboard(dev))
@@ -2761,6 +2777,13 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
ret = get_fan_status(dev, &dummy);
dev->fan_supported = !ret;
 
+   /*
+* Enable the "Special Functions" mode only if they are
+* supported and if they are activated.
+*/
+   if (dev->kbd_function_keys_supported && special_functions)
+   toshiba_acpi_enable_special_functions(dev);
+
ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
 &toshiba_attr_group);
if (ret) {
-- 
2.2.2

--
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/


Re: [PATCH v2 1/3] toshiba_acpi: Update and fix USB Sleep and Charge modes

2015-04-02 Thread Azael Avalos
Hi Darren,

2015-04-01 23:21 GMT-06:00 Darren Hart :
> On Sun, Mar 29, 2015 at 07:25:39PM -0600, Azael Avalos wrote:
>> This patch fixes the USB Sleep and Charge mode on certain models
>> where the value returned by the BIOS is different, and thus, making
>> this feature not to work for those models.
>>
>> Also, the "Typical" charging mode was added as a supported mode.
>>
>> Signed-off-by: Azael Avalos 
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 69 
>> -
>>  1 file changed, 60 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index 17a259e..c8ad61c 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -150,9 +150,10 @@ MODULE_LICENSE("GPL");
>>  #define SCI_KBD_MODE_OFF 0x10
>>  #define SCI_KBD_TIME_MAX 0x3c001a
>>  #define SCI_USB_CHARGE_MODE_MASK 0xff
>> -#define SCI_USB_CHARGE_DISABLED  0x3
>> -#define SCI_USB_CHARGE_ALTERNATE 0x30009
>> -#define SCI_USB_CHARGE_AUTO  0x30021
>> +#define SCI_USB_CHARGE_DISABLED  0x00
>> +#define SCI_USB_CHARGE_ALTERNATE 0x09
>> +#define SCI_USB_CHARGE_TYPICAL   0x11
>> +#define SCI_USB_CHARGE_AUTO  0x21
>>  #define SCI_USB_CHARGE_BAT_MASK  0x7
>>  #define SCI_USB_CHARGE_BAT_LVL_OFF   0x1
>>  #define SCI_USB_CHARGE_BAT_LVL_ON0x4
>> @@ -177,6 +178,7 @@ struct toshiba_acpi_dev {
>>   int kbd_mode;
>>   int kbd_time;
>>   int usbsc_bat_level;
>> + int usbsc_mode_base;
>>   int hotkey_event_type;
>>
>>   unsigned int illumination_supported:1;
>> @@ -800,6 +802,52 @@ static int toshiba_accelerometer_get(struct 
>> toshiba_acpi_dev *dev,
>>  }
>>
>>  /* Sleep (Charge and Music) utilities support */
>> +static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
>> +{
>> + u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
>> + u32 out[TCI_WORDS];
>> + acpi_status status;
>> +
>> + /* Set the feature to "not supported" in case of error */
>> + dev->usb_sleep_charge_supported = 0;
>> +
>> + if (!sci_open(dev))
>> + return;
>> +
>> + status = tci_raw(dev, in, out);
>> + if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
>> + pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
>> + sci_close(dev);
>> + return;
>> + } else if (out[0] == TOS_NOT_SUPPORTED) {
>> + pr_info("USB Sleep and Charge not supported\n");
>> + sci_close(dev);
>> + return;
>> + }
>
> Sorry Azael for not asking the first time, and maybe this is just how it is -
> but it occurs to me that after the above tci_raw call, we check for 3 error
> cases, but we never test for success. Can we not check for out[0] == 
> TOS_SUCCESS
> or similar? The above logic seems like the kind to lead to failure going
> unnoticed as success is assumed and not confirmed.
>

No problem, will send v3 in a few :-)

>> + dev->usbsc_mode_base = out[4];
>> +
>> + in[5] = SCI_USB_CHARGE_BAT_LVL;
>> + status = tci_raw(dev, in, out);
>> + if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
>> + pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
>> + sci_close(dev);
>> + return;
>> + } else if (out[0] == TOS_NOT_SUPPORTED) {
>> + pr_info("USB Sleep and Charge not supported\n");
>> + sci_close(dev);
>> + return;
>> + }
>
> Here too.
>
> --
> Darren Hart
> Intel Open Source Technology Center


Cheers
Azael


-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


[PATCH v3 2/3] toshiba_acpi: Fix pr_* messages from USB Sleep Functions

2015-04-02 Thread Azael Avalos
This patch fixes the messages displayed by the USB Sleep Functions,
they were printing wrong messages not associated to the feature
currently queried.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 37f5f64..f624dd5 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -965,11 +965,11 @@ static int toshiba_usb_rapid_charge_get(struct 
toshiba_acpi_dev *dev,
status = tci_raw(dev, in, out);
sci_close(dev);
if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
-   pr_err("ACPI call to get USB S&C battery level failed\n");
+   pr_err("ACPI call to get USB Rapid Charge failed\n");
return -EIO;
} else if (out[0] == TOS_NOT_SUPPORTED ||
   out[0] == TOS_INPUT_DATA_ERROR) {
-   pr_info("USB Sleep and Charge not supported\n");
+   pr_info("USB Rapid Charge not supported\n");
return -ENODEV;
}
 
@@ -993,10 +993,10 @@ static int toshiba_usb_rapid_charge_set(struct 
toshiba_acpi_dev *dev,
status = tci_raw(dev, in, out);
sci_close(dev);
if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
-   pr_err("ACPI call to set USB S&C battery level failed\n");
+   pr_err("ACPI call to set USB Rapid Charge failed\n");
return -EIO;
} else if (out[0] == TOS_NOT_SUPPORTED) {
-   pr_info("USB Sleep and Charge not supported\n");
+   pr_info("USB Rapid Charge not supported\n");
return -ENODEV;
} else if (out[0] == TOS_INPUT_DATA_ERROR) {
return -EIO;
@@ -1015,10 +1015,10 @@ static int toshiba_usb_sleep_music_get(struct 
toshiba_acpi_dev *dev, u32 *state)
result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
sci_close(dev);
if (result == TOS_FAILURE) {
-   pr_err("ACPI call to set USB S&C mode failed\n");
+   pr_err("ACPI call to get Sleep and Music failed\n");
return -EIO;
} else if (result == TOS_NOT_SUPPORTED) {
-   pr_info("USB Sleep and Charge not supported\n");
+   pr_info("Sleep and Music not supported\n");
return -ENODEV;
} else if (result == TOS_INPUT_DATA_ERROR) {
return -EIO;
@@ -1037,10 +1037,10 @@ static int toshiba_usb_sleep_music_set(struct 
toshiba_acpi_dev *dev, u32 state)
result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
sci_close(dev);
if (result == TOS_FAILURE) {
-   pr_err("ACPI call to set USB S&C mode failed\n");
+   pr_err("ACPI call to set Sleep and Music failed\n");
return -EIO;
} else if (result == TOS_NOT_SUPPORTED) {
-   pr_info("USB Sleep and Charge not supported\n");
+   pr_info("Sleep and Music not supported\n");
return -ENODEV;
} else if (result == TOS_INPUT_DATA_ERROR) {
return -EIO;
-- 
2.3.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/


[PATCH v3 1/3] toshiba_acpi: Update and fix USB Sleep and Charge modes

2015-04-02 Thread Azael Avalos
This patch fixes the USB Sleep and Charge mode on certain models
where the value returned by the BIOS is different, and thus, making
this feature not to work for those models.

Also, the "Typical" charging mode was added as a supported mode.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 17a259e..37f5f64 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -150,9 +150,10 @@ MODULE_LICENSE("GPL");
 #define SCI_KBD_MODE_OFF   0x10
 #define SCI_KBD_TIME_MAX   0x3c001a
 #define SCI_USB_CHARGE_MODE_MASK   0xff
-#define SCI_USB_CHARGE_DISABLED0x3
-#define SCI_USB_CHARGE_ALTERNATE   0x30009
-#define SCI_USB_CHARGE_AUTO0x30021
+#define SCI_USB_CHARGE_DISABLED0x00
+#define SCI_USB_CHARGE_ALTERNATE   0x09
+#define SCI_USB_CHARGE_TYPICAL 0x11
+#define SCI_USB_CHARGE_AUTO0x21
 #define SCI_USB_CHARGE_BAT_MASK0x7
 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
 #define SCI_USB_CHARGE_BAT_LVL_ON  0x4
@@ -177,6 +178,7 @@ struct toshiba_acpi_dev {
int kbd_mode;
int kbd_time;
int usbsc_bat_level;
+   int usbsc_mode_base;
int hotkey_event_type;
 
unsigned int illumination_supported:1;
@@ -800,6 +802,54 @@ static int toshiba_accelerometer_get(struct 
toshiba_acpi_dev *dev,
 }
 
 /* Sleep (Charge and Music) utilities support */
+static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
+{
+   u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   /* Set the feature to "not supported" in case of error */
+   dev->usb_sleep_charge_supported = 0;
+
+   if (!sci_open(dev))
+   return;
+
+   status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
+   sci_close(dev);
+   return;
+   } else if (out[0] == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   sci_close(dev);
+   return;
+   } else if (out[0] == TOS_SUCCESS) {
+   dev->usbsc_mode_base = out[4];
+   }
+
+   in[5] = SCI_USB_CHARGE_BAT_LVL;
+   status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+   pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
+   sci_close(dev);
+   return;
+   } else if (out[0] == TOS_NOT_SUPPORTED) {
+   pr_info("USB Sleep and Charge not supported\n");
+   sci_close(dev);
+   return;
+   } else if (out[0] == TOS_SUCCESS) {
+   dev->usbsc_bat_level = out[2];
+   /*
+* If we reach this point, it means that the laptop has support
+* for this feature and all values are initialized.
+* Set it as supported.
+*/
+   dev->usb_sleep_charge_supported = 1;
+   }
+
+   sci_close(dev);
+}
+
 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
u32 *mode)
 {
@@ -1976,17 +2026,21 @@ static ssize_t usb_sleep_charge_store(struct device 
*dev,
 * 0 - Disabled
 * 1 - Alternate (Non USB conformant devices that require more power)
 * 2 - Auto (USB conformant devices)
+* 3 - Typical
 */
-   if (state != 0 && state != 1 && state != 2)
+   if (state != 0 && state != 1 && state != 2 && state != 3)
return -EINVAL;
 
/* Set the USB charging mode to internal value */
+   mode = toshiba->usbsc_mode_base;
if (state == 0)
-   mode = SCI_USB_CHARGE_DISABLED;
+   mode |= SCI_USB_CHARGE_DISABLED;
else if (state == 1)
-   mode = SCI_USB_CHARGE_ALTERNATE;
+   mode |= SCI_USB_CHARGE_ALTERNATE;
else if (state == 2)
-   mode = SCI_USB_CHARGE_AUTO;
+   mode |= SCI_USB_CHARGE_AUTO;
+   else if (state == 3)
+   mode |= SCI_USB_CHARGE_TYPICAL;
 
ret = toshiba_usb_sleep_charge_set(toshiba, mode);
if (ret)
@@ -2756,8 +2810,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
ret = toshiba_accelerometer_supported(dev);
dev->accelerometer_supported = !ret;
 
-   ret = toshiba_usb_sleep_charge_get(dev, &dummy);
-   dev->usb_sleep_charge_supported = !ret;
+   toshiba_usb

[PATCH v3 0/3] toshiba_acpi: Fix USB Sleep & Charge mode and documentation updates

2015-04-02 Thread Azael Avalos
This patch fixes the USB Sleep & Charge charging mode on certain
models, fixes pr_* messages and also adds the missing entries in the
documentation file.

Changes since v2:
- Check for TOS_SUCCESS to initialize and flag as supported on first
  patch

Changes since v1:
- Set the default supported value of sleep and charge to zero in case
  of an error and added comments.
- Updated the title and commit message of second patch to better
  reflect what the patch is doing.

Azael Avalos (3):
  toshiba_acpi: Update and fix USB Sleep and Charge modes
  toshiba_acpi: Fix pr_* messages from USB Sleep Functions
  Documentation/ABI: Update sysfs-driver-toshiba_acpi entry

 .../ABI/testing/sysfs-driver-toshiba_acpi  | 93 +++---
 drivers/platform/x86/toshiba_acpi.c| 87 
 2 files changed, 150 insertions(+), 30 deletions(-)

-- 
2.3.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/


[PATCH v3 3/3] Documentation/ABI: Update sysfs-driver-toshiba_acpi entry

2015-04-02 Thread Azael Avalos
This patch updates the sysfs-driver-toshiba_acpi entry, adding the
missing entries for USB Sleep functions.

And also, while at the neighborhood, fix some typos and add a note
that some features require a reboot.

Signed-off-by: Azael Avalos 
---
 .../ABI/testing/sysfs-driver-toshiba_acpi  | 93 +++---
 1 file changed, 80 insertions(+), 13 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-driver-toshiba_acpi 
b/Documentation/ABI/testing/sysfs-driver-toshiba_acpi
index ca9c71a..eed922e 100644
--- a/Documentation/ABI/testing/sysfs-driver-toshiba_acpi
+++ b/Documentation/ABI/testing/sysfs-driver-toshiba_acpi
@@ -8,9 +8,11 @@ Description:   This file controls the keyboard backlight 
operation mode, valid
* 0x2  -> AUTO (also called TIMER)
* 0x8  -> ON
* 0x10 -> OFF
-   Note that the kernel 3.16 onwards this file accepts all listed
+   Note that from kernel 3.16 onwards this file accepts all listed
parameters, kernel 3.15 only accepts the first two (FN-Z and
AUTO).
+   Also note that toggling this value on type 1 devices, requires
+   a reboot for changes to take effect.
 Users: KToshiba
 
 What:  
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/TOS{1900,620{0,7,8}}:00/kbd_backlight_timeout
@@ -67,15 +69,72 @@ Description:This file shows the current keyboard 
backlight type,
* 2 -> Type 2, supporting modes TIMER, ON and OFF
 Users: KToshiba
 
+What:  
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/TOS{1900,620{0,7,8}}:00/usb_sleep_charge
+Date:  January 23, 2015
+KernelVersion: 4.0
+Contact:   Azael Avalos 
+Description:   This file controls the USB Sleep & Charge charging mode, which
+   can be:
+   * 0 -> Disabled (0x00)
+   * 1 -> Alternate(0x09)
+   * 2 -> Auto (0x21)
+   * 3 -> Typical  (0x11)
+   Note that from kernel 4.1 onwards this file accepts all listed
+   values, kernel 4.0 only supports the first three.
+   Note that this feature only works when connected to power, if
+   you want to use it under battery, see the entry named
+   "sleep_functions_on_battery"
+Users: KToshiba
+
+What:  
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/TOS{1900,620{0,7,8}}:00/sleep_functions_on_battery
+Date:  January 23, 2015
+KernelVersion: 4.0
+Contact:   Azael Avalos 
+Description:   This file controls the USB Sleep Functions under battery, and
+   set the level at which point they will be disabled, accepted
+   values can be:
+   * 0 -> Disabled
+   * 1-100 -> Battery level to disable sleep functions
+   Currently it prints two values, the first one indicates if the
+   feature is enabled or disabled, while the second one shows the
+   current battery level set.
+   Note that when the value is set to disabled, the sleep function
+   will only work when connected to power.
+Users: KToshiba
+
+What:  
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/TOS{1900,620{0,7,8}}:00/usb_rapid_charge
+Date:  January 23, 2015
+KernelVersion: 4.0
+Contact:   Azael Avalos 
+Description:   This file controls the USB Rapid Charge state, which can be:
+   * 0 -> Disabled
+   * 1 -> Enabled
+   Note that toggling this value requires a reboot for changes to
+   take effect.
+Users: KToshiba
+
+What:  
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/TOS{1900,620{0,7,8}}:00/usb_sleep_music
+Date:  January 23, 2015
+KernelVersion: 4.0
+Contact:   Azael Avalos 
+Description:   This file controls the Sleep & Music state, which values can be:
+   * 0 -> Disabled
+   * 1 -> Enabled
+   Note that this feature only works when connected to power, if
+   you want to use it under battery, see the entry named
+   "sleep_functions_on_battery"
+Users: KToshiba
+
 What:  
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/TOS{1900,620{0,7,8}}:00/version
-Date:  February, 2015
-KernelVersion: 3.20
+Date:  February 12, 2015
+KernelVersion: 4.0
 Contact:   Azael Avalos 
 Description:   This file shows the current version of the driver
+Users: KToshiba
 
 What:  /sys/devices/LNXSYSTM:00/LNXSYBUS:00/TOS{1900,620{0,7,8}}:00/fan
-Date:  February, 2015
-KernelVersion: 3.20
+Date:  February 12, 2015
+KernelVersion: 4.0
 Contact:   Azael Avalos 
 Description:   This file controls the state 

[PATCH v3 2/3] toshiba_acpi: Fix pr_* messages from USB Sleep Functions

2015-04-02 Thread Azael Avalos
This patch fixes the messages displayed by the USB Sleep Functions,
they were printing wrong messages not associated to the feature
currently queried.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 37f5f64..f624dd5 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -965,11 +965,11 @@ static int toshiba_usb_rapid_charge_get(struct 
toshiba_acpi_dev *dev,
status = tci_raw(dev, in, out);
sci_close(dev);
if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
-   pr_err("ACPI call to get USB S&C battery level failed\n");
+   pr_err("ACPI call to get USB Rapid Charge failed\n");
return -EIO;
} else if (out[0] == TOS_NOT_SUPPORTED ||
   out[0] == TOS_INPUT_DATA_ERROR) {
-   pr_info("USB Sleep and Charge not supported\n");
+   pr_info("USB Rapid Charge not supported\n");
return -ENODEV;
}
 
@@ -993,10 +993,10 @@ static int toshiba_usb_rapid_charge_set(struct 
toshiba_acpi_dev *dev,
status = tci_raw(dev, in, out);
sci_close(dev);
if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
-   pr_err("ACPI call to set USB S&C battery level failed\n");
+   pr_err("ACPI call to set USB Rapid Charge failed\n");
return -EIO;
} else if (out[0] == TOS_NOT_SUPPORTED) {
-   pr_info("USB Sleep and Charge not supported\n");
+   pr_info("USB Rapid Charge not supported\n");
return -ENODEV;
} else if (out[0] == TOS_INPUT_DATA_ERROR) {
return -EIO;
@@ -1015,10 +1015,10 @@ static int toshiba_usb_sleep_music_get(struct 
toshiba_acpi_dev *dev, u32 *state)
result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
sci_close(dev);
if (result == TOS_FAILURE) {
-   pr_err("ACPI call to set USB S&C mode failed\n");
+   pr_err("ACPI call to get Sleep and Music failed\n");
return -EIO;
} else if (result == TOS_NOT_SUPPORTED) {
-   pr_info("USB Sleep and Charge not supported\n");
+   pr_info("Sleep and Music not supported\n");
return -ENODEV;
} else if (result == TOS_INPUT_DATA_ERROR) {
return -EIO;
@@ -1037,10 +1037,10 @@ static int toshiba_usb_sleep_music_set(struct 
toshiba_acpi_dev *dev, u32 state)
result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
sci_close(dev);
if (result == TOS_FAILURE) {
-   pr_err("ACPI call to set USB S&C mode failed\n");
+   pr_err("ACPI call to set Sleep and Music failed\n");
return -EIO;
} else if (result == TOS_NOT_SUPPORTED) {
-   pr_info("USB Sleep and Charge not supported\n");
+   pr_info("Sleep and Music not supported\n");
return -ENODEV;
} else if (result == TOS_INPUT_DATA_ERROR) {
return -EIO;
-- 
2.3.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/


[PATCH 2/2] platform/x86: Remove RFKILL dependency from toshiba_acpi

2015-04-27 Thread Azael Avalos
This patch removes the dependency on rfkill for toshiba_acpi from
KConfig, as a previous patch removed all the code related to it.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/Kconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 9752761..35319f8 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -612,7 +612,6 @@ config ACPI_TOSHIBA
select NEW_LEDS
depends on BACKLIGHT_CLASS_DEVICE
depends on INPUT
-   depends on RFKILL || RFKILL = n
depends on SERIO_I8042 || SERIO_I8042 = n
select INPUT_POLLDEV
select INPUT_SPARSEKMAP
-- 
2.3.5

--
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/


[PATCH 0/2] toshiba_acpi: Purge driver from bluetooth RFKill code

2015-04-27 Thread Azael Avalos
These two patches remove all bluetooth rfkill code from toshiba_acpi
and its build dependencies, as another series of patches will re-add
the rfkill code to toshiba_bluetooth instead.

Azael Avalos (2):
  toshiba_acpi: Remove bluetooth rfkill code
  platform/x86: Remove RFKILL dependency from toshiba_acpi

 drivers/platform/x86/Kconfig|   1 -
 drivers/platform/x86/toshiba_acpi.c | 123 
 2 files changed, 124 deletions(-)

-- 
2.3.5

--
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/


[PATCH 1/2] toshiba_acpi: Remove bluetooth rfkill code

2015-04-27 Thread Azael Avalos
This patch removes all bluetooth rfkill related code residing in
the toshiba_acpi driver.

Separate patches will add (and adapt) the code to toshiba_bluetooth
(where it belongs).

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 123 
 1 file changed, 123 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index f624dd5..2599d23 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -41,7 +41,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -163,7 +162,6 @@ MODULE_LICENSE("GPL");
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
const char *method_hci;
-   struct rfkill *bt_rfk;
struct input_dev *hotkey_dev;
struct work_struct hotkey_work;
struct backlight_device *backlight_dev;
@@ -200,8 +198,6 @@ struct toshiba_acpi_dev {
unsigned int panel_power_on_supported:1;
unsigned int usb_three_supported:1;
unsigned int sysfs_created:1;
-
-   struct mutex mutex;
 };
 
 static struct toshiba_acpi_dev *toshiba_acpi;
@@ -1202,97 +1198,6 @@ static int toshiba_hotkey_event_type_get(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
-/* Bluetooth rfkill handlers */
-
-static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
-{
-   u32 hci_result;
-   u32 value, value2;
-
-   value = 0;
-   value2 = 0;
-   hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
-   if (hci_result == TOS_SUCCESS)
-   *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
-
-   return hci_result;
-}
-
-static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
-{
-   u32 hci_result;
-   u32 value, value2;
-
-   value = 0;
-   value2 = 0x0001;
-   hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
-
-   *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
-   return hci_result;
-}
-
-static int bt_rfkill_set_block(void *data, bool blocked)
-{
-   struct toshiba_acpi_dev *dev = data;
-   u32 result1, result2;
-   u32 value;
-   int err;
-   bool radio_state;
-
-   value = (blocked == false);
-
-   mutex_lock(&dev->mutex);
-   if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) {
-   err = -EIO;
-   goto out;
-   }
-
-   if (!radio_state) {
-   err = 0;
-   goto out;
-   }
-
-   result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER);
-   result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH);
-
-   if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS)
-   err = -EIO;
-   else
-   err = 0;
- out:
-   mutex_unlock(&dev->mutex);
-   return err;
-}
-
-static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
-{
-   bool new_rfk_state;
-   bool value;
-   u32 hci_result;
-   struct toshiba_acpi_dev *dev = data;
-
-   mutex_lock(&dev->mutex);
-
-   hci_result = hci_get_radio_state(dev, &value);
-   if (hci_result != TOS_SUCCESS) {
-   /* Can't do anything useful */
-   mutex_unlock(&dev->mutex);
-   return;
-   }
-
-   new_rfk_state = value;
-
-   mutex_unlock(&dev->mutex);
-
-   if (rfkill_set_hw_state(rfkill, !new_rfk_state))
-   bt_rfkill_set_block(data, true);
-}
-
-static const struct rfkill_ops toshiba_rfk_ops = {
-   .set_block = bt_rfkill_set_block,
-   .poll = bt_rfkill_poll,
-};
-
 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
 {
u32 hci_result;
@@ -2668,11 +2573,6 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
sparse_keymap_free(dev->hotkey_dev);
}
 
-   if (dev->bt_rfk) {
-   rfkill_unregister(dev->bt_rfk);
-   rfkill_destroy(dev->bt_rfk);
-   }
-
backlight_device_unregister(dev->backlight_dev);
 
if (dev->illumination_supported)
@@ -2745,33 +2645,10 @@ static int toshiba_acpi_add(struct acpi_device 
*acpi_dev)
if (toshiba_acpi_setup_keyboard(dev))
pr_info("Unable to activate hotkeys\n");
 
-   mutex_init(&dev->mutex);
-
ret = toshiba_acpi_setup_backlight(dev);
if (ret)
goto error;
 
-   /* Register rfkill switch for Bluetooth */
-   if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
-   dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
-  &acpi_dev->dev,
-  RFKILL_TYPE_BLUETOOTH,
-  &

[PATCH 1/6] toshiba_bluetooth: Add a container struct named toshiba_bluetooth_dev

2015-04-27 Thread Azael Avalos
This patch adds a struct named toshiba_bluetooth_dev, which will be
used to contain the acpi_device struct and bluetooth status booleans.

This struct will also be used by later patches to store the rfkill
struct as well.

Also, a helper function named toshiba_bluetooth_sync_status was added
to be also used by upcomming patches.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_bluetooth.c | 47 +++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_bluetooth.c 
b/drivers/platform/x86/toshiba_bluetooth.c
index 2498007..a619ba6 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -34,6 +34,14 @@ MODULE_AUTHOR("Jes Sorensen ");
 MODULE_DESCRIPTION("Toshiba Laptop ACPI Bluetooth Enable Driver");
 MODULE_LICENSE("GPL");
 
+struct toshiba_bluetooth_dev {
+   struct acpi_device *acpi_dev;
+
+   bool killswitch;
+   bool plugged;
+   bool powered;
+};
+
 static int toshiba_bt_rfkill_add(struct acpi_device *device);
 static int toshiba_bt_rfkill_remove(struct acpi_device *device);
 static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event);
@@ -165,6 +173,25 @@ static int toshiba_bluetooth_disable(acpi_handle handle)
return 0;
 }
 
+/* Helper function */
+static int toshiba_bluetooth_sync_status(struct toshiba_bluetooth_dev *bt_dev)
+{
+   int status;
+
+   status = toshiba_bluetooth_status(bt_dev->acpi_dev->handle);
+   if (status < 0) {
+   pr_err("Could not sync bluetooth device status\n");
+   return status;
+   }
+
+   bt_dev->killswitch = (status & BT_KILLSWITCH_MASK) ? true : false;
+   bt_dev->plugged = (status & BT_PLUGGED_MASK) ? true : false;
+   bt_dev->powered = (status & BT_POWER_MASK) ? true : false;
+
+   return 0;
+}
+
+/* ACPI driver functions */
 static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event)
 {
toshiba_bluetooth_enable(device->handle);
@@ -179,6 +206,7 @@ static int toshiba_bt_resume(struct device *dev)
 
 static int toshiba_bt_rfkill_add(struct acpi_device *device)
 {
+   struct toshiba_bluetooth_dev *bt_dev;
int result;
 
result = toshiba_bluetooth_present(device->handle);
@@ -187,17 +215,34 @@ static int toshiba_bt_rfkill_add(struct acpi_device 
*device)
 
pr_info("Toshiba ACPI Bluetooth device driver\n");
 
+   bt_dev = kzalloc(sizeof(*bt_dev), GFP_KERNEL);
+   if (!bt_dev)
+   return -ENOMEM;
+   bt_dev->acpi_dev = device;
+   device->driver_data = bt_dev;
+   dev_set_drvdata(&device->dev, bt_dev);
+
+   result = toshiba_bluetooth_sync_status(bt_dev);
+   if (result) {
+   kfree(bt_dev);
+   return result;
+   }
+
/* Enable the BT device */
result = toshiba_bluetooth_enable(device->handle);
if (result)
-   return result;
+   kfree(bt_dev);
 
return result;
 }
 
 static int toshiba_bt_rfkill_remove(struct acpi_device *device)
 {
+   struct toshiba_bluetooth_dev *bt_dev = acpi_driver_data(device);
+
/* clean up */
+   kfree(bt_dev);
+
return toshiba_bluetooth_disable(device->handle);
 }
 
-- 
2.3.5

--
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/


[PATCH 0/6] toshiba_bluetooth: Add rfkill code to driver

2015-04-27 Thread Azael Avalos
These patches add support to use the rfkill core functionality to the
Toshiba bluetooth driver and adapting the existing code to it.

Azael Avalos (6):
  toshiba_bluetooth: Add a container struct named toshiba_bluetooth_dev
  toshiba_bluetooth: Add RFKill handler functions
  toshiba_bluetooth: Clean toshiba_bluetooth_enable function
  toshiba_bluetooth: Adapt *_notify and *_resume functions to rfkill
  toshiba_bluetooth: Change BT status message to debug
  platform/x86: Add RFKILL dependency to toshiba_bluetooth driver

 drivers/platform/x86/Kconfig |   1 +
 drivers/platform/x86/toshiba_bluetooth.c | 175 ---
 2 files changed, 137 insertions(+), 39 deletions(-)

-- 
2.3.5

--
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/


[PATCH 6/6] platform/x86: Add RFKILL dependency to toshiba_bluetooth driver

2015-04-27 Thread Azael Avalos
This patch simply adds the RFKILL dependency to Kconfig, as we are
now using rfkill code on the driver.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 9752761..681b0c5 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -642,6 +642,7 @@ config ACPI_TOSHIBA
 config TOSHIBA_BT_RFKILL
tristate "Toshiba Bluetooth RFKill switch support"
depends on ACPI
+   depends on RFKILL || RFKILL = n
---help---
  This driver adds support for Bluetooth events for the RFKill
  switch on modern Toshiba laptops with full ACPI support and
-- 
2.3.5

--
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/


[PATCH 4/6] toshiba_bluetooth: Adapt *_notify and *_resume functions to rfkill

2015-04-27 Thread Azael Avalos
This patch adapts toshiba_bt_rfkill_notify and toshiba_bt_resume
functions to update the rfkill status, as they were only calling
toshiba_bluetooth_enable.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_bluetooth.c | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/toshiba_bluetooth.c 
b/drivers/platform/x86/toshiba_bluetooth.c
index 875ff6c..9867ccd 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -206,13 +206,29 @@ static const struct rfkill_ops rfk_ops = {
 /* ACPI driver functions */
 static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event)
 {
-   toshiba_bluetooth_enable(device->handle);
+   struct toshiba_bluetooth_dev *bt_dev = acpi_driver_data(device);
+
+   if (toshiba_bluetooth_sync_status(bt_dev))
+   return;
+
+   rfkill_set_hw_state(bt_dev->rfk, !bt_dev->killswitch);
 }
 
 #ifdef CONFIG_PM_SLEEP
 static int toshiba_bt_resume(struct device *dev)
 {
-   return toshiba_bluetooth_enable(to_acpi_device(dev)->handle);
+   struct toshiba_bluetooth_dev *bt_dev;
+   int ret;
+
+   bt_dev = acpi_driver_data(to_acpi_device(dev));
+
+   ret = toshiba_bluetooth_sync_status(bt_dev);
+   if (ret)
+   return ret;
+
+   rfkill_set_hw_state(bt_dev->rfk, !bt_dev->killswitch);
+
+   return 0;
 }
 #endif
 
-- 
2.3.5

--
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/


[PATCH 5/6] toshiba_bluetooth: Change BT status message to debug

2015-04-27 Thread Azael Avalos
The function toshiba_bluetooth_status s currently printing the status
of the device whenever it is queried, but since the introduction of
the rfkill poll code, this value will get printed everytime the poll
occurs.

This patch changes the level of the printed message from info to
debug, and also adds a few more debug messages printing the
killswitch, plug and power status of the device as well.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_bluetooth.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_bluetooth.c 
b/drivers/platform/x86/toshiba_bluetooth.c
index 9867ccd..93b9688 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -99,7 +99,7 @@ static int toshiba_bluetooth_status(acpi_handle handle)
return -ENXIO;
}
 
-   pr_info("Bluetooth status %llu\n", status);
+   pr_debug("Bluetooth status %llu\n", status);
 
return status;
 }
@@ -157,6 +157,10 @@ static int toshiba_bluetooth_sync_status(struct 
toshiba_bluetooth_dev *bt_dev)
bt_dev->plugged = (status & BT_PLUGGED_MASK) ? true : false;
bt_dev->powered = (status & BT_POWER_MASK) ? true : false;
 
+   pr_debug("killswitch %d\n", bt_dev->killswitch);
+   pr_debug("plugged %d\n", bt_dev->plugged);
+   pr_debug("powered %d\n", bt_dev->powered);
+
return 0;
 }
 
-- 
2.3.5

--
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/


[PATCH 3/6] toshiba_bluetooth: Clean toshiba_bluetooth_enable function

2015-04-27 Thread Azael Avalos
This patch removes unneeded code from the toshiba_bluetooth_enable
function as propper rfkill code as been added now.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_bluetooth.c | 27 ---
 1 file changed, 27 deletions(-)

diff --git a/drivers/platform/x86/toshiba_bluetooth.c 
b/drivers/platform/x86/toshiba_bluetooth.c
index a3b2d38..875ff6c 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -107,33 +107,6 @@ static int toshiba_bluetooth_status(acpi_handle handle)
 static int toshiba_bluetooth_enable(acpi_handle handle)
 {
acpi_status result;
-   bool killswitch;
-   bool powered;
-   bool plugged;
-   int status;
-
-   /*
-* Query ACPI to verify RFKill switch is set to 'on'.
-* If not, we return silently, no need to report it as
-* an error.
-*/
-   status = toshiba_bluetooth_status(handle);
-   if (status < 0)
-   return status;
-
-   killswitch = (status & BT_KILLSWITCH_MASK) ? true : false;
-   powered = (status & BT_POWER_MASK) ? true : false;
-   plugged = (status & BT_PLUGGED_MASK) ? true : false;
-
-   if (!killswitch)
-   return 0;
-   /*
-* This check ensures to only enable the device if it is powered
-* off or detached, as some recent devices somehow pass the killswitch
-* test, causing a loop enabling/disabling the device, see bug 93911.
-*/
-   if (powered || plugged)
-   return 0;
 
result = acpi_evaluate_object(handle, "AUSB", NULL, NULL);
if (ACPI_FAILURE(result)) {
-- 
2.3.5

--
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/


[PATCH 2/6] toshiba_bluetooth: Add RFKill handler functions

2015-04-27 Thread Azael Avalos
This patch adds RFKill handler functions to the driver, allowing it
to register and update the rfkill switch.

Also, a comment block was moved from the header to the poll function,
as it explains why we need to poll the killswitch on older devices.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_bluetooth.c | 77 
 1 file changed, 68 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/toshiba_bluetooth.c 
b/drivers/platform/x86/toshiba_bluetooth.c
index a619ba6..a3b2d38 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -10,12 +10,6 @@
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
- *
- * Note the Toshiba Bluetooth RFKill switch seems to be a strange
- * fish. It only provides a BT event when the switch is flipped to
- * the 'on' position. When flipping it to 'off', the USB device is
- * simply pulled away underneath us, without any BT event being
- * delivered.
  */
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -25,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define BT_KILLSWITCH_MASK 0x01
 #define BT_PLUGGED_MASK0x40
@@ -36,6 +31,7 @@ MODULE_LICENSE("GPL");
 
 struct toshiba_bluetooth_dev {
struct acpi_device *acpi_dev;
+   struct rfkill *rfk;
 
bool killswitch;
bool plugged;
@@ -191,6 +187,49 @@ static int toshiba_bluetooth_sync_status(struct 
toshiba_bluetooth_dev *bt_dev)
return 0;
 }
 
+/* RFKill handlers */
+static int bt_rfkill_set_block(void *data, bool blocked)
+{
+   struct toshiba_bluetooth_dev *bt_dev = data;
+   int ret;
+
+   ret = toshiba_bluetooth_sync_status(bt_dev);
+   if (ret)
+   return ret;
+
+   if (!bt_dev->killswitch)
+   return 0;
+
+   if (blocked)
+   ret = toshiba_bluetooth_disable(bt_dev->acpi_dev->handle);
+   else
+   ret = toshiba_bluetooth_enable(bt_dev->acpi_dev->handle);
+
+   return ret;
+}
+
+static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
+{
+   struct toshiba_bluetooth_dev *bt_dev = data;
+
+   if (toshiba_bluetooth_sync_status(bt_dev))
+   return;
+
+   /*
+* Note the Toshiba Bluetooth RFKill switch seems to be a strange
+* fish. It only provides a BT event when the switch is flipped to
+* the 'on' position. When flipping it to 'off', the USB device is
+* simply pulled away underneath us, without any BT event being
+* delivered.
+*/
+   rfkill_set_hw_state(bt_dev->rfk, !bt_dev->killswitch);
+}
+
+static const struct rfkill_ops rfk_ops = {
+   .set_block = bt_rfkill_set_block,
+   .poll = bt_rfkill_poll,
+};
+
 /* ACPI driver functions */
 static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event)
 {
@@ -228,10 +267,25 @@ static int toshiba_bt_rfkill_add(struct acpi_device 
*device)
return result;
}
 
-   /* Enable the BT device */
-   result = toshiba_bluetooth_enable(device->handle);
-   if (result)
+   bt_dev->rfk = rfkill_alloc("Toshiba Bluetooth",
+  &device->dev,
+  RFKILL_TYPE_BLUETOOTH,
+  &rfk_ops,
+  bt_dev);
+   if (!bt_dev->rfk) {
+   pr_err("Unable to allocate rfkill device\n");
+   kfree(bt_dev);
+   return -ENOMEM;
+   }
+
+   rfkill_set_hw_state(bt_dev->rfk, !bt_dev->killswitch);
+
+   result = rfkill_register(bt_dev->rfk);
+   if (result) {
+   pr_err("Unable to register rfkill device\n");
+   rfkill_destroy(bt_dev->rfk);
kfree(bt_dev);
+   }
 
return result;
 }
@@ -241,6 +295,11 @@ static int toshiba_bt_rfkill_remove(struct acpi_device 
*device)
struct toshiba_bluetooth_dev *bt_dev = acpi_driver_data(device);
 
/* clean up */
+   if (bt_dev->rfk) {
+   rfkill_unregister(bt_dev->rfk);
+   rfkill_destroy(bt_dev->rfk);
+   }
+
kfree(bt_dev);
 
return toshiba_bluetooth_disable(device->handle);
-- 
2.3.5

--
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/


Re: [PATCH 5/6] toshiba_bluetooth: Change BT status message to debug

2015-04-28 Thread Azael Avalos
Hi there,

2015-04-28 1:36 GMT-06:00 Bjørn Mork :
> Azael Avalos  writes:
>
>> The function toshiba_bluetooth_status s currently printing the status
>> of the device whenever it is queried, but since the introduction of
>> the rfkill poll code, this value will get printed everytime the poll
>> occurs.
>>
>> This patch changes the level of the printed message from info to
>> debug, and also adds a few more debug messages printing the
>> killswitch, plug and power status of the device as well.
>>
>> Signed-off-by: Azael Avalos 
>> ---
>>  drivers/platform/x86/toshiba_bluetooth.c | 6 +-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_bluetooth.c 
>> b/drivers/platform/x86/toshiba_bluetooth.c
>> index 9867ccd..93b9688 100644
>> --- a/drivers/platform/x86/toshiba_bluetooth.c
>> +++ b/drivers/platform/x86/toshiba_bluetooth.c
>> @@ -99,7 +99,7 @@ static int toshiba_bluetooth_status(acpi_handle handle)
>>   return -ENXIO;
>>   }
>>
>> - pr_info("Bluetooth status %llu\n", status);
>> + pr_debug("Bluetooth status %llu\n", status);
>>
>>   return status;
>>  }
>> @@ -157,6 +157,10 @@ static int toshiba_bluetooth_sync_status(struct 
>> toshiba_bluetooth_dev *bt_dev)
>>   bt_dev->plugged = (status & BT_PLUGGED_MASK) ? true : false;
>>   bt_dev->powered = (status & BT_POWER_MASK) ? true : false;
>>
>> + pr_debug("killswitch %d\n", bt_dev->killswitch);
>> + pr_debug("plugged %d\n", bt_dev->plugged);
>> + pr_debug("powered %d\n", bt_dev->powered);
>
>
> Those are terribly generic messages.  I don't think I would have guessed
> which device was trying to tell me "powered 1" if I found it in the
> logs...

Well, I was under the impression that what really gets printed is:
toshiba_bluetooth: killswitch 1

and then a siple "dmesg | grep toshiba_bluetooth" would suffice,
but yeah, they are quite non obvious.

>
> How about using e.g dev_dbg() to get a bit more context here?
>
> You might also want to put all three into a single call, so that they
> make a single dynamic debug entry when dynamic debugging is enabled.
>

Alright, will do, I'll just wait on Darren's (or someone else) comments and
send a v2.

> And looking at toshiba_bluetooth_status() I see that all callers have a
> device. How about propagating the device to be able to use the dev_*
> printk's there as well?  Let the device identify itself instead of
> having to guess.
>
>
> Bjørn


Cheers
Azael



-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


Re: [PATCH 1/2] platform/x86: asus-wmi: Call new led hw_changed API on kbd brightness change

2018-06-04 Thread Azael Avalos
Hi there

Let me add my two cents on the Toshiba side.

2018-06-04 8:23 GMT-06:00 Hans de Goede :

>
> 1) drivers/platform/x86/toshiba_acpi.c
>
> I don't know how the key on Toshiba's behaves on models where
> it is hardwired / under Windows

With Toshiba we have two types of hardware implementations:

1st gen keyboards, supporting AUTO and FN-Z
AUTO - Turns on/off automatically after some (configurable) time
FN-Z - Creates "toshiba::kbd_backlight" and it's toggled by userspace

2nd gen keyborads, supporting AUTO, ON and OFF
AUTO - Ditto
ON - Always on
OFF - Always off

The second gen keyboards are completely driven by hardware,
userspace must be checking sysfs for "kbd_backlight_mode"
changes, however, the Toshiba interface emits the 0x92
ACPI event when we have a kbd mode change, but it's not
currently being transmitted to userspace via netlink.


Saludos
Azael


-- 
-- El mundo apesta y vosotros apestais tambien --


[PATCH 3/8] toshiba_acpi: Add platform support

2013-11-04 Thread Azael Avalos
Add platform support and change the backlight
and led devices to register on it instead of the acpi_device.

The use of the platform is to have just one place where to
look for files instead of looking at the current three different
ACPI devices (TOS6200, TOS6208 and TOS1900) and thus making
userspace a bit easier.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index d7ecef3..226e0b5 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -54,6 +54,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -129,6 +130,7 @@ MODULE_LICENSE("GPL");
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
+   struct platform_device *pf_dev;
const char *method_hci;
struct rfkill *bt_rfk;
struct input_dev *hotkey_dev;
@@ -1156,7 +1158,7 @@ static int toshiba_acpi_setup_backlight(struct 
toshiba_acpi_dev *dev)
props.max_brightness++;
 
dev->backlight_dev = backlight_device_register("toshiba",
-  &dev->acpi_dev->dev,
+  &dev->pf_dev->dev,
   dev,
   &toshiba_backlight_data,
   &props);
@@ -1198,6 +1200,9 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
if (dev->illumination_supported)
led_classdev_unregister(&dev->led_dev);
 
+   if (dev->pf_dev)
+   platform_device_unregister(dev->pf_dev);
+
if (toshiba_acpi)
toshiba_acpi = NULL;
 
@@ -1249,6 +1254,15 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->method_hci = hci_method;
acpi_dev->driver_data = dev;
 
+   dev->pf_dev = platform_device_register_simple("toshiba", -1, NULL, 0);
+   if (IS_ERR(dev->pf_dev)) {
+   ret = PTR_ERR(dev->pf_dev);
+   pr_err("Unable to register platform device\n");
+   kfree(dev);
+   return ret;
+   }
+   platform_set_drvdata(dev->pf_dev, dev);
+
if (toshiba_acpi_setup_keyboard(dev))
pr_info("Unable to activate hotkeys\n");
 
@@ -1284,7 +1298,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->led_dev.max_brightness = 1;
dev->led_dev.brightness_set = toshiba_illumination_set;
dev->led_dev.brightness_get = toshiba_illumination_get;
-   if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
+   if (!led_classdev_register(&dev->pf_dev->dev, &dev->led_dev))
dev->illumination_supported = 1;
}
 
@@ -1388,6 +1402,13 @@ static struct acpi_driver toshiba_acpi_driver = {
.drv.pm = &toshiba_acpi_pm,
 };
 
+static struct platform_driver platform_driver = {
+   .driver = {
+   .name = "toshiba",
+   .owner = THIS_MODULE,
+   },
+};
+
 static int __init toshiba_acpi_init(void)
 {
int ret;
@@ -1406,6 +1427,12 @@ static int __init toshiba_acpi_init(void)
return -ENODEV;
}
 
+   ret = platform_driver_register(&platform_driver);
+   if (ret < 0) {
+   pr_err("Failed to register platform driver: %d\n", ret);
+   return ret;
+   }
+
ret = acpi_bus_register_driver(&toshiba_acpi_driver);
if (ret) {
pr_err("Failed to register ACPI driver: %d\n", ret);
@@ -1418,6 +1445,7 @@ static int __init toshiba_acpi_init(void)
 static void __exit toshiba_acpi_exit(void)
 {
acpi_bus_unregister_driver(&toshiba_acpi_driver);
+   platform_driver_unregister(&platform_driver);
if (toshiba_proc_dir)
remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
 }
-- 
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/


[PATCH 5/8] toshiba_acpi: Add ECO led support

2013-11-04 Thread Azael Avalos
Newer Toshiba laptops now come with a feature called
ECO Mode, where the system is put in low power consupmtion
state and a green (world shaped with leaves) icon illuminates
indicating that the system is in such power state.

This patch adds support to turn on/off the ECO led by
creating and registering the toshiba::eco_mode led.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index f97f942..022c6e6 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -113,6 +113,7 @@ MODULE_LICENSE("GPL");
 #define HCI_LCD_BRIGHTNESS 0x002a
 #define HCI_WIRELESS   0x0056
 #define HCI_KBD_ILLUMINATION   0x0095
+#define HCI_ECO_MODE   0x0097
 #define SCI_ILLUMINATION   0x014e
 #define SCI_KBD_ILLUM_STATUS   0x015c
 
@@ -143,6 +144,7 @@ struct toshiba_acpi_dev {
struct backlight_device *backlight_dev;
struct led_classdev led_dev;
struct led_classdev kbd_led;
+   struct led_classdev eco_led;
 
int force_fan;
int last_key_event;
@@ -159,6 +161,7 @@ struct toshiba_acpi_dev {
unsigned int tr_backlight_supported:1;
unsigned int kbd_illum_supported:1;
unsigned int kbd_led_registered:1;
+   unsigned int eco_supported:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -538,6 +541,57 @@ static void toshiba_kbd_backlight_set(struct led_classdev 
*cdev,
}
 }
 
+/* Eco Mode support */
+static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
+{
+   acpi_status status;
+   u32 in[HCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
+   u32 out[HCI_WORDS];
+
+   status = hci_raw(dev, in, out);
+   if (ACPI_FAILURE(status) || out[0] == INPUT_DATA_ERROR) {
+   pr_info("ACPI call to get ECO led failed\n");
+   return 0;
+   }
+
+   return 1;
+}
+
+static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev 
*cdev)
+{
+   struct toshiba_acpi_dev *dev = container_of(cdev,
+   struct toshiba_acpi_dev, eco_led);
+   u32 in[HCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
+   u32 out[HCI_WORDS];
+   acpi_status status;
+
+   status = hci_raw(dev, in, out);
+   if (ACPI_FAILURE(status) || out[0] == INPUT_DATA_ERROR) {
+   pr_err("ACPI call to get ECO led failed\n");
+   return LED_OFF;
+   }
+
+   return out[2] ? LED_FULL : LED_OFF;
+}
+
+static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
+enum led_brightness brightness)
+{
+   struct toshiba_acpi_dev *dev = container_of(cdev,
+   struct toshiba_acpi_dev, eco_led);
+   u32 in[HCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
+   u32 out[HCI_WORDS];
+   acpi_status status;
+
+   /* Switch the Eco Mode led on/off */
+   in[2] = (brightness) ? 1 : 0;
+   status = hci_raw(dev, in, out);
+   if (ACPI_FAILURE(status) || out[0] == INPUT_DATA_ERROR) {
+   pr_err("ACPI call to set ECO led failed\n");
+   return;
+   }
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1413,6 +1467,9 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
if (dev->kbd_led_registered)
led_classdev_unregister(&dev->kbd_led);
 
+   if (dev->eco_supported)
+   led_classdev_unregister(&dev->eco_led);
+
if (dev->pf_dev)
platform_device_unregister(dev->pf_dev);
 
@@ -1515,6 +1572,15 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->illumination_supported = 1;
}
 
+   if (toshiba_eco_mode_available(dev)) {
+   dev->eco_led.name = "toshiba::eco_mode";
+   dev->eco_led.max_brightness = 1;
+   dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
+   dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
+   if (!led_classdev_register(&dev->pf_dev->dev, &dev->eco_led))
+   dev->eco_supported = 1;
+   }
+
ret = toshiba_kbd_illum_status_get(dev, &dummy);
if (!ret) {
dev->kbd_time = dummy >> HCI_MISC_SHIFT;
-- 
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/


[PATCH 7/8] toshiba_acpi: Add touchpad enable/disable support

2013-11-04 Thread Azael Avalos
Toshiba laptops have two ways of enabling/disabling the
touchpad, one with a hardwired button on top of the touchpad
that simply emmits scancodes to let userspace know it has changed,
and another with a SCI call that triggers (on Windows drivers)
whenever the user press the Fn-F9 (touchpad toggle) hotkey.

This patch adds support to enable/disable the touchpad
by exposing the _touchpad_ file in sysfs.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 9c718eb..0e14e9c 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -120,6 +120,7 @@ MODULE_LICENSE("GPL");
 #define HCI_ACCELEROMETER2 0x00a6
 #define SCI_ILLUMINATION   0x014e
 #define SCI_KBD_ILLUM_STATUS   0x015c
+#define SCI_TOUCHPAD   0x050e
 
 /* field definitions */
 #define HCI_ACCEL_MASK 0x7fff
@@ -168,6 +169,7 @@ struct toshiba_acpi_dev {
unsigned int kbd_led_registered:1;
unsigned int eco_supported:1;
unsigned int accelerometer_supported:1;
+   unsigned int touchpad_supported:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -643,6 +645,47 @@ static int toshiba_accelerometer_get(struct 
toshiba_acpi_dev *dev,
return 0;
 }
 
+/* TouchPad support */
+static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
+{
+   u32 result;
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   status = sci_write(dev, SCI_TOUCHPAD, state, &result);
+   sci_close(dev);
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to set the touchpad failed\n");
+   return -EIO;
+   } else if (result == NOT_SUPPORTED) {
+   return -ENODEV;
+   }
+
+   return 0;
+}
+
+static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
+{
+   u32 result;
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   status = sci_read(dev, SCI_TOUCHPAD, state, &result);
+   sci_close(dev);
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to query the touchpad failed\n");
+   return -EIO;
+   } else if (result == NOT_SUPPORTED) {
+   return -ENODEV;
+   }
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1267,16 +1310,49 @@ static ssize_t toshiba_position_show(struct device *dev,
return sprintf(buf, "%d %d %d\n", x, y, z);
 }
 
+static ssize_t toshiba_touchpad_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
+   int state;
+
+   /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
+   if (sscanf(buf, "%i", &state) == 1 && (state == 0 || state == 1)) {
+   if (toshiba_touchpad_set(toshiba, state) < 0)
+   return -EIO;
+   }
+
+   return count;
+}
+
+static ssize_t toshiba_touchpad_show(struct device *dev,
+struct device_attribute *attr, char *buf)
+{
+   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
+   u32 state;
+   int ret;
+
+   ret = toshiba_touchpad_get(toshiba, &state);
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%i\n", state);
+}
+
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
 static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
 static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
+static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
+  toshiba_touchpad_show, toshiba_touchpad_store);
 
 static struct attribute *toshiba_attributes[] = {
&dev_attr_kbd_backlight_mode.attr,
&dev_attr_kbd_backlight_timeout.attr,
&dev_attr_position.attr,
+   &dev_attr_touchpad.attr,
NULL,
 };
 
@@ -1294,6 +1370,8 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (driver->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
else if (attr == &dev_attr_position.attr)
exists = (driver->accelerometer_supported) ? true : false;
+   else if (attr == &dev_attr_touchpad.attr)
+   exists = (driver->touchpad_supported) ? true : false;
 
return exists ? attr->mode : 0;
 }

[PATCH 6/8] toshiba_acpi: Add accelerometer support

2013-11-04 Thread Azael Avalos
Recent Toshiba laptops now come equiped with a built in
accelerometer (TOS620A), but such device does not
expose the axis information, however, HCI calls 0x006d
and 0x00a6 can be used to query such info.

This patch adds support to read the axis values and
exposing them through the _position_ sysfs file.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 022c6e6..9c718eb 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -103,6 +103,8 @@ MODULE_LICENSE("GPL");
 #define INPUT_DATA_ERROR   0x8300
 #define NOT_PRESENT0x8600
 #define FIFO_EMPTY 0x8c00
+#define DATA_NOT_AVAILABLE 0x8d20
+#define NOT_INITIALIZED0x8d50
 
 /* registers */
 #define HCI_FAN0x0004
@@ -112,12 +114,15 @@ MODULE_LICENSE("GPL");
 #define HCI_HOTKEY_EVENT   0x001e
 #define HCI_LCD_BRIGHTNESS 0x002a
 #define HCI_WIRELESS   0x0056
+#define HCI_ACCELEROMETER  0x006d
 #define HCI_KBD_ILLUMINATION   0x0095
 #define HCI_ECO_MODE   0x0097
+#define HCI_ACCELEROMETER2 0x00a6
 #define SCI_ILLUMINATION   0x014e
 #define SCI_KBD_ILLUM_STATUS   0x015c
 
 /* field definitions */
+#define HCI_ACCEL_MASK 0x7fff
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
 #define HCI_LCD_BRIGHTNESS_BITS3
@@ -162,6 +167,7 @@ struct toshiba_acpi_dev {
unsigned int kbd_illum_supported:1;
unsigned int kbd_led_registered:1;
unsigned int eco_supported:1;
+   unsigned int accelerometer_supported:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -592,6 +598,51 @@ static void toshiba_eco_mode_set_status(struct 
led_classdev *cdev,
}
 }
 
+/* Accelerometer support */
+static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
+{
+   u32 in[HCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
+   u32 out[HCI_WORDS];
+   acpi_status status;
+
+   /* Check if the accelerometer call exists,
+* this call also serves as initialization
+*/
+   status = hci_raw(dev, in, out);
+   if (ACPI_FAILURE(status) || out[0] == INPUT_DATA_ERROR) {
+   pr_err("ACPI call to query the accelerometer failed\n");
+   return -EIO;
+   } else if (out[0] == DATA_NOT_AVAILABLE || out[0] == NOT_INITIALIZED) {
+   pr_err("Accelerometer not initialized\n");
+   return -EIO;
+   } else if (out[0] == NOT_SUPPORTED) {
+   pr_info("Accelerometer not supported\n");
+   return -ENODEV;
+   }
+
+   return 0;
+}
+
+static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
+ u32 *xy, u32 *z)
+{
+   u32 in[HCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
+   u32 out[HCI_WORDS];
+   acpi_status status;
+
+   /* Check the Accelerometer status */
+   status = hci_raw(dev, in, out);
+   if (ACPI_FAILURE(status) || out[0] == INPUT_DATA_ERROR) {
+   pr_err("ACPI call to query the accelerometer failed\n");
+   return -EIO;
+   }
+
+   *xy = out[2];
+   *z = out[4];
+
+   return 0;
+}
+
 /* Bluetooth rfkill handlers */
 
 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1195,14 +1246,37 @@ static ssize_t toshiba_kbd_bl_timeout_show(struct 
device *dev,
return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
 }
 
+static ssize_t toshiba_position_show(struct device *dev,
+struct device_attribute *attr, char *buf)
+{
+   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
+   u32 xyval, zval, tmp;
+   u16 x, y, z;
+   int ret;
+
+   xyval = zval = 0;
+   ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
+   if (ret < 0)
+   return ret;
+
+   x = xyval & HCI_ACCEL_MASK;
+   tmp = xyval >> HCI_MISC_SHIFT;
+   y = tmp & HCI_ACCEL_MASK;
+   z = zval & HCI_ACCEL_MASK;
+
+   return sprintf(buf, "%d %d %d\n", x, y, z);
+}
+
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
 static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
+static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
 
 static struct attribute *toshiba_attributes[] = {
&dev_at

[PATCH 8/8] toshiba_acpi: Update version and copyright information

2013-11-04 Thread Azael Avalos
Add myself to the copyright list and bump version to
0.20 since several new features have been added.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 0e14e9c..22178f2 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -5,6 +5,7 @@
  *  Copyright (C) 2002-2004 John Belmonte
  *  Copyright (C) 2008 Philip Langdale
  *  Copyright (C) 2010 Pierre Ducroquet
+ *  Copyright (C) 2013 Azael Avalos
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -37,7 +38,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#define TOSHIBA_ACPI_VERSION   "0.19"
+#define TOSHIBA_ACPI_VERSION   "0.20"
 #define PROC_INTERFACE_VERSION 1
 
 #include 
-- 
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/


[PATCH 2/8] toshiba_acpi: Adapt illumination_* code to use the new SCI

2013-11-04 Thread Azael Avalos
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 
---
 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) {
+   

[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) {
+   r

[PATCH 4/8] toshiba_acpi: Add kbd backlight support and sysfs files

2013-11-04 Thread Azael Avalos
Toshiba laptops equiped with an illuminated keyboard
can operate in two different modes: Auto and FN-Z.

The Auto mode turns on the led on keystrokes and
automatically turns it off after some (configurable)
time the last key was pressed.

The FN-Z mode is used to toggle the keyboard led on/off
by userspace.

This patch adds support to set the desired KBD mode and
timeout via sysfs, creates and registers toshiba::kbd_backlight
led device whenever the mode is set to FN-Z.

The acceptable values for mode are: 1 (Auto) and 2 (Fn-Z)
The time values range are: 1-60 seconds

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 226e0b5..f97f942 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -112,7 +112,9 @@ MODULE_LICENSE("GPL");
 #define HCI_HOTKEY_EVENT   0x001e
 #define HCI_LCD_BRIGHTNESS 0x002a
 #define HCI_WIRELESS   0x0056
+#define HCI_KBD_ILLUMINATION   0x0095
 #define SCI_ILLUMINATION   0x014e
+#define SCI_KBD_ILLUM_STATUS   0x015c
 
 /* field definitions */
 #define HCI_HOTKEY_DISABLE 0x0b
@@ -120,6 +122,7 @@ MODULE_LICENSE("GPL");
 #define HCI_LCD_BRIGHTNESS_BITS3
 #define HCI_LCD_BRIGHTNESS_SHIFT   (16-HCI_LCD_BRIGHTNESS_BITS)
 #define HCI_LCD_BRIGHTNESS_LEVELS  (1 << HCI_LCD_BRIGHTNESS_BITS)
+#define HCI_MISC_SHIFT 0x10
 #define HCI_VIDEO_OUT_LCD  0x1
 #define HCI_VIDEO_OUT_CRT  0x2
 #define HCI_VIDEO_OUT_TV   0x4
@@ -127,6 +130,8 @@ MODULE_LICENSE("GPL");
 #define HCI_WIRELESS_BT_PRESENT0x0f
 #define HCI_WIRELESS_BT_ATTACH 0x40
 #define HCI_WIRELESS_BT_POWER  0x80
+#define SCI_KBD_MODE_FNZ   0x1
+#define SCI_KBD_MODE_AUTO  0x2
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -137,10 +142,13 @@ struct toshiba_acpi_dev {
struct work_struct hotkey_work;
struct backlight_device *backlight_dev;
struct led_classdev led_dev;
+   struct led_classdev kbd_led;
 
int force_fan;
int last_key_event;
int key_event_valid;
+   int kbd_mode;
+   int kbd_time;
 
unsigned int illumination_supported:1;
unsigned int video_supported:1;
@@ -149,6 +157,9 @@ struct toshiba_acpi_dev {
unsigned int ntfy_supported:1;
unsigned int info_supported:1;
unsigned int tr_backlight_supported:1;
+   unsigned int kbd_illum_supported:1;
+   unsigned int kbd_led_registered:1;
+   unsigned int sysfs_created:1;
 
struct mutex mutex;
 };
@@ -444,6 +455,89 @@ static enum led_brightness toshiba_illumination_get(struct 
led_classdev *cdev)
return state ? LED_FULL : LED_OFF;
 }
 
+/* KBD Illumination */
+static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
+{
+   u32 result;
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result);
+   if (ACPI_FAILURE(status) || result == INPUT_DATA_ERROR) {
+   pr_err("ACPI call to set KBD backlight status failed\n");
+   return -EIO;
+   } else if (result == NOT_SUPPORTED) {
+   pr_info("Keyboard backlight status not supported\n");
+   return -ENODEV;
+   }
+   sci_close(dev);
+
+   return 0;
+}
+
+static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 
*time)
+{
+   u32 result;
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return -EIO;
+
+   status = sci_read(dev, SCI_KBD_ILLUM_STATUS, time, &result);
+   if (ACPI_FAILURE(status) || result == INPUT_DATA_ERROR) {
+   pr_err("ACPI call to get KBD backlight status failed\n");
+   return -EIO;
+   } else if (result == NOT_SUPPORTED) {
+   pr_info("Keyboard backlight status not supported\n");
+   return -ENODEV;
+   }
+   sci_close(dev);
+
+   return 0;
+}
+
+static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
+{
+   struct toshiba_acpi_dev *dev = container_of(cdev,
+   struct toshiba_acpi_dev, kbd_led);
+   u32 state, result;
+   acpi_status status;
+
+   /* Check the keyboard backlight state */
+   status = hci_read1(dev, HCI_KBD_ILLUMINATION, &state, &result);
+   if (ACPI_FAILURE(status) || result == INPUT_DATA_ERROR) {
+   pr_err("ACPI call to get the keyboard backlight failed\n");
+   return LED_OFF;
+   } else if (result == NOT_SUPP

[PATCH 0/8] toshiba_acpi: New features added and a fix

2013-11-04 Thread Azael Avalos
Up for review, the following patch series add new features
found on newer Toshiba laptops.

The first two fix an illumination detection bug, so consider
applying those to stable.

The rest just add support for touchpad, accelerometer axes,
keyboard backlight and ECO led, plus platform support, bumping
the version to 0.20.

These apply cleanly to Matthew's platform tree and with
just some fuzz to next tree.

[PATCH 1/8] toshiba_acpi: Add System Configuration Interface (SCI)
[PATCH 2/8] toshiba_acpi: Adapt illumination_* code to use the new SCI
[PATCH 3/8] toshiba_acpi: Add platform support
[PATCH 4/8] toshiba_acpi: Add kbd backlight support and sysfs files
[PATCH 5/8] toshiba_acpi: Add ECO led support
[PATCH 6/8] toshiba_acpi: Add accelerometer support
[PATCH 7/8] toshiba_acpi: Add touchpad enable/disable support
[PATCH 8/8] toshiba_acpi: Update version and copyright information


Saludos
Azael

--
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/


[PATCH 3/4] toshiba_acpi: Change HCI/SCI functions return code type

2014-09-23 Thread Azael Avalos
Currently the HCI/SCI read/write functions are returning
the status of the ACPI call and also assigning the
returned value of the HCI/SCI function.

This patch changes such functions, returning the value
of the HCI/SCI function instead of the ACPI call status.

The next patch will change all the HCI/SCI functions
to reflect the change made in this patch.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 5b16d11..43385f7 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -316,47 +316,49 @@ static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
  * may be useful (such as "not supported").
  */
 
-static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg,
- u32 in1, u32 *result)
+static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
 {
u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
 }
 
-static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg,
-u32 *out1, u32 *result)
+static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
 {
u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status))
+   return TOS_FAILURE;
+
*out1 = out[2];
-   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return out[0];
 }
 
-static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg,
- u32 in1, u32 in2, u32 *result)
+static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2)
 {
u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
 }
 
-static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg,
-u32 *out1, u32 *out2, u32 *result)
+static u32 hci_read2(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 
*out2)
 {
u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status))
+   return TOS_FAILURE;
+
*out1 = out[2];
*out2 = out[3];
-   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return out[0];
 }
 
 /* common sci tasks
@@ -406,25 +408,26 @@ static void sci_close(struct toshiba_acpi_dev *dev)
pr_info("Toshiba SCI is not present\n");
 }
 
-static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg,
-   u32 *out1, u32 *result)
+static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
 {
u32 in[HCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status))
+   return TOS_FAILURE;
+
*out1 = out[2];
-   *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return out[0];
 }
 
-static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg,
-u32 in1, u32 *result)
+static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
 {
u32 in[HCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
u32 out[HCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
-   *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
 }
 
 /* Illumination support */
-- 
2.0.0

--
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/


[PATCH 2/4] toshiba_acpi: Unify return codes prefix to from HCI/SCI to TOS

2014-09-23 Thread Azael Avalos
The return codes are split in between HCI/SCI prefixes,
but they are shared (used) by both interfaces, mixing
hci_read/write calls with SCI_* return codes, and
sci_read/write calls with HCI_* ones.

This patch changes the prefix of the return codes
definitions, dropping the HCI/SCI naming and instead
replacing it with TOS (for TOShiba).

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index b7030dc..5b16d11 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -95,17 +95,18 @@ MODULE_LICENSE("GPL");
 #define SCI_SET0xf400
 
 /* return codes */
-#define HCI_SUCCESS0x
-#define HCI_FAILURE0x1000
-#define HCI_NOT_SUPPORTED  0x8000
-#define HCI_EMPTY  0x8c00
-#define HCI_DATA_NOT_AVAILABLE 0x8d20
-#define HCI_NOT_INITIALIZED0x8d50
-#define SCI_OPEN_CLOSE_OK  0x0044
-#define SCI_ALREADY_OPEN   0x8100
-#define SCI_NOT_OPENED 0x8200
-#define SCI_INPUT_DATA_ERROR   0x8300
-#define SCI_NOT_PRESENT0x8600
+#define TOS_SUCCESS0x
+#define TOS_OPEN_CLOSE_OK  0x0044
+#define TOS_FAILURE0x1000
+#define TOS_NOT_SUPPORTED  0x8000
+#define TOS_ALREADY_OPEN   0x8100
+#define TOS_NOT_OPENED 0x8200
+#define TOS_INPUT_DATA_ERROR   0x8300
+#define TOS_WRITE_PROTECTED0x8400
+#define TOS_NOT_PRESENT0x8600
+#define TOS_FIFO_EMPTY 0x8c00
+#define TOS_DATA_NOT_AVAILABLE 0x8d20
+#define TOS_NOT_INITIALIZED0x8d50
 
 /* registers */
 #define HCI_FAN0x0004
@@ -321,7 +322,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 = tci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
return status;
 }
 
@@ -332,7 +333,7 @@ static acpi_status hci_read1(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 out[HCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
*out1 = out[2];
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
return status;
 }
 
@@ -342,7 +343,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 = tci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
return status;
 }
 
@@ -354,7 +355,7 @@ static acpi_status hci_read2(struct toshiba_acpi_dev *dev, 
u32 reg,
acpi_status status = tci_raw(dev, in, out);
*out1 = out[2];
*out2 = out[3];
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
return status;
 }
 
@@ -368,17 +369,17 @@ static int sci_open(struct toshiba_acpi_dev *dev)
acpi_status status;
 
status = tci_raw(dev, in, out);
-   if  (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
+   if  (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
pr_err("ACPI call to open SCI failed\n");
return 0;
}
 
-   if (out[0] == SCI_OPEN_CLOSE_OK) {
+   if (out[0] == TOS_OPEN_CLOSE_OK) {
return 1;
-   } else if (out[0] == SCI_ALREADY_OPEN) {
+   } else if (out[0] == TOS_ALREADY_OPEN) {
pr_info("Toshiba SCI already opened\n");
return 1;
-   } else if (out[0] == SCI_NOT_PRESENT) {
+   } else if (out[0] == TOS_NOT_PRESENT) {
pr_info("Toshiba SCI is not present\n");
}
 
@@ -392,16 +393,16 @@ static void sci_close(struct toshiba_acpi_dev *dev)
acpi_status status;
 
status = tci_raw(dev, in, out);
-   if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
pr_err("ACPI call to close SCI failed\n");
return;
}
 
-   if (out[0] == SCI_OPEN_CLOSE_OK)
+   if (out[0] == TOS_OPEN_CLOSE_OK)
return;
-   else if (out[0] == SCI_NOT_OPENED)
+   else if (out[0] == TOS_NOT_OPENED)
pr_info("Toshiba SCI not opened\n");
-   else if (out[0] == SCI_NOT_PRESENT)
+   else if (out[0] == 

[PATCH 4/4] toshiba_acpi: Adapt functions to the changes made to HCI/SCI

2014-09-23 Thread Azael Avalos
The previous patch changed the return type for the HCI/SCI
read/write functions.

This patch adapts the code for that change, as now the
"result" parameter is returned by those functions, instead
of the ACPI status call.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 43385f7..582563d 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -459,7 +459,6 @@ static void toshiba_illumination_set(struct led_classdev 
*cdev,
struct toshiba_acpi_dev *dev = container_of(cdev,
struct toshiba_acpi_dev, led_dev);
u32 state, result;
-   acpi_status status;
 
/* First request : initialize communication. */
if (!sci_open(dev))
@@ -467,9 +466,9 @@ static void toshiba_illumination_set(struct led_classdev 
*cdev,
 
/* Switch the illumination on/off */
state = brightness ? 1 : 0;
-   status = sci_write(dev, SCI_ILLUMINATION, state, &result);
+   result = sci_write(dev, SCI_ILLUMINATION, state);
sci_close(dev);
-   if (ACPI_FAILURE(status)) {
+   if (result == TOS_FAILURE) {
pr_err("ACPI call for illumination failed\n");
return;
} else if (result == TOS_NOT_SUPPORTED) {
@@ -483,16 +482,15 @@ static enum led_brightness 
toshiba_illumination_get(struct led_classdev *cdev)
struct toshiba_acpi_dev *dev = container_of(cdev,
struct toshiba_acpi_dev, led_dev);
u32 state, result;
-   acpi_status status;
 
/* First request : initialize communication. */
if (!sci_open(dev))
return LED_OFF;
 
/* Check the illumination */
-   status = sci_read(dev, SCI_ILLUMINATION, &state, &result);
+   result = sci_read(dev, SCI_ILLUMINATION, &state);
sci_close(dev);
-   if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) {
+   if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
pr_err("ACPI call for illumination failed\n");
return LED_OFF;
} else if (result == TOS_NOT_SUPPORTED) {
@@ -543,14 +541,13 @@ static int toshiba_kbd_illum_available(struct 
toshiba_acpi_dev *dev)
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
 {
u32 result;
-   acpi_status status;
 
if (!sci_open(dev))
return -EIO;
 
-   status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result);
+   result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
sci_close(dev);
-   if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) {
+   if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
pr_err("ACPI call to set KBD backlight status failed\n");
return -EIO;
} else if (result == TOS_NOT_SUPPORTED) {
@@ -564,14 +561,13 @@ static int toshiba_kbd_illum_status_set(struct 
toshiba_acpi_dev *dev, u32 time)
 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 
*time)
 {
u32 result;
-   acpi_status status;
 
if (!sci_open(dev))
return -EIO;
 
-   status = sci_read(dev, SCI_KBD_ILLUM_STATUS, time, &result);
+   result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
sci_close(dev);
-   if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) {
+   if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
pr_err("ACPI call to get KBD backlight status failed\n");
return -EIO;
} else if (result == TOS_NOT_SUPPORTED) {
@@ -587,11 +583,10 @@ static enum led_brightness 
toshiba_kbd_backlight_get(struct led_classdev *cdev)
struct toshiba_acpi_dev *dev = container_of(cdev,
struct toshiba_acpi_dev, kbd_led);
u32 state, result;
-   acpi_status status;
 
/* Check the keyboard backlight state */
-   status = hci_read1(dev, HCI_KBD_ILLUMINATION, &state, &result);
-   if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) {
+   result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state);
+   if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
pr_err("ACPI call to get the keyboard backlight failed\n");
return LED_OFF;
} else if (result == TOS_NOT_SUPPORTED) {
@@ -608,12 +603,11 @@ static void toshiba_kbd_backlight_set(struct led_classdev 
*cdev,
struct toshiba_acpi_dev *dev = container_of(cdev,
struct toshiba_acpi_dev, kbd_led);
u32 state, result;
-   acpi_status status;
 
/* Set the keyboard backlight state */
state = bright

[PATCH 1/4] toshiba_acpi: Rename hci_raw to tci_raw

2014-09-23 Thread Azael Avalos
The function name hci_raw was used before to reflect
a raw (read/write) call to the Toshiba's Hardware
Configuration Interface (HCI), however, since the
introduction of the System Configuration Interface
(SCI), that "name" no longer applies.

This patch changes the name of that function to
tci_raw (for Toshiba Configuration Interface), and
change the comments about it.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index edd8f3d..b7030dc 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -71,7 +71,7 @@ MODULE_LICENSE("GPL");
 /* Toshiba ACPI method paths */
 #define METHOD_VIDEO_OUT   "\\_SB_.VALX.DSSX"
 
-/* Toshiba HCI interface definitions
+/* 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
@@ -274,10 +274,10 @@ static int write_acpi_int(const char *methodName, int val)
return (status == AE_OK) ? 0 : -EIO;
 }
 
-/* Perform a raw HCI call.  Here we don't care about input or output buffer
- * format.
+/* Perform a raw configuration call.  Here we don't care about input or output
+ * buffer format.
  */
-static acpi_status hci_raw(struct toshiba_acpi_dev *dev,
+static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
   const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
 {
struct acpi_object_list params;
@@ -320,7 +320,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);
+   acpi_status status = tci_raw(dev, in, out);
*result = (status == AE_OK) ? out[0] : HCI_FAILURE;
return status;
 }
@@ -330,7 +330,7 @@ static acpi_status hci_read1(struct toshiba_acpi_dev *dev, 
u32 reg,
 {
u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
u32 out[HCI_WORDS];
-   acpi_status status = hci_raw(dev, in, out);
+   acpi_status status = tci_raw(dev, in, out);
*out1 = out[2];
*result = (status == AE_OK) ? out[0] : HCI_FAILURE;
return status;
@@ -341,7 +341,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);
+   acpi_status status = tci_raw(dev, in, out);
*result = (status == AE_OK) ? out[0] : HCI_FAILURE;
return status;
 }
@@ -351,7 +351,7 @@ static acpi_status hci_read2(struct toshiba_acpi_dev *dev, 
u32 reg,
 {
u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
u32 out[HCI_WORDS];
-   acpi_status status = hci_raw(dev, in, out);
+   acpi_status status = tci_raw(dev, in, out);
*out1 = out[2];
*out2 = out[3];
*result = (status == AE_OK) ? out[0] : HCI_FAILURE;
@@ -367,7 +367,7 @@ static int sci_open(struct toshiba_acpi_dev *dev)
u32 out[HCI_WORDS];
acpi_status status;
 
-   status = hci_raw(dev, in, out);
+   status = tci_raw(dev, in, out);
if  (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
pr_err("ACPI call to open SCI failed\n");
return 0;
@@ -391,7 +391,7 @@ static void sci_close(struct toshiba_acpi_dev *dev)
u32 out[HCI_WORDS];
acpi_status status;
 
-   status = hci_raw(dev, in, out);
+   status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
pr_err("ACPI call to close SCI failed\n");
return;
@@ -410,7 +410,7 @@ static acpi_status sci_read(struct toshiba_acpi_dev *dev, 
u32 reg,
 {
u32 in[HCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
u32 out[HCI_WORDS];
-   acpi_status status = hci_raw(dev, in, out);
+   acpi_status status = tci_raw(dev, in, out);
*out1 = out[2];
*result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE;
return status;
@@ -421,7 +421,7 @@ static acpi_status sci_write(struct toshiba_acpi_dev *dev, 
u32 reg,
 {
u32 in[HCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
u32 out[HCI_WORDS];
-   acpi_status status = hci_raw(dev, in, out);
+   acpi_status status = tci_raw(dev, in, out);
*result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE;
return status;
 }
@@ -436,7 +436,7 @@ static int toshiba_illumination_available(struct 
toshiba_acpi_dev *dev)
if (!sci_open(dev))
return 0;
 
-   status = hci_raw(dev, in, out);
+   status = tci_raw(dev, in, out);
sci_close(dev);
   

[PATCH 0/4] toshiba_acpi: Return codes cleanup

2014-09-23 Thread Azael Avalos
Up for review.

This series of patches are a cleanup thee Toshiba
configuration interface return codes (unification),
as well as changing the returned type of the HCI/SCI
read/write functions from acpi_status to u32, since
the "status" was never checked on most of the functions.

I would like these to be queued for 3.18 if possible.

Azael Avalos (4):
  toshiba_acpi: Rename hci_raw to tci_raw
  toshiba_acpi: Unify return codes prefix to from HCI/SCI to TOS
  toshiba_acpi: Change HCI/SCI functions return code type
  toshiba_acpi: Adapt functions to the changes made to HCI/SCI

 drivers/platform/x86/toshiba_acpi.c | 289 ++--
 1 file changed, 142 insertions(+), 147 deletions(-)

-- 
2.0.0

--
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/


Re: [PATCH 1/4] toshiba_acpi: Rename hci_raw to tci_raw

2014-09-25 Thread Azael Avalos
2014-09-25 21:01 GMT-06:00 Darren Hart :
> On Tue, Sep 23, 2014 at 06:24:25PM -0600, Azael Avalos wrote:
>> The function name hci_raw was used before to reflect
>> a raw (read/write) call to the Toshiba's Hardware
>> Configuration Interface (HCI), however, since the
>> introduction of the System Configuration Interface
>> (SCI), that "name" no longer applies.
>>
>> This patch changes the name of that function to
>> tci_raw (for Toshiba Configuration Interface), and
>> change the comments about it.
>
> I'm not following the motivation for this change. The HCI clearly still 
> exists,
> at least on the platforms this driver was written to support. When/Where was 
> the
> "SCI" "introduced" in a way that requires a change here? Was this a change by
> Toshiba you are refering to?

The HCI and SCI form an integral part of the Toshiba configuration scheme,
the SCI has been present on any Toshiba branded laptop to date, what
was not present (at least on toshiba_acpi) was (propper) SCI support
until the patches I sent.

Take a look at Jonathan Buzzard documentation [1], and also the toshiba
module under char, the documentation was written in 1999, and the
module has a (starting) date of 1996.

By the time toshiba_acpi was written, only HCI functions were accessed,
as well as the configuration handle was (and still is, depending on model)
named GHCI, and so the comments refer to it, now that we have SCI
(driver support) on board, the naming seems obsolete, or at least
misguiding, as the HCI is not the only configuration interface.

Hope this clears things a bit.

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

>
>
>>
>> Signed-off-by: Azael Avalos 
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 40 
>> ++---
>>  1 file changed, 20 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index edd8f3d..b7030dc 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -71,7 +71,7 @@ MODULE_LICENSE("GPL");
>>  /* Toshiba ACPI method paths */
>>  #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
>>
>> -/* Toshiba HCI interface definitions
>> +/* Toshiba configuration interface definitions
>>   *
>>   * HCI is Toshiba's "Hardware Control Interface" which is supposed to
>
> I'm not sure this patch is appropriate/necessary, but if so, you missed a spot
> here :)

Oh no, this is intentional, what I probably should have done here is be more
verbose about it, perhaps something like:

/*
 * The Toshiba configuration interface is composed of the HCI and the
 * SCI, which are defined as
...

>
> --
> Darren Hart
> Intel Open Source Technology Center


Cheers
Azael

-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


Re: [PATCH 3/4] toshiba_acpi: Change HCI/SCI functions return code type

2014-09-25 Thread Azael Avalos
2014-09-25 21:11 GMT-06:00 Darren Hart :
> On Tue, Sep 23, 2014 at 06:24:27PM -0600, Azael Avalos wrote:
>> Currently the HCI/SCI read/write functions are returning
>> the status of the ACPI call and also assigning the
>> returned value of the HCI/SCI function.
>>
>> This patch changes such functions, returning the value
>> of the HCI/SCI function instead of the ACPI call status.
>>
>> The next patch will change all the HCI/SCI functions
>> to reflect the change made in this patch.
>
> If you are changing what the functions return in this patch, you also need to
> update the call sites at the same time (same patch).

Ok

>
>>
>> Signed-off-by: Azael Avalos 
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 51 
>> -
>>  1 file changed, 27 insertions(+), 24 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index 5b16d11..43385f7 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -316,47 +316,49 @@ static acpi_status tci_raw(struct toshiba_acpi_dev 
>> *dev,
>>   * may be useful (such as "not supported").
>>   */
>
> The full text of the comment above is:
>
> /* common hci tasks (get or set one or two value)
>  *
>  * In addition to the ACPI status, the HCI system returns a result which
>  * may be useful (such as "not supported").
>  */
>
> Is this no longer relevant?

On the contrary, the "result" parameter is the one being returned by the
modified read/write functions now, and was (and still is) the only one
being checked for support, error, or otherwise, depending on what the
Toshiba method returns.

>
> I agree that the return and status approach seems suboptimal, but I'm not 
> clear on the motivation for the change. Is there something besides cleanup 
> you're attempting to work toward with this series?

Cleanup mostly, what's the purpose of returning a value,
if that value is never checked? Better return a value that
indeed is being checked, and contains useful info about
the status of the queried function (such as "not supported")
:-)


>
> --
> Darren Hart
> Intel Open Source Technology Center

Cheers
Azael


-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


[PATCH v2 4/5] toshiba_acpi: Support new keyboard backlight type

2014-09-10 Thread Azael Avalos
Newer Toshiba models now come with a new (and different) keyboard
backlight implementation with three modes of operation: TIMER,
ON and OFF, and the LED is controlled internally by the firmware.

This patch adds support for that type of backlight, changing the
existing code to accomodate the new implementation.

The timeout value range is now 1-60 seconds, and the accepted
modes are now: 1 (FN-Z), 2 (AUTO or TIMER), 8(ON) and 10 (OFF),
this adds two new entries keyboard_type and available_kbd_modes,
the first shows the keyboard type and the latter shows the
supported modes depending on the type.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 4c8fa7b..08147c5 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -140,6 +140,10 @@ MODULE_LICENSE("GPL");
 #define HCI_WIRELESS_BT_POWER  0x80
 #define SCI_KBD_MODE_FNZ   0x1
 #define SCI_KBD_MODE_AUTO  0x2
+#define SCI_KBD_MODE_ON0x8
+#define SCI_KBD_MODE_OFF   0x10
+#define SCI_KBD_MODE_MAX   SCI_KBD_MODE_OFF
+#define SCI_KBD_TIME_MAX   0x3c001a
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -155,6 +159,7 @@ struct toshiba_acpi_dev {
int force_fan;
int last_key_event;
int key_event_valid;
+   int kbd_type;
int kbd_mode;
int kbd_time;
 
@@ -495,6 +500,42 @@ static enum led_brightness toshiba_illumination_get(struct 
led_classdev *cdev)
 }
 
 /* KBD Illumination */
+static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
+{
+   u32 in[HCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
+   u32 out[HCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return 0;
+
+   status = hci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
+   pr_err("ACPI call to query kbd illumination support failed\n");
+   return 0;
+   } else if (out[0] == HCI_NOT_SUPPORTED) {
+   pr_info("Keyboard illumination not available\n");
+   return 0;
+   }
+
+   /* Check for keyboard backlight timeout max value,
+   /* previous kbd backlight implementation set this to
+* 0x3c0003, and now the new implementation set this
+* to 0x3c001a, use this to distinguish between them
+*/
+   if (out[3] == SCI_KBD_TIME_MAX)
+   dev->kbd_type = 2;
+   else
+   dev->kbd_type = 1;
+   /* Get the current keyboard backlight mode */
+   dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
+   /* Get the current time (1-60 seconds) */
+   dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
+
+   return 1;
+}
+
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
 {
u32 result;
@@ -1268,20 +1309,46 @@ static ssize_t toshiba_kbd_bl_mode_store(struct device 
*dev,
ret = kstrtoint(buf, 0, &mode);
if (ret)
return ret;
-   if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
+   if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO &&
+   mode != SCI_KBD_MODE_ON && mode != SCI_KBD_MODE_OFF)
return -EINVAL;
 
+   /* Check for supported modes depending on keyboard backlight type */
+   if (toshiba->kbd_type == 1) {
+   /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
+   if (mode == SCI_KBD_MODE_ON || mode == SCI_KBD_MODE_OFF)
+   return -EINVAL;
+   } else if (toshiba->kbd_type == 2) {
+   /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
+   if (mode == SCI_KBD_MODE_FNZ)
+   return -EINVAL;
+   }
+
/* Set the Keyboard Backlight Mode where:
-* Mode - Auto (2) | FN-Z (1)
 *  Auto - KBD backlight turns off automatically in given time
 *  FN-Z - KBD backlight "toggles" when hotkey pressed
+*  ON   - KBD backlight is always on
+*  OFF  - KBD backlight is always off
 */
+
+   /* Only make a change if the actual mode has changed */
if (toshiba->kbd_mode != mode) {
+   /* Shift the time to "base time" (0x3c == 60 seconds) */
time = toshiba->kbd_time << HCI_MISC_SHIFT;
-   time = time + toshiba->kbd_mode;
+
+   /* OR the "base time" to the actual method format */
+   if (toshiba->kbd_type == 1) {
+   /* Type 1 requires the current mode */
+  

[PATCH v2 5/5] toshiba_acpi: Change touchpad store to check for invalid values

2014-09-10 Thread Azael Avalos
The function toshiba_touchpad_store is not checking
for invalid values and simply returns silently.

This patch checks for invalid values and returns accordingly.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 08147c5..5a2324d 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1429,12 +1429,18 @@ static ssize_t toshiba_touchpad_store(struct device 
*dev,
 {
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
int state;
+   int ret;
 
/* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
-   if (sscanf(buf, "%i", &state) == 1 && (state == 0 || state == 1)) {
-   if (toshiba_touchpad_set(toshiba, state) < 0)
-   return -EIO;
-   }
+   ret = kstrtoint(buf, 0, &state);
+   if (ret)
+   return ret;
+   if (state != 0 && state != 1)
+   return -EINVAL;
+
+   ret = toshiba_touchpad_set(toshiba, state);
+   if (ret)
+   return ret;
 
return count;
 }
-- 
2.0.0

--
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/


Re: [PATCH v2 4/5] toshiba_acpi: Support new keyboard backlight type

2014-09-11 Thread Azael Avalos
Hi Darren,

2014-09-11 18:36 GMT-06:00 Darren Hart :
> On Wed, Sep 10, 2014 at 09:01:56PM -0600, Azael Avalos wrote:
>
> Hi Azael,
>
>> Newer Toshiba models now come with a new (and different) keyboard
>> backlight implementation with three modes of operation: TIMER,
>> ON and OFF, and the LED is controlled internally by the firmware.
>>
>> This patch adds support for that type of backlight, changing the
>> existing code to accomodate the new implementation.
>>
>> The timeout value range is now 1-60 seconds, and the accepted
>> modes are now: 1 (FN-Z), 2 (AUTO or TIMER), 8(ON) and 10 (OFF),
>> this adds two new entries keyboard_type and available_kbd_modes,
>> the first shows the keyboard type and the latter shows the
>> supported modes depending on the type.
>>
>> Signed-off-by: Azael Avalos 
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 117 
>> +++-
>>  1 file changed, 102 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index 4c8fa7b..08147c5 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -140,6 +140,10 @@ MODULE_LICENSE("GPL");
>>  #define HCI_WIRELESS_BT_POWER0x80
>>  #define SCI_KBD_MODE_FNZ 0x1
>>  #define SCI_KBD_MODE_AUTO0x2
>> +#define SCI_KBD_MODE_ON  0x8
>> +#define SCI_KBD_MODE_OFF 0x10
>> +#define SCI_KBD_MODE_MAX SCI_KBD_MODE_OFF
>> +#define SCI_KBD_TIME_MAX 0x3c001a
>>
>>  struct toshiba_acpi_dev {
>>   struct acpi_device *acpi_dev;
>> @@ -155,6 +159,7 @@ struct toshiba_acpi_dev {
>>   int force_fan;
>>   int last_key_event;
>>   int key_event_valid;
>> + int kbd_type;
>>   int kbd_mode;
>>   int kbd_time;
>>
>> @@ -495,6 +500,42 @@ static enum led_brightness 
>> toshiba_illumination_get(struct led_classdev *cdev)
>>  }
>>
>>  /* KBD Illumination */
>> +static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
>> +{
>> + u32 in[HCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
>> + u32 out[HCI_WORDS];
>> + acpi_status status;
>> +
>> + if (!sci_open(dev))
>> + return 0;
>> +
>> + status = hci_raw(dev, in, out);
>> + sci_close(dev);
>> + if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
>> + pr_err("ACPI call to query kbd illumination support failed\n");
>> + return 0;
>> + } else if (out[0] == HCI_NOT_SUPPORTED) {
>> + pr_info("Keyboard illumination not available\n");
>> + return 0;
>> + }
>> +
>> + /* Check for keyboard backlight timeout max value,
>> + /* previous kbd backlight implementation set this to
>
> Extra / ^
>
>> +  * 0x3c0003, and now the new implementation set this
>> +  * to 0x3c001a, use this to distinguish between them
>> +  */
>> + if (out[3] == SCI_KBD_TIME_MAX)
>> + dev->kbd_type = 2;
>> + else
>> + dev->kbd_type = 1;
>> + /* Get the current keyboard backlight mode */
>> + dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
>> + /* Get the current time (1-60 seconds) */
>> + dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
>> +
>> + return 1;
>> +}
>> +
>>  static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 
>> time)
>>  {
>>   u32 result;
>> @@ -1268,20 +1309,46 @@ static ssize_t toshiba_kbd_bl_mode_store(struct 
>> device *dev,
>>   ret = kstrtoint(buf, 0, &mode);
>>   if (ret)
>>   return ret;
>> - if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
>> + if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO &&
>> + mode != SCI_KBD_MODE_ON && mode != SCI_KBD_MODE_OFF)
>>   return -EINVAL;
>
> Since you have to check for a type::mode match anyway, this initial test is
> redundant. I suggest inverting the type::mode match below and make it
> exhaustive, something like:
>
>>
>> + /* Check for supported modes depending on keyboard backlight type */
>> + if (toshiba->kbd_type == 1) {
>> + /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
>> + if 

[PATCH v3] toshiba_acpi: Support new keyboard backlight type

2014-09-11 Thread Azael Avalos
Newer Toshiba models now come with a new (and different) keyboard
backlight implementation with three modes of operation: TIMER,
ON and OFF, and the LED is controlled internally by the firmware.

This patch adds support for that type of backlight, changing the
existing code to accomodate the new implementation.

The timeout value range is now 1-60 seconds, and the accepted
modes are now: 1 (FN-Z), 2 (AUTO or TIMER), 8(ON) and 10 (OFF),
this adds two new entries keyboard_type and available_kbd_modes,
the first shows the keyboard type and the latter shows the
supported modes depending on the type.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 4c8fa7b..a5d7d83 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -138,8 +138,12 @@ MODULE_LICENSE("GPL");
 #define HCI_WIRELESS_BT_PRESENT0x0f
 #define HCI_WIRELESS_BT_ATTACH 0x40
 #define HCI_WIRELESS_BT_POWER  0x80
+#define SCI_KBD_MODE_MASK  0x1f
 #define SCI_KBD_MODE_FNZ   0x1
 #define SCI_KBD_MODE_AUTO  0x2
+#define SCI_KBD_MODE_ON0x8
+#define SCI_KBD_MODE_OFF   0x10
+#define SCI_KBD_TIME_MAX   0x3c001a
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -155,6 +159,7 @@ struct toshiba_acpi_dev {
int force_fan;
int last_key_event;
int key_event_valid;
+   int kbd_type;
int kbd_mode;
int kbd_time;
 
@@ -495,6 +500,42 @@ static enum led_brightness toshiba_illumination_get(struct 
led_classdev *cdev)
 }
 
 /* KBD Illumination */
+static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
+{
+   u32 in[HCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
+   u32 out[HCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return 0;
+
+   status = hci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
+   pr_err("ACPI call to query kbd illumination support failed\n");
+   return 0;
+   } else if (out[0] == HCI_NOT_SUPPORTED) {
+   pr_info("Keyboard illumination not available\n");
+   return 0;
+   }
+
+   /* Check for keyboard backlight timeout max value,
+* previous kbd backlight implementation set this to
+* 0x3c0003, and now the new implementation set this
+* to 0x3c001a, use this to distinguish between them
+*/
+   if (out[3] == SCI_KBD_TIME_MAX)
+   dev->kbd_type = 2;
+   else
+   dev->kbd_type = 1;
+   /* Get the current keyboard backlight mode */
+   dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
+   /* Get the current time (1-60 seconds) */
+   dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
+
+   return 1;
+}
+
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
 {
u32 result;
@@ -1254,6 +1295,62 @@ static const struct backlight_ops toshiba_backlight_data 
= {
 /*
  * Sysfs files
  */
+static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
+struct device_attribute *attr,
+const char *buf, size_t count);
+static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf);
+static ssize_t toshiba_kbd_type_show(struct device *dev,
+struct device_attribute *attr,
+char *buf);
+static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf);
+static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count);
+static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
+  struct device_attribute *attr,
+  char *buf);
+static ssize_t toshiba_touchpad_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count);
+static ssize_t toshiba_touchpad_show(struct device *dev,
+struct device_attribute *attr,
+char *buf);
+static ssize_t toshiba_position_show(struct device *dev,
+ 

Re: [PATCH v3] toshiba_acpi: Support new keyboard backlight type

2014-09-12 Thread Azael Avalos
Hi Darren,

2014-09-12 14:48 GMT-06:00 Darren Hart :
> On Thu, Sep 11, 2014 at 09:22:25PM -0600, Azael Avalos wrote:
>> Newer Toshiba models now come with a new (and different) keyboard
>> backlight implementation with three modes of operation: TIMER,
>> ON and OFF, and the LED is controlled internally by the firmware.
>>
>> This patch adds support for that type of backlight, changing the
>> existing code to accomodate the new implementation.
>>
>> The timeout value range is now 1-60 seconds, and the accepted
>> modes are now: 1 (FN-Z), 2 (AUTO or TIMER), 8(ON) and 10 (OFF),
>> this adds two new entries keyboard_type and available_kbd_modes,
>
> ^ update for new naming
>
>> the first shows the keyboard type and the latter shows the
>> supported modes depending on the type.
>>
>> Signed-off-by: Azael Avalos 
>> ---
>
> Note you can update your v2,v3 changes here after the ---
>
> See Documentation/SubmittingPatches L639,649
>
>> @@ -1293,12 +1420,34 @@ static ssize_t toshiba_kbd_bl_mode_show(struct 
>> device *dev,
>>   char *buf)
>>  {
>>   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
>> - u32 time;
>>
>> - if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
>> - return -EIO;
>> + if (toshiba == NULL)
>> + return -ENXIO;
>
> If this testing is necessary for this sysfs callback, it is needed for all of 
> them. Looking at the code more closely, I think this is out of scope for this 
> patch. The entire file assumes a valid toshiba_acpi_dev. If this is a 
> problem, it needs a separate patch to address it. So, let's drop this change, 
> update the commit log to match the new sysfs filenames, and this should be 
> ready to go.

Ok, I'll leave this function as it is for this patch. I'll send an updated
(and hopefuly final) patch.

I have some "cleanup" changes comming, so that might be a good
place for them.

>
>
> --
> Darren Hart
> Intel Open Source Technology Center

Cheers
Azael


-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


[PATCH v2 3/5] toshiba_acpi: Fix accelerometer direction reporting

2014-09-12 Thread Azael Avalos
The position file on sysfs was reporting absolute values
for its axes.

This patch fixes the direction reporting (either negative
or positive), as well as added a mutex lock to it.

Signed-off-by: Azael Avalos 
---
This was: Add accelerometer input polled device

Changes since v1:
Dropped polldev and kept the position entry, and simply
fix the axes direction reporting, the IIO device will
be added in a future patch instead of the polled device.

 drivers/platform/x86/toshiba_acpi.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index edd8f3d..a94e5ed 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -124,6 +124,7 @@ MODULE_LICENSE("GPL");
 #define SCI_TOUCHPAD   0x050e
 
 /* field definitions */
+#define HCI_ACCEL_DIRECTION_MASK   0x8000
 #define HCI_ACCEL_MASK 0x7fff
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
@@ -1527,19 +1528,29 @@ static ssize_t toshiba_position_show(struct device *dev,
 struct device_attribute *attr, char *buf)
 {
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-   u32 xyval, zval, tmp;
-   u16 x, y, z;
+   u32 xyval, zval;
+   int x, y, z;
int ret;
 
+   mutex_lock(&dev->mutex);
+
xyval = zval = 0;
ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
-   if (ret < 0)
+   if (ret) {
+   mutex_unlock(&dev->mutex);
return ret;
+   }
 
+   /* Accelerometer values */
x = xyval & HCI_ACCEL_MASK;
-   tmp = xyval >> HCI_MISC_SHIFT;
-   y = tmp & HCI_ACCEL_MASK;
+   y = (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
z = zval & HCI_ACCEL_MASK;
+   /* Movement direction */
+   x *= xyval & HCI_ACCEL_DIRECTION_MASK ? -1 : 1;
+   y *= (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ? -1 : 1;
+   z *= zval & HCI_ACCEL_DIRECTION_MASK ? -1 : 1;
+
+   mutex_unlock(&dev->mutex);
 
return sprintf(buf, "%d %d %d\n", x, y, z);
 }
-- 
2.0.0

--
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/


[PATCH v4 4/5] toshiba_acpi: Support new keyboard backlight type

2014-09-12 Thread Azael Avalos
Newer Toshiba models now come with a new (and different) keyboard
backlight implementation with three modes of operation: TIMER,
ON and OFF, and the LED is now controlled internally by the firmware.

This patch adds support for that type of backlight, changing the
existing code to accomodate the new implementation.

The timeout value range is now 1-60 seconds, and the accepted
modes are now: 1 (FN-Z), 2 (AUTO or TIMER), 8 (ON) and 10 (OFF),
this adds two new entries kbd_type and available_kbd_modes,
the first shows the keyboard type and the latter shows the
supported modes depending on the keyboard type.

Signed-off-by: Azael Avalos 
---
Changes since v3:
Fixed typos on patch description
Dropped changes to toshiba_kbd_bl_mode_show and simply added the new mode mask
 drivers/platform/x86/toshiba_acpi.c | 188 ++--
 1 file changed, 156 insertions(+), 32 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 2a84652..edd8f3d 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -138,8 +138,12 @@ MODULE_LICENSE("GPL");
 #define HCI_WIRELESS_BT_PRESENT0x0f
 #define HCI_WIRELESS_BT_ATTACH 0x40
 #define HCI_WIRELESS_BT_POWER  0x80
+#define SCI_KBD_MODE_MASK  0x1f
 #define SCI_KBD_MODE_FNZ   0x1
 #define SCI_KBD_MODE_AUTO  0x2
+#define SCI_KBD_MODE_ON0x8
+#define SCI_KBD_MODE_OFF   0x10
+#define SCI_KBD_TIME_MAX   0x3c001a
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -155,6 +159,7 @@ struct toshiba_acpi_dev {
int force_fan;
int last_key_event;
int key_event_valid;
+   int kbd_type;
int kbd_mode;
int kbd_time;
 
@@ -495,6 +500,42 @@ static enum led_brightness toshiba_illumination_get(struct 
led_classdev *cdev)
 }
 
 /* KBD Illumination */
+static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
+{
+   u32 in[HCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
+   u32 out[HCI_WORDS];
+   acpi_status status;
+
+   if (!sci_open(dev))
+   return 0;
+
+   status = hci_raw(dev, in, out);
+   sci_close(dev);
+   if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
+   pr_err("ACPI call to query kbd illumination support failed\n");
+   return 0;
+   } else if (out[0] == HCI_NOT_SUPPORTED) {
+   pr_info("Keyboard illumination not available\n");
+   return 0;
+   }
+
+   /* Check for keyboard backlight timeout max value,
+* previous kbd backlight implementation set this to
+* 0x3c0003, and now the new implementation set this
+* to 0x3c001a, use this to distinguish between them
+*/
+   if (out[3] == SCI_KBD_TIME_MAX)
+   dev->kbd_type = 2;
+   else
+   dev->kbd_type = 1;
+   /* Get the current keyboard backlight mode */
+   dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
+   /* Get the current time (1-60 seconds) */
+   dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
+
+   return 1;
+}
+
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
 {
u32 result;
@@ -1254,6 +1295,62 @@ static const struct backlight_ops toshiba_backlight_data 
= {
 /*
  * Sysfs files
  */
+static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
+struct device_attribute *attr,
+const char *buf, size_t count);
+static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf);
+static ssize_t toshiba_kbd_type_show(struct device *dev,
+struct device_attribute *attr,
+char *buf);
+static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf);
+static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count);
+static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
+  struct device_attribute *attr,
+  char *buf);
+static ssize_t toshiba_touchpad_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count);
+static ssize_t toshiba_touchpad_show(struct device *dev,
+struct device_attribute *attr,
+   

[PATCH v2 0/3] Return codes cleanup

2014-09-29 Thread Azael Avalos
Up for review.

This series of patches are a cleanup to the Toshiba
configuration interface return codes (unification),
since we are now using both the HCI and the SCI, as
well as changing the returned type of the HCI/SCI
read/write functions from acpi_status to u32, since
the "status" was never checked on most of the functions.

Changes since v1:
- Be a bit more verbose on patch 1 about the Toshiba
  configuration interface
- Merged patches 3 and 4 into a same patch

Azael Avalos (3):
  toshiba_acpi: Rename hci_raw to tci_raw
  toshiba_acpi: Unify return codes prefix from HCI/SCI to TOS
  toshiba_acpi: Change HCI/SCI functions return code type

 drivers/platform/x86/toshiba_acpi.c | 369 ++--
 1 file changed, 183 insertions(+), 186 deletions(-)

-- 
2.0.0

--
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/


[PATCH v2 3/3] toshiba_acpi: Change HCI/SCI functions return code type

2014-09-29 Thread Azael Avalos
Currently the HCI/SCI read/write functions are returning
the status of the ACPI call and also assigning the
returned value of the HCI/SCI function, however, only
the HCI/SCI status is being checked.

This patch changes such functions, returning the value
of the HCI/SCI function instead of the ACPI call status,
eliminating one parameter, and returning something
useful that indeed is being checked.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 589a858..5d509ea 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -317,47 +317,49 @@ static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
  * may be useful (such as "not supported").
  */
 
-static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg,
- u32 in1, u32 *result)
+static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
 {
u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
u32 out[TCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
 }
 
-static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg,
-u32 *out1, u32 *result)
+static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
 {
u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status))
+   return TOS_FAILURE;
+
*out1 = out[2];
-   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return out[0];
 }
 
-static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg,
- u32 in1, u32 in2, u32 *result)
+static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2)
 {
u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
u32 out[TCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
 }
 
-static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg,
-u32 *out1, u32 *out2, u32 *result)
+static u32 hci_read2(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 
*out2)
 {
u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
u32 out[TCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status))
+   return TOS_FAILURE;
+
*out1 = out[2];
*out2 = out[3];
-   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return out[0];
 }
 
 /* common sci tasks
@@ -407,25 +409,26 @@ static void sci_close(struct toshiba_acpi_dev *dev)
pr_info("Toshiba SCI is not present\n");
 }
 
-static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg,
-   u32 *out1, u32 *result)
+static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
 {
u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status))
+   return TOS_FAILURE;
+
*out1 = out[2];
-   *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return out[0];
 }
 
-static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg,
-u32 in1, u32 *result)
+static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
 {
u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
u32 out[TCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
-   *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE;
-   return status;
+
+   return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
 }
 
 /* Illumination support */
@@ -457,7 +460,6 @@ static void toshiba_illumination_set(struct led_classdev 
*cdev,
struct toshiba_acpi_dev *dev = container_of(cdev,
struct toshiba_acpi_dev, led_dev);
u32 state, result;
-   acpi_status status;
 
/* First request : initialize communication. */
if (!sci_open(dev))
@@ -465,9 +467,9 @@ static void toshiba_illumination_set(struct led_classdev 
*cdev,
 
/* Switch the illumination on/off */
state = brightness ? 1 : 0;
-   status = sci_write(dev, SCI_ILLUMINATION, state, &result);
+   result = sci_write(dev, SCI_ILLUMINATION, state);
sci_close(dev);
-   if (ACPI_FAILURE(status)) {
+   i

[PATCH v2 2/3] toshiba_acpi: Unify return codes prefix from HCI/SCI to TOS

2014-09-29 Thread Azael Avalos
The return codes are split in between HCI/SCI prefixes,
but they are shared (used) by both interfaces, mixing
hci_read/write calls with SCI_* return codes, and
sci_read/write calls with HCI_* ones.

This patch changes the prefix of the return codes
definitions, dropping the HCI/SCI naming and instead
replacing it with TOS (for TOShiba).

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index ed3671c..589a858 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -96,17 +96,18 @@ MODULE_LICENSE("GPL");
 #define SCI_SET0xf400
 
 /* return codes */
-#define HCI_SUCCESS0x
-#define HCI_FAILURE0x1000
-#define HCI_NOT_SUPPORTED  0x8000
-#define HCI_EMPTY  0x8c00
-#define HCI_DATA_NOT_AVAILABLE 0x8d20
-#define HCI_NOT_INITIALIZED0x8d50
-#define SCI_OPEN_CLOSE_OK  0x0044
-#define SCI_ALREADY_OPEN   0x8100
-#define SCI_NOT_OPENED 0x8200
-#define SCI_INPUT_DATA_ERROR   0x8300
-#define SCI_NOT_PRESENT0x8600
+#define TOS_SUCCESS0x
+#define TOS_OPEN_CLOSE_OK  0x0044
+#define TOS_FAILURE0x1000
+#define TOS_NOT_SUPPORTED  0x8000
+#define TOS_ALREADY_OPEN   0x8100
+#define TOS_NOT_OPENED 0x8200
+#define TOS_INPUT_DATA_ERROR   0x8300
+#define TOS_WRITE_PROTECTED0x8400
+#define TOS_NOT_PRESENT0x8600
+#define TOS_FIFO_EMPTY 0x8c00
+#define TOS_DATA_NOT_AVAILABLE 0x8d20
+#define TOS_NOT_INITIALIZED0x8d50
 
 /* registers */
 #define HCI_FAN0x0004
@@ -322,7 +323,7 @@ static acpi_status hci_write1(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
u32 out[TCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
return status;
 }
 
@@ -333,7 +334,7 @@ static acpi_status hci_read1(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 out[TCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
*out1 = out[2];
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
return status;
 }
 
@@ -343,7 +344,7 @@ static acpi_status hci_write2(struct toshiba_acpi_dev *dev, 
u32 reg,
u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
u32 out[TCI_WORDS];
acpi_status status = tci_raw(dev, in, out);
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
return status;
 }
 
@@ -355,7 +356,7 @@ static acpi_status hci_read2(struct toshiba_acpi_dev *dev, 
u32 reg,
acpi_status status = tci_raw(dev, in, out);
*out1 = out[2];
*out2 = out[3];
-   *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
+   *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
return status;
 }
 
@@ -369,17 +370,17 @@ static int sci_open(struct toshiba_acpi_dev *dev)
acpi_status status;
 
status = tci_raw(dev, in, out);
-   if  (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
+   if  (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
pr_err("ACPI call to open SCI failed\n");
return 0;
}
 
-   if (out[0] == SCI_OPEN_CLOSE_OK) {
+   if (out[0] == TOS_OPEN_CLOSE_OK) {
return 1;
-   } else if (out[0] == SCI_ALREADY_OPEN) {
+   } else if (out[0] == TOS_ALREADY_OPEN) {
pr_info("Toshiba SCI already opened\n");
return 1;
-   } else if (out[0] == SCI_NOT_PRESENT) {
+   } else if (out[0] == TOS_NOT_PRESENT) {
pr_info("Toshiba SCI is not present\n");
}
 
@@ -393,16 +394,16 @@ static void sci_close(struct toshiba_acpi_dev *dev)
acpi_status status;
 
status = tci_raw(dev, in, out);
-   if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
+   if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
pr_err("ACPI call to close SCI failed\n");
return;
}
 
-   if (out[0] == SCI_OPEN_CLOSE_OK)
+   if (out[0] == TOS_OPEN_CLOSE_OK)
return;
-   else if (out[0] == SCI_NOT_OPENED)
+   else if (out[0] == TOS_NOT_OPENED)
pr_info("Toshiba SCI not opened\n");
-   else if (out[0] == SCI_NOT_PRESENT)
+   else if (out[0] == 

[PATCH v2 1/3] toshiba_acpi: Rename hci_raw to tci_raw

2014-09-29 Thread Azael Avalos
The function name hci_raw was used before to reflect
a raw (read/write) call to Toshiba's Hardware
Configuration Interface (HCI), however, since the
introduction of the System Configuration Interface
(SCI), that "name" no longer applies.

This patch changes the name of that function to
tci_raw (for Toshiba Configuration Interface), and
change the comments about it.

Also, the HCI_WORDS definition was changed to TCI_RAW,
to better reflect that we're no longer using pure HCI
calls, but a combination of HCI and SCI, which form
part of the Toshiba Configuration Interface.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index edd8f3d..ed3671c 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -71,7 +71,8 @@ MODULE_LICENSE("GPL");
 /* Toshiba ACPI method paths */
 #define METHOD_VIDEO_OUT   "\\_SB_.VALX.DSSX"
 
-/* Toshiba HCI interface definitions
+/* The Toshiba configuration interface is composed of the HCI and the SCI,
+ * which are defined as follows:
  *
  * HCI is Toshiba's "Hardware Control Interface" which is supposed to
  * be uniform across all their models.  Ideally we would just call
@@ -84,7 +85,7 @@ MODULE_LICENSE("GPL");
  * conceal differences in hardware between different models.
  */
 
-#define HCI_WORDS  6
+#define TCI_WORDS  6
 
 /* operations */
 #define HCI_SET0xff00
@@ -274,22 +275,22 @@ static int write_acpi_int(const char *methodName, int val)
return (status == AE_OK) ? 0 : -EIO;
 }
 
-/* Perform a raw HCI call.  Here we don't care about input or output buffer
- * format.
+/* Perform a raw configuration call.  Here we don't care about input or output
+ * buffer format.
  */
-static acpi_status hci_raw(struct toshiba_acpi_dev *dev,
-  const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
+static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
+  const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
 {
struct acpi_object_list params;
-   union acpi_object in_objs[HCI_WORDS];
+   union acpi_object in_objs[TCI_WORDS];
struct acpi_buffer results;
-   union acpi_object out_objs[HCI_WORDS + 1];
+   union acpi_object out_objs[TCI_WORDS + 1];
acpi_status status;
int i;
 
-   params.count = HCI_WORDS;
+   params.count = TCI_WORDS;
params.pointer = in_objs;
-   for (i = 0; i < HCI_WORDS; ++i) {
+   for (i = 0; i < TCI_WORDS; ++i) {
in_objs[i].type = ACPI_TYPE_INTEGER;
in_objs[i].integer.value = in[i];
}
@@ -300,7 +301,7 @@ static acpi_status hci_raw(struct toshiba_acpi_dev *dev,
status = acpi_evaluate_object(dev->acpi_dev->handle,
  (char *)dev->method_hci, ¶ms,
  &results);
-   if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
+   if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
for (i = 0; i < out_objs->package.count; ++i) {
out[i] = out_objs->package.elements[i].integer.value;
}
@@ -318,9 +319,9 @@ static acpi_status hci_raw(struct toshiba_acpi_dev *dev,
 static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg,
  u32 in1, u32 *result)
 {
-   u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
-   u32 out[HCI_WORDS];
-   acpi_status status = hci_raw(dev, in, out);
+   u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status = tci_raw(dev, in, out);
*result = (status == AE_OK) ? out[0] : HCI_FAILURE;
return status;
 }
@@ -328,9 +329,9 @@ static acpi_status hci_write1(struct toshiba_acpi_dev *dev, 
u32 reg,
 static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg,
 u32 *out1, u32 *result)
 {
-   u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
-   u32 out[HCI_WORDS];
-   acpi_status status = hci_raw(dev, in, out);
+   u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status = tci_raw(dev, in, out);
*out1 = out[2];
*result = (status == AE_OK) ? out[0] : HCI_FAILURE;
return status;
@@ -339,9 +340,9 @@ static acpi_status hci_read1(struct toshiba_acpi_dev *dev, 
u32 reg,
 static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg,
  u32 in1, u32 in2, u32 *result)
 {
-   u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
-  

[PATCH] toshiba_acpi: Adapt kbd_bl_timeout_store to the new kbd type

2014-09-29 Thread Azael Avalos
With the introduccion of the new keyboard backlight
implementation, the *_timeout_store function is
broken, as it only supports the first kbd_type.

This patch adapt such function for the new kbd_type,
as well as convert from using sscanf to kstrtoint.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 5d509ea..13ee56b 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1453,18 +1453,35 @@ static ssize_t toshiba_kbd_bl_timeout_store(struct 
device *dev,
const char *buf, size_t count)
 {
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-   int time = -1;
+   int time;
+   int ret;
+
+   ret = kstrtoint(buf, 0, &time);
+   if (ret)
+   return ret;
 
-   if (sscanf(buf, "%i", &time) != 1 && (time < 0 || time > 60))
+   if (time < 1 || time > 60)
return -EINVAL;
 
-   /* Set the Keyboard Backlight Timeout: 0-60 seconds */
-   if (time != -1 && toshiba->kbd_time != time) {
+   /* Set the Keyboard Backlight Timeout: 1-60 seconds */
+   
+   /* Only make a change if the actual timeout has changed */
+   if (toshiba->kbd_time != time) {
+   /* Shift the time to "base time" (0x3c == 60 seconds)*/
time = time << HCI_MISC_SHIFT;
-   time = (toshiba->kbd_mode == SCI_KBD_MODE_AUTO) ?
-   time + 1 : time + 2;
-   if (toshiba_kbd_illum_status_set(toshiba, time) < 0)
-   return -EIO;
+   /* OR the "base time" to the actual method format */
+   if (toshiba->kbd_type == 1) {
+   /* Type 1 requires the oposite mode */
+   time |= SCI_KBD_MODE_FNZ;
+   } else if (toshiba->kbd_type == 2) {
+   /* Type 2 requires the actual mode */
+   time |= SCI_KBD_MODE_AUTO;
+   }
+
+   ret = toshiba_kbd_illum_status_set(toshiba, time);
+   if (ret)
+   return ret;
+
toshiba->kbd_time = time >> HCI_MISC_SHIFT;
}
 
-- 
2.0.0

--
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/


Re: [PATCH] platform/x86/toshiba-apci.c possible bad if test?

2014-06-13 Thread Azael Avalos
Hi,

I've sent this patch a few weeks ago, but somehow it didn't managed to
get through :-(

If it's still possible, please pick it up Matthew.


Cheers.
Azael


8<->8
Intel test builder caught some warnings, one at the
KBD backlight mode store while validating for
correct parameters, and another one that might lead
to not creating the sysfs group

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

diff --git a/drivers/platform/x86/toshiba_acpi.c
b/drivers/platform/x86/toshiba_acpi.c
index fbbe46d..f397594 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1218,7 +1218,7 @@ static ssize_t toshiba_kbd_bl_mode_store(struct
device *dev,
int mode = -1;
int time = -1;

-   if (sscanf(buf, "%i", &mode) != 1 && (mode != 2 || mode != 1))
+   if (sscanf(buf, "%i", &mode) != 1 || mode > 2 || mode < 1)
return -EINVAL;

/* Set the Keyboard Backlight Mode where:
@@ -1741,7 +1741,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)

ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
 &toshiba_attr_group);
-   if (ret) {
+   if (ret != 0) {
dev->sysfs_created = 0;
goto error;
}


--
1.9.1

2014-06-12 21:04 GMT-06:00 Nick :
> diff --git a/drivers/platform/x86/toshiba_acpi.c 
> b/drivers/platform/x86/toshiba_acpi.c
> index 76441dc..dfd2243 100644
> --- a/drivers/platform/x86/toshiba_acpi.c
> +++ b/drivers/platform/x86/toshiba_acpi.c
> @@ -1238,7 +1238,7 @@ static ssize_t toshiba_kbd_bl_mode_store(struct device 
> *dev,
> int mode = -1;
> int time = -1;
>
> -   if (sscanf(buf, "%i", &mode) != 1 && (mode != 2 || mode != 1))
> +   if (sscanf(buf, "%i", &mode) != 1  || (mode != 2 || mode != 1))
> return -EINVAL;
>
> /* Set the Keyboard Backlight Mode where:
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe 
> platform-driver-x86" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


Re: [PATCH 3/5] toshiba_acpi: Add accelerometer input polled device

2014-09-10 Thread Azael Avalos
Hi there,

2014-09-09 21:35 GMT-06:00 Darren Hart :
>
> I immediately went to a tablet with a marble maze game and it didn't seem too
> crazy, but I don't suppose that is what people are actually doing with it...
>
> What are people actually doing with this thing Azael?

Gaming mostly (supertuxkart anyone?), but some others (including myself)
want to use it as a movement detection (one exists for the IBM/Lenovo
Thinkpads).

Digging into platform drivers, I've found that the hdaps and also the lis3lv02d
drivers report the axes via polldev, and since I don't want to break userspace,
I'm left with two choices:

1 - Keep sysfs entry and adapt it to properly report direction, and no
polled device.

2 - Keep sysfs entry and adapt it to properly report direction, and also
a polled device.

Let me know your decision so I can send an updated patch.

>
> --
> Darren Hart
> Intel Open Source Technology Center

Cheers
Azael


-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


Re: [PATCH 4/5] toshiba_acpi: Support new keyboard backlight type

2014-09-10 Thread Azael Avalos
Hi Darren,

2014-09-09 22:11 GMT-06:00 Darren Hart :
> On Fri, Sep 05, 2014 at 11:14:06AM -0600, Azael Avalos wrote:
>
> Hi Azael,
>
> Apologies for the delay. I'm still recovering from a couple weeks of travel 
> and
> a nasty conference bug. Thanks for being patient.
>
>> Newer Toshiba models now come with a new (and different) keyboard
>> backlight implementation whith three modes of operation: TIMER,
>> ON and OFF, and the LED is controlled internally by the firmware.
>>
>> This patch adds support for that type of backlight, changing the
>> existing code to accomodate the new implementation.
>>
>> The timeout value range is now 1-60 seconds, and the accepted
>> modes are now: 0 (OFF), 1 (ON or FN-Z) and 2 (AUTO or TIMER), and
>> the keyboard_backlight_mode entry now displays two values, the
>> keyboard backlight type (either 1 or 2) and the current mode.
>
>
> Wouldn't adding a new entry make more sense than multiplexing an existing 
> one? I
> was fairly sure that was contrary to the goals of sys...

Sure, I don't want to break userspace.

>
>
>>
>> Signed-off-by: Azael Avalos 
>
>
> On testing, were you able to verify on new as well as previous models that 
> this
> continues to work?

Yes, that was the first thing I did whenever I got this new implementation.

>
>
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 145 
>> 
>>  1 file changed, 98 insertions(+), 47 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index ac1503c..1738171 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -142,6 +142,8 @@ MODULE_LICENSE("GPL");
>>  #define HCI_WIRELESS_BT_POWER0x80
>>  #define SCI_KBD_MODE_FNZ 0x1
>>  #define SCI_KBD_MODE_AUTO0x2
>> +#define SCI_KBD_MODE_ON  0x8
>> +#define SCI_KBD_MODE_OFF 0x10
>>
>>  struct toshiba_acpi_dev {
>>   struct acpi_device *acpi_dev;
>> @@ -158,6 +160,7 @@ struct toshiba_acpi_dev {
>>   int force_fan;
>>   int last_key_event;
>>   int key_event_valid;
>> + int kbd_type;
>
> Consider some defines or enum values for the types?

Makes sense, in case Toshiba decides to change the keyboard backlight
modes again...

>
>>   int kbd_mode;
>>   int kbd_time;
>>
>> @@ -499,28 +502,36 @@ static enum led_brightness 
>> toshiba_illumination_get(struct led_classdev *cdev)
>>  }
>>
>>  /* KBD Illumination */
>> -static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 
>> time)
>> +static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
>>  {
>> - u32 result;
>> + u32 in[HCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
>> + u32 out[HCI_WORDS];
>>   acpi_status status;
>>
>>   if (!sci_open(dev))
>> - return -EIO;
>> + return 0;
>>
>> - status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result);
>> + status = hci_raw(dev, in, out);
>>   sci_close(dev);
>> - if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
>> - pr_err("ACPI call to set KBD backlight status failed\n");
>> - return -EIO;
>> - } else if (result == HCI_NOT_SUPPORTED) {
>> - pr_info("Keyboard backlight status not supported\n");
>> - return -ENODEV;
>> + if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
>> + pr_err("ACPI call to query kbd illumination support failed\n");
>> + return 0;
>> + } else if (out[0] == HCI_NOT_SUPPORTED) {
>> + pr_info("Keyboard illumination not available\n");
>> + return 0;
>>   }
>>
>> - return 0;
>> + if (out[3] == 0x3c001a)
>
> Do have any information on what this value means? It would be preferable to 
> use
> sensible defines here rather than magic hex codes if at all possible.

That is the max value the backlight method supports, and on the new
implementation, it is different from the previous one.

On reading any Toshiba method:
out[0] holds success or error
out[1] varies depending on method (usually zero)
out[2] holds the actual value
out[3] holds the max value
out[4] varies depending on method (usually zero)
out[5] varies depending on method (usually zero)

>
>> + dev->kbd_typ

[PATCH 0/5] toshiba_acpi: Various changes plus fixes

2014-09-05 Thread Azael Avalos
Up for review.

This series of patches introduce support for the new
keyboard backlight type found on recent Toshiba laptops,
removes the position sysfs entry and instead creates an
input polled device (joystick), and a few fixes and
additions to the keymap list.

Azael Avalos (5):
  toshiba_acpi: Additional hotkey scancodes
  toshiba_acpi: Fix illumination not available on certain models
  toshiba_acpi: Add accelerometer input polled device
  toshiba_acpi: Support new keyboard backlight type
  toshiba_acpi: Change touchpad store to check for invalid values

 drivers/platform/x86/toshiba_acpi.c | 277 ++--
 1 file changed, 199 insertions(+), 78 deletions(-)

-- 
2.0.0

--
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/


[PATCH 1/5] toshiba_acpi: Additional hotkey scancodes

2014-09-05 Thread Azael Avalos
Appart from reporting hotkeys, the INFO method is used
as a system wide event notifier for hardware or
software changes.

This patch adds additional "events" to the keymap list,
ignored by now, until we find them a good use.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index b062d3d..a149bc6 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -190,6 +190,7 @@ static const struct key_entry toshiba_acpi_keymap[] = {
{ KE_KEY, 0x101, { KEY_MUTE } },
{ KE_KEY, 0x102, { KEY_ZOOMOUT } },
{ KE_KEY, 0x103, { KEY_ZOOMIN } },
+   { KE_KEY, 0x10f, { KEY_TAB } },
{ KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
{ KE_KEY, 0x139, { KEY_ZOOMRESET } },
{ KE_KEY, 0x13b, { KEY_COFFEE } },
@@ -210,7 +211,11 @@ static const struct key_entry toshiba_acpi_keymap[] = {
{ KE_KEY, 0xb32, { KEY_NEXTSONG } },
{ KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
{ KE_KEY, 0xb5a, { KEY_MEDIA } },
-   { KE_IGNORE, 0x1430, { KEY_RESERVED } },
+   { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
+   { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
+   { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
+   { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
+   { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
{ KE_END, 0 },
 };
 
-- 
2.0.0

--
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/


[PATCH 3/5] toshiba_acpi: Add accelerometer input polled device

2014-09-05 Thread Azael Avalos
The accelerometer sensor is very sensitive, and having userspace
poll the sysfs position entry is not very battery friendly.

This patch removes the sysfs entry and instead, it creates an
input polled device (joystick) for the built-in accelerometer.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 4803e7b..ac1503c 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -124,6 +125,7 @@ MODULE_LICENSE("GPL");
 #define SCI_TOUCHPAD   0x050e
 
 /* field definitions */
+#define HCI_ACCEL_DIRECTION_MASK   0x8000
 #define HCI_ACCEL_MASK 0x7fff
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
@@ -146,6 +148,7 @@ struct toshiba_acpi_dev {
const char *method_hci;
struct rfkill *bt_rfk;
struct input_dev *hotkey_dev;
+   struct input_polled_dev *ip_dev;
struct work_struct hotkey_work;
struct backlight_device *backlight_dev;
struct led_classdev led_dev;
@@ -170,6 +173,7 @@ struct toshiba_acpi_dev {
unsigned int touchpad_supported:1;
unsigned int eco_supported:1;
unsigned int accelerometer_supported:1;
+   unsigned int joystick_registered:1;
unsigned int sysfs_created:1;
 
struct mutex mutex;
@@ -1361,40 +1365,17 @@ static ssize_t toshiba_touchpad_show(struct device *dev,
return sprintf(buf, "%i\n", state);
 }
 
-static ssize_t toshiba_position_show(struct device *dev,
-struct device_attribute *attr, char *buf)
-{
-   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-   u32 xyval, zval, tmp;
-   u16 x, y, z;
-   int ret;
-
-   xyval = zval = 0;
-   ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
-   if (ret < 0)
-   return ret;
-
-   x = xyval & HCI_ACCEL_MASK;
-   tmp = xyval >> HCI_MISC_SHIFT;
-   y = tmp & HCI_ACCEL_MASK;
-   z = zval & HCI_ACCEL_MASK;
-
-   return sprintf(buf, "%d %d %d\n", x, y, z);
-}
-
 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
 static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
   toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
 static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
   toshiba_touchpad_show, toshiba_touchpad_store);
-static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
 
 static struct attribute *toshiba_attributes[] = {
&dev_attr_kbd_backlight_mode.attr,
&dev_attr_kbd_backlight_timeout.attr,
&dev_attr_touchpad.attr,
-   &dev_attr_position.attr,
NULL,
 };
 
@@ -1411,8 +1392,6 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
else if (attr == &dev_attr_touchpad.attr)
exists = (drv->touchpad_supported) ? true : false;
-   else if (attr == &dev_attr_position.attr)
-   exists = (drv->accelerometer_supported) ? true : false;
 
return exists ? attr->mode : 0;
 }
@@ -1621,6 +1600,75 @@ static int toshiba_acpi_setup_backlight(struct 
toshiba_acpi_dev *dev)
return 0;
 }
 
+static void toshiba_acpi_joystick_poll(struct input_polled_dev *ip_dev)
+{
+   struct toshiba_acpi_dev *dev = ip_dev->private;
+   u32 xy, zval;
+   int x, y, z;
+
+   mutex_lock(&dev->mutex);
+
+   if (toshiba_accelerometer_get(dev, &xy, &zval) < 0) {
+   pr_err("Could not get accelerometer axes");
+   mutex_unlock(&dev->mutex);
+   return;
+   }
+
+   /* Accelerometer values */
+   x = xy & HCI_ACCEL_MASK;
+   y = (xy >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
+   z = zval & HCI_ACCEL_MASK;
+   /* Movement direction */
+   x *= xy & HCI_ACCEL_DIRECTION_MASK ? -1 : 1;
+   y *= (xy >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ? -1 : 1;
+   z *= zval & HCI_ACCEL_DIRECTION_MASK ? -1 : 1;
+
+   input_report_abs(ip_dev->input, ABS_X, x);
+   input_report_abs(ip_dev->input, ABS_Y, y);
+   input_report_abs(ip_dev->input, ABS_Z, z);
+   input_sync(ip_dev->input);
+
+   mutex_unlock(&dev->mutex);
+}
+
+static int toshiba_acpi_setup_joystick(struct toshiba_acpi_dev *dev)
+{
+   struct input_dev *idev;
+   int ret;
+
+   if (dev->ip_dev)
+   return -

[PATCH 4/5] toshiba_acpi: Support new keyboard backlight type

2014-09-05 Thread Azael Avalos
Newer Toshiba models now come with a new (and different) keyboard
backlight implementation whith three modes of operation: TIMER,
ON and OFF, and the LED is controlled internally by the firmware.

This patch adds support for that type of backlight, changing the
existing code to accomodate the new implementation.

The timeout value range is now 1-60 seconds, and the accepted
modes are now: 0 (OFF), 1 (ON or FN-Z) and 2 (AUTO or TIMER), and
the keyboard_backlight_mode entry now displays two values, the
keyboard backlight type (either 1 or 2) and the current mode.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index ac1503c..1738171 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -142,6 +142,8 @@ MODULE_LICENSE("GPL");
 #define HCI_WIRELESS_BT_POWER  0x80
 #define SCI_KBD_MODE_FNZ   0x1
 #define SCI_KBD_MODE_AUTO  0x2
+#define SCI_KBD_MODE_ON0x8
+#define SCI_KBD_MODE_OFF   0x10
 
 struct toshiba_acpi_dev {
struct acpi_device *acpi_dev;
@@ -158,6 +160,7 @@ struct toshiba_acpi_dev {
int force_fan;
int last_key_event;
int key_event_valid;
+   int kbd_type;
int kbd_mode;
int kbd_time;
 
@@ -499,28 +502,36 @@ static enum led_brightness 
toshiba_illumination_get(struct led_classdev *cdev)
 }
 
 /* KBD Illumination */
-static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
+static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
 {
-   u32 result;
+   u32 in[HCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
+   u32 out[HCI_WORDS];
acpi_status status;
 
if (!sci_open(dev))
-   return -EIO;
+   return 0;
 
-   status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result);
+   status = hci_raw(dev, in, out);
sci_close(dev);
-   if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
-   pr_err("ACPI call to set KBD backlight status failed\n");
-   return -EIO;
-   } else if (result == HCI_NOT_SUPPORTED) {
-   pr_info("Keyboard backlight status not supported\n");
-   return -ENODEV;
+   if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
+   pr_err("ACPI call to query kbd illumination support failed\n");
+   return 0;
+   } else if (out[0] == HCI_NOT_SUPPORTED) {
+   pr_info("Keyboard illumination not available\n");
+   return 0;
}
 
-   return 0;
+   if (out[3] == 0x3c001a)
+   dev->kbd_type = 2;
+   else
+   dev->kbd_type = 1;
+   dev->kbd_mode = out[2] & 0x1f;
+   dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
+
+   return 1;
 }
 
-static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 
*time)
+static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
 {
u32 result;
acpi_status status;
@@ -528,10 +539,10 @@ static int toshiba_kbd_illum_status_get(struct 
toshiba_acpi_dev *dev, u32 *time)
if (!sci_open(dev))
return -EIO;
 
-   status = sci_read(dev, SCI_KBD_ILLUM_STATUS, time, &result);
+   status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result);
sci_close(dev);
if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
-   pr_err("ACPI call to get KBD backlight status failed\n");
+   pr_err("ACPI call to set KBD backlight status failed\n");
return -EIO;
} else if (result == HCI_NOT_SUPPORTED) {
pr_info("Keyboard backlight status not supported\n");
@@ -1264,22 +1275,54 @@ static ssize_t toshiba_kbd_bl_mode_store(struct device 
*dev,
 const char *buf, size_t count)
 {
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-   int mode = -1;
-   int time = -1;
+   int mode;
+   int time;
+   int ret;
 
-   if (sscanf(buf, "%i", &mode) != 1 && (mode != 2 || mode != 1))
+   ret = kstrtoint(buf, 0, &mode);
+   if (ret)
+   return ret;
+   if (mode > 2 || mode < 0)
return -EINVAL;
 
/* Set the Keyboard Backlight Mode where:
-* Mode - Auto (2) | FN-Z (1)
+* Mode - Auto (2) | FN-Z or ON (1) | OFF (0)
 *  Auto - KBD backlight turns off automatically in given time
 *  FN-Z - KBD backlight "toggles" when hotkey pressed
+*  ON   - KBD backlight is always on
+*

[PATCH 5/5] toshiba_acpi: Change touchpad store to check for invalid values

2014-09-05 Thread Azael Avalos
The function toshiba_touchpad_store is not checking
for invalid values and simply returns silently.

This patch checks for invalid values and returns accordingly.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 1738171..777fb3c 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1396,12 +1396,18 @@ static ssize_t toshiba_touchpad_store(struct device 
*dev,
 {
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
int state;
+   int ret;
 
/* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
-   if (sscanf(buf, "%i", &state) == 1 && (state == 0 || state == 1)) {
-   if (toshiba_touchpad_set(toshiba, state) < 0)
-   return -EIO;
-   }
+   ret = kstrtoint(buf, 0, &state);
+   if (ret)
+   return ret;
+   if (state != 0 || state != 1)
+   return -EINVAL;
+
+   ret = toshiba_touchpad_set(toshiba, state);
+   if (ret)
+   return ret;
 
return count;
 }
-- 
2.0.0

--
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/


[PATCH 2/5] toshiba_acpi: Fix illumination not available on certain models

2014-09-05 Thread Azael Avalos
Some Toshiba models with illumination support set a different
value on the returned codes, thus not allowing the illumination
LED to be registered, where it should be.

This patch removes a check from toshiba_illumination_available
function to allow such models to register the illumination LED.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index a149bc6..4803e7b 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -436,7 +436,7 @@ static int toshiba_illumination_available(struct 
toshiba_acpi_dev *dev)
if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
pr_err("ACPI call to query Illumination support failed\n");
return 0;
-   } else if (out[0] == HCI_NOT_SUPPORTED || out[1] != 1) {
+   } else if (out[0] == HCI_NOT_SUPPORTED) {
pr_info("Illumination device not available\n");
return 0;
}
-- 
2.0.0

--
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/


Re: [PATCH 2/5] toshiba_acpi: Fix illumination not available on certain models

2014-09-05 Thread Azael Avalos
Hi there

2014-09-05 20:35 GMT-06:00 Darren Hart :
> On Fri, Sep 05, 2014 at 11:14:04AM -0600, Azael Avalos wrote:
>> Some Toshiba models with illumination support set a different
>> value on the returned codes, thus not allowing the illumination
>> LED to be registered, where it should be.
>>
>> This patch removes a check from toshiba_illumination_available
>> function to allow such models to register the illumination LED.
>>
>> Signed-off-by: Azael Avalos 
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index a149bc6..4803e7b 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -436,7 +436,7 @@ static int toshiba_illumination_available(struct 
>> toshiba_acpi_dev *dev)
>>   if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
>>   pr_err("ACPI call to query Illumination support failed\n");
>>   return 0;
>> - } else if (out[0] == HCI_NOT_SUPPORTED || out[1] != 1) {
>> + } else if (out[0] == HCI_NOT_SUPPORTED) {
>
> OK, but by eliminating the check, supposedly certain models which do not 
> support
> illumination but do not report it via out[0], but instead via out[1], will now
> attempt to use illumination - correct?

Oh no, the main check is out[0], which either hold success if the
feature is supported
or an HCI/SCI error otherwise.

>
> The end result being user calls to an ACPI function which at best doesn't 
> exist
> and at worst does, but does something entirely different.
>
> I admit the potential for a problem is slight, but is it possible to check
> something explicit for support on the newer models rather than removing an
> existing check?

Our only resource right now is the DSDT and actual hardware to test,
as those calls
are not documented anywhere, and everytime the vendor decides to
change something,
we're on the loose end.

All the DSDTs that I previously had all set out[1] to one, so I was
using that as an
extra check to make sure we had illumination support, but now, recent models
set out[1] to zero, and those models, which do happen to have illumination
support (Qosmio X75 for example) were failing to register the LED.

>
> --
> Darren Hart
> Intel Open Source Technology Center



-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


Re: [PATCH 3/5] toshiba_acpi: Add accelerometer input polled device

2014-09-05 Thread Azael Avalos
Hi there,

2014-09-05 20:42 GMT-06:00 Darren Hart :
> On Fri, Sep 05, 2014 at 11:14:05AM -0600, Azael Avalos wrote:
>> The accelerometer sensor is very sensitive, and having userspace
>> poll the sysfs position entry is not very battery friendly.
>>
>> This patch removes the sysfs entry and instead, it creates an
>> input polled device (joystick) for the built-in accelerometer.
>
> Hrm, while sysfs details can change across kernel versions, usually due to
> driver core changes, we try to keep them as consistent as possible so as not 
> to
> break userspace.
>
> That said, if we are going to try and come up with a better model for
> representing an accelerometer, wouldn't treating it as an IIO device be the 
> more
> logical approach?

Yes of course, but the actual accelerometer device (sensor?) is not
really exposed,
only certain "functions" it provides, and they are divided across two
different ACPI devices,
TOS620A exposes the protection, and the TOS1900 (and et. al.) only
exposes the axes.

I see your point in breaking userspace, but given the fact that it was
recently introduced,
I didn't thought it was already "adopted", that's why I decided to
remove the sysfs entry.

Then we might as well keep the sysfs entry and have the input polled
device as well.

>
> --
> Darren Hart
> Intel Open Source Technology Center


Cheers
Azael


-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


[PATCH v2] toshiba_acpi: Adapt kbd_bl_timeout_store to the new kbd type

2014-10-04 Thread Azael Avalos
With the introduccion of the new keyboard backlight
implementation, the *_timeout_store function is
broken, as it only supports the first kbd_type.

This patch adapt such function for the new kbd_type,
as well as convert from using sscanf to kstrtoint.

Signed-off-by: Azael Avalos 
---
Changes since v1:
- Check for timeout values depending on kbd_type
- Removed some misleading comments

Note: I'll be out of town until the next weekend,
in case something else needs to be changed, I'll
catch up whenever I'm back.

 drivers/platform/x86/toshiba_acpi.c | 38 -
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 5d509ea..f360dac 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1453,18 +1453,38 @@ static ssize_t toshiba_kbd_bl_timeout_store(struct 
device *dev,
const char *buf, size_t count)
 {
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-   int time = -1;
+   int time;
+   int ret;
 
-   if (sscanf(buf, "%i", &time) != 1 && (time < 0 || time > 60))
-   return -EINVAL;
+   ret = kstrtoint(buf, 0, &time);
+   if (ret)
+   return ret;
 
-   /* Set the Keyboard Backlight Timeout: 0-60 seconds */
-   if (time != -1 && toshiba->kbd_time != time) {
+   /* Check for supported values depending on kbd_type */
+   if (toshiba->kbd_type == 1) {
+   if (time < 0 || time > 60)
+   return -EINVAL;
+   } else if (toshiba->kbd_type == 2) {
+   if (time < 1 || time > 60)
+   return -EINVAL;
+   }
+
+   /* Set the Keyboard Backlight Timeout */
+   
+   /* Only make a change if the actual timeout has changed */
+   if (toshiba->kbd_time != time) {
+   /* Shift the time to "base time" (0x3c == 60 seconds) */
time = time << HCI_MISC_SHIFT;
-   time = (toshiba->kbd_mode == SCI_KBD_MODE_AUTO) ?
-   time + 1 : time + 2;
-   if (toshiba_kbd_illum_status_set(toshiba, time) < 0)
-   return -EIO;
+   /* OR the "base time" to the actual method format */
+   if (toshiba->kbd_type == 1)
+   time |= SCI_KBD_MODE_FNZ;
+   else if (toshiba->kbd_type == 2)
+   time |= SCI_KBD_MODE_AUTO;
+
+   ret = toshiba_kbd_illum_status_set(toshiba, time);
+   if (ret)
+   return ret;
+
toshiba->kbd_time = time >> HCI_MISC_SHIFT;
}
 
-- 
2.0.0

--
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/


Re: [PATCH] toshiba_acpi: Adapt kbd_bl_timeout_store to the new kbd type

2014-10-02 Thread Azael Avalos
Hi there,

2014-10-02 12:32 GMT-06:00 Darren Hart :
> On Mon, Sep 29, 2014 at 08:57:04PM -0600, Azael Avalos wrote:
>> With the introduccion of the new keyboard backlight
>> implementation, the *_timeout_store function is
>> broken, as it only supports the first kbd_type.
>>
>> This patch adapt such function for the new kbd_type,
>> as well as convert from using sscanf to kstrtoint.
>>
>> Signed-off-by: Azael Avalos 
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 33 +
>>  1 file changed, 25 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index 5d509ea..13ee56b 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -1453,18 +1453,35 @@ static ssize_t toshiba_kbd_bl_timeout_store(struct 
>> device *dev,
>>   const char *buf, size_t count)
>>  {
>>   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
>> - int time = -1;
>> + int time;
>> + int ret;
>> +
>> + ret = kstrtoint(buf, 0, &time);
>> + if (ret)
>> + return ret;
>>
>> - if (sscanf(buf, "%i", &time) != 1 && (time < 0 || time > 60))
>> + if (time < 1 || time > 60)
>>   return -EINVAL;
>
> If I'm parsing this correctly, previously a time==0 was valid, and now it will
> return -EINVAL. Is that intentional?

Yes, see below.

>
>>
>> - /* Set the Keyboard Backlight Timeout: 0-60 seconds */
>> - if (time != -1 && toshiba->kbd_time != time) {
>> + /* Set the Keyboard Backlight Timeout: 1-60 seconds */
>
> So the time range change appears intentional. Why is that?

The previous implementation (type 1) accepted values 0-60,
but the new one (type 2) just accepts 1-60, so I basically
just changed both to the new range.

>
>> +
>> + /* Only make a change if the actual timeout has changed */
>> + if (toshiba->kbd_time != time) {
>> + /* Shift the time to "base time" (0x3c == 60 seconds)*/
>>   time = time << HCI_MISC_SHIFT;
>> - time = (toshiba->kbd_mode == SCI_KBD_MODE_AUTO) ?
>> - time + 1 : time + 2;
>> - if (toshiba_kbd_illum_status_set(toshiba, time) < 0)
>> - return -EIO;
>> + /* OR the "base time" to the actual method format */
>> + if (toshiba->kbd_type == 1) {
>> + /* Type 1 requires the oposite mode */
>
> opposite

Typo there, sorry.

>
> Is it "opposite" or "current"?
>

Opposite (again, welcome to Toshiba's KBD BL implementation).

For type 1, to change modes you set (OR?) the value to
the current mode, if FNZ, you set it to AUTO, and viceversa.
Now, to change the time (in case we are in AUTO), you set
the timeout to the opposite mode, if AUTO, you set it to FNZ,
and viceversa (of course this will never happen as the sysfs
entry is hidden).

For type 2, to change modes and time you set the value to the desired
mode (ON, OFF or AUTO), again, the time can only be changed when
in AUTO mode (entry is hidden).

Perhaps something like this?

/* Type 1 requires FNZ mode, if set to AUTO, the time
 * will change, but the mode will be changed as well
 */

>> + time |= SCI_KBD_MODE_FNZ;
>> + } else if (toshiba->kbd_type == 2) {
>> + /* Type 2 requires the actual mode */
>
> actual... as in the mode you are changing to or the mode you are changing 
> from?

We're not changing modes here, just time. Perhaps that comment
is misleading, I can probaly change it to:

/* Type 2 requires SCI_KBD_MODE_AUTO */

Or leave it blank, or perhaps be more verbose:

/* Type 2 requires SCI_KBD_MODE_AUTO, if set to another
 * mode, the time will change but the mode will change as well
 */

>
> From the previous keyboard backlight type patch:
>
> toshiba_acpi: Support new keyboard backlight type
>
> There are several keyboard modes, why do we have only 2 of them here?

Because the timeout entry only takes place (and appears)
whenever the keyboard mode is set to AUTO, on any other
mode is hidden.

> Is it because by setting the timeout we are always changing to _AUTO?

Yes and no.
If the timeout entry exists, that means we are in AUTO, however,
the timeout can be changed even if we are on another mode (without
changing modes).

> Even if that's
> the case, shouldn't one of

[PATCH] toshiba_acpi: Fix regression caused by backlight extra check code

2014-11-03 Thread Azael Avalos
Bug 86521 uncovered that some TOS6208 devices also return
non zero values on a write call to the backlight method,
thus getting caught and bailed out by the extra check code.

This patch makes sure that the extra check is being done
on a TOS1900 device and then make the check for the broken
backlight code.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index ef3a190..e3fed12 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -944,9 +944,13 @@ static int set_lcd_brightness(struct toshiba_acpi_dev 
*dev, int value)
/* Extra check for "incomplete" backlight method, where the AML code
 * doesn't check for HCI_SET or HCI_GET and returns TOS_SUCCESS,
 * the actual brightness, and in some cases the max brightness.
+* Use the SPFC method as an indicator that we're on a TOS1900 device,
+* otherwise some TOS6208 devices might get bailed out, see bug 86521
 */
-   if (out[2] > 0  || out[3] == 0xE000)
-   return -ENODEV;
+   if (acpi_has_method(dev->acpi_dev->handle, "SPFC")) {
+   if (out[2] > 0  || out[3] == 0xE000)
+   return -ENODEV;
+   }
 
return out[0] == TOS_SUCCESS ? 0 : -EIO;
 }
-- 
2.1.1

--
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/


Re: [PATCH] toshiba_acpi: Avoid registering input device on WMI event laptops

2015-07-22 Thread Azael Avalos
Hi Darren,

2015-07-22 14:54 GMT-06:00 Darren Hart :
> On Mon, Jul 20, 2015 at 04:49:51PM -0600, Azael Avalos wrote:
>> Hi Darren,
>>
>> 2015-07-20 15:55 GMT-06:00 Darren Hart :
>> > On Thu, Jul 16, 2015 at 05:38:57PM -0600, Azael Avalos wrote:
>> >> Commit f11f999e9890 ("toshiba_acpi: Refuse to load on machines with
>> >> buggy INFO implementations") denied loading on laptops with a WMI Event
>> >> GUID given that such laptops manage the hotkeys via that interface,
>> >> however, such laptops have a working Toshiba Configuration Interface
>> >> (TCI), and thus, such commit denied several supported features.
>> >>
>> >> This patch avoids registering the input device and ignores all hotkey
>> >> events on laptops with such WMI Event GUI, making the supported
>> >
>> > GUID
>> >
>> >> features found in those laptops to work.
>> >>
>> >> Signed-off-by: Azael Avalos 
>> >> ---
>> >>  drivers/platform/x86/toshiba_acpi.c | 21 +
>> >>  1 file changed, 13 insertions(+), 8 deletions(-)
>> >>
>> >> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> >> b/drivers/platform/x86/toshiba_acpi.c
>> >> index 15d8f0d..a3c6ea2 100644
>> >> --- a/drivers/platform/x86/toshiba_acpi.c
>> >> +++ b/drivers/platform/x86/toshiba_acpi.c
>> >> @@ -2397,6 +2397,11 @@ static int toshiba_acpi_setup_keyboard(struct 
>> >> toshiba_acpi_dev *dev)
>> >>   u32 hci_result;
>> >>   int error;
>> >>
>> >> + if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
>> >> + pr_info("WMI event detected, hotkeys won't be monitored\n");
>> >
>> > It's best practice to avoid contractions in any form of technical writing. 
>> > (See
>> > what I did there? ;-)
>> >
>> > While this is good for comments, I feel it's more important for kernel 
>> > messages.
>> >
>> >> + return 0;
>> >> + }
>> >> +
>> >>   error = toshiba_acpi_enable_hotkeys(dev);
>> >>   if (error)
>> >>   return error;
>> >> @@ -2730,6 +2735,14 @@ static void toshiba_acpi_notify(struct acpi_device 
>> >> *acpi_dev, u32 event)
>> >>
>> >>   switch (event) {
>> >>   case 0x80: /* Hotkeys and some system events */
>> >> + /*
>> >> +  * Machines with this WMI guid aren't supported due to bugs 
>> >> in
>> >> +  * their AML.
>> >> +  *
>> >> +  * Return silently to avoid triggering a netlink event.
>> >> +  */
>> >> + if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
>> >> + return;
>> >>   toshiba_acpi_process_hotkeys(dev);
>> >>   break;
>> >>   case 0x81: /* Dock events */
>> >> @@ -2816,14 +2829,6 @@ static int __init toshiba_acpi_init(void)
>> >>  {
>> >>   int ret;
>> >>
>> >> - /*
>> >> -  * Machines with this WMI guid aren't supported due to bugs in
>> >
>> > Good idea to capitalize acronyms like GUID.
>> >
>> >> -  * their AML. This check relies on wmi initializing before
>> >> -  * toshiba_acpi to guarantee guids have been identified.
>> >> -  */
>> >> - if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
>> >> - return -ENODEV;
>> >> -
>> >>   toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
>> >>   if (!toshiba_proc_dir) {
>> >>   pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
>> >> --
>> >> 2.4.3
>> >>
>> >>
>> >
>> > Functional content looks good. No need to resend, just please keep the 
>> > above in
>> > mind for the future. I'll make the minor updates and merge all three after 
>> > your
>> > response to the first regarding user:kernel interface - unless of course 
>> > you
>> > choose to resend the 3 at the same time, and I'll pick those up.
>>
>> OK, will keep those things in mind, will wait for comments on first patch and
>> send a v2.
>>
>
> I believe I've responded to all the patches in my queue from you. If I'm 
> missing
> one, please let me know which one. I have 4 pending from you. If you send a 
> v2,
> would you just send all 4 to avoid any confusion?

I was waiting for some feedback on the first patch, tho' if there is
no problem with
it, I'll send v2 in a few for you to queue, plus a few others for-review.

>
> Thanks,
>
> --
> Darren Hart
> Intel Open Source Technology Center


Cheers
Azael


-- 
-- El mundo apesta y vosotros apestais tambien --
--
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/


[PATCH v2] toshiba_acpi: Add /dev/toshiba_acpi device

2015-07-22 Thread Azael Avalos
There were previous attempts to "merge" the toshiba SMM module to the
toshiba_acpi one, they were trying to imitate what the old toshiba
module does, however, some models (TOS1900 devices) come with a
"crippled" implementation and do not provide all the "features" a
"genuine" Toshiba BIOS does.

This patch adds a new device called toshiba_acpi, which aim is to
enable userspace to access the SMM on Toshiba laptops via ACPI calls.

Creating a new convenience _IOWR command to access the SCI functions
by opening/closing the SCI internally to avoid buggy BIOS, while at
the same time providing backwards compatibility.

Older programs (and new) who wish to access the SMM on newer models
can do it by pointing their path to /dev/toshiba_acpi (instead of
/dev/toshiba) as the toshiba.h header was modified to reflect these
changes as well as adds all the toshiba_acpi paths and command,
however, it is strongly reccomended to use the new IOCTL for any
SCI command to avoid any buggy BIOS.

Signed-off-by: Azael Avalos 
---
Changes since v1:
- Expanded patch comment a bit

 Documentation/ioctl/ioctl-number.txt |  2 +-
 drivers/platform/x86/toshiba_acpi.c  | 91 
 include/uapi/linux/toshiba.h | 32 +++--
 3 files changed, 121 insertions(+), 4 deletions(-)

diff --git a/Documentation/ioctl/ioctl-number.txt 
b/Documentation/ioctl/ioctl-number.txt
index 611c522..21d2f27 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -263,7 +263,7 @@ Code  Seq#(hex) Include FileComments
 's'all linux/cdk.h
 't'00-7F   linux/ppp-ioctl.h
 't'80-8F   linux/isdn_ppp.h
-'t'90  linux/toshiba.h
+'t'90-91   linux/toshiba.h toshiba and toshiba_acpi SMM
 'u'00-1F   linux/smb_fs.h  gone
 'u'20-3F   linux/uvcvideo.hUSB video class host driver
 'v'00-1F   linux/ext2_fs.h conflict!
diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 871b6d6..0aaf3ed 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -50,6 +50,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 MODULE_AUTHOR("John Belmonte");
@@ -170,6 +172,7 @@ struct toshiba_acpi_dev {
struct led_classdev led_dev;
struct led_classdev kbd_led;
struct led_classdev eco_led;
+   struct miscdevice miscdev;
 
int force_fan;
int last_key_event;
@@ -2255,6 +2258,81 @@ static struct attribute_group toshiba_attr_group = {
 };
 
 /*
+ * Misc device
+ */
+static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
+{
+   u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
+ regs->edx, regs->esi, regs->edi };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   status = tci_raw(toshiba_acpi, in, out);
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to query SMM registers failed\n");
+   return -EIO;
+   }
+
+   /* Fillout the SMM struct with the TCI call results */
+   regs->eax = out[0];
+   regs->ebx = out[1];
+   regs->ecx = out[2];
+   regs->edx = out[3];
+   regs->esi = out[4];
+   regs->edi = out[5];
+
+   return 0;
+}
+
+static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
+  unsigned long arg)
+{
+   SMMRegisters __user *argp = (SMMRegisters __user *)arg;
+   SMMRegisters regs;
+   int ret;
+
+   if (!argp)
+   return -EINVAL;
+
+   switch (cmd) {
+   case TOSH_SMM:
+   if (copy_from_user(®s, argp, sizeof(SMMRegisters)))
+   return -EFAULT;
+   ret = toshiba_acpi_smm_bridge(®s);
+   if (ret)
+   return ret;
+   if (copy_to_user(argp, ®s, sizeof(SMMRegisters)))
+   return -EFAULT;
+   break;
+   case TOSHIBA_ACPI_SCI:
+   if (copy_from_user(®s, argp, sizeof(SMMRegisters)))
+   return -EFAULT;
+   /* Ensure we are being called with a SCI_{GET, SET} register */
+   if (regs.eax != SCI_GET && regs.eax != SCI_SET)
+   return -EINVAL;
+   if (!sci_open(toshiba_acpi))
+   return -EIO;
+   ret = toshiba_acpi_smm_bridge(®s);
+   sci_close(toshiba_acpi);
+   if (ret)
+   return ret;
+   if (copy_to_user(argp, ®s, sizeof(SMMRegisters)))
+   return -EFAULT;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static const struct file_operations 

[PATCH v2] toshiba_acpi: Adapt /proc/acpi/toshiba/keys to TOS1900 devices

2015-07-22 Thread Azael Avalos
Since the introduction of TOS1900 devices support to the driver, the
"keys" entry under the proc directory was broken, given that it only
handled TOS620X devices accordingly.

This patch adapts the code to show the hotkey values of TOS1900
devices too, and in case some programs are still using that interface,
hotkeys reporting should now work on these devices.

Signed-off-by: Azael Avalos 
---
Changes since v1:
- No changes were made, this is simply a resend

 drivers/platform/x86/toshiba_acpi.c | 56 +
 1 file changed, 20 insertions(+), 36 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 0aaf3ed..649786d 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1495,32 +1495,10 @@ static const struct file_operations fan_proc_fops = {
 static int keys_proc_show(struct seq_file *m, void *v)
 {
struct toshiba_acpi_dev *dev = m->private;
-   u32 hci_result;
-   u32 value;
-
-   if (!dev->key_event_valid && dev->system_event_supported) {
-   hci_result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
-   if (hci_result == TOS_SUCCESS) {
-   dev->key_event_valid = 1;
-   dev->last_key_event = value;
-   } else if (hci_result == TOS_FIFO_EMPTY) {
-   /* Better luck next time */
-   } else if (hci_result == TOS_NOT_SUPPORTED) {
-   /*
-* This is a workaround for an unresolved issue on
-* some machines where system events sporadically
-* become disabled.
-*/
-   hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
-   pr_notice("Re-enabled hotkeys\n");
-   } else {
-   pr_err("Error reading hotkey status\n");
-   return -EIO;
-   }
-   }
 
seq_printf(m, "hotkey_ready:%d\n", dev->key_event_valid);
seq_printf(m, "hotkey:  0x%04x\n", dev->last_key_event);
+
return 0;
 }
 
@@ -2432,22 +2410,28 @@ static void toshiba_acpi_report_hotkey(struct 
toshiba_acpi_dev *dev,
 
 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
 {
-   u32 hci_result, value;
-   int retries = 3;
-   int scancode;
-
if (dev->info_supported) {
-   scancode = toshiba_acpi_query_hotkey(dev);
-   if (scancode < 0)
+   int scancode = toshiba_acpi_query_hotkey(dev);
+
+   if (scancode < 0) {
pr_err("Failed to query hotkey event\n");
-   else if (scancode != 0)
+   } else if (scancode != 0) {
toshiba_acpi_report_hotkey(dev, scancode);
+   dev->key_event_valid = 1;
+   dev->last_key_event = scancode;
+   }
} else if (dev->system_event_supported) {
+   u32 result;
+   u32 value;
+   int retries = 3;
+
do {
-   hci_result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
-   switch (hci_result) {
+   result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
+   switch (result) {
case TOS_SUCCESS:
toshiba_acpi_report_hotkey(dev, (int)value);
+   dev->key_event_valid = 1;
+   dev->last_key_event = value;
break;
case TOS_NOT_SUPPORTED:
/*
@@ -2455,15 +2439,15 @@ static void toshiba_acpi_process_hotkeys(struct 
toshiba_acpi_dev *dev)
 * issue on some machines where system events
 * sporadically become disabled.
 */
-   hci_result =
-   hci_write(dev, HCI_SYSTEM_EVENT, 1);
-   pr_notice("Re-enabled hotkeys\n");
+   result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
+   if (result == TOS_SUCCESS)
+   pr_notice("Re-enabled hotkeys\n");
/* Fall through */
default:
retries--;
break;
}
-   } while (retries && hci_result != TOS_FIFO_EMPTY);
+   } while (retries && result != TOS_FIFO_EMPTY);
}
 }
 
-- 
2.4.5

--
To unsubscr

[PATCH v2] toshiba_acpi: Transflective backlight updates

2015-07-22 Thread Azael Avalos
This patch changes the tr function second parameter from bool to u32,
to be on par with the rest of the TCI functions of the driver, and the
code was updated accordingly.

Also, the check for translective support was moved to the *add
function, as the {__get, set}_lcd_brightness functions make use of it.

Signed-off-by: Azael Avalos 
---
Changes since v1:
- Minor typographical corrections in patch description

 drivers/platform/x86/toshiba_acpi.c | 30 +++---
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 3ad7b1f..15d8f0d 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1184,22 +1184,17 @@ static int toshiba_hotkey_event_type_get(struct 
toshiba_acpi_dev *dev,
 }
 
 /* Transflective Backlight */
-static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
+static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
 {
-   u32 hci_result;
-   u32 status;
+   u32 hci_result = hci_read(dev, HCI_TR_BACKLIGHT, status);
 
-   hci_result = hci_read(dev, HCI_TR_BACKLIGHT, &status);
-   *enabled = !status;
return hci_result == TOS_SUCCESS ? 0 : -EIO;
 }
 
-static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
+static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
 {
-   u32 hci_result;
-   u32 value = !enable;
+   u32 hci_result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
 
-   hci_result = hci_write(dev, HCI_TR_BACKLIGHT, value);
return hci_result == TOS_SUCCESS ? 0 : -EIO;
 }
 
@@ -1213,12 +1208,11 @@ static int __get_lcd_brightness(struct toshiba_acpi_dev 
*dev)
int brightness = 0;
 
if (dev->tr_backlight_supported) {
-   bool enabled;
-   int ret = get_tr_backlight_status(dev, &enabled);
+   int ret = get_tr_backlight_status(dev, &value);
 
if (ret)
return ret;
-   if (enabled)
+   if (value)
return 0;
brightness++;
}
@@ -1268,8 +1262,7 @@ static int set_lcd_brightness(struct toshiba_acpi_dev 
*dev, int value)
u32 hci_result;
 
if (dev->tr_backlight_supported) {
-   bool enable = !value;
-   int ret = set_tr_backlight_status(dev, enable);
+   int ret = set_tr_backlight_status(dev, !value);
 
if (ret)
return ret;
@@ -2496,7 +2489,6 @@ static int toshiba_acpi_setup_backlight(struct 
toshiba_acpi_dev *dev)
struct backlight_properties props;
int brightness;
int ret;
-   bool enabled;
 
/*
 * Some machines don't support the backlight methods at all, and
@@ -2513,10 +2505,6 @@ static int toshiba_acpi_setup_backlight(struct 
toshiba_acpi_dev *dev)
return 0;
}
 
-   /* Determine whether or not BIOS supports transflective backlight */
-   ret = get_tr_backlight_status(dev, &enabled);
-   dev->tr_backlight_supported = !ret;
-
/*
 * Tell acpi-video-detect code to prefer vendor backlight on all
 * systems with transflective backlight and on dmi matched systems.
@@ -2643,6 +2631,10 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
if (toshiba_acpi_setup_keyboard(dev))
pr_info("Unable to activate hotkeys\n");
 
+   /* Determine whether or not BIOS supports transflective backlight */
+   ret = get_tr_backlight_status(dev, &dummy);
+   dev->tr_backlight_supported = !ret;
+
ret = toshiba_acpi_setup_backlight(dev);
if (ret)
goto error;
-- 
2.4.5

--
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/


  1   2   3   4   >