Add support for MediaTek MT7987/MT7988 built-in 2.5Gb ethernet PHY (v3)
Subsystems (5)
v3 cover Add support for MediaTek MT7987/MT7988 built-in 2.5Gb ethernet PHY (v3)
This patch adds PHY driver for MediaTek MT7987/MT7988 built-in 2.5Gb ethernet PHY.
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 v3 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.
--- 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 v3 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().
--- 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 v3 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 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 v3 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 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
PATCH v3 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 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/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 ++++ 7 files changed, 859 insertions(+) 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/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 v3 2/5] misc: fs_loader: allow using long script name in request_firmware_into_buf_via_script()
In reply to Weijie GaoHi,
Quoted 13 lines · On Wed, 3 Sep 2025 16:38:30 +0800 Weijie Gao wrote:
Use
cmd_process()to remove the length limit of script name used forrun_command().Signed-off-by Weijie Gao <[email protected]>--- drivers/misc/fs_loader.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/misc/fs_loader.c +0
-0
drivers/misc/fs_loader.c int request_firmware_into_buf_via_script(void **buf, size_t max_size, · line 236
Quoted 5 lines
drivers/misc/fs_loader.c +1
-0@@ -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 };
const char *args[2] = { "run", script_name };
does not work?
I don't see any need for a non-const 'args' here.
Lothar Waßmann
Re: [PATCH v3 2/5] misc: fs_loader: allow using long script name in request_firmware_into_buf_via_script()
Quoted 31 lines · Lothar Waßmann
External email : Please do not click links or open attachments until you have verified the sender or the content.
Hi,
Quoted 14 lines · On Wed, 3 Sep 2025 16:38:30 +0800 Weijie Gao wrote:
Use
cmd_process()to remove the length limit of script name used forrun_command().Signed-off-by Weijie Gao <[email protected]>--- drivers/misc/fs_loader.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/misc/fs_loader.c +0
-0drivers/misc/fs_loader.c int request_firmware_into_buf_via_script(void · line 237
Quoted 6 lines
drivers/misc/fs_loader.c +1
-0@@ -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 };const char *args[2] = { "run",
script_name};
does not work?
Quoted 1 line
I don't see any need for a non-const 'args' here.
We'll get compiler warning if using const char *[]:
CC drivers/misc/fs_loader.odrivers/misc/fs_loader.c: In function 'request_firmware_into_buf_via_script':drivers/misc/fs_loader.c:243:33: warning: passing argument 3 of 'cmd_process' from incompatible pointer type [-Wincompatible-pointer- types]
243 | ret = cmd_process(0, 2, args, &repeatable, NULL);
| ^~~~
| |
| const char **
In file included from include/image.h:35,
from include/spl.h:17,
from drivers/misc/fs_loader.c:22:include/command.h:278:64: note: expected 'char * const*' but argument is of type 'const char **'
278 | enum command_ret_t cmd_process(int flag, int argc, char *const
argv[],
| ~~~~~~~~~~~~
^~~~~~
Quoted 3 lines
Lothar Waßmann
Re: [PATCH v3 2/5] misc: fs_loader: allow using long script name in request_firmware_into_buf_via_script()
Hi,
Quoted 42 lines · On Thu, 4 Sep 2025 08:23:28 +0800 Weijie Gao wrote:
Quoted 31 lines · Lothar Waßmann
External email : Please do not click links or open attachments until you have verified the sender or the content.
Hi,
Quoted 14 lines · On Wed, 3 Sep 2025 16:38:30 +0800 Weijie Gao wrote:
Use
cmd_process()to remove the length limit of script name used forrun_command().Signed-off-by Weijie Gao <[email protected]>--- drivers/misc/fs_loader.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/misc/fs_loader.c +0
-0drivers/misc/fs_loader.c int request_firmware_into_buf_via_script(void · line 237
Quoted 6 lines
drivers/misc/fs_loader.c +1
-0@@ -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 };const char *args[2] = { "run",
script_name};
does not work?Quoted 1 line
I don't see any need for a non-const 'args' here.
We'll get compiler warning if using const char *[]:
CC
drivers/misc/fs_loader.odrivers/misc/fs_loader.c: In function 'request_firmware_into_buf_via_script':drivers/misc/fs_loader.c:243:33: warning: passing argument 3 of 'cmd_process' from incompatible pointer type [-Wincompatible-pointer- types]
Quoted 5 lines
243 | ret = cmd_process(0, 2, args, &repeatable, NULL);
| ^~~~
| |
| const char **OK. But at least:
char *args[2] = { "run", (char *)script_name };should work...
NB: The right fix would be to change the argument type of cmd_process() (and all functions with similar semantics...) to
"const char *const argv[]", since cmd_process() need not and should not be able to modify any of the strings within argv[].
Lothar Waßmann
Re: [PATCH v3 2/5] misc: fs_loader: allow using long script name in request_firmware_into_buf_via_script()
Hi,
Quoted 60 lines · Lothar Waßmann
External email : Please do not click links or open attachments until you have verified the sender or the content.
Hi,
Quoted 47 lines · On Thu, 4 Sep 2025 08:23:28 +0800 Weijie Gao wrote:
Quoted 35 lines · Lothar Waßmann
External email : Please do not click links or open attachments until
you have verified the sender or the content.Hi,
Quoted 16 lines · On Wed, 3 Sep 2025 16:38:30 +0800 Weijie Gao wrote:
Use
cmd_process()to remove the length limit of script name used
forrun_command().Signed-off-by Weijie Gao <[email protected]>--- drivers/misc/fs_loader.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/misc/fs_loader.c +0
-0@@ -232,18 +232,15 @@ intQuoted 7 lines
request_firmware_into_buf_via_script(void
**buf,size_tmax_size,
const char*script_name,size_t*retsize)
{
+ char *args[2] = { (char *)"run", (char *)script_name };const char *args[2] = { "run",
script_name};
does not work?Quoted 1 line
I don't see any need for a non-const 'args' here.
We'll get compiler warning if using const char *[]:
CC
drivers/misc/fs_loader.odrivers/misc/fs_loader.c: In function 'request_firmware_into_buf_via_script':drivers/misc/fs_loader.c:243:33: warning: passing argument 3 of 'cmd_process' from incompatible pointer type [-Wincompatible- pointer-
types]Quoted 5 lines
243 | ret = cmd_process(0, 2, args, &repeatable, NULL); | ^~~~ | | | const char **
Quoted 3 lines
OK. But at least:
char *args[2] = { "run", (char *)script_name };should work...
You're right. I thought string literals are always const.
Quoted 8 lines
NB: The right fix would be to change the argument type of
cmd_process()
(and all functions with similar semantics...) to
"const char *const argv[]", sincecmd_process()need not and should not
be able to modify any of the strings within argv[].
I agree. But this should be sent in another patch series.
Quoted 3 lines
Lothar Waßmann
Re: [PATCH v3 2/5] misc: fs_loader: allow using long script name in request_firmware_into_buf_via_script()
Hi,
On Fri, 5 Sep 2025 09:26:05 +0800 Weijie Gao wrote:
[...]
Quoted 23 lines
Quoted 15 lines
Quoted 9 lines
We'll get compiler warning if using const char *[]:
CC
drivers/misc/fs_loader.odrivers/misc/fs_loader.c: In function 'request_firmware_into_buf_via_script':drivers/misc/fs_loader.c:243:33: warning: passing argument 3 of 'cmd_process' from incompatible pointer type [-Wincompatible- pointer-
types]Quoted 5 lines
243 | ret = cmd_process(0, 2, args, &repeatable, NULL); | ^~~~ | | | const char **Quoted 3 lines
OK. But at least:
char *args[2] = { "run", (char *)script_name };should work...
You're right. I thought string literals are always const.
Quoted 2 lines
Quoted 9 lines
Quoted 6 lines
NB: The right fix would be to change the argument type of
cmd_process()
(and all functions with similar semantics...) to
"const char *const argv[]", sincecmd_process()need not and should not
be able to modify any of the strings within argv[].I agree. But this should be sent in another patch series.
Above all, this should be considered when designing a new API. There is no reason why a function like cmd_process() should ever be able to modify the strings it gets passed in the argument list, so they should always be declared as 'const char *...'.
Lothar Waßmann