From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Tue, 15 Dec 2015 01:20:06 +0100 Subject: [U-Boot] [PATCH 1/5] lib: Add wait_for_bit In-Reply-To: <1450138168-25102-2-git-send-email-mateusz.kulikowski@gmail.com> References: <1450138168-25102-1-git-send-email-mateusz.kulikowski@gmail.com> <1450138168-25102-2-git-send-email-mateusz.kulikowski@gmail.com> Message-ID: <201512150120.06981.marex@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 > --- 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