summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/target/mips/ingenic_jz47xx/ata-sd-jz4760.c52
1 files changed, 25 insertions, 27 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4760.c b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4760.c
index 93426157b7..d01015fee6 100644
--- a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4760.c
+++ b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4760.c
@@ -33,6 +33,12 @@
33static long last_disk_activity = -1; 33static long last_disk_activity = -1;
34static tCardInfo card[NUM_DRIVES]; 34static tCardInfo card[NUM_DRIVES];
35 35
36#if defined(CONFIG_STORAGE_MULTI) || defined(HAVE_HOTSWAP)
37static int sd_drive_nr = 0;
38#else
39#define sd_drive_nr 0
40#endif
41
36static struct mutex sd_mtx; 42static struct mutex sd_mtx;
37//static struct semaphore sd_wakeup; 43//static struct semaphore sd_wakeup;
38 44
@@ -1402,65 +1408,55 @@ int sd_soft_reset(void)
1402} 1408}
1403 1409
1404#ifdef HAVE_HOTSWAP 1410#ifdef HAVE_HOTSWAP
1405bool sd_removable(const int drive) 1411bool sd_removable(IF_MD_NONVOID(const int drive))
1406{ 1412{
1407 (void)drive; 1413#ifdef HAVE_MULTIDRIVE
1414 (void)drive;
1415#endif
1408 return true; 1416 return true;
1409} 1417}
1410 1418
1411static int sd1_oneshot_callback(struct timeout *tmo) 1419static int sd_oneshot_callback(struct timeout *tmo)
1412{ 1420{
1413 int state = card_detect_target(SD_SLOT_1); 1421 int slot = (int) tmo->data;
1422 int state = card_detect_target(slot);
1414 1423
1415 /* This is called only if the state was stable for 300ms - check state 1424 /* This is called only if the state was stable for 300ms - check state
1416 * and post appropriate event. */ 1425 * and post appropriate event. */
1417 queue_broadcast(state ? SYS_HOTSWAP_INSERTED : SYS_HOTSWAP_EXTRACTED, 1426 queue_broadcast(state ? SYS_HOTSWAP_INSERTED : SYS_HOTSWAP_EXTRACTED,
1418 0); 1427 sd_drive_nr + slot);
1419 1428
1420 sd_gpio_setup_irq(SD_SLOT_1, state); 1429 sd_gpio_setup_irq(slot, state);
1421 1430
1422 return 0; 1431 return 0;
1423 (void)tmo;
1424}
1425
1426static int sd2_oneshot_callback(struct timeout *tmo)
1427{
1428 int state = card_detect_target(SD_SLOT_2);
1429
1430 /* This is called only if the state was stable for 300ms - check state
1431 * and post appropriate event. */
1432 queue_broadcast(state ? SYS_HOTSWAP_INSERTED : SYS_HOTSWAP_EXTRACTED,
1433 1);
1434
1435 sd_gpio_setup_irq(SD_SLOT_2, state);
1436
1437 return 0;
1438 (void)tmo;
1439} 1432}
1440 1433
1441/* called on insertion/removal interrupt */ 1434/* called on insertion/removal interrupt */
1442void GPIO_SD1_CD(void) 1435void GPIO_SD1_CD(void)
1443{ 1436{
1444 static struct timeout sd1_oneshot; 1437 static struct timeout sd1_oneshot;
1445 timeout_register(&sd1_oneshot, sd1_oneshot_callback, (3*HZ/10), 0); 1438 timeout_register(&sd1_oneshot, sd_oneshot_callback, (3*HZ/10), SD_SLOT_1);
1446} 1439}
1447 1440
1448void GPIO_SD2_CD(void) 1441void GPIO_SD2_CD(void)
1449{ 1442{
1450 static struct timeout sd2_oneshot; 1443 static struct timeout sd2_oneshot;
1451 timeout_register(&sd2_oneshot, sd2_oneshot_callback, (3*HZ/10), 0); 1444 timeout_register(&sd2_oneshot, sd_oneshot_callback, (3*HZ/10), SD_SLOT_2);
1452} 1445}
1453#endif
1454 1446
1455bool sd_present(const int drive) 1447bool sd_present(IF_MD_NONVOID(const int drive))
1456{ 1448{
1449#ifndef HAVE_MULTIDRIVE
1450 const int drive = 0;
1451#endif
1457 return card_detect_target(drive); 1452 return card_detect_target(drive);
1458} 1453}
1454#endif
1459 1455
1460#ifdef CONFIG_STORAGE_MULTI 1456#ifdef CONFIG_STORAGE_MULTI
1461int sd_num_drives(int first_drive) 1457int sd_num_drives(int first_drive)
1462{ 1458{
1463 (void)first_drive; 1459 sd_drive_nr = first_drive;
1464 return NUM_DRIVES; 1460 return NUM_DRIVES;
1465} 1461}
1466#endif /* CONFIG_STORAGE_MULTI */ 1462#endif /* CONFIG_STORAGE_MULTI */
@@ -1478,6 +1474,8 @@ int sd_event(long id, intptr_t data)
1478 * clear if the last attempt to init failed with an error. */ 1474 * clear if the last attempt to init failed with an error. */
1479 mutex_lock(&sd_mtx); /* lock-out card activity */ 1475 mutex_lock(&sd_mtx); /* lock-out card activity */
1480 card[data].initialized = 0; 1476 card[data].initialized = 0;
1477 if (id == SYS_HOTSWAP_INSERTED)
1478 sd_init_device(data);
1481 mutex_unlock(&sd_mtx); 1479 mutex_unlock(&sd_mtx);
1482 break; 1480 break;
1483#endif /* HAVE_HOTSWAP */ 1481#endif /* HAVE_HOTSWAP */