MMC hotswap handling in USB mode

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5247 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2004-10-10 19:51:11 +00:00
parent 120d863c68
commit 5789ee9928
3 changed files with 46 additions and 4 deletions

View file

@ -135,18 +135,21 @@ static void swapcopy_sector(const unsigned char *buf);
static int send_sector(const unsigned char *nextbuf, int timeout);
static int send_single_sector(const unsigned char *buf, int timeout);
static bool mmc_detect(void);
static void mmc_tick(void);
/* implementation */
static int select_card(int card_no)
void mmc_select_clock(int card_no)
{
if (card_no == 0) /* internal */
or_b(0x10, &PADRH); /* set clock gate PA12 CHECKME: mask? */
else /* external */
and_b(~0x10, &PADRH); /* clear clock gate PA12 CHECKME: mask?*/
}
static int select_card(int card_no)
{
mmc_select_clock(card_no);
last_disk_activity = current_tick;
if (!card_info[card_no].initialized)
@ -760,7 +763,7 @@ void ata_spin(void)
{
}
static bool mmc_detect(void)
bool mmc_detect(void)
{
return adc_read(ADC_MMC_SWITCH) < 0x200 ? true : false;
}

View file

@ -35,6 +35,8 @@ typedef struct
unsigned int r2w_factor;
} tCardInfo;
void mmc_select_clock(int card_no);
bool mmc_detect(void);
unsigned long mmc_extract_bits(const unsigned long *p, unsigned int start,
unsigned int size);
tCardInfo *mmc_card_info(int card_no);

View file

@ -32,6 +32,9 @@
#include "button.h"
#include "sprintf.h"
#include "hwcompat.h"
#ifdef HAVE_MMC
#include "ata_mmc.h"
#endif
extern void dbg_ports(void); /* NASTY! defined in apps/ */
@ -47,6 +50,9 @@ void screen_dump(void); /* Nasty again. Defined in apps/ too */
/* Messages from usb_tick */
#define USB_INSERTED 1
#define USB_EXTRACTED 2
#ifdef HAVE_MMC
#define USB_REENABLE 3
#endif
/* Thread states */
#define EXTRACTING 1
@ -62,6 +68,10 @@ static int countdown;
static int usb_state;
#ifdef HAVE_MMC
static int usb_mmc_countdown = 0;
#endif
/* FIXME: The extra 0x400 is consumed by fat_mount() when the fsinfo
needs updating */
static char usb_stack[DEFAULT_STACK_SIZE + 0x400];
@ -75,6 +85,9 @@ static void usb_enable(bool on)
#ifdef USB_ENABLE_ONDIOSTYLE
if(on)
{
#ifdef HAVE_MMC
mmc_select_clock(mmc_detect() ? 1 : 0);
#endif
or_b(0x20, &PADRL); /* enable USB */
and_b(~0x08, &PADRL); /* assert card detect */
}
@ -255,6 +268,22 @@ static void usb_thread(void)
}
}
break;
#ifdef HAVE_MMC
case SYS_MMC_INSERTED:
case SYS_MMC_EXTRACTED:
if(usb_state == USB_INSERTED)
{
usb_enable(false);
usb_mmc_countdown = HZ/2; /* re-enable after 0.5 sec */
}
break;
case USB_REENABLE:
if(usb_state == USB_INSERTED)
usb_enable(true); /* reenable only if still inserted */
break;
#endif
}
}
}
@ -308,6 +337,14 @@ static void usb_tick(void)
}
}
}
#ifdef HAVE_MMC
if(usb_mmc_countdown > 0)
{
usb_mmc_countdown--;
if (usb_mmc_countdown == 0)
queue_post(&usb_queue, USB_REENABLE, NULL);
}
#endif
}
void usb_acknowledge(int id)