From: Hans de Goede <hdegoede@redhat.com>
To: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
Yauhen Kharuzhy <jekhor@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>, linux-leds@vger.kernel.org
Subject: [PATCH 2/5] leds: cht-wcove: Add suspend/resume handling
Date: Thu, 13 Apr 2023 17:18:05 +0200 [thread overview]
Message-ID: <20230413151808.20900-3-hdegoede@redhat.com> (raw)
In-Reply-To: <20230413151808.20900-1-hdegoede@redhat.com>
When LED1 is showing the tablet is charging and then the device gets
suspended followed by unplugging the charger, then it will incorrectly
still show it is charging.
To avoid this turn both LEDs off on suspend, just like the PMIC always
turns them off when the tablet is powered off (even if the tablet is
charging). If hw-control is supported for LED1, then restore the
initial hw-control settings to let the hw control LED1 while suspended.
To restore the state the LEDs had before suspending, save it before
turning the LEDs off and restore it on resume.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/leds/leds-cht-wcove.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/drivers/leds/leds-cht-wcove.c b/drivers/leds/leds-cht-wcove.c
index 06447804d050..2d968ddd18c5 100644
--- a/drivers/leds/leds-cht-wcove.c
+++ b/drivers/leds/leds-cht-wcove.c
@@ -15,6 +15,7 @@
#include <linux/mod_devicetable.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
+#include <linux/suspend.h>
#define CHT_WC_LED1_CTRL 0x5e1f
#define CHT_WC_LED1_FSM 0x5e20
@@ -69,6 +70,7 @@ struct cht_wc_led {
const struct cht_wc_led_regs *regs;
struct regmap *regmap;
struct mutex mutex;
+ struct cht_wc_led_saved_regs saved_regs;
};
struct cht_wc_leds {
@@ -352,12 +354,43 @@ static void cht_wc_leds_disable(struct platform_device *pdev)
cht_wc_led_restore_regs(&leds->leds[0], &leds->led1_initial_regs);
}
+/* On suspend save current settings and turn LEDs off */
+static int cht_wc_leds_suspend(struct device *dev)
+{
+ struct cht_wc_leds *leds = dev_get_drvdata(dev);
+ int i, ret;
+
+ for (i = 0; i < CHT_WC_LED_COUNT; i++) {
+ ret = cht_wc_led_save_regs(&leds->leds[i], &leds->leds[i].saved_regs);
+ if (ret < 0)
+ return ret;
+ }
+
+ cht_wc_leds_disable(to_platform_device(dev));
+ return 0;
+}
+
+/* On resume restore the saveds settings */
+static int cht_wc_leds_resume(struct device *dev)
+{
+ struct cht_wc_leds *leds = dev_get_drvdata(dev);
+ int i;
+
+ for (i = 0; i < CHT_WC_LED_COUNT; i++)
+ cht_wc_led_restore_regs(&leds->leds[i], &leds->leds[i].saved_regs);
+
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(cht_wc_leds_pm, cht_wc_leds_suspend, cht_wc_leds_resume);
+
static struct platform_driver cht_wc_leds_driver = {
.probe = cht_wc_leds_probe,
.remove_new = cht_wc_leds_remove,
.shutdown = cht_wc_leds_disable,
.driver = {
.name = "cht_wcove_leds",
+ .pm = pm_sleep_ptr(&cht_wc_leds_pm),
},
};
module_platform_driver(cht_wc_leds_driver);
--
2.39.1
next prev parent reply other threads:[~2023-04-13 15:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-13 15:18 [PATCH 0/5] leds: Add Intel Cherry Trail Whiskey Cove PMIC LED driver Hans de Goede
2023-04-13 15:18 ` [PATCH 1/5] " Hans de Goede
2023-04-14 12:44 ` Pavel Machek
2023-04-19 13:04 ` Hans de Goede
2023-04-20 12:17 ` Hans de Goede
2023-04-13 15:18 ` Hans de Goede [this message]
2023-04-14 12:46 ` [PATCH 2/5] leds: cht-wcove: Add suspend/resume handling Pavel Machek
2023-04-13 15:18 ` [PATCH 3/5] leds: cht-wcove: Add support for breathing mode use hw_pattern sysfs API Hans de Goede
2023-04-16 15:17 ` Jacek Anaszewski
2023-04-16 20:31 ` Hans de Goede
2023-04-17 20:00 ` Jacek Anaszewski
2023-04-19 13:05 ` Hans de Goede
2023-04-13 15:18 ` [PATCH 4/5] leds: cht-wcove: Set default trigger for charging LED Hans de Goede
2023-04-13 15:18 ` [PATCH 5/5] leds: cht-wcove: Use breathing when LED_INIT_DEFAULT_TRIGGER is set Hans de Goede
2023-04-15 20:32 ` [PATCH 0/5] leds: Add Intel Cherry Trail Whiskey Cove PMIC LED driver Yauhen Kharuzhy
2023-04-16 13:04 ` Hans de Goede
2023-04-25 13:37 ` Hans de Goede
2023-04-26 11:12 ` Yauhen Kharuzhy
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=20230413151808.20900-3-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=jekhor@gmail.com \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/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).