LKML Archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <florian.fainelli@broadcom.com>
To: Andrea della Porta <andrea.porta@suse.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Kamal Dasu <kamal.dasu@broadcom.com>,
	Al Cooper <alcooperx@gmail.com>,
	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 <jonathan@raspberrypi.com>,
	Phil Elwell <phil@raspberrypi.com>
Subject: Re: [PATCH 6/6] mmc: sdhci-brcmstb: Add BCM2712 SD Express support
Date: Sun, 14 Apr 2024 08:55:45 -0700	[thread overview]
Message-ID: <6042c0c7-bb8a-4898-8bed-92155b8e9c4f@broadcom.com> (raw)
In-Reply-To: <a3d82e5a28fe53f1f61621d37d1695b0cd7655d2.1713036964.git.andrea.porta@suse.com>

[-- Attachment #1: Type: text/plain, Size: 6173 bytes --]



On 4/13/2024 3:14 PM, Andrea della Porta wrote:
> Broadcom BCM2712 SDHCI controller is SD Express capable. Add support
> for sde capability where the implementation is based on downstream driver,
> diverging from it in the way that init_sd_express callback is invoked:
> in downstream the sdhci_ops structure has been augmented with a new
> function ptr 'init_sd_express' that just propagate the call to the
> driver specific callback so that the callstack from a structure
> standpoint is mmc_host_ops -> sdhci_ops. The drawback here is in the
> added level of indirection (the newly added init_sd_express is
> redundant) and the sdhci_ops structure declaration has to be changed.
> To overcome this the presented approach consist in patching the mmc_host_ops
> init_sd_express callback to point directly to the custom function defined in
> this driver (see struct brcmstb_match_priv).
> 
> Signed-off-by: Andrea della Porta <andrea.porta@suse.com>
> ---
>   drivers/mmc/host/Kconfig         |   1 +
>   drivers/mmc/host/sdhci-brcmstb.c | 147 ++++++++++++++++++++++++++++++-
>   2 files changed, 147 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
> index aebc587f77a7..343ccac1a4e4 100644
> --- a/drivers/mmc/host/Kconfig
> +++ b/drivers/mmc/host/Kconfig
> @@ -1018,6 +1018,7 @@ config MMC_SDHCI_BRCMSTB
>   	depends on ARCH_BRCMSTB || BMIPS_GENERIC || COMPILE_TEST
>   	depends on MMC_SDHCI_PLTFM
>   	select MMC_CQHCI
> +	select OF_DYNAMIC
>   	default ARCH_BRCMSTB || BMIPS_GENERIC
>   	help
>   	  This selects support for the SDIO/SD/MMC Host Controller on
> diff --git a/drivers/mmc/host/sdhci-brcmstb.c b/drivers/mmc/host/sdhci-brcmstb.c
> index 907a4947abe5..56fb34a75ec2 100644
> --- a/drivers/mmc/host/sdhci-brcmstb.c
> +++ b/drivers/mmc/host/sdhci-brcmstb.c
> @@ -29,6 +29,7 @@
>   
>   #define BRCMSTB_PRIV_FLAGS_HAS_CQE		BIT(0)
>   #define BRCMSTB_PRIV_FLAGS_GATE_CLOCK		BIT(1)
> +#define BRCMSTB_PRIV_FLAGS_HAS_SD_EXPRESS	BIT(2)
>   
>   #define SDHCI_ARASAN_CQE_BASE_ADDR		0x200
>   
> @@ -50,13 +51,19 @@ struct sdhci_brcmstb_priv {
>   	unsigned int flags;
>   	struct clk *base_clk;
>   	u32 base_freq_hz;
> +	struct regulator *sde_1v8;
> +	struct device_node *sde_pcie;
> +	void *__iomem sde_ioaddr;
> +	void *__iomem sde_ioaddr2;
>   	struct pinctrl *pinctrl;
>   	struct pinctrl_state *pins_default;
> +	struct pinctrl_state *pins_sdex;
>   };
>   
>   struct brcmstb_match_priv {
>   	void (*hs400es)(struct mmc_host *mmc, struct mmc_ios *ios);
>   	void (*cfginit)(struct sdhci_host *host);
> +	int (*init_sd_express)(struct mmc_host *mmc, struct mmc_ios *ios);
>   	struct sdhci_ops *ops;
>   	const unsigned int flags;
>   };
> @@ -263,6 +270,105 @@ static void sdhci_brcmstb_cfginit_2712(struct sdhci_host *host)
>   	}
>   }
>   
> +static int bcm2712_init_sd_express(struct mmc_host *mmc, struct mmc_ios *ios)
> +{
> +	struct sdhci_host *host = mmc_priv(mmc);
> +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> +	struct sdhci_brcmstb_priv *brcmstb_priv = sdhci_pltfm_priv(pltfm_host);
> +	struct device *dev = host->mmc->parent;
> +	u32 ctrl_val;
> +	u32 present_state;
> +	int ret;
> +
> +	if (!brcmstb_priv->sde_ioaddr || !brcmstb_priv->sde_ioaddr2)
> +		return -EINVAL;
> +
> +	if (!brcmstb_priv->pinctrl)
> +		return -EINVAL;
> +
> +	/* Turn off the SD clock first */
> +	sdhci_set_clock(host, 0);
> +
> +	/* Disable SD DAT0-3 pulls */
> +	pinctrl_select_state(brcmstb_priv->pinctrl, brcmstb_priv->pins_sdex);
> +
> +	ctrl_val = readl(brcmstb_priv->sde_ioaddr);
> +	dev_dbg(dev, "ctrl_val 1 %08x\n", ctrl_val);
> +
> +	/* Tri-state the SD pins */
> +	ctrl_val |= 0x1ff8;

No magic values please.

> +	writel(ctrl_val, brcmstb_priv->sde_ioaddr);
> +	dev_dbg(dev, "ctrl_val 1->%08x (%08x)\n", ctrl_val, readl(brcmstb_priv->sde_ioaddr));
> +	/* Let voltages settle */
> +	udelay(100);

Why not usleep_range()?

> +
> +	/* Enable the PCIe sideband pins */
> +	ctrl_val &= ~0x6000;

No magic values please.

> +	writel(ctrl_val, brcmstb_priv->sde_ioaddr);
> +	dev_dbg(dev, "ctrl_val 1->%08x (%08x)\n", ctrl_val, readl(brcmstb_priv->sde_ioaddr));
> +	/* Let voltages settle */
> +	udelay(100);

Likewise.

> +
> +	/* Turn on the 1v8 VDD2 regulator */
> +	ret = regulator_enable(brcmstb_priv->sde_1v8);
> +	if (ret)
> +		return ret;
> +
> +	/* Wait for Tpvcrl */
> +	msleep(1);
> +
> +	/* Sample DAT2 (CLKREQ#) - if low, card is in PCIe mode */
> +	present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
> +	present_state = (present_state & SDHCI_DATA_LVL_MASK) >> SDHCI_DATA_LVL_SHIFT;
> +	dev_dbg(dev, "state = 0x%08x\n", present_state);
> +
> +	if (present_state & BIT(2)) {

Likewise, replace with constant.

> +		dev_err(dev, "DAT2 still high, abandoning SDex switch\n");
> +		return -ENODEV;
> +	}
> +
> +	/* Turn on the LCPLL PTEST mux */
> +	ctrl_val = readl(brcmstb_priv->sde_ioaddr2 + 20); // misc5
> +	ctrl_val &= ~(0x7 << 7);
> +	ctrl_val |= 3 << 7;
> +	writel(ctrl_val, brcmstb_priv->sde_ioaddr2 + 20);
> +	dev_dbg(dev, "misc 5->%08x (%08x)\n", ctrl_val, readl(brcmstb_priv->sde_ioaddr2 + 20));
> +
> +	/* PTEST diff driver enable */
> +	ctrl_val = readl(brcmstb_priv->sde_ioaddr2);
> +	ctrl_val |= BIT(21);
> +	writel(ctrl_val, brcmstb_priv->sde_ioaddr2);
> +
> +	dev_dbg(dev, "misc 0->%08x (%08x)\n", ctrl_val, readl(brcmstb_priv->sde_ioaddr2));
> +
> +	/* Wait for more than the minimum Tpvpgl time */
> +	msleep(100);
> +
> +	if (brcmstb_priv->sde_pcie) {
> +		struct of_changeset changeset;
> +		static struct property okay_property = {
> +			.name = "status",
> +			.value = "okay",
> +			.length = 5,
> +		};
> +
> +		/* Enable the pcie controller */
> +		of_changeset_init(&changeset);
> +		ret = of_changeset_update_property(&changeset,
> +						   brcmstb_priv->sde_pcie,
> +						   &okay_property);
> +		if (ret) {
> +			dev_err(dev, "%s: failed to update property - %d\n", __func__,
> +			       ret);
> +			return -ENODEV;
> +		}
> +		ret = of_changeset_apply(&changeset);
> +	}

Why are you doing this? Cannot the firmware enable/disable the node 
according to the boot mode or something else?

This is not going to fly for upstream, sorry.
-- 
Florian

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

  parent reply	other threads:[~2024-04-14 15:55 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-13 22:14 [PATCH 0/6] Add support for BCM2712 SD card controller Andrea della Porta
2024-04-13 22:14 ` [PATCH 1/6] dt-bindings: pinctrl: Add support for BCM2712 pin controller Andrea della Porta
2024-04-13 23:22   ` Rob Herring
2024-04-14  6:09   ` Krzysztof Kozlowski
2024-04-14 15:45   ` Florian Fainelli
2024-04-16 12:59     ` Linus Walleij
2024-04-27 10:55     ` Andrea della Porta
2024-04-13 22:14 ` [PATCH 2/6] dt-bindings: mmc: Add support for BCM2712 SD host controller Andrea della Porta
2024-04-13 23:22   ` Rob Herring
2024-04-14  6:11   ` Krzysztof Kozlowski
2024-04-14 15:55   ` Florian Fainelli
2024-04-13 22:14 ` [PATCH 3/6] arm64: dts: broadcom: Add support for BCM2712 Andrea della Porta
2024-04-14  6:22   ` Krzysztof Kozlowski
2024-04-14 16:01   ` Florian Fainelli
2024-04-27 11:02     ` Andrea della Porta
2024-04-15  8:20   ` Stefan Wahren
2024-04-15  8:52     ` Phil Elwell
2024-04-15  9:06       ` Stefan Wahren
2024-04-15 10:43         ` Phil Elwell
2024-04-13 22:14 ` [PATCH 4/6] pinctrl: bcm: Add pinconf/pinmux controller driver " Andrea della Porta
2024-04-14  7:19   ` Christophe JAILLET
2024-04-27 11:04     ` Andrea della Porta
2024-04-14 16:00   ` Florian Fainelli
2024-04-27 11:06     ` Andrea della Porta
2024-04-16 13:07   ` Linus Walleij
2024-04-27 11:13     ` Andrea della Porta
2024-04-13 22:14 ` [PATCH 5/6] mmc: sdhci-brcmstb: Add BCM2712 support Andrea della Porta
2024-04-14  6:25   ` Krzysztof Kozlowski
2024-04-14  7:28   ` Christophe JAILLET
2024-04-14 15:53   ` Florian Fainelli
2024-04-13 22:14 ` [PATCH 6/6] mmc: sdhci-brcmstb: Add BCM2712 SD Express support Andrea della Porta
2024-04-14  7:34   ` Christophe JAILLET
2024-04-27 11:16     ` Andrea della Porta
2024-04-14 15:55   ` Florian Fainelli [this message]
2024-04-27 11:21     ` Andrea della Porta
2024-04-14 10:07 ` [PATCH 0/6] Add support for BCM2712 SD card controller Stefan Wahren
2024-05-02  9:12   ` Andrea della Porta
2024-04-14 15:54 ` Florian Fainelli
2024-04-15 18:47 ` Rob Herring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6042c0c7-bb8a-4898-8bed-92155b8e9c4f@broadcom.com \
    --to=florian.fainelli@broadcom.com \
    --cc=adrian.hunter@intel.com \
    --cc=alcooperx@gmail.com \
    --cc=andrea.porta@suse.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jonathan@raspberrypi.com \
    --cc=kamal.dasu@broadcom.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=phil@raspberrypi.com \
    --cc=robh@kernel.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).