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,
29 * TRAB board specific commands. Especially commands for burn-in and function
32 #if (CONFIG_COMMANDS & CFG_CMD_BSP)
34 /* limits for valid range of VCC5V in mV */
35 #define VCC5V_MIN 4500
36 #define VCC5V_MAX 5500
39 * Test strings for EEPROM test. Length of string 2 must not exceed length of
40 * string 1. Otherwise a buffer overrun could occur!
42 #define EEPROM_TEST_STRING_1 "0987654321 :tset a si siht"
43 #define EEPROM_TEST_STRING_2 "this is a test: 1234567890"
46 * min/max limits for valid contact temperature during burn in test (in
47 * degree Centigrade * 100)
49 #define MIN_CONTACT_TEMP -1000
50 #define MAX_CONTACT_TEMP +9000
52 /* blinking frequency of status LED */
53 #define LED_BLINK_FREQ 5
55 /* delay time between burn in cycles in seconds */
56 #ifndef BURN_IN_CYCLE_DELAY /* if not defined in include/configs/trab.h */
57 #define BURN_IN_CYCLE_DELAY 5
60 /* physical SRAM parameters */
61 #define SRAM_ADDR 0x02000000 /* GCS1 */
62 #define SRAM_SIZE 0x40000 /* 256 kByte */
64 /* CPLD-Register for controlling TRAB hardware functions */
65 #define CPLD_BUTTONS ((volatile unsigned long *)0x04020000)
66 #define CPLD_FILL_LEVEL ((volatile unsigned long *)0x04008000)
67 #define CPLD_ROTARY_SWITCH ((volatile unsigned long *)0x04018000)
68 #define CPLD_RS485_RE ((volatile unsigned long *)0x04028000)
70 /* I2C EEPROM device address */
71 #define I2C_EEPROM_DEV_ADDR 0x54
73 /* EEPROM address map */
74 #define EE_ADDR_TEST 128
75 #define EE_ADDR_MAX_CYCLES 256
76 #define EE_ADDR_STATUS 258
77 #define EE_ADDR_PASS_CYCLES 259
78 #define EE_ADDR_FIRST_ERROR_CYCLE 261
79 #define EE_ADDR_FIRST_ERROR_NUM 263
80 #define EE_ADDR_FIRST_ERROR_NAME 264
81 #define EE_ADDR_ACT_CYCLE 280
83 /* Bit definitions for ADCCON */
84 #define ADC_ENABLE_START 0x1
85 #define ADC_READ_START 0x2
87 #define ADC_INP_AIN0 (0x0 << 3)
88 #define ADC_INP_AIN1 (0x1 << 3)
89 #define ADC_INP_AIN2 (0x2 << 3)
90 #define ADC_INP_AIN3 (0x3 << 3)
91 #define ADC_INP_AIN4 (0x4 << 3)
92 #define ADC_INP_AIN5 (0x5 << 3)
93 #define ADC_INP_AIN6 (0x6 << 3)
94 #define ADC_INP_AIN7 (0x7 << 3)
95 #define ADC_PRSCEN 0x4000
96 #define ADC_ECFLG 0x800
101 extern int memory_post_tests (unsigned long start, unsigned long size);
102 extern int i2c_write (uchar, uint, int , uchar* , int);
103 extern int i2c_read (uchar, uint, int , uchar* , int);
104 extern void tsc2000_reg_init (void);
105 extern s32 tsc2000_contact_temp (void);
106 extern void spi_init(void);
108 /* function declarations */
109 int do_dip (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
110 int do_vcc5v (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
111 int do_burn_in (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
112 int do_contact_temp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
113 int do_burn_in_status (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
114 int i2c_write_multiple (uchar chip, uint addr, int alen,
115 uchar *buffer, int len);
116 int i2c_read_multiple (uchar chip, uint addr, int alen,
117 uchar *buffer, int len);
119 /* helper functions */
120 static void adc_init (void);
121 static int adc_read (unsigned int channel);
122 static int read_dip (void);
123 static int read_vcc5v (void);
124 static int test_dip (void);
125 static int test_vcc5v (void);
126 static int test_rotary_switch (void);
127 static int test_sram (void);
128 static int test_eeprom (void);
129 static int test_contact_temp (void);
130 static void led_set (unsigned int);
131 static void led_blink (void);
132 static void led_init (void);
133 static void sdelay (unsigned long seconds); /* delay in seconds */
134 static int dummy (void);
135 static int read_max_cycles(void);
136 static void test_function_table_init (void);
137 static void global_vars_init (void);
138 static int global_vars_write_to_eeprom (void);
144 u16 first_error_cycle;
146 unsigned char first_error_name[16];
149 typedef struct test_function_s {
154 /* max number of Burn In Functions */
157 /* table with burn in functions */
158 test_function_t test_function[BIF_MAX];
161 int do_burn_in (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
167 printf ("Usage:\n%s\n", cmdtp->usage);
173 test_function_table_init ();
175 if (global_vars_write_to_eeprom () != 0) {
176 printf ("%s: error writing global_vars to eeprom\n",
181 if (read_max_cycles () != 0) {
182 printf ("%s: error reading max_cycles from eeprom\n",
187 if (max_cycles == 0) {
188 printf ("%s: error, burn in max_cycles = 0\n", __FUNCTION__);
193 for (act_cycle = 1; act_cycle <= max_cycles; act_cycle++) {
196 for (i = 0; i < BIF_MAX; i++) {
198 /* call test function */
199 if ((*test_function[i].pf)() != 0) {
200 printf ("error in %s test\n",
201 test_function[i].name);
203 /* is it the first error? */
206 first_error_cycle = act_cycle;
208 /* do not use error_num 0 */
209 first_error_num = i+1;
210 strncpy (first_error_name,
211 test_function[i].name,
212 sizeof (first_error_name));
218 /* were all tests of actual cycle OK? */
219 if (cycle_status == 0)
222 /* set status LED if no error is occoured since yet */
226 printf ("%s: cycle %d finished\n", __FUNCTION__, act_cycle);
228 /* pause between cycles */
229 sdelay (BURN_IN_CYCLE_DELAY);
232 if (global_vars_write_to_eeprom () != 0) {
234 printf ("%s: error writing global_vars to eeprom\n",
240 led_blink (); /* endless loop!! */
249 burn_in, 1, 1, do_burn_in,
250 "burn_in - start burn-in test application on TRAB\n",
252 " - start burn-in test application\n"
253 " The burn-in test could took a while to finish!\n"
254 " The content of the onboard EEPROM is modified!\n"
258 int do_dip (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
263 printf ("Usage:\n%s\n", cmdtp->usage);
267 if ((dip = read_dip ()) == -1) {
271 for (i = 0; i < 4; i++) {
272 if ((dip & (1 << i)) == 0)
284 "dip - read dip switch on TRAB\n",
286 " - read state of dip switch (S1) on TRAB board\n"
287 " read sequence: 1-2-3-4; ON=1; OFF=0; e.g.: \"0100\"\n"
291 int do_vcc5v (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
296 printf ("Usage:\n%s\n", cmdtp->usage);
300 if ((vcc5v = read_vcc5v ()) == -1) {
304 printf ("%d", (vcc5v / 1000));
305 printf (".%d", (vcc5v % 1000) / 100);
306 printf ("%d V\n", (vcc5v % 100) / 10) ;
312 vcc5v, 1, 1, do_vcc5v,
313 "vcc5v - read VCC5V on TRAB\n",
315 " - read actual value of voltage VCC5V\n"
319 int do_contact_temp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
324 printf ("Usage:\n%s\n", cmdtp->usage);
331 contact_temp = tsc2000_contact_temp();
332 printf ("%d degree C * 100\n", contact_temp) ;
338 c_temp, 1, 1, do_contact_temp,
339 "c_temp - read contact temperature on TRAB\n",
341 " - reads the onboard temperature (=contact temperature)\n"
345 int do_burn_in_status (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
348 printf ("Usage:\n%s\n", cmdtp->usage);
352 if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_STATUS, 1,
353 (unsigned char*) &status, 1)) {
356 if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_PASS_CYCLES, 1,
357 (unsigned char*) &pass_cycles, 2)) {
360 if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_CYCLE,
361 1, (unsigned char*) &first_error_cycle, 2)) {
364 if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_NUM,
365 1, (unsigned char*) &first_error_num, 1)) {
368 if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_NAME,
370 sizeof (first_error_name))) {
374 if (read_max_cycles () != 0) {
378 printf ("max_cycles = %d\n", max_cycles);
379 printf ("status = %d\n", status);
380 printf ("pass_cycles = %d\n", pass_cycles);
381 printf ("first_error_cycle = %d\n", first_error_cycle);
382 printf ("first_error_num = %d\n", first_error_num);
383 printf ("first_error_name = %.*s\n",(int) sizeof(first_error_name),
390 bis, 1, 1, do_burn_in_status,
391 "bis - print burn in status on TRAB\n",
393 " - prints the status variables of the last burn in test\n"
394 " stored in the onboard EEPROM on TRAB board\n"
397 static int read_dip (void)
399 unsigned int result = 0;
403 /***********************************************************
404 DIP switch connection (according to wa4-cpu.sp.301.pdf, page 3):
410 "On" DIP switch position short-circuits the voltage from
411 the input channel (i.e. '0' conversion result means "on").
412 *************************************************************/
414 for (i = 7; i > 3; i--) {
416 if ((adc_val = adc_read (i)) == -1) {
417 printf ("%s: Channel %d could not be read\n",
423 * Input voltage (switch open) is 1.8 V.
424 * (Vin_High/VRef)*adc_res = (1,8V/2,5V)*1023) = 736
425 * Set trigger at halve that value.
428 result |= (1 << (i-4));
434 static int read_vcc5v (void)
438 /* VCC5V is connected to channel 2 */
440 if ((result = adc_read (2)) == -1) {
441 printf ("%s: VCC5V could not be read\n", __FUNCTION__);
445 * Calculate voltage value. Split in two parts because there is no
446 * floating point support. VCC5V is connected over an resistor divider:
447 * VCC5V=ADCval*2,5V/1023*(10K+30K)/10K.
449 result = result * 10 * 1000 / 1023; /* result in mV */
455 static int test_dip (void)
457 static int first_run = 1;
458 static int first_dip;
461 if ((first_dip = read_dip ()) == -1) {
465 debug ("%s: first_dip=%d\n", __FUNCTION__, first_dip);
467 if (first_dip != read_dip ()) {
475 static int test_vcc5v (void)
479 if ((vcc5v = read_vcc5v ()) == -1) {
483 if ((vcc5v > VCC5V_MAX) || (vcc5v < VCC5V_MIN)) {
491 static int test_rotary_switch (void)
493 static int first_run = 1;
498 * clear bits in CPLD, because they have random values after
501 *CPLD_ROTARY_SWITCH |= (1 << 16) | (1 << 17);
503 first_rs = ((*CPLD_ROTARY_SWITCH >> 16) & 0x7);
505 debug ("%s: first_rs=%d\n", __FUNCTION__, first_rs);
508 if (first_rs != ((*CPLD_ROTARY_SWITCH >> 16) & 0x7)) {
516 static int test_sram (void)
518 return (memory_post_tests (SRAM_ADDR, SRAM_SIZE));
522 static int test_eeprom (void)
524 unsigned char temp[sizeof (EEPROM_TEST_STRING_1)];
527 /* write test string 1, read back and verify */
528 if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_TEST, 1,
529 EEPROM_TEST_STRING_1,
530 sizeof (EEPROM_TEST_STRING_1))) {
534 if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_TEST, 1,
535 temp, sizeof (EEPROM_TEST_STRING_1))) {
539 if (strcmp (temp, EEPROM_TEST_STRING_1) != 0) {
541 printf ("%s: error; read_str = \"%s\"\n", __FUNCTION__, temp);
544 /* write test string 2, read back and verify */
546 if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_TEST, 1,
547 EEPROM_TEST_STRING_2,
548 sizeof (EEPROM_TEST_STRING_2))) {
552 if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_TEST, 1,
553 temp, sizeof (EEPROM_TEST_STRING_2))) {
557 if (strcmp (temp, EEPROM_TEST_STRING_2) != 0) {
559 printf ("%s: error; read str = \"%s\"\n",
567 static int test_contact_temp (void)
572 contact_temp = tsc2000_contact_temp ();
574 if ((contact_temp < MIN_CONTACT_TEMP)
575 || (contact_temp > MAX_CONTACT_TEMP))
582 int i2c_write_multiple (uchar chip, uint addr, int alen,
583 uchar *buffer, int len)
588 printf ("%s: addr len other than 1 not supported\n",
593 for (i = 0; i < len; i++) {
594 if (i2c_write (chip, addr+i, alen, buffer+i, 1)) {
595 printf ("%s: could not write to i2c device %d"
596 ", addr %d\n", __FUNCTION__, chip, addr);
600 printf ("chip=%#x, addr+i=%#x+%d=%p, alen=%d, *buffer+i="
601 "%#x+%d=%p=\"%.1s\"\n", chip, addr, i, addr+i,
602 alen, buffer, i, buffer+i, buffer+i);
611 int i2c_read_multiple ( uchar chip, uint addr, int alen,
612 uchar *buffer, int len)
617 printf ("%s: addr len other than 1 not supported\n",
622 for (i = 0; i < len; i++) {
623 if (i2c_read (chip, addr+i, alen, buffer+i, 1)) {
624 printf ("%s: could not read from i2c device %#x"
625 ", addr %d\n", __FUNCTION__, chip, addr);
633 static int adc_read (unsigned int channel)
635 int j = 1000; /* timeout value for wait loop in us */
638 padc = S3C2400_GetBase_ADC();
643 debug ("%s: adccon %#x\n", __FUNCTION__, padc->ADCCON);
645 padc->ADCCON &= ~ADC_STDBM; /* select normal mode */
646 padc->ADCCON &= ~(0x7 << 3); /* clear the channel bits */
647 padc->ADCCON |= ((channel << 3) | ADC_ENABLE_START);
649 debug ("%s: reading ch %d, addcon %#x\n", __FUNCTION__,
650 (padc->ADCCON >> 3) & 0x7, padc->ADCCON);
653 if ((padc->ADCCON & ADC_ENABLE_START) == 0)
659 printf("%s: ADC timeout\n", __FUNCTION__);
660 padc->ADCCON |= ADC_STDBM; /* select standby mode */
664 padc->ADCCON |= ADC_STDBM; /* select standby mode */
666 debug ("%s: return %#x, adccon %#x\n", __FUNCTION__,
667 padc->ADCDAT & 0x3FF, padc->ADCCON);
669 return (padc->ADCDAT & 0x3FF);
673 static void adc_init (void)
677 padc = S3C2400_GetBase_ADC();
679 padc->ADCCON &= ~(0xff << 6); /* clear prescaler bits */
680 padc->ADCCON |= ((65 << 6) | ADC_PRSCEN); /* set prescaler */
686 static void led_set (unsigned int state)
688 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
693 case 0: /* turn LED off */
694 gpio->PADAT |= (1 << 12);
696 case 1: /* turn LED on */
697 gpio->PADAT &= ~(1 << 12);
703 static void led_blink (void)
707 /* blink LED. This function does not return! */
710 udelay (1000000 / LED_BLINK_FREQ / 2);
712 udelay (1000000 / LED_BLINK_FREQ / 2);
717 static void led_init (void)
719 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
721 /* configure GPA12 as output and set to High -> LED off */
722 gpio->PACON &= ~(1 << 12);
723 gpio->PADAT |= (1 << 12);
727 static void sdelay (unsigned long seconds)
731 for (i = 0; i < seconds; i++) {
737 static int global_vars_write_to_eeprom (void)
739 if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_STATUS, 1,
740 (unsigned char*) &status, 1)) {
743 if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_PASS_CYCLES, 1,
744 (unsigned char*) &pass_cycles, 2)) {
747 if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_CYCLE,
748 1, (unsigned char*) &first_error_cycle, 2)) {
751 if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_NUM,
752 1, (unsigned char*) &first_error_num, 1)) {
755 if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_NAME,
757 sizeof(first_error_name))) {
763 static void global_vars_init (void)
765 status = 1; /* error */
767 first_error_cycle = 0;
769 first_error_name[0] = '\0';
775 static void test_function_table_init (void)
779 for (i = 0; i < BIF_MAX; i++)
780 test_function[i].pf = dummy;
783 * the length of "name" must not exceed 16, including the '\0'
784 * termination. See also the EEPROM address map.
786 test_function[0].pf = test_dip;
787 test_function[0].name = "dip";
789 test_function[1].pf = test_vcc5v;
790 test_function[1].name = "vcc5v";
792 test_function[2].pf = test_rotary_switch;
793 test_function[2].name = "rotary_switch";
795 test_function[3].pf = test_sram;
796 test_function[3].name = "sram";
798 test_function[4].pf = test_eeprom;
799 test_function[4].name = "eeprom";
801 test_function[5].pf = test_contact_temp;
802 test_function[5].name = "contact_temp";
806 static int read_max_cycles (void)
808 if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_MAX_CYCLES, 1,
809 (unsigned char *) &max_cycles, 2) != 0) {
816 static int dummy(void)
821 #endif /* CFG_CMD_BSP */