1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 1999 ARM Limited
4 * Copyright (C) 2000 Deep Blue Solutions Ltd
5 * Copyright 2006-2007,2010 Freescale Semiconductor, Inc. All Rights Reserved.
6 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
7 * Copyright 2009 Ilya Yanok, Emcraft Systems Ltd, yanok@emcraft.com
8 * Copyright (C) 2011 Wolfram Sang, Pengutronix e.K.
12 #include <linux/errno.h>
13 #include <linux/delay.h>
14 #include <linux/compiler.h>
15 #include <linux/export.h>
16 #include <linux/stmp_device.h>
18 #define STMP_MODULE_CLKGATE (1 << 30)
19 #define STMP_MODULE_SFTRST (1 << 31)
22 * Clear the bit and poll it cleared. This is usually called with
23 * a reset address and mask being either SFTRST(bit 31) or CLKGATE
26 static int stmp_clear_poll_bit(void __iomem
*addr
, u32 mask
)
30 writel(mask
, addr
+ STMP_OFFSET_REG_CLR
);
32 while ((readl(addr
) & mask
) && --timeout
)
38 int stmp_reset_block(void __iomem
*reset_addr
)
43 /* clear and poll SFTRST */
44 ret
= stmp_clear_poll_bit(reset_addr
, STMP_MODULE_SFTRST
);
49 writel(STMP_MODULE_CLKGATE
, reset_addr
+ STMP_OFFSET_REG_CLR
);
51 /* set SFTRST to reset the block */
52 writel(STMP_MODULE_SFTRST
, reset_addr
+ STMP_OFFSET_REG_SET
);
55 /* poll CLKGATE becoming set */
56 while ((!(readl(reset_addr
) & STMP_MODULE_CLKGATE
)) && --timeout
)
58 if (unlikely(!timeout
))
61 /* clear and poll SFTRST */
62 ret
= stmp_clear_poll_bit(reset_addr
, STMP_MODULE_SFTRST
);
66 /* clear and poll CLKGATE */
67 ret
= stmp_clear_poll_bit(reset_addr
, STMP_MODULE_CLKGATE
);
74 pr_err("%s(%p): module reset timeout\n", __func__
, reset_addr
);
77 EXPORT_SYMBOL(stmp_reset_block
);