From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Andy Shevchenko <andy@kernel.org>
Subject: [PATCH v1 04/10] gpio: pca953x: Split pca953x_restore_context() and pca953x_save_context()
Date: Fri, 1 Sep 2023 16:40:35 +0300 [thread overview]
Message-ID: <20230901134041.1165562-4-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230901134041.1165562-1-andriy.shevchenko@linux.intel.com>
Split regcache handling to the respective helpers. It will allow to
have further refactoring with ease.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpio-pca953x.c | 44 ++++++++++++++++++++++++-------------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 4249ec350ace..71d87d570a2b 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -1182,9 +1182,9 @@ static int pca953x_probe(struct i2c_client *client)
}
#ifdef CONFIG_PM_SLEEP
-static int pca953x_regcache_sync(struct device *dev)
+static int pca953x_regcache_sync(struct pca953x_chip *chip)
{
- struct pca953x_chip *chip = dev_get_drvdata(dev);
+ struct device *dev = &chip->client->dev;
int ret;
u8 regaddr;
@@ -1231,13 +1231,37 @@ static int pca953x_regcache_sync(struct device *dev)
return 0;
}
-static int pca953x_suspend(struct device *dev)
+static int pca953x_restore_context(struct pca953x_chip *chip)
{
- struct pca953x_chip *chip = dev_get_drvdata(dev);
+ int ret;
+ mutex_lock(&chip->i2c_lock);
+
+ regcache_cache_only(chip->regmap, false);
+ regcache_mark_dirty(chip->regmap);
+ ret = pca953x_regcache_sync(chip);
+ if (ret) {
+ mutex_unlock(&chip->i2c_lock);
+ return ret;
+ }
+
+ ret = regcache_sync(chip->regmap);
+ mutex_unlock(&chip->i2c_lock);
+ return ret;
+}
+
+static void pca953x_save_context(struct pca953x_chip *chip)
+{
mutex_lock(&chip->i2c_lock);
regcache_cache_only(chip->regmap, true);
mutex_unlock(&chip->i2c_lock);
+}
+
+static int pca953x_suspend(struct device *dev)
+{
+ struct pca953x_chip *chip = dev_get_drvdata(dev);
+
+ pca953x_save_context(chip);
if (atomic_read(&chip->wakeup_path))
device_set_wakeup_path(dev);
@@ -1260,17 +1284,7 @@ static int pca953x_resume(struct device *dev)
}
}
- mutex_lock(&chip->i2c_lock);
- regcache_cache_only(chip->regmap, false);
- regcache_mark_dirty(chip->regmap);
- ret = pca953x_regcache_sync(dev);
- if (ret) {
- mutex_unlock(&chip->i2c_lock);
- return ret;
- }
-
- ret = regcache_sync(chip->regmap);
- mutex_unlock(&chip->i2c_lock);
+ ret = pca953x_restore_context(chip);
if (ret) {
dev_err(dev, "Failed to restore register map: %d\n", ret);
return ret;
--
2.40.0.1.gaa8946217a0b
next prev parent reply other threads:[~2023-09-01 13:40 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-01 13:40 [PATCH v1 01/10] gpio: pca953x: Drop unused fields in struct pca953x_platform_data Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 02/10] gpio: pca953x: Fully convert to device managed resources Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 03/10] gpio: pca953x: Utilise dev_err_probe() where it makes sense Andy Shevchenko
2023-09-01 13:40 ` Andy Shevchenko [this message]
2023-09-01 13:40 ` [PATCH v1 05/10] gpio: pca953x: Simplify code with cleanup helpers Andy Shevchenko
2023-09-13 14:35 ` Geert Uytterhoeven
2023-09-13 15:27 ` Bartosz Golaszewski
2023-09-14 7:47 ` guard coding style (was: Re: [PATCH v1 05/10] gpio: pca953x: Simplify code with cleanup helpers) Geert Uytterhoeven
2023-09-14 20:51 ` Mitchell Levy
2023-09-14 22:26 ` Peter Zijlstra
2023-09-14 22:41 ` Peter Zijlstra
2023-09-14 22:17 ` Peter Zijlstra
2023-09-14 22:30 ` Peter Zijlstra
2023-09-01 13:40 ` [PATCH v1 06/10] gpio: pca953x: Utilise temporary variable for struct device Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 07/10] gpio: pca953x: Utilise temporary variable for struct gpio_chip Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 08/10] gpio: pca953x: Switch to DEFINE_SIMPLE_DEV_PM_OPS() Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 09/10] gpio: pca953x: Get rid of useless goto label Andy Shevchenko
2023-09-04 7:41 ` Bartosz Golaszewski
2023-09-04 8:38 ` Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 10/10] gpio: pca953x: Revisit header inclusions Andy Shevchenko
2023-09-04 7:43 ` [PATCH v1 01/10] gpio: pca953x: Drop unused fields in struct pca953x_platform_data Bartosz Golaszewski
2023-09-06 16:26 ` Andy Shevchenko
2023-09-11 7:01 ` Bartosz Golaszewski
2023-09-12 7:50 ` Linus Walleij
2023-09-12 9:31 ` Andy Shevchenko
2023-09-12 9:48 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230901134041.1165562-4-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).