Commit 0a024d63 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] ov7670: get xclk

Get the clock for this sensor.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent d569e90b
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
* This file may be distributed under the terms of the GNU General * This file may be distributed under the terms of the GNU General
* Public License, version 2. * Public License, version 2.
*/ */
#include <linux/clk.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -227,6 +228,7 @@ struct ov7670_info { ...@@ -227,6 +228,7 @@ struct ov7670_info {
struct v4l2_ctrl *hue; struct v4l2_ctrl *hue;
}; };
struct ov7670_format_struct *fmt; /* Current format */ struct ov7670_format_struct *fmt; /* Current format */
struct clk *clk;
int min_width; /* Filter out smaller sizes */ int min_width; /* Filter out smaller sizes */
int min_height; /* Filter out smaller sizes */ int min_height; /* Filter out smaller sizes */
int clock_speed; /* External clock speed (MHz) */ int clock_speed; /* External clock speed (MHz) */
...@@ -1587,13 +1589,24 @@ static int ov7670_probe(struct i2c_client *client, ...@@ -1587,13 +1589,24 @@ static int ov7670_probe(struct i2c_client *client,
info->pclk_hb_disable = true; info->pclk_hb_disable = true;
} }
info->clk = devm_clk_get(&client->dev, "xclk");
if (IS_ERR(info->clk))
return -EPROBE_DEFER;
clk_prepare_enable(info->clk);
info->clock_speed = clk_get_rate(info->clk) / 1000000;
if (info->clock_speed < 10 || info->clock_speed > 48) {
ret = -EINVAL;
goto clk_disable;
}
/* Make sure it's an ov7670 */ /* Make sure it's an ov7670 */
ret = ov7670_detect(sd); ret = ov7670_detect(sd);
if (ret) { if (ret) {
v4l_dbg(1, debug, client, v4l_dbg(1, debug, client,
"chip found @ 0x%x (%s) is not an ov7670 chip.\n", "chip found @ 0x%x (%s) is not an ov7670 chip.\n",
client->addr << 1, client->adapter->name); client->addr << 1, client->adapter->name);
return ret; goto clk_disable;
} }
v4l_info(client, "chip found @ 0x%02x (%s)\n", v4l_info(client, "chip found @ 0x%02x (%s)\n",
client->addr << 1, client->adapter->name); client->addr << 1, client->adapter->name);
...@@ -1656,6 +1669,8 @@ static int ov7670_probe(struct i2c_client *client, ...@@ -1656,6 +1669,8 @@ static int ov7670_probe(struct i2c_client *client,
hdl_free: hdl_free:
v4l2_ctrl_handler_free(&info->hdl); v4l2_ctrl_handler_free(&info->hdl);
clk_disable:
clk_disable_unprepare(info->clk);
return ret; return ret;
} }
...@@ -1667,6 +1682,7 @@ static int ov7670_remove(struct i2c_client *client) ...@@ -1667,6 +1682,7 @@ static int ov7670_remove(struct i2c_client *client)
v4l2_device_unregister_subdev(sd); v4l2_device_unregister_subdev(sd);
v4l2_ctrl_handler_free(&info->hdl); v4l2_ctrl_handler_free(&info->hdl);
clk_disable_unprepare(info->clk);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment