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