Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: magnetometer: mmc35240: Add PM sleep support

We rely on regmap to save the state of the registers at suspend,
and then we do an explicit sync at resume.

Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Daniel Baluta and committed by
Jonathan Cameron
553a776b abeb6b1e

+35
+35
drivers/iio/magnetometer/mmc35240.c
··· 17 17 #include <linux/i2c.h> 18 18 #include <linux/delay.h> 19 19 #include <linux/regmap.h> 20 + #include <linux/pm.h> 20 21 21 22 #include <linux/iio/iio.h> 22 23 #include <linux/iio/sysfs.h> ··· 449 448 return devm_iio_device_register(&client->dev, indio_dev); 450 449 } 451 450 451 + #ifdef CONFIG_PM_SLEEP 452 + static int mmc35240_suspend(struct device *dev) 453 + { 454 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 455 + struct mmc35240_data *data = iio_priv(indio_dev); 456 + 457 + regcache_cache_only(data->regmap, true); 458 + 459 + return 0; 460 + } 461 + 462 + static int mmc35240_resume(struct device *dev) 463 + { 464 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 465 + struct mmc35240_data *data = iio_priv(indio_dev); 466 + int ret; 467 + 468 + regcache_mark_dirty(data->regmap); 469 + ret = regcache_sync_region(data->regmap, MMC35240_REG_CTRL0, 470 + MMC35240_REG_CTRL1); 471 + if (ret < 0) 472 + dev_err(dev, "Failed to restore control registers\n"); 473 + 474 + regcache_cache_only(data->regmap, false); 475 + 476 + return 0; 477 + } 478 + #endif 479 + 480 + static const struct dev_pm_ops mmc35240_pm_ops = { 481 + SET_SYSTEM_SLEEP_PM_OPS(mmc35240_suspend, mmc35240_resume) 482 + }; 483 + 452 484 static const struct i2c_device_id mmc35240_id[] = { 453 485 {"MMC35240", 0}, 454 486 {} ··· 491 457 static struct i2c_driver mmc35240_driver = { 492 458 .driver = { 493 459 .name = MMC35240_DRV_NAME, 460 + .pm = &mmc35240_pm_ops, 494 461 }, 495 462 .probe = mmc35240_probe, 496 463 .id_table = mmc35240_id,