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