mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-27 17:18:59 +00:00
93 lines
2.4 KiB
Diff
93 lines
2.4 KiB
Diff
|
From 34220db79008820c110473fe804cf02af3037889 Mon Sep 17 00:00:00 2001
|
||
|
From: Dave Stevenson <dave.stevenson@raspberrypi.org>
|
||
|
Date: Thu, 18 May 2017 15:42:34 +0100
|
||
|
Subject: [PATCH 323/454] ov5647: Add support for PWDN GPIO.
|
||
|
|
||
|
Add support for an optional GPIO connected to PWDN on the sensor.
|
||
|
|
||
|
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
|
||
|
---
|
||
|
drivers/media/i2c/ov5647.c | 28 ++++++++++++++++++++++++++++
|
||
|
1 file changed, 28 insertions(+)
|
||
|
|
||
|
--- a/drivers/media/i2c/ov5647.c
|
||
|
+++ b/drivers/media/i2c/ov5647.c
|
||
|
@@ -21,6 +21,7 @@
|
||
|
|
||
|
#include <linux/clk.h>
|
||
|
#include <linux/delay.h>
|
||
|
+#include <linux/gpio/consumer.h>
|
||
|
#include <linux/i2c.h>
|
||
|
#include <linux/init.h>
|
||
|
#include <linux/io.h>
|
||
|
@@ -35,6 +36,13 @@
|
||
|
|
||
|
#define SENSOR_NAME "ov5647"
|
||
|
|
||
|
+/*
|
||
|
+ * From the datasheet, "20ms after PWDN goes low or 20ms after RESETB goes
|
||
|
+ * high if reset is inserted after PWDN goes high, host can access sensor's
|
||
|
+ * SCCB to initialize sensor."
|
||
|
+ */
|
||
|
+#define PWDN_ACTIVE_DELAY_MS 20
|
||
|
+
|
||
|
#define OV5647_SW_RESET 0x0103
|
||
|
#define OV5647_REG_CHIPID_H 0x300A
|
||
|
#define OV5647_REG_CHIPID_L 0x300B
|
||
|
@@ -77,6 +85,7 @@ struct ov5647 {
|
||
|
unsigned int height;
|
||
|
int power_count;
|
||
|
struct clk *xclk;
|
||
|
+ struct gpio_desc *pwdn;
|
||
|
};
|
||
|
|
||
|
static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
|
||
|
@@ -334,6 +343,11 @@ static int ov5647_sensor_power(struct v4
|
||
|
if (on && !ov5647->power_count) {
|
||
|
dev_dbg(&client->dev, "OV5647 power on\n");
|
||
|
|
||
|
+ if (ov5647->pwdn) {
|
||
|
+ gpiod_set_value(ov5647->pwdn, 0);
|
||
|
+ msleep(PWDN_ACTIVE_DELAY_MS);
|
||
|
+ }
|
||
|
+
|
||
|
ret = clk_prepare_enable(ov5647->xclk);
|
||
|
if (ret < 0) {
|
||
|
dev_err(&client->dev, "clk prepare enable failed\n");
|
||
|
@@ -371,6 +385,8 @@ static int ov5647_sensor_power(struct v4
|
||
|
dev_dbg(&client->dev, "soft stby failed\n");
|
||
|
|
||
|
clk_disable_unprepare(ov5647->xclk);
|
||
|
+
|
||
|
+ gpiod_set_value(ov5647->pwdn, 1);
|
||
|
}
|
||
|
|
||
|
/* Update the power count. */
|
||
|
@@ -583,6 +599,10 @@ static int ov5647_probe(struct i2c_clien
|
||
|
return -EINVAL;
|
||
|
}
|
||
|
|
||
|
+ /* Request the power down GPIO asserted */
|
||
|
+ sensor->pwdn = devm_gpiod_get_optional(&client->dev, "pwdn",
|
||
|
+ GPIOD_OUT_HIGH);
|
||
|
+
|
||
|
mutex_init(&sensor->lock);
|
||
|
|
||
|
sd = &sensor->sd;
|
||
|
@@ -596,7 +616,15 @@ static int ov5647_probe(struct i2c_clien
|
||
|
if (ret < 0)
|
||
|
goto mutex_remove;
|
||
|
|
||
|
+ if (sensor->pwdn) {
|
||
|
+ gpiod_set_value(sensor->pwdn, 0);
|
||
|
+ msleep(PWDN_ACTIVE_DELAY_MS);
|
||
|
+ }
|
||
|
+
|
||
|
ret = ov5647_detect(sd);
|
||
|
+
|
||
|
+ gpiod_set_value(sensor->pwdn, 1);
|
||
|
+
|
||
|
if (ret < 0)
|
||
|
goto error;
|
||
|
|