]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - drivers/i2c/busses/i2c-designware-platdrv.c
i2c: designware: Default to fast mode in case of ACPI
[mirror_ubuntu-artful-kernel.git] / drivers / i2c / busses / i2c-designware-platdrv.c
index bc877333315586cc2a3051a8678c6fe7e7f41b68..353adc4dc5831b839eefe8358bcc29fbcdba38f0 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/io.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
+#include <linux/platform_data/i2c-designware.h>
 #include "i2c-designware-core.h"
 
 static struct i2c_algorithm i2c_dw_algo = {
@@ -79,7 +80,6 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, char method[],
 static int dw_i2c_acpi_configure(struct platform_device *pdev)
 {
        struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
-       bool fs_mode = dev->master_cfg & DW_IC_CON_SPEED_FAST;
 
        if (!ACPI_HANDLE(&pdev->dev))
                return -ENODEV;
@@ -92,10 +92,9 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
         * Try to get SDA hold time and *CNT values from an ACPI method if
         * it exists for both supported speed modes.
         */
-       dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt,
-                          fs_mode ? NULL : &dev->sda_hold_time);
+       dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt, NULL);
        dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt,
-                          fs_mode ? &dev->sda_hold_time : NULL);
+                          &dev->sda_hold_time);
 
        return 0;
 }
@@ -122,7 +121,9 @@ static int dw_i2c_probe(struct platform_device *pdev)
        struct dw_i2c_dev *dev;
        struct i2c_adapter *adap;
        struct resource *mem;
+       struct dw_i2c_platform_data *pdata;
        int irq, r;
+       u32 clk_freq;
 
        irq = platform_get_irq(pdev, 0);
        if (irq < 0) {
@@ -152,6 +153,9 @@ static int dw_i2c_probe(struct platform_device *pdev)
                return PTR_ERR(dev->clk);
        clk_prepare_enable(dev->clk);
 
+       /* fast mode by default because of legacy reasons */
+       clk_freq = 400000;
+
        if (pdev->dev.of_node) {
                u32 ht = 0;
                u32 ic_clk = dev->get_clk_rate_khz(dev);
@@ -167,6 +171,21 @@ static int dw_i2c_probe(struct platform_device *pdev)
                of_property_read_u32(pdev->dev.of_node,
                                     "i2c-scl-falling-time-ns",
                                     &dev->scl_falling_time);
+
+               of_property_read_u32(pdev->dev.of_node, "clock-frequency",
+                                    &clk_freq);
+
+               /* Only standard mode at 100kHz and fast mode at 400kHz
+                * are supported.
+                */
+               if (clk_freq != 100000 && clk_freq != 400000) {
+                       dev_err(&pdev->dev, "Only 100kHz and 400kHz supported");
+                       return -EINVAL;
+               }
+       } else {
+               pdata = dev_get_platdata(&pdev->dev);
+               if (pdata)
+                       clk_freq = pdata->i2c_scl_freq;
        }
 
        dev->functionality =
@@ -176,8 +195,12 @@ static int dw_i2c_probe(struct platform_device *pdev)
                I2C_FUNC_SMBUS_BYTE_DATA |
                I2C_FUNC_SMBUS_WORD_DATA |
                I2C_FUNC_SMBUS_I2C_BLOCK;
-       dev->master_cfg =  DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
-               DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
+       if (clk_freq == 100000)
+               dev->master_cfg =  DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
+                       DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_STD;
+       else
+               dev->master_cfg =  DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
+                       DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
 
        /* Try first if we can configure the device from ACPI */
        r = dw_i2c_acpi_configure(pdev);