taihu.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 <netdev.h>
  32. #include <asm/gpio.h>
  33. extern int lcd_init(void);
  34. /*
  35. * board_early_init_f
  36. */
  37. int board_early_init_f(void)
  38. {
  39. lcd_init();
  40. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  41. mtdcr(uicer, 0x00000000); /* disable all ints */
  42. mtdcr(uiccr, 0x00000000);
  43. mtdcr(uicpr, 0xFFFF7F00); /* set int polarities */
  44. mtdcr(uictr, 0x00000000); /* set int trigger levels */
  45. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  46. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
  47. mtebc(pb3ap, CFG_EBC_PB3AP); /* memory bank 3 (CPLD_LCM) initialization */
  48. mtebc(pb3cr, CFG_EBC_PB3CR);
  49. /*
  50. * Configure CPC0_PCI to enable PerWE as output
  51. * and enable the internal PCI arbiter
  52. */
  53. mtdcr(cpc0_pci, CPC0_PCI_SPE | CPC0_PCI_HOST_CFG_EN | CPC0_PCI_ARBIT_EN);
  54. return 0;
  55. }
  56. /*
  57. * Check Board Identity:
  58. */
  59. int checkboard(void)
  60. {
  61. char *s = getenv("serial#");
  62. puts("Board: Taihu - AMCC PPC405EP Evaluation Board");
  63. if (s != NULL) {
  64. puts(", serial# ");
  65. puts(s);
  66. }
  67. putc('\n');
  68. return 0;
  69. }
  70. /*************************************************************************
  71. * phys_size_t initdram
  72. *
  73. ************************************************************************/
  74. phys_size_t initdram(int board)
  75. {
  76. return CFG_SDRAM_SIZE_PER_BANK * CFG_SDRAM_BANKS; /* 128Mbytes */
  77. }
  78. static int do_sw_stat(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
  79. {
  80. char stat;
  81. int i;
  82. stat = in_8((u8 *) CPLD_REG0_ADDR);
  83. printf("SW2 status: ");
  84. for (i=0; i<4; i++) /* 4-position */
  85. printf("%d:%s ", i, stat & (0x08 >> i)?"on":"off");
  86. printf("\n");
  87. return 0;
  88. }
  89. U_BOOT_CMD (
  90. sw2_stat, 1, 1, do_sw_stat,
  91. "sw2_stat - show status of switch 2\n",
  92. NULL
  93. );
  94. static int do_led_ctl(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
  95. {
  96. int led_no;
  97. if (argc != 3) {
  98. printf("%s", cmd_tp->usage);
  99. return -1;
  100. }
  101. led_no = simple_strtoul(argv[1], NULL, 16);
  102. if (led_no != 1 && led_no != 2) {
  103. printf("%s", cmd_tp->usage);
  104. return -1;
  105. }
  106. if (strcmp(argv[2],"off") == 0x0) {
  107. if (led_no == 1)
  108. gpio_write_bit(30, 1);
  109. else
  110. gpio_write_bit(31, 1);
  111. } else if (strcmp(argv[2],"on") == 0x0) {
  112. if (led_no == 1)
  113. gpio_write_bit(30, 0);
  114. else
  115. gpio_write_bit(31, 0);
  116. } else {
  117. printf("%s", cmd_tp->usage);
  118. return -1;
  119. }
  120. return 0;
  121. }
  122. U_BOOT_CMD (
  123. led_ctl, 3, 1, do_led_ctl,
  124. "led_ctl - make led 1 or 2 on or off\n",
  125. "<led_no> <on/off> - make led <led_no> on/off,\n"
  126. "\tled_no is 1 or 2\t"
  127. );
  128. #define SPI_CS_GPIO0 0
  129. #define SPI_SCLK_GPIO14 14
  130. #define SPI_DIN_GPIO15 15
  131. #define SPI_DOUT_GPIO16 16
  132. void spi_scl(int bit)
  133. {
  134. gpio_write_bit(SPI_SCLK_GPIO14, bit);
  135. }
  136. void spi_sda(int bit)
  137. {
  138. gpio_write_bit(SPI_DOUT_GPIO16, bit);
  139. }
  140. unsigned char spi_read(void)
  141. {
  142. return (unsigned char)gpio_read_in_bit(SPI_DIN_GPIO15);
  143. }
  144. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  145. {
  146. return bus == 0 && cs == 0;
  147. }
  148. void spi_cs_activate(struct spi_slave *slave)
  149. {
  150. gpio_write_bit(SPI_CS_GPIO0, 1);
  151. }
  152. void spi_cs_deactivate(struct spi_slave *slave)
  153. {
  154. gpio_write_bit(SPI_CS_GPIO0, 0);
  155. }
  156. #ifdef CONFIG_PCI
  157. static unsigned char int_lines[32] = {
  158. 29, 30, 27, 28, 29, 30, 25, 27,
  159. 29, 30, 27, 28, 29, 30, 27, 28,
  160. 29, 30, 27, 28, 29, 30, 27, 28,
  161. 29, 30, 27, 28, 29, 30, 27, 28};
  162. static void taihu_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  163. {
  164. unsigned char int_line = int_lines[PCI_DEV(dev) & 31];
  165. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
  166. }
  167. int pci_pre_init(struct pci_controller *hose)
  168. {
  169. hose->fixup_irq = taihu_pci_fixup_irq;
  170. return 1;
  171. }
  172. #endif /* CONFIG_PCI */
  173. int board_eth_init(bd_t *bis)
  174. {
  175. return pci_eth_init(bis);
  176. }