summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2008-11-01 16:14:28 +0000
committerFrank Gevaerts <frank@gevaerts.be>2008-11-01 16:14:28 +0000
commit2f8a0081c64534da23fc0fa9cc685eb7454fd9c9 (patch)
tree84dbdbd5326cb48f43d2ebd5a4c86e992c1d5288 /firmware/drivers
parent646cac0bde7b11fa7bcb670d1d76eec78e360485 (diff)
downloadrockbox-2f8a0081c64534da23fc0fa9cc685eb7454fd9c9.tar.gz
rockbox-2f8a0081c64534da23fc0fa9cc685eb7454fd9c9.zip
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
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/ata.c57
-rw-r--r--firmware/drivers/ata_flash.c89
-rw-r--r--firmware/drivers/ata_mmc.c80
-rw-r--r--firmware/drivers/fat.c20
4 files changed, 141 insertions, 105 deletions
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 @@
32#include "string.h" 32#include "string.h"
33#include "ata_idle_notify.h" 33#include "ata_idle_notify.h"
34#include "ata-target.h" 34#include "ata-target.h"
35#include "storage.h"
35 36
36#define SECTOR_SIZE (512) 37#define SECTOR_SIZE (512)
37 38
@@ -148,7 +149,7 @@ static void ata_lock_unlock(struct ata_lock *l)
148static struct mutex ata_mtx SHAREDBSS_ATTR; 149static struct mutex ata_mtx SHAREDBSS_ATTR;
149static int ata_device; /* device 0 (master) or 1 (slave) */ 150static int ata_device; /* device 0 (master) or 1 (slave) */
150 151
151int ata_spinup_time = 0; 152static int spinup_time = 0;
152#if (CONFIG_LED == LED_REAL) 153#if (CONFIG_LED == LED_REAL)
153static bool ata_led_enabled = true; 154static bool ata_led_enabled = true;
154static bool ata_led_on = false; 155static bool ata_led_on = false;
@@ -166,7 +167,7 @@ static struct event_queue ata_queue;
166static bool initialized = false; 167static bool initialized = false;
167 168
168static long last_user_activity = -1; 169static long last_user_activity = -1;
169long last_disk_activity = -1; 170static long last_disk_activity = -1;
170 171
171static unsigned long total_sectors; 172static unsigned long total_sectors;
172static int multisectors; /* number of supported multisectors */ 173static int multisectors; /* number of supported multisectors */
@@ -407,7 +408,7 @@ int ata_read_sectors(IF_MV2(int drive,)
407 } 408 }
408 409
409 if (spinup) { 410 if (spinup) {
410 ata_spinup_time = current_tick - spinup_start; 411 spinup_time = current_tick - spinup_start;
411 spinup = false; 412 spinup = false;
412 sleeping = false; 413 sleeping = false;
413 poweroff = false; 414 poweroff = false;
@@ -584,7 +585,7 @@ int ata_write_sectors(IF_MV2(int drive,)
584 } 585 }
585 586
586 if (spinup) { 587 if (spinup) {
587 ata_spinup_time = current_tick - spinup_start; 588 spinup_time = current_tick - spinup_start;
588 spinup = false; 589 spinup = false;
589 sleeping = false; 590 sleeping = false;
590 poweroff = false; 591 poweroff = false;
@@ -873,7 +874,7 @@ void ata_sleepnow(void)
873{ 874{
874 if (!spinup && !sleeping && !ata_mtx.locked && initialized) 875 if (!spinup && !sleeping && !ata_mtx.locked && initialized)
875 { 876 {
876 call_ata_idle_notifys(false); 877 call_storage_idle_notifys(false);
877 ata_perform_sleep(); 878 ata_perform_sleep();
878 } 879 }
879} 880}
@@ -908,7 +909,7 @@ static void ata_thread(void)
908#ifdef ALLOW_USB_SPINDOWN 909#ifdef ALLOW_USB_SPINDOWN
909 if(!usb_mode) 910 if(!usb_mode)
910#endif 911#endif
911 call_ata_idle_notifys(false); 912 call_storage_idle_notifys(false);
912 last_seen_mtx_unlock = 0; 913 last_seen_mtx_unlock = 0;
913 } 914 }
914 } 915 }
@@ -921,7 +922,7 @@ static void ata_thread(void)
921#ifdef ALLOW_USB_SPINDOWN 922#ifdef ALLOW_USB_SPINDOWN
922 if(!usb_mode) 923 if(!usb_mode)
923#endif 924#endif
924 call_ata_idle_notifys(true); 925 call_storage_idle_notifys(true);
925 ata_perform_sleep(); 926 ata_perform_sleep();
926 last_sleep = current_tick; 927 last_sleep = current_tick;
927 } 928 }
@@ -974,7 +975,7 @@ static void ata_thread(void)
974#ifdef ALLOW_USB_SPINDOWN 975#ifdef ALLOW_USB_SPINDOWN
975 if(!usb_mode) 976 if(!usb_mode)
976#endif 977#endif
977 call_ata_idle_notifys(false); 978 call_storage_idle_notifys(false);
978 last_disk_activity = current_tick - sleep_timeout + (HZ/2); 979 last_disk_activity = current_tick - sleep_timeout + (HZ/2);
979 break; 980 break;
980 981
@@ -1391,3 +1392,43 @@ void ata_set_led_enabled(bool enabled)
1391 led(false); 1392 led(false);
1392} 1393}
1393#endif 1394#endif
1395
1396long ata_last_disk_activity(void)
1397{
1398 return last_disk_activity;
1399}
1400
1401int ata_spinup_time(void)
1402{
1403 return spinup_time;
1404}
1405
1406void ata_get_info(struct storage_info *info)
1407{
1408 unsigned short *src,*dest;
1409 static char vendor[8];
1410 static char product[16];
1411 static char revision[4];
1412 int i;
1413 info->sector_size = SECTOR_SIZE;
1414 info->num_sectors= ((unsigned long)identify_info[61] << 16 | \
1415 (unsigned long)identify_info[60]);
1416
1417 src = (unsigned short*)&identify_info[27];
1418 dest = (unsigned short*)vendor;
1419 for (i=0;i<4;i++)
1420 dest[i] = htobe16(src[i]);
1421 info->vendor=vendor;
1422
1423 src = (unsigned short*)&identify_info[31];
1424 dest = (unsigned short*)product;
1425 for (i=0;i<8;i++)
1426 dest[i] = htobe16(src[i]);
1427 info->product=product;
1428
1429 src = (unsigned short*)&identify_info[23];
1430 dest = (unsigned short*)revision;
1431 for (i=0;i<2;i++)
1432 dest[i] = htobe16(src[i]);
1433 info->revision=revision;
1434}
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 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#include "ata.h" 22#include "storage.h"
23#include <stdbool.h> 23#include <stdbool.h>
24#include <string.h> 24#include <string.h>
25 25
@@ -42,8 +42,6 @@
42 42
43#define SECTOR_SIZE (512) 43#define SECTOR_SIZE (512)
44 44
45static unsigned short identify_info[SECTOR_SIZE];
46int ata_spinup_time = 0;
47long last_disk_activity = -1; 45long last_disk_activity = -1;
48 46
49#if CONFIG_FLASH == FLASH_IFP7XX 47#if CONFIG_FLASH == FLASH_IFP7XX
@@ -386,7 +384,7 @@ int flash_disk_read_sectors(unsigned long start,
386 return done; 384 return done;
387} 385}
388 386
389int ata_read_sectors(IF_MV2(int drive,) 387int nand_read_sectors(IF_MV2(int drive,)
390 unsigned long start, 388 unsigned long start,
391 int incount, 389 int incount,
392 void* inbuf) 390 void* inbuf)
@@ -403,7 +401,7 @@ int ata_read_sectors(IF_MV2(int drive,)
403 return 0; 401 return 0;
404} 402}
405 403
406int ata_write_sectors(IF_MV2(int drive,) 404int nand_write_sectors(IF_MV2(int drive,)
407 unsigned long start, 405 unsigned long start,
408 int count, 406 int count,
409 const void* buf) 407 const void* buf)
@@ -414,60 +412,7 @@ int ata_write_sectors(IF_MV2(int drive,)
414 return -1; 412 return -1;
415} 413}
416 414
417/* schedule a single sector write, executed with the the next spinup 415int nand_init(void)
418 (volume 0 only, used for config sector) */
419extern void ata_delayed_write(unsigned long sector, const void* buf)
420{
421 (void)sector;
422 (void)buf;
423}
424
425/* write the delayed sector to volume 0 */
426extern void ata_flush(void)
427{
428
429}
430
431void ata_spindown(int seconds)
432{
433 (void)seconds;
434}
435
436bool ata_disk_is_active(void)
437{
438 return 0;
439}
440
441void ata_sleep(void)
442{
443}
444
445void ata_spin(void)
446{
447}
448
449/* Hardware reset protocol as specified in chapter 9.1, ATA spec draft v5 */
450int ata_hard_reset(void)
451{
452 return 0;
453}
454
455int ata_soft_reset(void)
456{
457 return 0;
458}
459
460void ata_enable(bool on)
461{
462 (void)on;
463}
464
465unsigned short* ata_get_identify(void)
466{
467 return identify_info;
468}
469
470int ata_init(void)
471{ 416{
472 int i, id, id2; 417 int i, id, id2;
473 418
@@ -499,3 +444,29 @@ int ata_init(void)
499 444
500 return 0; 445 return 0;
501} 446}
447
448long nand_last_disk_activity(void)
449{
450 return last_disk_activity;
451}
452
453void nand_get_info(struct storage_info *info)
454{
455 unsigned long blocks;
456 int i;
457
458 /* firmware version */
459 info->revision="0.00";
460
461 /* vendor field, need better name? */
462 info->vendor="Rockbox";
463 /* model field, need better name? */
464 info->product="TNFL";
465
466 /* blocks count */
467 info->num_sectors = 0;
468 info->sector_size=SECTOR_SIZE;
469
470 info->serial=0;
471}
472
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 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include <stdbool.h> 21#include <stdbool.h>
22#include "ata.h" 22#include "mmc.h"
23#include "ata_mmc.h" 23#include "ata_mmc.h"
24#include "ata_idle_notify.h" 24#include "ata_idle_notify.h"
25#include "kernel.h" 25#include "kernel.h"
@@ -36,6 +36,7 @@
36#include "adc.h" 36#include "adc.h"
37#include "bitswap.h" 37#include "bitswap.h"
38#include "disk.h" /* for mount/unmount */ 38#include "disk.h" /* for mount/unmount */
39#include "storage.h"
39 40
40#define BLOCK_SIZE 512 /* fixed */ 41#define BLOCK_SIZE 512 /* fixed */
41 42
@@ -84,8 +85,7 @@
84#define DT_STOP_TRAN 0xfd 85#define DT_STOP_TRAN 0xfd
85 86
86/* for compatibility */ 87/* for compatibility */
87int ata_spinup_time = 0; 88static long last_disk_activity = -1;
88long last_disk_activity = -1;
89 89
90/* private variables */ 90/* private variables */
91 91
@@ -601,7 +601,7 @@ static int send_block_send(unsigned char start_token, long timeout,
601 return rc; 601 return rc;
602} 602}
603 603
604int ata_read_sectors(IF_MV2(int drive,) 604int mmc_read_sectors(IF_MV2(int drive,)
605 unsigned long start, 605 unsigned long start,
606 int incount, 606 int incount,
607 void* inbuf) 607 void* inbuf)
@@ -687,7 +687,7 @@ int ata_read_sectors(IF_MV2(int drive,)
687 return rc; 687 return rc;
688} 688}
689 689
690int ata_write_sectors(IF_MV2(int drive,) 690int mmc_write_sectors(IF_MV2(int drive,)
691 unsigned long start, 691 unsigned long start,
692 int count, 692 int count,
693 const void* buf) 693 const void* buf)
@@ -755,25 +755,12 @@ int ata_write_sectors(IF_MV2(int drive,)
755 return rc; 755 return rc;
756} 756}
757 757
758void ata_spindown(int seconds) 758bool mmc_disk_is_active(void)
759{
760 (void)seconds;
761}
762
763bool ata_disk_is_active(void)
764{ 759{
765 /* this is correct unless early return from write gets implemented */ 760 /* this is correct unless early return from write gets implemented */
766 return mmc_mutex.locked; 761 return mmc_mutex.locked;
767} 762}
768 763
769void ata_sleep(void)
770{
771}
772
773void ata_spin(void)
774{
775}
776
777static void mmc_thread(void) 764static void mmc_thread(void)
778{ 765{
779 struct queue_event ev; 766 struct queue_event ev;
@@ -810,7 +797,7 @@ static void mmc_thread(void)
810 { 797 {
811 if (!idle_notified) 798 if (!idle_notified)
812 { 799 {
813 call_ata_idle_notifys(false); 800 call_storage_idle_notifys(false);
814 idle_notified = true; 801 idle_notified = true;
815 } 802 }
816 } 803 }
@@ -904,12 +891,7 @@ static void mmc_tick(void)
904 } 891 }
905} 892}
906 893
907int ata_soft_reset(void) 894void mmc_enable(bool on)
908{
909 return 0;
910}
911
912void ata_enable(bool on)
913{ 895{
914 PBCR1 &= ~0x0CF0; /* PB13, PB11 and PB10 become GPIO, 896 PBCR1 &= ~0x0CF0; /* PB13, PB11 and PB10 become GPIO,
915 * if not modified below */ 897 * if not modified below */
@@ -924,7 +906,7 @@ void ata_enable(bool on)
924 card_info[1].initialized = false; 906 card_info[1].initialized = false;
925} 907}
926 908
927int ata_init(void) 909int mmc_init(void)
928{ 910{
929 int rc = 0; 911 int rc = 0;
930 912
@@ -970,9 +952,51 @@ int ata_init(void)
970 tick_add_task(mmc_tick); 952 tick_add_task(mmc_tick);
971 initialized = true; 953 initialized = true;
972 } 954 }
973 ata_enable(true); 955 mmc_enable(true);
974 956
975 mutex_unlock(&mmc_mutex); 957 mutex_unlock(&mmc_mutex);
976 return rc; 958 return rc;
977} 959}
978 960
961long mmc_last_disk_activity(void)
962{
963 return last_disk_activity;
964}
965
966void mmc_get_info(IF_MV2(int drive,) struct storage_info *info)
967{
968#ifndef HAVE_MULTIVOLUME
969 const int drive=0;
970#endif
971 info->sector_size=card_info[drive].blocksize;
972 info->num_sectors=card_info[drive].numblocks;
973 info->vendor="Rockbox";
974 if(drive==0)
975 {
976 info->product="Internal Storage";
977 }
978 else
979 {
980 info->product="MMC Card Slot";
981 }
982 info->revision="0.00";
983}
984
985#ifdef HAVE_HOTSWAP
986bool mmc_removable(IF_MV_NONVOID(int drive))
987{
988#ifndef HAVE_MULTIVOLUME
989 const int drive=0;
990#endif
991 return (drive==1);
992}
993
994bool mmc_present(IF_MV_NONVOID(int drive))
995{
996#ifndef HAVE_MULTIVOLUME
997 const int drive=0;
998#endif
999 return (card_info[drive].initialized && card_info[drive].numblocks > 0);
1000}
1001#endif
1002
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 @@
24#include <ctype.h> 24#include <ctype.h>
25#include <stdbool.h> 25#include <stdbool.h>
26#include "fat.h" 26#include "fat.h"
27#include "ata.h" 27#include "storage.h"
28#include "debug.h" 28#include "debug.h"
29#include "panic.h" 29#include "panic.h"
30#include "system.h" 30#include "system.h"
@@ -300,7 +300,7 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector)
300#endif 300#endif
301 301
302 /* Read the sector */ 302 /* Read the sector */
303 rc = ata_read_sectors(IF_MV2(drive,) startsector,1,buf); 303 rc = storage_read_sectors(IF_MV2(drive,) startsector,1,buf);
304 if(rc) 304 if(rc)
305 { 305 {
306 DEBUGF( "fat_mount() - Couldn't read BPB (error code %d)\n", rc); 306 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)
422#endif /* #ifdef HAVE_FAT16SUPPORT */ 422#endif /* #ifdef HAVE_FAT16SUPPORT */
423 { 423 {
424 /* Read the fsinfo sector */ 424 /* Read the fsinfo sector */
425 rc = ata_read_sectors(IF_MV2(drive,) 425 rc = storage_read_sectors(IF_MV2(drive,)
426 startsector + fat_bpb->bpb_fsinfo, 1, buf); 426 startsector + fat_bpb->bpb_fsinfo, 1, buf);
427 if (rc < 0) 427 if (rc < 0)
428 { 428 {
@@ -597,7 +597,7 @@ static void flush_fat_sector(struct fat_cache_entry *fce,
597#endif 597#endif
598 598
599 /* Write to the first FAT */ 599 /* Write to the first FAT */
600 rc = ata_write_sectors(IF_MV2(fce->fat_vol->drive,) 600 rc = storage_write_sectors(IF_MV2(fce->fat_vol->drive,)
601 secnum, 1, 601 secnum, 1,
602 sectorbuf); 602 sectorbuf);
603 if(rc < 0) 603 if(rc < 0)
@@ -618,7 +618,7 @@ static void flush_fat_sector(struct fat_cache_entry *fce,
618#else 618#else
619 secnum += fat_bpbs[0].fatsize; 619 secnum += fat_bpbs[0].fatsize;
620#endif 620#endif
621 rc = ata_write_sectors(IF_MV2(fce->fat_vol->drive,) 621 rc = storage_write_sectors(IF_MV2(fce->fat_vol->drive,)
622 secnum, 1, sectorbuf); 622 secnum, 1, sectorbuf);
623 if(rc < 0) 623 if(rc < 0)
624 { 624 {
@@ -664,7 +664,7 @@ static void *cache_fat_sector(IF_MV2(struct bpb* fat_bpb,)
664 /* Load the sector if it is not cached */ 664 /* Load the sector if it is not cached */
665 if(!fce->inuse) 665 if(!fce->inuse)
666 { 666 {
667 rc = ata_read_sectors(IF_MV2(fat_bpb->drive,) 667 rc = storage_read_sectors(IF_MV2(fat_bpb->drive,)
668 secnum + fat_bpb->startsector,1, 668 secnum + fat_bpb->startsector,1,
669 sectorbuf); 669 sectorbuf);
670 if(rc < 0) 670 if(rc < 0)
@@ -923,7 +923,7 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb))
923#endif /* #ifdef HAVE_FAT16SUPPORT */ 923#endif /* #ifdef HAVE_FAT16SUPPORT */
924 924
925 /* update fsinfo */ 925 /* update fsinfo */
926 rc = ata_read_sectors(IF_MV2(fat_bpb->drive,) 926 rc = storage_read_sectors(IF_MV2(fat_bpb->drive,)
927 fat_bpb->startsector + fat_bpb->bpb_fsinfo, 1,fsinfo); 927 fat_bpb->startsector + fat_bpb->bpb_fsinfo, 1,fsinfo);
928 if (rc < 0) 928 if (rc < 0)
929 { 929 {
@@ -936,7 +936,7 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb))
936 intptr = (long*)&(fsinfo[FSINFO_NEXTFREE]); 936 intptr = (long*)&(fsinfo[FSINFO_NEXTFREE]);
937 *intptr = htole32(fat_bpb->fsinfo.nextfree); 937 *intptr = htole32(fat_bpb->fsinfo.nextfree);
938 938
939 rc = ata_write_sectors(IF_MV2(fat_bpb->drive,) 939 rc = storage_write_sectors(IF_MV2(fat_bpb->drive,)
940 fat_bpb->startsector + fat_bpb->bpb_fsinfo,1,fsinfo); 940 fat_bpb->startsector + fat_bpb->bpb_fsinfo,1,fsinfo);
941 if (rc < 0) 941 if (rc < 0)
942 { 942 {
@@ -2077,11 +2077,11 @@ static int transfer(IF_MV2(struct bpb* fat_bpb,)
2077 if (start + count > fat_bpb->totalsectors) 2077 if (start + count > fat_bpb->totalsectors)
2078 panicf("Write %ld after data\n", 2078 panicf("Write %ld after data\n",
2079 start + count - fat_bpb->totalsectors); 2079 start + count - fat_bpb->totalsectors);
2080 rc = ata_write_sectors(IF_MV2(fat_bpb->drive,) 2080 rc = storage_write_sectors(IF_MV2(fat_bpb->drive,)
2081 start + fat_bpb->startsector, count, buf); 2081 start + fat_bpb->startsector, count, buf);
2082 } 2082 }
2083 else 2083 else
2084 rc = ata_read_sectors(IF_MV2(fat_bpb->drive,) 2084 rc = storage_read_sectors(IF_MV2(fat_bpb->drive,)
2085 start + fat_bpb->startsector, count, buf); 2085 start + fat_bpb->startsector, count, buf);
2086 if (rc < 0) { 2086 if (rc < 0) {
2087 DEBUGF( "transfer() - Couldn't %s sector %lx" 2087 DEBUGF( "transfer() - Couldn't %s sector %lx"