diff --git a/sys/dev/rtsx/rtsx.c b/sys/dev/rtsx/rtsx.c --- a/sys/dev/rtsx/rtsx.c +++ b/sys/dev/rtsx/rtsx.c @@ -640,6 +640,7 @@ } } +#ifdef MMCCAM /* * This function is called at startup. */ @@ -651,19 +652,49 @@ if (rtsx_is_card_present(sc)) { sc->rtsx_flags |= RTSX_F_CARD_PRESENT; /* Card is present, attach if necessary. */ -#ifdef MMCCAM if (sc->rtsx_cam_status == 0) { -#else /* !MMCCAM */ - if (sc->rtsx_mmc_dev == NULL) { -#endif /* MMCCAM */ if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) device_printf(sc->rtsx_dev, "Card inserted\n"); sc->rtsx_read_count = sc->rtsx_write_count = 0; -#ifdef MMCCAM sc->rtsx_cam_status = 1; mmc_cam_sim_discover(&sc->rtsx_mmc_sim); -#else /* !MMCCAM */ + } + } else { + sc->rtsx_flags &= ~RTSX_F_CARD_PRESENT; + /* Card isn't present, detach if necessary. */ + if (sc->rtsx_cam_status != 0) { + if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) + device_printf(sc->rtsx_dev, "Card removed\n"); + + if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) + device_printf(sc->rtsx_dev, "Read count: %jx, write count: %jx\n", + (uintmax_t)sc->rtsx_read_count, + (uintmax_t)sc->rtsx_write_count); + sc->rtsx_cam_status = 0; + mmc_cam_sim_discover(&sc->rtsx_mmc_sim); + } + } +} + +#else /* !MMCCAM */ + +/* + * This function is called at startup. + */ +static void +rtsx_card_task(void *arg, int pending __unused) +{ + struct rtsx_softc *sc = arg; + + if (rtsx_is_card_present(sc)) { + sc->rtsx_flags |= RTSX_F_CARD_PRESENT; + /* Card is present, attach if necessary. */ + if (sc->rtsx_mmc_dev == NULL) { + if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) + device_printf(sc->rtsx_dev, "Card inserted\n"); + + sc->rtsx_read_count = sc->rtsx_write_count = 0; RTSX_LOCK(sc); sc->rtsx_mmc_dev = device_add_child(sc->rtsx_dev, "mmc", DEVICE_UNIT_ANY); RTSX_UNLOCK(sc); @@ -673,33 +704,25 @@ device_set_ivars(sc->rtsx_mmc_dev, sc); device_probe_and_attach(sc->rtsx_mmc_dev); } -#endif /* MMCCAM */ } } else { sc->rtsx_flags &= ~RTSX_F_CARD_PRESENT; /* Card isn't present, detach if necessary. */ -#ifdef MMCCAM - if (sc->rtsx_cam_status != 0) { -#else /* !MMCCAM */ if (sc->rtsx_mmc_dev != NULL) { -#endif /* MMCCAM */ if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) device_printf(sc->rtsx_dev, "Card removed\n"); if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) - device_printf(sc->rtsx_dev, "Read count: %" PRIu64 ", write count: %" PRIu64 "\n", - sc->rtsx_read_count, sc->rtsx_write_count); -#ifdef MMCCAM - sc->rtsx_cam_status = 0; - mmc_cam_sim_discover(&sc->rtsx_mmc_sim); -#else /* !MMCCAM */ + device_printf(sc->rtsx_dev, "Read count: %jx, write count: %jx\n", + (uintmax_t)sc->rtsx_read_count, + (uintmax_t)sc->rtsx_write_count); if (device_delete_child(sc->rtsx_dev, sc->rtsx_mmc_dev)) device_printf(sc->rtsx_dev, "Detaching MMC bus failed\n"); sc->rtsx_mmc_dev = NULL; -#endif /* MMCCAM */ } } } +#endif /* MMCCAM */ static bool rtsx_is_card_present(struct rtsx_softc *sc)