dri-devel Archive on lore.kernel.org
 help / color / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: dri-devel@lists.freedesktop.org,
	Jingoo Han <jingoohan1@gmail.com>,
	Lee Jones <lee.jones@linaro.org>,
	Daniel Thompson <daniel.thompson@linaro.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>, Sam Ravnborg <sam@ravnborg.org>
Subject: [PATCH v1 05/22] drm/gma500: Backlight support
Date: Sun,  2 Aug 2020 13:06:19 +0200
Message-ID: <20200802110636.1018743-6-sam@ravnborg.org> (raw)
In-Reply-To: <20200802110636.1018743-1-sam@ravnborg.org>

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.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
---
 drivers/gpu/drm/gma500/backlight.c       | 35 ++++++------------------
 drivers/gpu/drm/gma500/cdv_device.c      | 29 +++++++++-----------
 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         |  8 ++----
 7 files changed, 31 insertions(+), 72 deletions(-)

diff --git a/drivers/gpu/drm/gma500/backlight.c b/drivers/gpu/drm/gma500/backlight.c
index 35600d070cb5..48b166a702fa 100644
--- a/drivers/gpu/drm/gma500/backlight.c
+++ b/drivers/gpu/drm/gma500/backlight.c
@@ -13,48 +13,31 @@
 #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_set_brightness(dev_priv->backlight_device,
+				 dev_priv->backlight_level);
+	backlight_update_status(dev_priv->backlight_device);
 }
 
 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_set_brightness(dev_priv->backlight_device, 0);
+	backlight_update_status(dev_priv->backlight_device);
 }
 
 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);
+	if (dev_priv->backlight_enabled) {
+		backlight_set_brightness(dev_priv->backlight_device, v);
+		backlight_update_status(dev_priv->backlight_device);
 	}
-#endif	
 }
 
 int gma_backlight_init(struct drm_device *dev)
@@ -73,7 +56,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_set_brightness(dev_priv->backlight_device, 0);
 		backlight_update_status(dev_priv->backlight_device);
 		backlight_device_unregister(dev_priv->backlight_device);
 	}
diff --git a/drivers/gpu/drm/gma500/cdv_device.c b/drivers/gpu/drm/gma500/cdv_device.c
index 4d216a0205f2..31a1eef35a3c 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,18 @@ 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;
-
-	memset(&props, 0, sizeof(struct backlight_properties));
-	props.max_brightness = 100;
-	props.type = BACKLIGHT_PLATFORM;
-
-	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;
+	DECLARE_BACKLIGHT_INIT_PLATFORM(props, 0, 100);
+	struct backlight_device *bl;
+
+	bl = backlight_device_register("psb-bl",
+				       NULL, (void *)dev, &cdv_ops, &props);
+	if (IS_ERR(bl))
+		return PTR_ERR(bl);
+
+	cdv_backlight_device = bl;
+	backlight_set_brightness(bl, cdv_get_brightness(bl));
+	backlight_update_status(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..0da56d4b6f7b 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -398,12 +398,8 @@ 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_set_brightness(bd, backlight_get_actual_brightness(bd));
+	backlight_update_status(bd);
 }
 
 static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
-- 
2.25.1

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

  parent reply index

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-02 11:06 [RFC PATCH v1 0/22] backlight: add init macros and accessors Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 01/22] backlight: Silently fail backlight_update_status() if no device Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 02/22] backlight: Add DECLARE_* macro for device registration Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 03/22] backlight: Add get/set operations for brightness/power properties Sam Ravnborg
2020-08-04 16:43   ` daniel
2020-08-04 19:56     ` Sam Ravnborg
2020-08-05  7:16       ` daniel
2020-08-02 11:06 ` [PATCH v1 04/22] backlight: gpio: Use DECLARE_BACKLIGHT_INIT_RAW and get/setters Sam Ravnborg
2020-08-02 11:06 ` Sam Ravnborg [this message]
2020-08-02 11:06 ` [PATCH v1 06/22] drm/panel: asus-z00t-tm5p5-n35596: Backlight update Sam Ravnborg
2020-08-04 16:59   ` daniel
2020-08-02 11:06 ` [PATCH v1 07/22] drm/panel: jdi-lt070me05000: " Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 08/22] drm/panel: novatek-nt35510: " Sam Ravnborg
2020-08-04 21:29   ` Linus Walleij
2020-08-02 11:06 ` [PATCH v1 09/22] drm/panel: orisetech-otm8009a: " Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 10/22] drm/panel: raydium-rm67191: " Sam Ravnborg
2020-08-04 17:04   ` daniel
2020-08-02 11:06 ` [PATCH v1 11/22] drm/panel: samsung-s6e63m0: " Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 12/22] drm/panel: samsung-s6e63j0x03: " Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 13/22] drm/panel: samsung-s6e3ha2: " Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 14/22] drm/panel: sony-acx424akp: " Sam Ravnborg
2020-08-04 21:31   ` Linus Walleij
2020-08-02 11:06 ` [PATCH v1 15/22] drm/panel: sony-acx565akm: " Sam Ravnborg
2020-08-04 17:09   ` daniel
2020-08-02 11:06 ` [PATCH v1 16/22] drm/bridge: parade-ps8622: " Sam Ravnborg
2020-08-02 14:05   ` kernel test robot
2020-08-02 14:32   ` Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 17/22] drm/tilcdc: " Sam Ravnborg
2020-08-02 13:21   ` kernel test robot
2020-08-02 11:06 ` [PATCH v1 18/22] drm/radeon: " Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 19/22] drm/amdgpu/atom: " Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 20/22] drm/i915: " Sam Ravnborg
2020-08-02 11:06 ` [PATCH v1 21/22] drm/omap: display: " Sam Ravnborg
2020-08-02 14:26   ` Sebastian Reichel
2020-08-02 14:32     ` Sam Ravnborg
2020-08-02 22:48       ` Sebastian Reichel
2020-08-02 11:06 ` [PATCH v1 22/22] drm/shmobile: " Sam Ravnborg
2020-08-04 16:51 ` [RFC PATCH v1 0/22] backlight: add init macros and accessors daniel

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=20200802110636.1018743-6-sam@ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=daniel.thompson@linaro.org \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jingoohan1@gmail.com \
    --cc=lee.jones@linaro.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

dri-devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dri-devel/0 dri-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dri-devel dri-devel/ https://lore.kernel.org/dri-devel \
		dri-devel@lists.freedesktop.org
	public-inbox-index dri-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.freedesktop.lists.dri-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git