Re: assignment of spi to can channels

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/16/20 11:43 AM, Sven Schuchmann wrote:
> Hello,
> I have a question regarding the assignment of spi to can channels.
> At this time I see sometimes this:
> 
> [    6.665217] mcp251xfd spi0.0 can0: MCP2518FD rev0.0 (-RX_INT ...
> [    6.675670] mcp251xfd spi1.0 can1: MCP2518FD rev0.0 (-RX_INT ...
> 
> and sometimes this:
> 
> [    6.612654] mcp251xfd spi1.0 can0: MCP2518FD rev0.0 (-RX_INT ...
> [    6.623504] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_INT ...
> 
> Probably asked a thousand times but I did not find
> a solution: How can I fix the assignment from spi0.0 to can0
> and spi1.0 to can1?

The classic solution would be a udev rule in e.g. /etc/udev/rules.d/70-can.rules"

> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi0.0/net/can?", NAME="mcp0"
> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi1.0/net/can?", NAME="mcp1"
> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi2.0/net/can?", NAME="mcp2"
> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi2.1/net/can?", NAME="mcp3"

Figure out the exact DEVPATH with

> udevadm test /sys/class/net/can0
> udevadm test /sys/class/net/can1

Note, with older versions of udev it was possible to rename interfaces within
the same namespace, e.g. use "NAME=can0". I think this doesn't work with newer
udevs anymore, so in this example "mcp?" is used.

The above udev-only approach is from some old documentation I found, but not
tested. I'm using the modern systemd approach...


The modern approach is to use systemd-networkd, this requires systemd > 246, as
the older versions don't have the chip select "-cs-" in the "Path".

/etc/systemd/network/70-mcp251xfd0.link:
> [Match]
> Driver=mcp251xfd
> # RPI3 RPI4
> Path=platform-3f204000.spi-cs-0 platform-fe204000.spi-cs-0
> 
> [Link]
> Name=mcp251xfd0

Again use "udevadm test /sys/class/net/can0", but the "Path" in the .link file
corresponds to ID_PATH from udevadm test. See "man systemd.link" for details.

And use this file to configure the CAN interface.

/etc/systemd/network/80-can.network:
> [Match]
> Name=mcp251x*
> 
> [CAN]
> BitRate=500K
> RestartSec=1s

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux