Skip to content

Commit f10ec82

Browse files
Wenyou Yangehristev
authored andcommitted
media: ov7670: Add the ov7670_s_power function
Add the ov7670_s_power function which is responsible for manipulating the power dowm mode through the PWDN pin and the reset operation through the RESET pin, and keep it powered at all times. [sakari.ailus@linux.intel.com: set pwdn_gpio direction only once] Signed-off-by: Wenyou Yang <wenyou.yang@microchip.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
1 parent 251bad0 commit f10ec82

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

drivers/media/i2c/ov7670.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,22 @@ static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regis
15441544
}
15451545
#endif
15461546

1547+
static int ov7670_s_power(struct v4l2_subdev *sd, int on)
1548+
{
1549+
struct ov7670_info *info = to_state(sd);
1550+
1551+
if (info->pwdn_gpio)
1552+
gpiod_set_value(info->pwdn_gpio, !on);
1553+
if (on && info->resetb_gpio) {
1554+
gpiod_set_value(info->resetb_gpio, 1);
1555+
usleep_range(500, 1000);
1556+
gpiod_set_value(info->resetb_gpio, 0);
1557+
usleep_range(3000, 5000);
1558+
}
1559+
1560+
return 0;
1561+
}
1562+
15471563
static void ov7670_get_default_format(struct v4l2_subdev *sd,
15481564
struct v4l2_mbus_framefmt *format)
15491565
{
@@ -1694,23 +1710,25 @@ static int ov7670_probe(struct i2c_client *client,
16941710
if (ret)
16951711
return ret;
16961712

1697-
ret = ov7670_init_gpio(client, info);
1698-
if (ret)
1699-
goto clk_disable;
1700-
17011713
info->clock_speed = clk_get_rate(info->clk) / 1000000;
17021714
if (info->clock_speed < 10 || info->clock_speed > 48) {
17031715
ret = -EINVAL;
17041716
goto clk_disable;
17051717
}
17061718

1719+
ret = ov7670_init_gpio(client, info);
1720+
if (ret)
1721+
goto clk_disable;
1722+
1723+
ov7670_s_power(sd, 1);
1724+
17071725
/* Make sure it's an ov7670 */
17081726
ret = ov7670_detect(sd);
17091727
if (ret) {
17101728
v4l_dbg(1, debug, client,
17111729
"chip found @ 0x%x (%s) is not an ov7670 chip.\n",
17121730
client->addr << 1, client->adapter->name);
1713-
goto clk_disable;
1731+
goto power_off;
17141732
}
17151733
v4l_info(client, "chip found @ 0x%02x (%s)\n",
17161734
client->addr << 1, client->adapter->name);
@@ -1789,6 +1807,8 @@ static int ov7670_probe(struct i2c_client *client,
17891807
#endif
17901808
hdl_free:
17911809
v4l2_ctrl_handler_free(&info->hdl);
1810+
power_off:
1811+
ov7670_s_power(sd, 0);
17921812
clk_disable:
17931813
clk_disable_unprepare(info->clk);
17941814
return ret;
@@ -1806,6 +1826,7 @@ static int ov7670_remove(struct i2c_client *client)
18061826
#if defined(CONFIG_MEDIA_CONTROLLER)
18071827
media_entity_cleanup(&info->sd.entity);
18081828
#endif
1829+
ov7670_s_power(sd, 0);
18091830
return 0;
18101831
}
18111832

0 commit comments

Comments
 (0)