John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 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> |
Ben Warren | 052a5ea | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 31 | #include <netdev.h> |
Stefan Roese | de21eab | 2010-09-16 14:30:37 +0200 | [diff] [blame] | 32 | #include <asm/ppc4xx-gpio.h> |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 33 | |
| 34 | extern int lcd_init(void); |
| 35 | |
| 36 | /* |
| 37 | * board_early_init_f |
| 38 | */ |
| 39 | int board_early_init_f(void) |
| 40 | { |
| 41 | lcd_init(); |
| 42 | |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 43 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 44 | mtdcr(UIC0ER, 0x00000000); /* disable all ints */ |
| 45 | mtdcr(UIC0CR, 0x00000000); |
| 46 | mtdcr(UIC0PR, 0xFFFF7F00); /* set int polarities */ |
| 47 | mtdcr(UIC0TR, 0x00000000); /* set int trigger levels */ |
| 48 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 49 | mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */ |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 50 | |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 51 | mtebc(PB3AP, CONFIG_SYS_EBC_PB3AP); /* memory bank 3 (CPLD_LCM) initialization */ |
| 52 | mtebc(PB3CR, CONFIG_SYS_EBC_PB3CR); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 53 | |
Stefan Roese | a5d182e | 2007-08-14 14:44:41 +0200 | [diff] [blame] | 54 | /* |
| 55 | * Configure CPC0_PCI to enable PerWE as output |
| 56 | * and enable the internal PCI arbiter |
| 57 | */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 58 | mtdcr(CPC0_PCI, CPC0_PCI_SPE | CPC0_PCI_HOST_CFG_EN | CPC0_PCI_ARBIT_EN); |
Stefan Roese | a5d182e | 2007-08-14 14:44:41 +0200 | [diff] [blame] | 59 | |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Check Board Identity: |
| 65 | */ |
| 66 | int checkboard(void) |
| 67 | { |
Wolfgang Denk | 5c1cfee | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 68 | char buf[64]; |
| 69 | int i = getenv_f("serial#", buf, sizeof(buf)); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 70 | |
| 71 | puts("Board: Taihu - AMCC PPC405EP Evaluation Board"); |
| 72 | |
Wolfgang Denk | 5c1cfee | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 73 | if (i > 0) { |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 74 | puts(", serial# "); |
Wolfgang Denk | 5c1cfee | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 75 | puts(buf); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 76 | } |
| 77 | putc('\n'); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 82 | static int do_sw_stat(cmd_tbl_t* cmd_tp, int flags, int argc, char * const argv[]) |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 83 | { |
| 84 | char stat; |
| 85 | int i; |
| 86 | |
| 87 | stat = in_8((u8 *) CPLD_REG0_ADDR); |
| 88 | printf("SW2 status: "); |
| 89 | for (i=0; i<4; i++) /* 4-position */ |
| 90 | printf("%d:%s ", i, stat & (0x08 >> i)?"on":"off"); |
| 91 | printf("\n"); |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | U_BOOT_CMD ( |
| 96 | sw2_stat, 1, 1, do_sw_stat, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 97 | "show status of switch 2", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 98 | "" |
| 99 | ); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 100 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 101 | static int do_led_ctl(cmd_tbl_t* cmd_tp, int flags, int argc, char * const argv[]) |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 102 | { |
| 103 | int led_no; |
| 104 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 105 | if (argc != 3) |
| 106 | return cmd_usage(cmd_tp); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 107 | |
| 108 | led_no = simple_strtoul(argv[1], NULL, 16); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 109 | if (led_no != 1 && led_no != 2) |
| 110 | return cmd_usage(cmd_tp); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 111 | |
| 112 | if (strcmp(argv[2],"off") == 0x0) { |
| 113 | if (led_no == 1) |
| 114 | gpio_write_bit(30, 1); |
| 115 | else |
| 116 | gpio_write_bit(31, 1); |
| 117 | } else if (strcmp(argv[2],"on") == 0x0) { |
| 118 | if (led_no == 1) |
| 119 | gpio_write_bit(30, 0); |
| 120 | else |
| 121 | gpio_write_bit(31, 0); |
| 122 | } else { |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 123 | return cmd_usage(cmd_tp); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | U_BOOT_CMD ( |
| 130 | led_ctl, 3, 1, do_led_ctl, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 131 | "make led 1 or 2 on or off", |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 132 | "<led_no> <on/off> - make led <led_no> on/off,\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 133 | "\tled_no is 1 or 2" |
| 134 | ); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 135 | |
| 136 | #define SPI_CS_GPIO0 0 |
| 137 | #define SPI_SCLK_GPIO14 14 |
| 138 | #define SPI_DIN_GPIO15 15 |
| 139 | #define SPI_DOUT_GPIO16 16 |
| 140 | |
| 141 | void spi_scl(int bit) |
| 142 | { |
| 143 | gpio_write_bit(SPI_SCLK_GPIO14, bit); |
| 144 | } |
| 145 | |
| 146 | void spi_sda(int bit) |
| 147 | { |
| 148 | gpio_write_bit(SPI_DOUT_GPIO16, bit); |
| 149 | } |
| 150 | |
| 151 | unsigned char spi_read(void) |
| 152 | { |
Markus Brunner | c459e39 | 2008-03-05 21:38:12 +0100 | [diff] [blame] | 153 | return (unsigned char)gpio_read_in_bit(SPI_DIN_GPIO15); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Haavard Skinnemoen | d74084a | 2008-05-16 11:10:31 +0200 | [diff] [blame] | 156 | int spi_cs_is_valid(unsigned int bus, unsigned int cs) |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 157 | { |
Haavard Skinnemoen | d74084a | 2008-05-16 11:10:31 +0200 | [diff] [blame] | 158 | return bus == 0 && cs == 0; |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 159 | } |
| 160 | |
Haavard Skinnemoen | d74084a | 2008-05-16 11:10:31 +0200 | [diff] [blame] | 161 | void spi_cs_activate(struct spi_slave *slave) |
| 162 | { |
| 163 | gpio_write_bit(SPI_CS_GPIO0, 1); |
| 164 | } |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 165 | |
Haavard Skinnemoen | d74084a | 2008-05-16 11:10:31 +0200 | [diff] [blame] | 166 | void spi_cs_deactivate(struct spi_slave *slave) |
| 167 | { |
| 168 | gpio_write_bit(SPI_CS_GPIO0, 0); |
| 169 | } |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 170 | |
| 171 | #ifdef CONFIG_PCI |
| 172 | static unsigned char int_lines[32] = { |
| 173 | 29, 30, 27, 28, 29, 30, 25, 27, |
| 174 | 29, 30, 27, 28, 29, 30, 27, 28, |
| 175 | 29, 30, 27, 28, 29, 30, 27, 28, |
| 176 | 29, 30, 27, 28, 29, 30, 27, 28}; |
| 177 | |
| 178 | static void taihu_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev) |
| 179 | { |
| 180 | unsigned char int_line = int_lines[PCI_DEV(dev) & 31]; |
| 181 | |
| 182 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line); |
| 183 | } |
| 184 | |
| 185 | int pci_pre_init(struct pci_controller *hose) |
| 186 | { |
| 187 | hose->fixup_irq = taihu_pci_fixup_irq; |
| 188 | return 1; |
| 189 | } |
| 190 | #endif /* CONFIG_PCI */ |
Ben Warren | 052a5ea | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 191 | |
| 192 | int board_eth_init(bd_t *bis) |
| 193 | { |
Stefan Roese | b33e6d7 | 2009-02-11 09:29:33 +0100 | [diff] [blame] | 194 | cpu_eth_init(bis); |
Ben Warren | 052a5ea | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 195 | return pci_eth_init(bis); |
| 196 | } |