Lines Matching +full:hs400 +full:- +full:cmd +full:- +full:int +full:- +full:delay

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
12 * - Lutz Bichler <Lutz.Bichler@gmail.com>
73 /* The softc holds our per-instance data. */
82 int rtsx_irq_res_id; /* bus IRQ resource id */
86 int rtsx_timeout_cmd; /* interrupt timeout for setup commands */
87 int rtsx_timeout_io; /* interrupt timeout for I/O commands */
97 int rtsx_mem_res_id; /* bus memory resource id */
106 int rtsx_cmd_index; /* index in rtsx_cmd_buffer */
121 int rtsx_pcie_cap; /* PCIe capability offset */
136 uint8_t rtsx_cam_status; /* CAM status - 1 if card in use */
143 bool rtsx_vpclk; /* voltage at Pulse-width Modulation(PWM) clock? */
201 static int rtsx_dma_alloc(struct rtsx_softc *sc);
202 static void rtsx_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error);
206 static void rtsx_card_task(void *arg, int pending __unused);
208 static int rtsx_init(struct rtsx_softc *sc);
209 static int rtsx_map_sd_drive(int index);
210 static int rtsx_rts5227_fill_driving(struct rtsx_softc *sc);
211 static int rtsx_rts5249_fill_driving(struct rtsx_softc *sc);
212 static int rtsx_rts5260_fill_driving(struct rtsx_softc *sc);
213 static int rtsx_read(struct rtsx_softc *, uint16_t, uint8_t *);
214 static int rtsx_read_cfg(struct rtsx_softc *sc, uint8_t func, uint16_t addr, uint32_t *val);
215 static int rtsx_write(struct rtsx_softc *sc, uint16_t addr, uint8_t mask, uint8_t val);
216 static int rtsx_read_phy(struct rtsx_softc *sc, uint8_t addr, uint16_t *val);
217 static int rtsx_write_phy(struct rtsx_softc *sc, uint8_t addr, uint16_t val);
218 static int rtsx_bus_power_off(struct rtsx_softc *sc);
219 static int rtsx_bus_power_on(struct rtsx_softc *sc);
220 static int rtsx_set_bus_width(struct rtsx_softc *sc, enum mmc_bus_width width);
221 static int rtsx_set_sd_timing(struct rtsx_softc *sc, enum mmc_bus_timing timing);
222 static int rtsx_set_sd_clock(struct rtsx_softc *sc, uint32_t freq);
223 static int rtsx_stop_sd_clock(struct rtsx_softc *sc);
224 static int rtsx_switch_sd_clock(struct rtsx_softc *sc, uint8_t clk, uint8_t n, uint8_t div, uint8_t…
229 static int rtsx_sd_tuning_rx_cmd(struct rtsx_softc *sc, uint8_t sample_point);
230 static int rtsx_sd_tuning_rx_cmd_wait(struct rtsx_softc *sc, struct mmc_command *cmd);
234 static int rtsx_sd_get_rx_phase_len(uint32_t phase_map, int start_bit);
237 static int rtsx_led_enable(struct rtsx_softc *sc);
238 static int rtsx_led_disable(struct rtsx_softc *sc);
241 static void rtsx_init_cmd(struct rtsx_softc *sc, struct mmc_command *cmd);
242 static void rtsx_push_cmd(struct rtsx_softc *sc, uint8_t cmd, uint16_t reg,
247 static void rtsx_set_resp(struct rtsx_softc *sc, struct mmc_command *cmd);
251 static int rtsx_send_req(struct rtsx_softc *sc, struct mmc_command *cmd);
252 static int rtsx_xfer_short(struct rtsx_softc *sc, struct mmc_command *cmd);
259 static int rtsx_xfer(struct rtsx_softc *sc, struct mmc_command *cmd);
266 static int rtsx_get_tran_settings(device_t dev, struct ccb_trans_settings_mmc *cts);
267 static int rtsx_set_tran_settings(device_t dev, struct ccb_trans_settings_mmc *cts);
268 static int rtsx_cam_request(device_t dev, union ccb *ccb);
271 static int rtsx_read_ivar(device_t bus, device_t child, int which, uintptr_t *result);
272 static int rtsx_write_ivar(device_t bus, device_t child, int which, uintptr_t value);
274 static int rtsx_mmcbr_update_ios(device_t bus, device_t child __unused);
275 static int rtsx_mmcbr_switch_vccq(device_t bus, device_t child __unused);
276 static int rtsx_mmcbr_request(device_t bus, device_t child __unused, struct mmc_request *req);
278 static int rtsx_mmcbr_tune(device_t bus, device_t child __unused, bool hs400 __unused);
279 static int rtsx_mmcbr_retune(device_t bus, device_t child __unused, bool reset __unused);
280 static int rtsx_mmcbr_get_ro(device_t bus, device_t child __unused);
281 static int rtsx_mmcbr_acquire_host(device_t bus, device_t child __unused);
282 static int rtsx_mmcbr_release_host(device_t bus, device_t child __unused);
285 static int rtsx_probe(device_t dev);
286 static int rtsx_attach(device_t dev);
287 static int rtsx_detach(device_t dev);
288 static int rtsx_shutdown(device_t dev);
289 static int rtsx_suspend(device_t dev);
290 static int rtsx_resume(device_t dev);
292 #define RTSX_LOCK_INIT(_sc) mtx_init(&(_sc)->rtsx_mtx, \
293 device_get_nameunit(sc->rtsx_dev), "rtsx", MTX_DEF)
294 #define RTSX_LOCK(_sc) mtx_lock(&(_sc)->rtsx_mtx)
295 #define RTSX_UNLOCK(_sc) mtx_unlock(&(_sc)->rtsx_mtx)
296 #define RTSX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->rtsx_mtx)
319 (bus_space_read_4((sc)->rtsx_mem_btag, (sc)->rtsx_mem_bhandle, (reg)))
321 (bus_space_write_4((sc)->rtsx_mem_btag, (sc)->rtsx_mem_bhandle, (reg), (val)))
325 int err = rtsx_read((sc), (reg), (val)); \
332 int err = rtsx_write((sc), (reg), 0xff, (val)); \
338 int err = rtsx_write((sc), (reg), (bits), 0); \
345 int err = rtsx_write((sc), (reg), (bits), 0xff);\
352 int err = rtsx_write((sc), (reg), (mask), (bits)); \
366 * and a data bit-mask and value.
387 * CMD13 Send status (32 bits - bit 25: card password protected)
389 * ACMD51 Send SCR (SD CARD Configuration Register - [51:48]: Bus widths supported)
406 static int
409 int error = 0; in rtsx_dma_alloc()
411 error = bus_dma_tag_create(bus_get_dma_tag(sc->rtsx_dev), /* inherit from parent */ in rtsx_dma_alloc()
420 &sc->rtsx_cmd_dma_tag); in rtsx_dma_alloc()
422 device_printf(sc->rtsx_dev, in rtsx_dma_alloc()
423 "Can't create cmd parent DMA tag\n"); in rtsx_dma_alloc()
426 error = bus_dmamem_alloc(sc->rtsx_cmd_dma_tag, /* DMA tag */ in rtsx_dma_alloc()
427 &sc->rtsx_cmd_dmamem, /* will hold the KVA pointer */ in rtsx_dma_alloc()
429 &sc->rtsx_cmd_dmamap); /* DMA map */ in rtsx_dma_alloc()
431 device_printf(sc->rtsx_dev, in rtsx_dma_alloc()
436 error = bus_dmamap_load(sc->rtsx_cmd_dma_tag, /* DMA tag */ in rtsx_dma_alloc()
437 sc->rtsx_cmd_dmamap, /* DMA map */ in rtsx_dma_alloc()
438 sc->rtsx_cmd_dmamem, /* KVA pointer to be mapped */ in rtsx_dma_alloc()
441 &sc->rtsx_cmd_buffer, /* first arg of callback */ in rtsx_dma_alloc()
443 if (error || sc->rtsx_cmd_buffer == 0) { in rtsx_dma_alloc()
444 device_printf(sc->rtsx_dev, in rtsx_dma_alloc()
450 error = bus_dma_tag_create(bus_get_dma_tag(sc->rtsx_dev), /* inherit from parent */ in rtsx_dma_alloc()
459 &sc->rtsx_data_dma_tag); in rtsx_dma_alloc()
461 device_printf(sc->rtsx_dev, in rtsx_dma_alloc()
465 error = bus_dmamem_alloc(sc->rtsx_data_dma_tag, /* DMA tag */ in rtsx_dma_alloc()
466 &sc->rtsx_data_dmamem, /* will hold the KVA pointer */ in rtsx_dma_alloc()
468 &sc->rtsx_data_dmamap); /* DMA map */ in rtsx_dma_alloc()
470 device_printf(sc->rtsx_dev, in rtsx_dma_alloc()
474 error = bus_dmamap_load(sc->rtsx_data_dma_tag, /* DMA tag */ in rtsx_dma_alloc()
475 sc->rtsx_data_dmamap, /* DMA map */ in rtsx_dma_alloc()
476 sc->rtsx_data_dmamem, /* KVA pointer to be mapped */ in rtsx_dma_alloc()
479 &sc->rtsx_data_buffer, /* first arg of callback */ in rtsx_dma_alloc()
481 if (error || sc->rtsx_data_buffer == 0) { in rtsx_dma_alloc()
482 device_printf(sc->rtsx_dev, in rtsx_dma_alloc()
490 bus_dmamem_free(sc->rtsx_data_dma_tag, sc->rtsx_data_dmamem, sc->rtsx_data_dmamap); in rtsx_dma_alloc()
492 bus_dma_tag_destroy(sc->rtsx_data_dma_tag); in rtsx_dma_alloc()
494 bus_dmamap_unload(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamap); in rtsx_dma_alloc()
496 bus_dmamem_free(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamem, sc->rtsx_cmd_dmamap); in rtsx_dma_alloc()
498 bus_dma_tag_destroy(sc->rtsx_cmd_dma_tag); in rtsx_dma_alloc()
504 rtsx_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error) in rtsx_dmamap_cb()
516 if (sc->rtsx_cmd_dma_tag != NULL) { in rtsx_dma_free()
517 if (sc->rtsx_cmd_dmamap != NULL) in rtsx_dma_free()
518 bus_dmamap_unload(sc->rtsx_cmd_dma_tag, in rtsx_dma_free()
519 sc->rtsx_cmd_dmamap); in rtsx_dma_free()
520 if (sc->rtsx_cmd_dmamem != NULL) in rtsx_dma_free()
521 bus_dmamem_free(sc->rtsx_cmd_dma_tag, in rtsx_dma_free()
522 sc->rtsx_cmd_dmamem, in rtsx_dma_free()
523 sc->rtsx_cmd_dmamap); in rtsx_dma_free()
524 sc->rtsx_cmd_dmamap = NULL; in rtsx_dma_free()
525 sc->rtsx_cmd_dmamem = NULL; in rtsx_dma_free()
526 sc->rtsx_cmd_buffer = 0; in rtsx_dma_free()
527 bus_dma_tag_destroy(sc->rtsx_cmd_dma_tag); in rtsx_dma_free()
528 sc->rtsx_cmd_dma_tag = NULL; in rtsx_dma_free()
530 if (sc->rtsx_data_dma_tag != NULL) { in rtsx_dma_free()
531 if (sc->rtsx_data_dmamap != NULL) in rtsx_dma_free()
532 bus_dmamap_unload(sc->rtsx_data_dma_tag, in rtsx_dma_free()
533 sc->rtsx_data_dmamap); in rtsx_dma_free()
534 if (sc->rtsx_data_dmamem != NULL) in rtsx_dma_free()
535 bus_dmamem_free(sc->rtsx_data_dma_tag, in rtsx_dma_free()
536 sc->rtsx_data_dmamem, in rtsx_dma_free()
537 sc->rtsx_data_dmamap); in rtsx_dma_free()
538 sc->rtsx_data_dmamap = NULL; in rtsx_dma_free()
539 sc->rtsx_data_dmamem = NULL; in rtsx_dma_free()
540 sc->rtsx_data_buffer = 0; in rtsx_dma_free()
541 bus_dma_tag_destroy(sc->rtsx_data_dma_tag); in rtsx_dma_free()
542 sc->rtsx_data_dma_tag = NULL; in rtsx_dma_free()
555 enabled = sc->rtsx_intr_enabled; in rtsx_intr()
557 sc->rtsx_intr_status = status; in rtsx_intr()
559 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD) in rtsx_intr()
560 …device_printf(sc->rtsx_dev, "Interrupt handler - enabled: 0x%08x, status: 0x%08x\n", enabled, stat… in rtsx_intr()
566 …device_printf(sc->rtsx_dev, "Spurious interrupt - enabled: 0x%08x, status: 0x%08x\n", enabled, sta… in rtsx_intr()
573 sc->rtsx_read_only = 1; in rtsx_intr()
575 sc->rtsx_read_only = 0; in rtsx_intr()
579 device_printf(sc->rtsx_dev, "Interrupt card inserted/removed\n"); in rtsx_intr()
583 if (sc->rtsx_req == NULL) { in rtsx_intr()
589 sc->rtsx_req->cmd->error = MMC_ERR_NONE; in rtsx_intr()
590 if (sc->rtsx_intr_trans_ok != NULL) in rtsx_intr()
591 sc->rtsx_intr_trans_ok(sc); in rtsx_intr()
594 sc->rtsx_req->cmd->error = MMC_ERR_FAILED; in rtsx_intr()
597 device_printf(sc->rtsx_dev, "CRC error\n"); in rtsx_intr()
598 sc->rtsx_req->cmd->error = MMC_ERR_BADCRC; in rtsx_intr()
600 if (!sc->rtsx_tuning_mode) in rtsx_intr()
601 device_printf(sc->rtsx_dev, "Transfer fail - status: 0x%08x\n", status); in rtsx_intr()
603 if (sc->rtsx_intr_trans_ko != NULL) in rtsx_intr()
604 sc->rtsx_intr_trans_ko(sc); in rtsx_intr()
620 was_present = sc->rtsx_cam_status; in rtsx_handle_card_present()
622 was_present = sc->rtsx_mmc_dev != NULL; in rtsx_handle_card_present()
626 device_printf(sc->rtsx_dev, "Card present\n"); in rtsx_handle_card_present()
628 device_printf(sc->rtsx_dev, "Card absent\n"); in rtsx_handle_card_present()
632 * The delay is to debounce the card insert in rtsx_handle_card_present()
637 &sc->rtsx_card_insert_task, -hz); in rtsx_handle_card_present()
639 taskqueue_enqueue(taskqueue_bus, &sc->rtsx_card_remove_task); in rtsx_handle_card_present()
647 rtsx_card_task(void *arg, int pending __unused)
655 sc->rtsx_flags |= RTSX_F_CARD_PRESENT;
658 if (sc->rtsx_cam_status == 0) {
660 if (sc->rtsx_mmc_dev == NULL) {
662 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
663 device_printf(sc->rtsx_dev, "Card inserted\n");
665 sc->rtsx_read_count = sc->rtsx_write_count = 0;
667 sc->rtsx_cam_status = 1;
668 mmc_cam_sim_discover(&sc->rtsx_mmc_sim);
670 sc->rtsx_mmc_dev = device_add_child(sc->rtsx_dev, "mmc", DEVICE_UNIT_ANY);
671 if (sc->rtsx_mmc_dev == NULL) {
672 device_printf(sc->rtsx_dev, "Adding MMC bus failed\n");
674 device_set_ivars(sc->rtsx_mmc_dev, sc);
675 device_probe_and_attach(sc->rtsx_mmc_dev);
680 sc->rtsx_flags &= ~RTSX_F_CARD_PRESENT;
683 if (sc->rtsx_cam_status != 0) {
685 if (sc->rtsx_mmc_dev != NULL) {
687 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
688 device_printf(sc->rtsx_dev, "Card removed\n");
690 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
691 device_printf(sc->rtsx_dev, "Read count: %" PRIu64 ", write count: %" PRIu64 "\n",
692 sc->rtsx_read_count, sc->rtsx_write_count);
694 sc->rtsx_cam_status = 0;
695 mmc_cam_sim_discover(&sc->rtsx_mmc_sim);
697 if (device_delete_child(sc->rtsx_dev, sc->rtsx_mmc_dev))
698 device_printf(sc->rtsx_dev, "Detaching MMC bus failed\n");
699 sc->rtsx_mmc_dev = NULL;
714 if (sc->rtsx_inversion == 0)
720 static int
725 int error;
727 sc->rtsx_host.host_ocr = RTSX_SUPPORTED_VOLTAGE;
728 sc->rtsx_host.f_min = RTSX_SDCLK_250KHZ;
729 sc->rtsx_host.f_max = RTSX_SDCLK_208MHZ;
730 sc->rtsx_host.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_HSPEED |
733 sc->rtsx_host.caps |= MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104;
734 if (sc->rtsx_device_id == RTSX_RTS5209)
735 sc->rtsx_host.caps |= MMC_CAP_8_BIT_DATA;
736 pci_find_cap(sc->rtsx_dev, PCIY_EXPRESS, &(sc->rtsx_pcie_cap));
741 switch (sc->rtsx_device_id) {
746 sc->rtsx_flags |= RTSX_F_VERSION_C;
752 sc->rtsx_flags |= RTSX_F_VERSION_A;
758 sc->rtsx_flags |= RTSX_F_VERSION_A;
763 sc->rtsx_flags |= RTSX_F_8411B_QFN48;
776 sc->rtsx_card_drive_sel = RTSX_CARD_DRIVE_DEFAULT;
777 switch (sc->rtsx_device_id) {
782 sc->rtsx_card_drive_sel = RTSX_RTS5209_CARD_DRIVE_DEFAULT;
783 sc->rtsx_sd30_drive_sel_3v3 = RTSX_DRIVER_TYPE_D;
784 reg = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG2, 4);
786 sc->rtsx_card_drive_sel = (reg >> 8) & 0x3F;
787 sc->rtsx_sd30_drive_sel_3v3 = reg & 0x07;
788 } else if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) {
789 device_printf(sc->rtsx_dev, "pci_read_config() error - reg: 0x%08x\n", reg);
791 if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
792 device_printf(sc->rtsx_dev, "card_drive_sel: 0x%02x, sd30_drive_sel_3v3: 0x%02x\n",
793 sc->rtsx_card_drive_sel, sc->rtsx_sd30_drive_sel_3v3);
797 sc->rtsx_sd30_drive_sel_3v3 = RTSX_CFG_DRIVER_TYPE_B;
798 reg = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG1, 4);
800 sc->rtsx_card_drive_sel &= 0x3F;
801 sc->rtsx_card_drive_sel |= ((reg >> 25) & 0x01) << 6;
802 reg = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG2, 4);
803 sc->rtsx_sd30_drive_sel_3v3 = (reg >> 5) & 0x03;
805 sc->rtsx_flags |= RTSX_F_REVERSE_SOCKET;
806 } else if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) {
807 device_printf(sc->rtsx_dev, "pci_read_config() error - reg: 0x%08x\n", reg);
809 if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
810 device_printf(sc->rtsx_dev,
812 sc->rtsx_card_drive_sel, sc->rtsx_sd30_drive_sel_3v3,
813 (sc->rtsx_flags & RTSX_F_REVERSE_SOCKET) ? "true" : "false");
816 sc->rtsx_sd30_drive_sel_3v3 = RTSX_DRIVER_TYPE_D;
817 reg = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG1, 4);
819 sc->rtsx_card_drive_sel &= 0x3F;
820 sc->rtsx_card_drive_sel |= ((reg >> 25) & 0x01) << 6;
821 reg = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG2, 4);
822 sc->rtsx_sd30_drive_sel_3v3 = rtsx_map_sd_drive((reg >> 5) & 0x03);
823 } else if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) {
824 device_printf(sc->rtsx_dev, "pci_read_config() error - reg: 0x%08x\n", reg);
826 if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
827 device_printf(sc->rtsx_dev, "card_drive_sel: 0x%02x, sd30_drive_sel_3v3: 0x%02x\n",
828 sc->rtsx_card_drive_sel, sc->rtsx_sd30_drive_sel_3v3);
833 sc->rtsx_sd30_drive_sel_3v3 = RTSX_CFG_DRIVER_TYPE_B;
834 reg = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG1, 4);
836 sc->rtsx_card_drive_sel &= 0x3F;
837 sc->rtsx_card_drive_sel |= ((reg >> 25) & 0x01) << 6;
838 reg = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG2, 4);
839 sc->rtsx_sd30_drive_sel_3v3 = (reg >> 5) & 0x03;
841 sc->rtsx_flags |= RTSX_F_REVERSE_SOCKET;
842 } else if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) {
843 device_printf(sc->rtsx_dev, "pci_read_config() error - reg: 0x%08x\n", reg);
845 if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
846 device_printf(sc->rtsx_dev,
848 sc->rtsx_card_drive_sel, sc->rtsx_sd30_drive_sel_3v3,
849 (sc->rtsx_flags & RTSX_F_REVERSE_SOCKET) ? "true" : "false");
853 sc->rtsx_card_drive_sel = RTSX_RTL8411_CARD_DRIVE_DEFAULT;
854 sc->rtsx_sd30_drive_sel_3v3 = RTSX_DRIVER_TYPE_D;
855 reg1 = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG1, 4);
857 sc->rtsx_card_drive_sel &= 0x3F;
858 sc->rtsx_card_drive_sel |= ((reg1 >> 25) & 0x01) << 6;
859 reg3 = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG3, 1);
860 sc->rtsx_sd30_drive_sel_3v3 = (reg3 >> 5) & 0x07;
861 } else if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) {
862 device_printf(sc->rtsx_dev, "pci_read_config() error - reg1: 0x%08x\n", reg1);
864 if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
865 device_printf(sc->rtsx_dev,
867 sc->rtsx_card_drive_sel, sc->rtsx_sd30_drive_sel_3v3);
870 sc->rtsx_card_drive_sel = RTSX_RTL8411_CARD_DRIVE_DEFAULT;
871 sc->rtsx_sd30_drive_sel_3v3 = RTSX_DRIVER_TYPE_D;
872 reg = pci_read_config(sc->rtsx_dev, RTSX_PCR_SETTING_REG1, 4);
874 sc->rtsx_sd30_drive_sel_3v3 = rtsx_map_sd_drive(reg & 0x03);
875 } else if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) {
876 device_printf(sc->rtsx_dev, "pci_read_config() error - reg: 0x%08x\n", reg);
878 if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
879 device_printf(sc->rtsx_dev,
881 sc->rtsx_card_drive_sel, sc->rtsx_sd30_drive_sel_3v3);
885 if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
886 device_printf(sc->rtsx_dev, "rtsx_init() rtsx_flags: 0x%04x\n", sc->rtsx_flags);
889 sc->rtsx_intr_enabled = RTSX_TRANS_OK_INT_EN | RTSX_TRANS_FAIL_INT_EN | RTSX_SD_INT_EN;
890 WRITE4(sc, RTSX_BIER, sc->rtsx_intr_enabled);
895 DELAY(200);
898 val = pci_read_config(sc->rtsx_dev, sc->rtsx_pcie_cap + PCIER_LINK_CTL, 1);
899 pci_write_config(sc->rtsx_dev, sc->rtsx_pcie_cap + PCIER_LINK_CTL, val & 0xfc, 1);
904 switch (sc->rtsx_device_id) {
924 if (sc->rtsx_flags & RTSX_F_VERSION_A) {
947 if (sc->rtsx_flags & RTSX_F_VERSION_A)
962 DELAY(1000);
1016 RTSX_WRITE(sc, RTSX_CARD_DRIVE_SEL, sc->rtsx_card_drive_sel);
1035 /* Enable interrupt write-clear (default is read-clear). */
1038 switch (sc->rtsx_device_id) {
1049 pci_write_config(sc->rtsx_dev, sc->rtsx_pcie_cap + PCIER_LINK_CTL + 1, 1, 1);
1052 pci_write_config(sc->rtsx_dev, 0x70F, 0x5B, 1);
1057 switch (sc->rtsx_device_id) {
1069 RTSX_WRITE(sc, RTSX_SD30_CMD_DRIVE_SEL, sc->rtsx_sd30_drive_sel_3v3);
1082 cap = pci_read_config(sc->rtsx_dev, sc->rtsx_pcie_cap + PCIER_DEVICE_CTL2, 2);
1091 if (sc->rtsx_flags & RTSX_F_REVERSE_SOCKET)
1113 RTSX_WRITE(sc, RTSX_SD30_CMD_DRIVE_SEL, sc->rtsx_sd30_drive_sel_3v3);
1127 cap = pci_read_config(sc->rtsx_dev, sc->rtsx_pcie_cap + PCIER_DEVICE_CTL2, 2);
1136 if (sc->rtsx_flags & RTSX_F_REVERSE_SOCKET)
1167 if (sc->rtsx_flags & RTSX_F_REVERSE_SOCKET)
1174 if (sc->rtsx_flags & RTSX_F_VERSION_A) {
1206 if (sc->rtsx_flags & RTSX_F_REVERSE_SOCKET)
1230 if (sc->rtsx_flags & RTSX_F_REVERSE_SOCKET)
1245 RTSX_WRITE(sc, RTSX_SD30_CMD_DRIVE_SEL, sc->rtsx_sd30_drive_sel_3v3);
1250 if (sc->rtsx_flags & RTSX_F_8411B_QFN48)
1252 RTSX_WRITE(sc, RTSX_SD30_CMD_DRIVE_SEL, sc->rtsx_sd30_drive_sel_3v3);
1270 static int
1271 rtsx_map_sd_drive(int index)
1284 static int
1293 RTSX_WRITE(sc, RTSX_SD30_CLK_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][0]);
1294 RTSX_WRITE(sc, RTSX_SD30_CMD_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][1]);
1295 RTSX_WRITE(sc, RTSX_SD30_DAT_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][2]);
1301 static int
1310 RTSX_WRITE(sc, RTSX_SD30_CLK_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][0]);
1311 RTSX_WRITE(sc, RTSX_SD30_CMD_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][1]);
1312 RTSX_WRITE(sc, RTSX_SD30_DAT_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][2]);
1317 static int
1326 RTSX_WRITE(sc, RTSX_SD30_CLK_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][0]);
1327 RTSX_WRITE(sc, RTSX_SD30_CMD_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][1]);
1328 RTSX_WRITE(sc, RTSX_SD30_DAT_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][2]);
1333 static int
1336 int tries = 1024;
1343 while (tries--) {
1353 device_printf(sc->rtsx_dev, "rtsx_read(0x%x) timeout\n", arg);
1358 static int
1361 int tries = 1024;
1368 while (tries--) {
1387 static int
1390 int tries = 1024;
1399 while (tries--) {
1403 device_printf(sc->rtsx_dev, "rtsx_write(0x%x) error reg=0x%x\n", arg, reg);
1409 device_printf(sc->rtsx_dev, "rtsx_write(0x%x) timeout\n", arg);
1414 static int
1417 int tries = 100000;
1423 while (tries--) {
1438 static int
1441 int tries = 100000;
1449 while (tries--) {
1463 static int
1466 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
1467 device_printf(sc->rtsx_dev, "rtsx_bus_power_off()\n");
1476 switch (sc->rtsx_device_id) {
1516 switch (sc->rtsx_device_id) {
1529 if (sc->rtsx_flags & RTSX_F_VERSION_C)
1552 if (sc->rtsx_flags & RTSX_F_8411B_QFN48) {
1570 static int
1573 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
1574 device_printf(sc->rtsx_dev, "rtsx_bus_power_on()\n");
1584 switch (sc->rtsx_device_id) {
1597 if (sc->rtsx_flags & RTSX_F_VERSION_C)
1620 if (sc->rtsx_flags & RTSX_F_8411B_QFN48) {
1637 * with a delay in between.
1639 switch (sc->rtsx_device_id) {
1645 DELAY(200);
1657 DELAY(20000);
1671 DELAY(200);
1685 DELAY(5000);
1698 DELAY(20000);
1726 DELAY(150);
1729 DELAY(150);
1732 DELAY(150);
1743 DELAY(200);
1751 static int
1771 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) {
1777 device_printf(sc->rtsx_dev, "Setting bus width to %s\n", busw[bus_width]);
1782 static int
1785 if (timing == bus_timing_hs && sc->rtsx_force_timing) {
1787 sc->rtsx_ios_timing = timing;
1790 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
1791 device_printf(sc->rtsx_dev, "rtsx_set_sd_timing(%u)\n", timing);
1796 sc->rtsx_double_clk = false;
1797 sc->rtsx_vpclk = true;
1837 static int
1842 int error = 0;
1844 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
1845 device_printf(sc->rtsx_dev, "rtsx_set_sd_clock(%u)\n", freq);
1852 sc->rtsx_ssc_depth = RTSX_SSC_DEPTH_500K;
1853 sc->rtsx_discovery_mode = (freq <= 1000000) ? true : false;
1855 if (sc->rtsx_discovery_mode) {
1865 if (sc->rtsx_discovery_mode || !sc->rtsx_double_clk)
1870 switch (sc->rtsx_device_id) {
1874 n = clk * 4 / 5 - 2;
1877 n = clk - 2;
1890 switch (sc->rtsx_device_id) {
1894 n = (((n + 2) * 5 / 4) * 2) * 4 / 5 - 2;
1897 n = (n + 2) * 2 - 2;
1903 if (sc->rtsx_double_clk && sc->rtsx_ssc_depth > 1)
1904 sc->rtsx_ssc_depth -= 1;
1907 if (sc->rtsx_ssc_depth > (div - 1))
1908 sc->rtsx_ssc_depth -= (div - 1);
1910 sc->rtsx_ssc_depth = RTSX_SSC_DEPTH_4M;
1919 static int
1928 static int
1931 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC) {
1932 device_printf(sc->rtsx_dev, "rtsx_switch_sd_clock() - discovery-mode is %s, ssc_depth: %d\n",
1933 (sc->rtsx_discovery_mode) ? "true" : "false", sc->rtsx_ssc_depth);
1934 device_printf(sc->rtsx_dev, "rtsx_switch_sd_clock() - clk: %d, n: %d, div: %d, mcu: %d\n",
1941 RTSX_BITOP(sc, RTSX_SSC_CTL2, RTSX_SSC_DEPTH_MASK, sc->rtsx_ssc_depth);
1944 if (sc->rtsx_vpclk) {
1950 DELAY(200);
1961 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
1962 device_printf(sc->rtsx_dev, "rtsx_sd_change_tx_phase() - sample_point: %d\n", sample_point);
1975 if (sc->rtsx_debug_mask & RTSX_DEBUG_TUNING)
1976 device_printf(sc->rtsx_dev, "rtsx_sd_change_rx_phase() - sample_point: %d\n", sample_point);
1990 int i;
1991 int error;
2002 static int
2006 struct mmc_command cmd = {}; local
2007 int error = 0;
2009 cmd.opcode = MMC_SEND_TUNING_BLOCK;
2010 cmd.arg = 0;
2011 req.cmd = &cmd;
2015 sc->rtsx_req = &req;
2022 rtsx_init_cmd(sc, &cmd);
2033 sc->rtsx_intr_trans_ok = rtsx_sd_tuning_rx_cmd_wakeup;
2034 sc->rtsx_intr_trans_ko = rtsx_sd_tuning_rx_cmd_wakeup;
2039 error = rtsx_sd_tuning_rx_cmd_wait(sc, &cmd);
2042 if (sc->rtsx_debug_mask & RTSX_DEBUG_TUNING)
2043 device_printf(sc->rtsx_dev, "rtsx_sd_tuning_rx_cmd() - error: %d\n", error);
2049 sc->rtsx_req = NULL;
2056 static int
2057 rtsx_sd_tuning_rx_cmd_wait(struct rtsx_softc *sc, struct mmc_command *cmd) argument
2059 int status;
2060 int mask = RTSX_TRANS_OK_INT | RTSX_TRANS_FAIL_INT;
2062 status = sc->rtsx_intr_status & mask;
2064 …if (msleep(&sc->rtsx_intr_status, &sc->rtsx_mtx, 0, "rtsxintr", sc->rtsx_timeout_cmd) == EWOULDBLO…
2065 cmd->error = MMC_ERR_TIMEOUT;
2068 status = sc->rtsx_intr_status & mask;
2070 return (cmd->error);
2076 wakeup(&sc->rtsx_intr_status);
2082 int i;
2089 DELAY(100);
2096 int start = 0, len = 0;
2097 int start_final = 0, len_final = 0;
2111 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
2112 device_printf(sc->rtsx_dev,
2113 …"rtsx_sd_search_final_rx_phase() - phase_map: %x, start_final: %d, len_final: %d, final_phase: %d\…
2119 static int
2120 rtsx_sd_get_rx_phase_len(uint32_t phase_map, int start_bit)
2122 int i;
2133 static int
2136 switch (sc->rtsx_device_id) {
2156 static int
2159 switch (sc->rtsx_device_id) {
2181 int i;
2209 rtsx_init_cmd(struct rtsx_softc *sc, struct mmc_command *cmd) argument
2211 sc->rtsx_cmd_index = 0;
2213 0xff, RTSX_SD_CMD_START | cmd->opcode);
2215 0xff, cmd->arg >> 24);
2217 0xff, cmd->arg >> 16);
2219 0xff, cmd->arg >> 8);
2221 0xff, cmd->arg);
2228 rtsx_push_cmd(struct rtsx_softc *sc, uint8_t cmd, uint16_t reg, argument
2231 KASSERT(sc->rtsx_cmd_index < RTSX_HOSTCMD_MAX,
2232 ("rtsx: Too many host commands (%d)\n", sc->rtsx_cmd_index));
2234 uint32_t *cmd_buffer = (uint32_t *)(sc->rtsx_cmd_dmamem);
2235 cmd_buffer[sc->rtsx_cmd_index++] =
2236 htole32((uint32_t)(cmd & 0x3) << 30) |
2264 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
2265 device_printf(sc->rtsx_dev, "rtsx_send_cmd()\n");
2267 sc->rtsx_intr_status = 0;
2270 bus_dmamap_sync(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamap, BUS_DMASYNC_PREREAD);
2271 bus_dmamap_sync(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamap, BUS_DMASYNC_PREWRITE);
2274 WRITE4(sc, RTSX_HCBAR, (uint32_t)sc->rtsx_cmd_buffer);
2276 ((sc->rtsx_cmd_index * 4) & 0x00ffffff) | RTSX_START_CMD | RTSX_HW_AUTO_RSP);
2291 switch (sc->rtsx_device_id) {
2328 req = sc->rtsx_req;
2329 if (req->cmd->error == MMC_ERR_NONE) {
2330 if (req->cmd->opcode == MMC_READ_SINGLE_BLOCK ||
2331 req->cmd->opcode == MMC_READ_MULTIPLE_BLOCK)
2332 sc->rtsx_read_count++;
2333 else if (req->cmd->opcode == MMC_WRITE_BLOCK ||
2334 req->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)
2335 sc->rtsx_write_count++;
2339 callout_stop(&sc->rtsx_timeout_callout);
2340 sc->rtsx_req = NULL;
2342 ccb = sc->rtsx_ccb;
2343 sc->rtsx_ccb = NULL;
2344 ccb->ccb_h.status = (req->cmd->error == 0 ? CAM_REQ_CMP : CAM_REQ_CMP_ERR);
2347 req->done(req);
2354 static int
2355 rtsx_send_req(struct rtsx_softc *sc, struct mmc_command *cmd) argument
2360 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
2361 device_printf(sc->rtsx_dev, "rtsx_send_req() - CMD%d\n", cmd->opcode);
2364 rsp_type = rtsx_response_type(cmd->flags & MMC_RSP_MASK);
2366 device_printf(sc->rtsx_dev, "Unknown rsp_type: 0x%lx\n", (cmd->flags & MMC_RSP_MASK));
2367 cmd->error = MMC_ERR_INVALID;
2371 rtsx_init_cmd(sc, cmd);
2376 /* Use the ping-pong buffer (cmd buffer) for commands which do not transfer data. */
2389 /* Read data from ping-pong buffer. */
2400 if (sc->rtsx_intr_trans_ok == NULL)
2401 sc->rtsx_intr_trans_ok = rtsx_ret_resp;
2410 * Return response of previous command (case cmd->data == NULL) and complete resquest.
2411 * This Function is called by the interrupt handler via sc->rtsx_intr_trans_ok.
2416 struct mmc_command *cmd; local
2418 cmd = sc->rtsx_req->cmd;
2419 rtsx_set_resp(sc, cmd);
2427 rtsx_set_resp(struct rtsx_softc *sc, struct mmc_command *cmd) argument
2431 rsp_type = rtsx_response_type(cmd->flags & MMC_RSP_MASK);
2434 bus_dmamap_sync(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamap, BUS_DMASYNC_POSTREAD);
2435 bus_dmamap_sync(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamap, BUS_DMASYNC_POSTWRITE);
2438 if (ISSET(cmd->flags, MMC_RSP_PRESENT)) {
2439 uint32_t *cmd_buffer = (uint32_t *)(sc->rtsx_cmd_dmamem);
2441 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD) {
2442 device_printf(sc->rtsx_dev, "cmd_buffer: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
2449 int i;
2452 * The controller offloads the last byte {CRC-7, end bit 1}
2459 cmd->resp[i] = be32dec(ptr + 1 + i * 4);
2463 * one is the command op code -- we skip those.
2465 cmd->resp[0] =
2470 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
2471 device_printf(sc->rtsx_dev, "cmd->resp: 0x%08x 0x%08x 0x%08x 0x%08x\n",
2472 cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
2477 * Use the ping-pong buffer (cmd buffer) for transfer <= 512 bytes.
2479 static int
2480 rtsx_xfer_short(struct rtsx_softc *sc, struct mmc_command *cmd) argument
2482 int read;
2484 if (cmd->data == NULL || cmd->data->len == 0) {
2485 cmd->error = MMC_ERR_INVALID;
2488 cmd->data->xfer_len = (cmd->data->len > RTSX_MAX_DATA_BLKLEN) ?
2489 RTSX_MAX_DATA_BLKLEN : cmd->data->len;
2491 read = ISSET(cmd->data->flags, MMC_DATA_READ);
2493 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
2494 device_printf(sc->rtsx_dev, "rtsx_xfer_short() - %s xfer: %ld bytes with block size %ld\n",
2496 (unsigned long)cmd->data->len, (unsigned long)cmd->data->xfer_len);
2498 if (cmd->data->len > 512) {
2499 device_printf(sc->rtsx_dev, "rtsx_xfer_short() - length too large: %ld > 512\n",
2500 (unsigned long)cmd->data->len);
2501 cmd->error = MMC_ERR_INVALID;
2506 if (sc->rtsx_discovery_mode)
2509 rtsx_init_cmd(sc, cmd);
2512 rtsx_set_cmd_data_len(sc, cmd->data->len / cmd->data->xfer_len, cmd->data->xfer_len);
2519 /* Use the ping-pong buffer (cmd buffer). */
2530 sc->rtsx_intr_trans_ok = rtsx_ask_ppbuf_part1;
2536 sc->rtsx_intr_trans_ok = rtsx_put_ppbuf_part1;
2539 rtsx_send_req(sc, cmd);
2546 * Use the ping-pong buffer (cmd buffer) for the transfer - first part <= 256 bytes.
2547 * This Function is called by the interrupt handler via sc->rtsx_intr_trans_ok.
2552 struct mmc_command *cmd; local
2554 int len;
2555 int i;
2557 cmd = sc->rtsx_req->cmd;
2558 len = (cmd->data->len > RTSX_HOSTCMD_MAX) ? RTSX_HOSTCMD_MAX : cmd->data->len;
2560 sc->rtsx_cmd_index = 0;
2566 sc->rtsx_intr_trans_ok = rtsx_get_ppbuf_part1;
2573 * Get the data from the ping-pong buffer (cmd buffer) - first part <= 256 bytes.
2574 * This Function is called by the interrupt handler via sc->rtsx_intr_trans_ok.
2579 struct mmc_command *cmd; local
2581 int len;
2583 cmd = sc->rtsx_req->cmd;
2584 ptr = cmd->data->data;
2585 len = (cmd->data->len > RTSX_HOSTCMD_MAX) ? RTSX_HOSTCMD_MAX : cmd->data->len;
2588 bus_dmamap_sync(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamap, BUS_DMASYNC_POSTREAD);
2589 bus_dmamap_sync(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamap, BUS_DMASYNC_POSTWRITE);
2591 memcpy(ptr, sc->rtsx_cmd_dmamem, len);
2593 len = (cmd->data->len > RTSX_HOSTCMD_MAX) ? cmd->data->len - RTSX_HOSTCMD_MAX : 0;
2595 /* Use the ping-pong buffer (cmd buffer) for the transfer - second part > 256 bytes. */
2598 int i;
2600 sc->rtsx_cmd_index = 0;
2606 sc->rtsx_intr_trans_ok = rtsx_get_ppbuf_part2;
2611 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD && cmd->opcode == ACMD_SEND_SCR) {
2612 uint8_t *ptr = cmd->data->data;
2613 device_printf(sc->rtsx_dev, "SCR: 0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
2618 if (sc->rtsx_discovery_mode)
2626 * Get the data from the ping-pong buffer (cmd buffer) - second part > 256 bytes.
2627 * This Function is called by the interrupt handler via sc->rtsx_intr_trans_ok.
2632 struct mmc_command *cmd; local
2634 int len;
2636 cmd = sc->rtsx_req->cmd;
2637 ptr = cmd->data->data;
2639 len = cmd->data->len - RTSX_HOSTCMD_MAX;
2642 bus_dmamap_sync(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamap, BUS_DMASYNC_POSTREAD);
2643 bus_dmamap_sync(sc->rtsx_cmd_dma_tag, sc->rtsx_cmd_dmamap, BUS_DMASYNC_POSTWRITE);
2645 memcpy(ptr, sc->rtsx_cmd_dmamem, len);
2647 if (sc->rtsx_discovery_mode)
2654 * Use the ping-pong buffer (cmd buffer) for transfer - first part <= 256 bytes.
2655 * This Function is called by the interrupt handler via sc->rtsx_intr_trans_ok.
2660 struct mmc_command *cmd; local
2663 int len;
2664 int i;
2666 cmd = sc->rtsx_req->cmd;
2667 ptr = cmd->data->data;
2668 len = (cmd->data->len > RTSX_HOSTCMD_MAX) ? RTSX_HOSTCMD_MAX : cmd->data->len;
2670 rtsx_set_resp(sc, cmd);
2672 sc->rtsx_cmd_index = 0;
2679 if (cmd->data->len > RTSX_HOSTCMD_MAX)
2680 sc->rtsx_intr_trans_ok = rtsx_put_ppbuf_part2;
2682 sc->rtsx_intr_trans_ok = rtsx_write_ppbuf;
2689 * Use the ping-pong buffer (cmd buffer) for transfer - second part > 256 bytes.
2690 * This Function is called by the interrupt handler via sc->rtsx_intr_trans_ok.
2695 struct mmc_command *cmd; local
2698 int len;
2699 int i;
2701 cmd = sc->rtsx_req->cmd;
2702 ptr = cmd->data->data;
2704 len = cmd->data->len - RTSX_HOSTCMD_MAX;
2706 sc->rtsx_cmd_index = 0;
2713 sc->rtsx_intr_trans_ok = rtsx_write_ppbuf;
2720 * Write the data previously given via the ping-pong buffer on the card.
2721 * This Function is called by the interrupt handler via sc->rtsx_intr_trans_ok.
2726 struct mmc_command *cmd; local
2728 cmd = sc->rtsx_req->cmd;
2730 sc->rtsx_cmd_index = 0;
2733 rtsx_set_cmd_data_len(sc, cmd->data->len / cmd->data->xfer_len, cmd->data->xfer_len);
2746 sc->rtsx_intr_trans_ok = rtsx_req_done;
2755 static int
2756 rtsx_xfer(struct rtsx_softc *sc, struct mmc_command *cmd) argument
2758 int read = ISSET(cmd->data->flags, MMC_DATA_READ);
2760 cmd->data->xfer_len = (cmd->data->len > RTSX_MAX_DATA_BLKLEN) ?
2761 RTSX_MAX_DATA_BLKLEN : cmd->data->len;
2763 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
2764 device_printf(sc->rtsx_dev, "rtsx_xfer() - %s xfer: %ld bytes with block size %ld\n",
2766 (unsigned long)cmd->data->len, (unsigned long)cmd->data->xfer_len);
2768 if (cmd->data->len > RTSX_DMA_DATA_BUFSIZE) {
2769 device_printf(sc->rtsx_dev, "rtsx_xfer() length too large: %ld > %ld\n",
2770 (unsigned long)cmd->data->len, RTSX_DMA_DATA_BUFSIZE);
2771 cmd->error = MMC_ERR_INVALID;
2777 sc->rtsx_intr_trans_ok = rtsx_xfer_begin;
2780 rtsx_send_req(sc, cmd);
2790 * This Function is called by the interrupt handler via sc->rtsx_intr_trans_ok.
2795 struct mmc_command *cmd; local
2797 cmd = sc->rtsx_req->cmd;
2799 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
2800 device_printf(sc->rtsx_dev, "rtsx_xfer_begin() - CMD%d\n", cmd->opcode);
2802 rtsx_set_resp(sc, cmd);
2812 struct mmc_command *cmd; local
2813 int read;
2815 int dma_dir;
2816 int tmode;
2818 cmd = sc->rtsx_req->cmd;
2819 read = ISSET(cmd->data->flags, MMC_DATA_READ);
2822 if (cmd->opcode == MMC_READ_MULTIPLE_BLOCK)
2831 * CMD 12 manually after read.
2836 rtsx_init_cmd(sc, cmd);
2842 * send CMD 12 manually after writing.
2847 sc->rtsx_cmd_index = 0;
2851 rtsx_set_cmd_data_len(sc, cmd->data->len / cmd->data->xfer_len, cmd->data->xfer_len);
2857 0xff, cmd->data->len >> 24);
2859 0xff, cmd->data->len >> 16);
2861 0xff, cmd->data->len >> 8);
2863 0xff, cmd->data->len);
2885 memcpy(sc->rtsx_data_dmamem, cmd->data->data, cmd->data->len);
2888 bus_dmamap_sync(sc->rtsx_data_dma_tag, sc->rtsx_data_dmamap, BUS_DMASYNC_PREREAD);
2889 bus_dmamap_sync(sc->rtsx_data_dma_tag, sc->rtsx_data_dmamap, BUS_DMASYNC_PREWRITE);
2892 sc->rtsx_intr_trans_ok = rtsx_xfer_finish;
2895 WRITE4(sc, RTSX_HDBAR, sc->rtsx_data_buffer);
2897 (cmd->data->len & 0x00ffffff));
2902 * This Function is called by the interrupt handler via sc->rtsx_intr_trans_ok.
2907 struct mmc_command *cmd; local
2908 int read;
2910 cmd = sc->rtsx_req->cmd;
2912 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
2913 device_printf(sc->rtsx_dev, "rtsx_xfer_finish() - CMD%d\n", cmd->opcode);
2915 read = ISSET(cmd->data->flags, MMC_DATA_READ);
2918 bus_dmamap_sync(sc->rtsx_data_dma_tag, sc->rtsx_data_dmamap, BUS_DMASYNC_POSTREAD);
2919 bus_dmamap_sync(sc->rtsx_data_dma_tag, sc->rtsx_data_dmamap, BUS_DMASYNC_POSTWRITE);
2922 memcpy(cmd->data->data, sc->rtsx_data_dmamem, cmd->data->len);
2927 sc->rtsx_intr_trans_ok = NULL;
2928 rtsx_send_req(sc, sc->rtsx_req->stop);
2941 if (sc->rtsx_req != NULL) {
2942 device_printf(sc->rtsx_dev, "Controller timeout for CMD%u\n",
2943 sc->rtsx_req->cmd->opcode);
2944 sc->rtsx_req->cmd->error = MMC_ERR_TIMEOUT;
2948 device_printf(sc->rtsx_dev, "Controller timeout!\n");
2953 static int
2960 cts->host_ocr = sc->rtsx_host.host_ocr;
2961 cts->host_f_min = sc->rtsx_host.f_min;
2962 cts->host_f_max = sc->rtsx_host.f_max;
2963 cts->host_caps = sc->rtsx_host.caps;
2964 cts->host_max_data = RTSX_DMA_DATA_BUFSIZE / MMC_SECTOR_SIZE;
2965 memcpy(&cts->ios, &sc->rtsx_host.ios, sizeof(struct mmc_ios));
2973 static int
2982 ios = &sc->rtsx_host.ios;
2983 new_ios = &cts->ios;
2986 if (cts->ios_valid & MMC_CLK) {
2987 ios->clock = new_ios->clock;
2988 sc->rtsx_ios_clock = -1; /* To be updated by rtsx_mmcbr_update_ios(). */
2989 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
2990 device_printf(sc->rtsx_dev, "rtsx_set_tran_settings() - clock: %u\n", ios->clock);
2992 if (cts->ios_valid & MMC_VDD) {
2993 ios->vdd = new_ios->vdd;
2994 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
2995 device_printf(sc->rtsx_dev, "rtsx_set_tran_settings() - vdd: %d\n", ios->vdd);
2997 if (cts->ios_valid & MMC_CS) {
2998 ios->chip_select = new_ios->chip_select;
2999 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
3000 device_printf(sc->rtsx_dev, "rtsx_set_tran_settings() - chip_select: %d\n", ios->chip_select);
3002 if (cts->ios_valid & MMC_BW) {
3003 ios->bus_width = new_ios->bus_width;
3004 sc->rtsx_ios_bus_width = -1; /* To be updated by rtsx_mmcbr_update_ios(). */
3005 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
3006 device_printf(sc->rtsx_dev, "rtsx_set_tran_settings() - bus width: %d\n", ios->bus_width);
3008 if (cts->ios_valid & MMC_PM) {
3009 ios->power_mode = new_ios->power_mode;
3010 sc->rtsx_ios_power_mode = -1; /* To be updated by rtsx_mmcbr_update_ios(). */
3011 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
3012 device_printf(sc->rtsx_dev, "rtsx_set_tran_settings() - power mode: %d\n", ios->power_mode);
3014 if (cts->ios_valid & MMC_BT) {
3015 ios->timing = new_ios->timing;
3016 sc->rtsx_ios_timing = -1; /* To be updated by rtsx_mmcbr_update_ios(). */
3017 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
3018 device_printf(sc->rtsx_dev, "rtsx_set_tran_settings() - timing: %d\n", ios->timing);
3020 if (cts->ios_valid & MMC_BM) {
3021 ios->bus_mode = new_ios->bus_mode;
3022 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
3023 device_printf(sc->rtsx_dev, "rtsx_set_tran_settings() - bus mode: %d\n", ios->bus_mode);
3026 if (cts->ios_valid & MMC_VCCQ) {
3027 ios->vccq = new_ios->vccq;
3028 sc->rtsx_ios_vccq = -1; /* To be updated by rtsx_mmcbr_update_ios(). */
3029 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
3030 device_printf(sc->rtsx_dev, "rtsx_set_tran_settings() - vccq: %d\n", ios->vccq);
3033 if (rtsx_mmcbr_update_ios(sc->rtsx_dev, NULL) == 0)
3042 static int
3050 if (sc->rtsx_ccb != NULL) {
3054 sc->rtsx_ccb = ccb;
3055 sc->rtsx_cam_req.cmd = &ccb->mmcio.cmd;
3056 sc->rtsx_cam_req.stop = &ccb->mmcio.stop;
3059 rtsx_mmcbr_request(sc->rtsx_dev, NULL, &sc->rtsx_cam_req);
3064 static int
3065 rtsx_read_ivar(device_t bus, device_t child, int which, uintptr_t *result)
3071 case MMCBR_IVAR_BUS_MODE: /* ivar 0 - 1 = opendrain, 2 = pushpull */
3072 *result = sc->rtsx_host.ios.bus_mode;
3074 case MMCBR_IVAR_BUS_WIDTH: /* ivar 1 - 0 = 1b 2 = 4b, 3 = 8b */
3075 *result = sc->rtsx_host.ios.bus_width;
3077 case MMCBR_IVAR_CHIP_SELECT: /* ivar 2 - O = dontcare, 1 = cs_high, 2 = cs_low */
3078 *result = sc->rtsx_host.ios.chip_select;
3080 case MMCBR_IVAR_CLOCK: /* ivar 3 - clock in Hz */
3081 *result = sc->rtsx_host.ios.clock;
3084 *result = sc->rtsx_host.f_min;
3087 *result = sc->rtsx_host.f_max;
3089 case MMCBR_IVAR_HOST_OCR: /* ivar 6 - host operation conditions register */
3090 *result = sc->rtsx_host.host_ocr;
3092 case MMCBR_IVAR_MODE: /* ivar 7 - 0 = mode_mmc, 1 = mode_sd */
3093 *result = sc->rtsx_host.mode;
3095 case MMCBR_IVAR_OCR: /* ivar 8 - operation conditions register */
3096 *result = sc->rtsx_host.ocr;
3098 case MMCBR_IVAR_POWER_MODE: /* ivar 9 - 0 = off, 1 = up, 2 = on */
3099 *result = sc->rtsx_host.ios.power_mode;
3101 case MMCBR_IVAR_VDD: /* ivar 11 - voltage power pin */
3102 *result = sc->rtsx_host.ios.vdd;
3104 case MMCBR_IVAR_VCCQ: /* ivar 12 - signaling: 0 = 1.20V, 1 = 1.80V, 2 = 3.30V */
3105 *result = sc->rtsx_host.ios.vccq;
3108 *result = sc->rtsx_host.caps;
3110 case MMCBR_IVAR_TIMING: /* ivar 14 - 0 = normal, 1 = timing_hs, ... */
3111 *result = sc->rtsx_host.ios.timing;
3122 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
3124 which, *(int *)result, *(int *)result);
3129 static int
3130 rtsx_write_ivar(device_t bus, device_t child, int which, uintptr_t value)
3135 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
3137 which, (int)value, (int)value);
3140 case MMCBR_IVAR_BUS_MODE: /* ivar 0 - 1 = opendrain, 2 = pushpull */
3141 sc->rtsx_host.ios.bus_mode = value;
3143 case MMCBR_IVAR_BUS_WIDTH: /* ivar 1 - 0 = 1b 2 = 4b, 3 = 8b */
3144 sc->rtsx_host.ios.bus_width = value;
3145 sc->rtsx_ios_bus_width = -1; /* To be updated on next rtsx_mmcbr_update_ios(). */
3147 case MMCBR_IVAR_CHIP_SELECT: /* ivar 2 - O = dontcare, 1 = cs_high, 2 = cs_low */
3148 sc->rtsx_host.ios.chip_select = value;
3150 case MMCBR_IVAR_CLOCK: /* ivar 3 - clock in Hz */
3151 sc->rtsx_host.ios.clock = value;
3152 sc->rtsx_ios_clock = -1; /* To be updated on next rtsx_mmcbr_update_ios(). */
3154 case MMCBR_IVAR_MODE: /* ivar 7 - 0 = mode_mmc, 1 = mode_sd */
3155 sc->rtsx_host.mode = value;
3157 case MMCBR_IVAR_OCR: /* ivar 8 - operation conditions register */
3158 sc->rtsx_host.ocr = value;
3160 case MMCBR_IVAR_POWER_MODE: /* ivar 9 - 0 = off, 1 = up, 2 = on */
3161 sc->rtsx_host.ios.power_mode = value;
3162 sc->rtsx_ios_power_mode = -1; /* To be updated on next rtsx_mmcbr_update_ios(). */
3164 case MMCBR_IVAR_VDD: /* ivar 11 - voltage power pin */
3165 sc->rtsx_host.ios.vdd = value;
3167 case MMCBR_IVAR_VCCQ: /* ivar 12 - signaling: 0 = 1.20V, 1 = 1.80V, 2 = 3.30V */
3168 sc->rtsx_host.ios.vccq = value;
3169 sc->rtsx_ios_vccq = value; /* rtsx_mmcbr_switch_vccq() will be called by mmc.c (MMCCAM undef). */
3171 case MMCBR_IVAR_TIMING: /* ivar 14 - 0 = normal, 1 = timing_hs, ... */
3172 sc->rtsx_host.ios.timing = value;
3173 sc->rtsx_ios_timing = -1; /* To be updated on next rtsx_mmcbr_update_ios(). */
3175 /* These are read-only. */
3178 case MMCBR_IVAR_HOST_OCR: /* ivar 6 - host operation conditions register */
3190 static int
3195 int error;
3198 ios = &sc->rtsx_host.ios;
3200 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
3204 if (sc->rtsx_ios_bus_width < 0) {
3205 sc->rtsx_ios_bus_width = ios->bus_width;
3206 if ((error = rtsx_set_bus_width(sc, ios->bus_width)))
3211 if (sc->rtsx_ios_power_mode < 0) {
3212 sc->rtsx_ios_power_mode = ios->power_mode;
3213 switch (ios->power_mode) {
3229 sc->rtsx_double_clk = true;
3230 sc->rtsx_vpclk = false;
3233 if (sc->rtsx_ios_timing < 0) {
3234 sc->rtsx_ios_timing = ios->timing;
3235 if ((error = rtsx_set_sd_timing(sc, ios->timing)))
3240 if (sc->rtsx_ios_clock < 0) {
3241 sc->rtsx_ios_clock = ios->clock;
3242 if ((error = rtsx_set_sd_clock(sc, ios->clock)))
3247 if (sc->rtsx_ios_vccq < 0) {
3248 sc->rtsx_ios_vccq = ios->vccq;
3249 if ((error = rtsx_mmcbr_switch_vccq(sc->rtsx_dev, NULL)))
3259 static int
3263 int vccq = 0;
3264 int error;
3268 switch (sc->rtsx_host.ios.vccq) {
3281 switch (sc->rtsx_device_id) {
3291 RTSX_BITOP(sc, RTSX_SD30_CMD_DRIVE_SEL, RTSX_SD30_DRIVE_SEL_MASK, sc->rtsx_sd30_drive_sel_3v3);
3324 RTSX_BITOP(sc, RTSX_SD30_CMD_DRIVE_SEL, RTSX_SD30_DRIVE_SEL_MASK, sc->rtsx_sd30_drive_sel_3v3);
3331 RTSX_BITOP(sc, RTSX_SD30_CMD_DRIVE_SEL, RTSX_SD30_DRIVE_SEL_MASK, sc->rtsx_sd30_drive_sel_3v3);
3337 DELAY(300);
3340 if (sc->rtsx_debug_mask & (RTSX_DEBUG_BASIC | RTSX_TRACE_SD_CMD))
3341 device_printf(sc->rtsx_dev, "rtsx_mmcbr_switch_vccq(%d)\n", vccq);
3350 static int
3351 rtsx_mmcbr_tune(device_t bus, device_t child __unused, bool hs400) argument
3357 int i;
3361 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
3362 device_printf(sc->rtsx_dev, "rtsx_mmcbr_tune() - hs400 is %s\n",
3363 (hs400) ? "true" : "false");
3365 if (sc->rtsx_ios_timing != bus_timing_uhs_sdr50)
3368 sc->rtsx_tuning_mode = true;
3370 switch (sc->rtsx_device_id) {
3401 if (sc->rtsx_debug_mask & (RTSX_DEBUG_BASIC | RTSX_DEBUG_TUNING))
3402 device_printf(sc->rtsx_dev, "rtsx_mmcbr_tune() - RX raw_phase_map[%d]: 0x%08x\n",
3406 if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
3407 device_printf(sc->rtsx_dev, "rtsx_mmcbr_tune() - RX phase_map: 0x%08x\n", phase_map);
3416 sc->rtsx_tuning_mode = false;
3421 static int
3428 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
3429 device_printf(sc->rtsx_dev, "rtsx_mmcbr_retune()\n");
3435 static int
3439 struct mmc_command *cmd; local
3440 int timeout;
3441 int error;
3446 if (sc->rtsx_req != NULL) {
3450 sc->rtsx_req = req;
3451 cmd = req->cmd;
3452 cmd->error = error = MMC_ERR_NONE;
3453 sc->rtsx_intr_status = 0;
3454 sc->rtsx_intr_trans_ok = NULL;
3455 sc->rtsx_intr_trans_ko = rtsx_req_done;
3457 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
3458 device_printf(sc->rtsx_dev, "rtsx_mmcbr_request(CMD%u arg %#x, flags %#x, dlen %u, dflags %#x)\n",
3459 cmd->opcode, cmd->arg, cmd->flags,
3460 cmd->data != NULL ? (unsigned int)cmd->data->len : 0,
3461 cmd->data != NULL ? cmd->data->flags : 0);
3464 if (!ISSET(sc->rtsx_flags, RTSX_F_CARD_PRESENT)) {
3465 cmd->error = error = MMC_ERR_FAILED;
3470 if (cmd->opcode == IO_SEND_OP_COND &&
3471 !ISSET(sc->rtsx_flags, RTSX_F_SDIO_SUPPORT)) {
3472 cmd->error = error = MMC_ERR_INVALID;
3477 if (cmd->opcode == SD_IO_RW_DIRECT || cmd->opcode == IO_SEND_OP_COND) {
3478 cmd->error = error = MMC_ERR_TIMEOUT;
3486 if (cmd->data == NULL) {
3487 DELAY(200);
3488 timeout = sc->rtsx_timeout_cmd;
3489 error = rtsx_send_req(sc, cmd);
3490 } else if (cmd->data->len <= 512) {
3491 timeout = sc->rtsx_timeout_io;
3492 error = rtsx_xfer_short(sc, cmd);
3494 timeout = sc->rtsx_timeout_io;
3495 error = rtsx_xfer(sc, cmd);
3499 callout_reset(&sc->rtsx_timeout_callout, timeout * hz, rtsx_timeout, sc);
3509 static int
3516 if (sc->rtsx_inversion == 0)
3517 return (sc->rtsx_read_only);
3519 return !(sc->rtsx_read_only);
3522 static int
3528 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
3532 while (sc->rtsx_bus_busy)
3533 msleep(&sc->rtsx_bus_busy, &sc->rtsx_mtx, 0, "rtsxah", 0);
3534 sc->rtsx_bus_busy++;
3540 static int
3546 if (sc->rtsx_debug_mask & RTSX_TRACE_SD_CMD)
3550 sc->rtsx_bus_busy--;
3551 wakeup(&sc->rtsx_bus_busy);
3568 static int
3573 int i;
3592 static int
3600 int msi_count = 1;
3602 int error;
3606 int i;
3611 device_printf(dev, "Attach - Vendor ID: 0x%x - Device ID: 0x%x\n",
3614 sc->rtsx_dev = dev;
3615 sc->rtsx_device_id = device_id;
3616 sc->rtsx_req = NULL;
3617 sc->rtsx_timeout_cmd = 1;
3618 sc->rtsx_timeout_io = 10;
3619 sc->rtsx_read_only = 0;
3620 sc->rtsx_inversion = 0;
3621 sc->rtsx_force_timing = 0;
3622 sc->rtsx_debug_mask = 0;
3623 sc->rtsx_read_count = 0;
3624 sc->rtsx_write_count = 0;
3636 sc->rtsx_inversion = 1;
3646 &sc->rtsx_timeout_io, 0, "Request timeout for I/O commands in seconds");
3648 &sc->rtsx_timeout_cmd, 0, "Request timeout for setup commands in seconds");
3650 &sc->rtsx_read_only, 0, "Card is write protected");
3652 &sc->rtsx_inversion, 0, "Inversion of card detection and read only status");
3654 &sc->rtsx_force_timing, 0, "Force bus_timing_uhs_sdr50");
3656 &sc->rtsx_debug_mask, 0, "debugging mask, see rtsx(4)");
3658 &sc->rtsx_read_count, 0, "Count of read operations");
3660 &sc->rtsx_write_count, 0, "Count of write operations");
3662 if (bootverbose || sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
3663 device_printf(dev, "We are running with inversion: %d\n", sc->rtsx_inversion);
3666 sc->rtsx_irq_res_id = 0;
3668 sc->rtsx_irq_res_id = 1;
3669 sc->rtsx_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->rtsx_irq_res_id,
3670 RF_ACTIVE | (sc->rtsx_irq_res_id != 0 ? 0 : RF_SHAREABLE));
3671 if (sc->rtsx_irq_res == NULL) {
3672 device_printf(dev, "Can't allocate IRQ resources for %d\n", sc->rtsx_irq_res_id);
3677 callout_init_mtx(&sc->rtsx_timeout_callout, &sc->rtsx_mtx, 0);
3680 if (sc->rtsx_device_id == RTSX_RTS525A)
3681 sc->rtsx_mem_res_id = PCIR_BAR(1);
3683 sc->rtsx_mem_res_id = PCIR_BAR(0);
3684 sc->rtsx_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->rtsx_mem_res_id, RF_ACTIVE);
3685 if (sc->rtsx_mem_res == NULL) {
3686 device_printf(dev, "Can't allocate memory resource for %d\n", sc->rtsx_mem_res_id);
3692 sc->rtsx_irq_res_id, sc->rtsx_mem_res_id);
3694 sc->rtsx_mem_btag = rman_get_bustag(sc->rtsx_mem_res);
3695 sc->rtsx_mem_bhandle = rman_get_bushandle(sc->rtsx_mem_res);
3697 TIMEOUT_TASK_INIT(taskqueue_bus, &sc->rtsx_card_insert_task, 0,
3699 TASK_INIT(&sc->rtsx_card_remove_task, 0, rtsx_card_task, sc);
3707 error = bus_setup_intr(dev, sc->rtsx_irq_res, INTR_TYPE_MISC | INTR_MPSAFE,
3708 NULL, rtsx_intr, sc, &sc->rtsx_irq_cookie);
3718 sc->rtsx_flags |= RTSX_F_SDIO_SUPPORT;
3722 sc->rtsx_ccb = NULL;
3723 sc->rtsx_cam_status = 0;
3726 &sc->rtsx_cam_status, 0, "driver cam card present");
3728 if (mmc_cam_sim_alloc(dev, "rtsx_mmc", &sc->rtsx_mmc_sim) != 0) {
3745 * change the card presence state. This delay avoid a panic
3748 DELAY(250000);
3750 device_printf(sc->rtsx_dev, "A card is detected\n");
3752 device_printf(sc->rtsx_dev, "No card is detected\n");
3761 bus_teardown_intr(dev, sc->rtsx_irq_res, sc->rtsx_irq_cookie);
3763 bus_release_resource(dev, SYS_RES_MEMORY, sc->rtsx_mem_res_id,
3764 sc->rtsx_mem_res);
3767 callout_drain(&sc->rtsx_timeout_callout);
3768 bus_release_resource(dev, SYS_RES_IRQ, sc->rtsx_irq_res_id,
3769 sc->rtsx_irq_res);
3776 static int
3780 int error;
3783 device_printf(dev, "Detach - Vendor ID: 0x%x - Device ID: 0x%x\n",
3784 pci_get_vendor(dev), sc->rtsx_device_id);
3787 sc->rtsx_intr_enabled = 0;
3788 WRITE4(sc, RTSX_BIER, sc->rtsx_intr_enabled);
3791 error = bus_generic_detach(sc->rtsx_dev);
3794 sc->rtsx_mmc_dev = NULL;
3796 taskqueue_drain_timeout(taskqueue_bus, &sc->rtsx_card_insert_task);
3797 taskqueue_drain(taskqueue_bus, &sc->rtsx_card_remove_task);
3801 if (sc->rtsx_mem_res != NULL)
3802 bus_release_resource(dev, SYS_RES_MEMORY, sc->rtsx_mem_res_id,
3803 sc->rtsx_mem_res);
3804 if (sc->rtsx_irq_cookie != NULL)
3805 bus_teardown_intr(dev, sc->rtsx_irq_res, sc->rtsx_irq_cookie);
3806 if (sc->rtsx_irq_res != NULL) {
3807 callout_drain(&sc->rtsx_timeout_callout);
3808 bus_release_resource(dev, SYS_RES_IRQ, sc->rtsx_irq_res_id,
3809 sc->rtsx_irq_res);
3814 mmc_cam_sim_free(&sc->rtsx_mmc_sim);
3820 static int
3832 static int
3840 if (sc->rtsx_ccb != NULL) {
3841 device_printf(dev, "Request in progress: CMD%u, rtsr_intr_status: 0x%08x\n",
3842 sc->rtsx_ccb->mmcio.cmd.opcode, sc->rtsx_intr_status);
3845 if (sc->rtsx_req != NULL) {
3846 device_printf(dev, "Request in progress: CMD%u, rtsr_intr_status: 0x%08x\n",
3847 sc->rtsx_req->cmd->opcode, sc->rtsx_intr_status);
3859 static int