summaryrefslogtreecommitdiff
path: root/sys/dev/ic
diff options
context:
space:
mode:
authorjmcneill <jmcneill@NetBSD.org>2022-01-09 15:03:43 +0000
committerjmcneill <jmcneill@NetBSD.org>2022-01-09 15:03:43 +0000
commitdfebed1bf71f2956158fca82cd28bafd1d0b9ea2 (patch)
tree00b7383dfdb5254cb3a70d02b739dd24e0f6282a /sys/dev/ic
parent8430034e2e13a441893821617c5968c088eef719 (diff)
dwcmmc: Add support for card detect using SDMMC_CDETECT register
Diffstat (limited to 'sys/dev/ic')
-rw-r--r--sys/dev/ic/dwc_mmc.c33
-rw-r--r--sys/dev/ic/dwc_mmc_reg.h4
-rw-r--r--sys/dev/ic/dwc_mmc_var.h4
3 files changed, 31 insertions, 10 deletions
diff --git a/sys/dev/ic/dwc_mmc.c b/sys/dev/ic/dwc_mmc.c
index 5d93d0f0528..d7568c3fcf4 100644
--- a/sys/dev/ic/dwc_mmc.c
+++ b/sys/dev/ic/dwc_mmc.c
@@ -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>
@@ -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 @@ dwc_mmc_attach_i(device_t self)
{
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 @@ dwc_mmc_attach_i(device_t self)
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 @@ static int
dwc_mmc_card_detect(sdmmc_chipset_handle_t sch)
{
struct dwc_mmc_softc *sc = sch;
+ int det_n;
+
+ 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 */
+ }
- if (!sc->sc_card_detect)
- return 1; /* no card detect pin, assume present */
+ det_n = MMC_READ(sc, DWC_MMC_CDETECT) & DWC_MMC_CDETECT_CARD_DETECT_N;
- return sc->sc_card_detect(sc);
+ return !det_n;
}
static int
diff --git a/sys/dev/ic/dwc_mmc_reg.h b/sys/dev/ic/dwc_mmc_reg.h
index ea5756e2ac1..71b39cdaa3a 100644
--- a/sys/dev/ic/dwc_mmc_reg.h
+++ b/sys/dev/ic/dwc_mmc_reg.h
@@ -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>
@@ -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 --git a/sys/dev/ic/dwc_mmc_var.h b/sys/dev/ic/dwc_mmc_var.h
index 1daee77a1cf..20601b77f96 100644
--- a/sys/dev/ic/dwc_mmc_var.h
+++ b/sys/dev/ic/dwc_mmc_var.h
@@ -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>
@@ -40,6 +40,8 @@ struct dwc_mmc_softc {
#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;