diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-08-05 12:49:58 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-08-05 12:49:58 +0200 |
commit | feefc3ef3b4d201845480b17cb9e6c6729eb1a96 (patch) | |
tree | 355bae733a4bb876425a06549b8e1bdd393a5020 /lib | |
parent | 9ebb0554cd0e19f3757f4f5eea723eaf3b6dab78 (diff) | |
parent | ae5eeb06ed37914d6a47a1f414a9165763ac5677 (diff) | |
download | barebox-feefc3ef3b4d201845480b17cb9e6c6729eb1a96.tar.gz barebox-feefc3ef3b4d201845480b17cb9e6c6729eb1a96.tar.xz |
Merge branch 'for-next/mtd'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 3 | ||||
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/random.c | 4 | ||||
-rw-r--r-- | lib/stmp-device.c | 63 | ||||
-rw-r--r-- | lib/string.c | 59 |
5 files changed, 129 insertions, 1 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index b5ac22a2a4..d9ad4aa949 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -47,6 +47,9 @@ config LIBUBIGEN config LIBMTD bool +config STMP_DEVICE + bool + source lib/gui/Kconfig source lib/bootstrap/Kconfig diff --git a/lib/Makefile b/lib/Makefile index 61f1e63ae3..e1db99b95b 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -43,3 +43,4 @@ obj-$(CONFIG_LIBMTD) += libmtd.o obj-y += gui/ obj-$(CONFIG_XYMODEM) += xymodem.o obj-y += unlink-recursive.o +obj-$(CONFIG_STMP_DEVICE) += stmp-device.o diff --git a/lib/random.c b/lib/random.c index 352d6bf3f7..14c7da119d 100644 --- a/lib/random.c +++ b/lib/random.c @@ -18,8 +18,10 @@ void srand(unsigned int seed) random_seed = seed; } -void get_random_bytes(char *buf, int len) +void get_random_bytes(void *_buf, int len) { + char *buf = _buf; + while (len--) *buf++ = rand() % 256; } diff --git a/lib/stmp-device.c b/lib/stmp-device.c new file mode 100644 index 0000000000..74d476316e --- /dev/null +++ b/lib/stmp-device.c @@ -0,0 +1,63 @@ +/* + * Freescale i.MXS common code + * + * Copyright (C) 2012 Wolfram Sang <w.sang@pengutronix.de> + * + * Based on code from LTIB: + * Copyright (C) 2010 Freescale Semiconductor, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include <common.h> +#include <io.h> +#include <stmp-device.h> +#include <errno.h> +#include <clock.h> + +#define STMP_IP_RESET_TIMEOUT (10 * MSECOND) + +#define STMP_BLOCK_SFTRST (1 << 31) +#define STMP_BLOCK_CLKGATE (1 << 30) + +int stmp_reset_block(void __iomem *reg, int just_enable) +{ + /* Clear SFTRST */ + writel(STMP_BLOCK_SFTRST, reg + STMP_OFFSET_REG_CLR); + + if (wait_on_timeout(STMP_IP_RESET_TIMEOUT, !(readl(reg) & STMP_BLOCK_SFTRST))) + goto timeout; + + /* Clear CLKGATE */ + writel(STMP_BLOCK_CLKGATE, reg + STMP_OFFSET_REG_CLR); + + if (!just_enable) { + /* Set SFTRST */ + writel(STMP_BLOCK_SFTRST, reg + STMP_OFFSET_REG_SET); + + /* Wait for CLKGATE being set */ + if (wait_on_timeout(STMP_IP_RESET_TIMEOUT, readl(reg) & STMP_BLOCK_CLKGATE)) + goto timeout; + } + + /* Clear SFTRST */ + writel(STMP_BLOCK_SFTRST, reg + STMP_OFFSET_REG_CLR); + + if (wait_on_timeout(STMP_IP_RESET_TIMEOUT, !(readl(reg) & STMP_BLOCK_SFTRST))) + goto timeout; + + /* Clear CLKGATE */ + writel(STMP_BLOCK_CLKGATE, reg + STMP_OFFSET_REG_CLR); + + if (wait_on_timeout(STMP_IP_RESET_TIMEOUT, !(readl(reg) & STMP_BLOCK_CLKGATE))) + goto timeout; + + return 0; + +timeout: + printf("MXS: Timeout resetting block via register 0x%p\n", reg); + return -ETIMEDOUT; +} diff --git a/lib/string.c b/lib/string.c index f544b23664..eeec137c9e 100644 --- a/lib/string.c +++ b/lib/string.c @@ -666,3 +666,62 @@ char *strim(char *s) return s; } EXPORT_SYMBOL(strim); + +static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) +{ + while (bytes) { + if (*start != value) + return (void *)start; + start++; + bytes--; + } + return NULL; +} + +/** + * memchr_inv - Find an unmatching character in an area of memory. + * @start: The memory area + * @c: Find a character other than c + * @bytes: The size of the area. + * + * returns the address of the first character other than @c, or %NULL + * if the whole buffer contains just @c. + */ +void *memchr_inv(const void *start, int c, size_t bytes) +{ + u8 value = c; + u64 value64; + unsigned int words, prefix; + + if (bytes <= 16) + return check_bytes8(start, value, bytes); + + value64 = value; + value64 |= value64 << 8; + value64 |= value64 << 16; + value64 |= value64 << 32; + + prefix = (unsigned long)start % 8; + if (prefix) { + u8 *r; + + prefix = 8 - prefix; + r = check_bytes8(start, value, prefix); + if (r) + return r; + start += prefix; + bytes -= prefix; + } + + words = bytes / 8; + + while (words) { + if (*(u64 *)start != value64) + return check_bytes8(start, value, 8); + start += 8; + words--; + } + + return check_bytes8(start, value, bytes % 8); +} +EXPORT_SYMBOL(memchr_inv); |