From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 16/16] i2c: uniphier-f: use readl_poll_timeout() to poll registers
Date: Tue, 31 Jan 2017 06:09:18 +0100 [thread overview]
Message-ID: <58901BFE.3090906@denx.de> (raw)
In-Reply-To: <1485554036-29320-17-git-send-email-yamada.masahiro@socionext.com>
Hello Masahiro,
Am 27.01.2017 um 22:53 schrieb Masahiro Yamada:
> The readl_poll_timeout() is a useful helper to poll registers
> and error out if the condition is not met.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> drivers/i2c/i2c-uniphier-f.c | 34 ++++++++++------------------------
> 1 file changed, 10 insertions(+), 24 deletions(-)
Reviewed-by: Heiko Schocher <hs@denx.de>
bye,
Heiko
>
> diff --git a/drivers/i2c/i2c-uniphier-f.c b/drivers/i2c/i2c-uniphier-f.c
> index e212c13..9f0df59 100644
> --- a/drivers/i2c/i2c-uniphier-f.c
> +++ b/drivers/i2c/i2c-uniphier-f.c
> @@ -9,6 +9,7 @@
> #include <common.h>
> #include <linux/types.h>
> #include <linux/io.h>
> +#include <linux/iopoll.h>
> #include <linux/sizes.h>
> #include <linux/errno.h>
> #include <dm/device.h>
> @@ -69,26 +70,14 @@ struct uniphier_fi2c_dev {
> unsigned long timeout; /* time out (us) */
> };
>
> -static int poll_status(u32 __iomem *reg, u32 flag)
> -{
> - int wait = 1000000; /* 1 sec is long enough */
> -
> - while (readl(reg) & flag) {
> - if (wait-- < 0)
> - return -EREMOTEIO;
> - udelay(1);
> - }
> -
> - return 0;
> -}
> -
> static int reset_bus(struct uniphier_fi2c_regs __iomem *regs)
> {
> + u32 val;
> int ret;
>
> /* bus forcible reset */
> writel(I2C_RST_RST, ®s->rst);
> - ret = poll_status(®s->rst, I2C_RST_RST);
> + ret = readl_poll_timeout(®s->rst, val, !(val & I2C_RST_RST), 1);
> if (ret < 0)
> debug("error: fail to reset I2C controller\n");
>
> @@ -97,9 +86,10 @@ static int reset_bus(struct uniphier_fi2c_regs __iomem *regs)
>
> static int check_device_busy(struct uniphier_fi2c_regs __iomem *regs)
> {
> + u32 val;
> int ret;
>
> - ret = poll_status(®s->sr, I2C_SR_DB);
> + ret = readl_poll_timeout(®s->sr, val, !(val & I2C_SR_DB), 100);
> if (ret < 0) {
> debug("error: device busy too long. reset...\n");
> ret = reset_bus(regs);
> @@ -138,15 +128,11 @@ static int wait_for_irq(struct uniphier_fi2c_dev *dev, u32 flags,
> bool *stop)
> {
> u32 irq;
> - unsigned long wait = dev->timeout;
> - int ret = -EREMOTEIO;
> -
> - do {
> - udelay(1);
> - irq = readl(&dev->regs->intr);
> - } while (!(irq & flags) && wait--);
> + int ret;
>
> - if (wait < 0) {
> + ret = readl_poll_timeout(&dev->regs->intr, irq, irq & flags,
> + dev->timeout);
> + if (ret < 0) {
> debug("error: time out\n");
> return ret;
> }
> @@ -172,7 +158,7 @@ static int issue_stop(struct uniphier_fi2c_dev *dev, int old_ret)
> debug("stop condition\n");
> writel(I2C_CR_MST | I2C_CR_STO, &dev->regs->cr);
>
> - ret = poll_status(&dev->regs->sr, I2C_SR_DB);
> + ret = check_device_busy(dev->regs);
> if (ret < 0)
> debug("error: device busy after operation\n");
>
>
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
next prev parent reply other threads:[~2017-01-31 5:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-27 21:53 [U-Boot] [PATCH 00/16] ARM: uniphier: UniPhier SoC updates for v2017.03 (3rd round) Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 01/16] clk: uniphier: fix compatible strings for Pro5, PXs2, LD20 SD clock Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 02/16] ARM: uniphier: shrink arrays of DDR-PHY parameters for LD20 SoC Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 03/16] ARM: uniphier: detect RAM size by decoding HW register instead of DT Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 04/16] ARM: uniphier: use gd->bd->bi_dram for memory reserve on LD20 SoC Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 05/16] ARM: uniphier: refactor cmd_ddrphy Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 06/16] ARM: uniphier: clean up UMC init for PXs2 SoC Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 07/16] ARM: uniphier: refactor cmd_ddrmphy Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 08/16] ARM: uniphier: compile board data only for SPL Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 09/16] ARM: uniphier: collect SPL CONFIG symbols to the bottom of header Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 10/16] ARM: uniphier: use Image.gz instead Image for booting ARM64 Linux Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 11/16] ARM: uniphier: set initrd_high environment to skip initrd relocation Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 12/16] ARM: uniphier: change the offset to environment storage area Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 13/16] ARM: uniphier: change CONFIG_SPL_PAD_TO to 128KB Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 14/16] ARM: uniphier: make update commands more flexible for ATF Masahiro Yamada
2017-01-27 21:53 ` [U-Boot] [PATCH 15/16] i2c: uniphier(-f): remove unneeded #include <dm/root.h> Masahiro Yamada
2017-01-31 5:07 ` Heiko Schocher
2017-01-27 21:53 ` [U-Boot] [PATCH 16/16] i2c: uniphier-f: use readl_poll_timeout() to poll registers Masahiro Yamada
2017-01-31 5:09 ` Heiko Schocher [this message]
2017-01-29 12:11 ` [U-Boot] [PATCH 00/16] ARM: uniphier: UniPhier SoC updates for v2017.03 (3rd round) Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58901BFE.3090906@denx.de \
--to=hs@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.