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


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


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

2016-10-19 Thread Azael Avalos
Hi Darren,

2016-10-19 14:26 GMT-06:00 Darren Hart <dvh...@infradead.org>:
> On Wed, Oct 12, 2016 at 10:26:43AM -0600, Azael Avalos wrote:
>> *ping*
>>
>> 2016-08-28 11:00 GMT-06:00 Darren Hart <dvh...@infradead.org>:
>> > On Thu, Aug 25, 2016 at 12:50:55PM -0600, Azael Avalos wrote:
>> >> 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: <sta...@vger.kernel.org> # 4.4+
>> >> Signed-off-by: Azael Avalos <coproscef...@gmail.com>
>> >> ---
>> >> 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.
>> >
>> > Thanks. Let's see if Carlos (wmi.c author) has an opinion...
>> >
>> > Carlos?
>>
>> Any input on this?
>
> Looks like a sane workaround to me. Queued to fixes.

Thanks.

>
> Want to going to stable?

If possible, yes, as this issue affects other laptop manufacturers,
we may never know if someone might try to load an older kernel
on an affected laptop and end up with the toshiba_wmi loaded
instead of the actual laptop support module, however, I'm not
sure if this is a "big" issue to bother stable, if not, simply drop
the cc to stable for me please.

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


Cheers
Azael


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


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

2016-10-19 Thread Azael Avalos
Hi Darren,

2016-10-19 14:26 GMT-06:00 Darren Hart :
> On Wed, Oct 12, 2016 at 10:26:43AM -0600, Azael Avalos wrote:
>> *ping*
>>
>> 2016-08-28 11:00 GMT-06:00 Darren Hart :
>> > On Thu, Aug 25, 2016 at 12:50:55PM -0600, Azael Avalos wrote:
>> >> 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.
>> >
>> > Thanks. Let's see if Carlos (wmi.c author) has an opinion...
>> >
>> > Carlos?
>>
>> Any input on this?
>
> Looks like a sane workaround to me. Queued to fixes.

Thanks.

>
> Want to going to stable?

If possible, yes, as this issue affects other laptop manufacturers,
we may never know if someone might try to load an older kernel
on an affected laptop and end up with the toshiba_wmi loaded
instead of the actual laptop support module, however, I'm not
sure if this is a "big" issue to bother stable, if not, simply drop
the cc to stable for me please.

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


Cheers
Azael


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


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

2016-10-12 Thread Azael Avalos
*ping*

2016-08-28 11:00 GMT-06:00 Darren Hart <dvh...@infradead.org>:
> On Thu, Aug 25, 2016 at 12:50:55PM -0600, Azael Avalos wrote:
>> 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: <sta...@vger.kernel.org> # 4.4+
>> Signed-off-by: Azael Avalos <coproscef...@gmail.com>
>> ---
>> 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.
>
> Thanks. Let's see if Carlos (wmi.c author) has an opinion...
>
> Carlos?

Any input on this?

>
>>
>>  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
>>
>>
>
> --
> Darren Hart
> Intel Open Source Technology Center



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


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

2016-10-12 Thread Azael Avalos
*ping*

2016-08-28 11:00 GMT-06:00 Darren Hart :
> On Thu, Aug 25, 2016 at 12:50:55PM -0600, Azael Avalos wrote:
>> 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.
>
> Thanks. Let's see if Carlos (wmi.c author) has an opinion...
>
> Carlos?

Any input on this?

>
>>
>>  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
>>
>>
>
> --
> Darren Hart
> Intel Open Source Technology Center



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


[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 <coproscef...@gmail.com>
---
 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(>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 <coproscef...@gmail.com>
---
 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 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(>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 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 <coproscef...@gmail.com>
---
 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,
-  _present);
-   if (ACPI_FAILURE(status) || !hdd_present) {
+   status = acpi_evaluate_integer(handle, "_STA", NULL, _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 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,
-  _present);
-   if (ACPI_FAILURE(status) || !hdd_present) {
+   status = acpi_evaluate_integer(handle, "_STA", NULL, _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 v2 1/3] toshiba_acpi: Clean up variable declaration

2016-08-29 Thread Azael Avalos
This patch moves all the multiple line variable declaration to a
single line declaration (except variables being initialized)
following the reverse tree order, to conform to the practices
of the kernel.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 9d60a40..54dea64 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -321,10 +321,9 @@ static int write_acpi_int(const char *methodName, int val)
 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
   const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
 {
+   union acpi_object in_objs[TCI_WORDS], out_objs[TCI_WORDS + 1];
struct acpi_object_list params;
-   union acpi_object in_objs[TCI_WORDS];
struct acpi_buffer results;
-   union acpi_object out_objs[TCI_WORDS + 1];
acpi_status status;
int i;
 
@@ -387,9 +386,8 @@ static int sci_open(struct toshiba_acpi_dev *dev)
 {
u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
-   acpi_status status;
+   acpi_status status = tci_raw(dev, in, out);
 
-   status = tci_raw(dev, in, out);
if  (ACPI_FAILURE(status)) {
pr_err("ACPI call to open SCI failed\n");
return 0;
@@ -425,9 +423,8 @@ static void sci_close(struct toshiba_acpi_dev *dev)
 {
u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
-   acpi_status status;
+   acpi_status status = tci_raw(dev, in, out);
 
-   status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to close SCI failed\n");
return;
@@ -509,7 +506,8 @@ 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;
+   u32 result;
+   u32 state;
 
/* First request : initialize communication. */
if (!sci_open(dev))
@@ -672,9 +670,9 @@ static int toshiba_touchpad_get(struct toshiba_acpi_dev 
*dev, u32 *state)
 /* Eco Mode support */
 static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
 {
-   acpi_status status;
u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
+   acpi_status status;
 
dev->eco_supported = 0;
dev->eco_led_registered = false;
@@ -1282,9 +1280,9 @@ static struct proc_dir_entry *toshiba_proc_dir;
 /* LCD Brightness */
 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
 {
+   int brightness = 0;
u32 result;
u32 value;
-   int brightness = 0;
 
if (dev->tr_backlight_supported) {
int ret = get_tr_backlight_status(dev, );
@@ -1377,7 +1375,7 @@ static ssize_t lcd_proc_write(struct file *file, const 
char __user *buf,
struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
char cmd[42];
size_t len;
-   int levels = dev->backlight_dev->props.max_brightness + 1;
+   int levels;
int value;
 
len = min(count, sizeof(cmd) - 1);
@@ -1385,6 +1383,7 @@ static ssize_t lcd_proc_write(struct file *file, const 
char __user *buf,
return -EFAULT;
cmd[len] = '\0';
 
+   levels = dev->backlight_dev->props.max_brightness + 1;
if (sscanf(cmd, " brightness : %i", ) != 1 &&
value < 0 && value > levels)
return -EINVAL;
@@ -1447,10 +1446,8 @@ static ssize_t video_proc_write(struct file *file, const 
char __user *buf,
struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
char *buffer;
char *cmd;
+   int lcd_out, crt_out, tv_out;
int remain = count;
-   int lcd_out = -1;
-   int crt_out = -1;
-   int tv_out = -1;
int value;
int ret;
u32 video_out;
@@ -1486,6 +1483,7 @@ static ssize_t video_proc_write(struct file *file, const 
char __user *buf,
 
kfree(cmd);
 
+   lcd_out = crt_out = tv_out = -1;
ret = get_video_status(dev, _out);
if (!ret) {
unsigned int new_video_out = video_out;
@@ -1980,9 +1978,9 @@ static ssize_t usb_sleep_charge_store(struct device *dev,
  const char *buf, size_t count)
 {
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-   u32 mode;
int state;
int ret;
+   u32 mode;
 
ret = kstrtoint(buf, 0, );
if (ret)
@@ -2021,11 +2019,10 @@ static ssize_t sleep_functions_on_battery_show(struct 
device *dev,

[PATCH v2 1/3] toshiba_acpi: Clean up variable declaration

2016-08-29 Thread Azael Avalos
This patch moves all the multiple line variable declaration to a
single line declaration (except variables being initialized)
following the reverse tree order, to conform to the practices
of the kernel.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 9d60a40..54dea64 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -321,10 +321,9 @@ static int write_acpi_int(const char *methodName, int val)
 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
   const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
 {
+   union acpi_object in_objs[TCI_WORDS], out_objs[TCI_WORDS + 1];
struct acpi_object_list params;
-   union acpi_object in_objs[TCI_WORDS];
struct acpi_buffer results;
-   union acpi_object out_objs[TCI_WORDS + 1];
acpi_status status;
int i;
 
@@ -387,9 +386,8 @@ static int sci_open(struct toshiba_acpi_dev *dev)
 {
u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
-   acpi_status status;
+   acpi_status status = tci_raw(dev, in, out);
 
-   status = tci_raw(dev, in, out);
if  (ACPI_FAILURE(status)) {
pr_err("ACPI call to open SCI failed\n");
return 0;
@@ -425,9 +423,8 @@ static void sci_close(struct toshiba_acpi_dev *dev)
 {
u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
-   acpi_status status;
+   acpi_status status = tci_raw(dev, in, out);
 
-   status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to close SCI failed\n");
return;
@@ -509,7 +506,8 @@ 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;
+   u32 result;
+   u32 state;
 
/* First request : initialize communication. */
if (!sci_open(dev))
@@ -672,9 +670,9 @@ static int toshiba_touchpad_get(struct toshiba_acpi_dev 
*dev, u32 *state)
 /* Eco Mode support */
 static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
 {
-   acpi_status status;
u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
+   acpi_status status;
 
dev->eco_supported = 0;
dev->eco_led_registered = false;
@@ -1282,9 +1280,9 @@ static struct proc_dir_entry *toshiba_proc_dir;
 /* LCD Brightness */
 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
 {
+   int brightness = 0;
u32 result;
u32 value;
-   int brightness = 0;
 
if (dev->tr_backlight_supported) {
int ret = get_tr_backlight_status(dev, );
@@ -1377,7 +1375,7 @@ static ssize_t lcd_proc_write(struct file *file, const 
char __user *buf,
struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
char cmd[42];
size_t len;
-   int levels = dev->backlight_dev->props.max_brightness + 1;
+   int levels;
int value;
 
len = min(count, sizeof(cmd) - 1);
@@ -1385,6 +1383,7 @@ static ssize_t lcd_proc_write(struct file *file, const 
char __user *buf,
return -EFAULT;
cmd[len] = '\0';
 
+   levels = dev->backlight_dev->props.max_brightness + 1;
if (sscanf(cmd, " brightness : %i", ) != 1 &&
value < 0 && value > levels)
return -EINVAL;
@@ -1447,10 +1446,8 @@ static ssize_t video_proc_write(struct file *file, const 
char __user *buf,
struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
char *buffer;
char *cmd;
+   int lcd_out, crt_out, tv_out;
int remain = count;
-   int lcd_out = -1;
-   int crt_out = -1;
-   int tv_out = -1;
int value;
int ret;
u32 video_out;
@@ -1486,6 +1483,7 @@ static ssize_t video_proc_write(struct file *file, const 
char __user *buf,
 
kfree(cmd);
 
+   lcd_out = crt_out = tv_out = -1;
ret = get_video_status(dev, _out);
if (!ret) {
unsigned int new_video_out = video_out;
@@ -1980,9 +1978,9 @@ static ssize_t usb_sleep_charge_store(struct device *dev,
  const char *buf, size_t count)
 {
struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-   u32 mode;
int state;
int ret;
+   u32 mode;
 
ret = kstrtoint(buf, 0, );
if (ret)
@@ -2021,11 +2019,10 @@ static ssize_t sleep_functions_on_battery_show(struct 
device *dev,
   char *buf)
 {
s

[PATCH v2 3/3] toshiba_acpi: Fix typo in *_cooling_method_set function

2016-08-29 Thread Azael Avalos
This patch simply fixes a typo in the error string printed in such
function.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 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 cc14e80..93f9ce1 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1291,7 +1291,7 @@ static int toshiba_cooling_method_set(struct 
toshiba_acpi_dev *dev, u32 state)
u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
 
if (result == TOS_FAILURE)
-   pr_err("ACPI call to get Cooling Method failed\n");
+   pr_err("ACPI call to set Cooling Method failed\n");
 
if (result == TOS_NOT_SUPPORTED)
return -ENODEV;
-- 
2.9.3



[PATCH v2 3/3] toshiba_acpi: Fix typo in *_cooling_method_set function

2016-08-29 Thread Azael Avalos
This patch simply fixes a typo in the error string printed in such
function.

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 cc14e80..93f9ce1 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1291,7 +1291,7 @@ static int toshiba_cooling_method_set(struct 
toshiba_acpi_dev *dev, u32 state)
u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
 
if (result == TOS_FAILURE)
-   pr_err("ACPI call to get Cooling Method failed\n");
+   pr_err("ACPI call to set Cooling Method failed\n");
 
if (result == TOS_NOT_SUPPORTED)
return -ENODEV;
-- 
2.9.3



[PATCH v2 0/3] toshiba_acpi: Functions cleanup

2016-08-29 Thread Azael Avalos
These set of patches make some cleanup in some of the driver's functions.

The first patch changes the variables declaration, the second changes
the error checking logic and the third simply fixes a typo found while
making these changes.

Changes since v1:
- Small changes to patch 01 acording to Darren's comments
- Added a missing return on *eco_mode_available function

Azael Avalos (3):
  toshiba_acpi: Clean up variable declaration
  toshiba_acpi: Change error checking logic from TCI functions
  toshiba_acpi: Fix typo in *_cooling_method_set function

 drivers/platform/x86/toshiba_acpi.c | 261 +---
 1 file changed, 154 insertions(+), 107 deletions(-)

-- 
2.9.3



[PATCH v2 2/3] toshiba_acpi: Change error checking logic from TCI functions

2016-08-29 Thread Azael Avalos
Currently the success/error checking logic is intermixed, making the
code a bit cumbersome to understand.

This patch changes the affected functions to first check for errors
and take appropriate actions, then check for the supported features.

This patch also separates the error check from the acpi_status and
the tci_raw function call error check, as those two are completely
unrelated and were nested in if/else statements.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 54dea64..cc14e80 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -476,10 +476,15 @@ static void toshiba_illumination_available(struct 
toshiba_acpi_dev *dev)
 
status = tci_raw(dev, in, out);
sci_close(dev);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query Illumination support failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->illumination_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->illumination_supported = 1;
 }
 
 static void toshiba_illumination_set(struct led_classdev *cdev,
@@ -544,24 +549,28 @@ static void toshiba_kbd_illum_available(struct 
toshiba_acpi_dev *dev)
sci_close(dev);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query kbd illumination support failed\n");
-   } else if (out[0] == TOS_SUCCESS) {
-   /*
-* 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;
-   /* Flag as supported */
-   dev->kbd_illum_supported = 1;
+   return;
}
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   /*
+* 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;
+   /* Flag as supported */
+   dev->kbd_illum_supported = 1;
 }
 
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
@@ -680,7 +689,10 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return;
+   }
+
+   if (out[0] == TOS_INPUT_DATA_ERROR) {
/*
 * If we receive 0x8300 (Input Data Error), it means that the
 * LED device is present, but that we just screwed the input
@@ -692,10 +704,15 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
 */
in[3] = 1;
status = tci_raw(dev, in, out);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->eco_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->eco_supported = 1;
}
 }
 
@@ -712,10 +729,11 @@ toshiba_eco_mode_get_status(struct led_classdev *cdev)
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
return LED_OFF;
-   } else if (out[0] != TOS_SUCCESS) {
-   return LED_OFF;
}
 
+   if (out[0] != TOS_SUCCESS)
+   return LED_OFF;
+
   

[PATCH v2 0/3] toshiba_acpi: Functions cleanup

2016-08-29 Thread Azael Avalos
These set of patches make some cleanup in some of the driver's functions.

The first patch changes the variables declaration, the second changes
the error checking logic and the third simply fixes a typo found while
making these changes.

Changes since v1:
- Small changes to patch 01 acording to Darren's comments
- Added a missing return on *eco_mode_available function

Azael Avalos (3):
  toshiba_acpi: Clean up variable declaration
  toshiba_acpi: Change error checking logic from TCI functions
  toshiba_acpi: Fix typo in *_cooling_method_set function

 drivers/platform/x86/toshiba_acpi.c | 261 +---
 1 file changed, 154 insertions(+), 107 deletions(-)

-- 
2.9.3



[PATCH v2 2/3] toshiba_acpi: Change error checking logic from TCI functions

2016-08-29 Thread Azael Avalos
Currently the success/error checking logic is intermixed, making the
code a bit cumbersome to understand.

This patch changes the affected functions to first check for errors
and take appropriate actions, then check for the supported features.

This patch also separates the error check from the acpi_status and
the tci_raw function call error check, as those two are completely
unrelated and were nested in if/else statements.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 54dea64..cc14e80 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -476,10 +476,15 @@ static void toshiba_illumination_available(struct 
toshiba_acpi_dev *dev)
 
status = tci_raw(dev, in, out);
sci_close(dev);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query Illumination support failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->illumination_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->illumination_supported = 1;
 }
 
 static void toshiba_illumination_set(struct led_classdev *cdev,
@@ -544,24 +549,28 @@ static void toshiba_kbd_illum_available(struct 
toshiba_acpi_dev *dev)
sci_close(dev);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query kbd illumination support failed\n");
-   } else if (out[0] == TOS_SUCCESS) {
-   /*
-* 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;
-   /* Flag as supported */
-   dev->kbd_illum_supported = 1;
+   return;
}
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   /*
+* 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;
+   /* Flag as supported */
+   dev->kbd_illum_supported = 1;
 }
 
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
@@ -680,7 +689,10 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return;
+   }
+
+   if (out[0] == TOS_INPUT_DATA_ERROR) {
/*
 * If we receive 0x8300 (Input Data Error), it means that the
 * LED device is present, but that we just screwed the input
@@ -692,10 +704,15 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
 */
in[3] = 1;
status = tci_raw(dev, in, out);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->eco_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->eco_supported = 1;
}
 }
 
@@ -712,10 +729,11 @@ toshiba_eco_mode_get_status(struct led_classdev *cdev)
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
return LED_OFF;
-   } else if (out[0] != TOS_SUCCESS) {
-   return LED_OFF;
}
 
+   if (out[0] != TOS_SUCCESS)
+   return LED_OFF;
+
return out[2] ? LED_FULL

Re: [PATCH 1/3] toshiba_acpi: Cleanup variable declaration

2016-08-29 Thread Azael Avalos
Hi Darren,

2016-08-28 10:49 GMT-06:00 Darren Hart <dvh...@infradead.org>:
> On Tue, Aug 16, 2016 at 12:06:15PM -0600, Azael Avalos wrote:
>> This patch moves all the multiple line variable declaration to a
>> single line declaration (except variables being initialized)
>> following the reverse tree order, to conform to the practices
>> of the kernel.
>
> Azael,
>
> Apologies for the delay, I was trying to decide what position I wanted to take
> on this as anything I do builds precedent for future patches.
>
> Early on I was pretty strict about this for new code. I've found that there is
> less consensus about this among the maintainers than I initially thought. I'm
> not sure it's worth a patch just to clean this up - but I also don't object,
> especially given how actively you maintain this driver.
>
> One minor point about consolidating similar types in one declaration line. We
> prefer to group similar types of related purpose. For example:
>
> int in_len, out_len;
> int num_frames;
> int ret;
>
> Rather than:
>
> int in_len, out_len, num_frames, ret;
>
> With that in mind, I'll take this as is, or I'll wait for a respin. Up to you.

I'll send a v2 in a few as I caught a missing return on one of the functions
on patch 02.

>
> --
> Darren
>
>>
>> Signed-off-by: Azael Avalos <coproscef...@gmail.com>
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 98 
>> +
>>  1 file changed, 33 insertions(+), 65 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index 9d60a40..c6fc5cc 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -321,10 +321,9 @@ static int write_acpi_int(const char *methodName, int 
>> val)
>>  static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
>>  const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
>>  {
>> + union acpi_object in_objs[TCI_WORDS], out_objs[TCI_WORDS + 1];
>>   struct acpi_object_list params;
>> - union acpi_object in_objs[TCI_WORDS];
>>   struct acpi_buffer results;
>> - union acpi_object out_objs[TCI_WORDS + 1];
>>   acpi_status status;
>>   int i;
>>
>> @@ -387,9 +386,8 @@ static int sci_open(struct toshiba_acpi_dev *dev)
>>  {
>>   u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
>>   u32 out[TCI_WORDS];
>> - acpi_status status;
>> + acpi_status status = tci_raw(dev, in, out);
>>
>> - status = tci_raw(dev, in, out);
>>   if  (ACPI_FAILURE(status)) {
>>   pr_err("ACPI call to open SCI failed\n");
>>   return 0;
>> @@ -425,9 +423,8 @@ static void sci_close(struct toshiba_acpi_dev *dev)
>>  {
>>   u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
>>   u32 out[TCI_WORDS];
>> - acpi_status status;
>> + acpi_status status = tci_raw(dev, in, out);
>>
>> - status = tci_raw(dev, in, out);
>>   if (ACPI_FAILURE(status)) {
>>   pr_err("ACPI call to close SCI failed\n");
>>   return;
>> @@ -490,8 +487,7 @@ static void toshiba_illumination_set(struct led_classdev 
>> *cdev,
>>  {
>>   struct toshiba_acpi_dev *dev = container_of(cdev,
>>   struct toshiba_acpi_dev, led_dev);
>> - u32 result;
>> - u32 state;
>> + u32 result, state;
>>
>>   /* First request : initialize communication. */
>>   if (!sci_open(dev))
>> @@ -509,7 +505,7 @@ 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;
>> + u32 result, state;
>>
>>   /* First request : initialize communication. */
>>   if (!sci_open(dev))
>> @@ -604,8 +600,7 @@ 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 result;
>> - u32 state;
>> + u32 result, state;
>>
>>   /* Check the keyboard backlight state */
>>   result = hci_read(dev, HCI_KBD_ILLUMINATION, );
>> @@ -624,8 +619,7 @@ static void toshiba_kbd_backlight_set(struct 
>> led_classdev *cdev,
>>  {
>>   struct toshiba_acpi_dev *dev = containe

Re: [PATCH 1/3] toshiba_acpi: Cleanup variable declaration

2016-08-29 Thread Azael Avalos
Hi Darren,

2016-08-28 10:49 GMT-06:00 Darren Hart :
> On Tue, Aug 16, 2016 at 12:06:15PM -0600, Azael Avalos wrote:
>> This patch moves all the multiple line variable declaration to a
>> single line declaration (except variables being initialized)
>> following the reverse tree order, to conform to the practices
>> of the kernel.
>
> Azael,
>
> Apologies for the delay, I was trying to decide what position I wanted to take
> on this as anything I do builds precedent for future patches.
>
> Early on I was pretty strict about this for new code. I've found that there is
> less consensus about this among the maintainers than I initially thought. I'm
> not sure it's worth a patch just to clean this up - but I also don't object,
> especially given how actively you maintain this driver.
>
> One minor point about consolidating similar types in one declaration line. We
> prefer to group similar types of related purpose. For example:
>
> int in_len, out_len;
> int num_frames;
> int ret;
>
> Rather than:
>
> int in_len, out_len, num_frames, ret;
>
> With that in mind, I'll take this as is, or I'll wait for a respin. Up to you.

I'll send a v2 in a few as I caught a missing return on one of the functions
on patch 02.

>
> --
> Darren
>
>>
>> Signed-off-by: Azael Avalos 
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 98 
>> +
>>  1 file changed, 33 insertions(+), 65 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index 9d60a40..c6fc5cc 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -321,10 +321,9 @@ static int write_acpi_int(const char *methodName, int 
>> val)
>>  static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
>>  const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
>>  {
>> + union acpi_object in_objs[TCI_WORDS], out_objs[TCI_WORDS + 1];
>>   struct acpi_object_list params;
>> - union acpi_object in_objs[TCI_WORDS];
>>   struct acpi_buffer results;
>> - union acpi_object out_objs[TCI_WORDS + 1];
>>   acpi_status status;
>>   int i;
>>
>> @@ -387,9 +386,8 @@ static int sci_open(struct toshiba_acpi_dev *dev)
>>  {
>>   u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
>>   u32 out[TCI_WORDS];
>> - acpi_status status;
>> + acpi_status status = tci_raw(dev, in, out);
>>
>> - status = tci_raw(dev, in, out);
>>   if  (ACPI_FAILURE(status)) {
>>   pr_err("ACPI call to open SCI failed\n");
>>   return 0;
>> @@ -425,9 +423,8 @@ static void sci_close(struct toshiba_acpi_dev *dev)
>>  {
>>   u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
>>   u32 out[TCI_WORDS];
>> - acpi_status status;
>> + acpi_status status = tci_raw(dev, in, out);
>>
>> - status = tci_raw(dev, in, out);
>>   if (ACPI_FAILURE(status)) {
>>   pr_err("ACPI call to close SCI failed\n");
>>   return;
>> @@ -490,8 +487,7 @@ static void toshiba_illumination_set(struct led_classdev 
>> *cdev,
>>  {
>>   struct toshiba_acpi_dev *dev = container_of(cdev,
>>   struct toshiba_acpi_dev, led_dev);
>> - u32 result;
>> - u32 state;
>> + u32 result, state;
>>
>>   /* First request : initialize communication. */
>>   if (!sci_open(dev))
>> @@ -509,7 +505,7 @@ 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;
>> + u32 result, state;
>>
>>   /* First request : initialize communication. */
>>   if (!sci_open(dev))
>> @@ -604,8 +600,7 @@ 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 result;
>> - u32 state;
>> + u32 result, state;
>>
>>   /* Check the keyboard backlight state */
>>   result = hci_read(dev, HCI_KBD_ILLUMINATION, );
>> @@ -624,8 +619,7 @@ static void toshiba_kbd_backlight_set(struct 
>> led_classdev *cdev,
>>  {
>>   struct toshiba_acpi_dev *dev = container_of(cdev,
>>   struct toshib

Re: [PATCH 2/3] toshiba_acpi: Change error checking logic from TCI functions

2016-08-29 Thread Azael Avalos
Hi Darren,

2016-08-28 10:56 GMT-06:00 Darren Hart <dvh...@infradead.org>:
> On Tue, Aug 16, 2016 at 12:06:16PM -0600, Azael Avalos wrote:
>> Currently the success/error checking logic is intermixed, making the
>> code a bit cumbersome to understand.
>>
>> This patch changes the affected functions to first check for errors
>> and take appropriate actions, then check for the supported features.
>>
>> This patch also separates the error check from the acpi_status and
>> the tci_raw function call error check, as those two are completely
>> unrelated and were nested in if/else statements.
>
> Thanks, this is a good improvement. One questions below...
>
>>
>> Signed-off-by: Azael Avalos <coproscef...@gmail.com>
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 222 
>> ++--
>>  1 file changed, 135 insertions(+), 87 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index c6fc5cc..2256cf5 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -476,10 +476,15 @@ static void toshiba_illumination_available(struct 
>> toshiba_acpi_dev *dev)
>>
>>   status = tci_raw(dev, in, out);
>>   sci_close(dev);
>> - if (ACPI_FAILURE(status))
>> + if (ACPI_FAILURE(status)) {
>>   pr_err("ACPI call to query Illumination support failed\n");
>> - else if (out[0] == TOS_SUCCESS)
>> - dev->illumination_supported = 1;
>> + return;
>> + }
>> +
>> + if (out[0] != TOS_SUCCESS)
>
> Does this condition not merit a pr_err message? It reads like an error...
>
> There are several similar situations below which are equally silent. Is this a
> deliberate decision?

This was on purpose, since we are querying for all the supported features,
the kernel log will contain a lot of error strings for not supported features,
as not all laptop models support all of them.

>
> --
> Darren Hart
> Intel Open Source Technology Center
> --
> 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 --


Re: [PATCH 2/3] toshiba_acpi: Change error checking logic from TCI functions

2016-08-29 Thread Azael Avalos
Hi Darren,

2016-08-28 10:56 GMT-06:00 Darren Hart :
> On Tue, Aug 16, 2016 at 12:06:16PM -0600, Azael Avalos wrote:
>> Currently the success/error checking logic is intermixed, making the
>> code a bit cumbersome to understand.
>>
>> This patch changes the affected functions to first check for errors
>> and take appropriate actions, then check for the supported features.
>>
>> This patch also separates the error check from the acpi_status and
>> the tci_raw function call error check, as those two are completely
>> unrelated and were nested in if/else statements.
>
> Thanks, this is a good improvement. One questions below...
>
>>
>> Signed-off-by: Azael Avalos 
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 222 
>> ++--
>>  1 file changed, 135 insertions(+), 87 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index c6fc5cc..2256cf5 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -476,10 +476,15 @@ static void toshiba_illumination_available(struct 
>> toshiba_acpi_dev *dev)
>>
>>   status = tci_raw(dev, in, out);
>>   sci_close(dev);
>> - if (ACPI_FAILURE(status))
>> + if (ACPI_FAILURE(status)) {
>>   pr_err("ACPI call to query Illumination support failed\n");
>> - else if (out[0] == TOS_SUCCESS)
>> - dev->illumination_supported = 1;
>> + return;
>> + }
>> +
>> + if (out[0] != TOS_SUCCESS)
>
> Does this condition not merit a pr_err message? It reads like an error...
>
> There are several similar situations below which are equally silent. Is this a
> deliberate decision?

This was on purpose, since we are querying for all the supported features,
the kernel log will contain a lot of error strings for not supported features,
as not all laptop models support all of them.

>
> --
> Darren Hart
> Intel Open Source Technology Center
> --
> 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 --


[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: <sta...@vger.kernel.org> # 4.4+
Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
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-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 0/3] toshiba_acpi: Functions cleanup

2016-08-16 Thread Azael Avalos
These set of patches make some cleanup in some of the driver's functions.

The first patch changes the variables declaration, the second changes
the error checking logic and the third simply fixes a typo found while
making these changes.

Azael Avalos (3):
  toshiba_acpi: Cleanup variable declaration
  toshiba_acpi: Change error checking logic from TCI functions
  toshiba_acpi: Fix typo in *_cooling_method_set function

 drivers/platform/x86/toshiba_acpi.c | 322 +++-
 1 file changed, 169 insertions(+), 153 deletions(-)

-- 
2.9.2



[PATCH 3/3] toshiba_acpi: Fix typo in *_cooling_method_set function

2016-08-16 Thread Azael Avalos
This patch simply fixes a typo in the error string printed in such
function.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 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 2256cf5..254a4d5 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1285,7 +1285,7 @@ static int toshiba_cooling_method_set(struct 
toshiba_acpi_dev *dev, u32 state)
u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
 
if (result == TOS_FAILURE)
-   pr_err("ACPI call to get Cooling Method failed\n");
+   pr_err("ACPI call to set Cooling Method failed\n");
 
if (result == TOS_NOT_SUPPORTED)
return -ENODEV;
-- 
2.9.2



[PATCH 0/3] toshiba_acpi: Functions cleanup

2016-08-16 Thread Azael Avalos
These set of patches make some cleanup in some of the driver's functions.

The first patch changes the variables declaration, the second changes
the error checking logic and the third simply fixes a typo found while
making these changes.

Azael Avalos (3):
  toshiba_acpi: Cleanup variable declaration
  toshiba_acpi: Change error checking logic from TCI functions
  toshiba_acpi: Fix typo in *_cooling_method_set function

 drivers/platform/x86/toshiba_acpi.c | 322 +++-
 1 file changed, 169 insertions(+), 153 deletions(-)

-- 
2.9.2



[PATCH 3/3] toshiba_acpi: Fix typo in *_cooling_method_set function

2016-08-16 Thread Azael Avalos
This patch simply fixes a typo in the error string printed in such
function.

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 2256cf5..254a4d5 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1285,7 +1285,7 @@ static int toshiba_cooling_method_set(struct 
toshiba_acpi_dev *dev, u32 state)
u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
 
if (result == TOS_FAILURE)
-   pr_err("ACPI call to get Cooling Method failed\n");
+   pr_err("ACPI call to set Cooling Method failed\n");
 
if (result == TOS_NOT_SUPPORTED)
return -ENODEV;
-- 
2.9.2



[PATCH 2/3] toshiba_acpi: Change error checking logic from TCI functions

2016-08-16 Thread Azael Avalos
Currently the success/error checking logic is intermixed, making the
code a bit cumbersome to understand.

This patch changes the affected functions to first check for errors
and take appropriate actions, then check for the supported features.

This patch also separates the error check from the acpi_status and
the tci_raw function call error check, as those two are completely
unrelated and were nested in if/else statements.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index c6fc5cc..2256cf5 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -476,10 +476,15 @@ static void toshiba_illumination_available(struct 
toshiba_acpi_dev *dev)
 
status = tci_raw(dev, in, out);
sci_close(dev);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query Illumination support failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->illumination_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->illumination_supported = 1;
 }
 
 static void toshiba_illumination_set(struct led_classdev *cdev,
@@ -542,24 +547,28 @@ static void toshiba_kbd_illum_available(struct 
toshiba_acpi_dev *dev)
sci_close(dev);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query kbd illumination support failed\n");
-   } else if (out[0] == TOS_SUCCESS) {
-   /*
-* 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;
-   /* Flag as supported */
-   dev->kbd_illum_supported = 1;
+   return;
}
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   /*
+* 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;
+   /* Flag as supported */
+   dev->kbd_illum_supported = 1;
 }
 
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
@@ -676,7 +685,10 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return;
+   }
+
+   if (out[0] == TOS_INPUT_DATA_ERROR) {
/*
 * If we receive 0x8300 (Input Data Error), it means that the
 * LED device is present, but that we just screwed the input
@@ -690,8 +702,11 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status))
pr_err("ACPI call to get ECO led failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->eco_supported = 1;
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->eco_supported = 1;
}
 }
 
@@ -708,10 +723,11 @@ toshiba_eco_mode_get_status(struct led_classdev *cdev)
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
return LED_OFF;
-   } else if (out[0] != TOS_SUCCESS) {
-   return LED_OFF;
}
 
+   if (out[0] != TOS_SUCCESS)
+   return LED_OFF;
+
return out[2] ? LED_FULL : LED_OFF;
 }
 
@@ -745,10 +761,15 @@ static void toshiba_accelerometer_available(struct 
toshiba_acpi_dev *dev)
 

[PATCH 1/3] toshiba_acpi: Cleanup variable declaration

2016-08-16 Thread Azael Avalos
This patch moves all the multiple line variable declaration to a
single line declaration (except variables being initialized)
following the reverse tree order, to conform to the practices
of the kernel.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 9d60a40..c6fc5cc 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -321,10 +321,9 @@ static int write_acpi_int(const char *methodName, int val)
 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
   const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
 {
+   union acpi_object in_objs[TCI_WORDS], out_objs[TCI_WORDS + 1];
struct acpi_object_list params;
-   union acpi_object in_objs[TCI_WORDS];
struct acpi_buffer results;
-   union acpi_object out_objs[TCI_WORDS + 1];
acpi_status status;
int i;
 
@@ -387,9 +386,8 @@ static int sci_open(struct toshiba_acpi_dev *dev)
 {
u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
-   acpi_status status;
+   acpi_status status = tci_raw(dev, in, out);
 
-   status = tci_raw(dev, in, out);
if  (ACPI_FAILURE(status)) {
pr_err("ACPI call to open SCI failed\n");
return 0;
@@ -425,9 +423,8 @@ static void sci_close(struct toshiba_acpi_dev *dev)
 {
u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
-   acpi_status status;
+   acpi_status status = tci_raw(dev, in, out);
 
-   status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to close SCI failed\n");
return;
@@ -490,8 +487,7 @@ static void toshiba_illumination_set(struct led_classdev 
*cdev,
 {
struct toshiba_acpi_dev *dev = container_of(cdev,
struct toshiba_acpi_dev, led_dev);
-   u32 result;
-   u32 state;
+   u32 result, state;
 
/* First request : initialize communication. */
if (!sci_open(dev))
@@ -509,7 +505,7 @@ 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;
+   u32 result, state;
 
/* First request : initialize communication. */
if (!sci_open(dev))
@@ -604,8 +600,7 @@ 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 result;
-   u32 state;
+   u32 result, state;
 
/* Check the keyboard backlight state */
result = hci_read(dev, HCI_KBD_ILLUMINATION, );
@@ -624,8 +619,7 @@ 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 result;
-   u32 state;
+   u32 result, state;
 
/* Set the keyboard backlight state */
state = brightness ? 1 : 0;
@@ -672,9 +666,9 @@ static int toshiba_touchpad_get(struct toshiba_acpi_dev 
*dev, u32 *state)
 /* Eco Mode support */
 static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
 {
-   acpi_status status;
u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
+   acpi_status status;
 
dev->eco_supported = 0;
dev->eco_led_registered = false;
@@ -1282,9 +1276,8 @@ static struct proc_dir_entry *toshiba_proc_dir;
 /* LCD Brightness */
 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
 {
-   u32 result;
-   u32 value;
int brightness = 0;
+   u32 result, value;
 
if (dev->tr_backlight_supported) {
int ret = get_tr_backlight_status(dev, );
@@ -1317,8 +1310,7 @@ static int get_lcd_brightness(struct backlight_device *bd)
 static int lcd_proc_show(struct seq_file *m, void *v)
 {
struct toshiba_acpi_dev *dev = m->private;
-   int levels;
-   int value;
+   int levels, value;
 
if (!dev->backlight_dev)
return -ENODEV;
@@ -1375,16 +1367,16 @@ static ssize_t lcd_proc_write(struct file *file, const 
char __user *buf,
  size_t count, loff_t *pos)
 {
struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
+   int levels, value;
char cmd[42];
size_t len;
-   int levels = dev->backlight_dev->props.max_brightness + 1;
-   int value;
 
len = min(count, sizeof(cmd) - 1);
if (copy_from_user(cmd, buf, len))
   

[PATCH 2/3] toshiba_acpi: Change error checking logic from TCI functions

2016-08-16 Thread Azael Avalos
Currently the success/error checking logic is intermixed, making the
code a bit cumbersome to understand.

This patch changes the affected functions to first check for errors
and take appropriate actions, then check for the supported features.

This patch also separates the error check from the acpi_status and
the tci_raw function call error check, as those two are completely
unrelated and were nested in if/else statements.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index c6fc5cc..2256cf5 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -476,10 +476,15 @@ static void toshiba_illumination_available(struct 
toshiba_acpi_dev *dev)
 
status = tci_raw(dev, in, out);
sci_close(dev);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query Illumination support failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->illumination_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->illumination_supported = 1;
 }
 
 static void toshiba_illumination_set(struct led_classdev *cdev,
@@ -542,24 +547,28 @@ static void toshiba_kbd_illum_available(struct 
toshiba_acpi_dev *dev)
sci_close(dev);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query kbd illumination support failed\n");
-   } else if (out[0] == TOS_SUCCESS) {
-   /*
-* 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;
-   /* Flag as supported */
-   dev->kbd_illum_supported = 1;
+   return;
}
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   /*
+* 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;
+   /* Flag as supported */
+   dev->kbd_illum_supported = 1;
 }
 
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
@@ -676,7 +685,10 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return;
+   }
+
+   if (out[0] == TOS_INPUT_DATA_ERROR) {
/*
 * If we receive 0x8300 (Input Data Error), it means that the
 * LED device is present, but that we just screwed the input
@@ -690,8 +702,11 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status))
pr_err("ACPI call to get ECO led failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->eco_supported = 1;
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->eco_supported = 1;
}
 }
 
@@ -708,10 +723,11 @@ toshiba_eco_mode_get_status(struct led_classdev *cdev)
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
return LED_OFF;
-   } else if (out[0] != TOS_SUCCESS) {
-   return LED_OFF;
}
 
+   if (out[0] != TOS_SUCCESS)
+   return LED_OFF;
+
return out[2] ? LED_FULL : LED_OFF;
 }
 
@@ -745,10 +761,15 @@ static void toshiba_accelerometer_available(struct 
toshiba_acpi_dev *dev)
 * this call a

[PATCH 1/3] toshiba_acpi: Cleanup variable declaration

2016-08-16 Thread Azael Avalos
This patch moves all the multiple line variable declaration to a
single line declaration (except variables being initialized)
following the reverse tree order, to conform to the practices
of the kernel.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 9d60a40..c6fc5cc 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -321,10 +321,9 @@ static int write_acpi_int(const char *methodName, int val)
 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
   const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
 {
+   union acpi_object in_objs[TCI_WORDS], out_objs[TCI_WORDS + 1];
struct acpi_object_list params;
-   union acpi_object in_objs[TCI_WORDS];
struct acpi_buffer results;
-   union acpi_object out_objs[TCI_WORDS + 1];
acpi_status status;
int i;
 
@@ -387,9 +386,8 @@ static int sci_open(struct toshiba_acpi_dev *dev)
 {
u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
-   acpi_status status;
+   acpi_status status = tci_raw(dev, in, out);
 
-   status = tci_raw(dev, in, out);
if  (ACPI_FAILURE(status)) {
pr_err("ACPI call to open SCI failed\n");
return 0;
@@ -425,9 +423,8 @@ static void sci_close(struct toshiba_acpi_dev *dev)
 {
u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
-   acpi_status status;
+   acpi_status status = tci_raw(dev, in, out);
 
-   status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to close SCI failed\n");
return;
@@ -490,8 +487,7 @@ static void toshiba_illumination_set(struct led_classdev 
*cdev,
 {
struct toshiba_acpi_dev *dev = container_of(cdev,
struct toshiba_acpi_dev, led_dev);
-   u32 result;
-   u32 state;
+   u32 result, state;
 
/* First request : initialize communication. */
if (!sci_open(dev))
@@ -509,7 +505,7 @@ 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;
+   u32 result, state;
 
/* First request : initialize communication. */
if (!sci_open(dev))
@@ -604,8 +600,7 @@ 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 result;
-   u32 state;
+   u32 result, state;
 
/* Check the keyboard backlight state */
result = hci_read(dev, HCI_KBD_ILLUMINATION, );
@@ -624,8 +619,7 @@ 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 result;
-   u32 state;
+   u32 result, state;
 
/* Set the keyboard backlight state */
state = brightness ? 1 : 0;
@@ -672,9 +666,9 @@ static int toshiba_touchpad_get(struct toshiba_acpi_dev 
*dev, u32 *state)
 /* Eco Mode support */
 static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
 {
-   acpi_status status;
u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
u32 out[TCI_WORDS];
+   acpi_status status;
 
dev->eco_supported = 0;
dev->eco_led_registered = false;
@@ -1282,9 +1276,8 @@ static struct proc_dir_entry *toshiba_proc_dir;
 /* LCD Brightness */
 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
 {
-   u32 result;
-   u32 value;
int brightness = 0;
+   u32 result, value;
 
if (dev->tr_backlight_supported) {
int ret = get_tr_backlight_status(dev, );
@@ -1317,8 +1310,7 @@ static int get_lcd_brightness(struct backlight_device *bd)
 static int lcd_proc_show(struct seq_file *m, void *v)
 {
struct toshiba_acpi_dev *dev = m->private;
-   int levels;
-   int value;
+   int levels, value;
 
if (!dev->backlight_dev)
return -ENODEV;
@@ -1375,16 +1367,16 @@ static ssize_t lcd_proc_write(struct file *file, const 
char __user *buf,
  size_t count, loff_t *pos)
 {
struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
+   int levels, value;
char cmd[42];
size_t len;
-   int levels = dev->backlight_dev->props.max_brightness + 1;
-   int value;
 
len = min(count, sizeof(cmd) - 1);
if (copy_from_user(cmd, buf, len))
return -EFAULT;
  

[PATCH] toshiba_acpi: Fix the kbd_backlight_mode_show printed value

2016-08-16 Thread Azael Avalos
The mentioned function prints the value in decimal, but the
documentation and its parent function available_kbd_modes_show
are showing the value as hexadecimal.

This patch simply changes the value printed from decimal to hex,
as stated in the documentation and the parent function.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 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 254a4d5..444f351 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1873,7 +1873,7 @@ static ssize_t kbd_backlight_mode_show(struct device *dev,
if (toshiba_kbd_illum_status_get(toshiba, ) < 0)
return -EIO;
 
-   return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
+   return sprintf(buf, "0x%x\n", time & SCI_KBD_MODE_MASK);
 }
 static DEVICE_ATTR_RW(kbd_backlight_mode);
 
-- 
2.9.2



[PATCH] toshiba_acpi: Fix the kbd_backlight_mode_show printed value

2016-08-16 Thread Azael Avalos
The mentioned function prints the value in decimal, but the
documentation and its parent function available_kbd_modes_show
are showing the value as hexadecimal.

This patch simply changes the value printed from decimal to hex,
as stated in the documentation and the parent function.

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 254a4d5..444f351 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1873,7 +1873,7 @@ static ssize_t kbd_backlight_mode_show(struct device *dev,
if (toshiba_kbd_illum_status_get(toshiba, ) < 0)
return -EIO;
 
-   return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
+   return sprintf(buf, "0x%x\n", time & SCI_KBD_MODE_MASK);
 }
 static DEVICE_ATTR_RW(kbd_backlight_mode);
 
-- 
2.9.2



Re: [PATCH] platform/x86: Add IIO dependency to ACPI_TOSHIBA

2016-06-28 Thread Azael Avalos
2016-06-28 23:16 GMT-06:00 Darren Hart <dvh...@infradead.org>:
> On Tue, Jun 28, 2016 at 01:58:55PM -0600, Azael Avalos wrote:
>> The toshiba_acpi driver added support to the accelerometer axis
>> via the IIO subsystem, but failed to add the dependency to the
>> Kconfig file, making the driver fail to compile if the IIO
>> subsystem is not selected.
>>
>> This patch adds a depedency to the IIO subsystem to the
>> ACPI_TOSHIBA entry in Kconfig to avoid such build failure.
>>
>> Signed-off-by: Azael Avalos <coproscef...@gmail.com>
>> ---
>> Darren, Jonathan:
>>  I just received a few mails from the kbuild test robot informing
>>  the build failure, as a fix for this I just added a hard dependency
>>  to IIO, but maybe Jonathan can weigh in and provide me with a better
>>  alternative (perhaps some ifdefs) as to the hard IIO dependency.
>
> Don't you just love the giant kernel builder in the sky?

I certainly do, the ever watching eye XD

>
> Rather than add this separately and leave a potential build failure in the
> kernel, I'll add this line to:
>
> toshiba_acpi: Add IIO interface for accelerometer axis data

Great :-)

>
>>
>>  drivers/platform/x86/Kconfig | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
>> index c06bb85..633fc5c 100644
>> --- a/drivers/platform/x86/Kconfig
>> +++ b/drivers/platform/x86/Kconfig
>> @@ -669,6 +669,7 @@ config ACPI_TOSHIBA
>>   depends on SERIO_I8042 || SERIO_I8042 = n
>>   depends on ACPI_VIDEO || ACPI_VIDEO = n
>>   depends on RFKILL || RFKILL = n
>> + depends on IIO
>>   select INPUT_POLLDEV
>>   select INPUT_SPARSEKMAP
>>   ---help---
>> --
>> 2.8.4
>>
>>
>
> --
> Darren Hart
> Intel Open Source Technology Center



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


Re: [PATCH] platform/x86: Add IIO dependency to ACPI_TOSHIBA

2016-06-28 Thread Azael Avalos
2016-06-28 23:16 GMT-06:00 Darren Hart :
> On Tue, Jun 28, 2016 at 01:58:55PM -0600, Azael Avalos wrote:
>> The toshiba_acpi driver added support to the accelerometer axis
>> via the IIO subsystem, but failed to add the dependency to the
>> Kconfig file, making the driver fail to compile if the IIO
>> subsystem is not selected.
>>
>> This patch adds a depedency to the IIO subsystem to the
>> ACPI_TOSHIBA entry in Kconfig to avoid such build failure.
>>
>> Signed-off-by: Azael Avalos 
>> ---
>> Darren, Jonathan:
>>  I just received a few mails from the kbuild test robot informing
>>  the build failure, as a fix for this I just added a hard dependency
>>  to IIO, but maybe Jonathan can weigh in and provide me with a better
>>  alternative (perhaps some ifdefs) as to the hard IIO dependency.
>
> Don't you just love the giant kernel builder in the sky?

I certainly do, the ever watching eye XD

>
> Rather than add this separately and leave a potential build failure in the
> kernel, I'll add this line to:
>
> toshiba_acpi: Add IIO interface for accelerometer axis data

Great :-)

>
>>
>>  drivers/platform/x86/Kconfig | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
>> index c06bb85..633fc5c 100644
>> --- a/drivers/platform/x86/Kconfig
>> +++ b/drivers/platform/x86/Kconfig
>> @@ -669,6 +669,7 @@ config ACPI_TOSHIBA
>>   depends on SERIO_I8042 || SERIO_I8042 = n
>>   depends on ACPI_VIDEO || ACPI_VIDEO = n
>>   depends on RFKILL || RFKILL = n
>> + depends on IIO
>>   select INPUT_POLLDEV
>>   select INPUT_SPARSEKMAP
>>   ---help---
>> --
>> 2.8.4
>>
>>
>
> --
> Darren Hart
> Intel Open Source Technology Center



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


[PATCH] platform/x86: Add IIO dependency to ACPI_TOSHIBA

2016-06-28 Thread Azael Avalos
The toshiba_acpi driver added support to the accelerometer axis
via the IIO subsystem, but failed to add the dependency to the
Kconfig file, making the driver fail to compile if the IIO
subsystem is not selected.

This patch adds a depedency to the IIO subsystem to the
ACPI_TOSHIBA entry in Kconfig to avoid such build failure.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
Darren, Jonathan:
 I just received a few mails from the kbuild test robot informing
 the build failure, as a fix for this I just added a hard dependency
 to IIO, but maybe Jonathan can weigh in and provide me with a better
 alternative (perhaps some ifdefs) as to the hard IIO dependency.

 drivers/platform/x86/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index c06bb85..633fc5c 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -669,6 +669,7 @@ config ACPI_TOSHIBA
depends on SERIO_I8042 || SERIO_I8042 = n
depends on ACPI_VIDEO || ACPI_VIDEO = n
depends on RFKILL || RFKILL = n
+   depends on IIO
select INPUT_POLLDEV
select INPUT_SPARSEKMAP
---help---
-- 
2.8.4



[PATCH] platform/x86: Add IIO dependency to ACPI_TOSHIBA

2016-06-28 Thread Azael Avalos
The toshiba_acpi driver added support to the accelerometer axis
via the IIO subsystem, but failed to add the dependency to the
Kconfig file, making the driver fail to compile if the IIO
subsystem is not selected.

This patch adds a depedency to the IIO subsystem to the
ACPI_TOSHIBA entry in Kconfig to avoid such build failure.

Signed-off-by: Azael Avalos 
---
Darren, Jonathan:
 I just received a few mails from the kbuild test robot informing
 the build failure, as a fix for this I just added a hard dependency
 to IIO, but maybe Jonathan can weigh in and provide me with a better
 alternative (perhaps some ifdefs) as to the hard IIO dependency.

 drivers/platform/x86/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index c06bb85..633fc5c 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -669,6 +669,7 @@ config ACPI_TOSHIBA
depends on SERIO_I8042 || SERIO_I8042 = n
depends on ACPI_VIDEO || ACPI_VIDEO = n
depends on RFKILL || RFKILL = n
+   depends on IIO
select INPUT_POLLDEV
select INPUT_SPARSEKMAP
---help---
-- 
2.8.4



[PATCH v3 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-27 Thread Azael Avalos
This patch adds the accelerometer axis data to the IIO subsystem.

Currently reporting the X, Y and Z values, as no other data can be
queried given the fact that the accelerometer chip itself is hidden
behind the Toshiba proprietary interface.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 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 01e12d2..bd9b346a 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -53,6 +53,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
 
 /* Field definitions */
 #define HCI_ACCEL_MASK 0x7fff
+#define HCI_ACCEL_DIRECTION_MASK   0x8000
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
 #define HCI_HOTKEY_SPECIAL_FUNCTIONS   0x10
@@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
struct led_classdev eco_led;
struct miscdevice miscdev;
struct rfkill *wwan_rfk;
+   struct iio_dev *indio_dev;
 
int force_fan;
int last_key_event;
@@ -2420,6 +2423,81 @@ static void toshiba_acpi_kbd_bl_work(struct work_struct 
*work)
 }
 
 /*
+ * IIO device
+ */
+
+enum toshiba_iio_accel_chan {
+   AXIS_X,
+   AXIS_Y,
+   AXIS_Z
+};
+
+static int toshiba_iio_accel_get_axis(enum toshiba_iio_accel_chan chan)
+{
+   u32 xyval, zval;
+   int ret;
+
+   ret = toshiba_accelerometer_get(toshiba_acpi, , );
+   if (ret < 0)
+   return ret;
+
+   switch (chan) {
+   case AXIS_X:
+   return xyval & HCI_ACCEL_DIRECTION_MASK ?
+   -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
+   case AXIS_Y:
+   return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
+   -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
+   (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
+   case AXIS_Z:
+   return zval & HCI_ACCEL_DIRECTION_MASK ?
+   -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
+   }
+
+   return ret;
+}
+
+static int toshiba_iio_accel_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+   int ret;
+
+   switch (mask) {
+   case IIO_CHAN_INFO_RAW:
+   ret = toshiba_iio_accel_get_axis(chan->channel);
+   if (ret == -EIO || ret == -ENODEV)
+   return ret;
+
+   *val = ret;
+
+   return IIO_VAL_INT;
+   }
+
+   return -EINVAL;
+}
+
+#define TOSHIBA_IIO_ACCEL_CHANNEL(axis, chan) { \
+   .type = IIO_ACCEL, \
+   .modified = 1, \
+   .channel = chan, \
+   .channel2 = IIO_MOD_##axis, \
+   .output = 1, \
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+}
+
+static const struct iio_chan_spec toshiba_iio_accel_channels[] = {
+   TOSHIBA_IIO_ACCEL_CHANNEL(X, AXIS_X),
+   TOSHIBA_IIO_ACCEL_CHANNEL(Y, AXIS_Y),
+   TOSHIBA_IIO_ACCEL_CHANNEL(Z, AXIS_Z),
+};
+
+static const struct iio_info toshiba_iio_accel_info = {
+   .driver_module = THIS_MODULE,
+   .read_raw = _iio_accel_read_raw,
+};
+
+/*
  * Misc device
  */
 static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
@@ -2904,6 +2982,11 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
 
remove_toshiba_proc_entries(dev);
 
+   if (dev->accelerometer_supported && dev->indio_dev) {
+   iio_device_unregister(dev->indio_dev);
+   iio_device_free(dev->indio_dev);
+   }
+
if (dev->sysfs_created)
sysfs_remove_group(>acpi_dev->dev.kobj,
   _attr_group);
@@ -3051,6 +3134,30 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->touchpad_supported = !ret;
 
toshiba_accelerometer_available(dev);
+   if (dev->accelerometer_supported) {
+   dev->indio_dev = iio_device_alloc(sizeof(*dev));
+   if (!dev->indio_dev) {
+   pr_err("Unable to allocate iio device\n");
+   goto iio_error;
+   }
+
+   pr_info("Registering Toshiba accelerometer iio device\n");
+
+   dev->indio_dev->info = _iio_accel_info;
+   dev->indio_dev->name = "Toshiba accelerometer";
+   dev->indio_dev->dev.parent = _dev->dev;
+   dev->indio_dev->modes = INDIO_DIRECT_MODE;
+   dev->indio_dev->channels = toshiba_iio_accel_channels;
+

[PATCH v3 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-27 Thread Azael Avalos
This patch adds the accelerometer axis data to the IIO subsystem.

Currently reporting the X, Y and Z values, as no other data can be
queried given the fact that the accelerometer chip itself is hidden
behind the Toshiba proprietary interface.

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 01e12d2..bd9b346a 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -53,6 +53,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
 
 /* Field definitions */
 #define HCI_ACCEL_MASK 0x7fff
+#define HCI_ACCEL_DIRECTION_MASK   0x8000
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
 #define HCI_HOTKEY_SPECIAL_FUNCTIONS   0x10
@@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
struct led_classdev eco_led;
struct miscdevice miscdev;
struct rfkill *wwan_rfk;
+   struct iio_dev *indio_dev;
 
int force_fan;
int last_key_event;
@@ -2420,6 +2423,81 @@ static void toshiba_acpi_kbd_bl_work(struct work_struct 
*work)
 }
 
 /*
+ * IIO device
+ */
+
+enum toshiba_iio_accel_chan {
+   AXIS_X,
+   AXIS_Y,
+   AXIS_Z
+};
+
+static int toshiba_iio_accel_get_axis(enum toshiba_iio_accel_chan chan)
+{
+   u32 xyval, zval;
+   int ret;
+
+   ret = toshiba_accelerometer_get(toshiba_acpi, , );
+   if (ret < 0)
+   return ret;
+
+   switch (chan) {
+   case AXIS_X:
+   return xyval & HCI_ACCEL_DIRECTION_MASK ?
+   -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
+   case AXIS_Y:
+   return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
+   -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
+   (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
+   case AXIS_Z:
+   return zval & HCI_ACCEL_DIRECTION_MASK ?
+   -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
+   }
+
+   return ret;
+}
+
+static int toshiba_iio_accel_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+   int ret;
+
+   switch (mask) {
+   case IIO_CHAN_INFO_RAW:
+   ret = toshiba_iio_accel_get_axis(chan->channel);
+   if (ret == -EIO || ret == -ENODEV)
+   return ret;
+
+   *val = ret;
+
+   return IIO_VAL_INT;
+   }
+
+   return -EINVAL;
+}
+
+#define TOSHIBA_IIO_ACCEL_CHANNEL(axis, chan) { \
+   .type = IIO_ACCEL, \
+   .modified = 1, \
+   .channel = chan, \
+   .channel2 = IIO_MOD_##axis, \
+   .output = 1, \
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+}
+
+static const struct iio_chan_spec toshiba_iio_accel_channels[] = {
+   TOSHIBA_IIO_ACCEL_CHANNEL(X, AXIS_X),
+   TOSHIBA_IIO_ACCEL_CHANNEL(Y, AXIS_Y),
+   TOSHIBA_IIO_ACCEL_CHANNEL(Z, AXIS_Z),
+};
+
+static const struct iio_info toshiba_iio_accel_info = {
+   .driver_module = THIS_MODULE,
+   .read_raw = _iio_accel_read_raw,
+};
+
+/*
  * Misc device
  */
 static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
@@ -2904,6 +2982,11 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
 
remove_toshiba_proc_entries(dev);
 
+   if (dev->accelerometer_supported && dev->indio_dev) {
+   iio_device_unregister(dev->indio_dev);
+   iio_device_free(dev->indio_dev);
+   }
+
if (dev->sysfs_created)
sysfs_remove_group(>acpi_dev->dev.kobj,
   _attr_group);
@@ -3051,6 +3134,30 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->touchpad_supported = !ret;
 
toshiba_accelerometer_available(dev);
+   if (dev->accelerometer_supported) {
+   dev->indio_dev = iio_device_alloc(sizeof(*dev));
+   if (!dev->indio_dev) {
+   pr_err("Unable to allocate iio device\n");
+   goto iio_error;
+   }
+
+   pr_info("Registering Toshiba accelerometer iio device\n");
+
+   dev->indio_dev->info = _iio_accel_info;
+   dev->indio_dev->name = "Toshiba accelerometer";
+   dev->indio_dev->dev.parent = _dev->dev;
+   dev->indio_dev->modes = INDIO_DIRECT_MODE;
+   dev->indio_dev->channels = toshiba_iio_accel_channels;
+   dev->indio_dev->num

[PATCH v3 2/3] toshiba_acpi: Remove the position sysfs entry

2016-06-27 Thread Azael Avalos
Now that we have proper support for the acceleromeer under the IIO
subsystem, the _position_ sysfs file is now deprecated.

This patch removes all code related to the position sysfs entry.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index bd9b346a..ea0262e 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1961,28 +1961,6 @@ static ssize_t touchpad_show(struct device *dev,
 }
 static DEVICE_ATTR_RW(touchpad);
 
-static ssize_t 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, , );
-   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_RO(position);
-
 static ssize_t usb_sleep_charge_show(struct device *dev,
 struct device_attribute *attr, char *buf)
 {
@@ -2353,7 +2331,6 @@ static struct attribute *toshiba_attributes[] = {
_attr_available_kbd_modes.attr,
_attr_kbd_backlight_timeout.attr,
_attr_touchpad.attr,
-   _attr_position.attr,
_attr_usb_sleep_charge.attr,
_attr_sleep_functions_on_battery.attr,
_attr_usb_rapid_charge.attr,
@@ -2380,8 +2357,6 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
else if (attr == _attr_touchpad.attr)
exists = (drv->touchpad_supported) ? true : false;
-   else if (attr == _attr_position.attr)
-   exists = (drv->accelerometer_supported) ? true : false;
else if (attr == _attr_usb_sleep_charge.attr)
exists = (drv->usb_sleep_charge_supported) ? true : false;
else if (attr == _attr_sleep_functions_on_battery.attr)
-- 
2.8.4



[PATCH v3 2/3] toshiba_acpi: Remove the position sysfs entry

2016-06-27 Thread Azael Avalos
Now that we have proper support for the acceleromeer under the IIO
subsystem, the _position_ sysfs file is now deprecated.

This patch removes all code related to the position sysfs entry.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index bd9b346a..ea0262e 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1961,28 +1961,6 @@ static ssize_t touchpad_show(struct device *dev,
 }
 static DEVICE_ATTR_RW(touchpad);
 
-static ssize_t 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, , );
-   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_RO(position);
-
 static ssize_t usb_sleep_charge_show(struct device *dev,
 struct device_attribute *attr, char *buf)
 {
@@ -2353,7 +2331,6 @@ static struct attribute *toshiba_attributes[] = {
_attr_available_kbd_modes.attr,
_attr_kbd_backlight_timeout.attr,
_attr_touchpad.attr,
-   _attr_position.attr,
_attr_usb_sleep_charge.attr,
_attr_sleep_functions_on_battery.attr,
_attr_usb_rapid_charge.attr,
@@ -2380,8 +2357,6 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
else if (attr == _attr_touchpad.attr)
exists = (drv->touchpad_supported) ? true : false;
-   else if (attr == _attr_position.attr)
-   exists = (drv->accelerometer_supported) ? true : false;
else if (attr == _attr_usb_sleep_charge.attr)
exists = (drv->usb_sleep_charge_supported) ? true : false;
else if (attr == _attr_sleep_functions_on_battery.attr)
-- 
2.8.4



[PATCH v3 3/3] toshiba_acpi: Bump driver version and update copyright year

2016-06-27 Thread Azael Avalos
After several fixes, and added support for more features (WWAN,
Cooling Method and IIO accelometer axis data), bump the driver
version to 0.24.

Also update the copyright year.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 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 ea0262e..9d60a40 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -4,7 +4,7 @@
  *  Copyright (C) 2002-2004 John Belmonte
  *  Copyright (C) 2008 Philip Langdale
  *  Copyright (C) 2010 Pierre Ducroquet
- *  Copyright (C) 2014-2015 Azael Avalos
+ *  Copyright (C) 2014-2016 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
@@ -31,7 +31,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#define TOSHIBA_ACPI_VERSION   "0.23"
+#define TOSHIBA_ACPI_VERSION   "0.24"
 #define PROC_INTERFACE_VERSION 1
 
 #include 
-- 
2.8.4



[PATCH v3 3/3] toshiba_acpi: Bump driver version and update copyright year

2016-06-27 Thread Azael Avalos
After several fixes, and added support for more features (WWAN,
Cooling Method and IIO accelometer axis data), bump the driver
version to 0.24.

Also update the copyright year.

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 ea0262e..9d60a40 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -4,7 +4,7 @@
  *  Copyright (C) 2002-2004 John Belmonte
  *  Copyright (C) 2008 Philip Langdale
  *  Copyright (C) 2010 Pierre Ducroquet
- *  Copyright (C) 2014-2015 Azael Avalos
+ *  Copyright (C) 2014-2016 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
@@ -31,7 +31,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#define TOSHIBA_ACPI_VERSION   "0.23"
+#define TOSHIBA_ACPI_VERSION   "0.24"
 #define PROC_INTERFACE_VERSION 1
 
 #include 
-- 
2.8.4



[PATCH v3 0/3] toshiba_acpi: Accelerometer updates

2016-06-27 Thread Azael Avalos
These series of patches update the accelerometer axis data
reporting to use the IIO subsystem, deprecating the custom
position sysfs entry, and finally bumping the driver version
to 0.24.

Changes since v2:
- Small format and style changes once again
- Renamed toshiba_accel* functions to toshiba_iio_accel* to
  differentiate from the iio functions and the toshiba_acpi
  driver fuctions
- Print error messages instead of bailing out in case the
  iio_device* functions fail, this is to allow the driver
  to continue loading its many functions

Changes since v1:
- Small format and style changes
- Changed the iio code according to feedback from Jonathan Cameron

Azael Avalos (3):
  toshiba_acpi: Add IIO interface for accelerometer axis data
  toshiba_acpi: Remove the position sysfs entry
  toshiba_acpi: Bump driver version and update copyright year

 drivers/platform/x86/toshiba_acpi.c | 136 +---
 1 file changed, 109 insertions(+), 27 deletions(-)

-- 
2.8.4



[PATCH v3 0/3] toshiba_acpi: Accelerometer updates

2016-06-27 Thread Azael Avalos
These series of patches update the accelerometer axis data
reporting to use the IIO subsystem, deprecating the custom
position sysfs entry, and finally bumping the driver version
to 0.24.

Changes since v2:
- Small format and style changes once again
- Renamed toshiba_accel* functions to toshiba_iio_accel* to
  differentiate from the iio functions and the toshiba_acpi
  driver fuctions
- Print error messages instead of bailing out in case the
  iio_device* functions fail, this is to allow the driver
  to continue loading its many functions

Changes since v1:
- Small format and style changes
- Changed the iio code according to feedback from Jonathan Cameron

Azael Avalos (3):
  toshiba_acpi: Add IIO interface for accelerometer axis data
  toshiba_acpi: Remove the position sysfs entry
  toshiba_acpi: Bump driver version and update copyright year

 drivers/platform/x86/toshiba_acpi.c | 136 +---
 1 file changed, 109 insertions(+), 27 deletions(-)

-- 
2.8.4



Re: [PATCH v2 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-27 Thread Azael Avalos
Hi Darren,

2016-06-27 18:19 GMT-06:00 Darren Hart <dvh...@infradead.org>:
> On Sun, Jun 19, 2016 at 05:28:04PM -0600, Azael Avalos wrote:
>> This patch adds the accelerometer axis data to the IIO subsystem.
>>
>> Currently reporting the X, Y and Z values, as no other data can be
>> queried given the fact that the accelerometer chip itself is hidden
>> behind the Toshiba proprietary interface.
>>
>> Signed-off-by: Azael Avalos <coproscef...@gmail.com>
>> ---
>>  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 01e12d2..7949929 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -53,6 +53,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>
>> @@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
>>
>>  /* Field definitions */
>>  #define HCI_ACCEL_MASK   0x7fff
>> +#define HCI_ACCEL_DIRECTION_MASK 0x8000
>>  #define HCI_HOTKEY_DISABLE   0x0b
>>  #define HCI_HOTKEY_ENABLE0x09
>>  #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
>> @@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
>>   struct led_classdev eco_led;
>>   struct miscdevice miscdev;
>>   struct rfkill *wwan_rfk;
>> + struct iio_dev *indio_dev;
>>
>>   int force_fan;
>>   int last_key_event;
>> @@ -2420,6 +2423,83 @@ static void toshiba_acpi_kbd_bl_work(struct 
>> work_struct *work)
>>  }
>>
>>  /*
>> + * IIO device
>> + */
>> +
>> +enum toshiba_accel_chan {
>> + AXIS_X,
>> + AXIS_Y,
>> + AXIS_Z
>> +};
>> +
>> +static int toshiba_accel_get_axis(enum toshiba_accel_chan chan)
>> +{
>> + u32 xyval;
>> + u32 zval;
>
> u32 xyval, zval; please (not a big deal). We have plenty of both, and I've
> changed my policy on this sometime last year to be more consistent with the 
> rest
> of the kernel, Especially where values are related and of the same type, they
> should be declared on the same line.

Ok, I can send another patch later to conform to this for the rest of
the driver.

>
>> + int ret;
>> +
>> + xyval = zval = 0;
>
> This assignment is unnecessary. The toshiba_accelerometer_get function either
> populates both values without reading them or it returns an error. If the
> latter, we exit immediately without reading the values.

Will do.

>
>> + ret = toshiba_accelerometer_get(toshiba_acpi, , );
>> + if (ret < 0)
>> + return ret;
>> +
>> + switch (chan) {
>> + case AXIS_X:
>> + return xyval & HCI_ACCEL_DIRECTION_MASK ?
>> + -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
>> + case AXIS_Y:
>> + return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
>> + -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
>> + (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
>> + case AXIS_Z:
>> + return zval & HCI_ACCEL_DIRECTION_MASK ?
>> + -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
>> + }
>> +
>> + return ret;
>> +}
>> +
>> +static int toshiba_accel_read_raw(struct iio_dev *indio_dev,
>
> The toshiba_accel* namespace is starting to get crowded. It would useful to 
> have
> a comment or section that was clearly the IIO interface versus the ACPI 
> platform
> interface.

Ok, I can change the name to something like "toshiba_iio_accel*" to
differentiate.

>
>> +   struct iio_chan_spec const *chan,
>> +   int *val, int *val2, long mask)
>> +{
>> + int ret;
>> +
>> + switch (mask) {
>> + case IIO_CHAN_INFO_RAW:
>> + ret = toshiba_accel_get_axis(chan->channel);
>> + if (ret == -EIO || ret == -ENODEV)
>> + return ret;
>> +
>> + *val = ret;
>> +
>> + return IIO_VAL_INT;
>> + }
>> +
>> + return -EINVAL;
>> +}
>> +
>> +#define TOSHIBA_ACCEL_CHANNEL(axis, chan) { \
>> + .type = IIO_ACCEL, \
>> + .modified = 1, \
>> + .channel = chan, \
>> +

Re: [PATCH v2 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-27 Thread Azael Avalos
Hi Darren,

2016-06-27 18:19 GMT-06:00 Darren Hart :
> On Sun, Jun 19, 2016 at 05:28:04PM -0600, Azael Avalos wrote:
>> This patch adds the accelerometer axis data to the IIO subsystem.
>>
>> Currently reporting the X, Y and Z values, as no other data can be
>> queried given the fact that the accelerometer chip itself is hidden
>> behind the Toshiba proprietary interface.
>>
>> 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 01e12d2..7949929 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -53,6 +53,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>
>> @@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
>>
>>  /* Field definitions */
>>  #define HCI_ACCEL_MASK   0x7fff
>> +#define HCI_ACCEL_DIRECTION_MASK 0x8000
>>  #define HCI_HOTKEY_DISABLE   0x0b
>>  #define HCI_HOTKEY_ENABLE0x09
>>  #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
>> @@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
>>   struct led_classdev eco_led;
>>   struct miscdevice miscdev;
>>   struct rfkill *wwan_rfk;
>> + struct iio_dev *indio_dev;
>>
>>   int force_fan;
>>   int last_key_event;
>> @@ -2420,6 +2423,83 @@ static void toshiba_acpi_kbd_bl_work(struct 
>> work_struct *work)
>>  }
>>
>>  /*
>> + * IIO device
>> + */
>> +
>> +enum toshiba_accel_chan {
>> + AXIS_X,
>> + AXIS_Y,
>> + AXIS_Z
>> +};
>> +
>> +static int toshiba_accel_get_axis(enum toshiba_accel_chan chan)
>> +{
>> + u32 xyval;
>> + u32 zval;
>
> u32 xyval, zval; please (not a big deal). We have plenty of both, and I've
> changed my policy on this sometime last year to be more consistent with the 
> rest
> of the kernel, Especially where values are related and of the same type, they
> should be declared on the same line.

Ok, I can send another patch later to conform to this for the rest of
the driver.

>
>> + int ret;
>> +
>> + xyval = zval = 0;
>
> This assignment is unnecessary. The toshiba_accelerometer_get function either
> populates both values without reading them or it returns an error. If the
> latter, we exit immediately without reading the values.

Will do.

>
>> + ret = toshiba_accelerometer_get(toshiba_acpi, , );
>> + if (ret < 0)
>> + return ret;
>> +
>> + switch (chan) {
>> + case AXIS_X:
>> + return xyval & HCI_ACCEL_DIRECTION_MASK ?
>> + -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
>> + case AXIS_Y:
>> + return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
>> + -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
>> + (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
>> + case AXIS_Z:
>> + return zval & HCI_ACCEL_DIRECTION_MASK ?
>> + -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
>> + }
>> +
>> + return ret;
>> +}
>> +
>> +static int toshiba_accel_read_raw(struct iio_dev *indio_dev,
>
> The toshiba_accel* namespace is starting to get crowded. It would useful to 
> have
> a comment or section that was clearly the IIO interface versus the ACPI 
> platform
> interface.

Ok, I can change the name to something like "toshiba_iio_accel*" to
differentiate.

>
>> +   struct iio_chan_spec const *chan,
>> +   int *val, int *val2, long mask)
>> +{
>> + int ret;
>> +
>> + switch (mask) {
>> + case IIO_CHAN_INFO_RAW:
>> + ret = toshiba_accel_get_axis(chan->channel);
>> + if (ret == -EIO || ret == -ENODEV)
>> + return ret;
>> +
>> + *val = ret;
>> +
>> + return IIO_VAL_INT;
>> + }
>> +
>> + return -EINVAL;
>> +}
>> +
>> +#define TOSHIBA_ACCEL_CHANNEL(axis, chan) { \
>> + .type = IIO_ACCEL, \
>> + .modified = 1, \
>> + .channel = chan, \
>> + .channel2 = IIO_MOD_##axis, \
>> + .outp

Re: [PATCH 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-19 Thread Azael Avalos
Hi,

Thanks for the feedback, I just did a respin of the series with the
changes you mentioned.


Cheers
Azael

2016-06-19 14:16 GMT-06:00 Jonathan Cameron <ji...@kernel.org>:
> On 11/06/16 19:57, Azael Avalos wrote:
>> This patch adds the accelerometer axis data to the IIO subsystem.
>>
>> Currently reporting the X, Y and Z values, as no other data can be
>> queried given the fact that the accelerometer chip itself is hidden
>> behind the Toshiba proprietary interface.
>>
>> Signed-off-by: Azael Avalos <coproscef...@gmail.com>
> Looks pretty good and simple to me.  A few bits and bobs inline.
>
> Jonathan
>> ---
>> All:
>>  This is my first attempt with the IIO subsysem, I'll be looking
>>  forward for your valuable input on this.
>>
>> Darren:
>>  There's a warning about more than 80 columns on this patch, once
>>  I get feedback from the IIO guys I'll respin this with that issue
>>  corrected.
>>
>>  drivers/platform/x86/toshiba_acpi.c | 130 
>> ++--
>>  1 file changed, 126 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index 01e12d2..85014a3 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -53,6 +53,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>
>> @@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
>>
>>  /* Field definitions */
>>  #define HCI_ACCEL_MASK   0x7fff
>> +#define HCI_ACCEL_DIRECTION_MASK 0x8000
>>  #define HCI_HOTKEY_DISABLE   0x0b
>>  #define HCI_HOTKEY_ENABLE0x09
>>  #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
>> @@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
>>   struct led_classdev eco_led;
>>   struct miscdevice miscdev;
>>   struct rfkill *wwan_rfk;
>> + struct iio_dev *indio_dev;
>>
>>   int force_fan;
>>   int last_key_event;
>> @@ -1962,8 +1965,8 @@ static ssize_t 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;
>>
>>   xyval = zval = 0;
>> @@ -1971,10 +1974,14 @@ static ssize_t position_show(struct device *dev,
>>   if (ret < 0)
>>   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;
> This lot is really an unrelated change - do it as a separate precursor patch
> to the IIO support.
>>
>>   return sprintf(buf, "%d %d %d\n", x, y, z);
>>  }
>> @@ -2420,6 +2427,94 @@ static void toshiba_acpi_kbd_bl_work(struct 
>> work_struct *work)
>>  }
>>
>>  /*
>> + * IIO device
>> + */
>> +
>> +enum toshiba_accel_chan {
>> + AXIS_X,
>> + AXIS_Y,
>> + AXIS_Z
>> +};
>> +
>> +static int toshiba_accel_get_axis(enum toshiba_accel_chan chan)
>> +{
>> + u32 xyval, zval;
>> + int x, y, z;
>> + int ret;
>> +
>> + xyval = zval = 0;
>> + ret = toshiba_accelerometer_get(toshiba_acpi, , );
>> + if (ret < 0)
>> + return ret;
>> +
>> + /* Accelerometer values */
>> + x = xyval & 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;
> Wow, that's hideous ;)
>> +
>> + switch (chan) {
>> + case AXIS_X:
>> + ret = x;
>> + break;
>> + case AXIS

Re: [PATCH 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-19 Thread Azael Avalos
Hi,

Thanks for the feedback, I just did a respin of the series with the
changes you mentioned.


Cheers
Azael

2016-06-19 14:16 GMT-06:00 Jonathan Cameron :
> On 11/06/16 19:57, Azael Avalos wrote:
>> This patch adds the accelerometer axis data to the IIO subsystem.
>>
>> Currently reporting the X, Y and Z values, as no other data can be
>> queried given the fact that the accelerometer chip itself is hidden
>> behind the Toshiba proprietary interface.
>>
>> Signed-off-by: Azael Avalos 
> Looks pretty good and simple to me.  A few bits and bobs inline.
>
> Jonathan
>> ---
>> All:
>>  This is my first attempt with the IIO subsysem, I'll be looking
>>  forward for your valuable input on this.
>>
>> Darren:
>>  There's a warning about more than 80 columns on this patch, once
>>  I get feedback from the IIO guys I'll respin this with that issue
>>  corrected.
>>
>>  drivers/platform/x86/toshiba_acpi.c | 130 
>> ++--
>>  1 file changed, 126 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index 01e12d2..85014a3 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -53,6 +53,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>
>> @@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
>>
>>  /* Field definitions */
>>  #define HCI_ACCEL_MASK   0x7fff
>> +#define HCI_ACCEL_DIRECTION_MASK 0x8000
>>  #define HCI_HOTKEY_DISABLE   0x0b
>>  #define HCI_HOTKEY_ENABLE0x09
>>  #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
>> @@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
>>   struct led_classdev eco_led;
>>   struct miscdevice miscdev;
>>   struct rfkill *wwan_rfk;
>> + struct iio_dev *indio_dev;
>>
>>   int force_fan;
>>   int last_key_event;
>> @@ -1962,8 +1965,8 @@ static ssize_t 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;
>>
>>   xyval = zval = 0;
>> @@ -1971,10 +1974,14 @@ static ssize_t position_show(struct device *dev,
>>   if (ret < 0)
>>   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;
> This lot is really an unrelated change - do it as a separate precursor patch
> to the IIO support.
>>
>>   return sprintf(buf, "%d %d %d\n", x, y, z);
>>  }
>> @@ -2420,6 +2427,94 @@ static void toshiba_acpi_kbd_bl_work(struct 
>> work_struct *work)
>>  }
>>
>>  /*
>> + * IIO device
>> + */
>> +
>> +enum toshiba_accel_chan {
>> + AXIS_X,
>> + AXIS_Y,
>> + AXIS_Z
>> +};
>> +
>> +static int toshiba_accel_get_axis(enum toshiba_accel_chan chan)
>> +{
>> + u32 xyval, zval;
>> + int x, y, z;
>> + int ret;
>> +
>> + xyval = zval = 0;
>> + ret = toshiba_accelerometer_get(toshiba_acpi, , );
>> + if (ret < 0)
>> + return ret;
>> +
>> + /* Accelerometer values */
>> + x = xyval & 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;
> Wow, that's hideous ;)
>> +
>> + switch (chan) {
>> + case AXIS_X:
>> + ret = x;
>> + break;
>> + case AXIS_Y:
>> + ret = y;
>> + break;
>> +  

[PATCH v2 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-19 Thread Azael Avalos
This patch adds the accelerometer axis data to the IIO subsystem.

Currently reporting the X, Y and Z values, as no other data can be
queried given the fact that the accelerometer chip itself is hidden
behind the Toshiba proprietary interface.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 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 01e12d2..7949929 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -53,6 +53,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
 
 /* Field definitions */
 #define HCI_ACCEL_MASK 0x7fff
+#define HCI_ACCEL_DIRECTION_MASK   0x8000
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
 #define HCI_HOTKEY_SPECIAL_FUNCTIONS   0x10
@@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
struct led_classdev eco_led;
struct miscdevice miscdev;
struct rfkill *wwan_rfk;
+   struct iio_dev *indio_dev;
 
int force_fan;
int last_key_event;
@@ -2420,6 +2423,83 @@ static void toshiba_acpi_kbd_bl_work(struct work_struct 
*work)
 }
 
 /*
+ * IIO device
+ */
+
+enum toshiba_accel_chan {
+   AXIS_X,
+   AXIS_Y,
+   AXIS_Z
+};
+
+static int toshiba_accel_get_axis(enum toshiba_accel_chan chan)
+{
+   u32 xyval;
+   u32 zval;
+   int ret;
+
+   xyval = zval = 0;
+   ret = toshiba_accelerometer_get(toshiba_acpi, , );
+   if (ret < 0)
+   return ret;
+
+   switch (chan) {
+   case AXIS_X:
+   return xyval & HCI_ACCEL_DIRECTION_MASK ?
+   -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
+   case AXIS_Y:
+   return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
+   -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
+   (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
+   case AXIS_Z:
+   return zval & HCI_ACCEL_DIRECTION_MASK ?
+   -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
+   }
+
+   return ret;
+}
+
+static int toshiba_accel_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+   int ret;
+
+   switch (mask) {
+   case IIO_CHAN_INFO_RAW:
+   ret = toshiba_accel_get_axis(chan->channel);
+   if (ret == -EIO || ret == -ENODEV)
+   return ret;
+
+   *val = ret;
+
+   return IIO_VAL_INT;
+   }
+
+   return -EINVAL;
+}
+
+#define TOSHIBA_ACCEL_CHANNEL(axis, chan) { \
+   .type = IIO_ACCEL, \
+   .modified = 1, \
+   .channel = chan, \
+   .channel2 = IIO_MOD_##axis, \
+   .output = 1, \
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+}
+
+static const struct iio_chan_spec toshiba_accel_channels[] = {
+   TOSHIBA_ACCEL_CHANNEL(X, AXIS_X),
+   TOSHIBA_ACCEL_CHANNEL(Y, AXIS_Y),
+   TOSHIBA_ACCEL_CHANNEL(Z, AXIS_Z),
+};
+
+static const struct iio_info toshiba_accel_info = {
+   .driver_module = THIS_MODULE,
+   .read_raw = _accel_read_raw,
+};
+
+/*
  * Misc device
  */
 static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
@@ -2904,6 +2984,11 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
 
remove_toshiba_proc_entries(dev);
 
+   if (dev->accelerometer_supported) {
+   iio_device_unregister(dev->indio_dev);
+   iio_device_free(dev->indio_dev);
+   }
+
if (dev->sysfs_created)
sysfs_remove_group(>acpi_dev->dev.kobj,
   _attr_group);
@@ -3051,6 +3136,28 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->touchpad_supported = !ret;
 
toshiba_accelerometer_available(dev);
+   if (dev->accelerometer_supported) {
+   dev->indio_dev = iio_device_alloc(sizeof(*dev));
+   if (!dev->indio_dev)
+   return -ENOMEM;
+
+   pr_info("Registering Toshiba accelerometer iio device\n");
+
+   dev->indio_dev->info = _accel_info;
+   dev->indio_dev->name = "Toshiba accelerometer";
+   dev->indio_dev->dev.parent = _dev->dev;
+   dev->indio_dev->modes = INDIO_DIRECT_MODE;
+   dev->indio_dev->channels = toshiba_accel_channels;
+   dev->indio_dev->num_channels =
+   ARRAY_SIZE(toshiba_accel_channels);
+
+   ret = iio_device_register(dev-

[PATCH v2 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-19 Thread Azael Avalos
This patch adds the accelerometer axis data to the IIO subsystem.

Currently reporting the X, Y and Z values, as no other data can be
queried given the fact that the accelerometer chip itself is hidden
behind the Toshiba proprietary interface.

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 01e12d2..7949929 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -53,6 +53,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
 
 /* Field definitions */
 #define HCI_ACCEL_MASK 0x7fff
+#define HCI_ACCEL_DIRECTION_MASK   0x8000
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
 #define HCI_HOTKEY_SPECIAL_FUNCTIONS   0x10
@@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
struct led_classdev eco_led;
struct miscdevice miscdev;
struct rfkill *wwan_rfk;
+   struct iio_dev *indio_dev;
 
int force_fan;
int last_key_event;
@@ -2420,6 +2423,83 @@ static void toshiba_acpi_kbd_bl_work(struct work_struct 
*work)
 }
 
 /*
+ * IIO device
+ */
+
+enum toshiba_accel_chan {
+   AXIS_X,
+   AXIS_Y,
+   AXIS_Z
+};
+
+static int toshiba_accel_get_axis(enum toshiba_accel_chan chan)
+{
+   u32 xyval;
+   u32 zval;
+   int ret;
+
+   xyval = zval = 0;
+   ret = toshiba_accelerometer_get(toshiba_acpi, , );
+   if (ret < 0)
+   return ret;
+
+   switch (chan) {
+   case AXIS_X:
+   return xyval & HCI_ACCEL_DIRECTION_MASK ?
+   -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
+   case AXIS_Y:
+   return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
+   -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
+   (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
+   case AXIS_Z:
+   return zval & HCI_ACCEL_DIRECTION_MASK ?
+   -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
+   }
+
+   return ret;
+}
+
+static int toshiba_accel_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+   int ret;
+
+   switch (mask) {
+   case IIO_CHAN_INFO_RAW:
+   ret = toshiba_accel_get_axis(chan->channel);
+   if (ret == -EIO || ret == -ENODEV)
+   return ret;
+
+   *val = ret;
+
+   return IIO_VAL_INT;
+   }
+
+   return -EINVAL;
+}
+
+#define TOSHIBA_ACCEL_CHANNEL(axis, chan) { \
+   .type = IIO_ACCEL, \
+   .modified = 1, \
+   .channel = chan, \
+   .channel2 = IIO_MOD_##axis, \
+   .output = 1, \
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+}
+
+static const struct iio_chan_spec toshiba_accel_channels[] = {
+   TOSHIBA_ACCEL_CHANNEL(X, AXIS_X),
+   TOSHIBA_ACCEL_CHANNEL(Y, AXIS_Y),
+   TOSHIBA_ACCEL_CHANNEL(Z, AXIS_Z),
+};
+
+static const struct iio_info toshiba_accel_info = {
+   .driver_module = THIS_MODULE,
+   .read_raw = _accel_read_raw,
+};
+
+/*
  * Misc device
  */
 static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
@@ -2904,6 +2984,11 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
 
remove_toshiba_proc_entries(dev);
 
+   if (dev->accelerometer_supported) {
+   iio_device_unregister(dev->indio_dev);
+   iio_device_free(dev->indio_dev);
+   }
+
if (dev->sysfs_created)
sysfs_remove_group(>acpi_dev->dev.kobj,
   _attr_group);
@@ -3051,6 +3136,28 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->touchpad_supported = !ret;
 
toshiba_accelerometer_available(dev);
+   if (dev->accelerometer_supported) {
+   dev->indio_dev = iio_device_alloc(sizeof(*dev));
+   if (!dev->indio_dev)
+   return -ENOMEM;
+
+   pr_info("Registering Toshiba accelerometer iio device\n");
+
+   dev->indio_dev->info = _accel_info;
+   dev->indio_dev->name = "Toshiba accelerometer";
+   dev->indio_dev->dev.parent = _dev->dev;
+   dev->indio_dev->modes = INDIO_DIRECT_MODE;
+   dev->indio_dev->channels = toshiba_accel_channels;
+   dev->indio_dev->num_channels =
+   ARRAY_SIZE(toshiba_accel_channels);
+
+   ret = iio_device_register(dev->in

[PATCH v2 2/3] toshiba_acpi: Remove the position sysfs entry

2016-06-19 Thread Azael Avalos
Now that we have proper support for the acceleromeer under the IIO
subsystem, the _position_ sysfs file is now deprecated.

This patch removes all code related to the position sysfs entry.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 7949929..a9760d2 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1961,28 +1961,6 @@ static ssize_t touchpad_show(struct device *dev,
 }
 static DEVICE_ATTR_RW(touchpad);
 
-static ssize_t 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, , );
-   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_RO(position);
-
 static ssize_t usb_sleep_charge_show(struct device *dev,
 struct device_attribute *attr, char *buf)
 {
@@ -2353,7 +2331,6 @@ static struct attribute *toshiba_attributes[] = {
_attr_available_kbd_modes.attr,
_attr_kbd_backlight_timeout.attr,
_attr_touchpad.attr,
-   _attr_position.attr,
_attr_usb_sleep_charge.attr,
_attr_sleep_functions_on_battery.attr,
_attr_usb_rapid_charge.attr,
@@ -2380,8 +2357,6 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
else if (attr == _attr_touchpad.attr)
exists = (drv->touchpad_supported) ? true : false;
-   else if (attr == _attr_position.attr)
-   exists = (drv->accelerometer_supported) ? true : false;
else if (attr == _attr_usb_sleep_charge.attr)
exists = (drv->usb_sleep_charge_supported) ? true : false;
else if (attr == _attr_sleep_functions_on_battery.attr)
-- 
2.8.4



[PATCH v2 0/3] toshiba_acpi: Accelerometer updates

2016-06-19 Thread Azael Avalos
These series of patches update the accelerometer axis data
reporting to use the IIO subsystem, deprecating the custom
position sysfs entry, and finally bumping the driver version
to 0.24.

Changes since v1:
- Small format and style changes
- Changed the iio code according to feedback from Jonathan Cameron

Azael Avalos (3):
  toshiba_acpi: Add IIO interface for accelerometer axis data
  toshiba_acpi: Remove the position sysfs entry
  toshiba_acpi: Bump driver version and update copyright year

 drivers/platform/x86/toshiba_acpi.c | 136 +---
 1 file changed, 109 insertions(+), 27 deletions(-)

-- 
2.8.4



[PATCH v2 3/3] toshiba_acpi: Bump driver version and update copyright year

2016-06-19 Thread Azael Avalos
After several fixes, and added support for more features (WWAN,
Cooling Method and IIO accelometer axis data), bump the driver
version to 0.24.

Also update the copyright year.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 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 a9760d2..9c8f349 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -4,7 +4,7 @@
  *  Copyright (C) 2002-2004 John Belmonte
  *  Copyright (C) 2008 Philip Langdale
  *  Copyright (C) 2010 Pierre Ducroquet
- *  Copyright (C) 2014-2015 Azael Avalos
+ *  Copyright (C) 2014-2016 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
@@ -31,7 +31,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#define TOSHIBA_ACPI_VERSION   "0.23"
+#define TOSHIBA_ACPI_VERSION   "0.24"
 #define PROC_INTERFACE_VERSION 1
 
 #include 
-- 
2.8.4



[PATCH v2 2/3] toshiba_acpi: Remove the position sysfs entry

2016-06-19 Thread Azael Avalos
Now that we have proper support for the acceleromeer under the IIO
subsystem, the _position_ sysfs file is now deprecated.

This patch removes all code related to the position sysfs entry.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 7949929..a9760d2 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1961,28 +1961,6 @@ static ssize_t touchpad_show(struct device *dev,
 }
 static DEVICE_ATTR_RW(touchpad);
 
-static ssize_t 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, , );
-   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_RO(position);
-
 static ssize_t usb_sleep_charge_show(struct device *dev,
 struct device_attribute *attr, char *buf)
 {
@@ -2353,7 +2331,6 @@ static struct attribute *toshiba_attributes[] = {
_attr_available_kbd_modes.attr,
_attr_kbd_backlight_timeout.attr,
_attr_touchpad.attr,
-   _attr_position.attr,
_attr_usb_sleep_charge.attr,
_attr_sleep_functions_on_battery.attr,
_attr_usb_rapid_charge.attr,
@@ -2380,8 +2357,6 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
else if (attr == _attr_touchpad.attr)
exists = (drv->touchpad_supported) ? true : false;
-   else if (attr == _attr_position.attr)
-   exists = (drv->accelerometer_supported) ? true : false;
else if (attr == _attr_usb_sleep_charge.attr)
exists = (drv->usb_sleep_charge_supported) ? true : false;
else if (attr == _attr_sleep_functions_on_battery.attr)
-- 
2.8.4



[PATCH v2 0/3] toshiba_acpi: Accelerometer updates

2016-06-19 Thread Azael Avalos
These series of patches update the accelerometer axis data
reporting to use the IIO subsystem, deprecating the custom
position sysfs entry, and finally bumping the driver version
to 0.24.

Changes since v1:
- Small format and style changes
- Changed the iio code according to feedback from Jonathan Cameron

Azael Avalos (3):
  toshiba_acpi: Add IIO interface for accelerometer axis data
  toshiba_acpi: Remove the position sysfs entry
  toshiba_acpi: Bump driver version and update copyright year

 drivers/platform/x86/toshiba_acpi.c | 136 +---
 1 file changed, 109 insertions(+), 27 deletions(-)

-- 
2.8.4



[PATCH v2 3/3] toshiba_acpi: Bump driver version and update copyright year

2016-06-19 Thread Azael Avalos
After several fixes, and added support for more features (WWAN,
Cooling Method and IIO accelometer axis data), bump the driver
version to 0.24.

Also update the copyright year.

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 a9760d2..9c8f349 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -4,7 +4,7 @@
  *  Copyright (C) 2002-2004 John Belmonte
  *  Copyright (C) 2008 Philip Langdale
  *  Copyright (C) 2010 Pierre Ducroquet
- *  Copyright (C) 2014-2015 Azael Avalos
+ *  Copyright (C) 2014-2016 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
@@ -31,7 +31,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#define TOSHIBA_ACPI_VERSION   "0.23"
+#define TOSHIBA_ACPI_VERSION   "0.24"
 #define PROC_INTERFACE_VERSION 1
 
 #include 
-- 
2.8.4



[PATCH 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-11 Thread Azael Avalos
This patch adds the accelerometer axis data to the IIO subsystem.

Currently reporting the X, Y and Z values, as no other data can be
queried given the fact that the accelerometer chip itself is hidden
behind the Toshiba proprietary interface.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
All:
 This is my first attempt with the IIO subsysem, I'll be looking
 forward for your valuable input on this.

Darren:
 There's a warning about more than 80 columns on this patch, once
 I get feedback from the IIO guys I'll respin this with that issue
 corrected.

 drivers/platform/x86/toshiba_acpi.c | 130 ++--
 1 file changed, 126 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 01e12d2..85014a3 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -53,6 +53,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
 
 /* Field definitions */
 #define HCI_ACCEL_MASK 0x7fff
+#define HCI_ACCEL_DIRECTION_MASK   0x8000
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
 #define HCI_HOTKEY_SPECIAL_FUNCTIONS   0x10
@@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
struct led_classdev eco_led;
struct miscdevice miscdev;
struct rfkill *wwan_rfk;
+   struct iio_dev *indio_dev;
 
int force_fan;
int last_key_event;
@@ -1962,8 +1965,8 @@ static ssize_t 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;
 
xyval = zval = 0;
@@ -1971,10 +1974,14 @@ static ssize_t position_show(struct device *dev,
if (ret < 0)
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;
 
return sprintf(buf, "%d %d %d\n", x, y, z);
 }
@@ -2420,6 +2427,94 @@ static void toshiba_acpi_kbd_bl_work(struct work_struct 
*work)
 }
 
 /*
+ * IIO device
+ */
+
+enum toshiba_accel_chan {
+   AXIS_X,
+   AXIS_Y,
+   AXIS_Z
+};
+
+static int toshiba_accel_get_axis(enum toshiba_accel_chan chan)
+{
+   u32 xyval, zval;
+   int x, y, z;
+   int ret;
+
+   xyval = zval = 0;
+   ret = toshiba_accelerometer_get(toshiba_acpi, , );
+   if (ret < 0)
+   return ret;
+
+   /* Accelerometer values */
+   x = xyval & 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;
+
+   switch (chan) {
+   case AXIS_X:
+   ret = x;
+   break;
+   case AXIS_Y:
+   ret = y;
+   break;
+   case AXIS_Z:
+   ret = z;
+   break;
+   }
+
+   return ret;
+}
+
+static int toshiba_accel_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+   int ret;
+
+   switch (mask) {
+   case IIO_CHAN_INFO_RAW:
+   if (iio_buffer_enabled(indio_dev))
+   return -EBUSY;
+
+   ret = toshiba_accel_get_axis(chan->scan_index);
+   if (ret == -EIO || ret == -ENODEV)
+   return ret;
+
+   *val = ret;
+
+   return IIO_VAL_INT;
+   }
+
+   return -EINVAL;
+}
+
+#define TOSHIBA_ACCEL_CHANNEL(axis, chan) { \
+   .type = IIO_ACCEL, \
+   .modified = 1, \
+   .channel2 = IIO_MOD_##axis, \
+   .output = 1, \
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+   .scan_index = chan, \
+}
+
+static const struct iio_chan_spec toshiba_accel_channels[] = {
+   TOSHIBA_ACCEL_CHANNEL(X, AXIS_X),
+   TOSHIBA_ACCEL_CHANNEL(Y, AXIS_Y),
+   TOSHIBA_ACCEL_CHANNEL(Z, AXIS_Z),
+};
+
+static const struct iio_info toshiba_accel_info = {
+   .driver_module = THIS_MODULE,
+   .read_raw = _accel_read_raw,
+};
+
+/*
  * Misc device
  */
 static int

[PATCH 1/3] toshiba_acpi: Add IIO interface for accelerometer axis data

2016-06-11 Thread Azael Avalos
This patch adds the accelerometer axis data to the IIO subsystem.

Currently reporting the X, Y and Z values, as no other data can be
queried given the fact that the accelerometer chip itself is hidden
behind the Toshiba proprietary interface.

Signed-off-by: Azael Avalos 
---
All:
 This is my first attempt with the IIO subsysem, I'll be looking
 forward for your valuable input on this.

Darren:
 There's a warning about more than 80 columns on this patch, once
 I get feedback from the IIO guys I'll respin this with that issue
 corrected.

 drivers/platform/x86/toshiba_acpi.c | 130 ++--
 1 file changed, 126 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 01e12d2..85014a3 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -53,6 +53,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -134,6 +135,7 @@ MODULE_LICENSE("GPL");
 
 /* Field definitions */
 #define HCI_ACCEL_MASK 0x7fff
+#define HCI_ACCEL_DIRECTION_MASK   0x8000
 #define HCI_HOTKEY_DISABLE 0x0b
 #define HCI_HOTKEY_ENABLE  0x09
 #define HCI_HOTKEY_SPECIAL_FUNCTIONS   0x10
@@ -178,6 +180,7 @@ struct toshiba_acpi_dev {
struct led_classdev eco_led;
struct miscdevice miscdev;
struct rfkill *wwan_rfk;
+   struct iio_dev *indio_dev;
 
int force_fan;
int last_key_event;
@@ -1962,8 +1965,8 @@ static ssize_t 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;
 
xyval = zval = 0;
@@ -1971,10 +1974,14 @@ static ssize_t position_show(struct device *dev,
if (ret < 0)
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;
 
return sprintf(buf, "%d %d %d\n", x, y, z);
 }
@@ -2420,6 +2427,94 @@ static void toshiba_acpi_kbd_bl_work(struct work_struct 
*work)
 }
 
 /*
+ * IIO device
+ */
+
+enum toshiba_accel_chan {
+   AXIS_X,
+   AXIS_Y,
+   AXIS_Z
+};
+
+static int toshiba_accel_get_axis(enum toshiba_accel_chan chan)
+{
+   u32 xyval, zval;
+   int x, y, z;
+   int ret;
+
+   xyval = zval = 0;
+   ret = toshiba_accelerometer_get(toshiba_acpi, , );
+   if (ret < 0)
+   return ret;
+
+   /* Accelerometer values */
+   x = xyval & 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;
+
+   switch (chan) {
+   case AXIS_X:
+   ret = x;
+   break;
+   case AXIS_Y:
+   ret = y;
+   break;
+   case AXIS_Z:
+   ret = z;
+   break;
+   }
+
+   return ret;
+}
+
+static int toshiba_accel_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+   int ret;
+
+   switch (mask) {
+   case IIO_CHAN_INFO_RAW:
+   if (iio_buffer_enabled(indio_dev))
+   return -EBUSY;
+
+   ret = toshiba_accel_get_axis(chan->scan_index);
+   if (ret == -EIO || ret == -ENODEV)
+   return ret;
+
+   *val = ret;
+
+   return IIO_VAL_INT;
+   }
+
+   return -EINVAL;
+}
+
+#define TOSHIBA_ACCEL_CHANNEL(axis, chan) { \
+   .type = IIO_ACCEL, \
+   .modified = 1, \
+   .channel2 = IIO_MOD_##axis, \
+   .output = 1, \
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+   .scan_index = chan, \
+}
+
+static const struct iio_chan_spec toshiba_accel_channels[] = {
+   TOSHIBA_ACCEL_CHANNEL(X, AXIS_X),
+   TOSHIBA_ACCEL_CHANNEL(Y, AXIS_Y),
+   TOSHIBA_ACCEL_CHANNEL(Z, AXIS_Z),
+};
+
+static const struct iio_info toshiba_accel_info = {
+   .driver_module = THIS_MODULE,
+   .read_raw = _accel_read_raw,
+};
+
+/*
  * Misc device
  */
 static int toshiba_acpi_smm

[PATCH 0/3] toshiba_acpi: Accelerometer updates

2016-06-11 Thread Azael Avalos
These series of patches update the accelerometer axis data
reporting to use the IIO subsystem, deprecating the custom
position sysfs entry, and finally bumping the driver version
to 0.24.

Azael Avalos (3):
  toshiba_acpi: Add IIO interface for accelerometer axis data
  toshiba_acpi: Remove the position sysfs entry
  toshiba_acpi: Bump driver version and update copyrignt year

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

-- 
2.8.3



[PATCH 2/3] toshiba_acpi: Remove the position sysfs entry

2016-06-11 Thread Azael Avalos
Now that we have proper support for the acceleromeer under the IIO
subsystem, the _position_ sysfs file is now deprecated.

This patch removes all code related to the position sysfs entry.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 85014a3..818b960 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1961,32 +1961,6 @@ static ssize_t touchpad_show(struct device *dev,
 }
 static DEVICE_ATTR_RW(touchpad);
 
-static ssize_t position_show(struct device *dev,
-struct device_attribute *attr, char *buf)
-{
-   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-   u32 xyval, zval;
-   int x, y, z;
-   int ret;
-
-   xyval = zval = 0;
-   ret = toshiba_accelerometer_get(toshiba, , );
-   if (ret < 0)
-   return ret;
-
-   /* Accelerometer values */
-   x = xyval & 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;
-
-   return sprintf(buf, "%d %d %d\n", x, y, z);
-}
-static DEVICE_ATTR_RO(position);
-
 static ssize_t usb_sleep_charge_show(struct device *dev,
 struct device_attribute *attr, char *buf)
 {
@@ -2357,7 +2331,6 @@ static struct attribute *toshiba_attributes[] = {
_attr_available_kbd_modes.attr,
_attr_kbd_backlight_timeout.attr,
_attr_touchpad.attr,
-   _attr_position.attr,
_attr_usb_sleep_charge.attr,
_attr_sleep_functions_on_battery.attr,
_attr_usb_rapid_charge.attr,
@@ -2384,8 +2357,6 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
else if (attr == _attr_touchpad.attr)
exists = (drv->touchpad_supported) ? true : false;
-   else if (attr == _attr_position.attr)
-   exists = (drv->accelerometer_supported) ? true : false;
else if (attr == _attr_usb_sleep_charge.attr)
exists = (drv->usb_sleep_charge_supported) ? true : false;
else if (attr == _attr_sleep_functions_on_battery.attr)
-- 
2.8.3



[PATCH 3/3] toshiba_acpi: Bump driver version and update copyrignt year

2016-06-11 Thread Azael Avalos
After several fixes, and added support for more features (WWAN,
Cooling Method and IIO accelometer axis data), bump the driver
version to 0.24.

Also update the copyright year.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 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 818b960..c2983bd 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -4,7 +4,7 @@
  *  Copyright (C) 2002-2004 John Belmonte
  *  Copyright (C) 2008 Philip Langdale
  *  Copyright (C) 2010 Pierre Ducroquet
- *  Copyright (C) 2014-2015 Azael Avalos
+ *  Copyright (C) 2014-2016 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
@@ -31,7 +31,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#define TOSHIBA_ACPI_VERSION   "0.23"
+#define TOSHIBA_ACPI_VERSION   "0.24"
 #define PROC_INTERFACE_VERSION 1
 
 #include 
-- 
2.8.3



[PATCH 0/3] toshiba_acpi: Accelerometer updates

2016-06-11 Thread Azael Avalos
These series of patches update the accelerometer axis data
reporting to use the IIO subsystem, deprecating the custom
position sysfs entry, and finally bumping the driver version
to 0.24.

Azael Avalos (3):
  toshiba_acpi: Add IIO interface for accelerometer axis data
  toshiba_acpi: Remove the position sysfs entry
  toshiba_acpi: Bump driver version and update copyrignt year

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

-- 
2.8.3



[PATCH 2/3] toshiba_acpi: Remove the position sysfs entry

2016-06-11 Thread Azael Avalos
Now that we have proper support for the acceleromeer under the IIO
subsystem, the _position_ sysfs file is now deprecated.

This patch removes all code related to the position sysfs entry.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 85014a3..818b960 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1961,32 +1961,6 @@ static ssize_t touchpad_show(struct device *dev,
 }
 static DEVICE_ATTR_RW(touchpad);
 
-static ssize_t position_show(struct device *dev,
-struct device_attribute *attr, char *buf)
-{
-   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-   u32 xyval, zval;
-   int x, y, z;
-   int ret;
-
-   xyval = zval = 0;
-   ret = toshiba_accelerometer_get(toshiba, , );
-   if (ret < 0)
-   return ret;
-
-   /* Accelerometer values */
-   x = xyval & 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;
-
-   return sprintf(buf, "%d %d %d\n", x, y, z);
-}
-static DEVICE_ATTR_RO(position);
-
 static ssize_t usb_sleep_charge_show(struct device *dev,
 struct device_attribute *attr, char *buf)
 {
@@ -2357,7 +2331,6 @@ static struct attribute *toshiba_attributes[] = {
_attr_available_kbd_modes.attr,
_attr_kbd_backlight_timeout.attr,
_attr_touchpad.attr,
-   _attr_position.attr,
_attr_usb_sleep_charge.attr,
_attr_sleep_functions_on_battery.attr,
_attr_usb_rapid_charge.attr,
@@ -2384,8 +2357,6 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
else if (attr == _attr_touchpad.attr)
exists = (drv->touchpad_supported) ? true : false;
-   else if (attr == _attr_position.attr)
-   exists = (drv->accelerometer_supported) ? true : false;
else if (attr == _attr_usb_sleep_charge.attr)
exists = (drv->usb_sleep_charge_supported) ? true : false;
else if (attr == _attr_sleep_functions_on_battery.attr)
-- 
2.8.3



[PATCH 3/3] toshiba_acpi: Bump driver version and update copyrignt year

2016-06-11 Thread Azael Avalos
After several fixes, and added support for more features (WWAN,
Cooling Method and IIO accelometer axis data), bump the driver
version to 0.24.

Also update the copyright year.

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 818b960..c2983bd 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -4,7 +4,7 @@
  *  Copyright (C) 2002-2004 John Belmonte
  *  Copyright (C) 2008 Philip Langdale
  *  Copyright (C) 2010 Pierre Ducroquet
- *  Copyright (C) 2014-2015 Azael Avalos
+ *  Copyright (C) 2014-2016 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
@@ -31,7 +31,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#define TOSHIBA_ACPI_VERSION   "0.23"
+#define TOSHIBA_ACPI_VERSION   "0.24"
 #define PROC_INTERFACE_VERSION 1
 
 #include 
-- 
2.8.3



Re: [PATCH] toshiba_acpi: Fix regression caused by hotkey enabling value

2016-04-25 Thread Azael Avalos
Hi Darren,


No problem with me, ohh and thanks, I forgot to include stable.


Cheers
Azael


2016-04-25 11:31 GMT-06:00 Darren Hart <dvh...@infradead.org>:
> On Fri, Apr 22, 2016 at 09:29:36AM -0600, Azael Avalos wrote:
>> Commit 52cbae0127ad ("toshiba_acpi: Change default Hotkey enabling value")
>> changed the hotkeys enabling value, as it was the same value Windows uses,
>> however, it turns out that the value tells the EC that the driver will now
>> take care of the hardware events like the physical RFKill switch or the
>> pointing device toggle button.
>>
>> This patch reverts such commit by changing the default hotkey enabling
>> value to 0x09, which enables hotkey events only, making the hardware
>> buttons working again.
>>
>> Fixes bugs 113331 and 114941.
>>
>> Signed-off-by: Azael Avalos <coproscef...@gmail.com>
>
> I wasn't planning on another pull to Linus at r5, but since this is a
> regression, I've queued it for 4.6-rc6. It will liketly be the only patch in 
> the
> pull request. If Linus objects, we'll push it to 4.7. Either way, I'll tag it
> for stable.
>
>> ---
>>  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 df1f1a7..01e12d2 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -135,7 +135,7 @@ MODULE_LICENSE("GPL");
>>  /* Field definitions */
>>  #define HCI_ACCEL_MASK   0x7fff
>>  #define HCI_HOTKEY_DISABLE   0x0b
>> -#define HCI_HOTKEY_ENABLE0x01
>> +#define HCI_HOTKEY_ENABLE0x09
>>  #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
>>  #define HCI_LCD_BRIGHTNESS_BITS  3
>>  #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
>> --
>> 2.8.1
>>
>>
>
> --
> Darren Hart
> Intel Open Source Technology Center



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


Re: [PATCH] toshiba_acpi: Fix regression caused by hotkey enabling value

2016-04-25 Thread Azael Avalos
Hi Darren,


No problem with me, ohh and thanks, I forgot to include stable.


Cheers
Azael


2016-04-25 11:31 GMT-06:00 Darren Hart :
> On Fri, Apr 22, 2016 at 09:29:36AM -0600, Azael Avalos wrote:
>> Commit 52cbae0127ad ("toshiba_acpi: Change default Hotkey enabling value")
>> changed the hotkeys enabling value, as it was the same value Windows uses,
>> however, it turns out that the value tells the EC that the driver will now
>> take care of the hardware events like the physical RFKill switch or the
>> pointing device toggle button.
>>
>> This patch reverts such commit by changing the default hotkey enabling
>> value to 0x09, which enables hotkey events only, making the hardware
>> buttons working again.
>>
>> Fixes bugs 113331 and 114941.
>>
>> Signed-off-by: Azael Avalos 
>
> I wasn't planning on another pull to Linus at r5, but since this is a
> regression, I've queued it for 4.6-rc6. It will liketly be the only patch in 
> the
> pull request. If Linus objects, we'll push it to 4.7. Either way, I'll tag it
> for stable.
>
>> ---
>>  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 df1f1a7..01e12d2 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -135,7 +135,7 @@ MODULE_LICENSE("GPL");
>>  /* Field definitions */
>>  #define HCI_ACCEL_MASK   0x7fff
>>  #define HCI_HOTKEY_DISABLE   0x0b
>> -#define HCI_HOTKEY_ENABLE0x01
>> +#define HCI_HOTKEY_ENABLE0x09
>>  #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
>>  #define HCI_LCD_BRIGHTNESS_BITS  3
>>  #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
>> --
>> 2.8.1
>>
>>
>
> --
> Darren Hart
> Intel Open Source Technology Center



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


[PATCH] toshiba_acpi: Fix regression caused by hotkey enabling value

2016-04-22 Thread Azael Avalos
Commit 52cbae0127ad ("toshiba_acpi: Change default Hotkey enabling value")
changed the hotkeys enabling value, as it was the same value Windows uses,
however, it turns out that the value tells the EC that the driver will now
take care of the hardware events like the physical RFKill switch or the
pointing device toggle button.

This patch reverts such commit by changing the default hotkey enabling
value to 0x09, which enables hotkey events only, making the hardware
buttons working again.

Fixes bugs 113331 and 114941.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 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 df1f1a7..01e12d2 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -135,7 +135,7 @@ MODULE_LICENSE("GPL");
 /* Field definitions */
 #define HCI_ACCEL_MASK 0x7fff
 #define HCI_HOTKEY_DISABLE 0x0b
-#define HCI_HOTKEY_ENABLE  0x01
+#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)
-- 
2.8.1



[PATCH] toshiba_acpi: Fix regression caused by hotkey enabling value

2016-04-22 Thread Azael Avalos
Commit 52cbae0127ad ("toshiba_acpi: Change default Hotkey enabling value")
changed the hotkeys enabling value, as it was the same value Windows uses,
however, it turns out that the value tells the EC that the driver will now
take care of the hardware events like the physical RFKill switch or the
pointing device toggle button.

This patch reverts such commit by changing the default hotkey enabling
value to 0x09, which enables hotkey events only, making the hardware
buttons working again.

Fixes bugs 113331 and 114941.

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 df1f1a7..01e12d2 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -135,7 +135,7 @@ MODULE_LICENSE("GPL");
 /* Field definitions */
 #define HCI_ACCEL_MASK 0x7fff
 #define HCI_HOTKEY_DISABLE 0x0b
-#define HCI_HOTKEY_ENABLE  0x01
+#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)
-- 
2.8.1



[PATCH] toshiba_acpi: Add a module parameter to disable hotkeys registration

2016-01-25 Thread Azael Avalos
Some laptop models have working hotkeys without the need of the driver
to activate them.

This patch adds a module parameter to tell the driver not to register
the hotkeys.

The new parameter is useful in DE less installations or where the DE
does not handle the hotkeys (see bug 99501).

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 5ace1e0..df1f1a7 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -36,6 +36,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -220,6 +221,10 @@ struct toshiba_acpi_dev {
 
 static struct toshiba_acpi_dev *toshiba_acpi;
 
+static bool disable_hotkeys;
+module_param(disable_hotkeys, bool, 0444);
+MODULE_PARM_DESC(disable_hotkeys, "Disables the hotkeys activation");
+
 static const struct acpi_device_id toshiba_device_ids[] = {
{"TOS6200", 0},
{"TOS6207", 0},
@@ -2692,6 +2697,11 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
acpi_handle ec_handle;
int error;
 
+   if (disable_hotkeys) {
+   pr_info("Hotkeys disabled by module parameter\n");
+   return 0;
+   }
+
if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
pr_info("WMI event detected, hotkeys will not be monitored\n");
return 0;
-- 
2.7.0



[PATCH 0/3] toshiba_acpi: Add support for Cooling Method

2016-01-25 Thread Azael Avalos
These patches add support for the Cooling Method feature found in most
Toshiba laptops, allowing userspace to control the desired cooling method,
which are the following:
0 - Maximum Performance
1 - Peformance
2 - Battery Optimized

The Cooling Method feature basically controls the speed of the system fan,
setting the speed (and quietness) according to the selected method.

The default value at every boot is zero (Maximum Performance), on Windows,
Toshiba provides hooks to the power management system, allowing
the user to change it according to their needs and/or the AC adapter state.


Azael Avalos (3):
  toshiba_acpi: Add support for cooling method feature
  toshiba_acpi: Add sysfs entries for th Cooling Method feature
  Documentation/ABI: Update sysfs-driver-toshiba_acpi file

 .../ABI/testing/sysfs-driver-toshiba_acpi  |  16 
 drivers/platform/x86/toshiba_acpi.c| 105 +
 2 files changed, 121 insertions(+)

-- 
2.7.0



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

2016-01-25 Thread Azael Avalos
This patch updates the documentation file adding the Cooling Method
entry.

Signed-off-by: Azael Avalos 
---
 Documentation/ABI/testing/sysfs-driver-toshiba_acpi | 16 
 1 file changed, 16 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-driver-toshiba_acpi 
b/Documentation/ABI/testing/sysfs-driver-toshiba_acpi
index eed922e..f34221b 100644
--- a/Documentation/ABI/testing/sysfs-driver-toshiba_acpi
+++ b/Documentation/ABI/testing/sysfs-driver-toshiba_acpi
@@ -179,3 +179,19 @@ Description:   This file controls the USB 3 
functionality, valid values are:
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/cooling_method
+Date:  2016
+KernelVersion: 4.6
+Contact:   Azael Avalos 
+Description:   This file controls the Cooling Method feature.
+   Reading this file prints two values, the first is the actual 
cooling method
+   and the second is the maximum cooling method supported.
+   When the maximum cooling method is ONE, valid values are:
+   * 0 -> Maximum Performance
+   * 1 -> Battery Optimized
+   When the maximum cooling method is TWO, valid values are:
+   * 0 -> Maximum Performance
+   * 1 -> Performance
+   * 2 -> Battery Optimized
+Users: KToshiba
-- 
2.7.0



[PATCH 1/3] toshiba_acpi: Add support for cooling method feature

2016-01-25 Thread Azael Avalos
This patch adds support to query and set the "Cooling Method" feature,
which basically changes how the system fan behaves, depending on the
supported cooling methods.

Depending on the laptop model, these are the (so far...) available
cooling methods:
- Maximum Performance
- Performance
- Battery Optimized

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 7383307..c6f92ec 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -117,6 +117,7 @@ MODULE_LICENSE("GPL");
 #define HCI_LCD_BRIGHTNESS 0x002a
 #define HCI_WIRELESS   0x0056
 #define HCI_ACCELEROMETER  0x006d
+#define HCI_COOLING_METHOD 0x007f
 #define HCI_KBD_ILLUMINATION   0x0095
 #define HCI_ECO_MODE   0x0097
 #define HCI_ACCELEROMETER2 0x00a6
@@ -186,6 +187,7 @@ struct toshiba_acpi_dev {
int usbsc_bat_level;
int usbsc_mode_base;
int hotkey_event_type;
+   int max_cooling_method;
 
unsigned int illumination_supported:1;
unsigned int video_supported:1;
@@ -205,6 +207,7 @@ struct toshiba_acpi_dev {
unsigned int panel_power_on_supported:1;
unsigned int usb_three_supported:1;
unsigned int wwan_supported:1;
+   unsigned int cooling_method_supported:1;
unsigned int sysfs_created:1;
unsigned int special_functions;
 
@@ -1194,6 +1197,53 @@ static int toshiba_wwan_set(struct toshiba_acpi_dev 
*dev, u32 state)
return out[0] == TOS_SUCCESS ? 0 : -EIO;
 }
 
+/* Cooling Method */
+static void toshiba_cooling_method_available(struct toshiba_acpi_dev *dev)
+{
+   u32 in[TCI_WORDS] = { HCI_GET, HCI_COOLING_METHOD, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   dev->cooling_method_supported = 0;
+   dev->max_cooling_method = 0;
+
+   status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status))
+   pr_err("ACPI call to get Cooling Method failed\n");
+
+   if (out[0] != TOS_SUCCESS && out[0] != TOS_SUCCESS2)
+   return;
+
+   dev->cooling_method_supported = 1;
+   dev->max_cooling_method = out[3];
+}
+
+static int toshiba_cooling_method_get(struct toshiba_acpi_dev *dev, u32 *state)
+{
+   u32 result = hci_read(dev, HCI_COOLING_METHOD, state);
+
+   if (result == TOS_FAILURE)
+   pr_err("ACPI call to get Cooling Method failed\n");
+
+   if (result == TOS_NOT_SUPPORTED)
+   return -ENODEV;
+
+   return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
+}
+
+static int toshiba_cooling_method_set(struct toshiba_acpi_dev *dev, u32 state)
+{
+   u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
+
+   if (result == TOS_FAILURE)
+   pr_err("ACPI call to get Cooling Method failed\n");
+
+   if (result == TOS_NOT_SUPPORTED)
+   return -ENODEV;
+
+   return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
+}
+
 /* Transflective Backlight */
 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
 {
@@ -2779,6 +2829,8 @@ static void print_supported_features(struct 
toshiba_acpi_dev *dev)
pr_cont(" usb3");
if (dev->wwan_supported)
pr_cont(" wwan");
+   if (dev->cooling_method_supported)
+   pr_cont(" cooling-method");
 
pr_cont("\n");
 }
@@ -2963,6 +3015,8 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
if (dev->wwan_supported)
toshiba_acpi_setup_wwan_rfkill(dev);
 
+   toshiba_cooling_method_available(dev);
+
print_supported_features(dev);
 
ret = sysfs_create_group(>acpi_dev->dev.kobj,
-- 
2.7.0



[PATCH 2/2] toshiba_acpi: Add sysfs entries for the Cooling Method feature

2016-01-25 Thread Azael Avalos
This patch adds the sysfs entry

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index c6f92ec..5ace1e0 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -2289,6 +2289,54 @@ static ssize_t usb_three_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(usb_three);
 
+static ssize_t cooling_method_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
+   int state;
+   int ret;
+
+   ret = toshiba_cooling_method_get(toshiba, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%d %d\n", state, toshiba->max_cooling_method);
+}
+
+static ssize_t cooling_method_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;
+   int ret;
+
+   ret = kstrtoint(buf, 0, );
+   if (ret)
+   return ret;
+
+   /*
+* Check for supported values
+* Depending on the laptop model, some only support these two:
+* 0 - Maximum Performance
+* 1 - Battery Optimized
+*
+* While some others support all three methods:
+* 0 - Maximum Performance
+* 1 - Performance
+* 2 - Battery Optimized
+*/
+   if (state < 0 || state > toshiba->max_cooling_method)
+   return -EINVAL;
+
+   ret = toshiba_cooling_method_set(toshiba, state);
+   if (ret)
+   return ret;
+
+   return count;
+}
+static DEVICE_ATTR_RW(cooling_method);
+
 static struct attribute *toshiba_attributes[] = {
_attr_version.attr,
_attr_fan.attr,
@@ -2305,6 +2353,7 @@ static struct attribute *toshiba_attributes[] = {
_attr_kbd_function_keys.attr,
_attr_panel_power_on.attr,
_attr_usb_three.attr,
+   _attr_cooling_method.attr,
NULL,
 };
 
@@ -2339,6 +2388,8 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (drv->panel_power_on_supported) ? true : false;
else if (attr == _attr_usb_three.attr)
exists = (drv->usb_three_supported) ? true : false;
+   else if (attr == _attr_cooling_method.attr)
+   exists = (drv->cooling_method_supported) ? true : false;
 
return exists ? attr->mode : 0;
 }
-- 
2.7.0



[PATCH] toshiba_acpi: Add a module parameter to disable hotkeys registration

2016-01-25 Thread Azael Avalos
Some laptop models have working hotkeys without the need of the driver
to activate them.

This patch adds a module parameter to tell the driver not to register
the hotkeys.

The new parameter is useful in DE less installations or where the DE
does not handle the hotkeys (see bug 99501).

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 5ace1e0..df1f1a7 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -36,6 +36,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -220,6 +221,10 @@ struct toshiba_acpi_dev {
 
 static struct toshiba_acpi_dev *toshiba_acpi;
 
+static bool disable_hotkeys;
+module_param(disable_hotkeys, bool, 0444);
+MODULE_PARM_DESC(disable_hotkeys, "Disables the hotkeys activation");
+
 static const struct acpi_device_id toshiba_device_ids[] = {
{"TOS6200", 0},
{"TOS6207", 0},
@@ -2692,6 +2697,11 @@ static int toshiba_acpi_setup_keyboard(struct 
toshiba_acpi_dev *dev)
acpi_handle ec_handle;
int error;
 
+   if (disable_hotkeys) {
+   pr_info("Hotkeys disabled by module parameter\n");
+   return 0;
+   }
+
if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
pr_info("WMI event detected, hotkeys will not be monitored\n");
return 0;
-- 
2.7.0



[PATCH 2/2] toshiba_acpi: Add sysfs entries for the Cooling Method feature

2016-01-25 Thread Azael Avalos
This patch adds the sysfs entry

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index c6f92ec..5ace1e0 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -2289,6 +2289,54 @@ static ssize_t usb_three_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(usb_three);
 
+static ssize_t cooling_method_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
+   int state;
+   int ret;
+
+   ret = toshiba_cooling_method_get(toshiba, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%d %d\n", state, toshiba->max_cooling_method);
+}
+
+static ssize_t cooling_method_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;
+   int ret;
+
+   ret = kstrtoint(buf, 0, );
+   if (ret)
+   return ret;
+
+   /*
+* Check for supported values
+* Depending on the laptop model, some only support these two:
+* 0 - Maximum Performance
+* 1 - Battery Optimized
+*
+* While some others support all three methods:
+* 0 - Maximum Performance
+* 1 - Performance
+* 2 - Battery Optimized
+*/
+   if (state < 0 || state > toshiba->max_cooling_method)
+   return -EINVAL;
+
+   ret = toshiba_cooling_method_set(toshiba, state);
+   if (ret)
+   return ret;
+
+   return count;
+}
+static DEVICE_ATTR_RW(cooling_method);
+
 static struct attribute *toshiba_attributes[] = {
_attr_version.attr,
_attr_fan.attr,
@@ -2305,6 +2353,7 @@ static struct attribute *toshiba_attributes[] = {
_attr_kbd_function_keys.attr,
_attr_panel_power_on.attr,
_attr_usb_three.attr,
+   _attr_cooling_method.attr,
NULL,
 };
 
@@ -2339,6 +2388,8 @@ static umode_t toshiba_sysfs_is_visible(struct kobject 
*kobj,
exists = (drv->panel_power_on_supported) ? true : false;
else if (attr == _attr_usb_three.attr)
exists = (drv->usb_three_supported) ? true : false;
+   else if (attr == _attr_cooling_method.attr)
+   exists = (drv->cooling_method_supported) ? true : false;
 
return exists ? attr->mode : 0;
 }
-- 
2.7.0



[PATCH 0/3] toshiba_acpi: Add support for Cooling Method

2016-01-25 Thread Azael Avalos
These patches add support for the Cooling Method feature found in most
Toshiba laptops, allowing userspace to control the desired cooling method,
which are the following:
0 - Maximum Performance
1 - Peformance
2 - Battery Optimized

The Cooling Method feature basically controls the speed of the system fan,
setting the speed (and quietness) according to the selected method.

The default value at every boot is zero (Maximum Performance), on Windows,
Toshiba provides hooks to the power management system, allowing
the user to change it according to their needs and/or the AC adapter state.


Azael Avalos (3):
  toshiba_acpi: Add support for cooling method feature
  toshiba_acpi: Add sysfs entries for th Cooling Method feature
  Documentation/ABI: Update sysfs-driver-toshiba_acpi file

 .../ABI/testing/sysfs-driver-toshiba_acpi  |  16 
 drivers/platform/x86/toshiba_acpi.c| 105 +
 2 files changed, 121 insertions(+)

-- 
2.7.0



[PATCH 1/3] toshiba_acpi: Add support for cooling method feature

2016-01-25 Thread Azael Avalos
This patch adds support to query and set the "Cooling Method" feature,
which basically changes how the system fan behaves, depending on the
supported cooling methods.

Depending on the laptop model, these are the (so far...) available
cooling methods:
- Maximum Performance
- Performance
- Battery Optimized

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 7383307..c6f92ec 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -117,6 +117,7 @@ MODULE_LICENSE("GPL");
 #define HCI_LCD_BRIGHTNESS 0x002a
 #define HCI_WIRELESS   0x0056
 #define HCI_ACCELEROMETER  0x006d
+#define HCI_COOLING_METHOD 0x007f
 #define HCI_KBD_ILLUMINATION   0x0095
 #define HCI_ECO_MODE   0x0097
 #define HCI_ACCELEROMETER2 0x00a6
@@ -186,6 +187,7 @@ struct toshiba_acpi_dev {
int usbsc_bat_level;
int usbsc_mode_base;
int hotkey_event_type;
+   int max_cooling_method;
 
unsigned int illumination_supported:1;
unsigned int video_supported:1;
@@ -205,6 +207,7 @@ struct toshiba_acpi_dev {
unsigned int panel_power_on_supported:1;
unsigned int usb_three_supported:1;
unsigned int wwan_supported:1;
+   unsigned int cooling_method_supported:1;
unsigned int sysfs_created:1;
unsigned int special_functions;
 
@@ -1194,6 +1197,53 @@ static int toshiba_wwan_set(struct toshiba_acpi_dev 
*dev, u32 state)
return out[0] == TOS_SUCCESS ? 0 : -EIO;
 }
 
+/* Cooling Method */
+static void toshiba_cooling_method_available(struct toshiba_acpi_dev *dev)
+{
+   u32 in[TCI_WORDS] = { HCI_GET, HCI_COOLING_METHOD, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   dev->cooling_method_supported = 0;
+   dev->max_cooling_method = 0;
+
+   status = tci_raw(dev, in, out);
+   if (ACPI_FAILURE(status))
+   pr_err("ACPI call to get Cooling Method failed\n");
+
+   if (out[0] != TOS_SUCCESS && out[0] != TOS_SUCCESS2)
+   return;
+
+   dev->cooling_method_supported = 1;
+   dev->max_cooling_method = out[3];
+}
+
+static int toshiba_cooling_method_get(struct toshiba_acpi_dev *dev, u32 *state)
+{
+   u32 result = hci_read(dev, HCI_COOLING_METHOD, state);
+
+   if (result == TOS_FAILURE)
+   pr_err("ACPI call to get Cooling Method failed\n");
+
+   if (result == TOS_NOT_SUPPORTED)
+   return -ENODEV;
+
+   return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
+}
+
+static int toshiba_cooling_method_set(struct toshiba_acpi_dev *dev, u32 state)
+{
+   u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
+
+   if (result == TOS_FAILURE)
+   pr_err("ACPI call to get Cooling Method failed\n");
+
+   if (result == TOS_NOT_SUPPORTED)
+   return -ENODEV;
+
+   return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
+}
+
 /* Transflective Backlight */
 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
 {
@@ -2779,6 +2829,8 @@ static void print_supported_features(struct 
toshiba_acpi_dev *dev)
pr_cont(" usb3");
if (dev->wwan_supported)
pr_cont(" wwan");
+   if (dev->cooling_method_supported)
+   pr_cont(" cooling-method");
 
pr_cont("\n");
 }
@@ -2963,6 +3015,8 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
if (dev->wwan_supported)
toshiba_acpi_setup_wwan_rfkill(dev);
 
+   toshiba_cooling_method_available(dev);
+
print_supported_features(dev);
 
ret = sysfs_create_group(>acpi_dev->dev.kobj,
-- 
2.7.0



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

2016-01-25 Thread Azael Avalos
This patch updates the documentation file adding the Cooling Method
entry.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 Documentation/ABI/testing/sysfs-driver-toshiba_acpi | 16 
 1 file changed, 16 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-driver-toshiba_acpi 
b/Documentation/ABI/testing/sysfs-driver-toshiba_acpi
index eed922e..f34221b 100644
--- a/Documentation/ABI/testing/sysfs-driver-toshiba_acpi
+++ b/Documentation/ABI/testing/sysfs-driver-toshiba_acpi
@@ -179,3 +179,19 @@ Description:   This file controls the USB 3 
functionality, valid values are:
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/cooling_method
+Date:  2016
+KernelVersion: 4.6
+Contact:   Azael Avalos <coproscef...@gmail.com>
+Description:   This file controls the Cooling Method feature.
+   Reading this file prints two values, the first is the actual 
cooling method
+   and the second is the maximum cooling method supported.
+   When the maximum cooling method is ONE, valid values are:
+   * 0 -> Maximum Performance
+   * 1 -> Battery Optimized
+   When the maximum cooling method is TWO, valid values are:
+   * 0 -> Maximum Performance
+   * 1 -> Performance
+   * 2 -> Battery Optimized
+Users: KToshiba
-- 
2.7.0



[PATCH] platform/x86: Add rfkill dependency to ACPI_TOSHIBA entry

2015-12-14 Thread Azael Avalos
Commit 2fdde83443aa ("toshiba_acpi: Add WWAN RFKill support") added
WWAN rfkill support to the driver, but the KConfig entry was not
updated to add the RFKill dependency, causing a broken build if
RFKill is not selected.

This patch adds the RFKILL dependency to the KConfig entry, fixing
the build issue.

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 1089eaa..25a02f9 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -641,6 +641,7 @@ config ACPI_TOSHIBA
depends on INPUT
depends on SERIO_I8042 || SERIO_I8042 = n
depends on ACPI_VIDEO || ACPI_VIDEO = n
+   depends on RFKILL || RFKILL = n
select INPUT_POLLDEV
select INPUT_SPARSEKMAP
---help---
-- 
2.6.3

--
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: Add rfkill dependency to ACPI_TOSHIBA entry

2015-12-14 Thread Azael Avalos
Commit 2fdde83443aa ("toshiba_acpi: Add WWAN RFKill support") added
WWAN rfkill support to the driver, but the KConfig entry was not
updated to add the RFKill dependency, causing a broken build if
RFKill is not selected.

This patch adds the RFKILL dependency to the KConfig entry, fixing
the build issue.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 drivers/platform/x86/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 1089eaa..25a02f9 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -641,6 +641,7 @@ config ACPI_TOSHIBA
depends on INPUT
depends on SERIO_I8042 || SERIO_I8042 = n
depends on ACPI_VIDEO || ACPI_VIDEO = n
+   depends on RFKILL || RFKILL = n
select INPUT_POLLDEV
select INPUT_SPARSEKMAP
---help---
-- 
2.6.3

--
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: Fix keyboard backight sysfs entries not being updated

2015-11-23 Thread Azael Avalos
Certain Toshiba models with the second generation keyboard backlight
(type 2) do not generate the keyboard backlight changed event (0x92),
and thus, the sysfs entries are never being updated.

This patch adds a workquee and a global boolean variable to address
the issue.

For those models that do generate the event, the sysfs entries are
being updated via the *notify function and the boolean is set to
true to avoid a second call to update the entries.

For those models that do not generate the event, the workquee is
used to update the sysfs entries and also to emulate the event via
netlink, to make userspace aware of such change.

Signed-off-by: Azael Avalos 
---
Changes since v1:
- Moved the implementation of the toshiba_acpi_kbd_bl_work function further down
  to make the file compile

 drivers/platform/x86/toshiba_acpi.c | 47 +
 1 file changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index df2612e..410bacc 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -206,6 +206,7 @@ struct toshiba_acpi_dev {
unsigned int sysfs_created:1;
unsigned int special_functions;
 
+   bool kbd_event_generated;
bool kbd_led_registered;
bool illumination_led_registered;
bool eco_led_registered;
@@ -523,6 +524,7 @@ static void toshiba_kbd_illum_available(struct 
toshiba_acpi_dev *dev)
 
dev->kbd_illum_supported = 0;
dev->kbd_led_registered = false;
+   dev->kbd_event_generated = false;
 
if (!sci_open(dev))
return;
@@ -1642,6 +1644,11 @@ static const struct backlight_ops toshiba_backlight_data 
= {
.update_status  = set_lcd_status,
 };
 
+/* Keyboard backlight work */
+static void toshiba_acpi_kbd_bl_work(struct work_struct *work);
+
+static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work);
+
 /*
  * Sysfs files
  */
@@ -1741,6 +1748,24 @@ static ssize_t kbd_backlight_mode_store(struct device 
*dev,
return ret;
 
toshiba->kbd_mode = mode;
+
+   /*
+* Some laptop models with the second generation backlit
+* keyboard (type 2) do not generate the keyboard backlight
+* changed event (0x92), and thus, the driver will never update
+* the sysfs entries.
+*
+* The event is generated right when changing the keyboard
+* backlight mode and the *notify function will set the
+* kbd_event_generated to true.
+*
+* In case the event is not generated, schedule the keyboard
+* backlight work to update the sysfs entries and emulate the
+* event via genetlink.
+*/
+   if (toshiba->kbd_type == 2 &&
+   !toshiba_acpi->kbd_event_generated)
+   schedule_work(_bl_work);
}
 
return count;
@@ -2273,6 +2298,21 @@ static struct attribute_group toshiba_attr_group = {
.attrs = toshiba_attributes,
 };
 
+static void toshiba_acpi_kbd_bl_work(struct work_struct *work)
+{
+   struct acpi_device *acpi_dev = toshiba_acpi->acpi_dev;
+
+   /* Update the sysfs entries */
+   if (sysfs_update_group(_dev->dev.kobj,
+  _attr_group))
+   pr_err("Unable to update sysfs entries\n");
+
+   /* Emulate the keyboard backlight event */
+   acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
+   dev_name(_dev->dev),
+   0x92, 0);
+}
+
 /*
  * Misc device
  */
@@ -2871,7 +2911,6 @@ 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 */
@@ -2901,10 +2940,10 @@ static void toshiba_acpi_notify(struct acpi_device 
*acpi_dev, u32 event)
pr_info("SATA power event received %x\n", event);
break;
case 0x92: /* Keyboard backlight mode changed */
+   toshiba_acpi->kbd_event_generated = true;
/* Update sysfs entries */
-   ret = sysfs_update_group(_dev->dev.kobj,
-_attr_group);
-   if (ret)
+   if (sysfs_update_group(_dev->dev.kobj,
+  _attr_group))
pr_err("Unable to update sysfs entries\n");
break;
case 0x85: /* Unknown */
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More maj

[PATCH v3 1/2] toshiba_acpi: Add support for WWAN devices

2015-11-23 Thread Azael Avalos
Toshiba laptops with WWAN devices installed cannot use the device unless
it is attached and powered, similar to how Toshiba Bluetooth devices
work.

This patch adds support to WWAN devices, introducing three functions,
one to query the overall status of the wireless devices (RFKill, WLAN,
BT, WWAN), the second queries WWAN support, and finally the third
(de)activates the device.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index c013029..dfa760d 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -114,6 +114,7 @@ MODULE_LICENSE("GPL");
 #define HCI_VIDEO_OUT  0x001c
 #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
@@ -148,6 +149,10 @@ MODULE_LICENSE("GPL");
 #define SCI_KBD_MODE_ON0x8
 #define SCI_KBD_MODE_OFF   0x10
 #define SCI_KBD_TIME_MAX   0x3c001a
+#define HCI_WIRELESS_STATUS0x1
+#define HCI_WIRELESS_WWAN  0x3
+#define HCI_WIRELESS_WWAN_STATUS   0x2000
+#define HCI_WIRELESS_WWAN_POWER0x4000
 #define SCI_USB_CHARGE_MODE_MASK   0xff
 #define SCI_USB_CHARGE_DISABLED0x00
 #define SCI_USB_CHARGE_ALTERNATE   0x09
@@ -197,12 +202,14 @@ struct toshiba_acpi_dev {
unsigned int kbd_function_keys_supported:1;
unsigned int panel_power_on_supported:1;
unsigned int usb_three_supported:1;
+   unsigned int wwan_supported:1;
unsigned int sysfs_created:1;
unsigned int special_functions;
 
bool kbd_led_registered;
bool illumination_led_registered;
bool eco_led_registered;
+   bool killswitch;
 };
 
 static struct toshiba_acpi_dev *toshiba_acpi;
@@ -1085,6 +1092,104 @@ static int toshiba_hotkey_event_type_get(struct 
toshiba_acpi_dev *dev,
return -EIO;
 }
 
+/* Wireless status (RFKill, WLAN, BT, WWAN) */
+static int toshiba_wireless_status(struct toshiba_acpi_dev *dev)
+{
+   u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   in[3] = HCI_WIRELESS_STATUS;
+   status = tci_raw(dev, in, out);
+
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to get Wireless status failed\n");
+   return -EIO;
+   }
+
+   if (out[0] == TOS_NOT_SUPPORTED)
+   return -ENODEV;
+
+   if (out[0] != TOS_SUCCESS)
+   return -EIO;
+
+   dev->killswitch = !!(out[2] & HCI_WIRELESS_STATUS);
+
+   return 0;
+}
+
+/* WWAN */
+static void toshiba_wwan_available(struct toshiba_acpi_dev *dev)
+{
+   u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   dev->wwan_supported = 0;
+
+   /*
+* WWAN support can be queried by setting the in[3] value to
+* HCI_WIRELESS_WWAN (0x03).
+*
+* If supported, out[0] contains TOS_SUCCESS and out[2] contains
+* HCI_WIRELESS_WWAN_STATUS (0x2000).
+*
+* If not supported, out[0] contains TOS_INPUT_DATA_ERROR (0x8300)
+* or TOS_NOT_SUPPORTED (0x8000).
+*/
+   in[3] = HCI_WIRELESS_WWAN;
+   status = tci_raw(dev, in, out);
+
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to get WWAN status failed\n");
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->wwan_supported = (out[2] == HCI_WIRELESS_WWAN_STATUS);
+}
+
+static int toshiba_wwan_set(struct toshiba_acpi_dev *dev, u32 state)
+{
+   u32 in[TCI_WORDS] = { HCI_SET, HCI_WIRELESS, state, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   in[3] = HCI_WIRELESS_WWAN_STATUS;
+   status = tci_raw(dev, in, out);
+
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to set WWAN status failed\n");
+   return -EIO;
+   }
+
+   if (out[0] == TOS_NOT_SUPPORTED)
+   return -ENODEV;
+
+   if (out[0] != TOS_SUCCESS)
+   return -EIO;
+
+   /*
+* Some devices only need to call HCI_WIRELESS_WWAN_STATUS to
+* (de)activate the device, but some others need the
+* HCI_WIRELESS_WWAN_POWER call as well.
+*/
+   in[3] = HCI_WIRELESS_WWAN_POWER;
+   status = tci_raw(dev, in, out);
+
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to set WWAN power failed\n");
+  

[PATCH v3 2/2] toshiba_acpi: Add WWAN RFKill support

2015-11-23 Thread Azael Avalos
A previuos patch added WWAN support to the driver, allowing to query
and set the device status.

This patch adds RFKill support for the recently introduced WWAN device,
making use of the WWAN and *wireless_status functions to query the
killswitch and (de)activate the device accordingly to its status.

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

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index dfa760d..f65e003 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -51,6 +51,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -174,6 +175,7 @@ struct toshiba_acpi_dev {
struct led_classdev kbd_led;
struct led_classdev eco_led;
struct miscdevice miscdev;
+   struct rfkill *wwan_rfk;
 
int force_fan;
int last_key_event;
@@ -2347,6 +2349,67 @@ static const struct file_operations toshiba_acpi_fops = {
 };
 
 /*
+ * WWAN RFKill handlers
+ */
+static int toshiba_acpi_wwan_set_block(void *data, bool blocked)
+{
+   struct toshiba_acpi_dev *dev = data;
+   int ret;
+
+   ret = toshiba_wireless_status(dev);
+   if (ret)
+   return ret;
+
+   if (!dev->killswitch)
+   return 0;
+
+   return toshiba_wwan_set(dev, !blocked);
+}
+
+static void toshiba_acpi_wwan_poll(struct rfkill *rfkill, void *data)
+{
+   struct toshiba_acpi_dev *dev = data;
+
+   if (toshiba_wireless_status(dev))
+   return;
+
+   rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
+}
+
+static const struct rfkill_ops wwan_rfk_ops = {
+   .set_block = toshiba_acpi_wwan_set_block,
+   .poll = toshiba_acpi_wwan_poll,
+};
+
+static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
+{
+   int ret = toshiba_wireless_status(dev);
+
+   if (ret)
+   return ret;
+
+   dev->wwan_rfk = rfkill_alloc("Toshiba WWAN",
+>acpi_dev->dev,
+RFKILL_TYPE_WWAN,
+_rfk_ops,
+dev);
+   if (!dev->wwan_rfk) {
+   pr_err("Unable to allocate WWAN rfkill device\n");
+   return -ENOMEM;
+   }
+
+   rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
+
+   ret = rfkill_register(dev->wwan_rfk);
+   if (ret) {
+   pr_err("Unable to register WWAN rfkill device\n");
+   rfkill_destroy(dev->wwan_rfk);
+   }
+
+   return ret;
+}
+
+/*
  * Hotkeys
  */
 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
@@ -2705,6 +2768,11 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
if (dev->eco_led_registered)
led_classdev_unregister(>eco_led);
 
+   if (dev->wwan_rfk) {
+   rfkill_unregister(dev->wwan_rfk);
+   rfkill_destroy(dev->wwan_rfk);
+   }
+
if (toshiba_acpi)
toshiba_acpi = NULL;
 
@@ -2844,6 +2912,8 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->fan_supported = !ret;
 
toshiba_wwan_available(dev);
+   if (dev->wwan_supported)
+   toshiba_acpi_setup_wwan_rfkill(dev);
 
print_supported_features(dev);
 
@@ -2941,12 +3011,15 @@ static int toshiba_acpi_resume(struct device *device)
struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
 
if (dev->hotkey_dev) {
-   int error = toshiba_acpi_enable_hotkeys(dev);
-
-   if (error)
+   if (toshiba_acpi_enable_hotkeys(dev))
pr_info("Unable to re-enable hotkeys\n");
}
 
+   if (dev->wwan_rfk) {
+   if (!toshiba_wireless_status(dev))
+   rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
+   }
+
return 0;
 }
 #endif
-- 
2.6.3

--
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/2] toshiba_acpi: Add WWAN support

2015-11-23 Thread Azael Avalos
These two patches add WWAN support to the driver, the first adds the actual
support functions and the second adds RFKill handler functions to set the
device status according to the killswitch.

Changes since v2:
- Changed code according to review comments

Changes since v1:
- Added missing calls to rfkill_unregister and rfkill_destroy functions

Azael Avalos (2):
  toshiba_acpi: Add support for WWAN devices
  toshiba_acpi: Add WWAN RFKill support

 drivers/platform/x86/toshiba_acpi.c | 188 +++-
 1 file changed, 185 insertions(+), 3 deletions(-)

-- 
2.6.3

--
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/2] toshiba_acpi: Add WWAN RFKill support

2015-11-23 Thread Azael Avalos
A previuos patch added WWAN support to the driver, allowing to query
and set the device status.

This patch adds RFKill support for the recently introduced WWAN device,
making use of the WWAN and *wireless_status functions to query the
killswitch and (de)activate the device accordingly to its status.

Signed-off-by: Fabian Koester <fabian.koes...@bringnow.com>
Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
 drivers/platform/x86/toshiba_acpi.c | 79 +++--
 1 file changed, 76 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index dfa760d..f65e003 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -51,6 +51,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -174,6 +175,7 @@ struct toshiba_acpi_dev {
struct led_classdev kbd_led;
struct led_classdev eco_led;
struct miscdevice miscdev;
+   struct rfkill *wwan_rfk;
 
int force_fan;
int last_key_event;
@@ -2347,6 +2349,67 @@ static const struct file_operations toshiba_acpi_fops = {
 };
 
 /*
+ * WWAN RFKill handlers
+ */
+static int toshiba_acpi_wwan_set_block(void *data, bool blocked)
+{
+   struct toshiba_acpi_dev *dev = data;
+   int ret;
+
+   ret = toshiba_wireless_status(dev);
+   if (ret)
+   return ret;
+
+   if (!dev->killswitch)
+   return 0;
+
+   return toshiba_wwan_set(dev, !blocked);
+}
+
+static void toshiba_acpi_wwan_poll(struct rfkill *rfkill, void *data)
+{
+   struct toshiba_acpi_dev *dev = data;
+
+   if (toshiba_wireless_status(dev))
+   return;
+
+   rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
+}
+
+static const struct rfkill_ops wwan_rfk_ops = {
+   .set_block = toshiba_acpi_wwan_set_block,
+   .poll = toshiba_acpi_wwan_poll,
+};
+
+static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
+{
+   int ret = toshiba_wireless_status(dev);
+
+   if (ret)
+   return ret;
+
+   dev->wwan_rfk = rfkill_alloc("Toshiba WWAN",
+>acpi_dev->dev,
+RFKILL_TYPE_WWAN,
+_rfk_ops,
+dev);
+   if (!dev->wwan_rfk) {
+   pr_err("Unable to allocate WWAN rfkill device\n");
+   return -ENOMEM;
+   }
+
+   rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
+
+   ret = rfkill_register(dev->wwan_rfk);
+   if (ret) {
+   pr_err("Unable to register WWAN rfkill device\n");
+   rfkill_destroy(dev->wwan_rfk);
+   }
+
+   return ret;
+}
+
+/*
  * Hotkeys
  */
 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
@@ -2705,6 +2768,11 @@ static int toshiba_acpi_remove(struct acpi_device 
*acpi_dev)
if (dev->eco_led_registered)
led_classdev_unregister(>eco_led);
 
+   if (dev->wwan_rfk) {
+   rfkill_unregister(dev->wwan_rfk);
+   rfkill_destroy(dev->wwan_rfk);
+   }
+
if (toshiba_acpi)
toshiba_acpi = NULL;
 
@@ -2844,6 +2912,8 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
dev->fan_supported = !ret;
 
toshiba_wwan_available(dev);
+   if (dev->wwan_supported)
+   toshiba_acpi_setup_wwan_rfkill(dev);
 
print_supported_features(dev);
 
@@ -2941,12 +3011,15 @@ static int toshiba_acpi_resume(struct device *device)
struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
 
if (dev->hotkey_dev) {
-   int error = toshiba_acpi_enable_hotkeys(dev);
-
-   if (error)
+   if (toshiba_acpi_enable_hotkeys(dev))
pr_info("Unable to re-enable hotkeys\n");
}
 
+   if (dev->wwan_rfk) {
+   if (!toshiba_wireless_status(dev))
+   rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
+   }
+
return 0;
 }
 #endif
-- 
2.6.3

--
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/2] toshiba_acpi: Add WWAN support

2015-11-23 Thread Azael Avalos
These two patches add WWAN support to the driver, the first adds the actual
support functions and the second adds RFKill handler functions to set the
device status according to the killswitch.

Changes since v2:
- Changed code according to review comments

Changes since v1:
- Added missing calls to rfkill_unregister and rfkill_destroy functions

Azael Avalos (2):
  toshiba_acpi: Add support for WWAN devices
  toshiba_acpi: Add WWAN RFKill support

 drivers/platform/x86/toshiba_acpi.c | 188 +++-
 1 file changed, 185 insertions(+), 3 deletions(-)

-- 
2.6.3

--
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/2] toshiba_acpi: Add support for WWAN devices

2015-11-23 Thread Azael Avalos
Toshiba laptops with WWAN devices installed cannot use the device unless
it is attached and powered, similar to how Toshiba Bluetooth devices
work.

This patch adds support to WWAN devices, introducing three functions,
one to query the overall status of the wireless devices (RFKill, WLAN,
BT, WWAN), the second queries WWAN support, and finally the third
(de)activates the device.

Signed-off-by: Fabian Koester <fabian.koes...@bringnow.com>
Signed-off-by: Azael Avalos <coproscef...@gmail.com>ZZ
---
 drivers/platform/x86/toshiba_acpi.c | 109 
 1 file changed, 109 insertions(+)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index c013029..dfa760d 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -114,6 +114,7 @@ MODULE_LICENSE("GPL");
 #define HCI_VIDEO_OUT  0x001c
 #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
@@ -148,6 +149,10 @@ MODULE_LICENSE("GPL");
 #define SCI_KBD_MODE_ON0x8
 #define SCI_KBD_MODE_OFF   0x10
 #define SCI_KBD_TIME_MAX   0x3c001a
+#define HCI_WIRELESS_STATUS0x1
+#define HCI_WIRELESS_WWAN  0x3
+#define HCI_WIRELESS_WWAN_STATUS   0x2000
+#define HCI_WIRELESS_WWAN_POWER0x4000
 #define SCI_USB_CHARGE_MODE_MASK   0xff
 #define SCI_USB_CHARGE_DISABLED0x00
 #define SCI_USB_CHARGE_ALTERNATE   0x09
@@ -197,12 +202,14 @@ struct toshiba_acpi_dev {
unsigned int kbd_function_keys_supported:1;
unsigned int panel_power_on_supported:1;
unsigned int usb_three_supported:1;
+   unsigned int wwan_supported:1;
unsigned int sysfs_created:1;
unsigned int special_functions;
 
bool kbd_led_registered;
bool illumination_led_registered;
bool eco_led_registered;
+   bool killswitch;
 };
 
 static struct toshiba_acpi_dev *toshiba_acpi;
@@ -1085,6 +1092,104 @@ static int toshiba_hotkey_event_type_get(struct 
toshiba_acpi_dev *dev,
return -EIO;
 }
 
+/* Wireless status (RFKill, WLAN, BT, WWAN) */
+static int toshiba_wireless_status(struct toshiba_acpi_dev *dev)
+{
+   u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   in[3] = HCI_WIRELESS_STATUS;
+   status = tci_raw(dev, in, out);
+
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to get Wireless status failed\n");
+   return -EIO;
+   }
+
+   if (out[0] == TOS_NOT_SUPPORTED)
+   return -ENODEV;
+
+   if (out[0] != TOS_SUCCESS)
+   return -EIO;
+
+   dev->killswitch = !!(out[2] & HCI_WIRELESS_STATUS);
+
+   return 0;
+}
+
+/* WWAN */
+static void toshiba_wwan_available(struct toshiba_acpi_dev *dev)
+{
+   u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   dev->wwan_supported = 0;
+
+   /*
+* WWAN support can be queried by setting the in[3] value to
+* HCI_WIRELESS_WWAN (0x03).
+*
+* If supported, out[0] contains TOS_SUCCESS and out[2] contains
+* HCI_WIRELESS_WWAN_STATUS (0x2000).
+*
+* If not supported, out[0] contains TOS_INPUT_DATA_ERROR (0x8300)
+* or TOS_NOT_SUPPORTED (0x8000).
+*/
+   in[3] = HCI_WIRELESS_WWAN;
+   status = tci_raw(dev, in, out);
+
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to get WWAN status failed\n");
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->wwan_supported = (out[2] == HCI_WIRELESS_WWAN_STATUS);
+}
+
+static int toshiba_wwan_set(struct toshiba_acpi_dev *dev, u32 state)
+{
+   u32 in[TCI_WORDS] = { HCI_SET, HCI_WIRELESS, state, 0, 0, 0 };
+   u32 out[TCI_WORDS];
+   acpi_status status;
+
+   in[3] = HCI_WIRELESS_WWAN_STATUS;
+   status = tci_raw(dev, in, out);
+
+   if (ACPI_FAILURE(status)) {
+   pr_err("ACPI call to set WWAN status failed\n");
+   return -EIO;
+   }
+
+   if (out[0] == TOS_NOT_SUPPORTED)
+   return -ENODEV;
+
+   if (out[0] != TOS_SUCCESS)
+   return -EIO;
+
+   /*
+* Some devices only need to call HCI_WIRELESS_WWAN_STATUS to
+* (de)activate the device, but some others need the
+* HCI_WIRELESS_WWAN_POWER call as well.
+*/
+   in[3] = HCI_WIRELESS_WWAN_POWER;
+   status = tci_raw(dev, in, out);
+
+   if (ACPI_FAILURE(status)) {
+   

[PATCH v2] toshiba_acpi: Fix keyboard backight sysfs entries not being updated

2015-11-23 Thread Azael Avalos
Certain Toshiba models with the second generation keyboard backlight
(type 2) do not generate the keyboard backlight changed event (0x92),
and thus, the sysfs entries are never being updated.

This patch adds a workquee and a global boolean variable to address
the issue.

For those models that do generate the event, the sysfs entries are
being updated via the *notify function and the boolean is set to
true to avoid a second call to update the entries.

For those models that do not generate the event, the workquee is
used to update the sysfs entries and also to emulate the event via
netlink, to make userspace aware of such change.

Signed-off-by: Azael Avalos <coproscef...@gmail.com>
---
Changes since v1:
- Moved the implementation of the toshiba_acpi_kbd_bl_work function further down
  to make the file compile

 drivers/platform/x86/toshiba_acpi.c | 47 +
 1 file changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index df2612e..410bacc 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -206,6 +206,7 @@ struct toshiba_acpi_dev {
unsigned int sysfs_created:1;
unsigned int special_functions;
 
+   bool kbd_event_generated;
bool kbd_led_registered;
bool illumination_led_registered;
bool eco_led_registered;
@@ -523,6 +524,7 @@ static void toshiba_kbd_illum_available(struct 
toshiba_acpi_dev *dev)
 
dev->kbd_illum_supported = 0;
dev->kbd_led_registered = false;
+   dev->kbd_event_generated = false;
 
if (!sci_open(dev))
return;
@@ -1642,6 +1644,11 @@ static const struct backlight_ops toshiba_backlight_data 
= {
.update_status  = set_lcd_status,
 };
 
+/* Keyboard backlight work */
+static void toshiba_acpi_kbd_bl_work(struct work_struct *work);
+
+static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work);
+
 /*
  * Sysfs files
  */
@@ -1741,6 +1748,24 @@ static ssize_t kbd_backlight_mode_store(struct device 
*dev,
return ret;
 
toshiba->kbd_mode = mode;
+
+   /*
+* Some laptop models with the second generation backlit
+* keyboard (type 2) do not generate the keyboard backlight
+* changed event (0x92), and thus, the driver will never update
+* the sysfs entries.
+*
+* The event is generated right when changing the keyboard
+* backlight mode and the *notify function will set the
+* kbd_event_generated to true.
+*
+* In case the event is not generated, schedule the keyboard
+* backlight work to update the sysfs entries and emulate the
+* event via genetlink.
+*/
+   if (toshiba->kbd_type == 2 &&
+   !toshiba_acpi->kbd_event_generated)
+   schedule_work(_bl_work);
}
 
return count;
@@ -2273,6 +2298,21 @@ static struct attribute_group toshiba_attr_group = {
.attrs = toshiba_attributes,
 };
 
+static void toshiba_acpi_kbd_bl_work(struct work_struct *work)
+{
+   struct acpi_device *acpi_dev = toshiba_acpi->acpi_dev;
+
+   /* Update the sysfs entries */
+   if (sysfs_update_group(_dev->dev.kobj,
+  _attr_group))
+   pr_err("Unable to update sysfs entries\n");
+
+   /* Emulate the keyboard backlight event */
+   acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
+   dev_name(_dev->dev),
+   0x92, 0);
+}
+
 /*
  * Misc device
  */
@@ -2871,7 +2911,6 @@ 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 */
@@ -2901,10 +2940,10 @@ static void toshiba_acpi_notify(struct acpi_device 
*acpi_dev, u32 event)
pr_info("SATA power event received %x\n", event);
break;
case 0x92: /* Keyboard backlight mode changed */
+   toshiba_acpi->kbd_event_generated = true;
/* Update sysfs entries */
-   ret = sysfs_update_group(_dev->dev.kobj,
-_attr_group);
-   if (ret)
+   if (sysfs_update_group(_dev->dev.kobj,
+  _attr_group))
pr_err("Unable to update sysfs entries\n");
break;
case 0x85: /* Unknown */
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to

Re: [PATCH 1/1] toshiba_acpi: Propagate the hotkey value via genetlink

2015-11-20 Thread Azael Avalos
Hi Darren,

2015-11-20 16:19 GMT-07:00 Darren Hart :
> On Sun, Nov 15, 2015 at 08:33:46PM -0700, Azael Avalos wrote:
>> The driver uses genetlink to inform userspace of events generated by
>> the system, but the data passed is always zero as there is no data to
>> pass, except for the hotkey event.
>>
>> This patch propagates the hotkey value via genetlink so userspace can
>> make use of it.
>
> Which keys were not working previously?

It's not about the keys, but the "extra events" generated, I still do not
know why Toshiba sent system events inside the hotkey event (maybe
they ran out of numbers...).

>
> My concern is that we introduce new events that then get "double handled".
>

Well, the events are already being generated, but they are Toshiba specific
events, the only thing here that changed is that now we pass the hotkey value
to userspace, and as said, some of the system events that were not passed
before and are not handled at all.

A good example here are the 0x1ABE and 0x1ABF events, which fire (on
certain laptops) when the HDD protection level changes and is disabled
respectively.

There a re a lot of unknown events that are being sent as hotkeys, but
I still have to ideintify them :-(

> Some more context about the problem experienced and how this resolves it would
> be helpful.
>
> Thanks,
>

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] toshiba_acpi: Fix keyboard backight sysfs entries not being updated

2015-11-20 Thread Azael Avalos
Hi Darren,

2015-11-20 16:39 GMT-07:00 Darren Hart :
> On Mon, Nov 16, 2015 at 12:59:31PM -0700, Azael Avalos wrote:
>> Certain Toshiba models with the second generation keyboard backlight
>> (type 2) do not generate the keyboard backlight changed event (0x92),
>> and thus, the sysfs entries are never being updated.
>>
>> This patch adds a workquee and a global boolean variable to address
>> the issue.
>>
>> For those models that do generate the event, the sysfs entries are
>> being updated via the *notify function and the boolean is set to
>> true to avoid a second call to update the entries.
>>
>> For those models that do not generate the event, the workquee is
>> used to update the sysfs entries and also to emulate the event via
>> netlink, to make userspace aware of such change.
>
> Thanks Azael,
>
> Rather than ask you to wait while I research workqueues and their use more, 
> what
> is it about this task that requires a workqueue? Why can we not call what's in
> the workqueue below directly from the kbd_backlight_mode_store sysfs write
> callback?

I used the workquee to let the sysfs *store function to finish w/o affecting
the "refresh" of the sysfs entries.

Previously the sysfs_update_group resided inside the *store function,
but caused a lock everytime the keyboard mode was changed, and the
sysfs entries were never updated, this was fixed by moving such function
to the *notify function, but turns out that some models do not fire such
event.


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] toshiba_acpi: Fix blank screen at boot if transflective backlight is supported

2015-11-20 Thread Azael Avalos
Hi Darren,

2015-11-20 16:16 GMT-07:00 Darren Hart :
> On Sun, Nov 15, 2015 at 08:32:47PM -0700, Azael Avalos wrote:
>> If transflective backlight is supported and the brightness is zero
>> (lowest brightness level), the set_lcd_brightness function will activate
>> the transflective backlight, making the LCD appear to be turned off.
>>
>> This patch fixes the issue by incrementing the brightness level, and
>> by doing so, avoiding the activation of the tranflective backlight.
>
> So... I'm not sure this is a bug or even wrong behavior. The lowest setting on
> my Thinkpad Yoga 12 is also "off" in Linux. Same is true for my Mac Book Pro 
> (in
> Mac OS X).

Yeah, and even on "regular" (with non transflective backlight) Toshibas
zero is also "off" and no problem is observed.

>
> From what I can tell, what this patch does is merely disable the lowest 
> setting.

Nope, we are just not letting the driver enable transflective backlight
and continue using the "normal" brightness range.

>
> What is it about this behavior that is considered to be wrong?
>

The problem is with laptops with transflective backlight support.

The code for transflective backlight is fused with the LCD backlight
code (go figure...), so if a Toshiba laptop with transflective support
is detected, the max brightness levels are raised by one.

A regular laptop's brightness levels are 0-7, but on a laptop with
transflective support, the brightness levels are 0-8, zero being
"activate transflective backlight" and 1-8 the regular brightness
levels.

So, when a laptop with transflective support AND an initial
brightness level of zero gets probed for backlight support,
the set_lcd_brightness function activates the transfective
backlight, as the brightness levels are still not incremented,
and thus, the screen goes dark.


I hope this clarifies a bit the situation here.


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/2] toshiba_acpi: Add WWAN RFKill support

2015-11-20 Thread Azael Avalos
Hi Darren,

2015-11-20 15:50 GMT-07:00 Darren Hart :
> On Thu, Nov 19, 2015 at 08:49:25AM -0700, Azael Avalos wrote:
>
> Hi Azael,
>
>> A previuos patch added WWAN support to the driver, allowing to query
>> and set the device status.
>>
>> This patch adds RFKill support for the recently introduced WWAN device,
>> making use of the WWAN and *wireless_status functions to query the
>> killswitch and (de)activate the device accordingly to its status.
>>
>> Signed-off-by: Fabian Koester 
>
> So this is Fabian's code which he sent to you and you are submitting on his
> behalf?

Yes, he sent me the code for review, but made some changes to the
actual code he sent me (mostly patch 01), sent back to him the resulting
changes for testing, and I told him I was gonna submmit the changes :-)

>
>> Signed-off-by: Azael Avalos 
>
>
> A couple minor nits below.
>
>> ---
>>  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 60d1ad9..d1315c5 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -51,6 +51,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>
>> @@ -174,6 +175,7 @@ struct toshiba_acpi_dev {
>>   struct led_classdev kbd_led;
>>   struct led_classdev eco_led;
>>   struct miscdevice miscdev;
>> + struct rfkill *wwan_rfk;
>>
>>   int force_fan;
>>   int last_key_event;
>> @@ -2330,6 +2332,67 @@ static const struct file_operations toshiba_acpi_fops 
>> = {
>>  };
>>
>>  /*
>> + * WWAN RFKill handlers
>> + */
>> +static int toshiba_acpi_wwan_set_block(void *data, bool blocked)
>> +{
>> + struct toshiba_acpi_dev *dev = data;
>> + int ret;
>> +
>> + ret = toshiba_wireless_status(dev);
>> + if (ret)
>> + return ret;
>> +
>> + if (!dev->killswitch)
>> + return 0;
>> +
>> + return toshiba_wwan_set(dev, blocked ? 0 : 1);
>
> You can avoid the ternary operation with binary output and just invert the
> bool.
>
> !blocked

OK, will do.

>
>
>> +}
>> +
>> +static void toshiba_acpi_wwan_poll(struct rfkill *rfkill, void *data)
>> +{
>> + struct toshiba_acpi_dev *dev = data;
>> +
>> + if (toshiba_wireless_status(dev))
>> + return;
>> +
>> + rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
>> +}
>> +
>> +static const struct rfkill_ops wwan_rfk_ops = {
>> + .set_block = toshiba_acpi_wwan_set_block,
>> + .poll = toshiba_acpi_wwan_poll,
>> +};
>> +
>> +static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
>> +{
>> + int ret = toshiba_wireless_status(dev);
>> +
>> + if (ret)
>> + return ret;
>> +
>> + dev->wwan_rfk = rfkill_alloc("Toshiba WWAN",
>> +  >acpi_dev->dev,
>> +  RFKILL_TYPE_WWAN,
>> +  _rfk_ops,
>> +  dev);
>> + if (!dev->wwan_rfk) {
>> + pr_err("Unable to allocate WWAN rfkill device\n");
>> + return -ENOMEM;
>> + }
>> +
>> + rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
>> +
>> + ret = rfkill_register(dev->wwan_rfk);
>> + if (ret) {
>> + pr_err("Unable to register WWAN rfkill device\n");
>> + rfkill_destroy(dev->wwan_rfk);
>> + }
>> +
>> + return ret;
>> +}
>> +
>> +/*
>>   * Hotkeys
>>   */
>>  static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
>> @@ -2688,6 +2751,11 @@ static int toshiba_acpi_remove(struct acpi_device 
>> *acpi_dev)
>>   if (dev->eco_led_registered)
>>   led_classdev_unregister(>eco_led);
>>
>> + if (dev->wwan_rfk) {
>> + rfkill_unregister(dev->wwan_rfk);
>> + rfkill_destroy(dev->wwan_rfk);
>> + }
>> +
>>   if (toshiba_acpi)
>>   toshiba_acpi = NULL;
>>
>> @@ -2827,6 +2895,8 @@ static int toshiba_acpi_add(struct acpi_device 
>> *acpi_dev)
>>   dev->fan_sup

Re: [PATCH v2 1/2] toshiba_acpi: Add support for WWAN devices

2015-11-20 Thread Azael Avalos
Hi Darren,

2015-11-20 15:49 GMT-07:00 Darren Hart :
> On Thu, Nov 19, 2015 at 08:49:24AM -0700, Azael Avalos wrote:
>> Toshiba laptops with WWAN devices installed cannot use the device unless
>> it is attached and powered, similar to how Toshiba Bluetooth devices
>> work.
>>
>> This patch adds support to WWAN devices, introducing three functions,
>> one to query the overall status of the wireless devices (RFKill, WLAN,
>> BT, WWAN), the second queries WWAN support, and finally the third
>> (de)activates the device.
>>
>> Signed-off-by: Fabian Koester 
>> Signed-off-by: Azael Avalos 
>
> Thanks Azael,
>
> A few comments on code flow and one bug I think below.
>
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 92 
>> +
>>  1 file changed, 92 insertions(+)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c 
>> b/drivers/platform/x86/toshiba_acpi.c
>> index c013029..60d1ad9 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -114,6 +114,7 @@ MODULE_LICENSE("GPL");
>>  #define HCI_VIDEO_OUT0x001c
>>  #define HCI_HOTKEY_EVENT 0x001e
>>  #define HCI_LCD_BRIGHTNESS   0x002a
>> +#define HCI_WIRELESS 0x0056
>>  #define HCI_ACCELEROMETER0x006d
>>  #define HCI_KBD_ILLUMINATION 0x0095
>>  #define HCI_ECO_MODE 0x0097
>> @@ -148,6 +149,10 @@ MODULE_LICENSE("GPL");
>>  #define SCI_KBD_MODE_ON  0x8
>>  #define SCI_KBD_MODE_OFF 0x10
>>  #define SCI_KBD_TIME_MAX 0x3c001a
>> +#define HCI_WIRELESS_STATUS  0x1
>> +#define HCI_WIRELESS_WWAN0x3
>> +#define HCI_WIRELESS_WWAN_STATUS 0x2000
>> +#define HCI_WIRELESS_WWAN_POWER  0x4000
>>  #define SCI_USB_CHARGE_MODE_MASK 0xff
>>  #define SCI_USB_CHARGE_DISABLED  0x00
>>  #define SCI_USB_CHARGE_ALTERNATE 0x09
>> @@ -197,12 +202,14 @@ struct toshiba_acpi_dev {
>>   unsigned int kbd_function_keys_supported:1;
>>   unsigned int panel_power_on_supported:1;
>>   unsigned int usb_three_supported:1;
>> + unsigned int wwan_supported:1;
>>   unsigned int sysfs_created:1;
>>   unsigned int special_functions;
>>
>>   bool kbd_led_registered;
>>   bool illumination_led_registered;
>>   bool eco_led_registered;
>> + bool killswitch;
>>  };
>>
>>  static struct toshiba_acpi_dev *toshiba_acpi;
>> @@ -1085,6 +1092,87 @@ static int toshiba_hotkey_event_type_get(struct 
>> toshiba_acpi_dev *dev,
>>   return -EIO;
>>  }
>>
>> +/* Wireless status (RFKill, WLAN, BT, WWAN) */
>> +static int toshiba_wireless_status(struct toshiba_acpi_dev *dev)
>> +{
>> + u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
>> + u32 out[TCI_WORDS];
>> + acpi_status status;
>> +
>> + in[3] = HCI_WIRELESS_STATUS;
>> + status = tci_raw(dev, in, out);
>> + if (ACPI_FAILURE(status)) {
>> + pr_err("ACPI call to get Wireless status failed\n");
>> + } else if (out[0] == TOS_NOT_SUPPORTED) {
>> + return -ENODEV;
>> + } else if (out[0] == TOS_SUCCESS) {
>> + dev->killswitch =
>> + (out[2] & HCI_WIRELESS_STATUS) ? true : false;
>
> This should assign successfully without the need for the ternary operator. You
> can also then drop the extra newline. You can always use:
>
> !!(out[2] & HCI_WIRELESS_STATUS)
>
> To ensure a 1 or 0 assignment.

OK, will change on v3.

>
>> + return 0;
>> + }
>> +
>> + return -EIO;
>
> Also, we should be testing for error and do the expected path outside the if
> blocks.
>
>
> if (ACPI_FAILURE(status) {
> pr_err("ACPI call to get Wireless status failed\n");
> return -EIO;
> }
>
> if (out[0] == TOS_NOT_SUPPORTED)
> return -ENODEV;
>
> if (out[0] != TOS_SUCCESS)
> return -EIO;
>
> dev->killswitch = !!(out[2] & HCI_WIRELESS_STATUS);
>
> return 0;
>

OK, will change the functions to this style on v3.

>> +}
>> +
>> +/* WWAN */
>> +static void toshiba_wwan_available(struct toshiba_acpi_dev *dev)
>> +{
>> + u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
>> + u32 out[T

Re: [PATCH] toshiba_acpi: Fix blank screen at boot if transflective backlight is supported

2015-11-20 Thread Azael Avalos
Hi Darren,

2015-11-20 16:16 GMT-07:00 Darren Hart <dvh...@infradead.org>:
> On Sun, Nov 15, 2015 at 08:32:47PM -0700, Azael Avalos wrote:
>> If transflective backlight is supported and the brightness is zero
>> (lowest brightness level), the set_lcd_brightness function will activate
>> the transflective backlight, making the LCD appear to be turned off.
>>
>> This patch fixes the issue by incrementing the brightness level, and
>> by doing so, avoiding the activation of the tranflective backlight.
>
> So... I'm not sure this is a bug or even wrong behavior. The lowest setting on
> my Thinkpad Yoga 12 is also "off" in Linux. Same is true for my Mac Book Pro 
> (in
> Mac OS X).

Yeah, and even on "regular" (with non transflective backlight) Toshibas
zero is also "off" and no problem is observed.

>
> From what I can tell, what this patch does is merely disable the lowest 
> setting.

Nope, we are just not letting the driver enable transflective backlight
and continue using the "normal" brightness range.

>
> What is it about this behavior that is considered to be wrong?
>

The problem is with laptops with transflective backlight support.

The code for transflective backlight is fused with the LCD backlight
code (go figure...), so if a Toshiba laptop with transflective support
is detected, the max brightness levels are raised by one.

A regular laptop's brightness levels are 0-7, but on a laptop with
transflective support, the brightness levels are 0-8, zero being
"activate transflective backlight" and 1-8 the regular brightness
levels.

So, when a laptop with transflective support AND an initial
brightness level of zero gets probed for backlight support,
the set_lcd_brightness function activates the transfective
backlight, as the brightness levels are still not incremented,
and thus, the screen goes dark.


I hope this clarifies a bit the situation here.


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/


  1   2   3   4   5   6   7   >