From patchwork Tue Jan 2 16:09:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Dasu X-Patchwork-Id: 184397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4536186dyb; Tue, 2 Jan 2024 08:10:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAafrvmDTXKBqgg2/g5RoW3obnnUts8piOMfdWmFnc9qafkSfjrKpylaTHf1xbm9pPEWok X-Received: by 2002:a05:6102:3fa2:b0:467:2212:a443 with SMTP id o34-20020a0561023fa200b004672212a443mr3671578vsv.23.1704211805805; Tue, 02 Jan 2024 08:10:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704211805; cv=none; d=google.com; s=arc-20160816; b=fu+ImjLBy7WULw7ZR1Gg57dkWFPZ0Jw9/h1zN3xxlEXkp/zPHjQEeUyF9w2mdpb2NQ izsQEwDIpisQACeN3lGne5aaCq6Rdwyc7NzQv53suCRF39Pry6Burapxmp5wLPC7gbvl lyXBLb3eQOrIx04LR4cYF4yFQppJjeR5uKf2CBDorTBTbOmc7Fukigl4ag2JYRER6OFY o63bRtCSifc78knNwtlDFQGQaafPREX3aMKhvDto6VsCmJFQy5Z2OOl3YPRftz+C4noW 7lkW+UGP1FPlBZnr/j+IHUZQmkZqRYvFJ/XxCUAqbfWckVKk0LWABE3rxzrLsAhYBJLX jJhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=pfrYnQ2VeA7FSOetZv6xln9JGe69fYiqroiSkvqVflw=; fh=kl6jwBYwyWQ8UusyU/LVQEf4sbplVtOrtPygnUZLHOM=; b=PXiigVsaA4FfOVDxPYLQ+vK6NW42uJ0+vJ1qRJmY1yKAgzrr/Y8hZEBKbzFOy6AdYk d+gMPAcSOlFfD7Xgy+zXy/d3W9VKQoBsQseHQ+g+xobMySVA3kJ29lm1ednnxC0CMxq+ CXwo76zWg62EVtyl/OnFd9Cg3w2WWSxPJ3UyW1iy5mEj2FUTxNcHZSK7hIBiy4JCovbl Rt5yKlmIS0BDQ9Vbe2Aa1aEzD/fOKZ1tsdWjIcyp+9lNM55HJYkJtbbYo6gS4JKVFeWs 5xpFD07fb65IY+brkzBCNKxlOU27SAl0CLQ5mW0znZ9pwPoLNqvhN1okM1viOaXCZAVk qhVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=dTX8tc9m; spf=pass (google.com: domain of linux-kernel+bounces-14586-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14586-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q22-20020a67e9d6000000b00466df8c6084si2490618vso.294.2024.01.02.08.10.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 08:10:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14586-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=dTX8tc9m; spf=pass (google.com: domain of linux-kernel+bounces-14586-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14586-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.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 8204D1C222F7 for ; Tue, 2 Jan 2024 16:10:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37557154B9; Tue, 2 Jan 2024 16:09:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="dTX8tc9m" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (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 344F214F92 for ; Tue, 2 Jan 2024 16:09:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3bbbd4d2b4aso4713286b6e.0 for ; Tue, 02 Jan 2024 08:09:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1704211759; x=1704816559; 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=pfrYnQ2VeA7FSOetZv6xln9JGe69fYiqroiSkvqVflw=; b=dTX8tc9mUXN4KqgTOYrX0ismtLvtlOijgCkV23j9HsgDKYk1v/rIkjcEvlJA7KyCoR Gay1Boe9BAjdjUTY4CZDd1uAE7nAOisa/23bwFoXwqcILPOeST5KOivf/HldG6l39X9c xw59GO0pLV3CWx69OE2uL5fBTviPtHM1UhelU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704211759; x=1704816559; 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=pfrYnQ2VeA7FSOetZv6xln9JGe69fYiqroiSkvqVflw=; b=N+5Sub7V99AilojR5Woyax3KuOy6WjhzubtYx712ntoMxv00vqZVGDBN3L09oOVITj cNvxU/Bw6LY15gwIr4UuCeLG2jLqQOXoMOPkpbP4fXAj5caxxn3W6zC7qlx5JfQspR8z kDLr0S61VyEFAdddl/lAb8Lqwk9WKpsQWMad6DXGyCJQhBUcr8JwCJI91ttdeknbEHXp kcpBoeZRWzOHI+ST4i7DeaH091YRuaBYa+u8mcUwQWY5AGiQarSPsMI7YtowfaMGz450 DUZGoPHYqqkZNckxo6Is1YwUFaD+KXjSh047LN4d8rT3eZn8szOKAdbaYq3djREsSEyI jyXg== X-Gm-Message-State: AOJu0Yx65eX9Rtiy2TTck74eij5MR9RbXMDrqCdqUcvCshhI29LAlnyB jYBuclVSU0S+axFM5+etRSqw32Oye87MPIz9e2IqZXwbv7v3 X-Received: by 2002:a05:6808:107:b0:3bb:c65c:2c58 with SMTP id b7-20020a056808010700b003bbc65c2c58mr9407756oie.101.1704211759300; Tue, 02 Jan 2024 08:09:19 -0800 (PST) Received: from mail.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id hf8-20020a0562140e8800b0067f6f8c2a66sm10137520qvb.126.2024.01.02.08.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 08:09:18 -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 v7 2/2] mmc: add new sdhci reset sequence for brcm 74165b0 Date: Tue, 2 Jan 2024 11:09:10 -0500 Message-Id: <20240102160910.15485-3-kamal.dasu@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240102160910.15485-1-kamal.dasu@broadcom.com> References: <20240102160910.15485-1-kamal.dasu@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786995570106330295 X-GMAIL-MSGID: 1786995598489475888 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 SDHCI 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 Acked-by: Adrian Hunter --- 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..9053526fa212 100644 --- a/drivers/mmc/host/sdhci-brcmstb.c +++ b/drivers/mmc/host/sdhci-brcmstb.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -44,8 +45,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 +59,53 @@ 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) +{ + u32 new_mask = (mask & (SDHCI_RESET_CMD | SDHCI_RESET_DATA)) << 24; + int ret; + u32 reg; + + /* + * SDHCI_CLOCK_CONTROL register CARD_EN and CLOCK_INT_EN bits shall + * be set along with SOFTWARE_RESET register RESET_CMD or RESET_DATA + * bits, hence access SDHCI_CLOCK_CONTROL register as 32-bit register + */ + 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); + + reg = sdhci_readb(host, SDHCI_SOFTWARE_RESET); + + ret = read_poll_timeout_atomic(sdhci_readb, reg, !(reg & mask), + 10, 10000, false, + host, SDHCI_SOFTWARE_RESET); + + if (ret) { + 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); + } +} + +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 }, {}, };