Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic dwcmmc: Add support for card detect using SDMMC_C...



details:   https://anonhg.NetBSD.org/src/rev/809ae830c4d0
branches:  trunk
changeset: 359553:809ae830c4d0
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Jan 09 15:03:43 2022 +0000

description:
dwcmmc: Add support for card detect using SDMMC_CDETECT register

diffstat:

 sys/dev/ic/dwc_mmc.c     |  33 +++++++++++++++++++++++++--------
 sys/dev/ic/dwc_mmc_reg.h |   4 +++-
 sys/dev/ic/dwc_mmc_var.h |   4 +++-
 3 files changed, 31 insertions(+), 10 deletions(-)

diffs (109 lines):

diff -r 7855a1b2d8d5 -r 809ae830c4d0 sys/dev/ic/dwc_mmc.c
--- a/sys/dev/ic/dwc_mmc.c      Sun Jan 09 14:28:23 2022 +0000
+++ b/sys/dev/ic/dwc_mmc.c      Sun Jan 09 15:03:43 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_mmc.c,v 1.28 2021/08/07 16:19:12 thorpej Exp $ */
+/* $NetBSD: dwc_mmc.c,v 1.29 2022/01/09 15:03:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dwc_mmc.c,v 1.28 2021/08/07 16:19:12 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc_mmc.c,v 1.29 2022/01/09 15:03:43 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -162,6 +162,10 @@
 {
        struct dwc_mmc_softc *sc = device_private(self);
        struct sdmmcbus_attach_args saa;
+       bool poll_detect;
+
+       poll_detect = sc->sc_card_detect != NULL ||
+          (sc->sc_flags & (DWC_MMC_F_BROKEN_CD|DWC_MMC_F_NON_REMOVABLE)) == 0;
 
        if (sc->sc_pre_power_on)
                sc->sc_pre_power_on(sc);
@@ -185,12 +189,15 @@
                       SMC_CAPS_AUTO_STOP |
                       SMC_CAPS_DMA |
                       SMC_CAPS_MULTI_SEG_DMA;
-       if (sc->sc_bus_width == 8)
+       if (sc->sc_bus_width == 8) {
                saa.saa_caps |= SMC_CAPS_8BIT_MODE;
-       else
+       } else {
                saa.saa_caps |= SMC_CAPS_4BIT_MODE;
-       if (sc->sc_card_detect)
+       }
+
+       if (poll_detect) {
                saa.saa_caps |= SMC_CAPS_POLL_CARD_DET;
+       }
 
        sc->sc_sdmmc_dev = config_found(self, &saa, NULL, CFARGS_NONE);
 }
@@ -276,11 +283,21 @@
 dwc_mmc_card_detect(sdmmc_chipset_handle_t sch)
 {
        struct dwc_mmc_softc *sc = sch;
+       int det_n;
 
-       if (!sc->sc_card_detect)
-               return 1;       /* no card detect pin, assume present */
+       if (sc->sc_card_detect != NULL) {
+               return sc->sc_card_detect(sc);
+       }
+       if ((sc->sc_flags & DWC_MMC_F_BROKEN_CD) != 0) {
+               return 1;       /* broken card detect, assume present */
+       }
+       if ((sc->sc_flags & DWC_MMC_F_NON_REMOVABLE) != 0) {
+               return 1;       /* non-removable device is always present */
+       }
 
-       return sc->sc_card_detect(sc);
+       det_n = MMC_READ(sc, DWC_MMC_CDETECT) & DWC_MMC_CDETECT_CARD_DETECT_N;
+
+       return !det_n;
 }
 
 static int
diff -r 7855a1b2d8d5 -r 809ae830c4d0 sys/dev/ic/dwc_mmc_reg.h
--- a/sys/dev/ic/dwc_mmc_reg.h  Sun Jan 09 14:28:23 2022 +0000
+++ b/sys/dev/ic/dwc_mmc_reg.h  Sun Jan 09 15:03:43 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_mmc_reg.h,v 1.10 2020/03/20 17:02:16 skrll Exp $ */
+/* $NetBSD: dwc_mmc_reg.h,v 1.11 2022/01/09 15:03:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -147,6 +147,8 @@
 #define        DWC_MMC_FIFOTH_RX_WMARK         __BITS(27,16)
 #define        DWC_MMC_FIFOTH_TX_WMARK         __BITS(11,0)
 
+#define        DWC_MMC_CDETECT_CARD_DETECT_N   __BIT(0)
+
 #define DWC_MMC_DMAC_IDMA_ON           __BIT(7)
 #define DWC_MMC_DMAC_FIX_BURST         __BIT(1)
 #define DWC_MMC_DMAC_SOFTRESET         __BIT(0)
diff -r 7855a1b2d8d5 -r 809ae830c4d0 sys/dev/ic/dwc_mmc_var.h
--- a/sys/dev/ic/dwc_mmc_var.h  Sun Jan 09 14:28:23 2022 +0000
+++ b/sys/dev/ic/dwc_mmc_var.h  Sun Jan 09 15:03:43 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_mmc_var.h,v 1.14 2020/03/20 17:07:17 skrll Exp $ */
+/* $NetBSD: dwc_mmc_var.h,v 1.15 2022/01/09 15:03:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -40,6 +40,8 @@
 #define        DWC_MMC_F_DMA           __BIT(0)
 #define        DWC_MMC_F_USE_HOLD_REG  __BIT(1)
 #define        DWC_MMC_F_PWREN_INV     __BIT(2)
+#define        DWC_MMC_F_BROKEN_CD     __BIT(3)
+#define        DWC_MMC_F_NON_REMOVABLE __BIT(4)
        uint32_t sc_fifo_reg;
        uint32_t sc_fifo_depth;
        u_int sc_clock_freq;



Home | Main Index | Thread Index | Old Index