SJA1105, access over spi to use sja1105-tool to program

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SJA1105, access over spi to use sja1105-tool to program

1,019 Views
gsally
Contributor II

I have sja1105q switch on an evaluation board.  This is connected via a sc18is606 i2c/spi bridge, connected to a jetson eval kit.  The goal is to be able to use the sja1105 tools to upload the switch's firmware, no interest in using the DSA features of this part.  Currently using the 5.10.104 kernel in a Yocto system for my build.

Is it necessary to use the sja1105 driver for SPI access? When using the driver, during driver startup I can see the spi device being registered:

[ 7.869618] sja1105 spi8.2: setup mode 1, 8 bits/w, 1875000 Hz max --> 0
[ 7.875192] sja1105 spi8.2: Probed switch chip: SJA1105Q
[ 7.876333] sc18is602 8-0028: registered child spi8.2

I can see the corresponding entries in the /sys file system.  I have udev on this system and it should be creating a /dev/spidev node, but it isn't.  Creating a device node by hand (mknod /dev/spidev8.2 c 153 0) resulted in the sja1105-tool failing to open the file (maybe I had the minor number incorrect?)

I tried to create a minimal DT for this device for this purpose, as my interest was getting the SPI interface registered and nothing else. To accomplish this goal my DT entry looked like so (as a child of the i2c/spi bridge DT entry):

sja1105@2 {
    reg = <2>;
    #address-cells = <1>;
    #size-cells = <0>;
    compatible = "nxp,sja1105q";
    spi-cpha = <1>;
    spi-max-frequency = <1875000>;
    /* these settings from datasheet */
    fsl,spi-cs-sck-delay = <100>;
    fsl,spi-sck-cs-delay = <130>;
    ports {
      #address-cells = <1>;
      #size-cells = <0>;
      port@4 {
          /* some faux port, for right now */
          label = "swp5";
          phy-mode = "rgmii";
          reg = <4>;
          ethernet = <&fake_enet>;
          /* Implicit "sja1105,role-mac;" */
          fixed-link {
              speed = <1000>; 
              full-duplex;
          };
      };
   };
};

The driver won't load unless an DT entry for ports exists with a port.  

Switching approaches, I removed the DT entry for the driver and used the standard Linux spidev driver: 

sja1105-spidev@2 {
    reg = <2>;
    compatible = "linux,spidev";
    spi-cpha = <1>;
    spi-max-frequency = <1875000>;
    fsl,spi-cs-sck-delay = <100>;
    fsl,spi-sck-cs-delay = <130>;
};

This resulted in me getting udev to create the device node for me:

root@jetson:/dev# ls -la /dev/spidev8.2
crw------- 1 root root 153, 0 Jan 1 1970 /dev/spidev8.2

But a failure with the firmware upload: 

root@m09jetson:/dev# sja1105-tool config upload
ioctl failed
sja1105_spi_transfer failed
spi_send_packed_buf returned -5
static_config_upload failed
static_config_flush failed
root@m09jetson:/dev# dmesg | tail -10
[ 2250.455763] spidev spi8.2: setup mode 1, 8 bits/w, 1000000 Hz max --> 0
[ 2250.455767] spidev spi8.2: 1000000 Hz (max)
[ 2250.467664] spi_master spi8: failed to transfer one message from queue
[ 6340.641868] spidev spi8.2: setup mode 1, 8 bits/w, 1875000 Hz max --> 0
[ 6340.641879] spidev spi8.2: spi mode 1
[ 6340.641895] spidev spi8.2: setup mode 1, 8 bits/w, 1875000 Hz max --> 0
[ 6340.641899] spidev spi8.2: 8 bits per word
[ 6340.641912] spidev spi8.2: setup mode 1, 8 bits/w, 1000000 Hz max --> 0
[ 6340.641917] spidev spi8.2: 1000000 Hz (max)
[ 6340.653298] spi_master spi8: failed to transfer one message from queue

At this point, given the goal (program L2 switch config via SPI), I'm not sure the best way to go about doing that and I'd appreciate any advice to point me in the right direction. 

Thanks much! 

Tags (3)
0 Kudos
Reply
1 Reply

959 Views
Sabeur
NXP Employee
NXP Employee

Hi, 

I understood that you are using openIL with the mainline DSA driver. Is there a reason for this combination ? 


Actually, if you use a DSA driver, Linux is managing the switch and you can use the Linux tools. In this case you don't need a user space application. 

The OpenIL has its own driver and the sja1105-tool.


The two drivers have a meaningful difference for spidev:

The DSA driver seems to assign the spidev to a dev->priv, while for the openIL driver seems to be "more public".

That would explain, why there is no spidev created when the DSA driver is loaded.

Now, creating the spidev node by hand means that the driver and the user-space application accessing the manually created note compete for access.

Or that the manually created note is not useable (as spi is already occupied by the driver).

 

This hypothesis seems to explain the behavior you were seeing.

If there is no reason to use the combination of openIL and the mainline DSA driver, I recommend to use either the Open Industrial Linux either Real-Time Edge Software (DSA Driver).

 

Best regards,

Sabeur