forked from len0rd/rockbox
Cleaned up the sleep options a little
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1514 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
63e9bedfc4
commit
513e8510cc
1 changed files with 65 additions and 10 deletions
|
|
@ -28,6 +28,16 @@
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
|
|
||||||
|
/* Define one of USE_STANDBY, USE_SLEEP or USE_POWEROFF */
|
||||||
|
#define USE_STANDBY
|
||||||
|
|
||||||
|
/* We can only use power off on the recorder */
|
||||||
|
#if !defined(ARCHOS_RECORDER) && defined(USE_POWEROFF)
|
||||||
|
#undef USE_POWEROFF
|
||||||
|
#define USE_STANDBY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define SECTOR_SIZE 512
|
#define SECTOR_SIZE 512
|
||||||
#define ATA_DATA (*((volatile unsigned short*)0x06104100))
|
#define ATA_DATA (*((volatile unsigned short*)0x06104100))
|
||||||
#define ATA_ERROR (*((volatile unsigned char*)0x06100101))
|
#define ATA_ERROR (*((volatile unsigned char*)0x06100101))
|
||||||
|
|
@ -80,6 +90,10 @@ static char ata_thread_name[] = "ata";
|
||||||
static struct event_queue ata_queue;
|
static struct event_queue ata_queue;
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
|
|
||||||
|
#ifdef USE_POWEROFF
|
||||||
|
static int ata_power_on(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
static int wait_for_bsy(void) __attribute__ ((section (".icode")));
|
static int wait_for_bsy(void) __attribute__ ((section (".icode")));
|
||||||
static int wait_for_bsy(void)
|
static int wait_for_bsy(void)
|
||||||
{
|
{
|
||||||
|
|
@ -131,12 +145,19 @@ int ata_read_sectors(unsigned long start,
|
||||||
int i;
|
int i;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
#ifndef USE_STANDBY
|
||||||
if ( sleeping ) {
|
if ( sleeping ) {
|
||||||
|
#ifdef USE_POWEROFF
|
||||||
|
if (ata_power_on()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (ata_soft_reset()) {
|
if (ata_soft_reset()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
mutex_lock(&ata_mtx);
|
mutex_lock(&ata_mtx);
|
||||||
sleep_timer = sleep_timeout;
|
sleep_timer = sleep_timeout;
|
||||||
|
|
||||||
|
|
@ -188,12 +209,17 @@ int ata_write_sectors(unsigned long start,
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if ( sleeping ) {
|
#ifndef USE_STANDBY
|
||||||
|
#ifdef USE_POWEROFF
|
||||||
|
if (ata_power_on()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (ata_soft_reset()) {
|
if (ata_soft_reset()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
#endif
|
||||||
|
#endif
|
||||||
mutex_lock(&ata_mtx);
|
mutex_lock(&ata_mtx);
|
||||||
sleep_timer = sleep_timeout;
|
sleep_timer = sleep_timeout;
|
||||||
|
|
||||||
|
|
@ -291,11 +317,15 @@ static int ata_perform_sleep(void)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ATA_POWER_OFF
|
#ifdef USE_POWEROFF
|
||||||
ide_power_enable(false);
|
ide_power_enable(false);
|
||||||
#else
|
#else
|
||||||
ATA_SELECT = ata_device;
|
ATA_SELECT = ata_device;
|
||||||
|
#ifdef USE_SLEEP
|
||||||
|
ATA_COMMAND = CMD_SLEEP;
|
||||||
|
#else
|
||||||
ATA_COMMAND = CMD_STANDBY;
|
ATA_COMMAND = CMD_STANDBY;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!wait_for_rdy())
|
if (!wait_for_rdy())
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
@ -373,17 +403,13 @@ int ata_soft_reset(void)
|
||||||
|
|
||||||
mutex_lock(&ata_mtx);
|
mutex_lock(&ata_mtx);
|
||||||
|
|
||||||
#ifdef ATA_POWER_OFF
|
|
||||||
ide_power_enable(true);
|
|
||||||
sleep(HZ);
|
|
||||||
#else
|
|
||||||
ATA_SELECT = SELECT_LBA | ata_device;
|
ATA_SELECT = SELECT_LBA | ata_device;
|
||||||
ATA_CONTROL = CONTROL_nIEN|CONTROL_SRST;
|
ATA_CONTROL = CONTROL_nIEN|CONTROL_SRST;
|
||||||
sleep(HZ/20000); /* >= 5us */
|
sleep(HZ/20000); /* >= 5us */
|
||||||
|
|
||||||
ATA_CONTROL = CONTROL_nIEN;
|
ATA_CONTROL = CONTROL_nIEN;
|
||||||
sleep(HZ/400); /* >2ms */
|
sleep(HZ/400); /* >2ms */
|
||||||
#endif
|
|
||||||
/* This little sucker can take up to 30 seconds */
|
/* This little sucker can take up to 30 seconds */
|
||||||
retry_count = 8;
|
retry_count = 8;
|
||||||
do
|
do
|
||||||
|
|
@ -399,6 +425,35 @@ int ata_soft_reset(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_POWEROFF
|
||||||
|
static int ata_power_on(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int retry_count;
|
||||||
|
|
||||||
|
mutex_lock(&ata_mtx);
|
||||||
|
|
||||||
|
ide_power_enable(true);
|
||||||
|
sleep(HZ/2);
|
||||||
|
|
||||||
|
ATA_CONTROL = CONTROL_nIEN;
|
||||||
|
|
||||||
|
/* This little sucker can take up to 30 seconds */
|
||||||
|
retry_count = 8;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ret = wait_for_rdy();
|
||||||
|
} while(!ret && retry_count--);
|
||||||
|
|
||||||
|
/* Massage the return code so it is 0 on success and -1 on failure */
|
||||||
|
ret = ret?0:-1;
|
||||||
|
|
||||||
|
sleeping = false;
|
||||||
|
mutex_unlock(&ata_mtx);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int master_slave_detect(void)
|
static int master_slave_detect(void)
|
||||||
{
|
{
|
||||||
/* master? */
|
/* master? */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue