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>
33 static ulong strfractoint(uchar *strptr);
39 void pixis_reset(void)
41 out8(PIXIS_BASE + PIXIS_RST, 0);
46 * Per table 27, page 58 of MPC8641HPCN spec.
48 int set_px_sysclk(ulong sysclk)
50 u8 sysclk_s, sysclk_r, sysclk_v, vclkh, vclkl, sysclk_aux;
102 printf("Unsupported SYSCLK frequency.\n");
106 vclkh = (sysclk_s << 5) | sysclk_r;
109 out8(PIXIS_BASE + PIXIS_VCLKH, vclkh);
110 out8(PIXIS_BASE + PIXIS_VCLKL, vclkl);
112 out8(PIXIS_BASE + PIXIS_AUX, sysclk_aux);
118 int set_px_mpxpll(ulong mpxpll)
135 printf("Unsupported MPXPLL ratio.\n");
139 tmp = in8(PIXIS_BASE + PIXIS_VSPEED1);
140 tmp = (tmp & 0xF0) | (val & 0x0F);
141 out8(PIXIS_BASE + PIXIS_VSPEED1, tmp);
147 int set_px_corepll(ulong corepll)
152 switch ((int)corepll) {
172 printf("Unsupported COREPLL ratio.\n");
176 tmp = in8(PIXIS_BASE + PIXIS_VSPEED0);
177 tmp = (tmp & 0xE0) | (val & 0x1F);
178 out8(PIXIS_BASE + PIXIS_VSPEED0, tmp);
184 void read_from_px_regs(int set)
186 u8 mask = 0x1C; /* COREPLL, MPXPLL, SYSCLK controlled by PIXIS */
187 u8 tmp = in8(PIXIS_BASE + PIXIS_VCFGEN0);
193 out8(PIXIS_BASE + PIXIS_VCFGEN0, tmp);
197 void read_from_px_regs_altbank(int set)
199 u8 mask = 0x04; /* FLASHBANK and FLASHMAP controlled by PIXIS */
200 u8 tmp = in8(PIXIS_BASE + PIXIS_VCFGEN1);
206 out8(PIXIS_BASE + PIXIS_VCFGEN1, tmp);
209 #ifndef CFG_PIXIS_VBOOT_MASK
210 #define CFG_PIXIS_VBOOT_MASK (0x40)
213 void clear_altbank(void)
217 tmp = in8(PIXIS_BASE + PIXIS_VBOOT);
218 tmp &= ~CFG_PIXIS_VBOOT_MASK;
220 out8(PIXIS_BASE + PIXIS_VBOOT, tmp);
224 void set_altbank(void)
228 tmp = in8(PIXIS_BASE + PIXIS_VBOOT);
229 tmp |= CFG_PIXIS_VBOOT_MASK;
231 out8(PIXIS_BASE + PIXIS_VBOOT, tmp);
239 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
240 tmp = tmp & 0x1E; /* clear GO bit */
241 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
243 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
244 tmp = tmp | 0x01; /* set GO bit - start reset sequencer */
245 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
249 void set_px_go_with_watchdog(void)
253 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
255 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
257 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
259 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
263 int pixis_disable_watchdog_cmd(cmd_tbl_t *cmdtp,
264 int flag, int argc, char *argv[])
268 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
270 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
272 /* setting VCTL[WDEN] to 0 to disable watch dog */
273 tmp = in8(PIXIS_BASE + PIXIS_VCTL);
275 out8(PIXIS_BASE + PIXIS_VCTL, tmp);
281 diswd, 1, 0, pixis_disable_watchdog_cmd,
282 "diswd - Disable watchdog timer \n",
286 * This function takes the non-integral cpu:mpx pll ratio
287 * and converts it to an integer that can be used to assign
288 * FPGA register values.
289 * input: strptr i.e. argv[2]
292 static ulong strfractoint(uchar *strptr)
296 int intarr_len = 0, decarr_len = 0, no_dec = 0;
297 ulong intval = 0, decval = 0;
298 uchar intarr[3], decarr[3];
300 /* Assign the integer part to intarr[]
301 * If there is no decimal point i.e.
302 * if the ratio is an integral value
303 * simply create the intarr.
306 while (strptr[i] != '.') {
307 if (strptr[i] == 0) {
311 intarr[i] = strptr[i];
315 /* Assign length of integer part to intarr_len. */
320 /* Currently needed only for single digit corepll ratios */
325 i++; /* Skipping the decimal point */
326 while ((strptr[i] >= '0') && (strptr[i] <= '9')) {
327 decarr[j] = strptr[i];
336 for (i = 0; i < decarr_len; i++)
338 decval = simple_strtoul((char *)decarr, NULL, 10);
341 intval = simple_strtoul((char *)intarr, NULL, 10);
342 intval = intval * mulconst;
344 retval = intval + decval;
351 pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
355 char *p_cf_sysclk = NULL;
356 char *p_cf_corepll = NULL;
357 char *p_cf_mpxpll = NULL;
358 char *p_altbank = NULL;
360 unsigned int unknown_param = 0;
363 * No args is a simple reset request.
370 for (i = 1; i < argc; i++) {
371 if (strcmp(argv[i], "cf") == 0) {
376 p_cf_sysclk = argv[i+1];
377 p_cf_corepll = argv[i+2];
378 p_cf_mpxpll = argv[i+3];
383 if (strcmp(argv[i], "altbank") == 0) {
388 if (strcmp(argv[i], "wd") == 0) {
397 * Check that cf has all required parms
399 if ((p_cf && !(p_cf_sysclk && p_cf_corepll && p_cf_mpxpll))
406 * PIXIS seems to be sensitive to the ordering of
407 * the registers that are touched.
409 read_from_px_regs(0);
412 read_from_px_regs_altbank(0);
417 * Clock configuration specified.
420 unsigned long sysclk;
421 unsigned long corepll;
422 unsigned long mpxpll;
424 sysclk = simple_strtoul(p_cf_sysclk, NULL, 10);
425 corepll = strfractoint((uchar *) p_cf_corepll);
426 mpxpll = simple_strtoul(p_cf_mpxpll, NULL, 10);
428 if (!(set_px_sysclk(sysclk)
429 && set_px_corepll(corepll)
430 && set_px_mpxpll(mpxpll))) {
434 read_from_px_regs(1);
440 * NOTE CHANGE IN BEHAVIOR: previous code would default
441 * to enabling watchdog if altbank is specified.
442 * Now the watchdog must be enabled explicitly using 'wd'.
446 read_from_px_regs_altbank(1);
450 * Reset with watchdog specified.
453 set_px_go_with_watchdog();
459 * Shouldn't be 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"