All of lore.kernel.org
 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 24/25] sony-laptop: backlight device changes
Date: Fri, 03 Jun 2011 22:10:13 +0200	[thread overview]
Message-ID: <4DE93FA5.7000705@absence.it> (raw)
In-Reply-To: <4DE8FC4A.9010401@absence.it>

On Vaio models equipped with an ALS device, when the video driver 
backlight device is not used, a similar backlight device (based on the 
_BCM method implementation) is created by the sony-laptop driver, using 
the same backlight levels.


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

--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -1038,69 +1038,6 @@ static ssize_t sony_nc_sysfs_store(struc
  	return count;
  }

-
-/*
- * Backlight device
- */
-struct sony_backlight_props {
-	struct backlight_device *dev;
-	int			handle;
-	u8			offset;
-	u8			maxlvl;
-};
-struct sony_backlight_props sony_bl_props;
-
-static int sony_backlight_update_status(struct backlight_device *bd)
-{
-	return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
-				bd->props.brightness + 1, NULL);
-}
-
-static int sony_backlight_get_brightness(struct backlight_device *bd)
-{
-	unsigned int value;
-
-	if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
-		return 0;
-	/* brightness levels are 1-based, while backlight ones are 0-based */
-	return value - 1;
-}
-
-static int sony_nc_get_brightness_ng(struct backlight_device *bd)
-{
-	unsigned int result;
-	struct sony_backlight_props *sdev =
-		(struct sony_backlight_props *)bl_get_data(bd);
-
-	sony_call_snc_handle(sdev->handle, 0x0200, &result);
-
-	return (result & 0xff) - sdev->offset;
-}
-
-static int sony_nc_update_status_ng(struct backlight_device *bd)
-{
-	unsigned int value, result;
-	struct sony_backlight_props *sdev =
-		(struct sony_backlight_props *)bl_get_data(bd);
-
-	value = bd->props.brightness + sdev->offset;
-	if (sony_call_snc_handle(sdev->handle, 0x0100 | (value << 16), &result))
-		return -EIO;
-
-	return value;
-}
-
-static const struct backlight_ops sony_backlight_ops = {
-	.options = BL_CORE_SUSPENDRESUME,
-	.update_status = sony_backlight_update_status,
-	.get_brightness = sony_backlight_get_brightness,
-};
-static const struct backlight_ops sony_backlight_ng_ops = {
-	.options = BL_CORE_SUSPENDRESUME,
-	.update_status = sony_nc_update_status_ng,
-	.get_brightness = sony_nc_get_brightness_ng,
-};
-
  /*
   * New SNC-only Vaios event mapping to driver known keys
   */
@@ -2069,6 +2006,44 @@ static int sony_nc_als_managed_set(unsig
  	return ret;
  }

+static unsigned int level;
+static int sony_nc_als_get_brightness(struct backlight_device *bd)
+{
+	if (bd->props.brightness != level)
+		dprintk("bd->props.brightness != level\n");
+
+	return level;
+}
+
+static int sony_nc_als_update_status(struct backlight_device *bd)
+{
+	unsigned int value, result;
+
+	if (als_handle->managed) {
+		if (bd->props.brightness != level) {
+			dprintk("generating ALS event 3 (reason: 2)\n");
+			acpi_bus_generate_proc_event(sony_nc_acpi_device,
+					3, 2);
+			acpi_bus_generate_netlink_event(
+					sony_nc_acpi_device->pnp.device_class,
+					dev_name(&sony_nc_acpi_device->dev),
+					3, 2);
+		}
+	} else {
+		unsigned int cmd;
+
+		value = als_handle->levels[bd->props.brightness];
+		cmd = sony_als_handle == 0x0143 ? 0x3000 : 0x0100;
+		if (sony_call_snc_handle(sony_als_handle,
+					(value << 0x10) | cmd, &result))
+			return -EIO;
+	}
+
+	level = bd->props.brightness;
+
+	return level;
+}
+
  /*	ALS sys interface	*/
  static ssize_t sony_nc_als_power_show(struct device *dev,
  		struct device_attribute *attr, char *buffer)
@@ -2245,7 +2220,6 @@ static ssize_t sony_nc_als_kelvin_show(s
  	return count;
  }

-
  /*	ALS attach/detach functions	*/
  static int sony_nc_als_setup(struct platform_device *pd)
  {
@@ -3742,76 +3716,38 @@ static int sony_nc_odd_cleanup(struct pl
  	return 0;
  }

+/*
+ * Backlight device
+ */
+static struct backlight_device *sony_backlight_device;

-static void sony_nc_backlight_ng_read_limits(int handle,
-		struct sony_backlight_props *props)
+static int sony_backlight_update_status(struct backlight_device *bd)
  {
-	int offset;
-	acpi_status status;
-	u8 brlvl, i;
-	u8 min = 0xff, max = 0x00;
-	struct acpi_object_list params;
-	union acpi_object in_obj;
-	union acpi_object *lvl_enum;
-	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-
-	props->handle = handle;
-	props->offset = 0;
-	props->maxlvl = 0xff;
-
-	offset = sony_find_snc_handle(handle);
-	if (offset < 0)
-		return;
-
-	/* try to read the boundaries from ACPI tables, if we fail the above
-	 * defaults should be reasonable
-	 */
-	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))
-		return;
-
-	lvl_enum = (union acpi_object *) buffer.pointer;
-	if (!lvl_enum) {
-		pr_err("No SN06 return object.");
-		return;
-	}
-	if (lvl_enum->type != ACPI_TYPE_BUFFER) {
-		pr_err("Invalid SN06 return object 0x%.2x\n",
-		       lvl_enum->type);
-		goto out_invalid;
-	}
-
-	/* the buffer lists brightness levels available, brightness levels are
-	 * from 0 to 8 in the array, other values are used by ALS control.
-	 */
-	for (i = 0; i < 9 && i < lvl_enum->buffer.length; i++) {
-
-		brlvl = *(lvl_enum->buffer.pointer + i);
-		dprintk("Brightness level: %d\n", brlvl);
-
-		if (!brlvl)
-			break;
+	return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
+				bd->props.brightness + 1, NULL);
+}

-		if (brlvl > max)
-			max = brlvl;
-		if (brlvl < min)
-			min = brlvl;
-	}
-	props->offset = min;
-	props->maxlvl = max;
-	dprintk("Brightness levels: min=%d max=%d\n", props->offset,
-			props->maxlvl);
+static int sony_backlight_get_brightness(struct backlight_device *bd)
+{
+	unsigned int value;

-out_invalid:
-	kfree(buffer.pointer);
-	return;
+	if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
+		return 0;
+	/* brightness levels are 1-based, while backlight ones are 0-based */
+	return value - 1;
  }

+static const struct backlight_ops sony_backlight_ops = {
+	.options = BL_CORE_SUSPENDRESUME,
+	.update_status = sony_backlight_update_status,
+	.get_brightness = sony_backlight_get_brightness,
+};
+static const struct backlight_ops sony_als_backlight_ops = {
+	.options = BL_CORE_SUSPENDRESUME,
+	.update_status = sony_nc_als_update_status,
+	.get_brightness = sony_nc_als_get_brightness,
+};
+
  static void sony_nc_backlight_setup(void)
  {
  	acpi_handle unused;
@@ -3819,43 +3755,38 @@ static void sony_nc_backlight_setup(void
  	const struct backlight_ops *ops = NULL;
  	struct backlight_properties props;

-	if (sony_find_snc_handle(0x12f) != -1) {
-		ops = &sony_backlight_ng_ops;
-		sony_nc_backlight_ng_read_limits(0x12f, &sony_bl_props);
-		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset;
-
-	} else if (sony_find_snc_handle(0x137) != -1) {
-		ops = &sony_backlight_ng_ops;
-		sony_nc_backlight_ng_read_limits(0x137, &sony_bl_props);
-		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset;
-
+	/* do not use SNC GBRT/SBRT controls along with the ALS */
+	if (sony_als_handle != -1) {
+		/* ALS based backlight device */
+		ops = &sony_als_backlight_ops;
+		max_brightness = als_handle->levels_num - 1;
  	} else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT",
  						&unused))) {
  		ops = &sony_backlight_ops;
  		max_brightness = SONY_MAX_BRIGHTNESS - 1;
-
-	} else
+	} else {
  		return;
+	}

  	memset(&props, 0, sizeof(struct backlight_properties));
  	props.type = BACKLIGHT_PLATFORM;
  	props.max_brightness = max_brightness;
-	sony_bl_props.dev = backlight_device_register("sony", NULL,
-						      &sony_bl_props,
-						      ops, &props);
+	sony_backlight_device = backlight_device_register("sony", NULL, NULL,
+								ops, &props);

-	if (IS_ERR(sony_bl_props.dev)) {
+	if (IS_ERR(sony_backlight_device)) {
  		pr_warn("unable to register backlight device\n");
-		sony_bl_props.dev = NULL;
-	} else
-		sony_bl_props.dev->props.brightness =
-			ops->get_brightness(sony_bl_props.dev);
+		sony_backlight_device = NULL;
+	} else {
+		sony_backlight_device->props.brightness =
+			ops->get_brightness(sony_backlight_device);
+	}
  }

  static void sony_nc_backlight_cleanup(void)
  {
-	if (sony_bl_props.dev)
-		backlight_device_unregister(sony_bl_props.dev);
+	if (sony_backlight_device)
+		backlight_device_unregister(sony_backlight_device);
  }

  static void sony_nc_snc_setup_handles(struct platform_device *pd)
@@ -5273,7 +5204,7 @@ static long sonypi_misc_ioctl(struct fil
  	mutex_lock(&spic_dev.lock);
  	switch (cmd) {
  	case SONYPI_IOCGBRT:
-		if (sony_bl_props.dev == NULL) {
+		if (sony_backlight_device == NULL) {
  			ret = -EIO;
  			break;
  		}
@@ -5286,7 +5217,7 @@ static long sonypi_misc_ioctl(struct fil
  				ret = -EFAULT;
  		break;
  	case SONYPI_IOCSBRT:
-		if (sony_bl_props.dev == NULL) {
+		if (sony_backlight_device == NULL) {
  			ret = -EIO;
  			break;
  		}
@@ -5300,8 +5231,8 @@ static long sonypi_misc_ioctl(struct fil
  			break;
  		}
  		/* sync the backlight device status */
-		sony_bl_props.dev->props.brightness =
-		    sony_backlight_get_brightness(sony_bl_props.dev);
+		sony_backlight_device->props.brightness =
+		    sony_backlight_get_brightness(sony_backlight_device);
  		break;
  	case SONYPI_IOCGBAT1CAP:
  		if (ec_read16(SONYPI_BAT1_FULL, &val16)) {

  parent reply	other threads:[~2011-06-03 20:10 UTC|newest]

Thread overview: 129+ 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 ` [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
2011-06-04 12:44       ` Matthew Garrett
2011-06-04 12:44         ` Matthew Garrett
2011-06-04 13:11         ` Marco Chiappero
2011-06-08  8:26       ` Joey Lee
2011-06-08  8:26         ` Joey Lee
2011-06-04 15:21     ` Marco Chiappero
2011-06-04 16:40       ` Mattia Dongili
2011-06-04 16:40         ` Mattia Dongili
2011-06-04 16:58         ` Marco Chiappero
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 ` Marco Chiappero [this message]
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=4DE93FA5.7000705@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.