stroese | b762b9f | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
stroese | b762b9f | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <pci.h> |
Wolfgang Denk | 9ea4b58 | 2005-09-23 13:12:15 +0200 | [diff] [blame] | 11 | #include <pci_ids.h> |
Stefan Roese | 3048bcb | 2007-10-03 15:01:02 +0200 | [diff] [blame] | 12 | #include <asm/4xx_pci.h> |
stroese | b762b9f | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 13 | |
| 14 | |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 15 | #if defined(CONFIG_CMD_BSP) |
stroese | b762b9f | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 16 | |
stroese | b762b9f | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 17 | /* |
| 18 | * Set device number on pci board |
| 19 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 20 | int do_setdevice(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
stroese | b762b9f | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 21 | { |
| 22 | int idx = 1; /* start at 1 (skip device 0) */ |
| 23 | pci_dev_t bdf = 0; |
| 24 | u32 addr; |
| 25 | |
| 26 | while (bdf >= 0) { |
Wolfgang Denk | 9ea4b58 | 2005-09-23 13:12:15 +0200 | [diff] [blame] | 27 | if ((bdf = pci_find_device(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_405GP, idx++)) < 0) { |
stroese | b762b9f | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 28 | break; |
| 29 | } |
| 30 | printf("Found device nr %d at %x!\n", idx-1, bdf); |
| 31 | pci_read_config_dword(bdf, PCI_BASE_ADDRESS_1, &addr); |
| 32 | addr &= ~0xf; |
| 33 | *(u32 *)addr = (bdf & 0x0000f800) >> 11; |
| 34 | printf("Wrote %x at %x!\n", (bdf & 0x0000f800) >> 11, addr); |
| 35 | } |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | U_BOOT_CMD( |
| 40 | setdevice, 1, 1, do_setdevice, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 41 | "Set device number on pci adapter boards", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 42 | "" |
stroese | b762b9f | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 43 | ); |
| 44 | |
| 45 | |
| 46 | /* |
| 47 | * Get device number on pci board |
| 48 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 49 | int do_getdevice(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
stroese | b762b9f | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 50 | { |
| 51 | u32 device; |
| 52 | char str[32]; |
| 53 | |
| 54 | device = *(u32 *)0x0; |
| 55 | device = 0x16 - device; /* calculate vxworks bp slot id */ |
| 56 | sprintf(str, "%d", device); |
| 57 | setenv("slot", str); |
| 58 | printf("Variabel slot set to %x\n", device); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | U_BOOT_CMD( |
| 63 | getdevice, 1, 1, do_getdevice, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 64 | "Get device number and set slot env variable", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 65 | "" |
stroese | b762b9f | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 66 | ); |
| 67 | |
| 68 | #endif |