3 * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * STK52XX specific functions
32 #if defined(CONFIG_CMD_BSP)
34 #if defined(CONFIG_STK52XX) || defined(CONFIG_FO300)
35 #define DEFAULT_VOL 45
36 #define DEFAULT_FREQ 500
37 #define DEFAULT_DURATION 200
44 #define SM501_GPIO_CTRL_LOW 0x00000008UL
45 #define SM501_GPIO_CTRL_HIGH 0x0000000CUL
46 #define SM501_POWER_MODE0_GATE 0x00000040UL
47 #define SM501_POWER_MODE1_GATE 0x00000048UL
48 #define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
49 #define SM501_GPIO_DATA_LOW 0x00010000UL
50 #define SM501_GPIO_DATA_HIGH 0x00010004UL
51 #define SM501_GPIO_DATA_DIR_LOW 0x00010008UL
52 #define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
53 #define SM501_PANEL_DISPLAY_CONTROL 0x00080000UL
55 static int i2s_squarewave(unsigned long duration
, unsigned int freq
,
56 unsigned int channel
);
57 static int i2s_sawtooth(unsigned long duration
, unsigned int freq
,
58 unsigned int channel
);
59 static void spi_init(void);
60 static int spi_transmit(unsigned char data
);
61 static void pcm1772_write_reg(unsigned char addr
, unsigned char data
);
62 static void set_attenuation(unsigned char attenuation
);
64 static void spi_init(void)
66 struct mpc5xxx_spi
*spi
= (struct mpc5xxx_spi
*)MPC5XXX_SPI
;
67 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
69 /* PSC3 as SPI and GPIOs */
70 gpio
->port_config
&= 0xFFFFF0FF;
71 gpio
->port_config
|= 0x00000800;
73 * Its important to use the correct order when initializing the
76 spi
->ddr
= 0x0F; /* set all SPI pins as output */
77 spi
->pdr
= 0x08; /* set SS high */
78 spi
->cr1
= 0x50; /* SPI is master, SS is general purpose output */
79 spi
->cr2
= 0x00; /* normal operation */
80 spi
->brr
= 0xFF; /* baud rate: IPB clock / 2048 */
83 static int spi_transmit(unsigned char data
)
86 struct mpc5xxx_spi
*spi
= (struct mpc5xxx_spi
*)MPC5XXX_SPI
;
89 /* wait for SPI transmission completed */
90 while(!(spi
->sr
& 0x80))
92 if (spi
->sr
& 0x40) /* if write collision occured */
94 /* do dummy read to clear status register */
96 printf ("SPI write collision\n");
103 static void pcm1772_write_reg(unsigned char addr
, unsigned char data
)
105 struct mpc5xxx_spi
*spi
= (struct mpc5xxx_spi
*)MPC5XXX_SPI
;
107 spi
->pdr
= 0x00; /* Set SS low */
110 /* wait some time to meet MS# hold time of PCM1772 */
112 spi
->pdr
= 0x08; /* set SS high */
115 static void set_attenuation(unsigned char attenuation
)
117 pcm1772_write_reg(0x01, attenuation
); /* left channel */
118 debug ("PCM1772 attenuation left set to %d.\n", attenuation
);
119 pcm1772_write_reg(0x02, attenuation
); /* right channel */
120 debug ("PCM1772 attenuation right set to %d.\n", attenuation
);
123 void amplifier_init(void)
125 static int init_done
= 0;
127 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
129 /* Do this only once, because of the long time delay */
131 /* configure PCM1772 audio format as I2S */
132 pcm1772_write_reg(0x03, 0x01);
133 /* enable audio amplifier */
134 gpio
->sint_gpioe
|= 0x02; /* PSC3_5 as GPIO */
135 gpio
->sint_ode
&= ~0x02; /* PSC3_5 is not open Drain */
136 gpio
->sint_dvo
&= ~0x02; /* PSC3_5 is LOW */
137 gpio
->sint_ddr
|= 0x02; /* PSC3_5 as output */
139 * wait some time to allow amplifier to recover from shutdown
142 for(i
= 0; i
< 350; i
++)
145 * The used amplifier (LM4867) has a so called "pop and click"
146 * elmination filter. The input signal of the amplifier must
147 * exceed a certain level once after power up to activate the
148 * generation of the output signal. This is achieved by
149 * sending a low frequent (nearly inaudible) sawtooth with a
150 * sufficient signal level.
153 i2s_sawtooth (200, 5, LEFT_RIGHT
);
158 static void i2s_init(void)
161 struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)MPC5XXX_PSC2
;;
162 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
164 gpio
->port_config
|= 0x00000070; /* PSC2 ports as Codec with MCLK */
165 psc
->command
= (PSC_RX_DISABLE
| PSC_TX_DISABLE
);
166 psc
->sicr
= 0x22E00000; /* 16 bit data; I2S */
168 *(vu_long
*)(CONFIG_SYS_MBAR
+ 0x22C) = 0x805d; /* PSC2 CDM MCLK config; MCLK
170 *(vu_long
*)(CONFIG_SYS_MBAR
+ 0x214) |= 0x00000040; /* CDM clock enable
172 psc
->ccr
= 0x1F03; /* 16 bit data width; 5.617MHz MCLK */
173 psc
->ctur
= 0x0F; /* 16 bit frame width */
177 psc
->psc_buffer_32
= 0; /* clear tx fifo */
181 static int i2s_play_wave(unsigned long addr
, unsigned long len
)
184 unsigned char *wave_file
= (uchar
*)addr
+ 44; /* quick'n dirty: skip
186 unsigned char swapped
[4];
187 struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)MPC5XXX_PSC2
;
190 * play wave file in memory; bytes/words are be swapped
192 psc
->command
= (PSC_RX_ENABLE
| PSC_TX_ENABLE
);
194 for(i
= 0;i
< (len
/ 4); i
++) {
195 swapped
[3] = *wave_file
++;
196 swapped
[2] = *wave_file
++;
197 swapped
[1] = *wave_file
++;
198 swapped
[0] = *wave_file
++;
199 psc
->psc_buffer_32
= *((unsigned long*)swapped
);
200 while (psc
->tfnum
> 400) {
205 while (psc
->tfnum
> 0); /* wait for fifo empty */
207 psc
->command
= (PSC_RX_DISABLE
| PSC_TX_DISABLE
);
211 static int i2s_sawtooth(unsigned long duration
, unsigned int freq
,
212 unsigned int channel
)
216 struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)MPC5XXX_PSC2
;
218 psc
->command
= (PSC_RX_ENABLE
| PSC_TX_ENABLE
);
221 * Generate sawtooth. Start with middle level up to highest level. Then
222 * go to lowest level and back to middle level.
224 for(j
= 0; j
< ((duration
* freq
) / 1000); j
++) {
225 for(i
= 0; i
<= 0x7FFF; i
+= (0x7FFF/(44100/(freq
*4)))) {
227 /* data format: right data left data) */
228 if (channel
== LEFT_RIGHT
)
230 if (channel
== RIGHT
)
232 psc
->psc_buffer_32
= data
;
233 while (psc
->tfnum
> 400);
235 for(i
= 0x7FFF; i
>= -0x7FFF; i
-= (0xFFFF/(44100/(freq
*2)))) {
237 /* data format: right data left data) */
238 if (channel
== LEFT_RIGHT
)
240 if (channel
== RIGHT
)
242 psc
->psc_buffer_32
= data
;
243 while (psc
->tfnum
> 400);
245 for(i
= -0x7FFF; i
<= 0; i
+= (0x7FFF/(44100/(freq
*4)))) {
247 /* data format: right data left data) */
248 if (channel
== LEFT_RIGHT
)
250 if (channel
== RIGHT
)
252 psc
->psc_buffer_32
= data
;
253 while (psc
->tfnum
> 400);
256 while (psc
->tfnum
> 0); /* wait for fifo empty */
258 psc
->command
= (PSC_RX_DISABLE
| PSC_TX_DISABLE
);
263 static int i2s_squarewave(unsigned long duration
, unsigned int freq
,
264 unsigned int channel
)
268 struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)MPC5XXX_PSC2
;
270 psc
->command
= (PSC_RX_ENABLE
| PSC_TX_ENABLE
);
273 * Generate sqarewave. Start with high level, duty cycle 1:1.
275 for(j
= 0; j
< ((duration
* freq
) / 1000); j
++) {
276 for(i
= 0; i
< (44100/(freq
*2)); i
++) {
278 /* data format: right data left data) */
279 if (channel
== LEFT_RIGHT
)
281 if (channel
== RIGHT
)
283 psc
->psc_buffer_32
= data
;
284 while (psc
->tfnum
> 400);
286 for(i
= 0; i
< (44100/(freq
*2)); i
++) {
288 /* data format: right data left data) */
289 if (channel
== LEFT_RIGHT
)
291 if (channel
== RIGHT
)
293 psc
->psc_buffer_32
= data
;
294 while (psc
->tfnum
> 400);
297 while (psc
->tfnum
> 0); /* wait for fifo empty */
299 psc
->command
= (PSC_RX_DISABLE
| PSC_TX_DISABLE
);
304 static int cmd_sound(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
306 unsigned long reg
, val
, duration
;
308 unsigned int freq
, channel
;
309 unsigned char volume
;
312 #ifdef CONFIG_STK52XX_REV100
313 printf ("Revision 100 of STK52XX not supported!\n");
320 if ((tmp
= getenv ("volume")) != NULL
) {
321 volume
= simple_strtoul (tmp
, NULL
, 10);
323 volume
= DEFAULT_VOL
;
325 set_attenuation(volume
);
330 return cmd_usage(cmdtp
);
332 if (strncmp(argv
[1],"saw",3) == 0) {
333 printf ("Play sawtooth\n");
334 rcode
= i2s_sawtooth (DEFAULT_DURATION
, DEFAULT_FREQ
,
337 } else if (strncmp(argv
[1],"squ",3) == 0) {
338 printf ("Play squarewave\n");
339 rcode
= i2s_squarewave (DEFAULT_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 printf ("Play sawtooth\n");
349 rcode
= i2s_sawtooth (duration
, DEFAULT_FREQ
,
352 } else if (strncmp(argv
[1],"squ",3) == 0) {
353 duration
= simple_strtoul(argv
[2], NULL
, 10);
354 printf ("Play squarewave\n");
355 rcode
= i2s_squarewave (duration
, DEFAULT_FREQ
,
359 return cmd_usage(cmdtp
);
361 if (strncmp(argv
[1],"saw",3) == 0) {
362 duration
= simple_strtoul(argv
[2], NULL
, 10);
363 freq
= (unsigned int)simple_strtoul(argv
[3], NULL
, 10);
364 printf ("Play sawtooth\n");
365 rcode
= i2s_sawtooth (duration
, freq
,
368 } else if (strncmp(argv
[1],"squ",3) == 0) {
369 duration
= simple_strtoul(argv
[2], NULL
, 10);
370 freq
= (unsigned int)simple_strtoul(argv
[3], NULL
, 10);
371 printf ("Play squarewave\n");
372 rcode
= i2s_squarewave (duration
, freq
,
375 } else if (strcmp(argv
[1],"pcm1772") == 0) {
376 reg
= simple_strtoul(argv
[2], NULL
, 10);
377 val
= simple_strtoul(argv
[3], NULL
, 10);
378 printf("Set PCM1772 %lu. %lu\n", reg
, val
);
379 pcm1772_write_reg((uchar
)reg
, (uchar
)val
);
382 return cmd_usage(cmdtp
);
384 if (strncmp(argv
[1],"saw",3) == 0) {
385 duration
= simple_strtoul(argv
[2], NULL
, 10);
386 freq
= (unsigned int)simple_strtoul(argv
[3], NULL
, 10);
387 if (strncmp(argv
[4],"l",1) == 0)
389 else if (strncmp(argv
[4],"r",1) == 0)
392 channel
= LEFT_RIGHT
;
393 printf ("Play squarewave\n");
394 rcode
= i2s_sawtooth (duration
, freq
,
397 } else if (strncmp(argv
[1],"squ",3) == 0) {
398 duration
= simple_strtoul(argv
[2], NULL
, 10);
399 freq
= (unsigned int)simple_strtoul(argv
[3], NULL
, 10);
400 if (strncmp(argv
[4],"l",1) == 0)
402 else if (strncmp(argv
[4],"r",1) == 0)
405 channel
= LEFT_RIGHT
;
406 printf ("Play squarewave\n");
407 rcode
= i2s_squarewave (duration
, freq
,
411 return cmd_usage(cmdtp
);
413 printf ("Usage:\nsound cmd [arg1] [arg2] ...\n");
417 static int cmd_wav(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
419 unsigned long length
, addr
;
420 unsigned char volume
;
424 #ifdef CONFIG_STK52XX_REV100
425 printf ("Revision 100 of STK52XX not supported!\n");
435 length
= simple_strtoul(argv
[2], NULL
, 16);
436 addr
= simple_strtoul(argv
[1], NULL
, 16);
440 if ((tmp
= getenv ("filesize")) != NULL
) {
441 length
= simple_strtoul (tmp
, NULL
, 16);
443 puts ("No filesize provided\n");
446 addr
= simple_strtoul(argv
[1], NULL
, 16);
449 if ((tmp
= getenv ("filesize")) != NULL
) {
450 length
= simple_strtoul (tmp
, NULL
, 16);
452 puts ("No filesize provided\n");
455 if ((tmp
= getenv ("loadaddr")) != NULL
) {
456 addr
= simple_strtoul (tmp
, NULL
, 16);
458 puts ("No loadaddr provided\n");
464 printf("Usage:\nwav <addr> <length[s]\n");
469 if ((tmp
= getenv ("volume")) != NULL
) {
470 volume
= simple_strtoul (tmp
, NULL
, 10);
472 volume
= DEFAULT_VOL
;
474 set_attenuation(volume
);
476 printf("Play wave file at %lX with length %lX\n", addr
, length
);
477 rcode
= i2s_play_wave(addr
, length
);
482 static int cmd_beep(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
484 unsigned char volume
;
485 unsigned int channel
;
489 #ifdef CONFIG_STK52XX_REV100
490 printf ("Revision 100 of STK52XX not supported!\n");
500 channel
= LEFT_RIGHT
;
503 if (strncmp(argv
[1],"l",1) == 0)
505 else if (strncmp(argv
[1],"r",1) == 0)
508 channel
= LEFT_RIGHT
;
511 return cmd_usage(cmdtp
);
514 if ((tmp
= getenv ("volume")) != NULL
) {
515 volume
= simple_strtoul (tmp
, NULL
, 10);
517 volume
= DEFAULT_VOL
;
519 set_attenuation(volume
);
524 else if (channel
== RIGHT
)
527 printf ("left and right ");
528 printf ("channel\n");
530 rcode
= i2s_squarewave (DEFAULT_DURATION
, DEFAULT_FREQ
, channel
);
536 #if defined(CONFIG_STK52XX)
539 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
540 struct mpc5xxx_gpt_0_7
*gpt
= (struct mpc5xxx_gpt_0_7
*)MPC5XXX_GPT
;
542 /* configure PSC3 for SPI and GPIO */
543 gpio
->port_config
&= ~(0x00000F00);
544 gpio
->port_config
|= 0x00000800;
546 gpio
->simple_gpioe
&= ~(0x00000F00);
547 gpio
->simple_gpioe
|= 0x00000F00;
549 gpio
->simple_ddr
&= ~(0x00000F00);
550 gpio
->simple_ddr
|= 0x00000F00;
552 /* configure timer 4-7 for simple GPIO output */
553 gpt
->gpt4
.emsr
|= 0x00000024;
554 gpt
->gpt5
.emsr
|= 0x00000024;
555 gpt
->gpt6
.emsr
|= 0x00000024;
556 gpt
->gpt7
.emsr
|= 0x00000024;
558 #ifndef CONFIG_TQM5200S
559 /* enable SM501 GPIO control (in both power modes) */
560 *(vu_long
*) (SM501_MMIO_BASE
+SM501_POWER_MODE0_GATE
) |=
561 POWER_MODE_GATE_GPIO_PWM_I2C
;
562 *(vu_long
*) (SM501_MMIO_BASE
+SM501_POWER_MODE1_GATE
) |=
563 POWER_MODE_GATE_GPIO_PWM_I2C
;
565 /* configure SM501 gpio pins 24-27 as output */
566 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_CTRL_LOW
) &= ~(0xF << 24);
567 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_DIR_LOW
) |= (0xF << 24);
569 /* configure SM501 gpio pins 48-51 as output */
570 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_DIR_HIGH
) |= (0xF << 16);
571 #endif /* !CONFIG_TQM5200S */
575 * return 1 if led number unknown
578 int do_led(char * const argv
[])
580 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
581 struct mpc5xxx_gpt_0_7
*gpt
= (struct mpc5xxx_gpt_0_7
*)MPC5XXX_GPT
;
583 switch (simple_strtoul(argv
[2], NULL
, 10)) {
586 if (strcmp (argv
[3], "on") == 0) {
587 gpio
->simple_dvo
|= (1 << 8);
589 gpio
->simple_dvo
&= ~(1 << 8);
594 if (strcmp (argv
[3], "on") == 0) {
595 gpio
->simple_dvo
|= (1 << 9);
597 gpio
->simple_dvo
&= ~(1 << 9);
602 if (strcmp (argv
[3], "on") == 0) {
603 gpio
->simple_dvo
|= (1 << 10);
605 gpio
->simple_dvo
&= ~(1 << 10);
610 if (strcmp (argv
[3], "on") == 0) {
611 gpio
->simple_dvo
|= (1 << 11);
613 gpio
->simple_dvo
&= ~(1 << 11);
618 if (strcmp (argv
[3], "on") == 0) {
619 gpt
->gpt4
.emsr
|= (1 << 4);
621 gpt
->gpt4
.emsr
&= ~(1 << 4);
626 if (strcmp (argv
[3], "on") == 0) {
627 gpt
->gpt5
.emsr
|= (1 << 4);
629 gpt
->gpt5
.emsr
&= ~(1 << 4);
634 if (strcmp (argv
[3], "on") == 0) {
635 gpt
->gpt6
.emsr
|= (1 << 4);
637 gpt
->gpt6
.emsr
&= ~(1 << 4);
642 if (strcmp (argv
[3], "on") == 0) {
643 gpt
->gpt7
.emsr
|= (1 << 4);
645 gpt
->gpt7
.emsr
&= ~(1 << 4);
648 #ifndef CONFIG_TQM5200S
650 if (strcmp (argv
[3], "on") == 0) {
651 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) |=
654 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) &=
660 if (strcmp (argv
[3], "on") == 0) {
661 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) |=
664 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) &=
670 if (strcmp (argv
[3], "on") == 0) {
671 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) |=
674 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) &=
680 if (strcmp (argv
[3], "on") == 0) {
681 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) |=
684 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_LOW
) &=
690 if (strcmp (argv
[3], "on") == 0) {
691 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) |=
694 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) &=
700 if (strcmp (argv
[3], "on") == 0) {
701 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) |=
704 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) &=
710 if (strcmp (argv
[3], "on") == 0) {
711 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) |=
714 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) &=
720 if (strcmp (argv
[3], "on") == 0) {
721 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) |=
724 *(vu_long
*) (SM501_MMIO_BASE
+SM501_GPIO_DATA_HIGH
) &=
728 #endif /* !CONFIG_TQM5200S */
730 printf ("%s: invalid led number %s\n", __FUNCTION__
, argv
[2]);
738 #if defined(CONFIG_STK52XX) || defined(CONFIG_FO300)
740 * return 1 on CAN initialization failure
741 * return 0 if no failure
745 static int init_done
= 0;
747 struct mpc5xxx_mscan
*can1
=
748 (struct mpc5xxx_mscan
*)(CONFIG_SYS_MBAR
+ 0x0900);
749 struct mpc5xxx_mscan
*can2
=
750 (struct mpc5xxx_mscan
*)(CONFIG_SYS_MBAR
+ 0x0980);
752 /* GPIO configuration of the CAN pins is done in TQM5200.h */
756 can1
->canctl1
|= 0x80; /* CAN enable */
760 can1
->canctl0
|= 0x02; /* sleep mode */
761 /* wait until sleep mode reached */
762 while (!(can1
->canctl1
& 0x02)) {
766 printf ("%s: CAN1 initialize error, "
767 "can not enter sleep mode!\n",
773 can1
->canctl0
= 0x01; /* enter init mode */
774 /* wait until init mode reached */
775 while (!(can1
->canctl1
& 0x01)) {
779 printf ("%s: CAN1 initialize error, "
780 "can not enter init mode!\n",
785 can1
->canctl1
= 0x80;
786 can1
->canctl1
|= 0x40;
787 can1
->canbtr0
= 0x0F;
788 can1
->canbtr1
= 0x7F;
789 can1
->canidac
&= ~(0x30);
790 can1
->canidar1
= 0x00;
791 can1
->canidar3
= 0x00;
792 can1
->canidar5
= 0x00;
793 can1
->canidar7
= 0x00;
794 can1
->canidmr0
= 0xFF;
795 can1
->canidmr1
= 0xFF;
796 can1
->canidmr2
= 0xFF;
797 can1
->canidmr3
= 0xFF;
798 can1
->canidmr4
= 0xFF;
799 can1
->canidmr5
= 0xFF;
800 can1
->canidmr6
= 0xFF;
801 can1
->canidmr7
= 0xFF;
804 can1
->canctl0
&= ~(0x01); /* leave init mode */
805 can1
->canctl0
&= ~(0x02);
806 /* wait until init and sleep mode left */
807 while ((can1
->canctl1
& 0x01) || (can1
->canctl1
& 0x02)) {
811 printf ("%s: CAN1 initialize error, "
812 "can not leave init/sleep mode!\n",
819 can2
->canctl1
|= 0x80; /* CAN enable */
823 can2
->canctl0
|= 0x02; /* sleep mode */
824 /* wait until sleep mode reached */
825 while (!(can2
->canctl1
& 0x02)) {
829 printf ("%s: CAN2 initialize error, "
830 "can not enter sleep mode!\n",
836 can2
->canctl0
= 0x01; /* enter init mode */
837 /* wait until init mode reached */
838 while (!(can2
->canctl1
& 0x01)) {
842 printf ("%s: CAN2 initialize error, "
843 "can not enter init mode!\n",
848 can2
->canctl1
= 0x80;
849 can2
->canctl1
|= 0x40;
850 can2
->canbtr0
= 0x0F;
851 can2
->canbtr1
= 0x7F;
852 can2
->canidac
&= ~(0x30);
853 can2
->canidar1
= 0x00;
854 can2
->canidar3
= 0x00;
855 can2
->canidar5
= 0x00;
856 can2
->canidar7
= 0x00;
857 can2
->canidmr0
= 0xFF;
858 can2
->canidmr1
= 0xFF;
859 can2
->canidmr2
= 0xFF;
860 can2
->canidmr3
= 0xFF;
861 can2
->canidmr4
= 0xFF;
862 can2
->canidmr5
= 0xFF;
863 can2
->canidmr6
= 0xFF;
864 can2
->canidmr7
= 0xFF;
865 can2
->canctl0
&= ~(0x01); /* leave init mode */
866 can2
->canctl0
&= ~(0x02);
869 /* wait until init mode left */
870 while ((can2
->canctl1
& 0x01) || (can2
->canctl1
& 0x02)) {
874 printf ("%s: CAN2 initialize error, "
875 "can not leave init/sleep mode!\n",
886 * return 1 on CAN failure
887 * return 0 if no failure
889 int do_can(char * const argv
[])
892 struct mpc5xxx_mscan
*can1
=
893 (struct mpc5xxx_mscan
*)(CONFIG_SYS_MBAR
+ 0x0900);
894 struct mpc5xxx_mscan
*can2
=
895 (struct mpc5xxx_mscan
*)(CONFIG_SYS_MBAR
+ 0x0980);
897 /* send a message on CAN1 */
898 can1
->cantbsel
= 0x01;
899 can1
->cantxfg
.idr
[0] = 0x55;
900 can1
->cantxfg
.idr
[1] = 0x00;
901 can1
->cantxfg
.idr
[1] &= ~0x8;
902 can1
->cantxfg
.idr
[1] &= ~0x10;
903 can1
->cantxfg
.dsr
[0] = 0xCC;
904 can1
->cantxfg
.dlr
= 1;
905 can1
->cantxfg
.tbpr
= 0;
906 can1
->cantflg
= 0x01;
909 while ((can1
->cantflg
& 0x01) == 0) {
912 printf ("%s: CAN1 send timeout, "
913 "can not send message!\n",
922 while (!(can2
->canrflg
& 0x01)) {
925 printf ("%s: CAN2 receive timeout, "
926 "no message received!\n",
933 if (can2
->canrxfg
.dsr
[0] != 0xCC) {
934 printf ("%s: CAN2 receive error, "
940 /* send a message on CAN2 */
941 can2
->cantbsel
= 0x01;
942 can2
->cantxfg
.idr
[0] = 0x55;
943 can2
->cantxfg
.idr
[1] = 0x00;
944 can2
->cantxfg
.idr
[1] &= ~0x8;
945 can2
->cantxfg
.idr
[1] &= ~0x10;
946 can2
->cantxfg
.dsr
[0] = 0xCC;
947 can2
->cantxfg
.dlr
= 1;
948 can2
->cantxfg
.tbpr
= 0;
949 can2
->cantflg
= 0x01;
952 while ((can2
->cantflg
& 0x01) == 0) {
955 printf ("%s: CAN2 send error, "
956 "can not send message!\n",
965 while (!(can1
->canrflg
& 0x01)) {
968 printf ("%s: CAN1 receive timeout, "
969 "no message received!\n",
976 if (can1
->canrxfg
.dsr
[0] != 0xCC) {
977 printf ("%s: CAN1 receive error 0x%02x\n",
978 __FUNCTION__
, (can1
->canrxfg
.dsr
[0]));
986 * return 1 if rs232 port unknown
987 * return 2 on txd/rxd failure (only rs232 2)
988 * return 3 on rts/cts failure
989 * return 0 if no failure
991 int do_rs232(char * const argv
[])
993 int error_status
= 0;
994 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
995 struct mpc5xxx_psc
*psc1
= (struct mpc5xxx_psc
*)MPC5XXX_PSC1
;
997 switch (simple_strtoul(argv
[2], NULL
, 10)) {
1000 /* check RTS <-> CTS loop */
1004 /* wait some time before requesting status */
1007 /* check status at cts */
1008 if ((psc1
->ip
& 0x01) != 0) {
1010 printf ("%s: failure at rs232_1, cts status is %d "
1012 __FUNCTION__
, (psc1
->ip
& 0x01));
1018 /* wait some time before requesting status */
1021 /* check status at cts */
1022 if ((psc1
->ip
& 0x01) != 1) {
1024 printf ("%s: failure at rs232_1, cts status is %d "
1026 __FUNCTION__
, (psc1
->ip
& 0x01));
1032 /* set PSC3_0, PSC3_2 as output and PSC3_1, PSC3_3 as input */
1033 gpio
->simple_ddr
&= ~(0x00000F00);
1034 gpio
->simple_ddr
|= 0x00000500;
1036 /* check TXD <-> RXD loop */
1038 gpio
->simple_dvo
|= (1 << 8);
1040 /* wait some time before requesting status */
1043 if ((gpio
->simple_ival
& 0x00000200) != 0x00000200) {
1045 printf ("%s: failure at rs232_2, rxd status is %d "
1048 (gpio
->simple_ival
& 0x00000200) >> 9);
1052 gpio
->simple_dvo
&= ~(1 << 8);
1054 /* wait some time before requesting status */
1057 if ((gpio
->simple_ival
& 0x00000200) != 0x00000000) {
1059 printf ("%s: failure at rs232_2, rxd status is %d "
1062 (gpio
->simple_ival
& 0x00000200) >> 9);
1065 /* check RTS <-> CTS loop */
1067 gpio
->simple_dvo
|= (1 << 10);
1069 /* wait some time before requesting status */
1072 if ((gpio
->simple_ival
& 0x00000800) != 0x00000800) {
1074 printf ("%s: failure at rs232_2, cts status is %d "
1077 (gpio
->simple_ival
& 0x00000800) >> 11);
1081 gpio
->simple_dvo
&= ~(1 << 10);
1083 /* wait some time before requesting status */
1086 if ((gpio
->simple_ival
& 0x00000800) != 0x00000000) {
1088 printf ("%s: failure at rs232_2, cts status is %d "
1091 (gpio
->simple_ival
& 0x00000800) >> 11);
1094 /* set PSC3_0, PSC3_1, PSC3_2 and PSC3_3 as output */
1095 gpio
->simple_ddr
&= ~(0x00000F00);
1096 gpio
->simple_ddr
|= 0x00000F00;
1100 printf ("%s: invalid rs232 number %s\n", __FUNCTION__
, argv
[2]);
1105 return error_status
;
1108 #if !defined(CONFIG_FO300) && !defined(CONFIG_TQM5200S)
1109 static void sm501_backlight (unsigned int state
)
1111 if (state
== BL_ON
) {
1112 *(vu_long
*)(SM501_MMIO_BASE
+SM501_PANEL_DISPLAY_CONTROL
) |=
1113 (1 << 26) | (1 << 27);
1114 } else if (state
== BL_OFF
)
1115 *(vu_long
*)(SM501_MMIO_BASE
+SM501_PANEL_DISPLAY_CONTROL
) &=
1116 ~((1 << 26) | (1 << 27));
1118 #endif /* !CONFIG_FO300 & !CONFIG_TQM5200S */
1120 int cmd_fkt(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1124 #ifdef CONFIG_STK52XX_REV100
1125 printf ("Revision 100 of STK52XX not supported!\n");
1128 #if defined(CONFIG_STK52XX)
1140 if (strncmp (argv
[1], "can", 3) == 0) {
1141 rcode
= do_can (argv
);
1151 if (strncmp (argv
[1], "rs232", 3) == 0) {
1152 rcode
= do_rs232 (argv
);
1158 #if !defined(CONFIG_FO300) && !defined(CONFIG_TQM5200S)
1159 } else if (strncmp (argv
[1], "backlight", 4) == 0) {
1160 if (strncmp (argv
[2], "on", 2) == 0) {
1161 sm501_backlight (BL_ON
);
1164 else if (strncmp (argv
[2], "off", 3) == 0) {
1165 sm501_backlight (BL_OFF
);
1168 #endif /* !CONFIG_FO300 & !CONFIG_TQM5200S */
1172 #if defined(CONFIG_STK52XX)
1174 if (strcmp (argv
[1], "led") == 0) {
1175 return (do_led (argv
));
1184 printf ("Usage:\nfkt cmd [arg1] [arg2] ...\n");
1190 sound
, 5, 1, cmd_sound
,
1192 "saw [duration] [freq] [channel]\n"
1193 " - generate sawtooth for 'duration' ms with frequency 'freq'\n"
1194 " on left \"l\" or right \"r\" channel\n"
1195 "sound square [duration] [freq] [channel]\n"
1196 " - generate squarewave for 'duration' ms with frequency 'freq'\n"
1197 " on left \"l\" or right \"r\" channel\n"
1202 wav
, 3, 1, cmd_wav
,
1205 " - play wav file at address 'addr' with length 'bytes'"
1209 beep
, 2, 1, cmd_beep
,
1212 " - play short beep on \"l\"eft or \"r\"ight channel"
1214 #endif /* CONFIG_STK52XX || CONFIG_FO300 */
1216 #if defined(CONFIG_STK52XX)
1218 fkt
, 4, 1, cmd_fkt
,
1219 "Function test routines",
1220 "led number on/off\n"
1221 " - 'number's like printed on STK52XX board\n"
1223 " - loopback plug for X83 required\n"
1224 "fkt rs232 number\n"
1225 " - loopback plug(s) for X2 required"
1226 #ifndef CONFIG_TQM5200S
1228 "fkt backlight on/off\n"
1229 " - switch backlight on or off"
1230 #endif /* !CONFIG_TQM5200S */
1232 #elif defined(CONFIG_FO300)
1234 fkt
, 3, 1, cmd_fkt
,
1235 "Function test routines",
1237 " - loopback plug for X16/X29 required\n"
1238 "fkt rs232 number\n"
1239 " - loopback plug(s) for X21/X22 required"