Re: [PATCH v5 5/7] [media] of: move common endpoint parsing to drivers/of

2014-03-06 Thread Laurent Pinchart
Hi Tomi,

On Tuesday 04 March 2014 14:21:09 Tomi Valkeinen wrote:
 On 04/03/14 13:36, Philipp Zabel wrote:
  Am Dienstag, den 04.03.2014, 10:58 +0200 schrieb Tomi Valkeinen:
  [...]

[snip]

  Then, about the get_remote functions: I think there should be only one
  function for that purpose, one that returns the device node that
  contains the remote endpoint.
  
  My reasoning is that the ports and endpoints, and their contents, should
  be private to the device. So the only use to get the remote is to get
  the actual device, to see if it's been probed, or maybe get some video
  API for that device.
  
  of_graph_get_remote_port currently is used in the exynos4-is/fimc-is.c
  v4l2 driver to get the mipi-csi channel id from the remote port, and
  I've started using it in imx-drm-core.c for two cases:
  - given an endpoint on the encoder, find the remote port connected to
it, get the associated drm_crtc, to obtain its the drm_crtc_mask
for encoder-possible_crtcs.
  
  - given an encoder and a connected drm_crtc, walk all endpoints to find
the remote port associated with the drm_crtc, and then use the local
endpoint parent port to determine multiplexer settings.
 
 Ok.
 
 In omapdss each driver handles only the ports and endpoints defined for
 its device, and they can be considered private to that device. The only
 reason to look for the remote endpoint is to find the remote device. To
 me the omapdss model makes sense, and feels logical and sane =). So I
 have to say I'm not really familiar with the model you're using.

I agree with you that most of the content of the remote endpoint should be 
considered private to the remote device and not accessed by the local device 
driver. There is, however, one piece of information from the remote endpoint 
useful to the local device driver, it's the remote port identifier. This can 
be expressed by a phandle, a remote port number, a media entity pad pointer, 
or any other mean, but the information is useful for the local device driver 
to communicate with the remote device driver. For instance a driver could use 
it to ask its video stream source to start the video stream on a given port.

 Of course, the different get_remove_* funcs do no harm, even if we have
 a bunch of them. My point was only about enforcing the correct use of
 the model, where correct is of course subjective =).

-- 
Regards,

Laurent Pinchart


signature.asc
Description: This is a digitally signed message part.


Re: [PATCH v5 5/7] [media] of: move common endpoint parsing to drivers/of

2014-03-05 Thread Tomi Valkeinen
On 04/03/14 17:47, Philipp Zabel wrote:
 Am Dienstag, den 04.03.2014, 14:21 +0200 schrieb Tomi Valkeinen:
 On 04/03/14 13:36, Philipp Zabel wrote:
 [...]
 Can port_node be NULL? Probably only if something is quite wrong, but
 maybe it's safer to return error in that case.

 both of_property_read_u32 and of_node_put can handle port_node == NULL.
 I'll add a WARN_ONCE here as for of_graph_get_next_endpoint and continue
 on.

 Isn't it better to return an error?
 
 I am not sure. We can still correctly parse the endpoint properties of a
 parentless node. All current users ignore the return value anyway. So as
 long as we still do the memset and and set local_node and id, returning
 an error effectively won't change the current behaviour.

Is the parentless node case an error or not? If it's not, we can handle
it silently and return 0, no WARN needed. If it is an error, we should
return an error, even if nobody is currently handling that (which is a
bug in itself, as the function does return an error value, and callers
should handle it).

 Tomi




signature.asc
Description: OpenPGP digital signature


Re: [PATCH v5 5/7] [media] of: move common endpoint parsing to drivers/of

2014-03-04 Thread Tomi Valkeinen
Hi Philipp,

On 27/02/14 19:35, Philipp Zabel wrote:
 This patch adds a new struct of_endpoint which is then embedded in struct
 v4l2_of_endpoint and contains the endpoint properties that are not V4L2
 (or even media) specific: the port number, endpoint id, local device tree
 node and remote endpoint phandle. of_graph_parse_endpoint parses those
 properties and is used by v4l2_of_parse_endpoint, which just adds the
 V4L2 MBUS information to the containing v4l2_of_endpoint structure.

snip

 diff --git a/drivers/of/base.c b/drivers/of/base.c
 index 8ecca7a..ba3cfca 100644
 --- a/drivers/of/base.c
 +++ b/drivers/of/base.c
 @@ -1985,6 +1985,37 @@ struct device_node *of_find_next_cache_node(const 
 struct device_node *np)
  }
  
  /**
 + * of_graph_parse_endpoint() - parse common endpoint node properties
 + * @node: pointer to endpoint device_node
 + * @endpoint: pointer to the OF endpoint data structure
 + *
 + * All properties are optional. If none are found, we don't set any flags.
 + * This means the port has a static configuration and no properties have
 + * to be specified explicitly.
 + * The caller should hold a reference to @node.
 + */
 +int of_graph_parse_endpoint(const struct device_node *node,
 + struct of_endpoint *endpoint)
 +{
 + struct device_node *port_node = of_get_parent(node);

Can port_node be NULL? Probably only if something is quite wrong, but
maybe it's safer to return error in that case.

 + memset(endpoint, 0, sizeof(*endpoint));
 +
 + endpoint-local_node = node;
 + /*
 +  * It doesn't matter whether the two calls below succeed.
 +  * If they don't then the default value 0 is used.
 +  */
 + of_property_read_u32(port_node, reg, endpoint-port);
 + of_property_read_u32(node, reg, endpoint-id);

If the endpoint does not have 'port' as parent (i.e. the shortened
format), the above will return the 'reg' of the device node (with
'device node' I mean the main node, with 'compatible' property).

And generally speaking, if struct of_endpoint is needed, maybe it would
be better to return the struct of_endpoint when iterating the ports and
endpoints. That way there's no need to do parsing afterwards, trying
to figure out if there's a parent port node, but the information is
already at hand.

 +
 + of_node_put(port_node);
 +
 + return 0;
 +}
 +EXPORT_SYMBOL(of_graph_parse_endpoint);
 +
 +/**
   * of_graph_get_next_endpoint() - get next endpoint node
   * @parent: pointer to the parent device node
   * @prev: previous endpoint node, or NULL to get first
 diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
 index 3bbeb60..2b233db 100644
 --- a/include/linux/of_graph.h
 +++ b/include/linux/of_graph.h
 @@ -14,7 +14,21 @@
  #ifndef __LINUX_OF_GRAPH_H
  #define __LINUX_OF_GRAPH_H
  
 +/**
 + * struct of_endpoint - the OF graph endpoint data structure
 + * @port: identifier (value of reg property) of a port this endpoint belongs 
 to
 + * @id: identifier (value of reg property) of this endpoint
 + * @local_node: pointer to device_node of this endpoint
 + */
 +struct of_endpoint {
 + unsigned int port;
 + unsigned int id;
 + const struct device_node *local_node;
 +};

A few thoughts about the iteration, and the API in general.

In the omapdss version I separated iterating ports and endpoints, for
the two reasons:

1) I think there are cases where you may want to have properties in the
port node, for things that are common for all the port's endpoints.

2) if there are multiple ports, I think the driver code is cleaner if
you first take the port, decide what port that is and maybe call a
sub-function, and then iterate the endpoints for that port only.

Both of those are possible with the API in the series, but not very cleanly.

Also, if you just want to iterate the endpoints, it's easy to implement
a helper using the separate port and endpoint iterations.


Then, about the get_remote functions: I think there should be only one
function for that purpose, one that returns the device node that
contains the remote endpoint.

My reasoning is that the ports and endpoints, and their contents, should
be private to the device. So the only use to get the remote is to get
the actual device, to see if it's been probed, or maybe get some video
API for that device.

If the driver model used has some kind of master-driver, which goes
through all the display entities, I think the above is still valid. When
the master-driver follows the remote-link, it still needs to first get
the main device node, as the ports and endpoints make no sense without
the context of the main device node.

 Tomi




signature.asc
Description: OpenPGP digital signature


Re: [PATCH v5 5/7] [media] of: move common endpoint parsing to drivers/of

2014-03-04 Thread Philipp Zabel
Am Freitag, den 28.02.2014, 22:09 +0100 schrieb Sylwester Nawrocki:
[...]
  --- a/drivers/of/base.c
  +++ b/drivers/of/base.c
  @@ -1985,6 +1985,37 @@ struct device_node *of_find_next_cache_node(const 
  struct device_node *np)
}
 
/**
  + * of_graph_parse_endpoint() - parse common endpoint node properties
  + * @node: pointer to endpoint device_node
  + * @endpoint: pointer to the OF endpoint data structure
  + *
  + * All properties are optional. If none are found, we don't set any flags.
  + * This means the port has a static configuration and no properties have
  + * to be specified explicitly.
 
 I don't think these two sentences are needed, it's all described in the
 DT binding documentation. And struct of_endpoint doesn't contain any
 flags field.

Thanks, I'll remove them.

regards
Philipp

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 5/7] [media] of: move common endpoint parsing to drivers/of

2014-03-04 Thread Philipp Zabel
Hi Tomi,

Am Dienstag, den 04.03.2014, 10:58 +0200 schrieb Tomi Valkeinen:
[...]
  +int of_graph_parse_endpoint(const struct device_node *node,
  +   struct of_endpoint *endpoint)
  +{
  +   struct device_node *port_node = of_get_parent(node);
 
 Can port_node be NULL? Probably only if something is quite wrong, but
 maybe it's safer to return error in that case.

both of_property_read_u32 and of_node_put can handle port_node == NULL.
I'll add a WARN_ONCE here as for of_graph_get_next_endpoint and continue
on.

  +   memset(endpoint, 0, sizeof(*endpoint));
  +
  +   endpoint-local_node = node;
  +   /*
  +* It doesn't matter whether the two calls below succeed.
  +* If they don't then the default value 0 is used.
  +*/
  +   of_property_read_u32(port_node, reg, endpoint-port);
  +   of_property_read_u32(node, reg, endpoint-id);
 
 If the endpoint does not have 'port' as parent (i.e. the shortened
 format), the above will return the 'reg' of the device node (with
 'device node' I mean the main node, with 'compatible' property).

Yes, a check for the port_node name is in order.

 And generally speaking, if struct of_endpoint is needed, maybe it would
 be better to return the struct of_endpoint when iterating the ports and
 endpoints. That way there's no need to do parsing afterwards, trying
 to figure out if there's a parent port node, but the information is
 already at hand.

I'd like to keep the iteration separate from parsing so we can
eventually introduce a for_each_endpoint_of_node helper macro around
of_graph_get_next_endpoint.

[...]
 A few thoughts about the iteration, and the API in general.
 
 In the omapdss version I separated iterating ports and endpoints, for
 the two reasons:
 
 1) I think there are cases where you may want to have properties in the
 port node, for things that are common for all the port's endpoints.

 2) if there are multiple ports, I think the driver code is cleaner if
 you first take the port, decide what port that is and maybe call a
 sub-function, and then iterate the endpoints for that port only.

It depends a bit on whether you are actually iterating over individual
ports, or if you are just walking the whole endpoint graph to find
remote devices that have to be added to the component master's waiting
list, for example.

 Both of those are possible with the API in the series, but not very cleanly.

 Also, if you just want to iterate the endpoints, it's easy to implement
 a helper using the separate port and endpoint iterations.

I started out to move an existing (albeit lightly used) API to a common
place so others can use it and improve upon it, too. I'm happy to pile
on fixes directly in this series, but could we separate the improvement
step from the move, for the bigger modifications?

I had no immediate use for the port iteration, so I have taken no steps
to add a function for this. I see no problem to add this later when
somebody needs it, or even rewrite of_graph_get_next_endpoint to use it
if it is feasible. Iterating over endpoints on a given port needs no
helper, as you can just use for_each_child_of_node.

 Then, about the get_remote functions: I think there should be only one
 function for that purpose, one that returns the device node that
 contains the remote endpoint.
 
 My reasoning is that the ports and endpoints, and their contents, should
 be private to the device. So the only use to get the remote is to get
 the actual device, to see if it's been probed, or maybe get some video
 API for that device.

of_graph_get_remote_port currently is used in the exynos4-is/fimc-is.c
v4l2 driver to get the mipi-csi channel id from the remote port, and
I've started using it in imx-drm-core.c for two cases:
- given an endpoint on the encoder, find the remote port connected to
  it, get the associated drm_crtc, to obtain its the drm_crtc_mask
  for encoder-possible_crtcs.
- given an encoder and a connected drm_crtc, walk all endpoints to find
  the remote port associated with the drm_crtc, and then use the local
  endpoint parent port to determine multiplexer settings.

 If the driver model used has some kind of master-driver, which goes
 through all the display entities, I think the above is still valid. When
 the master-driver follows the remote-link, it still needs to first get
 the main device node, as the ports and endpoints make no sense without
 the context of the main device node.

I'm not sure about this. I might just need the remote port node
associated with a remote drm_crtc or drm_encoder structure to find out
which local endpoint I should look at to retrieve configuration.

regards
Philipp

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 5/7] [media] of: move common endpoint parsing to drivers/of

2014-03-04 Thread Tomi Valkeinen
On 04/03/14 13:36, Philipp Zabel wrote:
 Hi Tomi,
 
 Am Dienstag, den 04.03.2014, 10:58 +0200 schrieb Tomi Valkeinen:
 [...]
 +int of_graph_parse_endpoint(const struct device_node *node,
 +   struct of_endpoint *endpoint)
 +{
 +   struct device_node *port_node = of_get_parent(node);

 Can port_node be NULL? Probably only if something is quite wrong, but
 maybe it's safer to return error in that case.
 
 both of_property_read_u32 and of_node_put can handle port_node == NULL.
 I'll add a WARN_ONCE here as for of_graph_get_next_endpoint and continue
 on.

Isn't it better to return an error?

 And generally speaking, if struct of_endpoint is needed, maybe it would
 be better to return the struct of_endpoint when iterating the ports and
 endpoints. That way there's no need to do parsing afterwards, trying
 to figure out if there's a parent port node, but the information is
 already at hand.
 
 I'd like to keep the iteration separate from parsing so we can
 eventually introduce a for_each_endpoint_of_node helper macro around
 of_graph_get_next_endpoint.
 
 [...]
 A few thoughts about the iteration, and the API in general.

 In the omapdss version I separated iterating ports and endpoints, for
 the two reasons:

 1) I think there are cases where you may want to have properties in the
 port node, for things that are common for all the port's endpoints.

 2) if there are multiple ports, I think the driver code is cleaner if
 you first take the port, decide what port that is and maybe call a
 sub-function, and then iterate the endpoints for that port only.
 
 It depends a bit on whether you are actually iterating over individual
 ports, or if you are just walking the whole endpoint graph to find
 remote devices that have to be added to the component master's waiting
 list, for example.

True, but the latter is easily implemented using the separate
port/endpoint iteration. So I see it as a more powerful API.

 Both of those are possible with the API in the series, but not very cleanly.

 Also, if you just want to iterate the endpoints, it's easy to implement
 a helper using the separate port and endpoint iterations.
 
 I started out to move an existing (albeit lightly used) API to a common
 place so others can use it and improve upon it, too. I'm happy to pile
 on fixes directly in this series, but could we separate the improvement
 step from the move, for the bigger modifications?

Yes, I understand that. What I wonder is that which is easier: make it a
public API now, more or less as it was in v4l2, or make it a public API
only when all the improvements we can think of have been made.

So my fear is that the API is now made public, and you and others start
to use it. But I can't use it, as I need things like separate
port/endpoint iteration. I need to add those, which also means that I
need to change all the users of the API, making the task more difficult
than I'd like.

However, this is more of thinking out loud than I don't like the
series. It's a good series =).

 I had no immediate use for the port iteration, so I have taken no steps
 to add a function for this. I see no problem to add this later when
 somebody needs it, or even rewrite of_graph_get_next_endpoint to use it
 if it is feasible. Iterating over endpoints on a given port needs no
 helper, as you can just use for_each_child_of_node.

I would have a helper, which should do some sanity checks, like that the
node names are endpoint.

 Then, about the get_remote functions: I think there should be only one
 function for that purpose, one that returns the device node that
 contains the remote endpoint.

 My reasoning is that the ports and endpoints, and their contents, should
 be private to the device. So the only use to get the remote is to get
 the actual device, to see if it's been probed, or maybe get some video
 API for that device.
 
 of_graph_get_remote_port currently is used in the exynos4-is/fimc-is.c
 v4l2 driver to get the mipi-csi channel id from the remote port, and
 I've started using it in imx-drm-core.c for two cases:
 - given an endpoint on the encoder, find the remote port connected to
   it, get the associated drm_crtc, to obtain its the drm_crtc_mask
   for encoder-possible_crtcs.
 - given an encoder and a connected drm_crtc, walk all endpoints to find
   the remote port associated with the drm_crtc, and then use the local
   endpoint parent port to determine multiplexer settings.

Ok.

In omapdss each driver handles only the ports and endpoints defined for
its device, and they can be considered private to that device. The only
reason to look for the remote endpoint is to find the remote device. To
me the omapdss model makes sense, and feels logical and sane =). So I
have to say I'm not really familiar with the model you're using.

Of course, the different get_remove_* funcs do no harm, even if we have
a bunch of them. My point was only about enforcing the correct use of
the model, where correct is of course 

Re: [PATCH v5 5/7] [media] of: move common endpoint parsing to drivers/of

2014-03-04 Thread Philipp Zabel
Am Dienstag, den 04.03.2014, 14:21 +0200 schrieb Tomi Valkeinen:
 On 04/03/14 13:36, Philipp Zabel wrote:
[...]
  Can port_node be NULL? Probably only if something is quite wrong, but
  maybe it's safer to return error in that case.
  
  both of_property_read_u32 and of_node_put can handle port_node == NULL.
  I'll add a WARN_ONCE here as for of_graph_get_next_endpoint and continue
  on.
 
 Isn't it better to return an error?

I am not sure. We can still correctly parse the endpoint properties of a
parentless node. All current users ignore the return value anyway. So as
long as we still do the memset and and set local_node and id, returning
an error effectively won't change the current behaviour.

[...]
  It depends a bit on whether you are actually iterating over individual
  ports, or if you are just walking the whole endpoint graph to find
  remote devices that have to be added to the component master's waiting
  list, for example.
 
 True, but the latter is easily implemented using the separate
 port/endpoint iteration. So I see it as a more powerful API.

Indeed. I see no problem in adding an of_graph_get_next_port function.
But I'd like to keep the current of_graph_get_next_endpoint function
iterating over all endpoints of the device.

  Both of those are possible with the API in the series, but not very 
  cleanly.
 
  Also, if you just want to iterate the endpoints, it's easy to implement
  a helper using the separate port and endpoint iterations.
  
  I started out to move an existing (albeit lightly used) API to a common
  place so others can use it and improve upon it, too. I'm happy to pile
  on fixes directly in this series, but could we separate the improvement
  step from the move, for the bigger modifications?
 
 Yes, I understand that. What I wonder is that which is easier: make it a
 public API now, more or less as it was in v4l2, or make it a public API
 only when all the improvements we can think of have been made.
 
 So my fear is that the API is now made public, and you and others start
 to use it.

And I fear that this series might outgrow maintainer attention spans if
I keep adding to it.

 But I can't use it, as I need things like separate
 port/endpoint iteration. I need to add those, which also means that I
 need to change all the users of the API, making the task more difficult
 than I'd like.

 However, this is more of thinking out loud than I don't like the
 series. It's a good series =).

Thanks. How about I follow this up with a split port/endpoint parsing
helpers after I get some acks?

  I had no immediate use for the port iteration, so I have taken no steps
  to add a function for this. I see no problem to add this later when
  somebody needs it, or even rewrite of_graph_get_next_endpoint to use it
  if it is feasible. Iterating over endpoints on a given port needs no
  helper, as you can just use for_each_child_of_node.
 
 I would have a helper, which should do some sanity checks, like that the
 node names are endpoint.

I'd prefer this to be a generic function of_get_next_child_by_name and
possibly a macro for_each_named_child_of_node wrapping that.

[...]
 In omapdss each driver handles only the ports and endpoints defined for
 its device, and they can be considered private to that device. The only
 reason to look for the remote endpoint is to find the remote device. To
 me the omapdss model makes sense, and feels logical and sane =). So I
 have to say I'm not really familiar with the model you're using.

The main difference I see is that a single IPU device will have two port
nodes handled by the DRM driver and two port nodes handled by the V4L2
driver, so we can't go back up to the IPU device tree node and iterate
over all its ports in either the DRM or V4L2 drivers.
You could argue that all the device tree parsing should be done from the
IPU drivers, and the DRM and V4L2 drivers should use preparsed internal
graph structures. But then we are getting into using struct media_entity
in DRM drivers territory, and rather not go there right now.

regards
Philipp

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 5/7] [media] of: move common endpoint parsing to drivers/of

2014-02-28 Thread Sylwester Nawrocki

On 02/27/2014 06:35 PM, Philipp Zabel wrote:

This patch adds a new struct of_endpoint which is then embedded in struct
v4l2_of_endpoint and contains the endpoint properties that are not V4L2
(or even media) specific: the port number, endpoint id, local device tree
node and remote endpoint phandle. of_graph_parse_endpoint parses those
properties and is used by v4l2_of_parse_endpoint, which just adds the
V4L2 MBUS information to the containing v4l2_of_endpoint structure.

Signed-off-by: Philipp Zabelp.za...@pengutronix.de
---
Changes since v4:
  - Fixed users of struct v4l2_of_endpoint
  - Removed left-over #includemedia/of_graph.h  from v4l2-of.h
---
  drivers/media/platform/exynos4-is/media-dev.c | 10 -
  drivers/media/platform/exynos4-is/mipi-csis.c |  2 +-
  drivers/media/v4l2-core/v4l2-of.c | 16 +++---
  drivers/of/base.c | 31 +++
  include/linux/of_graph.h  | 20 +
  include/media/v4l2-of.h   |  8 ++-
  6 files changed, 62 insertions(+), 25 deletions(-)

diff --git a/drivers/media/platform/exynos4-is/media-dev.c 
b/drivers/media/platform/exynos4-is/media-dev.c
index d0f82da..04d6ecd 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -469,10 +469,10 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
return 0;

v4l2_of_parse_endpoint(ep,endpoint);
-   if (WARN_ON(endpoint.port == 0) || index= FIMC_MAX_SENSORS)
+   if (WARN_ON(endpoint.base.port == 0) || index= FIMC_MAX_SENSORS)
return -EINVAL;

-   pd-mux_id = (endpoint.port - 1)  0x1;
+   pd-mux_id = (endpoint.base.port - 1)  0x1;

rem = of_graph_get_remote_port_parent(ep);
of_node_put(ep);
@@ -494,13 +494,13 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
return -EINVAL;
}

-   if (fimc_input_is_parallel(endpoint.port)) {
+   if (fimc_input_is_parallel(endpoint.base.port)) {
if (endpoint.bus_type == V4L2_MBUS_PARALLEL)
pd-sensor_bus_type = FIMC_BUS_TYPE_ITU_601;
else
pd-sensor_bus_type = FIMC_BUS_TYPE_ITU_656;
pd-flags = endpoint.bus.parallel.flags;
-   } else if (fimc_input_is_mipi_csi(endpoint.port)) {
+   } else if (fimc_input_is_mipi_csi(endpoint.base.port)) {
/*
 * MIPI CSI-2: only input mux selection and
 * the sensor's clock frequency is needed.
@@ -508,7 +508,7 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
pd-sensor_bus_type = FIMC_BUS_TYPE_MIPI_CSI2;
} else {
v4l2_err(fmd-v4l2_dev, Wrong port id (%u) at node %s\n,
-endpoint.port, rem-full_name);
+endpoint.base.port, rem-full_name);
}
/*
 * For FIMC-IS handled sensors, that are placed under i2c-isp device
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c 
b/drivers/media/platform/exynos4-is/mipi-csis.c
index fd1ae65..3678ba5 100644
--- a/drivers/media/platform/exynos4-is/mipi-csis.c
+++ b/drivers/media/platform/exynos4-is/mipi-csis.c
@@ -772,7 +772,7 @@ static int s5pcsis_parse_dt(struct platform_device *pdev,
/* Get port node and validate MIPI-CSI channel id. */
v4l2_of_parse_endpoint(node,endpoint);

-   state-index = endpoint.port - FIMC_INPUT_MIPI_CSI2_0;
+   state-index = endpoint.base.port - FIMC_INPUT_MIPI_CSI2_0;
if (state-index  0 || state-index= CSIS_MAX_ENTITIES)
return -ENXIO;

diff --git a/drivers/media/v4l2-core/v4l2-of.c 
b/drivers/media/v4l2-core/v4l2-of.c
index f919db3..b4ed9a9 100644
--- a/drivers/media/v4l2-core/v4l2-of.c
+++ b/drivers/media/v4l2-core/v4l2-of.c
@@ -127,17 +127,9 @@ static void v4l2_of_parse_parallel_bus(const struct 
device_node *node,
  int v4l2_of_parse_endpoint(const struct device_node *node,
   struct v4l2_of_endpoint *endpoint)
  {
-   struct device_node *port_node = of_get_parent(node);
-
-   memset(endpoint, 0, offsetof(struct v4l2_of_endpoint, head));
-
-   endpoint-local_node = node;
-   /*
-* It doesn't matter whether the two calls below succeed.
-* If they don't then the default value 0 is used.
-*/
-   of_property_read_u32(port_node, reg,endpoint-port);
-   of_property_read_u32(node, reg,endpoint-id);
+   of_graph_parse_endpoint(node,endpoint-base);
+   endpoint-bus_type = 0;
+   memset(endpoint-bus, 0, sizeof(endpoint-bus));

v4l2_of_parse_csi_bus(node, endpoint);
/*
@@ -147,8 +139,6 @@ int v4l2_of_parse_endpoint(const struct device_node *node,
if (endpoint-bus.mipi_csi2.flags == 0)
v4l2_of_parse_parallel_bus(node, endpoint);

-   of_node_put(port_node);
-
return 

[PATCH v5 5/7] [media] of: move common endpoint parsing to drivers/of

2014-02-27 Thread Philipp Zabel
This patch adds a new struct of_endpoint which is then embedded in struct
v4l2_of_endpoint and contains the endpoint properties that are not V4L2
(or even media) specific: the port number, endpoint id, local device tree
node and remote endpoint phandle. of_graph_parse_endpoint parses those
properties and is used by v4l2_of_parse_endpoint, which just adds the
V4L2 MBUS information to the containing v4l2_of_endpoint structure.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
Changes since v4:
 - Fixed users of struct v4l2_of_endpoint
 - Removed left-over #include media/of_graph.h from v4l2-of.h
---
 drivers/media/platform/exynos4-is/media-dev.c | 10 -
 drivers/media/platform/exynos4-is/mipi-csis.c |  2 +-
 drivers/media/v4l2-core/v4l2-of.c | 16 +++---
 drivers/of/base.c | 31 +++
 include/linux/of_graph.h  | 20 +
 include/media/v4l2-of.h   |  8 ++-
 6 files changed, 62 insertions(+), 25 deletions(-)

diff --git a/drivers/media/platform/exynos4-is/media-dev.c 
b/drivers/media/platform/exynos4-is/media-dev.c
index d0f82da..04d6ecd 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -469,10 +469,10 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
return 0;
 
v4l2_of_parse_endpoint(ep, endpoint);
-   if (WARN_ON(endpoint.port == 0) || index = FIMC_MAX_SENSORS)
+   if (WARN_ON(endpoint.base.port == 0) || index = FIMC_MAX_SENSORS)
return -EINVAL;
 
-   pd-mux_id = (endpoint.port - 1)  0x1;
+   pd-mux_id = (endpoint.base.port - 1)  0x1;
 
rem = of_graph_get_remote_port_parent(ep);
of_node_put(ep);
@@ -494,13 +494,13 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
return -EINVAL;
}
 
-   if (fimc_input_is_parallel(endpoint.port)) {
+   if (fimc_input_is_parallel(endpoint.base.port)) {
if (endpoint.bus_type == V4L2_MBUS_PARALLEL)
pd-sensor_bus_type = FIMC_BUS_TYPE_ITU_601;
else
pd-sensor_bus_type = FIMC_BUS_TYPE_ITU_656;
pd-flags = endpoint.bus.parallel.flags;
-   } else if (fimc_input_is_mipi_csi(endpoint.port)) {
+   } else if (fimc_input_is_mipi_csi(endpoint.base.port)) {
/*
 * MIPI CSI-2: only input mux selection and
 * the sensor's clock frequency is needed.
@@ -508,7 +508,7 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
pd-sensor_bus_type = FIMC_BUS_TYPE_MIPI_CSI2;
} else {
v4l2_err(fmd-v4l2_dev, Wrong port id (%u) at node %s\n,
-endpoint.port, rem-full_name);
+endpoint.base.port, rem-full_name);
}
/*
 * For FIMC-IS handled sensors, that are placed under i2c-isp device
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c 
b/drivers/media/platform/exynos4-is/mipi-csis.c
index fd1ae65..3678ba5 100644
--- a/drivers/media/platform/exynos4-is/mipi-csis.c
+++ b/drivers/media/platform/exynos4-is/mipi-csis.c
@@ -772,7 +772,7 @@ static int s5pcsis_parse_dt(struct platform_device *pdev,
/* Get port node and validate MIPI-CSI channel id. */
v4l2_of_parse_endpoint(node, endpoint);
 
-   state-index = endpoint.port - FIMC_INPUT_MIPI_CSI2_0;
+   state-index = endpoint.base.port - FIMC_INPUT_MIPI_CSI2_0;
if (state-index  0 || state-index = CSIS_MAX_ENTITIES)
return -ENXIO;
 
diff --git a/drivers/media/v4l2-core/v4l2-of.c 
b/drivers/media/v4l2-core/v4l2-of.c
index f919db3..b4ed9a9 100644
--- a/drivers/media/v4l2-core/v4l2-of.c
+++ b/drivers/media/v4l2-core/v4l2-of.c
@@ -127,17 +127,9 @@ static void v4l2_of_parse_parallel_bus(const struct 
device_node *node,
 int v4l2_of_parse_endpoint(const struct device_node *node,
   struct v4l2_of_endpoint *endpoint)
 {
-   struct device_node *port_node = of_get_parent(node);
-
-   memset(endpoint, 0, offsetof(struct v4l2_of_endpoint, head));
-
-   endpoint-local_node = node;
-   /*
-* It doesn't matter whether the two calls below succeed.
-* If they don't then the default value 0 is used.
-*/
-   of_property_read_u32(port_node, reg, endpoint-port);
-   of_property_read_u32(node, reg, endpoint-id);
+   of_graph_parse_endpoint(node, endpoint-base);
+   endpoint-bus_type = 0;
+   memset(endpoint-bus, 0, sizeof(endpoint-bus));
 
v4l2_of_parse_csi_bus(node, endpoint);
/*
@@ -147,8 +139,6 @@ int v4l2_of_parse_endpoint(const struct device_node *node,
if (endpoint-bus.mipi_csi2.flags == 0)
v4l2_of_parse_parallel_bus(node, endpoint);
 
-   of_node_put(port_node);
-
return 0;
 }