From: Yajun Deng <yajun.deng@linux.dev>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: andrew@lunn.ch, olteanv@gmail.com, hkallweit1@gmail.com,
linux@armlinux.org.uk, przemyslaw.kitszel@intel.com,
rmk+kernel@armlinux.org.uk, kabel@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-phy@lists.infradead.org, Yajun Deng <yajun.deng@linux.dev>
Subject: [PATCH net-next v2 2/2] net: phy: Introduce is_phy_device()
Date: Wed, 3 Jan 2024 10:53:34 +0800 [thread overview]
Message-ID: <20240103025334.541682-3-yajun.deng@linux.dev> (raw)
In-Reply-To: <20240103025334.541682-1-yajun.deng@linux.dev>
MDIO_DEVICE_FLAG_PHY is the only flag that can be set in the
struct mdio_device. This flag is used to test that if it is a phy
device.
We can test that the type of the device is equal to mdio_bus_phy_type,
so that, the flags in struct mdio_device can be removed.
Introduce is_phy_device(), use it to test that if the device is a phy
device.
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
drivers/net/phy/mdio_bus.c | 7 +++----
drivers/net/phy/phy_device.c | 8 ++++++--
include/linux/mdio.h | 3 ---
include/linux/phy.h | 1 +
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 69b8ddef9500..a80e6a7cbca5 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -75,7 +75,7 @@ int mdiobus_register_device(struct mdio_device *mdiodev)
if (mdiodev->bus->mdio_map[mdiodev->addr])
return -EBUSY;
- if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
+ if (is_phy_device(&mdiodev->dev)) {
err = mdiobus_register_gpiod(mdiodev);
if (err)
return err;
@@ -125,7 +125,7 @@ struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
if (!mdiodev)
return NULL;
- if (!(mdiodev->flags & MDIO_DEVICE_FLAG_PHY))
+ if (!is_phy_device(&mdiodev->dev))
return NULL;
return container_of(mdiodev, struct phy_device, mdio);
@@ -1345,8 +1345,7 @@ static int mdio_bus_match(struct device *dev, struct device_driver *drv)
struct mdio_device *mdio = to_mdio_device(dev);
/* Both the driver and device must type-match */
- if (is_phy_driver(&mdiodrv->driver) ==
- !(mdio->flags & MDIO_DEVICE_FLAG_PHY))
+ if (is_phy_driver(&mdiodrv->driver) != is_phy_device(&mdio->dev))
return 0;
if (of_driver_match_device(dev, drv))
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 732cfec293dd..1e19956e9e8d 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -640,6 +640,11 @@ static int phy_request_driver_module(struct phy_device *dev, u32 phy_id)
return 0;
}
+bool is_phy_device(struct device *dev)
+{
+ return dev->type == &mdio_bus_phy_type;
+}
+
struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
bool is_c45,
struct phy_c45_device_ids *c45_ids)
@@ -660,7 +665,6 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
mdiodev->bus = bus;
mdiodev->bus_match = phy_bus_match;
mdiodev->addr = addr;
- mdiodev->flags = MDIO_DEVICE_FLAG_PHY;
mdiodev->device_free = phy_mdio_device_free;
mdiodev->device_remove = phy_mdio_device_remove;
mdiodev->reset_state = -1;
@@ -3266,7 +3270,7 @@ struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode)
if (!mdiodev)
return NULL;
- if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
+ if (is_phy_device(&mdiodev->dev))
return to_phy_device(&mdiodev->dev);
put_device(&mdiodev->dev);
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 852f838f52f5..8364e2d0c269 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -37,7 +37,6 @@ struct mdio_device {
/* Bus address of the MDIO device (0-31) */
int addr;
- int flags;
int reset_state;
struct gpio_desc *reset_gpio;
struct reset_control *reset_ctrl;
@@ -50,8 +49,6 @@ static inline struct mdio_device *to_mdio_device(const struct device *dev)
return container_of(dev, struct mdio_device, dev);
}
-#define MDIO_DEVICE_FLAG_PHY 1
-
/* struct mdio_driver: Generic MDIO driver */
struct mdio_driver {
struct device_driver driver;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 603c440f09f6..7d10b44a475b 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -2156,5 +2156,6 @@ module_exit(phy_module_exit)
bool phy_driver_is_genphy(struct phy_device *phydev);
bool phy_driver_is_genphy_10g(struct phy_device *phydev);
bool is_phy_driver(struct device_driver *driver);
+bool is_phy_device(struct device *dev);
#endif /* __PHY_H */
--
2.25.1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2024-01-03 2:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-03 2:53 [PATCH net-next v2 0/2] net: phy: Use is_phy_driver() and is_phy_device() Yajun Deng
2024-01-03 2:53 ` [PATCH net-next v2 1/2] net: phy: Cleanup struct mdio_driver_common and introduce is_phy_driver() Yajun Deng
2024-01-03 2:53 ` Yajun Deng [this message]
2024-01-03 13:54 ` [PATCH net-next v2 0/2] net: phy: Use is_phy_driver() and is_phy_device() Andrew Lunn
2024-01-03 14:00 ` Russell King (Oracle)
2024-01-04 2:02 ` Yajun Deng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240103025334.541682-3-yajun.deng@linux.dev \
--to=yajun.deng@linux.dev \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kabel@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=rmk+kernel@armlinux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).