Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 1/7] hwmon: (g762) Simplify clock initialization
Date: Thu,  4 Jul 2024 14:37:06 -0700	[thread overview]
Message-ID: <20240704213712.2699553-2-linux@roeck-us.net> (raw)
In-Reply-To: <20240704213712.2699553-1-linux@roeck-us.net>

Use a device managed function to prepare and enable the clock.
To match the current code, only let it fails if a device node
is present (i.e., when it is mandatory). Otherwise set the default
clock speed.

No functional change intended, even though the code now does set
the default frequency if there is neither a devicetree node nor
platform data.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/g762.c | 66 +++++++++-----------------------------------
 1 file changed, 13 insertions(+), 53 deletions(-)

diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c
index af1228708e25..da43a26f558d 100644
--- a/drivers/hwmon/g762.c
+++ b/drivers/hwmon/g762.c
@@ -115,7 +115,6 @@ enum g762_regs {
 
 struct g762_data {
 	struct i2c_client *client;
-	struct clk *clk;
 
 	/* update mutex */
 	struct mutex update_lock;
@@ -574,66 +573,27 @@ MODULE_DEVICE_TABLE(of, g762_dt_match);
 
 /*
  * Grab clock (a required property), enable it, get (fixed) clock frequency
- * and store it. Note: upon success, clock has been prepared and enabled; it
- * must later be unprepared and disabled (e.g. during module unloading) by a
- * call to g762_of_clock_disable(). Note that a reference to clock is kept
- * in our private data structure to be used in this function.
+ * and store it.
  */
-static void g762_of_clock_disable(void *data)
+static int g762_of_clock_enable(struct device *dev)
 {
-	struct g762_data *g762 = data;
-
-	clk_disable_unprepare(g762->clk);
-	clk_put(g762->clk);
-}
-
-static int g762_of_clock_enable(struct i2c_client *client)
-{
-	struct g762_data *data;
-	unsigned long clk_freq;
+	unsigned long clk_freq = 0;
 	struct clk *clk;
 	int ret;
 
-	if (!client->dev.of_node)
-		return 0;
-
-	clk = of_clk_get(client->dev.of_node, 0);
+	clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(clk)) {
-		dev_err(&client->dev, "failed to get clock\n");
-		return PTR_ERR(clk);
+		if (dev->of_node)
+			return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
+	} else {
+		clk_freq = clk_get_rate(clk);
 	}
 
-	ret = clk_prepare_enable(clk);
-	if (ret) {
-		dev_err(&client->dev, "failed to enable clock\n");
-		goto clk_put;
-	}
-
-	clk_freq = clk_get_rate(clk);
-	ret = do_set_clk_freq(&client->dev, clk_freq);
-	if (ret) {
-		dev_err(&client->dev, "invalid clock freq %lu\n", clk_freq);
-		goto clk_unprep;
-	}
-
-	data = i2c_get_clientdata(client);
-	data->clk = clk;
-
-	ret = devm_add_action(&client->dev, g762_of_clock_disable, data);
-	if (ret) {
-		dev_err(&client->dev, "failed to add disable clock action\n");
-		goto clk_unprep;
-	}
+	ret = do_set_clk_freq(dev, clk_freq);
+	if (ret)
+		return dev_err_probe(dev, ret, "invalid clock freq %lu\n", clk_freq);
 
 	return 0;
-
- clk_unprep:
-	clk_disable_unprepare(clk);
-
- clk_put:
-	clk_put(clk);
-
-	return ret;
 }
 
 static int g762_of_prop_import_one(struct i2c_client *client,
@@ -682,7 +642,7 @@ static int g762_of_prop_import(struct i2c_client *client)
 	return 0;
 }
 
-static int g762_of_clock_enable(struct i2c_client *client)
+static int g762_of_clock_enable(struct device *dev)
 {
 	return 0;
 }
@@ -1062,7 +1022,7 @@ static int g762_probe(struct i2c_client *client)
 		return ret;
 
 	/* Get configuration via DT ... */
-	ret = g762_of_clock_enable(client);
+	ret = g762_of_clock_enable(dev);
 	if (ret)
 		return ret;
 	ret = g762_of_prop_import(client);
-- 
2.39.2


  reply	other threads:[~2024-07-04 21:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-04 21:37 [PATCH 0/7] hwmon: (g762) Convert to with_info API Guenter Roeck
2024-07-04 21:37 ` Guenter Roeck [this message]
2024-07-04 21:37 ` [PATCH 2/7] hwmon: (g762) Drop platform data support Guenter Roeck
2024-07-04 21:37 ` [PATCH 3/7] hwmon: (g762) Reorder include files to be in alphabetic order Guenter Roeck
2024-07-04 21:37 ` [PATCH 4/7] hwmon: (g762) Use bit operations Guenter Roeck
2024-07-04 21:37 ` [PATCH 5/7] hwmon: (g762) Make chip configuration devicetree independent Guenter Roeck
2024-07-04 21:37 ` [PATCH 6/7] hwmon: (g762) Convert to use regmap Guenter Roeck
2024-07-04 21:37 ` [PATCH 7/7] hwmon: (g762) Convert to with_info API 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=20240704213712.2699553-2-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-hwmon@vger.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