aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-05-26 15:50:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-26 15:50:04 -0400
commit39b6cc668c5ecc66f6f9c9293ffab681cb6f7065 (patch)
treef048b17a1b1a0a0f6d6a8d33459e8789c600c634 /lib
parent27953437059c64d14086196eb96f43c78caa9db3 (diff)
parent3f81b2c49d31e763a9c1da831ceb6cef087cf6c6 (diff)
Merge tag 'stmp-dev' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Pull arm-soc stmp-dev library code from Olof Johansson: "A number of devices are using a common register layout, this adds support code for it in lib/stmp_device.c so we do not need to duplicate it in each driver." Fix up trivial conflicts in drivers/i2c/busses/i2c-mxs.c and lib/Makefile * tag 'stmp-dev' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc: i2c: mxs: use global reset function lib: add support for stmp-style devices
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig3
-rw-r--r--lib/Makefile2
-rw-r--r--lib/stmp_device.c80
3 files changed, 85 insertions, 0 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index 98230ac3db29..3e63af089082 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -36,6 +36,9 @@ config GENERIC_IO
36 boolean 36 boolean
37 default n 37 default n
38 38
39config STMP_DEVICE
40 bool
41
39config CRC_CCITT 42config CRC_CCITT
40 tristate "CRC-CCITT functions" 43 tristate "CRC-CCITT functions"
41 help 44 help
diff --git a/lib/Makefile b/lib/Makefile
index b98df505f335..2a1d7f9d39a2 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -127,6 +127,8 @@ obj-$(CONFIG_DDR) += jedec_ddr_data.o
127 127
128obj-$(CONFIG_GENERIC_STRNCPY_FROM_USER) += strncpy_from_user.o 128obj-$(CONFIG_GENERIC_STRNCPY_FROM_USER) += strncpy_from_user.o
129 129
130obj-$(CONFIG_STMP_DEVICE) += stmp_device.o
131
130hostprogs-y := gen_crc32table 132hostprogs-y := gen_crc32table
131clean-files := crc32table.h 133clean-files := crc32table.h
132 134
diff --git a/lib/stmp_device.c b/lib/stmp_device.c
new file mode 100644
index 000000000000..8ac9bcc4289a
--- /dev/null
+++ b/lib/stmp_device.c
@@ -0,0 +1,80 @@
1/*
2 * Copyright (C) 1999 ARM Limited
3 * Copyright (C) 2000 Deep Blue Solutions Ltd
4 * Copyright 2006-2007,2010 Freescale Semiconductor, Inc. All Rights Reserved.
5 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
6 * Copyright 2009 Ilya Yanok, Emcraft Systems Ltd, yanok@emcraft.com
7 * Copyright (C) 2011 Wolfram Sang, Pengutronix e.K.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14
15#include <linux/io.h>
16#include <linux/errno.h>
17#include <linux/delay.h>
18#include <linux/module.h>
19#include <linux/stmp_device.h>
20
21#define STMP_MODULE_CLKGATE (1 << 30)
22#define STMP_MODULE_SFTRST (1 << 31)
23
24/*
25 * Clear the bit and poll it cleared. This is usually called with
26 * a reset address and mask being either SFTRST(bit 31) or CLKGATE
27 * (bit 30).
28 */
29static int stmp_clear_poll_bit(void __iomem *addr, u32 mask)
30{
31 int timeout = 0x400;
32
33 writel(mask, addr + STMP_OFFSET_REG_CLR);
34 udelay(1);
35 while ((readl(addr) & mask) && --timeout)
36 /* nothing */;
37
38 return !timeout;
39}
40
41int stmp_reset_block(void __iomem *reset_addr)
42{
43 int ret;
44 int timeout = 0x400;
45
46 /* clear and poll SFTRST */
47 ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
48 if (unlikely(ret))
49 goto error;
50
51 /* clear CLKGATE */
52 writel(STMP_MODULE_CLKGATE, reset_addr + STMP_OFFSET_REG_CLR);
53
54 /* set SFTRST to reset the block */
55 writel(STMP_MODULE_SFTRST, reset_addr + STMP_OFFSET_REG_SET);
56 udelay(1);
57
58 /* poll CLKGATE becoming set */
59 while ((!(readl(reset_addr) & STMP_MODULE_CLKGATE)) && --timeout)
60 /* nothing */;
61 if (unlikely(!timeout))
62 goto error;
63
64 /* clear and poll SFTRST */
65 ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
66 if (unlikely(ret))
67 goto error;
68
69 /* clear and poll CLKGATE */
70 ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_CLKGATE);
71 if (unlikely(ret))
72 goto error;
73
74 return 0;
75
76error:
77 pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
78 return -ETIMEDOUT;
79}
80EXPORT_SYMBOL(stmp_reset_block);