blob: bdddf5ca67c47a73843d59ceab71ea6f018631d2 [file] [log] [blame]
Paul Walmsleycf214052010-09-21 10:34:10 -06001/*
2 * OMAP2/3 PRM module functions
3 *
Paul Walmsley26c98c52011-12-16 14:36:58 -07004 * Copyright (C) 2010-2011 Texas Instruments, Inc.
Paul Walmsleycf214052010-09-21 10:34:10 -06005 * Copyright (C) 2010 Nokia Corporation
6 * BenoƮt Cousson
7 * Paul Walmsley
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 version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/kernel.h>
Paul Walmsleycf214052010-09-21 10:34:10 -060015#include <linux/errno.h>
16#include <linux/err.h>
Paul Walmsley59fb6592010-12-21 15:30:55 -070017#include <linux/io.h>
Paul Walmsleycf214052010-09-21 10:34:10 -060018
Tony Lindgrendbc04162012-08-31 10:59:07 -070019#include "common.h"
Paul Walmsley49815392012-10-21 01:01:10 -060020#include "powerdomain.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070021#include "prm2xxx_3xxx.h"
Paul Walmsleycf214052010-09-21 10:34:10 -060022#include "prm-regbits-24xx.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070023
Paul Walmsleycf214052010-09-21 10:34:10 -060024/**
25 * omap2_prm_is_hardreset_asserted - read the HW reset line state of
26 * submodules contained in the hwmod module
27 * @prm_mod: PRM submodule base (e.g. CORE_MOD)
28 * @shift: register bit shift corresponding to the reset line to check
29 *
30 * Returns 1 if the (sub)module hardreset line is currently asserted,
31 * 0 if the (sub)module hardreset line is not currently asserted, or
32 * -EINVAL if called while running on a non-OMAP2/3 chip.
33 */
34int omap2_prm_is_hardreset_asserted(s16 prm_mod, u8 shift)
35{
Paul Walmsleyc4d7e582010-12-21 21:05:14 -070036 return omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL,
Paul Walmsleycf214052010-09-21 10:34:10 -060037 (1 << shift));
38}
39
40/**
41 * omap2_prm_assert_hardreset - assert the HW reset line of a submodule
42 * @prm_mod: PRM submodule base (e.g. CORE_MOD)
43 * @shift: register bit shift corresponding to the reset line to assert
44 *
45 * Some IPs like dsp or iva contain processors that require an HW
46 * reset line to be asserted / deasserted in order to fully enable the
47 * IP. These modules may have multiple hard-reset lines that reset
48 * different 'submodules' inside the IP block. This function will
49 * place the submodule into reset. Returns 0 upon success or -EINVAL
50 * upon an argument error.
51 */
52int omap2_prm_assert_hardreset(s16 prm_mod, u8 shift)
53{
54 u32 mask;
55
Paul Walmsleycf214052010-09-21 10:34:10 -060056 mask = 1 << shift;
Paul Walmsleyc4d7e582010-12-21 21:05:14 -070057 omap2_prm_rmw_mod_reg_bits(mask, mask, prm_mod, OMAP2_RM_RSTCTRL);
Paul Walmsleycf214052010-09-21 10:34:10 -060058
59 return 0;
60}
61
62/**
63 * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait
64 * @prm_mod: PRM submodule base (e.g. CORE_MOD)
omar ramirezcc1226e2011-03-04 13:32:44 -070065 * @rst_shift: register bit shift corresponding to the reset line to deassert
66 * @st_shift: register bit shift for the status of the deasserted submodule
Paul Walmsleycf214052010-09-21 10:34:10 -060067 *
68 * Some IPs like dsp or iva contain processors that require an HW
69 * reset line to be asserted / deasserted in order to fully enable the
70 * IP. These modules may have multiple hard-reset lines that reset
71 * different 'submodules' inside the IP block. This function will
72 * take the submodule out of reset and wait until the PRCM indicates
73 * that the reset has completed before returning. Returns 0 upon success or
74 * -EINVAL upon an argument error, -EEXIST if the submodule was already out
75 * of reset, or -EBUSY if the submodule did not exit reset promptly.
76 */
omar ramirezcc1226e2011-03-04 13:32:44 -070077int omap2_prm_deassert_hardreset(s16 prm_mod, u8 rst_shift, u8 st_shift)
Paul Walmsleycf214052010-09-21 10:34:10 -060078{
omar ramirezcc1226e2011-03-04 13:32:44 -070079 u32 rst, st;
Paul Walmsleycf214052010-09-21 10:34:10 -060080 int c;
81
omar ramirezcc1226e2011-03-04 13:32:44 -070082 rst = 1 << rst_shift;
83 st = 1 << st_shift;
Paul Walmsleycf214052010-09-21 10:34:10 -060084
85 /* Check the current status to avoid de-asserting the line twice */
omar ramirezcc1226e2011-03-04 13:32:44 -070086 if (omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, rst) == 0)
Paul Walmsleycf214052010-09-21 10:34:10 -060087 return -EEXIST;
88
89 /* Clear the reset status by writing 1 to the status bit */
omar ramirezcc1226e2011-03-04 13:32:44 -070090 omap2_prm_rmw_mod_reg_bits(0xffffffff, st, prm_mod, OMAP2_RM_RSTST);
Paul Walmsleycf214052010-09-21 10:34:10 -060091 /* de-assert the reset control line */
omar ramirezcc1226e2011-03-04 13:32:44 -070092 omap2_prm_rmw_mod_reg_bits(rst, 0, prm_mod, OMAP2_RM_RSTCTRL);
Paul Walmsleycf214052010-09-21 10:34:10 -060093 /* wait the status to be set */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -070094 omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST,
omar ramirezcc1226e2011-03-04 13:32:44 -070095 st),
Paul Walmsleycf214052010-09-21 10:34:10 -060096 MAX_MODULE_HARDRESET_WAIT, c);
97
98 return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
99}
Kevin Hilman58aaa592011-03-28 10:52:04 -0700100
Paul Walmsley49815392012-10-21 01:01:10 -0600101
102/* Powerdomain low-level functions */
103
104/* Common functions across OMAP2 and OMAP3 */
105int omap2_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
106{
107 omap2_prm_rmw_mod_reg_bits(OMAP_POWERSTATE_MASK,
108 (pwrst << OMAP_POWERSTATE_SHIFT),
109 pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL);
110 return 0;
111}
112
113int omap2_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
114{
115 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
116 OMAP2_PM_PWSTCTRL,
117 OMAP_POWERSTATE_MASK);
118}
119
120int omap2_pwrdm_read_pwrst(struct powerdomain *pwrdm)
121{
122 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
123 OMAP2_PM_PWSTST,
124 OMAP_POWERSTATEST_MASK);
125}
126
127int omap2_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
128 u8 pwrst)
129{
130 u32 m;
131
132 m = omap2_pwrdm_get_mem_bank_onstate_mask(bank);
133
134 omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
135 OMAP2_PM_PWSTCTRL);
136
137 return 0;
138}
139
140int omap2_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
141 u8 pwrst)
142{
143 u32 m;
144
145 m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
146
147 omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
148 OMAP2_PM_PWSTCTRL);
149
150 return 0;
151}
152
153int omap2_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
154{
155 u32 m;
156
157 m = omap2_pwrdm_get_mem_bank_stst_mask(bank);
158
159 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP2_PM_PWSTST,
160 m);
161}
162
163int omap2_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
164{
165 u32 m;
166
167 m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
168
169 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
170 OMAP2_PM_PWSTCTRL, m);
171}
172
173int omap2_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
174{
175 u32 v;
176
177 v = pwrst << __ffs(OMAP_LOGICRETSTATE_MASK);
178 omap2_prm_rmw_mod_reg_bits(OMAP_LOGICRETSTATE_MASK, v, pwrdm->prcm_offs,
179 OMAP2_PM_PWSTCTRL);
180
181 return 0;
182}
183
184int omap2_pwrdm_wait_transition(struct powerdomain *pwrdm)
185{
186 u32 c = 0;
187
188 /*
189 * REVISIT: pwrdm_wait_transition() may be better implemented
190 * via a callback and a periodic timer check -- how long do we expect
191 * powerdomain transitions to take?
192 */
193
194 /* XXX Is this udelay() value meaningful? */
195 while ((omap2_prm_read_mod_reg(pwrdm->prcm_offs, OMAP2_PM_PWSTST) &
196 OMAP_INTRANSITION_MASK) &&
197 (c++ < PWRDM_TRANSITION_BAILOUT))
198 udelay(1);
199
200 if (c > PWRDM_TRANSITION_BAILOUT) {
201 pr_err("powerdomain: %s: waited too long to complete transition\n",
202 pwrdm->name);
203 return -EAGAIN;
204 }
205
206 pr_debug("powerdomain: completed transition in %d loops\n", c);
207
208 return 0;
209}
210