platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Antheas Kapenekakis <lkml@antheas.dev>
Cc: "Armin Wolf" <W_Armin@gmx.de>,
	platform-driver-x86@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	linux-hwmon@vger.kernel.org, "Hans de Goede" <hansg@kernel.org>,
	"Derek John Clark" <derekjohn.clark@gmail.com>,
	"Joaquín Ignacio Aramendía" <samsagax@gmail.com>,
	"Jean Delvare" <jdelvare@suse.com>,
	"Guenter Roeck" <linux@roeck-us.net>
Subject: Re: [PATCH v3 6/6] platform/x86: ayaneo-ec: Add suspend hook
Date: Mon, 10 Nov 2025 14:11:12 +0200 (EET)	[thread overview]
Message-ID: <a99dee5b-8469-c09f-0388-d7e6d6071bdf@linux.intel.com> (raw)
In-Reply-To: <CAGwozwFJKeU-pWzNTkryoUpD63LFuJVSB6=y4C_22+4qat05eA@mail.gmail.com>

On Sun, 2 Nov 2025, Antheas Kapenekakis wrote:

> On Sun, 2 Nov 2025 at 19:35, Armin Wolf <W_Armin@gmx.de> wrote:
> >
> > Am 31.10.25 um 17:36 schrieb Antheas Kapenekakis:
> >
> > > The Ayaneo EC resets after hibernation, losing the charge control state.
> > > Add a small PM hook to restore this state on hibernation resume.
> > >
> > > The fan speed is also lost during hibernation, but since hibernation
> > > failures are common with this class of devices, setting a low fan speed
> > > when the userspace program controlling the fan will potentially not
> > > take over could cause the device to overheat, so it is not restored.
> >
> > Please update the patch description.
> >
> > >
> > > Signed-off-by: Antheas Kapenekakis <lkml@antheas.dev>
> > > ---
> > >   drivers/platform/x86/ayaneo-ec.c | 73 ++++++++++++++++++++++++++++++++
> > >   1 file changed, 73 insertions(+)
> > >
> > > diff --git a/drivers/platform/x86/ayaneo-ec.c b/drivers/platform/x86/ayaneo-ec.c
> > > index 9548e3d22093..e1ad5968d3b4 100644
> > > --- a/drivers/platform/x86/ayaneo-ec.c
> > > +++ b/drivers/platform/x86/ayaneo-ec.c
> > > @@ -41,6 +41,8 @@
> > >   #define AYANEO_MODULE_LEFT  BIT(0)
> > >   #define AYANEO_MODULE_RIGHT BIT(1)
> > >
> > > +#define AYANEO_CACHE_LEN     1
> > > +
> > >   struct ayaneo_ec_quirk {
> > >       bool has_fan_control;
> > >       bool has_charge_control;
> > > @@ -51,6 +53,9 @@ struct ayaneo_ec_platform_data {
> > >       struct platform_device *pdev;
> > >       struct ayaneo_ec_quirk *quirks;
> > >       struct acpi_battery_hook battery_hook;
> > > +
> > > +     bool restore_charge_limit;
> > > +     bool restore_pwm;
> > >   };
> > >
> > >   static const struct ayaneo_ec_quirk quirk_fan = {
> > > @@ -207,10 +212,14 @@ static int ayaneo_ec_read(struct device *dev, enum hwmon_sensor_types type,
> > >   static int ayaneo_ec_write(struct device *dev, enum hwmon_sensor_types type,
> > >                          u32 attr, int channel, long val)
> > >   {
> > > +     struct ayaneo_ec_platform_data *data = platform_get_drvdata(
> > > +             to_platform_device(dev));
> > > +     int ret;
> > >       switch (type) {
> > >       case hwmon_pwm:
> > >               switch (attr) {
> > >               case hwmon_pwm_enable:
> > > +                     data->restore_pwm = false;
> > >                       switch (val) {
> > >                       case 1:
> > >                               return ec_write(AYANEO_PWM_ENABLE_REG,
> > > @@ -224,6 +233,15 @@ static int ayaneo_ec_write(struct device *dev, enum hwmon_sensor_types type,
> > >               case hwmon_pwm_input:
> > >                       if (val < 0 || val > 255)
> > >                               return -EINVAL;
> > > +                     if (data->restore_pwm) {
> > > +                             // Defer restoring PWM control to after
> > > +                             // userspace resumes successfully
> > > +                             ret = ec_write(AYANEO_PWM_ENABLE_REG,
> > > +                                            AYANEO_PWM_MODE_MANUAL);
> > > +                             if (ret)
> > > +                                     return ret;
> > > +                             data->restore_pwm = false;
> >
> > I suspect that you need to use a mutex to protect the restore sequence.
> 
> This is indeed true. I can respin the last patch with a mutex and fix
> the description.
> 
> If the date on the control modules patch is the only issue, I can skip
> re-sending the first 5.

As usual, please send next version of the series once you've addressed the 
review comments.

If you want some patches to not delay the first part of the series, send 
those separately.

--
 i.

> 
> 
> > Thanks,
> > Armin Wolf
> >
> > > +                     }
> > >                       return ec_write(AYANEO_PWM_REG, (val * 100) / 255);
> > >               default:
> > >                       break;
> > > @@ -474,10 +492,65 @@ static int ayaneo_ec_probe(struct platform_device *pdev)
> > >       return 0;
> > >   }
> > >
> > > +static int ayaneo_freeze(struct device *dev)
> > > +{
> > > +     struct platform_device *pdev = to_platform_device(dev);
> > > +     struct ayaneo_ec_platform_data *data = platform_get_drvdata(pdev);
> > > +     int ret;
> > > +     u8 tmp;
> > > +
> > > +     if (data->quirks->has_charge_control) {
> > > +             ret = ec_read(AYANEO_CHARGE_REG, &tmp);
> > > +             if (ret)
> > > +                     return ret;
> > > +
> > > +             data->restore_charge_limit = tmp == AYANEO_CHARGE_VAL_INHIBIT;
> > > +     }
> > > +
> > > +     if (data->quirks->has_fan_control) {
> > > +             ret = ec_read(AYANEO_PWM_ENABLE_REG, &tmp);
> > > +             if (ret)
> > > +                     return ret;
> > > +
> > > +             data->restore_pwm = tmp == AYANEO_PWM_MODE_MANUAL;
> > > +
> > > +             // Release the fan when entering hibernation to avoid
> > > +             // overheating if hibernation fails and hangs
> > > +             if (data->restore_pwm) {
> > > +                     ret = ec_write(AYANEO_PWM_ENABLE_REG, AYANEO_PWM_MODE_AUTO);
> > > +                     if (ret)
> > > +                             return ret;
> > > +             }
> > > +     }
> > > +
> > > +     return 0;
> > > +}
> > > +
> > > +static int ayaneo_restore(struct device *dev)
> > > +{
> > > +     struct platform_device *pdev = to_platform_device(dev);
> > > +     struct ayaneo_ec_platform_data *data = platform_get_drvdata(pdev);
> > > +     int ret;
> > > +
> > > +     if (data->quirks->has_charge_control && data->restore_charge_limit) {
> > > +             ret = ec_write(AYANEO_CHARGE_REG, AYANEO_CHARGE_VAL_INHIBIT);
> > > +             if (ret)
> > > +                     return ret;
> > > +     }
> > > +
> > > +     return 0;
> > > +}
> > > +
> > > +static const struct dev_pm_ops ayaneo_pm_ops = {
> > > +     .freeze = ayaneo_freeze,
> > > +     .restore = ayaneo_restore,
> > > +};
> > > +
> > >   static struct platform_driver ayaneo_platform_driver = {
> > >       .driver = {
> > >               .name = "ayaneo-ec",
> > >               .dev_groups = ayaneo_ec_groups,
> > > +             .pm = &ayaneo_pm_ops,
> > >       },
> > >       .probe = ayaneo_ec_probe,
> > >   };
> >
> 
> 

  reply	other threads:[~2025-11-10 12:11 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-31 16:36 [PATCH v3 0/6] platform/x86: ayaneo-ec: Add Ayaneo Embedded Controller platform driver Antheas Kapenekakis
2025-10-31 16:36 ` [PATCH v3 1/6] " Antheas Kapenekakis
2025-11-02 18:21   ` Armin Wolf
2025-11-02 18:35     ` Armin Wolf
     [not found]     ` <CAGwozwGO=sZjGro7NaKH=zC4x_GR8H7kaPSn8NP60H7EZ4s3+g@mail.gmail.com>
2025-11-04 19:58       ` Armin Wolf
2025-10-31 16:36 ` [PATCH v3 2/6] platform/x86: ayaneo-ec: Add hwmon support Antheas Kapenekakis
2025-11-02 18:22   ` Armin Wolf
2025-10-31 16:36 ` [PATCH v3 3/6] platform/x86: ayaneo-ec: Add charge control support Antheas Kapenekakis
2025-11-02 18:26   ` Armin Wolf
2025-11-02 18:37     ` Antheas Kapenekakis
2025-11-04 20:00       ` Armin Wolf
2025-10-31 16:36 ` [PATCH v3 4/6] platform/x86: ayaneo-ec: Add controller power and modules attributes Antheas Kapenekakis
2025-11-02 18:30   ` Armin Wolf
2025-11-02 18:46     ` Antheas Kapenekakis
2025-11-04 20:03       ` Armin Wolf
2025-11-05 12:33         ` Antheas Kapenekakis
2025-11-05 13:24           ` Ilpo Järvinen
2025-11-05 13:38             ` Antheas Kapenekakis
2025-11-05 22:20             ` Armin Wolf
2025-10-31 16:36 ` [PATCH v3 5/6] platform/x86: ayaneo-ec: Move Ayaneo devices from oxpec to ayaneo-ec Antheas Kapenekakis
2025-10-31 16:36 ` [PATCH v3 6/6] platform/x86: ayaneo-ec: Add suspend hook Antheas Kapenekakis
2025-11-02 18:35   ` Armin Wolf
2025-11-02 18:58     ` Antheas Kapenekakis
2025-11-10 12:11       ` Ilpo Järvinen [this message]
2025-11-03 16:51   ` Mario Limonciello (AMD) (kernel.org)
2025-11-03 21:20     ` Antheas Kapenekakis
2025-11-03 21:33       ` Mario Limonciello (AMD) (kernel.org)
2025-11-03 22:09         ` Antheas Kapenekakis
2025-10-31 16:38 ` [PATCH v3 0/6] platform/x86: ayaneo-ec: Add Ayaneo Embedded Controller platform driver Antheas Kapenekakis
2025-10-31 16:39   ` Antheas Kapenekakis

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=a99dee5b-8469-c09f-0388-d7e6d6071bdf@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=W_Armin@gmx.de \
    --cc=derekjohn.clark@gmail.com \
    --cc=hansg@kernel.org \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lkml@antheas.dev \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=samsagax@gmail.com \
    /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).