Skip to content

Commit

Permalink
media: media si2168: fully initialize si2168 on resume only when nece…
Browse files Browse the repository at this point in the history
…ssary

At connection time (or boot) in si2168_probe(), the firmware is not
loaded to the device and the device is not fully activated. It is
not useful or sensible to do this full initialization on resume in
case it has not been previously initialized and is expected to be
in this initialized state.
Calling si2168_init() and therefore reading the firmware file for
the first time during resume leads to problems and should be avoided.
It is however safe to read the firmware file once it has already been
read outside of a suspend/resume situation.

Add a staus flag 'initialized' to store whether si2168_init() has
successfully been called. If initialization fails (e.g. due to missing
firmware file), the flag is not set.
Register a separate si2168_resume callback which only calls
si2168_init() once the 'initialized' flag has been set and it is safe
to load the firmware at resume.
The first call to si2168_init() will now always happen when the device
is actually used for the first time and never during resume.
This avoids the unsafe firmware file reading and should also speed up
resume by skipping unnecessary device initialization.

Link: https://lore.kernel.org/linux-media/[email protected]

[mchehab: fix several Coding Style issues]
Cc: Antti Palosaari <[email protected]>
Signed-off-by: Lukas Middendorf <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
Lukas Middendorf authored and mchehab committed Nov 19, 2021
1 parent 40ae6ef commit 51c2664
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions drivers/media/dvb-frontends/si2168.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ static int si2168_init(struct dvb_frontend *fe)
goto err;

dev->warm = true;
dev->initialized = true;
warm:
/* Init stats here to indicate which stats are supported */
c->cnr.len = 1;
Expand All @@ -535,6 +536,26 @@ static int si2168_init(struct dvb_frontend *fe)
return ret;
}

static int si2168_resume(struct dvb_frontend *fe)
{
struct i2c_client *client = fe->demodulator_priv;
struct si2168_dev *dev = i2c_get_clientdata(client);

/*
* check whether si2168_init() has been called successfully
* outside of a resume cycle. Only call it (and load firmware)
* in this case. si2168_init() is only called during resume
* once the device has actually been used. Otherwise, leave the
* device untouched.
*/
if (dev->initialized) {
dev_dbg(&client->dev, "previsously initialized, call si2168_init()\n");
return si2168_init(fe);
}
dev_dbg(&client->dev, "not initialized yet, skipping init on resume\n");
return 0;
}

static int si2168_sleep(struct dvb_frontend *fe)
{
struct i2c_client *client = fe->demodulator_priv;
Expand Down Expand Up @@ -644,6 +665,7 @@ static const struct dvb_frontend_ops si2168_ops = {

.init = si2168_init,
.sleep = si2168_sleep,
.resume = si2168_resume,

.set_frontend = si2168_set_frontend,

Expand Down
1 change: 1 addition & 0 deletions drivers/media/dvb-frontends/si2168_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct si2168_dev {
u8 ts_mode;
unsigned int active:1;
unsigned int warm:1;
unsigned int initialized:1;
unsigned int ts_clock_inv:1;
unsigned int ts_clock_gapped:1;
unsigned int spectral_inversion:1;
Expand Down

0 comments on commit 51c2664

Please sign in to comment.