From patchwork Fri Jul 21 10:13:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 123774 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp114323vqg; Fri, 21 Jul 2023 03:46:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlGOnJsUHIupvlQsccvzH1bCTrfpsCxJGVrt/fqd0oDWjKb5kD95bbnLbNkDyWqLq4lirXbj X-Received: by 2002:a05:6a20:b903:b0:136:e26b:6401 with SMTP id fe3-20020a056a20b90300b00136e26b6401mr1435152pzb.16.1689936367826; Fri, 21 Jul 2023 03:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689936367; cv=none; d=google.com; s=arc-20160816; b=kvYTlOz4EYgN8QrxdfftqeFPHsGSN3avGxoEwLDjTROd1yV37Nv1IYr31XTn4o033h X/kROasZ1avDSyflHtdEc7QVU+0YtEXpM59JLt/RXH3XomgHu59ST94NwHFso43OofIn HsqnXi1+66DomaZVRMnjn0BZLTkm+EHbK7W2RFoPL4GT4Wpc+n70BqeFDJrvqKE8/TTu 7lTyTQTlO7zPL+7IjNSC478dmsSLniB0opnOWM85RkrYSfIWB8Q1d1TD77GE4z9OfKxE er28wcgfgcs4Z3nuobGx8SxgOV7GcdmeuPqRK5F67J/3LmhVi3OM/lMiJxZ/k1xFr4+f h7mw== 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=CoEbBebr7dmAMf5ozpSCS4n1CD0bD5XzTtblLDc2XiM=; fh=fI4q009785iZEQbMo9mPiCtk2O+O6Kfjq5womanK3eI=; b=Q+0Ugx5bps6YKSftszlw5KpRfmKlSGlxsGxq0ZrcnrQMSFl5416Kn0OP4sI2Lvxv0X Vw9urcASWQEUWz1wsm53D5JZxIZThlnoExImg31q7Xz/f8vGlaoWngkgoKNI4N0ykwMP Nz5/0JqbQePJUwOqFCsMKJBPoHtZ5elCT9pxkRWbnNSuboY4o9/tmUigYUNWz07RojWU SN78xRxaL6A5F6nWeeMw/dT+3tcyW1sYgR69NdvytFtdVBDF7tQ1obXcVwhSPsaGfCpL nrMGZJ+7jKSm9k2Bn6EEGCCeiHxOvBHKYZzHbYtnhfaUvaFqryG9VfYOfDnbwiRmiW2V M1IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=SiI+TGif; 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 o28-20020a634e5c000000b0055acc7f8088si2730867pgl.301.2023.07.21.03.45.53; Fri, 21 Jul 2023 03:46:07 -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=20221208 header.b=SiI+TGif; 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 S231656AbjGUKPs (ORCPT + 99 others); Fri, 21 Jul 2023 06:15:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231851AbjGUKPD (ORCPT ); Fri, 21 Jul 2023 06:15:03 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF0C73583; Fri, 21 Jul 2023 03:14:54 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bb119be881so12995735ad.3; Fri, 21 Jul 2023 03:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689934494; x=1690539294; 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=CoEbBebr7dmAMf5ozpSCS4n1CD0bD5XzTtblLDc2XiM=; b=SiI+TGifg1HNaMsQgY4N2ytccANVfwHGr5glj/sN/LTUQBABtfLhhCOgilXjNQ6wJ8 dPt+DZ8Zzi3DhpCVyqvDCdekTRd752baPYVVP9ySwSLIEd74dnU0qOIGLiH2OaKmM9zo QiQDuPcEY4Deu1WrBTQzcLCVTeheV38N1kqpZfKwxgASJEyb3MexY2nqnCds1AStyBkp j70pGrmVYaXDlbNURQdGhx25E5iYvQP+wvmCzzM+oubdfLM7cS7pHudp5GKhD63rg/VS uvffDOxalsoAsFdGCmiJpOq42jt5YjAEX+uA4VkDbv4oMPayLE9TYKaKkwdyxuNCJEtt vYdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689934494; x=1690539294; 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=CoEbBebr7dmAMf5ozpSCS4n1CD0bD5XzTtblLDc2XiM=; b=UZWgAaD0NjL7lB4cKUHEnPpfmZ+Ym26IkqOswLEOvCsgvJhbVX0h76UOH48lZKaEMp uSo0+2QxiocQ10NbBeizpaLjVMAhN3LBINCgtFWNcYw5bZIZ4ejkcoD3cDiaY9aV/KBN OOcY+wwdOGTABRmERkdgBHiH7igEkRUszMnA8YXm+kICxM9IaLYD221nRY/WvH9OS11M rKHiwkzEIg3a43kLh6ndDA9uK3EEadjDemo6XHdJWlXQGYO4mC2SJiD0GlAaR8hfdvM8 dqMSiITbnnHHNgHFwNBfX41Cn6vH8OID4naL/foc2o5vLQ1EPTtyVTRJHz+r85lSPM78 f9lQ== X-Gm-Message-State: ABy/qLYLEevQsU2JJbMi7XaQt9dR/HR0ZuBwPdRLPExnIUCbZZ3IgUT/ 74kYiwJChNsNeXaQwZnnNzbxUYDhs2c= X-Received: by 2002:a17:902:ce89:b0:1ae:10b3:61e9 with SMTP id f9-20020a170902ce8900b001ae10b361e9mr1641908plg.65.1689934494181; Fri, 21 Jul 2023 03:14:54 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e23e-6b0d-6c46-3684-497a-06ee.emome-ip6.hinet.net. [2001:b400:e23e:6b0d:6c46:3684:497a:6ee]) by smtp.gmail.com with ESMTPSA id y1-20020a170902b48100b001b86492d724sm3050719plr.223.2023.07.21.03.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 03:14:53 -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 V9 13/23] mmc: sdhci-uhs2: add set_timeout() Date: Fri, 21 Jul 2023 18:13:39 +0800 Message-Id: <20230721101349.12387-14-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721101349.12387-1-victorshihgli@gmail.com> References: <20230721101349.12387-1-victorshihgli@gmail.com> 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1772026716749441036 X-GMAIL-MSGID: 1772026716749441036 From: Victor Shih This is a UHS-II version of sdhci's set_timeout() operation. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih --- Updates in V8: - Initialization be combined with declaration and realigned in sdhci_calc_timeout_uhs2(). - Forward declare struct mmc_command in sdhci_uhs2.h. Updates in V6: - Use GENMASK() and FIELD_PREP() in some case. - Use sdhci_uhs2_mode() to simplify code. - Remove unnecessary functions. --- drivers/mmc/host/sdhci-uhs2.c | 72 +++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 2 + 2 files changed, 74 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 92fb69b7e209..d519e6ce6199 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "sdhci.h" #include "sdhci-uhs2.h" @@ -142,6 +143,77 @@ static void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, un } } +static u8 sdhci_calc_timeout_uhs2(struct sdhci_host *host, u8 *cmd_res, u8 *dead_lock) +{ + /* timeout in us */ + unsigned int dead_lock_timeout = 1 * 1000 * 1000; + unsigned int cmd_res_timeout = 5 * 1000; + unsigned int current_timeout; + u8 count; + + /* + * 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 |= FIELD_PREP(SDHCI_UHS2_TIMER_CTRL_DEADLOCK_MASK, dead_lock); + 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 (sdhci_uhs2_mode(host)) + __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 8253d50f7852..ccf4e1834c2d 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -175,9 +175,11 @@ #define SDHCI_UHS2_VENDOR_PTR 0xE8 struct sdhci_host; +struct mmc_command; 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); +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd); #endif /* __SDHCI_UHS2_H */