diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 3 | ||||
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/stmp-device.c | 63 |
3 files changed, 67 insertions, 0 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 646fdb7d71..4fa300909c 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -43,6 +43,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 7c42537ccd..8436d27e91 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -41,3 +41,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/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; +} |