selfcheck.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17. * MA 02111-1307 USA
  18. */
  19. #include <common.h>
  20. #include <asm/io.h>
  21. #include <asm/processor.h>
  22. #include <asm/pci.h>
  23. #if defined(CONFIG_CPU_32BIT)
  24. #define NOCACHE_OFFSET 0x00000000
  25. #else
  26. #define NOCACHE_OFFSET 0xa0000000
  27. #endif
  28. #define PLD_LEDCR (0x04000008 + NOCACHE_OFFSET)
  29. #define PLD_SWSR (0x0400000a + NOCACHE_OFFSET)
  30. #define PLD_VERSR (0x0400000c + NOCACHE_OFFSET)
  31. #define SM107_DEVICEID (0x13e00060 + NOCACHE_OFFSET)
  32. static void wait_ms(unsigned long time)
  33. {
  34. while (time--)
  35. udelay(1000);
  36. }
  37. static void test_pld(void)
  38. {
  39. printf("PLD version = %04x\n", readb(PLD_VERSR));
  40. }
  41. static void test_sm107(void)
  42. {
  43. printf("SM107 device ID = %04x\n", readl(SM107_DEVICEID));
  44. }
  45. static void test_led(void)
  46. {
  47. printf("turn on LEDs 3, 5, 7, 9\n");
  48. writeb(0x55, PLD_LEDCR);
  49. wait_ms(2000);
  50. printf("turn on LEDs 4, 6, 8, 10\n");
  51. writeb(0xaa, PLD_LEDCR);
  52. wait_ms(2000);
  53. writeb(0x00, PLD_LEDCR);
  54. }
  55. static void test_dipsw(void)
  56. {
  57. printf("Please DIPSW set = B'0101\n");
  58. while (readb(PLD_SWSR) != 0x05) {
  59. if (ctrlc())
  60. return;
  61. }
  62. printf("Please DIPSW set = B'1010\n");
  63. while (readb(PLD_SWSR) != 0x0A) {
  64. if (ctrlc())
  65. return;
  66. }
  67. printf("DIPSW OK\n");
  68. }
  69. static void test_net(void)
  70. {
  71. unsigned long data;
  72. writel(0x80000000, 0xfe0401c0);
  73. data = readl(0xfe040220);
  74. if (data == 0x816910ec)
  75. printf("Ethernet OK\n");
  76. else
  77. printf("Ethernet NG, data = %08x\n", (unsigned int)data);
  78. }
  79. static void test_sata(void)
  80. {
  81. unsigned long data;
  82. writel(0x80000800, 0xfe0401c0);
  83. data = readl(0xfe040220);
  84. if (data == 0x35121095)
  85. printf("SATA OK\n");
  86. else
  87. printf("SATA NG, data = %08x\n", (unsigned int)data);
  88. }
  89. static void test_pci(void)
  90. {
  91. writel(0x80001800, 0xfe0401c0);
  92. printf("PCI CN1 ID = %08x\n", readl(0xfe040220));
  93. writel(0x80001000, 0xfe0401c0);
  94. printf("PCI CN2 ID = %08x\n", readl(0xfe040220));
  95. }
  96. int do_hw_test(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  97. {
  98. char *cmd;
  99. if (argc != 2) {
  100. printf("Usage:\n%s\n", cmdtp->usage);
  101. return 1;
  102. }
  103. cmd = argv[1];
  104. switch (cmd[0]) {
  105. case 'a': /* all */
  106. test_pld();
  107. test_led();
  108. test_dipsw();
  109. test_sm107();
  110. test_net();
  111. test_sata();
  112. test_pci();
  113. break;
  114. case 'p': /* pld or pci */
  115. if (cmd[1] == 'l')
  116. test_pld();
  117. else
  118. test_pci();
  119. break;
  120. case 'l': /* led */
  121. test_led();
  122. break;
  123. case 'd': /* dipsw */
  124. test_dipsw();
  125. break;
  126. case 's': /* sm107 or sata */
  127. if (cmd[1] == 'm')
  128. test_sm107();
  129. else
  130. test_sata();
  131. break;
  132. case 'n': /* net */
  133. test_net();
  134. break;
  135. default:
  136. printf("Usage:\n%s\n", cmdtp->usage);
  137. return 1;
  138. }
  139. return 0;
  140. }
  141. U_BOOT_CMD(
  142. hwtest, 2, 1, do_hw_test,
  143. "hwtest - hardware test for R0P7785LC0011RL board\n",
  144. "\n"
  145. "hwtest all - test all hardware\n"
  146. "hwtest pld - output PLD version\n"
  147. "hwtest led - turn on LEDs\n"
  148. "hwtest dipsw - test DIP switch\n"
  149. "hwtest sm107 - output SM107 version\n"
  150. "hwtest net - check RTL8110 ID\n"
  151. "hwtest sata - check SiI3512 ID\n"
  152. "hwtest pci - output PCI slot device ID\n"
  153. );