wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
| 26 | #include <command.h> |
| 27 | #include <pci.h> |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 28 | #include <asm/io.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 29 | |
| 30 | #define OK 0 |
| 31 | #define ERROR (-1) |
| 32 | |
| 33 | #define TRUE 1 |
| 34 | #define FALSE 0 |
| 35 | |
| 36 | |
| 37 | extern u_long pci9054_iobase; |
| 38 | |
| 39 | |
| 40 | /*************************************************************************** |
| 41 | * |
| 42 | * Routines for PLX PCI9054 eeprom access |
| 43 | * |
| 44 | */ |
| 45 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 46 | static unsigned int PciEepromReadLongVPD (int offs) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 47 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 48 | unsigned int value; |
| 49 | unsigned int ret; |
| 50 | int count; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 51 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 52 | pci_write_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x4c, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 53 | (offs << 16) | 0x0003); |
| 54 | count = 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 55 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 56 | for (;;) { |
| 57 | udelay (10 * 1000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 58 | pci_read_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x4c, &ret); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 59 | if ((ret & 0x80000000) != 0) { |
| 60 | break; |
| 61 | } else { |
| 62 | count++; |
| 63 | if (count > 10) { |
| 64 | printf ("\nTimeout: ret=%08x - Please try again!\n", ret); |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 69 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 70 | pci_read_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x50, &value); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 71 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 72 | return value; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 76 | static int PciEepromWriteLongVPD (int offs, unsigned int value) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 77 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 78 | unsigned int ret; |
| 79 | int count; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 80 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | pci_write_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x50, value); |
| 82 | pci_write_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x4c, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 83 | (offs << 16) | 0x80000003); |
| 84 | count = 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 85 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | for (;;) { |
| 87 | udelay (10 * 1000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 88 | pci_read_config_dword (CONFIG_SYS_PCI9054_DEV_FN, 0x4c, &ret); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 89 | if ((ret & 0x80000000) == 0) { |
| 90 | break; |
| 91 | } else { |
| 92 | count++; |
| 93 | if (count > 10) { |
| 94 | printf ("\nTimeout: ret=%08x - Please try again!\n", ret); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 99 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 100 | return TRUE; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 104 | static void showPci9054 (void) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 105 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 106 | int val; |
| 107 | int l, i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 108 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 109 | /* read 9054-values */ |
| 110 | for (l = 0; l < 6; l++) { |
| 111 | printf ("%02x: ", l * 0x10); |
| 112 | for (i = 0; i < 4; i++) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | pci_read_config_dword (CONFIG_SYS_PCI9054_DEV_FN, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 114 | l * 16 + i * 4, |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 115 | (unsigned int *)&val); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 116 | printf ("%08x ", val); |
| 117 | } |
| 118 | printf ("\n"); |
| 119 | } |
| 120 | printf ("\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 121 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 122 | for (l = 0; l < 7; l++) { |
| 123 | printf ("%02x: ", l * 0x10); |
| 124 | for (i = 0; i < 4; i++) |
| 125 | printf ("%08x ", |
| 126 | PciEepromReadLongVPD ((i + l * 4) * 4)); |
| 127 | printf ("\n"); |
| 128 | } |
| 129 | printf ("\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 133 | static void updatePci9054 (void) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 134 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | int val; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 136 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 137 | /* |
| 138 | * Set EEPROM write-protect register to 0 |
| 139 | */ |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 140 | out_be32 ((void *)(pci9054_iobase + 0x0c), |
| 141 | in_be32 ((void *)(pci9054_iobase + 0x0c)) & 0xffff00ff); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 142 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 143 | /* Long Serial EEPROM Load Registers... */ |
| 144 | val = PciEepromWriteLongVPD (0x00, 0x905410b5); |
| 145 | val = PciEepromWriteLongVPD (0x04, 0x09800001); /* other input controller */ |
| 146 | val = PciEepromWriteLongVPD (0x08, 0x28140100); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 147 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 148 | val = PciEepromWriteLongVPD (0x0c, 0x00000000); /* MBOX0... */ |
| 149 | val = PciEepromWriteLongVPD (0x10, 0x00000000); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 150 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 151 | /* las0: fpga access (0x0000.0000 ... 0x0003.ffff) */ |
| 152 | val = PciEepromWriteLongVPD (0x14, 0xfffc0000); /* LAS0RR... */ |
| 153 | val = PciEepromWriteLongVPD (0x18, 0x00000001); /* LAS0BA */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 154 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 155 | val = PciEepromWriteLongVPD (0x1c, 0x00200000); /* MARBR... */ |
| 156 | val = PciEepromWriteLongVPD (0x20, 0x00300500); /* LMISC/BIGEND */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 157 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 158 | val = PciEepromWriteLongVPD (0x24, 0x00000000); /* EROMRR... */ |
| 159 | val = PciEepromWriteLongVPD (0x28, 0x00000000); /* EROMBA */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 160 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 161 | val = PciEepromWriteLongVPD (0x2c, 0x43030000); /* LBRD0... */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 162 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 163 | val = PciEepromWriteLongVPD (0x30, 0x00000000); /* DMRR... */ |
| 164 | val = PciEepromWriteLongVPD (0x34, 0x00000000); |
| 165 | val = PciEepromWriteLongVPD (0x38, 0x00000000); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 166 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 167 | val = PciEepromWriteLongVPD (0x3c, 0x00000000); /* DMPBAM... */ |
| 168 | val = PciEepromWriteLongVPD (0x40, 0x00000000); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 169 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 170 | /* Extra Long Serial EEPROM Load Registers... */ |
| 171 | val = PciEepromWriteLongVPD (0x44, 0x010212fe); /* PCISID... */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 172 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 173 | /* las1: 505-sram access (0x0004.0000 ... 0x001f.ffff) */ |
| 174 | /* Offset to LAS1: Group 1: 0x00040000 */ |
| 175 | /* Group 2: 0x00080000 */ |
| 176 | /* Group 3: 0x000c0000 */ |
| 177 | val = PciEepromWriteLongVPD (0x48, 0xffe00000); /* LAS1RR */ |
| 178 | val = PciEepromWriteLongVPD (0x4c, 0x00040001); /* LAS1BA */ |
| 179 | val = PciEepromWriteLongVPD (0x50, 0x00000208); /* LBRD1 */ /* so wars bisher */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 180 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 181 | val = PciEepromWriteLongVPD (0x54, 0x00004c06); /* HotSwap... */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 182 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 183 | printf ("Finished writing defaults into PLX PCI9054 EEPROM!\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 187 | static void clearPci9054 (void) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 188 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 189 | int val; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 190 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 191 | /* |
| 192 | * Set EEPROM write-protect register to 0 |
| 193 | */ |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 194 | out_be32 ((void *)(pci9054_iobase + 0x0c), |
| 195 | in_be32 ((void *)(pci9054_iobase + 0x0c)) & 0xffff00ff); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 196 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 197 | /* Long Serial EEPROM Load Registers... */ |
| 198 | val = PciEepromWriteLongVPD (0x00, 0xffffffff); |
| 199 | val = PciEepromWriteLongVPD (0x04, 0xffffffff); /* other input controller */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 200 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 201 | printf ("Finished clearing PLX PCI9054 EEPROM!\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
| 205 | /* ------------------------------------------------------------------------- */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 206 | int do_pci9054 (cmd_tbl_t * cmdtp, int flag, int argc, |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 207 | char * const argv[]) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 208 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 209 | if (strcmp (argv[1], "info") == 0) { |
| 210 | showPci9054 (); |
| 211 | return 0; |
| 212 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 213 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 214 | if (strcmp (argv[1], "update") == 0) { |
| 215 | updatePci9054 (); |
| 216 | return 0; |
| 217 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 218 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 219 | if (strcmp (argv[1], "clear") == 0) { |
| 220 | clearPci9054 (); |
| 221 | return 0; |
| 222 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 223 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame^] | 224 | return cmd_usage(cmdtp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 225 | } |
| 226 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 227 | U_BOOT_CMD( |
| 228 | pci9054, 3, 1, do_pci9054, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 229 | "PLX PCI9054 EEPROM access", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 230 | "pci9054 info - print EEPROM values\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 231 | "pci9054 update - updates EEPROM with default values" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 232 | ); |
| 233 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 234 | /* ------------------------------------------------------------------------- */ |