i2c: mpc: Use devm_clk_get_optional_enabled() to simplify code
authorZhang Zekun <zhangzekun11@huawei.com>
Wed, 4 Sep 2024 12:22:26 +0000 (20:22 +0800)
committerAndi Shyti <andi.shyti@kernel.org>
Mon, 9 Sep 2024 22:36:45 +0000 (00:36 +0200)
devm_clk_get_optional() and clk_prepare_enable() can be replaced by the
helper function devm_clk_get_optional_enabled(). Let's simplify the code by
using devm_clk_get_optional_enabled() and avoid calling
clk_disable_unprepare().

Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
drivers/i2c/busses/i2c-mpc.c

index 41d6c8ed163a26ddf04b56d61d58b682acfa46cb..236d6b8ba867578aa9421523b5ae59f5d175bdf6 100644 (file)
@@ -88,7 +88,6 @@ struct mpc_i2c {
        int irq;
        u32 real_clk;
        u8 fdr, dfsrr;
-       struct clk *clk_per;
        u32 cntl_bits;
        enum mpc_i2c_action action;
        struct i2c_msg *msgs;
@@ -779,7 +778,6 @@ static int fsl_i2c_probe(struct platform_device *op)
        struct clk *clk;
        int result;
        u32 clock;
-       int err;
 
        i2c = devm_kzalloc(&op->dev, sizeof(*i2c), GFP_KERNEL);
        if (!i2c)
@@ -809,18 +807,12 @@ static int fsl_i2c_probe(struct platform_device *op)
         * enable clock for the I2C peripheral (non fatal),
         * keep a reference upon successful allocation
         */
-       clk = devm_clk_get_optional(&op->dev, NULL);
-       if (IS_ERR(clk))
-               return PTR_ERR(clk);
-
-       err = clk_prepare_enable(clk);
-       if (err) {
+       clk = devm_clk_get_optional_enabled(&op->dev, NULL);
+       if (IS_ERR(clk)) {
                dev_err(&op->dev, "failed to enable clock\n");
-               return err;
+               return PTR_ERR(clk);
        }
 
-       i2c->clk_per = clk;
-
        if (of_property_read_bool(op->dev.of_node, "fsl,preserve-clocking")) {
                clock = MPC_I2C_CLOCK_PRESERVE;
        } else {
@@ -876,14 +868,9 @@ static int fsl_i2c_probe(struct platform_device *op)
 
        result = i2c_add_numbered_adapter(&i2c->adap);
        if (result)
-               goto fail_add;
+               return result;
 
        return 0;
-
- fail_add:
-       clk_disable_unprepare(i2c->clk_per);
-
-       return result;
 };
 
 static void fsl_i2c_remove(struct platform_device *op)
@@ -891,8 +878,6 @@ static void fsl_i2c_remove(struct platform_device *op)
        struct mpc_i2c *i2c = platform_get_drvdata(op);
 
        i2c_del_adapter(&i2c->adap);
-
-       clk_disable_unprepare(i2c->clk_per);
 };
 
 static int __maybe_unused mpc_i2c_suspend(struct device *dev)