rtsx.c (5bdf58e196096993758b3e50291db17104025b65) | rtsx.c (9d3bc163825415f900d06d62efdf02caaad2d51d) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> 5 * Copyright (c) 2012 Stefan Sperling <stsp@openbsd.org> 6 * Copyright (c) 2020 Henri Hennebert <hlh@restart.be> 7 * Copyright (c) 2020 Gary Jennejohn <gj@freebsd.org> 8 * Copyright (c) 2020 Jesper Schmitz Mouridsen <jsm@FreeBSD.org> --- 33 unchanged lines hidden (view full) --- 42#include <sys/systm.h> /* For FreeBSD 11 */ 43#include <sys/types.h> /* For FreeBSD 11 */ 44#include <sys/errno.h> 45#include <sys/kernel.h> 46#include <sys/bus.h> 47#include <sys/endian.h> 48#include <machine/bus.h> 49#include <sys/mutex.h> | 1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> 5 * Copyright (c) 2012 Stefan Sperling <stsp@openbsd.org> 6 * Copyright (c) 2020 Henri Hennebert <hlh@restart.be> 7 * Copyright (c) 2020 Gary Jennejohn <gj@freebsd.org> 8 * Copyright (c) 2020 Jesper Schmitz Mouridsen <jsm@FreeBSD.org> --- 33 unchanged lines hidden (view full) --- 42#include <sys/systm.h> /* For FreeBSD 11 */ 43#include <sys/types.h> /* For FreeBSD 11 */ 44#include <sys/errno.h> 45#include <sys/kernel.h> 46#include <sys/bus.h> 47#include <sys/endian.h> 48#include <machine/bus.h> 49#include <sys/mutex.h> |
50#include <sys/malloc.h> |
|
50#include <sys/rman.h> 51#include <sys/queue.h> 52#include <sys/taskqueue.h> 53#include <sys/sysctl.h> 54#include <dev/pci/pcivar.h> 55#include <dev/pci/pcireg.h> 56#include <dev/mmc/bridge.h> 57#include <dev/mmc/mmcreg.h> --- 20 unchanged lines hidden (view full) --- 78 uint16_t rtsx_device_id; /* device ID */ 79 device_t rtsx_mmc_dev; /* device of mmc bus */ 80 uint32_t rtsx_intr_enabled; /* enabled interrupts */ 81 uint32_t rtsx_intr_status; /* soft interrupt status */ 82 int rtsx_irq_res_id; /* bus IRQ resource id */ 83 struct resource *rtsx_irq_res; /* bus IRQ resource */ 84 void *rtsx_irq_cookie; /* bus IRQ resource cookie */ 85 struct callout rtsx_timeout_callout; /* callout for timeout */ | 51#include <sys/rman.h> 52#include <sys/queue.h> 53#include <sys/taskqueue.h> 54#include <sys/sysctl.h> 55#include <dev/pci/pcivar.h> 56#include <dev/pci/pcireg.h> 57#include <dev/mmc/bridge.h> 58#include <dev/mmc/mmcreg.h> --- 20 unchanged lines hidden (view full) --- 79 uint16_t rtsx_device_id; /* device ID */ 80 device_t rtsx_mmc_dev; /* device of mmc bus */ 81 uint32_t rtsx_intr_enabled; /* enabled interrupts */ 82 uint32_t rtsx_intr_status; /* soft interrupt status */ 83 int rtsx_irq_res_id; /* bus IRQ resource id */ 84 struct resource *rtsx_irq_res; /* bus IRQ resource */ 85 void *rtsx_irq_cookie; /* bus IRQ resource cookie */ 86 struct callout rtsx_timeout_callout; /* callout for timeout */ |
86 int rtsx_timeout; /* interrupt timeout value */ | 87 int rtsx_timeout_cmd; /* interrupt timeout for setup commands */ 88 int rtsx_timeout_io; /* interrupt timeout for I/O commands */ |
87 void (*rtsx_intr_trans_ok)(struct rtsx_softc *sc); 88 /* function to call if transfer succeed */ 89 void (*rtsx_intr_trans_ko)(struct rtsx_softc *sc); 90 /* function to call if transfer fail */ | 89 void (*rtsx_intr_trans_ok)(struct rtsx_softc *sc); 90 /* function to call if transfer succeed */ 91 void (*rtsx_intr_trans_ko)(struct rtsx_softc *sc); 92 /* function to call if transfer fail */ |
93 |
|
91 struct timeout_task 92 rtsx_card_insert_task; /* card insert delayed task */ 93 struct task rtsx_card_remove_task; /* card remove task */ 94 95 int rtsx_res_id; /* bus memory resource id */ 96 struct resource *rtsx_res; /* bus memory resource */ 97 int rtsx_res_type; /* bus memory resource type */ 98 bus_space_tag_t rtsx_btag; /* host register set tag */ --- 62 unchanged lines hidden (view full) --- 161#define RTSX_RTS5229 0x5229 162#define RTSX_RTS522A 0x522a 163#define RTSX_RTS525A 0x525a 164#define RTSX_RTS5249 0x5249 165#define RTSX_RTL8402 0x5286 166#define RTSX_RTL8411 0x5289 167#define RTSX_RTL8411B 0x5287 168 | 94 struct timeout_task 95 rtsx_card_insert_task; /* card insert delayed task */ 96 struct task rtsx_card_remove_task; /* card remove task */ 97 98 int rtsx_res_id; /* bus memory resource id */ 99 struct resource *rtsx_res; /* bus memory resource */ 100 int rtsx_res_type; /* bus memory resource type */ 101 bus_space_tag_t rtsx_btag; /* host register set tag */ --- 62 unchanged lines hidden (view full) --- 164#define RTSX_RTS5229 0x5229 165#define RTSX_RTS522A 0x522a 166#define RTSX_RTS525A 0x525a 167#define RTSX_RTS5249 0x5249 168#define RTSX_RTL8402 0x5286 169#define RTSX_RTL8411 0x5289 170#define RTSX_RTL8411B 0x5287 171 |
169#define RTSX_VERSION "2.0c" | 172#define RTSX_VERSION "2.0i" |
170 171static const struct rtsx_device { 172 uint16_t vendor_id; 173 uint16_t device_id; 174 const char *desc; 175} rtsx_devices[] = { | 173 174static const struct rtsx_device { 175 uint16_t vendor_id; 176 uint16_t device_id; 177 const char *desc; 178} rtsx_devices[] = { |
176 { RTSX_REALTEK, RTSX_RTS5209, RTSX_VERSION " Realtek RTS5209 PCI MMC/SD Card Reader"}, 177 { RTSX_REALTEK, RTSX_RTS5227, RTSX_VERSION " Realtek RTS5227 PCI MMC/SD Card Reader"}, 178 { RTSX_REALTEK, RTSX_RTS5229, RTSX_VERSION " Realtek RTS5229 PCI MMC/SD Card Reader"}, 179 { RTSX_REALTEK, RTSX_RTS522A, RTSX_VERSION " Realtek RTS522A PCI MMC/SD Card Reader"}, 180 { RTSX_REALTEK, RTSX_RTS525A, RTSX_VERSION " Realtek RTS525A PCI MMC/SD Card Reader"}, 181 { RTSX_REALTEK, RTSX_RTS5249, RTSX_VERSION " Realtek RTS5249 PCI MMC/SD Card Reader"}, 182 { RTSX_REALTEK, RTSX_RTL8402, RTSX_VERSION " Realtek RTL8402 PCI MMC/SD Card Reader"}, 183 { RTSX_REALTEK, RTSX_RTL8411, RTSX_VERSION " Realtek RTL8411 PCI MMC/SD Card Reader"}, 184 { RTSX_REALTEK, RTSX_RTL8411B, RTSX_VERSION " Realtek RTL8411B PCI MMC/SD Card Reader"}, | 179 { RTSX_REALTEK, RTSX_RTS5209, RTSX_VERSION " Realtek RTS5209 PCIe MMC/SD Card Reader"}, 180 { RTSX_REALTEK, RTSX_RTS5227, RTSX_VERSION " Realtek RTS5227 PCIe MMC/SD Card Reader"}, 181 { RTSX_REALTEK, RTSX_RTS5229, RTSX_VERSION " Realtek RTS5229 PCIe MMC/SD Card Reader"}, 182 { RTSX_REALTEK, RTSX_RTS522A, RTSX_VERSION " Realtek RTS522A PCIe MMC/SD Card Reader"}, 183 { RTSX_REALTEK, RTSX_RTS525A, RTSX_VERSION " Realtek RTS525A PCIe MMC/SD Card Reader"}, 184 { RTSX_REALTEK, RTSX_RTS5249, RTSX_VERSION " Realtek RTS5249 PCIe MMC/SD Card Reader"}, 185 { RTSX_REALTEK, RTSX_RTL8402, RTSX_VERSION " Realtek RTL8402 PCIe MMC/SD Card Reader"}, 186 { RTSX_REALTEK, RTSX_RTL8411, RTSX_VERSION " Realtek RTL8411 PCIe MMC/SD Card Reader"}, 187 { RTSX_REALTEK, RTSX_RTL8411B, RTSX_VERSION " Realtek RTL8411B PCIe MMC/SD Card Reader"}, |
185 { 0, 0, NULL} 186}; 187 | 188 { 0, 0, NULL} 189}; 190 |
191/* See `kenv | grep smbios.system` */ 192static const struct rtsx_inversion_model { 193 char *maker; 194 char *family; 195 char *product; 196} rtsx_inversion_models[] = { 197 { "LENOVO", "ThinkPad T470p", "20J7S0PM00"}, 198 { NULL, NULL, NULL} 199}; 200 |
|
188static int rtsx_dma_alloc(struct rtsx_softc *sc); 189static void rtsx_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error); 190static void rtsx_dma_free(struct rtsx_softc *sc); 191static void rtsx_intr(void *arg); 192static void rtsx_handle_card_present(struct rtsx_softc *sc); 193static void rtsx_card_task(void *arg, int pending __unused); 194static bool rtsx_is_card_present(struct rtsx_softc *sc); 195static int rtsx_init(struct rtsx_softc *sc); --- 400 unchanged lines hidden (view full) --- 596static void 597rtsx_handle_card_present(struct rtsx_softc *sc) 598{ 599 bool was_present; 600 bool is_present; 601 602#ifdef MMCCAM 603 was_present = sc->rtsx_cam_status; | 201static int rtsx_dma_alloc(struct rtsx_softc *sc); 202static void rtsx_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error); 203static void rtsx_dma_free(struct rtsx_softc *sc); 204static void rtsx_intr(void *arg); 205static void rtsx_handle_card_present(struct rtsx_softc *sc); 206static void rtsx_card_task(void *arg, int pending __unused); 207static bool rtsx_is_card_present(struct rtsx_softc *sc); 208static int rtsx_init(struct rtsx_softc *sc); --- 400 unchanged lines hidden (view full) --- 609static void 610rtsx_handle_card_present(struct rtsx_softc *sc) 611{ 612 bool was_present; 613 bool is_present; 614 615#ifdef MMCCAM 616 was_present = sc->rtsx_cam_status; |
604#else | 617#else /* !MMCCAM */ |
605 was_present = sc->rtsx_mmc_dev != NULL; 606#endif /* MMCCAM */ 607 is_present = rtsx_is_card_present(sc); 608 if (is_present) 609 device_printf(sc->rtsx_dev, "Card present\n"); 610 else 611 device_printf(sc->rtsx_dev, "Card absent\n"); 612 --- 22 unchanged lines hidden (view full) --- 635 636 if (rtsx_is_card_present(sc)) { 637 sc->rtsx_flags |= RTSX_F_CARD_PRESENT; 638 /* Card is present, attach if necessary. */ 639#ifdef MMCCAM 640 if (sc->rtsx_cam_status == 0) { 641 union ccb *ccb; 642 uint32_t pathid; | 618 was_present = sc->rtsx_mmc_dev != NULL; 619#endif /* MMCCAM */ 620 is_present = rtsx_is_card_present(sc); 621 if (is_present) 622 device_printf(sc->rtsx_dev, "Card present\n"); 623 else 624 device_printf(sc->rtsx_dev, "Card absent\n"); 625 --- 22 unchanged lines hidden (view full) --- 648 649 if (rtsx_is_card_present(sc)) { 650 sc->rtsx_flags |= RTSX_F_CARD_PRESENT; 651 /* Card is present, attach if necessary. */ 652#ifdef MMCCAM 653 if (sc->rtsx_cam_status == 0) { 654 union ccb *ccb; 655 uint32_t pathid; |
643#else | 656#else /* !MMCCAM */ |
644 if (sc->rtsx_mmc_dev == NULL) { 645#endif /* MMCCAM */ 646 if (bootverbose) 647 device_printf(sc->rtsx_dev, "Card inserted\n"); 648 649 sc->rtsx_read_count = sc->rtsx_write_count = 0; 650#ifdef MMCCAM 651 sc->rtsx_cam_status = 1; --- 12 unchanged lines hidden (view full) --- 664 /* target */ 0, /* lun */ 0) != CAM_REQ_CMP) { 665 device_printf(sc->rtsx_dev, "Unable to create path for rescan\n"); 666 RTSX_UNLOCK(sc); 667 xpt_free_ccb(ccb); 668 return; 669 } 670 RTSX_UNLOCK(sc); 671 xpt_rescan(ccb); | 657 if (sc->rtsx_mmc_dev == NULL) { 658#endif /* MMCCAM */ 659 if (bootverbose) 660 device_printf(sc->rtsx_dev, "Card inserted\n"); 661 662 sc->rtsx_read_count = sc->rtsx_write_count = 0; 663#ifdef MMCCAM 664 sc->rtsx_cam_status = 1; --- 12 unchanged lines hidden (view full) --- 677 /* target */ 0, /* lun */ 0) != CAM_REQ_CMP) { 678 device_printf(sc->rtsx_dev, "Unable to create path for rescan\n"); 679 RTSX_UNLOCK(sc); 680 xpt_free_ccb(ccb); 681 return; 682 } 683 RTSX_UNLOCK(sc); 684 xpt_rescan(ccb); |
672#else | 685#else /* !MMCCAM */ |
673 sc->rtsx_mmc_dev = device_add_child(sc->rtsx_dev, "mmc", -1); 674 RTSX_UNLOCK(sc); 675 if (sc->rtsx_mmc_dev == NULL) { 676 device_printf(sc->rtsx_dev, "Adding MMC bus failed\n"); 677 } else { 678 device_set_ivars(sc->rtsx_mmc_dev, sc); 679 device_probe_and_attach(sc->rtsx_mmc_dev); 680 } 681#endif /* MMCCAM */ 682 } else 683 RTSX_UNLOCK(sc); 684 } else { 685 sc->rtsx_flags &= ~RTSX_F_CARD_PRESENT; 686 /* Card isn't present, detach if necessary. */ 687#ifdef MMCCAM 688 if (sc->rtsx_cam_status != 0) { 689 union ccb *ccb; 690 uint32_t pathid; | 686 sc->rtsx_mmc_dev = device_add_child(sc->rtsx_dev, "mmc", -1); 687 RTSX_UNLOCK(sc); 688 if (sc->rtsx_mmc_dev == NULL) { 689 device_printf(sc->rtsx_dev, "Adding MMC bus failed\n"); 690 } else { 691 device_set_ivars(sc->rtsx_mmc_dev, sc); 692 device_probe_and_attach(sc->rtsx_mmc_dev); 693 } 694#endif /* MMCCAM */ 695 } else 696 RTSX_UNLOCK(sc); 697 } else { 698 sc->rtsx_flags &= ~RTSX_F_CARD_PRESENT; 699 /* Card isn't present, detach if necessary. */ 700#ifdef MMCCAM 701 if (sc->rtsx_cam_status != 0) { 702 union ccb *ccb; 703 uint32_t pathid; |
691#else | 704#else /* !MMCCAM */ |
692 if (sc->rtsx_mmc_dev != NULL) { 693#endif /* MMCCAM */ 694 if (bootverbose) 695 device_printf(sc->rtsx_dev, "Card removed\n"); 696 697 if (sc->rtsx_debug) 698 device_printf(sc->rtsx_dev, "Read count: %" PRIu64 ", write count: %" PRIu64 "\n", 699 sc->rtsx_read_count, sc->rtsx_write_count); --- 14 unchanged lines hidden (view full) --- 714 /* target */ 0, /* lun */ 0) != CAM_REQ_CMP) { 715 device_printf(sc->rtsx_dev, "Unable to create path for rescan\n"); 716 RTSX_UNLOCK(sc); 717 xpt_free_ccb(ccb); 718 return; 719 } 720 RTSX_UNLOCK(sc); 721 xpt_rescan(ccb); | 705 if (sc->rtsx_mmc_dev != NULL) { 706#endif /* MMCCAM */ 707 if (bootverbose) 708 device_printf(sc->rtsx_dev, "Card removed\n"); 709 710 if (sc->rtsx_debug) 711 device_printf(sc->rtsx_dev, "Read count: %" PRIu64 ", write count: %" PRIu64 "\n", 712 sc->rtsx_read_count, sc->rtsx_write_count); --- 14 unchanged lines hidden (view full) --- 727 /* target */ 0, /* lun */ 0) != CAM_REQ_CMP) { 728 device_printf(sc->rtsx_dev, "Unable to create path for rescan\n"); 729 RTSX_UNLOCK(sc); 730 xpt_free_ccb(ccb); 731 return; 732 } 733 RTSX_UNLOCK(sc); 734 xpt_rescan(ccb); |
722#else | 735#else /* !MMCCAM */ |
723 RTSX_UNLOCK(sc); 724 if (device_delete_child(sc->rtsx_dev, sc->rtsx_mmc_dev)) 725 device_printf(sc->rtsx_dev, "Detaching MMC bus failed\n"); 726 sc->rtsx_mmc_dev = NULL; 727#endif /* MMCCAM */ 728 } else 729 RTSX_UNLOCK(sc); 730 } --- 248 unchanged lines hidden (view full) --- 979 RTSX_CLR(sc, RTSX_PM_CTRL3, RTSX_D3_DELINK_MODE_EN); 980 if ((error = rtsx_write_phy(sc, RTSX_PHY_REV, 981 RTSX_PHY_REV_RESV | RTSX_PHY_REV_RXIDLE_LATCHED | 982 RTSX_PHY_REV_P1_EN | RTSX_PHY_REV_RXIDLE_EN | 983 RTSX_PHY_REV_CLKREQ_TX_EN | RTSX_PHY_REV_RX_PWST | 984 RTSX_PHY_REV_CLKREQ_DT_1_0 | RTSX_PHY_REV_STOP_CLKRD | 985 RTSX_PHY_REV_STOP_CLKWR))) 986 return (error); | 736 RTSX_UNLOCK(sc); 737 if (device_delete_child(sc->rtsx_dev, sc->rtsx_mmc_dev)) 738 device_printf(sc->rtsx_dev, "Detaching MMC bus failed\n"); 739 sc->rtsx_mmc_dev = NULL; 740#endif /* MMCCAM */ 741 } else 742 RTSX_UNLOCK(sc); 743 } --- 248 unchanged lines hidden (view full) --- 992 RTSX_CLR(sc, RTSX_PM_CTRL3, RTSX_D3_DELINK_MODE_EN); 993 if ((error = rtsx_write_phy(sc, RTSX_PHY_REV, 994 RTSX_PHY_REV_RESV | RTSX_PHY_REV_RXIDLE_LATCHED | 995 RTSX_PHY_REV_P1_EN | RTSX_PHY_REV_RXIDLE_EN | 996 RTSX_PHY_REV_CLKREQ_TX_EN | RTSX_PHY_REV_RX_PWST | 997 RTSX_PHY_REV_CLKREQ_DT_1_0 | RTSX_PHY_REV_STOP_CLKRD | 998 RTSX_PHY_REV_STOP_CLKWR))) 999 return (error); |
987 DELAY(10); | 1000 DELAY(1000); |
988 if ((error = rtsx_write_phy(sc, RTSX_PHY_BPCR, 989 RTSX_PHY_BPCR_IBRXSEL | RTSX_PHY_BPCR_IBTXSEL | 990 RTSX_PHY_BPCR_IB_FILTER | RTSX_PHY_BPCR_CMIRROR_EN))) 991 return (error); 992 if ((error = rtsx_write_phy(sc, RTSX_PHY_PCR, 993 RTSX_PHY_PCR_FORCE_CODE | RTSX_PHY_PCR_OOBS_CALI_50 | 994 RTSX_PHY_PCR_OOBS_VCM_08 | RTSX_PHY_PCR_OOBS_SEN_90 | 995 RTSX_PHY_PCR_RSSI_EN | RTSX_PHY_PCR_RX10K))) --- 603 unchanged lines hidden (view full) --- 1599 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, RTSX_LDO3318_ON); 1600 break; 1601 case RTSX_RTS5227: 1602 case RTSX_RTS522A: 1603 /* Partial power. */ 1604 RTSX_BITOP(sc, RTSX_CARD_PWR_CTL, RTSX_SD_PWR_MASK, RTSX_SD_PARTIAL_PWR_ON); 1605 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, RTSX_LDO3318_VCC1); 1606 | 1001 if ((error = rtsx_write_phy(sc, RTSX_PHY_BPCR, 1002 RTSX_PHY_BPCR_IBRXSEL | RTSX_PHY_BPCR_IBTXSEL | 1003 RTSX_PHY_BPCR_IB_FILTER | RTSX_PHY_BPCR_CMIRROR_EN))) 1004 return (error); 1005 if ((error = rtsx_write_phy(sc, RTSX_PHY_PCR, 1006 RTSX_PHY_PCR_FORCE_CODE | RTSX_PHY_PCR_OOBS_CALI_50 | 1007 RTSX_PHY_PCR_OOBS_VCM_08 | RTSX_PHY_PCR_OOBS_SEN_90 | 1008 RTSX_PHY_PCR_RSSI_EN | RTSX_PHY_PCR_RX10K))) --- 603 unchanged lines hidden (view full) --- 1612 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, RTSX_LDO3318_ON); 1613 break; 1614 case RTSX_RTS5227: 1615 case RTSX_RTS522A: 1616 /* Partial power. */ 1617 RTSX_BITOP(sc, RTSX_CARD_PWR_CTL, RTSX_SD_PWR_MASK, RTSX_SD_PARTIAL_PWR_ON); 1618 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, RTSX_LDO3318_VCC1); 1619 |
1607 DELAY(200); | 1620 DELAY(20000); |
1608 1609 /* Full power. */ 1610 RTSX_BITOP(sc, RTSX_CARD_PWR_CTL, RTSX_SD_PWR_MASK, RTSX_SD_PWR_ON); 1611 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, 1612 RTSX_LDO3318_VCC1 | RTSX_LDO3318_VCC2); 1613 RTSX_BITOP(sc, RTSX_CARD_OE, RTSX_SD_OUTPUT_EN, RTSX_SD_OUTPUT_EN); 1614 RTSX_BITOP(sc, RTSX_CARD_OE, RTSX_MS_OUTPUT_EN, RTSX_MS_OUTPUT_EN); 1615 break; --- 11 unchanged lines hidden (view full) --- 1627 break; 1628 case RTSX_RTS525A: 1629 RTSX_BITOP(sc, RTSX_LDO_VCC_CFG1, RTSX_LDO_VCC_TUNE_MASK, RTSX_LDO_VCC_3V3); 1630 case RTSX_RTS5249: 1631 /* Partial power. */ 1632 RTSX_BITOP(sc, RTSX_CARD_PWR_CTL, RTSX_SD_PWR_MASK, RTSX_SD_PARTIAL_PWR_ON); 1633 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, RTSX_LDO3318_VCC1); 1634 | 1621 1622 /* Full power. */ 1623 RTSX_BITOP(sc, RTSX_CARD_PWR_CTL, RTSX_SD_PWR_MASK, RTSX_SD_PWR_ON); 1624 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, 1625 RTSX_LDO3318_VCC1 | RTSX_LDO3318_VCC2); 1626 RTSX_BITOP(sc, RTSX_CARD_OE, RTSX_SD_OUTPUT_EN, RTSX_SD_OUTPUT_EN); 1627 RTSX_BITOP(sc, RTSX_CARD_OE, RTSX_MS_OUTPUT_EN, RTSX_MS_OUTPUT_EN); 1628 break; --- 11 unchanged lines hidden (view full) --- 1640 break; 1641 case RTSX_RTS525A: 1642 RTSX_BITOP(sc, RTSX_LDO_VCC_CFG1, RTSX_LDO_VCC_TUNE_MASK, RTSX_LDO_VCC_3V3); 1643 case RTSX_RTS5249: 1644 /* Partial power. */ 1645 RTSX_BITOP(sc, RTSX_CARD_PWR_CTL, RTSX_SD_PWR_MASK, RTSX_SD_PARTIAL_PWR_ON); 1646 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, RTSX_LDO3318_VCC1); 1647 |
1635 DELAY(200); | 1648 DELAY(5000); |
1636 1637 /* Full power. */ 1638 RTSX_BITOP(sc, RTSX_CARD_PWR_CTL, RTSX_SD_PWR_MASK, RTSX_SD_PWR_ON); 1639 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, 1640 RTSX_LDO3318_VCC1 | RTSX_LDO3318_VCC2); 1641 break; 1642 case RTSX_RTL8402: 1643 case RTSX_RTL8411: --- 334 unchanged lines hidden (view full) --- 1978static int 1979rtsx_sd_tuning_rx_cmd_wait(struct rtsx_softc *sc, struct mmc_command *cmd) 1980{ 1981 int status; 1982 int mask = RTSX_TRANS_OK_INT | RTSX_TRANS_FAIL_INT; 1983 1984 status = sc->rtsx_intr_status & mask; 1985 while (status == 0) { | 1649 1650 /* Full power. */ 1651 RTSX_BITOP(sc, RTSX_CARD_PWR_CTL, RTSX_SD_PWR_MASK, RTSX_SD_PWR_ON); 1652 RTSX_BITOP(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_PWR_MASK, 1653 RTSX_LDO3318_VCC1 | RTSX_LDO3318_VCC2); 1654 break; 1655 case RTSX_RTL8402: 1656 case RTSX_RTL8411: --- 334 unchanged lines hidden (view full) --- 1991static int 1992rtsx_sd_tuning_rx_cmd_wait(struct rtsx_softc *sc, struct mmc_command *cmd) 1993{ 1994 int status; 1995 int mask = RTSX_TRANS_OK_INT | RTSX_TRANS_FAIL_INT; 1996 1997 status = sc->rtsx_intr_status & mask; 1998 while (status == 0) { |
1986 if (msleep(&sc->rtsx_intr_status, &sc->rtsx_mtx, 0, "rtsxintr", sc->rtsx_timeout) == EWOULDBLOCK) { | 1999 if (msleep(&sc->rtsx_intr_status, &sc->rtsx_mtx, 0, "rtsxintr", sc->rtsx_timeout_cmd) == EWOULDBLOCK) { |
1987 cmd->error = MMC_ERR_TIMEOUT; 1988 return (MMC_ERR_TIMEOUT); 1989 } 1990 status = sc->rtsx_intr_status & mask; 1991 } 1992 return (cmd->error); 1993} 1994 --- 254 unchanged lines hidden (view full) --- 2249 } 2250 callout_stop(&sc->rtsx_timeout_callout); 2251 sc->rtsx_req = NULL; 2252#ifdef MMCCAM 2253 ccb = sc->rtsx_ccb; 2254 sc->rtsx_ccb = NULL; 2255 ccb->ccb_h.status = (req->cmd->error == 0 ? CAM_REQ_CMP : CAM_REQ_CMP_ERR); 2256 xpt_done(ccb); | 2000 cmd->error = MMC_ERR_TIMEOUT; 2001 return (MMC_ERR_TIMEOUT); 2002 } 2003 status = sc->rtsx_intr_status & mask; 2004 } 2005 return (cmd->error); 2006} 2007 --- 254 unchanged lines hidden (view full) --- 2262 } 2263 callout_stop(&sc->rtsx_timeout_callout); 2264 sc->rtsx_req = NULL; 2265#ifdef MMCCAM 2266 ccb = sc->rtsx_ccb; 2267 sc->rtsx_ccb = NULL; 2268 ccb->ccb_h.status = (req->cmd->error == 0 ? CAM_REQ_CMP : CAM_REQ_CMP_ERR); 2269 xpt_done(ccb); |
2257#else | 2270#else /* !MMCCAM */ |
2258 req->done(req); 2259#endif /* MMCCAM */ 2260} 2261 2262/* 2263 * Send request. 2264 */ 2265static int --- 628 unchanged lines hidden (view full) --- 2894 cpi->protocol = PROTO_MMCSD; 2895 cpi->protocol_version = SCSI_REV_0; 2896 cpi->transport = XPORT_MMCSD; 2897 cpi->transport_version = 1; 2898 2899 cpi->ccb_h.status = CAM_REQ_CMP; 2900 break; 2901 } | 2271 req->done(req); 2272#endif /* MMCCAM */ 2273} 2274 2275/* 2276 * Send request. 2277 */ 2278static int --- 628 unchanged lines hidden (view full) --- 2907 cpi->protocol = PROTO_MMCSD; 2908 cpi->protocol_version = SCSI_REV_0; 2909 cpi->transport = XPORT_MMCSD; 2910 cpi->transport_version = 1; 2911 2912 cpi->ccb_h.status = CAM_REQ_CMP; 2913 break; 2914 } |
2915 case XPT_MMC_GET_TRAN_SETTINGS: |
|
2902 case XPT_GET_TRAN_SETTINGS: 2903 { 2904 struct ccb_trans_settings *cts = &ccb->cts; 2905 2906 if (bootverbose || sc->rtsx_debug) 2907 device_printf(sc->rtsx_dev, "rtsx_cam_action() - got XPT_GET_TRAN_SETTINGS\n"); 2908 2909 cts->protocol = PROTO_MMCSD; --- 8 unchanged lines hidden (view full) --- 2918#if __FreeBSD__ > 12 2919 cts->proto_specific.mmc.host_max_data = RTSX_DMA_DATA_BUFSIZE / MMC_SECTOR_SIZE; 2920#endif 2921 memcpy(&cts->proto_specific.mmc.ios, &sc->rtsx_host.ios, sizeof(struct mmc_ios)); 2922 2923 ccb->ccb_h.status = CAM_REQ_CMP; 2924 break; 2925 } | 2916 case XPT_GET_TRAN_SETTINGS: 2917 { 2918 struct ccb_trans_settings *cts = &ccb->cts; 2919 2920 if (bootverbose || sc->rtsx_debug) 2921 device_printf(sc->rtsx_dev, "rtsx_cam_action() - got XPT_GET_TRAN_SETTINGS\n"); 2922 2923 cts->protocol = PROTO_MMCSD; --- 8 unchanged lines hidden (view full) --- 2932#if __FreeBSD__ > 12 2933 cts->proto_specific.mmc.host_max_data = RTSX_DMA_DATA_BUFSIZE / MMC_SECTOR_SIZE; 2934#endif 2935 memcpy(&cts->proto_specific.mmc.ios, &sc->rtsx_host.ios, sizeof(struct mmc_ios)); 2936 2937 ccb->ccb_h.status = CAM_REQ_CMP; 2938 break; 2939 } |
2940 case XPT_MMC_SET_TRAN_SETTINGS: |
|
2926 case XPT_SET_TRAN_SETTINGS: 2927 if (bootverbose || sc->rtsx_debug) 2928 device_printf(sc->rtsx_dev, "rtsx_cam_action() - got XPT_SET_TRAN_SETTINGS\n"); 2929 2930 /* Apply settings and set ccb->ccb_h.status accordingly. */ 2931 rtsx_cam_set_tran_settings(sc, ccb); 2932 break; 2933 case XPT_RESET_BUS: --- 83 unchanged lines hidden (view full) --- 3017 } 3018#if __FreeBSD__ > 12 3019 if (cts->ios_valid & MMC_VCCQ) { 3020 ios->vccq = new_ios->vccq; 3021 sc->rtsx_ios_vccq = -1; /* To be updated by rtsx_mmcbr_update_ios(). */ 3022 if (bootverbose || sc->rtsx_debug) 3023 device_printf(sc->rtsx_dev, "rtsx_cam_set_tran_settings() - vccq: %d\n", ios->vccq); 3024 } | 2941 case XPT_SET_TRAN_SETTINGS: 2942 if (bootverbose || sc->rtsx_debug) 2943 device_printf(sc->rtsx_dev, "rtsx_cam_action() - got XPT_SET_TRAN_SETTINGS\n"); 2944 2945 /* Apply settings and set ccb->ccb_h.status accordingly. */ 2946 rtsx_cam_set_tran_settings(sc, ccb); 2947 break; 2948 case XPT_RESET_BUS: --- 83 unchanged lines hidden (view full) --- 3032 } 3033#if __FreeBSD__ > 12 3034 if (cts->ios_valid & MMC_VCCQ) { 3035 ios->vccq = new_ios->vccq; 3036 sc->rtsx_ios_vccq = -1; /* To be updated by rtsx_mmcbr_update_ios(). */ 3037 if (bootverbose || sc->rtsx_debug) 3038 device_printf(sc->rtsx_dev, "rtsx_cam_set_tran_settings() - vccq: %d\n", ios->vccq); 3039 } |
3025#endif | 3040#endif /* __FreeBSD__ > 12 */ |
3026 if (rtsx_mmcbr_update_ios(sc->rtsx_dev, NULL) == 0) 3027 ccb->ccb_h.status = CAM_REQ_CMP; 3028 else 3029 ccb->ccb_h.status = CAM_REQ_CMP_ERR; 3030 3031 return; 3032} 3033 --- 387 unchanged lines hidden (view full) --- 3421 return (0); 3422} 3423 3424static int 3425rtsx_mmcbr_request(device_t bus, device_t child __unused, struct mmc_request *req) 3426{ 3427 struct rtsx_softc *sc; 3428 struct mmc_command *cmd; | 3041 if (rtsx_mmcbr_update_ios(sc->rtsx_dev, NULL) == 0) 3042 ccb->ccb_h.status = CAM_REQ_CMP; 3043 else 3044 ccb->ccb_h.status = CAM_REQ_CMP_ERR; 3045 3046 return; 3047} 3048 --- 387 unchanged lines hidden (view full) --- 3436 return (0); 3437} 3438 3439static int 3440rtsx_mmcbr_request(device_t bus, device_t child __unused, struct mmc_request *req) 3441{ 3442 struct rtsx_softc *sc; 3443 struct mmc_command *cmd; |
3444 int timeout; |
|
3429 int error; 3430 3431 sc = device_get_softc(bus); 3432 3433 RTSX_LOCK(sc); 3434 if (sc->rtsx_req != NULL) { 3435 RTSX_UNLOCK(sc); 3436 return (EBUSY); --- 31 unchanged lines hidden (view full) --- 3468 } 3469 3470 /* Select SD card. */ 3471 RTSX_BITOP(sc, RTSX_CARD_SELECT, 0x07, RTSX_SD_MOD_SEL); 3472 RTSX_BITOP(sc, RTSX_CARD_SHARE_MODE, RTSX_CARD_SHARE_MASK, RTSX_CARD_SHARE_48_SD); 3473 3474 if (cmd->data == NULL) { 3475 DELAY(200); | 3445 int error; 3446 3447 sc = device_get_softc(bus); 3448 3449 RTSX_LOCK(sc); 3450 if (sc->rtsx_req != NULL) { 3451 RTSX_UNLOCK(sc); 3452 return (EBUSY); --- 31 unchanged lines hidden (view full) --- 3484 } 3485 3486 /* Select SD card. */ 3487 RTSX_BITOP(sc, RTSX_CARD_SELECT, 0x07, RTSX_SD_MOD_SEL); 3488 RTSX_BITOP(sc, RTSX_CARD_SHARE_MODE, RTSX_CARD_SHARE_MASK, RTSX_CARD_SHARE_48_SD); 3489 3490 if (cmd->data == NULL) { 3491 DELAY(200); |
3492 timeout = sc->rtsx_timeout_cmd; |
|
3476 error = rtsx_send_req(sc, cmd); 3477 } else if (cmd->data->len <= 512) { | 3493 error = rtsx_send_req(sc, cmd); 3494 } else if (cmd->data->len <= 512) { |
3495 timeout = sc->rtsx_timeout_io; |
|
3478 error = rtsx_xfer_short(sc, cmd); 3479 } else { | 3496 error = rtsx_xfer_short(sc, cmd); 3497 } else { |
3498 timeout = sc->rtsx_timeout_io; |
|
3480 error = rtsx_xfer(sc, cmd); 3481 } 3482 end: 3483 if (error == MMC_ERR_NONE) { | 3499 error = rtsx_xfer(sc, cmd); 3500 } 3501 end: 3502 if (error == MMC_ERR_NONE) { |
3484 callout_reset(&sc->rtsx_timeout_callout, sc->rtsx_timeout * hz, rtsx_timeout, sc); | 3503 callout_reset(&sc->rtsx_timeout_callout, timeout * hz, rtsx_timeout, sc); |
3485 } else { 3486 rtsx_req_done(sc); 3487 } 3488 RTSX_UNLOCK(sc); 3489 3490 return (error); 3491} 3492 --- 89 unchanged lines hidden (view full) --- 3582rtsx_attach(device_t dev) 3583{ 3584 struct rtsx_softc *sc = device_get_softc(dev); 3585 struct sysctl_ctx_list *ctx; 3586 struct sysctl_oid_list *tree; 3587 int msi_count = 1; 3588 uint32_t sdio_cfg; 3589 int error; | 3504 } else { 3505 rtsx_req_done(sc); 3506 } 3507 RTSX_UNLOCK(sc); 3508 3509 return (error); 3510} 3511 --- 89 unchanged lines hidden (view full) --- 3601rtsx_attach(device_t dev) 3602{ 3603 struct rtsx_softc *sc = device_get_softc(dev); 3604 struct sysctl_ctx_list *ctx; 3605 struct sysctl_oid_list *tree; 3606 int msi_count = 1; 3607 uint32_t sdio_cfg; 3608 int error; |
3609 char *maker; 3610 char *family; 3611 char *product; 3612 int i; |
|
3590 3591 if (bootverbose) 3592 device_printf(dev, "Attach - Vendor ID: 0x%x - Device ID: 0x%x\n", 3593 pci_get_vendor(dev), pci_get_device(dev)); 3594 3595 sc->rtsx_dev = dev; 3596 sc->rtsx_req = NULL; | 3613 3614 if (bootverbose) 3615 device_printf(dev, "Attach - Vendor ID: 0x%x - Device ID: 0x%x\n", 3616 pci_get_vendor(dev), pci_get_device(dev)); 3617 3618 sc->rtsx_dev = dev; 3619 sc->rtsx_req = NULL; |
3597 sc->rtsx_timeout = 10; | 3620 sc->rtsx_timeout_cmd = 1; 3621 sc->rtsx_timeout_io = 10; |
3598 sc->rtsx_read_only = 0; | 3622 sc->rtsx_read_only = 0; |
3623 sc->rtsx_inversion = 0; |
|
3599 sc->rtsx_force_timing = 0; 3600 sc->rtsx_debug = 0; 3601 sc->rtsx_read_count = 0; 3602 sc->rtsx_write_count = 0; 3603 | 3624 sc->rtsx_force_timing = 0; 3625 sc->rtsx_debug = 0; 3626 sc->rtsx_read_count = 0; 3627 sc->rtsx_write_count = 0; 3628 |
3629 maker = kern_getenv("smbios.system.maker"); 3630 family = kern_getenv("smbios.system.family"); 3631 product = kern_getenv("smbios.system.product"); 3632 for (i = 0; rtsx_inversion_models[i].maker != NULL; i++) { 3633 if (strcmp(rtsx_inversion_models[i].maker, maker) == 0 && 3634 strcmp(rtsx_inversion_models[i].family, family) == 0 && 3635 strcmp(rtsx_inversion_models[i].product, product) == 0) { 3636 device_printf(dev, "Inversion activated for %s/%s/%s, see BUG in rtsx(4)\n", maker, family, product); 3637 device_printf(dev, "If a card is detected without an SD card present," 3638 " add dev.rtsx.0.inversion=0 in loader.conf(5)\n"); 3639 sc->rtsx_inversion = 1; 3640 } 3641 } 3642 |
|
3604 RTSX_LOCK_INIT(sc); 3605 3606 ctx = device_get_sysctl_ctx(dev); 3607 tree = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); | 3643 RTSX_LOCK_INIT(sc); 3644 3645 ctx = device_get_sysctl_ctx(dev); 3646 tree = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); |
3608 SYSCTL_ADD_INT(ctx, tree, OID_AUTO, "req_timeout", CTLFLAG_RW, 3609 &sc->rtsx_timeout, 0, "Request timeout in seconds"); | 3647 SYSCTL_ADD_INT(ctx, tree, OID_AUTO, "timeout_io", CTLFLAG_RW, 3648 &sc->rtsx_timeout_io, 0, "Request timeout for I/O commands in seconds"); 3649 SYSCTL_ADD_INT(ctx, tree, OID_AUTO, "timeout_cmd", CTLFLAG_RW, 3650 &sc->rtsx_timeout_cmd, 0, "Request timeout for setup commands in seconds"); |
3610 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "read_only", CTLFLAG_RD, 3611 &sc->rtsx_read_only, 0, "Card is write protected"); 3612 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "inversion", CTLFLAG_RWTUN, 3613 &sc->rtsx_inversion, 0, "Inversion of card detection and read only status"); 3614 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "force_timing", CTLFLAG_RW, 3615 &sc->rtsx_force_timing, 0, "Force bus_timing_uhs_sdr50"); | 3651 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "read_only", CTLFLAG_RD, 3652 &sc->rtsx_read_only, 0, "Card is write protected"); 3653 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "inversion", CTLFLAG_RWTUN, 3654 &sc->rtsx_inversion, 0, "Inversion of card detection and read only status"); 3655 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "force_timing", CTLFLAG_RW, 3656 &sc->rtsx_force_timing, 0, "Force bus_timing_uhs_sdr50"); |
3616 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "debug", CTLFLAG_RW, | 3657 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "debug", CTLFLAG_RWTUN, |
3617 &sc->rtsx_debug, 0, "Debugging flag"); 3618 SYSCTL_ADD_U64(ctx, tree, OID_AUTO, "read_count", CTLFLAG_RD, 3619 &sc->rtsx_read_count, 0, "Count of read operations"); 3620 SYSCTL_ADD_U64(ctx, tree, OID_AUTO, "write_count", CTLFLAG_RD, 3621 &sc->rtsx_write_count, 0, "Count of write operations"); 3622 | 3658 &sc->rtsx_debug, 0, "Debugging flag"); 3659 SYSCTL_ADD_U64(ctx, tree, OID_AUTO, "read_count", CTLFLAG_RD, 3660 &sc->rtsx_read_count, 0, "Count of read operations"); 3661 SYSCTL_ADD_U64(ctx, tree, OID_AUTO, "write_count", CTLFLAG_RD, 3662 &sc->rtsx_write_count, 0, "Count of write operations"); 3663 |
3664 if (bootverbose || sc->rtsx_debug) 3665 device_printf(dev, "We are running with inversion: %d\n", sc->rtsx_inversion); 3666 |
|
3623 /* Allocate IRQ. */ 3624 sc->rtsx_irq_res_id = 0; 3625 if (pci_alloc_msi(dev, &msi_count) == 0) 3626 sc->rtsx_irq_res_id = 1; 3627 sc->rtsx_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->rtsx_irq_res_id, 3628 RF_ACTIVE | (sc->rtsx_irq_res_id != 0 ? 0 : RF_SHAREABLE)); 3629 if (sc->rtsx_irq_res == NULL) { 3630 device_printf(dev, "Can't allocate IRQ resources for %d\n", sc->rtsx_irq_res_id); --- 16 unchanged lines hidden (view full) --- 3647 3648 if (bootverbose) 3649 device_printf(dev, "rtsx_irq_res_id: %d, rtsx_res_id: %d\n", 3650 sc->rtsx_irq_res_id, sc->rtsx_res_id); 3651 3652 sc->rtsx_btag = rman_get_bustag(sc->rtsx_res); 3653 sc->rtsx_bhandle = rman_get_bushandle(sc->rtsx_res); 3654 | 3667 /* Allocate IRQ. */ 3668 sc->rtsx_irq_res_id = 0; 3669 if (pci_alloc_msi(dev, &msi_count) == 0) 3670 sc->rtsx_irq_res_id = 1; 3671 sc->rtsx_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->rtsx_irq_res_id, 3672 RF_ACTIVE | (sc->rtsx_irq_res_id != 0 ? 0 : RF_SHAREABLE)); 3673 if (sc->rtsx_irq_res == NULL) { 3674 device_printf(dev, "Can't allocate IRQ resources for %d\n", sc->rtsx_irq_res_id); --- 16 unchanged lines hidden (view full) --- 3691 3692 if (bootverbose) 3693 device_printf(dev, "rtsx_irq_res_id: %d, rtsx_res_id: %d\n", 3694 sc->rtsx_irq_res_id, sc->rtsx_res_id); 3695 3696 sc->rtsx_btag = rman_get_bustag(sc->rtsx_res); 3697 sc->rtsx_bhandle = rman_get_bushandle(sc->rtsx_res); 3698 |
3699 TIMEOUT_TASK_INIT(taskqueue_swi_giant, &sc->rtsx_card_insert_task, 0, 3700 rtsx_card_task, sc); 3701 TASK_INIT(&sc->rtsx_card_remove_task, 0, rtsx_card_task, sc); 3702 3703 /* Allocate two DMA buffers: a command buffer and a data buffer. */ 3704 error = rtsx_dma_alloc(sc); 3705 if (error) 3706 goto destroy_rtsx_irq_res; 3707 |
|
3655 /* Activate the interrupt. */ 3656 error = bus_setup_intr(dev, sc->rtsx_irq_res, INTR_TYPE_MISC | INTR_MPSAFE, 3657 NULL, rtsx_intr, sc, &sc->rtsx_irq_cookie); 3658 if (error) { 3659 device_printf(dev, "Can't set up irq [0x%x]!\n", error); 3660 goto destroy_rtsx_res; 3661 } 3662 pci_enable_busmaster(dev); 3663 3664 if (rtsx_read_cfg(sc, 0, RTSX_SDIOCFG_REG, &sdio_cfg) == 0) { 3665 if ((sdio_cfg & RTSX_SDIOCFG_SDIO_ONLY) || 3666 (sdio_cfg & RTSX_SDIOCFG_HAVE_SDIO)) 3667 sc->rtsx_flags |= RTSX_F_SDIO_SUPPORT; 3668 } 3669 | 3708 /* Activate the interrupt. */ 3709 error = bus_setup_intr(dev, sc->rtsx_irq_res, INTR_TYPE_MISC | INTR_MPSAFE, 3710 NULL, rtsx_intr, sc, &sc->rtsx_irq_cookie); 3711 if (error) { 3712 device_printf(dev, "Can't set up irq [0x%x]!\n", error); 3713 goto destroy_rtsx_res; 3714 } 3715 pci_enable_busmaster(dev); 3716 3717 if (rtsx_read_cfg(sc, 0, RTSX_SDIOCFG_REG, &sdio_cfg) == 0) { 3718 if ((sdio_cfg & RTSX_SDIOCFG_SDIO_ONLY) || 3719 (sdio_cfg & RTSX_SDIOCFG_HAVE_SDIO)) 3720 sc->rtsx_flags |= RTSX_F_SDIO_SUPPORT; 3721 } 3722 |
3670 /* Allocate two DMA buffers: a command buffer and a data buffer. */ 3671 error = rtsx_dma_alloc(sc); 3672 if (error) { 3673 goto destroy_rtsx_irq; 3674 } 3675 3676 /* From dwmmc.c. */ 3677 TIMEOUT_TASK_INIT(taskqueue_swi_giant, &sc->rtsx_card_insert_task, 0, 3678 rtsx_card_task, sc); 3679 TASK_INIT(&sc->rtsx_card_remove_task, 0, rtsx_card_task, sc); 3680 | |
3681#ifdef MMCCAM 3682 sc->rtsx_ccb = NULL; 3683 sc->rtsx_cam_status = 0; 3684 3685 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "cam_status", CTLFLAG_RD, 3686 &sc->rtsx_cam_status, 0, "driver cam card present"); 3687 if ((sc->rtsx_devq = cam_simq_alloc(1)) == NULL) { 3688 device_printf(dev, "Error during CAM queue allocation\n"); --- 19 unchanged lines hidden (view full) --- 3708 /* Initialize device. */ 3709 if (rtsx_init(sc)) { 3710 device_printf(dev, "Error during rtsx_init()\n"); 3711 goto destroy_rtsx_irq; 3712 } 3713 3714 /* 3715 * Schedule a card detection as we won't get an interrupt | 3723#ifdef MMCCAM 3724 sc->rtsx_ccb = NULL; 3725 sc->rtsx_cam_status = 0; 3726 3727 SYSCTL_ADD_U8(ctx, tree, OID_AUTO, "cam_status", CTLFLAG_RD, 3728 &sc->rtsx_cam_status, 0, "driver cam card present"); 3729 if ((sc->rtsx_devq = cam_simq_alloc(1)) == NULL) { 3730 device_printf(dev, "Error during CAM queue allocation\n"); --- 19 unchanged lines hidden (view full) --- 3750 /* Initialize device. */ 3751 if (rtsx_init(sc)) { 3752 device_printf(dev, "Error during rtsx_init()\n"); 3753 goto destroy_rtsx_irq; 3754 } 3755 3756 /* 3757 * Schedule a card detection as we won't get an interrupt |
3716 * if the card is inserted when we attach | 3758 * if the card is inserted when we attach. We wait a quarter 3759 * of a second to allow for a "spontaneous" interrupt which may 3760 * change the card presence state. This delay avoid a panic 3761 * on some configuration (e.g. Lenovo T540p). |
3717 */ | 3762 */ |
3718 DELAY(500); | 3763 DELAY(250000); |
3719 if (rtsx_is_card_present(sc)) | 3764 if (rtsx_is_card_present(sc)) |
3720 device_printf(sc->rtsx_dev, "Card present\n"); | 3765 device_printf(sc->rtsx_dev, "A card is detected\n"); |
3721 else | 3766 else |
3722 device_printf(sc->rtsx_dev, "Card absent\n"); | 3767 device_printf(sc->rtsx_dev, "No card is detected\n"); |
3723 rtsx_card_task(sc, 0); 3724 3725 if (bootverbose) 3726 device_printf(dev, "Device attached\n"); 3727 3728 return (0); 3729 3730 destroy_rtsx_irq: 3731 bus_teardown_intr(dev, sc->rtsx_irq_res, sc->rtsx_irq_cookie); 3732 destroy_rtsx_res: 3733 bus_release_resource(dev, SYS_RES_MEMORY, sc->rtsx_res_id, 3734 sc->rtsx_res); | 3768 rtsx_card_task(sc, 0); 3769 3770 if (bootverbose) 3771 device_printf(dev, "Device attached\n"); 3772 3773 return (0); 3774 3775 destroy_rtsx_irq: 3776 bus_teardown_intr(dev, sc->rtsx_irq_res, sc->rtsx_irq_cookie); 3777 destroy_rtsx_res: 3778 bus_release_resource(dev, SYS_RES_MEMORY, sc->rtsx_res_id, 3779 sc->rtsx_res); |
3780 rtsx_dma_free(sc); |
|
3735 destroy_rtsx_irq_res: 3736 callout_drain(&sc->rtsx_timeout_callout); 3737 bus_release_resource(dev, SYS_RES_IRQ, sc->rtsx_irq_res_id, 3738 sc->rtsx_irq_res); 3739 pci_release_msi(dev); 3740 RTSX_LOCK_DESTROY(sc); 3741#ifdef MMCCAM 3742 if (sc->rtsx_sim != NULL) { --- 85 unchanged lines hidden (view full) --- 3828 3829 device_printf(dev, "Suspend\n"); 3830 3831#ifdef MMCCAM 3832 if (sc->rtsx_ccb != NULL) { 3833 device_printf(dev, "Request in progress: CMD%u, rtsr_intr_status: 0x%08x\n", 3834 sc->rtsx_ccb->mmcio.cmd.opcode, sc->rtsx_intr_status); 3835 } | 3781 destroy_rtsx_irq_res: 3782 callout_drain(&sc->rtsx_timeout_callout); 3783 bus_release_resource(dev, SYS_RES_IRQ, sc->rtsx_irq_res_id, 3784 sc->rtsx_irq_res); 3785 pci_release_msi(dev); 3786 RTSX_LOCK_DESTROY(sc); 3787#ifdef MMCCAM 3788 if (sc->rtsx_sim != NULL) { --- 85 unchanged lines hidden (view full) --- 3874 3875 device_printf(dev, "Suspend\n"); 3876 3877#ifdef MMCCAM 3878 if (sc->rtsx_ccb != NULL) { 3879 device_printf(dev, "Request in progress: CMD%u, rtsr_intr_status: 0x%08x\n", 3880 sc->rtsx_ccb->mmcio.cmd.opcode, sc->rtsx_intr_status); 3881 } |
3836#else | 3882#else /* !MMCCAM */ |
3837 if (sc->rtsx_req != NULL) { 3838 device_printf(dev, "Request in progress: CMD%u, rtsr_intr_status: 0x%08x\n", 3839 sc->rtsx_req->cmd->opcode, sc->rtsx_intr_status); 3840 } 3841#endif /* MMCCAM */ 3842 3843 bus_generic_suspend(dev); 3844 --- 49 unchanged lines hidden --- | 3883 if (sc->rtsx_req != NULL) { 3884 device_printf(dev, "Request in progress: CMD%u, rtsr_intr_status: 0x%08x\n", 3885 sc->rtsx_req->cmd->opcode, sc->rtsx_intr_status); 3886 } 3887#endif /* MMCCAM */ 3888 3889 bus_generic_suspend(dev); 3890 --- 49 unchanged lines hidden --- |