From 2f8a0081c64534da23fc0fa9cc685eb7454fd9c9 Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Sat, 1 Nov 2008 16:14:28 +0000 Subject: Apply FS#9500. This adds a storage_*() abstraction to replace ata_*(). To do that, it also introduces sd_*, nand_*, and mmc_*. This should be a good first step to allow multi-driver targets, like the Elio (ATA/SD), or the D2 (NAND/SD). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18960 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/ata.c | 57 ++++++++++++++++++++++++---- firmware/drivers/ata_flash.c | 89 +++++++++++++++----------------------------- firmware/drivers/ata_mmc.c | 80 +++++++++++++++++++++++++-------------- firmware/drivers/fat.c | 20 +++++----- 4 files changed, 141 insertions(+), 105 deletions(-) (limited to 'firmware/drivers') diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index b80f615eb3..c2882a5b74 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -32,6 +32,7 @@ #include "string.h" #include "ata_idle_notify.h" #include "ata-target.h" +#include "storage.h" #define SECTOR_SIZE (512) @@ -148,7 +149,7 @@ static void ata_lock_unlock(struct ata_lock *l) static struct mutex ata_mtx SHAREDBSS_ATTR; static int ata_device; /* device 0 (master) or 1 (slave) */ -int ata_spinup_time = 0; +static int spinup_time = 0; #if (CONFIG_LED == LED_REAL) static bool ata_led_enabled = true; static bool ata_led_on = false; @@ -166,7 +167,7 @@ static struct event_queue ata_queue; static bool initialized = false; static long last_user_activity = -1; -long last_disk_activity = -1; +static long last_disk_activity = -1; static unsigned long total_sectors; static int multisectors; /* number of supported multisectors */ @@ -407,7 +408,7 @@ int ata_read_sectors(IF_MV2(int drive,) } if (spinup) { - ata_spinup_time = current_tick - spinup_start; + spinup_time = current_tick - spinup_start; spinup = false; sleeping = false; poweroff = false; @@ -584,7 +585,7 @@ int ata_write_sectors(IF_MV2(int drive,) } if (spinup) { - ata_spinup_time = current_tick - spinup_start; + spinup_time = current_tick - spinup_start; spinup = false; sleeping = false; poweroff = false; @@ -873,7 +874,7 @@ void ata_sleepnow(void) { if (!spinup && !sleeping && !ata_mtx.locked && initialized) { - call_ata_idle_notifys(false); + call_storage_idle_notifys(false); ata_perform_sleep(); } } @@ -908,7 +909,7 @@ static void ata_thread(void) #ifdef ALLOW_USB_SPINDOWN if(!usb_mode) #endif - call_ata_idle_notifys(false); + call_storage_idle_notifys(false); last_seen_mtx_unlock = 0; } } @@ -921,7 +922,7 @@ static void ata_thread(void) #ifdef ALLOW_USB_SPINDOWN if(!usb_mode) #endif - call_ata_idle_notifys(true); + call_storage_idle_notifys(true); ata_perform_sleep(); last_sleep = current_tick; } @@ -974,7 +975,7 @@ static void ata_thread(void) #ifdef ALLOW_USB_SPINDOWN if(!usb_mode) #endif - call_ata_idle_notifys(false); + call_storage_idle_notifys(false); last_disk_activity = current_tick - sleep_timeout + (HZ/2); break; @@ -1391,3 +1392,43 @@ void ata_set_led_enabled(bool enabled) led(false); } #endif + +long ata_last_disk_activity(void) +{ + return last_disk_activity; +} + +int ata_spinup_time(void) +{ + return spinup_time; +} + +void ata_get_info(struct storage_info *info) +{ + unsigned short *src,*dest; + static char vendor[8]; + static char product[16]; + static char revision[4]; + int i; + info->sector_size = SECTOR_SIZE; + info->num_sectors= ((unsigned long)identify_info[61] << 16 | \ + (unsigned long)identify_info[60]); + + src = (unsigned short*)&identify_info[27]; + dest = (unsigned short*)vendor; + for (i=0;i<4;i++) + dest[i] = htobe16(src[i]); + info->vendor=vendor; + + src = (unsigned short*)&identify_info[31]; + dest = (unsigned short*)product; + for (i=0;i<8;i++) + dest[i] = htobe16(src[i]); + info->product=product; + + src = (unsigned short*)&identify_info[23]; + dest = (unsigned short*)revision; + for (i=0;i<2;i++) + dest[i] = htobe16(src[i]); + info->revision=revision; +} diff --git a/firmware/drivers/ata_flash.c b/firmware/drivers/ata_flash.c index d77e05647b..9b1b64145d 100644 --- a/firmware/drivers/ata_flash.c +++ b/firmware/drivers/ata_flash.c @@ -19,7 +19,7 @@ * ****************************************************************************/ -#include "ata.h" +#include "storage.h" #include #include @@ -42,8 +42,6 @@ #define SECTOR_SIZE (512) -static unsigned short identify_info[SECTOR_SIZE]; -int ata_spinup_time = 0; long last_disk_activity = -1; #if CONFIG_FLASH == FLASH_IFP7XX @@ -386,7 +384,7 @@ int flash_disk_read_sectors(unsigned long start, return done; } -int ata_read_sectors(IF_MV2(int drive,) +int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, void* inbuf) @@ -403,7 +401,7 @@ int ata_read_sectors(IF_MV2(int drive,) return 0; } -int ata_write_sectors(IF_MV2(int drive,) +int nand_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf) @@ -414,60 +412,7 @@ int ata_write_sectors(IF_MV2(int drive,) return -1; } -/* schedule a single sector write, executed with the the next spinup - (volume 0 only, used for config sector) */ -extern void ata_delayed_write(unsigned long sector, const void* buf) -{ - (void)sector; - (void)buf; -} - -/* write the delayed sector to volume 0 */ -extern void ata_flush(void) -{ - -} - -void ata_spindown(int seconds) -{ - (void)seconds; -} - -bool ata_disk_is_active(void) -{ - return 0; -} - -void ata_sleep(void) -{ -} - -void ata_spin(void) -{ -} - -/* Hardware reset protocol as specified in chapter 9.1, ATA spec draft v5 */ -int ata_hard_reset(void) -{ - return 0; -} - -int ata_soft_reset(void) -{ - return 0; -} - -void ata_enable(bool on) -{ - (void)on; -} - -unsigned short* ata_get_identify(void) -{ - return identify_info; -} - -int ata_init(void) +int nand_init(void) { int i, id, id2; @@ -499,3 +444,29 @@ int ata_init(void) return 0; } + +long nand_last_disk_activity(void) +{ + return last_disk_activity; +} + +void nand_get_info(struct storage_info *info) +{ + unsigned long blocks; + int i; + + /* firmware version */ + info->revision="0.00"; + + /* vendor field, need better name? */ + info->vendor="Rockbox"; + /* model field, need better name? */ + info->product="TNFL"; + + /* blocks count */ + info->num_sectors = 0; + info->sector_size=SECTOR_SIZE; + + info->serial=0; +} + diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c index 1040ab067f..953bb90bbc 100644 --- a/firmware/drivers/ata_mmc.c +++ b/firmware/drivers/ata_mmc.c @@ -19,7 +19,7 @@ * ****************************************************************************/ #include -#include "ata.h" +#include "mmc.h" #include "ata_mmc.h" #include "ata_idle_notify.h" #include "kernel.h" @@ -36,6 +36,7 @@ #include "adc.h" #include "bitswap.h" #include "disk.h" /* for mount/unmount */ +#include "storage.h" #define BLOCK_SIZE 512 /* fixed */ @@ -84,8 +85,7 @@ #define DT_STOP_TRAN 0xfd /* for compatibility */ -int ata_spinup_time = 0; -long last_disk_activity = -1; +static long last_disk_activity = -1; /* private variables */ @@ -601,7 +601,7 @@ static int send_block_send(unsigned char start_token, long timeout, return rc; } -int ata_read_sectors(IF_MV2(int drive,) +int mmc_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, void* inbuf) @@ -687,7 +687,7 @@ int ata_read_sectors(IF_MV2(int drive,) return rc; } -int ata_write_sectors(IF_MV2(int drive,) +int mmc_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf) @@ -755,25 +755,12 @@ int ata_write_sectors(IF_MV2(int drive,) return rc; } -void ata_spindown(int seconds) -{ - (void)seconds; -} - -bool ata_disk_is_active(void) +bool mmc_disk_is_active(void) { /* this is correct unless early return from write gets implemented */ return mmc_mutex.locked; } -void ata_sleep(void) -{ -} - -void ata_spin(void) -{ -} - static void mmc_thread(void) { struct queue_event ev; @@ -810,7 +797,7 @@ static void mmc_thread(void) { if (!idle_notified) { - call_ata_idle_notifys(false); + call_storage_idle_notifys(false); idle_notified = true; } } @@ -904,12 +891,7 @@ static void mmc_tick(void) } } -int ata_soft_reset(void) -{ - return 0; -} - -void ata_enable(bool on) +void mmc_enable(bool on) { PBCR1 &= ~0x0CF0; /* PB13, PB11 and PB10 become GPIO, * if not modified below */ @@ -924,7 +906,7 @@ void ata_enable(bool on) card_info[1].initialized = false; } -int ata_init(void) +int mmc_init(void) { int rc = 0; @@ -970,9 +952,51 @@ int ata_init(void) tick_add_task(mmc_tick); initialized = true; } - ata_enable(true); + mmc_enable(true); mutex_unlock(&mmc_mutex); return rc; } +long mmc_last_disk_activity(void) +{ + return last_disk_activity; +} + +void mmc_get_info(IF_MV2(int drive,) struct storage_info *info) +{ +#ifndef HAVE_MULTIVOLUME + const int drive=0; +#endif + info->sector_size=card_info[drive].blocksize; + info->num_sectors=card_info[drive].numblocks; + info->vendor="Rockbox"; + if(drive==0) + { + info->product="Internal Storage"; + } + else + { + info->product="MMC Card Slot"; + } + info->revision="0.00"; +} + +#ifdef HAVE_HOTSWAP +bool mmc_removable(IF_MV_NONVOID(int drive)) +{ +#ifndef HAVE_MULTIVOLUME + const int drive=0; +#endif + return (drive==1); +} + +bool mmc_present(IF_MV_NONVOID(int drive)) +{ +#ifndef HAVE_MULTIVOLUME + const int drive=0; +#endif + return (card_info[drive].initialized && card_info[drive].numblocks > 0); +} +#endif + diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 90be93f4f4..4317b70766 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -24,7 +24,7 @@ #include #include #include "fat.h" -#include "ata.h" +#include "storage.h" #include "debug.h" #include "panic.h" #include "system.h" @@ -300,7 +300,7 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector) #endif /* Read the sector */ - rc = ata_read_sectors(IF_MV2(drive,) startsector,1,buf); + rc = storage_read_sectors(IF_MV2(drive,) startsector,1,buf); if(rc) { DEBUGF( "fat_mount() - Couldn't read BPB (error code %d)\n", rc); @@ -422,7 +422,7 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector) #endif /* #ifdef HAVE_FAT16SUPPORT */ { /* Read the fsinfo sector */ - rc = ata_read_sectors(IF_MV2(drive,) + rc = storage_read_sectors(IF_MV2(drive,) startsector + fat_bpb->bpb_fsinfo, 1, buf); if (rc < 0) { @@ -597,7 +597,7 @@ static void flush_fat_sector(struct fat_cache_entry *fce, #endif /* Write to the first FAT */ - rc = ata_write_sectors(IF_MV2(fce->fat_vol->drive,) + rc = storage_write_sectors(IF_MV2(fce->fat_vol->drive,) secnum, 1, sectorbuf); if(rc < 0) @@ -618,7 +618,7 @@ static void flush_fat_sector(struct fat_cache_entry *fce, #else secnum += fat_bpbs[0].fatsize; #endif - rc = ata_write_sectors(IF_MV2(fce->fat_vol->drive,) + rc = storage_write_sectors(IF_MV2(fce->fat_vol->drive,) secnum, 1, sectorbuf); if(rc < 0) { @@ -664,7 +664,7 @@ static void *cache_fat_sector(IF_MV2(struct bpb* fat_bpb,) /* Load the sector if it is not cached */ if(!fce->inuse) { - rc = ata_read_sectors(IF_MV2(fat_bpb->drive,) + rc = storage_read_sectors(IF_MV2(fat_bpb->drive,) secnum + fat_bpb->startsector,1, sectorbuf); if(rc < 0) @@ -923,7 +923,7 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb)) #endif /* #ifdef HAVE_FAT16SUPPORT */ /* update fsinfo */ - rc = ata_read_sectors(IF_MV2(fat_bpb->drive,) + rc = storage_read_sectors(IF_MV2(fat_bpb->drive,) fat_bpb->startsector + fat_bpb->bpb_fsinfo, 1,fsinfo); if (rc < 0) { @@ -936,7 +936,7 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb)) intptr = (long*)&(fsinfo[FSINFO_NEXTFREE]); *intptr = htole32(fat_bpb->fsinfo.nextfree); - rc = ata_write_sectors(IF_MV2(fat_bpb->drive,) + rc = storage_write_sectors(IF_MV2(fat_bpb->drive,) fat_bpb->startsector + fat_bpb->bpb_fsinfo,1,fsinfo); if (rc < 0) { @@ -2077,11 +2077,11 @@ static int transfer(IF_MV2(struct bpb* fat_bpb,) if (start + count > fat_bpb->totalsectors) panicf("Write %ld after data\n", start + count - fat_bpb->totalsectors); - rc = ata_write_sectors(IF_MV2(fat_bpb->drive,) + rc = storage_write_sectors(IF_MV2(fat_bpb->drive,) start + fat_bpb->startsector, count, buf); } else - rc = ata_read_sectors(IF_MV2(fat_bpb->drive,) + rc = storage_read_sectors(IF_MV2(fat_bpb->drive,) start + fat_bpb->startsector, count, buf); if (rc < 0) { DEBUGF( "transfer() - Couldn't %s sector %lx" -- cgit v1.2.3