Commit b3bfce2b authored by Gerhard Sittig's avatar Gerhard Sittig Committed by Wolfram Sang

i2c: mpc: cleanup clock API use

make the MPC I2C driver get, prepare and enable the gated clock item for
register access during probe; disable and unprepare the clock upon
remove(), put is done by the devm approach; hold a reference to the
clock over the period of use

clock lookup is non-fatal in this implementation as not all platforms
may provide clock specs in their device tree, but failure to enable a
clock when specified is considered fatal
Signed-off-by: default avatarGerhard Sittig <gsi@denx.de>
Signed-off-by: default avatarAnatolij Gustschin <agust@denx.de>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 498c0146
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/clk.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/fsl_devices.h> #include <linux/fsl_devices.h>
#include <linux/i2c.h> #include <linux/i2c.h>
...@@ -66,6 +67,7 @@ struct mpc_i2c { ...@@ -66,6 +67,7 @@ struct mpc_i2c {
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
u8 fdr, dfsrr; u8 fdr, dfsrr;
#endif #endif
struct clk *clk_per;
}; };
struct mpc_i2c_divider { struct mpc_i2c_divider {
...@@ -622,6 +624,8 @@ static int fsl_i2c_probe(struct platform_device *op) ...@@ -622,6 +624,8 @@ static int fsl_i2c_probe(struct platform_device *op)
int result = 0; int result = 0;
int plen; int plen;
struct resource res; struct resource res;
struct clk *clk;
int err;
match = of_match_device(mpc_i2c_of_match, &op->dev); match = of_match_device(mpc_i2c_of_match, &op->dev);
if (!match) if (!match)
...@@ -652,6 +656,21 @@ static int fsl_i2c_probe(struct platform_device *op) ...@@ -652,6 +656,21 @@ 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(&op->dev, NULL);
if (!IS_ERR(clk)) {
err = clk_prepare_enable(clk);
if (err) {
dev_err(&op->dev, "failed to enable clock\n");
goto fail_request;
} else {
i2c->clk_per = clk;
}
}
if (of_get_property(op->dev.of_node, "fsl,preserve-clocking", NULL)) { if (of_get_property(op->dev.of_node, "fsl,preserve-clocking", NULL)) {
clock = MPC_I2C_CLOCK_PRESERVE; clock = MPC_I2C_CLOCK_PRESERVE;
} else { } else {
...@@ -697,6 +716,8 @@ static int fsl_i2c_probe(struct platform_device *op) ...@@ -697,6 +716,8 @@ static int fsl_i2c_probe(struct platform_device *op)
return result; return result;
fail_add: fail_add:
if (i2c->clk_per)
clk_disable_unprepare(i2c->clk_per);
free_irq(i2c->irq, i2c); free_irq(i2c->irq, i2c);
fail_request: fail_request:
irq_dispose_mapping(i2c->irq); irq_dispose_mapping(i2c->irq);
...@@ -712,6 +733,9 @@ static int fsl_i2c_remove(struct platform_device *op) ...@@ -712,6 +733,9 @@ static int fsl_i2c_remove(struct platform_device *op)
i2c_del_adapter(&i2c->adap); i2c_del_adapter(&i2c->adap);
if (i2c->clk_per)
clk_disable_unprepare(i2c->clk_per);
if (i2c->irq) if (i2c->irq)
free_irq(i2c->irq, i2c); free_irq(i2c->irq, i2c);
......
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