Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4663610rdb; Fri, 15 Sep 2023 08:42:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuZfdlXep2+5k1kfR3OPbPq5W7n1cjFkO1NGFlyla4m/CSs/a+2cLe4QtF1fUu+/C7KJ+G X-Received: by 2002:a05:6a20:5488:b0:14d:16c:2d20 with SMTP id i8-20020a056a20548800b0014d016c2d20mr2627265pzk.44.1694792552180; Fri, 15 Sep 2023 08:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694792552; cv=none; d=google.com; s=arc-20160816; b=FYATbnjgJH1N+idJz7oN0BcbSCIC2NvYrG8e5N4uQIUXEFJnkStKwIfs0okxjo4EjA jh5FZQMQYn0OpJEmzel1DhrkhJhHLtS+r9x+neQeURUP0yVh73Iosac1UgIxC+kavQuN VCJ9XNFOC6AkdVkdXn6pITdBR9sPWjBDj/nXjDBzMF2bmEWnWzkmFT+cxbjgPMznHtfq BeuEz/B6E3VCzYkVKS6LwDQ/TQndzEfhBlV+TF1x/LaQgbYTZQ8nWb7jgxrFdshbO6ON 1OiyMhFW9mcAmC+s3Is1FHwyGz1OsV3oQo3YXpVChOU4eVATiD+C3Ub2xRKLIsbKxJxW 4N+A== 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=EGi6sD/0z+vEmIB7Q0DnnHWWHQnmVsUVEwzrXdfL/i8=; fh=y5fk6vguAkbcel7KoRWpitGO8B8BpGYTQpzSdaI/dY4=; b=iihUb8y3P2yUpw87K7rkcZj1YNwzLiORANXZnWZNUw+LmTmnkUpBpjX8igPU+6uBtJ UkMuXpVQok8bmI1XHk9cwXsQCBQ6pNcWi1UQOkDBKD8hOgJTlqVgW367XLr6z5HIzjjJ AIBUDAgm/d6HIC15GxT3aGaiV0bH7MPpP7h5U27noZVICVvXjgIpNfs43hKFCl24/QmP 1R5kCWsj2VLKtFpuhUWe37ClEChqDPugqkGiOpP2fdRlalm69RLQ0/dvOSrPHLJlytCt VOY0Emmg1/bolCAatlHaw6zRUiQR8+BeZH3RIHnXkO1W5do4TImmnpF5+sXOzfm7NUxM bP/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cdF00aMj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id fp7-20020a056a00608700b0068fce0c7193si3474765pfb.282.2023.09.15.08.42.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 08:42:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cdF00aMj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 0ACC680698EF; Fri, 15 Sep 2023 02:46:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234003AbjIOJpZ (ORCPT + 99 others); Fri, 15 Sep 2023 05:45:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234045AbjIOJpO (ORCPT ); Fri, 15 Sep 2023 05:45:14 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C24E62D6D; Fri, 15 Sep 2023 02:44:34 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-26f38171174so1546745a91.3; Fri, 15 Sep 2023 02:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694771074; x=1695375874; darn=vger.kernel.org; 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=EGi6sD/0z+vEmIB7Q0DnnHWWHQnmVsUVEwzrXdfL/i8=; b=cdF00aMjkd+G2i/PhyAmApMVrIQT9WPGyVBvR/pTLsuTioxDXy7n+/x/sUA6rkBccp ahdOPulUkfNBnI8xvMC/0h23+LWgXvoWeb5LCYhjZ+k17jM7QgE78KiaCc2La3ICNsuk eSFoOQ1DBU8JQnq3ZWGqbHRbVZYg6JdfxcSGp3eD2bxxmrT2hArnrOQFaLKvRfxJGu3e hSbylsEDmUzi9feT/Pme/TZlaOxbauiNho+RpvNizhDOBizszO4Oo7Jcj8UHTukG5shB POXpzY4MCs8RxHgdWshH6ozgu6Ifer2ewy/T3zaV1Fn+A85TlP3IgJmVAQocXYgbPP0s ie1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694771074; x=1695375874; 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=EGi6sD/0z+vEmIB7Q0DnnHWWHQnmVsUVEwzrXdfL/i8=; b=n5KouBf/A8UbYstB8DVFRy/MwZw7n7KSDj4RCsW8PPe+NvLsIJGyqPsRnZKAI0MmKy +xtWY+1Pemi5fhcrDJmIKr4Bv27Neav9TAmC9apGrYkzPz8K3FAKHGm7uC9FjCq2FR4J kY75qHh4vLtdWdDsPXZFLVjyp+gdMRBVv10BIZqXDjYqKVmjFRffziMOKbissxw/hbsI dWA1jQuWIVx4YweFxva9y4XrAHBgevwthkmlcA68Tax3H2Db7GJuV72+phhm7garvoDM wXmGlOQX9tEiSDv17+wexKpCDSifXECH5x1Va+VPp9VPdWOMphRF6gHl/apguU5odcqd BTvQ== X-Gm-Message-State: AOJu0YyvErqfeBfUfwpfZlgI7fbEM9Y8HZgnel/E5U3Uy1DCwVrY3X3d DpYqoTWBEYTjwTN918JGib8= X-Received: by 2002:a17:90a:a609:b0:267:fb26:32bd with SMTP id c9-20020a17090aa60900b00267fb2632bdmr977053pjq.7.1694771074192; Fri, 15 Sep 2023 02:44:34 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e2a6-6d77-d32f-f490-6688-3d32.emome-ip6.hinet.net. [2001:b400:e2a6:6d77:d32f:f490:6688:3d32]) by smtp.gmail.com with ESMTPSA id x4-20020a17090a530400b0025023726fc4sm4432794pjh.26.2023.09.15.02.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 02:44:33 -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 V12 13/23] mmc: sdhci-uhs2: add set_timeout() Date: Fri, 15 Sep 2023 17:43:41 +0800 Message-Id: <20230915094351.11120-14-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915094351.11120-1-victorshihgli@gmail.com> References: <20230915094351.11120-1-victorshihgli@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 15 Sep 2023 02:46:32 -0700 (PDT) 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 Acked-by: Adrian Hunter --- 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 */ -- 2.25.1