All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lu <aaron.lu@intel.com>
To: linux-acpi@vger.kernel.org, intel-gfx@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Cc: "Daniel Vetter" <daniel@ffwll.ch>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	"Matthew Garrett" <matthew.garrett@nebula.com>,
	"Seth Forshee" <seth.forshee@canonical.com>,
	"Lee Chun-Yi" <joeyli.kernel@gmail.com>,
	"Richard Purdie" <rpurdie@rpsys.net>,
	"Igor Gnatenko" <i.gnatenko.brain@gmail.com>,
	"Yves-Alexis Perez" <corsac@debian.org>,
	"Felipe Contreras" <felipe.contreras@gmail.com>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Aaron Lu" <aaron.lu@intel.com>, "Ben Jencks" <ben@bjencks.net>,
	"Steven Newbury" <steve@snewbury.org.uk>,
	"James Hogan" <james@albanarts.com>,
	"Kamal Mostafa" <kamal@canonical.com>,
	"Joerg Platte" <jplatte@naasa.net>,
	"Kalle Valo" <kvalo@adurom.com>,
	"Martin Steigerwald" <Martin@lichtvoll.de>,
	"Jörg Otte" <jrg.otte@gmail.com>,
	"Mike Galbraith" <bitbucket@online.de>,
	platform-driver-x86@vger.kernel.org,
	"Mika Westerberg" <mika.westerberg@linux.intel.com>
Subject: [PATCH v4 4/4] thinkpad-acpi: fix handle locate for video and query of _BCL
Date: Tue,  8 Oct 2013 14:40:01 +0800	[thread overview]
Message-ID: <1381214401-24672-5-git-send-email-aaron.lu@intel.com> (raw)
In-Reply-To: <1381214401-24672-1-git-send-email-aaron.lu@intel.com>

The tpacpi_acpi_handle_locate function makes use of acpi_get_devices to
locate handle for ACPI video by HID, the problem is, ACPI video node
doesn't really have HID defined(i.e. no _HID control method is defined
for video device), so.. that function would fail. This can be solved by
enhancing the callback function for acpi_get_devices, where we can use
acpi_device_hid function to check if the ACPI node corresponds to a
video controller.

In addition to that, the _BCL control method only exists under a video
output device node, not a video controller device node. So to evaluate
_BCL, we need the handle of a video output device node, which is child
of the located video controller node from tpacpi_acpi_handle_locate.

The two fix are necessary for some Thinkpad models to emit notification
on backlight hotkey press as a result of evaluation of _BCL.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
Tested-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
---
 drivers/platform/x86/thinkpad_acpi.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 03ca6c1..170f278 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -700,6 +700,14 @@ static void __init drv_acpi_handle_init(const char *name,
 static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle,
 			u32 level, void *context, void **return_value)
 {
+	struct acpi_device *dev;
+	if (!strcmp(context, "video")) {
+		if (acpi_bus_get_device(handle, &dev))
+			return AE_OK;
+		if (strcmp(ACPI_VIDEO_HID, acpi_device_hid(dev)))
+			return AE_OK;
+	}
+
 	*(acpi_handle *)return_value = handle;
 
 	return AE_CTRL_TERMINATE;
@@ -712,10 +720,10 @@ static void __init tpacpi_acpi_handle_locate(const char *name,
 	acpi_status status;
 	acpi_handle device_found;
 
-	BUG_ON(!name || !hid || !handle);
+	BUG_ON(!name || !handle);
 	vdbg_printk(TPACPI_DBG_INIT,
 			"trying to locate ACPI handle for %s, using HID %s\n",
-			name, hid);
+			name, hid ? hid : "NULL");
 
 	memset(&device_found, 0, sizeof(device_found));
 	status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback,
@@ -6090,19 +6098,28 @@ static int __init tpacpi_query_bcl_levels(acpi_handle handle)
 {
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 	union acpi_object *obj;
+	struct acpi_device *device, *child;
 	int rc;
 
-	if (ACPI_SUCCESS(acpi_evaluate_object(handle, "_BCL", NULL, &buffer))) {
+	if (acpi_bus_get_device(handle, &device))
+		return 0;
+
+	rc = 0;
+	list_for_each_entry(child, &device->children, node) {
+		acpi_status status = acpi_evaluate_object(child->handle, "_BCL",
+							  NULL, &buffer);
+		if (ACPI_FAILURE(status))
+			continue;
+
 		obj = (union acpi_object *)buffer.pointer;
 		if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
 			pr_err("Unknown _BCL data, please report this to %s\n",
-			       TPACPI_MAIL);
+				TPACPI_MAIL);
 			rc = 0;
 		} else {
 			rc = obj->package.count;
 		}
-	} else {
-		return 0;
+		break;
 	}
 
 	kfree(buffer.pointer);
@@ -6118,7 +6135,7 @@ static unsigned int __init tpacpi_check_std_acpi_brightness_support(void)
 	acpi_handle video_device;
 	int bcl_levels = 0;
 
-	tpacpi_acpi_handle_locate("video", ACPI_VIDEO_HID, &video_device);
+	tpacpi_acpi_handle_locate("video", NULL, &video_device);
 	if (video_device)
 		bcl_levels = tpacpi_query_bcl_levels(video_device);
 
-- 
1.8.4.12.g2ea3df6

WARNING: multiple messages have this Message-ID (diff)
From: Aaron Lu <aaron.lu@intel.com>
To: linux-acpi@vger.kernel.org, intel-gfx@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Cc: "Daniel Vetter" <daniel@ffwll.ch>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	"Matthew Garrett" <matthew.garrett@nebula.com>,
	"Seth Forshee" <seth.forshee@canonical.com>,
	"Lee Chun-Yi" <joeyli.kernel@gmail.com>,
	"Richard Purdie" <rpurdie@rpsys.net>,
	"Igor Gnatenko" <i.gnatenko.brain@gmail.com>,
	"Yves-Alexis Perez" <corsac@debian.org>,
	"Felipe Contreras" <felipe.contreras@gmail.com>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Aaron Lu" <aaron.lu@intel.com>, "Ben Jencks" <ben@bjencks.net>,
	"Steven Newbury" <steve@snewbury.org.uk>,
	"James Hogan" <james@albanarts.com>,
	"Kamal Mostafa" <kamal@canonical.com>,
	"Joerg Platte" <jplatte@naasa.net>,
	"Kalle Valo" <kvalo@adurom.com>,
	"Martin Steigerwald" <Martin@lichtvoll.de>,
	"Jörg Otte" <jrg.otte@gmail.com>,
	"Mike Galbraith" <bitbucket@online.de>,
	platform-driver-x86@vger.kernel.org,
	"Mika Westerberg" <mika.westerberg@linux.intel.com>,
	"Henrique de Moraes Holschuh" <hmh@hmh.eng.br>
Subject: [PATCH v4 4/4] thinkpad-acpi: fix handle locate for video and query of _BCL
Date: Tue,  8 Oct 2013 14:40:01 +0800	[thread overview]
Message-ID: <1381214401-24672-5-git-send-email-aaron.lu@intel.com> (raw)
In-Reply-To: <1381214401-24672-1-git-send-email-aaron.lu@intel.com>

The tpacpi_acpi_handle_locate function makes use of acpi_get_devices to
locate handle for ACPI video by HID, the problem is, ACPI video node
doesn't really have HID defined(i.e. no _HID control method is defined
for video device), so.. that function would fail. This can be solved by
enhancing the callback function for acpi_get_devices, where we can use
acpi_device_hid function to check if the ACPI node corresponds to a
video controller.

In addition to that, the _BCL control method only exists under a video
output device node, not a video controller device node. So to evaluate
_BCL, we need the handle of a video output device node, which is child
of the located video controller node from tpacpi_acpi_handle_locate.

The two fix are necessary for some Thinkpad models to emit notification
on backlight hotkey press as a result of evaluation of _BCL.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
Tested-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
---
 drivers/platform/x86/thinkpad_acpi.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 03ca6c1..170f278 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -700,6 +700,14 @@ static void __init drv_acpi_handle_init(const char *name,
 static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle,
 			u32 level, void *context, void **return_value)
 {
+	struct acpi_device *dev;
+	if (!strcmp(context, "video")) {
+		if (acpi_bus_get_device(handle, &dev))
+			return AE_OK;
+		if (strcmp(ACPI_VIDEO_HID, acpi_device_hid(dev)))
+			return AE_OK;
+	}
+
 	*(acpi_handle *)return_value = handle;
 
 	return AE_CTRL_TERMINATE;
@@ -712,10 +720,10 @@ static void __init tpacpi_acpi_handle_locate(const char *name,
 	acpi_status status;
 	acpi_handle device_found;
 
-	BUG_ON(!name || !hid || !handle);
+	BUG_ON(!name || !handle);
 	vdbg_printk(TPACPI_DBG_INIT,
 			"trying to locate ACPI handle for %s, using HID %s\n",
-			name, hid);
+			name, hid ? hid : "NULL");
 
 	memset(&device_found, 0, sizeof(device_found));
 	status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback,
@@ -6090,19 +6098,28 @@ static int __init tpacpi_query_bcl_levels(acpi_handle handle)
 {
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 	union acpi_object *obj;
+	struct acpi_device *device, *child;
 	int rc;
 
-	if (ACPI_SUCCESS(acpi_evaluate_object(handle, "_BCL", NULL, &buffer))) {
+	if (acpi_bus_get_device(handle, &device))
+		return 0;
+
+	rc = 0;
+	list_for_each_entry(child, &device->children, node) {
+		acpi_status status = acpi_evaluate_object(child->handle, "_BCL",
+							  NULL, &buffer);
+		if (ACPI_FAILURE(status))
+			continue;
+
 		obj = (union acpi_object *)buffer.pointer;
 		if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
 			pr_err("Unknown _BCL data, please report this to %s\n",
-			       TPACPI_MAIL);
+				TPACPI_MAIL);
 			rc = 0;
 		} else {
 			rc = obj->package.count;
 		}
-	} else {
-		return 0;
+		break;
 	}
 
 	kfree(buffer.pointer);
@@ -6118,7 +6135,7 @@ static unsigned int __init tpacpi_check_std_acpi_brightness_support(void)
 	acpi_handle video_device;
 	int bcl_levels = 0;
 
-	tpacpi_acpi_handle_locate("video", ACPI_VIDEO_HID, &video_device);
+	tpacpi_acpi_handle_locate("video", NULL, &video_device);
 	if (video_device)
 		bcl_levels = tpacpi_query_bcl_levels(video_device);
 
-- 
1.8.4.12.g2ea3df6


  parent reply	other threads:[~2013-10-08  6:40 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-08  6:39 [PATCH v4 0/4] Fix Win8 backlight issue Aaron Lu
2013-10-08  6:39 ` Aaron Lu
2013-10-08  6:39 ` [PATCH v4 1/4] backlight: introduce backlight_device_registered Aaron Lu
2013-10-08  6:39   ` Aaron Lu
2013-10-10  0:25   ` Rafael J. Wysocki
2013-10-10  0:25     ` Rafael J. Wysocki
2013-10-10  0:54     ` Aaron Lu
2013-10-10  0:54       ` Aaron Lu
2013-10-10  1:07       ` Rafael J. Wysocki
2013-10-10  1:07         ` Rafael J. Wysocki
2013-10-10  4:29       ` Jani Nikula
2013-10-10  4:29         ` Jani Nikula
2013-10-10  4:53         ` Aaron Lu
2013-10-10  4:53           ` Aaron Lu
2013-10-10  5:23           ` Jani Nikula
2013-10-10  5:23             ` Jani Nikula
2013-10-08  6:39 ` [PATCH v4 2/4] ACPI / video: seperate backlight control and event interface Aaron Lu
2013-10-08  6:39   ` Aaron Lu
2013-10-08  6:40 ` [PATCH v4 3/4] ACPI / video: Do not register backlight if win8 and native interface exists Aaron Lu
2013-10-08  6:40   ` Aaron Lu
2013-10-10  0:29   ` Rafael J. Wysocki
2013-10-10  0:29     ` Rafael J. Wysocki
2013-10-10  1:02     ` Aaron Lu
2013-10-10  1:02       ` Aaron Lu
2013-10-10 12:59       ` Rafael J. Wysocki
2013-10-10 12:59         ` Rafael J. Wysocki
2013-10-11  1:09         ` Aaron Lu
2013-10-11  1:09           ` Aaron Lu
2013-10-08  6:40 ` Aaron Lu [this message]
2013-10-08  6:40   ` [PATCH v4 4/4] thinkpad-acpi: fix handle locate for video and query of _BCL Aaron Lu

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=1381214401-24672-5-git-send-email-aaron.lu@intel.com \
    --to=aaron.lu@intel.com \
    --cc=Martin@lichtvoll.de \
    --cc=ben@bjencks.net \
    --cc=bitbucket@online.de \
    --cc=corsac@debian.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=felipe.contreras@gmail.com \
    --cc=i.gnatenko.brain@gmail.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=james@albanarts.com \
    --cc=jani.nikula@linux.intel.com \
    --cc=joeyli.kernel@gmail.com \
    --cc=jplatte@naasa.net \
    --cc=jrg.otte@gmail.com \
    --cc=kamal@canonical.com \
    --cc=kvalo@adurom.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.garrett@nebula.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rjw@sisk.pl \
    --cc=rpurdie@rpsys.net \
    --cc=seth.forshee@canonical.com \
    --cc=steve@snewbury.org.uk \
    /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.