]> Pileus Git - ~andy/linux/blobdiff - drivers/i2c/busses/i2c-designware-platdrv.c
cnic: Redefine BNX2X_HW_CID using existing bnx2x macros
[~andy/linux] / drivers / i2c / busses / i2c-designware-platdrv.c
index 35b70a1edf572bedda30222ec8c9d49693491314..4c5fadabe49df3236e479c86105d7e479aa90d79 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/sched.h>
 #include <linux/err.h>
 #include <linux/interrupt.h>
+#include <linux/of.h>
 #include <linux/of_i2c.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
@@ -87,13 +88,6 @@ static int dw_i2c_probe(struct platform_device *pdev)
        struct resource *mem;
        int irq, r;
 
-       /* NOTE: driver uses the static register mapping */
-       mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!mem) {
-               dev_err(&pdev->dev, "no mem resource?\n");
-               return -EINVAL;
-       }
-
        irq = platform_get_irq(pdev, 0);
        if (irq < 0) {
                dev_err(&pdev->dev, "no irq resource?\n");
@@ -104,6 +98,7 @@ static int dw_i2c_probe(struct platform_device *pdev)
        if (!dev)
                return -ENOMEM;
 
+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        dev->base = devm_ioremap_resource(&pdev->dev, mem);
        if (IS_ERR(dev->base))
                return PTR_ERR(dev->base);
@@ -121,6 +116,16 @@ static int dw_i2c_probe(struct platform_device *pdev)
                return PTR_ERR(dev->clk);
        clk_prepare_enable(dev->clk);
 
+       if (pdev->dev.of_node) {
+               u32 ht = 0;
+               u32 ic_clk = dev->get_clk_rate_khz(dev);
+
+               of_property_read_u32(pdev->dev.of_node,
+                                       "i2c-sda-hold-time-ns", &ht);
+               dev->sda_hold_time = div_u64((u64)ic_clk * ht + 500000,
+                                            1000000);
+       }
+
        dev->functionality =
                I2C_FUNC_I2C |
                I2C_FUNC_10BIT_ADDR |