gpio: fxl6408: Add suspend/resume support
PATCH v3 1/1 gpio: fxl6408: Add suspend/resume support
Currently, during suspend, do nothing; during resume, just sync the regmap cache to hw regs.
---
since v2:
- drop the reset pin support patch since no users now
since v1:
-fix W=1 build error on nios2 platform
drivers/gpio/gpio-fxl6408.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/gpio/gpio-fxl6408.c +23 -0
@@ -43,6 +43,10 @@#define FXL6408_NGPIO 8 +struct fxl6408_chip { +struct regmap *regmap; +}; +static const struct regmap_range rd_range[] = { {FXL6408_REG_DEVICE_ID ,FXL6408_REG_DEVICE_ID }, {FXL6408_REG_IO_DIR ,FXL6408_REG_OUTPUT },
@@ -104,6 +108,7 @@ static int fxl6408_identify(struct device *dev, struct regmap *regmap)static int fxl6408_probe (struct i2c_client *client) {struct device *dev = &client->dev; +struct fxl6408_chip *chip;int ret;struct gpio_regmap_config gpio_config = { .parent = dev,
@@ -114,6 +119,10 @@ static int fxl6408_probe(struct i2c_client *client) .ngpio_per_reg = FXL6408_NGPIO, }; + chip =devm_kzalloc (dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + gpio_config.regmap =devm_regmap_init_i2c (client, ®map);if (IS_ERR (gpio_config.regmap)) return dev_err_probe(dev, PTR_ERR(gpio_config.regmap),
@@ -123,6 +132,9 @@ static int fxl6408_probe(struct i2c_client *client)if (ret)return ret; + chip->regmap = gpio_config.regmap; +i2c_set_clientdata (client, chip); +/* Disable High-Z of outputs, so that our OUTPUT updates actually take effect. */ ret =regmap_write (gpio_config.regmap,FXL6408_REG_OUTPUT_HIGH_Z ,0 );if (ret)
@@ -131,6 +143,16 @@ static int fxl6408_probe(struct i2c_client *client)return PTR_ERR_OR_ZERO (devm_gpio_regmap_register (dev, &gpio_config)); } +static int fxl6408_resume (struct device *dev) +{ +struct fxl6408_chip *chip =dev_get_drvdata (dev); + +regcache_mark_dirty (chip->regmap); +return regcache_sync (chip->regmap); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(fxl6408_pm_ops, NULL, fxl6408_resume); +static const __maybe_unused struct of_device_id fxl6408_dt_ids[] = { { .compatible ="fcs,fxl6408" }, { }
@@ -146,6 +168,7 @@ MODULE_DEVICE_TABLE(i2c, fxl6408_id);static struct i2c_driver fxl6408_driver = { .driver = { .name ="fxl6408" , + .pm =pm_sleep_ptr (&fxl6408_pm_ops), .of_match_table = fxl6408_dt_ids, }, .probe = fxl6408_probe,
Signature · 1 line
2.51.0
Quoted 21 lines · Jisheng Zhang
Currently, during suspend, do nothing; during resume, just sync the regmap cache to hw regs.
Signed-off-by Jisheng Zhang <[email protected]>---
since v2:
- drop the reset pin support patch since no users nowsince v1:
-fix W=1 build error on nios2 platformdrivers/gpio/gpio-fxl6408.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)drivers/gpio/gpio-fxl6408.c +0
-0
drivers/gpio/gpio-fxl6408.c line 48
Quoted 6 lines
drivers/gpio/gpio-fxl6408.c +3
-0@@ -43,6 +43,10 @@#define FXL6408_NGPIO 8 +struct fxl6408_chip { +struct regmap *regmap; +};
I would simplify the patch by roughly 50% by dropping this wrapper structure. I know it's less future-proof but it doesn't seem that we'll need more fields here anytime soon. We can cross that bridge when we get there.
Quoted 13 lines
drivers/gpio/gpio-fxl6408.c +2
-0+static const struct regmap_range rd_range[] = { {FXL6408_REG_DEVICE_ID ,FXL6408_REG_DEVICE_ID }, {FXL6408_REG_IO_DIR ,FXL6408_REG_OUTPUT },@@ -104,6 +108,7 @@ static int fxl6408_identify(struct device *dev, struct regmap *regmap)static int fxl6408_probe (struct i2c_client *client) {struct device *dev = &client->dev; +struct fxl6408_chip *chip;int ret;struct gpio_regmap_config gpio_config = { .parent = dev,
drivers/gpio/gpio-fxl6408.c static int fxl6408_probe(struct i2c_client *client) · line 124
Quoted 6 lines
drivers/gpio/gpio-fxl6408.c +3
-0@@ -114,6 +119,10 @@ static int fxl6408_probe(struct i2c_client *client) .ngpio_per_reg = FXL6408_NGPIO, }; + chip =devm_kzalloc (dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ;
That would go away.
drivers/gpio/gpio-fxl6408.c static int fxl6408_probe(struct i2c_client *client) · line 135
Quoted 9 lines
drivers/gpio/gpio-fxl6408.c +2
-0+ gpio_config.regmap =devm_regmap_init_i2c (client, ®map);if (IS_ERR (gpio_config.regmap)) return dev_err_probe(dev, PTR_ERR(gpio_config.regmap),@@ -123,6 +132,9 @@ static int fxl6408_probe(struct i2c_client *client)if (ret)return ret; + chip->regmap = gpio_config.regmap;
That too.
drivers/gpio/gpio-fxl6408.c static int fxl6408_probe(struct i2c_client *client) · line 136
Quoted 1 line
drivers/gpio/gpio-fxl6408.c +1
-0+i2c_set_clientdata (client, chip);
You'd just do i2c_set_clientdata(client, gpio_config.regmap) here.
Quoted 30 lines
drivers/gpio/gpio-fxl6408.c +12
-1+/* Disable High-Z of outputs, so that our OUTPUT updates actually take effect. */ ret =regmap_write (gpio_config.regmap,FXL6408_REG_OUTPUT_HIGH_Z ,0 );if (ret)@@ -131,6 +143,16 @@ static int fxl6408_probe(struct i2c_client *client)return PTR_ERR_OR_ZERO (devm_gpio_regmap_register (dev, &gpio_config)); } +static int fxl6408_resume (struct device *dev) +{ +struct fxl6408_chip *chip =dev_get_drvdata (dev); + +regcache_mark_dirty (chip->regmap); +return regcache_sync (chip->regmap); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(fxl6408_pm_ops, NULL, fxl6408_resume); +static const __maybe_unused struct of_device_id fxl6408_dt_ids[] = { { .compatible ="fcs,fxl6408" }, { }@@ -146,6 +168,7 @@ MODULE_DEVICE_TABLE(i2c, fxl6408_id);static struct i2c_driver fxl6408_driver = { .driver = { .name ="fxl6408" , + .pm =pm_sleep_ptr (&fxl6408_pm_ops), .of_match_table = fxl6408_dt_ids, }, .probe = fxl6408_probe, --
Quoted 2 lines
2.51.0
Bart