]> Git Repo - J-u-boot.git/blobdiff - drivers/i2c/rcar_i2c.c
Merge branch 'master' of https://source.denx.de/u-boot/custodians/u-boot-usb
[J-u-boot.git] / drivers / i2c / rcar_i2c.c
index 2ebae349ed3c2123db58e539598e517ae468b3d7..3bd5108fd2357800ebecef3a38a4a93f65d32792 100644 (file)
  *   Kuninori Morimoto <[email protected]>
  */
 
-#include <common.h>
 #include <clk.h>
 #include <dm.h>
 #include <i2c.h>
 #include <asm/io.h>
 #include <wait_bit.h>
+#include <dm/device_compat.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
 
 #define RCAR_I2C_ICSCR                 0x00 /* slave ctrl */
 #define RCAR_I2C_ICMCR                 0x04 /* master ctrl */
@@ -52,7 +54,6 @@
 #define RCAR_I2C_ICFBSCR               0x38
 #define RCAR_I2C_ICFBSCR_TCYC17                0x0f /* 17*Tcyc */
 
-
 enum rcar_i2c_type {
        RCAR_I2C_TYPE_GEN2,
        RCAR_I2C_TYPE_GEN3,
@@ -61,6 +62,8 @@ enum rcar_i2c_type {
 struct rcar_i2c_priv {
        void __iomem            *base;
        struct clk              clk;
+       u32                     fall_ns;
+       u32                     rise_ns;
        u32                     intdelay;
        u32                     icccr;
        enum rcar_i2c_type      type;
@@ -208,7 +211,7 @@ static int rcar_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int nmsgs)
        int ret;
 
        for (; nmsgs > 0; nmsgs--, msg++) {
-               ret = rcar_i2c_set_addr(dev, msg->addr, 1);
+               ret = rcar_i2c_set_addr(dev, msg->addr, !!(msg->flags & I2C_M_RD));
                if (ret)
                        return ret;
 
@@ -275,7 +278,7 @@ static int rcar_i2c_set_speed(struct udevice *dev, uint bus_freq_hz)
         *  = F[sum * ick / 1000000000]
         *  = F[(ick / 1000000) * sum / 1000]
         */
-       sum = 35 + 200 + priv->intdelay;
+       sum = priv->fall_ns + priv->rise_ns + priv->intdelay;
        round = (ick + 500000) / 1000000 * sum;
        round = (round + 500) / 1000;
 
@@ -320,6 +323,10 @@ static int rcar_i2c_probe(struct udevice *dev)
        int ret;
 
        priv->base = dev_read_addr_ptr(dev);
+       priv->rise_ns = dev_read_u32_default(dev,
+                                            "i2c-scl-rising-time-ns", 200);
+       priv->fall_ns = dev_read_u32_default(dev,
+                                            "i2c-scl-falling-time-ns", 35);
        priv->intdelay = dev_read_u32_default(dev,
                                              "i2c-scl-internal-delay-ns", 5);
        priv->type = dev_get_driver_data(dev);
@@ -344,7 +351,7 @@ static int rcar_i2c_probe(struct udevice *dev)
        writel(0, priv->base + RCAR_I2C_ICMSR);
        writel(0, priv->base + RCAR_I2C_ICMAR);
 
-       ret = rcar_i2c_set_speed(dev, 100000);
+       ret = rcar_i2c_set_speed(dev, I2C_SPEED_STANDARD_RATE);
        if (ret)
                clk_disable(&priv->clk);
 
@@ -360,6 +367,7 @@ static const struct dm_i2c_ops rcar_i2c_ops = {
 static const struct udevice_id rcar_i2c_ids[] = {
        { .compatible = "renesas,rcar-gen2-i2c", .data = RCAR_I2C_TYPE_GEN2 },
        { .compatible = "renesas,rcar-gen3-i2c", .data = RCAR_I2C_TYPE_GEN3 },
+       { .compatible = "renesas,rcar-gen4-i2c", .data = RCAR_I2C_TYPE_GEN3 },
        { }
 };
 
@@ -368,6 +376,6 @@ U_BOOT_DRIVER(i2c_rcar) = {
        .id             = UCLASS_I2C,
        .of_match       = rcar_i2c_ids,
        .probe          = rcar_i2c_probe,
-       .priv_auto_alloc_size = sizeof(struct rcar_i2c_priv),
+       .priv_auto      = sizeof(struct rcar_i2c_priv),
        .ops            = &rcar_i2c_ops,
 };
This page took 0.030497 seconds and 4 git commands to generate.