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,
29 #ifdef CONFIG_FSL_PIXIS
30 #include <asm/cache.h>
34 static ulong strfractoint(uchar *strptr);
40 void pixis_reset(void)
42 out8(PIXIS_BASE + PIXIS_RST, 0);
47 * Per table 27, page 58 of MPC8641HPCN spec.
49 int set_px_sysclk(ulong sysclk)
51 u8 sysclk_s, sysclk_r, sysclk_v, vclkh, vclkl, sysclk_aux;
103 printf("Unsupported SYSCLK frequency.\n");
107 vclkh = (sysclk_s << 5) | sysclk_r;
110 out8(PIXIS_BASE + PIXIS_VCLKH, vclkh);
111 out8(PIXIS_BASE + PIXIS_VCLKL, vclkl);
113 out8(PIXIS_BASE + PIXIS_AUX, sysclk_aux);
119 int set_px_mpxpll(ulong mpxpll)
136 printf("Unsupported MPXPLL ratio.\n");
140 tmp = in8(PIXIS_BASE + PIXIS_VSPEED1);
141 tmp = (tmp & 0xF0) | (val & 0x0F);
142 out8(PIXIS_BASE + PIXIS_VSPEED1, tmp);
148 int set_px_corepll(ulong corepll)
153 switch ((int)corepll) {
173 printf("Unsupported COREPLL ratio.\n");
177 tmp = in8(PIXIS_BASE + PIXIS_VSPEED0);
178 tmp = (tmp & 0xE0) | (val & 0x1F);
179 out8(PIXIS_BASE + PIXIS_VSPEED0, tmp);
185 void read_from_px_regs(int set)
188 u8 tmp = in8(PIXIS_BASE + PIXIS_VCFGEN0);
194 out8(PIXIS_BASE + PIXIS_VCFGEN0, tmp);
198 void read_from_px_regs_altbank(int set)
201 u8 tmp = in8(PIXIS_BASE + PIXIS_VCFGEN1);
207 out8(PIXIS_BASE + PIXIS_VCFGEN1, tmp);
211 void set_altbank(void)
215 tmp = in8(PIXIS_BASE + PIXIS_VBOOT);
218 out8(PIXIS_BASE + PIXIS_VBOOT, tmp);
226 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
228 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
230 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
232 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
236 void set_px_go_with_watchdog(void)
240 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
242 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
244 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
246 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
250 int pixis_disable_watchdog_cmd(cmd_tbl_t *cmdtp,
251 int flag, int argc, char *argv[])
255 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
257 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
259 /* setting VCTL[WDEN] to 0 to disable watch dog */
260 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
262 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
268 diswd, 1, 0, pixis_disable_watchdog_cmd,
269 "diswd - Disable watchdog timer \n",
273 * This function takes the non-integral cpu:mpx pll ratio
274 * and converts it to an integer that can be used to assign
275 * FPGA register values.
276 * input: strptr i.e. argv[2]
279 static ulong strfractoint(uchar *strptr)
283 int intarr_len = 0, decarr_len = 0, no_dec = 0;
284 ulong intval = 0, decval = 0;
285 uchar intarr[3], decarr[3];
287 /* Assign the integer part to intarr[]
288 * If there is no decimal point i.e.
289 * if the ratio is an integral value
290 * simply create the intarr.
293 while (strptr[i] != 46) {
294 if (strptr[i] == 0) {
298 intarr[i] = strptr[i];
302 /* Assign length of integer part to intarr_len. */
307 /* Currently needed only for single digit corepll ratios */
312 i++; /* Skipping the decimal point */
313 while ((strptr[i] > 47) && (strptr[i] < 58)) {
314 decarr[j] = strptr[i];
323 for (i = 0; i < decarr_len; i++)
325 decval = simple_strtoul((char *)decarr, NULL, 10);
328 intval = simple_strtoul((char *)intarr, NULL, 10);
329 intval = intval * mulconst;
331 retval = intval + decval;
338 pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
344 * No args is a simple reset request.
351 if (strcmp(argv[1], "cf") == 0) {
354 * Reset with frequency changed:
355 * cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>
362 read_from_px_regs(0);
364 val = set_px_sysclk(simple_strtoul(argv[2], NULL, 10));
366 corepll = strfractoint((uchar *)argv[3]);
367 val = val + set_px_corepll(corepll);
368 val = val + set_px_mpxpll(simple_strtoul(argv[4], NULL, 10));
370 puts("Setting registers VCFGEN0 and VCTL\n");
371 read_from_px_regs(1);
372 puts("Resetting board with values from ");
373 puts("VSPEED0, VSPEED1, VCLKH, and VCLKL \n");
380 while (1) ; /* Not reached */
382 } else if (strcmp(argv[1], "altbank") == 0) {
385 * Reset using alternate flash bank:
389 * Reset from alternate bank without changing
390 * frequency and without watchdog timer enabled.
393 read_from_px_regs(0);
394 read_from_px_regs_altbank(0);
399 puts("Setting registers VCFGNE1, VBOOT, and VCTL\n");
401 read_from_px_regs_altbank(1);
402 puts("Resetting board to boot from the other bank.\n");
405 } else if (strcmp(argv[2], "cf") == 0) {
407 * Reset with frequency changed
408 * altbank cf <SYSCLK freq> <COREPLL ratio>
411 read_from_px_regs(0);
412 read_from_px_regs_altbank(0);
413 val = set_px_sysclk(simple_strtoul(argv[3], NULL, 10));
414 corepll = strfractoint((uchar *)argv[4]);
415 val = val + set_px_corepll(corepll);
416 val = val + set_px_mpxpll(simple_strtoul(argv[5],
419 puts("Setting registers VCFGEN0, VCFGEN1, VBOOT, and VCTL\n");
421 read_from_px_regs(1);
422 read_from_px_regs_altbank(1);
423 puts("Enabling watchdog timer on the FPGA\n");
424 puts("Resetting board with values from ");
425 puts("VSPEED0, VSPEED1, VCLKH and VCLKL ");
426 puts("to boot from the other bank.\n");
427 set_px_go_with_watchdog();
433 while (1) ; /* Not reached */
435 } else if (strcmp(argv[2], "wd") == 0) {
437 * Reset from alternate bank without changing
438 * frequencies but with watchdog timer enabled:
441 read_from_px_regs(0);
442 read_from_px_regs_altbank(0);
443 puts("Setting registers VCFGEN1, VBOOT, and VCTL\n");
445 read_from_px_regs_altbank(1);
446 puts("Enabling watchdog timer on the FPGA\n");
447 puts("Resetting board to boot from the other bank.\n");
448 set_px_go_with_watchdog();
449 while (1) ; /* Not reached */
466 pixis_reset, CFG_MAXARGS, 1, pixis_reset_cmd,
467 "pixis_reset - Reset the board using the FPGA sequencer\n",
469 " pixis_reset [altbank]\n"
470 " pixis_reset altbank wd\n"
471 " pixis_reset altbank cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
472 " pixis_reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
474 #endif /* CONFIG_FSL_PIXIS */