mvblue.c 5.64 KB
Newer Older
wdenk's avatar
wdenk committed
1 2 3 4 5 6 7 8 9 10 11
/*
 * GNU General Public License for more details.
 *
 * MATRIX Vision GmbH / June 2002-Nov 2003
 * Andre Schwarz
 */

#include <common.h>
#include <mpc824x.h>
#include <asm/io.h>
#include <ns16550.h>
12
#include <netdev.h>
wdenk's avatar
wdenk committed
13 14

#ifdef CONFIG_PCI
wdenk's avatar
wdenk committed
15
#include <pci.h>
wdenk's avatar
wdenk committed
16 17
#endif

18 19
DECLARE_GLOBAL_DATA_PTR;

wdenk's avatar
wdenk committed
20
u32 get_BoardType (void);
wdenk's avatar
wdenk committed
21 22

#define PCI_CONFIG(b,d,f,r)    cpu_to_le32(0x80000000 | ((b&0xff)<<16) \
wdenk's avatar
wdenk committed
23 24 25
						      | ((d&0x1f)<<11) \
						      | ((f&0x7)<<7)   \
						      | (r&0xfc) )
wdenk's avatar
wdenk committed
26

wdenk's avatar
wdenk committed
27
int mv_pci_read (int bus, int dev, int func, int reg)
wdenk's avatar
wdenk committed
28
{
wdenk's avatar
wdenk committed
29 30 31
	*(u32 *) (0xfec00cf8) = PCI_CONFIG (bus, dev, func, reg);
	asm ("sync");
	return cpu_to_le32 (*(u32 *) (0xfee00cfc));
wdenk's avatar
wdenk committed
32
}
wdenk's avatar
wdenk committed
33 34 35 36

u32 get_BoardType ()
{
	return (mv_pci_read (0, 0xe, 0, 0) == 0x06801095 ? 0 : 1);
wdenk's avatar
wdenk committed
37 38
}

wdenk's avatar
wdenk committed
39
void init_2nd_DUART (void)
wdenk's avatar
wdenk committed
40
{
wdenk's avatar
wdenk committed
41
	NS16550_t console = (NS16550_t) CFG_NS16550_COM2;
wdenk's avatar
wdenk committed
42
	int clock_divisor = CFG_NS16550_CLK / 16 / CONFIG_BAUDRATE;
wdenk's avatar
wdenk committed
43 44 45

	*(u8 *) (0xfc004511) = 0x1;
	NS16550_init (console, clock_divisor);
wdenk's avatar
wdenk committed
46
}
wdenk's avatar
wdenk committed
47
void hw_watchdog_reset (void)
wdenk's avatar
wdenk committed
48
{
wdenk's avatar
wdenk committed
49 50 51
	if (get_BoardType () == 0) {
		*(u32 *) (0xff000005) = 0;
		asm ("sync");
wdenk's avatar
wdenk committed
52 53 54 55
	}
}
int checkboard (void)
{
wdenk's avatar
wdenk committed
56 57 58
	ulong busfreq = get_bus_freq (0);
	char buf[32];
	u32 BoardType = get_BoardType ();
wdenk's avatar
wdenk committed
59 60 61 62
	char *BoardName[2] = { "mvBlueBOX", "mvBlueLYNX" };
	char *p;
	bd_t *bd = gd->bd;

wdenk's avatar
wdenk committed
63 64 65 66 67
	hw_watchdog_reset ();

	printf ("U-Boot (%s) running on mvBLUE device.\n", MV_VERSION);
	printf ("       Found %s running at %s MHz memory clock.\n",
		BoardName[BoardType], strmhz (buf, busfreq));
wdenk's avatar
wdenk committed
68

wdenk's avatar
wdenk committed
69
	init_2nd_DUART ();
wdenk's avatar
wdenk committed
70

wdenk's avatar
wdenk committed
71 72
	if ((p = getenv ("console_nr")) != NULL) {
		unsigned long con_nr = simple_strtoul (p, NULL, 10) & 3;
wdenk's avatar
wdenk committed
73

wdenk's avatar
wdenk committed
74 75
		bd->bi_baudrate &= ~3;
		bd->bi_baudrate |= con_nr & 3;
wdenk's avatar
wdenk committed
76 77 78 79
	}
	return 0;
}

80
phys_size_t initdram (int board_type)
wdenk's avatar
wdenk committed
81
{
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
	long size;
	long new_bank0_end;
	long mear1;
	long emear1;

	size = get_ram_size(CFG_SDRAM_BASE, CFG_MAX_RAM_SIZE);

	new_bank0_end = size - 1;
	mear1 = mpc824x_mpc107_getreg(MEAR1);
	emear1 = mpc824x_mpc107_getreg(EMEAR1);
	mear1 = (mear1  & 0xFFFFFF00) |
		((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
	emear1 = (emear1 & 0xFFFFFF00) |
		((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
	mpc824x_mpc107_setreg(MEAR1,  mear1);
	mpc824x_mpc107_setreg(EMEAR1, emear1);

	return (size);
wdenk's avatar
wdenk committed
100 101 102
}

/* ------------------------------------------------------------------------- */
wdenk's avatar
wdenk committed
103
u8 *dhcp_vendorex_prep (u8 * e)
wdenk's avatar
wdenk committed
104
{
wdenk's avatar
wdenk committed
105
	char *ptr;
wdenk's avatar
wdenk committed
106 107

	/* DHCP vendor-class-identifier = 60 */
wdenk's avatar
wdenk committed
108 109 110 111 112 113
	if ((ptr = getenv ("dhcp_vendor-class-identifier"))) {
		*e++ = 60;
		*e++ = strlen (ptr);
		while (*ptr)
			*e++ = *ptr++;
	}
wdenk's avatar
wdenk committed
114
	/* my DHCP_CLIENT_IDENTIFIER = 61 */
wdenk's avatar
wdenk committed
115 116 117 118 119 120 121
	if ((ptr = getenv ("dhcp_client_id"))) {
		*e++ = 61;
		*e++ = strlen (ptr);
		while (*ptr)
			*e++ = *ptr++;
	}
	return e;
wdenk's avatar
wdenk committed
122
}
wdenk's avatar
wdenk committed
123 124

u8 *dhcp_vendorex_proc (u8 * popt)
wdenk's avatar
wdenk committed
125
{
wdenk's avatar
wdenk committed
126
	return NULL;
wdenk's avatar
wdenk committed
127
}
wdenk's avatar
wdenk committed
128

wdenk's avatar
wdenk committed
129 130 131 132 133 134
/* ------------------------------------------------------------------------- */

/*
 * Initialize PCI Devices
 */
#ifdef CONFIG_PCI
wdenk's avatar
wdenk committed
135
void pci_mvblue_clear_base (struct pci_controller *hose, pci_dev_t dev)
wdenk's avatar
wdenk committed
136 137
{
	u32 cnt;
wdenk's avatar
wdenk committed
138 139 140 141 142 143 144

	printf ("clear base @ dev/func 0x%02x/0x%02x ... ", PCI_DEV (dev),
		PCI_FUNC (dev));
	for (cnt = 0; cnt < 6; cnt++)
		pci_hose_write_config_dword (hose, dev, 0x10 + (4 * cnt),
					     0x0);
	printf ("done\n");
wdenk's avatar
wdenk committed
145 146
}

wdenk's avatar
wdenk committed
147
void duart_setup (u32 base, u16 divisor)
wdenk's avatar
wdenk committed
148
{
wdenk's avatar
wdenk committed
149 150 151 152 153 154 155 156
	printf ("duart setup ...");
	out_8 ((u8 *) (CFG_ISA_IO + base + 3), 0x80);
	out_8 ((u8 *) (CFG_ISA_IO + base + 0), divisor & 0xff);
	out_8 ((u8 *) (CFG_ISA_IO + base + 1), divisor >> 8);
	out_8 ((u8 *) (CFG_ISA_IO + base + 3), 0x03);
	out_8 ((u8 *) (CFG_ISA_IO + base + 4), 0x03);
	out_8 ((u8 *) (CFG_ISA_IO + base + 2), 0x07);
	printf ("done\n");
wdenk's avatar
wdenk committed
157 158
}

wdenk's avatar
wdenk committed
159 160
void pci_mvblue_fixup_irq_behind_bridge (struct pci_controller *hose,
					 pci_dev_t bridge, unsigned char irq)
wdenk's avatar
wdenk committed
161 162
{
	pci_dev_t d;
wdenk's avatar
wdenk committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
	unsigned char bus;
	unsigned short vendor, class;

	pci_hose_read_config_byte (hose, bridge, PCI_SECONDARY_BUS, &bus);
	for (d = PCI_BDF (bus, 0, 0);
	     d < PCI_BDF (bus, PCI_MAX_PCI_DEVICES - 1,
			  PCI_MAX_PCI_FUNCTIONS - 1);
	     d += PCI_BDF (0, 0, 1)) {
		pci_hose_read_config_word (hose, d, PCI_VENDOR_ID, &vendor);
		if (vendor != 0xffff && vendor != 0x0000) {
			pci_hose_read_config_word (hose, d, PCI_CLASS_DEVICE,
						   &class);
			if (class == PCI_CLASS_BRIDGE_PCI)
				pci_mvblue_fixup_irq_behind_bridge (hose, d,
								    irq);
wdenk's avatar
wdenk committed
178
			else
wdenk's avatar
wdenk committed
179 180 181
				pci_hose_write_config_byte (hose, d,
							    PCI_INTERRUPT_LINE,
							    irq);
wdenk's avatar
wdenk committed
182 183 184 185 186 187 188
		}
	}
}

#define MV_MAX_PCI_BUSSES	3
#define SLOT0_IRQ	3
#define SLOT1_IRQ	4
wdenk's avatar
wdenk committed
189
void pci_mvblue_fixup_irq (struct pci_controller *hose, pci_dev_t dev)
wdenk's avatar
wdenk committed
190
{
wdenk's avatar
wdenk committed
191 192
	unsigned char line = 0xff;
	unsigned short class;
wdenk's avatar
wdenk committed
193

wdenk's avatar
wdenk committed
194 195 196 197
	if (PCI_BUS (dev) == 0) {
		switch (PCI_DEV (dev)) {
		case 0xd:
			if (get_BoardType () == 0) {
wdenk's avatar
wdenk committed
198 199 200
				line = 1;
			} else
				/* mvBL */
wdenk's avatar
wdenk committed
201 202 203
				line = 2;
			break;
		case 0xe:
wdenk's avatar
wdenk committed
204 205
			/* mvBB: IDE */
			line = 2;
wdenk's avatar
wdenk committed
206
			pci_hose_write_config_byte (hose, dev, 0x8a, 0x20);
wdenk's avatar
wdenk committed
207 208 209
			break;
		case 0xf:
			/* mvBB: Slot0 (Grabber) */
wdenk's avatar
wdenk committed
210 211 212 213 214
			pci_hose_read_config_word (hose, dev,
						   PCI_CLASS_DEVICE, &class);
			if (class == PCI_CLASS_BRIDGE_PCI) {
				pci_mvblue_fixup_irq_behind_bridge (hose, dev,
								    SLOT0_IRQ);
wdenk's avatar
wdenk committed
215 216 217 218 219 220
				line = 0xff;
			} else
				line = SLOT0_IRQ;
			break;
		case 0x10:
			/* mvBB: Slot1 */
wdenk's avatar
wdenk committed
221 222 223 224 225
			pci_hose_read_config_word (hose, dev,
						   PCI_CLASS_DEVICE, &class);
			if (class == PCI_CLASS_BRIDGE_PCI) {
				pci_mvblue_fixup_irq_behind_bridge (hose, dev,
								    SLOT1_IRQ);
wdenk's avatar
wdenk committed
226 227 228 229
				line = 0xff;
			} else
				line = SLOT1_IRQ;
			break;
wdenk's avatar
wdenk committed
230 231 232
		default:
			printf ("***pci_scan: illegal dev = 0x%08x\n",
				PCI_DEV (dev));
wdenk's avatar
wdenk committed
233 234
			line = 0xff;
			break;
wdenk's avatar
wdenk committed
235 236 237
		}
		pci_hose_write_config_byte (hose, dev, PCI_INTERRUPT_LINE,
					    line);
wdenk's avatar
wdenk committed
238 239 240 241
	}
}

struct pci_controller hose = {
wdenk's avatar
wdenk committed
242
	fixup_irq:pci_mvblue_fixup_irq
wdenk's avatar
wdenk committed
243 244
};

wdenk's avatar
wdenk committed
245
void pci_init_board (void)
wdenk's avatar
wdenk committed
246
{
wdenk's avatar
wdenk committed
247
	pci_mpc824x_init (&hose);
wdenk's avatar
wdenk committed
248
}
249 250 251 252 253

int board_eth_init(bd_t *bis)
{
	return pci_eth_init(bis);
}
wdenk's avatar
wdenk committed
254
#endif