diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2016-09-01 07:46:28 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2016-09-08 16:40:32 -0400 |
commit | 4c91307ce9387519836e17482906ef0f698ea7d9 (patch) | |
tree | 059b502e466ff8e50b5142bc349365bf73b17997 /drivers/i2c | |
parent | fbf8090b723d4df3cfe18c9491a8bc21ec15a5c0 (diff) |
i2c: uniphier: avoid WARN_ON() of clk_disable() in failure path
If clk_prepare_enable() fails, clk_disable_unprepare() is called in
the failure path, where the enable_count is still zero, so it hits
WARN_ON(core->enable_count == 0) in the clk_core_disable().
To fix this, make the clock setting more linear in the probe function
so that it can exploit "goto err" in case of error.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/busses/i2c-uniphier.c | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/drivers/i2c/busses/i2c-uniphier.c b/drivers/i2c/busses/i2c-uniphier.c index d6e612a0e02a..56e92af46ddc 100644 --- a/drivers/i2c/busses/i2c-uniphier.c +++ b/drivers/i2c/busses/i2c-uniphier.c | |||
@@ -316,50 +316,15 @@ static struct i2c_bus_recovery_info uniphier_i2c_bus_recovery_info = { | |||
316 | .unprepare_recovery = uniphier_i2c_unprepare_recovery, | 316 | .unprepare_recovery = uniphier_i2c_unprepare_recovery, |
317 | }; | 317 | }; |
318 | 318 | ||
319 | static int uniphier_i2c_clk_init(struct device *dev, | 319 | static void uniphier_i2c_hw_init(struct uniphier_i2c_priv *priv, |
320 | struct uniphier_i2c_priv *priv) | 320 | u32 bus_speed, unsigned long clk_rate) |
321 | { | 321 | { |
322 | struct device_node *np = dev->of_node; | ||
323 | unsigned long clk_rate; | ||
324 | u32 bus_speed; | ||
325 | int ret; | ||
326 | |||
327 | if (of_property_read_u32(np, "clock-frequency", &bus_speed)) | ||
328 | bus_speed = UNIPHIER_I2C_DEFAULT_SPEED; | ||
329 | |||
330 | if (!bus_speed) { | ||
331 | dev_err(dev, "clock-frequency should not be zero\n"); | ||
332 | return -EINVAL; | ||
333 | } | ||
334 | |||
335 | if (bus_speed > UNIPHIER_I2C_MAX_SPEED) | ||
336 | bus_speed = UNIPHIER_I2C_MAX_SPEED; | ||
337 | |||
338 | /* Get input clk rate through clk driver */ | ||
339 | priv->clk = devm_clk_get(dev, NULL); | ||
340 | if (IS_ERR(priv->clk)) { | ||
341 | dev_err(dev, "failed to get clock\n"); | ||
342 | return PTR_ERR(priv->clk); | ||
343 | } | ||
344 | |||
345 | ret = clk_prepare_enable(priv->clk); | ||
346 | if (ret) | ||
347 | return ret; | ||
348 | |||
349 | clk_rate = clk_get_rate(priv->clk); | ||
350 | if (!clk_rate) { | ||
351 | dev_err(dev, "input clock rate should not be zero\n"); | ||
352 | return -EINVAL; | ||
353 | } | ||
354 | |||
355 | uniphier_i2c_reset(priv, true); | 322 | uniphier_i2c_reset(priv, true); |
356 | 323 | ||
357 | writel((clk_rate / bus_speed / 2 << 16) | (clk_rate / bus_speed), | 324 | writel((clk_rate / bus_speed / 2 << 16) | (clk_rate / bus_speed), |
358 | priv->membase + UNIPHIER_I2C_CLK); | 325 | priv->membase + UNIPHIER_I2C_CLK); |
359 | 326 | ||
360 | uniphier_i2c_reset(priv, false); | 327 | uniphier_i2c_reset(priv, false); |
361 | |||
362 | return 0; | ||
363 | } | 328 | } |
364 | 329 | ||
365 | static int uniphier_i2c_probe(struct platform_device *pdev) | 330 | static int uniphier_i2c_probe(struct platform_device *pdev) |
@@ -367,8 +332,9 @@ static int uniphier_i2c_probe(struct platform_device *pdev) | |||
367 | struct device *dev = &pdev->dev; | 332 | struct device *dev = &pdev->dev; |
368 | struct uniphier_i2c_priv *priv; | 333 | struct uniphier_i2c_priv *priv; |
369 | struct resource *regs; | 334 | struct resource *regs; |
370 | int irq; | 335 | u32 bus_speed; |
371 | int ret; | 336 | unsigned long clk_rate; |
337 | int irq, ret; | ||
372 | 338 | ||
373 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | 339 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
374 | if (!priv) | 340 | if (!priv) |
@@ -385,6 +351,31 @@ static int uniphier_i2c_probe(struct platform_device *pdev) | |||
385 | return irq; | 351 | return irq; |
386 | } | 352 | } |
387 | 353 | ||
354 | if (of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed)) | ||
355 | bus_speed = UNIPHIER_I2C_DEFAULT_SPEED; | ||
356 | |||
357 | if (!bus_speed || bus_speed > UNIPHIER_I2C_MAX_SPEED) { | ||
358 | dev_err(dev, "invalid clock-frequency %d\n", bus_speed); | ||
359 | return -EINVAL; | ||
360 | } | ||
361 | |||
362 | priv->clk = devm_clk_get(dev, NULL); | ||
363 | if (IS_ERR(priv->clk)) { | ||
364 | dev_err(dev, "failed to get clock\n"); | ||
365 | return PTR_ERR(priv->clk); | ||
366 | } | ||
367 | |||
368 | ret = clk_prepare_enable(priv->clk); | ||
369 | if (ret) | ||
370 | return ret; | ||
371 | |||
372 | clk_rate = clk_get_rate(priv->clk); | ||
373 | if (!clk_rate) { | ||
374 | dev_err(dev, "input clock rate should not be zero\n"); | ||
375 | ret = -EINVAL; | ||
376 | goto err; | ||
377 | } | ||
378 | |||
388 | init_completion(&priv->comp); | 379 | init_completion(&priv->comp); |
389 | priv->adap.owner = THIS_MODULE; | 380 | priv->adap.owner = THIS_MODULE; |
390 | priv->adap.algo = &uniphier_i2c_algo; | 381 | priv->adap.algo = &uniphier_i2c_algo; |
@@ -395,9 +386,7 @@ static int uniphier_i2c_probe(struct platform_device *pdev) | |||
395 | i2c_set_adapdata(&priv->adap, priv); | 386 | i2c_set_adapdata(&priv->adap, priv); |
396 | platform_set_drvdata(pdev, priv); | 387 | platform_set_drvdata(pdev, priv); |
397 | 388 | ||
398 | ret = uniphier_i2c_clk_init(dev, priv); | 389 | uniphier_i2c_hw_init(priv, bus_speed, clk_rate); |
399 | if (ret) | ||
400 | goto err; | ||
401 | 390 | ||
402 | ret = devm_request_irq(dev, irq, uniphier_i2c_interrupt, 0, pdev->name, | 391 | ret = devm_request_irq(dev, irq, uniphier_i2c_interrupt, 0, pdev->name, |
403 | priv); | 392 | priv); |