Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit edd75ede authored by Jonathan Corbet's avatar Jonathan Corbet Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (5691): Ov7670: reset clkrc in rgb565 mode



A bug in the ov7670 sensor causes it to introduce noise unless the CLKRC
register is rewritten *after* setting the image mode.  Naturally,
resetting CLKRC in this way will cause other modes to fail.  So
carefully poke the register only when indicated.

Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 7acf90c7
Loading
Loading
Loading
Loading
+18 −3
Original line number Original line Diff line number Diff line
@@ -720,11 +720,21 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt)
	struct ov7670_format_struct *ovfmt;
	struct ov7670_format_struct *ovfmt;
	struct ov7670_win_size *wsize;
	struct ov7670_win_size *wsize;
	struct ov7670_info *info = i2c_get_clientdata(c);
	struct ov7670_info *info = i2c_get_clientdata(c);
	unsigned char com7;
	unsigned char com7, clkrc;


	ret = ov7670_try_fmt(c, fmt, &ovfmt, &wsize);
	ret = ov7670_try_fmt(c, fmt, &ovfmt, &wsize);
	if (ret)
	if (ret)
		return ret;
		return ret;
	/*
	 * HACK: if we're running rgb565 we need to grab then rewrite
	 * CLKRC.  If we're *not*, however, then rewriting clkrc hoses
	 * the colors.
	 */
	if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565) {
		ret = ov7670_read(c, REG_CLKRC, &clkrc);
		if (ret)
			return ret;
	}
	/*
	/*
	 * COM7 is a pain in the ass, it doesn't like to be read then
	 * COM7 is a pain in the ass, it doesn't like to be read then
	 * quickly written afterward.  But we have everything we need
	 * quickly written afterward.  But we have everything we need
@@ -744,7 +754,10 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt)
	if (wsize->regs)
	if (wsize->regs)
		ret = ov7670_write_array(c, wsize->regs);
		ret = ov7670_write_array(c, wsize->regs);
	info->fmt = ovfmt;
	info->fmt = ovfmt;
	return 0;

	if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565 && ret == 0)
		ret = ov7670_write(c, REG_CLKRC, clkrc);
	return ret;
}
}


/*
/*
@@ -1267,7 +1280,9 @@ static int ov7670_attach(struct i2c_adapter *adapter)
	ret = ov7670_detect(client);
	ret = ov7670_detect(client);
	if (ret)
	if (ret)
		goto out_free_info;
		goto out_free_info;
	i2c_attach_client(client);
	ret = i2c_attach_client(client);
	if (ret)
		goto out_free_info;
	return 0;
	return 0;


  out_free_info:
  out_free_info: