Add support for MediaTek MT7987/MT7988 built-in 2.5Gb ethernet PHY (v4)
Subsystems (5)
v4 cover Add support for MediaTek MT7987/MT7988 built-in 2.5Gb ethernet PHY (v4)
This patch adds PHY driver for MediaTek MT7987/MT7988 built-in 2.5Gb ethernet PHY.
Changes in v4:
Remove unneeded const from argv[0] used for cmd_process()
Changes in v3:
1. Removed all optional code configured by dt properties
2. Make use of request_firmware_into_buf_via_script() for firmware loading
Changes in v2:
1. rename "pd-disable" property to "half-en"
2. rename "gbe-min-ipg-11-bytes" property to "gbe-min-ipg-11-bytes-en"
3. rename "auto-downshift-disable" property to "auto-downshift-dis"
4. add default settings for "auto-downshift-dis"
5. add default settings for "half-en"
6. add "retrain-dis" property
Weijie Gao (5):
misc: fs_loader: allow returning actual firmware data size in
request_firmware_into_buf_via_script()
misc: fs_loader: allow using long script name in
request_firmware_into_buf_via_script()
net: mediatek: associate PHY device with dts node specified by
phy-handle
net: phy: Add MediaTek built-in 2.5Gb ethernet PHY driver
MAINTAINERS: update ethernet-related file list for MediaTek ARM
platform
MAINTAINERS | 4 +- drivers/misc/fs_loader.c | 15 +- drivers/net/mtk_eth/mtk_eth.c | 4 + drivers/net/phy/Kconfig | 2 + drivers/net/phy/Makefile | 1 + drivers/net/phy/mediatek/Kconfig | 16 + drivers/net/phy/mediatek/Makefile | 4 + drivers/net/phy/mediatek/mtk-2p5ge.c | 627 +++++++++++++++++++++++++ drivers/net/phy/mediatek/mtk-phy-lib.c | 106 +++++ drivers/net/phy/mediatek/mtk.h | 103 ++++ include/fs_loader.h | 4 +- 11 files changed, 876 insertions(+), 10 deletions(-) create mode 100644 drivers/net/phy/mediatek/Kconfig create mode 100644 drivers/net/phy/mediatek/Makefile create mode 100644 drivers/net/phy/mediatek/mtk-2p5ge.c create mode 100644 drivers/net/phy/mediatek/mtk-phy-lib.c create mode 100644 drivers/net/phy/mediatek/mtk.h
Signature · 1 line
2.34.1
PATCH v4 1/5 misc: fs_loader: allow returning actual firmware data size in request_firmware_into_buf_via_script()
It's important to return the actual firmware data size as some firmware files may have no checksum and need the size as the only way for firmware validation check.
---
Changes in v4: none
--- drivers/misc/fs_loader.c | 6 +++++- include/fs_loader.h | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/misc/fs_loader.c +5 -1
@@ -229,7 +229,8 @@ int request_firmware_into_buf(struct udevice *dev, }int request_firmware_into_buf_via_script (void **buf,size_t max_size, -const char *script_name) +const char *script_name, +size_t *retsize) {ulong addr, size;int ret;
@@ -269,6 +270,9 @@ int request_firmware_into_buf_via_script(void **buf, size_t max_size,return -E2BIG ; } +if (retsize) + *retsize = size; +memcpy (*buf, (void *)addr, size);return 0 ;
include/fs_loader.h +3 -1
@@ -71,6 +71,7 @@ int get_fs_loader(struct udevice **dev);* @buf: Pointer to a pointer where the firmware buffer will be stored. * @max_size: Maximum allowed size for the firmware to be loaded. * @script_name: Name of the U-Boot script to execute for firmware loading. +* @retsize: Return the actual firmware data size (optional). * * Executes a U-Boot script (@script_name) that loads firmware into * memory and sets the environment variables 'fw_addr' (address) and
@@ -87,5 +88,6 @@ int get_fs_loader(struct udevice **dev);* Return: 0 on success, negative value on error. */ int request_firmware_into_buf_via_script (void **buf,size_t max_size, -const char *script_name); +const char *script_name, +size_t *retsize);#endif
Signature · 1 line
2.34.1
PATCH v4 2/5 misc: fs_loader: allow using long script name in request_firmware_into_buf_via_script()
In reply to Weijie GaoUse cmd_process() to remove the length limit of script name used for run_command().
---
Changes in v4: Remove unneeded const from argv[0] used for cmd_process()
--- drivers/misc/fs_loader.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/misc/fs_loader.c +3 -6
@@ -232,18 +232,15 @@ int request_firmware_into_buf_via_script(void **buf, size_t max_size,const char *script_name, size_t *retsize) { + char *args[2] = { (char *)"run", (char *)script_name }; +int ret, repeatable;ulong addr, size; -int ret; -char cmd[32 ];if (!buf || !script_name || !max_size)return -EINVAL ; -/* Create command to run the firmware loading script */ -snprintf (cmd,sizeof (cmd),"run %s" , script_name); -/* Run the firmware loading script */ - ret =run_command_list (cmd,-1 ,0 ); + ret =cmd_process (0 ,2 , args, &repeatable,NULL );if (ret) {log_err ("Firmware loading script '%s' not defined or failed.\n" , script_name);
Signature · 1 line
2.34.1
PATCH v4 3/5 net: mediatek: associate PHY device with dts node specified by phy-handle
In reply to Weijie GaoAssociate PHY device with its device node specified by phy-handle property. This makes it possible for PHY drivers to read dedicated information to configure the PHY device.
---
Changes in v4: none
Changes in v3: none
Changes in v2: none
--- drivers/net/mtk_eth/mtk_eth.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/mtk_eth/mtk_eth.c +4 -0
@@ -100,6 +100,7 @@ struct mtk_eth_priv {bool pn_swap;struct phy_device *phydev; +ofnode phy_node;int phy_interface;int phy_addr;
@@ -572,6 +573,7 @@ static int mtk_phy_probe(struct udevice *dev)if (!phydev)return -ENODEV ; + phydev->node = priv->phy_node; phydev->supported &=PHY_GBIT_FEATURES ; phydev->advertising = phydev->supported;
@@ -1458,6 +1460,8 @@ static int mtk_eth_of_to_plat(struct udevice *dev)return ret; } + priv->phy_node = args.node; + priv->phy_addr =ofnode_read_s32_default (args.node,"reg" ,-1 );if (priv->phy_addr <0 ) {printf ("error: phy address is not specified\n" );
Signature · 1 line
2.34.1
PATCH v4 4/5 net: phy: Add MediaTek built-in 2.5Gb ethernet PHY driver
In reply to Weijie GaoThe MediaTek MT7987/MT7988 SoCs features a built-in 2.5Gb PHY connected to GMAC1. The PHY supports 10/100/1000/2500 Mbps full-duplex only.
The PHY requires one or two firmware files. Firmware for MT7988 has already been added to upstream: mediatek/mt7988/i2p5ge-phy-pmb.bin. MT7987 has two firmware files which will be add to upstream later:
i2p5ge-phy-pmb.bin and i2p5ge-phy-DSPBitTb.bin.
Environment variable can be set for firmware data loading:mt7987_i2p5ge_load_pmb_firmware for i2p5ge-phy-pmb.bin mt7987_i2p5ge_load_dspbit_firmware for i2p5ge-phy-DSPBitTb.bin mt7988_i2p5ge_load_pmb_firmware for i2p5ge-phy-pmb.bin
This driver allows dedicated weak functions to be overridden by board to provide the firmware data:mt7987_i2p5ge_get_fw() for MT7987 mt7988_i2p5ge_get_fw() for MT7988
To enable the PHY, add the following not to device tree:
ð1 {
status = "okay";
phy-mode = "xgmii";
phy-handle = <&phy15>;
phy15: ethernet-phy@15 {
compatible = "ethernet-phy-ieee802.3-c45";
reg = <15>;
phy-mode = "xgmii";
};
};---
Changes in v4: none
Changes in v3:
1. Removed all optional code configured by dt properties
2. Make use of request_firmware_into_buf_via_script() for firmware loading
Changes in v2:
1. rename "pd-disable" property to "half-en"
2. rename "gbe-min-ipg-11-bytes" property to "gbe-min-ipg-11-bytes-en"
3. rename "auto-downshift-disable" property to "auto-downshift-dis"
4. add default settings for "auto-downshift-dis"
5. add default settings for "half-en"
6. add "retrain-dis" property
--- drivers/misc/fs_loader.c | 2 +- drivers/net/phy/Kconfig | 2 + drivers/net/phy/Makefile | 1 + drivers/net/phy/mediatek/Kconfig | 16 + drivers/net/phy/mediatek/Makefile | 4 + drivers/net/phy/mediatek/mtk-2p5ge.c | 627 +++++++++++++++++++++++++ drivers/net/phy/mediatek/mtk-phy-lib.c | 106 +++++ drivers/net/phy/mediatek/mtk.h | 103 ++++ 8 files changed, 860 insertions(+), 1 deletion(-) create mode 100644 drivers/net/phy/mediatek/Kconfig create mode 100644 drivers/net/phy/mediatek/Makefile create mode 100644 drivers/net/phy/mediatek/mtk-2p5ge.c create mode 100644 drivers/net/phy/mediatek/mtk-phy-lib.c create mode 100644 drivers/net/phy/mediatek/mtk.h
drivers/misc/fs_loader.c +1 -1
@@ -232,7 +232,7 @@ int request_firmware_into_buf_via_script(void **buf, size_t max_size,const char *script_name, size_t *retsize) { - char *args[2] = { (char *)"run", (char *)script_name }; + char *args[2] = { "run", (char *)script_name };int ret, repeatable;ulong addr, size;
drivers/net/phy/Kconfig +2 -0
@@ -184,6 +184,8 @@ config PHY_MARVELL_10G help Support for the Marvell Alaska MV88X3310 and compatible PHYs. +source "drivers/net/phy/mediatek/Kconfig" + config PHY_MESON_GXL bool "Amlogic Meson GXL Internal PHY support"
drivers/net/phy/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_PHY_ET1011C) += et1011c.o obj-$(CONFIG_PHY_LXT) += lxt.o obj-$(CONFIG_PHY_MARVELL) += marvell.o obj-$(CONFIG_PHY_MARVELL_10G) += marvell10g.o +obj-y += mediatek/ obj-$(CONFIG_PHY_MICREL_KSZ8XXX) += micrel_ksz8xxx.o obj-$(CONFIG_PHY_MICREL_KSZ90X1) += micrel_ksz90x1.o obj-$(CONFIG_PHY_MESON_GXL) += meson-gxl.o
drivers/net/phy/mediatek/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config MTK_NET_PHYLIB + tristate + +config PHY_MEDIATEK_2P5GE + tristate "MediaTek built-in 2.5Gb ethernet PHYs" + depends on OF_CONTROL && (TARGET_MT7987 || TARGET_MT7988) + select MTK_NET_PHYLIB + select FS_LOADER + help + Supports MediaTek SoC built-in 2.5Gb ethernet PHYs. + + This driver requires firmware download for PHY to enable its + functionality. The board can override certian firmware downloading + function to provide the firmware data.
drivers/net/phy/mediatek/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_MTK_NET_PHYLIB) += mtk-phy-lib.o +obj-$(CONFIG_PHY_MEDIATEK_2P5GE) += mtk-2p5ge.o
drivers/net/phy/mediatek/mtk-2p5ge.c new file +627 -0
627 lines not on this page · raw message
drivers/net/phy/mediatek/mtk-phy-lib.c new file +106 -0
106 lines not on this page · raw message
drivers/net/phy/mediatek/mtk.h new file +103 -0
103 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v4 4/5] net: phy: Add MediaTek built-in 2.5Gb ethernet PHY driver
Quoted 32 lines · Weijie Gao
The MediaTek MT7987/MT7988 SoCs features a built-in 2.5Gb PHY connected to GMAC1. The PHY supports 10/100/1000/2500 Mbps full-duplex only.
The PHY requires one or two firmware files. Firmware for MT7988 has already been added to upstream: mediatek/mt7988/i2p5ge-phy-pmb.bin. MT7987 has two firmware files which will be add to upstream later:
i2p5ge-phy-pmb.bin and i2p5ge-phy-DSPBitTb.bin.Environment variable can be set for firmware data loading:
mt7987_i2p5ge_load_pmb_firmwarefor i2p5ge-phy-pmb.binmt7987_i2p5ge_load_dspbit_firmwarefor i2p5ge-phy-DSPBitTb.binmt7988_i2p5ge_load_pmb_firmwarefor i2p5ge-phy-pmb.binThis driver allows dedicated weak functions to be overridden by board to provide the firmware data:
mt7987_i2p5ge_get_fw()for MT7987mt7988_i2p5ge_get_fw()for MT7988To enable the PHY, add the following not to device tree:
ð1 { status = "okay"; phy-mode = "xgmii"; phy-handle = <&phy15>; phy15: ethernet-phy@15 { compatible = "ethernet-phy-ieee802.3-c45"; reg = <15>; phy-mode = "xgmii"; }; };
Quoted 2 lines
Signed-off-by Sky Huang <[email protected]>Signed-off-by Weijie Gao <[email protected]>
Sorry for the late review:
drivers/net/phy/mediatek/Kconfig line 4
Quoted 10 lines
drivers/net/phy/mediatek/Kconfig new file +4
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config MTK_NET_PHYLIB + tristate
A tristate makes no sense in U-Boot, it needs to be bool. I'll fix this in the merge commit while applying.
Signature · 1 line
Tom
PATCH v4 5/5 MAINTAINERS: update ethernet-related file list for MediaTek ARM platform
In reply to Weijie GaoUpdate ethernet-related files for MediaTek ARM platform
---
Changes in v4: none
Changes in v3: none
Changes in v2: none
--- MAINTAINERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
MAINTAINERS +2 -2
@@ -423,6 +423,8 @@ F: drivers/clk/mediatek/ F: drivers/cpu/mtk_cpu.c F: drivers/i2c/mtk_i2c.c F: drivers/mmc/mtk-sd.c +F: drivers/net/mtk_eth/ +F: drivers/net/phy/mediatek/ F: drivers/phy/phy-mtk-* F: drivers/pinctrl/mediatek/ F: drivers/power/domain/mtk-power-domain.c
@@ -437,8 +439,6 @@ F: drivers/timer/mtk_timer.c F: drivers/usb/host/xhci-mtk.c F: drivers/usb/mtu3/ F: drivers/watchdog/mtk_wdt.c -F: drivers/net/mtk_eth.c -F: drivers/net/mtk_eth.h F: drivers/reset/reset-mediatek.c F: drivers/serial/serial_mtk.c F: include/dt-bindings/clock/mediatek,*
Signature · 1 line
2.34.1
Quoted 11 lines · Weijie Gao
This patch adds PHY driver for MediaTek MT7987/MT7988 built-in 2.5Gb ethernet PHY.
Changes in v4:
Remove unneeded const from argv[0] used forcmd_process()Changes in v3:
1. Removed all optional code configured by dt properties
2. Make use ofrequest_firmware_into_buf_via_script()for firmware loading[...]
Applied to u-boot/next, thanks!
[1/5] misc: fs_loader: allow returning actual firmware data size in request_firmware_into_buf_via_script()
commit: 63585689686fee83b382edacad249a4ec35d7c3d
[2/5] misc: fs_loader: allow using long script name in request_firmware_into_buf_via_script()
commit: 5b1d3d83d68a713c492bfad991338d47069f337e
[3/5] net: mediatek: associate PHY device with dts node specified by phy-handle
commit: 465d76a0381dae83942f81329400b1fa2487185a
[4/5] net: phy: Add MediaTek built-in 2.5Gb ethernet PHY driver
commit: b4b266fc139ad0a8856db6a7495f7e9a2cc27a6f
[5/5] MAINTAINERS: update ethernet-related file list for MediaTek ARM platform
commit: 32b4c88ff2712ffafec875e22d866537d2f33dacSignature · 1 line
Tom