Skip to content
Noralf Trønnes edited this page Jun 7, 2024 · 21 revisions

The panel-mipi-dbi Linux display driver works with all displays that have a MIPI DBI compatible controller, use the SPI interface and supports RGB565.

Displays with MIPI DBI compaptible controllers can be recognised in their use of MIPI DCS commands.

Here's a few common commands:

# configuration
0x11 - Exit sleep mode
0x29 - Set display on
0x36 - Set address mode: 1 parameter
0x3A - Set pixel format: 1 parameter

# set window for pixel buffer transfer
0x2A - Set column address (y): 4 parameters
0x2B - Set row address (x): 4 parameters
0x2C - Set memory start

Example configuration for a Sainsmart 1.8 display:

Device Tree node:

sainsmart18@0 {
	compatible = "sainsmart18", "panel-mipi-dbi-spi";

	spi-max-frequency = <40000000>;
	reg = <0>;

	width-mm = <35>;
	height-mm = <28>;

	reset-gpios = <&gpio 25 0>;
	dc-gpios = <&gpio 24 0>;
	write-only;

	panel-timing {
		hactive = <160>;
		vactive = <128>;
		hback-porch = <0>;
		vback-porch = <0>;

		clock-frequency = <0>;
		hfront-porch = <0>;
		hsync-len = <0>;
		vfront-porch = <0>;
		vsync-len = <0>;
	};
};

Commands file: sainsmart18.txt

command 0x11 # exit sleep mode
delay 120

command 0xB1 0x01 0x2C 0x2D # FRMCTR1
command 0xB4 0x07           # INVCTR
command 0xC0 0xA2 0x02 0x84 # PWCTR1
command 0xC1 0xC5           # PWCTR2
command 0xC2 0x0A 0x00      # PWCTR3
command 0xC5 0x0E           # VMCTR1

command 0x3A 0x05 # pixel format RGB565
command 0x36 0xA0 # address mode (madctl)

# gamma
command 0xE0 0x0F 0x1A 0x0F 0x18 0x2F 0x28 0x20 0x22 0x1F 0x1B 0x23 0x37 0x00 0x07 0x02 0x10
command 0xE1 0x0F 0x1B 0x0F 0x17 0x33 0x2C 0x29 0x2E 0x30 0x30 0x39 0x3F 0x00 0x07 0x03 0x10

command 0x29 # display on

Use mipi-dbi-cmd to convert and then copy

$ mipi-dbi-cmd sainsmart18.bin sainsmart18.txt
$ sudo cp sainsmart18.bin /lib/firmware

Parse firmware file:

$ mipi-dbi-cmd /lib/firmware/sainsmart18.bin
command 0x11
delay 120
command 0xb1 0x01 0x2c 0x2d
command 0xb4 0x07
command 0xc0 0xa2 0x02 0x84
command 0xc1 0xc5
command 0xc2 0x0a 0x00
command 0xc5 0x0e
command 0x3a 0x05
command 0x36 0xa0
command 0xe0 0x0f 0x1a 0x0f 0x18 0x2f 0x28 0x20 0x22 0x1f 0x1b 0x23 0x37 0x00 0x07 0x02 0x10
command 0xe1 0x0f 0x1b 0x0f 0x17 0x33 0x2c 0x29 0x2e 0x30 0x30 0x39 0x3f 0x00 0x07 0x03 0x10
command 0x29

RGB666

Some controllers like ILI9486 and ILI9488 do not support RGB565 on the SPI interface.
Linux v6.11 will have support for RGB666.

The pixel format is set using the format property supporting the following formats:

  • r5g6b5, RGB565
  • b6x2g6x2r6x2, BGR666

Example:

    format = "b6x2g6x2r6x2";

RGB/BGR order can be controlled using the MIPI DCS command set_address_mode (36h).

The downside of using RGB666 is that the pixels are sent using 3 bytes instead of 2 as with RGB565. This means a ~30% drop in framerate.

Ref. Device Tree binding

Controller reset

When the display pipeline is enabled the driver first checks if the controller has display output turned on. If it is on nothing more is done.

If display output can not be determined to be on the following happens:

  • If the reset gpio is specified, do a hardware reset.
  • Next send the SOFT reset command
  • If we did a hw reset wait ~10ms, else wait 120ms
  • Execute commands from the firmware file

Ref: mipi_dbi_poweron_conditional_reset()

Raspberry Pi

The driver has been backported to rpi-5.15.y with an accompanying Device Tree overlay.

The sainsmart18 DT example can be replaced using this overlay:

dtoverlay=mipi-dbi-spi,spi0-0,speed=40000000
dtparam=width=160,height=128,width-mm=35,height-mm=28
dtparam=reset-gpio=25,dc-gpio=24
dtparam=write-only

The default firmware file for the initialisation commands will be /lib/firmware/panel.bin.

In the case of multiple displays with differing configs, the compatible can be set like this example shows (notice the NUL separator):

dtoverlay=mipi-dbi-spi,spi0-0,speed=70000000
dtparam=compatible=rpi-display\0panel-mipi-dbi-spi
dtparam=width=320,height=240,width-mm=58,height-mm=43
dtparam=reset-gpio=23,dc-gpio=24
dtparam=backlight-gpio=18
dtparam=backlight-pwm

The firmware file will now be /lib/firmware/rpi-display.bin.

If you don't get the expected frames per second: Pi4 SPI clock running at half speed or is mainline at double speed?

Barebox

The driver has been ported to Barebox.

Clone this wiki locally