From: Josh Wu <josh.wu-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
To: linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: m.chehab-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
g.liakhovetski-Mmb7MZpHnFY@public.gmane.org,
laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org,
Josh Wu <josh.wu-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 2/4] media: ov2640: add primary dt support
Date: Fri, 28 Nov 2014 18:28:25 +0800 [thread overview]
Message-ID: <1417170507-11172-3-git-send-email-josh.wu@atmel.com> (raw)
In-Reply-To: <1417170507-11172-1-git-send-email-josh.wu-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
Add device tree support for ov2640.
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Josh Wu <josh.wu-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
---
drivers/media/i2c/soc_camera/ov2640.c | 95 ++++++++++++++++++++++++++++++++---
1 file changed, 89 insertions(+), 6 deletions(-)
diff --git a/drivers/media/i2c/soc_camera/ov2640.c b/drivers/media/i2c/soc_camera/ov2640.c
index 9ee910d..6506126 100644
--- a/drivers/media/i2c/soc_camera/ov2640.c
+++ b/drivers/media/i2c/soc_camera/ov2640.c
@@ -18,6 +18,8 @@
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
#include <linux/v4l2-mediabus.h>
#include <linux/videodev2.h>
@@ -283,6 +285,10 @@ struct ov2640_priv {
u32 cfmt_code;
struct v4l2_clk *clk;
const struct ov2640_win_size *win;
+
+ struct soc_camera_subdev_desc ssdd_dt;
+ int reset_pin;
+ int pwr_down_pin;
};
/*
@@ -1047,6 +1053,70 @@ static struct v4l2_subdev_ops ov2640_subdev_ops = {
.video = &ov2640_subdev_video_ops,
};
+/* OF probe functions */
+static int ov2640_hw_power(struct device *dev, int on)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct ov2640_priv *priv = to_ov2640(client);
+
+ dev_dbg(&client->dev, "%s: %s the camera\n",
+ __func__, on ? "ENABLE" : "DISABLE");
+
+ /* enable or disable the camera */
+ gpio_direction_output(priv->pwr_down_pin, !on);
+
+ return 0;
+}
+
+static int ov2640_hw_reset(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct ov2640_priv *priv = to_ov2640(client);
+
+ /* If enabled, give a reset impulse */
+ gpio_direction_output(priv->reset_pin, 0);
+ msleep(20);
+ gpio_direction_output(priv->reset_pin, 1);
+ msleep(100);
+
+ return 0;
+}
+
+static int ov2640_probe_dt(struct i2c_client *client,
+ struct ov2640_priv *priv)
+{
+ struct device_node *np = client->dev.of_node;
+ int ret;
+
+ priv->reset_pin = of_get_named_gpio(np, "reset-gpio", 0);
+ priv->pwr_down_pin = of_get_named_gpio(np, "power-down-gpio", 0);
+ if (!gpio_is_valid(priv->reset_pin) ||
+ !gpio_is_valid(priv->pwr_down_pin))
+ return -EINVAL;
+
+ ret = devm_gpio_request(&client->dev, priv->pwr_down_pin,
+ "power-down-pin");
+ if (ret < 0) {
+ dev_err(&client->dev, "request gpio pin %d failed\n",
+ priv->pwr_down_pin);
+ return ret;
+ }
+
+ ret = devm_gpio_request(&client->dev, priv->reset_pin, "reset_pin");
+ if (ret < 0) {
+ dev_err(&client->dev, "request gpio pin %d failed\n",
+ priv->reset_pin);
+ return ret;
+ }
+
+ /* Initialize the soc_camera_subdev_desc */
+ priv->ssdd_dt.power = ov2640_hw_power;
+ priv->ssdd_dt.reset = ov2640_hw_reset;
+ client->dev.platform_data = &priv->ssdd_dt;
+
+ return 0;
+}
+
/*
* i2c_driver functions
*/
@@ -1058,12 +1128,6 @@ static int ov2640_probe(struct i2c_client *client,
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
int ret;
- if (!ssdd) {
- dev_err(&adapter->dev,
- "OV2640: Missing platform_data for driver\n");
- return -EINVAL;
- }
-
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_err(&adapter->dev,
"OV2640: I2C-Adapter doesn't support SMBUS\n");
@@ -1077,6 +1141,18 @@ static int ov2640_probe(struct i2c_client *client,
return -ENOMEM;
}
+ if (!ssdd) {
+ if (client->dev.of_node) {
+ ret = ov2640_probe_dt(client, priv);
+ if (ret)
+ return ret;
+ } else {
+ dev_err(&client->dev,
+ "Missing platform_data for driver\n");
+ return -EINVAL;
+ }
+ }
+
v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops);
v4l2_ctrl_handler_init(&priv->hdl, 2);
v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
@@ -1123,9 +1199,16 @@ static const struct i2c_device_id ov2640_id[] = {
};
MODULE_DEVICE_TABLE(i2c, ov2640_id);
+static const struct of_device_id ov2640_of_match[] = {
+ {.compatible = "omnivision,ov2640", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, ov2640_of_match);
+
static struct i2c_driver ov2640_i2c_driver = {
.driver = {
.name = "ov2640",
+ .of_match_table = of_match_ptr(ov2640_of_match),
},
.probe = ov2640_probe,
.remove = ov2640_remove,
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next parent reply other threads:[~2014-11-28 10:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1417170507-11172-1-git-send-email-josh.wu@atmel.com>
[not found] ` <1417170507-11172-1-git-send-email-josh.wu-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
2014-11-28 10:28 ` Josh Wu [this message]
2014-12-01 22:33 ` [PATCH 2/4] media: ov2640: add primary dt support Laurent Pinchart
2014-12-05 10:17 ` Josh Wu
2014-11-28 10:28 ` [PATCH 4/4] media: ov2640: dt: add the device tree binding document Josh Wu
2014-12-01 22:14 ` Laurent Pinchart
2014-12-03 9:49 ` Josh Wu
[not found] ` <1417170507-11172-4-git-send-email-josh.wu@atmel.com>
2014-12-01 22:26 ` [PATCH 3/4] media: ov2640: add a master clock for sensor Laurent Pinchart
2014-12-03 9:54 ` Josh Wu
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=1417170507-11172-3-git-send-email-josh.wu@atmel.com \
--to=josh.wu-aife0yeh4naavxtiumwx3w@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=g.liakhovetski-Mmb7MZpHnFY@public.gmane.org \
--cc=laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=m.chehab-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
/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).