cmd_trab.c 19 KB

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