Skip to content

Commit 016b221

Browse files
Zhang ZekunAndi Shyti
authored andcommitted
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: Zhang Zekun <[email protected]> Reviewed-by: Chris Packham <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent 2259ce0 commit 016b221

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

drivers/i2c/busses/i2c-mpc.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ struct mpc_i2c {
8888
int irq;
8989
u32 real_clk;
9090
u8 fdr, dfsrr;
91-
struct clk *clk_per;
9291
u32 cntl_bits;
9392
enum mpc_i2c_action action;
9493
struct i2c_msg *msgs;
@@ -779,7 +778,6 @@ static int fsl_i2c_probe(struct platform_device *op)
779778
struct clk *clk;
780779
int result;
781780
u32 clock;
782-
int err;
783781

784782
i2c = devm_kzalloc(&op->dev, sizeof(*i2c), GFP_KERNEL);
785783
if (!i2c)
@@ -809,18 +807,12 @@ static int fsl_i2c_probe(struct platform_device *op)
809807
* enable clock for the I2C peripheral (non fatal),
810808
* keep a reference upon successful allocation
811809
*/
812-
clk = devm_clk_get_optional(&op->dev, NULL);
813-
if (IS_ERR(clk))
814-
return PTR_ERR(clk);
815-
816-
err = clk_prepare_enable(clk);
817-
if (err) {
810+
clk = devm_clk_get_optional_enabled(&op->dev, NULL);
811+
if (IS_ERR(clk)) {
818812
dev_err(&op->dev, "failed to enable clock\n");
819-
return err;
813+
return PTR_ERR(clk);
820814
}
821815

822-
i2c->clk_per = clk;
823-
824816
if (of_property_read_bool(op->dev.of_node, "fsl,preserve-clocking")) {
825817
clock = MPC_I2C_CLOCK_PRESERVE;
826818
} else {
@@ -876,23 +868,16 @@ static int fsl_i2c_probe(struct platform_device *op)
876868

877869
result = i2c_add_numbered_adapter(&i2c->adap);
878870
if (result)
879-
goto fail_add;
871+
return result;
880872

881873
return 0;
882-
883-
fail_add:
884-
clk_disable_unprepare(i2c->clk_per);
885-
886-
return result;
887874
};
888875

889876
static void fsl_i2c_remove(struct platform_device *op)
890877
{
891878
struct mpc_i2c *i2c = platform_get_drvdata(op);
892879

893880
i2c_del_adapter(&i2c->adap);
894-
895-
clk_disable_unprepare(i2c->clk_per);
896881
};
897882

898883
static int __maybe_unused mpc_i2c_suspend(struct device *dev)

0 commit comments

Comments
 (0)