Hi Steve, On Wed, Apr 29, 2020 at 01:56:33PM -0700, Steve Longerbeam wrote: > > > On 4/29/20 7:42 AM, Sakari Ailus wrote: > > Hi Steve, > > > > On Sun, Apr 19, 2020 at 05:39:09PM -0700, Steve Longerbeam wrote: > > > Modify the default behavior of media_entity_get_fwnode_pad() (when the > > > entity does not provide the get_fwnode_pad op) to first assume the entity > > > implements a 1:1 mapping between fwnode port number and media pad index. > > > > > > If the 1:1 mapping is not valid, e.g. the port number falls outside the > > > entity's pad index range, or the pad at that port number doesn't match the > > > given direction_flags, fall-back to the previous behavior that searches > > > the entity for the first pad that matches the given direction_flags. > > > > > > The previous default behavior can choose the wrong pad for entities with > > > multiple sink or source pads. With this change the function will choose > > > the correct pad index if the entity implements a 1:1 port to pad mapping > > > at that port. > > > > > > Signed-off-by: Steve Longerbeam <slongerbeam@xxxxxxxxx> > > > --- > > > drivers/media/mc/mc-entity.c | 25 ++++++++++++++++++++----- > > > include/media/media-entity.h | 6 ++++-- > > > 2 files changed, 24 insertions(+), 7 deletions(-) > > > > > > diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c > > > index 12b45e669bcc..b1e0259a58c5 100644 > > > --- a/drivers/media/mc/mc-entity.c > > > +++ b/drivers/media/mc/mc-entity.c > > > @@ -370,22 +370,37 @@ int media_entity_get_fwnode_pad(struct media_entity *entity, > > > unsigned long direction_flags) > > > { > > > struct fwnode_endpoint endpoint; > > > - unsigned int i; > > > int ret; > > > + ret = fwnode_graph_parse_endpoint(fwnode, &endpoint); > > > + if (ret) > > > + return ret; > > > + > > > if (!entity->ops || !entity->ops->get_fwnode_pad) { > > > + unsigned int i; > > > + > > > + /* > > > + * for the default case, first try a 1:1 mapping between > > > + * fwnode port number and pad index. > > > + */ > > > + ret = endpoint.port; > > > + if (ret < entity->num_pads && > > > + (entity->pads[ret].flags & direction_flags)) > > > + return ret; > > Given the 3rd patch, is this one still meant to be here? > > It's true, it's not needed anymore, at least for imx, since all the imx > devices have implemented get_fwnode_pad. I decided to leave it here anyway, > since it does make some sense. But I have no problem removing it and > possibly revisit this later. Please. We could remove the other heuristics and move it into drivers (perhaps with a similar helper), but that's for later. -- Regards, Sakari Ailus