wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 24 | #undef DEBUG |
| 25 | |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 26 | #include <common.h> |
| 27 | #include <command.h> |
| 28 | #include <s3c2400.h> |
| 29 | |
| 30 | /* |
| 31 | * TRAB board specific commands. Especially commands for burn-in and function |
| 32 | * test. |
| 33 | */ |
| 34 | #if (CONFIG_COMMANDS & CFG_CMD_BSP) |
| 35 | |
| 36 | /* limits for valid range of VCC5V in mV */ |
| 37 | #define VCC5V_MIN 4500 |
| 38 | #define VCC5V_MAX 5500 |
| 39 | |
| 40 | /* |
| 41 | * Test strings for EEPROM test. Length of string 2 must not exceed length of |
| 42 | * string 1. Otherwise a buffer overrun could occur! |
| 43 | */ |
| 44 | #define EEPROM_TEST_STRING_1 "0987654321 :tset a si siht" |
| 45 | #define EEPROM_TEST_STRING_2 "this is a test: 1234567890" |
| 46 | |
| 47 | /* |
| 48 | * min/max limits for valid contact temperature during burn in test (in |
| 49 | * degree Centigrade * 100) |
| 50 | */ |
| 51 | #define MIN_CONTACT_TEMP -1000 |
| 52 | #define MAX_CONTACT_TEMP +9000 |
| 53 | |
| 54 | /* blinking frequency of status LED */ |
| 55 | #define LED_BLINK_FREQ 5 |
| 56 | |
| 57 | /* delay time between burn in cycles in seconds */ |
| 58 | #ifndef BURN_IN_CYCLE_DELAY /* if not defined in include/configs/trab.h */ |
| 59 | #define BURN_IN_CYCLE_DELAY 5 |
| 60 | #endif |
| 61 | |
| 62 | /* physical SRAM parameters */ |
| 63 | #define SRAM_ADDR 0x02000000 /* GCS1 */ |
| 64 | #define SRAM_SIZE 0x40000 /* 256 kByte */ |
| 65 | |
| 66 | /* CPLD-Register for controlling TRAB hardware functions */ |
| 67 | #define CPLD_BUTTONS ((volatile unsigned long *)0x04020000) |
| 68 | #define CPLD_FILL_LEVEL ((volatile unsigned long *)0x04008000) |
| 69 | #define CPLD_ROTARY_SWITCH ((volatile unsigned long *)0x04018000) |
| 70 | #define CPLD_RS485_RE ((volatile unsigned long *)0x04028000) |
| 71 | |
| 72 | /* I2C EEPROM device address */ |
| 73 | #define I2C_EEPROM_DEV_ADDR 0x54 |
| 74 | |
| 75 | /* EEPROM address map */ |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 76 | #define EE_ADDR_TEST 192 |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 77 | #define EE_ADDR_MAX_CYCLES 256 |
| 78 | #define EE_ADDR_STATUS 258 |
| 79 | #define EE_ADDR_PASS_CYCLES 259 |
| 80 | #define EE_ADDR_FIRST_ERROR_CYCLE 261 |
| 81 | #define EE_ADDR_FIRST_ERROR_NUM 263 |
| 82 | #define EE_ADDR_FIRST_ERROR_NAME 264 |
| 83 | #define EE_ADDR_ACT_CYCLE 280 |
| 84 | |
| 85 | /* Bit definitions for ADCCON */ |
| 86 | #define ADC_ENABLE_START 0x1 |
| 87 | #define ADC_READ_START 0x2 |
| 88 | #define ADC_STDBM 0x4 |
| 89 | #define ADC_INP_AIN0 (0x0 << 3) |
| 90 | #define ADC_INP_AIN1 (0x1 << 3) |
| 91 | #define ADC_INP_AIN2 (0x2 << 3) |
| 92 | #define ADC_INP_AIN3 (0x3 << 3) |
| 93 | #define ADC_INP_AIN4 (0x4 << 3) |
| 94 | #define ADC_INP_AIN5 (0x5 << 3) |
| 95 | #define ADC_INP_AIN6 (0x6 << 3) |
| 96 | #define ADC_INP_AIN7 (0x7 << 3) |
| 97 | #define ADC_PRSCEN 0x4000 |
| 98 | #define ADC_ECFLG 0x800 |
| 99 | |
| 100 | /* misc */ |
| 101 | |
| 102 | /* externals */ |
| 103 | extern int memory_post_tests (unsigned long start, unsigned long size); |
| 104 | extern int i2c_write (uchar, uint, int , uchar* , int); |
| 105 | extern int i2c_read (uchar, uint, int , uchar* , int); |
| 106 | extern void tsc2000_reg_init (void); |
| 107 | extern s32 tsc2000_contact_temp (void); |
| 108 | extern void spi_init(void); |
| 109 | |
| 110 | /* function declarations */ |
| 111 | int do_dip (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 112 | int do_vcc5v (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 113 | int do_burn_in (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 114 | int do_contact_temp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 115 | int do_burn_in_status (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 116 | int i2c_write_multiple (uchar chip, uint addr, int alen, |
| 117 | uchar *buffer, int len); |
| 118 | int i2c_read_multiple (uchar chip, uint addr, int alen, |
| 119 | uchar *buffer, int len); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 120 | |
| 121 | /* helper functions */ |
| 122 | static void adc_init (void); |
| 123 | static int adc_read (unsigned int channel); |
| 124 | static int read_dip (void); |
| 125 | static int read_vcc5v (void); |
| 126 | static int test_dip (void); |
| 127 | static int test_vcc5v (void); |
| 128 | static int test_rotary_switch (void); |
| 129 | static int test_sram (void); |
| 130 | static int test_eeprom (void); |
| 131 | static int test_contact_temp (void); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 132 | static void led_set (unsigned int); |
| 133 | static void led_blink (void); |
| 134 | static void led_init (void); |
| 135 | static void sdelay (unsigned long seconds); /* delay in seconds */ |
| 136 | static int dummy (void); |
| 137 | static int read_max_cycles(void); |
| 138 | static void test_function_table_init (void); |
| 139 | static void global_vars_init (void); |
| 140 | static int global_vars_write_to_eeprom (void); |
| 141 | |
| 142 | /* globals */ |
| 143 | u16 max_cycles; |
| 144 | u8 status; |
| 145 | u16 pass_cycles; |
| 146 | u16 first_error_cycle; |
| 147 | u8 first_error_num; |
| 148 | unsigned char first_error_name[16]; |
| 149 | u16 act_cycle; |
| 150 | |
| 151 | typedef struct test_function_s { |
| 152 | unsigned char *name; |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 153 | int (*pf)(void); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 154 | } test_function_t; |
| 155 | |
| 156 | /* max number of Burn In Functions */ |
| 157 | #define BIF_MAX 6 |
| 158 | |
| 159 | /* table with burn in functions */ |
| 160 | test_function_t test_function[BIF_MAX]; |
| 161 | |
| 162 | |
| 163 | int do_burn_in (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 164 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 165 | int i; |
| 166 | int cycle_status; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 167 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 168 | if (argc > 1) { |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 169 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 170 | return 1; |
| 171 | } |
| 172 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 173 | led_init (); |
| 174 | global_vars_init (); |
| 175 | test_function_table_init (); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 176 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 177 | if (global_vars_write_to_eeprom () != 0) { |
| 178 | printf ("%s: error writing global_vars to eeprom\n", |
| 179 | __FUNCTION__); |
| 180 | return (1); |
| 181 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 182 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 183 | if (read_max_cycles () != 0) { |
| 184 | printf ("%s: error reading max_cycles from eeprom\n", |
| 185 | __FUNCTION__); |
| 186 | return (1); |
| 187 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 188 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 189 | if (max_cycles == 0) { |
| 190 | printf ("%s: error, burn in max_cycles = 0\n", __FUNCTION__); |
| 191 | return (1); |
| 192 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 193 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 194 | status = 0; |
| 195 | for (act_cycle = 1; act_cycle <= max_cycles; act_cycle++) { |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 196 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 197 | cycle_status = 0; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 198 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 199 | /* |
| 200 | * avoid timestamp overflow problem after about 68 minutes of |
| 201 | * udelay() time. |
| 202 | */ |
| 203 | reset_timer_masked (); |
| 204 | for (i = 0; i < BIF_MAX; i++) { |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 205 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 206 | /* call test function */ |
| 207 | if ((*test_function[i].pf)() != 0) { |
| 208 | printf ("error in %s test\n", |
| 209 | test_function[i].name); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 210 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 211 | /* is it the first error? */ |
| 212 | if (status == 0) { |
| 213 | status = 1; |
| 214 | first_error_cycle = act_cycle; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 215 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 216 | /* do not use error_num 0 */ |
| 217 | first_error_num = i+1; |
| 218 | strncpy (first_error_name, |
| 219 | test_function[i].name, |
| 220 | sizeof (first_error_name)); |
| 221 | led_set (0); |
| 222 | } |
| 223 | cycle_status = 1; |
| 224 | } |
| 225 | } |
| 226 | /* were all tests of actual cycle OK? */ |
| 227 | if (cycle_status == 0) |
| 228 | pass_cycles++; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 229 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 230 | /* set status LED if no error is occoured since yet */ |
| 231 | if (status == 0) |
| 232 | led_set (1); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 233 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 234 | printf ("%s: cycle %d finished\n", __FUNCTION__, act_cycle); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 235 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 236 | /* pause between cycles */ |
| 237 | sdelay (BURN_IN_CYCLE_DELAY); |
| 238 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 239 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 240 | if (global_vars_write_to_eeprom () != 0) { |
| 241 | led_set (0); |
| 242 | printf ("%s: error writing global_vars to eeprom\n", |
| 243 | __FUNCTION__); |
| 244 | status = 1; |
| 245 | } |
| 246 | |
| 247 | if (status == 0) { |
| 248 | led_blink (); /* endless loop!! */ |
| 249 | return (0); |
| 250 | } else { |
| 251 | led_set (0); |
| 252 | return (1); |
| 253 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | U_BOOT_CMD( |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 257 | burn_in, 1, 1, do_burn_in, |
| 258 | "burn_in - start burn-in test application on TRAB\n", |
| 259 | "\n" |
| 260 | " - start burn-in test application\n" |
| 261 | " The burn-in test could took a while to finish!\n" |
| 262 | " The content of the onboard EEPROM is modified!\n" |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 263 | ); |
| 264 | |
| 265 | |
| 266 | int do_dip (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 267 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 268 | int i, dip; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 269 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 270 | if (argc > 1) { |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 271 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 272 | return 1; |
| 273 | } |
| 274 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 275 | if ((dip = read_dip ()) == -1) { |
| 276 | return 1; |
| 277 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 278 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 279 | for (i = 0; i < 4; i++) { |
| 280 | if ((dip & (1 << i)) == 0) |
| 281 | printf("0"); |
| 282 | else |
| 283 | printf("1"); |
| 284 | } |
| 285 | printf("\n"); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | U_BOOT_CMD( |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 291 | dip, 1, 1, do_dip, |
| 292 | "dip - read dip switch on TRAB\n", |
| 293 | "\n" |
| 294 | " - read state of dip switch (S1) on TRAB board\n" |
| 295 | " read sequence: 1-2-3-4; ON=1; OFF=0; e.g.: \"0100\"\n" |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 296 | ); |
| 297 | |
| 298 | |
| 299 | int do_vcc5v (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 300 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 301 | int vcc5v; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 302 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 303 | if (argc > 1) { |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 304 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 305 | return 1; |
| 306 | } |
| 307 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 308 | if ((vcc5v = read_vcc5v ()) == -1) { |
| 309 | return (1); |
| 310 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 311 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 312 | printf ("%d", (vcc5v / 1000)); |
| 313 | printf (".%d", (vcc5v % 1000) / 100); |
| 314 | printf ("%d V\n", (vcc5v % 100) / 10) ; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | U_BOOT_CMD( |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 320 | vcc5v, 1, 1, do_vcc5v, |
| 321 | "vcc5v - read VCC5V on TRAB\n", |
| 322 | "\n" |
| 323 | " - read actual value of voltage VCC5V\n" |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 324 | ); |
| 325 | |
| 326 | |
| 327 | int do_contact_temp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 328 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 329 | int contact_temp; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 330 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 331 | if (argc > 1) { |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 332 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 333 | return 1; |
| 334 | } |
| 335 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 336 | spi_init (); |
| 337 | tsc2000_reg_init (); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 338 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 339 | contact_temp = tsc2000_contact_temp(); |
| 340 | printf ("%d degree C * 100\n", contact_temp) ; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | U_BOOT_CMD( |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 346 | c_temp, 1, 1, do_contact_temp, |
| 347 | "c_temp - read contact temperature on TRAB\n", |
| 348 | "\n" |
| 349 | " - reads the onboard temperature (=contact temperature)\n" |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 350 | ); |
| 351 | |
| 352 | |
| 353 | int do_burn_in_status (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 354 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 355 | if (argc > 1) { |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 356 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 357 | return 1; |
| 358 | } |
| 359 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 360 | if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_STATUS, 1, |
| 361 | (unsigned char*) &status, 1)) { |
| 362 | return (1); |
| 363 | } |
| 364 | if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_PASS_CYCLES, 1, |
| 365 | (unsigned char*) &pass_cycles, 2)) { |
| 366 | return (1); |
| 367 | } |
| 368 | if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_CYCLE, |
| 369 | 1, (unsigned char*) &first_error_cycle, 2)) { |
| 370 | return (1); |
| 371 | } |
| 372 | if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_NUM, |
| 373 | 1, (unsigned char*) &first_error_num, 1)) { |
| 374 | return (1); |
| 375 | } |
| 376 | if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_NAME, |
| 377 | 1, first_error_name, |
| 378 | sizeof (first_error_name))) { |
| 379 | return (1); |
| 380 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 381 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 382 | if (read_max_cycles () != 0) { |
| 383 | return (1); |
| 384 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 385 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 386 | printf ("max_cycles = %d\n", max_cycles); |
| 387 | printf ("status = %d\n", status); |
| 388 | printf ("pass_cycles = %d\n", pass_cycles); |
| 389 | printf ("first_error_cycle = %d\n", first_error_cycle); |
| 390 | printf ("first_error_num = %d\n", first_error_num); |
| 391 | printf ("first_error_name = %.*s\n",(int) sizeof(first_error_name), |
| 392 | first_error_name); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | U_BOOT_CMD( |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 398 | bis, 1, 1, do_burn_in_status, |
| 399 | "bis - print burn in status on TRAB\n", |
| 400 | "\n" |
| 401 | " - prints the status variables of the last burn in test\n" |
| 402 | " stored in the onboard EEPROM on TRAB board\n" |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 403 | ); |
| 404 | |
| 405 | static int read_dip (void) |
| 406 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 407 | unsigned int result = 0; |
| 408 | int adc_val; |
| 409 | int i; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 410 | |
| 411 | /*********************************************************** |
| 412 | DIP switch connection (according to wa4-cpu.sp.301.pdf, page 3): |
| 413 | SW1 - AIN4 |
| 414 | SW2 - AIN5 |
| 415 | SW3 - AIN6 |
| 416 | SW4 - AIN7 |
| 417 | |
| 418 | "On" DIP switch position short-circuits the voltage from |
| 419 | the input channel (i.e. '0' conversion result means "on"). |
| 420 | *************************************************************/ |
| 421 | |
| 422 | for (i = 7; i > 3; i--) { |
| 423 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 424 | if ((adc_val = adc_read (i)) == -1) { |
| 425 | printf ("%s: Channel %d could not be read\n", |
| 426 | __FUNCTION__, i); |
| 427 | return (-1); |
| 428 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 429 | |
| 430 | /* |
| 431 | * Input voltage (switch open) is 1.8 V. |
| 432 | * (Vin_High/VRef)*adc_res = (1,8V/2,5V)*1023) = 736 |
| 433 | * Set trigger at halve that value. |
| 434 | */ |
| 435 | if (adc_val < 368) |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 436 | result |= (1 << (i-4)); |
| 437 | } |
| 438 | return (result); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | |
| 442 | static int read_vcc5v (void) |
| 443 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 444 | s32 result; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 445 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 446 | /* VCC5V is connected to channel 2 */ |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 447 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 448 | if ((result = adc_read (2)) == -1) { |
| 449 | printf ("%s: VCC5V could not be read\n", __FUNCTION__); |
| 450 | return (-1); |
| 451 | } |
| 452 | /* |
| 453 | * Calculate voltage value. Split in two parts because there is no |
| 454 | * floating point support. VCC5V is connected over an resistor divider: |
| 455 | * VCC5V=ADCval*2,5V/1023*(10K+30K)/10K. |
| 456 | */ |
| 457 | result = result * 10 * 1000 / 1023; /* result in mV */ |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 458 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 459 | return (result); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | |
| 463 | static int test_dip (void) |
| 464 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 465 | static int first_run = 1; |
| 466 | static int first_dip; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 467 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 468 | if (first_run) { |
| 469 | if ((first_dip = read_dip ()) == -1) { |
| 470 | return (1); |
| 471 | } |
| 472 | first_run = 0; |
| 473 | debug ("%s: first_dip=%d\n", __FUNCTION__, first_dip); |
| 474 | } |
| 475 | if (first_dip != read_dip ()) { |
| 476 | return (1); |
| 477 | } else { |
| 478 | return (0); |
| 479 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | |
| 483 | static int test_vcc5v (void) |
| 484 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 485 | int vcc5v; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 486 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 487 | if ((vcc5v = read_vcc5v ()) == -1) { |
| 488 | return (1); |
| 489 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 490 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 491 | if ((vcc5v > VCC5V_MAX) || (vcc5v < VCC5V_MIN)) { |
| 492 | printf ("%s: vcc5v[V/100]=%d\n", __FUNCTION__, vcc5v); |
| 493 | return (1); |
| 494 | } else { |
| 495 | return (0); |
| 496 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | |
| 500 | static int test_rotary_switch (void) |
| 501 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 502 | static int first_run = 1; |
| 503 | static int first_rs; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 504 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 505 | if (first_run) { |
| 506 | /* |
| 507 | * clear bits in CPLD, because they have random values after |
| 508 | * power-up or reset. |
| 509 | */ |
| 510 | *CPLD_ROTARY_SWITCH |= (1 << 16) | (1 << 17); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 511 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 512 | first_rs = ((*CPLD_ROTARY_SWITCH >> 16) & 0x7); |
| 513 | first_run = 0; |
| 514 | debug ("%s: first_rs=%d\n", __FUNCTION__, first_rs); |
| 515 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 516 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 517 | if (first_rs != ((*CPLD_ROTARY_SWITCH >> 16) & 0x7)) { |
| 518 | return (1); |
| 519 | } else { |
| 520 | return (0); |
| 521 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | |
| 525 | static int test_sram (void) |
| 526 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 527 | return (memory_post_tests (SRAM_ADDR, SRAM_SIZE)); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | |
| 531 | static int test_eeprom (void) |
| 532 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 533 | unsigned char temp[sizeof (EEPROM_TEST_STRING_1)]; |
| 534 | int result = 0; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 535 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 536 | /* write test string 1, read back and verify */ |
| 537 | if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_TEST, 1, |
| 538 | EEPROM_TEST_STRING_1, |
| 539 | sizeof (EEPROM_TEST_STRING_1))) { |
| 540 | return (1); |
| 541 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 542 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 543 | if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_TEST, 1, |
| 544 | temp, sizeof (EEPROM_TEST_STRING_1))) { |
| 545 | return (1); |
| 546 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 547 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 548 | if (strcmp (temp, EEPROM_TEST_STRING_1) != 0) { |
| 549 | result = 1; |
| 550 | printf ("%s: error; read_str = \"%s\"\n", __FUNCTION__, temp); |
| 551 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 552 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 553 | /* write test string 2, read back and verify */ |
| 554 | if (result == 0) { |
| 555 | if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_TEST, 1, |
| 556 | EEPROM_TEST_STRING_2, |
| 557 | sizeof (EEPROM_TEST_STRING_2))) { |
| 558 | return (1); |
| 559 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 560 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 561 | if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_TEST, 1, |
| 562 | temp, sizeof (EEPROM_TEST_STRING_2))) { |
| 563 | return (1); |
| 564 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 565 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 566 | if (strcmp (temp, EEPROM_TEST_STRING_2) != 0) { |
| 567 | result = 1; |
| 568 | printf ("%s: error; read str = \"%s\"\n", |
| 569 | __FUNCTION__, temp); |
| 570 | } |
| 571 | } |
| 572 | return (result); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | |
| 576 | static int test_contact_temp (void) |
| 577 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 578 | int contact_temp; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 579 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 580 | spi_init (); |
| 581 | contact_temp = tsc2000_contact_temp (); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 582 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 583 | if ((contact_temp < MIN_CONTACT_TEMP) |
| 584 | || (contact_temp > MAX_CONTACT_TEMP)) |
| 585 | return (1); |
| 586 | else |
| 587 | return (0); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 591 | int i2c_write_multiple (uchar chip, uint addr, int alen, |
| 592 | uchar *buffer, int len) |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 593 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 594 | int i; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 595 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 596 | if (alen != 1) { |
| 597 | printf ("%s: addr len other than 1 not supported\n", |
| 598 | __FUNCTION__); |
| 599 | return (1); |
| 600 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 601 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 602 | for (i = 0; i < len; i++) { |
| 603 | if (i2c_write (chip, addr+i, alen, buffer+i, 1)) { |
| 604 | printf ("%s: could not write to i2c device %d" |
| 605 | ", addr %d\n", __FUNCTION__, chip, addr); |
| 606 | return (1); |
| 607 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 608 | #if 0 |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 609 | printf ("chip=%#x, addr+i=%#x+%d=%p, alen=%d, *buffer+i=" |
| 610 | "%#x+%d=%p=\"%.1s\"\n", chip, addr, i, addr+i, |
| 611 | alen, buffer, i, buffer+i, buffer+i); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 612 | #endif |
| 613 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 614 | udelay (30000); |
| 615 | } |
| 616 | return (0); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 620 | int i2c_read_multiple ( uchar chip, uint addr, int alen, |
| 621 | uchar *buffer, int len) |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 622 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 623 | int i; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 624 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 625 | if (alen != 1) { |
| 626 | printf ("%s: addr len other than 1 not supported\n", |
| 627 | __FUNCTION__); |
| 628 | return (1); |
| 629 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 630 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 631 | for (i = 0; i < len; i++) { |
| 632 | if (i2c_read (chip, addr+i, alen, buffer+i, 1)) { |
| 633 | printf ("%s: could not read from i2c device %#x" |
| 634 | ", addr %d\n", __FUNCTION__, chip, addr); |
| 635 | return (1); |
| 636 | } |
| 637 | } |
| 638 | return (0); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | |
| 642 | static int adc_read (unsigned int channel) |
| 643 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 644 | int j = 1000; /* timeout value for wait loop in us */ |
| 645 | int result; |
| 646 | S3C2400_ADC *padc; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 647 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 648 | padc = S3C2400_GetBase_ADC(); |
| 649 | channel &= 0x7; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 650 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 651 | adc_init (); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 652 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 653 | padc->ADCCON &= ~ADC_STDBM; /* select normal mode */ |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 654 | padc->ADCCON &= ~(0x7 << 3); /* clear the channel bits */ |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 655 | padc->ADCCON |= ((channel << 3) | ADC_ENABLE_START); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 656 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 657 | while (j--) { |
| 658 | if ((padc->ADCCON & ADC_ENABLE_START) == 0) |
| 659 | break; |
| 660 | udelay (1); |
| 661 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 662 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 663 | if (j == 0) { |
| 664 | printf("%s: ADC timeout\n", __FUNCTION__); |
| 665 | padc->ADCCON |= ADC_STDBM; /* select standby mode */ |
| 666 | return -1; |
| 667 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 668 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 669 | result = padc->ADCDAT & 0x3FF; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 670 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 671 | padc->ADCCON |= ADC_STDBM; /* select standby mode */ |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 672 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 673 | debug ("%s: channel %d, result[DIGIT]=%d\n", __FUNCTION__, |
| 674 | (padc->ADCCON >> 3) & 0x7, result); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 675 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 676 | /* |
| 677 | * Wait for ADC to be ready for next conversion. This delay value was |
| 678 | * estimated, because the datasheet does not specify a value. |
| 679 | */ |
| 680 | udelay (1000); |
| 681 | |
| 682 | return (result); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | |
| 686 | static void adc_init (void) |
| 687 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 688 | S3C2400_ADC *padc; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 689 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 690 | padc = S3C2400_GetBase_ADC(); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 691 | |
| 692 | padc->ADCCON &= ~(0xff << 6); /* clear prescaler bits */ |
| 693 | padc->ADCCON |= ((65 << 6) | ADC_PRSCEN); /* set prescaler */ |
| 694 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 695 | /* |
| 696 | * Wait some time to avoid problem with very first call of |
| 697 | * adc_read(). Without this delay, sometimes the first read |
| 698 | * adc value is 0. Perhaps because the adjustment of prescaler |
| 699 | * takes some clock cycles? |
| 700 | */ |
| 701 | udelay (1000); |
| 702 | |
| 703 | return; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | |
| 707 | static void led_set (unsigned int state) |
| 708 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 709 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 710 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 711 | led_init (); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 712 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 713 | switch (state) { |
| 714 | case 0: /* turn LED off */ |
| 715 | gpio->PADAT |= (1 << 12); |
| 716 | break; |
| 717 | case 1: /* turn LED on */ |
| 718 | gpio->PADAT &= ~(1 << 12); |
| 719 | break; |
| 720 | default: |
| 721 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static void led_blink (void) |
| 725 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 726 | led_init (); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 727 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 728 | /* blink LED. This function does not return! */ |
| 729 | while (1) { |
| 730 | led_set (1); |
| 731 | udelay (1000000 / LED_BLINK_FREQ / 2); |
| 732 | led_set (0); |
| 733 | udelay (1000000 / LED_BLINK_FREQ / 2); |
| 734 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | |
| 738 | static void led_init (void) |
| 739 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 740 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 741 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 742 | /* configure GPA12 as output and set to High -> LED off */ |
| 743 | gpio->PACON &= ~(1 << 12); |
| 744 | gpio->PADAT |= (1 << 12); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | |
| 748 | static void sdelay (unsigned long seconds) |
| 749 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 750 | unsigned long i; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 751 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 752 | for (i = 0; i < seconds; i++) { |
| 753 | udelay (1000000); |
| 754 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | |
| 758 | static int global_vars_write_to_eeprom (void) |
| 759 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 760 | if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_STATUS, 1, |
| 761 | (unsigned char*) &status, 1)) { |
| 762 | return (1); |
| 763 | } |
| 764 | if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_PASS_CYCLES, 1, |
| 765 | (unsigned char*) &pass_cycles, 2)) { |
| 766 | return (1); |
| 767 | } |
| 768 | if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_CYCLE, |
| 769 | 1, (unsigned char*) &first_error_cycle, 2)) { |
| 770 | return (1); |
| 771 | } |
| 772 | if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_NUM, |
| 773 | 1, (unsigned char*) &first_error_num, 1)) { |
| 774 | return (1); |
| 775 | } |
| 776 | if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_FIRST_ERROR_NAME, |
| 777 | 1, first_error_name, |
| 778 | sizeof(first_error_name))) { |
| 779 | return (1); |
| 780 | } |
| 781 | return (0); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static void global_vars_init (void) |
| 785 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 786 | status = 1; /* error */ |
| 787 | pass_cycles = 0; |
| 788 | first_error_cycle = 0; |
| 789 | first_error_num = 0; |
| 790 | first_error_name[0] = '\0'; |
| 791 | act_cycle = 0; |
| 792 | max_cycles = 0; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | |
| 796 | static void test_function_table_init (void) |
| 797 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 798 | int i; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 799 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 800 | for (i = 0; i < BIF_MAX; i++) |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 801 | test_function[i].pf = dummy; |
| 802 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 803 | /* |
| 804 | * the length of "name" must not exceed 16, including the '\0' |
| 805 | * termination. See also the EEPROM address map. |
| 806 | */ |
| 807 | test_function[0].pf = test_dip; |
| 808 | test_function[0].name = "dip"; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 809 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 810 | test_function[1].pf = test_vcc5v; |
| 811 | test_function[1].name = "vcc5v"; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 812 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 813 | test_function[2].pf = test_rotary_switch; |
| 814 | test_function[2].name = "rotary_switch"; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 815 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 816 | test_function[3].pf = test_sram; |
| 817 | test_function[3].name = "sram"; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 818 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 819 | test_function[4].pf = test_eeprom; |
| 820 | test_function[4].name = "eeprom"; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 821 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 822 | test_function[5].pf = test_contact_temp; |
| 823 | test_function[5].name = "contact_temp"; |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | |
| 827 | static int read_max_cycles (void) |
| 828 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 829 | if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, EE_ADDR_MAX_CYCLES, 1, |
| 830 | (unsigned char *) &max_cycles, 2) != 0) { |
| 831 | return (1); |
| 832 | } |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 833 | |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 834 | return (0); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | static int dummy(void) |
| 838 | { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 839 | return (0); |
wdenk | 4f7cb08 | 2003-09-11 23:06:34 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | #endif /* CFG_CMD_BSP */ |