Hi there,
I am in the process of trying to get a MCP2515 dual-channel CAN hat to work on my Rock Pi 4C based on the Ubuntu image provided by raxda.
I copied the MCP2515 can0/1 dts overlays from the Raspberry project and adapted them to the RK3399 to my best knowledge. It seem that the first channel (can0) is working property - I can bring the interface up and send messages. However, the second channel is not working - nor is the can1 interface showing up. Note that I did not configure any other overlays and spi1 is enabled in /boot/hw_intfc.conf
On the /sys/bus/spi/devices I can see that both two SPI devices are configured (spi32766.0 and spi32766.1) but it seems the driver is not loaded for the can1 interface.
Compare
root@rockpi4c:/home/rock/overlays# ls /sys/bus/spi/devices/spi32766.0/
driver modalias net of_node power statistics subsystem uevent
vs.
root@rockpi4c:/home/rock/overlays# ls /sys/bus/spi/devices/spi32766.1/
modalias of_node power statistics subsystem uevent
mcp251x-can0.dts
/*
* Device tree overlay for mcp251x/can0 on spi1
*/
/dts-v1/;
/plugin/;
/ {
compatible = "rockchip,rockpi","rockchip,rk3399";
/* enable spi-dev for spi1 */
fragment@0 {
target = <&spi1>;
__overlay__ {
status = "okay";
};
};
/* the interrupt pin of the can-controller */
/* Hat uses physical pin 16 (GPIO4_D2) which converts to gpio 154 */
fragment@1 {
target = <&pinctrl>;
__overlay__ {
can0_pins: can0_pins {
rockchip,pins = <4 154 1 &pcfg_output_low>;
};
};
};
/* the clock/oscillator of the can-controller */
fragment@2 {
target-path = "/";
__overlay__ {
/* external oscillator of mcp2515 on SPI1 */
can0_osc: can0_osc {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <16000000>;
clock-output-names = "can0_osc";
};
};
};
/* the spi config of the can-controller itself binding everything together */
fragment@3 {
target = <&spi1>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
can0: mcp2515@0 {
reg = <0>;
compatible = "microchip,mcp2515";
pinctrl-names = "default";
#pinctrl-0 = <&can0_pins>;
spi-max-frequency = <10000000>;
interrupt-parent = <&gpio4>;
interrupts = <16 8>;
clocks = <&can0_osc>;
};
};
};
__overrides__ {
oscillator = <&can0_osc>,"clock-frequency:0";
spimaxfrequency = <&can0>,"spi-max-frequency:0";
interrupt = <&can0_pins>,"rockchip,pins:0",<&can0>,"interrupts:0";
};
};
mcp251x-can1.dts
/*
* Device tree overlay for mcp251x/can1 on spi1
*/
/dts-v1/;
/plugin/;
/ {
compatible = "rockchip,rockpi","rockchip,rk3399";
/* enable spi-dev for spi1 */
fragment@0 {
target = <&spi1>;
__overlay__ {
status = "okay";
};
};
/* the interrupt pin of the can-controller */
/* Hat uses physical pin 22 (GPIO4_D5) which translate to gpio 157 */
fragment@1 {
target = <&pinctrl>;
__overlay__ {
can1_pins: can1_pins {
rockchip,pins = <4 157 0 &pcfg_output_low>;
};
};
};
/* the clock/oscillator of the can-controller */
fragment@2 {
target-path = "/";
__overlay__ {
/* external oscillator of mcp2515 on SPI1 */
can1_osc: can1_osc {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <16000000>;
clock-output-names = "can1_osc";
};
};
};
/* the spi config of the can-controller itself binding everything together */
fragment@3 {
target = <&spi1>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
can1: mcp2515@1 {
reg = <1>;
compatible = "microchip,mcp2515";
pinctrl-names = "default";
#pinctrl-0 = <&can1_pins>;
spi-max-frequency = <10000000>;
interrupt-parent = <&gpio4>;
interrupts = <22 8>;
clocks = <&can1_osc>;
};
};
};
__overrides__ {
oscillator = <&can1_osc>,"clock-frequency:0";
spimaxfrequency = <&can1>,"spi-max-frequency:0";
interrupt = <&can1_pins>,"rockchip,pins:0",<&can1>,"interrupts:0";
};
};
Both overlays are loaded without errors. The relevant kernel messages are:
[ 2.331552] rockchip-spi ff1d0000.spi: Failed to request TX DMA channel
[ 2.332140] rockchip-spi ff1d0000.spi: Failed to request RX DMA channel
[ 2.332723] rockchip-spi ff1d0000.spi: no high_speed pinctrl state
[ 2.334688] CAN device driver interface
[ 6.699798] mcp251x spi32766.1: Looking up vdd-supply from device tree
[ 6.699815] mcp251x spi32766.1: Looking up vdd-supply property in node /spi@ff1d0000/mcp2515@1 failed
[ 6.699854] mcp251x spi32766.1: Looking up xceiver-supply from device tree
[ 6.699861] mcp251x spi32766.1: Looking up xceiver-supply property in node /spi@ff1d0000/mcp2515@1 failed
[ 6.710252] mcp251x spi32766.0: Looking up vdd-supply from device tree
[ 6.710267] mcp251x spi32766.0: Looking up vdd-supply property in node /spi@ff1d0000/mcp2515@0 failed
[ 6.710292] mcp251x spi32766.0: Looking up xceiver-supply from device tree
[ 6.710299] mcp251x spi32766.0: Looking up xceiver-supply property in node /spi@ff1d0000/mcp2515@0 failed
[ 6.720410] mcp251x spi32766.0: CANCTRL 0x87
[ 154.887431] mcp251x spi32766.0: CNF: 0x09 0xb5 0x01
Note that for this particular shield both MCP2515 share the same SPI bus (SPI1). I suspect that the chip select is not working but I have no idea how to verify or fix that. I appreciate any suggestions!
Mat