Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Armin Wolf <W_Armin@gmx.de>
To: Antheas Kapenekakis <lkml@antheas.dev>,
	platform-driver-x86@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"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 v2 3/6] platform/x86: ayaneo-ec: Add charge control support
Date: Sun, 26 Oct 2025 23:35:51 +0100	[thread overview]
Message-ID: <7f215fa8-b355-4830-ab5c-a9f5c419e207@gmx.de> (raw)
In-Reply-To: <20251015084414.1391595-4-lkml@antheas.dev>

Am 15.10.25 um 10:44 schrieb Antheas Kapenekakis:

> Ayaneo devices support charge inhibition via the EC. This inhibition
> only works while the device is powered on, and resets between restarts.
> However, it is maintained across suspend/resume cycles.
>
> The EC does not support charge threshold control. Instead, userspace
> software on Windows manually toggles charge inhibition depending on
> battery level.
>
> Signed-off-by: Antheas Kapenekakis <lkml@antheas.dev>
> ---
>   drivers/platform/x86/Kconfig     |   1 +
>   drivers/platform/x86/ayaneo-ec.c | 111 +++++++++++++++++++++++++++++++
>   2 files changed, 112 insertions(+)
>
> diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> index f132a87fcee9..f5b2edc6bc67 100644
> --- a/drivers/platform/x86/Kconfig
> +++ b/drivers/platform/x86/Kconfig
> @@ -320,6 +320,7 @@ config AYANEO_EC
>   	tristate "Ayaneo EC platform control"
>   	depends on X86
>   	depends on ACPI_EC
> +	depends on ACPI_BATTERY
>   	depends on HWMON
>   	help
>   	  Enables support for the platform EC of Ayaneo devices. This
> diff --git a/drivers/platform/x86/ayaneo-ec.c b/drivers/platform/x86/ayaneo-ec.c
> index 9884eed0cc84..23c283f5eb61 100644
> --- a/drivers/platform/x86/ayaneo-ec.c
> +++ b/drivers/platform/x86/ayaneo-ec.c
> @@ -14,6 +14,7 @@
>   #include <linux/kernel.h>
>   #include <linux/module.h>
>   #include <linux/platform_device.h>
> +#include <acpi/battery.h>

You should also include <linux/power_supply.h>. With that being fixed:

Reviewed-by: Armin Wolf <W_Armin@gmx.de>

>   
>   #define AYANEO_PWM_ENABLE_REG	 0x4A
>   #define AYANEO_PWM_REG		 0x4B
> @@ -22,17 +23,27 @@
>   
>   #define AYANEO_FAN_REG		 0x76
>   
> +#define EC_CHARGE_CONTROL_BEHAVIOURS                         \
> +	(BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO) |           \
> +	 BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE))
> +#define AYANEO_CHARGE_REG		0x1e
> +#define AYANEO_CHARGE_VAL_AUTO		0xaa
> +#define AYANEO_CHARGE_VAL_INHIBIT	0x55
> +
>   struct ayaneo_ec_quirk {
>   	bool has_fan_control;
> +	bool has_charge_control;
>   };
>   
>   struct ayaneo_ec_platform_data {
>   	struct platform_device *pdev;
>   	struct ayaneo_ec_quirk *quirks;
> +	struct acpi_battery_hook battery_hook;
>   };
>   
>   static const struct ayaneo_ec_quirk ayaneo3 = {
>   	.has_fan_control = true,
> +	.has_charge_control = true,
>   };
>   
>   static const struct dmi_system_id dmi_table[] = {
> @@ -161,11 +172,102 @@ static const struct hwmon_chip_info ayaneo_ec_chip_info = {
>   	.info = ayaneo_ec_sensors,
>   };
>   
> +static int ayaneo_psy_ext_get_prop(struct power_supply *psy,
> +				const struct power_supply_ext *ext,
> +				void *data,
> +				enum power_supply_property psp,
> +				union power_supply_propval *val)
> +{
> +	int ret;
> +	u8 tmp;
> +
> +	switch (psp) {
> +	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
> +		ret = ec_read(AYANEO_CHARGE_REG, &tmp);
> +		if (ret)
> +			return ret;
> +
> +		if (tmp == AYANEO_CHARGE_VAL_INHIBIT)
> +			val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE;
> +		else
> +			val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO;
> +		return 0;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static int ayaneo_psy_ext_set_prop(struct power_supply *psy,
> +				const struct power_supply_ext *ext,
> +				void *data,
> +				enum power_supply_property psp,
> +				const union power_supply_propval *val)
> +{
> +	u8 raw_val;
> +
> +	switch (psp) {
> +	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
> +		switch (val->intval) {
> +		case POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO:
> +			raw_val = AYANEO_CHARGE_VAL_AUTO;
> +			break;
> +		case POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE:
> +			raw_val = AYANEO_CHARGE_VAL_INHIBIT;
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
> +		return ec_write(AYANEO_CHARGE_REG, raw_val);
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static int ayaneo_psy_prop_is_writeable(struct power_supply *psy,
> +				     const struct power_supply_ext *ext,
> +				     void *data,
> +				     enum power_supply_property psp)
> +{
> +	return true;
> +}
> +
> +static const enum power_supply_property ayaneo_psy_ext_props[] = {
> +	POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
> +};
> +
> +static const struct power_supply_ext ayaneo_psy_ext = {
> +	.name			= "ayaneo-charge-control",
> +	.properties		= ayaneo_psy_ext_props,
> +	.num_properties		= ARRAY_SIZE(ayaneo_psy_ext_props),
> +	.charge_behaviours	= EC_CHARGE_CONTROL_BEHAVIOURS,
> +	.get_property		= ayaneo_psy_ext_get_prop,
> +	.set_property		= ayaneo_psy_ext_set_prop,
> +	.property_is_writeable	= ayaneo_psy_prop_is_writeable,
> +};
> +
> +static int ayaneo_add_battery(struct power_supply *battery,
> +			   struct acpi_battery_hook *hook)
> +{
> +	struct ayaneo_ec_platform_data *data =
> +		container_of(hook, struct ayaneo_ec_platform_data, battery_hook);
> +
> +	return power_supply_register_extension(battery, &ayaneo_psy_ext,
> +					       &data->pdev->dev, NULL);
> +}
> +
> +static int ayaneo_remove_battery(struct power_supply *battery,
> +			      struct acpi_battery_hook *hook)
> +{
> +	power_supply_unregister_extension(battery, &ayaneo_psy_ext);
> +	return 0;
> +}
> +
>   static int ayaneo_ec_probe(struct platform_device *pdev)
>   {
>   	const struct dmi_system_id *dmi_entry;
>   	struct ayaneo_ec_platform_data *data;
>   	struct device *hwdev;
> +	int ret;
>   
>   	dmi_entry = dmi_first_match(dmi_table);
>   	if (!dmi_entry)
> @@ -186,6 +288,15 @@ static int ayaneo_ec_probe(struct platform_device *pdev)
>   			return PTR_ERR(hwdev);
>   	}
>   
> +	if (data->quirks->has_charge_control) {
> +		data->battery_hook.add_battery = ayaneo_add_battery;
> +		data->battery_hook.remove_battery = ayaneo_remove_battery;
> +		data->battery_hook.name = "Ayaneo Battery";
> +		ret = devm_battery_hook_register(&pdev->dev, &data->battery_hook);
> +		if (ret)
> +			return ret;
> +	}
> +
>   	return 0;
>   }
>   

  reply	other threads:[~2025-10-26 22:36 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15  8:44 [PATCH v2 0/6] platform/x86: ayaneo-ec: Add Ayaneo Embedded Controller platform driver Antheas Kapenekakis
2025-10-15  8:44 ` [PATCH v2 1/6] " Antheas Kapenekakis
2025-10-15  9:04   ` Ilpo Järvinen
2025-10-26 22:25   ` Armin Wolf
2025-10-15  8:44 ` [PATCH v2 2/6] platform/x86: ayaneo-ec: Add hwmon support Antheas Kapenekakis
2025-10-26 22:33   ` Armin Wolf
2025-10-15  8:44 ` [PATCH v2 3/6] platform/x86: ayaneo-ec: Add charge control support Antheas Kapenekakis
2025-10-26 22:35   ` Armin Wolf [this message]
2025-10-15  8:44 ` [PATCH v2 4/6] platform/x86: ayaneo-ec: Add controller power and modules attributes Antheas Kapenekakis
2025-10-15  9:05   ` Ilpo Järvinen
2025-10-15  9:08     ` Ilpo Järvinen
2025-10-26 22:42   ` Armin Wolf
2025-10-15  8:44 ` [PATCH v2 5/6] platform/x86: ayaneo-ec: Move Ayaneo devices from oxpec to ayaneo-ec Antheas Kapenekakis
2025-10-15  9:09   ` Ilpo Järvinen
2025-10-26 22:45   ` Armin Wolf
2025-10-15  8:44 ` [PATCH v2 6/6] platform/x86: ayaneo-ec: Add suspend hook Antheas Kapenekakis
2025-10-15  9:11   ` Ilpo Järvinen
2025-10-15  9:16     ` Antheas Kapenekakis
2025-10-15  9:27       ` Ilpo Järvinen
2025-10-15  9:36         ` Antheas Kapenekakis
2025-10-26 22:49   ` Armin Wolf
2025-10-26 23:17     ` Antheas Kapenekakis
2025-10-28 13:50       ` Armin Wolf
2025-10-28 15:20         ` Antheas Kapenekakis
2025-10-28 15:25           ` Armin Wolf
2025-10-28 17:49             ` Antheas Kapenekakis
2025-10-28 23:14               ` Armin Wolf
2025-10-28 20:26   ` Mario Limonciello
2025-10-28 20:34     ` Antheas Kapenekakis
2025-10-28 21:21       ` Mario Limonciello
2025-10-28 21:39         ` Antheas Kapenekakis
2025-10-29  3:36           ` Mario Limonciello (AMD) (kernel.org)
2025-10-29  8:48             ` Antheas Kapenekakis
2025-10-29 10:22               ` Guenter Roeck
2025-10-29 10:49                 ` Antheas Kapenekakis
2025-10-29 14:25                   ` Guenter Roeck

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=7f215fa8-b355-4830-ab5c-a9f5c419e207@gmx.de \
    --to=w_armin@gmx.de \
    --cc=derekjohn.clark@gmail.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --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