From patchwork Mon Oct 17 09:11:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 3313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1347761wrs; Mon, 17 Oct 2022 02:18:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xLz3zxYEpZjuIHCyOfoO0FImtGJzF2GQZtOzrW+pktq+uoZEhbGIrTEC6JajXXov2q0BL X-Received: by 2002:a63:ea58:0:b0:45f:ffa9:60a0 with SMTP id l24-20020a63ea58000000b0045fffa960a0mr9916455pgk.433.1665998302321; Mon, 17 Oct 2022 02:18:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665998302; cv=none; d=google.com; s=arc-20160816; b=OZdSpf8HJ9Zi5o2D3XEvxowLLuPCincJgZli9hASj3jVuzo400tSGTycC9y0CFPRgl ve9JKXlGGjjhs6Q61TZZVpKL0i81NWeurBb01ZI5TcvnZZ//gRRKwYaQyWZsDk5HGhQ2 OHHUdS5VP/Ujaa22L1cC2dvosyz4KW0vHJwe9mRioTGryigegeiHvRxtgoUgp+cU1pSG TdiBSJftGXyS4rHfTZzXcdKvlvJwJ4dAAsPmyDgA7yzxr2xYG8hR4dF0Vpao5KJ54lAP /jg5CtOtoo+buJtHpb5w/hbr3VCoGiSKBEu2d0BgK2QOeNb9dBkmL3EX7PEAMDf4dR3v 0xlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h5ky6yRKLirOgAuzcb87q4FCsZ9Aux469YNihh1WRPk=; b=IDq+hi56zw7Z1HF/cs6nDxVbvqNTR63Z2i1Bt/d3DnOTUwRlZrowjsAk04r2Il+OJg SZ2tHYNJOBMY3q9rQgoT1mO0qEpU/rxSONwyMQnUHOb+yleHOYdv3z7vUBHwDSTPRuYL Dcy2urIJAYR1Vz+gpHX0GiBBtQGxB+AK0lVWJ9yvy3el4TnJxeL3OKg8rM3BLKU3SKd6 x/0HM++JbZpIP0/ZnXBT6X+7p2cpC6AXOEB9eJbUTZzf06Y12rFqwi5JFdVGWWLn55nB 3mfwSrRKv5l+fpyPd7c66mtafi828iNUOJZWe7acaMcxUPrx/I3ygA47ThggU8RhgENP Hrww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LCiAMVeH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020a63d94e000000b0043cae020a12si11361493pgj.378.2022.10.17.02.17.59; Mon, 17 Oct 2022 02:18:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LCiAMVeH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbiJQJOQ (ORCPT + 99 others); Mon, 17 Oct 2022 05:14:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231222AbiJQJN2 (ORCPT ); Mon, 17 Oct 2022 05:13:28 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF154BA7C; Mon, 17 Oct 2022 02:13:03 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id i3so10489860pfc.11; Mon, 17 Oct 2022 02:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=h5ky6yRKLirOgAuzcb87q4FCsZ9Aux469YNihh1WRPk=; b=LCiAMVeHcYmVLz4j7kDEOEuc3K3J56MBIcWcSg/55nGw3o5dt07to9W3GYhLBtvnBK gqAbTLQE2Do0Qz67tSNodhslopkR/o6IXMOkqJI3shyEqSGtFCnuY2K/Zmm9aHZnMhnG 4Hld5EvhzYbc/4b8X9kvruYzB2AXa5WuvGM1pBBejv6G3K0cZtKd6wAy0+KWXFvDD23k gs8p6piRlgavlttmKitqcivw3WJgoF/XS1t902Kl/QqZGIM4sW/1GtdQSearuiAnw8Ks jwkyVgsWOd7pm31iC03BTUN+W5V1e1f9Z1fPXgsM/VugSrMcS+atMLM3M1NFM4wszJ1s D+XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=h5ky6yRKLirOgAuzcb87q4FCsZ9Aux469YNihh1WRPk=; b=ZGu4lFv241Un0oVO/s+HZ1NPEtOojfZdsI7RLKBLcToQ7SGFoSp2krZ3ONdZFe/C+X Q74FiY3ZqNGQyzZ/J4KYpf4JbJzJjTPo4CiafHVe7CuZqWf3U03oDX3reUAuX1xQ4nQF /PdkSTikUvKw/es99u840UGVAxKONLtQteRZp5iT/P/zd5z/4ozrorqGcbHEPgiw4TNo TxFvZhHg3GqW0R5OkbMYd27LMpVqj7NnHVg4DKitxrc4ZgufJ/uptNGzUHfW+TCzhHqa ntyOOSgI9Tfz3qVgNMj2DAoaQHOmSAv2U93YiAwoBNqI8hC7u/uOv8qz7DzkrDrAybzl UUlQ== X-Gm-Message-State: ACrzQf0SZ06T5rFxCDVIM18bwHN38HbYA6TBUpgApLU/zgRHmlQ8fC7g uR+tMhKdTO/IZrcN4GJIbwQ= X-Received: by 2002:a05:6a00:4214:b0:562:67d0:77e7 with SMTP id cd20-20020a056a00421400b0056267d077e7mr11973951pfb.62.1665997972815; Mon, 17 Oct 2022 02:12:52 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e258-8c34-4ca3-4989-34c1-7890.emome-ip6.hinet.net. [2001:b400:e258:8c34:4ca3:4989:34c1:7890]) by smtp.gmail.com with ESMTPSA id t22-20020a170902b21600b0017f75bc7a61sm6091996plr.166.2022.10.17.02.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 02:12:52 -0700 (PDT) From: Victor Shih X-Google-Original-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 Subject: [PATCH V5 14/26] mmc: sdhci-uhs2: add set_timeout() Date: Mon, 17 Oct 2022 17:11:41 +0800 Message-Id: <20221017091153.454873-15-victor.shih@genesyslogic.com.tw> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221017091153.454873-1-victor.shih@genesyslogic.com.tw> References: <20221017091153.454873-1-victor.shih@genesyslogic.com.tw> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746925836030037169?= X-GMAIL-MSGID: =?utf-8?q?1746925836030037169?= From: AKASHI Takahiro This is a UHS-II version of sdhci's set_timeout() operation. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro --- drivers/mmc/host/sdhci-uhs2.c | 85 +++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 1 + 2 files changed, 86 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 4dc3e904d7d2..2b90e5308764 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -196,6 +196,91 @@ void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, } EXPORT_SYMBOL_GPL(sdhci_uhs2_set_power); +static u8 sdhci_calc_timeout_uhs2(struct sdhci_host *host, u8 *cmd_res, + u8 *dead_lock) +{ + u8 count; + unsigned int cmd_res_timeout, dead_lock_timeout, current_timeout; + + /* + * If the host controller provides us with an incorrect timeout + * value, just skip the check and use 0xE. The hardware may take + * longer to time out, but that's much better than having a too-short + * timeout value. + */ + if (host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL) { + *cmd_res = 0xE; + *dead_lock = 0xE; + return 0xE; + } + + /* timeout in us */ + cmd_res_timeout = 5 * 1000; + dead_lock_timeout = 1 * 1000 * 1000; + + /* + * Figure out needed cycles. + * We do this in steps in order to fit inside a 32 bit int. + * The first step is the minimum timeout, which will have a + * minimum resolution of 6 bits: + * (1) 2^13*1000 > 2^22, + * (2) host->timeout_clk < 2^16 + * => + * (1) / (2) > 2^6 + */ + count = 0; + current_timeout = (1 << 13) * 1000 / host->timeout_clk; + while (current_timeout < cmd_res_timeout) { + count++; + current_timeout <<= 1; + if (count >= 0xF) + break; + } + + if (count >= 0xF) { + DBG("%s: Too large timeout 0x%x requested for CMD_RES!\n", + mmc_hostname(host->mmc), count); + count = 0xE; + } + *cmd_res = count; + + count = 0; + current_timeout = (1 << 13) * 1000 / host->timeout_clk; + while (current_timeout < dead_lock_timeout) { + count++; + current_timeout <<= 1; + if (count >= 0xF) + break; + } + + if (count >= 0xF) { + DBG("%s: Too large timeout 0x%x requested for DEADLOCK!\n", + mmc_hostname(host->mmc), count); + count = 0xE; + } + *dead_lock = count; + + return count; +} + +static void __sdhci_uhs2_set_timeout(struct sdhci_host *host) +{ + u8 cmd_res, dead_lock; + + sdhci_calc_timeout_uhs2(host, &cmd_res, &dead_lock); + cmd_res |= dead_lock << SDHCI_UHS2_TIMER_CTRL_DEADLOCK_SHIFT; + sdhci_writeb(host, cmd_res, SDHCI_UHS2_TIMER_CTRL); +} + +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) +{ + __sdhci_set_timeout(host, cmd); + + if (host->mmc->flags & MMC_UHS2_SUPPORT) + __sdhci_uhs2_set_timeout(host); +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_set_timeout); + /*****************************************************************************\ * * * MMC callbacks * diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index 3179915f7f79..5ea235b14108 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -215,5 +215,6 @@ bool sdhci_uhs2_mode(struct sdhci_host *host); void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask); void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, unsigned short vdd); +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd); #endif /* __SDHCI_UHS2_H */