cmd_dasa_sim.c 5.82 KB
Newer Older
wdenk's avatar
wdenk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * (C) Copyright 2001
 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 */

#include <common.h>
#include <command.h>
#include <pci.h>
28
#include <asm/io.h>
wdenk's avatar
wdenk committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

#define OK 0
#define ERROR (-1)

#define TRUE 1
#define FALSE 0


extern u_long pci9054_iobase;


/***************************************************************************
 *
 * Routines for PLX PCI9054 eeprom access
 *
 */

wdenk's avatar
wdenk committed
46
static unsigned int PciEepromReadLongVPD (int offs)
wdenk's avatar
wdenk committed
47
{
wdenk's avatar
wdenk committed
48 49 50 51
	unsigned int value;
	unsigned int ret;
	int count;

52
	pci_write_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x4c,
wdenk's avatar
wdenk committed
53 54 55 56 57
				(offs << 16) | 0x0003);
	count = 0;

	for (;;) {
		udelay (10 * 1000);
58
		pci_read_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x4c, &ret);
wdenk's avatar
wdenk committed
59 60 61 62 63 64 65 66 67 68 69
		if ((ret & 0x80000000) != 0) {
			break;
		} else {
			count++;
			if (count > 10) {
				printf ("\nTimeout: ret=%08x - Please try again!\n", ret);
				break;
			}
		}
	}

70
	pci_read_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x50, &value);
wdenk's avatar
wdenk committed
71 72

	return value;
wdenk's avatar
wdenk committed
73 74 75
}


wdenk's avatar
wdenk committed
76
static int PciEepromWriteLongVPD (int offs, unsigned int value)
wdenk's avatar
wdenk committed
77
{
wdenk's avatar
wdenk committed
78 79 80
	unsigned int ret;
	int count;

81 82
	pci_write_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x50, value);
	pci_write_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x4c,
wdenk's avatar
wdenk committed
83 84 85 86 87
				(offs << 16) | 0x80000003);
	count = 0;

	for (;;) {
		udelay (10 * 1000);
88
		pci_read_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x4c, &ret);
wdenk's avatar
wdenk committed
89 90 91 92 93 94 95 96 97 98 99 100
		if ((ret & 0x80000000) == 0) {
			break;
		} else {
			count++;
			if (count > 10) {
				printf ("\nTimeout: ret=%08x - Please try again!\n", ret);
				break;
			}
		}
	}

	return TRUE;
wdenk's avatar
wdenk committed
101 102 103
}


wdenk's avatar
wdenk committed
104
static void showPci9054 (void)
wdenk's avatar
wdenk committed
105
{
wdenk's avatar
wdenk committed
106 107 108 109 110 111 112
	int val;
	int l, i;

	/* read 9054-values */
	for (l = 0; l < 6; l++) {
		printf ("%02x: ", l * 0x10);
		for (i = 0; i < 4; i++) {
113
			pci_read_config_dword (CONFIG_SYS_PCI9054_DEV_FN,
wdenk's avatar
wdenk committed
114
						l * 16 + i * 4,
Wolfgang Denk's avatar
Wolfgang Denk committed
115
						(unsigned int *)&val);
wdenk's avatar
wdenk committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129
			printf ("%08x ", val);
		}
		printf ("\n");
	}
	printf ("\n");

	for (l = 0; l < 7; l++) {
		printf ("%02x: ", l * 0x10);
		for (i = 0; i < 4; i++)
			printf ("%08x ",
				PciEepromReadLongVPD ((i + l * 4) * 4));
		printf ("\n");
	}
	printf ("\n");
wdenk's avatar
wdenk committed
130 131 132
}


wdenk's avatar
wdenk committed
133
static void updatePci9054 (void)
wdenk's avatar
wdenk committed
134
{
wdenk's avatar
wdenk committed
135
	int val;
wdenk's avatar
wdenk committed
136

wdenk's avatar
wdenk committed
137 138 139
	/*
	 * Set EEPROM write-protect register to 0
	 */
140 141
	out_be32 ((void *)(pci9054_iobase + 0x0c),
		  in_be32 ((void *)(pci9054_iobase + 0x0c)) & 0xffff00ff);
wdenk's avatar
wdenk committed
142

wdenk's avatar
wdenk committed
143 144 145 146
	/* Long Serial EEPROM Load Registers... */
	val = PciEepromWriteLongVPD (0x00, 0x905410b5);
	val = PciEepromWriteLongVPD (0x04, 0x09800001);	/* other input controller */
	val = PciEepromWriteLongVPD (0x08, 0x28140100);
wdenk's avatar
wdenk committed
147

wdenk's avatar
wdenk committed
148 149
	val = PciEepromWriteLongVPD (0x0c, 0x00000000);	/* MBOX0... */
	val = PciEepromWriteLongVPD (0x10, 0x00000000);
wdenk's avatar
wdenk committed
150

wdenk's avatar
wdenk committed
151 152 153
	/* las0: fpga access (0x0000.0000 ... 0x0003.ffff) */
	val = PciEepromWriteLongVPD (0x14, 0xfffc0000);	/* LAS0RR... */
	val = PciEepromWriteLongVPD (0x18, 0x00000001);	/* LAS0BA */
wdenk's avatar
wdenk committed
154

wdenk's avatar
wdenk committed
155 156
	val = PciEepromWriteLongVPD (0x1c, 0x00200000);	/* MARBR... */
	val = PciEepromWriteLongVPD (0x20, 0x00300500);	/* LMISC/BIGEND */
wdenk's avatar
wdenk committed
157

wdenk's avatar
wdenk committed
158 159
	val = PciEepromWriteLongVPD (0x24, 0x00000000);	/* EROMRR... */
	val = PciEepromWriteLongVPD (0x28, 0x00000000);	/* EROMBA */
wdenk's avatar
wdenk committed
160

wdenk's avatar
wdenk committed
161
	val = PciEepromWriteLongVPD (0x2c, 0x43030000);	/* LBRD0... */
wdenk's avatar
wdenk committed
162

wdenk's avatar
wdenk committed
163 164 165
	val = PciEepromWriteLongVPD (0x30, 0x00000000);	/* DMRR... */
	val = PciEepromWriteLongVPD (0x34, 0x00000000);
	val = PciEepromWriteLongVPD (0x38, 0x00000000);
wdenk's avatar
wdenk committed
166

wdenk's avatar
wdenk committed
167 168
	val = PciEepromWriteLongVPD (0x3c, 0x00000000);	/* DMPBAM... */
	val = PciEepromWriteLongVPD (0x40, 0x00000000);
wdenk's avatar
wdenk committed
169

wdenk's avatar
wdenk committed
170 171
	/* Extra Long Serial EEPROM Load Registers... */
	val = PciEepromWriteLongVPD (0x44, 0x010212fe);	/* PCISID... */
wdenk's avatar
wdenk committed
172

wdenk's avatar
wdenk committed
173 174 175 176 177 178 179
	/* las1: 505-sram access (0x0004.0000 ... 0x001f.ffff) */
	/* Offset to LAS1: Group 1: 0x00040000                 */
	/*                 Group 2: 0x00080000                 */
	/*                 Group 3: 0x000c0000                 */
	val = PciEepromWriteLongVPD (0x48, 0xffe00000);	/* LAS1RR */
	val = PciEepromWriteLongVPD (0x4c, 0x00040001);	/* LAS1BA */
	val = PciEepromWriteLongVPD (0x50, 0x00000208);	/* LBRD1 */ /* so wars bisher */
wdenk's avatar
wdenk committed
180

wdenk's avatar
wdenk committed
181
	val = PciEepromWriteLongVPD (0x54, 0x00004c06);	/* HotSwap... */
wdenk's avatar
wdenk committed
182

wdenk's avatar
wdenk committed
183
	printf ("Finished writing defaults into PLX PCI9054 EEPROM!\n");
wdenk's avatar
wdenk committed
184 185 186
}


wdenk's avatar
wdenk committed
187
static void clearPci9054 (void)
wdenk's avatar
wdenk committed
188
{
wdenk's avatar
wdenk committed
189
	int val;
wdenk's avatar
wdenk committed
190

wdenk's avatar
wdenk committed
191 192 193
	/*
	 * Set EEPROM write-protect register to 0
	 */
194 195
	out_be32 ((void *)(pci9054_iobase + 0x0c),
		  in_be32 ((void *)(pci9054_iobase + 0x0c)) & 0xffff00ff);
wdenk's avatar
wdenk committed
196

wdenk's avatar
wdenk committed
197 198 199
	/* Long Serial EEPROM Load Registers... */
	val = PciEepromWriteLongVPD (0x00, 0xffffffff);
	val = PciEepromWriteLongVPD (0x04, 0xffffffff);	/* other input controller */
wdenk's avatar
wdenk committed
200

wdenk's avatar
wdenk committed
201
	printf ("Finished clearing PLX PCI9054 EEPROM!\n");
wdenk's avatar
wdenk committed
202 203 204 205
}


/* ------------------------------------------------------------------------- */
wdenk's avatar
wdenk committed
206 207
int do_pci9054 (cmd_tbl_t * cmdtp, int flag, int argc,
				char *argv[])
wdenk's avatar
wdenk committed
208
{
wdenk's avatar
wdenk committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
	if (strcmp (argv[1], "info") == 0) {
		showPci9054 ();
		return 0;
	}

	if (strcmp (argv[1], "update") == 0) {
		updatePci9054 ();
		return 0;
	}

	if (strcmp (argv[1], "clear") == 0) {
		clearPci9054 ();
		return 0;
	}

224
	cmd_usage(cmdtp);
wdenk's avatar
wdenk committed
225
	return 1;
wdenk's avatar
wdenk committed
226 227 228

}

229 230
U_BOOT_CMD(
	pci9054, 3, 1, do_pci9054,
Peter Tyser's avatar
Peter Tyser committed
231
	"PLX PCI9054 EEPROM access",
wdenk's avatar
wdenk committed
232
	"pci9054 info - print EEPROM values\n"
Wolfgang Denk's avatar
Wolfgang Denk committed
233
	"pci9054 update - updates EEPROM with default values"
wdenk's avatar
wdenk committed
234 235
);

wdenk's avatar
wdenk committed
236
/* ------------------------------------------------------------------------- */