From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Schwierzeck Date: Tue, 2 Jan 2018 21:24:40 +0100 Subject: [U-Boot] [PATCH v6 01/11] wait_bit: add big endian version of wait_for_bit function In-Reply-To: <20180102190111.2192-2-noltari@gmail.com> References: <20170730121347.30494-1-noltari@gmail.com> <20180102190111.2192-1-noltari@gmail.com> <20180102190111.2192-2-noltari@gmail.com> Message-ID: <863c5ee1-e983-f9c9-3f8a-0b45ea1d8b08@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit To: u-boot@lists.denx.de On 02.01.2018 20:01, Álvaro Fernández Rojas wrote: > Add 8/16/32 bits and BE/LE versions of wait_for_bit. > This is needed for reading registers that are not aligned to 32 bits. > > Signed-off-by: Álvaro Fernández Rojas > --- > v6: Introduce changes suggested by Jagan Teki: > - Switch to wait_for_bit instead of infinite loop. > > include/wait_bit.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 44 insertions(+) > > diff --git a/include/wait_bit.h b/include/wait_bit.h > index 06ad43a122..47891fa75c 100644 > --- a/include/wait_bit.h > +++ b/include/wait_bit.h > @@ -69,5 +69,49 @@ static inline int wait_for_bit(const char *prefix, const u32 *reg, > return -ETIMEDOUT; > } > > +#define BUILD_WAIT_FOR_BIT(sfx, type, read) \ > + \ > +static inline int wait_for_bit_##sfx(const char *prefix, \ > + const u32 *reg, \ I suggest to use 'const void *reg' for compatibility with 64 bit systems and to be consistant with the most readl() implementations > + const type mask, \ > + const bool set, \ > + const unsigned int timeout_ms, \ > + const bool breakable) \ > +{ \ > + type val; \ > + unsigned long start = get_timer(0); \ > + \ > + while (1) { \ > + val = read(reg); \ > + \ > + if (!set) \ > + val = ~val; \ > + \ > + if ((val & mask) == mask) \ > + return 0; \ > + \ > + if (get_timer(start) > timeout_ms) \ > + break; \ > + \ > + if (breakable && ctrlc()) { \ > + puts("Abort\n"); \ > + return -EINTR; \ > + } \ > + \ > + udelay(1); \ > + WATCHDOG_RESET(); \ > + } \ > + \ > + debug("%s: Timeout (reg=%p mask=%x wait_set=%i)\n", prefix, \ > + reg, mask, set); \ almost all users pass __func__ as value for the prefix argument. Since this is a macro now, we could directly use __func__ in the debug() call and omit the prefix argument > + \ > + return -ETIMEDOUT; \ > +} > + > +BUILD_WAIT_FOR_BIT(8, u8, readb) > +BUILD_WAIT_FOR_BIT(le16, u16, readw) > +BUILD_WAIT_FOR_BIT(be16, u16, readw_be) > +BUILD_WAIT_FOR_BIT(le32, u32, readl) > +BUILD_WAIT_FOR_BIT(be32, u32, readl_be) > > #endif > -- - Daniel -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: