From 0b3dac2c336a1c7e8dcad0846e5e2859801bbc5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=84=9A=E8=B9=AC=E7=A0=B4=E6=8B=96=E9=9E=8B?= Date: Mon, 6 Jan 2020 20:49:17 -0600 Subject: [PATCH] Author: Gregory Nutt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Run all .c and .h files in last PR through nxstyle. Author: 脚蹬破拖鞋 Add Imxrt usdhc insert or remove detection (#43) * Add usdhc card insertion and removal detection using interrupt for imxrt. * Add interrupt handle when usdhc insert or remove. --- arch/arm/src/imxrt/imxrt_ehci.c | 2 +- arch/arm/src/imxrt/imxrt_usdhc.c | 32 +++++++++++++++++-- .../imxrt/imxrt1060-evk/src/imxrt_bringup.c | 5 ++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/arch/arm/src/imxrt/imxrt_ehci.c b/arch/arm/src/imxrt/imxrt_ehci.c index 2a98806bdfb..3005066bea3 100644 --- a/arch/arm/src/imxrt/imxrt_ehci.c +++ b/arch/arm/src/imxrt/imxrt_ehci.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/imxrt/imxrt_ehci.c * - * Copyright (C) 2013-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2017, 2020 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * Dave Marples * diff --git a/arch/arm/src/imxrt/imxrt_usdhc.c b/arch/arm/src/imxrt/imxrt_usdhc.c index 76e3bf88a7f..a138a152e5f 100644 --- a/arch/arm/src/imxrt/imxrt_usdhc.c +++ b/arch/arm/src/imxrt/imxrt_usdhc.c @@ -78,7 +78,7 @@ /* Configuration ************************************************************/ -#if ((defined(CONFIG_IMXRT_USDHC1) && !defined(CONFIG_IMXRT_USDHC2)) || \ +#if ((defined(CONFIG_IMXRT_USDHC1) && !defined(CONFIG_IMXRT_USDHC2)) || \ (defined(CONFIG_IMXRT_USDHC2) && !defined(CONFIG_IMXRT_USDHC1))) # define IMXRT_MAX_SDHC_DEV_SLOTS 1 #elif (defined(CONFIG_IMXRT_USDHC1) && defined(CONFIG_IMXRT_USDHC2)) @@ -1232,11 +1232,30 @@ static int imxrt_interrupt(int irq, void *context, FAR void *arg) /* We don't want any more ints now, so switch it off */ - priv->cintints = 0; regval &= ~USDHC_INT_CINT; + priv->cintints = regval; putreg32(regval, priv->addr + IMXRT_USDHC_IRQSIGEN_OFFSET); } + if ((pending & USDHC_INT_CINS) != 0 || (pending & USDHC_INT_CRM) != 0) + { + if (up_interrupt_context()) + { + /* Yes.. queue it */ + + mcinfo("Queuing callback to %p(%p)\n", priv->callback, priv->cbarg); + (void)work_queue(HPWORK, &priv->cbwork, (worker_t)priv->callback, + priv->cbarg, 0); + } + else + { + /* No.. then just call the callback here */ + + mcinfo("Callback to %p(%p)\n", priv->callback, priv->cbarg); + priv->callback(priv->cbarg); + } + } + /* Handle wait events *****************************************************/ pending = enabled & priv->waitints; @@ -3019,7 +3038,14 @@ void imxrt_usdhc_set_sdio_card_isr(FAR struct sdio_dev_s *dev, priv->cintints = 0; } - flags = enter_critical_section(); +#if defined(CONFIG_MMCSD_HAVE_CARDDETECT) + if (priv->sw_cd_gpio == 0) + { + priv->cintints |= USDHC_INT_CINS | USDHC_INT_CRM; + } +#endif + + flags = enter_critical_section(); regval = getreg32(priv->addr + IMXRT_USDHC_IRQSIGEN_OFFSET); regval = (regval & ~USDHC_INT_CINT) | priv->cintints; putreg32(regval, priv->addr + IMXRT_USDHC_IRQSIGEN_OFFSET); diff --git a/boards/arm/imxrt/imxrt1060-evk/src/imxrt_bringup.c b/boards/arm/imxrt/imxrt1060-evk/src/imxrt_bringup.c index e38c96b1a01..c7376087306 100644 --- a/boards/arm/imxrt/imxrt1060-evk/src/imxrt_bringup.c +++ b/boards/arm/imxrt/imxrt1060-evk/src/imxrt_bringup.c @@ -1,7 +1,7 @@ /**************************************************************************** * boards/arm/imxrt/imxrt1060-evk/src/imxrt_bringup.c * - * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Copyright (C) 2018, 2020 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * David Sidrane * @@ -121,7 +121,10 @@ static int nsh_sdmmc_initialize(void) "ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); } + + imxrt_usdhc_set_sdio_card_isr(sdmmc, NULL, NULL); } + return OK; } #else