Subject: [PATCH] [acpi video] Improve LCD detection

- Get rid of is_lcd() helper
- Set ->v_lcd when we have an LCD device
- Set ->v_br when we can control brightness correctly
- Add is_method() helper for determinig presence of certain methods

Signed-off-by: Patrick Mochel <mochel@linux.intel.com>

---

 drivers/acpi/drivers/video/dev-device.c |   55 +++++++++++++++++++++++--------
 1 files changed, 41 insertions(+), 14 deletions(-)

applies-to: d172c78655649439c130777b2dfb360d65b68ea4
3dd229894e32e4a151bf045c7f564acf18c9e4bd
diff --git a/drivers/acpi/drivers/video/dev-device.c b/drivers/acpi/drivers/video/dev-device.c
index 2b297c7..fd46229 100644
--- a/drivers/acpi/drivers/video/dev-device.c
+++ b/drivers/acpi/drivers/video/dev-device.c
@@ -14,6 +14,15 @@
 #include "video.h"
 
 
+static int is_method(struct acpi_dev * ad, char * obj)
+{
+	acpi_handle h;
+	acpi_status status;
+
+	status = acpi_get_handle(ad->acpi_device->handle, obj, &h);
+	return ACPI_SUCCESS(status) ? 1 : 0;
+}
+
 static int get_int(struct acpi_dev * ad, char * method, unsigned long * val)
 {
 	acpi_status status;
@@ -165,10 +174,21 @@ int video_dev_test(struct acpi_dev * ad)
 }
 
 
-static int is_lcd(struct acpi_video_dev * vd)
-{
-	return (vd->v_id.v_type == VIDEO_DEV_LCD);
-}
+/**
+ *	lcd_init - Initialize LCD capabilities of device
+ *	@vd:	The ACPI video device
+ *
+ *	First, check if this device is advertised as an LCD.
+ *	If so, then make sure that it has a good set of methods.
+ *	- No methods are required, but if _BCL is there, then 
+ *	  so must _BCM and _BQC.
+ *	- EDID is also optional, so we don't check for that.
+ *
+ *	If that doesn't work, then return an error, because that's
+ *	going to cause problems.
+ *	If it does have everything that it needs, cache the brightness
+ *	levels in the device.
+ */
 
 static int lcd_init(struct acpi_video_dev * vd)
 {
@@ -177,17 +197,24 @@ static int lcd_init(struct acpi_video_de
 	int ret = 0;
 	int i;
 
-	if (is_lcd(vd)) {
-		ret = get_int_array(vd->v_ad, "_BCL", values, &num);
-		if (ret)
-			return ret;
-
-		vd->v_br_ac = values[0];
-		vd->v_br_batt = values[1];
-
-		for (i = 0; (i + 2) < num; i++)
-			vd->v_br_levels[i] = values[i + 2];
+	if (vd->v_id.v_type == VIDEO_DEV_LCD) {
+		if (is_method(vd->v_ad, "_BCL")) {
+			if (!(is_method(vd->v_ad, "_BCM") && 
+			      is_method(vd->v_ad, "_BQC")))
+				return -EIO;
+
+			ret = get_int_array(vd->v_ad, "_BCL", values, &num);
+			if (ret)
+				return ret;
+
+			vd->v_br = 1;
+			vd->v_br_ac = values[0];
+			vd->v_br_batt = values[1];
 
+			for (i = 0; (i + 2) < num; i++)
+				vd->v_br_levels[i] = values[i + 2];
+		}
+		vd->v_lcd = 1;
 	}
 	return ret;
 }
---
0.99.9.GIT