From patchwork Fri Oct 13 10:21:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 115741 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp565823qgn; Fri, 13 Oct 2017 03:34:01 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDhMTeNbUKcYIox0pGu3fJypfkuwJ8pNwqJZicIUfxPMfv9vBpD9Oxr9lq63cAv610NWhEo X-Received: by 10.80.212.208 with SMTP id e16mr1519997edj.263.1507890841204; Fri, 13 Oct 2017 03:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507890841; cv=none; d=google.com; s=arc-20160816; b=ROaClKL8Iroj6gBv37FEt027cVbRLXVnofD0oaEGa0WFwVF5rW30q0VP/zfryAQ7Ln tmzOKl5bezjaHw5IBRjc/Olzf2XOJix5kJ48AeVqvC02LBmrOtHFnIbC8Pfy4EthKjBW 2hxTbW7Jh1ZpajiDpv/VfrCB43KHKDCH2AwyVtkiILtojVXS2BMHObyT3qIfWyIWvRLZ 6b/v4BT+lPV13FiyDD7XZGLi+nFh3zKsSLcr9YcEyXq6zslIkwTAR7EEXJl7XIcFBXN9 FjTyhCqH3T+QC9wdJaZil5wdr/CyLY+TdU2NeRnBP+L3ogLgbn4fC85hyeMs/ZPbH43h vq6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=uvKPkeglq5ZDciJSt1FbsYXyCgOvhwEA6oY/YQYN/i4=; b=kK+mMokeorkPUj8fwDltFqYgfB7OsQnJ/V3hRhw3YC1wVXvz+cvPa9roYm0sn+QNoe aqIDjjRZzgKRVIvo7Ai1t3vrCnlhNrlm3HTaYe+oX0sTAkfjhUY2fYRhcuAcIcgpf8/N fqRvYjyy4zHZv3dL1Mx7zaQQ3nRQZYpVYSk3aOVlf+bll87zrJKznxYzzwYvic/APRPk DQK77Nj8sc5e9O4EqYhTKYy7JKsE2sP7QMwzwdegOhR4d6BacxqRR3hC5IPQv1qztthO i4EikhdcitXyohPSqXRvm2L/2HHNa+59nXSVVW2jjgXH667fCbI7p23zpLWeJPYVs54X WBaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=sEtGzZrd; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id g25si613302edm.285.2017.10.13.03.34.00; Fri, 13 Oct 2017 03:34:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=sEtGzZrd; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id C23A6C21FFD; Fri, 13 Oct 2017 10:30:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C1209C2203C; Fri, 13 Oct 2017 10:22:58 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F07ABC21F5D; Fri, 13 Oct 2017 10:22:41 +0000 (UTC) Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by lists.denx.de (Postfix) with ESMTPS id BA524C21F2C for ; Fri, 13 Oct 2017 10:22:39 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-12.nifty.com with ESMTP id v9DAMGxC009903; Fri, 13 Oct 2017 19:22:21 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com v9DAMGxC009903 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1507890141; bh=T7dsMyV2QgMCf3qbIWdr7A4Zd27PteeQP+vYmYi53Yc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sEtGzZrdateN53a5KisdVzak9Yl1gqG5Jn61a6J+XNs0q9KZVECegHcnQf7sqbbeW Q/zAwZdfD1Sv9njpbSa9AmXGqm3nKcWSWS0TuOz7TWhlryvoyZMwGRidg1yVu6+mvH aF1R+bQeK+YMxutjLnZaKkUmclQ9hoGWQvZDQwuCiDebMwHgvFVbNcvaKtW7Q2J2GM o3tDZEVn14JNz1aXwNoRONCJHKISblUgERJt/vDvGaegGVfrxe7W6CUQ7CaHJq7jno 1tY0brarW+VnKchC3meaviQNlGeIokCkR87/fDAlWEJrF1wU/iRnKgwlIwiXs4pV6B 9woyalnaHSk7w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Fri, 13 Oct 2017 19:21:58 +0900 Message-Id: <1507890129-1543-10-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507890129-1543-1-git-send-email-yamada.masahiro@socionext.com> References: <1507890129-1543-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH 09/20] i2c: uniphier-f: replace debug() with dev_dbg() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Use dev_dbg() functions. It will be helpful to prefix log messages with the corresponding device name when the core framework is ready. While I am here, I renamed "dev", which was actually private data, into "priv" because dev->dev looks confusing. Signed-off-by: Masahiro Yamada Reviewed-by: Heiko Schocher --- drivers/i2c/i2c-uniphier-f.c | 114 ++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/drivers/i2c/i2c-uniphier-f.c b/drivers/i2c/i2c-uniphier-f.c index e51537b..eb6c9f3 100644 --- a/drivers/i2c/i2c-uniphier-f.c +++ b/drivers/i2c/i2c-uniphier-f.c @@ -6,13 +6,12 @@ * SPDX-License-Identifier: GPL-2.0+ */ -#include -#include -#include +#include #include #include #include -#include +#include +#include #include #include @@ -64,35 +63,27 @@ struct uniphier_fi2c_regs { #define FIOCLK 50000000 -struct uniphier_fi2c_dev { +struct uniphier_fi2c_priv { + struct udevice *dev; struct uniphier_fi2c_regs __iomem *regs; /* register base */ unsigned long fioclk; /* internal operation clock */ unsigned long timeout; /* time out (us) */ }; -static int reset_bus(struct uniphier_fi2c_regs __iomem *regs) +static void uniphier_fi2c_reset(struct uniphier_fi2c_priv *priv) { - u32 val; - int ret; - - /* bus forcible reset */ - writel(I2C_RST_RST, ®s->rst); - ret = readl_poll_timeout(®s->rst, val, !(val & I2C_RST_RST), 1); - if (ret < 0) - debug("error: fail to reset I2C controller\n"); - - return ret; + writel(I2C_RST_RST, &priv->regs->rst); } -static int check_device_busy(struct uniphier_fi2c_regs __iomem *regs) +static int uniphier_fi2c_check_bus_busy(struct uniphier_fi2c_priv *priv) { u32 val; int ret; - ret = readl_poll_timeout(®s->sr, val, !(val & I2C_SR_DB), 100); + ret = readl_poll_timeout(&priv->regs->sr, val, !(val & I2C_SR_DB), 100); if (ret < 0) { - debug("error: device busy too long. reset...\n"); - ret = reset_bus(regs); + dev_dbg(priv->dev, "error: device busy too long. reset...\n"); + uniphier_fi2c_reset(priv); } return ret; @@ -101,8 +92,7 @@ static int check_device_busy(struct uniphier_fi2c_regs __iomem *regs) static int uniphier_fi2c_probe(struct udevice *dev) { fdt_addr_t addr; - struct uniphier_fi2c_dev *priv = dev_get_priv(dev); - int ret; + struct uniphier_fi2c_priv *priv = dev_get_priv(dev); addr = devfdt_get_addr(dev); if (addr == FDT_ADDR_T_NONE) @@ -114,85 +104,85 @@ static int uniphier_fi2c_probe(struct udevice *dev) priv->fioclk = FIOCLK; + priv->dev = dev; + /* bus forcible reset */ - ret = reset_bus(priv->regs); - if (ret < 0) - return ret; + uniphier_fi2c_reset(priv); writel(I2C_BRST_FOEN | I2C_BRST_RSCLO, &priv->regs->brst); return 0; } -static int wait_for_irq(struct uniphier_fi2c_dev *dev, u32 flags, +static int wait_for_irq(struct uniphier_fi2c_priv *priv, u32 flags, bool *stop) { u32 irq; int ret; - ret = readl_poll_timeout(&dev->regs->intr, irq, irq & flags, - dev->timeout); + ret = readl_poll_timeout(&priv->regs->intr, irq, irq & flags, + priv->timeout); if (ret < 0) { - debug("error: time out\n"); + dev_dbg(priv->dev, "error: time out\n"); return ret; } if (irq & I2C_INT_AL) { - debug("error: arbitration lost\n"); + dev_dbg(priv->dev, "error: arbitration lost\n"); *stop = false; return ret; } if (irq & I2C_INT_NA) { - debug("error: no answer\n"); + dev_dbg(priv->dev, "error: no answer\n"); return ret; } return 0; } -static int issue_stop(struct uniphier_fi2c_dev *dev, int old_ret) +static int issue_stop(struct uniphier_fi2c_priv *priv, int old_ret) { int ret; - debug("stop condition\n"); - writel(I2C_CR_MST | I2C_CR_STO, &dev->regs->cr); + dev_dbg(priv->dev, "stop condition\n"); + writel(I2C_CR_MST | I2C_CR_STO, &priv->regs->cr); - ret = check_device_busy(dev->regs); + ret = uniphier_fi2c_check_bus_busy(priv); if (ret < 0) - debug("error: device busy after operation\n"); + dev_dbg(priv->dev, "error: device busy after operation\n"); return old_ret ? old_ret : ret; } -static int uniphier_fi2c_transmit(struct uniphier_fi2c_dev *dev, uint addr, +static int uniphier_fi2c_transmit(struct uniphier_fi2c_priv *priv, uint addr, uint len, const u8 *buf, bool *stop) { int ret; const u32 irq_flags = I2C_INT_TE | I2C_INT_NA | I2C_INT_AL; - struct uniphier_fi2c_regs __iomem *regs = dev->regs; + struct uniphier_fi2c_regs __iomem *regs = priv->regs; - debug("%s: addr = %x, len = %d\n", __func__, addr, len); + dev_dbg(priv->dev, "%s: addr = %x, len = %d\n", __func__, addr, len); writel(I2C_DTTX_CMD | addr << 1, ®s->dttx); writel(irq_flags, ®s->ie); writel(irq_flags, ®s->ic); - debug("start condition\n"); + dev_dbg(priv->dev, "start condition\n"); writel(I2C_CR_MST | I2C_CR_STA, ®s->cr); - ret = wait_for_irq(dev, irq_flags, stop); + ret = wait_for_irq(priv, irq_flags, stop); if (ret < 0) goto error; while (len--) { - debug("sending %x\n", *buf); + dev_dbg(priv->dev, "sending %x\n", *buf); writel(*buf++, ®s->dttx); writel(irq_flags, ®s->ic); - ret = wait_for_irq(dev, irq_flags, stop); + ret = wait_for_irq(priv, irq_flags, stop); if (ret < 0) goto error; } @@ -201,26 +191,26 @@ error: writel(irq_flags, ®s->ic); if (*stop) - ret = issue_stop(dev, ret); + ret = issue_stop(priv, ret); return ret; } -static int uniphier_fi2c_receive(struct uniphier_fi2c_dev *dev, uint addr, +static int uniphier_fi2c_receive(struct uniphier_fi2c_priv *priv, uint addr, uint len, u8 *buf, bool *stop) { int ret = 0; const u32 irq_flags = I2C_INT_RB | I2C_INT_NA | I2C_INT_AL; - struct uniphier_fi2c_regs __iomem *regs = dev->regs; + struct uniphier_fi2c_regs __iomem *regs = priv->regs; - debug("%s: addr = %x, len = %d\n", __func__, addr, len); + dev_dbg(priv->dev, "%s: addr = %x, len = %d\n", __func__, addr, len); /* * In case 'len == 0', only the slave address should be sent * for probing, which is covered by the transmit function. */ if (len == 0) - return uniphier_fi2c_transmit(dev, addr, len, buf, stop); + return uniphier_fi2c_transmit(priv, addr, len, buf, stop); writel(I2C_DTTX_CMD | I2C_DTTX_RD | addr << 1, ®s->dttx); @@ -228,17 +218,17 @@ static int uniphier_fi2c_receive(struct uniphier_fi2c_dev *dev, uint addr, writel(irq_flags, ®s->ie); writel(irq_flags, ®s->ic); - debug("start condition\n"); + dev_dbg(priv->dev, "start condition\n"); writel(I2C_CR_MST | I2C_CR_STA | (len == 1 ? I2C_CR_NACK : 0), ®s->cr); while (len--) { - ret = wait_for_irq(dev, irq_flags, stop); + ret = wait_for_irq(priv, irq_flags, stop); if (ret < 0) goto error; *buf++ = readl(®s->dtrx); - debug("received %x\n", *(buf - 1)); + dev_dbg(priv->dev, "received %x\n", *(buf - 1)); if (len == 1) writel(I2C_CR_MST | I2C_CR_NACK, ®s->cr); @@ -250,7 +240,7 @@ error: writel(irq_flags, ®s->ic); if (*stop) - ret = issue_stop(dev, ret); + ret = issue_stop(priv, ret); return ret; } @@ -259,10 +249,10 @@ static int uniphier_fi2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs) { int ret; - struct uniphier_fi2c_dev *dev = dev_get_priv(bus); + struct uniphier_fi2c_priv *priv = dev_get_priv(bus); bool stop; - ret = check_device_busy(dev->regs); + ret = uniphier_fi2c_check_bus_busy(priv); if (ret < 0) return ret; @@ -271,10 +261,10 @@ static int uniphier_fi2c_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_fi2c_receive(dev, msg->addr, msg->len, + ret = uniphier_fi2c_receive(priv, msg->addr, msg->len, msg->buf, &stop); else - ret = uniphier_fi2c_transmit(dev, msg->addr, msg->len, + ret = uniphier_fi2c_transmit(priv, msg->addr, msg->len, msg->buf, &stop); if (ret < 0) @@ -288,21 +278,21 @@ static int uniphier_fi2c_set_bus_speed(struct udevice *bus, unsigned int speed) { int ret; unsigned int clk_count; - struct uniphier_fi2c_dev *dev = dev_get_priv(bus); - struct uniphier_fi2c_regs __iomem *regs = dev->regs; + struct uniphier_fi2c_priv *priv = dev_get_priv(bus); + struct uniphier_fi2c_regs __iomem *regs = priv->regs; /* max supported frequency is 400 kHz */ if (speed > 400000) return -EINVAL; - ret = check_device_busy(dev->regs); + ret = uniphier_fi2c_check_bus_busy(priv); if (ret < 0) return ret; /* make sure the bus is idle when changing the frequency */ writel(I2C_BRST_RSCLO, ®s->brst); - clk_count = dev->fioclk / speed; + clk_count = priv->fioclk / speed; writel(clk_count, ®s->cyc); writel(clk_count / 2, ®s->lctl); @@ -316,7 +306,7 @@ static int uniphier_fi2c_set_bus_speed(struct udevice *bus, unsigned int speed) * 1000000 * 9 / speed usec. * This time out value is long enough. */ - dev->timeout = 100000000L / speed; + priv->timeout = 100000000L / speed; return 0; } @@ -336,6 +326,6 @@ U_BOOT_DRIVER(uniphier_fi2c) = { .id = UCLASS_I2C, .of_match = uniphier_fi2c_of_match, .probe = uniphier_fi2c_probe, - .priv_auto_alloc_size = sizeof(struct uniphier_fi2c_dev), + .priv_auto_alloc_size = sizeof(struct uniphier_fi2c_priv), .ops = &uniphier_fi2c_ops, };