linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: linux-media@vger.kernel.org,
	Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>,
	Songjun Wu <songjun.wu@microchip.com>,
	Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [PATCH 04/15] ov7670: get xclk
Date: Mon, 2 Jan 2017 14:18:08 +0100	[thread overview]
Message-ID: <023d8199-395c-c646-7dc2-a789e6009679@xs4all.nl> (raw)
In-Reply-To: <20161218221520.GX16630@valkosipuli.retiisi.org.uk>

On 12/18/16 23:15, Sakari Ailus wrote:
> Hi Hans,
>
> On Mon, Dec 12, 2016 at 04:55:09PM +0100, Hans Verkuil wrote:
>> From: Hans Verkuil <hans.verkuil@cisco.com>
>>
>> Get the clock for this sensor.
>>
>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
>> ---
>>  drivers/media/i2c/ov7670.c | 35 ++++++++++++++++++++++++++++-------
>>  1 file changed, 28 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
>> index 35b09d2..d2c0e23 100644
>> --- a/drivers/media/i2c/ov7670.c
>> +++ b/drivers/media/i2c/ov7670.c
>> @@ -10,6 +10,7 @@
>>   * This file may be distributed under the terms of the GNU General
>>   * Public License, version 2.
>>   */
>> +#include <linux/clk.h>
>>  #include <linux/init.h>
>>  #include <linux/module.h>
>>  #include <linux/slab.h>
>> @@ -230,6 +231,7 @@ struct ov7670_info {
>>  		struct v4l2_ctrl *hue;
>>  	};
>>  	struct ov7670_format_struct *fmt;  /* Current format */
>> +	struct clk *clk;
>>  	int min_width;			/* Filter out smaller sizes */
>>  	int min_height;			/* Filter out smaller sizes */
>>  	int clock_speed;		/* External clock speed (MHz) */
>> @@ -1590,13 +1592,28 @@ static int ov7670_probe(struct i2c_client *client,
>>  			info->pclk_hb_disable = true;
>>  	}
>>
>> +	info->clk = clk_get(&client->dev, "xclk");
>> +	if (IS_ERR(info->clk))
>> +		return -EPROBE_DEFER;
>
> How about devm_clk_get() instead? I think there's nothing wrong in using
> devm.*() here as it's not memory.

True. Changed to devm_clk_get.

>
>> +	clk_prepare_enable(info->clk);
>> +
>> +	ret = ov7670_probe_dt(client, info);
>> +	if (ret)
>> +		goto clk_put;
>> +
>> +	info->clock_speed = clk_get_rate(info->clk) / 1000000;
>> +	if (info->clock_speed < 12 || info->clock_speed > 48) {
>
> What's the clock expected to be? I don't know the sensor but all sensors
> I've seen do derive their internal clocks from the one provided to the
> sensor, meaning that any frequency would be directly related to this one. As
> the sensor driver makes no effort in programming the PLL according to the
> input clock, I bet the register lists used assume a certain frequency
> instead. Shouldn't you check instead you're getting exactly that frequency?

All the datasheet says is that the clock is expected to be between 10 and 48 MHz
with 24 MHz as the recommended frequency. So the < 12 should be < 10.

Of course, if the given clock is slower, then the framerate will be correspondingly
slower as well.

All this test does is to check that the given clock is within the spec.

Regards,

	Hans

>
>> +		ret = -EINVAL;
>> +		goto clk_put;
>> +	}
>> +
>>  	/* Make sure it's an ov7670 */
>>  	ret = ov7670_detect(sd);
>>  	if (ret) {
>>  		v4l_dbg(1, debug, client,
>>  			"chip found @ 0x%x (%s) is not an ov7670 chip.\n",
>>  			client->addr << 1, client->adapter->name);
>> -		return ret;
>> +		goto clk_put;
>>  	}
>>  	v4l_info(client, "chip found @ 0x%02x (%s)\n",
>>  			client->addr << 1, client->adapter->name);
>> @@ -1637,9 +1654,8 @@ static int ov7670_probe(struct i2c_client *client,
>>  			V4L2_EXPOSURE_AUTO);
>>  	sd->ctrl_handler = &info->hdl;
>>  	if (info->hdl.error) {
>> -		int err = info->hdl.error;
>> -
>> -		goto fail;
>> +		ret = info->hdl.error;
>> +		goto hdl_free;
>>  	}
>>
>>  #if defined(CONFIG_MEDIA_CONTROLLER)
>> @@ -1647,7 +1663,7 @@ static int ov7670_probe(struct i2c_client *client,
>>  	info->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
>>  	ret = media_entity_pads_init(&info->sd.entity, 1, &info->pad);
>>  	if (ret < 0)
>> -		goto fail;
>> +		goto hdl_free;
>>  #endif
>>  	/*
>>  	 * We have checked empirically that hw allows to read back the gain
>> @@ -1664,13 +1680,16 @@ static int ov7670_probe(struct i2c_client *client,
>>  #if defined(CONFIG_MEDIA_CONTROLLER)
>>  		media_entity_cleanup(&info->sd.entity);
>>  #endif
>> -		goto fail;
>> +		goto hdl_free;
>>  	}
>>
>>  	return 0;
>>
>> -fail:
>> +hdl_free:
>>  	v4l2_ctrl_handler_free(&info->hdl);
>> +clk_put:
>> +	clk_disable_unprepare(info->clk);
>> +	clk_put(info->clk);
>>  	return ret;
>>  }
>>
>> @@ -1685,6 +1704,8 @@ static int ov7670_remove(struct i2c_client *client)
>>  #if defined(CONFIG_MEDIA_CONTROLLER)
>>  	media_entity_cleanup(&sd->entity);
>>  #endif
>> +	clk_disable_unprepare(info->clk);
>> +	clk_put(info->clk);
>>  	return 0;
>>  }
>>
>


  reply	other threads:[~2017-01-02 13:18 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-12 15:55 [PATCH 00/15] atmel-isi/ov7670/ov2640: convert to standalone drivers Hans Verkuil
2016-12-12 15:55 ` [PATCH 01/15] ov7670: add media controller support Hans Verkuil
2016-12-18 22:07   ` Sakari Ailus
2016-12-12 15:55 ` [PATCH 02/15] ov7670: call v4l2_async_register_subdev Hans Verkuil
2016-12-18 22:08   ` Sakari Ailus
2017-01-02 13:09     ` Hans Verkuil
2016-12-12 15:55 ` [PATCH 03/15] ov7670: fix g/s_parm Hans Verkuil
2016-12-12 15:55 ` [PATCH 04/15] ov7670: get xclk Hans Verkuil
2016-12-18 22:15   ` Sakari Ailus
2017-01-02 13:18     ` Hans Verkuil [this message]
2016-12-12 15:55 ` [PATCH 05/15] ov7670: add devicetree support Hans Verkuil
2016-12-12 15:55 ` [PATCH 06/15] ov7670: document device tree bindings Hans Verkuil
2016-12-12 15:55 ` [PATCH 07/15] atmel-isi: remove dependency of the soc-camera framework Hans Verkuil
2016-12-12 15:55 ` [PATCH 08/15] atmel-isi: move out of soc_camera to atmel Hans Verkuil
2016-12-12 15:55 ` [PATCH 09/15] atmel-isi: document device tree bindings Hans Verkuil
2016-12-12 15:55 ` [PATCH 10/15] ov2640: convert from soc-camera to a standard subdev sensor driver Hans Verkuil
2016-12-12 15:55 ` [PATCH 11/15] ov2640: enable clock, fix power/reset and add MC support Hans Verkuil
2016-12-12 15:55 ` [PATCH 12/15] ov2640 bindings update Hans Verkuil
2016-12-12 15:55 ` [PATCH 13/15] em28xx: drop last soc_camera link Hans Verkuil
2016-12-12 15:55 ` [PATCH 14/15] sama5d3 dts: enable atmel-isi Hans Verkuil
2016-12-12 15:55 ` [PATCH 15/15] at91-sama5d3_xplained.dts: select ov2640 Hans Verkuil
2016-12-18 22:10 ` [PATCH 00/15] atmel-isi/ov7670/ov2640: convert to standalone drivers Sakari Ailus
2017-01-02 13:37   ` Hans Verkuil
2017-01-02 13:41     ` Hans Verkuil
2017-01-02 21:09       ` Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=023d8199-395c-c646-7dc2-a789e6009679@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=guennadi.liakhovetski@intel.com \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-media@vger.kernel.org \
    --cc=sakari.ailus@iki.fi \
    --cc=songjun.wu@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).