All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code
@ 2012-02-20  1:56 Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 01/33] v4l: Introduce integer menu controls Sakari Ailus
                   ` (33 more replies)
  0 siblings, 34 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: Laurent Pinchart, David Cohen, Sylwester Nawrocki, Hans Verkuil,
	Andy Shevchenko, Tomasz Stanislawski, tuukkat76, Kamil Debski,
	Kim HeungJun, teturtia

Hi everyone,

This the third version of my patchset that contains:

- Integer menu controls [2],
- Selection IOCTL for subdevs [3],
- Sensor control changes [5,7],
- link_validate() media entity and V4L2 subdev pad ops,
- OMAP 3 ISP driver improvements [4],
- SMIA++ sensor driver,
- rm680/rm696 board code (a.k.a Nokia N9 and N950) and
- Other V4L2 and media improvements (see individual patches)

The Docbook documentation in HTML format can be found in [11].

Changes to version 2 [10] include:

- V4L2
  - Image source controls
    - Documentation no longer refers to "pixel clock" in v4l2_mbus_framefmt
      (this should have been the last reference to those!!)
    - Capitalise first letters in control names
  - Selections
    - Use hex numbers for targets
  - Return NULL instead of invalid pointer when accessing non-existend pads
    in v4l2_subdev_get_try_{format,crop,compose} (new patch)
  - Put link validation definitions in v4l2-subdev.h behind
    #ifdef CONFIG_MEDIA_CONTROLLER ... #endif
  - Spelling fixes (selections and 4cc guidelines)
  - Change vdev_to_v4l2_subdev() return type to struct v4l2_subdev * (new
    patch)

- SMIA++ driver
  - Clock tree calculation fixes
  - Control handler setup usage fixes at smiapp_open()
  - Don't access non-existent pads

Changes to version 1 [8] include:

- OMAP 3 ISP driver
  - Swapped order of csi receiver's lane definitions
  - Rewrote omap 3 isp link validation patches almost completely
    - Information on connected external entity collected to isp_pipeline
    - Information collected during link checking and used at streamon

- Media entity link validation
  - Error handling fixes

- SMIA++ driver
  - Selection API bugfixes
  - Report correct pixel order right from boot
  - Move link rate control to subdev connected to subdev external to the
    sensor (e.g. ISP's CSI-2 receiver)
  - Introduce proper serialisation
  - Deny changing some controls when streaming (flipping and link rate)
  - Control handler setup moved from streamon time to first subdev open
  - There is no source compose target
  - Bugfixes

- Media bus pixel codes
  - Documentation fix for dpcm compressed formats
  - Added patch for 4CC guidelines (raw bayer only for now)

- Selections
  - Improved selections documentation
  - Added more selections examples
  - Compose target is not available on source pads anymore [9]
  - Dropped default targets

- V4L2
  - Add documentation on link_validate()
  - link_validate() and relater functions  depends on CONFIG_MEDIA_CONTROLLER
  - Skip link validation for links on which stream_count was non-zero
  - Do not validate link if entity's stream count is non-zero
  - Use v4l2_subdev_link_validate_default() if no link_validate pad op is set
  - Allow changing control handler mutex: this enables a driver to provide
    multiple subdevs but use only one mutex. Default mutex (part of struct
    v4l2_ctrl_handler) is set in v4l2_ctrl_handler_init().
  - Split image source class into two: image source and image processing

Changes to the RFC v1 [6] include:

- Integer controls:
  - Target Linux 3.4 instead of 3.3
  - Proper control type check in querymenu
  - vivi compile fixes

- Subdev selections
  - Pad try fields combined to single struct
  - Correctly set sel.which based on crop->which in crop fall-back

- Subdev selection documentation
  - Better explanation on image processing in subdevs
  - Added a diagram to visualise subdev configuration
  - Fixed DocBook syntax issues
  - Mark VIDIOC_SUBDEV_S_CROP and VIDIOC_SUBDEV_G_CROP obsolete

- Pixel rate
  - Pixel rate is now a 64-bit control, not part of v4l2_mbus_framefmt
  - Unit for pixel rate is pixels / second
  - Pixel rate is read-only

- Link frequency is now in Hz --- documented as such also

- Link validation instead of pipeline validation
  - Each link is validated by calling link_validate op
    - Added link validation op to media_entity_ops
  - Link validation op in pad ops makes this easy for subdev drivers
  - media_entity_pipeline_start() may return an error code now
    - This might affect other drivers, but will warn in compilation.
      No adverse effects are caused if the driver does not use
      link_validate().

- OMAP 3 ISP
  - Make lanecfg as part of the platform data structure, not pointer
  - Document lane configuration structures
  - Link validation moved to respective subdev drivers from ispvideo.c
    - isp_validate_pipeline() removed

- SMIA++ driver
  - Update pixel order based on vflip and hflip
  - Cleanups in the main driver, register definitions and PLL code
  - Depend on V4L2_V4L2_SUBDEV_API and MEDIA_CONTROLLER
  - Use pr_* macros instead of printk
  - Improved error handling for i2c_transfer()
  - Removed useless definitions
  - Don't access try crop / compose directly but use helper functions
  - Add xshutdown to platform data
  - Move driver under smiapp directory

- rm680 board code
  - Use REGULATOR_SUPPLY() where possible
  - Removed printk()'s
  - Don't include private smiapp headers


References:

[1] http://www.spinics.net/lists/linux-omap/msg61295.html

[2] http://www.spinics.net/lists/linux-media/msg40796.html

[3] http://www.spinics.net/lists/linux-media/msg41503.html

[4] http://www.spinics.net/lists/linux-media/msg41542.html

[5] http://www.spinics.net/lists/linux-media/msg40861.html

[6] http://www.spinics.net/lists/linux-media/msg41765.html

[7] http://www.spinics.net/lists/linux-media/msg42848.html

[8] http://www.spinics.net/lists/linux-media/msg42991.html

[9] http://www.spinics.net/lists/linux-media/msg43810.html

[10] http://www.spinics.net/lists/linux-media/msg43888.html

[11] http://www.retiisi.org.uk/v4l2/tmp/media_api/

Kind regards,

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

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

* [PATCH v3 01/33] v4l: Introduce integer menu controls
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20 17:36   ` Sylwester Nawrocki
  2012-02-20  1:56 ` [PATCH v3 02/33] v4l: Document " Sakari Ailus
                   ` (32 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Create a new control type called V4L2_CTRL_TYPE_INTEGER_MENU. Integer menu
controls are just like menu controls but the menu items are 64-bit integers
rather than strings.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/video/v4l2-ctrls.c |   74 +++++++++++++++++++++++++++++---------
 include/linux/videodev2.h        |    6 +++-
 include/media/v4l2-ctrls.h       |    6 +++-
 3 files changed, 67 insertions(+), 19 deletions(-)

diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
index 9091172..f0484bd 100644
--- a/drivers/media/video/v4l2-ctrls.c
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -828,7 +828,8 @@ static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, u32 change
 		ev->u.ctrl.value64 = ctrl->cur.val64;
 	ev->u.ctrl.minimum = ctrl->minimum;
 	ev->u.ctrl.maximum = ctrl->maximum;
-	if (ctrl->type == V4L2_CTRL_TYPE_MENU)
+	if (ctrl->type == V4L2_CTRL_TYPE_MENU
+	    || ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU)
 		ev->u.ctrl.step = 1;
 	else
 		ev->u.ctrl.step = ctrl->step;
@@ -1059,10 +1060,13 @@ static int validate_new_int(const struct v4l2_ctrl *ctrl, s32 *pval)
 		return 0;
 
 	case V4L2_CTRL_TYPE_MENU:
+	case V4L2_CTRL_TYPE_INTEGER_MENU:
 		if (val < ctrl->minimum || val > ctrl->maximum)
 			return -ERANGE;
-		if (ctrl->qmenu[val][0] == '\0' ||
-		    (ctrl->menu_skip_mask & (1 << val)))
+		if (ctrl->menu_skip_mask & (1 << val))
+			return -EINVAL;
+		if (ctrl->type == V4L2_CTRL_TYPE_MENU &&
+		    ctrl->qmenu[val][0] == '\0')
 			return -EINVAL;
 		return 0;
 
@@ -1090,6 +1094,7 @@ static int validate_new(const struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c
 	case V4L2_CTRL_TYPE_INTEGER:
 	case V4L2_CTRL_TYPE_BOOLEAN:
 	case V4L2_CTRL_TYPE_MENU:
+	case V4L2_CTRL_TYPE_INTEGER_MENU:
 	case V4L2_CTRL_TYPE_BITMASK:
 	case V4L2_CTRL_TYPE_BUTTON:
 	case V4L2_CTRL_TYPE_CTRL_CLASS:
@@ -1319,7 +1324,8 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 			const struct v4l2_ctrl_ops *ops,
 			u32 id, const char *name, enum v4l2_ctrl_type type,
 			s32 min, s32 max, u32 step, s32 def,
-			u32 flags, const char * const *qmenu, void *priv)
+			u32 flags, const char * const *qmenu,
+			const s64 *qmenu_int, void *priv)
 {
 	struct v4l2_ctrl *ctrl;
 	unsigned sz_extra = 0;
@@ -1332,6 +1338,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	    (type == V4L2_CTRL_TYPE_INTEGER && step == 0) ||
 	    (type == V4L2_CTRL_TYPE_BITMASK && max == 0) ||
 	    (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) ||
+	    (type == V4L2_CTRL_TYPE_INTEGER_MENU && qmenu_int == NULL) ||
 	    (type == V4L2_CTRL_TYPE_STRING && max == 0)) {
 		handler_set_err(hdl, -ERANGE);
 		return NULL;
@@ -1342,6 +1349,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	}
 	if ((type == V4L2_CTRL_TYPE_INTEGER ||
 	     type == V4L2_CTRL_TYPE_MENU ||
+	     type == V4L2_CTRL_TYPE_INTEGER_MENU ||
 	     type == V4L2_CTRL_TYPE_BOOLEAN) &&
 	    (def < min || def > max)) {
 		handler_set_err(hdl, -ERANGE);
@@ -1376,7 +1384,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	ctrl->minimum = min;
 	ctrl->maximum = max;
 	ctrl->step = step;
-	ctrl->qmenu = qmenu;
+	if (type == V4L2_CTRL_TYPE_MENU)
+		ctrl->qmenu = qmenu;
+	else if (type == V4L2_CTRL_TYPE_INTEGER_MENU)
+		ctrl->qmenu_int = qmenu_int;
 	ctrl->priv = priv;
 	ctrl->cur.val = ctrl->val = ctrl->default_value = def;
 
@@ -1403,6 +1414,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
 	struct v4l2_ctrl *ctrl;
 	const char *name = cfg->name;
 	const char * const *qmenu = cfg->qmenu;
+	const s64 *qmenu_int = cfg->qmenu_int;
 	enum v4l2_ctrl_type type = cfg->type;
 	u32 flags = cfg->flags;
 	s32 min = cfg->min;
@@ -1414,18 +1426,24 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
 		v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step,
 								&def, &flags);
 
-	is_menu = (cfg->type == V4L2_CTRL_TYPE_MENU);
+	is_menu = (cfg->type == V4L2_CTRL_TYPE_MENU ||
+		   cfg->type == V4L2_CTRL_TYPE_INTEGER_MENU);
 	if (is_menu)
 		WARN_ON(step);
 	else
 		WARN_ON(cfg->menu_skip_mask);
-	if (is_menu && qmenu == NULL)
+	if (cfg->type == V4L2_CTRL_TYPE_MENU && qmenu == NULL)
 		qmenu = v4l2_ctrl_get_menu(cfg->id);
+	else if (cfg->type == V4L2_CTRL_TYPE_INTEGER_MENU &&
+		 qmenu_int == NULL) {
+		handler_set_err(hdl, -EINVAL);
+		return NULL;
+	}
 
 	ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->id, name,
 			type, min, max,
 			is_menu ? cfg->menu_skip_mask : step,
-			def, flags, qmenu, priv);
+			def, flags, qmenu, qmenu_int, priv);
 	if (ctrl)
 		ctrl->is_private = cfg->is_private;
 	return ctrl;
@@ -1442,12 +1460,13 @@ struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
 	u32 flags;
 
 	v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
-	if (type == V4L2_CTRL_TYPE_MENU) {
+	if (type == V4L2_CTRL_TYPE_MENU
+	    || type == V4L2_CTRL_TYPE_INTEGER_MENU) {
 		handler_set_err(hdl, -EINVAL);
 		return NULL;
 	}
 	return v4l2_ctrl_new(hdl, ops, id, name, type,
-				    min, max, step, def, flags, NULL, NULL);
+			     min, max, step, def, flags, NULL, NULL, NULL);
 }
 EXPORT_SYMBOL(v4l2_ctrl_new_std);
 
@@ -1469,7 +1488,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
 		return NULL;
 	}
 	return v4l2_ctrl_new(hdl, ops, id, name, type,
-				    0, max, mask, def, flags, qmenu, NULL);
+			     0, max, mask, def, flags, qmenu, NULL, NULL);
 }
 EXPORT_SYMBOL(v4l2_ctrl_new_std_menu);
 
@@ -1633,6 +1652,9 @@ static void log_ctrl(const struct v4l2_ctrl *ctrl,
 	case V4L2_CTRL_TYPE_MENU:
 		printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]);
 		break;
+	case V4L2_CTRL_TYPE_INTEGER_MENU:
+		printk(KERN_CONT "%lld", ctrl->qmenu_int[ctrl->cur.val]);
+		break;
 	case V4L2_CTRL_TYPE_BITMASK:
 		printk(KERN_CONT "0x%08x", ctrl->cur.val);
 		break;
@@ -1769,7 +1791,8 @@ int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc)
 	qc->minimum = ctrl->minimum;
 	qc->maximum = ctrl->maximum;
 	qc->default_value = ctrl->default_value;
-	if (ctrl->type == V4L2_CTRL_TYPE_MENU)
+	if (ctrl->type == V4L2_CTRL_TYPE_MENU
+	    || ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU)
 		qc->step = 1;
 	else
 		qc->step = ctrl->step;
@@ -1799,16 +1822,33 @@ int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm)
 
 	qm->reserved = 0;
 	/* Sanity checks */
-	if (ctrl->qmenu == NULL ||
-	    i < ctrl->minimum || i > ctrl->maximum)
+	switch (ctrl->type) {
+	case V4L2_CTRL_TYPE_MENU:
+		if (ctrl->qmenu == NULL)
+			return -EINVAL;
+		break;
+	case V4L2_CTRL_TYPE_INTEGER_MENU:
+		if (ctrl->qmenu_int == NULL)
+			return -EINVAL;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (i < ctrl->minimum || i > ctrl->maximum)
 		return -EINVAL;
+
 	/* Use mask to see if this menu item should be skipped */
 	if (ctrl->menu_skip_mask & (1 << i))
 		return -EINVAL;
 	/* Empty menu items should also be skipped */
-	if (ctrl->qmenu[i] == NULL || ctrl->qmenu[i][0] == '\0')
-		return -EINVAL;
-	strlcpy(qm->name, ctrl->qmenu[i], sizeof(qm->name));
+	if (ctrl->type == V4L2_CTRL_TYPE_MENU) {
+		if (ctrl->qmenu[i] == NULL || ctrl->qmenu[i][0] == '\0')
+			return -EINVAL;
+		strlcpy(qm->name, ctrl->qmenu[i], sizeof(qm->name));
+	} else {
+		qm->value = ctrl->qmenu_int[i];
+	}
 	return 0;
 }
 EXPORT_SYMBOL(v4l2_querymenu);
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index b739d7d..e3c6302 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -1150,6 +1150,7 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_CTRL_CLASS    = 6,
 	V4L2_CTRL_TYPE_STRING        = 7,
 	V4L2_CTRL_TYPE_BITMASK       = 8,
+	V4L2_CTRL_TYPE_INTEGER_MENU = 9,
 };
 
 /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
@@ -1169,7 +1170,10 @@ struct v4l2_queryctrl {
 struct v4l2_querymenu {
 	__u32		id;
 	__u32		index;
-	__u8		name[32];	/* Whatever */
+	union {
+		__u8	name[32];	/* Whatever */
+		__s64	value;
+	};
 	__u32		reserved;
 };
 
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 3dbd066..533315b 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -130,7 +130,10 @@ struct v4l2_ctrl {
 		u32 step;
 		u32 menu_skip_mask;
 	};
-	const char * const *qmenu;
+	union {
+		const char * const *qmenu;
+		const s64 *qmenu_int;
+	};
 	unsigned long flags;
 	union {
 		s32 val;
@@ -220,6 +223,7 @@ struct v4l2_ctrl_config {
 	u32 flags;
 	u32 menu_skip_mask;
 	const char * const *qmenu;
+	const s64 *qmenu_int;
 	unsigned int is_private:1;
 };
 
-- 
1.7.2.5


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

* [PATCH v3 02/33] v4l: Document integer menu controls
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 01/33] v4l: Introduce integer menu controls Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 03/33] vivi: Add an integer menu test control Sakari Ailus
                   ` (31 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 Documentation/DocBook/media/v4l/compat.xml         |   10 +++++
 Documentation/DocBook/media/v4l/v4l2.xml           |    6 +++
 .../DocBook/media/v4l/vidioc-queryctrl.xml         |   39 +++++++++++++++++++-
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/Documentation/DocBook/media/v4l/compat.xml b/Documentation/DocBook/media/v4l/compat.xml
index c93298f..8cd5c96 100644
--- a/Documentation/DocBook/media/v4l/compat.xml
+++ b/Documentation/DocBook/media/v4l/compat.xml
@@ -2400,6 +2400,16 @@ details.</para>
       </orderedlist>
     </section>
 
+    <section>
+      <title>V4L2 in Linux 3.4</title>
+      <orderedlist>
+        <listitem>
+	  <para>Added integer menus, the new type will be
+	  V4L2_CTRL_TYPE_INTEGER_MENU.</para>
+        </listitem>
+      </orderedlist>
+    </section>
+
     <section id="other">
       <title>Relation of V4L2 to other Linux multimedia APIs</title>
 
diff --git a/Documentation/DocBook/media/v4l/v4l2.xml b/Documentation/DocBook/media/v4l/v4l2.xml
index dcf9e33..ff11a13 100644
--- a/Documentation/DocBook/media/v4l/v4l2.xml
+++ b/Documentation/DocBook/media/v4l/v4l2.xml
@@ -128,6 +128,12 @@ structs, ioctls) must be noted in more detail in the history chapter
 applications. -->
 
       <revision>
+	<revnumber>3.4</revnumber>
+	<date>2012-01-26</date>
+	<authorinitials>sa</authorinitials>
+	<revremark>Added V4L2_CTRL_TYPE_INTEGER_MENU.</revremark>
+      </revision>
+      <revision>
 	<revnumber>3.3</revnumber>
 	<date>2012-01-11</date>
 	<authorinitials>hv</authorinitials>
diff --git a/Documentation/DocBook/media/v4l/vidioc-queryctrl.xml b/Documentation/DocBook/media/v4l/vidioc-queryctrl.xml
index 36660d3..505f020 100644
--- a/Documentation/DocBook/media/v4l/vidioc-queryctrl.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-queryctrl.xml
@@ -215,11 +215,12 @@ the array to zero.</entry>
 
     <table pgwide="1" frame="none" id="v4l2-querymenu">
       <title>struct <structname>v4l2_querymenu</structname></title>
-      <tgroup cols="3">
+      <tgroup cols="4">
 	&cs-str;
 	<tbody valign="top">
 	  <row>
 	    <entry>__u32</entry>
+	    <entry></entry>
 	    <entry><structfield>id</structfield></entry>
 	    <entry>Identifies the control, set by the application
 from the respective &v4l2-queryctrl;
@@ -227,18 +228,38 @@ from the respective &v4l2-queryctrl;
 	  </row>
 	  <row>
 	    <entry>__u32</entry>
+	    <entry></entry>
 	    <entry><structfield>index</structfield></entry>
 	    <entry>Index of the menu item, starting at zero, set by
 	    the application.</entry>
 	  </row>
 	  <row>
+	    <entry>union</entry>
+	    <entry></entry>
+	    <entry></entry>
+	    <entry></entry>
+	  </row>
+	  <row>
+	    <entry></entry>
 	    <entry>__u8</entry>
 	    <entry><structfield>name</structfield>[32]</entry>
 	    <entry>Name of the menu item, a NUL-terminated ASCII
-string. This information is intended for the user.</entry>
+string. This information is intended for the user. This field is valid
+for <constant>V4L2_CTRL_FLAG_MENU</constant> type controls.</entry>
+	  </row>
+	  <row>
+	    <entry></entry>
+	    <entry>__s64</entry>
+	    <entry><structfield>value</structfield></entry>
+	    <entry>
+              Value of the integer menu item. This field is valid for
+              <constant>V4L2_CTRL_FLAG_INTEGER_MENU</constant> type
+              controls.
+            </entry>
 	  </row>
 	  <row>
 	    <entry>__u32</entry>
+	    <entry></entry>
 	    <entry><structfield>reserved</structfield></entry>
 	    <entry>Reserved for future extensions. Drivers must set
 the array to zero.</entry>
@@ -292,6 +313,20 @@ the menu items can be enumerated with the
 <constant>VIDIOC_QUERYMENU</constant> ioctl.</entry>
 	  </row>
 	  <row>
+	    <entry><constant>V4L2_CTRL_TYPE_INTEGER_MENU</constant></entry>
+	    <entry>&ge; 0</entry>
+	    <entry>1</entry>
+	    <entry>N-1</entry>
+	    <entry>
+              The control has a menu of N choices. The values of the
+              menu items can be enumerated with the
+              <constant>VIDIOC_QUERYMENU</constant> ioctl. This is
+              similar to <constant>V4L2_CTRL_TYPE_MENU</constant>
+              except that instead of strings, the menu items are
+              signed 64-bit integers.
+            </entry>
+	  </row>
+	  <row>
 	    <entry><constant>V4L2_CTRL_TYPE_BITMASK</constant></entry>
 	    <entry>0</entry>
 	    <entry>n/a</entry>
-- 
1.7.2.5


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

* [PATCH v3 03/33] vivi: Add an integer menu test control
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 01/33] v4l: Introduce integer menu controls Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 02/33] v4l: Document " Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs Sakari Ailus
                   ` (30 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Add an integer menu test control for the vivi driver.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/video/vivi.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 5e8b071..d75a1e4 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -177,6 +177,7 @@ struct vivi_dev {
 	struct v4l2_ctrl	   *menu;
 	struct v4l2_ctrl	   *string;
 	struct v4l2_ctrl	   *bitmask;
+	struct v4l2_ctrl	   *int_menu;
 
 	spinlock_t                 slock;
 	struct mutex		   mutex;
@@ -503,6 +504,10 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
 			dev->boolean->cur.val,
 			dev->menu->qmenu[dev->menu->cur.val],
 			dev->string->cur.string);
+	snprintf(str, sizeof(str), " integer_menu %lld, value %d ",
+			dev->int_menu->qmenu_int[dev->int_menu->cur.val],
+			dev->int_menu->cur.val);
+	gen_text(dev, vbuf, line++ * 16, 16, str);
 	mutex_unlock(&dev->ctrl_handler.lock);
 	gen_text(dev, vbuf, line++ * 16, 16, str);
 	if (dev->button_pressed) {
@@ -1165,6 +1170,22 @@ static const struct v4l2_ctrl_config vivi_ctrl_bitmask = {
 	.step = 0,
 };
 
+static const s64 vivi_ctrl_int_menu_values[] = {
+	1, 1, 2, 3, 5, 8, 13, 21, 42,
+};
+
+static const struct v4l2_ctrl_config vivi_ctrl_int_menu = {
+	.ops = &vivi_ctrl_ops,
+	.id = VIVI_CID_CUSTOM_BASE + 7,
+	.name = "Integer menu",
+	.type = V4L2_CTRL_TYPE_INTEGER_MENU,
+	.min = 1,
+	.max = 8,
+	.def = 4,
+	.menu_skip_mask = 0x02,
+	.qmenu_int = vivi_ctrl_int_menu_values,
+};
+
 static const struct v4l2_file_operations vivi_fops = {
 	.owner		= THIS_MODULE,
 	.open           = v4l2_fh_open,
@@ -1275,6 +1296,7 @@ static int __init vivi_create_instance(int inst)
 	dev->menu = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_menu, NULL);
 	dev->string = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_string, NULL);
 	dev->bitmask = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_bitmask, NULL);
+	dev->int_menu = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_int_menu, NULL);
 	if (hdl->error) {
 		ret = hdl->error;
 		goto unreg_dev;
-- 
1.7.2.5


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

* [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (2 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 03/33] vivi: Add an integer menu test control Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-21 14:34   ` Laurent Pinchart
  2012-02-21 16:15   ` Laurent Pinchart
  2012-02-20  1:56 ` [PATCH v3 05/33] v4l: vdev_to_v4l2_subdev() should have return type "struct v4l2_subdev *" Sakari Ailus
                   ` (29 subsequent siblings)
  33 siblings, 2 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Add support for VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION
IOCTLs. They replace functionality provided by VIDIOC_SUBDEV_S_CROP and
VIDIOC_SUBDEV_G_CROP IOCTLs and also add new functionality (composing).

VIDIOC_SUBDEV_G_CROP and VIDIOC_SUBDEV_S_CROP continue to be supported.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/v4l2-subdev.c |   34 +++++++++++++++++++++---------
 include/linux/v4l2-subdev.h       |   41 +++++++++++++++++++++++++++++++++++++
 include/media/v4l2-subdev.h       |   21 +++++++++++++++---
 3 files changed, 82 insertions(+), 14 deletions(-)

diff --git a/drivers/media/video/v4l2-subdev.c b/drivers/media/video/v4l2-subdev.c
index 6fe88e9..30c7fd9 100644
--- a/drivers/media/video/v4l2-subdev.c
+++ b/drivers/media/video/v4l2-subdev.c
@@ -35,14 +35,9 @@
 static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd)
 {
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
-	/* Allocate try format and crop in the same memory block */
-	fh->try_fmt = kzalloc((sizeof(*fh->try_fmt) + sizeof(*fh->try_crop))
-			      * sd->entity.num_pads, GFP_KERNEL);
-	if (fh->try_fmt == NULL)
+	fh->pad = kzalloc(sizeof(*fh->pad) * sd->entity.num_pads, GFP_KERNEL);
+	if (fh->pad == NULL)
 		return -ENOMEM;
-
-	fh->try_crop = (struct v4l2_rect *)
-		(fh->try_fmt + sd->entity.num_pads);
 #endif
 	return 0;
 }
@@ -50,9 +45,8 @@ static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd)
 static void subdev_fh_free(struct v4l2_subdev_fh *fh)
 {
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
-	kfree(fh->try_fmt);
-	fh->try_fmt = NULL;
-	fh->try_crop = NULL;
+	kfree(fh->pad);
+	fh->pad = NULL;
 #endif
 }
 
@@ -293,6 +287,26 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 		return v4l2_subdev_call(sd, pad, enum_frame_interval, subdev_fh,
 					fie);
 	}
+
+	case VIDIOC_SUBDEV_G_SELECTION: {
+		struct v4l2_subdev_selection *sel = arg;
+
+		if (sel->pad >= sd->entity.num_pads)
+			return -EINVAL;
+
+		return v4l2_subdev_call(
+			sd, pad, get_selection, subdev_fh, sel);
+	}
+
+	case VIDIOC_SUBDEV_S_SELECTION: {
+		struct v4l2_subdev_selection *sel = arg;
+
+		if (sel->pad >= sd->entity.num_pads)
+			return -EINVAL;
+
+		return v4l2_subdev_call(
+			sd, pad, set_selection, subdev_fh, sel);
+	}
 #endif
 	default:
 		return v4l2_subdev_call(sd, core, ioctl, cmd, arg);
diff --git a/include/linux/v4l2-subdev.h b/include/linux/v4l2-subdev.h
index ed29cbb..6c84390 100644
--- a/include/linux/v4l2-subdev.h
+++ b/include/linux/v4l2-subdev.h
@@ -123,6 +123,43 @@ struct v4l2_subdev_frame_interval_enum {
 	__u32 reserved[9];
 };
 
+#define V4L2_SUBDEV_SEL_FLAG_SIZE_GE			(1 << 0)
+#define V4L2_SUBDEV_SEL_FLAG_SIZE_LE			(1 << 1)
+#define V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG		(1 << 2)
+
+/* active cropping area */
+#define V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE			0x0000
+/* cropping bounds */
+#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS			0x0002
+/* current composing area */
+#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE		0x0100
+/* composing bounds */
+#define V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS		0x0102
+
+
+/**
+ * struct v4l2_subdev_selection - selection info
+ *
+ * @which: either V4L2_SUBDEV_FORMAT_ACTIVE or V4L2_SUBDEV_FORMAT_TRY
+ * @pad: pad number, as reported by the media API
+ * @target: selection target, used to choose one of possible rectangles
+ * @flags: constraint flags
+ * @r: coordinates of the selection window
+ * @reserved: for future use, rounds structure size to 64 bytes, set to zero
+ *
+ * Hardware may use multiple helper windows to process a video stream.
+ * The structure is used to exchange this selection areas between
+ * an application and a driver.
+ */
+struct v4l2_subdev_selection {
+	__u32 which;
+	__u32 pad;
+	__u32 target;
+	__u32 flags;
+	struct v4l2_rect r;
+	__u32 reserved[8];
+};
+
 #define VIDIOC_SUBDEV_G_FMT	_IOWR('V',  4, struct v4l2_subdev_format)
 #define VIDIOC_SUBDEV_S_FMT	_IOWR('V',  5, struct v4l2_subdev_format)
 #define VIDIOC_SUBDEV_G_FRAME_INTERVAL \
@@ -137,5 +174,9 @@ struct v4l2_subdev_frame_interval_enum {
 			_IOWR('V', 75, struct v4l2_subdev_frame_interval_enum)
 #define VIDIOC_SUBDEV_G_CROP	_IOWR('V', 59, struct v4l2_subdev_crop)
 #define VIDIOC_SUBDEV_S_CROP	_IOWR('V', 60, struct v4l2_subdev_crop)
+#define VIDIOC_SUBDEV_G_SELECTION \
+	_IOWR('V', 61, struct v4l2_subdev_selection)
+#define VIDIOC_SUBDEV_S_SELECTION \
+	_IOWR('V', 62, struct v4l2_subdev_selection)
 
 #endif
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index f0f3358..feab950 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -466,6 +466,10 @@ struct v4l2_subdev_pad_ops {
 		       struct v4l2_subdev_crop *crop);
 	int (*get_crop)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
 		       struct v4l2_subdev_crop *crop);
+	int (*get_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+			     struct v4l2_subdev_selection *sel);
+	int (*set_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+			     struct v4l2_subdev_selection *sel);
 };
 
 struct v4l2_subdev_ops {
@@ -549,8 +553,11 @@ struct v4l2_subdev {
 struct v4l2_subdev_fh {
 	struct v4l2_fh vfh;
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
-	struct v4l2_mbus_framefmt *try_fmt;
-	struct v4l2_rect *try_crop;
+	struct {
+		struct v4l2_mbus_framefmt try_fmt;
+		struct v4l2_rect try_crop;
+		struct v4l2_rect try_compose;
+	} *pad;
 #endif
 };
 
@@ -561,13 +568,19 @@ struct v4l2_subdev_fh {
 static inline struct v4l2_mbus_framefmt *
 v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
 {
-	return &fh->try_fmt[pad];
+	return &fh->pad[pad].try_fmt;
 }
 
 static inline struct v4l2_rect *
 v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
 {
-	return &fh->try_crop[pad];
+	return &fh->pad[pad].try_crop;
+}
+
+static inline struct v4l2_rect *
+v4l2_subdev_get_try_compose(struct v4l2_subdev_fh *fh, unsigned int pad)
+{
+	return &fh->pad[pad].try_compose;
 }
 #endif
 
-- 
1.7.2.5


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

* [PATCH v3 05/33] v4l: vdev_to_v4l2_subdev() should have return type "struct v4l2_subdev *"
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (3 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-21 14:37   ` Laurent Pinchart
  2012-02-20  1:56 ` [PATCH v3 06/33] v4l: Check pad number in get try pointer functions Sakari Ailus
                   ` (28 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

vdev_to_v4l2_subdev() should return struct v4l2_subdev *, not void *. Fix
this.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 include/media/v4l2-subdev.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index feab950..bcaf6b8 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -545,7 +545,7 @@ struct v4l2_subdev {
 #define media_entity_to_v4l2_subdev(ent) \
 	container_of(ent, struct v4l2_subdev, entity)
 #define vdev_to_v4l2_subdev(vdev) \
-	video_get_drvdata(vdev)
+	((struct v4l2_subdev *)video_get_drvdata(vdev))
 
 /*
  * Used for storing subdev information per file handle
-- 
1.7.2.5


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

* [PATCH v3 06/33] v4l: Check pad number in get try pointer functions
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (4 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 05/33] v4l: vdev_to_v4l2_subdev() should have return type "struct v4l2_subdev *" Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-21 14:42   ` Laurent Pinchart
  2012-02-20  1:56 ` [PATCH v3 07/33] v4l: Support s_crop and g_crop through s/g_selection Sakari Ailus
                   ` (27 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Unify functions to get try pointers and validate the pad number accessed by
the user.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 include/media/v4l2-subdev.h |   31 ++++++++++++++-----------------
 1 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index bcaf6b8..d48dae5 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -565,23 +565,20 @@ struct v4l2_subdev_fh {
 	container_of(fh, struct v4l2_subdev_fh, vfh)
 
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
-static inline struct v4l2_mbus_framefmt *
-v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
-{
-	return &fh->pad[pad].try_fmt;
-}
-
-static inline struct v4l2_rect *
-v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
-{
-	return &fh->pad[pad].try_crop;
-}
-
-static inline struct v4l2_rect *
-v4l2_subdev_get_try_compose(struct v4l2_subdev_fh *fh, unsigned int pad)
-{
-	return &fh->pad[pad].try_compose;
-}
+#define __V4L2_SUBDEV_MK_GET_TRY(rtype, fun_name, field_name)		\
+	static inline struct rtype *					\
+	v4l2_subdev_get_try_##fun_name(struct v4l2_subdev_fh *fh,	\
+				       unsigned int pad)		\
+	{								\
+		if (unlikely(pad > vdev_to_v4l2_subdev(			\
+				     fh->vfh.vdev->entity.num_pads)	\
+			return NULL;					\
+		return &fh->pad[pad].field_name;			\
+	}
+
+__V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, format, try_fmt)
+__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_compose)
+__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, compose, try_compose)
 #endif
 
 extern const struct v4l2_file_operations v4l2_subdev_fops;
-- 
1.7.2.5


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

* [PATCH v3 07/33] v4l: Support s_crop and g_crop through s/g_selection
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (5 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 06/33] v4l: Check pad number in get try pointer functions Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 08/33] v4l: Add subdev selections documentation: svg and dia files Sakari Ailus
                   ` (26 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Fall back to s_selection if s_crop isn't implemented by a driver. Same for
g_selection / g_crop.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/video/v4l2-subdev.c |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/drivers/media/video/v4l2-subdev.c b/drivers/media/video/v4l2-subdev.c
index 30c7fd9..ef27144 100644
--- a/drivers/media/video/v4l2-subdev.c
+++ b/drivers/media/video/v4l2-subdev.c
@@ -228,6 +228,8 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 
 	case VIDIOC_SUBDEV_G_CROP: {
 		struct v4l2_subdev_crop *crop = arg;
+		struct v4l2_subdev_selection sel;
+		int rval;
 
 		if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
 		    crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
@@ -236,11 +238,27 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 		if (crop->pad >= sd->entity.num_pads)
 			return -EINVAL;
 
-		return v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
+		rval = v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
+		if (rval != -ENOIOCTLCMD)
+			return rval;
+
+		memset(&sel, 0, sizeof(sel));
+		sel.which = crop->which;
+		sel.pad = crop->pad;
+		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
+
+		rval = v4l2_subdev_call(
+			sd, pad, get_selection, subdev_fh, &sel);
+
+		crop->rect = sel.r;
+
+		return rval;
 	}
 
 	case VIDIOC_SUBDEV_S_CROP: {
 		struct v4l2_subdev_crop *crop = arg;
+		struct v4l2_subdev_selection sel;
+		int rval;
 
 		if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
 		    crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
@@ -249,7 +267,22 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 		if (crop->pad >= sd->entity.num_pads)
 			return -EINVAL;
 
-		return v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
+		rval = v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
+		if (rval != -ENOIOCTLCMD)
+			return rval;
+
+		memset(&sel, 0, sizeof(sel));
+		sel.which = crop->which;
+		sel.pad = crop->pad;
+		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
+		sel.r = crop->rect;
+
+		rval = v4l2_subdev_call(
+			sd, pad, set_selection, subdev_fh, &sel);
+
+		crop->rect = sel.r;
+
+		return rval;
 	}
 
 	case VIDIOC_SUBDEV_ENUM_MBUS_CODE: {
-- 
1.7.2.5


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

* [PATCH v3 08/33] v4l: Add subdev selections documentation: svg and dia files
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (6 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 07/33] v4l: Support s_crop and g_crop through s/g_selection Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-21 15:00   ` Laurent Pinchart
  2012-02-20  1:56 ` [PATCH v3 09/33] v4l: Add subdev selections documentation Sakari Ailus
                   ` (25 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Add svga and dia files for V4L2 subdev selections documentation.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 .../media/v4l/subdev-image-processing-crop.dia     |  719 ++++++++
 .../media/v4l/subdev-image-processing-crop.svg     |   71 +
 .../media/v4l/subdev-image-processing-full.dia     | 1888 ++++++++++++++++++++
 .../media/v4l/subdev-image-processing-full.svg     |  172 ++
 ...ubdev-image-processing-scaling-multi-source.dia | 1407 +++++++++++++++
 ...ubdev-image-processing-scaling-multi-source.svg |  130 ++
 6 files changed, 4387 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/DocBook/media/v4l/subdev-image-processing-crop.dia
 create mode 100644 Documentation/DocBook/media/v4l/subdev-image-processing-crop.svg
 create mode 100644 Documentation/DocBook/media/v4l/subdev-image-processing-full.dia
 create mode 100644 Documentation/DocBook/media/v4l/subdev-image-processing-full.svg
 create mode 100644 Documentation/DocBook/media/v4l/subdev-image-processing-scaling-multi-source.dia
 create mode 100644 Documentation/DocBook/media/v4l/subdev-image-processing-scaling-multi-source.svg

diff --git a/Documentation/DocBook/media/v4l/subdev-image-processing-crop.dia b/Documentation/DocBook/media/v4l/subdev-image-processing-crop.dia
new file mode 100644
index 0000000..5c467ec
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/subdev-image-processing-crop.dia
@@ -0,0 +1,719 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<dia:diagram xmlns:dia="http://www.lysator.liu.se/~alla/dia/">
+  <dia:diagramdata>
+    <dia:attribute name="background">
+      <dia:color val="#ffffff"/>
+    </dia:attribute>
+    <dia:attribute name="pagebreak">
+      <dia:color val="#000099"/>
+    </dia:attribute>
+    <dia:attribute name="paper">
+      <dia:composite type="paper">
+        <dia:attribute name="name">
+          <dia:string>#A4#</dia:string>
+        </dia:attribute>
+        <dia:attribute name="tmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="bmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="lmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="rmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="is_portrait">
+          <dia:boolean val="false"/>
+        </dia:attribute>
+        <dia:attribute name="scaling">
+          <dia:real val="0.49000000953674316"/>
+        </dia:attribute>
+        <dia:attribute name="fitto">
+          <dia:boolean val="false"/>
+        </dia:attribute>
+      </dia:composite>
+    </dia:attribute>
+    <dia:attribute name="grid">
+      <dia:composite type="grid">
+        <dia:attribute name="width_x">
+          <dia:real val="1"/>
+        </dia:attribute>
+        <dia:attribute name="width_y">
+          <dia:real val="1"/>
+        </dia:attribute>
+        <dia:attribute name="visible_x">
+          <dia:int val="1"/>
+        </dia:attribute>
+        <dia:attribute name="visible_y">
+          <dia:int val="1"/>
+        </dia:attribute>
+        <dia:composite type="color"/>
+      </dia:composite>
+    </dia:attribute>
+    <dia:attribute name="color">
+      <dia:color val="#d8e5e5"/>
+    </dia:attribute>
+    <dia:attribute name="guides">
+      <dia:composite type="guides">
+        <dia:attribute name="hguides"/>
+        <dia:attribute name="vguides"/>
+      </dia:composite>
+    </dia:attribute>
+  </dia:diagramdata>
+  <dia:layer name="Background" visible="true" active="true">
+    <dia:object type="Standard - Box" version="0" id="O0">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-0.4,6.5"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-0.45,6.45;23.1387,16.2"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="-0.4,6.5"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="23.48871579904775"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="9.6500000000000004"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O1">
+      <dia:attribute name="obj_pos">
+        <dia:point val="0.225,9.45"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="0.175,9.4;8.225,14.7"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="0.225,9.45"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="7.9499999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="5.1999999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a52a2a"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O2">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.625,11.35"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.575,11.3;15.375,15.25"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="10.625,11.35"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="4.6999999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.8499999999999979"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#0000ff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O3">
+      <dia:attribute name="obj_pos">
+        <dia:point val="2.915,9.75"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.865,9.7;7.665,13.65"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="2.915,9.75"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="4.6999999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.8499999999999979"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#0000ff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="4"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O4">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.625,15.2"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.85588,13.5409;10.6841,15.2591"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="10.625,15.2"/>
+        <dia:point val="2.915,13.6"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O2" connection="5"/>
+        <dia:connection handle="1" to="O3" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O5">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.625,11.35"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.85588,9.69088;10.6841,11.4091"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="10.625,11.35"/>
+        <dia:point val="2.915,9.75"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O2" connection="0"/>
+        <dia:connection handle="1" to="O3" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O6">
+      <dia:attribute name="obj_pos">
+        <dia:point val="15.325,15.2"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="7.55588,13.5409;15.3841,15.2591"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="15.325,15.2"/>
+        <dia:point val="7.615,13.6"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O2" connection="7"/>
+        <dia:connection handle="1" to="O3" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O7">
+      <dia:attribute name="obj_pos">
+        <dia:point val="15.325,11.35"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="7.55588,9.69088;15.3841,11.4091"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="15.325,11.35"/>
+        <dia:point val="7.615,9.75"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O2" connection="2"/>
+        <dia:connection handle="1" to="O3" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O8">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.625,7.65"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.625,7.055;13.5025,9.4025"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#sink
+crop
+selection#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="10.625,7.65"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#0000ff"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O9">
+      <dia:attribute name="obj_pos">
+        <dia:point val="1.475,7.9"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="1.475,7.305;1.475,8.0525"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>##</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="1.475,7.9"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O10">
+      <dia:attribute name="obj_pos">
+        <dia:point val="0.426918,7.89569"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="0.426918,7.30069;3.90942,8.84819"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#sink media
+bus format#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="0.426918,7.89569"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#a52a2a"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O11">
+      <dia:attribute name="obj_pos">
+        <dia:point val="17.4887,7.75"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="17.4887,7.155;21.8112,8.7025"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#source media
+bus format#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="17.4887,7.75"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#8b6914"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O12">
+      <dia:attribute name="obj_pos">
+        <dia:point val="17.5244,9.5417"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="17.4744,9.4917;22.2387,13.35"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="17.5244,9.5417"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="4.6643157990477508"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.758300000000002"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#8b6914"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O13">
+      <dia:attribute name="obj_pos">
+        <dia:point val="17.5244,13.3"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.5635,13.2385;17.5859,15.2615"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="17.5244,13.3"/>
+        <dia:point val="10.625,15.2"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O12" connection="5"/>
+        <dia:connection handle="1" to="O2" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O14">
+      <dia:attribute name="obj_pos">
+        <dia:point val="17.5244,9.5417"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.564,9.48066;17.5854,11.411"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="17.5244,9.5417"/>
+        <dia:point val="10.625,11.35"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O12" connection="0"/>
+        <dia:connection handle="1" to="O2" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O15">
+      <dia:attribute name="obj_pos">
+        <dia:point val="22.1887,13.3"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="15.2635,13.2385;22.2502,15.2615"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="22.1887,13.3"/>
+        <dia:point val="15.325,15.2"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O12" connection="7"/>
+        <dia:connection handle="1" to="O2" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O16">
+      <dia:attribute name="obj_pos">
+        <dia:point val="22.1887,9.5417"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="15.2639,9.48061;22.2498,11.4111"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="22.1887,9.5417"/>
+        <dia:point val="15.325,11.35"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O12" connection="2"/>
+        <dia:connection handle="1" to="O2" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Geometric - Perfect Circle" version="1" id="O17">
+      <dia:attribute name="obj_pos">
+        <dia:point val="23.23,10.5742"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="23.18,10.5242;24.13,11.4742"/>
+      </dia:attribute>
+      <dia:attribute name="meta">
+        <dia:composite type="dict"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="23.23,10.5742"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="line_width">
+        <dia:real val="0.10000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="line_colour">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_colour">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="0"/>
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="flip_horizontal">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="flip_vertical">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="subscale">
+        <dia:real val="1"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O18">
+      <dia:attribute name="obj_pos">
+        <dia:point val="24.08,10.9992"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="24.03,10.6388;32.4953,11.3624"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="24.08,10.9992"/>
+        <dia:point val="32.3835,11.0007"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow">
+        <dia:enum val="22"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_length">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_width">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O17" connection="3"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O19">
+      <dia:attribute name="obj_pos">
+        <dia:point val="25.3454,10.49"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="25.3454,9.895;29.9904,10.6425"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#pad 1 (source)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="25.3454,10.49"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Geometric - Perfect Circle" version="1" id="O20">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-1.44491,11.6506"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-1.49491,11.6006;-0.544912,12.5506"/>
+      </dia:attribute>
+      <dia:attribute name="meta">
+        <dia:composite type="dict"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="-1.44491,11.6506"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="line_width">
+        <dia:real val="0.10000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="line_colour">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_colour">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="0"/>
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="flip_horizontal">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="flip_vertical">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="subscale">
+        <dia:real val="1"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O21">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-9.61991,12.09"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-9.67,11.7149;-1.33311,12.4385"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="-9.61991,12.09"/>
+        <dia:point val="-1.44491,12.0756"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow">
+        <dia:enum val="22"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_length">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_width">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="1" to="O20" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O22">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-7.39291,11.49"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-7.39291,10.895;-3.58791,11.6425"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#pad 0 (sink)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="-7.39291,11.49"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+  </dia:layer>
+</dia:diagram>
diff --git a/Documentation/DocBook/media/v4l/subdev-image-processing-crop.svg b/Documentation/DocBook/media/v4l/subdev-image-processing-crop.svg
new file mode 100644
index 0000000..7faee4d
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/subdev-image-processing-crop.svg
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
+<svg width="43cm" height="10cm" viewBox="-194 128 844 196" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+  <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x="-8" y="130" width="469.774" height="193"/>
+  <g>
+    <rect style="fill: #ffffff" x="4.5" y="189" width="159" height="104"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #a52a2a" x="4.5" y="189" width="159" height="104"/>
+  </g>
+  <g>
+    <rect style="fill: #ffffff" x="212.5" y="227" width="94" height="77"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #0000ff" x="212.5" y="227" width="94" height="77"/>
+  </g>
+  <g>
+    <rect style="fill: #ffffff" x="58.3" y="195" width="94" height="77"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke-dasharray: 4; stroke: #0000ff" x="58.3" y="195" width="94" height="77"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="212.5" y1="304" x2="58.3" y2="272"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="212.5" y1="227" x2="58.3" y2="195"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="306.5" y1="304" x2="152.3" y2="272"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="306.5" y1="227" x2="152.3" y2="195"/>
+  <text style="fill: #0000ff;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="212.5" y="153">
+    <tspan x="212.5" y="153">sink</tspan>
+    <tspan x="212.5" y="169">crop</tspan>
+    <tspan x="212.5" y="185">selection</tspan>
+  </text>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="29.5" y="158">
+    <tspan x="29.5" y="158"></tspan>
+  </text>
+  <text style="fill: #a52a2a;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="8.53836" y="157.914">
+    <tspan x="8.53836" y="157.914">sink media</tspan>
+    <tspan x="8.53836" y="173.914">bus format</tspan>
+  </text>
+  <text style="fill: #8b6914;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="349.774" y="155">
+    <tspan x="349.774" y="155">source media</tspan>
+    <tspan x="349.774" y="171">bus format</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="350.488" y="190.834" width="93.2863" height="75.166"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #8b6914" x="350.488" y="190.834" width="93.2863" height="75.166"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="350.488" y1="266" x2="212.5" y2="304"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="350.488" y1="190.834" x2="212.5" y2="227"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="443.774" y1="266" x2="306.5" y2="304"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="443.774" y1="190.834" x2="306.5" y2="227"/>
+  <g>
+    <ellipse style="fill: #ffffff" cx="473.1" cy="219.984" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="473.1" cy="219.984" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="473.1" cy="219.984" rx="8.5" ry="8.5"/>
+  </g>
+  <g>
+    <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x1="481.6" y1="219.984" x2="637.934" y2="220.012"/>
+    <polygon style="fill: #000000" points="645.434,220.014 635.433,225.012 637.934,220.012 635.435,215.012 "/>
+    <polygon style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" points="645.434,220.014 635.433,225.012 637.934,220.012 635.435,215.012 "/>
+  </g>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="506.908" y="209.8">
+    <tspan x="506.908" y="209.8">pad 1 (source)</tspan>
+  </text>
+  <g>
+    <ellipse style="fill: #ffffff" cx="-20.3982" cy="241.512" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="-20.3982" cy="241.512" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="-20.3982" cy="241.512" rx="8.5" ry="8.5"/>
+  </g>
+  <g>
+    <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x1="-192.398" y1="241.8" x2="-38.6343" y2="241.529"/>
+    <polygon style="fill: #000000" points="-31.1343,241.516 -41.1254,246.534 -38.6343,241.529 -41.1431,236.534 "/>
+    <polygon style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" points="-31.1343,241.516 -41.1254,246.534 -38.6343,241.529 -41.1431,236.534 "/>
+  </g>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="-147.858" y="229.8">
+    <tspan x="-147.858" y="229.8">pad 0 (sink)</tspan>
+  </text>
+</svg>
diff --git a/Documentation/DocBook/media/v4l/subdev-image-processing-full.dia b/Documentation/DocBook/media/v4l/subdev-image-processing-full.dia
new file mode 100644
index 0000000..c228679
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/subdev-image-processing-full.dia
@@ -0,0 +1,1888 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<dia:diagram xmlns:dia="http://www.lysator.liu.se/~alla/dia/">
+  <dia:diagramdata>
+    <dia:attribute name="background">
+      <dia:color val="#ffffff"/>
+    </dia:attribute>
+    <dia:attribute name="pagebreak">
+      <dia:color val="#000099"/>
+    </dia:attribute>
+    <dia:attribute name="paper">
+      <dia:composite type="paper">
+        <dia:attribute name="name">
+          <dia:string>#A4#</dia:string>
+        </dia:attribute>
+        <dia:attribute name="tmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="bmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="lmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="rmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="is_portrait">
+          <dia:boolean val="false"/>
+        </dia:attribute>
+        <dia:attribute name="scaling">
+          <dia:real val="0.49000000953674316"/>
+        </dia:attribute>
+        <dia:attribute name="fitto">
+          <dia:boolean val="false"/>
+        </dia:attribute>
+      </dia:composite>
+    </dia:attribute>
+    <dia:attribute name="grid">
+      <dia:composite type="grid">
+        <dia:attribute name="width_x">
+          <dia:real val="1"/>
+        </dia:attribute>
+        <dia:attribute name="width_y">
+          <dia:real val="1"/>
+        </dia:attribute>
+        <dia:attribute name="visible_x">
+          <dia:int val="1"/>
+        </dia:attribute>
+        <dia:attribute name="visible_y">
+          <dia:int val="1"/>
+        </dia:attribute>
+        <dia:composite type="color"/>
+      </dia:composite>
+    </dia:attribute>
+    <dia:attribute name="color">
+      <dia:color val="#d8e5e5"/>
+    </dia:attribute>
+    <dia:attribute name="guides">
+      <dia:composite type="guides">
+        <dia:attribute name="hguides"/>
+        <dia:attribute name="vguides"/>
+      </dia:composite>
+    </dia:attribute>
+  </dia:diagramdata>
+  <dia:layer name="Background" visible="true" active="true">
+    <dia:object type="Standard - Box" version="0" id="O0">
+      <dia:attribute name="obj_pos">
+        <dia:point val="15.945,6.45"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="15.895,6.4;26.4,18.95"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="15.945,6.45"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="10.404999999254942"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="12.449999999999992"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#ff765a"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O1">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-0.1,3.65"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-0.15,3.6;40.25,20.85"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="-0.1,3.65"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="40.300000000000004"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="17.149999999999999"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Geometric - Perfect Circle" version="1" id="O2">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-1.05,7.9106"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-1.1,7.8606;-0.15,8.8106"/>
+      </dia:attribute>
+      <dia:attribute name="meta">
+        <dia:composite type="dict"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="-1.05,7.9106"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="line_width">
+        <dia:real val="0.10000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="line_colour">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_colour">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="0"/>
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="flip_horizontal">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="flip_vertical">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="subscale">
+        <dia:real val="1"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Geometric - Perfect Circle" version="1" id="O3">
+      <dia:attribute name="obj_pos">
+        <dia:point val="40.3366,9.8342"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="40.2866,9.7842;41.2366,10.7342"/>
+      </dia:attribute>
+      <dia:attribute name="meta">
+        <dia:composite type="dict"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="40.3366,9.8342"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="line_width">
+        <dia:real val="0.10000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="line_colour">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_colour">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="0"/>
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="flip_horizontal">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="flip_vertical">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="subscale">
+        <dia:real val="1"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O4">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-9.225,8.35"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-9.27509,7.97487;-0.938197,8.69848"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="-9.225,8.35"/>
+        <dia:point val="-1.05,8.3356"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow">
+        <dia:enum val="22"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_length">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_width">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="1" to="O2" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O5">
+      <dia:attribute name="obj_pos">
+        <dia:point val="41.1866,10.2592"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="41.1366,9.89879;49.6019,10.6224"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="41.1866,10.2592"/>
+        <dia:point val="49.4901,10.2607"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow">
+        <dia:enum val="22"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_length">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_width">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O3" connection="3"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O6">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-6.998,7.75"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-6.998,7.155;-3.193,7.9025"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#pad 0 (sink)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="-6.998,7.75"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O7">
+      <dia:attribute name="obj_pos">
+        <dia:point val="42.452,9.75"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="42.452,9.155;47.097,9.9025"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#pad 2 (source)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="42.452,9.75"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O8">
+      <dia:attribute name="obj_pos">
+        <dia:point val="0.275,6"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="0.225,5.95;8.275,11.25"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="0.275,6"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="7.9499999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="5.1999999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a52a2a"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O9">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.725,7"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.675,6.95;15.475,10.9"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="10.725,7"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="4.6999999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.8499999999999979"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#0000ff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O10">
+      <dia:attribute name="obj_pos">
+        <dia:point val="2.965,6.3"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.915,6.25;7.715,10.2"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="2.965,6.3"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="4.6999999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.8499999999999979"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#0000ff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="4"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O11">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.725,10.85"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.91071,10.0957;10.7793,10.9043"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="10.725,10.85"/>
+        <dia:point val="2.965,10.15"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O9" connection="5"/>
+        <dia:connection handle="1" to="O10" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O12">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.725,7"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.91071,6.24571;10.7793,7.05429"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="10.725,7"/>
+        <dia:point val="2.965,6.3"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O9" connection="0"/>
+        <dia:connection handle="1" to="O10" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O13">
+      <dia:attribute name="obj_pos">
+        <dia:point val="15.425,10.85"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="7.61071,10.0957;15.4793,10.9043"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="15.425,10.85"/>
+        <dia:point val="7.665,10.15"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O9" connection="7"/>
+        <dia:connection handle="1" to="O10" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O14">
+      <dia:attribute name="obj_pos">
+        <dia:point val="15.425,7"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="7.61071,6.24571;15.4793,7.05429"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="15.425,7"/>
+        <dia:point val="7.665,6.3"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O9" connection="2"/>
+        <dia:connection handle="1" to="O10" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O15">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.675,4.2"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.675,3.605;13.5525,5.9525"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#sink
+crop
+selection#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="10.675,4.2"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#0000ff"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O16">
+      <dia:attribute name="obj_pos">
+        <dia:point val="1.525,4.45"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="1.525,3.855;1.525,4.6025"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>##</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="1.525,4.45"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O17">
+      <dia:attribute name="obj_pos">
+        <dia:point val="0.476918,4.44569"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="0.476918,3.85069;3.95942,5.39819"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#sink media
+bus format#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="0.476918,4.44569"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#a52a2a"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O18">
+      <dia:attribute name="obj_pos">
+        <dia:point val="16.6822,9.28251"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="16.6322,9.23251;24.9922,17.9564"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="16.6822,9.28251"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="8.2600228398861297"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="8.6238900617957164"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#00ff00"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O19">
+      <dia:attribute name="obj_pos">
+        <dia:point val="16.6822,17.9064"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.6545,10.7795;16.7527,17.9769"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="16.6822,17.9064"/>
+        <dia:point val="10.725,10.85"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O18" connection="5"/>
+        <dia:connection handle="1" to="O9" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O20">
+      <dia:attribute name="obj_pos">
+        <dia:point val="16.6822,9.28251"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.6604,6.93542;16.7468,9.34709"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="16.6822,9.28251"/>
+        <dia:point val="10.725,7"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O18" connection="0"/>
+        <dia:connection handle="1" to="O9" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O21">
+      <dia:attribute name="obj_pos">
+        <dia:point val="24.9422,17.9064"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="15.3551,10.7801;25.0121,17.9763"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="24.9422,17.9064"/>
+        <dia:point val="15.425,10.85"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O18" connection="7"/>
+        <dia:connection handle="1" to="O9" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O22">
+      <dia:attribute name="obj_pos">
+        <dia:point val="24.9422,9.28251"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="15.3647,6.93972;25.0025,9.34279"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="24.9422,9.28251"/>
+        <dia:point val="15.425,7"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O18" connection="2"/>
+        <dia:connection handle="1" to="O9" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O23">
+      <dia:attribute name="obj_pos">
+        <dia:point val="16.7352,7.47209"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="16.7352,6.87709;22.5602,8.42459"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#sink compose
+selection (scaling)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="16.7352,7.47209"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#00ff00"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O24">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.0661,6.77825"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.0161,6.72825;32.1254,10.4009"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="27.0661,6.77825"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.009308462554376"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.5726155970598077"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a020f0"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O25">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.0661,10.3509"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="19.2637,10.2825;27.1344,14.8959"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="27.0661,10.3509"/>
+        <dia:point val="19.332,14.8276"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O24" connection="5"/>
+        <dia:connection handle="1" to="O53" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O26">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.0661,6.77825"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="19.2637,6.70993;27.1344,11.3233"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="27.0661,6.77825"/>
+        <dia:point val="19.332,11.255"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O24" connection="0"/>
+        <dia:connection handle="1" to="O53" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O27">
+      <dia:attribute name="obj_pos">
+        <dia:point val="32.0754,10.3509"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="24.273,10.2825;32.1437,14.8959"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="32.0754,10.3509"/>
+        <dia:point val="24.3413,14.8276"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O24" connection="7"/>
+        <dia:connection handle="1" to="O53" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O28">
+      <dia:attribute name="obj_pos">
+        <dia:point val="32.0754,6.77825"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="24.273,6.70993;32.1437,11.3233"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="32.0754,6.77825"/>
+        <dia:point val="24.3413,11.255"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O24" connection="2"/>
+        <dia:connection handle="1" to="O53" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O29">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.0661,4.87209"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.0661,4.27709;29.9436,6.62459"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#source
+crop
+selection#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="27.0661,4.87209"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#a020f0"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O30">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.475,5.2564"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="34.475,4.6614;38.7975,6.2089"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#source media
+bus format#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="34.475,5.2564"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#8b6914"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O31">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.4244,8.6917"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="34.3744,8.6417;39.4837,12.3143"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="34.4244,8.6917"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.009308462554376"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.5726155970598077"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#8b6914"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O32">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.4244,12.2643"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.0051,10.2899;34.4854,12.3253"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="34.4244,12.2643"/>
+        <dia:point val="27.0661,10.3509"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O31" connection="5"/>
+        <dia:connection handle="1" to="O24" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O33">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.4244,8.6917"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.0051,6.71728;34.4854,8.75267"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="34.4244,8.6917"/>
+        <dia:point val="27.0661,6.77825"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O31" connection="0"/>
+        <dia:connection handle="1" to="O24" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O34">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.4337,12.2643"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="32.0144,10.2899;39.4947,12.3253"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="39.4337,12.2643"/>
+        <dia:point val="32.0754,10.3509"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O31" connection="7"/>
+        <dia:connection handle="1" to="O24" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O35">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.4337,8.6917"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="32.0144,6.71728;39.4947,8.75267"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="39.4337,8.6917"/>
+        <dia:point val="32.0754,6.77825"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O31" connection="2"/>
+        <dia:connection handle="1" to="O24" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O36">
+      <dia:attribute name="obj_pos">
+        <dia:point val="16.25,5.15"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="16.25,4.555;21.6975,6.1025"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#compose bounds
+selection#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="16.25,5.15"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#ff765a"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Geometric - Perfect Circle" version="1" id="O37">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-1.02991,16.6506"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-1.07991,16.6006;-0.129912,17.5506"/>
+      </dia:attribute>
+      <dia:attribute name="meta">
+        <dia:composite type="dict"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="-1.02991,16.6506"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="line_width">
+        <dia:real val="0.10000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="line_colour">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_colour">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="0"/>
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="flip_horizontal">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="flip_vertical">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="subscale">
+        <dia:real val="1"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O38">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-9.20491,17.09"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-9.255,16.7149;-0.918109,17.4385"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="-9.20491,17.09"/>
+        <dia:point val="-1.02991,17.0756"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow">
+        <dia:enum val="22"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_length">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_width">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="1" to="O37" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O39">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-6.95,16.45"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-6.95,15.8363;-3.12631,16.6399"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#pad 1 (sink)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="-6.95,16.45"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O40">
+      <dia:attribute name="obj_pos">
+        <dia:point val="0.390412,14.64"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="0.340412,14.59;6.045,18.8"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="0.390412,14.64"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.604587512785236"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="4.1099999999999994"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a52a2a"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O41">
+      <dia:attribute name="obj_pos">
+        <dia:point val="11.145,16.39"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="11.095,16.34;14.1,18.95"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="11.145,16.39"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="2.904999999254942"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="2.5100000000000016"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#0000ff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O42">
+      <dia:attribute name="obj_pos">
+        <dia:point val="2.635,15.69"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.585,15.64;5.65,18.45"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="2.635,15.69"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="2.9649999992549416"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="2.7100000000000009"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#0000ff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="4"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O43">
+      <dia:attribute name="obj_pos">
+        <dia:point val="11.145,18.9"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.58215,18.3472;11.1978,18.9528"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="11.145,18.9"/>
+        <dia:point val="2.635,18.4"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O41" connection="5"/>
+        <dia:connection handle="1" to="O42" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O44">
+      <dia:attribute name="obj_pos">
+        <dia:point val="11.145,16.39"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.58107,15.6361;11.1989,16.4439"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="11.145,16.39"/>
+        <dia:point val="2.635,15.69"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O41" connection="0"/>
+        <dia:connection handle="1" to="O42" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O45">
+      <dia:attribute name="obj_pos">
+        <dia:point val="14.05,18.9"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="5.54713,18.3471;14.1029,18.9529"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="14.05,18.9"/>
+        <dia:point val="5.6,18.4"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O41" connection="7"/>
+        <dia:connection handle="1" to="O42" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O46">
+      <dia:attribute name="obj_pos">
+        <dia:point val="14.05,16.39"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="5.54604,15.636;14.104,16.444"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="14.05,16.39"/>
+        <dia:point val="5.6,15.69"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O41" connection="2"/>
+        <dia:connection handle="1" to="O42" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O47">
+      <dia:attribute name="obj_pos">
+        <dia:point val="1.595,12.99"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="1.595,12.395;1.595,13.1425"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>##</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="1.595,12.99"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O48">
+      <dia:attribute name="obj_pos">
+        <dia:point val="17.945,12.595"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="11.077,12.527;18.013,16.458"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="17.945,12.595"/>
+        <dia:point val="11.145,16.39"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O52" connection="0"/>
+        <dia:connection handle="1" to="O41" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O49">
+      <dia:attribute name="obj_pos">
+        <dia:point val="17.945,15.8"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="11.0788,15.7338;18.0112,18.9662"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="17.945,15.8"/>
+        <dia:point val="11.145,18.9"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O52" connection="5"/>
+        <dia:connection handle="1" to="O41" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O50">
+      <dia:attribute name="obj_pos">
+        <dia:point val="21.7,15.8"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="13.9849,15.7349;21.7651,18.9651"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="21.7,15.8"/>
+        <dia:point val="14.05,18.9"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O52" connection="7"/>
+        <dia:connection handle="1" to="O41" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O51">
+      <dia:attribute name="obj_pos">
+        <dia:point val="21.7,12.595"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="13.983,12.528;21.767,16.457"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="21.7,12.595"/>
+        <dia:point val="14.05,16.39"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O52" connection="2"/>
+        <dia:connection handle="1" to="O41" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O52">
+      <dia:attribute name="obj_pos">
+        <dia:point val="17.945,12.595"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="17.895,12.545;21.75,15.85"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="17.945,12.595"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="3.7549999992549452"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.2049999992549427"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#00ff00"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O53">
+      <dia:attribute name="obj_pos">
+        <dia:point val="19.332,11.255"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="19.282,11.205;24.3913,14.8776"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="19.332,11.255"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.009308462554376"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.5726155970598077"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a020f0"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="4"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O54">
+      <dia:attribute name="obj_pos">
+        <dia:point val="29.9131,13.2733"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="29.8631,13.2233;32.252,15.25"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="29.9131,13.2733"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="2.2888999992549444"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="1.9267499992549393"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a020f0"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O55">
+      <dia:attribute name="obj_pos">
+        <dia:point val="29.9131,15.2"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="20.1901,15.1431;29.97,16.7069"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="29.9131,15.2"/>
+        <dia:point val="20.247,16.65"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O54" connection="5"/>
+        <dia:connection handle="1" to="O64" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O56">
+      <dia:attribute name="obj_pos">
+        <dia:point val="29.9131,13.2733"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="20.1903,13.2165;29.9698,14.7517"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="29.9131,13.2733"/>
+        <dia:point val="20.247,14.695"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O54" connection="0"/>
+        <dia:connection handle="1" to="O64" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O57">
+      <dia:attribute name="obj_pos">
+        <dia:point val="32.202,15.2"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="22.5951,15.1431;32.2589,16.7069"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="32.202,15.2"/>
+        <dia:point val="22.652,16.65"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O54" connection="7"/>
+        <dia:connection handle="1" to="O64" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O58">
+      <dia:attribute name="obj_pos">
+        <dia:point val="32.202,13.2733"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="22.5952,13.2164;32.2588,14.7518"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="32.202,13.2733"/>
+        <dia:point val="22.652,14.695"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O54" connection="2"/>
+        <dia:connection handle="1" to="O64" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O59">
+      <dia:attribute name="obj_pos">
+        <dia:point val="36.9214,16.3367"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="36.8714,16.2867;39.302,18.35"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="36.9214,16.3367"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="2.3305999992549431"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="1.9632999992549358"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#8b6914"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O60">
+      <dia:attribute name="obj_pos">
+        <dia:point val="36.9214,18.3"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="29.8472,15.134;36.9874,18.366"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="36.9214,18.3"/>
+        <dia:point val="29.9131,15.2"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O59" connection="5"/>
+        <dia:connection handle="1" to="O54" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O61">
+      <dia:attribute name="obj_pos">
+        <dia:point val="36.9214,16.3367"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="29.8473,13.2074;36.9872,16.4025"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="36.9214,16.3367"/>
+        <dia:point val="29.9131,13.2733"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O59" connection="0"/>
+        <dia:connection handle="1" to="O54" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O62">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.252,18.3"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="32.1361,15.1341;39.3179,18.3659"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="39.252,18.3"/>
+        <dia:point val="32.202,15.2"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O59" connection="7"/>
+        <dia:connection handle="1" to="O54" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O63">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.252,16.3367"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="32.1362,13.2075;39.3178,16.4025"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="39.252,16.3367"/>
+        <dia:point val="32.202,13.2733"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O59" connection="2"/>
+        <dia:connection handle="1" to="O54" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O64">
+      <dia:attribute name="obj_pos">
+        <dia:point val="20.247,14.695"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="20.197,14.645;22.702,16.7"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="20.247,14.695"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="2.4049999992549402"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="1.9549999992549409"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a020f0"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="4"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Geometric - Perfect Circle" version="1" id="O65">
+      <dia:attribute name="obj_pos">
+        <dia:point val="40.347,16.7742"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="40.297,16.7242;41.247,17.6742"/>
+      </dia:attribute>
+      <dia:attribute name="meta">
+        <dia:composite type="dict"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="40.347,16.7742"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="line_width">
+        <dia:real val="0.10000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="line_colour">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_colour">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="0"/>
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="flip_horizontal">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="flip_vertical">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="subscale">
+        <dia:real val="1"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O66">
+      <dia:attribute name="obj_pos">
+        <dia:point val="41.197,17.1992"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="41.147,16.8388;49.6123,17.5624"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="41.197,17.1992"/>
+        <dia:point val="49.5005,17.2007"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow">
+        <dia:enum val="22"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_length">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_width">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O65" connection="3"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O67">
+      <dia:attribute name="obj_pos">
+        <dia:point val="42.4624,16.69"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="42.4624,16.0763;47.1261,16.8799"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#pad 3 (source)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="42.4624,16.69"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+  </dia:layer>
+</dia:diagram>
diff --git a/Documentation/DocBook/media/v4l/subdev-image-processing-full.svg b/Documentation/DocBook/media/v4l/subdev-image-processing-full.svg
new file mode 100644
index 0000000..5170f10
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/subdev-image-processing-full.svg
@@ -0,0 +1,172 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
+<svg width="59cm" height="18cm" viewBox="-186 71 1178 346" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+  <g>
+    <rect style="fill: #ffffff" x="318.9" y="129" width="208.1" height="249"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #ff765a" x="318.9" y="129" width="208.1" height="249"/>
+  </g>
+  <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x="-2" y="73" width="806" height="343"/>
+  <g>
+    <ellipse style="fill: #ffffff" cx="-12.5" cy="166.712" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="-12.5" cy="166.712" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="-12.5" cy="166.712" rx="8.5" ry="8.5"/>
+  </g>
+  <g>
+    <ellipse style="fill: #ffffff" cx="815.232" cy="205.184" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="815.232" cy="205.184" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="815.232" cy="205.184" rx="8.5" ry="8.5"/>
+  </g>
+  <g>
+    <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x1="-184.5" y1="167" x2="-30.7361" y2="166.729"/>
+    <polygon style="fill: #000000" points="-23.2361,166.716 -33.2272,171.734 -30.7361,166.729 -33.2449,161.734 "/>
+    <polygon style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" points="-23.2361,166.716 -33.2272,171.734 -30.7361,166.729 -33.2449,161.734 "/>
+  </g>
+  <g>
+    <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x1="823.732" y1="205.184" x2="980.066" y2="205.212"/>
+    <polygon style="fill: #000000" points="987.566,205.214 977.565,210.212 980.066,205.212 977.567,200.212 "/>
+    <polygon style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" points="987.566,205.214 977.565,210.212 980.066,205.212 977.567,200.212 "/>
+  </g>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="-139.96" y="155">
+    <tspan x="-139.96" y="155">pad 0 (sink)</tspan>
+  </text>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="849.04" y="195">
+    <tspan x="849.04" y="195">pad 2 (source)</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="5.5" y="120" width="159" height="104"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #a52a2a" x="5.5" y="120" width="159" height="104"/>
+  </g>
+  <g>
+    <rect style="fill: #ffffff" x="214.5" y="140" width="94" height="77"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #0000ff" x="214.5" y="140" width="94" height="77"/>
+  </g>
+  <g>
+    <rect style="fill: #ffffff" x="59.3" y="126" width="94" height="77"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke-dasharray: 4; stroke: #0000ff" x="59.3" y="126" width="94" height="77"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="214.5" y1="217" x2="59.3" y2="203"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="214.5" y1="140" x2="59.3" y2="126"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="308.5" y1="217" x2="153.3" y2="203"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="308.5" y1="140" x2="153.3" y2="126"/>
+  <text style="fill: #0000ff;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="213.5" y="84">
+    <tspan x="213.5" y="84">sink</tspan>
+    <tspan x="213.5" y="100">crop</tspan>
+    <tspan x="213.5" y="116">selection</tspan>
+  </text>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="30.5" y="89">
+    <tspan x="30.5" y="89"></tspan>
+  </text>
+  <text style="fill: #a52a2a;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="9.53836" y="88.9138">
+    <tspan x="9.53836" y="88.9138">sink media</tspan>
+    <tspan x="9.53836" y="104.914">bus format</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="333.644" y="185.65" width="165.2" height="172.478"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #00ff00" x="333.644" y="185.65" width="165.2" height="172.478"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="333.644" y1="358.128" x2="214.5" y2="217"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="333.644" y1="185.65" x2="214.5" y2="140"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="498.844" y1="358.128" x2="308.5" y2="217"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="498.844" y1="185.65" x2="308.5" y2="140"/>
+  <text style="fill: #00ff00;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="334.704" y="149.442">
+    <tspan x="334.704" y="149.442">sink compose</tspan>
+    <tspan x="334.704" y="165.442">selection (scaling)</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="541.322" y="135.565" width="100.186" height="71.4523"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #a020f0" x="541.322" y="135.565" width="100.186" height="71.4523"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="541.322" y1="207.018" x2="386.64" y2="296.552"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="541.322" y1="135.565" x2="386.64" y2="225.1"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="641.508" y1="207.018" x2="486.826" y2="296.552"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="641.508" y1="135.565" x2="486.826" y2="225.1"/>
+  <text style="fill: #a020f0;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="541.322" y="97.4418">
+    <tspan x="541.322" y="97.4418">source</tspan>
+    <tspan x="541.322" y="113.442">crop</tspan>
+    <tspan x="541.322" y="129.442">selection</tspan>
+  </text>
+  <text style="fill: #8b6914;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="689.5" y="105.128">
+    <tspan x="689.5" y="105.128">source media</tspan>
+    <tspan x="689.5" y="121.128">bus format</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="688.488" y="173.834" width="100.186" height="71.4523"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #8b6914" x="688.488" y="173.834" width="100.186" height="71.4523"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="688.488" y1="245.286" x2="541.322" y2="207.018"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="688.488" y1="173.834" x2="541.322" y2="135.565"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="788.674" y1="245.286" x2="641.508" y2="207.018"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="788.674" y1="173.834" x2="641.508" y2="135.565"/>
+  <text style="fill: #ff765a;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="325" y="103">
+    <tspan x="325" y="103">compose bounds</tspan>
+    <tspan x="325" y="119">selection</tspan>
+  </text>
+  <g>
+    <ellipse style="fill: #ffffff" cx="-12.0982" cy="341.512" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="-12.0982" cy="341.512" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="-12.0982" cy="341.512" rx="8.5" ry="8.5"/>
+  </g>
+  <g>
+    <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x1="-184.098" y1="341.8" x2="-30.3343" y2="341.529"/>
+    <polygon style="fill: #000000" points="-22.8343,341.516 -32.8254,346.534 -30.3343,341.529 -32.8431,336.534 "/>
+    <polygon style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" points="-22.8343,341.516 -32.8254,346.534 -30.3343,341.529 -32.8431,336.534 "/>
+  </g>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="-139" y="329">
+    <tspan x="-139" y="329">pad 1 (sink)</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="7.80824" y="292.8" width="112.092" height="82.2"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #a52a2a" x="7.80824" y="292.8" width="112.092" height="82.2"/>
+  </g>
+  <g>
+    <rect style="fill: #ffffff" x="222.9" y="327.8" width="58.1" height="50.2"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #0000ff" x="222.9" y="327.8" width="58.1" height="50.2"/>
+  </g>
+  <g>
+    <rect style="fill: #ffffff" x="52.7" y="313.8" width="59.3" height="54.2"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke-dasharray: 4; stroke: #0000ff" x="52.7" y="313.8" width="59.3" height="54.2"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="222.9" y1="378" x2="52.7" y2="368"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="222.9" y1="327.8" x2="52.7" y2="313.8"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="281" y1="378" x2="112" y2="368"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="281" y1="327.8" x2="112" y2="313.8"/>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="31.9" y="259.8">
+    <tspan x="31.9" y="259.8"></tspan>
+  </text>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="358.9" y1="251.9" x2="222.9" y2="327.8"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="358.9" y1="316" x2="222.9" y2="378"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="434" y1="316" x2="281" y2="378"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="434" y1="251.9" x2="281" y2="327.8"/>
+  <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #00ff00" x="358.9" y="251.9" width="75.1" height="64.1"/>
+  <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke-dasharray: 4; stroke: #a020f0" x="386.64" y="225.1" width="100.186" height="71.4523"/>
+  <g>
+    <rect style="fill: #ffffff" x="598.262" y="265.466" width="45.778" height="38.535"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #a020f0" x="598.262" y="265.466" width="45.778" height="38.535"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="598.262" y1="304" x2="404.94" y2="333"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="598.262" y1="265.466" x2="404.94" y2="293.9"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="644.04" y1="304" x2="453.04" y2="333"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="644.04" y1="265.466" x2="453.04" y2="293.9"/>
+  <g>
+    <rect style="fill: #ffffff" x="738.428" y="326.734" width="46.612" height="39.266"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #8b6914" x="738.428" y="326.734" width="46.612" height="39.266"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="738.428" y1="366" x2="598.262" y2="304"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="738.428" y1="326.734" x2="598.262" y2="265.466"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="785.04" y1="366" x2="644.04" y2="304"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="785.04" y1="326.734" x2="644.04" y2="265.466"/>
+  <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke-dasharray: 4; stroke: #a020f0" x="404.94" y="293.9" width="48.1" height="39.1"/>
+  <g>
+    <ellipse style="fill: #ffffff" cx="815.44" cy="343.984" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="815.44" cy="343.984" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="815.44" cy="343.984" rx="8.5" ry="8.5"/>
+  </g>
+  <g>
+    <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x1="823.94" y1="343.984" x2="980.274" y2="344.012"/>
+    <polygon style="fill: #000000" points="987.774,344.014 977.773,349.012 980.274,344.012 977.775,339.012 "/>
+    <polygon style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" points="987.774,344.014 977.773,349.012 980.274,344.012 977.775,339.012 "/>
+  </g>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="849.248" y="333.8">
+    <tspan x="849.248" y="333.8">pad 3 (source)</tspan>
+  </text>
+</svg>
diff --git a/Documentation/DocBook/media/v4l/subdev-image-processing-scaling-multi-source.dia b/Documentation/DocBook/media/v4l/subdev-image-processing-scaling-multi-source.dia
new file mode 100644
index 0000000..a051812
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/subdev-image-processing-scaling-multi-source.dia
@@ -0,0 +1,1407 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<dia:diagram xmlns:dia="http://www.lysator.liu.se/~alla/dia/">
+  <dia:diagramdata>
+    <dia:attribute name="background">
+      <dia:color val="#ffffff"/>
+    </dia:attribute>
+    <dia:attribute name="pagebreak">
+      <dia:color val="#000099"/>
+    </dia:attribute>
+    <dia:attribute name="paper">
+      <dia:composite type="paper">
+        <dia:attribute name="name">
+          <dia:string>#A4#</dia:string>
+        </dia:attribute>
+        <dia:attribute name="tmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="bmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="lmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="rmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="is_portrait">
+          <dia:boolean val="false"/>
+        </dia:attribute>
+        <dia:attribute name="scaling">
+          <dia:real val="0.49000000953674316"/>
+        </dia:attribute>
+        <dia:attribute name="fitto">
+          <dia:boolean val="false"/>
+        </dia:attribute>
+      </dia:composite>
+    </dia:attribute>
+    <dia:attribute name="grid">
+      <dia:composite type="grid">
+        <dia:attribute name="width_x">
+          <dia:real val="1"/>
+        </dia:attribute>
+        <dia:attribute name="width_y">
+          <dia:real val="1"/>
+        </dia:attribute>
+        <dia:attribute name="visible_x">
+          <dia:int val="1"/>
+        </dia:attribute>
+        <dia:attribute name="visible_y">
+          <dia:int val="1"/>
+        </dia:attribute>
+        <dia:composite type="color"/>
+      </dia:composite>
+    </dia:attribute>
+    <dia:attribute name="color">
+      <dia:color val="#d8e5e5"/>
+    </dia:attribute>
+    <dia:attribute name="guides">
+      <dia:composite type="guides">
+        <dia:attribute name="hguides"/>
+        <dia:attribute name="vguides"/>
+      </dia:composite>
+    </dia:attribute>
+  </dia:diagramdata>
+  <dia:layer name="Background" visible="true" active="true">
+    <dia:object type="Standard - Box" version="0" id="O0">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-0.4,6.5"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-0.45,6.45;39.95,22.9"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="-0.4,6.5"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="40.299999999999997"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="16.349999999999998"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O1">
+      <dia:attribute name="obj_pos">
+        <dia:point val="0.225,9.45"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="0.175,9.4;8.225,14.7"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="0.225,9.45"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="7.9499999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="5.1999999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a52a2a"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O2">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.675,10.45"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.625,10.4;15.425,14.35"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="10.675,10.45"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="4.6999999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.8499999999999979"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#0000ff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O3">
+      <dia:attribute name="obj_pos">
+        <dia:point val="2.915,9.75"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.865,9.7;7.665,13.65"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="2.915,9.75"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="4.6999999999999975"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.8499999999999979"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#0000ff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="4"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O4">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.675,14.3"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.86071,13.5457;10.7293,14.3543"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="10.675,14.3"/>
+        <dia:point val="2.915,13.6"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O2" connection="5"/>
+        <dia:connection handle="1" to="O3" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O5">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.675,10.45"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="2.86071,9.69571;10.7293,10.5043"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="10.675,10.45"/>
+        <dia:point val="2.915,9.75"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O2" connection="0"/>
+        <dia:connection handle="1" to="O3" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O6">
+      <dia:attribute name="obj_pos">
+        <dia:point val="15.375,14.3"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="7.56071,13.5457;15.4293,14.3543"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="15.375,14.3"/>
+        <dia:point val="7.615,13.6"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O2" connection="7"/>
+        <dia:connection handle="1" to="O3" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O7">
+      <dia:attribute name="obj_pos">
+        <dia:point val="15.375,10.45"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="7.56071,9.69571;15.4293,10.5043"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="15.375,10.45"/>
+        <dia:point val="7.615,9.75"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O2" connection="2"/>
+        <dia:connection handle="1" to="O3" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O8">
+      <dia:attribute name="obj_pos">
+        <dia:point val="10.625,7.65"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.625,7.055;13.5025,9.4025"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#sink
+crop
+selection#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="10.625,7.65"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#0000ff"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O9">
+      <dia:attribute name="obj_pos">
+        <dia:point val="1.475,7.9"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="1.475,7.305;1.475,8.0525"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>##</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="1.475,7.9"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O10">
+      <dia:attribute name="obj_pos">
+        <dia:point val="0.426918,7.89569"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="0.426918,7.30069;3.90942,8.84819"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#sink media
+bus format#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="0.426918,7.89569"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#a52a2a"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O11">
+      <dia:attribute name="obj_pos">
+        <dia:point val="16.6822,9.28251"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="16.6322,9.23251;24.9922,17.9564"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="16.6822,9.28251"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="8.2600228398861297"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="8.6238900617957164"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#00ff00"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O12">
+      <dia:attribute name="obj_pos">
+        <dia:point val="16.6822,17.9064"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.6064,14.2314;16.7508,17.975"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="16.6822,17.9064"/>
+        <dia:point val="10.675,14.3"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O11" connection="5"/>
+        <dia:connection handle="1" to="O2" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O13">
+      <dia:attribute name="obj_pos">
+        <dia:point val="16.6822,9.28251"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="10.6164,9.22389;16.7408,10.5086"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="16.6822,9.28251"/>
+        <dia:point val="10.675,10.45"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O11" connection="0"/>
+        <dia:connection handle="1" to="O2" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O14">
+      <dia:attribute name="obj_pos">
+        <dia:point val="24.9422,17.9064"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="15.3106,14.2356;25.0066,17.9708"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="24.9422,17.9064"/>
+        <dia:point val="15.375,14.3"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O11" connection="7"/>
+        <dia:connection handle="1" to="O2" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O15">
+      <dia:attribute name="obj_pos">
+        <dia:point val="24.9422,9.28251"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="15.3193,9.22682;24.9979,10.5057"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="24.9422,9.28251"/>
+        <dia:point val="15.375,10.45"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O11" connection="2"/>
+        <dia:connection handle="1" to="O2" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O16">
+      <dia:attribute name="obj_pos">
+        <dia:point val="16.7352,7.47209"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="16.7352,6.87709;22.5602,8.42459"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#sink compose
+selection (scaling)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="16.7352,7.47209"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#00ff00"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O17">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.1661,9.37825"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.1161,9.32825;32.2254,13.0009"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="27.1661,9.37825"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.009308462554376"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.5726155970598077"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a020f0"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O18">
+      <dia:attribute name="obj_pos">
+        <dia:point val="19.332,11.255"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="19.282,11.205;24.3913,14.8776"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="19.332,11.255"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.009308462554376"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.5726155970598077"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a020f0"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="4"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O19">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.1661,12.9509"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="19.2717,12.8906;27.2264,14.8879"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="27.1661,12.9509"/>
+        <dia:point val="19.332,14.8276"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O17" connection="5"/>
+        <dia:connection handle="1" to="O18" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O20">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.1661,9.37825"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="19.2717,9.31798;27.2264,11.3153"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="27.1661,9.37825"/>
+        <dia:point val="19.332,11.255"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O17" connection="0"/>
+        <dia:connection handle="1" to="O18" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O21">
+      <dia:attribute name="obj_pos">
+        <dia:point val="32.1754,12.9509"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="24.281,12.8906;32.2357,14.8879"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="32.1754,12.9509"/>
+        <dia:point val="24.3413,14.8276"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O17" connection="7"/>
+        <dia:connection handle="1" to="O18" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O22">
+      <dia:attribute name="obj_pos">
+        <dia:point val="32.1754,9.37825"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="24.281,9.31798;32.2357,11.3153"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="32.1754,9.37825"/>
+        <dia:point val="24.3413,11.255"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O17" connection="2"/>
+        <dia:connection handle="1" to="O18" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O23">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.1661,7.47209"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.1661,6.87709;30.0436,9.22459"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#source
+crop
+selection#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="27.1661,7.47209"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#a020f0"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O24">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.575,7.8564"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="34.575,7.2614;38.8975,8.8089"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#source media
+bus format#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="34.575,7.8564"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#8b6914"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O25">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.5244,11.2917"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="34.4744,11.2417;39.5837,14.9143"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="34.5244,11.2917"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.009308462554376"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.5726155970598077"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#8b6914"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O26">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.5244,14.8643"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.1051,12.8899;34.5854,14.9253"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="34.5244,14.8643"/>
+        <dia:point val="27.1661,12.9509"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O25" connection="5"/>
+        <dia:connection handle="1" to="O17" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O27">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.5244,11.2917"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.1051,9.31728;34.5854,11.3527"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="34.5244,11.2917"/>
+        <dia:point val="27.1661,9.37825"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O25" connection="0"/>
+        <dia:connection handle="1" to="O17" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O28">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.5337,14.8643"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="32.1144,12.8899;39.5947,14.9253"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="39.5337,14.8643"/>
+        <dia:point val="32.1754,12.9509"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O25" connection="7"/>
+        <dia:connection handle="1" to="O17" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O29">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.5337,11.2917"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="32.1144,9.31728;39.5947,11.3527"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="39.5337,11.2917"/>
+        <dia:point val="32.1754,9.37825"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O25" connection="2"/>
+        <dia:connection handle="1" to="O17" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Geometric - Perfect Circle" version="1" id="O30">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.98,12.0742"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="39.93,12.0242;40.88,12.9742"/>
+      </dia:attribute>
+      <dia:attribute name="meta">
+        <dia:composite type="dict"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="39.98,12.0742"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="line_width">
+        <dia:real val="0.10000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="line_colour">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_colour">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="0"/>
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="flip_horizontal">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="flip_vertical">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="subscale">
+        <dia:real val="1"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O31">
+      <dia:attribute name="obj_pos">
+        <dia:point val="40.83,12.4992"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="40.78,12.1388;49.2453,12.8624"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="40.83,12.4992"/>
+        <dia:point val="49.1335,12.5007"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow">
+        <dia:enum val="22"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_length">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_width">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O30" connection="3"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O32">
+      <dia:attribute name="obj_pos">
+        <dia:point val="42.0954,11.99"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="42.0954,11.395;46.7404,12.1425"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#pad 1 (source)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="42.0954,11.99"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Geometric - Perfect Circle" version="1" id="O33">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-1.44491,11.6506"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-1.49491,11.6006;-0.54491,12.5506"/>
+      </dia:attribute>
+      <dia:attribute name="meta">
+        <dia:composite type="dict"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="-1.44491,11.6506"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="line_width">
+        <dia:real val="0.10000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="line_colour">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_colour">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="0"/>
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="flip_horizontal">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="flip_vertical">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="subscale">
+        <dia:real val="1"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O34">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-9.61991,12.09"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-9.67,11.7149;-1.33311,12.4385"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="-9.61991,12.09"/>
+        <dia:point val="-1.44491,12.0756"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow">
+        <dia:enum val="22"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_length">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_width">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="1" to="O33" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O35">
+      <dia:attribute name="obj_pos">
+        <dia:point val="-7.39291,11.49"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-7.39291,10.895;-3.58791,11.6425"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#pad 0 (sink)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="-7.39291,11.49"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O36">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.0911,18.2833"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.0411,18.2333;32.1504,21.9059"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="27.0911,18.2833"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.009308462554376"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.5726155970598077"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a020f0"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O37">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.0911,21.8559"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="17.9067,16.5093;27.1594,21.9242"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="27.0911,21.8559"/>
+        <dia:point val="17.975,16.5776"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O36" connection="5"/>
+        <dia:connection handle="1" to="O49" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O38">
+      <dia:attribute name="obj_pos">
+        <dia:point val="27.0911,18.2833"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="17.9067,12.9367;27.1594,18.3516"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="27.0911,18.2833"/>
+        <dia:point val="17.975,13.005"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O36" connection="0"/>
+        <dia:connection handle="1" to="O49" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O39">
+      <dia:attribute name="obj_pos">
+        <dia:point val="32.1004,21.8559"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="22.916,16.5093;32.1687,21.9242"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="32.1004,21.8559"/>
+        <dia:point val="22.9843,16.5776"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O36" connection="7"/>
+        <dia:connection handle="1" to="O49" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O40">
+      <dia:attribute name="obj_pos">
+        <dia:point val="32.1004,18.2833"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="22.916,12.9367;32.1687,18.3516"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="32.1004,18.2833"/>
+        <dia:point val="22.9843,13.005"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O36" connection="2"/>
+        <dia:connection handle="1" to="O49" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O41">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.4994,17.2967"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="34.4494,17.2467;39.5587,20.9193"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="34.4994,17.2967"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.009308462554376"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.5726155970598077"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#8b6914"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O42">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.4994,20.8693"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.0349,20.8132;34.5556,21.912"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="34.4994,20.8693"/>
+        <dia:point val="27.0911,21.8559"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O41" connection="5"/>
+        <dia:connection handle="1" to="O36" connection="5"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O43">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.4994,17.2967"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="27.0349,17.2405;34.5556,18.3394"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="34.4994,17.2967"/>
+        <dia:point val="27.0911,18.2833"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O41" connection="0"/>
+        <dia:connection handle="1" to="O36" connection="0"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O44">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.5087,20.8693"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="32.0442,20.8132;39.5649,21.912"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="39.5087,20.8693"/>
+        <dia:point val="32.1004,21.8559"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O41" connection="7"/>
+        <dia:connection handle="1" to="O36" connection="7"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O45">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.5087,17.2967"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="32.0442,17.2405;39.5649,18.3394"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="39.5087,17.2967"/>
+        <dia:point val="32.1004,18.2833"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#e60505"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O41" connection="2"/>
+        <dia:connection handle="1" to="O36" connection="2"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Geometric - Perfect Circle" version="1" id="O46">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.855,18.7792"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="39.805,18.7292;40.755,19.6792"/>
+      </dia:attribute>
+      <dia:attribute name="meta">
+        <dia:composite type="dict"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="39.855,18.7792"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="0.84999999999999787"/>
+      </dia:attribute>
+      <dia:attribute name="line_width">
+        <dia:real val="0.10000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="line_colour">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_colour">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="0"/>
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="flip_horizontal">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="flip_vertical">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="subscale">
+        <dia:real val="1"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Line" version="0" id="O47">
+      <dia:attribute name="obj_pos">
+        <dia:point val="40.705,19.2042"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="40.655,18.8438;49.1203,19.5674"/>
+      </dia:attribute>
+      <dia:attribute name="conn_endpoints">
+        <dia:point val="40.705,19.2042"/>
+        <dia:point val="49.0085,19.2057"/>
+      </dia:attribute>
+      <dia:attribute name="numcp">
+        <dia:int val="1"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow">
+        <dia:enum val="22"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_length">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:attribute name="end_arrow_width">
+        <dia:real val="0.5"/>
+      </dia:attribute>
+      <dia:connections>
+        <dia:connection handle="0" to="O46" connection="3"/>
+      </dia:connections>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O48">
+      <dia:attribute name="obj_pos">
+        <dia:point val="41.9704,18.695"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="41.9704,18.0813;46.6341,18.8849"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#pad 2 (source)#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.80000000000000004"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="41.9704,18.695"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="0"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="3"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Box" version="0" id="O49">
+      <dia:attribute name="obj_pos">
+        <dia:point val="17.975,13.005"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="17.925,12.955;23.0343,16.6276"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="17.975,13.005"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="5.009308462554376"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.5726155970598077"/>
+      </dia:attribute>
+      <dia:attribute name="border_width">
+        <dia:real val="0.10000000149011612"/>
+      </dia:attribute>
+      <dia:attribute name="border_color">
+        <dia:color val="#a020f0"/>
+      </dia:attribute>
+      <dia:attribute name="show_background">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="line_style">
+        <dia:enum val="4"/>
+      </dia:attribute>
+    </dia:object>
+  </dia:layer>
+</dia:diagram>
diff --git a/Documentation/DocBook/media/v4l/subdev-image-processing-scaling-multi-source.svg b/Documentation/DocBook/media/v4l/subdev-image-processing-scaling-multi-source.svg
new file mode 100644
index 0000000..eadb774
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/subdev-image-processing-scaling-multi-source.svg
@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
+<svg width="59cm" height="17cm" viewBox="-194 128 1179 330" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+  <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x="-8" y="130" width="806" height="327"/>
+  <g>
+    <rect style="fill: #ffffff" x="4.5" y="189" width="159" height="104"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #a52a2a" x="4.5" y="189" width="159" height="104"/>
+  </g>
+  <g>
+    <rect style="fill: #ffffff" x="213.5" y="209" width="94" height="77"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #0000ff" x="213.5" y="209" width="94" height="77"/>
+  </g>
+  <g>
+    <rect style="fill: #ffffff" x="58.3" y="195" width="94" height="77"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke-dasharray: 4; stroke: #0000ff" x="58.3" y="195" width="94" height="77"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="213.5" y1="286" x2="58.3" y2="272"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="213.5" y1="209" x2="58.3" y2="195"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="307.5" y1="286" x2="152.3" y2="272"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="307.5" y1="209" x2="152.3" y2="195"/>
+  <text style="fill: #0000ff;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="212.5" y="153">
+    <tspan x="212.5" y="153">sink</tspan>
+    <tspan x="212.5" y="169">crop</tspan>
+    <tspan x="212.5" y="185">selection</tspan>
+  </text>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="29.5" y="158">
+    <tspan x="29.5" y="158"></tspan>
+  </text>
+  <text style="fill: #a52a2a;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="8.53836" y="157.914">
+    <tspan x="8.53836" y="157.914">sink media</tspan>
+    <tspan x="8.53836" y="173.914">bus format</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="333.644" y="185.65" width="165.2" height="172.478"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #00ff00" x="333.644" y="185.65" width="165.2" height="172.478"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="333.644" y1="358.128" x2="213.5" y2="286"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="333.644" y1="185.65" x2="213.5" y2="209"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="498.844" y1="358.128" x2="307.5" y2="286"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="498.844" y1="185.65" x2="307.5" y2="209"/>
+  <text style="fill: #00ff00;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="334.704" y="149.442">
+    <tspan x="334.704" y="149.442">sink compose</tspan>
+    <tspan x="334.704" y="165.442">selection (scaling)</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="543.322" y="187.565" width="100.186" height="71.4523"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #a020f0" x="543.322" y="187.565" width="100.186" height="71.4523"/>
+  </g>
+  <g>
+    <rect style="fill: #ffffff" x="386.64" y="225.1" width="100.186" height="71.4523"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke-dasharray: 4; stroke: #a020f0" x="386.64" y="225.1" width="100.186" height="71.4523"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="543.322" y1="259.018" x2="386.64" y2="296.552"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="543.322" y1="187.565" x2="386.64" y2="225.1"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="643.508" y1="259.018" x2="486.826" y2="296.552"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="643.508" y1="187.565" x2="486.826" y2="225.1"/>
+  <text style="fill: #a020f0;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="543.322" y="149.442">
+    <tspan x="543.322" y="149.442">source</tspan>
+    <tspan x="543.322" y="165.442">crop</tspan>
+    <tspan x="543.322" y="181.442">selection</tspan>
+  </text>
+  <text style="fill: #8b6914;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="691.5" y="157.128">
+    <tspan x="691.5" y="157.128">source media</tspan>
+    <tspan x="691.5" y="173.128">bus format</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="690.488" y="225.834" width="100.186" height="71.4523"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #8b6914" x="690.488" y="225.834" width="100.186" height="71.4523"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="690.488" y1="297.286" x2="543.322" y2="259.018"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="690.488" y1="225.834" x2="543.322" y2="187.565"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="790.674" y1="297.286" x2="643.508" y2="259.018"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="790.674" y1="225.834" x2="643.508" y2="187.565"/>
+  <g>
+    <ellipse style="fill: #ffffff" cx="808.1" cy="249.984" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="808.1" cy="249.984" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="808.1" cy="249.984" rx="8.5" ry="8.5"/>
+  </g>
+  <g>
+    <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x1="816.6" y1="249.984" x2="972.934" y2="250.012"/>
+    <polygon style="fill: #000000" points="980.434,250.014 970.433,255.012 972.934,250.012 970.435,245.012 "/>
+    <polygon style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" points="980.434,250.014 970.433,255.012 972.934,250.012 970.435,245.012 "/>
+  </g>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="841.908" y="239.8">
+    <tspan x="841.908" y="239.8">pad 1 (source)</tspan>
+  </text>
+  <g>
+    <ellipse style="fill: #ffffff" cx="-20.3982" cy="241.512" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="-20.3982" cy="241.512" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="-20.3982" cy="241.512" rx="8.5" ry="8.5"/>
+  </g>
+  <g>
+    <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x1="-192.398" y1="241.8" x2="-38.6343" y2="241.529"/>
+    <polygon style="fill: #000000" points="-31.1343,241.516 -41.1254,246.534 -38.6343,241.529 -41.1431,236.534 "/>
+    <polygon style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" points="-31.1343,241.516 -41.1254,246.534 -38.6343,241.529 -41.1431,236.534 "/>
+  </g>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="-147.858" y="229.8">
+    <tspan x="-147.858" y="229.8">pad 0 (sink)</tspan>
+  </text>
+  <g>
+    <rect style="fill: #ffffff" x="541.822" y="365.666" width="100.186" height="71.4523"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #a020f0" x="541.822" y="365.666" width="100.186" height="71.4523"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="541.822" y1="437.118" x2="359.5" y2="331.552"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="541.822" y1="365.666" x2="359.5" y2="260.1"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="642.008" y1="437.118" x2="459.686" y2="331.552"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="642.008" y1="365.666" x2="459.686" y2="260.1"/>
+  <g>
+    <rect style="fill: #ffffff" x="689.988" y="345.934" width="100.186" height="71.4523"/>
+    <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #8b6914" x="689.988" y="345.934" width="100.186" height="71.4523"/>
+  </g>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="689.988" y1="417.386" x2="541.822" y2="437.118"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="689.988" y1="345.934" x2="541.822" y2="365.666"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="790.174" y1="417.386" x2="642.008" y2="437.118"/>
+  <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #e60505" x1="790.174" y1="345.934" x2="642.008" y2="365.666"/>
+  <g>
+    <ellipse style="fill: #ffffff" cx="805.6" cy="384.084" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="805.6" cy="384.084" rx="8.5" ry="8.5"/>
+    <ellipse style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" cx="805.6" cy="384.084" rx="8.5" ry="8.5"/>
+  </g>
+  <g>
+    <line style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x1="814.1" y1="384.084" x2="970.434" y2="384.112"/>
+    <polygon style="fill: #000000" points="977.934,384.114 967.933,389.112 970.434,384.112 967.935,379.112 "/>
+    <polygon style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" points="977.934,384.114 967.933,389.112 970.434,384.112 967.935,379.112 "/>
+  </g>
+  <text style="fill: #000000;text-anchor:start;font-size:12.8;font-family:sanserif;font-style:normal;font-weight:normal" x="839.408" y="373.9">
+    <tspan x="839.408" y="373.9">pad 2 (source)</tspan>
+  </text>
+  <rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke-dasharray: 4; stroke: #a020f0" x="359.5" y="260.1" width="100.186" height="71.4523"/>
+</svg>
-- 
1.7.2.5


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

* [PATCH v3 09/33] v4l: Add subdev selections documentation
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (7 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 08/33] v4l: Add subdev selections documentation: svg and dia files Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-21 16:41   ` Laurent Pinchart
  2012-02-20  1:56 ` [PATCH v3 10/33] v4l: Mark VIDIOC_SUBDEV_G_CROP and VIDIOC_SUBDEV_S_CROP obsolete Sakari Ailus
                   ` (24 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Add documentation for V4L2 subdev selection API. This changes also
experimental V4L2 subdev API so that scaling now works through selection API
only.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 Documentation/DocBook/media/Makefile               |    2 +-
 Documentation/DocBook/media/v4l/compat.xml         |    3 +
 Documentation/DocBook/media/v4l/dev-subdev.xml     |  188 +++++++++++++++--
 Documentation/DocBook/media/v4l/v4l2.xml           |   17 ++-
 .../media/v4l/vidioc-subdev-g-selection.xml        |  222 ++++++++++++++++++++
 5 files changed, 405 insertions(+), 27 deletions(-)
 create mode 100644 Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml

diff --git a/Documentation/DocBook/media/Makefile b/Documentation/DocBook/media/Makefile
index 6628b4b..729f840 100644
--- a/Documentation/DocBook/media/Makefile
+++ b/Documentation/DocBook/media/Makefile
@@ -193,7 +193,7 @@ DVB_DOCUMENTED = \
 #
 
 install_media_images = \
-	$(Q)cp $(OBJIMGFILES) $(MEDIA_OBJ_DIR)/media_api
+	$(Q)cp $(OBJIMGFILES) $(MEDIA_SRC_DIR)/v4l/*.svg $(MEDIA_OBJ_DIR)/media_api
 
 $(MEDIA_OBJ_DIR)/%: $(MEDIA_SRC_DIR)/%.b64
 	$(Q)base64 -d $< >$@
diff --git a/Documentation/DocBook/media/v4l/compat.xml b/Documentation/DocBook/media/v4l/compat.xml
index 8cd5c96..0c498db 100644
--- a/Documentation/DocBook/media/v4l/compat.xml
+++ b/Documentation/DocBook/media/v4l/compat.xml
@@ -2407,6 +2407,9 @@ details.</para>
 	  <para>Added integer menus, the new type will be
 	  V4L2_CTRL_TYPE_INTEGER_MENU.</para>
         </listitem>
+        <listitem>
+	  <para>Added selection API for V4L2 subdev interface.</para>
+        </listitem>
       </orderedlist>
     </section>
 
diff --git a/Documentation/DocBook/media/v4l/dev-subdev.xml b/Documentation/DocBook/media/v4l/dev-subdev.xml
index 0916a73..9d5e7da 100644
--- a/Documentation/DocBook/media/v4l/dev-subdev.xml
+++ b/Documentation/DocBook/media/v4l/dev-subdev.xml
@@ -76,11 +76,12 @@
     <wordasword>format</wordasword> means the combination of media bus data
     format, frame width and frame height.</para></note>
 
-    <para>Image formats are typically negotiated on video capture and output
-    devices using the <link linkend="crop">cropping and scaling</link> ioctls.
-    The driver is responsible for configuring every block in the video pipeline
-    according to the requested format at the pipeline input and/or
-    output.</para>
+    <para>Image formats are typically negotiated on video capture and
+    output devices using the format and <link
+    linkend="vidioc-subdev-g-selection">selection</link> ioctls. The
+    driver is responsible for configuring every block in the video
+    pipeline according to the requested format at the pipeline input
+    and/or output.</para>
 
     <para>For complex devices, such as often found in embedded systems,
     identical image sizes at the output of a pipeline can be achieved using
@@ -276,11 +277,11 @@
     </section>
 
     <section>
-      <title>Cropping and scaling</title>
+      <title>Selections: cropping, scaling and composition</title>
 
       <para>Many sub-devices support cropping frames on their input or output
       pads (or possible even on both). Cropping is used to select the area of
-      interest in an image, typically on a video sensor or video decoder. It can
+      interest in an image, typically on an image sensor or a video decoder. It can
       also be used as part of digital zoom implementations to select the area of
       the image that will be scaled up.</para>
 
@@ -288,26 +289,165 @@
       &v4l2-rect; by the coordinates of the top left corner and the rectangle
       size. Both the coordinates and sizes are expressed in pixels.</para>
 
-      <para>The crop rectangle is retrieved and set using the
-      &VIDIOC-SUBDEV-G-CROP; and &VIDIOC-SUBDEV-S-CROP; ioctls. Like for pad
-      formats, drivers store try and active crop rectangles. The format
-      negotiation mechanism applies to crop settings as well.</para>
-
-      <para>On input pads, cropping is applied relatively to the current pad
-      format. The pad format represents the image size as received by the
-      sub-device from the previous block in the pipeline, and the crop rectangle
-      represents the sub-image that will be transmitted further inside the
-      sub-device for processing. The crop rectangle be entirely containted
-      inside the input image size.</para>
-
-      <para>Input crop rectangle are reset to their default value when the input
-      image format is modified. Drivers should use the input image size as the
-      crop rectangle default value, but hardware requirements may prevent this.
-      </para>
+      <para>Scaling operation changes the size of the image by scaling
+      it to new dimensions. Some sub-devices support it. The scaled
+      size (width and height) is represented by &v4l2-rect;. In the
+      case of scaling, top and left will always be zero. Scaling is
+      configured using &sub-subdev-g-selection; and
+      <constant>V4L2_SUBDEV_SEL_COMPOSE_ACTIVE</constant> selection
+      target on the sink pad of the subdev. The scaling is performed
+      related to the width and height of the crop rectangle on the
+      subdev's sink pad.</para>
+
+      <para>As for pad formats, drivers store try and active
+      rectangles for the selection targets of ACTIVE type <xref
+      linkend="v4l2-subdev-selection-targets">.</xref></para>
+
+      <para>On sink pads, cropping is applied relatively to the
+      current pad format. The pad format represents the image size as
+      received by the sub-device from the previous block in the
+      pipeline, and the crop rectangle represents the sub-image that
+      will be transmitted further inside the sub-device for
+      processing.</para>
+
+      <para>On source pads, cropping is similar to sink pads, with the
+      exception that the source size from which the cropping is
+      performed, is the COMPOSE rectangle on the sink pad. In both
+      sink and source pads, the crop rectangle must be entirely
+      containted inside the source image size for the crop
+      operation.</para>
+
+      <para>The drivers should always use the closest possible
+      rectangle the user requests on all selection targets, unless
+      specificly told otherwise<xref
+      linkend="v4l2-subdev-selection-flags">.</xref></para>
+    </section>
+
+    <section>
+      <title>Types of selection targets</title>
+
+      <section>
+	<title>ACTIVE targets</title>
+
+	<para>ACTIVE targets reflect the actual hardware configuration
+	at any point of time.</para>
+      </section>
+
+      <section>
+	<title>BOUNDS targets</title>
+
+	<para>BOUNDS targets is the smallest rectangle within which
+	contains all valid ACTIVE rectangles. It may not be possible
+	to set the ACTIVE rectangle as large as the BOUNDS rectangle,
+	however.</para>
+      </section>
 
-      <para>Cropping behaviour on output pads is not defined.</para>
+    </section>
+
+    <section>
+      <title>Order of configuration and format propagation</title>
+
+      <para>Inside subdevs, the order of image processing steps will
+      always be from the sink pad towards the source pad. This is also
+      reflected in the order in which the configuration must be
+      performed by the user: the changes made will be propagated to
+      any subsequent stages. If this behaviour is not desired, the
+      user must set
+      <constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant> flag. The
+      coordinates to a step always refer to the active size of the
+      previous step. The exception to this rule is the source compose
+      rectangle, which refers to the sink compose bounds rectangle ---
+      if it is supported by the hardware.</para>
+
+      <orderedlist>
+	<listitem>Sink pad format. The user configures the sink pad
+	format. This format defines the parameters of the image the
+	entity receives through the pad for further processing.</listitem>
+
+	<listitem>Sink pad active crop selection. The sink pad crop
+	defines the performed to the sink pad format.</listitem>
+
+	<listitem>Sink pad active compose selection. The size of the
+	sink pad compose rectangle defines the scaling ratio compared
+	to the size of the sink pad crop rectangle. The location of
+	the compose rectangle specifies the location of the active
+	sink compose rectangle in the sink compose bounds
+	rectangle.</listitem>
+
+	<listitem>Source pad active crop selection. Crop on the source
+	pad defines crop performed to the image in the sink compose
+	bounds rectangle.</listitem>
+
+	<listitem>Source pad format. The source pad format defines the
+	output pixel format of the subdev, as well as the other
+	parameters with the exception of the image width and height.
+	Width and height are defined by the size of the source pad
+	active crop selection.</listitem>
+      </orderedlist>
+
+      <para>Accessing any of the above rectangles not supported by the
+      subdev will return <constant>EINVAL</constant>. Any rectangle
+      referring to a previous unsupported rectangle coordinates will
+      instead refer to the previous supported rectangle. For example,
+      if sink crop is not supported, the compose selection will refer
+      to the sink pad format dimensions instead.</para>
+
+      <figure id="subdev-image-processing-crop">
+	<title>Image processing in subdevs: simple crop example</title>
+	<mediaobject>
+	  <imageobject>
+	    <imagedata fileref="subdev-image-processing-crop.svg"
+	    format="SVG" scale="200" />
+	  </imageobject>
+	</mediaobject>
+      </figure>
+
+      <para>In the above example, the subdev supports cropping on its
+      sink pad. To configure it, the user sets the media bus format on
+      the subdev's sink pad. Now the active crop rectangle can be set
+      on the sink pad --- the location and size of this rectangle
+      reflect the location and size of a rectangle to be cropped from
+      the sink format. The size of the sink crop rectangle will also
+      be the size of the format of the subdev's source pad.</para>
+
+      <figure id="subdev-image-processing-scaling-multi-source">
+	<title>Image processing in subdevs: scaling with multiple sources</title>
+	<mediaobject>
+	  <imageobject>
+	    <imagedata fileref="subdev-image-processing-scaling-multi-source.svg"
+	    format="SVG" scale="200" />
+	  </imageobject>
+	</mediaobject>
+      </figure>
+
+      <para>In this example, the subdev is capable of first cropping,
+      then scaling and finally cropping for two source pads
+      individually from the resulting scaled image. The location of
+      the scaled image in the cropped image is ignored in sink compose
+      target. Both of the locations of the source crop rectangles
+      refer to the sink scaling rectangle, independently cropping an
+      area at location specified by the source crop rectangle from
+      it.</para>
+
+      <figure id="subdev-image-processing-full">
+	<title>Image processing in subdevs: scaling and composition
+	with multiple sinks and sources</title>
+	<mediaobject>
+	  <imageobject>
+	    <imagedata fileref="subdev-image-processing-full.svg"
+	    format="SVG" scale="200" />
+	  </imageobject>
+	</mediaobject>
+      </figure>
+
+      <para>The subdev driver supports two sink pads and two source
+      pads. The images from both of the sink pads are individually
+      cropped, then scaled and further composed on the composition
+      bounds rectangle. From that, two independent streams are cropped
+      and sent out of the subdev from the source pads.</para>
 
     </section>
+
   </section>
 
   &sub-subdev-formats;
diff --git a/Documentation/DocBook/media/v4l/v4l2.xml b/Documentation/DocBook/media/v4l/v4l2.xml
index ff11a13..912ec9c 100644
--- a/Documentation/DocBook/media/v4l/v4l2.xml
+++ b/Documentation/DocBook/media/v4l/v4l2.xml
@@ -96,6 +96,17 @@ Remote Controller chapter.</contrib>
 	  </address>
 	</affiliation>
       </author>
+
+      <author>
+	<firstname>Sakari</firstname>
+	<surname>Ailus</surname>
+	<contrib>Subdev selections API.</contrib>
+	<affiliation>
+	  <address>
+	    <email>sakari.ailus@iki.fi</email>
+	  </address>
+	</affiliation>
+      </author>
     </authorgroup>
 
     <copyright>
@@ -129,9 +140,10 @@ applications. -->
 
       <revision>
 	<revnumber>3.4</revnumber>
-	<date>2012-01-26</date>
+	<date>2012-02-02</date>
 	<authorinitials>sa</authorinitials>
-	<revremark>Added V4L2_CTRL_TYPE_INTEGER_MENU.</revremark>
+	<revremark>Added V4L2_CTRL_TYPE_INTEGER_MENU. Added V4L2 subdev
+		   selections API.</revremark>
       </revision>
       <revision>
 	<revnumber>3.3</revnumber>
@@ -537,6 +549,7 @@ and discussions on the V4L mailing list.</revremark>
     &sub-subdev-g-crop;
     &sub-subdev-g-fmt;
     &sub-subdev-g-frame-interval;
+    &sub-subdev-g-selection;
     &sub-subscribe-event;
     <!-- End of ioctls. -->
     &sub-mmap;
diff --git a/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
new file mode 100644
index 0000000..033077a
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
@@ -0,0 +1,222 @@
+<refentry id="vidioc-subdev-g-selection">
+  <refmeta>
+    <refentrytitle>ioctl VIDIOC_SUBDEV_G_SELECTION, VIDIOC_SUBDEV_S_SELECTION</refentrytitle>
+    &manvol;
+  </refmeta>
+
+  <refnamediv>
+    <refname>VIDIOC_SUBDEV_G_SELECTION</refname>
+    <refname>VIDIOC_SUBDEV_S_SELECTION</refname>
+    <refpurpose>Get or set selection rectangles on a subdev pad</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <funcsynopsis>
+      <funcprototype>
+	<funcdef>int <function>ioctl</function></funcdef>
+	<paramdef>int <parameter>fd</parameter></paramdef>
+	<paramdef>int <parameter>request</parameter></paramdef>
+	<paramdef>struct v4l2_subdev_selection *<parameter>argp</parameter></paramdef>
+      </funcprototype>
+    </funcsynopsis>
+  </refsynopsisdiv>
+
+  <refsect1>
+    <title>Arguments</title>
+
+    <variablelist>
+      <varlistentry>
+	<term><parameter>fd</parameter></term>
+	<listitem>
+	  <para>&fd;</para>
+	</listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><parameter>request</parameter></term>
+	<listitem>
+	  <para>VIDIOC_SUBDEV_G_SELECTION, VIDIOC_SUBDEV_S_SELECTION</para>
+	</listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><parameter>argp</parameter></term>
+	<listitem>
+	  <para></para>
+	</listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
+  <refsect1>
+    <title>Description</title>
+
+    <note>
+      <title>Experimental</title>
+      <para>This is an <link linkend="experimental">experimental</link>
+      interface and may change in the future.</para>
+    </note>
+
+    <para>The selections are used to configure various image
+    processing functionality performed by the subdevs which affect the
+    image size. This currently includes cropping, scaling and
+    composition.</para>
+
+    <para>The selection API replaces <link
+    linkend="vidioc-subdev-g-crop">the old subdev crop API</link>. All
+    the function of the crop API, and more, are supported by the
+    selections API.</para>
+
+    <para>See <xref linkend="subdev"></xref> for
+    more information on how each selection target affects the image
+    processing pipeline inside the subdevice.</para>
+
+    <section>
+      <title>Types of selection targets</title>
+
+      <para>The are four types of selection targets: active, default,
+      bounds and padding. The ACTIVE targets are the targets which
+      configure the hardware. The BOUNDS target will return the
+      maximum width and height of the target.</para>
+    </section>
+
+    <section>
+      <title>Discovering supported features</title>
+
+      <para>To discover which targets are supported, the user can
+      perform <constant>VIDIOC_SUBDEV_G_SELECTION</constant> on them.
+      Any unsupported target will return
+      <constant>EINVAL</constant>.</para>
+    </section>
+
+    <table pgwide="1" frame="none" id="v4l2-subdev-selection-targets">
+      <title>V4L2 subdev selection targets</title>
+      <tgroup cols="3">
+        &cs-def;
+	<tbody valign="top">
+	  <row>
+	    <entry><constant>V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE</constant></entry>
+	    <entry>0x0000</entry>
+	    <entry>Active crop. Defines the cropping
+	    performed by the processing step.</entry>
+	  </row>
+	  <row>
+	    <entry><constant>V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS</constant></entry>
+	    <entry>0x0002</entry>
+	    <entry>Bounds of the crop rectangle.</entry>
+	  </row>
+	  <row>
+	    <entry><constant>V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE</constant></entry>
+	    <entry>0x0100</entry>
+	    <entry>Active compose rectangle. Used to configure scaling
+	    on sink pads and composition on source pads.</entry>
+	  </row>
+	  <row>
+	    <entry><constant>V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS</constant></entry>
+	    <entry>0x0102</entry>
+	    <entry>Bounds of the compose rectangle.</entry>
+	  </row>
+	</tbody>
+      </tgroup>
+    </table>
+
+    <table pgwide="1" frame="none" id="v4l2-subdev-selection-flags">
+      <title>V4L2 subdev selection flags</title>
+      <tgroup cols="3">
+        &cs-def;
+	<tbody valign="top">
+	  <row>
+	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_GE</constant></entry>
+	    <entry>(1 &lt;&lt; 0)</entry>
+	    <entry>Suggest the driver it should choose greater or
+	    equal rectangle (in size) than was requested.</entry>
+	  </row>
+	  <row>
+	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_LE</constant></entry>
+	    <entry>(1 &lt;&lt; 1)</entry>
+	    <entry>Suggest the driver it should choose lesser or
+	    equal rectangle (in size) than was requested.</entry>
+	  </row>
+	  <row>
+	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant></entry>
+	    <entry>(1 &lt;&lt; 2)</entry>
+	    <entry>The configuration should not be propagated to any
+	    further processing steps. If this flag is not given, the
+	    configuration is propagated inside the subdevice to all
+	    further processing steps.</entry>
+	  </row>
+	</tbody>
+      </tgroup>
+    </table>
+
+    <table pgwide="1" frame="none" id="v4l2-subdev-selection">
+      <title>struct <structname>v4l2_subdev_selection</structname></title>
+      <tgroup cols="3">
+        &cs-str;
+	<tbody valign="top">
+	  <row>
+	    <entry>__u32</entry>
+	    <entry><structfield>which</structfield></entry>
+	    <entry>Active or try selection, from
+	    &v4l2-subdev-format-whence;.</entry>
+	  </row>
+	  <row>
+	    <entry>__u32</entry>
+	    <entry><structfield>pad</structfield></entry>
+	    <entry>Pad number as reported by the media framework.</entry>
+	  </row>
+	  <row>
+	    <entry>__u32</entry>
+	    <entry><structfield>target</structfield></entry>
+	    <entry>Target selection rectangle. See
+	    <xref linkend="v4l2-subdev-selection-targets">.</xref>.</entry>
+	  </row>
+	  <row>
+	    <entry>__u32</entry>
+	    <entry><structfield>flags</structfield></entry>
+	    <entry>Flags. See
+	    <xref linkend="v4l2-subdev-selection-flags">.</xref></entry>
+	  </row>
+	  <row>
+	    <entry>&v4l2-rect;</entry>
+	    <entry><structfield>rect</structfield></entry>
+	    <entry>Crop rectangle boundaries, in pixels.</entry>
+	  </row>
+	  <row>
+	    <entry>__u32</entry>
+	    <entry><structfield>reserved</structfield>[8]</entry>
+	    <entry>Reserved for future extensions. Applications and drivers must
+	    set the array to zero.</entry>
+	  </row>
+	</tbody>
+      </tgroup>
+    </table>
+
+  </refsect1>
+
+  <refsect1>
+    &return-value;
+
+    <variablelist>
+      <varlistentry>
+	<term><errorcode>EBUSY</errorcode></term>
+	<listitem>
+	  <para>The selection rectangle can't be changed because the
+	  pad is currently busy. This can be caused, for instance, by
+	  an active video stream on the pad. The ioctl must not be
+	  retried without performing another action to fix the problem
+	  first. Only returned by
+	  <constant>VIDIOC_SUBDEV_S_SELECTION</constant></para>
+	</listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><errorcode>EINVAL</errorcode></term>
+	<listitem>
+	  <para>The &v4l2-subdev-selection;
+	  <structfield>pad</structfield> references a non-existing
+	  pad, the <structfield>which</structfield> field references a
+	  non-existing format, or the selection target is not
+	  supported on the given subdev pad.</para>
+	</listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+</refentry>
-- 
1.7.2.5


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

* [PATCH v3 10/33] v4l: Mark VIDIOC_SUBDEV_G_CROP and VIDIOC_SUBDEV_S_CROP obsolete
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (8 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 09/33] v4l: Add subdev selections documentation Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-21 16:42   ` Laurent Pinchart
  2012-02-20  1:56 ` [PATCH v3 11/33] v4l: Image source control class Sakari Ailus
                   ` (23 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

These two IOCTLS are obsoleted by VIDIOC_SUBDEV_G_SELECTION and
VIDIOC_SUBDEV_S_SELECTION. Mark them obsolete.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 Documentation/DocBook/media/v4l/compat.xml         |    7 +++++++
 .../DocBook/media/v4l/vidioc-subdev-g-crop.xml     |    9 ++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/Documentation/DocBook/media/v4l/compat.xml b/Documentation/DocBook/media/v4l/compat.xml
index 0c498db..da9b3bd 100644
--- a/Documentation/DocBook/media/v4l/compat.xml
+++ b/Documentation/DocBook/media/v4l/compat.xml
@@ -2541,6 +2541,13 @@ interfaces and should not be implemented in new drivers.</para>
 <constant>VIDIOC_S_MPEGCOMP</constant> ioctls. Use Extended Controls,
 <xref linkend="extended-controls" />.</para>
         </listitem>
+        <listitem>
+	  <para><constant>VIDIOC_SUBDEV_G_CROP</constant> and
+	  <constant>VIDIOC_SUBDEV_S_CROP</constant> ioctls. Use
+	  <constant>VIDIOC_SUBDEV_G_SELECTION</constant> and
+	  <constant>VIDIOC_SUBDEV_S_SELECTION</constant>, <xref
+	  linkend="vidioc-subdev-g-selection" />.</para>
+        </listitem>
       </itemizedlist>
     </section>
   </section>
diff --git a/Documentation/DocBook/media/v4l/vidioc-subdev-g-crop.xml b/Documentation/DocBook/media/v4l/vidioc-subdev-g-crop.xml
index 0619732..4cddd78 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subdev-g-crop.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subdev-g-crop.xml
@@ -58,9 +58,12 @@
     <title>Description</title>
 
     <note>
-      <title>Experimental</title>
-      <para>This is an <link linkend="experimental">experimental</link>
-      interface and may change in the future.</para>
+      <title>Obsolete</title>
+
+      <para>This is an <link linkend="obsolete">obsolete</link>
+      interface and may be removed in the future. It is superseded by
+      <link linkend="vidioc-subdev-g-selection">the selection
+      API</link>.</para>
     </note>
 
     <para>To retrieve the current crop rectangle applications set the
-- 
1.7.2.5


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

* [PATCH v3 11/33] v4l: Image source control class
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (9 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 10/33] v4l: Mark VIDIOC_SUBDEV_G_CROP and VIDIOC_SUBDEV_S_CROP obsolete Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 12/33] v4l: Image processing " Sakari Ailus
                   ` (22 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Add image source control class. This control class is intended to contain
low level controls which deal with control of the image capture process ---
the A/D converter in image sensors, for example.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 Documentation/DocBook/media/v4l/controls.xml       |   86 ++++++++++++++++++++
 .../DocBook/media/v4l/vidioc-g-ext-ctrls.xml       |    6 ++
 drivers/media/video/v4l2-ctrls.c                   |    7 ++
 include/linux/videodev2.h                          |    9 ++
 4 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/Documentation/DocBook/media/v4l/controls.xml b/Documentation/DocBook/media/v4l/controls.xml
index 3f3d2e2..2257db4 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -3438,4 +3438,90 @@ interface and may change in the future.</para>
       </table>
 
     </section>
+
+    <section id="image-source-controls">
+      <title>Image Source Control Reference</title>
+
+      <note>
+	<title>Experimental</title>
+
+	<para>This is an <link
+	linkend="experimental">experimental</link> interface and may
+	change in the future.</para>
+      </note>
+
+      <para>
+	The Image Source control class is intended for low-level
+	control of image source devices such as image sensors. The
+	devices feature an analogue to digital converter and a bus
+	transmitter to transmit the image data out of the device.
+      </para>
+
+      <table pgwide="1" frame="none" id="image-source-control-id">
+      <title>Image Source Control IDs</title>
+
+      <tgroup cols="4">
+	<colspec colname="c1" colwidth="1*" />
+	<colspec colname="c2" colwidth="6*" />
+	<colspec colname="c3" colwidth="2*" />
+	<colspec colname="c4" colwidth="6*" />
+	<spanspec namest="c1" nameend="c2" spanname="id" />
+	<spanspec namest="c2" nameend="c4" spanname="descr" />
+	<thead>
+	  <row>
+	    <entry spanname="id" align="left">ID</entry>
+	    <entry align="left">Type</entry>
+	  </row><row rowsep="1"><entry spanname="descr" align="left">Description</entry>
+	  </row>
+	</thead>
+	<tbody valign="top">
+	  <row><entry></entry></row>
+	  <row>
+	    <entry spanname="id"><constant>V4L2_CID_IMAGE_SOURCE_CLASS</constant></entry>
+	    <entry>class</entry>
+	  </row>
+	  <row>
+	    <entry spanname="descr">The IMAGE_SOURCE class descriptor.</entry>
+	  </row>
+	  <row>
+	    <entry spanname="id"><constant>V4L2_CID_VBLANK</constant></entry>
+	    <entry>integer</entry>
+	  </row>
+	  <row>
+	    <entry spanname="descr">Vertical blanking. The idle period
+	    after every frame during which no image data is produced.
+	    The unit of vertical blanking is a line. Every line has
+	    length of the image width plus horizontal blanking at the
+	    pixel rate defined by
+	    <constant>V4L2_CID_PIXEL_RATE</constant> control in the
+	    same sub-device.</entry>
+	  </row>
+	  <row>
+	    <entry spanname="id"><constant>V4L2_CID_HBLANK</constant></entry>
+	    <entry>integer</entry>
+	  </row>
+	  <row>
+	    <entry spanname="descr">Horizontal blanking. The idle
+	    period after every line of image data during which no
+	    image data is produced. The unit of horizontal blanking is
+	    pixels.</entry>
+	  </row>
+	  <row>
+	    <entry spanname="id"><constant>V4L2_CID_ANALOGUE_GAIN</constant></entry>
+	    <entry>integer</entry>
+	  </row>
+	  <row>
+	    <entry spanname="descr">Analogue gain is gain affecting
+	    all colour components in the pixel matrix. The gain
+	    operation is performed in the analogue domain before A/D
+	    conversion.
+	    </entry>
+	  </row>
+	  <row><entry></entry></row>
+	</tbody>
+      </tgroup>
+      </table>
+
+    </section>
+
 </section>
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
index b17a7aa..f420034 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
@@ -265,6 +265,12 @@ These controls are described in <xref
 These controls are described in <xref
 		linkend="flash-controls" />.</entry>
 	  </row>
+	  <row>
+	    <entry><constant>V4L2_CTRL_CLASS_IMAGE_SOURCE</constant></entry>
+	    <entry>0x9d0000</entry> <entry>The class containing image
+	    source controls. These controls are described in <xref
+	    linkend="image-source-controls" />.</entry>
+	  </row>
 	</tbody>
       </tgroup>
     </table>
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
index f0484bd..3ca6bc7 100644
--- a/drivers/media/video/v4l2-ctrls.c
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -623,6 +623,12 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_FLASH_CHARGE:		return "Charge";
 	case V4L2_CID_FLASH_READY:		return "Ready to Strobe";
 
+	/* Image source controls */
+	case V4L2_CID_IMAGE_SOURCE_CLASS:	return "Image Source Controls";
+	case V4L2_CID_VBLANK:			return "Vertical Blanking";
+	case V4L2_CID_HBLANK:			return "Horizontal Blanking";
+	case V4L2_CID_ANALOGUE_GAIN:		return "Analogue Gain";
+
 	default:
 		return NULL;
 	}
@@ -722,6 +728,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_MPEG_CLASS:
 	case V4L2_CID_FM_TX_CLASS:
 	case V4L2_CID_FLASH_CLASS:
+	case V4L2_CID_IMAGE_SOURCE_CLASS:
 		*type = V4L2_CTRL_TYPE_CTRL_CLASS;
 		/* You can neither read not write these */
 		*flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index e3c6302..ca64202 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -1136,6 +1136,7 @@ struct v4l2_ext_controls {
 #define V4L2_CTRL_CLASS_CAMERA 0x009a0000	/* Camera class controls */
 #define V4L2_CTRL_CLASS_FM_TX 0x009b0000	/* FM Modulator control class */
 #define V4L2_CTRL_CLASS_FLASH 0x009c0000	/* Camera flash controls */
+#define V4L2_CTRL_CLASS_IMAGE_SOURCE 0x009d0000	/* Image source controls */
 
 #define V4L2_CTRL_ID_MASK      	  (0x0fffffff)
 #define V4L2_CTRL_ID2CLASS(id)    ((id) & 0x0fff0000UL)
@@ -1762,6 +1763,14 @@ enum v4l2_flash_strobe_source {
 #define V4L2_CID_FLASH_CHARGE			(V4L2_CID_FLASH_CLASS_BASE + 11)
 #define V4L2_CID_FLASH_READY			(V4L2_CID_FLASH_CLASS_BASE + 12)
 
+/* Image source controls */
+#define V4L2_CID_IMAGE_SOURCE_CLASS_BASE	(V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
+#define V4L2_CID_IMAGE_SOURCE_CLASS		(V4L2_CTRL_CLASS_IMAGE_SOURCE | 1)
+
+#define V4L2_CID_VBLANK				(V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 1)
+#define V4L2_CID_HBLANK				(V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 2)
+#define V4L2_CID_ANALOGUE_GAIN			(V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 3)
+
 /*
  *	T U N I N G
  */
-- 
1.7.2.5


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

* [PATCH v3 12/33] v4l: Image processing control class
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (10 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 11/33] v4l: Image source control class Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 13/33] v4l: Document raw bayer 4CC codes Sakari Ailus
                   ` (21 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Add control class for image processing controls. The control class deals
with controls processing image, for example digital gain or noise filtering,
which can be present in any part of the pipeline.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 Documentation/DocBook/media/v4l/controls.xml       |   82 ++++++++++++++++++++
 .../DocBook/media/v4l/vidioc-g-ext-ctrls.xml       |    6 ++
 drivers/media/video/v4l2-ctrls.c                   |   13 +++
 include/linux/videodev2.h                          |    8 ++
 4 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/Documentation/DocBook/media/v4l/controls.xml b/Documentation/DocBook/media/v4l/controls.xml
index 2257db4..4ca03f1 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -3524,4 +3524,86 @@ interface and may change in the future.</para>
 
     </section>
 
+    <section id="image-process-controls">
+      <title>Image Process Control Reference</title>
+
+      <note>
+	<title>Experimental</title>
+
+	<para>This is an <link
+	linkend="experimental">experimental</link> interface and may
+	change in the future.</para>
+      </note>
+
+      <para>
+	The Image Source control class is intended for low-level control of
+	image processing functions. Unlike
+	<constant>V4L2_CID_IMAGE_SOURCE_CLASS</constant>, the controls in
+	this class affect processing the image, and do not control capturing
+	of it.
+      </para>
+
+      <table pgwide="1" frame="none" id="image-process-control-id">
+      <title>Image Source Control IDs</title>
+
+      <tgroup cols="4">
+	<colspec colname="c1" colwidth="1*" />
+	<colspec colname="c2" colwidth="6*" />
+	<colspec colname="c3" colwidth="2*" />
+	<colspec colname="c4" colwidth="6*" />
+	<spanspec namest="c1" nameend="c2" spanname="id" />
+	<spanspec namest="c2" nameend="c4" spanname="descr" />
+	<thead>
+	  <row>
+	    <entry spanname="id" align="left">ID</entry>
+	    <entry align="left">Type</entry>
+	  </row><row rowsep="1"><entry spanname="descr" align="left">Description</entry>
+	  </row>
+	</thead>
+	<tbody valign="top">
+	  <row><entry></entry></row>
+	  <row>
+	    <entry spanname="id"><constant>V4L2_CID_IMAGE_PROC_CLASS</constant></entry>
+	    <entry>class</entry>
+	  </row>
+	  <row>
+	    <entry spanname="descr">The IMAGE_PROC class descriptor.</entry>
+	  </row>
+	  <row>
+	    <entry spanname="id"><constant>V4L2_CID_LINK_FREQ</constant></entry>
+	    <entry>integer menu</entry>
+	  </row>
+	  <row>
+	    <entry spanname="descr">Data bus frequency. Together with the
+	    media bus pixel code, bus type (clock cycles per sample), the
+	    data bus frequency defines the pixel rate
+	    (<constant>V4L2_CID_PIXEL_RATE</constant>) in the
+	    pixel array (or possibly elsewhere, if the device is not an
+	    image sensor). The frame rate can be calculated from the pixel
+	    clock, image width and height and horizontal and vertical
+	    blanking. While the pixel rate control may be defined elsewhere
+	    than in the subdev containing the pixel array, the frame rate
+	    cannot be obtained from that information. This is because only
+	    on the pixel array it can be assumed that the vertical and
+	    horizontal blanking information is exact: no other blanking is
+	    allowed in the pixel array. The selection of frame rate is
+	    performed by selecting the desired horizontal and vertical
+	    blanking. The unit of this control is Hz. </entry>
+	  </row>
+	  <row>
+	    <entry spanname="id"><constant>V4L2_CID_PIXEL_RATE</constant></entry>
+	    <entry>64-bit integer</entry>
+	  </row>
+	  <row>
+	    <entry spanname="descr">Pixel rate in the source pads of
+	    the subdev. This control is read-only and its unit is
+	    pixels / second.
+	    </entry>
+	  </row>
+	  <row><entry></entry></row>
+	</tbody>
+      </tgroup>
+      </table>
+
+    </section>
 </section>
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
index f420034..f41a2f5 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
@@ -271,6 +271,12 @@ These controls are described in <xref
 	    source controls. These controls are described in <xref
 	    linkend="image-source-controls" />.</entry>
 	  </row>
+	  <row>
+	    <entry><constant>V4L2_CTRL_CLASS_IMAGE_PROC</constant></entry>
+	    <entry>0x9e0000</entry> <entry>The class containing image
+	    processing controls. These controls are described in <xref
+	    linkend="image-process-controls" />.</entry>
+	  </row>
 	</tbody>
       </tgroup>
     </table>
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
index 3ca6bc7..1cbf97f 100644
--- a/drivers/media/video/v4l2-ctrls.c
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -629,6 +629,11 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_HBLANK:			return "Horizontal Blanking";
 	case V4L2_CID_ANALOGUE_GAIN:		return "Analogue Gain";
 
+	/* Image processing controls */
+	case V4L2_CID_IMAGE_PROC_CLASS:		return "Image Processing Controls";
+	case V4L2_CID_LINK_FREQ:		return "Link Frequency";
+	case V4L2_CID_PIXEL_RATE:		return "Pixel Rate";
+
 	default:
 		return NULL;
 	}
@@ -719,6 +724,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
 		*type = V4L2_CTRL_TYPE_MENU;
 		break;
+	case V4L2_CID_LINK_FREQ:
+		*type = V4L2_CTRL_TYPE_INTEGER_MENU;
+		break;
 	case V4L2_CID_RDS_TX_PS_NAME:
 	case V4L2_CID_RDS_TX_RADIO_TEXT:
 		*type = V4L2_CTRL_TYPE_STRING;
@@ -729,6 +737,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_FM_TX_CLASS:
 	case V4L2_CID_FLASH_CLASS:
 	case V4L2_CID_IMAGE_SOURCE_CLASS:
+	case V4L2_CID_IMAGE_PROC_CLASS:
 		*type = V4L2_CTRL_TYPE_CTRL_CLASS;
 		/* You can neither read not write these */
 		*flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
@@ -754,6 +763,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 		*type = V4L2_CTRL_TYPE_INTEGER64;
 		*flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_VOLATILE;
 		break;
+	case V4L2_CID_PIXEL_RATE:
+		*type = V4L2_CTRL_TYPE_INTEGER64;
+		*flags |= V4L2_CTRL_FLAG_READ_ONLY;
+		break;
 	default:
 		*type = V4L2_CTRL_TYPE_INTEGER;
 		break;
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index ca64202..f46350e 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -1137,6 +1137,7 @@ struct v4l2_ext_controls {
 #define V4L2_CTRL_CLASS_FM_TX 0x009b0000	/* FM Modulator control class */
 #define V4L2_CTRL_CLASS_FLASH 0x009c0000	/* Camera flash controls */
 #define V4L2_CTRL_CLASS_IMAGE_SOURCE 0x009d0000	/* Image source controls */
+#define V4L2_CTRL_CLASS_IMAGE_PROC 0x009e0000	/* Image processing controls */
 
 #define V4L2_CTRL_ID_MASK      	  (0x0fffffff)
 #define V4L2_CTRL_ID2CLASS(id)    ((id) & 0x0fff0000UL)
@@ -1771,6 +1772,13 @@ enum v4l2_flash_strobe_source {
 #define V4L2_CID_HBLANK				(V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 2)
 #define V4L2_CID_ANALOGUE_GAIN			(V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 3)
 
+/* Image processing controls */
+#define V4L2_CID_IMAGE_PROC_CLASS_BASE		(V4L2_CTRL_CLASS_IMAGE_PROC | 0x900)
+#define V4L2_CID_IMAGE_PROC_CLASS		(V4L2_CTRL_CLASS_IMAGE_PROC | 1)
+
+#define V4L2_CID_LINK_FREQ			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 1)
+#define V4L2_CID_PIXEL_RATE			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 2)
+
 /*
  *	T U N I N G
  */
-- 
1.7.2.5


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

* [PATCH v3 13/33] v4l: Document raw bayer 4CC codes
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (11 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 12/33] v4l: Image processing " Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 14/33] v4l: Add DPCM compressed formats Sakari Ailus
                   ` (20 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Document guidelines how 4CC codes should be named. Only raw bayer is
included currently. Other formats should be documented later on.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 Documentation/video4linux/4CCs.txt |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/video4linux/4CCs.txt

diff --git a/Documentation/video4linux/4CCs.txt b/Documentation/video4linux/4CCs.txt
new file mode 100644
index 0000000..41241af
--- /dev/null
+++ b/Documentation/video4linux/4CCs.txt
@@ -0,0 +1,32 @@
+Guidelines for Linux4Linux pixel format 4CCs
+============================================
+
+Guidelines for Video4Linux 4CC codes defined using v4l2_fourcc() are
+specified in this document. First of the characters defines the nature of
+the pixel format, compression and colour space. The interpretation of the
+other three characters depends on the first one.
+
+Existing 4CCs may not obey these guidelines.
+
+Formats
+=======
+
+Raw bayer
+---------
+
+The following first characters are used by raw bayer formats:
+
+	B: raw bayer, uncompressed
+	b: raw bayer, DPCM compressed
+	a: A-law compressed
+	u: u-law compressed
+
+2nd character: pixel order
+	B: BGGR
+	G: GBRG
+	g: GRBG
+	R: RGGB
+
+3rd character: uncompressed bits-per-pixel 0--9, A--
+
+4th character: compressed bits-per-pixel 0--9, A--
-- 
1.7.2.5


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

* [PATCH v3 14/33] v4l: Add DPCM compressed formats
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (12 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 13/33] v4l: Document raw bayer 4CC codes Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 15/33] media: Add link_validate() op to check links to the sink pad Sakari Ailus
                   ` (19 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Add three other colour orders for 10-bit to 8-bit DPCM compressed formats.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 Documentation/DocBook/media/v4l/pixfmt-srggb10.xml |    2 +-
 .../DocBook/media/v4l/pixfmt-srggb10dpcm8.xml      |   29 ++++++++++++++++++++
 Documentation/DocBook/media/v4l/pixfmt.xml         |    1 +
 include/linux/videodev2.h                          |    3 ++
 4 files changed, 34 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/DocBook/media/v4l/pixfmt-srggb10dpcm8.xml

diff --git a/Documentation/DocBook/media/v4l/pixfmt-srggb10.xml b/Documentation/DocBook/media/v4l/pixfmt-srggb10.xml
index 7b27409..c1c62a9 100644
--- a/Documentation/DocBook/media/v4l/pixfmt-srggb10.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt-srggb10.xml
@@ -1,4 +1,4 @@
-    <refentry>
+    <refentry id="pixfmt-srggb10">
       <refmeta>
 	<refentrytitle>V4L2_PIX_FMT_SRGGB10 ('RG10'),
 	 V4L2_PIX_FMT_SGRBG10 ('BA10'),
diff --git a/Documentation/DocBook/media/v4l/pixfmt-srggb10dpcm8.xml b/Documentation/DocBook/media/v4l/pixfmt-srggb10dpcm8.xml
new file mode 100644
index 0000000..40455f1
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/pixfmt-srggb10dpcm8.xml
@@ -0,0 +1,29 @@
+    <refentry>
+      <refmeta>
+	<refentrytitle>
+	 V4L2_PIX_FMT_SRGGB10DPCM8 ('bBA8'),
+	 V4L2_PIX_FMT_SGBRG10DPCM8 ('bGA8'),
+	 V4L2_PIX_FMT_SGRBG10DPCM8 ('BD10'),
+	 V4L2_PIX_FMT_SBGGR10DPCM8 ('bRA8'),
+	 </refentrytitle>
+	&manvol;
+      </refmeta>
+      <refnamediv>
+	<refname id="V4L2-PIX-FMT-SRGGB10DPCM8"><constant>V4L2_PIX_FMT_SRGGB10DPCM8</constant></refname>
+	<refname id="V4L2-PIX-FMT-SGRBG10DPCM8"><constant>V4L2_PIX_FMT_SGRBG10DPCM8</constant></refname>
+	<refname id="V4L2-PIX-FMT-SGBRG10DPCM8"><constant>V4L2_PIX_FMT_SGBRG10DPCM8</constant></refname>
+	<refname id="V4L2-PIX-FMT-SBGGR10DPCM8"><constant>V4L2_PIX_FMT_SBGGR10DPCM8</constant></refname>
+	<refpurpose>10-bit Bayer formats compressed to 8 bits</refpurpose>
+      </refnamediv>
+      <refsect1>
+	<title>Description</title>
+
+	<para>The following four pixel formats are raw sRGB / Bayer formats
+	with 10 bits per colour compressed to 8 bits each, using DPCM
+	compression. DPCM, differential pulse-code modulation, is lossy.
+	Each colour component consumes 8 bits of memory. In other respects
+	this format is similar to <xref
+	linkend="pixfmt-srggb10">.</xref></para>
+
+      </refsect1>
+    </refentry>
diff --git a/Documentation/DocBook/media/v4l/pixfmt.xml b/Documentation/DocBook/media/v4l/pixfmt.xml
index 31eaae2..74d4fcd 100644
--- a/Documentation/DocBook/media/v4l/pixfmt.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt.xml
@@ -673,6 +673,7 @@ access the palette, this must be done with ioctls of the Linux framebuffer API.<
     &sub-srggb8;
     &sub-sbggr16;
     &sub-srggb10;
+    &sub-srggb10dpcm8;
     &sub-srggb12;
   </section>
 
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index f46350e..76f3153 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -378,7 +378,10 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_SGRBG12 v4l2_fourcc('B', 'A', '1', '2') /* 12  GRGR.. BGBG.. */
 #define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2') /* 12  RGRG.. GBGB.. */
 	/* 10bit raw bayer DPCM compressed to 8 bits */
+#define V4L2_PIX_FMT_SBGGR10DPCM8 v4l2_fourcc('b', 'B', 'A', '8')
+#define V4L2_PIX_FMT_SGBRG10DPCM8 v4l2_fourcc('b', 'G', 'A', '8')
 #define V4L2_PIX_FMT_SGRBG10DPCM8 v4l2_fourcc('B', 'D', '1', '0')
+#define V4L2_PIX_FMT_SRGGB10DPCM8 v4l2_fourcc('b', 'R', 'A', '8')
 	/*
 	 * 10bit raw bayer, expanded to 16 bits
 	 * xxxxrrrrrrrrrrxxxxgggggggggg xxxxggggggggggxxxxbbbbbbbbbb...
-- 
1.7.2.5


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

* [PATCH v3 15/33] media: Add link_validate() op to check links to the sink pad
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (13 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 14/33] v4l: Add DPCM compressed formats Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-22 10:05   ` Laurent Pinchart
  2012-02-20  1:56 ` [PATCH v3 16/33] v4l: Improve sub-device documentation for pad ops Sakari Ailus
                   ` (18 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

The purpose of the link_validate() op is to allow an entity driver to ensure
that the properties of the pads at the both ends of the link are suitable
for starting the pipeline. link_validate is called on sink pads on active
links which belong to the active part of the graph.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 Documentation/media-framework.txt |   19 +++++++++++++
 drivers/media/media-entity.c      |   53 +++++++++++++++++++++++++++++++++++-
 include/media/media-entity.h      |    5 ++-
 3 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 3a0f879..0e90169 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -335,6 +335,9 @@ the media_entity pipe field.
 Calls to media_entity_pipeline_start() can be nested. The pipeline pointer must
 be identical for all nested calls to the function.
 
+media_entity_pipeline_start() may return an error. In that case, it will
+clean up any the changes it did by itself.
+
 When stopping the stream, drivers must notify the entities with
 
 	media_entity_pipeline_stop(struct media_entity *entity);
@@ -351,3 +354,19 @@ If other operations need to be disallowed on streaming entities (such as
 changing entities configuration parameters) drivers can explicitly check the
 media_entity stream_count field to find out if an entity is streaming. This
 operation must be done with the media_device graph_mutex held.
+
+
+Link validation
+---------------
+
+Link validation is performed from media_entity_pipeline_start() for any
+entity which has sink pads in the pipeline. The
+media_entity::link_validate() callback is used for that purpose. In
+link_validate() callback, entity driver should check that the properties of
+the source pad of the connected entity and its own sink pad match. It is up
+to the type of the entity (and in the end, the properties of the hardware)
+what matching actually means.
+
+Subsystems should facilitate link validation by providing subsystem specific
+helper functions to provide easy access for commonly needed information, and
+in the end provide a way to use driver-specific callbacks.
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 056138f..678ec07 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -214,23 +214,72 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
  * pipeline pointer must be identical for all nested calls to
  * media_entity_pipeline_start().
  */
-void media_entity_pipeline_start(struct media_entity *entity,
-				 struct media_pipeline *pipe)
+__must_check int media_entity_pipeline_start(struct media_entity *entity,
+					     struct media_pipeline *pipe)
 {
 	struct media_device *mdev = entity->parent;
 	struct media_entity_graph graph;
+	struct media_entity *entity_err = entity;
+	int ret = 0;
 
 	mutex_lock(&mdev->graph_mutex);
 
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
+		int i;
+
 		entity->stream_count++;
 		WARN_ON(entity->pipe && entity->pipe != pipe);
 		entity->pipe = pipe;
+
+		/* Already streaming --- no need to check. */
+		if (entity->stream_count > 1)
+			continue;
+
+		if (!entity->ops || !entity->ops->link_validate)
+			continue;
+
+		for (i = 0; i < entity->num_links; i++) {
+			struct media_link *link = &entity->links[i];
+
+			/* Is this pad part of an enabled link? */
+			if ((link->flags & MEDIA_LNK_FL_ENABLED)
+			    != MEDIA_LNK_FL_ENABLED)
+				continue;
+
+			/* Are we the sink or not? */
+			if (link->sink->entity != entity)
+				continue;
+
+			ret = entity->ops->link_validate(link);
+			if (ret < 0 && ret != -ENOIOCTLCMD)
+				break;
+		}
+		if (ret < 0 && ret != -ENOIOCTLCMD)
+			goto error;
 	}
 
 	mutex_unlock(&mdev->graph_mutex);
+
+	return 0;
+
+error:
+	/*
+	 * Link validation on graph failed. We revert what we did and
+	 * return the error.
+	 */
+	media_entity_graph_walk_start(&graph, entity_err);
+	do {
+		entity_err = media_entity_graph_walk_next(&graph);
+		entity_err->stream_count--;
+		if (entity_err->stream_count == 0)
+			entity_err->pipe = NULL;
+	} while (entity_err != entity);
+
+	mutex_unlock(&mdev->graph_mutex);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
 
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 29e7bba..0c16f51 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -46,6 +46,7 @@ struct media_entity_operations {
 	int (*link_setup)(struct media_entity *entity,
 			  const struct media_pad *local,
 			  const struct media_pad *remote, u32 flags);
+	int (*link_validate)(struct media_link *link);
 };
 
 struct media_entity {
@@ -140,8 +141,8 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 		struct media_entity *entity);
 struct media_entity *
 media_entity_graph_walk_next(struct media_entity_graph *graph);
-void media_entity_pipeline_start(struct media_entity *entity,
-		struct media_pipeline *pipe);
+__must_check int media_entity_pipeline_start(struct media_entity *entity,
+					     struct media_pipeline *pipe);
 void media_entity_pipeline_stop(struct media_entity *entity);
 
 #define media_entity_call(entity, operation, args...)			\
-- 
1.7.2.5


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

* [PATCH v3 16/33] v4l: Improve sub-device documentation for pad ops
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (14 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 15/33] media: Add link_validate() op to check links to the sink pad Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-22 10:06   ` Laurent Pinchart
  2012-02-20  1:56 ` [PATCH v3 17/33] v4l: Implement v4l2_subdev_link_validate() Sakari Ailus
                   ` (17 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Document that format related configuration is done through pad ops in case
the driver does use the media framework.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 Documentation/video4linux/v4l2-framework.txt |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index 659b2ba..f06c563 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -262,11 +262,16 @@ struct v4l2_subdev_video_ops {
 	...
 };
 
+struct v4l2_subdev_pad_ops {
+	...
+};
+
 struct v4l2_subdev_ops {
 	const struct v4l2_subdev_core_ops  *core;
 	const struct v4l2_subdev_tuner_ops *tuner;
 	const struct v4l2_subdev_audio_ops *audio;
 	const struct v4l2_subdev_video_ops *video;
+	const struct v4l2_subdev_pad_ops *video;
 };
 
 The core ops are common to all subdevs, the other categories are implemented
@@ -303,6 +308,10 @@ Don't forget to cleanup the media entity before the sub-device is destroyed:
 
 	media_entity_cleanup(&sd->entity);
 
+If the subdev driver intends to process video and integrate with the media
+framework, it must implement format related functionality using
+v4l2_subdev_pad_ops instead of v4l2_subdev_video_ops.
+
 A device (bridge) driver needs to register the v4l2_subdev with the
 v4l2_device:
 
-- 
1.7.2.5


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

* [PATCH v3 17/33] v4l: Implement v4l2_subdev_link_validate()
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (15 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 16/33] v4l: Improve sub-device documentation for pad ops Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-22 10:14   ` Laurent Pinchart
  2012-02-20  1:56 ` [PATCH v3 18/33] v4l: Allow changing control handler lock Sakari Ailus
                   ` (16 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

v4l2_subdev_link_validate() is the default op for validating a link. In V4L2
subdev context, it is used to call a pad op which performs the proper link
check without much extra work.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 Documentation/video4linux/v4l2-framework.txt |   12 +++++
 drivers/media/video/v4l2-subdev.c            |   69 ++++++++++++++++++++++++++
 include/media/v4l2-subdev.h                  |   12 +++++
 3 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index f06c563..9d341bc 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -312,6 +312,18 @@ If the subdev driver intends to process video and integrate with the media
 framework, it must implement format related functionality using
 v4l2_subdev_pad_ops instead of v4l2_subdev_video_ops.
 
+In that case, the subdev driver may set the link_validate field to provide
+its own link validation function. The link validation function is called for
+every link in the pipeline where both of the ends of the links are V4L2
+sub-devices. The driver is still responsible for validating the correctness
+of the format configuration between sub-devices and video nodes.
+
+If link_validate op is not set, the default function
+v4l2_subdev_link_validate_default() is used instead. This function ensures
+that width, height and the media bus pixel code are equal on both source and
+sink of the link. Subdev drivers are also free to use this function to
+perform the checks mentioned above in addition to their own checks.
+
 A device (bridge) driver needs to register the v4l2_subdev with the
 v4l2_device:
 
diff --git a/drivers/media/video/v4l2-subdev.c b/drivers/media/video/v4l2-subdev.c
index ef27144..d2ec552 100644
--- a/drivers/media/video/v4l2-subdev.c
+++ b/drivers/media/video/v4l2-subdev.c
@@ -379,6 +379,75 @@ const struct v4l2_file_operations v4l2_subdev_fops = {
 	.poll = subdev_poll,
 };
 
+#ifdef CONFIG_MEDIA_CONTROLLER
+int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
+				      struct media_link *link,
+				      struct v4l2_subdev_format *source_fmt,
+				      struct v4l2_subdev_format *sink_fmt)
+{
+	if (source_fmt->format.width != sink_fmt->format.width
+	    || source_fmt->format.height != sink_fmt->format.height
+	    || source_fmt->format.code != sink_fmt->format.code)
+		return -EINVAL;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate_default);
+
+static struct v4l2_subdev_format
+*v4l2_subdev_link_validate_get_format(struct media_pad *pad,
+				      struct v4l2_subdev_format *fmt)
+{
+	int rval;
+
+	switch (media_entity_type(pad->entity)) {
+	case MEDIA_ENT_T_V4L2_SUBDEV:
+		fmt->which = V4L2_SUBDEV_FORMAT_ACTIVE;
+		fmt->pad = pad->index;
+		rval = v4l2_subdev_call(media_entity_to_v4l2_subdev(
+						pad->entity),
+					pad, get_fmt, NULL, fmt);
+		if (rval < 0)
+			return NULL;
+		return fmt;
+	default:
+		WARN(1, "Driver bug! Wrong media entity type %d, entity %s\n",
+		     media_entity_type(pad->entity), pad->entity->name);
+		/* Fall through */
+	case MEDIA_ENT_T_DEVNODE_V4L:
+		return NULL;
+	}
+}
+
+int v4l2_subdev_link_validate(struct media_link *link)
+{
+	struct v4l2_subdev *sink;
+	struct v4l2_subdev_format _sink_fmt, _source_fmt;
+	struct v4l2_subdev_format *sink_fmt, *source_fmt;
+	int rval;
+
+	source_fmt = v4l2_subdev_link_validate_get_format(
+		link->source, &_source_fmt);
+	if (!source_fmt)
+		return 0;
+
+	sink_fmt = v4l2_subdev_link_validate_get_format(
+		link->sink, &_sink_fmt);
+	if (!sink_fmt)
+		return 0;
+
+	sink = media_entity_to_v4l2_subdev(link->sink->entity);
+
+	rval = v4l2_subdev_call(sink, pad, link_validate, link,
+				source_fmt, sink_fmt);
+	if (rval < 0 && rval != -ENOIOCTLCMD)
+		return rval;
+	return v4l2_subdev_link_validate_default(sink, link, source_fmt,
+						 sink_fmt);
+}
+EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate);
+#endif /* CONFIG_MEDIA_CONTROLLER */
+
 void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
 {
 	INIT_LIST_HEAD(&sd->list);
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index d48dae5..f115608 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -470,6 +470,11 @@ struct v4l2_subdev_pad_ops {
 			     struct v4l2_subdev_selection *sel);
 	int (*set_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
 			     struct v4l2_subdev_selection *sel);
+#ifdef CONFIG_MEDIA_CONTROLLER
+	int (*link_validate)(struct v4l2_subdev *sd, struct media_link *link,
+			     struct v4l2_subdev_format *source_fmt,
+			     struct v4l2_subdev_format *sink_fmt);
+#endif /* CONFIG_MEDIA_CONTROLLER */
 };
 
 struct v4l2_subdev_ops {
@@ -603,6 +608,13 @@ static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
 	return sd->host_priv;
 }
 
+#ifdef CONFIG_MEDIA_CONTROLLER
+int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
+				      struct media_link *link,
+				      struct v4l2_subdev_format *source_fmt,
+				      struct v4l2_subdev_format *sink_fmt);
+int v4l2_subdev_link_validate(struct media_link *link);
+#endif /* CONFIG_MEDIA_CONTROLLER */
 void v4l2_subdev_init(struct v4l2_subdev *sd,
 		      const struct v4l2_subdev_ops *ops);
 
-- 
1.7.2.5


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

* [PATCH v3 18/33] v4l: Allow changing control handler lock
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (16 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 17/33] v4l: Implement v4l2_subdev_link_validate() Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 19/33] omap3isp: Support additional in-memory compressed bayer formats Sakari Ailus
                   ` (15 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Allow choosing the lock used by the control handler. This may be handy
sometimes when a driver providing multiple subdevs does not want to use
several locks to serialise its functions.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/adp1653.c    |    8 +++---
 drivers/media/video/v4l2-ctrls.c |   39 +++++++++++++++++++------------------
 drivers/media/video/vivi.c       |    4 +-
 include/media/v4l2-ctrls.h       |    9 +++++--
 4 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/drivers/media/video/adp1653.c b/drivers/media/video/adp1653.c
index 12eedf4..becaba4 100644
--- a/drivers/media/video/adp1653.c
+++ b/drivers/media/video/adp1653.c
@@ -283,19 +283,19 @@ adp1653_init_device(struct adp1653_flash *flash)
 		return -EIO;
 	}
 
-	mutex_lock(&flash->ctrls.lock);
+	mutex_lock(flash->ctrls.lock);
 	/* Reset faults before reading new ones. */
 	flash->fault = 0;
 	rval = adp1653_get_fault(flash);
-	mutex_unlock(&flash->ctrls.lock);
+	mutex_unlock(flash->ctrls.lock);
 	if (rval > 0) {
 		dev_err(&client->dev, "faults detected: 0x%1.1x\n", rval);
 		return -EIO;
 	}
 
-	mutex_lock(&flash->ctrls.lock);
+	mutex_lock(flash->ctrls.lock);
 	rval = adp1653_update_hw(flash);
-	mutex_unlock(&flash->ctrls.lock);
+	mutex_unlock(flash->ctrls.lock);
 	if (rval) {
 		dev_err(&client->dev,
 			"adp1653_update_hw failed at %s\n", __func__);
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
index 1cbf97f..c38055f 100644
--- a/drivers/media/video/v4l2-ctrls.c
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -1153,7 +1153,8 @@ static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err)
 int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl,
 			   unsigned nr_of_controls_hint)
 {
-	mutex_init(&hdl->lock);
+	hdl->lock = &hdl->_lock;
+	mutex_init(hdl->lock);
 	INIT_LIST_HEAD(&hdl->ctrls);
 	INIT_LIST_HEAD(&hdl->ctrl_refs);
 	hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8;
@@ -1174,7 +1175,7 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
 	if (hdl == NULL || hdl->buckets == NULL)
 		return;
 
-	mutex_lock(&hdl->lock);
+	mutex_lock(hdl->lock);
 	/* Free all nodes */
 	list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) {
 		list_del(&ref->node);
@@ -1191,7 +1192,7 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
 	hdl->buckets = NULL;
 	hdl->cached = NULL;
 	hdl->error = 0;
-	mutex_unlock(&hdl->lock);
+	mutex_unlock(hdl->lock);
 }
 EXPORT_SYMBOL(v4l2_ctrl_handler_free);
 
@@ -1256,9 +1257,9 @@ static struct v4l2_ctrl_ref *find_ref_lock(
 	struct v4l2_ctrl_ref *ref = NULL;
 
 	if (hdl) {
-		mutex_lock(&hdl->lock);
+		mutex_lock(hdl->lock);
 		ref = find_ref(hdl, id);
-		mutex_unlock(&hdl->lock);
+		mutex_unlock(hdl->lock);
 	}
 	return ref;
 }
@@ -1305,7 +1306,7 @@ static int handler_new_ref(struct v4l2_ctrl_handler *hdl,
 
 	INIT_LIST_HEAD(&new_ref->node);
 
-	mutex_lock(&hdl->lock);
+	mutex_lock(hdl->lock);
 
 	/* Add immediately at the end of the list if the list is empty, or if
 	   the last element in the list has a lower ID.
@@ -1335,7 +1336,7 @@ insert_in_hash:
 	hdl->buckets[bucket] = new_ref;
 
 unlock:
-	mutex_unlock(&hdl->lock);
+	mutex_unlock(hdl->lock);
 	return 0;
 }
 
@@ -1421,9 +1422,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 		kfree(ctrl);
 		return NULL;
 	}
-	mutex_lock(&hdl->lock);
+	mutex_lock(hdl->lock);
 	list_add_tail(&ctrl->node, &hdl->ctrls);
-	mutex_unlock(&hdl->lock);
+	mutex_unlock(hdl->lock);
 	return ctrl;
 }
 
@@ -1540,7 +1541,7 @@ int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
 		return 0;
 	if (hdl->error)
 		return hdl->error;
-	mutex_lock(&add->lock);
+	mutex_lock(add->lock);
 	list_for_each_entry(ctrl, &add->ctrls, node) {
 		/* Skip handler-private controls. */
 		if (ctrl->is_private)
@@ -1552,7 +1553,7 @@ int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
 		if (ret)
 			break;
 	}
-	mutex_unlock(&add->lock);
+	mutex_unlock(add->lock);
 	return ret;
 }
 EXPORT_SYMBOL(v4l2_ctrl_add_handler);
@@ -1716,11 +1717,11 @@ void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
 	len = strlen(prefix);
 	if (len && prefix[len - 1] != ' ')
 		colon = ": ";
-	mutex_lock(&hdl->lock);
+	mutex_lock(hdl->lock);
 	list_for_each_entry(ctrl, &hdl->ctrls, node)
 		if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED))
 			log_ctrl(ctrl, prefix, colon);
-	mutex_unlock(&hdl->lock);
+	mutex_unlock(hdl->lock);
 }
 EXPORT_SYMBOL(v4l2_ctrl_handler_log_status);
 
@@ -1732,7 +1733,7 @@ int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
 
 	if (hdl == NULL)
 		return 0;
-	mutex_lock(&hdl->lock);
+	mutex_lock(hdl->lock);
 	list_for_each_entry(ctrl, &hdl->ctrls, node)
 		ctrl->done = false;
 
@@ -1757,7 +1758,7 @@ int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
 		if (ret)
 			break;
 	}
-	mutex_unlock(&hdl->lock);
+	mutex_unlock(hdl->lock);
 	return ret;
 }
 EXPORT_SYMBOL(v4l2_ctrl_handler_setup);
@@ -1772,7 +1773,7 @@ int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc)
 	if (hdl == NULL)
 		return -EINVAL;
 
-	mutex_lock(&hdl->lock);
+	mutex_lock(hdl->lock);
 
 	/* Try to find it */
 	ref = find_ref(hdl, id);
@@ -1797,7 +1798,7 @@ int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc)
 					break;
 		}
 	}
-	mutex_unlock(&hdl->lock);
+	mutex_unlock(hdl->lock);
 	if (!ref)
 		return -EINVAL;
 
@@ -1974,7 +1975,7 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
 	   belong to the same cluster. */
 
 	/* This has to be done with the handler lock taken. */
-	mutex_lock(&hdl->lock);
+	mutex_lock(hdl->lock);
 
 	/* First zero the helper field in the master control references */
 	for (i = 0; i < cs->count; i++)
@@ -1996,7 +1997,7 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
 		/* Point the mref helper to the current helper struct. */
 		mref->helper = h;
 	}
-	mutex_unlock(&hdl->lock);
+	mutex_unlock(hdl->lock);
 	return 0;
 }
 
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index d75a1e4..256e9ba 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -485,7 +485,7 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
 	gen_text(dev, vbuf, line++ * 16, 16, str);
 
 	gain = v4l2_ctrl_g_ctrl(dev->gain);
-	mutex_lock(&dev->ctrl_handler.lock);
+	mutex_lock(dev->ctrl_handler.lock);
 	snprintf(str, sizeof(str), " brightness %3d, contrast %3d, saturation %3d, hue %d ",
 			dev->brightness->cur.val,
 			dev->contrast->cur.val,
@@ -508,7 +508,7 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
 			dev->int_menu->qmenu_int[dev->int_menu->cur.val],
 			dev->int_menu->cur.val);
 	gen_text(dev, vbuf, line++ * 16, 16, str);
-	mutex_unlock(&dev->ctrl_handler.lock);
+	mutex_unlock(dev->ctrl_handler.lock);
 	gen_text(dev, vbuf, line++ * 16, 16, str);
 	if (dev->button_pressed) {
 		dev->button_pressed--;
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 533315b..71abac0 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -168,7 +168,9 @@ struct v4l2_ctrl_ref {
 /** struct v4l2_ctrl_handler - The control handler keeps track of all the
   * controls: both the controls owned by the handler and those inherited
   * from other handlers.
+  * @_lock:	Default for "lock".
   * @lock:	Lock to control access to this handler and its controls.
+  *		May be replaced by the user right after init.
   * @ctrls:	The list of controls owned by this handler.
   * @ctrl_refs:	The list of control references.
   * @cached:	The last found control reference. It is common that the same
@@ -179,7 +181,8 @@ struct v4l2_ctrl_ref {
   * @error:	The error code of the first failed control addition.
   */
 struct v4l2_ctrl_handler {
-	struct mutex lock;
+	struct mutex _lock;
+	struct mutex *lock;
 	struct list_head ctrls;
 	struct list_head ctrl_refs;
 	struct v4l2_ctrl_ref *cached;
@@ -456,7 +459,7 @@ void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
   */
 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
 {
-	mutex_lock(&ctrl->handler->lock);
+	mutex_lock(ctrl->handler->lock);
 }
 
 /** v4l2_ctrl_lock() - Helper function to unlock the handler
@@ -465,7 +468,7 @@ static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
   */
 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
 {
-	mutex_unlock(&ctrl->handler->lock);
+	mutex_unlock(ctrl->handler->lock);
 }
 
 /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver.
-- 
1.7.2.5


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

* [PATCH v3 19/33] omap3isp: Support additional in-memory compressed bayer formats
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (17 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 18/33] v4l: Allow changing control handler lock Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:56 ` [PATCH v3 20/33] omap3isp: Move definitions required by board code under include/media Sakari Ailus
                   ` (14 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

This also prevents accessing NULL pointer in csi2_try_format().

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/video/omap3isp/ispvideo.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/omap3isp/ispvideo.c b/drivers/media/video/omap3isp/ispvideo.c
index b020700..c191f13 100644
--- a/drivers/media/video/omap3isp/ispvideo.c
+++ b/drivers/media/video/omap3isp/ispvideo.c
@@ -46,6 +46,10 @@
  * Helper functions
  */
 
+/*
+ * NOTE: When adding new media bus codes, always remember to add
+ * corresponding in-memory formats to the table below!!!
+ */
 static struct isp_format_info formats[] = {
 	{ V4L2_MBUS_FMT_Y8_1X8, V4L2_MBUS_FMT_Y8_1X8,
 	  V4L2_MBUS_FMT_Y8_1X8, V4L2_MBUS_FMT_Y8_1X8,
@@ -68,9 +72,18 @@ static struct isp_format_info formats[] = {
 	{ V4L2_MBUS_FMT_SRGGB8_1X8, V4L2_MBUS_FMT_SRGGB8_1X8,
 	  V4L2_MBUS_FMT_SRGGB8_1X8, V4L2_MBUS_FMT_SRGGB8_1X8,
 	  V4L2_PIX_FMT_SRGGB8, 8, },
+	{ V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8,
+	  V4L2_MBUS_FMT_SBGGR10_1X10, 0,
+	  V4L2_PIX_FMT_SBGGR10DPCM8, 8, },
+	{ V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8,
+	  V4L2_MBUS_FMT_SGBRG10_1X10, 0,
+	  V4L2_PIX_FMT_SGBRG10DPCM8, 8, },
 	{ V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8,
 	  V4L2_MBUS_FMT_SGRBG10_1X10, 0,
 	  V4L2_PIX_FMT_SGRBG10DPCM8, 8, },
+	{ V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8,
+	  V4L2_MBUS_FMT_SRGGB10_1X10, 0,
+	  V4L2_PIX_FMT_SRGGB10DPCM8, 8, },
 	{ V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_MBUS_FMT_SBGGR10_1X10,
 	  V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_MBUS_FMT_SBGGR8_1X8,
 	  V4L2_PIX_FMT_SBGGR10, 10, },
-- 
1.7.2.5


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

* [PATCH v3 20/33] omap3isp: Move definitions required by board code under include/media.
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (18 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 19/33] omap3isp: Support additional in-memory compressed bayer formats Sakari Ailus
@ 2012-02-20  1:56 ` Sakari Ailus
  2012-02-20  1:57 ` [PATCH v3 21/33] omap3: add definition for CONTROL_CAMERA_PHY_CTRL Sakari Ailus
                   ` (13 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:56 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

XCLK definitions are often required by the board code. Move them to public
include file.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/video/omap3isp/isp.h |    4 ----
 include/media/omap3isp.h           |    4 ++++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/video/omap3isp/isp.h b/drivers/media/video/omap3isp/isp.h
index d96603e..2e78041 100644
--- a/drivers/media/video/omap3isp/isp.h
+++ b/drivers/media/video/omap3isp/isp.h
@@ -237,10 +237,6 @@ void omap3isp_configure_bridge(struct isp_device *isp,
 			       const struct isp_parallel_platform_data *pdata,
 			       unsigned int shift);
 
-#define ISP_XCLK_NONE			0
-#define ISP_XCLK_A			1
-#define ISP_XCLK_B			2
-
 struct isp_device *omap3isp_get(struct isp_device *isp);
 void omap3isp_put(struct isp_device *isp);
 
diff --git a/include/media/omap3isp.h b/include/media/omap3isp.h
index 042849a..3f4928d 100644
--- a/include/media/omap3isp.h
+++ b/include/media/omap3isp.h
@@ -29,6 +29,10 @@
 struct i2c_board_info;
 struct isp_device;
 
+#define ISP_XCLK_NONE			0
+#define ISP_XCLK_A			1
+#define ISP_XCLK_B			2
+
 enum isp_interface_type {
 	ISP_INTERFACE_PARALLEL,
 	ISP_INTERFACE_CSI2A_PHY2,
-- 
1.7.2.5


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

* [PATCH v3 21/33] omap3: add definition for CONTROL_CAMERA_PHY_CTRL
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (19 preceding siblings ...)
  2012-02-20  1:56 ` [PATCH v3 20/33] omap3isp: Move definitions required by board code under include/media Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-20  1:57 ` [PATCH v3 22/33] omap3isp: Assume media_entity_pipeline_start may fail Sakari Ailus
                   ` (12 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

This register is available only in OMAP3630.

The original patch was submitted by Vimarsh Zutshi.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 arch/arm/mach-omap2/control.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap2/control.h b/arch/arm/mach-omap2/control.h
index 0ba68d3..f3acf09 100644
--- a/arch/arm/mach-omap2/control.h
+++ b/arch/arm/mach-omap2/control.h
@@ -183,6 +183,7 @@
 #define OMAP3630_CONTROL_FUSE_OPP120_VDD1       (OMAP2_CONTROL_GENERAL + 0x0120)
 #define OMAP3630_CONTROL_FUSE_OPP50_VDD2        (OMAP2_CONTROL_GENERAL + 0x0128)
 #define OMAP3630_CONTROL_FUSE_OPP100_VDD2       (OMAP2_CONTROL_GENERAL + 0x012C)
+#define OMAP3630_CONTROL_CAMERA_PHY_CTRL	(OMAP2_CONTROL_GENERAL + 0x02f0)
 
 /* OMAP44xx control efuse offsets */
 #define OMAP44XX_CONTROL_FUSE_IVA_OPP50		0x22C
-- 
1.7.2.5


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

* [PATCH v3 22/33] omap3isp: Assume media_entity_pipeline_start may fail
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (20 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 21/33] omap3: add definition for CONTROL_CAMERA_PHY_CTRL Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-22 10:48   ` Laurent Pinchart
  2012-02-20  1:57 ` [PATCH v3 23/33] omap3isp: Add lane configuration to platform data Sakari Ailus
                   ` (11 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Since media_entity_pipeline_start() now does link validation, it may
actually fail. Perform the error handling.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/omap3isp/ispvideo.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/media/video/omap3isp/ispvideo.c b/drivers/media/video/omap3isp/ispvideo.c
index c191f13..17522db 100644
--- a/drivers/media/video/omap3isp/ispvideo.c
+++ b/drivers/media/video/omap3isp/ispvideo.c
@@ -993,14 +993,16 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 	 */
 	pipe = video->video.entity.pipe
 	     ? to_isp_pipeline(&video->video.entity) : &video->pipe;
-	media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
+	ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
+	if (ret < 0)
+		goto err_media_entity_pipeline_start;
 
 	/* Verify that the currently configured format matches the output of
 	 * the connected subdev.
 	 */
 	ret = isp_video_check_format(video, vfh);
 	if (ret < 0)
-		goto error;
+		goto err_isp_video_check_format;
 
 	video->bpl_padding = ret;
 	video->bpl_value = vfh->format.fmt.pix.bytesperline;
@@ -1017,7 +1019,7 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 	} else {
 		if (far_end == NULL) {
 			ret = -EPIPE;
-			goto error;
+			goto err_isp_video_check_format;
 		}
 
 		state = ISP_PIPELINE_STREAM_INPUT | ISP_PIPELINE_IDLE_INPUT;
@@ -1032,7 +1034,7 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 	/* Validate the pipeline and update its state. */
 	ret = isp_video_validate_pipeline(pipe);
 	if (ret < 0)
-		goto error;
+		goto err_isp_video_check_format;
 
 	pipe->error = false;
 
@@ -1054,7 +1056,7 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 
 	ret = omap3isp_video_queue_streamon(&vfh->queue);
 	if (ret < 0)
-		goto error;
+		goto err_isp_video_check_format;
 
 	/* In sensor-to-memory mode, the stream can be started synchronously
 	 * to the stream on command. In memory-to-memory mode, it will be
@@ -1064,19 +1066,21 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 		ret = omap3isp_pipeline_set_stream(pipe,
 					      ISP_PIPELINE_STREAM_CONTINUOUS);
 		if (ret < 0)
-			goto error;
+			goto err_omap3isp_set_stream;
 		spin_lock_irqsave(&video->queue->irqlock, flags);
 		if (list_empty(&video->dmaqueue))
 			video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
 		spin_unlock_irqrestore(&video->queue->irqlock, flags);
 	}
 
-error:
 	if (ret < 0) {
+err_omap3isp_set_stream:
 		omap3isp_video_queue_streamoff(&vfh->queue);
+err_isp_video_check_format:
+		media_entity_pipeline_stop(&video->video.entity);
+err_media_entity_pipeline_start:
 		if (video->isp->pdata->set_constraints)
 			video->isp->pdata->set_constraints(video->isp, false);
-		media_entity_pipeline_stop(&video->video.entity);
 		/* The DMA queue must be emptied here, otherwise CCDC interrupts
 		 * that will get triggered the next time the CCDC is powered up
 		 * will try to access buffers that might have been freed but
-- 
1.7.2.5


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

* [PATCH v3 23/33] omap3isp: Add lane configuration to platform data
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (21 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 22/33] omap3isp: Assume media_entity_pipeline_start may fail Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-20  1:57 ` [PATCH v3 24/33] omap3isp: Add information on external subdev to struct isp_pipeline Sakari Ailus
                   ` (10 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Add lane configuration (order of clock and data lane) to platform data on
both CCP2 and CSI-2.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/video/omap3isp/ispcsiphy.h |   15 ++-------------
 include/media/omap3isp.h                 |   25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/drivers/media/video/omap3isp/ispcsiphy.h b/drivers/media/video/omap3isp/ispcsiphy.h
index 9596dc6..e93a661 100644
--- a/drivers/media/video/omap3isp/ispcsiphy.h
+++ b/drivers/media/video/omap3isp/ispcsiphy.h
@@ -27,22 +27,11 @@
 #ifndef OMAP3_ISP_CSI_PHY_H
 #define OMAP3_ISP_CSI_PHY_H
 
+#include <media/omap3isp.h>
+
 struct isp_csi2_device;
 struct regulator;
 
-struct csiphy_lane {
-	u8 pos;
-	u8 pol;
-};
-
-#define ISP_CSIPHY2_NUM_DATA_LANES	2
-#define ISP_CSIPHY1_NUM_DATA_LANES	1
-
-struct isp_csiphy_lanes_cfg {
-	struct csiphy_lane data[ISP_CSIPHY2_NUM_DATA_LANES];
-	struct csiphy_lane clk;
-};
-
 struct isp_csiphy_dphy_cfg {
 	u8 ths_term;
 	u8 ths_settle;
diff --git a/include/media/omap3isp.h b/include/media/omap3isp.h
index 3f4928d..4d94be5 100644
--- a/include/media/omap3isp.h
+++ b/include/media/omap3isp.h
@@ -91,6 +91,29 @@ enum {
 };
 
 /**
+ * struct isp_csiphy_lane: CCP2/CSI2 lane position and polarity
+ * @pos: position of the lane
+ * @pol: polarity of the lane
+ */
+struct isp_csiphy_lane {
+	u8 pos;
+	u8 pol;
+};
+
+#define ISP_CSIPHY1_NUM_DATA_LANES	1
+#define ISP_CSIPHY2_NUM_DATA_LANES	2
+
+/**
+ * struct isp_csiphy_lanes_cfg - CCP2/CSI2 lane configuration
+ * @data: Configuration of one or two data lanes
+ * @clk: Clock lane configuration
+ */
+struct isp_csiphy_lanes_cfg {
+	struct isp_csiphy_lane data[ISP_CSIPHY2_NUM_DATA_LANES];
+	struct isp_csiphy_lane clk;
+};
+
+/**
  * struct isp_ccp2_platform_data - CCP2 interface platform data
  * @strobe_clk_pol: Strobe/clock polarity
  *		0 - Non Inverted, 1 - Inverted
@@ -109,6 +132,7 @@ struct isp_ccp2_platform_data {
 	unsigned int ccp2_mode:1;
 	unsigned int phy_layer:1;
 	unsigned int vpclk_div:2;
+	struct isp_csiphy_lanes_cfg lanecfg;
 };
 
 /**
@@ -119,6 +143,7 @@ struct isp_ccp2_platform_data {
 struct isp_csi2_platform_data {
 	unsigned crc:1;
 	unsigned vpclk_div:2;
+	struct isp_csiphy_lanes_cfg lanecfg;
 };
 
 struct isp_subdev_i2c_board_info {
-- 
1.7.2.5


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

* [PATCH v3 24/33] omap3isp: Add information on external subdev to struct isp_pipeline
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (22 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 23/33] omap3isp: Add lane configuration to platform data Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-20  1:57 ` [PATCH v3 25/33] omap3isp: Introduce omap3isp_get_external_info() Sakari Ailus
                   ` (9 subsequent siblings)
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Add pointer to external subdev, pixel rate of the external subdev and bpp of
the format to struct isp_pipeline.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/omap3isp/ispvideo.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/omap3isp/ispvideo.h b/drivers/media/video/omap3isp/ispvideo.h
index d91bdb9..b198723 100644
--- a/drivers/media/video/omap3isp/ispvideo.h
+++ b/drivers/media/video/omap3isp/ispvideo.h
@@ -102,6 +102,9 @@ struct isp_pipeline {
 	bool do_propagation; /* of frame number */
 	bool error;
 	struct v4l2_fract max_timeperframe;
+	struct v4l2_subdev *external;
+	unsigned int external_rate;
+	int external_bpp;
 };
 
 #define to_isp_pipeline(__e) \
-- 
1.7.2.5


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

* [PATCH v3 25/33] omap3isp: Introduce omap3isp_get_external_info()
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (23 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 24/33] omap3isp: Add information on external subdev to struct isp_pipeline Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-22 10:55   ` Laurent Pinchart
  2012-02-20  1:57 ` [PATCH v3 26/33] omap3isp: Default link validation for ccp2, csi2, preview and resizer Sakari Ailus
                   ` (8 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

omap3isp_get_external_info() will retrieve external subdev's bits-per-pixel
and pixel rate for the use of other ISP subdevs at streamon time.
omap3isp_get_external_info() is used during pipeline validation.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/omap3isp/isp.c |   48 ++++++++++++++++++++++++++++++++++++
 drivers/media/video/omap3isp/isp.h |    3 ++
 2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/omap3isp/isp.c b/drivers/media/video/omap3isp/isp.c
index 12d5f92..89a9bf8 100644
--- a/drivers/media/video/omap3isp/isp.c
+++ b/drivers/media/video/omap3isp/isp.c
@@ -353,6 +353,54 @@ void omap3isp_hist_dma_done(struct isp_device *isp)
 	}
 }
 
+int omap3isp_get_external_info(struct isp_pipeline *pipe,
+			       struct media_link *link)
+{
+	struct isp_device *isp =
+		container_of(pipe, struct isp_video, pipe)->isp;
+	struct v4l2_subdev_format fmt;
+	struct v4l2_ext_controls ctrls;
+	struct v4l2_ext_control ctrl;
+	int ret;
+
+	if (!pipe->external)
+		return 0;
+
+	if (pipe->external_rate)
+		return 0;
+
+	memset(&fmt, 0, sizeof(fmt));
+
+	fmt.pad = link->source->index;
+	fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+	ret = v4l2_subdev_call(media_entity_to_v4l2_subdev(link->sink->entity),
+			       pad, get_fmt, NULL, &fmt);
+	if (ret < 0)
+		return -EPIPE;
+
+	pipe->external_bpp = omap3isp_video_format_info(fmt.format.code)->bpp;
+
+	memset(&ctrls, 0, sizeof(ctrls));
+	memset(&ctrl, 0, sizeof(ctrl));
+
+	ctrl.id = V4L2_CID_PIXEL_RATE;
+
+	ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(ctrl.id);
+	ctrls.count = 1;
+	ctrls.controls = &ctrl;
+
+	ret = v4l2_g_ext_ctrls(pipe->external->ctrl_handler, &ctrls);
+	if (ret < 0) {
+		dev_warn(isp->dev, "no pixel rate control in subdev %s\n",
+			 pipe->external->name);
+		return ret;
+	}
+
+	pipe->external_rate = ctrl.value64;
+
+	return 0;
+}
+
 static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
 {
 	static const char *name[] = {
diff --git a/drivers/media/video/omap3isp/isp.h b/drivers/media/video/omap3isp/isp.h
index 2e78041..8b0bc2d 100644
--- a/drivers/media/video/omap3isp/isp.h
+++ b/drivers/media/video/omap3isp/isp.h
@@ -222,6 +222,9 @@ struct isp_device {
 
 void omap3isp_hist_dma_done(struct isp_device *isp);
 
+int omap3isp_get_external_info(struct isp_pipeline *pipe,
+			       struct media_link *link);
+
 void omap3isp_flush(struct isp_device *isp);
 
 int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
-- 
1.7.2.5


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

* [PATCH v3 26/33] omap3isp: Default link validation for ccp2, csi2, preview and resizer
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (24 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 25/33] omap3isp: Introduce omap3isp_get_external_info() Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-22 11:01   ` Laurent Pinchart
  2012-02-20  1:57 ` [PATCH v3 27/33] omap3isp: Implement proper CCDC link validation, check pixel rate Sakari Ailus
                   ` (7 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Use default link validation for ccp2, csi2, preview and resizer. On ccp2,
csi2 and ccdc we also collect information on external subdevs as one may be
connected to those entities.

The CCDC link validation still must be done separately.

Also set pipe->external correctly as we go

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/omap3isp/ispccdc.c    |   23 +++++++++++++++++++++++
 drivers/media/video/omap3isp/ispccp2.c    |   20 ++++++++++++++++++++
 drivers/media/video/omap3isp/ispcsi2.c    |   19 +++++++++++++++++++
 drivers/media/video/omap3isp/isppreview.c |    2 ++
 drivers/media/video/omap3isp/ispresizer.c |    2 ++
 drivers/media/video/omap3isp/ispvideo.c   |    4 ++++
 6 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/omap3isp/ispccdc.c b/drivers/media/video/omap3isp/ispccdc.c
index a74a797..6aff241 100644
--- a/drivers/media/video/omap3isp/ispccdc.c
+++ b/drivers/media/video/omap3isp/ispccdc.c
@@ -1999,6 +1999,27 @@ static int ccdc_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
 	return 0;
 }
 
+static int ccdc_link_validate(struct v4l2_subdev *sd,
+			      struct media_link *link,
+			      struct v4l2_subdev_format *source_fmt,
+			      struct v4l2_subdev_format *sink_fmt)
+{
+	struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
+	struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
+	int rval;
+
+	/* We've got a parallel sensor here. */
+	if (ccdc->input == CCDC_INPUT_PARALLEL) {
+		pipe->external =
+			media_entity_to_v4l2_subdev(link->source->entity);
+		rval = omap3isp_get_external_info(pipe, link);
+		if (rval < 0)
+			return 0;
+	}
+
+	return 0;
+}
+
 /*
  * ccdc_init_formats - Initialize formats on all pads
  * @sd: ISP CCDC V4L2 subdevice
@@ -2041,6 +2062,7 @@ static const struct v4l2_subdev_pad_ops ccdc_v4l2_pad_ops = {
 	.enum_frame_size = ccdc_enum_frame_size,
 	.get_fmt = ccdc_get_format,
 	.set_fmt = ccdc_set_format,
+	.link_validate = ccdc_link_validate,
 };
 
 /* V4L2 subdev operations */
@@ -2150,6 +2172,7 @@ static int ccdc_link_setup(struct media_entity *entity,
 /* media operations */
 static const struct media_entity_operations ccdc_media_ops = {
 	.link_setup = ccdc_link_setup,
+	.link_validate = v4l2_subdev_link_validate,
 };
 
 void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
diff --git a/drivers/media/video/omap3isp/ispccp2.c b/drivers/media/video/omap3isp/ispccp2.c
index 70ddbf3..4fb34ee 100644
--- a/drivers/media/video/omap3isp/ispccp2.c
+++ b/drivers/media/video/omap3isp/ispccp2.c
@@ -819,6 +819,24 @@ static int ccp2_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
 	return 0;
 }
 
+static int ccp2_link_validate(struct v4l2_subdev *sd, struct media_link *link,
+			      struct v4l2_subdev_format *source_fmt,
+			      struct v4l2_subdev_format *sink_fmt)
+{
+	struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
+	struct isp_pipeline *pipe = to_isp_pipeline(&ccp2->subdev.entity);
+	int rval;
+
+	pipe->external = media_entity_to_v4l2_subdev(link->source->entity);
+	rval = omap3isp_get_external_info(pipe, link);
+	if (rval < 0)
+		return rval;
+
+	return v4l2_subdev_link_validate_default(sd, link, source_fmt,
+						 sink_fmt);
+}
+
+
 /*
  * ccp2_init_formats - Initialize formats on all pads
  * @sd: ISP CCP2 V4L2 subdevice
@@ -925,6 +943,7 @@ static const struct v4l2_subdev_pad_ops ccp2_sd_pad_ops = {
 	.enum_frame_size = ccp2_enum_frame_size,
 	.get_fmt = ccp2_get_format,
 	.set_fmt = ccp2_set_format,
+	.link_validate = ccp2_link_validate,
 };
 
 /* subdev operations */
@@ -1021,6 +1040,7 @@ static int ccp2_link_setup(struct media_entity *entity,
 /* media operations */
 static const struct media_entity_operations ccp2_media_ops = {
 	.link_setup = ccp2_link_setup,
+	.link_validate = v4l2_subdev_link_validate,
 };
 
 /*
diff --git a/drivers/media/video/omap3isp/ispcsi2.c b/drivers/media/video/omap3isp/ispcsi2.c
index fcb5168..9313f7c 100644
--- a/drivers/media/video/omap3isp/ispcsi2.c
+++ b/drivers/media/video/omap3isp/ispcsi2.c
@@ -1012,6 +1012,23 @@ static int csi2_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
 	return 0;
 }
 
+static int csi2_link_validate(struct v4l2_subdev *sd, struct media_link *link,
+			      struct v4l2_subdev_format *source_fmt,
+			      struct v4l2_subdev_format *sink_fmt)
+{
+	struct isp_csi2_device *csi2 = v4l2_get_subdevdata(sd);
+	struct isp_pipeline *pipe = to_isp_pipeline(&csi2->subdev.entity);
+	int rval;
+
+	pipe->external = media_entity_to_v4l2_subdev(link->source->entity);
+	rval = omap3isp_get_external_info(pipe, link);
+	if (rval < 0)
+		return rval;
+
+	return v4l2_subdev_link_validate_default(sd, link, source_fmt,
+						 sink_fmt);
+}
+
 /*
  * csi2_init_formats - Initialize formats on all pads
  * @sd: ISP CSI2 V4L2 subdevice
@@ -1107,6 +1124,7 @@ static const struct v4l2_subdev_pad_ops csi2_pad_ops = {
 	.enum_frame_size = csi2_enum_frame_size,
 	.get_fmt = csi2_get_format,
 	.set_fmt = csi2_set_format,
+	.link_validate = csi2_link_validate,
 };
 
 /* subdev operations */
@@ -1181,6 +1199,7 @@ static int csi2_link_setup(struct media_entity *entity,
 /* media operations */
 static const struct media_entity_operations csi2_media_ops = {
 	.link_setup = csi2_link_setup,
+	.link_validate = v4l2_subdev_link_validate,
 };
 
 void omap3isp_csi2_unregister_entities(struct isp_csi2_device *csi2)
diff --git a/drivers/media/video/omap3isp/isppreview.c b/drivers/media/video/omap3isp/isppreview.c
index 6d0fb2c..c2bf500 100644
--- a/drivers/media/video/omap3isp/isppreview.c
+++ b/drivers/media/video/omap3isp/isppreview.c
@@ -1981,6 +1981,7 @@ static const struct v4l2_subdev_pad_ops preview_v4l2_pad_ops = {
 	.set_fmt = preview_set_format,
 	.get_crop = preview_get_crop,
 	.set_crop = preview_set_crop,
+	.link_validate = v4l2_subdev_link_validate_default,
 };
 
 /* subdev operations */
@@ -2076,6 +2077,7 @@ static int preview_link_setup(struct media_entity *entity,
 /* media operations */
 static const struct media_entity_operations preview_media_ops = {
 	.link_setup = preview_link_setup,
+	.link_validate = v4l2_subdev_link_validate,
 };
 
 void omap3isp_preview_unregister_entities(struct isp_prev_device *prev)
diff --git a/drivers/media/video/omap3isp/ispresizer.c b/drivers/media/video/omap3isp/ispresizer.c
index 6958a9e..6ce2349 100644
--- a/drivers/media/video/omap3isp/ispresizer.c
+++ b/drivers/media/video/omap3isp/ispresizer.c
@@ -1532,6 +1532,7 @@ static const struct v4l2_subdev_pad_ops resizer_v4l2_pad_ops = {
 	.set_fmt = resizer_set_format,
 	.get_crop = resizer_g_crop,
 	.set_crop = resizer_s_crop,
+	.link_validate = v4l2_subdev_link_validate_default,
 };
 
 /* subdev operations */
@@ -1603,6 +1604,7 @@ static int resizer_link_setup(struct media_entity *entity,
 /* media operations */
 static const struct media_entity_operations resizer_media_ops = {
 	.link_setup = resizer_link_setup,
+	.link_validate = v4l2_subdev_link_validate,
 };
 
 void omap3isp_resizer_unregister_entities(struct isp_res_device *res)
diff --git a/drivers/media/video/omap3isp/ispvideo.c b/drivers/media/video/omap3isp/ispvideo.c
index 17522db..f1c68ca 100644
--- a/drivers/media/video/omap3isp/ispvideo.c
+++ b/drivers/media/video/omap3isp/ispvideo.c
@@ -993,6 +993,10 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 	 */
 	pipe = video->video.entity.pipe
 	     ? to_isp_pipeline(&video->video.entity) : &video->pipe;
+	pipe->external = NULL;
+	pipe->external_rate = 0;
+	pipe->external_bpp = 0;
+
 	ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
 	if (ret < 0)
 		goto err_media_entity_pipeline_start;
-- 
1.7.2.5


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

* [PATCH v3 27/33] omap3isp: Implement proper CCDC link validation, check pixel rate
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (25 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 26/33] omap3isp: Default link validation for ccp2, csi2, preview and resizer Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-22 11:11   ` Laurent Pinchart
  2012-02-20  1:57 ` [PATCH v3 28/33] omap3isp: Move setting constaints above media_entity_pipeline_start Sakari Ailus
                   ` (6 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Implement correct link validation for the CCDC. Use external_rate from
isp_pipeline to configurat vp divisor and check that external_rate does not
exceed our data rate limitations.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/omap3isp/ispccdc.c |   69 +++++++++++++++++++++++++++++--
 1 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/drivers/media/video/omap3isp/ispccdc.c b/drivers/media/video/omap3isp/ispccdc.c
index 6aff241..1555891 100644
--- a/drivers/media/video/omap3isp/ispccdc.c
+++ b/drivers/media/video/omap3isp/ispccdc.c
@@ -836,8 +836,8 @@ static void ccdc_config_vp(struct isp_ccdc_device *ccdc)
 
 	if (pipe->input)
 		div = DIV_ROUND_UP(l3_ick, pipe->max_rate);
-	else if (ccdc->vpcfg.pixelclk)
-		div = l3_ick / ccdc->vpcfg.pixelclk;
+	else if (pipe->external_rate)
+		div = l3_ick / pipe->external_rate;
 
 	div = clamp(div, 2U, max_div);
 	fmtcfg_vp |= (div - 2) << ISPCCDC_FMTCFG_VPIF_FRQ_SHIFT;
@@ -1749,7 +1749,18 @@ static int ccdc_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	switch (enable) {
-	case ISP_PIPELINE_STREAM_CONTINUOUS:
+	case ISP_PIPELINE_STREAM_CONTINUOUS: {
+		struct isp_pipeline *pipe = to_isp_pipeline(&sd->entity);
+		unsigned int rate = UINT_MAX;
+
+		/*
+		 * Check that maximum allowed rate isn't exceeded by
+		 * the pixel rate.
+		 */
+		omap3isp_ccdc_max_rate(&isp->isp_ccdc, &rate);
+		if (pipe->external_rate > rate)
+			return -ENOSPC;
+
 		if (ccdc->output & CCDC_OUTPUT_MEMORY)
 			omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
 
@@ -1758,6 +1769,7 @@ static int ccdc_set_stream(struct v4l2_subdev *sd, int enable)
 
 		ccdc->underrun = 0;
 		break;
+	}
 
 	case ISP_PIPELINE_STREAM_SINGLESHOT:
 		if (ccdc->output & CCDC_OUTPUT_MEMORY &&
@@ -1999,6 +2011,37 @@ static int ccdc_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
 	return 0;
 }
 
+/*
+ * Decide whether desired output pixel code can be obtained with
+ * the lane shifter by shifting the input pixel code.
+ * @in: input pixelcode to shifter
+ * @out: output pixelcode from shifter
+ * @additional_shift: # of bits the sensor's LSB is offset from CAMEXT[0]
+ *
+ * return true if the combination is possible
+ * return false otherwise
+ */
+static bool ccdc_is_shiftable(enum v4l2_mbus_pixelcode in,
+			      enum v4l2_mbus_pixelcode out,
+			      unsigned int additional_shift)
+{
+	const struct isp_format_info *in_info, *out_info;
+
+	if (in == out)
+		return true;
+
+	in_info = omap3isp_video_format_info(in);
+	out_info = omap3isp_video_format_info(out);
+
+	if ((in_info->flavor == 0) || (out_info->flavor == 0))
+		return false;
+
+	if (in_info->flavor != out_info->flavor)
+		return false;
+
+	return in_info->bpp - out_info->bpp + additional_shift <= 6;
+}
+
 static int ccdc_link_validate(struct v4l2_subdev *sd,
 			      struct media_link *link,
 			      struct v4l2_subdev_format *source_fmt,
@@ -2008,13 +2051,31 @@ static int ccdc_link_validate(struct v4l2_subdev *sd,
 	struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
 	int rval;
 
+	/* Check if the two ends match */
+	if (source_fmt->format.width != sink_fmt->format.width ||
+	    source_fmt->format.height != sink_fmt->format.height)
+		return -EPIPE;
+
 	/* We've got a parallel sensor here. */
 	if (ccdc->input == CCDC_INPUT_PARALLEL) {
+		struct isp_parallel_platform_data *pdata =
+			&((struct isp_v4l2_subdevs_group *)
+			  media_entity_to_v4l2_subdev(link->source->entity)
+			  ->host_priv)->bus.parallel;
+		unsigned long parallel_shift = pdata->data_lane_shift * 2;
+		/* Lane shifter may be used to drop bits on CCDC sink pad */
+		if (!ccdc_is_shiftable(source_fmt->format.code,
+				       sink_fmt->format.code, parallel_shift))
+			return -EPIPE;
+
 		pipe->external =
 			media_entity_to_v4l2_subdev(link->source->entity);
 		rval = omap3isp_get_external_info(pipe, link);
 		if (rval < 0)
 			return 0;
+	} else {
+		if (source_fmt->format.code != sink_fmt->format.code)
+			return -EPIPE;
 	}
 
 	return 0;
@@ -2299,8 +2360,6 @@ int omap3isp_ccdc_init(struct isp_device *isp)
 	ccdc->clamp.oblen = 0;
 	ccdc->clamp.dcsubval = 0;
 
-	ccdc->vpcfg.pixelclk = 0;
-
 	ccdc->update = OMAP3ISP_CCDC_BLCLAMP;
 	ccdc_apply_controls(ccdc);
 
-- 
1.7.2.5


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

* [PATCH v3 28/33] omap3isp: Move setting constaints above media_entity_pipeline_start
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (26 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 27/33] omap3isp: Implement proper CCDC link validation, check pixel rate Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-22 11:12   ` Laurent Pinchart
  2012-02-20  1:57 ` [PATCH v3 29/33] omap3isp: Configure CSI-2 phy based on platform data Sakari Ailus
                   ` (5 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/omap3isp/ispvideo.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/media/video/omap3isp/ispvideo.c b/drivers/media/video/omap3isp/ispvideo.c
index f1c68ca..2e4786d 100644
--- a/drivers/media/video/omap3isp/ispvideo.c
+++ b/drivers/media/video/omap3isp/ispvideo.c
@@ -304,8 +304,6 @@ static int isp_video_validate_pipeline(struct isp_pipeline *pipe)
 	struct v4l2_subdev *subdev;
 	int ret;
 
-	pipe->max_rate = pipe->l3_ick;
-
 	subdev = isp_video_remote_subdev(pipe->output, NULL);
 	if (subdev == NULL)
 		return -EPIPE;
@@ -997,6 +995,11 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 	pipe->external_rate = 0;
 	pipe->external_bpp = 0;
 
+	if (video->isp->pdata->set_constraints)
+		video->isp->pdata->set_constraints(video->isp, true);
+	pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]);
+	pipe->max_rate = pipe->l3_ick;
+
 	ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
 	if (ret < 0)
 		goto err_media_entity_pipeline_start;
@@ -1031,10 +1034,6 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 		pipe->output = far_end;
 	}
 
-	if (video->isp->pdata->set_constraints)
-		video->isp->pdata->set_constraints(video->isp, true);
-	pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]);
-
 	/* Validate the pipeline and update its state. */
 	ret = isp_video_validate_pipeline(pipe);
 	if (ret < 0)
-- 
1.7.2.5


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

* [PATCH v3 29/33] omap3isp: Configure CSI-2 phy based on platform data
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (27 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 28/33] omap3isp: Move setting constaints above media_entity_pipeline_start Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-22 11:21   ` Laurent Pinchart
  2012-02-20  1:57 ` [PATCH v3 30/33] omap3isp: Add resizer data rate configuration to resizer_set_stream Sakari Ailus
                   ` (4 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Configure CSI-2 phy based on platform data in the ISP driver. For that, the
new V4L2_CID_IMAGE_SOURCE_PIXEL_RATE control is used. Previously the same
was configured from the board code.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/omap3isp/isp.h       |    3 -
 drivers/media/video/omap3isp/ispcsiphy.c |  168 +++++++++++++++++-------------
 drivers/media/video/omap3isp/ispcsiphy.h |   10 --
 3 files changed, 97 insertions(+), 84 deletions(-)

diff --git a/drivers/media/video/omap3isp/isp.h b/drivers/media/video/omap3isp/isp.h
index 8b0bc2d..43a1b16 100644
--- a/drivers/media/video/omap3isp/isp.h
+++ b/drivers/media/video/omap3isp/isp.h
@@ -126,9 +126,6 @@ struct isp_reg {
 
 struct isp_platform_callback {
 	u32 (*set_xclk)(struct isp_device *isp, u32 xclk, u8 xclksel);
-	int (*csiphy_config)(struct isp_csiphy *phy,
-			     struct isp_csiphy_dphy_cfg *dphy,
-			     struct isp_csiphy_lanes_cfg *lanes);
 	void (*set_pixel_clock)(struct isp_device *isp, unsigned int pixelclk);
 };
 
diff --git a/drivers/media/video/omap3isp/ispcsiphy.c b/drivers/media/video/omap3isp/ispcsiphy.c
index 5be37ce..902477d 100644
--- a/drivers/media/video/omap3isp/ispcsiphy.c
+++ b/drivers/media/video/omap3isp/ispcsiphy.c
@@ -28,41 +28,13 @@
 #include <linux/device.h>
 #include <linux/regulator/consumer.h>
 
+#include "../../../../arch/arm/mach-omap2/control.h"
+
 #include "isp.h"
 #include "ispreg.h"
 #include "ispcsiphy.h"
 
 /*
- * csiphy_lanes_config - Configuration of CSIPHY lanes.
- *
- * Updates HW configuration.
- * Called with phy->mutex taken.
- */
-static void csiphy_lanes_config(struct isp_csiphy *phy)
-{
-	unsigned int i;
-	u32 reg;
-
-	reg = isp_reg_readl(phy->isp, phy->cfg_regs, ISPCSI2_PHY_CFG);
-
-	for (i = 0; i < phy->num_data_lanes; i++) {
-		reg &= ~(ISPCSI2_PHY_CFG_DATA_POL_MASK(i + 1) |
-			 ISPCSI2_PHY_CFG_DATA_POSITION_MASK(i + 1));
-		reg |= (phy->lanes.data[i].pol <<
-			ISPCSI2_PHY_CFG_DATA_POL_SHIFT(i + 1));
-		reg |= (phy->lanes.data[i].pos <<
-			ISPCSI2_PHY_CFG_DATA_POSITION_SHIFT(i + 1));
-	}
-
-	reg &= ~(ISPCSI2_PHY_CFG_CLOCK_POL_MASK |
-		 ISPCSI2_PHY_CFG_CLOCK_POSITION_MASK);
-	reg |= phy->lanes.clk.pol << ISPCSI2_PHY_CFG_CLOCK_POL_SHIFT;
-	reg |= phy->lanes.clk.pos << ISPCSI2_PHY_CFG_CLOCK_POSITION_SHIFT;
-
-	isp_reg_writel(phy->isp, reg, phy->cfg_regs, ISPCSI2_PHY_CFG);
-}
-
-/*
  * csiphy_power_autoswitch_enable
  * @enable: Sets or clears the autoswitch function enable flag.
  */
@@ -107,46 +79,31 @@ static int csiphy_set_power(struct isp_csiphy *phy, u32 power)
 }
 
 /*
- * csiphy_dphy_config - Configure CSI2 D-PHY parameters.
- *
- * Called with phy->mutex taken.
+ * TCLK values are OK at their reset values
  */
-static void csiphy_dphy_config(struct isp_csiphy *phy)
-{
-	u32 reg;
-
-	/* Set up ISPCSIPHY_REG0 */
-	reg = isp_reg_readl(phy->isp, phy->phy_regs, ISPCSIPHY_REG0);
-
-	reg &= ~(ISPCSIPHY_REG0_THS_TERM_MASK |
-		 ISPCSIPHY_REG0_THS_SETTLE_MASK);
-	reg |= phy->dphy.ths_term << ISPCSIPHY_REG0_THS_TERM_SHIFT;
-	reg |= phy->dphy.ths_settle << ISPCSIPHY_REG0_THS_SETTLE_SHIFT;
-
-	isp_reg_writel(phy->isp, reg, phy->phy_regs, ISPCSIPHY_REG0);
-
-	/* Set up ISPCSIPHY_REG1 */
-	reg = isp_reg_readl(phy->isp, phy->phy_regs, ISPCSIPHY_REG1);
-
-	reg &= ~(ISPCSIPHY_REG1_TCLK_TERM_MASK |
-		 ISPCSIPHY_REG1_TCLK_MISS_MASK |
-		 ISPCSIPHY_REG1_TCLK_SETTLE_MASK);
-	reg |= phy->dphy.tclk_term << ISPCSIPHY_REG1_TCLK_TERM_SHIFT;
-	reg |= phy->dphy.tclk_miss << ISPCSIPHY_REG1_TCLK_MISS_SHIFT;
-	reg |= phy->dphy.tclk_settle << ISPCSIPHY_REG1_TCLK_SETTLE_SHIFT;
+#define TCLK_TERM	0
+#define TCLK_MISS	1
+#define TCLK_SETTLE	14
 
-	isp_reg_writel(phy->isp, reg, phy->phy_regs, ISPCSIPHY_REG1);
-}
-
-static int csiphy_config(struct isp_csiphy *phy,
-			 struct isp_csiphy_dphy_cfg *dphy,
-			 struct isp_csiphy_lanes_cfg *lanes)
+static int omap3isp_csiphy_config(struct isp_csiphy *phy)
 {
+	struct isp_csi2_device *csi2 = phy->csi2;
+	struct isp_pipeline *pipe = to_isp_pipeline(&csi2->subdev.entity);
+	struct isp_v4l2_subdevs_group *subdevs = pipe->external->host_priv;
+	struct isp_csiphy_lanes_cfg *lanes;
+	int csi2_ddrclk_khz;
 	unsigned int used_lanes = 0;
 	unsigned int i;
+	u32 reg;
+
+	if (subdevs->interface == ISP_INTERFACE_CCP2B_PHY1
+	    || subdevs->interface == ISP_INTERFACE_CCP2B_PHY2)
+		lanes = &subdevs->bus.ccp2.lanecfg;
+	else
+		lanes = &subdevs->bus.csi2.lanecfg;
 
 	/* Clock and data lanes verification */
-	for (i = 0; i < phy->num_data_lanes; i++) {
+	for (i = 0; i < csi2->phy->num_data_lanes; i++) {
 		if (lanes->data[i].pol > 1 || lanes->data[i].pos > 3)
 			return -EINVAL;
 
@@ -162,10 +119,80 @@ static int csiphy_config(struct isp_csiphy *phy,
 	if (lanes->clk.pos == 0 || used_lanes & (1 << lanes->clk.pos))
 		return -EINVAL;
 
-	mutex_lock(&phy->mutex);
-	phy->dphy = *dphy;
-	phy->lanes = *lanes;
-	mutex_unlock(&phy->mutex);
+	/* FIXME: Do 34xx / 35xx require something here? */
+	if (cpu_is_omap3630()) {
+		u32 cam_phy_ctrl =
+			omap_readl(OMAP343X_CTRL_BASE
+				   + OMAP3630_CONTROL_CAMERA_PHY_CTRL);
+
+		/*
+		 * SCM.CONTROL_CAMERA_PHY_CTRL
+		 * - bit[4]    : CSIPHY1 data sent to CSIB
+		 * - bit [3:2] : CSIPHY1 config: 00 d-phy, 01/10 ccp2
+		 * - bit [1:0] : CSIPHY2 config: 00 d-phy, 01/10 ccp2
+		 */
+		if (subdevs->interface == ISP_INTERFACE_CCP2B_PHY1)
+			cam_phy_ctrl |= 1 << 2;
+		else if (subdevs->interface == ISP_INTERFACE_CSI2C_PHY1)
+			cam_phy_ctrl &= ~(1 << 2);
+
+		if (subdevs->interface == ISP_INTERFACE_CCP2B_PHY2)
+			cam_phy_ctrl |= 1;
+		else if (subdevs->interface == ISP_INTERFACE_CSI2A_PHY2)
+			cam_phy_ctrl &= ~1;
+
+		omap_writel(cam_phy_ctrl,
+			    OMAP343X_CTRL_BASE
+			    + OMAP3630_CONTROL_CAMERA_PHY_CTRL);
+	}
+
+	/* DPHY timing configuration */
+	/* CSI-2 is DDR and we only count used lanes. */
+	csi2_ddrclk_khz = pipe->external_rate / 1000
+		/ (2 * hweight32(used_lanes)) * pipe->external_bpp;
+
+	reg = isp_reg_readl(csi2->isp, csi2->phy->phy_regs, ISPCSIPHY_REG0);
+
+	reg &= ~(ISPCSIPHY_REG0_THS_TERM_MASK |
+		 ISPCSIPHY_REG0_THS_SETTLE_MASK);
+	/* THS_TERM: Programmed value = ceil(12.5 ns/DDRClk period) - 1. */
+	reg |= (DIV_ROUND_UP(25 * csi2_ddrclk_khz, 2000000) - 1)
+		<< ISPCSIPHY_REG0_THS_TERM_SHIFT;
+	/* THS_SETTLE: Programmed value = ceil(90 ns/DDRClk period) + 3. */
+	reg |= (DIV_ROUND_UP(90 * csi2_ddrclk_khz, 1000000) + 3)
+		<< ISPCSIPHY_REG0_THS_SETTLE_SHIFT;
+
+	isp_reg_writel(csi2->isp, reg, csi2->phy->phy_regs, ISPCSIPHY_REG0);
+
+	reg = isp_reg_readl(csi2->isp, csi2->phy->phy_regs, ISPCSIPHY_REG1);
+
+	reg &= ~(ISPCSIPHY_REG1_TCLK_TERM_MASK |
+		 ISPCSIPHY_REG1_TCLK_MISS_MASK |
+		 ISPCSIPHY_REG1_TCLK_SETTLE_MASK);
+	reg |= TCLK_TERM << ISPCSIPHY_REG1_TCLK_TERM_SHIFT;
+	reg |= TCLK_MISS << ISPCSIPHY_REG1_TCLK_MISS_SHIFT;
+	reg |= TCLK_SETTLE << ISPCSIPHY_REG1_TCLK_SETTLE_SHIFT;
+
+	isp_reg_writel(csi2->isp, reg, csi2->phy->phy_regs, ISPCSIPHY_REG1);
+
+	/* DPHY lane configuration */
+	reg = isp_reg_readl(csi2->isp, csi2->phy->cfg_regs, ISPCSI2_PHY_CFG);
+
+	for (i = 0; i < csi2->phy->num_data_lanes; i++) {
+		reg &= ~(ISPCSI2_PHY_CFG_DATA_POL_MASK(i + 1) |
+			 ISPCSI2_PHY_CFG_DATA_POSITION_MASK(i + 1));
+		reg |= (lanes->data[i].pol <<
+			ISPCSI2_PHY_CFG_DATA_POL_SHIFT(i + 1));
+		reg |= (lanes->data[i].pos <<
+			ISPCSI2_PHY_CFG_DATA_POSITION_SHIFT(i + 1));
+	}
+
+	reg &= ~(ISPCSI2_PHY_CFG_CLOCK_POL_MASK |
+		 ISPCSI2_PHY_CFG_CLOCK_POSITION_MASK);
+	reg |= lanes->clk.pol << ISPCSI2_PHY_CFG_CLOCK_POL_SHIFT;
+	reg |= lanes->clk.pos << ISPCSI2_PHY_CFG_CLOCK_POSITION_SHIFT;
+
+	isp_reg_writel(csi2->isp, reg, csi2->phy->cfg_regs, ISPCSI2_PHY_CFG);
 
 	return 0;
 }
@@ -188,8 +215,9 @@ int omap3isp_csiphy_acquire(struct isp_csiphy *phy)
 
 	omap3isp_csi2_reset(phy->csi2);
 
-	csiphy_dphy_config(phy);
-	csiphy_lanes_config(phy);
+	rval = omap3isp_csiphy_config(phy);
+	if (rval < 0)
+		goto done;
 
 	rval = csiphy_set_power(phy, ISPCSI2_PHY_CFG_PWR_CMD_ON);
 	if (rval) {
@@ -225,8 +253,6 @@ int omap3isp_csiphy_init(struct isp_device *isp)
 	struct isp_csiphy *phy1 = &isp->isp_csiphy1;
 	struct isp_csiphy *phy2 = &isp->isp_csiphy2;
 
-	isp->platform_cb.csiphy_config = csiphy_config;
-
 	phy2->isp = isp;
 	phy2->csi2 = &isp->isp_csi2a;
 	phy2->num_data_lanes = ISP_CSIPHY2_NUM_DATA_LANES;
diff --git a/drivers/media/video/omap3isp/ispcsiphy.h b/drivers/media/video/omap3isp/ispcsiphy.h
index e93a661..14551fd 100644
--- a/drivers/media/video/omap3isp/ispcsiphy.h
+++ b/drivers/media/video/omap3isp/ispcsiphy.h
@@ -32,14 +32,6 @@
 struct isp_csi2_device;
 struct regulator;
 
-struct isp_csiphy_dphy_cfg {
-	u8 ths_term;
-	u8 ths_settle;
-	u8 tclk_term;
-	unsigned tclk_miss:1;
-	u8 tclk_settle;
-};
-
 struct isp_csiphy {
 	struct isp_device *isp;
 	struct mutex mutex;	/* serialize csiphy configuration */
@@ -52,8 +44,6 @@ struct isp_csiphy {
 	unsigned int phy_regs;
 
 	u8 num_data_lanes;	/* number of CSI2 Data Lanes supported */
-	struct isp_csiphy_lanes_cfg lanes;
-	struct isp_csiphy_dphy_cfg dphy;
 };
 
 int omap3isp_csiphy_acquire(struct isp_csiphy *phy);
-- 
1.7.2.5


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

* [PATCH v3 30/33] omap3isp: Add resizer data rate configuration to resizer_set_stream
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (28 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 29/33] omap3isp: Configure CSI-2 phy based on platform data Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-22 11:24   ` Laurent Pinchart
  2012-02-20  1:57 ` [PATCH v3 31/33] omap3isp: Remove isp_validate_pipeline and other old stuff Sakari Ailus
                   ` (3 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/omap3isp/ispresizer.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/omap3isp/ispresizer.c b/drivers/media/video/omap3isp/ispresizer.c
index 6ce2349..81e1bc4 100644
--- a/drivers/media/video/omap3isp/ispresizer.c
+++ b/drivers/media/video/omap3isp/ispresizer.c
@@ -1147,9 +1147,13 @@ static int resizer_set_stream(struct v4l2_subdev *sd, int enable)
 	struct device *dev = to_device(res);
 
 	if (res->state == ISP_PIPELINE_STREAM_STOPPED) {
+		struct isp_pipeline *pipe = to_isp_pipeline(&sd->entity);
+
 		if (enable == ISP_PIPELINE_STREAM_STOPPED)
 			return 0;
 
+		omap3isp_resizer_max_rate(res, &pipe->max_rate);
+
 		omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_RESIZER);
 		resizer_configure(res);
 		resizer_print_status(res);
-- 
1.7.2.5


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

* [PATCH v3 31/33] omap3isp: Remove isp_validate_pipeline and other old stuff
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (29 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 30/33] omap3isp: Add resizer data rate configuration to resizer_set_stream Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-22 11:26   ` Laurent Pinchart
  2012-02-20  1:57 ` [PATCH v3 32/33] smiapp: Add driver Sakari Ailus
                   ` (2 subsequent siblings)
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Remove isp_set_pixel_clock().

Remove set_pixel_clock() callback from platform callbacks since the same
information is now passed to the ISP driver by other means.

Remove struct ispccdc_vp since the only field in this structure, pixelclk,
is no longer used.

Remove isp_video_is_shiftable() --- this will live on as ccdc_is_shiftable
in ispccdc.c.

Remove isp_video_validate_pipeline(). Pipeline validation is now split into
appropriate subdevs, so this can be removed.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/omap3isp/isp.c      |   14 ---
 drivers/media/video/omap3isp/isp.h      |    1 -
 drivers/media/video/omap3isp/ispccdc.h  |   10 --
 drivers/media/video/omap3isp/ispvideo.c |  139 -------------------------------
 4 files changed, 0 insertions(+), 164 deletions(-)

diff --git a/drivers/media/video/omap3isp/isp.c b/drivers/media/video/omap3isp/isp.c
index 89a9bf8..4b2290d 100644
--- a/drivers/media/video/omap3isp/isp.c
+++ b/drivers/media/video/omap3isp/isp.c
@@ -329,19 +329,6 @@ void omap3isp_configure_bridge(struct isp_device *isp,
 	isp_reg_writel(isp, ispctrl_val, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
 }
 
-/**
- * isp_set_pixel_clock - Configures the ISP pixel clock
- * @isp: OMAP3 ISP device
- * @pixelclk: Average pixel clock in Hz
- *
- * Set the average pixel clock required by the sensor. The ISP will use the
- * lowest possible memory bandwidth settings compatible with the clock.
- **/
-static void isp_set_pixel_clock(struct isp_device *isp, unsigned int pixelclk)
-{
-	isp->isp_ccdc.vpcfg.pixelclk = pixelclk;
-}
-
 void omap3isp_hist_dma_done(struct isp_device *isp)
 {
 	if (omap3isp_ccdc_busy(&isp->isp_ccdc) ||
@@ -2116,7 +2103,6 @@ static int isp_probe(struct platform_device *pdev)
 
 	isp->autoidle = autoidle;
 	isp->platform_cb.set_xclk = isp_set_xclk;
-	isp->platform_cb.set_pixel_clock = isp_set_pixel_clock;
 
 	mutex_init(&isp->isp_mutex);
 	spin_lock_init(&isp->stat_lock);
diff --git a/drivers/media/video/omap3isp/isp.h b/drivers/media/video/omap3isp/isp.h
index 43a1b16..90f3743 100644
--- a/drivers/media/video/omap3isp/isp.h
+++ b/drivers/media/video/omap3isp/isp.h
@@ -126,7 +126,6 @@ struct isp_reg {
 
 struct isp_platform_callback {
 	u32 (*set_xclk)(struct isp_device *isp, u32 xclk, u8 xclksel);
-	void (*set_pixel_clock)(struct isp_device *isp, unsigned int pixelclk);
 };
 
 /*
diff --git a/drivers/media/video/omap3isp/ispccdc.h b/drivers/media/video/omap3isp/ispccdc.h
index 6d0264b..e570abe 100644
--- a/drivers/media/video/omap3isp/ispccdc.h
+++ b/drivers/media/video/omap3isp/ispccdc.h
@@ -80,14 +80,6 @@ struct ispccdc_syncif {
 	u8 bt_r656_en;
 };
 
-/*
- * struct ispccdc_vp - Structure for Video Port parameters
- * @pixelclk: Input pixel clock in Hz
- */
-struct ispccdc_vp {
-	unsigned int pixelclk;
-};
-
 enum ispccdc_lsc_state {
 	LSC_STATE_STOPPED = 0,
 	LSC_STATE_STOPPING = 1,
@@ -161,7 +153,6 @@ struct ispccdc_lsc {
  * @update: Bitmask of controls to update during the next interrupt
  * @shadow_update: Controls update in progress by userspace
  * @syncif: Interface synchronization configuration
- * @vpcfg: Video port configuration
  * @underrun: A buffer underrun occurred and a new buffer has been queued
  * @state: Streaming state
  * @lock: Serializes shadow_update with interrupt handler
@@ -190,7 +181,6 @@ struct isp_ccdc_device {
 	unsigned int shadow_update;
 
 	struct ispccdc_syncif syncif;
-	struct ispccdc_vp vpcfg;
 
 	unsigned int underrun:1;
 	enum isp_pipeline_stream_state state;
diff --git a/drivers/media/video/omap3isp/ispvideo.c b/drivers/media/video/omap3isp/ispvideo.c
index 2e4786d..07832c8 100644
--- a/drivers/media/video/omap3isp/ispvideo.c
+++ b/drivers/media/video/omap3isp/ispvideo.c
@@ -130,37 +130,6 @@ omap3isp_video_format_info(enum v4l2_mbus_pixelcode code)
 }
 
 /*
- * Decide whether desired output pixel code can be obtained with
- * the lane shifter by shifting the input pixel code.
- * @in: input pixelcode to shifter
- * @out: output pixelcode from shifter
- * @additional_shift: # of bits the sensor's LSB is offset from CAMEXT[0]
- *
- * return true if the combination is possible
- * return false otherwise
- */
-static bool isp_video_is_shiftable(enum v4l2_mbus_pixelcode in,
-		enum v4l2_mbus_pixelcode out,
-		unsigned int additional_shift)
-{
-	const struct isp_format_info *in_info, *out_info;
-
-	if (in == out)
-		return true;
-
-	in_info = omap3isp_video_format_info(in);
-	out_info = omap3isp_video_format_info(out);
-
-	if ((in_info->flavor == 0) || (out_info->flavor == 0))
-		return false;
-
-	if (in_info->flavor != out_info->flavor)
-		return false;
-
-	return in_info->bpp - out_info->bpp + additional_shift <= 6;
-}
-
-/*
  * isp_video_mbus_to_pix - Convert v4l2_mbus_framefmt to v4l2_pix_format
  * @video: ISP video instance
  * @mbus: v4l2_mbus_framefmt format (input)
@@ -284,107 +253,6 @@ isp_video_far_end(struct isp_video *video)
 	return far_end;
 }
 
-/*
- * Validate a pipeline by checking both ends of all links for format
- * discrepancies.
- *
- * Compute the minimum time per frame value as the maximum of time per frame
- * limits reported by every block in the pipeline.
- *
- * Return 0 if all formats match, or -EPIPE if at least one link is found with
- * different formats on its two ends or if the pipeline doesn't start with a
- * video source (either a subdev with no input pad, or a non-subdev entity).
- */
-static int isp_video_validate_pipeline(struct isp_pipeline *pipe)
-{
-	struct isp_device *isp = pipe->output->isp;
-	struct v4l2_subdev_format fmt_source;
-	struct v4l2_subdev_format fmt_sink;
-	struct media_pad *pad;
-	struct v4l2_subdev *subdev;
-	int ret;
-
-	subdev = isp_video_remote_subdev(pipe->output, NULL);
-	if (subdev == NULL)
-		return -EPIPE;
-
-	while (1) {
-		unsigned int shifter_link;
-		/* Retrieve the sink format */
-		pad = &subdev->entity.pads[0];
-		if (!(pad->flags & MEDIA_PAD_FL_SINK))
-			break;
-
-		fmt_sink.pad = pad->index;
-		fmt_sink.which = V4L2_SUBDEV_FORMAT_ACTIVE;
-		ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt_sink);
-		if (ret < 0 && ret != -ENOIOCTLCMD)
-			return -EPIPE;
-
-		/* Update the maximum frame rate */
-		if (subdev == &isp->isp_res.subdev)
-			omap3isp_resizer_max_rate(&isp->isp_res,
-						  &pipe->max_rate);
-
-		/* Check ccdc maximum data rate when data comes from sensor
-		 * TODO: Include ccdc rate in pipe->max_rate and compare the
-		 *       total pipe rate with the input data rate from sensor.
-		 */
-		if (subdev == &isp->isp_ccdc.subdev && pipe->input == NULL) {
-			unsigned int rate = UINT_MAX;
-
-			omap3isp_ccdc_max_rate(&isp->isp_ccdc, &rate);
-			if (isp->isp_ccdc.vpcfg.pixelclk > rate)
-				return -ENOSPC;
-		}
-
-		/* If sink pad is on CCDC, the link has the lane shifter
-		 * in the middle of it. */
-		shifter_link = subdev == &isp->isp_ccdc.subdev;
-
-		/* Retrieve the source format. Return an error if no source
-		 * entity can be found, and stop checking the pipeline if the
-		 * source entity isn't a subdev.
-		 */
-		pad = media_entity_remote_source(pad);
-		if (pad == NULL)
-			return -EPIPE;
-
-		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
-			break;
-
-		subdev = media_entity_to_v4l2_subdev(pad->entity);
-
-		fmt_source.pad = pad->index;
-		fmt_source.which = V4L2_SUBDEV_FORMAT_ACTIVE;
-		ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt_source);
-		if (ret < 0 && ret != -ENOIOCTLCMD)
-			return -EPIPE;
-
-		/* Check if the two ends match */
-		if (fmt_source.format.width != fmt_sink.format.width ||
-		    fmt_source.format.height != fmt_sink.format.height)
-			return -EPIPE;
-
-		if (shifter_link) {
-			unsigned int parallel_shift = 0;
-			if (isp->isp_ccdc.input == CCDC_INPUT_PARALLEL) {
-				struct isp_parallel_platform_data *pdata =
-					&((struct isp_v4l2_subdevs_group *)
-					      subdev->host_priv)->bus.parallel;
-				parallel_shift = pdata->data_lane_shift * 2;
-			}
-			if (!isp_video_is_shiftable(fmt_source.format.code,
-						fmt_sink.format.code,
-						parallel_shift))
-				return -EPIPE;
-		} else if (fmt_source.format.code != fmt_sink.format.code)
-			return -EPIPE;
-	}
-
-	return 0;
-}
-
 static int
 __isp_video_get_format(struct isp_video *video, struct v4l2_format *format)
 {
@@ -1034,13 +902,6 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 		pipe->output = far_end;
 	}
 
-	/* Validate the pipeline and update its state. */
-	ret = isp_video_validate_pipeline(pipe);
-	if (ret < 0)
-		goto err_isp_video_check_format;
-
-	pipe->error = false;
-
 	spin_lock_irqsave(&pipe->lock, flags);
 	pipe->state &= ~ISP_PIPELINE_STREAM;
 	pipe->state |= state;
-- 
1.7.2.5


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

* [PATCH v3 32/33] smiapp: Add driver.
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (30 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 31/33] omap3isp: Remove isp_validate_pipeline and other old stuff Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-27 15:38   ` Laurent Pinchart
  2012-02-20  1:57 ` [PATCH v3 33/33] rm680: Add camera init Sakari Ailus
  2012-02-20  2:03 ` [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

From: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>

Add driver for SMIA++/SMIA image sensors. The driver exposes the sensor as
three subdevs, pixel array, binner and scaler --- in case the device has a
scaler.

Currently it relies on the board code for external clock handling. There is
no fast way out of this dependency before the ISP drivers (omap3isp) among
others will be able to export that clock through the clock framework
instead.

Signed-off-by: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
---
 drivers/media/video/Kconfig                  |    2 +
 drivers/media/video/Makefile                 |    1 +
 drivers/media/video/smiapp/Kconfig           |   12 +
 drivers/media/video/smiapp/Makefile          |    3 +
 drivers/media/video/smiapp/smiapp-core.c     | 2729 ++++++++++++++++++++++++++
 drivers/media/video/smiapp/smiapp-debug.h    |   32 +
 drivers/media/video/smiapp/smiapp-limits.c   |  132 ++
 drivers/media/video/smiapp/smiapp-limits.h   |  128 ++
 drivers/media/video/smiapp/smiapp-pll.c      |  582 ++++++
 drivers/media/video/smiapp/smiapp-quirk.c    |  264 +++
 drivers/media/video/smiapp/smiapp-quirk.h    |   72 +
 drivers/media/video/smiapp/smiapp-reg-defs.h |  503 +++++
 drivers/media/video/smiapp/smiapp-reg.h      |  122 ++
 drivers/media/video/smiapp/smiapp-regs.c     |  230 +++
 drivers/media/video/smiapp/smiapp-regs.h     |   46 +
 drivers/media/video/smiapp/smiapp.h          |  268 +++
 include/media/smiapp.h                       |   83 +
 17 files changed, 5209 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/smiapp/Kconfig
 create mode 100644 drivers/media/video/smiapp/Makefile
 create mode 100644 drivers/media/video/smiapp/smiapp-core.c
 create mode 100644 drivers/media/video/smiapp/smiapp-debug.h
 create mode 100644 drivers/media/video/smiapp/smiapp-limits.c
 create mode 100644 drivers/media/video/smiapp/smiapp-limits.h
 create mode 100644 drivers/media/video/smiapp/smiapp-pll.c
 create mode 100644 drivers/media/video/smiapp/smiapp-quirk.c
 create mode 100644 drivers/media/video/smiapp/smiapp-quirk.h
 create mode 100644 drivers/media/video/smiapp/smiapp-reg-defs.h
 create mode 100644 drivers/media/video/smiapp/smiapp-reg.h
 create mode 100644 drivers/media/video/smiapp/smiapp-regs.c
 create mode 100644 drivers/media/video/smiapp/smiapp-regs.h
 create mode 100644 drivers/media/video/smiapp/smiapp.h
 create mode 100644 include/media/smiapp.h

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 9adada0..6033cff 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -524,6 +524,8 @@ config VIDEO_S5K6AA
 	  This is a V4L2 sensor-level driver for Samsung S5K6AA(FX) 1.3M
 	  camera sensor with an embedded SoC image signal processor.
 
+source "drivers/media/video/smiapp/Kconfig"
+
 comment "Flash devices"
 
 config VIDEO_ADP1653
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 3541388..e4c9e16 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -73,6 +73,7 @@ obj-$(CONFIG_VIDEO_SR030PC30)	+= sr030pc30.o
 obj-$(CONFIG_VIDEO_NOON010PC30)	+= noon010pc30.o
 obj-$(CONFIG_VIDEO_M5MOLS)	+= m5mols/
 obj-$(CONFIG_VIDEO_S5K6AA)	+= s5k6aa.o
+obj-$(CONFIG_VIDEO_SMIAPP)	+= smiapp/
 obj-$(CONFIG_VIDEO_ADP1653)	+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)	+= as3645a.o
 
diff --git a/drivers/media/video/smiapp/Kconfig b/drivers/media/video/smiapp/Kconfig
new file mode 100644
index 0000000..3f98e8e
--- /dev/null
+++ b/drivers/media/video/smiapp/Kconfig
@@ -0,0 +1,12 @@
+config VIDEO_SMIAPP
+	tristate "SMIA++/SMIA sensor support"
+	depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER
+	---help---
+	  This is a generic driver for SMIA++/SMIA camera modules.
+
+config VIDEO_SMIAPP_DEBUG
+	bool "Enable debugging for the generic SMIA++/SMIA driver"
+	depends on VIDEO_SMIAPP
+	---help---
+	  Enable debugging output in the generic SMIA++/SMIA driver. If you
+	  are developing the driver you might want to enable this.
diff --git a/drivers/media/video/smiapp/Makefile b/drivers/media/video/smiapp/Makefile
new file mode 100644
index 0000000..83dc0d1
--- /dev/null
+++ b/drivers/media/video/smiapp/Makefile
@@ -0,0 +1,3 @@
+smiapp-objs			+= smiapp-core.o smiapp-regs.o smiapp-pll.o \
+				   smiapp-quirk.o smiapp-limits.o
+obj-$(CONFIG_VIDEO_SMIAPP)	+= smiapp.o
diff --git a/drivers/media/video/smiapp/smiapp-core.c b/drivers/media/video/smiapp/smiapp-core.c
new file mode 100644
index 0000000..9fd08a1
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-core.c
@@ -0,0 +1,2729 @@
+/*
+ * drivers/media/video/smiapp-core.c
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2010--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * Based on smiapp driver by Vimarsh Zutshi
+ * Based on jt8ev1.c by Vimarsh Zutshi
+ * Based on smia-sensor.c by Tuukka Toivonen <tuukkat76@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "smiapp-debug.h"
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/gpio.h>
+#include <linux/module.h>
+#include <linux/regulator/consumer.h>
+#include <linux/v4l2-mediabus.h>
+#include <media/v4l2-device.h>
+
+#include "smiapp.h"
+
+#define SMIAPP_ALIGN_DIM(dim, flags)	      \
+	(flags & V4L2_SUBDEV_SEL_FLAG_SIZE_GE \
+	 ? ALIGN(dim, 2)		      \
+	 : dim & ~1)
+
+/*
+ * smiapp_module_idents - supported camera modules
+ */
+static const struct smiapp_module_ident smiapp_module_idents[] = {
+	SMIAPP_IDENT_LQ(0x10, 0x4141, -1, "jt8ev1", &smiapp_jt8ev1_quirk),
+	SMIAPP_IDENT_LQ(0x10, 0x4241, -1, "imx125es", &smiapp_imx125es_quirk),
+	SMIAPP_IDENT_L(0x01, 0x022b, -1, "vs6555"),
+	SMIAPP_IDENT_L(0x0c, 0x208a, -1, "tcm8330md"),
+	SMIAPP_IDENT_L(0x01, 0x022e, -1, "vw6558"),
+	SMIAPP_IDENT_LQ(0x0c, 0x2134, -1, "tcm8500md", &smiapp_tcm8500md_quirk),
+	SMIAPP_IDENT_L(0x07, 0x7698, -1, "ovm7698"),
+	SMIAPP_IDENT_L(0x0b, 0x4242, -1, "smiapp-003"),
+	SMIAPP_IDENT_LQ(0x0c, 0x560f, -1, "jt8ew9", &smiapp_jt8ew9_quirk),
+	SMIAPP_IDENT_L(0x0c, 0x213e, -1, "et8en2"),
+	SMIAPP_IDENT_L(0x0c, 0x2184, -1, "tcm8580md"),
+};
+
+/*
+ *
+ * Dynamic Capability Identification
+ *
+ */
+
+static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	u32 fmt_model_type, fmt_model_subtype, ncol_desc, nrow_desc;
+	int i;
+	int rval;
+	int line_count = 0;
+	int embedded_start = -1, embedded_end = -1;
+	int image_start = 0;
+
+	rval = smia_i2c_read_reg(client,
+				 SMIAPP_REG_U8_FRAME_FORMAT_MODEL_TYPE,
+				 &fmt_model_type);
+	if (rval)
+		return rval;
+
+	rval = smia_i2c_read_reg(client,
+				 SMIAPP_REG_U8_FRAME_FORMAT_MODEL_SUBTYPE,
+				 &fmt_model_subtype);
+	if (rval)
+		return rval;
+
+	ncol_desc = (fmt_model_subtype
+		     & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_MASK)
+		>> SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_SHIFT;
+	nrow_desc = (fmt_model_subtype
+		     & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NROWS_MASK);
+
+	dev_dbg(&client->dev, "format_model_type %s\n",
+		fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE
+		? "2 byte" :
+		fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE
+		? "4 byte" : "is simply bad");
+
+	for (i = 0; i < ncol_desc + nrow_desc; i++) {
+		u32 desc;
+		u32 pixelcode;
+		u32 pixels;
+		char *which;
+		char *what;
+
+		if (fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE) {
+			rval = smia_i2c_read_reg(
+				client,
+				SMIAPP_REG_U16_FRAME_FORMAT_DESCRIPTOR_2(i),
+				&desc);
+			if (rval)
+				return rval;
+
+			pixelcode =
+				(desc
+				 & SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_MASK)
+				>> SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_SHIFT;
+			pixels = desc & SMIAPP_FRAME_FORMAT_DESC_2_PIXELS_MASK;
+		} else if (fmt_model_type
+			   == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE) {
+			rval = smia_i2c_read_reg(
+				client,
+				SMIAPP_REG_U32_FRAME_FORMAT_DESCRIPTOR_4(i),
+				&desc);
+			if (rval)
+				return rval;
+
+			pixelcode =
+				(desc
+				 & SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_MASK)
+				>> SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_SHIFT;
+			pixels = desc & SMIAPP_FRAME_FORMAT_DESC_4_PIXELS_MASK;
+		} else {
+			dev_dbg(&client->dev,
+				"invalid frame format model type %d\n",
+				fmt_model_type);
+			return -EINVAL;
+		}
+
+		if (i < ncol_desc)
+			which = "columns";
+		else
+			which = "rows";
+
+		switch (pixelcode) {
+		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED:
+			what = "embedded";
+			break;
+		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DUMMY:
+			what = "dummy";
+			break;
+		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_BLACK:
+			what = "black";
+			break;
+		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DARK:
+			what = "dark";
+			break;
+		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE:
+			what = "visible";
+			break;
+		default:
+			what = "invalid";
+			dev_dbg(&client->dev, "pixelcode %d\n", pixelcode);
+			break;
+		}
+
+		dev_dbg(&client->dev, "%s pixels: %d %s\n",
+			what, pixels, which);
+
+		if (i < ncol_desc)
+			continue;
+
+		/* Handle row descriptors */
+		if (pixelcode
+		    == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED) {
+			embedded_start = line_count;
+		} else {
+			if (pixelcode
+			    == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE
+			    || pixels
+			    >= sensor->limits[
+				    SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES] / 2) {
+				image_start = line_count;
+			}
+			if (embedded_start != -1 && embedded_end == -1)
+				embedded_end = line_count;
+		}
+		line_count += pixels;
+	}
+
+	if (embedded_start == -1 || embedded_end == -1)
+		embedded_start = embedded_end = 0;
+
+	dev_dbg(&client->dev, "embedded data from lines %d to %d\n",
+		embedded_start, embedded_end);
+	dev_dbg(&client->dev, "image data starts at line %d\n", image_start);
+
+	return 0;
+}
+
+/*
+ *
+ * V4L2 Controls handling
+ *
+ */
+
+static void __smiapp_update_exposure_limits(struct smiapp_sensor *sensor)
+{
+	struct v4l2_ctrl *ctrl = sensor->exposure;
+	int max;
+
+	max = sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
+		+ sensor->vblank->val -
+		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MAX_MARGIN];
+
+	ctrl->maximum = max;
+	if (ctrl->default_value > max)
+		ctrl->default_value = max;
+	if (ctrl->val > max)
+		ctrl->val = max;
+	if (ctrl->cur.val > max)
+		ctrl->cur.val = max;
+}
+
+/*
+ * Order matters.
+ *
+ * 1. Bits-per-pixel, descending.
+ * 2. Bits-per-pixel compressed, descending.
+ * 3. Pixel order, same as in pixel_order_str. Formats for all four pixel
+ *    orders must be defined.
+ */
+static const struct smiapp_csi_data_format smiapp_csi_data_formats[] = {
+	{ V4L2_MBUS_FMT_SGRBG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GRBG, },
+	{ V4L2_MBUS_FMT_SRGGB12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_RGGB, },
+	{ V4L2_MBUS_FMT_SBGGR12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_BGGR, },
+	{ V4L2_MBUS_FMT_SGBRG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GBRG, },
+	{ V4L2_MBUS_FMT_SGRBG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GRBG, },
+	{ V4L2_MBUS_FMT_SRGGB10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_RGGB, },
+	{ V4L2_MBUS_FMT_SBGGR10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_BGGR, },
+	{ V4L2_MBUS_FMT_SGBRG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GBRG, },
+	{ V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GRBG, },
+	{ V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_RGGB, },
+	{ V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_BGGR, },
+	{ V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GBRG, },
+};
+
+const char *pixel_order_str[] = { "GRBG", "RGGB", "BGGR", "GBRG" };
+
+#define to_csi_format_idx(fmt) (((unsigned long)(fmt)			\
+				 - (unsigned long)smiapp_csi_data_formats) \
+				/ sizeof(*smiapp_csi_data_formats))
+
+static void smiapp_update_mbus_formats(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int csi_format_idx = to_csi_format_idx(sensor->csi_format) & ~3;
+	int internal_csi_format_idx =
+		to_csi_format_idx(sensor->internal_csi_format) & ~3;
+	int flip = 0;
+	int pixel_order;
+
+	if (sensor->hflip) {
+		if (sensor->hflip->val)
+			flip |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
+
+		if (sensor->vflip->val)
+			flip |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
+	}
+
+	flip ^= sensor->hvflip_inv_mask;
+
+	pixel_order = sensor->default_pixel_order ^ flip;
+
+	sensor->mbus_frame_fmts =
+		sensor->default_mbus_frame_fmts << pixel_order;
+	sensor->csi_format =
+		&smiapp_csi_data_formats[csi_format_idx + pixel_order];
+	sensor->internal_csi_format =
+		&smiapp_csi_data_formats[internal_csi_format_idx
+					 + pixel_order];
+
+	BUG_ON(max(internal_csi_format_idx, csi_format_idx) + pixel_order
+	       >= ARRAY_SIZE(smiapp_csi_data_formats));
+	BUG_ON(min(internal_csi_format_idx, csi_format_idx) < 0);
+
+	dev_dbg(&client->dev, "flip %d; new pixel order %s\n",
+		flip, pixel_order_str[pixel_order]);
+}
+
+static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct smiapp_sensor *sensor =
+		container_of(ctrl->handler, struct smiapp_subdev, ctrl_handler)
+			->sensor;
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	u32 orient;
+	int exposure;
+	int rval = 0;
+
+	switch (ctrl->id) {
+	case V4L2_CID_ANALOGUE_GAIN:
+		return smia_i2c_write_reg(
+			client,
+			SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GLOBAL, ctrl->val);
+
+	case V4L2_CID_EXPOSURE:
+		return smia_i2c_write_reg(
+			client,
+			SMIAPP_REG_U16_COARSE_INTEGRATION_TIME, ctrl->val);
+
+	case V4L2_CID_HFLIP:
+	case V4L2_CID_VFLIP:
+		orient = 0;
+
+		if (sensor->streaming)
+			return -EBUSY;
+
+		if (sensor->hflip->val)
+			orient |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
+
+		if (sensor->vflip->val)
+			orient |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
+
+		orient ^= sensor->hvflip_inv_mask;
+		rval = smia_i2c_write_reg(client,
+					  SMIAPP_REG_U8_IMAGE_ORIENTATION,
+					  orient);
+		if (rval < 0)
+			return rval;
+
+		smiapp_update_mbus_formats(sensor);
+
+		return 0;
+
+	case V4L2_CID_VBLANK:
+		exposure = sensor->exposure->val;
+
+		__smiapp_update_exposure_limits(sensor);
+
+		if (exposure > sensor->exposure->maximum) {
+			sensor->exposure->val =
+				sensor->exposure->maximum;
+			rval = smiapp_set_ctrl(
+				sensor->exposure);
+		}
+
+		if (rval < 0)
+			return rval;
+
+		return smia_i2c_write_reg(
+			client, SMIAPP_REG_U16_FRAME_LENGTH_LINES,
+			sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
+			+ ctrl->val);
+
+	case V4L2_CID_HBLANK:
+		return smia_i2c_write_reg(
+			client, SMIAPP_REG_U16_LINE_LENGTH_PCK,
+			sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width
+			+ ctrl->val);
+
+	case V4L2_CID_LINK_FREQ:
+		if (sensor->streaming)
+			return -EBUSY;
+
+		return smiapp_pll_update(sensor);
+
+	default:
+		return -EINVAL;
+	}
+}
+
+static const struct v4l2_ctrl_ops smiapp_ctrl_ops = {
+	.s_ctrl = smiapp_set_ctrl,
+};
+
+static int smiapp_init_controls(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	struct v4l2_ctrl_config cfg;
+	int rval;
+
+	rval = v4l2_ctrl_handler_init(&sensor->pixel_array->ctrl_handler, 7);
+	if (rval)
+		return rval;
+	sensor->pixel_array->ctrl_handler.lock = &sensor->mutex;
+
+	sensor->analog_gain = v4l2_ctrl_new_std(
+		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
+		V4L2_CID_ANALOGUE_GAIN,
+		sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN],
+		sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX],
+		max_t(int,
+		      sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_STEP], 1),
+		sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN]);
+
+	sensor->exposure = v4l2_ctrl_new_std(
+		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
+		V4L2_CID_EXPOSURE,
+		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN],
+		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN], 1,
+		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN]);
+
+	sensor->hflip = v4l2_ctrl_new_std(
+		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
+		V4L2_CID_HFLIP, 0, 1, 1, 0);
+	sensor->vflip = v4l2_ctrl_new_std(
+		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
+		V4L2_CID_VFLIP, 0, 1, 1, 0);
+
+	sensor->vblank = v4l2_ctrl_new_std(
+		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
+		V4L2_CID_VBLANK, 0, 1, 1, 0);
+
+	if (sensor->vblank)
+		sensor->vblank->flags |= V4L2_CTRL_FLAG_UPDATE;
+
+	sensor->hblank = v4l2_ctrl_new_std(
+		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
+		V4L2_CID_HBLANK, 0, 1, 1, 0);
+
+	if (sensor->hblank)
+		sensor->hblank->flags |= V4L2_CTRL_FLAG_UPDATE;
+
+	sensor->pixel_rate_parray = v4l2_ctrl_new_std(
+		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
+		V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
+
+	if (sensor->pixel_array->ctrl_handler.error) {
+		dev_err(&client->dev,
+			"pixel array controls initialization failed (%d)\n",
+			sensor->pixel_array->ctrl_handler.error);
+		return sensor->pixel_array->ctrl_handler.error;
+	}
+
+	sensor->pixel_array->sd.ctrl_handler =
+		&sensor->pixel_array->ctrl_handler;
+
+	v4l2_ctrl_cluster(2, &sensor->hflip);
+
+	rval = v4l2_ctrl_handler_init(&sensor->binner->ctrl_handler, 0);
+	if (rval)
+		return rval;
+	sensor->binner->ctrl_handler.lock = &sensor->mutex;
+
+	if (sensor->scaler) {
+		rval = v4l2_ctrl_handler_init(&sensor->scaler->ctrl_handler, 0);
+		if (rval)
+			return rval;
+		sensor->scaler->ctrl_handler.lock = &sensor->mutex;
+	}
+
+	memset(&cfg, 0, sizeof(cfg));
+
+	cfg.ops = &smiapp_ctrl_ops;
+	cfg.id = V4L2_CID_LINK_FREQ;
+	cfg.type = V4L2_CTRL_TYPE_INTEGER_MENU;
+	while (sensor->platform_data->op_sys_clock[cfg.max])
+		cfg.max++;
+	cfg.max--;
+	cfg.qmenu_int = sensor->platform_data->op_sys_clock;
+
+	sensor->link_freq = v4l2_ctrl_new_custom(
+		&sensor->src->ctrl_handler, &cfg, NULL);
+
+	sensor->pixel_rate_csi = v4l2_ctrl_new_std(
+		&sensor->src->ctrl_handler, &smiapp_ctrl_ops,
+		V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
+
+	if (sensor->src->ctrl_handler.error) {
+		dev_err(&client->dev,
+			"src controls initialization failed (%d)\n",
+			sensor->src->ctrl_handler.error);
+		return sensor->src->ctrl_handler.error;
+	}
+
+	sensor->src->sd.ctrl_handler =
+		&sensor->src->ctrl_handler;
+
+	return 0;
+}
+
+static void smiapp_free_controls(struct smiapp_sensor *sensor)
+{
+	int i;
+
+	for (i = 0; i < sensor->sds_used; i++)
+		v4l2_ctrl_handler_free(&sensor->sds[i].ctrl_handler);
+}
+
+static int smiapp_get_limits(struct smiapp_sensor *sensor, int const *limit,
+			     int n)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int i, val;
+	int rval;
+
+	for (i = 0; i < n; i++) {
+		rval = smia_i2c_read_reg(
+			client, smiapp_reg_limits[limit[i]].addr, &val);
+		if (rval) {
+			dev_dbg(&client->dev, "error reading register %4.4x\n",
+				(u16)smiapp_reg_limits[limit[i]].addr);
+			return rval;
+		}
+		sensor->limits[limit[i]] = val;
+		dev_dbg(&client->dev, "0x%8.8x \"%s\" = %d, 0x%x\n",
+			smiapp_reg_limits[limit[i]].addr,
+			smiapp_reg_limits[limit[i]].what, val, val);
+	}
+
+	return 0;
+}
+
+static int smiapp_get_all_limits(struct smiapp_sensor *sensor)
+{
+	int rval, i;
+
+	for (i = 0; i < SMIAPP_LIMIT_LAST; i++) {
+		rval = smiapp_get_limits(sensor, &i, 1);
+		if (rval < 0)
+			return rval;
+	}
+
+	if (sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN] == 0)
+		smiapp_replace_limit(sensor, SMIAPP_LIMIT_SCALER_N_MIN, 16);
+
+	return 0;
+}
+
+static int smiapp_get_limits_binning(struct smiapp_sensor *sensor)
+{
+	static u32 const limits[] = {
+		SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN,
+		SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN,
+		SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN,
+		SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN,
+		SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN,
+		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN_BIN,
+		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN,
+	};
+	static u32 const limits_replace[] = {
+		SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES,
+		SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES,
+		SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK,
+		SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK,
+		SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK,
+		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN,
+		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN,
+	};
+
+	if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY] ==
+	    SMIAPP_BINNING_CAPABILITY_NO) {
+		int i;
+
+		for (i = 0; i < ARRAY_SIZE(limits); i++)
+			sensor->limits[limits[i]] =
+				sensor->limits[limits_replace[i]];
+
+		return 0;
+	}
+
+	return smiapp_get_limits(sensor, limits, ARRAY_SIZE(limits));
+}
+
+static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	unsigned int type, n;
+	int i, rval, pixel_order;
+
+	rval = smia_i2c_read_reg(
+		client, SMIAPP_REG_U8_DATA_FORMAT_MODEL_TYPE, &type);
+	if (rval)
+		return rval;
+
+	dev_dbg(&client->dev, "data_format_model_type %d\n", type);
+
+	rval = smia_i2c_read_reg(client, SMIAPP_REG_U8_PIXEL_ORDER,
+				 &pixel_order);
+	if (rval)
+		return rval;
+
+	if (pixel_order >= ARRAY_SIZE(pixel_order_str)) {
+		dev_dbg(&client->dev, "bad pixel order %d\n", pixel_order);
+		return -EINVAL;
+	}
+
+	dev_dbg(&client->dev, "pixel order %d (%s)\n", pixel_order,
+		pixel_order_str[pixel_order]);
+
+	switch (type) {
+	case SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL:
+		n = SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL_N;
+		break;
+	case SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED:
+		n = SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED_N;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	sensor->default_pixel_order = pixel_order;
+	sensor->mbus_frame_fmts = 0;
+
+	for (i = 0; i < n; i++) {
+		int fmt, j;
+
+		rval = smia_i2c_read_reg(
+			client,
+			SMIAPP_REG_U16_DATA_FORMAT_DESCRIPTOR(i), &fmt);
+		if (rval)
+			return rval;
+
+		dev_dbg(&client->dev, "bpp %d, compressed %d\n",
+			fmt >> 8, (u8)fmt);
+
+		for (j = 0; j < ARRAY_SIZE(smiapp_csi_data_formats); j++) {
+			const struct smiapp_csi_data_format *f =
+				&smiapp_csi_data_formats[j];
+
+			if (f->pixel_order != SMIAPP_PIXEL_ORDER_GRBG)
+				continue;
+
+			if (f->width != fmt >> 8 || f->compressed != (u8)fmt)
+				continue;
+
+			dev_dbg(&client->dev, "jolly good! %d\n", j);
+
+			sensor->default_mbus_frame_fmts |= 1 << j;
+			if (!sensor->csi_format) {
+				sensor->csi_format = f;
+				sensor->internal_csi_format = f;
+			}
+		}
+	}
+
+	if (!sensor->csi_format) {
+		dev_err(&client->dev, "no supported mbus code found\n");
+		return -EINVAL;
+	}
+
+	smiapp_update_mbus_formats(sensor);
+
+	return 0;
+}
+
+static void smiapp_update_blanking(struct smiapp_sensor *sensor)
+{
+	struct v4l2_ctrl *vblank = sensor->vblank, *hblank = sensor->hblank;
+
+	vblank->minimum =
+		max_t(int,
+		      sensor->limits[SMIAPP_LIMIT_MIN_FRAME_BLANKING_LINES],
+		      sensor->limits[SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN] -
+		      sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height);
+	vblank->maximum =
+		sensor->limits[SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN] -
+		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height;
+
+	vblank->val = clamp_t(int, vblank->val,
+			      vblank->minimum, vblank->maximum);
+	vblank->default_value = vblank->minimum;
+	vblank->val = vblank->val;
+	vblank->cur.val = vblank->val;
+
+	hblank->minimum =
+		max_t(int,
+		      sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN] -
+		      sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width,
+		      sensor->limits[SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN]);
+	hblank->maximum =
+		sensor->limits[SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN] -
+		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width;
+
+	hblank->val = clamp_t(int, hblank->val,
+			      hblank->minimum, hblank->maximum);
+	hblank->default_value = hblank->minimum;
+	hblank->val = hblank->val;
+	hblank->cur.val = hblank->val;
+
+	__smiapp_update_exposure_limits(sensor);
+}
+
+static int smiapp_update_mode(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int binning_mode;
+	int rval;
+
+	dev_dbg(&client->dev, "frame size: %dx%d\n",
+		sensor->src->crop[SMIAPP_PAD_SOURCE].width,
+		sensor->src->crop[SMIAPP_PAD_SOURCE].height);
+	dev_dbg(&client->dev, "csi format width: %d\n",
+		sensor->csi_format->width);
+
+	/* Binning has to be set up here; it affects limits */
+	if (sensor->binning_horizontal == 1 &&
+	    sensor->binning_vertical == 1) {
+		binning_mode = 0;
+	} else {
+		u8 binning_type =
+			(sensor->binning_horizontal << 4)
+			| sensor->binning_vertical;
+
+		rval = smia_i2c_write_reg(
+			client, SMIAPP_REG_U8_BINNING_TYPE, binning_type);
+		if (rval < 0)
+			return rval;
+
+		binning_mode = 1;
+	}
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U8_BINNING_MODE, binning_mode);
+	if (rval < 0)
+		return rval;
+
+	/* Get updated limits due to binning */
+	rval = smiapp_get_limits_binning(sensor);
+	if (rval < 0)
+		return rval;
+
+	rval = smiapp_pll_update(sensor);
+	if (rval < 0)
+		return rval;
+
+	/* Output from pixel array, including blanking */
+	smiapp_update_blanking(sensor);
+
+	dev_dbg(&client->dev, "vblank\t\t%d\n", sensor->vblank->val);
+	dev_dbg(&client->dev, "hblank\t\t%d\n", sensor->hblank->val);
+
+	dev_dbg(&client->dev, "real timeperframe\t100/%d\n",
+		sensor->pll.vt_pix_clk_freq_hz /
+		((sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width
+		  + sensor->hblank->val) *
+		 (sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
+		  + sensor->vblank->val) / 100));
+
+	return 0;
+}
+
+/*
+ *
+ * SMIA++ NVM handling
+ *
+ */
+static int smiapp_read_nvm(struct smiapp_sensor *sensor,
+			   unsigned char *nvm)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	u32 i, s, p, np, v;
+	int rval;
+
+	np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;
+	for (p = 0; p < np; p++) {
+		rval = smia_i2c_write_reg(
+			client,
+			SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT, p);
+		if (rval)
+			goto out;
+
+		rval = smia_i2c_write_reg(client,
+					  SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL,
+					  SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN |
+					  SMIAPP_DATA_TRANSFER_IF_1_CTRL_RD_EN);
+		if (rval)
+			goto out;
+
+		i = 1000;
+		do {
+			rval = smia_i2c_read_reg(client,
+				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s);
+
+			if (rval)
+				goto out;
+
+			if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
+				break;
+
+			if (--i == 0)
+				goto out;
+
+		} while (1);
+
+		for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {
+			rval = smia_i2c_read_reg(client,
+				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0 + i,
+				&v);
+			if (rval)
+				goto out;
+
+			*nvm++ = v;
+		}
+	}
+
+out:
+	rval |= smia_i2c_write_reg(client,
+				   SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL, 0);
+	return rval;
+}
+
+/*
+ *
+ * SMIA++ CCI address control
+ *
+ */
+static int smiapp_change_cci_addr(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int rval;
+	u32 val;
+
+	client->addr = sensor->platform_data->i2c_addr_dfl;
+
+	rval = smia_i2c_write_reg(client,
+				  SMIAPP_REG_U8_CCI_ADDRESS_CONTROL,
+				  sensor->platform_data->i2c_addr_alt << 1);
+	if (rval) {
+		client->addr = sensor->platform_data->i2c_addr_alt;
+		return rval;
+	}
+
+	client->addr = sensor->platform_data->i2c_addr_alt;
+
+	/* verify addr change went ok */
+	rval = smia_i2c_read_reg(client,
+				 SMIAPP_REG_U8_CCI_ADDRESS_CONTROL, &val);
+	if (rval)
+		return rval;
+
+	if (val != sensor->platform_data->i2c_addr_alt << 1)
+		return -ENODEV;
+
+	return 0;
+}
+
+/*
+ *
+ * SMIA++ Mode Control
+ *
+ */
+static int smiapp_setup_flash_strobe(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	struct smiapp_flash_strobe_parms *strobe_setup;
+	unsigned int ext_freq = sensor->platform_data->ext_clk;
+	int rval;
+	u32 tmp;
+	u32 strobe_adjustment;
+	u32 strobe_width_high_rs;
+
+	strobe_setup = sensor->platform_data->strobe_setup;
+
+	/*
+	 * How to calculate registers related to strobe length. Please
+	 * do not change, or if you do at least know what you're
+	 * doing. :-)
+	 *
+	 * Sakari Ailus <sakari.ailus@maxwell.research.nokia.com> 2010-10-25
+	 *
+	 * flash_strobe_length [us] / 10^6 = (tFlash_strobe_width_ctrl
+	 *	/ EXTCLK freq [Hz]) * flash_strobe_adjustment
+	 *
+	 * tFlash_strobe_width_ctrl E N, [1 - 0xffff]
+	 * flash_strobe_adjustment E N, [1 - 0xff]
+	 *
+	 * The formula above is written as below to keep it on one
+	 * line:
+	 *
+	 * l / 10^6 = w / e * a
+	 *
+	 * Let's mark w * a by x:
+	 *
+	 * x = w * a
+	 *
+	 * Thus, we get:
+	 *
+	 * x = l * e / 10^6
+	 *
+	 * The strobe width must be at least as long as requested,
+	 * thus rounding upwards is needed.
+	 *
+	 * x = (l * e + 10^6 - 1) / 10^6
+	 * -----------------------------
+	 *
+	 * Maximum possible accuracy is wanted at all times. Thus keep
+	 * a as small as possible.
+	 *
+	 * Calculate a, assuming maximum w, with rounding upwards:
+	 *
+	 * a = (x + (2^16 - 1) - 1) / (2^16 - 1)
+	 * -------------------------------------
+	 *
+	 * Thus, we also get w, with that a, with rounding upwards:
+	 *
+	 * w = (x + a - 1) / a
+	 * -------------------
+	 *
+	 * To get limits:
+	 *
+	 * x E [1, (2^16 - 1) * (2^8 - 1)]
+	 *
+	 * Substituting maximum x to the original formula (with rounding),
+	 * the maximum l is thus
+	 *
+	 * (2^16 - 1) * (2^8 - 1) * 10^6 = l * e + 10^6 - 1
+	 *
+	 * l = (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / e
+	 * --------------------------------------------------
+	 *
+	 * flash_strobe_length must be clamped between 1 and
+	 * (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / EXTCLK freq.
+	 *
+	 * Then,
+	 *
+	 * flash_strobe_adjustment = ((flash_strobe_length *
+	 *	EXTCLK freq + 10^6 - 1) / 10^6 + (2^16 - 1) - 1) / (2^16 - 1)
+	 *
+	 * tFlash_strobe_width_ctrl = ((flash_strobe_length *
+	 *	EXTCLK freq + 10^6 - 1) / 10^6 +
+	 *	flash_strobe_adjustment - 1) / flash_strobe_adjustment
+	 */
+	tmp = div_u64(1000000ULL * ((1 << 16) - 1) * ((1 << 8) - 1) -
+		      1000000 + 1, ext_freq);
+	strobe_setup->strobe_width_high_us =
+		clamp_t(u32, strobe_setup->strobe_width_high_us, 1, tmp);
+
+	tmp = div_u64(((u64)strobe_setup->strobe_width_high_us * (u64)ext_freq +
+			1000000 - 1), 1000000ULL);
+	strobe_adjustment = (tmp + (1 << 16) - 1 - 1) / ((1 << 16) - 1);
+	strobe_width_high_rs = (tmp + strobe_adjustment - 1) /
+				strobe_adjustment;
+
+	rval = smia_i2c_write_reg(client,
+				  SMIAPP_REG_U8_FLASH_MODE_RS,
+				  strobe_setup->mode);
+	if (rval < 0)
+		goto out;
+
+	rval = smia_i2c_write_reg(client,
+				  SMIAPP_REG_U8_FLASH_STROBE_ADJUSTMENT,
+				  strobe_adjustment);
+	if (rval < 0)
+		goto out;
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_RS_CTRL,
+		strobe_width_high_rs);
+	if (rval < 0)
+		goto out;
+
+	rval = smia_i2c_write_reg(client,
+				  SMIAPP_REG_U16_TFLASH_STROBE_DELAY_RS_CTRL,
+				  strobe_setup->strobe_delay);
+	if (rval < 0)
+		goto out;
+
+	rval = smia_i2c_write_reg(client,
+				  SMIAPP_REG_U16_FLASH_STROBE_START_POINT,
+				  strobe_setup->stobe_start_point);
+	if (rval < 0)
+		goto out;
+
+	rval = smia_i2c_write_reg(client,
+				  SMIAPP_REG_U8_FLASH_TRIGGER_RS,
+				  strobe_setup->trigger);
+
+out:
+	sensor->platform_data->strobe_setup->trigger = 0;
+
+	return rval;
+}
+
+/* -----------------------------------------------------------------------------
+ * Power management
+ */
+
+static int smiapp_power_on(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int sleep;
+	int rval;
+
+	rval = regulator_enable(sensor->vana);
+	if (rval) {
+		dev_err(&client->dev, "failed to enable vana regulator\n");
+		return rval;
+	}
+	usleep_range(1000, 1000);
+
+	rval = sensor->platform_data->set_xclk(&sensor->src->sd,
+					sensor->platform_data->ext_clk);
+	if (rval < 0) {
+		dev_dbg(&client->dev, "failed to set xclk\n");
+		goto out_xclk_fail;
+	}
+	usleep_range(1000, 1000);
+
+	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
+		gpio_set_value(sensor->platform_data->xshutdown, 1);
+
+	sleep = SMIAPP_RESET_DELAY(sensor->platform_data->ext_clk);
+	usleep_range(sleep, sleep);
+
+	/*
+	 * Failures to respond to the address change command have been noticed.
+	 * Those failures seem to be caused by the sensor requiring a longer
+	 * boot time than advertised. An additional 10ms delay seems to work
+	 * around the issue, but the SMIA++ I2C write retry hack makes the delay
+	 * unnecessary. The failures need to be investigated to find a proper
+	 * fix, and a delay will likely need to be added here if the I2C write
+	 * retry hack is reverted before the root cause of the boot time issue
+	 * is found.
+	 */
+
+	if (sensor->platform_data->i2c_addr_alt) {
+		rval = smiapp_change_cci_addr(sensor);
+		if (rval) {
+			dev_err(&client->dev, "cci address change error\n");
+			goto out_cci_addr_fail;
+		}
+	}
+
+	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_SOFTWARE_RESET,
+				  SMIAPP_SOFTWARE_RESET);
+	if (rval < 0) {
+		dev_err(&client->dev, "software reset failed\n");
+		goto out_cci_addr_fail;
+	}
+
+	if (sensor->platform_data->i2c_addr_alt) {
+		rval = smiapp_change_cci_addr(sensor);
+		if (rval) {
+			dev_err(&client->dev, "cci address change error\n");
+			goto out_cci_addr_fail;
+		}
+	}
+
+	rval = smia_i2c_write_reg(client,
+				  SMIAPP_REG_U16_COMPRESSION_MODE,
+				  SMIAPP_COMPRESSION_MODE_SIMPLE_PREDICTOR);
+	if (rval) {
+		dev_err(&client->dev, "compression mode set failed\n");
+		goto out_cci_addr_fail;
+	}
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_EXTCLK_FREQUENCY_MHZ,
+		sensor->platform_data->ext_clk / (1000000 / (1 << 8)));
+	if (rval) {
+		dev_err(&client->dev, "extclk frequency set failed\n");
+		goto out_cci_addr_fail;
+	}
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U8_CSI_LANE_MODE,
+		sensor->platform_data->lanes - 1);
+	if (rval) {
+		dev_err(&client->dev, "csi lane mode set failed\n");
+		goto out_cci_addr_fail;
+	}
+
+	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_FAST_STANDBY_CTRL,
+				  SMIAPP_FAST_STANDBY_CTRL_IMMEDIATE);
+	if (rval) {
+		dev_err(&client->dev, "fast standby set failed\n");
+		goto out_cci_addr_fail;
+	}
+
+	/* DPHY control done by sensor based on requested link rate */
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U8_DPHY_CTRL, SMIAPP_DPHY_CTRL_UI);
+	if (rval < 0) {
+		dev_err(&client->dev, "set dphy_ctrl_ui failed\n");
+		goto out_cci_addr_fail;
+	}
+
+	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_CSI_SIGNALLING_MODE,
+				  sensor->platform_data->csi_signalling_mode);
+	if (rval) {
+		dev_err(&client->dev, "csi signalling mode set failed\n");
+		goto out_cci_addr_fail;
+	}
+
+	/* DPHY control done by sensor based on requested link rate */
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U8_DPHY_CTRL, SMIAPP_DPHY_CTRL_UI);
+	if (rval < 0)
+		return rval;
+
+	rval = smiapp_call_quirk(sensor, post_poweron);
+	if (rval) {
+		dev_err(&client->dev, "post_poweron quirks failed\n");
+		goto out_cci_addr_fail;
+	}
+
+	return 0;
+
+out_cci_addr_fail:
+	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
+		gpio_set_value(sensor->platform_data->xshutdown, 0);
+	sensor->platform_data->set_xclk(&sensor->src->sd, 0);
+
+out_xclk_fail:
+	regulator_disable(sensor->vana);
+	return rval;
+}
+
+static void smiapp_power_off(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+
+	/*
+	 * Currently power/clock to lens are enable/disabled separately
+	 * but they are essentially the same signals. So if the sensor is
+	 * powered off while the lens is powered on the sensor does not
+	 * really see a power off and next time the cci address change
+	 * will fail. So do a soft reset explicitly here.
+	 */
+	if (sensor->platform_data->i2c_addr_alt)
+		smia_i2c_write_reg(client,
+				   SMIAPP_REG_U8_SOFTWARE_RESET,
+				   SMIAPP_SOFTWARE_RESET);
+
+	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
+		gpio_set_value(sensor->platform_data->xshutdown, 0);
+	sensor->platform_data->set_xclk(&sensor->src->sd, 0);
+	usleep_range(5000, 5000);
+	regulator_disable(sensor->vana);
+	sensor->streaming = 0;
+}
+
+static int smiapp_set_power(struct v4l2_subdev *subdev, int on)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int ret;
+
+	/* If the power count is modified from 0 to != 0 or from != 0 to 0,
+	 * update the power state.
+	 */
+	if (sensor->power_count == !on) {
+		if (on) {
+			ret = smiapp_power_on(sensor);
+			if (ret < 0)
+				return ret;
+			ret = smiapp_update_mode(sensor);
+			if (ret < 0)
+				return ret;
+		} else {
+			smiapp_power_off(sensor);
+		}
+	}
+
+	/* Update the power count. */
+	sensor->power_count += on ? 1 : -1;
+	WARN_ON(sensor->power_count < 0);
+
+	return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * Video stream management
+ */
+
+static int smiapp_start_streaming(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int rval;
+
+	mutex_lock(&sensor->mutex);
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_CSI_DATA_FORMAT,
+		(sensor->csi_format->width << 8) |
+		sensor->csi_format->compressed);
+	if (rval)
+		goto out;
+
+	rval = smiapp_pll_configure(sensor);
+	if (rval)
+		goto out;
+
+	/* Analog crop start coordinates */
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_X_ADDR_START,
+		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].left);
+	if (rval < 0)
+		goto out;
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_Y_ADDR_START,
+		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].top);
+	if (rval < 0)
+		goto out;
+
+	/* Analog crop end coordinates */
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_X_ADDR_END,
+		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].left
+		+ sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width - 1);
+	if (rval < 0)
+		goto out;
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_Y_ADDR_END,
+		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].top
+		+ sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height - 1);
+	if (rval < 0)
+		goto out;
+
+	/*
+	 * Output from pixel array, including blanking, is set using
+	 * controls below. No need to set here.
+	 */
+
+	/* Digital crop */
+	if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
+	    == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
+		rval = smia_i2c_write_reg(
+			client, SMIAPP_REG_U16_DIGITAL_CROP_X_OFFSET,
+			sensor->scaler->crop[SMIAPP_PAD_SINK].left);
+		if (rval < 0)
+			goto out;
+
+		rval = smia_i2c_write_reg(
+			client, SMIAPP_REG_U16_DIGITAL_CROP_Y_OFFSET,
+			sensor->scaler->crop[SMIAPP_PAD_SINK].top);
+		if (rval < 0)
+			goto out;
+
+		rval = smia_i2c_write_reg(
+			client, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_WIDTH,
+			sensor->scaler->crop[SMIAPP_PAD_SINK].width);
+		if (rval < 0)
+			goto out;
+
+		rval = smia_i2c_write_reg(
+			client, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_HEIGHT,
+			sensor->scaler->crop[SMIAPP_PAD_SINK].height);
+		if (rval < 0)
+			goto out;
+	}
+
+	/* Scaling */
+	if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
+	    != SMIAPP_SCALING_CAPABILITY_NONE) {
+		rval = smia_i2c_write_reg(
+			client, SMIAPP_REG_U16_SCALING_MODE,
+			sensor->scaling_mode);
+		if (rval < 0)
+			goto out;
+
+		if (sensor->scale_m
+		    != sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]) {
+			rval = smia_i2c_write_reg(
+				client, SMIAPP_REG_U16_SCALE_M,
+				sensor->scale_m);
+			if (rval < 0)
+				goto out;
+		}
+	}
+
+	/* Output size from sensor */
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_X_OUTPUT_SIZE,
+		sensor->src->crop[SMIAPP_PAD_SOURCE].width);
+	if (rval < 0)
+		goto out;
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_Y_OUTPUT_SIZE,
+		sensor->src->crop[SMIAPP_PAD_SOURCE].height);
+	if (rval < 0)
+		goto out;
+
+	if ((sensor->flash_capability &
+	     (SMIAPP_FLASH_MODE_CAPABILITY_SINGLE_STROBE |
+	      SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE)) &&
+	    sensor->platform_data->strobe_setup != NULL &&
+	    sensor->platform_data->strobe_setup->trigger != 0) {
+		rval = smiapp_setup_flash_strobe(sensor);
+		if (rval)
+			goto out;
+	}
+
+	rval = smiapp_call_quirk(sensor, pre_streamon);
+	if (rval) {
+		dev_err(&client->dev, "pre_streamon quirks failed\n");
+		goto out;
+	}
+
+	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_MODE_SELECT,
+				  SMIAPP_MODE_SELECT_STREAMING);
+
+out:
+	mutex_unlock(&sensor->mutex);
+
+	return rval;
+}
+
+static int smiapp_stop_streaming(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int rval;
+
+	mutex_lock(&sensor->mutex);
+	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_MODE_SELECT,
+		SMIAPP_MODE_SELECT_SOFTWARE_STANDBY);
+	if (rval)
+		goto out;
+
+	rval = smiapp_call_quirk(sensor, post_streamoff);
+	if (rval)
+		dev_err(&client->dev, "post_streamoff quirks failed\n");
+
+out:
+	mutex_unlock(&sensor->mutex);
+	return rval;
+}
+
+/* -----------------------------------------------------------------------------
+ * V4L2 subdev video operations
+ */
+
+static int smiapp_set_stream(struct v4l2_subdev *subdev, int enable)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int rval;
+
+	if (sensor->streaming == enable)
+		return 0;
+
+	if (enable) {
+		sensor->streaming = 1;
+		rval = smiapp_start_streaming(sensor);
+		if (rval < 0)
+			sensor->streaming = 0;
+	} else {
+		rval = smiapp_stop_streaming(sensor);
+		sensor->streaming = 0;
+	}
+
+	return rval;
+}
+
+static int smiapp_enum_mbus_code(struct v4l2_subdev *subdev,
+				 struct v4l2_subdev_fh *fh,
+				 struct v4l2_subdev_mbus_code_enum *code)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(subdev);
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int i, idx = -1;
+	int rval = -EINVAL;
+
+	mutex_lock(&sensor->mutex);
+
+	dev_err(&client->dev, "subdev %s, pad %d, index %d\n",
+		subdev->name, code->pad, code->index);
+
+	if (subdev != &sensor->src->sd
+	    || code->pad != SMIAPP_PAD_SOURCE) {
+		if (code->index)
+			goto out;
+
+		code->code = sensor->internal_csi_format->code;
+		rval = 0;
+		goto out;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
+		if (sensor->mbus_frame_fmts & (1 << i))
+			idx++;
+
+		if (idx == code->index) {
+			code->code = smiapp_csi_data_formats[i].code;
+			dev_err(&client->dev, "found index %d, i %d, code %x\n",
+				code->index, i, code->code);
+			rval = 0;
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&sensor->mutex);
+
+	return rval;
+}
+
+static int __smiapp_get_format(struct v4l2_subdev *subdev,
+			     struct v4l2_subdev_fh *fh,
+			     struct v4l2_subdev_format *fmt)
+{
+	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+
+	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
+		fmt->format = *v4l2_subdev_get_try_format(fh, fmt->pad);
+	} else {
+		struct v4l2_rect *r;
+
+		if (fmt->pad == SMIAPP_PAD_SOURCE)
+			r = &ssd->crop[SMIAPP_PAD_SOURCE];
+		else
+			r = &ssd->sink_fmt;
+
+		fmt->format.width = r->width;
+		fmt->format.height = r->height;
+		if (subdev == &sensor->src->sd
+		    && fmt->pad == SMIAPP_PAD_SOURCE)
+			fmt->format.code = sensor->csi_format->code;
+		else
+			fmt->format.code = sensor->internal_csi_format->code;
+	}
+
+	return 0;
+}
+
+static int smiapp_get_format(struct v4l2_subdev *subdev,
+			     struct v4l2_subdev_fh *fh,
+			     struct v4l2_subdev_format *fmt)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int rval;
+
+	mutex_lock(&sensor->mutex);
+	rval = __smiapp_get_format(subdev, fh, fmt);
+	mutex_unlock(&sensor->mutex);
+
+	return rval;
+}
+
+static void smiapp_get_crop_compose(struct v4l2_subdev *subdev,
+				    struct v4l2_subdev_fh *fh,
+				    struct v4l2_rect **crops,
+				    struct v4l2_rect **comps, int which)
+{
+	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
+	int i;
+
+	if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+		for (i = 0; i < subdev->entity.num_pads; i++)
+			if (crops)
+				crops[i] = &ssd->crop[i];
+		if (comps)
+			*comps = &ssd->compose;
+	} else {
+		for (i = 0; i < subdev->entity.num_pads; i++)
+			if (crops) {
+				crops[i] = v4l2_subdev_get_try_crop(fh, i);
+				BUG_ON(!crops[i]);
+			}
+		if (comps) {
+			*comps = v4l2_subdev_get_try_compose(fh,
+							     SMIAPP_PAD_SINK);
+			BUG_ON(!*comps);
+		}
+	}
+}
+
+/* Changes require propagation only on sink pad. */
+static void smiapp_propagate(struct v4l2_subdev *subdev,
+			     struct v4l2_subdev_fh *fh, int which,
+			     int target)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
+	struct v4l2_rect *comp, *crops[SMIAPP_PADS];
+
+	smiapp_get_crop_compose(subdev, fh, crops, &comp, which);
+
+	switch (target) {
+	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
+		comp->width = crops[SMIAPP_PAD_SINK]->width;
+		comp->height = crops[SMIAPP_PAD_SINK]->height;
+		if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+			if (ssd == sensor->scaler) {
+				sensor->scale_m =
+					sensor->limits[
+						SMIAPP_LIMIT_SCALER_N_MIN];
+				sensor->scaling_mode =
+					SMIAPP_SCALING_MODE_NONE;
+			} else if (ssd == sensor->binner) {
+				sensor->binning_horizontal = 1;
+				sensor->binning_vertical = 1;
+			}
+		}
+		/* Fall through */
+	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
+		*crops[SMIAPP_PAD_SOURCE] = *comp;
+		break;
+	default:
+		BUG();
+	}
+}
+
+static int smiapp_set_format(struct v4l2_subdev *subdev,
+			     struct v4l2_subdev_fh *fh,
+			     struct v4l2_subdev_format *fmt)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
+	struct v4l2_rect *crops[SMIAPP_PADS];
+	int i = 0;
+
+	mutex_lock(&sensor->mutex);
+
+	smiapp_get_crop_compose(subdev, fh, crops, NULL, fmt->which);
+
+	if (subdev == &sensor->src->sd && fmt->pad == SMIAPP_PAD_SOURCE) {
+		for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
+			if (sensor->mbus_frame_fmts & (1 << i) &&
+			    smiapp_csi_data_formats[i].code
+			    == fmt->format.code) {
+				if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+					sensor->csi_format =
+						&smiapp_csi_data_formats[i];
+				break;
+			}
+		}
+	}
+
+	if (fmt->pad == SMIAPP_PAD_SOURCE) {
+		int rval;
+
+		rval = __smiapp_get_format(subdev, fh, fmt);
+
+		mutex_unlock(&sensor->mutex);
+		return rval;
+	}
+
+	fmt->format.code = sensor->csi_format->code;
+
+	fmt->format.width &= ~1;
+	fmt->format.height &= ~1;
+
+	if (fmt->format.width < sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE])
+		fmt->format.width =
+			sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE];
+	if (fmt->format.height
+	    < sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE])
+		fmt->format.height =
+			sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE];
+
+	crops[SMIAPP_PAD_SINK]->left = crops[SMIAPP_PAD_SINK]->top = 0;
+	crops[SMIAPP_PAD_SINK]->width = fmt->format.width;
+	crops[SMIAPP_PAD_SINK]->height = fmt->format.height;
+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+		ssd->sink_fmt = *crops[SMIAPP_PAD_SINK];
+	smiapp_propagate(subdev, fh, fmt->which,
+			 V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE);
+
+	mutex_unlock(&sensor->mutex);
+
+	return 0;
+}
+
+#define SCALING_GOODNESS		100000
+#define SCALING_GOODNESS_EXTREME	100000000
+static int scaling_goodness(struct v4l2_subdev *subdev, int w, int ask_w,
+			    int h, int ask_h, u32 flags)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	struct i2c_client *client = v4l2_get_subdevdata(subdev);
+	int val = 0;
+
+	w &= ~1;
+	ask_w &= ~1;
+	h &= ~1;
+	ask_h &= ~1;
+
+	if (flags & V4L2_SUBDEV_SEL_FLAG_SIZE_GE) {
+		if (w < ask_w)
+			val -= SCALING_GOODNESS;
+		if (h < ask_h)
+			val -= SCALING_GOODNESS;
+	}
+
+	if (flags & V4L2_SUBDEV_SEL_FLAG_SIZE_LE) {
+		if (w > ask_w)
+			val -= SCALING_GOODNESS;
+		if (h > ask_h)
+			val -= SCALING_GOODNESS;
+	}
+
+	val -= abs(w - ask_w);
+	val -= abs(h - ask_h);
+
+	if (w < sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE])
+		val -= SCALING_GOODNESS_EXTREME;
+
+	dev_dbg(&client->dev, "w %d ask_w %d h %d ask_h %d goodness %d\n",
+		w, ask_h, h, ask_h, val);
+
+	return val;
+}
+
+/* We're only called on source pads. This function sets scaling. */
+static int smiapp_set_compose(struct v4l2_subdev *subdev,
+			      struct v4l2_subdev_fh *fh,
+			      struct v4l2_subdev_selection *sel)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(subdev);
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
+	struct v4l2_rect *comp, *crops[SMIAPP_PADS];
+
+	smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
+
+	sel->r.top = 0;
+	sel->r.left = 0;
+
+	if (ssd == sensor->binner) {
+		int i;
+		int binh = 1, binv = 1;
+		int best = scaling_goodness(
+			subdev,
+			crops[SMIAPP_PAD_SINK]->width,
+			sel->r.width,
+			crops[SMIAPP_PAD_SINK]->height,
+			sel->r.height, sel->flags);
+
+		for (i = 0; i < sensor->nbinning_subtypes; i++) {
+			int this = scaling_goodness(
+				subdev,
+				crops[SMIAPP_PAD_SINK]->width
+				/ sensor->binning_subtypes[i].horizontal,
+				sel->r.width,
+				crops[SMIAPP_PAD_SINK]->height
+				/ sensor->binning_subtypes[i].vertical,
+				sel->r.height, sel->flags);
+
+			if (this > best) {
+				binh = sensor->binning_subtypes[i].horizontal;
+				binv = sensor->binning_subtypes[i].vertical;
+				best = this;
+
+				if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+					sensor->binning_vertical = binv;
+					sensor->binning_horizontal = binh;
+				}
+			}
+		}
+
+		sel->r.width =
+			(crops[SMIAPP_PAD_SINK]->width / binh) & ~1;
+		sel->r.height =
+			(crops[SMIAPP_PAD_SINK]->height / binv) & ~1;
+
+	} else {
+		u32 min, max, a, b, max_m;
+		u32 scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
+		int mode = SMIAPP_SCALING_MODE_HORIZONTAL;
+		u32 try[4];
+		u32 ntry = 0;
+		int i;
+		int best = INT_MIN;
+
+		sel->r.width = min_t(unsigned int, sel->r.width,
+				     crops[SMIAPP_PAD_SINK]->width);
+		sel->r.height = min_t(unsigned int, sel->r.height,
+				      crops[SMIAPP_PAD_SINK]->height);
+
+		a = crops[SMIAPP_PAD_SINK]->width
+			* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
+			/ sel->r.width;
+		b = crops[SMIAPP_PAD_SINK]->height
+			* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
+			/ sel->r.height;
+		max_m = crops[SMIAPP_PAD_SINK]->width
+			* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
+			/ sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE];
+
+		a = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
+			max(a, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
+		b = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
+			max(b, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
+		max_m = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
+			    max(max_m,
+				sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
+
+		dev_dbg(&client->dev, "scaling: a %d b %d max_m %d\n",
+			a, b, max_m);
+
+		min = min(max_m, min(a, b));
+		max = min(max_m, max(a, b));
+
+		try[ntry] = min;
+		ntry++;
+		if (min != max) {
+			try[ntry] = max;
+			ntry++;
+		}
+		if (max != max_m) {
+			try[ntry] = min + 1;
+			ntry++;
+			if (min != max) {
+				try[ntry] = max + 1;
+				ntry++;
+			}
+		}
+
+		for (i = 0; i < ntry; i++) {
+			int this = scaling_goodness(
+				subdev,
+				crops[SMIAPP_PAD_SINK]->width
+				/ try[i]
+				* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
+				sel->r.width,
+				crops[SMIAPP_PAD_SINK]->height,
+				sel->r.height,
+				sel->flags);
+
+			dev_dbg(&client->dev, "trying factor %d (%d)\n",
+				try[i], i);
+
+			if (this > best) {
+				scale_m = try[i];
+				mode = SMIAPP_SCALING_MODE_HORIZONTAL;
+				best = this;
+			}
+
+			if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
+			    == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
+				continue;
+
+			this = scaling_goodness(
+				subdev, crops[SMIAPP_PAD_SINK]->width
+				/ try[i]
+				* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
+				sel->r.width,
+				crops[SMIAPP_PAD_SINK]->height
+				/ try[i]
+				* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
+				sel->r.height,
+				sel->flags);
+
+			if (this > best) {
+				scale_m = try[i];
+				mode = SMIAPP_SCALING_MODE_BOTH;
+				best = this;
+			}
+		}
+
+		sel->r.width =
+			(crops[SMIAPP_PAD_SINK]->width
+			 / scale_m
+			 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]) & ~1;
+		if (mode == SMIAPP_SCALING_MODE_BOTH)
+			sel->r.height =
+				(crops[SMIAPP_PAD_SINK]->height
+				 / scale_m
+				 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN])
+				& ~1;
+		else
+			sel->r.height = crops[SMIAPP_PAD_SINK]->height;
+
+		if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+			sensor->scale_m = scale_m;
+			sensor->scaling_mode = mode;
+		}
+	}
+
+	*comp = sel->r;
+	smiapp_propagate(subdev, fh, sel->which,
+			 V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE);
+
+	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+		return smiapp_update_mode(sensor);
+
+	return 0;
+}
+
+static int __smiapp_sel_supported(struct v4l2_subdev *subdev,
+				  struct v4l2_subdev_selection *sel)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
+
+	/* We only implement crop in three places. */
+	switch (sel->target) {
+	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
+	case V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS:
+		if (ssd == sensor->pixel_array
+		    && sel->pad == SMIAPP_PAD_SOURCE)
+			return 0;
+		if (ssd == sensor->src
+		    && sel->pad == SMIAPP_PAD_SOURCE)
+			return 0;
+		if (ssd == sensor->scaler
+		    && sel->pad == SMIAPP_PAD_SINK
+		    && sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
+		    == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP)
+			return 0;
+		return -EINVAL;
+	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
+	case V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS:
+		if (sel->pad != SMIAPP_PAD_SINK)
+			return -EINVAL;
+		if (ssd == sensor->binner)
+			return 0;
+		if (ssd == sensor->scaler
+		    && sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
+		    != SMIAPP_SCALING_CAPABILITY_NONE)
+			return 0;
+		/* Fall through */
+	default:
+		return -EINVAL;
+	}
+}
+
+static int smiapp_set_crop(struct v4l2_subdev *subdev,
+			   struct v4l2_subdev_fh *fh,
+			   struct v4l2_subdev_selection *sel)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
+	struct v4l2_rect *src_size, *crops[SMIAPP_PADS];
+	struct v4l2_rect _r;
+
+	smiapp_get_crop_compose(subdev, fh, crops, NULL, sel->which);
+
+	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+		if (sel->pad == SMIAPP_PAD_SINK)
+			src_size = &ssd->sink_fmt;
+		else
+			src_size = &ssd->compose;
+	} else {
+		if (sel->pad == SMIAPP_PAD_SINK) {
+			_r.left = _r.top = 0;
+			_r.width = v4l2_subdev_get_try_format(fh, sel->pad)
+				->width;
+			_r.height = v4l2_subdev_get_try_format(fh, sel->pad)
+				->height;
+			src_size = &_r;
+		} else {
+			src_size =
+				v4l2_subdev_get_try_compose(fh,
+							    SMIAPP_PAD_SINK);
+		}
+	}
+
+	if (ssd == sensor->src && sel->pad == SMIAPP_PAD_SOURCE)
+		sel->r.left = 0, sel->r.top = 0;
+
+	if (sel->r.width > src_size->width)
+		sel->r.width = src_size->width;
+	if (sel->r.height > src_size->height)
+		sel->r.height = src_size->height;
+
+	if (sel->r.left + sel->r.width > src_size->width)
+		sel->r.left =
+			src_size->width - sel->r.width;
+	if (sel->r.top + sel->r.height > src_size->height)
+		sel->r.top =
+			src_size->height - sel->r.height;
+
+	*crops[sel->pad] = sel->r;
+
+	if (sel->pad == SMIAPP_PAD_SINK)
+		smiapp_propagate(subdev, fh, sel->which,
+				 V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE);
+
+	return 0;
+}
+
+static int __smiapp_get_selection(struct v4l2_subdev *subdev,
+				  struct v4l2_subdev_fh *fh,
+				  struct v4l2_subdev_selection *sel)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
+	struct v4l2_rect *comp, *crops[SMIAPP_PADS];
+	struct v4l2_rect sink_fmt;
+	int ret;
+
+	ret = __smiapp_sel_supported(subdev, sel);
+	if (ret)
+		return ret;
+
+	smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
+
+	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+		sink_fmt = ssd->sink_fmt;
+	} else if (ssd != sensor->pixel_array) {
+		struct v4l2_mbus_framefmt *fmt =
+			v4l2_subdev_get_try_format(fh, SMIAPP_PAD_SINK);
+
+		sink_fmt.left = sink_fmt.top = 0;
+		sink_fmt.width = fmt->width;
+		sink_fmt.height = fmt->height;
+	} else {
+		BUG();
+	}
+
+	switch (sel->target) {
+	case V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS:
+		if (ssd == sensor->pixel_array) {
+			sel->r.width =
+				sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
+			sel->r.height =
+				sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
+		} else if (sel->pad == SMIAPP_PAD_SINK) {
+			sel->r = sink_fmt;
+		} else {
+			sel->r = *comp;
+		}
+		break;
+	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
+	case V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS:
+		sel->r = *crops[sel->pad];
+		break;
+	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
+		sel->r = *comp;
+		break;
+	}
+
+	return 0;
+}
+
+static int smiapp_get_selection(struct v4l2_subdev *subdev,
+				struct v4l2_subdev_fh *fh,
+				struct v4l2_subdev_selection *sel)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int rval;
+
+	mutex_lock(&sensor->mutex);
+	rval = __smiapp_get_selection(subdev, fh, sel);
+	mutex_unlock(&sensor->mutex);
+
+	return rval;
+}
+static int smiapp_set_selection(struct v4l2_subdev *subdev,
+				struct v4l2_subdev_fh *fh,
+				struct v4l2_subdev_selection *sel)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int ret;
+
+	ret = __smiapp_sel_supported(subdev, sel);
+	if (ret)
+		return ret;
+
+	mutex_lock(&sensor->mutex);
+
+	sel->r.left = max(0, sel->r.left & ~1);
+	sel->r.top = max(0, sel->r.top & ~1);
+	sel->r.width = max(0, SMIAPP_ALIGN_DIM(sel->r.width, sel->flags));
+	sel->r.height = max(0, SMIAPP_ALIGN_DIM(sel->r.height, sel->flags));
+
+	sel->r.width = max_t(unsigned int,
+			     sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE],
+			     sel->r.width);
+	sel->r.height = max_t(unsigned int,
+			      sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE],
+			      sel->r.height);
+
+	switch (sel->target) {
+	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
+		ret = smiapp_set_crop(subdev, fh, sel);
+		break;
+	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
+		ret = smiapp_set_compose(subdev, fh, sel);
+		break;
+	default:
+		BUG();
+	}
+
+	mutex_unlock(&sensor->mutex);
+	return ret;
+}
+
+static int smiapp_get_skip_frames(struct v4l2_subdev *subdev, u32 *frames)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+
+	*frames = sensor->frame_skip;
+	return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * sysfs attributes
+ */
+
+static ssize_t
+smiapp_sysfs_nvm_read(struct device *dev, struct device_attribute *attr,
+		      char *buf)
+{
+	struct v4l2_subdev *subdev = i2c_get_clientdata(to_i2c_client(dev));
+	struct i2c_client *client = v4l2_get_subdevdata(subdev);
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int nbytes;
+
+	if (!sensor->dev_init_done)
+		return -EBUSY;
+
+	if (!sensor->nvm_size) {
+		/* NVM not read yet - read it now */
+		sensor->nvm_size = sensor->platform_data->nvm_size;
+		if (smiapp_set_power(subdev, 1) < 0)
+			return -ENODEV;
+		if (smiapp_read_nvm(sensor, sensor->nvm)) {
+			dev_err(&client->dev, "nvm read failed\n");
+			return -ENODEV;
+		}
+		smiapp_set_power(subdev, 0);
+	}
+	/*
+	 * NVM is still way below a PAGE_SIZE, so we can safely
+	 * assume this for now.
+	 */
+	nbytes = min_t(unsigned int, sensor->nvm_size, PAGE_SIZE);
+	memcpy(buf, sensor->nvm, nbytes);
+
+	return nbytes;
+}
+static DEVICE_ATTR(nvm, S_IRUGO, smiapp_sysfs_nvm_read, NULL);
+
+/* -----------------------------------------------------------------------------
+ * V4L2 subdev core operations
+ */
+
+static int smiapp_identify_module(struct v4l2_subdev *subdev)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	struct i2c_client *client = v4l2_get_subdevdata(subdev);
+	int i, rval = 0;
+	struct smiapp_module_info *minfo = &sensor->minfo;
+
+	minfo->name = SMIAPP_NAME;
+
+	/* Module info */
+	rval = smia_i2c_read_reg(client,
+				 SMIAPP_REG_U8_MANUFACTURER_ID,
+				 &minfo->manufacturer_id);
+	if (!rval)
+		rval = smia_i2c_read_reg(client,
+					 SMIAPP_REG_U16_MODEL_ID,
+					 &minfo->model_id);
+	if (!rval)
+		rval |= smia_i2c_read_reg(client,
+					  SMIAPP_REG_U8_REVISION_NUMBER_MAJOR,
+					  &minfo->revision_number_major);
+	if (!rval)
+		rval |= smia_i2c_read_reg(client,
+					  SMIAPP_REG_U8_REVISION_NUMBER_MINOR,
+					  &minfo->revision_number_minor);
+	if (!rval)
+		rval |= smia_i2c_read_reg(client,
+					  SMIAPP_REG_U8_MODULE_DATE_YEAR,
+					  &minfo->module_year);
+	if (!rval)
+		rval |= smia_i2c_read_reg(client,
+					  SMIAPP_REG_U8_MODULE_DATE_MONTH,
+					  &minfo->module_month);
+	if (!rval)
+		rval |= smia_i2c_read_reg(client,
+					  SMIAPP_REG_U8_MODULE_DATE_DAY,
+					  &minfo->module_day);
+
+	/* Sensor info */
+	if (!rval)
+		rval |= smia_i2c_read_reg(client,
+					  SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID,
+					  &minfo->sensor_manufacturer_id);
+	if (!rval)
+		rval |= smia_i2c_read_reg(client,
+					  SMIAPP_REG_U16_SENSOR_MODEL_ID,
+					  &minfo->sensor_model_id);
+	if (!rval)
+		rval = smia_i2c_read_reg(client,
+					 SMIAPP_REG_U8_SENSOR_REVISION_NUMBER,
+					 &minfo->sensor_revision_number);
+	if (!rval)
+		rval = smia_i2c_read_reg(client,
+					 SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION,
+					 &minfo->sensor_firmware_version);
+
+	/* SMIA */
+	if (!rval)
+		rval = smia_i2c_read_reg(client,
+					 SMIAPP_REG_U8_SMIA_VERSION,
+					 &minfo->smia_version);
+	if (!rval)
+		rval = smia_i2c_read_reg(client,
+					 SMIAPP_REG_U8_SMIAPP_VERSION,
+					 &minfo->smiapp_version);
+
+	if (rval) {
+		dev_err(&client->dev, "sensor detection failed\n");
+		return -ENODEV;
+	}
+
+	dev_dbg(&client->dev, "module 0x%2.2x-0x%4.4x\n",
+		minfo->manufacturer_id, minfo->model_id);
+
+	dev_dbg(&client->dev,
+		"module revision 0x%2.2x-0x%2.2x date %2.2d-%2.2d-%2.2d\n",
+		minfo->revision_number_major, minfo->revision_number_minor,
+		minfo->module_year, minfo->module_month, minfo->module_day);
+
+	dev_dbg(&client->dev, "sensor 0x%2.2x-0x%4.4x\n",
+		minfo->sensor_manufacturer_id, minfo->sensor_model_id);
+
+	dev_dbg(&client->dev,
+		"sensor revision 0x%2.2x firmware version 0x%2.2x\n",
+		minfo->sensor_revision_number, minfo->sensor_firmware_version);
+
+	dev_dbg(&client->dev, "smia version %2.2d smiapp version %2.2d\n",
+		minfo->smia_version, minfo->smiapp_version);
+
+	if (!minfo->manufacturer_id && !minfo->model_id) {
+		minfo->manufacturer_id = minfo->sensor_manufacturer_id;
+		minfo->model_id = minfo->sensor_model_id;
+		minfo->revision_number_major = minfo->sensor_revision_number;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(smiapp_module_idents); i++) {
+		if (smiapp_module_idents[i].manufacturer_id
+		    != minfo->manufacturer_id)
+			continue;
+		if (smiapp_module_idents[i].model_id != minfo->model_id)
+			continue;
+		if (smiapp_module_idents[i].flags
+		    & SMIAPP_MODULE_IDENT_FLAG_REV_LE) {
+			if (smiapp_module_idents[i].revision_number_major
+			    < minfo->revision_number_major)
+				continue;
+		} else {
+			if (smiapp_module_idents[i].revision_number_major
+			    != minfo->revision_number_major)
+				continue;
+		}
+
+		minfo->name = smiapp_module_idents[i].name;
+		minfo->quirk = smiapp_module_idents[i].quirk;
+		break;
+	}
+
+	if (i >= ARRAY_SIZE(smiapp_module_idents))
+		dev_warn(&client->dev, "no quirks for this module\n");
+
+	dev_dbg(&client->dev, "the sensor is called %s, ident %2.2x%4.4x%2.2x\n",
+		minfo->name, minfo->manufacturer_id, minfo->model_id,
+		minfo->revision_number_major);
+
+	strlcpy(subdev->name, sensor->minfo.name, sizeof(subdev->name));
+
+	return 0;
+}
+
+static const struct v4l2_subdev_ops smiapp_ops;
+static const struct v4l2_subdev_internal_ops smiapp_internal_ops;
+static const struct media_entity_operations smiapp_entity_ops;
+
+static int smiapp_registered(struct v4l2_subdev *subdev)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	struct i2c_client *client = v4l2_get_subdevdata(subdev);
+	struct smiapp_subdev *last = NULL;
+	int rval;
+	u32 tmp, i;
+
+	sensor->vana = regulator_get(&client->dev, "VANA");
+	if (IS_ERR(sensor->vana)) {
+		dev_err(&client->dev, "could not get regulator for vana\n");
+		return -ENODEV;
+	}
+
+	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) {
+		if (gpio_request_one(sensor->platform_data->xshutdown, 0,
+				     "SMIA++ xshutdown") != 0) {
+			dev_err(&client->dev,
+				"unable to acquire reset gpio %d\n",
+				sensor->platform_data->xshutdown);
+			rval = -ENODEV;
+			goto out_gpio_request;
+		}
+	}
+
+	rval = smiapp_power_on(sensor);
+	if (rval) {
+		rval = -ENODEV;
+		goto out_smiapp_power_on;
+	}
+
+	rval = smiapp_identify_module(subdev);
+	if (rval) {
+		rval = -ENODEV;
+		goto out_power_off;
+	}
+
+	rval = smiapp_get_all_limits(sensor);
+	if (rval) {
+		rval = -ENODEV;
+		goto out_power_off;
+	}
+
+	/*
+	 * Handle Sensor Module orientation on the board.
+	 *
+	 * The application of H-FLIP and V-FLIP on the sensor is modified by
+	 * the sensor orientation on the board.
+	 *
+	 * For SMIAPP_BOARD_SENSOR_ORIENT_180 the default behaviour is to set
+	 * both H-FLIP and V-FLIP for normal operation which also implies
+	 * that a set/unset operation for user space HFLIP and VFLIP v4l2
+	 * controls will need to be internally inverted.
+	 *
+	 * Rotation also changes the bayer pattern.
+	 */
+	if (sensor->platform_data->module_board_orient ==
+	    SMIAPP_MODULE_BOARD_ORIENT_180)
+		sensor->hvflip_inv_mask = SMIAPP_IMAGE_ORIENTATION_HFLIP |
+					  SMIAPP_IMAGE_ORIENTATION_VFLIP;
+
+	rval = smiapp_get_mbus_formats(sensor);
+	if (rval) {
+		rval = -ENODEV;
+		goto out_power_off;
+	}
+
+	if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY]) {
+		int i;
+		int val;
+
+		rval = smia_i2c_read_reg(client,
+					 SMIAPP_REG_U8_BINNING_SUBTYPES, &val);
+		if (rval < 0) {
+			rval = -ENODEV;
+			goto out_power_off;
+		}
+		sensor->nbinning_subtypes = min_t(u8, val,
+						  SMIAPP_BINNING_SUBTYPES);
+
+		for (i = 0; i < sensor->nbinning_subtypes; i++) {
+			rval = smia_i2c_read_reg(
+				client, SMIAPP_REG_U8_BINNING_TYPE_n(i), &val);
+			if (rval < 0) {
+				rval = -ENODEV;
+				goto out_power_off;
+			}
+			sensor->binning_subtypes[i] =
+				*(struct smiapp_binning_subtype *)&val;
+
+			dev_dbg(&client->dev, "binning %xx%x\n",
+				sensor->binning_subtypes[i].horizontal,
+				sensor->binning_subtypes[i].vertical);
+		}
+	}
+	sensor->binning_horizontal = 1;
+	sensor->binning_vertical = 1;
+
+	/* SMIA++ NVM initialization - it will be read from the sensor
+	 * when it is first requested by userspace.
+	 */
+	if (sensor->minfo.smiapp_version && sensor->platform_data->nvm_size) {
+		sensor->nvm = kzalloc(sensor->platform_data->nvm_size,
+				      GFP_KERNEL);
+		if (sensor->nvm == NULL) {
+			dev_err(&client->dev, "nvm buf allocation failed\n");
+			rval = -ENOMEM;
+			goto out_power_off;
+		}
+
+		if (device_create_file(&client->dev, &dev_attr_nvm) != 0) {
+			dev_err(&client->dev, "sysfs nvm entry failed\n");
+			rval = -EBUSY;
+			goto out_nvm_release1;
+		}
+	}
+
+	rval = smiapp_call_quirk(sensor, limits);
+	if (rval) {
+		dev_err(&client->dev, "limits quirks failed\n");
+		goto out_nvm_release2;
+	}
+
+	/* We consider this as profile 0 sensor if any of these are zero. */
+	if (!sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV] ||
+	    !sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV] ||
+	    !sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV] ||
+	    !sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV]) {
+		sensor->minfo.smiapp_profile = SMIAPP_PROFILE_0;
+	} else if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
+		   != SMIAPP_SCALING_CAPABILITY_NONE) {
+		if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
+		    == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
+			sensor->minfo.smiapp_profile = SMIAPP_PROFILE_1;
+		else
+			sensor->minfo.smiapp_profile = SMIAPP_PROFILE_2;
+		sensor->scaler = &sensor->sds[sensor->sds_used];
+		sensor->sds_used++;
+	} else if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
+		   == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
+		sensor->scaler = &sensor->sds[sensor->sds_used];
+		sensor->sds_used++;
+	}
+	sensor->binner = &sensor->sds[sensor->sds_used];
+	sensor->sds_used++;
+	sensor->pixel_array = &sensor->sds[sensor->sds_used];
+	sensor->sds_used++;
+
+	sensor->scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
+
+	for (i = 0; i < SMIAPP_SUBDEVS; i++) {
+		struct {
+			struct smiapp_subdev *sds;
+			char *name;
+		} _t[] = {
+			{ sensor->scaler, "scaler", },
+			{ sensor->binner, "binner", },
+			{ sensor->pixel_array, "pixel array", },
+		}, *this = &_t[i];
+		if (!this->sds)
+			continue;
+
+		if (this->sds != sensor->src)
+			v4l2_subdev_init(&this->sds->sd, &smiapp_ops);
+
+		this->sds->sensor = sensor;
+
+		if (this->sds == sensor->pixel_array) {
+			if (this->sds == sensor->src)
+				sensor->sds->sd.entity.num_pads = 1;
+			this->sds->npads = 1;
+		} else {
+			this->sds->npads = 2;
+		}
+
+		snprintf(this->sds->sd.name,
+			 sizeof(this->sds->sd.name), "%s %s",
+			 sensor->minfo.name, this->name);
+
+		this->sds->sink_fmt.width =
+			sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
+		this->sds->sink_fmt.height =
+			sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
+		this->sds->crop[SMIAPP_PAD_SINK].width =
+			this->sds->sink_fmt.width;
+		this->sds->crop[SMIAPP_PAD_SINK].height =
+			this->sds->sink_fmt.height;
+		this->sds->crop[SMIAPP_PAD_SOURCE] =
+			this->sds->compose =
+			this->sds->crop[SMIAPP_PAD_SINK];
+
+		this->sds->pads[1].flags = MEDIA_PAD_FL_SINK;
+		this->sds->pads[0].flags = MEDIA_PAD_FL_SOURCE;
+
+		this->sds->sd.entity.ops = &smiapp_entity_ops;
+
+		if (last == NULL) {
+			last = this->sds;
+			continue;
+		}
+
+		this->sds->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+		this->sds->sd.internal_ops = &smiapp_internal_ops;
+		this->sds->sd.owner = NULL;
+		v4l2_set_subdevdata(&this->sds->sd, client);
+
+		rval = v4l2_device_register_subdev(sensor->src->sd.v4l2_dev,
+						   &this->sds->sd);
+		if (rval) {
+			dev_err(&client->dev,
+				"v4l2_device_register_subdev failed\n");
+			goto out_nvm_release2;
+		}
+
+		rval = media_entity_init(&this->sds->sd.entity,
+					 this->sds->npads, this->sds->pads, 0);
+		if (rval) {
+			dev_err(&client->dev,
+				"media_entity_init failed\n");
+			goto out_nvm_release2;
+		}
+
+		rval = media_entity_create_link(&this->sds->sd.entity, 0,
+						&last->sd.entity, 1,
+						MEDIA_LNK_FL_ENABLED |
+						MEDIA_LNK_FL_IMMUTABLE);
+		if (rval) {
+			dev_err(&client->dev,
+				"media_entity_create_link failed\n");
+			goto out_nvm_release2;
+		}
+
+		last = this->sds;
+	}
+
+	dev_dbg(&client->dev, "profile %d\n", sensor->minfo.smiapp_profile);
+
+	sensor->pixel_array->sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
+
+	/* final steps */
+	smiapp_read_frame_fmt(sensor);
+	rval = smiapp_init_controls(sensor);
+	if (rval < 0)
+		goto out_nvm_release2;
+
+	rval = smiapp_update_mode(sensor);
+	if (rval) {
+		dev_err(&client->dev, "update mode failed\n");
+		goto out_nvm_release2;
+	}
+
+	sensor->streaming = false;
+	sensor->dev_init_done = true;
+
+	/* check flash capability */
+	rval = smia_i2c_read_reg(client,
+				 SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, &tmp);
+	sensor->flash_capability = tmp;
+	if (rval)
+		goto out_nvm_release2;
+
+	smiapp_power_off(sensor);
+
+	return 0;
+
+out_nvm_release2:
+	device_remove_file(&client->dev, &dev_attr_nvm);
+
+out_nvm_release1:
+	kfree(sensor->nvm);
+	sensor->nvm = NULL;
+
+out_power_off:
+	smiapp_power_off(sensor);
+
+out_smiapp_power_on:
+	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
+		gpio_free(sensor->platform_data->xshutdown);
+
+out_gpio_request:
+	regulator_put(sensor->vana);
+	sensor->vana = NULL;
+	return rval;
+}
+
+static int smiapp_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+	struct smiapp_subdev *ssd = to_smiapp_subdev(sd);
+	struct v4l2_subdev_selection sel;
+	struct v4l2_rect *try_sel;
+	int i;
+	int rval;
+
+	mutex_lock(&ssd->sensor->power_mutex);
+	mutex_lock(&ssd->sensor->mutex);
+
+	for (i = 0; i < ssd->npads; i++) {
+		struct v4l2_subdev_format fmt;
+		struct v4l2_mbus_framefmt *try_fmt;
+
+		fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+		fmt.pad = i;
+		__smiapp_get_format(sd, fh, &fmt);
+		try_fmt = v4l2_subdev_get_try_format(fh, i);
+		*try_fmt = fmt.format;
+
+		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+		sel.pad = i;
+		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
+		__smiapp_get_selection(sd, fh, &sel);
+		try_sel = v4l2_subdev_get_try_crop(fh, i);
+		*try_sel = sel.r;
+	}
+
+	if (ssd != ssd->sensor->pixel_array) {
+		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+		sel.pad = SMIAPP_PAD_SINK;
+		sel.target = V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE;
+		__smiapp_get_selection(sd, fh, &sel);
+		try_sel = v4l2_subdev_get_try_compose(fh, SMIAPP_PAD_SINK);
+		*try_sel = sel.r;
+	}
+
+	rval = smiapp_set_power(sd, 1);
+
+	mutex_unlock(&ssd->sensor->mutex);
+
+	if (rval < 0)
+		goto out;
+
+	/* Was the sensor already powered on? */
+	if (ssd->sensor->power_count > 1)
+		goto out;
+
+	for (i = 0; i < ssd->sensor->sds_used; i++) {
+		rval = v4l2_ctrl_handler_setup(
+			&ssd->sensor->sds[i].ctrl_handler);
+		if (rval)
+			goto out;
+	}
+
+out:
+	mutex_unlock(&ssd->sensor->power_mutex);
+
+	return rval;
+}
+
+static int smiapp_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+	struct smiapp_sensor *sensor = to_smiapp_sensor(sd);
+	int rval;
+
+	mutex_lock(&sensor->power_mutex);
+	mutex_lock(&sensor->mutex);
+	rval = smiapp_set_power(sd, 0);
+	mutex_unlock(&sensor->mutex);
+	mutex_unlock(&sensor->power_mutex);
+
+	return rval;
+}
+
+static const struct v4l2_subdev_video_ops smiapp_video_ops = {
+	.s_stream = smiapp_set_stream,
+};
+
+static const struct v4l2_subdev_core_ops smiapp_core_ops = {
+	.s_power = smiapp_set_power,
+};
+
+static const struct v4l2_subdev_pad_ops smiapp_pad_ops = {
+	.enum_mbus_code = smiapp_enum_mbus_code,
+	.get_fmt = smiapp_get_format,
+	.set_fmt = smiapp_set_format,
+	.get_selection = smiapp_get_selection,
+	.set_selection = smiapp_set_selection,
+	.link_validate = v4l2_subdev_link_validate_default,
+};
+
+static const struct v4l2_subdev_sensor_ops smiapp_sensor_ops = {
+	.g_skip_frames = smiapp_get_skip_frames,
+};
+
+static const struct v4l2_subdev_ops smiapp_ops = {
+	.core = &smiapp_core_ops,
+	.video = &smiapp_video_ops,
+	.pad = &smiapp_pad_ops,
+	.sensor = &smiapp_sensor_ops,
+};
+
+static const struct media_entity_operations smiapp_entity_ops = {
+	.link_validate = v4l2_subdev_link_validate,
+};
+
+static const struct v4l2_subdev_internal_ops smiapp_internal_src_ops = {
+	.registered = smiapp_registered,
+	.open = smiapp_open,
+	.close = smiapp_close,
+};
+
+static const struct v4l2_subdev_internal_ops smiapp_internal_ops = {
+	.open = smiapp_open,
+	.close = smiapp_close,
+};
+
+/* -----------------------------------------------------------------------------
+ * I2C Driver
+ */
+
+#ifdef CONFIG_PM
+
+static int smiapp_suspend(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int ss;
+
+	BUG_ON(mutex_is_locked(&sensor->mutex));
+
+	if (sensor->power_count == 0)
+		return 0;
+
+	if (sensor->streaming)
+		smiapp_stop_streaming(sensor);
+
+	ss = sensor->streaming;
+
+	smiapp_power_off(sensor);
+
+	/* save state for resume */
+	sensor->streaming = ss;
+
+	return 0;
+}
+
+static int smiapp_resume(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int rval;
+
+	if (sensor->power_count == 0)
+		return 0;
+
+	rval = smiapp_power_on(sensor);
+	if (rval)
+		return rval;
+
+	if (sensor->streaming)
+		rval = smiapp_start_streaming(sensor);
+
+	return rval;
+}
+
+#else
+
+#define smiapp_suspend	NULL
+#define smiapp_resume	NULL
+
+#endif /* CONFIG_PM */
+
+static int smiapp_probe(struct i2c_client *client,
+			const struct i2c_device_id *devid)
+{
+	struct smiapp_sensor *sensor;
+	int rval;
+
+	if (client->dev.platform_data == NULL)
+		return -ENODEV;
+
+	sensor = kzalloc(sizeof(*sensor), GFP_KERNEL);
+	if (sensor == NULL)
+		return -ENOMEM;
+
+	sensor->platform_data = client->dev.platform_data;
+	mutex_init(&sensor->mutex);
+	mutex_init(&sensor->power_mutex);
+	sensor->src = &sensor->sds[sensor->sds_used];
+
+	v4l2_i2c_subdev_init(&sensor->src->sd, client, &smiapp_ops);
+	sensor->src->sd.internal_ops = &smiapp_internal_src_ops;
+	sensor->src->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	sensor->src->sensor = sensor;
+
+	sensor->src->pads[0].flags = MEDIA_PAD_FL_SOURCE;
+	rval = media_entity_init(&sensor->src->sd.entity, 2,
+				 sensor->src->pads, 0);
+	if (rval < 0)
+		kfree(sensor);
+
+	return rval;
+}
+
+static int __exit smiapp_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
+	int i;
+
+	if (sensor->power_count) {
+		if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
+			gpio_set_value(sensor->platform_data->xshutdown, 0);
+		sensor->platform_data->set_xclk(&sensor->src->sd, 0);
+		sensor->power_count = 0;
+	}
+
+	if (sensor->nvm) {
+		device_remove_file(&client->dev, &dev_attr_nvm);
+		kfree(sensor->nvm);
+	}
+
+	for (i = 0; i < sensor->sds_used; i++) {
+		media_entity_cleanup(&sensor->sds[i].sd.entity);
+		v4l2_device_unregister_subdev(&sensor->sds[i].sd);
+	}
+	smiapp_free_controls(sensor);
+	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
+		gpio_free(sensor->platform_data->xshutdown);
+	if (sensor->vana)
+		regulator_put(sensor->vana);
+
+	kfree(sensor);
+
+	return 0;
+}
+
+static const struct i2c_device_id smiapp_id_table[] = {
+	{ SMIAPP_NAME, 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(i2c, smiapp_id_table);
+
+static const struct dev_pm_ops smiapp_pm_ops = {
+	.suspend	= smiapp_suspend,
+	.resume		= smiapp_resume,
+};
+
+static struct i2c_driver smiapp_i2c_driver = {
+	.driver	= {
+		.name = SMIAPP_NAME,
+		.pm = &smiapp_pm_ops,
+	},
+	.probe	= smiapp_probe,
+	.remove	= __exit_p(smiapp_remove),
+	.id_table = smiapp_id_table,
+};
+
+static int __init smiapp_init(void)
+{
+	int rval;
+
+	rval = i2c_add_driver(&smiapp_i2c_driver);
+	if (rval)
+		pr_err("Failed registering driver" SMIAPP_NAME "\n");
+
+	return rval;
+}
+
+static void __exit smiapp_exit(void)
+{
+	i2c_del_driver(&smiapp_i2c_driver);
+}
+
+module_init(smiapp_init);
+module_exit(smiapp_exit);
+
+MODULE_AUTHOR("Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>");
+MODULE_DESCRIPTION("Generic SMIA/SMIA++ camera module driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/smiapp/smiapp-debug.h b/drivers/media/video/smiapp/smiapp-debug.h
new file mode 100644
index 0000000..011bf53
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-debug.h
@@ -0,0 +1,32 @@
+/*
+ * drivers/media/video/smiapp-debug.h
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef SMIAPP_DEBUG_H
+#define SMIAPP_DEBUG_H
+
+#ifdef CONFIG_VIDEO_SMIAPP_DEBUG
+#define DEBUG
+#endif
+
+#endif
diff --git a/drivers/media/video/smiapp/smiapp-limits.c b/drivers/media/video/smiapp/smiapp-limits.c
new file mode 100644
index 0000000..79c740d
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-limits.c
@@ -0,0 +1,132 @@
+/*
+ * drivers/media/video/smiapp-limits.c
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "smiapp.h"
+
+struct smiapp_reg_limits smiapp_reg_limits[] = {
+	{ SMIAPP_REG_U16_ANALOGUE_GAIN_CAPABILITY, "analogue_gain_capability" }, /* 0 */
+	{ SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_MIN, "analogue_gain_code_min" },
+	{ SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_MAX, "analogue_gain_code_max" },
+	{ SMIAPP_REG_U8_THS_ZERO_MIN, "ths_zero_min" },
+	{ SMIAPP_REG_U8_TCLK_TRAIL_MIN, "tclk_trail_min" },
+	{ SMIAPP_REG_U16_INTEGRATION_TIME_CAPABILITY, "integration_time_capability" }, /* 5 */
+	{ SMIAPP_REG_U16_COARSE_INTEGRATION_TIME_MIN, "coarse_integration_time_min" },
+	{ SMIAPP_REG_U16_COARSE_INTEGRATION_TIME_MAX_MARGIN, "coarse_integration_time_max_margin" },
+	{ SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MIN, "fine_integration_time_min" },
+	{ SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MAX_MARGIN, "fine_integration_time_max_margin" },
+	{ SMIAPP_REG_U16_DIGITAL_GAIN_CAPABILITY, "digital_gain_capability" }, /* 10 */
+	{ SMIAPP_REG_U16_DIGITAL_GAIN_MIN, "digital_gain_min" },
+	{ SMIAPP_REG_U16_DIGITAL_GAIN_MAX, "digital_gain_max" },
+	{ SMIAPP_REG_F32_MIN_EXT_CLK_FREQ_HZ, "min_ext_clk_freq_hz" },
+	{ SMIAPP_REG_F32_MAX_EXT_CLK_FREQ_HZ, "max_ext_clk_freq_hz" },
+	{ SMIAPP_REG_U16_MIN_PRE_PLL_CLK_DIV, "min_pre_pll_clk_div" }, /* 15 */
+	{ SMIAPP_REG_U16_MAX_PRE_PLL_CLK_DIV, "max_pre_pll_clk_div" },
+	{ SMIAPP_REG_F32_MIN_PLL_IP_FREQ_HZ, "min_pll_ip_freq_hz" },
+	{ SMIAPP_REG_F32_MAX_PLL_IP_FREQ_HZ, "max_pll_ip_freq_hz" },
+	{ SMIAPP_REG_U16_MIN_PLL_MULTIPLIER, "min_pll_multiplier" },
+	{ SMIAPP_REG_U16_MAX_PLL_MULTIPLIER, "max_pll_multiplier" }, /* 20 */
+	{ SMIAPP_REG_F32_MIN_PLL_OP_FREQ_HZ, "min_pll_op_freq_hz" },
+	{ SMIAPP_REG_F32_MAX_PLL_OP_FREQ_HZ, "max_pll_op_freq_hz" },
+	{ SMIAPP_REG_U16_MIN_VT_SYS_CLK_DIV, "min_vt_sys_clk_div" },
+	{ SMIAPP_REG_U16_MAX_VT_SYS_CLK_DIV, "max_vt_sys_clk_div" },
+	{ SMIAPP_REG_F32_MIN_VT_SYS_CLK_FREQ_HZ, "min_vt_sys_clk_freq_hz" }, /* 25 */
+	{ SMIAPP_REG_F32_MAX_VT_SYS_CLK_FREQ_HZ, "max_vt_sys_clk_freq_hz" },
+	{ SMIAPP_REG_F32_MIN_VT_PIX_CLK_FREQ_HZ, "min_vt_pix_clk_freq_hz" },
+	{ SMIAPP_REG_F32_MAX_VT_PIX_CLK_FREQ_HZ, "max_vt_pix_clk_freq_hz" },
+	{ SMIAPP_REG_U16_MIN_VT_PIX_CLK_DIV, "min_vt_pix_clk_div" },
+	{ SMIAPP_REG_U16_MAX_VT_PIX_CLK_DIV, "max_vt_pix_clk_div" }, /* 30 */
+	{ SMIAPP_REG_U16_MIN_FRAME_LENGTH_LINES, "min_frame_length_lines" },
+	{ SMIAPP_REG_U16_MAX_FRAME_LENGTH_LINES, "max_frame_length_lines" },
+	{ SMIAPP_REG_U16_MIN_LINE_LENGTH_PCK, "min_line_length_pck" },
+	{ SMIAPP_REG_U16_MAX_LINE_LENGTH_PCK, "max_line_length_pck" },
+	{ SMIAPP_REG_U16_MIN_LINE_BLANKING_PCK, "min_line_blanking_pck" }, /* 35 */
+	{ SMIAPP_REG_U16_MIN_FRAME_BLANKING_LINES, "min_frame_blanking_lines" },
+	{ SMIAPP_REG_U8_MIN_LINE_LENGTH_PCK_STEP_SIZE, "min_line_length_pck_step_size" },
+	{ SMIAPP_REG_U16_MIN_OP_SYS_CLK_DIV, "min_op_sys_clk_div" },
+	{ SMIAPP_REG_U16_MAX_OP_SYS_CLK_DIV, "max_op_sys_clk_div" },
+	{ SMIAPP_REG_F32_MIN_OP_SYS_CLK_FREQ_HZ, "min_op_sys_clk_freq_hz" }, /* 40 */
+	{ SMIAPP_REG_F32_MAX_OP_SYS_CLK_FREQ_HZ, "max_op_sys_clk_freq_hz" },
+	{ SMIAPP_REG_U16_MIN_OP_PIX_CLK_DIV, "min_op_pix_clk_div" },
+	{ SMIAPP_REG_U16_MAX_OP_PIX_CLK_DIV, "max_op_pix_clk_div" },
+	{ SMIAPP_REG_F32_MIN_OP_PIX_CLK_FREQ_HZ, "min_op_pix_clk_freq_hz" },
+	{ SMIAPP_REG_F32_MAX_OP_PIX_CLK_FREQ_HZ, "max_op_pix_clk_freq_hz" }, /* 45 */
+	{ SMIAPP_REG_U16_X_ADDR_MIN, "x_addr_min" },
+	{ SMIAPP_REG_U16_Y_ADDR_MIN, "y_addr_min" },
+	{ SMIAPP_REG_U16_X_ADDR_MAX, "x_addr_max" },
+	{ SMIAPP_REG_U16_Y_ADDR_MAX, "y_addr_max" },
+	{ SMIAPP_REG_U16_MIN_X_OUTPUT_SIZE, "min_x_output_size" }, /* 50 */
+	{ SMIAPP_REG_U16_MIN_Y_OUTPUT_SIZE, "min_y_output_size" },
+	{ SMIAPP_REG_U16_MAX_X_OUTPUT_SIZE, "max_x_output_size" },
+	{ SMIAPP_REG_U16_MAX_Y_OUTPUT_SIZE, "max_y_output_size" },
+	{ SMIAPP_REG_U16_MIN_EVEN_INC, "min_even_inc" },
+	{ SMIAPP_REG_U16_MAX_EVEN_INC, "max_even_inc" }, /* 55 */
+	{ SMIAPP_REG_U16_MIN_ODD_INC, "min_odd_inc" },
+	{ SMIAPP_REG_U16_MAX_ODD_INC, "max_odd_inc" },
+	{ SMIAPP_REG_U16_SCALING_CAPABILITY, "scaling_capability" },
+	{ SMIAPP_REG_U16_SCALER_M_MIN, "scaler_m_min" },
+	{ SMIAPP_REG_U16_SCALER_M_MAX, "scaler_m_max" }, /* 60 */
+	{ SMIAPP_REG_U16_SCALER_N_MIN, "scaler_n_min" },
+	{ SMIAPP_REG_U16_SCALER_N_MAX, "scaler_n_max" },
+	{ SMIAPP_REG_U16_SPATIAL_SAMPLING_CAPABILITY, "spatial_sampling_capability" },
+	{ SMIAPP_REG_U8_DIGITAL_CROP_CAPABILITY, "digital_crop_capability" },
+	{ SMIAPP_REG_U16_COMPRESSION_CAPABILITY, "compression_capability" }, /* 65 */
+	{ SMIAPP_REG_U8_FIFO_SUPPORT_CAPABILITY, "fifo_support_capability" },
+	{ SMIAPP_REG_U8_DPHY_CTRL_CAPABILITY, "dphy_ctrl_capability" },
+	{ SMIAPP_REG_U8_CSI_LANE_MODE_CAPABILITY, "csi_lane_mode_capability" },
+	{ SMIAPP_REG_U8_CSI_SIGNALLING_MODE_CAPABILITY, "csi_signalling_mode_capability" },
+	{ SMIAPP_REG_U8_FAST_STANDBY_CAPABILITY, "fast_standby_capability" }, /* 70 */
+	{ SMIAPP_REG_U8_CCI_ADDRESS_CONTROL_CAPABILITY, "cci_address_control_capability" },
+	{ SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_1_LANE_MODE_MBPS, "max_per_lane_bitrate_1_lane_mode_mbps" },
+	{ SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_2_LANE_MODE_MBPS, "max_per_lane_bitrate_2_lane_mode_mbps" },
+	{ SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_3_LANE_MODE_MBPS, "max_per_lane_bitrate_3_lane_mode_mbps" },
+	{ SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_4_LANE_MODE_MBPS, "max_per_lane_bitrate_4_lane_mode_mbps" }, /* 75 */
+	{ SMIAPP_REG_U8_TEMP_SENSOR_CAPABILITY, "temp_sensor_capability" },
+	{ SMIAPP_REG_U16_MIN_FRAME_LENGTH_LINES_BIN, "min_frame_length_lines_bin" },
+	{ SMIAPP_REG_U16_MAX_FRAME_LENGTH_LINES_BIN, "max_frame_length_lines_bin" },
+	{ SMIAPP_REG_U16_MIN_LINE_LENGTH_PCK_BIN, "min_line_length_pck_bin" },
+	{ SMIAPP_REG_U16_MAX_LINE_LENGTH_PCK_BIN, "max_line_length_pck_bin" }, /* 80 */
+	{ SMIAPP_REG_U16_MIN_LINE_BLANKING_PCK_BIN, "min_line_blanking_pck_bin" },
+	{ SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MIN_BIN, "fine_integration_time_min_bin" },
+	{ SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN, "fine_integration_time_max_margin_bin" },
+	{ SMIAPP_REG_U8_BINNING_CAPABILITY, "binning_capability" },
+	{ SMIAPP_REG_U8_BINNING_WEIGHTING_CAPABILITY, "binning_weighting_capability" }, /* 85 */
+	{ SMIAPP_REG_U8_DATA_TRANSFER_IF_CAPABILITY, "data_transfer_if_capability" },
+	{ SMIAPP_REG_U8_SHADING_CORRECTION_CAPABILITY, "shading_correction_capability" },
+	{ SMIAPP_REG_U8_GREEN_IMBALANCE_CAPABILITY, "green_imbalance_capability" },
+	{ SMIAPP_REG_U8_BLACK_LEVEL_CAPABILITY, "black_level_capability" },
+	{ SMIAPP_REG_U8_MODULE_SPECIFIC_CORRECTION_CAPABILITY, "module_specific_correction_capability" }, /* 90 */
+	{ SMIAPP_REG_U16_DEFECT_CORRECTION_CAPABILITY, "defect_correction_capability" },
+	{ SMIAPP_REG_U16_DEFECT_CORRECTION_CAPABILITY_2, "defect_correction_capability_2" },
+	{ SMIAPP_REG_U8_EDOF_CAPABILITY, "edof_capability" },
+	{ SMIAPP_REG_U8_COLOUR_FEEDBACK_CAPABILITY, "colour_feedback_capability" },
+	{ SMIAPP_REG_U8_ESTIMATION_MODE_CAPABILITY, "estimation_mode_capability" }, /* 95 */
+	{ SMIAPP_REG_U8_ESTIMATION_ZONE_CAPABILITY, "estimation_zone_capability" },
+	{ SMIAPP_REG_U16_CAPABILITY_TRDY_MIN, "capability_trdy_min" },
+	{ SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, "flash_mode_capability" },
+	{ SMIAPP_REG_U8_ACTUATOR_CAPABILITY, "actuator_capability" },
+	{ SMIAPP_REG_U8_BRACKETING_LUT_CAPABILITY_1, "bracketing_lut_capability_1" }, /* 100 */
+	{ SMIAPP_REG_U8_BRACKETING_LUT_CAPABILITY_2, "bracketing_lut_capability_2" },
+	{ SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_STEP, "analogue_gain_code_step" },
+	{ 0, NULL },
+};
diff --git a/drivers/media/video/smiapp/smiapp-limits.h b/drivers/media/video/smiapp/smiapp-limits.h
new file mode 100644
index 0000000..b74c03d
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-limits.h
@@ -0,0 +1,128 @@
+/*
+ * drivers/media/video/smiapp-limits.h
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#define SMIAPP_LIMIT_ANALOGUE_GAIN_CAPABILITY			0
+#define SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN			1
+#define SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX			2
+#define SMIAPP_LIMIT_THS_ZERO_MIN				3
+#define SMIAPP_LIMIT_TCLK_TRAIL_MIN				4
+#define SMIAPP_LIMIT_INTEGRATION_TIME_CAPABILITY		5
+#define SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN		6
+#define SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MAX_MARGIN		7
+#define SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN			8
+#define SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN		9
+#define SMIAPP_LIMIT_DIGITAL_GAIN_CAPABILITY			10
+#define SMIAPP_LIMIT_DIGITAL_GAIN_MIN				11
+#define SMIAPP_LIMIT_DIGITAL_GAIN_MAX				12
+#define SMIAPP_LIMIT_MIN_EXT_CLK_FREQ_HZ			13
+#define SMIAPP_LIMIT_MAX_EXT_CLK_FREQ_HZ			14
+#define SMIAPP_LIMIT_MIN_PRE_PLL_CLK_DIV			15
+#define SMIAPP_LIMIT_MAX_PRE_PLL_CLK_DIV			16
+#define SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ				17
+#define SMIAPP_LIMIT_MAX_PLL_IP_FREQ_HZ				18
+#define SMIAPP_LIMIT_MIN_PLL_MULTIPLIER				19
+#define SMIAPP_LIMIT_MAX_PLL_MULTIPLIER				20
+#define SMIAPP_LIMIT_MIN_PLL_OP_FREQ_HZ				21
+#define SMIAPP_LIMIT_MAX_PLL_OP_FREQ_HZ				22
+#define SMIAPP_LIMIT_MIN_VT_SYS_CLK_DIV				23
+#define SMIAPP_LIMIT_MAX_VT_SYS_CLK_DIV				24
+#define SMIAPP_LIMIT_MIN_VT_SYS_CLK_FREQ_HZ			25
+#define SMIAPP_LIMIT_MAX_VT_SYS_CLK_FREQ_HZ			26
+#define SMIAPP_LIMIT_MIN_VT_PIX_CLK_FREQ_HZ			27
+#define SMIAPP_LIMIT_MAX_VT_PIX_CLK_FREQ_HZ			28
+#define SMIAPP_LIMIT_MIN_VT_PIX_CLK_DIV				29
+#define SMIAPP_LIMIT_MAX_VT_PIX_CLK_DIV				30
+#define SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES			31
+#define SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES			32
+#define SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK			33
+#define SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK			34
+#define SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK			35
+#define SMIAPP_LIMIT_MIN_FRAME_BLANKING_LINES			36
+#define SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_STEP_SIZE		37
+#define SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV				38
+#define SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV				39
+#define SMIAPP_LIMIT_MIN_OP_SYS_CLK_FREQ_HZ			40
+#define SMIAPP_LIMIT_MAX_OP_SYS_CLK_FREQ_HZ			41
+#define SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV				42
+#define SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV				43
+#define SMIAPP_LIMIT_MIN_OP_PIX_CLK_FREQ_HZ			44
+#define SMIAPP_LIMIT_MAX_OP_PIX_CLK_FREQ_HZ			45
+#define SMIAPP_LIMIT_X_ADDR_MIN					46
+#define SMIAPP_LIMIT_Y_ADDR_MIN					47
+#define SMIAPP_LIMIT_X_ADDR_MAX					48
+#define SMIAPP_LIMIT_Y_ADDR_MAX					49
+#define SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE				50
+#define SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE				51
+#define SMIAPP_LIMIT_MAX_X_OUTPUT_SIZE				52
+#define SMIAPP_LIMIT_MAX_Y_OUTPUT_SIZE				53
+#define SMIAPP_LIMIT_MIN_EVEN_INC				54
+#define SMIAPP_LIMIT_MAX_EVEN_INC				55
+#define SMIAPP_LIMIT_MIN_ODD_INC				56
+#define SMIAPP_LIMIT_MAX_ODD_INC				57
+#define SMIAPP_LIMIT_SCALING_CAPABILITY				58
+#define SMIAPP_LIMIT_SCALER_M_MIN				59
+#define SMIAPP_LIMIT_SCALER_M_MAX				60
+#define SMIAPP_LIMIT_SCALER_N_MIN				61
+#define SMIAPP_LIMIT_SCALER_N_MAX				62
+#define SMIAPP_LIMIT_SPATIAL_SAMPLING_CAPABILITY		63
+#define SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY			64
+#define SMIAPP_LIMIT_COMPRESSION_CAPABILITY			65
+#define SMIAPP_LIMIT_FIFO_SUPPORT_CAPABILITY			66
+#define SMIAPP_LIMIT_DPHY_CTRL_CAPABILITY			67
+#define SMIAPP_LIMIT_CSI_LANE_MODE_CAPABILITY			68
+#define SMIAPP_LIMIT_CSI_SIGNALLING_MODE_CAPABILITY		69
+#define SMIAPP_LIMIT_FAST_STANDBY_CAPABILITY			70
+#define SMIAPP_LIMIT_CCI_ADDRESS_CONTROL_CAPABILITY		71
+#define SMIAPP_LIMIT_MAX_PER_LANE_BITRATE_1_LANE_MODE_MBPS	72
+#define SMIAPP_LIMIT_MAX_PER_LANE_BITRATE_2_LANE_MODE_MBPS	73
+#define SMIAPP_LIMIT_MAX_PER_LANE_BITRATE_3_LANE_MODE_MBPS	74
+#define SMIAPP_LIMIT_MAX_PER_LANE_BITRATE_4_LANE_MODE_MBPS	75
+#define SMIAPP_LIMIT_TEMP_SENSOR_CAPABILITY			76
+#define SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN			77
+#define SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN			78
+#define SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN			79
+#define SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN			80
+#define SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN			81
+#define SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN_BIN		82
+#define SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN	83
+#define SMIAPP_LIMIT_BINNING_CAPABILITY				84
+#define SMIAPP_LIMIT_BINNING_WEIGHTING_CAPABILITY		85
+#define SMIAPP_LIMIT_DATA_TRANSFER_IF_CAPABILITY		86
+#define SMIAPP_LIMIT_SHADING_CORRECTION_CAPABILITY		87
+#define SMIAPP_LIMIT_GREEN_IMBALANCE_CAPABILITY			88
+#define SMIAPP_LIMIT_BLACK_LEVEL_CAPABILITY			89
+#define SMIAPP_LIMIT_MODULE_SPECIFIC_CORRECTION_CAPABILITY	90
+#define SMIAPP_LIMIT_DEFECT_CORRECTION_CAPABILITY		91
+#define SMIAPP_LIMIT_DEFECT_CORRECTION_CAPABILITY_2		92
+#define SMIAPP_LIMIT_EDOF_CAPABILITY				93
+#define SMIAPP_LIMIT_COLOUR_FEEDBACK_CAPABILITY			94
+#define SMIAPP_LIMIT_ESTIMATION_MODE_CAPABILITY			95
+#define SMIAPP_LIMIT_ESTIMATION_ZONE_CAPABILITY			96
+#define SMIAPP_LIMIT_CAPABILITY_TRDY_MIN			97
+#define SMIAPP_LIMIT_FLASH_MODE_CAPABILITY			98
+#define SMIAPP_LIMIT_ACTUATOR_CAPABILITY			99
+#define SMIAPP_LIMIT_BRACKETING_LUT_CAPABILITY_1		100
+#define SMIAPP_LIMIT_BRACKETING_LUT_CAPABILITY_2		101
+#define SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_STEP			102
+#define SMIAPP_LIMIT_LAST					103
diff --git a/drivers/media/video/smiapp/smiapp-pll.c b/drivers/media/video/smiapp/smiapp-pll.c
new file mode 100644
index 0000000..5014730
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-pll.c
@@ -0,0 +1,582 @@
+/*
+ * drivers/media/video/smiapp-pll.c
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "smiapp-debug.h"
+
+#include "smiapp.h"
+
+#include <linux/gcd.h>
+#include <linux/lcm.h>
+
+struct smiapp_pll_limits {
+	uint32_t min_ext_clk_freq_hz;
+	uint32_t max_ext_clk_freq_hz;
+	uint16_t min_pre_pll_clk_div;
+	uint16_t max_pre_pll_clk_div;
+	uint32_t min_pll_ip_freq_hz;
+	uint32_t max_pll_ip_freq_hz;
+	uint16_t min_pll_multiplier;
+	uint16_t max_pll_multiplier;
+	uint32_t min_pll_op_freq_hz;
+	uint32_t max_pll_op_freq_hz;
+
+	uint16_t min_vt_sys_clk_div;
+	uint16_t max_vt_sys_clk_div;
+	uint16_t min_vt_pix_clk_div;
+	uint16_t max_vt_pix_clk_div;
+
+	uint16_t min_op_sys_clk_div;
+	uint16_t max_op_sys_clk_div;
+	uint32_t min_op_sys_clk_freq_hz;
+	uint32_t max_op_sys_clk_freq_hz;
+	uint16_t min_op_pix_clk_div;
+	uint16_t max_op_pix_clk_div;
+	uint32_t min_op_pix_clk_freq_hz;
+	uint32_t max_op_pix_clk_freq_hz;
+};
+
+/* Return an even number or one. */
+static inline uint32_t clk_div_even(uint32_t a)
+{
+	return max_t(uint32_t, 1, a & ~1);
+}
+
+/* Return an even number or one. */
+static inline uint32_t clk_div_even_up(uint32_t a)
+{
+	if (a == 1)
+		return 1;
+	return (a + 1) & ~1;
+}
+
+static inline int is_one_or_even(uint32_t a)
+{
+	if (a == 1)
+		return 1;
+	if (a & 1)
+		return 0;
+
+	return 1;
+}
+
+static int bounds_check(struct device *dev, uint32_t val,
+			uint32_t min, uint32_t max, char *str)
+{
+	if (val >= min && val <= max)
+		return 0;
+
+	dev_warn(dev, "%s out of bounds: %d (%d--%d)\n",
+		 str, val, min, max);
+
+	return -EINVAL;
+}
+
+static void print_pll(struct smiapp_sensor *sensor, struct smiapp_pll *pll)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+
+	dev_dbg(&client->dev, "pre_pll_clk_div\t%d\n",  pll->pre_pll_clk_div);
+	dev_dbg(&client->dev, "pll_multiplier \t%d\n",  pll->pll_multiplier);
+	if (sensor->minfo.smiapp_profile != SMIAPP_PROFILE_0) {
+		dev_dbg(&client->dev, "op_sys_clk_div \t%d\n",
+			pll->op_sys_clk_div);
+		dev_dbg(&client->dev, "op_pix_clk_div \t%d\n",
+			pll->op_pix_clk_div);
+	}
+	dev_dbg(&client->dev, "vt_sys_clk_div \t%d\n",  pll->vt_sys_clk_div);
+	dev_dbg(&client->dev, "vt_pix_clk_div \t%d\n",  pll->vt_pix_clk_div);
+
+	dev_dbg(&client->dev, "ext_clk_freq_hz \t%d\n",
+		pll->ext_clk_freq_hz);
+	dev_dbg(&client->dev, "pll_ip_clk_freq_hz \t%d\n",
+		pll->pll_ip_clk_freq_hz);
+	dev_dbg(&client->dev, "pll_op_clk_freq_hz \t%d\n",
+		pll->pll_op_clk_freq_hz);
+	if (sensor->minfo.smiapp_profile != SMIAPP_PROFILE_0) {
+		dev_dbg(&client->dev, "op_sys_clk_freq_hz \t%d\n",
+			pll->op_sys_clk_freq_hz);
+		dev_dbg(&client->dev, "op_pix_clk_freq_hz \t%d\n",
+			pll->op_pix_clk_freq_hz);
+	}
+	dev_dbg(&client->dev, "vt_sys_clk_freq_hz \t%d\n",
+		pll->vt_sys_clk_freq_hz);
+	dev_dbg(&client->dev, "vt_pix_clk_freq_hz \t%d\n",
+		pll->vt_pix_clk_freq_hz);
+}
+
+static void smiapp_link_freq_to_pll(struct smiapp_sensor *sensor,
+				    u64 freq, unsigned int *mul,
+				    unsigned int *div)
+{
+	int t;
+
+	t = gcd(freq,
+		sensor->platform_data->ext_clk);
+	*mul = div_u64(freq, t);
+	*div = sensor->platform_data->ext_clk / t;
+}
+
+int smiapp_pll_update(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	struct smiapp_pll_limits lim = {
+		.min_pre_pll_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_PRE_PLL_CLK_DIV],
+		.max_pre_pll_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_PRE_PLL_CLK_DIV],
+		.min_pll_ip_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ],
+		.max_pll_ip_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_PLL_IP_FREQ_HZ],
+		.min_pll_multiplier = sensor->limits[SMIAPP_LIMIT_MIN_PLL_MULTIPLIER],
+		.max_pll_multiplier = sensor->limits[SMIAPP_LIMIT_MAX_PLL_MULTIPLIER],
+		.min_pll_op_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_PLL_OP_FREQ_HZ],
+		.max_pll_op_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_PLL_OP_FREQ_HZ],
+
+		.min_op_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV],
+		.max_op_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV],
+		.min_op_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV],
+		.max_op_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV],
+		.min_op_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_FREQ_HZ],
+		.max_op_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_FREQ_HZ],
+		.min_op_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_FREQ_HZ],
+		.max_op_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_FREQ_HZ],
+	};
+	struct smiapp_pll *pll = &sensor->pll;
+	const struct smiapp_csi_data_format *format = sensor->csi_format;
+	uint32_t lanes = sensor->platform_data->lanes;
+	uint32_t ext_clk = sensor->platform_data->ext_clk;
+	uint32_t compressed = format->compressed;
+	uint32_t sys_div;
+	uint32_t best_pix_div = INT_MAX >> 1;
+	uint32_t vt_op_binning_div;
+	uint32_t lane_op_clock_ratio;
+	uint32_t mul, div;
+	uint32_t more_mul_min, more_mul_max;
+	uint32_t more_mul_factor;
+	uint32_t i;
+	uint32_t min_vt_div, max_vt_div, vt_div;
+	uint32_t min_sys_div, max_sys_div;
+	int rval;
+
+	if (sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0) {
+		/*
+		 * Fill in operational clock divisors limits from the
+		 * video timing ones. On profile 0 sensors the
+		 * requirements regarding them are essentially the
+		 * same as on VT ones.
+		 */
+		lim.min_op_sys_clk_div =
+			sensor->limits[SMIAPP_LIMIT_MIN_VT_SYS_CLK_DIV];
+		lim.max_op_sys_clk_div =
+			sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_DIV];
+		lim.min_op_pix_clk_div =
+			sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_DIV];
+		lim.max_op_pix_clk_div =
+			sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_DIV];
+		lim.min_op_sys_clk_freq_hz =
+			sensor->limits[SMIAPP_LIMIT_MIN_VT_SYS_CLK_FREQ_HZ];
+		lim.max_op_sys_clk_freq_hz =
+			sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_FREQ_HZ];
+		lim.min_op_pix_clk_freq_hz =
+			sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_FREQ_HZ];
+		lim.max_op_pix_clk_freq_hz =
+			sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_FREQ_HZ];
+	}
+
+	if (smiapp_needs_quirk(sensor,
+			       SMIAPP_QUIRK_FLAG_OP_PIX_CLOCK_PER_LANE))
+		lane_op_clock_ratio = lanes;
+	else
+		lane_op_clock_ratio = 1;
+	dev_dbg(&client->dev, "lane_op_clock_ratio: %d\n", lane_op_clock_ratio);
+
+	dev_dbg(&client->dev, "binning: %dx%d\n", sensor->binning_horizontal,
+		sensor->binning_vertical);
+
+	pll->ext_clk_freq_hz = ext_clk;
+	/* CSI transfers 2 bits per clock per lane; thus times 2 */
+	pll->pll_op_clk_freq_hz = sensor->link_freq->qmenu_int[
+		sensor->link_freq->val] * 2
+		* (sensor->platform_data->lanes / lane_op_clock_ratio);
+
+	/* Figure out limits for pre-pll divider based on extclk */
+	dev_dbg(&client->dev, "min / max pre_pll_clk_div: %d / %d\n",
+		lim.min_pre_pll_clk_div, lim.max_pre_pll_clk_div);
+	lim.max_pre_pll_clk_div =
+		min_t(uint16_t, lim.max_pre_pll_clk_div,
+		      clk_div_even(pll->ext_clk_freq_hz /
+				   lim.min_pll_ip_freq_hz));
+	lim.min_pre_pll_clk_div =
+		max_t(uint16_t, lim.min_pre_pll_clk_div,
+		      clk_div_even(pll->ext_clk_freq_hz /
+				   lim.max_pll_ip_freq_hz));
+	dev_dbg(&client->dev,
+		"pre-pll check: min / max pre_pll_clk_div: %d / %d\n",
+		lim.min_pre_pll_clk_div, lim.max_pre_pll_clk_div);
+
+	smiapp_link_freq_to_pll(sensor, pll->pll_op_clk_freq_hz, &mul, &div);
+	dev_dbg(&client->dev, "mul %d / div %d\n", mul, div);
+
+	lim.min_pre_pll_clk_div =
+		max_t(uint16_t, lim.min_pre_pll_clk_div,
+		      clk_div_even_up(
+			      DIV_ROUND_UP(mul * pll->ext_clk_freq_hz,
+					   lim.max_pll_op_freq_hz)));
+	dev_dbg(&client->dev,
+		"pll_op check: min / max pre_pll_clk_div: %d / %d\n",
+		lim.min_pre_pll_clk_div, lim.max_pre_pll_clk_div);
+
+	if (lim.min_pre_pll_clk_div > lim.max_pre_pll_clk_div) {
+		dev_err(&client->dev, "unable to compute pre_pll divisor\n");
+		return -EINVAL;
+	}
+
+	pll->pre_pll_clk_div = lim.min_pre_pll_clk_div;
+
+	/*
+	 * Get pre_pll_clk_div so that our pll_op_clk_freq_hz won't be
+	 * too high.
+	 */
+	dev_dbg(&client->dev, "pre_pll_clk_div %d\n", pll->pre_pll_clk_div);
+
+	/* Don't go above max pll multiplier. */
+	more_mul_max = lim.max_pll_multiplier / mul;
+	dev_dbg(&client->dev, "more_mul_max: max_pll_multiplier check: %d\n",
+		more_mul_max);
+	/* Don't go above max pll op frequency. */
+	more_mul_max =
+		min_t(int,
+		      more_mul_max,
+		      lim.max_pll_op_freq_hz
+		      / (pll->ext_clk_freq_hz / pll->pre_pll_clk_div * mul));
+	dev_dbg(&client->dev, "more_mul_max: max_pll_op_freq_hz check: %d\n",
+		more_mul_max);
+	/* Don't go above the division capability of op sys clock divider. */
+	more_mul_max = min(more_mul_max,
+			   lim.max_op_sys_clk_div * pll->pre_pll_clk_div
+			   / div);
+	dev_dbg(&client->dev, "more_mul_max: max_op_sys_clk_div check: %d\n",
+		more_mul_max);
+	/* Ensure we won't go above min_pll_multiplier. */
+	more_mul_max = min(more_mul_max,
+			   DIV_ROUND_UP(lim.max_pll_multiplier, mul));
+	dev_dbg(&client->dev, "more_mul_max: min_pll_multiplier check: %d\n",
+		more_mul_max);
+
+	/* Ensure we won't go below min_pll_op_freq_hz. */
+	more_mul_min = DIV_ROUND_UP(lim.min_pll_op_freq_hz,
+				    pll->ext_clk_freq_hz / pll->pre_pll_clk_div
+				    * mul);
+	dev_dbg(&client->dev, "more_mul_min: min_pll_op_freq_hz check: %d\n",
+		more_mul_min);
+	/* Ensure we won't go below min_pll_multiplier. */
+	more_mul_min = max(more_mul_min,
+			   DIV_ROUND_UP(lim.min_pll_multiplier, mul));
+	dev_dbg(&client->dev, "more_mul_min: min_pll_multiplier check: %d\n",
+		more_mul_min);
+
+	if (more_mul_min > more_mul_max) {
+		dev_warn(&client->dev,
+			 "unable to compute more_mul_min and more_mul_max");
+		return -EINVAL;
+	}
+
+	more_mul_factor = lcm(div, pll->pre_pll_clk_div) / div;
+	dev_dbg(&client->dev, "more_mul_factor: %d\n", more_mul_factor);
+	more_mul_factor = lcm(more_mul_factor, lim.min_op_sys_clk_div);
+	dev_dbg(&client->dev, "more_mul_factor: min_op_sys_clk_div: %d\n",
+		more_mul_factor);
+	i = ALIGN(more_mul_min, more_mul_factor);
+	if (!is_one_or_even(i))
+		i <<= 1;
+
+	dev_dbg(&client->dev, "final more_mul: %d\n", i);
+	if (i > more_mul_max) {
+		dev_warn(&client->dev, "final more_mul is bad, max %d",
+			 more_mul_max);
+		return -EINVAL;
+	}
+
+	pll->pll_multiplier = mul * i;
+	pll->op_sys_clk_div = div * i / pll->pre_pll_clk_div;
+	dev_dbg(&client->dev, "op_sys_clk_div: %d\n", pll->op_sys_clk_div);
+
+	pll->pll_ip_clk_freq_hz = pll->ext_clk_freq_hz
+		/ pll->pre_pll_clk_div;
+
+	pll->pll_op_clk_freq_hz = pll->pll_ip_clk_freq_hz
+		* pll->pll_multiplier;
+
+	/* Derive pll_op_clk_freq_hz. */
+	pll->op_sys_clk_freq_hz =
+		pll->pll_op_clk_freq_hz / pll->op_sys_clk_div;
+
+	pll->op_pix_clk_div = compressed;
+	dev_dbg(&client->dev, "op_pix_clk_div: %d\n", pll->op_pix_clk_div);
+
+	pll->op_pix_clk_freq_hz =
+		pll->op_sys_clk_freq_hz / pll->op_pix_clk_div;
+
+	/*
+	 * Some sensors perform analogue binning and some do this
+	 * digitally. The ones doing this digitally can be roughly be
+	 * found out using this formula. The ones doing this digitally
+	 * should run at higher clock rate, so smaller divisor is used
+	 * on video timing side.
+	 */
+	if (sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN] >
+	    sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK] /
+	    sensor->binning_horizontal)
+		vt_op_binning_div = sensor->binning_horizontal;
+	else
+		vt_op_binning_div = 1;
+	dev_dbg(&client->dev, "vt_op_binning_div: %d\n", vt_op_binning_div);
+
+	/*
+	 * Profile 2 supports vt_pix_clk_div E [4, 10]
+	 *
+	 * Horizontal binning can be used as a base for difference in
+	 * divisors. One must make sure that horizontal blanking is
+	 * enough to accommodate the CSI-2 sync codes.
+	 *
+	 * Take scaling factor into account as well.
+	 *
+	 * Find absolute limits for the factor of vt divider.
+	 */
+	dev_dbg(&client->dev, "scale_m: %d\n", sensor->scale_m);
+	min_vt_div = DIV_ROUND_UP(pll->op_pix_clk_div * pll->op_sys_clk_div
+				  * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
+				  lane_op_clock_ratio * vt_op_binning_div
+				  * sensor->scale_m);
+
+	/* Find smallest and biggest allowed vt divisor. */
+	dev_dbg(&client->dev, "min_vt_div: %d\n", min_vt_div);
+	min_vt_div = max(
+		min_vt_div,
+		DIV_ROUND_UP(
+			pll->pll_op_clk_freq_hz,
+			sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_FREQ_HZ]));
+	dev_dbg(&client->dev, "min_vt_div: max_vt_pix_clk_freq_hz: %d\n",
+		min_vt_div);
+	min_vt_div = max(
+		min_vt_div,
+		sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_DIV]
+		* sensor->limits[SMIAPP_LIMIT_MIN_VT_SYS_CLK_DIV]);
+	dev_dbg(&client->dev, "min_vt_div: min_vt_clk_div: %d\n",
+		min_vt_div);
+
+	max_vt_div = sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_DIV]
+		* sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_DIV];
+	dev_dbg(&client->dev, "max_vt_div: %d\n", max_vt_div);
+	max_vt_div = min(
+		max_vt_div,
+		DIV_ROUND_UP(
+			pll->pll_op_clk_freq_hz,
+			sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_FREQ_HZ]));
+	dev_dbg(&client->dev, "max_vt_div: min_vt_pix_clk_freq_hz: %d\n",
+		max_vt_div);
+
+	/*
+	 * Find limits for sys_clk_div. Not all values are possible
+	 * with all values of pix_clk_div.
+	 */
+	min_sys_div = sensor->limits[SMIAPP_LIMIT_MIN_VT_SYS_CLK_DIV];
+	dev_dbg(&client->dev, "min_sys_div: %d\n", min_sys_div);
+	min_sys_div = max(
+		min_sys_div,
+		DIV_ROUND_UP(
+			min_vt_div,
+			sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_DIV]));
+	dev_dbg(&client->dev, "min_sys_div: max_vt_pix_clk_div: %d\n",
+		min_sys_div);
+	min_sys_div = max(
+		min_sys_div,
+		pll->pll_op_clk_freq_hz
+		/ sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_FREQ_HZ]);
+	dev_dbg(&client->dev, "min_sys_div: max_pll_op_clk_freq_hz: %d\n",
+		min_sys_div);
+	min_sys_div = clk_div_even_up(min_sys_div);
+	dev_dbg(&client->dev, "min_sys_div: one or even: %d\n", min_sys_div);
+
+	max_sys_div = sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_DIV];
+	dev_dbg(&client->dev, "max_sys_div: %d\n", max_sys_div);
+	max_sys_div = min(
+		max_sys_div,
+		DIV_ROUND_UP(
+			max_vt_div,
+			sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_DIV]));
+	dev_dbg(&client->dev, "max_sys_div: min_vt_pix_clk_div: %d\n",
+		max_sys_div);
+	max_sys_div =
+		min(max_sys_div,
+		    DIV_ROUND_UP(
+			    pll->pll_op_clk_freq_hz,
+			    sensor->limits[
+				    SMIAPP_LIMIT_MIN_VT_PIX_CLK_FREQ_HZ]));
+	dev_dbg(&client->dev, "max_sys_div: min_vt_pix_clk_freq_hz: %d\n",
+		max_sys_div);
+
+	/*
+	 * Find pix_div such that a legal pix_div * sys_div results
+	 * into a value which is not smaller than div, the desired
+	 * divisor.
+	 */
+	for (vt_div = min_vt_div; vt_div <= max_vt_div;
+	     vt_div += 2 - (vt_div & 1)) {
+		for (sys_div = min_sys_div;
+		     sys_div <= max_sys_div;
+		     sys_div += 2 - (sys_div & 1)) {
+			int pix_div = DIV_ROUND_UP(vt_div, sys_div);
+
+			if (pix_div <
+			    sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_DIV]
+			    || pix_div
+			    > sensor->limits[
+				    SMIAPP_LIMIT_MAX_VT_PIX_CLK_DIV]) {
+				dev_dbg(&client->dev,
+					"pix_div %d too small or too big (%d--%d)\n",
+					pix_div,
+					sensor->limits[
+						SMIAPP_LIMIT_MIN_VT_PIX_CLK_DIV],
+					sensor->limits[
+						SMIAPP_LIMIT_MAX_VT_PIX_CLK_DIV]);
+				continue;
+			}
+
+			/* Check if this one is better. */
+			if (pix_div * sys_div
+			    <= ALIGN(min_vt_div, best_pix_div))
+				best_pix_div = pix_div;
+		}
+		if (best_pix_div < INT_MAX >> 1)
+			break;
+	}
+
+	pll->vt_sys_clk_div = DIV_ROUND_UP(min_vt_div, best_pix_div);
+	pll->vt_pix_clk_div = best_pix_div;
+
+	pll->vt_sys_clk_freq_hz =
+		pll->pll_op_clk_freq_hz / pll->vt_sys_clk_div;
+	pll->vt_pix_clk_freq_hz =
+		pll->vt_sys_clk_freq_hz / pll->vt_pix_clk_div;
+
+	sensor->pixel_rate_parray->cur.val64 = pll->vt_pix_clk_freq_hz;
+	sensor->pixel_rate_csi->cur.val64 =
+		pll->op_pix_clk_freq_hz * lane_op_clock_ratio;
+
+	print_pll(sensor, pll);
+
+	rval = bounds_check(&client->dev, pll->pre_pll_clk_div,
+			    lim.min_pre_pll_clk_div, lim.max_pre_pll_clk_div,
+			    "pre_pll_clk_div");
+	if (!rval)
+		rval = bounds_check(
+			&client->dev, pll->pll_ip_clk_freq_hz,
+			lim.min_pll_ip_freq_hz, lim.max_pll_ip_freq_hz,
+			"pll_ip_clk_freq_hz");
+	if (!rval)
+		rval = bounds_check(
+			&client->dev, pll->pll_multiplier,
+			lim.min_pll_multiplier, lim.max_pll_multiplier,
+			"pll_multiplier");
+	if (!rval)
+		rval = bounds_check(
+			&client->dev, pll->pll_op_clk_freq_hz,
+			lim.min_pll_op_freq_hz, lim.max_pll_op_freq_hz,
+			"pll_op_clk_freq_hz");
+	if (!rval)
+		rval = bounds_check(
+			&client->dev, pll->op_sys_clk_div,
+			lim.min_op_sys_clk_div, lim.max_op_sys_clk_div,
+			"op_sys_clk_div");
+	if (!rval)
+		rval = bounds_check(
+			&client->dev, pll->op_pix_clk_div,
+			lim.min_op_pix_clk_div, lim.max_op_pix_clk_div,
+			"op_pix_clk_div");
+	if (!rval)
+		rval = bounds_check(
+			&client->dev, pll->op_sys_clk_freq_hz,
+			lim.min_op_sys_clk_freq_hz, lim.max_op_sys_clk_freq_hz,
+			"op_sys_clk_freq_hz");
+	if (!rval)
+		rval = bounds_check(
+			&client->dev, pll->op_pix_clk_freq_hz,
+			lim.min_op_pix_clk_freq_hz, lim.max_op_pix_clk_freq_hz,
+			"op_pix_clk_freq_hz");
+	if (!rval)
+		rval = bounds_check(
+			&client->dev, pll->vt_sys_clk_freq_hz,
+			sensor->limits[SMIAPP_LIMIT_MIN_VT_SYS_CLK_FREQ_HZ],
+			sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_FREQ_HZ],
+			"vt_sys_clk_freq_hz");
+	if (!rval)
+		rval = bounds_check(
+			&client->dev, pll->vt_pix_clk_freq_hz,
+			sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_FREQ_HZ],
+			sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_FREQ_HZ],
+			"vt_pix_clk_freq_hz");
+
+	return rval;
+}
+
+int smiapp_pll_configure(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	struct smiapp_pll *pll = &sensor->pll;
+	int rval;
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_VT_PIX_CLK_DIV, pll->vt_pix_clk_div);
+	if (rval < 0)
+		return rval;
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_VT_SYS_CLK_DIV, pll->vt_sys_clk_div);
+	if (rval < 0)
+		return rval;
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_PRE_PLL_CLK_DIV, pll->pre_pll_clk_div);
+	if (rval < 0)
+		return rval;
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_PLL_MULTIPLIER, pll->pll_multiplier);
+	if (rval < 0)
+		return rval;
+
+	/* Lane op clock ratio does not apply here. */
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U32_REQUESTED_LINK_BIT_RATE_MBPS,
+		DIV_ROUND_UP(pll->op_sys_clk_freq_hz, 1000000 / 256 / 256));
+	if (rval < 0 ||
+	    sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0)
+		return rval;
+
+	rval = smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_OP_PIX_CLK_DIV, pll->op_pix_clk_div);
+	if (rval < 0)
+		return rval;
+
+	return smia_i2c_write_reg(
+		client, SMIAPP_REG_U16_OP_SYS_CLK_DIV, pll->op_sys_clk_div);
+}
diff --git a/drivers/media/video/smiapp/smiapp-quirk.c b/drivers/media/video/smiapp/smiapp-quirk.c
new file mode 100644
index 0000000..bbbbfd0
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-quirk.c
@@ -0,0 +1,264 @@
+/*
+ * drivers/media/video/smiapp-pll.c
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "smiapp-debug.h"
+
+#include <linux/delay.h>
+
+#include "smiapp.h"
+
+static int smiapp_write_reg_8(struct smiapp_sensor *sensor, u16 reg, u8 val)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+
+	return smia_i2c_write_reg(client, (SMIA_REG_8BIT << 16) | reg, val);
+}
+
+static int smiapp_write_regs_8(struct smiapp_sensor *sensor,
+			       struct smiapp_reg_8 *regs, int len)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int rval;
+
+	for (; len > 0; len--, regs++) {
+		rval = smiapp_write_reg_8(sensor, regs->reg, regs->val);
+		if (rval < 0) {
+			dev_err(&client->dev,
+				"error %d writing reg 0x%4.4x, val 0x%2.2x",
+				rval, regs->reg, regs->val);
+			return rval;
+		}
+	}
+
+	return 0;
+}
+
+void smiapp_replace_limit(struct smiapp_sensor *sensor,
+			  u32 limit, u32 val)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+
+	dev_dbg(&client->dev, "quirk: 0x%8.8x \"%s\" = %d, 0x%x\n",
+		smiapp_reg_limits[limit].addr,
+		smiapp_reg_limits[limit].what, val, val);
+	sensor->limits[limit] = val;
+}
+
+int smiapp_replace_limit_at(struct smiapp_sensor *sensor,
+			    u32 reg, u32 val)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int i;
+
+	for (i = 0; smiapp_reg_limits[i].addr; i++) {
+		if ((smiapp_reg_limits[i].addr & 0xffff) != reg)
+			continue;
+
+		smiapp_replace_limit(sensor, i, val);
+
+		return 0;
+	}
+
+	dev_dbg(&client->dev, "quirk: bad register 0x%4.4x\n", reg);
+
+	return -EINVAL;
+}
+
+static int jt8ew9_limits(struct smiapp_sensor *sensor)
+{
+	if (sensor->minfo.revision_number_major < 0x03)
+		sensor->frame_skip = 1;
+
+	/* Below 24 gain doesn't have effect at all, */
+	/* but ~59 is needed for full dynamic range */
+	smiapp_replace_limit(sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN, 59);
+	smiapp_replace_limit(
+		sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX, 6000);
+
+	return 0;
+}
+
+static int jt8ew9_post_poweron(struct smiapp_sensor *sensor)
+{
+	struct smiapp_reg_8 regs[] = {
+		{ 0x30a3, 0xd8 }, /* Output port control : LVDS ports only */
+		{ 0x30ae, 0x00 }, /* 0x0307 pll_multiplier maximum value on PLL input 9.6MHz ( 19.2MHz is divided on pre_pll_div) */
+		{ 0x30af, 0xd0 }, /* 0x0307 pll_multiplier maximum value on PLL input 9.6MHz ( 19.2MHz is divided on pre_pll_div) */
+		{ 0x322d, 0x04 }, /* Adjusting Processing Image Size to Scaler Toshiba Recommendation Setting */
+		{ 0x3255, 0x0f }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */
+		{ 0x3256, 0x15 }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */
+		{ 0x3258, 0x70 }, /* Analog Gain Control Toshiba Recommendation Setting */
+		{ 0x3259, 0x70 }, /* Analog Gain Control Toshiba Recommendation Setting */
+		{ 0x325f, 0x7c }, /* Analog Gain Control Toshiba Recommendation Setting */
+		{ 0x3302, 0x06 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
+		{ 0x3304, 0x00 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
+		{ 0x3307, 0x22 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
+		{ 0x3308, 0x8d }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
+		{ 0x331e, 0x0f }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
+		{ 0x3320, 0x30 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
+		{ 0x3321, 0x11 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
+		{ 0x3322, 0x98 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
+		{ 0x3323, 0x64 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
+		{ 0x3325, 0x83 }, /* Read Out Timing Control Toshiba Recommendation Setting */
+		{ 0x3330, 0x18 }, /* Read Out Timing Control Toshiba Recommendation Setting */
+		{ 0x333c, 0x01 }, /* Read Out Timing Control Toshiba Recommendation Setting */
+		{ 0x3345, 0x2f }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
+		{ 0x33de, 0x38 }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */
+		/* Taken from v03. No idea what the rest are. */
+		{ 0x32e0, 0x05 },
+		{ 0x32e1, 0x05 },
+		{ 0x32e2, 0x04 },
+		{ 0x32e5, 0x04 },
+		{ 0x32e6, 0x04 },
+
+	};
+
+	return smiapp_write_regs_8(sensor, regs, ARRAY_SIZE(regs));
+}
+
+const struct smiapp_quirk smiapp_jt8ew9_quirk = {
+	.limits = jt8ew9_limits,
+	.post_poweron = jt8ew9_post_poweron,
+};
+
+static int imx125es_post_poweron(struct smiapp_sensor *sensor)
+{
+	/* Taken from v02. No idea what the other two are. */
+	struct smiapp_reg_8 regs[] = {
+		/*
+		 * 0x3302: clk during frame blanking:
+		 * 0x00 - HS mode, 0x01 - LP11
+		 */
+		{ 0x3302, 0x01 },
+		{ 0x302d, 0x00 },
+		{ 0x3b08, 0x8c },
+	};
+
+	return smiapp_write_regs_8(sensor, regs, ARRAY_SIZE(regs));
+}
+
+const struct smiapp_quirk smiapp_imx125es_quirk = {
+	.post_poweron = imx125es_post_poweron,
+};
+
+static int jt8ev1_limits(struct smiapp_sensor *sensor)
+{
+	smiapp_replace_limit(sensor, SMIAPP_LIMIT_X_ADDR_MAX, 4271);
+	smiapp_replace_limit(sensor,
+			     SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN, 184);
+
+	return 0;
+}
+
+static int jt8ev1_post_poweron(struct smiapp_sensor *sensor)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int rval;
+
+	struct smiapp_reg_8 regs[] = {
+		{ 0x3031, 0xcd }, /* For digital binning (EQ_MONI) */
+		{ 0x30a3, 0xd0 }, /* FLASH STROBE enable */
+		{ 0x3237, 0x00 }, /* For control of pulse timing for ADC */
+		{ 0x3238, 0x43 },
+		{ 0x3301, 0x06 }, /* For analog bias for sensor */
+		{ 0x3302, 0x06 },
+		{ 0x3304, 0x00 },
+		{ 0x3305, 0x88 },
+		{ 0x332a, 0x14 },
+		{ 0x332c, 0x6b },
+		{ 0x3336, 0x01 },
+		{ 0x333f, 0x1f },
+		{ 0x3355, 0x00 },
+		{ 0x3356, 0x20 },
+		{ 0x33bf, 0x20 }, /* Adjust the FBC speed */
+		{ 0x33c9, 0x20 },
+		{ 0x33ce, 0x30 }, /* Adjust the parameter for logic function */
+		{ 0x33cf, 0xec }, /* For Black sun */
+		{ 0x3328, 0x80 }, /* Ugh. No idea what's this. */
+	};
+
+	struct smiapp_reg_8 regs_96[] = {
+		{ 0x30ae, 0x00 }, /* For control of ADC clock */
+		{ 0x30af, 0xd0 },
+		{ 0x30b0, 0x01 },
+	};
+
+	rval = smiapp_write_regs_8(sensor, regs, ARRAY_SIZE(regs));
+	if (rval < 0)
+		return rval;
+
+	switch (sensor->platform_data->ext_clk) {
+	case 9600000:
+		return smiapp_write_regs_8(sensor, regs_96,
+					   ARRAY_SIZE(regs_96));
+	default:
+		dev_warn(&client->dev, "no MSRs for %d Hz ext_clk\n",
+			 sensor->platform_data->ext_clk);
+		return 0;
+	}
+}
+
+static int jt8ev1_pre_streamon(struct smiapp_sensor *sensor)
+{
+	return smiapp_write_reg_8(sensor, 0x3328, 0x00);
+}
+
+static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)
+{
+	int rval;
+
+	/* Workaround: allows fast standby to work properly */
+	rval = smiapp_write_reg_8(sensor, 0x3205, 0x04);
+	if (rval < 0)
+		return rval;
+
+	/* Wait for 1 ms + one line => 2 ms is likely enough */
+	usleep_range(2000, 2000);
+
+	/* Restore it */
+	rval = smiapp_write_reg_8(sensor, 0x3205, 0x00);
+	if (rval < 0)
+		return rval;
+
+	return smiapp_write_reg_8(sensor, 0x3328, 0x80);
+}
+
+const struct smiapp_quirk smiapp_jt8ev1_quirk = {
+	.limits = jt8ev1_limits,
+	.post_poweron = jt8ev1_post_poweron,
+	.pre_streamon = jt8ev1_pre_streamon,
+	.post_streamoff = jt8ev1_post_streamoff,
+	.flags = SMIAPP_QUIRK_FLAG_OP_PIX_CLOCK_PER_LANE,
+};
+
+static int tcm8500md_limits(struct smiapp_sensor *sensor)
+{
+	smiapp_replace_limit(sensor, SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ, 2700000);
+
+	return 0;
+}
+
+const struct smiapp_quirk smiapp_tcm8500md_quirk = {
+	.limits = tcm8500md_limits,
+};
diff --git a/drivers/media/video/smiapp/smiapp-quirk.h b/drivers/media/video/smiapp/smiapp-quirk.h
new file mode 100644
index 0000000..611536b
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-quirk.h
@@ -0,0 +1,72 @@
+/*
+ * drivers/media/video/smiapp-quirk.h
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __SMIAPP_QUIRK__
+#define __SMIAPP_QUIRK__
+
+struct smiapp_sensor;
+
+/**
+ * struct smiapp_quirk - quirks for sensors that deviate from SMIA++ standard
+ *
+ * @limits: Replace sensor->limits with values which can't be read from
+ *	    sensor registers. Called the first time the sensor is powered up.
+ * @post_poweron: Called always after the sensor has been fully powered on.
+ * @pre_streamon: Called just before streaming is enabled.
+ * @post_streamon: Called right after stopping streaming.
+ */
+struct smiapp_quirk {
+	int (*limits)(struct smiapp_sensor *sensor);
+	int (*post_poweron)(struct smiapp_sensor *sensor);
+	int (*pre_streamon)(struct smiapp_sensor *sensor);
+	int (*post_streamoff)(struct smiapp_sensor *sensor);
+	unsigned long flags;
+};
+
+/* op pix clock is for all lanes in total normally */
+#define SMIAPP_QUIRK_FLAG_OP_PIX_CLOCK_PER_LANE			(1 << 0)
+
+struct smiapp_reg_8 {
+	u16 reg;
+	u8 val;
+};
+
+void smiapp_replace_limit(struct smiapp_sensor *sensor,
+			  u32 limit, u32 val);
+
+#define smiapp_call_quirk(_sensor, _quirk, ...)				\
+	(_sensor->minfo.quirk &&					\
+	 _sensor->minfo.quirk->_quirk ?					\
+	 _sensor->minfo.quirk->_quirk(_sensor, ##__VA_ARGS__) : 0)
+
+#define smiapp_needs_quirk(_sensor, _quirk)		\
+	(_sensor->minfo.quirk ?				\
+	 _sensor->minfo.quirk->flags & _quirk : 0)
+
+extern const struct smiapp_quirk smiapp_jt8ev1_quirk;
+extern const struct smiapp_quirk smiapp_imx125es_quirk;
+extern const struct smiapp_quirk smiapp_jt8ew9_quirk;
+extern const struct smiapp_quirk smiapp_tcm8500md_quirk;
+
+#endif /* __SMIAPP_QUIRK__ */
diff --git a/drivers/media/video/smiapp/smiapp-reg-defs.h b/drivers/media/video/smiapp/smiapp-reg-defs.h
new file mode 100644
index 0000000..50266d4
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-reg-defs.h
@@ -0,0 +1,503 @@
+/*
+ * drivers/media/video/smiapp-reg-defs.h
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#define SMIAPP_REG_MK_U8(r) ((SMIA_REG_8BIT << 16) | (r))
+#define SMIAPP_REG_MK_U16(r) ((SMIA_REG_16BIT << 16) | (r))
+#define SMIAPP_REG_MK_U32(r) ((SMIA_REG_32BIT << 16) | (r))
+
+#define SMIAPP_REG_MK_F32(r) (SMIA_REG_FLAG_FLOAT | (SMIA_REG_32BIT << 16) | (r))
+
+#define SMIAPP_REG_U16_MODEL_ID					SMIAPP_REG_MK_U16(0x0000)
+#define SMIAPP_REG_U8_REVISION_NUMBER_MAJOR			SMIAPP_REG_MK_U8(0x0002)
+#define SMIAPP_REG_U8_MANUFACTURER_ID				SMIAPP_REG_MK_U8(0x0003)
+#define SMIAPP_REG_U8_SMIA_VERSION				SMIAPP_REG_MK_U8(0x0004)
+#define SMIAPP_REG_U8_FRAME_COUNT				SMIAPP_REG_MK_U8(0x0005)
+#define SMIAPP_REG_U8_PIXEL_ORDER				SMIAPP_REG_MK_U8(0x0006)
+#define SMIAPP_REG_U16_DATA_PEDESTAL				SMIAPP_REG_MK_U16(0x0008)
+#define SMIAPP_REG_U8_PIXEL_DEPTH				SMIAPP_REG_MK_U8(0x000c)
+#define SMIAPP_REG_U8_REVISION_NUMBER_MINOR			SMIAPP_REG_MK_U8(0x0010)
+#define SMIAPP_REG_U8_SMIAPP_VERSION				SMIAPP_REG_MK_U8(0x0011)
+#define SMIAPP_REG_U8_MODULE_DATE_YEAR				SMIAPP_REG_MK_U8(0x0012)
+#define SMIAPP_REG_U8_MODULE_DATE_MONTH				SMIAPP_REG_MK_U8(0x0013)
+#define SMIAPP_REG_U8_MODULE_DATE_DAY				SMIAPP_REG_MK_U8(0x0014)
+#define SMIAPP_REG_U8_MODULE_DATE_PHASE				SMIAPP_REG_MK_U8(0x0015)
+#define SMIAPP_REG_U16_SENSOR_MODEL_ID				SMIAPP_REG_MK_U16(0x0016)
+#define SMIAPP_REG_U8_SENSOR_REVISION_NUMBER			SMIAPP_REG_MK_U8(0x0018)
+#define SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID			SMIAPP_REG_MK_U8(0x0019)
+#define SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION			SMIAPP_REG_MK_U8(0x001a)
+#define SMIAPP_REG_U32_SERIAL_NUMBER				SMIAPP_REG_MK_U32(0x001c)
+#define SMIAPP_REG_U8_FRAME_FORMAT_MODEL_TYPE			SMIAPP_REG_MK_U8(0x0040)
+#define SMIAPP_REG_U8_FRAME_FORMAT_MODEL_SUBTYPE		SMIAPP_REG_MK_U8(0x0041)
+#define SMIAPP_REG_U16_FRAME_FORMAT_DESCRIPTOR_2(n)		SMIAPP_REG_MK_U16(0x0042 + ((n) << 1)) /* 0 <= n <= 14 */
+#define SMIAPP_REG_U32_FRAME_FORMAT_DESCRIPTOR_4(n)		SMIAPP_REG_MK_U32(0x0060 + ((n) << 2)) /* 0 <= n <= 7 */
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_CAPABILITY			SMIAPP_REG_MK_U16(0x0080)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_MIN			SMIAPP_REG_MK_U16(0x0084)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_MAX			SMIAPP_REG_MK_U16(0x0086)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_STEP			SMIAPP_REG_MK_U16(0x0088)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_TYPE			SMIAPP_REG_MK_U16(0x008a)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_M0				SMIAPP_REG_MK_U16(0x008c)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_C0				SMIAPP_REG_MK_U16(0x008e)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_M1				SMIAPP_REG_MK_U16(0x0090)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_C1				SMIAPP_REG_MK_U16(0x0092)
+#define SMIAPP_REG_U8_DATA_FORMAT_MODEL_TYPE			SMIAPP_REG_MK_U8(0x00c0)
+#define SMIAPP_REG_U8_DATA_FORMAT_MODEL_SUBTYPE			SMIAPP_REG_MK_U8(0x00c1)
+#define SMIAPP_REG_U16_DATA_FORMAT_DESCRIPTOR(n)		SMIAPP_REG_MK_U16(0x00c2 + ((n) << 1))
+#define SMIAPP_REG_U8_MODE_SELECT				SMIAPP_REG_MK_U8(0x0100)
+#define SMIAPP_REG_U8_IMAGE_ORIENTATION				SMIAPP_REG_MK_U8(0x0101)
+#define SMIAPP_REG_U8_SOFTWARE_RESET				SMIAPP_REG_MK_U8(0x0103)
+#define SMIAPP_REG_U8_GROUPED_PARAMETER_HOLD			SMIAPP_REG_MK_U8(0x0104)
+#define SMIAPP_REG_U8_MASK_CORRUPTED_FRAMES			SMIAPP_REG_MK_U8(0x0105)
+#define SMIAPP_REG_U8_FAST_STANDBY_CTRL				SMIAPP_REG_MK_U8(0x0106)
+#define SMIAPP_REG_U8_CCI_ADDRESS_CONTROL			SMIAPP_REG_MK_U8(0x0107)
+#define SMIAPP_REG_U8_2ND_CCI_IF_CONTROL			SMIAPP_REG_MK_U8(0x0108)
+#define SMIAPP_REG_U8_2ND_CCI_ADDRESS_CONTROL			SMIAPP_REG_MK_U8(0x0109)
+#define SMIAPP_REG_U8_CSI_CHANNEL_IDENTIFIER			SMIAPP_REG_MK_U8(0x0110)
+#define SMIAPP_REG_U8_CSI_SIGNALLING_MODE			SMIAPP_REG_MK_U8(0x0111)
+#define SMIAPP_REG_U16_CSI_DATA_FORMAT				SMIAPP_REG_MK_U16(0x0112)
+#define SMIAPP_REG_U8_CSI_LANE_MODE				SMIAPP_REG_MK_U8(0x0114)
+#define SMIAPP_REG_U8_CSI2_10_TO_8_DT				SMIAPP_REG_MK_U8(0x0115)
+#define SMIAPP_REG_U8_CSI2_10_TO_7_DT				SMIAPP_REG_MK_U8(0x0116)
+#define SMIAPP_REG_U8_CSI2_10_TO_6_DT				SMIAPP_REG_MK_U8(0x0117)
+#define SMIAPP_REG_U8_CSI2_12_TO_8_DT				SMIAPP_REG_MK_U8(0x0118)
+#define SMIAPP_REG_U8_CSI2_12_TO_7_DT				SMIAPP_REG_MK_U8(0x0119)
+#define SMIAPP_REG_U8_CSI2_12_TO_6_DT				SMIAPP_REG_MK_U8(0x011a)
+#define SMIAPP_REG_U8_CSI2_14_TO_10_DT				SMIAPP_REG_MK_U8(0x011b)
+#define SMIAPP_REG_U8_CSI2_14_TO_8_DT				SMIAPP_REG_MK_U8(0x011c)
+#define SMIAPP_REG_U8_CSI2_16_TO_10_DT				SMIAPP_REG_MK_U8(0x011d)
+#define SMIAPP_REG_U8_CSI2_16_TO_8_DT				SMIAPP_REG_MK_U8(0x011e)
+#define SMIAPP_REG_U8_GAIN_MODE					SMIAPP_REG_MK_U8(0x0120)
+#define SMIAPP_REG_U16_VANA_VOLTAGE				SMIAPP_REG_MK_U16(0x0130)
+#define SMIAPP_REG_U16_VDIG_VOLTAGE				SMIAPP_REG_MK_U16(0x0132)
+#define SMIAPP_REG_U16_VIO_VOLTAGE				SMIAPP_REG_MK_U16(0x0134)
+#define SMIAPP_REG_U16_EXTCLK_FREQUENCY_MHZ			SMIAPP_REG_MK_U16(0x0136)
+#define SMIAPP_REG_U8_TEMP_SENSOR_CONTROL			SMIAPP_REG_MK_U8(0x0138)
+#define SMIAPP_REG_U8_TEMP_SENSOR_MODE				SMIAPP_REG_MK_U8(0x0139)
+#define SMIAPP_REG_U8_TEMP_SENSOR_OUTPUT			SMIAPP_REG_MK_U8(0x013a)
+#define SMIAPP_REG_U16_FINE_INTEGRATION_TIME			SMIAPP_REG_MK_U16(0x0200)
+#define SMIAPP_REG_U16_COARSE_INTEGRATION_TIME			SMIAPP_REG_MK_U16(0x0202)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GLOBAL		SMIAPP_REG_MK_U16(0x0204)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GREENR		SMIAPP_REG_MK_U16(0x0206)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_RED			SMIAPP_REG_MK_U16(0x0208)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_BLUE			SMIAPP_REG_MK_U16(0x020a)
+#define SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GREENB		SMIAPP_REG_MK_U16(0x020c)
+#define SMIAPP_REG_U16_DIGITAL_GAIN_GREENR			SMIAPP_REG_MK_U16(0x020e)
+#define SMIAPP_REG_U16_DIGITAL_GAIN_RED				SMIAPP_REG_MK_U16(0x0210)
+#define SMIAPP_REG_U16_DIGITAL_GAIN_BLUE			SMIAPP_REG_MK_U16(0x0212)
+#define SMIAPP_REG_U16_DIGITAL_GAIN_GREENB			SMIAPP_REG_MK_U16(0x0214)
+#define SMIAPP_REG_U16_VT_PIX_CLK_DIV				SMIAPP_REG_MK_U16(0x0300)
+#define SMIAPP_REG_U16_VT_SYS_CLK_DIV				SMIAPP_REG_MK_U16(0x0302)
+#define SMIAPP_REG_U16_PRE_PLL_CLK_DIV				SMIAPP_REG_MK_U16(0x0304)
+#define SMIAPP_REG_U16_PLL_MULTIPLIER				SMIAPP_REG_MK_U16(0x0306)
+#define SMIAPP_REG_U16_OP_PIX_CLK_DIV				SMIAPP_REG_MK_U16(0x0308)
+#define SMIAPP_REG_U16_OP_SYS_CLK_DIV				SMIAPP_REG_MK_U16(0x030a)
+#define SMIAPP_REG_U16_FRAME_LENGTH_LINES			SMIAPP_REG_MK_U16(0x0340)
+#define SMIAPP_REG_U16_LINE_LENGTH_PCK				SMIAPP_REG_MK_U16(0x0342)
+#define SMIAPP_REG_U16_X_ADDR_START				SMIAPP_REG_MK_U16(0x0344)
+#define SMIAPP_REG_U16_Y_ADDR_START				SMIAPP_REG_MK_U16(0x0346)
+#define SMIAPP_REG_U16_X_ADDR_END				SMIAPP_REG_MK_U16(0x0348)
+#define SMIAPP_REG_U16_Y_ADDR_END				SMIAPP_REG_MK_U16(0x034a)
+#define SMIAPP_REG_U16_X_OUTPUT_SIZE				SMIAPP_REG_MK_U16(0x034c)
+#define SMIAPP_REG_U16_Y_OUTPUT_SIZE				SMIAPP_REG_MK_U16(0x034e)
+#define SMIAPP_REG_U16_X_EVEN_INC				SMIAPP_REG_MK_U16(0x0380)
+#define SMIAPP_REG_U16_X_ODD_INC				SMIAPP_REG_MK_U16(0x0382)
+#define SMIAPP_REG_U16_Y_EVEN_INC				SMIAPP_REG_MK_U16(0x0384)
+#define SMIAPP_REG_U16_Y_ODD_INC				SMIAPP_REG_MK_U16(0x0386)
+#define SMIAPP_REG_U16_SCALING_MODE				SMIAPP_REG_MK_U16(0x0400)
+#define SMIAPP_REG_U16_SPATIAL_SAMPLING				SMIAPP_REG_MK_U16(0x0402)
+#define SMIAPP_REG_U16_SCALE_M					SMIAPP_REG_MK_U16(0x0404)
+#define SMIAPP_REG_U16_SCALE_N					SMIAPP_REG_MK_U16(0x0406)
+#define SMIAPP_REG_U16_DIGITAL_CROP_X_OFFSET			SMIAPP_REG_MK_U16(0x0408)
+#define SMIAPP_REG_U16_DIGITAL_CROP_Y_OFFSET			SMIAPP_REG_MK_U16(0x040a)
+#define SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_WIDTH			SMIAPP_REG_MK_U16(0x040c)
+#define SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_HEIGHT		SMIAPP_REG_MK_U16(0x040e)
+#define SMIAPP_REG_U16_COMPRESSION_MODE				SMIAPP_REG_MK_U16(0x0500)
+#define SMIAPP_REG_U16_TEST_PATTERN_MODE			SMIAPP_REG_MK_U16(0x0600)
+#define SMIAPP_REG_U16_TEST_DATA_RED				SMIAPP_REG_MK_U16(0x0602)
+#define SMIAPP_REG_U16_TEST_DATA_GREENR				SMIAPP_REG_MK_U16(0x0604)
+#define SMIAPP_REG_U16_TEST_DATA_BLUE				SMIAPP_REG_MK_U16(0x0606)
+#define SMIAPP_REG_U16_TEST_DATA_GREENB				SMIAPP_REG_MK_U16(0x0608)
+#define SMIAPP_REG_U16_HORIZONTAL_CURSOR_WIDTH			SMIAPP_REG_MK_U16(0x060a)
+#define SMIAPP_REG_U16_HORIZONTAL_CURSOR_POSITION		SMIAPP_REG_MK_U16(0x060c)
+#define SMIAPP_REG_U16_VERTICAL_CURSOR_WIDTH			SMIAPP_REG_MK_U16(0x060e)
+#define SMIAPP_REG_U16_VERTICAL_CURSOR_POSITION			SMIAPP_REG_MK_U16(0x0610)
+#define SMIAPP_REG_U16_FIFO_WATER_MARK_PIXELS			SMIAPP_REG_MK_U16(0x0700)
+#define SMIAPP_REG_U8_TCLK_POST					SMIAPP_REG_MK_U8(0x0800)
+#define SMIAPP_REG_U8_THS_PREPARE				SMIAPP_REG_MK_U8(0x0801)
+#define SMIAPP_REG_U8_THS_ZERO_MIN				SMIAPP_REG_MK_U8(0x0802)
+#define SMIAPP_REG_U8_THS_TRAIL					SMIAPP_REG_MK_U8(0x0803)
+#define SMIAPP_REG_U8_TCLK_TRAIL_MIN				SMIAPP_REG_MK_U8(0x0804)
+#define SMIAPP_REG_U8_TCLK_PREPARE				SMIAPP_REG_MK_U8(0x0805)
+#define SMIAPP_REG_U8_TCLK_ZERO					SMIAPP_REG_MK_U8(0x0806)
+#define SMIAPP_REG_U8_TLPX					SMIAPP_REG_MK_U8(0x0807)
+#define SMIAPP_REG_U8_DPHY_CTRL					SMIAPP_REG_MK_U8(0x0808)
+#define SMIAPP_REG_U32_REQUESTED_LINK_BIT_RATE_MBPS		SMIAPP_REG_MK_U32(0x0820)
+#define SMIAPP_REG_U8_BINNING_MODE				SMIAPP_REG_MK_U8(0x0900)
+#define SMIAPP_REG_U8_BINNING_TYPE				SMIAPP_REG_MK_U8(0x0901)
+#define SMIAPP_REG_U8_BINNING_WEIGHTING				SMIAPP_REG_MK_U8(0x0902)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL			SMIAPP_REG_MK_U8(0x0a00)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS			SMIAPP_REG_MK_U8(0x0a01)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT		SMIAPP_REG_MK_U8(0x0a02)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0			SMIAPP_REG_MK_U8(0x0a04)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_1			SMIAPP_REG_MK_U8(0x0a05)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_2			SMIAPP_REG_MK_U8(0x0a06)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_3			SMIAPP_REG_MK_U8(0x0a07)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_4			SMIAPP_REG_MK_U8(0x0a08)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_5			SMIAPP_REG_MK_U8(0x0a09)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_12		SMIAPP_REG_MK_U8(0x0a10)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_13		SMIAPP_REG_MK_U8(0x0a11)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_14		SMIAPP_REG_MK_U8(0x0a12)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_15		SMIAPP_REG_MK_U8(0x0a13)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_16		SMIAPP_REG_MK_U8(0x0a14)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_17		SMIAPP_REG_MK_U8(0x0a15)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_18		SMIAPP_REG_MK_U8(0x0a16)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_19		SMIAPP_REG_MK_U8(0x0a17)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_20		SMIAPP_REG_MK_U8(0x0a18)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_21		SMIAPP_REG_MK_U8(0x0a19)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_22		SMIAPP_REG_MK_U8(0x0a1a)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_23		SMIAPP_REG_MK_U8(0x0a1b)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_24		SMIAPP_REG_MK_U8(0x0a1c)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_25		SMIAPP_REG_MK_U8(0x0a1d)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_26		SMIAPP_REG_MK_U8(0x0a1e)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_27		SMIAPP_REG_MK_U8(0x0a1f)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_28		SMIAPP_REG_MK_U8(0x0a20)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_29		SMIAPP_REG_MK_U8(0x0a21)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_30		SMIAPP_REG_MK_U8(0x0a22)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_31		SMIAPP_REG_MK_U8(0x0a23)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_32		SMIAPP_REG_MK_U8(0x0a24)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_33		SMIAPP_REG_MK_U8(0x0a25)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_34		SMIAPP_REG_MK_U8(0x0a26)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_35		SMIAPP_REG_MK_U8(0x0a27)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_36		SMIAPP_REG_MK_U8(0x0a28)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_37		SMIAPP_REG_MK_U8(0x0a29)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_38		SMIAPP_REG_MK_U8(0x0a2a)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_39		SMIAPP_REG_MK_U8(0x0a2b)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_40		SMIAPP_REG_MK_U8(0x0a2c)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_41		SMIAPP_REG_MK_U8(0x0a2d)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_42		SMIAPP_REG_MK_U8(0x0a2e)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_43		SMIAPP_REG_MK_U8(0x0a2f)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_44		SMIAPP_REG_MK_U8(0x0a30)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_45		SMIAPP_REG_MK_U8(0x0a31)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_46		SMIAPP_REG_MK_U8(0x0a32)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_47		SMIAPP_REG_MK_U8(0x0a33)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_48		SMIAPP_REG_MK_U8(0x0a34)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_49		SMIAPP_REG_MK_U8(0x0a35)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_50		SMIAPP_REG_MK_U8(0x0a36)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_51		SMIAPP_REG_MK_U8(0x0a37)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_52		SMIAPP_REG_MK_U8(0x0a38)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_53		SMIAPP_REG_MK_U8(0x0a39)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_54		SMIAPP_REG_MK_U8(0x0a3a)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_55		SMIAPP_REG_MK_U8(0x0a3b)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_56		SMIAPP_REG_MK_U8(0x0a3c)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_57		SMIAPP_REG_MK_U8(0x0a3d)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_58		SMIAPP_REG_MK_U8(0x0a3e)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_59		SMIAPP_REG_MK_U8(0x0a3f)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_60		SMIAPP_REG_MK_U8(0x0a40)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_61		SMIAPP_REG_MK_U8(0x0a41)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_62		SMIAPP_REG_MK_U8(0x0a42)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_63		SMIAPP_REG_MK_U8(0x0a43)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_CTRL			SMIAPP_REG_MK_U8(0x0a44)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_STATUS			SMIAPP_REG_MK_U8(0x0a45)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_PAGE_SELECT		SMIAPP_REG_MK_U8(0x0a46)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_0			SMIAPP_REG_MK_U8(0x0a48)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_1			SMIAPP_REG_MK_U8(0x0a49)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_2			SMIAPP_REG_MK_U8(0x0a4a)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_3			SMIAPP_REG_MK_U8(0x0a4b)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_4			SMIAPP_REG_MK_U8(0x0a4c)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_5			SMIAPP_REG_MK_U8(0x0a4d)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_6			SMIAPP_REG_MK_U8(0x0a4e)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_7			SMIAPP_REG_MK_U8(0x0a4f)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_8			SMIAPP_REG_MK_U8(0x0a50)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_9			SMIAPP_REG_MK_U8(0x0a51)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_10		SMIAPP_REG_MK_U8(0x0a52)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_11		SMIAPP_REG_MK_U8(0x0a53)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_12		SMIAPP_REG_MK_U8(0x0a54)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_13		SMIAPP_REG_MK_U8(0x0a55)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_14		SMIAPP_REG_MK_U8(0x0a56)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_15		SMIAPP_REG_MK_U8(0x0a57)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_16		SMIAPP_REG_MK_U8(0x0a58)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_17		SMIAPP_REG_MK_U8(0x0a59)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_18		SMIAPP_REG_MK_U8(0x0a5a)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_19		SMIAPP_REG_MK_U8(0x0a5b)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_20		SMIAPP_REG_MK_U8(0x0a5c)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_21		SMIAPP_REG_MK_U8(0x0a5d)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_22		SMIAPP_REG_MK_U8(0x0a5e)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_23		SMIAPP_REG_MK_U8(0x0a5f)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_24		SMIAPP_REG_MK_U8(0x0a60)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_25		SMIAPP_REG_MK_U8(0x0a61)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_26		SMIAPP_REG_MK_U8(0x0a62)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_27		SMIAPP_REG_MK_U8(0x0a63)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_28		SMIAPP_REG_MK_U8(0x0a64)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_29		SMIAPP_REG_MK_U8(0x0a65)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_30		SMIAPP_REG_MK_U8(0x0a66)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_31		SMIAPP_REG_MK_U8(0x0a67)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_32		SMIAPP_REG_MK_U8(0x0a68)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_33		SMIAPP_REG_MK_U8(0x0a69)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_34		SMIAPP_REG_MK_U8(0x0a6a)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_35		SMIAPP_REG_MK_U8(0x0a6b)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_36		SMIAPP_REG_MK_U8(0x0a6c)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_37		SMIAPP_REG_MK_U8(0x0a6d)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_38		SMIAPP_REG_MK_U8(0x0a6e)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_39		SMIAPP_REG_MK_U8(0x0a6f)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_40		SMIAPP_REG_MK_U8(0x0a70)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_41		SMIAPP_REG_MK_U8(0x0a71)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_42		SMIAPP_REG_MK_U8(0x0a72)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_43		SMIAPP_REG_MK_U8(0x0a73)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_44		SMIAPP_REG_MK_U8(0x0a74)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_45		SMIAPP_REG_MK_U8(0x0a75)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_46		SMIAPP_REG_MK_U8(0x0a76)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_47		SMIAPP_REG_MK_U8(0x0a77)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_48		SMIAPP_REG_MK_U8(0x0a78)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_49		SMIAPP_REG_MK_U8(0x0a79)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_50		SMIAPP_REG_MK_U8(0x0a7a)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_51		SMIAPP_REG_MK_U8(0x0a7b)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_52		SMIAPP_REG_MK_U8(0x0a7c)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_53		SMIAPP_REG_MK_U8(0x0a7d)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_54		SMIAPP_REG_MK_U8(0x0a7e)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_55		SMIAPP_REG_MK_U8(0x0a7f)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_56		SMIAPP_REG_MK_U8(0x0a80)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_57		SMIAPP_REG_MK_U8(0x0a81)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_58		SMIAPP_REG_MK_U8(0x0a82)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_59		SMIAPP_REG_MK_U8(0x0a83)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_60		SMIAPP_REG_MK_U8(0x0a84)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_61		SMIAPP_REG_MK_U8(0x0a85)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_62		SMIAPP_REG_MK_U8(0x0a86)
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_2_DATA_63		SMIAPP_REG_MK_U8(0x0a87)
+#define SMIAPP_REG_U8_SHADING_CORRECTION_ENABLE			SMIAPP_REG_MK_U8(0x0b00)
+#define SMIAPP_REG_U8_LUMINANCE_CORRECTION_LEVEL		SMIAPP_REG_MK_U8(0x0b01)
+#define SMIAPP_REG_U8_GREEN_IMBALANCE_FILTER_ENABLE		SMIAPP_REG_MK_U8(0x0b02)
+#define SMIAPP_REG_U8_GREEN_IMBALANCE_FILTER_WEIGHT		SMIAPP_REG_MK_U8(0x0b03)
+#define SMIAPP_REG_U8_BLACK_LEVEL_CORRECTION_ENABLE		SMIAPP_REG_MK_U8(0x0b04)
+#define SMIAPP_REG_U8_MAPPED_COUPLET_CORRECT_ENABLE		SMIAPP_REG_MK_U8(0x0b05)
+#define SMIAPP_REG_U8_SINGLE_DEFECT_CORRECT_ENABLE		SMIAPP_REG_MK_U8(0x0b06)
+#define SMIAPP_REG_U8_SINGLE_DEFECT_CORRECT_WEIGHT		SMIAPP_REG_MK_U8(0x0b07)
+#define SMIAPP_REG_U8_DYNAMIC_COUPLET_CORRECT_ENABLE		SMIAPP_REG_MK_U8(0x0b08)
+#define SMIAPP_REG_U8_DYNAMIC_COUPLET_CORRECT_WEIGHT		SMIAPP_REG_MK_U8(0x0b09)
+#define SMIAPP_REG_U8_COMBINED_DEFECT_CORRECT_ENABLE		SMIAPP_REG_MK_U8(0x0b0a)
+#define SMIAPP_REG_U8_COMBINED_DEFECT_CORRECT_WEIGHT		SMIAPP_REG_MK_U8(0x0b0b)
+#define SMIAPP_REG_U8_MODULE_SPECIFIC_CORRECTION_ENABLE		SMIAPP_REG_MK_U8(0x0b0c)
+#define SMIAPP_REG_U8_MODULE_SPECIFIC_CORRECTION_WEIGHT		SMIAPP_REG_MK_U8(0x0b0d)
+#define SMIAPP_REG_U8_MAPPED_LINE_DEFECT_CORRECT_ENABLE		SMIAPP_REG_MK_U8(0x0b0e)
+#define SMIAPP_REG_U8_MAPPED_LINE_DEFECT_CORRECT_ADJUST		SMIAPP_REG_MK_U8(0x0b0f)
+#define SMIAPP_REG_U8_MAPPED_COUPLET_CORRECT_ADJUST		SMIAPP_REG_MK_U8(0x0b10)
+#define SMIAPP_REG_U8_MAPPED_TRIPLET_DEFECT_CORRECT_ENABLE	SMIAPP_REG_MK_U8(0x0b11)
+#define SMIAPP_REG_U8_MAPPED_TRIPLET_DEFECT_CORRECT_ADJUST	SMIAPP_REG_MK_U8(0x0b12)
+#define SMIAPP_REG_U8_DYNAMIC_TRIPLET_DEFECT_CORRECT_ENABLE	SMIAPP_REG_MK_U8(0x0b13)
+#define SMIAPP_REG_U8_DYNAMIC_TRIPLET_DEFECT_CORRECT_ADJUST	SMIAPP_REG_MK_U8(0x0b14)
+#define SMIAPP_REG_U8_DYNAMIC_LINE_DEFECT_CORRECT_ENABLE	SMIAPP_REG_MK_U8(0x0b15)
+#define SMIAPP_REG_U8_DYNAMIC_LINE_DEFECT_CORRECT_ADJUST	SMIAPP_REG_MK_U8(0x0b16)
+#define SMIAPP_REG_U8_EDOF_MODE					SMIAPP_REG_MK_U8(0x0b80)
+#define SMIAPP_REG_U8_SHARPNESS					SMIAPP_REG_MK_U8(0x0b83)
+#define SMIAPP_REG_U8_DENOISING					SMIAPP_REG_MK_U8(0x0b84)
+#define SMIAPP_REG_U8_MODULE_SPECIFIC				SMIAPP_REG_MK_U8(0x0b85)
+#define SMIAPP_REG_U16_DEPTH_OF_FIELD				SMIAPP_REG_MK_U16(0x0b86)
+#define SMIAPP_REG_U16_FOCUS_DISTANCE				SMIAPP_REG_MK_U16(0x0b88)
+#define SMIAPP_REG_U8_ESTIMATION_MODE_CTRL			SMIAPP_REG_MK_U8(0x0b8a)
+#define SMIAPP_REG_U16_COLOUR_TEMPERATURE			SMIAPP_REG_MK_U16(0x0b8c)
+#define SMIAPP_REG_U16_ABSOLUTE_GAIN_GREENR			SMIAPP_REG_MK_U16(0x0b8e)
+#define SMIAPP_REG_U16_ABSOLUTE_GAIN_RED			SMIAPP_REG_MK_U16(0x0b90)
+#define SMIAPP_REG_U16_ABSOLUTE_GAIN_BLUE			SMIAPP_REG_MK_U16(0x0b92)
+#define SMIAPP_REG_U16_ABSOLUTE_GAIN_GREENB			SMIAPP_REG_MK_U16(0x0b94)
+#define SMIAPP_REG_U8_ESTIMATION_ZONE_MODE			SMIAPP_REG_MK_U8(0x0bc0)
+#define SMIAPP_REG_U16_FIXED_ZONE_WEIGHTING			SMIAPP_REG_MK_U16(0x0bc2)
+#define SMIAPP_REG_U16_CUSTOM_ZONE_X_START			SMIAPP_REG_MK_U16(0x0bc4)
+#define SMIAPP_REG_U16_CUSTOM_ZONE_Y_START			SMIAPP_REG_MK_U16(0x0bc6)
+#define SMIAPP_REG_U16_CUSTOM_ZONE_WIDTH			SMIAPP_REG_MK_U16(0x0bc8)
+#define SMIAPP_REG_U16_CUSTOM_ZONE_HEIGHT			SMIAPP_REG_MK_U16(0x0bca)
+#define SMIAPP_REG_U8_GLOBAL_RESET_CTRL1			SMIAPP_REG_MK_U8(0x0c00)
+#define SMIAPP_REG_U8_GLOBAL_RESET_CTRL2			SMIAPP_REG_MK_U8(0x0c01)
+#define SMIAPP_REG_U8_GLOBAL_RESET_MODE_CONFIG_1		SMIAPP_REG_MK_U8(0x0c02)
+#define SMIAPP_REG_U8_GLOBAL_RESET_MODE_CONFIG_2		SMIAPP_REG_MK_U8(0x0c03)
+#define SMIAPP_REG_U16_TRDY_CTRL				SMIAPP_REG_MK_U16(0x0c04)
+#define SMIAPP_REG_U16_TRDOUT_CTRL				SMIAPP_REG_MK_U16(0x0c06)
+#define SMIAPP_REG_U16_TSHUTTER_STROBE_DELAY_CTRL		SMIAPP_REG_MK_U16(0x0c08)
+#define SMIAPP_REG_U16_TSHUTTER_STROBE_WIDTH_CTRL		SMIAPP_REG_MK_U16(0x0c0a)
+#define SMIAPP_REG_U16_TFLASH_STROBE_DELAY_CTRL			SMIAPP_REG_MK_U16(0x0c0c)
+#define SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_CTRL		SMIAPP_REG_MK_U16(0x0c0e)
+#define SMIAPP_REG_U16_TGRST_INTERVAL_CTRL			SMIAPP_REG_MK_U16(0x0c10)
+#define SMIAPP_REG_U8_FLASH_STROBE_ADJUSTMENT			SMIAPP_REG_MK_U8(0x0c12)
+#define SMIAPP_REG_U16_FLASH_STROBE_START_POINT			SMIAPP_REG_MK_U16(0x0c14)
+#define SMIAPP_REG_U16_TFLASH_STROBE_DELAY_RS_CTRL		SMIAPP_REG_MK_U16(0x0c16)
+#define SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_RS_CTRL		SMIAPP_REG_MK_U16(0x0c18)
+#define SMIAPP_REG_U8_FLASH_MODE_RS				SMIAPP_REG_MK_U8(0x0c1a)
+#define SMIAPP_REG_U8_FLASH_TRIGGER_RS				SMIAPP_REG_MK_U8(0x0c1b)
+#define SMIAPP_REG_U8_FLASH_STATUS				SMIAPP_REG_MK_U8(0x0c1c)
+#define SMIAPP_REG_U8_SA_STROBE_MODE				SMIAPP_REG_MK_U8(0x0c1d)
+#define SMIAPP_REG_U16_SA_STROBE_START_POINT			SMIAPP_REG_MK_U16(0x0c1e)
+#define SMIAPP_REG_U16_TSA_STROBE_DELAY_CTRL			SMIAPP_REG_MK_U16(0x0c20)
+#define SMIAPP_REG_U16_TSA_STROBE_WIDTH_CTRL			SMIAPP_REG_MK_U16(0x0c22)
+#define SMIAPP_REG_U8_SA_STROBE_TRIGGER				SMIAPP_REG_MK_U8(0x0c24)
+#define SMIAPP_REG_U8_SPECIAL_ACTUATOR_STATUS			SMIAPP_REG_MK_U8(0x0c25)
+#define SMIAPP_REG_U16_TFLASH_STROBE_WIDTH2_HIGH_RS_CTRL	SMIAPP_REG_MK_U16(0x0c26)
+#define SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_LOW_RS_CTRL		SMIAPP_REG_MK_U16(0x0c28)
+#define SMIAPP_REG_U8_TFLASH_STROBE_COUNT_RS_CTRL		SMIAPP_REG_MK_U8(0x0c2a)
+#define SMIAPP_REG_U8_TFLASH_STROBE_COUNT_CTRL			SMIAPP_REG_MK_U8(0x0c2b)
+#define SMIAPP_REG_U16_TFLASH_STROBE_WIDTH2_HIGH_CTRL		SMIAPP_REG_MK_U16(0x0c2c)
+#define SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_LOW_CTRL		SMIAPP_REG_MK_U16(0x0c2e)
+#define SMIAPP_REG_U8_LOW_LEVEL_CTRL				SMIAPP_REG_MK_U8(0x0c80)
+#define SMIAPP_REG_U16_MAIN_TRIGGER_REF_POINT			SMIAPP_REG_MK_U16(0x0c82)
+#define SMIAPP_REG_U16_MAIN_TRIGGER_T3				SMIAPP_REG_MK_U16(0x0c84)
+#define SMIAPP_REG_U8_MAIN_TRIGGER_COUNT			SMIAPP_REG_MK_U8(0x0c86)
+#define SMIAPP_REG_U16_PHASE1_TRIGGER_T3			SMIAPP_REG_MK_U16(0x0c88)
+#define SMIAPP_REG_U8_PHASE1_TRIGGER_COUNT			SMIAPP_REG_MK_U8(0x0c8a)
+#define SMIAPP_REG_U16_PHASE2_TRIGGER_T3			SMIAPP_REG_MK_U16(0x0c8c)
+#define SMIAPP_REG_U8_PHASE2_TRIGGER_COUNT			SMIAPP_REG_MK_U8(0x0c8e)
+#define SMIAPP_REG_U8_MECH_SHUTTER_CTRL				SMIAPP_REG_MK_U8(0x0d00)
+#define SMIAPP_REG_U8_OPERATION_MODE				SMIAPP_REG_MK_U8(0x0d01)
+#define SMIAPP_REG_U8_ACT_STATE1				SMIAPP_REG_MK_U8(0x0d02)
+#define SMIAPP_REG_U8_ACT_STATE2				SMIAPP_REG_MK_U8(0x0d03)
+#define SMIAPP_REG_U16_FOCUS_CHANGE				SMIAPP_REG_MK_U16(0x0d80)
+#define SMIAPP_REG_U16_FOCUS_CHANGE_CONTROL			SMIAPP_REG_MK_U16(0x0d82)
+#define SMIAPP_REG_U16_FOCUS_CHANGE_NUMBER_PHASE1		SMIAPP_REG_MK_U16(0x0d84)
+#define SMIAPP_REG_U16_FOCUS_CHANGE_NUMBER_PHASE2		SMIAPP_REG_MK_U16(0x0d86)
+#define SMIAPP_REG_U8_STROBE_COUNT_PHASE1			SMIAPP_REG_MK_U8(0x0d88)
+#define SMIAPP_REG_U8_STROBE_COUNT_PHASE2			SMIAPP_REG_MK_U8(0x0d89)
+#define SMIAPP_REG_U8_POSITION					SMIAPP_REG_MK_U8(0x0d8a)
+#define SMIAPP_REG_U8_BRACKETING_LUT_CONTROL			SMIAPP_REG_MK_U8(0x0e00)
+#define SMIAPP_REG_U8_BRACKETING_LUT_MODE			SMIAPP_REG_MK_U8(0x0e01)
+#define SMIAPP_REG_U8_BRACKETING_LUT_ENTRY_CONTROL		SMIAPP_REG_MK_U8(0x0e02)
+#define SMIAPP_REG_U8_LUT_PARAMETERS_START			SMIAPP_REG_MK_U8(0x0e10)
+#define SMIAPP_REG_U8_LUT_PARAMETERS_END			SMIAPP_REG_MK_U8(0x0eff)
+#define SMIAPP_REG_U16_INTEGRATION_TIME_CAPABILITY		SMIAPP_REG_MK_U16(0x1000)
+#define SMIAPP_REG_U16_COARSE_INTEGRATION_TIME_MIN		SMIAPP_REG_MK_U16(0x1004)
+#define SMIAPP_REG_U16_COARSE_INTEGRATION_TIME_MAX_MARGIN	SMIAPP_REG_MK_U16(0x1006)
+#define SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MIN		SMIAPP_REG_MK_U16(0x1008)
+#define SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MAX_MARGIN		SMIAPP_REG_MK_U16(0x100a)
+#define SMIAPP_REG_U16_DIGITAL_GAIN_CAPABILITY			SMIAPP_REG_MK_U16(0x1080)
+#define SMIAPP_REG_U16_DIGITAL_GAIN_MIN				SMIAPP_REG_MK_U16(0x1084)
+#define SMIAPP_REG_U16_DIGITAL_GAIN_MAX				SMIAPP_REG_MK_U16(0x1086)
+#define SMIAPP_REG_U16_DIGITAL_GAIN_STEP_SIZE			SMIAPP_REG_MK_U16(0x1088)
+#define SMIAPP_REG_F32_MIN_EXT_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x1100)
+#define SMIAPP_REG_F32_MAX_EXT_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x1104)
+#define SMIAPP_REG_U16_MIN_PRE_PLL_CLK_DIV			SMIAPP_REG_MK_U16(0x1108)
+#define SMIAPP_REG_U16_MAX_PRE_PLL_CLK_DIV			SMIAPP_REG_MK_U16(0x110a)
+#define SMIAPP_REG_F32_MIN_PLL_IP_FREQ_HZ			SMIAPP_REG_MK_F32(0x110c)
+#define SMIAPP_REG_F32_MAX_PLL_IP_FREQ_HZ			SMIAPP_REG_MK_F32(0x1110)
+#define SMIAPP_REG_U16_MIN_PLL_MULTIPLIER			SMIAPP_REG_MK_U16(0x1114)
+#define SMIAPP_REG_U16_MAX_PLL_MULTIPLIER			SMIAPP_REG_MK_U16(0x1116)
+#define SMIAPP_REG_F32_MIN_PLL_OP_FREQ_HZ			SMIAPP_REG_MK_F32(0x1118)
+#define SMIAPP_REG_F32_MAX_PLL_OP_FREQ_HZ			SMIAPP_REG_MK_F32(0x111c)
+#define SMIAPP_REG_U16_MIN_VT_SYS_CLK_DIV			SMIAPP_REG_MK_U16(0x1120)
+#define SMIAPP_REG_U16_MAX_VT_SYS_CLK_DIV			SMIAPP_REG_MK_U16(0x1122)
+#define SMIAPP_REG_F32_MIN_VT_SYS_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x1124)
+#define SMIAPP_REG_F32_MAX_VT_SYS_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x1128)
+#define SMIAPP_REG_F32_MIN_VT_PIX_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x112c)
+#define SMIAPP_REG_F32_MAX_VT_PIX_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x1130)
+#define SMIAPP_REG_U16_MIN_VT_PIX_CLK_DIV			SMIAPP_REG_MK_U16(0x1134)
+#define SMIAPP_REG_U16_MAX_VT_PIX_CLK_DIV			SMIAPP_REG_MK_U16(0x1136)
+#define SMIAPP_REG_U16_MIN_FRAME_LENGTH_LINES			SMIAPP_REG_MK_U16(0x1140)
+#define SMIAPP_REG_U16_MAX_FRAME_LENGTH_LINES			SMIAPP_REG_MK_U16(0x1142)
+#define SMIAPP_REG_U16_MIN_LINE_LENGTH_PCK			SMIAPP_REG_MK_U16(0x1144)
+#define SMIAPP_REG_U16_MAX_LINE_LENGTH_PCK			SMIAPP_REG_MK_U16(0x1146)
+#define SMIAPP_REG_U16_MIN_LINE_BLANKING_PCK			SMIAPP_REG_MK_U16(0x1148)
+#define SMIAPP_REG_U16_MIN_FRAME_BLANKING_LINES			SMIAPP_REG_MK_U16(0x114a)
+#define SMIAPP_REG_U8_MIN_LINE_LENGTH_PCK_STEP_SIZE		SMIAPP_REG_MK_U8(0x114c)
+#define SMIAPP_REG_U16_MIN_OP_SYS_CLK_DIV			SMIAPP_REG_MK_U16(0x1160)
+#define SMIAPP_REG_U16_MAX_OP_SYS_CLK_DIV			SMIAPP_REG_MK_U16(0x1162)
+#define SMIAPP_REG_F32_MIN_OP_SYS_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x1164)
+#define SMIAPP_REG_F32_MAX_OP_SYS_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x1168)
+#define SMIAPP_REG_U16_MIN_OP_PIX_CLK_DIV			SMIAPP_REG_MK_U16(0x116c)
+#define SMIAPP_REG_U16_MAX_OP_PIX_CLK_DIV			SMIAPP_REG_MK_U16(0x116e)
+#define SMIAPP_REG_F32_MIN_OP_PIX_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x1170)
+#define SMIAPP_REG_F32_MAX_OP_PIX_CLK_FREQ_HZ			SMIAPP_REG_MK_F32(0x1174)
+#define SMIAPP_REG_U16_X_ADDR_MIN				SMIAPP_REG_MK_U16(0x1180)
+#define SMIAPP_REG_U16_Y_ADDR_MIN				SMIAPP_REG_MK_U16(0x1182)
+#define SMIAPP_REG_U16_X_ADDR_MAX				SMIAPP_REG_MK_U16(0x1184)
+#define SMIAPP_REG_U16_Y_ADDR_MAX				SMIAPP_REG_MK_U16(0x1186)
+#define SMIAPP_REG_U16_MIN_X_OUTPUT_SIZE			SMIAPP_REG_MK_U16(0x1188)
+#define SMIAPP_REG_U16_MIN_Y_OUTPUT_SIZE			SMIAPP_REG_MK_U16(0x118a)
+#define SMIAPP_REG_U16_MAX_X_OUTPUT_SIZE			SMIAPP_REG_MK_U16(0x118c)
+#define SMIAPP_REG_U16_MAX_Y_OUTPUT_SIZE			SMIAPP_REG_MK_U16(0x118e)
+#define SMIAPP_REG_U16_MIN_EVEN_INC				SMIAPP_REG_MK_U16(0x11c0)
+#define SMIAPP_REG_U16_MAX_EVEN_INC				SMIAPP_REG_MK_U16(0x11c2)
+#define SMIAPP_REG_U16_MIN_ODD_INC				SMIAPP_REG_MK_U16(0x11c4)
+#define SMIAPP_REG_U16_MAX_ODD_INC				SMIAPP_REG_MK_U16(0x11c6)
+#define SMIAPP_REG_U16_SCALING_CAPABILITY			SMIAPP_REG_MK_U16(0x1200)
+#define SMIAPP_REG_U16_SCALER_M_MIN				SMIAPP_REG_MK_U16(0x1204)
+#define SMIAPP_REG_U16_SCALER_M_MAX				SMIAPP_REG_MK_U16(0x1206)
+#define SMIAPP_REG_U16_SCALER_N_MIN				SMIAPP_REG_MK_U16(0x1208)
+#define SMIAPP_REG_U16_SCALER_N_MAX				SMIAPP_REG_MK_U16(0x120a)
+#define SMIAPP_REG_U16_SPATIAL_SAMPLING_CAPABILITY		SMIAPP_REG_MK_U16(0x120c)
+#define SMIAPP_REG_U8_DIGITAL_CROP_CAPABILITY			SMIAPP_REG_MK_U8(0x120e)
+#define SMIAPP_REG_U16_COMPRESSION_CAPABILITY			SMIAPP_REG_MK_U16(0x1300)
+#define SMIAPP_REG_U16_MATRIX_ELEMENT_REDINRED			SMIAPP_REG_MK_U16(0x1400)
+#define SMIAPP_REG_U16_MATRIX_ELEMENT_GREENINRED		SMIAPP_REG_MK_U16(0x1402)
+#define SMIAPP_REG_U16_MATRIX_ELEMENT_BLUEINRED			SMIAPP_REG_MK_U16(0x1404)
+#define SMIAPP_REG_U16_MATRIX_ELEMENT_REDINGREEN		SMIAPP_REG_MK_U16(0x1406)
+#define SMIAPP_REG_U16_MATRIX_ELEMENT_GREENINGREEN		SMIAPP_REG_MK_U16(0x1408)
+#define SMIAPP_REG_U16_MATRIX_ELEMENT_BLUEINGREEN		SMIAPP_REG_MK_U16(0x140a)
+#define SMIAPP_REG_U16_MATRIX_ELEMENT_REDINBLUE			SMIAPP_REG_MK_U16(0x140c)
+#define SMIAPP_REG_U16_MATRIX_ELEMENT_GREENINBLUE		SMIAPP_REG_MK_U16(0x140e)
+#define SMIAPP_REG_U16_MATRIX_ELEMENT_BLUEINBLUE		SMIAPP_REG_MK_U16(0x1410)
+#define SMIAPP_REG_U16_FIFO_SIZE_PIXELS				SMIAPP_REG_MK_U16(0x1500)
+#define SMIAPP_REG_U8_FIFO_SUPPORT_CAPABILITY			SMIAPP_REG_MK_U8(0x1502)
+#define SMIAPP_REG_U8_DPHY_CTRL_CAPABILITY			SMIAPP_REG_MK_U8(0x1600)
+#define SMIAPP_REG_U8_CSI_LANE_MODE_CAPABILITY			SMIAPP_REG_MK_U8(0x1601)
+#define SMIAPP_REG_U8_CSI_SIGNALLING_MODE_CAPABILITY		SMIAPP_REG_MK_U8(0x1602)
+#define SMIAPP_REG_U8_FAST_STANDBY_CAPABILITY			SMIAPP_REG_MK_U8(0x1603)
+#define SMIAPP_REG_U8_CCI_ADDRESS_CONTROL_CAPABILITY		SMIAPP_REG_MK_U8(0x1604)
+#define SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_1_LANE_MODE_MBPS	SMIAPP_REG_MK_U32(0x1608)
+#define SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_2_LANE_MODE_MBPS	SMIAPP_REG_MK_U32(0x160c)
+#define SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_3_LANE_MODE_MBPS	SMIAPP_REG_MK_U32(0x1610)
+#define SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_4_LANE_MODE_MBPS	SMIAPP_REG_MK_U32(0x1614)
+#define SMIAPP_REG_U8_TEMP_SENSOR_CAPABILITY			SMIAPP_REG_MK_U8(0x1618)
+#define SMIAPP_REG_U16_MIN_FRAME_LENGTH_LINES_BIN		SMIAPP_REG_MK_U16(0x1700)
+#define SMIAPP_REG_U16_MAX_FRAME_LENGTH_LINES_BIN		SMIAPP_REG_MK_U16(0x1702)
+#define SMIAPP_REG_U16_MIN_LINE_LENGTH_PCK_BIN			SMIAPP_REG_MK_U16(0x1704)
+#define SMIAPP_REG_U16_MAX_LINE_LENGTH_PCK_BIN			SMIAPP_REG_MK_U16(0x1706)
+#define SMIAPP_REG_U16_MIN_LINE_BLANKING_PCK_BIN		SMIAPP_REG_MK_U16(0x1708)
+#define SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MIN_BIN		SMIAPP_REG_MK_U16(0x170a)
+#define SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN	SMIAPP_REG_MK_U16(0x170c)
+#define SMIAPP_REG_U8_BINNING_CAPABILITY			SMIAPP_REG_MK_U8(0x1710)
+#define SMIAPP_REG_U8_BINNING_WEIGHTING_CAPABILITY		SMIAPP_REG_MK_U8(0x1711)
+#define SMIAPP_REG_U8_BINNING_SUBTYPES				SMIAPP_REG_MK_U8(0x1712)
+#define SMIAPP_REG_U8_BINNING_TYPE_n(n)				SMIAPP_REG_MK_U8(0x1713) /* 1 <= n <= 237 */
+#define SMIAPP_REG_U8_DATA_TRANSFER_IF_CAPABILITY		SMIAPP_REG_MK_U8(0x1800)
+#define SMIAPP_REG_U8_SHADING_CORRECTION_CAPABILITY		SMIAPP_REG_MK_U8(0x1900)
+#define SMIAPP_REG_U8_GREEN_IMBALANCE_CAPABILITY		SMIAPP_REG_MK_U8(0x1901)
+#define SMIAPP_REG_U8_BLACK_LEVEL_CAPABILITY			SMIAPP_REG_MK_U8(0x1902)
+#define SMIAPP_REG_U8_MODULE_SPECIFIC_CORRECTION_CAPABILITY	SMIAPP_REG_MK_U8(0x1903)
+#define SMIAPP_REG_U16_DEFECT_CORRECTION_CAPABILITY		SMIAPP_REG_MK_U16(0x1904)
+#define SMIAPP_REG_U16_DEFECT_CORRECTION_CAPABILITY_2		SMIAPP_REG_MK_U16(0x1906)
+#define SMIAPP_REG_U8_EDOF_CAPABILITY				SMIAPP_REG_MK_U8(0x1980)
+#define SMIAPP_REG_U8_ESTIMATION_FRAMES				SMIAPP_REG_MK_U8(0x1981)
+#define SMIAPP_REG_U8_SUPPORTS_SHARPNESS_ADJ			SMIAPP_REG_MK_U8(0x1982)
+#define SMIAPP_REG_U8_SUPPORTS_DENOISING_ADJ			SMIAPP_REG_MK_U8(0x1983)
+#define SMIAPP_REG_U8_SUPPORTS_MODULE_SPECIFIC_ADJ		SMIAPP_REG_MK_U8(0x1984)
+#define SMIAPP_REG_U8_SUPPORTS_DEPTH_OF_FIELD_ADJ		SMIAPP_REG_MK_U8(0x1985)
+#define SMIAPP_REG_U8_SUPPORTS_FOCUS_DISTANCE_ADJ		SMIAPP_REG_MK_U8(0x1986)
+#define SMIAPP_REG_U8_COLOUR_FEEDBACK_CAPABILITY		SMIAPP_REG_MK_U8(0x1987)
+#define SMIAPP_REG_U8_EDOF_SUPPORT_AB_NXM			SMIAPP_REG_MK_U8(0x1988)
+#define SMIAPP_REG_U8_ESTIMATION_MODE_CAPABILITY		SMIAPP_REG_MK_U8(0x19c0)
+#define SMIAPP_REG_U8_ESTIMATION_ZONE_CAPABILITY		SMIAPP_REG_MK_U8(0x19c1)
+#define SMIAPP_REG_U16_EST_DEPTH_OF_FIELD			SMIAPP_REG_MK_U16(0x19c2)
+#define SMIAPP_REG_U16_EST_FOCUS_DISTANCE			SMIAPP_REG_MK_U16(0x19c4)
+#define SMIAPP_REG_U16_CAPABILITY_TRDY_MIN			SMIAPP_REG_MK_U16(0x1a00)
+#define SMIAPP_REG_U8_FLASH_MODE_CAPABILITY			SMIAPP_REG_MK_U8(0x1a02)
+#define SMIAPP_REG_U16_MECH_SHUT_AND_ACT_START_ADDR		SMIAPP_REG_MK_U16(0x1b02)
+#define SMIAPP_REG_U8_ACTUATOR_CAPABILITY			SMIAPP_REG_MK_U8(0x1b04)
+#define SMIAPP_REG_U16_ACTUATOR_TYPE				SMIAPP_REG_MK_U16(0x1b40)
+#define SMIAPP_REG_U8_AF_DEVICE_ADDRESS				SMIAPP_REG_MK_U8(0x1b42)
+#define SMIAPP_REG_U16_FOCUS_CHANGE_ADDRESS			SMIAPP_REG_MK_U16(0x1b44)
+#define SMIAPP_REG_U8_BRACKETING_LUT_CAPABILITY_1		SMIAPP_REG_MK_U8(0x1c00)
+#define SMIAPP_REG_U8_BRACKETING_LUT_CAPABILITY_2		SMIAPP_REG_MK_U8(0x1c01)
+#define SMIAPP_REG_U8_BRACKETING_LUT_SIZE			SMIAPP_REG_MK_U8(0x1c02)
diff --git a/drivers/media/video/smiapp/smiapp-reg.h b/drivers/media/video/smiapp/smiapp-reg.h
new file mode 100644
index 0000000..126ca5b
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-reg.h
@@ -0,0 +1,122 @@
+/*
+ * drivers/media/video/smiapp-reg.h
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __SMIAPP_REG_H_
+#define __SMIAPP_REG_H_
+
+#include "smiapp-reg-defs.h"
+
+/* Bits for above register */
+#define SMIAPP_IMAGE_ORIENTATION_HFLIP		(1 << 0)
+#define SMIAPP_IMAGE_ORIENTATION_VFLIP		(1 << 1)
+
+#define SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN		(1 << 0)
+#define SMIAPP_DATA_TRANSFER_IF_1_CTRL_RD_EN		(0 << 1)
+#define SMIAPP_DATA_TRANSFER_IF_1_CTRL_WR_EN		(1 << 1)
+#define SMIAPP_DATA_TRANSFER_IF_1_CTRL_ERR_CLEAR	(1 << 2)
+#define SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY	(1 << 0)
+#define SMIAPP_DATA_TRANSFER_IF_1_STATUS_WR_READY	(1 << 1)
+#define SMIAPP_DATA_TRANSFER_IF_1_STATUS_EDATA		(1 << 2)
+#define SMIAPP_DATA_TRANSFER_IF_1_STATUS_EUSAGE		(1 << 3)
+
+#define SMIAPP_SOFTWARE_RESET				(1 << 0)
+
+#define SMIAPP_FLASH_MODE_CAPABILITY_SINGLE_STROBE	(1 << 0)
+#define SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE	(1 << 1)
+
+#define SMIAPP_DPHY_CTRL_AUTOMATIC			0
+/* DPHY control based on REQUESTED_LINK_BIT_RATE_MBPS */
+#define SMIAPP_DPHY_CTRL_UI				1
+#define SMIAPP_DPHY_CTRL_REGISTER			2
+
+#define SMIAPP_COMPRESSION_MODE_SIMPLE_PREDICTOR	1
+#define SMIAPP_COMPRESSION_MODE_ADVANCED_PREDICTOR	2
+
+#define SMIAPP_MODE_SELECT_SOFTWARE_STANDBY		0
+#define SMIAPP_MODE_SELECT_STREAMING			1
+
+#define SMIAPP_SCALING_MODE_NONE			0
+#define SMIAPP_SCALING_MODE_HORIZONTAL			1
+#define SMIAPP_SCALING_MODE_BOTH			2
+
+#define SMIAPP_SCALING_CAPABILITY_NONE			0
+#define SMIAPP_SCALING_CAPABILITY_HORIZONTAL		1
+#define SMIAPP_SCALING_CAPABILITY_BOTH			2 /* horizontal/both */
+
+/* digital crop right before scaler */
+#define SMIAPP_DIGITAL_CROP_CAPABILITY_NONE		0
+#define SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP	1
+
+#define SMIAPP_BINNING_CAPABILITY_NO			0
+#define SMIAPP_BINNING_CAPABILITY_YES			1
+
+/* Maximum number of binning subtypes */
+#define SMIAPP_BINNING_SUBTYPES				253
+
+#define SMIAPP_PIXEL_ORDER_GRBG				0
+#define SMIAPP_PIXEL_ORDER_RGGB				1
+#define SMIAPP_PIXEL_ORDER_BGGR				2
+#define SMIAPP_PIXEL_ORDER_GBRG				3
+
+#define SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL		1
+#define SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED		2
+#define SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL_N		8
+#define SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED_N	16
+
+#define SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE		0x01
+#define SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE		0x02
+#define SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NROWS_MASK	0x0f
+#define SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_MASK	0xf0
+#define SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_SHIFT	4
+
+#define SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_MASK	0xf000
+#define SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_SHIFT	12
+#define SMIAPP_FRAME_FORMAT_DESC_2_PIXELS_MASK		0x0fff
+
+#define SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_MASK	0xf0000000
+#define SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_SHIFT	28
+#define SMIAPP_FRAME_FORMAT_DESC_4_PIXELS_MASK		0x0000ffff
+
+#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED	1
+#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DUMMY	2
+#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_BLACK	3
+#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DARK		4
+#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE	5
+
+#define SMIAPP_FAST_STANDBY_CTRL_COMPLETE_FRAMES	0
+#define SMIAPP_FAST_STANDBY_CTRL_IMMEDIATE		1
+
+/* Scaling N factor */
+#define SMIAPP_SCALE_N					16
+
+/* Image statistics registers */
+/* Registers 0x2000 to 0x2fff are reserved for future
+ * use for statistics features.
+ */
+
+/* Manufacturer Specific Registers: 0x3000 to 0x3fff
+ * The manufacturer specifies these as a black box.
+ */
+
+#endif /* __SMIAPP_REG_H_ */
diff --git a/drivers/media/video/smiapp/smiapp-regs.c b/drivers/media/video/smiapp/smiapp-regs.c
new file mode 100644
index 0000000..9a2326a
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-regs.c
@@ -0,0 +1,230 @@
+/*
+ * drivers/media/video/smiapp-regs.c
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "smiapp-debug.h"
+
+#include <linux/delay.h>
+#include <linux/i2c.h>
+
+#include "smiapp-regs.h"
+
+static uint32_t float_to_u32_mul_1000000(struct i2c_client *client,
+					 uint32_t phloat)
+{
+	int32_t exp;
+	uint64_t man;
+
+	if (phloat >= 0x80000000) {
+		dev_err(&client->dev, "this is a negative number\n");
+		return 0;
+	}
+
+	if (phloat == 0x7f800000)
+		return ~0; /* Inf. */
+
+	if ((phloat & 0x7f800000) == 0x7f800000) {
+		dev_err(&client->dev, "NaN or other special number\n");
+		return 0;
+	}
+
+	/* Valid cases begin here */
+	if (phloat == 0)
+		return 0; /* Valid zero */
+
+	if (phloat > 0x4f800000)
+		return ~0; /* larger than 4294967295 */
+
+	/*
+	 * Unbias exponent (note how phloat is now guaranteed to
+	 * have 0 in the high bit)
+	 */
+	exp = ((int32_t)phloat >> 23) - 127;
+
+	/* Extract mantissa, add missing '1' bit and it's in MHz */
+	man = ((phloat & 0x7fffff) | 0x800000) * 1000000ULL;
+
+	if (exp < 0)
+		man >>= -exp;
+	else
+		man <<= exp;
+
+	man >>= 23; /* Remove mantissa bias */
+
+	return man & 0xffffffff;
+}
+
+
+/*
+ * Read a 8/16/32-bit i2c register.  The value is returned in 'val'.
+ * Returns zero if successful, or non-zero otherwise.
+ */
+int smia_i2c_read_reg(struct i2c_client *client, u32 reg, u32 *val)
+{
+	struct i2c_msg msg[1];
+	unsigned char data[4];
+	unsigned int len = (u8)(reg >> 16);
+	u16 offset = reg;
+	int r;
+
+	if (!client->adapter)
+		return -ENODEV;
+	if (len != SMIA_REG_8BIT && len != SMIA_REG_16BIT
+	    && len != SMIA_REG_32BIT)
+		return -EINVAL;
+
+	msg->addr = client->addr;
+	msg->flags = 0;
+	msg->len = 2;
+	msg->buf = data;
+
+	/* high byte goes out first */
+	data[0] = (u8) (offset >> 8);
+	data[1] = (u8) offset;
+	r = i2c_transfer(client->adapter, msg, 1);
+	if (r != 1) {
+		if (r >= 0)
+			r = -EBUSY;
+		goto err;
+	}
+
+	msg->len = len;
+	msg->flags = I2C_M_RD;
+	r = i2c_transfer(client->adapter, msg, 1);
+	if (r != 1) {
+		if (r >= 0)
+			r = -EBUSY;
+		goto err;
+	}
+
+	*val = 0;
+	/* high byte comes first */
+	switch (len) {
+	case SMIA_REG_32BIT:
+		*val = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) +
+			data[3];
+		break;
+	case SMIA_REG_16BIT:
+		*val = (data[0] << 8) + data[1];
+		break;
+	case SMIA_REG_8BIT:
+		*val = data[0];
+		break;
+	default:
+		BUG();
+	}
+
+	if (reg & SMIA_REG_FLAG_FLOAT)
+		*val = float_to_u32_mul_1000000(client, *val);
+
+	return 0;
+
+err:
+	dev_err(&client->dev, "read from offset 0x%x error %d\n", offset, r);
+
+	return r;
+}
+
+static void smia_i2c_create_msg(struct i2c_client *client, u16 len, u16 reg,
+				u32 val, struct i2c_msg *msg,
+				unsigned char *buf)
+{
+	msg->addr = client->addr;
+	msg->flags = 0; /* Write */
+	msg->len = 2 + len;
+	msg->buf = buf;
+
+	/* high byte goes out first */
+	buf[0] = (u8) (reg >> 8);
+	buf[1] = (u8) (reg & 0xff);
+
+	switch (len) {
+	case SMIA_REG_8BIT:
+		buf[2] = val;
+		break;
+	case SMIA_REG_16BIT:
+		buf[2] = val >> 8;
+		buf[3] = val;
+		break;
+	case SMIA_REG_32BIT:
+		buf[2] = val >> 24;
+		buf[3] = val >> 16;
+		buf[4] = val >> 8;
+		buf[5] = val;
+		break;
+	default:
+		BUG();
+	}
+}
+
+/*
+ * Write to a 8/16-bit register.
+ * Returns zero if successful, or non-zero otherwise.
+ */
+int smia_i2c_write_reg(struct i2c_client *client, u32 reg, u32 val)
+{
+	struct i2c_msg msg[1];
+	unsigned char data[6];
+	unsigned int retries = 5;
+	unsigned int flags = reg >> 24;
+	unsigned int len = (u8)(reg >> 16);
+	u16 offset = reg;
+	int r;
+
+	if (!client->adapter)
+		return -ENODEV;
+
+	if ((len != SMIA_REG_8BIT && len != SMIA_REG_16BIT &&
+	     len != SMIA_REG_32BIT) || flags)
+		return -EINVAL;
+
+	smia_i2c_create_msg(client, len, offset, val, msg, data);
+
+	do {
+		/*
+		 * Due to unknown reason sensor stops responding. This
+		 * loop is a temporaty solution until the root cause
+		 * is found.
+		 */
+		r = i2c_transfer(client->adapter, msg, 1);
+		if (r == 1)
+			break;
+
+		usleep_range(2000, 2000);
+	} while (retries--);
+
+	if (r != 1) {
+		dev_err(&client->dev,
+			"wrote 0x%x to offset 0x%x error %d\n", val, offset, r);
+	} else {
+		if (r >= 0)
+			r = -EBUSY;
+		r = 0; /* on success i2c_transfer() return messages trasfered */
+	}
+
+	if (retries < 5)
+		dev_err(&client->dev, "sensor i2c stall encountered. "
+			"retries: %d\n", 5 - retries);
+
+	return r;
+}
diff --git a/drivers/media/video/smiapp/smiapp-regs.h b/drivers/media/video/smiapp/smiapp-regs.h
new file mode 100644
index 0000000..20c4c25
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp-regs.h
@@ -0,0 +1,46 @@
+/*
+ * include/media/smiapp-regs.h
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef SMIAPP_REGS_H
+#define SMIAPP_REGS_H
+
+#include <linux/i2c.h>
+#include <linux/types.h>
+
+/* Use upper 8 bits of the type field for flags */
+#define SMIA_REG_FLAG_FLOAT		(1 << 24)
+
+#define SMIA_REG_8BIT			1
+#define SMIA_REG_16BIT			2
+#define SMIA_REG_32BIT			4
+struct smia_reg {
+	u16 type;
+	u16 reg;			/* 16-bit offset */
+	u32 val;			/* 8/16/32-bit value */
+};
+
+int smia_i2c_read_reg(struct i2c_client *client, u32 reg, u32 *val);
+int smia_i2c_write_reg(struct i2c_client *client, u32 reg, u32 val);
+
+#endif
diff --git a/drivers/media/video/smiapp/smiapp.h b/drivers/media/video/smiapp/smiapp.h
new file mode 100644
index 0000000..df514dd
--- /dev/null
+++ b/drivers/media/video/smiapp/smiapp.h
@@ -0,0 +1,268 @@
+/*
+ * drivers/media/video/smiapp.h
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2010-2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __SMIAPP_PRIV_H_
+#define __SMIAPP_PRIV_H_
+
+#include <linux/mutex.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-subdev.h>
+#include <media/smiapp.h>
+
+#include "smiapp-reg.h"
+#include "smiapp-regs.h"
+#include "smiapp-quirk.h"
+
+/*
+ * Standard SMIA++ constants
+ */
+#define SMIA_VERSION_1			10
+#define SMIAPP_VERSION_0_8		8 /* Draft 0.8 */
+#define SMIAPP_VERSION_0_9		9 /* Draft 0.9 */
+#define SMIAPP_VERSION_1		10
+
+#define SMIAPP_PROFILE_0		0
+#define SMIAPP_PROFILE_1		1
+#define SMIAPP_PROFILE_2		2
+
+#define SMIAPP_NVM_PAGE_SIZE		64	/* bytes */
+
+#define SMIAPP_RESET_DELAY_CLOCKS	2400
+#define SMIAPP_RESET_DELAY(clk)				\
+	(1000 +	(SMIAPP_RESET_DELAY_CLOCKS * 1000	\
+		 + (clk) / 1000 - 1) / ((clk) / 1000))
+
+#include "smiapp-limits.h"
+
+struct smiapp_quirk;
+
+#define SMIAPP_MODULE_IDENT_FLAG_REV_LE		(1 << 0)
+
+struct smiapp_module_ident {
+	u8 manufacturer_id;
+	u16 model_id;
+	u8 revision_number_major;
+
+	u8 flags;
+
+	char *name;
+	const struct smiapp_quirk *quirk;
+} __packed;
+
+struct smiapp_module_info {
+	u32 manufacturer_id;
+	u32 model_id;
+	u32 revision_number_major;
+	u32 revision_number_minor;
+
+	u32 module_year;
+	u32 module_month;
+	u32 module_day;
+
+	u32 sensor_manufacturer_id;
+	u32 sensor_model_id;
+	u32 sensor_revision_number;
+	u32 sensor_firmware_version;
+
+	u32 smia_version;
+	u32 smiapp_version;
+
+	u32 smiapp_profile;
+
+	char *name;
+	const struct smiapp_quirk *quirk;
+};
+
+#define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk)	\
+	{ .manufacturer_id = manufacturer,				\
+			.model_id = model,				\
+			.revision_number_major = rev,			\
+			.flags = fl,					\
+			.name = _name,					\
+			.quirk = _quirk, }
+
+#define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk)	\
+	{ .manufacturer_id = manufacturer,				\
+			.model_id = model,				\
+			.revision_number_major = rev,			\
+			.flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE,	\
+			.name = _name,					\
+			.quirk = _quirk, }
+
+#define SMIAPP_IDENT_L(manufacturer, model, rev, _name)			\
+	{ .manufacturer_id = manufacturer,				\
+			.model_id = model,				\
+			.revision_number_major = rev,			\
+			.flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE,	\
+			.name = _name, }
+
+#define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk)		\
+	{ .manufacturer_id = manufacturer,				\
+			.model_id = model,				\
+			.revision_number_major = rev,			\
+			.flags = 0,					\
+			.name = _name,					\
+			.quirk = _quirk, }
+
+#define SMIAPP_IDENT(manufacturer, model, rev, _name)			\
+	{ .manufacturer_id = manufacturer,				\
+			.model_id = model,				\
+			.revision_number_major = rev,			\
+			.flags = 0,					\
+			.name = _name, }
+
+struct smiapp_reg_limits {
+	u32 addr;
+	char *what;
+};
+
+extern struct smiapp_reg_limits smiapp_reg_limits[];
+
+struct smiapp_csi_data_format {
+	u32 code;
+	u8 width;
+	u8 compressed;
+	u8 pixel_order;
+};
+
+struct smiapp_pll {
+	uint16_t pre_pll_clk_div;
+	uint16_t pll_multiplier;
+	uint16_t op_sys_clk_div;
+	uint16_t op_pix_clk_div;
+	uint16_t vt_sys_clk_div;
+	uint16_t vt_pix_clk_div;
+
+	uint32_t ext_clk_freq_hz;
+	uint32_t pll_ip_clk_freq_hz;
+	uint32_t pll_op_clk_freq_hz;
+	uint32_t op_sys_clk_freq_hz;
+	uint32_t op_pix_clk_freq_hz;
+	uint32_t vt_sys_clk_freq_hz;
+	uint32_t vt_pix_clk_freq_hz;
+};
+
+#define SMIAPP_SUBDEVS			3
+
+#define SMIAPP_PAD_SOURCE		0
+#define SMIAPP_PAD_SINK			1
+#define SMIAPP_PADS			2
+
+struct smiapp_binning_subtype {
+	u8 horizontal:4;
+	u8 vertical:4;
+} __packed;
+
+struct smiapp_subdev {
+	struct v4l2_subdev sd;
+	struct media_pad pads[2];
+	struct v4l2_rect sink_fmt;
+	struct v4l2_rect crop[2];
+	struct v4l2_rect compose; /* compose on sink */
+	int npads;
+	struct smiapp_sensor *sensor;
+	struct v4l2_ctrl_handler ctrl_handler;
+};
+
+/*
+ * struct smiapp_sensor - Main device structure
+ */
+struct smiapp_sensor {
+	/*
+	 * "mutex" is used to serialise access to all fields here
+	 * except v4l2_ctrls at the end of the struct. Should both
+	 * "mutex" and the control handler locks be held
+	 * simultaneously, the control handler lock must be acquired
+	 * first. "mutex" is also used to serialise access to file
+	 * handle specific information. The exception to this rule is
+	 * the power_mutex below.
+	 */
+	struct mutex mutex;
+	/*
+	 * power_mutex is used to serialise opening and closing of
+	 * file handles, including power management.
+	 */
+	struct mutex power_mutex;
+	struct smiapp_subdev sds[SMIAPP_SUBDEVS];
+	u32 sds_used;
+	struct smiapp_subdev *src;
+	struct smiapp_subdev *binner;
+	struct smiapp_subdev *scaler;
+	struct smiapp_subdev *pixel_array;
+	struct smiapp_platform_data *platform_data;
+	struct regulator *vana;
+	u32 limits[SMIAPP_LIMIT_LAST];
+	u8 nbinning_subtypes;
+	struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
+	u32 mbus_frame_fmts;
+	const struct smiapp_csi_data_format *csi_format;
+	const struct smiapp_csi_data_format *internal_csi_format;
+	u32 default_mbus_frame_fmts;
+	int default_pixel_order;
+
+	u8 binning_horizontal;
+	u8 binning_vertical;
+
+	u8 scale_m;
+	u8 scaling_mode;
+
+	u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
+	u8 flash_capability;
+	u8 frame_skip;
+
+	int power_count;
+
+	unsigned int streaming:1;
+	unsigned int dev_init_done:1;
+
+	u8 *nvm;		/* nvm memory buffer */
+	unsigned int nvm_size;	/* bytes */
+
+	struct smiapp_module_info minfo;
+
+	struct smiapp_pll pll;
+
+	/* Pixel array controls */
+	struct v4l2_ctrl *analog_gain;
+	struct v4l2_ctrl *exposure;
+	struct v4l2_ctrl *hflip;
+	struct v4l2_ctrl *vflip;
+	struct v4l2_ctrl *vblank;
+	struct v4l2_ctrl *hblank;
+	struct v4l2_ctrl *pixel_rate_parray;
+	/* src controls */
+	struct v4l2_ctrl *link_freq;
+	struct v4l2_ctrl *pixel_rate_csi;
+};
+
+#define to_smiapp_subdev(_sd)				\
+	container_of(_sd, struct smiapp_subdev, sd)
+
+#define to_smiapp_sensor(_sd)	\
+	(to_smiapp_subdev(_sd)->sensor)
+
+int smiapp_pll_update(struct smiapp_sensor *sensor);
+int smiapp_pll_configure(struct smiapp_sensor *sensor);
+
+#endif /* __SMIAPP_PRIV_H_ */
diff --git a/include/media/smiapp.h b/include/media/smiapp.h
new file mode 100644
index 0000000..a7877cd
--- /dev/null
+++ b/include/media/smiapp.h
@@ -0,0 +1,83 @@
+/*
+ * include/media/smiapp.h
+ *
+ * Generic driver for SMIA/SMIA++ compliant camera modules
+ *
+ * Copyright (C) 2011--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __SMIAPP_H_
+#define __SMIAPP_H_
+
+#include <media/v4l2-subdev.h>
+
+#define SMIAPP_NAME		"smiapp"
+
+#define SMIAPP_DFL_I2C_ADDR	(0x20 >> 1) /* Default I2C Address */
+#define SMIAPP_ALT_I2C_ADDR	(0x6e >> 1) /* Alternate I2C Address */
+
+#define SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK	0
+#define SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_STROBE	1
+#define SMIAPP_CSI_SIGNALLING_MODE_CSI2			2
+
+#define SMIAPP_NO_XSHUTDOWN	-1
+
+/*
+ * Sometimes due to board layout considerations the camera module can be
+ * mounted rotated. The typical rotation used is 180 degrees which can be
+ * corrected by giving a default H-FLIP and V-FLIP in the sensor readout.
+ * FIXME: rotation also changes the bayer pattern.
+ */
+enum smiapp_module_board_orient {
+	SMIAPP_MODULE_BOARD_ORIENT_0 = 0,
+	SMIAPP_MODULE_BOARD_ORIENT_180,
+};
+
+struct smiapp_flash_strobe_parms {
+	u8 mode;
+	u32 strobe_width_high_us;
+	u16 strobe_delay;
+	u16 stobe_start_point;
+	u8 trigger;
+};
+
+struct smiapp_platform_data {
+	/*
+	 * Change the cci address if i2c_addr_alt is set.
+	 * Both default and alternate cci addr need to be present
+	 */
+	unsigned short i2c_addr_dfl;	/* Default i2c addr */
+	unsigned short i2c_addr_alt;	/* Alternate i2c addr */
+
+	unsigned int nvm_size;			/* bytes */
+	unsigned int ext_clk;			/* sensor external clk */
+
+	unsigned int lanes;		/* Number of CSI-2 lanes */
+	u8 csi_signalling_mode;		/* SMIAPP_CSI_SIGNALLING_MODE_* */
+	const s64 *op_sys_clock;
+
+	enum smiapp_module_board_orient module_board_orient;
+
+	struct smiapp_flash_strobe_parms *strobe_setup;
+
+	int (*set_xclk)(struct v4l2_subdev *sd, int hz);
+	int xshutdown;			/* gpio or SMIAPP_NO_XSHUTDOWN */
+};
+
+#endif /* __SMIAPP_H_  */
-- 
1.7.2.5


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

* [PATCH v3 33/33] rm680: Add camera init
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (31 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 32/33] smiapp: Add driver Sakari Ailus
@ 2012-02-20  1:57 ` Sakari Ailus
  2012-02-27  1:06   ` Laurent Pinchart
  2012-02-20  2:03 ` [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
  33 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  1:57 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

From: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>

This currently introduces an extra file to the arch/arm/mach-omap2
directory: board-rm680-camera.c. Keeping the device tree in mind, the
context of the file could be represented as static data with one exception:
the external clock to the sensor.

This external clock is provided by the OMAP 3 SoC and required by the
sensor. The issue is that the clock originates from the ISP and not from
PRCM block as the other clocks and thus is not supported by the clock
framework. Otherwise the sensor driver could just clk_get() and clk_enable()
it, just like the regulators and gpios.

Signed-off-by: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
---
 arch/arm/mach-omap2/Makefile             |    3 +-
 arch/arm/mach-omap2/board-rm680-camera.c |  375 ++++++++++++++++++++++++++++++
 arch/arm/mach-omap2/board-rm680.c        |   38 +++
 3 files changed, 415 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-omap2/board-rm680-camera.c

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index fc9b238..f92cc92 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -206,7 +206,8 @@ obj-$(CONFIG_MACH_OMAP3_PANDORA)	+= board-omap3pandora.o
 obj-$(CONFIG_MACH_OMAP_3430SDP)		+= board-3430sdp.o
 obj-$(CONFIG_MACH_NOKIA_N8X0)		+= board-n8x0.o
 obj-$(CONFIG_MACH_NOKIA_RM680)		+= board-rm680.o \
-					   sdram-nokia.o
+					   sdram-nokia.o \
+					   board-rm680-camera.o
 obj-$(CONFIG_MACH_NOKIA_RX51)		+= board-rx51.o \
 					   sdram-nokia.o \
 					   board-rx51-peripherals.o \
diff --git a/arch/arm/mach-omap2/board-rm680-camera.c b/arch/arm/mach-omap2/board-rm680-camera.c
new file mode 100644
index 0000000..5059821
--- /dev/null
+++ b/arch/arm/mach-omap2/board-rm680-camera.c
@@ -0,0 +1,375 @@
+/**
+ * arch/arm/mach-omap2/board-rm680-camera.c
+ *
+ * Copyright (C) 2010--2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * Based on board-rx71-camera.c by Vimarsh Zutshi
+ * Based on board-rx51-camera.c by Sakari Ailus
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/mm.h>
+#include <linux/platform_device.h>
+#include <linux/videodev2.h>
+
+#include <asm/mach-types.h>
+#include <plat/omap-pm.h>
+
+#include <media/omap3isp.h>
+#include <media/smiapp.h>
+
+#include "../../../drivers/media/video/omap3isp/isp.h"
+#include "devices.h"
+
+#define SEC_CAMERA_RESET_GPIO	97
+
+#define RM680_PRI_SENSOR	1
+#define RM680_PRI_LENS		2
+#define RM680_SEC_SENSOR	3
+#define MAIN_CAMERA_XCLK	ISP_XCLK_A
+#define SEC_CAMERA_XCLK		ISP_XCLK_B
+
+/*
+ *
+ * Main Camera Module EXTCLK
+ * Used by the sensor and the actuator driver.
+ *
+ */
+static struct camera_xclk {
+	u32 hz;
+	u32 lock;
+	u8 xclksel;
+} cameras_xclk;
+
+static DEFINE_MUTEX(lock_xclk);
+
+static int rm680_update_xclk(struct v4l2_subdev *subdev, u32 hz, u32 which,
+			     u8 xclksel)
+{
+	struct isp_device *isp = v4l2_dev_to_isp_device(subdev->v4l2_dev);
+	int ret;
+
+	mutex_lock(&lock_xclk);
+
+	if (which == RM680_SEC_SENSOR) {
+		if (cameras_xclk.xclksel == MAIN_CAMERA_XCLK) {
+			ret = -EBUSY;
+			goto done;
+		}
+	} else {
+		if (cameras_xclk.xclksel == SEC_CAMERA_XCLK) {
+			ret = -EBUSY;
+			goto done;
+		}
+	}
+
+	if (hz) {	/* Turn on */
+		cameras_xclk.lock |= which;
+		if (cameras_xclk.hz == 0) {
+			isp->platform_cb.set_xclk(isp, hz, xclksel);
+			cameras_xclk.hz = hz;
+			cameras_xclk.xclksel = xclksel;
+		}
+	} else {	/* Turn off */
+		cameras_xclk.lock &= ~which;
+		if (cameras_xclk.lock == 0) {
+			isp->platform_cb.set_xclk(isp, 0, xclksel);
+			cameras_xclk.hz = 0;
+			cameras_xclk.xclksel = 0;
+		}
+	}
+
+	ret = cameras_xclk.hz;
+
+done:
+	mutex_unlock(&lock_xclk);
+	return ret;
+}
+
+/*
+ *
+ * Main Camera Sensor
+ *
+ */
+
+static int rm680_main_camera_set_xclk(struct v4l2_subdev *sd, int hz)
+{
+	return rm680_update_xclk(sd, hz, RM680_PRI_SENSOR, MAIN_CAMERA_XCLK);
+}
+
+static struct smiapp_flash_strobe_parms rm680_main_camera_strobe_setup = {
+	.mode			= 0x0c,
+	.strobe_width_high_us	= 100000,
+	.strobe_delay		= 0,
+	.stobe_start_point	= 0,
+	.trigger		= 0,
+};
+
+static struct smiapp_platform_data rm696_main_camera_platform_data = {
+	.i2c_addr_dfl		= SMIAPP_DFL_I2C_ADDR,
+	.i2c_addr_alt		= SMIAPP_ALT_I2C_ADDR,
+	.nvm_size		= 16 * 64,
+	.ext_clk		= (9.6 * 1000 * 1000),
+	.lanes			= 2,
+	/* bit rate / ddr / lanes */
+	.op_sys_clock		= (s64 []){ 796800000 / 2 / 2,
+					    840000000 / 2 / 2,
+					    1996800000 / 2 / 2, 0 },
+	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CSI2,
+	.strobe_setup		= &rm680_main_camera_strobe_setup,
+	.set_xclk		= rm680_main_camera_set_xclk,
+	.xshutdown		= SMIAPP_NO_XSHUTDOWN,
+};
+
+static struct smiapp_platform_data rm680_main_camera_platform_data = {
+	.i2c_addr_dfl		= SMIAPP_DFL_I2C_ADDR,
+	.i2c_addr_alt		= SMIAPP_ALT_I2C_ADDR,
+	.nvm_size		= 16 * 64,
+	.ext_clk		= (9.6 * 1000 * 1000),
+	.lanes			= 2,
+	.op_sys_clock		= (s64 []){ 840000000 / 2 / 2,
+					    1334400000 / 2 / 2,
+					    1593600000 / 2 / 2, 0 },
+	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CSI2,
+	.module_board_orient	= SMIAPP_MODULE_BOARD_ORIENT_180,
+	.strobe_setup		= &rm680_main_camera_strobe_setup,
+	.set_xclk		= rm680_main_camera_set_xclk,
+	.xshutdown		= SMIAPP_NO_XSHUTDOWN,
+};
+
+/*
+ *
+ * SECONDARY CAMERA Sensor
+ *
+ */
+
+#define SEC_CAMERA_XCLK		ISP_XCLK_B
+
+static int rm680_sec_camera_set_xclk(struct v4l2_subdev *sd, int hz)
+{
+	return rm680_update_xclk(sd, hz, RM680_SEC_SENSOR, SEC_CAMERA_XCLK);
+}
+
+static struct smiapp_platform_data rm696_sec_camera_platform_data = {
+	.ext_clk		= (10.8 * 1000 * 1000),
+	.lanes			= 1,
+	/* bit rate / ddr */
+	.op_sys_clock		= (s64 []){ 13770000 * 10 / 2, 0 },
+	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK,
+	.module_board_orient	= SMIAPP_MODULE_BOARD_ORIENT_180,
+	.set_xclk		= rm680_sec_camera_set_xclk,
+	.xshutdown		= SEC_CAMERA_RESET_GPIO,
+};
+
+static struct smiapp_platform_data rm680_sec_camera_platform_data = {
+	.ext_clk		= (10.8 * 1000 * 1000),
+	.lanes			= 1,
+	/* bit rate / ddr */
+	.op_sys_clock		= (s64 []){ 11880000 * 10 / 2, 0 },
+	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK,
+	.set_xclk		= rm680_sec_camera_set_xclk,
+	.xshutdown		= SEC_CAMERA_RESET_GPIO,
+};
+
+/*
+ *
+ * Init all the modules
+ *
+ */
+
+#define CAMERA_I2C_BUS_NUM		2
+#define AD5836_I2C_BUS_NUM		2
+#define AS3645A_I2C_BUS_NUM		2
+
+static struct i2c_board_info rm696_camera_i2c_devices[] = {
+	{
+		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_ALT_I2C_ADDR),
+		.platform_data = &rm696_main_camera_platform_data,
+	},
+	{
+		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_DFL_I2C_ADDR),
+		.platform_data = &rm696_sec_camera_platform_data,
+	},
+};
+
+static struct i2c_board_info rm680_camera_i2c_devices[] = {
+	{
+		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_ALT_I2C_ADDR),
+		.platform_data = &rm680_main_camera_platform_data,
+	},
+	{
+		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_DFL_I2C_ADDR),
+		.platform_data = &rm680_sec_camera_platform_data,
+	},
+};
+
+static struct isp_subdev_i2c_board_info rm696_camera_primary_subdevs[] = {
+	{
+		.board_info = &rm696_camera_i2c_devices[0],
+		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
+	},
+	{ NULL, 0, },
+};
+
+static struct isp_subdev_i2c_board_info rm696_camera_secondary_subdevs[] = {
+	{
+		.board_info = &rm696_camera_i2c_devices[1],
+		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
+	},
+	{ NULL, 0, },
+};
+
+static struct isp_subdev_i2c_board_info rm680_camera_primary_subdevs[] = {
+	{
+		.board_info = &rm680_camera_i2c_devices[0],
+		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
+	},
+	{ NULL, 0, },
+};
+
+static struct isp_subdev_i2c_board_info rm680_camera_secondary_subdevs[] = {
+	{
+		.board_info = &rm680_camera_i2c_devices[1],
+		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
+	},
+	{ NULL, 0, },
+};
+
+static struct isp_v4l2_subdevs_group rm696_camera_subdevs[] = {
+	{
+		.subdevs = rm696_camera_primary_subdevs,
+		.interface = ISP_INTERFACE_CSI2A_PHY2,
+		.bus = { .csi2 = {
+			.crc		= 1,
+			.vpclk_div	= 1,
+			.lanecfg	= {
+				.clk = {
+					.pol = 1,
+					.pos = 2,
+				},
+				.data[0] = {
+					.pol = 1,
+					.pos = 1,
+				},
+				.data[1] = {
+					.pol = 1,
+					.pos = 3,
+				},
+			},
+		} },
+	},
+	{
+		.subdevs = rm696_camera_secondary_subdevs,
+		.interface = ISP_INTERFACE_CCP2B_PHY1,
+		.bus = { .ccp2 = {
+			.strobe_clk_pol	= 0,
+			.crc		= 0,
+			.ccp2_mode	= 0,
+			.phy_layer	= 0,
+			.vpclk_div	= 2,
+			.lanecfg	= {
+				.clk = {
+					.pol = 0,
+					.pos = 1,
+				},
+				.data[0] = {
+					.pol = 0,
+					.pos = 2,
+				},
+			},
+		} },
+	},
+	{ NULL, 0, },
+};
+
+static struct isp_v4l2_subdevs_group rm680_camera_subdevs[] = {
+	{
+		.subdevs = rm680_camera_primary_subdevs,
+		.interface = ISP_INTERFACE_CSI2A_PHY2,
+		.bus = { .csi2 = {
+			.crc		= 1,
+			.vpclk_div	= 1,
+			.lanecfg	= {
+				.clk = {
+					.pol = 1,
+					.pos = 2,
+				},
+				.data[0] = {
+					.pol = 1,
+					.pos = 3,
+				},
+				.data[1] = {
+					.pol = 1,
+					.pos = 1,
+				},
+			},
+		} },
+	},
+	{
+		.subdevs = rm680_camera_secondary_subdevs,
+		.interface = ISP_INTERFACE_CCP2B_PHY1,
+		.bus = { .ccp2 = {
+			.strobe_clk_pol	= 0,
+			.crc		= 0,
+			.ccp2_mode	= 0,
+			.phy_layer	= 0,
+			.vpclk_div	= 2,
+			.lanecfg	= {
+				.clk = {
+					.pol = 0,
+					.pos = 1,
+				},
+				.data[0] = {
+					.pol = 0,
+					.pos = 2,
+				},
+			},
+		} },
+	},
+	{ NULL, 0, },
+};
+
+static struct isp_platform_data rm696_isp_platform_data = {
+	.subdevs = rm696_camera_subdevs,
+};
+
+static struct isp_platform_data rm680_isp_platform_data = {
+	.subdevs = rm680_camera_subdevs,
+};
+
+static inline int board_is_rm680(void)
+{
+	return (system_rev & 0x00f0) == 0x0020;
+}
+
+void __init rm680_camera_init(void)
+{
+	struct isp_platform_data *pdata;
+
+	if (board_is_rm680())
+		pdata = &rm680_isp_platform_data;
+	else
+		pdata = &rm696_isp_platform_data;
+
+	if (omap3_init_camera(pdata) < 0)
+		pr_warn("%s: unable to register camera platform device\n",
+			__func__);
+}
diff --git a/arch/arm/mach-omap2/board-rm680.c b/arch/arm/mach-omap2/board-rm680.c
index 8678b38..71607a70 100644
--- a/arch/arm/mach-omap2/board-rm680.c
+++ b/arch/arm/mach-omap2/board-rm680.c
@@ -66,6 +66,39 @@ static struct platform_device rm680_vemmc_device = {
 	},
 };
 
+#define REGULATOR_INIT_DATA(_name, _min, _max, _apply, _ops_mask) \
+	static struct regulator_init_data _name##_data = { \
+		.constraints = { \
+			.name                   = #_name, \
+			.min_uV                 = _min, \
+			.max_uV                 = _max, \
+			.apply_uV               = _apply, \
+			.valid_modes_mask       = REGULATOR_MODE_NORMAL | \
+						REGULATOR_MODE_STANDBY, \
+			.valid_ops_mask         = _ops_mask, \
+		}, \
+		.num_consumer_supplies  = ARRAY_SIZE(_name##_consumers), \
+		.consumer_supplies      = _name##_consumers, \
+}
+#define REGULATOR_INIT_DATA_FIXED(_name, _voltage) \
+	REGULATOR_INIT_DATA(_name, _voltage, _voltage, true, \
+				REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_MODE)
+
+static struct regulator_consumer_supply rm680_vaux2_consumers[] = {
+	REGULATOR_SUPPLY("VDD_CSIPHY1", "omap3isp"),	/* OMAP ISP */
+	REGULATOR_SUPPLY("VDD_CSIPHY2", "omap3isp"),	/* OMAP ISP */
+	REGULATOR_SUPPLY("vaux2", NULL),
+};
+REGULATOR_INIT_DATA_FIXED(rm680_vaux2, 1800000);
+
+static struct regulator_consumer_supply rm680_vaux3_consumers[] = {
+	REGULATOR_SUPPLY("VANA", "2-0037"),	/* Main Camera Sensor */
+	REGULATOR_SUPPLY("VANA", "2-000e"),	/* Main Camera Lens */
+	REGULATOR_SUPPLY("VANA", "2-0010"),	/* Front Camera */
+	REGULATOR_SUPPLY("vaux3", NULL),
+};
+REGULATOR_INIT_DATA_FIXED(rm680_vaux3, 2800000);
+
 static struct platform_device *rm680_peripherals_devices[] __initdata = {
 	&rm680_vemmc_device,
 };
@@ -82,6 +115,8 @@ static struct twl4030_gpio_platform_data rm680_gpio_data = {
 static struct twl4030_platform_data rm680_twl_data = {
 	.gpio			= &rm680_gpio_data,
 	/* add rest of the children here */
+	.vaux2			= &rm680_vaux2_data,
+	.vaux3			= &rm680_vaux3_data,
 };
 
 static void __init rm680_i2c_init(void)
@@ -129,6 +164,8 @@ static struct omap_board_mux board_mux[] __initdata = {
 };
 #endif
 
+void rm680_camera_init(void);
+
 static void __init rm680_init(void)
 {
 	struct omap_sdrc_params *sdrc_params;
@@ -141,6 +178,7 @@ static void __init rm680_init(void)
 
 	usb_musb_init(NULL);
 	rm680_peripherals_init();
+	rm680_camera_init();
 }
 
 MACHINE_START(NOKIA_RM680, "Nokia RM-680 board")
-- 
1.7.2.5


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

* Re: [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code
  2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
                   ` (32 preceding siblings ...)
  2012-02-20  1:57 ` [PATCH v3 33/33] rm680: Add camera init Sakari Ailus
@ 2012-02-20  2:03 ` Sakari Ailus
  33 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-20  2:03 UTC (permalink / raw)
  To: linux-media
  Cc: Laurent Pinchart, David Cohen, Sylwester Nawrocki, Hans Verkuil,
	Andy Shevchenko, Tomasz Stanislawski, tuukkat76, Kamil Debski,
	Kim HeungJun, teturtia

Hi,

On Mon, Feb 20, 2012 at 03:56:05AM +0200, Sakari Ailus wrote:
> Hi everyone,
> 
> This the third version of my patchset that contains:
> 
> - Integer menu controls [2],
> - Selection IOCTL for subdevs [3],
> - Sensor control changes [5,7],
> - link_validate() media entity and V4L2 subdev pad ops,
> - OMAP 3 ISP driver improvements [4],
> - SMIA++ sensor driver,
> - rm680/rm696 board code (a.k.a Nokia N9 and N950) and
> - Other V4L2 and media improvements (see individual patches)
> 
> The Docbook documentation in HTML format can be found in [11].

I forgot to mention the git tree is available here:

	http://linuxtv.org/git/sailus/media_tree.git media-for-3.4

Cheers,

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

* Re: [PATCH v3 01/33] v4l: Introduce integer menu controls
  2012-02-20  1:56 ` [PATCH v3 01/33] v4l: Introduce integer menu controls Sakari Ailus
@ 2012-02-20 17:36   ` Sylwester Nawrocki
  0 siblings, 0 replies; 87+ messages in thread
From: Sylwester Nawrocki @ 2012-02-20 17:36 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, laurent.pinchart, hverkuil, teturtia, dacohen,
	snjw23, andriy.shevchenko, t.stanislaws, tuukkat76, k.debski,
	riverful

Hi Sakari,

On 02/20/2012 02:56 AM, Sakari Ailus wrote:
> Create a new control type called V4L2_CTRL_TYPE_INTEGER_MENU. Integer menu
> controls are just like menu controls but the menu items are 64-bit integers
> rather than strings.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I've tested this patch when working on the camera exposure bias control,
feel free to add my
	
 Tested-by: Sylwester Nawrocki <s.nawrocki@samsung.com>

if you wish.

--

Thanks!
Sylwester

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

* Re: [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs
  2012-02-20  1:56 ` [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs Sakari Ailus
@ 2012-02-21 14:34   ` Laurent Pinchart
  2012-02-23  5:49     ` Sakari Ailus
  2012-02-21 16:15   ` Laurent Pinchart
  1 sibling, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-21 14:34 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:56:43 Sakari Ailus wrote:
> Add support for VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION
> IOCTLs. They replace functionality provided by VIDIOC_SUBDEV_S_CROP and
> VIDIOC_SUBDEV_G_CROP IOCTLs and also add new functionality (composing).
> 
> VIDIOC_SUBDEV_G_CROP and VIDIOC_SUBDEV_S_CROP continue to be supported.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/media/video/v4l2-subdev.c |   34 +++++++++++++++++++++---------
>  include/linux/v4l2-subdev.h       |   41
> +++++++++++++++++++++++++++++++++++++ include/media/v4l2-subdev.h       |  
> 21 +++++++++++++++---
>  3 files changed, 82 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/media/video/v4l2-subdev.c
> b/drivers/media/video/v4l2-subdev.c index 6fe88e9..30c7fd9 100644
> --- a/drivers/media/video/v4l2-subdev.c
> +++ b/drivers/media/video/v4l2-subdev.c
> @@ -35,14 +35,9 @@
>  static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev
> *sd) {
>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
> -	/* Allocate try format and crop in the same memory block */
> -	fh->try_fmt = kzalloc((sizeof(*fh->try_fmt) + sizeof(*fh->try_crop))
> -			      * sd->entity.num_pads, GFP_KERNEL);
> -	if (fh->try_fmt == NULL)
> +	fh->pad = kzalloc(sizeof(*fh->pad) * sd->entity.num_pads, GFP_KERNEL);
> +	if (fh->pad == NULL)
>  		return -ENOMEM;
> -
> -	fh->try_crop = (struct v4l2_rect *)
> -		(fh->try_fmt + sd->entity.num_pads);
>  #endif
>  	return 0;
>  }
> @@ -50,9 +45,8 @@ static int subdev_fh_init(struct v4l2_subdev_fh *fh,
> struct v4l2_subdev *sd) static void subdev_fh_free(struct v4l2_subdev_fh
> *fh)
>  {
>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
> -	kfree(fh->try_fmt);
> -	fh->try_fmt = NULL;
> -	fh->try_crop = NULL;
> +	kfree(fh->pad);
> +	fh->pad = NULL;
>  #endif
>  }
> 
> @@ -293,6 +287,26 @@ static long subdev_do_ioctl(struct file *file, unsigned
> int cmd, void *arg) return v4l2_subdev_call(sd, pad, enum_frame_interval,
> subdev_fh, fie);
>  	}
> +
> +	case VIDIOC_SUBDEV_G_SELECTION: {
> +		struct v4l2_subdev_selection *sel = arg;
> +
> +		if (sel->pad >= sd->entity.num_pads)
> +			return -EINVAL;

Shouldn't you verify the which field as well, as done for the crop ioctls ?

> +
> +		return v4l2_subdev_call(
> +			sd, pad, get_selection, subdev_fh, sel);
> +	}
> +
> +	case VIDIOC_SUBDEV_S_SELECTION: {
> +		struct v4l2_subdev_selection *sel = arg;
> +
> +		if (sel->pad >= sd->entity.num_pads)
> +			return -EINVAL;
> +
> +		return v4l2_subdev_call(
> +			sd, pad, set_selection, subdev_fh, sel);
> +	}
>  #endif
>  	default:
>  		return v4l2_subdev_call(sd, core, ioctl, cmd, arg);
> diff --git a/include/linux/v4l2-subdev.h b/include/linux/v4l2-subdev.h
> index ed29cbb..6c84390 100644
> --- a/include/linux/v4l2-subdev.h
> +++ b/include/linux/v4l2-subdev.h
> @@ -123,6 +123,43 @@ struct v4l2_subdev_frame_interval_enum {
>  	__u32 reserved[9];
>  };
> 
> +#define V4L2_SUBDEV_SEL_FLAG_SIZE_GE			(1 << 0)
> +#define V4L2_SUBDEV_SEL_FLAG_SIZE_LE			(1 << 1)
> +#define V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG		(1 << 2)
> +
> +/* active cropping area */
> +#define V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE			0x0000
> +/* cropping bounds */
> +#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS			0x0002
> +/* current composing area */
> +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE		0x0100
> +/* composing bounds */
> +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS		0x0102
> +
> +
> +/**
> + * struct v4l2_subdev_selection - selection info
> + *
> + * @which: either V4L2_SUBDEV_FORMAT_ACTIVE or V4L2_SUBDEV_FORMAT_TRY
> + * @pad: pad number, as reported by the media API
> + * @target: selection target, used to choose one of possible rectangles
> + * @flags: constraint flags
> + * @r: coordinates of the selection window
> + * @reserved: for future use, rounds structure size to 64 bytes, set to
> zero

I'm not sure we need to mention that the reserved fields round the structure 
size to 64 bytes.

> + *
> + * Hardware may use multiple helper windows to process a video stream.
> + * The structure is used to exchange this selection areas between
> + * an application and a driver.
> + */
> +struct v4l2_subdev_selection {
> +	__u32 which;
> +	__u32 pad;
> +	__u32 target;
> +	__u32 flags;
> +	struct v4l2_rect r;
> +	__u32 reserved[8];
> +};
> +
>  #define VIDIOC_SUBDEV_G_FMT	_IOWR('V',  4, struct v4l2_subdev_format)
>  #define VIDIOC_SUBDEV_S_FMT	_IOWR('V',  5, struct v4l2_subdev_format)
>  #define VIDIOC_SUBDEV_G_FRAME_INTERVAL \
> @@ -137,5 +174,9 @@ struct v4l2_subdev_frame_interval_enum {
>  			_IOWR('V', 75, struct v4l2_subdev_frame_interval_enum)
>  #define VIDIOC_SUBDEV_G_CROP	_IOWR('V', 59, struct v4l2_subdev_crop)
>  #define VIDIOC_SUBDEV_S_CROP	_IOWR('V', 60, struct v4l2_subdev_crop)
> +#define VIDIOC_SUBDEV_G_SELECTION \
> +	_IOWR('V', 61, struct v4l2_subdev_selection)
> +#define VIDIOC_SUBDEV_S_SELECTION \
> +	_IOWR('V', 62, struct v4l2_subdev_selection)
> 
>  #endif
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index f0f3358..feab950 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -466,6 +466,10 @@ struct v4l2_subdev_pad_ops {
>  		       struct v4l2_subdev_crop *crop);
>  	int (*get_crop)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
>  		       struct v4l2_subdev_crop *crop);
> +	int (*get_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
> +			     struct v4l2_subdev_selection *sel);
> +	int (*set_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
> +			     struct v4l2_subdev_selection *sel);
>  };
> 
>  struct v4l2_subdev_ops {
> @@ -549,8 +553,11 @@ struct v4l2_subdev {
>  struct v4l2_subdev_fh {
>  	struct v4l2_fh vfh;
>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
> -	struct v4l2_mbus_framefmt *try_fmt;
> -	struct v4l2_rect *try_crop;
> +	struct {
> +		struct v4l2_mbus_framefmt try_fmt;
> +		struct v4l2_rect try_crop;
> +		struct v4l2_rect try_compose;
> +	} *pad;
>  #endif
>  };
> 
> @@ -561,13 +568,19 @@ struct v4l2_subdev_fh {
>  static inline struct v4l2_mbus_framefmt *
>  v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
>  {
> -	return &fh->try_fmt[pad];
> +	return &fh->pad[pad].try_fmt;
>  }
> 
>  static inline struct v4l2_rect *
>  v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
>  {
> -	return &fh->try_crop[pad];
> +	return &fh->pad[pad].try_crop;
> +}
> +
> +static inline struct v4l2_rect *
> +v4l2_subdev_get_try_compose(struct v4l2_subdev_fh *fh, unsigned int pad)
> +{
> +	return &fh->pad[pad].try_compose;
>  }
>  #endif
-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 05/33] v4l: vdev_to_v4l2_subdev() should have return type "struct v4l2_subdev *"
  2012-02-20  1:56 ` [PATCH v3 05/33] v4l: vdev_to_v4l2_subdev() should have return type "struct v4l2_subdev *" Sakari Ailus
@ 2012-02-21 14:37   ` Laurent Pinchart
  0 siblings, 0 replies; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-21 14:37 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:56:44 Sakari Ailus wrote:
> vdev_to_v4l2_subdev() should return struct v4l2_subdev *, not void *. Fix
> this.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>

Sounds like you've been bitten by this :-)

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  include/media/v4l2-subdev.h |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index feab950..bcaf6b8 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -545,7 +545,7 @@ struct v4l2_subdev {
>  #define media_entity_to_v4l2_subdev(ent) \
>  	container_of(ent, struct v4l2_subdev, entity)
>  #define vdev_to_v4l2_subdev(vdev) \
> -	video_get_drvdata(vdev)
> +	((struct v4l2_subdev *)video_get_drvdata(vdev))
> 
>  /*
>   * Used for storing subdev information per file handle
-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 06/33] v4l: Check pad number in get try pointer functions
  2012-02-20  1:56 ` [PATCH v3 06/33] v4l: Check pad number in get try pointer functions Sakari Ailus
@ 2012-02-21 14:42   ` Laurent Pinchart
  2012-02-23  5:57     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-21 14:42 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:56:45 Sakari Ailus wrote:
> Unify functions to get try pointers and validate the pad number accessed by
> the user.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  include/media/v4l2-subdev.h |   31 ++++++++++++++-----------------
>  1 files changed, 14 insertions(+), 17 deletions(-)
> 
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index bcaf6b8..d48dae5 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -565,23 +565,20 @@ struct v4l2_subdev_fh {
>  	container_of(fh, struct v4l2_subdev_fh, vfh)
> 
>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
> -static inline struct v4l2_mbus_framefmt *
> -v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
> -{
> -	return &fh->pad[pad].try_fmt;
> -}
> -
> -static inline struct v4l2_rect *
> -v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
> -{
> -	return &fh->pad[pad].try_crop;
> -}
> -
> -static inline struct v4l2_rect *
> -v4l2_subdev_get_try_compose(struct v4l2_subdev_fh *fh, unsigned int pad)
> -{
> -	return &fh->pad[pad].try_compose;
> -}
> +#define __V4L2_SUBDEV_MK_GET_TRY(rtype, fun_name, field_name)		\
> +	static inline struct rtype *					\
> +	v4l2_subdev_get_try_##fun_name(struct v4l2_subdev_fh *fh,	\
> +				       unsigned int pad)		\
> +	{								\
> +		if (unlikely(pad > vdev_to_v4l2_subdev(			\
> +				     fh->vfh.vdev->entity.num_pads)	\
> +			return NULL;					\
> +		return &fh->pad[pad].field_name;			\
> +	}
> +
> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, format, try_fmt)
> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_compose)
> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, compose, try_compose)
>  #endif
> 
>  extern const struct v4l2_file_operations v4l2_subdev_fops;

I'm not sure if this is a good idea. Drivers usually access the active and try 
formats/rectangles through a single function that checks the which argument 
and returns the active format/rectangle from the driver-specific device 
structure, or calls v4l2_subdev_get_try_*. The pad number should be checked 
for both active and try formats/rectangles, as both can result in accessing a 
wrong memory location.

Furthermore, only in-kernel access to the active/try formats/rectangles need 
to be checked, as the pad argument to subdev ioctls are already checked in 
v4l2-subdev.c. If your goal is to catch buggy kernel code here, a BUG_ON might 
be more suitable (although accessing the NULL pointer would result in an oops 
anyway).

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 08/33] v4l: Add subdev selections documentation: svg and dia files
  2012-02-20  1:56 ` [PATCH v3 08/33] v4l: Add subdev selections documentation: svg and dia files Sakari Ailus
@ 2012-02-21 15:00   ` Laurent Pinchart
  2012-02-26 18:56     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-21 15:00 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:56:47 Sakari Ailus wrote:
> Add svga and dia files for V4L2 subdev selections documentation.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>

The diagram look fine, although a bit complex. They could be simplified by 
merging the identical rectangles (for instance moving the sink crop selection 
label to the dotted blue rectangle, and removing the plain blue rectangle). 
I'm not sure if that would be really more readable though, it's up to you.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs
  2012-02-20  1:56 ` [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs Sakari Ailus
  2012-02-21 14:34   ` Laurent Pinchart
@ 2012-02-21 16:15   ` Laurent Pinchart
  2012-02-23  6:01     ` Sakari Ailus
  1 sibling, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-21 16:15 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

One more comment.

On Monday 20 February 2012 03:56:43 Sakari Ailus wrote:

[snip]

> +/* active cropping area */
> +#define V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE			0x0000
> +/* cropping bounds */
> +#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS			0x0002
> +/* current composing area */
> +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE		0x0100
> +/* composing bounds */

I'm not sure if ACTIVE is a good name here. It sounds confusing as we already 
have V4L2_SUBDEV_FORMAT_ACTIVE.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 09/33] v4l: Add subdev selections documentation
  2012-02-20  1:56 ` [PATCH v3 09/33] v4l: Add subdev selections documentation Sakari Ailus
@ 2012-02-21 16:41   ` Laurent Pinchart
  2012-02-26 21:42     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-21 16:41 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:56:48 Sakari Ailus wrote:
> Add documentation for V4L2 subdev selection API. This changes also
> experimental V4L2 subdev API so that scaling now works through selection API
> only.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>


> diff --git a/Documentation/DocBook/media/v4l/dev-subdev.xml
> b/Documentation/DocBook/media/v4l/dev-subdev.xml index 0916a73..9d5e7da
> 100644
> --- a/Documentation/DocBook/media/v4l/dev-subdev.xml
> +++ b/Documentation/DocBook/media/v4l/dev-subdev.xml

[snip]

> +      <para>Scaling operation changes the size of the image by scaling
> +      it to new dimensions. Some sub-devices support it. The scaled
> +      size (width and height) is represented by &v4l2-rect;. In the
> +      case of scaling, top and left will always be zero. Scaling is
> +      configured using &sub-subdev-g-selection; and
> +      <constant>V4L2_SUBDEV_SEL_COMPOSE_ACTIVE</constant> selection
> +      target on the sink pad of the subdev. The scaling is performed
> +      related to the width and height of the crop rectangle on the
> +      subdev's sink pad.</para>

I'm not sure if that would be very clear for readers who are not yet familiar 
with the API. What about the following text instead ?

"The scaling operation changes the size of the image by scaling it to new 
dimensions. The scaling ratio isn't specified explicitly, but is implied from 
the original and scaled image sizes. Both sizes are represented by &v4l2-
rect;.

Scaling support is optional. When supported by a subdev, the crop rectangle on 
the subdev's sink pad is scaled to the size configured using &VIDIOC-SUBDEV-G-
SELECTION; and <constant>V4L2_SUBDEV_SEL_COMPOSE_ACTIVE</constant> selection 
target on the same pad. If the subdev supports scaling but no composing, the 
top and left values are not used and must always be set to zero."

(note that &sub-subdev-g-selection; has been replaced with &VIDIOC-SUBDEV-G-
SELECTION;)

I would also move this text after the sink pad crop description to follow the 
order in which operations are applied by subdevs.

> +      <para>As for pad formats, drivers store try and active
> +      rectangles for the selection targets of ACTIVE type <xref
> +      linkend="v4l2-subdev-selection-targets">.</xref></para>
> +
> +      <para>On sink pads, cropping is applied relatively to the
> +      current pad format. The pad format represents the image size as
> +      received by the sub-device from the previous block in the
> +      pipeline, and the crop rectangle represents the sub-image that
> +      will be transmitted further inside the sub-device for
> +      processing.</para>
> +
> +      <para>On source pads, cropping is similar to sink pads, with the
> +      exception that the source size from which the cropping is
> +      performed, is the COMPOSE rectangle on the sink pad. In both
> +      sink and source pads, the crop rectangle must be entirely
> +      containted inside the source image size for the crop
> +      operation.</para>
> +
> +      <para>The drivers should always use the closest possible
> +      rectangle the user requests on all selection targets, unless
> +      specificly told otherwise<xref
> +      linkend="v4l2-subdev-selection-flags">.</xref></para>
> +    </section>
> +
> +    <section>
> +      <title>Types of selection targets</title>
> +
> +      <section>
> +	<title>ACTIVE targets</title>
> +
> +	<para>ACTIVE targets reflect the actual hardware configuration
> +	at any point of time.</para>
> +      </section>
> +
> +      <section>
> +	<title>BOUNDS targets</title>
> +
> +	<para>BOUNDS targets is the smallest rectangle within which
> +	contains all valid ACTIVE rectangles.

s/within which/that/ ?

> It may not be possible
> +	to set the ACTIVE rectangle as large as the BOUNDS rectangle,
> +	however.</para>

What about

"The BOUNDS rectangle might not itself be a valid ACTIVE rectangle when all 
possible ACTIVE pixels do not form a rectangular shape (e.g. cross-shaped or 
round sensors)."

> +      </section>
> 
> -      <para>Cropping behaviour on output pads is not defined.</para>
> +    </section>
> +
> +    <section>
> +      <title>Order of configuration and format propagation</title>
> +
> +      <para>Inside subdevs, the order of image processing steps will
> +      always be from the sink pad towards the source pad. This is also
> +      reflected in the order in which the configuration must be
> +      performed by the user: the changes made will be propagated to
> +      any subsequent stages. If this behaviour is not desired, the
> +      user must set
> +      <constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant> flag.

Could you explain what happens when V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG is set ? 
Just stating that it doesn't follow the propagation behaviour previously 
described could be understood in many different ways.

> The
> +      coordinates to a step always refer to the active size of the
> +      previous step. The exception to this rule is the source compose
> +      rectangle, which refers to the sink compose bounds rectangle ---
> +      if it is supported by the hardware.</para>
> +
> +      <orderedlist>
> +	<listitem>Sink pad format. The user configures the sink pad
> +	format. This format defines the parameters of the image the
> +	entity receives through the pad for further processing.</listitem>
> +
> +	<listitem>Sink pad active crop selection. The sink pad crop
> +	defines the performed to the sink pad format.</listitem>

s/defines the/defines the cropping/ ?

> +
> +	<listitem>Sink pad active compose selection. The size of the
> +	sink pad compose rectangle defines the scaling ratio compared
> +	to the size of the sink pad crop rectangle. The location of
> +	the compose rectangle specifies the location of the active
> +	sink compose rectangle in the sink compose bounds
> +	rectangle.</listitem>
> +
> +	<listitem>Source pad active crop selection. Crop on the source
> +	pad defines crop performed to the image in the sink compose
> +	bounds rectangle.</listitem>
> +
> +	<listitem>Source pad format. The source pad format defines the
> +	output pixel format of the subdev, as well as the other
> +	parameters with the exception of the image width and height.
> +	Width and height are defined by the size of the source pad
> +	active crop selection.</listitem>
> +      </orderedlist>
> +
> +      <para>Accessing any of the above rectangles not supported by the
> +      subdev will return <constant>EINVAL</constant>.

Do drivers have to support BOUNDS rectangles for every ACTIVE rectangle they 
support (and the other way around) ? If so, I think it should be specified.

Is EINVAL returned for any other error case in the selection API ? If so, it 
might make enumeration of the supported rectangles difficult.

> Any rectangle
> +      referring to a previous unsupported rectangle coordinates will
> +      instead refer to the previous supported rectangle. For example,
> +      if sink crop is not supported, the compose selection will refer
> +      to the sink pad format dimensions instead.</para>

Should we add a list of the rectangles a subdev must/should/can support for 
the different possible use cases ?

> +      <figure id="subdev-image-processing-crop">
> +	<title>Image processing in subdevs: simple crop example</title>
> +	<mediaobject>
> +	  <imageobject>
> +	    <imagedata fileref="subdev-image-processing-crop.svg"
> +	    format="SVG" scale="200" />
> +	  </imageobject>
> +	</mediaobject>
> +      </figure>
> +
> +      <para>In the above example, the subdev supports cropping on its
> +      sink pad. To configure it, the user sets the media bus format on
> +      the subdev's sink pad. Now the active crop rectangle can be set
> +      on the sink pad --- the location and size of this rectangle
> +      reflect the location and size of a rectangle to be cropped from
> +      the sink format. The size of the sink crop rectangle will also
> +      be the size of the format of the subdev's source pad.</para>
> +
> +      <figure id="subdev-image-processing-scaling-multi-source">
> +	<title>Image processing in subdevs: scaling with multiple sources</title>
> +	<mediaobject>
> +	  <imageobject>
> +	    <imagedata fileref="subdev-image-processing-scaling-multi-source.svg"
> +	    format="SVG" scale="200" />
> +	  </imageobject>
> +	</mediaobject>
> +      </figure>
> +
> +      <para>In this example, the subdev is capable of first cropping,
> +      then scaling and finally cropping for two source pads
> +      individually from the resulting scaled image. The location of
> +      the scaled image in the cropped image is ignored in sink compose
> +      target. Both of the locations of the source crop rectangles
> +      refer to the sink scaling rectangle, independently cropping an
> +      area at location specified by the source crop rectangle from
> +      it.</para>
> +
> +      <figure id="subdev-image-processing-full">
> +	<title>Image processing in subdevs: scaling and composition
> +	with multiple sinks and sources</title>
> +	<mediaobject>
> +	  <imageobject>
> +	    <imagedata fileref="subdev-image-processing-full.svg"
> +	    format="SVG" scale="200" />
> +	  </imageobject>
> +	</mediaobject>
> +      </figure>
> +
> +      <para>The subdev driver supports two sink pads and two source
> +      pads. The images from both of the sink pads are individually
> +      cropped, then scaled and further composed on the composition
> +      bounds rectangle. From that, two independent streams are cropped
> +      and sent out of the subdev from the source pads.</para>
> 
>      </section>
> +
>    </section>
> 
>    &sub-subdev-formats;

[snip]

> diff --git a/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
> b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml new file
> mode 100644
> index 0000000..033077a
> --- /dev/null
> +++ b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
> @@ -0,0 +1,222 @@
> +<refentry id="vidioc-subdev-g-selection">
> +  <refmeta>
> +    <refentrytitle>ioctl VIDIOC_SUBDEV_G_SELECTION,
> VIDIOC_SUBDEV_S_SELECTION</refentrytitle> +    &manvol;
> +  </refmeta>
> +
> +  <refnamediv>
> +    <refname>VIDIOC_SUBDEV_G_SELECTION</refname>
> +    <refname>VIDIOC_SUBDEV_S_SELECTION</refname>
> +    <refpurpose>Get or set selection rectangles on a subdev
> pad</refpurpose> +  </refnamediv>
> +
> +  <refsynopsisdiv>
> +    <funcsynopsis>
> +      <funcprototype>
> +	<funcdef>int <function>ioctl</function></funcdef>
> +	<paramdef>int <parameter>fd</parameter></paramdef>
> +	<paramdef>int <parameter>request</parameter></paramdef>
> +	<paramdef>struct v4l2_subdev_selection
> *<parameter>argp</parameter></paramdef> +      </funcprototype>
> +    </funcsynopsis>
> +  </refsynopsisdiv>
> +
> +  <refsect1>
> +    <title>Arguments</title>
> +
> +    <variablelist>
> +      <varlistentry>
> +	<term><parameter>fd</parameter></term>
> +	<listitem>
> +	  <para>&fd;</para>
> +	</listitem>
> +      </varlistentry>
> +      <varlistentry>
> +	<term><parameter>request</parameter></term>
> +	<listitem>
> +	  <para>VIDIOC_SUBDEV_G_SELECTION, VIDIOC_SUBDEV_S_SELECTION</para>
> +	</listitem>
> +      </varlistentry>
> +      <varlistentry>
> +	<term><parameter>argp</parameter></term>
> +	<listitem>
> +	  <para></para>
> +	</listitem>
> +      </varlistentry>
> +    </variablelist>
> +  </refsect1>
> +
> +  <refsect1>
> +    <title>Description</title>
> +
> +    <note>
> +      <title>Experimental</title>
> +      <para>This is an <link linkend="experimental">experimental</link>
> +      interface and may change in the future.</para>
> +    </note>

I think you forgot to add the subdev selection API to the list of experimental 
APIs.

> +    <para>The selections are used to configure various image
> +    processing functionality performed by the subdevs which affect the
> +    image size. This currently includes cropping, scaling and
> +    composition.</para>
> +
> +    <para>The selection API replaces <link
> +    linkend="vidioc-subdev-g-crop">the old subdev crop API</link>. All
> +    the function of the crop API, and more, are supported by the
> +    selections API.</para>
> +
> +    <para>See <xref linkend="subdev"></xref> for
> +    more information on how each selection target affects the image
> +    processing pipeline inside the subdevice.</para>
> +
> +    <section>
> +      <title>Types of selection targets</title>
> +
> +      <para>The are four types of selection targets: active, default,
> +      bounds and padding.

You don't define any default or padding selection target, should these be 
removed here ?

> The ACTIVE targets are the targets which
> +      configure the hardware. The BOUNDS target will return the
> +      maximum width and height of the target.</para>
> +    </section>
> +
> +    <section>
> +      <title>Discovering supported features</title>
> +
> +      <para>To discover which targets are supported, the user can
> +      perform <constant>VIDIOC_SUBDEV_G_SELECTION</constant> on them.
> +      Any unsupported target will return
> +      <constant>EINVAL</constant>.</para>
> +    </section>
> +
> +    <table pgwide="1" frame="none" id="v4l2-subdev-selection-targets">
> +      <title>V4L2 subdev selection targets</title>
> +      <tgroup cols="3">
> +        &cs-def;
> +	<tbody valign="top">
> +	  <row>
> +	    <entry><constant>V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE</constant></entry>
> +	    <entry>0x0000</entry>
> +	    <entry>Active crop. Defines the cropping
> +	    performed by the processing step.</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS</constant></entry>
> +	    <entry>0x0002</entry>
> +	    <entry>Bounds of the crop rectangle.</entry>
> +	  </row>
> +	  <row>
> +	    
<entry><constant>V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE</constant></entry>
> +	    <entry>0x0100</entry>
> +	    <entry>Active compose rectangle. Used to configure scaling
> +	    on sink pads and composition on source pads.</entry>
> +	  </row>
> +	  <row>
> +	    
<entry><constant>V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS</constant></entry>
> +	    <entry>0x0102</entry>
> +	    <entry>Bounds of the compose rectangle.</entry>
> +	  </row>
> +	</tbody>
> +      </tgroup>
> +    </table>
> +
> +    <table pgwide="1" frame="none" id="v4l2-subdev-selection-flags">
> +      <title>V4L2 subdev selection flags</title>
> +      <tgroup cols="3">
> +        &cs-def;
> +	<tbody valign="top">
> +	  <row>
> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_GE</constant></entry>
> +	    <entry>(1 &lt;&lt; 0)</entry>
> +	    <entry>Suggest the driver it should choose greater or
> +	    equal rectangle (in size) than was requested.</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_LE</constant></entry>
> +	    <entry>(1 &lt;&lt; 1)</entry>
> +	    <entry>Suggest the driver it should choose lesser or
> +	    equal rectangle (in size) than was requested.</entry>
> +	  </row>

Those two flags are only briefly described here, could you add a more detailed 
description either here or in Documentation/DocBook/media/v4l/dev-subdev.xml ?

> +	  <row>
> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant></entry>
> +	    <entry>(1 &lt;&lt; 2)</entry>
> +	    <entry>The configuration should not be propagated to any
> +	    further processing steps. If this flag is not given, the
> +	    configuration is propagated inside the subdevice to all
> +	    further processing steps.</entry>
> +	  </row>
> +	</tbody>
> +      </tgroup>
> +    </table>
> +
> +    <table pgwide="1" frame="none" id="v4l2-subdev-selection">
> +      <title>struct <structname>v4l2_subdev_selection</structname></title>
> +      <tgroup cols="3">
> +        &cs-str;
> +	<tbody valign="top">
> +	  <row>
> +	    <entry>__u32</entry>
> +	    <entry><structfield>which</structfield></entry>
> +	    <entry>Active or try selection, from
> +	    &v4l2-subdev-format-whence;.</entry>
> +	  </row>
> +	  <row>
> +	    <entry>__u32</entry>
> +	    <entry><structfield>pad</structfield></entry>
> +	    <entry>Pad number as reported by the media framework.</entry>
> +	  </row>
> +	  <row>
> +	    <entry>__u32</entry>
> +	    <entry><structfield>target</structfield></entry>
> +	    <entry>Target selection rectangle. See
> +	    <xref linkend="v4l2-subdev-selection-targets">.</xref>.</entry>
> +	  </row>
> +	  <row>
> +	    <entry>__u32</entry>
> +	    <entry><structfield>flags</structfield></entry>
> +	    <entry>Flags. See
> +	    <xref linkend="v4l2-subdev-selection-flags">.</xref></entry>
> +	  </row>
> +	  <row>
> +	    <entry>&v4l2-rect;</entry>
> +	    <entry><structfield>rect</structfield></entry>
> +	    <entry>Crop rectangle boundaries, in pixels.</entry>
> +	  </row>
> +	  <row>
> +	    <entry>__u32</entry>
> +	    <entry><structfield>reserved</structfield>[8]</entry>
> +	    <entry>Reserved for future extensions. Applications and drivers must
> +	    set the array to zero.</entry>
> +	  </row>
> +	</tbody>
> +      </tgroup>
> +    </table>
> +
> +  </refsect1>
> +
> +  <refsect1>
> +    &return-value;
> +
> +    <variablelist>
> +      <varlistentry>
> +	<term><errorcode>EBUSY</errorcode></term>
> +	<listitem>
> +	  <para>The selection rectangle can't be changed because the
> +	  pad is currently busy. This can be caused, for instance, by
> +	  an active video stream on the pad. The ioctl must not be
> +	  retried without performing another action to fix the problem
> +	  first. Only returned by
> +	  <constant>VIDIOC_SUBDEV_S_SELECTION</constant></para>
> +	</listitem>
> +      </varlistentry>
> +      <varlistentry>
> +	<term><errorcode>EINVAL</errorcode></term>
> +	<listitem>
> +	  <para>The &v4l2-subdev-selection;
> +	  <structfield>pad</structfield> references a non-existing
> +	  pad, the <structfield>which</structfield> field references a
> +	  non-existing format, or the selection target is not
> +	  supported on the given subdev pad.</para>
> +	</listitem>
> +      </varlistentry>
> +    </variablelist>
> +  </refsect1>
> +</refentry>
-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 10/33] v4l: Mark VIDIOC_SUBDEV_G_CROP and VIDIOC_SUBDEV_S_CROP obsolete
  2012-02-20  1:56 ` [PATCH v3 10/33] v4l: Mark VIDIOC_SUBDEV_G_CROP and VIDIOC_SUBDEV_S_CROP obsolete Sakari Ailus
@ 2012-02-21 16:42   ` Laurent Pinchart
  0 siblings, 0 replies; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-21 16:42 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:56:49 Sakari Ailus wrote:
> These two IOCTLS are obsoleted by VIDIOC_SUBDEV_G_SELECTION and
> VIDIOC_SUBDEV_S_SELECTION. Mark them obsolete.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 15/33] media: Add link_validate() op to check links to the sink pad
  2012-02-20  1:56 ` [PATCH v3 15/33] media: Add link_validate() op to check links to the sink pad Sakari Ailus
@ 2012-02-22 10:05   ` Laurent Pinchart
  2012-02-23 15:04     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 10:05 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:56:54 Sakari Ailus wrote:
> The purpose of the link_validate() op is to allow an entity driver to ensure
> that the properties of the pads at the both ends of the link are suitable
> for starting the pipeline. link_validate is called on sink pads on active
> links which belong to the active part of the graph.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  Documentation/media-framework.txt |   19 +++++++++++++
>  drivers/media/media-entity.c      |   53
> +++++++++++++++++++++++++++++++++++- include/media/media-entity.h      |   
> 5 ++-
>  3 files changed, 73 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/media-framework.txt
> b/Documentation/media-framework.txt index 3a0f879..0e90169 100644
> --- a/Documentation/media-framework.txt
> +++ b/Documentation/media-framework.txt
> @@ -335,6 +335,9 @@ the media_entity pipe field.
>  Calls to media_entity_pipeline_start() can be nested. The pipeline pointer
> must be identical for all nested calls to the function.
> 
> +media_entity_pipeline_start() may return an error. In that case, it will
> +clean up any the changes it did by itself.
> +
>  When stopping the stream, drivers must notify the entities with
> 
>  	media_entity_pipeline_stop(struct media_entity *entity);
> @@ -351,3 +354,19 @@ If other operations need to be disallowed on streaming
> entities (such as changing entities configuration parameters) drivers can
> explicitly check the media_entity stream_count field to find out if an
> entity is streaming. This operation must be done with the media_device
> graph_mutex held.
> +
> +
> +Link validation
> +---------------
> +
> +Link validation is performed from media_entity_pipeline_start() for any

s/from/by/ ?

> +entity which has sink pads in the pipeline. The
> +media_entity::link_validate() callback is used for that purpose. In
> +link_validate() callback, entity driver should check that the properties of
> +the source pad of the connected entity and its own sink pad match. It is up
> +to the type of the entity (and in the end, the properties of the hardware)
> +what matching actually means.
> +
> +Subsystems should facilitate link validation by providing subsystem
> specific
> +helper functions to provide easy access for commonly needed information,
> and
> +in the end provide a way to use driver-specific callbacks.
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 056138f..678ec07 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -214,23 +214,72 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
>   * pipeline pointer must be identical for all nested calls to
>   * media_entity_pipeline_start().
>   */
> -void media_entity_pipeline_start(struct media_entity *entity,
> -				 struct media_pipeline *pipe)
> +__must_check int media_entity_pipeline_start(struct media_entity *entity,
> +					     struct media_pipeline *pipe)
>  {
>  	struct media_device *mdev = entity->parent;
>  	struct media_entity_graph graph;
> +	struct media_entity *entity_err = entity;
> +	int ret = 0;
> 
>  	mutex_lock(&mdev->graph_mutex);
> 
>  	media_entity_graph_walk_start(&graph, entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> +		int i;
> +

entity->num_link is unsigned, what about making i an unsigned int ?

>  		entity->stream_count++;
>  		WARN_ON(entity->pipe && entity->pipe != pipe);
>  		entity->pipe = pipe;
> +
> +		/* Already streaming --- no need to check. */
> +		if (entity->stream_count > 1)
> +			continue;
> +
> +		if (!entity->ops || !entity->ops->link_validate)
> +			continue;
> +
> +		for (i = 0; i < entity->num_links; i++) {
> +			struct media_link *link = &entity->links[i];
> +
> +			/* Is this pad part of an enabled link? */
> +			if ((link->flags & MEDIA_LNK_FL_ENABLED)
> +			    != MEDIA_LNK_FL_ENABLED)

Just nickpicking, if you wrote it

			if (!(link->flags & MEDIA_LNK_FL_ENABLED))

it would fit on a single line :-)

> +				continue;
> +
> +			/* Are we the sink or not? */
> +			if (link->sink->entity != entity)
> +				continue;
> +
> +			ret = entity->ops->link_validate(link);
> +			if (ret < 0 && ret != -ENOIOCTLCMD)
> +				break;

You could goto error directly here, this would avoid checking the ret value 
after the loop, and you could also avoid initializing ret to 0.

> +		}
> +		if (ret < 0 && ret != -ENOIOCTLCMD)
> +			goto error;
>  	}
> 
>  	mutex_unlock(&mdev->graph_mutex);
> +
> +	return 0;
> +
> +error:
> +	/*
> +	 * Link validation on graph failed. We revert what we did and
> +	 * return the error.
> +	 */
> +	media_entity_graph_walk_start(&graph, entity_err);
> +	do {
> +		entity_err = media_entity_graph_walk_next(&graph);
> +		entity_err->stream_count--;
> +		if (entity_err->stream_count == 0)
> +			entity_err->pipe = NULL;
> +	} while (entity_err != entity);
> +
> +	mutex_unlock(&mdev->graph_mutex);
> +
> +	return ret;
>  }
>  EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 29e7bba..0c16f51 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -46,6 +46,7 @@ struct media_entity_operations {
>  	int (*link_setup)(struct media_entity *entity,
>  			  const struct media_pad *local,
>  			  const struct media_pad *remote, u32 flags);
> +	int (*link_validate)(struct media_link *link);
>  };
> 
>  struct media_entity {
> @@ -140,8 +141,8 @@ void media_entity_graph_walk_start(struct
> media_entity_graph *graph, struct media_entity *entity);
>  struct media_entity *
>  media_entity_graph_walk_next(struct media_entity_graph *graph);
> -void media_entity_pipeline_start(struct media_entity *entity,
> -		struct media_pipeline *pipe);
> +__must_check int media_entity_pipeline_start(struct media_entity *entity,
> +					     struct media_pipeline *pipe);
>  void media_entity_pipeline_stop(struct media_entity *entity);
> 
>  #define media_entity_call(entity, operation, args...)			\

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 16/33] v4l: Improve sub-device documentation for pad ops
  2012-02-20  1:56 ` [PATCH v3 16/33] v4l: Improve sub-device documentation for pad ops Sakari Ailus
@ 2012-02-22 10:06   ` Laurent Pinchart
  0 siblings, 0 replies; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 10:06 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:56:55 Sakari Ailus wrote:
> Document that format related configuration is done through pad ops in case
> the driver does use the media framework.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 17/33] v4l: Implement v4l2_subdev_link_validate()
  2012-02-20  1:56 ` [PATCH v3 17/33] v4l: Implement v4l2_subdev_link_validate() Sakari Ailus
@ 2012-02-22 10:14   ` Laurent Pinchart
  2012-02-23 16:07     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 10:14 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:56:56 Sakari Ailus wrote:
> v4l2_subdev_link_validate() is the default op for validating a link. In V4L2
> subdev context, it is used to call a pad op which performs the proper link
> check without much extra work.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  Documentation/video4linux/v4l2-framework.txt |   12 +++++
>  drivers/media/video/v4l2-subdev.c            |   69
> ++++++++++++++++++++++++++ include/media/v4l2-subdev.h                  |  
> 12 +++++
>  3 files changed, 93 insertions(+), 0 deletions(-)
> 
> diff --git a/Documentation/video4linux/v4l2-framework.txt
> b/Documentation/video4linux/v4l2-framework.txt index f06c563..9d341bc
> 100644
> --- a/Documentation/video4linux/v4l2-framework.txt
> +++ b/Documentation/video4linux/v4l2-framework.txt
> @@ -312,6 +312,18 @@ If the subdev driver intends to process video and
> integrate with the media framework, it must implement format related
> functionality using
>  v4l2_subdev_pad_ops instead of v4l2_subdev_video_ops.
> 
> +In that case, the subdev driver may set the link_validate field to provide
> +its own link validation function. The link validation function is called
> for +every link in the pipeline where both of the ends of the links are
> V4L2 +sub-devices. The driver is still responsible for validating the
> correctness +of the format configuration between sub-devices and video
> nodes.
> +
> +If link_validate op is not set, the default function
> +v4l2_subdev_link_validate_default() is used instead. This function ensures
> +that width, height and the media bus pixel code are equal on both source
> and +sink of the link. Subdev drivers are also free to use this function to
> +perform the checks mentioned above in addition to their own checks. +
>  A device (bridge) driver needs to register the v4l2_subdev with the
>  v4l2_device:
> 
> diff --git a/drivers/media/video/v4l2-subdev.c
> b/drivers/media/video/v4l2-subdev.c index ef27144..d2ec552 100644
> --- a/drivers/media/video/v4l2-subdev.c
> +++ b/drivers/media/video/v4l2-subdev.c
> @@ -379,6 +379,75 @@ const struct v4l2_file_operations v4l2_subdev_fops = {
>  	.poll = subdev_poll,
>  };
> 
> +#ifdef CONFIG_MEDIA_CONTROLLER
> +int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
> +				      struct media_link *link,
> +				      struct v4l2_subdev_format *source_fmt,
> +				      struct v4l2_subdev_format *sink_fmt)
> +{
> +	if (source_fmt->format.width != sink_fmt->format.width
> +	    || source_fmt->format.height != sink_fmt->format.height
> +	    || source_fmt->format.code != sink_fmt->format.code)
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate_default);
> +
> +static struct v4l2_subdev_format
> +*v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> +				      struct v4l2_subdev_format *fmt)

Why do you return a pointer to the passed struct v4l2_subdev_format instead of 
just an error code ?

> +{
> +	int rval;

I would have used ret instead of rval as that's the preferred variable name in 
this file (OK, I'm cheating, there's a single instance of ret, and I wrote 
that one ;-)).

> +
> +	switch (media_entity_type(pad->entity)) {
> +	case MEDIA_ENT_T_V4L2_SUBDEV:
> +		fmt->which = V4L2_SUBDEV_FORMAT_ACTIVE;
> +		fmt->pad = pad->index;
> +		rval = v4l2_subdev_call(media_entity_to_v4l2_subdev(
> +						pad->entity),
> +					pad, get_fmt, NULL, fmt);
> +		if (rval < 0)
> +			return NULL;
> +		return fmt;
> +	default:
> +		WARN(1, "Driver bug! Wrong media entity type %d, entity %s\n",
> +		     media_entity_type(pad->entity), pad->entity->name);
> +		/* Fall through */
> +	case MEDIA_ENT_T_DEVNODE_V4L:
> +		return NULL;
> +	}
> +}
> +
> +int v4l2_subdev_link_validate(struct media_link *link)
> +{
> +	struct v4l2_subdev *sink;
> +	struct v4l2_subdev_format _sink_fmt, _source_fmt;
> +	struct v4l2_subdev_format *sink_fmt, *source_fmt;
> +	int rval;
> +
> +	source_fmt = v4l2_subdev_link_validate_get_format(
> +		link->source, &_source_fmt);
> +	if (!source_fmt)
> +		return 0;
> +
> +	sink_fmt = v4l2_subdev_link_validate_get_format(
> +		link->sink, &_sink_fmt);
> +	if (!sink_fmt)
> +		return 0;
> +
> +	sink = media_entity_to_v4l2_subdev(link->sink->entity);
> +
> +	rval = v4l2_subdev_call(sink, pad, link_validate, link,
> +				source_fmt, sink_fmt);
> +	if (rval < 0 && rval != -ENOIOCTLCMD)
> +		return rval;
> +	return v4l2_subdev_link_validate_default(sink, link, source_fmt,
> +						 sink_fmt);

I don't think you should call v4l2_subdev_link_validate_default() if the 
link_validate operation is implemented and returns that the link is valid. The 
subdev might have weaker requirements than the default.

> +}
> +EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate);
> +#endif /* CONFIG_MEDIA_CONTROLLER */
> +
>  void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops
> *ops) {
>  	INIT_LIST_HEAD(&sd->list);
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index d48dae5..f115608 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -470,6 +470,11 @@ struct v4l2_subdev_pad_ops {
>  			     struct v4l2_subdev_selection *sel);
>  	int (*set_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
>  			     struct v4l2_subdev_selection *sel);
> +#ifdef CONFIG_MEDIA_CONTROLLER
> +	int (*link_validate)(struct v4l2_subdev *sd, struct media_link *link,
> +			     struct v4l2_subdev_format *source_fmt,
> +			     struct v4l2_subdev_format *sink_fmt);
> +#endif /* CONFIG_MEDIA_CONTROLLER */
>  };
> 
>  struct v4l2_subdev_ops {
> @@ -603,6 +608,13 @@ static inline void *v4l2_get_subdev_hostdata(const
> struct v4l2_subdev *sd) return sd->host_priv;
>  }
> 
> +#ifdef CONFIG_MEDIA_CONTROLLER
> +int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
> +				      struct media_link *link,
> +				      struct v4l2_subdev_format *source_fmt,
> +				      struct v4l2_subdev_format *sink_fmt);
> +int v4l2_subdev_link_validate(struct media_link *link);
> +#endif /* CONFIG_MEDIA_CONTROLLER */
>  void v4l2_subdev_init(struct v4l2_subdev *sd,
>  		      const struct v4l2_subdev_ops *ops);
-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 22/33] omap3isp: Assume media_entity_pipeline_start may fail
  2012-02-20  1:57 ` [PATCH v3 22/33] omap3isp: Assume media_entity_pipeline_start may fail Sakari Ailus
@ 2012-02-22 10:48   ` Laurent Pinchart
  2012-02-26  1:08     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 10:48 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:01 Sakari Ailus wrote:
> Since media_entity_pipeline_start() now does link validation, it may
> actually fail. Perform the error handling.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/media/video/omap3isp/ispvideo.c |   20 ++++++++++++--------
>  1 files changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/video/omap3isp/ispvideo.c
> b/drivers/media/video/omap3isp/ispvideo.c index c191f13..17522db 100644
> --- a/drivers/media/video/omap3isp/ispvideo.c
> +++ b/drivers/media/video/omap3isp/ispvideo.c
> @@ -993,14 +993,16 @@ isp_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type) */
>  	pipe = video->video.entity.pipe
>  	     ? to_isp_pipeline(&video->video.entity) : &video->pipe;
> -	media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
> +	ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
> +	if (ret < 0)
> +		goto err_media_entity_pipeline_start;
> 
>  	/* Verify that the currently configured format matches the output of
>  	 * the connected subdev.
>  	 */
>  	ret = isp_video_check_format(video, vfh);
>  	if (ret < 0)
> -		goto error;
> +		goto err_isp_video_check_format;
> 
>  	video->bpl_padding = ret;
>  	video->bpl_value = vfh->format.fmt.pix.bytesperline;
> @@ -1017,7 +1019,7 @@ isp_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type) } else {
>  		if (far_end == NULL) {
>  			ret = -EPIPE;
> -			goto error;
> +			goto err_isp_video_check_format;
>  		}
> 
>  		state = ISP_PIPELINE_STREAM_INPUT | ISP_PIPELINE_IDLE_INPUT;
> @@ -1032,7 +1034,7 @@ isp_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type) /* Validate the pipeline and update its state. */
>  	ret = isp_video_validate_pipeline(pipe);
>  	if (ret < 0)
> -		goto error;
> +		goto err_isp_video_check_format;
> 
>  	pipe->error = false;
> 
> @@ -1054,7 +1056,7 @@ isp_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type)
> 
>  	ret = omap3isp_video_queue_streamon(&vfh->queue);
>  	if (ret < 0)
> -		goto error;
> +		goto err_isp_video_check_format;
> 
>  	/* In sensor-to-memory mode, the stream can be started synchronously
>  	 * to the stream on command. In memory-to-memory mode, it will be
> @@ -1064,19 +1066,21 @@ isp_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type) ret = omap3isp_pipeline_set_stream(pipe,
>  					      ISP_PIPELINE_STREAM_CONTINUOUS);
>  		if (ret < 0)
> -			goto error;
> +			goto err_omap3isp_set_stream;
>  		spin_lock_irqsave(&video->queue->irqlock, flags);
>  		if (list_empty(&video->dmaqueue))
>  			video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
>  		spin_unlock_irqrestore(&video->queue->irqlock, flags);
>  	}
> 
> -error:
>  	if (ret < 0) {
> +err_omap3isp_set_stream:
>  		omap3isp_video_queue_streamoff(&vfh->queue);
> +err_isp_video_check_format:
> +		media_entity_pipeline_stop(&video->video.entity);
> +err_media_entity_pipeline_start:
>  		if (video->isp->pdata->set_constraints)
>  			video->isp->pdata->set_constraints(video->isp, false);
> -		media_entity_pipeline_stop(&video->video.entity);
>  		/* The DMA queue must be emptied here, otherwise CCDC interrupts
>  		 * that will get triggered the next time the CCDC is powered up
>  		 * will try to access buffers that might have been freed but

As you add error labels, you can remove the if (ret < 0) test and move error 
handling to a separate block. set_constraint() should be called before 
media_entity_pipeline_stop() in that case. Another option is to leave error 
handling untouched, and to return directly when media_entity_pipeline_start() 
fails (after unlocking the mutex of course).

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 25/33] omap3isp: Introduce omap3isp_get_external_info()
  2012-02-20  1:57 ` [PATCH v3 25/33] omap3isp: Introduce omap3isp_get_external_info() Sakari Ailus
@ 2012-02-22 10:55   ` Laurent Pinchart
  2012-02-26  1:09     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 10:55 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:04 Sakari Ailus wrote:
> omap3isp_get_external_info() will retrieve external subdev's bits-per-pixel
> and pixel rate for the use of other ISP subdevs at streamon time.
> omap3isp_get_external_info() is used during pipeline validation.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/media/video/omap3isp/isp.c |   48
> ++++++++++++++++++++++++++++++++++++ drivers/media/video/omap3isp/isp.h |  
>  3 ++
>  2 files changed, 51 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/media/video/omap3isp/isp.c
> b/drivers/media/video/omap3isp/isp.c index 12d5f92..89a9bf8 100644
> --- a/drivers/media/video/omap3isp/isp.c
> +++ b/drivers/media/video/omap3isp/isp.c
> @@ -353,6 +353,54 @@ void omap3isp_hist_dma_done(struct isp_device *isp)
>  	}
>  }
> 
> +int omap3isp_get_external_info(struct isp_pipeline *pipe,
> +			       struct media_link *link)
> +{
> +	struct isp_device *isp =
> +		container_of(pipe, struct isp_video, pipe)->isp;
> +	struct v4l2_subdev_format fmt;
> +	struct v4l2_ext_controls ctrls;
> +	struct v4l2_ext_control ctrl;
> +	int ret;
> +
> +	if (!pipe->external)
> +		return 0;
> +
> +	if (pipe->external_rate)
> +		return 0;
> +
> +	memset(&fmt, 0, sizeof(fmt));
> +
> +	fmt.pad = link->source->index;
> +	fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> +	ret = v4l2_subdev_call(media_entity_to_v4l2_subdev(link->sink->entity),
> +			       pad, get_fmt, NULL, &fmt);
> +	if (ret < 0)
> +		return -EPIPE;
> +
> +	pipe->external_bpp = omap3isp_video_format_info(fmt.format.code)->bpp;
> +
> +	memset(&ctrls, 0, sizeof(ctrls));
> +	memset(&ctrl, 0, sizeof(ctrl));
> +
> +	ctrl.id = V4L2_CID_PIXEL_RATE;
> +
> +	ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(ctrl.id);
> +	ctrls.count = 1;
> +	ctrls.controls = &ctrl;
> +
> +	ret = v4l2_g_ext_ctrls(pipe->external->ctrl_handler, &ctrls);
> +	if (ret < 0) {
> +		dev_warn(isp->dev, "no pixel rate control in subdev %s\n",
> +			 pipe->external->name);
> +		return ret;
> +	}
> +
> +	pipe->external_rate = ctrl.value64;
> +
> +	return 0;
> +}

What about moving this to ispvideo.c ? You could then call the function from 
isp_video_streamon() only, and make it static.

> +
>  static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
>  {
>  	static const char *name[] = {
> diff --git a/drivers/media/video/omap3isp/isp.h
> b/drivers/media/video/omap3isp/isp.h index 2e78041..8b0bc2d 100644
> --- a/drivers/media/video/omap3isp/isp.h
> +++ b/drivers/media/video/omap3isp/isp.h
> @@ -222,6 +222,9 @@ struct isp_device {
> 
>  void omap3isp_hist_dma_done(struct isp_device *isp);
> 
> +int omap3isp_get_external_info(struct isp_pipeline *pipe,
> +			       struct media_link *link);
> +
>  void omap3isp_flush(struct isp_device *isp);
> 
>  int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t
> *wait,
-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 26/33] omap3isp: Default link validation for ccp2, csi2, preview and resizer
  2012-02-20  1:57 ` [PATCH v3 26/33] omap3isp: Default link validation for ccp2, csi2, preview and resizer Sakari Ailus
@ 2012-02-22 11:01   ` Laurent Pinchart
  2012-02-25  1:34     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 11:01 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:05 Sakari Ailus wrote:
> Use default link validation for ccp2, csi2, preview and resizer. On ccp2,
> csi2 and ccdc we also collect information on external subdevs as one may be
> connected to those entities.
> 
> The CCDC link validation still must be done separately.
> 
> Also set pipe->external correctly as we go
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/media/video/omap3isp/ispccdc.c    |   23 +++++++++++++++++++++++
>  drivers/media/video/omap3isp/ispccp2.c    |   20 ++++++++++++++++++++
>  drivers/media/video/omap3isp/ispcsi2.c    |   19 +++++++++++++++++++
>  drivers/media/video/omap3isp/isppreview.c |    2 ++
>  drivers/media/video/omap3isp/ispresizer.c |    2 ++
>  drivers/media/video/omap3isp/ispvideo.c   |    4 ++++
>  6 files changed, 70 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/media/video/omap3isp/ispccdc.c
> b/drivers/media/video/omap3isp/ispccdc.c index a74a797..6aff241 100644
> --- a/drivers/media/video/omap3isp/ispccdc.c
> +++ b/drivers/media/video/omap3isp/ispccdc.c
> @@ -1999,6 +1999,27 @@ static int ccdc_set_format(struct v4l2_subdev *sd,
> struct v4l2_subdev_fh *fh, return 0;
>  }
> 
> +static int ccdc_link_validate(struct v4l2_subdev *sd,
> +			      struct media_link *link,
> +			      struct v4l2_subdev_format *source_fmt,
> +			      struct v4l2_subdev_format *sink_fmt)
> +{
> +	struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
> +	struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
> +	int rval;
> +
> +	/* We've got a parallel sensor here. */
> +	if (ccdc->input == CCDC_INPUT_PARALLEL) {
> +		pipe->external =
> +			media_entity_to_v4l2_subdev(link->source->entity);
> +		rval = omap3isp_get_external_info(pipe, link);
> +		if (rval < 0)
> +			return 0;
> +	}

Pending my comments on 25/33, this wouldn't be needed in this patch, and could 
be squashed with 27/33.

> +
> +	return 0;
> +}
> +
>  /*
>   * ccdc_init_formats - Initialize formats on all pads
>   * @sd: ISP CCDC V4L2 subdevice
> @@ -2041,6 +2062,7 @@ static const struct v4l2_subdev_pad_ops
> ccdc_v4l2_pad_ops = { .enum_frame_size = ccdc_enum_frame_size,
>  	.get_fmt = ccdc_get_format,
>  	.set_fmt = ccdc_set_format,
> +	.link_validate = ccdc_link_validate,
>  };
> 
>  /* V4L2 subdev operations */
> @@ -2150,6 +2172,7 @@ static int ccdc_link_setup(struct media_entity
> *entity, /* media operations */
>  static const struct media_entity_operations ccdc_media_ops = {
>  	.link_setup = ccdc_link_setup,
> +	.link_validate = v4l2_subdev_link_validate,
>  };
> 
>  void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
> diff --git a/drivers/media/video/omap3isp/ispccp2.c
> b/drivers/media/video/omap3isp/ispccp2.c index 70ddbf3..4fb34ee 100644
> --- a/drivers/media/video/omap3isp/ispccp2.c
> +++ b/drivers/media/video/omap3isp/ispccp2.c
> @@ -819,6 +819,24 @@ static int ccp2_set_format(struct v4l2_subdev *sd,
> struct v4l2_subdev_fh *fh, return 0;
>  }
> 
> +static int ccp2_link_validate(struct v4l2_subdev *sd, struct media_link
> *link, +			      struct v4l2_subdev_format *source_fmt,
> +			      struct v4l2_subdev_format *sink_fmt)
> +{
> +	struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
> +	struct isp_pipeline *pipe = to_isp_pipeline(&ccp2->subdev.entity);
> +	int rval;
> +
> +	pipe->external = media_entity_to_v4l2_subdev(link->source->entity);
> +	rval = omap3isp_get_external_info(pipe, link);
> +	if (rval < 0)
> +		return rval;
> +
> +	return v4l2_subdev_link_validate_default(sd, link, source_fmt,
> +						 sink_fmt);

That's the default behaviour, if omap3isp_get_external_info() is moved to 
ispvideo.c you can just leave .link_validate as NULL.

> +}
> +
> +
>  /*
>   * ccp2_init_formats - Initialize formats on all pads
>   * @sd: ISP CCP2 V4L2 subdevice
> @@ -925,6 +943,7 @@ static const struct v4l2_subdev_pad_ops ccp2_sd_pad_ops
> = { .enum_frame_size = ccp2_enum_frame_size,
>  	.get_fmt = ccp2_get_format,
>  	.set_fmt = ccp2_set_format,
> +	.link_validate = ccp2_link_validate,
>  };
> 
>  /* subdev operations */
> @@ -1021,6 +1040,7 @@ static int ccp2_link_setup(struct media_entity
> *entity, /* media operations */
>  static const struct media_entity_operations ccp2_media_ops = {
>  	.link_setup = ccp2_link_setup,
> +	.link_validate = v4l2_subdev_link_validate,
>  };
> 
>  /*
> diff --git a/drivers/media/video/omap3isp/ispcsi2.c
> b/drivers/media/video/omap3isp/ispcsi2.c index fcb5168..9313f7c 100644
> --- a/drivers/media/video/omap3isp/ispcsi2.c
> +++ b/drivers/media/video/omap3isp/ispcsi2.c
> @@ -1012,6 +1012,23 @@ static int csi2_set_format(struct v4l2_subdev *sd,
> struct v4l2_subdev_fh *fh, return 0;
>  }
> 
> +static int csi2_link_validate(struct v4l2_subdev *sd, struct media_link
> *link, +			      struct v4l2_subdev_format *source_fmt,
> +			      struct v4l2_subdev_format *sink_fmt)
> +{
> +	struct isp_csi2_device *csi2 = v4l2_get_subdevdata(sd);
> +	struct isp_pipeline *pipe = to_isp_pipeline(&csi2->subdev.entity);
> +	int rval;
> +
> +	pipe->external = media_entity_to_v4l2_subdev(link->source->entity);
> +	rval = omap3isp_get_external_info(pipe, link);
> +	if (rval < 0)
> +		return rval;
> +
> +	return v4l2_subdev_link_validate_default(sd, link, source_fmt,
> +						 sink_fmt);

Same here.

> +}
> +
>  /*
>   * csi2_init_formats - Initialize formats on all pads
>   * @sd: ISP CSI2 V4L2 subdevice
> @@ -1107,6 +1124,7 @@ static const struct v4l2_subdev_pad_ops csi2_pad_ops =
> { .enum_frame_size = csi2_enum_frame_size,
>  	.get_fmt = csi2_get_format,
>  	.set_fmt = csi2_set_format,
> +	.link_validate = csi2_link_validate,
>  };
> 
>  /* subdev operations */
> @@ -1181,6 +1199,7 @@ static int csi2_link_setup(struct media_entity
> *entity, /* media operations */
>  static const struct media_entity_operations csi2_media_ops = {
>  	.link_setup = csi2_link_setup,
> +	.link_validate = v4l2_subdev_link_validate,
>  };
> 
>  void omap3isp_csi2_unregister_entities(struct isp_csi2_device *csi2)
> diff --git a/drivers/media/video/omap3isp/isppreview.c
> b/drivers/media/video/omap3isp/isppreview.c index 6d0fb2c..c2bf500 100644
> --- a/drivers/media/video/omap3isp/isppreview.c
> +++ b/drivers/media/video/omap3isp/isppreview.c
> @@ -1981,6 +1981,7 @@ static const struct v4l2_subdev_pad_ops
> preview_v4l2_pad_ops = { .set_fmt = preview_set_format,
>  	.get_crop = preview_get_crop,
>  	.set_crop = preview_set_crop,
> +	.link_validate = v4l2_subdev_link_validate_default,

You can leave this as NULL as well.

>  };
> 
>  /* subdev operations */
> @@ -2076,6 +2077,7 @@ static int preview_link_setup(struct media_entity
> *entity, /* media operations */
>  static const struct media_entity_operations preview_media_ops = {
>  	.link_setup = preview_link_setup,
> +	.link_validate = v4l2_subdev_link_validate,
>  };
> 
>  void omap3isp_preview_unregister_entities(struct isp_prev_device *prev)
> diff --git a/drivers/media/video/omap3isp/ispresizer.c
> b/drivers/media/video/omap3isp/ispresizer.c index 6958a9e..6ce2349 100644
> --- a/drivers/media/video/omap3isp/ispresizer.c
> +++ b/drivers/media/video/omap3isp/ispresizer.c
> @@ -1532,6 +1532,7 @@ static const struct v4l2_subdev_pad_ops
> resizer_v4l2_pad_ops = { .set_fmt = resizer_set_format,
>  	.get_crop = resizer_g_crop,
>  	.set_crop = resizer_s_crop,
> +	.link_validate = v4l2_subdev_link_validate_default,

And this too.

>  };
> 
>  /* subdev operations */
> @@ -1603,6 +1604,7 @@ static int resizer_link_setup(struct media_entity
> *entity, /* media operations */
>  static const struct media_entity_operations resizer_media_ops = {
>  	.link_setup = resizer_link_setup,
> +	.link_validate = v4l2_subdev_link_validate,
>  };
> 
>  void omap3isp_resizer_unregister_entities(struct isp_res_device *res)
> diff --git a/drivers/media/video/omap3isp/ispvideo.c
> b/drivers/media/video/omap3isp/ispvideo.c index 17522db..f1c68ca 100644
> --- a/drivers/media/video/omap3isp/ispvideo.c
> +++ b/drivers/media/video/omap3isp/ispvideo.c
> @@ -993,6 +993,10 @@ isp_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type) */
>  	pipe = video->video.entity.pipe
>  	     ? to_isp_pipeline(&video->video.entity) : &video->pipe;
> +	pipe->external = NULL;
> +	pipe->external_rate = 0;
> +	pipe->external_bpp = 0;
> +
>  	ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
>  	if (ret < 0)
>  		goto err_media_entity_pipeline_start;
-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 27/33] omap3isp: Implement proper CCDC link validation, check pixel rate
  2012-02-20  1:57 ` [PATCH v3 27/33] omap3isp: Implement proper CCDC link validation, check pixel rate Sakari Ailus
@ 2012-02-22 11:11   ` Laurent Pinchart
  2012-02-25  1:42     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 11:11 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:06 Sakari Ailus wrote:
> Implement correct link validation for the CCDC. Use external_rate from
> isp_pipeline to configurat vp divisor and check that external_rate does not
> exceed our data rate limitations.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/media/video/omap3isp/ispccdc.c |   69
> +++++++++++++++++++++++++++++-- 1 files changed, 64 insertions(+), 5
> deletions(-)
> 
> diff --git a/drivers/media/video/omap3isp/ispccdc.c
> b/drivers/media/video/omap3isp/ispccdc.c index 6aff241..1555891 100644
> --- a/drivers/media/video/omap3isp/ispccdc.c
> +++ b/drivers/media/video/omap3isp/ispccdc.c
> @@ -836,8 +836,8 @@ static void ccdc_config_vp(struct isp_ccdc_device *ccdc)
> 
>  	if (pipe->input)
>  		div = DIV_ROUND_UP(l3_ick, pipe->max_rate);
> -	else if (ccdc->vpcfg.pixelclk)
> -		div = l3_ick / ccdc->vpcfg.pixelclk;
> +	else if (pipe->external_rate)
> +		div = l3_ick / pipe->external_rate;
> 
>  	div = clamp(div, 2U, max_div);
>  	fmtcfg_vp |= (div - 2) << ISPCCDC_FMTCFG_VPIF_FRQ_SHIFT;
> @@ -1749,7 +1749,18 @@ static int ccdc_set_stream(struct v4l2_subdev *sd,
> int enable) }
> 
>  	switch (enable) {
> -	case ISP_PIPELINE_STREAM_CONTINUOUS:
> +	case ISP_PIPELINE_STREAM_CONTINUOUS: {
> +		struct isp_pipeline *pipe = to_isp_pipeline(&sd->entity);
> +		unsigned int rate = UINT_MAX;
> +
> +		/*
> +		 * Check that maximum allowed rate isn't exceeded by
> +		 * the pixel rate.
> +		 */
> +		omap3isp_ccdc_max_rate(&isp->isp_ccdc, &rate);
> +		if (pipe->external_rate > rate)
> +			return -ENOSPC;
> +

What about checking this at pipeline validation time ?

>  		if (ccdc->output & CCDC_OUTPUT_MEMORY)
>  			omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
> 
> @@ -1758,6 +1769,7 @@ static int ccdc_set_stream(struct v4l2_subdev *sd, int
> enable)
> 
>  		ccdc->underrun = 0;
>  		break;
> +	}
> 
>  	case ISP_PIPELINE_STREAM_SINGLESHOT:
>  		if (ccdc->output & CCDC_OUTPUT_MEMORY &&
> @@ -1999,6 +2011,37 @@ static int ccdc_set_format(struct v4l2_subdev *sd,
> struct v4l2_subdev_fh *fh, return 0;
>  }
> 
> +/*
> + * Decide whether desired output pixel code can be obtained with
> + * the lane shifter by shifting the input pixel code.
> + * @in: input pixelcode to shifter
> + * @out: output pixelcode from shifter
> + * @additional_shift: # of bits the sensor's LSB is offset from CAMEXT[0]
> + *
> + * return true if the combination is possible
> + * return false otherwise
> + */
> +static bool ccdc_is_shiftable(enum v4l2_mbus_pixelcode in,
> +			      enum v4l2_mbus_pixelcode out,
> +			      unsigned int additional_shift)
> +{
> +	const struct isp_format_info *in_info, *out_info;
> +
> +	if (in == out)
> +		return true;
> +
> +	in_info = omap3isp_video_format_info(in);
> +	out_info = omap3isp_video_format_info(out);
> +
> +	if ((in_info->flavor == 0) || (out_info->flavor == 0))
> +		return false;
> +
> +	if (in_info->flavor != out_info->flavor)
> +		return false;
> +
> +	return in_info->bpp - out_info->bpp + additional_shift <= 6;
> +}
> +
>  static int ccdc_link_validate(struct v4l2_subdev *sd,
>  			      struct media_link *link,
>  			      struct v4l2_subdev_format *source_fmt,
> @@ -2008,13 +2051,31 @@ static int ccdc_link_validate(struct v4l2_subdev
> *sd, struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity); int
> rval;
> 
> +	/* Check if the two ends match */
> +	if (source_fmt->format.width != sink_fmt->format.width ||
> +	    source_fmt->format.height != sink_fmt->format.height)
> +		return -EPIPE;
> +
>  	/* We've got a parallel sensor here. */
>  	if (ccdc->input == CCDC_INPUT_PARALLEL) {

The lane shifter is usable with the CCP2 and CSI2 inputs as well. The 
parallel_shift value is restricted to parallel input though. Please perform 
the same check as done in isp_video_validate_pipeline().

Revies would also be easier if you removed the CCDC-specific code from 
isp_video_validate_pipeline() in this patch.

> +		struct isp_parallel_platform_data *pdata =
> +			&((struct isp_v4l2_subdevs_group *)
> +			  media_entity_to_v4l2_subdev(link->source->entity)
> +			  ->host_priv)->bus.parallel;
> +		unsigned long parallel_shift = pdata->data_lane_shift * 2;
> +		/* Lane shifter may be used to drop bits on CCDC sink pad */
> +		if (!ccdc_is_shiftable(source_fmt->format.code,
> +				       sink_fmt->format.code, parallel_shift))
> +			return -EPIPE;
> +
>  		pipe->external =
>  			media_entity_to_v4l2_subdev(link->source->entity);
>  		rval = omap3isp_get_external_info(pipe, link);
>  		if (rval < 0)
>  			return 0;
> +	} else {
> +		if (source_fmt->format.code != sink_fmt->format.code)
> +			return -EPIPE;
>  	}
> 
>  	return 0;
> @@ -2299,8 +2360,6 @@ int omap3isp_ccdc_init(struct isp_device *isp)
>  	ccdc->clamp.oblen = 0;
>  	ccdc->clamp.dcsubval = 0;
> 
> -	ccdc->vpcfg.pixelclk = 0;
> -
>  	ccdc->update = OMAP3ISP_CCDC_BLCLAMP;
>  	ccdc_apply_controls(ccdc);
-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 28/33] omap3isp: Move setting constaints above media_entity_pipeline_start
  2012-02-20  1:57 ` [PATCH v3 28/33] omap3isp: Move setting constaints above media_entity_pipeline_start Sakari Ailus
@ 2012-02-22 11:12   ` Laurent Pinchart
  2012-02-25  1:46     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 11:12 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:07 Sakari Ailus wrote:

Could you please briefly explain why this is needed ?

> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/media/video/omap3isp/ispvideo.c |   11 +++++------
>  1 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/video/omap3isp/ispvideo.c
> b/drivers/media/video/omap3isp/ispvideo.c index f1c68ca..2e4786d 100644
> --- a/drivers/media/video/omap3isp/ispvideo.c
> +++ b/drivers/media/video/omap3isp/ispvideo.c
> @@ -304,8 +304,6 @@ static int isp_video_validate_pipeline(struct
> isp_pipeline *pipe) struct v4l2_subdev *subdev;
>  	int ret;
> 
> -	pipe->max_rate = pipe->l3_ick;
> -
>  	subdev = isp_video_remote_subdev(pipe->output, NULL);
>  	if (subdev == NULL)
>  		return -EPIPE;
> @@ -997,6 +995,11 @@ isp_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type) pipe->external_rate = 0;
>  	pipe->external_bpp = 0;
> 
> +	if (video->isp->pdata->set_constraints)
> +		video->isp->pdata->set_constraints(video->isp, true);
> +	pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]);
> +	pipe->max_rate = pipe->l3_ick;
> +
>  	ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
>  	if (ret < 0)
>  		goto err_media_entity_pipeline_start;
> @@ -1031,10 +1034,6 @@ isp_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type) pipe->output = far_end;
>  	}
> 
> -	if (video->isp->pdata->set_constraints)
> -		video->isp->pdata->set_constraints(video->isp, true);
> -	pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]);
> -
>  	/* Validate the pipeline and update its state. */
>  	ret = isp_video_validate_pipeline(pipe);
>  	if (ret < 0)
-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 29/33] omap3isp: Configure CSI-2 phy based on platform data
  2012-02-20  1:57 ` [PATCH v3 29/33] omap3isp: Configure CSI-2 phy based on platform data Sakari Ailus
@ 2012-02-22 11:21   ` Laurent Pinchart
  2012-02-25  1:49     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 11:21 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:08 Sakari Ailus wrote:
> Configure CSI-2 phy based on platform data in the ISP driver. For that, the
> new V4L2_CID_IMAGE_SOURCE_PIXEL_RATE control is used. Previously the same
> was configured from the board code.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>

[snip]

> diff --git a/drivers/media/video/omap3isp/ispcsiphy.c
> b/drivers/media/video/omap3isp/ispcsiphy.c index 5be37ce..902477d 100644
> --- a/drivers/media/video/omap3isp/ispcsiphy.c
> +++ b/drivers/media/video/omap3isp/ispcsiphy.c
> @@ -28,41 +28,13 @@
>  #include <linux/device.h>
>  #include <linux/regulator/consumer.h>
> 
> +#include "../../../../arch/arm/mach-omap2/control.h"

I expect you will have to fix that somehow, but as far as I'm concerned,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 30/33] omap3isp: Add resizer data rate configuration to resizer_set_stream
  2012-02-20  1:57 ` [PATCH v3 30/33] omap3isp: Add resizer data rate configuration to resizer_set_stream Sakari Ailus
@ 2012-02-22 11:24   ` Laurent Pinchart
  2012-02-26  1:10     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 11:24 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:09 Sakari Ailus wrote:
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/media/video/omap3isp/ispresizer.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/media/video/omap3isp/ispresizer.c
> b/drivers/media/video/omap3isp/ispresizer.c index 6ce2349..81e1bc4 100644
> --- a/drivers/media/video/omap3isp/ispresizer.c
> +++ b/drivers/media/video/omap3isp/ispresizer.c
> @@ -1147,9 +1147,13 @@ static int resizer_set_stream(struct v4l2_subdev *sd,
> int enable) struct device *dev = to_device(res);
> 
>  	if (res->state == ISP_PIPELINE_STREAM_STOPPED) {
> +		struct isp_pipeline *pipe = to_isp_pipeline(&sd->entity);
> +
>  		if (enable == ISP_PIPELINE_STREAM_STOPPED)
>  			return 0;
> 
> +		omap3isp_resizer_max_rate(res, &pipe->max_rate);
> +
>  		omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_RESIZER);
>  		resizer_configure(res);
>  		resizer_print_status(res);

What about moving this to link validation ?

Could you please also remove it from isp_video_validate_pipeline() in this 
patch ? It would make review easier.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 31/33] omap3isp: Remove isp_validate_pipeline and other old stuff
  2012-02-20  1:57 ` [PATCH v3 31/33] omap3isp: Remove isp_validate_pipeline and other old stuff Sakari Ailus
@ 2012-02-22 11:26   ` Laurent Pinchart
  2012-02-25  1:52     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-22 11:26 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:10 Sakari Ailus wrote:
> Remove isp_set_pixel_clock().
> 
> Remove set_pixel_clock() callback from platform callbacks since the same
> information is now passed to the ISP driver by other means.
>
> Remove struct ispccdc_vp since the only field in this structure, pixelclk,
> is no longer used.
> 
> Remove isp_video_is_shiftable() --- this will live on as ccdc_is_shiftable
> in ispccdc.c.

Could you please move those changes to the patches where you add them to the 
other modules ?

> Remove isp_video_validate_pipeline(). Pipeline validation is now split into
> appropriate subdevs, so this can be removed.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/media/video/omap3isp/isp.c      |   14 ---
>  drivers/media/video/omap3isp/isp.h      |    1 -
>  drivers/media/video/omap3isp/ispccdc.h  |   10 --
>  drivers/media/video/omap3isp/ispvideo.c |  139
> ------------------------------- 4 files changed, 0 insertions(+), 164
> deletions(-)
> 
> diff --git a/drivers/media/video/omap3isp/isp.c
> b/drivers/media/video/omap3isp/isp.c index 89a9bf8..4b2290d 100644
> --- a/drivers/media/video/omap3isp/isp.c
> +++ b/drivers/media/video/omap3isp/isp.c
> @@ -329,19 +329,6 @@ void omap3isp_configure_bridge(struct isp_device *isp,
>  	isp_reg_writel(isp, ispctrl_val, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
>  }
> 
> -/**
> - * isp_set_pixel_clock - Configures the ISP pixel clock
> - * @isp: OMAP3 ISP device
> - * @pixelclk: Average pixel clock in Hz
> - *
> - * Set the average pixel clock required by the sensor. The ISP will use the
> - * lowest possible memory bandwidth settings compatible with the clock. -
> **/
> -static void isp_set_pixel_clock(struct isp_device *isp, unsigned int
> pixelclk) -{
> -	isp->isp_ccdc.vpcfg.pixelclk = pixelclk;
> -}
> -
>  void omap3isp_hist_dma_done(struct isp_device *isp)
>  {
>  	if (omap3isp_ccdc_busy(&isp->isp_ccdc) ||
> @@ -2116,7 +2103,6 @@ static int isp_probe(struct platform_device *pdev)
> 
>  	isp->autoidle = autoidle;
>  	isp->platform_cb.set_xclk = isp_set_xclk;
> -	isp->platform_cb.set_pixel_clock = isp_set_pixel_clock;
> 
>  	mutex_init(&isp->isp_mutex);
>  	spin_lock_init(&isp->stat_lock);
> diff --git a/drivers/media/video/omap3isp/isp.h
> b/drivers/media/video/omap3isp/isp.h index 43a1b16..90f3743 100644
> --- a/drivers/media/video/omap3isp/isp.h
> +++ b/drivers/media/video/omap3isp/isp.h
> @@ -126,7 +126,6 @@ struct isp_reg {
> 
>  struct isp_platform_callback {
>  	u32 (*set_xclk)(struct isp_device *isp, u32 xclk, u8 xclksel);
> -	void (*set_pixel_clock)(struct isp_device *isp, unsigned int pixelclk);
>  };
> 
>  /*
> diff --git a/drivers/media/video/omap3isp/ispccdc.h
> b/drivers/media/video/omap3isp/ispccdc.h index 6d0264b..e570abe 100644
> --- a/drivers/media/video/omap3isp/ispccdc.h
> +++ b/drivers/media/video/omap3isp/ispccdc.h
> @@ -80,14 +80,6 @@ struct ispccdc_syncif {
>  	u8 bt_r656_en;
>  };
> 
> -/*
> - * struct ispccdc_vp - Structure for Video Port parameters
> - * @pixelclk: Input pixel clock in Hz
> - */
> -struct ispccdc_vp {
> -	unsigned int pixelclk;
> -};
> -
>  enum ispccdc_lsc_state {
>  	LSC_STATE_STOPPED = 0,
>  	LSC_STATE_STOPPING = 1,
> @@ -161,7 +153,6 @@ struct ispccdc_lsc {
>   * @update: Bitmask of controls to update during the next interrupt
>   * @shadow_update: Controls update in progress by userspace
>   * @syncif: Interface synchronization configuration
> - * @vpcfg: Video port configuration
>   * @underrun: A buffer underrun occurred and a new buffer has been queued
>   * @state: Streaming state
>   * @lock: Serializes shadow_update with interrupt handler
> @@ -190,7 +181,6 @@ struct isp_ccdc_device {
>  	unsigned int shadow_update;
> 
>  	struct ispccdc_syncif syncif;
> -	struct ispccdc_vp vpcfg;
> 
>  	unsigned int underrun:1;
>  	enum isp_pipeline_stream_state state;
> diff --git a/drivers/media/video/omap3isp/ispvideo.c
> b/drivers/media/video/omap3isp/ispvideo.c index 2e4786d..07832c8 100644
> --- a/drivers/media/video/omap3isp/ispvideo.c
> +++ b/drivers/media/video/omap3isp/ispvideo.c
> @@ -130,37 +130,6 @@ omap3isp_video_format_info(enum v4l2_mbus_pixelcode
> code) }
> 
>  /*
> - * Decide whether desired output pixel code can be obtained with
> - * the lane shifter by shifting the input pixel code.
> - * @in: input pixelcode to shifter
> - * @out: output pixelcode from shifter
> - * @additional_shift: # of bits the sensor's LSB is offset from CAMEXT[0]
> - *
> - * return true if the combination is possible
> - * return false otherwise
> - */
> -static bool isp_video_is_shiftable(enum v4l2_mbus_pixelcode in,
> -		enum v4l2_mbus_pixelcode out,
> -		unsigned int additional_shift)
> -{
> -	const struct isp_format_info *in_info, *out_info;
> -
> -	if (in == out)
> -		return true;
> -
> -	in_info = omap3isp_video_format_info(in);
> -	out_info = omap3isp_video_format_info(out);
> -
> -	if ((in_info->flavor == 0) || (out_info->flavor == 0))
> -		return false;
> -
> -	if (in_info->flavor != out_info->flavor)
> -		return false;
> -
> -	return in_info->bpp - out_info->bpp + additional_shift <= 6;
> -}
> -
> -/*
>   * isp_video_mbus_to_pix - Convert v4l2_mbus_framefmt to v4l2_pix_format
>   * @video: ISP video instance
>   * @mbus: v4l2_mbus_framefmt format (input)
> @@ -284,107 +253,6 @@ isp_video_far_end(struct isp_video *video)
>  	return far_end;
>  }
> 
> -/*
> - * Validate a pipeline by checking both ends of all links for format
> - * discrepancies.
> - *
> - * Compute the minimum time per frame value as the maximum of time per
> frame - * limits reported by every block in the pipeline.
> - *
> - * Return 0 if all formats match, or -EPIPE if at least one link is found
> with - * different formats on its two ends or if the pipeline doesn't start
> with a - * video source (either a subdev with no input pad, or a non-subdev
> entity). - */
> -static int isp_video_validate_pipeline(struct isp_pipeline *pipe)
> -{
> -	struct isp_device *isp = pipe->output->isp;
> -	struct v4l2_subdev_format fmt_source;
> -	struct v4l2_subdev_format fmt_sink;
> -	struct media_pad *pad;
> -	struct v4l2_subdev *subdev;
> -	int ret;
> -
> -	subdev = isp_video_remote_subdev(pipe->output, NULL);
> -	if (subdev == NULL)
> -		return -EPIPE;
> -
> -	while (1) {
> -		unsigned int shifter_link;
> -		/* Retrieve the sink format */
> -		pad = &subdev->entity.pads[0];
> -		if (!(pad->flags & MEDIA_PAD_FL_SINK))
> -			break;
> -
> -		fmt_sink.pad = pad->index;
> -		fmt_sink.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> -		ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt_sink);
> -		if (ret < 0 && ret != -ENOIOCTLCMD)
> -			return -EPIPE;
> -
> -		/* Update the maximum frame rate */
> -		if (subdev == &isp->isp_res.subdev)
> -			omap3isp_resizer_max_rate(&isp->isp_res,
> -						  &pipe->max_rate);
> -
> -		/* Check ccdc maximum data rate when data comes from sensor
> -		 * TODO: Include ccdc rate in pipe->max_rate and compare the
> -		 *       total pipe rate with the input data rate from sensor.
> -		 */
> -		if (subdev == &isp->isp_ccdc.subdev && pipe->input == NULL) {
> -			unsigned int rate = UINT_MAX;
> -
> -			omap3isp_ccdc_max_rate(&isp->isp_ccdc, &rate);
> -			if (isp->isp_ccdc.vpcfg.pixelclk > rate)
> -				return -ENOSPC;
> -		}
> -
> -		/* If sink pad is on CCDC, the link has the lane shifter
> -		 * in the middle of it. */
> -		shifter_link = subdev == &isp->isp_ccdc.subdev;
> -
> -		/* Retrieve the source format. Return an error if no source
> -		 * entity can be found, and stop checking the pipeline if the
> -		 * source entity isn't a subdev.
> -		 */
> -		pad = media_entity_remote_source(pad);
> -		if (pad == NULL)
> -			return -EPIPE;
> -
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> -			break;
> -
> -		subdev = media_entity_to_v4l2_subdev(pad->entity);
> -
> -		fmt_source.pad = pad->index;
> -		fmt_source.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> -		ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt_source);
> -		if (ret < 0 && ret != -ENOIOCTLCMD)
> -			return -EPIPE;
> -
> -		/* Check if the two ends match */
> -		if (fmt_source.format.width != fmt_sink.format.width ||
> -		    fmt_source.format.height != fmt_sink.format.height)
> -			return -EPIPE;
> -
> -		if (shifter_link) {
> -			unsigned int parallel_shift = 0;
> -			if (isp->isp_ccdc.input == CCDC_INPUT_PARALLEL) {
> -				struct isp_parallel_platform_data *pdata =
> -					&((struct isp_v4l2_subdevs_group *)
> -					      subdev->host_priv)->bus.parallel;
> -				parallel_shift = pdata->data_lane_shift * 2;
> -			}
> -			if (!isp_video_is_shiftable(fmt_source.format.code,
> -						fmt_sink.format.code,
> -						parallel_shift))
> -				return -EPIPE;
> -		} else if (fmt_source.format.code != fmt_sink.format.code)
> -			return -EPIPE;
> -	}
> -
> -	return 0;
> -}
> -
>  static int
>  __isp_video_get_format(struct isp_video *video, struct v4l2_format *format)
> {
> @@ -1034,13 +902,6 @@ isp_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type) pipe->output = far_end;
>  	}
> 
> -	/* Validate the pipeline and update its state. */
> -	ret = isp_video_validate_pipeline(pipe);
> -	if (ret < 0)
> -		goto err_isp_video_check_format;
> -
> -	pipe->error = false;
> -
>  	spin_lock_irqsave(&pipe->lock, flags);
>  	pipe->state &= ~ISP_PIPELINE_STREAM;
>  	pipe->state |= state;
-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs
  2012-02-21 14:34   ` Laurent Pinchart
@ 2012-02-23  5:49     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-23  5:49 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.

And thank you for the review!!!

> On Monday 20 February 2012 03:56:43 Sakari Ailus wrote:
>> Add support for VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION
>> IOCTLs. They replace functionality provided by VIDIOC_SUBDEV_S_CROP and
>> VIDIOC_SUBDEV_G_CROP IOCTLs and also add new functionality (composing).
>>
>> VIDIOC_SUBDEV_G_CROP and VIDIOC_SUBDEV_S_CROP continue to be supported.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  drivers/media/video/v4l2-subdev.c |   34 +++++++++++++++++++++---------
>>  include/linux/v4l2-subdev.h       |   41
>> +++++++++++++++++++++++++++++++++++++ include/media/v4l2-subdev.h       |  
>> 21 +++++++++++++++---
>>  3 files changed, 82 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/media/video/v4l2-subdev.c
>> b/drivers/media/video/v4l2-subdev.c index 6fe88e9..30c7fd9 100644
>> --- a/drivers/media/video/v4l2-subdev.c
>> +++ b/drivers/media/video/v4l2-subdev.c
>> @@ -35,14 +35,9 @@
>>  static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev
>> *sd) {
>>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
>> -	/* Allocate try format and crop in the same memory block */
>> -	fh->try_fmt = kzalloc((sizeof(*fh->try_fmt) + sizeof(*fh->try_crop))
>> -			      * sd->entity.num_pads, GFP_KERNEL);
>> -	if (fh->try_fmt == NULL)
>> +	fh->pad = kzalloc(sizeof(*fh->pad) * sd->entity.num_pads, GFP_KERNEL);
>> +	if (fh->pad == NULL)
>>  		return -ENOMEM;
>> -
>> -	fh->try_crop = (struct v4l2_rect *)
>> -		(fh->try_fmt + sd->entity.num_pads);
>>  #endif
>>  	return 0;
>>  }
>> @@ -50,9 +45,8 @@ static int subdev_fh_init(struct v4l2_subdev_fh *fh,
>> struct v4l2_subdev *sd) static void subdev_fh_free(struct v4l2_subdev_fh
>> *fh)
>>  {
>>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
>> -	kfree(fh->try_fmt);
>> -	fh->try_fmt = NULL;
>> -	fh->try_crop = NULL;
>> +	kfree(fh->pad);
>> +	fh->pad = NULL;
>>  #endif
>>  }
>>
>> @@ -293,6 +287,26 @@ static long subdev_do_ioctl(struct file *file, unsigned
>> int cmd, void *arg) return v4l2_subdev_call(sd, pad, enum_frame_interval,
>> subdev_fh, fie);
>>  	}
>> +
>> +	case VIDIOC_SUBDEV_G_SELECTION: {
>> +		struct v4l2_subdev_selection *sel = arg;
>> +
>> +		if (sel->pad >= sd->entity.num_pads)
>> +			return -EINVAL;
> 
> Shouldn't you verify the which field as well, as done for the crop ioctls ?

I thought I got a comment on that and fixed it, but apparently not. :-P
Thanks for pointing this out.

>> +
>> +		return v4l2_subdev_call(
>> +			sd, pad, get_selection, subdev_fh, sel);
>> +	}
>> +
>> +	case VIDIOC_SUBDEV_S_SELECTION: {
>> +		struct v4l2_subdev_selection *sel = arg;
>> +

Fixed it here as well...

>> +		if (sel->pad >= sd->entity.num_pads)
>> +			return -EINVAL;
>> +
>> +		return v4l2_subdev_call(
>> +			sd, pad, set_selection, subdev_fh, sel);
>> +	}
>>  #endif
>>  	default:
>>  		return v4l2_subdev_call(sd, core, ioctl, cmd, arg);
>> diff --git a/include/linux/v4l2-subdev.h b/include/linux/v4l2-subdev.h
>> index ed29cbb..6c84390 100644
>> --- a/include/linux/v4l2-subdev.h
>> +++ b/include/linux/v4l2-subdev.h
>> @@ -123,6 +123,43 @@ struct v4l2_subdev_frame_interval_enum {
>>  	__u32 reserved[9];
>>  };
>>
>> +#define V4L2_SUBDEV_SEL_FLAG_SIZE_GE			(1 << 0)
>> +#define V4L2_SUBDEV_SEL_FLAG_SIZE_LE			(1 << 1)
>> +#define V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG		(1 << 2)
>> +
>> +/* active cropping area */
>> +#define V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE			0x0000
>> +/* cropping bounds */
>> +#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS			0x0002
>> +/* current composing area */
>> +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE		0x0100
>> +/* composing bounds */
>> +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS		0x0102
>> +
>> +
>> +/**
>> + * struct v4l2_subdev_selection - selection info
>> + *
>> + * @which: either V4L2_SUBDEV_FORMAT_ACTIVE or V4L2_SUBDEV_FORMAT_TRY
>> + * @pad: pad number, as reported by the media API
>> + * @target: selection target, used to choose one of possible rectangles
>> + * @flags: constraint flags
>> + * @r: coordinates of the selection window
>> + * @reserved: for future use, rounds structure size to 64 bytes, set to
>> zero
> 
> I'm not sure we need to mention that the reserved fields round the structure 
> size to 64 bytes.

Fixed.

>> + *
>> + * Hardware may use multiple helper windows to process a video stream.
>> + * The structure is used to exchange this selection areas between
>> + * an application and a driver.
>> + */
>> +struct v4l2_subdev_selection {
>> +	__u32 which;
>> +	__u32 pad;
>> +	__u32 target;
>> +	__u32 flags;
>> +	struct v4l2_rect r;
>> +	__u32 reserved[8];
>> +};
>> +
>>  #define VIDIOC_SUBDEV_G_FMT	_IOWR('V',  4, struct v4l2_subdev_format)
>>  #define VIDIOC_SUBDEV_S_FMT	_IOWR('V',  5, struct v4l2_subdev_format)
>>  #define VIDIOC_SUBDEV_G_FRAME_INTERVAL \
>> @@ -137,5 +174,9 @@ struct v4l2_subdev_frame_interval_enum {
>>  			_IOWR('V', 75, struct v4l2_subdev_frame_interval_enum)
>>  #define VIDIOC_SUBDEV_G_CROP	_IOWR('V', 59, struct v4l2_subdev_crop)
>>  #define VIDIOC_SUBDEV_S_CROP	_IOWR('V', 60, struct v4l2_subdev_crop)
>> +#define VIDIOC_SUBDEV_G_SELECTION \
>> +	_IOWR('V', 61, struct v4l2_subdev_selection)
>> +#define VIDIOC_SUBDEV_S_SELECTION \
>> +	_IOWR('V', 62, struct v4l2_subdev_selection)
>>
>>  #endif
>> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
>> index f0f3358..feab950 100644
>> --- a/include/media/v4l2-subdev.h
>> +++ b/include/media/v4l2-subdev.h
>> @@ -466,6 +466,10 @@ struct v4l2_subdev_pad_ops {
>>  		       struct v4l2_subdev_crop *crop);
>>  	int (*get_crop)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
>>  		       struct v4l2_subdev_crop *crop);
>> +	int (*get_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
>> +			     struct v4l2_subdev_selection *sel);
>> +	int (*set_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
>> +			     struct v4l2_subdev_selection *sel);
>>  };
>>
>>  struct v4l2_subdev_ops {
>> @@ -549,8 +553,11 @@ struct v4l2_subdev {
>>  struct v4l2_subdev_fh {
>>  	struct v4l2_fh vfh;
>>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
>> -	struct v4l2_mbus_framefmt *try_fmt;
>> -	struct v4l2_rect *try_crop;
>> +	struct {
>> +		struct v4l2_mbus_framefmt try_fmt;
>> +		struct v4l2_rect try_crop;
>> +		struct v4l2_rect try_compose;
>> +	} *pad;
>>  #endif
>>  };
>>
>> @@ -561,13 +568,19 @@ struct v4l2_subdev_fh {
>>  static inline struct v4l2_mbus_framefmt *
>>  v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
>>  {
>> -	return &fh->try_fmt[pad];
>> +	return &fh->pad[pad].try_fmt;
>>  }
>>
>>  static inline struct v4l2_rect *
>>  v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
>>  {
>> -	return &fh->try_crop[pad];
>> +	return &fh->pad[pad].try_crop;
>> +}
>> +
>> +static inline struct v4l2_rect *
>> +v4l2_subdev_get_try_compose(struct v4l2_subdev_fh *fh, unsigned int pad)
>> +{
>> +	return &fh->pad[pad].try_compose;
>>  }
>>  #endif


-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 06/33] v4l: Check pad number in get try pointer functions
  2012-02-21 14:42   ` Laurent Pinchart
@ 2012-02-23  5:57     ` Sakari Ailus
  2012-02-27  0:33       ` Laurent Pinchart
  0 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-23  5:57 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Thanks for the patch.

Thanks for the review! :-)

> On Monday 20 February 2012 03:56:45 Sakari Ailus wrote:
>> Unify functions to get try pointers and validate the pad number accessed by
>> the user.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  include/media/v4l2-subdev.h |   31 ++++++++++++++-----------------
>>  1 files changed, 14 insertions(+), 17 deletions(-)
>>
>> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
>> index bcaf6b8..d48dae5 100644
>> --- a/include/media/v4l2-subdev.h
>> +++ b/include/media/v4l2-subdev.h
>> @@ -565,23 +565,20 @@ struct v4l2_subdev_fh {
>>  	container_of(fh, struct v4l2_subdev_fh, vfh)
>>
>>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
>> -static inline struct v4l2_mbus_framefmt *
>> -v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
>> -{
>> -	return &fh->pad[pad].try_fmt;
>> -}
>> -
>> -static inline struct v4l2_rect *
>> -v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
>> -{
>> -	return &fh->pad[pad].try_crop;
>> -}
>> -
>> -static inline struct v4l2_rect *
>> -v4l2_subdev_get_try_compose(struct v4l2_subdev_fh *fh, unsigned int pad)
>> -{
>> -	return &fh->pad[pad].try_compose;
>> -}
>> +#define __V4L2_SUBDEV_MK_GET_TRY(rtype, fun_name, field_name)		\
>> +	static inline struct rtype *					\
>> +	v4l2_subdev_get_try_##fun_name(struct v4l2_subdev_fh *fh,	\
>> +				       unsigned int pad)		\
>> +	{								\
>> +		if (unlikely(pad > vdev_to_v4l2_subdev(			\
>> +				     fh->vfh.vdev->entity.num_pads)	\
>> +			return NULL;					\
>> +		return &fh->pad[pad].field_name;			\
>> +	}
>> +
>> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, format, try_fmt)
>> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_compose)
>> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, compose, try_compose)
>>  #endif
>>
>>  extern const struct v4l2_file_operations v4l2_subdev_fops;
> 
> I'm not sure if this is a good idea. Drivers usually access the active and try 
> formats/rectangles through a single function that checks the which argument 
> and returns the active format/rectangle from the driver-specific device 
> structure, or calls v4l2_subdev_get_try_*. The pad number should be checked 
> for both active and try formats/rectangles, as both can result in accessing a 
> wrong memory location.
> 
> Furthermore, only in-kernel access to the active/try formats/rectangles need 
> to be checked, as the pad argument to subdev ioctls are already checked in 
> v4l2-subdev.c. If your goal is to catch buggy kernel code here, a BUG_ON might 
> be more suitable (although accessing the NULL pointer would result in an oops 
> anyway).

This was basically the reason for the memory corryption issue I had some
time ago with the driver. The drivers (typically, I guess) need to
access this data also to validate the following selection rectangles
inside the subdev.

The active rectangles are also driver's own property so it's the matter
of driver to access them properly. In principle the same goes for the
try rectangles, but the fact still is that this patch would have caught
the bad accesses right at the time they were made. I feel it's just too
easy to give the function a faulty pad number --- see the SMIA++ driver
for an example.

I'd prefer to keep this change, and also I'm fine with doing BUG()
instead of returning NULL.

Cheers,

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs
  2012-02-21 16:15   ` Laurent Pinchart
@ 2012-02-23  6:01     ` Sakari Ailus
  2012-02-27  0:22       ` Laurent Pinchart
  0 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-23  6:01 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> [snip]
> 
>> +/* active cropping area */
>> +#define V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE			0x0000
>> +/* cropping bounds */
>> +#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS			0x0002
>> +/* current composing area */
>> +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE		0x0100
>> +/* composing bounds */
> 
> I'm not sure if ACTIVE is a good name here. It sounds confusing as we already 
> have V4L2_SUBDEV_FORMAT_ACTIVE.

We are using V4L2_SEL_TGT_COMPOSE_ACTIVE on V4L2 nodes already --- the
name I'm using here just mirrors the naming on V4L2 device nodes. If I
choose a different name here, some of that analogy is lost.

That said, I'm not against changing this but the equivalent change
should then be made on V4L2 selection API for consistency.

Kind regards,

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 15/33] media: Add link_validate() op to check links to the sink pad
  2012-02-22 10:05   ` Laurent Pinchart
@ 2012-02-23 15:04     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-23 15:04 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent

Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.

Thanks for the review!

> On Monday 20 February 2012 03:56:54 Sakari Ailus wrote:
>> The purpose of the link_validate() op is to allow an entity driver to ensure
>> that the properties of the pads at the both ends of the link are suitable
>> for starting the pipeline. link_validate is called on sink pads on active
>> links which belong to the active part of the graph.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  Documentation/media-framework.txt |   19 +++++++++++++
>>  drivers/media/media-entity.c      |   53
>> +++++++++++++++++++++++++++++++++++- include/media/media-entity.h      |   
>> 5 ++-
>>  3 files changed, 73 insertions(+), 4 deletions(-)
>>
>> diff --git a/Documentation/media-framework.txt
>> b/Documentation/media-framework.txt index 3a0f879..0e90169 100644
>> --- a/Documentation/media-framework.txt
>> +++ b/Documentation/media-framework.txt
>> @@ -335,6 +335,9 @@ the media_entity pipe field.
>>  Calls to media_entity_pipeline_start() can be nested. The pipeline pointer
>> must be identical for all nested calls to the function.
>>
>> +media_entity_pipeline_start() may return an error. In that case, it will
>> +clean up any the changes it did by itself.
>> +
>>  When stopping the stream, drivers must notify the entities with
>>
>>  	media_entity_pipeline_stop(struct media_entity *entity);
>> @@ -351,3 +354,19 @@ If other operations need to be disallowed on streaming
>> entities (such as changing entities configuration parameters) drivers can
>> explicitly check the media_entity stream_count field to find out if an
>> entity is streaming. This operation must be done with the media_device
>> graph_mutex held.
>> +
>> +
>> +Link validation
>> +---------------
>> +
>> +Link validation is performed from media_entity_pipeline_start() for any
> 
> s/from/by/ ?
> 
>> +entity which has sink pads in the pipeline. The
>> +media_entity::link_validate() callback is used for that purpose. In
>> +link_validate() callback, entity driver should check that the properties of
>> +the source pad of the connected entity and its own sink pad match. It is up
>> +to the type of the entity (and in the end, the properties of the hardware)
>> +what matching actually means.
>> +
>> +Subsystems should facilitate link validation by providing subsystem
>> specific
>> +helper functions to provide easy access for commonly needed information,
>> and
>> +in the end provide a way to use driver-specific callbacks.
>> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
>> index 056138f..678ec07 100644
>> --- a/drivers/media/media-entity.c
>> +++ b/drivers/media/media-entity.c
>> @@ -214,23 +214,72 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
>>   * pipeline pointer must be identical for all nested calls to
>>   * media_entity_pipeline_start().
>>   */
>> -void media_entity_pipeline_start(struct media_entity *entity,
>> -				 struct media_pipeline *pipe)
>> +__must_check int media_entity_pipeline_start(struct media_entity *entity,
>> +					     struct media_pipeline *pipe)
>>  {
>>  	struct media_device *mdev = entity->parent;
>>  	struct media_entity_graph graph;
>> +	struct media_entity *entity_err = entity;
>> +	int ret = 0;
>>
>>  	mutex_lock(&mdev->graph_mutex);
>>
>>  	media_entity_graph_walk_start(&graph, entity);
>>
>>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>> +		int i;
>> +
> 
> entity->num_link is unsigned, what about making i an unsigned int ?

Fixed.

>>  		entity->stream_count++;
>>  		WARN_ON(entity->pipe && entity->pipe != pipe);
>>  		entity->pipe = pipe;
>> +
>> +		/* Already streaming --- no need to check. */
>> +		if (entity->stream_count > 1)
>> +			continue;
>> +
>> +		if (!entity->ops || !entity->ops->link_validate)
>> +			continue;
>> +
>> +		for (i = 0; i < entity->num_links; i++) {
>> +			struct media_link *link = &entity->links[i];
>> +
>> +			/* Is this pad part of an enabled link? */
>> +			if ((link->flags & MEDIA_LNK_FL_ENABLED)
>> +			    != MEDIA_LNK_FL_ENABLED)
> 
> Just nickpicking, if you wrote it
> 
> 			if (!(link->flags & MEDIA_LNK_FL_ENABLED))
> 
> it would fit on a single line :-)
> 
>> +				continue;
>> +
>> +			/* Are we the sink or not? */
>> +			if (link->sink->entity != entity)
>> +				continue;
>> +
>> +			ret = entity->ops->link_validate(link);
>> +			if (ret < 0 && ret != -ENOIOCTLCMD)
>> +				break;
> 
> You could goto error directly here, this would avoid checking the ret value 
> after the loop, and you could also avoid initializing ret to 0.

Good point. Fixed.

>> +		}
>> +		if (ret < 0 && ret != -ENOIOCTLCMD)
>> +			goto error;
>>  	}
>>
>>  	mutex_unlock(&mdev->graph_mutex);
>> +
>> +	return 0;
>> +
>> +error:
>> +	/*
>> +	 * Link validation on graph failed. We revert what we did and
>> +	 * return the error.
>> +	 */
>> +	media_entity_graph_walk_start(&graph, entity_err);
>> +	do {
>> +		entity_err = media_entity_graph_walk_next(&graph);
>> +		entity_err->stream_count--;
>> +		if (entity_err->stream_count == 0)
>> +			entity_err->pipe = NULL;
>> +	} while (entity_err != entity);
>> +
>> +	mutex_unlock(&mdev->graph_mutex);
>> +
>> +	return ret;
>>  }
>>  EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
>>
>> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
>> index 29e7bba..0c16f51 100644
>> --- a/include/media/media-entity.h
>> +++ b/include/media/media-entity.h
>> @@ -46,6 +46,7 @@ struct media_entity_operations {
>>  	int (*link_setup)(struct media_entity *entity,
>>  			  const struct media_pad *local,
>>  			  const struct media_pad *remote, u32 flags);
>> +	int (*link_validate)(struct media_link *link);
>>  };
>>
>>  struct media_entity {
>> @@ -140,8 +141,8 @@ void media_entity_graph_walk_start(struct
>> media_entity_graph *graph, struct media_entity *entity);
>>  struct media_entity *
>>  media_entity_graph_walk_next(struct media_entity_graph *graph);
>> -void media_entity_pipeline_start(struct media_entity *entity,
>> -		struct media_pipeline *pipe);
>> +__must_check int media_entity_pipeline_start(struct media_entity *entity,
>> +					     struct media_pipeline *pipe);
>>  void media_entity_pipeline_stop(struct media_entity *entity);
>>
>>  #define media_entity_call(entity, operation, args...)			\
> 


-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 17/33] v4l: Implement v4l2_subdev_link_validate()
  2012-02-22 10:14   ` Laurent Pinchart
@ 2012-02-23 16:07     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-23 16:07 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.

Thanks for your comments!!

> On Monday 20 February 2012 03:56:56 Sakari Ailus wrote:
>> v4l2_subdev_link_validate() is the default op for validating a link. In V4L2
>> subdev context, it is used to call a pad op which performs the proper link
>> check without much extra work.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  Documentation/video4linux/v4l2-framework.txt |   12 +++++
>>  drivers/media/video/v4l2-subdev.c            |   69
>> ++++++++++++++++++++++++++ include/media/v4l2-subdev.h                  |  
>> 12 +++++
>>  3 files changed, 93 insertions(+), 0 deletions(-)
>>
>> diff --git a/Documentation/video4linux/v4l2-framework.txt
>> b/Documentation/video4linux/v4l2-framework.txt index f06c563..9d341bc
>> 100644
>> --- a/Documentation/video4linux/v4l2-framework.txt
>> +++ b/Documentation/video4linux/v4l2-framework.txt
>> @@ -312,6 +312,18 @@ If the subdev driver intends to process video and
>> integrate with the media framework, it must implement format related
>> functionality using
>>  v4l2_subdev_pad_ops instead of v4l2_subdev_video_ops.
>>
>> +In that case, the subdev driver may set the link_validate field to provide
>> +its own link validation function. The link validation function is called
>> for +every link in the pipeline where both of the ends of the links are
>> V4L2 +sub-devices. The driver is still responsible for validating the
>> correctness +of the format configuration between sub-devices and video
>> nodes.
>> +
>> +If link_validate op is not set, the default function
>> +v4l2_subdev_link_validate_default() is used instead. This function ensures
>> +that width, height and the media bus pixel code are equal on both source
>> and +sink of the link. Subdev drivers are also free to use this function to
>> +perform the checks mentioned above in addition to their own checks. +
>>  A device (bridge) driver needs to register the v4l2_subdev with the
>>  v4l2_device:
>>
>> diff --git a/drivers/media/video/v4l2-subdev.c
>> b/drivers/media/video/v4l2-subdev.c index ef27144..d2ec552 100644
>> --- a/drivers/media/video/v4l2-subdev.c
>> +++ b/drivers/media/video/v4l2-subdev.c
>> @@ -379,6 +379,75 @@ const struct v4l2_file_operations v4l2_subdev_fops = {
>>  	.poll = subdev_poll,
>>  };
>>
>> +#ifdef CONFIG_MEDIA_CONTROLLER
>> +int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
>> +				      struct media_link *link,
>> +				      struct v4l2_subdev_format *source_fmt,
>> +				      struct v4l2_subdev_format *sink_fmt)
>> +{
>> +	if (source_fmt->format.width != sink_fmt->format.width
>> +	    || source_fmt->format.height != sink_fmt->format.height
>> +	    || source_fmt->format.code != sink_fmt->format.code)
>> +		return -EINVAL;
>> +
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate_default);
>> +
>> +static struct v4l2_subdev_format
>> +*v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>> +				      struct v4l2_subdev_format *fmt)
> 
> Why do you return a pointer to the passed struct v4l2_subdev_format instead of 
> just an error code ?

I don't remember. ;-) I'll replace that with an integer return value for
the next version.

>> +{
>> +	int rval;
> 
> I would have used ret instead of rval as that's the preferred variable name in 
> this file (OK, I'm cheating, there's a single instance of ret, and I wrote 
> that one ;-)).

If you can get a patch through to Documentation/CodingStyle that
recognises "ret" as the variable name for return value, I'll change it.
How about that? ;-) ;-)

>> +
>> +	switch (media_entity_type(pad->entity)) {
>> +	case MEDIA_ENT_T_V4L2_SUBDEV:
>> +		fmt->which = V4L2_SUBDEV_FORMAT_ACTIVE;
>> +		fmt->pad = pad->index;
>> +		rval = v4l2_subdev_call(media_entity_to_v4l2_subdev(
>> +						pad->entity),
>> +					pad, get_fmt, NULL, fmt);
>> +		if (rval < 0)
>> +			return NULL;
>> +		return fmt;
>> +	default:
>> +		WARN(1, "Driver bug! Wrong media entity type %d, entity %s\n",
>> +		     media_entity_type(pad->entity), pad->entity->name);
>> +		/* Fall through */
>> +	case MEDIA_ENT_T_DEVNODE_V4L:
>> +		return NULL;
>> +	}
>> +}
>> +
>> +int v4l2_subdev_link_validate(struct media_link *link)
>> +{
>> +	struct v4l2_subdev *sink;
>> +	struct v4l2_subdev_format _sink_fmt, _source_fmt;
>> +	struct v4l2_subdev_format *sink_fmt, *source_fmt;
>> +	int rval;
>> +
>> +	source_fmt = v4l2_subdev_link_validate_get_format(
>> +		link->source, &_source_fmt);
>> +	if (!source_fmt)
>> +		return 0;
>> +
>> +	sink_fmt = v4l2_subdev_link_validate_get_format(
>> +		link->sink, &_sink_fmt);
>> +	if (!sink_fmt)
>> +		return 0;
>> +
>> +	sink = media_entity_to_v4l2_subdev(link->sink->entity);
>> +
>> +	rval = v4l2_subdev_call(sink, pad, link_validate, link,
>> +				source_fmt, sink_fmt);
>> +	if (rval < 0 && rval != -ENOIOCTLCMD)
>> +		return rval;
>> +	return v4l2_subdev_link_validate_default(sink, link, source_fmt,
>> +						 sink_fmt);
> 
> I don't think you should call v4l2_subdev_link_validate_default() if the 
> link_validate operation is implemented and returns that the link is valid. The 
> subdev might have weaker requirements than the default.

Right; the link validation should succeed by default. I'll remove that part.

>> +}
>> +EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate);
>> +#endif /* CONFIG_MEDIA_CONTROLLER */
>> +
>>  void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops
>> *ops) {
>>  	INIT_LIST_HEAD(&sd->list);
>> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
>> index d48dae5..f115608 100644
>> --- a/include/media/v4l2-subdev.h
>> +++ b/include/media/v4l2-subdev.h
>> @@ -470,6 +470,11 @@ struct v4l2_subdev_pad_ops {
>>  			     struct v4l2_subdev_selection *sel);
>>  	int (*set_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
>>  			     struct v4l2_subdev_selection *sel);
>> +#ifdef CONFIG_MEDIA_CONTROLLER
>> +	int (*link_validate)(struct v4l2_subdev *sd, struct media_link *link,
>> +			     struct v4l2_subdev_format *source_fmt,
>> +			     struct v4l2_subdev_format *sink_fmt);
>> +#endif /* CONFIG_MEDIA_CONTROLLER */
>>  };
>>
>>  struct v4l2_subdev_ops {
>> @@ -603,6 +608,13 @@ static inline void *v4l2_get_subdev_hostdata(const
>> struct v4l2_subdev *sd) return sd->host_priv;
>>  }
>>
>> +#ifdef CONFIG_MEDIA_CONTROLLER
>> +int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
>> +				      struct media_link *link,
>> +				      struct v4l2_subdev_format *source_fmt,
>> +				      struct v4l2_subdev_format *sink_fmt);
>> +int v4l2_subdev_link_validate(struct media_link *link);
>> +#endif /* CONFIG_MEDIA_CONTROLLER */
>>  void v4l2_subdev_init(struct v4l2_subdev *sd,
>>  		      const struct v4l2_subdev_ops *ops);


-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 26/33] omap3isp: Default link validation for ccp2, csi2, preview and resizer
  2012-02-22 11:01   ` Laurent Pinchart
@ 2012-02-25  1:34     ` Sakari Ailus
  2012-02-26 23:14       ` Laurent Pinchart
  0 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-25  1:34 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Thanks for the comments.

On Wed, Feb 22, 2012 at 12:01:26PM +0100, Laurent Pinchart wrote:
> On Monday 20 February 2012 03:57:05 Sakari Ailus wrote:
> > Use default link validation for ccp2, csi2, preview and resizer. On ccp2,
> > csi2 and ccdc we also collect information on external subdevs as one may be
> > connected to those entities.
> > 
> > The CCDC link validation still must be done separately.
> > 
> > Also set pipe->external correctly as we go
> > 
> > Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> > ---
> >  drivers/media/video/omap3isp/ispccdc.c    |   23 +++++++++++++++++++++++
> >  drivers/media/video/omap3isp/ispccp2.c    |   20 ++++++++++++++++++++
> >  drivers/media/video/omap3isp/ispcsi2.c    |   19 +++++++++++++++++++
> >  drivers/media/video/omap3isp/isppreview.c |    2 ++
> >  drivers/media/video/omap3isp/ispresizer.c |    2 ++
> >  drivers/media/video/omap3isp/ispvideo.c   |    4 ++++
> >  6 files changed, 70 insertions(+), 0 deletions(-)
> > 
> > diff --git a/drivers/media/video/omap3isp/ispccdc.c
> > b/drivers/media/video/omap3isp/ispccdc.c index a74a797..6aff241 100644
> > --- a/drivers/media/video/omap3isp/ispccdc.c
> > +++ b/drivers/media/video/omap3isp/ispccdc.c
> > @@ -1999,6 +1999,27 @@ static int ccdc_set_format(struct v4l2_subdev *sd,
> > struct v4l2_subdev_fh *fh, return 0;
> >  }
> > 
> > +static int ccdc_link_validate(struct v4l2_subdev *sd,
> > +			      struct media_link *link,
> > +			      struct v4l2_subdev_format *source_fmt,
> > +			      struct v4l2_subdev_format *sink_fmt)
> > +{
> > +	struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
> > +	struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
> > +	int rval;
> > +
> > +	/* We've got a parallel sensor here. */
> > +	if (ccdc->input == CCDC_INPUT_PARALLEL) {
> > +		pipe->external =
> > +			media_entity_to_v4l2_subdev(link->source->entity);
> > +		rval = omap3isp_get_external_info(pipe, link);
> > +		if (rval < 0)
> > +			return 0;
> > +	}
> 
> Pending my comments on 25/33, this wouldn't be needed in this patch, and could 
> be squashed with 27/33.

If I moved this code out of pipeline validation, I'd have to walk the graph
one additional time. Do you think it's worth it, or are there easier ways to
find the external entity connected to a pipeline?

> > +
> > +	return 0;
> > +}
> > +
> >  /*
> >   * ccdc_init_formats - Initialize formats on all pads
> >   * @sd: ISP CCDC V4L2 subdevice
> > @@ -2041,6 +2062,7 @@ static const struct v4l2_subdev_pad_ops
> > ccdc_v4l2_pad_ops = { .enum_frame_size = ccdc_enum_frame_size,
> >  	.get_fmt = ccdc_get_format,
> >  	.set_fmt = ccdc_set_format,
> > +	.link_validate = ccdc_link_validate,
> >  };
> > 
> >  /* V4L2 subdev operations */
> > @@ -2150,6 +2172,7 @@ static int ccdc_link_setup(struct media_entity
> > *entity, /* media operations */
> >  static const struct media_entity_operations ccdc_media_ops = {
> >  	.link_setup = ccdc_link_setup,
> > +	.link_validate = v4l2_subdev_link_validate,
> >  };
> > 
> >  void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
> > diff --git a/drivers/media/video/omap3isp/ispccp2.c
> > b/drivers/media/video/omap3isp/ispccp2.c index 70ddbf3..4fb34ee 100644
> > --- a/drivers/media/video/omap3isp/ispccp2.c
> > +++ b/drivers/media/video/omap3isp/ispccp2.c
> > @@ -819,6 +819,24 @@ static int ccp2_set_format(struct v4l2_subdev *sd,
> > struct v4l2_subdev_fh *fh, return 0;
> >  }
> > 
> > +static int ccp2_link_validate(struct v4l2_subdev *sd, struct media_link
> > *link, +			      struct v4l2_subdev_format *source_fmt,
> > +			      struct v4l2_subdev_format *sink_fmt)
> > +{
> > +	struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
> > +	struct isp_pipeline *pipe = to_isp_pipeline(&ccp2->subdev.entity);
> > +	int rval;
> > +
> > +	pipe->external = media_entity_to_v4l2_subdev(link->source->entity);
> > +	rval = omap3isp_get_external_info(pipe, link);
> > +	if (rval < 0)
> > +		return rval;
> > +
> > +	return v4l2_subdev_link_validate_default(sd, link, source_fmt,
> > +						 sink_fmt);
> 
> That's the default behaviour, if omap3isp_get_external_info() is moved to 
> ispvideo.c you can just leave .link_validate as NULL.
> 
> > +}
> > +
> > +
> >  /*
> >   * ccp2_init_formats - Initialize formats on all pads
> >   * @sd: ISP CCP2 V4L2 subdevice
> > @@ -925,6 +943,7 @@ static const struct v4l2_subdev_pad_ops ccp2_sd_pad_ops
> > = { .enum_frame_size = ccp2_enum_frame_size,
> >  	.get_fmt = ccp2_get_format,
> >  	.set_fmt = ccp2_set_format,
> > +	.link_validate = ccp2_link_validate,
> >  };
> > 
> >  /* subdev operations */
> > @@ -1021,6 +1040,7 @@ static int ccp2_link_setup(struct media_entity
> > *entity, /* media operations */
> >  static const struct media_entity_operations ccp2_media_ops = {
> >  	.link_setup = ccp2_link_setup,
> > +	.link_validate = v4l2_subdev_link_validate,
> >  };
> > 
> >  /*
> > diff --git a/drivers/media/video/omap3isp/ispcsi2.c
> > b/drivers/media/video/omap3isp/ispcsi2.c index fcb5168..9313f7c 100644
> > --- a/drivers/media/video/omap3isp/ispcsi2.c
> > +++ b/drivers/media/video/omap3isp/ispcsi2.c
> > @@ -1012,6 +1012,23 @@ static int csi2_set_format(struct v4l2_subdev *sd,
> > struct v4l2_subdev_fh *fh, return 0;
> >  }
> > 
> > +static int csi2_link_validate(struct v4l2_subdev *sd, struct media_link
> > *link, +			      struct v4l2_subdev_format *source_fmt,
> > +			      struct v4l2_subdev_format *sink_fmt)
> > +{
> > +	struct isp_csi2_device *csi2 = v4l2_get_subdevdata(sd);
> > +	struct isp_pipeline *pipe = to_isp_pipeline(&csi2->subdev.entity);
> > +	int rval;
> > +
> > +	pipe->external = media_entity_to_v4l2_subdev(link->source->entity);
> > +	rval = omap3isp_get_external_info(pipe, link);
> > +	if (rval < 0)
> > +		return rval;
> > +
> > +	return v4l2_subdev_link_validate_default(sd, link, source_fmt,
> > +						 sink_fmt);
> 
> Same here.
> 
> > +}
> > +
> >  /*
> >   * csi2_init_formats - Initialize formats on all pads
> >   * @sd: ISP CSI2 V4L2 subdevice
> > @@ -1107,6 +1124,7 @@ static const struct v4l2_subdev_pad_ops csi2_pad_ops =
> > { .enum_frame_size = csi2_enum_frame_size,
> >  	.get_fmt = csi2_get_format,
> >  	.set_fmt = csi2_set_format,
> > +	.link_validate = csi2_link_validate,
> >  };
> > 
> >  /* subdev operations */
> > @@ -1181,6 +1199,7 @@ static int csi2_link_setup(struct media_entity
> > *entity, /* media operations */
> >  static const struct media_entity_operations csi2_media_ops = {
> >  	.link_setup = csi2_link_setup,
> > +	.link_validate = v4l2_subdev_link_validate,
> >  };
> > 
> >  void omap3isp_csi2_unregister_entities(struct isp_csi2_device *csi2)
> > diff --git a/drivers/media/video/omap3isp/isppreview.c
> > b/drivers/media/video/omap3isp/isppreview.c index 6d0fb2c..c2bf500 100644
> > --- a/drivers/media/video/omap3isp/isppreview.c
> > +++ b/drivers/media/video/omap3isp/isppreview.c
> > @@ -1981,6 +1981,7 @@ static const struct v4l2_subdev_pad_ops
> > preview_v4l2_pad_ops = { .set_fmt = preview_set_format,
> >  	.get_crop = preview_get_crop,
> >  	.set_crop = preview_set_crop,
> > +	.link_validate = v4l2_subdev_link_validate_default,
> 
> You can leave this as NULL as well.
> 
> >  };
> > 
> >  /* subdev operations */
> > @@ -2076,6 +2077,7 @@ static int preview_link_setup(struct media_entity
> > *entity, /* media operations */
> >  static const struct media_entity_operations preview_media_ops = {
> >  	.link_setup = preview_link_setup,
> > +	.link_validate = v4l2_subdev_link_validate,
> >  };
> > 
> >  void omap3isp_preview_unregister_entities(struct isp_prev_device *prev)
> > diff --git a/drivers/media/video/omap3isp/ispresizer.c
> > b/drivers/media/video/omap3isp/ispresizer.c index 6958a9e..6ce2349 100644
> > --- a/drivers/media/video/omap3isp/ispresizer.c
> > +++ b/drivers/media/video/omap3isp/ispresizer.c
> > @@ -1532,6 +1532,7 @@ static const struct v4l2_subdev_pad_ops
> > resizer_v4l2_pad_ops = { .set_fmt = resizer_set_format,
> >  	.get_crop = resizer_g_crop,
> >  	.set_crop = resizer_s_crop,
> > +	.link_validate = v4l2_subdev_link_validate_default,
> 
> And this too.
> 
> >  };
> > 
> >  /* subdev operations */
> > @@ -1603,6 +1604,7 @@ static int resizer_link_setup(struct media_entity
> > *entity, /* media operations */
> >  static const struct media_entity_operations resizer_media_ops = {
> >  	.link_setup = resizer_link_setup,
> > +	.link_validate = v4l2_subdev_link_validate,
> >  };
> > 
> >  void omap3isp_resizer_unregister_entities(struct isp_res_device *res)
> > diff --git a/drivers/media/video/omap3isp/ispvideo.c
> > b/drivers/media/video/omap3isp/ispvideo.c index 17522db..f1c68ca 100644
> > --- a/drivers/media/video/omap3isp/ispvideo.c
> > +++ b/drivers/media/video/omap3isp/ispvideo.c
> > @@ -993,6 +993,10 @@ isp_video_streamon(struct file *file, void *fh, enum
> > v4l2_buf_type type) */
> >  	pipe = video->video.entity.pipe
> >  	     ? to_isp_pipeline(&video->video.entity) : &video->pipe;
> > +	pipe->external = NULL;
> > +	pipe->external_rate = 0;
> > +	pipe->external_bpp = 0;
> > +
> >  	ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
> >  	if (ret < 0)
> >  		goto err_media_entity_pipeline_start;
> -- 
> Regards,
> 
> Laurent Pinchart

Cheers,

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

* Re: [PATCH v3 27/33] omap3isp: Implement proper CCDC link validation, check pixel rate
  2012-02-22 11:11   ` Laurent Pinchart
@ 2012-02-25  1:42     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-25  1:42 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Thanks for your comments.

On Wed, Feb 22, 2012 at 12:11:07PM +0100, Laurent Pinchart wrote:
> On Monday 20 February 2012 03:57:06 Sakari Ailus wrote:
> > Implement correct link validation for the CCDC. Use external_rate from
> > isp_pipeline to configurat vp divisor and check that external_rate does not
> > exceed our data rate limitations.
> > 
> > Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> > ---
> >  drivers/media/video/omap3isp/ispccdc.c |   69
> > +++++++++++++++++++++++++++++-- 1 files changed, 64 insertions(+), 5
> > deletions(-)
> > 
> > diff --git a/drivers/media/video/omap3isp/ispccdc.c
> > b/drivers/media/video/omap3isp/ispccdc.c index 6aff241..1555891 100644
> > --- a/drivers/media/video/omap3isp/ispccdc.c
> > +++ b/drivers/media/video/omap3isp/ispccdc.c
> > @@ -836,8 +836,8 @@ static void ccdc_config_vp(struct isp_ccdc_device *ccdc)
> > 
> >  	if (pipe->input)
> >  		div = DIV_ROUND_UP(l3_ick, pipe->max_rate);
> > -	else if (ccdc->vpcfg.pixelclk)
> > -		div = l3_ick / ccdc->vpcfg.pixelclk;
> > +	else if (pipe->external_rate)
> > +		div = l3_ick / pipe->external_rate;
> > 
> >  	div = clamp(div, 2U, max_div);
> >  	fmtcfg_vp |= (div - 2) << ISPCCDC_FMTCFG_VPIF_FRQ_SHIFT;
> > @@ -1749,7 +1749,18 @@ static int ccdc_set_stream(struct v4l2_subdev *sd,
> > int enable) }
> > 
> >  	switch (enable) {
> > -	case ISP_PIPELINE_STREAM_CONTINUOUS:
> > +	case ISP_PIPELINE_STREAM_CONTINUOUS: {
> > +		struct isp_pipeline *pipe = to_isp_pipeline(&sd->entity);
> > +		unsigned int rate = UINT_MAX;
> > +
> > +		/*
> > +		 * Check that maximum allowed rate isn't exceeded by
> > +		 * the pixel rate.
> > +		 */
> > +		omap3isp_ccdc_max_rate(&isp->isp_ccdc, &rate);
> > +		if (pipe->external_rate > rate)
> > +			return -ENOSPC;
> > +
> 
> What about checking this at pipeline validation time ?

If the external entity is found before pipeline validation, then I can move
this there. I agree in principle that's the right thing to do.

> >  		if (ccdc->output & CCDC_OUTPUT_MEMORY)
> >  			omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
> > 
> > @@ -1758,6 +1769,7 @@ static int ccdc_set_stream(struct v4l2_subdev *sd, int
> > enable)
> > 
> >  		ccdc->underrun = 0;
> >  		break;
> > +	}
> > 
> >  	case ISP_PIPELINE_STREAM_SINGLESHOT:
> >  		if (ccdc->output & CCDC_OUTPUT_MEMORY &&
> > @@ -1999,6 +2011,37 @@ static int ccdc_set_format(struct v4l2_subdev *sd,
> > struct v4l2_subdev_fh *fh, return 0;
> >  }
> > 
> > +/*
> > + * Decide whether desired output pixel code can be obtained with
> > + * the lane shifter by shifting the input pixel code.
> > + * @in: input pixelcode to shifter
> > + * @out: output pixelcode from shifter
> > + * @additional_shift: # of bits the sensor's LSB is offset from CAMEXT[0]
> > + *
> > + * return true if the combination is possible
> > + * return false otherwise
> > + */
> > +static bool ccdc_is_shiftable(enum v4l2_mbus_pixelcode in,
> > +			      enum v4l2_mbus_pixelcode out,
> > +			      unsigned int additional_shift)
> > +{
> > +	const struct isp_format_info *in_info, *out_info;
> > +
> > +	if (in == out)
> > +		return true;
> > +
> > +	in_info = omap3isp_video_format_info(in);
> > +	out_info = omap3isp_video_format_info(out);
> > +
> > +	if ((in_info->flavor == 0) || (out_info->flavor == 0))
> > +		return false;
> > +
> > +	if (in_info->flavor != out_info->flavor)
> > +		return false;
> > +
> > +	return in_info->bpp - out_info->bpp + additional_shift <= 6;
> > +}
> > +
> >  static int ccdc_link_validate(struct v4l2_subdev *sd,
> >  			      struct media_link *link,
> >  			      struct v4l2_subdev_format *source_fmt,
> > @@ -2008,13 +2051,31 @@ static int ccdc_link_validate(struct v4l2_subdev
> > *sd, struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity); int
> > rval;
> > 
> > +	/* Check if the two ends match */
> > +	if (source_fmt->format.width != sink_fmt->format.width ||
> > +	    source_fmt->format.height != sink_fmt->format.height)
> > +		return -EPIPE;
> > +
> >  	/* We've got a parallel sensor here. */
> >  	if (ccdc->input == CCDC_INPUT_PARALLEL) {
> 
> The lane shifter is usable with the CCP2 and CSI2 inputs as well. The 
> parallel_shift value is restricted to parallel input though. Please perform 
> the same check as done in isp_video_validate_pipeline().

Good catch. I'll fix this.

> Revies would also be easier if you removed the CCDC-specific code from 
> isp_video_validate_pipeline() in this patch.

Ok. I see what I could do for the next version.

> > +		struct isp_parallel_platform_data *pdata =
> > +			&((struct isp_v4l2_subdevs_group *)
> > +			  media_entity_to_v4l2_subdev(link->source->entity)
> > +			  ->host_priv)->bus.parallel;
> > +		unsigned long parallel_shift = pdata->data_lane_shift * 2;
> > +		/* Lane shifter may be used to drop bits on CCDC sink pad */
> > +		if (!ccdc_is_shiftable(source_fmt->format.code,
> > +				       sink_fmt->format.code, parallel_shift))
> > +			return -EPIPE;
> > +
> >  		pipe->external =
> >  			media_entity_to_v4l2_subdev(link->source->entity);
> >  		rval = omap3isp_get_external_info(pipe, link);
> >  		if (rval < 0)
> >  			return 0;
> > +	} else {
> > +		if (source_fmt->format.code != sink_fmt->format.code)
> > +			return -EPIPE;
> >  	}
> > 
> >  	return 0;
> > @@ -2299,8 +2360,6 @@ int omap3isp_ccdc_init(struct isp_device *isp)
> >  	ccdc->clamp.oblen = 0;
> >  	ccdc->clamp.dcsubval = 0;
> > 
> > -	ccdc->vpcfg.pixelclk = 0;
> > -
> >  	ccdc->update = OMAP3ISP_CCDC_BLCLAMP;
> >  	ccdc_apply_controls(ccdc);
> -- 
> Regards,
> 
> Laurent Pinchart

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

* Re: [PATCH v3 28/33] omap3isp: Move setting constaints above media_entity_pipeline_start
  2012-02-22 11:12   ` Laurent Pinchart
@ 2012-02-25  1:46     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-25  1:46 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

On Wed, Feb 22, 2012 at 12:12:58PM +0100, Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.
> 
> On Monday 20 February 2012 03:57:07 Sakari Ailus wrote:
> 
> Could you please briefly explain why this is needed ?

Sure. The clock rates are now acquired during pipeline validation which is
now part of media_entity_pipeline_start(). For that reason we set
constraints earlier on.

I'll add this to the description.

Regards,

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

* Re: [PATCH v3 29/33] omap3isp: Configure CSI-2 phy based on platform data
  2012-02-22 11:21   ` Laurent Pinchart
@ 2012-02-25  1:49     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-25  1:49 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

On Wed, Feb 22, 2012 at 12:21:50PM +0100, Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.
> 
> On Monday 20 February 2012 03:57:08 Sakari Ailus wrote:
> > Configure CSI-2 phy based on platform data in the ISP driver. For that, the
> > new V4L2_CID_IMAGE_SOURCE_PIXEL_RATE control is used. Previously the same
> > was configured from the board code.
> > 
> > Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> 
> [snip]
> 
> > diff --git a/drivers/media/video/omap3isp/ispcsiphy.c
> > b/drivers/media/video/omap3isp/ispcsiphy.c index 5be37ce..902477d 100644
> > --- a/drivers/media/video/omap3isp/ispcsiphy.c
> > +++ b/drivers/media/video/omap3isp/ispcsiphy.c
> > @@ -28,41 +28,13 @@
> >  #include <linux/device.h>
> >  #include <linux/regulator/consumer.h>
> > 
> > +#include "../../../../arch/arm/mach-omap2/control.h"
> 
> I expect you will have to fix that somehow, but as far as I'm concerned,
> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Thanks. I don't think I like this any more than you do, but my understandint
is there is no good solution to this _right now_, and the proper solution
won't be that far away anyway, so I just intend to keep it as-is for now.

Cheers,

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

* Re: [PATCH v3 31/33] omap3isp: Remove isp_validate_pipeline and other old stuff
  2012-02-22 11:26   ` Laurent Pinchart
@ 2012-02-25  1:52     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-25  1:52 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

On Wed, Feb 22, 2012 at 12:26:30PM +0100, Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.
> 
> On Monday 20 February 2012 03:57:10 Sakari Ailus wrote:
> > Remove isp_set_pixel_clock().
> > 
> > Remove set_pixel_clock() callback from platform callbacks since the same
> > information is now passed to the ISP driver by other means.
> >
> > Remove struct ispccdc_vp since the only field in this structure, pixelclk,
> > is no longer used.
> > 
> > Remove isp_video_is_shiftable() --- this will live on as ccdc_is_shiftable
> > in ispccdc.c.
> 
> Could you please move those changes to the patches where you add them to the 
> other modules ?

Ack. I'll fix this for the next version.

Cheers,

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

* Re: [PATCH v3 22/33] omap3isp: Assume media_entity_pipeline_start may fail
  2012-02-22 10:48   ` Laurent Pinchart
@ 2012-02-26  1:08     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-26  1:08 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Thanks for the patch.

Thanks for the comments.

> On Monday 20 February 2012 03:57:01 Sakari Ailus wrote:
>> Since media_entity_pipeline_start() now does link validation, it may
>> actually fail. Perform the error handling.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  drivers/media/video/omap3isp/ispvideo.c |   20 ++++++++++++--------
>>  1 files changed, 12 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/media/video/omap3isp/ispvideo.c
>> b/drivers/media/video/omap3isp/ispvideo.c index c191f13..17522db 100644
>> --- a/drivers/media/video/omap3isp/ispvideo.c
>> +++ b/drivers/media/video/omap3isp/ispvideo.c
>> @@ -993,14 +993,16 @@ isp_video_streamon(struct file *file, void *fh, enum
>> v4l2_buf_type type) */
>>  	pipe = video->video.entity.pipe
>>  	     ? to_isp_pipeline(&video->video.entity) : &video->pipe;
>> -	media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
>> +	ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe);
>> +	if (ret < 0)
>> +		goto err_media_entity_pipeline_start;
>>
>>  	/* Verify that the currently configured format matches the output of
>>  	 * the connected subdev.
>>  	 */
>>  	ret = isp_video_check_format(video, vfh);
>>  	if (ret < 0)
>> -		goto error;
>> +		goto err_isp_video_check_format;
>>
>>  	video->bpl_padding = ret;
>>  	video->bpl_value = vfh->format.fmt.pix.bytesperline;
>> @@ -1017,7 +1019,7 @@ isp_video_streamon(struct file *file, void *fh, enum
>> v4l2_buf_type type) } else {
>>  		if (far_end == NULL) {
>>  			ret = -EPIPE;
>> -			goto error;
>> +			goto err_isp_video_check_format;
>>  		}
>>
>>  		state = ISP_PIPELINE_STREAM_INPUT | ISP_PIPELINE_IDLE_INPUT;
>> @@ -1032,7 +1034,7 @@ isp_video_streamon(struct file *file, void *fh, enum
>> v4l2_buf_type type) /* Validate the pipeline and update its state. */
>>  	ret = isp_video_validate_pipeline(pipe);
>>  	if (ret < 0)
>> -		goto error;
>> +		goto err_isp_video_check_format;
>>
>>  	pipe->error = false;
>>
>> @@ -1054,7 +1056,7 @@ isp_video_streamon(struct file *file, void *fh, enum
>> v4l2_buf_type type)
>>
>>  	ret = omap3isp_video_queue_streamon(&vfh->queue);
>>  	if (ret < 0)
>> -		goto error;
>> +		goto err_isp_video_check_format;
>>
>>  	/* In sensor-to-memory mode, the stream can be started synchronously
>>  	 * to the stream on command. In memory-to-memory mode, it will be
>> @@ -1064,19 +1066,21 @@ isp_video_streamon(struct file *file, void *fh, enum
>> v4l2_buf_type type) ret = omap3isp_pipeline_set_stream(pipe,
>>  					      ISP_PIPELINE_STREAM_CONTINUOUS);
>>  		if (ret < 0)
>> -			goto error;
>> +			goto err_omap3isp_set_stream;
>>  		spin_lock_irqsave(&video->queue->irqlock, flags);
>>  		if (list_empty(&video->dmaqueue))
>>  			video->dmaqueue_flags |= ISP_VIDEO_DMAQUEUE_UNDERRUN;
>>  		spin_unlock_irqrestore(&video->queue->irqlock, flags);
>>  	}
>>
>> -error:
>>  	if (ret < 0) {
>> +err_omap3isp_set_stream:
>>  		omap3isp_video_queue_streamoff(&vfh->queue);
>> +err_isp_video_check_format:
>> +		media_entity_pipeline_stop(&video->video.entity);
>> +err_media_entity_pipeline_start:
>>  		if (video->isp->pdata->set_constraints)
>>  			video->isp->pdata->set_constraints(video->isp, false);
>> -		media_entity_pipeline_stop(&video->video.entity);
>>  		/* The DMA queue must be emptied here, otherwise CCDC interrupts
>>  		 * that will get triggered the next time the CCDC is powered up
>>  		 * will try to access buffers that might have been freed but
> 
> As you add error labels, you can remove the if (ret < 0) test and move error 
> handling to a separate block. set_constraint() should be called before 
> media_entity_pipeline_stop() in that case. Another option is to leave error 
> handling untouched, and to return directly when media_entity_pipeline_start() 
> fails (after unlocking the mutex of course).

I've added separate error handling part and moved the constraint
settings patch before this one.

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 25/33] omap3isp: Introduce omap3isp_get_external_info()
  2012-02-22 10:55   ` Laurent Pinchart
@ 2012-02-26  1:09     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-26  1:09 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.
> 
> On Monday 20 February 2012 03:57:04 Sakari Ailus wrote:
>> omap3isp_get_external_info() will retrieve external subdev's bits-per-pixel
>> and pixel rate for the use of other ISP subdevs at streamon time.
>> omap3isp_get_external_info() is used during pipeline validation.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  drivers/media/video/omap3isp/isp.c |   48
>> ++++++++++++++++++++++++++++++++++++ drivers/media/video/omap3isp/isp.h |  
>>  3 ++
>>  2 files changed, 51 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/media/video/omap3isp/isp.c
>> b/drivers/media/video/omap3isp/isp.c index 12d5f92..89a9bf8 100644
>> --- a/drivers/media/video/omap3isp/isp.c
>> +++ b/drivers/media/video/omap3isp/isp.c
>> @@ -353,6 +353,54 @@ void omap3isp_hist_dma_done(struct isp_device *isp)
>>  	}
>>  }
>>
>> +int omap3isp_get_external_info(struct isp_pipeline *pipe,
>> +			       struct media_link *link)
>> +{
>> +	struct isp_device *isp =
>> +		container_of(pipe, struct isp_video, pipe)->isp;
>> +	struct v4l2_subdev_format fmt;
>> +	struct v4l2_ext_controls ctrls;
>> +	struct v4l2_ext_control ctrl;
>> +	int ret;
>> +
>> +	if (!pipe->external)
>> +		return 0;
>> +
>> +	if (pipe->external_rate)
>> +		return 0;
>> +
>> +	memset(&fmt, 0, sizeof(fmt));
>> +
>> +	fmt.pad = link->source->index;
>> +	fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
>> +	ret = v4l2_subdev_call(media_entity_to_v4l2_subdev(link->sink->entity),
>> +			       pad, get_fmt, NULL, &fmt);
>> +	if (ret < 0)
>> +		return -EPIPE;
>> +
>> +	pipe->external_bpp = omap3isp_video_format_info(fmt.format.code)->bpp;
>> +
>> +	memset(&ctrls, 0, sizeof(ctrls));
>> +	memset(&ctrl, 0, sizeof(ctrl));
>> +
>> +	ctrl.id = V4L2_CID_PIXEL_RATE;
>> +
>> +	ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(ctrl.id);
>> +	ctrls.count = 1;
>> +	ctrls.controls = &ctrl;
>> +
>> +	ret = v4l2_g_ext_ctrls(pipe->external->ctrl_handler, &ctrls);
>> +	if (ret < 0) {
>> +		dev_warn(isp->dev, "no pixel rate control in subdev %s\n",
>> +			 pipe->external->name);
>> +		return ret;
>> +	}
>> +
>> +	pipe->external_rate = ctrl.value64;
>> +
>> +	return 0;
>> +}
> 
> What about moving this to ispvideo.c ? You could then call the function from 
> isp_video_streamon() only, and make it static.

Done.

>> +
>>  static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
>>  {
>>  	static const char *name[] = {
>> diff --git a/drivers/media/video/omap3isp/isp.h
>> b/drivers/media/video/omap3isp/isp.h index 2e78041..8b0bc2d 100644
>> --- a/drivers/media/video/omap3isp/isp.h
>> +++ b/drivers/media/video/omap3isp/isp.h
>> @@ -222,6 +222,9 @@ struct isp_device {
>>
>>  void omap3isp_hist_dma_done(struct isp_device *isp);
>>
>> +int omap3isp_get_external_info(struct isp_pipeline *pipe,
>> +			       struct media_link *link);
>> +
>>  void omap3isp_flush(struct isp_device *isp);
>>
>>  int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t
>> *wait,


-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 30/33] omap3isp: Add resizer data rate configuration to resizer_set_stream
  2012-02-22 11:24   ` Laurent Pinchart
@ 2012-02-26  1:10     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-26  1:10 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.
> 
> On Monday 20 February 2012 03:57:09 Sakari Ailus wrote:
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  drivers/media/video/omap3isp/ispresizer.c |    4 ++++
>>  1 files changed, 4 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/media/video/omap3isp/ispresizer.c
>> b/drivers/media/video/omap3isp/ispresizer.c index 6ce2349..81e1bc4 100644
>> --- a/drivers/media/video/omap3isp/ispresizer.c
>> +++ b/drivers/media/video/omap3isp/ispresizer.c
>> @@ -1147,9 +1147,13 @@ static int resizer_set_stream(struct v4l2_subdev *sd,
>> int enable) struct device *dev = to_device(res);
>>
>>  	if (res->state == ISP_PIPELINE_STREAM_STOPPED) {
>> +		struct isp_pipeline *pipe = to_isp_pipeline(&sd->entity);
>> +
>>  		if (enable == ISP_PIPELINE_STREAM_STOPPED)
>>  			return 0;
>>
>> +		omap3isp_resizer_max_rate(res, &pipe->max_rate);
>> +
>>  		omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_RESIZER);
>>  		resizer_configure(res);
>>  		resizer_print_status(res);
> 
> What about moving this to link validation ?

Done. I hope I can resend the patchset tomorrow. The SMIA++ driver is
unchanged just in case you happen to have time to review that one. ;-)

Cheers,

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 08/33] v4l: Add subdev selections documentation: svg and dia files
  2012-02-21 15:00   ` Laurent Pinchart
@ 2012-02-26 18:56     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-26 18:56 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.
> 
> On Monday 20 February 2012 03:56:47 Sakari Ailus wrote:
>> Add svga and dia files for V4L2 subdev selections documentation.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> 
> The diagram look fine, although a bit complex. They could be simplified by 
> merging the identical rectangles (for instance moving the sink crop selection 
> label to the dotted blue rectangle, and removing the plain blue rectangle). 
> I'm not sure if that would be really more readable though, it's up to you.

I did that change, and I indeed think it improves readability. Now the
documentation has equal number of rectangles that there really are.

Cheers,

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 09/33] v4l: Add subdev selections documentation
  2012-02-21 16:41   ` Laurent Pinchart
@ 2012-02-26 21:42     ` Sakari Ailus
  2012-02-28 11:42       ` Laurent Pinchart
  0 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-26 21:42 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Many thanks for the comments!

Laurent Pinchart wrote:
> On Monday 20 February 2012 03:56:48 Sakari Ailus wrote:
>> Add documentation for V4L2 subdev selection API. This changes also
>> experimental V4L2 subdev API so that scaling now works through selection API
>> only.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> 
> 
>> diff --git a/Documentation/DocBook/media/v4l/dev-subdev.xml
>> b/Documentation/DocBook/media/v4l/dev-subdev.xml index 0916a73..9d5e7da
>> 100644
>> --- a/Documentation/DocBook/media/v4l/dev-subdev.xml
>> +++ b/Documentation/DocBook/media/v4l/dev-subdev.xml
> 
> [snip]
> 
>> +      <para>Scaling operation changes the size of the image by scaling
>> +      it to new dimensions. Some sub-devices support it. The scaled
>> +      size (width and height) is represented by &v4l2-rect;. In the
>> +      case of scaling, top and left will always be zero. Scaling is
>> +      configured using &sub-subdev-g-selection; and
>> +      <constant>V4L2_SUBDEV_SEL_COMPOSE_ACTIVE</constant> selection
>> +      target on the sink pad of the subdev. The scaling is performed
>> +      related to the width and height of the crop rectangle on the
>> +      subdev's sink pad.</para>
> 
> I'm not sure if that would be very clear for readers who are not yet familiar 
> with the API. What about the following text instead ?
> 
> "The scaling operation changes the size of the image by scaling it to new 
> dimensions. The scaling ratio isn't specified explicitly, but is implied from 
> the original and scaled image sizes. Both sizes are represented by &v4l2-
> rect;.
> 
> Scaling support is optional. When supported by a subdev, the crop rectangle on 
> the subdev's sink pad is scaled to the size configured using &VIDIOC-SUBDEV-G-
> SELECTION; and <constant>V4L2_SUBDEV_SEL_COMPOSE_ACTIVE</constant> selection 
> target on the same pad. If the subdev supports scaling but no composing, the 
> top and left values are not used and must always be set to zero."
> 
> (note that &sub-subdev-g-selection; has been replaced with &VIDIOC-SUBDEV-G-
> SELECTION;)
> 
> I would also move this text after the sink pad crop description to follow the 
> order in which operations are applied by subdevs.

I'm fine with that change, so I did it. However, I won't replace
&sub-subdev-g-selection; with &VIDIOC-SUBDEV-G-SELECTION; simply because
it won't work:

dev-subdev.xml:310: parser error : Entity 'VIDIOC-SUBDEV-G-SELECTION'
not defined
      size configured using &VIDIOC-SUBDEV-G-SELECTION; and

It's beyond me why not; similar references are being used elsewhere with
otherwise equivalent definitions. Perhaps the name is just too long?
That's the only difference I could think of: xmlto typically segfaults
on errors so I wouldn't be surprised of something so simple.

>> +      <para>As for pad formats, drivers store try and active
>> +      rectangles for the selection targets of ACTIVE type <xref
>> +      linkend="v4l2-subdev-selection-targets">.</xref></para>
>> +
>> +      <para>On sink pads, cropping is applied relatively to the
>> +      current pad format. The pad format represents the image size as
>> +      received by the sub-device from the previous block in the
>> +      pipeline, and the crop rectangle represents the sub-image that
>> +      will be transmitted further inside the sub-device for
>> +      processing.</para>
>> +
>> +      <para>On source pads, cropping is similar to sink pads, with the
>> +      exception that the source size from which the cropping is
>> +      performed, is the COMPOSE rectangle on the sink pad. In both
>> +      sink and source pads, the crop rectangle must be entirely
>> +      containted inside the source image size for the crop
>> +      operation.</para>
>> +
>> +      <para>The drivers should always use the closest possible
>> +      rectangle the user requests on all selection targets, unless
>> +      specificly told otherwise<xref
>> +      linkend="v4l2-subdev-selection-flags">.</xref></para>
>> +    </section>
>> +
>> +    <section>
>> +      <title>Types of selection targets</title>
>> +
>> +      <section>
>> +	<title>ACTIVE targets</title>
>> +
>> +	<para>ACTIVE targets reflect the actual hardware configuration
>> +	at any point of time.</para>
>> +      </section>
>> +
>> +      <section>
>> +	<title>BOUNDS targets</title>
>> +
>> +	<para>BOUNDS targets is the smallest rectangle within which
>> +	contains all valid ACTIVE rectangles.
> 
> s/within which/that/ ?

Ack.

>> It may not be possible
>> +	to set the ACTIVE rectangle as large as the BOUNDS rectangle,
>> +	however.</para>
> 
> What about
> 
> "The BOUNDS rectangle might not itself be a valid ACTIVE rectangle when all 
> possible ACTIVE pixels do not form a rectangular shape (e.g. cross-shaped or 
> round sensors)."

There are cases where the active size is limited, even if it's
rectangular. I can add the above case there, sure, if you think such
devices exist --- I've never heard of nor seen them. Some sensors are
documented to be cross-shaped but the only thing separating these from
the rest is that the manufacturer doesn't guarantee the quality of the
pixels in the corners. At least on those I've seen. You can still
capture the full pixel matrix.

>> +      </section>
>>
>> -      <para>Cropping behaviour on output pads is not defined.</para>
>> +    </section>
>> +
>> +    <section>
>> +      <title>Order of configuration and format propagation</title>
>> +
>> +      <para>Inside subdevs, the order of image processing steps will
>> +      always be from the sink pad towards the source pad. This is also
>> +      reflected in the order in which the configuration must be
>> +      performed by the user: the changes made will be propagated to
>> +      any subsequent stages. If this behaviour is not desired, the
>> +      user must set
>> +      <constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant> flag.
> 
> Could you explain what happens when V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG is set ? 
> Just stating that it doesn't follow the propagation behaviour previously 
> described could be understood in many different ways.

Good point. How about this:

"This flag causes that no propagation of the changes are allowed in any
circumstances. This may also lead the accessed rectangle not being
changed at all, depending on the properties of the underlying hardware.
Some drivers may not support this flag."

>> The
>> +      coordinates to a step always refer to the active size of the
>> +      previous step. The exception to this rule is the source compose
>> +      rectangle, which refers to the sink compose bounds rectangle ---
>> +      if it is supported by the hardware.</para>
>> +
>> +      <orderedlist>
>> +	<listitem>Sink pad format. The user configures the sink pad
>> +	format. This format defines the parameters of the image the
>> +	entity receives through the pad for further processing.</listitem>
>> +
>> +	<listitem>Sink pad active crop selection. The sink pad crop
>> +	defines the performed to the sink pad format.</listitem>
> 
> s/defines the/defines the cropping/ ?

Fixed.

>> +
>> +	<listitem>Sink pad active compose selection. The size of the
>> +	sink pad compose rectangle defines the scaling ratio compared
>> +	to the size of the sink pad crop rectangle. The location of
>> +	the compose rectangle specifies the location of the active
>> +	sink compose rectangle in the sink compose bounds
>> +	rectangle.</listitem>
>> +
>> +	<listitem>Source pad active crop selection. Crop on the source
>> +	pad defines crop performed to the image in the sink compose
>> +	bounds rectangle.</listitem>
>> +
>> +	<listitem>Source pad format. The source pad format defines the
>> +	output pixel format of the subdev, as well as the other
>> +	parameters with the exception of the image width and height.
>> +	Width and height are defined by the size of the source pad
>> +	active crop selection.</listitem>
>> +      </orderedlist>
>> +
>> +      <para>Accessing any of the above rectangles not supported by the
>> +      subdev will return <constant>EINVAL</constant>.
> 
> Do drivers have to support BOUNDS rectangles for every ACTIVE rectangle they 
> support (and the other way around) ? If so, I think it should be specified.

I think the answer to that should be "yes", albeit this hasn't been
discussed previously. I see no reason not to support equivalent BOUNDS
rectangles.

I'll change the documentation to state that.

> Is EINVAL returned for any other error case in the selection API ? If so, it 
> might make enumeration of the supported rectangles difficult.

Good point. There are two other reasons to return EINVAL and those are
invalid parameters in either pad or which fields. I think that should be
fine. I'd keep it EINVAL.

Alternatively we could use e.g. ENOENT.

What do you think?

>> Any rectangle
>> +      referring to a previous unsupported rectangle coordinates will
>> +      instead refer to the previous supported rectangle. For example,
>> +      if sink crop is not supported, the compose selection will refer
>> +      to the sink pad format dimensions instead.</para>
> 
> Should we add a list of the rectangles a subdev must/should/can support for 
> the different possible use cases ?

I think this should be rather obvious with the examples and the
statement on BOUNDS rectangles. Such a list, if we make it very
detailed, will be unnecessarily redundant and will soon become
out-of-date. In principle I don't like redundancy whether it's code or
documentation. It easily leads to contradictions.

If it turns out it'll be needed we can easily add it later on.

>> +      <figure id="subdev-image-processing-crop">
>> +	<title>Image processing in subdevs: simple crop example</title>
>> +	<mediaobject>
>> +	  <imageobject>
>> +	    <imagedata fileref="subdev-image-processing-crop.svg"
>> +	    format="SVG" scale="200" />
>> +	  </imageobject>
>> +	</mediaobject>
>> +      </figure>
>> +
>> +      <para>In the above example, the subdev supports cropping on its
>> +      sink pad. To configure it, the user sets the media bus format on
>> +      the subdev's sink pad. Now the active crop rectangle can be set
>> +      on the sink pad --- the location and size of this rectangle
>> +      reflect the location and size of a rectangle to be cropped from
>> +      the sink format. The size of the sink crop rectangle will also
>> +      be the size of the format of the subdev's source pad.</para>
>> +
>> +      <figure id="subdev-image-processing-scaling-multi-source">
>> +	<title>Image processing in subdevs: scaling with multiple sources</title>
>> +	<mediaobject>
>> +	  <imageobject>
>> +	    <imagedata fileref="subdev-image-processing-scaling-multi-source.svg"
>> +	    format="SVG" scale="200" />
>> +	  </imageobject>
>> +	</mediaobject>
>> +      </figure>
>> +
>> +      <para>In this example, the subdev is capable of first cropping,
>> +      then scaling and finally cropping for two source pads
>> +      individually from the resulting scaled image. The location of
>> +      the scaled image in the cropped image is ignored in sink compose
>> +      target. Both of the locations of the source crop rectangles
>> +      refer to the sink scaling rectangle, independently cropping an
>> +      area at location specified by the source crop rectangle from
>> +      it.</para>
>> +
>> +      <figure id="subdev-image-processing-full">
>> +	<title>Image processing in subdevs: scaling and composition
>> +	with multiple sinks and sources</title>
>> +	<mediaobject>
>> +	  <imageobject>
>> +	    <imagedata fileref="subdev-image-processing-full.svg"
>> +	    format="SVG" scale="200" />
>> +	  </imageobject>
>> +	</mediaobject>
>> +      </figure>
>> +
>> +      <para>The subdev driver supports two sink pads and two source
>> +      pads. The images from both of the sink pads are individually
>> +      cropped, then scaled and further composed on the composition
>> +      bounds rectangle. From that, two independent streams are cropped
>> +      and sent out of the subdev from the source pads.</para>
>>
>>      </section>
>> +
>>    </section>
>>
>>    &sub-subdev-formats;
> 
> [snip]
> 
>> diff --git a/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
>> b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml new file
>> mode 100644
>> index 0000000..033077a
>> --- /dev/null
>> +++ b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
>> @@ -0,0 +1,222 @@
>> +<refentry id="vidioc-subdev-g-selection">
>> +  <refmeta>
>> +    <refentrytitle>ioctl VIDIOC_SUBDEV_G_SELECTION,
>> VIDIOC_SUBDEV_S_SELECTION</refentrytitle> +    &manvol;
>> +  </refmeta>
>> +
>> +  <refnamediv>
>> +    <refname>VIDIOC_SUBDEV_G_SELECTION</refname>
>> +    <refname>VIDIOC_SUBDEV_S_SELECTION</refname>
>> +    <refpurpose>Get or set selection rectangles on a subdev
>> pad</refpurpose> +  </refnamediv>
>> +
>> +  <refsynopsisdiv>
>> +    <funcsynopsis>
>> +      <funcprototype>
>> +	<funcdef>int <function>ioctl</function></funcdef>
>> +	<paramdef>int <parameter>fd</parameter></paramdef>
>> +	<paramdef>int <parameter>request</parameter></paramdef>
>> +	<paramdef>struct v4l2_subdev_selection
>> *<parameter>argp</parameter></paramdef> +      </funcprototype>
>> +    </funcsynopsis>
>> +  </refsynopsisdiv>
>> +
>> +  <refsect1>
>> +    <title>Arguments</title>
>> +
>> +    <variablelist>
>> +      <varlistentry>
>> +	<term><parameter>fd</parameter></term>
>> +	<listitem>
>> +	  <para>&fd;</para>
>> +	</listitem>
>> +      </varlistentry>
>> +      <varlistentry>
>> +	<term><parameter>request</parameter></term>
>> +	<listitem>
>> +	  <para>VIDIOC_SUBDEV_G_SELECTION, VIDIOC_SUBDEV_S_SELECTION</para>
>> +	</listitem>
>> +      </varlistentry>
>> +      <varlistentry>
>> +	<term><parameter>argp</parameter></term>
>> +	<listitem>
>> +	  <para></para>
>> +	</listitem>
>> +      </varlistentry>
>> +    </variablelist>
>> +  </refsect1>
>> +
>> +  <refsect1>
>> +    <title>Description</title>
>> +
>> +    <note>
>> +      <title>Experimental</title>
>> +      <para>This is an <link linkend="experimental">experimental</link>
>> +      interface and may change in the future.</para>
>> +    </note>
> 
> I think you forgot to add the subdev selection API to the list of experimental 
> APIs.

Fixed.

>> +    <para>The selections are used to configure various image
>> +    processing functionality performed by the subdevs which affect the
>> +    image size. This currently includes cropping, scaling and
>> +    composition.</para>
>> +
>> +    <para>The selection API replaces <link
>> +    linkend="vidioc-subdev-g-crop">the old subdev crop API</link>. All
>> +    the function of the crop API, and more, are supported by the
>> +    selections API.</para>
>> +
>> +    <para>See <xref linkend="subdev"></xref> for
>> +    more information on how each selection target affects the image
>> +    processing pipeline inside the subdevice.</para>
>> +
>> +    <section>
>> +      <title>Types of selection targets</title>
>> +
>> +      <para>The are four types of selection targets: active, default,
>> +      bounds and padding.
> 
> You don't define any default or padding selection target, should these be 
> removed here ?

These are leftovers from earlier versions of the patch. Removed.

I also corrected the BOUNDS description below.

>> The ACTIVE targets are the targets which
>> +      configure the hardware. The BOUNDS target will return the
>> +      maximum width and height of the target.</para>
>> +    </section>
>> +
>> +    <section>
>> +      <title>Discovering supported features</title>
>> +
>> +      <para>To discover which targets are supported, the user can
>> +      perform <constant>VIDIOC_SUBDEV_G_SELECTION</constant> on them.
>> +      Any unsupported target will return
>> +      <constant>EINVAL</constant>.</para>
>> +    </section>
>> +
>> +    <table pgwide="1" frame="none" id="v4l2-subdev-selection-targets">
>> +      <title>V4L2 subdev selection targets</title>
>> +      <tgroup cols="3">
>> +        &cs-def;
>> +	<tbody valign="top">
>> +	  <row>
>> +	    <entry><constant>V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE</constant></entry>
>> +	    <entry>0x0000</entry>
>> +	    <entry>Active crop. Defines the cropping
>> +	    performed by the processing step.</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS</constant></entry>
>> +	    <entry>0x0002</entry>
>> +	    <entry>Bounds of the crop rectangle.</entry>
>> +	  </row>
>> +	  <row>
>> +	    
> <entry><constant>V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE</constant></entry>
>> +	    <entry>0x0100</entry>
>> +	    <entry>Active compose rectangle. Used to configure scaling
>> +	    on sink pads and composition on source pads.</entry>
>> +	  </row>
>> +	  <row>
>> +	    
> <entry><constant>V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS</constant></entry>
>> +	    <entry>0x0102</entry>
>> +	    <entry>Bounds of the compose rectangle.</entry>
>> +	  </row>
>> +	</tbody>
>> +      </tgroup>
>> +    </table>
>> +
>> +    <table pgwide="1" frame="none" id="v4l2-subdev-selection-flags">
>> +      <title>V4L2 subdev selection flags</title>
>> +      <tgroup cols="3">
>> +        &cs-def;
>> +	<tbody valign="top">
>> +	  <row>
>> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_GE</constant></entry>
>> +	    <entry>(1 &lt;&lt; 0)</entry>
>> +	    <entry>Suggest the driver it should choose greater or
>> +	    equal rectangle (in size) than was requested.</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_LE</constant></entry>
>> +	    <entry>(1 &lt;&lt; 1)</entry>
>> +	    <entry>Suggest the driver it should choose lesser or
>> +	    equal rectangle (in size) than was requested.</entry>
>> +	  </row>
> 
> Those two flags are only briefly described here, could you add a more detailed 
> description either here or in Documentation/DocBook/media/v4l/dev-subdev.xml ?

Added:

            " Albeit the driver may choose a lesser size,
	    it will only do so due to hardware limitations. Without
	    this flag (and
	    <constant>V4L2_SUBDEV_SEL_FLAG_SIZE_LE</constant>) the
	    behaviour is to choose the closest possible
	    rectangle."

Does that cover your understanding of a more detailed description? :-)

>> +	  <row>
>> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant></entry>
>> +	    <entry>(1 &lt;&lt; 2)</entry>
>> +	    <entry>The configuration should not be propagated to any
>> +	    further processing steps. If this flag is not given, the
>> +	    configuration is propagated inside the subdevice to all
>> +	    further processing steps.</entry>
>> +	  </row>
>> +	</tbody>
>> +      </tgroup>
>> +    </table>
>> +
>> +    <table pgwide="1" frame="none" id="v4l2-subdev-selection">
>> +      <title>struct <structname>v4l2_subdev_selection</structname></title>
>> +      <tgroup cols="3">
>> +        &cs-str;
>> +	<tbody valign="top">
>> +	  <row>
>> +	    <entry>__u32</entry>
>> +	    <entry><structfield>which</structfield></entry>
>> +	    <entry>Active or try selection, from
>> +	    &v4l2-subdev-format-whence;.</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry>__u32</entry>
>> +	    <entry><structfield>pad</structfield></entry>
>> +	    <entry>Pad number as reported by the media framework.</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry>__u32</entry>
>> +	    <entry><structfield>target</structfield></entry>
>> +	    <entry>Target selection rectangle. See
>> +	    <xref linkend="v4l2-subdev-selection-targets">.</xref>.</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry>__u32</entry>
>> +	    <entry><structfield>flags</structfield></entry>
>> +	    <entry>Flags. See
>> +	    <xref linkend="v4l2-subdev-selection-flags">.</xref></entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry>&v4l2-rect;</entry>
>> +	    <entry><structfield>rect</structfield></entry>
>> +	    <entry>Crop rectangle boundaries, in pixels.</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry>__u32</entry>
>> +	    <entry><structfield>reserved</structfield>[8]</entry>
>> +	    <entry>Reserved for future extensions. Applications and drivers must
>> +	    set the array to zero.</entry>
>> +	  </row>
>> +	</tbody>
>> +      </tgroup>
>> +    </table>
>> +
>> +  </refsect1>
>> +
>> +  <refsect1>
>> +    &return-value;
>> +
>> +    <variablelist>
>> +      <varlistentry>
>> +	<term><errorcode>EBUSY</errorcode></term>
>> +	<listitem>
>> +	  <para>The selection rectangle can't be changed because the
>> +	  pad is currently busy. This can be caused, for instance, by
>> +	  an active video stream on the pad. The ioctl must not be
>> +	  retried without performing another action to fix the problem
>> +	  first. Only returned by
>> +	  <constant>VIDIOC_SUBDEV_S_SELECTION</constant></para>
>> +	</listitem>
>> +      </varlistentry>
>> +      <varlistentry>
>> +	<term><errorcode>EINVAL</errorcode></term>
>> +	<listitem>
>> +	  <para>The &v4l2-subdev-selection;
>> +	  <structfield>pad</structfield> references a non-existing
>> +	  pad, the <structfield>which</structfield> field references a
>> +	  non-existing format, or the selection target is not
>> +	  supported on the given subdev pad.</para>
>> +	</listitem>
>> +      </varlistentry>
>> +    </variablelist>
>> +  </refsect1>
>> +</refentry>

Kind regards,

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 26/33] omap3isp: Default link validation for ccp2, csi2, preview and resizer
  2012-02-25  1:34     ` Sakari Ailus
@ 2012-02-26 23:14       ` Laurent Pinchart
  2012-02-26 23:40         ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-26 23:14 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

On Saturday 25 February 2012 03:34:36 Sakari Ailus wrote:
> On Wed, Feb 22, 2012 at 12:01:26PM +0100, Laurent Pinchart wrote:
> > On Monday 20 February 2012 03:57:05 Sakari Ailus wrote:
> > > Use default link validation for ccp2, csi2, preview and resizer. On
> > > ccp2, csi2 and ccdc we also collect information on external subdevs as
> > > one may be connected to those entities.
> > > 
> > > The CCDC link validation still must be done separately.
> > > 
> > > Also set pipe->external correctly as we go

[snip]

> > > @@ -1999,6 +1999,27 @@ static int ccdc_set_format(struct v4l2_subdev
> > > *sd,
> > > struct v4l2_subdev_fh *fh, return 0;
> > > 
> > >  }
> > > 
> > > +static int ccdc_link_validate(struct v4l2_subdev *sd,
> > > +			      struct media_link *link,
> > > +			      struct v4l2_subdev_format *source_fmt,
> > > +			      struct v4l2_subdev_format *sink_fmt)
> > > +{
> > > +	struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
> > > +	struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
> > > +	int rval;
> > > +
> > > +	/* We've got a parallel sensor here. */
> > > +	if (ccdc->input == CCDC_INPUT_PARALLEL) {
> > > +		pipe->external =
> > > +			media_entity_to_v4l2_subdev(link->source->entity);
> > > +		rval = omap3isp_get_external_info(pipe, link);
> > > +		if (rval < 0)
> > > +			return 0;
> > > +	}
> > 
> > Pending my comments on 25/33, this wouldn't be needed in this patch, and
> > could be squashed with 27/33.
> 
> If I moved this code out of pipeline validation, I'd have to walk the graph
> one additional time. Do you think it's worth it, or are there easier ways to
> find the external entity connected to a pipeline?

If I understand you correctly, the problem is that 
omap3isp_get_external_info() can only be called when the external entity has 
been located, and the CCDC link validation operation would be called before 
that. Is that correct ?

One option would be to locate the external entity before validating the link. 
When the validation pipeline walk operation gets to the CCDC entity, it would 
first follow the link, check if the connected entity is external (and in that 
case sotre it in pipe->external and call omap3isp_get_external_info()), and 
then only call the CCDC link validation operation.

The other option is to leave the code as-is :-) Or rather modify it slightly: 
assigning the entity to pipe->external and calling 
omap3isp_get_external_info() should be done in ispvideo.c at pipeline 
validation time.

> > > +
> > > +	return 0;
> > > +}
> > > +
> > > 
> > >  /*
> > >  
> > >   * ccdc_init_formats - Initialize formats on all pads
> > >   * @sd: ISP CCDC V4L2 subdevice
> > > 

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 26/33] omap3isp: Default link validation for ccp2, csi2, preview and resizer
  2012-02-26 23:14       ` Laurent Pinchart
@ 2012-02-26 23:40         ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-26 23:40 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Hi Sakari,
> 
> On Saturday 25 February 2012 03:34:36 Sakari Ailus wrote:
>> On Wed, Feb 22, 2012 at 12:01:26PM +0100, Laurent Pinchart wrote:
>>> On Monday 20 February 2012 03:57:05 Sakari Ailus wrote:
>>>> Use default link validation for ccp2, csi2, preview and resizer. On
>>>> ccp2, csi2 and ccdc we also collect information on external subdevs as
>>>> one may be connected to those entities.
>>>>
>>>> The CCDC link validation still must be done separately.
>>>>
>>>> Also set pipe->external correctly as we go
> 
> [snip]
> 
>>>> @@ -1999,6 +1999,27 @@ static int ccdc_set_format(struct v4l2_subdev
>>>> *sd,
>>>> struct v4l2_subdev_fh *fh, return 0;
>>>>
>>>>  }
>>>>
>>>> +static int ccdc_link_validate(struct v4l2_subdev *sd,
>>>> +			      struct media_link *link,
>>>> +			      struct v4l2_subdev_format *source_fmt,
>>>> +			      struct v4l2_subdev_format *sink_fmt)
>>>> +{
>>>> +	struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
>>>> +	struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
>>>> +	int rval;
>>>> +
>>>> +	/* We've got a parallel sensor here. */
>>>> +	if (ccdc->input == CCDC_INPUT_PARALLEL) {
>>>> +		pipe->external =
>>>> +			media_entity_to_v4l2_subdev(link->source->entity);
>>>> +		rval = omap3isp_get_external_info(pipe, link);
>>>> +		if (rval < 0)
>>>> +			return 0;
>>>> +	}
>>>
>>> Pending my comments on 25/33, this wouldn't be needed in this patch, and
>>> could be squashed with 27/33.
>>
>> If I moved this code out of pipeline validation, I'd have to walk the graph
>> one additional time. Do you think it's worth it, or are there easier ways to
>> find the external entity connected to a pipeline?
> 
> If I understand you correctly, the problem is that 
> omap3isp_get_external_info() can only be called when the external entity has 
> been located, and the CCDC link validation operation would be called before 
> that. Is that correct ?
> 
> One option would be to locate the external entity before validating the link. 
> When the validation pipeline walk operation gets to the CCDC entity, it would 
> first follow the link, check if the connected entity is external (and in that 
> case sotre it in pipe->external and call omap3isp_get_external_info()), and 
> then only call the CCDC link validation operation.
> 
> The other option is to leave the code as-is :-) Or rather modify it slightly: 
> assigning the entity to pipe->external and calling 
> omap3isp_get_external_info() should be done in ispvideo.c at pipeline 
> validation time.

I've modified it so that the entities which are part of the pipe will be
disovered by media_entity_pipeline_start() and stored in struct
media_pipeline.entities (as bitmask).

It's trivial to figure out the external entity from that one in the ISP
driver.

I did it so since I assume pretty much every single driver supporting
any non-linear data path must perform the same. It's also almost no work
in doing this in the above function, compared to a relatively
significant headache in the ISP driver.

I'll resend the patchset once I've gotten your reply on my selections
documentation changes. :-)

Cheers,

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs
  2012-02-23  6:01     ` Sakari Ailus
@ 2012-02-27  0:22       ` Laurent Pinchart
  2012-02-27  0:57         ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-27  0:22 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

On Thursday 23 February 2012 08:01:23 Sakari Ailus wrote:
> Laurent Pinchart wrote:
> > [snip]
> > 
> >> +/* active cropping area */
> >> +#define V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE			0x0000
> >> +/* cropping bounds */
> >> +#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS			0x0002
> >> +/* current composing area */
> >> +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE		0x0100
> >> +/* composing bounds */
> > 
> > I'm not sure if ACTIVE is a good name here. It sounds confusing as we
> > already have V4L2_SUBDEV_FORMAT_ACTIVE.
> 
> We are using V4L2_SEL_TGT_COMPOSE_ACTIVE on V4L2 nodes already --- the
> name I'm using here just mirrors the naming on V4L2 device nodes. If I
> choose a different name here, some of that analogy is lost.
> 
> That said, I'm not against changing this but the equivalent change
> should then be made on V4L2 selection API for consistency.

I'm not against changing the V4L2 selection API either :-) Just think about 
developers talking about "try crop active" or "active crop bounds". Even 
worse, will "active crop" refer to the active target or the active "which" ? 
That will be very confusing.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 06/33] v4l: Check pad number in get try pointer functions
  2012-02-23  5:57     ` Sakari Ailus
@ 2012-02-27  0:33       ` Laurent Pinchart
  2012-02-27 12:27         ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-27  0:33 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

On Thursday 23 February 2012 07:57:54 Sakari Ailus wrote:
> Laurent Pinchart wrote:
> > On Monday 20 February 2012 03:56:45 Sakari Ailus wrote:
> >> Unify functions to get try pointers and validate the pad number accessed
> >> by
> >> the user.
> >> 
> >> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> >> ---
> >> 
> >>  include/media/v4l2-subdev.h |   31 ++++++++++++++-----------------
> >>  1 files changed, 14 insertions(+), 17 deletions(-)
> >> 
> >> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> >> index bcaf6b8..d48dae5 100644
> >> --- a/include/media/v4l2-subdev.h
> >> +++ b/include/media/v4l2-subdev.h
> >> @@ -565,23 +565,20 @@ struct v4l2_subdev_fh {
> >> 
> >>  	container_of(fh, struct v4l2_subdev_fh, vfh)
> >>  
> >>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
> >> 
> >> -static inline struct v4l2_mbus_framefmt *
> >> -v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
> >> -{
> >> -	return &fh->pad[pad].try_fmt;
> >> -}
> >> -
> >> -static inline struct v4l2_rect *
> >> -v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
> >> -{
> >> -	return &fh->pad[pad].try_crop;
> >> -}
> >> -
> >> -static inline struct v4l2_rect *
> >> -v4l2_subdev_get_try_compose(struct v4l2_subdev_fh *fh, unsigned int pad)
> >> -{
> >> -	return &fh->pad[pad].try_compose;
> >> -}
> >> +#define __V4L2_SUBDEV_MK_GET_TRY(rtype, fun_name, field_name)		\
> >> +	static inline struct rtype *					\
> >> +	v4l2_subdev_get_try_##fun_name(struct v4l2_subdev_fh *fh,	\
> >> +				       unsigned int pad)		\
> >> +	{								\
> >> +		if (unlikely(pad > vdev_to_v4l2_subdev(			\
> >> +				     fh->vfh.vdev->entity.num_pads)	\
> >> +			return NULL;					\
> >> +		return &fh->pad[pad].field_name;			\
> >> +	}
> >> +
> >> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, format, try_fmt)
> >> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_compose)
> >> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, compose, try_compose)
> >> 
> >>  #endif
> >>  
> >>  extern const struct v4l2_file_operations v4l2_subdev_fops;
> > 
> > I'm not sure if this is a good idea. Drivers usually access the active and
> > try formats/rectangles through a single function that checks the which
> > argument and returns the active format/rectangle from the driver-specific
> > device structure, or calls v4l2_subdev_get_try_*. The pad number should
> > be checked for both active and try formats/rectangles, as both can result
> > in accessing a wrong memory location.
> > 
> > Furthermore, only in-kernel access to the active/try formats/rectangles
> > need to be checked, as the pad argument to subdev ioctls are already
> > checked in v4l2-subdev.c. If your goal is to catch buggy kernel code
> > here, a BUG_ON might be more suitable (although accessing the NULL
> > pointer would result in an oops anyway).
> 
> This was basically the reason for the memory corryption issue I had some
> time ago with the driver. The drivers (typically, I guess) need to
> access this data also to validate the following selection rectangles
> inside the subdev.
> 
> The active rectangles are also driver's own property so it's the matter
> of driver to access them properly. In principle the same goes for the
> try rectangles, but the fact still is that this patch would have caught
> the bad accesses right at the time they were made. I feel it's just too
> easy to give the function a faulty pad number --- see the SMIA++ driver
> for an example.
> 
> I'd prefer to keep this change, and also I'm fine with doing BUG()
> instead of returning NULL.

I think I would prefer a BUG() as well. I'm OK with keeping the check. If 
drivers were bug-free this wouldn't be needed at all of course :-)

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs
  2012-02-27  0:22       ` Laurent Pinchart
@ 2012-02-27  0:57         ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-27  0:57 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

On Mon, Feb 27, 2012 at 01:22:34AM +0100, Laurent Pinchart wrote:
> Hi Sakari,
> 
> On Thursday 23 February 2012 08:01:23 Sakari Ailus wrote:
> > Laurent Pinchart wrote:
> > > [snip]
> > > 
> > >> +/* active cropping area */
> > >> +#define V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE			0x0000
> > >> +/* cropping bounds */
> > >> +#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS			0x0002
> > >> +/* current composing area */
> > >> +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE		0x0100
> > >> +/* composing bounds */
> > > 
> > > I'm not sure if ACTIVE is a good name here. It sounds confusing as we
> > > already have V4L2_SUBDEV_FORMAT_ACTIVE.
> > 
> > We are using V4L2_SEL_TGT_COMPOSE_ACTIVE on V4L2 nodes already --- the
> > name I'm using here just mirrors the naming on V4L2 device nodes. If I
> > choose a different name here, some of that analogy is lost.
> > 
> > That said, I'm not against changing this but the equivalent change
> > should then be made on V4L2 selection API for consistency.
> 
> I'm not against changing the V4L2 selection API either :-) Just think about 
> developers talking about "try crop active" or "active crop bounds". Even 
> worse, will "active crop" refer to the active target or the active "which" ? 
> That will be very confusing.

I think I understand your concern. An easy solution would be to rename
active targets to something else, but what would that be exactly?

Also I can't currently think non-active rectangles would have use with which
== try as they're not (typically) changeable. I guess this doesn't matter in
resolving the issue.

Current?
Effective?
Real?
Brisk?

Cheers,

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

* Re: [PATCH v3 33/33] rm680: Add camera init
  2012-02-20  1:57 ` [PATCH v3 33/33] rm680: Add camera init Sakari Ailus
@ 2012-02-27  1:06   ` Laurent Pinchart
  2012-02-28 19:05     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-27  1:06 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:12 Sakari Ailus wrote:
> From: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> 
> This currently introduces an extra file to the arch/arm/mach-omap2
> directory: board-rm680-camera.c. Keeping the device tree in mind, the
> context of the file could be represented as static data with one exception:
> the external clock to the sensor.
> 
> This external clock is provided by the OMAP 3 SoC and required by the
> sensor. The issue is that the clock originates from the ISP and not from
> PRCM block as the other clocks and thus is not supported by the clock
> framework. Otherwise the sensor driver could just clk_get() and clk_enable()
> it, just like the regulators and gpios.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> ---
>  arch/arm/mach-omap2/Makefile             |    3 +-
>  arch/arm/mach-omap2/board-rm680-camera.c |  375 +++++++++++++++++++++++++++
>  arch/arm/mach-omap2/board-rm680.c        |   38 +++
>  3 files changed, 415 insertions(+), 1 deletions(-)
>  create mode 100644 arch/arm/mach-omap2/board-rm680-camera.c
> 

[snip]

> diff --git a/arch/arm/mach-omap2/board-rm680-camera.c
> b/arch/arm/mach-omap2/board-rm680-camera.c new file mode 100644
> index 0000000..5059821
> --- /dev/null
> +++ b/arch/arm/mach-omap2/board-rm680-camera.c

[snip]

> +#include <asm/mach-types.h>
> +#include <plat/omap-pm.h>
> +
> +#include <media/omap3isp.h>
> +#include <media/smiapp.h>
> +
> +#include "../../../drivers/media/video/omap3isp/isp.h"

Do we still need the private OMAP3 ISP header ? You can move the ISP_XCLK_* 
macros to the public header (and maybe rename them to OMAP3ISP_XCLK_*).

> +#include "devices.h"
> +
> +#define SEC_CAMERA_RESET_GPIO	97
> +
> +#define RM680_PRI_SENSOR	1
> +#define RM680_PRI_LENS		2
> +#define RM680_SEC_SENSOR	3
> +#define MAIN_CAMERA_XCLK	ISP_XCLK_A
> +#define SEC_CAMERA_XCLK		ISP_XCLK_B
> +
> +/*
> + *
> + * Main Camera Module EXTCLK
> + * Used by the sensor and the actuator driver.
> + *
> + */
> +static struct camera_xclk {
> +	u32 hz;
> +	u32 lock;
> +	u8 xclksel;
> +} cameras_xclk;
> +
> +static DEFINE_MUTEX(lock_xclk);
> +
> +static int rm680_update_xclk(struct v4l2_subdev *subdev, u32 hz, u32 which,
> +			     u8 xclksel)
> +{
> +	struct isp_device *isp = v4l2_dev_to_isp_device(subdev->v4l2_dev);
> +	int ret;
> +
> +	mutex_lock(&lock_xclk);
> +
> +	if (which == RM680_SEC_SENSOR) {
> +		if (cameras_xclk.xclksel == MAIN_CAMERA_XCLK) {
> +			ret = -EBUSY;
> +			goto done;
> +		}
> +	} else {
> +		if (cameras_xclk.xclksel == SEC_CAMERA_XCLK) {
> +			ret = -EBUSY;
> +			goto done;
> +		}
> +	}
> +
> +	if (hz) {	/* Turn on */
> +		cameras_xclk.lock |= which;
> +		if (cameras_xclk.hz == 0) {
> +			isp->platform_cb.set_xclk(isp, hz, xclksel);
> +			cameras_xclk.hz = hz;
> +			cameras_xclk.xclksel = xclksel;
> +		}
> +	} else {	/* Turn off */
> +		cameras_xclk.lock &= ~which;
> +		if (cameras_xclk.lock == 0) {
> +			isp->platform_cb.set_xclk(isp, 0, xclksel);
> +			cameras_xclk.hz = 0;
> +			cameras_xclk.xclksel = 0;
> +		}
> +	}
> +
> +	ret = cameras_xclk.hz;
> +
> +done:
> +	mutex_unlock(&lock_xclk);
> +	return ret;
> +}

I don't like this, but we can't do much better until the generic struct clk is 
available :-) However, in addition to handling the ISP clocks, the above code 
also prevents the two sensors from being used at the same time. This won't be 
handle by the clock framework and will need to be implemented somewhere else. 
Shouldn't we already split the two functions ?

> +
> +/*
> + *
> + * Main Camera Sensor
> + *
> + */
> +
> +static int rm680_main_camera_set_xclk(struct v4l2_subdev *sd, int hz)
> +{
> +	return rm680_update_xclk(sd, hz, RM680_PRI_SENSOR, MAIN_CAMERA_XCLK);
> +}
> +
> +static struct smiapp_flash_strobe_parms rm680_main_camera_strobe_setup = {
> +	.mode			= 0x0c,
> +	.strobe_width_high_us	= 100000,
> +	.strobe_delay		= 0,
> +	.stobe_start_point	= 0,
> +	.trigger		= 0,
> +};
> +
> +static struct smiapp_platform_data rm696_main_camera_platform_data = {
> +	.i2c_addr_dfl		= SMIAPP_DFL_I2C_ADDR,
> +	.i2c_addr_alt		= SMIAPP_ALT_I2C_ADDR,
> +	.nvm_size		= 16 * 64,
> +	.ext_clk		= (9.6 * 1000 * 1000),

Parenthesis are not needed.

> +	.lanes			= 2,
> +	/* bit rate / ddr / lanes */
> +	.op_sys_clock		= (s64 []){ 796800000 / 2 / 2,
> +					    840000000 / 2 / 2,
> +					    1996800000 / 2 / 2, 0 },
> +	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CSI2,
> +	.strobe_setup		= &rm680_main_camera_strobe_setup,

What about embedding the flash strobe parameters in smiapp_platform_data ? Do 
you think that would be better ?

> +	.set_xclk		= rm680_main_camera_set_xclk,
> +	.xshutdown		= SMIAPP_NO_XSHUTDOWN,
> +};
> +
> +static struct smiapp_platform_data rm680_main_camera_platform_data = {
> +	.i2c_addr_dfl		= SMIAPP_DFL_I2C_ADDR,
> +	.i2c_addr_alt		= SMIAPP_ALT_I2C_ADDR,
> +	.nvm_size		= 16 * 64,
> +	.ext_clk		= (9.6 * 1000 * 1000),
> +	.lanes			= 2,
> +	.op_sys_clock		= (s64 []){ 840000000 / 2 / 2,
> +					    1334400000 / 2 / 2,
> +					    1593600000 / 2 / 2, 0 },
> +	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CSI2,
> +	.module_board_orient	= SMIAPP_MODULE_BOARD_ORIENT_180,
> +	.strobe_setup		= &rm680_main_camera_strobe_setup,
> +	.set_xclk		= rm680_main_camera_set_xclk,
> +	.xshutdown		= SMIAPP_NO_XSHUTDOWN,
> +};
> +
> +/*
> + *
> + * SECONDARY CAMERA Sensor
> + *
> + */
> +
> +#define SEC_CAMERA_XCLK		ISP_XCLK_B
> +
> +static int rm680_sec_camera_set_xclk(struct v4l2_subdev *sd, int hz)
> +{
> +	return rm680_update_xclk(sd, hz, RM680_SEC_SENSOR, SEC_CAMERA_XCLK);
> +}
> +
> +static struct smiapp_platform_data rm696_sec_camera_platform_data = {
> +	.ext_clk		= (10.8 * 1000 * 1000),
> +	.lanes			= 1,
> +	/* bit rate / ddr */
> +	.op_sys_clock		= (s64 []){ 13770000 * 10 / 2, 0 },
> +	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK,
> +	.module_board_orient	= SMIAPP_MODULE_BOARD_ORIENT_180,
> +	.set_xclk		= rm680_sec_camera_set_xclk,
> +	.xshutdown		= SEC_CAMERA_RESET_GPIO,
> +};
> +
> +static struct smiapp_platform_data rm680_sec_camera_platform_data = {
> +	.ext_clk		= (10.8 * 1000 * 1000),
> +	.lanes			= 1,
> +	/* bit rate / ddr */
> +	.op_sys_clock		= (s64 []){ 11880000 * 10 / 2, 0 },
> +	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK,
> +	.set_xclk		= rm680_sec_camera_set_xclk,
> +	.xshutdown		= SEC_CAMERA_RESET_GPIO,
> +};
> +
> +/*
> + *
> + * Init all the modules
> + *
> + */
> +
> +#define CAMERA_I2C_BUS_NUM		2
> +#define AD5836_I2C_BUS_NUM		2
> +#define AS3645A_I2C_BUS_NUM		2
> +
> +static struct i2c_board_info rm696_camera_i2c_devices[] = {
> +	{
> +		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_ALT_I2C_ADDR),
> +		.platform_data = &rm696_main_camera_platform_data,
> +	},
> +	{
> +		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_DFL_I2C_ADDR),
> +		.platform_data = &rm696_sec_camera_platform_data,
> +	},
> +};
> +
> +static struct i2c_board_info rm680_camera_i2c_devices[] = {
> +	{
> +		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_ALT_I2C_ADDR),
> +		.platform_data = &rm680_main_camera_platform_data,
> +	},
> +	{
> +		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_DFL_I2C_ADDR),
> +		.platform_data = &rm680_sec_camera_platform_data,
> +	},
> +};
> +
> +static struct isp_subdev_i2c_board_info rm696_camera_primary_subdevs[] = {
> +	{
> +		.board_info = &rm696_camera_i2c_devices[0],
> +		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
> +	},
> +	{ NULL, 0, },
> +};
> +
> +static struct isp_subdev_i2c_board_info rm696_camera_secondary_subdevs[] =
> { +	{
> +		.board_info = &rm696_camera_i2c_devices[1],
> +		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
> +	},
> +	{ NULL, 0, },
> +};
> +
> +static struct isp_subdev_i2c_board_info rm680_camera_primary_subdevs[] = {
> +	{
> +		.board_info = &rm680_camera_i2c_devices[0],
> +		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
> +	},
> +	{ NULL, 0, },
> +};
> +
> +static struct isp_subdev_i2c_board_info rm680_camera_secondary_subdevs[] =
> { +	{
> +		.board_info = &rm680_camera_i2c_devices[1],
> +		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
> +	},
> +	{ NULL, 0, },
> +};
> +
> +static struct isp_v4l2_subdevs_group rm696_camera_subdevs[] = {
> +	{
> +		.subdevs = rm696_camera_primary_subdevs,
> +		.interface = ISP_INTERFACE_CSI2A_PHY2,
> +		.bus = { .csi2 = {
> +			.crc		= 1,
> +			.vpclk_div	= 1,

Just wondering, is vpclk_div really needed in platform data, or should it be 
computed by the driver at runtime based on the clock frequencies ?

> +			.lanecfg	= {
> +				.clk = {
> +					.pol = 1,
> +					.pos = 2,
> +				},
> +				.data[0] = {
> +					.pol = 1,
> +					.pos = 1,
> +				},
> +				.data[1] = {
> +					.pol = 1,
> +					.pos = 3,
> +				},
> +			},
> +		} },
> +	},
> +	{
> +		.subdevs = rm696_camera_secondary_subdevs,
> +		.interface = ISP_INTERFACE_CCP2B_PHY1,
> +		.bus = { .ccp2 = {
> +			.strobe_clk_pol	= 0,
> +			.crc		= 0,
> +			.ccp2_mode	= 0,
> +			.phy_layer	= 0,
> +			.vpclk_div	= 2,
> +			.lanecfg	= {
> +				.clk = {
> +					.pol = 0,
> +					.pos = 1,
> +				},
> +				.data[0] = {
> +					.pol = 0,
> +					.pos = 2,
> +				},
> +			},
> +		} },
> +	},
> +	{ NULL, 0, },
> +};
> +
> +static struct isp_v4l2_subdevs_group rm680_camera_subdevs[] = {
> +	{
> +		.subdevs = rm680_camera_primary_subdevs,
> +		.interface = ISP_INTERFACE_CSI2A_PHY2,
> +		.bus = { .csi2 = {
> +			.crc		= 1,
> +			.vpclk_div	= 1,
> +			.lanecfg	= {
> +				.clk = {
> +					.pol = 1,
> +					.pos = 2,
> +				},
> +				.data[0] = {
> +					.pol = 1,
> +					.pos = 3,
> +				},
> +				.data[1] = {
> +					.pol = 1,
> +					.pos = 1,
> +				},
> +			},
> +		} },
> +	},
> +	{
> +		.subdevs = rm680_camera_secondary_subdevs,
> +		.interface = ISP_INTERFACE_CCP2B_PHY1,
> +		.bus = { .ccp2 = {
> +			.strobe_clk_pol	= 0,
> +			.crc		= 0,
> +			.ccp2_mode	= 0,
> +			.phy_layer	= 0,
> +			.vpclk_div	= 2,
> +			.lanecfg	= {
> +				.clk = {
> +					.pol = 0,
> +					.pos = 1,
> +				},
> +				.data[0] = {
> +					.pol = 0,
> +					.pos = 2,
> +				},
> +			},
> +		} },
> +	},
> +	{ NULL, 0, },
> +};

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 06/33] v4l: Check pad number in get try pointer functions
  2012-02-27  0:33       ` Laurent Pinchart
@ 2012-02-27 12:27         ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-27 12:27 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Hi Sakari,
> 
> On Thursday 23 February 2012 07:57:54 Sakari Ailus wrote:
>> Laurent Pinchart wrote:
>>> On Monday 20 February 2012 03:56:45 Sakari Ailus wrote:
>>>> Unify functions to get try pointers and validate the pad number accessed
>>>> by
>>>> the user.
>>>>
>>>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>>>> ---
>>>>
>>>>  include/media/v4l2-subdev.h |   31 ++++++++++++++-----------------
>>>>  1 files changed, 14 insertions(+), 17 deletions(-)
>>>>
>>>> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
>>>> index bcaf6b8..d48dae5 100644
>>>> --- a/include/media/v4l2-subdev.h
>>>> +++ b/include/media/v4l2-subdev.h
>>>> @@ -565,23 +565,20 @@ struct v4l2_subdev_fh {
>>>>
>>>>  	container_of(fh, struct v4l2_subdev_fh, vfh)
>>>>  
>>>>  #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
>>>>
>>>> -static inline struct v4l2_mbus_framefmt *
>>>> -v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
>>>> -{
>>>> -	return &fh->pad[pad].try_fmt;
>>>> -}
>>>> -
>>>> -static inline struct v4l2_rect *
>>>> -v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
>>>> -{
>>>> -	return &fh->pad[pad].try_crop;
>>>> -}
>>>> -
>>>> -static inline struct v4l2_rect *
>>>> -v4l2_subdev_get_try_compose(struct v4l2_subdev_fh *fh, unsigned int pad)
>>>> -{
>>>> -	return &fh->pad[pad].try_compose;
>>>> -}
>>>> +#define __V4L2_SUBDEV_MK_GET_TRY(rtype, fun_name, field_name)		\
>>>> +	static inline struct rtype *					\
>>>> +	v4l2_subdev_get_try_##fun_name(struct v4l2_subdev_fh *fh,	\
>>>> +				       unsigned int pad)		\
>>>> +	{								\
>>>> +		if (unlikely(pad > vdev_to_v4l2_subdev(			\
>>>> +				     fh->vfh.vdev->entity.num_pads)	\
>>>> +			return NULL;					\
>>>> +		return &fh->pad[pad].field_name;			\
>>>> +	}
>>>> +
>>>> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, format, try_fmt)
>>>> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_compose)
>>>> +__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, compose, try_compose)
>>>>
>>>>  #endif
>>>>  
>>>>  extern const struct v4l2_file_operations v4l2_subdev_fops;
>>>
>>> I'm not sure if this is a good idea. Drivers usually access the active and
>>> try formats/rectangles through a single function that checks the which
>>> argument and returns the active format/rectangle from the driver-specific
>>> device structure, or calls v4l2_subdev_get_try_*. The pad number should
>>> be checked for both active and try formats/rectangles, as both can result
>>> in accessing a wrong memory location.
>>>
>>> Furthermore, only in-kernel access to the active/try formats/rectangles
>>> need to be checked, as the pad argument to subdev ioctls are already
>>> checked in v4l2-subdev.c. If your goal is to catch buggy kernel code
>>> here, a BUG_ON might be more suitable (although accessing the NULL
>>> pointer would result in an oops anyway).
>>
>> This was basically the reason for the memory corryption issue I had some
>> time ago with the driver. The drivers (typically, I guess) need to
>> access this data also to validate the following selection rectangles
>> inside the subdev.
>>
>> The active rectangles are also driver's own property so it's the matter
>> of driver to access them properly. In principle the same goes for the
>> try rectangles, but the fact still is that this patch would have caught
>> the bad accesses right at the time they were made. I feel it's just too
>> easy to give the function a faulty pad number --- see the SMIA++ driver
>> for an example.
>>
>> I'd prefer to keep this change, and also I'm fine with doing BUG()
>> instead of returning NULL.
> 
> I think I would prefer a BUG() as well. I'm OK with keeping the check. If 
> drivers were bug-free this wouldn't be needed at all of course :-)

Changed to BUG_ON() in the next revision.

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 32/33] smiapp: Add driver.
  2012-02-20  1:57 ` [PATCH v3 32/33] smiapp: Add driver Sakari Ailus
@ 2012-02-27 15:38   ` Laurent Pinchart
  2012-02-29  5:41     ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-27 15:38 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

Thanks for the patch.

On Monday 20 February 2012 03:57:11 Sakari Ailus wrote:
> From: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> 
> Add driver for SMIA++/SMIA image sensors. The driver exposes the sensor as
> three subdevs, pixel array, binner and scaler --- in case the device has a
> scaler.
> 
> Currently it relies on the board code for external clock handling. There is
> no fast way out of this dependency before the ISP drivers (omap3isp) among
> others will be able to export that clock through the clock framework
> instead.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>

[snip]

> diff --git a/drivers/media/video/smiapp/Kconfig
> b/drivers/media/video/smiapp/Kconfig new file mode 100644
> index 0000000..3f98e8e
> --- /dev/null
> +++ b/drivers/media/video/smiapp/Kconfig
> @@ -0,0 +1,12 @@
> +config VIDEO_SMIAPP
> +	tristate "SMIA++/SMIA sensor support"
> +	depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER

VIDEO_V4L2_SUBDEV_API depends on MEDIA_CONTROLLER, you don't have to set the
dependency explicitly.

> +	---help---
> +	  This is a generic driver for SMIA++/SMIA camera modules.
> +
> +config VIDEO_SMIAPP_DEBUG
> +	bool "Enable debugging for the generic SMIA++/SMIA driver"
> +	depends on VIDEO_SMIAPP
> +	---help---
> +	  Enable debugging output in the generic SMIA++/SMIA driver. If you
> +	  are developing the driver you might want to enable this.

[snip]

> diff --git a/drivers/media/video/smiapp/smiapp-core.c
> b/drivers/media/video/smiapp/smiapp-core.c new file mode 100644
> index 0000000..9fd08a1
> --- /dev/null
> +++ b/drivers/media/video/smiapp/smiapp-core.c

[snip]

> +#define SMIAPP_ALIGN_DIM(dim, flags)	      \
> +	(flags & V4L2_SUBDEV_SEL_FLAG_SIZE_GE \
> +	 ? ALIGN(dim, 2)		      \
> +	 : dim & ~1)

Please enclose dim in parenthesis in the macro definition.

> +
> +/*
> + * smiapp_module_idents - supported camera modules
> + */
> +static const struct smiapp_module_ident smiapp_module_idents[] = {
> +	SMIAPP_IDENT_LQ(0x10, 0x4141, -1, "jt8ev1", &smiapp_jt8ev1_quirk),
> +	SMIAPP_IDENT_LQ(0x10, 0x4241, -1, "imx125es", &smiapp_imx125es_quirk),
> +	SMIAPP_IDENT_L(0x01, 0x022b, -1, "vs6555"),
> +	SMIAPP_IDENT_L(0x0c, 0x208a, -1, "tcm8330md"),
> +	SMIAPP_IDENT_L(0x01, 0x022e, -1, "vw6558"),
> +	SMIAPP_IDENT_LQ(0x0c, 0x2134, -1, "tcm8500md", &smiapp_tcm8500md_quirk),
> +	SMIAPP_IDENT_L(0x07, 0x7698, -1, "ovm7698"),
> +	SMIAPP_IDENT_L(0x0b, 0x4242, -1, "smiapp-003"),
> +	SMIAPP_IDENT_LQ(0x0c, 0x560f, -1, "jt8ew9", &smiapp_jt8ew9_quirk),
> +	SMIAPP_IDENT_L(0x0c, 0x213e, -1, "et8en2"),
> +	SMIAPP_IDENT_L(0x0c, 0x2184, -1, "tcm8580md"),
> +};

What about sorting those either by ID or name ?

> +
> +/*
> + *
> + * Dynamic Capability Identification
> + *
> + */
> +
> +static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	u32 fmt_model_type, fmt_model_subtype, ncol_desc, nrow_desc;
> +	int i;
> +	int rval;
> +	int line_count = 0;
> +	int embedded_start = -1, embedded_end = -1;
> +	int image_start = 0;
> +
> +	rval = smia_i2c_read_reg(client,
> +				 SMIAPP_REG_U8_FRAME_FORMAT_MODEL_TYPE,
> +				 &fmt_model_type);
> +	if (rval)
> +		return rval;
> +
> +	rval = smia_i2c_read_reg(client,
> +				 SMIAPP_REG_U8_FRAME_FORMAT_MODEL_SUBTYPE,
> +				 &fmt_model_subtype);
> +	if (rval)
> +		return rval;
> +
> +	ncol_desc = (fmt_model_subtype
> +		     & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_MASK)
> +		>> SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_SHIFT;
> +	nrow_desc = (fmt_model_subtype
> +		     & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NROWS_MASK);

No need for parenthesis.

> +
> +	dev_dbg(&client->dev, "format_model_type %s\n",
> +		fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE
> +		? "2 byte" :
> +		fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE
> +		? "4 byte" : "is simply bad");

Simply ? :-)

> +
> +	for (i = 0; i < ncol_desc + nrow_desc; i++) {
> +		u32 desc;
> +		u32 pixelcode;
> +		u32 pixels;
> +		char *which;
> +		char *what;
> +
> +		if (fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE) {
> +			rval = smia_i2c_read_reg(
> +				client,
> +				SMIAPP_REG_U16_FRAME_FORMAT_DESCRIPTOR_2(i),
> +				&desc);
> +			if (rval)
> +				return rval;
> +
> +			pixelcode =
> +				(desc
> +				 & SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_MASK)
> +				>> SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_SHIFT;
> +			pixels = desc & SMIAPP_FRAME_FORMAT_DESC_2_PIXELS_MASK;
> +		} else if (fmt_model_type
> +			   == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE) {
> +			rval = smia_i2c_read_reg(
> +				client,
> +				SMIAPP_REG_U32_FRAME_FORMAT_DESCRIPTOR_4(i),
> +				&desc);
> +			if (rval)
> +				return rval;
> +
> +			pixelcode =
> +				(desc
> +				 & SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_MASK)
> +				>> SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_SHIFT;
> +			pixels = desc & SMIAPP_FRAME_FORMAT_DESC_4_PIXELS_MASK;
> +		} else {
> +			dev_dbg(&client->dev,
> +				"invalid frame format model type %d\n",
> +				fmt_model_type);
> +			return -EINVAL;
> +		}
> +
> +		if (i < ncol_desc)
> +			which = "columns";
> +		else
> +			which = "rows";
> +
> +		switch (pixelcode) {
> +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED:
> +			what = "embedded";
> +			break;
> +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DUMMY:
> +			what = "dummy";
> +			break;
> +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_BLACK:
> +			what = "black";
> +			break;
> +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DARK:
> +			what = "dark";
> +			break;
> +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE:
> +			what = "visible";
> +			break;
> +		default:
> +			what = "invalid";
> +			dev_dbg(&client->dev, "pixelcode %d\n", pixelcode);
> +			break;
> +		}
> +
> +		dev_dbg(&client->dev, "%s pixels: %d %s\n",
> +			what, pixels, which);
> +
> +		if (i < ncol_desc)
> +			continue;
> +
> +		/* Handle row descriptors */
> +		if (pixelcode
> +		    == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED) {
> +			embedded_start = line_count;
> +		} else {
> +			if (pixelcode
> +			    == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE
> +			    || pixels
> +			    >= sensor->limits[
> +				    SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES] / 2) {

I'm not a huge fan of lines larger than 80 columns, but it would make sense
here. This is hard to read. An option would be to shorten all the constants a
bit.

> +				image_start = line_count;
> +			}
> +			if (embedded_start != -1 && embedded_end == -1)
> +				embedded_end = line_count;
> +		}
> +		line_count += pixels;
> +	}
> +
> +	if (embedded_start == -1 || embedded_end == -1)
> +		embedded_start = embedded_end = 0;

One assignment per line please.

> +
> +	dev_dbg(&client->dev, "embedded data from lines %d to %d\n",
> +		embedded_start, embedded_end);
> +	dev_dbg(&client->dev, "image data starts at line %d\n", image_start);
> +
> +	return 0;
> +}
> +
> +/*
> + *
> + * V4L2 Controls handling
> + *
> + */
> +
> +static void __smiapp_update_exposure_limits(struct smiapp_sensor *sensor)
> +{
> +	struct v4l2_ctrl *ctrl = sensor->exposure;
> +	int max;
> +
> +	max = sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
> +		+ sensor->vblank->val -
> +		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MAX_MARGIN];

Just for reference, I would have found

	max = sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
	    + sensor->vblank->val
	    - sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MAX_MARGIN];

to be more readable, but it's obviously your call.

> +
> +	ctrl->maximum = max;
> +	if (ctrl->default_value > max)
> +		ctrl->default_value = max;
> +	if (ctrl->val > max)
> +		ctrl->val = max;
> +	if (ctrl->cur.val > max)
> +		ctrl->cur.val = max;
> +}
> +
> +/*
> + * Order matters.
> + *
> + * 1. Bits-per-pixel, descending.
> + * 2. Bits-per-pixel compressed, descending.
> + * 3. Pixel order, same as in pixel_order_str. Formats for all four pixel
> + *    orders must be defined.
> + */
> +static const struct smiapp_csi_data_format smiapp_csi_data_formats[] = {
> +	{ V4L2_MBUS_FMT_SGRBG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GRBG, },
> +	{ V4L2_MBUS_FMT_SRGGB12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_RGGB, },
> +	{ V4L2_MBUS_FMT_SBGGR12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_BGGR, },
> +	{ V4L2_MBUS_FMT_SGBRG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GBRG, },
> +	{ V4L2_MBUS_FMT_SGRBG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GRBG, },
> +	{ V4L2_MBUS_FMT_SRGGB10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_RGGB, },
> +	{ V4L2_MBUS_FMT_SBGGR10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_BGGR, },
> +	{ V4L2_MBUS_FMT_SGBRG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GBRG, },
> +	{ V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GRBG, },
> +	{ V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_RGGB, },
> +	{ V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_BGGR, },
> +	{ V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GBRG, },
> +};
> +
> +const char *pixel_order_str[] = { "GRBG", "RGGB", "BGGR", "GBRG" };
> +
> +#define to_csi_format_idx(fmt) (((unsigned long)(fmt)			\
> +				 - (unsigned long)smiapp_csi_data_formats) \
> +				/ sizeof(*smiapp_csi_data_formats))
> +
> +static void smiapp_update_mbus_formats(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	int csi_format_idx = to_csi_format_idx(sensor->csi_format) & ~3;
> +	int internal_csi_format_idx =
> +		to_csi_format_idx(sensor->internal_csi_format) & ~3;
> +	int flip = 0;
> +	int pixel_order;

Here again shortening names a bit might help.

> +
> +	if (sensor->hflip) {
> +		if (sensor->hflip->val)
> +			flip |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
> +
> +		if (sensor->vflip->val)
> +			flip |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
> +	}
> +
> +	flip ^= sensor->hvflip_inv_mask;
> +
> +	pixel_order = sensor->default_pixel_order ^ flip;
> +
> +	sensor->mbus_frame_fmts =
> +		sensor->default_mbus_frame_fmts << pixel_order;
> +	sensor->csi_format =
> +		&smiapp_csi_data_formats[csi_format_idx + pixel_order];
> +	sensor->internal_csi_format =
> +		&smiapp_csi_data_formats[internal_csi_format_idx
> +					 + pixel_order];
> +
> +	BUG_ON(max(internal_csi_format_idx, csi_format_idx) + pixel_order
> +	       >= ARRAY_SIZE(smiapp_csi_data_formats));
> +	BUG_ON(min(internal_csi_format_idx, csi_format_idx) < 0);
> +
> +	dev_dbg(&client->dev, "flip %d; new pixel order %s\n",
> +		flip, pixel_order_str[pixel_order]);
> +}
> +
> +static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)
> +{
> +	struct smiapp_sensor *sensor =
> +		container_of(ctrl->handler, struct smiapp_subdev, ctrl_handler)
> +			->sensor;
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	u32 orient;
> +	int exposure;
> +	int rval = 0;
> +
> +	switch (ctrl->id) {
> +	case V4L2_CID_ANALOGUE_GAIN:
> +		return smia_i2c_write_reg(
> +			client,
> +			SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GLOBAL, ctrl->val);
> +
> +	case V4L2_CID_EXPOSURE:
> +		return smia_i2c_write_reg(
> +			client,
> +			SMIAPP_REG_U16_COARSE_INTEGRATION_TIME, ctrl->val);
> +
> +	case V4L2_CID_HFLIP:
> +	case V4L2_CID_VFLIP:
> +		orient = 0;

You can move this line after the streaming check.

> +
> +		if (sensor->streaming)
> +			return -EBUSY;
> +
> +		if (sensor->hflip->val)
> +			orient |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
> +
> +		if (sensor->vflip->val)
> +			orient |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
> +
> +		orient ^= sensor->hvflip_inv_mask;
> +		rval = smia_i2c_write_reg(client,
> +					  SMIAPP_REG_U8_IMAGE_ORIENTATION,
> +					  orient);
> +		if (rval < 0)
> +			return rval;
> +
> +		smiapp_update_mbus_formats(sensor);
> +
> +		return 0;
> +
> +	case V4L2_CID_VBLANK:
> +		exposure = sensor->exposure->val;
> +
> +		__smiapp_update_exposure_limits(sensor);
> +
> +		if (exposure > sensor->exposure->maximum) {
> +			sensor->exposure->val =
> +				sensor->exposure->maximum;
> +			rval = smiapp_set_ctrl(
> +				sensor->exposure);

Shouldn't you call the V4L2 control API here instead ? Otherwise no control
change event will be generated for the exposure time. Will this work as
expected if the user sets the exposure time in the same VIDIOC_S_EXT_CTRLS
call ?

> +		}
> +
> +		if (rval < 0)
> +			return rval;

If you moved this check inside the if you wouldn't have to initialize rval to
0 above.

> +
> +		return smia_i2c_write_reg(
> +			client, SMIAPP_REG_U16_FRAME_LENGTH_LINES,
> +			sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
> +			+ ctrl->val);
> +
> +	case V4L2_CID_HBLANK:
> +		return smia_i2c_write_reg(
> +			client, SMIAPP_REG_U16_LINE_LENGTH_PCK,
> +			sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width
> +			+ ctrl->val);
> +
> +	case V4L2_CID_LINK_FREQ:
> +		if (sensor->streaming)
> +			return -EBUSY;
> +
> +		return smiapp_pll_update(sensor);
> +
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static const struct v4l2_ctrl_ops smiapp_ctrl_ops = {
> +	.s_ctrl = smiapp_set_ctrl,
> +};
> +
> +static int smiapp_init_controls(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	struct v4l2_ctrl_config cfg;
> +	int rval;
> +
> +	rval = v4l2_ctrl_handler_init(&sensor->pixel_array->ctrl_handler, 7);
> +	if (rval)
> +		return rval;
> +	sensor->pixel_array->ctrl_handler.lock = &sensor->mutex;
> +
> +	sensor->analog_gain = v4l2_ctrl_new_std(
> +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> +		V4L2_CID_ANALOGUE_GAIN,
> +		sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN],
> +		sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX],
> +		max_t(int,
> +		      sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_STEP], 1),

Won't max() work ? You might have to use 1U though.

> +		sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN]);
> +
> +	sensor->exposure = v4l2_ctrl_new_std(
> +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> +		V4L2_CID_EXPOSURE,
> +		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN],
> +		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN], 1,
> +		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN]);

Maybe a short comment explaining where this (and other controls below) will be
updated would help future readers to figure out why maximum == minimum.

> +
> +	sensor->hflip = v4l2_ctrl_new_std(
> +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> +		V4L2_CID_HFLIP, 0, 1, 1, 0);
> +	sensor->vflip = v4l2_ctrl_new_std(
> +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> +		V4L2_CID_VFLIP, 0, 1, 1, 0);
> +
> +	sensor->vblank = v4l2_ctrl_new_std(
> +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> +		V4L2_CID_VBLANK, 0, 1, 1, 0);
> +
> +	if (sensor->vblank)
> +		sensor->vblank->flags |= V4L2_CTRL_FLAG_UPDATE;
> +
> +	sensor->hblank = v4l2_ctrl_new_std(
> +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> +		V4L2_CID_HBLANK, 0, 1, 1, 0);
> +
> +	if (sensor->hblank)
> +		sensor->hblank->flags |= V4L2_CTRL_FLAG_UPDATE;
> +
> +	sensor->pixel_rate_parray = v4l2_ctrl_new_std(
> +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> +		V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
> +
> +	if (sensor->pixel_array->ctrl_handler.error) {
> +		dev_err(&client->dev,
> +			"pixel array controls initialization failed (%d)\n",
> +			sensor->pixel_array->ctrl_handler.error);

Shouldn't you call v4l2_ctrl_handler_free() here ?

> +		return sensor->pixel_array->ctrl_handler.error;
> +	}
> +
> +	sensor->pixel_array->sd.ctrl_handler =
> +		&sensor->pixel_array->ctrl_handler;
> +
> +	v4l2_ctrl_cluster(2, &sensor->hflip);

Shouldn't you move this before the control handler check ?

> +
> +	rval = v4l2_ctrl_handler_init(&sensor->binner->ctrl_handler, 0);
> +	if (rval)
> +		return rval;

The pixel array control handler won't be freed if this fails. Same for the
other error cases below.

> +	sensor->binner->ctrl_handler.lock = &sensor->mutex;

Just curious, what's the point in having an empty control handler ? Same
question for the scaler. Is it because sensor->src will end up pointing to
either the binner or scaler ? Maybe you could then just initialize
sensor->src->ctrl_handler then.

> +
> +	if (sensor->scaler) {
> +		rval = v4l2_ctrl_handler_init(&sensor->scaler->ctrl_handler, 0);
> +		if (rval)
> +			return rval;
> +		sensor->scaler->ctrl_handler.lock = &sensor->mutex;
> +	}
> +
> +	memset(&cfg, 0, sizeof(cfg));
> +
> +	cfg.ops = &smiapp_ctrl_ops;
> +	cfg.id = V4L2_CID_LINK_FREQ;
> +	cfg.type = V4L2_CTRL_TYPE_INTEGER_MENU;
> +	while (sensor->platform_data->op_sys_clock[cfg.max])
> +		cfg.max++;
> +	cfg.max--;

Maybe

	while (sensor->platform_data->op_sys_clock[cfg.max+1])
		cfg.max++;

? Not sure if the compiler will optimize that better though.

> +	cfg.qmenu_int = sensor->platform_data->op_sys_clock;
> +
> +	sensor->link_freq = v4l2_ctrl_new_custom(
> +		&sensor->src->ctrl_handler, &cfg, NULL);
> +
> +	sensor->pixel_rate_csi = v4l2_ctrl_new_std(
> +		&sensor->src->ctrl_handler, &smiapp_ctrl_ops,
> +		V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
> +
> +	if (sensor->src->ctrl_handler.error) {
> +		dev_err(&client->dev,
> +			"src controls initialization failed (%d)\n",
> +			sensor->src->ctrl_handler.error);
> +		return sensor->src->ctrl_handler.error;
> +	}
> +
> +	sensor->src->sd.ctrl_handler =
> +		&sensor->src->ctrl_handler;
> +
> +	return 0;
> +}
> +
> +static void smiapp_free_controls(struct smiapp_sensor *sensor)
> +{
> +	int i;

unsigned ?

> +
> +	for (i = 0; i < sensor->sds_used; i++)
> +		v4l2_ctrl_handler_free(&sensor->sds[i].ctrl_handler);
> +}
> +
> +static int smiapp_get_limits(struct smiapp_sensor *sensor, int const
> *limit, +			     int n)

unsigned int n ?

> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	int i, val;

unsigned int i;
u32 val;

?

> +	int rval;
> +
> +	for (i = 0; i < n; i++) {
> +		rval = smia_i2c_read_reg(
> +			client, smiapp_reg_limits[limit[i]].addr, &val);
> +		if (rval) {
> +			dev_dbg(&client->dev, "error reading register %4.4x\n",
> +				(u16)smiapp_reg_limits[limit[i]].addr);

What about moving the error message to smia_i2c_read_reg ?

> +			return rval;
> +		}
> +		sensor->limits[limit[i]] = val;
> +		dev_dbg(&client->dev, "0x%8.8x \"%s\" = %d, 0x%x\n",
> +			smiapp_reg_limits[limit[i]].addr,
> +			smiapp_reg_limits[limit[i]].what, val, val);
> +	}
> +
> +	return 0;
> +}
> +
> +static int smiapp_get_all_limits(struct smiapp_sensor *sensor)
> +{
> +	int rval, i;

unsigned int i; ?

> +
> +	for (i = 0; i < SMIAPP_LIMIT_LAST; i++) {
> +		rval = smiapp_get_limits(sensor, &i, 1);
> +		if (rval < 0)
> +			return rval;
> +	}
> +
> +	if (sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN] == 0)
> +		smiapp_replace_limit(sensor, SMIAPP_LIMIT_SCALER_N_MIN, 16);
> +
> +	return 0;
> +}
> +
> +static int smiapp_get_limits_binning(struct smiapp_sensor *sensor)
> +{
> +	static u32 const limits[] = {
> +		SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN,
> +		SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN,
> +		SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN,
> +		SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN,
> +		SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN,
> +		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN_BIN,
> +		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN,
> +	};
> +	static u32 const limits_replace[] = {
> +		SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES,
> +		SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES,
> +		SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK,
> +		SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK,
> +		SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK,
> +		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN,
> +		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN,
> +	};
> +
> +	if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY] ==
> +	    SMIAPP_BINNING_CAPABILITY_NO) {
> +		int i;

unsigned int i; (and in the other functions below) ?

> +
> +		for (i = 0; i < ARRAY_SIZE(limits); i++)
> +			sensor->limits[limits[i]] =
> +				sensor->limits[limits_replace[i]];
> +
> +		return 0;
> +	}
> +
> +	return smiapp_get_limits(sensor, limits, ARRAY_SIZE(limits));
> +}
> +
> +static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	unsigned int type, n;
> +	int i, rval, pixel_order;
> +
> +	rval = smia_i2c_read_reg(
> +		client, SMIAPP_REG_U8_DATA_FORMAT_MODEL_TYPE, &type);
> +	if (rval)
> +		return rval;
> +
> +	dev_dbg(&client->dev, "data_format_model_type %d\n", type);
> +
> +	rval = smia_i2c_read_reg(client, SMIAPP_REG_U8_PIXEL_ORDER,
> +				 &pixel_order);
> +	if (rval)
> +		return rval;
> +
> +	if (pixel_order >= ARRAY_SIZE(pixel_order_str)) {
> +		dev_dbg(&client->dev, "bad pixel order %d\n", pixel_order);
> +		return -EINVAL;
> +	}
> +
> +	dev_dbg(&client->dev, "pixel order %d (%s)\n", pixel_order,
> +		pixel_order_str[pixel_order]);
> +
> +	switch (type) {
> +	case SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL:
> +		n = SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL_N;
> +		break;
> +	case SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED:
> +		n = SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED_N;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	sensor->default_pixel_order = pixel_order;
> +	sensor->mbus_frame_fmts = 0;
> +
> +	for (i = 0; i < n; i++) {
> +		int fmt, j;

j can be unsigned as well, this isn't restricted to i :-)

> +
> +		rval = smia_i2c_read_reg(
> +			client,
> +			SMIAPP_REG_U16_DATA_FORMAT_DESCRIPTOR(i), &fmt);
> +		if (rval)
> +			return rval;
> +
> +		dev_dbg(&client->dev, "bpp %d, compressed %d\n",
> +			fmt >> 8, (u8)fmt);
> +
> +		for (j = 0; j < ARRAY_SIZE(smiapp_csi_data_formats); j++) {
> +			const struct smiapp_csi_data_format *f =
> +				&smiapp_csi_data_formats[j];
> +
> +			if (f->pixel_order != SMIAPP_PIXEL_ORDER_GRBG)
> +				continue;
> +
> +			if (f->width != fmt >> 8 || f->compressed != (u8)fmt)
> +				continue;
> +
> +			dev_dbg(&client->dev, "jolly good! %d\n", j);
> +
> +			sensor->default_mbus_frame_fmts |= 1 << j;
> +			if (!sensor->csi_format) {
> +				sensor->csi_format = f;
> +				sensor->internal_csi_format = f;
> +			}
> +		}
> +	}
> +
> +	if (!sensor->csi_format) {
> +		dev_err(&client->dev, "no supported mbus code found\n");
> +		return -EINVAL;
> +	}
> +
> +	smiapp_update_mbus_formats(sensor);
> +
> +	return 0;
> +}
> +
> +static void smiapp_update_blanking(struct smiapp_sensor *sensor)
> +{
> +	struct v4l2_ctrl *vblank = sensor->vblank, *hblank = sensor->hblank;

Two lines please.

> +
> +	vblank->minimum =
> +		max_t(int,
> +		      sensor->limits[SMIAPP_LIMIT_MIN_FRAME_BLANKING_LINES],
> +		      sensor->limits[SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN] -
> +		      sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height);
> +	vblank->maximum =
> +		sensor->limits[SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN] -
> +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height;
> +
> +	vblank->val = clamp_t(int, vblank->val,
> +			      vblank->minimum, vblank->maximum);
> +	vblank->default_value = vblank->minimum;
> +	vblank->val = vblank->val;
> +	vblank->cur.val = vblank->val;
> +
> +	hblank->minimum =
> +		max_t(int,
> +		      sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN] -
> +		      sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width,
> +		      sensor->limits[SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN]);
> +	hblank->maximum =
> +		sensor->limits[SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN] -
> +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width;
> +
> +	hblank->val = clamp_t(int, hblank->val,
> +			      hblank->minimum, hblank->maximum);
> +	hblank->default_value = hblank->minimum;
> +	hblank->val = hblank->val;
> +	hblank->cur.val = hblank->val;
> +
> +	__smiapp_update_exposure_limits(sensor);
> +}
> +
> +static int smiapp_update_mode(struct smiapp_sensor *sensor)
> +{

This function isn't protected by the sensor mutex when called from s_power,
but it changes controls. The other call paths seem OK, but you might want to
double-check them.

> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	int binning_mode;
> +	int rval;
> +
> +	dev_dbg(&client->dev, "frame size: %dx%d\n",
> +		sensor->src->crop[SMIAPP_PAD_SOURCE].width,
> +		sensor->src->crop[SMIAPP_PAD_SOURCE].height);
> +	dev_dbg(&client->dev, "csi format width: %d\n",
> +		sensor->csi_format->width);
> +
> +	/* Binning has to be set up here; it affects limits */
> +	if (sensor->binning_horizontal == 1 &&
> +	    sensor->binning_vertical == 1) {
> +		binning_mode = 0;
> +	} else {
> +		u8 binning_type =
> +			(sensor->binning_horizontal << 4)
> +			| sensor->binning_vertical;
> +
> +		rval = smia_i2c_write_reg(
> +			client, SMIAPP_REG_U8_BINNING_TYPE, binning_type);
> +		if (rval < 0)
> +			return rval;
> +
> +		binning_mode = 1;
> +	}
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U8_BINNING_MODE, binning_mode);
> +	if (rval < 0)
> +		return rval;
> +
> +	/* Get updated limits due to binning */
> +	rval = smiapp_get_limits_binning(sensor);
> +	if (rval < 0)
> +		return rval;
> +
> +	rval = smiapp_pll_update(sensor);
> +	if (rval < 0)
> +		return rval;
> +
> +	/* Output from pixel array, including blanking */
> +	smiapp_update_blanking(sensor);
> +
> +	dev_dbg(&client->dev, "vblank\t\t%d\n", sensor->vblank->val);
> +	dev_dbg(&client->dev, "hblank\t\t%d\n", sensor->hblank->val);
> +
> +	dev_dbg(&client->dev, "real timeperframe\t100/%d\n",
> +		sensor->pll.vt_pix_clk_freq_hz /
> +		((sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width
> +		  + sensor->hblank->val) *
> +		 (sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
> +		  + sensor->vblank->val) / 100));
> +
> +	return 0;
> +}
> +
> +/*
> + *
> + * SMIA++ NVM handling
> + *
> + */
> +static int smiapp_read_nvm(struct smiapp_sensor *sensor,
> +			   unsigned char *nvm)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	u32 i, s, p, np, v;
> +	int rval;
> +
> +	np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;

DIV_ROUND_UP() ? Or is sensor->nvm_size guaranteed to be a multiple of
SMIAPP_NVM_PAGE_SIZE ?

> +	for (p = 0; p < np; p++) {
> +		rval = smia_i2c_write_reg(
> +			client,
> +			SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT, p);
> +		if (rval)
> +			goto out;
> +
> +		rval = smia_i2c_write_reg(client,
> +					  SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL,
> +					  SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN |
> +					  SMIAPP_DATA_TRANSFER_IF_1_CTRL_RD_EN);
> +		if (rval)
> +			goto out;
> +
> +		i = 1000;
> +		do {
> +			rval = smia_i2c_read_reg(client,
> +				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s);
> +
> +			if (rval)
> +				goto out;
> +
> +			if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
> +				break;
> +
> +			if (--i == 0)
> +				goto out;
> +
> +		} while (1);

I'd use a for loop on i. BTW, isn't 1000 a bit high ?

> +
> +		for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {
> +			rval = smia_i2c_read_reg(client,
> +				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0 + i,
> +				&v);
> +			if (rval)
> +				goto out;
> +
> +			*nvm++ = v;
> +		}
> +	}
> +
> +out:
> +	rval |= smia_i2c_write_reg(client,
> +				   SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL, 0);

Could this be optimized away by the compiler, as the return value of this
function is only checked against 0 ?

> +	return rval;
> +}
> +
> +/*
> + *
> + * SMIA++ CCI address control
> + *
> + */
> +static int smiapp_change_cci_addr(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	int rval;
> +	u32 val;
> +
> +	client->addr = sensor->platform_data->i2c_addr_dfl;
> +
> +	rval = smia_i2c_write_reg(client,
> +				  SMIAPP_REG_U8_CCI_ADDRESS_CONTROL,
> +				  sensor->platform_data->i2c_addr_alt << 1);
> +	if (rval) {
> +		client->addr = sensor->platform_data->i2c_addr_alt;

Why do you set the client address to the alternate one if the call failed ?

> +		return rval;
> +	}
> +
> +	client->addr = sensor->platform_data->i2c_addr_alt;
> +
> +	/* verify addr change went ok */
> +	rval = smia_i2c_read_reg(client,
> +				 SMIAPP_REG_U8_CCI_ADDRESS_CONTROL, &val);
> +	if (rval)
> +		return rval;
> +
> +	if (val != sensor->platform_data->i2c_addr_alt << 1)
> +		return -ENODEV;
> +
> +	return 0;
> +}
> +
> +/*
> + *
> + * SMIA++ Mode Control
> + *
> + */
> +static int smiapp_setup_flash_strobe(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	struct smiapp_flash_strobe_parms *strobe_setup;
> +	unsigned int ext_freq = sensor->platform_data->ext_clk;
> +	int rval;
> +	u32 tmp;
> +	u32 strobe_adjustment;
> +	u32 strobe_width_high_rs;
> +
> +	strobe_setup = sensor->platform_data->strobe_setup;
> +
> +	/*
> +	 * How to calculate registers related to strobe length. Please
> +	 * do not change, or if you do at least know what you're
> +	 * doing. :-)

You could reindent the text here up to 80 columns, that would shorten the
comment a bit.

> +	 *
> +	 * Sakari Ailus <sakari.ailus@maxwell.research.nokia.com> 2010-10-25
> +	 *
> +	 * flash_strobe_length [us] / 10^6 = (tFlash_strobe_width_ctrl
> +	 *	/ EXTCLK freq [Hz]) * flash_strobe_adjustment
> +	 *
> +	 * tFlash_strobe_width_ctrl E N, [1 - 0xffff]
> +	 * flash_strobe_adjustment E N, [1 - 0xff]
> +	 *
> +	 * The formula above is written as below to keep it on one
> +	 * line:
> +	 *
> +	 * l / 10^6 = w / e * a
> +	 *
> +	 * Let's mark w * a by x:
> +	 *
> +	 * x = w * a
> +	 *
> +	 * Thus, we get:
> +	 *
> +	 * x = l * e / 10^6
> +	 *
> +	 * The strobe width must be at least as long as requested,
> +	 * thus rounding upwards is needed.
> +	 *
> +	 * x = (l * e + 10^6 - 1) / 10^6
> +	 * -----------------------------
> +	 *
> +	 * Maximum possible accuracy is wanted at all times. Thus keep
> +	 * a as small as possible.
> +	 *
> +	 * Calculate a, assuming maximum w, with rounding upwards:
> +	 *
> +	 * a = (x + (2^16 - 1) - 1) / (2^16 - 1)
> +	 * -------------------------------------
> +	 *
> +	 * Thus, we also get w, with that a, with rounding upwards:
> +	 *
> +	 * w = (x + a - 1) / a
> +	 * -------------------
> +	 *
> +	 * To get limits:
> +	 *
> +	 * x E [1, (2^16 - 1) * (2^8 - 1)]
> +	 *
> +	 * Substituting maximum x to the original formula (with rounding),
> +	 * the maximum l is thus
> +	 *
> +	 * (2^16 - 1) * (2^8 - 1) * 10^6 = l * e + 10^6 - 1
> +	 *
> +	 * l = (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / e
> +	 * --------------------------------------------------
> +	 *
> +	 * flash_strobe_length must be clamped between 1 and
> +	 * (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / EXTCLK freq.
> +	 *
> +	 * Then,
> +	 *
> +	 * flash_strobe_adjustment = ((flash_strobe_length *
> +	 *	EXTCLK freq + 10^6 - 1) / 10^6 + (2^16 - 1) - 1) / (2^16 - 1)
> +	 *
> +	 * tFlash_strobe_width_ctrl = ((flash_strobe_length *
> +	 *	EXTCLK freq + 10^6 - 1) / 10^6 +
> +	 *	flash_strobe_adjustment - 1) / flash_strobe_adjustment
> +	 */
> +	tmp = div_u64(1000000ULL * ((1 << 16) - 1) * ((1 << 8) - 1) -
> +		      1000000 + 1, ext_freq);
> +	strobe_setup->strobe_width_high_us =
> +		clamp_t(u32, strobe_setup->strobe_width_high_us, 1, tmp);
> +
> +	tmp = div_u64(((u64)strobe_setup->strobe_width_high_us * (u64)ext_freq +
> +			1000000 - 1), 1000000ULL);
> +	strobe_adjustment = (tmp + (1 << 16) - 1 - 1) / ((1 << 16) - 1);
> +	strobe_width_high_rs = (tmp + strobe_adjustment - 1) /
> +				strobe_adjustment;
> +
> +	rval = smia_i2c_write_reg(client,
> +				  SMIAPP_REG_U8_FLASH_MODE_RS,
> +				  strobe_setup->mode);
> +	if (rval < 0)
> +		goto out;
> +
> +	rval = smia_i2c_write_reg(client,
> +				  SMIAPP_REG_U8_FLASH_STROBE_ADJUSTMENT,
> +				  strobe_adjustment);
> +	if (rval < 0)
> +		goto out;
> +
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_RS_CTRL,
> +		strobe_width_high_rs);
> +	if (rval < 0)
> +		goto out;
> +
> +	rval = smia_i2c_write_reg(client,
> +				  SMIAPP_REG_U16_TFLASH_STROBE_DELAY_RS_CTRL,
> +				  strobe_setup->strobe_delay);
> +	if (rval < 0)
> +		goto out;
> +
> +	rval = smia_i2c_write_reg(client,
> +				  SMIAPP_REG_U16_FLASH_STROBE_START_POINT,
> +				  strobe_setup->stobe_start_point);
> +	if (rval < 0)
> +		goto out;
> +
> +	rval = smia_i2c_write_reg(client,
> +				  SMIAPP_REG_U8_FLASH_TRIGGER_RS,
> +				  strobe_setup->trigger);
> +
> +out:
> +	sensor->platform_data->strobe_setup->trigger = 0;
> +
> +	return rval;
> +}
> +
> +/*
> ---------------------------------------------------------------------------
> -- + * Power management
> + */
> +
> +static int smiapp_power_on(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	int sleep;
> +	int rval;
> +
> +	rval = regulator_enable(sensor->vana);
> +	if (rval) {
> +		dev_err(&client->dev, "failed to enable vana regulator\n");
> +		return rval;
> +	}
> +	usleep_range(1000, 1000);

That's a very tight range :-)

> +
> +	rval = sensor->platform_data->set_xclk(&sensor->src->sd,
> +					sensor->platform_data->ext_clk);
> +	if (rval < 0) {
> +		dev_dbg(&client->dev, "failed to set xclk\n");
> +		goto out_xclk_fail;
> +	}
> +	usleep_range(1000, 1000);
> +
> +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> +		gpio_set_value(sensor->platform_data->xshutdown, 1);
> +
> +	sleep = SMIAPP_RESET_DELAY(sensor->platform_data->ext_clk);
> +	usleep_range(sleep, sleep);
> +
> +	/*
> +	 * Failures to respond to the address change command have been noticed.
> +	 * Those failures seem to be caused by the sensor requiring a longer
> +	 * boot time than advertised. An additional 10ms delay seems to work
> +	 * around the issue, but the SMIA++ I2C write retry hack makes the delay
> +	 * unnecessary. The failures need to be investigated to find a proper
> +	 * fix, and a delay will likely need to be added here if the I2C write
> +	 * retry hack is reverted before the root cause of the boot time issue
> +	 * is found.
> +	 */
> +
> +	if (sensor->platform_data->i2c_addr_alt) {
> +		rval = smiapp_change_cci_addr(sensor);
> +		if (rval) {
> +			dev_err(&client->dev, "cci address change error\n");
> +			goto out_cci_addr_fail;
> +		}
> +	}
> +
> +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_SOFTWARE_RESET,
> +				  SMIAPP_SOFTWARE_RESET);
> +	if (rval < 0) {
> +		dev_err(&client->dev, "software reset failed\n");
> +		goto out_cci_addr_fail;
> +	}
> +
> +	if (sensor->platform_data->i2c_addr_alt) {
> +		rval = smiapp_change_cci_addr(sensor);
> +		if (rval) {
> +			dev_err(&client->dev, "cci address change error\n");
> +			goto out_cci_addr_fail;
> +		}
> +	}
> +
> +	rval = smia_i2c_write_reg(client,
> +				  SMIAPP_REG_U16_COMPRESSION_MODE,
> +				  SMIAPP_COMPRESSION_MODE_SIMPLE_PREDICTOR);
> +	if (rval) {
> +		dev_err(&client->dev, "compression mode set failed\n");
> +		goto out_cci_addr_fail;
> +	}
> +
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U16_EXTCLK_FREQUENCY_MHZ,
> +		sensor->platform_data->ext_clk / (1000000 / (1 << 8)));
> +	if (rval) {
> +		dev_err(&client->dev, "extclk frequency set failed\n");
> +		goto out_cci_addr_fail;
> +	}
> +
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U8_CSI_LANE_MODE,
> +		sensor->platform_data->lanes - 1);
> +	if (rval) {
> +		dev_err(&client->dev, "csi lane mode set failed\n");
> +		goto out_cci_addr_fail;
> +	}
> +
> +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_FAST_STANDBY_CTRL,
> +				  SMIAPP_FAST_STANDBY_CTRL_IMMEDIATE);
> +	if (rval) {
> +		dev_err(&client->dev, "fast standby set failed\n");
> +		goto out_cci_addr_fail;
> +	}
> +
> +	/* DPHY control done by sensor based on requested link rate */
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U8_DPHY_CTRL, SMIAPP_DPHY_CTRL_UI);
> +	if (rval < 0) {
> +		dev_err(&client->dev, "set dphy_ctrl_ui failed\n");
> +		goto out_cci_addr_fail;
> +	}
> +
> +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_CSI_SIGNALLING_MODE,
> +				  sensor->platform_data->csi_signalling_mode);
> +	if (rval) {
> +		dev_err(&client->dev, "csi signalling mode set failed\n");
> +		goto out_cci_addr_fail;
> +	}
> +
> +	/* DPHY control done by sensor based on requested link rate */
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U8_DPHY_CTRL, SMIAPP_DPHY_CTRL_UI);
> +	if (rval < 0)
> +		return rval;

Is there a need to the SMIAPP_REG_U8_DPHY_CTRL register twice to the same
value ?

> +
> +	rval = smiapp_call_quirk(sensor, post_poweron);
> +	if (rval) {
> +		dev_err(&client->dev, "post_poweron quirks failed\n");
> +		goto out_cci_addr_fail;
> +	}
> +
> +	return 0;
> +
> +out_cci_addr_fail:
> +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> +		gpio_set_value(sensor->platform_data->xshutdown, 0);
> +	sensor->platform_data->set_xclk(&sensor->src->sd, 0);
> +
> +out_xclk_fail:
> +	regulator_disable(sensor->vana);
> +	return rval;
> +}
> +
> +static void smiapp_power_off(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +
> +	/*
> +	 * Currently power/clock to lens are enable/disabled separately
> +	 * but they are essentially the same signals. So if the sensor is
> +	 * powered off while the lens is powered on the sensor does not
> +	 * really see a power off and next time the cci address change
> +	 * will fail. So do a soft reset explicitly here.
> +	 */
> +	if (sensor->platform_data->i2c_addr_alt)
> +		smia_i2c_write_reg(client,
> +				   SMIAPP_REG_U8_SOFTWARE_RESET,
> +				   SMIAPP_SOFTWARE_RESET);
> +
> +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> +		gpio_set_value(sensor->platform_data->xshutdown, 0);
> +	sensor->platform_data->set_xclk(&sensor->src->sd, 0);
> +	usleep_range(5000, 5000);
> +	regulator_disable(sensor->vana);
> +	sensor->streaming = 0;
> +}
> +
> +static int smiapp_set_power(struct v4l2_subdev *subdev, int on)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int ret;
> +
> +	/* If the power count is modified from 0 to != 0 or from != 0 to 0,
> +	 * update the power state.
> +	 */
> +	if (sensor->power_count == !on) {
> +		if (on) {
> +			ret = smiapp_power_on(sensor);
> +			if (ret < 0)
> +				return ret;
> +			ret = smiapp_update_mode(sensor);
> +			if (ret < 0)
> +				return ret;
> +		} else {
> +			smiapp_power_off(sensor);
> +		}
> +	}
> +
> +	/* Update the power count. */
> +	sensor->power_count += on ? 1 : -1;
> +	WARN_ON(sensor->power_count < 0);
> +
> +	return 0;
> +}
> +
> +/*
> ---------------------------------------------------------------------------
> -- + * Video stream management
> + */
> +
> +static int smiapp_start_streaming(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	int rval;
> +
> +	mutex_lock(&sensor->mutex);
> +
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U16_CSI_DATA_FORMAT,
> +		(sensor->csi_format->width << 8) |
> +		sensor->csi_format->compressed);
> +	if (rval)
> +		goto out;
> +
> +	rval = smiapp_pll_configure(sensor);
> +	if (rval)
> +		goto out;
> +
> +	/* Analog crop start coordinates */
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U16_X_ADDR_START,
> +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].left);
> +	if (rval < 0)
> +		goto out;
> +
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U16_Y_ADDR_START,
> +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].top);
> +	if (rval < 0)
> +		goto out;
> +
> +	/* Analog crop end coordinates */
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U16_X_ADDR_END,
> +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].left
> +		+ sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width - 1);
> +	if (rval < 0)
> +		goto out;
> +
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U16_Y_ADDR_END,
> +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].top
> +		+ sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height - 1);
> +	if (rval < 0)
> +		goto out;
> +
> +	/*
> +	 * Output from pixel array, including blanking, is set using
> +	 * controls below. No need to set here.
> +	 */
> +
> +	/* Digital crop */
> +	if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
> +	    == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
> +		rval = smia_i2c_write_reg(
> +			client, SMIAPP_REG_U16_DIGITAL_CROP_X_OFFSET,
> +			sensor->scaler->crop[SMIAPP_PAD_SINK].left);
> +		if (rval < 0)
> +			goto out;
> +
> +		rval = smia_i2c_write_reg(
> +			client, SMIAPP_REG_U16_DIGITAL_CROP_Y_OFFSET,
> +			sensor->scaler->crop[SMIAPP_PAD_SINK].top);
> +		if (rval < 0)
> +			goto out;
> +
> +		rval = smia_i2c_write_reg(
> +			client, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_WIDTH,
> +			sensor->scaler->crop[SMIAPP_PAD_SINK].width);
> +		if (rval < 0)
> +			goto out;
> +
> +		rval = smia_i2c_write_reg(
> +			client, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_HEIGHT,
> +			sensor->scaler->crop[SMIAPP_PAD_SINK].height);
> +		if (rval < 0)
> +			goto out;
> +	}
> +
> +	/* Scaling */
> +	if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> +	    != SMIAPP_SCALING_CAPABILITY_NONE) {
> +		rval = smia_i2c_write_reg(
> +			client, SMIAPP_REG_U16_SCALING_MODE,
> +			sensor->scaling_mode);
> +		if (rval < 0)
> +			goto out;
> +
> +		if (sensor->scale_m
> +		    != sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]) {
> +			rval = smia_i2c_write_reg(
> +				client, SMIAPP_REG_U16_SCALE_M,
> +				sensor->scale_m);
> +			if (rval < 0)
> +				goto out;
> +		}

I could be wrong, but it seems to me like the scaling M factor won't be 
updated
properly if you first enable/disable streaming with a non-default M factor,
reconfigure the sensor to use the default value, and then start streaming
again.

> +	}
> +
> +	/* Output size from sensor */
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U16_X_OUTPUT_SIZE,
> +		sensor->src->crop[SMIAPP_PAD_SOURCE].width);
> +	if (rval < 0)
> +		goto out;
> +	rval = smia_i2c_write_reg(
> +		client, SMIAPP_REG_U16_Y_OUTPUT_SIZE,
> +		sensor->src->crop[SMIAPP_PAD_SOURCE].height);
> +	if (rval < 0)
> +		goto out;
> +
> +	if ((sensor->flash_capability &
> +	     (SMIAPP_FLASH_MODE_CAPABILITY_SINGLE_STROBE |
> +	      SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE)) &&
> +	    sensor->platform_data->strobe_setup != NULL &&
> +	    sensor->platform_data->strobe_setup->trigger != 0) {
> +		rval = smiapp_setup_flash_strobe(sensor);
> +		if (rval)
> +			goto out;
> +	}
> +
> +	rval = smiapp_call_quirk(sensor, pre_streamon);
> +	if (rval) {
> +		dev_err(&client->dev, "pre_streamon quirks failed\n");
> +		goto out;
> +	}
> +
> +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_MODE_SELECT,
> +				  SMIAPP_MODE_SELECT_STREAMING);
> +
> +out:
> +	mutex_unlock(&sensor->mutex);
> +
> +	return rval;
> +}
> +
> +static int smiapp_stop_streaming(struct smiapp_sensor *sensor)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> +	int rval;
> +
> +	mutex_lock(&sensor->mutex);
> +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_MODE_SELECT,
> +		SMIAPP_MODE_SELECT_SOFTWARE_STANDBY);
> +	if (rval)
> +		goto out;
> +
> +	rval = smiapp_call_quirk(sensor, post_streamoff);
> +	if (rval)
> +		dev_err(&client->dev, "post_streamoff quirks failed\n");
> +
> +out:
> +	mutex_unlock(&sensor->mutex);
> +	return rval;
> +}
> +
> +/*
> ---------------------------------------------------------------------------
> -- + * V4L2 subdev video operations
> + */
> +
> +static int smiapp_set_stream(struct v4l2_subdev *subdev, int enable)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int rval;
> +
> +	if (sensor->streaming == enable)
> +		return 0;
> +
> +	if (enable) {
> +		sensor->streaming = 1;
> +		rval = smiapp_start_streaming(sensor);
> +		if (rval < 0)
> +			sensor->streaming = 0;

Is there a reason not to just set sensor->streaming after calling
smiapp_start_streaming() ?

> +	} else {
> +		rval = smiapp_stop_streaming(sensor);
> +		sensor->streaming = 0;
> +	}
> +
> +	return rval;
> +}
> +
> +static int smiapp_enum_mbus_code(struct v4l2_subdev *subdev,
> +				 struct v4l2_subdev_fh *fh,
> +				 struct v4l2_subdev_mbus_code_enum *code)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int i, idx = -1;
> +	int rval = -EINVAL;
> +
> +	mutex_lock(&sensor->mutex);
> +
> +	dev_err(&client->dev, "subdev %s, pad %d, index %d\n",
> +		subdev->name, code->pad, code->index);
> +
> +	if (subdev != &sensor->src->sd
> +	    || code->pad != SMIAPP_PAD_SOURCE) {
> +		if (code->index)
> +			goto out;
> +
> +		code->code = sensor->internal_csi_format->code;
> +		rval = 0;
> +		goto out;
> +	}
> +
> +	for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
> +		if (sensor->mbus_frame_fmts & (1 << i))
> +			idx++;
> +
> +		if (idx == code->index) {
> +			code->code = smiapp_csi_data_formats[i].code;
> +			dev_err(&client->dev, "found index %d, i %d, code %x\n",
> +				code->index, i, code->code);
> +			rval = 0;
> +			goto out;

break; would do :-)

> +		}
> +	}
> +
> +out:
> +	mutex_unlock(&sensor->mutex);
> +
> +	return rval;
> +}
> +
> +static int __smiapp_get_format(struct v4l2_subdev *subdev,
> +			     struct v4l2_subdev_fh *fh,
> +			     struct v4l2_subdev_format *fmt)
> +{
> +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +
> +	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> +		fmt->format = *v4l2_subdev_get_try_format(fh, fmt->pad);
> +	} else {
> +		struct v4l2_rect *r;
> +
> +		if (fmt->pad == SMIAPP_PAD_SOURCE)
> +			r = &ssd->crop[SMIAPP_PAD_SOURCE];
> +		else
> +			r = &ssd->sink_fmt;
> +
> +		fmt->format.width = r->width;
> +		fmt->format.height = r->height;
> +		if (subdev == &sensor->src->sd
> +		    && fmt->pad == SMIAPP_PAD_SOURCE)
> +			fmt->format.code = sensor->csi_format->code;
> +		else
> +			fmt->format.code = sensor->internal_csi_format->code;
> +	}
> +
> +	return 0;
> +}
> +
> +static int smiapp_get_format(struct v4l2_subdev *subdev,
> +			     struct v4l2_subdev_fh *fh,
> +			     struct v4l2_subdev_format *fmt)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int rval;
> +
> +	mutex_lock(&sensor->mutex);
> +	rval = __smiapp_get_format(subdev, fh, fmt);
> +	mutex_unlock(&sensor->mutex);
> +
> +	return rval;
> +}
> +
> +static void smiapp_get_crop_compose(struct v4l2_subdev *subdev,
> +				    struct v4l2_subdev_fh *fh,
> +				    struct v4l2_rect **crops,
> +				    struct v4l2_rect **comps, int which)
> +{
> +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> +	int i;
> +
> +	if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> +		for (i = 0; i < subdev->entity.num_pads; i++)
> +			if (crops)
> +				crops[i] = &ssd->crop[i];

You could move the if outside the for.

> +		if (comps)
> +			*comps = &ssd->compose;
> +	} else {
> +		for (i = 0; i < subdev->entity.num_pads; i++)
> +			if (crops) {
> +				crops[i] = v4l2_subdev_get_try_crop(fh, i);
> +				BUG_ON(!crops[i]);
> +			}

Same here.

> +		if (comps) {
> +			*comps = v4l2_subdev_get_try_compose(fh,
> +							     SMIAPP_PAD_SINK);
> +			BUG_ON(!*comps);
> +		}
> +	}
> +}
> +
> +/* Changes require propagation only on sink pad. */
> +static void smiapp_propagate(struct v4l2_subdev *subdev,
> +			     struct v4l2_subdev_fh *fh, int which,
> +			     int target)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> +	struct v4l2_rect *comp, *crops[SMIAPP_PADS];
> +
> +	smiapp_get_crop_compose(subdev, fh, crops, &comp, which);
> +
> +	switch (target) {
> +	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
> +		comp->width = crops[SMIAPP_PAD_SINK]->width;
> +		comp->height = crops[SMIAPP_PAD_SINK]->height;
> +		if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> +			if (ssd == sensor->scaler) {
> +				sensor->scale_m =
> +					sensor->limits[
> +						SMIAPP_LIMIT_SCALER_N_MIN];
> +				sensor->scaling_mode =
> +					SMIAPP_SCALING_MODE_NONE;
> +			} else if (ssd == sensor->binner) {
> +				sensor->binning_horizontal = 1;
> +				sensor->binning_vertical = 1;
> +			}
> +		}
> +		/* Fall through */
> +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
> +		*crops[SMIAPP_PAD_SOURCE] = *comp;
> +		break;
> +	default:
> +		BUG();
> +	}
> +}
> +
> +static int smiapp_set_format(struct v4l2_subdev *subdev,
> +			     struct v4l2_subdev_fh *fh,
> +			     struct v4l2_subdev_format *fmt)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> +	struct v4l2_rect *crops[SMIAPP_PADS];
> +	int i = 0;

There's no need to initialize i to 0.

> +
> +	mutex_lock(&sensor->mutex);
> +
> +	smiapp_get_crop_compose(subdev, fh, crops, NULL, fmt->which);
> +
> +	if (subdev == &sensor->src->sd && fmt->pad == SMIAPP_PAD_SOURCE) {
> +		for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
> +			if (sensor->mbus_frame_fmts & (1 << i) &&
> +			    smiapp_csi_data_formats[i].code
> +			    == fmt->format.code) {
> +				if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> +					sensor->csi_format =
> +						&smiapp_csi_data_formats[i];
> +				break;
> +			}
> +		}
> +	}
> +
> +	if (fmt->pad == SMIAPP_PAD_SOURCE) {
> +		int rval;
> +
> +		rval = __smiapp_get_format(subdev, fh, fmt);
> +
> +		mutex_unlock(&sensor->mutex);
> +		return rval;
> +	}
> +
> +	fmt->format.code = sensor->csi_format->code;

sensor->csi_format is the active format. You seem to always return the active
format code. That will break setting the try format.

> +
> +	fmt->format.width &= ~1;
> +	fmt->format.height &= ~1;
> +
> +	if (fmt->format.width < sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE])
> +		fmt->format.width =
> +			sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE];
> +	if (fmt->format.height
> +	    < sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE])
> +		fmt->format.height =
> +			sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE];

Isn't there a maximum size as well ?

> +
> +	crops[SMIAPP_PAD_SINK]->left = crops[SMIAPP_PAD_SINK]->top = 0;

One assignment per line please.

> +	crops[SMIAPP_PAD_SINK]->width = fmt->format.width;
> +	crops[SMIAPP_PAD_SINK]->height = fmt->format.height;
> +	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> +		ssd->sink_fmt = *crops[SMIAPP_PAD_SINK];
> +	smiapp_propagate(subdev, fh, fmt->which,
> +			 V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE);
> +
> +	mutex_unlock(&sensor->mutex);
> +
> +	return 0;
> +}
> +
> +#define SCALING_GOODNESS		100000
> +#define SCALING_GOODNESS_EXTREME	100000000
> +static int scaling_goodness(struct v4l2_subdev *subdev, int w, int ask_w,
> +			    int h, int ask_h, u32 flags)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> +	int val = 0;
> +
> +	w &= ~1;
> +	ask_w &= ~1;
> +	h &= ~1;
> +	ask_h &= ~1;
> +
> +	if (flags & V4L2_SUBDEV_SEL_FLAG_SIZE_GE) {
> +		if (w < ask_w)
> +			val -= SCALING_GOODNESS;
> +		if (h < ask_h)
> +			val -= SCALING_GOODNESS;
> +	}
> +
> +	if (flags & V4L2_SUBDEV_SEL_FLAG_SIZE_LE) {
> +		if (w > ask_w)
> +			val -= SCALING_GOODNESS;
> +		if (h > ask_h)
> +			val -= SCALING_GOODNESS;
> +	}
> +
> +	val -= abs(w - ask_w);
> +	val -= abs(h - ask_h);
> +
> +	if (w < sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE])
> +		val -= SCALING_GOODNESS_EXTREME;
> +
> +	dev_dbg(&client->dev, "w %d ask_w %d h %d ask_h %d goodness %d\n",
> +		w, ask_h, h, ask_h, val);
> +
> +	return val;
> +}
> +
> +/* We're only called on source pads. This function sets scaling. */
> +static int smiapp_set_compose(struct v4l2_subdev *subdev,
> +			      struct v4l2_subdev_fh *fh,
> +			      struct v4l2_subdev_selection *sel)
> +{
> +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> +	struct v4l2_rect *comp, *crops[SMIAPP_PADS];
> +
> +	smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
> +
> +	sel->r.top = 0;
> +	sel->r.left = 0;
> +
> +	if (ssd == sensor->binner) {

Wouldn't per-subdev operation handlers be more readable ?

> +		int i;
> +		int binh = 1, binv = 1;
> +		int best = scaling_goodness(
> +			subdev,
> +			crops[SMIAPP_PAD_SINK]->width,
> +			sel->r.width,
> +			crops[SMIAPP_PAD_SINK]->height,
> +			sel->r.height, sel->flags);
> +
> +		for (i = 0; i < sensor->nbinning_subtypes; i++) {
> +			int this = scaling_goodness(
> +				subdev,
> +				crops[SMIAPP_PAD_SINK]->width
> +				/ sensor->binning_subtypes[i].horizontal,
> +				sel->r.width,
> +				crops[SMIAPP_PAD_SINK]->height
> +				/ sensor->binning_subtypes[i].vertical,
> +				sel->r.height, sel->flags);
> +
> +			if (this > best) {
> +				binh = sensor->binning_subtypes[i].horizontal;
> +				binv = sensor->binning_subtypes[i].vertical;
> +				best = this;
> +
> +				if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> +					sensor->binning_vertical = binv;
> +					sensor->binning_horizontal = binh;
> +				}

If the initial best value turns out the be the best one, binning_vertical and
binning_horizontal will never be updated. Moving the if() outside the for loop
would solve this.

> +			}
> +		}
> +
> +		sel->r.width =
> +			(crops[SMIAPP_PAD_SINK]->width / binh) & ~1;
> +		sel->r.height =
> +			(crops[SMIAPP_PAD_SINK]->height / binv) & ~1;
> +
> +	} else {
> +		u32 min, max, a, b, max_m;
> +		u32 scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
> +		int mode = SMIAPP_SCALING_MODE_HORIZONTAL;
> +		u32 try[4];
> +		u32 ntry = 0;
> +		int i;
> +		int best = INT_MIN;
> +
> +		sel->r.width = min_t(unsigned int, sel->r.width,
> +				     crops[SMIAPP_PAD_SINK]->width);
> +		sel->r.height = min_t(unsigned int, sel->r.height,
> +				      crops[SMIAPP_PAD_SINK]->height);
> +
> +		a = crops[SMIAPP_PAD_SINK]->width
> +			* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
> +			/ sel->r.width;
> +		b = crops[SMIAPP_PAD_SINK]->height
> +			* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
> +			/ sel->r.height;
> +		max_m = crops[SMIAPP_PAD_SINK]->width
> +			* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
> +			/ sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE];
> +
> +		a = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
> +			max(a, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
> +		b = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
> +			max(b, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
> +		max_m = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
> +			    max(max_m,
> +				sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
> +
> +		dev_dbg(&client->dev, "scaling: a %d b %d max_m %d\n",
> +			a, b, max_m);
> +
> +		min = min(max_m, min(a, b));
> +		max = min(max_m, max(a, b));
> +
> +		try[ntry] = min;
> +		ntry++;
> +		if (min != max) {
> +			try[ntry] = max;
> +			ntry++;
> +		}
> +		if (max != max_m) {
> +			try[ntry] = min + 1;
> +			ntry++;
> +			if (min != max) {
> +				try[ntry] = max + 1;
> +				ntry++;
> +			}
> +		}

Please add a comment to explain how you compute the scaling values, the code
isn't self-explicit.

> +
> +		for (i = 0; i < ntry; i++) {
> +			int this = scaling_goodness(
> +				subdev,
> +				crops[SMIAPP_PAD_SINK]->width
> +				/ try[i]
> +				* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
> +				sel->r.width,
> +				crops[SMIAPP_PAD_SINK]->height,
> +				sel->r.height,
> +				sel->flags);
> +
> +			dev_dbg(&client->dev, "trying factor %d (%d)\n",
> +				try[i], i);
> +
> +			if (this > best) {
> +				scale_m = try[i];
> +				mode = SMIAPP_SCALING_MODE_HORIZONTAL;
> +				best = this;
> +			}
> +
> +			if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> +			    == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
> +				continue;
> +
> +			this = scaling_goodness(
> +				subdev, crops[SMIAPP_PAD_SINK]->width
> +				/ try[i]
> +				* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
> +				sel->r.width,
> +				crops[SMIAPP_PAD_SINK]->height
> +				/ try[i]
> +				* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
> +				sel->r.height,
> +				sel->flags);
> +
> +			if (this > best) {
> +				scale_m = try[i];
> +				mode = SMIAPP_SCALING_MODE_BOTH;
> +				best = this;
> +			}
> +		}
> +
> +		sel->r.width =
> +			(crops[SMIAPP_PAD_SINK]->width
> +			 / scale_m
> +			 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]) & ~1;
> +		if (mode == SMIAPP_SCALING_MODE_BOTH)
> +			sel->r.height =
> +				(crops[SMIAPP_PAD_SINK]->height
> +				 / scale_m
> +				 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN])
> +				& ~1;
> +		else
> +			sel->r.height = crops[SMIAPP_PAD_SINK]->height;
> +
> +		if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> +			sensor->scale_m = scale_m;
> +			sensor->scaling_mode = mode;
> +		}
> +	}
> +
> +	*comp = sel->r;
> +	smiapp_propagate(subdev, fh, sel->which,
> +			 V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE);
> +
> +	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> +		return smiapp_update_mode(sensor);
> +
> +	return 0;
> +}
> +
> +static int __smiapp_sel_supported(struct v4l2_subdev *subdev,
> +				  struct v4l2_subdev_selection *sel)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> +
> +	/* We only implement crop in three places. */
> +	switch (sel->target) {
> +	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
> +	case V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS:
> +		if (ssd == sensor->pixel_array
> +		    && sel->pad == SMIAPP_PAD_SOURCE)
> +			return 0;
> +		if (ssd == sensor->src
> +		    && sel->pad == SMIAPP_PAD_SOURCE)
> +			return 0;
> +		if (ssd == sensor->scaler
> +		    && sel->pad == SMIAPP_PAD_SINK
> +		    && sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
> +		    == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP)
> +			return 0;
> +		return -EINVAL;
> +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
> +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS:
> +		if (sel->pad != SMIAPP_PAD_SINK)
> +			return -EINVAL;
> +		if (ssd == sensor->binner)
> +			return 0;
> +		if (ssd == sensor->scaler
> +		    && sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> +		    != SMIAPP_SCALING_CAPABILITY_NONE)
> +			return 0;
> +		/* Fall through */
> +	default:
> +		return -EINVAL;
> +	}

What about returning 1 if the selection target is supported, and 0 if it isn't
?

> +}
> +
> +static int smiapp_set_crop(struct v4l2_subdev *subdev,
> +			   struct v4l2_subdev_fh *fh,
> +			   struct v4l2_subdev_selection *sel)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> +	struct v4l2_rect *src_size, *crops[SMIAPP_PADS];
> +	struct v4l2_rect _r;
> +
> +	smiapp_get_crop_compose(subdev, fh, crops, NULL, sel->which);
> +
> +	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> +		if (sel->pad == SMIAPP_PAD_SINK)
> +			src_size = &ssd->sink_fmt;
> +		else
> +			src_size = &ssd->compose;
> +	} else {
> +		if (sel->pad == SMIAPP_PAD_SINK) {
> +			_r.left = _r.top = 0;

One assignment per line please.

> +			_r.width = v4l2_subdev_get_try_format(fh, sel->pad)
> +				->width;
> +			_r.height = v4l2_subdev_get_try_format(fh, sel->pad)
> +				->height;
> +			src_size = &_r;
> +		} else {
> +			src_size =
> +				v4l2_subdev_get_try_compose(fh,
> +							    SMIAPP_PAD_SINK);

Why do you get the try compose rectangle when setting the crop rectangle ?

> +		}
> +	}

This looks a bit too complex to me (but it's just a feeling).

> +
> +	if (ssd == sensor->src && sel->pad == SMIAPP_PAD_SOURCE)
> +		sel->r.left = 0, sel->r.top = 0;

Please...

> +
> +	if (sel->r.width > src_size->width)
> +		sel->r.width = src_size->width;
> +	if (sel->r.height > src_size->height)
> +		sel->r.height = src_size->height;
> +
> +	if (sel->r.left + sel->r.width > src_size->width)
> +		sel->r.left =
> +			src_size->width - sel->r.width;
> +	if (sel->r.top + sel->r.height > src_size->height)
> +		sel->r.top =
> +			src_size->height - sel->r.height;
> +
> +	*crops[sel->pad] = sel->r;
> +
> +	if (sel->pad == SMIAPP_PAD_SINK)
> +		smiapp_propagate(subdev, fh, sel->which,
> +				 V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE);
> +
> +	return 0;
> +}
> +
> +static int __smiapp_get_selection(struct v4l2_subdev *subdev,
> +				  struct v4l2_subdev_fh *fh,
> +				  struct v4l2_subdev_selection *sel)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> +	struct v4l2_rect *comp, *crops[SMIAPP_PADS];
> +	struct v4l2_rect sink_fmt;
> +	int ret;
> +
> +	ret = __smiapp_sel_supported(subdev, sel);
> +	if (ret)
> +		return ret;
> +
> +	smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
> +
> +	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> +		sink_fmt = ssd->sink_fmt;
> +	} else if (ssd != sensor->pixel_array) {
> +		struct v4l2_mbus_framefmt *fmt =
> +			v4l2_subdev_get_try_format(fh, SMIAPP_PAD_SINK);
> +
> +		sink_fmt.left = sink_fmt.top = 0;
> +		sink_fmt.width = fmt->width;
> +		sink_fmt.height = fmt->height;
> +	} else {
> +		BUG();

So you support active selections on the pixel array subdev, but not try
selections ?

> +	}
> +
> +	switch (sel->target) {
> +	case V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS:
> +		if (ssd == sensor->pixel_array) {
> +			sel->r.width =
> +				sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
> +			sel->r.height =
> +				sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
> +		} else if (sel->pad == SMIAPP_PAD_SINK) {
> +			sel->r = sink_fmt;
> +		} else {
> +			sel->r = *comp;
> +		}
> +		break;
> +	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
> +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS:
> +		sel->r = *crops[sel->pad];
> +		break;
> +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
> +		sel->r = *comp;
> +		break;
> +	}
> +
> +	return 0;
> +}
> +
> +static int smiapp_get_selection(struct v4l2_subdev *subdev,
> +				struct v4l2_subdev_fh *fh,
> +				struct v4l2_subdev_selection *sel)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int rval;
> +
> +	mutex_lock(&sensor->mutex);
> +	rval = __smiapp_get_selection(subdev, fh, sel);
> +	mutex_unlock(&sensor->mutex);
> +
> +	return rval;
> +}
> +static int smiapp_set_selection(struct v4l2_subdev *subdev,
> +				struct v4l2_subdev_fh *fh,
> +				struct v4l2_subdev_selection *sel)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int ret;
> +
> +	ret = __smiapp_sel_supported(subdev, sel);
> +	if (ret)
> +		return ret;
> +
> +	mutex_lock(&sensor->mutex);
> +
> +	sel->r.left = max(0, sel->r.left & ~1);
> +	sel->r.top = max(0, sel->r.top & ~1);
> +	sel->r.width = max(0, SMIAPP_ALIGN_DIM(sel->r.width, sel->flags));
> +	sel->r.height = max(0, SMIAPP_ALIGN_DIM(sel->r.height, sel->flags));
> +
> +	sel->r.width = max_t(unsigned int,
> +			     sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE],
> +			     sel->r.width);
> +	sel->r.height = max_t(unsigned int,
> +			      sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE],
> +			      sel->r.height);
> +
> +	switch (sel->target) {
> +	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
> +		ret = smiapp_set_crop(subdev, fh, sel);
> +		break;
> +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
> +		ret = smiapp_set_compose(subdev, fh, sel);
> +		break;
> +	default:
> +		BUG();
> +	}
> +
> +	mutex_unlock(&sensor->mutex);
> +	return ret;
> +}
> +
> +static int smiapp_get_skip_frames(struct v4l2_subdev *subdev, u32 *frames)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +
> +	*frames = sensor->frame_skip;
> +	return 0;
> +}
> +
> +/*
> ---------------------------------------------------------------------------
> -- + * sysfs attributes
> + */
> +
> +static ssize_t
> +smiapp_sysfs_nvm_read(struct device *dev, struct device_attribute *attr,
> +		      char *buf)
> +{
> +	struct v4l2_subdev *subdev = i2c_get_clientdata(to_i2c_client(dev));
> +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int nbytes;
> +
> +	if (!sensor->dev_init_done)
> +		return -EBUSY;
> +
> +	if (!sensor->nvm_size) {
> +		/* NVM not read yet - read it now */
> +		sensor->nvm_size = sensor->platform_data->nvm_size;
> +		if (smiapp_set_power(subdev, 1) < 0)
> +			return -ENODEV;
> +		if (smiapp_read_nvm(sensor, sensor->nvm)) {
> +			dev_err(&client->dev, "nvm read failed\n");
> +			return -ENODEV;
> +		}
> +		smiapp_set_power(subdev, 0);
> +	}
> +	/*
> +	 * NVM is still way below a PAGE_SIZE, so we can safely
> +	 * assume this for now.
> +	 */
> +	nbytes = min_t(unsigned int, sensor->nvm_size, PAGE_SIZE);
> +	memcpy(buf, sensor->nvm, nbytes);
> +
> +	return nbytes;
> +}
> +static DEVICE_ATTR(nvm, S_IRUGO, smiapp_sysfs_nvm_read, NULL);
> +
> +/*
> ---------------------------------------------------------------------------
> -- + * V4L2 subdev core operations
> + */
> +
> +static int smiapp_identify_module(struct v4l2_subdev *subdev)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> +	int i, rval = 0;
> +	struct smiapp_module_info *minfo = &sensor->minfo;
> +
> +	minfo->name = SMIAPP_NAME;
> +
> +	/* Module info */
> +	rval = smia_i2c_read_reg(client,
> +				 SMIAPP_REG_U8_MANUFACTURER_ID,
> +				 &minfo->manufacturer_id);
> +	if (!rval)
> +		rval = smia_i2c_read_reg(client,
> +					 SMIAPP_REG_U16_MODEL_ID,
> +					 &minfo->model_id);
> +	if (!rval)
> +		rval |= smia_i2c_read_reg(client,
> +					  SMIAPP_REG_U8_REVISION_NUMBER_MAJOR,
> +					  &minfo->revision_number_major);

s/|=/=/

> +	if (!rval)
> +		rval |= smia_i2c_read_reg(client,
> +					  SMIAPP_REG_U8_REVISION_NUMBER_MINOR,
> +					  &minfo->revision_number_minor);
> +	if (!rval)
> +		rval |= smia_i2c_read_reg(client,
> +					  SMIAPP_REG_U8_MODULE_DATE_YEAR,
> +					  &minfo->module_year);
> +	if (!rval)
> +		rval |= smia_i2c_read_reg(client,
> +					  SMIAPP_REG_U8_MODULE_DATE_MONTH,
> +					  &minfo->module_month);
> +	if (!rval)
> +		rval |= smia_i2c_read_reg(client,
> +					  SMIAPP_REG_U8_MODULE_DATE_DAY,
> +					  &minfo->module_day);
> +
> +	/* Sensor info */
> +	if (!rval)
> +		rval |= smia_i2c_read_reg(client,
> +					  SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID,
> +					  &minfo->sensor_manufacturer_id);
> +	if (!rval)
> +		rval |= smia_i2c_read_reg(client,
> +					  SMIAPP_REG_U16_SENSOR_MODEL_ID,
> +					  &minfo->sensor_model_id);
> +	if (!rval)
> +		rval = smia_i2c_read_reg(client,
> +					 SMIAPP_REG_U8_SENSOR_REVISION_NUMBER,
> +					 &minfo->sensor_revision_number);
> +	if (!rval)
> +		rval = smia_i2c_read_reg(client,
> +					 SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION,
> +					 &minfo->sensor_firmware_version);
> +
> +	/* SMIA */
> +	if (!rval)
> +		rval = smia_i2c_read_reg(client,
> +					 SMIAPP_REG_U8_SMIA_VERSION,
> +					 &minfo->smia_version);
> +	if (!rval)
> +		rval = smia_i2c_read_reg(client,
> +					 SMIAPP_REG_U8_SMIAPP_VERSION,
> +					 &minfo->smiapp_version);
> +
> +	if (rval) {
> +		dev_err(&client->dev, "sensor detection failed\n");
> +		return -ENODEV;
> +	}
> +
> +	dev_dbg(&client->dev, "module 0x%2.2x-0x%4.4x\n",

"module 0x%02x-0x%04x\n" (and similarly below) ?

> +		minfo->manufacturer_id, minfo->model_id);
> +
> +	dev_dbg(&client->dev,
> +		"module revision 0x%2.2x-0x%2.2x date %2.2d-%2.2d-%2.2d\n",
> +		minfo->revision_number_major, minfo->revision_number_minor,
> +		minfo->module_year, minfo->module_month, minfo->module_day);
> +
> +	dev_dbg(&client->dev, "sensor 0x%2.2x-0x%4.4x\n",
> +		minfo->sensor_manufacturer_id, minfo->sensor_model_id);
> +
> +	dev_dbg(&client->dev,
> +		"sensor revision 0x%2.2x firmware version 0x%2.2x\n",
> +		minfo->sensor_revision_number, minfo->sensor_firmware_version);
> +
> +	dev_dbg(&client->dev, "smia version %2.2d smiapp version %2.2d\n",
> +		minfo->smia_version, minfo->smiapp_version);
> +

Could you please add a short comment to explain why this is needed ?

> +	if (!minfo->manufacturer_id && !minfo->model_id) {
> +		minfo->manufacturer_id = minfo->sensor_manufacturer_id;
> +		minfo->model_id = minfo->sensor_model_id;
> +		minfo->revision_number_major = minfo->sensor_revision_number;
> +	}
> +
> +	for (i = 0; i < ARRAY_SIZE(smiapp_module_idents); i++) {
> +		if (smiapp_module_idents[i].manufacturer_id
> +		    != minfo->manufacturer_id)
> +			continue;
> +		if (smiapp_module_idents[i].model_id != minfo->model_id)
> +			continue;
> +		if (smiapp_module_idents[i].flags
> +		    & SMIAPP_MODULE_IDENT_FLAG_REV_LE) {
> +			if (smiapp_module_idents[i].revision_number_major
> +			    < minfo->revision_number_major)
> +				continue;
> +		} else {
> +			if (smiapp_module_idents[i].revision_number_major
> +			    != minfo->revision_number_major)
> +				continue;
> +		}
> +
> +		minfo->name = smiapp_module_idents[i].name;
> +		minfo->quirk = smiapp_module_idents[i].quirk;
> +		break;
> +	}
> +
> +	if (i >= ARRAY_SIZE(smiapp_module_idents))
> +		dev_warn(&client->dev, "no quirks for this module\n");

Maybe a message such as "unknown SMIA++ module - trying generic support" would
be better ? Many of the known modules have no quirks.

> +
> +	dev_dbg(&client->dev, "the sensor is called %s, ident %2.2x%4.4x%2.2x\n",
> +		minfo->name, minfo->manufacturer_id, minfo->model_id,
> +		minfo->revision_number_major);
> +
> +	strlcpy(subdev->name, sensor->minfo.name, sizeof(subdev->name));
> +
> +	return 0;
> +}
> +
> +static const struct v4l2_subdev_ops smiapp_ops;
> +static const struct v4l2_subdev_internal_ops smiapp_internal_ops;
> +static const struct media_entity_operations smiapp_entity_ops;
> +
> +static int smiapp_registered(struct v4l2_subdev *subdev)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> +	struct smiapp_subdev *last = NULL;
> +	int rval;
> +	u32 tmp, i;
> +
> +	sensor->vana = regulator_get(&client->dev, "VANA");
> +	if (IS_ERR(sensor->vana)) {
> +		dev_err(&client->dev, "could not get regulator for vana\n");
> +		return -ENODEV;
> +	}
> +
> +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) {
> +		if (gpio_request_one(sensor->platform_data->xshutdown, 0,
> +				     "SMIA++ xshutdown") != 0) {
> +			dev_err(&client->dev,
> +				"unable to acquire reset gpio %d\n",
> +				sensor->platform_data->xshutdown);
> +			rval = -ENODEV;
> +			goto out_gpio_request;
> +		}
> +	}
> +
> +	rval = smiapp_power_on(sensor);
> +	if (rval) {
> +		rval = -ENODEV;
> +		goto out_smiapp_power_on;
> +	}
> +
> +	rval = smiapp_identify_module(subdev);
> +	if (rval) {
> +		rval = -ENODEV;
> +		goto out_power_off;
> +	}
> +
> +	rval = smiapp_get_all_limits(sensor);
> +	if (rval) {
> +		rval = -ENODEV;
> +		goto out_power_off;
> +	}
> +
> +	/*
> +	 * Handle Sensor Module orientation on the board.
> +	 *
> +	 * The application of H-FLIP and V-FLIP on the sensor is modified by
> +	 * the sensor orientation on the board.
> +	 *
> +	 * For SMIAPP_BOARD_SENSOR_ORIENT_180 the default behaviour is to set
> +	 * both H-FLIP and V-FLIP for normal operation which also implies
> +	 * that a set/unset operation for user space HFLIP and VFLIP v4l2
> +	 * controls will need to be internally inverted.
> +	 *
> +	 * Rotation also changes the bayer pattern.
> +	 */
> +	if (sensor->platform_data->module_board_orient ==
> +	    SMIAPP_MODULE_BOARD_ORIENT_180)
> +		sensor->hvflip_inv_mask = SMIAPP_IMAGE_ORIENTATION_HFLIP |
> +					  SMIAPP_IMAGE_ORIENTATION_VFLIP;
> +
> +	rval = smiapp_get_mbus_formats(sensor);
> +	if (rval) {
> +		rval = -ENODEV;
> +		goto out_power_off;
> +	}
> +
> +	if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY]) {
> +		int i;
> +		int val;
> +
> +		rval = smia_i2c_read_reg(client,
> +					 SMIAPP_REG_U8_BINNING_SUBTYPES, &val);
> +		if (rval < 0) {
> +			rval = -ENODEV;
> +			goto out_power_off;
> +		}
> +		sensor->nbinning_subtypes = min_t(u8, val,
> +						  SMIAPP_BINNING_SUBTYPES);
> +
> +		for (i = 0; i < sensor->nbinning_subtypes; i++) {
> +			rval = smia_i2c_read_reg(
> +				client, SMIAPP_REG_U8_BINNING_TYPE_n(i), &val);
> +			if (rval < 0) {
> +				rval = -ENODEV;
> +				goto out_power_off;
> +			}
> +			sensor->binning_subtypes[i] =
> +				*(struct smiapp_binning_subtype *)&val;
> +
> +			dev_dbg(&client->dev, "binning %xx%x\n",
> +				sensor->binning_subtypes[i].horizontal,
> +				sensor->binning_subtypes[i].vertical);
> +		}
> +	}
> +	sensor->binning_horizontal = 1;
> +	sensor->binning_vertical = 1;
> +
> +	/* SMIA++ NVM initialization - it will be read from the sensor
> +	 * when it is first requested by userspace.
> +	 */
> +	if (sensor->minfo.smiapp_version && sensor->platform_data->nvm_size) {
> +		sensor->nvm = kzalloc(sensor->platform_data->nvm_size,
> +				      GFP_KERNEL);
> +		if (sensor->nvm == NULL) {
> +			dev_err(&client->dev, "nvm buf allocation failed\n");
> +			rval = -ENOMEM;
> +			goto out_power_off;
> +		}
> +
> +		if (device_create_file(&client->dev, &dev_attr_nvm) != 0) {
> +			dev_err(&client->dev, "sysfs nvm entry failed\n");
> +			rval = -EBUSY;
> +			goto out_nvm_release1;
> +		}
> +	}
> +
> +	rval = smiapp_call_quirk(sensor, limits);
> +	if (rval) {
> +		dev_err(&client->dev, "limits quirks failed\n");
> +		goto out_nvm_release2;
> +	}
> +
> +	/* We consider this as profile 0 sensor if any of these are zero. */
> +	if (!sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV] ||
> +	    !sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV] ||
> +	    !sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV] ||
> +	    !sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV]) {
> +		sensor->minfo.smiapp_profile = SMIAPP_PROFILE_0;
> +	} else if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> +		   != SMIAPP_SCALING_CAPABILITY_NONE) {
> +		if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> +		    == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
> +			sensor->minfo.smiapp_profile = SMIAPP_PROFILE_1;
> +		else
> +			sensor->minfo.smiapp_profile = SMIAPP_PROFILE_2;
> +		sensor->scaler = &sensor->sds[sensor->sds_used];
> +		sensor->sds_used++;
> +	} else if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
> +		   == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
> +		sensor->scaler = &sensor->sds[sensor->sds_used];
> +		sensor->sds_used++;
> +	}
> +	sensor->binner = &sensor->sds[sensor->sds_used];
> +	sensor->sds_used++;
> +	sensor->pixel_array = &sensor->sds[sensor->sds_used];
> +	sensor->sds_used++;
> +
> +	sensor->scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
> +
> +	for (i = 0; i < SMIAPP_SUBDEVS; i++) {
> +		struct {
> +			struct smiapp_subdev *sds;
> +			char *name;
> +		} _t[] = {
> +			{ sensor->scaler, "scaler", },
> +			{ sensor->binner, "binner", },
> +			{ sensor->pixel_array, "pixel array", },
> +		}, *this = &_t[i];

What about moving _t outside of the loop (and renaming it to something more
explicit) ? There's no need to initialize it at each iteration.

> +		if (!this->sds)
> +			continue;
> +
> +		if (this->sds != sensor->src)
> +			v4l2_subdev_init(&this->sds->sd, &smiapp_ops);
> +
> +		this->sds->sensor = sensor;
> +
> +		if (this->sds == sensor->pixel_array) {
> +			if (this->sds == sensor->src)
> +				sensor->sds->sd.entity.num_pads = 1;

That's supposed to be initialized by media_entity_init(), why do you need to
set it explictly here ?

> +			this->sds->npads = 1;
> +		} else {
> +			this->sds->npads = 2;
> +		}
> +
> +		snprintf(this->sds->sd.name,
> +			 sizeof(this->sds->sd.name), "%s %s",
> +			 sensor->minfo.name, this->name);
> +
> +		this->sds->sink_fmt.width =
> +			sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
> +		this->sds->sink_fmt.height =
> +			sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
> +		this->sds->crop[SMIAPP_PAD_SINK].width =
> +			this->sds->sink_fmt.width;
> +		this->sds->crop[SMIAPP_PAD_SINK].height =
> +			this->sds->sink_fmt.height;
> +		this->sds->crop[SMIAPP_PAD_SOURCE] =
> +			this->sds->compose =
> +			this->sds->crop[SMIAPP_PAD_SINK];
> +
> +		this->sds->pads[1].flags = MEDIA_PAD_FL_SINK;
> +		this->sds->pads[0].flags = MEDIA_PAD_FL_SOURCE;

Pad 1 is the sink pad and pad 0 the source pad ? That's very unusual, couldn't
you make it the other way around ?

> +
> +		this->sds->sd.entity.ops = &smiapp_entity_ops;
> +
> +		if (last == NULL) {
> +			last = this->sds;
> +			continue;
> +		}
> +
> +		this->sds->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
> +		this->sds->sd.internal_ops = &smiapp_internal_ops;
> +		this->sds->sd.owner = NULL;
> +		v4l2_set_subdevdata(&this->sds->sd, client);
> +
> +		rval = v4l2_device_register_subdev(sensor->src->sd.v4l2_dev,
> +						   &this->sds->sd);
> +		if (rval) {
> +			dev_err(&client->dev,
> +				"v4l2_device_register_subdev failed\n");
> +			goto out_nvm_release2;
> +		}
> +
> +		rval = media_entity_init(&this->sds->sd.entity,
> +					 this->sds->npads, this->sds->pads, 0);
> +		if (rval) {
> +			dev_err(&client->dev,
> +				"media_entity_init failed\n");
> +			goto out_nvm_release2;
> +		}

You should initialize the entity (and possibly create the link) before
registering the subdev.

> +
> +		rval = media_entity_create_link(&this->sds->sd.entity, 0,
> +						&last->sd.entity, 1,
> +						MEDIA_LNK_FL_ENABLED |
> +						MEDIA_LNK_FL_IMMUTABLE);
> +		if (rval) {
> +			dev_err(&client->dev,
> +				"media_entity_create_link failed\n");
> +			goto out_nvm_release2;
> +		}
> +
> +		last = this->sds;
> +	}
> +
> +	dev_dbg(&client->dev, "profile %d\n", sensor->minfo.smiapp_profile);
> +
> +	sensor->pixel_array->sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
> +
> +	/* final steps */
> +	smiapp_read_frame_fmt(sensor);
> +	rval = smiapp_init_controls(sensor);
> +	if (rval < 0)
> +		goto out_nvm_release2;
> +
> +	rval = smiapp_update_mode(sensor);
> +	if (rval) {
> +		dev_err(&client->dev, "update mode failed\n");
> +		goto out_nvm_release2;
> +	}
> +
> +	sensor->streaming = false;
> +	sensor->dev_init_done = true;
> +
> +	/* check flash capability */
> +	rval = smia_i2c_read_reg(client,
> +				 SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, &tmp);
> +	sensor->flash_capability = tmp;
> +	if (rval)
> +		goto out_nvm_release2;
> +
> +	smiapp_power_off(sensor);

Shouldn't you take the sensor mutex around the whole function ?

> +
> +	return 0;
> +
> +out_nvm_release2:
> +	device_remove_file(&client->dev, &dev_attr_nvm);
> +
> +out_nvm_release1:
> +	kfree(sensor->nvm);
> +	sensor->nvm = NULL;

You can move this under out_power_off, if sensor->nvm is already NULL kfree
will be a no-op.

> +
> +out_power_off:
> +	smiapp_power_off(sensor);
> +
> +out_smiapp_power_on:
> +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> +		gpio_free(sensor->platform_data->xshutdown);
> +
> +out_gpio_request:
> +	regulator_put(sensor->vana);
> +	sensor->vana = NULL;
> +	return rval;
> +}
> +
> +static int smiapp_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
> +{
> +	struct smiapp_subdev *ssd = to_smiapp_subdev(sd);
> +	struct v4l2_subdev_selection sel;
> +	struct v4l2_rect *try_sel;
> +	int i;
> +	int rval;
> +
> +	mutex_lock(&ssd->sensor->power_mutex);
> +	mutex_lock(&ssd->sensor->mutex);
> +
> +	for (i = 0; i < ssd->npads; i++) {
> +		struct v4l2_subdev_format fmt;
> +		struct v4l2_mbus_framefmt *try_fmt;
> +
> +		fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> +		fmt.pad = i;
> +		__smiapp_get_format(sd, fh, &fmt);
> +		try_fmt = v4l2_subdev_get_try_format(fh, i);
> +		*try_fmt = fmt.format;
> +
> +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> +		sel.pad = i;
> +		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
> +		__smiapp_get_selection(sd, fh, &sel);
> +		try_sel = v4l2_subdev_get_try_crop(fh, i);
> +		*try_sel = sel.r;

Wouldn't it be better to use the default values instead of the active ones
here ?

> +	}
> +
> +	if (ssd != ssd->sensor->pixel_array) {
> +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> +		sel.pad = SMIAPP_PAD_SINK;
> +		sel.target = V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE;
> +		__smiapp_get_selection(sd, fh, &sel);
> +		try_sel = v4l2_subdev_get_try_compose(fh, SMIAPP_PAD_SINK);
> +		*try_sel = sel.r;
> +	}
> +
> +	rval = smiapp_set_power(sd, 1);
> +
> +	mutex_unlock(&ssd->sensor->mutex);
> +
> +	if (rval < 0)
> +		goto out;
> +
> +	/* Was the sensor already powered on? */
> +	if (ssd->sensor->power_count > 1)

power_count is accessed in smiapp_set_power without taking the power_mutex
lock. Are two locks really needed ?

> +		goto out;
> +
> +	for (i = 0; i < ssd->sensor->sds_used; i++) {
> +		rval = v4l2_ctrl_handler_setup(
> +			&ssd->sensor->sds[i].ctrl_handler);
> +		if (rval)
> +			goto out;
> +	}

Doesn't this belong to the set power handler ?

> +
> +out:
> +	mutex_unlock(&ssd->sensor->power_mutex);
> +
> +	return rval;
> +}
> +
> +static int smiapp_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
> +{
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(sd);
> +	int rval;
> +
> +	mutex_lock(&sensor->power_mutex);
> +	mutex_lock(&sensor->mutex);
> +	rval = smiapp_set_power(sd, 0);
> +	mutex_unlock(&sensor->mutex);
> +	mutex_unlock(&sensor->power_mutex);
> +
> +	return rval;
> +}
> +
> +static const struct v4l2_subdev_video_ops smiapp_video_ops = {
> +	.s_stream = smiapp_set_stream,
> +};
> +
> +static const struct v4l2_subdev_core_ops smiapp_core_ops = {
> +	.s_power = smiapp_set_power,
> +};
> +
> +static const struct v4l2_subdev_pad_ops smiapp_pad_ops = {
> +	.enum_mbus_code = smiapp_enum_mbus_code,
> +	.get_fmt = smiapp_get_format,
> +	.set_fmt = smiapp_set_format,
> +	.get_selection = smiapp_get_selection,
> +	.set_selection = smiapp_set_selection,
> +	.link_validate = v4l2_subdev_link_validate_default,

This can be left NULL.

> +};
> +
> +static const struct v4l2_subdev_sensor_ops smiapp_sensor_ops = {
> +	.g_skip_frames = smiapp_get_skip_frames,
> +};
> +
> +static const struct v4l2_subdev_ops smiapp_ops = {
> +	.core = &smiapp_core_ops,
> +	.video = &smiapp_video_ops,
> +	.pad = &smiapp_pad_ops,
> +	.sensor = &smiapp_sensor_ops,
> +};
> +
> +static const struct media_entity_operations smiapp_entity_ops = {
> +	.link_validate = v4l2_subdev_link_validate,
> +};
> +
> +static const struct v4l2_subdev_internal_ops smiapp_internal_src_ops = {
> +	.registered = smiapp_registered,
> +	.open = smiapp_open,
> +	.close = smiapp_close,
> +};
> +
> +static const struct v4l2_subdev_internal_ops smiapp_internal_ops = {
> +	.open = smiapp_open,
> +	.close = smiapp_close,
> +};
> +
> +/*
> ---------------------------------------------------------------------------
> -- + * I2C Driver
> + */
> +
> +#ifdef CONFIG_PM
> +
> +static int smiapp_suspend(struct device *dev)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int ss;
> +
> +	BUG_ON(mutex_is_locked(&sensor->mutex));
> +
> +	if (sensor->power_count == 0)
> +		return 0;
> +
> +	if (sensor->streaming)
> +		smiapp_stop_streaming(sensor);
> +
> +	ss = sensor->streaming;
> +
> +	smiapp_power_off(sensor);
> +
> +	/* save state for resume */
> +	sensor->streaming = ss;
> +
> +	return 0;
> +}
> +
> +static int smiapp_resume(struct device *dev)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int rval;
> +
> +	if (sensor->power_count == 0)
> +		return 0;
> +
> +	rval = smiapp_power_on(sensor);
> +	if (rval)
> +		return rval;
> +
> +	if (sensor->streaming)
> +		rval = smiapp_start_streaming(sensor);
> +
> +	return rval;
> +}
> +
> +#else
> +
> +#define smiapp_suspend	NULL
> +#define smiapp_resume	NULL
> +
> +#endif /* CONFIG_PM */
> +
> +static int smiapp_probe(struct i2c_client *client,
> +			const struct i2c_device_id *devid)
> +{
> +	struct smiapp_sensor *sensor;
> +	int rval;
> +
> +	if (client->dev.platform_data == NULL)
> +		return -ENODEV;
> +
> +	sensor = kzalloc(sizeof(*sensor), GFP_KERNEL);
> +	if (sensor == NULL)
> +		return -ENOMEM;
> +
> +	sensor->platform_data = client->dev.platform_data;
> +	mutex_init(&sensor->mutex);
> +	mutex_init(&sensor->power_mutex);
> +	sensor->src = &sensor->sds[sensor->sds_used];
> +
> +	v4l2_i2c_subdev_init(&sensor->src->sd, client, &smiapp_ops);
> +	sensor->src->sd.internal_ops = &smiapp_internal_src_ops;
> +	sensor->src->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
> +	sensor->src->sensor = sensor;
> +
> +	sensor->src->pads[0].flags = MEDIA_PAD_FL_SOURCE;
> +	rval = media_entity_init(&sensor->src->sd.entity, 2,
> +				 sensor->src->pads, 0);
> +	if (rval < 0)
> +		kfree(sensor);
> +
> +	return rval;
> +}
> +
> +static int __exit smiapp_remove(struct i2c_client *client)
> +{
> +	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
> +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> +	int i;
> +
> +	if (sensor->power_count) {
> +		if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> +			gpio_set_value(sensor->platform_data->xshutdown, 0);
> +		sensor->platform_data->set_xclk(&sensor->src->sd, 0);
> +		sensor->power_count = 0;
> +	}
> +
> +	if (sensor->nvm) {
> +		device_remove_file(&client->dev, &dev_attr_nvm);
> +		kfree(sensor->nvm);
> +	}
> +
> +	for (i = 0; i < sensor->sds_used; i++) {
> +		media_entity_cleanup(&sensor->sds[i].sd.entity);
> +		v4l2_device_unregister_subdev(&sensor->sds[i].sd);
> +	}
> +	smiapp_free_controls(sensor);
> +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> +		gpio_free(sensor->platform_data->xshutdown);
> +	if (sensor->vana)
> +		regulator_put(sensor->vana);
> +
> +	kfree(sensor);
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id smiapp_id_table[] = {
> +	{ SMIAPP_NAME, 0 },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(i2c, smiapp_id_table);
> +
> +static const struct dev_pm_ops smiapp_pm_ops = {
> +	.suspend	= smiapp_suspend,
> +	.resume		= smiapp_resume,
> +};
> +
> +static struct i2c_driver smiapp_i2c_driver = {
> +	.driver	= {
> +		.name = SMIAPP_NAME,
> +		.pm = &smiapp_pm_ops,
> +	},
> +	.probe	= smiapp_probe,
> +	.remove	= __exit_p(smiapp_remove),
> +	.id_table = smiapp_id_table,
> +};
> +
> +static int __init smiapp_init(void)
> +{
> +	int rval;
> +
> +	rval = i2c_add_driver(&smiapp_i2c_driver);
> +	if (rval)
> +		pr_err("Failed registering driver" SMIAPP_NAME "\n");
> +
> +	return rval;
> +}
> +
> +static void __exit smiapp_exit(void)
> +{
> +	i2c_del_driver(&smiapp_i2c_driver);
> +}
> +
> +module_init(smiapp_init);
> +module_exit(smiapp_exit);
> +
> +MODULE_AUTHOR("Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>");
> +MODULE_DESCRIPTION("Generic SMIA/SMIA++ camera module driver");
> +MODULE_LICENSE("GPL");

[snip]

> diff --git a/drivers/media/video/smiapp/smiapp-pll.c
> b/drivers/media/video/smiapp/smiapp-pll.c new file mode 100644
> index 0000000..5014730
> --- /dev/null
> +++ b/drivers/media/video/smiapp/smiapp-pll.c

[snip]

I'll send a patch on top of this one to split smiapp-pll to a separate module,
as the code is needed for at least one non-SMIA(++) Aptina sensor.

[snip]

> --git a/drivers/media/video/smiapp/smiapp-reg.h
> b/drivers/media/video/smiapp/smiapp-reg.h new file mode 100644
> index 0000000..126ca5b
> --- /dev/null
> +++ b/drivers/media/video/smiapp/smiapp-reg.h

[snip]

> +#define SMIAPP_SCALING_CAPABILITY_NONE			0
> +#define SMIAPP_SCALING_CAPABILITY_HORIZONTAL		1
> +#define SMIAPP_SCALING_CAPABILITY_BOTH			2 /* horizontal/both */

Do you mean horizontal/vertical ?

[snip]

> diff --git a/drivers/media/video/smiapp/smiapp-regs.c
> b/drivers/media/video/smiapp/smiapp-regs.c new file mode 100644
> index 0000000..9a2326a
> --- /dev/null
> +++ b/drivers/media/video/smiapp/smiapp-regs.c
> @@ -0,0 +1,230 @@
> +/*
> + * drivers/media/video/smiapp-regs.c
> + *
> + * Generic driver for SMIA/SMIA++ compliant camera modules
> + *
> + * Copyright (C) 2011--2012 Nokia Corporation
> + * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA
> + *
> + */
> +
> +#include "smiapp-debug.h"
> +
> +#include <linux/delay.h>
> +#include <linux/i2c.h>
> +
> +#include "smiapp-regs.h"
> +
> +static uint32_t float_to_u32_mul_1000000(struct i2c_client *client,
> +					 uint32_t phloat)

Now that's creative :-)

> +{
> +	int32_t exp;
> +	uint64_t man;
> +
> +	if (phloat >= 0x80000000) {
> +		dev_err(&client->dev, "this is a negative number\n");
> +		return 0;
> +	}
> +
> +	if (phloat == 0x7f800000)
> +		return ~0; /* Inf. */
> +
> +	if ((phloat & 0x7f800000) == 0x7f800000) {
> +		dev_err(&client->dev, "NaN or other special number\n");
> +		return 0;
> +	}
> +
> +	/* Valid cases begin here */
> +	if (phloat == 0)
> +		return 0; /* Valid zero */
> +
> +	if (phloat > 0x4f800000)
> +		return ~0; /* larger than 4294967295 */
> +
> +	/*
> +	 * Unbias exponent (note how phloat is now guaranteed to
> +	 * have 0 in the high bit)
> +	 */
> +	exp = ((int32_t)phloat >> 23) - 127;
> +
> +	/* Extract mantissa, add missing '1' bit and it's in MHz */
> +	man = ((phloat & 0x7fffff) | 0x800000) * 1000000ULL;
> +
> +	if (exp < 0)
> +		man >>= -exp;
> +	else
> +		man <<= exp;
> +
> +	man >>= 23; /* Remove mantissa bias */
> +
> +	return man & 0xffffffff;
> +}
> +
> +
> +/*
> + * Read a 8/16/32-bit i2c register.  The value is returned in 'val'.
> + * Returns zero if successful, or non-zero otherwise.
> + */
> +int smia_i2c_read_reg(struct i2c_client *client, u32 reg, u32 *val)
> +{
> +	struct i2c_msg msg[1];

s/[1]// ?

> +	unsigned char data[4];
> +	unsigned int len = (u8)(reg >> 16);
> +	u16 offset = reg;
> +	int r;
> +
> +	if (!client->adapter)
> +		return -ENODEV;

Can this happen ?

> +	if (len != SMIA_REG_8BIT && len != SMIA_REG_16BIT
> +	    && len != SMIA_REG_32BIT)
> +		return -EINVAL;
> +
> +	msg->addr = client->addr;
> +	msg->flags = 0;
> +	msg->len = 2;
> +	msg->buf = data;
> +
> +	/* high byte goes out first */
> +	data[0] = (u8) (offset >> 8);
> +	data[1] = (u8) offset;
> +	r = i2c_transfer(client->adapter, msg, 1);
> +	if (r != 1) {
> +		if (r >= 0)
> +			r = -EBUSY;
> +		goto err;
> +	}
> +
> +	msg->len = len;
> +	msg->flags = I2C_M_RD;
> +	r = i2c_transfer(client->adapter, msg, 1);
> +	if (r != 1) {
> +		if (r >= 0)
> +			r = -EBUSY;
> +		goto err;
> +	}
> +
> +	*val = 0;
> +	/* high byte comes first */
> +	switch (len) {
> +	case SMIA_REG_32BIT:
> +		*val = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) +
> +			data[3];
> +		break;
> +	case SMIA_REG_16BIT:
> +		*val = (data[0] << 8) + data[1];
> +		break;
> +	case SMIA_REG_8BIT:
> +		*val = data[0];
> +		break;
> +	default:
> +		BUG();
> +	}
> +
> +	if (reg & SMIA_REG_FLAG_FLOAT)
> +		*val = float_to_u32_mul_1000000(client, *val);
> +
> +	return 0;
> +
> +err:
> +	dev_err(&client->dev, "read from offset 0x%x error %d\n", offset, r);
> +
> +	return r;
> +}
> +
> +static void smia_i2c_create_msg(struct i2c_client *client, u16 len, u16
> reg, +				u32 val, struct i2c_msg *msg,
> +				unsigned char *buf)
> +{
> +	msg->addr = client->addr;
> +	msg->flags = 0; /* Write */
> +	msg->len = 2 + len;
> +	msg->buf = buf;
> +
> +	/* high byte goes out first */
> +	buf[0] = (u8) (reg >> 8);
> +	buf[1] = (u8) (reg & 0xff);
> +
> +	switch (len) {
> +	case SMIA_REG_8BIT:
> +		buf[2] = val;
> +		break;
> +	case SMIA_REG_16BIT:
> +		buf[2] = val >> 8;
> +		buf[3] = val;
> +		break;
> +	case SMIA_REG_32BIT:
> +		buf[2] = val >> 24;
> +		buf[3] = val >> 16;
> +		buf[4] = val >> 8;
> +		buf[5] = val;
> +		break;
> +	default:
> +		BUG();
> +	}

As this function is reused anywhere else, I would inline ti inside 
smia_i2c_write_reg().

> +}
> +
> +/*
> + * Write to a 8/16-bit register.
> + * Returns zero if successful, or non-zero otherwise.
> + */
> +int smia_i2c_write_reg(struct i2c_client *client, u32 reg, u32 val)
> +{
> +	struct i2c_msg msg[1];

s/[1]// ?

> +	unsigned char data[6];
> +	unsigned int retries = 5;
> +	unsigned int flags = reg >> 24;
> +	unsigned int len = (u8)(reg >> 16);
> +	u16 offset = reg;
> +	int r;
> +
> +	if (!client->adapter)
> +		return -ENODEV;

Can this happen ?

> +
> +	if ((len != SMIA_REG_8BIT && len != SMIA_REG_16BIT &&
> +	     len != SMIA_REG_32BIT) || flags)
> +		return -EINVAL;
> +
> +	smia_i2c_create_msg(client, len, offset, val, msg, data);
> +
> +	do {
> +		/*
> +		 * Due to unknown reason sensor stops responding. This
> +		 * loop is a temporaty solution until the root cause
> +		 * is found.
> +		 */
> +		r = i2c_transfer(client->adapter, msg, 1);
> +		if (r == 1)
> +			break;
> +
> +		usleep_range(2000, 2000);
> +	} while (retries--);

What about a for loop ?

> +
> +	if (r != 1) {
> +		dev_err(&client->dev,
> +			"wrote 0x%x to offset 0x%x error %d\n", val, offset, r);
> +	} else {
> +		if (r >= 0)
> +			r = -EBUSY;
> +		r = 0; /* on success i2c_transfer() return messages trasfered */

Was this added at the end of the patch just to see if I would review
everything ? :-)

> +	}
> +
> +	if (retries < 5)
> +		dev_err(&client->dev, "sensor i2c stall encountered. "
> +			"retries: %d\n", 5 - retries);

You can move this right after the loop and return an error.

> +
> +	return r;
> +}
> diff --git a/drivers/media/video/smiapp/smiapp-regs.h
> b/drivers/media/video/smiapp/smiapp-regs.h new file mode 100644
> index 0000000..20c4c25
> --- /dev/null
> +++ b/drivers/media/video/smiapp/smiapp-regs.h
> @@ -0,0 +1,46 @@
> +/*
> + * include/media/smiapp-regs.h
> + *
> + * Generic driver for SMIA/SMIA++ compliant camera modules
> + *
> + * Copyright (C) 2011--2012 Nokia Corporation
> + * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA
> + *
> + */
> +
> +#ifndef SMIAPP_REGS_H
> +#define SMIAPP_REGS_H
> +
> +#include <linux/i2c.h>
> +#include <linux/types.h>
> +
> +/* Use upper 8 bits of the type field for flags */
> +#define SMIA_REG_FLAG_FLOAT		(1 << 24)
> +
> +#define SMIA_REG_8BIT			1
> +#define SMIA_REG_16BIT			2
> +#define SMIA_REG_32BIT			4
> +struct smia_reg {
> +	u16 type;
> +	u16 reg;			/* 16-bit offset */
> +	u32 val;			/* 8/16/32-bit value */
> +};
> +
> +int smia_i2c_read_reg(struct i2c_client *client, u32 reg, u32 *val);
> +int smia_i2c_write_reg(struct i2c_client *client, u32 reg, u32 val);

What about renaming those to smia_read() and smia_write() (or possible
smia_i2c_read() and smia_i2c_write()) ? It would help
shortening long code lines.

> +
> +#endif
> diff --git a/drivers/media/video/smiapp/smiapp.h
> b/drivers/media/video/smiapp/smiapp.h new file mode 100644
> index 0000000..df514dd
> --- /dev/null
> +++ b/drivers/media/video/smiapp/smiapp.h

[snip]

> +struct smiapp_module_ident {
> +	u8 manufacturer_id;
> +	u16 model_id;
> +	u8 revision_number_major;
> +
> +	u8 flags;
> +
> +	char *name;
> +	const struct smiapp_quirk *quirk;
> +} __packed;

Is there really a need to pack this ? You could just move
revision_number_major above model_id to save a couple of bytes and leave
packing out.

> +#define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk)	\
> +	{ .manufacturer_id = manufacturer,				\
> +			.model_id = model,				\
> +			.revision_number_major = rev,			\
> +			.flags = fl,					\
> +			.name = _name,					\
> +			.quirk = _quirk, }

Any reason for the strange indentation ?

> +
> +#define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk)	\
> +	{ .manufacturer_id = manufacturer,				\
> +			.model_id = model,				\
> +			.revision_number_major = rev,			\
> +			.flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE,	\
> +			.name = _name,					\
> +			.quirk = _quirk, }
> +
> +#define SMIAPP_IDENT_L(manufacturer, model, rev, _name)			\
> +	{ .manufacturer_id = manufacturer,				\
> +			.model_id = model,				\
> +			.revision_number_major = rev,			\
> +			.flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE,	\
> +			.name = _name, }
> +
> +#define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk)		\
> +	{ .manufacturer_id = manufacturer,				\
> +			.model_id = model,				\
> +			.revision_number_major = rev,			\
> +			.flags = 0,					\
> +			.name = _name,					\
> +			.quirk = _quirk, }
> +
> +#define SMIAPP_IDENT(manufacturer, model, rev, _name)			\
> +	{ .manufacturer_id = manufacturer,				\
> +			.model_id = model,				\
> +			.revision_number_major = rev,			\
> +			.flags = 0,					\
> +			.name = _name, }
> +

[snip]

> +/*
> + * struct smiapp_sensor - Main device structure
> + */
> +struct smiapp_sensor {
> +	/*
> +	 * "mutex" is used to serialise access to all fields here
> +	 * except v4l2_ctrls at the end of the struct. Should both
> +	 * "mutex" and the control handler locks be held
> +	 * simultaneously, the control handler lock must be acquired
> +	 * first. "mutex" is also used to serialise access to file
> +	 * handle specific information. The exception to this rule is
> +	 * the power_mutex below.
> +	 */

This comment is probably a bit outdated.

> +	struct mutex mutex;
> +	/*
> +	 * power_mutex is used to serialise opening and closing of
> +	 * file handles, including power management.
> +	 */
> +	struct mutex power_mutex;
> +	struct smiapp_subdev sds[SMIAPP_SUBDEVS];
> +	u32 sds_used;
> +	struct smiapp_subdev *src;
> +	struct smiapp_subdev *binner;
> +	struct smiapp_subdev *scaler;
> +	struct smiapp_subdev *pixel_array;
> +	struct smiapp_platform_data *platform_data;
> +	struct regulator *vana;
> +	u32 limits[SMIAPP_LIMIT_LAST];
> +	u8 nbinning_subtypes;
> +	struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
> +	u32 mbus_frame_fmts;
> +	const struct smiapp_csi_data_format *csi_format;
> +	const struct smiapp_csi_data_format *internal_csi_format;
> +	u32 default_mbus_frame_fmts;
> +	int default_pixel_order;
> +
> +	u8 binning_horizontal;
> +	u8 binning_vertical;
> +
> +	u8 scale_m;
> +	u8 scaling_mode;
> +
> +	u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
> +	u8 flash_capability;
> +	u8 frame_skip;
> +
> +	int power_count;
> +
> +	unsigned int streaming:1;
> +	unsigned int dev_init_done:1;
> +
> +	u8 *nvm;		/* nvm memory buffer */
> +	unsigned int nvm_size;	/* bytes */
> +
> +	struct smiapp_module_info minfo;
> +
> +	struct smiapp_pll pll;
> +
> +	/* Pixel array controls */
> +	struct v4l2_ctrl *analog_gain;
> +	struct v4l2_ctrl *exposure;
> +	struct v4l2_ctrl *hflip;
> +	struct v4l2_ctrl *vflip;
> +	struct v4l2_ctrl *vblank;
> +	struct v4l2_ctrl *hblank;
> +	struct v4l2_ctrl *pixel_rate_parray;
> +	/* src controls */
> +	struct v4l2_ctrl *link_freq;
> +	struct v4l2_ctrl *pixel_rate_csi;
> +};
> +
> +#define to_smiapp_subdev(_sd)				\
> +	container_of(_sd, struct smiapp_subdev, sd)
> +
> +#define to_smiapp_sensor(_sd)	\
> +	(to_smiapp_subdev(_sd)->sensor)
> +
> +int smiapp_pll_update(struct smiapp_sensor *sensor);
> +int smiapp_pll_configure(struct smiapp_sensor *sensor);
> +
> +#endif /* __SMIAPP_PRIV_H_ */

[snip]

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH v3 09/33] v4l: Add subdev selections documentation
  2012-02-26 21:42     ` Sakari Ailus
@ 2012-02-28 11:42       ` Laurent Pinchart
  2012-03-02 12:24         ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-28 11:42 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

On Sunday 26 February 2012 23:42:19 Sakari Ailus wrote:
> Laurent Pinchart wrote:
> > On Monday 20 February 2012 03:56:48 Sakari Ailus wrote:
> >> Add documentation for V4L2 subdev selection API. This changes also
> >> experimental V4L2 subdev API so that scaling now works through selection
> >> API only.
> >> 
> >> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> >> 
> >> 
> >> diff --git a/Documentation/DocBook/media/v4l/dev-subdev.xml
> >> b/Documentation/DocBook/media/v4l/dev-subdev.xml index 0916a73..9d5e7da
> >> 100644
> >> --- a/Documentation/DocBook/media/v4l/dev-subdev.xml
> >> +++ b/Documentation/DocBook/media/v4l/dev-subdev.xml
> > 
> > [snip]
> > 
> >> +      <para>Scaling operation changes the size of the image by scaling
> >> +      it to new dimensions. Some sub-devices support it. The scaled
> >> +      size (width and height) is represented by &v4l2-rect;. In the
> >> +      case of scaling, top and left will always be zero. Scaling is
> >> +      configured using &sub-subdev-g-selection; and
> >> +      <constant>V4L2_SUBDEV_SEL_COMPOSE_ACTIVE</constant> selection
> >> +      target on the sink pad of the subdev. The scaling is performed
> >> +      related to the width and height of the crop rectangle on the
> >> +      subdev's sink pad.</para>
> > 
> > I'm not sure if that would be very clear for readers who are not yet
> > familiar with the API. What about the following text instead ?
> > 
> > "The scaling operation changes the size of the image by scaling it to new
> > dimensions. The scaling ratio isn't specified explicitly, but is implied
> > from the original and scaled image sizes. Both sizes are represented by
> > &v4l2- rect;.
> > 
> > Scaling support is optional. When supported by a subdev, the crop
> > rectangle on the subdev's sink pad is scaled to the size configured using
> > &VIDIOC-SUBDEV-G- SELECTION; and
> > <constant>V4L2_SUBDEV_SEL_COMPOSE_ACTIVE</constant> selection target on
> > the same pad. If the subdev supports scaling but no composing, the top
> > and left values are not used and must always be set to zero."
> > 
> > (note that &sub-subdev-g-selection; has been replaced with
> > &VIDIOC-SUBDEV-G- SELECTION;)
> > 
> > I would also move this text after the sink pad crop description to follow
> > the order in which operations are applied by subdevs.
> 
> I'm fine with that change, so I did it. However, I won't replace
> &sub-subdev-g-selection; with &VIDIOC-SUBDEV-G-SELECTION; simply because
> it won't work:
> 
> dev-subdev.xml:310: parser error : Entity 'VIDIOC-SUBDEV-G-SELECTION'
> not defined
>       size configured using &VIDIOC-SUBDEV-G-SELECTION; and
> 
> It's beyond me why not; similar references are being used elsewhere with
> otherwise equivalent definitions. Perhaps the name is just too long?
> That's the only difference I could think of: xmlto typically segfaults
> on errors so I wouldn't be surprised of something so simple.

Don't give up so fast :-)

diff --git a/Documentation/DocBook/media/Makefile b/Documentation/DocBook/media/Makefile
index 729f840..77ead85 100644
--- a/Documentation/DocBook/media/Makefile
+++ b/Documentation/DocBook/media/Makefile
@@ -65,6 +65,8 @@ IOCTLS = \
 	$(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/dvb/video.h) \
 	$(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/media.h) \
 	$(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/v4l2-subdev.h) \
+	VIDIOC_SUBDEV_G_SELECTION \
+	VIDIOC_SUBDEV_S_SELECTION \
 	VIDIOC_SUBDEV_G_FRAME_INTERVAL \
 	VIDIOC_SUBDEV_S_FRAME_INTERVAL \
 	VIDIOC_SUBDEV_ENUM_MBUS_CODE \

and rm Documentation/DocBook/media-entities.tmpl before you compile the
documentation.

> >> +      <para>As for pad formats, drivers store try and active
> >> +      rectangles for the selection targets of ACTIVE type <xref
> >> +      linkend="v4l2-subdev-selection-targets">.</xref></para>
> >> +
> >> +      <para>On sink pads, cropping is applied relatively to the
> >> +      current pad format. The pad format represents the image size as
> >> +      received by the sub-device from the previous block in the
> >> +      pipeline, and the crop rectangle represents the sub-image that
> >> +      will be transmitted further inside the sub-device for
> >> +      processing.</para>
> >> +
> >> +      <para>On source pads, cropping is similar to sink pads, with the
> >> +      exception that the source size from which the cropping is
> >> +      performed, is the COMPOSE rectangle on the sink pad. In both
> >> +      sink and source pads, the crop rectangle must be entirely
> >> +      containted inside the source image size for the crop
> >> +      operation.</para>
> >> +
> >> +      <para>The drivers should always use the closest possible
> >> +      rectangle the user requests on all selection targets, unless
> >> +      specificly told otherwise<xref
> >> +      linkend="v4l2-subdev-selection-flags">.</xref></para>
> >> +    </section>
> >> +
> >> +    <section>
> >> +      <title>Types of selection targets</title>
> >> +
> >> +      <section>
> >> +	<title>ACTIVE targets</title>
> >> +
> >> +	<para>ACTIVE targets reflect the actual hardware configuration
> >> +	at any point of time.</para>
> >> +      </section>
> >> +
> >> +      <section>
> >> +	<title>BOUNDS targets</title>
> >> +
> >> +	<para>BOUNDS targets is the smallest rectangle within which
> >> +	contains all valid ACTIVE rectangles.
> > 
> > s/within which/that/ ?
> 
> Ack.
> 
> >> It may not be possible
> >> +	to set the ACTIVE rectangle as large as the BOUNDS rectangle,
> >> +	however.</para>
> > 
> > What about
> > 
> > "The BOUNDS rectangle might not itself be a valid ACTIVE rectangle when
> > all possible ACTIVE pixels do not form a rectangular shape (e.g.
> > cross-shaped or round sensors)."
> 
> There are cases where the active size is limited, even if it's
> rectangular. I can add the above case there, sure, if you think such
> devices exist --- I've never heard of nor seen them. Some sensors are
> documented to be cross-shaped but the only thing separating these from
> the rest is that the manufacturer doesn't guarantee the quality of the
> pixels in the corners. At least on those I've seen. You can still
> capture the full pixel matrix.

Those are just examples. I think it's useful to add them, otherwise the reader
won't know why and under what kind of circumstances the ACTIVE rectangle can't
be as large at the BOUNDS rectangle.

> >> +      </section>
> >> 
> >> -      <para>Cropping behaviour on output pads is not defined.</para>
> >> +    </section>
> >> +
> >> +    <section>
> >> +      <title>Order of configuration and format propagation</title>
> >> +
> >> +      <para>Inside subdevs, the order of image processing steps will
> >> +      always be from the sink pad towards the source pad. This is also
> >> +      reflected in the order in which the configuration must be
> >> +      performed by the user: the changes made will be propagated to
> >> +      any subsequent stages. If this behaviour is not desired, the
> >> +      user must set
> >> +      <constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant> flag.
> > 
> > Could you explain what happens when V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG is
> > set ? Just stating that it doesn't follow the propagation behaviour
> > previously described could be understood in many different ways.
> 
> Good point. How about this:
> 
> "This flag causes that no propagation of the changes are allowed in any
> circumstances. This may also lead the accessed rectangle not being
> changed at all,

"The accessed rectangle will likely be adjusted by the driver,"

> depending on the properties of the underlying hardware.
> Some drivers may not support this flag."

What should happen then ? Should the flag be ignored, or should the driver
return an error ?

> >> The
> >> +      coordinates to a step always refer to the active size of the
> >> +      previous step. The exception to this rule is the source compose
> >> +      rectangle, which refers to the sink compose bounds rectangle ---
> >> +      if it is supported by the hardware.</para>
> >> +
> >> +      <orderedlist>
> >> +	<listitem>Sink pad format. The user configures the sink pad
> >> +	format. This format defines the parameters of the image the
> >> +	entity receives through the pad for further processing.</listitem>
> >> +
> >> +	<listitem>Sink pad active crop selection. The sink pad crop
> >> +	defines the performed to the sink pad format.</listitem>
> > 
> > s/defines the/defines the cropping/ ?
> 
> Fixed.
> 
> >> +
> >> +	<listitem>Sink pad active compose selection. The size of the
> >> +	sink pad compose rectangle defines the scaling ratio compared
> >> +	to the size of the sink pad crop rectangle. The location of
> >> +	the compose rectangle specifies the location of the active
> >> +	sink compose rectangle in the sink compose bounds
> >> +	rectangle.</listitem>
> >> +
> >> +	<listitem>Source pad active crop selection. Crop on the source
> >> +	pad defines crop performed to the image in the sink compose
> >> +	bounds rectangle.</listitem>
> >> +
> >> +	<listitem>Source pad format. The source pad format defines the
> >> +	output pixel format of the subdev, as well as the other
> >> +	parameters with the exception of the image width and height.
> >> +	Width and height are defined by the size of the source pad
> >> +	active crop selection.</listitem>
> >> +      </orderedlist>
> >> +
> >> +      <para>Accessing any of the above rectangles not supported by the
> >> +      subdev will return <constant>EINVAL</constant>.
> > 
> > Do drivers have to support BOUNDS rectangles for every ACTIVE rectangle
> > they support (and the other way around) ? If so, I think it should be
> > specified.
> I think the answer to that should be "yes", albeit this hasn't been
> discussed previously. I see no reason not to support equivalent BOUNDS
> rectangles.
> 
> I'll change the documentation to state that.
> 
> > Is EINVAL returned for any other error case in the selection API ? If so,
> > it might make enumeration of the supported rectangles difficult.
> 
> Good point. There are two other reasons to return EINVAL and those are
> invalid parameters in either pad or which fields. I think that should be
> fine. I'd keep it EINVAL.
> 
> Alternatively we could use e.g. ENOENT.
> 
> What do you think?

I'm OK with EINVAL then, as applications shouldn't pass an invalid pad or
which value in the first place.

> >> Any rectangle
> >> +      referring to a previous unsupported rectangle coordinates will
> >> +      instead refer to the previous supported rectangle. For example,
> >> +      if sink crop is not supported, the compose selection will refer
> >> +      to the sink pad format dimensions instead.</para>
> > 
> > Should we add a list of the rectangles a subdev must/should/can support
> > for the different possible use cases ?
> 
> I think this should be rather obvious with the examples and the
> statement on BOUNDS rectangles. Such a list, if we make it very
> detailed, will be unnecessarily redundant and will soon become
> out-of-date. In principle I don't like redundancy whether it's code or
> documentation. It easily leads to contradictions.
> 
> If it turns out it'll be needed we can easily add it later on.

OK.

[snip]

> >> diff --git
> >> a/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
> >> b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml new file
> >> mode 100644
> >> index 0000000..033077a
> >> --- /dev/null
> >> +++ b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml

[snip]

> >> +    <table pgwide="1" frame="none" id="v4l2-subdev-selection-flags">
> >> +      <title>V4L2 subdev selection flags</title>
> >> +      <tgroup cols="3">
> >> +        &cs-def;
> >> +	<tbody valign="top">
> >> +	  <row>
> >> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_GE</constant></entry>
> >> +	    <entry>(1 &lt;&lt; 0)</entry>
> >> +	    <entry>Suggest the driver it should choose greater or
> >> +	    equal rectangle (in size) than was requested.</entry>
> >> +	  </row>
> >> +	  <row>
> >> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_LE</constant></entry>
> >> +	    <entry>(1 &lt;&lt; 1)</entry>
> >> +	    <entry>Suggest the driver it should choose lesser or
> >> +	    equal rectangle (in size) than was requested.</entry>
> >> +	  </row>
> > 
> > Those two flags are only briefly described here, could you add a more
> > detailed description either here or in
> > Documentation/DocBook/media/v4l/dev-subdev.xml ?
> Added:
> 
>             " Albeit the driver may choose a lesser size,
> 	    it will only do so due to hardware limitations. Without
> 	    this flag (and
> 	    <constant>V4L2_SUBDEV_SEL_FLAG_SIZE_LE</constant>) the
> 	    behaviour is to choose the closest possible
> 	    rectangle."
> 
> Does that cover your understanding of a more detailed description? :-)

I was thinking about something in media/v4l/dev-subdev.xml that would explain
what the flags are used for. media/v4l/vidioc-subdev-g-selection.xml is more
like reference documentation.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 33/33] rm680: Add camera init
  2012-02-27  1:06   ` Laurent Pinchart
@ 2012-02-28 19:05     ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-02-28 19:05 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
> Thanks for the patch.

Thanks for the review!

> On Monday 20 February 2012 03:57:12 Sakari Ailus wrote:
>> From: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
>>
>> This currently introduces an extra file to the arch/arm/mach-omap2
>> directory: board-rm680-camera.c. Keeping the device tree in mind, the
>> context of the file could be represented as static data with one exception:
>> the external clock to the sensor.
>>
>> This external clock is provided by the OMAP 3 SoC and required by the
>> sensor. The issue is that the clock originates from the ISP and not from
>> PRCM block as the other clocks and thus is not supported by the clock
>> framework. Otherwise the sensor driver could just clk_get() and clk_enable()
>> it, just like the regulators and gpios.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
>> ---
>>  arch/arm/mach-omap2/Makefile             |    3 +-
>>  arch/arm/mach-omap2/board-rm680-camera.c |  375 +++++++++++++++++++++++++++
>>  arch/arm/mach-omap2/board-rm680.c        |   38 +++
>>  3 files changed, 415 insertions(+), 1 deletions(-)
>>  create mode 100644 arch/arm/mach-omap2/board-rm680-camera.c
>>
> 
> [snip]
> 
>> diff --git a/arch/arm/mach-omap2/board-rm680-camera.c
>> b/arch/arm/mach-omap2/board-rm680-camera.c new file mode 100644
>> index 0000000..5059821
>> --- /dev/null
>> +++ b/arch/arm/mach-omap2/board-rm680-camera.c
> 
> [snip]
> 
>> +#include <asm/mach-types.h>
>> +#include <plat/omap-pm.h>
>> +
>> +#include <media/omap3isp.h>
>> +#include <media/smiapp.h>
>> +
>> +#include "../../../drivers/media/video/omap3isp/isp.h"
> 
> Do we still need the private OMAP3 ISP header ? You can move the ISP_XCLK_* 
> macros to the public header (and maybe rename them to OMAP3ISP_XCLK_*).

Not for macros, but for e.g. isp_device definition (for platform
callbacks) that are related to XCLK. Once we get the generic clock
framework we can get rid of this.

>> +#include "devices.h"
>> +
>> +#define SEC_CAMERA_RESET_GPIO	97
>> +
>> +#define RM680_PRI_SENSOR	1
>> +#define RM680_PRI_LENS		2
>> +#define RM680_SEC_SENSOR	3
>> +#define MAIN_CAMERA_XCLK	ISP_XCLK_A
>> +#define SEC_CAMERA_XCLK		ISP_XCLK_B
>> +
>> +/*
>> + *
>> + * Main Camera Module EXTCLK
>> + * Used by the sensor and the actuator driver.
>> + *
>> + */
>> +static struct camera_xclk {
>> +	u32 hz;
>> +	u32 lock;
>> +	u8 xclksel;
>> +} cameras_xclk;
>> +
>> +static DEFINE_MUTEX(lock_xclk);
>> +
>> +static int rm680_update_xclk(struct v4l2_subdev *subdev, u32 hz, u32 which,
>> +			     u8 xclksel)
>> +{
>> +	struct isp_device *isp = v4l2_dev_to_isp_device(subdev->v4l2_dev);
>> +	int ret;
>> +
>> +	mutex_lock(&lock_xclk);
>> +
>> +	if (which == RM680_SEC_SENSOR) {
>> +		if (cameras_xclk.xclksel == MAIN_CAMERA_XCLK) {
>> +			ret = -EBUSY;
>> +			goto done;
>> +		}
>> +	} else {
>> +		if (cameras_xclk.xclksel == SEC_CAMERA_XCLK) {
>> +			ret = -EBUSY;
>> +			goto done;
>> +		}
>> +	}
>> +
>> +	if (hz) {	/* Turn on */
>> +		cameras_xclk.lock |= which;
>> +		if (cameras_xclk.hz == 0) {
>> +			isp->platform_cb.set_xclk(isp, hz, xclksel);
>> +			cameras_xclk.hz = hz;
>> +			cameras_xclk.xclksel = xclksel;
>> +		}
>> +	} else {	/* Turn off */
>> +		cameras_xclk.lock &= ~which;
>> +		if (cameras_xclk.lock == 0) {
>> +			isp->platform_cb.set_xclk(isp, 0, xclksel);
>> +			cameras_xclk.hz = 0;
>> +			cameras_xclk.xclksel = 0;
>> +		}
>> +	}
>> +
>> +	ret = cameras_xclk.hz;
>> +
>> +done:
>> +	mutex_unlock(&lock_xclk);
>> +	return ret;
>> +}
> 
> I don't like this, but we can't do much better until the generic struct clk is 
> available :-) However, in addition to handling the ISP clocks, the above code 
> also prevents the two sensors from being used at the same time. This won't be 
> handle by the clock framework and will need to be implemented somewhere else. 
> Shouldn't we already split the two functions ?

This code will disappear with generic clock framework. It's as simple as
that.

To prevent them from being used simultaneously we should probably use
two virtual regulators --- one for each sensor and only one can be
powered simultaneously. There's actually even a small delay for the
duration of which one must wait before powering on the other one. That
can be easily handled in regulators, too (I guess).

>> +
>> +/*
>> + *
>> + * Main Camera Sensor
>> + *
>> + */
>> +
>> +static int rm680_main_camera_set_xclk(struct v4l2_subdev *sd, int hz)
>> +{
>> +	return rm680_update_xclk(sd, hz, RM680_PRI_SENSOR, MAIN_CAMERA_XCLK);
>> +}
>> +
>> +static struct smiapp_flash_strobe_parms rm680_main_camera_strobe_setup = {
>> +	.mode			= 0x0c,
>> +	.strobe_width_high_us	= 100000,
>> +	.strobe_delay		= 0,
>> +	.stobe_start_point	= 0,
>> +	.trigger		= 0,
>> +};
>> +
>> +static struct smiapp_platform_data rm696_main_camera_platform_data = {
>> +	.i2c_addr_dfl		= SMIAPP_DFL_I2C_ADDR,
>> +	.i2c_addr_alt		= SMIAPP_ALT_I2C_ADDR,
>> +	.nvm_size		= 16 * 64,
>> +	.ext_clk		= (9.6 * 1000 * 1000),
> 
> Parenthesis are not needed.

Fixed.

>> +	.lanes			= 2,
>> +	/* bit rate / ddr / lanes */
>> +	.op_sys_clock		= (s64 []){ 796800000 / 2 / 2,
>> +					    840000000 / 2 / 2,
>> +					    1996800000 / 2 / 2, 0 },
>> +	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CSI2,
>> +	.strobe_setup		= &rm680_main_camera_strobe_setup,
> 
> What about embedding the flash strobe parameters in smiapp_platform_data ? Do 
> you think that would be better ?

The same struct is used on both sensors, and making this part of the
smiapp_platform_data directly would cause duplication of the definition.
That said, I don't like this either, and actually think it'll go away sooner
or later.

>> +	.set_xclk		= rm680_main_camera_set_xclk,
>> +	.xshutdown		= SMIAPP_NO_XSHUTDOWN,
>> +};
>> +
>> +static struct smiapp_platform_data rm680_main_camera_platform_data = {
>> +	.i2c_addr_dfl		= SMIAPP_DFL_I2C_ADDR,
>> +	.i2c_addr_alt		= SMIAPP_ALT_I2C_ADDR,
>> +	.nvm_size		= 16 * 64,
>> +	.ext_clk		= (9.6 * 1000 * 1000),
>> +	.lanes			= 2,
>> +	.op_sys_clock		= (s64 []){ 840000000 / 2 / 2,
>> +					    1334400000 / 2 / 2,
>> +					    1593600000 / 2 / 2, 0 },
>> +	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CSI2,
>> +	.module_board_orient	= SMIAPP_MODULE_BOARD_ORIENT_180,
>> +	.strobe_setup		= &rm680_main_camera_strobe_setup,
>> +	.set_xclk		= rm680_main_camera_set_xclk,
>> +	.xshutdown		= SMIAPP_NO_XSHUTDOWN,
>> +};
>> +
>> +/*
>> + *
>> + * SECONDARY CAMERA Sensor
>> + *
>> + */
>> +
>> +#define SEC_CAMERA_XCLK		ISP_XCLK_B
>> +
>> +static int rm680_sec_camera_set_xclk(struct v4l2_subdev *sd, int hz)
>> +{
>> +	return rm680_update_xclk(sd, hz, RM680_SEC_SENSOR, SEC_CAMERA_XCLK);
>> +}
>> +
>> +static struct smiapp_platform_data rm696_sec_camera_platform_data = {
>> +	.ext_clk		= (10.8 * 1000 * 1000),
>> +	.lanes			= 1,
>> +	/* bit rate / ddr */
>> +	.op_sys_clock		= (s64 []){ 13770000 * 10 / 2, 0 },
>> +	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK,
>> +	.module_board_orient	= SMIAPP_MODULE_BOARD_ORIENT_180,
>> +	.set_xclk		= rm680_sec_camera_set_xclk,
>> +	.xshutdown		= SEC_CAMERA_RESET_GPIO,
>> +};
>> +
>> +static struct smiapp_platform_data rm680_sec_camera_platform_data = {
>> +	.ext_clk		= (10.8 * 1000 * 1000),
>> +	.lanes			= 1,
>> +	/* bit rate / ddr */
>> +	.op_sys_clock		= (s64 []){ 11880000 * 10 / 2, 0 },
>> +	.csi_signalling_mode	= SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK,
>> +	.set_xclk		= rm680_sec_camera_set_xclk,
>> +	.xshutdown		= SEC_CAMERA_RESET_GPIO,
>> +};
>> +
>> +/*
>> + *
>> + * Init all the modules
>> + *
>> + */
>> +
>> +#define CAMERA_I2C_BUS_NUM		2
>> +#define AD5836_I2C_BUS_NUM		2
>> +#define AS3645A_I2C_BUS_NUM		2
>> +
>> +static struct i2c_board_info rm696_camera_i2c_devices[] = {
>> +	{
>> +		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_ALT_I2C_ADDR),
>> +		.platform_data = &rm696_main_camera_platform_data,
>> +	},
>> +	{
>> +		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_DFL_I2C_ADDR),
>> +		.platform_data = &rm696_sec_camera_platform_data,
>> +	},
>> +};
>> +
>> +static struct i2c_board_info rm680_camera_i2c_devices[] = {
>> +	{
>> +		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_ALT_I2C_ADDR),
>> +		.platform_data = &rm680_main_camera_platform_data,
>> +	},
>> +	{
>> +		I2C_BOARD_INFO(SMIAPP_NAME, SMIAPP_DFL_I2C_ADDR),
>> +		.platform_data = &rm680_sec_camera_platform_data,
>> +	},
>> +};
>> +
>> +static struct isp_subdev_i2c_board_info rm696_camera_primary_subdevs[] = {
>> +	{
>> +		.board_info = &rm696_camera_i2c_devices[0],
>> +		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
>> +	},
>> +	{ NULL, 0, },
>> +};
>> +
>> +static struct isp_subdev_i2c_board_info rm696_camera_secondary_subdevs[] =
>> { +	{
>> +		.board_info = &rm696_camera_i2c_devices[1],
>> +		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
>> +	},
>> +	{ NULL, 0, },
>> +};
>> +
>> +static struct isp_subdev_i2c_board_info rm680_camera_primary_subdevs[] = {
>> +	{
>> +		.board_info = &rm680_camera_i2c_devices[0],
>> +		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
>> +	},
>> +	{ NULL, 0, },
>> +};
>> +
>> +static struct isp_subdev_i2c_board_info rm680_camera_secondary_subdevs[] =
>> { +	{
>> +		.board_info = &rm680_camera_i2c_devices[1],
>> +		.i2c_adapter_id = CAMERA_I2C_BUS_NUM,
>> +	},
>> +	{ NULL, 0, },
>> +};
>> +
>> +static struct isp_v4l2_subdevs_group rm696_camera_subdevs[] = {
>> +	{
>> +		.subdevs = rm696_camera_primary_subdevs,
>> +		.interface = ISP_INTERFACE_CSI2A_PHY2,
>> +		.bus = { .csi2 = {
>> +			.crc		= 1,
>> +			.vpclk_div	= 1,
> 
> Just wondering, is vpclk_div really needed in platform data, or should it be 
> computed by the driver at runtime based on the clock frequencies ?

Probably, but I don't know how. :-)

Figuring out that probably requires some work. It was originally set
fixed since we didn't have any information on the clocks in the driver
itself.

The TRM doesn't explicitly say how to configure this; it just tells to set
the value if the reset value isn't correct. ;-) I think actually that it
might be possible to calculate this from pixel rate and l3_ick.

I'll need to try how that works out. Do you think I should try to make this
change as part of this patchset? I'd suggest to postpone it to avoid
breaking too many things at once --- there are already large number of
changes to the ISP driver.

>> +			.lanecfg	= {
>> +				.clk = {
>> +					.pol = 1,
>> +					.pos = 2,
>> +				},
>> +				.data[0] = {
>> +					.pol = 1,
>> +					.pos = 1,
>> +				},
>> +				.data[1] = {
>> +					.pol = 1,
>> +					.pos = 3,
>> +				},
>> +			},
>> +		} },
>> +	},
>> +	{
>> +		.subdevs = rm696_camera_secondary_subdevs,
>> +		.interface = ISP_INTERFACE_CCP2B_PHY1,
>> +		.bus = { .ccp2 = {
>> +			.strobe_clk_pol	= 0,
>> +			.crc		= 0,
>> +			.ccp2_mode	= 0,
>> +			.phy_layer	= 0,
>> +			.vpclk_div	= 2,
>> +			.lanecfg	= {
>> +				.clk = {
>> +					.pol = 0,
>> +					.pos = 1,
>> +				},
>> +				.data[0] = {
>> +					.pol = 0,
>> +					.pos = 2,
>> +				},
>> +			},
>> +		} },
>> +	},
>> +	{ NULL, 0, },
>> +};
>> +
>> +static struct isp_v4l2_subdevs_group rm680_camera_subdevs[] = {
>> +	{
>> +		.subdevs = rm680_camera_primary_subdevs,
>> +		.interface = ISP_INTERFACE_CSI2A_PHY2,
>> +		.bus = { .csi2 = {
>> +			.crc		= 1,
>> +			.vpclk_div	= 1,
>> +			.lanecfg	= {
>> +				.clk = {
>> +					.pol = 1,
>> +					.pos = 2,
>> +				},
>> +				.data[0] = {
>> +					.pol = 1,
>> +					.pos = 3,
>> +				},
>> +				.data[1] = {
>> +					.pol = 1,
>> +					.pos = 1,
>> +				},
>> +			},
>> +		} },
>> +	},
>> +	{
>> +		.subdevs = rm680_camera_secondary_subdevs,
>> +		.interface = ISP_INTERFACE_CCP2B_PHY1,
>> +		.bus = { .ccp2 = {
>> +			.strobe_clk_pol	= 0,
>> +			.crc		= 0,
>> +			.ccp2_mode	= 0,
>> +			.phy_layer	= 0,
>> +			.vpclk_div	= 2,
>> +			.lanecfg	= {
>> +				.clk = {
>> +					.pol = 0,
>> +					.pos = 1,
>> +				},
>> +				.data[0] = {
>> +					.pol = 0,
>> +					.pos = 2,
>> +				},
>> +			},
>> +		} },
>> +	},
>> +	{ NULL, 0, },
>> +};
> 

Regards,

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 32/33] smiapp: Add driver.
  2012-02-27 15:38   ` Laurent Pinchart
@ 2012-02-29  5:41     ` Sakari Ailus
  2012-02-29  9:35       ` Laurent Pinchart
  0 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-02-29  5:41 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

On Mon, Feb 27, 2012 at 04:38:49PM +0100, Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.

Thanks for the review!!

> On Monday 20 February 2012 03:57:11 Sakari Ailus wrote:
> > From: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> > 
> > Add driver for SMIA++/SMIA image sensors. The driver exposes the sensor as
> > three subdevs, pixel array, binner and scaler --- in case the device has a
> > scaler.
> > 
> > Currently it relies on the board code for external clock handling. There is
> > no fast way out of this dependency before the ISP drivers (omap3isp) among
> > others will be able to export that clock through the clock framework
> > instead.
> > 
> > Signed-off-by: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> 
> [snip]
> 
> > diff --git a/drivers/media/video/smiapp/Kconfig
> > b/drivers/media/video/smiapp/Kconfig new file mode 100644
> > index 0000000..3f98e8e
> > --- /dev/null
> > +++ b/drivers/media/video/smiapp/Kconfig
> > @@ -0,0 +1,12 @@
> > +config VIDEO_SMIAPP
> > +	tristate "SMIA++/SMIA sensor support"
> > +	depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER
> 
> VIDEO_V4L2_SUBDEV_API depends on MEDIA_CONTROLLER, you don't have to set the
> dependency explicitly.

Ok. I'll remove the dependency.

> > +	---help---
> > +	  This is a generic driver for SMIA++/SMIA camera modules.
> > +
> > +config VIDEO_SMIAPP_DEBUG
> > +	bool "Enable debugging for the generic SMIA++/SMIA driver"
> > +	depends on VIDEO_SMIAPP
> > +	---help---
> > +	  Enable debugging output in the generic SMIA++/SMIA driver. If you
> > +	  are developing the driver you might want to enable this.
> 
> [snip]
> 
> > diff --git a/drivers/media/video/smiapp/smiapp-core.c
> > b/drivers/media/video/smiapp/smiapp-core.c new file mode 100644
> > index 0000000..9fd08a1
> > --- /dev/null
> > +++ b/drivers/media/video/smiapp/smiapp-core.c
> 
> [snip]
> 
> > +#define SMIAPP_ALIGN_DIM(dim, flags)	      \
> > +	(flags & V4L2_SUBDEV_SEL_FLAG_SIZE_GE \
> > +	 ? ALIGN(dim, 2)		      \
> > +	 : dim & ~1)
> 
> Please enclose dim in parenthesis in the macro definition.

Flags, too...

> > +
> > +/*
> > + * smiapp_module_idents - supported camera modules
> > + */
> > +static const struct smiapp_module_ident smiapp_module_idents[] = {
> > +	SMIAPP_IDENT_LQ(0x10, 0x4141, -1, "jt8ev1", &smiapp_jt8ev1_quirk),
> > +	SMIAPP_IDENT_LQ(0x10, 0x4241, -1, "imx125es", &smiapp_imx125es_quirk),
> > +	SMIAPP_IDENT_L(0x01, 0x022b, -1, "vs6555"),
> > +	SMIAPP_IDENT_L(0x0c, 0x208a, -1, "tcm8330md"),
> > +	SMIAPP_IDENT_L(0x01, 0x022e, -1, "vw6558"),
> > +	SMIAPP_IDENT_LQ(0x0c, 0x2134, -1, "tcm8500md", &smiapp_tcm8500md_quirk),
> > +	SMIAPP_IDENT_L(0x07, 0x7698, -1, "ovm7698"),
> > +	SMIAPP_IDENT_L(0x0b, 0x4242, -1, "smiapp-003"),
> > +	SMIAPP_IDENT_LQ(0x0c, 0x560f, -1, "jt8ew9", &smiapp_jt8ew9_quirk),
> > +	SMIAPP_IDENT_L(0x0c, 0x213e, -1, "et8en2"),
> > +	SMIAPP_IDENT_L(0x0c, 0x2184, -1, "tcm8580md"),
> > +};
> 
> What about sorting those either by ID or name ?

By ID it makes more sense, I think.

> > +
> > +/*
> > + *
> > + * Dynamic Capability Identification
> > + *
> > + */
> > +
> > +static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	u32 fmt_model_type, fmt_model_subtype, ncol_desc, nrow_desc;
> > +	int i;
> > +	int rval;
> > +	int line_count = 0;
> > +	int embedded_start = -1, embedded_end = -1;
> > +	int image_start = 0;
> > +
> > +	rval = smia_i2c_read_reg(client,
> > +				 SMIAPP_REG_U8_FRAME_FORMAT_MODEL_TYPE,
> > +				 &fmt_model_type);
> > +	if (rval)
> > +		return rval;
> > +
> > +	rval = smia_i2c_read_reg(client,
> > +				 SMIAPP_REG_U8_FRAME_FORMAT_MODEL_SUBTYPE,
> > +				 &fmt_model_subtype);
> > +	if (rval)
> > +		return rval;
> > +
> > +	ncol_desc = (fmt_model_subtype
> > +		     & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_MASK)
> > +		>> SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_SHIFT;
> > +	nrow_desc = (fmt_model_subtype
> > +		     & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NROWS_MASK);
> 
> No need for parenthesis.

Fixed.

> > +
> > +	dev_dbg(&client->dev, "format_model_type %s\n",
> > +		fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE
> > +		? "2 byte" :
> > +		fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE
> > +		? "4 byte" : "is simply bad");
> 
> Simply ? :-)

Yeah, well, it's not that complex. :-) Do you think I should change that to
something else?

> > +
> > +	for (i = 0; i < ncol_desc + nrow_desc; i++) {
> > +		u32 desc;
> > +		u32 pixelcode;
> > +		u32 pixels;
> > +		char *which;
> > +		char *what;
> > +
> > +		if (fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE) {
> > +			rval = smia_i2c_read_reg(
> > +				client,
> > +				SMIAPP_REG_U16_FRAME_FORMAT_DESCRIPTOR_2(i),
> > +				&desc);
> > +			if (rval)
> > +				return rval;
> > +
> > +			pixelcode =
> > +				(desc
> > +				 & SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_MASK)
> > +				>> SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_SHIFT;
> > +			pixels = desc & SMIAPP_FRAME_FORMAT_DESC_2_PIXELS_MASK;
> > +		} else if (fmt_model_type
> > +			   == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE) {
> > +			rval = smia_i2c_read_reg(
> > +				client,
> > +				SMIAPP_REG_U32_FRAME_FORMAT_DESCRIPTOR_4(i),
> > +				&desc);
> > +			if (rval)
> > +				return rval;
> > +
> > +			pixelcode =
> > +				(desc
> > +				 & SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_MASK)
> > +				>> SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_SHIFT;
> > +			pixels = desc & SMIAPP_FRAME_FORMAT_DESC_4_PIXELS_MASK;
> > +		} else {
> > +			dev_dbg(&client->dev,
> > +				"invalid frame format model type %d\n",
> > +				fmt_model_type);
> > +			return -EINVAL;
> > +		}
> > +
> > +		if (i < ncol_desc)
> > +			which = "columns";
> > +		else
> > +			which = "rows";
> > +
> > +		switch (pixelcode) {
> > +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED:
> > +			what = "embedded";
> > +			break;
> > +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DUMMY:
> > +			what = "dummy";
> > +			break;
> > +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_BLACK:
> > +			what = "black";
> > +			break;
> > +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DARK:
> > +			what = "dark";
> > +			break;
> > +		case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE:
> > +			what = "visible";
> > +			break;
> > +		default:
> > +			what = "invalid";
> > +			dev_dbg(&client->dev, "pixelcode %d\n", pixelcode);
> > +			break;
> > +		}
> > +
> > +		dev_dbg(&client->dev, "%s pixels: %d %s\n",
> > +			what, pixels, which);
> > +
> > +		if (i < ncol_desc)
> > +			continue;
> > +
> > +		/* Handle row descriptors */
> > +		if (pixelcode
> > +		    == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED) {
> > +			embedded_start = line_count;
> > +		} else {
> > +			if (pixelcode
> > +			    == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE
> > +			    || pixels
> > +			    >= sensor->limits[
> > +				    SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES] / 2) {
> 
> I'm not a huge fan of lines larger than 80 columns, but it would make sense
> here. This is hard to read. An option would be to shorten all the constants a
> bit.

Done. I also realised the braces were not needed.

I'd prefer to keep the names since they're quite descriptive this way, and
are local to the driver..

> > +				image_start = line_count;
> > +			}
> > +			if (embedded_start != -1 && embedded_end == -1)
> > +				embedded_end = line_count;
> > +		}
> > +		line_count += pixels;
> > +	}
> > +
> > +	if (embedded_start == -1 || embedded_end == -1)
> > +		embedded_start = embedded_end = 0;
> 
> One assignment per line please.

I'm not sure if you gain any clarity with that, but I guess it's a norm
still. Fixed.

> > +
> > +	dev_dbg(&client->dev, "embedded data from lines %d to %d\n",
> > +		embedded_start, embedded_end);
> > +	dev_dbg(&client->dev, "image data starts at line %d\n", image_start);
> > +
> > +	return 0;
> > +}
> > +
> > +/*
> > + *
> > + * V4L2 Controls handling
> > + *
> > + */
> > +
> > +static void __smiapp_update_exposure_limits(struct smiapp_sensor *sensor)
> > +{
> > +	struct v4l2_ctrl *ctrl = sensor->exposure;
> > +	int max;
> > +
> > +	max = sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
> > +		+ sensor->vblank->val -
> > +		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MAX_MARGIN];
> 
> Just for reference, I would have found
> 
> 	max = sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
> 	    + sensor->vblank->val
> 	    - sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MAX_MARGIN];
> 
> to be more readable, but it's obviously your call.

Moved "-" to the previous line.

> > +
> > +	ctrl->maximum = max;
> > +	if (ctrl->default_value > max)
> > +		ctrl->default_value = max;
> > +	if (ctrl->val > max)
> > +		ctrl->val = max;
> > +	if (ctrl->cur.val > max)
> > +		ctrl->cur.val = max;
> > +}
> > +
> > +/*
> > + * Order matters.
> > + *
> > + * 1. Bits-per-pixel, descending.
> > + * 2. Bits-per-pixel compressed, descending.
> > + * 3. Pixel order, same as in pixel_order_str. Formats for all four pixel
> > + *    orders must be defined.
> > + */
> > +static const struct smiapp_csi_data_format smiapp_csi_data_formats[] = {
> > +	{ V4L2_MBUS_FMT_SGRBG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GRBG, },
> > +	{ V4L2_MBUS_FMT_SRGGB12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_RGGB, },
> > +	{ V4L2_MBUS_FMT_SBGGR12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_BGGR, },
> > +	{ V4L2_MBUS_FMT_SGBRG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GBRG, },
> > +	{ V4L2_MBUS_FMT_SGRBG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GRBG, },
> > +	{ V4L2_MBUS_FMT_SRGGB10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_RGGB, },
> > +	{ V4L2_MBUS_FMT_SBGGR10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_BGGR, },
> > +	{ V4L2_MBUS_FMT_SGBRG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GBRG, },
> > +	{ V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GRBG, },
> > +	{ V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_RGGB, },
> > +	{ V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_BGGR, },
> > +	{ V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GBRG, },
> > +};
> > +
> > +const char *pixel_order_str[] = { "GRBG", "RGGB", "BGGR", "GBRG" };
> > +
> > +#define to_csi_format_idx(fmt) (((unsigned long)(fmt)			\
> > +				 - (unsigned long)smiapp_csi_data_formats) \
> > +				/ sizeof(*smiapp_csi_data_formats))
> > +
> > +static void smiapp_update_mbus_formats(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	int csi_format_idx = to_csi_format_idx(sensor->csi_format) & ~3;
> > +	int internal_csi_format_idx =
> > +		to_csi_format_idx(sensor->internal_csi_format) & ~3;
> > +	int flip = 0;
> > +	int pixel_order;
> 
> Here again shortening names a bit might help.
> 
> > +
> > +	if (sensor->hflip) {
> > +		if (sensor->hflip->val)
> > +			flip |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
> > +
> > +		if (sensor->vflip->val)
> > +			flip |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
> > +	}
> > +
> > +	flip ^= sensor->hvflip_inv_mask;
> > +
> > +	pixel_order = sensor->default_pixel_order ^ flip;
> > +
> > +	sensor->mbus_frame_fmts =
> > +		sensor->default_mbus_frame_fmts << pixel_order;
> > +	sensor->csi_format =
> > +		&smiapp_csi_data_formats[csi_format_idx + pixel_order];
> > +	sensor->internal_csi_format =
> > +		&smiapp_csi_data_formats[internal_csi_format_idx
> > +					 + pixel_order];
> > +
> > +	BUG_ON(max(internal_csi_format_idx, csi_format_idx) + pixel_order
> > +	       >= ARRAY_SIZE(smiapp_csi_data_formats));
> > +	BUG_ON(min(internal_csi_format_idx, csi_format_idx) < 0);
> > +
> > +	dev_dbg(&client->dev, "flip %d; new pixel order %s\n",
> > +		flip, pixel_order_str[pixel_order]);
> > +}
> > +
> > +static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)
> > +{
> > +	struct smiapp_sensor *sensor =
> > +		container_of(ctrl->handler, struct smiapp_subdev, ctrl_handler)
> > +			->sensor;
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	u32 orient;
> > +	int exposure;
> > +	int rval = 0;
> > +
> > +	switch (ctrl->id) {
> > +	case V4L2_CID_ANALOGUE_GAIN:
> > +		return smia_i2c_write_reg(
> > +			client,
> > +			SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GLOBAL, ctrl->val);
> > +
> > +	case V4L2_CID_EXPOSURE:
> > +		return smia_i2c_write_reg(
> > +			client,
> > +			SMIAPP_REG_U16_COARSE_INTEGRATION_TIME, ctrl->val);
> > +
> > +	case V4L2_CID_HFLIP:
> > +	case V4L2_CID_VFLIP:
> > +		orient = 0;
> 
> You can move this line after the streaming check.

Moved the assignment to initialisation.

> > +
> > +		if (sensor->streaming)
> > +			return -EBUSY;
> > +
> > +		if (sensor->hflip->val)
> > +			orient |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
> > +
> > +		if (sensor->vflip->val)
> > +			orient |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
> > +
> > +		orient ^= sensor->hvflip_inv_mask;
> > +		rval = smia_i2c_write_reg(client,
> > +					  SMIAPP_REG_U8_IMAGE_ORIENTATION,
> > +					  orient);
> > +		if (rval < 0)
> > +			return rval;
> > +
> > +		smiapp_update_mbus_formats(sensor);
> > +
> > +		return 0;
> > +
> > +	case V4L2_CID_VBLANK:
> > +		exposure = sensor->exposure->val;
> > +
> > +		__smiapp_update_exposure_limits(sensor);
> > +
> > +		if (exposure > sensor->exposure->maximum) {
> > +			sensor->exposure->val =
> > +				sensor->exposure->maximum;
> > +			rval = smiapp_set_ctrl(
> > +				sensor->exposure);
> 
> Shouldn't you call the V4L2 control API here instead ? Otherwise no control
> change event will be generated for the exposure time. Will this work as
> expected if the user sets the exposure time in the same VIDIOC_S_EXT_CTRLS
> call ?

Good question. I'm holding the ctrl handler lock here and so can't use the
regular functions to perform the change. Perhaps time to implement
__v4l2_subdev_s_ext_ctrls() and use that?

> > +		}
> > +
> > +		if (rval < 0)
> > +			return rval;
> 
> If you moved this check inside the if you wouldn't have to initialize rval to
> 0 above.

Fixed.

> > +
> > +		return smia_i2c_write_reg(
> > +			client, SMIAPP_REG_U16_FRAME_LENGTH_LINES,
> > +			sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
> > +			+ ctrl->val);
> > +
> > +	case V4L2_CID_HBLANK:
> > +		return smia_i2c_write_reg(
> > +			client, SMIAPP_REG_U16_LINE_LENGTH_PCK,
> > +			sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width
> > +			+ ctrl->val);
> > +
> > +	case V4L2_CID_LINK_FREQ:
> > +		if (sensor->streaming)
> > +			return -EBUSY;
> > +
> > +		return smiapp_pll_update(sensor);
> > +
> > +	default:
> > +		return -EINVAL;
> > +	}
> > +}
> > +
> > +static const struct v4l2_ctrl_ops smiapp_ctrl_ops = {
> > +	.s_ctrl = smiapp_set_ctrl,
> > +};
> > +
> > +static int smiapp_init_controls(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	struct v4l2_ctrl_config cfg;
> > +	int rval;
> > +
> > +	rval = v4l2_ctrl_handler_init(&sensor->pixel_array->ctrl_handler, 7);
> > +	if (rval)
> > +		return rval;
> > +	sensor->pixel_array->ctrl_handler.lock = &sensor->mutex;
> > +
> > +	sensor->analog_gain = v4l2_ctrl_new_std(
> > +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> > +		V4L2_CID_ANALOGUE_GAIN,
> > +		sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN],
> > +		sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX],
> > +		max_t(int,
> > +		      sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_STEP], 1),
> 
> Won't max() work ? You might have to use 1U though.

Thanks. Fixed.

> > +		sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN]);
> > +
> > +	sensor->exposure = v4l2_ctrl_new_std(
> > +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> > +		V4L2_CID_EXPOSURE,
> > +		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN],
> > +		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN], 1,
> > +		sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN]);
> 
> Maybe a short comment explaining where this (and other controls below) will be
> updated would help future readers to figure out why maximum == minimum.

I initialise them to zero now and added a comment to explain it.

> > +
> > +	sensor->hflip = v4l2_ctrl_new_std(
> > +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> > +		V4L2_CID_HFLIP, 0, 1, 1, 0);
> > +	sensor->vflip = v4l2_ctrl_new_std(
> > +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> > +		V4L2_CID_VFLIP, 0, 1, 1, 0);
> > +
> > +	sensor->vblank = v4l2_ctrl_new_std(
> > +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> > +		V4L2_CID_VBLANK, 0, 1, 1, 0);
> > +
> > +	if (sensor->vblank)
> > +		sensor->vblank->flags |= V4L2_CTRL_FLAG_UPDATE;
> > +
> > +	sensor->hblank = v4l2_ctrl_new_std(
> > +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> > +		V4L2_CID_HBLANK, 0, 1, 1, 0);
> > +
> > +	if (sensor->hblank)
> > +		sensor->hblank->flags |= V4L2_CTRL_FLAG_UPDATE;
> > +
> > +	sensor->pixel_rate_parray = v4l2_ctrl_new_std(
> > +		&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
> > +		V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
> > +
> > +	if (sensor->pixel_array->ctrl_handler.error) {
> > +		dev_err(&client->dev,
> > +			"pixel array controls initialization failed (%d)\n",
> > +			sensor->pixel_array->ctrl_handler.error);
> 
> Shouldn't you call v4l2_ctrl_handler_free() here ?

Yes. Fixed.

> > +		return sensor->pixel_array->ctrl_handler.error;
> > +	}
> > +
> > +	sensor->pixel_array->sd.ctrl_handler =
> > +		&sensor->pixel_array->ctrl_handler;
> > +
> > +	v4l2_ctrl_cluster(2, &sensor->hflip);
> 
> Shouldn't you move this before the control handler check ?

Why? It can't fail.

> > +
> > +	rval = v4l2_ctrl_handler_init(&sensor->binner->ctrl_handler, 0);
> > +	if (rval)
> > +		return rval;
> 
> The pixel array control handler won't be freed if this fails. Same for the
> other error cases below.
> 
> > +	sensor->binner->ctrl_handler.lock = &sensor->mutex;
> 
> Just curious, what's the point in having an empty control handler ? Same
> question for the scaler. Is it because sensor->src will end up pointing to
> either the binner or scaler ? Maybe you could then just initialize
> sensor->src->ctrl_handler then.

Good idea. Fixed. I think I originally thought also binner would have
controls but currently there are none. There probably actually will be some,
but it's easy to change the code back when that's needed.

> > +
> > +	if (sensor->scaler) {
> > +		rval = v4l2_ctrl_handler_init(&sensor->scaler->ctrl_handler, 0);
> > +		if (rval)
> > +			return rval;
> > +		sensor->scaler->ctrl_handler.lock = &sensor->mutex;
> > +	}
> > +
> > +	memset(&cfg, 0, sizeof(cfg));
> > +
> > +	cfg.ops = &smiapp_ctrl_ops;
> > +	cfg.id = V4L2_CID_LINK_FREQ;
> > +	cfg.type = V4L2_CTRL_TYPE_INTEGER_MENU;
> > +	while (sensor->platform_data->op_sys_clock[cfg.max])
> > +		cfg.max++;
> > +	cfg.max--;
> 
> Maybe
> 
> 	while (sensor->platform_data->op_sys_clock[cfg.max+1])
> 		cfg.max++;
> 
> ? Not sure if the compiler will optimize that better though.

We don't care about compiler optimisations here; this is run once per sensor
registration. Nevertheless, it's probably better. There always must be at
least one possible setting for the link frequency.

> > +	cfg.qmenu_int = sensor->platform_data->op_sys_clock;
> > +
> > +	sensor->link_freq = v4l2_ctrl_new_custom(
> > +		&sensor->src->ctrl_handler, &cfg, NULL);
> > +
> > +	sensor->pixel_rate_csi = v4l2_ctrl_new_std(
> > +		&sensor->src->ctrl_handler, &smiapp_ctrl_ops,
> > +		V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
> > +
> > +	if (sensor->src->ctrl_handler.error) {
> > +		dev_err(&client->dev,
> > +			"src controls initialization failed (%d)\n",
> > +			sensor->src->ctrl_handler.error);
> > +		return sensor->src->ctrl_handler.error;
> > +	}
> > +
> > +	sensor->src->sd.ctrl_handler =
> > +		&sensor->src->ctrl_handler;
> > +
> > +	return 0;
> > +}
> > +
> > +static void smiapp_free_controls(struct smiapp_sensor *sensor)
> > +{
> > +	int i;
> 
> unsigned ?

Fixed.

> > +
> > +	for (i = 0; i < sensor->sds_used; i++)
> > +		v4l2_ctrl_handler_free(&sensor->sds[i].ctrl_handler);
> > +}
> > +
> > +static int smiapp_get_limits(struct smiapp_sensor *sensor, int const
> > *limit, +			     int n)
> 
> unsigned int n ?

Fixed.

> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	int i, val;
> 
> unsigned int i;
> u32 val;
> 
> ?

Fixed.

> > +	int rval;
> > +
> > +	for (i = 0; i < n; i++) {
> > +		rval = smia_i2c_read_reg(
> > +			client, smiapp_reg_limits[limit[i]].addr, &val);
> > +		if (rval) {
> > +			dev_dbg(&client->dev, "error reading register %4.4x\n",
> > +				(u16)smiapp_reg_limits[limit[i]].addr);
> 
> What about moving the error message to smia_i2c_read_reg ?

Interestingly there's already one. :-) Removed this one.

> > +			return rval;
> > +		}
> > +		sensor->limits[limit[i]] = val;
> > +		dev_dbg(&client->dev, "0x%8.8x \"%s\" = %d, 0x%x\n",
> > +			smiapp_reg_limits[limit[i]].addr,
> > +			smiapp_reg_limits[limit[i]].what, val, val);
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int smiapp_get_all_limits(struct smiapp_sensor *sensor)
> > +{
> > +	int rval, i;
> 
> unsigned int i; ?

Fixed.

> > +
> > +	for (i = 0; i < SMIAPP_LIMIT_LAST; i++) {
> > +		rval = smiapp_get_limits(sensor, &i, 1);
> > +		if (rval < 0)
> > +			return rval;
> > +	}
> > +
> > +	if (sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN] == 0)
> > +		smiapp_replace_limit(sensor, SMIAPP_LIMIT_SCALER_N_MIN, 16);
> > +
> > +	return 0;
> > +}
> > +
> > +static int smiapp_get_limits_binning(struct smiapp_sensor *sensor)
> > +{
> > +	static u32 const limits[] = {
> > +		SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN,
> > +		SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN,
> > +		SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN,
> > +		SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN,
> > +		SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN,
> > +		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN_BIN,
> > +		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN,
> > +	};
> > +	static u32 const limits_replace[] = {
> > +		SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES,
> > +		SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES,
> > +		SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK,
> > +		SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK,
> > +		SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK,
> > +		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN,
> > +		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN,
> > +	};
> > +
> > +	if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY] ==
> > +	    SMIAPP_BINNING_CAPABILITY_NO) {
> > +		int i;
> 
> unsigned int i; (and in the other functions below) ?

Ditto.

> > +
> > +		for (i = 0; i < ARRAY_SIZE(limits); i++)
> > +			sensor->limits[limits[i]] =
> > +				sensor->limits[limits_replace[i]];
> > +
> > +		return 0;
> > +	}
> > +
> > +	return smiapp_get_limits(sensor, limits, ARRAY_SIZE(limits));
> > +}
> > +
> > +static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	unsigned int type, n;
> > +	int i, rval, pixel_order;
> > +
> > +	rval = smia_i2c_read_reg(
> > +		client, SMIAPP_REG_U8_DATA_FORMAT_MODEL_TYPE, &type);
> > +	if (rval)
> > +		return rval;
> > +
> > +	dev_dbg(&client->dev, "data_format_model_type %d\n", type);
> > +
> > +	rval = smia_i2c_read_reg(client, SMIAPP_REG_U8_PIXEL_ORDER,
> > +				 &pixel_order);
> > +	if (rval)
> > +		return rval;
> > +
> > +	if (pixel_order >= ARRAY_SIZE(pixel_order_str)) {
> > +		dev_dbg(&client->dev, "bad pixel order %d\n", pixel_order);
> > +		return -EINVAL;
> > +	}
> > +
> > +	dev_dbg(&client->dev, "pixel order %d (%s)\n", pixel_order,
> > +		pixel_order_str[pixel_order]);
> > +
> > +	switch (type) {
> > +	case SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL:
> > +		n = SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL_N;
> > +		break;
> > +	case SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED:
> > +		n = SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED_N;
> > +		break;
> > +	default:
> > +		return -EINVAL;
> > +	}
> > +
> > +	sensor->default_pixel_order = pixel_order;
> > +	sensor->mbus_frame_fmts = 0;
> > +
> > +	for (i = 0; i < n; i++) {
> > +		int fmt, j;
> 
> j can be unsigned as well, this isn't restricted to i :-)

Hmm. I'll soon start using plain "unsigned". :-D

> > +
> > +		rval = smia_i2c_read_reg(
> > +			client,
> > +			SMIAPP_REG_U16_DATA_FORMAT_DESCRIPTOR(i), &fmt);
> > +		if (rval)
> > +			return rval;
> > +
> > +		dev_dbg(&client->dev, "bpp %d, compressed %d\n",
> > +			fmt >> 8, (u8)fmt);
> > +
> > +		for (j = 0; j < ARRAY_SIZE(smiapp_csi_data_formats); j++) {
> > +			const struct smiapp_csi_data_format *f =
> > +				&smiapp_csi_data_formats[j];
> > +
> > +			if (f->pixel_order != SMIAPP_PIXEL_ORDER_GRBG)
> > +				continue;
> > +
> > +			if (f->width != fmt >> 8 || f->compressed != (u8)fmt)
> > +				continue;
> > +
> > +			dev_dbg(&client->dev, "jolly good! %d\n", j);
> > +
> > +			sensor->default_mbus_frame_fmts |= 1 << j;
> > +			if (!sensor->csi_format) {
> > +				sensor->csi_format = f;
> > +				sensor->internal_csi_format = f;
> > +			}
> > +		}
> > +	}
> > +
> > +	if (!sensor->csi_format) {
> > +		dev_err(&client->dev, "no supported mbus code found\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	smiapp_update_mbus_formats(sensor);
> > +
> > +	return 0;
> > +}
> > +
> > +static void smiapp_update_blanking(struct smiapp_sensor *sensor)
> > +{
> > +	struct v4l2_ctrl *vblank = sensor->vblank, *hblank = sensor->hblank;
> 
> Two lines please.

Fixed.

> > +
> > +	vblank->minimum =
> > +		max_t(int,
> > +		      sensor->limits[SMIAPP_LIMIT_MIN_FRAME_BLANKING_LINES],
> > +		      sensor->limits[SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN] -
> > +		      sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height);
> > +	vblank->maximum =
> > +		sensor->limits[SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN] -
> > +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height;
> > +
> > +	vblank->val = clamp_t(int, vblank->val,
> > +			      vblank->minimum, vblank->maximum);
> > +	vblank->default_value = vblank->minimum;
> > +	vblank->val = vblank->val;
> > +	vblank->cur.val = vblank->val;
> > +
> > +	hblank->minimum =
> > +		max_t(int,
> > +		      sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN] -
> > +		      sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width,
> > +		      sensor->limits[SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN]);
> > +	hblank->maximum =
> > +		sensor->limits[SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN] -
> > +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width;
> > +
> > +	hblank->val = clamp_t(int, hblank->val,
> > +			      hblank->minimum, hblank->maximum);
> > +	hblank->default_value = hblank->minimum;
> > +	hblank->val = hblank->val;
> > +	hblank->cur.val = hblank->val;
> > +
> > +	__smiapp_update_exposure_limits(sensor);
> > +}
> > +
> > +static int smiapp_update_mode(struct smiapp_sensor *sensor)
> > +{
> 
> This function isn't protected by the sensor mutex when called from s_power,
> but it changes controls. The other call paths seem OK, but you might want to
> double-check them.

It's actually not an issue. When s_power is being called there are no other
users and the power_lock serialises it.

I implemented it this way since the control setup acquires the same lock
that I would have to hold while powering up. The power_lock fixes this
issue.

I cleaned this up so that I won't take sensor->mutex at all anymore.

> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	int binning_mode;
> > +	int rval;
> > +
> > +	dev_dbg(&client->dev, "frame size: %dx%d\n",
> > +		sensor->src->crop[SMIAPP_PAD_SOURCE].width,
> > +		sensor->src->crop[SMIAPP_PAD_SOURCE].height);
> > +	dev_dbg(&client->dev, "csi format width: %d\n",
> > +		sensor->csi_format->width);
> > +
> > +	/* Binning has to be set up here; it affects limits */
> > +	if (sensor->binning_horizontal == 1 &&
> > +	    sensor->binning_vertical == 1) {
> > +		binning_mode = 0;
> > +	} else {
> > +		u8 binning_type =
> > +			(sensor->binning_horizontal << 4)
> > +			| sensor->binning_vertical;
> > +
> > +		rval = smia_i2c_write_reg(
> > +			client, SMIAPP_REG_U8_BINNING_TYPE, binning_type);
> > +		if (rval < 0)
> > +			return rval;
> > +
> > +		binning_mode = 1;
> > +	}
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U8_BINNING_MODE, binning_mode);
> > +	if (rval < 0)
> > +		return rval;
> > +
> > +	/* Get updated limits due to binning */
> > +	rval = smiapp_get_limits_binning(sensor);
> > +	if (rval < 0)
> > +		return rval;
> > +
> > +	rval = smiapp_pll_update(sensor);
> > +	if (rval < 0)
> > +		return rval;
> > +
> > +	/* Output from pixel array, including blanking */
> > +	smiapp_update_blanking(sensor);
> > +
> > +	dev_dbg(&client->dev, "vblank\t\t%d\n", sensor->vblank->val);
> > +	dev_dbg(&client->dev, "hblank\t\t%d\n", sensor->hblank->val);
> > +
> > +	dev_dbg(&client->dev, "real timeperframe\t100/%d\n",
> > +		sensor->pll.vt_pix_clk_freq_hz /
> > +		((sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width
> > +		  + sensor->hblank->val) *
> > +		 (sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height
> > +		  + sensor->vblank->val) / 100));
> > +
> > +	return 0;
> > +}
> > +
> > +/*
> > + *
> > + * SMIA++ NVM handling
> > + *
> > + */
> > +static int smiapp_read_nvm(struct smiapp_sensor *sensor,
> > +			   unsigned char *nvm)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	u32 i, s, p, np, v;
> > +	int rval;
> > +
> > +	np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;
> 
> DIV_ROUND_UP() ? Or is sensor->nvm_size guaranteed to be a multiple of
> SMIAPP_NVM_PAGE_SIZE ?

I'd think so. I'm not sure if reading partial pages is supported either.

> > +	for (p = 0; p < np; p++) {
> > +		rval = smia_i2c_write_reg(
> > +			client,
> > +			SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT, p);
> > +		if (rval)
> > +			goto out;
> > +
> > +		rval = smia_i2c_write_reg(client,
> > +					  SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL,
> > +					  SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN |
> > +					  SMIAPP_DATA_TRANSFER_IF_1_CTRL_RD_EN);
> > +		if (rval)
> > +			goto out;
> > +
> > +		i = 1000;
> > +		do {
> > +			rval = smia_i2c_read_reg(client,
> > +				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s);
> > +
> > +			if (rval)
> > +				goto out;
> > +
> > +			if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
> > +				break;
> > +
> > +			if (--i == 0)
> > +				goto out;
> > +
> > +		} while (1);
> 
> I'd use a for loop on i. BTW, isn't 1000 a bit high ?

Changed to for loop. Well, I don't know what's the typical time one has to
wait but at least 1000 should be enough. I don't expect this to happen but
if it does it's a bad thing; even more than 1000 might make sense.

> > +
> > +		for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {
> > +			rval = smia_i2c_read_reg(client,
> > +				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0 + i,
> > +				&v);
> > +			if (rval)
> > +				goto out;
> > +
> > +			*nvm++ = v;
> > +		}
> > +	}
> > +
> > +out:
> > +	rval |= smia_i2c_write_reg(client,
> > +				   SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL, 0);
> 
> Could this be optimized away by the compiler, as the return value of this
> function is only checked against 0 ?

Could be. But the logical or makes no sense at all. Removed it.

> > +	return rval;
> > +}
> > +
> > +/*
> > + *
> > + * SMIA++ CCI address control
> > + *
> > + */
> > +static int smiapp_change_cci_addr(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	int rval;
> > +	u32 val;
> > +
> > +	client->addr = sensor->platform_data->i2c_addr_dfl;
> > +
> > +	rval = smia_i2c_write_reg(client,
> > +				  SMIAPP_REG_U8_CCI_ADDRESS_CONTROL,
> > +				  sensor->platform_data->i2c_addr_alt << 1);
> > +	if (rval) {
> > +		client->addr = sensor->platform_data->i2c_addr_alt;
> 
> Why do you set the client address to the alternate one if the call failed ?

I think it's called a "bug". :-P

> > +		return rval;
> > +	}
> > +
> > +	client->addr = sensor->platform_data->i2c_addr_alt;
> > +
> > +	/* verify addr change went ok */
> > +	rval = smia_i2c_read_reg(client,
> > +				 SMIAPP_REG_U8_CCI_ADDRESS_CONTROL, &val);
> > +	if (rval)
> > +		return rval;
> > +
> > +	if (val != sensor->platform_data->i2c_addr_alt << 1)
> > +		return -ENODEV;
> > +
> > +	return 0;
> > +}
> > +
> > +/*
> > + *
> > + * SMIA++ Mode Control
> > + *
> > + */
> > +static int smiapp_setup_flash_strobe(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	struct smiapp_flash_strobe_parms *strobe_setup;
> > +	unsigned int ext_freq = sensor->platform_data->ext_clk;
> > +	int rval;
> > +	u32 tmp;
> > +	u32 strobe_adjustment;
> > +	u32 strobe_width_high_rs;
> > +
> > +	strobe_setup = sensor->platform_data->strobe_setup;
> > +
> > +	/*
> > +	 * How to calculate registers related to strobe length. Please
> > +	 * do not change, or if you do at least know what you're
> > +	 * doing. :-)
> 
> You could reindent the text here up to 80 columns, that would shorten the
> comment a bit.

This is how my XEmacsitor indents it by default. And for good reason: it's
very readable that way --- filling the full 80 columns with text makes it
tougher to read.

> > +	 *
> > +	 * Sakari Ailus <sakari.ailus@maxwell.research.nokia.com> 2010-10-25
> > +	 *
> > +	 * flash_strobe_length [us] / 10^6 = (tFlash_strobe_width_ctrl
> > +	 *	/ EXTCLK freq [Hz]) * flash_strobe_adjustment
> > +	 *
> > +	 * tFlash_strobe_width_ctrl E N, [1 - 0xffff]
> > +	 * flash_strobe_adjustment E N, [1 - 0xff]
> > +	 *
> > +	 * The formula above is written as below to keep it on one
> > +	 * line:
> > +	 *
> > +	 * l / 10^6 = w / e * a
> > +	 *
> > +	 * Let's mark w * a by x:
> > +	 *
> > +	 * x = w * a
> > +	 *
> > +	 * Thus, we get:
> > +	 *
> > +	 * x = l * e / 10^6
> > +	 *
> > +	 * The strobe width must be at least as long as requested,
> > +	 * thus rounding upwards is needed.
> > +	 *
> > +	 * x = (l * e + 10^6 - 1) / 10^6
> > +	 * -----------------------------
> > +	 *
> > +	 * Maximum possible accuracy is wanted at all times. Thus keep
> > +	 * a as small as possible.
> > +	 *
> > +	 * Calculate a, assuming maximum w, with rounding upwards:
> > +	 *
> > +	 * a = (x + (2^16 - 1) - 1) / (2^16 - 1)
> > +	 * -------------------------------------
> > +	 *
> > +	 * Thus, we also get w, with that a, with rounding upwards:
> > +	 *
> > +	 * w = (x + a - 1) / a
> > +	 * -------------------
> > +	 *
> > +	 * To get limits:
> > +	 *
> > +	 * x E [1, (2^16 - 1) * (2^8 - 1)]
> > +	 *
> > +	 * Substituting maximum x to the original formula (with rounding),
> > +	 * the maximum l is thus
> > +	 *
> > +	 * (2^16 - 1) * (2^8 - 1) * 10^6 = l * e + 10^6 - 1
> > +	 *
> > +	 * l = (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / e
> > +	 * --------------------------------------------------
> > +	 *
> > +	 * flash_strobe_length must be clamped between 1 and
> > +	 * (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / EXTCLK freq.
> > +	 *
> > +	 * Then,
> > +	 *
> > +	 * flash_strobe_adjustment = ((flash_strobe_length *
> > +	 *	EXTCLK freq + 10^6 - 1) / 10^6 + (2^16 - 1) - 1) / (2^16 - 1)
> > +	 *
> > +	 * tFlash_strobe_width_ctrl = ((flash_strobe_length *
> > +	 *	EXTCLK freq + 10^6 - 1) / 10^6 +
> > +	 *	flash_strobe_adjustment - 1) / flash_strobe_adjustment
> > +	 */
> > +	tmp = div_u64(1000000ULL * ((1 << 16) - 1) * ((1 << 8) - 1) -
> > +		      1000000 + 1, ext_freq);
> > +	strobe_setup->strobe_width_high_us =
> > +		clamp_t(u32, strobe_setup->strobe_width_high_us, 1, tmp);
> > +
> > +	tmp = div_u64(((u64)strobe_setup->strobe_width_high_us * (u64)ext_freq +
> > +			1000000 - 1), 1000000ULL);
> > +	strobe_adjustment = (tmp + (1 << 16) - 1 - 1) / ((1 << 16) - 1);
> > +	strobe_width_high_rs = (tmp + strobe_adjustment - 1) /
> > +				strobe_adjustment;
> > +
> > +	rval = smia_i2c_write_reg(client,
> > +				  SMIAPP_REG_U8_FLASH_MODE_RS,
> > +				  strobe_setup->mode);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	rval = smia_i2c_write_reg(client,
> > +				  SMIAPP_REG_U8_FLASH_STROBE_ADJUSTMENT,
> > +				  strobe_adjustment);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_RS_CTRL,
> > +		strobe_width_high_rs);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	rval = smia_i2c_write_reg(client,
> > +				  SMIAPP_REG_U16_TFLASH_STROBE_DELAY_RS_CTRL,
> > +				  strobe_setup->strobe_delay);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	rval = smia_i2c_write_reg(client,
> > +				  SMIAPP_REG_U16_FLASH_STROBE_START_POINT,
> > +				  strobe_setup->stobe_start_point);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	rval = smia_i2c_write_reg(client,
> > +				  SMIAPP_REG_U8_FLASH_TRIGGER_RS,
> > +				  strobe_setup->trigger);
> > +
> > +out:
> > +	sensor->platform_data->strobe_setup->trigger = 0;
> > +
> > +	return rval;
> > +}
> > +
> > +/*
> > ---------------------------------------------------------------------------
> > -- + * Power management
> > + */
> > +
> > +static int smiapp_power_on(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	int sleep;
> > +	int rval;
> > +
> > +	rval = regulator_enable(sensor->vana);
> > +	if (rval) {
> > +		dev_err(&client->dev, "failed to enable vana regulator\n");
> > +		return rval;
> > +	}
> > +	usleep_range(1000, 1000);
> 
> That's a very tight range :-)

We're waiting for something that's got to do with user interaction. Thus no
extra delays should be added even if that generates more interrupts.

> > +
> > +	rval = sensor->platform_data->set_xclk(&sensor->src->sd,
> > +					sensor->platform_data->ext_clk);
> > +	if (rval < 0) {
> > +		dev_dbg(&client->dev, "failed to set xclk\n");
> > +		goto out_xclk_fail;
> > +	}
> > +	usleep_range(1000, 1000);
> > +
> > +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> > +		gpio_set_value(sensor->platform_data->xshutdown, 1);
> > +
> > +	sleep = SMIAPP_RESET_DELAY(sensor->platform_data->ext_clk);
> > +	usleep_range(sleep, sleep);
> > +
> > +	/*
> > +	 * Failures to respond to the address change command have been noticed.
> > +	 * Those failures seem to be caused by the sensor requiring a longer
> > +	 * boot time than advertised. An additional 10ms delay seems to work
> > +	 * around the issue, but the SMIA++ I2C write retry hack makes the delay
> > +	 * unnecessary. The failures need to be investigated to find a proper
> > +	 * fix, and a delay will likely need to be added here if the I2C write
> > +	 * retry hack is reverted before the root cause of the boot time issue
> > +	 * is found.
> > +	 */
> > +
> > +	if (sensor->platform_data->i2c_addr_alt) {
> > +		rval = smiapp_change_cci_addr(sensor);
> > +		if (rval) {
> > +			dev_err(&client->dev, "cci address change error\n");
> > +			goto out_cci_addr_fail;
> > +		}
> > +	}
> > +
> > +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_SOFTWARE_RESET,
> > +				  SMIAPP_SOFTWARE_RESET);
> > +	if (rval < 0) {
> > +		dev_err(&client->dev, "software reset failed\n");
> > +		goto out_cci_addr_fail;
> > +	}
> > +
> > +	if (sensor->platform_data->i2c_addr_alt) {
> > +		rval = smiapp_change_cci_addr(sensor);
> > +		if (rval) {
> > +			dev_err(&client->dev, "cci address change error\n");
> > +			goto out_cci_addr_fail;
> > +		}
> > +	}
> > +
> > +	rval = smia_i2c_write_reg(client,
> > +				  SMIAPP_REG_U16_COMPRESSION_MODE,
> > +				  SMIAPP_COMPRESSION_MODE_SIMPLE_PREDICTOR);
> > +	if (rval) {
> > +		dev_err(&client->dev, "compression mode set failed\n");
> > +		goto out_cci_addr_fail;
> > +	}
> > +
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U16_EXTCLK_FREQUENCY_MHZ,
> > +		sensor->platform_data->ext_clk / (1000000 / (1 << 8)));
> > +	if (rval) {
> > +		dev_err(&client->dev, "extclk frequency set failed\n");
> > +		goto out_cci_addr_fail;
> > +	}
> > +
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U8_CSI_LANE_MODE,
> > +		sensor->platform_data->lanes - 1);
> > +	if (rval) {
> > +		dev_err(&client->dev, "csi lane mode set failed\n");
> > +		goto out_cci_addr_fail;
> > +	}
> > +
> > +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_FAST_STANDBY_CTRL,
> > +				  SMIAPP_FAST_STANDBY_CTRL_IMMEDIATE);
> > +	if (rval) {
> > +		dev_err(&client->dev, "fast standby set failed\n");
> > +		goto out_cci_addr_fail;
> > +	}
> > +
> > +	/* DPHY control done by sensor based on requested link rate */
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U8_DPHY_CTRL, SMIAPP_DPHY_CTRL_UI);
> > +	if (rval < 0) {
> > +		dev_err(&client->dev, "set dphy_ctrl_ui failed\n");
> > +		goto out_cci_addr_fail;
> > +	}
> > +
> > +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_CSI_SIGNALLING_MODE,
> > +				  sensor->platform_data->csi_signalling_mode);
> > +	if (rval) {
> > +		dev_err(&client->dev, "csi signalling mode set failed\n");
> > +		goto out_cci_addr_fail;
> > +	}
> > +
> > +	/* DPHY control done by sensor based on requested link rate */
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U8_DPHY_CTRL, SMIAPP_DPHY_CTRL_UI);
> > +	if (rval < 0)
> > +		return rval;
> 
> Is there a need to the SMIAPP_REG_U8_DPHY_CTRL register twice to the same
> value ?

I think I intended to move the write, not copy the lines. Removed the first
one.

> > +
> > +	rval = smiapp_call_quirk(sensor, post_poweron);
> > +	if (rval) {
> > +		dev_err(&client->dev, "post_poweron quirks failed\n");
> > +		goto out_cci_addr_fail;
> > +	}
> > +
> > +	return 0;
> > +
> > +out_cci_addr_fail:
> > +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> > +		gpio_set_value(sensor->platform_data->xshutdown, 0);
> > +	sensor->platform_data->set_xclk(&sensor->src->sd, 0);
> > +
> > +out_xclk_fail:
> > +	regulator_disable(sensor->vana);
> > +	return rval;
> > +}
> > +
> > +static void smiapp_power_off(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +
> > +	/*
> > +	 * Currently power/clock to lens are enable/disabled separately
> > +	 * but they are essentially the same signals. So if the sensor is
> > +	 * powered off while the lens is powered on the sensor does not
> > +	 * really see a power off and next time the cci address change
> > +	 * will fail. So do a soft reset explicitly here.
> > +	 */
> > +	if (sensor->platform_data->i2c_addr_alt)
> > +		smia_i2c_write_reg(client,
> > +				   SMIAPP_REG_U8_SOFTWARE_RESET,
> > +				   SMIAPP_SOFTWARE_RESET);
> > +
> > +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> > +		gpio_set_value(sensor->platform_data->xshutdown, 0);
> > +	sensor->platform_data->set_xclk(&sensor->src->sd, 0);
> > +	usleep_range(5000, 5000);
> > +	regulator_disable(sensor->vana);
> > +	sensor->streaming = 0;
> > +}
> > +
> > +static int smiapp_set_power(struct v4l2_subdev *subdev, int on)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int ret;
> > +
> > +	/* If the power count is modified from 0 to != 0 or from != 0 to 0,
> > +	 * update the power state.
> > +	 */
> > +	if (sensor->power_count == !on) {
> > +		if (on) {
> > +			ret = smiapp_power_on(sensor);
> > +			if (ret < 0)
> > +				return ret;
> > +			ret = smiapp_update_mode(sensor);
> > +			if (ret < 0)
> > +				return ret;
> > +		} else {
> > +			smiapp_power_off(sensor);
> > +		}
> > +	}
> > +
> > +	/* Update the power count. */
> > +	sensor->power_count += on ? 1 : -1;
> > +	WARN_ON(sensor->power_count < 0);
> > +
> > +	return 0;
> > +}
> > +
> > +/*
> > ---------------------------------------------------------------------------
> > -- + * Video stream management
> > + */
> > +
> > +static int smiapp_start_streaming(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	int rval;
> > +
> > +	mutex_lock(&sensor->mutex);
> > +
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U16_CSI_DATA_FORMAT,
> > +		(sensor->csi_format->width << 8) |
> > +		sensor->csi_format->compressed);
> > +	if (rval)
> > +		goto out;
> > +
> > +	rval = smiapp_pll_configure(sensor);
> > +	if (rval)
> > +		goto out;
> > +
> > +	/* Analog crop start coordinates */
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U16_X_ADDR_START,
> > +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].left);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U16_Y_ADDR_START,
> > +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].top);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	/* Analog crop end coordinates */
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U16_X_ADDR_END,
> > +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].left
> > +		+ sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].width - 1);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U16_Y_ADDR_END,
> > +		sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].top
> > +		+ sensor->pixel_array->crop[SMIAPP_PAD_SOURCE].height - 1);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	/*
> > +	 * Output from pixel array, including blanking, is set using
> > +	 * controls below. No need to set here.
> > +	 */
> > +
> > +	/* Digital crop */
> > +	if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
> > +	    == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
> > +		rval = smia_i2c_write_reg(
> > +			client, SMIAPP_REG_U16_DIGITAL_CROP_X_OFFSET,
> > +			sensor->scaler->crop[SMIAPP_PAD_SINK].left);
> > +		if (rval < 0)
> > +			goto out;
> > +
> > +		rval = smia_i2c_write_reg(
> > +			client, SMIAPP_REG_U16_DIGITAL_CROP_Y_OFFSET,
> > +			sensor->scaler->crop[SMIAPP_PAD_SINK].top);
> > +		if (rval < 0)
> > +			goto out;
> > +
> > +		rval = smia_i2c_write_reg(
> > +			client, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_WIDTH,
> > +			sensor->scaler->crop[SMIAPP_PAD_SINK].width);
> > +		if (rval < 0)
> > +			goto out;
> > +
> > +		rval = smia_i2c_write_reg(
> > +			client, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_HEIGHT,
> > +			sensor->scaler->crop[SMIAPP_PAD_SINK].height);
> > +		if (rval < 0)
> > +			goto out;
> > +	}
> > +
> > +	/* Scaling */
> > +	if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> > +	    != SMIAPP_SCALING_CAPABILITY_NONE) {
> > +		rval = smia_i2c_write_reg(
> > +			client, SMIAPP_REG_U16_SCALING_MODE,
> > +			sensor->scaling_mode);
> > +		if (rval < 0)
> > +			goto out;
> > +
> > +		if (sensor->scale_m
> > +		    != sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]) {
> > +			rval = smia_i2c_write_reg(
> > +				client, SMIAPP_REG_U16_SCALE_M,
> > +				sensor->scale_m);
> > +			if (rval < 0)
> > +				goto out;
> > +		}
> 
> I could be wrong, but it seems to me like the scaling M factor won't be 
> updated
> properly if you first enable/disable streaming with a non-default M factor,
> reconfigure the sensor to use the default value, and then start streaming
> again.

Excellent point. Fixed.

> > +	}
> > +
> > +	/* Output size from sensor */
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U16_X_OUTPUT_SIZE,
> > +		sensor->src->crop[SMIAPP_PAD_SOURCE].width);
> > +	if (rval < 0)
> > +		goto out;
> > +	rval = smia_i2c_write_reg(
> > +		client, SMIAPP_REG_U16_Y_OUTPUT_SIZE,
> > +		sensor->src->crop[SMIAPP_PAD_SOURCE].height);
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	if ((sensor->flash_capability &
> > +	     (SMIAPP_FLASH_MODE_CAPABILITY_SINGLE_STROBE |
> > +	      SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE)) &&
> > +	    sensor->platform_data->strobe_setup != NULL &&
> > +	    sensor->platform_data->strobe_setup->trigger != 0) {
> > +		rval = smiapp_setup_flash_strobe(sensor);
> > +		if (rval)
> > +			goto out;
> > +	}
> > +
> > +	rval = smiapp_call_quirk(sensor, pre_streamon);
> > +	if (rval) {
> > +		dev_err(&client->dev, "pre_streamon quirks failed\n");
> > +		goto out;
> > +	}
> > +
> > +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_MODE_SELECT,
> > +				  SMIAPP_MODE_SELECT_STREAMING);
> > +
> > +out:
> > +	mutex_unlock(&sensor->mutex);
> > +
> > +	return rval;
> > +}
> > +
> > +static int smiapp_stop_streaming(struct smiapp_sensor *sensor)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
> > +	int rval;
> > +
> > +	mutex_lock(&sensor->mutex);
> > +	rval = smia_i2c_write_reg(client, SMIAPP_REG_U8_MODE_SELECT,
> > +		SMIAPP_MODE_SELECT_SOFTWARE_STANDBY);
> > +	if (rval)
> > +		goto out;
> > +
> > +	rval = smiapp_call_quirk(sensor, post_streamoff);
> > +	if (rval)
> > +		dev_err(&client->dev, "post_streamoff quirks failed\n");
> > +
> > +out:
> > +	mutex_unlock(&sensor->mutex);
> > +	return rval;
> > +}
> > +
> > +/*
> > ---------------------------------------------------------------------------
> > -- + * V4L2 subdev video operations
> > + */
> > +
> > +static int smiapp_set_stream(struct v4l2_subdev *subdev, int enable)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int rval;
> > +
> > +	if (sensor->streaming == enable)
> > +		return 0;
> > +
> > +	if (enable) {
> > +		sensor->streaming = 1;
> > +		rval = smiapp_start_streaming(sensor);
> > +		if (rval < 0)
> > +			sensor->streaming = 0;
> 
> Is there a reason not to just set sensor->streaming after calling
> smiapp_start_streaming() ?

Yes. There are controls which return -EBUSY in those cases.

Ideally I guess I should grab them, but I'd like to make grabbing counted
instead of being boolean. I think I'll prepare additional patches for this
later on.

> > +	} else {
> > +		rval = smiapp_stop_streaming(sensor);
> > +		sensor->streaming = 0;
> > +	}
> > +
> > +	return rval;
> > +}
> > +
> > +static int smiapp_enum_mbus_code(struct v4l2_subdev *subdev,
> > +				 struct v4l2_subdev_fh *fh,
> > +				 struct v4l2_subdev_mbus_code_enum *code)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int i, idx = -1;
> > +	int rval = -EINVAL;
> > +
> > +	mutex_lock(&sensor->mutex);
> > +
> > +	dev_err(&client->dev, "subdev %s, pad %d, index %d\n",
> > +		subdev->name, code->pad, code->index);
> > +
> > +	if (subdev != &sensor->src->sd
> > +	    || code->pad != SMIAPP_PAD_SOURCE) {
> > +		if (code->index)
> > +			goto out;
> > +
> > +		code->code = sensor->internal_csi_format->code;
> > +		rval = 0;
> > +		goto out;
> > +	}
> > +
> > +	for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
> > +		if (sensor->mbus_frame_fmts & (1 << i))
> > +			idx++;
> > +
> > +		if (idx == code->index) {
> > +			code->code = smiapp_csi_data_formats[i].code;
> > +			dev_err(&client->dev, "found index %d, i %d, code %x\n",
> > +				code->index, i, code->code);
> > +			rval = 0;
> > +			goto out;
> 
> break; would do :-)

Fixed.

> > +		}
> > +	}
> > +
> > +out:
> > +	mutex_unlock(&sensor->mutex);
> > +
> > +	return rval;
> > +}
> > +
> > +static int __smiapp_get_format(struct v4l2_subdev *subdev,
> > +			     struct v4l2_subdev_fh *fh,
> > +			     struct v4l2_subdev_format *fmt)
> > +{
> > +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +
> > +	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> > +		fmt->format = *v4l2_subdev_get_try_format(fh, fmt->pad);
> > +	} else {
> > +		struct v4l2_rect *r;
> > +
> > +		if (fmt->pad == SMIAPP_PAD_SOURCE)
> > +			r = &ssd->crop[SMIAPP_PAD_SOURCE];
> > +		else
> > +			r = &ssd->sink_fmt;
> > +
> > +		fmt->format.width = r->width;
> > +		fmt->format.height = r->height;
> > +		if (subdev == &sensor->src->sd
> > +		    && fmt->pad == SMIAPP_PAD_SOURCE)
> > +			fmt->format.code = sensor->csi_format->code;
> > +		else
> > +			fmt->format.code = sensor->internal_csi_format->code;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int smiapp_get_format(struct v4l2_subdev *subdev,
> > +			     struct v4l2_subdev_fh *fh,
> > +			     struct v4l2_subdev_format *fmt)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int rval;
> > +
> > +	mutex_lock(&sensor->mutex);
> > +	rval = __smiapp_get_format(subdev, fh, fmt);
> > +	mutex_unlock(&sensor->mutex);
> > +
> > +	return rval;
> > +}
> > +
> > +static void smiapp_get_crop_compose(struct v4l2_subdev *subdev,
> > +				    struct v4l2_subdev_fh *fh,
> > +				    struct v4l2_rect **crops,
> > +				    struct v4l2_rect **comps, int which)
> > +{
> > +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> > +	int i;
> > +
> > +	if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> > +		for (i = 0; i < subdev->entity.num_pads; i++)
> > +			if (crops)
> > +				crops[i] = &ssd->crop[i];
> 
> You could move the if outside the for.

Good point. The code wasn't originally written like that. :-)

> > +		if (comps)
> > +			*comps = &ssd->compose;
> > +	} else {
> > +		for (i = 0; i < subdev->entity.num_pads; i++)
> > +			if (crops) {
> > +				crops[i] = v4l2_subdev_get_try_crop(fh, i);
> > +				BUG_ON(!crops[i]);
> > +			}
> 
> Same here.

Ditto.

> > +		if (comps) {
> > +			*comps = v4l2_subdev_get_try_compose(fh,
> > +							     SMIAPP_PAD_SINK);
> > +			BUG_ON(!*comps);
> > +		}
> > +	}
> > +}
> > +
> > +/* Changes require propagation only on sink pad. */
> > +static void smiapp_propagate(struct v4l2_subdev *subdev,
> > +			     struct v4l2_subdev_fh *fh, int which,
> > +			     int target)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> > +	struct v4l2_rect *comp, *crops[SMIAPP_PADS];
> > +
> > +	smiapp_get_crop_compose(subdev, fh, crops, &comp, which);
> > +
> > +	switch (target) {
> > +	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
> > +		comp->width = crops[SMIAPP_PAD_SINK]->width;
> > +		comp->height = crops[SMIAPP_PAD_SINK]->height;
> > +		if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> > +			if (ssd == sensor->scaler) {
> > +				sensor->scale_m =
> > +					sensor->limits[
> > +						SMIAPP_LIMIT_SCALER_N_MIN];
> > +				sensor->scaling_mode =
> > +					SMIAPP_SCALING_MODE_NONE;
> > +			} else if (ssd == sensor->binner) {
> > +				sensor->binning_horizontal = 1;
> > +				sensor->binning_vertical = 1;
> > +			}
> > +		}
> > +		/* Fall through */
> > +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
> > +		*crops[SMIAPP_PAD_SOURCE] = *comp;
> > +		break;
> > +	default:
> > +		BUG();
> > +	}
> > +}
> > +
> > +static int smiapp_set_format(struct v4l2_subdev *subdev,
> > +			     struct v4l2_subdev_fh *fh,
> > +			     struct v4l2_subdev_format *fmt)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> > +	struct v4l2_rect *crops[SMIAPP_PADS];
> > +	int i = 0;
> 
> There's no need to initialize i to 0.

Ack.

> > +
> > +	mutex_lock(&sensor->mutex);
> > +
> > +	smiapp_get_crop_compose(subdev, fh, crops, NULL, fmt->which);
> > +
> > +	if (subdev == &sensor->src->sd && fmt->pad == SMIAPP_PAD_SOURCE) {
> > +		for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
> > +			if (sensor->mbus_frame_fmts & (1 << i) &&
> > +			    smiapp_csi_data_formats[i].code
> > +			    == fmt->format.code) {
> > +				if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> > +					sensor->csi_format =
> > +						&smiapp_csi_data_formats[i];
> > +				break;
> > +			}
> > +		}
> > +	}
> > +
> > +	if (fmt->pad == SMIAPP_PAD_SOURCE) {
> > +		int rval;
> > +
> > +		rval = __smiapp_get_format(subdev, fh, fmt);
> > +
> > +		mutex_unlock(&sensor->mutex);
> > +		return rval;
> > +	}
> > +
> > +	fmt->format.code = sensor->csi_format->code;
> 
> sensor->csi_format is the active format. You seem to always return the active
> format code. That will break setting the try format.

Fixed.

> > +
> > +	fmt->format.width &= ~1;
> > +	fmt->format.height &= ~1;
> > +
> > +	if (fmt->format.width < sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE])
> > +		fmt->format.width =
> > +			sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE];
> > +	if (fmt->format.height
> > +	    < sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE])
> > +		fmt->format.height =
> > +			sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE];
> 
> Isn't there a maximum size as well ?

Hmm. I think there's something missing from here. :-)

> > +
> > +	crops[SMIAPP_PAD_SINK]->left = crops[SMIAPP_PAD_SINK]->top = 0;
> 
> One assignment per line please.

Ok...

> > +	crops[SMIAPP_PAD_SINK]->width = fmt->format.width;
> > +	crops[SMIAPP_PAD_SINK]->height = fmt->format.height;
> > +	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> > +		ssd->sink_fmt = *crops[SMIAPP_PAD_SINK];
> > +	smiapp_propagate(subdev, fh, fmt->which,
> > +			 V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE);
> > +
> > +	mutex_unlock(&sensor->mutex);
> > +
> > +	return 0;
> > +}
> > +
> > +#define SCALING_GOODNESS		100000
> > +#define SCALING_GOODNESS_EXTREME	100000000
> > +static int scaling_goodness(struct v4l2_subdev *subdev, int w, int ask_w,
> > +			    int h, int ask_h, u32 flags)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> > +	int val = 0;
> > +
> > +	w &= ~1;
> > +	ask_w &= ~1;
> > +	h &= ~1;
> > +	ask_h &= ~1;
> > +
> > +	if (flags & V4L2_SUBDEV_SEL_FLAG_SIZE_GE) {
> > +		if (w < ask_w)
> > +			val -= SCALING_GOODNESS;
> > +		if (h < ask_h)
> > +			val -= SCALING_GOODNESS;
> > +	}
> > +
> > +	if (flags & V4L2_SUBDEV_SEL_FLAG_SIZE_LE) {
> > +		if (w > ask_w)
> > +			val -= SCALING_GOODNESS;
> > +		if (h > ask_h)
> > +			val -= SCALING_GOODNESS;
> > +	}
> > +
> > +	val -= abs(w - ask_w);
> > +	val -= abs(h - ask_h);
> > +
> > +	if (w < sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE])
> > +		val -= SCALING_GOODNESS_EXTREME;
> > +
> > +	dev_dbg(&client->dev, "w %d ask_w %d h %d ask_h %d goodness %d\n",
> > +		w, ask_h, h, ask_h, val);
> > +
> > +	return val;
> > +}
> > +
> > +/* We're only called on source pads. This function sets scaling. */
> > +static int smiapp_set_compose(struct v4l2_subdev *subdev,
> > +			      struct v4l2_subdev_fh *fh,
> > +			      struct v4l2_subdev_selection *sel)
> > +{
> > +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> > +	struct v4l2_rect *comp, *crops[SMIAPP_PADS];
> > +
> > +	smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
> > +
> > +	sel->r.top = 0;
> > +	sel->r.left = 0;
> > +
> > +	if (ssd == sensor->binner) {
> 
> Wouldn't per-subdev operation handlers be more readable ?

Separated the two.

> > +		int i;
> > +		int binh = 1, binv = 1;
> > +		int best = scaling_goodness(
> > +			subdev,
> > +			crops[SMIAPP_PAD_SINK]->width,
> > +			sel->r.width,
> > +			crops[SMIAPP_PAD_SINK]->height,
> > +			sel->r.height, sel->flags);
> > +
> > +		for (i = 0; i < sensor->nbinning_subtypes; i++) {
> > +			int this = scaling_goodness(
> > +				subdev,
> > +				crops[SMIAPP_PAD_SINK]->width
> > +				/ sensor->binning_subtypes[i].horizontal,
> > +				sel->r.width,
> > +				crops[SMIAPP_PAD_SINK]->height
> > +				/ sensor->binning_subtypes[i].vertical,
> > +				sel->r.height, sel->flags);
> > +
> > +			if (this > best) {
> > +				binh = sensor->binning_subtypes[i].horizontal;
> > +				binv = sensor->binning_subtypes[i].vertical;
> > +				best = this;
> > +
> > +				if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> > +					sensor->binning_vertical = binv;
> > +					sensor->binning_horizontal = binh;
> > +				}
> 
> If the initial best value turns out the be the best one, binning_vertical and
> binning_horizontal will never be updated. Moving the if() outside the for loop
> would solve this.

Good catch. Fixed.

> > +			}
> > +		}
> > +
> > +		sel->r.width =
> > +			(crops[SMIAPP_PAD_SINK]->width / binh) & ~1;
> > +		sel->r.height =
> > +			(crops[SMIAPP_PAD_SINK]->height / binv) & ~1;
> > +
> > +	} else {
> > +		u32 min, max, a, b, max_m;
> > +		u32 scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
> > +		int mode = SMIAPP_SCALING_MODE_HORIZONTAL;
> > +		u32 try[4];
> > +		u32 ntry = 0;
> > +		int i;
> > +		int best = INT_MIN;
> > +
> > +		sel->r.width = min_t(unsigned int, sel->r.width,
> > +				     crops[SMIAPP_PAD_SINK]->width);
> > +		sel->r.height = min_t(unsigned int, sel->r.height,
> > +				      crops[SMIAPP_PAD_SINK]->height);
> > +
> > +		a = crops[SMIAPP_PAD_SINK]->width
> > +			* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
> > +			/ sel->r.width;
> > +		b = crops[SMIAPP_PAD_SINK]->height
> > +			* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
> > +			/ sel->r.height;
> > +		max_m = crops[SMIAPP_PAD_SINK]->width
> > +			* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
> > +			/ sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE];
> > +
> > +		a = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
> > +			max(a, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
> > +		b = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
> > +			max(b, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
> > +		max_m = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
> > +			    max(max_m,
> > +				sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
> > +
> > +		dev_dbg(&client->dev, "scaling: a %d b %d max_m %d\n",
> > +			a, b, max_m);
> > +
> > +		min = min(max_m, min(a, b));
> > +		max = min(max_m, max(a, b));
> > +
> > +		try[ntry] = min;
> > +		ntry++;
> > +		if (min != max) {
> > +			try[ntry] = max;
> > +			ntry++;
> > +		}
> > +		if (max != max_m) {
> > +			try[ntry] = min + 1;
> > +			ntry++;
> > +			if (min != max) {
> > +				try[ntry] = max + 1;
> > +				ntry++;
> > +			}
> > +		}
> 
> Please add a comment to explain how you compute the scaling values, the code
> isn't self-explicit.

Added.

> > +
> > +		for (i = 0; i < ntry; i++) {
> > +			int this = scaling_goodness(
> > +				subdev,
> > +				crops[SMIAPP_PAD_SINK]->width
> > +				/ try[i]
> > +				* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
> > +				sel->r.width,
> > +				crops[SMIAPP_PAD_SINK]->height,
> > +				sel->r.height,
> > +				sel->flags);
> > +
> > +			dev_dbg(&client->dev, "trying factor %d (%d)\n",
> > +				try[i], i);
> > +
> > +			if (this > best) {
> > +				scale_m = try[i];
> > +				mode = SMIAPP_SCALING_MODE_HORIZONTAL;
> > +				best = this;
> > +			}
> > +
> > +			if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> > +			    == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
> > +				continue;
> > +
> > +			this = scaling_goodness(
> > +				subdev, crops[SMIAPP_PAD_SINK]->width
> > +				/ try[i]
> > +				* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
> > +				sel->r.width,
> > +				crops[SMIAPP_PAD_SINK]->height
> > +				/ try[i]
> > +				* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
> > +				sel->r.height,
> > +				sel->flags);
> > +
> > +			if (this > best) {
> > +				scale_m = try[i];
> > +				mode = SMIAPP_SCALING_MODE_BOTH;
> > +				best = this;
> > +			}
> > +		}
> > +
> > +		sel->r.width =
> > +			(crops[SMIAPP_PAD_SINK]->width
> > +			 / scale_m
> > +			 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]) & ~1;
> > +		if (mode == SMIAPP_SCALING_MODE_BOTH)
> > +			sel->r.height =
> > +				(crops[SMIAPP_PAD_SINK]->height
> > +				 / scale_m
> > +				 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN])
> > +				& ~1;
> > +		else
> > +			sel->r.height = crops[SMIAPP_PAD_SINK]->height;
> > +
> > +		if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> > +			sensor->scale_m = scale_m;
> > +			sensor->scaling_mode = mode;
> > +		}
> > +	}
> > +
> > +	*comp = sel->r;
> > +	smiapp_propagate(subdev, fh, sel->which,
> > +			 V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE);
> > +
> > +	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> > +		return smiapp_update_mode(sensor);
> > +
> > +	return 0;
> > +}
> > +
> > +static int __smiapp_sel_supported(struct v4l2_subdev *subdev,
> > +				  struct v4l2_subdev_selection *sel)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> > +
> > +	/* We only implement crop in three places. */
> > +	switch (sel->target) {
> > +	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
> > +	case V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS:
> > +		if (ssd == sensor->pixel_array
> > +		    && sel->pad == SMIAPP_PAD_SOURCE)
> > +			return 0;
> > +		if (ssd == sensor->src
> > +		    && sel->pad == SMIAPP_PAD_SOURCE)
> > +			return 0;
> > +		if (ssd == sensor->scaler
> > +		    && sel->pad == SMIAPP_PAD_SINK
> > +		    && sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
> > +		    == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP)
> > +			return 0;
> > +		return -EINVAL;
> > +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
> > +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS:
> > +		if (sel->pad != SMIAPP_PAD_SINK)
> > +			return -EINVAL;
> > +		if (ssd == sensor->binner)
> > +			return 0;
> > +		if (ssd == sensor->scaler
> > +		    && sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> > +		    != SMIAPP_SCALING_CAPABILITY_NONE)
> > +			return 0;
> > +		/* Fall through */
> > +	default:
> > +		return -EINVAL;
> > +	}
> 
> What about returning 1 if the selection target is supported, and 0 if it isn't
> ?

Well, this way I can easily return a reasonable error code --- should it be
changed, it's just a single place in the driver. :-)

> > +}
> > +
> > +static int smiapp_set_crop(struct v4l2_subdev *subdev,
> > +			   struct v4l2_subdev_fh *fh,
> > +			   struct v4l2_subdev_selection *sel)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> > +	struct v4l2_rect *src_size, *crops[SMIAPP_PADS];
> > +	struct v4l2_rect _r;
> > +
> > +	smiapp_get_crop_compose(subdev, fh, crops, NULL, sel->which);
> > +
> > +	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> > +		if (sel->pad == SMIAPP_PAD_SINK)
> > +			src_size = &ssd->sink_fmt;
> > +		else
> > +			src_size = &ssd->compose;
> > +	} else {
> > +		if (sel->pad == SMIAPP_PAD_SINK) {
> > +			_r.left = _r.top = 0;
> 
> One assignment per line please.

Fixed.

> > +			_r.width = v4l2_subdev_get_try_format(fh, sel->pad)
> > +				->width;
> > +			_r.height = v4l2_subdev_get_try_format(fh, sel->pad)
> > +				->height;
> > +			src_size = &_r;
> > +		} else {
> > +			src_size =
> > +				v4l2_subdev_get_try_compose(fh,
> > +							    SMIAPP_PAD_SINK);
> 
> Why do you get the try compose rectangle when setting the crop rectangle ?

This is source pad, so the source crop is directly related to sink compose.

> > +		}
> > +	}
> 
> This looks a bit too complex to me (but it's just a feeling).
> 
> > +
> > +	if (ssd == sensor->src && sel->pad == SMIAPP_PAD_SOURCE)
> > +		sel->r.left = 0, sel->r.top = 0;
> 
> Please...

I think assigning a static value to multiple variables at the same time
should be allowed. I'm sure Kernighan and Ritchie didn't put it there just
to annoy people. :-)

I changed it nevertheless since you're asking so kindly. ;-)

> > +
> > +	if (sel->r.width > src_size->width)
> > +		sel->r.width = src_size->width;
> > +	if (sel->r.height > src_size->height)
> > +		sel->r.height = src_size->height;
> > +
> > +	if (sel->r.left + sel->r.width > src_size->width)
> > +		sel->r.left =
> > +			src_size->width - sel->r.width;
> > +	if (sel->r.top + sel->r.height > src_size->height)
> > +		sel->r.top =
> > +			src_size->height - sel->r.height;
> > +
> > +	*crops[sel->pad] = sel->r;
> > +
> > +	if (sel->pad == SMIAPP_PAD_SINK)
> > +		smiapp_propagate(subdev, fh, sel->which,
> > +				 V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE);
> > +
> > +	return 0;
> > +}
> > +
> > +static int __smiapp_get_selection(struct v4l2_subdev *subdev,
> > +				  struct v4l2_subdev_fh *fh,
> > +				  struct v4l2_subdev_selection *sel)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
> > +	struct v4l2_rect *comp, *crops[SMIAPP_PADS];
> > +	struct v4l2_rect sink_fmt;
> > +	int ret;
> > +
> > +	ret = __smiapp_sel_supported(subdev, sel);
> > +	if (ret)
> > +		return ret;
> > +
> > +	smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
> > +
> > +	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> > +		sink_fmt = ssd->sink_fmt;
> > +	} else if (ssd != sensor->pixel_array) {
> > +		struct v4l2_mbus_framefmt *fmt =
> > +			v4l2_subdev_get_try_format(fh, SMIAPP_PAD_SINK);
> > +
> > +		sink_fmt.left = sink_fmt.top = 0;
> > +		sink_fmt.width = fmt->width;
> > +		sink_fmt.height = fmt->height;
> > +	} else {
> > +		BUG();
> 
> So you support active selections on the pixel array subdev, but not try
> selections ?

Removed the pixel array check. The BUG()'s now in
v4l2_subdev_get_try_format(). The real check's in __smiapp_sel_supported()
above.

> > +	}
> > +
> > +	switch (sel->target) {
> > +	case V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS:
> > +		if (ssd == sensor->pixel_array) {
> > +			sel->r.width =
> > +				sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
> > +			sel->r.height =
> > +				sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
> > +		} else if (sel->pad == SMIAPP_PAD_SINK) {
> > +			sel->r = sink_fmt;
> > +		} else {
> > +			sel->r = *comp;
> > +		}
> > +		break;
> > +	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
> > +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS:
> > +		sel->r = *crops[sel->pad];
> > +		break;
> > +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
> > +		sel->r = *comp;
> > +		break;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int smiapp_get_selection(struct v4l2_subdev *subdev,
> > +				struct v4l2_subdev_fh *fh,
> > +				struct v4l2_subdev_selection *sel)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int rval;
> > +
> > +	mutex_lock(&sensor->mutex);
> > +	rval = __smiapp_get_selection(subdev, fh, sel);
> > +	mutex_unlock(&sensor->mutex);
> > +
> > +	return rval;
> > +}
> > +static int smiapp_set_selection(struct v4l2_subdev *subdev,
> > +				struct v4l2_subdev_fh *fh,
> > +				struct v4l2_subdev_selection *sel)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int ret;
> > +
> > +	ret = __smiapp_sel_supported(subdev, sel);
> > +	if (ret)
> > +		return ret;
> > +
> > +	mutex_lock(&sensor->mutex);
> > +
> > +	sel->r.left = max(0, sel->r.left & ~1);
> > +	sel->r.top = max(0, sel->r.top & ~1);
> > +	sel->r.width = max(0, SMIAPP_ALIGN_DIM(sel->r.width, sel->flags));
> > +	sel->r.height = max(0, SMIAPP_ALIGN_DIM(sel->r.height, sel->flags));
> > +
> > +	sel->r.width = max_t(unsigned int,
> > +			     sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE],
> > +			     sel->r.width);
> > +	sel->r.height = max_t(unsigned int,
> > +			      sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE],
> > +			      sel->r.height);
> > +
> > +	switch (sel->target) {
> > +	case V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE:
> > +		ret = smiapp_set_crop(subdev, fh, sel);
> > +		break;
> > +	case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE:
> > +		ret = smiapp_set_compose(subdev, fh, sel);
> > +		break;
> > +	default:
> > +		BUG();
> > +	}
> > +
> > +	mutex_unlock(&sensor->mutex);
> > +	return ret;
> > +}
> > +
> > +static int smiapp_get_skip_frames(struct v4l2_subdev *subdev, u32 *frames)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +
> > +	*frames = sensor->frame_skip;
> > +	return 0;
> > +}
> > +
> > +/*
> > ---------------------------------------------------------------------------
> > -- + * sysfs attributes
> > + */
> > +
> > +static ssize_t
> > +smiapp_sysfs_nvm_read(struct device *dev, struct device_attribute *attr,
> > +		      char *buf)
> > +{
> > +	struct v4l2_subdev *subdev = i2c_get_clientdata(to_i2c_client(dev));
> > +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int nbytes;
> > +
> > +	if (!sensor->dev_init_done)
> > +		return -EBUSY;
> > +
> > +	if (!sensor->nvm_size) {
> > +		/* NVM not read yet - read it now */
> > +		sensor->nvm_size = sensor->platform_data->nvm_size;
> > +		if (smiapp_set_power(subdev, 1) < 0)
> > +			return -ENODEV;
> > +		if (smiapp_read_nvm(sensor, sensor->nvm)) {
> > +			dev_err(&client->dev, "nvm read failed\n");
> > +			return -ENODEV;
> > +		}
> > +		smiapp_set_power(subdev, 0);
> > +	}
> > +	/*
> > +	 * NVM is still way below a PAGE_SIZE, so we can safely
> > +	 * assume this for now.
> > +	 */
> > +	nbytes = min_t(unsigned int, sensor->nvm_size, PAGE_SIZE);
> > +	memcpy(buf, sensor->nvm, nbytes);
> > +
> > +	return nbytes;
> > +}
> > +static DEVICE_ATTR(nvm, S_IRUGO, smiapp_sysfs_nvm_read, NULL);
> > +
> > +/*
> > ---------------------------------------------------------------------------
> > -- + * V4L2 subdev core operations
> > + */
> > +
> > +static int smiapp_identify_module(struct v4l2_subdev *subdev)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> > +	int i, rval = 0;
> > +	struct smiapp_module_info *minfo = &sensor->minfo;
> > +
> > +	minfo->name = SMIAPP_NAME;
> > +
> > +	/* Module info */
> > +	rval = smia_i2c_read_reg(client,
> > +				 SMIAPP_REG_U8_MANUFACTURER_ID,
> > +				 &minfo->manufacturer_id);
> > +	if (!rval)
> > +		rval = smia_i2c_read_reg(client,
> > +					 SMIAPP_REG_U16_MODEL_ID,
> > +					 &minfo->model_id);
> > +	if (!rval)
> > +		rval |= smia_i2c_read_reg(client,
> > +					  SMIAPP_REG_U8_REVISION_NUMBER_MAJOR,
> > +					  &minfo->revision_number_major);
> 
> s/|=/=/

Fixed.

> > +	if (!rval)
> > +		rval |= smia_i2c_read_reg(client,
> > +					  SMIAPP_REG_U8_REVISION_NUMBER_MINOR,
> > +					  &minfo->revision_number_minor);
> > +	if (!rval)
> > +		rval |= smia_i2c_read_reg(client,
> > +					  SMIAPP_REG_U8_MODULE_DATE_YEAR,
> > +					  &minfo->module_year);
> > +	if (!rval)
> > +		rval |= smia_i2c_read_reg(client,
> > +					  SMIAPP_REG_U8_MODULE_DATE_MONTH,
> > +					  &minfo->module_month);
> > +	if (!rval)
> > +		rval |= smia_i2c_read_reg(client,
> > +					  SMIAPP_REG_U8_MODULE_DATE_DAY,
> > +					  &minfo->module_day);
> > +
> > +	/* Sensor info */
> > +	if (!rval)
> > +		rval |= smia_i2c_read_reg(client,
> > +					  SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID,
> > +					  &minfo->sensor_manufacturer_id);
> > +	if (!rval)
> > +		rval |= smia_i2c_read_reg(client,
> > +					  SMIAPP_REG_U16_SENSOR_MODEL_ID,
> > +					  &minfo->sensor_model_id);
> > +	if (!rval)
> > +		rval = smia_i2c_read_reg(client,
> > +					 SMIAPP_REG_U8_SENSOR_REVISION_NUMBER,
> > +					 &minfo->sensor_revision_number);
> > +	if (!rval)
> > +		rval = smia_i2c_read_reg(client,
> > +					 SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION,
> > +					 &minfo->sensor_firmware_version);
> > +
> > +	/* SMIA */
> > +	if (!rval)
> > +		rval = smia_i2c_read_reg(client,
> > +					 SMIAPP_REG_U8_SMIA_VERSION,
> > +					 &minfo->smia_version);
> > +	if (!rval)
> > +		rval = smia_i2c_read_reg(client,
> > +					 SMIAPP_REG_U8_SMIAPP_VERSION,
> > +					 &minfo->smiapp_version);
> > +
> > +	if (rval) {
> > +		dev_err(&client->dev, "sensor detection failed\n");
> > +		return -ENODEV;
> > +	}
> > +
> > +	dev_dbg(&client->dev, "module 0x%2.2x-0x%4.4x\n",
> 
> "module 0x%02x-0x%04x\n" (and similarly below) ?

Hmm. %y.yx means exactly y characters of %x. What does %0yx mean?

> > +		minfo->manufacturer_id, minfo->model_id);
> > +
> > +	dev_dbg(&client->dev,
> > +		"module revision 0x%2.2x-0x%2.2x date %2.2d-%2.2d-%2.2d\n",
> > +		minfo->revision_number_major, minfo->revision_number_minor,
> > +		minfo->module_year, minfo->module_month, minfo->module_day);
> > +
> > +	dev_dbg(&client->dev, "sensor 0x%2.2x-0x%4.4x\n",
> > +		minfo->sensor_manufacturer_id, minfo->sensor_model_id);
> > +
> > +	dev_dbg(&client->dev,
> > +		"sensor revision 0x%2.2x firmware version 0x%2.2x\n",
> > +		minfo->sensor_revision_number, minfo->sensor_firmware_version);
> > +
> > +	dev_dbg(&client->dev, "smia version %2.2d smiapp version %2.2d\n",
> > +		minfo->smia_version, minfo->smiapp_version);
> > +
> 
> Could you please add a short comment to explain why this is needed ?

The one below? Some devices just have bad data in these variables. Hopefully
the other variables have better stuff.

The lvalues are module parameters whereas the rvalues are sensor parameters.

> > +	if (!minfo->manufacturer_id && !minfo->model_id) {
> > +		minfo->manufacturer_id = minfo->sensor_manufacturer_id;
> > +		minfo->model_id = minfo->sensor_model_id;
> > +		minfo->revision_number_major = minfo->sensor_revision_number;
> > +	}
> > +
> > +	for (i = 0; i < ARRAY_SIZE(smiapp_module_idents); i++) {
> > +		if (smiapp_module_idents[i].manufacturer_id
> > +		    != minfo->manufacturer_id)
> > +			continue;
> > +		if (smiapp_module_idents[i].model_id != minfo->model_id)
> > +			continue;
> > +		if (smiapp_module_idents[i].flags
> > +		    & SMIAPP_MODULE_IDENT_FLAG_REV_LE) {
> > +			if (smiapp_module_idents[i].revision_number_major
> > +			    < minfo->revision_number_major)
> > +				continue;
> > +		} else {
> > +			if (smiapp_module_idents[i].revision_number_major
> > +			    != minfo->revision_number_major)
> > +				continue;
> > +		}
> > +
> > +		minfo->name = smiapp_module_idents[i].name;
> > +		minfo->quirk = smiapp_module_idents[i].quirk;
> > +		break;
> > +	}
> > +
> > +	if (i >= ARRAY_SIZE(smiapp_module_idents))
> > +		dev_warn(&client->dev, "no quirks for this module\n");
> 
> Maybe a message such as "unknown SMIA++ module - trying generic support" would
> be better ? Many of the known modules have no quirks.

I'd like to think it as a positive message of the conformance of the sensor
--- still it may inform that the quirks are actually missing. What do you
think?

> > +
> > +	dev_dbg(&client->dev, "the sensor is called %s, ident %2.2x%4.4x%2.2x\n",
> > +		minfo->name, minfo->manufacturer_id, minfo->model_id,
> > +		minfo->revision_number_major);
> > +
> > +	strlcpy(subdev->name, sensor->minfo.name, sizeof(subdev->name));
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct v4l2_subdev_ops smiapp_ops;
> > +static const struct v4l2_subdev_internal_ops smiapp_internal_ops;
> > +static const struct media_entity_operations smiapp_entity_ops;
> > +
> > +static int smiapp_registered(struct v4l2_subdev *subdev)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> > +	struct smiapp_subdev *last = NULL;
> > +	int rval;
> > +	u32 tmp, i;
> > +
> > +	sensor->vana = regulator_get(&client->dev, "VANA");
> > +	if (IS_ERR(sensor->vana)) {
> > +		dev_err(&client->dev, "could not get regulator for vana\n");
> > +		return -ENODEV;
> > +	}
> > +
> > +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) {
> > +		if (gpio_request_one(sensor->platform_data->xshutdown, 0,
> > +				     "SMIA++ xshutdown") != 0) {
> > +			dev_err(&client->dev,
> > +				"unable to acquire reset gpio %d\n",
> > +				sensor->platform_data->xshutdown);
> > +			rval = -ENODEV;
> > +			goto out_gpio_request;
> > +		}
> > +	}
> > +
> > +	rval = smiapp_power_on(sensor);
> > +	if (rval) {
> > +		rval = -ENODEV;
> > +		goto out_smiapp_power_on;
> > +	}
> > +
> > +	rval = smiapp_identify_module(subdev);
> > +	if (rval) {
> > +		rval = -ENODEV;
> > +		goto out_power_off;
> > +	}
> > +
> > +	rval = smiapp_get_all_limits(sensor);
> > +	if (rval) {
> > +		rval = -ENODEV;
> > +		goto out_power_off;
> > +	}
> > +
> > +	/*
> > +	 * Handle Sensor Module orientation on the board.
> > +	 *
> > +	 * The application of H-FLIP and V-FLIP on the sensor is modified by
> > +	 * the sensor orientation on the board.
> > +	 *
> > +	 * For SMIAPP_BOARD_SENSOR_ORIENT_180 the default behaviour is to set
> > +	 * both H-FLIP and V-FLIP for normal operation which also implies
> > +	 * that a set/unset operation for user space HFLIP and VFLIP v4l2
> > +	 * controls will need to be internally inverted.
> > +	 *
> > +	 * Rotation also changes the bayer pattern.
> > +	 */
> > +	if (sensor->platform_data->module_board_orient ==
> > +	    SMIAPP_MODULE_BOARD_ORIENT_180)
> > +		sensor->hvflip_inv_mask = SMIAPP_IMAGE_ORIENTATION_HFLIP |
> > +					  SMIAPP_IMAGE_ORIENTATION_VFLIP;
> > +
> > +	rval = smiapp_get_mbus_formats(sensor);
> > +	if (rval) {
> > +		rval = -ENODEV;
> > +		goto out_power_off;
> > +	}
> > +
> > +	if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY]) {
> > +		int i;
> > +		int val;
> > +
> > +		rval = smia_i2c_read_reg(client,
> > +					 SMIAPP_REG_U8_BINNING_SUBTYPES, &val);
> > +		if (rval < 0) {
> > +			rval = -ENODEV;
> > +			goto out_power_off;
> > +		}
> > +		sensor->nbinning_subtypes = min_t(u8, val,
> > +						  SMIAPP_BINNING_SUBTYPES);
> > +
> > +		for (i = 0; i < sensor->nbinning_subtypes; i++) {
> > +			rval = smia_i2c_read_reg(
> > +				client, SMIAPP_REG_U8_BINNING_TYPE_n(i), &val);
> > +			if (rval < 0) {
> > +				rval = -ENODEV;
> > +				goto out_power_off;
> > +			}
> > +			sensor->binning_subtypes[i] =
> > +				*(struct smiapp_binning_subtype *)&val;
> > +
> > +			dev_dbg(&client->dev, "binning %xx%x\n",
> > +				sensor->binning_subtypes[i].horizontal,
> > +				sensor->binning_subtypes[i].vertical);
> > +		}
> > +	}
> > +	sensor->binning_horizontal = 1;
> > +	sensor->binning_vertical = 1;
> > +
> > +	/* SMIA++ NVM initialization - it will be read from the sensor
> > +	 * when it is first requested by userspace.
> > +	 */
> > +	if (sensor->minfo.smiapp_version && sensor->platform_data->nvm_size) {
> > +		sensor->nvm = kzalloc(sensor->platform_data->nvm_size,
> > +				      GFP_KERNEL);
> > +		if (sensor->nvm == NULL) {
> > +			dev_err(&client->dev, "nvm buf allocation failed\n");
> > +			rval = -ENOMEM;
> > +			goto out_power_off;
> > +		}
> > +
> > +		if (device_create_file(&client->dev, &dev_attr_nvm) != 0) {
> > +			dev_err(&client->dev, "sysfs nvm entry failed\n");
> > +			rval = -EBUSY;
> > +			goto out_nvm_release1;
> > +		}
> > +	}
> > +
> > +	rval = smiapp_call_quirk(sensor, limits);
> > +	if (rval) {
> > +		dev_err(&client->dev, "limits quirks failed\n");
> > +		goto out_nvm_release2;
> > +	}
> > +
> > +	/* We consider this as profile 0 sensor if any of these are zero. */
> > +	if (!sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV] ||
> > +	    !sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV] ||
> > +	    !sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV] ||
> > +	    !sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV]) {
> > +		sensor->minfo.smiapp_profile = SMIAPP_PROFILE_0;
> > +	} else if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> > +		   != SMIAPP_SCALING_CAPABILITY_NONE) {
> > +		if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
> > +		    == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
> > +			sensor->minfo.smiapp_profile = SMIAPP_PROFILE_1;
> > +		else
> > +			sensor->minfo.smiapp_profile = SMIAPP_PROFILE_2;
> > +		sensor->scaler = &sensor->sds[sensor->sds_used];
> > +		sensor->sds_used++;
> > +	} else if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
> > +		   == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
> > +		sensor->scaler = &sensor->sds[sensor->sds_used];
> > +		sensor->sds_used++;
> > +	}
> > +	sensor->binner = &sensor->sds[sensor->sds_used];
> > +	sensor->sds_used++;
> > +	sensor->pixel_array = &sensor->sds[sensor->sds_used];
> > +	sensor->sds_used++;
> > +
> > +	sensor->scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
> > +
> > +	for (i = 0; i < SMIAPP_SUBDEVS; i++) {
> > +		struct {
> > +			struct smiapp_subdev *sds;
> > +			char *name;
> > +		} _t[] = {
> > +			{ sensor->scaler, "scaler", },
> > +			{ sensor->binner, "binner", },
> > +			{ sensor->pixel_array, "pixel array", },
> > +		}, *this = &_t[i];
> 
> What about moving _t outside of the loop (and renaming it to something more
> explicit) ? There's no need to initialize it at each iteration.

I will have to populate it in code rather than initialiser, or I'll add more
braces. I think the compiler will optimise that nevertheless. I could make
it const. How about that? :-)

> > +		if (!this->sds)
> > +			continue;
> > +
> > +		if (this->sds != sensor->src)
> > +			v4l2_subdev_init(&this->sds->sd, &smiapp_ops);
> > +
> > +		this->sds->sensor = sensor;
> > +
> > +		if (this->sds == sensor->pixel_array) {
> > +			if (this->sds == sensor->src)
> > +				sensor->sds->sd.entity.num_pads = 1;
> 
> That's supposed to be initialized by media_entity_init(), why do you need to
> set it explictly here ?

For historical reasons... I once didn't expect the binner to always exist.
It now does. Removed the two lines.

> > +			this->sds->npads = 1;
> > +		} else {
> > +			this->sds->npads = 2;
> > +		}
> > +
> > +		snprintf(this->sds->sd.name,
> > +			 sizeof(this->sds->sd.name), "%s %s",
> > +			 sensor->minfo.name, this->name);
> > +
> > +		this->sds->sink_fmt.width =
> > +			sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
> > +		this->sds->sink_fmt.height =
> > +			sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
> > +		this->sds->crop[SMIAPP_PAD_SINK].width =
> > +			this->sds->sink_fmt.width;
> > +		this->sds->crop[SMIAPP_PAD_SINK].height =
> > +			this->sds->sink_fmt.height;
> > +		this->sds->crop[SMIAPP_PAD_SOURCE] =
> > +			this->sds->compose =
> > +			this->sds->crop[SMIAPP_PAD_SINK];
> > +
> > +		this->sds->pads[1].flags = MEDIA_PAD_FL_SINK;
> > +		this->sds->pads[0].flags = MEDIA_PAD_FL_SOURCE;
> 
> Pad 1 is the sink pad and pad 0 the source pad ? That's very unusual, couldn't
> you make it the other way around ?

Originally, when I was creating the src entity I didn't know whether it was
going to have one or two pads. There's one reason left tough: I now know all
my sink pads have id 1 and source pads have id 0. That makes things easier
in a number of places.

> > +
> > +		this->sds->sd.entity.ops = &smiapp_entity_ops;
> > +
> > +		if (last == NULL) {
> > +			last = this->sds;
> > +			continue;
> > +		}
> > +
> > +		this->sds->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
> > +		this->sds->sd.internal_ops = &smiapp_internal_ops;
> > +		this->sds->sd.owner = NULL;
> > +		v4l2_set_subdevdata(&this->sds->sd, client);
> > +
> > +		rval = v4l2_device_register_subdev(sensor->src->sd.v4l2_dev,
> > +						   &this->sds->sd);
> > +		if (rval) {
> > +			dev_err(&client->dev,
> > +				"v4l2_device_register_subdev failed\n");
> > +			goto out_nvm_release2;
> > +		}
> > +
> > +		rval = media_entity_init(&this->sds->sd.entity,
> > +					 this->sds->npads, this->sds->pads, 0);
> > +		if (rval) {
> > +			dev_err(&client->dev,
> > +				"media_entity_init failed\n");
> > +			goto out_nvm_release2;
> > +		}
> 
> You should initialize the entity (and possibly create the link) before
> registering the subdev.

Fixed.

> > +
> > +		rval = media_entity_create_link(&this->sds->sd.entity, 0,
> > +						&last->sd.entity, 1,
> > +						MEDIA_LNK_FL_ENABLED |
> > +						MEDIA_LNK_FL_IMMUTABLE);
> > +		if (rval) {
> > +			dev_err(&client->dev,
> > +				"media_entity_create_link failed\n");
> > +			goto out_nvm_release2;
> > +		}
> > +
> > +		last = this->sds;
> > +	}
> > +
> > +	dev_dbg(&client->dev, "profile %d\n", sensor->minfo.smiapp_profile);
> > +
> > +	sensor->pixel_array->sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
> > +
> > +	/* final steps */
> > +	smiapp_read_frame_fmt(sensor);
> > +	rval = smiapp_init_controls(sensor);
> > +	if (rval < 0)
> > +		goto out_nvm_release2;
> > +
> > +	rval = smiapp_update_mode(sensor);
> > +	if (rval) {
> > +		dev_err(&client->dev, "update mode failed\n");
> > +		goto out_nvm_release2;
> > +	}
> > +
> > +	sensor->streaming = false;
> > +	sensor->dev_init_done = true;
> > +
> > +	/* check flash capability */
> > +	rval = smia_i2c_read_reg(client,
> > +				 SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, &tmp);
> > +	sensor->flash_capability = tmp;
> > +	if (rval)
> > +		goto out_nvm_release2;
> > +
> > +	smiapp_power_off(sensor);
> 
> Shouldn't you take the sensor mutex around the whole function ?

I don't think it's necessary --- the device nodes will be created by the
master driver later on so no-one can access them yet.

> > +
> > +	return 0;
> > +
> > +out_nvm_release2:
> > +	device_remove_file(&client->dev, &dev_attr_nvm);
> > +
> > +out_nvm_release1:
> > +	kfree(sensor->nvm);
> > +	sensor->nvm = NULL;
> 
> You can move this under out_power_off, if sensor->nvm is already NULL kfree
> will be a no-op.

Ack.

> > +
> > +out_power_off:
> > +	smiapp_power_off(sensor);
> > +
> > +out_smiapp_power_on:
> > +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> > +		gpio_free(sensor->platform_data->xshutdown);
> > +
> > +out_gpio_request:
> > +	regulator_put(sensor->vana);
> > +	sensor->vana = NULL;
> > +	return rval;
> > +}
> > +
> > +static int smiapp_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
> > +{
> > +	struct smiapp_subdev *ssd = to_smiapp_subdev(sd);
> > +	struct v4l2_subdev_selection sel;
> > +	struct v4l2_rect *try_sel;
> > +	int i;
> > +	int rval;
> > +
> > +	mutex_lock(&ssd->sensor->power_mutex);
> > +	mutex_lock(&ssd->sensor->mutex);
> > +
> > +	for (i = 0; i < ssd->npads; i++) {
> > +		struct v4l2_subdev_format fmt;
> > +		struct v4l2_mbus_framefmt *try_fmt;
> > +
> > +		fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> > +		fmt.pad = i;
> > +		__smiapp_get_format(sd, fh, &fmt);
> > +		try_fmt = v4l2_subdev_get_try_format(fh, i);
> > +		*try_fmt = fmt.format;
> > +
> > +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> > +		sel.pad = i;
> > +		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
> > +		__smiapp_get_selection(sd, fh, &sel);
> > +		try_sel = v4l2_subdev_get_try_crop(fh, i);
> > +		*try_sel = sel.r;
> 
> Wouldn't it be better to use the default values instead of the active ones
> here ?

Good question.

> > +	}
> > +
> > +	if (ssd != ssd->sensor->pixel_array) {
> > +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> > +		sel.pad = SMIAPP_PAD_SINK;
> > +		sel.target = V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE;
> > +		__smiapp_get_selection(sd, fh, &sel);
> > +		try_sel = v4l2_subdev_get_try_compose(fh, SMIAPP_PAD_SINK);
> > +		*try_sel = sel.r;
> > +	}
> > +
> > +	rval = smiapp_set_power(sd, 1);
> > +
> > +	mutex_unlock(&ssd->sensor->mutex);
> > +
> > +	if (rval < 0)
> > +		goto out;
> > +
> > +	/* Was the sensor already powered on? */
> > +	if (ssd->sensor->power_count > 1)
> 
> power_count is accessed in smiapp_set_power without taking the power_mutex
> lock. Are two locks really needed ?

Well, now that you mention it, control handler setup function that wouldn't
take the locks would resolve the issue, I think. Should I create one?

> > +		goto out;
> > +
> > +	for (i = 0; i < ssd->sensor->sds_used; i++) {
> > +		rval = v4l2_ctrl_handler_setup(
> > +			&ssd->sensor->sds[i].ctrl_handler);
> > +		if (rval)
> > +			goto out;
> > +	}
> 
> Doesn't this belong to the set power handler ?

Yes, it does. Fixed.

> > +
> > +out:
> > +	mutex_unlock(&ssd->sensor->power_mutex);
> > +
> > +	return rval;
> > +}
> > +
> > +static int smiapp_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
> > +{
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(sd);
> > +	int rval;
> > +
> > +	mutex_lock(&sensor->power_mutex);
> > +	mutex_lock(&sensor->mutex);
> > +	rval = smiapp_set_power(sd, 0);
> > +	mutex_unlock(&sensor->mutex);
> > +	mutex_unlock(&sensor->power_mutex);
> > +
> > +	return rval;
> > +}
> > +
> > +static const struct v4l2_subdev_video_ops smiapp_video_ops = {
> > +	.s_stream = smiapp_set_stream,
> > +};
> > +
> > +static const struct v4l2_subdev_core_ops smiapp_core_ops = {
> > +	.s_power = smiapp_set_power,
> > +};
> > +
> > +static const struct v4l2_subdev_pad_ops smiapp_pad_ops = {
> > +	.enum_mbus_code = smiapp_enum_mbus_code,
> > +	.get_fmt = smiapp_get_format,
> > +	.set_fmt = smiapp_set_format,
> > +	.get_selection = smiapp_get_selection,
> > +	.set_selection = smiapp_set_selection,
> > +	.link_validate = v4l2_subdev_link_validate_default,
> 
> This can be left NULL.

Fixed.

> > +};
> > +
> > +static const struct v4l2_subdev_sensor_ops smiapp_sensor_ops = {
> > +	.g_skip_frames = smiapp_get_skip_frames,
> > +};
> > +
> > +static const struct v4l2_subdev_ops smiapp_ops = {
> > +	.core = &smiapp_core_ops,
> > +	.video = &smiapp_video_ops,
> > +	.pad = &smiapp_pad_ops,
> > +	.sensor = &smiapp_sensor_ops,
> > +};
> > +
> > +static const struct media_entity_operations smiapp_entity_ops = {
> > +	.link_validate = v4l2_subdev_link_validate,
> > +};
> > +
> > +static const struct v4l2_subdev_internal_ops smiapp_internal_src_ops = {
> > +	.registered = smiapp_registered,
> > +	.open = smiapp_open,
> > +	.close = smiapp_close,
> > +};
> > +
> > +static const struct v4l2_subdev_internal_ops smiapp_internal_ops = {
> > +	.open = smiapp_open,
> > +	.close = smiapp_close,
> > +};
> > +
> > +/*
> > ---------------------------------------------------------------------------
> > -- + * I2C Driver
> > + */
> > +
> > +#ifdef CONFIG_PM
> > +
> > +static int smiapp_suspend(struct device *dev)
> > +{
> > +	struct i2c_client *client = to_i2c_client(dev);
> > +	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int ss;
> > +
> > +	BUG_ON(mutex_is_locked(&sensor->mutex));
> > +
> > +	if (sensor->power_count == 0)
> > +		return 0;
> > +
> > +	if (sensor->streaming)
> > +		smiapp_stop_streaming(sensor);
> > +
> > +	ss = sensor->streaming;
> > +
> > +	smiapp_power_off(sensor);
> > +
> > +	/* save state for resume */
> > +	sensor->streaming = ss;
> > +
> > +	return 0;
> > +}
> > +
> > +static int smiapp_resume(struct device *dev)
> > +{
> > +	struct i2c_client *client = to_i2c_client(dev);
> > +	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int rval;
> > +
> > +	if (sensor->power_count == 0)
> > +		return 0;
> > +
> > +	rval = smiapp_power_on(sensor);
> > +	if (rval)
> > +		return rval;
> > +
> > +	if (sensor->streaming)
> > +		rval = smiapp_start_streaming(sensor);
> > +
> > +	return rval;
> > +}
> > +
> > +#else
> > +
> > +#define smiapp_suspend	NULL
> > +#define smiapp_resume	NULL
> > +
> > +#endif /* CONFIG_PM */
> > +
> > +static int smiapp_probe(struct i2c_client *client,
> > +			const struct i2c_device_id *devid)
> > +{
> > +	struct smiapp_sensor *sensor;
> > +	int rval;
> > +
> > +	if (client->dev.platform_data == NULL)
> > +		return -ENODEV;
> > +
> > +	sensor = kzalloc(sizeof(*sensor), GFP_KERNEL);
> > +	if (sensor == NULL)
> > +		return -ENOMEM;
> > +
> > +	sensor->platform_data = client->dev.platform_data;
> > +	mutex_init(&sensor->mutex);
> > +	mutex_init(&sensor->power_mutex);
> > +	sensor->src = &sensor->sds[sensor->sds_used];
> > +
> > +	v4l2_i2c_subdev_init(&sensor->src->sd, client, &smiapp_ops);
> > +	sensor->src->sd.internal_ops = &smiapp_internal_src_ops;
> > +	sensor->src->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
> > +	sensor->src->sensor = sensor;
> > +
> > +	sensor->src->pads[0].flags = MEDIA_PAD_FL_SOURCE;
> > +	rval = media_entity_init(&sensor->src->sd.entity, 2,
> > +				 sensor->src->pads, 0);
> > +	if (rval < 0)
> > +		kfree(sensor);
> > +
> > +	return rval;
> > +}
> > +
> > +static int __exit smiapp_remove(struct i2c_client *client)
> > +{
> > +	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
> > +	struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
> > +	int i;
> > +
> > +	if (sensor->power_count) {
> > +		if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> > +			gpio_set_value(sensor->platform_data->xshutdown, 0);
> > +		sensor->platform_data->set_xclk(&sensor->src->sd, 0);
> > +		sensor->power_count = 0;
> > +	}
> > +
> > +	if (sensor->nvm) {
> > +		device_remove_file(&client->dev, &dev_attr_nvm);
> > +		kfree(sensor->nvm);
> > +	}
> > +
> > +	for (i = 0; i < sensor->sds_used; i++) {
> > +		media_entity_cleanup(&sensor->sds[i].sd.entity);
> > +		v4l2_device_unregister_subdev(&sensor->sds[i].sd);
> > +	}
> > +	smiapp_free_controls(sensor);
> > +	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
> > +		gpio_free(sensor->platform_data->xshutdown);
> > +	if (sensor->vana)
> > +		regulator_put(sensor->vana);
> > +
> > +	kfree(sensor);
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct i2c_device_id smiapp_id_table[] = {
> > +	{ SMIAPP_NAME, 0 },
> > +	{ },
> > +};
> > +MODULE_DEVICE_TABLE(i2c, smiapp_id_table);
> > +
> > +static const struct dev_pm_ops smiapp_pm_ops = {
> > +	.suspend	= smiapp_suspend,
> > +	.resume		= smiapp_resume,
> > +};
> > +
> > +static struct i2c_driver smiapp_i2c_driver = {
> > +	.driver	= {
> > +		.name = SMIAPP_NAME,
> > +		.pm = &smiapp_pm_ops,
> > +	},
> > +	.probe	= smiapp_probe,
> > +	.remove	= __exit_p(smiapp_remove),
> > +	.id_table = smiapp_id_table,
> > +};
> > +
> > +static int __init smiapp_init(void)
> > +{
> > +	int rval;
> > +
> > +	rval = i2c_add_driver(&smiapp_i2c_driver);
> > +	if (rval)
> > +		pr_err("Failed registering driver" SMIAPP_NAME "\n");
> > +
> > +	return rval;
> > +}
> > +
> > +static void __exit smiapp_exit(void)
> > +{
> > +	i2c_del_driver(&smiapp_i2c_driver);
> > +}
> > +
> > +module_init(smiapp_init);
> > +module_exit(smiapp_exit);
> > +
> > +MODULE_AUTHOR("Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>");
> > +MODULE_DESCRIPTION("Generic SMIA/SMIA++ camera module driver");
> > +MODULE_LICENSE("GPL");
> 
> [snip]
> 
> > diff --git a/drivers/media/video/smiapp/smiapp-pll.c
> > b/drivers/media/video/smiapp/smiapp-pll.c new file mode 100644
> > index 0000000..5014730
> > --- /dev/null
> > +++ b/drivers/media/video/smiapp/smiapp-pll.c
> 
> [snip]
> 
> I'll send a patch on top of this one to split smiapp-pll to a separate module,
> as the code is needed for at least one non-SMIA(++) Aptina sensor.

Ack.

> [snip]
> 
> > --git a/drivers/media/video/smiapp/smiapp-reg.h
> > b/drivers/media/video/smiapp/smiapp-reg.h new file mode 100644
> > index 0000000..126ca5b
> > --- /dev/null
> > +++ b/drivers/media/video/smiapp/smiapp-reg.h
> 
> [snip]
> 
> > +#define SMIAPP_SCALING_CAPABILITY_NONE			0
> > +#define SMIAPP_SCALING_CAPABILITY_HORIZONTAL		1
> > +#define SMIAPP_SCALING_CAPABILITY_BOTH			2 /* horizontal/both */
> 
> Do you mean horizontal/vertical ?

No. The BOTH capability means that either horizontal or (horizontal and
vertical) scaling is supported (parentheses for precedence).

> [snip]
> 
> > diff --git a/drivers/media/video/smiapp/smiapp-regs.c
> > b/drivers/media/video/smiapp/smiapp-regs.c new file mode 100644
> > index 0000000..9a2326a
> > --- /dev/null
> > +++ b/drivers/media/video/smiapp/smiapp-regs.c
> > @@ -0,0 +1,230 @@
> > +/*
> > + * drivers/media/video/smiapp-regs.c
> > + *
> > + * Generic driver for SMIA/SMIA++ compliant camera modules
> > + *
> > + * Copyright (C) 2011--2012 Nokia Corporation
> > + * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> > + *
> > + * This program is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License
> > + * version 2 as published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that it will be useful, but
> > + * WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> > + * 02110-1301 USA
> > + *
> > + */
> > +
> > +#include "smiapp-debug.h"
> > +
> > +#include <linux/delay.h>
> > +#include <linux/i2c.h>
> > +
> > +#include "smiapp-regs.h"
> > +
> > +static uint32_t float_to_u32_mul_1000000(struct i2c_client *client,
> > +					 uint32_t phloat)
> 
> Now that's creative :-)

I couldn't figure out a way to avoid that, unfortunately. There are a few
corresponding functions in math emulation libraries but it seems onethey
would require significant changes to be usable for this driver.

> > +{
> > +	int32_t exp;
> > +	uint64_t man;
> > +
> > +	if (phloat >= 0x80000000) {
> > +		dev_err(&client->dev, "this is a negative number\n");
> > +		return 0;
> > +	}
> > +
> > +	if (phloat == 0x7f800000)
> > +		return ~0; /* Inf. */
> > +
> > +	if ((phloat & 0x7f800000) == 0x7f800000) {
> > +		dev_err(&client->dev, "NaN or other special number\n");
> > +		return 0;
> > +	}
> > +
> > +	/* Valid cases begin here */
> > +	if (phloat == 0)
> > +		return 0; /* Valid zero */
> > +
> > +	if (phloat > 0x4f800000)
> > +		return ~0; /* larger than 4294967295 */
> > +
> > +	/*
> > +	 * Unbias exponent (note how phloat is now guaranteed to
> > +	 * have 0 in the high bit)
> > +	 */
> > +	exp = ((int32_t)phloat >> 23) - 127;
> > +
> > +	/* Extract mantissa, add missing '1' bit and it's in MHz */
> > +	man = ((phloat & 0x7fffff) | 0x800000) * 1000000ULL;
> > +
> > +	if (exp < 0)
> > +		man >>= -exp;
> > +	else
> > +		man <<= exp;
> > +
> > +	man >>= 23; /* Remove mantissa bias */
> > +
> > +	return man & 0xffffffff;
> > +}
> > +
> > +
> > +/*
> > + * Read a 8/16/32-bit i2c register.  The value is returned in 'val'.
> > + * Returns zero if successful, or non-zero otherwise.
> > + */
> > +int smia_i2c_read_reg(struct i2c_client *client, u32 reg, u32 *val)
> > +{
> > +	struct i2c_msg msg[1];
> 
> s/[1]// ?

Fixed.

> > +	unsigned char data[4];
> > +	unsigned int len = (u8)(reg >> 16);
> > +	u16 offset = reg;
> > +	int r;
> > +
> > +	if (!client->adapter)
> > +		return -ENODEV;
> 
> Can this happen ?

I guess not. Fixed.

> > +	if (len != SMIA_REG_8BIT && len != SMIA_REG_16BIT
> > +	    && len != SMIA_REG_32BIT)
> > +		return -EINVAL;
> > +
> > +	msg->addr = client->addr;
> > +	msg->flags = 0;
> > +	msg->len = 2;
> > +	msg->buf = data;
> > +
> > +	/* high byte goes out first */
> > +	data[0] = (u8) (offset >> 8);
> > +	data[1] = (u8) offset;
> > +	r = i2c_transfer(client->adapter, msg, 1);
> > +	if (r != 1) {
> > +		if (r >= 0)
> > +			r = -EBUSY;
> > +		goto err;
> > +	}
> > +
> > +	msg->len = len;
> > +	msg->flags = I2C_M_RD;
> > +	r = i2c_transfer(client->adapter, msg, 1);
> > +	if (r != 1) {
> > +		if (r >= 0)
> > +			r = -EBUSY;
> > +		goto err;
> > +	}
> > +
> > +	*val = 0;
> > +	/* high byte comes first */
> > +	switch (len) {
> > +	case SMIA_REG_32BIT:
> > +		*val = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) +
> > +			data[3];
> > +		break;
> > +	case SMIA_REG_16BIT:
> > +		*val = (data[0] << 8) + data[1];
> > +		break;
> > +	case SMIA_REG_8BIT:
> > +		*val = data[0];
> > +		break;
> > +	default:
> > +		BUG();
> > +	}
> > +
> > +	if (reg & SMIA_REG_FLAG_FLOAT)
> > +		*val = float_to_u32_mul_1000000(client, *val);
> > +
> > +	return 0;
> > +
> > +err:
> > +	dev_err(&client->dev, "read from offset 0x%x error %d\n", offset, r);
> > +
> > +	return r;
> > +}
> > +
> > +static void smia_i2c_create_msg(struct i2c_client *client, u16 len, u16
> > reg, +				u32 val, struct i2c_msg *msg,
> > +				unsigned char *buf)
> > +{
> > +	msg->addr = client->addr;
> > +	msg->flags = 0; /* Write */
> > +	msg->len = 2 + len;
> > +	msg->buf = buf;
> > +
> > +	/* high byte goes out first */
> > +	buf[0] = (u8) (reg >> 8);
> > +	buf[1] = (u8) (reg & 0xff);
> > +
> > +	switch (len) {
> > +	case SMIA_REG_8BIT:
> > +		buf[2] = val;
> > +		break;
> > +	case SMIA_REG_16BIT:
> > +		buf[2] = val >> 8;
> > +		buf[3] = val;
> > +		break;
> > +	case SMIA_REG_32BIT:
> > +		buf[2] = val >> 24;
> > +		buf[3] = val >> 16;
> > +		buf[4] = val >> 8;
> > +		buf[5] = val;
> > +		break;
> > +	default:
> > +		BUG();
> > +	}
> 
> As this function is reused anywhere else, I would inline ti inside 
> smia_i2c_write_reg().

Done.

> > +}
> > +
> > +/*
> > + * Write to a 8/16-bit register.
> > + * Returns zero if successful, or non-zero otherwise.
> > + */
> > +int smia_i2c_write_reg(struct i2c_client *client, u32 reg, u32 val)
> > +{
> > +	struct i2c_msg msg[1];
> 
> s/[1]// ?

Fixed.

> > +	unsigned char data[6];
> > +	unsigned int retries = 5;
> > +	unsigned int flags = reg >> 24;
> > +	unsigned int len = (u8)(reg >> 16);
> > +	u16 offset = reg;
> > +	int r;
> > +
> > +	if (!client->adapter)
> > +		return -ENODEV;
> 
> Can this happen ?

Fixed.

> > +
> > +	if ((len != SMIA_REG_8BIT && len != SMIA_REG_16BIT &&
> > +	     len != SMIA_REG_32BIT) || flags)
> > +		return -EINVAL;
> > +
> > +	smia_i2c_create_msg(client, len, offset, val, msg, data);
> > +
> > +	do {
> > +		/*
> > +		 * Due to unknown reason sensor stops responding. This
> > +		 * loop is a temporaty solution until the root cause
> > +		 * is found.
> > +		 */
> > +		r = i2c_transfer(client->adapter, msg, 1);
> > +		if (r == 1)
> > +			break;
> > +
> > +		usleep_range(2000, 2000);
> > +	} while (retries--);
> 
> What about a for loop ?

Fixed.

> > +
> > +	if (r != 1) {
> > +		dev_err(&client->dev,
> > +			"wrote 0x%x to offset 0x%x error %d\n", val, offset, r);
> > +	} else {
> > +		if (r >= 0)
> > +			r = -EBUSY;
> > +		r = 0; /* on success i2c_transfer() return messages trasfered */
> 
> Was this added at the end of the patch just to see if I would review
> everything ? :-)

No; it comes from the naming of the files I think. I didn't write much of
the code in this function --- it's mostly the same in the Harmattan version,
too.

> > +	}
> > +
> > +	if (retries < 5)
> > +		dev_err(&client->dev, "sensor i2c stall encountered. "
> > +			"retries: %d\n", 5 - retries);
> 
> You can move this right after the loop and return an error.

I simplified error handling in this function.

> > +
> > +	return r;
> > +}
> > diff --git a/drivers/media/video/smiapp/smiapp-regs.h
> > b/drivers/media/video/smiapp/smiapp-regs.h new file mode 100644
> > index 0000000..20c4c25
> > --- /dev/null
> > +++ b/drivers/media/video/smiapp/smiapp-regs.h
> > @@ -0,0 +1,46 @@
> > +/*
> > + * include/media/smiapp-regs.h
> > + *
> > + * Generic driver for SMIA/SMIA++ compliant camera modules
> > + *
> > + * Copyright (C) 2011--2012 Nokia Corporation
> > + * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> > + *
> > + * This program is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License
> > + * version 2 as published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that it will be useful, but
> > + * WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> > + * 02110-1301 USA
> > + *
> > + */
> > +
> > +#ifndef SMIAPP_REGS_H
> > +#define SMIAPP_REGS_H
> > +
> > +#include <linux/i2c.h>
> > +#include <linux/types.h>
> > +
> > +/* Use upper 8 bits of the type field for flags */
> > +#define SMIA_REG_FLAG_FLOAT		(1 << 24)
> > +
> > +#define SMIA_REG_8BIT			1
> > +#define SMIA_REG_16BIT			2
> > +#define SMIA_REG_32BIT			4
> > +struct smia_reg {
> > +	u16 type;
> > +	u16 reg;			/* 16-bit offset */
> > +	u32 val;			/* 8/16/32-bit value */
> > +};
> > +
> > +int smia_i2c_read_reg(struct i2c_client *client, u32 reg, u32 *val);
> > +int smia_i2c_write_reg(struct i2c_client *client, u32 reg, u32 val);
> 
> What about renaming those to smia_read() and smia_write() (or possible
> smia_i2c_read() and smia_i2c_write()) ? It would help
> shortening long code lines.

smia_{read,write} sound good.

> > +
> > +#endif
> > diff --git a/drivers/media/video/smiapp/smiapp.h
> > b/drivers/media/video/smiapp/smiapp.h new file mode 100644
> > index 0000000..df514dd
> > --- /dev/null
> > +++ b/drivers/media/video/smiapp/smiapp.h
> 
> [snip]
> 
> > +struct smiapp_module_ident {
> > +	u8 manufacturer_id;
> > +	u16 model_id;
> > +	u8 revision_number_major;
> > +
> > +	u8 flags;
> > +
> > +	char *name;
> > +	const struct smiapp_quirk *quirk;
> > +} __packed;
> 
> Is there really a need to pack this ? You could just move
> revision_number_major above model_id to save a couple of bytes and leave
> packing out.

The order is there for readability, packing to save memory. I can change the
order, too, if you think it's a good idea.

> > +#define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk)	\
> > +	{ .manufacturer_id = manufacturer,				\
> > +			.model_id = model,				\
> > +			.revision_number_major = rev,			\
> > +			.flags = fl,					\
> > +			.name = _name,					\
> > +			.quirk = _quirk, }
> 
> Any reason for the strange indentation ?

This is standard indentation in my Emacsitor. Hmm. I think I might be fine
even if it indented less. It looks like it wouldn't be indended to work that
way.

> > +
> > +#define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk)	\
> > +	{ .manufacturer_id = manufacturer,				\
> > +			.model_id = model,				\
> > +			.revision_number_major = rev,			\
> > +			.flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE,	\
> > +			.name = _name,					\
> > +			.quirk = _quirk, }
> > +
> > +#define SMIAPP_IDENT_L(manufacturer, model, rev, _name)			\
> > +	{ .manufacturer_id = manufacturer,				\
> > +			.model_id = model,				\
> > +			.revision_number_major = rev,			\
> > +			.flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE,	\
> > +			.name = _name, }
> > +
> > +#define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk)		\
> > +	{ .manufacturer_id = manufacturer,				\
> > +			.model_id = model,				\
> > +			.revision_number_major = rev,			\
> > +			.flags = 0,					\
> > +			.name = _name,					\
> > +			.quirk = _quirk, }
> > +
> > +#define SMIAPP_IDENT(manufacturer, model, rev, _name)			\
> > +	{ .manufacturer_id = manufacturer,				\
> > +			.model_id = model,				\
> > +			.revision_number_major = rev,			\
> > +			.flags = 0,					\
> > +			.name = _name, }
> > +
> 
> [snip]
> 
> > +/*
> > + * struct smiapp_sensor - Main device structure
> > + */
> > +struct smiapp_sensor {
> > +	/*
> > +	 * "mutex" is used to serialise access to all fields here
> > +	 * except v4l2_ctrls at the end of the struct. Should both
> > +	 * "mutex" and the control handler locks be held
> > +	 * simultaneously, the control handler lock must be acquired
> > +	 * first. "mutex" is also used to serialise access to file
> > +	 * handle specific information. The exception to this rule is
> > +	 * the power_mutex below.
> > +	 */
> 
> This comment is probably a bit outdated.

Fixed.

> > +	struct mutex mutex;
> > +	/*
> > +	 * power_mutex is used to serialise opening and closing of
> > +	 * file handles, including power management.
> > +	 */
> > +	struct mutex power_mutex;
> > +	struct smiapp_subdev sds[SMIAPP_SUBDEVS];
> > +	u32 sds_used;
> > +	struct smiapp_subdev *src;
> > +	struct smiapp_subdev *binner;
> > +	struct smiapp_subdev *scaler;
> > +	struct smiapp_subdev *pixel_array;
> > +	struct smiapp_platform_data *platform_data;
> > +	struct regulator *vana;
> > +	u32 limits[SMIAPP_LIMIT_LAST];
> > +	u8 nbinning_subtypes;
> > +	struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
> > +	u32 mbus_frame_fmts;
> > +	const struct smiapp_csi_data_format *csi_format;
> > +	const struct smiapp_csi_data_format *internal_csi_format;
> > +	u32 default_mbus_frame_fmts;
> > +	int default_pixel_order;
> > +
> > +	u8 binning_horizontal;
> > +	u8 binning_vertical;
> > +
> > +	u8 scale_m;
> > +	u8 scaling_mode;
> > +
> > +	u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
> > +	u8 flash_capability;
> > +	u8 frame_skip;
> > +
> > +	int power_count;
> > +
> > +	unsigned int streaming:1;
> > +	unsigned int dev_init_done:1;
> > +
> > +	u8 *nvm;		/* nvm memory buffer */
> > +	unsigned int nvm_size;	/* bytes */
> > +
> > +	struct smiapp_module_info minfo;
> > +
> > +	struct smiapp_pll pll;
> > +
> > +	/* Pixel array controls */
> > +	struct v4l2_ctrl *analog_gain;
> > +	struct v4l2_ctrl *exposure;
> > +	struct v4l2_ctrl *hflip;
> > +	struct v4l2_ctrl *vflip;
> > +	struct v4l2_ctrl *vblank;
> > +	struct v4l2_ctrl *hblank;
> > +	struct v4l2_ctrl *pixel_rate_parray;
> > +	/* src controls */
> > +	struct v4l2_ctrl *link_freq;
> > +	struct v4l2_ctrl *pixel_rate_csi;
> > +};
> > +
> > +#define to_smiapp_subdev(_sd)				\
> > +	container_of(_sd, struct smiapp_subdev, sd)
> > +
> > +#define to_smiapp_sensor(_sd)	\
> > +	(to_smiapp_subdev(_sd)->sensor)
> > +
> > +int smiapp_pll_update(struct smiapp_sensor *sensor);
> > +int smiapp_pll_configure(struct smiapp_sensor *sensor);
> > +
> > +#endif /* __SMIAPP_PRIV_H_ */
> 
> [snip]

Many thanks for your comments in this review, Laurent!

Kind regards,

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

* Re: [PATCH v3 32/33] smiapp: Add driver.
  2012-02-29  5:41     ` Sakari Ailus
@ 2012-02-29  9:35       ` Laurent Pinchart
  2012-02-29 10:00         ` Sylwester Nawrocki
  2012-03-01 14:01         ` Sakari Ailus
  0 siblings, 2 replies; 87+ messages in thread
From: Laurent Pinchart @ 2012-02-29  9:35 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

On Wednesday 29 February 2012 07:41:50 Sakari Ailus wrote:
> On Mon, Feb 27, 2012 at 04:38:49PM +0100, Laurent Pinchart wrote:
> > On Monday 20 February 2012 03:57:11 Sakari Ailus wrote:
> > > From: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
> > > 
> > > Add driver for SMIA++/SMIA image sensors. The driver exposes the sensor
> > > as three subdevs, pixel array, binner and scaler --- in case the device
> > > has a scaler.
> > > 
> > > Currently it relies on the board code for external clock handling. There
> > > is no fast way out of this dependency before the ISP drivers (omap3isp)
> > > among others will be able to export that clock through the clock
> > > framework instead.
> > > 
> > > Signed-off-by: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>

[snip]

> > > +
> > > +	dev_dbg(&client->dev, "format_model_type %s\n",
> > > +		fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE
> > > +		? "2 byte" :
> > > +		fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE
> > > +		? "4 byte" : "is simply bad");
> > 
> > Simply ? :-)
> 
> Yeah, well, it's not that complex. :-) Do you think I should change that to
> something else?

No, that's fine. I just found it funny that the format could be "simply bad" 
:-)

[snip]

> > > +	if (embedded_start == -1 || embedded_end == -1)
> > > +		embedded_start = embedded_end = 0;
> > 
> > One assignment per line please.
> 
> I'm not sure if you gain any clarity with that, but I guess it's a norm
> still. Fixed.

It's very easy to miss one of the assignments if you group them in a single 
line.Or at least it is for me.

[snip]

> > > +	case V4L2_CID_VBLANK:
> > > +		exposure = sensor->exposure->val;
> > > +
> > > +		__smiapp_update_exposure_limits(sensor);
> > > +
> > > +		if (exposure > sensor->exposure->maximum) {
> > > +			sensor->exposure->val =
> > > +				sensor->exposure->maximum;
> > > +			rval = smiapp_set_ctrl(
> > > +				sensor->exposure);
> > 
> > Shouldn't you call the V4L2 control API here instead ? Otherwise no
> > control change event will be generated for the exposure time. Will this
> > work as expected if the user sets the exposure time in the same
> > VIDIOC_S_EXT_CTRLS call ?
> 
> Good question. I'm holding the ctrl handler lock here and so can't use the
> regular functions to perform the change. Perhaps time to implement
> __v4l2_subdev_s_ext_ctrls() and use that?

Do you mean __v4l2_ctrl_s_ctrl() ? I think it would make sense, yes.

> > > +	if (sensor->pixel_array->ctrl_handler.error) {
> > > +		dev_err(&client->dev,
> > > +			"pixel array controls initialization failed (%d)\n",
> > > +			sensor->pixel_array->ctrl_handler.error);
> > 
> > Shouldn't you call v4l2_ctrl_handler_free() here ?
> 
> Yes. Fixed.
> 
> > > +		return sensor->pixel_array->ctrl_handler.error;
> > > +	}
> > > +
> > > +	sensor->pixel_array->sd.ctrl_handler =
> > > +		&sensor->pixel_array->ctrl_handler;
> > > +
> > > +	v4l2_ctrl_cluster(2, &sensor->hflip);
> > 
> > Shouldn't you move this before the control handler check ?
> 
> Why? It can't fail.

I thought it could fail. You could then leave it here, but it would be easier 
from a maintenance point of view to check the error code after completing all 
control-related initialization, as it would avoid introducing a bug if for 
some reason the v4l2_ctrl_cluster() function needs to return an error later.

[snip]

> > > +static int smiapp_update_mode(struct smiapp_sensor *sensor)
> > > +{
> > 
> > This function isn't protected by the sensor mutex when called from
> > s_power, but it changes controls. The other call paths seem OK, but you
> > might want to double-check them.
> 
> It's actually not an issue. When s_power is being called there are no other
> users and the power_lock serialises it.

Are you sure about that? s_power can be called from both the subdev video node 
open() handlers (assuming the sensor is in the pipe).

> I implemented it this way since the control setup acquires the same lock
> that I would have to hold while powering up. The power_lock fixes this
> issue.
> 
> I cleaned this up so that I won't take sensor->mutex at all anymore.

[snip]

> > > +	dev_dbg(&client->dev, "module 0x%2.2x-0x%4.4x\n",
> > 
> > "module 0x%02x-0x%04x\n" (and similarly below) ?
> 
> Hmm. %y.yx means exactly y characters of %x. What does %0yx mean?

at least y characters, pad with 0. You can keep %y.yx if you prefer it.

> > > +		minfo->manufacturer_id, minfo->model_id);
> > > +
> > > +	dev_dbg(&client->dev,
> > > +		"module revision 0x%2.2x-0x%2.2x date %2.2d-%2.2d-%2.2d\n",
> > > +		minfo->revision_number_major, minfo->revision_number_minor,
> > > +		minfo->module_year, minfo->module_month, minfo->module_day);
> > > +
> > > +	dev_dbg(&client->dev, "sensor 0x%2.2x-0x%4.4x\n",
> > > +		minfo->sensor_manufacturer_id, minfo->sensor_model_id);
> > > +
> > > +	dev_dbg(&client->dev,
> > > +		"sensor revision 0x%2.2x firmware version 0x%2.2x\n",
> > > +		minfo->sensor_revision_number, minfo->sensor_firmware_version);
> > > +
> > > +	dev_dbg(&client->dev, "smia version %2.2d smiapp version %2.2d\n",
> > > +		minfo->smia_version, minfo->smiapp_version);
> > > +
> > 
> > Could you please add a short comment to explain why this is needed ?
> 
> The one below?

Yes, the lines below, sorry.

> Some devices just have bad data in these variables. Hopefully the other
> variables have better stuff.

I knew why this was needed, but other readers might not :-) That's why a 
comment would be good.

> The lvalues are module parameters whereas the rvalues are sensor parameters.
>
> > > +	if (!minfo->manufacturer_id && !minfo->model_id) {
> > > +		minfo->manufacturer_id = minfo->sensor_manufacturer_id;
> > > +		minfo->model_id = minfo->sensor_model_id;
> > > +		minfo->revision_number_major = minfo->sensor_revision_number;
> > > +	}
> > > +
> > > +	for (i = 0; i < ARRAY_SIZE(smiapp_module_idents); i++) {
> > > +		if (smiapp_module_idents[i].manufacturer_id
> > > +		    != minfo->manufacturer_id)
> > > +			continue;
> > > +		if (smiapp_module_idents[i].model_id != minfo->model_id)
> > > +			continue;
> > > +		if (smiapp_module_idents[i].flags
> > > +		    & SMIAPP_MODULE_IDENT_FLAG_REV_LE) {
> > > +			if (smiapp_module_idents[i].revision_number_major
> > > +			    < minfo->revision_number_major)
> > > +				continue;
> > > +		} else {
> > > +			if (smiapp_module_idents[i].revision_number_major
> > > +			    != minfo->revision_number_major)
> > > +				continue;
> > > +		}
> > > +
> > > +		minfo->name = smiapp_module_idents[i].name;
> > > +		minfo->quirk = smiapp_module_idents[i].quirk;
> > > +		break;
> > > +	}
> > > +
> > > +	if (i >= ARRAY_SIZE(smiapp_module_idents))
> > > +		dev_warn(&client->dev, "no quirks for this module\n");
> > 
> > Maybe a message such as "unknown SMIA++ module - trying generic support"
> > would be better ? Many of the known modules have no quirks.
> 
> I'd like to think it as a positive message of the conformance of the sensor
> --- still it may inform that the quirks are actually missing. What do you
> think?

In that case I think something similar to my message is better :-) I agree 
about the meaning the message should convey.

> > > +
> > > +	dev_dbg(&client->dev, "the sensor is called %s, ident
> > > %2.2x%4.4x%2.2x\n",
> > > +		minfo->name, minfo->manufacturer_id, minfo->model_id,
> > > +		minfo->revision_number_major);
> > > +
> > > +	strlcpy(subdev->name, sensor->minfo.name, sizeof(subdev->name));
> > > +
> > > +	return 0;
> > > +}

[snip]

> > > +static int smiapp_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh
> > > *fh)
> > > +{
> > > +	struct smiapp_subdev *ssd = to_smiapp_subdev(sd);
> > > +	struct v4l2_subdev_selection sel;
> > > +	struct v4l2_rect *try_sel;
> > > +	int i;
> > > +	int rval;
> > > +
> > > +	mutex_lock(&ssd->sensor->power_mutex);
> > > +	mutex_lock(&ssd->sensor->mutex);
> > > +
> > > +	for (i = 0; i < ssd->npads; i++) {
> > > +		struct v4l2_subdev_format fmt;
> > > +		struct v4l2_mbus_framefmt *try_fmt;
> > > +
> > > +		fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> > > +		fmt.pad = i;
> > > +		__smiapp_get_format(sd, fh, &fmt);
> > > +		try_fmt = v4l2_subdev_get_try_format(fh, i);
> > > +		*try_fmt = fmt.format;
> > > +
> > > +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> > > +		sel.pad = i;
> > > +		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
> > > +		__smiapp_get_selection(sd, fh, &sel);
> > > +		try_sel = v4l2_subdev_get_try_crop(fh, i);
> > > +		*try_sel = sel.r;
> > 
> > Wouldn't it be better to use the default values instead of the active ones
> > here ?
> 
> Good question.
> 
> > > +	}
> > > +
> > > +	if (ssd != ssd->sensor->pixel_array) {
> > > +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> > > +		sel.pad = SMIAPP_PAD_SINK;
> > > +		sel.target = V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE;
> > > +		__smiapp_get_selection(sd, fh, &sel);
> > > +		try_sel = v4l2_subdev_get_try_compose(fh, SMIAPP_PAD_SINK);
> > > +		*try_sel = sel.r;
> > > +	}
> > > +
> > > +	rval = smiapp_set_power(sd, 1);
> > > +
> > > +	mutex_unlock(&ssd->sensor->mutex);
> > > +
> > > +	if (rval < 0)
> > > +		goto out;
> > > +
> > > +	/* Was the sensor already powered on? */
> > > +	if (ssd->sensor->power_count > 1)
> > 
> > power_count is accessed in smiapp_set_power without taking the power_mutex
> > lock. Are two locks really needed ?
> 
> Well, now that you mention it, control handler setup function that wouldn't
> take the locks would resolve the issue, I think. Should I create one?

I'd ask Hans about that.

[snip]

> > > --git a/drivers/media/video/smiapp/smiapp-reg.h
> > > b/drivers/media/video/smiapp/smiapp-reg.h new file mode 100644
> > > index 0000000..126ca5b
> > > --- /dev/null
> > > +++ b/drivers/media/video/smiapp/smiapp-reg.h
> > 
> > [snip]
> > 
> > > +#define SMIAPP_SCALING_CAPABILITY_NONE			0
> > > +#define SMIAPP_SCALING_CAPABILITY_HORIZONTAL		1
> > > +#define SMIAPP_SCALING_CAPABILITY_BOTH			2 /* horizontal/both */
> > 
> > Do you mean horizontal/vertical ?
> 
> No. The BOTH capability means that either horizontal or (horizontal and
> vertical) scaling is supported (parentheses for precedence).

I was referring to the comment on the third line.

[snip]

> > > +static uint32_t float_to_u32_mul_1000000(struct i2c_client *client,
> > > +					 uint32_t phloat)
> > 
> > Now that's creative :-)
> 
> I couldn't figure out a way to avoid that, unfortunately. There are a few
> corresponding functions in math emulation libraries but it seems onethey
> would require significant changes to be usable for this driver.

I should have been more specific, I was referring to the name 'phloat' :-)

[snip]

> > > diff --git a/drivers/media/video/smiapp/smiapp.h
> > > b/drivers/media/video/smiapp/smiapp.h new file mode 100644
> > > index 0000000..df514dd
> > > --- /dev/null
> > > +++ b/drivers/media/video/smiapp/smiapp.h
> > 
> > [snip]
> > 
> > > +struct smiapp_module_ident {
> > > +	u8 manufacturer_id;
> > > +	u16 model_id;
> > > +	u8 revision_number_major;
> > > +
> > > +	u8 flags;
> > > +
> > > +	char *name;
> > > +	const struct smiapp_quirk *quirk;
> > > +} __packed;
> > 
> > Is there really a need to pack this ? You could just move
> > revision_number_major above model_id to save a couple of bytes and leave
> > packing out.
> 
> The order is there for readability, packing to save memory. I can change the
> order, too, if you think it's a good idea.

Packing usually increases the run time (and possibly code size), as the CPU 
will need to perform unaligned access. I don't think it's worth it in this 
case. At second thought moving the fields around won't save any memory, so I 
would just remove __packed.

> > > +#define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk)	
\
> > > +	{ .manufacturer_id = manufacturer,				\
> > > +			.model_id = model,				\
> > > +			.revision_number_major = rev,			\
> > > +			.flags = fl,					\
> > > +			.name = _name,					\
> > > +			.quirk = _quirk, }
> > 
> > Any reason for the strange indentation ?
> 
> This is standard indentation in my Emacsitor. Hmm. I think I might be fine
> even if it indented less. It looks like it wouldn't be indended to work that
> way.

Maybe it's time to switch to vi ? :-D

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH v3 32/33] smiapp: Add driver.
  2012-02-29  9:35       ` Laurent Pinchart
@ 2012-02-29 10:00         ` Sylwester Nawrocki
  2012-03-01 14:01         ` Sakari Ailus
  1 sibling, 0 replies; 87+ messages in thread
From: Sylwester Nawrocki @ 2012-02-29 10:00 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Sakari Ailus, linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi,

On 02/29/2012 10:35 AM, Laurent Pinchart wrote:
>>>> +	if (sensor->pixel_array->ctrl_handler.error) {
>>>> +		dev_err(&client->dev,
>>>> +			"pixel array controls initialization failed (%d)\n",
>>>> +			sensor->pixel_array->ctrl_handler.error);
>>>
>>> Shouldn't you call v4l2_ctrl_handler_free() here ?
>>
>> Yes. Fixed.
>>
>>>> +		return sensor->pixel_array->ctrl_handler.error;
>>>> +	}
>>>> +
>>>> +	sensor->pixel_array->sd.ctrl_handler =
>>>> +		&sensor->pixel_array->ctrl_handler;
>>>> +
>>>> +	v4l2_ctrl_cluster(2, &sensor->hflip);
>>>
>>> Shouldn't you move this before the control handler check ?
>>
>> Why? It can't fail.
> 
> I thought it could fail. You could then leave it here, but it would be easier 
> from a maintenance point of view to check the error code after completing all 
> control-related initialization, as it would avoid introducing a bug if for 
> some reason the v4l2_ctrl_cluster() function needs to return an error later.

By calling v4l2_ctrl_cluster() after the control handler check you're sure
sensor->hflip is a pointer to a valid control. In case the HFLIP control
creation fails and you try to cluster that, unpredictable things may happen.
Well, predictable, e.g. BUG_ON() in v4l2_ctrl_cluster(). :-)

So using v4l2_ctrl_cluster() before checking ctrl_handler.error would require
validating the control pointer or maybe something more.

-- 

Regards,
Sylwester

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

* Re: [PATCH v3 32/33] smiapp: Add driver.
  2012-02-29  9:35       ` Laurent Pinchart
  2012-02-29 10:00         ` Sylwester Nawrocki
@ 2012-03-01 14:01         ` Sakari Ailus
  2012-03-01 14:56           ` Laurent Pinchart
  1 sibling, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-03-01 14:01 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

Laurent Pinchart wrote:
...
>>>> +	case V4L2_CID_VBLANK:
>>>> +		exposure = sensor->exposure->val;
>>>> +
>>>> +		__smiapp_update_exposure_limits(sensor);
>>>> +
>>>> +		if (exposure > sensor->exposure->maximum) {
>>>> +			sensor->exposure->val =
>>>> +				sensor->exposure->maximum;
>>>> +			rval = smiapp_set_ctrl(
>>>> +				sensor->exposure);
>>>
>>> Shouldn't you call the V4L2 control API here instead ? Otherwise no
>>> control change event will be generated for the exposure time. Will this
>>> work as expected if the user sets the exposure time in the same
>>> VIDIOC_S_EXT_CTRLS call ?
>>
>> Good question. I'm holding the ctrl handler lock here and so can't use the
>> regular functions to perform the change. Perhaps time to implement
>> __v4l2_subdev_s_ext_ctrls() and use that?
> 
> Do you mean __v4l2_ctrl_s_ctrl() ? I think it would make sense, yes.

Something to discuss with Hans, I guess.

>>>> +	if (sensor->pixel_array->ctrl_handler.error) {
>>>> +		dev_err(&client->dev,
>>>> +			"pixel array controls initialization failed (%d)\n",
>>>> +			sensor->pixel_array->ctrl_handler.error);
>>>
>>> Shouldn't you call v4l2_ctrl_handler_free() here ?
>>
>> Yes. Fixed.
>>
>>>> +		return sensor->pixel_array->ctrl_handler.error;
>>>> +	}
>>>> +
>>>> +	sensor->pixel_array->sd.ctrl_handler =
>>>> +		&sensor->pixel_array->ctrl_handler;
>>>> +
>>>> +	v4l2_ctrl_cluster(2, &sensor->hflip);
>>>
>>> Shouldn't you move this before the control handler check ?
>>
>> Why? It can't fail.
> 
> I thought it could fail. You could then leave it here, but it would be easier 
> from a maintenance point of view to check the error code after completing all 
> control-related initialization, as it would avoid introducing a bug if for 
> some reason the v4l2_ctrl_cluster() function needs to return an error later.

Then every other driver must also take that into account. And as
Sylwester said, there are things to check before that as well.

So I could also re-check the control handler error status after the
function but currently it doesn't look like it would make sense.

> [snip]
> 
>>>> +static int smiapp_update_mode(struct smiapp_sensor *sensor)
>>>> +{
>>>
>>> This function isn't protected by the sensor mutex when called from
>>> s_power, but it changes controls. The other call paths seem OK, but you
>>> might want to double-check them.
>>
>> It's actually not an issue. When s_power is being called there are no other
>> users and the power_lock serialises it.
> 
> Are you sure about that? s_power can be called from both the subdev video node 
> open() handlers (assuming the sensor is in the pipe).

Good point... That certainly needs to be taken into account. I move the
lock to set_power directly.

>>>> +		minfo->manufacturer_id, minfo->model_id);
>>>> +
>>>> +	dev_dbg(&client->dev,
>>>> +		"module revision 0x%2.2x-0x%2.2x date %2.2d-%2.2d-%2.2d\n",
>>>> +		minfo->revision_number_major, minfo->revision_number_minor,
>>>> +		minfo->module_year, minfo->module_month, minfo->module_day);
>>>> +
>>>> +	dev_dbg(&client->dev, "sensor 0x%2.2x-0x%4.4x\n",
>>>> +		minfo->sensor_manufacturer_id, minfo->sensor_model_id);
>>>> +
>>>> +	dev_dbg(&client->dev,
>>>> +		"sensor revision 0x%2.2x firmware version 0x%2.2x\n",
>>>> +		minfo->sensor_revision_number, minfo->sensor_firmware_version);
>>>> +
>>>> +	dev_dbg(&client->dev, "smia version %2.2d smiapp version %2.2d\n",
>>>> +		minfo->smia_version, minfo->smiapp_version);
>>>> +
>>>
>>> Could you please add a short comment to explain why this is needed ?
>>
>> The one below?
> 
> Yes, the lines below, sorry.
> 
>> Some devices just have bad data in these variables. Hopefully the other
>> variables have better stuff.
> 
> I knew why this was needed, but other readers might not :-) That's why a 
> comment would be good.

Comment added.

>> The lvalues are module parameters whereas the rvalues are sensor parameters.
>>
>>>> +	if (!minfo->manufacturer_id && !minfo->model_id) {
>>>> +		minfo->manufacturer_id = minfo->sensor_manufacturer_id;
>>>> +		minfo->model_id = minfo->sensor_model_id;
>>>> +		minfo->revision_number_major = minfo->sensor_revision_number;
>>>> +	}
>>>> +
>>>> +	for (i = 0; i < ARRAY_SIZE(smiapp_module_idents); i++) {
>>>> +		if (smiapp_module_idents[i].manufacturer_id
>>>> +		    != minfo->manufacturer_id)
>>>> +			continue;
>>>> +		if (smiapp_module_idents[i].model_id != minfo->model_id)
>>>> +			continue;
>>>> +		if (smiapp_module_idents[i].flags
>>>> +		    & SMIAPP_MODULE_IDENT_FLAG_REV_LE) {
>>>> +			if (smiapp_module_idents[i].revision_number_major
>>>> +			    < minfo->revision_number_major)
>>>> +				continue;
>>>> +		} else {
>>>> +			if (smiapp_module_idents[i].revision_number_major
>>>> +			    != minfo->revision_number_major)
>>>> +				continue;
>>>> +		}
>>>> +
>>>> +		minfo->name = smiapp_module_idents[i].name;
>>>> +		minfo->quirk = smiapp_module_idents[i].quirk;
>>>> +		break;
>>>> +	}
>>>> +
>>>> +	if (i >= ARRAY_SIZE(smiapp_module_idents))
>>>> +		dev_warn(&client->dev, "no quirks for this module\n");
>>>
>>> Maybe a message such as "unknown SMIA++ module - trying generic support"
>>> would be better ? Many of the known modules have no quirks.
>>
>> I'd like to think it as a positive message of the conformance of the sensor
>> --- still it may inform that the quirks are actually missing. What do you
>> think?
> 
> In that case I think something similar to my message is better :-) I agree 
> about the meaning the message should convey.

I understand from your message that the sensor should have quirks and
the fact they're missing is a fall-back solution. :-)

>>>> +
>>>> +	dev_dbg(&client->dev, "the sensor is called %s, ident
>>>> %2.2x%4.4x%2.2x\n",
>>>> +		minfo->name, minfo->manufacturer_id, minfo->model_id,
>>>> +		minfo->revision_number_major);
>>>> +
>>>> +	strlcpy(subdev->name, sensor->minfo.name, sizeof(subdev->name));
>>>> +
>>>> +	return 0;
>>>> +}
> 
> [snip]
> 
>>>> +static int smiapp_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh
>>>> *fh)
>>>> +{
>>>> +	struct smiapp_subdev *ssd = to_smiapp_subdev(sd);
>>>> +	struct v4l2_subdev_selection sel;
>>>> +	struct v4l2_rect *try_sel;
>>>> +	int i;
>>>> +	int rval;
>>>> +
>>>> +	mutex_lock(&ssd->sensor->power_mutex);
>>>> +	mutex_lock(&ssd->sensor->mutex);
>>>> +
>>>> +	for (i = 0; i < ssd->npads; i++) {
>>>> +		struct v4l2_subdev_format fmt;
>>>> +		struct v4l2_mbus_framefmt *try_fmt;
>>>> +
>>>> +		fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
>>>> +		fmt.pad = i;
>>>> +		__smiapp_get_format(sd, fh, &fmt);
>>>> +		try_fmt = v4l2_subdev_get_try_format(fh, i);
>>>> +		*try_fmt = fmt.format;
>>>> +
>>>> +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
>>>> +		sel.pad = i;
>>>> +		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
>>>> +		__smiapp_get_selection(sd, fh, &sel);
>>>> +		try_sel = v4l2_subdev_get_try_crop(fh, i);
>>>> +		*try_sel = sel.r;
>>>
>>> Wouldn't it be better to use the default values instead of the active ones
>>> here ?
>>
>> Good question.
>>
>>>> +	}
>>>> +
>>>> +	if (ssd != ssd->sensor->pixel_array) {
>>>> +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
>>>> +		sel.pad = SMIAPP_PAD_SINK;
>>>> +		sel.target = V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE;
>>>> +		__smiapp_get_selection(sd, fh, &sel);
>>>> +		try_sel = v4l2_subdev_get_try_compose(fh, SMIAPP_PAD_SINK);
>>>> +		*try_sel = sel.r;
>>>> +	}
>>>> +
>>>> +	rval = smiapp_set_power(sd, 1);
>>>> +
>>>> +	mutex_unlock(&ssd->sensor->mutex);
>>>> +
>>>> +	if (rval < 0)
>>>> +		goto out;
>>>> +
>>>> +	/* Was the sensor already powered on? */
>>>> +	if (ssd->sensor->power_count > 1)
>>>
>>> power_count is accessed in smiapp_set_power without taking the power_mutex
>>> lock. Are two locks really needed ?
>>
>> Well, now that you mention it, control handler setup function that wouldn't
>> take the locks would resolve the issue, I think. Should I create one?
> 
> I'd ask Hans about that.
> 
> [snip]

I agree. I think I'll postpone the change so we can have time for
discussion. Would you be ok with that?

...
>>>> +static uint32_t float_to_u32_mul_1000000(struct i2c_client *client,
>>>> +					 uint32_t phloat)
>>>
>>> Now that's creative :-)
>>
>> I couldn't figure out a way to avoid that, unfortunately. There are a few
>> corresponding functions in math emulation libraries but it seems onethey
>> would require significant changes to be usable for this driver.
> 
> I should have been more specific, I was referring to the name 'phloat' :-)

Ah, that one. Antti wrote this part. :-)

>>>> diff --git a/drivers/media/video/smiapp/smiapp.h
>>>> b/drivers/media/video/smiapp/smiapp.h new file mode 100644
>>>> index 0000000..df514dd
>>>> --- /dev/null
>>>> +++ b/drivers/media/video/smiapp/smiapp.h
>>>
>>> [snip]
>>>
>>>> +struct smiapp_module_ident {
>>>> +	u8 manufacturer_id;
>>>> +	u16 model_id;
>>>> +	u8 revision_number_major;
>>>> +
>>>> +	u8 flags;
>>>> +
>>>> +	char *name;
>>>> +	const struct smiapp_quirk *quirk;
>>>> +} __packed;
>>>
>>> Is there really a need to pack this ? You could just move
>>> revision_number_major above model_id to save a couple of bytes and leave
>>> packing out.
>>
>> The order is there for readability, packing to save memory. I can change the
>> order, too, if you think it's a good idea.
> 
> Packing usually increases the run time (and possibly code size), as the CPU 
> will need to perform unaligned access. I don't think it's worth it in this 
> case. At second thought moving the fields around won't save any memory, so I 
> would just remove __packed.

Uh, you're right. I remove __packed.

I think this has come to be this way since I added flags later on.

>>>> +#define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk)	
> \
>>>> +	{ .manufacturer_id = manufacturer,				\
>>>> +			.model_id = model,				\
>>>> +			.revision_number_major = rev,			\
>>>> +			.flags = fl,					\
>>>> +			.name = _name,					\
>>>> +			.quirk = _quirk, }
>>>
>>> Any reason for the strange indentation ?
>>
>> This is standard indentation in my Emacsitor. Hmm. I think I might be fine
>> even if it indented less. It looks like it wouldn't be indended to work that
>> way.
> 
> Maybe it's time to switch to vi ? :-D

No, no Viitor. I once tried it and that didn't go well. I can recommend
Vigor for you, though:

<URL:http://vigor.sf.net>

:-)

Kind regards,

-- 
Sakari Ailus
sakari.ailus@iki.fi

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

* Re: [PATCH v3 32/33] smiapp: Add driver.
  2012-03-01 14:01         ` Sakari Ailus
@ 2012-03-01 14:56           ` Laurent Pinchart
  0 siblings, 0 replies; 87+ messages in thread
From: Laurent Pinchart @ 2012-03-01 14:56 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

On Thursday 01 March 2012 16:01:39 Sakari Ailus wrote:
> Laurent Pinchart wrote:

[snip]

> >>>> +		return sensor->pixel_array->ctrl_handler.error;
> >>>> +	}
> >>>> +
> >>>> +	sensor->pixel_array->sd.ctrl_handler =
> >>>> +		&sensor->pixel_array->ctrl_handler;
> >>>> +
> >>>> +	v4l2_ctrl_cluster(2, &sensor->hflip);
> >>> 
> >>> Shouldn't you move this before the control handler check ?
> >> 
> >> Why? It can't fail.
> > 
> > I thought it could fail. You could then leave it here, but it would be
> > easier from a maintenance point of view to check the error code after
> > completing all control-related initialization, as it would avoid
> > introducing a bug if for some reason the v4l2_ctrl_cluster() function
> > needs to return an error later.
> Then every other driver must also take that into account. And as
> Sylwester said, there are things to check before that as well.
> 
> So I could also re-check the control handler error status after the
> function but currently it doesn't look like it would make sense.

Sylwester made a very good point. Let's leave the code as-is.

[snip]

> >> The lvalues are module parameters whereas the rvalues are sensor
> >> parameters.>> 
> >>>> +	if (!minfo->manufacturer_id && !minfo->model_id) {
> >>>> +		minfo->manufacturer_id = minfo->sensor_manufacturer_id;
> >>>> +		minfo->model_id = minfo->sensor_model_id;
> >>>> +		minfo->revision_number_major = minfo->sensor_revision_number;
> >>>> +	}
> >>>> +
> >>>> +	for (i = 0; i < ARRAY_SIZE(smiapp_module_idents); i++) {
> >>>> +		if (smiapp_module_idents[i].manufacturer_id
> >>>> +		    != minfo->manufacturer_id)
> >>>> +			continue;
> >>>> +		if (smiapp_module_idents[i].model_id != minfo->model_id)
> >>>> +			continue;
> >>>> +		if (smiapp_module_idents[i].flags
> >>>> +		    & SMIAPP_MODULE_IDENT_FLAG_REV_LE) {
> >>>> +			if (smiapp_module_idents[i].revision_number_major
> >>>> +			    < minfo->revision_number_major)
> >>>> +				continue;
> >>>> +		} else {
> >>>> +			if (smiapp_module_idents[i].revision_number_major
> >>>> +			    != minfo->revision_number_major)
> >>>> +				continue;
> >>>> +		}
> >>>> +
> >>>> +		minfo->name = smiapp_module_idents[i].name;
> >>>> +		minfo->quirk = smiapp_module_idents[i].quirk;
> >>>> +		break;
> >>>> +	}
> >>>> +
> >>>> +	if (i >= ARRAY_SIZE(smiapp_module_idents))
> >>>> +		dev_warn(&client->dev, "no quirks for this module\n");
> >>> 
> >>> Maybe a message such as "unknown SMIA++ module - trying generic support"
> >>> would be better ? Many of the known modules have no quirks.
> >> 
> >> I'd like to think it as a positive message of the conformance of the
> >> sensor
> >> --- still it may inform that the quirks are actually missing. What do you
> >> think?
> > 
> > In that case I think something similar to my message is better :-) I agree
> > about the meaning the message should convey.
> 
> I understand from your message that the sensor should have quirks and
> the fact they're missing is a fall-back solution. :-)

Just use any message you want that says that the sensor model isn't known to 
the driver, but should still work as it's supposed to be standard-compliant 
:-)

[snip]

> >>>> +	}
> >>>> +
> >>>> +	if (ssd != ssd->sensor->pixel_array) {
> >>>> +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> >>>> +		sel.pad = SMIAPP_PAD_SINK;
> >>>> +		sel.target = V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTIVE;
> >>>> +		__smiapp_get_selection(sd, fh, &sel);
> >>>> +		try_sel = v4l2_subdev_get_try_compose(fh, SMIAPP_PAD_SINK);
> >>>> +		*try_sel = sel.r;
> >>>> +	}
> >>>> +
> >>>> +	rval = smiapp_set_power(sd, 1);
> >>>> +
> >>>> +	mutex_unlock(&ssd->sensor->mutex);
> >>>> +
> >>>> +	if (rval < 0)
> >>>> +		goto out;
> >>>> +
> >>>> +	/* Was the sensor already powered on? */
> >>>> +	if (ssd->sensor->power_count > 1)
> >>> 
> >>> power_count is accessed in smiapp_set_power without taking the
> >>> power_mutex lock. Are two locks really needed ?
> >> 
> >> Well, now that you mention it, control handler setup function that
> >> wouldn't take the locks would resolve the issue, I think. Should I create
> >> one?
> > 
> > I'd ask Hans about that.
> > 
> > [snip]
> 
> I agree. I think I'll postpone the change so we can have time for
> discussion. Would you be ok with that?

OK.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v3 09/33] v4l: Add subdev selections documentation
  2012-02-28 11:42       ` Laurent Pinchart
@ 2012-03-02 12:24         ` Sakari Ailus
  2012-03-02 17:54           ` Laurent Pinchart
  0 siblings, 1 reply; 87+ messages in thread
From: Sakari Ailus @ 2012-03-02 12:24 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

On Tue, Feb 28, 2012 at 12:42:26PM +0100, Laurent Pinchart wrote:
> On Sunday 26 February 2012 23:42:19 Sakari Ailus wrote:
> > Laurent Pinchart wrote:
> > > On Monday 20 February 2012 03:56:48 Sakari Ailus wrote:
> > >> Add documentation for V4L2 subdev selection API. This changes also
> > >> experimental V4L2 subdev API so that scaling now works through selection
> > >> API only.
> > >> 
> > >> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> > >> 
> > >> 
> > >> diff --git a/Documentation/DocBook/media/v4l/dev-subdev.xml
> > >> b/Documentation/DocBook/media/v4l/dev-subdev.xml index 0916a73..9d5e7da
> > >> 100644
> > >> --- a/Documentation/DocBook/media/v4l/dev-subdev.xml
> > >> +++ b/Documentation/DocBook/media/v4l/dev-subdev.xml
> > > 
> > > [snip]
> > > 
> > >> +      <para>Scaling operation changes the size of the image by scaling
> > >> +      it to new dimensions. Some sub-devices support it. The scaled
> > >> +      size (width and height) is represented by &v4l2-rect;. In the
> > >> +      case of scaling, top and left will always be zero. Scaling is
> > >> +      configured using &sub-subdev-g-selection; and
> > >> +      <constant>V4L2_SUBDEV_SEL_COMPOSE_ACTIVE</constant> selection
> > >> +      target on the sink pad of the subdev. The scaling is performed
> > >> +      related to the width and height of the crop rectangle on the
> > >> +      subdev's sink pad.</para>
> > > 
> > > I'm not sure if that would be very clear for readers who are not yet
> > > familiar with the API. What about the following text instead ?
> > > 
> > > "The scaling operation changes the size of the image by scaling it to new
> > > dimensions. The scaling ratio isn't specified explicitly, but is implied
> > > from the original and scaled image sizes. Both sizes are represented by
> > > &v4l2- rect;.
> > > 
> > > Scaling support is optional. When supported by a subdev, the crop
> > > rectangle on the subdev's sink pad is scaled to the size configured using
> > > &VIDIOC-SUBDEV-G- SELECTION; and
> > > <constant>V4L2_SUBDEV_SEL_COMPOSE_ACTIVE</constant> selection target on
> > > the same pad. If the subdev supports scaling but no composing, the top
> > > and left values are not used and must always be set to zero."
> > > 
> > > (note that &sub-subdev-g-selection; has been replaced with
> > > &VIDIOC-SUBDEV-G- SELECTION;)
> > > 
> > > I would also move this text after the sink pad crop description to follow
> > > the order in which operations are applied by subdevs.
> > 
> > I'm fine with that change, so I did it. However, I won't replace
> > &sub-subdev-g-selection; with &VIDIOC-SUBDEV-G-SELECTION; simply because
> > it won't work:
> > 
> > dev-subdev.xml:310: parser error : Entity 'VIDIOC-SUBDEV-G-SELECTION'
> > not defined
> >       size configured using &VIDIOC-SUBDEV-G-SELECTION; and
> > 
> > It's beyond me why not; similar references are being used elsewhere with
> > otherwise equivalent definitions. Perhaps the name is just too long?
> > That's the only difference I could think of: xmlto typically segfaults
> > on errors so I wouldn't be surprised of something so simple.
> 
> Don't give up so fast :-)
> 
> diff --git a/Documentation/DocBook/media/Makefile b/Documentation/DocBook/media/Makefile
> index 729f840..77ead85 100644
> --- a/Documentation/DocBook/media/Makefile
> +++ b/Documentation/DocBook/media/Makefile
> @@ -65,6 +65,8 @@ IOCTLS = \
>  	$(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/dvb/video.h) \
>  	$(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/media.h) \
>  	$(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/v4l2-subdev.h) \
> +	VIDIOC_SUBDEV_G_SELECTION \
> +	VIDIOC_SUBDEV_S_SELECTION \
>  	VIDIOC_SUBDEV_G_FRAME_INTERVAL \
>  	VIDIOC_SUBDEV_S_FRAME_INTERVAL \
>  	VIDIOC_SUBDEV_ENUM_MBUS_CODE \
> 
> and rm Documentation/DocBook/media-entities.tmpl before you compile the
> documentation.

Uh, well, at least it wasn't magic... but not far from that: the names are
in unexpected place and different from what are referred to in the xml
files.

> 
> > >> +      <para>As for pad formats, drivers store try and active
> > >> +      rectangles for the selection targets of ACTIVE type <xref
> > >> +      linkend="v4l2-subdev-selection-targets">.</xref></para>
> > >> +
> > >> +      <para>On sink pads, cropping is applied relatively to the
> > >> +      current pad format. The pad format represents the image size as
> > >> +      received by the sub-device from the previous block in the
> > >> +      pipeline, and the crop rectangle represents the sub-image that
> > >> +      will be transmitted further inside the sub-device for
> > >> +      processing.</para>
> > >> +
> > >> +      <para>On source pads, cropping is similar to sink pads, with the
> > >> +      exception that the source size from which the cropping is
> > >> +      performed, is the COMPOSE rectangle on the sink pad. In both
> > >> +      sink and source pads, the crop rectangle must be entirely
> > >> +      containted inside the source image size for the crop
> > >> +      operation.</para>
> > >> +
> > >> +      <para>The drivers should always use the closest possible
> > >> +      rectangle the user requests on all selection targets, unless
> > >> +      specificly told otherwise<xref
> > >> +      linkend="v4l2-subdev-selection-flags">.</xref></para>
> > >> +    </section>
> > >> +
> > >> +    <section>
> > >> +      <title>Types of selection targets</title>
> > >> +
> > >> +      <section>
> > >> +	<title>ACTIVE targets</title>
> > >> +
> > >> +	<para>ACTIVE targets reflect the actual hardware configuration
> > >> +	at any point of time.</para>
> > >> +      </section>
> > >> +
> > >> +      <section>
> > >> +	<title>BOUNDS targets</title>
> > >> +
> > >> +	<para>BOUNDS targets is the smallest rectangle within which
> > >> +	contains all valid ACTIVE rectangles.
> > > 
> > > s/within which/that/ ?
> > 
> > Ack.
> > 
> > >> It may not be possible
> > >> +	to set the ACTIVE rectangle as large as the BOUNDS rectangle,
> > >> +	however.</para>
> > > 
> > > What about
> > > 
> > > "The BOUNDS rectangle might not itself be a valid ACTIVE rectangle when
> > > all possible ACTIVE pixels do not form a rectangular shape (e.g.
> > > cross-shaped or round sensors)."
> > 
> > There are cases where the active size is limited, even if it's
> > rectangular. I can add the above case there, sure, if you think such
> > devices exist --- I've never heard of nor seen them. Some sensors are
> > documented to be cross-shaped but the only thing separating these from
> > the rest is that the manufacturer doesn't guarantee the quality of the
> > pixels in the corners. At least on those I've seen. You can still
> > capture the full pixel matrix.
> 
> Those are just examples. I think it's useful to add them, otherwise the reader
> won't know why and under what kind of circumstances the ACTIVE rectangle can't
> be as large at the BOUNDS rectangle.

Ok. Added that, plus a note that the maximum size may also be smaller than
the bounds rectangle.

> > >> +      </section>
> > >> 
> > >> -      <para>Cropping behaviour on output pads is not defined.</para>
> > >> +    </section>
> > >> +
> > >> +    <section>
> > >> +      <title>Order of configuration and format propagation</title>
> > >> +
> > >> +      <para>Inside subdevs, the order of image processing steps will
> > >> +      always be from the sink pad towards the source pad. This is also
> > >> +      reflected in the order in which the configuration must be
> > >> +      performed by the user: the changes made will be propagated to
> > >> +      any subsequent stages. If this behaviour is not desired, the
> > >> +      user must set
> > >> +      <constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant> flag.
> > > 
> > > Could you explain what happens when V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG is
> > > set ? Just stating that it doesn't follow the propagation behaviour
> > > previously described could be understood in many different ways.
> > 
> > Good point. How about this:
> > 
> > "This flag causes that no propagation of the changes are allowed in any
> > circumstances. This may also lead the accessed rectangle not being
> > changed at all,
> 
> "The accessed rectangle will likely be adjusted by the driver,"

Why "likely"? I think it should say "may" instead, but this of course
depends on what the user asks.

> > depending on the properties of the underlying hardware.
> > Some drivers may not support this flag."
> 
> What should happen then ? Should the flag be ignored, or should the driver
> return an error ?

Only the SMIA++ driver supports this flag so far (as goes for the subdev
selection interface).

I think it should be ignored. Consider a situation that we add a new flag
which most of the drivers are unaware of.

As we're adding the flag right at the time the interface is introduced, we
could also require that all drivers must support it. How about that? In that
case I'd remove the last sentence of that paragraph.

...

> [snip]
> 
> > >> +    <table pgwide="1" frame="none" id="v4l2-subdev-selection-flags">
> > >> +      <title>V4L2 subdev selection flags</title>
> > >> +      <tgroup cols="3">
> > >> +        &cs-def;
> > >> +	<tbody valign="top">
> > >> +	  <row>
> > >> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_GE</constant></entry>
> > >> +	    <entry>(1 &lt;&lt; 0)</entry>
> > >> +	    <entry>Suggest the driver it should choose greater or
> > >> +	    equal rectangle (in size) than was requested.</entry>
> > >> +	  </row>
> > >> +	  <row>
> > >> +	    <entry><constant>V4L2_SUBDEV_SEL_FLAG_SIZE_LE</constant></entry>
> > >> +	    <entry>(1 &lt;&lt; 1)</entry>
> > >> +	    <entry>Suggest the driver it should choose lesser or
> > >> +	    equal rectangle (in size) than was requested.</entry>
> > >> +	  </row>
> > > 
> > > Those two flags are only briefly described here, could you add a more
> > > detailed description either here or in
> > > Documentation/DocBook/media/v4l/dev-subdev.xml ?
> > Added:
> > 
> >             " Albeit the driver may choose a lesser size,
> > 	    it will only do so due to hardware limitations. Without
> > 	    this flag (and
> > 	    <constant>V4L2_SUBDEV_SEL_FLAG_SIZE_LE</constant>) the
> > 	    behaviour is to choose the closest possible
> > 	    rectangle."
> > 
> > Does that cover your understanding of a more detailed description? :-)
> 
> I was thinking about something in media/v4l/dev-subdev.xml that would explain
> what the flags are used for. media/v4l/vidioc-subdev-g-selection.xml is more
> like reference documentation.

Ok. I'll add a note there.

Regards,

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

* Re: [PATCH v3 09/33] v4l: Add subdev selections documentation
  2012-03-02 12:24         ` Sakari Ailus
@ 2012-03-02 17:54           ` Laurent Pinchart
  2012-03-02 18:01             ` Sakari Ailus
  0 siblings, 1 reply; 87+ messages in thread
From: Laurent Pinchart @ 2012-03-02 17:54 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Sakari,

On Friday 02 March 2012 14:24:40 Sakari Ailus wrote:
> On Tue, Feb 28, 2012 at 12:42:26PM +0100, Laurent Pinchart wrote:
> > On Sunday 26 February 2012 23:42:19 Sakari Ailus wrote:
> > > Laurent Pinchart wrote:
> > > > On Monday 20 February 2012 03:56:48 Sakari Ailus wrote:

> > > >> +      </section>
> > > >> 
> > > >> -      <para>Cropping behaviour on output pads is not defined.</para>
> > > >> +    </section>
> > > >> +
> > > >> +    <section>
> > > >> +      <title>Order of configuration and format propagation</title>
> > > >> +
> > > >> +      <para>Inside subdevs, the order of image processing steps will
> > > >> +      always be from the sink pad towards the source pad. This is
> > > >> also
> > > >> +      reflected in the order in which the configuration must be
> > > >> +      performed by the user: the changes made will be propagated to
> > > >> +      any subsequent stages. If this behaviour is not desired, the
> > > >> +      user must set
> > > >> +      <constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant> flag.
> > > > 
> > > > Could you explain what happens when V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG
> > > > is
> > > > set ? Just stating that it doesn't follow the propagation behaviour
> > > > previously described could be understood in many different ways.
> > > 
> > > Good point. How about this:
> > > 
> > > "This flag causes that no propagation of the changes are allowed in any
> > > circumstances. This may also lead the accessed rectangle not being
> > > changed at all,
> > 
> > "The accessed rectangle will likely be adjusted by the driver,"
> 
> Why "likely"? I think it should say "may" instead, but this of course
> depends on what the user asks.

I'm fine with "The accessed rectangle may be adjusted by the driver" (or 
s/may/can/, as adjusting the rectangle is part of the negotiation mechanism 
and is thus more likely than not).

> > > depending on the properties of the underlying hardware.
> > > Some drivers may not support this flag."
> > 
> > What should happen then ? Should the flag be ignored, or should the driver
> > return an error ?
> 
> Only the SMIA++ driver supports this flag so far (as goes for the subdev
> selection interface).
> 
> I think it should be ignored. Consider a situation that we add a new flag
> which most of the drivers are unaware of.
> 
> As we're adding the flag right at the time the interface is introduced, we
> could also require that all drivers must support it. How about that? In that
> case I'd remove the last sentence of that paragraph.

I think I'd like that better. Otherwise applications would be forced to check 
the returned rectangle to find out if the flag was taken into account.

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH v3 09/33] v4l: Add subdev selections documentation
  2012-03-02 17:54           ` Laurent Pinchart
@ 2012-03-02 18:01             ` Sakari Ailus
  0 siblings, 0 replies; 87+ messages in thread
From: Sakari Ailus @ 2012-03-02 18:01 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, hverkuil, teturtia, dacohen, snjw23,
	andriy.shevchenko, t.stanislaws, tuukkat76, k.debski, riverful

Hi Laurent,

On Fri, Mar 02, 2012 at 06:54:48PM +0100, Laurent Pinchart wrote:
> Hi Sakari,
> 
> On Friday 02 March 2012 14:24:40 Sakari Ailus wrote:
> > On Tue, Feb 28, 2012 at 12:42:26PM +0100, Laurent Pinchart wrote:
> > > On Sunday 26 February 2012 23:42:19 Sakari Ailus wrote:
> > > > Laurent Pinchart wrote:
> > > > > On Monday 20 February 2012 03:56:48 Sakari Ailus wrote:
> 
> > > > >> +      </section>
> > > > >> 
> > > > >> -      <para>Cropping behaviour on output pads is not defined.</para>
> > > > >> +    </section>
> > > > >> +
> > > > >> +    <section>
> > > > >> +      <title>Order of configuration and format propagation</title>
> > > > >> +
> > > > >> +      <para>Inside subdevs, the order of image processing steps will
> > > > >> +      always be from the sink pad towards the source pad. This is
> > > > >> also
> > > > >> +      reflected in the order in which the configuration must be
> > > > >> +      performed by the user: the changes made will be propagated to
> > > > >> +      any subsequent stages. If this behaviour is not desired, the
> > > > >> +      user must set
> > > > >> +      <constant>V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG</constant> flag.
> > > > > 
> > > > > Could you explain what happens when V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG
> > > > > is
> > > > > set ? Just stating that it doesn't follow the propagation behaviour
> > > > > previously described could be understood in many different ways.
> > > > 
> > > > Good point. How about this:
> > > > 
> > > > "This flag causes that no propagation of the changes are allowed in any
> > > > circumstances. This may also lead the accessed rectangle not being
> > > > changed at all,
> > > 
> > > "The accessed rectangle will likely be adjusted by the driver,"
> > 
> > Why "likely"? I think it should say "may" instead, but this of course
> > depends on what the user asks.
> 
> I'm fine with "The accessed rectangle may be adjusted by the driver" (or 
> s/may/can/, as adjusting the rectangle is part of the negotiation mechanism 
> and is thus more likely than not).
> 
> > > > depending on the properties of the underlying hardware.
> > > > Some drivers may not support this flag."
> > > 
> > > What should happen then ? Should the flag be ignored, or should the driver
> > > return an error ?
> > 
> > Only the SMIA++ driver supports this flag so far (as goes for the subdev
> > selection interface).
> > 
> > I think it should be ignored. Consider a situation that we add a new flag
> > which most of the drivers are unaware of.
> > 
> > As we're adding the flag right at the time the interface is introduced, we
> > could also require that all drivers must support it. How about that? In that
> > case I'd remove the last sentence of that paragraph.
> 
> I think I'd like that better. Otherwise applications would be forced to check 
> the returned rectangle to find out if the flag was taken into account.

Fixed for the next one.

Cheers,

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	jabber/XMPP/Gmail: sailus@retiisi.org.uk

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

end of thread, other threads:[~2012-03-02 18:01 UTC | newest]

Thread overview: 87+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-20  1:56 [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 01/33] v4l: Introduce integer menu controls Sakari Ailus
2012-02-20 17:36   ` Sylwester Nawrocki
2012-02-20  1:56 ` [PATCH v3 02/33] v4l: Document " Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 03/33] vivi: Add an integer menu test control Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 04/33] v4l: VIDIOC_SUBDEV_S_SELECTION and VIDIOC_SUBDEV_G_SELECTION IOCTLs Sakari Ailus
2012-02-21 14:34   ` Laurent Pinchart
2012-02-23  5:49     ` Sakari Ailus
2012-02-21 16:15   ` Laurent Pinchart
2012-02-23  6:01     ` Sakari Ailus
2012-02-27  0:22       ` Laurent Pinchart
2012-02-27  0:57         ` Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 05/33] v4l: vdev_to_v4l2_subdev() should have return type "struct v4l2_subdev *" Sakari Ailus
2012-02-21 14:37   ` Laurent Pinchart
2012-02-20  1:56 ` [PATCH v3 06/33] v4l: Check pad number in get try pointer functions Sakari Ailus
2012-02-21 14:42   ` Laurent Pinchart
2012-02-23  5:57     ` Sakari Ailus
2012-02-27  0:33       ` Laurent Pinchart
2012-02-27 12:27         ` Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 07/33] v4l: Support s_crop and g_crop through s/g_selection Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 08/33] v4l: Add subdev selections documentation: svg and dia files Sakari Ailus
2012-02-21 15:00   ` Laurent Pinchart
2012-02-26 18:56     ` Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 09/33] v4l: Add subdev selections documentation Sakari Ailus
2012-02-21 16:41   ` Laurent Pinchart
2012-02-26 21:42     ` Sakari Ailus
2012-02-28 11:42       ` Laurent Pinchart
2012-03-02 12:24         ` Sakari Ailus
2012-03-02 17:54           ` Laurent Pinchart
2012-03-02 18:01             ` Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 10/33] v4l: Mark VIDIOC_SUBDEV_G_CROP and VIDIOC_SUBDEV_S_CROP obsolete Sakari Ailus
2012-02-21 16:42   ` Laurent Pinchart
2012-02-20  1:56 ` [PATCH v3 11/33] v4l: Image source control class Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 12/33] v4l: Image processing " Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 13/33] v4l: Document raw bayer 4CC codes Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 14/33] v4l: Add DPCM compressed formats Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 15/33] media: Add link_validate() op to check links to the sink pad Sakari Ailus
2012-02-22 10:05   ` Laurent Pinchart
2012-02-23 15:04     ` Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 16/33] v4l: Improve sub-device documentation for pad ops Sakari Ailus
2012-02-22 10:06   ` Laurent Pinchart
2012-02-20  1:56 ` [PATCH v3 17/33] v4l: Implement v4l2_subdev_link_validate() Sakari Ailus
2012-02-22 10:14   ` Laurent Pinchart
2012-02-23 16:07     ` Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 18/33] v4l: Allow changing control handler lock Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 19/33] omap3isp: Support additional in-memory compressed bayer formats Sakari Ailus
2012-02-20  1:56 ` [PATCH v3 20/33] omap3isp: Move definitions required by board code under include/media Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 21/33] omap3: add definition for CONTROL_CAMERA_PHY_CTRL Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 22/33] omap3isp: Assume media_entity_pipeline_start may fail Sakari Ailus
2012-02-22 10:48   ` Laurent Pinchart
2012-02-26  1:08     ` Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 23/33] omap3isp: Add lane configuration to platform data Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 24/33] omap3isp: Add information on external subdev to struct isp_pipeline Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 25/33] omap3isp: Introduce omap3isp_get_external_info() Sakari Ailus
2012-02-22 10:55   ` Laurent Pinchart
2012-02-26  1:09     ` Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 26/33] omap3isp: Default link validation for ccp2, csi2, preview and resizer Sakari Ailus
2012-02-22 11:01   ` Laurent Pinchart
2012-02-25  1:34     ` Sakari Ailus
2012-02-26 23:14       ` Laurent Pinchart
2012-02-26 23:40         ` Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 27/33] omap3isp: Implement proper CCDC link validation, check pixel rate Sakari Ailus
2012-02-22 11:11   ` Laurent Pinchart
2012-02-25  1:42     ` Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 28/33] omap3isp: Move setting constaints above media_entity_pipeline_start Sakari Ailus
2012-02-22 11:12   ` Laurent Pinchart
2012-02-25  1:46     ` Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 29/33] omap3isp: Configure CSI-2 phy based on platform data Sakari Ailus
2012-02-22 11:21   ` Laurent Pinchart
2012-02-25  1:49     ` Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 30/33] omap3isp: Add resizer data rate configuration to resizer_set_stream Sakari Ailus
2012-02-22 11:24   ` Laurent Pinchart
2012-02-26  1:10     ` Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 31/33] omap3isp: Remove isp_validate_pipeline and other old stuff Sakari Ailus
2012-02-22 11:26   ` Laurent Pinchart
2012-02-25  1:52     ` Sakari Ailus
2012-02-20  1:57 ` [PATCH v3 32/33] smiapp: Add driver Sakari Ailus
2012-02-27 15:38   ` Laurent Pinchart
2012-02-29  5:41     ` Sakari Ailus
2012-02-29  9:35       ` Laurent Pinchart
2012-02-29 10:00         ` Sylwester Nawrocki
2012-03-01 14:01         ` Sakari Ailus
2012-03-01 14:56           ` Laurent Pinchart
2012-02-20  1:57 ` [PATCH v3 33/33] rm680: Add camera init Sakari Ailus
2012-02-27  1:06   ` Laurent Pinchart
2012-02-28 19:05     ` Sakari Ailus
2012-02-20  2:03 ` [PATCH v3 0/33] V4L2 subdev and sensor control changes, SMIA++ driver and N9 camera board code 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.