cmd_trab.c 20 KB

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