Skip to content
Newer
Older
100644 295 lines (253 sloc) 8.86 KB
4bc042b initial public release v1.50
Patrick Titiano authored
1 /*
2 *
3 * @Component OMAPCONF
4 * @Filename prm54xx.h
5 * @Description OMAP5 PRM Registers Functions
6 * @Author Patrick Titiano (p-titiano@ti.com)
7 * @Date 2011
8 * @Copyright Texas Instruments Incorporated
9 *
10 *
11 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
12 *
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * Neither the name of Texas Instruments Incorporated nor the names of
27 * its contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 */
43
44
45 #include <prm54xx.h>
46 #include <cm54xx.h>
47 #include <lib.h>
48 #include <autoadjust_table.h>
49 #include <cpuinfo.h>
50 #include <module54xx.h>
51
52
53 /* #define PRM54XX_DEBUG */
54 #ifdef PRM54XX_DEBUG
55 #define dprintf(format, ...) printf(format, ## __VA_ARGS__)
56 #else
57 #define dprintf(format, ...)
58 #endif
59
60
61 /* ------------------------------------------------------------------------*//**
62 * @FUNCTION prm54xx_mod_name_get
63 * @BRIEF return PRM module name
64 * @RETURNS PRM module name
65 * NULL in case of incorrect id
66 * @param[in] id: PRM module ID
67 * @DESCRIPTION return PRM module name
68 *//*------------------------------------------------------------------------ */
69 const char *prm54xx_mod_name_get(prm54xx_mod_id id)
70 {
71 if (id >= PRM54XX_MODS_COUNT) {
72 fprintf(stderr, "%s(): id (%u) >= PRM54XX_MODS_COUNT (%u)!\n",
73 __func__, id, PRM54XX_MODS_COUNT);
74 return NULL;
75 }
76
77 return prm54xx_mods_name[id];
78 }
79
80
81 /* ------------------------------------------------------------------------*//**
82 * @FUNCTION prm54xx_is_profiling_running
83 * @BRIEF return 1 if profiling module (PMI) is running,
84 * 0 otherwise
85 * @RETURNS 1 if profiling module (PMI) is running,
86 * 0 otherwise
87 * @DESCRIPTION return 1 if profiling module (PMI) is running,
88 * 0 otherwise
89 *//*------------------------------------------------------------------------ */
90 unsigned int prm54xx_is_profiling_running(void)
91 {
92 reg *cm_clkctrl_reg = &omap5430_cm_prm_profiling_clkctrl;
93 unsigned int cm_clkctrl;
94
95 if (cm_clkctrl_reg == NULL) {
96 dprintf("%s(): cm_clkctrl_reg == NULL!!!\n", __func__);
97 return 0;
98 }
99
100 cm_clkctrl = reg_read(cm_clkctrl_reg);
101 return mod_is_accessible(cm_clkctrl);
102 }
103
104
105 /* ------------------------------------------------------------------------*//**
106 * @FUNCTION prm54xx_dump
107 * @BRIEF dump selected registers and pretty-print it in
108 * selected output stream
109 * @RETURNS 0 in case of success
110 * OMAPCONF_ERR_CPU
111 * OMAPCONF_ERR_ARG
112 * @param[in,out] stream: output stream
113 * @param[in] id: PRM module ID - If id == PRM54XX_MODS_COUNT,
114 * dump all PRM registers.
115 * @DESCRIPTION dump selected registers and pretty-print it in
116 * selected output stream
117 *//*------------------------------------------------------------------------ */
118 int prm54xx_dump(FILE *stream, prm54xx_mod_id id)
119 {
120 unsigned int i = 0, mid;
121 unsigned int val = 0;
122 int err = 0;
123 reg **mod;
124 reg *r;
125 char s[TABLE_MAX_ELT_LEN];
126 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
127 unsigned int row;
128
129
130 if (stream == NULL) {
131 fprintf(stderr, "%s(): stream == NULL!!!\n", __func__);
132 err = OMAPCONF_ERR_ARG;
133 goto prm54xx_dump_end;
134 }
135
136 if (id > PRM54XX_MODS_COUNT) {
137 fprintf(stderr, "%s(): id (%u) > PRM54XX_MODS_COUNT!!! (%u)\n",
138 __func__, id, PRM54XX_MODS_COUNT);
139 err = OMAPCONF_ERR_ARG;
140 goto prm54xx_dump_end;
141 }
142
143 autoadjust_table_init(table);
144 row = 0;
145
146 if (id != PRM54XX_MODS_COUNT)
147 snprintf(table[row][0], TABLE_MAX_ELT_LEN, "%s Reg. Name",
148 prm54xx_mod_name_get(id));
149 else
150 strncpy(table[row][0], "PRM Reg. Name", TABLE_MAX_ELT_LEN);
151 strncpy(table[row][1], "Reg. Address",
152 TABLE_MAX_ELT_LEN);
153 strncpy(table[row][2], "Reg. Value", TABLE_MAX_ELT_LEN);
154 row++;
155
156 for (mid = PRM54XX_DSS_PRM; mid < PRM54XX_MODS_COUNT; mid++) {
157 if ((id != PRM54XX_MODS_COUNT) && (mid != id))
158 continue;
159 else {
160 mod = prm54xx_mods[mid];
161 for (i = 0; mod[i] != NULL; i++) {
162 r = mod[i];
163 /* Read register */
164 val = reg_read(r);
165 /* Show register name, addr & content */
166 snprintf(s, TABLE_MAX_ELT_LEN, "%s", r->name);
167 autoadjust_table_strncpy(table, row, 0, s);
168
169 snprintf(s, TABLE_MAX_ELT_LEN, "0x%08X",
170 r->addr);
171 autoadjust_table_strncpy(table, row, 1, s);
172
173 snprintf(s, TABLE_MAX_ELT_LEN, "0x%08X", val);
174 autoadjust_table_strncpy(table, row++, 2, s);
175 }
176 }
177 }
178
179 autoadjust_table_print(table, row, 3);
180
181 prm54xx_dump_end:
182 return err;
183 }
184
185
186 /* ------------------------------------------------------------------------*//**
187 * @FUNCTION prm54xx_export
188 * @BRIEF export module register content to file, in XML format.
189 * @RETURNS 0 in case of success
190 * OMAPCONF_ERR_CPU
191 * OMAPCONF_ERR_ARG
192 * @param[in,out] fp: output file stream (opened for write operations)
193 * @param[in] id: PRM module ID
194 * @DESCRIPTION export module register content to file, in XML format.
195 *//*------------------------------------------------------------------------ */
196 int prm54xx_export(FILE *fp, prm54xx_mod_id id)
197 {
198 reg **mod;
199 unsigned int i;
200
201 CHECK_CPU(54xx, OMAPCONF_ERR_CPU);
202 CHECK_NULL_ARG(fp, OMAPCONF_ERR_ARG);
203 CHECK_ARG_LESS_THAN(id, PRM54XX_MODS_COUNT, OMAPCONF_ERR_ARG);
204
205 mod = prm54xx_mods[id];
206
207 if ((id == PRM54XX_INSTR_PRM) && !prm54xx_is_profiling_running()) {
208 dprintf("%s(%s): PRM module is not accessible, "
209 "don't export registers\n", __func__,
210 prm54xx_mod_name_get(id));
211 return 0;
212 }
213
214 fprintf(fp, " <submodule id=\"%u\" name=\"%s\">\n",
215 id, prm54xx_mod_name_get(id));
216
217 for (i = 0; mod[i] != NULL; i++)
218 fprintf(fp, " <register id=\"%u\" name=\"%s\" "
219 "addr=\"0x%08X\" data=\"0x%08X\" />\n", i,
220 reg_name_get(mod[i]), reg_addr_get(mod[i]),
221 reg_read(mod[i]));
222
223 fprintf(fp, " </submodule>\n");
224
225 return 0;
226 }
227
228
229 /* ------------------------------------------------------------------------*//**
230 * @FUNCTION prm54xx_import
231 * @BRIEF import OMAP PRM registers from XML file
232 * @RETURNS 0 in case of success
233 * OMAPCONF_ERR_ARG
234 * OMAPCONF_ERR_UNEXPECTED
235 * @param[in,out] fp: XML import file descriptor
236 * @param[in] id: CM module ID
237 * @DESCRIPTION import OMAP PRM registers from XML file,
238 * generated with lib54xx_export().
239 *//*------------------------------------------------------------------------ */
240 int prm54xx_import(FILE *fp, prm54xx_mod_id id)
241 {
242 reg **mod;
243 char line[256], sline[256];
244 char *xml_entry;
245 int ret, i, n;
246
247 CHECK_NULL_ARG(fp, OMAPCONF_ERR_ARG);
248 CHECK_ARG_LESS_THAN(id, PRM54XX_MODS_COUNT, OMAPCONF_ERR_ARG);
249
250 mod = prm54xx_mods[id];
251 rewind(fp);
252
253 /* Search for the PRM module tag */
254 sprintf(sline, "<submodule id=\"%u\" name=\"%s\">",
255 id, prm54xx_mod_name_get(id));
256 while (fgets(line, sizeof(line), fp) != NULL) {
257 if (strstr(line, sline) == NULL)
258 continue;
259 /* Import register content */
260 for (i = 0; mod[i] != NULL; i++) {
261 if (fgets(line, sizeof(line), fp) == NULL)
262 return OMAPCONF_ERR_UNEXPECTED;
263 line[strlen(line) - 1] = '\0'; /* remove ending '\n' */
264 xml_entry = strstr(line, "<"); /* remove spaces */
265
266 dprintf("%s(%u (%s)): xml_entry=%s\n", __func__, id,
267 prm54xx_mod_name_get(id), xml_entry);
268
269 /* Check register id is correct */
270 ret = sscanf(xml_entry, "<register id=\"%u\" %s",
271 &n, sline);
272 if (ret != 2) {
273 dprintf("%s(%u (%s)): could not get id\n",
274 __func__, id, prm54xx_mod_name_get(id));
275 return OMAPCONF_ERR_UNEXPECTED;
276 }
277 if (n != i) {
278 dprintf("%s(%u (%s)): register id does not "
279 "match! (n=%u, i=%u)\n", __func__, id,
280 prm54xx_mod_name_get(id), n, i);
281 return OMAPCONF_ERR_UNEXPECTED;
282 }
283
284 ret = reg_xml_import(mod[i], xml_entry);
285 if (ret != 0)
286 return ret;
287 }
288 dprintf("%s(%u (%s)): all registers imported.\n", __func__, id,
289 prm54xx_mod_name_get(id));
290 break;
291 }
292
293 return 0;
294 }
Something went wrong with that request. Please try again.