]> git.sur5r.net Git - u-boot/blobdiff - drivers/i2c/i2c-uniphier.c
net: mvneta: zero Tx descriptors on init
[u-boot] / drivers / i2c / i2c-uniphier.c
index f391f11e93572ae6a947999566379c856acedca8..e427415e7ed72b18bb2bc479982269b797909240 100644 (file)
@@ -1,20 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2014      Panasonic Corporation
  * Copyright (C) 2015-2016 Socionext Inc.
  *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
-#include <common.h>
-#include <linux/types.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
 #include <linux/io.h>
 #include <linux/sizes.h>
-#include <linux/errno.h>
-#include <dm/device.h>
-#include <dm/root.h>
-#include <i2c.h>
+#include <linux/types.h>
+#include <dm.h>
 #include <fdtdec.h>
+#include <i2c.h>
 
 struct uniphier_i2c_regs {
        u32 dtrm;                       /* data transmission */
@@ -39,7 +37,8 @@ struct uniphier_i2c_regs {
 
 #define IOBUS_FREQ     100000000
 
-struct uniphier_i2c_dev {
+struct uniphier_i2c_priv {
+       struct udevice *dev;
        struct uniphier_i2c_regs __iomem *regs; /* register base */
        unsigned long input_clk;        /* master clock (Hz) */
        unsigned long wait_us;          /* wait for every byte transfer (us) */
@@ -48,9 +47,9 @@ struct uniphier_i2c_dev {
 static int uniphier_i2c_probe(struct udevice *dev)
 {
        fdt_addr_t addr;
-       struct uniphier_i2c_dev *priv = dev_get_priv(dev);
+       struct uniphier_i2c_priv *priv = dev_get_priv(dev);
 
-       addr = dev_get_addr(dev);
+       addr = devfdt_get_addr(dev);
        if (addr == FDT_ADDR_T_NONE)
                return -EINVAL;
 
@@ -60,15 +59,17 @@ static int uniphier_i2c_probe(struct udevice *dev)
 
        priv->input_clk = IOBUS_FREQ;
 
+       priv->dev = dev;
+
        /* deassert reset */
        writel(0x3, &priv->regs->brst);
 
        return 0;
 }
 
-static int send_and_recv_byte(struct uniphier_i2c_dev *dev, u32 dtrm)
+static int send_and_recv_byte(struct uniphier_i2c_priv *priv, u32 dtrm)
 {
-       writel(dtrm, &dev->regs->dtrm);
+       writel(dtrm, &priv->regs->dtrm);
 
        /*
         * This controller only provides interruption to inform the completion
@@ -76,72 +77,72 @@ static int send_and_recv_byte(struct uniphier_i2c_dev *dev, u32 dtrm)
         * Unfortunately, U-Boot does not have a good support of interrupt.
         * Wait for a while.
         */
-       udelay(dev->wait_us);
+       udelay(priv->wait_us);
 
-       return readl(&dev->regs->drec);
+       return readl(&priv->regs->drec);
 }
 
-static int send_byte(struct uniphier_i2c_dev *dev, u32 dtrm, bool *stop)
+static int send_byte(struct uniphier_i2c_priv *priv, u32 dtrm, bool *stop)
 {
        int ret = 0;
        u32 drec;
 
-       drec = send_and_recv_byte(dev, dtrm);
+       drec = send_and_recv_byte(priv, dtrm);
 
        if (drec & I2C_DREC_LAB) {
-               debug("uniphier_i2c: bus arbitration failed\n");
+               dev_dbg(priv->dev, "uniphier_i2c: bus arbitration failed\n");
                *stop = false;
                ret = -EREMOTEIO;
        }
        if (drec & I2C_DREC_LRB) {
-               debug("uniphier_i2c: slave did not return ACK\n");
+               dev_dbg(priv->dev, "uniphier_i2c: slave did not return ACK\n");
                ret = -EREMOTEIO;
        }
        return ret;
 }
 
-static int uniphier_i2c_transmit(struct uniphier_i2c_dev *dev, uint addr,
+static int uniphier_i2c_transmit(struct uniphier_i2c_priv *priv, uint addr,
                                 uint len, const u8 *buf, bool *stop)
 {
        int ret;
 
-       debug("%s: addr = %x, len = %d\n", __func__, addr, len);
+       dev_dbg(priv->dev, "%s: addr = %x, len = %d\n", __func__, addr, len);
 
-       ret = send_byte(dev, I2C_DTRM_STA | I2C_DTRM_NACK | addr << 1, stop);
+       ret = send_byte(priv, I2C_DTRM_STA | I2C_DTRM_NACK | addr << 1, stop);
        if (ret < 0)
                goto fail;
 
        while (len--) {
-               ret = send_byte(dev, I2C_DTRM_NACK | *buf++, stop);
+               ret = send_byte(priv, I2C_DTRM_NACK | *buf++, stop);
                if (ret < 0)
                        goto fail;
        }
 
 fail:
        if (*stop)
-               writel(I2C_DTRM_STO | I2C_DTRM_NACK, &dev->regs->dtrm);
+               writel(I2C_DTRM_STO | I2C_DTRM_NACK, &priv->regs->dtrm);
 
        return ret;
 }
 
-static int uniphier_i2c_receive(struct uniphier_i2c_dev *dev, uint addr,
+static int uniphier_i2c_receive(struct uniphier_i2c_priv *priv, uint addr,
                                uint len, u8 *buf, bool *stop)
 {
        int ret;
 
-       debug("%s: addr = %x, len = %d\n", __func__, addr, len);
+       dev_dbg(priv->dev, "%s: addr = %x, len = %d\n", __func__, addr, len);
 
-       ret = send_byte(dev, I2C_DTRM_STA | I2C_DTRM_NACK |
+       ret = send_byte(priv, I2C_DTRM_STA | I2C_DTRM_NACK |
                        I2C_DTRM_RD | addr << 1, stop);
        if (ret < 0)
                goto fail;
 
        while (len--)
-               *buf++ = send_and_recv_byte(dev, len ? 0 : I2C_DTRM_NACK);
+               *buf++ = send_and_recv_byte(priv, len ? 0 : I2C_DTRM_NACK);
 
 fail:
        if (*stop)
-               writel(I2C_DTRM_STO | I2C_DTRM_NACK, &dev->regs->dtrm);
+               writel(I2C_DTRM_STO | I2C_DTRM_NACK, &priv->regs->dtrm);
 
        return ret;
 }
@@ -150,7 +151,7 @@ static int uniphier_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
                             int nmsgs)
 {
        int ret = 0;
-       struct uniphier_i2c_dev *dev = dev_get_priv(bus);
+       struct uniphier_i2c_priv *priv = dev_get_priv(bus);
        bool stop;
 
        for (; nmsgs > 0; nmsgs--, msg++) {
@@ -158,10 +159,10 @@ static int uniphier_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
                stop = nmsgs > 1 && msg[1].flags & I2C_M_RD ? false : true;
 
                if (msg->flags & I2C_M_RD)
-                       ret = uniphier_i2c_receive(dev, msg->addr, msg->len,
+                       ret = uniphier_i2c_receive(priv, msg->addr, msg->len,
                                                   msg->buf, &stop);
                else
-                       ret = uniphier_i2c_transmit(dev, msg->addr, msg->len,
+                       ret = uniphier_i2c_transmit(priv, msg->addr, msg->len,
                                                    msg->buf, &stop);
 
                if (ret < 0)
@@ -173,7 +174,7 @@ static int uniphier_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
 
 static int uniphier_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
 {
-       struct uniphier_i2c_dev *priv = dev_get_priv(bus);
+       struct uniphier_i2c_priv *priv = dev_get_priv(bus);
 
        /* max supported frequency is 400 kHz */
        if (speed > 400000)
@@ -212,6 +213,6 @@ U_BOOT_DRIVER(uniphier_i2c) = {
        .id = UCLASS_I2C,
        .of_match = uniphier_i2c_of_match,
        .probe = uniphier_i2c_probe,
-       .priv_auto_alloc_size = sizeof(struct uniphier_i2c_dev),
+       .priv_auto_alloc_size = sizeof(struct uniphier_i2c_priv),
        .ops = &uniphier_i2c_ops,
 };