From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 30 Dec 2017 11:12:36 +0100 Subject: [U-Boot] [PATCH] wait_bit: add big endian version of wait_for_bit function Message-ID: <20171230101236.12937-1-noltari@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 The only difference with the existing wait_for_bit function is the fact that wait_for_bit_be expects the register size to be read. Signed-off-by: Álvaro Fernández Rojas --- include/wait_bit.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/include/wait_bit.h b/include/wait_bit.h index 06ad43a122..828fdcda02 100644 --- a/include/wait_bit.h +++ b/include/wait_bit.h @@ -69,5 +69,74 @@ static inline int wait_for_bit(const char *prefix, const u32 *reg, return -ETIMEDOUT; } +/** + * wait_for_bit_be() waits for bit set/cleared in BE register + * + * Function polls register waiting for specific bit(s) change + * (either 0->1 or 1->0). It can fail under two conditions: + * - Timeout + * - User interaction (CTRL-C) + * Function succeeds only if all bits of masked register are set/cleared + * (depending on set option). + * + * @param prefix Prefix added to timeout messagge (message visible only + * with debug enabled) + * @param reg Register that will be read (using read_be()) + * @param size Size of the register that will be read + * @param mask Bit(s) of register that must be active + * @param set Selects wait condition (bit set or clear) + * @param timeout_ms Timeout (in miliseconds) + * @param breakable Enables CTRL-C interruption + * @return 0 on success, -EINVAL, -ETIMEDOUT or -EINTR on failure + */ +static inline int wait_for_bit_be(const char *prefix, + const u32 *reg, const u8 size, + const u32 mask, const bool set, + const unsigned int timeout_ms, + const bool breakable) +{ + u32 val; + unsigned long start = get_timer(0); + + while (1) { + switch(size) + { + case 8: + val = readb_be(reg); + break; + case 16: + val = readw_be(reg); + break; + case 32: + val = readl_be(reg); + break; + default: + debug("%s: invalid size %u\n", prefix, size); + return -EINVAL; + } + + 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=%08x wait_set=%i)\n", prefix, reg, mask, + set); + + return -ETIMEDOUT; +} #endif -- 2.11.0