net: mvpp2: convert FDT access to ofnode API
Convert mvpp2 driver from legacy fdtdec/fdt_* APIs to the ofnode-based interfaces. Replace usage of dev_of_offset(), fdtdec_lookup_phandle(), fdtdec_get_int(), fdt_parent_offset(), and related helpers with their ofnode equivalents, including dev_ofnode(), ofnode_parse_phandle(), ofnode_read_s32_default(), ofnode_get_parent(), and ofnode_for_each_subnode(). Remove direct dependencies on gd->fdt_blob. Main changes: - Use ofnode_valid() instead of integer checks for node presence - Switch fixed-link detection to ofnode_find_subnode() - Replace uclass_get_device_by_of_offset() with uclass_get_device_by_ofnode() - Update subnode iteration and device binding to use ofnode No functional changes. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Peng Fan <peng.fan@nxp.com>
This commit is contained in:
committed by
Jerome Forissier
parent
f603d10d72
commit
dafa6a3603
+21
-26
@@ -4731,33 +4731,32 @@ static int mvpp2_port_init(struct udevice *dev, struct mvpp2_port *port)
|
||||
|
||||
static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port)
|
||||
{
|
||||
int port_node = dev_of_offset(dev);
|
||||
int phy_node;
|
||||
ofnode port_node = dev_ofnode(dev);
|
||||
ofnode phy_node;
|
||||
u32 id;
|
||||
int phyaddr = 0;
|
||||
int fixed_link = 0;
|
||||
ofnode fixed_link;
|
||||
int ret;
|
||||
|
||||
phy_node = fdtdec_lookup_phandle(gd->fdt_blob, port_node, "phy");
|
||||
fixed_link = fdt_subnode_offset(gd->fdt_blob, port_node, "fixed-link");
|
||||
phy_node = ofnode_parse_phandle(port_node, "phy", 0);
|
||||
fixed_link = ofnode_find_subnode(port_node, "fixed-link");
|
||||
|
||||
if (phy_node > 0) {
|
||||
int parent;
|
||||
if (ofnode_valid(phy_node)) {
|
||||
ofnode parent;
|
||||
|
||||
if (fixed_link != -FDT_ERR_NOTFOUND) {
|
||||
if (ofnode_valid(fixed_link)) {
|
||||
/* phy_addr is set to invalid value for fixed links */
|
||||
phyaddr = PHY_MAX_ADDR;
|
||||
} else {
|
||||
phyaddr = fdtdec_get_int(gd->fdt_blob, phy_node,
|
||||
"reg", 0);
|
||||
phyaddr = ofnode_read_s32_default(phy_node, "reg", 0);
|
||||
if (phyaddr < 0) {
|
||||
dev_err(dev, "could not find phy address\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
parent = fdt_parent_offset(gd->fdt_blob, phy_node);
|
||||
ret = uclass_get_device_by_of_offset(UCLASS_MDIO, parent,
|
||||
&port->mdio_dev);
|
||||
parent = ofnode_get_parent(phy_node);
|
||||
ret = uclass_get_device_by_ofnode(UCLASS_MDIO, parent,
|
||||
&port->mdio_dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
} else {
|
||||
@@ -4771,7 +4770,7 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
id = fdtdec_get_int(gd->fdt_blob, port_node, "port-id", -1);
|
||||
id = dev_read_s32_default(dev, "port-id", -1);
|
||||
if (id == -1) {
|
||||
dev_err(dev, "missing port-id value\n");
|
||||
return -EINVAL;
|
||||
@@ -4812,7 +4811,7 @@ static void mvpp2_gpio_init(struct mvpp2_port *port)
|
||||
/* Ports initialization */
|
||||
static int mvpp2_port_probe(struct udevice *dev,
|
||||
struct mvpp2_port *port,
|
||||
int port_node,
|
||||
ofnode port_node,
|
||||
struct mvpp2 *priv)
|
||||
{
|
||||
int err;
|
||||
@@ -5350,8 +5349,7 @@ static int mvpp2_probe(struct udevice *dev)
|
||||
if (!port->base)
|
||||
return -EINVAL;
|
||||
} else {
|
||||
port->gop_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
|
||||
"gop-port-id", -1);
|
||||
port->gop_id = ofnode_read_s32_default(dev_ofnode(dev), "gop-port-id", -1);
|
||||
if (port->gop_id == -1) {
|
||||
dev_err(dev, "missing gop-port-id value\n");
|
||||
return -EINVAL;
|
||||
@@ -5375,7 +5373,7 @@ static int mvpp2_probe(struct udevice *dev)
|
||||
priv->probe_done = 1;
|
||||
}
|
||||
|
||||
err = mvpp2_port_probe(dev, port, dev_of_offset(dev), priv);
|
||||
err = mvpp2_port_probe(dev, port, dev_ofnode(dev), priv);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@@ -5436,13 +5434,11 @@ static struct driver mvpp2_driver = {
|
||||
*/
|
||||
static int mvpp2_base_bind(struct udevice *parent)
|
||||
{
|
||||
const void *blob = gd->fdt_blob;
|
||||
int node = dev_of_offset(parent);
|
||||
struct uclass_driver *drv;
|
||||
struct udevice *dev;
|
||||
struct eth_pdata *plat;
|
||||
char *name;
|
||||
int subnode;
|
||||
ofnode subnode;
|
||||
u32 id;
|
||||
int base_id_add;
|
||||
|
||||
@@ -5455,19 +5451,19 @@ static int mvpp2_base_bind(struct udevice *parent)
|
||||
|
||||
base_id_add = base_id;
|
||||
|
||||
fdt_for_each_subnode(subnode, blob, node) {
|
||||
dev_for_each_subnode(subnode, parent) {
|
||||
/* Increment base_id for all subnodes, also the disabled ones */
|
||||
base_id++;
|
||||
|
||||
/* Skip disabled ports */
|
||||
if (!fdtdec_get_is_enabled(blob, subnode))
|
||||
if (!ofnode_is_enabled(subnode))
|
||||
continue;
|
||||
|
||||
plat = calloc(1, sizeof(*plat));
|
||||
if (!plat)
|
||||
return -ENOMEM;
|
||||
|
||||
id = fdtdec_get_int(blob, subnode, "port-id", -1);
|
||||
id = ofnode_read_s32_default(subnode, "port-id", -1);
|
||||
id += base_id_add;
|
||||
|
||||
name = calloc(1, 16);
|
||||
@@ -5478,8 +5474,7 @@ static int mvpp2_base_bind(struct udevice *parent)
|
||||
sprintf(name, "mvpp2-%d", id);
|
||||
|
||||
/* Create child device UCLASS_ETH and bind it */
|
||||
device_bind(parent, &mvpp2_driver, name, plat,
|
||||
offset_to_ofnode(subnode), &dev);
|
||||
device_bind(parent, &mvpp2_driver, name, plat, subnode, &dev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user