cmd_trab.c 23 KB

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