[PATCH v2 07/24] drm/gma500: Backlight update

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The backlight support is updated to utilise newly added macros and
functions thus simplifying the code.

- Introduced backlight_set_brightness() that can be called with a
  NULL backlight_device
- backlight_update_status() can be called with a NULL backlight_device.
  Benefit from this by removing helper that otherwise was iffed'ed out
- Use DECLARE_BACKLIGHT_INIT_PLATFORM() when creating backlight devices
- Replace direct access to backlight_properties with get/set methods

No functional changes, but a nice reduction in complexity and code.

v2:
  - Use backlight_update_brightness() (Daniel)
  -

Signed-off-by: Sam Ravnborg <sam@xxxxxxxxxxxx>
Cc: Patrik Jakobsson <patrik.r.jakobsson@xxxxxxxxx>
---
 drivers/gpu/drm/gma500/backlight.c       | 34 +++++-------------------
 drivers/gpu/drm/gma500/cdv_device.c      | 24 +++++++----------
 drivers/gpu/drm/gma500/mdfld_device.c    |  9 ++-----
 drivers/gpu/drm/gma500/oaktrail_device.c | 10 ++-----
 drivers/gpu/drm/gma500/opregion.c        |  2 +-
 drivers/gpu/drm/gma500/psb_device.c      | 10 ++-----
 drivers/gpu/drm/gma500/psb_drv.c         |  7 +----
 7 files changed, 24 insertions(+), 72 deletions(-)

diff --git a/drivers/gpu/drm/gma500/backlight.c b/drivers/gpu/drm/gma500/backlight.c
index 35600d070cb5..40b96d1277be 100644
--- a/drivers/gpu/drm/gma500/backlight.c
+++ b/drivers/gpu/drm/gma500/backlight.c
@@ -13,48 +13,27 @@
 #include "intel_bios.h"
 #include "power.h"
 
-#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
-static void do_gma_backlight_set(struct drm_device *dev)
-{
-	struct drm_psb_private *dev_priv = dev->dev_private;
-	backlight_update_status(dev_priv->backlight_device);
-}
-#endif
-
 void gma_backlight_enable(struct drm_device *dev)
 {
-#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
 	struct drm_psb_private *dev_priv = dev->dev_private;
 	dev_priv->backlight_enabled = true;
-	if (dev_priv->backlight_device) {
-		dev_priv->backlight_device->props.brightness = dev_priv->backlight_level;
-		do_gma_backlight_set(dev);
-	}
-#endif	
+	backlight_update_brightness(dev_priv->backlight_device,
+				    dev_priv->backlight_level);
 }
 
 void gma_backlight_disable(struct drm_device *dev)
 {
-#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
 	struct drm_psb_private *dev_priv = dev->dev_private;
 	dev_priv->backlight_enabled = false;
-	if (dev_priv->backlight_device) {
-		dev_priv->backlight_device->props.brightness = 0;
-		do_gma_backlight_set(dev);
-	}
-#endif	
+	backlight_update_brightness(dev_priv->backlight_device, 0);
 }
 
 void gma_backlight_set(struct drm_device *dev, int v)
 {
-#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
 	struct drm_psb_private *dev_priv = dev->dev_private;
 	dev_priv->backlight_level = v;
-	if (dev_priv->backlight_device && dev_priv->backlight_enabled) {
-		dev_priv->backlight_device->props.brightness = v;
-		do_gma_backlight_set(dev);
-	}
-#endif	
+	if (dev_priv->backlight_enabled)
+		backlight_update_brightness(dev_priv->backlight_device, v);
 }
 
 int gma_backlight_init(struct drm_device *dev)
@@ -73,8 +52,7 @@ void gma_backlight_exit(struct drm_device *dev)
 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
 	struct drm_psb_private *dev_priv = dev->dev_private;
 	if (dev_priv->backlight_device) {
-		dev_priv->backlight_device->props.brightness = 0;
-		backlight_update_status(dev_priv->backlight_device);
+		backlight_update_brightness(dev_priv->backlight_device, 0);
 		backlight_device_unregister(dev_priv->backlight_device);
 	}
 #endif
diff --git a/drivers/gpu/drm/gma500/cdv_device.c b/drivers/gpu/drm/gma500/cdv_device.c
index 4d216a0205f2..52ec1b427bf8 100644
--- a/drivers/gpu/drm/gma500/cdv_device.c
+++ b/drivers/gpu/drm/gma500/cdv_device.c
@@ -111,7 +111,7 @@ static int cdv_get_brightness(struct backlight_device *bd)
 static int cdv_set_brightness(struct backlight_device *bd)
 {
 	struct drm_device *dev = bl_get_data(bd);
-	int level = bd->props.brightness;
+	int level = backlight_get_brightness(bd);
 	u32 blc_pwm_ctl;
 
 	/* Percentage 1-100% being valid */
@@ -145,21 +145,17 @@ static const struct backlight_ops cdv_ops = {
 static int cdv_backlight_init(struct drm_device *dev)
 {
 	struct drm_psb_private *dev_priv = dev->dev_private;
-	struct backlight_properties props;
+	DECLARE_BACKLIGHT_INIT_PLATFORM(props, 0, 100);
+	struct backlight_device *bl;
 
-	memset(&props, 0, sizeof(struct backlight_properties));
-	props.max_brightness = 100;
-	props.type = BACKLIGHT_PLATFORM;
+	bl = backlight_device_register("psb-bl",
+				       NULL, (void *)dev, &cdv_ops, &props);
+	if (IS_ERR(bl))
+		return PTR_ERR(bl);
 
-	cdv_backlight_device = backlight_device_register("psb-bl",
-					NULL, (void *)dev, &cdv_ops, &props);
-	if (IS_ERR(cdv_backlight_device))
-		return PTR_ERR(cdv_backlight_device);
-
-	cdv_backlight_device->props.brightness =
-			cdv_get_brightness(cdv_backlight_device);
-	backlight_update_status(cdv_backlight_device);
-	dev_priv->backlight_device = cdv_backlight_device;
+	cdv_backlight_device = bl;
+	backlight_update_brightness(bl, cdv_get_brightness(bl));
+	dev_priv->backlight_device = bl;
 	dev_priv->backlight_enabled = true;
 	return 0;
 }
diff --git a/drivers/gpu/drm/gma500/mdfld_device.c b/drivers/gpu/drm/gma500/mdfld_device.c
index b718efccdcf2..674e6e619d9a 100644
--- a/drivers/gpu/drm/gma500/mdfld_device.c
+++ b/drivers/gpu/drm/gma500/mdfld_device.c
@@ -42,7 +42,7 @@ int mdfld_set_brightness(struct backlight_device *bd)
 	struct drm_device *dev =
 		(struct drm_device *)bl_get_data(mdfld_backlight_device);
 	struct drm_psb_private *dev_priv = dev->dev_private;
-	int level = bd->props.brightness;
+	int level = backlight_get_brightness(bd);
 
 	DRM_DEBUG_DRIVER("backlight level set to %d\n", level);
 
@@ -113,12 +113,9 @@ static int device_backlight_init(struct drm_device *dev)
 
 static int mdfld_backlight_init(struct drm_device *dev)
 {
-	struct backlight_properties props;
+	DECLARE_BACKLIGHT_INIT_PLATFORM(props, BRIGHTNESS_MAX_LEVEL, BRIGHTNESS_MAX_LEVEL);
 	int ret = 0;
 
-	memset(&props, 0, sizeof(struct backlight_properties));
-	props.max_brightness = BRIGHTNESS_MAX_LEVEL;
-	props.type = BACKLIGHT_PLATFORM;
 	mdfld_backlight_device = backlight_device_register("mdfld-bl",
 				NULL, (void *)dev, &mdfld_ops, &props);
 
@@ -129,8 +126,6 @@ static int mdfld_backlight_init(struct drm_device *dev)
 	if (ret)
 		return ret;
 
-	mdfld_backlight_device->props.brightness = BRIGHTNESS_MAX_LEVEL;
-	mdfld_backlight_device->props.max_brightness = BRIGHTNESS_MAX_LEVEL;
 	backlight_update_status(mdfld_backlight_device);
 	return 0;
 }
diff --git a/drivers/gpu/drm/gma500/oaktrail_device.c b/drivers/gpu/drm/gma500/oaktrail_device.c
index ade7e2416a66..52c0f1a35d3f 100644
--- a/drivers/gpu/drm/gma500/oaktrail_device.c
+++ b/drivers/gpu/drm/gma500/oaktrail_device.c
@@ -55,7 +55,7 @@ static int oaktrail_set_brightness(struct backlight_device *bd)
 {
 	struct drm_device *dev = bl_get_data(oaktrail_backlight_device);
 	struct drm_psb_private *dev_priv = dev->dev_private;
-	int level = bd->props.brightness;
+	int level = backlight_get_brightness(bd);
 	u32 blc_pwm_ctl;
 	u32 max_pwm_blc;
 
@@ -136,13 +136,9 @@ static const struct backlight_ops oaktrail_ops = {
 
 static int oaktrail_backlight_init(struct drm_device *dev)
 {
+	DECLARE_BACKLIGHT_INIT_PLATFORM(props, 100, 100);
 	struct drm_psb_private *dev_priv = dev->dev_private;
 	int ret;
-	struct backlight_properties props;
-
-	memset(&props, 0, sizeof(struct backlight_properties));
-	props.max_brightness = 100;
-	props.type = BACKLIGHT_PLATFORM;
 
 	oaktrail_backlight_device = backlight_device_register("oaktrail-bl",
 				NULL, (void *)dev, &oaktrail_ops, &props);
@@ -155,8 +151,6 @@ static int oaktrail_backlight_init(struct drm_device *dev)
 		backlight_device_unregister(oaktrail_backlight_device);
 		return ret;
 	}
-	oaktrail_backlight_device->props.brightness = 100;
-	oaktrail_backlight_device->props.max_brightness = 100;
 	backlight_update_status(oaktrail_backlight_device);
 	dev_priv->backlight_device = oaktrail_backlight_device;
 	return 0;
diff --git a/drivers/gpu/drm/gma500/opregion.c b/drivers/gpu/drm/gma500/opregion.c
index eab6d889bde9..68587cdf6206 100644
--- a/drivers/gpu/drm/gma500/opregion.c
+++ b/drivers/gpu/drm/gma500/opregion.c
@@ -163,7 +163,7 @@ static u32 asle_set_backlight(struct drm_device *dev, u32 bclp)
 	if (bclp > 255)
 		return ASLE_BACKLIGHT_FAILED;
 
-	gma_backlight_set(dev, bclp * bd->props.max_brightness / 255);
+	gma_backlight_set(dev, bclp * backlight_get_max_brightness(bd) / 255);
 
 	asle->cblv = (bclp * 0x64) / 0xff | ASLE_CBLV_VALID;
 
diff --git a/drivers/gpu/drm/gma500/psb_device.c b/drivers/gpu/drm/gma500/psb_device.c
index ece994c4c21a..857681b860c4 100644
--- a/drivers/gpu/drm/gma500/psb_device.c
+++ b/drivers/gpu/drm/gma500/psb_device.c
@@ -92,7 +92,7 @@ static int psb_backlight_setup(struct drm_device *dev)
 static int psb_set_brightness(struct backlight_device *bd)
 {
 	struct drm_device *dev = bl_get_data(psb_backlight_device);
-	int level = bd->props.brightness;
+	int level = backlight_get_brightness(bd);
 
 	/* Percentage 1-100% being valid */
 	if (level < 1)
@@ -110,13 +110,9 @@ static const struct backlight_ops psb_ops = {
 
 static int psb_backlight_init(struct drm_device *dev)
 {
+	DECLARE_BACKLIGHT_INIT_PLATFORM(props, 100, 100);
 	struct drm_psb_private *dev_priv = dev->dev_private;
 	int ret;
-	struct backlight_properties props;
-
-	memset(&props, 0, sizeof(struct backlight_properties));
-	props.max_brightness = 100;
-	props.type = BACKLIGHT_PLATFORM;
 
 	psb_backlight_device = backlight_device_register("psb-bl",
 					NULL, (void *)dev, &psb_ops, &props);
@@ -129,8 +125,6 @@ static int psb_backlight_init(struct drm_device *dev)
 		psb_backlight_device = NULL;
 		return ret;
 	}
-	psb_backlight_device->props.brightness = 100;
-	psb_backlight_device->props.max_brightness = 100;
 	backlight_update_status(psb_backlight_device);
 	dev_priv->backlight_device = psb_backlight_device;
 
diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
index 2411eb9827b8..f13d9861e571 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -398,12 +398,7 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
 
 static inline void get_brightness(struct backlight_device *bd)
 {
-#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
-	if (bd) {
-		bd->props.brightness = bd->ops->get_brightness(bd);
-		backlight_update_status(bd);
-	}
-#endif
+	backlight_update_brightness(bd, backlight_get_actual_brightness(bd));
 }
 
 static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
-- 
2.25.1

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel



[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux