Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright (C) 1999 ARM Limited
0004  * Copyright (C) 2000 Deep Blue Solutions Ltd
0005  * Copyright 2006-2007,2010 Freescale Semiconductor, Inc. All Rights Reserved.
0006  * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
0007  * Copyright 2009 Ilya Yanok, Emcraft Systems Ltd, yanok@emcraft.com
0008  * Copyright (C) 2011 Wolfram Sang, Pengutronix e.K.
0009  */
0010 
0011 #include <linux/io.h>
0012 #include <linux/errno.h>
0013 #include <linux/delay.h>
0014 #include <linux/compiler.h>
0015 #include <linux/export.h>
0016 #include <linux/stmp_device.h>
0017 
0018 #define STMP_MODULE_CLKGATE (1 << 30)
0019 #define STMP_MODULE_SFTRST  (1 << 31)
0020 
0021 /*
0022  * Clear the bit and poll it cleared.  This is usually called with
0023  * a reset address and mask being either SFTRST(bit 31) or CLKGATE
0024  * (bit 30).
0025  */
0026 static int stmp_clear_poll_bit(void __iomem *addr, u32 mask)
0027 {
0028     int timeout = 0x400;
0029 
0030     writel(mask, addr + STMP_OFFSET_REG_CLR);
0031     udelay(1);
0032     while ((readl(addr) & mask) && --timeout)
0033         /* nothing */;
0034 
0035     return !timeout;
0036 }
0037 
0038 int stmp_reset_block(void __iomem *reset_addr)
0039 {
0040     int ret;
0041     int timeout = 0x400;
0042 
0043     /* clear and poll SFTRST */
0044     ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
0045     if (unlikely(ret))
0046         goto error;
0047 
0048     /* clear CLKGATE */
0049     writel(STMP_MODULE_CLKGATE, reset_addr + STMP_OFFSET_REG_CLR);
0050 
0051     /* set SFTRST to reset the block */
0052     writel(STMP_MODULE_SFTRST, reset_addr + STMP_OFFSET_REG_SET);
0053     udelay(1);
0054 
0055     /* poll CLKGATE becoming set */
0056     while ((!(readl(reset_addr) & STMP_MODULE_CLKGATE)) && --timeout)
0057         /* nothing */;
0058     if (unlikely(!timeout))
0059         goto error;
0060 
0061     /* clear and poll SFTRST */
0062     ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
0063     if (unlikely(ret))
0064         goto error;
0065 
0066     /* clear and poll CLKGATE */
0067     ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_CLKGATE);
0068     if (unlikely(ret))
0069         goto error;
0070 
0071     return 0;
0072 
0073 error:
0074     pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
0075     return -ETIMEDOUT;
0076 }
0077 EXPORT_SYMBOL(stmp_reset_block);