blob: fcb893633a0c804d63c23785ba644390d1c7767b [file] [log] [blame]
John Otken9aa36772007-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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
John Otken9aa36772007-07-26 17:49:11 +02009 */
10#include <common.h>
11#include <command.h>
12#include <asm/processor.h>
13#include <asm/io.h>
14#include <spi.h>
Ben Warren052a5ea2008-08-31 20:37:00 -070015#include <netdev.h>
Stefan Roesede21eab2010-09-16 14:30:37 +020016#include <asm/ppc4xx-gpio.h>
John Otken9aa36772007-07-26 17:49:11 +020017
18extern int lcd_init(void);
19
20/*
21 * board_early_init_f
22 */
23int board_early_init_f(void)
24{
25 lcd_init();
26
Stefan Roese707fd362009-09-24 09:55:50 +020027 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 Otken9aa36772007-07-26 17:49:11 +020034
Stefan Roese918010a2009-09-09 16:25:29 +020035 mtebc(PB3AP, CONFIG_SYS_EBC_PB3AP); /* memory bank 3 (CPLD_LCM) initialization */
36 mtebc(PB3CR, CONFIG_SYS_EBC_PB3CR);
John Otken9aa36772007-07-26 17:49:11 +020037
Stefan Roesea5d182e2007-08-14 14:44:41 +020038 /*
39 * Configure CPC0_PCI to enable PerWE as output
40 * and enable the internal PCI arbiter
41 */
Stefan Roese918010a2009-09-09 16:25:29 +020042 mtdcr(CPC0_PCI, CPC0_PCI_SPE | CPC0_PCI_HOST_CFG_EN | CPC0_PCI_ARBIT_EN);
Stefan Roesea5d182e2007-08-14 14:44:41 +020043
John Otken9aa36772007-07-26 17:49:11 +020044 return 0;
45}
46
47/*
48 * Check Board Identity:
49 */
50int checkboard(void)
51{
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +000052 char buf[64];
53 int i = getenv_f("serial#", buf, sizeof(buf));
John Otken9aa36772007-07-26 17:49:11 +020054
55 puts("Board: Taihu - AMCC PPC405EP Evaluation Board");
56
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +000057 if (i > 0) {
John Otken9aa36772007-07-26 17:49:11 +020058 puts(", serial# ");
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +000059 puts(buf);
John Otken9aa36772007-07-26 17:49:11 +020060 }
61 putc('\n');
62
63 return 0;
64}
65
Wolfgang Denk6262d0212010-06-28 22:00:46 +020066static int do_sw_stat(cmd_tbl_t* cmd_tp, int flags, int argc, char * const argv[])
John Otken9aa36772007-07-26 17:49:11 +020067{
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
79U_BOOT_CMD (
80 sw2_stat, 1, 1, do_sw_stat,
Peter Tyserdfb72b82009-01-27 18:03:12 -060081 "show status of switch 2",
Wolfgang Denkc54781c2009-05-24 17:06:54 +020082 ""
83);
John Otken9aa36772007-07-26 17:49:11 +020084
Wolfgang Denk6262d0212010-06-28 22:00:46 +020085static int do_led_ctl(cmd_tbl_t* cmd_tp, int flags, int argc, char * const argv[])
John Otken9aa36772007-07-26 17:49:11 +020086{
87 int led_no;
88
Wolfgang Denk3b683112010-07-17 01:06:04 +020089 if (argc != 3)
90 return cmd_usage(cmd_tp);
John Otken9aa36772007-07-26 17:49:11 +020091
92 led_no = simple_strtoul(argv[1], NULL, 16);
Wolfgang Denk3b683112010-07-17 01:06:04 +020093 if (led_no != 1 && led_no != 2)
94 return cmd_usage(cmd_tp);
John Otken9aa36772007-07-26 17:49:11 +020095
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 Denk3b683112010-07-17 01:06:04 +0200107 return cmd_usage(cmd_tp);
John Otken9aa36772007-07-26 17:49:11 +0200108 }
109
110 return 0;
111}
112
113U_BOOT_CMD (
114 led_ctl, 3, 1, do_led_ctl,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600115 "make led 1 or 2 on or off",
John Otken9aa36772007-07-26 17:49:11 +0200116 "<led_no> <on/off> - make led <led_no> on/off,\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200117 "\tled_no is 1 or 2"
118);
John Otken9aa36772007-07-26 17:49:11 +0200119
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
125void spi_scl(int bit)
126{
127 gpio_write_bit(SPI_SCLK_GPIO14, bit);
128}
129
130void spi_sda(int bit)
131{
132 gpio_write_bit(SPI_DOUT_GPIO16, bit);
133}
134
135unsigned char spi_read(void)
136{
Markus Brunnerc459e392008-03-05 21:38:12 +0100137 return (unsigned char)gpio_read_in_bit(SPI_DIN_GPIO15);
John Otken9aa36772007-07-26 17:49:11 +0200138}
139
Haavard Skinnemoend74084a2008-05-16 11:10:31 +0200140int spi_cs_is_valid(unsigned int bus, unsigned int cs)
John Otken9aa36772007-07-26 17:49:11 +0200141{
Haavard Skinnemoend74084a2008-05-16 11:10:31 +0200142 return bus == 0 && cs == 0;
John Otken9aa36772007-07-26 17:49:11 +0200143}
144
Haavard Skinnemoend74084a2008-05-16 11:10:31 +0200145void spi_cs_activate(struct spi_slave *slave)
146{
147 gpio_write_bit(SPI_CS_GPIO0, 1);
148}
John Otken9aa36772007-07-26 17:49:11 +0200149
Haavard Skinnemoend74084a2008-05-16 11:10:31 +0200150void spi_cs_deactivate(struct spi_slave *slave)
151{
152 gpio_write_bit(SPI_CS_GPIO0, 0);
153}
John Otken9aa36772007-07-26 17:49:11 +0200154
155#ifdef CONFIG_PCI
156static 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
162static 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
169int 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 Warren052a5ea2008-08-31 20:37:00 -0700175
176int board_eth_init(bd_t *bis)
177{
Stefan Roeseb33e6d72009-02-11 09:29:33 +0100178 cpu_eth_init(bis);
Ben Warren052a5ea2008-08-31 20:37:00 -0700179 return pci_eth_init(bis);
180}