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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
stroese | c5c31a7 | 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 | 152870d | 2005-09-23 13:12:15 +0200 | [diff] [blame] | 11 | #include <pci_ids.h> |
Stefan Roese | ca8725f | 2007-10-03 15:01:02 +0200 | [diff] [blame] | 12 | #include <asm/4xx_pci.h> |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 13 | |
| 14 | |
Jon Loeliger | 4ed9ed6 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 15 | #if defined(CONFIG_CMD_BSP) |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 16 | |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 17 | /* |
| 18 | * Set device number on pci board |
| 19 | */ |
Wolfgang Denk | 6262d021 | 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 | c5c31a7 | 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 | 152870d | 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 | c5c31a7 | 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 | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 41 | "Set device number on pci adapter boards", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 42 | "" |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 43 | ); |
| 44 | |
| 45 | |
| 46 | /* |
| 47 | * Get device number on pci board |
| 48 | */ |
Wolfgang Denk | 6262d021 | 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 | c5c31a7 | 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 | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 64 | "Get device number and set slot env variable", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 65 | "" |
stroese | c5c31a7 | 2003-07-11 08:14:14 +0000 | [diff] [blame] | 66 | ); |
| 67 | |
| 68 | #endif |