aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-04-25 10:54:38 -0600
committerTom Rini <trini@konsulko.com>2023-04-27 13:51:06 -0400
commit6579bb00cf4f072084a02e806b214eed95a9e5bc (patch)
treea2e6e8e454b8f11d54735f51937ddcfa9ccc105d /drivers
parent2a165956ac804ebd825ba9eaf4fe26c9bbfb8925 (diff)
downloadu-boot-6579bb00cf4f072084a02e806b214eed95a9e5bc.zip
u-boot-6579bb00cf4f072084a02e806b214eed95a9e5bc.tar.gz
u-boot-6579bb00cf4f072084a02e806b214eed95a9e5bc.tar.bz2
ide: Refactor confusing loop code
This code is hard to follow as it uses #ifdef in a strange way. Adjust it to avoid the preprocessor. Drop the special return for the non-ATAPI case since we can rely on tries becoming 0 and exiting the loop. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/ide.c43
1 files changed, 15 insertions, 28 deletions
diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 782780f..2f45bb6 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -555,10 +555,8 @@ static void ide_ident(struct blk_desc *dev_desc)
{
unsigned char c;
hd_driveid_t iop;
-#ifdef CONFIG_ATAPI
bool is_atapi = false;
int tries = 1;
-#endif
int device;
device = dev_desc->devnum;
@@ -568,17 +566,16 @@ static void ide_ident(struct blk_desc *dev_desc)
*/
ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
dev_desc->uclass_id = UCLASS_IDE;
-#ifdef CONFIG_ATAPI
+ if (IS_ENABLED(CONFIG_ATAPI))
+ tries = 2;
- tries = 2;
-
- /* Warning: This will be tricky to read */
while (tries) {
/* check signature */
- if ((ide_inb(device, ATA_SECT_CNT) == 0x01) &&
- (ide_inb(device, ATA_SECT_NUM) == 0x01) &&
- (ide_inb(device, ATA_CYL_LOW) == 0x14) &&
- (ide_inb(device, ATA_CYL_HIGH) == 0xEB)) {
+ if (IS_ENABLED(CONFIG_ATAPI) &&
+ ide_inb(device, ATA_SECT_CNT) == 0x01 &&
+ ide_inb(device, ATA_SECT_NUM) == 0x01 &&
+ ide_inb(device, ATA_CYL_LOW) == 0x14 &&
+ ide_inb(device, ATA_CYL_HIGH) == 0xeb) {
/* ATAPI Signature found */
is_atapi = true;
/*
@@ -590,9 +587,7 @@ static void ide_ident(struct blk_desc *dev_desc)
* to become ready
*/
c = ide_wait(device, ATAPI_TIME_OUT);
- } else
-#endif
- {
+ } else {
/*
* Start Ident Command
*/
@@ -606,8 +601,7 @@ static void ide_ident(struct blk_desc *dev_desc)
if (((c & ATA_STAT_DRQ) == 0) ||
((c & (ATA_STAT_FAULT | ATA_STAT_ERR)) != 0)) {
-#ifdef CONFIG_ATAPI
- {
+ if (IS_ENABLED(CONFIG_ATAPI)) {
/*
* Need to soft reset the device
* in case it's an ATAPI...
@@ -618,25 +612,18 @@ static void ide_ident(struct blk_desc *dev_desc)
mdelay(100);
ide_outb(device, ATA_COMMAND, 0x08);
mdelay(500);
+ /* Select device */
+ ide_outb(device, ATA_DEV_HD,
+ ATA_LBA | ATA_DEVICE(device));
}
- /*
- * Select device
- */
- ide_outb(device, ATA_DEV_HD,
- ATA_LBA | ATA_DEVICE(device));
tries--;
-#else
- return;
-#endif
- }
-#ifdef CONFIG_ATAPI
- else
+ } else {
break;
- } /* see above - ugly to read */
+ }
+ }
if (!tries) /* Not found */
return;
-#endif
ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);