Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 334 lines (294 sloc) 10.299 kB
4bc042b initial public release v1.50
Patrick Titiano authored
1 /*
2 *
3 * @Component OMAPCONF
4 * @Filename vp44xx.c
5 * @Description OMAP4 VOLTAGE PROCESSOR (VP) Definitions &
6 * Functions
7 * @Author Patrick Titiano (p-titiano@ti.com)
8 * @Date 2012
9 * @Copyright Texas Instruments Incorporated
10 *
11 *
12 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
13 *
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 *
19 * Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 *
22 * Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the
25 * distribution.
26 *
27 * Neither the name of Texas Instruments Incorporated nor the names of
28 * its contributors may be used to endorse or promote products derived
29 * from this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 */
44
45
46 #include <vp44xx.h>
47 #include <vp44xx-data.h>
48 #include <vp.h>
49 #include <lib.h>
50 #include <mem.h>
51 #include <cpuinfo.h>
52 #include <voltdm44xx.h>
53 #include <prm44xx.h>
54
55
56 /* #define VP44XX_DEBUG */
57 #ifdef VP44XX_DEBUG
58 #define dprintf(format, ...) printf(format, ## __VA_ARGS__)
59 #else
60 #define dprintf(format, ...)
61 #endif
62
63
64 /* ------------------------------------------------------------------------*//**
65 * @FUNCTION vp44xx_name_get
66 * @BRIEF return VP module name.
67 * @RETURNS VP module name on success
68 * "FIXME" string in case of error
69 * @param[in] vp_id: VP module ID
70 * @DESCRIPTION return VP module name.
71 *//*------------------------------------------------------------------------ */
72 const char *vp44xx_name_get(vp44xx_mod_id vp_id)
73 {
74 if (vp_id < VP44XX_ID_MAX)
75 return vp44xx_mod_names[vp_id];
76 else
77 return vp44xx_mod_names[VP44XX_ID_MAX];
78 }
79
80
81 /* ------------------------------------------------------------------------*//**
82 * @FUNCTION vp44xx_registers_get
83 * @BRIEF save VP registers content into vp_regs structure.
84 * @RETURNS 0 in case of success
85 * OMAPCONF_ERR_CPU
86 * OMAPCONF_ERR_ARG
87 * OMAPCONF_ERR_REG_ACCESS
88 * @param[in] vp_id: VP module ID
89 * @param[in,out] vp_regs: VP module registers content
90 * @DESCRIPTION save VP registers content into vp_regs structure.
91 *//*------------------------------------------------------------------------ */
92 int vp44xx_registers_get(vp44xx_mod_id vp_id, vp_registers *vp_regs)
93 {
94 int ret;
95
96 CHECK_CPU(44xx, OMAPCONF_ERR_CPU);
97 CHECK_ARG_LESS_THAN(vp_id, VP44XX_ID_MAX, OMAPCONF_ERR_ARG);
98 CHECK_NULL_ARG(vp_regs, OMAPCONF_ERR_ARG);
99
100 switch (vp_id) {
101 case VP44XX_MPU:
102 vp_regs->vdd_id = (unsigned short) OMAP4_VDD_MPU;
103 ret = mem_read(OMAP4430_PRM_VP_MPU_CONFIG,
104 &(vp_regs->vp_config));
105 ret += mem_read(OMAP4430_PRM_VP_MPU_VSTEPMIN,
106 &(vp_regs->vp_vstepmin));
107 ret += mem_read(OMAP4430_PRM_VP_MPU_VSTEPMAX,
108 &(vp_regs->vp_vstepmax));
109 ret += mem_read(OMAP4430_PRM_VP_MPU_VLIMITTO,
110 &(vp_regs->vp_vlimitto));
111 ret += mem_read(OMAP4430_PRM_VP_MPU_VOLTAGE,
112 &(vp_regs->vp_voltage));
113 ret += mem_read(OMAP4430_PRM_VP_MPU_STATUS,
114 &(vp_regs->vp_status));
115 break;
116
117 case VP44XX_IVA:
118 vp_regs->vdd_id = (unsigned short) OMAP4_VDD_IVA;
119 ret = mem_read(OMAP4430_PRM_VP_IVA_CONFIG,
120 &(vp_regs->vp_config));
121 ret += mem_read(OMAP4430_PRM_VP_IVA_VSTEPMIN,
122 &(vp_regs->vp_vstepmin));
123 ret += mem_read(OMAP4430_PRM_VP_IVA_VSTEPMAX,
124 &(vp_regs->vp_vstepmax));
125 ret += mem_read(OMAP4430_PRM_VP_IVA_VLIMITTO,
126 &(vp_regs->vp_vlimitto));
127 ret += mem_read(OMAP4430_PRM_VP_IVA_VOLTAGE,
128 &(vp_regs->vp_voltage));
129 ret += mem_read(OMAP4430_PRM_VP_IVA_STATUS,
130 &(vp_regs->vp_status));
131 break;
132
133 case VP44XX_CORE:
134 vp_regs->vdd_id = (unsigned short) OMAP4_VDD_CORE;
135 ret = mem_read(OMAP4430_PRM_VP_CORE_CONFIG,
136 &(vp_regs->vp_config));
137 ret += mem_read(OMAP4430_PRM_VP_CORE_VSTEPMIN,
138 &(vp_regs->vp_vstepmin));
139 ret += mem_read(OMAP4430_PRM_VP_CORE_VSTEPMAX,
140 &(vp_regs->vp_vstepmax));
141 ret += mem_read(OMAP4430_PRM_VP_CORE_VLIMITTO,
142 &(vp_regs->vp_vlimitto));
143 ret += mem_read(OMAP4430_PRM_VP_CORE_VOLTAGE,
144 &(vp_regs->vp_voltage));
145 ret += mem_read(OMAP4430_PRM_VP_CORE_STATUS,
146 &(vp_regs->vp_status));
147 break;
148
149 default:
150 ret = OMAPCONF_ERR_ARG;
151 }
152
153 return ret;
154 }
155
156
157 /* ------------------------------------------------------------------------*//**
158 * @FUNCTION vp44xx_golden_settings_get
159 * @BRIEF return VP module golden settings.
160 * @RETURNS VP module name on success
161 * "FIXME" string in case of error
162 * @param[in] vp_id: VP module ID
163 * @param[in] opp_id: OPP ID
164 * @DESCRIPTION return VP module golden settings, for a given chip,
165 * module and OPP.
166 *//*------------------------------------------------------------------------ */
167 const vp_audit_settings *vp44xx_golden_settings_get(vp44xx_mod_id vp_id,
168 opp44xx_id opp_id)
169 {
170 omap_chip chip_id;
171
172 CHECK_ARG_LESS_THAN(vp_id, VP44XX_ID_MAX, NULL);
173 CHECK_ARG_LESS_THAN(opp_id, OPP44XX_ID_MAX, NULL);
174
175 chip_id = cpu_get();
176 dprintf("%s(): vp_id=%d opp_id=%d chip_id=%d\n", __func__,
177 vp_id, opp_id, chip_id);
178 return vp44xx_golden_settings[chip_id][vp_id][opp_id];
179 }
180
181
182 /* ------------------------------------------------------------------------*//**
183 * @FUNCTION vp44xx_config_show
184 * @BRIEF decode and print Voltage Processor (VP) configuration
185 * @RETURNS 0 in case of success
186 * OMAPCONF_ERR_CPU
187 * OMAPCONF_ERR_REG_ACCESS
188 * @param[in] stream: output file (NULL: no output (silent))
189 * @DESCRIPTION decode and print Voltage Processor (VP) configuration
190 *//*------------------------------------------------------------------------ */
191 int vp44xx_config_show(FILE *stream)
192 {
193 int ret = 0;
194 vp_registers vp_regs[VP44XX_ID_MAX];
195
196 CHECK_CPU(44xx, OMAPCONF_ERR_CPU);
197
198 /* Read VP_MPU registers */
199 ret = vp44xx_registers_get(VP44XX_MPU, &(vp_regs[VP44XX_MPU]));
200 if (ret != 0)
201 return ret;
202
203 /* Read VP_IVA registers */
204 ret = vp44xx_registers_get(VP44XX_IVA, &(vp_regs[VP44XX_IVA]));
205 if (ret != 0)
206 return ret;
207
208 /* Read VP_CORE registers */
209 ret = vp44xx_registers_get(VP44XX_CORE, &(vp_regs[VP44XX_CORE]));
210 if (ret != 0)
211 return ret;
212
213 return vp_config_show(stream, vp_regs);
214 }
215
216
217 /* ------------------------------------------------------------------------*//**
218 * @FUNCTION vp44xx_config_audit
219 * @BRIEF audit Voltage Processor (VP) configuration
220 * @RETURNS 0 in case of success
221 * OMAPCONF_ERR_CPU
222 * OMAPCONF_ERR_ARG
223 * OMAPCONF_ERR_REG_ACCESS
224 * @param[in] stream: output file (NULL: no output (silent))
225 * @param[in] vp_id: VP module ID
226 * @param[in,out] err_nbr: audit error number
227 * @param[in,out] wng_nbr: audit warning number
228 * @DESCRIPTION audit Voltage Processor (VP) configuration by comparison
229 * with expected ("golden") settings
230 *//*------------------------------------------------------------------------ */
231 int vp44xx_config_audit(FILE *stream, vp44xx_mod_id vp_id,
232 unsigned int *err_nbr, unsigned int *wng_nbr)
233 {
234 int ret = 0;
235 vp_registers vp_regs;
236 const vp_audit_settings *vp_golden_settings;
237 vp44xx_mod_id vp;
238 opp44xx_id opp;
239 unsigned int err_cnt, wng_cnt;
240 char opp_name[OPP44XX_MAX_NAME_LENGTH];
241
242 CHECK_CPU(44xx, OMAPCONF_ERR_CPU);
243 CHECK_NULL_ARG(err_nbr, OMAPCONF_ERR_ARG);
244 CHECK_NULL_ARG(wng_nbr, OMAPCONF_ERR_ARG);
245 CHECK_ARG_LESS_THAN(vp_id, VP44XX_ID_MAX + 1, OMAPCONF_ERR_ARG);
246
247 *err_nbr = 0;
248 *wng_nbr = 0;
249 for (vp = VP44XX_MPU; vp < VP44XX_ID_MAX; vp++) {
250 if ((vp_id != VP44XX_ID_MAX) && (vp_id != vp))
251 continue;
252
253 dprintf("\n%s(): Auditing %s\n", __func__,
254 vp44xx_name_get(vp));
255 err_cnt = 0;
256 wng_cnt = 0;
257
258 /* Read VP registers */
259 ret = vp44xx_registers_get(vp, &vp_regs);
260 if (ret != 0) {
261 (*err_nbr) += 1;
262 return ret;
263 }
264
265 /* Get OPP */
266 switch (vp) {
267 case VP44XX_MPU:
268 ret = voltdm44xx_get_opp(OMAP4_VDD_MPU, &opp);
269 voltdm44xx_opp2string(opp_name, opp, OMAP4_VDD_MPU);
270 dprintf(" OPP is %s\n", opp_name);
271 break;
272
273 case VP44XX_IVA:
274 ret = voltdm44xx_get_opp(OMAP4_VDD_IVA, &opp);
275 voltdm44xx_opp2string(opp_name, opp, OMAP4_VDD_IVA);
276 dprintf(" OPP is %s\n", opp_name);
277 break;
278
279 case VP44XX_CORE:
280 ret = voltdm44xx_get_opp(OMAP4_VDD_CORE, &opp);
281 voltdm44xx_opp2string(opp_name, opp, OMAP4_VDD_CORE);
282 dprintf(" OPP is %s\n", opp_name);
283 break;
284
285 default:
286 (*err_nbr) += 1;
287 fprintf(stderr, "unexpected vp! (%u)\n", vp);
288 return OMAPCONF_ERR_UNEXPECTED;
289 }
290 if (ret != 0) {
291 (*wng_nbr) += 1;
292 if (stream != NULL) {
293 fprintf(stream, "Warning: could not find OPP"
294 ", audit cannot be run.\n");
295 }
296 continue;
297 }
298
299 /* Get expected ("golden") settings */
300 vp_golden_settings = vp44xx_golden_settings_get(vp, opp);
301 if (vp_golden_settings == NULL) {
302 (*wng_nbr) += 1;
303 if (stream != NULL) {
304 fprintf(stream, "Warning: could not find golden"
305 " settings, audit cannot be run.\n");
306 }
307 continue;
308 }
309
310 /* Audit settings */
311 ret = vp_config_audit(stream, vp44xx_name_get(vp), opp_name,
312 &vp_regs, vp_golden_settings, &err_cnt, &wng_cnt);
313 (*err_nbr) += err_cnt;
314 (*wng_nbr) += wng_cnt;
315 if (ret != 0)
316 return ret;
317 }
318
319 if (stream != NULL) {
320 if (*err_nbr == 0)
321 fprintf(stream,
322 "\nSUCCESS! VP Configuration Audit "
323 "completed with 0 error (%u warning(s)).\n\n",
324 *wng_nbr);
325 else
326 fprintf(stream,
327 "\nFAILED! VP Configuration Audit "
328 "completed with %u error(s) and %u warning(s)."
329 "\n\n", *err_nbr, *wng_nbr);
330 }
331
332 return ret;
333 }
Something went wrong with that request. Please try again.