Linux Audio

Check our new training course

Yocto / OpenEmbedded training

Feb 10-13, 2025
Register
Loading...
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 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.
 9 */
10
11#include <linux/io.h>
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>
17
18#define STMP_MODULE_CLKGATE	(1 << 30)
19#define STMP_MODULE_SFTRST	(1 << 31)
20
21/*
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
24 * (bit 30).
25 */
26static int stmp_clear_poll_bit(void __iomem *addr, u32 mask)
27{
28	int timeout = 0x400;
29
30	writel(mask, addr + STMP_OFFSET_REG_CLR);
31	udelay(1);
32	while ((readl(addr) & mask) && --timeout)
33		/* nothing */;
34
35	return !timeout;
36}
37
38int stmp_reset_block(void __iomem *reset_addr)
39{
40	int ret;
41	int timeout = 0x400;
42
43	/* clear and poll SFTRST */
44	ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
45	if (unlikely(ret))
46		goto error;
47
48	/* clear CLKGATE */
49	writel(STMP_MODULE_CLKGATE, reset_addr + STMP_OFFSET_REG_CLR);
50
51	/* set SFTRST to reset the block */
52	writel(STMP_MODULE_SFTRST, reset_addr + STMP_OFFSET_REG_SET);
53	udelay(1);
54
55	/* poll CLKGATE becoming set */
56	while ((!(readl(reset_addr) & STMP_MODULE_CLKGATE)) && --timeout)
57		/* nothing */;
58	if (unlikely(!timeout))
59		goto error;
60
61	/* clear and poll SFTRST */
62	ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
63	if (unlikely(ret))
64		goto error;
65
66	/* clear and poll CLKGATE */
67	ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_CLKGATE);
68	if (unlikely(ret))
69		goto error;
70
71	return 0;
72
73error:
74	pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
75	return -ETIMEDOUT;
76}
77EXPORT_SYMBOL(stmp_reset_block);
 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/compiler.h>
19#include <linux/export.h>
20#include <linux/stmp_device.h>
21
22#define STMP_MODULE_CLKGATE	(1 << 30)
23#define STMP_MODULE_SFTRST	(1 << 31)
24
25/*
26 * Clear the bit and poll it cleared.  This is usually called with
27 * a reset address and mask being either SFTRST(bit 31) or CLKGATE
28 * (bit 30).
29 */
30static int stmp_clear_poll_bit(void __iomem *addr, u32 mask)
31{
32	int timeout = 0x400;
33
34	writel(mask, addr + STMP_OFFSET_REG_CLR);
35	udelay(1);
36	while ((readl(addr) & mask) && --timeout)
37		/* nothing */;
38
39	return !timeout;
40}
41
42int stmp_reset_block(void __iomem *reset_addr)
43{
44	int ret;
45	int timeout = 0x400;
46
47	/* clear and poll SFTRST */
48	ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
49	if (unlikely(ret))
50		goto error;
51
52	/* clear CLKGATE */
53	writel(STMP_MODULE_CLKGATE, reset_addr + STMP_OFFSET_REG_CLR);
54
55	/* set SFTRST to reset the block */
56	writel(STMP_MODULE_SFTRST, reset_addr + STMP_OFFSET_REG_SET);
57	udelay(1);
58
59	/* poll CLKGATE becoming set */
60	while ((!(readl(reset_addr) & STMP_MODULE_CLKGATE)) && --timeout)
61		/* nothing */;
62	if (unlikely(!timeout))
63		goto error;
64
65	/* clear and poll SFTRST */
66	ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST);
67	if (unlikely(ret))
68		goto error;
69
70	/* clear and poll CLKGATE */
71	ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_CLKGATE);
72	if (unlikely(ret))
73		goto error;
74
75	return 0;
76
77error:
78	pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
79	return -ETIMEDOUT;
80}
81EXPORT_SYMBOL(stmp_reset_block);