[PATCH 1/7] hwmon: (g762) Simplify clock initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
---
 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





[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux