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.
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.
16 #include <linux/errno.h>
17 #include <linux/delay.h>
18 #include <linux/module.h>
19 #include <linux/stmp_device.h>
21 #define STMP_MODULE_CLKGATE (1 << 30)
22 #define STMP_MODULE_SFTRST (1 << 31)
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
29 static int stmp_clear_poll_bit(void __iomem *addr, u32 mask)
33 writel(mask, addr + STMP_OFFSET_REG_CLR);
35 while ((readl(addr) & mask) && --timeout)
41 int stmp_reset_block(void __iomem *reset_addr)
46 /* clear and poll SFTRST */
47 ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
52 writel(STMP_MODULE_CLKGATE, reset_addr + STMP_OFFSET_REG_CLR);
54 /* set SFTRST to reset the block */
55 writel(STMP_MODULE_SFTRST, reset_addr + STMP_OFFSET_REG_SET);
58 /* poll CLKGATE becoming set */
59 while ((!(readl(reset_addr) & STMP_MODULE_CLKGATE)) && --timeout)
61 if (unlikely(!timeout))
64 /* clear and poll SFTRST */
65 ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
69 /* clear and poll CLKGATE */
70 ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_CLKGATE);
77 pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
80 EXPORT_SYMBOL(stmp_reset_block);