Hello,
we were trying to connect KSZ8795 switch via MDIO to imx8qx, but it was wrong, because not all features are supported via SPI. Now we are trying to connect it via SPI, but there is still something amiss. At first we same problems as in KSZ8795-SPI-setup and changed from native chip select to gpio and at least some communication happens with switch.
Kernel is built with following options, .ko files are built and can be loaded with insmod
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
There are two problems.
1. When ksz8795_spi is loaded for the first time it fails with "ksz8795-switch: probe of spi1.0 failed with error -22" .We've checked communication and think that i.MX for some reason toggles spi_clk shortly before communication which causes following communication to fail. Only the first attempt fails. Every next attempt doesn't have this toggle and some data is received in all following attempts. Do you have any idea what could be causing this toggle on spi_clk?
1st spi communication fail
2. After that we rmmod and insmod spi driver again and spi communication looks better this time, e.g. first 4 data transfers are read register 0, and response is 0x8791 which is correct for KSZ8795. However after one more read and 2 write operations nothing else happens, no output in dmesg and "Unable cannot connect to phy" if attempting to up the interface.
spi data
We based our device tree on this example. KSZ8795 is connected to SPI0 and FEC1 is connected to CPU port. There is README for the driver
The KSZ8795 driver creates a virtual MDIO bus and exposes each port in the
switch as a PHY device under that MDIO bus. To access the switch from the
network controller driver a PHY device with PHY id 0 needs to be retrieved
from the virtual MDIO bus. Inside the PHY device's private data is a pointer
to the switch structure. With that pointer all the switch functions can be
accessed.
Unfortunately I don't understand the implications of this description. Is following device tree correct or are there some changes necessary?
&lpspi0 {
#address-cells = <1>;
#size-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_lpspi0>, <&pinctrl_lpspi0_gpio>;
dma-names = "tx","rx";
dmas = <&edma2 1 0 0>, <&edma2 0 0 1>;
clocks = <&clk IMX_SC_R_SPI_0 IMX_SC_PM_CLK_PER>,
<&dma_ipg_clk>;
cs-gpios = <&lsio_gpio1 8 GPIO_ACTIVE_LOW>, <&lsio_gpio1 7 GPIO_ACTIVE_LOW>;
fsl,spi-num-chipselects = <2>;
status = "okay";
ksz8795: ksz8795@0 {
compatible = "microchip,ksz8795";
reg = <0>;
spi-max-frequency = <2000000>;
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 = "lan5";
};
port@5 {
reg = <5>;
label = "cpu";
ethernet = <ðphy0>;
fixed-link {
speed = <1000>;
full-duplex;
};
};
};
};
};
&fec1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_fec1>;
phy-mode = "rgmii-id";
phy-handle = <ðphy0>;
fsl,magic-packet;
local-mac-address = [00 11 22 33 44 55];
status = "okay";
mdio {
#address-cells = <1>;
#size-cells = <0>;
ethphy0: ethernet-phy@0 {
compatible = "ethernet-phy-ieee802.3-c22";
reg = <0>;
fixed-link {
speed = <1000>;
full-duplex;
};
};
};
};
Thank you in advance!
已解决! 转到解答。
For anyone having similar problems.
1. The main problem was cpu port configuration. cpu port is connected directly to fec, so the correct device tree is:
port@4 {
reg = <4>;
label = "cpu";
ethernet = <&fec1>;
fixed-link {
speed = <1000>;
full-duplex;
};
};
&fec1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_fec1>;
phy-mode = "rgmii-id";
fsl,magic-packet;
local-mac-address = [00 11 22 33 44 55];
status = "okay";
fixed-link {
speed = <1000>;
full-duplex;
};
};
2. Another problem were spi-cpha and spi-cpol options in ksz device tree node, we have copied them from some examples, but they are not necessary and were causing strange effects on spi communication and should be removed.
Hi.. @igorpadykov & @sergey_tarassen
Hope you guys are well
I'm also facing a similar issue with the KSZ8795 with i.mx6
In my case, I'm also using the SPI to communicate with the switch
The CPU port is connected with the FEC2
I have also updated the DTS configuration as per the suggestions here
Take a look
&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 = <20000000>;
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>;
phy-mode = "rmii";
fsl,magic-packet;
local-mac-address = [00 11 22 33 44 55];
phy-reset-gpios = <&gpio5 5 GPIO_ACTIVE_LOW>;
phy-reset-duration = <100>;
status = "okay";
fixed-link {
speed = <100>;
full-duplex;
};
};
The modules are configured as lodable (=m)
But unfortunately, I'm also getting a similar error -22 from the SPI during the driver probing
here is the kernel 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
FEC2 is communicating with the CPU port as I got the message "fec 20b4000.ethernet eth0: Link is Up - 1Gbps/Full - flow control off"
In my case, I'm using the native ECSPI1_SS0 slave select rather than the normal GPIO
The kernel version is 5.10
Now , my query is,
1. Do I need to update the drivers provided by the microchip or mentioned here?
2. Do I need to allocate a separate GPIO for the CS ?
here is my original post
https://community.nxp.com/t5/i-MX-Processors/ksz8795-spi-master-spi0-spi-device-register-error/m-p/1...
Thanks
For anyone having similar problems.
1. The main problem was cpu port configuration. cpu port is connected directly to fec, so the correct device tree is:
port@4 {
reg = <4>;
label = "cpu";
ethernet = <&fec1>;
fixed-link {
speed = <1000>;
full-duplex;
};
};
&fec1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_fec1>;
phy-mode = "rgmii-id";
fsl,magic-packet;
local-mac-address = [00 11 22 33 44 55];
status = "okay";
fixed-link {
speed = <1000>;
full-duplex;
};
};
2. Another problem were spi-cpha and spi-cpol options in ksz device tree node, we have copied them from some examples, but they are not necessary and were causing strange effects on spi communication and should be removed.
Hi sergey_tarassen
1. for "toggle spi_clk" issue one can try to use latest Linux 5.4.47_2.2.0 from
source.codeaurora.org/external/imx/linux-imx repository
https://source.codeaurora.org/external/imx/linux-imx/tree/?h=imx_5.4.47_2.2.0
lpspi0 example:
2. may be useful to look at below links for debugging spi switches:
https://community.nxp.com/t5/i-MX-Processors/i-MX6UL-with-KSZ8895-switch-not-working/m-p/766133
https://community.nxp.com/t5/i-MX-Processors/configure-the-ksz8765-5-port-Ethernet-switch/m-p/759455
Best regards
igor
1. Unfortunately there is still the same short drop in SPI CLK, with the new 5.4.47_2.2.0 kernel. Do you have any ideas what else we could check?
2. There is also SPI driver for KSZ8795 provided by microchip for evaluation board.
What do you think, is existing KSZ8795 driver sufficient ( https://source.codeaurora.org/external/imx/linux-imx/tree/drivers/net/dsa/microchip?h=imx_5.4.47_2.2... ) or should the driver from the manufacturer be used?
for 1. recommended to reproduce issue on i.MX8QXP MEK board with Demo Images
and lpspi example:
for 2. seems existing KSZ8795 driver is sufficient
Best regards
igor