+
+#ifdef CONFIG_BOARD_LATE_INIT
+int board_late_init(void)
+{
+ pci_dev_t bdf;
+ ulong bootcount;
+
+ /*
+ * Check if the PEX switch is detected (somtimes its not available
+ * on the PCIe bus). In this case, try to recover by issuing a
+ * soft-reset or even a power-cycle, depending on the bootcounter
+ * value.
+ */
+ bdf = pci_find_device(PCI_VENDOR_ID_PLX, 0x8619, 0);
+ if (bdf == -1) {
+ u8 i2c_buf[8];
+ int ret;
+
+ /* PEX switch not found! */
+ bootcount = bootcount_load();
+ printf("Failed to find PLX PEX-switch (bootcount=%ld)\n",
+ bootcount);
+ if (bootcount > PEX_SWITCH_NOT_FOUNT_LIMIT) {
+ printf("Issuing power-switch via uC!\n");
+
+ printf("Issuing power-switch via uC!\n");
+ i2c_set_bus_num(STM_I2C_BUS);
+ i2c_buf[0] = STM_I2C_ADDR << 1;
+ i2c_buf[1] = 0xc5; /* cmd */
+ i2c_buf[2] = 0x01; /* enable */
+ /* Delay before reboot */
+ i2c_buf[3] = REBOOT_DELAY & 0x00ff;
+ i2c_buf[4] = (REBOOT_DELAY & 0xff00) >> 8;
+ /* Delay before shutdown */
+ i2c_buf[5] = 0x00;
+ i2c_buf[6] = 0x00;
+ i2c_buf[7] = crc8(0x72, &i2c_buf[0], 7);
+
+ ret = i2c_write(STM_I2C_ADDR, 0, 0, &i2c_buf[1], 7);
+ if (ret) {
+ printf("I2C write error (ret=%d)\n", ret);
+ printf("Issuing soft-reset...\n");
+ /* default handling: SOFT reset */
+ do_reset(NULL, 0, 0, NULL);
+ }
+
+ /* Wait for power-cycle to occur... */
+ printf("Waiting for power-cycle via uC...\n");
+ while (1)
+ ;
+ } else {
+ printf("Issuing soft-reset...\n");
+ /* default handling: SOFT reset */
+ do_reset(NULL, 0, 0, NULL);
+ }
+ }
+
+ return 0;
+}
+#endif
+
+#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_PCI)
+int do_pcie_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ pci_dev_t bdf;
+ u16 ven_id, dev_id;
+
+ if (argc != 3)
+ return cmd_usage(cmdtp);
+
+ ven_id = simple_strtoul(argv[1], NULL, 16);
+ dev_id = simple_strtoul(argv[2], NULL, 16);
+
+ printf("Checking for PCIe device: VendorID 0x%04x, DeviceId 0x%04x\n",
+ ven_id, dev_id);
+
+ /*
+ * Check if the PCIe device is detected (somtimes its not available
+ * on the PCIe bus)
+ */
+ bdf = pci_find_device(ven_id, dev_id, 0);
+ if (bdf == -1) {
+ /* PCIe device not found! */
+ printf("Failed to find PCIe device\n");
+ } else {
+ /* PCIe device found! */
+ printf("PCIe device found, resetting board...\n");
+
+ /* default handling: SOFT reset */
+ do_reset(NULL, 0, 0, NULL);
+ }
+
+ return 0;
+}
+
+U_BOOT_CMD(
+ pcie, 3, 0, do_pcie_test,
+ "Test for presence of a PCIe device",
+ "<VendorID> <DeviceID>"
+);
+#endif