Skip to contentSkip to conversation

toshiba_acpi: Fix USB Sleep & Charge mode and documentation updates

PATCH Superseded Azael Avalos 2 participants 5 messages Mar 30, 2015 – Apr 3, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Azael Avalos

author maintainer
#0 lore raw

v2 cover toshiba_acpi: Fix USB Sleep & Charge mode and documentation updates

This patch fixes the USB Sleep & Charge charging mode on certain models, fixes pr_* messages and also adds the missing entries in the documentation file.

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

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

 .../ABI/testing/sysfs-driver-toshiba_acpi          | 93 +++++++++++++++++++---
 drivers/platform/x86/toshiba_acpi.c                | 85 ++++++++++++++++----
 2 files changed, 148 insertions(+), 30 deletions(-)
Signature · 1 line
2.2.2
author maintainer
#1 lore raw

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

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

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

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

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

Quoted 53 lines · Azael Avalos

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

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

---
 drivers/platform/x86/toshiba_acpi.c | 69 ++++++++++++++++++++++++++++++++-----
 1 file changed, 60 insertions(+), 9 deletions(-)
drivers/platform/x86/toshiba_acpi.c +17 -3
index 17a259e..c8ad61c 100644
@@ -150,9 +150,10 @@ MODULE_LICENSE("GPL");
 #define SCI_KBD_MODE_OFF		0x10
 #define SCI_KBD_TIME_MAX		0x3c001a
 #define SCI_USB_CHARGE_MODE_MASK	0xff
-#define SCI_USB_CHARGE_DISABLED		0x30000
-#define SCI_USB_CHARGE_ALTERNATE	0x30009
-#define SCI_USB_CHARGE_AUTO		0x30021
+#define SCI_USB_CHARGE_DISABLED		0x00
+#define SCI_USB_CHARGE_ALTERNATE	0x09
+#define SCI_USB_CHARGE_TYPICAL		0x11
+#define SCI_USB_CHARGE_AUTO		0x21
 #define SCI_USB_CHARGE_BAT_MASK		0x7
 #define SCI_USB_CHARGE_BAT_LVL_OFF	0x1
 #define SCI_USB_CHARGE_BAT_LVL_ON	0x4
@@ -177,6 +178,7 @@ struct toshiba_acpi_dev {
 	int kbd_mode;
 	int kbd_time;
 	int usbsc_bat_level;
+	int usbsc_mode_base;
 	int hotkey_event_type;
 
 	unsigned int illumination_supported:1;
@@ -800,6 +802,52 @@ static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
 }
 
 /* Sleep (Charge and Music) utilities support */
+static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
+{
+	u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+	u32 out[TCI_WORDS];
+	acpi_status status;
+
+	/* Set the feature to "not supported" in case of error */
+	dev->usb_sleep_charge_supported = 0;
+
+	if (!sci_open(dev))
+		return;
+

drivers/platform/x86/toshiba_acpi.c static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, · line 826

Quoted 10 lines
drivers/platform/x86/toshiba_acpi.c +10 -0
+	status = tci_raw(dev, in, out);
+	if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+		pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
+		sci_close(dev);
+		return;
+	} else if (out[0] == TOS_NOT_SUPPORTED) {
+		pr_info("USB Sleep and Charge not supported\n");
+		sci_close(dev);
+		return;
+	}

Sorry Azael for not asking the first time, and maybe this is just how it is - but it occurs to me that after the above tci_raw call, we check for 3 error cases, but we never test for success. Can we not check for out[0] == TOS_SUCCESS or similar? The above logic seems like the kind to lead to failure going unnoticed as success is assumed and not confirmed.

drivers/platform/x86/toshiba_acpi.c static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, · line 839

Quoted 13 lines
drivers/platform/x86/toshiba_acpi.c +13 -0
+	dev->usbsc_mode_base = out[4];
+
+	in[5] = SCI_USB_CHARGE_BAT_LVL;
+	status = tci_raw(dev, in, out);
+	if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+		pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
+		sci_close(dev);
+		return;
+	} else if (out[0] == TOS_NOT_SUPPORTED) {
+		pr_info("USB Sleep and Charge not supported\n");
+		sci_close(dev);
+		return;
+	}

Here too.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
author maintainer
#3 lore raw

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

Hi Darren,

2015-04-01 23:21 GMT-06:00 Darren Hart <[email protected]>:

Quoted 62 lines · Azael Avalos
Quoted 61 lines

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

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

---
 drivers/platform/x86/toshiba_acpi.c | 69 ++++++++++++++++++++++++++++++++-----
 1 file changed, 60 insertions(+), 9 deletions(-)
drivers/platform/x86/toshiba_acpi.c +25 -3
index 17a259e..c8ad61c 100644
@@ -150,9 +150,10 @@ MODULE_LICENSE("GPL");
 #define SCI_KBD_MODE_OFF             0x10
 #define SCI_KBD_TIME_MAX             0x3c001a
 #define SCI_USB_CHARGE_MODE_MASK     0xff
-#define SCI_USB_CHARGE_DISABLED              0x30000
-#define SCI_USB_CHARGE_ALTERNATE     0x30009
-#define SCI_USB_CHARGE_AUTO          0x30021
+#define SCI_USB_CHARGE_DISABLED              0x00
+#define SCI_USB_CHARGE_ALTERNATE     0x09
+#define SCI_USB_CHARGE_TYPICAL               0x11
+#define SCI_USB_CHARGE_AUTO          0x21
 #define SCI_USB_CHARGE_BAT_MASK              0x7
 #define SCI_USB_CHARGE_BAT_LVL_OFF   0x1
 #define SCI_USB_CHARGE_BAT_LVL_ON    0x4
@@ -177,6 +178,7 @@ struct toshiba_acpi_dev {
      int kbd_mode;
      int kbd_time;
      int usbsc_bat_level;
+     int usbsc_mode_base;
      int hotkey_event_type;
 
      unsigned int illumination_supported:1;
@@ -800,6 +802,52 @@ static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
 }
 
 /* Sleep (Charge and Music) utilities support */
+static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
+{
+     u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
+     u32 out[TCI_WORDS];
+     acpi_status status;
+
+     /* Set the feature to "not supported" in case of error */
+     dev->usb_sleep_charge_supported = 0;
+
+     if (!sci_open(dev))
+             return;
+
+     status = tci_raw(dev, in, out);
+     if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+             pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
+             sci_close(dev);
+             return;
+     } else if (out[0] == TOS_NOT_SUPPORTED) {
+             pr_info("USB Sleep and Charge not supported\n");
+             sci_close(dev);
Quoted 9 lines

drivers/platform/x86/toshiba_acpi.c static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, · line 826

Quoted 2 lines
drivers/platform/x86/toshiba_acpi.c +2 -0
+             return;
+     }

Sorry Azael for not asking the first time, and maybe this is just how it is - but it occurs to me that after the above tci_raw call, we check for 3 error cases, but we never test for success. Can we not check for out[0] == TOS_SUCCESS or similar? The above logic seems like the kind to lead to failure going unnoticed as success is assumed and not confirmed.

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

Quoted 14 lines

drivers/platform/x86/toshiba_acpi.c static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, · line 839

Quoted 13 lines
drivers/platform/x86/toshiba_acpi.c +13 -0
+     dev->usbsc_mode_base = out[4];
+
+     in[5] = SCI_USB_CHARGE_BAT_LVL;
+     status = tci_raw(dev, in, out);
+     if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
+             pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
+             sci_close(dev);
+             return;
+     } else if (out[0] == TOS_NOT_SUPPORTED) {
+             pr_info("USB Sleep and Charge not supported\n");
+             sci_close(dev);
+             return;
+     }
Quoted 5 lines

Here too.

--
Darren Hart
Intel Open Source Technology Center

Cheers
Azael

Signature · 1 line
-- El mundo apesta y vosotros apestais tambien --
author maintainer
#4 lore raw

PATCH v2 2/3 toshiba_acpi: Fix pr_* messages from USB Sleep Functions

In reply to Azael Avalos

This patch fixes the messages displayed by the USB Sleep Functions, they were printing wrong messages not associated to the feature currently queried.

---
 drivers/platform/x86/toshiba_acpi.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/platform/x86/toshiba_acpi.c +8 -8
index c8ad61c..be755606 100644
@@ -963,11 +963,11 @@ static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
 	status = tci_raw(dev, in, out);
 	sci_close(dev);
 	if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
-		pr_err("ACPI call to get USB S&C battery level failed\n");
+		pr_err("ACPI call to get USB Rapid Charge failed\n");
 		return -EIO;
 	} else if (out[0] == TOS_NOT_SUPPORTED ||
 		   out[0] == TOS_INPUT_DATA_ERROR) {
-		pr_info("USB Sleep and Charge not supported\n");
+		pr_info("USB Rapid Charge not supported\n");
 		return -ENODEV;
 	}
 
@@ -991,10 +991,10 @@ static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
 	status = tci_raw(dev, in, out);
 	sci_close(dev);
 	if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
-		pr_err("ACPI call to set USB S&C battery level failed\n");
+		pr_err("ACPI call to set USB Rapid Charge failed\n");
 		return -EIO;
 	} else if (out[0] == TOS_NOT_SUPPORTED) {
-		pr_info("USB Sleep and Charge not supported\n");
+		pr_info("USB Rapid Charge not supported\n");
 		return -ENODEV;
 	} else if (out[0] == TOS_INPUT_DATA_ERROR) {
 		return -EIO;
@@ -1013,10 +1013,10 @@ static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
 	result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
 	sci_close(dev);
 	if (result == TOS_FAILURE) {
-		pr_err("ACPI call to set USB S&C mode failed\n");
+		pr_err("ACPI call to get Sleep and Music failed\n");
 		return -EIO;
 	} else if (result == TOS_NOT_SUPPORTED) {
-		pr_info("USB Sleep and Charge not supported\n");
+		pr_info("Sleep and Music not supported\n");
 		return -ENODEV;
 	} else if (result == TOS_INPUT_DATA_ERROR) {
 		return -EIO;
@@ -1035,10 +1035,10 @@ static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
 	result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
 	sci_close(dev);
 	if (result == TOS_FAILURE) {
-		pr_err("ACPI call to set USB S&C mode failed\n");
+		pr_err("ACPI call to set Sleep and Music failed\n");
 		return -EIO;
 	} else if (result == TOS_NOT_SUPPORTED) {
-		pr_info("USB Sleep and Charge not supported\n");
+		pr_info("Sleep and Music not supported\n");
 		return -ENODEV;
 	} else if (result == TOS_INPUT_DATA_ERROR) {
 		return -EIO;
Signature · 1 line
2.2.2