@@ -617,7 +617,8 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
617617 return 0 ;
618618}
619619
620- static int dsa_parse_ports_of (struct device_node * dn , struct dsa_switch * ds )
620+ static int dsa_switch_parse_ports_of (struct dsa_switch * ds ,
621+ struct device_node * dn )
621622{
622623 struct device_node * ports , * port ;
623624 struct dsa_port * dp ;
@@ -648,6 +649,39 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
648649 return 0 ;
649650}
650651
652+ static int dsa_switch_parse_member_of (struct dsa_switch * ds ,
653+ struct device_node * dn )
654+ {
655+ u32 m [2 ] = { 0 , 0 };
656+ int sz ;
657+
658+ /* Don't error out if this optional property isn't found */
659+ sz = of_property_read_variable_u32_array (dn , "dsa,member" , m , 2 , 2 );
660+ if (sz < 0 && sz != - EINVAL )
661+ return sz ;
662+
663+ ds -> index = m [1 ];
664+ if (ds -> index >= DSA_MAX_SWITCHES )
665+ return - EINVAL ;
666+
667+ ds -> dst = dsa_tree_touch (m [0 ]);
668+ if (!ds -> dst )
669+ return - ENOMEM ;
670+
671+ return 0 ;
672+ }
673+
674+ static int dsa_switch_parse_of (struct dsa_switch * ds , struct device_node * dn )
675+ {
676+ int err ;
677+
678+ err = dsa_switch_parse_member_of (ds , dn );
679+ if (err )
680+ return err ;
681+
682+ return dsa_switch_parse_ports_of (ds , dn );
683+ }
684+
651685static int dsa_port_parse (struct dsa_port * dp , const char * name ,
652686 struct device * dev )
653687{
@@ -673,7 +707,8 @@ static int dsa_port_parse(struct dsa_port *dp, const char *name,
673707 return 0 ;
674708}
675709
676- static int dsa_parse_ports (struct dsa_chip_data * cd , struct dsa_switch * ds )
710+ static int dsa_switch_parse_ports (struct dsa_switch * ds ,
711+ struct dsa_chip_data * cd )
677712{
678713 bool valid_name_found = false;
679714 struct dsa_port * dp ;
@@ -703,77 +738,41 @@ static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds)
703738 return 0 ;
704739}
705740
706- static int dsa_parse_member_dn (struct device_node * np , u32 * tree , u32 * index )
707- {
708- int err ;
709-
710- * tree = * index = 0 ;
711-
712- err = of_property_read_u32_index (np , "dsa,member" , 0 , tree );
713- if (err ) {
714- /* Does not exist, but it is optional */
715- if (err == - EINVAL )
716- return 0 ;
717- return err ;
718- }
719-
720- err = of_property_read_u32_index (np , "dsa,member" , 1 , index );
721- if (err )
722- return err ;
723-
724- if (* index >= DSA_MAX_SWITCHES )
725- return - EINVAL ;
726-
727- return 0 ;
728- }
729-
730- static int dsa_parse_member (struct dsa_chip_data * pd , u32 * tree , u32 * index )
741+ static int dsa_switch_parse (struct dsa_switch * ds , struct dsa_chip_data * cd )
731742{
732- if (!pd )
733- return - ENODEV ;
743+ ds -> cd = cd ;
734744
735- /* We do not support complex trees with dsa_chip_data */
736- * tree = 0 ;
737- * index = 0 ;
745+ /* We don't support interconnected switches nor multiple trees via
746+ * platform data, so this is the unique switch of the tree.
747+ */
748+ ds -> index = 0 ;
749+ ds -> dst = dsa_tree_touch (0 );
750+ if (!ds -> dst )
751+ return - ENOMEM ;
738752
739- return 0 ;
753+ return dsa_switch_parse_ports ( ds , cd ) ;
740754}
741755
742756static int _dsa_register_switch (struct dsa_switch * ds )
743757{
744758 struct dsa_chip_data * pdata = ds -> dev -> platform_data ;
745759 struct device_node * np = ds -> dev -> of_node ;
746760 struct dsa_switch_tree * dst ;
747- u32 tree , index ;
761+ unsigned int index ;
748762 int i , err ;
749763
750- if (np ) {
751- err = dsa_parse_member_dn (np , & tree , & index );
752- if (err )
753- return err ;
754- } else {
755- err = dsa_parse_member (pdata , & tree , & index );
756- if (err )
757- return err ;
758- }
764+ if (np )
765+ err = dsa_switch_parse_of (ds , np );
766+ else if (pdata )
767+ err = dsa_switch_parse (ds , pdata );
768+ else
769+ err = - ENODEV ;
759770
760- dst = dsa_tree_touch (tree );
761- if (!dst )
762- return - ENOMEM ;
763-
764- ds -> dst = dst ;
765- ds -> index = index ;
766- ds -> cd = pdata ;
771+ if (err )
772+ return err ;
767773
768- if (np ) {
769- err = dsa_parse_ports_of (np , ds );
770- if (err )
771- return err ;
772- } else {
773- err = dsa_parse_ports (pdata , ds );
774- if (err )
775- return err ;
776- }
774+ index = ds -> index ;
775+ dst = ds -> dst ;
777776
778777 /* Initialize the routing table */
779778 for (i = 0 ; i < DSA_MAX_SWITCHES ; ++ i )
0 commit comments