2 * Copyright 2006,2010 Freescale Semiconductor
4 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
6 * SPDX-License-Identifier: GPL-2.0+
13 #define pixis_base (u8 *)PIXIS_BASE
18 void pixis_reset(void)
20 out_8(pixis_base + PIXIS_RST, 0);
26 * Per table 27, page 58 of MPC8641HPCN spec.
28 static int set_px_sysclk(unsigned long sysclk)
30 u8 sysclk_s, sysclk_r, sysclk_v, vclkh, vclkl, sysclk_aux;
82 printf("Unsupported SYSCLK frequency.\n");
86 vclkh = (sysclk_s << 5) | sysclk_r;
89 out_8(pixis_base + PIXIS_VCLKH, vclkh);
90 out_8(pixis_base + PIXIS_VCLKL, vclkl);
92 out_8(pixis_base + PIXIS_AUX, sysclk_aux);
97 /* Set the CFG_SYSPLL bits
99 * This only has effect if PX_VCFGEN0[SYSPLL]=1, which is true if
100 * read_from_px_regs() is called.
102 static int set_px_mpxpll(unsigned long mpxpll)
113 clrsetbits_8(pixis_base + PIXIS_VSPEED1, 0x1F, mpxpll);
117 printf("Unsupported MPXPLL ratio.\n");
121 static int set_px_corepll(unsigned long corepll)
145 printf("Unsupported COREPLL ratio.\n");
149 clrsetbits_8(pixis_base + PIXIS_VSPEED0, 0x1F, val);
153 #ifndef CONFIG_SYS_PIXIS_VCFGEN0_ENABLE
154 #define CONFIG_SYS_PIXIS_VCFGEN0_ENABLE 0x1C
157 /* Tell the PIXIS where to find the COREPLL, MPXPLL, SYSCLK values
159 * The PIXIS can be programmed to look at either the on-board dip switches
160 * or various other PIXIS registers to determine the values for COREPLL,
161 * MPXPLL, and SYSCLK.
163 * CONFIG_SYS_PIXIS_VCFGEN0_ENABLE is the value to write to the PIXIS_VCFGEN0
164 * register that tells the pixis to use the various PIXIS register.
166 static void read_from_px_regs(int set)
168 u8 tmp = in_8(pixis_base + PIXIS_VCFGEN0);
171 tmp = tmp | CONFIG_SYS_PIXIS_VCFGEN0_ENABLE;
173 tmp = tmp & ~CONFIG_SYS_PIXIS_VCFGEN0_ENABLE;
175 out_8(pixis_base + PIXIS_VCFGEN0, tmp);
178 /* CONFIG_SYS_PIXIS_VBOOT_ENABLE is the value to write to the PX_VCFGEN1
179 * register that tells the pixis to use the PX_VBOOT[LBMAP] register.
181 #ifndef CONFIG_SYS_PIXIS_VBOOT_ENABLE
182 #define CONFIG_SYS_PIXIS_VBOOT_ENABLE 0x04
185 /* Configure the source of the boot location
187 * The PIXIS can be programmed to look at either the on-board dip switches
188 * or the PX_VBOOT[LBMAP] register to determine where we should boot.
190 * If we want to boot from the alternate boot bank, we need to tell the PIXIS
191 * to ignore the on-board dip switches and use the PX_VBOOT[LBMAP] instead.
193 static void read_from_px_regs_altbank(int set)
195 u8 tmp = in_8(pixis_base + PIXIS_VCFGEN1);
198 tmp = tmp | CONFIG_SYS_PIXIS_VBOOT_ENABLE;
200 tmp = tmp & ~CONFIG_SYS_PIXIS_VBOOT_ENABLE;
202 out_8(pixis_base + PIXIS_VCFGEN1, tmp);
205 /* CONFIG_SYS_PIXIS_VBOOT_MASK contains the bits to set in VBOOT register that
206 * tells the PIXIS what the alternate flash bank is.
208 * Note that it's not really a mask. It contains the actual LBMAP bits that
209 * must be set to select the alternate bank. This code assumes that the
210 * primary bank has these bits set to 0, and the alternate bank has these
213 #ifndef CONFIG_SYS_PIXIS_VBOOT_MASK
214 #define CONFIG_SYS_PIXIS_VBOOT_MASK (0x40)
217 /* Tell the PIXIS to boot from the default flash bank
219 * Program the default flash bank into the VBOOT register. This register is
220 * used only if PX_VCFGEN1[FLASH]=1.
222 static void clear_altbank(void)
224 clrbits_8(pixis_base + PIXIS_VBOOT, CONFIG_SYS_PIXIS_VBOOT_MASK);
227 /* Tell the PIXIS to boot from the alternate flash bank
229 * Program the alternate flash bank into the VBOOT register. This register is
230 * used only if PX_VCFGEN1[FLASH]=1.
232 static void set_altbank(void)
234 setbits_8(pixis_base + PIXIS_VBOOT, CONFIG_SYS_PIXIS_VBOOT_MASK);
237 /* Reset the board with watchdog disabled.
239 * This respects the altbank setting.
241 static void set_px_go(void)
243 /* Disable the VELA sequencer and watchdog */
244 clrbits_8(pixis_base + PIXIS_VCTL, 9);
246 /* Reboot by starting the VELA sequencer */
247 setbits_8(pixis_base + PIXIS_VCTL, 0x1);
252 /* Reset the board with watchdog enabled.
254 * This respects the altbank setting.
256 static void set_px_go_with_watchdog(void)
258 /* Disable the VELA sequencer */
259 clrbits_8(pixis_base + PIXIS_VCTL, 1);
261 /* Enable the watchdog and reboot by starting the VELA sequencer */
262 setbits_8(pixis_base + PIXIS_VCTL, 0x9);
267 /* Disable the watchdog
270 static int pixis_disable_watchdog_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
273 /* Disable the VELA sequencer and the watchdog */
274 clrbits_8(pixis_base + PIXIS_VCTL, 9);
280 diswd, 1, 0, pixis_disable_watchdog_cmd,
281 "Disable watchdog timer",
285 #ifdef CONFIG_PIXIS_SGMII_CMD
287 /* Enable or disable SGMII mode for a TSEC
289 static int pixis_set_sgmii(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
293 unsigned char switch_mask;
295 if ((argc > 2) && (strcmp(argv[1], "all") != 0))
296 which_tsec = simple_strtoul(argv[1], NULL, 0);
298 switch (which_tsec) {
301 mask = PIXIS_VSPEED2_TSEC1SER;
302 switch_mask = PIXIS_VCFGEN1_TSEC1SER;
307 mask = PIXIS_VSPEED2_TSEC2SER;
308 switch_mask = PIXIS_VCFGEN1_TSEC2SER;
313 mask = PIXIS_VSPEED2_TSEC3SER;
314 switch_mask = PIXIS_VCFGEN1_TSEC3SER;
319 mask = PIXIS_VSPEED2_TSEC4SER;
320 switch_mask = PIXIS_VCFGEN1_TSEC4SER;
324 mask = PIXIS_VSPEED2_MASK;
325 switch_mask = PIXIS_VCFGEN1_MASK;
329 /* Toggle whether the switches or FPGA control the settings */
330 if (!strcmp(argv[argc - 1], "switch"))
331 clrbits_8(pixis_base + PIXIS_VCFGEN1, switch_mask);
333 setbits_8(pixis_base + PIXIS_VCFGEN1, switch_mask);
335 /* If it's not the switches, enable or disable SGMII, as specified */
336 if (!strcmp(argv[argc - 1], "on"))
337 clrbits_8(pixis_base + PIXIS_VSPEED2, mask);
338 else if (!strcmp(argv[argc - 1], "off"))
339 setbits_8(pixis_base + PIXIS_VSPEED2, mask);
345 pixis_set_sgmii, CONFIG_SYS_MAXARGS, 1, pixis_set_sgmii,
347 " - Enable or disable SGMII mode for a given TSEC \n",
348 "\npixis_set_sgmii [TSEC num] <on|off|switch>\n"
349 " TSEC num: 1,2,3,4 or 'all'. 'all' is default.\n"
350 " on - enables SGMII\n"
351 " off - disables SGMII\n"
352 " switch - use switch settings"
358 * This function takes the non-integral cpu:mpx pll ratio
359 * and converts it to an integer that can be used to assign
360 * FPGA register values.
361 * input: strptr i.e. argv[2]
363 static unsigned long strfractoint(char *strptr)
368 unsigned long intval = 0, decval = 0;
369 char intarr[3], decarr[3];
371 /* Assign the integer part to intarr[]
372 * If there is no decimal point i.e.
373 * if the ratio is an integral value
374 * simply create the intarr.
377 while (strptr[i] != '.') {
378 if (strptr[i] == 0) {
382 intarr[i] = strptr[i];
389 /* Currently needed only for single digit corepll ratios */
394 i++; /* Skipping the decimal point */
395 while ((strptr[i] >= '0') && (strptr[i] <= '9')) {
396 decarr[j] = strptr[i];
404 for (i = 0; i < j; i++)
406 decval = simple_strtoul(decarr, NULL, 10);
409 intval = simple_strtoul(intarr, NULL, 10);
410 intval = intval * mulconst;
412 return intval + decval;
415 static int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
419 char *p_cf_sysclk = NULL;
420 char *p_cf_corepll = NULL;
421 char *p_cf_mpxpll = NULL;
422 char *p_altbank = NULL;
424 int unknown_param = 0;
427 * No args is a simple reset request.
434 for (i = 1; i < argc; i++) {
435 if (strcmp(argv[i], "cf") == 0) {
440 p_cf_sysclk = argv[i+1];
441 p_cf_corepll = argv[i+2];
442 p_cf_mpxpll = argv[i+3];
447 if (strcmp(argv[i], "altbank") == 0) {
452 if (strcmp(argv[i], "wd") == 0) {
461 * Check that cf has all required parms
463 if ((p_cf && !(p_cf_sysclk && p_cf_corepll && p_cf_mpxpll))
465 #ifdef CONFIG_SYS_LONGHELP
473 * PIXIS seems to be sensitive to the ordering of
474 * the registers that are touched.
476 read_from_px_regs(0);
479 read_from_px_regs_altbank(0);
484 * Clock configuration specified.
487 unsigned long sysclk;
488 unsigned long corepll;
489 unsigned long mpxpll;
491 sysclk = simple_strtoul(p_cf_sysclk, NULL, 10);
492 corepll = strfractoint(p_cf_corepll);
493 mpxpll = simple_strtoul(p_cf_mpxpll, NULL, 10);
495 if (!(set_px_sysclk(sysclk)
496 && set_px_corepll(corepll)
497 && set_px_mpxpll(mpxpll))) {
498 #ifdef CONFIG_SYS_LONGHELP
504 read_from_px_regs(1);
510 * NOTE CHANGE IN BEHAVIOR: previous code would default
511 * to enabling watchdog if altbank is specified.
512 * Now the watchdog must be enabled explicitly using 'wd'.
516 read_from_px_regs_altbank(1);
520 * Reset with watchdog specified.
523 set_px_go_with_watchdog();
528 * Shouldn't be reached.
535 pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd,
536 "Reset the board using the FPGA sequencer",
538 " pixis_reset [altbank]\n"
539 " pixis_reset altbank wd\n"
540 " pixis_reset altbank cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
541 " pixis_reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>"