modified i2c driver for jh7110
authorHuan.Feng <huan.feng@starfivetech.com>
Fri, 10 Dec 2021 09:50:41 +0000 (17:50 +0800)
committerHuan.Feng <huan.feng@starfivetech.com>
Fri, 10 Dec 2021 09:50:41 +0000 (17:50 +0800)
drivers/i2c/busses/i2c-designware-master.c
drivers/i2c/busses/i2c-designware-platdrv.c

index 9b08bb5..c6aee31 100644 (file)
@@ -815,6 +815,7 @@ static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap)
        i2c_dw_init_master(dev);
 }
 
+#ifndef CONFIG_SOC_STARFIVE_VIC7110
 static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
 {
        struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
@@ -842,6 +843,7 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
 
        return 0;
 }
+#endif
 
 static int amd_i2c_adap_quirk(struct dw_i2c_dev *dev)
 {
@@ -910,11 +912,11 @@ int i2c_dw_probe_master(struct dw_i2c_dev *dev)
                        dev->irq, ret);
                return ret;
        }
-
+#ifndef CONFIG_SOC_STARFIVE_VIC7110
        ret = i2c_dw_init_recovery_info(dev);
        if (ret)
                return ret;
-
+#endif
        /*
         * Increment PM usage count during adapter registration in order to
         * avoid possible spurious runtime suspend when adapter device is
index 2111366..d9c5ad1 100644 (file)
@@ -40,6 +40,21 @@ static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
        return clk_get_rate(dev->clk) / KILO;
 }
 
+#ifdef CONFIG_SOC_STARFIVE
+static u32 starfive_i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
+{
+       u32 val;
+
+       if(!device_property_read_u32(dev->dev, "clocks", &val)) {
+               dev_info(dev->dev, "Using 'clocks' : %u / 1000", val);
+               return (val / 1000);
+       } else {
+               dev_info(dev->dev, "Using the static setting value: 49500");
+               return 49500;
+       }
+}
+#endif
+
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id dw_i2c_acpi_match[] = {
        { "INT33C2", 0 },
@@ -272,6 +287,17 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
                if (!dev->sda_hold_time && t->sda_hold_ns)
                        dev->sda_hold_time =
                                DIV_S64_ROUND_CLOSEST(clk_khz * t->sda_hold_ns, MICRO);
+#ifdef CONFIG_SOC_STARFIVE
+       } else {
+               u64 clk_khz;
+
+               dev->get_clk_rate_khz = starfive_i2c_dw_get_clk_rate_khz;
+               clk_khz = dev->get_clk_rate_khz(dev);
+
+               if (!dev->sda_hold_time && t->sda_hold_ns)
+                       dev->sda_hold_time =
+                               DIV_S64_ROUND_CLOSEST(clk_khz * t->sda_hold_ns, MICRO);
+#endif
        }
 
        adap = &dev->adapter;