[J/OEM-5.14] [PATCH] iio: light: cm32181: Add PM support

Kai-Heng Feng kai.heng.feng at canonical.com
Thu Aug 4 12:24:27 UTC 2022


On Thu, Aug 4, 2022 at 8:15 PM Stefan Bader <stefan.bader at canonical.com> wrote:
>
> On 15.07.22 03:08, Kai-Heng Feng wrote:
> > BugLink: https://bugs.launchpad.net/bugs/1981773
> >
> > 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 <kai.heng.feng at canonical.com>
> > Link: https://lore.kernel.org/r/20220707000151.33381-1-kai.heng.feng@canonical.com
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron at huawei.com>
> > (backported from commit 68c1b3dd5c48b2323067f8c1f0649ae2f31ab20b linux-next)
> > [khfeng: Use #ifdef instead of backporting new PM macros]
> > Signed-off-by: Kai-Heng Feng <kai.heng.feng at canonical.com>
> > ---
> >   drivers/iio/light/cm32181.c | 24 ++++++++++++++++++++++++
> >   1 file changed, 24 insertions(+)
> >
> > diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c
> > index 97649944f1df6..3d52b8caf29a3 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,27 @@ static int cm32181_probe(struct i2c_client *client)
> >       return 0;
> >   }
> >
> > +#ifdef CONFIG_PM_SLEEP
> > +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(dev_get_drvdata(dev));
> > +
> > +     return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
> > +                                      cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
> > +}
> > +#endif
> > +
> > +SIMPLE_DEV_PM_OPS(cm32181_pm_ops, cm32181_suspend, cm32181_resume);
>
> Hm, does this not break when CONFIG_PM is not set? I think this needs an #else
> case which defines empty sudpend/resume handlers, no?

Commit 1a3c7bb08826 ("PM: core: Add new *_PM_OPS macros, deprecate old
ones"), which is included in v5.17, adds pm_sleep_ptr() and other
helpers to deprecate the usage #ifdef CONFIG_PM. So those #ifdef are
no longer needed for newer kernels.

The version for Jammy and OEM-5.14 still have #ifdef guard so they
won't break when CONFIG_PM is unset.

Kai-Heng

>
> -Stefan
>
> > +
> >   static const struct of_device_id cm32181_of_match[] = {
> >       { .compatible = "capella,cm3218" },
> >       { .compatible = "capella,cm32181" },
> > @@ -506,6 +529,7 @@ static struct i2c_driver cm32181_driver = {
> >               .name   = "cm32181",
> >               .acpi_match_table = ACPI_PTR(cm32181_acpi_match),
> >               .of_match_table = cm32181_of_match,
> > +             .pm = &cm32181_pm_ops,
> >       },
> >       .probe_new      = cm32181_probe,
> >   };
>



More information about the kernel-team mailing list