Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: phy: dp83822: Add support for phy_port representation

With the phy_port representation introduced, we can use .attach_port to
populate the port information based on either the straps or the
ti,fiber-mode property. This allows simplifying the probe function and
allow users to override the strapping configuration.

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/20260108080041.553250-5-maxime.chevallier@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Maxime Chevallier and committed by
Jakub Kicinski
333c29a2 589e934d

+45 -26
+45 -26
drivers/net/phy/dp83822.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/of.h> 13 13 #include <linux/phy.h> 14 + #include <linux/phy_port.h> 14 15 #include <linux/netdevice.h> 15 16 #include <linux/bitfield.h> 16 17 ··· 812 811 int i, ret; 813 812 u32 val; 814 813 815 - /* Signal detection for the PHY is only enabled if the FX_EN and the 816 - * SD_EN pins are strapped. Signal detection can only enabled if FX_EN 817 - * is strapped otherwise signal detection is disabled for the PHY. 818 - */ 819 - if (dp83822->fx_enabled && dp83822->fx_sd_enable) 820 - dp83822->fx_signal_det_low = device_property_present(dev, 821 - "ti,link-loss-low"); 822 - if (!dp83822->fx_enabled) 823 - dp83822->fx_enabled = device_property_present(dev, 824 - "ti,fiber-mode"); 825 - 826 814 if (!device_property_read_string(dev, "ti,gpio2-clk-out", &of_val)) { 827 815 if (strcmp(of_val, "mac-if") == 0) { 828 816 dp83822->gpio2_clk_out = DP83822_CLK_SRC_MAC_IF; ··· 940 950 return 0; 941 951 } 942 952 953 + static int dp83822_attach_mdi_port(struct phy_device *phydev, 954 + struct phy_port *port) 955 + { 956 + struct dp83822_private *dp83822 = phydev->priv; 957 + int ret; 958 + 959 + if (port->mediums) { 960 + if (phy_port_is_fiber(port)) 961 + dp83822->fx_enabled = true; 962 + } else { 963 + ret = dp83822_read_straps(phydev); 964 + if (ret) 965 + return ret; 966 + 967 + #if IS_ENABLED(CONFIG_OF_MDIO) 968 + if (dp83822->fx_enabled && dp83822->fx_sd_enable) 969 + dp83822->fx_signal_det_low = 970 + device_property_present(&phydev->mdio.dev, 971 + "ti,link-loss-low"); 972 + 973 + /* ti,fiber-mode is still used for backwards compatibility, but 974 + * has been replaced with the mdi node definition, see 975 + * ethernet-port.yaml 976 + */ 977 + if (!dp83822->fx_enabled) 978 + dp83822->fx_enabled = 979 + device_property_present(&phydev->mdio.dev, 980 + "ti,fiber-mode"); 981 + #endif /* CONFIG_OF_MDIO */ 982 + 983 + if (dp83822->fx_enabled) { 984 + port->mediums = BIT(ETHTOOL_LINK_MEDIUM_BASEF); 985 + } else { 986 + /* This PHY can only to 100BaseTX max, so on 2 pairs */ 987 + port->pairs = 2; 988 + port->mediums = BIT(ETHTOOL_LINK_MEDIUM_BASET); 989 + } 990 + } 991 + 992 + return 0; 993 + } 994 + 943 995 static int dp8382x_probe(struct phy_device *phydev) 944 996 { 945 997 struct dp83822_private *dp83822; ··· 1000 968 1001 969 static int dp83822_probe(struct phy_device *phydev) 1002 970 { 1003 - struct dp83822_private *dp83822; 1004 971 int ret; 1005 972 1006 973 ret = dp8382x_probe(phydev); 1007 974 if (ret) 1008 975 return ret; 1009 976 1010 - dp83822 = phydev->priv; 1011 - 1012 - ret = dp83822_read_straps(phydev); 1013 - if (ret) 1014 - return ret; 1015 - 1016 - ret = dp83822_of_init(phydev); 1017 - if (ret) 1018 - return ret; 1019 - 1020 - if (dp83822->fx_enabled) 1021 - phydev->port = PORT_FIBRE; 1022 - 1023 - return 0; 977 + return dp83822_of_init(phydev); 1024 978 } 1025 979 1026 980 static int dp83826_probe(struct phy_device *phydev) ··· 1190 1172 .led_hw_is_supported = dp83822_led_hw_is_supported, \ 1191 1173 .led_hw_control_set = dp83822_led_hw_control_set, \ 1192 1174 .led_hw_control_get = dp83822_led_hw_control_get, \ 1175 + .attach_mdi_port = dp83822_attach_mdi_port \ 1193 1176 } 1194 1177 1195 1178 #define DP83825_PHY_DRIVER(_id, _name) \