post.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * BF537-STAMP POST code
  3. *
  4. * Enter bugs at http://blackfin.uclinux.org/
  5. *
  6. * Copyright (c) 2005-2009 Analog Devices Inc.
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #include <common.h>
  11. #include <config.h>
  12. #include <command.h>
  13. #include <asm/blackfin.h>
  14. #include <asm/gpio.h>
  15. /* Using sw10-PF5 as the hotkey */
  16. int post_hotkeys_pressed(void)
  17. {
  18. int delay = 3;
  19. int i;
  20. unsigned short value;
  21. gpio_request(GPIO_PF5, "post");
  22. gpio_direction_input(GPIO_PF5);
  23. printf("########Press SW10 to enter Memory POST########: %2d ", delay);
  24. while (delay--) {
  25. for (i = 0; i < 100; i++) {
  26. value = gpio_get_value(GPIO_PF5);
  27. if (value != 0) {
  28. break;
  29. }
  30. udelay(10000);
  31. }
  32. printf("\b\b\b%2d ", delay);
  33. }
  34. printf("\b\b\b 0");
  35. printf("\n");
  36. if (value == 0)
  37. return 0;
  38. else {
  39. printf("Hotkey has been pressed, Enter POST . . . . . .\n");
  40. return 1;
  41. }
  42. gpio_free(GPIO_PF5);
  43. }
  44. int uart_post_test(int flags)
  45. {
  46. return 0;
  47. }
  48. #define BLOCK_SIZE 0x10000
  49. #define VERIFY_ADDR 0x2000000
  50. extern int erase_block_flash(int);
  51. extern int write_data(long lStart, long lCount, uchar * pnData);
  52. int flash_post_test(int flags)
  53. {
  54. unsigned short *pbuf, *temp;
  55. int offset, n, i;
  56. int value = 0;
  57. int result = 0;
  58. printf("\n");
  59. pbuf = (unsigned short *)VERIFY_ADDR;
  60. temp = pbuf;
  61. for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
  62. offset = (n - 7) * BLOCK_SIZE;
  63. printf("--------Erase block:%2d..", n);
  64. erase_block_flash(n);
  65. printf("OK\r");
  66. printf("--------Program block:%2d...", n);
  67. write_data(CONFIG_SYS_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
  68. printf("OK\r");
  69. printf("--------Verify block:%2d...", n);
  70. for (i = 0; i < BLOCK_SIZE; i += 2) {
  71. if (*(unsigned short *)(CONFIG_SYS_FLASH_BASE + offset + i) !=
  72. *temp++) {
  73. value = 1;
  74. result = 1;
  75. }
  76. }
  77. if (value)
  78. printf("failed\n");
  79. else
  80. printf("OK %3d%%\r",
  81. (int)(
  82. (n + 1 -
  83. FLASH_START_POST_BLOCK) *
  84. 100 / (FLASH_END_POST_BLOCK -
  85. FLASH_START_POST_BLOCK)));
  86. temp = pbuf;
  87. value = 0;
  88. }
  89. printf("\n");
  90. if (result)
  91. return -1;
  92. else
  93. return 0;
  94. }
  95. /****************************************************
  96. * LED1 ---- PF6 LED2 ---- PF7 *
  97. * LED3 ---- PF8 LED4 ---- PF9 *
  98. * LED5 ---- PF10 LED6 ---- PF11 *
  99. ****************************************************/
  100. int led_post_test(int flags)
  101. {
  102. unsigned int leds[] = {
  103. GPIO_PF6, GPIO_PF7, GPIO_PF8,
  104. GPIO_PF9, GPIO_PF10, GPIO_PF11,
  105. };
  106. int i;
  107. for (i = 0; i < ARRAY_SIZE(leds); ++i) {
  108. gpio_request(leds[i], "post");
  109. gpio_direction_output(leds[i], 0);
  110. printf("LED%i on", i + 1);
  111. gpio_set_value(leds[i], 1);
  112. udelay(1000000);
  113. printf("\b\b\b\b\b\b\b");
  114. gpio_free(leds[i]);
  115. }
  116. return 0;
  117. }
  118. /************************************************
  119. * SW10 ---- PF5 SW11 ---- PF4 *
  120. * SW12 ---- PF3 SW13 ---- PF2 *
  121. ************************************************/
  122. int button_post_test(int flags)
  123. {
  124. unsigned int buttons[] = {
  125. GPIO_PF2, GPIO_PF3, GPIO_PF4, GPIO_PF5,
  126. };
  127. unsigned int sws[] = { 13, 12, 11, 10, };
  128. int i, delay = 5;
  129. unsigned short value = 0;
  130. int result = 0;
  131. for (i = 0; i < ARRAY_SIZE(buttons); ++i) {
  132. gpio_request(buttons[i], "post");
  133. gpio_direction_input(buttons[i]);
  134. delay = 5;
  135. printf("\n--------Press SW%i: %2d ", sws[i], delay);
  136. while (delay--) {
  137. for (i = 0; i < 100; i++) {
  138. value = gpio_get_value(buttons[i]);
  139. if (value != 0)
  140. break;
  141. udelay(10000);
  142. }
  143. printf("\b\b\b%2d ", delay);
  144. }
  145. if (value != 0)
  146. puts("\b\bOK");
  147. else {
  148. result = -1;
  149. puts("\b\bfailed");
  150. }
  151. gpio_free(buttons[i]);
  152. }
  153. puts("\n");
  154. return result;
  155. }