linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: W_Armin@gmx.de
To: pali@kernel.org
Cc: linux@roeck-us.net, jdelvare@suse.com, linux-hwmon@vger.kernel.org
Subject: [RFC 1/3] hwmon: (dell-smm-hwmon) Use platform device
Date: Sat, 15 May 2021 20:34:07 +0200	[thread overview]
Message-ID: <20210515183409.682-2-W_Armin@gmx.de> (raw)
In-Reply-To: <20210515183409.682-1-W_Armin@gmx.de>

From: Armin Wolf <W_Armin@gmx.de>

Register a platform device for usage with
devm_hwmon_device_register_with_groups.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/hwmon/dell-smm-hwmon.c | 70 ++++++++++++++++++++--------------
 1 file changed, 41 insertions(+), 29 deletions(-)

diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c
index f2221ca0aa7b..006d435a6e78 100644
--- a/drivers/hwmon/dell-smm-hwmon.c
+++ b/drivers/hwmon/dell-smm-hwmon.c
@@ -14,7 +14,9 @@

 #include <linux/cpu.h>
 #include <linux/delay.h>
+#include <linux/err.h>
 #include <linux/module.h>
+#include <linux/platform_device.h>
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/proc_fs.h>
@@ -896,7 +898,7 @@ static const struct attribute_group i8k_group = {
 };
 __ATTRIBUTE_GROUPS(i8k);

-static int __init i8k_init_hwmon(void)
+static int __init dell_smm_init_hwmon(struct device *dev)
 {
 	int err;

@@ -956,15 +958,9 @@ static int __init i8k_init_hwmon(void)
 	if (err >= 0)
 		i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3;

-	i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm",
-							  NULL, i8k_groups);
-	if (IS_ERR(i8k_hwmon_dev)) {
-		err = PTR_ERR(i8k_hwmon_dev);
-		i8k_hwmon_dev = NULL;
-		pr_err("hwmon registration failed (%d)\n", err);
-		return err;
-	}
-	return 0;
+	i8k_hwmon_dev = devm_hwmon_device_register_with_groups(dev, "dell_smm", NULL, i8k_groups);
+
+	return PTR_ERR_OR_ZERO(i8k_hwmon_dev);
 }

 struct i8k_config_data {
@@ -1221,10 +1217,39 @@ static struct dmi_system_id i8k_whitelist_fan_control[] __initdata = {
 	{ }
 };

+static int __init dell_smm_probe(struct platform_device *pdev)
+{
+	int err;
+
+	err = dell_smm_init_hwmon(&pdev->dev);
+	if (err)
+		return err;
+
+	i8k_init_procfs();
+
+	return 0;
+}
+
+static int dell_smm_remove(struct platform_device *pdev)
+{
+	i8k_exit_procfs();
+
+	return 0;
+}
+
+static struct platform_driver dell_smm_driver = {
+	.driver		= {
+		.name	= KBUILD_MODNAME,
+	},
+	.remove		= dell_smm_remove,
+};
+
+static struct platform_device *dell_smm_device;
+
 /*
  * Probe for the presence of a supported laptop.
  */
-static int __init i8k_probe(void)
+static int __init i8k_init(void)
 {
 	const struct dmi_system_id *id, *fan_control;
 	int fan, ret;
@@ -1313,29 +1338,16 @@ static int __init i8k_probe(void)
 		i8k_fan_mult = fan_mult;
 	}

-	return 0;
-}
-
-static int __init i8k_init(void)
-{
-	int err;
-
-	/* Are we running on an supported laptop? */
-	if (i8k_probe())
-		return -ENODEV;
-
-	err = i8k_init_hwmon();
-	if (err)
-		return err;
+	dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL,
+						 0);

-	i8k_init_procfs();
-	return 0;
+	return PTR_ERR_OR_ZERO(dell_smm_device);
 }

 static void __exit i8k_exit(void)
 {
-	hwmon_device_unregister(i8k_hwmon_dev);
-	i8k_exit_procfs();
+	platform_device_unregister(dell_smm_device);
+	platform_driver_unregister(&dell_smm_driver);
 }

 module_init(i8k_init);
--
2.20.1


  reply	other threads:[~2021-05-15 18:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-15 18:34 [RFC 0/3] hwmon: (dell-smm-hwmon) Use platform device W_Armin
2021-05-15 18:34 ` W_Armin [this message]
2021-05-15 18:34 ` [RFC 2/3] hwmon: (dell-smm-hwmon) Use devm_add_action_or_reset() W_Armin
2021-05-15 18:34 ` [RFC 3/3] hwmon: (dell-smm-hwmon) Move variables into a driver private data structure W_Armin
2021-05-16 14:08 ` [RFC 0/3] hwmon: (dell-smm-hwmon) Use platform device Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210515183409.682-2-W_Armin@gmx.de \
    --to=w_armin@gmx.de \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=pali@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).