* [PATCH] i2c: mpc: Use devm_clk_get() to simplify code
@ 2024-09-04 7:04 Zhang Zekun
2024-09-04 8:31 ` zhangzekun (A)
0 siblings, 1 reply; 2+ messages in thread
From: Zhang Zekun @ 2024-09-04 7:04 UTC (permalink / raw)
To: chris.packham, andi.shyti, linux-i2c; +Cc: zhangzekun11
devm_clk_get() and clk_prepare_enable() can be replaced by helper
function devm_clk_get_enabled(). Let's use devm_clk_get_enabled() to
simplify code and avoid calling clk_disable_unprepare().
Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
---
drivers/i2c/busses/i2c-mpc.c | 23 ++++-------------------
1 file changed, 4 insertions(+), 19 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 41d6c8ed163a..236d6b8ba867 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -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)
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] i2c: mpc: Use devm_clk_get() to simplify code
2024-09-04 7:04 [PATCH] i2c: mpc: Use devm_clk_get() to simplify code Zhang Zekun
@ 2024-09-04 8:31 ` zhangzekun (A)
0 siblings, 0 replies; 2+ messages in thread
From: zhangzekun (A) @ 2024-09-04 8:31 UTC (permalink / raw)
To: chris.packham, andi.shyti, linux-i2c
Sorry for make noise. Please ignore this patch, there are some mistakes
in the commit message. I will send v2 to fix it.
Best Regards,
Zekun
在 2024/9/4 15:04, Zhang Zekun 写道:
> devm_clk_get() and clk_prepare_enable() can be replaced by helper
> function devm_clk_get_enabled(). Let's use devm_clk_get_enabled() to
> simplify code and avoid calling clk_disable_unprepare().
>
> Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
> ---
> drivers/i2c/busses/i2c-mpc.c | 23 ++++-------------------
> 1 file changed, 4 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
> index 41d6c8ed163a..236d6b8ba867 100644
> --- a/drivers/i2c/busses/i2c-mpc.c
> +++ b/drivers/i2c/busses/i2c-mpc.c
> @@ -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)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-04 8:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-04 7:04 [PATCH] i2c: mpc: Use devm_clk_get() to simplify code Zhang Zekun
2024-09-04 8:31 ` zhangzekun (A)
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).