Skip to content

Commit bfea948

Browse files
valpackettTravMurav
authored andcommitted
UPSTREAM: media: i2c: dw9719: Fix power on/off sequence
The "jiggle" code was not actually expecting failure, which it should because that's what actually happens when the device wasn't already woken up by the regulator power-on (i.e. in the case of a shared regulator). Also, do actually enter the internal suspend mode on shutdown, to save power in the case of a shared regulator. Also, wait a bit longer (2x tOPR) on waking up, 1x is not enough at least on the DW9718S as found on the motorola-nora smartphone. Signed-off-by: Val Packett <val@packett.cool> Signed-off-by: André Apitzsch <git@apitzsch.eu> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
1 parent c512fed commit bfea948

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

drivers/media/i2c/dw9719.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,20 @@ struct dw9719_device {
9595

9696
static int dw9719_power_down(struct dw9719_device *dw9719)
9797
{
98+
u32 reg_pwr = dw9719->model == DW9718S ? DW9718S_PD : DW9719_CONTROL;
99+
100+
/*
101+
* Worth engaging the internal SHUTDOWN mode especially due to the
102+
* regulator being potentially shared with other devices.
103+
*/
104+
if (cci_write(dw9719->regmap, reg_pwr, DW9719_SHUTDOWN, NULL))
105+
dev_err(dw9719->dev, "Error writing to power register\n");
98106
return regulator_disable(dw9719->regulator);
99107
}
100108

101109
static int dw9719_power_up(struct dw9719_device *dw9719, bool detect)
102110
{
103-
u32 reg_pwr;
111+
u32 reg_pwr = dw9719->model == DW9718S ? DW9718S_PD : DW9719_CONTROL;
104112
u64 val;
105113
int ret;
106114
int err;
@@ -109,13 +117,17 @@ static int dw9719_power_up(struct dw9719_device *dw9719, bool detect)
109117
if (ret)
110118
return ret;
111119

112-
/* Jiggle SCL pin to wake up device */
113-
reg_pwr = dw9719->model == DW9718S ? DW9718S_PD : DW9719_CONTROL;
114-
cci_write(dw9719->regmap, reg_pwr, DW9719_SHUTDOWN, &ret);
115-
fsleep(100);
120+
/*
121+
* Need 100us to transition from SHUTDOWN to STANDBY.
122+
* Jiggle the SCL pin to wake up the device (even when the regulator is
123+
* shared) and wait double the time to be sure, as 100us is not enough
124+
* at least on the DW9718S as found on the motorola-nora smartphone,
125+
* then retry the write.
126+
*/
127+
cci_write(dw9719->regmap, reg_pwr, DW9719_STANDBY, NULL);
128+
/* the jiggle is expected to fail, don't even log that as error */
129+
fsleep(200);
116130
cci_write(dw9719->regmap, reg_pwr, DW9719_STANDBY, &ret);
117-
/* Need 100us to transit from SHUTDOWN to STANDBY */
118-
fsleep(100);
119131

120132
if (detect) {
121133
/* This model does not have an INFO register */

0 commit comments

Comments
 (0)