Skip to content

Commit ac93f1a

Browse files
facchinmMaxPayne86
authored andcommitted
portenta x8: add lan865x T1S driver and dt binding
The driver doesn't currenly work due to the CS being connected to a GPIO pin from H7 :(
1 parent 2c8676f commit ac93f1a

File tree

13 files changed

+2615
-0
lines changed

13 files changed

+2615
-0
lines changed

recipes-bsp/device-tree/lmp-device-tree.bbappend

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ DTB_OVERLAYS:append:portenta-x8 = " \
5353
file://ov_carrier_ditto_base.dts \
5454
file://ov_carrier_mid_ov5647_camera_mipi.dts \
5555
file://ov_carrier_mid_pcie_mini.dts \
56+
file://ov_carrier_mid_pro_demo_t1s.dts \
5657
file://ov_carrier_mid_imx219_camera_mipi.dts \
5758
file://ov_carrier_mid_dsi_panel.dts \
5859
file://ov_carrier_mid_dsi_lds101.dts \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Portenta-X8 dtb overlay file
3+
* Arduino 2023
4+
* Rasp-Tenta base board
5+
* Enable:
6+
* - SPI (SPI1, ecspi1)
7+
*/
8+
9+
/dts-v1/;
10+
/plugin/;
11+
12+
#include "imx8mm-pinfunc.h"
13+
#include <dt-bindings/gpio/gpio.h>
14+
#include <dt-bindings/interrupt-controller/arm-gic.h>
15+
16+
/ {
17+
compatible = "fsl,imx8mm-evk", "fsl,imx8mm";
18+
19+
/* Enable SPI (SPI1) */
20+
fragment@0 {
21+
target = <&ecspi1>;
22+
__overlay__ {
23+
cs-gpios = <&x8h7_gpio 32 GPIO_ACTIVE_LOW>;
24+
status = "okay";
25+
eth4: lan865x@0{
26+
compatible = "microchip,lan865x";
27+
reg = <0>;
28+
pinctrl-names = "default";
29+
interrupt-parent = <&x8h7_gpio>;
30+
interrupts = <29 IRQ_TYPE_LEVEL_HIGH>;
31+
local-mac-address = [14 15 16 11 12 13];
32+
spi-max-frequency = <15000000>;
33+
/* PLCA settings */
34+
plca-enable = /bits/ 8 <1>; /* 1 - PLCA enable, 0 - CSMA/CD enable */
35+
plca-node-id = /bits/ 8 <0>; /* PLCA node id range: 0 to 254 */
36+
plca-node-count = /bits/ 8 <8>; /* PLCA node count range: 1 to 255 */
37+
plca-burst-count = /bits/ 8 <0x0>; /* PLCA burst count range: 0x0 to 0xFF */
38+
plca-burst-timer = /bits/ 8 <0x80>; /* PLCA burst timer */
39+
plca-to-timer = /bits/ 8 <0x20>; /* PLCA TO value */
40+
tx-cut-through-mode = /bits/ 8 <0>; /* 1 - tx cut through mode enable, 0 - Store and forward mode enable */
41+
rx-cut-through-mode = /bits/ 8 <0>; /* 1 - rx cut through mode enable, 0 - Store and forward mode enable */
42+
oa-chunk-size = /bits/ 8 <64>;
43+
oa-protected = /bits/ 8 <0>;
44+
status = "okay";
45+
};
46+
};
47+
};
48+
};
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SUMMARY = "Microchip LAN865x T1S driver"
2+
DESCRIPTION = "Driver for Single pair ethernet chips"
3+
LICENSE = "GPL-2.0-only"
4+
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6"
5+
6+
inherit module
7+
8+
PR = "r1"
9+
PV = "0.1"
10+
11+
SRC_URI = " \
12+
file://Makefile \
13+
file://src/lan865x.c \
14+
file://src/microchip_t1s.c \
15+
file://src/oa_tc6.c \
16+
file://src/oa_tc6.h \
17+
"
18+
19+
S = "${WORKDIR}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
obj-m += microchip_t1s.o
2+
microchip_t1s-y := src/microchip_t1s.o
3+
obj-m += lan865x_t1s.o
4+
lan865x_t1s-y := src/lan865x.o src/oa_tc6.o
5+
6+
SRC := $(shell pwd)
7+
8+
all:
9+
$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules
10+
11+
modules_install:
12+
$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
13+
14+
clean:
15+
rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c
16+
rm -f Module.markers Module.symvers modules.order
17+
rm -rf .tmp_versions Modules.symvers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# LAN865x 10BASE-T1S MAC-PHY Ethernet Linux Driver
2+
3+
This document describes the procedure for configuring the LAN865x hardware and installing driver. These procedures are tested in **Raspberry Pi 4 with Linux Kernel 6.1.21**.
4+
5+
## Setup the hardware
6+
- Connect the Pi 4 Click Shield board on the 40-pin header in Pi 4.
7+
- Pi 4 Click Shield buy link: https://www.mikroe.com/pi-4-click-shield
8+
- Connect the LAN865x on the Mikro Bus slots available on the Pi 4 Click Shield.
9+
- LAN865x Click board buy link: https://www.mikroe.com/two-wire-eth-click
10+
- For more details please refer to the Microchip LAN865x product website:
11+
- [LAN8650](https://www.microchip.com/en-us/product/lan8650)
12+
- [LAN8651](https://www.microchip.com/en-us/product/lan8651)
13+
- Prepare the SD card for Pi 4 with raspian image available in the Pi official website.
14+
- Link to refer: https://www.raspberrypi.com/software/
15+
## Prerequisites
16+
If the Raspberry Pi OS is freshly installed, then the below prerequisites are mandatory before using the driver package. Please make sure the Raspberry Pi is connected with internet because some dependencies need to be installed for driver package installation script.
17+
- Please make sure the **current date and time** of Raspberry Pi is up to date. Can be checked with the below command,
18+
19+
```
20+
$ date
21+
```
22+
- If they are not up to date and if you want to set it manually then use the below example and modify the fields for the current date and time,
23+
```
24+
$ sudo date -s "Wednesday 01 March 2023 02:38:43 PM IST"
25+
```
26+
Link to refer: https://raspberrytips.com/set-date-time-raspberry-pi/
27+
- Please make sure the **apt-get is up to date**. Run the below command to update apt-get,
28+
```
29+
$ sudo apt-get update
30+
```
31+
## Get project files
32+
- Extract the downloaded software package into your local directory using the below command,
33+
34+
```
35+
$ unzip lan865x-linux-driver-0v2.zip
36+
$ cd lan865x-linux-driver-0v2/
37+
```
38+
## Configure and install using script
39+
There are two scripts are available for the user interface. You can use either one of the script to configure LAN865x.
40+
Run the below command if you wan to go with command line interface.
41+
```
42+
$ ./prepare_lan865x_cli.sh
43+
```
44+
**Or** run the below command if you want to go with terminal user interface.
45+
```
46+
$ ./prepare_lan865x_tui.sh
47+
```
48+
**Note:** If the above script is failed to run because of the executable permission then try after running the below commands,
49+
```
50+
$ chmod +x prepare_lan865x_cli.sh
51+
$ chmod +x prepare_lan865x_tui.sh
52+
```
53+
- The script checks for the **dialog**, **device-tree-compiler** and **raspberrypi-kernel-headers** packages installation status and asks for your confirmation to install in case if they are not installed.
54+
- The script provides the following three options to prepare the LAN865x in Raspberry Pi 4.
55+
- **Configure 1st LAN865x (eth1)** - Provides options for configuring PLCA settings, MAC address, IP address and Save & Configure for the 1st LAN865x connected in the Mikroe bus 1 slot.
56+
**Note:** Always do **Save & Configure** in case if you modified something to take effect otherwise your changes will be lost.
57+
- **Configure 2nd LAN865x (eth2)** - Provides options for configuring PLCA settings, MAC address, IP address and Save & Configure for the 2nd LAN865x connected in the Mikroe bus 2 slot.
58+
**Note:** Always do **Save & Configure** in case if you modified something to take effect otherwise your changes will be lost.
59+
- **Install Driver** - Compiles and installs the driver.
60+
- In a fresh installation, **Save & Configure** and **Install Driver** are must even if you want to go with the default values and then **Reboot** the Raspberry Pi.
61+
- Please explore each and every option to get to know about the usage.
62+
- A **reboot** is always required in case you configured any of the above settings to take effect.
63+
64+
**Note**: IP address assignment is done based on the MAC address configuration. An invalid MAC address configuration may lead to a random IP assignment.
65+
## Configure manually
66+
- Open **config.txt** file which is located into the **/boot/** directory with **Superuser** access to include **lan865x device tree overlay**.
67+
- Uncomment the line **#dtparam=spi=on**
68+
- Add the line **dtoverlay=lan865x** after the above line, so the **config.txt** should have the below lines also,
69+
70+
**Command to open the file**,
71+
```
72+
$ sudo vim /boot/config.txt
73+
```
74+
**Contents to add in the file**,
75+
```
76+
dtparam=spi=on
77+
dtoverlay=lan865x
78+
```
79+
**Note:** A sample **config.txt** file with above settings is available in the **config** directory for the reference.
80+
81+
**Configure and compile device tree overlay**,
82+
83+
- The above hardware setup can support the maximum of two LAN865x 10BASE-T1S Ethernet devices and they can be configured in the device tree overlay file **lan865x-overlay.dts** which is located in the **dts** directory. Valid value ranges are commented nearby each property in the **lan865x-overlay.dts** file.
84+
- Edit the desired properties values in the device tree such as,
85+
- local-mac-address
86+
- Enter the desired MAC address
87+
- plca-enable
88+
- 1 - PLCA enable and CSMA/CD disable, 0 - vice versa.
89+
- plca-node-id
90+
- 0 to 254
91+
- plca-node-count
92+
- 1 to 255
93+
- plca-burst-count
94+
- 0x0 to 0xFF
95+
- plca-burst-timer
96+
- 0x0 to 0xFF
97+
- plca-To-timer
98+
- 0x0 to 0xFF
99+
- tx-cut-through-mode
100+
- 1 - Tx cut through mode enable and store & forward mode disable, 0 - vice versa.
101+
- rx-cut-through-mode
102+
- 1 - Rx cut through mode enable and store & forward mode disable, 0 - vice versa.
103+
- oa-chunk-size
104+
- 32 or 64.
105+
- oa-protected
106+
- 1 - OA protected enable, 0 - OA protected disable.
107+
108+
**Command to open the file**,
109+
```
110+
$ vim dts/lan865x-overlay.dts
111+
```
112+
**Note:** Tx and Rx cut through mode will fail if SPI transfer rate is slower than the network transfer rate.
113+
- Make sure the device tree compiler **dtc** is installed in Pi, if not use the below command to install it,
114+
```
115+
$ sudo apt-get install device-tree-compiler
116+
```
117+
- Compile the device tree overlay file **lan865x-overlay.dts** to generate **lan865x.dtbo** using the below command,
118+
```
119+
$ dtc -I dts -O dtb -o lan865x.dtbo dts/lan865x-overlay.dts
120+
```
121+
- Copy the generated **lan865x.dtbo** file into the **/boot/overlays/** directory using the below command,
122+
```
123+
$ sudo cp lan865x.dtbo /boot/overlays/
124+
```
125+
- Now reboot the Pi.
126+
127+
- Steps to compile and load the driver module
128+
- Make sure the **linux headers** are installed in Pi, if not use the below command to install it,
129+
```
130+
$ sudo apt-get --assume-yes install build-essential cmake subversion libncurses5-dev bc bison flex libssl-dev python2
131+
$ sudo wget https://raw.githubusercontent.com/RPi-Distro/rpi-source/master/rpi-source -O /usr/local/bin/rpi-source && sudo chmod +x /usr/local/bin/rpi-source && /usr/local/bin/rpi-source -q --tag-update
132+
$ rpi-source --skip-gcc
133+
```
134+
- Compile the driver using the below command,
135+
```
136+
$ cd lan865x-linux-driver/
137+
$ make
138+
```
139+
- Load the driver using the below command,
140+
```
141+
$ sudo insmod lan865x_t1s.ko
142+
```
143+
- Now you are ready with your 10BASE-T1S ethernet interfaces **eth1** and **eth2**.
144+
- Use the below command to enable better performance in Pi,
145+
```
146+
$ echo performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor > /dev/null
147+
```
148+
**Note:** The above setting needs to be done after every boot.
149+
**Example ethernet configuration**
150+
```
151+
$ sudo ip addr add dev eth1 192.168.10.11/24
152+
$ sudo ip addr add dev eth2 192.168.20.21/24
153+
```
154+
**Tips**
155+
- If you don't want to do the above **driver loading**, **setting scaling_governor** and **ip configuration** in every boot then add those commands in the **/etc/rc.local** file so that they will be executed automatically every time when you boot Pi. For that open the **rc.local** file with superuser permission and add the following lines before **exit 0**,
156+
157+
**Command to open the file**,
158+
```
159+
$ sudo vim /etc/rc.local
160+
```
161+
**Contents to add in the file**,
162+
```
163+
cd <your_local_directory_for_driver_module>
164+
insmod lan865x_t1s.ko
165+
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
166+
sleep 1
167+
sudo ip addr add dev eth1 192.168.10.11/24
168+
sudo ip addr add dev eth2 192.168.20.21/24
169+
```
170+
**OR**
171+
- You can add the IP configuration alone in **dhcpcd.conf** file which is located in the **/etc/** directory like below,
172+
173+
**Command to open the file**,
174+
```
175+
$ vim /etc/dhcpcd.conf
176+
```
177+
**Contents to add in the file**,
178+
```
179+
interface eth1
180+
static ip_address=192.168.10.11/24
181+
interface eth2
182+
static ip_address=192.168.20.21/24
183+
```
184+
## Testing results with iperf3 in RPI 4
185+
- Command on server side and the IP is 192.168.10.12,
186+
```
187+
$ iperf3 -s -i 1
188+
```
189+
- Command on client side and the IP is 192.168.10.11,
190+
```
191+
$ iperf3 -c 192.168.10.12 -b 10M -u -t 86400 -i 1
192+
```
193+
**Test case 1:** Single LAN865x connected and tx cut through mode enabled.
194+
195+
**Result:** Performance around **9.4Mbps**.
196+
197+
**Test case 2:** Single LAN865x connected and tx cut through mode disabled.
198+
199+
**Result:** Performance around **9.4Mbps**.
200+
201+
**Test case 3:** Two LAN865x's are connected and tx cut through mode enabled on both.
202+
203+
**Result:** The total bandwidth configuration should not exceed 10Mbps to achieve the expected performance.
204+
205+
**Test case 4:** Two LAN865x's are connected and tx cut through mode disabled on both.
206+
207+
**Result:** Performance around **5.0Mbps** on both when both LAN865x's are configured as Tx. In case of Rx, the total bandwidth configuration should not exceed more than 10 Mbps to achieve the expected performance.
208+
209+
**Note 1:** Test case 3 and 4 are tested with two networks and also note that the above hardware setup is using **single SPI master** and **two LAN865x SPI slaves**.
210+
211+
**Note 2:** The above tests are performed in RPI 4. Different platforms with dedicated SPI master for each nodes will give better performance than this.
212+
## TODO
213+
- Timestamping according to Open Alliance TC6 is to be implemented.
214+
## References
215+
- [OPEN Alliance TC6 - 10BASE-T1x MAC-PHY Serial Interface specification](https://www.opensig.org/Automotive-Ethernet-Specifications)
216+
- [OPEN Alliance TC6 Protocol Driver for LAN8650/1](https://github.com/MicrochipTech/oa-tc6-lib)
53.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)