notro / panel-mipi-dbi

14 stars 2 forks source link

fbtft conversion #4

Closed dsx724 closed 1 year ago

dsx724 commented 1 year ago

@notro Thanks for the great work on this. I'm trying to figure out how to convert an existing working sequence to panel-mipi-dbi and ran into some issues.

I dumped an fbtft log of the init:

fbtft_write_reg8_bus8: 11
fbtft_write_reg8_bus8: 3a 05
fbtft_write_reg8_bus8: b2 05 05 00 33 33
fbtft_write_reg8_bus8: b7 75
fbtft_write_reg8_bus8: c2 01 ff
fbtft_write_reg8_bus8: c3 13
fbtft_write_reg8_bus8: c4 20
fbtft_write_reg8_bus8: bb 22
fbtft_write_reg8_bus8: c5 20
fbtft_write_reg8_bus8: d0 a4 a1
fbtft_write_reg8_bus8: 29
fbtft_write_reg8_bus8: 21
fbtft_write_reg8_bus8: 36 c0
fbtft_update_display(start_line=0, end_line=134)
fbtft_write_reg8_bus8: 2a 00 00 00 ef
fbtft_write_reg8_bus8: 2b 00 00 00 86
fbtft_write_reg8_bus8: 2c
fbtft_write_vmem16_bus16(offset=0, len=64800)
fbtft_write_spi(len=64800): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...
fbtft_write_reg8_bus8: e0 d0 05 0a 09 08 05 2e 44 45 0f 17 16 2b 33
fbtft_write_reg8_bus8: e1 d0 05 0a 09 08 05 2e 43 45 0f 16 16 2b 33

I created an equivalent initialization file panel.bin in /lib/firmware:

command 0x11 # exit_sleep_mode
delay 120

command 0x3a 0x05 # pixel format

command 0xb2 0x05 0x05 0x00 0x33 0x33 
command 0xb7 0x75
command 0xc2 0x01 0xff
command 0xc3 0x13
command 0xc4 0x20
command 0xbb 0x22
command 0xc5 0x20
command 0xd0 0xa4 0xa1

command 0x29 # on
command 0x21 # invert
command 0x36 0xc0 # address mode
command 0x2a 0x00 0x00 0x00 0xef # column address
command 0x2b 0x00 0x00 0x00 0x86 # page address

command 0xe0 0xd0 0x05 0x0a 0x09 0x08 0x05 0x2e 0x44 0x45 0x0f 0x17 0x16 0x2b 0x33
command 0xe1 0xd0 0x05 0x0a 0x09 0x08 0x05 0x2e 0x43 0x45 0x0f 0x16 0x16 0x2b 0x33

It doesn't come with the screen clear but everything else is the same.

I create the device tree overlay:

            display@0 {
                compatible = "panel", "panel-mipi-dbi-spi";
                reg = <0>;
                spi-max-frequency = <40000000>;

                dc-gpios = <&gpio GPIOX_17 GPIO_ACTIVE_HIGH>; # copied from fbtft
                reset-gpios = <&gpio GPIOX_18 GPIO_ACTIVE_LOW>; # copied from fbtft
                write-only;

                backlight = <&display_backlight>;

                width-mm = <25>;
                height-mm = <15>;

                spi-cpol;
                spi-cpha;

                status = "okay";
                panel-timing {
                    hactive = <135>;
                    vactive = <240>;
                    hback-porch = <0>;
                    vback-porch = <0>;
                    clock-frequency = <0>;
                    hfront-porch = <0>;
                    hsync-porch = <0>;
                    hsync-len = <0>;
                    vfront-porch = <0>;
                    vsync-len = <0>;
                };
            };

1) For some reason, I have to manually modprobe panel-mipi-dbi. Is this expected?

I get the following dmesg after modprobe panel-mipi-dbi:

panel-mipi-dbi-spi spi0.0: Looking up power-supply from device tree
panel-mipi-dbi-spi spi0.0: Looking up power-supply property in node /soc/bus@c1100000/spi@8d80/display@0 failed
panel-mipi-dbi-spi spi0.0: supply power not found, using dummy regulator
[drm] Initialized panel-mipi-dbi 1.0.0 20220103 for spi0.0 on minor 2
panel-mipi-dbi-spi spi0.0: [drm] fb1: panel-mipi-dbid frame buffer device

The CS pins on SPI do not activate like with fbtft. I manually try to dump some data:

sudo dd if=/dev/zero of=/dev/fb1 bs=2
dd: error writing '/dev/fb1': No space left on device
32401+0 records in
32400+0 records out
64800 bytes (65 kB, 63 KiB) copied, 0.273157 s, 237 kB/s

However nothing is drawn on the screen and SPI CS never goes to ground. The reset line is stuck on low unlike just blinking with fbtft.

Any ideas? I'm on Linux 6.1.

notro commented 1 year ago

For some reason, I have to manually modprobe panel-mipi-dbi. Is this expected?

No, last time I tried it loaded automatically.

The CS pins on SPI do not activate like with fbtft. I manually try to dump some data:

DRM differs from fbtft in this respect, from wiki:

The reset-gpio polarity also differs (wiki):

You can see what the driver does by setting drm.debug

dsx724 commented 1 year ago

No, last time I tried it loaded automatically.

I have this DT segment for booting but the panel-mipi-dbi module is not loaded automatically. I have to manually modprobe it on boot.

                        spi@8d80 {
                                cs-gpios = <0x24 0x59 0x01>;
                                pinctrl-names = "default\0idle-high\0idle-low";
                                pinctrl-2 = <0x72 0x74>;
                                pinctrl-1 = <0x72 0x73>;
                                pinctrl-0 = <0x72>;
                                compatible = "amlogic,meson-gx-spicc";
                                reg = <0x00 0x8d80 0x00 0x80>;
                                interrupts = <0x00 0x51 0x04>;
                                #address-cells = <0x01>;
                                #size-cells = <0x00>;
                                status = "okay";
                                clocks = <0x03 0x15>;
                                clock-names = "core";
                                resets = <0x12 0xc1>;
                                num-cs = <0x01>;
                                phandle = <0x54>;

                                display@0 {
                                        status = "okay";
                                        spi-cpha;
                                        spi-cpol;
                                        height-mm = <0x0f>;
                                        width-mm = <0x19>;
                                        backlight = <0xa8>;
                                        write-only;
                                        reset-gpios = <0x24 0x61 0x00>;
                                        dc-gpios = <0x24 0x60 0x00>;
                                        spi-max-frequency = <0x27bc86a>;
                                        reg = <0x00>;
                                        compatible = "panel\0panel-mipi-dbi-spi";

                                        panel-timing {
                                                vsync-len = <0x00>;
                                                vfront-porch = <0x00>;
                                                hsync-len = <0x00>;
                                                hsync-porch = <0x00>;
                                                hfront-porch = <0x00>;
                                                clock-frequency = <0x00>;
                                                vback-porch = <0x00>;
                                                hback-porch = <0x00>;
                                                vactive = <0x87>;
                                                hactive = <0xf0>;
                                        };
                                };
                        };

DRM differs from fbtft in this respect, from wiki:

Ack.

The reset-gpio polarity also differs (wiki):

I discovered this earlier when converting some other displays. The logic is flipped compared to most other drivers using ACTIVE_LOW resets, but ack.

You can see what the driver does by setting drm.debug

Thanks for this.

dsx724 commented 1 year ago

I have fixed my issue but I can see not autoloading being an issue for others in the future. Thanks again.