From patchwork Fri Dec 8 20:21:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Dasu X-Patchwork-Id: 176026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5699787vqy; Fri, 8 Dec 2023 12:21:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiRGB65oc7Hf9KypLGDzVI4L4eVY8QvE5/EIJC44dW0ca6qiGqvO8nGbB3ePpqpTU3HM47 X-Received: by 2002:a17:90b:156:b0:286:6cc1:5fba with SMTP id em22-20020a17090b015600b002866cc15fbamr575997pjb.61.1702066908327; Fri, 08 Dec 2023 12:21:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702066908; cv=none; d=google.com; s=arc-20160816; b=zo5PWF9tO3Dx/rXp+5Fnpz6WN13H9aLhdfYiNwRSSSEJWqeWxYY9ZWVn0OiYa/v6gq G0Em9Yo6eRYUqxxDsm8YP5oyUDhSL+Ng7sM6sWfwP9AtwxiFfRyeGU0X2FYN2we7rPq3 9fiCDbtnnNlKwu69v5iOfZUjf/vwhgtiAzUkaEMxGjqHt5BNje3frq8ylslmo3+XyNIl gQOnH1CEbVlOMKoZzJ7RzobaSljEwKAFv7/nQtGAqHZha5A1pDvRifxqiy44AF41Px+C nCqSn1NVv3KhgE1bPqyaw+uI6t1KUO5fJ6EGb+vSBgJWQ/3S4hRV05qrocpYURJ8XQ4A Mqjw== 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=p7nOtgIAzYvWmDiz/7FL/mpKM1eCnJ0KpW1zMMF6zOE=; fh=kl6jwBYwyWQ8UusyU/LVQEf4sbplVtOrtPygnUZLHOM=; b=u7j+1e1x6ISWlLXN21z/iffIAZqQEqCDMnTLiNSCETCk3nt75WKZHw+r++Of18rh4u 7HyqB86ptghle9c9+2yGV+woqkzBOflwcNQ6lSZXb9nYdadSYXXIPVAJhaRmlavY3hTr /j4BA3o2eu0CxgQsWyl7d7AdOTHb9qQ7Upmx+uPYXIk2SSOTPA0ewJYHqG5uXYWiaUHs +TU7+CgEBabwHGqFtu8GB+wP+Y9I1xBkNlEmsKXFsVKRhb2eZ2zXtOuFZYYW1hE7D8vF a9VG0PPwyjudPT0dJ8XvNlEInafAhI8ptEePV6R1daET+0BGVc31iphNhVDjbYb3iaVI fK1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=QHgDaoQa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id my17-20020a17090b4c9100b00286bc9f66b6si2220301pjb.62.2023.12.08.12.21.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 12:21:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=QHgDaoQa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 36DD780859A6; Fri, 8 Dec 2023 12:21:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234157AbjLHUV3 (ORCPT + 99 others); Fri, 8 Dec 2023 15:21:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234267AbjLHUVZ (ORCPT ); Fri, 8 Dec 2023 15:21:25 -0500 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 C7A301997 for ; Fri, 8 Dec 2023 12:21:31 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1d069b1d127so19358275ad.0 for ; Fri, 08 Dec 2023 12:21:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1702066891; x=1702671691; 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=p7nOtgIAzYvWmDiz/7FL/mpKM1eCnJ0KpW1zMMF6zOE=; b=QHgDaoQagu41Y8fuPqPrO8pBijm+Ev1/hYVapqIje1impB/+n62moNPdX1L81JPRxx FIU6oasQ0vr43AzFtAGCPSd9MMy0l/0l4h69GRRugKYKJt6VNeQxA47dZRl8PqFwvenM UsFdLTcLRLAj38WkW6Qw/cPwPVRvhkRExjGbg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702066891; x=1702671691; 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=p7nOtgIAzYvWmDiz/7FL/mpKM1eCnJ0KpW1zMMF6zOE=; b=GSzaHLIfq4s2Gkb8Tfp7mkS8wUki9g2OY69tTCG1pOGNsOBCWCXbS0j3Lra3C5qLmH xOv7fje+E9Xr6ViWngBV7yBa4Y6J5wshpcAOVNh3ZxM8Pb4X5fL9zl60SvSVVf6v2cqM 31weX7uS34uiadZvGda8P5pI/wMzH0tMs7CuM5alW9jvlpygrPmqZeWUhZFDvRZM/XOZ gOX7fP/8CYQN39C5vPfTQjmI9Uyt5IRBchwJQ/q8Pezkmwjn3eh2CGJnShYRLhPHrtqQ G0zcJXzZZw2DC57HAPDxmflJiGgaDlhFH+ss5xDVW6m4HAgSQjjxYIpJUUE5tQIxc4XW 61pg== X-Gm-Message-State: AOJu0YwkeCzkfcYT8Ntdm8GJMLCGuMfELunZRrikoVYkJlI8l5ltkcoT ZF4wLNWTurecS4ac1OVYKTvSvg== X-Received: by 2002:a17:902:c20d:b0:1d0:3eac:e66 with SMTP id 13-20020a170902c20d00b001d03eac0e66mr574433pll.29.1702066891085; Fri, 08 Dec 2023 12:21:31 -0800 (PST) Received: from mail.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id v29-20020a63481d000000b005c19c586cb7sm1952127pga.33.2023.12.08.12.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 12:21:30 -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: [PATCH 2/2] mmc: add new sdhci reset sequence for brcm 74165b0 Date: Fri, 8 Dec 2023 15:21:08 -0500 Message-Id: <20231208202108.7468-2-kamal.dasu@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231208202108.7468-1-kamal.dasu@broadcom.com> References: <20231208202108.7468-1-kamal.dasu@broadcom.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MIME_HEADER_CTYPE_ONLY,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,T_TVD_MIME_NO_HEADERS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Fri, 08 Dec 2023 12:21:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784746510741701575 X-GMAIL-MSGID: 1784746510741701575 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 --- 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..3fac471b5b5d 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 const 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 const 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 }, {}, };