aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Dooks <ben.dooks@codethink.co.uk>2014-01-26 11:05:35 -0500
committerWolfram Sang <wsa@the-dreams.de>2014-01-26 16:48:34 -0500
commitbc8120f17ae87da0850b4e6a806ad88ffd01ca64 (patch)
treee41afe3176a871a1b7d347c10217430d19bb6dc8
parent770540f029ba65a2658b5204d850565ab7f61f1b (diff)
i2c: rcar: use devm_clk_get to ensure clock is properly ref-counted
The current i2c-rcar driver does clk_get() without a corresponding clk_put(). Add the clk to the driver private data and then get it with the devm functions so that it is released when the driver is unbound. Note, we do not call clk_prepare_enable() at this point due to the very possible magic that is being done by the pm_runtime system underneath the driver. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/i2c/busses/i2c-rcar.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index fd4cd7f6b3ef..57169d23aa3b 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -110,6 +110,7 @@ struct rcar_i2c_priv {
110 void __iomem *io; 110 void __iomem *io;
111 struct i2c_adapter adap; 111 struct i2c_adapter adap;
112 struct i2c_msg *msg; 112 struct i2c_msg *msg;
113 struct clk *clk;
113 114
114 spinlock_t lock; 115 spinlock_t lock;
115 wait_queue_head_t wait; 116 wait_queue_head_t wait;
@@ -226,18 +227,12 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
226 u32 bus_speed, 227 u32 bus_speed,
227 struct device *dev) 228 struct device *dev)
228{ 229{
229 struct clk *clkp = clk_get(dev, NULL);
230 u32 scgd, cdf; 230 u32 scgd, cdf;
231 u32 round, ick; 231 u32 round, ick;
232 u32 scl; 232 u32 scl;
233 u32 cdf_width; 233 u32 cdf_width;
234 unsigned long rate; 234 unsigned long rate;
235 235
236 if (IS_ERR(clkp)) {
237 dev_err(dev, "couldn't get clock\n");
238 return PTR_ERR(clkp);
239 }
240
241 switch (priv->devtype) { 236 switch (priv->devtype) {
242 case I2C_RCAR_GEN1: 237 case I2C_RCAR_GEN1:
243 cdf_width = 2; 238 cdf_width = 2;
@@ -265,7 +260,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
265 * clkp : peripheral_clk 260 * clkp : peripheral_clk
266 * F[] : integer up-valuation 261 * F[] : integer up-valuation
267 */ 262 */
268 rate = clk_get_rate(clkp); 263 rate = clk_get_rate(priv->clk);
269 cdf = rate / 20000000; 264 cdf = rate / 20000000;
270 if (cdf >= 1 << cdf_width) { 265 if (cdf >= 1 << cdf_width) {
271 dev_err(dev, "Input clock %lu too high\n", rate); 266 dev_err(dev, "Input clock %lu too high\n", rate);
@@ -307,7 +302,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
307 302
308scgd_find: 303scgd_find:
309 dev_dbg(dev, "clk %d/%d(%lu), round %u, CDF:0x%x, SCGD: 0x%x\n", 304 dev_dbg(dev, "clk %d/%d(%lu), round %u, CDF:0x%x, SCGD: 0x%x\n",
310 scl, bus_speed, clk_get_rate(clkp), round, cdf, scgd); 305 scl, bus_speed, clk_get_rate(priv->clk), round, cdf, scgd);
311 306
312 /* 307 /*
313 * keep icccr value 308 * keep icccr value
@@ -663,6 +658,12 @@ static int rcar_i2c_probe(struct platform_device *pdev)
663 return -ENOMEM; 658 return -ENOMEM;
664 } 659 }
665 660
661 priv->clk = devm_clk_get(dev, NULL);
662 if (IS_ERR(priv->clk)) {
663 dev_err(dev, "cannot get clock\n");
664 return PTR_ERR(priv->clk);
665 }
666
666 bus_speed = 100000; /* default 100 kHz */ 667 bus_speed = 100000; /* default 100 kHz */
667 ret = of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed); 668 ret = of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed);
668 if (ret < 0 && pdata && pdata->bus_speed) 669 if (ret < 0 && pdata && pdata->bus_speed)