blob: 266f2601c5d909a7562268856865fbbce5e9ef18 [file] [log] [blame]
John Otkend4024bb2007-07-26 17:49:11 +02001/*
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 Warren10efa022008-08-31 20:37:00 -070031#include <netdev.h>
John Otkend4024bb2007-07-26 17:49:11 +020032#include <asm/gpio.h>
33
34extern int lcd_init(void);
35
36/*
37 * board_early_init_f
38 */
39int board_early_init_f(void)
40{
41 lcd_init();
42
43 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
44 mtdcr(uicer, 0x00000000); /* disable all ints */
45 mtdcr(uiccr, 0x00000000);
46 mtdcr(uicpr, 0xFFFF7F00); /* set int polarities */
47 mtdcr(uictr, 0x00000000); /* set int trigger levels */
48 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
49 mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
50
51 mtebc(pb3ap, CFG_EBC_PB3AP); /* memory bank 3 (CPLD_LCM) initialization */
52 mtebc(pb3cr, CFG_EBC_PB3CR);
53
Stefan Roese779e9752007-08-14 14:44:41 +020054 /*
55 * Configure CPC0_PCI to enable PerWE as output
56 * and enable the internal PCI arbiter
57 */
58 mtdcr(cpc0_pci, CPC0_PCI_SPE | CPC0_PCI_HOST_CFG_EN | CPC0_PCI_ARBIT_EN);
59
John Otkend4024bb2007-07-26 17:49:11 +020060 return 0;
61}
62
63/*
64 * Check Board Identity:
65 */
66int checkboard(void)
67{
68 char *s = getenv("serial#");
69
70 puts("Board: Taihu - AMCC PPC405EP Evaluation Board");
71
72 if (s != NULL) {
73 puts(", serial# ");
74 puts(s);
75 }
76 putc('\n');
77
78 return 0;
79}
80
81/*************************************************************************
Becky Bruce9973e3c2008-06-09 16:03:40 -050082 * phys_size_t initdram
John Otkend4024bb2007-07-26 17:49:11 +020083 *
84 ************************************************************************/
Becky Bruce9973e3c2008-06-09 16:03:40 -050085phys_size_t initdram(int board)
John Otkend4024bb2007-07-26 17:49:11 +020086{
87 return CFG_SDRAM_SIZE_PER_BANK * CFG_SDRAM_BANKS; /* 128Mbytes */
88}
89
90static int do_sw_stat(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
91{
92 char stat;
93 int i;
94
95 stat = in_8((u8 *) CPLD_REG0_ADDR);
96 printf("SW2 status: ");
97 for (i=0; i<4; i++) /* 4-position */
98 printf("%d:%s ", i, stat & (0x08 >> i)?"on":"off");
99 printf("\n");
100 return 0;
101}
102
103U_BOOT_CMD (
104 sw2_stat, 1, 1, do_sw_stat,
105 "sw2_stat - show status of switch 2\n",
106 NULL
107 );
108
109static int do_led_ctl(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
110{
111 int led_no;
112
113 if (argc != 3) {
114 printf("%s", cmd_tp->usage);
115 return -1;
116 }
117
118 led_no = simple_strtoul(argv[1], NULL, 16);
119 if (led_no != 1 && led_no != 2) {
120 printf("%s", cmd_tp->usage);
121 return -1;
122 }
123
124 if (strcmp(argv[2],"off") == 0x0) {
125 if (led_no == 1)
126 gpio_write_bit(30, 1);
127 else
128 gpio_write_bit(31, 1);
129 } else if (strcmp(argv[2],"on") == 0x0) {
130 if (led_no == 1)
131 gpio_write_bit(30, 0);
132 else
133 gpio_write_bit(31, 0);
134 } else {
135 printf("%s", cmd_tp->usage);
136 return -1;
137 }
138
139 return 0;
140}
141
142U_BOOT_CMD (
143 led_ctl, 3, 1, do_led_ctl,
144 "led_ctl - make led 1 or 2 on or off\n",
145 "<led_no> <on/off> - make led <led_no> on/off,\n"
146 "\tled_no is 1 or 2\t"
147 );
148
149#define SPI_CS_GPIO0 0
150#define SPI_SCLK_GPIO14 14
151#define SPI_DIN_GPIO15 15
152#define SPI_DOUT_GPIO16 16
153
154void spi_scl(int bit)
155{
156 gpio_write_bit(SPI_SCLK_GPIO14, bit);
157}
158
159void spi_sda(int bit)
160{
161 gpio_write_bit(SPI_DOUT_GPIO16, bit);
162}
163
164unsigned char spi_read(void)
165{
Markus Brunner772003e2008-03-05 21:38:12 +0100166 return (unsigned char)gpio_read_in_bit(SPI_DIN_GPIO15);
John Otkend4024bb2007-07-26 17:49:11 +0200167}
168
Haavard Skinnemoend255bb02008-05-16 11:10:31 +0200169int spi_cs_is_valid(unsigned int bus, unsigned int cs)
John Otkend4024bb2007-07-26 17:49:11 +0200170{
Haavard Skinnemoend255bb02008-05-16 11:10:31 +0200171 return bus == 0 && cs == 0;
John Otkend4024bb2007-07-26 17:49:11 +0200172}
173
Haavard Skinnemoend255bb02008-05-16 11:10:31 +0200174void spi_cs_activate(struct spi_slave *slave)
175{
176 gpio_write_bit(SPI_CS_GPIO0, 1);
177}
John Otkend4024bb2007-07-26 17:49:11 +0200178
Haavard Skinnemoend255bb02008-05-16 11:10:31 +0200179void spi_cs_deactivate(struct spi_slave *slave)
180{
181 gpio_write_bit(SPI_CS_GPIO0, 0);
182}
John Otkend4024bb2007-07-26 17:49:11 +0200183
184#ifdef CONFIG_PCI
185static unsigned char int_lines[32] = {
186 29, 30, 27, 28, 29, 30, 25, 27,
187 29, 30, 27, 28, 29, 30, 27, 28,
188 29, 30, 27, 28, 29, 30, 27, 28,
189 29, 30, 27, 28, 29, 30, 27, 28};
190
191static void taihu_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
192{
193 unsigned char int_line = int_lines[PCI_DEV(dev) & 31];
194
195 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
196}
197
198int pci_pre_init(struct pci_controller *hose)
199{
200 hose->fixup_irq = taihu_pci_fixup_irq;
201 return 1;
202}
203#endif /* CONFIG_PCI */
Ben Warren10efa022008-08-31 20:37:00 -0700204
205int board_eth_init(bd_t *bis)
206{
207 return pci_eth_init(bis);
208}