[media] v4l: of: Read lane-polarities endpoint property
authorSakari Ailus <sakari.ailus@iki.fi>
Wed, 25 Mar 2015 22:57:37 +0000 (19:57 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Thu, 2 Apr 2015 19:46:42 +0000 (16:46 -0300)
Add lane_polarities field to struct v4l2_of_bus_mipi_csi2 and write the
contents of the lane-polarities property to it. The field tells the polarity
of the physical lanes starting from the first one. Any unused lanes are
ignored, i.e. only the polarity of the used lanes is specified.

Also rework reading the "data-lanes" property a little.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/v4l2-core/v4l2-of.c
include/media/v4l2-of.h

index b4ed9a955fbe0d779ad44b92a2780ff5d9808826..58e401f4893a9f3f5a119b4f25cd194b5da60b25 100644 (file)
 
 #include <media/v4l2-of.h>
 
-static void v4l2_of_parse_csi_bus(const struct device_node *node,
-                                 struct v4l2_of_endpoint *endpoint)
+static int v4l2_of_parse_csi_bus(const struct device_node *node,
+                                struct v4l2_of_endpoint *endpoint)
 {
        struct v4l2_of_bus_mipi_csi2 *bus = &endpoint->bus.mipi_csi2;
-       u32 data_lanes[ARRAY_SIZE(bus->data_lanes)];
        struct property *prop;
        bool have_clk_lane = false;
        unsigned int flags = 0;
@@ -32,16 +31,34 @@ static void v4l2_of_parse_csi_bus(const struct device_node *node,
        prop = of_find_property(node, "data-lanes", NULL);
        if (prop) {
                const __be32 *lane = NULL;
-               int i;
+               unsigned int i;
 
-               for (i = 0; i < ARRAY_SIZE(data_lanes); i++) {
-                       lane = of_prop_next_u32(prop, lane, &data_lanes[i]);
+               for (i = 0; i < ARRAY_SIZE(bus->data_lanes); i++) {
+                       lane = of_prop_next_u32(prop, lane, &v);
                        if (!lane)
                                break;
+                       bus->data_lanes[i] = v;
                }
                bus->num_data_lanes = i;
-               while (i--)
-                       bus->data_lanes[i] = data_lanes[i];
+       }
+
+       prop = of_find_property(node, "lane-polarities", NULL);
+       if (prop) {
+               const __be32 *polarity = NULL;
+               unsigned int i;
+
+               for (i = 0; i < ARRAY_SIZE(bus->lane_polarities); i++) {
+                       polarity = of_prop_next_u32(prop, polarity, &v);
+                       if (!polarity)
+                               break;
+                       bus->lane_polarities[i] = v;
+               }
+
+               if (i < 1 + bus->num_data_lanes /* clock + data */) {
+                       pr_warn("%s: too few lane-polarities entries (need %u, got %u)\n",
+                               node->full_name, 1 + bus->num_data_lanes, i);
+                       return -EINVAL;
+               }
        }
 
        if (!of_property_read_u32(node, "clock-lanes", &v)) {
@@ -56,6 +73,8 @@ static void v4l2_of_parse_csi_bus(const struct device_node *node,
 
        bus->flags = flags;
        endpoint->bus_type = V4L2_MBUS_CSI2;
+
+       return 0;
 }
 
 static void v4l2_of_parse_parallel_bus(const struct device_node *node,
@@ -127,11 +146,15 @@ static void v4l2_of_parse_parallel_bus(const struct device_node *node,
 int v4l2_of_parse_endpoint(const struct device_node *node,
                           struct v4l2_of_endpoint *endpoint)
 {
+       int rval;
+
        of_graph_parse_endpoint(node, &endpoint->base);
        endpoint->bus_type = 0;
        memset(&endpoint->bus, 0, sizeof(endpoint->bus));
 
-       v4l2_of_parse_csi_bus(node, endpoint);
+       rval = v4l2_of_parse_csi_bus(node, endpoint);
+       if (rval)
+               return rval;
        /*
         * Parse the parallel video bus properties only if none
         * of the MIPI CSI-2 specific properties were found.
index 70fa7b7b04879fc100bfce80cc79308260900e96..2de42c584eb28015aaa48c43ef7c5106f69c185b 100644 (file)
@@ -29,12 +29,15 @@ struct device_node;
  * @data_lanes: an array of physical data lane indexes
  * @clock_lane: physical lane index of the clock lane
  * @num_data_lanes: number of data lanes
+ * @lane_polarities: polarity of the lanes. The order is the same of
+ *                the physical lanes.
  */
 struct v4l2_of_bus_mipi_csi2 {
        unsigned int flags;
        unsigned char data_lanes[4];
        unsigned char clock_lane;
        unsigned short num_data_lanes;
+       bool lane_polarities[5];
 };
 
 /**
This page took 0.026847 seconds and 5 git commands to generate.