The read on in_illuminance_input keeps at 0 after system sleep.
So add proper suspend and resume callback to make the sensor keep
working after system sleep.
Signed-off-by: Kai-Heng Feng <[email protected]>
---
drivers/iio/light/cm32181.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c
index 97649944f1df6..e46bc6a54f199 100644
--- a/drivers/iio/light/cm32181.c
+++ b/drivers/iio/light/cm32181.c
@@ -460,6 +460,8 @@ static int cm32181_probe(struct i2c_client *client)
return PTR_ERR(client);
}
+ i2c_set_clientdata(client, indio_dev);
+
cm32181 = iio_priv(indio_dev);
cm32181->client = client;
cm32181->dev = dev;
@@ -486,6 +488,25 @@ static int cm32181_probe(struct i2c_client *client)
return 0;
}
+static int cm32181_suspend(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+
+ return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
+ CM32181_CMD_ALS_DISABLE);
+}
+
+static int cm32181_resume(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct cm32181_chip *cm32181 = iio_priv(i2c_get_clientdata(client));
+
+ return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
+ cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
+}
+
+DEFINE_SIMPLE_DEV_PM_OPS(cm32181_pm_ops, cm32181_suspend, cm32181_resume);
+
static const struct of_device_id cm32181_of_match[] = {
{ .compatible = "capella,cm3218" },
{ .compatible = "capella,cm32181" },
@@ -506,6 +527,7 @@ static struct i2c_driver cm32181_driver = {
.name = "cm32181",
.acpi_match_table = ACPI_PTR(cm32181_acpi_match),
.of_match_table = cm32181_of_match,
+ .pm = pm_sleep_ptr(&cm32181_pm_ops),
},
.probe_new = cm32181_probe,
};
--
2.36.1
On Tue, Jul 5, 2022 at 2:31 PM Kai-Heng Feng
<[email protected]> wrote:
>
> The read on in_illuminance_input keeps at 0 after system sleep.
>
> So add proper suspend and resume callback to make the sensor keep
> working after system sleep.
...
> +static int cm32181_resume(struct device *dev)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> + struct cm32181_chip *cm32181 = iio_priv(i2c_get_clientdata(client));
Simply device_get_drvdata(dev) ?
> + return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
> + cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
> +}
--
With Best Regards,
Andy Shevchenko
On Wed, Jul 6, 2022 at 3:12 AM Andy Shevchenko
<[email protected]> wrote:
>
> On Tue, Jul 5, 2022 at 2:31 PM Kai-Heng Feng
> <[email protected]> wrote:
> >
> > The read on in_illuminance_input keeps at 0 after system sleep.
> >
> > So add proper suspend and resume callback to make the sensor keep
> > working after system sleep.
>
> ...
>
> > +static int cm32181_resume(struct device *dev)
> > +{
> > + struct i2c_client *client = to_i2c_client(dev);
> > + struct cm32181_chip *cm32181 = iio_priv(i2c_get_clientdata(client));
>
> Simply device_get_drvdata(dev) ?
iio_priv() is still needed to get the struct priv.
Kai-Heng
>
> > + return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
> > + cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
> > +}
>
> --
> With Best Regards,
> Andy Shevchenko
On Wed, Jul 6, 2022 at 4:02 AM Kai-Heng Feng
<[email protected]> wrote:
> On Wed, Jul 6, 2022 at 3:12 AM Andy Shevchenko
> <[email protected]> wrote:
> > On Tue, Jul 5, 2022 at 2:31 PM Kai-Heng Feng
> > <[email protected]> wrote:
...
> > > +static int cm32181_resume(struct device *dev)
> > > +{
> > > + struct i2c_client *client = to_i2c_client(dev);
> > > + struct cm32181_chip *cm32181 = iio_priv(i2c_get_clientdata(client));
> >
> > Simply device_get_drvdata(dev) ?
>
> iio_priv() is still needed to get the struct priv.
I'm not objecting to that. My point is that you don't need to
dereference dev --> client --> dev.
And yes, I see that client is still used, but it's again not about my point.
> > > + return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
> > > + cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
> > > +}
--
With Best Regards,
Andy Shevchenko
On Wed, Jul 6, 2022 at 8:36 PM Andy Shevchenko
<[email protected]> wrote:
>
> On Wed, Jul 6, 2022 at 4:02 AM Kai-Heng Feng
> <[email protected]> wrote:
> > On Wed, Jul 6, 2022 at 3:12 AM Andy Shevchenko
> > <[email protected]> wrote:
> > > On Tue, Jul 5, 2022 at 2:31 PM Kai-Heng Feng
> > > <[email protected]> wrote:
>
> ...
>
> > > > +static int cm32181_resume(struct device *dev)
> > > > +{
> > > > + struct i2c_client *client = to_i2c_client(dev);
> > > > + struct cm32181_chip *cm32181 = iio_priv(i2c_get_clientdata(client));
> > >
> > > Simply device_get_drvdata(dev) ?
> >
> > iio_priv() is still needed to get the struct priv.
>
> I'm not objecting to that. My point is that you don't need to
> dereference dev --> client --> dev.
>
> And yes, I see that client is still used, but it's again not about my point.
You are right, let me send v2.
Kai-Heng
>
> > > > + return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
> > > > + cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
> > > > +}
>
> --
> With Best Regards,
> Andy Shevchenko