public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] toshiba_acpi: Adapt kbd_bl_timeout_store to the new kbd type
@ 2014-09-30  2:57 Azael Avalos
  2014-10-02 18:32 ` Darren Hart
  0 siblings, 1 reply; 4+ messages in thread
From: Azael Avalos @ 2014-09-30  2:57 UTC (permalink / raw)
  To: Darren Hart, platform-driver-x86, linux-kernel; +Cc: Azael Avalos

With the introduccion of the new keyboard backlight
implementation, the *_timeout_store function is
broken, as it only supports the first kbd_type.

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

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

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-10-04  6:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-30  2:57 [PATCH] toshiba_acpi: Adapt kbd_bl_timeout_store to the new kbd type Azael Avalos
2014-10-02 18:32 ` Darren Hart
2014-10-02 20:02   ` Azael Avalos
2014-10-04  6:57     ` Darren Hart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox