taihu.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. /*
  49. * Configure CPC0_PCI to enable PerWE as output
  50. * and enable the internal PCI arbiter
  51. */
  52. mtdcr(cpc0_pci, CPC0_PCI_SPE | CPC0_PCI_HOST_CFG_EN | CPC0_PCI_ARBIT_EN);
  53. return 0;
  54. }
  55. /*
  56. * Check Board Identity:
  57. */
  58. int checkboard(void)
  59. {
  60. char *s = getenv("serial#");
  61. puts("Board: Taihu - AMCC PPC405EP Evaluation Board");
  62. if (s != NULL) {
  63. puts(", serial# ");
  64. puts(s);
  65. }
  66. putc('\n');
  67. return 0;
  68. }
  69. /*************************************************************************
  70. * long int initdram
  71. *
  72. ************************************************************************/
  73. long int initdram(int board)
  74. {
  75. return CFG_SDRAM_SIZE_PER_BANK * CFG_SDRAM_BANKS; /* 128Mbytes */
  76. }
  77. static int do_sw_stat(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
  78. {
  79. char stat;
  80. int i;
  81. stat = in_8((u8 *) CPLD_REG0_ADDR);
  82. printf("SW2 status: ");
  83. for (i=0; i<4; i++) /* 4-position */
  84. printf("%d:%s ", i, stat & (0x08 >> i)?"on":"off");
  85. printf("\n");
  86. return 0;
  87. }
  88. U_BOOT_CMD (
  89. sw2_stat, 1, 1, do_sw_stat,
  90. "sw2_stat - show status of switch 2\n",
  91. NULL
  92. );
  93. static int do_led_ctl(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
  94. {
  95. int led_no;
  96. if (argc != 3) {
  97. printf("%s", cmd_tp->usage);
  98. return -1;
  99. }
  100. led_no = simple_strtoul(argv[1], NULL, 16);
  101. if (led_no != 1 && led_no != 2) {
  102. printf("%s", cmd_tp->usage);
  103. return -1;
  104. }
  105. if (strcmp(argv[2],"off") == 0x0) {
  106. if (led_no == 1)
  107. gpio_write_bit(30, 1);
  108. else
  109. gpio_write_bit(31, 1);
  110. } else if (strcmp(argv[2],"on") == 0x0) {
  111. if (led_no == 1)
  112. gpio_write_bit(30, 0);
  113. else
  114. gpio_write_bit(31, 0);
  115. } else {
  116. printf("%s", cmd_tp->usage);
  117. return -1;
  118. }
  119. return 0;
  120. }
  121. U_BOOT_CMD (
  122. led_ctl, 3, 1, do_led_ctl,
  123. "led_ctl - make led 1 or 2 on or off\n",
  124. "<led_no> <on/off> - make led <led_no> on/off,\n"
  125. "\tled_no is 1 or 2\t"
  126. );
  127. #define SPI_CS_GPIO0 0
  128. #define SPI_SCLK_GPIO14 14
  129. #define SPI_DIN_GPIO15 15
  130. #define SPI_DOUT_GPIO16 16
  131. void spi_scl(int bit)
  132. {
  133. gpio_write_bit(SPI_SCLK_GPIO14, bit);
  134. }
  135. void spi_sda(int bit)
  136. {
  137. gpio_write_bit(SPI_DOUT_GPIO16, bit);
  138. }
  139. unsigned char spi_read(void)
  140. {
  141. return (unsigned char)gpio_read_in_bit(SPI_DIN_GPIO15);
  142. }
  143. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  144. {
  145. return bus == 0 && cs == 0;
  146. }
  147. void spi_cs_activate(struct spi_slave *slave)
  148. {
  149. gpio_write_bit(SPI_CS_GPIO0, 1);
  150. }
  151. void spi_cs_deactivate(struct spi_slave *slave)
  152. {
  153. gpio_write_bit(SPI_CS_GPIO0, 0);
  154. }
  155. #ifdef CONFIG_PCI
  156. static unsigned char int_lines[32] = {
  157. 29, 30, 27, 28, 29, 30, 25, 27,
  158. 29, 30, 27, 28, 29, 30, 27, 28,
  159. 29, 30, 27, 28, 29, 30, 27, 28,
  160. 29, 30, 27, 28, 29, 30, 27, 28};
  161. static void taihu_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  162. {
  163. unsigned char int_line = int_lines[PCI_DEV(dev) & 31];
  164. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
  165. }
  166. int pci_pre_init(struct pci_controller *hose)
  167. {
  168. hose->fixup_irq = taihu_pci_fixup_irq;
  169. return 1;
  170. }
  171. #endif /* CONFIG_PCI */
  172. #ifdef CFG_DRAM_TEST
  173. int testdram(void)
  174. {
  175. unsigned long *mem = (unsigned long *)0;
  176. const unsigned long kend = (1024 / sizeof(unsigned long));
  177. unsigned long k, n;
  178. unsigned long msr;
  179. unsigned long total_kbytes = CFG_SDRAM_SIZE_PER_BANK * CFG_SDRAM_BANKS / 1024;
  180. msr = mfmsr();
  181. mtmsr(msr & ~(MSR_EE));
  182. for (k = 0; k < total_kbytes ;
  183. ++k, mem += (1024 / sizeof(unsigned long))) {
  184. if ((k & 1023) == 0)
  185. printf("%3d MB\r", k / 1024);
  186. memset(mem, 0xaaaaaaaa, 1024);
  187. for (n = 0; n < kend; ++n) {
  188. if (mem[n] != 0xaaaaaaaa) {
  189. printf("SDRAM test fails at: %08x\n",
  190. (uint) & mem[n]);
  191. return 1;
  192. }
  193. }
  194. memset(mem, 0x55555555, 1024);
  195. for (n = 0; n < kend; ++n) {
  196. if (mem[n] != 0x55555555) {
  197. printf("SDRAM test fails at: %08x\n",
  198. (uint) & mem[n]);
  199. return 1;
  200. }
  201. }
  202. }
  203. printf("SDRAM test passes\n");
  204. mtmsr(msr);
  205. return 0;
  206. }
  207. #endif /* CFG_DRAM_TEST */