Skip to contentSkip to conversation

fbdev: Make CONFIG_FB_DEVICE optional for drivers

PATCH Applied Chintan Patel 4 participants 13 messages Jan 7 – Jan 11

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

v4 cover fbdev: Make CONFIG_FB_DEVICE optional for drivers

This series makes CONFIG_FB_DEVICE optional for fbdev drivers that use it only for sysfs interfaces, addressing Thomas Zimmermann’s TODO to remove hard FB_DEVICE dependencies.

The series introduces a small helper, dev_of_fbinfo(), which returns NULL when CONFIG_FB_DEVICE=n. This allows sysfs code paths to be skipped via runtime checks, avoids #ifdef CONFIG_FB_DEVICE clutter, and keeps full compile-time syntax checking.

---
Changes in v4:
- PTR_IF() was removed and overlay sysfs is now optional via __maybe_unused and #ifdef CONFIG_FB_DEVICE (suggested by Helge Deller)
- Decouple variable definition and assignment in omapfb_remove/create_sysfs (suggested by Andy Shevchenko)
- Added Reviewed-by tags:
- fb: Add dev_of_fbinfo(): Helge Deller, Andy Shevchenko
- staging: fbtft: Helge Deller

Changes in v3:
- Use PTR_IF() to conditionally include overlay_sysfs_group in overlay_sysfs_groups(suggested by Andy Shevchenko)
- Decouple variable definition and assignment in fbtft_sysfs_init/exit(suggested by Andy Shevchenko)

Changes in v2:
- Add dev_of_fbinfo() helper (suggested by Helge Deller)
- Replace #ifdef CONFIG_FB_DEVICE blocks with runtime NULL checks
- Switch to fb_dbg() / fb_info() logging (suggested by Thomas Zimmermann)

---

Chintan Patel (4):
fb: Add dev_of_fbinfo() helper for optional sysfs support
staging: fbtft: Make FB_DEVICE dependency optional
fbdev: omapfb: Make FB_DEVICE dependency optional
fbdev: sh_mobile_lcdc: Make FB_DEVICE dependency optional

 drivers/staging/fbtft/Kconfig                 |  5 ++++-
 drivers/staging/fbtft/fbtft-sysfs.c           | 20 +++++++++++++++----
 drivers/video/fbdev/omap2/omapfb/Kconfig      |  3 ++-
 .../video/fbdev/omap2/omapfb/omapfb-sysfs.c   | 18 +++++++++++++----
 drivers/video/fbdev/sh_mobile_lcdcfb.c        |  5 ++++-
 include/linux/fb.h                            |  9 +++++++++
 6 files changed, 49 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/4 fb: Add dev_of_fbinfo() helper for optional sysfs support

Add dev_of_fbinfo() to return the framebuffer struct device when CONFIG_FB_DEVICE is enabled, or NULL otherwise.

This allows fbdev drivers to use sysfs interfaces via runtime checks instead of CONFIG_FB_DEVICE ifdefs, keeping the code clean while remaining fully buildable.

---
 include/linux/fb.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/linux/fb.h +9 -0
index 05cc251035da..dad3fb61a06a 100644
@@ -628,6 +628,15 @@ static inline void unlock_fb_info(struct fb_info *info)
 	mutex_unlock(&info->lock);
 }
 
+static inline struct device *dev_of_fbinfo(const struct fb_info *info)
+{
+#ifdef CONFIG_FB_DEVICE
+	return info->dev;
+#else
+	return NULL;
+#endif
+}
+
 static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch,
 					   u8 *src, u32 s_pitch, u32 height)
 {
Signature · 1 line
2.43.0
#5 lore raw

PATCH v4 2/4 staging: fbtft: Make FB_DEVICE dependency optional

In reply to Chintan Patel

fbtft provides sysfs interfaces for debugging and gamma configuration, but these are not required for the core driver.

Drop the hard dependency on CONFIG_FB_DEVICE and make sysfs support optional by using dev_of_fbinfo() at runtime. When FB_DEVICE is disabled, sysfs operations are skipped while the code remains buildable and type-checked.

---
 drivers/staging/fbtft/Kconfig       |  5 ++++-
 drivers/staging/fbtft/fbtft-sysfs.c | 20 ++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
drivers/staging/fbtft/Kconfig +4 -1
index c2655768209a..578412a2f379 100644
@@ -2,11 +2,14 @@
 menuconfig FB_TFT
 	tristate "Support for small TFT LCD display modules"
 	depends on FB && SPI
-	depends on FB_DEVICE
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on GPIOLIB || COMPILE_TEST
 	select FB_BACKLIGHT
 	select FB_SYSMEM_HELPERS_DEFERRED
+	help
+	  Support for small TFT LCD display modules over SPI bus. FB_DEVICE
+	  is not required, but if enabled, provides sysfs interface for debugging
+	  and gamma curve configuration.
 
 if FB_TFT
 
drivers/staging/fbtft/fbtft-sysfs.c +16 -4
index e45c90a03a90..d05599d80011 100644
@@ -203,14 +203,26 @@ static struct device_attribute debug_device_attr =
 
 void fbtft_sysfs_init(struct fbtft_par *par)
 {
-	device_create_file(par->info->dev, &debug_device_attr);
+	struct device *dev;
+
+	dev = dev_of_fbinfo(par->info);
+	if (!dev)
+		return;
+
+	device_create_file(dev, &debug_device_attr);
 	if (par->gamma.curves && par->fbtftops.set_gamma)
-		device_create_file(par->info->dev, &gamma_device_attrs[0]);
+		device_create_file(dev, &gamma_device_attrs[0]);
 }
 
 void fbtft_sysfs_exit(struct fbtft_par *par)
 {
-	device_remove_file(par->info->dev, &debug_device_attr);
+	struct device *dev;
+
+	dev = dev_of_fbinfo(par->info);
+	if (!dev)
+		return;
+
+	device_remove_file(dev, &debug_device_attr);
 	if (par->gamma.curves && par->fbtftops.set_gamma)
-		device_remove_file(par->info->dev, &gamma_device_attrs[0]);
+		device_remove_file(dev, &gamma_device_attrs[0]);
 }
Signature · 1 line
2.43.0
#8 lore raw

PATCH v4 3/4 fbdev: omapfb: Make FB_DEVICE dependency optional

In reply to Chintan Patel

omapfb provides several sysfs interfaces for framebuffer configuration and debugging, but these are not required for the core driver.

Remove the hard dependency on CONFIG_FB_DEVICE and make sysfs support optional by using dev_of_fbinfo() to obtain the backing device at runtime. When FB_DEVICE is disabled, sysfs operations are skipped while the code still builds and is type-checked.

---
 drivers/video/fbdev/omap2/omapfb/Kconfig       |  3 ++-
 .../video/fbdev/omap2/omapfb/omapfb-sysfs.c    | 18 ++++++++++++++----
 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/video/fbdev/omap2/omapfb/Kconfig +2 -1
index f4cdf999a080..2d20e79adefc 100644
@@ -5,7 +5,6 @@ config OMAP2_VRFB
 menuconfig FB_OMAP2
 	tristate "OMAP2+ frame buffer support"
 	depends on FB
-	depends on FB_DEVICE
 	depends on DRM_OMAP = n
 	depends on GPIOLIB
 	select FB_OMAP2_DSS
@@ -13,6 +12,8 @@ menuconfig FB_OMAP2
 	select FB_IOMEM_HELPERS
 	help
 	  Frame buffer driver for OMAP2+ based boards.
+	  FB_DEVICE is not required, but if enabled, provides sysfs interface
+	  for framebuffer configuration and debugging.
 
 if FB_OMAP2
 
drivers/video/fbdev/omap2/omapfb/omapfb-sysfs.c +14 -4
index 831b2c2fbdf9..38a635d38d58 100644
@@ -558,10 +558,15 @@ int omapfb_create_sysfs(struct omapfb2_device *fbdev)
 
 	DBG("create sysfs for fbs\n");
 	for (i = 0; i < fbdev->num_fbs; i++) {
+		struct device *dev;
 		int t;
+
+		dev = dev_of_fbinfo(fbdev->fbs[i]);
+		if (!dev)
+			continue;
+
 		for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++) {
-			r = device_create_file(fbdev->fbs[i]->dev,
-					&omapfb_attrs[t]);
+			r = device_create_file(dev, &omapfb_attrs[t]);
 
 			if (r) {
 				dev_err(fbdev->dev, "failed to create sysfs "
@@ -580,9 +585,14 @@ void omapfb_remove_sysfs(struct omapfb2_device *fbdev)
 
 	DBG("remove sysfs for fbs\n");
 	for (i = 0; i < fbdev->num_fbs; i++) {
+		struct device *dev;
+
+		dev = dev_of_fbinfo(fbdev->fbs[i]);
+		if (!dev)
+			continue;
+
 		for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++)
-			device_remove_file(fbdev->fbs[i]->dev,
-					&omapfb_attrs[t]);
+			device_remove_file(dev, &omapfb_attrs[t]);
 	}
 }
 
Signature · 1 line
2.43.0
#11 lore raw

PATCH v4 4/4 fbdev: sh_mobile_lcdc: Make FB_DEVICE dependency optional

In reply to Chintan Patel

The sh_mobile_lcdc driver exposes overlay configuration via sysfs, but the core driver does not require CONFIG_FB_DEVICE.

Make overlay sysfs optional so that the driver can build and operate even when FB_DEVICE is disabled. The kernel naturally ignores the missing attribute group, preserving buildability and type safety.

---
 drivers/video/fbdev/sh_mobile_lcdcfb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/video/fbdev/sh_mobile_lcdcfb.c +4 -1
index dd950e4ab5ce..5f3a0cd27db3 100644
@@ -1343,14 +1343,17 @@ static DEVICE_ATTR_RW(overlay_mode);
 static DEVICE_ATTR_RW(overlay_position);
 static DEVICE_ATTR_RW(overlay_rop3);
 
-static struct attribute *overlay_sysfs_attrs[] = {
+static struct attribute *overlay_sysfs_attrs[] __maybe_unused = {
 	&dev_attr_overlay_alpha.attr,
 	&dev_attr_overlay_mode.attr,
 	&dev_attr_overlay_position.attr,
 	&dev_attr_overlay_rop3.attr,
 	NULL,
 };
+
+#ifdef CONFIG_FB_DEVICE
 ATTRIBUTE_GROUPS(overlay_sysfs);
+#endif
 
 static const struct fb_fix_screeninfo sh_mobile_lcdc_overlay_fix  = {
 	.id =		"SH Mobile LCDC",
Signature · 1 line
2.43.0
Reviewed-by on v4 1/4
#2 lore raw

Re: [PATCH v4 1/4] fb: Add dev_of_fbinfo() helper for optional sysfs support

In reply to Chintan Patel

Am 07.01.26 um 05:42 schrieb Chintan Patel:

Quoted 11 lines

Add dev_of_fbinfo() to return the framebuffer struct device when CONFIG_FB_DEVICE is enabled, or NULL otherwise.

This allows fbdev drivers to use sysfs interfaces via runtime checks instead of CONFIG_FB_DEVICE ifdefs, keeping the code clean while remaining fully buildable.

Quoted 24 lines
---
  include/linux/fb.h | 9 +++++++++
  1 file changed, 9 insertions(+)
include/linux/fb.h +9 -0
index 05cc251035da..dad3fb61a06a 100644
@@ -628,6 +628,15 @@ static inline void unlock_fb_info(struct fb_info *info)
  	mutex_unlock(&info->lock);
  }
 
+static inline struct device *dev_of_fbinfo(const struct fb_info *info)
+{
+#ifdef CONFIG_FB_DEVICE
+	return info->dev;
+#else
+	return NULL;
+#endif
+}
+
  static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch,
  					   u8 *src, u32 s_pitch, u32 height)
  {
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Reviewed-by on v4 2/4
#6 lore raw

Re: [PATCH v4 2/4] staging: fbtft: Make FB_DEVICE dependency optional

In reply to Chintan Patel

Am 07.01.26 um 05:42 schrieb Chintan Patel:

Quoted 8 lines

fbtft provides sysfs interfaces for debugging and gamma configuration, but these are not required for the core driver.

Drop the hard dependency on CONFIG_FB_DEVICE and make sysfs support optional by using dev_of_fbinfo() at runtime. When FB_DEVICE is disabled, sysfs operations are skipped while the code remains buildable and type-checked.

Quoted 4 lines
Quoted 60 lines
---
  drivers/staging/fbtft/Kconfig       |  5 ++++-
  drivers/staging/fbtft/fbtft-sysfs.c | 20 ++++++++++++++++----
  2 files changed, 20 insertions(+), 5 deletions(-)
drivers/staging/fbtft/Kconfig +4 -1
index c2655768209a..578412a2f379 100644
@@ -2,11 +2,14 @@
  menuconfig FB_TFT
  	tristate "Support for small TFT LCD display modules"
  	depends on FB && SPI
-	depends on FB_DEVICE
  	depends on BACKLIGHT_CLASS_DEVICE
  	depends on GPIOLIB || COMPILE_TEST
  	select FB_BACKLIGHT
  	select FB_SYSMEM_HELPERS_DEFERRED
+	help
+	  Support for small TFT LCD display modules over SPI bus. FB_DEVICE
+	  is not required, but if enabled, provides sysfs interface for debugging
+	  and gamma curve configuration.
 
  if FB_TFT
 
drivers/staging/fbtft/fbtft-sysfs.c +16 -4
index e45c90a03a90..d05599d80011 100644
@@ -203,14 +203,26 @@ static struct device_attribute debug_device_attr =
 
  void fbtft_sysfs_init(struct fbtft_par *par)
  {
-	device_create_file(par->info->dev, &debug_device_attr);
+	struct device *dev;
+
+	dev = dev_of_fbinfo(par->info);
+	if (!dev)
+		return;
+
+	device_create_file(dev, &debug_device_attr);
  	if (par->gamma.curves && par->fbtftops.set_gamma)
-		device_create_file(par->info->dev, &gamma_device_attrs[0]);
+		device_create_file(dev, &gamma_device_attrs[0]);
  }
 
  void fbtft_sysfs_exit(struct fbtft_par *par)
  {
-	device_remove_file(par->info->dev, &debug_device_attr);
+	struct device *dev;
+
+	dev = dev_of_fbinfo(par->info);
+	if (!dev)
+		return;
+
+	device_remove_file(dev, &debug_device_attr);
  	if (par->gamma.curves && par->fbtftops.set_gamma)
-		device_remove_file(par->info->dev, &gamma_device_attrs[0]);
+		device_remove_file(dev, &gamma_device_attrs[0]);
  }
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Reviewed-by on v4 3/4
#9 lore raw

Re: [PATCH v4 3/4] fbdev: omapfb: Make FB_DEVICE dependency optional

In reply to Chintan Patel

Am 07.01.26 um 05:42 schrieb Chintan Patel:

Quoted 10 lines

omapfb provides several sysfs interfaces for framebuffer configuration and debugging, but these are not required for the core driver.

Remove the hard dependency on CONFIG_FB_DEVICE and make sysfs support optional by using dev_of_fbinfo() to obtain the backing device at runtime. When FB_DEVICE is disabled, sysfs operations are skipped while the code still builds and is type-checked.

Quoted 65 lines
---
  drivers/video/fbdev/omap2/omapfb/Kconfig       |  3 ++-
  .../video/fbdev/omap2/omapfb/omapfb-sysfs.c    | 18 ++++++++++++++----
  2 files changed, 16 insertions(+), 5 deletions(-)
drivers/video/fbdev/omap2/omapfb/Kconfig +2 -1
index f4cdf999a080..2d20e79adefc 100644
@@ -5,7 +5,6 @@ config OMAP2_VRFB
  menuconfig FB_OMAP2
  	tristate "OMAP2+ frame buffer support"
  	depends on FB
-	depends on FB_DEVICE
  	depends on DRM_OMAP = n
  	depends on GPIOLIB
  	select FB_OMAP2_DSS
@@ -13,6 +12,8 @@ menuconfig FB_OMAP2
  	select FB_IOMEM_HELPERS
  	help
  	  Frame buffer driver for OMAP2+ based boards.
+	  FB_DEVICE is not required, but if enabled, provides sysfs interface
+	  for framebuffer configuration and debugging.
 
  if FB_OMAP2
 
drivers/video/fbdev/omap2/omapfb/omapfb-sysfs.c +14 -4
index 831b2c2fbdf9..38a635d38d58 100644
@@ -558,10 +558,15 @@ int omapfb_create_sysfs(struct omapfb2_device *fbdev)
 
  	DBG("create sysfs for fbs\n");
  	for (i = 0; i < fbdev->num_fbs; i++) {
+		struct device *dev;
  		int t;
+
+		dev = dev_of_fbinfo(fbdev->fbs[i]);
+		if (!dev)
+			continue;
+
  		for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++) {
-			r = device_create_file(fbdev->fbs[i]->dev,
-					&omapfb_attrs[t]);
+			r = device_create_file(dev, &omapfb_attrs[t]);
 
  			if (r) {
  				dev_err(fbdev->dev, "failed to create sysfs "
@@ -580,9 +585,14 @@ void omapfb_remove_sysfs(struct omapfb2_device *fbdev)
 
  	DBG("remove sysfs for fbs\n");
  	for (i = 0; i < fbdev->num_fbs; i++) {
+		struct device *dev;
+
+		dev = dev_of_fbinfo(fbdev->fbs[i]);
+		if (!dev)
+			continue;
+
  		for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++)
-			device_remove_file(fbdev->fbs[i]->dev,
-					&omapfb_attrs[t]);
+			device_remove_file(dev, &omapfb_attrs[t]);
  	}
  }
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Reviewed-by on v4 4/4
#12 lore raw

Re: [PATCH v4 4/4] fbdev: sh_mobile_lcdc: Make FB_DEVICE dependency optional

In reply to Chintan Patel

Am 07.01.26 um 05:42 schrieb Chintan Patel:

Quoted 9 lines

The sh_mobile_lcdc driver exposes overlay configuration via sysfs, but the core driver does not require CONFIG_FB_DEVICE.

Make overlay sysfs optional so that the driver can build and operate even when FB_DEVICE is disabled. The kernel naturally ignores the missing attribute group, preserving buildability and type safety.

Quoted 27 lines
---
  drivers/video/fbdev/sh_mobile_lcdcfb.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/video/fbdev/sh_mobile_lcdcfb.c +4 -1
index dd950e4ab5ce..5f3a0cd27db3 100644
@@ -1343,14 +1343,17 @@ static DEVICE_ATTR_RW(overlay_mode);
  static DEVICE_ATTR_RW(overlay_position);
  static DEVICE_ATTR_RW(overlay_rop3);
 
-static struct attribute *overlay_sysfs_attrs[] = {
+static struct attribute *overlay_sysfs_attrs[] __maybe_unused = {
  	&dev_attr_overlay_alpha.attr,
  	&dev_attr_overlay_mode.attr,
  	&dev_attr_overlay_position.attr,
  	&dev_attr_overlay_rop3.attr,
  	NULL,
  };
+
+#ifdef CONFIG_FB_DEVICE
  ATTRIBUTE_GROUPS(overlay_sysfs);
+#endif
 
  static const struct fb_fix_screeninfo sh_mobile_lcdc_overlay_fix  = {
  	.id =		"SH Mobile LCDC",
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Reviewed-by on v4 2/4
#7 lore raw

Re: [PATCH v4 2/4] staging: fbtft: Make FB_DEVICE dependency optional

In reply to Chintan Patel
Quoted 7 lines · Chintan Patel

fbtft provides sysfs interfaces for debugging and gamma configuration, but these are not required for the core driver.

Drop the hard dependency on CONFIG_FB_DEVICE and make sysfs support optional by using dev_of_fbinfo() at runtime. When FB_DEVICE is disabled, sysfs operations are skipped while the code remains buildable and type-checked.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw

Re: [PATCH v4 1/4] fb: Add dev_of_fbinfo() helper for optional sysfs support

In reply to Chintan Patel
Quoted 7 lines · Chintan Patel

Add dev_of_fbinfo() to return the framebuffer struct device when CONFIG_FB_DEVICE is enabled, or NULL otherwise.

This allows fbdev drivers to use sysfs interfaces via runtime checks instead of CONFIG_FB_DEVICE ifdefs, keeping the code clean while remaining fully buildable.

Quoted 7 lines
---
  include/linux/fb.h | 9 +++++++++
  1 file changed, 9 insertions(+)

Whole v4 series applied to fbdev git tree.

Thanks!
Helge

maintainer Applied
#10 lore raw

Re: [PATCH v4 3/4] fbdev: omapfb: Make FB_DEVICE dependency optional

In reply to Thomas Zimmermann
Quoted 11 lines · Thomas Zimmermann

Am 07.01.26 um 05:42 schrieb Chintan Patel:

Quoted 8 lines

omapfb provides several sysfs interfaces for framebuffer configuration and debugging, but these are not required for the core driver.

Remove the hard dependency on CONFIG_FB_DEVICE and make sysfs support optional by using dev_of_fbinfo() to obtain the backing device at runtime. When FB_DEVICE is disabled, sysfs operations are skipped while the code still builds and is type-checked.

Quoted 4 lines
Quoted 2 lines

applied to fbdev.

Thanks!
Helge

Quoted 4 lines
Quoted 4 lines

---
  drivers/video/fbdev/omap2/omapfb/Kconfig       |  3 ++- .../video/fbdev/omap2/omapfb/omapfb-sysfs.c    | 18 ++++++++++++++----

  2 files changed, 16 insertions(+), 5 deletions(-)
#4 lore raw

Re: [PATCH v4 1/4] fb: Add dev_of_fbinfo() helper for optional sysfs support

In reply to Helge Deller
Quoted 16 lines · Helge Deller
Quoted 7 lines · Chintan Patel

Add dev_of_fbinfo() to return the framebuffer struct device when CONFIG_FB_DEVICE is enabled, or NULL otherwise.

This allows fbdev drivers to use sysfs interfaces via runtime checks instead of CONFIG_FB_DEVICE ifdefs, keeping the code clean while remaining fully buildable.

Quoted 7 lines

---
  include/linux/fb.h | 9 +++++++++

  1 file changed, 9 insertions(+)
Quoted 2 lines

Whole v4 series applied to fbdev git tree.

Appreciate Helge and everyone who reviewed it! This was my first kernel series and it was good learning experience for me.