sirnoname
Posts: 4
Joined: Thu Nov 27, 2014 8:14 am

Howto Backlight with GPIO?

Fri Jan 05, 2018 4:59 pm

Hello there,

I bought a simple display with HDMI but there is a manual switch for the backlight on it, instad of using a HSYNC with HDMI.
Now I see that the /lib/modules/4.9.35-v7+/kernel/drivers/video/backlight/gpio_backlight.ko driver module is available in standard raspbian image out of the box.
My question: I do not change the raspian device tree. How can I load the driver with giving it a GPIO number? Or do I have to change the tree first and then modprobe the driver?

regards

notro
Posts: 693
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: Howto Backlight with GPIO?

Sun Jan 07, 2018 11:13 pm

You need to use Device Tree to add the device.

backlight-overlay.dts (XX=gpio)

Code: Select all

/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835";

	[email protected] {
		target-path = "/soc";
		__overlay__ {
			backlight: backlight {
				compatible = "gpio-backlight";
				gpios = <&gpio XX 0>; /* GPIO_ACTIVE_HIGH */
				default-on;
			};
		};
	};
};
Compile and copy to folder

Code: Select all

$ dtc [email protected] -I dts -O dtb -o backlight.dtbo backlight-overlay.dts
$ sudo cp backlight.dtbo /boot/overlays/
Enable in /boot/config.txt

Code: Select all

dtoverlay=backlight
The gpio-backlight driver will autoload (udev).

Binding: https://www.kernel.org/doc/Documentatio ... klight.txt
Overlay docs: https://www.raspberrypi.org/documentati ... ce-tree.md

sirnoname
Posts: 4
Joined: Thu Nov 27, 2014 8:14 am

Re: Howto Backlight with GPIO?

Sun Jan 07, 2018 11:31 pm

Thank you.
I read in the forum that the overlay do not work. It is then a GPIO port which appears in /backlight but it has no binding to the display power of the OS itself. Do you know about this problem?

viewtopic.php?f=98&t=116748

notro
Posts: 693
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: Howto Backlight with GPIO?

Mon Jan 08, 2018 8:54 am

The backlight subsystem is tricky and outdated. Userspace does all kinds of thing to make it work in a modern world.

First some comments about the post you linked to:
- The gpio_backlight fix mentioned is about module autoloading and is available in Linux 4.9.
- There is no fb property that can link backlight to a framebuffer.
- The last value in the gpios property specifies active high/low, and 1 is active low. If that is wrong...

So the few things about userspace:
- systemd-backlight stores the brightness value on shutdown and restores it on boot.
- A few years back this was the case for X windows: https://github.com/notro/fbtft-spindle/ ... ght-script
- sysfs: /sys/class/backlight/soc\:backlight/: The brightness file turns on/off. The bl_power file (power state): 0-on, 4-off.
- fbcon console acts on all backlight devices unless they're tied to a fbdev (can't happen using Device Tree).

Return to “Interfacing (DSI, CSI, I2C, etc.)”