taihu.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * (C) Copyright 2000-2005
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2005-2007
  6. * Beijing UD Technology Co., Ltd., taihusupport@amcc.com
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <asm/processor.h>
  29. #include <asm/io.h>
  30. #include <spi.h>
  31. #include <asm/gpio.h>
  32. extern int lcd_init(void);
  33. /*
  34. * board_early_init_f
  35. */
  36. int board_early_init_f(void)
  37. {
  38. lcd_init();
  39. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  40. mtdcr(uicer, 0x00000000); /* disable all ints */
  41. mtdcr(uiccr, 0x00000000);
  42. mtdcr(uicpr, 0xFFFF7F00); /* set int polarities */
  43. mtdcr(uictr, 0x00000000); /* set int trigger levels */
  44. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  45. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
  46. mtebc(pb3ap, CFG_EBC_PB3AP); /* memory bank 3 (CPLD_LCM) initialization */
  47. mtebc(pb3cr, CFG_EBC_PB3CR);
  48. return 0;
  49. }
  50. /*
  51. * Check Board Identity:
  52. */
  53. int checkboard(void)
  54. {
  55. char *s = getenv("serial#");
  56. puts("Board: Taihu - AMCC PPC405EP Evaluation Board");
  57. if (s != NULL) {
  58. puts(", serial# ");
  59. puts(s);
  60. }
  61. putc('\n');
  62. return 0;
  63. }
  64. /*************************************************************************
  65. * long int initdram
  66. *
  67. ************************************************************************/
  68. long int initdram(int board)
  69. {
  70. return CFG_SDRAM_SIZE_PER_BANK * CFG_SDRAM_BANKS; /* 128Mbytes */
  71. }
  72. static int do_sw_stat(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
  73. {
  74. char stat;
  75. int i;
  76. stat = in_8((u8 *) CPLD_REG0_ADDR);
  77. printf("SW2 status: ");
  78. for (i=0; i<4; i++) /* 4-position */
  79. printf("%d:%s ", i, stat & (0x08 >> i)?"on":"off");
  80. printf("\n");
  81. return 0;
  82. }
  83. U_BOOT_CMD (
  84. sw2_stat, 1, 1, do_sw_stat,
  85. "sw2_stat - show status of switch 2\n",
  86. NULL
  87. );
  88. static int do_led_ctl(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
  89. {
  90. int led_no;
  91. if (argc != 3) {
  92. printf("%s", cmd_tp->usage);
  93. return -1;
  94. }
  95. led_no = simple_strtoul(argv[1], NULL, 16);
  96. if (led_no != 1 && led_no != 2) {
  97. printf("%s", cmd_tp->usage);
  98. return -1;
  99. }
  100. if (strcmp(argv[2],"off") == 0x0) {
  101. if (led_no == 1)
  102. gpio_write_bit(30, 1);
  103. else
  104. gpio_write_bit(31, 1);
  105. } else if (strcmp(argv[2],"on") == 0x0) {
  106. if (led_no == 1)
  107. gpio_write_bit(30, 0);
  108. else
  109. gpio_write_bit(31, 0);
  110. } else {
  111. printf("%s", cmd_tp->usage);
  112. return -1;
  113. }
  114. return 0;
  115. }
  116. U_BOOT_CMD (
  117. led_ctl, 3, 1, do_led_ctl,
  118. "led_ctl - make led 1 or 2 on or off\n",
  119. "<led_no> <on/off> - make led <led_no> on/off,\n"
  120. "\tled_no is 1 or 2\t"
  121. );
  122. #define SPI_CS_GPIO0 0
  123. #define SPI_SCLK_GPIO14 14
  124. #define SPI_DIN_GPIO15 15
  125. #define SPI_DOUT_GPIO16 16
  126. void spi_scl(int bit)
  127. {
  128. gpio_write_bit(SPI_SCLK_GPIO14, bit);
  129. }
  130. void spi_sda(int bit)
  131. {
  132. gpio_write_bit(SPI_DOUT_GPIO16, bit);
  133. }
  134. unsigned char spi_read(void)
  135. {
  136. return (unsigned char)gpio_read_out_bit(SPI_DIN_GPIO15);
  137. }
  138. void taihu_spi_chipsel(int cs)
  139. {
  140. gpio_write_bit(SPI_CS_GPIO0, cs);
  141. }
  142. spi_chipsel_type spi_chipsel[]= {
  143. taihu_spi_chipsel
  144. };
  145. int spi_chipsel_cnt = sizeof(spi_chipsel) / sizeof(spi_chipsel[0]);
  146. #ifdef CONFIG_PCI
  147. static unsigned char int_lines[32] = {
  148. 29, 30, 27, 28, 29, 30, 25, 27,
  149. 29, 30, 27, 28, 29, 30, 27, 28,
  150. 29, 30, 27, 28, 29, 30, 27, 28,
  151. 29, 30, 27, 28, 29, 30, 27, 28};
  152. static void taihu_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  153. {
  154. unsigned char int_line = int_lines[PCI_DEV(dev) & 31];
  155. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
  156. }
  157. int pci_pre_init(struct pci_controller *hose)
  158. {
  159. hose->fixup_irq = taihu_pci_fixup_irq;
  160. return 1;
  161. }
  162. #endif /* CONFIG_PCI */
  163. #ifdef CFG_DRAM_TEST
  164. int testdram(void)
  165. {
  166. unsigned long *mem = (unsigned long *)0;
  167. const unsigned long kend = (1024 / sizeof(unsigned long));
  168. unsigned long k, n;
  169. unsigned long msr;
  170. unsigned long total_kbytes = CFG_SDRAM_SIZE_PER_BANK * CFG_SDRAM_BANKS / 1024;
  171. msr = mfmsr();
  172. mtmsr(msr & ~(MSR_EE));
  173. for (k = 0; k < total_kbytes ;
  174. ++k, mem += (1024 / sizeof(unsigned long))) {
  175. if ((k & 1023) == 0)
  176. printf("%3d MB\r", k / 1024);
  177. memset(mem, 0xaaaaaaaa, 1024);
  178. for (n = 0; n < kend; ++n) {
  179. if (mem[n] != 0xaaaaaaaa) {
  180. printf("SDRAM test fails at: %08x\n",
  181. (uint) & mem[n]);
  182. return 1;
  183. }
  184. }
  185. memset(mem, 0x55555555, 1024);
  186. for (n = 0; n < kend; ++n) {
  187. if (mem[n] != 0x55555555) {
  188. printf("SDRAM test fails at: %08x\n",
  189. (uint) & mem[n]);
  190. return 1;
  191. }
  192. }
  193. }
  194. printf("SDRAM test passes\n");
  195. mtmsr(msr);
  196. return 0;
  197. }
  198. #endif /* CFG_DRAM_TEST */