xref: /openbmc/u-boot/cmd/mfsl.c (revision 2399e401)
1 /*
2  * (C) Copyright 2007 Michal Simek
3  *
4  * Michal  SIMEK <monstr@monstr.eu>
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 
9 /*
10  * Microblaze FSL support
11  */
12 
13 #include <common.h>
14 #include <config.h>
15 #include <command.h>
16 #include <asm/asm.h>
17 
18 int do_frd (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
19 {
20 	unsigned int fslnum;
21 	unsigned int num;
22 	unsigned int blocking;
23 
24 	if (argc < 2)
25 		return CMD_RET_USAGE;
26 
27 	fslnum = (unsigned int)simple_strtoul (argv[1], NULL, 16);
28 	blocking = (unsigned int)simple_strtoul (argv[2], NULL, 16);
29 	if (fslnum < 0 || fslnum >= XILINX_FSL_NUMBER) {
30 		puts ("Bad number of FSL\n");
31 		return CMD_RET_USAGE;
32 	}
33 
34 	switch (fslnum) {
35 #if (XILINX_FSL_NUMBER > 0)
36 	case 0:
37 		switch (blocking) {
38 		case 0:	NGET (num, 0);
39 			break;
40 		case 1:	NCGET (num, 0);
41 			break;
42 		case 2:	GET (num, 0);
43 			break;
44 		case 3:	CGET (num, 0);
45 			break;
46 		default:
47 			return 2;
48 		}
49 		break;
50 #endif
51 #if (XILINX_FSL_NUMBER > 1)
52 	case 1:
53 		switch (blocking) {
54 		case 0:	NGET (num, 1);
55 			break;
56 		case 1:	NCGET (num, 1);
57 			break;
58 		case 2:	GET (num, 1);
59 			break;
60 		case 3:	CGET (num, 1);
61 			break;
62 		default:
63 			return 2;
64 		}
65 		break;
66 #endif
67 #if (XILINX_FSL_NUMBER > 2)
68 	case 2:
69 		switch (blocking) {
70 		case 0:	NGET (num, 2);
71 			break;
72 		case 1:	NCGET (num, 2);
73 			break;
74 		case 2:	GET (num, 2);
75 			break;
76 		case 3:	CGET (num, 2);
77 			break;
78 		default:
79 			return 2;
80 		}
81 		break;
82 #endif
83 #if (XILINX_FSL_NUMBER > 3)
84 	case 3:
85 		switch (blocking) {
86 		case 0:	NGET (num, 3);
87 			break;
88 		case 1:	NCGET (num, 3);
89 			break;
90 		case 2:	GET (num, 3);
91 			break;
92 		case 3:	CGET (num, 3);
93 			break;
94 		default:
95 			return 2;
96 		}
97 		break;
98 #endif
99 #if (XILINX_FSL_NUMBER > 4)
100 	case 4:
101 		switch (blocking) {
102 		case 0:	NGET (num, 4);
103 			break;
104 		case 1:	NCGET (num, 4);
105 			break;
106 		case 2:	GET (num, 4);
107 			break;
108 		case 3:	CGET (num, 4);
109 			break;
110 		default:
111 			return 2;
112 		}
113 		break;
114 #endif
115 #if (XILINX_FSL_NUMBER > 5)
116 	case 5:
117 		switch (blocking) {
118 		case 0:	NGET (num, 5);
119 			break;
120 		case 1:	NCGET (num, 5);
121 			break;
122 		case 2:	GET (num, 5);
123 			break;
124 		case 3:	CGET (num, 5);
125 			break;
126 		default:
127 			return 2;
128 		}
129 		break;
130 #endif
131 #if (XILINX_FSL_NUMBER > 6)
132 	case 6:
133 		switch (blocking) {
134 		case 0:	NGET (num, 6);
135 			break;
136 		case 1:	NCGET (num, 6);
137 			break;
138 		case 2:	GET (num, 6);
139 			break;
140 		case 3:	CGET (num, 6);
141 			break;
142 		default:
143 			return 2;
144 		}
145 		break;
146 #endif
147 #if (XILINX_FSL_NUMBER > 7)
148 	case 7:
149 		switch (blocking) {
150 		case 0:	NGET (num, 7);
151 			break;
152 		case 1:	NCGET (num, 7);
153 			break;
154 		case 2:	GET (num, 7);
155 			break;
156 		case 3:	CGET (num, 7);
157 			break;
158 		default:
159 			return 2;
160 		}
161 		break;
162 #endif
163 	default:
164 		return 1;
165 	}
166 
167 	printf ("%01x: 0x%08x - %s %s read\n", fslnum, num,
168 		blocking < 2  ? "non blocking" : "blocking",
169 		((blocking == 1) || (blocking == 3)) ? "control" : "data" );
170 	return 0;
171 }
172 
173 int do_fwr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
174 {
175 	unsigned int fslnum;
176 	unsigned int num;
177 	unsigned int blocking;
178 
179 	if (argc < 3)
180 		return CMD_RET_USAGE;
181 
182 	fslnum = (unsigned int)simple_strtoul (argv[1], NULL, 16);
183 	num = (unsigned int)simple_strtoul (argv[2], NULL, 16);
184 	blocking = (unsigned int)simple_strtoul (argv[3], NULL, 16);
185 	if (fslnum < 0 || fslnum >= XILINX_FSL_NUMBER)
186 		return CMD_RET_USAGE;
187 
188 	switch (fslnum) {
189 #if (XILINX_FSL_NUMBER > 0)
190 	case 0:
191 		switch (blocking) {
192 		case 0:	NPUT (num, 0);
193 			break;
194 		case 1:	NCPUT (num, 0);
195 			break;
196 		case 2:	PUT (num, 0);
197 			break;
198 		case 3:	CPUT (num, 0);
199 			break;
200 		default:
201 			return 2;
202 		}
203 		break;
204 #endif
205 #if (XILINX_FSL_NUMBER > 1)
206 	case 1:
207 		switch (blocking) {
208 		case 0:	NPUT (num, 1);
209 			break;
210 		case 1:	NCPUT (num, 1);
211 			break;
212 		case 2:	PUT (num, 1);
213 			break;
214 		case 3:	CPUT (num, 1);
215 			break;
216 		default:
217 			return 2;
218 		}
219 		break;
220 #endif
221 #if (XILINX_FSL_NUMBER > 2)
222 	case 2:
223 		switch (blocking) {
224 		case 0:	NPUT (num, 2);
225 			break;
226 		case 1:	NCPUT (num, 2);
227 			break;
228 		case 2:	PUT (num, 2);
229 			break;
230 		case 3:	CPUT (num, 2);
231 			break;
232 		default:
233 			return 2;
234 		}
235 		break;
236 #endif
237 #if (XILINX_FSL_NUMBER > 3)
238 	case 3:
239 		switch (blocking) {
240 		case 0:	NPUT (num, 3);
241 			break;
242 		case 1:	NCPUT (num, 3);
243 			break;
244 		case 2:	PUT (num, 3);
245 			break;
246 		case 3:	CPUT (num, 3);
247 			break;
248 		default:
249 			return 2;
250 		}
251 		break;
252 #endif
253 #if (XILINX_FSL_NUMBER > 4)
254 	case 4:
255 		switch (blocking) {
256 		case 0:	NPUT (num, 4);
257 			break;
258 		case 1:	NCPUT (num, 4);
259 			break;
260 		case 2:	PUT (num, 4);
261 			break;
262 		case 3:	CPUT (num, 4);
263 			break;
264 		default:
265 			return 2;
266 		}
267 		break;
268 #endif
269 #if (XILINX_FSL_NUMBER > 5)
270 	case 5:
271 		switch (blocking) {
272 		case 0:	NPUT (num, 5);
273 			break;
274 		case 1:	NCPUT (num, 5);
275 			break;
276 		case 2:	PUT (num, 5);
277 			break;
278 		case 3:	CPUT (num, 5);
279 			break;
280 		default:
281 			return 2;
282 		}
283 		break;
284 #endif
285 #if (XILINX_FSL_NUMBER > 6)
286 	case 6:
287 		switch (blocking) {
288 		case 0:	NPUT (num, 6);
289 			break;
290 		case 1:	NCPUT (num, 6);
291 			break;
292 		case 2:	PUT (num, 6);
293 			break;
294 		case 3:	CPUT (num, 6);
295 			break;
296 		default:
297 			return 2;
298 		}
299 		break;
300 #endif
301 #if (XILINX_FSL_NUMBER > 7)
302 	case 7:
303 		switch (blocking) {
304 		case 0:	NPUT (num, 7);
305 			break;
306 		case 1:	NCPUT (num, 7);
307 			break;
308 		case 2:	PUT (num, 7);
309 			break;
310 		case 3:	CPUT (num, 7);
311 			break;
312 		default:
313 			return 2;
314 		}
315 		break;
316 #endif
317 	default:
318 		return 1;
319 	}
320 
321 	printf ("%01x: 0x%08x - %s %s write\n", fslnum, num,
322 		blocking < 2  ? "non blocking" : "blocking",
323 		((blocking == 1) || (blocking == 3)) ? "control" : "data" );
324 	return 0;
325 
326 }
327 
328 int do_rspr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
329 {
330 	unsigned int reg = 0;
331 	unsigned int val = 0;
332 
333 	if (argc < 2)
334 		return CMD_RET_USAGE;
335 
336 	reg = (unsigned int)simple_strtoul (argv[1], NULL, 16);
337 	val = (unsigned int)simple_strtoul (argv[2], NULL, 16);
338 	switch (reg) {
339 	case 0x1:
340 		if (argc > 2) {
341 			MTS (val, rmsr);
342 			NOP;
343 			MFS (val, rmsr);
344 		} else {
345 			MFS (val, rmsr);
346 		}
347 		puts ("MSR");
348 		break;
349 	case 0x3:
350 		MFS (val, rear);
351 		puts ("EAR");
352 		break;
353 	case 0x5:
354 		MFS (val, resr);
355 		puts ("ESR");
356 		break;
357 	default:
358 		puts ("Unsupported register\n");
359 		return 1;
360 	}
361 	printf (": 0x%08x\n", val);
362 	return 0;
363 }
364 
365 /***************************************************/
366 
367 U_BOOT_CMD (frd, 3, 1, do_frd,
368 		"read data from FSL",
369 		"- [fslnum [0|1|2|3]]\n"
370 		" 0 - non blocking data read\n"
371 		" 1 - non blocking control read\n"
372 		" 2 - blocking data read\n"
373 		" 3 - blocking control read");
374 
375 U_BOOT_CMD (fwr, 4, 1, do_fwr,
376 		"write data to FSL",
377 		"- [fslnum [0|1|2|3]]\n"
378 		" 0 - non blocking data write\n"
379 		" 1 - non blocking control write\n"
380 		" 2 - blocking data write\n"
381 		" 3 - blocking control write");
382 
383 U_BOOT_CMD (rspr, 3, 1, do_rspr,
384 		"read/write special purpose register",
385 		"- reg_num [write value] read/write special purpose register\n"
386 		" 1 - MSR - Machine status register\n"
387 		" 3 - EAR - Exception address register\n"
388 		" 5 - ESR - Exception status register");
389