cmd_trab.c 20 KB

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