📄 cmd_ide.c
字号:
ide_led (DEVICE_LED(device), 1); /* LED on */ /* Select device */ ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); dev_desc->if_type=IF_TYPE_IDE;#ifdef CONFIG_ATAPI do_retry = 0; retries = 0; /* Warning: This will be tricky to read */ while (retries <= 1) { /* 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)) { /* ATAPI Signature found */ dev_desc->if_type=IF_TYPE_ATAPI; /* Start Ident Command */ ide_outb (device, ATA_COMMAND, ATAPI_CMD_IDENT); /* * Wait for completion - ATAPI devices need more time * to become ready */ c = ide_wait (device, ATAPI_TIME_OUT); } else#endif { /* Start Ident Command */ ide_outb (device, ATA_COMMAND, ATA_CMD_IDENT); /* Wait for completion */ c = ide_wait (device, IDE_TIME_OUT); } ide_led (DEVICE_LED(device), 0); /* LED off */ if (((c & ATA_STAT_DRQ) == 0) || ((c & (ATA_STAT_FAULT|ATA_STAT_ERR)) != 0) ) {#ifdef CONFIG_ATAPI#ifdef CONFIG_AMIGAONEG3SE s = getenv("ide_doreset"); if (s && strcmp(s, "on") == 0)#endif { /* Need to soft reset the device in case it's an ATAPI... */ PRINTF("Retrying...\n"); ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); udelay(100000); ide_outb (device, ATA_COMMAND, 0x08); udelay (500000); /* 500 ms */ } /* Select device */ ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); retries++;#else return;#endif }#ifdef CONFIG_ATAPI else break; } /* see above - ugly to read */ if (retries == 2) /* Not found */ return;#endif input_swap_data (device, iobuf, ATA_SECTORWORDS); ident_cpy (dev_desc->revision, iop->fw_rev, sizeof(dev_desc->revision)); ident_cpy (dev_desc->vendor, iop->model, sizeof(dev_desc->vendor)); ident_cpy (dev_desc->product, iop->serial_no, sizeof(dev_desc->product));#ifdef __LITTLE_ENDIAN /* * firmware revision and model number have Big Endian Byte * order in Word. Convert both to little endian. * * See CF+ and CompactFlash Specification Revision 2.0: * 6.2.1.6: Identfy Drive, Table 39 for more details */ strswab (dev_desc->revision); strswab (dev_desc->vendor);#endif /* __LITTLE_ENDIAN */ if ((iop->config & 0x0080)==0x0080) dev_desc->removable = 1; else dev_desc->removable = 0;#if 0 /* * Drive PIO mode autoselection */ mode = iop->tPIO; printf ("tPIO = 0x%02x = %d\n",mode, mode); if (mode > 2) { /* 2 is maximum allowed tPIO value */ mode = 2; PRINTF ("Override tPIO -> 2\n"); } if (iop->field_valid & 2) { /* drive implements ATA2? */ PRINTF ("Drive implements ATA2\n"); if (iop->capability & 8) { /* drive supports use_iordy? */ cycle_time = iop->eide_pio_iordy; } else { cycle_time = iop->eide_pio; } PRINTF ("cycle time = %d\n", cycle_time); mode = 4; if (cycle_time > 120) mode = 3; /* 120 ns for PIO mode 4 */ if (cycle_time > 180) mode = 2; /* 180 ns for PIO mode 3 */ if (cycle_time > 240) mode = 1; /* 240 ns for PIO mode 4 */ if (cycle_time > 383) mode = 0; /* 383 ns for PIO mode 4 */ } printf ("PIO mode to use: PIO %d\n", mode);#endif /* 0 */#ifdef CONFIG_ATAPI if (dev_desc->if_type==IF_TYPE_ATAPI) { atapi_inquiry(dev_desc); return; }#endif /* CONFIG_ATAPI */#ifdef __BIG_ENDIAN /* swap shorts */ dev_desc->lba = (iop->lba_capacity << 16) | (iop->lba_capacity >> 16);#else /* ! __BIG_ENDIAN */ /* * do not swap shorts on little endian * * See CF+ and CompactFlash Specification Revision 2.0: * 6.2.1.6: Identfy Drive, Table 39, Word Address 57-58 for details. */ dev_desc->lba = iop->lba_capacity;#endif /* __BIG_ENDIAN */#ifdef CONFIG_LBA48 if (iop->command_set_2 & 0x0400) { /* LBA 48 support */ dev_desc->lba48 = 1; dev_desc->lba = (unsigned long long)iop->lba48_capacity[0] | ((unsigned long long)iop->lba48_capacity[1] << 16) | ((unsigned long long)iop->lba48_capacity[2] << 32) | ((unsigned long long)iop->lba48_capacity[3] << 48); } else { dev_desc->lba48 = 0; }#endif /* CONFIG_LBA48 */ /* assuming HD */ dev_desc->type=DEV_TYPE_HARDDISK; dev_desc->blksz=ATA_BLOCKSIZE; dev_desc->lun=0; /* just to fill something in... */#if 0 /* only used to test the powersaving mode, * if enabled, the drive goes after 5 sec * in standby mode */ ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); c = ide_wait (device, IDE_TIME_OUT); ide_outb (device, ATA_SECT_CNT, 1); ide_outb (device, ATA_LBA_LOW, 0); ide_outb (device, ATA_LBA_MID, 0); ide_outb (device, ATA_LBA_HIGH, 0); ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); ide_outb (device, ATA_COMMAND, 0xe3); udelay (50); c = ide_wait (device, IDE_TIME_OUT); /* can't take over 500 ms */#endif}/* ------------------------------------------------------------------------- */ulong ide_read (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer){ ulong n = 0; unsigned char c; unsigned char pwrsave=0; /* power save */#ifdef CONFIG_LBA48 unsigned char lba48 = 0; if (blknr & 0x0000fffff0000000) { /* more than 28 bits used, use 48bit mode */ lba48 = 1; }#endif PRINTF ("ide_read dev %d start %qX, blocks %lX buffer at %lX\n", device, blknr, blkcnt, (ulong)buffer); ide_led (DEVICE_LED(device), 1); /* LED on */ /* Select device */ ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); c = ide_wait (device, IDE_TIME_OUT); if (c & ATA_STAT_BUSY) { printf ("IDE read: device %d not ready\n", device); goto IDE_READ_E; } /* first check if the drive is in Powersaving mode, if yes, * increase the timeout value */ ide_outb (device, ATA_COMMAND, ATA_CMD_CHK_PWR); udelay (50); c = ide_wait (device, IDE_TIME_OUT); /* can't take over 500 ms */ if (c & ATA_STAT_BUSY) { printf ("IDE read: device %d not ready\n", device); goto IDE_READ_E; } if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) { printf ("No Powersaving mode %X\n", c); } else { c = ide_inb(device,ATA_SECT_CNT); PRINTF("Powersaving %02X\n",c); if(c==0) pwrsave=1; } while (blkcnt-- > 0) { c = ide_wait (device, IDE_TIME_OUT); if (c & ATA_STAT_BUSY) { printf ("IDE read: device %d not ready\n", device); break; }#ifdef CONFIG_LBA48 if (lba48) { /* write high bits */ ide_outb (device, ATA_SECT_CNT, 0); ide_outb (device, ATA_LBA_LOW, (blknr >> 24) & 0xFF); ide_outb (device, ATA_LBA_MID, (blknr >> 32) & 0xFF); ide_outb (device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF); }#endif ide_outb (device, ATA_SECT_CNT, 1); ide_outb (device, ATA_LBA_LOW, (blknr >> 0) & 0xFF); ide_outb (device, ATA_LBA_MID, (blknr >> 8) & 0xFF); ide_outb (device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF);#ifdef CONFIG_LBA48 if (lba48) { ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device) ); ide_outb (device, ATA_COMMAND, ATA_CMD_READ_EXT); } else#endif { ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device) | ((blknr >> 24) & 0xF) ); ide_outb (device, ATA_COMMAND, ATA_CMD_READ); } udelay (50); if(pwrsave) { c = ide_wait (device, IDE_SPIN_UP_TIME_OUT); /* may take up to 4 sec */ pwrsave=0; } else { c = ide_wait (device, IDE_TIME_OUT); /* can't take over 500 ms */ } if ((c&(ATA_STAT_DRQ|ATA_STAT_BUSY|ATA_STAT_ERR)) != ATA_STAT_DRQ) {#if defined(CFG_64BIT_LBA) && defined(CFG_64BIT_VSPRINTF) printf ("Error (no IRQ) dev %d blk %qd: status 0x%02x\n", device, blknr, c);#else printf ("Error (no IRQ) dev %d blk %ld: status 0x%02x\n", device, (ulong)blknr, c);#endif break; } input_data (device, buffer, ATA_SECTORWORDS); (void) ide_inb (device, ATA_STATUS); /* clear IRQ */ ++n; ++blknr; buffer += ATA_SECTORWORDS; }IDE_READ_E: ide_led (DEVICE_LED(device), 0); /* LED off */ return (n);}/* ------------------------------------------------------------------------- */ulong ide_write (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer){ ulong n = 0; unsigned char c;#ifdef CONFIG_LBA48 unsigned char lba48 = 0; if (blknr & 0x0000fffff0000000) { /* more than 28 bits used, use 48bit mode */ lba48 = 1; }#endif ide_led (DEVICE_LED(device), 1); /* LED on */ /* Select device */ ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); while (blkcnt-- > 0) { c = ide_wait (device, IDE_TIME_OUT); if (c & ATA_STAT_BUSY) { printf ("IDE read: device %d not ready\n", device); goto WR_OUT; }#ifdef CONFIG_LBA48 if (lba48) { /* write high bits */ ide_outb (device, ATA_SECT_CNT, 0); ide_outb (device, ATA_LBA_LOW, (blknr >> 24) & 0xFF); ide_outb (device, ATA_LBA_MID, (blknr >> 32) & 0xFF); ide_outb (device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF); }#endif ide_outb (device, ATA_SECT_CNT, 1); ide_outb (device, ATA_LBA_LOW, (blknr >> 0) & 0xFF); ide_outb (device, ATA_LBA_MID, (blknr >> 8) & 0xFF); ide_outb (device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF);#ifdef CONFIG_LBA48 if (lba48) { ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device) ); ide_outb (device, ATA_COMMAND, ATA_CMD_WRITE_EXT); } else#endif { ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device) | ((blknr >> 24) & 0xF) ); ide_outb (device, ATA_COMMAND, ATA_CMD_WRITE); } udelay (50); c = ide_wait (device, IDE_TIME_OUT); /* can't take over 500 ms */ if ((c&(ATA_STAT_DRQ|ATA_STAT_BUSY|ATA_STAT_ERR)) != ATA_STAT_DRQ) {#if defined(CFG_64BIT_LBA) && defined(CFG_64BIT_VSPRINTF) printf ("Error (no IRQ) dev %d blk %qd: status 0x%02x\n", device, blknr, c);#else printf ("Error (no IRQ) dev %d blk %ld: status 0x%02x\n", device, (ulong)blknr, c);#endif goto WR_OUT; } output_data (device, buffer, ATA_SECTORWORDS); c = ide_inb (device, ATA_STATUS); /* clear IRQ */ ++n; ++blknr; buffer += ATA_SECTORWORDS; }WR_OUT: ide_led (DEVICE_LED(device), 0); /* LED off */ return (n);}/* ------------------------------------------------------------------------- *//* * copy src to dest, skipping leading and trailing blanks and null * terminate the string * "len" is the size of available memory including the terminating '\0' */static void ident_cpy (unsigned char *dst, unsigned char *src, unsigned int len){ unsigned char *end, *last; last = dst; end = src + len - 1; /* reserve space for '\0' */ if (len < 2) goto OUT; /* skip leading white space */ while ((*src) && (src<end) && (*src==' ')) ++src; /* copy string, omitting trailing white space */ while ((*src) && (src<end)) { *dst++ = *src; if (*src++ != ' ') last = dst; }OUT: *last = '\0';}/* ------------------------------------------------------------------------- *//* * Wait until Busy bit is off, or timeout (in ms) * Return last status */static uchar ide_wait (int dev, ulong t){ ulong delay = 10 * t; /* poll every 100 us */ uchar c; while ((c = ide_inb(dev, ATA_STATUS)) & ATA_STAT_BUSY) { udelay (100); if (delay-- == 0) { break; } } return (c);}/* ------------------------------------------------------------------------- */#ifdef CONFIG_IDE_RESETextern void ide_set_reset(int idereset);static void ide_reset (void){#if defined(CFG_PB_12V_ENABLE) || defined(CFG_PB_IDE_MOTOR) volatile immap_t *immr = (immap_t *)CFG_IMMR;#endif int i; curr_device = -1; for (i=0; i<CFG_IDE_MAXBUS; ++i) ide_bus_ok[i] = 0; for (i=0; i<CFG_IDE_MAXDEVICE; ++i) ide_dev_desc[i].type = DEV_TYPE_UNKNOWN; ide_set_reset (1); /* assert reset */ WATCHDOG_RESET();#ifdef CFG_PB_12V_ENABLE immr->im_cpm.cp_pbdat &= ~(CFG_PB_12V_ENABLE); /* 12V Enable output OFF */ immr->im_cpm.cp_pbpar &= ~(CFG_PB_12V_ENABLE); immr->im_cpm.cp_pbodr &= ~(CFG_PB_12V_ENABLE); immr->im_cpm.cp_pbdir |= CFG_PB_12V_ENABLE; /* wait 500 ms for the voltage to stabilize */ for (i=0; i<500; ++i) { udelay (1000); } immr->im_cpm.cp_pbdat |= CFG_PB_12V_ENABLE; /* 12V Enable output ON */#endif /* CFG_PB_12V_ENABLE */#ifdef CFG_PB_IDE_MOTOR /* configure IDE Motor voltage monitor pin as input */ immr->im_cpm.cp_pbpar &= ~(CFG_PB_IDE_MOTOR); immr->im_cpm.cp_pbodr &= ~(CFG_PB_IDE_MOTOR); immr->im_cpm.cp_pbdir &= ~(CFG_PB_IDE_MOTOR); /* wait up to 1 s for the motor voltage to stabilize */ for (i=0; i<1000; ++i) { if ((immr->im_cpm.cp_pbdat & CFG_PB_IDE_MOTOR) != 0) { break; } udelay (1000); } if (i == 1000) { /* Timeout */ printf ("\nWarning: 5V for IDE Motor missing\n");# ifdef CONFIG_STATUS_LED# ifdef STATUS_LED_YELLOW status_led_set (STATUS_LED_YELLOW, STATUS_LED_ON );# endif# ifdef STATUS_LED_GREEN status_led_set (STATUS_LED_GREEN, STATUS_LED_OFF);# endif# endif /* CONFIG_STATUS_LED */ }#endif /* CFG_PB_IDE_MOTOR */ WATCHDOG_RESET(); /* de-assert RESET signal */ ide_set_reset(0); /* wait 250 ms */ for (i=0; i<250; ++i) { udelay (1000); }}#endif /* CONFIG_IDE_RESET *//* ------------------------------------------------------------------------- */#if defined(CONFIG_IDE_LED) && \ !defined(CONFIG_AMIGAONEG3SE)&& \ !defined(CONFIG_CPC45) && \ !defined(CONFIG_HMI10) && \ !defined(CONFIG_KUP4K) && \ !defined(CONFIG_KUP4X)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -