ksz8795 spi_master spi0: spi_device register error

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

ksz8795 spi_master spi0: spi_device register error

1,691 Views
mahendrasondaga
Contributor III

Hello there, 
Hope all are doing well 

I'm dealing with the i.mx6-based SOM with my custom hardware 
I'm using ksz8795 4 port Ethernet switch with using spi

For instance, I'm using Yocto Hardknott BSP provided by Variscite as my SOM is from Variscite 

The device tree configuration is as follows 

 

 

 

&ecspi1 {

		 fsl,spi-num-chipselects = <1>;
		//cs-gpios = <&gpio4 26 0>;
                 pinctrl-names = "default";
        	 pinctrl-0 = <&pinctrl_ecspi1_1>;
        	 status = "okay";

               chip1: spidev@0 {
	               compatible = "var,spidev";
        	       spi-max-frequency = <25000000>;
               	       reg = <0>;
                       status = "okay";
                     };

                      ksz8795@0 {
                      
                         compatible = "microchip,ksz8795";
                         spi-max-frequency = <25000000>;
                         reg = <0>;
                         pinctrl-names = "default";
                         cs-gpios = <&gpio4 26 0>;
                         reset-gpios = <&gpio5 5 0>;
                         status = "okay";

                        //spi-cpha;
                        //spi-cpol;
                       ports {
                             #address-cells = <1>;
                             #size-cells = <0>;
                             port@0 {
                                    reg = <0>;
                                    label = "lan1";
                             };
                             port@1 {
                                    reg = <1>;
                                    label = "lan2";
                             };
                             port@2 {
                                    reg = <2>;
                                    label = "lan3";
                             };
                             port@3 {
                                    reg = <3>;
                                    label = "lan4";
                             };
                             port@4 {
                                    reg = <4>;
                                    label = "cpu";
                                    ethernet = <&fec2>;
                                    fixed-link {
                                               speed = <100>;
                                               full-duplex;
                                    };
                             };
                       };
                   };
};

 

 


Apart from that, I have also activated all necessary drivers from the menu config as follows 

 

CONFIG_NET_DSA=y
CONFIG_NET_DSA_TAG_KSZ=y
CONFIG_NET_DSA_MICROCHIP_KSZ8795=m
CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON=m
CONFIG_NET_DSA_MICROCHIP_KSZ8795_SPI=m
CONFIG_REGMAP_SPI=y

 


For me, the SPI is working well 
However, during the boo time, I got the following errors, and ksz8795 drivers were unable to activate!

 

 

 

root@imx6ul-var-dart:~# dmesg | grep spi
[    2.324211] spi_imx 2008000.spi: registered master spi0
[    2.324649] spi spi0.0: spi_imx_setup: mode 0, 8 bpw, 25000000 hz
[    2.324688] spi spi0.0: setup mode 0, 8 bits/w, 25000000 Hz max --> 0
[    2.325946] spi_imx 2008000.spi: registered child spi0.0
[    2.326022] spi_imx 2008000.spi: chipselect 0 already in use
[    2.331997] spi_master spi0: spi_device register error /soc/bus@2000000/spba-bus@2000000/spi@2008000/ksz8795@0
[    2.342136] spi_master spi0: Failed to create SPI device for /soc/bus@2000000/spba-bus@2000000/spi@2008000/ksz8795@0

 

 

 

 
seems like CS line is utilizing by the spidev
 

Can anyone help me here?
For more information, I have attached dmesg logs here 

All suggestions and comments are welcome  

 

Thanks 

Mahendra 

0 Kudos
5 Replies

1,428 Views
mahendrasondaga
Contributor III

Hi.. @Zhiming_Liu 
First of all Thanks for the feedback 

I got some progress out of it 

Here are the steps that I performed to debug the issue 

1. I wanted to use the SPI to communicate with the ksz8795 and CPU port of the LAN controller is connected with the FEC2
    That's how i'd removed MDIO section from the FEC2

   The new updated DTS files are as follows 

 

 

    &ecspi1 {

                 fsl,spi-num-chipselects = <1>;
                 cs-gpios = <&gpio4 26 GPIO_ACTIVE_LOW>;
                 pinctrl-names = "default";
                 pinctrl-0 = <&pinctrl_ecspi1_1>;
                 status = "okay";

                      ksz8795@0 {                      
                         compatible = "microchip,ksz8795";
                         spi-max-frequency = <25000000>;
                         reg = <0>;
                         pinctrl-names = "default";
                         status = "okay";

                       ports {
                             #address-cells = <1>;
                             #size-cells = <0>;
                             port@0 {
                                    reg = <0>;
                                    label = "lan1";
                             };
                             port@1 {
                                    reg = <1>;
                                    label = "lan2";
                             };
                             port@2 {
                                    reg = <2>;
                                    label = "lan3";
                             };
                             port@3 {
                                    reg = <3>;
                                    label = "lan4";
                             };
                             port@4 {
                                    reg = <4>;
                                    label = "cpu";
                                    ethernet = <&fec2>;
                                    fixed-link {
                                               speed = <100>;
                                               full-duplex;
                                    };
                             };
                       };
                   };
};
       
/* AIO ETH switch node update */
&fec2 {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_enet2>, <&pinctrl_enet2_gpio>
        phy-mode = "rmii";
        phy-reset-gpios=<&gpio5 5 GPIO_ACTIVE_LOW>;
        phy-reset-duration=<100>;
        status = "okay";

        
        fixed-link {
                      speed = <100>;
                      full-duplex;
           };
};

 

 

 

 

2. Erlear I was using the spidev to debug the SPI communication. But once I confirmed that the SPI communication is working well then I removed it from the DTS sub-node as you can see from the above DTS snippets 

Because spidev and KSZ8795 are using the same CS pin of the SPI and that's how it was conflicting!

Right now I have completely removed the spidev subnode from the ecspi1 parent node 

 

3. All supported drivers of the KSZ8795 were selected as the dynamically loadable modules from the menuconfig 
   But somehow it was not installed with the custom image 
   

   As i'd confirmed by checking the "/lib/modules" directory on my custom board 

   The reason is CORE_IMAGE_EXTRA_INSTALL += " kernel-modules" was missing in to my local.conf file 
   By adding it I can see that the drivers are available in "/lib/modules/5.10.72+gb9b6d7d06d4a/kernel/drivers/net/dsa/microchip" directory 

    The listed drivers are ksz8795.ko  ksz8795_spi.ko  and ksz_common.ko

 

4. Finally, now FEC2 is communicating with ksz8795 if I consider the following logs from my kernel 

 

 

 

[   17.902843] Generic PHY fixed-0:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=fixed-0:00, irq=POLL)
[   17.951773] fec 20b4000.ethernet eth0: Link is Up - 100Mbps/Full - flow control off
[   17.997825] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

 

 

   
  5. From the observation of the lsmod command, I can see that the ksz drivers were not automatically loading upon boot 
     The reason is KERNEL_MODULE_AUTOLOAD variable was missing in to local.conf 

That's how, i'd specified It as follows 

 

 

 

KERNEL_MODULE_AUTOLOAD += "ksz_common ksz8795_spi ksz8795"

 

 

 

6. Now from the kernel logs, I can see that the ksz8795 driver forcefully try to load upon boot 
   However, it met with the SPI error 
  here are the Error logs......

root@imx6ul-var-dart:~# dmesg | grep spi
[    2.270526] spi_imx 2008000.spi: registered master spi0
[    2.270963] spi spi0.0: spi_imx_setup: mode 0, 8 bpw, 20000000 hz
[    2.271002] spi spi0.0: setup mode 0, 8 bits/w, 20000000 Hz max --> 0
[    2.271959] spi_imx 2008000.spi: registered child spi0.0
[    7.672984] spi_imx 2008000.spi: mx51_ecspi_clkdiv: fin: 60000000, fspi: 20000000, post: 0, pre: 2
[    7.673040] spi_imx 2008000.spi: mx51_ecspi_clkdiv: fin: 60000000, fspi: 20000000, post: 0, pre: 2
[    7.675620] ksz8795-switch: probe of spi0.0 failed with error -22

 


The error code "-22" typically corresponds to the EINVAL error, which stands for "Invalid argument."

 

Guys, Any suggestions?
Welcome all suggestions and comments 

I have attached the latest kernel logs here 

 

Thanks 

Mahendra

 

 

0 Kudos

1,355 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hi @mahendrasondaga 

I can't find error log in the attachment, please attach demsg log.

 

0 Kudos

1,302 Views
mahendrasondaga
Contributor III

Hi..
pl. find the dmesg logs from here

Recently, instead of using the loadable kernel modules, i have try with the loading the modules statically with the image itself 

 

 

0 Kudos

1,599 Views
mahendrasondaga
Contributor III

Hi... there 
Here is the further investigation and effort from my side 

1.  Disabled spidev sub-node to overcome the CS line occupying issue

2.  KSZ8795 Ethernet switch has the 5 ports of of that, the 5th port is connected with the CPU ENET2 i.e FEC2

here is the DST node for the FEC2

&fec2 {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_enet2>, <&pinctrl_enet2_gpio>, <&pinctrl_enet2_mdio>;
        phy-mode = "rmii";
        phy-handle = <&ethphy1>;
        phy-reset-gpios=<&gpio5 5 GPIO_ACTIVE_LOW>;
        phy-reset-duration=<100>;
        status = "okay";

        mdio {
                #address-cells = <1>;
                #size-cells = <0>;

                ethphy0: ethernet-phy@1 {
                        compatible = "ethernet-phy-ieee802.3-c22";
                        micrel,rmii-reference-clock-select-25-mhz;
                        micrel,led-mode = <1>;
                        clocks = <&rmii_ref_clk>;
                        clock-names = "rmii-ref";
                        reg = <1>;
                };

                ethphy1: ethernet-phy@3 {
                        compatible = "ethernet-phy-ieee802.3-c22";
                        micrel,rmii-reference-clock-select-25-mhz;
                        micrel,led-mode = <0>;
                        clocks = <&rmii_ref_clk>;
                        clock-names = "rmii-ref";
                        reg = <3>;
                };
        };
};


3. SPI & MDIO directories are also populated 

root@imx6ul-var-dart:/sys/bus/spi/devices/spi0.0# ls
consumers  driver_override  modalias  of_node  power  statistics  subsystem  supplier:platform:20a8000.gpio  supplier:platform:20ac000.gpio  suppliers  uevent

 

root@imx6ul-var-dart:/sys/bus/mdio_bus/devices/20b4000.ethernet-1:01# cd of_node
root@imx6ul-var-dart:/sys/bus/mdio_bus/devices/20b4000.ethernet-1:01/of_node# ls
clock-names  clocks  compatible  micrel,led-mode  micrel,rmii-reference-clock-select-25-mhz  name  phandle  reg
root@imx6ul-var-dart:/sys/bus/mdio_bus/devices/20b4000.ethernet-1:01/of_node#


The Error logs are as follows 

root@imx6ul-var-dart:~# dmesg | grep eth0
[    2.488402] fec 20b4000.ethernet eth0: registered PHC device 0
[   17.446500] fec 20b4000.ethernet eth0: Unable to connect to phy
[   19.404484] fec 20b4000.ethernet eth0: Unable to connect to phy


I have also attached the new dmesg logs here 

Thanks 


 

 

0 Kudos

1,479 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hello @mahendrasondaga 

 

From your log. there should be something missed or incorrect in your dts. You can trace phy_connect_direct in  of_phy_connect and fec_enet_adjust_link to figure out where it failed.