net: phy: nxp-c45-tja11xx: simplify .match_phy_device OP
authorChristian Marangi <ansuelsmth@gmail.com>
Sat, 17 May 2025 20:13:47 +0000 (22:13 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 21 May 2025 22:56:09 +0000 (15:56 -0700)
Simplify .match_phy_device OP by using a generic function and using the
new phy_id PHY driver info instead of hardcoding the matching PHY ID
with new variant for macsec and no_macsec PHYs.

Also make use of PHY_ID_MATCH_MODEL macro and drop PHY_ID_MASK define to
introduce phy_id and phy_id_mask again in phy_driver struct.

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Link: https://patch.msgid.link/20250517201353.5137-4-ansuelsmth@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/nxp-c45-tja11xx.c

index 22921b192a8bf2c8ebe11d20e6f638bc24ba4df9..4c6d905f0a9f7510287d87cae2547c9673af7e5a 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "nxp-c45-tja11xx.h"
 
-#define PHY_ID_MASK                    GENMASK(31, 4)
 /* Same id: TJA1103, TJA1104 */
 #define PHY_ID_TJA_1103                        0x001BB010
 /* Same id: TJA1120, TJA1121 */
@@ -1966,32 +1965,24 @@ static int nxp_c45_macsec_ability(struct phy_device *phydev)
        return macsec_ability;
 }
 
-static int tja1103_match_phy_device(struct phy_device *phydev,
-                                   const struct phy_driver *phydrv)
+static int tja11xx_no_macsec_match_phy_device(struct phy_device *phydev,
+                                             const struct phy_driver *phydrv)
 {
-       return phy_id_compare(phydev->phy_id, PHY_ID_TJA_1103, PHY_ID_MASK) &&
-              !nxp_c45_macsec_ability(phydev);
-}
+       if (!phy_id_compare(phydev->phy_id, phydrv->phy_id,
+                           phydrv->phy_id_mask))
+               return 0;
 
-static int tja1104_match_phy_device(struct phy_device *phydev,
-                                   const struct phy_driver *phydrv)
-{
-       return phy_id_compare(phydev->phy_id, PHY_ID_TJA_1103, PHY_ID_MASK) &&
-              nxp_c45_macsec_ability(phydev);
+       return !nxp_c45_macsec_ability(phydev);
 }
 
-static int tja1120_match_phy_device(struct phy_device *phydev,
-                                   const struct phy_driver *phydrv)
+static int tja11xx_macsec_match_phy_device(struct phy_device *phydev,
+                                          const struct phy_driver *phydrv)
 {
-       return phy_id_compare(phydev->phy_id, PHY_ID_TJA_1120, PHY_ID_MASK) &&
-              !nxp_c45_macsec_ability(phydev);
-}
+       if (!phy_id_compare(phydev->phy_id, phydrv->phy_id,
+                           phydrv->phy_id_mask))
+               return 0;
 
-static int tja1121_match_phy_device(struct phy_device *phydev,
-                                   const struct phy_driver *phydrv)
-{
-       return phy_id_compare(phydev->phy_id, PHY_ID_TJA_1120, PHY_ID_MASK) &&
-              nxp_c45_macsec_ability(phydev);
+       return nxp_c45_macsec_ability(phydev);
 }
 
 static const struct nxp_c45_regmap tja1120_regmap = {
@@ -2064,6 +2055,7 @@ static const struct nxp_c45_phy_data tja1120_phy_data = {
 
 static struct phy_driver nxp_c45_driver[] = {
        {
+               PHY_ID_MATCH_MODEL(PHY_ID_TJA_1103),
                .name                   = "NXP C45 TJA1103",
                .get_features           = nxp_c45_get_features,
                .driver_data            = &tja1103_phy_data,
@@ -2085,9 +2077,10 @@ static struct phy_driver nxp_c45_driver[] = {
                .get_sqi                = nxp_c45_get_sqi,
                .get_sqi_max            = nxp_c45_get_sqi_max,
                .remove                 = nxp_c45_remove,
-               .match_phy_device       = tja1103_match_phy_device,
+               .match_phy_device       = tja11xx_no_macsec_match_phy_device,
        },
        {
+               PHY_ID_MATCH_MODEL(PHY_ID_TJA_1103),
                .name                   = "NXP C45 TJA1104",
                .get_features           = nxp_c45_get_features,
                .driver_data            = &tja1103_phy_data,
@@ -2109,9 +2102,10 @@ static struct phy_driver nxp_c45_driver[] = {
                .get_sqi                = nxp_c45_get_sqi,
                .get_sqi_max            = nxp_c45_get_sqi_max,
                .remove                 = nxp_c45_remove,
-               .match_phy_device       = tja1104_match_phy_device,
+               .match_phy_device       = tja11xx_macsec_match_phy_device,
        },
        {
+               PHY_ID_MATCH_MODEL(PHY_ID_TJA_1120),
                .name                   = "NXP C45 TJA1120",
                .get_features           = nxp_c45_get_features,
                .driver_data            = &tja1120_phy_data,
@@ -2134,9 +2128,10 @@ static struct phy_driver nxp_c45_driver[] = {
                .get_sqi                = nxp_c45_get_sqi,
                .get_sqi_max            = nxp_c45_get_sqi_max,
                .remove                 = nxp_c45_remove,
-               .match_phy_device       = tja1120_match_phy_device,
+               .match_phy_device       = tja11xx_no_macsec_match_phy_device,
        },
        {
+               PHY_ID_MATCH_MODEL(PHY_ID_TJA_1120),
                .name                   = "NXP C45 TJA1121",
                .get_features           = nxp_c45_get_features,
                .driver_data            = &tja1120_phy_data,
@@ -2159,7 +2154,7 @@ static struct phy_driver nxp_c45_driver[] = {
                .get_sqi                = nxp_c45_get_sqi,
                .get_sqi_max            = nxp_c45_get_sqi_max,
                .remove                 = nxp_c45_remove,
-               .match_phy_device       = tja1121_match_phy_device,
+               .match_phy_device       = tja11xx_macsec_match_phy_device,
        },
 };