ppc4xx: Add support for AMCC 405EP Taihu board
[platform/kernel/u-boot.git] / board / amcc / taihu / taihu.c
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
33 extern int lcd_init(void);
34
35 /*
36  * board_early_init_f
37  */
38 int board_early_init_f(void)
39 {
40         lcd_init();
41
42         mtdcr(uicsr, 0xFFFFFFFF);       /* clear all ints */
43         mtdcr(uicer, 0x00000000);       /* disable all ints */
44         mtdcr(uiccr, 0x00000000);
45         mtdcr(uicpr, 0xFFFF7F00);       /* set int polarities */
46         mtdcr(uictr, 0x00000000);       /* set int trigger levels */
47         mtdcr(uicsr, 0xFFFFFFFF);       /* clear all ints */
48         mtdcr(uicvcr, 0x00000001);      /* set vect base=0,INT0 highest priority */
49
50         mtebc(pb3ap, CFG_EBC_PB3AP);    /* memory bank 3 (CPLD_LCM) initialization */
51         mtebc(pb3cr, CFG_EBC_PB3CR);
52
53         return 0;
54 }
55
56 /*
57  * Check Board Identity:
58  */
59 int checkboard(void)
60 {
61         char *s = getenv("serial#");
62
63         puts("Board: Taihu - AMCC PPC405EP Evaluation Board");
64
65         if (s != NULL) {
66                 puts(", serial# ");
67                 puts(s);
68         }
69         putc('\n');
70
71         return 0;
72 }
73
74 /*************************************************************************
75  *  long int initdram
76  *
77  ************************************************************************/
78 long int initdram(int board)
79 {
80         return CFG_SDRAM_SIZE_PER_BANK * CFG_SDRAM_BANKS; /* 128Mbytes */
81 }
82
83 static int do_sw_stat(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
84 {
85         char stat;
86         int i;
87
88         stat = in_8((u8 *) CPLD_REG0_ADDR);
89         printf("SW2 status: ");
90         for (i=0; i<4; i++) /* 4-position */
91                 printf("%d:%s ", i, stat & (0x08 >> i)?"on":"off");
92         printf("\n");
93         return 0;
94 }
95
96 U_BOOT_CMD (
97         sw2_stat, 1, 1, do_sw_stat,
98         "sw2_stat - show status of switch 2\n",
99         NULL
100         );
101
102 static int do_led_ctl(cmd_tbl_t* cmd_tp, int flags, int argc, char *argv[])
103 {
104         int led_no;
105
106         if (argc != 3) {
107                 printf("%s", cmd_tp->usage);
108                 return -1;
109         }
110
111         led_no = simple_strtoul(argv[1], NULL, 16);
112         if (led_no != 1 && led_no != 2) {
113                 printf("%s", cmd_tp->usage);
114                 return -1;
115         }
116
117         if (strcmp(argv[2],"off") == 0x0) {
118                 if (led_no == 1)
119                         gpio_write_bit(30, 1);
120                 else
121                         gpio_write_bit(31, 1);
122         } else if (strcmp(argv[2],"on") == 0x0) {
123                 if (led_no == 1)
124                         gpio_write_bit(30, 0);
125                 else
126                         gpio_write_bit(31, 0);
127         } else {
128                 printf("%s", cmd_tp->usage);
129                 return -1;
130         }
131
132         return 0;
133 }
134
135 U_BOOT_CMD (
136         led_ctl, 3, 1, do_led_ctl,
137         "led_ctl        - make led 1 or 2  on or off\n",
138         "<led_no> <on/off>      -  make led <led_no> on/off,\n"
139         "\tled_no is 1 or 2\t"
140         );
141
142 #define SPI_CS_GPIO0    0
143 #define SPI_SCLK_GPIO14 14
144 #define SPI_DIN_GPIO15  15
145 #define SPI_DOUT_GPIO16 16
146
147 void spi_scl(int bit)
148 {
149         gpio_write_bit(SPI_SCLK_GPIO14, bit);
150 }
151
152 void spi_sda(int bit)
153 {
154         gpio_write_bit(SPI_DOUT_GPIO16, bit);
155 }
156
157 unsigned char spi_read(void)
158 {
159         return (unsigned char)gpio_read_out_bit(SPI_DIN_GPIO15);
160 }
161
162 void taihu_spi_chipsel(int cs)
163 {
164         gpio_write_bit(SPI_CS_GPIO0, cs);
165 }
166
167 spi_chipsel_type spi_chipsel[]= {
168         taihu_spi_chipsel
169 };
170
171 int spi_chipsel_cnt = sizeof(spi_chipsel) / sizeof(spi_chipsel[0]);
172
173 #ifdef CONFIG_PCI
174 static unsigned char int_lines[32] = {
175         29, 30, 27, 28, 29, 30, 25, 27,
176         29, 30, 27, 28, 29, 30, 27, 28,
177         29, 30, 27, 28, 29, 30, 27, 28,
178         29, 30, 27, 28, 29, 30, 27, 28};
179
180 static void taihu_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
181 {
182         unsigned char int_line = int_lines[PCI_DEV(dev) & 31];
183
184         pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
185 }
186
187 int pci_pre_init(struct pci_controller *hose)
188 {
189         hose->fixup_irq = taihu_pci_fixup_irq;
190         return 1;
191 }
192 #endif /* CONFIG_PCI */
193
194 #ifdef CFG_DRAM_TEST
195 int testdram(void)
196 {
197         unsigned long *mem = (unsigned long *)0;
198         const unsigned long kend = (1024 / sizeof(unsigned long));
199         unsigned long k, n;
200         unsigned long msr;
201         unsigned long total_kbytes = CFG_SDRAM_SIZE_PER_BANK * CFG_SDRAM_BANKS / 1024;
202
203         msr = mfmsr();
204         mtmsr(msr & ~(MSR_EE));
205
206         for (k = 0; k < total_kbytes ;
207              ++k, mem += (1024 / sizeof(unsigned long))) {
208                 if ((k & 1023) == 0)
209                         printf("%3d MB\r", k / 1024);
210
211                 memset(mem, 0xaaaaaaaa, 1024);
212                 for (n = 0; n < kend; ++n) {
213                         if (mem[n] != 0xaaaaaaaa) {
214                                 printf("SDRAM test fails at: %08x\n",
215                                        (uint) & mem[n]);
216                                 return 1;
217                         }
218                 }
219
220                 memset(mem, 0x55555555, 1024);
221                 for (n = 0; n < kend; ++n) {
222                         if (mem[n] != 0x55555555) {
223                                 printf("SDRAM test fails at: %08x\n",
224                                        (uint) & mem[n]);
225                                 return 1;
226                         }
227                 }
228         }
229         printf("SDRAM test passes\n");
230         mtmsr(msr);
231
232         return 0;
233 }
234 #endif /* CFG_DRAM_TEST */