Re: [PATCH v2 2/2] v4l: mt9v032: Add OF support

2015-03-13 Thread Laurent Pinchart
Hi Prabhakar,

On Friday 13 March 2015 05:43:42 Lad, Prabhakar wrote:
> On Fri, Mar 13, 2015 at 12:03 AM, Laurent Pinchart wrote:
> > Parse DT properties into a platform data structure when a DT node is
> > available.
> > 
> > Signed-off-by: Laurent Pinchart 
> > 
> > ---
> 
> [snip]
> 
> > +static struct mt9v032_platform_data *
> > +mt9v032_get_pdata(struct i2c_client *client)
> > +{
> > +   struct mt9v032_platform_data *pdata;
> > +   struct v4l2_of_endpoint endpoint;
> > +   struct device_node *np;
> > +   struct property *prop;
> > +
> > +   if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
> > +   return client->dev.platform_data;
> > +
> > +   np = v4l2_of_get_next_endpoint(client->dev.of_node, NULL);
> > +   if (!np)
> > +   return NULL;
> > +
> > +   if (v4l2_of_parse_endpoint(np, &endpoint) < 0)
> > +   goto done;
> > +
> 
> with the above two statements it seems its based on older version of kernel.

You're absolutely right, I've sent the wrong version of the patch, sorry about 
that.

I'll fix the v4l2_of_get_next_endpoint() call in v3. Is there anything wrong 
with v4l2_of_parse_endpoint() though ?

-- 
Regards,

Laurent Pinchart

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


Re: [PATCH v2 2/2] v4l: mt9v032: Add OF support

2015-03-12 Thread Lad, Prabhakar
Hi Laurent,

Thanks for the patch.

On Fri, Mar 13, 2015 at 12:03 AM, Laurent Pinchart
 wrote:
> Parse DT properties into a platform data structure when a DT node is
> available.
>
> Signed-off-by: Laurent Pinchart 
>
> ---
>
[snip]
> +static struct mt9v032_platform_data *
> +mt9v032_get_pdata(struct i2c_client *client)
> +{
> +   struct mt9v032_platform_data *pdata;
> +   struct v4l2_of_endpoint endpoint;
> +   struct device_node *np;
> +   struct property *prop;
> +
> +   if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
> +   return client->dev.platform_data;
> +
> +   np = v4l2_of_get_next_endpoint(client->dev.of_node, NULL);
> +   if (!np)
> +   return NULL;
> +
> +   if (v4l2_of_parse_endpoint(np, &endpoint) < 0)
> +   goto done;
> +
with the above two statements it seems its based on older version of kernel.

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


[PATCH v2 2/2] v4l: mt9v032: Add OF support

2015-03-12 Thread Laurent Pinchart
Parse DT properties into a platform data structure when a DT node is
available.

Signed-off-by: Laurent Pinchart 

---

Changes since v1:

- Add MT9V02[24] compatible strings
- Prefix all compatible strings with "aptina,"
- Use "link-frequencies" instead of "link-freqs"

Open questions:

- Should the color/monochrome model be inferred from the compatible string, or
  should a separate DT property be used for that ?

---
 .../devicetree/bindings/media/i2c/mt9v032.txt  | 45 ++
 MAINTAINERS|  1 +
 drivers/media/i2c/mt9v032.c| 70 +-
 3 files changed, 115 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/mt9v032.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/mt9v032.txt 
b/Documentation/devicetree/bindings/media/i2c/mt9v032.txt
new file mode 100644
index 000..68b134e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/mt9v032.txt
@@ -0,0 +1,45 @@
+* Aptina 1/3-Inch WVGA CMOS Digital Image Sensor
+
+The Aptina MT9V032 is a 1/3-inch CMOS active pixel digital image sensor with
+an active array size of 752H x 480V. It is programmable through a simple
+two-wire serial interface.
+
+Required Properties:
+
+- compatible: value should be either one among the following
+   (a) "aptina,mt9v022" for MT9V022 color sensor
+   (b) "aptina,mt9v022m" for MT9V022 monochrome sensor
+   (c) "aptina,mt9v024" for MT9V024 color sensor
+   (d) "aptina,mt9v024m" for MT9V024 monochrome sensor
+   (e) "aptina,mt9v032" for MT9V032 color sensor
+   (f) "aptina,mt9v032m" for MT9V032 monochrome sensor
+   (g) "aptina,mt9v034" for MT9V034 color sensor
+   (h) "aptina,mt9v034m" for MT9V034 monochrome sensor
+
+Optional Properties:
+
+- link-frequencies: List of allowed link frequencies in Hz. Each frequency is
+   expressed as a 64-bit big-endian integer.
+
+For further reading on port node refer to
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+   i2c0@1c22000 {
+   ...
+   ...
+   mt9v032@5c {
+   compatible = "aptina,mt9v032";
+   reg = <0x5c>;
+
+   port {
+   mt9v032_1: endpoint {
+   link-frequencies =
+   <0 1300>, <0 2660>,
+   <0 2700>;
+   };
+   };
+   };
+   ...
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index ddc5a8c..180f6fb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6535,6 +6535,7 @@ M:Laurent Pinchart 

 L: linux-media@vger.kernel.org
 T: git git://linuxtv.org/media_tree.git
 S: Maintained
+F: Documentation/devicetree/bindings/media/i2c/mt9v032.txt
 F: drivers/media/i2c/mt9v032.c
 F: include/media/mt9v032.h
 
diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c
index 255ea91..89e6d8d 100644
--- a/drivers/media/i2c/mt9v032.c
+++ b/drivers/media/i2c/mt9v032.c
@@ -17,6 +17,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /* The first four rows are black rows. The active area spans 753x481 pixels. */
@@ -876,10 +879,59 @@ static const struct regmap_config mt9v032_regmap_config = 
{
  * Driver initialization and probing
  */
 
+static struct mt9v032_platform_data *
+mt9v032_get_pdata(struct i2c_client *client)
+{
+   struct mt9v032_platform_data *pdata;
+   struct v4l2_of_endpoint endpoint;
+   struct device_node *np;
+   struct property *prop;
+
+   if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
+   return client->dev.platform_data;
+
+   np = v4l2_of_get_next_endpoint(client->dev.of_node, NULL);
+   if (!np)
+   return NULL;
+
+   if (v4l2_of_parse_endpoint(np, &endpoint) < 0)
+   goto done;
+
+   pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   goto done;
+
+   prop = of_find_property(np, "link-frequencies", NULL);
+   if (prop) {
+   size_t size = prop->length / 8;
+   u64 *link_freqs;
+
+   link_freqs = devm_kzalloc(&client->dev,
+ size * sizeof(*link_freqs),
+ GFP_KERNEL);
+   if (!link_freqs)
+   goto done;
+
+   if (of_property_read_u64_array(np, "link-frequencies",
+  link_freqs, size) < 0)
+   goto done;
+
+   pdata->link_freqs = link_freqs;
+   pdata->link_def_freq = link_freqs[0];
+   }
+
+