From patchwork Sat Dec 9 16:58:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Dasu X-Patchwork-Id: 176198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6148879vqy; Sat, 9 Dec 2023 08:58:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKgLq7SLgpZV9vFurwXGnjfqH0Pp2ZlsS/1lIOfR8SbbHVrXksXw/sLwpR4t1jTDS/l5qZ X-Received: by 2002:a05:6358:59:b0:170:17ea:f4f0 with SMTP id 25-20020a056358005900b0017017eaf4f0mr1313353rwx.61.1702141130626; Sat, 09 Dec 2023 08:58:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702141130; cv=none; d=google.com; s=arc-20160816; b=qb/3/eTeRBniRgKXp9Yc3bQC39e1lCspELYWtgKGqMoMy+g6Jx7AW23ydW5MWVO2yR 8AB39lNDp2JwoCJCu+OckVZULJzzmAtyApbBQUUcP7Od7WJ2KeXRA1z3fNOjSqXyffmU PJIbjRcJpPOs5YtfEI+2X5YMASiSDJ3eEb7JSLGSVikxnqlyax/yDcd1QjQpTiITlhFl prH93GlAqwWkFx/NAmy2YITe3xO/FkwU2RNF+owHUBO2YA843PICgPk0rvMs73H4jHf3 akbpJBuSmN+5PGwO8Veq6kpXO6djYMEJ9lNNX9I1A+DWP1mLWUjJP57SMEXa+nblCcrN F/Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=tOYL2KNMMzjWX62eDNGCnZd6PflhNAkUWoUeuLul9YY=; fh=kl6jwBYwyWQ8UusyU/LVQEf4sbplVtOrtPygnUZLHOM=; b=HSr14nN4jNPwQa4DblpgtMLpgVfzsxIHif6w086UNq/AYqyHlW4mca42b3b+iiBDvc eIPEMFsW4KSj8rcRLx73LKzULxDHZzXt0/M4HDuJZ4/mG3HB/u4d0PNXx0B1MByVYM20 dW1GYbi2L9QPNbrXxSVY4WDzUg5tjRqwTM0kmYoWjBEdVXOf3GynyIbU6jg9pTSph7g2 SvqR+AdN0omNbbpMSKtSKvVXQgDI1LPxqmlcIS8tSPcUa3CW9Sh1KSRZQ4WpqPqohff8 HM0F3CH4TI9B68JZw8/C8/aPVvy5O4j+jmaUFsnN+HvwDZ5m3jPmsib78DK6fq1uYNoA CvJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=ZqHOgmZl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u9-20020a170902e80900b001cf579f758asi3466958plg.437.2023.12.09.08.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Dec 2023 08:58:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=ZqHOgmZl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 455DE80613B4; Sat, 9 Dec 2023 08:58:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229519AbjLIQ6f (ORCPT + 99 others); Sat, 9 Dec 2023 11:58:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231334AbjLIQ6a (ORCPT ); Sat, 9 Dec 2023 11:58:30 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 459FFB7 for ; Sat, 9 Dec 2023 08:58:37 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-7b70db00e64so74646939f.2 for ; Sat, 09 Dec 2023 08:58:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1702141116; x=1702745916; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=tOYL2KNMMzjWX62eDNGCnZd6PflhNAkUWoUeuLul9YY=; b=ZqHOgmZlheeSTM9McDsV5fsuq8N3J+ojyNjVG4y6InKDlIHKsSb8hZN4dQetj9zmGk Q9LoiuJZGQ1XvHhG5ArqCmNtqB109y8qW7Py2+S7Q22YBAqXrTLnpuMpBjKXpZGO+F1O 0AcIfkyPT/XyjyOu4FaPIZgItQ7pCU+19Z5X4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702141116; x=1702745916; h=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=tOYL2KNMMzjWX62eDNGCnZd6PflhNAkUWoUeuLul9YY=; b=FzZ5LaZsE1YY2pFyZr/ZGw51LNgd+p1O2Vre7116R5eKEbswnwMyO3SeddbW/9WRoU NpUPXRktjM/q6kFe84BlUBHfNVs03e19mLqz1dQo/jey6cOnZ0bCCKTSSSfii/GSCyI1 YapVtJiphfHBkPQcHiWSKEpIjG80sTmG+xMLzH10cznXRbXJ29XaGc5unI2S0hxDKf9P go1PeQrxKVPMfTOS8rzQrWh0PYUgefyiAES6XtWthhXO1GvBrbYdsMYP9xk04T4n2i+E jR5ID/HC1SREdGKhEEOM/xToWmcUzePxGuje01nX90jNblIbFjhanvkSHrY0xgj9E3Af a6kw== X-Gm-Message-State: AOJu0YxuQ3BcigUFe+VYgJjIE6e66Jv1GLhJq+kSEcD3TdU5FrrLG9Es pWuz+j4LxafbvxynPQvqW07pcnwRCEvQwuSMeK2NrA== X-Received: by 2002:a05:6e02:180b:b0:35d:6aa4:d5d8 with SMTP id a11-20020a056e02180b00b0035d6aa4d5d8mr3184087ilv.37.1702141116529; Sat, 09 Dec 2023 08:58:36 -0800 (PST) Received: from mail.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id g14-20020a1709029f8e00b001cf7c07be50sm3595751plq.58.2023.12.09.08.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Dec 2023 08:58:35 -0800 (PST) From: Kamal Dasu To: ulf.hansson@linaro.org, linux-kernel@vger.kernel.org, alcooperx@gmail.com, linux-arm-kernel@lists.infradead.org, adrian.hunter@intel.com, linux-mmc@vger.kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, devicetree@vger.kernel.org Cc: f.fainelli@gmail.com, bcm-kernel-feedback-list@broadcom.com, Kamal Dasu Subject: [V3, 2/2] mmc: add new sdhci reset sequence for brcm 74165b0 Date: Sat, 9 Dec 2023 11:58:16 -0500 Message-Id: <20231209165816.39044-2-kamal.dasu@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231209165816.39044-1-kamal.dasu@broadcom.com> References: <20231209165816.39044-1-kamal.dasu@broadcom.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, MIME_HEADER_CTYPE_ONLY,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,T_TVD_MIME_NO_HEADERS 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 09 Dec 2023 08:58:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784824338214984155 X-GMAIL-MSGID: 1784824338214984155 From: Kamal Dasu 74165b0 shall use a new sdio controller core version which requires a different reset sequence. For core reset we use sdhci_reset. For CMD and/or DATA reset added a new function to also enable SDCHI clocks SDHCI_CLOCK_CARD_EN SDHCI_CLOCK_INT_EN along with the SDHCI_RESET_CMD and/or SDHCI_RESET_DATA fields. Signed-off-by: Kamal Dasu Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202312091608.0VbkRxlh-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202312091905.UGzltx8A-lkp@intel.com/`````````````` --- drivers/mmc/host/sdhci-brcmstb.c | 69 +++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/host/sdhci-brcmstb.c b/drivers/mmc/host/sdhci-brcmstb.c index c23251bb95f3..d4bd5b3c0fa4 100644 --- a/drivers/mmc/host/sdhci-brcmstb.c +++ b/drivers/mmc/host/sdhci-brcmstb.c @@ -44,8 +44,13 @@ struct brcmstb_match_priv { static inline void enable_clock_gating(struct sdhci_host *host) { + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_brcmstb_priv *priv = sdhci_pltfm_priv(pltfm_host); u32 reg; + if (!(priv->flags & BRCMSTB_PRIV_FLAGS_GATE_CLOCK)) + return; + reg = sdhci_readl(host, SDHCI_VENDOR); reg |= SDHCI_VENDOR_GATE_SDCLK_EN; sdhci_writel(host, reg, SDHCI_VENDOR); @@ -53,14 +58,54 @@ static inline void enable_clock_gating(struct sdhci_host *host) static void brcmstb_reset(struct sdhci_host *host, u8 mask) { - struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); - struct sdhci_brcmstb_priv *priv = sdhci_pltfm_priv(pltfm_host); - sdhci_and_cqhci_reset(host, mask); /* Reset will clear this, so re-enable it */ - if (priv->flags & BRCMSTB_PRIV_FLAGS_GATE_CLOCK) - enable_clock_gating(host); + enable_clock_gating(host); +} + +static void brcmstb_sdhci_reset_cmd_data(struct sdhci_host *host, u8 mask) +{ + ktime_t timeout; + u32 reg; + u32 new_mask = (mask & (SDHCI_RESET_CMD | SDHCI_RESET_DATA)) << 24; + + new_mask |= SDHCI_CLOCK_CARD_EN | SDHCI_CLOCK_INT_EN; + reg = sdhci_readl(host, SDHCI_CLOCK_CONTROL); + sdhci_writel(host, reg | new_mask, SDHCI_CLOCK_CONTROL); + + /* Wait max 10 ms */ + timeout = ktime_add_ms(ktime_get(), 10); + + /* hw clears the bit when it's done */ + while (1) { + bool timedout = ktime_after(ktime_get(), timeout); + + if (!(sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask)) + break; + if (timedout) { + pr_err("%s: Reset 0x%x never completed.\n", + mmc_hostname(host->mmc), (int)mask); + sdhci_err_stats_inc(host, CTRL_TIMEOUT); + sdhci_dumpregs(host); + return; + } + udelay(10); + } +} + +static void brcmstb_reset_74165b0(struct sdhci_host *host, u8 mask) +{ + /* take care of RESET_ALL as usual */ + if (mask & SDHCI_RESET_ALL) + sdhci_and_cqhci_reset(host, SDHCI_RESET_ALL); + + /* cmd and/or data treated differently on this core */ + if (mask & (SDHCI_RESET_CMD | SDHCI_RESET_DATA)) + brcmstb_sdhci_reset_cmd_data(host, mask); + + /* Reset will clear this, so re-enable it */ + enable_clock_gating(host); } static void sdhci_brcmstb_hs400es(struct mmc_host *mmc, struct mmc_ios *ios) @@ -162,6 +207,13 @@ static struct sdhci_ops sdhci_brcmstb_ops_7216 = { .set_uhs_signaling = sdhci_brcmstb_set_uhs_signaling, }; +static struct sdhci_ops sdhci_brcmstb_ops_74165b0 = { + .set_clock = sdhci_brcmstb_set_clock, + .set_bus_width = sdhci_set_bus_width, + .reset = brcmstb_reset_74165b0, + .set_uhs_signaling = sdhci_brcmstb_set_uhs_signaling, +}; + static struct brcmstb_match_priv match_priv_7425 = { .flags = BRCMSTB_MATCH_FLAGS_NO_64BIT | BRCMSTB_MATCH_FLAGS_BROKEN_TIMEOUT, @@ -179,10 +231,17 @@ static const struct brcmstb_match_priv match_priv_7216 = { .ops = &sdhci_brcmstb_ops_7216, }; +static struct brcmstb_match_priv match_priv_74165b0 = { + .flags = BRCMSTB_MATCH_FLAGS_HAS_CLOCK_GATE, + .hs400es = sdhci_brcmstb_hs400es, + .ops = &sdhci_brcmstb_ops_74165b0, +}; + static const struct of_device_id __maybe_unused sdhci_brcm_of_match[] = { { .compatible = "brcm,bcm7425-sdhci", .data = &match_priv_7425 }, { .compatible = "brcm,bcm7445-sdhci", .data = &match_priv_7445 }, { .compatible = "brcm,bcm7216-sdhci", .data = &match_priv_7216 }, + { .compatible = "brcm,bcm74165b0-sdhci", .data = &match_priv_74165b0 }, {}, };