public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/5] lib: Add wait_for_bit
Date: Tue, 15 Dec 2015 01:20:06 +0100	[thread overview]
Message-ID: <201512150120.06981.marex@denx.de> (raw)
In-Reply-To: <1450138168-25102-2-git-send-email-mateusz.kulikowski@gmail.com>

On Tuesday, December 15, 2015 at 01:09:23 AM, Mateusz Kulikowski wrote:
> Add function to poll register waiting for specific bit(s).
> Similar functions are implemented in few drivers - they are almost
> identical and can be generalized.
> Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
> ---

Excellent !

>  include/wait_bit.h | 34 ++++++++++++++++++++++++++++++++++
>  lib/Kconfig        |  4 ++++
>  lib/Makefile       |  1 +
>  lib/wait_bit.c     | 44 ++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 83 insertions(+)
>  create mode 100644 include/wait_bit.h
>  create mode 100644 lib/wait_bit.c

[...]

> +int wait_for_bit(const char *prefix,

const u32 *

> u32 *reg, const u32 mask,

const bool, const unsigned int , const bool ;-)

> bool set,
> +		 unsigned int timeout, bool breakable)

> +{
> +	u32 val;
> +	unsigned long start = get_timer(0);
> +
> +	while (1) {
> +		val = readl(reg);
> +
> +		if (!set)
> +			val = ~val;
> +
> +		if ((val & mask) == mask)
> +			return 0;
> +
> +		if (get_timer(start) > timeout)
> +			break;
> +
> +		if (breakable && ctrlc()) {
> +			puts("Abort\n");
> +			return -EINTR;
> +		}
> +
> +		udelay(1);
> +	}
> +
> +	debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n", prefix, reg, mask,
> +	      set);
> +
> +	return -ETIMEDOUT;
> +}

Best regards,
Marek Vasut

  reply	other threads:[~2015-12-15  0:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-15  0:09 [U-Boot] [PATCH 0/5] Add wait_for_bit() Mateusz Kulikowski
2015-12-15  0:09 ` [U-Boot] [PATCH 1/5] lib: Add wait_for_bit Mateusz Kulikowski
2015-12-15  0:20   ` Marek Vasut [this message]
2015-12-15  0:09 ` [U-Boot] [PATCH 2/5] usb: dwc2: Use shared wait_for_bit Mateusz Kulikowski
2015-12-15  0:21   ` Marek Vasut
2015-12-15 21:22     ` Mateusz Kulikowski
2015-12-15 22:43       ` Marek Vasut
2015-12-15  0:09 ` [U-Boot] [PATCH 3/5] usb: ohci-lpc32xx: " Mateusz Kulikowski
2015-12-15 18:49   ` LEMIEUX, SYLVAIN
2015-12-15 21:20     ` Mateusz Kulikowski
2015-12-15  0:09 ` [U-Boot] [PATCH 4/5] usb: ehci-mx6: " Mateusz Kulikowski
2015-12-15  0:09 ` [U-Boot] [PATCH 5/5] net: zynq_gem: " Mateusz Kulikowski
2015-12-15 18:42 ` [U-Boot] [PATCH 0/5] Add wait_for_bit() LEMIEUX, SYLVAIN

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=201512150120.06981.marex@denx.de \
    --to=marex@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox