Skip to contentSkip to conversation

Hide platform_profile_handler from consumers

PATCH In review Kurt Borja 4 participants 37 messages Jan 16, 2025 – Jan 20, 2025

Subsystems (9)
lore
Share & tools
lore

Kurt Borja

author maintainer
#0 lore raw

v4 cover Hide platform_profile_handler from consumers

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3: https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH v4 1/19 ACPI: platform_profile: Replace *class_dev member with class_dev

Instead of holding a reference to the class device, embed it the platform_profile_handler. This involves manually creating and registering the device and replacing dev_get_drvdata() with the newly created to_pprof_handler() macro.

---
 drivers/acpi/platform_profile.c  | 37 +++++++++++++++++---------------
 include/linux/platform_profile.h |  3 ++-
 2 files changed, 22 insertions(+), 18 deletions(-)
drivers/acpi/platform_profile.c +20 -17
index 4c4200a0b1a6..15f24adc57d4 100644
@@ -5,11 +5,12 @@
 #include <linux/acpi.h>
 #include <linux/bits.h>
 #include <linux/init.h>
-#include <linux/kdev_t.h>
 #include <linux/mutex.h>
 #include <linux/platform_profile.h>
 #include <linux/sysfs.h>
 
+#define to_pprof_handler(d)	(container_of(d, struct platform_profile_handler, class_dev))
+
 static DEFINE_MUTEX(profile_lock);
 
 static const char * const profile_names[] = {
@@ -60,7 +61,7 @@ static int _store_class_profile(struct device *dev, void *data)
 	int *bit = (int *)data;
 
 	lockdep_assert_held(&profile_lock);
-	handler = dev_get_drvdata(dev);
+	handler = to_pprof_handler(dev);
 	if (!test_bit(*bit, handler->choices))
 		return -EOPNOTSUPP;
 
@@ -76,11 +77,11 @@ static int _store_class_profile(struct device *dev, void *data)
  */
 static int _notify_class_profile(struct device *dev, void *data)
 {
-	struct platform_profile_handler *handler = dev_get_drvdata(dev);
+	struct platform_profile_handler *handler = to_pprof_handler(dev);
 
 	lockdep_assert_held(&profile_lock);
-	sysfs_notify(&handler->class_dev->kobj, NULL, "profile");
-	kobject_uevent(&handler->class_dev->kobj, KOBJ_CHANGE);
+	sysfs_notify(&handler->class_dev.kobj, NULL, "profile");
+	kobject_uevent(&handler->class_dev.kobj, KOBJ_CHANGE);
 
 	return 0;
 }
@@ -100,7 +101,7 @@ static int get_class_profile(struct device *dev,
 	int err;
 
 	lockdep_assert_held(&profile_lock);
-	handler = dev_get_drvdata(dev);
+	handler = to_pprof_handler(dev);
 	err = handler->profile_get(handler, &val);
 	if (err) {
 		pr_err("Failed to get profile for handler %s\n", handler->name);
@@ -124,7 +125,7 @@ static int get_class_profile(struct device *dev,
  */
 static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	struct platform_profile_handler *handler = dev_get_drvdata(dev);
+	struct platform_profile_handler *handler = to_pprof_handler(dev);
 
 	return sysfs_emit(buf, "%s\n", handler->name);
 }
@@ -142,7 +143,7 @@ static ssize_t choices_show(struct device *dev,
 			    struct device_attribute *attr,
 			    char *buf)
 {
-	struct platform_profile_handler *handler = dev_get_drvdata(dev);
+	struct platform_profile_handler *handler = to_pprof_handler(dev);
 
 	return _commmon_choices_show(handler->choices, buf);
 }
@@ -229,7 +230,7 @@ static int _aggregate_choices(struct device *dev, void *data)
 	unsigned long *aggregate = data;
 
 	lockdep_assert_held(&profile_lock);
-	handler = dev_get_drvdata(dev);
+	handler = to_pprof_handler(dev);
 	if (test_bit(PLATFORM_PROFILE_LAST, aggregate))
 		bitmap_copy(aggregate, handler->choices, PLATFORM_PROFILE_LAST);
 	else
@@ -410,7 +411,7 @@ static const struct attribute_group platform_profile_group = {
 void platform_profile_notify(struct platform_profile_handler *pprof)
 {
 	scoped_cond_guard(mutex_intr, return, &profile_lock) {
-		_notify_class_profile(pprof->class_dev, NULL);
+		_notify_class_profile(&pprof->class_dev, NULL);
 	}
 	sysfs_notify(acpi_kobj, NULL, "platform_profile");
 }
@@ -476,11 +477,13 @@ int platform_profile_register(struct platform_profile_handler *pprof)
 	pprof->minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
 	if (pprof->minor < 0)
 		return pprof->minor;
-	pprof->class_dev = device_create(&platform_profile_class, pprof->dev,
-					 MKDEV(0, 0), pprof, "platform-profile-%d",
-					 pprof->minor);
-	if (IS_ERR(pprof->class_dev)) {
-		err = PTR_ERR(pprof->class_dev);
+
+	pprof->class_dev.class = &platform_profile_class;
+	pprof->class_dev.parent = pprof->dev;
+	dev_set_name(&pprof->class_dev, "platform-profile-%d", pprof->minor);
+	err = device_register(&pprof->class_dev);
+	if (err) {
+		put_device(&pprof->class_dev);
 		goto cleanup_ida;
 	}
 
@@ -493,7 +496,7 @@ int platform_profile_register(struct platform_profile_handler *pprof)
 	return 0;
 
 cleanup_cur:
-	device_unregister(pprof->class_dev);
+	device_unregister(&pprof->class_dev);
 
 cleanup_ida:
 	ida_free(&platform_profile_ida, pprof->minor);
@@ -508,7 +511,7 @@ int platform_profile_remove(struct platform_profile_handler *pprof)
 	guard(mutex)(&profile_lock);
 
 	id = pprof->minor;
-	device_unregister(pprof->class_dev);
+	device_unregister(&pprof->class_dev);
 	ida_free(&platform_profile_ida, id);
 
 	sysfs_notify(acpi_kobj, NULL, "platform_profile");
include/linux/platform_profile.h +2 -1
index f1cd4b65e351..8a9b8754f9ac 100644
@@ -9,6 +9,7 @@
 #ifndef _PLATFORM_PROFILE_H_
 #define _PLATFORM_PROFILE_H_
 
+#include <linux/device.h>
 #include <linux/bitops.h>
 
 /*
@@ -30,7 +31,7 @@ enum platform_profile_option {
 struct platform_profile_handler {
 	const char *name;
 	struct device *dev;
-	struct device *class_dev;
+	struct device class_dev;
 	int minor;
 	unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
 	int (*profile_get)(struct platform_profile_handler *pprof,
Signature · 1 line
2.48.1
author maintainer
#2 lore raw

PATCH v4 2/19 ACPI: platform_profile: Let drivers set drvdata to the class device

In reply to Kurt Borja

Add *drvdata to platform_profile_register() signature and assign it to the class device.

While at it, pass specific driver state as drvdata to replace uses of container_of() with dev_get_drvdata().

---
 drivers/acpi/platform_profile.c                     | 7 ++++---
 drivers/platform/surface/surface_platform_profile.c | 6 +++---
 drivers/platform/x86/acer-wmi.c                     | 2 +-
 drivers/platform/x86/amd/pmf/sps.c                  | 6 +++---
 drivers/platform/x86/asus-wmi.c                     | 6 +++---
 drivers/platform/x86/dell/alienware-wmi.c           | 2 +-
 drivers/platform/x86/dell/dell-pc.c                 | 2 +-
 drivers/platform/x86/hp/hp-wmi.c                    | 2 +-
 drivers/platform/x86/ideapad-laptop.c               | 6 +++---
 drivers/platform/x86/inspur_platform_profile.c      | 8 +++-----
 drivers/platform/x86/thinkpad_acpi.c                | 2 +-
 include/linux/platform_profile.h                    | 4 ++--
 12 files changed, 26 insertions(+), 27 deletions(-)
drivers/acpi/platform_profile.c +4 -3
index 15f24adc57d4..689541d2e66c 100644
@@ -460,7 +460,7 @@ int platform_profile_cycle(void)
 }
 EXPORT_SYMBOL_GPL(platform_profile_cycle);
 
-int platform_profile_register(struct platform_profile_handler *pprof)
+int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata)
 {
 	int err;
 
@@ -480,6 +480,7 @@ int platform_profile_register(struct platform_profile_handler *pprof)
 
 	pprof->class_dev.class = &platform_profile_class;
 	pprof->class_dev.parent = pprof->dev;
+	dev_set_drvdata(&pprof->class_dev, drvdata);
 	dev_set_name(&pprof->class_dev, "platform-profile-%d", pprof->minor);
 	err = device_register(&pprof->class_dev);
 	if (err) {
@@ -529,7 +530,7 @@ static void devm_platform_profile_release(struct device *dev, void *res)
 	platform_profile_remove(*pprof);
 }
 
-int devm_platform_profile_register(struct platform_profile_handler *pprof)
+int devm_platform_profile_register(struct platform_profile_handler *pprof, void *drvdata)
 {
 	struct platform_profile_handler **dr;
 	int ret;
@@ -538,7 +539,7 @@ int devm_platform_profile_register(struct platform_profile_handler *pprof)
 	if (!dr)
 		return -ENOMEM;
 
-	ret = platform_profile_register(pprof);
+	ret = platform_profile_register(pprof, drvdata);
 	if (ret) {
 		devres_free(dr);
 		return ret;
drivers/platform/surface/surface_platform_profile.c +3 -3
index 6c87e982bfc8..edb9362003a4 100644
@@ -161,7 +161,7 @@ static int ssam_platform_profile_get(struct platform_profile_handler *pprof,
 	enum ssam_tmp_profile tp;
 	int status;
 
-	tpd = container_of(pprof, struct ssam_platform_profile_device, handler);
+	tpd = dev_get_drvdata(&pprof->class_dev);
 
 	status = ssam_tmp_profile_get(tpd->sdev, &tp);
 	if (status)
@@ -181,7 +181,7 @@ static int ssam_platform_profile_set(struct platform_profile_handler *pprof,
 	struct ssam_platform_profile_device *tpd;
 	int tp;
 
-	tpd = container_of(pprof, struct ssam_platform_profile_device, handler);
+	tpd = dev_get_drvdata(&pprof->class_dev);
 
 	tp = convert_profile_to_ssam_tmp(tpd->sdev, profile);
 	if (tp < 0)
@@ -224,7 +224,7 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
 	set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, tpd->handler.choices);
 	set_bit(PLATFORM_PROFILE_PERFORMANCE, tpd->handler.choices);
 
-	return platform_profile_register(&tpd->handler);
+	return platform_profile_register(&tpd->handler, tpd);
 }
 
 static void surface_platform_profile_remove(struct ssam_device *sdev)
drivers/platform/x86/acer-wmi.c +1 -1
index acf610d59168..1aedf0ef4189 100644
@@ -2073,7 +2073,7 @@ static int acer_platform_profile_setup(struct platform_device *device)
 				ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
 		}
 
-		err = platform_profile_register(&platform_profile_handler);
+		err = platform_profile_register(&platform_profile_handler, NULL);
 		if (err)
 			return err;
 
drivers/platform/x86/amd/pmf/sps.c +3 -3
index bd2bd6cfc39a..259a598acd3e 100644
@@ -285,7 +285,7 @@ bool is_pprof_balanced(struct amd_pmf_dev *pmf)
 static int amd_pmf_profile_get(struct platform_profile_handler *pprof,
 			       enum platform_profile_option *profile)
 {
-	struct amd_pmf_dev *pmf = container_of(pprof, struct amd_pmf_dev, pprof);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
 
 	*profile = pmf->current_profile;
 	return 0;
@@ -366,7 +366,7 @@ int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev)
 static int amd_pmf_profile_set(struct platform_profile_handler *pprof,
 			       enum platform_profile_option profile)
 {
-	struct amd_pmf_dev *pmf = container_of(pprof, struct amd_pmf_dev, pprof);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
 	int ret = 0;
 
 	pmf->current_profile = profile;
@@ -416,7 +416,7 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
 	set_bit(PLATFORM_PROFILE_PERFORMANCE, dev->pprof.choices);
 
 	/* Create platform_profile structure and register */
-	err = platform_profile_register(&dev->pprof);
+	err = platform_profile_register(&dev->pprof, dev);
 	if (err)
 		dev_err(dev->dev, "Failed to register SPS support, this is most likely an SBIOS bug: %d\n",
 			err);
drivers/platform/x86/asus-wmi.c +3 -3
index 6c674de60ec0..f91099792cb9 100644
@@ -3806,7 +3806,7 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 	struct asus_wmi *asus;
 	int tp;
 
-	asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
+	asus = dev_get_drvdata(&pprof->class_dev);
 	tp = asus->throttle_thermal_policy_mode;
 
 	switch (tp) {
@@ -3832,7 +3832,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
 	struct asus_wmi *asus;
 	int tp;
 
-	asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
+	asus = dev_get_drvdata(&pprof->class_dev);
 
 	switch (profile) {
 	case PLATFORM_PROFILE_PERFORMANCE:
@@ -3887,7 +3887,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 	set_bit(PLATFORM_PROFILE_PERFORMANCE,
 		asus->platform_profile_handler.choices);
 
-	err = platform_profile_register(&asus->platform_profile_handler);
+	err = platform_profile_register(&asus->platform_profile_handler, asus);
 	if (err == -EEXIST) {
 		pr_warn("%s, a platform_profile handler is already registered\n", __func__);
 		return 0;
drivers/platform/x86/dell/alienware-wmi.c +1 -1
index d7f577e0d146..154c417a438c 100644
@@ -1129,7 +1129,7 @@ static int create_thermal_profile(struct platform_device *platform_device)
 	pp_handler.name = "alienware-wmi";
 	pp_handler.dev = &platform_device->dev;
 
-	return devm_platform_profile_register(&pp_handler);
+	return devm_platform_profile_register(&pp_handler, NULL);
 }
 
 /*
drivers/platform/x86/dell/dell-pc.c +1 -1
index 3797a5721dbd..1a0a721d706f 100644
@@ -271,7 +271,7 @@ static int thermal_init(void)
 		set_bit(PLATFORM_PROFILE_PERFORMANCE, thermal_handler->choices);
 
 	/* Clean up if failed */
-	ret = platform_profile_register(thermal_handler);
+	ret = platform_profile_register(thermal_handler, NULL);
 	if (ret)
 		goto cleanup_thermal_handler;
 
drivers/platform/x86/hp/hp-wmi.c +1 -1
index 6d6e13a0c6e2..8e5e1422e024 100644
@@ -1629,7 +1629,7 @@ static int thermal_profile_setup(struct platform_device *device)
 	set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
 	set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
 
-	err = platform_profile_register(&platform_profile_handler);
+	err = platform_profile_register(&platform_profile_handler, NULL);
 	if (err)
 		return err;
 
drivers/platform/x86/ideapad-laptop.c +3 -3
index dc98f862a06d..ed0d880a07a9 100644
@@ -936,7 +936,7 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe
 static int dytc_profile_get(struct platform_profile_handler *pprof,
 			    enum platform_profile_option *profile)
 {
-	struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof);
+	struct ideapad_dytc_priv *dytc = dev_get_drvdata(&pprof->class_dev);
 
 	*profile = dytc->current_profile;
 	return 0;
@@ -989,7 +989,7 @@ static int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd,
 static int dytc_profile_set(struct platform_profile_handler *pprof,
 			    enum platform_profile_option profile)
 {
-	struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof);
+	struct ideapad_dytc_priv *dytc = dev_get_drvdata(&pprof->class_dev);
 	struct ideapad_private *priv = dytc->priv;
 	unsigned long output;
 	int err;
@@ -1114,7 +1114,7 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
 	set_bit(PLATFORM_PROFILE_PERFORMANCE, priv->dytc->pprof.choices);
 
 	/* Create platform_profile structure and register */
-	err = platform_profile_register(&priv->dytc->pprof);
+	err = platform_profile_register(&priv->dytc->pprof, &priv->dytc);
 	if (err)
 		goto pp_reg_failed;
 
drivers/platform/x86/inspur_platform_profile.c +3 -5
index 53af73a7fbf7..471fca50d1c9 100644
@@ -87,8 +87,7 @@ static int inspur_wmi_perform_query(struct wmi_device *wdev,
 static int inspur_platform_profile_set(struct platform_profile_handler *pprof,
 				       enum platform_profile_option profile)
 {
-	struct inspur_wmi_priv *priv = container_of(pprof, struct inspur_wmi_priv,
-						    handler);
+	struct inspur_wmi_priv *priv = dev_get_drvdata(&pprof->class_dev);
 	u8 ret_code[4] = {0, 0, 0, 0};
 	int ret;
 
@@ -135,8 +134,7 @@ static int inspur_platform_profile_set(struct platform_profile_handler *pprof,
 static int inspur_platform_profile_get(struct platform_profile_handler *pprof,
 				       enum platform_profile_option *profile)
 {
-	struct inspur_wmi_priv *priv = container_of(pprof, struct inspur_wmi_priv,
-						    handler);
+	struct inspur_wmi_priv *priv = dev_get_drvdata(&pprof->class_dev);
 	u8 ret_code[4] = {0, 0, 0, 0};
 	int ret;
 
@@ -186,7 +184,7 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
 	set_bit(PLATFORM_PROFILE_BALANCED, priv->handler.choices);
 	set_bit(PLATFORM_PROFILE_PERFORMANCE, priv->handler.choices);
 
-	return platform_profile_register(&priv->handler);
+	return platform_profile_register(&priv->handler, priv);
 }
 
 static void inspur_wmi_remove(struct wmi_device *wdev)
drivers/platform/x86/thinkpad_acpi.c +1 -1
index d99573e7a983..8be3f4e5366d 100644
@@ -10641,7 +10641,7 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 
 	dytc_profile.dev = &tpacpi_pdev->dev;
 	/* Create platform_profile structure and register */
-	err = platform_profile_register(&dytc_profile);
+	err = platform_profile_register(&dytc_profile, NULL);
 	/*
 	 * If for some reason platform_profiles aren't enabled
 	 * don't quit terminally.
include/linux/platform_profile.h +2 -2
index 8a9b8754f9ac..1c8fdda51eaa 100644
@@ -40,9 +40,9 @@ struct platform_profile_handler {
 				enum platform_profile_option profile);
 };
 
-int platform_profile_register(struct platform_profile_handler *pprof);
+int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
 int platform_profile_remove(struct platform_profile_handler *pprof);
-int devm_platform_profile_register(struct platform_profile_handler *pprof);
+int devm_platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
 int platform_profile_cycle(void);
 void platform_profile_notify(struct platform_profile_handler *pprof);
 
Signature · 1 line
2.48.1
author maintainer
#4 lore raw

PATCH v4 3/19 ACPI: platform_profile: Remove platform_profile_handler from callbacks

In reply to Kurt Borja

Devices can now set drvdata to the class device, thus passing the platform_profile_handler to callbacks is unnecessary. Instead pass the class device.

---
 drivers/acpi/platform_profile.c                    |  4 ++--
 .../platform/surface/surface_platform_profile.c    |  8 ++++----
 drivers/platform/x86/acer-wmi.c                    |  4 ++--
 drivers/platform/x86/amd/pmf/sps.c                 |  8 ++++----
 drivers/platform/x86/asus-wmi.c                    |  8 ++++----
 drivers/platform/x86/dell/alienware-wmi.c          |  4 ++--
 drivers/platform/x86/dell/dell-pc.c                |  4 ++--
 drivers/platform/x86/hp/hp-wmi.c                   | 14 +++++++-------
 drivers/platform/x86/ideapad-laptop.c              |  8 ++++----
 drivers/platform/x86/inspur_platform_profile.c     |  8 ++++----
 drivers/platform/x86/thinkpad_acpi.c               |  4 ++--
 include/linux/platform_profile.h                   |  6 ++----
 12 files changed, 39 insertions(+), 41 deletions(-)
drivers/acpi/platform_profile.c +2 -2
index 689541d2e66c..bd90aa4e8371 100644
@@ -65,7 +65,7 @@ static int _store_class_profile(struct device *dev, void *data)
 	if (!test_bit(*bit, handler->choices))
 		return -EOPNOTSUPP;
 
-	return handler->profile_set(handler, *bit);
+	return handler->profile_set(dev, *bit);
 }
 
 /**
@@ -102,7 +102,7 @@ static int get_class_profile(struct device *dev,
 
 	lockdep_assert_held(&profile_lock);
 	handler = to_pprof_handler(dev);
-	err = handler->profile_get(handler, &val);
+	err = handler->profile_get(dev, &val);
 	if (err) {
 		pr_err("Failed to get profile for handler %s\n", handler->name);
 		return err;
drivers/platform/surface/surface_platform_profile.c +4 -4
index edb9362003a4..26c1230e75df 100644
@@ -154,14 +154,14 @@ static int convert_profile_to_ssam_fan(struct ssam_device *sdev, enum platform_p
 	}
 }
 
-static int ssam_platform_profile_get(struct platform_profile_handler *pprof,
+static int ssam_platform_profile_get(struct device *dev,
 				     enum platform_profile_option *profile)
 {
 	struct ssam_platform_profile_device *tpd;
 	enum ssam_tmp_profile tp;
 	int status;
 
-	tpd = dev_get_drvdata(&pprof->class_dev);
+	tpd = dev_get_drvdata(dev);
 
 	status = ssam_tmp_profile_get(tpd->sdev, &tp);
 	if (status)
@@ -175,13 +175,13 @@ static int ssam_platform_profile_get(struct platform_profile_handler *pprof,
 	return 0;
 }
 
-static int ssam_platform_profile_set(struct platform_profile_handler *pprof,
+static int ssam_platform_profile_set(struct device *dev,
 				     enum platform_profile_option profile)
 {
 	struct ssam_platform_profile_device *tpd;
 	int tp;
 
-	tpd = dev_get_drvdata(&pprof->class_dev);
+	tpd = dev_get_drvdata(dev);
 
 	tp = convert_profile_to_ssam_tmp(tpd->sdev, profile);
 	if (tp < 0)
drivers/platform/x86/acer-wmi.c +2 -2
index 1aedf0ef4189..c68c0d744a69 100644
@@ -1950,7 +1950,7 @@ static int acer_toggle_turbo(void)
 }
 
 static int
-acer_predator_v4_platform_profile_get(struct platform_profile_handler *pprof,
+acer_predator_v4_platform_profile_get(struct device *dev,
 				      enum platform_profile_option *profile)
 {
 	u8 tp;
@@ -1984,7 +1984,7 @@ acer_predator_v4_platform_profile_get(struct platform_profile_handler *pprof,
 }
 
 static int
-acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,
+acer_predator_v4_platform_profile_set(struct device *dev,
 				      enum platform_profile_option profile)
 {
 	int err, tp;
drivers/platform/x86/amd/pmf/sps.c +4 -4
index 259a598acd3e..cf2e51f67787 100644
@@ -282,10 +282,10 @@ bool is_pprof_balanced(struct amd_pmf_dev *pmf)
 	return (pmf->current_profile == PLATFORM_PROFILE_BALANCED) ? true : false;
 }
 
-static int amd_pmf_profile_get(struct platform_profile_handler *pprof,
+static int amd_pmf_profile_get(struct device *dev,
 			       enum platform_profile_option *profile)
 {
-	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(dev);
 
 	*profile = pmf->current_profile;
 	return 0;
@@ -363,10 +363,10 @@ int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev)
 	return 0;
 }
 
-static int amd_pmf_profile_set(struct platform_profile_handler *pprof,
+static int amd_pmf_profile_set(struct device *dev,
 			       enum platform_profile_option profile)
 {
-	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(dev);
 	int ret = 0;
 
 	pmf->current_profile = profile;
drivers/platform/x86/asus-wmi.c +4 -4
index f91099792cb9..6b8b30551d36 100644
@@ -3800,13 +3800,13 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
 static DEVICE_ATTR_RW(throttle_thermal_policy);
 
 /* Platform profile ***********************************************************/
-static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
+static int asus_wmi_platform_profile_get(struct device *dev,
 					enum platform_profile_option *profile)
 {
 	struct asus_wmi *asus;
 	int tp;
 
-	asus = dev_get_drvdata(&pprof->class_dev);
+	asus = dev_get_drvdata(dev);
 	tp = asus->throttle_thermal_policy_mode;
 
 	switch (tp) {
@@ -3826,13 +3826,13 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 	return 0;
 }
 
-static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
+static int asus_wmi_platform_profile_set(struct device *dev,
 					enum platform_profile_option profile)
 {
 	struct asus_wmi *asus;
 	int tp;
 
-	asus = dev_get_drvdata(&pprof->class_dev);
+	asus = dev_get_drvdata(dev);
 
 	switch (profile) {
 	case PLATFORM_PROFILE_PERFORMANCE:
drivers/platform/x86/dell/alienware-wmi.c +2 -2
index 154c417a438c..0346f8e88bf8 100644
@@ -1026,7 +1026,7 @@ static int wmax_game_shift_status(u8 operation, u32 *out_data)
 	return 0;
 }
 
-static int thermal_profile_get(struct platform_profile_handler *pprof,
+static int thermal_profile_get(struct device *dev,
 			       enum platform_profile_option *profile)
 {
 	u32 out_data;
@@ -1052,7 +1052,7 @@ static int thermal_profile_get(struct platform_profile_handler *pprof,
 	return 0;
 }
 
-static int thermal_profile_set(struct platform_profile_handler *pprof,
+static int thermal_profile_set(struct device *dev,
 			       enum platform_profile_option profile)
 {
 	if (quirks->gmode) {
drivers/platform/x86/dell/dell-pc.c +2 -2
index 1a0a721d706f..c86b05b5a1cb 100644
@@ -185,7 +185,7 @@ static int thermal_set_mode(enum thermal_mode_bits state)
 	return dell_send_request(&buffer, CLASS_INFO, SELECT_THERMAL_MANAGEMENT);
 }
 
-static int thermal_platform_profile_set(struct platform_profile_handler *pprof,
+static int thermal_platform_profile_set(struct device *dev,
 					enum platform_profile_option profile)
 {
 	switch (profile) {
@@ -202,7 +202,7 @@ static int thermal_platform_profile_set(struct platform_profile_handler *pprof,
 	}
 }
 
-static int thermal_platform_profile_get(struct platform_profile_handler *pprof,
+static int thermal_platform_profile_get(struct device *dev,
 					enum platform_profile_option *profile)
 {
 	int ret;
drivers/platform/x86/hp/hp-wmi.c +7 -7
index 8e5e1422e024..b8e62dc9cecd 100644
@@ -1221,7 +1221,7 @@ static int platform_profile_omen_get_ec(enum platform_profile_option *profile)
 	return 0;
 }
 
-static int platform_profile_omen_get(struct platform_profile_handler *pprof,
+static int platform_profile_omen_get(struct device *dev,
 				     enum platform_profile_option *profile)
 {
 	/*
@@ -1318,7 +1318,7 @@ static int platform_profile_omen_set_ec(enum platform_profile_option profile)
 	return 0;
 }
 
-static int platform_profile_omen_set(struct platform_profile_handler *pprof,
+static int platform_profile_omen_set(struct device *dev,
 				     enum platform_profile_option profile)
 {
 	int err;
@@ -1345,7 +1345,7 @@ static int thermal_profile_set(int thermal_profile)
 							   sizeof(thermal_profile), 0);
 }
 
-static int hp_wmi_platform_profile_get(struct platform_profile_handler *pprof,
+static int hp_wmi_platform_profile_get(struct device *dev,
 					enum platform_profile_option *profile)
 {
 	int tp;
@@ -1374,7 +1374,7 @@ static int hp_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 	return 0;
 }
 
-static int hp_wmi_platform_profile_set(struct platform_profile_handler *pprof,
+static int hp_wmi_platform_profile_set(struct device *dev,
 					enum platform_profile_option profile)
 {
 	int err, tp;
@@ -1440,11 +1440,11 @@ static int platform_profile_victus_get_ec(enum platform_profile_option *profile)
 	return 0;
 }
 
-static int platform_profile_victus_get(struct platform_profile_handler *pprof,
+static int platform_profile_victus_get(struct device *dev,
 				       enum platform_profile_option *profile)
 {
 	/* Same behaviour as platform_profile_omen_get */
-	return platform_profile_omen_get(pprof, profile);
+	return platform_profile_omen_get(dev, profile);
 }
 
 static int platform_profile_victus_set_ec(enum platform_profile_option profile)
@@ -1472,7 +1472,7 @@ static int platform_profile_victus_set_ec(enum platform_profile_option profile)
 	return 0;
 }
 
-static int platform_profile_victus_set(struct platform_profile_handler *pprof,
+static int platform_profile_victus_set(struct device *dev,
 				       enum platform_profile_option profile)
 {
 	int err;
drivers/platform/x86/ideapad-laptop.c +4 -4
index ed0d880a07a9..fc317f42bb82 100644
@@ -933,10 +933,10 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe
  * dytc_profile_get: Function to register with platform_profile
  * handler. Returns current platform profile.
  */
-static int dytc_profile_get(struct platform_profile_handler *pprof,
+static int dytc_profile_get(struct device *dev,
 			    enum platform_profile_option *profile)
 {
-	struct ideapad_dytc_priv *dytc = dev_get_drvdata(&pprof->class_dev);
+	struct ideapad_dytc_priv *dytc = dev_get_drvdata(dev);
 
 	*profile = dytc->current_profile;
 	return 0;
@@ -986,10 +986,10 @@ static int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd,
  * dytc_profile_set: Function to register with platform_profile
  * handler. Sets current platform profile.
  */
-static int dytc_profile_set(struct platform_profile_handler *pprof,
+static int dytc_profile_set(struct device *dev,
 			    enum platform_profile_option profile)
 {
-	struct ideapad_dytc_priv *dytc = dev_get_drvdata(&pprof->class_dev);
+	struct ideapad_dytc_priv *dytc = dev_get_drvdata(dev);
 	struct ideapad_private *priv = dytc->priv;
 	unsigned long output;
 	int err;
drivers/platform/x86/inspur_platform_profile.c +4 -4
index 471fca50d1c9..47d2dbbf3392 100644
@@ -84,10 +84,10 @@ static int inspur_wmi_perform_query(struct wmi_device *wdev,
  *         0x0: No Error
  *         0x1: Error
  */
-static int inspur_platform_profile_set(struct platform_profile_handler *pprof,
+static int inspur_platform_profile_set(struct device *dev,
 				       enum platform_profile_option profile)
 {
-	struct inspur_wmi_priv *priv = dev_get_drvdata(&pprof->class_dev);
+	struct inspur_wmi_priv *priv = dev_get_drvdata(dev);
 	u8 ret_code[4] = {0, 0, 0, 0};
 	int ret;
 
@@ -131,10 +131,10 @@ static int inspur_platform_profile_set(struct platform_profile_handler *pprof,
  *         0x1: Performance Mode
  *         0x2: Power Saver Mode
  */
-static int inspur_platform_profile_get(struct platform_profile_handler *pprof,
+static int inspur_platform_profile_get(struct device *dev,
 				       enum platform_profile_option *profile)
 {
-	struct inspur_wmi_priv *priv = dev_get_drvdata(&pprof->class_dev);
+	struct inspur_wmi_priv *priv = dev_get_drvdata(dev);
 	u8 ret_code[4] = {0, 0, 0, 0};
 	int ret;
 
drivers/platform/x86/thinkpad_acpi.c +2 -2
index 8be3f4e5366d..0abe22228fdb 100644
@@ -10415,7 +10415,7 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe
  * dytc_profile_get: Function to register with platform_profile
  * handler. Returns current platform profile.
  */
-static int dytc_profile_get(struct platform_profile_handler *pprof,
+static int dytc_profile_get(struct device *dev,
 			    enum platform_profile_option *profile)
 {
 	*profile = dytc_current_profile;
@@ -10490,7 +10490,7 @@ static int dytc_cql_command(int command, int *output)
  * dytc_profile_set: Function to register with platform_profile
  * handler. Sets current platform profile.
  */
-static int dytc_profile_set(struct platform_profile_handler *pprof,
+static int dytc_profile_set(struct device *dev,
 			    enum platform_profile_option profile)
 {
 	int perfmode;
include/linux/platform_profile.h +2 -4
index 1c8fdda51eaa..5296d886c243 100644
@@ -34,10 +34,8 @@ struct platform_profile_handler {
 	struct device class_dev;
 	int minor;
 	unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
-	int (*profile_get)(struct platform_profile_handler *pprof,
-				enum platform_profile_option *profile);
-	int (*profile_set)(struct platform_profile_handler *pprof,
-				enum platform_profile_option profile);
+	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
+	int (*profile_set)(struct device *dev, enum platform_profile_option profile);
 };
 
 int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
Signature · 1 line
2.48.1
author maintainer
#6 lore raw

PATCH v4 4/19 ACPI: platform_profile: Add `ops` member to handlers

In reply to Kurt Borja

Replace *profile_get and *profile_set members with a general *ops member.

---
 drivers/acpi/platform_profile.c               |  6 ++---
 .../surface/surface_platform_profile.c        |  8 +++++--
 drivers/platform/x86/acer-wmi.c               | 11 +++++----
 drivers/platform/x86/amd/pmf/sps.c            |  8 +++++--
 drivers/platform/x86/asus-wmi.c               |  8 +++++--
 drivers/platform/x86/dell/alienware-wmi.c     |  8 +++++--
 drivers/platform/x86/dell/dell-pc.c           |  8 +++++--
 drivers/platform/x86/hp/hp-wmi.c              | 24 ++++++++++++++-----
 drivers/platform/x86/ideapad-laptop.c         |  8 +++++--
 .../platform/x86/inspur_platform_profile.c    |  8 +++++--
 drivers/platform/x86/thinkpad_acpi.c          |  8 +++++--
 include/linux/platform_profile.h              | 10 ++++++--
 12 files changed, 84 insertions(+), 31 deletions(-)
drivers/acpi/platform_profile.c +3 -3
index bd90aa4e8371..161a05d57b0f 100644
@@ -65,7 +65,7 @@ static int _store_class_profile(struct device *dev, void *data)
 	if (!test_bit(*bit, handler->choices))
 		return -EOPNOTSUPP;
 
-	return handler->profile_set(dev, *bit);
+	return handler->ops->profile_set(dev, *bit);
 }
 
 /**
@@ -102,7 +102,7 @@ static int get_class_profile(struct device *dev,
 
 	lockdep_assert_held(&profile_lock);
 	handler = to_pprof_handler(dev);
-	err = handler->profile_get(dev, &val);
+	err = handler->ops->profile_get(dev, &val);
 	if (err) {
 		pr_err("Failed to get profile for handler %s\n", handler->name);
 		return err;
@@ -466,7 +466,7 @@ int platform_profile_register(struct platform_profile_handler *pprof, void *drvd
 
 	/* Sanity check the profile handler */
 	if (!pprof || bitmap_empty(pprof->choices, PLATFORM_PROFILE_LAST) ||
-	    !pprof->profile_set || !pprof->profile_get) {
+	    !pprof->ops->profile_set || !pprof->ops->profile_get) {
 		pr_err("platform_profile: handler is invalid\n");
 		return -EINVAL;
 	}
drivers/platform/surface/surface_platform_profile.c +6 -2
index 26c1230e75df..76967bfeeef8 100644
@@ -201,6 +201,11 @@ static int ssam_platform_profile_set(struct device *dev,
 	return tp;
 }
 
+static const struct platform_profile_ops ssam_platform_profile_ops = {
+	.profile_get = ssam_platform_profile_get,
+	.profile_set = ssam_platform_profile_set,
+};
+
 static int surface_platform_profile_probe(struct ssam_device *sdev)
 {
 	struct ssam_platform_profile_device *tpd;
@@ -214,8 +219,7 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
 
 	tpd->handler.name = "Surface Platform Profile";
 	tpd->handler.dev = &sdev->dev;
-	tpd->handler.profile_get = ssam_platform_profile_get;
-	tpd->handler.profile_set = ssam_platform_profile_set;
+	tpd->handler.ops = &ssam_platform_profile_ops;
 
 	tpd->has_fan = device_property_read_bool(&sdev->dev, "has_fan");
 
drivers/platform/x86/acer-wmi.c +7 -4
index c68c0d744a69..63e6bd1fe339 100644
@@ -2019,6 +2019,11 @@ acer_predator_v4_platform_profile_set(struct device *dev,
 	return 0;
 }
 
+static const struct platform_profile_ops acer_predator_v4_platform_profile_ops = {
+	.profile_get = acer_predator_v4_platform_profile_get,
+	.profile_set = acer_predator_v4_platform_profile_set,
+};
+
 static int acer_platform_profile_setup(struct platform_device *device)
 {
 	if (quirks->predator_v4) {
@@ -2027,10 +2032,8 @@ static int acer_platform_profile_setup(struct platform_device *device)
 
 		platform_profile_handler.name = "acer-wmi";
 		platform_profile_handler.dev = &device->dev;
-		platform_profile_handler.profile_get =
-			acer_predator_v4_platform_profile_get;
-		platform_profile_handler.profile_set =
-			acer_predator_v4_platform_profile_set;
+		platform_profile_handler.ops =
+			&acer_predator_v4_platform_profile_ops;
 
 		err = WMID_gaming_get_misc_setting(ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES,
 						   (u8 *)&supported_profiles);
drivers/platform/x86/amd/pmf/sps.c +6 -2
index cf2e51f67787..6ae82ae86d22 100644
@@ -387,6 +387,11 @@ static int amd_pmf_profile_set(struct device *dev,
 	return 0;
 }
 
+static const struct platform_profile_ops amd_pmf_profile_ops = {
+	.profile_get = amd_pmf_profile_get,
+	.profile_set = amd_pmf_profile_set,
+};
+
 int amd_pmf_init_sps(struct amd_pmf_dev *dev)
 {
 	int err;
@@ -407,8 +412,7 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
 
 	dev->pprof.name = "amd-pmf";
 	dev->pprof.dev = dev->dev;
-	dev->pprof.profile_get = amd_pmf_profile_get;
-	dev->pprof.profile_set = amd_pmf_profile_set;
+	dev->pprof.ops = &amd_pmf_profile_ops;
 
 	/* Setup supported modes */
 	set_bit(PLATFORM_PROFILE_LOW_POWER, dev->pprof.choices);
drivers/platform/x86/asus-wmi.c +6 -2
index 6b8b30551d36..992956c89d38 100644
@@ -3852,6 +3852,11 @@ static int asus_wmi_platform_profile_set(struct device *dev,
 	return throttle_thermal_policy_write(asus);
 }
 
+static const struct platform_profile_ops asus_wmi_platform_profile_ops = {
+	.profile_get = asus_wmi_platform_profile_get,
+	.profile_set = asus_wmi_platform_profile_set,
+};
+
 static int platform_profile_setup(struct asus_wmi *asus)
 {
 	struct device *dev = &asus->platform_device->dev;
@@ -3878,8 +3883,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 
 	asus->platform_profile_handler.name = "asus-wmi";
 	asus->platform_profile_handler.dev = dev;
-	asus->platform_profile_handler.profile_get = asus_wmi_platform_profile_get;
-	asus->platform_profile_handler.profile_set = asus_wmi_platform_profile_set;
+	asus->platform_profile_handler.ops = &asus_wmi_platform_profile_ops;
 
 	set_bit(PLATFORM_PROFILE_QUIET, asus->platform_profile_handler.choices);
 	set_bit(PLATFORM_PROFILE_BALANCED,
drivers/platform/x86/dell/alienware-wmi.c +6 -2
index 0346f8e88bf8..b8359b177a0f 100644
@@ -1078,6 +1078,11 @@ static int thermal_profile_set(struct device *dev,
 	return wmax_thermal_control(supported_thermal_profiles[profile]);
 }
 
+static const struct platform_profile_ops awcc_platform_profile_ops = {
+	.profile_get = thermal_profile_get,
+	.profile_set = thermal_profile_set,
+};
+
 static int create_thermal_profile(struct platform_device *platform_device)
 {
 	enum platform_profile_option profile;
@@ -1124,10 +1129,9 @@ static int create_thermal_profile(struct platform_device *platform_device)
 		set_bit(PLATFORM_PROFILE_PERFORMANCE, pp_handler.choices);
 	}
 
-	pp_handler.profile_get = thermal_profile_get;
-	pp_handler.profile_set = thermal_profile_set;
 	pp_handler.name = "alienware-wmi";
 	pp_handler.dev = &platform_device->dev;
+	pp_handler.ops = &awcc_platform_profile_ops;
 
 	return devm_platform_profile_register(&pp_handler, NULL);
 }
drivers/platform/x86/dell/dell-pc.c +6 -2
index c86b05b5a1cb..9010a231f209 100644
@@ -231,6 +231,11 @@ static int thermal_platform_profile_get(struct device *dev,
 	return 0;
 }
 
+static const struct platform_profile_ops dell_pc_platform_profile_ops = {
+	.profile_get = thermal_platform_profile_get,
+	.profile_set = thermal_platform_profile_set,
+};
+
 static int thermal_init(void)
 {
 	int ret;
@@ -258,8 +263,7 @@ static int thermal_init(void)
 	}
 	thermal_handler->name = "dell-pc";
 	thermal_handler->dev = &platform_device->dev;
-	thermal_handler->profile_get = thermal_platform_profile_get;
-	thermal_handler->profile_set = thermal_platform_profile_set;
+	thermal_handler->ops = &dell_pc_platform_profile_ops;
 
 	if (supported_modes & DELL_QUIET)
 		set_bit(PLATFORM_PROFILE_QUIET, thermal_handler->choices);
drivers/platform/x86/hp/hp-wmi.c +18 -6
index b8e62dc9cecd..60328b35be74 100644
@@ -1565,6 +1565,21 @@ static inline void omen_unregister_powersource_event_handler(void)
 	unregister_acpi_notifier(&platform_power_source_nb);
 }
 
+static const struct platform_profile_ops platform_profile_omen_ops = {
+	.profile_get = platform_profile_omen_get,
+	.profile_set = platform_profile_omen_set,
+};
+
+static const struct platform_profile_ops platform_profile_victus_ops = {
+	.profile_get = platform_profile_victus_get,
+	.profile_set = platform_profile_victus_set,
+};
+
+static const struct platform_profile_ops hp_wmi_platform_profile_ops = {
+	.profile_get = hp_wmi_platform_profile_get,
+	.profile_set = hp_wmi_platform_profile_set,
+};
+
 static int thermal_profile_setup(struct platform_device *device)
 {
 	int err, tp;
@@ -1582,8 +1597,7 @@ static int thermal_profile_setup(struct platform_device *device)
 		if (err < 0)
 			return err;
 
-		platform_profile_handler.profile_get = platform_profile_omen_get;
-		platform_profile_handler.profile_set = platform_profile_omen_set;
+		platform_profile_handler.ops = &platform_profile_omen_ops;
 
 		set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
 	} else if (is_victus_thermal_profile()) {
@@ -1599,8 +1613,7 @@ static int thermal_profile_setup(struct platform_device *device)
 		if (err < 0)
 			return err;
 
-		platform_profile_handler.profile_get = platform_profile_victus_get;
-		platform_profile_handler.profile_set = platform_profile_victus_set;
+		platform_profile_handler.ops = &platform_profile_victus_ops;
 
 		set_bit(PLATFORM_PROFILE_QUIET, platform_profile_handler.choices);
 	} else {
@@ -1617,8 +1630,7 @@ static int thermal_profile_setup(struct platform_device *device)
 		if (err)
 			return err;
 
-		platform_profile_handler.profile_get = hp_wmi_platform_profile_get;
-		platform_profile_handler.profile_set = hp_wmi_platform_profile_set;
+		platform_profile_handler.ops = &hp_wmi_platform_profile_ops;
 
 		set_bit(PLATFORM_PROFILE_QUIET, platform_profile_handler.choices);
 		set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
drivers/platform/x86/ideapad-laptop.c +6 -2
index fc317f42bb82..96e99513b0b5 100644
@@ -1063,6 +1063,11 @@ static const struct dmi_system_id ideapad_dytc_v4_allow_table[] = {
 	{}
 };
 
+static const struct platform_profile_ops dytc_profile_ops = {
+	.profile_get = dytc_profile_get,
+	.profile_set = dytc_profile_set,
+};
+
 static int ideapad_dytc_profile_init(struct ideapad_private *priv)
 {
 	int err, dytc_version;
@@ -1105,8 +1110,7 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
 	priv->dytc->pprof.name = "ideapad-laptop";
 	priv->dytc->pprof.dev = &priv->platform_device->dev;
 	priv->dytc->priv = priv;
-	priv->dytc->pprof.profile_get = dytc_profile_get;
-	priv->dytc->pprof.profile_set = dytc_profile_set;
+	priv->dytc->pprof.ops = &dytc_profile_ops;
 
 	/* Setup supported modes */
 	set_bit(PLATFORM_PROFILE_LOW_POWER, priv->dytc->pprof.choices);
drivers/platform/x86/inspur_platform_profile.c +6 -2
index 47d2dbbf3392..d0a8e4eebffa 100644
@@ -164,6 +164,11 @@ static int inspur_platform_profile_get(struct device *dev,
 	return 0;
 }
 
+static const struct platform_profile_ops inspur_platform_profile_ops = {
+	.profile_get = inspur_platform_profile_get,
+	.profile_set = inspur_platform_profile_set,
+};
+
 static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
 {
 	struct inspur_wmi_priv *priv;
@@ -177,8 +182,7 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
 
 	priv->handler.name = "inspur-wmi";
 	priv->handler.dev = &wdev->dev;
-	priv->handler.profile_get = inspur_platform_profile_get;
-	priv->handler.profile_set = inspur_platform_profile_set;
+	priv->handler.ops = &inspur_platform_profile_ops;
 
 	set_bit(PLATFORM_PROFILE_LOW_POWER, priv->handler.choices);
 	set_bit(PLATFORM_PROFILE_BALANCED, priv->handler.choices);
drivers/platform/x86/thinkpad_acpi.c +6 -2
index 0abe22228fdb..9e26f5670fc7 100644
@@ -10539,12 +10539,16 @@ static int dytc_profile_set(struct device *dev,
 	return err;
 }
 
-static struct platform_profile_handler dytc_profile = {
-	.name = "thinkpad-acpi",
+static const struct platform_profile_ops dytc_profile_ops = {
 	.profile_get = dytc_profile_get,
 	.profile_set = dytc_profile_set,
 };
 
+static struct platform_profile_handler dytc_profile = {
+	.name = "thinkpad-acpi",
+	.ops = &dytc_profile_ops,
+};
+
 static void dytc_profile_refresh(void)
 {
 	enum platform_profile_option profile;
include/linux/platform_profile.h +8 -2
index 5296d886c243..6013c05d7b86 100644
@@ -28,14 +28,20 @@ enum platform_profile_option {
 	PLATFORM_PROFILE_LAST, /*must always be last */
 };
 
+struct platform_profile_handler;
+
+struct platform_profile_ops {
+	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
+	int (*profile_set)(struct device *dev, enum platform_profile_option profile);
+};
+
 struct platform_profile_handler {
 	const char *name;
 	struct device *dev;
 	struct device class_dev;
 	int minor;
 	unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
-	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
-	int (*profile_set)(struct device *dev, enum platform_profile_option profile);
+	const struct platform_profile_ops *ops;
 };
 
 int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
Signature · 1 line
2.48.1
author maintainer
#8 lore raw

PATCH v4 5/19 ACPI: platform_profile: Add `probe` to platform_profile_ops

In reply to Kurt Borja

Add a probe callback to platform_profile_ops, which lets drivers initialize the choices member manually.

---
 drivers/acpi/platform_profile.c               | 15 +++-
 .../surface/surface_platform_profile.c        | 16 ++--
 drivers/platform/x86/acer-wmi.c               | 88 ++++++++++---------
 drivers/platform/x86/amd/pmf/sps.c            | 15 ++--
 drivers/platform/x86/asus-wmi.c               | 16 ++--
 drivers/platform/x86/dell/alienware-wmi.c     | 24 +++--
 drivers/platform/x86/dell/dell-pc.c           | 26 +++---
 drivers/platform/x86/hp/hp-wmi.c              | 29 ++++--
 drivers/platform/x86/ideapad-laptop.c         | 15 ++--
 .../platform/x86/inspur_platform_profile.c    | 14 ++-
 drivers/platform/x86/thinkpad_acpi.c          | 15 ++--
 include/linux/platform_profile.h              |  1 +
 12 files changed, 172 insertions(+), 102 deletions(-)
drivers/acpi/platform_profile.c +13 -2
index 161a05d57b0f..120f8402facd 100644
@@ -465,12 +465,23 @@ int platform_profile_register(struct platform_profile_handler *pprof, void *drvd
 	int err;
 
 	/* Sanity check the profile handler */
-	if (!pprof || bitmap_empty(pprof->choices, PLATFORM_PROFILE_LAST) ||
-	    !pprof->ops->profile_set || !pprof->ops->profile_get) {
+	if (!pprof || !pprof->ops->profile_set || !pprof->ops->profile_get ||
+	    !pprof->ops->probe) {
 		pr_err("platform_profile: handler is invalid\n");
 		return -EINVAL;
 	}
 
+	err = pprof->ops->probe(drvdata, pprof->choices);
+	if (err) {
+		dev_err(pprof->dev, "platform_profile probe failed\n");
+		return err;
+	}
+
+	if (bitmap_empty(pprof->choices, PLATFORM_PROFILE_LAST)) {
+		dev_err(pprof->dev, "Failed to register a platform_profile class device with empty choices\n");
+		return -EINVAL;
+	}
+
 	guard(mutex)(&profile_lock);
 
 	/* create class interface for individual handler */
drivers/platform/surface/surface_platform_profile.c +11 -5
index 76967bfeeef8..48cfe9cb89c8 100644
@@ -201,7 +201,18 @@ static int ssam_platform_profile_set(struct device *dev,
 	return tp;
 }
 
+static int ssam_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
 static const struct platform_profile_ops ssam_platform_profile_ops = {
+	.probe = ssam_platform_profile_probe,
 	.profile_get = ssam_platform_profile_get,
 	.profile_set = ssam_platform_profile_set,
 };
@@ -223,11 +234,6 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
 
 	tpd->has_fan = device_property_read_bool(&sdev->dev, "has_fan");
 
-	set_bit(PLATFORM_PROFILE_LOW_POWER, tpd->handler.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, tpd->handler.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, tpd->handler.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, tpd->handler.choices);
-
 	return platform_profile_register(&tpd->handler, tpd);
 }
 
drivers/platform/x86/acer-wmi.c +46 -42

107 lines not on this page · raw message

drivers/platform/x86/amd/pmf/sps.c +10 -5
index 6ae82ae86d22..e710405b581f 100644
@@ -387,7 +387,17 @@ static int amd_pmf_profile_set(struct device *dev,
 	return 0;
 }
 
+static int amd_pmf_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
 static const struct platform_profile_ops amd_pmf_profile_ops = {
+	.probe = amd_pmf_profile_probe,
 	.profile_get = amd_pmf_profile_get,
 	.profile_set = amd_pmf_profile_set,
 };
@@ -414,11 +424,6 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
 	dev->pprof.dev = dev->dev;
 	dev->pprof.ops = &amd_pmf_profile_ops;
 
-	/* Setup supported modes */
-	set_bit(PLATFORM_PROFILE_LOW_POWER, dev->pprof.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, dev->pprof.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, dev->pprof.choices);
-
 	/* Create platform_profile structure and register */
 	err = platform_profile_register(&dev->pprof, dev);
 	if (err)
drivers/platform/x86/asus-wmi.c +10 -6
index 992956c89d38..e775ec7371ce 100644
@@ -3852,7 +3852,17 @@ static int asus_wmi_platform_profile_set(struct device *dev,
 	return throttle_thermal_policy_write(asus);
 }
 
+static int asus_wmi_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_QUIET, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
 static const struct platform_profile_ops asus_wmi_platform_profile_ops = {
+	.probe = asus_wmi_platform_profile_probe,
 	.profile_get = asus_wmi_platform_profile_get,
 	.profile_set = asus_wmi_platform_profile_set,
 };
@@ -3885,12 +3895,6 @@ static int platform_profile_setup(struct asus_wmi *asus)
 	asus->platform_profile_handler.dev = dev;
 	asus->platform_profile_handler.ops = &asus_wmi_platform_profile_ops;
 
-	set_bit(PLATFORM_PROFILE_QUIET, asus->platform_profile_handler.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED,
-		asus->platform_profile_handler.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE,
-		asus->platform_profile_handler.choices);
-
 	err = platform_profile_register(&asus->platform_profile_handler, asus);
 	if (err == -EEXIST) {
 		pr_warn("%s, a platform_profile handler is already registered\n", __func__);
drivers/platform/x86/dell/alienware-wmi.c +15 -9
index b8359b177a0f..e7209863e7dc 100644
@@ -1078,12 +1078,7 @@ static int thermal_profile_set(struct device *dev,
 	return wmax_thermal_control(supported_thermal_profiles[profile]);
 }
 
-static const struct platform_profile_ops awcc_platform_profile_ops = {
-	.profile_get = thermal_profile_get,
-	.profile_set = thermal_profile_set,
-};
-
-static int create_thermal_profile(struct platform_device *platform_device)
+static int thermal_profile_probe(void *drvdata, unsigned long *choices)
 {
 	enum platform_profile_option profile;
 	enum wmax_thermal_mode mode;
@@ -1116,19 +1111,30 @@ static int create_thermal_profile(struct platform_device *platform_device)
 		profile = wmax_mode_to_platform_profile[mode];
 		supported_thermal_profiles[profile] = out_data;
 
-		set_bit(profile, pp_handler.choices);
+		set_bit(profile, choices);
 	}
 
-	if (bitmap_empty(pp_handler.choices, PLATFORM_PROFILE_LAST))
+	if (bitmap_empty(choices, PLATFORM_PROFILE_LAST))
 		return -ENODEV;
 
 	if (quirks->gmode) {
 		supported_thermal_profiles[PLATFORM_PROFILE_PERFORMANCE] =
 			WMAX_THERMAL_MODE_GMODE;
 
-		set_bit(PLATFORM_PROFILE_PERFORMANCE, pp_handler.choices);
+		set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
 	}
 
+	return 0;
+}
+
+static const struct platform_profile_ops awcc_platform_profile_ops = {
+	.probe = thermal_profile_probe,
+	.profile_get = thermal_profile_get,
+	.profile_set = thermal_profile_set,
+};
+
+static int create_thermal_profile(struct platform_device *platform_device)
+{
 	pp_handler.name = "alienware-wmi";
 	pp_handler.dev = &platform_device->dev;
 	pp_handler.ops = &awcc_platform_profile_ops;
drivers/platform/x86/dell/dell-pc.c +16 -10
index 9010a231f209..32b3be0723f8 100644
@@ -24,6 +24,7 @@
 #include "dell-smbios.h"
 
 static struct platform_device *platform_device;
+static int supported_modes;
 
 static const struct dmi_system_id dell_device_table[] __initconst = {
 	{
@@ -231,7 +232,22 @@ static int thermal_platform_profile_get(struct device *dev,
 	return 0;
 }
 
+static int thermal_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	if (supported_modes & DELL_QUIET)
+		set_bit(PLATFORM_PROFILE_QUIET, choices);
+	if (supported_modes & DELL_COOL_BOTTOM)
+		set_bit(PLATFORM_PROFILE_COOL, choices);
+	if (supported_modes & DELL_BALANCED)
+		set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	if (supported_modes & DELL_PERFORMANCE)
+		set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
 static const struct platform_profile_ops dell_pc_platform_profile_ops = {
+	.probe = thermal_platform_profile_probe,
 	.profile_get = thermal_platform_profile_get,
 	.profile_set = thermal_platform_profile_set,
 };
@@ -239,7 +255,6 @@ static const struct platform_profile_ops dell_pc_platform_profile_ops = {
 static int thermal_init(void)
 {
 	int ret;
-	int supported_modes;
 
 	/* If thermal commands are not supported, exit without error */
 	if (!dell_smbios_class_is_supported(CLASS_INFO))
@@ -265,15 +280,6 @@ static int thermal_init(void)
 	thermal_handler->dev = &platform_device->dev;
 	thermal_handler->ops = &dell_pc_platform_profile_ops;
 
-	if (supported_modes & DELL_QUIET)
-		set_bit(PLATFORM_PROFILE_QUIET, thermal_handler->choices);
-	if (supported_modes & DELL_COOL_BOTTOM)
-		set_bit(PLATFORM_PROFILE_COOL, thermal_handler->choices);
-	if (supported_modes & DELL_BALANCED)
-		set_bit(PLATFORM_PROFILE_BALANCED, thermal_handler->choices);
-	if (supported_modes & DELL_PERFORMANCE)
-		set_bit(PLATFORM_PROFILE_PERFORMANCE, thermal_handler->choices);
-
 	/* Clean up if failed */
 	ret = platform_profile_register(thermal_handler, NULL);
 	if (ret)
drivers/platform/x86/hp/hp-wmi.c +20 -9
index 60328b35be74..75bcd8460e7c 100644
@@ -1488,6 +1488,23 @@ static int platform_profile_victus_set(struct device *dev,
 	return 0;
 }
 
+static int hp_wmi_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	if (is_omen_thermal_profile()) {
+		set_bit(PLATFORM_PROFILE_COOL, choices);
+	} else if (is_victus_thermal_profile()) {
+		set_bit(PLATFORM_PROFILE_QUIET, choices);
+	} else {
+		set_bit(PLATFORM_PROFILE_QUIET, choices);
+		set_bit(PLATFORM_PROFILE_COOL, choices);
+	}
+
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
 static int omen_powersource_event(struct notifier_block *nb,
 				  unsigned long value,
 				  void *data)
@@ -1566,16 +1583,19 @@ static inline void omen_unregister_powersource_event_handler(void)
 }
 
 static const struct platform_profile_ops platform_profile_omen_ops = {
+	.probe = hp_wmi_platform_profile_probe,
 	.profile_get = platform_profile_omen_get,
 	.profile_set = platform_profile_omen_set,
 };
 
 static const struct platform_profile_ops platform_profile_victus_ops = {
+	.probe = hp_wmi_platform_profile_probe,
 	.profile_get = platform_profile_victus_get,
 	.profile_set = platform_profile_victus_set,
 };
 
 static const struct platform_profile_ops hp_wmi_platform_profile_ops = {
+	.probe = hp_wmi_platform_profile_probe,
 	.profile_get = hp_wmi_platform_profile_get,
 	.profile_set = hp_wmi_platform_profile_set,
 };
@@ -1598,8 +1618,6 @@ static int thermal_profile_setup(struct platform_device *device)
 			return err;
 
 		platform_profile_handler.ops = &platform_profile_omen_ops;
-
-		set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
 	} else if (is_victus_thermal_profile()) {
 		err = platform_profile_victus_get_ec(&active_platform_profile);
 		if (err < 0)
@@ -1614,8 +1632,6 @@ static int thermal_profile_setup(struct platform_device *device)
 			return err;
 
 		platform_profile_handler.ops = &platform_profile_victus_ops;
-
-		set_bit(PLATFORM_PROFILE_QUIET, platform_profile_handler.choices);
 	} else {
 		tp = thermal_profile_get();
 
@@ -1631,15 +1647,10 @@ static int thermal_profile_setup(struct platform_device *device)
 			return err;
 
 		platform_profile_handler.ops = &hp_wmi_platform_profile_ops;
-
-		set_bit(PLATFORM_PROFILE_QUIET, platform_profile_handler.choices);
-		set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
 	}
 
 	platform_profile_handler.name = "hp-wmi";
 	platform_profile_handler.dev = &device->dev;
-	set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
 
 	err = platform_profile_register(&platform_profile_handler, NULL);
 	if (err)
drivers/platform/x86/ideapad-laptop.c +10 -5
index 96e99513b0b5..050919a28d2b 100644
@@ -1023,6 +1023,15 @@ static int dytc_profile_set(struct device *dev,
 	return -EINTR;
 }
 
+static int dytc_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
 static void dytc_profile_refresh(struct ideapad_private *priv)
 {
 	enum platform_profile_option profile;
@@ -1064,6 +1073,7 @@ static const struct dmi_system_id ideapad_dytc_v4_allow_table[] = {
 };
 
 static const struct platform_profile_ops dytc_profile_ops = {
+	.probe = dytc_profile_probe,
 	.profile_get = dytc_profile_get,
 	.profile_set = dytc_profile_set,
 };
@@ -1112,11 +1122,6 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
 	priv->dytc->priv = priv;
 	priv->dytc->pprof.ops = &dytc_profile_ops;
 
-	/* Setup supported modes */
-	set_bit(PLATFORM_PROFILE_LOW_POWER, priv->dytc->pprof.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, priv->dytc->pprof.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, priv->dytc->pprof.choices);
-
 	/* Create platform_profile structure and register */
 	err = platform_profile_register(&priv->dytc->pprof, &priv->dytc);
 	if (err)
drivers/platform/x86/inspur_platform_profile.c +10 -4
index d0a8e4eebffa..06df3aae9a56 100644
@@ -164,7 +164,17 @@ static int inspur_platform_profile_get(struct device *dev,
 	return 0;
 }
 
+static int inspur_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
 static const struct platform_profile_ops inspur_platform_profile_ops = {
+	.probe = inspur_platform_profile_probe,
 	.profile_get = inspur_platform_profile_get,
 	.profile_set = inspur_platform_profile_set,
 };
@@ -184,10 +194,6 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
 	priv->handler.dev = &wdev->dev;
 	priv->handler.ops = &inspur_platform_profile_ops;
 
-	set_bit(PLATFORM_PROFILE_LOW_POWER, priv->handler.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, priv->handler.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, priv->handler.choices);
-
 	return platform_profile_register(&priv->handler, priv);
 }
 
drivers/platform/x86/thinkpad_acpi.c +10 -5
index 9e26f5670fc7..62b2ddfe7c0a 100644
@@ -10539,7 +10539,17 @@ static int dytc_profile_set(struct device *dev,
 	return err;
 }
 
+static int dytc_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
 static const struct platform_profile_ops dytc_profile_ops = {
+	.probe = dytc_profile_probe,
 	.profile_get = dytc_profile_get,
 	.profile_set = dytc_profile_set,
 };
@@ -10585,11 +10595,6 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 {
 	int err, output;
 
-	/* Setup supported modes */
-	set_bit(PLATFORM_PROFILE_LOW_POWER, dytc_profile.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, dytc_profile.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, dytc_profile.choices);
-
 	err = dytc_command(DYTC_CMD_QUERY, &output);
 	if (err)
 		return err;
include/linux/platform_profile.h +1 -0
index 6013c05d7b86..5ad1ab7b75e4 100644
@@ -31,6 +31,7 @@ enum platform_profile_option {
 struct platform_profile_handler;
 
 struct platform_profile_ops {
+	int (*probe)(void *drvdata, unsigned long *choices);
 	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
 	int (*profile_set)(struct device *dev, enum platform_profile_option profile);
 };
Signature · 1 line
2.48.1
author maintainer
#10 lore raw

PATCH v4 6/19 platform/surface: surface_platform_profile: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace platform_profile_register() with it's device managed version.

---
 drivers/platform/surface/surface_platform_profile.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/platform/surface/surface_platform_profile.c +1 -10
index 48cfe9cb89c8..bbdc873cb788 100644
@@ -234,15 +234,7 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
 
 	tpd->has_fan = device_property_read_bool(&sdev->dev, "has_fan");
 
-	return platform_profile_register(&tpd->handler, tpd);
-}
-
-static void surface_platform_profile_remove(struct ssam_device *sdev)
-{
-	struct ssam_platform_profile_device *tpd;
-
-	tpd = ssam_device_get_drvdata(sdev);
-	platform_profile_remove(&tpd->handler);
+	return devm_platform_profile_register(&tpd->handler, tpd);
 }
 
 static const struct ssam_device_id ssam_platform_profile_match[] = {
@@ -253,7 +245,6 @@ MODULE_DEVICE_TABLE(ssam, ssam_platform_profile_match);
 
 static struct ssam_device_driver surface_platform_profile = {
 	.probe = surface_platform_profile_probe,
-	.remove = surface_platform_profile_remove,
 	.match_table = ssam_platform_profile_match,
 	.driver = {
 		.name = "surface_platform_profile",
Signature · 1 line
2.48.1
author maintainer
#12 lore raw

PATCH v4 7/19 platform/x86: acer-wmi: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace platform_profile_register() with it's device managed version.

---
 drivers/platform/x86/acer-wmi.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/platform/x86/acer-wmi.c +1 -6
index 4d62a61cb241..d201ca0e01d6 100644
@@ -2080,7 +2080,7 @@ static int acer_platform_profile_setup(struct platform_device *device)
 		platform_profile_handler.ops =
 			&acer_predator_v4_platform_profile_ops;
 
-		err = platform_profile_register(&platform_profile_handler, NULL);
+		err = devm_platform_profile_register(&platform_profile_handler, NULL);
 		if (err)
 			return err;
 
@@ -2684,8 +2684,6 @@ static int acer_platform_probe(struct platform_device *device)
 	return 0;
 
 error_hwmon:
-	if (platform_profile_support)
-		platform_profile_remove(&platform_profile_handler);
 error_platform_profile:
 	acer_rfkill_exit();
 error_rfkill:
@@ -2706,9 +2704,6 @@ static void acer_platform_remove(struct platform_device *device)
 		acer_backlight_exit();
 
 	acer_rfkill_exit();
-
-	if (platform_profile_support)
-		platform_profile_remove(&platform_profile_handler);
 }
 
 #ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.48.1
author maintainer
#13 lore raw

PATCH v4 8/19 platform/x86: amd: pmf: sps: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace platform_profile_register() with it's device managed version.

---
 drivers/platform/x86/amd/pmf/core.c | 1 -
 drivers/platform/x86/amd/pmf/pmf.h  | 1 -
 drivers/platform/x86/amd/pmf/sps.c  | 7 +------
 3 files changed, 1 insertion(+), 8 deletions(-)
drivers/platform/x86/amd/pmf/core.c +0 -1
index 57ee95a327be..1211a753fee8 100644
@@ -371,7 +371,6 @@ static void amd_pmf_deinit_features(struct amd_pmf_dev *dev)
 	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR) ||
 	    is_apmf_func_supported(dev, APMF_FUNC_OS_POWER_SLIDER_UPDATE)) {
 		power_supply_unreg_notifier(&dev->pwr_src_notifier);
-		amd_pmf_deinit_sps(dev);
 	}
 
 	if (dev->smart_pc_enabled) {
drivers/platform/x86/amd/pmf/pmf.h +0 -1
index 080818dd173b..d99b3556205b 100644
@@ -780,7 +780,6 @@ int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf);
 void amd_pmf_update_slider(struct amd_pmf_dev *dev, bool op, int idx,
 			   struct amd_pmf_static_slider_granular *table);
 int amd_pmf_init_sps(struct amd_pmf_dev *dev);
-void amd_pmf_deinit_sps(struct amd_pmf_dev *dev);
 int apmf_get_static_slider_granular(struct amd_pmf_dev *pdev,
 				    struct apmf_static_slider_granular_output *output);
 bool is_pprof_balanced(struct amd_pmf_dev *pmf);
drivers/platform/x86/amd/pmf/sps.c +1 -6
index e710405b581f..7c7ed2b9de01 100644
@@ -425,15 +425,10 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
 	dev->pprof.ops = &amd_pmf_profile_ops;
 
 	/* Create platform_profile structure and register */
-	err = platform_profile_register(&dev->pprof, dev);
+	err = devm_platform_profile_register(&dev->pprof, dev);
 	if (err)
 		dev_err(dev->dev, "Failed to register SPS support, this is most likely an SBIOS bug: %d\n",
 			err);
 
 	return err;
 }
-
-void amd_pmf_deinit_sps(struct amd_pmf_dev *dev)
-{
-	platform_profile_remove(&dev->pprof);
-}
Signature · 1 line
2.48.1
author maintainer
#14 lore raw

PATCH v4 9/19 platform/x86: asus-wmi: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace platform_profile_register() with it's device managed version. Also replace pr_err with dev_err in case of error and make the error message more user-friendly.

---
 drivers/platform/x86/asus-wmi.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/platform/x86/asus-wmi.c +3 -11
index e775ec7371ce..dc713a5d8042 100644
@@ -3895,12 +3895,9 @@ static int platform_profile_setup(struct asus_wmi *asus)
 	asus->platform_profile_handler.dev = dev;
 	asus->platform_profile_handler.ops = &asus_wmi_platform_profile_ops;
 
-	err = platform_profile_register(&asus->platform_profile_handler, asus);
-	if (err == -EEXIST) {
-		pr_warn("%s, a platform_profile handler is already registered\n", __func__);
-		return 0;
-	} else if (err) {
-		pr_err("%s, failed at platform_profile_register: %d\n", __func__, err);
+	err = devm_platform_profile_register(&asus->platform_profile_handler, asus);
+	if (err) {
+		dev_err(dev, "Failed to register a platform_profile class device");
 		return err;
 	}
 
@@ -4859,8 +4856,6 @@ static int asus_wmi_add(struct platform_device *pdev)
 fail_sysfs:
 fail_custom_fan_curve:
 fail_platform_profile_setup:
-	if (asus->platform_profile_support)
-		platform_profile_remove(&asus->platform_profile_handler);
 fail_fan_boost_mode:
 fail_platform:
 	kfree(asus);
@@ -4886,9 +4881,6 @@ static void asus_wmi_remove(struct platform_device *device)
 	throttle_thermal_policy_set_default(asus);
 	asus_wmi_battery_exit(asus);
 
-	if (asus->platform_profile_support)
-		platform_profile_remove(&asus->platform_profile_handler);
-
 	kfree(asus);
 }
 
Signature · 1 line
2.48.1
author maintainer
#15 lore raw

PATCH v4 10/19 platform/x86: dell-pc: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace platform_profile_register() with it's device managed version.

---
 drivers/platform/x86/dell/dell-pc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/platform/x86/dell/dell-pc.c +1 -3
index 32b3be0723f8..2759bb608b1a 100644
@@ -281,7 +281,7 @@ static int thermal_init(void)
 	thermal_handler->ops = &dell_pc_platform_profile_ops;
 
 	/* Clean up if failed */
-	ret = platform_profile_register(thermal_handler, NULL);
+	ret = devm_platform_profile_register(thermal_handler, NULL);
 	if (ret)
 		goto cleanup_thermal_handler;
 
@@ -298,8 +298,6 @@ static int thermal_init(void)
 
 static void thermal_cleanup(void)
 {
-	if (thermal_handler)
-		platform_profile_remove(thermal_handler);
 	platform_device_unregister(platform_device);
 }
 
Signature · 1 line
2.48.1
author maintainer
#16 lore raw

PATCH v4 11/19 platform/x86: ideapad-laptop: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace platform_profile_register() with it's device managed version.

---
 drivers/platform/x86/ideapad-laptop.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/platform/x86/ideapad-laptop.c +1 -2
index 050919a28d2b..87c1e087770a 100644
@@ -1123,7 +1123,7 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
 	priv->dytc->pprof.ops = &dytc_profile_ops;
 
 	/* Create platform_profile structure and register */
-	err = platform_profile_register(&priv->dytc->pprof, &priv->dytc);
+	err = devm_platform_profile_register(&priv->dytc->pprof, &priv->dytc);
 	if (err)
 		goto pp_reg_failed;
 
@@ -1145,7 +1145,6 @@ static void ideapad_dytc_profile_exit(struct ideapad_private *priv)
 	if (!priv->dytc)
 		return;
 
-	platform_profile_remove(&priv->dytc->pprof);
 	mutex_destroy(&priv->dytc->mutex);
 	kfree(priv->dytc);
 
Signature · 1 line
2.48.1
author maintainer
#17 lore raw

PATCH v4 12/19 platform/x86: hp-wmi: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace platform_profile_register() with it's device managed version.

---
 drivers/platform/x86/hp/hp-wmi.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/platform/x86/hp/hp-wmi.c +1 -4
index 75bcd8460e7c..1304dfc65aab 100644
@@ -1652,7 +1652,7 @@ static int thermal_profile_setup(struct platform_device *device)
 	platform_profile_handler.name = "hp-wmi";
 	platform_profile_handler.dev = &device->dev;
 
-	err = platform_profile_register(&platform_profile_handler, NULL);
+	err = devm_platform_profile_register(&platform_profile_handler, NULL);
 	if (err)
 		return err;
 
@@ -1714,9 +1714,6 @@ static void __exit hp_wmi_bios_remove(struct platform_device *device)
 		rfkill_unregister(wwan_rfkill);
 		rfkill_destroy(wwan_rfkill);
 	}
-
-	if (platform_profile_support)
-		platform_profile_remove(&platform_profile_handler);
 }
 
 static int hp_wmi_resume_handler(struct device *device)
Signature · 1 line
2.48.1
author maintainer
#18 lore raw

PATCH v4 13/19 platform/x86: inspur_platform_profile: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace platform_profile_register() with it's device managed version. While at it, pass inspur_wmi_priv to the class device as drvdata and replace uses of container_of() with dev_get_drvdata().

---
 drivers/platform/x86/inspur_platform_profile.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/platform/x86/inspur_platform_profile.c +1 -10
index 06df3aae9a56..e1631de6ad86 100644
@@ -194,15 +194,7 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
 	priv->handler.dev = &wdev->dev;
 	priv->handler.ops = &inspur_platform_profile_ops;
 
-	return platform_profile_register(&priv->handler, priv);
-}
-
-static void inspur_wmi_remove(struct wmi_device *wdev)
-{
-	struct inspur_wmi_priv *priv;
-
-	priv = dev_get_drvdata(&wdev->dev);
-	platform_profile_remove(&priv->handler);
+	return devm_platform_profile_register(&priv->handler, priv);
 }
 
 static const struct wmi_device_id inspur_wmi_id_table[] = {
@@ -219,7 +211,6 @@ static struct wmi_driver inspur_wmi_driver = {
 	},
 	.id_table = inspur_wmi_id_table,
 	.probe = inspur_wmi_probe,
-	.remove = inspur_wmi_remove,
 	.no_singleton = true,
 };
 
Signature · 1 line
2.48.1
author maintainer
#19 lore raw

PATCH v4 14/19 platform/x86: thinkpad_acpi: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace platform_profile_register() with it's device managed version.

---
 drivers/platform/x86/thinkpad_acpi.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +1 -7
index 62b2ddfe7c0a..c9226e8dc713 100644
@@ -10650,7 +10650,7 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 
 	dytc_profile.dev = &tpacpi_pdev->dev;
 	/* Create platform_profile structure and register */
-	err = platform_profile_register(&dytc_profile, NULL);
+	err = devm_platform_profile_register(&dytc_profile, NULL);
 	/*
 	 * If for some reason platform_profiles aren't enabled
 	 * don't quit terminally.
@@ -10668,14 +10668,8 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 	return 0;
 }
 
-static void dytc_profile_exit(void)
-{
-	platform_profile_remove(&dytc_profile);
-}
-
 static struct ibm_struct  dytc_profile_driver_data = {
 	.name = "dytc-profile",
-	.exit = dytc_profile_exit,
 };
 
 /*************************************************************************
Signature · 1 line
2.48.1
author maintainer
#20 lore raw

PATCH v4 15/19 ACPI: platform_profile: Remove platform_profile_handler from exported symbols

In reply to Kurt Borja

In order to protect the platform_profile_handler from API consumers, allocate it in platform_profile_register() and modify it's signature accordingly.

Remove the platform_profile_handler from all consumer drivers and replace them with a pointer to the class device, which is now returned from platform_profile_register().

Replace *pprof with a pointer to the class device in the rest of exported symbols.

---
 drivers/acpi/platform_profile.c               | 98 ++++++++++++-------
 .../surface/surface_platform_profile.c        | 11 +--
 drivers/platform/x86/acer-wmi.c               | 18 ++--
 drivers/platform/x86/amd/pmf/pmf.h            |  2 +-
 drivers/platform/x86/amd/pmf/sps.c            | 17 ++--
 drivers/platform/x86/asus-wmi.c               | 15 ++-
 drivers/platform/x86/dell/alienware-wmi.c     | 10 +-
 drivers/platform/x86/dell/dell-pc.c           | 22 ++---
 drivers/platform/x86/hp/hp-wmi.c              | 19 ++--
 drivers/platform/x86/ideapad-laptop.c         | 15 +--
 .../platform/x86/inspur_platform_profile.c    |  9 +-
 drivers/platform/x86/thinkpad_acpi.c          | 14 +--
 include/linux/platform_profile.h              | 12 ++-
 13 files changed, 130 insertions(+), 132 deletions(-)
drivers/acpi/platform_profile.c +61 -37
index 120f8402facd..a1dfa168f51f 100644
@@ -4,6 +4,7 @@
 
 #include <linux/acpi.h>
 #include <linux/bits.h>
+#include <linux/cleanup.h>
 #include <linux/init.h>
 #include <linux/mutex.h>
 #include <linux/platform_profile.h>
@@ -212,9 +213,17 @@ static struct attribute *profile_attrs[] = {
 };
 ATTRIBUTE_GROUPS(profile);
 
+static void pprof_device_release(struct device *dev)
+{
+	struct platform_profile_handler *pprof = to_pprof_handler(dev);
+
+	kfree(pprof);
+}
+
 static const struct class platform_profile_class = {
 	.name = "platform-profile",
 	.dev_groups = profile_groups,
+	.dev_release = pprof_device_release,
 };
 
 /**
@@ -408,10 +417,10 @@ static const struct attribute_group platform_profile_group = {
 	.is_visible = profile_class_is_visible,
 };
 
-void platform_profile_notify(struct platform_profile_handler *pprof)
+void platform_profile_notify(struct device *dev)
 {
 	scoped_cond_guard(mutex_intr, return, &profile_lock) {
-		_notify_class_profile(&pprof->class_dev, NULL);
+		_notify_class_profile(dev, NULL);
 	}
 	sysfs_notify(acpi_kobj, NULL, "platform_profile");
 }
@@ -460,42 +469,54 @@ int platform_profile_cycle(void)
 }
 EXPORT_SYMBOL_GPL(platform_profile_cycle);
 
-int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata)
+struct device *platform_profile_register(struct device *dev, const char *name,
+					 void *drvdata,
+					 const struct platform_profile_ops *ops)
 {
+	struct device *ppdev;
+	int minor;
 	int err;
 
-	/* Sanity check the profile handler */
-	if (!pprof || !pprof->ops->profile_set || !pprof->ops->profile_get ||
-	    !pprof->ops->probe) {
-		pr_err("platform_profile: handler is invalid\n");
-		return -EINVAL;
-	}
+	/* Sanity check */
+	if (WARN_ON_ONCE(!dev || !name || !ops || !ops->profile_get ||
+	    !ops->profile_set || !ops->probe))
+		return ERR_PTR(-EINVAL);
+
+	struct platform_profile_handler *pprof __free(kfree) = kzalloc(
+		sizeof(*pprof), GFP_KERNEL);
+	if (!pprof)
+		return ERR_PTR(-ENOMEM);
 
-	err = pprof->ops->probe(drvdata, pprof->choices);
+	err = ops->probe(drvdata, pprof->choices);
 	if (err) {
-		dev_err(pprof->dev, "platform_profile probe failed\n");
-		return err;
+		dev_err(dev, "platform_profile probe failed\n");
+		return ERR_PTR(err);
 	}
 
 	if (bitmap_empty(pprof->choices, PLATFORM_PROFILE_LAST)) {
-		dev_err(pprof->dev, "Failed to register a platform_profile class device with empty choices\n");
-		return -EINVAL;
+		dev_err(dev, "Failed to register platform_profile class device with empty choices\n");
+		return ERR_PTR(-EINVAL);
 	}
 
 	guard(mutex)(&profile_lock);
 
 	/* create class interface for individual handler */
-	pprof->minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
-	if (pprof->minor < 0)
-		return pprof->minor;
+	minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
+	if (minor < 0)
+		return ERR_PTR(minor);
 
+	pprof->name = name;
+	pprof->ops = ops;
+	pprof->minor = minor;
 	pprof->class_dev.class = &platform_profile_class;
-	pprof->class_dev.parent = pprof->dev;
+	pprof->class_dev.parent = dev;
 	dev_set_drvdata(&pprof->class_dev, drvdata);
 	dev_set_name(&pprof->class_dev, "platform-profile-%d", pprof->minor);
-	err = device_register(&pprof->class_dev);
+	/* device_register() takes ownership of ppdev */
+	ppdev = &no_free_ptr(pprof)->class_dev;
+	err = device_register(ppdev);
 	if (err) {
-		put_device(&pprof->class_dev);
+		put_device(ppdev);
 		goto cleanup_ida;
 	}
 
@@ -505,20 +526,21 @@ int platform_profile_register(struct platform_profile_handler *pprof, void *drvd
 	if (err)
 		goto cleanup_cur;
 
-	return 0;
+	return ppdev;
 
 cleanup_cur:
-	device_unregister(&pprof->class_dev);
+	device_unregister(ppdev);
 
 cleanup_ida:
-	ida_free(&platform_profile_ida, pprof->minor);
+	ida_free(&platform_profile_ida, minor);
 
-	return err;
+	return ERR_PTR(err);
 }
 EXPORT_SYMBOL_GPL(platform_profile_register);
 
-int platform_profile_remove(struct platform_profile_handler *pprof)
+int platform_profile_remove(struct device *dev)
 {
+	struct platform_profile_handler *pprof = to_pprof_handler(dev);
 	int id;
 	guard(mutex)(&profile_lock);
 
@@ -536,30 +558,32 @@ EXPORT_SYMBOL_GPL(platform_profile_remove);
 
 static void devm_platform_profile_release(struct device *dev, void *res)
 {
-	struct platform_profile_handler **pprof = res;
+	struct device **ppdev = res;
 
-	platform_profile_remove(*pprof);
+	platform_profile_remove(*ppdev);
 }
 
-int devm_platform_profile_register(struct platform_profile_handler *pprof, void *drvdata)
+struct device *devm_platform_profile_register(struct device *dev, const char *name,
+					      void *drvdata,
+					      const struct platform_profile_ops *ops)
 {
-	struct platform_profile_handler **dr;
-	int ret;
+	struct device *ppdev;
+	struct device **dr;
 
 	dr = devres_alloc(devm_platform_profile_release, sizeof(*dr), GFP_KERNEL);
 	if (!dr)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
-	ret = platform_profile_register(pprof, drvdata);
-	if (ret) {
+	ppdev = platform_profile_register(dev, name, drvdata, ops);
+	if (IS_ERR(ppdev)) {
 		devres_free(dr);
-		return ret;
+		return ppdev;
 	}
 
-	*dr = pprof;
-	devres_add(pprof->dev, dr);
+	*dr = ppdev;
+	devres_add(dev, dr);
 
-	return 0;
+	return ppdev;
 }
 EXPORT_SYMBOL_GPL(devm_platform_profile_register);
 
drivers/platform/surface/surface_platform_profile.c +5 -6
index bbdc873cb788..0e479e35e66e 100644
@@ -40,7 +40,7 @@ struct ssam_tmp_profile_info {
 
 struct ssam_platform_profile_device {
 	struct ssam_device *sdev;
-	struct platform_profile_handler handler;
+	struct device *ppdev;
 	bool has_fan;
 };
 
@@ -228,13 +228,12 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
 	tpd->sdev = sdev;
 	ssam_device_set_drvdata(sdev, tpd);
 
-	tpd->handler.name = "Surface Platform Profile";
-	tpd->handler.dev = &sdev->dev;
-	tpd->handler.ops = &ssam_platform_profile_ops;
-
 	tpd->has_fan = device_property_read_bool(&sdev->dev, "has_fan");
 
-	return devm_platform_profile_register(&tpd->handler, tpd);
+	tpd->ppdev = devm_platform_profile_register(&sdev->dev, "Surface Platform Profile",
+						    tpd, &ssam_platform_profile_ops);
+
+	return PTR_ERR_OR_ZERO(tpd->ppdev);
 }
 
 static const struct ssam_device_id ssam_platform_profile_match[] = {
drivers/platform/x86/acer-wmi.c +6 -12
index d201ca0e01d6..ae2a7c93ab72 100644
@@ -784,7 +784,7 @@ static const struct dmi_system_id non_acer_quirks[] __initconst = {
 	{}
 };
 
-static struct platform_profile_handler platform_profile_handler;
+static struct device *platform_profile_device;
 static bool platform_profile_support;
 
 /*
@@ -2073,16 +2073,10 @@ static const struct platform_profile_ops acer_predator_v4_platform_profile_ops =
 static int acer_platform_profile_setup(struct platform_device *device)
 {
 	if (quirks->predator_v4) {
-		int err;
-
-		platform_profile_handler.name = "acer-wmi";
-		platform_profile_handler.dev = &device->dev;
-		platform_profile_handler.ops =
-			&acer_predator_v4_platform_profile_ops;
-
-		err = devm_platform_profile_register(&platform_profile_handler, NULL);
-		if (err)
-			return err;
+		platform_profile_device = devm_platform_profile_register(
+			&device->dev, "acer-wmi", NULL, &acer_predator_v4_platform_profile_ops);
+		if (IS_ERR(platform_profile_device))
+			return PTR_ERR(platform_profile_device);
 
 		platform_profile_support = true;
 
@@ -2125,7 +2119,7 @@ static int acer_thermal_profile_change(void)
 			if (current_tp != acer_predator_v4_max_perf)
 				last_non_turbo_profile = current_tp;
 
-			platform_profile_notify(&platform_profile_handler);
+			platform_profile_notify(platform_profile_device);
 		}
 	}
 
drivers/platform/x86/amd/pmf/pmf.h +1 -1
index d99b3556205b..41b2b91b8fdc 100644
@@ -338,7 +338,7 @@ struct amd_pmf_dev {
 	struct mutex lock; /* protects the PMF interface */
 	u32 supported_func;
 	enum platform_profile_option current_profile;
-	struct platform_profile_handler pprof;
+	struct device *ppdev; /* platform profile class device */
 	struct dentry *dbgfs_dir;
 	int hb_interval; /* SBIOS heartbeat interval */
 	struct delayed_work heart_beat;
drivers/platform/x86/amd/pmf/sps.c +6 -11
index 7c7ed2b9de01..e6cf0b22dac3 100644
@@ -404,8 +404,6 @@ static const struct platform_profile_ops amd_pmf_profile_ops = {
 
 int amd_pmf_init_sps(struct amd_pmf_dev *dev)
 {
-	int err;
-
 	dev->current_profile = PLATFORM_PROFILE_BALANCED;
 
 	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) {
@@ -420,15 +418,12 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
 		amd_pmf_set_sps_power_limits(dev);
 	}
 
-	dev->pprof.name = "amd-pmf";
-	dev->pprof.dev = dev->dev;
-	dev->pprof.ops = &amd_pmf_profile_ops;
-
 	/* Create platform_profile structure and register */
-	err = devm_platform_profile_register(&dev->pprof, dev);
-	if (err)
-		dev_err(dev->dev, "Failed to register SPS support, this is most likely an SBIOS bug: %d\n",
-			err);
+	dev->ppdev = devm_platform_profile_register(dev->dev, "amd-pmf", dev,
+						    &amd_pmf_profile_ops);
+	if (IS_ERR(dev->ppdev))
+		dev_err(dev->dev, "Failed to register SPS support, this is most likely an SBIOS bug: %ld\n",
+			PTR_ERR(dev->ppdev));
 
-	return err;
+	return PTR_ERR_OR_ZERO(dev->ppdev);
 }
drivers/platform/x86/asus-wmi.c +6 -9
index dc713a5d8042..9a485f777591 100644
@@ -313,7 +313,7 @@ struct asus_wmi {
 	bool mid_fan_curve_available;
 	struct fan_curve_data custom_fan_curves[3];
 
-	struct platform_profile_handler platform_profile_handler;
+	struct device *ppdev;
 	bool platform_profile_support;
 
 	// The RSOC controls the maximum charging percentage.
@@ -3789,7 +3789,7 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
 	 * Ensure that platform_profile updates userspace with the change to ensure
 	 * that platform_profile and throttle_thermal_policy_mode are in sync.
 	 */
-	platform_profile_notify(&asus->platform_profile_handler);
+	platform_profile_notify(asus->ppdev);
 
 	return count;
 }
@@ -3891,14 +3891,11 @@ static int platform_profile_setup(struct asus_wmi *asus)
 
 	dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n");
 
-	asus->platform_profile_handler.name = "asus-wmi";
-	asus->platform_profile_handler.dev = dev;
-	asus->platform_profile_handler.ops = &asus_wmi_platform_profile_ops;
-
-	err = devm_platform_profile_register(&asus->platform_profile_handler, asus);
-	if (err) {
+	asus->ppdev = devm_platform_profile_register(dev, "asus-wmi", asus,
+						     &asus_wmi_platform_profile_ops);
+	if (IS_ERR(asus->ppdev)) {
 		dev_err(dev, "Failed to register a platform_profile class device");
-		return err;
+		return PTR_ERR(asus->ppdev);
 	}
 
 	asus->platform_profile_support = true;
drivers/platform/x86/dell/alienware-wmi.c +5 -5
index e7209863e7dc..63cf016bc912 100644
@@ -406,7 +406,6 @@ struct wmax_u32_args {
 
 static struct platform_device *platform_device;
 static struct color_platform colors[4];
-static struct platform_profile_handler pp_handler;
 static enum wmax_thermal_mode supported_thermal_profiles[PLATFORM_PROFILE_LAST];
 
 static u8 interface;
@@ -1135,11 +1134,12 @@ static const struct platform_profile_ops awcc_platform_profile_ops = {
 
 static int create_thermal_profile(struct platform_device *platform_device)
 {
-	pp_handler.name = "alienware-wmi";
-	pp_handler.dev = &platform_device->dev;
-	pp_handler.ops = &awcc_platform_profile_ops;
+	struct device *ppdev;
 
-	return devm_platform_profile_register(&pp_handler, NULL);
+	ppdev = devm_platform_profile_register(&platform_device->dev, "alienware-wmi",
+					       NULL, &awcc_platform_profile_ops);
+
+	return PTR_ERR_OR_ZERO(ppdev);
 }
 
 /*
drivers/platform/x86/dell/dell-pc.c +6 -16
index 2759bb608b1a..1874d4adfb8a 100644
@@ -109,8 +109,6 @@ MODULE_DEVICE_TABLE(dmi, dell_device_table);
 #define DELL_ACC_SET_FIELD	GENMASK(11, 8)
 #define DELL_THERMAL_SUPPORTED	GENMASK(3, 0)
 
-static struct platform_profile_handler *thermal_handler;
-
 enum thermal_mode_bits {
 	DELL_BALANCED    = BIT(0),
 	DELL_COOL_BOTTOM = BIT(1),
@@ -254,6 +252,7 @@ static const struct platform_profile_ops dell_pc_platform_profile_ops = {
 
 static int thermal_init(void)
 {
+	struct device *ppdev;
 	int ret;
 
 	/* If thermal commands are not supported, exit without error */
@@ -271,26 +270,17 @@ static int thermal_init(void)
 	if (IS_ERR(platform_device))
 		return PTR_ERR(platform_device);
 
-	thermal_handler = devm_kzalloc(&platform_device->dev, sizeof(*thermal_handler), GFP_KERNEL);
-	if (!thermal_handler) {
-		ret = -ENOMEM;
-		goto cleanup_platform_device;
-	}
-	thermal_handler->name = "dell-pc";
-	thermal_handler->dev = &platform_device->dev;
-	thermal_handler->ops = &dell_pc_platform_profile_ops;
-
 	/* Clean up if failed */
-	ret = devm_platform_profile_register(thermal_handler, NULL);
-	if (ret)
+	ppdev = devm_platform_profile_register(&platform_device->dev, "dell-pc",
+					       NULL, &dell_pc_platform_profile_ops);
+	if (IS_ERR(ppdev)) {
+		ret = PTR_ERR(ppdev);
 		goto cleanup_thermal_handler;
+	}
 
 	return 0;
 
 cleanup_thermal_handler:
-	thermal_handler = NULL;
-
-cleanup_platform_device:
 	platform_device_unregister(platform_device);
 
 	return ret;
drivers/platform/x86/hp/hp-wmi.c +9 -10
index 1304dfc65aab..435e3ef2e3e7 100644
@@ -273,7 +273,7 @@ static DEFINE_MUTEX(active_platform_profile_lock);
 static struct input_dev *hp_wmi_input_dev;
 static struct input_dev *camera_shutter_input_dev;
 static struct platform_device *hp_wmi_platform_dev;
-static struct platform_profile_handler platform_profile_handler;
+static struct device *platform_profile_device;
 static struct notifier_block platform_power_source_nb;
 static enum platform_profile_option active_platform_profile;
 static bool platform_profile_support;
@@ -1602,6 +1602,7 @@ static const struct platform_profile_ops hp_wmi_platform_profile_ops = {
 
 static int thermal_profile_setup(struct platform_device *device)
 {
+	const struct platform_profile_ops *ops;
 	int err, tp;
 
 	if (is_omen_thermal_profile()) {
@@ -1617,7 +1618,7 @@ static int thermal_profile_setup(struct platform_device *device)
 		if (err < 0)
 			return err;
 
-		platform_profile_handler.ops = &platform_profile_omen_ops;
+		ops = &platform_profile_omen_ops;
 	} else if (is_victus_thermal_profile()) {
 		err = platform_profile_victus_get_ec(&active_platform_profile);
 		if (err < 0)
@@ -1631,7 +1632,7 @@ static int thermal_profile_setup(struct platform_device *device)
 		if (err < 0)
 			return err;
 
-		platform_profile_handler.ops = &platform_profile_victus_ops;
+		ops = &platform_profile_victus_ops;
 	} else {
 		tp = thermal_profile_get();
 
@@ -1646,15 +1647,13 @@ static int thermal_profile_setup(struct platform_device *device)
 		if (err)
 			return err;
 
-		platform_profile_handler.ops = &hp_wmi_platform_profile_ops;
+		ops = &hp_wmi_platform_profile_ops;
 	}
 
-	platform_profile_handler.name = "hp-wmi";
-	platform_profile_handler.dev = &device->dev;
-
-	err = devm_platform_profile_register(&platform_profile_handler, NULL);
-	if (err)
-		return err;
+	platform_profile_device = devm_platform_profile_register(&device->dev, "hp-wmi",
+								 NULL, ops);
+	if (IS_ERR(platform_profile_device))
+		return PTR_ERR(platform_profile_device);
 
 	platform_profile_support = true;
 
drivers/platform/x86/ideapad-laptop.c +8 -7
index 87c1e087770a..dfb5d4b8c046 100644
@@ -142,7 +142,7 @@ enum {
 
 struct ideapad_dytc_priv {
 	enum platform_profile_option current_profile;
-	struct platform_profile_handler pprof;
+	struct device *ppdev; /* platform profile device */
 	struct mutex mutex; /* protects the DYTC interface */
 	struct ideapad_private *priv;
 };
@@ -1050,7 +1050,7 @@ static void dytc_profile_refresh(struct ideapad_private *priv)
 
 	if (profile != priv->dytc->current_profile) {
 		priv->dytc->current_profile = profile;
-		platform_profile_notify(&priv->dytc->pprof);
+		platform_profile_notify(priv->dytc->ppdev);
 	}
 }
 
@@ -1117,15 +1117,16 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
 
 	mutex_init(&priv->dytc->mutex);
 
-	priv->dytc->pprof.name = "ideapad-laptop";
-	priv->dytc->pprof.dev = &priv->platform_device->dev;
 	priv->dytc->priv = priv;
-	priv->dytc->pprof.ops = &dytc_profile_ops;
 
 	/* Create platform_profile structure and register */
-	err = devm_platform_profile_register(&priv->dytc->pprof, &priv->dytc);
-	if (err)
+	priv->dytc->ppdev = devm_platform_profile_register(&priv->platform_device->dev,
+							   "ideapad-laptop", &priv->dytc,
+							   &dytc_profile_ops);
+	if (IS_ERR(priv->dytc->ppdev)) {
+		err = PTR_ERR(priv->dytc->ppdev);
 		goto pp_reg_failed;
+	}
 
 	/* Ensure initial values are correct */
 	dytc_profile_refresh(priv);
drivers/platform/x86/inspur_platform_profile.c +4 -5
index e1631de6ad86..e02f5a55a6c5 100644
@@ -32,7 +32,7 @@ enum inspur_tmp_profile {
 
 struct inspur_wmi_priv {
 	struct wmi_device *wdev;
-	struct platform_profile_handler handler;
+	struct device *ppdev;
 };
 
 static int inspur_wmi_perform_query(struct wmi_device *wdev,
@@ -190,11 +190,10 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
 	priv->wdev = wdev;
 	dev_set_drvdata(&wdev->dev, priv);
 
-	priv->handler.name = "inspur-wmi";
-	priv->handler.dev = &wdev->dev;
-	priv->handler.ops = &inspur_platform_profile_ops;
+	priv->ppdev = devm_platform_profile_register(&wdev->dev, "inspur-wmi", priv,
+						     &inspur_platform_profile_ops);
 
-	return devm_platform_profile_register(&priv->handler, priv);
+	return PTR_ERR_OR_ZERO(priv->ppdev);
 }
 
 static const struct wmi_device_id inspur_wmi_id_table[] = {
drivers/platform/x86/thinkpad_acpi.c +5 -9
index c9226e8dc713..56c57cb45a76 100644
@@ -962,6 +962,7 @@ static const struct proc_ops dispatch_proc_ops = {
 static struct platform_device *tpacpi_pdev;
 static struct platform_device *tpacpi_sensors_pdev;
 static struct device *tpacpi_hwmon;
+static struct device *tpacpi_pprof;
 static struct input_dev *tpacpi_inputdev;
 static struct mutex tpacpi_inputdev_send_mutex;
 static LIST_HEAD(tpacpi_all_drivers);
@@ -10554,11 +10555,6 @@ static const struct platform_profile_ops dytc_profile_ops = {
 	.profile_set = dytc_profile_set,
 };
 
-static struct platform_profile_handler dytc_profile = {
-	.name = "thinkpad-acpi",
-	.ops = &dytc_profile_ops,
-};
-
 static void dytc_profile_refresh(void)
 {
 	enum platform_profile_option profile;
@@ -10587,7 +10583,7 @@ static void dytc_profile_refresh(void)
 	err = convert_dytc_to_profile(funcmode, perfmode, &profile);
 	if (!err && profile != dytc_current_profile) {
 		dytc_current_profile = profile;
-		platform_profile_notify(&dytc_profile);
+		platform_profile_notify(tpacpi_pprof);
 	}
 }
 
@@ -10648,14 +10644,14 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 	dbg_printk(TPACPI_DBG_INIT,
 			"DYTC version %d: thermal mode available\n", dytc_version);
 
-	dytc_profile.dev = &tpacpi_pdev->dev;
 	/* Create platform_profile structure and register */
-	err = devm_platform_profile_register(&dytc_profile, NULL);
+	tpacpi_pprof = devm_platform_profile_register(&tpacpi_pdev->dev, "thinkpad-acpi",
+						      NULL, &dytc_profile_ops);
 	/*
 	 * If for some reason platform_profiles aren't enabled
 	 * don't quit terminally.
 	 */
-	if (err)
+	if (IS_ERR(tpacpi_pprof))
 		return -ENODEV;
 
 	/* Ensure initial values are correct */
include/linux/platform_profile.h +8 -4
index 5ad1ab7b75e4..778d4c661c3c 100644
@@ -45,10 +45,14 @@ struct platform_profile_handler {
 	const struct platform_profile_ops *ops;
 };
 
-int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
-int platform_profile_remove(struct platform_profile_handler *pprof);
-int devm_platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
+struct device *platform_profile_register(struct device *dev, const char *name,
+					 void *drvdata,
+					 const struct platform_profile_ops *ops);
+int platform_profile_remove(struct device *dev);
+struct device *devm_platform_profile_register(struct device *dev, const char *name,
+					      void *drvdata,
+					      const struct platform_profile_ops *ops);
 int platform_profile_cycle(void);
-void platform_profile_notify(struct platform_profile_handler *pprof);
+void platform_profile_notify(struct device *dev);
 
 #endif  /*_PLATFORM_PROFILE_H_*/
Signature · 1 line
2.48.1
author maintainer
#22 lore raw

PATCH v4 16/19 ACPI: platform_profile: Move platform_profile_handler

In reply to Kurt Borja

platform_profile_handler is now an internal structure. Move it to platform_profile.c.

---
 drivers/acpi/platform_profile.c  |  9 +++++++++
 include/linux/platform_profile.h | 11 -----------
 2 files changed, 9 insertions(+), 11 deletions(-)
drivers/acpi/platform_profile.c +9 -0
index a1dfa168f51f..f27005a267a1 100644
@@ -14,6 +14,15 @@
 
 static DEFINE_MUTEX(profile_lock);
 
+struct platform_profile_handler {
+	const char *name;
+	struct device *dev;
+	struct device class_dev;
+	int minor;
+	unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
+	const struct platform_profile_ops *ops;
+};
+
 static const char * const profile_names[] = {
 	[PLATFORM_PROFILE_LOW_POWER] = "low-power",
 	[PLATFORM_PROFILE_COOL] = "cool",
include/linux/platform_profile.h +0 -11
index 778d4c661c3c..eea1daf85616 100644
@@ -28,23 +28,12 @@ enum platform_profile_option {
 	PLATFORM_PROFILE_LAST, /*must always be last */
 };
 
-struct platform_profile_handler;
-
 struct platform_profile_ops {
 	int (*probe)(void *drvdata, unsigned long *choices);
 	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
 	int (*profile_set)(struct device *dev, enum platform_profile_option profile);
 };
 
-struct platform_profile_handler {
-	const char *name;
-	struct device *dev;
-	struct device class_dev;
-	int minor;
-	unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
-	const struct platform_profile_ops *ops;
-};
-
 struct device *platform_profile_register(struct device *dev, const char *name,
 					 void *drvdata,
 					 const struct platform_profile_ops *ops);
Signature · 1 line
2.48.1
author maintainer
#23 lore raw

PATCH v4 17/19 ACPI: platform_profile: Clean platform_profile_handler

In reply to Kurt Borja

Remove parent device *dev from platform_profile_handler, as it's no longer accessed directly. Rename class_dev -> dev.

---
 drivers/acpi/platform_profile.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/acpi/platform_profile.c +10 -11
index f27005a267a1..8a1454e66cf1 100644
@@ -10,14 +10,13 @@
 #include <linux/platform_profile.h>
 #include <linux/sysfs.h>
 
-#define to_pprof_handler(d)	(container_of(d, struct platform_profile_handler, class_dev))
+#define to_pprof_handler(d)	(container_of(d, struct platform_profile_handler, dev))
 
 static DEFINE_MUTEX(profile_lock);
 
 struct platform_profile_handler {
 	const char *name;
-	struct device *dev;
-	struct device class_dev;
+	struct device dev;
 	int minor;
 	unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
 	const struct platform_profile_ops *ops;
@@ -90,8 +89,8 @@ static int _notify_class_profile(struct device *dev, void *data)
 	struct platform_profile_handler *handler = to_pprof_handler(dev);
 
 	lockdep_assert_held(&profile_lock);
-	sysfs_notify(&handler->class_dev.kobj, NULL, "profile");
-	kobject_uevent(&handler->class_dev.kobj, KOBJ_CHANGE);
+	sysfs_notify(&handler->dev.kobj, NULL, "profile");
+	kobject_uevent(&handler->dev.kobj, KOBJ_CHANGE);
 
 	return 0;
 }
@@ -517,12 +516,12 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 	pprof->name = name;
 	pprof->ops = ops;
 	pprof->minor = minor;
-	pprof->class_dev.class = &platform_profile_class;
-	pprof->class_dev.parent = dev;
-	dev_set_drvdata(&pprof->class_dev, drvdata);
-	dev_set_name(&pprof->class_dev, "platform-profile-%d", pprof->minor);
+	pprof->dev.class = &platform_profile_class;
+	pprof->dev.parent = dev;
+	dev_set_drvdata(&pprof->dev, drvdata);
+	dev_set_name(&pprof->dev, "platform-profile-%d", pprof->minor);
 	/* device_register() takes ownership of ppdev */
-	ppdev = &no_free_ptr(pprof)->class_dev;
+	ppdev = &no_free_ptr(pprof)->dev;
 	err = device_register(ppdev);
 	if (err) {
 		put_device(ppdev);
@@ -554,7 +553,7 @@ int platform_profile_remove(struct device *dev)
 	guard(mutex)(&profile_lock);
 
 	id = pprof->minor;
-	device_unregister(&pprof->class_dev);
+	device_unregister(&pprof->dev);
 	ida_free(&platform_profile_ida, id);
 
 	sysfs_notify(acpi_kobj, NULL, "platform_profile");
Signature · 1 line
2.48.1
author maintainer
#24 lore raw

PATCH v4 18/19 ACPI: platform_profile: Add documentation

In reply to Kurt Borja

Add kerneldoc and sysfs class documentation.

---
 .../ABI/testing/sysfs-class-platform-profile  | 44 +++++++++++++++++++
 drivers/acpi/platform_profile.c               | 33 ++++++++++++++
 include/linux/platform_profile.h              | 10 +++++
 3 files changed, 87 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Documentation/ABI/testing/sysfs-class-platform-profile new file +44 -0
new file mode 100644
index 000000000000..b5a3600080bc
@@ -0,0 +1,44 @@
+What:		/sys/class/platform-profile/platform-profile-X/name
+Date:		January 2025
+Description:	Name of the class device given by the driver.
+
+		RO
+
+What:		/sys/class/platform-profile/platform-profile-X/choices
+Date:		January 2025
+Description:	This file contains a space-separated list of profiles supported for this device.
+
+		Drivers must use the following standard profile-names:
+
+		====================	========================================
+		low-power		Low power consumption
+		cool			Cooler operation
+		quiet			Quieter operation
+		balanced		Balance between low power consumption
+					and performance
+		balanced-performance	Balance between performance and low
+					power consumption with a slight bias
+					towards performance
+		performance		High performance operation
+		custom			Driver defined custom profile
+		====================	========================================
+
+		RO
+
+What:		/sys/class/platform-profile/platform-profile-X/profile
+Date:		January 2025
+Description:	Reading this file gives the current selected profile for this
+		device. Writing this file with one of the strings from
+		platform_profile_choices changes the profile to the new value.
+
+		This file can be monitored for changes by polling for POLLPRI,
+		POLLPRI will be signaled on any changes, independent of those
+		changes coming from a userspace write; or coming from another
+		source such as e.g. a hotkey triggered profile change handled
+		either directly by the embedded-controller or fully handled
+		inside the kernel.
+
+		This file may also emit the string 'custom' to indicate
+		that the driver is using a driver defined custom profile.
+
+		RW
drivers/acpi/platform_profile.c +33 -0
index 8a1454e66cf1..4895f37dd549 100644
@@ -425,6 +425,10 @@ static const struct attribute_group platform_profile_group = {
 	.is_visible = profile_class_is_visible,
 };
 
+/**
+ * platform_profile_notify - Notify class device and legacy sysfs interface
+ * @dev: The class device
+ */
 void platform_profile_notify(struct device *dev)
 {
 	scoped_cond_guard(mutex_intr, return, &profile_lock) {
@@ -434,6 +438,11 @@ void platform_profile_notify(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(platform_profile_notify);
 
+/**
+ * platform_profile_cycle - Cycles profiles available on all registered class devices
+ *
+ * Return: 0 on success, -errno on failure
+ */
 int platform_profile_cycle(void)
 {
 	enum platform_profile_option next = PLATFORM_PROFILE_LAST;
@@ -477,6 +486,15 @@ int platform_profile_cycle(void)
 }
 EXPORT_SYMBOL_GPL(platform_profile_cycle);
 
+/**
+ * platform_profile_register - Creates and registers a platform profile class device
+ * @dev: Parent device
+ * @name: Name of the class device
+ * @drvdata: Driver data that will be attached to the class device
+ * @ops: Platform profile's mandatory operations
+ *
+ * Return: pointer to the new class device on success, ERR_PTR on failure
+ */
 struct device *platform_profile_register(struct device *dev, const char *name,
 					 void *drvdata,
 					 const struct platform_profile_ops *ops)
@@ -546,6 +564,12 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 }
 EXPORT_SYMBOL_GPL(platform_profile_register);
 
+/**
+ * platform_profile_remove - Unregisters a platform profile class device
+ * @dev: Class device
+ *
+ * Return: 0
+ */
 int platform_profile_remove(struct device *dev)
 {
 	struct platform_profile_handler *pprof = to_pprof_handler(dev);
@@ -571,6 +595,15 @@ static void devm_platform_profile_release(struct device *dev, void *res)
 	platform_profile_remove(*ppdev);
 }
 
+/**
+ * devm_platform_profile_register - Device managed version of platform_profile_register
+ * @dev: Parent device
+ * @name: Name of the class device
+ * @drvdata: Driver data that will be attached to the class device
+ * @ops: Platform profile's mandatory operations
+ *
+ * Return: pointer to the new class device on success, ERR_PTR on failure
+ */
 struct device *devm_platform_profile_register(struct device *dev, const char *name,
 					      void *drvdata,
 					      const struct platform_profile_ops *ops)
include/linux/platform_profile.h +10 -0
index eea1daf85616..8ab5b0e8eb2c 100644
@@ -28,6 +28,16 @@ enum platform_profile_option {
 	PLATFORM_PROFILE_LAST, /*must always be last */
 };
 
+/**
+ * struct platform_profile_ops - platform profile operations
+ * @probe: Callback to setup choices available to the new class device. These
+ *	   choices will only be enforced when setting a new profile, not when
+ *	   getting the current one.
+ * @profile_get: Callback that will be called when showing the current platform
+ *		 profile in sysfs.
+ * @profile_set: Callback that will be called when storing a new platform
+ *		 profile in sysfs.
+ */
 struct platform_profile_ops {
 	int (*probe)(void *drvdata, unsigned long *choices);
 	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
Signature · 1 line
2.48.1
author maintainer
#25 lore raw

PATCH v4 19/19 ACPI: platform_profile: Add a prefix to log messages

In reply to Kurt Borja

Declare a pr_fmt prefix.

---
 drivers/acpi/platform_profile.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/platform_profile.c +2 -0
index 4895f37dd549..c9e46b6e27da 100644
@@ -2,6 +2,8 @@
 
 /* Platform profile sysfs interface */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/acpi.h>
 #include <linux/bits.h>
 #include <linux/cleanup.h>
Signature · 1 line
2.48.1
maintainer
#26 lore raw
In reply to Kurt Borja
Quoted 3 lines · Kurt Borja

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

Hi all,

I was hoping to finish this in this cycle since it has been so close and has only required minor tweaks recently.

I went to review the changes once again and ended up applying this now into the review-ilpo-next branch. Thank you all who worked on to improve this series! :-)

There were minor nits, however, I hadto address while applying. I added the justification into 5/19 commit message and changed a few trivial things in the code. Please check that the diff compared with your series w/o any modifications makes sense:

Documentation/ABI/testing/sysfs-class-platform-profile +8 -4
index b5a3600080bc..dc72adfb830a 100644
@@ -1,12 +1,15 @@
 What:		/sys/class/platform-profile/platform-profile-X/name
-Date:		January 2025
+Date:		March 2025
+KernelVersion:	6.14
 Description:	Name of the class device given by the driver.
 
 		RO
 
 What:		/sys/class/platform-profile/platform-profile-X/choices
-Date:		January 2025
-Description:	This file contains a space-separated list of profiles supported for this device.
+Date:		March 2025
+KernelVersion:	6.14
+Description:	This file contains a space-separated list of profiles supported
+		for this device.
 
 		Drivers must use the following standard profile-names:
 
@@ -26,7 +29,8 @@ Description:	This file contains a space-separated list of profiles supported for
 		RO
 
 What:		/sys/class/platform-profile/platform-profile-X/profile
-Date:		January 2025
+Date:		March 2025
+KernelVersion:	6.14
 Description:	Reading this file gives the current selected profile for this
 		device. Writing this file with one of the strings from
 		platform_profile_choices changes the profile to the new value.
drivers/acpi/platform_profile.c +1 -1
index c9e46b6e27da..fc92e43d0fe9 100644
@@ -540,7 +540,7 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 	pprof->dev.parent = dev;
 	dev_set_drvdata(&pprof->dev, drvdata);
 	dev_set_name(&pprof->dev, "platform-profile-%d", pprof->minor);
-	/* device_register() takes ownership of ppdev */
+	/* device_register() takes ownership of pprof/ppdev */
 	ppdev = &no_free_ptr(pprof)->dev;
 	err = device_register(ppdev);
 	if (err) {
drivers/platform/x86/asus-wmi.c +1 -1
index 9a485f777591..1032c0e84e3d 100644
@@ -3894,7 +3894,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 	asus->ppdev = devm_platform_profile_register(dev, "asus-wmi", asus,
 						     &asus_wmi_platform_profile_ops);
 	if (IS_ERR(asus->ppdev)) {
-		dev_err(dev, "Failed to register a platform_profile class device");
+		dev_err(dev, "Failed to register a platform_profile class device\n");
 		return PTR_ERR(asus->ppdev);
 	}
 
drivers/platform/x86/dell/dell-pc.c +2 -3
index 1874d4adfb8a..483240bb36e7 100644
@@ -270,17 +270,16 @@ static int thermal_init(void)
 	if (IS_ERR(platform_device))
 		return PTR_ERR(platform_device);
 
-	/* Clean up if failed */
 	ppdev = devm_platform_profile_register(&platform_device->dev, "dell-pc",
 					       NULL, &dell_pc_platform_profile_ops);
 	if (IS_ERR(ppdev)) {
 		ret = PTR_ERR(ppdev);
-		goto cleanup_thermal_handler;
+		goto cleanup_platform_device;
 	}
 
 	return 0;
 
-cleanup_thermal_handler:
+cleanup_platform_device:
 	platform_device_unregister(platform_device);
 
 	return ret;
Quoted 55 lines

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3: https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
 i.
Reviewed-by on the v4 series
#28 lore raw
In reply to Kurt Borja

Hi

Quoted 59 lines · Kurt Borja

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Quoted 3 lines

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1

For the series up to v4 commit 15/19:

I need to go over the last few commits just once more, as there a few pieces I need to get my head around - and I'm not going to get it done this evening. Hope it's OK to add review for the bits that I have done.

Thanks
Mark

author maintainer
#27 lore raw
In reply to Ilpo Järvinen
Quoted 6 lines · Colombia Standard Time Ilpo Järvinen
Quoted 3 lines · Kurt Borja

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

Quoted 8 lines

Hi all,

I was hoping to finish this in this cycle since it has been so close and has only required minor tweaks recently.

I went to review the changes once again and ended up applying this now into the review-ilpo-next branch. Thank you all who worked on to improve this series! :-)

Thank you Mario, Ilpo and Mark for reviewing this :)

Review

Quoted 8 lines

There were minor nits, however, I hadto address while applying. I added the justification into 5/19 commit message and changed a few trivial things in the code. Please check that the diff compared with your series w/o any modifications makes sense:

(quoted diff) renamed from Documentation/ABI/testing/sysfs-class-platform-profile +0 -0

Documentation/ABI/testing/sysfs-class-platform-profile

Quoted 5 lines

index b5a3600080bc..dc72adfb830a 100644

Documentation/ABI/testing/sysfs-class-platform-profile +0 -0
@@ -1,12 +1,15 @@
 What:		/sys/class/platform-profile/platform-profile-X/name

Documentation/ABI/testing/sysfs-class-platform-profile line 9

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-platform-profile +2 -3
-Date:		January 2025
+Date:		March 2025
+KernelVersion:	6.14
 Description:	Name of the class device given by the driver.
 
 		RO
 
 What:		/sys/class/platform-profile/platform-profile-X/choices
-Date:		January 2025
-Description:	This file contains a space-separated list of profiles 

supported for this device.

Documentation/ABI/testing/sysfs-class-platform-profile

Quoted 3 lines
Documentation/ABI/testing/sysfs-class-platform-profile +3 -0
+Date:		March 2025
+KernelVersion:	6.14
+Description:	This file contains a space-separated list of profiles 

supported

Documentation/ABI/testing/sysfs-class-platform-profile Description: This file contains a space-separated list

Quoted 5 lines
Documentation/ABI/testing/sysfs-class-platform-profile +1 -0
+		for this device.
 
 		Drivers must use the following standard profile-names:
 
@@ -26,7 +29,8 @@ Description:	This file contains a space-separated list 

of profiles supported for

Documentation/ABI/testing/sysfs-class-platform-profile Description: This file contains a space-separated list of profiles supported for

Quoted 7 lines
Documentation/ABI/testing/sysfs-class-platform-profile +2 -1
 		RO
 
 What:		/sys/class/platform-profile/platform-profile-X/profile
-Date:		January 2025
+Date:		March 2025
+KernelVersion:	6.14
 Description:	Reading this file gives the current selected profile 

for this

Documentation/ABI/testing/sysfs-class-platform-profile Description: This file contains a space-separated list · line 36

Quoted 2 lines
Documentation/ABI/testing/sysfs-class-platform-profile +0 -0
 		device. Writing this file with one of the strings from
 		platform_profile_choices changes the profile to the new 

value.

drivers/acpi/platform_profile.c struct device *platform_profile_register(struct device

Quoted 5 lines
drivers/acpi/platform_profile.c +0 -0
index c9e46b6e27da..fc92e43d0fe9 100644
@@ -540,7 +540,7 @@ struct device *platform_profile_register(struct device 

*dev, const char *name,

drivers/platform/x86/asus-

Quoted 9 lines
drivers/acpi/platform_profile.c +1 -1
 	pprof->dev.parent = dev;
 	dev_set_drvdata(&pprof->dev, drvdata);
 	dev_set_name(&pprof->dev, "platform-profile-%d", pprof->minor);
-	/* device_register() takes ownership of ppdev */
+	/* device_register() takes ownership of pprof/ppdev */
 	ppdev = &no_free_ptr(pprof)->dev;
 	err = device_register(ppdev);
 	if (err) {
drivers/platform/x86/asus- renamed from drivers/platform/x86/asus-wmi.c +0 -0

wmi.c

drivers/platform/x86/asus-wmi.c static int platform_profile_setup(struct asus_wmi

Quoted 4 lines

index 9a485f777591..1032c0e84e3d 100644

drivers/platform/x86/asus-wmi.c +0 -0
@@ -3894,7 +3894,7 @@ static int platform_profile_setup(struct asus_wmi 

*asus)

drivers/platform/x86/asus-wmi.c static int platform_profile_setup(struct asus_wmi *asus) · line 3900

Quoted 2 lines
drivers/platform/x86/asus-wmi.c +0 -0
 	asus->ppdev = devm_platform_profile_register(dev, "asus-wmi", asus,
 

&asus_wmi_platform_profile_ops);

drivers/platform/x86/asus-wmi.c static int platform_profile_setup(struct asus_wmi · line 3897

Quoted 2 lines
drivers/platform/x86/asus-wmi.c +0 -1
 	if (IS_ERR(asus->ppdev)) {
-		dev_err(dev, "Failed to register a platform_profile 

class device");

drivers/platform/x86/asus-wmi.c static int platform_profile_setup(struct asus_wmi · line 3897

Quoted 1 line
drivers/platform/x86/asus-wmi.c +1 -0
+		dev_err(dev, "Failed to register a platform_profile class 

device\n");

drivers/platform/x86/dell/

Quoted 4 lines
drivers/platform/x86/asus-wmi.c +0 -0
 		return PTR_ERR(asus->ppdev);
 	}
 
drivers/platform/x86/dell/ renamed from drivers/platform/x86/dell/dell-pc.c +0 -0

dell-pc.c

drivers/platform/x86/dell/dell-pc.c static int thermal_init(void) · line 273

Quoted 9 lines

index 1874d4adfb8a..483240bb36e7 100644

drivers/platform/x86/dell/dell-pc.c +0 -1
@@ -270,17 +270,16 @@ static int thermal_init(void)
 	if (IS_ERR(platform_device))
 		return PTR_ERR(platform_device);
 
-	/* Clean up if failed */
 	ppdev = devm_platform_profile_register(&platform_device->dev, 

"dell-pc",

drivers/platform/x86/dell/dell-pc.c static int thermal_init(void) · line 274

Quoted 1 line
drivers/platform/x86/dell/dell-pc.c +0 -0
 					       NULL, 

&dell_pc_platform_profile_ops);

drivers/platform/x86/dell/dell-pc.c static int thermal_init(void) · line 285

Quoted 13 lines
drivers/platform/x86/dell/dell-pc.c +2 -2
 	if (IS_ERR(ppdev)) {
 		ret = PTR_ERR(ppdev);
-		goto cleanup_thermal_handler;
+		goto cleanup_platform_device;
 	}
 
 	return 0;
 
-cleanup_thermal_handler:
+cleanup_platform_device:
 	platform_device_unregister(platform_device);
 
 	return ret;

Changes LGTM, thanks.

~ Kurt

Quoted 59 lines
Quoted 57 lines

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3: https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

author maintainer
#29 lore raw
In reply to Mark Pearson
Quoted 62 lines · Mark Pearson

Hi

Quoted 59 lines · Kurt Borja

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Quoted 6 lines
Quoted 3 lines

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1

For the series up to v4 commit 15/19:

This covers the most important patches, thank you very much!

~ Kurt

Quoted 5 lines

I need to go over the last few commits just once more, as there a few pieces I need to get my head around - and I'm not going to get it done this evening. Hope it's OK to add review for the bits that I have done.

Thanks
Mark

maintainer
#30 lore raw
In reply to Mark Pearson
Quoted 66 lines · Mark Pearson

Hi

Quoted 59 lines · Kurt Borja

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Quoted 3 lines

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1
Quoted 6 lines

For the series up to v4 commit 15/19:

I need to go over the last few commits just once more, as there a few pieces I need to get my head around - and I'm not going to get it done this evening. Hope it's OK to add review for the bits that I have done.

I, for the first time ever, tested filter-branch and after some initial hickups on how to specify the commit range, got your Reviewed-bys added with single command :-).

While at it, I also managed to catch one rev-by line without any name+email (I assume it was b4 messing something up).

I'll soon want to merge fixes branch into for-next though, and after that adding any rev-bys will not be as easy as it was now.

Signature · 1 line
 i.
author maintainer
#31 lore raw
Quoted 71 lines · Ilpo Järvinen
Quoted 69 lines · Mark Pearson

Hi

Quoted 59 lines · Kurt Borja

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Quoted 3 lines

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1

For the series up to v4 commit 15/19:

Quoted 7 lines
Quoted 3 lines

I need to go over the last few commits just once more, as there a few pieces I need to get my head around - and I'm not going to get it done this evening. Hope it's OK to add review for the bits that I have done.

I, for the first time ever, tested filter-branch and after some initial hickups on how to specify the commit range, got your Reviewed-bys added with single command :-).

Awesome! I believe commit 15/19

a213108c01e0 ("ACPI: platform_profile: Remove platform_profile_handler from exported symbols")

is still missing a rev-by by Mark, if there is still time.

~ Kurt

Quoted 6 lines

While at it, I also managed to catch one rev-by line without any name+email (I assume it was b4 messing something up).

I'll soon want to merge fixes branch into for-next though, and after that adding any rev-bys will not be as easy as it was now.

maintainer
#32 lore raw
Quoted 80 lines · Kurt Borja
Quoted 71 lines · Ilpo Järvinen
Quoted 69 lines · Mark Pearson

Hi

Quoted 59 lines · Kurt Borja

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Quoted 3 lines

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1

For the series up to v4 commit 15/19:

Quoted 7 lines
Quoted 3 lines

I need to go over the last few commits just once more, as there a few pieces I need to get my head around - and I'm not going to get it done this evening. Hope it's OK to add review for the bits that I have done.

I, for the first time ever, tested filter-branch and after some initial hickups on how to specify the commit range, got your Reviewed-bys added with single command :-).

Quoted 5 lines

Awesome! I believe commit 15/19

a213108c01e0 ("ACPI: platform_profile: Remove platform_profile_handler from exported symbols")

is still missing a rev-by by Mark, if there is still time.

Thanks for noticing this. I just recalled the patch numbering wrong.

It should be fixed now.

Signature · 1 line
 i.
Reviewed-by
#33 lore raw

Hi,

Quoted 84 lines · Ilpo Järvinen
Quoted 82 lines · Kurt Borja
Quoted 71 lines · Ilpo Järvinen
Quoted 69 lines · Mark Pearson

Hi

Quoted 59 lines · Kurt Borja

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Quoted 3 lines

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1

For the series up to v4 commit 15/19:

Quoted 7 lines
Quoted 3 lines

I need to go over the last few commits just once more, as there a few pieces I need to get my head around - and I'm not going to get it done this evening. Hope it's OK to add review for the bits that I have done.

I, for the first time ever, tested filter-branch and after some initial hickups on how to specify the commit range, got your Reviewed-bys added with single command :-).

Awesome! I believe commit 15/19

Quoted 10 lines
Quoted 3 lines

a213108c01e0 ("ACPI: platform_profile: Remove platform_profile_handler from exported symbols")

is still missing a rev-by by Mark, if there is still time.

Thanks for noticing this. I just recalled the patch numbering wrong.

It should be fixed now.

Signature · 1 line
 i.

I finished my review, and no concerns. For the series:

Note - I'm building and will give it a sniff test too, but that will take a bit longer.

Thanks for your work on this Kurt

Mark

Tested-by
#34 lore raw
Quoted 98 lines · Mark Pearson

Hi,

Quoted 84 lines · Ilpo Järvinen
Quoted 82 lines · Kurt Borja
Quoted 71 lines · Ilpo Järvinen
Quoted 69 lines · Mark Pearson

Hi

Quoted 59 lines · Kurt Borja

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Quoted 3 lines

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1

For the series up to v4 commit 15/19:

Quoted 7 lines
Quoted 3 lines

I need to go over the last few commits just once more, as there a few pieces I need to get my head around - and I'm not going to get it done this evening. Hope it's OK to add review for the bits that I have done.

I, for the first time ever, tested filter-branch and after some initial hickups on how to specify the commit range, got your Reviewed-bys added with single command :-).

Awesome! I believe commit 15/19

Quoted 10 lines
Quoted 3 lines

a213108c01e0 ("ACPI: platform_profile: Remove platform_profile_handler from exported symbols")

is still missing a rev-by by Mark, if there is still time.

Thanks for noticing this. I just recalled the patch numbering wrong.

It should be fixed now.

Signature · 1 line
 i.
Quoted 8 lines

I finished my review, and no concerns. For the series:

Note - I'm building and will give it a sniff test too, but that will take a bit longer.

Thanks for your work on this Kurt

Ran the series on an X1 Carbon G12 and profiles working well. Was able to check the new class and didn't find any issues. For the series:

author maintainer
#35 lore raw
Quoted 104 lines · Mark Pearson
Quoted 101 lines · Mark Pearson

Hi,

Quoted 84 lines · Ilpo Järvinen
Quoted 82 lines · Kurt Borja
Quoted 71 lines · Ilpo Järvinen
Quoted 69 lines · Mark Pearson

Hi

Quoted 59 lines · Kurt Borja

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Quoted 3 lines

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1

For the series up to v4 commit 15/19:

Quoted 7 lines
Quoted 3 lines

I need to go over the last few commits just once more, as there a few pieces I need to get my head around - and I'm not going to get it done this evening. Hope it's OK to add review for the bits that I have done.

I, for the first time ever, tested filter-branch and after some initial hickups on how to specify the commit range, got your Reviewed-bys added with single command :-).

Awesome! I believe commit 15/19

Quoted 10 lines
Quoted 3 lines

a213108c01e0 ("ACPI: platform_profile: Remove platform_profile_handler from exported symbols")

is still missing a rev-by by Mark, if there is still time.

Thanks for noticing this. I just recalled the patch numbering wrong.

It should be fixed now.

Signature · 1 line
 i.

I finished my review, and no concerns. For the series:

Quoted 8 lines
Quoted 5 lines

Note - I'm building and will give it a sniff test too, but that will take a bit longer.

Thanks for your work on this Kurt

Ran the series on an X1 Carbon G12 and profiles working well. Was able to check the new class and didn't find any issues. For the series:

Thank you so much for testing this too! This gives me a lot of peace of mind :)

~ Kurt

maintainer Reviewed-by on v4 2/19
#3 lore raw

Re: [PATCH v4 02/19] ACPI: platform_profile: Let drivers set drvdata to the class device

In reply to Kurt Borja
Quoted 8 lines · Kurt Borja

Add *drvdata to platform_profile_register() signature and assign it to the class device.

While at it, pass specific driver state as drvdata to replace uses of container_of() with dev_get_drvdata().

Quoted 292 lines
---
  drivers/acpi/platform_profile.c                     | 7 ++++---
  drivers/platform/surface/surface_platform_profile.c | 6 +++---
  drivers/platform/x86/acer-wmi.c                     | 2 +-
  drivers/platform/x86/amd/pmf/sps.c                  | 6 +++---
  drivers/platform/x86/asus-wmi.c                     | 6 +++---
  drivers/platform/x86/dell/alienware-wmi.c           | 2 +-
  drivers/platform/x86/dell/dell-pc.c                 | 2 +-
  drivers/platform/x86/hp/hp-wmi.c                    | 2 +-
  drivers/platform/x86/ideapad-laptop.c               | 6 +++---
  drivers/platform/x86/inspur_platform_profile.c      | 8 +++-----
  drivers/platform/x86/thinkpad_acpi.c                | 2 +-
  include/linux/platform_profile.h                    | 4 ++--
  12 files changed, 26 insertions(+), 27 deletions(-)
drivers/acpi/platform_profile.c +4 -3
index 15f24adc57d4..689541d2e66c 100644
@@ -460,7 +460,7 @@ int platform_profile_cycle(void)
  }
  EXPORT_SYMBOL_GPL(platform_profile_cycle);
 
-int platform_profile_register(struct platform_profile_handler *pprof)
+int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata)
  {
  	int err;
 
@@ -480,6 +480,7 @@ int platform_profile_register(struct platform_profile_handler *pprof)
 
  	pprof->class_dev.class = &platform_profile_class;
  	pprof->class_dev.parent = pprof->dev;
+	dev_set_drvdata(&pprof->class_dev, drvdata);
  	dev_set_name(&pprof->class_dev, "platform-profile-%d", pprof->minor);
  	err = device_register(&pprof->class_dev);
  	if (err) {
@@ -529,7 +530,7 @@ static void devm_platform_profile_release(struct device *dev, void *res)
  	platform_profile_remove(*pprof);
  }
 
-int devm_platform_profile_register(struct platform_profile_handler *pprof)
+int devm_platform_profile_register(struct platform_profile_handler *pprof, void *drvdata)
  {
  	struct platform_profile_handler **dr;
  	int ret;
@@ -538,7 +539,7 @@ int devm_platform_profile_register(struct platform_profile_handler *pprof)
  	if (!dr)
  		return -ENOMEM;
 
-	ret = platform_profile_register(pprof);
+	ret = platform_profile_register(pprof, drvdata);
  	if (ret) {
  		devres_free(dr);
  		return ret;
drivers/platform/surface/surface_platform_profile.c +3 -3
index 6c87e982bfc8..edb9362003a4 100644
@@ -161,7 +161,7 @@ static int ssam_platform_profile_get(struct platform_profile_handler *pprof,
  	enum ssam_tmp_profile tp;
  	int status;
 
-	tpd = container_of(pprof, struct ssam_platform_profile_device, handler);
+	tpd = dev_get_drvdata(&pprof->class_dev);
 
  	status = ssam_tmp_profile_get(tpd->sdev, &tp);
  	if (status)
@@ -181,7 +181,7 @@ static int ssam_platform_profile_set(struct platform_profile_handler *pprof,
  	struct ssam_platform_profile_device *tpd;
  	int tp;
 
-	tpd = container_of(pprof, struct ssam_platform_profile_device, handler);
+	tpd = dev_get_drvdata(&pprof->class_dev);
 
  	tp = convert_profile_to_ssam_tmp(tpd->sdev, profile);
  	if (tp < 0)
@@ -224,7 +224,7 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
  	set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, tpd->handler.choices);
  	set_bit(PLATFORM_PROFILE_PERFORMANCE, tpd->handler.choices);
 
-	return platform_profile_register(&tpd->handler);
+	return platform_profile_register(&tpd->handler, tpd);
  }
 
  static void surface_platform_profile_remove(struct ssam_device *sdev)
drivers/platform/x86/acer-wmi.c +1 -1
index acf610d59168..1aedf0ef4189 100644
@@ -2073,7 +2073,7 @@ static int acer_platform_profile_setup(struct platform_device *device)
  				ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
  		}
 
-		err = platform_profile_register(&platform_profile_handler);
+		err = platform_profile_register(&platform_profile_handler, NULL);
  		if (err)
  			return err;
 
drivers/platform/x86/amd/pmf/sps.c +3 -3
index bd2bd6cfc39a..259a598acd3e 100644
@@ -285,7 +285,7 @@ bool is_pprof_balanced(struct amd_pmf_dev *pmf)
  static int amd_pmf_profile_get(struct platform_profile_handler *pprof,
  			       enum platform_profile_option *profile)
  {
-	struct amd_pmf_dev *pmf = container_of(pprof, struct amd_pmf_dev, pprof);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
 
  	*profile = pmf->current_profile;
  	return 0;
@@ -366,7 +366,7 @@ int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev)
  static int amd_pmf_profile_set(struct platform_profile_handler *pprof,
  			       enum platform_profile_option profile)
  {
-	struct amd_pmf_dev *pmf = container_of(pprof, struct amd_pmf_dev, pprof);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
  	int ret = 0;
 
  	pmf->current_profile = profile;
@@ -416,7 +416,7 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
  	set_bit(PLATFORM_PROFILE_PERFORMANCE, dev->pprof.choices);
 
  	/* Create platform_profile structure and register */
-	err = platform_profile_register(&dev->pprof);
+	err = platform_profile_register(&dev->pprof, dev);
  	if (err)
  		dev_err(dev->dev, "Failed to register SPS support, this is most likely an SBIOS bug: %d\n",
  			err);
drivers/platform/x86/asus-wmi.c +3 -3
index 6c674de60ec0..f91099792cb9 100644
@@ -3806,7 +3806,7 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
  	struct asus_wmi *asus;
  	int tp;
 
-	asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
+	asus = dev_get_drvdata(&pprof->class_dev);
  	tp = asus->throttle_thermal_policy_mode;
 
  	switch (tp) {
@@ -3832,7 +3832,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
  	struct asus_wmi *asus;
  	int tp;
 
-	asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
+	asus = dev_get_drvdata(&pprof->class_dev);
 
  	switch (profile) {
  	case PLATFORM_PROFILE_PERFORMANCE:
@@ -3887,7 +3887,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
  	set_bit(PLATFORM_PROFILE_PERFORMANCE,
  		asus->platform_profile_handler.choices);
 
-	err = platform_profile_register(&asus->platform_profile_handler);
+	err = platform_profile_register(&asus->platform_profile_handler, asus);
  	if (err == -EEXIST) {
  		pr_warn("%s, a platform_profile handler is already registered\n", __func__);
  		return 0;
drivers/platform/x86/dell/alienware-wmi.c +1 -1
index d7f577e0d146..154c417a438c 100644
@@ -1129,7 +1129,7 @@ static int create_thermal_profile(struct platform_device *platform_device)
  	pp_handler.name = "alienware-wmi";
  	pp_handler.dev = &platform_device->dev;
 
-	return devm_platform_profile_register(&pp_handler);
+	return devm_platform_profile_register(&pp_handler, NULL);
  }
 
  /*
drivers/platform/x86/dell/dell-pc.c +1 -1
index 3797a5721dbd..1a0a721d706f 100644
@@ -271,7 +271,7 @@ static int thermal_init(void)
  		set_bit(PLATFORM_PROFILE_PERFORMANCE, thermal_handler->choices);
 
  	/* Clean up if failed */
-	ret = platform_profile_register(thermal_handler);
+	ret = platform_profile_register(thermal_handler, NULL);
  	if (ret)
  		goto cleanup_thermal_handler;
 
drivers/platform/x86/hp/hp-wmi.c +1 -1
index 6d6e13a0c6e2..8e5e1422e024 100644
@@ -1629,7 +1629,7 @@ static int thermal_profile_setup(struct platform_device *device)
  	set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
  	set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
 
-	err = platform_profile_register(&platform_profile_handler);
+	err = platform_profile_register(&platform_profile_handler, NULL);
  	if (err)
  		return err;
 
drivers/platform/x86/ideapad-laptop.c +3 -3
index dc98f862a06d..ed0d880a07a9 100644
@@ -936,7 +936,7 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe
  static int dytc_profile_get(struct platform_profile_handler *pprof,
  			    enum platform_profile_option *profile)
  {
-	struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof);
+	struct ideapad_dytc_priv *dytc = dev_get_drvdata(&pprof->class_dev);
 
  	*profile = dytc->current_profile;
  	return 0;
@@ -989,7 +989,7 @@ static int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd,
  static int dytc_profile_set(struct platform_profile_handler *pprof,
  			    enum platform_profile_option profile)
  {
-	struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof);
+	struct ideapad_dytc_priv *dytc = dev_get_drvdata(&pprof->class_dev);
  	struct ideapad_private *priv = dytc->priv;
  	unsigned long output;
  	int err;
@@ -1114,7 +1114,7 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
  	set_bit(PLATFORM_PROFILE_PERFORMANCE, priv->dytc->pprof.choices);
 
  	/* Create platform_profile structure and register */
-	err = platform_profile_register(&priv->dytc->pprof);
+	err = platform_profile_register(&priv->dytc->pprof, &priv->dytc);
  	if (err)
  		goto pp_reg_failed;
 
drivers/platform/x86/inspur_platform_profile.c +3 -5
index 53af73a7fbf7..471fca50d1c9 100644
@@ -87,8 +87,7 @@ static int inspur_wmi_perform_query(struct wmi_device *wdev,
  static int inspur_platform_profile_set(struct platform_profile_handler *pprof,
  				       enum platform_profile_option profile)
  {
-	struct inspur_wmi_priv *priv = container_of(pprof, struct inspur_wmi_priv,
-						    handler);
+	struct inspur_wmi_priv *priv = dev_get_drvdata(&pprof->class_dev);
  	u8 ret_code[4] = {0, 0, 0, 0};
  	int ret;
 
@@ -135,8 +134,7 @@ static int inspur_platform_profile_set(struct platform_profile_handler *pprof,
  static int inspur_platform_profile_get(struct platform_profile_handler *pprof,
  				       enum platform_profile_option *profile)
  {
-	struct inspur_wmi_priv *priv = container_of(pprof, struct inspur_wmi_priv,
-						    handler);
+	struct inspur_wmi_priv *priv = dev_get_drvdata(&pprof->class_dev);
  	u8 ret_code[4] = {0, 0, 0, 0};
  	int ret;
 
@@ -186,7 +184,7 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
  	set_bit(PLATFORM_PROFILE_BALANCED, priv->handler.choices);
  	set_bit(PLATFORM_PROFILE_PERFORMANCE, priv->handler.choices);
 
-	return platform_profile_register(&priv->handler);
+	return platform_profile_register(&priv->handler, priv);
  }
 
  static void inspur_wmi_remove(struct wmi_device *wdev)
drivers/platform/x86/thinkpad_acpi.c +1 -1
index d99573e7a983..8be3f4e5366d 100644
@@ -10641,7 +10641,7 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 
  	dytc_profile.dev = &tpacpi_pdev->dev;
  	/* Create platform_profile structure and register */
-	err = platform_profile_register(&dytc_profile);
+	err = platform_profile_register(&dytc_profile, NULL);
  	/*
  	 * If for some reason platform_profiles aren't enabled
  	 * don't quit terminally.
include/linux/platform_profile.h +2 -2
index 8a9b8754f9ac..1c8fdda51eaa 100644
@@ -40,9 +40,9 @@ struct platform_profile_handler {
  				enum platform_profile_option profile);
  };
 
-int platform_profile_register(struct platform_profile_handler *pprof);
+int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
  int platform_profile_remove(struct platform_profile_handler *pprof);
-int devm_platform_profile_register(struct platform_profile_handler *pprof);
+int devm_platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
  int platform_profile_cycle(void);
  void platform_profile_notify(struct platform_profile_handler *pprof);
 
maintainer Reviewed-by on v4 3/19
#5 lore raw

Re: [PATCH v4 03/19] ACPI: platform_profile: Remove platform_profile_handler from callbacks

In reply to Kurt Borja
Quoted 6 lines · Kurt Borja

Devices can now set drvdata to the class device, thus passing the platform_profile_handler to callbacks is unnecessary. Instead pass the class device.

Quoted 368 lines
---
  drivers/acpi/platform_profile.c                    |  4 ++--
  .../platform/surface/surface_platform_profile.c    |  8 ++++----
  drivers/platform/x86/acer-wmi.c                    |  4 ++--
  drivers/platform/x86/amd/pmf/sps.c                 |  8 ++++----
  drivers/platform/x86/asus-wmi.c                    |  8 ++++----
  drivers/platform/x86/dell/alienware-wmi.c          |  4 ++--
  drivers/platform/x86/dell/dell-pc.c                |  4 ++--
  drivers/platform/x86/hp/hp-wmi.c                   | 14 +++++++-------
  drivers/platform/x86/ideapad-laptop.c              |  8 ++++----
  drivers/platform/x86/inspur_platform_profile.c     |  8 ++++----
  drivers/platform/x86/thinkpad_acpi.c               |  4 ++--
  include/linux/platform_profile.h                   |  6 ++----
  12 files changed, 39 insertions(+), 41 deletions(-)
drivers/acpi/platform_profile.c +2 -2
index 689541d2e66c..bd90aa4e8371 100644
@@ -65,7 +65,7 @@ static int _store_class_profile(struct device *dev, void *data)
  	if (!test_bit(*bit, handler->choices))
  		return -EOPNOTSUPP;
 
-	return handler->profile_set(handler, *bit);
+	return handler->profile_set(dev, *bit);
  }
 
  /**
@@ -102,7 +102,7 @@ static int get_class_profile(struct device *dev,
 
  	lockdep_assert_held(&profile_lock);
  	handler = to_pprof_handler(dev);
-	err = handler->profile_get(handler, &val);
+	err = handler->profile_get(dev, &val);
  	if (err) {
  		pr_err("Failed to get profile for handler %s\n", handler->name);
  		return err;
drivers/platform/surface/surface_platform_profile.c +4 -4
index edb9362003a4..26c1230e75df 100644
@@ -154,14 +154,14 @@ static int convert_profile_to_ssam_fan(struct ssam_device *sdev, enum platform_p
  	}
  }
 
-static int ssam_platform_profile_get(struct platform_profile_handler *pprof,
+static int ssam_platform_profile_get(struct device *dev,
  				     enum platform_profile_option *profile)
  {
  	struct ssam_platform_profile_device *tpd;
  	enum ssam_tmp_profile tp;
  	int status;
 
-	tpd = dev_get_drvdata(&pprof->class_dev);
+	tpd = dev_get_drvdata(dev);
 
  	status = ssam_tmp_profile_get(tpd->sdev, &tp);
  	if (status)
@@ -175,13 +175,13 @@ static int ssam_platform_profile_get(struct platform_profile_handler *pprof,
  	return 0;
  }
 
-static int ssam_platform_profile_set(struct platform_profile_handler *pprof,
+static int ssam_platform_profile_set(struct device *dev,
  				     enum platform_profile_option profile)
  {
  	struct ssam_platform_profile_device *tpd;
  	int tp;
 
-	tpd = dev_get_drvdata(&pprof->class_dev);
+	tpd = dev_get_drvdata(dev);
 
  	tp = convert_profile_to_ssam_tmp(tpd->sdev, profile);
  	if (tp < 0)
drivers/platform/x86/acer-wmi.c +2 -2
index 1aedf0ef4189..c68c0d744a69 100644
@@ -1950,7 +1950,7 @@ static int acer_toggle_turbo(void)
  }
 
  static int
-acer_predator_v4_platform_profile_get(struct platform_profile_handler *pprof,
+acer_predator_v4_platform_profile_get(struct device *dev,
  				      enum platform_profile_option *profile)
  {
  	u8 tp;
@@ -1984,7 +1984,7 @@ acer_predator_v4_platform_profile_get(struct platform_profile_handler *pprof,
  }
 
  static int
-acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,
+acer_predator_v4_platform_profile_set(struct device *dev,
  				      enum platform_profile_option profile)
  {
  	int err, tp;
drivers/platform/x86/amd/pmf/sps.c +4 -4
index 259a598acd3e..cf2e51f67787 100644
@@ -282,10 +282,10 @@ bool is_pprof_balanced(struct amd_pmf_dev *pmf)
  	return (pmf->current_profile == PLATFORM_PROFILE_BALANCED) ? true : false;
  }
 
-static int amd_pmf_profile_get(struct platform_profile_handler *pprof,
+static int amd_pmf_profile_get(struct device *dev,
  			       enum platform_profile_option *profile)
  {
-	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(dev);
 
  	*profile = pmf->current_profile;
  	return 0;
@@ -363,10 +363,10 @@ int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev)
  	return 0;
  }
 
-static int amd_pmf_profile_set(struct platform_profile_handler *pprof,
+static int amd_pmf_profile_set(struct device *dev,
  			       enum platform_profile_option profile)
  {
-	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(dev);
  	int ret = 0;
 
  	pmf->current_profile = profile;
drivers/platform/x86/asus-wmi.c +4 -4
index f91099792cb9..6b8b30551d36 100644
@@ -3800,13 +3800,13 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
  static DEVICE_ATTR_RW(throttle_thermal_policy);
 
  /* Platform profile ***********************************************************/
-static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
+static int asus_wmi_platform_profile_get(struct device *dev,
  					enum platform_profile_option *profile)
  {
  	struct asus_wmi *asus;
  	int tp;
 
-	asus = dev_get_drvdata(&pprof->class_dev);
+	asus = dev_get_drvdata(dev);
  	tp = asus->throttle_thermal_policy_mode;
 
  	switch (tp) {
@@ -3826,13 +3826,13 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
  	return 0;
  }
 
-static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
+static int asus_wmi_platform_profile_set(struct device *dev,
  					enum platform_profile_option profile)
  {
  	struct asus_wmi *asus;
  	int tp;
 
-	asus = dev_get_drvdata(&pprof->class_dev);
+	asus = dev_get_drvdata(dev);
 
  	switch (profile) {
  	case PLATFORM_PROFILE_PERFORMANCE:
drivers/platform/x86/dell/alienware-wmi.c +2 -2
index 154c417a438c..0346f8e88bf8 100644
@@ -1026,7 +1026,7 @@ static int wmax_game_shift_status(u8 operation, u32 *out_data)
  	return 0;
  }
 
-static int thermal_profile_get(struct platform_profile_handler *pprof,
+static int thermal_profile_get(struct device *dev,
  			       enum platform_profile_option *profile)
  {
  	u32 out_data;
@@ -1052,7 +1052,7 @@ static int thermal_profile_get(struct platform_profile_handler *pprof,
  	return 0;
  }
 
-static int thermal_profile_set(struct platform_profile_handler *pprof,
+static int thermal_profile_set(struct device *dev,
  			       enum platform_profile_option profile)
  {
  	if (quirks->gmode) {
drivers/platform/x86/dell/dell-pc.c +2 -2
index 1a0a721d706f..c86b05b5a1cb 100644
@@ -185,7 +185,7 @@ static int thermal_set_mode(enum thermal_mode_bits state)
  	return dell_send_request(&buffer, CLASS_INFO, SELECT_THERMAL_MANAGEMENT);
  }
 
-static int thermal_platform_profile_set(struct platform_profile_handler *pprof,
+static int thermal_platform_profile_set(struct device *dev,
  					enum platform_profile_option profile)
  {
  	switch (profile) {
@@ -202,7 +202,7 @@ static int thermal_platform_profile_set(struct platform_profile_handler *pprof,
  	}
  }
 
-static int thermal_platform_profile_get(struct platform_profile_handler *pprof,
+static int thermal_platform_profile_get(struct device *dev,
  					enum platform_profile_option *profile)
  {
  	int ret;
drivers/platform/x86/hp/hp-wmi.c +7 -7
index 8e5e1422e024..b8e62dc9cecd 100644
@@ -1221,7 +1221,7 @@ static int platform_profile_omen_get_ec(enum platform_profile_option *profile)
  	return 0;
  }
 
-static int platform_profile_omen_get(struct platform_profile_handler *pprof,
+static int platform_profile_omen_get(struct device *dev,
  				     enum platform_profile_option *profile)
  {
  	/*
@@ -1318,7 +1318,7 @@ static int platform_profile_omen_set_ec(enum platform_profile_option profile)
  	return 0;
  }
 
-static int platform_profile_omen_set(struct platform_profile_handler *pprof,
+static int platform_profile_omen_set(struct device *dev,
  				     enum platform_profile_option profile)
  {
  	int err;
@@ -1345,7 +1345,7 @@ static int thermal_profile_set(int thermal_profile)
  							   sizeof(thermal_profile), 0);
  }
 
-static int hp_wmi_platform_profile_get(struct platform_profile_handler *pprof,
+static int hp_wmi_platform_profile_get(struct device *dev,
  					enum platform_profile_option *profile)
  {
  	int tp;
@@ -1374,7 +1374,7 @@ static int hp_wmi_platform_profile_get(struct platform_profile_handler *pprof,
  	return 0;
  }
 
-static int hp_wmi_platform_profile_set(struct platform_profile_handler *pprof,
+static int hp_wmi_platform_profile_set(struct device *dev,
  					enum platform_profile_option profile)
  {
  	int err, tp;
@@ -1440,11 +1440,11 @@ static int platform_profile_victus_get_ec(enum platform_profile_option *profile)
  	return 0;
  }
 
-static int platform_profile_victus_get(struct platform_profile_handler *pprof,
+static int platform_profile_victus_get(struct device *dev,
  				       enum platform_profile_option *profile)
  {
  	/* Same behaviour as platform_profile_omen_get */
-	return platform_profile_omen_get(pprof, profile);
+	return platform_profile_omen_get(dev, profile);
  }
 
  static int platform_profile_victus_set_ec(enum platform_profile_option profile)
@@ -1472,7 +1472,7 @@ static int platform_profile_victus_set_ec(enum platform_profile_option profile)
  	return 0;
  }
 
-static int platform_profile_victus_set(struct platform_profile_handler *pprof,
+static int platform_profile_victus_set(struct device *dev,
  				       enum platform_profile_option profile)
  {
  	int err;
drivers/platform/x86/ideapad-laptop.c +4 -4
index ed0d880a07a9..fc317f42bb82 100644
@@ -933,10 +933,10 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe
   * dytc_profile_get: Function to register with platform_profile
   * handler. Returns current platform profile.
   */
-static int dytc_profile_get(struct platform_profile_handler *pprof,
+static int dytc_profile_get(struct device *dev,
  			    enum platform_profile_option *profile)
  {
-	struct ideapad_dytc_priv *dytc = dev_get_drvdata(&pprof->class_dev);
+	struct ideapad_dytc_priv *dytc = dev_get_drvdata(dev);
 
  	*profile = dytc->current_profile;
  	return 0;
@@ -986,10 +986,10 @@ static int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd,
   * dytc_profile_set: Function to register with platform_profile
   * handler. Sets current platform profile.
   */
-static int dytc_profile_set(struct platform_profile_handler *pprof,
+static int dytc_profile_set(struct device *dev,
  			    enum platform_profile_option profile)
  {
-	struct ideapad_dytc_priv *dytc = dev_get_drvdata(&pprof->class_dev);
+	struct ideapad_dytc_priv *dytc = dev_get_drvdata(dev);
  	struct ideapad_private *priv = dytc->priv;
  	unsigned long output;
  	int err;
drivers/platform/x86/inspur_platform_profile.c +4 -4
index 471fca50d1c9..47d2dbbf3392 100644
@@ -84,10 +84,10 @@ static int inspur_wmi_perform_query(struct wmi_device *wdev,
   *         0x0: No Error
   *         0x1: Error
   */
-static int inspur_platform_profile_set(struct platform_profile_handler *pprof,
+static int inspur_platform_profile_set(struct device *dev,
  				       enum platform_profile_option profile)
  {
-	struct inspur_wmi_priv *priv = dev_get_drvdata(&pprof->class_dev);
+	struct inspur_wmi_priv *priv = dev_get_drvdata(dev);
  	u8 ret_code[4] = {0, 0, 0, 0};
  	int ret;
 
@@ -131,10 +131,10 @@ static int inspur_platform_profile_set(struct platform_profile_handler *pprof,
   *         0x1: Performance Mode
   *         0x2: Power Saver Mode
   */
-static int inspur_platform_profile_get(struct platform_profile_handler *pprof,
+static int inspur_platform_profile_get(struct device *dev,
  				       enum platform_profile_option *profile)
  {
-	struct inspur_wmi_priv *priv = dev_get_drvdata(&pprof->class_dev);
+	struct inspur_wmi_priv *priv = dev_get_drvdata(dev);
  	u8 ret_code[4] = {0, 0, 0, 0};
  	int ret;
 
drivers/platform/x86/thinkpad_acpi.c +2 -2
index 8be3f4e5366d..0abe22228fdb 100644
@@ -10415,7 +10415,7 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe
   * dytc_profile_get: Function to register with platform_profile
   * handler. Returns current platform profile.
   */
-static int dytc_profile_get(struct platform_profile_handler *pprof,
+static int dytc_profile_get(struct device *dev,
  			    enum platform_profile_option *profile)
  {
  	*profile = dytc_current_profile;
@@ -10490,7 +10490,7 @@ static int dytc_cql_command(int command, int *output)
   * dytc_profile_set: Function to register with platform_profile
   * handler. Sets current platform profile.
   */
-static int dytc_profile_set(struct platform_profile_handler *pprof,
+static int dytc_profile_set(struct device *dev,
  			    enum platform_profile_option profile)
  {
  	int perfmode;
include/linux/platform_profile.h +2 -4
index 1c8fdda51eaa..5296d886c243 100644
@@ -34,10 +34,8 @@ struct platform_profile_handler {
  	struct device class_dev;
  	int minor;
  	unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
-	int (*profile_get)(struct platform_profile_handler *pprof,
-				enum platform_profile_option *profile);
-	int (*profile_set)(struct platform_profile_handler *pprof,
-				enum platform_profile_option profile);
+	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
+	int (*profile_set)(struct device *dev, enum platform_profile_option profile);
  };
 
  int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
maintainer Reviewed-by on v4 4/19
#7 lore raw

Re: [PATCH v4 04/19] ACPI: platform_profile: Add `ops` member to handlers

In reply to Kurt Borja
Quoted 5 lines · Kurt Borja

Replace *profile_get and *profile_set members with a general *ops member.

Quoted 365 lines
---
  drivers/acpi/platform_profile.c               |  6 ++---
  .../surface/surface_platform_profile.c        |  8 +++++--
  drivers/platform/x86/acer-wmi.c               | 11 +++++----
  drivers/platform/x86/amd/pmf/sps.c            |  8 +++++--
  drivers/platform/x86/asus-wmi.c               |  8 +++++--
  drivers/platform/x86/dell/alienware-wmi.c     |  8 +++++--
  drivers/platform/x86/dell/dell-pc.c           |  8 +++++--
  drivers/platform/x86/hp/hp-wmi.c              | 24 ++++++++++++++-----
  drivers/platform/x86/ideapad-laptop.c         |  8 +++++--
  .../platform/x86/inspur_platform_profile.c    |  8 +++++--
  drivers/platform/x86/thinkpad_acpi.c          |  8 +++++--
  include/linux/platform_profile.h              | 10 ++++++--
  12 files changed, 84 insertions(+), 31 deletions(-)
drivers/acpi/platform_profile.c +3 -3
index bd90aa4e8371..161a05d57b0f 100644
@@ -65,7 +65,7 @@ static int _store_class_profile(struct device *dev, void *data)
  	if (!test_bit(*bit, handler->choices))
  		return -EOPNOTSUPP;
 
-	return handler->profile_set(dev, *bit);
+	return handler->ops->profile_set(dev, *bit);
  }
 
  /**
@@ -102,7 +102,7 @@ static int get_class_profile(struct device *dev,
 
  	lockdep_assert_held(&profile_lock);
  	handler = to_pprof_handler(dev);
-	err = handler->profile_get(dev, &val);
+	err = handler->ops->profile_get(dev, &val);
  	if (err) {
  		pr_err("Failed to get profile for handler %s\n", handler->name);
  		return err;
@@ -466,7 +466,7 @@ int platform_profile_register(struct platform_profile_handler *pprof, void *drvd
 
  	/* Sanity check the profile handler */
  	if (!pprof || bitmap_empty(pprof->choices, PLATFORM_PROFILE_LAST) ||
-	    !pprof->profile_set || !pprof->profile_get) {
+	    !pprof->ops->profile_set || !pprof->ops->profile_get) {
  		pr_err("platform_profile: handler is invalid\n");
  		return -EINVAL;
  	}
drivers/platform/surface/surface_platform_profile.c +6 -2
index 26c1230e75df..76967bfeeef8 100644
@@ -201,6 +201,11 @@ static int ssam_platform_profile_set(struct device *dev,
  	return tp;
  }
 
+static const struct platform_profile_ops ssam_platform_profile_ops = {
+	.profile_get = ssam_platform_profile_get,
+	.profile_set = ssam_platform_profile_set,
+};
+
  static int surface_platform_profile_probe(struct ssam_device *sdev)
  {
  	struct ssam_platform_profile_device *tpd;
@@ -214,8 +219,7 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
 
  	tpd->handler.name = "Surface Platform Profile";
  	tpd->handler.dev = &sdev->dev;
-	tpd->handler.profile_get = ssam_platform_profile_get;
-	tpd->handler.profile_set = ssam_platform_profile_set;
+	tpd->handler.ops = &ssam_platform_profile_ops;
 
  	tpd->has_fan = device_property_read_bool(&sdev->dev, "has_fan");
 
drivers/platform/x86/acer-wmi.c +7 -4
index c68c0d744a69..63e6bd1fe339 100644
@@ -2019,6 +2019,11 @@ acer_predator_v4_platform_profile_set(struct device *dev,
  	return 0;
  }
 
+static const struct platform_profile_ops acer_predator_v4_platform_profile_ops = {
+	.profile_get = acer_predator_v4_platform_profile_get,
+	.profile_set = acer_predator_v4_platform_profile_set,
+};
+
  static int acer_platform_profile_setup(struct platform_device *device)
  {
  	if (quirks->predator_v4) {
@@ -2027,10 +2032,8 @@ static int acer_platform_profile_setup(struct platform_device *device)
 
  		platform_profile_handler.name = "acer-wmi";
  		platform_profile_handler.dev = &device->dev;
-		platform_profile_handler.profile_get =
-			acer_predator_v4_platform_profile_get;
-		platform_profile_handler.profile_set =
-			acer_predator_v4_platform_profile_set;
+		platform_profile_handler.ops =
+			&acer_predator_v4_platform_profile_ops;
 
  		err = WMID_gaming_get_misc_setting(ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES,
  						   (u8 *)&supported_profiles);
drivers/platform/x86/amd/pmf/sps.c +6 -2
index cf2e51f67787..6ae82ae86d22 100644
@@ -387,6 +387,11 @@ static int amd_pmf_profile_set(struct device *dev,
  	return 0;
  }
 
+static const struct platform_profile_ops amd_pmf_profile_ops = {
+	.profile_get = amd_pmf_profile_get,
+	.profile_set = amd_pmf_profile_set,
+};
+
  int amd_pmf_init_sps(struct amd_pmf_dev *dev)
  {
  	int err;
@@ -407,8 +412,7 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
 
  	dev->pprof.name = "amd-pmf";
  	dev->pprof.dev = dev->dev;
-	dev->pprof.profile_get = amd_pmf_profile_get;
-	dev->pprof.profile_set = amd_pmf_profile_set;
+	dev->pprof.ops = &amd_pmf_profile_ops;
 
  	/* Setup supported modes */
  	set_bit(PLATFORM_PROFILE_LOW_POWER, dev->pprof.choices);
drivers/platform/x86/asus-wmi.c +6 -2
index 6b8b30551d36..992956c89d38 100644
@@ -3852,6 +3852,11 @@ static int asus_wmi_platform_profile_set(struct device *dev,
  	return throttle_thermal_policy_write(asus);
  }
 
+static const struct platform_profile_ops asus_wmi_platform_profile_ops = {
+	.profile_get = asus_wmi_platform_profile_get,
+	.profile_set = asus_wmi_platform_profile_set,
+};
+
  static int platform_profile_setup(struct asus_wmi *asus)
  {
  	struct device *dev = &asus->platform_device->dev;
@@ -3878,8 +3883,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 
  	asus->platform_profile_handler.name = "asus-wmi";
  	asus->platform_profile_handler.dev = dev;
-	asus->platform_profile_handler.profile_get = asus_wmi_platform_profile_get;
-	asus->platform_profile_handler.profile_set = asus_wmi_platform_profile_set;
+	asus->platform_profile_handler.ops = &asus_wmi_platform_profile_ops;
 
  	set_bit(PLATFORM_PROFILE_QUIET, asus->platform_profile_handler.choices);
  	set_bit(PLATFORM_PROFILE_BALANCED,
drivers/platform/x86/dell/alienware-wmi.c +6 -2
index 0346f8e88bf8..b8359b177a0f 100644
@@ -1078,6 +1078,11 @@ static int thermal_profile_set(struct device *dev,
  	return wmax_thermal_control(supported_thermal_profiles[profile]);
  }
 
+static const struct platform_profile_ops awcc_platform_profile_ops = {
+	.profile_get = thermal_profile_get,
+	.profile_set = thermal_profile_set,
+};
+
  static int create_thermal_profile(struct platform_device *platform_device)
  {
  	enum platform_profile_option profile;
@@ -1124,10 +1129,9 @@ static int create_thermal_profile(struct platform_device *platform_device)
  		set_bit(PLATFORM_PROFILE_PERFORMANCE, pp_handler.choices);
  	}
 
-	pp_handler.profile_get = thermal_profile_get;
-	pp_handler.profile_set = thermal_profile_set;
  	pp_handler.name = "alienware-wmi";
  	pp_handler.dev = &platform_device->dev;
+	pp_handler.ops = &awcc_platform_profile_ops;
 
  	return devm_platform_profile_register(&pp_handler, NULL);
  }
drivers/platform/x86/dell/dell-pc.c +6 -2
index c86b05b5a1cb..9010a231f209 100644
@@ -231,6 +231,11 @@ static int thermal_platform_profile_get(struct device *dev,
  	return 0;
  }
 
+static const struct platform_profile_ops dell_pc_platform_profile_ops = {
+	.profile_get = thermal_platform_profile_get,
+	.profile_set = thermal_platform_profile_set,
+};
+
  static int thermal_init(void)
  {
  	int ret;
@@ -258,8 +263,7 @@ static int thermal_init(void)
  	}
  	thermal_handler->name = "dell-pc";
  	thermal_handler->dev = &platform_device->dev;
-	thermal_handler->profile_get = thermal_platform_profile_get;
-	thermal_handler->profile_set = thermal_platform_profile_set;
+	thermal_handler->ops = &dell_pc_platform_profile_ops;
 
  	if (supported_modes & DELL_QUIET)
  		set_bit(PLATFORM_PROFILE_QUIET, thermal_handler->choices);
drivers/platform/x86/hp/hp-wmi.c +18 -6
index b8e62dc9cecd..60328b35be74 100644
@@ -1565,6 +1565,21 @@ static inline void omen_unregister_powersource_event_handler(void)
  	unregister_acpi_notifier(&platform_power_source_nb);
  }
 
+static const struct platform_profile_ops platform_profile_omen_ops = {
+	.profile_get = platform_profile_omen_get,
+	.profile_set = platform_profile_omen_set,
+};
+
+static const struct platform_profile_ops platform_profile_victus_ops = {
+	.profile_get = platform_profile_victus_get,
+	.profile_set = platform_profile_victus_set,
+};
+
+static const struct platform_profile_ops hp_wmi_platform_profile_ops = {
+	.profile_get = hp_wmi_platform_profile_get,
+	.profile_set = hp_wmi_platform_profile_set,
+};
+
  static int thermal_profile_setup(struct platform_device *device)
  {
  	int err, tp;
@@ -1582,8 +1597,7 @@ static int thermal_profile_setup(struct platform_device *device)
  		if (err < 0)
  			return err;
 
-		platform_profile_handler.profile_get = platform_profile_omen_get;
-		platform_profile_handler.profile_set = platform_profile_omen_set;
+		platform_profile_handler.ops = &platform_profile_omen_ops;
 
  		set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
  	} else if (is_victus_thermal_profile()) {
@@ -1599,8 +1613,7 @@ static int thermal_profile_setup(struct platform_device *device)
  		if (err < 0)
  			return err;
 
-		platform_profile_handler.profile_get = platform_profile_victus_get;
-		platform_profile_handler.profile_set = platform_profile_victus_set;
+		platform_profile_handler.ops = &platform_profile_victus_ops;
 
  		set_bit(PLATFORM_PROFILE_QUIET, platform_profile_handler.choices);
  	} else {
@@ -1617,8 +1630,7 @@ static int thermal_profile_setup(struct platform_device *device)
  		if (err)
  			return err;
 
-		platform_profile_handler.profile_get = hp_wmi_platform_profile_get;
-		platform_profile_handler.profile_set = hp_wmi_platform_profile_set;
+		platform_profile_handler.ops = &hp_wmi_platform_profile_ops;
 
  		set_bit(PLATFORM_PROFILE_QUIET, platform_profile_handler.choices);
  		set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
drivers/platform/x86/ideapad-laptop.c +6 -2
index fc317f42bb82..96e99513b0b5 100644
@@ -1063,6 +1063,11 @@ static const struct dmi_system_id ideapad_dytc_v4_allow_table[] = {
  	{}
  };
 
+static const struct platform_profile_ops dytc_profile_ops = {
+	.profile_get = dytc_profile_get,
+	.profile_set = dytc_profile_set,
+};
+
  static int ideapad_dytc_profile_init(struct ideapad_private *priv)
  {
  	int err, dytc_version;
@@ -1105,8 +1110,7 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
  	priv->dytc->pprof.name = "ideapad-laptop";
  	priv->dytc->pprof.dev = &priv->platform_device->dev;
  	priv->dytc->priv = priv;
-	priv->dytc->pprof.profile_get = dytc_profile_get;
-	priv->dytc->pprof.profile_set = dytc_profile_set;
+	priv->dytc->pprof.ops = &dytc_profile_ops;
 
  	/* Setup supported modes */
  	set_bit(PLATFORM_PROFILE_LOW_POWER, priv->dytc->pprof.choices);
drivers/platform/x86/inspur_platform_profile.c +6 -2
index 47d2dbbf3392..d0a8e4eebffa 100644
@@ -164,6 +164,11 @@ static int inspur_platform_profile_get(struct device *dev,
  	return 0;
  }
 
+static const struct platform_profile_ops inspur_platform_profile_ops = {
+	.profile_get = inspur_platform_profile_get,
+	.profile_set = inspur_platform_profile_set,
+};
+
  static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
  {
  	struct inspur_wmi_priv *priv;
@@ -177,8 +182,7 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
 
  	priv->handler.name = "inspur-wmi";
  	priv->handler.dev = &wdev->dev;
-	priv->handler.profile_get = inspur_platform_profile_get;
-	priv->handler.profile_set = inspur_platform_profile_set;
+	priv->handler.ops = &inspur_platform_profile_ops;
 
  	set_bit(PLATFORM_PROFILE_LOW_POWER, priv->handler.choices);
  	set_bit(PLATFORM_PROFILE_BALANCED, priv->handler.choices);
drivers/platform/x86/thinkpad_acpi.c +6 -2
index 0abe22228fdb..9e26f5670fc7 100644
@@ -10539,12 +10539,16 @@ static int dytc_profile_set(struct device *dev,
  	return err;
  }
 
-static struct platform_profile_handler dytc_profile = {
-	.name = "thinkpad-acpi",
+static const struct platform_profile_ops dytc_profile_ops = {
  	.profile_get = dytc_profile_get,
  	.profile_set = dytc_profile_set,
  };
 
+static struct platform_profile_handler dytc_profile = {
+	.name = "thinkpad-acpi",
+	.ops = &dytc_profile_ops,
+};
+
  static void dytc_profile_refresh(void)
  {
  	enum platform_profile_option profile;
include/linux/platform_profile.h +8 -2
index 5296d886c243..6013c05d7b86 100644
@@ -28,14 +28,20 @@ enum platform_profile_option {
  	PLATFORM_PROFILE_LAST, /*must always be last */
  };
 
+struct platform_profile_handler;
+
+struct platform_profile_ops {
+	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
+	int (*profile_set)(struct device *dev, enum platform_profile_option profile);
+};
+
  struct platform_profile_handler {
  	const char *name;
  	struct device *dev;
  	struct device class_dev;
  	int minor;
  	unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
-	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
-	int (*profile_set)(struct device *dev, enum platform_profile_option profile);
+	const struct platform_profile_ops *ops;
  };
 
  int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
maintainer Reviewed-by on v4 5/19
#9 lore raw

Re: [PATCH v4 05/19] ACPI: platform_profile: Add `probe` to platform_profile_ops

In reply to Kurt Borja
Quoted 5 lines · Kurt Borja

Add a probe callback to platform_profile_ops, which lets drivers initialize the choices member manually.

Quoted 575 lines
---
  drivers/acpi/platform_profile.c               | 15 +++-
  .../surface/surface_platform_profile.c        | 16 ++--
  drivers/platform/x86/acer-wmi.c               | 88 ++++++++++---------
  drivers/platform/x86/amd/pmf/sps.c            | 15 ++--
  drivers/platform/x86/asus-wmi.c               | 16 ++--
  drivers/platform/x86/dell/alienware-wmi.c     | 24 +++--
  drivers/platform/x86/dell/dell-pc.c           | 26 +++---
  drivers/platform/x86/hp/hp-wmi.c              | 29 ++++--
  drivers/platform/x86/ideapad-laptop.c         | 15 ++--
  .../platform/x86/inspur_platform_profile.c    | 14 ++-
  drivers/platform/x86/thinkpad_acpi.c          | 15 ++--
  include/linux/platform_profile.h              |  1 +
  12 files changed, 172 insertions(+), 102 deletions(-)
drivers/acpi/platform_profile.c +13 -2
index 161a05d57b0f..120f8402facd 100644
@@ -465,12 +465,23 @@ int platform_profile_register(struct platform_profile_handler *pprof, void *drvd
  	int err;
 
  	/* Sanity check the profile handler */
-	if (!pprof || bitmap_empty(pprof->choices, PLATFORM_PROFILE_LAST) ||
-	    !pprof->ops->profile_set || !pprof->ops->profile_get) {
+	if (!pprof || !pprof->ops->profile_set || !pprof->ops->profile_get ||
+	    !pprof->ops->probe) {
  		pr_err("platform_profile: handler is invalid\n");
  		return -EINVAL;
  	}
 
+	err = pprof->ops->probe(drvdata, pprof->choices);
+	if (err) {
+		dev_err(pprof->dev, "platform_profile probe failed\n");
+		return err;
+	}
+
+	if (bitmap_empty(pprof->choices, PLATFORM_PROFILE_LAST)) {
+		dev_err(pprof->dev, "Failed to register a platform_profile class device with empty choices\n");
+		return -EINVAL;
+	}
+
  	guard(mutex)(&profile_lock);
 
  	/* create class interface for individual handler */
drivers/platform/surface/surface_platform_profile.c +11 -5
index 76967bfeeef8..48cfe9cb89c8 100644
@@ -201,7 +201,18 @@ static int ssam_platform_profile_set(struct device *dev,
  	return tp;
  }
 
+static int ssam_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
  static const struct platform_profile_ops ssam_platform_profile_ops = {
+	.probe = ssam_platform_profile_probe,
  	.profile_get = ssam_platform_profile_get,
  	.profile_set = ssam_platform_profile_set,
  };
@@ -223,11 +234,6 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
 
  	tpd->has_fan = device_property_read_bool(&sdev->dev, "has_fan");
 
-	set_bit(PLATFORM_PROFILE_LOW_POWER, tpd->handler.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, tpd->handler.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, tpd->handler.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, tpd->handler.choices);
-
  	return platform_profile_register(&tpd->handler, tpd);
  }
 
drivers/platform/x86/acer-wmi.c +46 -42
index 63e6bd1fe339..4d62a61cb241 100644
@@ -2019,7 +2019,53 @@ acer_predator_v4_platform_profile_set(struct device *dev,
  	return 0;
  }
 
+static int
+acer_predator_v4_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	unsigned long supported_profiles;
+	int err;
+
+	err = WMID_gaming_get_misc_setting(ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES,
+					   (u8 *)&supported_profiles);
+	if (err)
+		return err;
+
+	/* Iterate through supported profiles in order of increasing performance */
+	if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_ECO, &supported_profiles)) {
+		set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+		acer_predator_v4_max_perf =
+			ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
+	}
+
+	if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET, &supported_profiles)) {
+		set_bit(PLATFORM_PROFILE_QUIET, choices);
+		acer_predator_v4_max_perf =
+			ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
+	}
+
+	if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED, &supported_profiles)) {
+		set_bit(PLATFORM_PROFILE_BALANCED, choices);
+		acer_predator_v4_max_perf =
+			ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
+	}
+
+	if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE, &supported_profiles)) {
+		set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, choices);
+		acer_predator_v4_max_perf =
+			ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
+	}
+
+	if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO, &supported_profiles)) {
+		set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+		acer_predator_v4_max_perf =
+			ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
+	}
+
+	return 0;
+}
+
  static const struct platform_profile_ops acer_predator_v4_platform_profile_ops = {
+	.probe = acer_predator_v4_platform_profile_probe,
  	.profile_get = acer_predator_v4_platform_profile_get,
  	.profile_set = acer_predator_v4_platform_profile_set,
  };
@@ -2027,7 +2073,6 @@ static const struct platform_profile_ops acer_predator_v4_platform_profile_ops =
  static int acer_platform_profile_setup(struct platform_device *device)
  {
  	if (quirks->predator_v4) {
-		unsigned long supported_profiles;
  		int err;
 
  		platform_profile_handler.name = "acer-wmi";
@@ -2035,47 +2080,6 @@ static int acer_platform_profile_setup(struct platform_device *device)
  		platform_profile_handler.ops =
  			&acer_predator_v4_platform_profile_ops;
 
-		err = WMID_gaming_get_misc_setting(ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES,
-						   (u8 *)&supported_profiles);
-		if (err)
-			return err;
-
-		/* Iterate through supported profiles in order of increasing performance */
-		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_ECO, &supported_profiles)) {
-			set_bit(PLATFORM_PROFILE_LOW_POWER,
-				platform_profile_handler.choices);
-			acer_predator_v4_max_perf =
-				ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
-		}
-
-		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET, &supported_profiles)) {
-			set_bit(PLATFORM_PROFILE_QUIET,
-				platform_profile_handler.choices);
-			acer_predator_v4_max_perf =
-				ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
-		}
-
-		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED, &supported_profiles)) {
-			set_bit(PLATFORM_PROFILE_BALANCED,
-				platform_profile_handler.choices);
-			acer_predator_v4_max_perf =
-				ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
-		}
-
-		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE, &supported_profiles)) {
-			set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE,
-				platform_profile_handler.choices);
-			acer_predator_v4_max_perf =
-				ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
-		}
-
-		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO, &supported_profiles)) {
-			set_bit(PLATFORM_PROFILE_PERFORMANCE,
-				platform_profile_handler.choices);
-			acer_predator_v4_max_perf =
-				ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
-		}
-
  		err = platform_profile_register(&platform_profile_handler, NULL);
  		if (err)
  			return err;
drivers/platform/x86/amd/pmf/sps.c +10 -5
index 6ae82ae86d22..e710405b581f 100644
@@ -387,7 +387,17 @@ static int amd_pmf_profile_set(struct device *dev,
  	return 0;
  }
 
+static int amd_pmf_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
  static const struct platform_profile_ops amd_pmf_profile_ops = {
+	.probe = amd_pmf_profile_probe,
  	.profile_get = amd_pmf_profile_get,
  	.profile_set = amd_pmf_profile_set,
  };
@@ -414,11 +424,6 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
  	dev->pprof.dev = dev->dev;
  	dev->pprof.ops = &amd_pmf_profile_ops;
 
-	/* Setup supported modes */
-	set_bit(PLATFORM_PROFILE_LOW_POWER, dev->pprof.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, dev->pprof.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, dev->pprof.choices);
-
  	/* Create platform_profile structure and register */
  	err = platform_profile_register(&dev->pprof, dev);
  	if (err)
drivers/platform/x86/asus-wmi.c +10 -6
index 992956c89d38..e775ec7371ce 100644
@@ -3852,7 +3852,17 @@ static int asus_wmi_platform_profile_set(struct device *dev,
  	return throttle_thermal_policy_write(asus);
  }
 
+static int asus_wmi_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_QUIET, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
  static const struct platform_profile_ops asus_wmi_platform_profile_ops = {
+	.probe = asus_wmi_platform_profile_probe,
  	.profile_get = asus_wmi_platform_profile_get,
  	.profile_set = asus_wmi_platform_profile_set,
  };
@@ -3885,12 +3895,6 @@ static int platform_profile_setup(struct asus_wmi *asus)
  	asus->platform_profile_handler.dev = dev;
  	asus->platform_profile_handler.ops = &asus_wmi_platform_profile_ops;
 
-	set_bit(PLATFORM_PROFILE_QUIET, asus->platform_profile_handler.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED,
-		asus->platform_profile_handler.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE,
-		asus->platform_profile_handler.choices);
-
  	err = platform_profile_register(&asus->platform_profile_handler, asus);
  	if (err == -EEXIST) {
  		pr_warn("%s, a platform_profile handler is already registered\n", __func__);
drivers/platform/x86/dell/alienware-wmi.c +15 -9
index b8359b177a0f..e7209863e7dc 100644
@@ -1078,12 +1078,7 @@ static int thermal_profile_set(struct device *dev,
  	return wmax_thermal_control(supported_thermal_profiles[profile]);
  }
 
-static const struct platform_profile_ops awcc_platform_profile_ops = {
-	.profile_get = thermal_profile_get,
-	.profile_set = thermal_profile_set,
-};
-
-static int create_thermal_profile(struct platform_device *platform_device)
+static int thermal_profile_probe(void *drvdata, unsigned long *choices)
  {
  	enum platform_profile_option profile;
  	enum wmax_thermal_mode mode;
@@ -1116,19 +1111,30 @@ static int create_thermal_profile(struct platform_device *platform_device)
  		profile = wmax_mode_to_platform_profile[mode];
  		supported_thermal_profiles[profile] = out_data;
 
-		set_bit(profile, pp_handler.choices);
+		set_bit(profile, choices);
  	}
 
-	if (bitmap_empty(pp_handler.choices, PLATFORM_PROFILE_LAST))
+	if (bitmap_empty(choices, PLATFORM_PROFILE_LAST))
  		return -ENODEV;
 
  	if (quirks->gmode) {
  		supported_thermal_profiles[PLATFORM_PROFILE_PERFORMANCE] =
  			WMAX_THERMAL_MODE_GMODE;
 
-		set_bit(PLATFORM_PROFILE_PERFORMANCE, pp_handler.choices);
+		set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
  	}
 
+	return 0;
+}
+
+static const struct platform_profile_ops awcc_platform_profile_ops = {
+	.probe = thermal_profile_probe,
+	.profile_get = thermal_profile_get,
+	.profile_set = thermal_profile_set,
+};
+
+static int create_thermal_profile(struct platform_device *platform_device)
+{
  	pp_handler.name = "alienware-wmi";
  	pp_handler.dev = &platform_device->dev;
  	pp_handler.ops = &awcc_platform_profile_ops;
drivers/platform/x86/dell/dell-pc.c +16 -10
index 9010a231f209..32b3be0723f8 100644
@@ -24,6 +24,7 @@
  #include "dell-smbios.h"
 
  static struct platform_device *platform_device;
+static int supported_modes;
 
  static const struct dmi_system_id dell_device_table[] __initconst = {
  	{
@@ -231,7 +232,22 @@ static int thermal_platform_profile_get(struct device *dev,
  	return 0;
  }
 
+static int thermal_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	if (supported_modes & DELL_QUIET)
+		set_bit(PLATFORM_PROFILE_QUIET, choices);
+	if (supported_modes & DELL_COOL_BOTTOM)
+		set_bit(PLATFORM_PROFILE_COOL, choices);
+	if (supported_modes & DELL_BALANCED)
+		set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	if (supported_modes & DELL_PERFORMANCE)
+		set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
  static const struct platform_profile_ops dell_pc_platform_profile_ops = {
+	.probe = thermal_platform_profile_probe,
  	.profile_get = thermal_platform_profile_get,
  	.profile_set = thermal_platform_profile_set,
  };
@@ -239,7 +255,6 @@ static const struct platform_profile_ops dell_pc_platform_profile_ops = {
  static int thermal_init(void)
  {
  	int ret;
-	int supported_modes;
 
  	/* If thermal commands are not supported, exit without error */
  	if (!dell_smbios_class_is_supported(CLASS_INFO))
@@ -265,15 +280,6 @@ static int thermal_init(void)
  	thermal_handler->dev = &platform_device->dev;
  	thermal_handler->ops = &dell_pc_platform_profile_ops;
 
-	if (supported_modes & DELL_QUIET)
-		set_bit(PLATFORM_PROFILE_QUIET, thermal_handler->choices);
-	if (supported_modes & DELL_COOL_BOTTOM)
-		set_bit(PLATFORM_PROFILE_COOL, thermal_handler->choices);
-	if (supported_modes & DELL_BALANCED)
-		set_bit(PLATFORM_PROFILE_BALANCED, thermal_handler->choices);
-	if (supported_modes & DELL_PERFORMANCE)
-		set_bit(PLATFORM_PROFILE_PERFORMANCE, thermal_handler->choices);
-
  	/* Clean up if failed */
  	ret = platform_profile_register(thermal_handler, NULL);
  	if (ret)
drivers/platform/x86/hp/hp-wmi.c +20 -9
index 60328b35be74..75bcd8460e7c 100644
@@ -1488,6 +1488,23 @@ static int platform_profile_victus_set(struct device *dev,
  	return 0;
  }
 
+static int hp_wmi_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	if (is_omen_thermal_profile()) {
+		set_bit(PLATFORM_PROFILE_COOL, choices);
+	} else if (is_victus_thermal_profile()) {
+		set_bit(PLATFORM_PROFILE_QUIET, choices);
+	} else {
+		set_bit(PLATFORM_PROFILE_QUIET, choices);
+		set_bit(PLATFORM_PROFILE_COOL, choices);
+	}
+
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
  static int omen_powersource_event(struct notifier_block *nb,
  				  unsigned long value,
  				  void *data)
@@ -1566,16 +1583,19 @@ static inline void omen_unregister_powersource_event_handler(void)
  }
 
  static const struct platform_profile_ops platform_profile_omen_ops = {
+	.probe = hp_wmi_platform_profile_probe,
  	.profile_get = platform_profile_omen_get,
  	.profile_set = platform_profile_omen_set,
  };
 
  static const struct platform_profile_ops platform_profile_victus_ops = {
+	.probe = hp_wmi_platform_profile_probe,
  	.profile_get = platform_profile_victus_get,
  	.profile_set = platform_profile_victus_set,
  };
 
  static const struct platform_profile_ops hp_wmi_platform_profile_ops = {
+	.probe = hp_wmi_platform_profile_probe,
  	.profile_get = hp_wmi_platform_profile_get,
  	.profile_set = hp_wmi_platform_profile_set,
  };
@@ -1598,8 +1618,6 @@ static int thermal_profile_setup(struct platform_device *device)
  			return err;
 
  		platform_profile_handler.ops = &platform_profile_omen_ops;
-
-		set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
  	} else if (is_victus_thermal_profile()) {
  		err = platform_profile_victus_get_ec(&active_platform_profile);
  		if (err < 0)
@@ -1614,8 +1632,6 @@ static int thermal_profile_setup(struct platform_device *device)
  			return err;
 
  		platform_profile_handler.ops = &platform_profile_victus_ops;
-
-		set_bit(PLATFORM_PROFILE_QUIET, platform_profile_handler.choices);
  	} else {
  		tp = thermal_profile_get();
 
@@ -1631,15 +1647,10 @@ static int thermal_profile_setup(struct platform_device *device)
  			return err;
 
  		platform_profile_handler.ops = &hp_wmi_platform_profile_ops;
-
-		set_bit(PLATFORM_PROFILE_QUIET, platform_profile_handler.choices);
-		set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
  	}
 
  	platform_profile_handler.name = "hp-wmi";
  	platform_profile_handler.dev = &device->dev;
-	set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
 
  	err = platform_profile_register(&platform_profile_handler, NULL);
  	if (err)
drivers/platform/x86/ideapad-laptop.c +10 -5
index 96e99513b0b5..050919a28d2b 100644
@@ -1023,6 +1023,15 @@ static int dytc_profile_set(struct device *dev,
  	return -EINTR;
  }
 
+static int dytc_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
  static void dytc_profile_refresh(struct ideapad_private *priv)
  {
  	enum platform_profile_option profile;
@@ -1064,6 +1073,7 @@ static const struct dmi_system_id ideapad_dytc_v4_allow_table[] = {
  };
 
  static const struct platform_profile_ops dytc_profile_ops = {
+	.probe = dytc_profile_probe,
  	.profile_get = dytc_profile_get,
  	.profile_set = dytc_profile_set,
  };
@@ -1112,11 +1122,6 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
  	priv->dytc->priv = priv;
  	priv->dytc->pprof.ops = &dytc_profile_ops;
 
-	/* Setup supported modes */
-	set_bit(PLATFORM_PROFILE_LOW_POWER, priv->dytc->pprof.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, priv->dytc->pprof.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, priv->dytc->pprof.choices);
-
  	/* Create platform_profile structure and register */
  	err = platform_profile_register(&priv->dytc->pprof, &priv->dytc);
  	if (err)
drivers/platform/x86/inspur_platform_profile.c +10 -4
index d0a8e4eebffa..06df3aae9a56 100644
@@ -164,7 +164,17 @@ static int inspur_platform_profile_get(struct device *dev,
  	return 0;
  }
 
+static int inspur_platform_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
  static const struct platform_profile_ops inspur_platform_profile_ops = {
+	.probe = inspur_platform_profile_probe,
  	.profile_get = inspur_platform_profile_get,
  	.profile_set = inspur_platform_profile_set,
  };
@@ -184,10 +194,6 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
  	priv->handler.dev = &wdev->dev;
  	priv->handler.ops = &inspur_platform_profile_ops;
 
-	set_bit(PLATFORM_PROFILE_LOW_POWER, priv->handler.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, priv->handler.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, priv->handler.choices);
-
  	return platform_profile_register(&priv->handler, priv);
  }
 
drivers/platform/x86/thinkpad_acpi.c +10 -5
index 9e26f5670fc7..62b2ddfe7c0a 100644
@@ -10539,7 +10539,17 @@ static int dytc_profile_set(struct device *dev,
  	return err;
  }
 
+static int dytc_profile_probe(void *drvdata, unsigned long *choices)
+{
+	set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+
+	return 0;
+}
+
  static const struct platform_profile_ops dytc_profile_ops = {
+	.probe = dytc_profile_probe,
  	.profile_get = dytc_profile_get,
  	.profile_set = dytc_profile_set,
  };
@@ -10585,11 +10595,6 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
  {
  	int err, output;
 
-	/* Setup supported modes */
-	set_bit(PLATFORM_PROFILE_LOW_POWER, dytc_profile.choices);
-	set_bit(PLATFORM_PROFILE_BALANCED, dytc_profile.choices);
-	set_bit(PLATFORM_PROFILE_PERFORMANCE, dytc_profile.choices);
-
  	err = dytc_command(DYTC_CMD_QUERY, &output);
  	if (err)
  		return err;
include/linux/platform_profile.h +1 -0
index 6013c05d7b86..5ad1ab7b75e4 100644
@@ -31,6 +31,7 @@ enum platform_profile_option {
  struct platform_profile_handler;
 
  struct platform_profile_ops {
+	int (*probe)(void *drvdata, unsigned long *choices);
  	int (*profile_get)(struct device *dev, enum platform_profile_option *profile);
  	int (*profile_set)(struct device *dev, enum platform_profile_option profile);
  };
maintainer Reviewed-by on v4 6/19
#11 lore raw

Re: [PATCH v4 06/19] platform/surface: surface_platform_profile: Use devm_platform_profile_register()

In reply to Kurt Borja
Quoted 4 lines · Kurt Borja

Replace platform_profile_register() with it's device managed version.

Makes sense, thanks!

Quoted 33 lines
---
  drivers/platform/surface/surface_platform_profile.c | 11 +----------
  1 file changed, 1 insertion(+), 10 deletions(-)
drivers/platform/surface/surface_platform_profile.c +1 -10
index 48cfe9cb89c8..bbdc873cb788 100644
@@ -234,15 +234,7 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
 
  	tpd->has_fan = device_property_read_bool(&sdev->dev, "has_fan");
 
-	return platform_profile_register(&tpd->handler, tpd);
-}
-
-static void surface_platform_profile_remove(struct ssam_device *sdev)
-{
-	struct ssam_platform_profile_device *tpd;
-
-	tpd = ssam_device_get_drvdata(sdev);
-	platform_profile_remove(&tpd->handler);
+	return devm_platform_profile_register(&tpd->handler, tpd);
  }
 
  static const struct ssam_device_id ssam_platform_profile_match[] = {
@@ -253,7 +245,6 @@ MODULE_DEVICE_TABLE(ssam, ssam_platform_profile_match);
 
  static struct ssam_device_driver surface_platform_profile = {
  	.probe = surface_platform_profile_probe,
-	.remove = surface_platform_profile_remove,
  	.match_table = ssam_platform_profile_match,
  	.driver = {
  		.name = "surface_platform_profile",
maintainer Reviewed-by on v4 15/19
#21 lore raw

Re: [PATCH v4 15/19] ACPI: platform_profile: Remove platform_profile_handler from exported symbols

In reply to Kurt Borja
Quoted 8 lines · Kurt Borja

In order to protect the platform_profile_handler from API consumers, allocate it in platform_profile_register() and modify it's signature accordingly.

Remove the platform_profile_handler from all consumer drivers and replace them with a pointer to the class device, which is now returned from platform_profile_register().

Quoted 5 lines

Replace *pprof with a pointer to the class device in the rest of exported symbols.

Quoted 655 lines
---
  drivers/acpi/platform_profile.c               | 98 ++++++++++++-------
  .../surface/surface_platform_profile.c        | 11 +--
  drivers/platform/x86/acer-wmi.c               | 18 ++--
  drivers/platform/x86/amd/pmf/pmf.h            |  2 +-
  drivers/platform/x86/amd/pmf/sps.c            | 17 ++--
  drivers/platform/x86/asus-wmi.c               | 15 ++-
  drivers/platform/x86/dell/alienware-wmi.c     | 10 +-
  drivers/platform/x86/dell/dell-pc.c           | 22 ++---
  drivers/platform/x86/hp/hp-wmi.c              | 19 ++--
  drivers/platform/x86/ideapad-laptop.c         | 15 +--
  .../platform/x86/inspur_platform_profile.c    |  9 +-
  drivers/platform/x86/thinkpad_acpi.c          | 14 +--
  include/linux/platform_profile.h              | 12 ++-
  13 files changed, 130 insertions(+), 132 deletions(-)
drivers/acpi/platform_profile.c +61 -37
index 120f8402facd..a1dfa168f51f 100644
@@ -4,6 +4,7 @@
 
  #include <linux/acpi.h>
  #include <linux/bits.h>
+#include <linux/cleanup.h>
  #include <linux/init.h>
  #include <linux/mutex.h>
  #include <linux/platform_profile.h>
@@ -212,9 +213,17 @@ static struct attribute *profile_attrs[] = {
  };
  ATTRIBUTE_GROUPS(profile);
 
+static void pprof_device_release(struct device *dev)
+{
+	struct platform_profile_handler *pprof = to_pprof_handler(dev);
+
+	kfree(pprof);
+}
+
  static const struct class platform_profile_class = {
  	.name = "platform-profile",
  	.dev_groups = profile_groups,
+	.dev_release = pprof_device_release,
  };
 
  /**
@@ -408,10 +417,10 @@ static const struct attribute_group platform_profile_group = {
  	.is_visible = profile_class_is_visible,
  };
 
-void platform_profile_notify(struct platform_profile_handler *pprof)
+void platform_profile_notify(struct device *dev)
  {
  	scoped_cond_guard(mutex_intr, return, &profile_lock) {
-		_notify_class_profile(&pprof->class_dev, NULL);
+		_notify_class_profile(dev, NULL);
  	}
  	sysfs_notify(acpi_kobj, NULL, "platform_profile");
  }
@@ -460,42 +469,54 @@ int platform_profile_cycle(void)
  }
  EXPORT_SYMBOL_GPL(platform_profile_cycle);
 
-int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata)
+struct device *platform_profile_register(struct device *dev, const char *name,
+					 void *drvdata,
+					 const struct platform_profile_ops *ops)
  {
+	struct device *ppdev;
+	int minor;
  	int err;
 
-	/* Sanity check the profile handler */
-	if (!pprof || !pprof->ops->profile_set || !pprof->ops->profile_get ||
-	    !pprof->ops->probe) {
-		pr_err("platform_profile: handler is invalid\n");
-		return -EINVAL;
-	}
+	/* Sanity check */
+	if (WARN_ON_ONCE(!dev || !name || !ops || !ops->profile_get ||
+	    !ops->profile_set || !ops->probe))
+		return ERR_PTR(-EINVAL);
+
+	struct platform_profile_handler *pprof __free(kfree) = kzalloc(
+		sizeof(*pprof), GFP_KERNEL);
+	if (!pprof)
+		return ERR_PTR(-ENOMEM);
 
-	err = pprof->ops->probe(drvdata, pprof->choices);
+	err = ops->probe(drvdata, pprof->choices);
  	if (err) {
-		dev_err(pprof->dev, "platform_profile probe failed\n");
-		return err;
+		dev_err(dev, "platform_profile probe failed\n");
+		return ERR_PTR(err);
  	}
 
  	if (bitmap_empty(pprof->choices, PLATFORM_PROFILE_LAST)) {
-		dev_err(pprof->dev, "Failed to register a platform_profile class device with empty choices\n");
-		return -EINVAL;
+		dev_err(dev, "Failed to register platform_profile class device with empty choices\n");
+		return ERR_PTR(-EINVAL);
  	}
 
  	guard(mutex)(&profile_lock);
 
  	/* create class interface for individual handler */
-	pprof->minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
-	if (pprof->minor < 0)
-		return pprof->minor;
+	minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
+	if (minor < 0)
+		return ERR_PTR(minor);
 
+	pprof->name = name;
+	pprof->ops = ops;
+	pprof->minor = minor;
  	pprof->class_dev.class = &platform_profile_class;
-	pprof->class_dev.parent = pprof->dev;
+	pprof->class_dev.parent = dev;
  	dev_set_drvdata(&pprof->class_dev, drvdata);
  	dev_set_name(&pprof->class_dev, "platform-profile-%d", pprof->minor);
-	err = device_register(&pprof->class_dev);
+	/* device_register() takes ownership of ppdev */
+	ppdev = &no_free_ptr(pprof)->class_dev;
+	err = device_register(ppdev);
  	if (err) {
-		put_device(&pprof->class_dev);
+		put_device(ppdev);
  		goto cleanup_ida;
  	}
 
@@ -505,20 +526,21 @@ int platform_profile_register(struct platform_profile_handler *pprof, void *drvd
  	if (err)
  		goto cleanup_cur;
 
-	return 0;
+	return ppdev;
 
  cleanup_cur:
-	device_unregister(&pprof->class_dev);
+	device_unregister(ppdev);
 
  cleanup_ida:
-	ida_free(&platform_profile_ida, pprof->minor);
+	ida_free(&platform_profile_ida, minor);
 
-	return err;
+	return ERR_PTR(err);
  }
  EXPORT_SYMBOL_GPL(platform_profile_register);
 
-int platform_profile_remove(struct platform_profile_handler *pprof)
+int platform_profile_remove(struct device *dev)
  {
+	struct platform_profile_handler *pprof = to_pprof_handler(dev);
  	int id;
  	guard(mutex)(&profile_lock);
 
@@ -536,30 +558,32 @@ EXPORT_SYMBOL_GPL(platform_profile_remove);
 
  static void devm_platform_profile_release(struct device *dev, void *res)
  {
-	struct platform_profile_handler **pprof = res;
+	struct device **ppdev = res;
 
-	platform_profile_remove(*pprof);
+	platform_profile_remove(*ppdev);
  }
 
-int devm_platform_profile_register(struct platform_profile_handler *pprof, void *drvdata)
+struct device *devm_platform_profile_register(struct device *dev, const char *name,
+					      void *drvdata,
+					      const struct platform_profile_ops *ops)
  {
-	struct platform_profile_handler **dr;
-	int ret;
+	struct device *ppdev;
+	struct device **dr;
 
  	dr = devres_alloc(devm_platform_profile_release, sizeof(*dr), GFP_KERNEL);
  	if (!dr)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
-	ret = platform_profile_register(pprof, drvdata);
-	if (ret) {
+	ppdev = platform_profile_register(dev, name, drvdata, ops);
+	if (IS_ERR(ppdev)) {
  		devres_free(dr);
-		return ret;
+		return ppdev;
  	}
 
-	*dr = pprof;
-	devres_add(pprof->dev, dr);
+	*dr = ppdev;
+	devres_add(dev, dr);
 
-	return 0;
+	return ppdev;
  }
  EXPORT_SYMBOL_GPL(devm_platform_profile_register);
 
drivers/platform/surface/surface_platform_profile.c +5 -6
index bbdc873cb788..0e479e35e66e 100644
@@ -40,7 +40,7 @@ struct ssam_tmp_profile_info {
 
  struct ssam_platform_profile_device {
  	struct ssam_device *sdev;
-	struct platform_profile_handler handler;
+	struct device *ppdev;
  	bool has_fan;
  };
 
@@ -228,13 +228,12 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
  	tpd->sdev = sdev;
  	ssam_device_set_drvdata(sdev, tpd);
 
-	tpd->handler.name = "Surface Platform Profile";
-	tpd->handler.dev = &sdev->dev;
-	tpd->handler.ops = &ssam_platform_profile_ops;
-
  	tpd->has_fan = device_property_read_bool(&sdev->dev, "has_fan");
 
-	return devm_platform_profile_register(&tpd->handler, tpd);
+	tpd->ppdev = devm_platform_profile_register(&sdev->dev, "Surface Platform Profile",
+						    tpd, &ssam_platform_profile_ops);
+
+	return PTR_ERR_OR_ZERO(tpd->ppdev);
  }
 
  static const struct ssam_device_id ssam_platform_profile_match[] = {
drivers/platform/x86/acer-wmi.c +6 -12
index d201ca0e01d6..ae2a7c93ab72 100644
@@ -784,7 +784,7 @@ static const struct dmi_system_id non_acer_quirks[] __initconst = {
  	{}
  };
 
-static struct platform_profile_handler platform_profile_handler;
+static struct device *platform_profile_device;
  static bool platform_profile_support;
 
  /*
@@ -2073,16 +2073,10 @@ static const struct platform_profile_ops acer_predator_v4_platform_profile_ops =
  static int acer_platform_profile_setup(struct platform_device *device)
  {
  	if (quirks->predator_v4) {
-		int err;
-
-		platform_profile_handler.name = "acer-wmi";
-		platform_profile_handler.dev = &device->dev;
-		platform_profile_handler.ops =
-			&acer_predator_v4_platform_profile_ops;
-
-		err = devm_platform_profile_register(&platform_profile_handler, NULL);
-		if (err)
-			return err;
+		platform_profile_device = devm_platform_profile_register(
+			&device->dev, "acer-wmi", NULL, &acer_predator_v4_platform_profile_ops);
+		if (IS_ERR(platform_profile_device))
+			return PTR_ERR(platform_profile_device);
 
  		platform_profile_support = true;
 
@@ -2125,7 +2119,7 @@ static int acer_thermal_profile_change(void)
  			if (current_tp != acer_predator_v4_max_perf)
  				last_non_turbo_profile = current_tp;
 
-			platform_profile_notify(&platform_profile_handler);
+			platform_profile_notify(platform_profile_device);
  		}
  	}
 
drivers/platform/x86/amd/pmf/pmf.h +1 -1
index d99b3556205b..41b2b91b8fdc 100644
@@ -338,7 +338,7 @@ struct amd_pmf_dev {
  	struct mutex lock; /* protects the PMF interface */
  	u32 supported_func;
  	enum platform_profile_option current_profile;
-	struct platform_profile_handler pprof;
+	struct device *ppdev; /* platform profile class device */
  	struct dentry *dbgfs_dir;
  	int hb_interval; /* SBIOS heartbeat interval */
  	struct delayed_work heart_beat;
drivers/platform/x86/amd/pmf/sps.c +6 -11
index 7c7ed2b9de01..e6cf0b22dac3 100644
@@ -404,8 +404,6 @@ static const struct platform_profile_ops amd_pmf_profile_ops = {
 
  int amd_pmf_init_sps(struct amd_pmf_dev *dev)
  {
-	int err;
-
  	dev->current_profile = PLATFORM_PROFILE_BALANCED;
 
  	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) {
@@ -420,15 +418,12 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
  		amd_pmf_set_sps_power_limits(dev);
  	}
 
-	dev->pprof.name = "amd-pmf";
-	dev->pprof.dev = dev->dev;
-	dev->pprof.ops = &amd_pmf_profile_ops;
-
  	/* Create platform_profile structure and register */
-	err = devm_platform_profile_register(&dev->pprof, dev);
-	if (err)
-		dev_err(dev->dev, "Failed to register SPS support, this is most likely an SBIOS bug: %d\n",
-			err);
+	dev->ppdev = devm_platform_profile_register(dev->dev, "amd-pmf", dev,
+						    &amd_pmf_profile_ops);
+	if (IS_ERR(dev->ppdev))
+		dev_err(dev->dev, "Failed to register SPS support, this is most likely an SBIOS bug: %ld\n",
+			PTR_ERR(dev->ppdev));
 
-	return err;
+	return PTR_ERR_OR_ZERO(dev->ppdev);
  }
drivers/platform/x86/asus-wmi.c +6 -9
index dc713a5d8042..9a485f777591 100644
@@ -313,7 +313,7 @@ struct asus_wmi {
  	bool mid_fan_curve_available;
  	struct fan_curve_data custom_fan_curves[3];
 
-	struct platform_profile_handler platform_profile_handler;
+	struct device *ppdev;
  	bool platform_profile_support;
 
  	// The RSOC controls the maximum charging percentage.
@@ -3789,7 +3789,7 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
  	 * Ensure that platform_profile updates userspace with the change to ensure
  	 * that platform_profile and throttle_thermal_policy_mode are in sync.
  	 */
-	platform_profile_notify(&asus->platform_profile_handler);
+	platform_profile_notify(asus->ppdev);
 
  	return count;
  }
@@ -3891,14 +3891,11 @@ static int platform_profile_setup(struct asus_wmi *asus)
 
  	dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n");
 
-	asus->platform_profile_handler.name = "asus-wmi";
-	asus->platform_profile_handler.dev = dev;
-	asus->platform_profile_handler.ops = &asus_wmi_platform_profile_ops;
-
-	err = devm_platform_profile_register(&asus->platform_profile_handler, asus);
-	if (err) {
+	asus->ppdev = devm_platform_profile_register(dev, "asus-wmi", asus,
+						     &asus_wmi_platform_profile_ops);
+	if (IS_ERR(asus->ppdev)) {
  		dev_err(dev, "Failed to register a platform_profile class device");
-		return err;
+		return PTR_ERR(asus->ppdev);
  	}
 
  	asus->platform_profile_support = true;
drivers/platform/x86/dell/alienware-wmi.c +5 -5
index e7209863e7dc..63cf016bc912 100644
@@ -406,7 +406,6 @@ struct wmax_u32_args {
 
  static struct platform_device *platform_device;
  static struct color_platform colors[4];
-static struct platform_profile_handler pp_handler;
  static enum wmax_thermal_mode supported_thermal_profiles[PLATFORM_PROFILE_LAST];
 
  static u8 interface;
@@ -1135,11 +1134,12 @@ static const struct platform_profile_ops awcc_platform_profile_ops = {
 
  static int create_thermal_profile(struct platform_device *platform_device)
  {
-	pp_handler.name = "alienware-wmi";
-	pp_handler.dev = &platform_device->dev;
-	pp_handler.ops = &awcc_platform_profile_ops;
+	struct device *ppdev;
 
-	return devm_platform_profile_register(&pp_handler, NULL);
+	ppdev = devm_platform_profile_register(&platform_device->dev, "alienware-wmi",
+					       NULL, &awcc_platform_profile_ops);
+
+	return PTR_ERR_OR_ZERO(ppdev);
  }
 
  /*
drivers/platform/x86/dell/dell-pc.c +6 -16
index 2759bb608b1a..1874d4adfb8a 100644
@@ -109,8 +109,6 @@ MODULE_DEVICE_TABLE(dmi, dell_device_table);
  #define DELL_ACC_SET_FIELD	GENMASK(11, 8)
  #define DELL_THERMAL_SUPPORTED	GENMASK(3, 0)
 
-static struct platform_profile_handler *thermal_handler;
-
  enum thermal_mode_bits {
  	DELL_BALANCED    = BIT(0),
  	DELL_COOL_BOTTOM = BIT(1),
@@ -254,6 +252,7 @@ static const struct platform_profile_ops dell_pc_platform_profile_ops = {
 
  static int thermal_init(void)
  {
+	struct device *ppdev;
  	int ret;
 
  	/* If thermal commands are not supported, exit without error */
@@ -271,26 +270,17 @@ static int thermal_init(void)
  	if (IS_ERR(platform_device))
  		return PTR_ERR(platform_device);
 
-	thermal_handler = devm_kzalloc(&platform_device->dev, sizeof(*thermal_handler), GFP_KERNEL);
-	if (!thermal_handler) {
-		ret = -ENOMEM;
-		goto cleanup_platform_device;
-	}
-	thermal_handler->name = "dell-pc";
-	thermal_handler->dev = &platform_device->dev;
-	thermal_handler->ops = &dell_pc_platform_profile_ops;
-
  	/* Clean up if failed */
-	ret = devm_platform_profile_register(thermal_handler, NULL);
-	if (ret)
+	ppdev = devm_platform_profile_register(&platform_device->dev, "dell-pc",
+					       NULL, &dell_pc_platform_profile_ops);
+	if (IS_ERR(ppdev)) {
+		ret = PTR_ERR(ppdev);
  		goto cleanup_thermal_handler;
+	}
 
  	return 0;
 
  cleanup_thermal_handler:
-	thermal_handler = NULL;
-
-cleanup_platform_device:
  	platform_device_unregister(platform_device);
 
  	return ret;
drivers/platform/x86/hp/hp-wmi.c +9 -10
index 1304dfc65aab..435e3ef2e3e7 100644
@@ -273,7 +273,7 @@ static DEFINE_MUTEX(active_platform_profile_lock);
  static struct input_dev *hp_wmi_input_dev;
  static struct input_dev *camera_shutter_input_dev;
  static struct platform_device *hp_wmi_platform_dev;
-static struct platform_profile_handler platform_profile_handler;
+static struct device *platform_profile_device;
  static struct notifier_block platform_power_source_nb;
  static enum platform_profile_option active_platform_profile;
  static bool platform_profile_support;
@@ -1602,6 +1602,7 @@ static const struct platform_profile_ops hp_wmi_platform_profile_ops = {
 
  static int thermal_profile_setup(struct platform_device *device)
  {
+	const struct platform_profile_ops *ops;
  	int err, tp;
 
  	if (is_omen_thermal_profile()) {
@@ -1617,7 +1618,7 @@ static int thermal_profile_setup(struct platform_device *device)
  		if (err < 0)
  			return err;
 
-		platform_profile_handler.ops = &platform_profile_omen_ops;
+		ops = &platform_profile_omen_ops;
  	} else if (is_victus_thermal_profile()) {
  		err = platform_profile_victus_get_ec(&active_platform_profile);
  		if (err < 0)
@@ -1631,7 +1632,7 @@ static int thermal_profile_setup(struct platform_device *device)
  		if (err < 0)
  			return err;
 
-		platform_profile_handler.ops = &platform_profile_victus_ops;
+		ops = &platform_profile_victus_ops;
  	} else {
  		tp = thermal_profile_get();
 
@@ -1646,15 +1647,13 @@ static int thermal_profile_setup(struct platform_device *device)
  		if (err)
  			return err;
 
-		platform_profile_handler.ops = &hp_wmi_platform_profile_ops;
+		ops = &hp_wmi_platform_profile_ops;
  	}
 
-	platform_profile_handler.name = "hp-wmi";
-	platform_profile_handler.dev = &device->dev;
-
-	err = devm_platform_profile_register(&platform_profile_handler, NULL);
-	if (err)
-		return err;
+	platform_profile_device = devm_platform_profile_register(&device->dev, "hp-wmi",
+								 NULL, ops);
+	if (IS_ERR(platform_profile_device))
+		return PTR_ERR(platform_profile_device);
 
  	platform_profile_support = true;
 
drivers/platform/x86/ideapad-laptop.c +8 -7
index 87c1e087770a..dfb5d4b8c046 100644
@@ -142,7 +142,7 @@ enum {
 
  struct ideapad_dytc_priv {
  	enum platform_profile_option current_profile;
-	struct platform_profile_handler pprof;
+	struct device *ppdev; /* platform profile device */
  	struct mutex mutex; /* protects the DYTC interface */
  	struct ideapad_private *priv;
  };
@@ -1050,7 +1050,7 @@ static void dytc_profile_refresh(struct ideapad_private *priv)
 
  	if (profile != priv->dytc->current_profile) {
  		priv->dytc->current_profile = profile;
-		platform_profile_notify(&priv->dytc->pprof);
+		platform_profile_notify(priv->dytc->ppdev);
  	}
  }
 
@@ -1117,15 +1117,16 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
 
  	mutex_init(&priv->dytc->mutex);
 
-	priv->dytc->pprof.name = "ideapad-laptop";
-	priv->dytc->pprof.dev = &priv->platform_device->dev;
  	priv->dytc->priv = priv;
-	priv->dytc->pprof.ops = &dytc_profile_ops;
 
  	/* Create platform_profile structure and register */
-	err = devm_platform_profile_register(&priv->dytc->pprof, &priv->dytc);
-	if (err)
+	priv->dytc->ppdev = devm_platform_profile_register(&priv->platform_device->dev,
+							   "ideapad-laptop", &priv->dytc,
+							   &dytc_profile_ops);
+	if (IS_ERR(priv->dytc->ppdev)) {
+		err = PTR_ERR(priv->dytc->ppdev);
  		goto pp_reg_failed;
+	}
 
  	/* Ensure initial values are correct */
  	dytc_profile_refresh(priv);
drivers/platform/x86/inspur_platform_profile.c +4 -5
index e1631de6ad86..e02f5a55a6c5 100644
@@ -32,7 +32,7 @@ enum inspur_tmp_profile {
 
  struct inspur_wmi_priv {
  	struct wmi_device *wdev;
-	struct platform_profile_handler handler;
+	struct device *ppdev;
  };
 
  static int inspur_wmi_perform_query(struct wmi_device *wdev,
@@ -190,11 +190,10 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context)
  	priv->wdev = wdev;
  	dev_set_drvdata(&wdev->dev, priv);
 
-	priv->handler.name = "inspur-wmi";
-	priv->handler.dev = &wdev->dev;
-	priv->handler.ops = &inspur_platform_profile_ops;
+	priv->ppdev = devm_platform_profile_register(&wdev->dev, "inspur-wmi", priv,
+						     &inspur_platform_profile_ops);
 
-	return devm_platform_profile_register(&priv->handler, priv);
+	return PTR_ERR_OR_ZERO(priv->ppdev);
  }
 
  static const struct wmi_device_id inspur_wmi_id_table[] = {
drivers/platform/x86/thinkpad_acpi.c +5 -9
index c9226e8dc713..56c57cb45a76 100644
@@ -962,6 +962,7 @@ static const struct proc_ops dispatch_proc_ops = {
  static struct platform_device *tpacpi_pdev;
  static struct platform_device *tpacpi_sensors_pdev;
  static struct device *tpacpi_hwmon;
+static struct device *tpacpi_pprof;
  static struct input_dev *tpacpi_inputdev;
  static struct mutex tpacpi_inputdev_send_mutex;
  static LIST_HEAD(tpacpi_all_drivers);
@@ -10554,11 +10555,6 @@ static const struct platform_profile_ops dytc_profile_ops = {
  	.profile_set = dytc_profile_set,
  };
 
-static struct platform_profile_handler dytc_profile = {
-	.name = "thinkpad-acpi",
-	.ops = &dytc_profile_ops,
-};
-
  static void dytc_profile_refresh(void)
  {
  	enum platform_profile_option profile;
@@ -10587,7 +10583,7 @@ static void dytc_profile_refresh(void)
  	err = convert_dytc_to_profile(funcmode, perfmode, &profile);
  	if (!err && profile != dytc_current_profile) {
  		dytc_current_profile = profile;
-		platform_profile_notify(&dytc_profile);
+		platform_profile_notify(tpacpi_pprof);
  	}
  }
 
@@ -10648,14 +10644,14 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
  	dbg_printk(TPACPI_DBG_INIT,
  			"DYTC version %d: thermal mode available\n", dytc_version);
 
-	dytc_profile.dev = &tpacpi_pdev->dev;
  	/* Create platform_profile structure and register */
-	err = devm_platform_profile_register(&dytc_profile, NULL);
+	tpacpi_pprof = devm_platform_profile_register(&tpacpi_pdev->dev, "thinkpad-acpi",
+						      NULL, &dytc_profile_ops);
  	/*
  	 * If for some reason platform_profiles aren't enabled
  	 * don't quit terminally.
  	 */
-	if (err)
+	if (IS_ERR(tpacpi_pprof))
  		return -ENODEV;
 
  	/* Ensure initial values are correct */
include/linux/platform_profile.h +8 -4
index 5ad1ab7b75e4..778d4c661c3c 100644
@@ -45,10 +45,14 @@ struct platform_profile_handler {
  	const struct platform_profile_ops *ops;
  };
 
-int platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
-int platform_profile_remove(struct platform_profile_handler *pprof);
-int devm_platform_profile_register(struct platform_profile_handler *pprof, void *drvdata);
+struct device *platform_profile_register(struct device *dev, const char *name,
+					 void *drvdata,
+					 const struct platform_profile_ops *ops);
+int platform_profile_remove(struct device *dev);
+struct device *devm_platform_profile_register(struct device *dev, const char *name,
+					      void *drvdata,
+					      const struct platform_profile_ops *ops);
  int platform_profile_cycle(void);
-void platform_profile_notify(struct platform_profile_handler *pprof);
+void platform_profile_notify(struct device *dev);
 
  #endif  /*_PLATFORM_PROFILE_H_*/
maintainer
#36 lore raw
In reply to Mark Pearson
Quoted 104 lines · Mark Pearson
Quoted 101 lines · Mark Pearson

Hi,

Quoted 84 lines · Ilpo Järvinen
Quoted 82 lines · Kurt Borja
Quoted 71 lines · Ilpo Järvinen
Quoted 69 lines · Mark Pearson

Hi

Quoted 59 lines · Kurt Borja

Hi :)

The merge window is about to open, so I rebased this patchset on top of pdx86/review-ilpo-next to pick up acer-wmi latest commits, in case we manage to squeeze this into v6.14.

~ Kurt
---
v3 -> v4:

[09/19]
- Replace error message with a user-friendly one

v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/

Kurt Borja (19):
ACPI: platform_profile: Replace *class_dev member with class_dev
ACPI: platform_profile: Let drivers set drvdata to the class device
ACPI: platform_profile: Remove platform_profile_handler from callbacks
ACPI: platform_profile: Add ops member to handlers
ACPI: platform_profile: Add probe to platform_profile_ops platform/surface: surface_platform_profile: Use
devm_platform_profile_register()
platform/x86: acer-wmi: Use devm_platform_profile_register() platform/x86: amd: pmf: sps: Use devm_platform_profile_register() platform/x86: asus-wmi: Use devm_platform_profile_register() platform/x86: dell-pc: Use devm_platform_profile_register() platform/x86: ideapad-laptop: Use devm_platform_profile_register() platform/x86: hp-wmi: Use devm_platform_profile_register() platform/x86: inspur_platform_profile: Use
devm_platform_profile_register()
platform/x86: thinkpad_acpi: Use devm_platform_profile_register()
ACPI: platform_profile: Remove platform_profile_handler from exported
symbols
ACPI: platform_profile: Move platform_profile_handler
ACPI: platform_profile: Clean platform_profile_handler
ACPI: platform_profile: Add documentation
ACPI: platform_profile: Add a prefix to log messages

 .../ABI/testing/sysfs-class-platform-profile  |  44 +++++
 drivers/acpi/platform_profile.c               | 172 +++++++++++++-----
 .../surface/surface_platform_profile.c        |  48 ++---
 drivers/platform/x86/acer-wmi.c               | 114 ++++++------
 drivers/platform/x86/amd/pmf/core.c           |   1 -
 drivers/platform/x86/amd/pmf/pmf.h            |   3 +-
 drivers/platform/x86/amd/pmf/sps.c            |  51 +++---
 drivers/platform/x86/asus-wmi.c               |  55 +++---
 drivers/platform/x86/dell/alienware-wmi.c     |  34 ++--
 drivers/platform/x86/dell/dell-pc.c           |  60 +++---
 drivers/platform/x86/hp/hp-wmi.c              |  83 +++++----
 drivers/platform/x86/ideapad-laptop.c         |  45 +++--
 .../platform/x86/inspur_platform_profile.c    |  48 +++--
 drivers/platform/x86/thinkpad_acpi.c          |  37 ++--
 include/linux/platform_profile.h              |  37 ++--
 15 files changed, 495 insertions(+), 337 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-platform-profile
Quoted 3 lines

base-commit: d98bf6a6ed61a8047e199495b0887cce392f8e5b

Signature · 1 line
2.48.1

For the series up to v4 commit 15/19:

Quoted 7 lines
Quoted 3 lines

I need to go over the last few commits just once more, as there a few pieces I need to get my head around - and I'm not going to get it done this evening. Hope it's OK to add review for the bits that I have done.

I, for the first time ever, tested filter-branch and after some initial hickups on how to specify the commit range, got your Reviewed-bys added with single command :-).

Awesome! I believe commit 15/19

Quoted 10 lines
Quoted 3 lines

a213108c01e0 ("ACPI: platform_profile: Remove platform_profile_handler from exported symbols")

is still missing a rev-by by Mark, if there is still time.

Thanks for noticing this. I just recalled the patch numbering wrong.

It should be fixed now.

Signature · 1 line
 i.

I finished my review, and no concerns. For the series:

Quoted 8 lines
Quoted 5 lines

Note - I'm building and will give it a sniff test too, but that will take a bit longer.

Thanks for your work on this Kurt

Ran the series on an X1 Carbon G12 and profiles working well. Was able to check the new class and didn't find any issues. For the series:

Thanks a lot for testing this! I've added you tags into the entire series now.

Signature · 1 line
 i.