Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2169981lqt; Mon, 22 Apr 2024 03:42:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVLVPShyXBvpIzg/ui2F1cLh7NqcrgbDPZg6sLOltXXYghkHIWlkcFNtc0aknVq86xVeigEYWA+F20uTRf6KaqMnI7B1ZpFJ3xiTTrzgA== X-Google-Smtp-Source: AGHT+IHJfHpLcrrWpHQ22EizQNPVVPklOnmMywI123YksISHdip5lS6c2h596/BNO2BDvtJm5g24 X-Received: by 2002:a05:620a:4388:b0:790:72d1:a615 with SMTP id a8-20020a05620a438800b0079072d1a615mr4447102qkp.67.1713782526952; Mon, 22 Apr 2024 03:42:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713782526; cv=pass; d=google.com; s=arc-20160816; b=t9hkc1hogGJatL2+XghDKeHLMqiiTj/4KYeu+EtHt2Uk/LpV2sla2WYoGoROIRiEC9 NK6vubSeMrNt3NUwsRvoHcYLwSa3X5ZeO4fJBTfKcon6FPB3A5WQdNZ4XVDTtS+VsZ3P qaTF4QlrNKGzJOA3GuR+YaWwRHxkKqlDxXFjE/5j2O7binkdwucZGjdt6XV4xyB3/Kvd kZGgksaPP//NR9i2V2oyXjSBGVPjCMwFSliRP4TfgzPu09R3//b3lT50Wm5TE0pY2yqo chZ7wMo5HL+mD06svZYdJfHPX8ieIJPP7C5Kbbfp/1pLAiPejrh1xAwHPyu0rZwTZifU 1pvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=0Fj7MKr2tOzge1qyOk9/xzb39EqiXpQi46erhjZRq7c=; fh=39hwyegWIGD/WHcf/39t6DTO6hoJSaNdZVvDonIfwWw=; b=AIHPeuX1U9cjFkk293evR8bU4kdpnjuCmnQo4kPbMoaao0E6UEU5id0y1xqxc6DHpX 66l7ONgTyZzeNnMl/LXiz3Ok+sE1khk+isYOdkyXjhEyVo7GkDCJmFFoaL5zG8EWLDr/ 2ZCukh7aDlgZeK9CcPYImRZ1mWQ6hhlzaV2+jOkj0d7llvx+8U+JEz107OA5th1rGCc4 f8/MyPqaLeHBGI9gPmi3ggGo7dPrneME6GbDqU9Z87CwkvYny9y4AgXsod0b9mC7kQ6V ZtqDt3htweLQhKbqbfF4gUNUd9ly2rWJGbmQ3n//obiiICrG8AGnnXDJC4mJ9fz2+HG9 fKyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Br9qKMT2; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-153213-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153213-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h1-20020a37c441000000b0078d3a3afba3si10091328qkm.746.2024.04.22.03.42.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 03:42:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153213-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Br9qKMT2; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-153213-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153213-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8B6511C20803 for ; Mon, 22 Apr 2024 10:42:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64D5D14F9F8; Mon, 22 Apr 2024 10:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Br9qKMT2" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0229915098A; Mon, 22 Apr 2024 10:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713782326; cv=none; b=bbS94+i94t9NmrTGjtqTS0JFdZQkBmBWoFVsGSUBvdQxS7bBidjrG85Ug0I2UrwjmjH+iy655Pzrt7zbJwip+wd3Opm9Mphb6GRYZFAdxB7kg6qnibTMc3auT8LxAYpfBsPU4MyJjYK6Wr9YJ6kcOJhEcY2MP23tOJH/O1dG73U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713782326; c=relaxed/simple; bh=Soy/+Fwgbt0INuM2cPmw0hhd0aE0PW8ni3wrIYcRiUQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tl1fvkLz9rxrdpLLkUM6t548rZygx1UzA+tINbvxnFi0uThOI2LAA9xStXeTuPCh0qPKUWT6KxSod1fVARLO6FOfkXmy2ynbS79OHu69GQJ4pdntyF2ticgRgPlywpu8xz+tsEdnEXL0JLW8A5v98hfY2OT4F3u8TBRsclOf8PU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Br9qKMT2; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1e3f6f03594so30869935ad.0; Mon, 22 Apr 2024 03:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713782324; x=1714387124; 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=0Fj7MKr2tOzge1qyOk9/xzb39EqiXpQi46erhjZRq7c=; b=Br9qKMT2d/PM/0ZV6Bh0g6bCZNtD5/82rh3CvCkm9aTuIWm25nn3P1W3JWe+kUcaPy nDscG4kjZBNDg96vlVSzodEb0Pt2nfefBrwVzhNBoAhyjbLaP9zBJNJv67wzT76xZrLn ylwzRVrRXyqGguRR+jnTpPN3P2wUcF3ldrJPwRGafmRd9A3dRqQHyAW4xqBdXwKnoUYB CsuYk0VIUF9q54Z1reyUag/2Jwsy10KeBPQEw789PWTlGmjNEZUuzgQNeK3mEKE0G+lz IWw7dD0djhP99A40nKdvK98s2m8cf4XEZxIPPB+KjiX6wKMo1nKfZ9yczyCZxZDicOOs RfnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713782324; x=1714387124; 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=0Fj7MKr2tOzge1qyOk9/xzb39EqiXpQi46erhjZRq7c=; b=f04jR5ySHREPSCWfQC2vgOIci2cEpAfCUcKkg9chrzeOrF3MkGEboL8cAqMhM5ZcV1 AfmmjnggAEIRKtNasqrPI5s2JW/pyqG2MX1VY2ACpTCQ2u5MVHDeiXV8CKyCNAi0NLEZ CylXuddrI7Zj3CNra4VpXgmcAYBd8umu3BmuOKPb+Gd4YnmSKmWX+y2dht1Tdg+/pHgU IIrcO9C2dcuMza7ZpMssxSLtYzVR3S7gmwjlkdjQRoLlr/qrY/b9Liz9nHqZAS0cmM59 mskK7tDp9IZFdnhaZM70bKBwryJGN2Dl+j1SfAuPmiGD1Ei80qJsisA0I/8wGjcjtELT lnGg== X-Forwarded-Encrypted: i=1; AJvYcCWF51PgyOp8tLlMlna47Pw0hQWoVLO0x4+oEAjTy6MOVaI+2IkNvKrIKof0G8NdJToNAWFLATxTIDOcsaJMaHsmDzFIwDhMVc2BWwGI X-Gm-Message-State: AOJu0YxxSyZDd43g4SwjTfkWNkpsqH0XYdn5iD7GXMEVUvlWWKxnHM1P 1td7qbKm8qIiAb1Kyiwg4diYTbTXlCohRHMV7irWHc2DOXaaIzz9 X-Received: by 2002:a17:902:d4cf:b0:1e7:b6f4:971 with SMTP id o15-20020a170902d4cf00b001e7b6f40971mr10998072plg.27.1713782324239; Mon, 22 Apr 2024 03:38:44 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e33b-6ac4-2bfb-4656-8624-cdbd.emome-ip6.hinet.net. [2001:b400:e33b:6ac4:2bfb:4656:8624:cdbd]) by smtp.gmail.com with ESMTPSA id c1-20020a170903234100b001e3dff1e4d5sm7807904plh.135.2024.04.22.03.38.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 03:38:43 -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 V15 13/22] mmc: sdhci-uhs2: add set_timeout() Date: Mon, 22 Apr 2024 18:37:36 +0800 Message-Id: <20240422103745.14725-14-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240422103745.14725-1-victorshihgli@gmail.com> References: <20240422103745.14725-1-victorshihgli@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Victor Shih This is a UHS-II version of sdhci's set_timeout() operation. Use sdhci_uhs2_set_timeout() to set and calculate the timeout time. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih --- Updates in V14: - Use mmc_card_uhs2() to stead sdhci_uhs2_mode() in the sdhci_uhs2_set_timeout(). Updates in V13: - Modify comment message. 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 8ad9a25484fa..8c802142e875 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" @@ -152,6 +153,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 (mmc_card_uhs2(host->mmc)) + __sdhci_uhs2_set_timeout(host); +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_set_timeout); + /*****************************************************************************\ * * * Driver init/exit * diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index caaf9fba4975..089a6c0cabda 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -175,8 +175,10 @@ #define SDHCI_UHS2_VENDOR_PTR 0xE8 struct sdhci_host; +struct mmc_command; void sdhci_uhs2_dump_regs(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