Sx Dop
Sx Dop

Reputation: 11

Linux device tree compatible property and driver probe with same pin different chip

I have a arm64 linux custom board with a spi-to-can chip, and the chip sometime is mcp2515, sometime is mcp2518fd.But they use different driver (mcp251x.ko/mcp25xxfd.ko). This is my dts:

&spi4 {
        status = "okay";
        canfd@0 {
                compatible = "microchip,mcp2515", "microchip,mcp2518fd";
                reg = <0x0>;
                clocks = <&clk20m>;
                #interrupts = <&gpio3 RK_PB6 IRQ_TYPE_LEVEL_LOW>;
                interrupt-parent = <&gpio3>;
                interrupts = <RK_PB6 IRQ_TYPE_LEVEL_LOW>;
                spi-max-frequency = <4000000>;
        };
};

The question is if the chip is mcp2518fd, kernel only match the first compatible "microchip,mcp2515 and then the driver(mcp251x.ko) probe failed.

Can i modify dts or driver src to meet this demand? If driver probe failed and kernel match next compatible ?

Or the only solution is to merge two driver into one?

Upvotes: 1

Views: 1366

Answers (1)

Ian Abbott
Ian Abbott

Reputation: 17403

The compatible strings are supposed to be in hierarchical order from most specific to most general, e.g. specifying an ID for a specific chip, followed by an ID for a "family" of related chips with a common programming interface (that will usually have less features than the chip-specific programming interfaces). That does not apply in this case, because microchip,mcp2515 and microchip,mcp2518fd refer to different specific chips with no hierarchical relationship.

The device tree node needs to specify which type of SPI-to-CAN controller is fitted. That means you need to load a different .dtb file for each type of board, or have a base .dtb file and load a different "device tree overlay" (.dtbo) file on top of the base .dtb file. Different .dtb files could be chosen by the bootloader based on some stored setting in the bootloader. Different .dtbo files could be loaded by the bootloader or by the Linux operating system based on some stored setting in the bootloader or in the Linux operating system, respectively.

It is possible to load different device tree overlays at runtime in the Linux operating system using the "DT-Overlay configfs interface" (CONFIG_OF_CONFIGFS), but that requires patched kernel sources. The patches can be found at topic/overlays.

Upvotes: 1

Related Questions