Line 169... |
Line 169... |
unsigned int tmp;
|
unsigned int tmp;
|
|
|
/* print debug information */
|
/* print debug information */
|
ata_device_debug(2, "ata_device executing command 'identify device'\n");
|
ata_device_debug(2, "ata_device executing command 'identify device'\n");
|
|
|
/* reset databuffer-counter */
|
/* reset databuffer */
|
device->settings.dbuf_cnt = 0;
|
device->internals.dbuf_cnt = 256;
|
|
device->internals.dbuf_ptr = device->internals.dbuf;
|
|
|
buf = device->settings.dbuf;
|
buf = device->internals.dbuf;
|
chksum_buf = (char *)buf;
|
chksum_buf = (char *)buf;
|
|
|
/*
|
/*
|
if number_of_available_sectors (==device->size / BYTES_PER_SECTOR) < 16,514,064 then
|
if number_of_available_sectors (==device->size / BYTES_PER_SECTOR) < 16,514,064 then
|
support CHS translation where:
|
support CHS translation where:
|
Line 433... |
Line 434... |
word 54: number of current logical cylinders (0-65535)
|
word 54: number of current logical cylinders (0-65535)
|
*/
|
*/
|
if ( (tmp = device->size / BYTES_PER_SECTOR) > 16514064 )
|
if ( (tmp = device->size / BYTES_PER_SECTOR) > 16514064 )
|
tmp = 16514064;
|
tmp = 16514064;
|
|
|
tmp /= (device->settings.heads_per_cylinder +1) * (device->settings.sectors_per_track);
|
tmp /= (device->internals.heads_per_cylinder +1) * (device->internals.sectors_per_track);
|
if (tmp > 65535)
|
if (tmp > 65535)
|
*buf++ = 65535;
|
*buf++ = 65535;
|
else
|
else
|
*buf++ = tmp;
|
*buf++ = tmp;
|
|
|
/*
|
/*
|
word 55: number of current logical heads, (0-15)
|
word 55: number of current logical heads, (0-15)
|
*/
|
*/
|
*buf++ = device->settings.heads_per_cylinder +1;
|
*buf++ = device->internals.heads_per_cylinder +1;
|
|
|
/*
|
/*
|
word 56: number of current logical sectors per track (1-255)
|
word 56: number of current logical sectors per track (1-255)
|
*/
|
*/
|
*buf++ = device->settings.sectors_per_track;
|
*buf++ = device->internals.sectors_per_track;
|
|
|
/*
|
/*
|
word 58-57: current capacity in sectors
|
word 58-57: current capacity in sectors
|
*/
|
*/
|
tmp = *(buf-3) * *(buf-2) * *(buf-1);
|
tmp = *(buf-3) * *(buf-2) * *(buf-1);
|
Line 568... |
Line 569... |
*buf++ = 0x0013;
|
*buf++ = 0x0013;
|
|
|
/*
|
/*
|
word 82: Command set supported
|
word 82: Command set supported
|
*/
|
*/
|
*buf++ = 0 << 15 | \ /* obsolete */
|
*buf++ = 0 << 15 | /* obsolete */
|
SUPPORT_NOP_CMD << 14 | \
|
SUPPORT_NOP_CMD << 14 |
|
SUPPORT_READ_BUFFER_CMD << 13 | \
|
SUPPORT_READ_BUFFER_CMD << 13 |
|
SUPPORT_WRITE_BUFFER_CMD << 12 | \
|
SUPPORT_WRITE_BUFFER_CMD << 12 |
|
0 << 11 | \ /* obsolete */
|
0 << 11 | /* obsolete */
|
SUPPORT_HOST_PROTECTED_AREA << 10 | \
|
SUPPORT_HOST_PROTECTED_AREA << 10 |
|
SUPPORT_DEVICE_RESET_CMD << 9 | \
|
SUPPORT_DEVICE_RESET_CMD << 9 |
|
SUPPORT_SERVICE_INTERRUPT << 8 | \
|
SUPPORT_SERVICE_INTERRUPT << 8 |
|
SUPPORT_RELEASE_INTERRUPT << 7 | \
|
SUPPORT_RELEASE_INTERRUPT << 7 |
|
SUPPORT_LOOKAHEAD << 6 | \
|
SUPPORT_LOOKAHEAD << 6 |
|
SUPPORT_WRITE_CACHE << 5 | \
|
SUPPORT_WRITE_CACHE << 5 |
|
0 << 4 | \ /* cleared to zero */
|
0 << 4 | /* cleared to zero */
|
SUPPORT_POWER_MANAGEMENT << 3 | \
|
SUPPORT_POWER_MANAGEMENT << 3 |
|
SUPPORT_REMOVABLE_MEDIA << 2 | \
|
SUPPORT_REMOVABLE_MEDIA << 2 |
|
SUPPORT_SECURITY_MODE << 1 | \
|
SUPPORT_SECURITY_MODE << 1 |
|
SUPPORT_SMART << 0
|
SUPPORT_SMART << 0
|
;
|
;
|
|
|
/*
|
/*
|
word 83: Command set supported
|
word 83: Command set supported
|
*/
|
*/
|
*buf++ = 0 << 15 | \ /* cleared to zero */
|
*buf++ = 0 << 15 | /* cleared to zero */
|
1 << 14 | \ /* set to one */
|
1 << 14 | /* set to one */
|
0 << 9 | \ /* reserved */
|
0 << 9 | /* reserved */
|
SUPPORT_SET_MAX << 8 | \
|
SUPPORT_SET_MAX << 8 |
|
0 << 7 | \ /* reserved for */
|
0 << 7 | /* reserved for */
|
/* project 1407DT */
|
/* project 1407DT */
|
SET_FEATURES_REQUIRED_AFTER_POWER_UP << 6 | \
|
SET_FEATURES_REQUIRED_AFTER_POWER_UP << 6 |
|
SUPPORT_POWER_UP_IN_STANDBY_MODE << 5 | \
|
SUPPORT_POWER_UP_IN_STANDBY_MODE << 5 |
|
SUPPORT_REMOVABLE_MEDIA_NOTIFICATION << 4 | \
|
SUPPORT_REMOVABLE_MEDIA_NOTIFICATION << 4 |
|
SUPPORT_APM << 3 | \
|
SUPPORT_APM << 3 |
|
SUPPORT_CFA << 2 | \
|
SUPPORT_CFA << 2 |
|
SUPPORT_READ_WRITE_DMA_QUEUED << 1 | \
|
SUPPORT_READ_WRITE_DMA_QUEUED << 1 |
|
SUPPORT_DOWNLOAD_MICROCODE << 0
|
SUPPORT_DOWNLOAD_MICROCODE << 0
|
;
|
;
|
|
|
/*
|
/*
|
word 84: Command set/feature supported
|
word 84: Command set/feature supported
|
*/
|
*/
|
*buf++ = 0 << 15 | \ /* cleared to zero */
|
*buf++ = 0 << 15 | /* cleared to zero */
|
1 << 14 /* set to one */
|
1 << 14 /* set to one */
|
; /* 0-13 reserved */
|
; /* 0-13 reserved */
|
|
|
/*
|
/*
|
word 85: Command set enabled FIXME
|
word 85: Command set enabled FIXME
|
*/
|
*/
|
*buf++ = 0 << 15 | \ /* obsolete */
|
*buf++ = 0 << 15 | /* obsolete */
|
SUPPORT_NOP_CMD << 14 | \
|
SUPPORT_NOP_CMD << 14 |
|
SUPPORT_READ_BUFFER_CMD << 13 | \
|
SUPPORT_READ_BUFFER_CMD << 13 |
|
SUPPORT_WRITE_BUFFER_CMD << 12 | \
|
SUPPORT_WRITE_BUFFER_CMD << 12 |
|
0 << 11 | \ /* obsolete */
|
0 << 11 | /* obsolete */
|
SUPPORT_HOST_PROTECTED_AREA << 10 | \
|
SUPPORT_HOST_PROTECTED_AREA << 10 |
|
SUPPORT_DEVICE_RESET_CMD << 9 | \
|
SUPPORT_DEVICE_RESET_CMD << 9 |
|
SUPPORT_SERVICE_INTERRUPT << 8 | \
|
SUPPORT_SERVICE_INTERRUPT << 8 |
|
SUPPORT_RELEASE_INTERRUPT << 7 | \
|
SUPPORT_RELEASE_INTERRUPT << 7 |
|
SUPPORT_LOOKAHEAD << 6 | \
|
SUPPORT_LOOKAHEAD << 6 |
|
SUPPORT_WRITE_CACHE << 5 | \
|
SUPPORT_WRITE_CACHE << 5 |
|
0 << 4 | \ /* cleared to zero */
|
0 << 4 | /* cleared to zero */
|
SUPPORT_POWER_MANAGEMENT << 3 | \
|
SUPPORT_POWER_MANAGEMENT << 3 |
|
SUPPORT_REMOVABLE_MEDIA << 2 | \
|
SUPPORT_REMOVABLE_MEDIA << 2 |
|
SUPPORT_SECURITY_MODE << 1 | \
|
SUPPORT_SECURITY_MODE << 1 |
|
SUPPORT_SMART << 0
|
SUPPORT_SMART << 0
|
;
|
;
|
|
|
/*
|
/*
|
word 86: Command set enables
|
word 86: Command set enables
|
*/
|
*/
|
*buf++ = 0 << 9 | \ /* 15-9 reserved */
|
*buf++ = 0 << 9 | /* 15-9 reserved */
|
SUPPORT_SET_MAX << 8 | \
|
SUPPORT_SET_MAX << 8 |
|
0 << 7 | \ /* reserved for */
|
0 << 7 | /* reserved for */
|
/* project 1407DT */
|
/* project 1407DT */
|
SET_FEATURES_REQUIRED_AFTER_POWER_UP << 6 | \
|
SET_FEATURES_REQUIRED_AFTER_POWER_UP << 6 |
|
SUPPORT_POWER_UP_IN_STANDBY_MODE << 5 | \
|
SUPPORT_POWER_UP_IN_STANDBY_MODE << 5 |
|
SUPPORT_REMOVABLE_MEDIA_NOTIFICATION << 4 | \
|
SUPPORT_REMOVABLE_MEDIA_NOTIFICATION << 4 |
|
SUPPORT_APM << 3 | \
|
SUPPORT_APM << 3 |
|
SUPPORT_CFA << 2 | \
|
SUPPORT_CFA << 2 |
|
SUPPORT_READ_WRITE_DMA_QUEUED << 1 | \
|
SUPPORT_READ_WRITE_DMA_QUEUED << 1 |
|
SUPPORT_DOWNLOAD_MICROCODE << 0
|
SUPPORT_DOWNLOAD_MICROCODE << 0
|
;
|
;
|
|
|
/*
|
/*
|
word 87: Command set/feature supported
|
word 87: Command set/feature supported
|
*/
|
*/
|
*buf++ = 0 << 15 | \ /* cleared to zero */
|
*buf++ = 0 << 15 | /* cleared to zero */
|
1 << 14 /* set to one */
|
1 << 14 /* set to one */
|
; /* 0-13 reserved */
|
; /* 0-13 reserved */
|
|
|
/*
|
/*
|
word 88: UltraDMA section
|
word 88: UltraDMA section
|
Line 710... |
Line 711... |
*buf++ = 0x0000;
|
*buf++ = 0x0000;
|
|
|
/*
|
/*
|
word 93: Hardware reset result
|
word 93: Hardware reset result
|
*/
|
*/
|
if (device->settings.dev)
|
if (device->internals.dev)
|
{
|
{
|
/* this is device1, clear device0 bits */
|
/* this is device1, clear device0 bits */
|
*buf++ = 0 << 15 | \
|
*buf++ = 0 << 15 |
|
1 << 14 | \
|
1 << 14 |
|
0 << 13 | \ /* CBLIBD level (1=Vih, 0=Vil) */
|
0 << 13 | /* CBLIBD level (1=Vih, 0=Vil) */
|
/* 12-8 Device 1 hardware reset result */
|
/* 12-8 Device 1 hardware reset result */
|
0 << 12 | \ /* reserved */
|
0 << 12 | /* reserved */
|
device->sigs.pdiago << 11 | \ /* 1: Device1 did assert PDIAG */
|
device->sigs.pdiago << 11 | /* 1: Device1 did assert PDIAG */
|
/* 0: Device1 did not assert PDIAG */
|
/* 0: Device1 did not assert PDIAG */
|
3 << 9 | \ /* Device1 determined device number by */
|
3 << 9 | /* Device1 determined device number by */
|
/* 00: reserved */
|
/* 00: reserved */
|
/* 01: a jumper was used */
|
/* 01: a jumper was used */
|
/* 10: the CSEL signal was used */
|
/* 10: the CSEL signal was used */
|
/* 11: some other or unknown method was used */
|
/* 11: some other or unknown method was used */
|
1 << 8 /* set to one */
|
1 << 8 /* set to one */
|
;
|
;
|
}
|
}
|
else
|
else
|
{ /* FIXME bit 6 */
|
{ /* FIXME bit 6 */
|
/* this is device0, clear device1 bits */
|
/* this is device0, clear device1 bits */
|
*buf++ = 0 << 7 | \ /* reserved */
|
*buf++ = 0 << 7 | /* reserved */
|
0 << 6 | \ /* 1: Device0 responds for device 1 */
|
0 << 6 | /* 1: Device0 responds for device 1 */
|
/* 0: Device0 does not respond for device1 */
|
/* 0: Device0 does not respond for device1 */
|
device->sigs.daspi << 5 | \ /* 1: Device0 did detected DASP assertion */
|
device->sigs.daspi << 5 | /* 1: Device0 did detected DASP assertion */
|
/* 0: Device0 did not detect DASP assertion */
|
/* 0: Device0 did not detect DASP assertion */
|
device->sigs.pdiagi << 4 | \ /* Device0 did detect PDIAG assertion */
|
device->sigs.pdiagi << 4 | /* Device0 did detect PDIAG assertion */
|
/* Device0 did not detect PDIAG assertion */
|
/* Device0 did not detect PDIAG assertion */
|
1 << 3 | \ /* Device0 did pass diagnostics */
|
1 << 3 | /* Device0 did pass diagnostics */
|
3 << 1 | \ /* Device0 determined device number by */
|
3 << 1 | /* Device0 determined device number by */
|
/* 00: reserved */
|
/* 00: reserved */
|
/* 01: a jumper was used */
|
/* 01: a jumper was used */
|
/* 10: the CSEL signal was used */
|
/* 10: the CSEL signal was used */
|
/* 11: some other or unknown method was used */
|
/* 11: some other or unknown method was used */
|
1 << 0 /* set to one */
|
1 << 0 /* set to one */
|
Line 820... |
Line 821... |
chksum += *chksum_buf++;
|
chksum += *chksum_buf++;
|
|
|
*buf = ( (0-chksum) << 8) | 0x00a5;
|
*buf = ( (0-chksum) << 8) | 0x00a5;
|
|
|
/* set status register bits */
|
/* set status register bits */
|
device->regs.status = ATA_SR_DRDY;
|
device->regs.status = ATA_SR_DRDY | ATA_SR_DRQ;
|
}
|
}
|
}
|
}
|
|
|
|
|
/*
|
/*
|
Line 833... |
Line 834... |
void ata_initialize_device_parameters_cmd(ata_device *device)
|
void ata_initialize_device_parameters_cmd(ata_device *device)
|
{
|
{
|
/* print debug information */
|
/* print debug information */
|
ata_device_debug(2, "executing command 'initialize device parameters'\n");
|
ata_device_debug(2, "executing command 'initialize device parameters'\n");
|
|
|
device->settings.sectors_per_track = device->regs.sector_count;
|
device->internals.sectors_per_track = device->regs.sector_count;
|
device->settings.heads_per_cylinder = device->regs.device_head & ATA_DHR_H;
|
device->internals.heads_per_cylinder = device->regs.device_head & ATA_DHR_H;
|
|
|
/* set status register bits */
|
/* set status register bits */
|
device->regs.status = 0;
|
device->regs.status = 0;
|
}
|
}
|
|
|
Line 852... |
Line 853... |
unsigned long lba;
|
unsigned long lba;
|
|
|
/* print debug information */
|
/* print debug information */
|
ata_device_debug(2, "executing command 'read sectors'\n");
|
ata_device_debug(2, "executing command 'read sectors'\n");
|
|
|
/* reset the buffer-counter */
|
|
device->settings.dbuf_cnt = 0;
|
|
|
|
/* check if this is a NON-PACKET device */
|
/* check if this is a NON-PACKET device */
|
if (device->packet)
|
if (device->packet)
|
{
|
{
|
/*
|
/*
|
This is a PACKET device.
|
This is a PACKET device.
|
Line 880... |
Line 878... |
sector_count = device->regs.sector_count;
|
sector_count = device->regs.sector_count;
|
|
|
/* check if we are using CHS or LBA translation, fill in the bits */
|
/* check if we are using CHS or LBA translation, fill in the bits */
|
if (device->regs.device_head & ATA_DHR_LBA)
|
if (device->regs.device_head & ATA_DHR_LBA)
|
{ /* we are using LBA translation */
|
{ /* we are using LBA translation */
|
lba = (device->regs.device_head & ATA_DHR_H) << 24 | \
|
lba = (device->regs.device_head & ATA_DHR_H) << 24 |
|
(device->regs.cylinder_high ) << 16 | \
|
(device->regs.cylinder_high ) << 16 |
|
(device->regs.cylinder_low ) << 8 |
|
(device->regs.cylinder_low ) << 8 |
|
device->regs.sector_number
|
device->regs.sector_number
|
;
|
;
|
}
|
}
|
else
|
else
|
{ /* we are using CHS translation, calculate lba address */
|
{ /* we are using CHS translation, calculate lba address */
|
lba = (device->regs.cylinder_high << 16) | device->regs.cylinder_low;
|
lba = (device->regs.cylinder_high << 16) | device->regs.cylinder_low;
|
lba *= device->settings.heads_per_cylinder;
|
lba *= device->internals.heads_per_cylinder;
|
lba += device->regs.device_head & ATA_DHR_H;
|
lba += device->regs.device_head & ATA_DHR_H;
|
lba *= device->settings.sectors_per_track;
|
lba *= device->internals.sectors_per_track;
|
lba += device->regs.sector_number;
|
lba += device->regs.sector_number;
|
lba -= 1;
|
lba -= 1;
|
}
|
}
|
|
|
/* check if sector within bounds */
|
/* check if sector within bounds */
|
Line 911... |
Line 909... |
|
|
/* set the file-positon pointer to the start of the sector */
|
/* set the file-positon pointer to the start of the sector */
|
fseek(device->stream, lba, SEEK_SET);
|
fseek(device->stream, lba, SEEK_SET);
|
|
|
/* get the bytes from the stream */
|
/* get the bytes from the stream */
|
fread(device->settings.dbuf, BYTES_PER_SECTOR, sector_count, device->stream);
|
fread(device->internals.dbuf, BYTES_PER_SECTOR, sector_count, device->stream);
|
|
|
/* set status register bits */
|
/* set status register bits */
|
device->regs.status = ATA_SR_DRDY;
|
device->regs.status = ATA_SR_DRDY | ATA_SR_DRQ;
|
|
|
|
/* reset the databuffer */
|
|
device->internals.dbuf_cnt = sector_count * BYTES_PER_SECTOR /2; //Words, not bytes
|
|
device->internals.dbuf_ptr = device->internals.dbuf;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
|
|