diff --git a/drivers/leds/leds-aw200xx.c b/drivers/leds/leds-aw200xx.c index 5142efea2..a38aaea8e 100644 --- a/drivers/leds/leds-aw200xx.c +++ b/drivers/leds/leds-aw200xx.c @@ -311,18 +311,6 @@ static int aw200xx_set_imax(const struct aw200xx *const chip, AW200XX_GCCR_IMAX(gccr_imax)); } -static int aw200xx_chip_reset(const struct aw200xx *const chip) -{ - int ret; - - ret = regmap_write(chip->regmap, AW200XX_REG_RSTR, AW200XX_RSTR_RESET); - if (ret) - return ret; - - regcache_mark_dirty(chip->regmap); - return regmap_write(chip->regmap, AW200XX_REG_FCD, AW200XX_FCD_CLEAR); -} - static int aw200xx_chip_init(const struct aw200xx *const chip) { int ret; @@ -526,10 +514,6 @@ static int aw200xx_probe(struct i2c_client *client) /* Need a lock now since after call aw200xx_probe_fw, sysfs nodes created */ mutex_lock(&chip->mutex); - ret = aw200xx_chip_reset(chip); - if (ret) - goto out_unlock; - ret = aw200xx_probe_fw(&client->dev, chip); if (ret) goto out_unlock; @@ -545,7 +529,6 @@ static void aw200xx_remove(struct i2c_client *client) { struct aw200xx *chip = i2c_get_clientdata(client); - aw200xx_chip_reset(chip); mutex_destroy(&chip->mutex); } @@ -583,9 +566,48 @@ static const struct of_device_id aw200xx_match_table[] = { }; MODULE_DEVICE_TABLE(of, aw200xx_match_table); +#if defined(CONFIG_PM_SLEEP) +static int aw200xx_suspend(struct device *dev) { + struct i2c_client *client = to_i2c_client(dev); + struct aw200xx *chip = i2c_get_clientdata(client); + + regcache_cache_only(chip->regmap, true); + + return 0; +} + +static int aw200xx_resume(struct device *dev) { + struct i2c_client *client = to_i2c_client(dev); + struct aw200xx *chip = i2c_get_clientdata(client); + int ret; + + usleep_range(5000, 10000); + + mutex_lock(&chip->mutex); + + regcache_mark_dirty(chip->regmap); + regcache_cache_only(chip->regmap, false); + + ret = regcache_sync(chip->regmap); + if (ret) + dev_err(dev, "Failed to sync regmap: %d\n", ret); + + ret = aw200xx_chip_init(chip); + if (ret) + dev_err(dev, "Failed to init chip: %d\n", ret); + + mutex_unlock(&chip->mutex); + + return ret; +} +#endif + +static SIMPLE_DEV_PM_OPS(aw200xx_pm_ops, aw200xx_suspend, aw200xx_resume); + static struct i2c_driver aw200xx_driver = { .driver = { .name = "aw200xx", + .pm = &aw200xx_pm_ops, .of_match_table = aw200xx_match_table, }, .probe = aw200xx_probe,