diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/ata_mmc.c | 11 | ||||
-rw-r--r-- | firmware/export/ata_mmc.h | 2 | ||||
-rw-r--r-- | firmware/usb.c | 37 |
3 files changed, 46 insertions, 4 deletions
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c index 7b3b8d1ea8..faa4c1f187 100644 --- a/firmware/drivers/ata_mmc.c +++ b/firmware/drivers/ata_mmc.c | |||
@@ -135,18 +135,21 @@ static void swapcopy_sector(const unsigned char *buf); | |||
135 | static int send_sector(const unsigned char *nextbuf, int timeout); | 135 | static int send_sector(const unsigned char *nextbuf, int timeout); |
136 | static int send_single_sector(const unsigned char *buf, int timeout); | 136 | static int send_single_sector(const unsigned char *buf, int timeout); |
137 | 137 | ||
138 | static bool mmc_detect(void); | ||
139 | static void mmc_tick(void); | 138 | static void mmc_tick(void); |
140 | 139 | ||
141 | /* implementation */ | 140 | /* implementation */ |
142 | 141 | ||
143 | static int select_card(int card_no) | 142 | void mmc_select_clock(int card_no) |
144 | { | 143 | { |
145 | if (card_no == 0) /* internal */ | 144 | if (card_no == 0) /* internal */ |
146 | or_b(0x10, &PADRH); /* set clock gate PA12 CHECKME: mask? */ | 145 | or_b(0x10, &PADRH); /* set clock gate PA12 CHECKME: mask? */ |
147 | else /* external */ | 146 | else /* external */ |
148 | and_b(~0x10, &PADRH); /* clear clock gate PA12 CHECKME: mask?*/ | 147 | and_b(~0x10, &PADRH); /* clear clock gate PA12 CHECKME: mask?*/ |
149 | 148 | } | |
149 | |||
150 | static int select_card(int card_no) | ||
151 | { | ||
152 | mmc_select_clock(card_no); | ||
150 | last_disk_activity = current_tick; | 153 | last_disk_activity = current_tick; |
151 | 154 | ||
152 | if (!card_info[card_no].initialized) | 155 | if (!card_info[card_no].initialized) |
@@ -760,7 +763,7 @@ void ata_spin(void) | |||
760 | { | 763 | { |
761 | } | 764 | } |
762 | 765 | ||
763 | static bool mmc_detect(void) | 766 | bool mmc_detect(void) |
764 | { | 767 | { |
765 | return adc_read(ADC_MMC_SWITCH) < 0x200 ? true : false; | 768 | return adc_read(ADC_MMC_SWITCH) < 0x200 ? true : false; |
766 | } | 769 | } |
diff --git a/firmware/export/ata_mmc.h b/firmware/export/ata_mmc.h index afc0dc24af..3e88b0e019 100644 --- a/firmware/export/ata_mmc.h +++ b/firmware/export/ata_mmc.h | |||
@@ -35,6 +35,8 @@ typedef struct | |||
35 | unsigned int r2w_factor; | 35 | unsigned int r2w_factor; |
36 | } tCardInfo; | 36 | } tCardInfo; |
37 | 37 | ||
38 | void mmc_select_clock(int card_no); | ||
39 | bool mmc_detect(void); | ||
38 | unsigned long mmc_extract_bits(const unsigned long *p, unsigned int start, | 40 | unsigned long mmc_extract_bits(const unsigned long *p, unsigned int start, |
39 | unsigned int size); | 41 | unsigned int size); |
40 | tCardInfo *mmc_card_info(int card_no); | 42 | tCardInfo *mmc_card_info(int card_no); |
diff --git a/firmware/usb.c b/firmware/usb.c index 8f3169e5df..65069c486a 100644 --- a/firmware/usb.c +++ b/firmware/usb.c | |||
@@ -32,6 +32,9 @@ | |||
32 | #include "button.h" | 32 | #include "button.h" |
33 | #include "sprintf.h" | 33 | #include "sprintf.h" |
34 | #include "hwcompat.h" | 34 | #include "hwcompat.h" |
35 | #ifdef HAVE_MMC | ||
36 | #include "ata_mmc.h" | ||
37 | #endif | ||
35 | 38 | ||
36 | extern void dbg_ports(void); /* NASTY! defined in apps/ */ | 39 | extern void dbg_ports(void); /* NASTY! defined in apps/ */ |
37 | 40 | ||
@@ -47,6 +50,9 @@ void screen_dump(void); /* Nasty again. Defined in apps/ too */ | |||
47 | /* Messages from usb_tick */ | 50 | /* Messages from usb_tick */ |
48 | #define USB_INSERTED 1 | 51 | #define USB_INSERTED 1 |
49 | #define USB_EXTRACTED 2 | 52 | #define USB_EXTRACTED 2 |
53 | #ifdef HAVE_MMC | ||
54 | #define USB_REENABLE 3 | ||
55 | #endif | ||
50 | 56 | ||
51 | /* Thread states */ | 57 | /* Thread states */ |
52 | #define EXTRACTING 1 | 58 | #define EXTRACTING 1 |
@@ -62,6 +68,10 @@ static int countdown; | |||
62 | 68 | ||
63 | static int usb_state; | 69 | static int usb_state; |
64 | 70 | ||
71 | #ifdef HAVE_MMC | ||
72 | static int usb_mmc_countdown = 0; | ||
73 | #endif | ||
74 | |||
65 | /* FIXME: The extra 0x400 is consumed by fat_mount() when the fsinfo | 75 | /* FIXME: The extra 0x400 is consumed by fat_mount() when the fsinfo |
66 | needs updating */ | 76 | needs updating */ |
67 | static char usb_stack[DEFAULT_STACK_SIZE + 0x400]; | 77 | static char usb_stack[DEFAULT_STACK_SIZE + 0x400]; |
@@ -75,6 +85,9 @@ static void usb_enable(bool on) | |||
75 | #ifdef USB_ENABLE_ONDIOSTYLE | 85 | #ifdef USB_ENABLE_ONDIOSTYLE |
76 | if(on) | 86 | if(on) |
77 | { | 87 | { |
88 | #ifdef HAVE_MMC | ||
89 | mmc_select_clock(mmc_detect() ? 1 : 0); | ||
90 | #endif | ||
78 | or_b(0x20, &PADRL); /* enable USB */ | 91 | or_b(0x20, &PADRL); /* enable USB */ |
79 | and_b(~0x08, &PADRL); /* assert card detect */ | 92 | and_b(~0x08, &PADRL); /* assert card detect */ |
80 | } | 93 | } |
@@ -255,6 +268,22 @@ static void usb_thread(void) | |||
255 | } | 268 | } |
256 | } | 269 | } |
257 | break; | 270 | break; |
271 | |||
272 | #ifdef HAVE_MMC | ||
273 | case SYS_MMC_INSERTED: | ||
274 | case SYS_MMC_EXTRACTED: | ||
275 | if(usb_state == USB_INSERTED) | ||
276 | { | ||
277 | usb_enable(false); | ||
278 | usb_mmc_countdown = HZ/2; /* re-enable after 0.5 sec */ | ||
279 | } | ||
280 | break; | ||
281 | |||
282 | case USB_REENABLE: | ||
283 | if(usb_state == USB_INSERTED) | ||
284 | usb_enable(true); /* reenable only if still inserted */ | ||
285 | break; | ||
286 | #endif | ||
258 | } | 287 | } |
259 | } | 288 | } |
260 | } | 289 | } |
@@ -308,6 +337,14 @@ static void usb_tick(void) | |||
308 | } | 337 | } |
309 | } | 338 | } |
310 | } | 339 | } |
340 | #ifdef HAVE_MMC | ||
341 | if(usb_mmc_countdown > 0) | ||
342 | { | ||
343 | usb_mmc_countdown--; | ||
344 | if (usb_mmc_countdown == 0) | ||
345 | queue_post(&usb_queue, USB_REENABLE, NULL); | ||
346 | } | ||
347 | #endif | ||
311 | } | 348 | } |
312 | 349 | ||
313 | void usb_acknowledge(int id) | 350 | void usb_acknowledge(int id) |