1cf21405fSPaul Walmsley /*
2cf21405fSPaul Walmsley  * OMAP2/3 PRM module functions
3cf21405fSPaul Walmsley  *
4cf21405fSPaul Walmsley  * Copyright (C) 2010 Texas Instruments, Inc.
5cf21405fSPaul Walmsley  * Copyright (C) 2010 Nokia Corporation
6cf21405fSPaul Walmsley  * Benoît Cousson
7cf21405fSPaul Walmsley  * Paul Walmsley
8cf21405fSPaul Walmsley  *
9cf21405fSPaul Walmsley  * This program is free software; you can redistribute it and/or modify
10cf21405fSPaul Walmsley  * it under the terms of the GNU General Public License version 2 as
11cf21405fSPaul Walmsley  * published by the Free Software Foundation.
12cf21405fSPaul Walmsley  */
13cf21405fSPaul Walmsley 
14cf21405fSPaul Walmsley #include <linux/kernel.h>
15cf21405fSPaul Walmsley #include <linux/delay.h>
16cf21405fSPaul Walmsley #include <linux/errno.h>
17cf21405fSPaul Walmsley #include <linux/err.h>
18cf21405fSPaul Walmsley 
19cf21405fSPaul Walmsley #include <plat/common.h>
20cf21405fSPaul Walmsley #include <plat/cpu.h>
21cf21405fSPaul Walmsley #include <plat/prcm.h>
22cf21405fSPaul Walmsley 
23cf21405fSPaul Walmsley #include "prm.h"
24cf21405fSPaul Walmsley #include "prm-regbits-24xx.h"
25cf21405fSPaul Walmsley #include "prm-regbits-34xx.h"
26cf21405fSPaul Walmsley 
27cf21405fSPaul Walmsley /**
28cf21405fSPaul Walmsley  * omap2_prm_is_hardreset_asserted - read the HW reset line state of
29cf21405fSPaul Walmsley  * submodules contained in the hwmod module
30cf21405fSPaul Walmsley  * @prm_mod: PRM submodule base (e.g. CORE_MOD)
31cf21405fSPaul Walmsley  * @shift: register bit shift corresponding to the reset line to check
32cf21405fSPaul Walmsley  *
33cf21405fSPaul Walmsley  * Returns 1 if the (sub)module hardreset line is currently asserted,
34cf21405fSPaul Walmsley  * 0 if the (sub)module hardreset line is not currently asserted, or
35cf21405fSPaul Walmsley  * -EINVAL if called while running on a non-OMAP2/3 chip.
36cf21405fSPaul Walmsley  */
37cf21405fSPaul Walmsley int omap2_prm_is_hardreset_asserted(s16 prm_mod, u8 shift)
38cf21405fSPaul Walmsley {
39cf21405fSPaul Walmsley 	if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
40cf21405fSPaul Walmsley 		return -EINVAL;
41cf21405fSPaul Walmsley 
42cf21405fSPaul Walmsley 	return prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL,
43cf21405fSPaul Walmsley 				       (1 << shift));
44cf21405fSPaul Walmsley }
45cf21405fSPaul Walmsley 
46cf21405fSPaul Walmsley /**
47cf21405fSPaul Walmsley  * omap2_prm_assert_hardreset - assert the HW reset line of a submodule
48cf21405fSPaul Walmsley  * @prm_mod: PRM submodule base (e.g. CORE_MOD)
49cf21405fSPaul Walmsley  * @shift: register bit shift corresponding to the reset line to assert
50cf21405fSPaul Walmsley  *
51cf21405fSPaul Walmsley  * Some IPs like dsp or iva contain processors that require an HW
52cf21405fSPaul Walmsley  * reset line to be asserted / deasserted in order to fully enable the
53cf21405fSPaul Walmsley  * IP.  These modules may have multiple hard-reset lines that reset
54cf21405fSPaul Walmsley  * different 'submodules' inside the IP block.  This function will
55cf21405fSPaul Walmsley  * place the submodule into reset.  Returns 0 upon success or -EINVAL
56cf21405fSPaul Walmsley  * upon an argument error.
57cf21405fSPaul Walmsley  */
58cf21405fSPaul Walmsley int omap2_prm_assert_hardreset(s16 prm_mod, u8 shift)
59cf21405fSPaul Walmsley {
60cf21405fSPaul Walmsley 	u32 mask;
61cf21405fSPaul Walmsley 
62cf21405fSPaul Walmsley 	if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
63cf21405fSPaul Walmsley 		return -EINVAL;
64cf21405fSPaul Walmsley 
65cf21405fSPaul Walmsley 	mask = 1 << shift;
66cf21405fSPaul Walmsley 	prm_rmw_mod_reg_bits(mask, mask, prm_mod, OMAP2_RM_RSTCTRL);
67cf21405fSPaul Walmsley 
68cf21405fSPaul Walmsley 	return 0;
69cf21405fSPaul Walmsley }
70cf21405fSPaul Walmsley 
71cf21405fSPaul Walmsley /**
72cf21405fSPaul Walmsley  * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait
73cf21405fSPaul Walmsley  * @prm_mod: PRM submodule base (e.g. CORE_MOD)
74cf21405fSPaul Walmsley  * @shift: register bit shift corresponding to the reset line to deassert
75cf21405fSPaul Walmsley  *
76cf21405fSPaul Walmsley  * Some IPs like dsp or iva contain processors that require an HW
77cf21405fSPaul Walmsley  * reset line to be asserted / deasserted in order to fully enable the
78cf21405fSPaul Walmsley  * IP.  These modules may have multiple hard-reset lines that reset
79cf21405fSPaul Walmsley  * different 'submodules' inside the IP block.  This function will
80cf21405fSPaul Walmsley  * take the submodule out of reset and wait until the PRCM indicates
81cf21405fSPaul Walmsley  * that the reset has completed before returning.  Returns 0 upon success or
82cf21405fSPaul Walmsley  * -EINVAL upon an argument error, -EEXIST if the submodule was already out
83cf21405fSPaul Walmsley  * of reset, or -EBUSY if the submodule did not exit reset promptly.
84cf21405fSPaul Walmsley  */
85cf21405fSPaul Walmsley int omap2_prm_deassert_hardreset(s16 prm_mod, u8 shift)
86cf21405fSPaul Walmsley {
87cf21405fSPaul Walmsley 	u32 mask;
88cf21405fSPaul Walmsley 	int c;
89cf21405fSPaul Walmsley 
90cf21405fSPaul Walmsley 	if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
91cf21405fSPaul Walmsley 		return -EINVAL;
92cf21405fSPaul Walmsley 
93cf21405fSPaul Walmsley 	mask = 1 << shift;
94cf21405fSPaul Walmsley 
95cf21405fSPaul Walmsley 	/* Check the current status to avoid de-asserting the line twice */
96cf21405fSPaul Walmsley 	if (prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, mask) == 0)
97cf21405fSPaul Walmsley 		return -EEXIST;
98cf21405fSPaul Walmsley 
99cf21405fSPaul Walmsley 	/* Clear the reset status by writing 1 to the status bit */
100cf21405fSPaul Walmsley 	prm_rmw_mod_reg_bits(0xffffffff, mask, prm_mod, OMAP2_RM_RSTST);
101cf21405fSPaul Walmsley 	/* de-assert the reset control line */
102cf21405fSPaul Walmsley 	prm_rmw_mod_reg_bits(mask, 0, prm_mod, OMAP2_RM_RSTCTRL);
103cf21405fSPaul Walmsley 	/* wait the status to be set */
104cf21405fSPaul Walmsley 	omap_test_timeout(prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST,
105cf21405fSPaul Walmsley 						  mask),
106cf21405fSPaul Walmsley 			  MAX_MODULE_HARDRESET_WAIT, c);
107cf21405fSPaul Walmsley 
108cf21405fSPaul Walmsley 	return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
109cf21405fSPaul Walmsley }
110cf21405fSPaul Walmsley 
111