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)
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>
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>
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
/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.
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 ??
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?
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).
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.
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.
/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.