Skip to content

Commit 9cad727

Browse files
fancerdavem330
authored andcommitted
net: pcs: xpcs: Add fwnode-based descriptor creation method
It's now possible to have the DW XPCS device defined as a standard platform device for instance in the platform DT-file. Although that functionality is useless unless there is a way to have the device found by the client drivers (STMMAC/DW *MAC, NXP SJA1105 Eth Switch, etc). Provide such ability by means of the xpcs_create_fwnode() method. It needs to be called with the device DW XPCS fwnode instance passed. That node will be then used to find the MDIO-device instance in order to create the DW XPCS descriptor. Note the method semantics and name is similar to what has been recently introduced in the Lynx PCS driver. Signed-off-by: Serge Semin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f6bb3e9 commit 9cad727

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

drivers/net/pcs/pcs-xpcs.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include <linux/delay.h>
1111
#include <linux/pcs/pcs-xpcs.h>
1212
#include <linux/mdio.h>
13+
#include <linux/phy.h>
1314
#include <linux/phylink.h>
15+
#include <linux/property.h>
1416

1517
#include "pcs-xpcs.h"
1618

@@ -1505,6 +1507,16 @@ static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
15051507
return ERR_PTR(ret);
15061508
}
15071509

1510+
/**
1511+
* xpcs_create_mdiodev() - create a DW xPCS instance with the MDIO @addr
1512+
* @bus: pointer to the MDIO-bus descriptor for the device to be looked at
1513+
* @addr: device MDIO-bus ID
1514+
* @interface: requested PHY interface
1515+
*
1516+
* Return: a pointer to the DW XPCS handle if successful, otherwise -ENODEV if
1517+
* the PCS device couldn't be found on the bus and other negative errno related
1518+
* to the data allocation and MDIO-bus communications.
1519+
*/
15081520
struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr,
15091521
phy_interface_t interface)
15101522
{
@@ -1529,6 +1541,44 @@ struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr,
15291541
}
15301542
EXPORT_SYMBOL_GPL(xpcs_create_mdiodev);
15311543

1544+
/**
1545+
* xpcs_create_fwnode() - Create a DW xPCS instance from @fwnode
1546+
* @fwnode: fwnode handle poining to the DW XPCS device
1547+
* @interface: requested PHY interface
1548+
*
1549+
* Return: a pointer to the DW XPCS handle if successful, otherwise -ENODEV if
1550+
* the fwnode device is unavailable or the PCS device couldn't be found on the
1551+
* bus, -EPROBE_DEFER if the respective MDIO-device instance couldn't be found,
1552+
* other negative errno related to the data allocations and MDIO-bus
1553+
* communications.
1554+
*/
1555+
struct dw_xpcs *xpcs_create_fwnode(struct fwnode_handle *fwnode,
1556+
phy_interface_t interface)
1557+
{
1558+
struct mdio_device *mdiodev;
1559+
struct dw_xpcs *xpcs;
1560+
1561+
if (!fwnode_device_is_available(fwnode))
1562+
return ERR_PTR(-ENODEV);
1563+
1564+
mdiodev = fwnode_mdio_find_device(fwnode);
1565+
if (!mdiodev)
1566+
return ERR_PTR(-EPROBE_DEFER);
1567+
1568+
xpcs = xpcs_create(mdiodev, interface);
1569+
1570+
/* xpcs_create() has taken a refcount on the mdiodev if it was
1571+
* successful. If xpcs_create() fails, this will free the mdio
1572+
* device here. In any case, we don't need to hold our reference
1573+
* anymore, and putting it here will allow mdio_device_put() in
1574+
* xpcs_destroy() to automatically free the mdio device.
1575+
*/
1576+
mdio_device_put(mdiodev);
1577+
1578+
return xpcs;
1579+
}
1580+
EXPORT_SYMBOL_GPL(xpcs_create_fwnode);
1581+
15321582
void xpcs_destroy(struct dw_xpcs *xpcs)
15331583
{
15341584
if (!xpcs)

include/linux/pcs/pcs-xpcs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define __LINUX_PCS_XPCS_H
99

1010
#include <linux/clk.h>
11+
#include <linux/fwnode.h>
1112
#include <linux/mdio.h>
1213
#include <linux/phy.h>
1314
#include <linux/phylink.h>
@@ -72,6 +73,8 @@ int xpcs_config_eee(struct dw_xpcs *xpcs, int mult_fact_100ns,
7273
int enable);
7374
struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr,
7475
phy_interface_t interface);
76+
struct dw_xpcs *xpcs_create_fwnode(struct fwnode_handle *fwnode,
77+
phy_interface_t interface);
7578
void xpcs_destroy(struct dw_xpcs *xpcs);
7679

7780
#endif /* __LINUX_PCS_XPCS_H */

0 commit comments

Comments
 (0)