media: entity: add operation to help map DT node to media pad
Subsystems (2)
v2 cover media: entity: add operation to help map DT node to media pad
From: Niklas Söderlund <[email protected]>
Hi,
This series add a new entity operation which will aid capture drivers to map a port/endpoint in DT to a media graph pad.
This series is implemented support for the ongoing ADV748x work by Kieran Bingham. In his work he have a driver which registers more then one subdevice. So when a driver finds this subdevice it must be able to ask the subdevice itself which pad number correspond to the DT endpoint the driver used to bind subdevice in the first place.
This is tested on Renesas H3 and M3-W together with the Renesas CSI-2 and VIN Gen3 driver (posted separately). It is based on top of Sakaris pull request '[GIT PULL FOR v4.13] V4L2 fwnode support'.
* Changes since v1
- Rebased work ontop of Sakaris fwnode branch and make use of the fwnode instead of the raw DT port/reg numbers.
- Do not assume DT port is equal to pad number if the driver do not implement the lookup function. Instead search for the first pad with the correct direction and use that. Thanks Sakari for the suggestion!
- Use ENXIO instead of EINVAL to signal lookup error.
Niklas Söderlund (2):
media: entity: Add pad_from_fwnode entity operation
media: entity: Add media_entity_pad_from_fwnode() function
drivers/media/media-entity.c | 39 +++++++++++++++++++++++++++++++++++++++ include/media/media-entity.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
Signature · 1 line
2.13.0
PATCH v2 1/2 media: entity: Add pad_from_fwnode entity operation
From: Niklas Söderlund <[email protected]>
The optional operation can be used by entities to report how it maps its fwnode endpoints to media pad numbers. This is useful for devices which require advanced mappings of pads.
--- include/media/media-entity.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/media/media-entity.h +6 -0
@@ -21,6 +21,7 @@#include <linux/bitmap.h> #include <linux/bug.h> +#include <linux/fwnode.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/media.h>
@@ -171,6 +172,9 @@ struct media_pad {/** * struct media_entity_operations - Media entity operations +* @pad_from_fwnode: Return the pad number based on a fwnode endpoint. +* This operation can be used to map a fwnode to a +* media pad number. Optional. * @link_setup: Notify the entity of link changes. The operation can * return an error, in which case link setup will be * cancelled. Optional.
@@ -184,6 +188,8 @@ struct media_pad {* mutex held. */ struct media_entity_operations { +int (*pad_from_fwnode)(struct fwnode_endpoint *endpoint, +unsigned int *pad);int (*link_setup)(struct media_entity *entity,const struct media_pad *local,const struct media_pad *remote,u32 flags);
Signature · 1 line
2.13.0
Re: [PATCH v2 1/2] media: entity: Add pad_from_fwnode entity operation
Hi Niklas,
Quoted 34 lines · Niklas S�derlund
From: Niklas S�derlund <[email protected]>
The optional operation can be used by entities to report how it maps its fwnode endpoints to media pad numbers. This is useful for devices which require advanced mappings of pads.
Signed-off-by Niklas S�derlund <[email protected]>--- include/media/media-entity.h | 6 ++++++ 1 file changed, 6 insertions(+)include/media/media-entity.h +4
-0@@ -21,6 +21,7 @@#include <linux/bitmap.h> #include <linux/bug.h> +#include <linux/fwnode.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/media.h> @@ -171,6 +172,9 @@ struct media_pad {/** * struct media_entity_operations - Media entity operations +* @pad_from_fwnode: Return the pad number based on a fwnode endpoint. +* This operation can be used to map a fwnode to a +* media pad number. Optional. * @link_setup: Notify the entity of link changes. The operation can * return an error, in which case link setup will be * cancelled. Optional.
include/media/media-entity.h struct media_pad { · line 192
Quoted 5 lines
include/media/media-entity.h +2
-0@@ -184,6 +188,8 @@ struct media_pad {* mutex held. */ struct media_entity_operations { +int (*pad_from_fwnode)(struct fwnode_endpoint *endpoint, +unsigned int *pad);
Hmm. How about calling this get_fwnode_pad for instance? I wonder what others think.
You could just return the pad number still, and a negative value on error. I think we won't have more than INT_MAX pads. :-)
Quoted 3 lines
include/media/media-entity.h +0
-0int (*link_setup)(struct media_entity *entity,const struct media_pad *local,const struct media_pad *remote,u32 flags);
Signature · 4 lines
Regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
Re: [PATCH v2 1/2] media: entity: Add pad_from_fwnode entity operation
Hi Sakari,
Thanks for your feedback.
Quoted 37 lines · Sakari Ailus
Hi Niklas,
Quoted 34 lines · Niklas Söderlund
From: Niklas Söderlund <[email protected]>
The optional operation can be used by entities to report how it maps its fwnode endpoints to media pad numbers. This is useful for devices which require advanced mappings of pads.
Signed-off-by Niklas Söderlund <[email protected]>--- include/media/media-entity.h | 6 ++++++ 1 file changed, 6 insertions(+)include/media/media-entity.h +4
-0@@ -21,6 +21,7 @@#include <linux/bitmap.h> #include <linux/bug.h> +#include <linux/fwnode.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/media.h> @@ -171,6 +172,9 @@ struct media_pad {/** * struct media_entity_operations - Media entity operations +* @pad_from_fwnode: Return the pad number based on a fwnode endpoint. +* This operation can be used to map a fwnode to a +* media pad number. Optional. * @link_setup: Notify the entity of link changes. The operation can * return an error, in which case link setup will be * cancelled. Optional. @@ -184,6 +188,8 @@ struct media_pad {
Quoted 8 lines
include/media/media-entity.h struct media_pad { · line 192
Quoted 5 lines
include/media/media-entity.h +2
-0* mutex held. */ struct media_entity_operations { +int (*pad_from_fwnode)(struct fwnode_endpoint *endpoint, +unsigned int *pad);Hmm. How about calling this
get_fwnode_padfor instance? I wonder what others think.
I'm OK with this name change, will update for next version.
Quoted 3 lines
You could just return the pad number still, and a negative value on error. I think we won't have more than
INT_MAXpads. :-)
I did that at first but then I remembered all the review comments I have gotten earlier about using int as the type for pads :-) If you and others agree in this case returning the pad as int or a negative value as error I have no problem chaining this for the next version.
Quoted 10 lines
Quoted 4 lines
include/media/media-entity.h +0
-0int (*link_setup)(struct media_entity *entity,const struct media_pad *local,const struct media_pad *remote,u32 flags);Signature · 4 lines
Regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
Signature · 2 lines
Regards, Niklas Söderlund
Re: [PATCH v2 1/2] media: entity: Add pad_from_fwnode entity operation
Hejssan,
Quoted 54 lines · Niklas S�derlund
Hi Sakari,
Thanks for your feedback.
Quoted 37 lines · Sakari Ailus
Hi Niklas,
Quoted 34 lines · Niklas S�derlund
From: Niklas S�derlund <[email protected]>
The optional operation can be used by entities to report how it maps its fwnode endpoints to media pad numbers. This is useful for devices which require advanced mappings of pads.
Signed-off-by Niklas S�derlund <[email protected]>--- include/media/media-entity.h | 6 ++++++ 1 file changed, 6 insertions(+)include/media/media-entity.h +4
-0@@ -21,6 +21,7 @@#include <linux/bitmap.h> #include <linux/bug.h> +#include <linux/fwnode.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/media.h> @@ -171,6 +172,9 @@ struct media_pad {/** * struct media_entity_operations - Media entity operations +* @pad_from_fwnode: Return the pad number based on a fwnode endpoint. +* This operation can be used to map a fwnode to a +* media pad number. Optional. * @link_setup: Notify the entity of link changes. The operation can * return an error, in which case link setup will be * cancelled. Optional. @@ -184,6 +188,8 @@ struct media_pad {Quoted 8 lines
include/media/media-entity.h struct media_pad { · line 192
Quoted 5 lines
include/media/media-entity.h +2
-0* mutex held. */ struct media_entity_operations { +int (*pad_from_fwnode)(struct fwnode_endpoint *endpoint, +unsigned int *pad);Hmm. How about calling this
get_fwnode_padfor instance? I wonder what others think.I'm OK with this name change, will update for next version.
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
You could just return the pad number still, and a negative value on error. I think we won't have more than
INT_MAXpads. :-)I did that at first but then I remembered all the review comments I have gotten earlier about using int as the type for pads :-) If you and others agree in this case returning the pad as int or a negative value as error I have no problem chaining this for the next version.
unsigned int was proposed for there was no need for negative values. In this case there is.
I don't really have a strong opinion either way. I wonder what Hans or Laurent thinks.
Signature · 4 lines
Regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
PATCH v2 2/2 media: entity: Add media_entity_pad_from_fwnode() function
In reply to Niklas SöderlundFrom: Niklas Söderlund <[email protected]>
This is a wrapper around the media entity pad_from_fwnode operation.
--- drivers/media/media-entity.c | 39 +++++++++++++++++++++++++++++++++++++++ include/media/media-entity.h | 22 ++++++++++++++++++++++ 2 files changed, 61 insertions(+)
drivers/media/media-entity.c +39 -0
@@ -18,6 +18,7 @@#include <linux/bitmap.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/slab.h> #include <media/media-entity.h> #include <media/media-device.h>
@@ -386,6 +387,44 @@ struct media_entity *media_graph_walk_next(struct media_graph *graph) }EXPORT_SYMBOL_GPL (media_graph_walk_next); +int media_entity_pad_from_fwnode (struct media_entity *entity, +struct fwnode_handle *fwnode, +int direction,unsigned int *pad) +{ +struct fwnode_endpoint endpoint; +int i, tmp, ret; + +if (!entity->ops || !entity->ops->pad_from_fwnode) { +for (i =0 ; i < entity->num_pads; i++) { +if (entity->pads[i].flags & direction) { + *pad = i; +return 0 ; + } + } + +return -ENXIO ; + } + + ret =fwnode_graph_parse_endpoint (fwnode, &endpoint); +if (ret) +return ret; + + ret = entity->ops->pad_from_fwnode (&endpoint, &tmp); +if (ret) +return ret; + +if (tmp >= entity->num_pads) +return -ENXIO ; + +if (!(entity->pads[tmp].flags & direction)) +return -ENXIO ; + + *pad = tmp; + +return 0 ; +} +EXPORT_SYMBOL_GPL (media_entity_pad_from_fwnode); +/* ----------------------------------------------------------------------------- * Pipeline management */
include/media/media-entity.h +22 -0
@@ -822,6 +822,28 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad);struct media_entity *media_entity_get (struct media_entity *entity);/** +* media_entity_pad_from_fwnode - Get pad number from fwnode +* +* @entity: The entity +* @fwnode: Pointer to fwnode_handle which should be used to find pad +* @direction: Expected direction of the pad +* @pad: Pointer to pad which will should be filled in +* +* This function can be used to resolve the media pad number from +* a fwnode. This is useful for devices which uses more complex +* mappings of media pads. +* +* If the entity do not implement the pad_from_fwnode() operation +* this function searches the entity for the first pad that matches +* the @direction. +* +* Return: return 0 on success. +*/ +int media_entity_pad_from_fwnode (struct media_entity *entity, +struct fwnode_handle *fwnode, +int direction,unsigned int *pad); + +/** * media_graph_walk_init - Allocate resources used by graph walk. * * @graph: Media graph structure that will be used to walk the graph
Signature · 1 line
2.13.0
Re: [PATCH v2 2/2] media: entity: Add media_entity_pad_from_fwnode() function
Hi Niklas,
Quoted 51 lines · Niklas Söderlund
From: Niklas Söderlund <[email protected]>
This is a wrapper around the media entity
pad_from_fwnodeoperation.Signed-off-by Niklas Söderlund <[email protected]>--- drivers/media/media-entity.c | 39 +++++++++++++++++++++++++++++++++++++++ include/media/media-entity.h | 22 ++++++++++++++++++++++ 2 files changed, 61 insertions(+)drivers/media/media-entity.c +26
-0@@ -18,6 +18,7 @@#include <linux/bitmap.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/slab.h> #include <media/media-entity.h> #include <media/media-device.h> @@ -386,6 +387,44 @@ struct media_entity *media_graph_walk_next(struct media_graph *graph) }EXPORT_SYMBOL_GPL (media_graph_walk_next); +int media_entity_pad_from_fwnode (struct media_entity *entity, +struct fwnode_handle *fwnode, +int direction,unsigned int *pad) +{ +struct fwnode_endpoint endpoint; +int i, tmp, ret; + +if (!entity->ops || !entity->ops->pad_from_fwnode) { +for (i =0 ; i < entity->num_pads; i++) { +if (entity->pads[i].flags & direction) { + *pad = i; +return 0 ; + } + } + +return -ENXIO ; + } + + ret =fwnode_graph_parse_endpoint (fwnode, &endpoint); +if (ret) +return ret; + + ret = entity->ops->pad_from_fwnode (&endpoint, &tmp); +if (ret) +return ret;
drivers/media/media-entity.c struct media_entity *media_graph_walk_next(struct media_graph *graph) · line 424
Quoted 10 lines
drivers/media/media-entity.c +10
-0+ +if (tmp >= entity->num_pads) +return -ENXIO ; + +if (!(entity->pads[tmp].flags & direction)) +return -ENXIO ; + + *pad = tmp; + +return 0 ;
I'd just return the pad number to the caller.
Quoted 11 lines
drivers/media/media-entity.c +3
-0+} +EXPORT_SYMBOL_GPL (media_entity_pad_from_fwnode); +/* ----------------------------------------------------------------------------- * Pipeline management */ include/media/media-entity.h +0
-0
include/media/media-entity.h struct media_pad *media_entity_remote_pad(struct media_pad *pad); · line 829
Quoted 8 lines
include/media/media-entity.h +5
-0@@ -822,6 +822,28 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad);struct media_entity *media_entity_get (struct media_entity *entity);/** +* media_entity_pad_from_fwnode - Get pad number from fwnode +* +* @entity: The entity +* @fwnode: Pointer to fwnode_handle which should be used to find pad +* @direction: Expected direction of the pad
You should document the possible values for this. What would you think about using a bool called e.g. is_sink? I don't have a strong opinion either way though.
Quoted 20 lines
include/media/media-entity.h +17
-0+* @pad: Pointer to pad which will should be filled in +* +* This function can be used to resolve the media pad number from +* a fwnode. This is useful for devices which uses more complex +* mappings of media pads. +* +* If the entity do not implement the pad_from_fwnode() operation +* this function searches the entity for the first pad that matches +* the @direction. +* +* Return: return 0 on success. +*/ +int media_entity_pad_from_fwnode (struct media_entity *entity, +struct fwnode_handle *fwnode, +int direction,unsigned int *pad); + +/** * media_graph_walk_init - Allocate resources used by graph walk. * * @graph: Media graph structure that will be used to walk the graph
Signature · 4 lines
Regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
Re: [PATCH v2 2/2] media: entity: Add media_entity_pad_from_fwnode() function
Hi Sakari,
Thanks for your feedback.
Quoted 58 lines · Sakari Ailus
Hi Niklas,
Quoted 55 lines · Niklas Söderlund
From: Niklas Söderlund <[email protected]>
This is a wrapper around the media entity
pad_from_fwnodeoperation.Signed-off-by Niklas Söderlund <[email protected]>--- drivers/media/media-entity.c | 39 +++++++++++++++++++++++++++++++++++++++ include/media/media-entity.h | 22 ++++++++++++++++++++++ 2 files changed, 61 insertions(+)drivers/media/media-entity.c +30
-0@@ -18,6 +18,7 @@#include <linux/bitmap.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/slab.h> #include <media/media-entity.h> #include <media/media-device.h> @@ -386,6 +387,44 @@ struct media_entity *media_graph_walk_next(struct media_graph *graph) }EXPORT_SYMBOL_GPL (media_graph_walk_next); +int media_entity_pad_from_fwnode (struct media_entity *entity, +struct fwnode_handle *fwnode, +int direction,unsigned int *pad) +{ +struct fwnode_endpoint endpoint; +int i, tmp, ret; + +if (!entity->ops || !entity->ops->pad_from_fwnode) { +for (i =0 ; i < entity->num_pads; i++) { +if (entity->pads[i].flags & direction) { + *pad = i; +return 0 ; + } + } + +return -ENXIO ; + } + + ret =fwnode_graph_parse_endpoint (fwnode, &endpoint); +if (ret) +return ret; + + ret = entity->ops->pad_from_fwnode (&endpoint, &tmp); +if (ret) +return ret; + +if (tmp >= entity->num_pads) +return -ENXIO ; +
Quoted 8 lines
drivers/media/media-entity.c struct media_entity *media_graph_walk_next(struct media_graph *graph) · line 424
Quoted 6 lines
drivers/media/media-entity.c +6
-0+if (!(entity->pads[tmp].flags & direction)) +return -ENXIO ; + + *pad = tmp; + +return 0 ;I'd just return the pad number to the caller.
Depending on if there is any comments about this in the previous patch I switch to returning an int from this function, where a negative value would signal an error.
Quoted 14 lines
Quoted 14 lines
drivers/media/media-entity.c +3
-0+} +EXPORT_SYMBOL_GPL (media_entity_pad_from_fwnode); +/* ----------------------------------------------------------------------------- * Pipeline management */ include/media/media-entity.h +0
-0@@ -822,6 +822,28 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad);struct media_entity *media_entity_get (struct media_entity *entity);
Quoted 10 lines
include/media/media-entity.h struct media_pad *media_entity_remote_pad(struct media_pad *pad); · line 829
Quoted 6 lines
include/media/media-entity.h +5
-0/** +* media_entity_pad_from_fwnode - Get pad number from fwnode +* +* @entity: The entity +* @fwnode: Pointer to fwnode_handle which should be used to find pad +* @direction: Expected direction of the pad You should document the possible values for this. What would you think about using a bool called e.g.
is_sink? I don't have a strong opinion either way though.
Thanks, I think it is better to add documentation about possible values here. If no one else disagrees whit this I will do so in the next version.
Quoted 27 lines
Quoted 21 lines
include/media/media-entity.h +17
-0+* @pad: Pointer to pad which will should be filled in +* +* This function can be used to resolve the media pad number from +* a fwnode. This is useful for devices which uses more complex +* mappings of media pads. +* +* If the entity do not implement the pad_from_fwnode() operation +* this function searches the entity for the first pad that matches +* the @direction. +* +* Return: return 0 on success. +*/ +int media_entity_pad_from_fwnode (struct media_entity *entity, +struct fwnode_handle *fwnode, +int direction,unsigned int *pad); + +/** * media_graph_walk_init - Allocate resources used by graph walk. * * @graph: Media graph structure that will be used to walk the graph Signature · 4 lines
Regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
Signature · 2 lines
Regards, Niklas Söderlund
Re: [PATCH v2 2/2] media: entity: Add media_entity_pad_from_fwnode() function
In reply to Niklas SöderlundQuoted 23 lines · Niklas Söderlund
From: Niklas Söderlund <[email protected]>
This is a wrapper around the media entity
pad_from_fwnodeoperation.Signed-off-by Niklas Söderlund <[email protected]>--- drivers/media/media-entity.c | 39 +++++++++++++++++++++++++++++++++++++++ include/media/media-entity.h | 22 ++++++++++++++++++++++ 2 files changed, 61 insertions(+)drivers/media/media-entity.c +1
-0@@ -18,6 +18,7 @@#include <linux/bitmap.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/slab.h> #include <media/media-entity.h> #include <media/media-device.h>
drivers/media/media-entity.c struct media_entity *media_graph_walk_next(struct media_graph *graph) · line 392
Quoted 6 lines
drivers/media/media-entity.c +3
-0@@ -386,6 +387,44 @@ struct media_entity *media_graph_walk_next(struct media_graph *graph) }EXPORT_SYMBOL_GPL (media_graph_walk_next); +int media_entity_pad_from_fwnode (struct media_entity *entity, +struct fwnode_handle *fwnode, +int direction,unsigned int *pad)
I'd use unsigned int or u32 for the direction: it's a bitmask so 'int' is not really appropriate.
Quoted 43 lines
drivers/media/media-entity.c +35
-0+{ +struct fwnode_endpoint endpoint; +int i, tmp, ret; + +if (!entity->ops || !entity->ops->pad_from_fwnode) { +for (i =0 ; i < entity->num_pads; i++) { +if (entity->pads[i].flags & direction) { + *pad = i; +return 0 ; + } + } + +return -ENXIO ; + } + + ret =fwnode_graph_parse_endpoint (fwnode, &endpoint); +if (ret) +return ret; + + ret = entity->ops->pad_from_fwnode (&endpoint, &tmp); +if (ret) +return ret; + +if (tmp >= entity->num_pads) +return -ENXIO ; + +if (!(entity->pads[tmp].flags & direction)) +return -ENXIO ; + + *pad = tmp; + +return 0 ; +} +EXPORT_SYMBOL_GPL (media_entity_pad_from_fwnode); +/* ----------------------------------------------------------------------------- * Pipeline management */ include/media/media-entity.h +0
-0
include/media/media-entity.h struct media_pad *media_entity_remote_pad(struct media_pad *pad); · line 828
Quoted 7 lines
include/media/media-entity.h +4
-0@@ -822,6 +822,28 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad);struct media_entity *media_entity_get (struct media_entity *entity);/** +* media_entity_pad_from_fwnode - Get pad number from fwnode +* +* @entity: The entity +* @fwnode: Pointer to fwnode_handle which should be used to find pad
* @fwnode: Pointer to the fwnode_handle which should be used to find the pad
include/media/media-entity.h struct media_pad *media_entity_remote_pad(struct media_pad *pad); · line 830
Quoted 2 lines
include/media/media-entity.h +2
-0+* @direction: Expected direction of the pad +* @pad: Pointer to pad which will should be filled in
* @pad: Pointer to the pad which will be filled in
include/media/media-entity.h struct media_pad *media_entity_remote_pad(struct media_pad *pad); · line 833
Quoted 3 lines
include/media/media-entity.h +3
-0+* +* This function can be used to resolve the media pad number from +* a fwnode. This is useful for devices which uses more complex
uses -> use
include/media/media-entity.h struct media_pad *media_entity_remote_pad(struct media_pad *pad); · line 836
Quoted 3 lines
include/media/media-entity.h +3
-0+* mappings of media pads. +* +* If the entity do not implement the pad_from_fwnode() operation
do -> does
include/media/media-entity.h struct media_pad *media_entity_remote_pad(struct media_pad *pad); · line 837
Quoted 1 line
include/media/media-entity.h +1
-0+* this function searches the entity for the first pad that matches
this -> then this
include/media/media-entity.h struct media_pad *media_entity_remote_pad(struct media_pad *pad); · line 849
Quoted 13 lines
include/media/media-entity.h +9
-0+* the @direction. +* +* Return: return 0 on success. +*/ +int media_entity_pad_from_fwnode (struct media_entity *entity, +struct fwnode_handle *fwnode, +int direction,unsigned int *pad); + +/** * media_graph_walk_init - Allocate resources used by graph walk. * * @graph: Media graph structure that will be used to walk the graph
Regards,
Hans