All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration
@ 2018-08-27  9:29 Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 01/23] v4l: fwnode: Add debug prints for V4L2 endpoint property parsing Sakari Ailus
                   ` (23 more replies)
  0 siblings, 24 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Hello everyone,

I've long thought the V4L2 fwnode framework requires some work (it's buggy
and it does not adequately serve common needs). This set should address in
particular these matters:

- Most devices support a particular media bus type but the V4L2 fwnode
  framework was not able to use such information, but instead tried to
  guess the bus type with varying levels of success while drivers
  generally ignored the results. This patchset makes that possible ---
  setting a bus type enables parsing configuration for only that bus.
  Failing that check results in returning -ENXIO to be returned.

- Support specifying default configuration. If the endpoint has no
  configuration, the defaults set by the driver (as documented in DT
  bindings) will prevail. Any available configuration will still be read
  from the endpoint as one could expect. A common use case for this is
  e.g. the number of CSI-2 lanes. Few devices support lane mapping, and
  default 1:1 mapping is provided in absence of a valid default or
  configuration read OF.

- Debugging information is greatly improved.

- Recognition of the differences between CSI-2 D-PHY and C-PHY. All
  currently supported hardware (or at least drivers) is D-PHY only, so
  this change is still easy.

The smiapp driver is converted to use the new functionality. This patchset
does not address remaining issues such as supporting setting defaults for
e.g. bridge drivers with multiple ports, but with Steve Longerbeam's
patchset we're much closer to that goal. I've rebased this set on top of
Steve's. Albeit the two deal with the same files, there were only a few
trivial conflicts.

Note that I've only tested parsing endpoints for the CSI-2 bus (no
parallel IF hardware). Jacopo has tested an earlier version of the set
with a few changes to the parallel bus handling compared to this one.

Comments are welcome.

I've pushed the patches (including Steve's) here:

<URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=v4l2-fwnode-next>

since v1:

- Rebase it all on current media tree master --- there was a conflict in
  drivers/media/platform/qcom/camss/camss.c in Steve's patch "media:
  platform: Switch to v4l2_async_notifier_add_subdev"; I hope the
  resolution was fine.

- Default to Bt.656 bus in guessing the bus type if no properties
  suggesting otherwise are set. In v1 and error was returned, which would
  have been troublesome for the existing drivers.

- Set the bus_type field to zero (i.e. guess) for existing callers of
  v4l2_fwnode_endpoint_(alloc_)parse.

- Improved documentation for v4l2_fwnode_endpoint_parse and
  v4l2_fwnode_endpoint_alloc_parse.

Sakari Ailus (23):
  v4l: fwnode: Add debug prints for V4L2 endpoint property parsing
  v4l: fwnode: Use fwnode_graph_for_each_endpoint
  v4l: fwnode: The CSI-2 clock is continuous if it's not non-continuous
  dt-bindings: media: Specify bus type for MIPI D-PHY, others,
    explicitly
  v4l: fwnode: Add definitions for CSI-2 D-PHY, parallel and Bt.656
    busses
  v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY
  v4l: fwnode: Let the caller provide V4L2 fwnode endpoint
  v4l: fwnode: Detect bus type correctly
  v4l: fwnode: Make use of newly specified bus types
  v4l: fwnode: Read lane inversion information despite lane numbering
  v4l: fwnode: Only assign configuration if there is no error
  v4l: fwnode: Support driver-defined lane mapping defaults
  v4l: fwnode: Support default CSI-2 lane mapping for drivers
  v4l: fwnode: Parse the graph endpoint as last
  v4l: fwnode: Use default parallel flags
  v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero
  v4l: fwnode: Only zero the struct if bus type is set to
    V4L2_MBUS_UNKNOWN
  v4l: fwnode: Use media bus type for bus parser selection
  v4l: fwnode: Print bus type
  v4l: fwnode: Use V4L2 fwnode endpoint media bus type if set
  v4l: fwnode: Support parsing of CSI-2 C-PHY endpoints
  v4l: fwnode: Update V4L2 fwnode endpoint parsing documentation
  smiapp: Query the V4L2 endpoint for a specific bus type

 .../devicetree/bindings/media/video-interfaces.txt |   4 +-
 drivers/gpu/ipu-v3/ipu-csi.c                       |   2 +-
 drivers/media/i2c/adv7180.c                        |   2 +-
 drivers/media/i2c/adv7604.c                        |   2 +-
 drivers/media/i2c/mt9v032.c                        |   2 +-
 drivers/media/i2c/ov2659.c                         |  14 +-
 drivers/media/i2c/ov5640.c                         |   4 +-
 drivers/media/i2c/ov5645.c                         |   2 +-
 drivers/media/i2c/ov5647.c                         |   2 +-
 drivers/media/i2c/ov7251.c                         |   4 +-
 drivers/media/i2c/ov7670.c                         |   2 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   4 +-
 drivers/media/i2c/s5k5baf.c                        |   6 +-
 drivers/media/i2c/s5k6aa.c                         |   2 +-
 drivers/media/i2c/smiapp/smiapp-core.c             |  34 +-
 drivers/media/i2c/soc_camera/ov5642.c              |   2 +-
 drivers/media/i2c/tc358743.c                       |  28 +-
 drivers/media/i2c/tda1997x.c                       |   2 +-
 drivers/media/i2c/tvp514x.c                        |   2 +-
 drivers/media/i2c/tvp5150.c                        |   2 +-
 drivers/media/i2c/tvp7002.c                        |   2 +-
 drivers/media/pci/intel/ipu3/ipu3-cio2.c           |   2 +-
 drivers/media/platform/am437x/am437x-vpfe.c        |   2 +-
 drivers/media/platform/atmel/atmel-isc.c           |   3 +-
 drivers/media/platform/atmel/atmel-isi.c           |   2 +-
 drivers/media/platform/cadence/cdns-csi2rx.c       |   4 +-
 drivers/media/platform/cadence/cdns-csi2tx.c       |   4 +-
 drivers/media/platform/davinci/vpif_capture.c      |   2 +-
 drivers/media/platform/exynos4-is/media-dev.c      |   2 +-
 drivers/media/platform/exynos4-is/mipi-csis.c      |   2 +-
 drivers/media/platform/marvell-ccic/mcam-core.c    |   4 +-
 drivers/media/platform/marvell-ccic/mmp-driver.c   |   2 +-
 drivers/media/platform/omap3isp/isp.c              |   2 +-
 drivers/media/platform/pxa_camera.c                |   4 +-
 drivers/media/platform/rcar-vin/rcar-csi2.c        |   4 +-
 drivers/media/platform/renesas-ceu.c               |   3 +-
 drivers/media/platform/soc_camera/soc_mediabus.c   |   2 +-
 drivers/media/platform/stm32/stm32-dcmi.c          |   4 +-
 drivers/media/platform/ti-vpe/cal.c                |   2 +-
 drivers/media/v4l2-core/v4l2-fwnode.c              | 508 ++++++++++++++++-----
 drivers/staging/media/imx/imx-media-csi.c          |   2 +-
 drivers/staging/media/imx/imx6-mipi-csi2.c         |   2 +-
 drivers/staging/media/imx074/imx074.c              |   2 +-
 include/media/v4l2-fwnode.h                        |  60 ++-
 include/media/v4l2-mediabus.h                      |   8 +-
 45 files changed, 536 insertions(+), 220 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 01/23] v4l: fwnode: Add debug prints for V4L2 endpoint property parsing
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 02/23] v4l: fwnode: Use fwnode_graph_for_each_endpoint Sakari Ailus
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Print debug info as standard V4L2 endpoint are parsed.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 108 ++++++++++++++++++++++++++--------
 1 file changed, 85 insertions(+), 23 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 5a65ca19ba05..dae01d5f570e 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -66,6 +66,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 			lanes_used |= BIT(array[i]);
 
 			bus->data_lanes[i] = array[i];
+			pr_debug("lane %u position %u\n", i, array[i]);
 		}
 
 		rval = fwnode_property_read_u32_array(fwnode,
@@ -82,8 +83,13 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 						       "lane-polarities", array,
 						       1 + bus->num_data_lanes);
 
-			for (i = 0; i < 1 + bus->num_data_lanes; i++)
+			for (i = 0; i < 1 + bus->num_data_lanes; i++) {
 				bus->lane_polarities[i] = array[i];
+				pr_debug("lane %u polarity %sinverted",
+					 i, array[i] ? "" : "not ");
+			}
+		} else {
+			pr_debug("no lane polarities defined, assuming not inverted\n");
 		}
 
 	}
@@ -95,12 +101,15 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 
 		bus->clock_lane = v;
 		have_clk_lane = true;
+		pr_debug("clock lane position %u\n", v);
 	}
 
-	if (fwnode_property_present(fwnode, "clock-noncontinuous"))
+	if (fwnode_property_present(fwnode, "clock-noncontinuous")) {
 		flags |= V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
-	else if (have_clk_lane || bus->num_data_lanes > 0)
+		pr_debug("non-continuous clock\n");
+	} else if (have_clk_lane || bus->num_data_lanes > 0) {
 		flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
+	}
 
 	bus->flags = flags;
 	vep->bus_type = V4L2_MBUS_CSI2;
@@ -115,48 +124,69 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
 	unsigned int flags = 0;
 	u32 v;
 
-	if (!fwnode_property_read_u32(fwnode, "hsync-active", &v))
+	if (!fwnode_property_read_u32(fwnode, "hsync-active", &v)) {
 		flags |= v ? V4L2_MBUS_HSYNC_ACTIVE_HIGH :
 			V4L2_MBUS_HSYNC_ACTIVE_LOW;
+		pr_debug("hsync-active %s\n", v ? "high" : "low");
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "vsync-active", &v))
+	if (!fwnode_property_read_u32(fwnode, "vsync-active", &v)) {
 		flags |= v ? V4L2_MBUS_VSYNC_ACTIVE_HIGH :
 			V4L2_MBUS_VSYNC_ACTIVE_LOW;
+		pr_debug("vsync-active %s\n", v ? "high" : "low");
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "field-even-active", &v))
+	if (!fwnode_property_read_u32(fwnode, "field-even-active", &v)) {
 		flags |= v ? V4L2_MBUS_FIELD_EVEN_HIGH :
 			V4L2_MBUS_FIELD_EVEN_LOW;
+		pr_debug("field-even-active %s\n", v ? "high" : "low");
+	}
+
 	if (flags)
 		vep->bus_type = V4L2_MBUS_PARALLEL;
 	else
 		vep->bus_type = V4L2_MBUS_BT656;
 
-	if (!fwnode_property_read_u32(fwnode, "pclk-sample", &v))
+	if (!fwnode_property_read_u32(fwnode, "pclk-sample", &v)) {
 		flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
 			V4L2_MBUS_PCLK_SAMPLE_FALLING;
+		pr_debug("pclk-sample %s\n", v ? "high" : "low");
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "data-active", &v))
+	if (!fwnode_property_read_u32(fwnode, "data-active", &v)) {
 		flags |= v ? V4L2_MBUS_DATA_ACTIVE_HIGH :
 			V4L2_MBUS_DATA_ACTIVE_LOW;
+		pr_debug("data-active %s\n", v ? "high" : "low");
+	}
 
-	if (fwnode_property_present(fwnode, "slave-mode"))
+	if (fwnode_property_present(fwnode, "slave-mode")) {
+		pr_debug("slave mode\n");
 		flags |= V4L2_MBUS_SLAVE;
-	else
+	} else {
 		flags |= V4L2_MBUS_MASTER;
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "bus-width", &v))
+	if (!fwnode_property_read_u32(fwnode, "bus-width", &v)) {
 		bus->bus_width = v;
+		pr_debug("bus-width %u\n", v);
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "data-shift", &v))
+	if (!fwnode_property_read_u32(fwnode, "data-shift", &v)) {
 		bus->data_shift = v;
+		pr_debug("data-shift %u\n", v);
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "sync-on-green-active", &v))
+	if (!fwnode_property_read_u32(fwnode, "sync-on-green-active", &v)) {
 		flags |= v ? V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH :
 			V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW;
+		pr_debug("sync-on-green-active %s\n", v ? "high" : "low");
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "data-enable-active", &v))
+	if (!fwnode_property_read_u32(fwnode, "data-enable-active", &v)) {
 		flags |= v ? V4L2_MBUS_DATA_ENABLE_HIGH :
 			V4L2_MBUS_DATA_ENABLE_LOW;
+		pr_debug("data-enable-active %s\n", v ? "high" : "low");
+	}
 
 	bus->flags = flags;
 
@@ -170,17 +200,25 @@ v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle *fwnode,
 	struct v4l2_fwnode_bus_mipi_csi1 *bus = &vep->bus.mipi_csi1;
 	u32 v;
 
-	if (!fwnode_property_read_u32(fwnode, "clock-inv", &v))
+	if (!fwnode_property_read_u32(fwnode, "clock-inv", &v)) {
 		bus->clock_inv = v;
+		pr_debug("clock-inv %u\n", v);
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "strobe", &v))
+	if (!fwnode_property_read_u32(fwnode, "strobe", &v)) {
 		bus->strobe = v;
+		pr_debug("strobe %u\n", v);
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "data-lanes", &v))
+	if (!fwnode_property_read_u32(fwnode, "data-lanes", &v)) {
 		bus->data_lane = v;
+		pr_debug("data-lanes %u\n", v);
+	}
 
-	if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v))
+	if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) {
 		bus->clock_lane = v;
+		pr_debug("clock-lanes %u\n", v);
+	}
 
 	if (bus_type == V4L2_FWNODE_BUS_TYPE_CCP2)
 		vep->bus_type = V4L2_MBUS_CCP2;
@@ -188,12 +226,14 @@ v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle *fwnode,
 		vep->bus_type = V4L2_MBUS_CSI1;
 }
 
-int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
-			       struct v4l2_fwnode_endpoint *vep)
+static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
+					struct v4l2_fwnode_endpoint *vep)
 {
 	u32 bus_type = 0;
 	int rval;
 
+	pr_debug("===== begin V4L2 endpoint properties\n");
+
 	fwnode_graph_parse_endpoint(fwnode, &vep->base);
 
 	/* Zero fields from bus_type to until the end */
@@ -214,16 +254,30 @@ int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 		if (vep->bus.mipi_csi2.flags == 0)
 			v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep);
 
-		return 0;
+		break;
 	case V4L2_FWNODE_BUS_TYPE_CCP2:
 	case V4L2_FWNODE_BUS_TYPE_CSI1:
 		v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, bus_type);
 
-		return 0;
+		break;
 	default:
 		pr_warn("unsupported bus type %u\n", bus_type);
 		return -EINVAL;
 	}
+
+	return 0;
+}
+
+int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
+			       struct v4l2_fwnode_endpoint *vep)
+{
+	int ret;
+
+	ret = __v4l2_fwnode_endpoint_parse(fwnode, vep);
+
+	pr_debug("===== end V4L2 endpoint properties\n");
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_parse);
 
@@ -247,13 +301,15 @@ struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
 	if (!vep)
 		return ERR_PTR(-ENOMEM);
 
-	rval = v4l2_fwnode_endpoint_parse(fwnode, vep);
+	rval = __v4l2_fwnode_endpoint_parse(fwnode, vep);
 	if (rval < 0)
 		goto out_err;
 
 	rval = fwnode_property_read_u64_array(fwnode, "link-frequencies",
 					      NULL, 0);
 	if (rval > 0) {
+		unsigned int i;
+
 		vep->link_frequencies =
 			kmalloc_array(rval, sizeof(*vep->link_frequencies),
 				      GFP_KERNEL);
@@ -269,8 +325,14 @@ struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
 			vep->nr_of_link_frequencies);
 		if (rval < 0)
 			goto out_err;
+
+		for (i = 0; i < vep->nr_of_link_frequencies; i++)
+			pr_info("link-frequencies %u value %llu\n", i,
+				vep->link_frequencies[i]);
 	}
 
+	pr_debug("===== end V4L2 endpoint properties\n");
+
 	return vep;
 
 out_err:
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 02/23] v4l: fwnode: Use fwnode_graph_for_each_endpoint
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 01/23] v4l: fwnode: Add debug prints for V4L2 endpoint property parsing Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 03/23] v4l: fwnode: The CSI-2 clock is continuous if it's not non-continuous Sakari Ailus
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Use fwnode_graph_for_each_endpoint iterator for better readability.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index dae01d5f570e..da13348b1f4a 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -456,8 +456,7 @@ static int __v4l2_async_notifier_parse_fwnode_endpoints(
 	if (WARN_ON(asd_struct_size < sizeof(struct v4l2_async_subdev)))
 		return -EINVAL;
 
-	for (fwnode = NULL; (fwnode = fwnode_graph_get_next_endpoint(
-				     dev_fwnode(dev), fwnode)); ) {
+	fwnode_graph_for_each_endpoint(dev_fwnode(dev), fwnode) {
 		struct fwnode_handle *dev_fwnode;
 		bool is_available;
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 03/23] v4l: fwnode: The CSI-2 clock is continuous if it's not non-continuous
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 01/23] v4l: fwnode: Add debug prints for V4L2 endpoint property parsing Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 02/23] v4l: fwnode: Use fwnode_graph_for_each_endpoint Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 04/23] dt-bindings: media: Specify bus type for MIPI D-PHY, others, explicitly Sakari Ailus
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

The continuous clock flag was only set if there was a clock or data lanes.
This isn't needed as such a configuration is invalid to begin with. Always
set the continuous clock flag if the non-continuous property is not found.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index da13348b1f4a..0cc96ee5f1e5 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -107,7 +107,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 	if (fwnode_property_present(fwnode, "clock-noncontinuous")) {
 		flags |= V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
 		pr_debug("non-continuous clock\n");
-	} else if (have_clk_lane || bus->num_data_lanes > 0) {
+	} else {
 		flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
 	}
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 04/23] dt-bindings: media: Specify bus type for MIPI D-PHY, others, explicitly
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (2 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 03/23] v4l: fwnode: The CSI-2 clock is continuous if it's not non-continuous Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-29  0:45   ` Rob Herring
  2018-08-27  9:29 ` [PATCH v2 05/23] v4l: fwnode: Add definitions for CSI-2 D-PHY, parallel and Bt.656 busses Sakari Ailus
                   ` (19 subsequent siblings)
  23 siblings, 1 reply; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Allow specifying the bus type explicitly for MIPI D-PHY, parallel and
Bt.656 busses. This is useful for devices that can make use of different
bus types. There are CSI-2 transmitters and receivers but the PHY
selection needs to be made between C-PHY and D-PHY; many devices also
support parallel and Bt.656 interfaces but the means to pass that
information to software wasn't there.

Autodetection (value 0) is removed as an option as the property could be
simply omitted in that case.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Documentation/devicetree/bindings/media/video-interfaces.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/media/video-interfaces.txt b/Documentation/devicetree/bindings/media/video-interfaces.txt
index baf9d9756b3c..f884ada0bffc 100644
--- a/Documentation/devicetree/bindings/media/video-interfaces.txt
+++ b/Documentation/devicetree/bindings/media/video-interfaces.txt
@@ -100,10 +100,12 @@ Optional endpoint properties
   slave device (data source) by the master device (data sink). In the master
   mode the data source device is also the source of the synchronization signals.
 - bus-type: data bus type. Possible values are:
-  0 - autodetect based on other properties (MIPI CSI-2 D-PHY, parallel or Bt656)
   1 - MIPI CSI-2 C-PHY
   2 - MIPI CSI1
   3 - CCP2
+  4 - MIPI CSI-2 D-PHY
+  5 - Parallel
+  6 - Bt.656
 - bus-width: number of data lines actively used, valid for the parallel busses.
 - data-shift: on the parallel data busses, if bus-width is used to specify the
   number of data lines, data-shift can be used to specify which data lines are
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 05/23] v4l: fwnode: Add definitions for CSI-2 D-PHY, parallel and Bt.656 busses
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (3 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 04/23] dt-bindings: media: Specify bus type for MIPI D-PHY, others, explicitly Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 06/23] v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY Sakari Ailus
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Add definitions corresponding to DT bindings to the CSI-2 D-PHY, parallel
and Bt.656 busses.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 0cc96ee5f1e5..4aa1608ba217 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -36,6 +36,9 @@ enum v4l2_fwnode_bus_type {
 	V4L2_FWNODE_BUS_TYPE_CSI2_CPHY,
 	V4L2_FWNODE_BUS_TYPE_CSI1,
 	V4L2_FWNODE_BUS_TYPE_CCP2,
+	V4L2_FWNODE_BUS_TYPE_CSI2_DPHY,
+	V4L2_FWNODE_BUS_TYPE_PARALLEL,
+	V4L2_FWNODE_BUS_TYPE_BT656,
 	NR_OF_V4L2_FWNODE_BUS_TYPE,
 };
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 06/23] v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (4 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 05/23] v4l: fwnode: Add definitions for CSI-2 D-PHY, parallel and Bt.656 busses Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-31  8:02     ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 07/23] v4l: fwnode: Let the caller provide V4L2 fwnode endpoint Sakari Ailus
                   ` (17 subsequent siblings)
  23 siblings, 1 reply; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

The CSI-2 bus may use either D-PHY or C-PHY. Make this visible in media
bus enum.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/gpu/ipu-v3/ipu-csi.c                     | 2 +-
 drivers/media/i2c/adv7180.c                      | 2 +-
 drivers/media/i2c/ov5640.c                       | 4 ++--
 drivers/media/i2c/ov5645.c                       | 2 +-
 drivers/media/i2c/ov7251.c                       | 4 ++--
 drivers/media/i2c/s5c73m3/s5c73m3-core.c         | 2 +-
 drivers/media/i2c/s5k5baf.c                      | 4 ++--
 drivers/media/i2c/s5k6aa.c                       | 2 +-
 drivers/media/i2c/smiapp/smiapp-core.c           | 2 +-
 drivers/media/i2c/soc_camera/ov5642.c            | 2 +-
 drivers/media/i2c/tc358743.c                     | 4 ++--
 drivers/media/pci/intel/ipu3/ipu3-cio2.c         | 2 +-
 drivers/media/platform/cadence/cdns-csi2rx.c     | 2 +-
 drivers/media/platform/cadence/cdns-csi2tx.c     | 2 +-
 drivers/media/platform/marvell-ccic/mcam-core.c  | 4 ++--
 drivers/media/platform/marvell-ccic/mmp-driver.c | 2 +-
 drivers/media/platform/omap3isp/isp.c            | 2 +-
 drivers/media/platform/pxa_camera.c              | 2 +-
 drivers/media/platform/rcar-vin/rcar-csi2.c      | 2 +-
 drivers/media/platform/soc_camera/soc_mediabus.c | 2 +-
 drivers/media/platform/stm32/stm32-dcmi.c        | 2 +-
 drivers/media/platform/ti-vpe/cal.c              | 2 +-
 drivers/media/v4l2-core/v4l2-fwnode.c            | 2 +-
 drivers/staging/media/imx/imx-media-csi.c        | 2 +-
 drivers/staging/media/imx/imx6-mipi-csi2.c       | 2 +-
 drivers/staging/media/imx074/imx074.c            | 2 +-
 include/media/v4l2-mediabus.h                    | 6 ++++--
 27 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index caa05b0702e1..4bc12d7b0b49 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -344,7 +344,7 @@ static void fill_csi_bus_cfg(struct ipu_csi_bus_config *csicfg,
 		else
 			csicfg->clk_mode = IPU_CSI_CLK_MODE_CCIR656_PROGRESSIVE;
 		break;
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		/*
 		 * MIPI CSI-2 requires non gated clock mode, all other
 		 * parameters are not applicable for MIPI CSI-2 bus.
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index de10367d550b..2848a46d149a 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -761,7 +761,7 @@ static int adv7180_g_mbus_config(struct v4l2_subdev *sd,
 	struct adv7180_state *state = to_state(sd);
 
 	if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
-		cfg->type = V4L2_MBUS_CSI2;
+		cfg->type = V4L2_MBUS_CSI2_DPHY;
 		cfg->flags = V4L2_MBUS_CSI2_1_LANE |
 				V4L2_MBUS_CSI2_CHANNEL_0 |
 				V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 071f4bc240ca..942531aaae92 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -1786,7 +1786,7 @@ static int ov5640_set_power(struct ov5640_dev *sensor, bool on)
 		if (ret)
 			goto power_off;
 
-		if (sensor->ep.bus_type == V4L2_MBUS_CSI2) {
+		if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
 			/*
 			 * start streaming briefly followed by stream off in
 			 * order to coax the clock lane into LP-11 state.
@@ -2550,7 +2550,7 @@ static int ov5640_s_stream(struct v4l2_subdev *sd, int enable)
 				goto out;
 		}
 
-		if (sensor->ep.bus_type == V4L2_MBUS_CSI2)
+		if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY)
 			ret = ov5640_set_stream_mipi(sensor, enable);
 		else
 			ret = ov5640_set_stream_dvp(sensor, enable);
diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index 1722cdab0daf..5eba8dd7222b 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -1127,7 +1127,7 @@ static int ov5645_probe(struct i2c_client *client,
 		return ret;
 	}
 
-	if (ov5645->ep.bus_type != V4L2_MBUS_CSI2) {
+	if (ov5645->ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "invalid bus type, must be CSI2\n");
 		return -EINVAL;
 	}
diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
index d3ebb7529fca..0c10203f822b 100644
--- a/drivers/media/i2c/ov7251.c
+++ b/drivers/media/i2c/ov7251.c
@@ -1279,9 +1279,9 @@ static int ov7251_probe(struct i2c_client *client)
 		return ret;
 	}
 
-	if (ov7251->ep.bus_type != V4L2_MBUS_CSI2) {
+	if (ov7251->ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "invalid bus type (%u), must be CSI2 (%u)\n",
-			ov7251->ep.bus_type, V4L2_MBUS_CSI2);
+			ov7251->ep.bus_type, V4L2_MBUS_CSI2_DPHY);
 		return -EINVAL;
 	}
 
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index ce196b60f917..9d5739cafec3 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1644,7 +1644,7 @@ static int s5c73m3_get_platform_data(struct s5c73m3 *state)
 	if (ret)
 		return ret;
 
-	if (ep.bus_type != V4L2_MBUS_CSI2) {
+	if (ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "unsupported bus type\n");
 		return -EINVAL;
 	}
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 5007c9659342..4c41a770b132 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -766,7 +766,7 @@ static int s5k5baf_hw_set_video_bus(struct s5k5baf *state)
 {
 	u16 en_pkts;
 
-	if (state->bus_type == V4L2_MBUS_CSI2)
+	if (state->bus_type == V4L2_MBUS_CSI2_DPHY)
 		en_pkts = EN_PACKETS_CSI2;
 	else
 		en_pkts = 0;
@@ -1875,7 +1875,7 @@ static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev)
 	state->bus_type = ep.bus_type;
 
 	switch (state->bus_type) {
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		state->nlanes = ep.bus.mipi_csi2.num_data_lanes;
 		break;
 	case V4L2_MBUS_PARALLEL:
diff --git a/drivers/media/i2c/s5k6aa.c b/drivers/media/i2c/s5k6aa.c
index 13c10b5e2b45..5f097ae7a5b1 100644
--- a/drivers/media/i2c/s5k6aa.c
+++ b/drivers/media/i2c/s5k6aa.c
@@ -688,7 +688,7 @@ static int s5k6aa_configure_video_bus(struct s5k6aa *s5k6aa,
 	 * but there is nothing indicating how to switch between both
 	 * in the datasheet. For now default BT.601 interface is assumed.
 	 */
-	if (bus_type == V4L2_MBUS_CSI2)
+	if (bus_type == V4L2_MBUS_CSI2_DPHY)
 		cfg = nlanes;
 	else if (bus_type != V4L2_MBUS_PARALLEL)
 		return -EINVAL;
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 1236683da8f7..9e33c2008ba6 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2784,7 +2784,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 		goto out_err;
 
 	switch (bus_cfg->bus_type) {
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		hwcfg->csi_signalling_mode = SMIAPP_CSI_SIGNALLING_MODE_CSI2;
 		hwcfg->lanes = bus_cfg->bus.mipi_csi2.num_data_lanes;
 		break;
diff --git a/drivers/media/i2c/soc_camera/ov5642.c b/drivers/media/i2c/soc_camera/ov5642.c
index 39f420db9c70..bc045259510d 100644
--- a/drivers/media/i2c/soc_camera/ov5642.c
+++ b/drivers/media/i2c/soc_camera/ov5642.c
@@ -913,7 +913,7 @@ static int ov5642_get_selection(struct v4l2_subdev *sd,
 static int ov5642_g_mbus_config(struct v4l2_subdev *sd,
 				struct v4l2_mbus_config *cfg)
 {
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 	cfg->flags = V4L2_MBUS_CSI2_2_LANE | V4L2_MBUS_CSI2_CHANNEL_0 |
 					V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
 
diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
index 44c41933415a..6a2064597124 100644
--- a/drivers/media/i2c/tc358743.c
+++ b/drivers/media/i2c/tc358743.c
@@ -1607,7 +1607,7 @@ static int tc358743_g_mbus_config(struct v4l2_subdev *sd,
 {
 	struct tc358743_state *state = to_state(sd);
 
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 
 	/* Support for non-continuous CSI-2 clock is missing in the driver */
 	cfg->flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
@@ -1922,7 +1922,7 @@ static int tc358743_probe_of(struct tc358743_state *state)
 		goto put_node;
 	}
 
-	if (endpoint->bus_type != V4L2_MBUS_CSI2 ||
+	if (endpoint->bus_type != V4L2_MBUS_CSI2_DPHY ||
 	    endpoint->bus.mipi_csi2.num_data_lanes == 0 ||
 	    endpoint->nr_of_link_frequencies == 0) {
 		dev_err(dev, "missing CSI-2 properties in endpoint\n");
diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
index ca3ad118d10b..cf77bc6da4a4 100644
--- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
+++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
@@ -1484,7 +1484,7 @@ static int cio2_fwnode_parse(struct device *dev,
 	struct sensor_async_subdev *s_asd =
 			container_of(asd, struct sensor_async_subdev, asd);
 
-	if (vep->bus_type != V4L2_MBUS_CSI2) {
+	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "Only CSI2 bus type is currently supported\n");
 		return -EINVAL;
 	}
diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
index da3eb349716f..0776a34f28ee 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -378,7 +378,7 @@ static int csi2rx_parse_dt(struct csi2rx_priv *csi2rx)
 		return ret;
 	}
 
-	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2) {
+	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(csi2rx->dev, "Unsupported media bus type: 0x%x\n",
 			v4l2_ep.bus_type);
 		of_node_put(ep);
diff --git a/drivers/media/platform/cadence/cdns-csi2tx.c b/drivers/media/platform/cadence/cdns-csi2tx.c
index 40d0de690ff4..6224daf891d7 100644
--- a/drivers/media/platform/cadence/cdns-csi2tx.c
+++ b/drivers/media/platform/cadence/cdns-csi2tx.c
@@ -446,7 +446,7 @@ static int csi2tx_check_lanes(struct csi2tx_priv *csi2tx)
 		goto out;
 	}
 
-	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2) {
+	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(csi2tx->dev, "Unsupported media bus type: 0x%x\n",
 			v4l2_ep.bus_type);
 		ret = -EINVAL;
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index dfdbd4354b74..5e20427aeca2 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -794,7 +794,7 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
 	/*
 	 * This field controls the generation of EOF(DVP only)
 	 */
-	if (cam->bus_type != V4L2_MBUS_CSI2)
+	if (cam->bus_type != V4L2_MBUS_CSI2_DPHY)
 		mcam_reg_set_bit(cam, REG_CTRL0,
 				C0_EOF_VSYNC | C0_VEDGE_CTRL);
 }
@@ -1023,7 +1023,7 @@ static int mcam_read_setup(struct mcam_camera *cam)
 		cam->calc_dphy(cam);
 	cam_dbg(cam, "camera: DPHY sets: dphy3=0x%x, dphy5=0x%x, dphy6=0x%x\n",
 			cam->dphy[0], cam->dphy[1], cam->dphy[2]);
-	if (cam->bus_type == V4L2_MBUS_CSI2)
+	if (cam->bus_type == V4L2_MBUS_CSI2_DPHY)
 		mcam_enable_mipi(cam);
 	else
 		mcam_disable_mipi(cam);
diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c
index 6d9f0abb2660..25ce31b71a45 100644
--- a/drivers/media/platform/marvell-ccic/mmp-driver.c
+++ b/drivers/media/platform/marvell-ccic/mmp-driver.c
@@ -362,7 +362,7 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam->mclk_div = pdata->mclk_div;
 	mcam->bus_type = pdata->bus_type;
 	mcam->dphy = pdata->dphy;
-	if (mcam->bus_type == V4L2_MBUS_CSI2) {
+	if (mcam->bus_type == V4L2_MBUS_CSI2_DPHY) {
 		cam->mipi_clk = devm_clk_get(mcam->dev, "mipi");
 		if ((IS_ERR(cam->mipi_clk) && mcam->dphy[2] == 0))
 			return PTR_ERR(cam->mipi_clk);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index a56f020794e6..ace3bf4ba2a1 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -2054,7 +2054,7 @@ static int isp_fwnode_parse(struct device *dev,
 			dev_dbg(dev, "CSI-1/CCP-2 configuration\n");
 			csi1 = true;
 			break;
-		case V4L2_MBUS_CSI2:
+		case V4L2_MBUS_CSI2_DPHY:
 			dev_dbg(dev, "CSI-2 configuration\n");
 			csi1 = false;
 			break;
diff --git a/drivers/media/platform/pxa_camera.c b/drivers/media/platform/pxa_camera.c
index 0cd26360a956..36e8329f8fa9 100644
--- a/drivers/media/platform/pxa_camera.c
+++ b/drivers/media/platform/pxa_camera.c
@@ -633,7 +633,7 @@ static unsigned int pxa_mbus_config_compatible(const struct v4l2_mbus_config *cf
 		mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
 		return (!hsync || !vsync || !pclk || !data || !mode) ?
 			0 : common_flags;
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
 		mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
 					     V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index 75ebd9c23813..25edc2edd197 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -714,7 +714,7 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
 	if (vep->base.port || vep->base.id)
 		return -ENOTCONN;
 
-	if (vep->bus_type != V4L2_MBUS_CSI2) {
+	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(priv->dev, "Unsupported bus: %u\n", vep->bus_type);
 		return -EINVAL;
 	}
diff --git a/drivers/media/platform/soc_camera/soc_mediabus.c b/drivers/media/platform/soc_camera/soc_mediabus.c
index 0ad4b28266e4..be74008ec0ca 100644
--- a/drivers/media/platform/soc_camera/soc_mediabus.c
+++ b/drivers/media/platform/soc_camera/soc_mediabus.c
@@ -503,7 +503,7 @@ unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
 		mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
 		return (!hsync || !vsync || !pclk || !data || !mode) ?
 			0 : common_flags;
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
 		mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
 					     V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
index b4110e6458d9..38b52a059985 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -1660,7 +1660,7 @@ static int dcmi_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	if (ep.bus_type == V4L2_MBUS_CSI2) {
+	if (ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
 		dev_err(&pdev->dev, "CSI bus not supported\n");
 		return -ENODEV;
 	}
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 6872cb263270..2134103c19f8 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -1710,7 +1710,7 @@ static int of_cal_create_instance(struct cal_ctx *ctx, int inst)
 	}
 	v4l2_fwnode_endpoint_parse(of_fwnode_handle(remote_ep), endpoint);
 
-	if (endpoint->bus_type != V4L2_MBUS_CSI2) {
+	if (endpoint->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		ctx_err(ctx, "Port:%d sub-device %s is not a CSI2 device\n",
 			inst, sensor_node->name);
 		goto err_put_remote_ep;
diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 4aa1608ba217..4f351d93b826 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -115,7 +115,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 	}
 
 	bus->flags = flags;
-	vep->bus_type = V4L2_MBUS_CSI2;
+	vep->bus_type = V4L2_MBUS_CSI2_DPHY;
 
 	return 0;
 }
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index 8e749fdec8d1..539159d9af6b 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -124,7 +124,7 @@ static inline struct csi_priv *sd_to_dev(struct v4l2_subdev *sdev)
 
 static inline bool is_parallel_bus(struct v4l2_fwnode_endpoint *ep)
 {
-	return ep->bus_type != V4L2_MBUS_CSI2;
+	return ep->bus_type != V4L2_MBUS_CSI2_DPHY;
 }
 
 static inline bool is_parallel_16bit_bus(struct v4l2_fwnode_endpoint *ep)
diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
index 94eb9a1f38bb..74438a4c1267 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -563,7 +563,7 @@ static int csi2_parse_endpoint(struct device *dev,
 		return -EINVAL;
 	}
 
-	if (vep->bus_type != V4L2_MBUS_CSI2) {
+	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		v4l2_err(&csi2->sd, "invalid bus type, must be MIPI CSI2\n");
 		return -EINVAL;
 	}
diff --git a/drivers/staging/media/imx074/imx074.c b/drivers/staging/media/imx074/imx074.c
index 77f1e0243d6e..0eee9f0def4d 100644
--- a/drivers/staging/media/imx074/imx074.c
+++ b/drivers/staging/media/imx074/imx074.c
@@ -263,7 +263,7 @@ static int imx074_s_power(struct v4l2_subdev *sd, int on)
 static int imx074_g_mbus_config(struct v4l2_subdev *sd,
 				struct v4l2_mbus_config *cfg)
 {
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 	cfg->flags = V4L2_MBUS_CSI2_2_LANE |
 		V4L2_MBUS_CSI2_CHANNEL_0 |
 		V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
diff --git a/include/media/v4l2-mediabus.h b/include/media/v4l2-mediabus.h
index 4bbb5f3d2b02..26e1c644ded6 100644
--- a/include/media/v4l2-mediabus.h
+++ b/include/media/v4l2-mediabus.h
@@ -75,14 +75,16 @@
  *			also be used for BT.1120
  * @V4L2_MBUS_CSI1:	MIPI CSI-1 serial interface
  * @V4L2_MBUS_CCP2:	CCP2 (Compact Camera Port 2)
- * @V4L2_MBUS_CSI2:	MIPI CSI-2 serial interface
+ * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
+ * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
  */
 enum v4l2_mbus_type {
 	V4L2_MBUS_PARALLEL,
 	V4L2_MBUS_BT656,
 	V4L2_MBUS_CSI1,
 	V4L2_MBUS_CCP2,
-	V4L2_MBUS_CSI2,
+	V4L2_MBUS_CSI2_DPHY,
+	V4L2_MBUS_CSI2_CPHY,
 };
 
 /**
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 07/23] v4l: fwnode: Let the caller provide V4L2 fwnode endpoint
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (5 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 06/23] v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-09-12 14:51   ` jacopo mondi
  2018-08-27  9:29 ` [PATCH v2 08/23] v4l: fwnode: Detect bus type correctly Sakari Ailus
                   ` (16 subsequent siblings)
  23 siblings, 1 reply; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Instead of allocating the V4L2 fwnode endpoint in
v4l2_fwnode_endpoint_alloc_parse, let the caller to do this. This allows
setting default parameters for the endpoint which is a very common need
for drivers.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/ov2659.c             | 14 +++++-----
 drivers/media/i2c/smiapp/smiapp-core.c | 26 +++++++++---------
 drivers/media/i2c/tc358743.c           | 26 +++++++++---------
 drivers/media/v4l2-core/v4l2-fwnode.c  | 49 +++++++++++++---------------------
 include/media/v4l2-fwnode.h            | 10 ++++---
 5 files changed, 60 insertions(+), 65 deletions(-)

diff --git a/drivers/media/i2c/ov2659.c b/drivers/media/i2c/ov2659.c
index 4715edc8ca33..799acce803fe 100644
--- a/drivers/media/i2c/ov2659.c
+++ b/drivers/media/i2c/ov2659.c
@@ -1347,8 +1347,9 @@ static struct ov2659_platform_data *
 ov2659_get_pdata(struct i2c_client *client)
 {
 	struct ov2659_platform_data *pdata;
-	struct v4l2_fwnode_endpoint *bus_cfg;
+	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *endpoint;
+	int ret;
 
 	if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
 		return client->dev.platform_data;
@@ -1357,8 +1358,9 @@ ov2659_get_pdata(struct i2c_client *client)
 	if (!endpoint)
 		return NULL;
 
-	bus_cfg = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(endpoint));
-	if (IS_ERR(bus_cfg)) {
+	ret = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(endpoint),
+					       &bus_cfg);
+	if (ret) {
 		pdata = NULL;
 		goto done;
 	}
@@ -1367,17 +1369,17 @@ ov2659_get_pdata(struct i2c_client *client)
 	if (!pdata)
 		goto done;
 
-	if (!bus_cfg->nr_of_link_frequencies) {
+	if (!bus_cfg.nr_of_link_frequencies) {
 		dev_err(&client->dev,
 			"link-frequencies property not found or too many\n");
 		pdata = NULL;
 		goto done;
 	}
 
-	pdata->link_frequency = bus_cfg->link_frequencies[0];
+	pdata->link_frequency = bus_cfg.link_frequencies[0];
 
 done:
-	v4l2_fwnode_endpoint_free(bus_cfg);
+	v4l2_fwnode_endpoint_free(&bus_cfg);
 	of_node_put(endpoint);
 	return pdata;
 }
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 9e33c2008ba6..048ab6cfaa97 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2761,7 +2761,7 @@ static int __maybe_unused smiapp_resume(struct device *dev)
 static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 {
 	struct smiapp_hwconfig *hwcfg;
-	struct v4l2_fwnode_endpoint *bus_cfg;
+	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct fwnode_handle *ep;
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
 	u32 rotation;
@@ -2775,27 +2775,27 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	if (!ep)
 		return NULL;
 
-	bus_cfg = v4l2_fwnode_endpoint_alloc_parse(ep);
-	if (IS_ERR(bus_cfg))
+	rval = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
+	if (rval)
 		goto out_err;
 
 	hwcfg = devm_kzalloc(dev, sizeof(*hwcfg), GFP_KERNEL);
 	if (!hwcfg)
 		goto out_err;
 
-	switch (bus_cfg->bus_type) {
+	switch (bus_cfg.bus_type) {
 	case V4L2_MBUS_CSI2_DPHY:
 		hwcfg->csi_signalling_mode = SMIAPP_CSI_SIGNALLING_MODE_CSI2;
-		hwcfg->lanes = bus_cfg->bus.mipi_csi2.num_data_lanes;
+		hwcfg->lanes = bus_cfg.bus.mipi_csi2.num_data_lanes;
 		break;
 	case V4L2_MBUS_CCP2:
-		hwcfg->csi_signalling_mode = (bus_cfg->bus.mipi_csi1.strobe) ?
+		hwcfg->csi_signalling_mode = (bus_cfg.bus.mipi_csi1.strobe) ?
 		SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_STROBE :
 		SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK;
 		hwcfg->lanes = 1;
 		break;
 	default:
-		dev_err(dev, "unsupported bus %u\n", bus_cfg->bus_type);
+		dev_err(dev, "unsupported bus %u\n", bus_cfg.bus_type);
 		goto out_err;
 	}
 
@@ -2827,28 +2827,28 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	dev_dbg(dev, "nvm %d, clk %d, mode %d\n",
 		hwcfg->nvm_size, hwcfg->ext_clk, hwcfg->csi_signalling_mode);
 
-	if (!bus_cfg->nr_of_link_frequencies) {
+	if (!bus_cfg.nr_of_link_frequencies) {
 		dev_warn(dev, "no link frequencies defined\n");
 		goto out_err;
 	}
 
 	hwcfg->op_sys_clock = devm_kcalloc(
-		dev, bus_cfg->nr_of_link_frequencies + 1 /* guardian */,
+		dev, bus_cfg.nr_of_link_frequencies + 1 /* guardian */,
 		sizeof(*hwcfg->op_sys_clock), GFP_KERNEL);
 	if (!hwcfg->op_sys_clock)
 		goto out_err;
 
-	for (i = 0; i < bus_cfg->nr_of_link_frequencies; i++) {
-		hwcfg->op_sys_clock[i] = bus_cfg->link_frequencies[i];
+	for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++) {
+		hwcfg->op_sys_clock[i] = bus_cfg.link_frequencies[i];
 		dev_dbg(dev, "freq %d: %lld\n", i, hwcfg->op_sys_clock[i]);
 	}
 
-	v4l2_fwnode_endpoint_free(bus_cfg);
+	v4l2_fwnode_endpoint_free(&bus_cfg);
 	fwnode_handle_put(ep);
 	return hwcfg;
 
 out_err:
-	v4l2_fwnode_endpoint_free(bus_cfg);
+	v4l2_fwnode_endpoint_free(&bus_cfg);
 	fwnode_handle_put(ep);
 	return NULL;
 }
diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
index 6a2064597124..8402d540eb8c 100644
--- a/drivers/media/i2c/tc358743.c
+++ b/drivers/media/i2c/tc358743.c
@@ -1895,11 +1895,11 @@ static void tc358743_gpio_reset(struct tc358743_state *state)
 static int tc358743_probe_of(struct tc358743_state *state)
 {
 	struct device *dev = &state->i2c_client->dev;
-	struct v4l2_fwnode_endpoint *endpoint;
+	struct v4l2_fwnode_endpoint endpoint = { .bus_type = 0 };
 	struct device_node *ep;
 	struct clk *refclk;
 	u32 bps_pr_lane;
-	int ret = -EINVAL;
+	int ret;
 
 	refclk = devm_clk_get(dev, "refclk");
 	if (IS_ERR(refclk)) {
@@ -1915,26 +1915,28 @@ static int tc358743_probe_of(struct tc358743_state *state)
 		return -EINVAL;
 	}
 
-	endpoint = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(ep));
-	if (IS_ERR(endpoint)) {
+	ret = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(ep), &endpoint);
+	if (ret) {
 		dev_err(dev, "failed to parse endpoint\n");
-		ret = PTR_ERR(endpoint);
+		ret = ret;
 		goto put_node;
 	}
 
-	if (endpoint->bus_type != V4L2_MBUS_CSI2_DPHY ||
-	    endpoint->bus.mipi_csi2.num_data_lanes == 0 ||
-	    endpoint->nr_of_link_frequencies == 0) {
+	if (endpoint.bus_type != V4L2_MBUS_CSI2_DPHY ||
+	    endpoint.bus.mipi_csi2.num_data_lanes == 0 ||
+	    endpoint.nr_of_link_frequencies == 0) {
 		dev_err(dev, "missing CSI-2 properties in endpoint\n");
+		ret = -EINVAL;
 		goto free_endpoint;
 	}
 
-	if (endpoint->bus.mipi_csi2.num_data_lanes > 4) {
+	if (endpoint.bus.mipi_csi2.num_data_lanes > 4) {
 		dev_err(dev, "invalid number of lanes\n");
+		ret = -EINVAL;
 		goto free_endpoint;
 	}
 
-	state->bus = endpoint->bus.mipi_csi2;
+	state->bus = endpoint.bus.mipi_csi2;
 
 	ret = clk_prepare_enable(refclk);
 	if (ret) {
@@ -1967,7 +1969,7 @@ static int tc358743_probe_of(struct tc358743_state *state)
 	 * The CSI bps per lane must be between 62.5 Mbps and 1 Gbps.
 	 * The default is 594 Mbps for 4-lane 1080p60 or 2-lane 720p60.
 	 */
-	bps_pr_lane = 2 * endpoint->link_frequencies[0];
+	bps_pr_lane = 2 * endpoint.link_frequencies[0];
 	if (bps_pr_lane < 62500000U || bps_pr_lane > 1000000000U) {
 		dev_err(dev, "unsupported bps per lane: %u bps\n", bps_pr_lane);
 		goto disable_clk;
@@ -2013,7 +2015,7 @@ static int tc358743_probe_of(struct tc358743_state *state)
 disable_clk:
 	clk_disable_unprepare(refclk);
 free_endpoint:
-	v4l2_fwnode_endpoint_free(endpoint);
+	v4l2_fwnode_endpoint_free(&endpoint);
 put_node:
 	of_node_put(ep);
 	return ret;
diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 4f351d93b826..801831c802a9 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -290,23 +290,17 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep)
 		return;
 
 	kfree(vep->link_frequencies);
-	kfree(vep);
 }
 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_free);
 
-struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
-	struct fwnode_handle *fwnode)
+int v4l2_fwnode_endpoint_alloc_parse(
+	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep)
 {
-	struct v4l2_fwnode_endpoint *vep;
 	int rval;
 
-	vep = kzalloc(sizeof(*vep), GFP_KERNEL);
-	if (!vep)
-		return ERR_PTR(-ENOMEM);
-
 	rval = __v4l2_fwnode_endpoint_parse(fwnode, vep);
 	if (rval < 0)
-		goto out_err;
+		return rval;
 
 	rval = fwnode_property_read_u64_array(fwnode, "link-frequencies",
 					      NULL, 0);
@@ -316,18 +310,18 @@ struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
 		vep->link_frequencies =
 			kmalloc_array(rval, sizeof(*vep->link_frequencies),
 				      GFP_KERNEL);
-		if (!vep->link_frequencies) {
-			rval = -ENOMEM;
-			goto out_err;
-		}
+		if (!vep->link_frequencies)
+			return -ENOMEM;
 
 		vep->nr_of_link_frequencies = rval;
 
 		rval = fwnode_property_read_u64_array(
 			fwnode, "link-frequencies", vep->link_frequencies,
 			vep->nr_of_link_frequencies);
-		if (rval < 0)
-			goto out_err;
+		if (rval < 0) {
+			v4l2_fwnode_endpoint_free(vep);
+			return rval;
+		}
 
 		for (i = 0; i < vep->nr_of_link_frequencies; i++)
 			pr_info("link-frequencies %u value %llu\n", i,
@@ -336,11 +330,7 @@ struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
 
 	pr_debug("===== end V4L2 endpoint properties\n");
 
-	return vep;
-
-out_err:
-	v4l2_fwnode_endpoint_free(vep);
-	return ERR_PTR(rval);
+	return 0;
 }
 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_alloc_parse);
 
@@ -392,9 +382,9 @@ static int v4l2_async_notifier_fwnode_parse_endpoint(
 			    struct v4l2_fwnode_endpoint *vep,
 			    struct v4l2_async_subdev *asd))
 {
+	struct v4l2_fwnode_endpoint vep = { .bus_type = V4L2_MBUS_UNKNOWN };
 	struct v4l2_async_subdev *asd;
-	struct v4l2_fwnode_endpoint *vep;
-	int ret = 0;
+	int ret;
 
 	asd = kzalloc(asd_struct_size, GFP_KERNEL);
 	if (!asd)
@@ -409,23 +399,22 @@ static int v4l2_async_notifier_fwnode_parse_endpoint(
 		goto out_err;
 	}
 
-	vep = v4l2_fwnode_endpoint_alloc_parse(endpoint);
-	if (IS_ERR(vep)) {
-		ret = PTR_ERR(vep);
+	ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &vep);
+	if (ret) {
 		dev_warn(dev, "unable to parse V4L2 fwnode endpoint (%d)\n",
 			 ret);
 		goto out_err;
 	}
 
-	ret = parse_endpoint ? parse_endpoint(dev, vep, asd) : 0;
+	ret = parse_endpoint ? parse_endpoint(dev, &vep, asd) : 0;
 	if (ret == -ENOTCONN)
-		dev_dbg(dev, "ignoring port@%u/endpoint@%u\n", vep->base.port,
-			vep->base.id);
+		dev_dbg(dev, "ignoring port@%u/endpoint@%u\n", vep.base.port,
+			vep.base.id);
 	else if (ret < 0)
 		dev_warn(dev,
 			 "driver could not parse port@%u/endpoint@%u (%d)\n",
-			 vep->base.port, vep->base.id, ret);
-	v4l2_fwnode_endpoint_free(vep);
+			 vep.base.port, vep.base.id, ret);
+	v4l2_fwnode_endpoint_free(&vep);
 	if (ret < 0)
 		goto out_err;
 
diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
index 8b4873c37098..4a371c3ad86c 100644
--- a/include/media/v4l2-fwnode.h
+++ b/include/media/v4l2-fwnode.h
@@ -161,6 +161,7 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
 /**
  * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties
  * @fwnode: pointer to the endpoint's fwnode handle
+ * @vep: pointer to the V4L2 fwnode 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
@@ -170,6 +171,8 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
  * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
  * reference to @fwnode.
  *
+ * The caller must set the bus_type field of @vep to zero.
+ *
  * v4l2_fwnode_endpoint_alloc_parse() has two important differences to
  * v4l2_fwnode_endpoint_parse():
  *
@@ -178,11 +181,10 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
  * 2. The memory it has allocated to store the variable size data must be freed
  *    using v4l2_fwnode_endpoint_free() when no longer needed.
  *
- * Return: Pointer to v4l2_fwnode_endpoint if successful, on an error pointer
- * on error.
+ * Return: 0 on success or a negative error code on failure.
  */
-struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
-	struct fwnode_handle *fwnode);
+int v4l2_fwnode_endpoint_alloc_parse(
+	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep);
 
 /**
  * v4l2_fwnode_parse_link() - parse a link between two endpoints
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 08/23] v4l: fwnode: Detect bus type correctly
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (6 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 07/23] v4l: fwnode: Let the caller provide V4L2 fwnode endpoint Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 09/23] v4l: fwnode: Make use of newly specified bus types Sakari Ailus
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

In case the device supports multiple video bus types on an endpoint, the
V4L2 fwnode framework attempts to detect the type based on the available
information. This wasn't working really well, and sometimes could lead to
the V4L2 fwnode endpoint struct as being mishandled between the bus types.

Default to Bt.656 if no properties suggesting a bus type are found.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 31 +++++++++++++++++--------------
 include/media/v4l2-mediabus.h         |  2 ++
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 801831c802a9..52bd9f839fb2 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -114,8 +114,11 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 		flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
 	}
 
-	bus->flags = flags;
-	vep->bus_type = V4L2_MBUS_CSI2_DPHY;
+	if (lanes_used || have_clk_lane ||
+	    (flags & ~V4L2_MBUS_CSI2_CONTINUOUS_CLOCK)) {
+		bus->flags = flags;
+		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
+	}
 
 	return 0;
 }
@@ -145,11 +148,6 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
 		pr_debug("field-even-active %s\n", v ? "high" : "low");
 	}
 
-	if (flags)
-		vep->bus_type = V4L2_MBUS_PARALLEL;
-	else
-		vep->bus_type = V4L2_MBUS_BT656;
-
 	if (!fwnode_property_read_u32(fwnode, "pclk-sample", &v)) {
 		flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
 			V4L2_MBUS_PCLK_SAMPLE_FALLING;
@@ -192,13 +190,21 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
 	}
 
 	bus->flags = flags;
-
+	if (flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH |
+		     V4L2_MBUS_HSYNC_ACTIVE_LOW |
+		     V4L2_MBUS_VSYNC_ACTIVE_HIGH |
+		     V4L2_MBUS_VSYNC_ACTIVE_LOW |
+		     V4L2_MBUS_FIELD_EVEN_HIGH |
+		     V4L2_MBUS_FIELD_EVEN_LOW))
+		vep->bus_type = V4L2_MBUS_PARALLEL;
+	else
+		vep->bus_type = V4L2_MBUS_BT656;
 }
 
 static void
 v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle *fwnode,
 				    struct v4l2_fwnode_endpoint *vep,
-				    u32 bus_type)
+				    enum v4l2_fwnode_bus_type bus_type)
 {
 	struct v4l2_fwnode_bus_mipi_csi1 *bus = &vep->bus.mipi_csi1;
 	u32 v;
@@ -250,11 +256,8 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep);
 		if (rval)
 			return rval;
-		/*
-		 * Parse the parallel video bus properties only if none
-		 * of the MIPI CSI-2 specific properties were found.
-		 */
-		if (vep->bus.mipi_csi2.flags == 0)
+
+		if (vep->bus_type == V4L2_MBUS_UNKNOWN)
 			v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep);
 
 		break;
diff --git a/include/media/v4l2-mediabus.h b/include/media/v4l2-mediabus.h
index 26e1c644ded6..df1d552e9df6 100644
--- a/include/media/v4l2-mediabus.h
+++ b/include/media/v4l2-mediabus.h
@@ -70,6 +70,7 @@
 
 /**
  * enum v4l2_mbus_type - media bus type
+ * @V4L2_MBUS_UNKNOWN:	unknown bus type, no V4L2 mediabus configuration
  * @V4L2_MBUS_PARALLEL:	parallel interface with hsync and vsync
  * @V4L2_MBUS_BT656:	parallel interface with embedded synchronisation, can
  *			also be used for BT.1120
@@ -79,6 +80,7 @@
  * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
  */
 enum v4l2_mbus_type {
+	V4L2_MBUS_UNKNOWN,
 	V4L2_MBUS_PARALLEL,
 	V4L2_MBUS_BT656,
 	V4L2_MBUS_CSI1,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 09/23] v4l: fwnode: Make use of newly specified bus types
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (7 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 08/23] v4l: fwnode: Detect bus type correctly Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 10/23] v4l: fwnode: Read lane inversion information despite lane numbering Sakari Ailus
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Add support for parsing CSI-2 D-PHY, parallel or Bt.656 bus explicitly.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 53 ++++++++++++++++++++++++++++-------
 1 file changed, 43 insertions(+), 10 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 52bd9f839fb2..ff34a7e47967 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -123,8 +123,16 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 	return 0;
 }
 
+#define PARALLEL_MBUS_FLAGS (V4L2_MBUS_HSYNC_ACTIVE_HIGH |	\
+			     V4L2_MBUS_HSYNC_ACTIVE_LOW |	\
+			     V4L2_MBUS_VSYNC_ACTIVE_HIGH |	\
+			     V4L2_MBUS_VSYNC_ACTIVE_LOW |	\
+			     V4L2_MBUS_FIELD_EVEN_HIGH |	\
+			     V4L2_MBUS_FIELD_EVEN_LOW)
+
 static void v4l2_fwnode_endpoint_parse_parallel_bus(
-	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep)
+	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep,
+	enum v4l2_fwnode_bus_type bus_type)
 {
 	struct v4l2_fwnode_bus_parallel *bus = &vep->bus.parallel;
 	unsigned int flags = 0;
@@ -189,16 +197,28 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
 		pr_debug("data-enable-active %s\n", v ? "high" : "low");
 	}
 
-	bus->flags = flags;
-	if (flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH |
-		     V4L2_MBUS_HSYNC_ACTIVE_LOW |
-		     V4L2_MBUS_VSYNC_ACTIVE_HIGH |
-		     V4L2_MBUS_VSYNC_ACTIVE_LOW |
-		     V4L2_MBUS_FIELD_EVEN_HIGH |
-		     V4L2_MBUS_FIELD_EVEN_LOW))
+	switch (bus_type) {
+	default:
+		bus->flags = flags;
+		if (flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH |
+			     V4L2_MBUS_HSYNC_ACTIVE_LOW |
+			     V4L2_MBUS_VSYNC_ACTIVE_HIGH |
+			     V4L2_MBUS_VSYNC_ACTIVE_LOW |
+			     V4L2_MBUS_FIELD_EVEN_HIGH |
+			     V4L2_MBUS_FIELD_EVEN_LOW))
+			vep->bus_type = V4L2_MBUS_PARALLEL;
+		else
+			vep->bus_type = V4L2_MBUS_BT656;
+		break;
+	case V4L2_FWNODE_BUS_TYPE_PARALLEL:
 		vep->bus_type = V4L2_MBUS_PARALLEL;
-	else
+		bus->flags = flags;
+		break;
+	case V4L2_FWNODE_BUS_TYPE_BT656:
 		vep->bus_type = V4L2_MBUS_BT656;
+		bus->flags = flags & ~PARALLEL_MBUS_FLAGS;
+		break;
+	}
 }
 
 static void
@@ -258,7 +278,8 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 			return rval;
 
 		if (vep->bus_type == V4L2_MBUS_UNKNOWN)
-			v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep);
+			v4l2_fwnode_endpoint_parse_parallel_bus(
+				fwnode, vep, V4L2_MBUS_UNKNOWN);
 
 		break;
 	case V4L2_FWNODE_BUS_TYPE_CCP2:
@@ -266,6 +287,18 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 		v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, bus_type);
 
 		break;
+	case V4L2_FWNODE_BUS_TYPE_CSI2_DPHY:
+		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
+		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep);
+		if (rval)
+			return rval;
+
+		break;
+	case V4L2_FWNODE_BUS_TYPE_PARALLEL:
+	case V4L2_FWNODE_BUS_TYPE_BT656:
+		v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep, bus_type);
+
+		break;
 	default:
 		pr_warn("unsupported bus type %u\n", bus_type);
 		return -EINVAL;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 10/23] v4l: fwnode: Read lane inversion information despite lane numbering
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (8 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 09/23] v4l: fwnode: Make use of newly specified bus types Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 11/23] v4l: fwnode: Only assign configuration if there is no error Sakari Ailus
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Read the lane inversion independently of whether the "data-lanes" property
exists. This makes sense since the caller may pass the number of lanes as
the default configuration while the lane inversion configuration may still
be available in firmware.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 65 +++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 30 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index ff34a7e47967..fb086242d2d9 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -43,26 +43,31 @@ enum v4l2_fwnode_bus_type {
 };
 
 static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
-					       struct v4l2_fwnode_endpoint *vep)
+					       struct v4l2_fwnode_endpoint *vep,
+					       enum v4l2_fwnode_bus_type bus_type)
 {
 	struct v4l2_fwnode_bus_mipi_csi2 *bus = &vep->bus.mipi_csi2;
 	bool have_clk_lane = false;
 	unsigned int flags = 0, lanes_used = 0;
+	u32 array[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES];
+	unsigned int num_data_lanes = 0;
 	unsigned int i;
 	u32 v;
 	int rval;
 
+	if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY)
+		num_data_lanes = min_t(u32, bus->num_data_lanes,
+				       V4L2_FWNODE_CSI2_MAX_DATA_LANES);
+
 	rval = fwnode_property_read_u32_array(fwnode, "data-lanes", NULL, 0);
 	if (rval > 0) {
-		u32 array[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES];
-
-		bus->num_data_lanes =
+		num_data_lanes =
 			min_t(int, V4L2_FWNODE_CSI2_MAX_DATA_LANES, rval);
 
 		fwnode_property_read_u32_array(fwnode, "data-lanes", array,
-					       bus->num_data_lanes);
+					       num_data_lanes);
 
-		for (i = 0; i < bus->num_data_lanes; i++) {
+		for (i = 0; i < num_data_lanes; i++) {
 			if (lanes_used & BIT(array[i]))
 				pr_warn("duplicated lane %u in data-lanes\n",
 					array[i]);
@@ -71,30 +76,27 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 			bus->data_lanes[i] = array[i];
 			pr_debug("lane %u position %u\n", i, array[i]);
 		}
+	}
 
-		rval = fwnode_property_read_u32_array(fwnode,
-						      "lane-polarities", NULL,
-						      0);
-		if (rval > 0) {
-			if (rval != 1 + bus->num_data_lanes /* clock+data */) {
-				pr_warn("invalid number of lane-polarities entries (need %u, got %u)\n",
-					1 + bus->num_data_lanes, rval);
-				return -EINVAL;
-			}
+	rval = fwnode_property_read_u32_array(fwnode, "lane-polarities", NULL,
+					      0);
+	if (rval > 0) {
+		if (rval != 1 + num_data_lanes /* clock+data */) {
+			pr_warn("invalid number of lane-polarities entries (need %u, got %u)\n",
+				1 + num_data_lanes, rval);
+			return -EINVAL;
+		}
 
-			fwnode_property_read_u32_array(fwnode,
-						       "lane-polarities", array,
-						       1 + bus->num_data_lanes);
+		fwnode_property_read_u32_array(fwnode, "lane-polarities", array,
+					       1 + num_data_lanes);
 
-			for (i = 0; i < 1 + bus->num_data_lanes; i++) {
-				bus->lane_polarities[i] = array[i];
-				pr_debug("lane %u polarity %sinverted",
-					 i, array[i] ? "" : "not ");
-			}
-		} else {
-			pr_debug("no lane polarities defined, assuming not inverted\n");
+		for (i = 0; i < 1 + num_data_lanes; i++) {
+			bus->lane_polarities[i] = array[i];
+			pr_debug("lane %u polarity %sinverted",
+				 i, array[i] ? "" : "not ");
 		}
-
+	} else {
+		pr_debug("no lane polarities defined, assuming not inverted\n");
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) {
@@ -114,10 +116,11 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 		flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
 	}
 
-	if (lanes_used || have_clk_lane ||
-	    (flags & ~V4L2_MBUS_CSI2_CONTINUOUS_CLOCK)) {
+	if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY || lanes_used ||
+	    have_clk_lane || (flags & ~V4L2_MBUS_CSI2_CONTINUOUS_CLOCK)) {
 		bus->flags = flags;
 		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
+		bus->num_data_lanes = num_data_lanes;
 	}
 
 	return 0;
@@ -273,7 +276,8 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 
 	switch (bus_type) {
 	case V4L2_FWNODE_BUS_TYPE_GUESS:
-		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep);
+		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
+							   bus_type);
 		if (rval)
 			return rval;
 
@@ -289,7 +293,8 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 		break;
 	case V4L2_FWNODE_BUS_TYPE_CSI2_DPHY:
 		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
-		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep);
+		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
+							   bus_type);
 		if (rval)
 			return rval;
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 11/23] v4l: fwnode: Only assign configuration if there is no error
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (9 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 10/23] v4l: fwnode: Read lane inversion information despite lane numbering Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 12/23] v4l: fwnode: Support driver-defined lane mapping defaults Sakari Ailus
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Only assign endpoint configuration if the endpoint is parsed successfully.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index fb086242d2d9..ea9262305968 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -47,7 +47,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 					       enum v4l2_fwnode_bus_type bus_type)
 {
 	struct v4l2_fwnode_bus_mipi_csi2 *bus = &vep->bus.mipi_csi2;
-	bool have_clk_lane = false;
+	bool have_clk_lane = false, have_lane_polarities = false;
 	unsigned int flags = 0, lanes_used = 0;
 	u32 array[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES];
 	unsigned int num_data_lanes = 0;
@@ -73,7 +73,6 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 					array[i]);
 			lanes_used |= BIT(array[i]);
 
-			bus->data_lanes[i] = array[i];
 			pr_debug("lane %u position %u\n", i, array[i]);
 		}
 	}
@@ -87,16 +86,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 			return -EINVAL;
 		}
 
-		fwnode_property_read_u32_array(fwnode, "lane-polarities", array,
-					       1 + num_data_lanes);
-
-		for (i = 0; i < 1 + num_data_lanes; i++) {
-			bus->lane_polarities[i] = array[i];
-			pr_debug("lane %u polarity %sinverted",
-				 i, array[i] ? "" : "not ");
-		}
-	} else {
-		pr_debug("no lane polarities defined, assuming not inverted\n");
+		have_lane_polarities = true;
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) {
@@ -121,6 +111,22 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 		bus->flags = flags;
 		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
 		bus->num_data_lanes = num_data_lanes;
+		for (i = 0; i < num_data_lanes; i++)
+			bus->data_lanes[i] = array[i];
+
+		if (have_lane_polarities) {
+			fwnode_property_read_u32_array(fwnode,
+						       "lane-polarities", array,
+						       1 + num_data_lanes);
+
+			for (i = 0; i < 1 + num_data_lanes; i++) {
+				bus->lane_polarities[i] = array[i];
+				pr_debug("lane %u polarity %sinverted",
+					 i, array[i] ? "" : "not ");
+			}
+		} else {
+			pr_debug("no lane polarities defined, assuming not inverted\n");
+		}
 	}
 
 	return 0;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 12/23] v4l: fwnode: Support driver-defined lane mapping defaults
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (10 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 11/23] v4l: fwnode: Only assign configuration if there is no error Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 13/23] v4l: fwnode: Support default CSI-2 lane mapping for drivers Sakari Ailus
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Make use of the default CSI-2 lane mapping from caller-passed
configuration.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index ea9262305968..282595c90818 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -55,10 +55,14 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 	u32 v;
 	int rval;
 
-	if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY)
+	if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY) {
 		num_data_lanes = min_t(u32, bus->num_data_lanes,
 				       V4L2_FWNODE_CSI2_MAX_DATA_LANES);
 
+		for (i = 0; i < num_data_lanes; i++)
+			array[i] = bus->data_lanes[i];
+	}
+
 	rval = fwnode_property_read_u32_array(fwnode, "data-lanes", NULL, 0);
 	if (rval > 0) {
 		num_data_lanes =
@@ -66,15 +70,15 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 
 		fwnode_property_read_u32_array(fwnode, "data-lanes", array,
 					       num_data_lanes);
+	}
 
-		for (i = 0; i < num_data_lanes; i++) {
-			if (lanes_used & BIT(array[i]))
-				pr_warn("duplicated lane %u in data-lanes\n",
-					array[i]);
-			lanes_used |= BIT(array[i]);
+	for (i = 0; i < num_data_lanes; i++) {
+		if (lanes_used & BIT(array[i]))
+			pr_warn("duplicated lane %u in data-lanes\n",
+				array[i]);
+		lanes_used |= BIT(array[i]);
 
-			pr_debug("lane %u position %u\n", i, array[i]);
-		}
+		pr_debug("lane %u position %u\n", i, array[i]);
 	}
 
 	rval = fwnode_property_read_u32_array(fwnode, "lane-polarities", NULL,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 13/23] v4l: fwnode: Support default CSI-2 lane mapping for drivers
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (11 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 12/23] v4l: fwnode: Support driver-defined lane mapping defaults Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 14/23] v4l: fwnode: Parse the graph endpoint as last Sakari Ailus
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Most hardware doesn't support re-mapping of the CSI-2 lanes. Especially
sensor drivers have a default number of lanes. Instead of requiring the
caller (the driver) to provide such a unit mapping, provide one if no
mapping is configured.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 60 +++++++++++++++++++++++++++--------
 1 file changed, 46 insertions(+), 14 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 282595c90818..0ddf05bb589a 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -47,20 +47,35 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 					       enum v4l2_fwnode_bus_type bus_type)
 {
 	struct v4l2_fwnode_bus_mipi_csi2 *bus = &vep->bus.mipi_csi2;
-	bool have_clk_lane = false, have_lane_polarities = false;
+	bool have_clk_lane = false, have_data_lanes = false,
+		have_lane_polarities = false;
 	unsigned int flags = 0, lanes_used = 0;
 	u32 array[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES];
+	u32 clock_lane = 0;
 	unsigned int num_data_lanes = 0;
+	bool use_default_lane_mapping = false;
 	unsigned int i;
 	u32 v;
 	int rval;
 
 	if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY) {
+		use_default_lane_mapping = true;
+
 		num_data_lanes = min_t(u32, bus->num_data_lanes,
 				       V4L2_FWNODE_CSI2_MAX_DATA_LANES);
 
-		for (i = 0; i < num_data_lanes; i++)
+		clock_lane = bus->clock_lane;
+		if (clock_lane)
+			use_default_lane_mapping = false;
+
+		for (i = 0; i < num_data_lanes; i++) {
 			array[i] = bus->data_lanes[i];
+			if (array[i])
+				use_default_lane_mapping = false;
+		}
+
+		if (use_default_lane_mapping)
+			pr_debug("using default lane mapping\n");
 	}
 
 	rval = fwnode_property_read_u32_array(fwnode, "data-lanes", NULL, 0);
@@ -70,15 +85,21 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 
 		fwnode_property_read_u32_array(fwnode, "data-lanes", array,
 					       num_data_lanes);
+
+		have_data_lanes = true;
 	}
 
 	for (i = 0; i < num_data_lanes; i++) {
-		if (lanes_used & BIT(array[i]))
-			pr_warn("duplicated lane %u in data-lanes\n",
-				array[i]);
+		if (lanes_used & BIT(array[i])) {
+			if (have_data_lanes || !use_default_lane_mapping)
+				pr_warn("duplicated lane %u in data-lanes, using defaults\n",
+					array[i]);
+			use_default_lane_mapping = true;
+		}
 		lanes_used |= BIT(array[i]);
 
-		pr_debug("lane %u position %u\n", i, array[i]);
+		if (have_data_lanes)
+			pr_debug("lane %u position %u\n", i, array[i]);
 	}
 
 	rval = fwnode_property_read_u32_array(fwnode, "lane-polarities", NULL,
@@ -94,13 +115,16 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) {
-		if (lanes_used & BIT(v))
-			pr_warn("duplicated lane %u in clock-lanes\n", v);
-		lanes_used |= BIT(v);
-
-		bus->clock_lane = v;
-		have_clk_lane = true;
+		clock_lane = v;
 		pr_debug("clock lane position %u\n", v);
+		have_clk_lane = true;
+	}
+
+	if (lanes_used & BIT(clock_lane)) {
+		if (have_clk_lane || !use_default_lane_mapping)
+			pr_warn("duplicated lane %u in clock-lanes, using defaults\n",
+			v);
+		use_default_lane_mapping = true;
 	}
 
 	if (fwnode_property_present(fwnode, "clock-noncontinuous")) {
@@ -115,8 +139,16 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 		bus->flags = flags;
 		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
 		bus->num_data_lanes = num_data_lanes;
-		for (i = 0; i < num_data_lanes; i++)
-			bus->data_lanes[i] = array[i];
+
+		if (use_default_lane_mapping) {
+			bus->clock_lane = 0;
+			for (i = 0; i < num_data_lanes; i++)
+				bus->data_lanes[i] = 1 + i;
+		} else {
+			bus->clock_lane = clock_lane;
+			for (i = 0; i < num_data_lanes; i++)
+				bus->data_lanes[i] = array[i];
+		}
 
 		if (have_lane_polarities) {
 			fwnode_property_read_u32_array(fwnode,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 14/23] v4l: fwnode: Parse the graph endpoint as last
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (12 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 13/23] v4l: fwnode: Support default CSI-2 lane mapping for drivers Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 15/23] v4l: fwnode: Use default parallel flags Sakari Ailus
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Parsing the graph endpoint is always successful; therefore parse it as
last.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 0ddf05bb589a..c7a52962a9c0 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -308,7 +308,11 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 
 	pr_debug("===== begin V4L2 endpoint properties\n");
 
-	fwnode_graph_parse_endpoint(fwnode, &vep->base);
+	/*
+	 * Zero the fwnode graph endpoint memory in case we don't end up parsing
+	 * the endpoint.
+	 */
+	memset(&vep->base, 0, sizeof(vep->base));
 
 	/* Zero fields from bus_type to until the end */
 	memset(&vep->bus_type, 0, sizeof(*vep) -
@@ -351,6 +355,8 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 		return -EINVAL;
 	}
 
+	fwnode_graph_parse_endpoint(fwnode, &vep->base);
+
 	return 0;
 }
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 15/23] v4l: fwnode: Use default parallel flags
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (13 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 14/23] v4l: fwnode: Parse the graph endpoint as last Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 16/23] v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero Sakari Ailus
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

The caller may provide default flags for the endpoint. Change the
configuration based on what is available through the fwnode property API.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index c7a52962a9c0..ba51c1ead314 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -183,31 +183,44 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
 	unsigned int flags = 0;
 	u32 v;
 
+	if (bus_type == V4L2_MBUS_PARALLEL || bus_type == V4L2_MBUS_BT656)
+		flags = bus->flags;
+
 	if (!fwnode_property_read_u32(fwnode, "hsync-active", &v)) {
+		flags &= ~(V4L2_MBUS_HSYNC_ACTIVE_HIGH |
+			   V4L2_MBUS_HSYNC_ACTIVE_LOW);
 		flags |= v ? V4L2_MBUS_HSYNC_ACTIVE_HIGH :
 			V4L2_MBUS_HSYNC_ACTIVE_LOW;
 		pr_debug("hsync-active %s\n", v ? "high" : "low");
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "vsync-active", &v)) {
+		flags &= ~(V4L2_MBUS_VSYNC_ACTIVE_HIGH |
+			   V4L2_MBUS_VSYNC_ACTIVE_LOW);
 		flags |= v ? V4L2_MBUS_VSYNC_ACTIVE_HIGH :
 			V4L2_MBUS_VSYNC_ACTIVE_LOW;
 		pr_debug("vsync-active %s\n", v ? "high" : "low");
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "field-even-active", &v)) {
+		flags &= ~(V4L2_MBUS_FIELD_EVEN_HIGH |
+			   V4L2_MBUS_FIELD_EVEN_LOW);
 		flags |= v ? V4L2_MBUS_FIELD_EVEN_HIGH :
 			V4L2_MBUS_FIELD_EVEN_LOW;
 		pr_debug("field-even-active %s\n", v ? "high" : "low");
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "pclk-sample", &v)) {
+		flags &= ~(V4L2_MBUS_PCLK_SAMPLE_RISING |
+			   V4L2_MBUS_PCLK_SAMPLE_FALLING);
 		flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
 			V4L2_MBUS_PCLK_SAMPLE_FALLING;
 		pr_debug("pclk-sample %s\n", v ? "high" : "low");
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "data-active", &v)) {
+		flags &= ~(V4L2_MBUS_PCLK_SAMPLE_RISING |
+			   V4L2_MBUS_PCLK_SAMPLE_FALLING);
 		flags |= v ? V4L2_MBUS_DATA_ACTIVE_HIGH :
 			V4L2_MBUS_DATA_ACTIVE_LOW;
 		pr_debug("data-active %s\n", v ? "high" : "low");
@@ -215,8 +228,10 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
 
 	if (fwnode_property_present(fwnode, "slave-mode")) {
 		pr_debug("slave mode\n");
+		flags &= ~V4L2_MBUS_MASTER;
 		flags |= V4L2_MBUS_SLAVE;
 	} else {
+		flags &= ~V4L2_MBUS_SLAVE;
 		flags |= V4L2_MBUS_MASTER;
 	}
 
@@ -231,12 +246,16 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "sync-on-green-active", &v)) {
+		flags &= ~(V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH |
+			   V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW);
 		flags |= v ? V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH :
 			V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW;
 		pr_debug("sync-on-green-active %s\n", v ? "high" : "low");
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "data-enable-active", &v)) {
+		flags &= ~(V4L2_MBUS_DATA_ENABLE_HIGH |
+			   V4L2_MBUS_DATA_ENABLE_LOW);
 		flags |= v ? V4L2_MBUS_DATA_ENABLE_HIGH :
 			V4L2_MBUS_DATA_ENABLE_LOW;
 		pr_debug("data-enable-active %s\n", v ? "high" : "low");
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 16/23] v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (14 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 15/23] v4l: fwnode: Use default parallel flags Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 17/23] v4l: fwnode: Only zero the struct if bus type is set to V4L2_MBUS_UNKNOWN Sakari Ailus
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Initialise the V4L2 fwnode endpoints to zero in all drivers using
v4l2_fwnode_endpoint_parse(). This prepares for setting default endpoint
flags as well as the bus type. Setting bus type to zero will continue to
guess the bus among the guessable set (parallel, Bt.656 and CSI-2 D-PHY).

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/adv7604.c                   | 2 +-
 drivers/media/i2c/mt9v032.c                   | 2 +-
 drivers/media/i2c/ov5647.c                    | 2 +-
 drivers/media/i2c/ov7670.c                    | 2 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c      | 2 +-
 drivers/media/i2c/s5k5baf.c                   | 2 +-
 drivers/media/i2c/tda1997x.c                  | 2 +-
 drivers/media/i2c/tvp514x.c                   | 2 +-
 drivers/media/i2c/tvp5150.c                   | 2 +-
 drivers/media/i2c/tvp7002.c                   | 2 +-
 drivers/media/platform/am437x/am437x-vpfe.c   | 2 +-
 drivers/media/platform/atmel/atmel-isc.c      | 3 ++-
 drivers/media/platform/atmel/atmel-isi.c      | 2 +-
 drivers/media/platform/cadence/cdns-csi2rx.c  | 2 +-
 drivers/media/platform/cadence/cdns-csi2tx.c  | 2 +-
 drivers/media/platform/davinci/vpif_capture.c | 2 +-
 drivers/media/platform/exynos4-is/media-dev.c | 2 +-
 drivers/media/platform/exynos4-is/mipi-csis.c | 2 +-
 drivers/media/platform/pxa_camera.c           | 2 +-
 drivers/media/platform/rcar-vin/rcar-csi2.c   | 2 +-
 drivers/media/platform/renesas-ceu.c          | 3 ++-
 drivers/media/platform/stm32/stm32-dcmi.c     | 2 +-
 include/media/v4l2-fwnode.h                   | 2 ++
 23 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 668be2bca57a..413578dc23a3 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -3093,7 +3093,7 @@ MODULE_DEVICE_TABLE(of, adv76xx_of_id);
 
 static int adv76xx_parse_dt(struct adv76xx_state *state)
 {
-	struct v4l2_fwnode_endpoint bus_cfg;
+	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *endpoint;
 	struct device_node *np;
 	unsigned int flags;
diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c
index f74730d24d8f..67f69ad6ecf4 100644
--- a/drivers/media/i2c/mt9v032.c
+++ b/drivers/media/i2c/mt9v032.c
@@ -989,7 +989,7 @@ static struct mt9v032_platform_data *
 mt9v032_get_pdata(struct i2c_client *client)
 {
 	struct mt9v032_platform_data *pdata = NULL;
-	struct v4l2_fwnode_endpoint endpoint;
+	struct v4l2_fwnode_endpoint endpoint = { .bus_type = 0 };
 	struct device_node *np;
 	struct property *prop;
 
diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index da39c49de503..4589631798c9 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -532,7 +532,7 @@ static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = {
 
 static int ov5647_parse_dt(struct device_node *np)
 {
-	struct v4l2_fwnode_endpoint bus_cfg;
+	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *ep;
 
 	int ret;
diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index 31bf577b0bd3..92f59ae1b624 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -1728,7 +1728,7 @@ static int ov7670_parse_dt(struct device *dev,
 			   struct ov7670_info *info)
 {
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
-	struct v4l2_fwnode_endpoint bus_cfg;
+	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct fwnode_handle *ep;
 	int ret;
 
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 9d5739cafec3..1900475ceb01 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1603,7 +1603,7 @@ static int s5c73m3_get_platform_data(struct s5c73m3 *state)
 	const struct s5c73m3_platform_data *pdata = dev->platform_data;
 	struct device_node *node = dev->of_node;
 	struct device_node *node_ep;
-	struct v4l2_fwnode_endpoint ep;
+	struct v4l2_fwnode_endpoint ep = { .bus_type = 0 };
 	int ret;
 
 	if (!node) {
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 4c41a770b132..727db7c0670a 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1841,7 +1841,7 @@ static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev)
 {
 	struct device_node *node = dev->of_node;
 	struct device_node *node_ep;
-	struct v4l2_fwnode_endpoint ep;
+	struct v4l2_fwnode_endpoint ep = { .bus_type = 0 };
 	int ret;
 
 	if (!node) {
diff --git a/drivers/media/i2c/tda1997x.c b/drivers/media/i2c/tda1997x.c
index d114ac5243ec..c4c2a6134e1e 100644
--- a/drivers/media/i2c/tda1997x.c
+++ b/drivers/media/i2c/tda1997x.c
@@ -2265,7 +2265,7 @@ MODULE_DEVICE_TABLE(of, tda1997x_of_id);
 static int tda1997x_parse_dt(struct tda1997x_state *state)
 {
 	struct tda1997x_platform_data *pdata = &state->pdata;
-	struct v4l2_fwnode_endpoint bus_cfg;
+	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *ep;
 	struct device_node *np;
 	unsigned int flags;
diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index 675b9ae212ab..1cc83cb934e2 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -989,7 +989,7 @@ static struct tvp514x_platform_data *
 tvp514x_get_pdata(struct i2c_client *client)
 {
 	struct tvp514x_platform_data *pdata = NULL;
-	struct v4l2_fwnode_endpoint bus_cfg;
+	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *endpoint;
 	unsigned int flags;
 
diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index 7b0d42bb6c57..54c1d158fd0b 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -1566,7 +1566,7 @@ static int tvp5150_init(struct i2c_client *c)
 
 static int tvp5150_parse_dt(struct tvp5150 *decoder, struct device_node *np)
 {
-	struct v4l2_fwnode_endpoint bus_cfg;
+	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *ep;
 #ifdef CONFIG_MEDIA_CONTROLLER
 	struct device_node *connectors, *child;
diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
index 4f5c627579c7..cab2f2bd0aa9 100644
--- a/drivers/media/i2c/tvp7002.c
+++ b/drivers/media/i2c/tvp7002.c
@@ -889,7 +889,7 @@ static const struct v4l2_subdev_ops tvp7002_ops = {
 static struct tvp7002_config *
 tvp7002_get_pdata(struct i2c_client *client)
 {
-	struct v4l2_fwnode_endpoint bus_cfg;
+	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct tvp7002_config *pdata = NULL;
 	struct device_node *endpoint;
 	unsigned int flags;
diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
index b19e0abd0327..54e985ebc780 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -2426,7 +2426,6 @@ static struct vpfe_config *
 vpfe_get_pdata(struct vpfe_device *vpfe)
 {
 	struct device_node *endpoint = NULL;
-	struct v4l2_fwnode_endpoint bus_cfg;
 	struct device *dev = vpfe->pdev;
 	struct vpfe_subdev_info *sdinfo;
 	struct vpfe_config *pdata;
@@ -2446,6 +2445,7 @@ vpfe_get_pdata(struct vpfe_device *vpfe)
 		return NULL;
 
 	for (i = 0; ; i++) {
+		struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 		struct device_node *rem;
 
 		endpoint = of_graph_get_next_endpoint(dev->of_node, endpoint);
diff --git a/drivers/media/platform/atmel/atmel-isc.c b/drivers/media/platform/atmel/atmel-isc.c
index aff4ebec5006..6a76b8761109 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -2028,7 +2028,6 @@ static int isc_parse_dt(struct device *dev, struct isc_device *isc)
 {
 	struct device_node *np = dev->of_node;
 	struct device_node *epn = NULL, *rem;
-	struct v4l2_fwnode_endpoint v4l2_epn;
 	struct isc_subdev_entity *subdev_entity;
 	unsigned int flags;
 	int ret;
@@ -2036,6 +2035,8 @@ static int isc_parse_dt(struct device *dev, struct isc_device *isc)
 	INIT_LIST_HEAD(&isc->subdev_entities);
 
 	while (1) {
+		struct v4l2_fwnode_endpoint v4l2_epn = { .bus_type = 0 };
+
 		epn = of_graph_get_next_endpoint(np, epn);
 		if (!epn)
 			return 0;
diff --git a/drivers/media/platform/atmel/atmel-isi.c b/drivers/media/platform/atmel/atmel-isi.c
index b05596634505..bc97319549d0 100644
--- a/drivers/media/platform/atmel/atmel-isi.c
+++ b/drivers/media/platform/atmel/atmel-isi.c
@@ -790,7 +790,7 @@ static int atmel_isi_parse_dt(struct atmel_isi *isi,
 			struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
-	struct v4l2_fwnode_endpoint ep;
+	struct v4l2_fwnode_endpoint ep = { .bus_type = 0 };
 	int err;
 
 	/* Default settings for ISI */
diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
index 0776a34f28ee..31ace114eda1 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -361,7 +361,7 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,
 
 static int csi2rx_parse_dt(struct csi2rx_priv *csi2rx)
 {
-	struct v4l2_fwnode_endpoint v4l2_ep;
+	struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 };
 	struct fwnode_handle *fwh;
 	struct device_node *ep;
 	int ret;
diff --git a/drivers/media/platform/cadence/cdns-csi2tx.c b/drivers/media/platform/cadence/cdns-csi2tx.c
index 6224daf891d7..5042d053b94e 100644
--- a/drivers/media/platform/cadence/cdns-csi2tx.c
+++ b/drivers/media/platform/cadence/cdns-csi2tx.c
@@ -432,7 +432,7 @@ static int csi2tx_get_resources(struct csi2tx_priv *csi2tx,
 
 static int csi2tx_check_lanes(struct csi2tx_priv *csi2tx)
 {
-	struct v4l2_fwnode_endpoint v4l2_ep;
+	struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 };
 	struct device_node *ep;
 	int ret;
 
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index bcc3c4f1fe57..8b312dfedbee 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -1509,7 +1509,6 @@ static struct vpif_capture_config *
 vpif_capture_get_pdata(struct platform_device *pdev)
 {
 	struct device_node *endpoint = NULL;
-	struct v4l2_fwnode_endpoint bus_cfg;
 	struct vpif_capture_config *pdata;
 	struct vpif_subdev_info *sdinfo;
 	struct vpif_capture_chan_config *chan;
@@ -1539,6 +1538,7 @@ vpif_capture_get_pdata(struct platform_device *pdev)
 		return NULL;
 
 	for (i = 0; i < VPIF_CAPTURE_NUM_CHANNELS; i++) {
+		struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 		struct device_node *rem;
 		unsigned int flags;
 		int err;
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 8012761d2912..5ec215cfe144 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -390,7 +390,7 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
 {
 	struct fimc_source_info *pd = &fmd->sensor[index].pdata;
 	struct device_node *rem, *ep, *np;
-	struct v4l2_fwnode_endpoint endpoint;
+	struct v4l2_fwnode_endpoint endpoint = { .bus_type = 0 };
 	int ret;
 
 	/* Assume here a port node can have only one endpoint node. */
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
index b4e28a299e26..35cb0162085b 100644
--- a/drivers/media/platform/exynos4-is/mipi-csis.c
+++ b/drivers/media/platform/exynos4-is/mipi-csis.c
@@ -718,7 +718,7 @@ static int s5pcsis_parse_dt(struct platform_device *pdev,
 			    struct csis_state *state)
 {
 	struct device_node *node = pdev->dev.of_node;
-	struct v4l2_fwnode_endpoint endpoint;
+	struct v4l2_fwnode_endpoint endpoint = { .bus_type = 0 };
 	int ret;
 
 	if (of_property_read_u32(node, "clock-frequency",
diff --git a/drivers/media/platform/pxa_camera.c b/drivers/media/platform/pxa_camera.c
index 36e8329f8fa9..d9b72f8a3d18 100644
--- a/drivers/media/platform/pxa_camera.c
+++ b/drivers/media/platform/pxa_camera.c
@@ -2298,7 +2298,7 @@ static int pxa_camera_pdata_from_dt(struct device *dev,
 {
 	u32 mclk_rate;
 	struct device_node *remote, *np = dev->of_node;
-	struct v4l2_fwnode_endpoint ep;
+	struct v4l2_fwnode_endpoint ep = { .bus_type = 0 };
 	int err = of_property_read_u32(np, "clock-frequency",
 				       &mclk_rate);
 	if (!err) {
diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index 25edc2edd197..b0044a08e71e 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -743,7 +743,7 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
 static int rcsi2_parse_dt(struct rcar_csi2 *priv)
 {
 	struct device_node *ep;
-	struct v4l2_fwnode_endpoint v4l2_ep;
+	struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 };
 	int ret;
 
 	ep = of_graph_get_endpoint_by_regs(priv->dev->of_node, 0, 0);
diff --git a/drivers/media/platform/renesas-ceu.c b/drivers/media/platform/renesas-ceu.c
index 16a9b40aa359..7d8b94c4722a 100644
--- a/drivers/media/platform/renesas-ceu.c
+++ b/drivers/media/platform/renesas-ceu.c
@@ -1536,7 +1536,6 @@ static int ceu_parse_platform_data(struct ceu_device *ceudev,
 static int ceu_parse_dt(struct ceu_device *ceudev)
 {
 	struct device_node *of = ceudev->dev->of_node;
-	struct v4l2_fwnode_endpoint fw_ep;
 	struct device_node *ep, *remote;
 	struct ceu_subdev *ceu_sd;
 	unsigned int i;
@@ -1552,6 +1551,8 @@ static int ceu_parse_dt(struct ceu_device *ceudev)
 		return ret;
 
 	for (i = 0; i < num_ep; i++) {
+		struct v4l2_fwnode_endpoint fw_ep = { .bus_type = 0 };
+
 		ep = of_graph_get_endpoint_by_regs(of, 0, i);
 		if (!ep) {
 			dev_err(ceudev->dev,
diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
index 38b52a059985..b5369c56aeb8 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -1621,7 +1621,7 @@ static int dcmi_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *match = NULL;
-	struct v4l2_fwnode_endpoint ep;
+	struct v4l2_fwnode_endpoint ep = { .bus_type = 0 };
 	struct stm32_dcmi *dcmi;
 	struct vb2_queue *q;
 	struct dma_chan *chan;
diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
index 4a371c3ad86c..1ea1a3ecf6d5 100644
--- a/include/media/v4l2-fwnode.h
+++ b/include/media/v4l2-fwnode.h
@@ -139,6 +139,8 @@ struct v4l2_fwnode_link {
  * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
  * reference to @fwnode.
  *
+ * The caller must set the bus_type field of @vep to zero.
+ *
  * NOTE: This function does not parse properties the size of which is variable
  * without a low fixed limit. Please use v4l2_fwnode_endpoint_alloc_parse() in
  * new drivers instead.
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 17/23] v4l: fwnode: Only zero the struct if bus type is set to V4L2_MBUS_UNKNOWN
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (15 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 16/23] v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 18/23] v4l: fwnode: Use media bus type for bus parser selection Sakari Ailus
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

In order to prepare for allowing drivers to set the defaults for a given
bus, make zeroing the struct conditional based on detecting the bus.
All callers now set the bus type to zero which allows only zeroing the
remaining bus union.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index ba51c1ead314..6c5a76442667 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -325,6 +325,12 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 	u32 bus_type = 0;
 	int rval;
 
+	if (vep->bus_type == V4L2_MBUS_UNKNOWN) {
+		/* Zero fields from bus union to until the end */
+		memset(&vep->bus, 0,
+		       sizeof(*vep) - offsetof(typeof(*vep), bus));
+	}
+
 	pr_debug("===== begin V4L2 endpoint properties\n");
 
 	/*
@@ -333,10 +339,6 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 	 */
 	memset(&vep->base, 0, sizeof(vep->base));
 
-	/* Zero fields from bus_type to until the end */
-	memset(&vep->bus_type, 0, sizeof(*vep) -
-	       offsetof(typeof(*vep), bus_type));
-
 	fwnode_property_read_u32(fwnode, "bus-type", &bus_type);
 
 	switch (bus_type) {
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 18/23] v4l: fwnode: Use media bus type for bus parser selection
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (16 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 17/23] v4l: fwnode: Only zero the struct if bus type is set to V4L2_MBUS_UNKNOWN Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-09-12 15:15   ` jacopo mondi
  2018-08-27  9:29 ` [PATCH v2 19/23] v4l: fwnode: Print bus type Sakari Ailus
                   ` (5 subsequent siblings)
  23 siblings, 1 reply; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Use the media bus types instead of the fwnode bus types internally. This
is the interface to the drivers as well, making the use of the fwnode bus
types more localised to the V4L2 fwnode framework.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 100 +++++++++++++++++++++++++++-------
 1 file changed, 80 insertions(+), 20 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 6c5a76442667..d502abd7406b 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -42,9 +42,66 @@ enum v4l2_fwnode_bus_type {
 	NR_OF_V4L2_FWNODE_BUS_TYPE,
 };
 
+static const struct v4l2_fwnode_bus_conv {
+	enum v4l2_fwnode_bus_type fwnode_bus_type;
+	enum v4l2_mbus_type mbus_type;
+	const char *name;
+} busses[] = {
+	{
+		V4L2_FWNODE_BUS_TYPE_GUESS,
+		V4L2_MBUS_UNKNOWN,
+		"not specified",
+	}, {
+		V4L2_FWNODE_BUS_TYPE_CSI2_CPHY,
+		V4L2_MBUS_CSI2_CPHY,
+		"MIPI CSI-2 C-PHY",
+	}, {
+		V4L2_FWNODE_BUS_TYPE_CSI1,
+		V4L2_MBUS_CSI1,
+		"MIPI CSI-1",
+	}, {
+		V4L2_FWNODE_BUS_TYPE_CCP2,
+		V4L2_MBUS_CCP2,
+		"compact camera port 2",
+	}, {
+		V4L2_FWNODE_BUS_TYPE_CSI2_DPHY,
+		V4L2_MBUS_CSI2_DPHY,
+		"MIPI CSI-2 D-PHY",
+	}, {
+		V4L2_FWNODE_BUS_TYPE_PARALLEL,
+		V4L2_MBUS_PARALLEL,
+		"parallel",
+	}, {
+		V4L2_FWNODE_BUS_TYPE_BT656,
+		V4L2_MBUS_BT656,
+		"Bt.656",
+	}
+};
+
+static const struct v4l2_fwnode_bus_conv *
+get_v4l2_fwnode_bus_conv_by_fwnode_bus(enum v4l2_fwnode_bus_type type)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(busses); i++)
+		if (busses[i].fwnode_bus_type == type)
+			return &busses[i];
+
+	return NULL;
+}
+
+static enum v4l2_mbus_type
+v4l2_fwnode_bus_type_to_mbus(enum v4l2_fwnode_bus_type type)
+{
+	const struct v4l2_fwnode_bus_conv *conv =
+		get_v4l2_fwnode_bus_conv_by_fwnode_bus(type);
+
+	return conv ? conv->mbus_type : V4L2_MBUS_UNKNOWN;
+}
+
 static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 					       struct v4l2_fwnode_endpoint *vep,
-					       enum v4l2_fwnode_bus_type bus_type)
+					       enum v4l2_mbus_type bus_type)
 {
 	struct v4l2_fwnode_bus_mipi_csi2 *bus = &vep->bus.mipi_csi2;
 	bool have_clk_lane = false, have_data_lanes = false,
@@ -58,7 +115,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 	u32 v;
 	int rval;
 
-	if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY) {
+	if (bus_type == V4L2_MBUS_CSI2_DPHY) {
 		use_default_lane_mapping = true;
 
 		num_data_lanes = min_t(u32, bus->num_data_lanes,
@@ -134,7 +191,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 		flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
 	}
 
-	if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY || lanes_used ||
+	if (bus_type == V4L2_MBUS_CSI2_DPHY || lanes_used ||
 	    have_clk_lane || (flags & ~V4L2_MBUS_CSI2_CONTINUOUS_CLOCK)) {
 		bus->flags = flags;
 		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
@@ -177,7 +234,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 
 static void v4l2_fwnode_endpoint_parse_parallel_bus(
 	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep,
-	enum v4l2_fwnode_bus_type bus_type)
+	enum v4l2_mbus_type bus_type)
 {
 	struct v4l2_fwnode_bus_parallel *bus = &vep->bus.parallel;
 	unsigned int flags = 0;
@@ -274,11 +331,11 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
 		else
 			vep->bus_type = V4L2_MBUS_BT656;
 		break;
-	case V4L2_FWNODE_BUS_TYPE_PARALLEL:
+	case V4L2_MBUS_PARALLEL:
 		vep->bus_type = V4L2_MBUS_PARALLEL;
 		bus->flags = flags;
 		break;
-	case V4L2_FWNODE_BUS_TYPE_BT656:
+	case V4L2_MBUS_BT656:
 		vep->bus_type = V4L2_MBUS_BT656;
 		bus->flags = flags & ~PARALLEL_MBUS_FLAGS;
 		break;
@@ -288,7 +345,7 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
 static void
 v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle *fwnode,
 				    struct v4l2_fwnode_endpoint *vep,
-				    enum v4l2_fwnode_bus_type bus_type)
+				    enum v4l2_mbus_type bus_type)
 {
 	struct v4l2_fwnode_bus_mipi_csi1 *bus = &vep->bus.mipi_csi1;
 	u32 v;
@@ -313,7 +370,7 @@ v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle *fwnode,
 		pr_debug("clock-lanes %u\n", v);
 	}
 
-	if (bus_type == V4L2_FWNODE_BUS_TYPE_CCP2)
+	if (bus_type == V4L2_MBUS_CCP2)
 		vep->bus_type = V4L2_MBUS_CCP2;
 	else
 		vep->bus_type = V4L2_MBUS_CSI1;
@@ -323,6 +380,7 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 					struct v4l2_fwnode_endpoint *vep)
 {
 	u32 bus_type = 0;
+	enum v4l2_mbus_type mbus_type;
 	int rval;
 
 	if (vep->bus_type == V4L2_MBUS_UNKNOWN) {
@@ -341,10 +399,12 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 
 	fwnode_property_read_u32(fwnode, "bus-type", &bus_type);
 
-	switch (bus_type) {
-	case V4L2_FWNODE_BUS_TYPE_GUESS:
+	mbus_type = v4l2_fwnode_bus_type_to_mbus(bus_type);
+
+	switch (mbus_type) {
+	case V4L2_MBUS_UNKNOWN:
 		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
-							   bus_type);
+							   mbus_type);
 		if (rval)
 			return rval;
 
@@ -353,26 +413,26 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 				fwnode, vep, V4L2_MBUS_UNKNOWN);
 
 		break;
-	case V4L2_FWNODE_BUS_TYPE_CCP2:
-	case V4L2_FWNODE_BUS_TYPE_CSI1:
-		v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, bus_type);
+	case V4L2_MBUS_CCP2:
+	case V4L2_MBUS_CSI1:
+		v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, mbus_type);
 
 		break;
-	case V4L2_FWNODE_BUS_TYPE_CSI2_DPHY:
+	case V4L2_MBUS_CSI2_DPHY:
 		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
 		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
-							   bus_type);
+							   mbus_type);
 		if (rval)
 			return rval;
 
 		break;
-	case V4L2_FWNODE_BUS_TYPE_PARALLEL:
-	case V4L2_FWNODE_BUS_TYPE_BT656:
-		v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep, bus_type);
+	case V4L2_MBUS_PARALLEL:
+	case V4L2_MBUS_BT656:
+		v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep, mbus_type);
 
 		break;
 	default:
-		pr_warn("unsupported bus type %u\n", bus_type);
+		pr_warn("unsupported bus type %u\n", mbus_type);
 		return -EINVAL;
 	}
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 19/23] v4l: fwnode: Print bus type
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (17 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 18/23] v4l: fwnode: Use media bus type for bus parser selection Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 20/23] v4l: fwnode: Use V4L2 fwnode endpoint media bus type if set Sakari Ailus
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Print bus type either as set by the driver or as parsed from the bus-type
property, as well as the guessed V4L2 media bus type.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 38 +++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index d502abd7406b..4c7f16ff79fa 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -99,6 +99,36 @@ v4l2_fwnode_bus_type_to_mbus(enum v4l2_fwnode_bus_type type)
 	return conv ? conv->mbus_type : V4L2_MBUS_UNKNOWN;
 }
 
+static const char *
+v4l2_fwnode_bus_type_to_string(enum v4l2_fwnode_bus_type type)
+{
+	const struct v4l2_fwnode_bus_conv *conv =
+		get_v4l2_fwnode_bus_conv_by_fwnode_bus(type);
+
+	return conv ? conv->name : "not found";
+}
+
+static const struct v4l2_fwnode_bus_conv *
+get_v4l2_fwnode_bus_conv_by_mbus(enum v4l2_mbus_type type)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(busses); i++)
+		if (busses[i].mbus_type == type)
+			return &busses[i];
+
+	return NULL;
+}
+
+static const char *
+v4l2_fwnode_mbus_type_to_string(enum v4l2_mbus_type type)
+{
+	const struct v4l2_fwnode_bus_conv *conv =
+		get_v4l2_fwnode_bus_conv_by_mbus(type);
+
+	return conv ? conv->name : "not found";
+}
+
 static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 					       struct v4l2_fwnode_endpoint *vep,
 					       enum v4l2_mbus_type bus_type)
@@ -398,6 +428,10 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 	memset(&vep->base, 0, sizeof(vep->base));
 
 	fwnode_property_read_u32(fwnode, "bus-type", &bus_type);
+	pr_debug("fwnode video bus type %s (%u), mbus type %s (%u)\n",
+		 v4l2_fwnode_bus_type_to_string(bus_type), bus_type,
+		 v4l2_fwnode_mbus_type_to_string(vep->bus_type),
+		 vep->bus_type);
 
 	mbus_type = v4l2_fwnode_bus_type_to_mbus(bus_type);
 
@@ -412,6 +446,10 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 			v4l2_fwnode_endpoint_parse_parallel_bus(
 				fwnode, vep, V4L2_MBUS_UNKNOWN);
 
+		pr_debug("assuming media bus type %s (%u)\n",
+			 v4l2_fwnode_mbus_type_to_string(vep->bus_type),
+			 vep->bus_type);
+
 		break;
 	case V4L2_MBUS_CCP2:
 	case V4L2_MBUS_CSI1:
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 20/23] v4l: fwnode: Use V4L2 fwnode endpoint media bus type if set
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (18 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 19/23] v4l: fwnode: Print bus type Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 21/23] v4l: fwnode: Support parsing of CSI-2 C-PHY endpoints Sakari Ailus
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Use the given media bus type set by the caller. If none is given (i.e. the
mbus type is V4L2_MBUS_UNKNOWN, or 0), fall back to the old behaviour.
This is to obtain the information from the DT or try to guess the bus
type.

-ENXIO is returned if the caller sets the bus type but that does not match
with what's in DT. Also return -ENXIO if bus type detection failed to
separate this from the rest of the errors.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 4c7f16ff79fa..4c2f7d709c5d 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -409,7 +409,7 @@ v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle *fwnode,
 static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 					struct v4l2_fwnode_endpoint *vep)
 {
-	u32 bus_type = 0;
+	u32 bus_type = V4L2_FWNODE_BUS_TYPE_GUESS;
 	enum v4l2_mbus_type mbus_type;
 	int rval;
 
@@ -432,13 +432,24 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 		 v4l2_fwnode_bus_type_to_string(bus_type), bus_type,
 		 v4l2_fwnode_mbus_type_to_string(vep->bus_type),
 		 vep->bus_type);
-
 	mbus_type = v4l2_fwnode_bus_type_to_mbus(bus_type);
 
-	switch (mbus_type) {
+	if (vep->bus_type != V4L2_MBUS_UNKNOWN) {
+		if (mbus_type != V4L2_MBUS_UNKNOWN &&
+		    vep->bus_type != mbus_type) {
+			pr_debug("expecting bus type %s\n",
+				 v4l2_fwnode_mbus_type_to_string(
+					 vep->bus_type));
+			return -ENXIO;
+		}
+	} else {
+		vep->bus_type = mbus_type;
+	}
+
+	switch (vep->bus_type) {
 	case V4L2_MBUS_UNKNOWN:
 		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
-							   mbus_type);
+							   V4L2_MBUS_UNKNOWN);
 		if (rval)
 			return rval;
 
@@ -453,20 +464,20 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 		break;
 	case V4L2_MBUS_CCP2:
 	case V4L2_MBUS_CSI1:
-		v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, mbus_type);
+		v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, vep->bus_type);
 
 		break;
 	case V4L2_MBUS_CSI2_DPHY:
-		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
 		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
-							   mbus_type);
+							   vep->bus_type);
 		if (rval)
 			return rval;
 
 		break;
 	case V4L2_MBUS_PARALLEL:
 	case V4L2_MBUS_BT656:
-		v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep, mbus_type);
+		v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep,
+							vep->bus_type);
 
 		break;
 	default:
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 21/23] v4l: fwnode: Support parsing of CSI-2 C-PHY endpoints
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (19 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 20/23] v4l: fwnode: Use V4L2 fwnode endpoint media bus type if set Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:29 ` [PATCH v2 22/23] v4l: fwnode: Update V4L2 fwnode endpoint parsing documentation Sakari Ailus
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

The V4L2 fwnode framework only parsed CSI-2 D-PHY endpoints while C-PHY
support wasn't there. Also parse endpoints for media bus type
V4L2_MBUS_CSI2_CPHY.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 4c2f7d709c5d..a863c423ee8c 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -145,7 +145,8 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 	u32 v;
 	int rval;
 
-	if (bus_type == V4L2_MBUS_CSI2_DPHY) {
+	if (bus_type == V4L2_MBUS_CSI2_DPHY ||
+	    bus_type == V4L2_MBUS_CSI2_CPHY) {
 		use_default_lane_mapping = true;
 
 		num_data_lanes = min_t(u32, bus->num_data_lanes,
@@ -221,10 +222,12 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 		flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
 	}
 
-	if (bus_type == V4L2_MBUS_CSI2_DPHY || lanes_used ||
+	if (bus_type == V4L2_MBUS_CSI2_DPHY ||
+	    bus_type == V4L2_MBUS_CSI2_CPHY || lanes_used ||
 	    have_clk_lane || (flags & ~V4L2_MBUS_CSI2_CONTINUOUS_CLOCK)) {
 		bus->flags = flags;
-		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
+		if (bus_type == V4L2_MBUS_UNKNOWN)
+			vep->bus_type = V4L2_MBUS_CSI2_DPHY;
 		bus->num_data_lanes = num_data_lanes;
 
 		if (use_default_lane_mapping) {
@@ -468,6 +471,7 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 
 		break;
 	case V4L2_MBUS_CSI2_DPHY:
+	case V4L2_MBUS_CSI2_CPHY:
 		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
 							   vep->bus_type);
 		if (rval)
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 22/23] v4l: fwnode: Update V4L2 fwnode endpoint parsing documentation
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (20 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 21/23] v4l: fwnode: Support parsing of CSI-2 C-PHY endpoints Sakari Ailus
@ 2018-08-27  9:29 ` Sakari Ailus
  2018-08-27  9:30 ` [PATCH v2 23/23] smiapp: Query the V4L2 endpoint for a specific bus type Sakari Ailus
  2018-08-29  0:53   ` Steve Longerbeam
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:29 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

The semantics of v4l2_fwnode_endpoint_parse() and
v4l2_fwnode_endpoint_alloc_parse() have changed slightly: they now take
the bus type from the user as well as a default configuration for the bus
that shall reflect the DT binding defaults. Document this.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 include/media/v4l2-fwnode.h | 56 ++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 19 deletions(-)

diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
index 1ea1a3ecf6d5..b4a49ca27579 100644
--- a/include/media/v4l2-fwnode.h
+++ b/include/media/v4l2-fwnode.h
@@ -131,21 +131,30 @@ struct v4l2_fwnode_link {
  * @fwnode: pointer to the endpoint's fwnode handle
  * @vep: pointer to the V4L2 fwnode 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. If any properties that identify the bus as parallel
- * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if
- * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we
- * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
- * reference to @fwnode.
- *
- * The caller must set the bus_type field of @vep to zero.
+ * This function parses the V4L2 fwnode endpoint specific parameters from the
+ * firmware. The caller is responsible for assigning @vep.bus_type to a valid
+ * media bus type. The caller may also set the default configuration for the
+ * endpoint --- a configuration that shall be in line with the DT binding
+ * documentation. Should a device support multiple bus types, the caller may
+ * call this function once the correct type is found --- with a default
+ * configuration valid for that type.
+ *
+ * As a compatibility means guessing the bus type is also supported by setting
+ * @vep.bus_type to V4L2_MBUS_UNKNOWN. The caller may not provide a default
+ * configuration in this case as the defaults are specific to a given bus type.
+ * This functionality is deprecated and should not be used in new drivers and it
+ * is only supported for CSI-2 D-PHY, parallel and Bt.656 busses.
+ *
+ * The function does not change the V4L2 fwnode endpoint state if it fails.
  *
  * NOTE: This function does not parse properties the size of which is variable
  * without a low fixed limit. Please use v4l2_fwnode_endpoint_alloc_parse() in
  * new drivers instead.
  *
- * Return: 0 on success or a negative error code on failure.
+ * Return: %0 on success or a negative error code on failure:
+ *	   %-ENOMEM on memory allocation failure
+ *	   %-EINVAL on parsing failure
+ *	   %-ENXIO on mismatching bus types
  */
 int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 			       struct v4l2_fwnode_endpoint *vep);
@@ -165,15 +174,21 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
  * @fwnode: pointer to the endpoint's fwnode handle
  * @vep: pointer to the V4L2 fwnode 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. If any properties that identify the bus as parallel
- * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if
- * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we
- * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
- * reference to @fwnode.
+ * This function parses the V4L2 fwnode endpoint specific parameters from the
+ * firmware. The caller is responsible for assigning @vep.bus_type to a valid
+ * media bus type. The caller may also set the default configuration for the
+ * endpoint --- a configuration that shall be in line with the DT binding
+ * documentation. Should a device support multiple bus types, the caller may
+ * call this function once the correct type is found --- with a default
+ * configuration valid for that type.
+ *
+ * As a compatibility means guessing the bus type is also supported by setting
+ * @vep.bus_type to V4L2_MBUS_UNKNOWN. The caller may not provide a default
+ * configuration in this case as the defaults are specific to a given bus type.
+ * This functionality is deprecated and should not be used in new drivers and it
+ * is only supported for CSI-2 D-PHY, parallel and Bt.656 busses.
  *
- * The caller must set the bus_type field of @vep to zero.
+ * The function does not change the V4L2 fwnode endpoint state if it fails.
  *
  * v4l2_fwnode_endpoint_alloc_parse() has two important differences to
  * v4l2_fwnode_endpoint_parse():
@@ -183,7 +198,10 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
  * 2. The memory it has allocated to store the variable size data must be freed
  *    using v4l2_fwnode_endpoint_free() when no longer needed.
  *
- * Return: 0 on success or a negative error code on failure.
+ * Return: %0 on success or a negative error code on failure:
+ *	   %-ENOMEM on memory allocation failure
+ *	   %-EINVAL on parsing failure
+ *	   %-ENXIO on mismatching bus types
  */
 int v4l2_fwnode_endpoint_alloc_parse(
 	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2 23/23] smiapp: Query the V4L2 endpoint for a specific bus type
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
                   ` (21 preceding siblings ...)
  2018-08-27  9:29 ` [PATCH v2 22/23] v4l: fwnode: Update V4L2 fwnode endpoint parsing documentation Sakari Ailus
@ 2018-08-27  9:30 ` Sakari Ailus
  2018-08-29  0:53   ` Steve Longerbeam
  23 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-27  9:30 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Instead of opportunistically trying to gather some information from the
V4L2 endpoint, set the bus type and let the V4L2 fwnode framework figure
out the configuration.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/smiapp/smiapp-core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 048ab6cfaa97..0d660349b13c 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2775,7 +2775,13 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	if (!ep)
 		return NULL;
 
+	bus_cfg.bus_type = V4L2_MBUS_CSI2_DPHY;
 	rval = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
+	if (rval == -ENXIO) {
+		bus_cfg = (struct v4l2_fwnode_endpoint)
+			{ .bus_type = V4L2_MBUS_CCP2 };
+		rval = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
+	}
 	if (rval)
 		goto out_err;
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 04/23] dt-bindings: media: Specify bus type for MIPI D-PHY, others, explicitly
  2018-08-27  9:29 ` [PATCH v2 04/23] dt-bindings: media: Specify bus type for MIPI D-PHY, others, explicitly Sakari Ailus
@ 2018-08-29  0:45   ` Rob Herring
  0 siblings, 0 replies; 35+ messages in thread
From: Rob Herring @ 2018-08-29  0:45 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, devicetree, slongerbeam, niklas.soderlund, jacopo

On Mon, 27 Aug 2018 12:29:41 +0300, Sakari Ailus wrote:
> Allow specifying the bus type explicitly for MIPI D-PHY, parallel and
> Bt.656 busses. This is useful for devices that can make use of different
> bus types. There are CSI-2 transmitters and receivers but the PHY
> selection needs to be made between C-PHY and D-PHY; many devices also
> support parallel and Bt.656 interfaces but the means to pass that
> information to software wasn't there.
> 
> Autodetection (value 0) is removed as an option as the property could be
> simply omitted in that case.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  Documentation/devicetree/bindings/media/video-interfaces.txt | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration
  2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
@ 2018-08-29  0:53   ` Steve Longerbeam
  2018-08-27  9:29 ` [PATCH v2 02/23] v4l: fwnode: Use fwnode_graph_for_each_endpoint Sakari Ailus
                     ` (22 subsequent siblings)
  23 siblings, 0 replies; 35+ messages in thread
From: Steve Longerbeam @ 2018-08-29  0:53 UTC (permalink / raw)
  To: Sakari Ailus, linux-media
  Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Hi Sakari,


On 08/27/2018 02:29 AM, Sakari Ailus wrote:
> Hello everyone,
>
> I've long thought the V4L2 fwnode framework requires some work (it's buggy
> and it does not adequately serve common needs). This set should address in
> particular these matters:
>
> - Most devices support a particular media bus type but the V4L2 fwnode
>    framework was not able to use such information, but instead tried to
>    guess the bus type with varying levels of success while drivers
>    generally ignored the results. This patchset makes that possible ---
>    setting a bus type enables parsing configuration for only that bus.
>    Failing that check results in returning -ENXIO to be returned.
>
> - Support specifying default configuration. If the endpoint has no
>    configuration, the defaults set by the driver (as documented in DT
>    bindings) will prevail. Any available configuration will still be read
>    from the endpoint as one could expect. A common use case for this is
>    e.g. the number of CSI-2 lanes. Few devices support lane mapping, and
>    default 1:1 mapping is provided in absence of a valid default or
>    configuration read OF.
>
> - Debugging information is greatly improved.
>
> - Recognition of the differences between CSI-2 D-PHY and C-PHY. All
>    currently supported hardware (or at least drivers) is D-PHY only, so
>    this change is still easy.
>
> The smiapp driver is converted to use the new functionality. This patchset
> does not address remaining issues such as supporting setting defaults for
> e.g. bridge drivers with multiple ports, but with Steve Longerbeam's
> patchset we're much closer to that goal. I've rebased this set on top of
> Steve's. Albeit the two deal with the same files, there were only a few
> trivial conflicts.
>
> Note that I've only tested parsing endpoints for the CSI-2 bus (no
> parallel IF hardware). Jacopo has tested an earlier version of the set
> with a few changes to the parallel bus handling compared to this one.
>
> Comments are welcome.

I got around to testing this. The following diff needs to be added
to initialize bus_type before calling v4l2_fwnode_endpoint_parse()
in imx-media driver, this should probably be squashed with
"v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero":

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index 539159d..ac9d718 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1050,7 +1050,7 @@ static int csi_link_validate(struct v4l2_subdev *sd,
                              struct v4l2_subdev_format *sink_fmt)
  {
         struct csi_priv *priv = v4l2_get_subdevdata(sd);
-       struct v4l2_fwnode_endpoint upstream_ep = {};
+       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
         bool is_csi2;
         int ret;

@@ -1164,7 +1164,7 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,
                               struct v4l2_subdev_mbus_code_enum *code)
  {
         struct csi_priv *priv = v4l2_get_subdevdata(sd);
-       struct v4l2_fwnode_endpoint upstream_ep;
+       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
         const struct imx_media_pixfmt *incc;
         struct v4l2_mbus_framefmt *infmt;
         int ret = 0;
@@ -1403,7 +1403,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
  {
         struct csi_priv *priv = v4l2_get_subdevdata(sd);
         struct imx_media_video_dev *vdev = priv->vdev;
-       struct v4l2_fwnode_endpoint upstream_ep;
+       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
         const struct imx_media_pixfmt *cc;
         struct v4l2_pix_format vdev_fmt;
         struct v4l2_mbus_framefmt *fmt;
@@ -1542,7 +1542,7 @@ static int csi_set_selection(struct v4l2_subdev *sd,
                              struct v4l2_subdev_selection *sel)
  {
         struct csi_priv *priv = v4l2_get_subdevdata(sd);
-       struct v4l2_fwnode_endpoint upstream_ep;
+       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
         struct v4l2_mbus_framefmt *infmt;
         struct v4l2_rect *crop, *compose;
         int pad, ret;


After making that change, capture from CSI-2 OV5640 and parallel
OV5642 on the imx6q Sabrelite is working fine. Feel free to add my
Tested-by on that platform.

>
> I've pushed the patches (including Steve's) here:
>
> <URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=v4l2-fwnode-next>
>
> since v1:
>
> - Rebase it all on current media tree master --- there was a conflict in
>    drivers/media/platform/qcom/camss/camss.c in Steve's patch "media:
>    platform: Switch to v4l2_async_notifier_add_subdev"; I hope the
>    resolution was fine.

I checked your resolution to camss.c and it was the same resolution I
made as well.

Thanks,
Steve

>
> - Default to Bt.656 bus in guessing the bus type if no properties
>    suggesting otherwise are set. In v1 and error was returned, which would
>    have been troublesome for the existing drivers.
>
> - Set the bus_type field to zero (i.e. guess) for existing callers of
>    v4l2_fwnode_endpoint_(alloc_)parse.
>
> - Improved documentation for v4l2_fwnode_endpoint_parse and
>    v4l2_fwnode_endpoint_alloc_parse.
>
> Sakari Ailus (23):
>    v4l: fwnode: Add debug prints for V4L2 endpoint property parsing
>    v4l: fwnode: Use fwnode_graph_for_each_endpoint
>    v4l: fwnode: The CSI-2 clock is continuous if it's not non-continuous
>    dt-bindings: media: Specify bus type for MIPI D-PHY, others,
>      explicitly
>    v4l: fwnode: Add definitions for CSI-2 D-PHY, parallel and Bt.656
>      busses
>    v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY
>    v4l: fwnode: Let the caller provide V4L2 fwnode endpoint
>    v4l: fwnode: Detect bus type correctly
>    v4l: fwnode: Make use of newly specified bus types
>    v4l: fwnode: Read lane inversion information despite lane numbering
>    v4l: fwnode: Only assign configuration if there is no error
>    v4l: fwnode: Support driver-defined lane mapping defaults
>    v4l: fwnode: Support default CSI-2 lane mapping for drivers
>    v4l: fwnode: Parse the graph endpoint as last
>    v4l: fwnode: Use default parallel flags
>    v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero
>    v4l: fwnode: Only zero the struct if bus type is set to
>      V4L2_MBUS_UNKNOWN
>    v4l: fwnode: Use media bus type for bus parser selection
>    v4l: fwnode: Print bus type
>    v4l: fwnode: Use V4L2 fwnode endpoint media bus type if set
>    v4l: fwnode: Support parsing of CSI-2 C-PHY endpoints
>    v4l: fwnode: Update V4L2 fwnode endpoint parsing documentation
>    smiapp: Query the V4L2 endpoint for a specific bus type
>
>   .../devicetree/bindings/media/video-interfaces.txt |   4 +-
>   drivers/gpu/ipu-v3/ipu-csi.c                       |   2 +-
>   drivers/media/i2c/adv7180.c                        |   2 +-
>   drivers/media/i2c/adv7604.c                        |   2 +-
>   drivers/media/i2c/mt9v032.c                        |   2 +-
>   drivers/media/i2c/ov2659.c                         |  14 +-
>   drivers/media/i2c/ov5640.c                         |   4 +-
>   drivers/media/i2c/ov5645.c                         |   2 +-
>   drivers/media/i2c/ov5647.c                         |   2 +-
>   drivers/media/i2c/ov7251.c                         |   4 +-
>   drivers/media/i2c/ov7670.c                         |   2 +-
>   drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   4 +-
>   drivers/media/i2c/s5k5baf.c                        |   6 +-
>   drivers/media/i2c/s5k6aa.c                         |   2 +-
>   drivers/media/i2c/smiapp/smiapp-core.c             |  34 +-
>   drivers/media/i2c/soc_camera/ov5642.c              |   2 +-
>   drivers/media/i2c/tc358743.c                       |  28 +-
>   drivers/media/i2c/tda1997x.c                       |   2 +-
>   drivers/media/i2c/tvp514x.c                        |   2 +-
>   drivers/media/i2c/tvp5150.c                        |   2 +-
>   drivers/media/i2c/tvp7002.c                        |   2 +-
>   drivers/media/pci/intel/ipu3/ipu3-cio2.c           |   2 +-
>   drivers/media/platform/am437x/am437x-vpfe.c        |   2 +-
>   drivers/media/platform/atmel/atmel-isc.c           |   3 +-
>   drivers/media/platform/atmel/atmel-isi.c           |   2 +-
>   drivers/media/platform/cadence/cdns-csi2rx.c       |   4 +-
>   drivers/media/platform/cadence/cdns-csi2tx.c       |   4 +-
>   drivers/media/platform/davinci/vpif_capture.c      |   2 +-
>   drivers/media/platform/exynos4-is/media-dev.c      |   2 +-
>   drivers/media/platform/exynos4-is/mipi-csis.c      |   2 +-
>   drivers/media/platform/marvell-ccic/mcam-core.c    |   4 +-
>   drivers/media/platform/marvell-ccic/mmp-driver.c   |   2 +-
>   drivers/media/platform/omap3isp/isp.c              |   2 +-
>   drivers/media/platform/pxa_camera.c                |   4 +-
>   drivers/media/platform/rcar-vin/rcar-csi2.c        |   4 +-
>   drivers/media/platform/renesas-ceu.c               |   3 +-
>   drivers/media/platform/soc_camera/soc_mediabus.c   |   2 +-
>   drivers/media/platform/stm32/stm32-dcmi.c          |   4 +-
>   drivers/media/platform/ti-vpe/cal.c                |   2 +-
>   drivers/media/v4l2-core/v4l2-fwnode.c              | 508 ++++++++++++++++-----
>   drivers/staging/media/imx/imx-media-csi.c          |   2 +-
>   drivers/staging/media/imx/imx6-mipi-csi2.c         |   2 +-
>   drivers/staging/media/imx074/imx074.c              |   2 +-
>   include/media/v4l2-fwnode.h                        |  60 ++-
>   include/media/v4l2-mediabus.h                      |   8 +-
>   45 files changed, 536 insertions(+), 220 deletions(-)
>

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration
@ 2018-08-29  0:53   ` Steve Longerbeam
  0 siblings, 0 replies; 35+ messages in thread
From: Steve Longerbeam @ 2018-08-29  0:53 UTC (permalink / raw)
  To: Sakari Ailus, linux-media
  Cc: devicetree, slongerbeam, niklas.soderlund, jacopo

Hi Sakari,


On 08/27/2018 02:29 AM, Sakari Ailus wrote:
> Hello everyone,
>
> I've long thought the V4L2 fwnode framework requires some work (it's buggy
> and it does not adequately serve common needs). This set should address in
> particular these matters:
>
> - Most devices support a particular media bus type but the V4L2 fwnode
>    framework was not able to use such information, but instead tried to
>    guess the bus type with varying levels of success while drivers
>    generally ignored the results. This patchset makes that possible ---
>    setting a bus type enables parsing configuration for only that bus.
>    Failing that check results in returning -ENXIO to be returned.
>
> - Support specifying default configuration. If the endpoint has no
>    configuration, the defaults set by the driver (as documented in DT
>    bindings) will prevail. Any available configuration will still be read
>    from the endpoint as one could expect. A common use case for this is
>    e.g. the number of CSI-2 lanes. Few devices support lane mapping, and
>    default 1:1 mapping is provided in absence of a valid default or
>    configuration read OF.
>
> - Debugging information is greatly improved.
>
> - Recognition of the differences between CSI-2 D-PHY and C-PHY. All
>    currently supported hardware (or at least drivers) is D-PHY only, so
>    this change is still easy.
>
> The smiapp driver is converted to use the new functionality. This patchset
> does not address remaining issues such as supporting setting defaults for
> e.g. bridge drivers with multiple ports, but with Steve Longerbeam's
> patchset we're much closer to that goal. I've rebased this set on top of
> Steve's. Albeit the two deal with the same files, there were only a few
> trivial conflicts.
>
> Note that I've only tested parsing endpoints for the CSI-2 bus (no
> parallel IF hardware). Jacopo has tested an earlier version of the set
> with a few changes to the parallel bus handling compared to this one.
>
> Comments are welcome.

I got around to testing this. The following diff needs to be added
to initialize bus_type before calling v4l2_fwnode_endpoint_parse()
in imx-media driver, this should probably be squashed with
"v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero":

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index 539159d..ac9d718 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1050,7 +1050,7 @@ static int csi_link_validate(struct v4l2_subdev *sd,
                              struct v4l2_subdev_format *sink_fmt)
  {
         struct csi_priv *priv = v4l2_get_subdevdata(sd);
-       struct v4l2_fwnode_endpoint upstream_ep = {};
+       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
         bool is_csi2;
         int ret;

@@ -1164,7 +1164,7 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,
                               struct v4l2_subdev_mbus_code_enum *code)
  {
         struct csi_priv *priv = v4l2_get_subdevdata(sd);
-       struct v4l2_fwnode_endpoint upstream_ep;
+       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
         const struct imx_media_pixfmt *incc;
         struct v4l2_mbus_framefmt *infmt;
         int ret = 0;
@@ -1403,7 +1403,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
  {
         struct csi_priv *priv = v4l2_get_subdevdata(sd);
         struct imx_media_video_dev *vdev = priv->vdev;
-       struct v4l2_fwnode_endpoint upstream_ep;
+       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
         const struct imx_media_pixfmt *cc;
         struct v4l2_pix_format vdev_fmt;
         struct v4l2_mbus_framefmt *fmt;
@@ -1542,7 +1542,7 @@ static int csi_set_selection(struct v4l2_subdev *sd,
                              struct v4l2_subdev_selection *sel)
  {
         struct csi_priv *priv = v4l2_get_subdevdata(sd);
-       struct v4l2_fwnode_endpoint upstream_ep;
+       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
         struct v4l2_mbus_framefmt *infmt;
         struct v4l2_rect *crop, *compose;
         int pad, ret;


After making that change, capture from CSI-2 OV5640 and parallel
OV5642 on the imx6q Sabrelite is working fine. Feel free to add my
Tested-by on that platform.

>
> I've pushed the patches (including Steve's) here:
>
> <URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=v4l2-fwnode-next>
>
> since v1:
>
> - Rebase it all on current media tree master --- there was a conflict in
>    drivers/media/platform/qcom/camss/camss.c in Steve's patch "media:
>    platform: Switch to v4l2_async_notifier_add_subdev"; I hope the
>    resolution was fine.

I checked your resolution to camss.c and it was the same resolution I
made as well.

Thanks,
Steve

>
> - Default to Bt.656 bus in guessing the bus type if no properties
>    suggesting otherwise are set. In v1 and error was returned, which would
>    have been troublesome for the existing drivers.
>
> - Set the bus_type field to zero (i.e. guess) for existing callers of
>    v4l2_fwnode_endpoint_(alloc_)parse.
>
> - Improved documentation for v4l2_fwnode_endpoint_parse and
>    v4l2_fwnode_endpoint_alloc_parse.
>
> Sakari Ailus (23):
>    v4l: fwnode: Add debug prints for V4L2 endpoint property parsing
>    v4l: fwnode: Use fwnode_graph_for_each_endpoint
>    v4l: fwnode: The CSI-2 clock is continuous if it's not non-continuous
>    dt-bindings: media: Specify bus type for MIPI D-PHY, others,
>      explicitly
>    v4l: fwnode: Add definitions for CSI-2 D-PHY, parallel and Bt.656
>      busses
>    v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY
>    v4l: fwnode: Let the caller provide V4L2 fwnode endpoint
>    v4l: fwnode: Detect bus type correctly
>    v4l: fwnode: Make use of newly specified bus types
>    v4l: fwnode: Read lane inversion information despite lane numbering
>    v4l: fwnode: Only assign configuration if there is no error
>    v4l: fwnode: Support driver-defined lane mapping defaults
>    v4l: fwnode: Support default CSI-2 lane mapping for drivers
>    v4l: fwnode: Parse the graph endpoint as last
>    v4l: fwnode: Use default parallel flags
>    v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero
>    v4l: fwnode: Only zero the struct if bus type is set to
>      V4L2_MBUS_UNKNOWN
>    v4l: fwnode: Use media bus type for bus parser selection
>    v4l: fwnode: Print bus type
>    v4l: fwnode: Use V4L2 fwnode endpoint media bus type if set
>    v4l: fwnode: Support parsing of CSI-2 C-PHY endpoints
>    v4l: fwnode: Update V4L2 fwnode endpoint parsing documentation
>    smiapp: Query the V4L2 endpoint for a specific bus type
>
>   .../devicetree/bindings/media/video-interfaces.txt |   4 +-
>   drivers/gpu/ipu-v3/ipu-csi.c                       |   2 +-
>   drivers/media/i2c/adv7180.c                        |   2 +-
>   drivers/media/i2c/adv7604.c                        |   2 +-
>   drivers/media/i2c/mt9v032.c                        |   2 +-
>   drivers/media/i2c/ov2659.c                         |  14 +-
>   drivers/media/i2c/ov5640.c                         |   4 +-
>   drivers/media/i2c/ov5645.c                         |   2 +-
>   drivers/media/i2c/ov5647.c                         |   2 +-
>   drivers/media/i2c/ov7251.c                         |   4 +-
>   drivers/media/i2c/ov7670.c                         |   2 +-
>   drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   4 +-
>   drivers/media/i2c/s5k5baf.c                        |   6 +-
>   drivers/media/i2c/s5k6aa.c                         |   2 +-
>   drivers/media/i2c/smiapp/smiapp-core.c             |  34 +-
>   drivers/media/i2c/soc_camera/ov5642.c              |   2 +-
>   drivers/media/i2c/tc358743.c                       |  28 +-
>   drivers/media/i2c/tda1997x.c                       |   2 +-
>   drivers/media/i2c/tvp514x.c                        |   2 +-
>   drivers/media/i2c/tvp5150.c                        |   2 +-
>   drivers/media/i2c/tvp7002.c                        |   2 +-
>   drivers/media/pci/intel/ipu3/ipu3-cio2.c           |   2 +-
>   drivers/media/platform/am437x/am437x-vpfe.c        |   2 +-
>   drivers/media/platform/atmel/atmel-isc.c           |   3 +-
>   drivers/media/platform/atmel/atmel-isi.c           |   2 +-
>   drivers/media/platform/cadence/cdns-csi2rx.c       |   4 +-
>   drivers/media/platform/cadence/cdns-csi2tx.c       |   4 +-
>   drivers/media/platform/davinci/vpif_capture.c      |   2 +-
>   drivers/media/platform/exynos4-is/media-dev.c      |   2 +-
>   drivers/media/platform/exynos4-is/mipi-csis.c      |   2 +-
>   drivers/media/platform/marvell-ccic/mcam-core.c    |   4 +-
>   drivers/media/platform/marvell-ccic/mmp-driver.c   |   2 +-
>   drivers/media/platform/omap3isp/isp.c              |   2 +-
>   drivers/media/platform/pxa_camera.c                |   4 +-
>   drivers/media/platform/rcar-vin/rcar-csi2.c        |   4 +-
>   drivers/media/platform/renesas-ceu.c               |   3 +-
>   drivers/media/platform/soc_camera/soc_mediabus.c   |   2 +-
>   drivers/media/platform/stm32/stm32-dcmi.c          |   4 +-
>   drivers/media/platform/ti-vpe/cal.c                |   2 +-
>   drivers/media/v4l2-core/v4l2-fwnode.c              | 508 ++++++++++++++++-----
>   drivers/staging/media/imx/imx-media-csi.c          |   2 +-
>   drivers/staging/media/imx/imx6-mipi-csi2.c         |   2 +-
>   drivers/staging/media/imx074/imx074.c              |   2 +-
>   include/media/v4l2-fwnode.h                        |  60 ++-
>   include/media/v4l2-mediabus.h                      |   8 +-
>   45 files changed, 536 insertions(+), 220 deletions(-)
>

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration
  2018-08-29  0:53   ` Steve Longerbeam
@ 2018-08-29 12:52     ` Sakari Ailus
  -1 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-29 12:52 UTC (permalink / raw)
  To: Steve Longerbeam
  Cc: linux-media, devicetree, slongerbeam, niklas.soderlund, jacopo

Hi Steve,

On Tue, Aug 28, 2018 at 05:53:51PM -0700, Steve Longerbeam wrote:
> Hi Sakari,
> 
> 
> On 08/27/2018 02:29 AM, Sakari Ailus wrote:
> > Hello everyone,
> > 
> > I've long thought the V4L2 fwnode framework requires some work (it's buggy
> > and it does not adequately serve common needs). This set should address in
> > particular these matters:
> > 
> > - Most devices support a particular media bus type but the V4L2 fwnode
> >    framework was not able to use such information, but instead tried to
> >    guess the bus type with varying levels of success while drivers
> >    generally ignored the results. This patchset makes that possible ---
> >    setting a bus type enables parsing configuration for only that bus.
> >    Failing that check results in returning -ENXIO to be returned.
> > 
> > - Support specifying default configuration. If the endpoint has no
> >    configuration, the defaults set by the driver (as documented in DT
> >    bindings) will prevail. Any available configuration will still be read
> >    from the endpoint as one could expect. A common use case for this is
> >    e.g. the number of CSI-2 lanes. Few devices support lane mapping, and
> >    default 1:1 mapping is provided in absence of a valid default or
> >    configuration read OF.
> > 
> > - Debugging information is greatly improved.
> > 
> > - Recognition of the differences between CSI-2 D-PHY and C-PHY. All
> >    currently supported hardware (or at least drivers) is D-PHY only, so
> >    this change is still easy.
> > 
> > The smiapp driver is converted to use the new functionality. This patchset
> > does not address remaining issues such as supporting setting defaults for
> > e.g. bridge drivers with multiple ports, but with Steve Longerbeam's
> > patchset we're much closer to that goal. I've rebased this set on top of
> > Steve's. Albeit the two deal with the same files, there were only a few
> > trivial conflicts.
> > 
> > Note that I've only tested parsing endpoints for the CSI-2 bus (no
> > parallel IF hardware). Jacopo has tested an earlier version of the set
> > with a few changes to the parallel bus handling compared to this one.
> > 
> > Comments are welcome.
> 
> I got around to testing this. The following diff needs to be added
> to initialize bus_type before calling v4l2_fwnode_endpoint_parse()
> in imx-media driver, this should probably be squashed with
> "v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero":

Thanks for the patch. Apologies for missing the IMX changes; I guess it
happened as it was the only driver that needed the changes in the staging
tree.

I've merged the changes below. Btw. your email client doesn't seem to like
tabs; I replaced the spaces with tabs and the changes were merged fine.

> 
> diff --git a/drivers/staging/media/imx/imx-media-csi.c
> b/drivers/staging/media/imx/imx-media-csi.c
> index 539159d..ac9d718 100644
> --- a/drivers/staging/media/imx/imx-media-csi.c
> +++ b/drivers/staging/media/imx/imx-media-csi.c
> @@ -1050,7 +1050,7 @@ static int csi_link_validate(struct v4l2_subdev *sd,
> ���������������������������� struct v4l2_subdev_format *sink_fmt)
> �{
> ������� struct csi_priv *priv = v4l2_get_subdevdata(sd);
> -������ struct v4l2_fwnode_endpoint upstream_ep = {};
> +������ struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
> ������� bool is_csi2;
> ������� int ret;
> 
> @@ -1164,7 +1164,7 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,
> ����������������������������� struct v4l2_subdev_mbus_code_enum *code)
> �{
> ������� struct csi_priv *priv = v4l2_get_subdevdata(sd);
> -������ struct v4l2_fwnode_endpoint upstream_ep;
> +������ struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
> ������� const struct imx_media_pixfmt *incc;
> ������� struct v4l2_mbus_framefmt *infmt;
> ������� int ret = 0;
> @@ -1403,7 +1403,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
> �{
> ������� struct csi_priv *priv = v4l2_get_subdevdata(sd);
> ������� struct imx_media_video_dev *vdev = priv->vdev;
> -������ struct v4l2_fwnode_endpoint upstream_ep;
> +������ struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
> ������� const struct imx_media_pixfmt *cc;
> ������� struct v4l2_pix_format vdev_fmt;
> ������� struct v4l2_mbus_framefmt *fmt;
> @@ -1542,7 +1542,7 @@ static int csi_set_selection(struct v4l2_subdev *sd,
> ���������������������������� struct v4l2_subdev_selection *sel)
> �{
> ������� struct csi_priv *priv = v4l2_get_subdevdata(sd);
> -������ struct v4l2_fwnode_endpoint upstream_ep;
> +������ struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
> ������� struct v4l2_mbus_framefmt *infmt;
> ������� struct v4l2_rect *crop, *compose;
> ������� int pad, ret;
> 
> 
> After making that change, capture from CSI-2 OV5640 and parallel
> OV5642 on the imx6q Sabrelite is working fine. Feel free to add my
> Tested-by on that platform.

Thanks!

> 
> > 
> > I've pushed the patches (including Steve's) here:
> > 
> > <URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=v4l2-fwnode-next>
> > 
> > since v1:
> > 
> > - Rebase it all on current media tree master --- there was a conflict in
> >    drivers/media/platform/qcom/camss/camss.c in Steve's patch "media:
> >    platform: Switch to v4l2_async_notifier_add_subdev"; I hope the
> >    resolution was fine.
> 
> I checked your resolution to camss.c and it was the same resolution I
> made as well.

Ack.

-- 
Regards,

Sakari Ailus
sakari.ailus@linux.intel.com

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration
@ 2018-08-29 12:52     ` Sakari Ailus
  0 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-29 12:52 UTC (permalink / raw)
  To: Steve Longerbeam
  Cc: linux-media, devicetree, slongerbeam, niklas.soderlund, jacopo

Hi Steve,

On Tue, Aug 28, 2018 at 05:53:51PM -0700, Steve Longerbeam wrote:
> Hi Sakari,
> 
> 
> On 08/27/2018 02:29 AM, Sakari Ailus wrote:
> > Hello everyone,
> > 
> > I've long thought the V4L2 fwnode framework requires some work (it's buggy
> > and it does not adequately serve common needs). This set should address in
> > particular these matters:
> > 
> > - Most devices support a particular media bus type but the V4L2 fwnode
> >    framework was not able to use such information, but instead tried to
> >    guess the bus type with varying levels of success while drivers
> >    generally ignored the results. This patchset makes that possible ---
> >    setting a bus type enables parsing configuration for only that bus.
> >    Failing that check results in returning -ENXIO to be returned.
> > 
> > - Support specifying default configuration. If the endpoint has no
> >    configuration, the defaults set by the driver (as documented in DT
> >    bindings) will prevail. Any available configuration will still be read
> >    from the endpoint as one could expect. A common use case for this is
> >    e.g. the number of CSI-2 lanes. Few devices support lane mapping, and
> >    default 1:1 mapping is provided in absence of a valid default or
> >    configuration read OF.
> > 
> > - Debugging information is greatly improved.
> > 
> > - Recognition of the differences between CSI-2 D-PHY and C-PHY. All
> >    currently supported hardware (or at least drivers) is D-PHY only, so
> >    this change is still easy.
> > 
> > The smiapp driver is converted to use the new functionality. This patchset
> > does not address remaining issues such as supporting setting defaults for
> > e.g. bridge drivers with multiple ports, but with Steve Longerbeam's
> > patchset we're much closer to that goal. I've rebased this set on top of
> > Steve's. Albeit the two deal with the same files, there were only a few
> > trivial conflicts.
> > 
> > Note that I've only tested parsing endpoints for the CSI-2 bus (no
> > parallel IF hardware). Jacopo has tested an earlier version of the set
> > with a few changes to the parallel bus handling compared to this one.
> > 
> > Comments are welcome.
> 
> I got around to testing this. The following diff needs to be added
> to initialize bus_type before calling v4l2_fwnode_endpoint_parse()
> in imx-media driver, this should probably be squashed with
> "v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero":

Thanks for the patch. Apologies for missing the IMX changes; I guess it
happened as it was the only driver that needed the changes in the staging
tree.

I've merged the changes below. Btw. your email client doesn't seem to like
tabs; I replaced the spaces with tabs and the changes were merged fine.

> 
> diff --git a/drivers/staging/media/imx/imx-media-csi.c
> b/drivers/staging/media/imx/imx-media-csi.c
> index 539159d..ac9d718 100644
> --- a/drivers/staging/media/imx/imx-media-csi.c
> +++ b/drivers/staging/media/imx/imx-media-csi.c
> @@ -1050,7 +1050,7 @@ static int csi_link_validate(struct v4l2_subdev *sd,
>                              struct v4l2_subdev_format *sink_fmt)
>  {
>         struct csi_priv *priv = v4l2_get_subdevdata(sd);
> -       struct v4l2_fwnode_endpoint upstream_ep = {};
> +       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
>         bool is_csi2;
>         int ret;
> 
> @@ -1164,7 +1164,7 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,
>                               struct v4l2_subdev_mbus_code_enum *code)
>  {
>         struct csi_priv *priv = v4l2_get_subdevdata(sd);
> -       struct v4l2_fwnode_endpoint upstream_ep;
> +       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
>         const struct imx_media_pixfmt *incc;
>         struct v4l2_mbus_framefmt *infmt;
>         int ret = 0;
> @@ -1403,7 +1403,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
>  {
>         struct csi_priv *priv = v4l2_get_subdevdata(sd);
>         struct imx_media_video_dev *vdev = priv->vdev;
> -       struct v4l2_fwnode_endpoint upstream_ep;
> +       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
>         const struct imx_media_pixfmt *cc;
>         struct v4l2_pix_format vdev_fmt;
>         struct v4l2_mbus_framefmt *fmt;
> @@ -1542,7 +1542,7 @@ static int csi_set_selection(struct v4l2_subdev *sd,
>                              struct v4l2_subdev_selection *sel)
>  {
>         struct csi_priv *priv = v4l2_get_subdevdata(sd);
> -       struct v4l2_fwnode_endpoint upstream_ep;
> +       struct v4l2_fwnode_endpoint upstream_ep = { .bus_type = 0 };
>         struct v4l2_mbus_framefmt *infmt;
>         struct v4l2_rect *crop, *compose;
>         int pad, ret;
> 
> 
> After making that change, capture from CSI-2 OV5640 and parallel
> OV5642 on the imx6q Sabrelite is working fine. Feel free to add my
> Tested-by on that platform.

Thanks!

> 
> > 
> > I've pushed the patches (including Steve's) here:
> > 
> > <URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=v4l2-fwnode-next>
> > 
> > since v1:
> > 
> > - Rebase it all on current media tree master --- there was a conflict in
> >    drivers/media/platform/qcom/camss/camss.c in Steve's patch "media:
> >    platform: Switch to v4l2_async_notifier_add_subdev"; I hope the
> >    resolution was fine.
> 
> I checked your resolution to camss.c and it was the same resolution I
> made as well.

Ack.

-- 
Regards,

Sakari Ailus
sakari.ailus@linux.intel.com

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2.1 06/23] v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY
  2018-08-27  9:29 ` [PATCH v2 06/23] v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY Sakari Ailus
@ 2018-08-31  8:02     ` Sakari Ailus
  0 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-31  8:02 UTC (permalink / raw)
  To: linux-media; +Cc: devicetree, jacopo, dri-devel, slongerbeam, niklas.soderlund

The CSI-2 bus may use either D-PHY or C-PHY. Make this visible in media
bus enum.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Tested-by: Steve Longerbeam <steve_longerbeam@mentor.com>
---
since v2:
- drivers/gpu/ipu-v3/ipu-csi.c got changed, requiring changes here.

 drivers/gpu/ipu-v3/ipu-csi.c                     | 6 +++---
 drivers/media/i2c/adv7180.c                      | 2 +-
 drivers/media/i2c/ov5640.c                       | 4 ++--
 drivers/media/i2c/ov5645.c                       | 2 +-
 drivers/media/i2c/ov7251.c                       | 4 ++--
 drivers/media/i2c/s5c73m3/s5c73m3-core.c         | 2 +-
 drivers/media/i2c/s5k5baf.c                      | 4 ++--
 drivers/media/i2c/s5k6aa.c                       | 2 +-
 drivers/media/i2c/smiapp/smiapp-core.c           | 2 +-
 drivers/media/i2c/soc_camera/ov5642.c            | 2 +-
 drivers/media/i2c/tc358743.c                     | 4 ++--
 drivers/media/pci/intel/ipu3/ipu3-cio2.c         | 2 +-
 drivers/media/platform/cadence/cdns-csi2rx.c     | 2 +-
 drivers/media/platform/cadence/cdns-csi2tx.c     | 2 +-
 drivers/media/platform/marvell-ccic/mcam-core.c  | 4 ++--
 drivers/media/platform/marvell-ccic/mmp-driver.c | 2 +-
 drivers/media/platform/omap3isp/isp.c            | 2 +-
 drivers/media/platform/pxa_camera.c              | 2 +-
 drivers/media/platform/rcar-vin/rcar-csi2.c      | 2 +-
 drivers/media/platform/soc_camera/soc_mediabus.c | 2 +-
 drivers/media/platform/stm32/stm32-dcmi.c        | 2 +-
 drivers/media/platform/ti-vpe/cal.c              | 2 +-
 drivers/media/v4l2-core/v4l2-fwnode.c            | 2 +-
 drivers/staging/media/imx/imx-media-csi.c        | 2 +-
 drivers/staging/media/imx/imx6-mipi-csi2.c       | 2 +-
 drivers/staging/media/imx074/imx074.c            | 2 +-
 include/media/v4l2-mediabus.h                    | 6 ++++--
 27 files changed, 37 insertions(+), 35 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 954eefe144e2..aa0e30a2ba18 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -232,7 +232,7 @@ static int mbus_code_to_bus_cfg(struct ipu_csi_bus_config *cfg, u32 mbus_code,
 	case MEDIA_BUS_FMT_BGR565_2X8_LE:
 	case MEDIA_BUS_FMT_RGB565_2X8_BE:
 	case MEDIA_BUS_FMT_RGB565_2X8_LE:
-		if (mbus_type == V4L2_MBUS_CSI2)
+		if (mbus_type == V4L2_MBUS_CSI2_DPHY)
 			cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_RGB565;
 		else
 			cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_BAYER;
@@ -359,7 +359,7 @@ static int fill_csi_bus_cfg(struct ipu_csi_bus_config *csicfg,
 		else
 			csicfg->clk_mode = IPU_CSI_CLK_MODE_CCIR656_PROGRESSIVE;
 		break;
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		/*
 		 * MIPI CSI-2 requires non gated clock mode, all other
 		 * parameters are not applicable for MIPI CSI-2 bus.
@@ -611,7 +611,7 @@ int ipu_csi_set_mipi_datatype(struct ipu_csi *csi, u32 vc,
 	if (vc > 3)
 		return -EINVAL;
 
-	ret = mbus_code_to_bus_cfg(&cfg, mbus_fmt->code, V4L2_MBUS_CSI2);
+	ret = mbus_code_to_bus_cfg(&cfg, mbus_fmt->code, V4L2_MBUS_CSI2_DPHY);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index de10367d550b..2848a46d149a 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -761,7 +761,7 @@ static int adv7180_g_mbus_config(struct v4l2_subdev *sd,
 	struct adv7180_state *state = to_state(sd);
 
 	if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
-		cfg->type = V4L2_MBUS_CSI2;
+		cfg->type = V4L2_MBUS_CSI2_DPHY;
 		cfg->flags = V4L2_MBUS_CSI2_1_LANE |
 				V4L2_MBUS_CSI2_CHANNEL_0 |
 				V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 071f4bc240ca..942531aaae92 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -1786,7 +1786,7 @@ static int ov5640_set_power(struct ov5640_dev *sensor, bool on)
 		if (ret)
 			goto power_off;
 
-		if (sensor->ep.bus_type == V4L2_MBUS_CSI2) {
+		if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
 			/*
 			 * start streaming briefly followed by stream off in
 			 * order to coax the clock lane into LP-11 state.
@@ -2550,7 +2550,7 @@ static int ov5640_s_stream(struct v4l2_subdev *sd, int enable)
 				goto out;
 		}
 
-		if (sensor->ep.bus_type == V4L2_MBUS_CSI2)
+		if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY)
 			ret = ov5640_set_stream_mipi(sensor, enable);
 		else
 			ret = ov5640_set_stream_dvp(sensor, enable);
diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index 1722cdab0daf..5eba8dd7222b 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -1127,7 +1127,7 @@ static int ov5645_probe(struct i2c_client *client,
 		return ret;
 	}
 
-	if (ov5645->ep.bus_type != V4L2_MBUS_CSI2) {
+	if (ov5645->ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "invalid bus type, must be CSI2\n");
 		return -EINVAL;
 	}
diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
index d3ebb7529fca..0c10203f822b 100644
--- a/drivers/media/i2c/ov7251.c
+++ b/drivers/media/i2c/ov7251.c
@@ -1279,9 +1279,9 @@ static int ov7251_probe(struct i2c_client *client)
 		return ret;
 	}
 
-	if (ov7251->ep.bus_type != V4L2_MBUS_CSI2) {
+	if (ov7251->ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "invalid bus type (%u), must be CSI2 (%u)\n",
-			ov7251->ep.bus_type, V4L2_MBUS_CSI2);
+			ov7251->ep.bus_type, V4L2_MBUS_CSI2_DPHY);
 		return -EINVAL;
 	}
 
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index ce196b60f917..9d5739cafec3 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1644,7 +1644,7 @@ static int s5c73m3_get_platform_data(struct s5c73m3 *state)
 	if (ret)
 		return ret;
 
-	if (ep.bus_type != V4L2_MBUS_CSI2) {
+	if (ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "unsupported bus type\n");
 		return -EINVAL;
 	}
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 5007c9659342..4c41a770b132 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -766,7 +766,7 @@ static int s5k5baf_hw_set_video_bus(struct s5k5baf *state)
 {
 	u16 en_pkts;
 
-	if (state->bus_type == V4L2_MBUS_CSI2)
+	if (state->bus_type == V4L2_MBUS_CSI2_DPHY)
 		en_pkts = EN_PACKETS_CSI2;
 	else
 		en_pkts = 0;
@@ -1875,7 +1875,7 @@ static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev)
 	state->bus_type = ep.bus_type;
 
 	switch (state->bus_type) {
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		state->nlanes = ep.bus.mipi_csi2.num_data_lanes;
 		break;
 	case V4L2_MBUS_PARALLEL:
diff --git a/drivers/media/i2c/s5k6aa.c b/drivers/media/i2c/s5k6aa.c
index 13c10b5e2b45..5f097ae7a5b1 100644
--- a/drivers/media/i2c/s5k6aa.c
+++ b/drivers/media/i2c/s5k6aa.c
@@ -688,7 +688,7 @@ static int s5k6aa_configure_video_bus(struct s5k6aa *s5k6aa,
 	 * but there is nothing indicating how to switch between both
 	 * in the datasheet. For now default BT.601 interface is assumed.
 	 */
-	if (bus_type == V4L2_MBUS_CSI2)
+	if (bus_type == V4L2_MBUS_CSI2_DPHY)
 		cfg = nlanes;
 	else if (bus_type != V4L2_MBUS_PARALLEL)
 		return -EINVAL;
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 1236683da8f7..9e33c2008ba6 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2784,7 +2784,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 		goto out_err;
 
 	switch (bus_cfg->bus_type) {
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		hwcfg->csi_signalling_mode = SMIAPP_CSI_SIGNALLING_MODE_CSI2;
 		hwcfg->lanes = bus_cfg->bus.mipi_csi2.num_data_lanes;
 		break;
diff --git a/drivers/media/i2c/soc_camera/ov5642.c b/drivers/media/i2c/soc_camera/ov5642.c
index 39f420db9c70..bc045259510d 100644
--- a/drivers/media/i2c/soc_camera/ov5642.c
+++ b/drivers/media/i2c/soc_camera/ov5642.c
@@ -913,7 +913,7 @@ static int ov5642_get_selection(struct v4l2_subdev *sd,
 static int ov5642_g_mbus_config(struct v4l2_subdev *sd,
 				struct v4l2_mbus_config *cfg)
 {
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 	cfg->flags = V4L2_MBUS_CSI2_2_LANE | V4L2_MBUS_CSI2_CHANNEL_0 |
 					V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
 
diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
index 44c41933415a..6a2064597124 100644
--- a/drivers/media/i2c/tc358743.c
+++ b/drivers/media/i2c/tc358743.c
@@ -1607,7 +1607,7 @@ static int tc358743_g_mbus_config(struct v4l2_subdev *sd,
 {
 	struct tc358743_state *state = to_state(sd);
 
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 
 	/* Support for non-continuous CSI-2 clock is missing in the driver */
 	cfg->flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
@@ -1922,7 +1922,7 @@ static int tc358743_probe_of(struct tc358743_state *state)
 		goto put_node;
 	}
 
-	if (endpoint->bus_type != V4L2_MBUS_CSI2 ||
+	if (endpoint->bus_type != V4L2_MBUS_CSI2_DPHY ||
 	    endpoint->bus.mipi_csi2.num_data_lanes == 0 ||
 	    endpoint->nr_of_link_frequencies == 0) {
 		dev_err(dev, "missing CSI-2 properties in endpoint\n");
diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
index ca3ad118d10b..cf77bc6da4a4 100644
--- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
+++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
@@ -1484,7 +1484,7 @@ static int cio2_fwnode_parse(struct device *dev,
 	struct sensor_async_subdev *s_asd =
 			container_of(asd, struct sensor_async_subdev, asd);
 
-	if (vep->bus_type != V4L2_MBUS_CSI2) {
+	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "Only CSI2 bus type is currently supported\n");
 		return -EINVAL;
 	}
diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
index da3eb349716f..0776a34f28ee 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -378,7 +378,7 @@ static int csi2rx_parse_dt(struct csi2rx_priv *csi2rx)
 		return ret;
 	}
 
-	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2) {
+	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(csi2rx->dev, "Unsupported media bus type: 0x%x\n",
 			v4l2_ep.bus_type);
 		of_node_put(ep);
diff --git a/drivers/media/platform/cadence/cdns-csi2tx.c b/drivers/media/platform/cadence/cdns-csi2tx.c
index 40d0de690ff4..6224daf891d7 100644
--- a/drivers/media/platform/cadence/cdns-csi2tx.c
+++ b/drivers/media/platform/cadence/cdns-csi2tx.c
@@ -446,7 +446,7 @@ static int csi2tx_check_lanes(struct csi2tx_priv *csi2tx)
 		goto out;
 	}
 
-	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2) {
+	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(csi2tx->dev, "Unsupported media bus type: 0x%x\n",
 			v4l2_ep.bus_type);
 		ret = -EINVAL;
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index dfdbd4354b74..5e20427aeca2 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -794,7 +794,7 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
 	/*
 	 * This field controls the generation of EOF(DVP only)
 	 */
-	if (cam->bus_type != V4L2_MBUS_CSI2)
+	if (cam->bus_type != V4L2_MBUS_CSI2_DPHY)
 		mcam_reg_set_bit(cam, REG_CTRL0,
 				C0_EOF_VSYNC | C0_VEDGE_CTRL);
 }
@@ -1023,7 +1023,7 @@ static int mcam_read_setup(struct mcam_camera *cam)
 		cam->calc_dphy(cam);
 	cam_dbg(cam, "camera: DPHY sets: dphy3=0x%x, dphy5=0x%x, dphy6=0x%x\n",
 			cam->dphy[0], cam->dphy[1], cam->dphy[2]);
-	if (cam->bus_type == V4L2_MBUS_CSI2)
+	if (cam->bus_type == V4L2_MBUS_CSI2_DPHY)
 		mcam_enable_mipi(cam);
 	else
 		mcam_disable_mipi(cam);
diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c
index 6d9f0abb2660..25ce31b71a45 100644
--- a/drivers/media/platform/marvell-ccic/mmp-driver.c
+++ b/drivers/media/platform/marvell-ccic/mmp-driver.c
@@ -362,7 +362,7 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam->mclk_div = pdata->mclk_div;
 	mcam->bus_type = pdata->bus_type;
 	mcam->dphy = pdata->dphy;
-	if (mcam->bus_type == V4L2_MBUS_CSI2) {
+	if (mcam->bus_type == V4L2_MBUS_CSI2_DPHY) {
 		cam->mipi_clk = devm_clk_get(mcam->dev, "mipi");
 		if ((IS_ERR(cam->mipi_clk) && mcam->dphy[2] == 0))
 			return PTR_ERR(cam->mipi_clk);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index a56f020794e6..ace3bf4ba2a1 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -2054,7 +2054,7 @@ static int isp_fwnode_parse(struct device *dev,
 			dev_dbg(dev, "CSI-1/CCP-2 configuration\n");
 			csi1 = true;
 			break;
-		case V4L2_MBUS_CSI2:
+		case V4L2_MBUS_CSI2_DPHY:
 			dev_dbg(dev, "CSI-2 configuration\n");
 			csi1 = false;
 			break;
diff --git a/drivers/media/platform/pxa_camera.c b/drivers/media/platform/pxa_camera.c
index 1401f54ded01..2522f7079dda 100644
--- a/drivers/media/platform/pxa_camera.c
+++ b/drivers/media/platform/pxa_camera.c
@@ -633,7 +633,7 @@ static unsigned int pxa_mbus_config_compatible(const struct v4l2_mbus_config *cf
 		mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
 		return (!hsync || !vsync || !pclk || !data || !mode) ?
 			0 : common_flags;
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
 		mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
 					     V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index 75ebd9c23813..25edc2edd197 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -714,7 +714,7 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
 	if (vep->base.port || vep->base.id)
 		return -ENOTCONN;
 
-	if (vep->bus_type != V4L2_MBUS_CSI2) {
+	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(priv->dev, "Unsupported bus: %u\n", vep->bus_type);
 		return -EINVAL;
 	}
diff --git a/drivers/media/platform/soc_camera/soc_mediabus.c b/drivers/media/platform/soc_camera/soc_mediabus.c
index 0ad4b28266e4..be74008ec0ca 100644
--- a/drivers/media/platform/soc_camera/soc_mediabus.c
+++ b/drivers/media/platform/soc_camera/soc_mediabus.c
@@ -503,7 +503,7 @@ unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
 		mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
 		return (!hsync || !vsync || !pclk || !data || !mode) ?
 			0 : common_flags;
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
 		mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
 					     V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
index b4110e6458d9..38b52a059985 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -1660,7 +1660,7 @@ static int dcmi_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	if (ep.bus_type == V4L2_MBUS_CSI2) {
+	if (ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
 		dev_err(&pdev->dev, "CSI bus not supported\n");
 		return -ENODEV;
 	}
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 6872cb263270..2134103c19f8 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -1710,7 +1710,7 @@ static int of_cal_create_instance(struct cal_ctx *ctx, int inst)
 	}
 	v4l2_fwnode_endpoint_parse(of_fwnode_handle(remote_ep), endpoint);
 
-	if (endpoint->bus_type != V4L2_MBUS_CSI2) {
+	if (endpoint->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		ctx_err(ctx, "Port:%d sub-device %s is not a CSI2 device\n",
 			inst, sensor_node->name);
 		goto err_put_remote_ep;
diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 104ef7f1754d..54162217bb36 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -115,7 +115,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 	}
 
 	bus->flags = flags;
-	vep->bus_type = V4L2_MBUS_CSI2;
+	vep->bus_type = V4L2_MBUS_CSI2_DPHY;
 
 	return 0;
 }
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index 8e749fdec8d1..539159d9af6b 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -124,7 +124,7 @@ static inline struct csi_priv *sd_to_dev(struct v4l2_subdev *sdev)
 
 static inline bool is_parallel_bus(struct v4l2_fwnode_endpoint *ep)
 {
-	return ep->bus_type != V4L2_MBUS_CSI2;
+	return ep->bus_type != V4L2_MBUS_CSI2_DPHY;
 }
 
 static inline bool is_parallel_16bit_bus(struct v4l2_fwnode_endpoint *ep)
diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
index 94eb9a1f38bb..74438a4c1267 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -563,7 +563,7 @@ static int csi2_parse_endpoint(struct device *dev,
 		return -EINVAL;
 	}
 
-	if (vep->bus_type != V4L2_MBUS_CSI2) {
+	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		v4l2_err(&csi2->sd, "invalid bus type, must be MIPI CSI2\n");
 		return -EINVAL;
 	}
diff --git a/drivers/staging/media/imx074/imx074.c b/drivers/staging/media/imx074/imx074.c
index 77f1e0243d6e..0eee9f0def4d 100644
--- a/drivers/staging/media/imx074/imx074.c
+++ b/drivers/staging/media/imx074/imx074.c
@@ -263,7 +263,7 @@ static int imx074_s_power(struct v4l2_subdev *sd, int on)
 static int imx074_g_mbus_config(struct v4l2_subdev *sd,
 				struct v4l2_mbus_config *cfg)
 {
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 	cfg->flags = V4L2_MBUS_CSI2_2_LANE |
 		V4L2_MBUS_CSI2_CHANNEL_0 |
 		V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
diff --git a/include/media/v4l2-mediabus.h b/include/media/v4l2-mediabus.h
index 4bbb5f3d2b02..26e1c644ded6 100644
--- a/include/media/v4l2-mediabus.h
+++ b/include/media/v4l2-mediabus.h
@@ -75,14 +75,16 @@
  *			also be used for BT.1120
  * @V4L2_MBUS_CSI1:	MIPI CSI-1 serial interface
  * @V4L2_MBUS_CCP2:	CCP2 (Compact Camera Port 2)
- * @V4L2_MBUS_CSI2:	MIPI CSI-2 serial interface
+ * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
+ * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
  */
 enum v4l2_mbus_type {
 	V4L2_MBUS_PARALLEL,
 	V4L2_MBUS_BT656,
 	V4L2_MBUS_CSI1,
 	V4L2_MBUS_CCP2,
-	V4L2_MBUS_CSI2,
+	V4L2_MBUS_CSI2_DPHY,
+	V4L2_MBUS_CSI2_CPHY,
 };
 
 /**
-- 
2.11.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v2.1 06/23] v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY
@ 2018-08-31  8:02     ` Sakari Ailus
  0 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-08-31  8:02 UTC (permalink / raw)
  To: linux-media
  Cc: devicetree, slongerbeam, niklas.soderlund, jacopo, p.zabel, dri-devel

The CSI-2 bus may use either D-PHY or C-PHY. Make this visible in media
bus enum.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Tested-by: Steve Longerbeam <steve_longerbeam@mentor.com>
---
since v2:
- drivers/gpu/ipu-v3/ipu-csi.c got changed, requiring changes here.

 drivers/gpu/ipu-v3/ipu-csi.c                     | 6 +++---
 drivers/media/i2c/adv7180.c                      | 2 +-
 drivers/media/i2c/ov5640.c                       | 4 ++--
 drivers/media/i2c/ov5645.c                       | 2 +-
 drivers/media/i2c/ov7251.c                       | 4 ++--
 drivers/media/i2c/s5c73m3/s5c73m3-core.c         | 2 +-
 drivers/media/i2c/s5k5baf.c                      | 4 ++--
 drivers/media/i2c/s5k6aa.c                       | 2 +-
 drivers/media/i2c/smiapp/smiapp-core.c           | 2 +-
 drivers/media/i2c/soc_camera/ov5642.c            | 2 +-
 drivers/media/i2c/tc358743.c                     | 4 ++--
 drivers/media/pci/intel/ipu3/ipu3-cio2.c         | 2 +-
 drivers/media/platform/cadence/cdns-csi2rx.c     | 2 +-
 drivers/media/platform/cadence/cdns-csi2tx.c     | 2 +-
 drivers/media/platform/marvell-ccic/mcam-core.c  | 4 ++--
 drivers/media/platform/marvell-ccic/mmp-driver.c | 2 +-
 drivers/media/platform/omap3isp/isp.c            | 2 +-
 drivers/media/platform/pxa_camera.c              | 2 +-
 drivers/media/platform/rcar-vin/rcar-csi2.c      | 2 +-
 drivers/media/platform/soc_camera/soc_mediabus.c | 2 +-
 drivers/media/platform/stm32/stm32-dcmi.c        | 2 +-
 drivers/media/platform/ti-vpe/cal.c              | 2 +-
 drivers/media/v4l2-core/v4l2-fwnode.c            | 2 +-
 drivers/staging/media/imx/imx-media-csi.c        | 2 +-
 drivers/staging/media/imx/imx6-mipi-csi2.c       | 2 +-
 drivers/staging/media/imx074/imx074.c            | 2 +-
 include/media/v4l2-mediabus.h                    | 6 ++++--
 27 files changed, 37 insertions(+), 35 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 954eefe144e2..aa0e30a2ba18 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -232,7 +232,7 @@ static int mbus_code_to_bus_cfg(struct ipu_csi_bus_config *cfg, u32 mbus_code,
 	case MEDIA_BUS_FMT_BGR565_2X8_LE:
 	case MEDIA_BUS_FMT_RGB565_2X8_BE:
 	case MEDIA_BUS_FMT_RGB565_2X8_LE:
-		if (mbus_type == V4L2_MBUS_CSI2)
+		if (mbus_type == V4L2_MBUS_CSI2_DPHY)
 			cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_RGB565;
 		else
 			cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_BAYER;
@@ -359,7 +359,7 @@ static int fill_csi_bus_cfg(struct ipu_csi_bus_config *csicfg,
 		else
 			csicfg->clk_mode = IPU_CSI_CLK_MODE_CCIR656_PROGRESSIVE;
 		break;
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		/*
 		 * MIPI CSI-2 requires non gated clock mode, all other
 		 * parameters are not applicable for MIPI CSI-2 bus.
@@ -611,7 +611,7 @@ int ipu_csi_set_mipi_datatype(struct ipu_csi *csi, u32 vc,
 	if (vc > 3)
 		return -EINVAL;
 
-	ret = mbus_code_to_bus_cfg(&cfg, mbus_fmt->code, V4L2_MBUS_CSI2);
+	ret = mbus_code_to_bus_cfg(&cfg, mbus_fmt->code, V4L2_MBUS_CSI2_DPHY);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index de10367d550b..2848a46d149a 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -761,7 +761,7 @@ static int adv7180_g_mbus_config(struct v4l2_subdev *sd,
 	struct adv7180_state *state = to_state(sd);
 
 	if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
-		cfg->type = V4L2_MBUS_CSI2;
+		cfg->type = V4L2_MBUS_CSI2_DPHY;
 		cfg->flags = V4L2_MBUS_CSI2_1_LANE |
 				V4L2_MBUS_CSI2_CHANNEL_0 |
 				V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 071f4bc240ca..942531aaae92 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -1786,7 +1786,7 @@ static int ov5640_set_power(struct ov5640_dev *sensor, bool on)
 		if (ret)
 			goto power_off;
 
-		if (sensor->ep.bus_type == V4L2_MBUS_CSI2) {
+		if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
 			/*
 			 * start streaming briefly followed by stream off in
 			 * order to coax the clock lane into LP-11 state.
@@ -2550,7 +2550,7 @@ static int ov5640_s_stream(struct v4l2_subdev *sd, int enable)
 				goto out;
 		}
 
-		if (sensor->ep.bus_type == V4L2_MBUS_CSI2)
+		if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY)
 			ret = ov5640_set_stream_mipi(sensor, enable);
 		else
 			ret = ov5640_set_stream_dvp(sensor, enable);
diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index 1722cdab0daf..5eba8dd7222b 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -1127,7 +1127,7 @@ static int ov5645_probe(struct i2c_client *client,
 		return ret;
 	}
 
-	if (ov5645->ep.bus_type != V4L2_MBUS_CSI2) {
+	if (ov5645->ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "invalid bus type, must be CSI2\n");
 		return -EINVAL;
 	}
diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
index d3ebb7529fca..0c10203f822b 100644
--- a/drivers/media/i2c/ov7251.c
+++ b/drivers/media/i2c/ov7251.c
@@ -1279,9 +1279,9 @@ static int ov7251_probe(struct i2c_client *client)
 		return ret;
 	}
 
-	if (ov7251->ep.bus_type != V4L2_MBUS_CSI2) {
+	if (ov7251->ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "invalid bus type (%u), must be CSI2 (%u)\n",
-			ov7251->ep.bus_type, V4L2_MBUS_CSI2);
+			ov7251->ep.bus_type, V4L2_MBUS_CSI2_DPHY);
 		return -EINVAL;
 	}
 
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index ce196b60f917..9d5739cafec3 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1644,7 +1644,7 @@ static int s5c73m3_get_platform_data(struct s5c73m3 *state)
 	if (ret)
 		return ret;
 
-	if (ep.bus_type != V4L2_MBUS_CSI2) {
+	if (ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "unsupported bus type\n");
 		return -EINVAL;
 	}
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 5007c9659342..4c41a770b132 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -766,7 +766,7 @@ static int s5k5baf_hw_set_video_bus(struct s5k5baf *state)
 {
 	u16 en_pkts;
 
-	if (state->bus_type == V4L2_MBUS_CSI2)
+	if (state->bus_type == V4L2_MBUS_CSI2_DPHY)
 		en_pkts = EN_PACKETS_CSI2;
 	else
 		en_pkts = 0;
@@ -1875,7 +1875,7 @@ static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev)
 	state->bus_type = ep.bus_type;
 
 	switch (state->bus_type) {
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		state->nlanes = ep.bus.mipi_csi2.num_data_lanes;
 		break;
 	case V4L2_MBUS_PARALLEL:
diff --git a/drivers/media/i2c/s5k6aa.c b/drivers/media/i2c/s5k6aa.c
index 13c10b5e2b45..5f097ae7a5b1 100644
--- a/drivers/media/i2c/s5k6aa.c
+++ b/drivers/media/i2c/s5k6aa.c
@@ -688,7 +688,7 @@ static int s5k6aa_configure_video_bus(struct s5k6aa *s5k6aa,
 	 * but there is nothing indicating how to switch between both
 	 * in the datasheet. For now default BT.601 interface is assumed.
 	 */
-	if (bus_type == V4L2_MBUS_CSI2)
+	if (bus_type == V4L2_MBUS_CSI2_DPHY)
 		cfg = nlanes;
 	else if (bus_type != V4L2_MBUS_PARALLEL)
 		return -EINVAL;
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 1236683da8f7..9e33c2008ba6 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2784,7 +2784,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 		goto out_err;
 
 	switch (bus_cfg->bus_type) {
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		hwcfg->csi_signalling_mode = SMIAPP_CSI_SIGNALLING_MODE_CSI2;
 		hwcfg->lanes = bus_cfg->bus.mipi_csi2.num_data_lanes;
 		break;
diff --git a/drivers/media/i2c/soc_camera/ov5642.c b/drivers/media/i2c/soc_camera/ov5642.c
index 39f420db9c70..bc045259510d 100644
--- a/drivers/media/i2c/soc_camera/ov5642.c
+++ b/drivers/media/i2c/soc_camera/ov5642.c
@@ -913,7 +913,7 @@ static int ov5642_get_selection(struct v4l2_subdev *sd,
 static int ov5642_g_mbus_config(struct v4l2_subdev *sd,
 				struct v4l2_mbus_config *cfg)
 {
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 	cfg->flags = V4L2_MBUS_CSI2_2_LANE | V4L2_MBUS_CSI2_CHANNEL_0 |
 					V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
 
diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
index 44c41933415a..6a2064597124 100644
--- a/drivers/media/i2c/tc358743.c
+++ b/drivers/media/i2c/tc358743.c
@@ -1607,7 +1607,7 @@ static int tc358743_g_mbus_config(struct v4l2_subdev *sd,
 {
 	struct tc358743_state *state = to_state(sd);
 
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 
 	/* Support for non-continuous CSI-2 clock is missing in the driver */
 	cfg->flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
@@ -1922,7 +1922,7 @@ static int tc358743_probe_of(struct tc358743_state *state)
 		goto put_node;
 	}
 
-	if (endpoint->bus_type != V4L2_MBUS_CSI2 ||
+	if (endpoint->bus_type != V4L2_MBUS_CSI2_DPHY ||
 	    endpoint->bus.mipi_csi2.num_data_lanes == 0 ||
 	    endpoint->nr_of_link_frequencies == 0) {
 		dev_err(dev, "missing CSI-2 properties in endpoint\n");
diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
index ca3ad118d10b..cf77bc6da4a4 100644
--- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
+++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
@@ -1484,7 +1484,7 @@ static int cio2_fwnode_parse(struct device *dev,
 	struct sensor_async_subdev *s_asd =
 			container_of(asd, struct sensor_async_subdev, asd);
 
-	if (vep->bus_type != V4L2_MBUS_CSI2) {
+	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(dev, "Only CSI2 bus type is currently supported\n");
 		return -EINVAL;
 	}
diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
index da3eb349716f..0776a34f28ee 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -378,7 +378,7 @@ static int csi2rx_parse_dt(struct csi2rx_priv *csi2rx)
 		return ret;
 	}
 
-	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2) {
+	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(csi2rx->dev, "Unsupported media bus type: 0x%x\n",
 			v4l2_ep.bus_type);
 		of_node_put(ep);
diff --git a/drivers/media/platform/cadence/cdns-csi2tx.c b/drivers/media/platform/cadence/cdns-csi2tx.c
index 40d0de690ff4..6224daf891d7 100644
--- a/drivers/media/platform/cadence/cdns-csi2tx.c
+++ b/drivers/media/platform/cadence/cdns-csi2tx.c
@@ -446,7 +446,7 @@ static int csi2tx_check_lanes(struct csi2tx_priv *csi2tx)
 		goto out;
 	}
 
-	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2) {
+	if (v4l2_ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(csi2tx->dev, "Unsupported media bus type: 0x%x\n",
 			v4l2_ep.bus_type);
 		ret = -EINVAL;
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index dfdbd4354b74..5e20427aeca2 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -794,7 +794,7 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
 	/*
 	 * This field controls the generation of EOF(DVP only)
 	 */
-	if (cam->bus_type != V4L2_MBUS_CSI2)
+	if (cam->bus_type != V4L2_MBUS_CSI2_DPHY)
 		mcam_reg_set_bit(cam, REG_CTRL0,
 				C0_EOF_VSYNC | C0_VEDGE_CTRL);
 }
@@ -1023,7 +1023,7 @@ static int mcam_read_setup(struct mcam_camera *cam)
 		cam->calc_dphy(cam);
 	cam_dbg(cam, "camera: DPHY sets: dphy3=0x%x, dphy5=0x%x, dphy6=0x%x\n",
 			cam->dphy[0], cam->dphy[1], cam->dphy[2]);
-	if (cam->bus_type == V4L2_MBUS_CSI2)
+	if (cam->bus_type == V4L2_MBUS_CSI2_DPHY)
 		mcam_enable_mipi(cam);
 	else
 		mcam_disable_mipi(cam);
diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c
index 6d9f0abb2660..25ce31b71a45 100644
--- a/drivers/media/platform/marvell-ccic/mmp-driver.c
+++ b/drivers/media/platform/marvell-ccic/mmp-driver.c
@@ -362,7 +362,7 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam->mclk_div = pdata->mclk_div;
 	mcam->bus_type = pdata->bus_type;
 	mcam->dphy = pdata->dphy;
-	if (mcam->bus_type == V4L2_MBUS_CSI2) {
+	if (mcam->bus_type == V4L2_MBUS_CSI2_DPHY) {
 		cam->mipi_clk = devm_clk_get(mcam->dev, "mipi");
 		if ((IS_ERR(cam->mipi_clk) && mcam->dphy[2] == 0))
 			return PTR_ERR(cam->mipi_clk);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index a56f020794e6..ace3bf4ba2a1 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -2054,7 +2054,7 @@ static int isp_fwnode_parse(struct device *dev,
 			dev_dbg(dev, "CSI-1/CCP-2 configuration\n");
 			csi1 = true;
 			break;
-		case V4L2_MBUS_CSI2:
+		case V4L2_MBUS_CSI2_DPHY:
 			dev_dbg(dev, "CSI-2 configuration\n");
 			csi1 = false;
 			break;
diff --git a/drivers/media/platform/pxa_camera.c b/drivers/media/platform/pxa_camera.c
index 1401f54ded01..2522f7079dda 100644
--- a/drivers/media/platform/pxa_camera.c
+++ b/drivers/media/platform/pxa_camera.c
@@ -633,7 +633,7 @@ static unsigned int pxa_mbus_config_compatible(const struct v4l2_mbus_config *cf
 		mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
 		return (!hsync || !vsync || !pclk || !data || !mode) ?
 			0 : common_flags;
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
 		mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
 					     V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index 75ebd9c23813..25edc2edd197 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -714,7 +714,7 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
 	if (vep->base.port || vep->base.id)
 		return -ENOTCONN;
 
-	if (vep->bus_type != V4L2_MBUS_CSI2) {
+	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		dev_err(priv->dev, "Unsupported bus: %u\n", vep->bus_type);
 		return -EINVAL;
 	}
diff --git a/drivers/media/platform/soc_camera/soc_mediabus.c b/drivers/media/platform/soc_camera/soc_mediabus.c
index 0ad4b28266e4..be74008ec0ca 100644
--- a/drivers/media/platform/soc_camera/soc_mediabus.c
+++ b/drivers/media/platform/soc_camera/soc_mediabus.c
@@ -503,7 +503,7 @@ unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
 		mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
 		return (!hsync || !vsync || !pclk || !data || !mode) ?
 			0 : common_flags;
-	case V4L2_MBUS_CSI2:
+	case V4L2_MBUS_CSI2_DPHY:
 		mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
 		mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
 					     V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
index b4110e6458d9..38b52a059985 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -1660,7 +1660,7 @@ static int dcmi_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	if (ep.bus_type == V4L2_MBUS_CSI2) {
+	if (ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
 		dev_err(&pdev->dev, "CSI bus not supported\n");
 		return -ENODEV;
 	}
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 6872cb263270..2134103c19f8 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -1710,7 +1710,7 @@ static int of_cal_create_instance(struct cal_ctx *ctx, int inst)
 	}
 	v4l2_fwnode_endpoint_parse(of_fwnode_handle(remote_ep), endpoint);
 
-	if (endpoint->bus_type != V4L2_MBUS_CSI2) {
+	if (endpoint->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		ctx_err(ctx, "Port:%d sub-device %s is not a CSI2 device\n",
 			inst, sensor_node->name);
 		goto err_put_remote_ep;
diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 104ef7f1754d..54162217bb36 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -115,7 +115,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 	}
 
 	bus->flags = flags;
-	vep->bus_type = V4L2_MBUS_CSI2;
+	vep->bus_type = V4L2_MBUS_CSI2_DPHY;
 
 	return 0;
 }
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index 8e749fdec8d1..539159d9af6b 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -124,7 +124,7 @@ static inline struct csi_priv *sd_to_dev(struct v4l2_subdev *sdev)
 
 static inline bool is_parallel_bus(struct v4l2_fwnode_endpoint *ep)
 {
-	return ep->bus_type != V4L2_MBUS_CSI2;
+	return ep->bus_type != V4L2_MBUS_CSI2_DPHY;
 }
 
 static inline bool is_parallel_16bit_bus(struct v4l2_fwnode_endpoint *ep)
diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
index 94eb9a1f38bb..74438a4c1267 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -563,7 +563,7 @@ static int csi2_parse_endpoint(struct device *dev,
 		return -EINVAL;
 	}
 
-	if (vep->bus_type != V4L2_MBUS_CSI2) {
+	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
 		v4l2_err(&csi2->sd, "invalid bus type, must be MIPI CSI2\n");
 		return -EINVAL;
 	}
diff --git a/drivers/staging/media/imx074/imx074.c b/drivers/staging/media/imx074/imx074.c
index 77f1e0243d6e..0eee9f0def4d 100644
--- a/drivers/staging/media/imx074/imx074.c
+++ b/drivers/staging/media/imx074/imx074.c
@@ -263,7 +263,7 @@ static int imx074_s_power(struct v4l2_subdev *sd, int on)
 static int imx074_g_mbus_config(struct v4l2_subdev *sd,
 				struct v4l2_mbus_config *cfg)
 {
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 	cfg->flags = V4L2_MBUS_CSI2_2_LANE |
 		V4L2_MBUS_CSI2_CHANNEL_0 |
 		V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
diff --git a/include/media/v4l2-mediabus.h b/include/media/v4l2-mediabus.h
index 4bbb5f3d2b02..26e1c644ded6 100644
--- a/include/media/v4l2-mediabus.h
+++ b/include/media/v4l2-mediabus.h
@@ -75,14 +75,16 @@
  *			also be used for BT.1120
  * @V4L2_MBUS_CSI1:	MIPI CSI-1 serial interface
  * @V4L2_MBUS_CCP2:	CCP2 (Compact Camera Port 2)
- * @V4L2_MBUS_CSI2:	MIPI CSI-2 serial interface
+ * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
+ * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
  */
 enum v4l2_mbus_type {
 	V4L2_MBUS_PARALLEL,
 	V4L2_MBUS_BT656,
 	V4L2_MBUS_CSI1,
 	V4L2_MBUS_CCP2,
-	V4L2_MBUS_CSI2,
+	V4L2_MBUS_CSI2_DPHY,
+	V4L2_MBUS_CSI2_CPHY,
 };
 
 /**
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 07/23] v4l: fwnode: Let the caller provide V4L2 fwnode endpoint
  2018-08-27  9:29 ` [PATCH v2 07/23] v4l: fwnode: Let the caller provide V4L2 fwnode endpoint Sakari Ailus
@ 2018-09-12 14:51   ` jacopo mondi
  2018-09-12 20:46     ` Sakari Ailus
  0 siblings, 1 reply; 35+ messages in thread
From: jacopo mondi @ 2018-09-12 14:51 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-media, devicetree, slongerbeam, niklas.soderlund

[-- Attachment #1: Type: text/plain, Size: 6155 bytes --]

Hi Sakari,

On Mon, Aug 27, 2018 at 12:29:44PM +0300, Sakari Ailus wrote:
> Instead of allocating the V4L2 fwnode endpoint in
> v4l2_fwnode_endpoint_alloc_parse, let the caller to do this. This allows
> setting default parameters for the endpoint which is a very common need
> for drivers.
>
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  drivers/media/i2c/ov2659.c             | 14 +++++-----
>  drivers/media/i2c/smiapp/smiapp-core.c | 26 +++++++++---------
>  drivers/media/i2c/tc358743.c           | 26 +++++++++---------
>  drivers/media/v4l2-core/v4l2-fwnode.c  | 49 +++++++++++++---------------------
>  include/media/v4l2-fwnode.h            | 10 ++++---
>  5 files changed, 60 insertions(+), 65 deletions(-)
>

[snip]

> -struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
> -	struct fwnode_handle *fwnode)
> +int v4l2_fwnode_endpoint_alloc_parse(
> +	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep)

Looking at the resulting implementation of
"v4l2_fwnode_endpoint_alloc_parse" and "v4l2_fwnode_endpoint_parse" I
wonder if there's still value in keeping them separate... Now that in
both cases the caller has to provide an v4l2_fwnode_endpoint, isn't it
worth making a single function out of them, that behaves like
"alloc_parse" is doing nowadays (allocates vep->link_frequencies
conditionally on the presence of the "link-frequencies" property) ?

Or is the size of the allocated vep relevant in the async subdevice
matching or registration process? I guess not, but I might be missing
something...

Thanks
   j


>  {
> -	struct v4l2_fwnode_endpoint *vep;
>  	int rval;
>
> -	vep = kzalloc(sizeof(*vep), GFP_KERNEL);
> -	if (!vep)
> -		return ERR_PTR(-ENOMEM);
> -
>  	rval = __v4l2_fwnode_endpoint_parse(fwnode, vep);
>  	if (rval < 0)
> -		goto out_err;
> +		return rval;
>
>  	rval = fwnode_property_read_u64_array(fwnode, "link-frequencies",
>  					      NULL, 0);
> @@ -316,18 +310,18 @@ struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
>  		vep->link_frequencies =
>  			kmalloc_array(rval, sizeof(*vep->link_frequencies),
>  				      GFP_KERNEL);
> -		if (!vep->link_frequencies) {
> -			rval = -ENOMEM;
> -			goto out_err;
> -		}
> +		if (!vep->link_frequencies)
> +			return -ENOMEM;
>
>  		vep->nr_of_link_frequencies = rval;
>
>  		rval = fwnode_property_read_u64_array(
>  			fwnode, "link-frequencies", vep->link_frequencies,
>  			vep->nr_of_link_frequencies);
> -		if (rval < 0)
> -			goto out_err;
> +		if (rval < 0) {
> +			v4l2_fwnode_endpoint_free(vep);
> +			return rval;
> +		}
>
>  		for (i = 0; i < vep->nr_of_link_frequencies; i++)
>  			pr_info("link-frequencies %u value %llu\n", i,
> @@ -336,11 +330,7 @@ struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
>
>  	pr_debug("===== end V4L2 endpoint properties\n");
>
> -	return vep;
> -
> -out_err:
> -	v4l2_fwnode_endpoint_free(vep);
> -	return ERR_PTR(rval);
> +	return 0;
>  }
>  EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_alloc_parse);
>
> @@ -392,9 +382,9 @@ static int v4l2_async_notifier_fwnode_parse_endpoint(
>  			    struct v4l2_fwnode_endpoint *vep,
>  			    struct v4l2_async_subdev *asd))
>  {
> +	struct v4l2_fwnode_endpoint vep = { .bus_type = V4L2_MBUS_UNKNOWN };
>  	struct v4l2_async_subdev *asd;
> -	struct v4l2_fwnode_endpoint *vep;
> -	int ret = 0;
> +	int ret;
>
>  	asd = kzalloc(asd_struct_size, GFP_KERNEL);
>  	if (!asd)
> @@ -409,23 +399,22 @@ static int v4l2_async_notifier_fwnode_parse_endpoint(
>  		goto out_err;
>  	}
>
> -	vep = v4l2_fwnode_endpoint_alloc_parse(endpoint);
> -	if (IS_ERR(vep)) {
> -		ret = PTR_ERR(vep);
> +	ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &vep);
> +	if (ret) {
>  		dev_warn(dev, "unable to parse V4L2 fwnode endpoint (%d)\n",
>  			 ret);
>  		goto out_err;
>  	}
>
> -	ret = parse_endpoint ? parse_endpoint(dev, vep, asd) : 0;
> +	ret = parse_endpoint ? parse_endpoint(dev, &vep, asd) : 0;
>  	if (ret == -ENOTCONN)
> -		dev_dbg(dev, "ignoring port@%u/endpoint@%u\n", vep->base.port,
> -			vep->base.id);
> +		dev_dbg(dev, "ignoring port@%u/endpoint@%u\n", vep.base.port,
> +			vep.base.id);
>  	else if (ret < 0)
>  		dev_warn(dev,
>  			 "driver could not parse port@%u/endpoint@%u (%d)\n",
> -			 vep->base.port, vep->base.id, ret);
> -	v4l2_fwnode_endpoint_free(vep);
> +			 vep.base.port, vep.base.id, ret);
> +	v4l2_fwnode_endpoint_free(&vep);
>  	if (ret < 0)
>  		goto out_err;
>
> diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
> index 8b4873c37098..4a371c3ad86c 100644
> --- a/include/media/v4l2-fwnode.h
> +++ b/include/media/v4l2-fwnode.h
> @@ -161,6 +161,7 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
>  /**
>   * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties
>   * @fwnode: pointer to the endpoint's fwnode handle
> + * @vep: pointer to the V4L2 fwnode 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
> @@ -170,6 +171,8 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
>   * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
>   * reference to @fwnode.
>   *
> + * The caller must set the bus_type field of @vep to zero.
> + *
>   * v4l2_fwnode_endpoint_alloc_parse() has two important differences to
>   * v4l2_fwnode_endpoint_parse():
>   *
> @@ -178,11 +181,10 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
>   * 2. The memory it has allocated to store the variable size data must be freed
>   *    using v4l2_fwnode_endpoint_free() when no longer needed.
>   *
> - * Return: Pointer to v4l2_fwnode_endpoint if successful, on an error pointer
> - * on error.
> + * Return: 0 on success or a negative error code on failure.
>   */
> -struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
> -	struct fwnode_handle *fwnode);
> +int v4l2_fwnode_endpoint_alloc_parse(
> +	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep);
>
>  /**
>   * v4l2_fwnode_parse_link() - parse a link between two endpoints
> --
> 2.11.0
>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 18/23] v4l: fwnode: Use media bus type for bus parser selection
  2018-08-27  9:29 ` [PATCH v2 18/23] v4l: fwnode: Use media bus type for bus parser selection Sakari Ailus
@ 2018-09-12 15:15   ` jacopo mondi
  2018-09-12 20:53     ` Sakari Ailus
  0 siblings, 1 reply; 35+ messages in thread
From: jacopo mondi @ 2018-09-12 15:15 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-media, devicetree, slongerbeam, niklas.soderlund

[-- Attachment #1: Type: text/plain, Size: 7148 bytes --]

Hi Sakari,

On Mon, Aug 27, 2018 at 12:29:55PM +0300, Sakari Ailus wrote:
> Use the media bus types instead of the fwnode bus types internally. This
> is the interface to the drivers as well, making the use of the fwnode bus
> types more localised to the V4L2 fwnode framework.
>

So basically now "v4l2_fwnode_bus_type" it is only used in a few
places in v4l2-fwnode and has to be kept in sync with the bus types
listed in the devicetree bindings documentation?

Do you think it is still worth to keep around functions dealing with
that enum type as "v4l2_fwnode_bus_type_to_string()" ?
It is only used by a debug printout (without that much value added, as
we can print out the integer parsed from the DT). In all other cases
it can be converted to the corresponing v4l2_mbus_type immediately.

> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  drivers/media/v4l2-core/v4l2-fwnode.c | 100 +++++++++++++++++++++++++++-------
>  1 file changed, 80 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
> index 6c5a76442667..d502abd7406b 100644
> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> @@ -42,9 +42,66 @@ enum v4l2_fwnode_bus_type {
>  	NR_OF_V4L2_FWNODE_BUS_TYPE,
>  };
>
> +static const struct v4l2_fwnode_bus_conv {
> +	enum v4l2_fwnode_bus_type fwnode_bus_type;
> +	enum v4l2_mbus_type mbus_type;
> +	const char *name;
> +} busses[] = {
> +	{
> +		V4L2_FWNODE_BUS_TYPE_GUESS,
> +		V4L2_MBUS_UNKNOWN,
> +		"not specified",
> +	}, {
> +		V4L2_FWNODE_BUS_TYPE_CSI2_CPHY,
> +		V4L2_MBUS_CSI2_CPHY,
> +		"MIPI CSI-2 C-PHY",
> +	}, {
> +		V4L2_FWNODE_BUS_TYPE_CSI1,
> +		V4L2_MBUS_CSI1,
> +		"MIPI CSI-1",
> +	}, {
> +		V4L2_FWNODE_BUS_TYPE_CCP2,
> +		V4L2_MBUS_CCP2,
> +		"compact camera port 2",
> +	}, {
> +		V4L2_FWNODE_BUS_TYPE_CSI2_DPHY,
> +		V4L2_MBUS_CSI2_DPHY,
> +		"MIPI CSI-2 D-PHY",
> +	}, {
> +		V4L2_FWNODE_BUS_TYPE_PARALLEL,
> +		V4L2_MBUS_PARALLEL,
> +		"parallel",
> +	}, {
> +		V4L2_FWNODE_BUS_TYPE_BT656,
> +		V4L2_MBUS_BT656,
> +		"Bt.656",
> +	}
> +};
> +
> +static const struct v4l2_fwnode_bus_conv *
> +get_v4l2_fwnode_bus_conv_by_fwnode_bus(enum v4l2_fwnode_bus_type type)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(busses); i++)
> +		if (busses[i].fwnode_bus_type == type)
> +			return &busses[i];
> +
> +	return NULL;
> +}
> +
> +static enum v4l2_mbus_type
> +v4l2_fwnode_bus_type_to_mbus(enum v4l2_fwnode_bus_type type)
> +{
> +	const struct v4l2_fwnode_bus_conv *conv =
> +		get_v4l2_fwnode_bus_conv_by_fwnode_bus(type);
> +
> +	return conv ? conv->mbus_type : V4L2_MBUS_UNKNOWN;
> +}
> +
>  static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
>  					       struct v4l2_fwnode_endpoint *vep,
> -					       enum v4l2_fwnode_bus_type bus_type)
> +					       enum v4l2_mbus_type bus_type)
>  {
>  	struct v4l2_fwnode_bus_mipi_csi2 *bus = &vep->bus.mipi_csi2;
>  	bool have_clk_lane = false, have_data_lanes = false,
> @@ -58,7 +115,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
>  	u32 v;
>  	int rval;
>
> -	if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY) {
> +	if (bus_type == V4L2_MBUS_CSI2_DPHY) {
>  		use_default_lane_mapping = true;
>
>  		num_data_lanes = min_t(u32, bus->num_data_lanes,
> @@ -134,7 +191,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
>  		flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
>  	}
>
> -	if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY || lanes_used ||
> +	if (bus_type == V4L2_MBUS_CSI2_DPHY || lanes_used ||
>  	    have_clk_lane || (flags & ~V4L2_MBUS_CSI2_CONTINUOUS_CLOCK)) {
>  		bus->flags = flags;
>  		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
> @@ -177,7 +234,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
>
>  static void v4l2_fwnode_endpoint_parse_parallel_bus(
>  	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep,
> -	enum v4l2_fwnode_bus_type bus_type)
> +	enum v4l2_mbus_type bus_type)
>  {
>  	struct v4l2_fwnode_bus_parallel *bus = &vep->bus.parallel;
>  	unsigned int flags = 0;
> @@ -274,11 +331,11 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
>  		else
>  			vep->bus_type = V4L2_MBUS_BT656;
>  		break;
> -	case V4L2_FWNODE_BUS_TYPE_PARALLEL:
> +	case V4L2_MBUS_PARALLEL:
>  		vep->bus_type = V4L2_MBUS_PARALLEL;
>  		bus->flags = flags;
>  		break;
> -	case V4L2_FWNODE_BUS_TYPE_BT656:
> +	case V4L2_MBUS_BT656:
>  		vep->bus_type = V4L2_MBUS_BT656;
>  		bus->flags = flags & ~PARALLEL_MBUS_FLAGS;
>  		break;
> @@ -288,7 +345,7 @@ static void v4l2_fwnode_endpoint_parse_parallel_bus(
>  static void
>  v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle *fwnode,
>  				    struct v4l2_fwnode_endpoint *vep,
> -				    enum v4l2_fwnode_bus_type bus_type)
> +				    enum v4l2_mbus_type bus_type)
>  {
>  	struct v4l2_fwnode_bus_mipi_csi1 *bus = &vep->bus.mipi_csi1;
>  	u32 v;
> @@ -313,7 +370,7 @@ v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle *fwnode,
>  		pr_debug("clock-lanes %u\n", v);
>  	}
>
> -	if (bus_type == V4L2_FWNODE_BUS_TYPE_CCP2)
> +	if (bus_type == V4L2_MBUS_CCP2)
>  		vep->bus_type = V4L2_MBUS_CCP2;
>  	else
>  		vep->bus_type = V4L2_MBUS_CSI1;
> @@ -323,6 +380,7 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
>  					struct v4l2_fwnode_endpoint *vep)
>  {
>  	u32 bus_type = 0;
> +	enum v4l2_mbus_type mbus_type;
>  	int rval;
>
>  	if (vep->bus_type == V4L2_MBUS_UNKNOWN) {
> @@ -341,10 +399,12 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
>
>  	fwnode_property_read_u32(fwnode, "bus-type", &bus_type);
>
> -	switch (bus_type) {
> -	case V4L2_FWNODE_BUS_TYPE_GUESS:
> +	mbus_type = v4l2_fwnode_bus_type_to_mbus(bus_type);
> +
> +	switch (mbus_type) {
> +	case V4L2_MBUS_UNKNOWN:
>  		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
> -							   bus_type);
> +							   mbus_type);
>  		if (rval)
>  			return rval;
>
> @@ -353,26 +413,26 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
>  				fwnode, vep, V4L2_MBUS_UNKNOWN);
>
>  		break;
> -	case V4L2_FWNODE_BUS_TYPE_CCP2:
> -	case V4L2_FWNODE_BUS_TYPE_CSI1:
> -		v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, bus_type);
> +	case V4L2_MBUS_CCP2:
> +	case V4L2_MBUS_CSI1:
> +		v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, mbus_type);
>
>  		break;
> -	case V4L2_FWNODE_BUS_TYPE_CSI2_DPHY:
> +	case V4L2_MBUS_CSI2_DPHY:
>  		vep->bus_type = V4L2_MBUS_CSI2_DPHY;
>  		rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
> -							   bus_type);
> +							   mbus_type);
>  		if (rval)
>  			return rval;
>
>  		break;
> -	case V4L2_FWNODE_BUS_TYPE_PARALLEL:
> -	case V4L2_FWNODE_BUS_TYPE_BT656:
> -		v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep, bus_type);
> +	case V4L2_MBUS_PARALLEL:
> +	case V4L2_MBUS_BT656:
> +		v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep, mbus_type);
>
>  		break;
>  	default:
> -		pr_warn("unsupported bus type %u\n", bus_type);
> +		pr_warn("unsupported bus type %u\n", mbus_type);
>  		return -EINVAL;
>  	}
>
> --
> 2.11.0
>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 07/23] v4l: fwnode: Let the caller provide V4L2 fwnode endpoint
  2018-09-12 14:51   ` jacopo mondi
@ 2018-09-12 20:46     ` Sakari Ailus
  0 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-09-12 20:46 UTC (permalink / raw)
  To: jacopo mondi; +Cc: linux-media, devicetree, slongerbeam, niklas.soderlund

Hi Jacopo,

On Wed, Sep 12, 2018 at 04:51:07PM +0200, jacopo mondi wrote:
> Hi Sakari,
> 
> On Mon, Aug 27, 2018 at 12:29:44PM +0300, Sakari Ailus wrote:
> > Instead of allocating the V4L2 fwnode endpoint in
> > v4l2_fwnode_endpoint_alloc_parse, let the caller to do this. This allows
> > setting default parameters for the endpoint which is a very common need
> > for drivers.
> >
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> >  drivers/media/i2c/ov2659.c             | 14 +++++-----
> >  drivers/media/i2c/smiapp/smiapp-core.c | 26 +++++++++---------
> >  drivers/media/i2c/tc358743.c           | 26 +++++++++---------
> >  drivers/media/v4l2-core/v4l2-fwnode.c  | 49 +++++++++++++---------------------
> >  include/media/v4l2-fwnode.h            | 10 ++++---
> >  5 files changed, 60 insertions(+), 65 deletions(-)
> >
> 
> [snip]
> 
> > -struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
> > -	struct fwnode_handle *fwnode)
> > +int v4l2_fwnode_endpoint_alloc_parse(
> > +	struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep)
> 
> Looking at the resulting implementation of
> "v4l2_fwnode_endpoint_alloc_parse" and "v4l2_fwnode_endpoint_parse" I
> wonder if there's still value in keeping them separate... Now that in
> both cases the caller has to provide an v4l2_fwnode_endpoint, isn't it
> worth making a single function out of them, that behaves like
> "alloc_parse" is doing nowadays (allocates vep->link_frequencies
> conditionally on the presence of the "link-frequencies" property) ?

The problem with that would be that the caller would have to know if there
are variable length properties, i.e. the caller would always have to call
v4l2_fwnode_endpoint_free() once it no longer needs them. For quite a few
drivers this means immediately after calling the function which parsed
them.

I prefer to keep this simple for the drivers that need no such properties.

> 
> Or is the size of the allocated vep relevant in the async subdevice
> matching or registration process? I guess not, but I might be missing
> something...

It's not. The link frequencies are a pointer anyway.

-- 
Kind regards,

Sakari Ailus
sakari.ailus@linux.intel.com

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 18/23] v4l: fwnode: Use media bus type for bus parser selection
  2018-09-12 15:15   ` jacopo mondi
@ 2018-09-12 20:53     ` Sakari Ailus
  0 siblings, 0 replies; 35+ messages in thread
From: Sakari Ailus @ 2018-09-12 20:53 UTC (permalink / raw)
  To: jacopo mondi; +Cc: linux-media, devicetree, slongerbeam, niklas.soderlund

Hi Jacopo,

Thanks for the comments.

On Wed, Sep 12, 2018 at 05:15:05PM +0200, jacopo mondi wrote:
> Hi Sakari,
> 
> On Mon, Aug 27, 2018 at 12:29:55PM +0300, Sakari Ailus wrote:
> > Use the media bus types instead of the fwnode bus types internally. This
> > is the interface to the drivers as well, making the use of the fwnode bus
> > types more localised to the V4L2 fwnode framework.
> >
> 
> So basically now "v4l2_fwnode_bus_type" it is only used in a few
> places in v4l2-fwnode and has to be kept in sync with the bus types
> listed in the devicetree bindings documentation?

Correct.

> 
> Do you think it is still worth to keep around functions dealing with
> that enum type as "v4l2_fwnode_bus_type_to_string()" ?
> It is only used by a debug printout (without that much value added, as
> we can print out the integer parsed from the DT). In all other cases
> it can be converted to the corresponing v4l2_mbus_type immediately.

One of the aims of this patchset is to make debugging easier. A string is
more informative to the developers than a number, and for a few additional
lines of code I think that is justifiable.

I'll send v3 probably early tomorrow as I fixed a build issue;
V4L2_MBUS_UNKNOWN was used in one patch that preceded its introduction.

-- 
Regards,

Sakari Ailus
sakari.ailus@linux.intel.com

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2018-09-13  2:00 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-27  9:29 [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 01/23] v4l: fwnode: Add debug prints for V4L2 endpoint property parsing Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 02/23] v4l: fwnode: Use fwnode_graph_for_each_endpoint Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 03/23] v4l: fwnode: The CSI-2 clock is continuous if it's not non-continuous Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 04/23] dt-bindings: media: Specify bus type for MIPI D-PHY, others, explicitly Sakari Ailus
2018-08-29  0:45   ` Rob Herring
2018-08-27  9:29 ` [PATCH v2 05/23] v4l: fwnode: Add definitions for CSI-2 D-PHY, parallel and Bt.656 busses Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 06/23] v4l: mediabus: Recognise CSI-2 D-PHY and C-PHY Sakari Ailus
2018-08-31  8:02   ` [PATCH v2.1 " Sakari Ailus
2018-08-31  8:02     ` Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 07/23] v4l: fwnode: Let the caller provide V4L2 fwnode endpoint Sakari Ailus
2018-09-12 14:51   ` jacopo mondi
2018-09-12 20:46     ` Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 08/23] v4l: fwnode: Detect bus type correctly Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 09/23] v4l: fwnode: Make use of newly specified bus types Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 10/23] v4l: fwnode: Read lane inversion information despite lane numbering Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 11/23] v4l: fwnode: Only assign configuration if there is no error Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 12/23] v4l: fwnode: Support driver-defined lane mapping defaults Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 13/23] v4l: fwnode: Support default CSI-2 lane mapping for drivers Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 14/23] v4l: fwnode: Parse the graph endpoint as last Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 15/23] v4l: fwnode: Use default parallel flags Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 16/23] v4l: fwnode: Initialise the V4L2 fwnode endpoints to zero Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 17/23] v4l: fwnode: Only zero the struct if bus type is set to V4L2_MBUS_UNKNOWN Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 18/23] v4l: fwnode: Use media bus type for bus parser selection Sakari Ailus
2018-09-12 15:15   ` jacopo mondi
2018-09-12 20:53     ` Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 19/23] v4l: fwnode: Print bus type Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 20/23] v4l: fwnode: Use V4L2 fwnode endpoint media bus type if set Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 21/23] v4l: fwnode: Support parsing of CSI-2 C-PHY endpoints Sakari Ailus
2018-08-27  9:29 ` [PATCH v2 22/23] v4l: fwnode: Update V4L2 fwnode endpoint parsing documentation Sakari Ailus
2018-08-27  9:30 ` [PATCH v2 23/23] smiapp: Query the V4L2 endpoint for a specific bus type Sakari Ailus
2018-08-29  0:53 ` [PATCH v2 00/23] V4L2 fwnode rework; support for default configuration Steve Longerbeam
2018-08-29  0:53   ` Steve Longerbeam
2018-08-29 12:52   ` Sakari Ailus
2018-08-29 12:52     ` Sakari Ailus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.