From patchwork Fri Mar 31 10:55:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 77727 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp477147vqo; Fri, 31 Mar 2023 04:06:25 -0700 (PDT) X-Google-Smtp-Source: AKy350bu4UdrrWqundL4I2/xOb3izxPsEM0ZOFzoZYSCwOhy/q7TwrgkT1m3kI1I2bbZ61690bFW X-Received: by 2002:a17:903:2903:b0:1a1:6584:31b0 with SMTP id lh3-20020a170903290300b001a1658431b0mr23823859plb.30.1680260785433; Fri, 31 Mar 2023 04:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680260785; cv=none; d=google.com; s=arc-20160816; b=q7xlmu0ePLKhrV3Z4acItwRHJYebBaRVPl5HMI7/V4G9Fk3Y9a7+U35al5wa3Ai6EG +xKlRqGqK//IxZYC5LHNl23ANG8/TeKiRB9xvs0hQw4lzb+1vSoFCdBg9EvdAJkP+ACf zchk1AES74FuCpAobg5xIQTalV3riFvr2rspVtb5tIb248Ank1FVHjVzg/kXGC2PjxQu X96Jb0IpSuAI0UUoURXF9EZV/4GEkpBuhbC3iysPDVUJ9l5bfd6Ir/vaSQn7+ihTV02x gvKPTQ7xefBdfbpYDh+KysxTfLKFiA/yiUNHXHSvT39Dtq7mkcBZaylom/M5QKjdfS0I 0r0g== 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=Wp30TZgq7jKbpo8InJLkytMfD3sdBwQgwReNUO4+h3A=; b=orwQgAVafOG4DlXiTp8TDYtN4goalVEMTm89vEuj1woYLa7aDuq41b0/4KihfO6fDl NcN6aZsRNHWOTtrOrGNTA3pOsxYD/xuLxAnTfXfUalEuI46VtcG7JGILlJPpVerSqUv2 bVohaa5cf8kdrV7kVwucE2ITGkZ/ONzFwceVF7/f5+6ytybW7wvbVqAngu3q1C9Iae15 peLoxpnJDgQMci4brlmlWcVIq0O/miOnir68IiB1K26Kqvv/IR07eCX4Ml1lQLbH95TT BDmnRBvEuxtsj0XZbkkStagOYmPcIk7fldDa+bcvQiiMEmpAlIegtLheRMSPMZ+2cHmO lN5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AMt6y63H; 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 t185-20020a6381c2000000b00513576ea7casi1611519pgd.795.2023.03.31.04.06.12; Fri, 31 Mar 2023 04:06:25 -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=AMt6y63H; 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 S231967AbjCaK6G (ORCPT + 99 others); Fri, 31 Mar 2023 06:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231818AbjCaK4y (ORCPT ); Fri, 31 Mar 2023 06:56:54 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2499E1DFB8; Fri, 31 Mar 2023 03:56:41 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id o11so20895222ple.1; Fri, 31 Mar 2023 03:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680260200; 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=Wp30TZgq7jKbpo8InJLkytMfD3sdBwQgwReNUO4+h3A=; b=AMt6y63HsQkvVBB3Zl90YYI96BX3sSyiEmVwU15sWWTCfrngdEwCCD5PJLbd9pfBQc TwzS7RC1mydjAUl60PiuGX5Rfzcy+xLI6z3Pz3kQZUWNdTjmUmUEronBTUpj2dEm3gCV qdgvCiSJ/S1B35IrfC6+/12TDQ1y8WmHeWI/fs064v+W/+miiByDKuXpGitXmzrp8W6a m2q9A9U5GoBYeADyjPwhenyfCdZl1SlRa8zuKi2TYfRzQDbvWgsN1sAHtb2bd8fh+XfA N0OrC4tB+mZG1CZaHJJOJUK1jJi9bnxfv7K6Skuef7On8uC6zBR/q+gp42H/IAHO62nd f6jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680260200; 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=Wp30TZgq7jKbpo8InJLkytMfD3sdBwQgwReNUO4+h3A=; b=kF+7Jyn6rYL73smwG6GbNqVWDDqNdIlesoybO4PiFLIBOnZVL18p23n7rYHgIunG4T aL1Mgem+SiD3AE7X4cwtT6sL1r8jAGrGG/fIwsdgLBC16AVAV4yG7pZ1i9vl8k5BW8oZ dRyGs3bbGHnYFOTvKjqdS8mOuEtqNZE9Ey2BXBZl8s/fBWihL1Er2NiaCaRa5twu9RmP FkCobZn4leuPtOTa9K4Yiimn4ND7sE7jExxF3LoC61iSqEGz+pCIttRvBpvlB7BhIrvw AfWanEqeQNCbMfbXNmxgZodUEH9dWxzTnhjO0Sft6hoxxe/PyFgsibHkehynCYBDeVPP Apyw== X-Gm-Message-State: AAQBX9cl2Z9icWnrUTZorWJuF4ZCCzf7fDnlf1rVlWtYMoAAuzBw3QzP 3DHOYep1dSh/QPrtQpCwvLk= X-Received: by 2002:a17:90b:180a:b0:23f:aa93:6cfd with SMTP id lw10-20020a17090b180a00b0023faa936cfdmr29807856pjb.18.1680260200590; Fri, 31 Mar 2023 03:56:40 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e25c-983f-c7ff-3efd-77d9-6c16.emome-ip6.hinet.net. [2001:b400:e25c:983f:c7ff:3efd:77d9:6c16]) by smtp.gmail.com with ESMTPSA id f19-20020a170902e99300b0019acd3151d0sm1287665plb.114.2023.03.31.03.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 03:56:40 -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 V7 13/23] mmc: sdhci-uhs2: add set_timeout() Date: Fri, 31 Mar 2023 18:55:36 +0800 Message-Id: <20230331105546.13607-14-victor.shih@genesyslogic.com.tw> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230331105546.13607-1-victor.shih@genesyslogic.com.tw> References: <20230331105546.13607-1-victor.shih@genesyslogic.com.tw> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, 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 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?1761881133056495066?= X-GMAIL-MSGID: =?utf-8?q?1761881133056495066?= 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 --- drivers/mmc/host/sdhci-uhs2.c | 72 +++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 1 + 2 files changed, 73 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 388d87537847..e2e9ce51b768 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" @@ -144,6 +145,77 @@ static void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, } } +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; + /* 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 |= 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 6834893eee85..fc03a178b676 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -180,5 +180,6 @@ 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); +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd); #endif /* __SDHCI_UHS2_H */