linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: linux-media@vger.kernel.org
Cc: Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>,
	Songjun Wu <songjun.wu@microchip.com>,
	Hans Verkuil <hans.verkuil@cisco.com>
Subject: [PATCH 05/15] ov7670: add devicetree support
Date: Mon, 12 Dec 2016 16:55:10 +0100	[thread overview]
Message-ID: <20161212155520.41375-6-hverkuil@xs4all.nl> (raw)
In-Reply-To: <20161212155520.41375-1-hverkuil@xs4all.nl>

From: Hans Verkuil <hans.verkuil@cisco.com>

Add DT support. Use it to get the reset and pwdn pins (if there are any).
Tested with one sensor requiring reset/pwdn and one sensor that doesn't
have reset/pwdn pins.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/ov7670.c | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index d2c0e23..1b06778 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -17,6 +17,8 @@
 #include <linux/i2c.h>
 #include <linux/delay.h>
 #include <linux/videodev2.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-mediabus.h>
@@ -232,6 +234,8 @@ struct ov7670_info {
 	};
 	struct ov7670_format_struct *fmt;  /* Current format */
 	struct clk *clk;
+	struct gpio_desc *resetb_gpio;
+	struct gpio_desc *pwdn_gpio;
 	int min_width;			/* Filter out smaller sizes */
 	int min_height;			/* Filter out smaller sizes */
 	int clock_speed;		/* External clock speed (MHz) */
@@ -594,8 +598,6 @@ static int ov7670_init(struct v4l2_subdev *sd, u32 val)
 	return ov7670_write_array(sd, ov7670_default_regs);
 }
 
-
-
 static int ov7670_detect(struct v4l2_subdev *sd)
 {
 	unsigned char v;
@@ -1552,6 +1554,29 @@ static const struct ov7670_devtype ov7670_devdata[] = {
 	},
 };
 
+static int ov7670_init_gpio(struct i2c_client *client, struct ov7670_info *info)
+{
+	/* Request the power down GPIO asserted */
+	info->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "pwdn",
+			GPIOD_OUT_LOW);
+	if (IS_ERR(info->pwdn_gpio)) {
+		dev_info(&client->dev, "can't get %s GPIO\n", "pwdn");
+		return PTR_ERR(info->pwdn_gpio);
+	}
+
+	/* Request the reset GPIO deasserted */
+	info->resetb_gpio = devm_gpiod_get_optional(&client->dev, "resetb",
+			GPIOD_OUT_LOW);
+	if (IS_ERR(info->resetb_gpio)) {
+		dev_info(&client->dev, "can't get %s GPIO\n", "resetb");
+		return PTR_ERR(info->resetb_gpio);
+	}
+
+	usleep_range(3000, 5000);
+
+	return 0;
+}
+
 static int ov7670_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -1597,7 +1622,7 @@ static int ov7670_probe(struct i2c_client *client,
 		return -EPROBE_DEFER;
 	clk_prepare_enable(info->clk);
 
-	ret = ov7670_probe_dt(client, info);
+	ret = ov7670_init_gpio(client, info);
 	if (ret)
 		goto clk_put;
 
@@ -1716,9 +1741,18 @@ static const struct i2c_device_id ov7670_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, ov7670_id);
 
+#if IS_ENABLED(CONFIG_OF)
+static const struct of_device_id ov7670_of_match[] = {
+	{ .compatible = "ovti,ov7670", },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, ov7670_of_match);
+#endif
+
 static struct i2c_driver ov7670_driver = {
 	.driver = {
 		.name	= "ov7670",
+		.of_match_table = of_match_ptr(ov7670_of_match),
 	},
 	.probe		= ov7670_probe,
 	.remove		= ov7670_remove,
-- 
2.10.2


  parent reply	other threads:[~2016-12-12 15:55 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
2016-12-12 15:55 ` Hans Verkuil [this message]
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=20161212155520.41375-6-hverkuil@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=guennadi.liakhovetski@intel.com \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-media@vger.kernel.org \
    --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).