ide: Move bus init into a function

Move this code into a separate function which returns whether the bus was
found, or not.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2023-04-25 10:54:42 -06:00 committed by Tom Rini
parent 8b1b943a7a
commit b6483ea223

View File

@ -679,29 +679,20 @@ static void ide_ident(struct blk_desc *dev_desc)
#endif #endif
} }
static void ide_init(void) /**
{ * ide_init_one() - Init one IDE device
unsigned char c; *
int i, bus; * @bus: Bus to use
* Return: 0 iuf OK, -EIO if not available, -ETIMEDOUT if timed out
schedule();
/* ATAPI Drives seems to need a proper IDE Reset */
ide_reset();
/*
* Wait for IDE to get ready.
* According to spec, this can take up to 31 seconds!
*/ */
for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) { static int ide_init_one(int bus)
int dev = {
bus * (CONFIG_SYS_IDE_MAXDEVICE / int dev = bus * CONFIG_SYS_IDE_MAXDEVICE / CONFIG_SYS_IDE_MAXBUS;
CONFIG_SYS_IDE_MAXBUS); int i;
u8 c;
printf("Bus %d: ", bus); printf("Bus %d: ", bus);
ide_bus_ok[bus] = 0;
/* Select device */ /* Select device */
mdelay(100); mdelay(100);
ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev)); ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev));
@ -714,24 +705,42 @@ static void ide_init(void)
i++; i++;
if (i > (ATA_RESET_TIME * 100)) { if (i > (ATA_RESET_TIME * 100)) {
puts("** Timeout **\n"); puts("** Timeout **\n");
return; return -ETIMEDOUT;
} }
if ((i >= 100) && ((i % 100) == 0)) if (i >= 100 && !(i % 100))
putc('.'); putc('.');
} while (c & ATA_STAT_BUSY); } while (c & ATA_STAT_BUSY);
if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) { if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) {
puts("not available "); puts("not available ");
debug("Status = 0x%02X ", c); debug("Status = 0x%02X ", c);
return -EIO;
} else if (IS_ENABLED(CONFIG_ATAPI) && !(c & ATA_STAT_READY)) { } else if (IS_ENABLED(CONFIG_ATAPI) && !(c & ATA_STAT_READY)) {
/* ATAPI Devices do not set DRDY */ /* ATAPI Devices do not set DRDY */
puts("not available "); puts("not available ");
debug("Status = 0x%02X ", c); debug("Status = 0x%02X ", c);
} else { return -EIO;
puts("OK ");
ide_bus_ok[bus] = 1;
} }
puts("OK ");
return 0;
}
static void ide_init(void)
{
int i, bus;
schedule();
/* ATAPI Drives seems to need a proper IDE Reset */
ide_reset();
/*
* Wait for IDE to get ready.
* According to spec, this can take up to 31 seconds!
*/
for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) {
ide_bus_ok[bus] = !ide_init_one(bus);
schedule(); schedule();
} }