1 From 34220db79008820c110473fe804cf02af3037889 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Thu, 18 May 2017 15:42:34 +0100
4 Subject: [PATCH 323/454] ov5647: Add support for PWDN GPIO.
6 Add support for an optional GPIO connected to PWDN on the sensor.
8 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
10 drivers/media/i2c/ov5647.c | 28 ++++++++++++++++++++++++++++
11 1 file changed, 28 insertions(+)
13 --- a/drivers/media/i2c/ov5647.c
14 +++ b/drivers/media/i2c/ov5647.c
17 #include <linux/clk.h>
18 #include <linux/delay.h>
19 +#include <linux/gpio/consumer.h>
20 #include <linux/i2c.h>
21 #include <linux/init.h>
25 #define SENSOR_NAME "ov5647"
28 + * From the datasheet, "20ms after PWDN goes low or 20ms after RESETB goes
29 + * high if reset is inserted after PWDN goes high, host can access sensor's
30 + * SCCB to initialize sensor."
32 +#define PWDN_ACTIVE_DELAY_MS 20
34 #define OV5647_SW_RESET 0x0103
35 #define OV5647_REG_CHIPID_H 0x300A
36 #define OV5647_REG_CHIPID_L 0x300B
37 @@ -77,6 +85,7 @@ struct ov5647 {
41 + struct gpio_desc *pwdn;
44 static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
45 @@ -334,6 +343,11 @@ static int ov5647_sensor_power(struct v4
46 if (on && !ov5647->power_count) {
47 dev_dbg(&client->dev, "OV5647 power on\n");
50 + gpiod_set_value(ov5647->pwdn, 0);
51 + msleep(PWDN_ACTIVE_DELAY_MS);
54 ret = clk_prepare_enable(ov5647->xclk);
56 dev_err(&client->dev, "clk prepare enable failed\n");
57 @@ -371,6 +385,8 @@ static int ov5647_sensor_power(struct v4
58 dev_dbg(&client->dev, "soft stby failed\n");
60 clk_disable_unprepare(ov5647->xclk);
62 + gpiod_set_value(ov5647->pwdn, 1);
65 /* Update the power count. */
66 @@ -583,6 +599,10 @@ static int ov5647_probe(struct i2c_clien
70 + /* Request the power down GPIO asserted */
71 + sensor->pwdn = devm_gpiod_get_optional(&client->dev, "pwdn",
74 mutex_init(&sensor->lock);
77 @@ -596,7 +616,15 @@ static int ov5647_probe(struct i2c_clien
82 + gpiod_set_value(sensor->pwdn, 0);
83 + msleep(PWDN_ACTIVE_DELAY_MS);
86 ret = ov5647_detect(sd);
88 + gpiod_set_value(sensor->pwdn, 1);