summaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
authorWolfram Sang <wsa@the-dreams.de>2015-02-19 11:22:34 -0500
committerWolfram Sang <wsa@the-dreams.de>2015-02-20 12:01:23 -0500
commit0d8fb59924cf20e7bef2c41f8d4e87127f573546 (patch)
tree9674de914ac8c29d1c17c65ea93fbe2983b4900a /drivers/i2c/busses
parentb4ad0510f5d9099487acf2c748b99081ab6ab869 (diff)
i2c: ocores: rework clk code to handle NULL cookie
For, !HAVE_CLK the clk API returns a NULL cookie. Rework the initialization code to handle that. If clk_get_rate() delivers 0, we use the fallback mechanisms. The patch is pretty easy when ignoring white space issues (git diff -b). Suggested-by: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: Wolfram Sang <wsa@the-dreams.de> Tested-by: Max Filippov <jcmvbkbc@gmail.com>
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/i2c-ocores.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 3fc76b6ffcaa..abf5db7e441e 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -354,20 +354,24 @@ static int ocores_i2c_of_probe(struct platform_device *pdev,
354 i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000; 354 i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000;
355 if (clock_frequency_present) 355 if (clock_frequency_present)
356 i2c->bus_clock_khz = clock_frequency / 1000; 356 i2c->bus_clock_khz = clock_frequency / 1000;
357 } else if (of_property_read_u32(np, "opencores,ip-clock-frequency", 357 }
358 &val)) { 358
359 if (!clock_frequency_present) { 359 if (i2c->ip_clock_khz == 0) {
360 dev_err(&pdev->dev, 360 if (of_property_read_u32(np, "opencores,ip-clock-frequency",
361 "Missing required parameter 'opencores,ip-clock-frequency'\n"); 361 &val)) {
362 return -ENODEV; 362 if (!clock_frequency_present) {
363 dev_err(&pdev->dev,
364 "Missing required parameter 'opencores,ip-clock-frequency'\n");
365 return -ENODEV;
366 }
367 i2c->ip_clock_khz = clock_frequency / 1000;
368 dev_warn(&pdev->dev,
369 "Deprecated usage of the 'clock-frequency' property, please update to 'opencores,ip-clock-frequency'\n");
370 } else {
371 i2c->ip_clock_khz = val / 1000;
372 if (clock_frequency_present)
373 i2c->bus_clock_khz = clock_frequency / 1000;
363 } 374 }
364 i2c->ip_clock_khz = clock_frequency / 1000;
365 dev_warn(&pdev->dev,
366 "Deprecated usage of the 'clock-frequency' property, please update to 'opencores,ip-clock-frequency'\n");
367 } else {
368 i2c->ip_clock_khz = val / 1000;
369 if (clock_frequency_present)
370 i2c->bus_clock_khz = clock_frequency / 1000;
371 } 375 }
372 376
373 of_property_read_u32(pdev->dev.of_node, "reg-io-width", 377 of_property_read_u32(pdev->dev.of_node, "reg-io-width",
@@ -518,6 +522,7 @@ static int ocores_i2c_resume(struct device *dev)
518 struct ocores_i2c *i2c = dev_get_drvdata(dev); 522 struct ocores_i2c *i2c = dev_get_drvdata(dev);
519 523
520 if (!IS_ERR(i2c->clk)) { 524 if (!IS_ERR(i2c->clk)) {
525 unsigned long rate;
521 int ret = clk_prepare_enable(i2c->clk); 526 int ret = clk_prepare_enable(i2c->clk);
522 527
523 if (ret) { 528 if (ret) {
@@ -525,7 +530,9 @@ static int ocores_i2c_resume(struct device *dev)
525 "clk_prepare_enable failed: %d\n", ret); 530 "clk_prepare_enable failed: %d\n", ret);
526 return ret; 531 return ret;
527 } 532 }
528 i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000; 533 rate = clk_get_rate(i2c->clk) / 1000;
534 if (rate)
535 i2c->ip_clock_khz = rate;
529 } 536 }
530 return ocores_init(dev, i2c); 537 return ocores_init(dev, i2c);
531} 538}