Commit c5fafbad authored by Hans de Goede's avatar Hans de Goede Committed by Mauro Carvalho Chehab

media: atomisp: gc0310: Power on sensor from set_fmt() callback

Depending on which order userspace makes various v4l2 calls, the sensor
might still be powered down when set_fmt is called.

What should really happen here is delay the writing of the mode-related
registers till streaming is started, but for now use the same quick fix
as the atomisp_ov2680 code and call power_up() from set_fmt() in
combination with keeping track of the power-state to avoid doing the
power-up sequence twice.
Reviewed-by: default avatarAndy Shevchenko <andy@kernel.org>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent eb314d87
...@@ -786,8 +786,6 @@ static int gpio_ctrl(struct v4l2_subdev *sd, bool flag) ...@@ -786,8 +786,6 @@ static int gpio_ctrl(struct v4l2_subdev *sd, bool flag)
return ret; return ret;
} }
static int power_down(struct v4l2_subdev *sd);
static int power_up(struct v4l2_subdev *sd) static int power_up(struct v4l2_subdev *sd)
{ {
struct gc0310_device *dev = to_gc0310_sensor(sd); struct gc0310_device *dev = to_gc0310_sensor(sd);
...@@ -800,6 +798,9 @@ static int power_up(struct v4l2_subdev *sd) ...@@ -800,6 +798,9 @@ static int power_up(struct v4l2_subdev *sd)
return -ENODEV; return -ENODEV;
} }
if (dev->power_on)
return 0; /* Already on */
/* power control */ /* power control */
ret = power_ctrl(sd, 1); ret = power_ctrl(sd, 1);
if (ret) if (ret)
...@@ -820,6 +821,7 @@ static int power_up(struct v4l2_subdev *sd) ...@@ -820,6 +821,7 @@ static int power_up(struct v4l2_subdev *sd)
msleep(100); msleep(100);
dev->power_on = true;
return 0; return 0;
fail_gpio: fail_gpio:
...@@ -844,6 +846,9 @@ static int power_down(struct v4l2_subdev *sd) ...@@ -844,6 +846,9 @@ static int power_down(struct v4l2_subdev *sd)
return -ENODEV; return -ENODEV;
} }
if (!dev->power_on)
return 0; /* Already off */
/* gpio ctrl */ /* gpio ctrl */
ret = gpio_ctrl(sd, 0); ret = gpio_ctrl(sd, 0);
if (ret) { if (ret) {
...@@ -861,6 +866,7 @@ static int power_down(struct v4l2_subdev *sd) ...@@ -861,6 +866,7 @@ static int power_down(struct v4l2_subdev *sd)
if (ret) if (ret)
dev_err(&client->dev, "vprog failed.\n"); dev_err(&client->dev, "vprog failed.\n");
dev->power_on = false;
return ret; return ret;
} }
...@@ -935,6 +941,9 @@ static int gc0310_set_fmt(struct v4l2_subdev *sd, ...@@ -935,6 +941,9 @@ static int gc0310_set_fmt(struct v4l2_subdev *sd,
return 0; return 0;
} }
/* s_power has not been called yet for std v4l2 clients (camorama) */
power_up(sd);
dev_dbg(&client->dev, "%s: before gc0310_write_reg_array %s\n", dev_dbg(&client->dev, "%s: before gc0310_write_reg_array %s\n",
__func__, dev->res->desc); __func__, dev->res->desc);
ret = startup(sd); ret = startup(sd);
...@@ -1073,6 +1082,7 @@ static int gc0310_s_config(struct v4l2_subdev *sd, ...@@ -1073,6 +1082,7 @@ static int gc0310_s_config(struct v4l2_subdev *sd,
* as first power on by board may not fulfill the * as first power on by board may not fulfill the
* power on sequqence needed by the module * power on sequqence needed by the module
*/ */
dev->power_on = true; /* force power_down() to run */
ret = power_down(sd); ret = power_down(sd);
if (ret) { if (ret) {
dev_err(&client->dev, "gc0310 power-off err.\n"); dev_err(&client->dev, "gc0310 power-off err.\n");
......
...@@ -152,6 +152,7 @@ struct gc0310_device { ...@@ -152,6 +152,7 @@ struct gc0310_device {
int vt_pix_clk_freq_mhz; int vt_pix_clk_freq_mhz;
struct gc0310_resolution *res; struct gc0310_resolution *res;
u8 type; u8 type;
bool power_on;
}; };
enum gc0310_tok_type { enum gc0310_tok_type {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment