From 57ea92cae1f4d0f28b453e0caf68977c599cc096 Mon Sep 17 00:00:00 2001 From: Jörg Hohensohn Date: Sat, 11 Sep 2004 03:48:05 +0000 Subject: prepared an empty MMC driver git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5065 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/ata.c | 5 + firmware/drivers/ata_mmc.c | 280 +++++++++++++++++++++++++++++++++++++++ firmware/export/config-ondiofm.h | 3 + firmware/export/config-ondiosp.h | 4 + 4 files changed, 292 insertions(+) create mode 100644 firmware/drivers/ata_mmc.c diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index 05000b02a8..21d97aa939 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -30,6 +30,9 @@ #include "string.h" #include "hwcompat.h" +/* skip whole file for an MMC-based system, FIXME in makefile */ +#ifndef HAVE_MMC + /* Uncomment the matching #define to use plain C code instead if the tweaked * assembler code for disk reading or writing should cause problems. */ /* #define PREFER_C_READING */ @@ -1170,3 +1173,5 @@ int ata_init(void) return 0; } + +#endif /* #ifndef HAVE_MMC */ \ No newline at end of file diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c new file mode 100644 index 0000000000..a3669573e0 --- /dev/null +++ b/firmware/drivers/ata_mmc.c @@ -0,0 +1,280 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Alan Korr + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include +#include "ata.h" +#include "kernel.h" +#include "thread.h" +#include "led.h" +#include "sh7034.h" +#include "system.h" +#include "debug.h" +#include "panic.h" +#include "usb.h" +#include "power.h" +#include "string.h" +#include "hwcompat.h" + +/* use file for an MMC-based system, FIXME in makefile */ +#ifdef HAVE_MMC + +#define SECTOR_SIZE 512 +#define Q_SLEEP 0 + +/* for compatibility */ +bool old_recorder = false; /* FIXME: get rid of this cross-dependency */ +int ata_spinup_time = 0; +static int sleep_timeout = 5*HZ; +char ata_device = 0; /* device 0 (master) or 1 (slave) */ +int ata_io_address = 0; /* 0x300 or 0x200, only valid on recorder */ +static unsigned short identify_info[SECTOR_SIZE]; + +static struct mutex ata_mtx; + +static bool sleeping = true; + +static char ata_stack[DEFAULT_STACK_SIZE]; +static const char ata_thread_name[] = "ata"; +static struct event_queue ata_queue; +static bool initialized = false; +static bool delayed_write = false; +static unsigned char delayed_sector[SECTOR_SIZE]; +static int delayed_sector_num; + +static long last_user_activity = -1; +long last_disk_activity = -1; + + +int ata_read_sectors(unsigned long start, + int incount, + void* inbuf) +{ + int ret = 0; + + mutex_lock(&ata_mtx); + + last_disk_activity = current_tick; + + led(true); + sleeping = false; + + /* ToDo: action */ + (void)start; + (void)incount; + (void)inbuf; + + led(false); + + mutex_unlock(&ata_mtx); + + /* only flush if reading went ok */ + if ( (ret == 0) && delayed_write ) + ata_flush(); + + return ret; +} + + + +int ata_write_sectors(unsigned long start, + int count, + const void* buf) +{ + int ret = 0; + + if (start == 0) + panicf("Writing on sector 0\n"); + + mutex_lock(&ata_mtx); + sleeping = false; + + last_disk_activity = current_tick; + + led(true); + + /* ToDo: action */ + (void)start; + (void)count; + (void)buf; + + led(false); + + mutex_unlock(&ata_mtx); + + /* only flush if writing went ok */ + if ( (ret == 0) && delayed_write ) + ata_flush(); + + return ret; +} + +extern void ata_delayed_write(unsigned long sector, const void* buf) +{ + memcpy(delayed_sector, buf, SECTOR_SIZE); + delayed_sector_num = sector; + delayed_write = true; +} + +extern void ata_flush(void) +{ + if ( delayed_write ) { + DEBUGF("ata_flush()\n"); + delayed_write = false; + ata_write_sectors(delayed_sector_num, 1, delayed_sector); + } +} + +void ata_spindown(int seconds) +{ + sleep_timeout = seconds * HZ; +} + +bool ata_disk_is_active(void) +{ + return !sleeping; +} + +static int ata_perform_sleep(void) +{ + int ret = 0; + + mutex_lock(&ata_mtx); + + /* ToDo: is there an equivalent? */ + + sleeping = true; + mutex_unlock(&ata_mtx); + return ret; +} + +int ata_standby(int time) +{ + int ret = 0; + + mutex_lock(&ata_mtx); + + /* ToDo: is there an equivalent? */ + (void)time; + + mutex_unlock(&ata_mtx); + return ret; +} + +int ata_sleep(void) +{ + queue_post(&ata_queue, Q_SLEEP, NULL); + return 0; +} + +void ata_spin(void) +{ + last_user_activity = current_tick; +} + +static void ata_thread(void) +{ + static long last_sleep = 0; + struct event ev; + + while (1) { + while ( queue_empty( &ata_queue ) ) { + if ( sleep_timeout && !sleeping && + TIME_AFTER( current_tick, + last_user_activity + sleep_timeout ) && + TIME_AFTER( current_tick, + last_disk_activity + sleep_timeout ) ) + { + ata_perform_sleep(); + last_sleep = current_tick; + } + + sleep(HZ/4); + } + queue_wait(&ata_queue, &ev); + switch ( ev.id ) { +#ifndef USB_NONE + case SYS_USB_CONNECTED: + /* Tell the USB thread that we are safe */ + DEBUGF("ata_thread got SYS_USB_CONNECTED\n"); + usb_acknowledge(SYS_USB_CONNECTED_ACK); + + /* Wait until the USB cable is extracted again */ + usb_wait_for_disconnect(&ata_queue); + break; +#endif + case Q_SLEEP: + last_disk_activity = current_tick - sleep_timeout + (HZ/2); + break; + } + } +} + +/* Hardware reset protocol as specified in chapter 9.1, ATA spec draft v5 */ +int ata_hard_reset(void) +{ + int ret = 0; + + return ret; +} + +int ata_soft_reset(void) +{ + int ret = 0; + + return ret; +} + +void ata_enable(bool on) +{ + (void)on; +} + +unsigned short* ata_get_identify(void) +{ + return identify_info; +} + +int ata_init(void) +{ + int rc = 0; + + mutex_init(&ata_mtx); + + led(false); + + /* ToDo: Port setup */ + // PAIOR |= 0x1680; + + + sleeping = false; + ata_enable(true); + + if ( !initialized ) { + + queue_init(&ata_queue); + + last_disk_activity = current_tick; + create_thread(ata_thread, ata_stack, + sizeof(ata_stack), ata_thread_name); + initialized = true; + } + + return rc; +} + +#endif /* #ifdef HAVE_MMC */ diff --git a/firmware/export/config-ondiofm.h b/firmware/export/config-ondiofm.h index 646deddb69..b7b557e1ec 100644 --- a/firmware/export/config-ondiofm.h +++ b/firmware/export/config-ondiofm.h @@ -61,3 +61,6 @@ /* Define this for different ADC channel assignment */ #define HAVE_ONDIO_ADC +/* Define this for MMC support instead of ATA harddisk */ +#define HAVE_MMC + diff --git a/firmware/export/config-ondiosp.h b/firmware/export/config-ondiosp.h index 7e364f738c..4189448070 100644 --- a/firmware/export/config-ondiosp.h +++ b/firmware/export/config-ondiosp.h @@ -60,3 +60,7 @@ /* Define this for different ADC channel assignment */ #define HAVE_ONDIO_ADC + +/* Define this for MMC support instead of ATA harddisk */ +#define HAVE_MMC + -- cgit v1.2.3