Skip to contentSkip to conversation

platform/x86: ideapad: Expose charge_types

PATCH Superseded Jelle van der Waa 4 participants 6 messages May 11, 2025 – May 14, 2025 x86 platform drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover platform/x86: ideapad: Expose charge_types

From: Jelle van der Waa <[email protected]>

This patch depends on one commit in the for-next branch of the power-supply tree [1].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git/commit/?h=for-next&id=c1f7375a246e5f810191a6c3031d2fa2b80e9f5e

Jelle van der Waa (1):
platform/x86: ideapad: Expose charge_types

 .../ABI/testing/sysfs-platform-ideapad-laptop |   2 +
 drivers/platform/x86/ideapad-laptop.c         | 126 +++++++++++++++++-
 2 files changed, 125 insertions(+), 3 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/1 platform/x86: ideapad: Expose charge_types

From: Jelle van der Waa <[email protected]>

Some Ideapad models support a battery conservation mode which limits the battery charge threshold for longer battery longevity. This is currently exposed via a custom conservation_mode attribute in sysfs.

The newly introduced charge_types sysfs attribute is a standardized replacement for laptops with a fixed end charge threshold. Setting it to Long Life would enable battery conservation mode. The standardized user space API would allow applications such as UPower to detect laptops which support this battery longevity mode and set it.

Tested on an Lenovo ideapad U330p.

---
 .../ABI/testing/sysfs-platform-ideapad-laptop |   2 +
 drivers/platform/x86/ideapad-laptop.c         | 126 +++++++++++++++++-
 2 files changed, 125 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-platform-ideapad-laptop +2 -0
index 4989ab266682..83eca4c14503 100644
@@ -32,6 +32,8 @@ Date:		Aug 2017
 KernelVersion:	4.14
 Contact:	[email protected]
 Description:
+		This interface is deprecated; please use /sys/class/power_supply/*/charge_types.
+
 		Controls whether the conservation mode is enabled or not.
 		This feature limits the maximum battery charge percentage to
 		around 50-60% in order to prolong the lifetime of the battery.
drivers/platform/x86/ideapad-laptop.c +123 -3

190 lines not on this page · raw message

Signature · 1 line
2.49.0
#2 lore raw

Am 11.05.25 um 13:30 schrieb Jelle van der Waa:

Quoted 6 lines

From: Jelle van der Waa <[email protected]>

Some Ideapad models support a battery conservation mode which limits the battery charge threshold for longer battery longevity. This is currently exposed via a custom conservation_mode attribute in sysfs.

Quoted 7 lines

The newly introduced charge_types sysfs attribute is a standardized replacement for laptops with a fixed end charge threshold. Setting it to Long Life would enable battery conservation mode. The standardized user space API would allow applications such as UPower to detect laptops which support this battery longevity mode and set it.

Tested on an Lenovo ideapad U330p.

Hi,

i like the idea behind this patch series, the charge_types attribute is indeed exactly what we need in this case.

Quoted 12 lines
---
  .../ABI/testing/sysfs-platform-ideapad-laptop |   2 +
  drivers/platform/x86/ideapad-laptop.c         | 126 +++++++++++++++++-
  2 files changed, 125 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-platform-ideapad-laptop +0 -0
index 4989ab266682..83eca4c14503 100644

Documentation/ABI/testing/sysfs-platform-ideapad-laptop Date: Aug 2017 · line 36

Quoted 5 lines
Documentation/ABI/testing/sysfs-platform-ideapad-laptop +2 -0
@@ -32,6 +32,8 @@ Date:		Aug 2017
  KernelVersion:	4.14
  Contact:	[email protected]
  Description:
+		This interface is deprecated; please use /sys/class/power_supply/*/charge_types.
+

Maybe it would make sense to move this attribute to Documentation/ABI/obsolete?

drivers/platform/x86/ideapad-laptop.c line 38

Quoted 13 lines
Documentation/ABI/testing/sysfs-platform-ideapad-laptop +0 -0
  		Controls whether the conservation mode is enabled or not.
  		This feature limits the maximum battery charge percentage to
  		around 50-60% in order to prolong the lifetime of the battery.
drivers/platform/x86/ideapad-laptop.c +2 -0
index ede483573fe0..fd9127ffd456 100644
@@ -34,12 +34,17 @@
  #include <linux/wmi.h>
  #include "ideapad-laptop.h"
 
+#include <linux/power_supply.h>
+#include <acpi/battery.h>

Please make sure that IDEAPAD_LAPTOP depends on ACPI_BATTERY inside the Kconfig.

drivers/platform/x86/ideapad-laptop.c line 46

Quoted 8 lines
drivers/platform/x86/ideapad-laptop.c +2 -0
  #include <acpi/video.h>
 
  #include <dt-bindings/leds/common.h>
 
  #define IDEAPAD_RFKILL_DEV_NUM	3
 
+#define IDEAPAD_CHARGE_TYPES		(BIT(POWER_SUPPLY_CHARGE_TYPE_STANDARD)  | \
+					 BIT(POWER_SUPPLY_CHARGE_TYPE_LONGLIFE))

This macro is rather small and only used once. Please open-code it.

drivers/platform/x86/ideapad-laptop.c struct ideapad_private { · line 171

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +3 -0
+
  enum {
  	CFG_CAP_BT_BIT       = 16,
  	CFG_CAP_3G_BIT       = 17,
@@ -162,6 +167,8 @@ struct ideapad_private {
  	struct backlight_device *blightdev;
  	struct ideapad_dytc_priv *dytc;
  	struct dentry *debug;
+	struct acpi_battery_hook battery_hook;
+	struct power_supply *hooked_battery;

Unused attribute, please remove.

Quoted 34 lines
drivers/platform/x86/ideapad-laptop.c +9 -0
  	unsigned long cfg;
  	unsigned long r_touchpad_val;
  	struct {
@@ -589,6 +596,11 @@ static ssize_t camera_power_store(struct device *dev,
 
  static DEVICE_ATTR_RW(camera_power);
 
+static void show_deprecation_warning(struct device *dev)
+{
+	dev_warn_once(dev, "conservation_mode attribute has been deprecated, see charge_types.\n");
+}
+
  static ssize_t conservation_mode_show(struct device *dev,
  				      struct device_attribute *attr,
  				      char *buf)
@@ -597,6 +609,8 @@ static ssize_t conservation_mode_show(struct device *dev,
  	unsigned long result;
  	int err;
 
+	show_deprecation_warning(dev);
+
  	err = eval_gbmd(priv->adev->handle, &result);
  	if (err)
  		return err;
@@ -612,6 +626,8 @@ static ssize_t conservation_mode_store(struct device *dev,
  	bool state;
  	int err;
 
+	show_deprecation_warning(dev);
+
  	err = kstrtobool(buf, &state);
  	if (err)
  		return err;

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 1993

Quoted 6 lines
drivers/platform/x86/ideapad-laptop.c +2 -1
@@ -1973,10 +1989,99 @@ static const struct dmi_system_id ctrl_ps2_aux_port_list[] = {
  	{}
  };
 
-static void ideapad_check_features(struct ideapad_private *priv)
+static int ideapad_psy_ext_set_prop(struct power_supply *psy,
+				       const struct power_supply_ext *ext,

Alignment should match open parenthesis.

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 2006

Quoted 13 lines
drivers/platform/x86/ideapad-laptop.c +13 -0
+				       void *ext_data,
+				       enum power_supply_property psp,
+				       const union power_supply_propval *val)
+{
+	struct ideapad_private *priv = ext_data;
+	int err;
+
+	if (psp != POWER_SUPPLY_PROP_CHARGE_TYPES)
+		return -EINVAL;
+
+	err = exec_sbmc(priv->adev->handle,
+			(val->intval == POWER_SUPPLY_CHARGE_TYPE_LONGLIFE ?
+			 SBMC_CONSERVATION_ON : SBMC_CONSERVATION_OFF));

AFAIK the power supply core does not check if val->intval holds a supported charge type value. Please use a switch case to return -EINVAL in such cases.

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 2008

Quoted 2 lines
drivers/platform/x86/ideapad-laptop.c +2 -0
+	if (err)
+		return err;

Please directly return the result of exec_sbmc() here.

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 2014

Quoted 6 lines
drivers/platform/x86/ideapad-laptop.c +6 -0
+
+	return 0;
+}
+
+static int ideapad_psy_ext_get_prop(struct power_supply *psy,
+				       const struct power_supply_ext *ext,

Alignment should match open parenthesis.

Quoted 15 lines
drivers/platform/x86/ideapad-laptop.c +15 -0
+				       void *ext_data,
+				       enum power_supply_property psp,
+				       union power_supply_propval *val)
+{
+	struct ideapad_private *priv = ext_data;
+	unsigned long result;
+	int err;
+
+	if (psp != POWER_SUPPLY_PROP_CHARGE_TYPES)
+		return -EINVAL;
+
+	err = eval_gbmd(priv->adev->handle, &result);
+	if (err)
+		return err;
+

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 2039

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +10 -0
+	if (test_bit(GBMD_CONSERVATION_STATE_BIT, &result))
+		val->intval = POWER_SUPPLY_CHARGE_TYPE_LONGLIFE;
+	else
+		val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
+
+	return 0;
+}
+
+static int ideapad_psy_prop_is_writeable(struct power_supply *psy,
+					    const struct power_supply_ext *ext,

Alignment should match open parenthesis.

Quoted 5 lines
drivers/platform/x86/ideapad-laptop.c +5 -0
+					    void *data,
+					    enum power_supply_property psp)
+{
+	if (psp == POWER_SUPPLY_PROP_CHARGE_TYPES)
+		return true;

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 2054

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +10 -0
+
+	return false;
+}
+
+static const enum power_supply_property ideapad_power_supply_props[] = {
+	POWER_SUPPLY_PROP_CHARGE_TYPES,
+};
+
+static const struct power_supply_ext ideapad_battery_ext = {
+	.name			= "ideapad",

Maybe using a more specific name like "ideapad_laptop"/"ideapad_acpi" would be better here?

Quoted 38 lines
drivers/platform/x86/ideapad-laptop.c +27 -1
+	.properties		= ideapad_power_supply_props,
+	.num_properties		= ARRAY_SIZE(ideapad_power_supply_props),
+	.charge_types		= IDEAPAD_CHARGE_TYPES,
+	.get_property		= ideapad_psy_ext_get_prop,
+	.set_property		= ideapad_psy_ext_set_prop,
+	.property_is_writeable	= ideapad_psy_prop_is_writeable,
+};
+
+static int ideapad_battery_add(struct power_supply *battery,
+			       struct acpi_battery_hook *hook)
+{
+	struct ideapad_private *priv = container_of(hook, struct ideapad_private, battery_hook);
+
+	return power_supply_register_extension(battery, &ideapad_battery_ext,
+					       &priv->platform_device->dev, priv);
+}
+
+static int ideapad_battery_remove(struct power_supply *battery,
+				  struct acpi_battery_hook *hook)
+{
+	power_supply_unregister_extension(battery, &ideapad_battery_ext);
+
+	return 0;
+}
+
+static int ideapad_check_features(struct ideapad_private *priv)
  {
  	acpi_handle handle = priv->adev->handle;
  	unsigned long val;
+	int err;
 
  	priv->features.set_fn_lock_led =
  		set_fn_lock_led || dmi_check_system(set_fn_lock_led_list);
@@ -1991,8 +2096,19 @@ static void ideapad_check_features(struct ideapad_private *priv)
  	if (!read_ec_data(handle, VPCCMD_R_FAN, &val))
  		priv->features.fan_mode = true;
 
-	if (acpi_has_method(handle, "GBMD") && acpi_has_method(handle, "SBMC"))

drivers/platform/x86/ideapad-laptop.c static void ideapad_check_features(struct ideapad_private *priv) · line 2108

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +9 -0
+	if (acpi_has_method(handle, "GBMD") && acpi_has_method(handle, "SBMC")) {
  		priv->features.conservation_mode = true;
+		priv->battery_hook.add_battery = ideapad_battery_add;
+		priv->battery_hook.remove_battery = ideapad_battery_remove;
+		priv->battery_hook.name = "Ideapad Battery Extension";
+
+		err = devm_battery_hook_register(&priv->platform_device->dev, &priv->battery_hook);
+		if (err) {
+			dev_dbg(&priv->platform_device->dev,
+				"failed to register battery hook: %d\n", err);

I think this error message is unnecessary. Please remove it.

Thanks,
Armin Wolf

Quoted 26 lines
drivers/platform/x86/ideapad-laptop.c +8 -1
+			return err;
+		}
+	}
 
  	if (acpi_has_method(handle, "DYTC"))
  		priv->features.dytc = true;
@@ -2027,6 +2143,8 @@ static void ideapad_check_features(struct ideapad_private *priv)
  			}
  		}
  	}
+
+	return 0;
  }
 
  #if IS_ENABLED(CONFIG_ACPI_WMI)
@@ -2175,7 +2293,9 @@ static int ideapad_acpi_add(struct platform_device *pdev)
  	if (err)
  		return err;
 
-	ideapad_check_features(priv);
+	err = ideapad_check_features(priv);
+	if (err)
+		return err;
 
  	ideapad_debugfs_init(priv);
 
#3 lore raw
Quoted 14 lines · Armin Wolf

Am 11.05.25 um 13:30 schrieb Jelle van der Waa:

Quoted 12 lines

From: Jelle van der Waa <[email protected]>

Some Ideapad models support a battery conservation mode which limits the battery charge threshold for longer battery longevity. This is currently exposed via a custom conservation_mode attribute in sysfs.

The newly introduced charge_types sysfs attribute is a standardized replacement for laptops with a fixed end charge threshold. Setting it to Long Life would enable battery conservation mode. The standardized user space API would allow applications such as UPower to detect laptops which support this battery longevity mode and set it.

Quoted 6 lines
Quoted 1 line

Tested on an Lenovo ideapad U330p.

Hi,

i like the idea behind this patch series, the charge_types attribute is indeed exactly what we need in this case.

Thanks! Credit where credit is due, this idea came from Hans de Goede (who also added charge_types). I only wrote the code.

Quoted 5 lines
Quoted 5 lines

---
  .../ABI/testing/sysfs-platform-ideapad-laptop |   2 + drivers/platform/x86/ideapad-laptop.c         | 126 +++++++++++++++++-

  2 files changed, 125 insertions(+), 3 deletions(-)
Quoted 13 lines
Quoted 11 lines
Documentation/ABI/testing/sysfs-platform-ideapad-laptop +0 -0
index 4989ab266682..83eca4c14503 100644
@@ -32,6 +32,8 @@ Date:        Aug 2017

  KernelVersion:    4.14
  Contact:    [email protected] Description:
+        This interface is deprecated; please use /sys/class/ power_supply/*/charge_types.
+

Maybe it would make sense to move this attribute to Documentation/ABI/ obsolete?

I am not sure what the normal workflow is so I've applied this suggestion in v2.

Quoted 8 lines
Quoted 8 lines

+                       void *ext_data,
+                       enum power_supply_property psp, +                       const union power_supply_propval *val)

Documentation/ABI/testing/sysfs-platform-ideapad-laptop +5 -0
+{
+    struct ideapad_private *priv = ext_data;
+    int err;
+
+    if (psp != POWER_SUPPLY_PROP_CHARGE_TYPES)
Quoted 8 lines
Quoted 5 lines

+        return -EINVAL;
+
+    err = exec_sbmc(priv->adev->handle,
+            (val->intval == POWER_SUPPLY_CHARGE_TYPE_LONGLIFE ? +             SBMC_CONSERVATION_ON : SBMC_CONSERVATION_OFF));

AFAIK the power supply core does not check if val->intval holds a supported charge type value. Please use a switch case to return -EINVAL in such cases.

From my testing checking val->intval wasn't needed, you'll get an "write error: invalid argument" when trying to set "Long lifeee".

I believe that is handled in power_supply_store_property, but reading the code I don't really believe that's true? So I've simply switched it over to a switch/case.

Thanks,

Jelle

maintainer
#4 lore raw
Quoted 17 lines · Jelle van der Waa
Quoted 16 lines · Armin Wolf

Am 11.05.25 um 13:30 schrieb Jelle van der Waa:

Quoted 13 lines

From: Jelle van der Waa <[email protected]>

Some Ideapad models support a battery conservation mode which limits the battery charge threshold for longer battery longevity. This is currently exposed via a custom conservation_mode attribute in sysfs.

The newly introduced charge_types sysfs attribute is a standardized replacement for laptops with a fixed end charge threshold. Setting it to Long Life would enable battery conservation mode. The standardized user space API would allow applications such as UPower to detect laptops which support this battery longevity mode and set it.

Tested on an Lenovo ideapad U330p.

Quoted 8 lines
Quoted 5 lines

Hi,

i like the idea behind this patch series, the charge_types attribute is indeed
exactly what we need in this case.

Thanks! Credit where credit is due, this idea came from Hans de Goede (who also added charge_types). I only wrote the code.

Add a Suggested-by tag then so the relevant people are easier to find, lets say, after 5 years from now.

Quoted 52 lines
Quoted 4 lines
Quoted 4 lines

  .../ABI/testing/sysfs-platform-ideapad-laptop |   2 + drivers/platform/x86/ideapad-laptop.c         | 126 +++++++++++++++++-

  2 files changed, 125 insertions(+), 3 deletions(-)
Quoted 15 lines
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-ideapad-laptop +0 -0
index 4989ab266682..83eca4c14503 100644
@@ -32,6 +32,8 @@ Date:        Aug 2017
Quoted 6 lines

  KernelVersion:    4.14
  Contact:    [email protected] Description:
+        This interface is deprecated; please use /sys/class/ power_supply/*/charge_types.
+

Maybe it would make sense to move this attribute to Documentation/ABI/ obsolete?

I am not sure what the normal workflow is so I've applied this suggestion in v2.

Quoted 9 lines
Quoted 9 lines

+                       void *ext_data,
+                       enum power_supply_property psp, +                       const union power_supply_propval *val)

Documentation/ABI/testing/sysfs-platform-ideapad-laptop +6 -0
+{
+    struct ideapad_private *priv = ext_data;
+    int err;
+
+    if (psp != POWER_SUPPLY_PROP_CHARGE_TYPES)
+        return -EINVAL;
Quoted 8 lines
Quoted 4 lines

+
+    err = exec_sbmc(priv->adev->handle,
+            (val->intval == POWER_SUPPLY_CHARGE_TYPE_LONGLIFE ? +             SBMC_CONSERVATION_ON : SBMC_CONSERVATION_OFF));

AFAIK the power supply core does not check if val->intval holds a supported charge type value.
Please use a switch case to return -EINVAL in such cases.

From my testing checking val->intval wasn't needed, you'll get an "write
error: invalid argument" when trying to set "Long lifeee".

I believe that is handled in power_supply_store_property, but reading the code I don't really believe that's true? So I've simply switched it over to a switch/case.

Thanks,

Jelle

Signature · 1 line
 i.
#5 lore raw
In reply to Jelle van der Waa
Quoted 38 lines · Jelle van der Waa

From: Jelle van der Waa <[email protected]>

Some Ideapad models support a battery conservation mode which limits the battery charge threshold for longer battery longevity. This is currently exposed via a custom conservation_mode attribute in sysfs.

The newly introduced charge_types sysfs attribute is a standardized replacement for laptops with a fixed end charge threshold. Setting it to Long Life would enable battery conservation mode. The standardized user space API would allow applications such as UPower to detect laptops which support this battery longevity mode and set it.

Tested on an Lenovo ideapad U330p.

---
 .../ABI/testing/sysfs-platform-ideapad-laptop |   2 +
 drivers/platform/x86/ideapad-laptop.c         | 126 +++++++++++++++++-
 2 files changed, 125 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-platform-ideapad-laptop +2 -0
index 4989ab266682..83eca4c14503 100644
@@ -32,6 +32,8 @@ Date:		Aug 2017
 KernelVersion:	4.14
 Contact:	[email protected]
 Description:
+		This interface is deprecated; please use /sys/class/power_supply/*/charge_types.
+
 		Controls whether the conservation mode is enabled or not.
 		This feature limits the maximum battery charge percentage to
 		around 50-60% in order to prolong the lifetime of the battery.
drivers/platform/x86/ideapad-laptop.c +0 -0
index ede483573fe0..fd9127ffd456 100644

drivers/platform/x86/ideapad-laptop.c line 37

Quoted 4 lines
drivers/platform/x86/ideapad-laptop.c +1 -0
@@ -34,12 +34,17 @@
 #include <linux/wmi.h>
 #include "ideapad-laptop.h"
 
+#include <linux/power_supply.h>

Other linux/ includes are in the block above.

Quoted 14 lines
drivers/platform/x86/ideapad-laptop.c +4 -0
+#include <acpi/battery.h>
 #include <acpi/video.h>
 
 #include <dt-bindings/leds/common.h>
 
 #define IDEAPAD_RFKILL_DEV_NUM	3
 
+#define IDEAPAD_CHARGE_TYPES		(BIT(POWER_SUPPLY_CHARGE_TYPE_STANDARD)  | \
+					 BIT(POWER_SUPPLY_CHARGE_TYPE_LONGLIFE))
+
 enum {
 	CFG_CAP_BT_BIT       = 16,
 	CFG_CAP_3G_BIT       = 17,

drivers/platform/x86/ideapad-laptop.c struct ideapad_private { · line 171

Quoted 5 lines
drivers/platform/x86/ideapad-laptop.c +2 -0
@@ -162,6 +167,8 @@ struct ideapad_private {
 	struct backlight_device *blightdev;
 	struct ideapad_dytc_priv *dytc;
 	struct dentry *debug;
+	struct acpi_battery_hook battery_hook;
+	struct power_supply *hooked_battery;

hooked_battery is not used.

drivers/platform/x86/ideapad-laptop.c static ssize_t camera_power_store(struct device *dev, · line 599

Quoted 8 lines
drivers/platform/x86/ideapad-laptop.c +1 -0
 	unsigned long cfg;
 	unsigned long r_touchpad_val;
 	struct {
@@ -589,6 +596,11 @@ static ssize_t camera_power_store(struct device *dev,
 
 static DEVICE_ATTR_RW(camera_power);
 
+static void show_deprecation_warning(struct device *dev)

show_conservation_mode_deprecation_warning();

Quoted 31 lines
drivers/platform/x86/ideapad-laptop.c +9 -1
+{
+	dev_warn_once(dev, "conservation_mode attribute has been deprecated, see charge_types.\n");
+}
+
 static ssize_t conservation_mode_show(struct device *dev,
 				      struct device_attribute *attr,
 				      char *buf)
@@ -597,6 +609,8 @@ static ssize_t conservation_mode_show(struct device *dev,
 	unsigned long result;
 	int err;
 
+	show_deprecation_warning(dev);
+
 	err = eval_gbmd(priv->adev->handle, &result);
 	if (err)
 		return err;
@@ -612,6 +626,8 @@ static ssize_t conservation_mode_store(struct device *dev,
 	bool state;
 	int err;
 
+	show_deprecation_warning(dev);
+
 	err = kstrtobool(buf, &state);
 	if (err)
 		return err;
@@ -1973,10 +1989,99 @@ static const struct dmi_system_id ctrl_ps2_aux_port_list[] = {
 	{}
 };
 
-static void ideapad_check_features(struct ideapad_private *priv)
+static int ideapad_psy_ext_set_prop(struct power_supply *psy,

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 2002

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +10 -0
+				       const struct power_supply_ext *ext,
+				       void *ext_data,
+				       enum power_supply_property psp,
+				       const union power_supply_propval *val)
+{
+	struct ideapad_private *priv = ext_data;
+	int err;
+
+	if (psp != POWER_SUPPLY_PROP_CHARGE_TYPES)
+		return -EINVAL;

This check will never trigger. Same below)

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 2006

Quoted 4 lines
drivers/platform/x86/ideapad-laptop.c +4 -0
+
+	err = exec_sbmc(priv->adev->handle,
+			(val->intval == POWER_SUPPLY_CHARGE_TYPE_LONGLIFE ?
+			 SBMC_CONSERVATION_ON : SBMC_CONSERVATION_OFF));

No need for braces.
Directly "return exec_sbmc()".

Quoted 28 lines
drivers/platform/x86/ideapad-laptop.c +28 -0
+	if (err)
+		return err;
+
+	return 0;
+}
+
+static int ideapad_psy_ext_get_prop(struct power_supply *psy,
+				       const struct power_supply_ext *ext,
+				       void *ext_data,
+				       enum power_supply_property psp,
+				       union power_supply_propval *val)
+{
+	struct ideapad_private *priv = ext_data;
+	unsigned long result;
+	int err;
+
+	if (psp != POWER_SUPPLY_PROP_CHARGE_TYPES)
+		return -EINVAL;
+
+	err = eval_gbmd(priv->adev->handle, &result);
+	if (err)
+		return err;
+
+	if (test_bit(GBMD_CONSERVATION_STATE_BIT, &result))
+		val->intval = POWER_SUPPLY_CHARGE_TYPE_LONGLIFE;
+	else
+		val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
+

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 2044

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +10 -0
+	return 0;
+}
+
+static int ideapad_psy_prop_is_writeable(struct power_supply *psy,
+					    const struct power_supply_ext *ext,
+					    void *data,
+					    enum power_supply_property psp)
+{
+	if (psp == POWER_SUPPLY_PROP_CHARGE_TYPES)
+		return true;

No need for the conditional.

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +10 -0
+
+	return false;
+}
+
+static const enum power_supply_property ideapad_power_supply_props[] = {
+	POWER_SUPPLY_PROP_CHARGE_TYPES,
+};
+
+static const struct power_supply_ext ideapad_battery_ext = {
+	.name			= "ideapad",

drivers/platform/x86/ideapad-laptop.c static const struct dmi_system_id ctrl_ps2_aux_port_list[] = { · line 2064

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +10 -0
+	.properties		= ideapad_power_supply_props,
+	.num_properties		= ARRAY_SIZE(ideapad_power_supply_props),
+	.charge_types		= IDEAPAD_CHARGE_TYPES,
+	.get_property		= ideapad_psy_ext_get_prop,
+	.set_property		= ideapad_psy_ext_set_prop,
+	.property_is_writeable	= ideapad_psy_prop_is_writeable,
+};
+
+static int ideapad_battery_add(struct power_supply *battery,
+			       struct acpi_battery_hook *hook)

No need for the linebreak, the line will be shorter than the one below.

Quoted 29 lines
drivers/platform/x86/ideapad-laptop.c +18 -1
+{
+	struct ideapad_private *priv = container_of(hook, struct ideapad_private, battery_hook);
+
+	return power_supply_register_extension(battery, &ideapad_battery_ext,
+					       &priv->platform_device->dev, priv);
+}
+
+static int ideapad_battery_remove(struct power_supply *battery,
+				  struct acpi_battery_hook *hook)
+{
+	power_supply_unregister_extension(battery, &ideapad_battery_ext);
+
+	return 0;
+}
+
+static int ideapad_check_features(struct ideapad_private *priv)
 {
 	acpi_handle handle = priv->adev->handle;
 	unsigned long val;
+	int err;
 
 	priv->features.set_fn_lock_led =
 		set_fn_lock_led || dmi_check_system(set_fn_lock_led_list);
@@ -1991,8 +2096,19 @@ static void ideapad_check_features(struct ideapad_private *priv)
 	if (!read_ec_data(handle, VPCCMD_R_FAN, &val))
 		priv->features.fan_mode = true;
 
-	if (acpi_has_method(handle, "GBMD") && acpi_has_method(handle, "SBMC"))
+	if (acpi_has_method(handle, "GBMD") && acpi_has_method(handle, "SBMC")) {

drivers/platform/x86/ideapad-laptop.c static void ideapad_check_features(struct ideapad_private *priv) · line 2109

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +9 -0
 		priv->features.conservation_mode = true;
+		priv->battery_hook.add_battery = ideapad_battery_add;
+		priv->battery_hook.remove_battery = ideapad_battery_remove;
+		priv->battery_hook.name = "Ideapad Battery Extension";
+
+		err = devm_battery_hook_register(&priv->platform_device->dev, &priv->battery_hook);
+		if (err) {
+			dev_dbg(&priv->platform_device->dev,
+				"failed to register battery hook: %d\n", err);
+			return err;

Use dev_err_probe().

Quoted 29 lines
drivers/platform/x86/ideapad-laptop.c +7 -1
+		}
+	}
 
 	if (acpi_has_method(handle, "DYTC"))
 		priv->features.dytc = true;
@@ -2027,6 +2143,8 @@ static void ideapad_check_features(struct ideapad_private *priv)
 			}
 		}
 	}
+
+	return 0;
 }
 
 #if IS_ENABLED(CONFIG_ACPI_WMI)
@@ -2175,7 +2293,9 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 	if (err)
 		return err;
 
-	ideapad_check_features(priv);
+	err = ideapad_check_features(priv);
+	if (err)
+		return err;
 
 	ideapad_debugfs_init(priv);
 
Signature · 1 line
2.49.0