[v3,2/3] media: ov7670: Add the get_fmt callback

Message ID 20170918012928.13278-3-wenyou.yang@microchip.com (mailing list archive)
State Changes Requested, archived
Headers

Commit Message

Wenyou Yang Sept. 18, 2017, 1:29 a.m. UTC
  Add the get_fmt callback, also enable V4L2_SUBDEV_FL_HAS_DEVNODE flag
to make this subdev has device node.

Signed-off-by: Wenyou Yang <wenyou.yang@microchip.com>
---

Changes in v3:
 - Keep tried format info in the try_fmt member of
   v4l2_subdev__pad_config struct.
 - Add the internal_ops callback to set default format.

Changes in v2: None

 drivers/media/i2c/ov7670.c | 58 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)
  

Comments

kernel test robot Sept. 18, 2017, 3:57 a.m. UTC | #1
Hi Wenyou,

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.14-rc1 next-20170915]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Wenyou-Yang/media-ov7670-Add-entity-init-and-power-operation/20170918-093913
base:   git://linuxtv.org/media_tree.git master
config: i386-randconfig-x009-09180108 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All error/warnings (new ones prefixed by >>):

   drivers/media//i2c/ov7670.c: In function 'ov7670_set_fmt':
>> drivers/media//i2c/ov7670.c:1004:14: error: implicit declaration of function 'v4l2_subdev_get_try_format' [-Werror=implicit-function-declaration]
      mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/media//i2c/ov7670.c:1004:12: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
      mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
               ^
   drivers/media//i2c/ov7670.c: In function 'ov7670_get_fmt':
   drivers/media//i2c/ov7670.c:1056:12: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
      mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, 0);
               ^
   drivers/media//i2c/ov7670.c: In function 'ov7670_open':
>> drivers/media//i2c/ov7670.c:1547:38: error: 'struct v4l2_subdev_fh' has no member named 'pad'
        v4l2_subdev_get_try_format(sd, fh->pad, 0);
                                         ^~
   drivers/media//i2c/ov7670.c: In function 'ov7670_probe':
   drivers/media//i2c/ov7670.c:1750:10: error: 'struct v4l2_subdev' has no member named 'entity'
     info->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
             ^
   drivers/media//i2c/ov7670.c:1751:40: error: 'struct v4l2_subdev' has no member named 'entity'
     ret = media_entity_pads_init(&info->sd.entity, 1, &info->pad);
                                           ^
   drivers/media//i2c/ov7670.c:1764:32: error: 'struct v4l2_subdev' has no member named 'entity'
     media_entity_cleanup(&info->sd.entity);
                                   ^
   drivers/media//i2c/ov7670.c: In function 'ov7670_remove':
   drivers/media//i2c/ov7670.c:1781:32: error: 'struct v4l2_subdev' has no member named 'entity'
     media_entity_cleanup(&info->sd.entity);
                                   ^
   cc1: some warnings being treated as errors

vim +/v4l2_subdev_get_try_format +1004 drivers/media//i2c/ov7670.c

   982	
   983	/*
   984	 * Set a format.
   985	 */
   986	static int ov7670_set_fmt(struct v4l2_subdev *sd,
   987			struct v4l2_subdev_pad_config *cfg,
   988			struct v4l2_subdev_format *format)
   989	{
   990		struct ov7670_format_struct *ovfmt;
   991		struct ov7670_win_size *wsize;
   992		struct ov7670_info *info = to_state(sd);
   993		struct v4l2_mbus_framefmt *mbus_fmt;
   994		unsigned char com7;
   995		int ret;
   996	
   997		if (format->pad)
   998			return -EINVAL;
   999	
  1000		if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
  1001			ret = ov7670_try_fmt_internal(sd, &format->format, NULL, NULL);
  1002			if (ret)
  1003				return ret;
> 1004			mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
  1005			*mbus_fmt = format->format;
  1006			return 0;
  1007		}
  1008	
  1009		ret = ov7670_try_fmt_internal(sd, &format->format, &ovfmt, &wsize);
  1010	
  1011		if (ret)
  1012			return ret;
  1013		/*
  1014		 * COM7 is a pain in the ass, it doesn't like to be read then
  1015		 * quickly written afterward.  But we have everything we need
  1016		 * to set it absolutely here, as long as the format-specific
  1017		 * register sets list it first.
  1018		 */
  1019		com7 = ovfmt->regs[0].value;
  1020		com7 |= wsize->com7_bit;
  1021		ov7670_write(sd, REG_COM7, com7);
  1022		/*
  1023		 * Now write the rest of the array.  Also store start/stops
  1024		 */
  1025		ov7670_write_array(sd, ovfmt->regs + 1);
  1026		ov7670_set_hw(sd, wsize->hstart, wsize->hstop, wsize->vstart,
  1027				wsize->vstop);
  1028		ret = 0;
  1029		if (wsize->regs)
  1030			ret = ov7670_write_array(sd, wsize->regs);
  1031		info->fmt = ovfmt;
  1032	
  1033		/*
  1034		 * If we're running RGB565, we must rewrite clkrc after setting
  1035		 * the other parameters or the image looks poor.  If we're *not*
  1036		 * doing RGB565, we must not rewrite clkrc or the image looks
  1037		 * *really* poor.
  1038		 *
  1039		 * (Update) Now that we retain clkrc state, we should be able
  1040		 * to write it unconditionally, and that will make the frame
  1041		 * rate persistent too.
  1042		 */
  1043		if (ret == 0)
  1044			ret = ov7670_write(sd, REG_CLKRC, info->clkrc);
  1045		return 0;
  1046	}
  1047	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
  

Patch

diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index 5c8460ee65c3..5d6f1859a39b 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -230,6 +230,7 @@  struct ov7670_info {
 		struct v4l2_ctrl *saturation;
 		struct v4l2_ctrl *hue;
 	};
+	struct v4l2_mbus_framefmt format;
 	struct ov7670_format_struct *fmt;  /* Current format */
 	struct clk *clk;
 	struct gpio_desc *resetb_gpio;
@@ -973,6 +974,9 @@  static int ov7670_try_fmt_internal(struct v4l2_subdev *sd,
 	fmt->width = wsize->width;
 	fmt->height = wsize->height;
 	fmt->colorspace = ov7670_formats[index].colorspace;
+
+	info->format = *fmt;
+
 	return 0;
 }
 
@@ -986,6 +990,7 @@  static int ov7670_set_fmt(struct v4l2_subdev *sd,
 	struct ov7670_format_struct *ovfmt;
 	struct ov7670_win_size *wsize;
 	struct ov7670_info *info = to_state(sd);
+	struct v4l2_mbus_framefmt *mbus_fmt;
 	unsigned char com7;
 	int ret;
 
@@ -996,7 +1001,8 @@  static int ov7670_set_fmt(struct v4l2_subdev *sd,
 		ret = ov7670_try_fmt_internal(sd, &format->format, NULL, NULL);
 		if (ret)
 			return ret;
-		cfg->try_fmt = format->format;
+		mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
+		*mbus_fmt = format->format;
 		return 0;
 	}
 
@@ -1039,6 +1045,23 @@  static int ov7670_set_fmt(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int ov7670_get_fmt(struct v4l2_subdev *sd,
+			  struct v4l2_subdev_pad_config *cfg,
+			  struct v4l2_subdev_format *format)
+{
+	struct ov7670_info *info = to_state(sd);
+	struct v4l2_mbus_framefmt *mbus_fmt;
+
+	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
+		mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, 0);
+		format->format = *mbus_fmt;
+	} else {
+		format->format = info->format;
+	}
+
+	return 0;
+}
+
 /*
  * Implement G/S_PARM.  There is a "high quality" mode we could try
  * to do someday; for now, we just do the frame rate tweak.
@@ -1506,6 +1529,28 @@  static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regis
 }
 #endif
 
+static void ov7670_get_default_format(struct v4l2_subdev *sd,
+				      struct v4l2_mbus_framefmt *format)
+{
+	struct ov7670_info *info = to_state(sd);
+
+	format->width = info->devtype->win_sizes[0].width;
+	format->height = info->devtype->win_sizes[0].height;
+	format->colorspace = info->fmt->colorspace;
+	format->code = info->fmt->mbus_code;
+	format->field = V4L2_FIELD_NONE;
+}
+
+static int ov7670_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+	struct v4l2_mbus_framefmt *format =
+				v4l2_subdev_get_try_format(sd, fh->pad, 0);
+
+	ov7670_get_default_format(sd, format);
+
+	return 0;
+}
+
 /* ----------------------------------------------------------------------- */
 
 static const struct v4l2_subdev_core_ops ov7670_core_ops = {
@@ -1526,6 +1571,7 @@  static const struct v4l2_subdev_pad_ops ov7670_pad_ops = {
 	.enum_frame_interval = ov7670_enum_frame_interval,
 	.enum_frame_size = ov7670_enum_frame_size,
 	.enum_mbus_code = ov7670_enum_mbus_code,
+	.get_fmt = ov7670_get_fmt,
 	.set_fmt = ov7670_set_fmt,
 };
 
@@ -1535,6 +1581,10 @@  static const struct v4l2_subdev_ops ov7670_ops = {
 	.pad = &ov7670_pad_ops,
 };
 
+static const struct v4l2_subdev_internal_ops ov7670_subdev_internal_ops = {
+	.open = ov7670_open,
+};
+
 /* ----------------------------------------------------------------------- */
 
 static const struct ov7670_devtype ov7670_devdata[] = {
@@ -1587,6 +1637,9 @@  static int ov7670_probe(struct i2c_client *client,
 	sd = &info->sd;
 	v4l2_i2c_subdev_init(sd, client, &ov7670_ops);
 
+	sd->internal_ops = &ov7670_subdev_internal_ops;
+	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+
 	info->clock_speed = 30; /* default: a guess */
 	if (client->dev.platform_data) {
 		struct ov7670_config *config = client->dev.platform_data;
@@ -1643,6 +1696,9 @@  static int ov7670_probe(struct i2c_client *client,
 
 	info->devtype = &ov7670_devdata[id->driver_data];
 	info->fmt = &ov7670_formats[0];
+
+	ov7670_get_default_format(sd, &info->format);
+
 	info->clkrc = 0;
 
 	/* Set default frame rate to 30 fps */