Commit 016b2212 authored by Zhang Zekun's avatar Zhang Zekun Committed by Andi Shyti

i2c: mpc: Use devm_clk_get_optional_enabled() to simplify code

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: default avatarZhang Zekun <zhangzekun11@huawei.com>
Reviewed-by: default avatarChris Packham <chris.packham@alliedtelesis.co.nz>
Signed-off-by: default avatarAndi Shyti <andi.shyti@kernel.org>
parent 2259ce0d
...@@ -88,7 +88,6 @@ struct mpc_i2c { ...@@ -88,7 +88,6 @@ struct mpc_i2c {
int irq; int irq;
u32 real_clk; u32 real_clk;
u8 fdr, dfsrr; u8 fdr, dfsrr;
struct clk *clk_per;
u32 cntl_bits; u32 cntl_bits;
enum mpc_i2c_action action; enum mpc_i2c_action action;
struct i2c_msg *msgs; struct i2c_msg *msgs;
...@@ -779,7 +778,6 @@ static int fsl_i2c_probe(struct platform_device *op) ...@@ -779,7 +778,6 @@ static int fsl_i2c_probe(struct platform_device *op)
struct clk *clk; struct clk *clk;
int result; int result;
u32 clock; u32 clock;
int err;
i2c = devm_kzalloc(&op->dev, sizeof(*i2c), GFP_KERNEL); i2c = devm_kzalloc(&op->dev, sizeof(*i2c), GFP_KERNEL);
if (!i2c) if (!i2c)
...@@ -809,18 +807,12 @@ static int fsl_i2c_probe(struct platform_device *op) ...@@ -809,18 +807,12 @@ static int fsl_i2c_probe(struct platform_device *op)
* enable clock for the I2C peripheral (non fatal), * enable clock for the I2C peripheral (non fatal),
* keep a reference upon successful allocation * keep a reference upon successful allocation
*/ */
clk = devm_clk_get_optional(&op->dev, NULL); clk = devm_clk_get_optional_enabled(&op->dev, NULL);
if (IS_ERR(clk)) if (IS_ERR(clk)) {
return PTR_ERR(clk);
err = clk_prepare_enable(clk);
if (err) {
dev_err(&op->dev, "failed to enable clock\n"); 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")) { if (of_property_read_bool(op->dev.of_node, "fsl,preserve-clocking")) {
clock = MPC_I2C_CLOCK_PRESERVE; clock = MPC_I2C_CLOCK_PRESERVE;
} else { } else {
...@@ -876,14 +868,9 @@ static int fsl_i2c_probe(struct platform_device *op) ...@@ -876,14 +868,9 @@ static int fsl_i2c_probe(struct platform_device *op)
result = i2c_add_numbered_adapter(&i2c->adap); result = i2c_add_numbered_adapter(&i2c->adap);
if (result) if (result)
goto fail_add; return result;
return 0; return 0;
fail_add:
clk_disable_unprepare(i2c->clk_per);
return result;
}; };
static void fsl_i2c_remove(struct platform_device *op) static void fsl_i2c_remove(struct platform_device *op)
...@@ -891,8 +878,6 @@ 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); struct mpc_i2c *i2c = platform_get_drvdata(op);
i2c_del_adapter(&i2c->adap); i2c_del_adapter(&i2c->adap);
clk_disable_unprepare(i2c->clk_per);
}; };
static int __maybe_unused mpc_i2c_suspend(struct device *dev) static int __maybe_unused mpc_i2c_suspend(struct device *dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment