]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ACPI: platform_profile: Add `ops` member to handlers
authorKurt Borja <kuurtb@gmail.com>
Thu, 16 Jan 2025 00:27:06 +0000 (19:27 -0500)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Thu, 16 Jan 2025 15:26:28 +0000 (17:26 +0200)
Replace *profile_get and *profile_set members with a general *ops
member.

Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Link: https://lore.kernel.org/r/20250116002721.75592-5-kuurtb@gmail.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
12 files changed:
drivers/acpi/platform_profile.c
drivers/platform/surface/surface_platform_profile.c
drivers/platform/x86/acer-wmi.c
drivers/platform/x86/amd/pmf/sps.c
drivers/platform/x86/asus-wmi.c
drivers/platform/x86/dell/alienware-wmi.c
drivers/platform/x86/dell/dell-pc.c
drivers/platform/x86/hp/hp-wmi.c
drivers/platform/x86/ideapad-laptop.c
drivers/platform/x86/inspur_platform_profile.c
drivers/platform/x86/thinkpad_acpi.c
include/linux/platform_profile.h

index bd90aa4e8371276bc7a3cc7eb8d470a9cd67e52f..161a05d57b0f894fdbeeac1a79436826e817ff96 100644 (file)
@@ -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;
        }
index 26c1230e75dfabb1eb6ed17bc78e4aa1a4db7aed..76967bfeeef8643fcbecd201c2de51d3c4ed960f 100644 (file)
@@ -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");
 
index c68c0d744a69ab9206dede0a5d1d25733f8fa22d..63e6bd1fe339ce893ea6099d71688cf74206bdb2 100644 (file)
@@ -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);
index cf2e51f67787ac9902e57a1ef2640ff747ec8086..6ae82ae86d22cb3a61cac3db0fab06ab81669f79 100644 (file)
@@ -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);
index 6b8b30551d36aa888f6f8faf74664f7b466b5690..992956c89d3804191e19a8f23ba2f69dd94a1fd5 100644 (file)
@@ -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,
index 0346f8e88bf81ceb0bc3f08c9b535db6adedb9a6..b8359b177a0f65b075bf0a4164d9a86011d83ca5 100644 (file)
@@ -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);
 }
index c86b05b5a1cb3e69dc961c4d54883e759d909670..9010a231f209bffbbf38ebd12d076f4f7fa52a5d 100644 (file)
@@ -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);
index b8e62dc9cecdd6a1da84fa6d1534d7849662a77f..60328b35be743302b542cc1a311455d81609d30c 100644 (file)
@@ -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);
index fc317f42bb82bca7faeae8f4f19bb839d375d8b4..96e99513b0b592d6a0a877f00e465d826270b67d 100644 (file)
@@ -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);
index 47d2dbbf3392fe90131995766437379ccd6ab1d0..d0a8e4eebffa41092891e1df38b086146b09b4f1 100644 (file)
@@ -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);
index 0abe22228fdbce7382ee459ce5389fa4531ebfbd..9e26f5670fc78548563d34cb8cf14c5fa6e26ac1 100644 (file)
@@ -10539,12 +10539,16 @@ unlock:
        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;
index 5296d886c243c3b40241fbd03195334e476350f9..6013c05d7b863168a66c14d8bc204ae6b4c1753c 100644 (file)
@@ -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);