Skip to content

Commit

Permalink
iio: light: cm32181: Add PM support
Browse files Browse the repository at this point in the history
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@canonical.com>
Link: https://lore.kernel.org/r/20220707000151.33381-1-kai.heng.feng@canonical.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
  • Loading branch information
Kai-Heng Feng authored and Jonathan Cameron committed Jul 7, 2022
1 parent bca036d commit 68c1b3d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions drivers/iio/light/cm32181.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(dev_get_drvdata(dev));

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" },
Expand All @@ -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,
};
Expand Down

0 comments on commit 68c1b3d

Please sign in to comment.