aboutsummaryrefslogtreecommitdiffstats
path: root/net/dsa/dsa2.c
diff options
context:
space:
mode:
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>2017-10-27 15:55:14 -0400
committerDavid S. Miller <davem@davemloft.net>2017-10-31 22:47:03 -0400
commitfd223e2e66eb076b5dda586db9a5a3c99f76f99a (patch)
tree4b7e73df61eb1f13c3ba39a01781a28c01e017e9 /net/dsa/dsa2.c
parent5b32fe070c2ddf31adc42c26dab8af346b652538 (diff)
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: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa/dsa2.c')
-rw-r--r--net/dsa/dsa2.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 9d57f8dee9a1..a0ee91cd3814 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -590,9 +590,17 @@ static int dsa_dst_parse(struct dsa_switch_tree *dst)
590 return 0; 590 return 0;
591} 591}
592 592
593static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
594{
595 dp->dn = dn;
596
597 return 0;
598}
599
593static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds) 600static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
594{ 601{
595 struct device_node *ports, *port; 602 struct device_node *ports, *port;
603 struct dsa_port *dp;
596 u32 reg; 604 u32 reg;
597 int err; 605 int err;
598 606
@@ -610,22 +618,45 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
610 if (reg >= ds->num_ports) 618 if (reg >= ds->num_ports)
611 return -EINVAL; 619 return -EINVAL;
612 620
613 ds->ports[reg].dn = port; 621 dp = &ds->ports[reg];
622
623 err = dsa_port_parse_of(dp, port);
624 if (err)
625 return err;
614 } 626 }
615 627
616 return 0; 628 return 0;
617} 629}
618 630
631static int dsa_port_parse(struct dsa_port *dp, const char *name,
632 struct device *dev)
633{
634 dp->name = name;
635
636 return 0;
637}
638
619static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds) 639static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds)
620{ 640{
621 bool valid_name_found = false; 641 bool valid_name_found = false;
642 struct dsa_port *dp;
643 struct device *dev;
644 const char *name;
622 unsigned int i; 645 unsigned int i;
646 int err;
623 647
624 for (i = 0; i < DSA_MAX_PORTS; i++) { 648 for (i = 0; i < DSA_MAX_PORTS; i++) {
625 if (!cd->port_names[i]) 649 name = cd->port_names[i];
650 dev = cd->netdev[i];
651 dp = &ds->ports[i];
652
653 if (!name)
626 continue; 654 continue;
627 655
628 ds->ports[i].name = cd->port_names[i]; 656 err = dsa_port_parse(dp, name, dev);
657 if (err)
658 return err;
659
629 valid_name_found = true; 660 valid_name_found = true;
630 } 661 }
631 662