Commit fd223e2e authored by Vivien Didelot's avatar Vivien Didelot Committed by David S. Miller

net: dsa: add port parse functions

Add symmetrical DSA port parsing functions for pdata and device tree,
used to parse and validate a given port node or platform data.

They don't do much for the moment but will be extended later on to
assign a port type and get device references.
Signed-off-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5b32fe07
...@@ -590,9 +590,17 @@ static int dsa_dst_parse(struct dsa_switch_tree *dst) ...@@ -590,9 +590,17 @@ static int dsa_dst_parse(struct dsa_switch_tree *dst)
return 0; return 0;
} }
static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
{
dp->dn = dn;
return 0;
}
static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds) static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
{ {
struct device_node *ports, *port; struct device_node *ports, *port;
struct dsa_port *dp;
u32 reg; u32 reg;
int err; int err;
...@@ -610,22 +618,45 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds) ...@@ -610,22 +618,45 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
if (reg >= ds->num_ports) if (reg >= ds->num_ports)
return -EINVAL; return -EINVAL;
ds->ports[reg].dn = port; dp = &ds->ports[reg];
err = dsa_port_parse_of(dp, port);
if (err)
return err;
} }
return 0; return 0;
} }
static int dsa_port_parse(struct dsa_port *dp, const char *name,
struct device *dev)
{
dp->name = name;
return 0;
}
static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds) static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds)
{ {
bool valid_name_found = false; bool valid_name_found = false;
struct dsa_port *dp;
struct device *dev;
const char *name;
unsigned int i; unsigned int i;
int err;
for (i = 0; i < DSA_MAX_PORTS; i++) { for (i = 0; i < DSA_MAX_PORTS; i++) {
if (!cd->port_names[i]) name = cd->port_names[i];
dev = cd->netdev[i];
dp = &ds->ports[i];
if (!name)
continue; continue;
ds->ports[i].name = cd->port_names[i]; err = dsa_port_parse(dp, name, dev);
if (err)
return err;
valid_name_found = true; valid_name_found = true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment