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
);
210 #ifndef CFG_PIXIS_VBOOT_MASK
211 #define CFG_PIXIS_VBOOT_MASK 0x40
214 void set_altbank(void)
218 tmp
= in8(PIXIS_BASE
+ PIXIS_VBOOT
);
219 tmp
^= CFG_PIXIS_VBOOT_MASK
;
221 out8(PIXIS_BASE
+ PIXIS_VBOOT
, tmp
);
229 tmp
= in8(PIXIS_BASE
+ PIXIS_VCTL
);
231 out8(PIXIS_BASE
+ PIXIS_VCTL
, tmp
);
233 tmp
= in8(PIXIS_BASE
+ PIXIS_VCTL
);
235 out8(PIXIS_BASE
+ PIXIS_VCTL
, tmp
);
239 void set_px_go_with_watchdog(void)
243 tmp
= in8(PIXIS_BASE
+ PIXIS_VCTL
);
245 out8(PIXIS_BASE
+ PIXIS_VCTL
, tmp
);
247 tmp
= in8(PIXIS_BASE
+ PIXIS_VCTL
);
249 out8(PIXIS_BASE
+ PIXIS_VCTL
, tmp
);
253 int pixis_disable_watchdog_cmd(cmd_tbl_t
*cmdtp
,
254 int flag
, int argc
, char *argv
[])
258 tmp
= in8(PIXIS_BASE
+ PIXIS_VCTL
);
260 out8(PIXIS_BASE
+ PIXIS_VCTL
, tmp
);
262 /* setting VCTL[WDEN] to 0 to disable watch dog */
263 tmp
= in8(PIXIS_BASE
+ PIXIS_VCTL
);
265 out8(PIXIS_BASE
+ PIXIS_VCTL
, tmp
);
271 diswd
, 1, 0, pixis_disable_watchdog_cmd
,
272 "diswd - Disable watchdog timer \n",
276 * This function takes the non-integral cpu:mpx pll ratio
277 * and converts it to an integer that can be used to assign
278 * FPGA register values.
279 * input: strptr i.e. argv[2]
282 static ulong
strfractoint(uchar
*strptr
)
286 int intarr_len
= 0, decarr_len
= 0, no_dec
= 0;
287 ulong intval
= 0, decval
= 0;
288 uchar intarr
[3], decarr
[3];
290 /* Assign the integer part to intarr[]
291 * If there is no decimal point i.e.
292 * if the ratio is an integral value
293 * simply create the intarr.
296 while (strptr
[i
] != 46) {
297 if (strptr
[i
] == 0) {
301 intarr
[i
] = strptr
[i
];
305 /* Assign length of integer part to intarr_len. */
310 /* Currently needed only for single digit corepll ratios */
315 i
++; /* Skipping the decimal point */
316 while ((strptr
[i
] > 47) && (strptr
[i
] < 58)) {
317 decarr
[j
] = strptr
[i
];
326 for (i
= 0; i
< decarr_len
; i
++)
328 decval
= simple_strtoul((char *)decarr
, NULL
, 10);
331 intval
= simple_strtoul((char *)intarr
, NULL
, 10);
332 intval
= intval
* mulconst
;
334 retval
= intval
+ decval
;
341 pixis_reset_cmd(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
347 * No args is a simple reset request.
354 if (strcmp(argv
[1], "cf") == 0) {
357 * Reset with frequency changed:
358 * cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>
365 read_from_px_regs(0);
367 val
= set_px_sysclk(simple_strtoul(argv
[2], NULL
, 10));
369 corepll
= strfractoint((uchar
*)argv
[3]);
370 val
= val
+ set_px_corepll(corepll
);
371 val
= val
+ set_px_mpxpll(simple_strtoul(argv
[4], NULL
, 10));
373 puts("Setting registers VCFGEN0 and VCTL\n");
374 read_from_px_regs(1);
375 puts("Resetting board with values from ");
376 puts("VSPEED0, VSPEED1, VCLKH, and VCLKL \n");
383 while (1) ; /* Not reached */
385 } else if (strcmp(argv
[1], "altbank") == 0) {
388 * Reset using alternate flash bank:
392 * Reset from alternate bank without changing
393 * frequency and without watchdog timer enabled.
396 read_from_px_regs(0);
397 read_from_px_regs_altbank(0);
402 puts("Setting registers VCFGNE1, VBOOT, and VCTL\n");
404 read_from_px_regs_altbank(1);
405 puts("Resetting board to boot from the other bank.\n");
408 } else if (strcmp(argv
[2], "cf") == 0) {
410 * Reset with frequency changed
411 * altbank cf <SYSCLK freq> <COREPLL ratio>
414 read_from_px_regs(0);
415 read_from_px_regs_altbank(0);
416 val
= set_px_sysclk(simple_strtoul(argv
[3], NULL
, 10));
417 corepll
= strfractoint((uchar
*)argv
[4]);
418 val
= val
+ set_px_corepll(corepll
);
419 val
= val
+ set_px_mpxpll(simple_strtoul(argv
[5],
422 puts("Setting registers VCFGEN0, VCFGEN1, VBOOT, and VCTL\n");
424 read_from_px_regs(1);
425 read_from_px_regs_altbank(1);
426 puts("Enabling watchdog timer on the FPGA\n");
427 puts("Resetting board with values from ");
428 puts("VSPEED0, VSPEED1, VCLKH and VCLKL ");
429 puts("to boot from the other bank.\n");
430 set_px_go_with_watchdog();
436 while (1) ; /* Not reached */
438 } else if (strcmp(argv
[2], "wd") == 0) {
440 * Reset from alternate bank without changing
441 * frequencies but with watchdog timer enabled:
444 read_from_px_regs(0);
445 read_from_px_regs_altbank(0);
446 puts("Setting registers VCFGEN1, VBOOT, and VCTL\n");
448 read_from_px_regs_altbank(1);
449 puts("Enabling watchdog timer on the FPGA\n");
450 puts("Resetting board to boot from the other bank.\n");
451 set_px_go_with_watchdog();
452 while (1) ; /* Not reached */
469 pixis_reset
, CFG_MAXARGS
, 1, pixis_reset_cmd
,
470 "pixis_reset - Reset the board using the FPGA sequencer\n",
472 " pixis_reset [altbank]\n"
473 " pixis_reset altbank wd\n"
474 " pixis_reset altbank cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
475 " pixis_reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
477 #endif /* CONFIG_FSL_PIXIS */