Overlay from raspberry not working in radxa rock s0

Hi,
Im trying to figure out how to adapt a kernel module for the raspberry pi to my
radxa rock S0, but I cant make it work.
My trouble is on how to adapt the dts overlay to make it working with the Radxa.
Please find attached the original and the modified version for radxa, as well as the module.
sharp_modules.zip (4.5 KB)

  1. If I would like to use the same pins in both boards, the SPI2 of the radxa matches
    the SPI0 of the raspberry, so I used as target=<&spi2>
  2. For the extra pins, the raspberry is using gpio24 and gpio25. Those pins in the Radxa are gpio2_A7 and gpio2_B1, so I putted in the dts file: target = <&gpio2> and
    rockchip,pins = <71 73>
  3. The kernel module is succesfully compiled, and I added to the /etc/modules file

Using the rsetup and adding the overlay as 3rd party overlay, doesnt work. I can see in the boot:
failed on fdt_overlay_apply(): FDT_ERR_NOTFOUND

Hi Victor,

In general, to adapt a Raspberry Pi overlay to our system, it is worth to first take a look at our existing examples. Here is a converted overlay based on rk3308-spi2-spidev.dts and radxa-s0-ext-antenna.dts:

/dts-v1/;
/plugin/;

// Include headers from radxa-s0-ext-antenna.dts
// so we can use human readable names for GPIOs
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>

// metadata block is a Radxa custom standard.
// It is only mandatory for Radxa official overlays.

// Use the same spi2 definition as in rk3308-spi2-spidev.dts
&spi2 {
	status = "okay";
	pinctrl-names = "default";
	// Need to check if you are using the same pin for SPI2
	// which was documented in the rk3308-spi2-spidev.dts as metadata.exclusive
	// "GPIO1_C6", "GPIO1_C7", "GPIO1_D0", "GPIO1_D1"
	pinctrl-0 = <&spi2_clk &spi2_csn0 &spi2_miso &spi2_mosi>;
	#address-cells = <1>;
	#size-cells = <0>;

	// Replace spidev@0 with our own device
	sharp_dev: sharp-dev@0{
		compatible = "sharp";
		reg = <0>;
		pinctrl-names = "default";
		pinctrl-0 = <&sharp_pins>;
		spi-cs-high = <1>;
		spi-max-frequency = <2000000>;
		buswidth = <8>;
		debug = <0>;

	};
};

// Keep the rk3308-spi2-spidev.dts disabled devices so SPI2 can work
&uart1 {
	status = "disabled";
};

&uart2 {
	status = "disabled";
};

// Add Rockchip pinctrl to set pins as GPIO
&pinctrl {
	sharp {
		sharp_pins: sharp-pins {
			// rockchip,pins is an array, so you can define multiple pins here.
			// You might need to adjust pcfg_pull_none to some other value
			rockchip,pins = <2 RK_PA7 RK_FUNC_GPIO &pcfg_pull_none>,
							<2 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

// Since GPIO2_A7 and GPIO2_B1 is not used by other devices, we are done here.
// Otherwise, we will also need to disable them like UART1/2 above.

You can then build this overlay with rsetup with Install 3rd party overlay option.

Ok, thank you!
Concerning the kernel module sharp.c, it uses those pins gpio2_A7 and gpio2_B1… how do I translate those to something linux/gpio.h understand? Is it correct to assign this gpio numbers:
gpio2_A7 = 2x32 + 0x8 + 7 = 71
gpio2_B1 = 2x32 + 1x8 + 1 = 73 ??

I installed the modified overlay via “install 3rd party overlay” in rsetup, and rebooted the board.
Now I get the following errors:

rock@typewrt:~$ sudo dmesg | grep sharp
[sudo] password for rock:
[ 1.355110] spi_master spi2: spi_device register error /spi@ff140000/sharp-dev@0
[ 1.355801] spi_master spi2: Failed to create SPI device for /spi@ff140000/sharp-dev@0
[ 6.031411] sharp: loading out-of-tree module taints kernel.

We usually provide them in the pinout table:

Though the best way should be using gpiod API to request it by chip and line, so you can reuse constant definitions such as RK_PA7,

Check if you can have rk3308-spi2-spidev.dtbo enabled and get a spidev device under /dev. Don’t forget to disable your own overlay first.

Umm… enabling the spi2-spidev overlay (with mine disabled) in rsetup works: I get a /dev/spi2.0.
I realized that the pinout table in the reference you post was completely different to the one I was using,
(https://www.okdo.com/wp-content/uploads/2023/12/radxa_rock_s0_product_brief_Revision_1.1.pdf)

Unfortunately, putting the right pins nothing changes:
Now, if I go back to enable my .dts and disabling the spi2_spidev, I get this:

$ sudo dmesg | grep sharp
[sudo] password for rock: 
[    1.357273] spi_master spi2: spi_device register error /spi@ff140000/sharp@0
[    1.357935] spi_master spi2: Failed to create SPI device for /spi@ff140000/sharp@0
[    5.928497] sharp: loading out-of-tree module taints kernel.

There are two things I think could cause problem:

  1. If I list the files in the /boot/dtbo
    root@typewrt:/boot/dtbo# ls -l rk3308-spi2* sharp*
    -rwxr-xr-x 1 root root 1235 May 28 08:58 rk3308-spi2-spidev.dtbo.disabled
    -rw-r–r-- 1 root root 1735 May 28 08:58 sharp_radxa.dtbo

I can see that my overlay doesnt have executable permissions… Is it something to care of?

  1. The other thing is, when I compile the sharp.c module, It compiles with no problem, but it warns that the kernel was compiled with gcc10 while my module is being compiled with gcc12. Thus, shouldnt be a problem.

For troubleshooting overlays I found the serial console output quite essential. I had to get a fast serial adapter capable of the 1.5Mbps configured in the bootloader/kernel (e.g. with CP2104).

Agree! all the output shown here is through the serial console

Any help please? I can also see this message from dmesg:

[ 1.355210] spi spi2.0: setup: non GPIO CS can’t be active-high
[ 1.355241] spi_master spi2: Failed to setup device: -22
[ 1.355746] rockchip-spi ff140000.spi: can’t setup spi2.0, status -22
[ 1.356392] spi_master spi2: spi_device register error /spi@ff140000/sharp@0
[ 1.357057] spi_master spi2: Failed to create SPI device for /spi@ff140000/sharp@0

From which I assume there is some pin assigned active-high that shouldn’t? I tried by setting the sharp_pins to ACTIVE_LOW and pulled-down, but it doesnt help.

rockchip,pins = <2 RK_PA7 1 &pcfg_pull_down>,
<2 RK_PB1 1 &pcfg_pull_down>;

From the spi2, my kernel module is using only SCLK and MOSI, the MISO pin is not connected/needed, and the CS pin is another gpio declared in the kernel module itself.

I’ll need to check which one is correct.

It is not executed so it does not matter.

This should not be a big problem.


Please provide your ROCK Pi S0’s hardware revision, as well as the physical pin numbers you are using.

My board is Radxa_S0_v1.1
The pins connected to the sharp_display are:
Pin 23 (gpio1_D0) SCLK spi2
Pin 19 (gpio1_C7) MOSI spi2
Pin 16 (gpio0_A1) kernel module’s CS
Pin 18 (gpio2_B7) kernel module’s sharp_pin
Pin 22 (gpio2_B3) kernel module’s sharp_pin

The SPI2_MISO and the SPI2_CSN0 are not connected

Hi, Victor:
Please try this dts:

/dts-v1/;
/plugin/;

// Include headers from radxa-s0-ext-antenna.dts
// so we can use human readable names for GPIOs
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>

// metadata block is a Radxa custom standard.
// It is only mandatory for Radxa official overlays.

// Use the same spi2 definition as in rk3308-spi2-spidev.dts
&spi2 {
        status = "okay";
        pinctrl-names = "default";
        // Need to check if you are using the same pin for SPI2
        // which was documented in the rk3308-spi2-spidev.dts as metadata.exclusive
        // "GPIO1_DO", "GPIO0_A1", "GPIO1_C6", "GPIO1_C7"
        pinctrl-0 = <&spi2_clk &spi2_csn0 &spi2_miso &spi2_mosi>;
        #address-cells = <1>;
        #size-cells = <0>;

        // Replace spidev@0 with our own device
        sharp_dev: sharp-dev@0{
                compatible = "sharp";
                reg = <0>;
                pinctrl-names = "default";
                pinctrl-0 = <&sharp_pins>;
                // spi-cs-high = <1>;
                spi-max-frequency = <2000000>;
                buswidth = <8>;
                debug = <0>;

        };
};

// Keep the rk3308-spi2-spidev.dts disabled devices so SPI2 can work
&uart1 {
        status = "disabled";
};

&uart2 {
        status = "disabled";
};

// Add Rockchip pinctrl to set pins as GPIO
&pinctrl {
        sharp {
                sharp_pins: sharp-pins {
                        // rockchip,pins is an array, so you can define multiple pins here.
                        // You might need to adjust pcfg_pull_none to some other value
                        rockchip,pins = <2 RK_PB7 RK_FUNC_GPIO &pcfg_pull_none>,
                                                        <2 RK_PB3 RK_FUNC_GPIO &pcfg_pull_none>;
                };
        };
        spi2{
                spi2_csn0: spi2-csn0 {
                        rockchip,pins = <0 RK_PA1 3 &pcfg_pull_up_4ma>;
                };
        };
};

// Since GPIO2_A7 and GPIO2_B1 is not used by other devices, we are done here.
// Otherwise, we will also need to disable them like UART1/2 above.

Excellent, it’s working! thank you very much. I can see in the screen the logging to tty1. But the console Im typing in is the serial-console in ttyS0.
In the Raspberry Pi I would go to /boot/cmdline.txt and add the parameter “fbcon=map:10” How I should do it here in Radxa? There is no such file to parse boot parameters.
Also, where should I fix the framebuffer_height and framebuffer_width? Again, in Raspberry I would do it in /boot/config.txt, but there is not such file in radxa.

Hi, Victor:
Please try adding cmdline to the append entry in /boot/extlinux/extlinux.conf

1 Like

thanks, its working