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 3/25] sony-laptop: new ACPI SN06 method helper functions
Date: Fri, 03 Jun 2011 17:29:06 +0200	[thread overview]
Message-ID: <4DE8FDC2.2030304@absence.it> (raw)
In-Reply-To: <4DE8FC4A.9010401@absence.it>

SN06 method related code moved from sony_nc_rfkill_setup to 
acpi_callsetfunc_buffer; a new helper sony_call_snc_handle_buffer added 
too, to be used by different handles and not just the rfkill handles.

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

--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -744,6 +744,72 @@ static int acpi_callsetfunc(acpi_handle
  	return -1;
  }

+static int acpi_callsetfunc_buffer(acpi_handle handle, u64 value,
+					u8 array[], unsigned int size)
+{
+	u8 buffer[sizeof(value)];
+	int length = -1;
+	struct acpi_object_list params;
+	union acpi_object in_obj;
+	union acpi_object *values;
+	struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
+	acpi_status status;
+
+	if (!array || !size)
+		return length;
+
+	/* use a buffer type as parameter to overcome any 32 bits ACPI limit */
+	memcpy(buffer, &value, sizeof(buffer));
+
+	params.count = 1;
+	params.pointer = &in_obj;
+	in_obj.type = ACPI_TYPE_BUFFER;
+	in_obj.buffer.length = sizeof(buffer);
+	in_obj.buffer.pointer = buffer;
+
+	/* since SN06 is the only known method returning a buffer we
+	 * can hard code it, it is not necessary to have a parameter
+	 */
+	status = acpi_evaluate_object(sony_nc_acpi_handle, "SN06", &params,
+			&output);
+	values = (union acpi_object *) output.pointer;
+	if (ACPI_FAILURE(status) || !values) {
+		dprintk("acpi_evaluate_object failed\n");
+		goto error;
+	}
+
+	/* some buggy DSDTs return integer when the output does
+	   not execede the 4 bytes size
+	*/
+	if (values->type == ACPI_TYPE_BUFFER) {
+		if (values->buffer.length <= 0)
+			goto error;
+
+		length = size > values->buffer.length ?
+			values->buffer.length : size;
+
+		memcpy(array, values->buffer.pointer, length);
+	} else if (values->type == ACPI_TYPE_INTEGER) {
+		u32 result = values->integer.value;
+		if (size < 4)
+			goto error;
+
+		length = 0;
+		while (length != 4) {
+			array[length] = result & 0xff;
+			result >>= 8;
+			length++;
+		}
+	} else {
+		pr_err("Invalid return object 0x%.2x\n", values->type);
+		goto error;
+	}
+
+error:
+	kfree(output.pointer);
+	return length;
+}
+
  struct sony_nc_handles {
  	u16 cap[0x10];
  	struct device_attribute devattr;
@@ -848,6 +914,24 @@ static int sony_call_snc_handle(int hand
  	return ret;
  }

+/* call command method SN06, accepts a wide input buffer, returns a 
buffer */
+static int sony_call_snc_handle_buffer(int handle, u64 argument, u8 
result[],
+					unsigned int size)
+{
+	int ret = 0;
+	int offset = sony_find_snc_handle(handle);
+
+	if (offset < 0)
+		return -1;
+
+	ret = acpi_callsetfunc_buffer(sony_nc_acpi_handle,
+			offset | argument, result, size);
+	dprintk("called SN06 with 0x%.4llx (%u bytes read)\n",
+			offset | argument, ret);
+
+	return ret;
+}
+
  /*
   * sony_nc_values input/output validate functions
   */
@@ -1300,21 +1384,17 @@ static void sony_nc_rfkill_update(void)
  	}
  }

-static void sony_nc_rfkill_setup(struct acpi_device *device)
+static int sony_nc_rfkill_setup(struct acpi_device *device)
  {
+#define	RFKILL_BUFF_SIZE 8
+	u8 dev_code, i, buff[RFKILL_BUFF_SIZE] = { 0 };
  	int offset;
-	u8 dev_code, i;
-	acpi_status status;
-	struct acpi_object_list params;
-	union acpi_object in_obj;
-	union acpi_object *device_enum;
-	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };

  	offset = sony_find_snc_handle(0x124);
  	if (offset == -1) {
  		offset = sony_find_snc_handle(0x135);
  		if (offset == -1)
-			return;
+			return 0;
  		else
  			sony_rfkill_handle = 0x135;
  	} else
@@ -1324,34 +1404,16 @@ static void sony_nc_rfkill_setup(struct
  	/* need to read the whole buffer returned by the acpi call to SN06
  	 * here otherwise we may miss some features
  	 */
-	params.count = 1;
-	params.pointer = &in_obj;
-	in_obj.type = ACPI_TYPE_INTEGER;
-	in_obj.integer.value = offset;
-	status = acpi_evaluate_object(sony_nc_acpi_handle, "SN06", &params,
-			&buffer);
-	if (ACPI_FAILURE(status)) {
-		dprintk("Radio device enumeration failed\n");
-		return;
-	}
-
-	device_enum = (union acpi_object *) buffer.pointer;
-	if (!device_enum) {
-		pr_err("No SN06 return object\n");
-		goto out_no_enum;
-	}
-	if (device_enum->type != ACPI_TYPE_BUFFER) {
-		pr_err("Invalid SN06 return object 0x%.2x\n",
-		       device_enum->type);
-		goto out_no_enum;
-	}
+	if (sony_call_snc_handle_buffer(sony_rfkill_handle, 0x000,
+					buff, RFKILL_BUFF_SIZE) < 0)
+		return -EIO;

  	/* the buffer is filled with magic numbers describing the devices
  	 * available, 0xff terminates the enumeration
  	 */
-	for (i = 0; i < device_enum->buffer.length; i++) {
+	for (i = 0; i < RFKILL_BUFF_SIZE; i++) {

-		dev_code = *(device_enum->buffer.pointer + i);
+		dev_code = buff[i];
  		if (dev_code == 0xff)
  			break;

@@ -1371,9 +1433,7 @@ static void sony_nc_rfkill_setup(struct
  			sony_nc_setup_rfkill(device, SONY_WIMAX);
  	}

-out_no_enum:
-	kfree(buffer.pointer);
-	return;
+	return 0;
  }

  /* Keyboard backlight feature */

  parent reply	other threads:[~2011-06-03 15:29 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 ` Marco Chiappero [this message]
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 ` [PATCH 10/25] sony-laptop: keyboard backlight support extended to newer Vaios Marco Chiappero
2011-06-04  7:58   ` 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=4DE8FDC2.2030304@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