From patchwork Wed May 17 13:49:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixun LI X-Patchwork-Id: 1782718 X-Patchwork-Delegate: eugen.hristev@microchip.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20221208.gappssmtp.com header.i=@hifiphile-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=MIgbqlOR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QLwsP4jD2z20dg for ; Thu, 18 May 2023 00:46:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 925A086215; Wed, 17 May 2023 16:46:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20221208.gappssmtp.com header.i=@hifiphile-com.20221208.gappssmtp.com header.b="MIgbqlOR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F022E86241; Wed, 17 May 2023 15:50:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C146484692 for ; Wed, 17 May 2023 15:49:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=admin@hifiphile.com Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3078d1c8828so750118f8f.3 for ; Wed, 17 May 2023 06:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hifiphile-com.20221208.gappssmtp.com; s=20221208; t=1684331398; x=1686923398; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CztcakkzcWmE53Glbc5oJyK+ktOCCHjVhwmJ1lN1YBo=; b=MIgbqlORIoGtIYsJBXaZSxtUUrQisGkSU/hoZ3aYRyKjPwUa52xHry6pIX55NT5BxI +WtmC87mtZeon5Ws52Rc/HZQ5QrX30z0M8RmM2plb5Buuev74a17JSY/BiAIz/eGLV57 sHXWeNA9f7HNlANojBkUzJyiKaSe0jnIz9DYcShFyg5+rMWI0BwzveJMufcJd77Q2enH Pg7bu8UmhW1b4eoj/bd5E7nmJYk8uAMcl3XupuFcekn5kQisHolFPr3jSjeGYwtPOvVI qTRkAKfvu5LZQbzS/KCgig4szywtBubRrYx+JGvMICTOIgjswEf4CMompW36SIl7K4lr CjOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684331398; x=1686923398; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CztcakkzcWmE53Glbc5oJyK+ktOCCHjVhwmJ1lN1YBo=; b=J5pEFh2P8aDlGgZZHHn/Htmrcr/6STcl694RY6yzVfPDIJMaXiM7pI7Gq+6QstWWVy +CyV4F7yWDWRimoLOCTokugXF+zMkDopnG0nxTMBdEDiT3oD2Rn+JtnwfGnRScP+Afse INFIIsqETJBWjsMzADGP4RiHbh4dzUw0Kb1xcutxq05l7MbYwbHeTTGtn7o5rXWndHz9 I1ovm/Vjxi/dEDgYAE/TVGTgDqLrOz8xMIbdZGaH2cRAHDZh0iYnieDrgCq2sSaGpb88 CkW3MgV355WrSJe/8rGirAbvunF4kqE4z+UfnFgnCcA9+9POEwIlJpbM2OLMytLhWkr0 Kp1g== X-Gm-Message-State: AC+VfDzbBj43djBIRaHGF2IWUvTm+SGnvvC0g/7vsT7hhVY5+BuR25lm p/QOT+f098wrJ5NuIYzVHvYW9jBSJxp31KF4wCP0og== X-Google-Smtp-Source: ACHHUZ5fVPNpOd0zTYZHFkqvK+6cCvCUVX53WceQIRJ6zhlefxTFVS7beox91j3jmbv1X0uI6DUpug== X-Received: by 2002:a5d:6d51:0:b0:309:4228:8e1a with SMTP id k17-20020a5d6d51000000b0030942288e1amr716693wri.9.1684331397687; Wed, 17 May 2023 06:49:57 -0700 (PDT) Received: from localhost.localdomain ([2a01:e34:ec73:c8f0:740b:5aa6:5225:86c6]) by smtp.gmail.com with ESMTPSA id k6-20020a056000004600b003047d5b8817sm2826918wrx.80.2023.05.17.06.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 06:49:57 -0700 (PDT) From: Zixun LI X-Google-Original-From: Zixun LI To: u-boot@lists.denx.de, eugen.hristev@collabora.com Cc: Zixun LI Subject: [PATCH v2] atmel_sdhci: Force card-detect if MMC_CAP_NONREMOVABLE. Date: Wed, 17 May 2023 15:49:45 +0200 Message-Id: <20230517134945.2201444-1-zli@ogga.fr> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 17 May 2023 16:46:11 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean If the device attached to the MMC bus is not removable, set force card-detect bit to bypass card detection procedure, so card detection pin can be used for other purposes. It's also a workaround for SAMA5D2 who doesn't drive CMD if using GPIO for card detection. Signed-off-by: Zixun LI Reviewed-by: Eugen Hristev --- drivers/mmc/atmel_sdhci.c | 40 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/atmel_sdhci.c b/drivers/mmc/atmel_sdhci.c index 37b0beeed4..ae56266f57 100644 --- a/drivers/mmc/atmel_sdhci.c +++ b/drivers/mmc/atmel_sdhci.c @@ -15,6 +15,9 @@ #define ATMEL_SDHC_MIN_FREQ 400000 #define ATMEL_SDHC_GCK_RATE 240000000 +#define ATMEL_SDHC_MC1R 0x204 +#define ATMEL_SDHC_MC1R_FCD 0x80 + #ifndef CONFIG_DM_MMC int atmel_sdhci_init(void *regbase, u32 id) { @@ -52,11 +55,38 @@ struct atmel_sdhci_plat { struct mmc mmc; }; +static void atmel_sdhci_config_fcd(struct sdhci_host *host) +{ + u8 mc1r; + + /* If nonremovable, assume that the card is always present. + * + * WA: SAMA5D2 doesn't drive CMD if using CD GPIO line. + */ + if ((host->mmc->cfg->host_caps & MMC_CAP_NONREMOVABLE) +#if CONFIG_IS_ENABLED(DM_GPIO) + || dm_gpio_get_value(&host->cd_gpio) >= 0 +#endif + ) + { + sdhci_readb(host, ATMEL_SDHC_MC1R); + mc1r |= ATMEL_SDHC_MC1R_FCD; + sdhci_writeb(host, mc1r, ATMEL_SDHC_MC1R); + } +} + static int atmel_sdhci_deferred_probe(struct sdhci_host *host) { struct udevice *dev = host->mmc->dev; + int ret; - return sdhci_probe(dev); + ret = sdhci_probe(dev); + if (ret) + return ret; + + atmel_sdhci_config_fcd(host); + + return 0; } static const struct sdhci_ops atmel_sdhci_ops = { @@ -120,7 +150,13 @@ static int atmel_sdhci_probe(struct udevice *dev) clk_free(&clk); - return sdhci_probe(dev); + ret = sdhci_probe(dev); + if (ret) + return ret; + + atmel_sdhci_config_fcd(host); + + return 0; } static int atmel_sdhci_bind(struct udevice *dev)