summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-07-09 13:01:00 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-07-23 16:25:13 +0200
commitca13a84ac2580d8507f292b469751a919af60411 (patch)
tree8cc52c2a7520bdd0d1f0b8c8175e4862503abc77 /lib
parent66891566ccf72c19c3c25182f98eda4dc2a8ad3e (diff)
downloadbarebox-ca13a84ac2580d8507f292b469751a919af60411.tar.gz
barebox-ca13a84ac2580d8507f292b469751a919af60411.tar.xz
ARM: MXS: introduce stmp device support
MXS specific devices have some common infrastructure in the kernel known as STMP devices. We have the same in barebox, but with a mxs_ prefix instead of a stmp_ prefix. As some STMP devices are also found on i.MX6 move the common infrastructure out of MXS specific files and use the stmp_ prefix. This is done in preparation for i.MX6 NAND support. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig3
-rw-r--r--lib/Makefile1
-rw-r--r--lib/stmp-device.c63
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;
+}