stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 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 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | #include <pci.h> |
Wolfgang Denk | 152870d | 2005-09-23 13:12:15 +0200 | [diff] [blame] | 27 | #include <pci_ids.h> |
Stefan Roese | ca8725f | 2007-10-03 15:01:02 +0200 | [diff] [blame] | 28 | #include <asm/4xx_pci.h> |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 29 | |
| 30 | |
Jon Loeliger | 4ed9ed6 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 31 | #if defined(CONFIG_CMD_BSP) |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 32 | |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 33 | /* |
| 34 | * Set device number on pci board |
| 35 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 36 | int do_setdevice(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 37 | { |
| 38 | int idx = 1; /* start at 1 (skip device 0) */ |
| 39 | pci_dev_t bdf = 0; |
| 40 | u32 addr; |
| 41 | |
| 42 | while (bdf >= 0) { |
Wolfgang Denk | 152870d | 2005-09-23 13:12:15 +0200 | [diff] [blame] | 43 | if ((bdf = pci_find_device(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_405GP, idx++)) < 0) { |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 44 | break; |
| 45 | } |
| 46 | printf("Found device nr %d at %x!\n", idx-1, bdf); |
| 47 | pci_read_config_dword(bdf, PCI_BASE_ADDRESS_1, &addr); |
| 48 | addr &= ~0xf; |
| 49 | *(u32 *)addr = (bdf & 0x0000f800) >> 11; |
| 50 | printf("Wrote %x at %x!\n", (bdf & 0x0000f800) >> 11, addr); |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | U_BOOT_CMD( |
| 56 | setdevice, 1, 1, do_setdevice, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 57 | "Set device number on pci adapter boards", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 58 | "" |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 59 | ); |
| 60 | |
| 61 | |
| 62 | /* |
| 63 | * Get device number on pci board |
| 64 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 65 | int do_getdevice(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 66 | { |
| 67 | u32 device; |
| 68 | char str[32]; |
| 69 | |
| 70 | device = *(u32 *)0x0; |
| 71 | device = 0x16 - device; /* calculate vxworks bp slot id */ |
| 72 | sprintf(str, "%d", device); |
| 73 | setenv("slot", str); |
| 74 | printf("Variabel slot set to %x\n", device); |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | U_BOOT_CMD( |
| 79 | getdevice, 1, 1, do_getdevice, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 80 | "Get device number and set slot env variable", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 81 | "" |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 82 | ); |
| 83 | |
| 84 | #endif |