From patchwork Wed Jun 21 10:01:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 695549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9288DEB64D8 for ; Wed, 21 Jun 2023 10:04:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232072AbjFUKEM (ORCPT ); Wed, 21 Jun 2023 06:04:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232192AbjFUKCx (ORCPT ); Wed, 21 Jun 2023 06:02:53 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBAC5E9; Wed, 21 Jun 2023 03:02:29 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-666683eb028so3316146b3a.0; Wed, 21 Jun 2023 03:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687341749; x=1689933749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MQhkkbl220OOjmhEpbjmN1GSLiQ0H1N57oOo51T5Ous=; b=QVTWyJCbzzhjmuaK6eykFkwHGjyw6KN4VVDYmMR1GShhh28cG0mNUIS/GD4kcOn67c 7AQk3qZMoRAO3ewrQ4TUZK19NXLLutPYqsXzmafon9WkZ4gGjoVHRCF2QHmN9kvvnmwK OtXVtIgrRREQygVgKc443VhZ7X1UT/xoHftOLoucZYNbMxay0F0BfZyRgmFd4XSOaaz0 fCqx68niLJaZs/b0/ZNEmM4kO9QuaRYC6Qo3xUO5QRnUfGtyARDzNs+ksgTUOutGrwwX JqLILGn0rh8bejxJtWET91LQuL+gCO4mdUu6WODqoG43YYSHVg/Exk81EeOKTG3rWZ5h La9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687341749; x=1689933749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MQhkkbl220OOjmhEpbjmN1GSLiQ0H1N57oOo51T5Ous=; b=F/y+d7CDbP2hxH33JHvOJ7F4+cKQVH4hFqrN+wRWVVSc7lVnEWagg0/gEbz01csbGM 32VFqJyKpZ0kTR9LsJinbx5LuPmPgRKuHfmCs22JUH1kGd7NH5bJ++mjBOQsyPOyW3hU gS+3gEHnt1xfcQeR6mDL0+iV7QwtX9I9UQTSRRf9SaL6QsH+NnOiU2CQzSdbB1FKnS7S uBiNCeAA3atLcyVyKgqvMyfYhJaB/Lxp6/4vh/KxewzeywV84RXITmtE8PfPqF09V7e7 u4D6BEFP4+4dIz8cQ8yEg0s8zsDNXXtd6jPqL4VLB+yJgtGVBWX2njJXfnckL+FrXWcs PQzg== X-Gm-Message-State: AC+VfDwW5ePsBIwWrib9c8QXmY7zdb8PJouWOW/vnJ98BGrvsIE6op6L kpwyHuQascc0GmZFOnX7flg= X-Google-Smtp-Source: ACHHUZ4BXMe2MztEtdaAZzFECRvLSIXW5f6SH4jh4DKgQELb0pagEw+P75aR2lseKNSLS7tn+2qkxw== X-Received: by 2002:a05:6a21:999d:b0:120:6b8e:9033 with SMTP id ve29-20020a056a21999d00b001206b8e9033mr7862832pzb.22.1687341749208; Wed, 21 Jun 2023 03:02:29 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e254-4eda-2716-05ea-20f5-b048.emome-ip6.hinet.net. [2001:b400:e254:4eda:2716:5ea:20f5:b048]) by smtp.gmail.com with ESMTPSA id g2-20020aa78742000000b0064f46570bb7sm2611196pfo.167.2023.06.21.03.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 03:02:28 -0700 (PDT) From: Victor Shih To: ulf.hansson@linaro.org, adrian.hunter@intel.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, benchuanggli@gmail.com, HL.Liu@genesyslogic.com.tw, Greg.tu@genesyslogic.com.tw, takahiro.akashi@linaro.org, dlunev@chromium.org, Victor Shih , Ben Chuang , Victor Shih Subject: [PATCH V8 10/23] mmc: sdhci-uhs2: add reset function and uhs2_mode function Date: Wed, 21 Jun 2023 18:01:38 +0800 Message-Id: <20230621100151.6329-11-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230621100151.6329-1-victorshihgli@gmail.com> References: <20230621100151.6329-1-victorshihgli@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: Victor Shih Sdhci_uhs2_reset() does a UHS-II specific reset operation. Updates in V8: - Adjust the position of matching brackets. Updates in V6: - Remove unnecessary functions and simplify code. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih --- drivers/mmc/host/sdhci-uhs2.c | 45 +++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index e339821d3504..dfc80a7f1bad 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -10,7 +10,9 @@ * Author: AKASHI Takahiro */ +#include #include +#include #include "sdhci.h" #include "sdhci-uhs2.h" @@ -49,6 +51,49 @@ void sdhci_uhs2_dump_regs(struct sdhci_host *host) } EXPORT_SYMBOL_GPL(sdhci_uhs2_dump_regs); +/*****************************************************************************\ + * * + * Low level functions * + * * +\*****************************************************************************/ + +bool sdhci_uhs2_mode(struct sdhci_host *host) +{ + return host->mmc->flags & MMC_UHS2_SUPPORT; +} + +/** + * sdhci_uhs2_reset - invoke SW reset + * @host: SDHCI host + * @mask: Control mask + * + * Invoke SW reset, depending on a bit in @mask and wait for completion. + */ +void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask) +{ + unsigned long timeout; + u32 val; + + sdhci_writew(host, mask, SDHCI_UHS2_SW_RESET); + + if (mask & SDHCI_UHS2_SW_RESET_FULL) + host->clock = 0; + + /* Wait max 100 ms */ + timeout = 100000; + + /* hw clears the bit when it's done */ + if (read_poll_timeout_atomic(sdhci_readw, val, !(val & mask), 10, + timeout, true, host, SDHCI_UHS2_SW_RESET)) { + pr_err("%s: %s: Reset 0x%x never completed.\n", __func__, + mmc_hostname(host->mmc), (int)mask); + pr_err("%s: clean reset bit\n", mmc_hostname(host->mmc)); + sdhci_writeb(host, 0, SDHCI_UHS2_SW_RESET); + return; + } +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_reset); + /*****************************************************************************\ * * * Driver init/exit * diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index 2bfe18d29bca..8253d50f7852 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -177,5 +177,7 @@ struct sdhci_host; void sdhci_uhs2_dump_regs(struct sdhci_host *host); +bool sdhci_uhs2_mode(struct sdhci_host *host); +void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask); #endif /* __SDHCI_UHS2_H */