2 * Copyright 2006 Freescale Semiconductor
4 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <asm/cache.h>
30 #ifdef CONFIG_FSL_PIXIS
35 static ulong strfractoint(uchar *strptr);
41 void pixis_reset(void)
43 out8(PIXIS_BASE + PIXIS_RST, 0);
48 * Per table 27, page 58 of MPC8641HPCN spec.
50 int set_px_sysclk(ulong sysclk)
52 u8 sysclk_s, sysclk_r, sysclk_v, vclkh, vclkl, sysclk_aux;
104 printf("Unsupported SYSCLK frequency.\n");
108 vclkh = (sysclk_s << 5) | sysclk_r;
111 out8(PIXIS_BASE + PIXIS_VCLKH, vclkh);
112 out8(PIXIS_BASE + PIXIS_VCLKL, vclkl);
114 out8(PIXIS_BASE + PIXIS_AUX, sysclk_aux);
120 int set_px_mpxpll(ulong mpxpll)
137 printf("Unsupported MPXPLL ratio.\n");
141 tmp = in8(PIXIS_BASE + PIXIS_VSPEED1);
142 tmp = (tmp & 0xF0) | (val & 0x0F);
143 out8(PIXIS_BASE + PIXIS_VSPEED1, tmp);
149 int set_px_corepll(ulong corepll)
154 switch ((int)corepll) {
174 printf("Unsupported COREPLL ratio.\n");
178 tmp = in8(PIXIS_BASE + PIXIS_VSPEED0);
179 tmp = (tmp & 0xE0) | (val & 0x1F);
180 out8(PIXIS_BASE + PIXIS_VSPEED0, tmp);
186 void read_from_px_regs(int set)
189 u8 tmp = in8(PIXIS_BASE + PIXIS_VCFGEN0);
195 out8(PIXIS_BASE + PIXIS_VCFGEN0, tmp);
199 void read_from_px_regs_altbank(int set)
202 u8 tmp = in8(PIXIS_BASE + PIXIS_VCFGEN1);
208 out8(PIXIS_BASE + PIXIS_VCFGEN1, tmp);
212 void set_altbank(void)
216 tmp = in8(PIXIS_BASE + PIXIS_VBOOT);
219 out8(PIXIS_BASE + PIXIS_VBOOT, tmp);
227 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
229 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
231 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
233 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
237 void set_px_go_with_watchdog(void)
241 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
243 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
245 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
247 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
251 int pixis_disable_watchdog_cmd(cmd_tbl_t *cmdtp,
252 int flag, int argc, char *argv[])
256 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
258 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
260 /* setting VCTL[WDEN] to 0 to disable watch dog */
261 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
263 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
269 diswd, 1, 0, pixis_disable_watchdog_cmd,
270 "diswd - Disable watchdog timer \n",
274 * This function takes the non-integral cpu:mpx pll ratio
275 * and converts it to an integer that can be used to assign
276 * FPGA register values.
277 * input: strptr i.e. argv[2]
280 static ulong strfractoint(uchar *strptr)
284 int intarr_len = 0, decarr_len = 0, no_dec = 0;
285 ulong intval = 0, decval = 0;
286 uchar intarr[3], decarr[3];
288 /* Assign the integer part to intarr[]
289 * If there is no decimal point i.e.
290 * if the ratio is an integral value
291 * simply create the intarr.
294 while (strptr[i] != 46) {
295 if (strptr[i] == 0) {
299 intarr[i] = strptr[i];
303 /* Assign length of integer part to intarr_len. */
308 /* Currently needed only for single digit corepll ratios */
313 i++; /* Skipping the decimal point */
314 while ((strptr[i] > 47) && (strptr[i] < 58)) {
315 decarr[j] = strptr[i];
324 for (i = 0; i < decarr_len; i++)
326 decval = simple_strtoul((char *)decarr, NULL, 10);
329 intval = simple_strtoul((char *)intarr, NULL, 10);
330 intval = intval * mulconst;
332 retval = intval + decval;
339 pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
345 * No args is a simple reset request.
352 if (strcmp(argv[1], "cf") == 0) {
355 * Reset with frequency changed:
356 * cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>
363 read_from_px_regs(0);
365 val = set_px_sysclk(simple_strtoul(argv[2], NULL, 10));
367 corepll = strfractoint((uchar *)argv[3]);
368 val = val + set_px_corepll(corepll);
369 val = val + set_px_mpxpll(simple_strtoul(argv[4], NULL, 10));
371 puts("Setting registers VCFGEN0 and VCTL\n");
372 read_from_px_regs(1);
373 puts("Resetting board with values from ");
374 puts("VSPEED0, VSPEED1, VCLKH, and VCLKL \n");
381 while (1) ; /* Not reached */
383 } else if (strcmp(argv[1], "altbank") == 0) {
386 * Reset using alternate flash bank:
390 * Reset from alternate bank without changing
391 * frequency and without watchdog timer enabled.
394 read_from_px_regs(0);
395 read_from_px_regs_altbank(0);
400 puts("Setting registers VCFGNE1, VBOOT, and VCTL\n");
402 read_from_px_regs_altbank(1);
403 puts("Resetting board to boot from the other bank.\n");
406 } else if (strcmp(argv[2], "cf") == 0) {
408 * Reset with frequency changed
409 * altbank cf <SYSCLK freq> <COREPLL ratio>
412 read_from_px_regs(0);
413 read_from_px_regs_altbank(0);
414 val = set_px_sysclk(simple_strtoul(argv[3], NULL, 10));
415 corepll = strfractoint((uchar *)argv[4]);
416 val = val + set_px_corepll(corepll);
417 val = val + set_px_mpxpll(simple_strtoul(argv[5],
420 puts("Setting registers VCFGEN0, VCFGEN1, VBOOT, and VCTL\n");
422 read_from_px_regs(1);
423 read_from_px_regs_altbank(1);
424 puts("Enabling watchdog timer on the FPGA\n");
425 puts("Resetting board with values from ");
426 puts("VSPEED0, VSPEED1, VCLKH and VCLKL ");
427 puts("to boot from the other bank.\n");
428 set_px_go_with_watchdog();
434 while (1) ; /* Not reached */
436 } else if (strcmp(argv[2], "wd") == 0) {
438 * Reset from alternate bank without changing
439 * frequencies but with watchdog timer enabled:
442 read_from_px_regs(0);
443 read_from_px_regs_altbank(0);
444 puts("Setting registers VCFGEN1, VBOOT, and VCTL\n");
446 read_from_px_regs_altbank(1);
447 puts("Enabling watchdog timer on the FPGA\n");
448 puts("Resetting board to boot from the other bank.\n");
449 set_px_go_with_watchdog();
450 while (1) ; /* Not reached */
467 pixis_reset, CFG_MAXARGS, 1, pixis_reset_cmd,
468 "pixis_reset - Reset the board using the FPGA sequencer\n",
470 " pixis_reset [altbank]\n"
471 " pixis_reset altbank wd\n"
472 " pixis_reset altbank cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
473 " pixis_reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
475 #endif /* CONFIG_FSL_PIXIS */