Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / u-boot / 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  * SPDX-License-Identifier:     GPL-2.0+
9  */
10 #include <common.h>
11 #include <command.h>
12 #include <asm/processor.h>
13 #include <asm/io.h>
14 #include <spi.h>
15 #include <netdev.h>
16 #include <asm/ppc4xx-gpio.h>
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
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 */
34
35         mtebc(PB3AP, CONFIG_SYS_EBC_PB3AP);     /* memory bank 3 (CPLD_LCM) initialization */
36         mtebc(PB3CR, CONFIG_SYS_EBC_PB3CR);
37
38         /*
39          * Configure CPC0_PCI to enable PerWE as output
40          * and enable the internal PCI arbiter
41          */
42         mtdcr(CPC0_PCI, CPC0_PCI_SPE | CPC0_PCI_HOST_CFG_EN | CPC0_PCI_ARBIT_EN);
43
44         return 0;
45 }
46
47 /*
48  * Check Board Identity:
49  */
50 int checkboard(void)
51 {
52         char buf[64];
53         int i = getenv_f("serial#", buf, sizeof(buf));
54
55         puts("Board: Taihu - AMCC PPC405EP Evaluation Board");
56
57         if (i > 0) {
58                 puts(", serial# ");
59                 puts(buf);
60         }
61         putc('\n');
62
63         return 0;
64 }
65
66 static int do_sw_stat(cmd_tbl_t* cmd_tp, int flags, int argc, char * const argv[])
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,
81         "show status of switch 2",
82         ""
83 );
84
85 static int do_led_ctl(cmd_tbl_t* cmd_tp, int flags, int argc, char * const argv[])
86 {
87         int led_no;
88
89         if (argc != 3)
90                 return cmd_usage(cmd_tp);
91
92         led_no = simple_strtoul(argv[1], NULL, 16);
93         if (led_no != 1 && led_no != 2)
94                 return cmd_usage(cmd_tp);
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 {
107                 return cmd_usage(cmd_tp);
108         }
109
110         return 0;
111 }
112
113 U_BOOT_CMD (
114         led_ctl, 3, 1, do_led_ctl,
115         "make led 1 or 2  on or off",
116         "<led_no> <on/off>      -  make led <led_no> on/off,\n"
117         "\tled_no is 1 or 2"
118 );
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 {
137         return (unsigned char)gpio_read_in_bit(SPI_DIN_GPIO15);
138 }
139
140 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
141 {
142         return bus == 0 && cs == 0;
143 }
144
145 void spi_cs_activate(struct spi_slave *slave)
146 {
147         gpio_write_bit(SPI_CS_GPIO0, 1);
148 }
149
150 void spi_cs_deactivate(struct spi_slave *slave)
151 {
152         gpio_write_bit(SPI_CS_GPIO0, 0);
153 }
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 */
175
176 int board_eth_init(bd_t *bis)
177 {
178         cpu_eth_init(bis);
179         return pci_eth_init(bis);
180 }