From patchwork Sat Apr 13 22:14:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea della Porta X-Patchwork-Id: 13628830 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 966D4C4345F for ; Sat, 13 Apr 2024 22:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5LCHHdotfq4I/FjCRmgdLz5pSYiuzyww3zG2mCFRamw=; b=i1X8a6R0/OR3kw HN/TXTal7608gQjhHUzKGl+GHsT4DjBZqesoCwurevFIlYm17GRZn1i3h+EXMSkl+/ohDS2MboPZL qoV5/jWBqrOsttPd5k54xDoeyCBoRFREH0EGUeBnWPtEl6ULIYxAQXWNzutmC4vwkbxC66Jg7n0uK s+1Jb8O+6leGlPXqZgeYYGGIIdRVdPrnIcOf2+JBupZyxd0UU6aNqBhwp9hgGNRy28sbZNlSnvU3m ps2W6XG5DPnVW7Y+zyDo7yWQmNiff+mMr7hzo7NKEBUz6S4PpC2vu0Y6X3yFJ+y6WiRCTTR+9DKWY TUIMbLLNNLbv9Meaw6Xw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvleH-000000044bv-1RFy; Sat, 13 Apr 2024 22:15:01 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvle4-000000044Vc-30MS for linux-arm-kernel@lists.infradead.org; Sat, 13 Apr 2024 22:14:51 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a5200afe39eso242980066b.1 for ; Sat, 13 Apr 2024 15:14:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1713046487; x=1713651287; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=OWTANOhwt+MSlpwP2S7BNom6jkNUFDJjf/oC5BBrk94=; b=UeMMTTUYiNhn6XmDt+ko5vPI9Mt8RWanWx6bIU8x25vU3jCqBbm88l5/Bt5gaFHKRi dFMwFwMx9voslPus1biDgRhvyk/dltlxqV+TGD61vspc2MKX3gAwFIMFvF4mLGpdWzwI 9qZOssSpuokGDP5DJltOBoJ5a7rlMMHJYPtfZ+ti5RH8B9HGbFv0iFsHThjQ2FG8fV3F ++bk/r70Vz6Sja4HjgGZ6l7092oA/DjgMW5tSMW2o60oUOwUs1f9X2bh9e+AMSJgNkea L8+r7gA+XsWEpM2xMZVHzOJiXIWtb144r1L/uUqEn6cogWGwPZqwlPKo0ATubNX7OPFk GBKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713046487; x=1713651287; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OWTANOhwt+MSlpwP2S7BNom6jkNUFDJjf/oC5BBrk94=; b=r4yEEgnFgPHWwz+OHWwcS/JTuE8CKKjuEzXkbD6mn+QCeFtrjlbDpIY4BsxTHL7vxx nguBY8AzHQ9JNxRlAn2Vdcqsy7xhC7t7ZZpBoPyfmtgCRK3Ix5w8J9ePWTWrKbAhSErQ LkUPmiLOshslTxsuz2PMWjUemNtkggo/VESgJH7izvc8daq0K+oTGO2aGeyjP2QEuQdf paRi6W0dAVYSoMTupE64wYB1tl8G7VJdPprw0ZSizVffiQcmZ3C9RwnwAjJUNFP2vYnD kAAtst31KbhfcWJf/kaEgpxVNxQD+wT9emOU/YF9/88Z66IT91cVZIZLjvhnHqi4mCO1 IWFw== X-Forwarded-Encrypted: i=1; AJvYcCVQK61kWDWXvSPGnYtoDKyuAHPZe5Nh7zZIIjEMZ97bRxCrky2rukYMuVY0f34Lv7Qeooc9RnY3ICDEwrQJj3Ilni/FScyNiAVimEDNIjl5i7fBA10= X-Gm-Message-State: AOJu0Yw6b3mztWEHQhg5FsX67q1cHcXaURquSpYE7DISj7zTdkAs4LgW y312zGVMcgLeAkCmyAgz1vJDlZauD49edg38oU4OzszS9R4NfSvQbrAx1+GHGT4= X-Google-Smtp-Source: AGHT+IGGACuxkVW15FsJ637ATg0ReSd4myxi07+XaFVDWXDTPQjXO0GYHx/ICzPrtC0Cv2kmv6xxKA== X-Received: by 2002:a17:906:2c59:b0:a52:5765:4850 with SMTP id f25-20020a1709062c5900b00a5257654850mr736703ejh.58.1713046486861; Sat, 13 Apr 2024 15:14:46 -0700 (PDT) Received: from localhost (host-87-4-160-102.retail.telecomitalia.it. [87.4.160.102]) by smtp.gmail.com with ESMTPSA id gv15-20020a170906f10f00b00a517995c070sm3453101ejb.33.2024.04.13.15.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Apr 2024 15:14:46 -0700 (PDT) From: Andrea della Porta To: Ulf Hansson , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Broadcom internal kernel review list , Linus Walleij , Adrian Hunter , Kamal Dasu , Al Cooper , della Porta , linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Jonathan Bell , Phil Elwell Subject: [PATCH 5/6] mmc: sdhci-brcmstb: Add BCM2712 support Date: Sun, 14 Apr 2024 00:14:27 +0200 Message-ID: <7a75876def65f6282b7b3ca17ef8008c305d6c32.1713036964.git.andrea.porta@suse.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240413_151448_879751_A95E3D12 X-CRM114-Status: GOOD ( 23.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Broadcom BCM2712 SoC has an SDHCI card controller using the SDIO CFG register block present on other STB chips. Add support for BCM2712 SD capabilities of this chipset. The silicon is SD Express capable but this driver port does not currently include that feature yet. Based on downstream driver by raspberry foundation maintained kernel. Signed-off-by: Andrea della Porta --- drivers/mmc/host/sdhci-brcmstb.c | 130 +++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/drivers/mmc/host/sdhci-brcmstb.c b/drivers/mmc/host/sdhci-brcmstb.c index 9053526fa212..907a4947abe5 100644 --- a/drivers/mmc/host/sdhci-brcmstb.c +++ b/drivers/mmc/host/sdhci-brcmstb.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "sdhci-cqhci.h" #include "sdhci-pltfm.h" @@ -30,15 +32,31 @@ #define SDHCI_ARASAN_CQE_BASE_ADDR 0x200 +#define SDIO_CFG_CTRL 0x0 +#define SDIO_CFG_CTRL_SDCD_N_TEST_EN BIT(31) +#define SDIO_CFG_CTRL_SDCD_N_TEST_LEV BIT(30) + +#define SDIO_CFG_SD_PIN_SEL 0x44 +#define SDIO_CFG_SD_PIN_SEL_MASK 0x3 +#define SDIO_CFG_SD_PIN_SEL_SD BIT(1) +#define SDIO_CFG_SD_PIN_SEL_MMC BIT(0) + +#define SDIO_CFG_MAX_50MHZ_MODE 0x1ac +#define SDIO_CFG_MAX_50MHZ_MODE_STRAP_OVERRIDE BIT(31) +#define SDIO_CFG_MAX_50MHZ_MODE_ENABLE BIT(0) + struct sdhci_brcmstb_priv { void __iomem *cfg_regs; unsigned int flags; struct clk *base_clk; u32 base_freq_hz; + struct pinctrl *pinctrl; + struct pinctrl_state *pins_default; }; struct brcmstb_match_priv { void (*hs400es)(struct mmc_host *mmc, struct mmc_ios *ios); + void (*cfginit)(struct sdhci_host *host); struct sdhci_ops *ops; const unsigned int flags; }; @@ -124,6 +142,42 @@ static void sdhci_brcmstb_hs400es(struct mmc_host *mmc, struct mmc_ios *ios) writel(reg, host->ioaddr + SDHCI_VENDOR); } +static void sdhci_bcm2712_set_clock(struct sdhci_host *host, unsigned int clock) +{ + u16 clk; + u32 reg; + bool is_emmc_rate = false; + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_brcmstb_priv *brcmstb_priv = sdhci_pltfm_priv(pltfm_host); + + host->mmc->actual_clock = 0; + + sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); + + switch (host->mmc->ios.timing) { + case MMC_TIMING_MMC_HS400: + case MMC_TIMING_MMC_HS200: + case MMC_TIMING_MMC_DDR52: + case MMC_TIMING_MMC_HS: + is_emmc_rate = true; + break; + } + + reg = readl(brcmstb_priv->cfg_regs + SDIO_CFG_SD_PIN_SEL); + reg &= ~SDIO_CFG_SD_PIN_SEL_MASK; + if (is_emmc_rate) + reg |= SDIO_CFG_SD_PIN_SEL_MMC; + else + reg |= SDIO_CFG_SD_PIN_SEL_SD; + writel(reg, brcmstb_priv->cfg_regs + SDIO_CFG_SD_PIN_SEL); + + if (clock == 0) + return; + + clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock); + sdhci_enable_clk(host, clk); +} + static void sdhci_brcmstb_set_clock(struct sdhci_host *host, unsigned int clock) { u16 clk; @@ -139,6 +193,17 @@ static void sdhci_brcmstb_set_clock(struct sdhci_host *host, unsigned int clock) sdhci_enable_clk(host, clk); } +static void sdhci_brcmstb_set_power(struct sdhci_host *host, unsigned char mode, + unsigned short vdd) +{ + if (!IS_ERR(host->mmc->supply.vmmc)) { + struct mmc_host *mmc = host->mmc; + + mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); + } + sdhci_set_power_noreg(host, mode, vdd); +} + static void sdhci_brcmstb_set_uhs_signaling(struct sdhci_host *host, unsigned int timing) { @@ -168,6 +233,36 @@ static void sdhci_brcmstb_set_uhs_signaling(struct sdhci_host *host, sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); } +static void sdhci_brcmstb_cfginit_2712(struct sdhci_host *host) +{ + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_brcmstb_priv *brcmstb_priv = sdhci_pltfm_priv(pltfm_host); + u32 uhs_mask = (MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104); + u32 hsemmc_mask = (MMC_CAP2_HS200_1_8V_SDR | MMC_CAP2_HS200_1_2V_SDR | + MMC_CAP2_HS400_1_8V | MMC_CAP2_HS400_1_2V); + u32 reg; + + /* + * If we support a speed that requires tuning, + * then select the delay line PHY as the clock source. + */ + if ((host->mmc->caps & uhs_mask) || (host->mmc->caps2 & hsemmc_mask)) { + reg = readl(brcmstb_priv->cfg_regs + SDIO_CFG_MAX_50MHZ_MODE); + reg &= ~SDIO_CFG_MAX_50MHZ_MODE_ENABLE; + reg |= SDIO_CFG_MAX_50MHZ_MODE_STRAP_OVERRIDE; + writel(reg, brcmstb_priv->cfg_regs + SDIO_CFG_MAX_50MHZ_MODE); + } + + if ((host->mmc->caps & MMC_CAP_NONREMOVABLE) || + (host->mmc->caps & MMC_CAP_NEEDS_POLL)) { + /* Force presence */ + reg = readl(brcmstb_priv->cfg_regs + SDIO_CFG_CTRL); + reg &= ~SDIO_CFG_CTRL_SDCD_N_TEST_LEV; + reg |= SDIO_CFG_CTRL_SDCD_N_TEST_EN; + writel(reg, brcmstb_priv->cfg_regs + SDIO_CFG_CTRL); + } +} + static void sdhci_brcmstb_dumpregs(struct mmc_host *mmc) { sdhci_dumpregs(mmc_priv(mmc)); @@ -200,6 +295,14 @@ static struct sdhci_ops sdhci_brcmstb_ops = { .set_uhs_signaling = sdhci_set_uhs_signaling, }; +static struct sdhci_ops sdhci_brcmstb_ops_2712 = { + .set_clock = sdhci_bcm2712_set_clock, + .set_power = sdhci_brcmstb_set_power, + .set_bus_width = sdhci_set_bus_width, + .reset = sdhci_reset, + .set_uhs_signaling = sdhci_set_uhs_signaling, +}; + static struct sdhci_ops sdhci_brcmstb_ops_7216 = { .set_clock = sdhci_brcmstb_set_clock, .set_bus_width = sdhci_set_bus_width, @@ -237,7 +340,13 @@ static struct brcmstb_match_priv match_priv_74165b0 = { .ops = &sdhci_brcmstb_ops_74165b0, }; +static const struct brcmstb_match_priv match_priv_2712 = { + .cfginit = sdhci_brcmstb_cfginit_2712, + .ops = &sdhci_brcmstb_ops_2712, +}; + static const struct of_device_id __maybe_unused sdhci_brcm_of_match[] = { + { .compatible = "brcm,bcm2712-sdhci", .data = &match_priv_2712 }, { .compatible = "brcm,bcm7425-sdhci", .data = &match_priv_7425 }, { .compatible = "brcm,bcm7445-sdhci", .data = &match_priv_7445 }, { .compatible = "brcm,bcm7216-sdhci", .data = &match_priv_7216 }, @@ -314,11 +423,16 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev) struct sdhci_brcmstb_priv *priv; u32 actual_clock_mhz; struct sdhci_host *host; + bool no_pinctrl = false; struct clk *clk; struct clk *base_clk = NULL; int res; match = of_match_node(sdhci_brcm_of_match, pdev->dev.of_node); + if (!match) { + dev_err(&pdev->dev, "fail to get matching of_match struct\n"); + return -EINVAL; + } match_priv = match->data; dev_dbg(&pdev->dev, "Probe found match for %s\n", match->compatible); @@ -354,6 +468,19 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev) if (res) goto err; + priv->pinctrl = devm_pinctrl_get(&pdev->dev); + if (IS_ERR(priv->pinctrl)) { + no_pinctrl = true; + } + priv->pins_default = pinctrl_lookup_state(priv->pinctrl, "default"); + if (IS_ERR(priv->pins_default)) { + dev_dbg(&pdev->dev, "No pinctrl default state\n"); + no_pinctrl = true; + } + + if (no_pinctrl ) + priv->pinctrl = NULL; + /* * Automatic clock gating does not work for SD cards that may * voltage switch so only enable it for non-removable devices. @@ -370,6 +497,9 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev) (host->mmc->caps2 & MMC_CAP2_HS400_ES)) host->mmc_host_ops.hs400_enhanced_strobe = match_priv->hs400es; + if(match_priv->cfginit) + match_priv->cfginit(host); + /* * Supply the existing CAPS, but clear the UHS modes. This * will allow these modes to be specified by device tree