blob: 6dcbd8b24c2ed1bfb11aabd8f6c5890ef416ac74 [file] [log] [blame]
stroeseb762b9f2003-07-11 08:14:14 +00001/*
2 * (C) Copyright 2003
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
stroeseb762b9f2003-07-11 08:14:14 +00006 */
7
8#include <common.h>
9#include <command.h>
10#include <pci.h>
Wolfgang Denk9ea4b582005-09-23 13:12:15 +020011#include <pci_ids.h>
Stefan Roese3048bcb2007-10-03 15:01:02 +020012#include <asm/4xx_pci.h>
stroeseb762b9f2003-07-11 08:14:14 +000013
14
Jon Loeligerb9307262007-07-09 18:24:55 -050015#if defined(CONFIG_CMD_BSP)
stroeseb762b9f2003-07-11 08:14:14 +000016
stroeseb762b9f2003-07-11 08:14:14 +000017/*
18 * Set device number on pci board
19 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020020int do_setdevice(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroeseb762b9f2003-07-11 08:14:14 +000021{
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 Denk9ea4b582005-09-23 13:12:15 +020027 if ((bdf = pci_find_device(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_405GP, idx++)) < 0) {
stroeseb762b9f2003-07-11 08:14:14 +000028 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}
39U_BOOT_CMD(
40 setdevice, 1, 1, do_setdevice,
Peter Tyser2fb26042009-01-27 18:03:12 -060041 "Set device number on pci adapter boards",
Wolfgang Denka89c33d2009-05-24 17:06:54 +020042 ""
stroeseb762b9f2003-07-11 08:14:14 +000043);
44
45
46/*
47 * Get device number on pci board
48 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020049int do_getdevice(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroeseb762b9f2003-07-11 08:14:14 +000050{
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}
62U_BOOT_CMD(
63 getdevice, 1, 1, do_getdevice,
Peter Tyser2fb26042009-01-27 18:03:12 -060064 "Get device number and set slot env variable",
Wolfgang Denka89c33d2009-05-24 17:06:54 +020065 ""
stroeseb762b9f2003-07-11 08:14:14 +000066);
67
68#endif