X86 platform drivers
 help / color / mirror / Atom feed
From: Marco Chiappero <marco@absence.it>
To: Matthew Garrett <mjg59@srcf.ucam.org>
Cc: platform-driver-x86@vger.kernel.org, Mattia Dongili <malattia@linux.it>
Subject: [PATCH 10/25] sony-laptop: keyboard backlight support extended to newer Vaios
Date: Fri, 03 Jun 2011 17:41:01 +0200	[thread overview]
Message-ID: <4DE9008D.7040504@absence.it> (raw)
In-Reply-To: <4DE8FC4A.9010401@absence.it>

Added support for handle 0x0143 (Vaio SA/SB/SC, CA/CB). Minor 
corrections included.

Signed-off-by: Marco Chiappero <marco@absence.it>
---

--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -127,7 +127,7 @@ MODULE_PARM_DESC(minor,
  		 "default is -1 (automatic)");
  #endif

-static int kbd_backlight;	/* = 1 */
+static int kbd_backlight;	/* = 0 */
  module_param(kbd_backlight, int, 0444);
  MODULE_PARM_DESC(kbd_backlight,
  		 "set this to 0 to disable keyboard backlight, "
@@ -140,15 +140,6 @@ MODULE_PARM_DESC(kbd_backlight_timeout,
  		 "1 for 30 seconds, 2 for 60 seconds and 3 to disable timeout "
  		 "(default: 0)");

-static void sony_nc_kbd_backlight_resume(void);
-
-enum sony_nc_rfkill {
-	SONY_WIFI,
-	SONY_BLUETOOTH,
-	SONY_WWAN,
-	SONY_WIMAX,
-	N_SONY_RFKILL,
-};

  static int sony_rfkill_handle;
  static struct rfkill *sony_rfkill_devices[N_SONY_RFKILL];
@@ -1356,38 +1347,33 @@ static int sony_nc_rfkill_setup(struct a
  }

  /* Keyboard backlight feature */
-#define KBDBL_HANDLER	0x137
-#define KBDBL_PRESENT	0xB00
-#define	SET_MODE	0xC00
-#define SET_STATE	0xD00
-#define SET_TIMEOUT	0xE00
-
  struct kbd_backlight {
-	int mode;
-	int timeout;
+	unsigned int base;
+	unsigned int mode;
+	unsigned int timeout;
  	struct device_attribute mode_attr;
  	struct device_attribute timeout_attr;
  };
-
  static struct kbd_backlight *kbdbl_handle;
+static int sony_kbd_handle = -1;

-static ssize_t __sony_nc_kbd_backlight_mode_set(u8 value)
+static int __sony_nc_kbd_backlight_mode_set(u8 value)
  {
  	unsigned int result;

  	if (value > 1)
  		return -EINVAL;

-	if (sony_call_snc_handle(KBDBL_HANDLER,
-				(value << 0x10) | SET_MODE, &result))
+	if (sony_call_snc_handle(sony_kbd_handle, (value << 0x10) |
+				(kbdbl_handle->base), &result))
  		return -EIO;

-	/* Try to turn the light on/off immediately */
-	sony_call_snc_handle(KBDBL_HANDLER, (value << 0x10) | SET_STATE,
-			&result);
-
  	kbdbl_handle->mode = value;

+	/* Try to turn the light on/off immediately */
+	sony_call_snc_handle(sony_kbd_handle, (value << 0x10) |
+				(kbdbl_handle->base + 0x100), &result);
+
  	return 0;
  }

@@ -1415,7 +1401,9 @@ static ssize_t sony_nc_kbd_backlight_mod
  		struct device_attribute *attr, char *buffer)
  {
  	ssize_t count = 0;
+
  	count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_handle->mode);
+
  	return count;
  }

@@ -1426,8 +1414,8 @@ static int __sony_nc_kbd_backlight_timeo
  	if (value > 3)
  		return -EINVAL;

-	if (sony_call_snc_handle(KBDBL_HANDLER,
-				(value << 0x10) | SET_TIMEOUT, &result))
+	if (sony_call_snc_handle(sony_kbd_handle, (value << 0x10) |
+				(kbdbl_handle->base + 0x200), &result))
  		return -EIO;

  	kbdbl_handle->timeout = value;
@@ -1459,18 +1447,36 @@ static ssize_t sony_nc_kbd_backlight_tim
  		struct device_attribute *attr, char *buffer)
  {
  	ssize_t count = 0;
+
  	count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_handle->timeout);
+
  	return count;
  }

  static int sony_nc_kbd_backlight_setup(struct platform_device *pd)
  {
-	unsigned int result;
+	unsigned int result, base_cmd;
+	bool found = false;

-	if (sony_call_snc_handle(KBDBL_HANDLER, KBDBL_PRESENT, &result))
-		return 0;
-	if (!(result & 0x02))
+	/* verify the kbd backlight presence, some models do not have it */
+	if (sony_kbd_handle == 0x0137) {
+		if (sony_call_snc_handle(sony_kbd_handle, 0x0B00, &result))
+			return -EIO;
+
+		found = !!(result & 0x02);
+		base_cmd = 0x0C00;
+	} else {
+		if (sony_call_snc_handle(sony_kbd_handle, 0x0100, &result))
+			return -EIO;
+
+		found = result & 0x01;
+		base_cmd = 0x4000;
+	}
+
+	if (!found) {
+		dprintk("no backlight keyboard found\n");
  		return 0;
+	}

  	kbdbl_handle = kzalloc(sizeof(*kbdbl_handle), GFP_KERNEL);
  	if (!kbdbl_handle)
@@ -1494,6 +1500,8 @@ static int sony_nc_kbd_backlight_setup(s
  	if (device_create_file(&pd->dev, &kbdbl_handle->timeout_attr))
  		goto outmode;

+	kbdbl_handle->base = base_cmd;
+
  	__sony_nc_kbd_backlight_mode_set(kbd_backlight);
  	__sony_nc_kbd_backlight_timeout_set(kbd_backlight_timeout);

@@ -1516,28 +1524,32 @@ static int sony_nc_kbd_backlight_cleanup
  		device_remove_file(&pd->dev, &kbdbl_handle->timeout_attr);

  		/* restore the default hw behaviour */
-		sony_call_snc_handle(KBDBL_HANDLER, 0x1000 | SET_MODE, &result);
-		sony_call_snc_handle(KBDBL_HANDLER, SET_TIMEOUT, &result);
+		sony_call_snc_handle(sony_kbd_handle,
+				kbdbl_handle->base | 0x10000, &result);
+		sony_call_snc_handle(sony_kbd_handle,
+				kbdbl_handle->base + 0x200, &result);

  		kfree(kbdbl_handle);
+		kbdbl_handle = NULL;
  	}
  	return 0;
  }

  static void sony_nc_kbd_backlight_resume(void)
  {
-	unsigned int ignore = 0;
+	unsigned int result;

  	if (!kbdbl_handle)
  		return;

  	if (kbdbl_handle->mode == 0)
-		sony_call_snc_handle(KBDBL_HANDLER, SET_MODE, &ignore);
+		sony_call_snc_handle(sony_kbd_handle,
+				kbdbl_handle->base, &result);

  	if (kbdbl_handle->timeout != 0)
-		sony_call_snc_handle(KBDBL_HANDLER,
-				(kbdbl_handle->timeout << 0x10) | SET_TIMEOUT,
-				&ignore);
+		sony_call_snc_handle(sony_kbd_handle,
+				(kbdbl_handle->base + 0x200) |
+				(kbdbl_handle->timeout << 0x10), &result);
  }

  static void sony_nc_backlight_ng_read_limits(int handle,
@@ -1676,6 +1688,8 @@ static void sony_nc_snc_setup_handles(st
  			ret = sony_nc_function_setup(handle);
  			break;
  		case 0x0137:
+		case 0x0143:
+			sony_kbd_handle = handle;
  			ret = sony_nc_kbd_backlight_setup(pd);
  			break;
  		case 0x0124:
@@ -1710,6 +1724,7 @@ static void sony_nc_snc_cleanup_handles(

  		switch (handle) {
  		case 0x0137:
+		case 0x0143:
  			sony_nc_kbd_backlight_cleanup(pd);
  			break;
  		case 0x0124:
@@ -1814,6 +1829,7 @@ static int sony_nc_snc_resume(void)
  			sony_nc_rfkill_update();
  			break;
  		case 0x0137: /* kbd + als */
+		case 0x0143:
  			sony_nc_kbd_backlight_resume();
  			break;
  		default:

  parent reply	other threads:[~2011-06-03 15:41 UTC|newest]

Thread overview: 125+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-03 15:22 [PATCH 0/25] sony-laptop: code improvements and support extension for newer Vaios Marco Chiappero
2011-06-03 15:26 ` [PATCH 1/25] sony-laptop: use usigned data type when calling ACPI methods Marco Chiappero
2011-06-03 15:28 ` [PATCH 2/25] sony-laptop: simple_strtoul replaced by strict_strtoul Marco Chiappero
2011-06-12 21:56   ` Mattia Dongili
2011-06-03 15:29 ` [PATCH 3/25] sony-laptop: new ACPI SN06 method helper functions Marco Chiappero
2011-06-03 15:32 ` [PATCH 4/25] sony-laptop: new SNC setup and cleanup functions Marco Chiappero
2011-06-12 22:21   ` Mattia Dongili
2011-06-13  0:01     ` Marco Chiappero
2011-06-13  1:28       ` Mattia Dongili
2011-06-13  9:39         ` Marco Chiappero
2011-06-13 13:42           ` Mattia Dongili
2011-06-13 14:10             ` Marco Chiappero
2011-06-18 22:50               ` Marco Chiappero
2011-06-18 23:06       ` Marco Chiappero
2011-06-28  9:27         ` Mattia Dongili
2011-06-28 10:04           ` Marco Chiappero
2011-07-01 10:54             ` Marco Chiappero
2011-07-13 22:19               ` Marco Chiappero
2011-07-14 22:05                 ` Mattia Dongili
2011-07-18 14:49                   ` Marco Chiappero
2011-07-19 22:03                     ` Mattia Dongili
2011-06-20 13:49     ` Marco Chiappero
2011-06-03 15:33 ` [PATCH 5/25] sony-laptop: new handles " Marco Chiappero
2011-06-03 15:35 ` [PATCH 6/25] sony-laptop: new notebook controller resume function Marco Chiappero
2011-06-03 15:36 ` [PATCH 7/25] sony-laptop: sony_nc_function_setup modifications Marco Chiappero
2011-06-03 15:38 ` [PATCH 8/25] sony-laptop: sony_nc_notify rewritten and improved Marco Chiappero
2011-06-04  8:43   ` Mattia Dongili
2011-06-04 11:26     ` Marco Chiappero
2011-06-05 22:38       ` Mattia Dongili
2011-06-06 12:23         ` Marco Chiappero
2011-06-06 12:42           ` Mattia Dongili
2011-06-06 12:45             ` Marco Chiappero
2011-06-20 14:00         ` Marco Chiappero
2011-07-19 21:30           ` Mattia Dongili
2011-06-04 12:42     ` Matthew Garrett
2011-06-04 14:22       ` Marco Chiappero
2011-06-04 14:30         ` Matthew Garrett
2011-06-04 14:34           ` Marco Chiappero
2011-06-04 14:36             ` Matthew Garrett
2011-06-04 14:42               ` Marco Chiappero
2011-06-04 14:45                 ` Matthew Garrett
2011-06-04 15:04                   ` Corentin Chary
2011-06-04 16:50                     ` Marco Chiappero
2011-06-04 20:22                 ` Alan Cox
2011-06-05 17:48                   ` Marco Chiappero
2011-06-05 19:14                     ` Alan Cox
2011-06-05 20:13                       ` Marco Chiappero
2011-06-03 15:39 ` [PATCH 9/25] sony-laptop: sony_walk_callback moved for better readability Marco Chiappero
2011-06-03 15:41 ` Marco Chiappero [this message]
2011-06-04  7:58   ` [PATCH 10/25] sony-laptop: keyboard backlight support extended to newer Vaios Mattia Dongili
2011-06-04 10:30     ` Marco Chiappero
2011-06-04 11:23       ` Mattia Dongili
2011-06-04 11:41         ` Marco Chiappero
2011-06-05 22:33           ` Mattia Dongili
2011-06-06 12:27             ` Marco Chiappero
2011-06-10 12:31     ` Marco Chiappero
2011-06-12 22:24       ` Mattia Dongili
2011-06-13 14:28         ` Marco Chiappero
2011-06-18  4:15           ` Mattia Dongili
2011-06-03 15:42 ` [PATCH 11/25] sony-laptop: rfkill improvements Marco Chiappero
2011-06-04  7:59   ` Mattia Dongili
2011-06-03 15:43 ` [PATCH 12/25] sony-laptop: input core improvements improvements Marco Chiappero
2011-06-04  8:07   ` Mattia Dongili
2011-06-04 10:42     ` Marco Chiappero
     [not found]       ` <4DEA0C27.1000508-YK5v5TwyeXionA0d6jMUrA@public.gmane.org>
2011-06-04 12:44         ` Matthew Garrett
2011-06-04 13:11           ` Marco Chiappero
2011-06-08  8:26       ` Joey Lee
2011-06-04 15:21     ` Marco Chiappero
     [not found]       ` <4DEA4D67.8000009-YK5v5TwyeXionA0d6jMUrA@public.gmane.org>
2011-06-04 16:40         ` Mattia Dongili
     [not found]           ` <20110604164021.GA12552-pM3i+3kAS8Rg9hUCZPvPmw@public.gmane.org>
2011-06-04 16:58             ` Marco Chiappero
2011-06-05 22:24               ` Mattia Dongili
2011-06-06 13:26                 ` Marco Chiappero
2011-06-07 14:23                   ` Mattia Dongili
2011-06-07 15:15                     ` Marco Chiappero
2011-06-07 16:24                       ` Mattia Dongili
2011-06-07 17:59                         ` Marco Chiappero
2011-06-20 13:53                           ` Marco Chiappero
2011-07-01 11:12                             ` Marco Chiappero
2011-07-01 12:50                               ` Matthew Garrett
2011-07-01 14:03                                 ` Marco Chiappero
2011-07-01 14:09                                   ` Matthew Garrett
2011-07-01 14:20                                     ` Marco Chiappero
2011-07-01 15:06                                       ` Matthew Garrett
2011-07-01 15:11                                         ` Marco Chiappero
2011-07-01 15:53                                           ` Matthew Garrett
2011-07-01 16:12                                             ` Marco Chiappero
2011-07-19 21:26                             ` Mattia Dongili
2011-06-03 15:45 ` [PATCH 13/25] sony-laptop: code style fixes Marco Chiappero
2011-06-03 15:46 ` [PATCH 14/25] sony-laptop: battery care functionality added Marco Chiappero
2011-06-03 17:33 ` [PATCH 15/25] sony-laptop: add thermal control feature Marco Chiappero
2011-06-03 17:45 ` [PATCH 16/25] sony-laptop: add HDD shock protection Marco Chiappero
2011-06-03 17:54 ` [PATCH 17/25] sony-laptop: add resume from S4/S3 when opening the lid Marco Chiappero
2011-06-03 18:02 ` [PATCH 18/25] sony-laptop: add control file for the HighSpeed Charging feature Marco Chiappero
2011-06-03 18:16 ` [PATCH 19/25] sony-laptop: add touchpad enable/disable control file Marco Chiappero
2011-06-03 20:23   ` Dmitry Torokhov
2011-06-03 20:33     ` Marco Chiappero
2011-06-03 21:00       ` Dmitry Torokhov
2011-06-03 21:46         ` Marco Chiappero
2011-06-03 22:12           ` Dmitry Torokhov
2011-06-04  1:54             ` Marco Chiappero
2011-06-04  7:09               ` Mattia Dongili
2011-06-04 11:15                 ` Marco Chiappero
2011-06-04 12:46                   ` Matthew Garrett
2011-06-04 14:28                     ` Marco Chiappero
2011-06-03 18:28 ` [PATCH 20/25] sony-laptop: add fan related controls Marco Chiappero
2011-06-03 18:50 ` [PATCH 21/25] sony-laptop: add optical device power control Marco Chiappero
2011-06-03 19:27 ` [PATCH 22/25] sony-laptop: forward Hybrid GFX notifications to userspace Marco Chiappero
2011-06-04  8:48   ` Mattia Dongili
2011-06-20 21:12     ` Marco Chiappero
2011-07-19 21:50       ` Mattia Dongili
2011-06-03 19:49 ` [PATCH 23/25] sony-laptop: add ALS support Marco Chiappero
2011-06-05  5:31   ` Mattia Dongili
2011-06-05 22:21     ` Marco Chiappero
2011-06-06  7:41       ` Javier Achirica
2011-06-06 13:08         ` Mattia Dongili
2011-06-06 13:51           ` Marco Chiappero
2011-06-06 22:24             ` Mattia Dongili
2011-06-06 23:26               ` Marco Chiappero
2011-06-07 16:07                 ` Mattia Dongili
2011-06-07 17:50                   ` Marco Chiappero
2011-06-07 22:39                     ` Mattia Dongili
2011-06-08  9:52                       ` Marco Chiappero
2011-06-03 20:10 ` [PATCH 24/25] sony-laptop: backlight device changes Marco Chiappero
2011-06-03 20:10 ` [PATCH 25/25] sony-laptop: update copyright owners Marco Chiappero
2011-06-04  8:54 ` [PATCH 0/25] sony-laptop: code improvements and support extension for newer Vaios Mattia Dongili

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DE9008D.7040504@absence.it \
    --to=marco@absence.it \
    --cc=malattia@linux.it \
    --cc=mjg59@srcf.ucam.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox