Line 32... |
Line 32... |
#include <string.h>
|
#include <string.h>
|
#include <stdarg.h>
|
#include <stdarg.h>
|
|
|
/*
|
/*
|
mandatory commands:
|
mandatory commands:
|
- execute device diagnostics
|
- execute device diagnostics (done)
|
- flush cache
|
- flush cache
|
- identify device
|
- identify device (done)
|
- initialize device parameters
|
- initialize device parameters (done)
|
- read dma
|
- read dma
|
- read multiple
|
- read multiple
|
- read sector(s)
|
- read sector(s) (done)
|
- read verify sector(s)
|
- read verify sector(s)
|
- seek
|
- seek
|
- set features
|
- set features
|
- set multiple mode
|
- set multiple mode
|
- write dma
|
- write dma
|
Line 164... |
Line 164... |
*/
|
*/
|
/* power-on and hardware reset */
|
/* power-on and hardware reset */
|
void ata_devices_hw_reset(ata_devices *devices, int reset_signal)
|
void ata_devices_hw_reset(ata_devices *devices, int reset_signal)
|
{
|
{
|
/* display debug information */
|
/* display debug information */
|
ata_device_debug(2, "ata_device_hw_reset.\n");
|
ata_device_debug(2, "ata_devices_hw_reset.\n");
|
|
|
/* find device 0 */
|
/* find device 0 */
|
if ( (devices->device0.stream) && (devices->device1.stream) )
|
if ( (devices->device0.stream) && (devices->device1.stream) )
|
{
|
{
|
/* this one is simple, device0 is device0 */
|
/* this one is simple, device0 is device0 */
|
Line 350... |
Line 350... |
{
|
{
|
ata_device *device;
|
ata_device *device;
|
|
|
/* check for no connected devices */
|
/* check for no connected devices */
|
if ( (!devices->device0.stream) && (!devices->device1.stream) )
|
if ( (!devices->device0.stream) && (!devices->device1.stream) )
|
MSG_ERROR("ata_device_read, no ata devices connected.");
|
MSG_ERROR("ata_devices_read, no ata devices connected.");
|
else
|
else
|
{
|
{
|
/* check if both device0 and device1 are connected */
|
/* check if both device0 and device1 are connected */
|
if ( (devices->device0.stream) && (devices->device1.stream) )
|
if ( (devices->device0.stream) && (devices->device1.stream) )
|
{
|
{
|
Line 374... |
Line 374... |
}
|
}
|
|
|
/* return data provided by selected device */
|
/* return data provided by selected device */
|
switch (adr) {
|
switch (adr) {
|
case ATA_ASR :
|
case ATA_ASR :
|
ata_device_debug(4, "ata_device alternate_status register read\n");
|
ata_device_debug(4, "alternate_status register read\n");
|
if ( (device->regs.device_head & ATA_DHR_DEV) == device->settings.dev )
|
if ( (device->regs.device_head & ATA_DHR_DEV) == device->settings.dev )
|
return device -> regs.status;
|
return device -> regs.status;
|
else
|
else
|
{
|
{
|
ata_device_debug(2, "device0 responds for device1, asr = 0x00\n");
|
ata_device_debug(2, "device0 responds for device1, asr = 0x00\n");
|
return 0; // return 0 when device0 responds for device1
|
return 0; // return 0 when device0 responds for device1
|
}
|
}
|
|
|
case ATA_CHR :
|
case ATA_CHR :
|
ata_device_debug(4, "ata_device cylinder_high register read, value = 0x%02X\n", \
|
ata_device_debug(4, "cylinder_high register read, value = 0x%02X\n", \
|
device->regs.cylinder_high);
|
device->regs.cylinder_high);
|
return device -> regs.cylinder_high;
|
return device -> regs.cylinder_high;
|
|
|
case ATA_CLR :
|
case ATA_CLR :
|
printf("I am here\n");
|
ata_device_debug(4, "cylinder_low register read, value = 0x%02X\n", \
|
ata_device_debug(4, "ata_device cylinder_low register read, value = 0x%02X\n", \
|
|
device->regs.cylinder_low);
|
device->regs.cylinder_low);
|
return device -> regs.cylinder_low;
|
return device -> regs.cylinder_low;
|
|
|
case ATA_DR :
|
case ATA_DR :
|
ata_device_debug(4, "ata_device device dataport read, value = 0x%04X, cnt = %3d\n", \
|
ata_device_debug(4, "data register read, value = 0x%04X, cnt = %3d\n", \
|
device->settings.dbuf[device->settings.dbuf_cnt], device->settings.dbuf_cnt);
|
device->settings.dbuf[device->settings.dbuf_cnt], device->settings.dbuf_cnt);
|
return device -> settings.dbuf[device->settings.dbuf_cnt++];
|
return device -> settings.dbuf[device->settings.dbuf_cnt++];
|
|
|
case ATA_DHR :
|
case ATA_DHR :
|
ata_device_debug(4, "ata_device device_head register read, value = 0x%02X\n", \
|
ata_device_debug(4, "device_head register read, value = 0x%02X\n", \
|
device->regs.device_head);
|
device->regs.device_head);
|
return device -> regs.device_head;
|
return device -> regs.device_head;
|
|
|
case ATA_ERR :
|
case ATA_ERR :
|
ata_device_debug(4, "ata_device error register read, value = 0x%02X\n", \
|
ata_device_debug(4, "error register read, value = 0x%02X\n", \
|
device->regs.error);
|
device->regs.error);
|
return device -> regs.error;
|
return device -> regs.error;
|
|
|
case ATA_SCR :
|
case ATA_SCR :
|
ata_device_debug(4, "ata_device device sector_count register read, value = 0x%02X\n", \
|
ata_device_debug(4, "sectorcount register read, value = 0x%02X\n", \
|
device->regs.sector_count);
|
device->regs.sector_count);
|
return device -> regs.sector_count;
|
return device -> regs.sector_count;
|
|
|
case ATA_SNR :
|
case ATA_SNR :
|
ata_device_debug(4, "ata_device sector_number register read, value = 0x%02X\n", \
|
ata_device_debug(4, "sectornumber register read, value = 0x%02X\n", \
|
device->regs.sector_number);
|
device->regs.sector_number);
|
return device -> regs.sector_number;
|
return device -> regs.sector_number;
|
|
|
case ATA_SR :
|
case ATA_SR :
|
ata_device_debug(4, "ata_device status register read\n");
|
ata_device_debug(4, "status register read\n");
|
if ( (device->regs.device_head & ATA_DHR_DEV) == device->settings.dev)
|
if ( (device->regs.device_head & ATA_DHR_DEV) == device->settings.dev)
|
return device -> regs.status;
|
return device -> regs.status;
|
else
|
else
|
{
|
{
|
ata_device_debug(2, "device0 responds for device1, sr = 0x00\n");
|
ata_device_debug(2, "device0 responds for device1, sr = 0x00\n");
|
Line 446... |
Line 445... |
{
|
{
|
ata_device *device;
|
ata_device *device;
|
|
|
/* check for no connected devices */
|
/* check for no connected devices */
|
if (!devices->device0.stream && !devices->device1.stream)
|
if (!devices->device0.stream && !devices->device1.stream)
|
MSG_ERROR("ata_device_write, no ata devices connected.");
|
MSG_ERROR("ata_devices_write, no ata devices connected.");
|
else
|
else
|
{
|
{
|
/* first device */
|
/* first device */
|
if (devices->device0.stream)
|
if (devices->device0.stream)
|
ata_device_write(&devices->device0, adr, value);
|
ata_device_write(&devices->device0, adr, value);
|
Line 465... |
Line 464... |
void ata_device_write(ata_device *device, char adr, short value)
|
void ata_device_write(ata_device *device, char adr, short value)
|
{
|
{
|
switch (adr) {
|
switch (adr) {
|
case ATA_CR :
|
case ATA_CR :
|
/*display debug information */
|
/*display debug information */
|
ata_device_debug(4, "ata_device command register written, value = 0x%02X\n", value);
|
ata_device_debug(4, "command register written, value = 0x%02X\n", value);
|
|
|
device->regs.command = value;
|
device->regs.command = value;
|
|
|
/* check command register settings and execute command */
|
/* check command register settings and execute command */
|
ata_device_do_command_register(device);
|
ata_device_do_command_register(device);
|
break;
|
break;
|
|
|
|
|
case ATA_CHR :
|
case ATA_CHR :
|
/*display debug information */
|
/*display debug information */
|
ata_device_debug(4, "ata_device cylinder high register written, value = 0x%02X\n", value);
|
ata_device_debug(4, "cylinder high register written, value = 0x%02X\n", value);
|
|
|
device->regs.cylinder_high = value;
|
device->regs.cylinder_high = value;
|
break;
|
break;
|
|
|
case ATA_CLR :
|
case ATA_CLR :
|
/*display debug information */
|
/*display debug information */
|
ata_device_debug(4, "ata_device cylinder low register written, value = 0x%02X\n", value);
|
ata_device_debug(4, "cylinder low register written, value = 0x%02X\n", value);
|
|
|
device->regs.cylinder_low = value;
|
device->regs.cylinder_low = value;
|
break;
|
break;
|
|
|
case ATA_DR :
|
case ATA_DR :
|
/*display debug information */
|
/*display debug information */
|
ata_device_debug(4, "ata_device data register written, value = 0x%04X\n", value);
|
ata_device_debug(4, "data register written, value = 0x%04X\n", value);
|
|
|
device->regs.dataport_i = value;
|
device->regs.dataport_i = value;
|
break;
|
break;
|
|
|
case ATA_DCR :
|
case ATA_DCR :
|
/*display debug information */
|
/*display debug information */
|
ata_device_debug(4, "ata_device device control register written, value = 0x%02X\n", value);
|
ata_device_debug(4, "device control register written, value = 0x%02X\n", value);
|
|
|
device->regs.device_control = value;
|
device->regs.device_control = value;
|
ata_device_do_control_register(device);
|
ata_device_do_control_register(device);
|
break;
|
break;
|
|
|
case ATA_DHR :
|
case ATA_DHR :
|
/*display debug information */
|
/*display debug information */
|
ata_device_debug(4, "ata_device device head register written, value = 0x%02X\n", value);
|
ata_device_debug(4, "device head register written, value = 0x%02X\n", value);
|
|
|
device->regs.device_head = value;
|
device->regs.device_head = value;
|
break;
|
break;
|
|
|
case ATA_FR :
|
case ATA_FR :
|
/*display debug information */
|
/*display debug information */
|
ata_device_debug(4, "ata_device features register written, value = 0x%02X\n", value);
|
ata_device_debug(4, "features register written, value = 0x%02X\n", value);
|
|
|
device->regs.features = value;
|
device->regs.features = value;
|
break;
|
break;
|
|
|
case ATA_SCR :
|
case ATA_SCR :
|
/*display debug information */
|
/*display debug information */
|
ata_device_debug(4, "ata_device sector-count register written, value = 0x%02X\n", value);
|
ata_device_debug(4, "sectorcount register written, value = 0x%02X\n", value);
|
|
|
device->regs.sector_count = value;
|
device->regs.sector_count = value;
|
break;
|
break;
|
|
|
case ATA_SNR :
|
case ATA_SNR :
|
/*display debug information */
|
/*display debug information */
|
ata_device_debug(4, "ata_device sector-number register written, value = 0x%02X\n", value);
|
ata_device_debug(4, "sectornumber register written, value = 0x%02X\n", value);
|
|
|
device->regs.sector_number = value;
|
device->regs.sector_number = value;
|
break;
|
break;
|
|
|
} //endcase
|
} //endcase
|