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