Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp688362lqp; Sat, 13 Apr 2024 15:15:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU0ErXpSTQQ0aNMA9ZV3v3Rl5eUKHCKG/F74vhseDVSXhtiA9YYIcyoDMI6GGRQ4wy8Nmaea6DkzdNpvZ2QrjgFXcdPrmWodxfVpAH2Cw== X-Google-Smtp-Source: AGHT+IEvdIku1iwEuAMxaJWEv3dhSRD0gH2tb0gIRIKWbtpZcXRrFWOB1oFAHfdKWBROjY3+I35B X-Received: by 2002:ac8:7e81:0:b0:436:ac98:984f with SMTP id w1-20020ac87e81000000b00436ac98984fmr5268708qtj.25.1713046553859; Sat, 13 Apr 2024 15:15:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713046553; cv=pass; d=google.com; s=arc-20160816; b=UAOAxu4UbCbTK1+Ak4Wd/RZW7/vd38UwCQXGtMolXfwPYYIfnQ/E1CWJQ7rYfIwbla oebRNouQi6Ki2sKoXisO31L5v1+1oUOlJffde8S2Zd7zkax0zLXkF3SqEJii6Hd2AYrg mGbxMXpqOkkTi6cPYD5rO6D9hMjwDP28/e8UV5IVyeV91JUVe/XUbYr6jGomLinh2d6S 9uzbCnR94zgOe8qaR0QvX/wc/iS+MQQWNp9enRL4leJsNageKDePCRgPX57Dd91tlo/Q KDJirLqQTGE24Cr+NzvK5wfFAVjORHH+eizyryr/Hl6bC3PhgRW6xYvpnegpE/JV9eQM 2WEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=OWTANOhwt+MSlpwP2S7BNom6jkNUFDJjf/oC5BBrk94=; fh=A84yxTGJ47WaO3uQbnNFCqoKNC8M/rl2tal67ooEQhA=; b=IxLoru/nL9QmeFU9ov7w7zPwLi4LOkL4nmS2aJRdyDhqW73vEBivwKJhOX+q3eDIpA zYlGD9B5jTPJ47YbUIBOgo044sG8yk0d2u90nPAXJeVzJ0mftzKhzJVzMhClgmcPnst7 g9Q/TZIlMPQn8ffkGXm6ULZJbUl+AJ+CSqvbMYUQ77wnw9qKwbZihR8eMT3F11a7ILD+ 9PAPX7cEExJR78+/K/dB6AVHD9gUISQbdo7k+4ypqks/VoR01oYYJJxCrYA/EyDR0QjF TLdDPyVg3Z4DetAp3otreMRv/1sL1MkvC9UrkjBL/79YEZrHlZGfjXhTs/K6ItjGIwHR vSQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=XEzRomwM; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-143913-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143913-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id fc26-20020a05622a489a00b00436da5cf86dsi1140390qtb.619.2024.04.13.15.15.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Apr 2024 15:15:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143913-linux.lists.archive=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=@suse.com header.s=google header.b=XEzRomwM; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-143913-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143913-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.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 7E8071C20AAF for ; Sat, 13 Apr 2024 22:15:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9AA559177; Sat, 13 Apr 2024 22:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="XEzRomwM" Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 8CFA158135 for ; Sat, 13 Apr 2024 22:14:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713046492; cv=none; b=B/9GCzjTXQTirJ4iajNKJ4DkGl4sOB+GIak/RVl1nk/dwhtFKlosiY/FnsiA9wyGpcyvCmk8iTECB1nHKZwED0wpCmg2kCPHbvIfwffAhafEsZDgBdh9IGgljJoAKFX1ntOcc+qWPHR9+dArDxgoKeFYjjeNVVbWmM0yWyiqacw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713046492; c=relaxed/simple; bh=M0HbViSqIJdpYbmigPx1R2It9w5wm6INS0lndwvsZtA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FShKfe66K0kAB2FgC9YH+Xn/8dgrZMwPAQsqaDdUjXWN4crF/nL634uoVwR9X8gUkxdN/zp+UTWqvhl/eCi4RWF6NNbkkGtdeH5bDdbh4VYAVeiiVNVbPA0D6F81vrXD80MOWlg5dKROER0rA9UsbuyeUxZSvU4wyWh6Bh6Xrwo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=XEzRomwM; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a5200202c1bso238373566b.0 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=vger.kernel.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=XEzRomwMx+653r/J2QLd+SGTM8G9ds5241XY9RGkG9VFn5/DhZ0ipfgi0PoGJH8Ocs vcuiOp7mbc7jtw4FG0mMlYsvuKOQp1SH4bV+bBHzPACEBMOa0TB9GEQQK10vv8Uiar8b H9TNUJdk2cc8maXVyFefRDi9fc7M1LJYL7b8srCzUh7GBiU3PWLkOftrubfAdDea+GAn aHnPvb3Mmnhyz9A5lHRUmMihuKsFKQLupv877uDTWTlPCf4mw15Fv02hRQbccMK7un09 7P6xufraqDXlRTPFw8231/JKV45jo3/QOZpS+9W086i6uoD8E8iRUDoS/619sEp5Xwr6 VKlg== 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=vXTG1Tn1+danD+caY2GzbBrcs6kuDQfhQ8ASA86kvCoSk+R+6rgJfQLYCfi8GHKGJh DGe/8Bx6aGy4vPDR5uuwJgZCw1aosVwXBg275agFuGOgQhtTq9sg5GMOaAvfw0A4u5mU Tz1ii4QBAOTefOYJm/kvRxDlyfiyjiGE5dbqC4Neyixp40JQUtbwkHsxCiecqtnsbdtq gMhPGQ+qWDT6ri6mn03RbyiaslpHU/gb1R60eqv02YHjW9fhJQOCNpH53HrNeQZ1hL8a SohzuZuged5yJHg9vETdoNBg23mxJJla8Qxhu8p1/ha4sNUN/0cYxjuIrsL5OWYd8FW5 uhVQ== X-Forwarded-Encrypted: i=1; AJvYcCVNp5mGkSmFFoNYj3GDxUF5q2QEwT3TRJKOvhnBZh1KfModctSslYh2O6BU4Jm+i0MaK/I4hgtkjwP3qT6xxdCmCNCz+sXnEzojQUKg X-Gm-Message-State: AOJu0YwxkX6XXuB8n3+AfCXNwXr+KqPTbgDDCAQ/cmiUUpXOb+vnFJjv yjEZ7XFl5p9hbY9zKklEMnCUt916Dd0GTaqtjTZ1Yak9lZGsbK/Hf2wVrMC3GA4= 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 -- 2.35.3