3 * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 * STK52XX specific functions
16 #if defined(CONFIG_CMD_BSP)
18 #if defined(CONFIG_STK52XX) || defined(CONFIG_FO300)
19 #define DEFAULT_VOL 45
20 #define DEFAULT_FREQ 500
21 #define DEFAULT_DURATION 200
28 #define SM501_GPIO_CTRL_LOW 0x00000008UL
29 #define SM501_GPIO_CTRL_HIGH 0x0000000CUL
30 #define SM501_POWER_MODE0_GATE 0x00000040UL
31 #define SM501_POWER_MODE1_GATE 0x00000048UL
32 #define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
33 #define SM501_GPIO_DATA_LOW 0x00010000UL
34 #define SM501_GPIO_DATA_HIGH 0x00010004UL
35 #define SM501_GPIO_DATA_DIR_LOW 0x00010008UL
36 #define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
37 #define SM501_PANEL_DISPLAY_CONTROL 0x00080000UL
39 static int i2s_squarewave(unsigned long duration
, unsigned int freq
,
40 unsigned int channel
);
41 static int i2s_sawtooth(unsigned long duration
, unsigned int freq
,
42 unsigned int channel
);
43 static void spi_init(void);
44 static int spi_transmit(unsigned char data
);
45 static void pcm1772_write_reg(unsigned char addr
, unsigned char data
);
46 static void set_attenuation(unsigned char attenuation
);
48 static void spi_init(void)
50 struct mpc5xxx_spi
*spi
= (struct mpc5xxx_spi
*)MPC5XXX_SPI
;
51 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
53 /* PSC3 as SPI and GPIOs */
54 gpio
->port_config
&= 0xFFFFF0FF;
55 gpio
->port_config
|= 0x00000800;
57 * Its important to use the correct order when initializing the
60 spi
->ddr
= 0x0F; /* set all SPI pins as output */
61 spi
->pdr
= 0x08; /* set SS high */
62 spi
->cr1
= 0x50; /* SPI is master, SS is general purpose output */
63 spi
->cr2
= 0x00; /* normal operation */
64 spi
->brr
= 0xFF; /* baud rate: IPB clock / 2048 */
67 static int spi_transmit(unsigned char data
)
69 struct mpc5xxx_spi
*spi
= (struct mpc5xxx_spi
*)MPC5XXX_SPI
;
72 /* wait for SPI transmission completed */
73 while (!(spi
->sr
& 0x80)) {
74 if (spi
->sr
& 0x40) { /* if write collision occured */
77 /* do dummy read to clear status register */
79 printf("SPI write collision: dr=0x%x\n", dummy
);
86 static void pcm1772_write_reg(unsigned char addr
, unsigned char data
)
88 struct mpc5xxx_spi
*spi
= (struct mpc5xxx_spi
*)MPC5XXX_SPI
;
90 spi
->pdr
= 0x00; /* Set SS low */
93 /* wait some time to meet MS# hold time of PCM1772 */
95 spi
->pdr
= 0x08; /* set SS high */
98 static void set_attenuation(unsigned char attenuation
)
100 pcm1772_write_reg(0x01, attenuation
); /* left channel */
101 debug ("PCM1772 attenuation left set to %d.\n", attenuation
);
102 pcm1772_write_reg(0x02, attenuation
); /* right channel */
103 debug ("PCM1772 attenuation right set to %d.\n", attenuation
);
106 void amplifier_init(void)
108 static int init_done
= 0;
110 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
112 /* Do this only once, because of the long time delay */
114 /* configure PCM1772 audio format as I2S */
115 pcm1772_write_reg(0x03, 0x01);
116 /* enable audio amplifier */
117 gpio
->sint_gpioe
|= 0x02; /* PSC3_5 as GPIO */
118 gpio
->sint_ode
&= ~0x02; /* PSC3_5 is not open Drain */
119 gpio
->sint_dvo
&= ~0x02; /* PSC3_5 is LOW */
120 gpio
->sint_ddr
|= 0x02; /* PSC3_5 as output */
122 * wait some time to allow amplifier to recover from shutdown
125 for(i
= 0; i
< 350; i
++)
128 * The used amplifier (LM4867) has a so called "pop and click"
129 * elmination filter. The input signal of the amplifier must
130 * exceed a certain level once after power up to activate the
131 * generation of the output signal. This is achieved by
132 * sending a low frequent (nearly inaudible) sawtooth with a
133 * sufficient signal level.
136 i2s_sawtooth (200, 5, LEFT_RIGHT
);
141 static void i2s_init(void)
144 struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)MPC5XXX_PSC2
;;
145 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
147 gpio
->port_config
|= 0x00000070; /* PSC2 ports as Codec with MCLK */
148 psc
->command
= (PSC_RX_DISABLE
| PSC_TX_DISABLE
);
149 psc
->sicr
= 0x22E00000; /* 16 bit data; I2S */
151 *(vu_long
*)(CONFIG_SYS_MBAR
+ 0x22C) = 0x805d; /* PSC2 CDM MCLK config; MCLK
153 *(vu_long
*)(CONFIG_SYS_MBAR
+ 0x214) |= 0x00000040; /* CDM clock enable
155 psc
->ccr
= 0x1F03; /* 16 bit data width; 5.617MHz MCLK */
156 psc
->ctur
= 0x0F; /* 16 bit frame width */
158 for (i
= 0; i
< 128; i
++)
159 psc
->psc_buffer_32
= 0; /* clear tx fifo */
162 static int i2s_play_wave(unsigned long addr
, unsigned long len
)
165 unsigned char *wave_file
= (uchar
*)addr
+ 44; /* quick'n dirty: skip
167 struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)MPC5XXX_PSC2
;
170 * play wave file in memory; bytes/words are be swapped
172 psc
->command
= (PSC_RX_ENABLE
| PSC_TX_ENABLE
);
174 for(i
= 0;i
< (len
/ 4); i
++) {
175 unsigned char swapped
[4];
176 unsigned long *p
= (unsigned long*)swapped
;
178 swapped
[3] = *wave_file
++;
179 swapped
[2] = *wave_file
++;
180 swapped
[1] = *wave_file
++;
181 swapped
[0] = *wave_file
++;
183 psc
->psc_buffer_32
= *p
;
185 while (psc
->tfnum
> 400) {
190 while (psc
->tfnum
> 0); /* wait for fifo empty */
192 psc
->command
= (PSC_RX_DISABLE
| PSC_TX_DISABLE
);
196 static int i2s_sawtooth(unsigned long duration
, unsigned int freq
,
197 unsigned int channel
)
201 struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)MPC5XXX_PSC2
;
203 psc
->command
= (PSC_RX_ENABLE
| PSC_TX_ENABLE
);
206 * Generate sawtooth. Start with middle level up to highest level. Then
207 * go to lowest level and back to middle level.
209 for(j
= 0; j
< ((duration
* freq
) / 1000); j
++) {
210 for(i
= 0; i
<= 0x7FFF; i
+= (0x7FFF/(44100/(freq
*4)))) {
212 /* data format: right data left data) */
213 if (channel
== LEFT_RIGHT
)
215 if (channel
== RIGHT
)
217 psc
->psc_buffer_32
= data
;
218 while (psc
->tfnum
> 400);
220 for(i
= 0x7FFF; i
>= -0x7FFF; i
-= (0xFFFF/(44100/(freq
*2)))) {
222 /* data format: right data left data) */
223 if (channel
== LEFT_RIGHT
)
225 if (channel
== RIGHT
)
227 psc
->psc_buffer_32
= data
;
228 while (psc
->tfnum
> 400);
230 for(i
= -0x7FFF; i
<= 0; i
+= (0x7FFF/(44100/(freq
*4)))) {
232 /* data format: right data left data) */
233 if (channel
== LEFT_RIGHT
)
235 if (channel
== RIGHT
)
237 psc
->psc_buffer_32
= data
;
238 while (psc
->tfnum
> 400);
241 while (psc
->tfnum
> 0); /* wait for fifo empty */
243 psc
->command
= (PSC_RX_DISABLE
| PSC_TX_DISABLE
);
248 static int i2s_squarewave(unsigned long duration
, unsigned int freq
,
249 unsigned int channel
)
253 struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)MPC5XXX_PSC2
;
255 psc
->command
= (PSC_RX_ENABLE
| PSC_TX_ENABLE
);
258 * Generate sqarewave. Start with high level, duty cycle 1:1.
260 for(j
= 0; j
< ((duration
* freq
) / 1000); j
++) {
261 for(i
= 0; i
< (44100/(freq
*2)); i
++) {
263 /* data format: right data left data) */
264 if (channel
== LEFT_RIGHT
)
266 if (channel
== RIGHT
)
268 psc
->psc_buffer_32
= data
;
269 while (psc
->tfnum
> 400);
271 for(i
= 0; i
< (44100/(freq
*2)); i
++) {
273 /* data format: right data left data) */
274 if (channel
== LEFT_RIGHT
)
276 if (channel
== RIGHT
)
278 psc
->psc_buffer_32
= data
;
279 while (psc
->tfnum
> 400);
282 while (psc
->tfnum
> 0); /* wait for fifo empty */
284 psc
->command
= (PSC_RX_DISABLE
| PSC_TX_DISABLE
);
289 static int cmd_sound(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
291 unsigned long reg
, val
, duration
;
293 unsigned int freq
, channel
;
294 unsigned char volume
;
297 #ifdef CONFIG_STK52XX_REV100
298 printf ("Revision 100 of STK52XX not supported!\n");
305 if ((tmp
= getenv ("volume")) != NULL
) {
306 volume
= simple_strtoul (tmp
, NULL
, 10);
308 volume
= DEFAULT_VOL
;
310 set_attenuation(volume
);
315 return cmd_usage(cmdtp
);
317 if (strncmp(argv
[1],"saw",3) == 0) {
318 printf ("Play sawtooth\n");
319 rcode
= i2s_sawtooth (DEFAULT_DURATION
, DEFAULT_FREQ
,
322 } else if (strncmp(argv
[1],"squ",3) == 0) {
323 printf ("Play squarewave\n");
324 rcode
= i2s_squarewave (DEFAULT_DURATION
, DEFAULT_FREQ
,
329 return cmd_usage(cmdtp
);
331 if (strncmp(argv
[1],"saw",3) == 0) {
332 duration
= simple_strtoul(argv
[2], NULL
, 10);
333 printf ("Play sawtooth\n");
334 rcode
= i2s_sawtooth (duration
, DEFAULT_FREQ
,
337 } else if (strncmp(argv
[1],"squ",3) == 0) {
338 duration
= simple_strtoul(argv
[2], NULL
, 10);
339 printf ("Play squarewave\n");
340 rcode
= i2s_squarewave (duration
, DEFAULT_FREQ
,
344 return cmd_usage(cmdtp
);
346 if (strncmp(argv
[1],"saw",3) == 0) {
347 duration
= simple_strtoul(argv
[2], NULL
, 10);
348 freq
= (unsigned int)simple_strtoul(argv
[3], NULL
, 10);
349 printf ("Play sawtooth\n");
350 rcode
= i2s_sawtooth (duration
, freq
,
353 } else if (strncmp(argv
[1],"squ",3) == 0) {
354 duration
= simple_strtoul(argv
[2], NULL
, 10);
355 freq
= (unsigned int)simple_strtoul(argv
[3], NULL
, 10);
356 printf ("Play squarewave\n");
357 rcode
= i2s_squarewave (duration
, freq
,
360 } else if (strcmp(argv
[1],"pcm1772") == 0) {
361 reg
= simple_strtoul(argv
[2], NULL
, 10);
362 val
= simple_strtoul(argv
[3], NULL
, 10);
363 printf("Set PCM1772 %lu. %lu\n", reg
, val
);
364 pcm1772_write_reg((uchar
)reg
, (uchar
)val
);
367 return cmd_usage(cmdtp
);
369 if (strncmp(argv
[1],"saw",3) == 0) {
370 duration
= simple_strtoul(argv
[2], NULL
, 10);
371 freq
= (unsigned int)simple_strtoul(argv
[3], NULL
, 10);
372 if (strncmp(argv
[4],"l",1) == 0)
374 else if (strncmp(argv
[4],"r",1) == 0)
377 channel
= LEFT_RIGHT
;
378 printf ("Play squarewave\n");
379 rcode
= i2s_sawtooth (duration
, freq
,
382 } else if (strncmp(argv
[1],"squ",3) == 0) {
383 duration
= simple_strtoul(argv
[2], NULL
, 10);
384 freq
= (unsigned int)simple_strtoul(argv
[3], NULL
, 10);
385 if (strncmp(argv
[4],"l",1) == 0)
387 else if (strncmp(argv
[4],"r",1) == 0)
390 channel
= LEFT_RIGHT
;
391 printf ("Play squarewave\n");
392 rcode
= i2s_squarewave (duration
, freq
,
396 return cmd_usage(cmdtp
);
398 printf ("Usage:\nsound cmd [arg1] [arg2] ...\n");
402 static int cmd_wav(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
404 unsigned long length
, addr
;
405 unsigned char volume
;
409 #ifdef CONFIG_STK52XX_REV100
410 printf ("Revision 100 of STK52XX not supported!\n");
420 length
= simple_strtoul(argv
[2], NULL
, 16);
421 addr
= simple_strtoul(argv
[1], NULL
, 16);
425 if ((tmp
= getenv ("filesize")) != NULL
) {
426 length
= simple_strtoul (tmp
, NULL
, 16);
428 puts ("No filesize provided\n");
431 addr
= simple_strtoul(argv
[1], NULL
, 16);
434 if ((tmp
= getenv ("filesize")) != NULL
) {
435 length
= simple_strtoul (tmp
, NULL
, 16);
437 puts ("No filesize provided\n");
440 if ((tmp
= getenv ("loadaddr")) != NULL
) {
441 addr
= simple_strtoul (tmp
, NULL
, 16);
443 puts ("No loadaddr provided\n");
449 printf("Usage:\nwav <addr> <length[s]\n");
454 if ((tmp
= getenv ("volume")) != NULL
) {
455 volume
= simple_strtoul (tmp
, NULL
, 10);
457 volume
= DEFAULT_VOL
;
459 set_attenuation(volume
);
461 printf("Play wave file at %lX with length %lX\n", addr
, length
);
462 rcode
= i2s_play_wave(addr
, length
);
467 static int cmd_beep(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
469 unsigned char volume
;
470 unsigned int channel
;
474 #ifdef CONFIG_STK52XX_REV100
475 printf ("Revision 100 of STK52XX not supported!\n");
485 channel
= LEFT_RIGHT
;
488 if (strncmp(argv
[1],"l",1) == 0)
490 else if (strncmp(argv
[1],"r",1) == 0)
493 channel
= LEFT_RIGHT
;
496 return cmd_usage(cmdtp
);
499 if ((tmp
= getenv ("volume")) != NULL
) {
500 volume
= simple_strtoul (tmp
, NULL
, 10);
502 volume
= DEFAULT_VOL
;
504 set_attenuation(volume
);
509 else if (channel
== RIGHT
)
512 printf ("left and right ");
513 printf ("channel\n");
515 rcode
= i2s_squarewave (DEFAULT_DURATION
, DEFAULT_FREQ
, channel
);
521 #if defined(CONFIG_STK52XX)
524 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
525 struct mpc5xxx_gpt_0_7
*gpt
= (struct mpc5xxx_gpt_0_7
*)MPC5XXX_GPT
;
527 /* configure PSC3 for SPI and GPIO */
528 gpio
->port_config
&= ~(0x00000F00);
529 gpio
->port_config
|= 0x00000800;
531 gpio
->simple_gpioe
&= ~(0x00000F00);
532 gpio
->simple_gpioe
|= 0x00000F00;
534 gpio
->simple_ddr
&= ~(0x00000F00);
535 gpio
->simple_ddr
|= 0x00000F00;
537 /* configure timer 4-7 for simple GPIO output */
538 gpt
->gpt4
.emsr
|= 0x00000024;
539 gpt
->gpt5
.emsr
|= 0x00000024;
540 gpt
->gpt6
.emsr
|= 0x00000024;
541 gpt
->gpt7
.emsr
|= 0x00000024;
543 #ifndef CONFIG_TQM5200S
544 /* enable SM501 GPIO control (in both power modes) */
545 *(vu_long
*) (SM501_MMIO_BASE
+SM501_POWER_MODE0_GATE
) |=
546 POWER_MODE_GATE_GPIO_PWM_I2C
;
547 *(vu_long
*) (SM501_MMIO_BASE
+SM501_POWER_MODE1_GATE
) |=
548 POWER_MODE_GATE_GPIO_PWM_I2C
;
550 /* configure SM501 gpio pins 24-27 as output */
551 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_CTRL_LOW
) &= ~(0xF << 24);
552 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_DIR_LOW
) |= (0xF << 24);
554 /* configure SM501 gpio pins 48-51 as output */
555 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_DIR_HIGH
) |= (0xF << 16);
556 #endif /* !CONFIG_TQM5200S */
560 * return 1 if led number unknown
563 int do_led(char * const argv
[])
565 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
566 struct mpc5xxx_gpt_0_7
*gpt
= (struct mpc5xxx_gpt_0_7
*)MPC5XXX_GPT
;
568 switch (simple_strtoul(argv
[2], NULL
, 10)) {
571 if (strcmp (argv
[3], "on") == 0) {
572 gpio
->simple_dvo
|= (1 << 8);
574 gpio
->simple_dvo
&= ~(1 << 8);
579 if (strcmp (argv
[3], "on") == 0) {
580 gpio
->simple_dvo
|= (1 << 9);
582 gpio
->simple_dvo
&= ~(1 << 9);
587 if (strcmp (argv
[3], "on") == 0) {
588 gpio
->simple_dvo
|= (1 << 10);
590 gpio
->simple_dvo
&= ~(1 << 10);
595 if (strcmp (argv
[3], "on") == 0) {
596 gpio
->simple_dvo
|= (1 << 11);
598 gpio
->simple_dvo
&= ~(1 << 11);
603 if (strcmp (argv
[3], "on") == 0) {
604 gpt
->gpt4
.emsr
|= (1 << 4);
606 gpt
->gpt4
.emsr
&= ~(1 << 4);
611 if (strcmp (argv
[3], "on") == 0) {
612 gpt
->gpt5
.emsr
|= (1 << 4);
614 gpt
->gpt5
.emsr
&= ~(1 << 4);
619 if (strcmp (argv
[3], "on") == 0) {
620 gpt
->gpt6
.emsr
|= (1 << 4);
622 gpt
->gpt6
.emsr
&= ~(1 << 4);
627 if (strcmp (argv
[3], "on") == 0) {
628 gpt
->gpt7
.emsr
|= (1 << 4);
630 gpt
->gpt7
.emsr
&= ~(1 << 4);
633 #ifndef CONFIG_TQM5200S
635 if (strcmp (argv
[3], "on") == 0) {
636 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) |=
639 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) &=
645 if (strcmp (argv
[3], "on") == 0) {
646 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) |=
649 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) &=
655 if (strcmp (argv
[3], "on") == 0) {
656 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) |=
659 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) &=
665 if (strcmp (argv
[3], "on") == 0) {
666 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) |=
669 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) &=
675 if (strcmp (argv
[3], "on") == 0) {
676 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) |=
679 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) &=
685 if (strcmp (argv
[3], "on") == 0) {
686 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) |=
689 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) &=
695 if (strcmp (argv
[3], "on") == 0) {
696 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) |=
699 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) &=
705 if (strcmp (argv
[3], "on") == 0) {
706 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) |=
709 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) &=
713 #endif /* !CONFIG_TQM5200S */
715 printf ("%s: invalid led number %s\n", __FUNCTION__
, argv
[2]);
723 #if defined(CONFIG_STK52XX) || defined(CONFIG_FO300)
725 * return 1 on CAN initialization failure
726 * return 0 if no failure
730 static int init_done
= 0;
732 struct mpc5xxx_mscan
*can1
=
733 (struct mpc5xxx_mscan
*)(CONFIG_SYS_MBAR
+ 0x0900);
734 struct mpc5xxx_mscan
*can2
=
735 (struct mpc5xxx_mscan
*)(CONFIG_SYS_MBAR
+ 0x0980);
737 /* GPIO configuration of the CAN pins is done in TQM5200.h */
741 can1
->canctl1
|= 0x80; /* CAN enable */
745 can1
->canctl0
|= 0x02; /* sleep mode */
746 /* wait until sleep mode reached */
747 while (!(can1
->canctl1
& 0x02)) {
751 printf ("%s: CAN1 initialize error, "
752 "can not enter sleep mode!\n",
758 can1
->canctl0
= 0x01; /* enter init mode */
759 /* wait until init mode reached */
760 while (!(can1
->canctl1
& 0x01)) {
764 printf ("%s: CAN1 initialize error, "
765 "can not enter init mode!\n",
770 can1
->canctl1
= 0x80;
771 can1
->canctl1
|= 0x40;
772 can1
->canbtr0
= 0x0F;
773 can1
->canbtr1
= 0x7F;
774 can1
->canidac
&= ~(0x30);
775 can1
->canidar1
= 0x00;
776 can1
->canidar3
= 0x00;
777 can1
->canidar5
= 0x00;
778 can1
->canidar7
= 0x00;
779 can1
->canidmr0
= 0xFF;
780 can1
->canidmr1
= 0xFF;
781 can1
->canidmr2
= 0xFF;
782 can1
->canidmr3
= 0xFF;
783 can1
->canidmr4
= 0xFF;
784 can1
->canidmr5
= 0xFF;
785 can1
->canidmr6
= 0xFF;
786 can1
->canidmr7
= 0xFF;
789 can1
->canctl0
&= ~(0x01); /* leave init mode */
790 can1
->canctl0
&= ~(0x02);
791 /* wait until init and sleep mode left */
792 while ((can1
->canctl1
& 0x01) || (can1
->canctl1
& 0x02)) {
796 printf ("%s: CAN1 initialize error, "
797 "can not leave init/sleep mode!\n",
804 can2
->canctl1
|= 0x80; /* CAN enable */
808 can2
->canctl0
|= 0x02; /* sleep mode */
809 /* wait until sleep mode reached */
810 while (!(can2
->canctl1
& 0x02)) {
814 printf ("%s: CAN2 initialize error, "
815 "can not enter sleep mode!\n",
821 can2
->canctl0
= 0x01; /* enter init mode */
822 /* wait until init mode reached */
823 while (!(can2
->canctl1
& 0x01)) {
827 printf ("%s: CAN2 initialize error, "
828 "can not enter init mode!\n",
833 can2
->canctl1
= 0x80;
834 can2
->canctl1
|= 0x40;
835 can2
->canbtr0
= 0x0F;
836 can2
->canbtr1
= 0x7F;
837 can2
->canidac
&= ~(0x30);
838 can2
->canidar1
= 0x00;
839 can2
->canidar3
= 0x00;
840 can2
->canidar5
= 0x00;
841 can2
->canidar7
= 0x00;
842 can2
->canidmr0
= 0xFF;
843 can2
->canidmr1
= 0xFF;
844 can2
->canidmr2
= 0xFF;
845 can2
->canidmr3
= 0xFF;
846 can2
->canidmr4
= 0xFF;
847 can2
->canidmr5
= 0xFF;
848 can2
->canidmr6
= 0xFF;
849 can2
->canidmr7
= 0xFF;
850 can2
->canctl0
&= ~(0x01); /* leave init mode */
851 can2
->canctl0
&= ~(0x02);
854 /* wait until init mode left */
855 while ((can2
->canctl1
& 0x01) || (can2
->canctl1
& 0x02)) {
859 printf ("%s: CAN2 initialize error, "
860 "can not leave init/sleep mode!\n",
871 * return 1 on CAN failure
872 * return 0 if no failure
874 int do_can(char * const argv
[])
877 struct mpc5xxx_mscan
*can1
=
878 (struct mpc5xxx_mscan
*)(CONFIG_SYS_MBAR
+ 0x0900);
879 struct mpc5xxx_mscan
*can2
=
880 (struct mpc5xxx_mscan
*)(CONFIG_SYS_MBAR
+ 0x0980);
882 /* send a message on CAN1 */
883 can1
->cantbsel
= 0x01;
884 can1
->cantxfg
.idr
[0] = 0x55;
885 can1
->cantxfg
.idr
[1] = 0x00;
886 can1
->cantxfg
.idr
[1] &= ~0x8;
887 can1
->cantxfg
.idr
[1] &= ~0x10;
888 can1
->cantxfg
.dsr
[0] = 0xCC;
889 can1
->cantxfg
.dlr
= 1;
890 can1
->cantxfg
.tbpr
= 0;
891 can1
->cantflg
= 0x01;
894 while ((can1
->cantflg
& 0x01) == 0) {
897 printf ("%s: CAN1 send timeout, "
898 "can not send message!\n",
907 while (!(can2
->canrflg
& 0x01)) {
910 printf ("%s: CAN2 receive timeout, "
911 "no message received!\n",
918 if (can2
->canrxfg
.dsr
[0] != 0xCC) {
919 printf ("%s: CAN2 receive error, "
925 /* send a message on CAN2 */
926 can2
->cantbsel
= 0x01;
927 can2
->cantxfg
.idr
[0] = 0x55;
928 can2
->cantxfg
.idr
[1] = 0x00;
929 can2
->cantxfg
.idr
[1] &= ~0x8;
930 can2
->cantxfg
.idr
[1] &= ~0x10;
931 can2
->cantxfg
.dsr
[0] = 0xCC;
932 can2
->cantxfg
.dlr
= 1;
933 can2
->cantxfg
.tbpr
= 0;
934 can2
->cantflg
= 0x01;
937 while ((can2
->cantflg
& 0x01) == 0) {
940 printf ("%s: CAN2 send error, "
941 "can not send message!\n",
950 while (!(can1
->canrflg
& 0x01)) {
953 printf ("%s: CAN1 receive timeout, "
954 "no message received!\n",
961 if (can1
->canrxfg
.dsr
[0] != 0xCC) {
962 printf ("%s: CAN1 receive error 0x%02x\n",
963 __FUNCTION__
, (can1
->canrxfg
.dsr
[0]));
971 * return 1 if rs232 port unknown
972 * return 2 on txd/rxd failure (only rs232 2)
973 * return 3 on rts/cts failure
974 * return 0 if no failure
976 int do_rs232(char * const argv
[])
978 int error_status
= 0;
979 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
980 struct mpc5xxx_psc
*psc1
= (struct mpc5xxx_psc
*)MPC5XXX_PSC1
;
982 switch (simple_strtoul(argv
[2], NULL
, 10)) {
985 /* check RTS <-> CTS loop */
989 /* wait some time before requesting status */
992 /* check status at cts */
993 if ((psc1
->ip
& 0x01) != 0) {
995 printf ("%s: failure at rs232_1, cts status is %d "
997 __FUNCTION__
, (psc1
->ip
& 0x01));
1003 /* wait some time before requesting status */
1006 /* check status at cts */
1007 if ((psc1
->ip
& 0x01) != 1) {
1009 printf ("%s: failure at rs232_1, cts status is %d "
1011 __FUNCTION__
, (psc1
->ip
& 0x01));
1017 /* set PSC3_0, PSC3_2 as output and PSC3_1, PSC3_3 as input */
1018 gpio
->simple_ddr
&= ~(0x00000F00);
1019 gpio
->simple_ddr
|= 0x00000500;
1021 /* check TXD <-> RXD loop */
1023 gpio
->simple_dvo
|= (1 << 8);
1025 /* wait some time before requesting status */
1028 if ((gpio
->simple_ival
& 0x00000200) != 0x00000200) {
1030 printf ("%s: failure at rs232_2, rxd status is %d "
1033 (gpio
->simple_ival
& 0x00000200) >> 9);
1037 gpio
->simple_dvo
&= ~(1 << 8);
1039 /* wait some time before requesting status */
1042 if ((gpio
->simple_ival
& 0x00000200) != 0x00000000) {
1044 printf ("%s: failure at rs232_2, rxd status is %d "
1047 (gpio
->simple_ival
& 0x00000200) >> 9);
1050 /* check RTS <-> CTS loop */
1052 gpio
->simple_dvo
|= (1 << 10);
1054 /* wait some time before requesting status */
1057 if ((gpio
->simple_ival
& 0x00000800) != 0x00000800) {
1059 printf ("%s: failure at rs232_2, cts status is %d "
1062 (gpio
->simple_ival
& 0x00000800) >> 11);
1066 gpio
->simple_dvo
&= ~(1 << 10);
1068 /* wait some time before requesting status */
1071 if ((gpio
->simple_ival
& 0x00000800) != 0x00000000) {
1073 printf ("%s: failure at rs232_2, cts status is %d "
1076 (gpio
->simple_ival
& 0x00000800) >> 11);
1079 /* set PSC3_0, PSC3_1, PSC3_2 and PSC3_3 as output */
1080 gpio
->simple_ddr
&= ~(0x00000F00);
1081 gpio
->simple_ddr
|= 0x00000F00;
1085 printf ("%s: invalid rs232 number %s\n", __FUNCTION__
, argv
[2]);
1090 return error_status
;
1093 #if !defined(CONFIG_FO300) && !defined(CONFIG_TQM5200S)
1094 static void sm501_backlight (unsigned int state
)
1096 if (state
== BL_ON
) {
1097 *(vu_long
*)(SM501_MMIO_BASE
+SM501_PANEL_DISPLAY_CONTROL
) |=
1098 (1 << 26) | (1 << 27);
1099 } else if (state
== BL_OFF
)
1100 *(vu_long
*)(SM501_MMIO_BASE
+SM501_PANEL_DISPLAY_CONTROL
) &=
1101 ~((1 << 26) | (1 << 27));
1103 #endif /* !CONFIG_FO300 & !CONFIG_TQM5200S */
1105 int cmd_fkt(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1109 #ifdef CONFIG_STK52XX_REV100
1110 printf ("Revision 100 of STK52XX not supported!\n");
1113 #if defined(CONFIG_STK52XX)
1125 if (strncmp (argv
[1], "can", 3) == 0) {
1126 rcode
= do_can (argv
);
1136 if (strncmp (argv
[1], "rs232", 3) == 0) {
1137 rcode
= do_rs232 (argv
);
1143 #if !defined(CONFIG_FO300) && !defined(CONFIG_TQM5200S)
1144 } else if (strncmp (argv
[1], "backlight", 4) == 0) {
1145 if (strncmp (argv
[2], "on", 2) == 0) {
1146 sm501_backlight (BL_ON
);
1149 else if (strncmp (argv
[2], "off", 3) == 0) {
1150 sm501_backlight (BL_OFF
);
1153 #endif /* !CONFIG_FO300 & !CONFIG_TQM5200S */
1157 #if defined(CONFIG_STK52XX)
1159 if (strcmp (argv
[1], "led") == 0) {
1160 return (do_led (argv
));
1169 printf ("Usage:\nfkt cmd [arg1] [arg2] ...\n");
1175 sound
, 5, 1, cmd_sound
,
1177 "saw [duration] [freq] [channel]\n"
1178 " - generate sawtooth for 'duration' ms with frequency 'freq'\n"
1179 " on left \"l\" or right \"r\" channel\n"
1180 "sound square [duration] [freq] [channel]\n"
1181 " - generate squarewave for 'duration' ms with frequency 'freq'\n"
1182 " on left \"l\" or right \"r\" channel\n"
1187 wav
, 3, 1, cmd_wav
,
1190 " - play wav file at address 'addr' with length 'bytes'"
1194 beep
, 2, 1, cmd_beep
,
1197 " - play short beep on \"l\"eft or \"r\"ight channel"
1199 #endif /* CONFIG_STK52XX || CONFIG_FO300 */
1201 #if defined(CONFIG_STK52XX)
1203 fkt
, 4, 1, cmd_fkt
,
1204 "Function test routines",
1205 "led number on/off\n"
1206 " - 'number's like printed on STK52XX board\n"
1208 " - loopback plug for X83 required\n"
1209 "fkt rs232 number\n"
1210 " - loopback plug(s) for X2 required"
1211 #ifndef CONFIG_TQM5200S
1213 "fkt backlight on/off\n"
1214 " - switch backlight on or off"
1215 #endif /* !CONFIG_TQM5200S */
1217 #elif defined(CONFIG_FO300)
1219 fkt
, 3, 1, cmd_fkt
,
1220 "Function test routines",
1222 " - loopback plug for X16/X29 required\n"
1223 "fkt rs232 number\n"
1224 " - loopback plug(s) for X21/X22 required"