Skip to contentSkip to conversation

backlight: Replace struct fb_info in interfaces

PATCH Applied Thomas Zimmermann 3 participants 17 messages Mar 5, 2024 – Mar 28, 2024

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

v4 cover backlight: Replace struct fb_info in interfaces

Backlight drivers implement struct backlight_ops.check_fb, which uses struct fb_info in its interface. Replace the callback with one that does not use fb_info.

In DRM, we have several drivers that implement backlight support. By including <linux/backlight.h> these drivers depend on <linux/fb.h>. At the same time, fbdev is deprecated for new drivers and likely to be replaced on many systems.

This patchset is part of a larger effort to implement the backlight code without depending on fbdev.

Patch 1 makes the backlight core match backlight and framebuffer devices via struct fb_info.bl_dev. Patches 2 to 9 then go through drivers and remove unnecessary implementations of check_fb. Finally, patch 10 replaces the check_fb hook with controls_device, which uses the framebuffer's Linux device instead of the framebuffer.

v4:
* fix fb_bl_device() declaration and export
v3:
* hide CONFIG_FB_BACKLIGHT behind fb_bl_device() (Lee)
* if-else cleanups (Andy)
* fix commit message of patch 2 (Andy)
v2:
* fix hid-picolcd for CONFIG_FB_BACKLIGHT=n
* fixes to commit messages

Thomas Zimmermann (10):
backlight: Match backlight device against struct fb_info.bl_dev auxdisplay/ht16k33: Remove struct backlight_ops.check_fb hid/hid-picolcd: Fix initialization order hid/hid-picolcd: Remove struct backlight_ops.check_fb backlight/aat2870-backlight: Remove struct backlight.check_fb backlight/pwm-backlight: Remove struct backlight_ops.check_fb fbdev/sh_mobile_lcdc_fb: Remove struct backlight_ops.check_fb fbdev/ssd1307fb: Init backlight before registering framebuffer fbdev/ssd1307fb: Remove struct backlight_ops.check_fb
backlight: Add controls_device callback to struct backlight_ops

 drivers/auxdisplay/ht16k33.c             |  8 ------
 drivers/hid/hid-picolcd_backlight.c      |  7 ------
 drivers/hid/hid-picolcd_core.c           | 14 +++++------
 drivers/hid/hid-picolcd_fb.c             |  6 +++++
 drivers/video/backlight/aat2870_bl.c     |  7 ------
 drivers/video/backlight/backlight.c      |  8 ++++--
 drivers/video/backlight/bd6107.c         | 12 ++++-----
 drivers/video/backlight/gpio_backlight.c | 12 ++++-----
 drivers/video/backlight/lv5207lp.c       | 12 ++++-----
 drivers/video/backlight/pwm_bl.c         | 12 ---------
 drivers/video/fbdev/core/fb_backlight.c  |  6 +++++
 drivers/video/fbdev/sh_mobile_lcdcfb.c   |  7 ------
 drivers/video/fbdev/ssd1307fb.c          | 31 +++++++++---------------
 include/linux/backlight.h                | 16 ++++++------
 include/linux/fb.h                       |  9 +++++++
 include/linux/pwm_backlight.h            |  1 -
 16 files changed, 71 insertions(+), 97 deletions(-)
Signature · 1 line
2.44.0
#1 lore raw

PATCH v4 1/10 backlight: Match backlight device against struct fb_info.bl_dev

Framebuffer drivers for devices with dedicated backlight are supposed to set struct fb_info.bl_dev to the backlight's respective device. Use the value to match backlight and framebuffer in the backlight core code.

The code first tests against struct backlight_ops.check_ops. If this test succeeds, it performs the test against fbdev. So backlight drivers can override the later test as before.

Fbdev's backlight support depends on CONFIG_FB_BACKLIGHT. To avoid ifdef in the code, the new helper fb_bl_device() returns the backlight device, or NULL if the config option has been disabled. The test in the backlight code will then do nothing.

v4:
* declare empty fb_bl_device() as static inline
* export fb_bl_device()
v3:
* hide ifdef in fb_bl_device() (Lee)
* no if-else blocks (Andy)

---
 drivers/video/backlight/backlight.c     | 8 ++++++--
 drivers/video/fbdev/core/fb_backlight.c | 6 ++++++
 include/linux/fb.h                      | 9 +++++++++
 3 files changed, 21 insertions(+), 2 deletions(-)
drivers/video/backlight/backlight.c +6 -2
index 86e1cdc8e3697..4f7973c6fcc79 100644
@@ -98,7 +98,9 @@ static int fb_notifier_callback(struct notifier_block *self,
 {
 	struct backlight_device *bd;
 	struct fb_event *evdata = data;
-	int node = evdata->info->node;
+	struct fb_info *info = evdata->info;
+	struct backlight_device *fb_bd = fb_bl_device(info);
+	int node = info->node;
 	int fb_blank = 0;
 
 	/* If we aren't interested in this event, skip it immediately ... */
@@ -110,7 +112,9 @@ static int fb_notifier_callback(struct notifier_block *self,
 
 	if (!bd->ops)
 		goto out;
-	if (bd->ops->check_fb && !bd->ops->check_fb(bd, evdata->info))
+	if (bd->ops->check_fb && !bd->ops->check_fb(bd, info))
+		goto out;
+	if (fb_bd && fb_bd != bd)
 		goto out;
 
 	fb_blank = *(int *)evdata->data;
drivers/video/fbdev/core/fb_backlight.c +6 -0
index e2d3b3adc870f..6fdaa9f81be90 100644
@@ -30,4 +30,10 @@ void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
 	mutex_unlock(&fb_info->bl_curve_mutex);
 }
 EXPORT_SYMBOL_GPL(fb_bl_default_curve);
+
+struct backlight_device *fb_bl_device(struct fb_info *info)
+{
+	return info->bl_dev;
+}
+EXPORT_SYMBOL(fb_bl_device);
 #endif
include/linux/fb.h +9 -0
index 708e6a177b1be..15e91c04758c8 100644
@@ -732,6 +732,15 @@ extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev);
 extern void framebuffer_release(struct fb_info *info);
 extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max);
 
+#if IS_ENABLED(CONFIG_FB_BACKLIGHT)
+struct backlight_device *fb_bl_device(struct fb_info *info);
+#else
+static inline struct backlight_device *fb_bl_device(struct fb_info *info)
+{
+	return NULL;
+}
+#endif
+
 /* fbmon.c */
 #define FB_MAXTIMINGS		0
 #define FB_VSYNCTIMINGS		1
Signature · 1 line
2.44.0
#2 lore raw

PATCH v4 2/10 auxdisplay/ht16k33: Remove struct backlight_ops.check_fb

In reply to Thomas Zimmermann

The driver sets struct fb_info.bl_dev to the correct backlight device. Thus rely on the backlight core code to match backlight and framebuffer devices, and remove the extra check_fb() function from struct backlight_ops.

v3:
* use 'check_fb()' in commit message (Andy)

---
 drivers/auxdisplay/ht16k33.c | 8 --------
 1 file changed, 8 deletions(-)
drivers/auxdisplay/ht16k33.c +0 -8
index a90430b7d07ba..0a858db32486b 100644
@@ -325,16 +325,8 @@ static int ht16k33_bl_update_status(struct backlight_device *bl)
 	return ht16k33_brightness_set(priv, brightness);
 }
 
-static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info *fi)
-{
-	struct ht16k33_priv *priv = bl_get_data(bl);
-
-	return (fi == NULL) || (fi->par == priv);
-}
-
 static const struct backlight_ops ht16k33_bl_ops = {
 	.update_status	= ht16k33_bl_update_status,
-	.check_fb	= ht16k33_bl_check_fb,
 };
 
 /*
Signature · 1 line
2.44.0
#3 lore raw

PATCH v4 3/10 hid/hid-picolcd: Fix initialization order

In reply to Thomas Zimmermann

For drivers that support backlight, LCD and fbdev devices, fbdev has to be initialized last. See documentation for struct fbinfo.bl_dev.

---
 drivers/hid/hid-picolcd_core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/hid/hid-picolcd_core.c +7 -7
index bbda231a7ce30..5ddebe25eb91f 100644
@@ -474,11 +474,6 @@ static int picolcd_probe_lcd(struct hid_device *hdev, struct picolcd_data *data)
 	if (error)
 		goto err;
 
-	/* Set up the framebuffer device */
-	error = picolcd_init_framebuffer(data);
-	if (error)
-		goto err;
-
 	/* Setup lcd class device */
 	error = picolcd_init_lcd(data, picolcd_out_report(REPORT_CONTRAST, hdev));
 	if (error)
@@ -489,6 +484,11 @@ static int picolcd_probe_lcd(struct hid_device *hdev, struct picolcd_data *data)
 	if (error)
 		goto err;
 
+	/* Set up the framebuffer device */
+	error = picolcd_init_framebuffer(data);
+	if (error)
+		goto err;
+
 	/* Setup the LED class devices */
 	error = picolcd_init_leds(data, picolcd_out_report(REPORT_LED_STATE, hdev));
 	if (error)
@@ -502,9 +502,9 @@ static int picolcd_probe_lcd(struct hid_device *hdev, struct picolcd_data *data)
 	return 0;
 err:
 	picolcd_exit_leds(data);
+	picolcd_exit_framebuffer(data);
 	picolcd_exit_backlight(data);
 	picolcd_exit_lcd(data);
-	picolcd_exit_framebuffer(data);
 	picolcd_exit_cir(data);
 	picolcd_exit_keys(data);
 	return error;
@@ -623,9 +623,9 @@ static void picolcd_remove(struct hid_device *hdev)
 	/* Cleanup LED */
 	picolcd_exit_leds(data);
 	/* Clean up the framebuffer */
+	picolcd_exit_framebuffer(data);
 	picolcd_exit_backlight(data);
 	picolcd_exit_lcd(data);
-	picolcd_exit_framebuffer(data);
 	/* Cleanup input */
 	picolcd_exit_cir(data);
 	picolcd_exit_keys(data);
Signature · 1 line
2.44.0
#4 lore raw

PATCH v4 4/10 hid/hid-picolcd: Remove struct backlight_ops.check_fb

In reply to Thomas Zimmermann

Update the driver to initialize struct fb_info.bl_dev to its backlight device, if any. Thus rely on the backlight core code to match backlight and framebuffer devices, and remove the extra check_fb function from struct backlight_ops.

v2:
* protect against CONFIG_FB_BACKLIGHT (Javier, kernel test robot)
* reword commit message (Daniel)

---
 drivers/hid/hid-picolcd_backlight.c | 7 -------
 drivers/hid/hid-picolcd_fb.c        | 6 ++++++
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/hid/hid-picolcd_backlight.c +0 -7
index 5bd2a8c4bbd66..08d16917eb60b 100644
@@ -9,7 +9,6 @@
 
 #include <linux/hid.h>
 
-#include <linux/fb.h>
 #include <linux/backlight.h>
 
 #include "hid-picolcd.h"
@@ -39,15 +38,9 @@ static int picolcd_set_brightness(struct backlight_device *bdev)
 	return 0;
 }
 
-static int picolcd_check_bl_fb(struct backlight_device *bdev, struct fb_info *fb)
-{
-	return fb && fb == picolcd_fbinfo((struct picolcd_data *)bl_get_data(bdev));
-}
-
 static const struct backlight_ops picolcd_blops = {
 	.update_status  = picolcd_set_brightness,
 	.get_brightness = picolcd_get_brightness,
-	.check_fb       = picolcd_check_bl_fb,
 };
 
 int picolcd_init_backlight(struct picolcd_data *data, struct hid_report *report)
drivers/hid/hid-picolcd_fb.c +6 -0
index d7dddd99d325e..750206f5fc674 100644
@@ -493,6 +493,12 @@ int picolcd_init_framebuffer(struct picolcd_data *data)
 	info->fix = picolcdfb_fix;
 	info->fix.smem_len   = PICOLCDFB_SIZE*8;
 
+#ifdef CONFIG_FB_BACKLIGHT
+#ifdef CONFIG_HID_PICOLCD_BACKLIGHT
+	info->bl_dev = data->backlight;
+#endif
+#endif
+
 	fbdata = info->par;
 	spin_lock_init(&fbdata->lock);
 	fbdata->picolcd = data;
Signature · 1 line
2.44.0
#5 lore raw

PATCH v4 5/10 backlight/aat2870-backlight: Remove struct backlight.check_fb

In reply to Thomas Zimmermann

The driver's implementation of check_fb always returns true, which is the default if no implementation has been set. So remove the code from the driver.

---
 drivers/video/backlight/aat2870_bl.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/video/backlight/aat2870_bl.c +0 -7
index 81fde3abb92c4..b4c3354a1a8a6 100644
@@ -12,7 +12,6 @@
 #include <linux/platform_device.h>
 #include <linux/mutex.h>
 #include <linux/delay.h>
-#include <linux/fb.h>
 #include <linux/backlight.h>
 #include <linux/mfd/aat2870.h>
 
@@ -90,15 +89,9 @@ static int aat2870_bl_update_status(struct backlight_device *bd)
 	return 0;
 }
 
-static int aat2870_bl_check_fb(struct backlight_device *bd, struct fb_info *fi)
-{
-	return 1;
-}
-
 static const struct backlight_ops aat2870_bl_ops = {
 	.options = BL_CORE_SUSPENDRESUME,
 	.update_status = aat2870_bl_update_status,
-	.check_fb = aat2870_bl_check_fb,
 };
 
 static int aat2870_bl_probe(struct platform_device *pdev)
Signature · 1 line
2.44.0
#6 lore raw

PATCH v4 6/10 backlight/pwm-backlight: Remove struct backlight_ops.check_fb

In reply to Thomas Zimmermann

The internal check_fb callback from struct pwm_bl_data is never implemented. The driver's implementation of check_fb always returns true, which is the backlight core's default if no implementation has been set. So remove the code from the driver.

v2:
* reword commit message

---
 drivers/video/backlight/pwm_bl.c | 12 ------------
 include/linux/pwm_backlight.h    |  1 -
 2 files changed, 13 deletions(-)
drivers/video/backlight/pwm_bl.c +0 -12
index ffcebf6aa76a9..61d30bc98eea5 100644
@@ -11,7 +11,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/fb.h>
 #include <linux/backlight.h>
 #include <linux/err.h>
 #include <linux/pwm.h>
@@ -34,7 +33,6 @@ struct pwm_bl_data {
 					  int brightness);
 	void			(*notify_after)(struct device *,
 					int brightness);
-	int			(*check_fb)(struct device *, struct fb_info *);
 	void			(*exit)(struct device *);
 };
 
@@ -129,17 +127,8 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
 	return 0;
 }
 
-static int pwm_backlight_check_fb(struct backlight_device *bl,
-				  struct fb_info *info)
-{
-	struct pwm_bl_data *pb = bl_get_data(bl);
-
-	return !pb->check_fb || pb->check_fb(pb->dev, info);
-}
-
 static const struct backlight_ops pwm_backlight_ops = {
 	.update_status	= pwm_backlight_update_status,
-	.check_fb	= pwm_backlight_check_fb,
 };
 
 #ifdef CONFIG_OF
@@ -482,7 +471,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 
 	pb->notify = data->notify;
 	pb->notify_after = data->notify_after;
-	pb->check_fb = data->check_fb;
 	pb->exit = data->exit;
 	pb->dev = &pdev->dev;
 	pb->enabled = false;
include/linux/pwm_backlight.h +0 -1
index cdd2ac366bc72..0bf80e98d5b40 100644
@@ -19,7 +19,6 @@ struct platform_pwm_backlight_data {
 	int (*notify)(struct device *dev, int brightness);
 	void (*notify_after)(struct device *dev, int brightness);
 	void (*exit)(struct device *dev);
-	int (*check_fb)(struct device *dev, struct fb_info *info);
 };
 
 #endif
Signature · 1 line
2.44.0
#7 lore raw

PATCH v4 7/10 fbdev/sh_mobile_lcdc_fb: Remove struct backlight_ops.check_fb

In reply to Thomas Zimmermann

The driver sets struct fb_info.bl_dev to the correct backlight device. Thus rely on the backlight core code to match backlight and framebuffer devices, and remove the extra check_fb function from struct backlight_ops.

---
 drivers/video/fbdev/sh_mobile_lcdcfb.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/video/fbdev/sh_mobile_lcdcfb.c +0 -7
index eb2297b37504c..bf34c8ec1a26c 100644
@@ -2140,17 +2140,10 @@ static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev)
 	return ch->bl_brightness;
 }
 
-static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev,
-				   struct fb_info *info)
-{
-	return (info->bl_dev == bdev);
-}
-
 static const struct backlight_ops sh_mobile_lcdc_bl_ops = {
 	.options	= BL_CORE_SUSPENDRESUME,
 	.update_status	= sh_mobile_lcdc_update_bl,
 	.get_brightness	= sh_mobile_lcdc_get_brightness,
-	.check_fb	= sh_mobile_lcdc_check_fb,
 };
 
 static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent,
Signature · 1 line
2.44.0
#8 lore raw

PATCH v4 8/10 fbdev/ssd1307fb: Init backlight before registering framebuffer

In reply to Thomas Zimmermann

For drivers that support backlight, LCD and fbdev devices, fbdev has to be initialized last. See documentation for struct fbinfo.bl_dev.

The backlight name's index number comes from register_framebuffer(), which now happens after initializing the backlight device. So like in all other backlight drivers, we now give the backlight device a generic name without the fbdev index.

---
 drivers/video/fbdev/ssd1307fb.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/video/fbdev/ssd1307fb.c +11 -13
index 1a4f90ea7d5a8..0d1590c61eb06 100644
@@ -594,7 +594,6 @@ static int ssd1307fb_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
 	struct backlight_device *bl;
-	char bl_name[12];
 	struct fb_info *info;
 	struct fb_deferred_io *ssd1307fb_defio;
 	u32 vmem_size;
@@ -733,31 +732,30 @@ static int ssd1307fb_probe(struct i2c_client *client)
 	if (ret)
 		goto regulator_enable_error;
 
-	ret = register_framebuffer(info);
-	if (ret) {
-		dev_err(dev, "Couldn't register the framebuffer\n");
-		goto panel_init_error;
-	}
-
-	snprintf(bl_name, sizeof(bl_name), "ssd1307fb%d", info->node);
-	bl = backlight_device_register(bl_name, dev, par, &ssd1307fb_bl_ops,
+	bl = backlight_device_register("ssd1307fb-bl", dev, par, &ssd1307fb_bl_ops,
 				       NULL);
 	if (IS_ERR(bl)) {
 		ret = PTR_ERR(bl);
 		dev_err(dev, "unable to register backlight device: %d\n", ret);
-		goto bl_init_error;
+		goto panel_init_error;
+	}
+	info->bl_dev = bl;
+
+	ret = register_framebuffer(info);
+	if (ret) {
+		dev_err(dev, "Couldn't register the framebuffer\n");
+		goto fb_init_error;
 	}
 
 	bl->props.brightness = par->contrast;
 	bl->props.max_brightness = MAX_CONTRAST;
-	info->bl_dev = bl;
 
 	dev_info(dev, "fb%d: %s framebuffer device registered, using %d bytes of video memory\n", info->node, info->fix.id, vmem_size);
 
 	return 0;
 
-bl_init_error:
-	unregister_framebuffer(info);
+fb_init_error:
+	backlight_device_unregister(bl);
 panel_init_error:
 	pwm_disable(par->pwm);
 	pwm_put(par->pwm);
Signature · 1 line
2.44.0
#9 lore raw

PATCH v4 9/10 fbdev/ssd1307fb: Remove struct backlight_ops.check_fb

In reply to Thomas Zimmermann

The driver sets struct fb_info.bl_dev to the correct backlight device. Thus rely on the backlight core code to match backlight and framebuffer devices, and remove the extra check_fb function from struct backlight_ops.

---
 drivers/video/fbdev/ssd1307fb.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/video/fbdev/ssd1307fb.c +0 -7
index 0d1590c61eb06..3f30af3c059e0 100644
@@ -530,17 +530,10 @@ static int ssd1307fb_get_brightness(struct backlight_device *bdev)
 	return par->contrast;
 }
 
-static int ssd1307fb_check_fb(struct backlight_device *bdev,
-				   struct fb_info *info)
-{
-	return (info->bl_dev == bdev);
-}
-
 static const struct backlight_ops ssd1307fb_bl_ops = {
 	.options	= BL_CORE_SUSPENDRESUME,
 	.update_status	= ssd1307fb_update_bl,
 	.get_brightness	= ssd1307fb_get_brightness,
-	.check_fb	= ssd1307fb_check_fb,
 };
 
 static struct ssd1307fb_deviceinfo ssd1307fb_ssd1305_deviceinfo = {
Signature · 1 line
2.44.0
#10 lore raw

PATCH v4 10/10 backlight: Add controls_device callback to struct backlight_ops

In reply to Thomas Zimmermann

Replace check_fb with controls_device in struct backlight_ops. The new callback interface takes a Linux device instead of a framebuffer. Resolves one of the dependencies of backlight.h on fb.h.

The few drivers that had custom implementations of check_fb can easily use the framebuffer's Linux device instead. Update them accordingly.

---
 drivers/video/backlight/backlight.c      |  2 +-
 drivers/video/backlight/bd6107.c         | 12 ++++++------
 drivers/video/backlight/gpio_backlight.c | 12 ++++++------
 drivers/video/backlight/lv5207lp.c       | 12 ++++++------
 include/linux/backlight.h                | 16 ++++++++--------
 5 files changed, 27 insertions(+), 27 deletions(-)
drivers/video/backlight/backlight.c +1 -1
index 4f7973c6fcc79..2bd4299206aef 100644
@@ -112,7 +112,7 @@ static int fb_notifier_callback(struct notifier_block *self,
 
 	if (!bd->ops)
 		goto out;
-	if (bd->ops->check_fb && !bd->ops->check_fb(bd, info))
+	if (bd->ops->controls_device && !bd->ops->controls_device(bd, info->device))
 		goto out;
 	if (fb_bd && fb_bd != bd)
 		goto out;
drivers/video/backlight/bd6107.c +6 -6
index c95a12bf0ce26..d124ede084ef9 100644
@@ -99,18 +99,18 @@ static int bd6107_backlight_update_status(struct backlight_device *backlight)
 	return 0;
 }
 
-static int bd6107_backlight_check_fb(struct backlight_device *backlight,
-				       struct fb_info *info)
+static bool bd6107_backlight_controls_device(struct backlight_device *backlight,
+					     struct device *display_dev)
 {
 	struct bd6107 *bd = bl_get_data(backlight);
 
-	return !bd->pdata->dev || bd->pdata->dev == info->device;
+	return !bd->pdata->dev || bd->pdata->dev == display_dev;
 }
 
 static const struct backlight_ops bd6107_backlight_ops = {
-	.options	= BL_CORE_SUSPENDRESUME,
-	.update_status	= bd6107_backlight_update_status,
-	.check_fb	= bd6107_backlight_check_fb,
+	.options	 = BL_CORE_SUSPENDRESUME,
+	.update_status	 = bd6107_backlight_update_status,
+	.controls_device = bd6107_backlight_controls_device,
 };
 
 static int bd6107_probe(struct i2c_client *client)
drivers/video/backlight/gpio_backlight.c +6 -6
index d28c30b2a35d2..c0cff685ea848 100644
@@ -30,18 +30,18 @@ static int gpio_backlight_update_status(struct backlight_device *bl)
 	return 0;
 }
 
-static int gpio_backlight_check_fb(struct backlight_device *bl,
-				   struct fb_info *info)
+static bool gpio_backlight_controls_device(struct backlight_device *bl,
+					   struct device *display_dev)
 {
 	struct gpio_backlight *gbl = bl_get_data(bl);
 
-	return !gbl->dev || gbl->dev == info->device;
+	return !gbl->dev || gbl->dev == display_dev;
 }
 
 static const struct backlight_ops gpio_backlight_ops = {
-	.options	= BL_CORE_SUSPENDRESUME,
-	.update_status	= gpio_backlight_update_status,
-	.check_fb	= gpio_backlight_check_fb,
+	.options	 = BL_CORE_SUSPENDRESUME,
+	.update_status	 = gpio_backlight_update_status,
+	.controls_device = gpio_backlight_controls_device,
 };
 
 static int gpio_backlight_probe(struct platform_device *pdev)
drivers/video/backlight/lv5207lp.c +6 -6
index 1f1d06b4e119a..0cf00fee0f605 100644
@@ -62,18 +62,18 @@ static int lv5207lp_backlight_update_status(struct backlight_device *backlight)
 	return 0;
 }
 
-static int lv5207lp_backlight_check_fb(struct backlight_device *backlight,
-				       struct fb_info *info)
+static bool lv5207lp_backlight_controls_device(struct backlight_device *backlight,
+					       struct device *display_dev)
 {
 	struct lv5207lp *lv = bl_get_data(backlight);
 
-	return !lv->pdata->dev || lv->pdata->dev == info->device;
+	return !lv->pdata->dev || lv->pdata->dev == display_dev;
 }
 
 static const struct backlight_ops lv5207lp_backlight_ops = {
-	.options	= BL_CORE_SUSPENDRESUME,
-	.update_status	= lv5207lp_backlight_update_status,
-	.check_fb	= lv5207lp_backlight_check_fb,
+	.options	 = BL_CORE_SUSPENDRESUME,
+	.update_status	 = lv5207lp_backlight_update_status,
+	.controls_device = lv5207lp_backlight_controls_device,
 };
 
 static int lv5207lp_probe(struct i2c_client *client)
include/linux/backlight.h +8 -8
index 614653e07e3a8..2db4c70053c46 100644
@@ -13,6 +13,7 @@
 #include <linux/fb.h>
 #include <linux/mutex.h>
 #include <linux/notifier.h>
+#include <linux/types.h>
 
 /**
  * enum backlight_update_reason - what method was used to update backlight
@@ -110,7 +111,6 @@ enum backlight_scale {
 };
 
 struct backlight_device;
-struct fb_info;
 
 /**
  * struct backlight_ops - backlight operations
@@ -160,18 +160,18 @@ struct backlight_ops {
 	int (*get_brightness)(struct backlight_device *);
 
 	/**
-	 * @check_fb: Check the framebuffer device.
+	 * @controls_device: Check against the display device
 	 *
-	 * Check if given framebuffer device is the one bound to this backlight.
-	 * This operation is optional and if not implemented it is assumed that the
-	 * fbdev is always the one bound to the backlight.
+	 * Check if the backlight controls the given display device. This
+	 * operation is optional and if not implemented it is assumed that
+	 * the display is always the one controlled by the backlight.
 	 *
 	 * RETURNS:
 	 *
-	 * If info is NULL or the info matches the fbdev bound to the backlight return true.
-	 * If info does not match the fbdev bound to the backlight return false.
+	 * If display_dev is NULL or display_dev matches the device controlled by
+	 * the backlight, return true. Otherwise return false.
 	 */
-	int (*check_fb)(struct backlight_device *bd, struct fb_info *info);
+	bool (*controls_device)(struct backlight_device *bd, struct device *display_dev);
 };
 
 /**
Signature · 1 line
2.44.0
#11 lore raw
In reply to Thomas Zimmermann

Hello Thomas,

Quoted 9 lines · Thomas Zimmermann

Backlight drivers implement struct backlight_ops.check_fb, which uses struct fb_info in its interface. Replace the callback with one that does not use fb_info.

In DRM, we have several drivers that implement backlight support. By including <linux/backlight.h> these drivers depend on <linux/fb.h>. At the same time, fbdev is deprecated for new drivers and likely to be replaced on many systems.

Quoted 8 lines

This patchset is part of a larger effort to implement the backlight code without depending on fbdev.

Patch 1 makes the backlight core match backlight and framebuffer devices via struct fb_info.bl_dev. Patches 2 to 9 then go through drivers and remove unnecessary implementations of check_fb. Finally, patch 10 replaces the check_fb hook with controls_device, which uses the framebuffer's Linux device instead of the framebuffer.

I assume the merge plan for this series is via drm-misc in one go?

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
maintainer
#12 lore raw
Quoted 15 lines · Uwe Kleine-König

Hello Thomas,

Quoted 12 lines · Thomas Zimmermann

Backlight drivers implement struct backlight_ops.check_fb, which uses struct fb_info in its interface. Replace the callback with one that does not use fb_info.

In DRM, we have several drivers that implement backlight support. By including <linux/backlight.h> these drivers depend on <linux/fb.h>. At the same time, fbdev is deprecated for new drivers and likely to be replaced on many systems.

This patchset is part of a larger effort to implement the backlight code without depending on fbdev.

Quoted 7 lines
Quoted 5 lines

Patch 1 makes the backlight core match backlight and framebuffer devices via struct fb_info.bl_dev. Patches 2 to 9 then go through drivers and remove unnecessary implementations of check_fb. Finally, patch 10 replaces the check_fb hook with controls_device, which uses the framebuffer's Linux device instead of the framebuffer.

I assume the merge plan for this series is via drm-misc in one go?

Backlight in one go. This will be the second attempt at applying it.

Signature · 1 line
Lee Jones [李琼斯]
maintainer Applied
#13 lore raw
In reply to Thomas Zimmermann
Quoted 10 lines · Thomas Zimmermann

Backlight drivers implement struct backlight_ops.check_fb, which uses struct fb_info in its interface. Replace the callback with one that does not use fb_info.

In DRM, we have several drivers that implement backlight support. By including <linux/backlight.h> these drivers depend on <linux/fb.h>. At the same time, fbdev is deprecated for new drivers and likely to be replaced on many systems.

[...]

Applied, thanks!

[01/10] backlight: Match backlight device against struct fb_info.bl_dev

        commit: f1ecddf747f0d734682152b37c927aa958a51497
[02/10] auxdisplay/ht16k33: Remove struct backlight_ops.check_fb
        commit: dddfda7d5f12a7b48aeca6c3840167529c8cd34a
[03/10] hid/hid-picolcd: Fix initialization order
        commit: a951a15002da620871d8f3d8218c043cdc4c2471
[04/10] hid/hid-picolcd: Remove struct backlight_ops.check_fb
        commit: b3c52552f8d8a816bda2bda984411c73f4dd0b87
[05/10] backlight/aat2870-backlight: Remove struct backlight.check_fb
        commit: 0e03c96046405281fb072c05a7810d2661a2f334
[06/10] backlight/pwm-backlight: Remove struct backlight_ops.check_fb
        commit: 78534967e7cb3c2fbfcb2d37820b51a80c570f90
[07/10] fbdev/sh_mobile_lcdc_fb: Remove struct backlight_ops.check_fb
        commit: b853c08cd6598b3b3ff91cb2bba336bfef9c0ac4
[08/10] fbdev/ssd1307fb: Init backlight before registering framebuffer
        commit: d5ae81e965953da27cf46db6281d6a6a28eaaccb
[09/10] fbdev/ssd1307fb: Remove struct backlight_ops.check_fb
        commit: ec5925ef4a2dfd7ee060f4fd2a2e8036f8a94e8e
[10/10] backlight: Add controls_device callback to struct backlight_ops
        commit: 2e427743de015c1ac047036ef495c3f004105439

--
Lee Jones [李琼斯]

maintainer
#14 lore raw
Quoted 26 lines · Lee Jones
Quoted 10 lines · Thomas Zimmermann

Backlight drivers implement struct backlight_ops.check_fb, which uses struct fb_info in its interface. Replace the callback with one that does not use fb_info.

In DRM, we have several drivers that implement backlight support. By including <linux/backlight.h> these drivers depend on <linux/fb.h>. At the same time, fbdev is deprecated for new drivers and likely to be replaced on many systems.

[...]

Applied, thanks!

[01/10] backlight: Match backlight device against struct fb_info.bl_dev

        commit: f1ecddf747f0d734682152b37c927aa958a51497
[02/10] auxdisplay/ht16k33: Remove struct backlight_ops.check_fb
        commit: dddfda7d5f12a7b48aeca6c3840167529c8cd34a
[03/10] hid/hid-picolcd: Fix initialization order
        commit: a951a15002da620871d8f3d8218c043cdc4c2471
[04/10] hid/hid-picolcd: Remove struct backlight_ops.check_fb
        commit: b3c52552f8d8a816bda2bda984411c73f4dd0b87
[05/10] backlight/aat2870-backlight: Remove struct backlight.check_fb
        commit: 0e03c96046405281fb072c05a7810d2661a2f334
[06/10] backlight/pwm-backlight: Remove struct backlight_ops.check_fb
        commit: 78534967e7cb3c2fbfcb2d37820b51a80c570f90
Quoted 8 lines

[07/10] fbdev/sh_mobile_lcdc_fb: Remove struct backlight_ops.check_fb

        commit: b853c08cd6598b3b3ff91cb2bba336bfef9c0ac4
[08/10] fbdev/ssd1307fb: Init backlight before registering framebuffer
        commit: d5ae81e965953da27cf46db6281d6a6a28eaaccb
[09/10] fbdev/ssd1307fb: Remove struct backlight_ops.check_fb
        commit: ec5925ef4a2dfd7ee060f4fd2a2e8036f8a94e8e
[10/10] backlight: Add controls_device callback to struct backlight_ops
        commit: 2e427743de015c1ac047036ef495c3f004105439

Okay, let's try this again.

Send off for more build testing based on v6.8.

Will report back once complete.

Signature · 1 line
Lee Jones [李琼斯]
maintainer
#15 lore raw
Quoted 37 lines · Lee Jones
Quoted 26 lines · Lee Jones
Quoted 10 lines · Thomas Zimmermann

Backlight drivers implement struct backlight_ops.check_fb, which uses struct fb_info in its interface. Replace the callback with one that does not use fb_info.

In DRM, we have several drivers that implement backlight support. By including <linux/backlight.h> these drivers depend on <linux/fb.h>. At the same time, fbdev is deprecated for new drivers and likely to be replaced on many systems.

[...]

Applied, thanks!

[01/10] backlight: Match backlight device against struct fb_info.bl_dev

        commit: f1ecddf747f0d734682152b37c927aa958a51497
[02/10] auxdisplay/ht16k33: Remove struct backlight_ops.check_fb
        commit: dddfda7d5f12a7b48aeca6c3840167529c8cd34a
[03/10] hid/hid-picolcd: Fix initialization order
        commit: a951a15002da620871d8f3d8218c043cdc4c2471
[04/10] hid/hid-picolcd: Remove struct backlight_ops.check_fb
        commit: b3c52552f8d8a816bda2bda984411c73f4dd0b87
[05/10] backlight/aat2870-backlight: Remove struct backlight.check_fb
        commit: 0e03c96046405281fb072c05a7810d2661a2f334
[06/10] backlight/pwm-backlight: Remove struct backlight_ops.check_fb
        commit: 78534967e7cb3c2fbfcb2d37820b51a80c570f90
Quoted 8 lines

[07/10] fbdev/sh_mobile_lcdc_fb: Remove struct backlight_ops.check_fb

        commit: b853c08cd6598b3b3ff91cb2bba336bfef9c0ac4
[08/10] fbdev/ssd1307fb: Init backlight before registering framebuffer
        commit: d5ae81e965953da27cf46db6281d6a6a28eaaccb
[09/10] fbdev/ssd1307fb: Remove struct backlight_ops.check_fb
        commit: ec5925ef4a2dfd7ee060f4fd2a2e8036f8a94e8e
[10/10] backlight: Add controls_device callback to struct backlight_ops
        commit: 2e427743de015c1ac047036ef495c3f004105439
Quoted 5 lines

Okay, let's try this again.

Send off for more build testing based on v6.8.

Will report back once complete.

So far, so good.

Will rebase these and sent out an immutable branch PR once v6.9-rc1 is out.

Note to self: ib-backlight-auxdisplay-hid-fb-6.9

Signature · 1 line
Lee Jones [李琼斯]
maintainer
#16 lore raw

[GIT PULL] Immutable branch between MFD, Auxdisplay, HID and FB due for the v6.9 merge window

In reply to Thomas Zimmermann

Enjoy!

The following changes since commit 4cece764965020c22cff7665b18a012006359095:

Linux 6.9-rc1 (2024-03-24 14:10:05 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight.git ib-backlight-auxdisplay-hid-fb-v6.9

for you to fetch changes up to 0a4be7263749945a3882f7a0e2e5b1c45c31064e:

backlight: Add controls_device callback to struct backlight_ops (2024-03-28 10:09:06 +0000)

----------------------------------------------------------------
Immutable branch between MFD, Auxdisplay, HID and FB due for the v6.9 merge window

----------------------------------------------------------------
Thomas Zimmermann (10):
backlight: Match backlight device against struct fb_info.bl_dev
auxdisplay: ht16k33: Remove struct backlight_ops.check_fb
hid: hid-picolcd: Fix initialization order
hid: hid-picolcd: Remove struct backlight_ops.check_fb
backlight: aat2870-backlight: Remove struct backlight.check_fb
backlight: pwm-backlight: Remove struct backlight_ops.check_fb
fbdev: sh_mobile_lcdc_fb: Remove struct backlight_ops.check_fb
fbdev: ssd1307fb: Init backlight before registering framebuffer
fbdev: ssd1307fb: Remove struct backlight_ops.check_fb
backlight: Add controls_device callback to struct backlight_ops

 drivers/auxdisplay/ht16k33.c             |  8 --------
 drivers/hid/hid-picolcd_backlight.c      |  7 -------
 drivers/hid/hid-picolcd_core.c           | 14 +++++++-------
 drivers/hid/hid-picolcd_fb.c             |  6 ++++++
 drivers/video/backlight/aat2870_bl.c     |  7 -------
 drivers/video/backlight/backlight.c      |  8 ++++++--
 drivers/video/backlight/bd6107.c         | 12 ++++++------
 drivers/video/backlight/gpio_backlight.c | 12 ++++++------
 drivers/video/backlight/lv5207lp.c       | 12 ++++++------
 drivers/video/backlight/pwm_bl.c         | 12 ------------
 drivers/video/fbdev/core/fb_backlight.c  |  6 ++++++
 drivers/video/fbdev/sh_mobile_lcdcfb.c   |  7 -------
 drivers/video/fbdev/ssd1307fb.c          | 31 +++++++++++--------------------
 include/linux/backlight.h                | 16 ++++++++--------
 include/linux/fb.h                       |  9 +++++++++
 include/linux/pwm_backlight.h            |  1 -
 16 files changed, 71 insertions(+), 97 deletions(-)
Signature · 1 line
Lee Jones [李琼斯]