1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2006,2010 Freescale Semiconductor
5 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
12 #define pixis_base (u8 *)PIXIS_BASE
17 void pixis_reset(void)
19 out_8(pixis_base
+ PIXIS_RST
, 0);
25 * Per table 27, page 58 of MPC8641HPCN spec.
27 static int set_px_sysclk(unsigned long sysclk
)
29 u8 sysclk_s
, sysclk_r
, sysclk_v
, vclkh
, vclkl
, sysclk_aux
;
81 printf("Unsupported SYSCLK frequency.\n");
85 vclkh
= (sysclk_s
<< 5) | sysclk_r
;
88 out_8(pixis_base
+ PIXIS_VCLKH
, vclkh
);
89 out_8(pixis_base
+ PIXIS_VCLKL
, vclkl
);
91 out_8(pixis_base
+ PIXIS_AUX
, sysclk_aux
);
96 /* Set the CFG_SYSPLL bits
98 * This only has effect if PX_VCFGEN0[SYSPLL]=1, which is true if
99 * read_from_px_regs() is called.
101 static int set_px_mpxpll(unsigned long mpxpll
)
112 clrsetbits_8(pixis_base
+ PIXIS_VSPEED1
, 0x1F, mpxpll
);
116 printf("Unsupported MPXPLL ratio.\n");
120 static int set_px_corepll(unsigned long corepll
)
144 printf("Unsupported COREPLL ratio.\n");
148 clrsetbits_8(pixis_base
+ PIXIS_VSPEED0
, 0x1F, val
);
152 #ifndef CONFIG_SYS_PIXIS_VCFGEN0_ENABLE
153 #define CONFIG_SYS_PIXIS_VCFGEN0_ENABLE 0x1C
156 /* Tell the PIXIS where to find the COREPLL, MPXPLL, SYSCLK values
158 * The PIXIS can be programmed to look at either the on-board dip switches
159 * or various other PIXIS registers to determine the values for COREPLL,
160 * MPXPLL, and SYSCLK.
162 * CONFIG_SYS_PIXIS_VCFGEN0_ENABLE is the value to write to the PIXIS_VCFGEN0
163 * register that tells the pixis to use the various PIXIS register.
165 static void read_from_px_regs(int set
)
167 u8 tmp
= in_8(pixis_base
+ PIXIS_VCFGEN0
);
170 tmp
= tmp
| CONFIG_SYS_PIXIS_VCFGEN0_ENABLE
;
172 tmp
= tmp
& ~CONFIG_SYS_PIXIS_VCFGEN0_ENABLE
;
174 out_8(pixis_base
+ PIXIS_VCFGEN0
, tmp
);
177 /* CONFIG_SYS_PIXIS_VBOOT_ENABLE is the value to write to the PX_VCFGEN1
178 * register that tells the pixis to use the PX_VBOOT[LBMAP] register.
180 #ifndef CONFIG_SYS_PIXIS_VBOOT_ENABLE
181 #define CONFIG_SYS_PIXIS_VBOOT_ENABLE 0x04
184 /* Configure the source of the boot location
186 * The PIXIS can be programmed to look at either the on-board dip switches
187 * or the PX_VBOOT[LBMAP] register to determine where we should boot.
189 * If we want to boot from the alternate boot bank, we need to tell the PIXIS
190 * to ignore the on-board dip switches and use the PX_VBOOT[LBMAP] instead.
192 static void read_from_px_regs_altbank(int set
)
194 u8 tmp
= in_8(pixis_base
+ PIXIS_VCFGEN1
);
197 tmp
= tmp
| CONFIG_SYS_PIXIS_VBOOT_ENABLE
;
199 tmp
= tmp
& ~CONFIG_SYS_PIXIS_VBOOT_ENABLE
;
201 out_8(pixis_base
+ PIXIS_VCFGEN1
, tmp
);
204 /* CONFIG_SYS_PIXIS_VBOOT_MASK contains the bits to set in VBOOT register that
205 * tells the PIXIS what the alternate flash bank is.
207 * Note that it's not really a mask. It contains the actual LBMAP bits that
208 * must be set to select the alternate bank. This code assumes that the
209 * primary bank has these bits set to 0, and the alternate bank has these
212 #ifndef CONFIG_SYS_PIXIS_VBOOT_MASK
213 #define CONFIG_SYS_PIXIS_VBOOT_MASK (0x40)
216 /* Tell the PIXIS to boot from the default flash bank
218 * Program the default flash bank into the VBOOT register. This register is
219 * used only if PX_VCFGEN1[FLASH]=1.
221 static void clear_altbank(void)
223 clrbits_8(pixis_base
+ PIXIS_VBOOT
, CONFIG_SYS_PIXIS_VBOOT_MASK
);
226 /* Tell the PIXIS to boot from the alternate flash bank
228 * Program the alternate flash bank into the VBOOT register. This register is
229 * used only if PX_VCFGEN1[FLASH]=1.
231 static void set_altbank(void)
233 setbits_8(pixis_base
+ PIXIS_VBOOT
, CONFIG_SYS_PIXIS_VBOOT_MASK
);
236 /* Reset the board with watchdog disabled.
238 * This respects the altbank setting.
240 static void set_px_go(void)
242 /* Disable the VELA sequencer and watchdog */
243 clrbits_8(pixis_base
+ PIXIS_VCTL
, 9);
245 /* Reboot by starting the VELA sequencer */
246 setbits_8(pixis_base
+ PIXIS_VCTL
, 0x1);
251 /* Reset the board with watchdog enabled.
253 * This respects the altbank setting.
255 static void set_px_go_with_watchdog(void)
257 /* Disable the VELA sequencer */
258 clrbits_8(pixis_base
+ PIXIS_VCTL
, 1);
260 /* Enable the watchdog and reboot by starting the VELA sequencer */
261 setbits_8(pixis_base
+ PIXIS_VCTL
, 0x9);
266 /* Disable the watchdog
269 static int pixis_disable_watchdog_cmd(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
272 /* Disable the VELA sequencer and the watchdog */
273 clrbits_8(pixis_base
+ PIXIS_VCTL
, 9);
279 diswd
, 1, 0, pixis_disable_watchdog_cmd
,
280 "Disable watchdog timer",
284 #ifdef CONFIG_PIXIS_SGMII_CMD
286 /* Enable or disable SGMII mode for a TSEC
288 static int pixis_set_sgmii(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
292 unsigned char switch_mask
;
294 if ((argc
> 2) && (strcmp(argv
[1], "all") != 0))
295 which_tsec
= simple_strtoul(argv
[1], NULL
, 0);
297 switch (which_tsec
) {
300 mask
= PIXIS_VSPEED2_TSEC1SER
;
301 switch_mask
= PIXIS_VCFGEN1_TSEC1SER
;
306 mask
= PIXIS_VSPEED2_TSEC2SER
;
307 switch_mask
= PIXIS_VCFGEN1_TSEC2SER
;
312 mask
= PIXIS_VSPEED2_TSEC3SER
;
313 switch_mask
= PIXIS_VCFGEN1_TSEC3SER
;
318 mask
= PIXIS_VSPEED2_TSEC4SER
;
319 switch_mask
= PIXIS_VCFGEN1_TSEC4SER
;
323 mask
= PIXIS_VSPEED2_MASK
;
324 switch_mask
= PIXIS_VCFGEN1_MASK
;
328 /* Toggle whether the switches or FPGA control the settings */
329 if (!strcmp(argv
[argc
- 1], "switch"))
330 clrbits_8(pixis_base
+ PIXIS_VCFGEN1
, switch_mask
);
332 setbits_8(pixis_base
+ PIXIS_VCFGEN1
, switch_mask
);
334 /* If it's not the switches, enable or disable SGMII, as specified */
335 if (!strcmp(argv
[argc
- 1], "on"))
336 clrbits_8(pixis_base
+ PIXIS_VSPEED2
, mask
);
337 else if (!strcmp(argv
[argc
- 1], "off"))
338 setbits_8(pixis_base
+ PIXIS_VSPEED2
, mask
);
344 pixis_set_sgmii
, CONFIG_SYS_MAXARGS
, 1, pixis_set_sgmii
,
346 " - Enable or disable SGMII mode for a given TSEC \n",
347 "\npixis_set_sgmii [TSEC num] <on|off|switch>\n"
348 " TSEC num: 1,2,3,4 or 'all'. 'all' is default.\n"
349 " on - enables SGMII\n"
350 " off - disables SGMII\n"
351 " switch - use switch settings"
357 * This function takes the non-integral cpu:mpx pll ratio
358 * and converts it to an integer that can be used to assign
359 * FPGA register values.
360 * input: strptr i.e. argv[2]
362 static unsigned long strfractoint(char *strptr
)
367 unsigned long intval
= 0, decval
= 0;
368 char intarr
[3], decarr
[3];
370 /* Assign the integer part to intarr[]
371 * If there is no decimal point i.e.
372 * if the ratio is an integral value
373 * simply create the intarr.
376 while (strptr
[i
] != '.') {
377 if (strptr
[i
] == 0) {
381 intarr
[i
] = strptr
[i
];
388 /* Currently needed only for single digit corepll ratios */
393 i
++; /* Skipping the decimal point */
394 while ((strptr
[i
] >= '0') && (strptr
[i
] <= '9')) {
395 decarr
[j
] = strptr
[i
];
403 for (i
= 0; i
< j
; i
++)
405 decval
= simple_strtoul(decarr
, NULL
, 10);
408 intval
= simple_strtoul(intarr
, NULL
, 10);
409 intval
= intval
* mulconst
;
411 return intval
+ decval
;
414 static int pixis_reset_cmd(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
418 char *p_cf_sysclk
= NULL
;
419 char *p_cf_corepll
= NULL
;
420 char *p_cf_mpxpll
= NULL
;
421 char *p_altbank
= NULL
;
423 int unknown_param
= 0;
426 * No args is a simple reset request.
433 for (i
= 1; i
< argc
; i
++) {
434 if (strcmp(argv
[i
], "cf") == 0) {
439 p_cf_sysclk
= argv
[i
+1];
440 p_cf_corepll
= argv
[i
+2];
441 p_cf_mpxpll
= argv
[i
+3];
446 if (strcmp(argv
[i
], "altbank") == 0) {
451 if (strcmp(argv
[i
], "wd") == 0) {
460 * Check that cf has all required parms
462 if ((p_cf
&& !(p_cf_sysclk
&& p_cf_corepll
&& p_cf_mpxpll
))
464 #ifdef CONFIG_SYS_LONGHELP
472 * PIXIS seems to be sensitive to the ordering of
473 * the registers that are touched.
475 read_from_px_regs(0);
478 read_from_px_regs_altbank(0);
483 * Clock configuration specified.
486 unsigned long sysclk
;
487 unsigned long corepll
;
488 unsigned long mpxpll
;
490 sysclk
= simple_strtoul(p_cf_sysclk
, NULL
, 10);
491 corepll
= strfractoint(p_cf_corepll
);
492 mpxpll
= simple_strtoul(p_cf_mpxpll
, NULL
, 10);
494 if (!(set_px_sysclk(sysclk
)
495 && set_px_corepll(corepll
)
496 && set_px_mpxpll(mpxpll
))) {
497 #ifdef CONFIG_SYS_LONGHELP
503 read_from_px_regs(1);
509 * NOTE CHANGE IN BEHAVIOR: previous code would default
510 * to enabling watchdog if altbank is specified.
511 * Now the watchdog must be enabled explicitly using 'wd'.
515 read_from_px_regs_altbank(1);
519 * Reset with watchdog specified.
522 set_px_go_with_watchdog();
527 * Shouldn't be reached.
534 pixis_reset
, CONFIG_SYS_MAXARGS
, 1, pixis_reset_cmd
,
535 "Reset the board using the FPGA sequencer",
537 " pixis_reset [altbank]\n"
538 " pixis_reset altbank wd\n"
539 " pixis_reset altbank cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
540 " pixis_reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>"