Skip to contentSkip to conversation

mmc: sdhci: Add Tegra234 support

PATCH In review Thierry Reding 3 participants 10 messages Dec 6, 2022 – Dec 8, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v13 cover mmc: sdhci: Add Tegra234 support

From: Thierry Reding <[email protected]>

Hi,

This is an updated version of v12 from a few days ago:

    https://lore.kernel.org/all/[email protected]/

The only difference here is a fix for the included headers (bitops.h does not have all the definitions on all architectures, so we need bitfield.h instead) and an Acked-by from Robin on the new Tegra-specific helper.

It'd be great to see this go in for v6.2 so that the new helper is available for the next release and the other patches that I have prepared can be merged.

Ulf, given that Joerg has acked patch 1 and Robin has acked patch 2, I think the expectation is for you to pick up the whole set.

Thanks,
Thierry

Prathamesh Shete (3):
mmc: sdhci-tegra: Separate Tegra194 and Tegra234 SoC data
mmc: sdhci-tegra: Add support to program MC stream ID
mmc: sdhci-tegra: Issue CMD and DAT resets together

Thierry Reding (3):
iommu: Add note about struct iommu_fwspec usage iommu/tegra: Add tegra_dev_iommu_get_stream_id() helper
mmc: sdhci-tegra: Sort includes alphabetically

 drivers/mmc/host/sdhci-tegra.c | 69 ++++++++++++++++++++++++++++------
 drivers/mmc/host/sdhci.c       |  5 +++
 drivers/mmc/host/sdhci.h       |  2 +
 include/linux/iommu.h          | 25 ++++++++++++
 4 files changed, 89 insertions(+), 12 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH v13 1/6 iommu: Add note about struct iommu_fwspec usage

From: Thierry Reding <[email protected]>

This structure is to be considered private to the IOMMU API. Except for very few exceptions, IOMMU consumer drivers should treat this as opaque data.

---
 include/linux/iommu.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/iommu.h +4 -0
index 1690c334e516..dc5e6f5c14fc 100644
@@ -641,6 +641,10 @@ struct iommu_group *fsl_mc_device_group(struct device *dev);
  * @flags: IOMMU_FWSPEC_* flags
  * @num_ids: number of associated device IDs
  * @ids: IDs which this device may present to the IOMMU
+ *
+ * Note that the IDs (and any other information, really) stored in this structure should be
+ * considered private to the IOMMU device driver and are not to be used directly by IOMMU
+ * consumers.
  */
 struct iommu_fwspec {
 	const struct iommu_ops	*ops;
Signature · 1 line
2.38.1
#2 lore raw

PATCH v13 2/6 iommu/tegra: Add tegra_dev_iommu_get_stream_id() helper

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Access to the internals of struct iommu_fwspec by non-IOMMU drivers is discouraged. Many drivers for Tegra SoCs, however, need access to their IOMMU stream IDs so that they can be programmed into various hardware registers.

Formalize this access into a common helper to make it easier to audit and maintain.

---
 include/linux/iommu.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
include/linux/iommu.h +21 -0
index dc5e6f5c14fc..f0d72acad7db 100644
@@ -1186,4 +1186,25 @@ static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle)
 }
 #endif /* CONFIG_IOMMU_SVA */
 
+/*
+ * Newer generations of Tegra SoCs require devices' stream IDs to be directly programmed into
+ * some registers. These are always paired with a Tegra SMMU or ARM SMMU, for which the contents
+ * of the struct iommu_fwspec are known. Use this helper to formalize access to these internals.
+ */
+#define TEGRA_STREAM_ID_BYPASS 0x7f
+
+static inline bool tegra_dev_iommu_get_stream_id(struct device *dev, u32 *stream_id)
+{
+#ifdef CONFIG_IOMMU_API
+	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+
+	if (fwspec && fwspec->num_ids == 1) {
+		*stream_id = fwspec->ids[0] & 0xffff;
+		return true;
+	}
+#endif
+
+	return false;
+}
+
 #endif /* __LINUX_IOMMU_H */
Signature · 1 line
2.38.1
#3 lore raw

PATCH v13 3/6 mmc: sdhci-tegra: Sort includes alphabetically

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Sort includes alphabetically to make it easier to add new ones subsequently.

---
 drivers/mmc/host/sdhci-tegra.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/mmc/host/sdhci-tegra.c +11 -11
index 9fc8a61eca54..afa9cbf9cb6f 100644
@@ -3,28 +3,28 @@
  * Copyright (C) 2010 Google, Inc.
  */
 
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/err.h>
-#include <linux/module.h>
+#include <linux/gpio/consumer.h>
 #include <linux/init.h>
-#include <linux/iopoll.h>
-#include <linux/platform_device.h>
-#include <linux/clk.h>
 #include <linux/io.h>
-#include <linux/of.h>
+#include <linux/iopoll.h>
+#include <linux/ktime.h>
+#include <linux/mmc/card.h>
+#include <linux/mmc/host.h>
+#include <linux/mmc/mmc.h>
+#include <linux/mmc/slot-gpio.h>
+#include <linux/module.h>
 #include <linux/of_device.h>
+#include <linux/of.h>
 #include <linux/pinctrl/consumer.h>
+#include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 #include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
 #include <linux/reset.h>
-#include <linux/mmc/card.h>
-#include <linux/mmc/host.h>
-#include <linux/mmc/mmc.h>
-#include <linux/mmc/slot-gpio.h>
-#include <linux/gpio/consumer.h>
-#include <linux/ktime.h>
 
 #include <soc/tegra/common.h>
 
Signature · 1 line
2.38.1
#4 lore raw

PATCH v13 4/6 mmc: sdhci-tegra: Separate Tegra194 and Tegra234 SoC data

In reply to Thierry Reding

From: Prathamesh Shete <[email protected]>

Create new SoC data structure for Tegra234 platforms. Additional features, tap value configurations are added/updated for Tegra234 platform hence separate Tegra194 and Tegra234 SoC data.

---
 drivers/mmc/host/sdhci-tegra.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/mmc/host/sdhci-tegra.c +14 -0
index afa9cbf9cb6f..f3f5a4abcafb 100644
@@ -1553,7 +1553,21 @@ static const struct sdhci_tegra_soc_data soc_data_tegra194 = {
 	.max_tap_delay = 139,
 };
 
+static const struct sdhci_tegra_soc_data soc_data_tegra234 = {
+	.pdata = &sdhci_tegra186_pdata,
+	.dma_mask = DMA_BIT_MASK(39),
+	.nvquirks = NVQUIRK_NEEDS_PAD_CONTROL |
+		    NVQUIRK_HAS_PADCALIB |
+		    NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
+		    NVQUIRK_ENABLE_SDR50 |
+		    NVQUIRK_ENABLE_SDR104 |
+		    NVQUIRK_HAS_TMCLK,
+	.min_tap_delay = 95,
+	.max_tap_delay = 111,
+};
+
 static const struct of_device_id sdhci_tegra_dt_match[] = {
+	{ .compatible = "nvidia,tegra234-sdhci", .data = &soc_data_tegra234 },
 	{ .compatible = "nvidia,tegra194-sdhci", .data = &soc_data_tegra194 },
 	{ .compatible = "nvidia,tegra186-sdhci", .data = &soc_data_tegra186 },
 	{ .compatible = "nvidia,tegra210-sdhci", .data = &soc_data_tegra210 },
Signature · 1 line
2.38.1
#5 lore raw

PATCH v13 5/6 mmc: sdhci-tegra: Add support to program MC stream ID

In reply to Thierry Reding

From: Prathamesh Shete <[email protected]>

SMMU clients are supposed to program stream ID from their respective address spaces instead of MC override. Define NVQUIRK_PROGRAM_STREAMID and use it to program SMMU stream ID from the SDMMC client address space.

---
 drivers/mmc/host/sdhci-tegra.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/mmc/host/sdhci-tegra.c +30 -0
index f3f5a4abcafb..fb3823c87cb8 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2010 Google, Inc.
  */
 
+#include <linux/bitfield.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
@@ -10,6 +11,7 @@
 #include <linux/gpio/consumer.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/iommu.h>
 #include <linux/iopoll.h>
 #include <linux/ktime.h>
 #include <linux/mmc/card.h>
@@ -95,6 +97,8 @@
 #define SDHCI_TEGRA_AUTO_CAL_STATUS			0x1ec
 #define SDHCI_TEGRA_AUTO_CAL_ACTIVE			BIT(31)
 
+#define SDHCI_TEGRA_CIF2AXI_CTRL_0			0x1fc
+
 #define NVQUIRK_FORCE_SDHCI_SPEC_200			BIT(0)
 #define NVQUIRK_ENABLE_BLOCK_GAP_DET			BIT(1)
 #define NVQUIRK_ENABLE_SDHCI_SPEC_300			BIT(2)
@@ -122,6 +126,7 @@
 #define NVQUIRK_HAS_TMCLK				BIT(10)
 
 #define NVQUIRK_HAS_ANDROID_GPT_SECTOR			BIT(11)
+#define NVQUIRK_PROGRAM_STREAMID			BIT(12)
 
 /* SDMMC CQE Base Address for Tegra Host Ver 4.1 and Higher */
 #define SDHCI_TEGRA_CQE_BASE_ADDR			0xF000
@@ -178,6 +183,7 @@ struct sdhci_tegra {
 	bool enable_hwcq;
 	unsigned long curr_clk_rate;
 	u8 tuned_tap_delay;
+	u32 stream_id;
 };
 
 static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
@@ -1561,6 +1567,7 @@ static const struct sdhci_tegra_soc_data soc_data_tegra234 = {
 		    NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
 		    NVQUIRK_ENABLE_SDR50 |
 		    NVQUIRK_ENABLE_SDR104 |
+		    NVQUIRK_PROGRAM_STREAMID |
 		    NVQUIRK_HAS_TMCLK,
 	.min_tap_delay = 95,
 	.max_tap_delay = 111,
@@ -1627,6 +1634,19 @@ static int sdhci_tegra_add_host(struct sdhci_host *host)
 	return ret;
 }
 
+/* Program MC streamID for DMA transfers */
+static void sdhci_tegra_program_stream_id(struct sdhci_host *host)
+{
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
+
+	if (tegra_host->soc_data->nvquirks & NVQUIRK_PROGRAM_STREAMID) {
+		tegra_sdhci_writel(host, FIELD_PREP(GENMASK(15, 8), tegra_host->stream_id) |
+					 FIELD_PREP(GENMASK( 7, 0), tegra_host->stream_id),
+					 SDHCI_TEGRA_CIF2AXI_CTRL_0);
+	}
+}
+
 static int sdhci_tegra_probe(struct platform_device *pdev)
 {
 	const struct sdhci_tegra_soc_data *soc_data;
@@ -1687,6 +1707,12 @@ static int sdhci_tegra_probe(struct platform_device *pdev)
 
 	tegra_sdhci_parse_dt(host);
 
+	if (tegra_host->soc_data->nvquirks & NVQUIRK_PROGRAM_STREAMID &&
+	    !tegra_dev_iommu_get_stream_id(&pdev->dev, &tegra_host->stream_id)) {
+		dev_warn(mmc_dev(host->mmc), "missing IOMMU stream ID\n");
+		tegra_host->stream_id = 0x7f;
+	}
+
 	tegra_host->power_gpio = devm_gpiod_get_optional(&pdev->dev, "power",
 							 GPIOD_OUT_HIGH);
 	if (IS_ERR(tegra_host->power_gpio)) {
@@ -1772,6 +1798,8 @@ static int sdhci_tegra_probe(struct platform_device *pdev)
 	if (rc)
 		goto err_add_host;
 
+	sdhci_tegra_program_stream_id(host);
+
 	return 0;
 
 err_add_host:
@@ -1868,6 +1896,8 @@ static int sdhci_tegra_resume(struct device *dev)
 	if (ret)
 		return ret;
 
+	sdhci_tegra_program_stream_id(host);
+
 	ret = sdhci_resume_host(host);
 	if (ret)
 		goto disable_clk;
Signature · 1 line
2.38.1
#6 lore raw

PATCH v13 6/6 mmc: sdhci-tegra: Issue CMD and DAT resets together

In reply to Thierry Reding

From: Prathamesh Shete <[email protected]>

In case of error condition to avoid system crash Tegra SDMMC controller requires CMD and DAT resets issued together. SDHCI controller FSM goes into bad state due to rapid SD card hot-plug event. Issuing reset on the CMD FSM before DATA FSM results in kernel panic, hence add support to issue CMD and DAT resets together.

This is applicable to Tegra186 and later chips.

---
 drivers/mmc/host/sdhci-tegra.c | 3 ++-
 drivers/mmc/host/sdhci.c       | 5 +++++
 drivers/mmc/host/sdhci.h       | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-tegra.c +2 -1
index fb3823c87cb8..4c2563b27ed6 100644
@@ -1528,7 +1528,8 @@ static const struct sdhci_pltfm_data sdhci_tegra186_pdata = {
 		  SDHCI_QUIRK_NO_HISPD_BIT |
 		  SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
 		  SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
-	.quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
+	.quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
+		   SDHCI_QUIRK2_ISSUE_CMD_DAT_RESET_TOGETHER,
 	.ops  = &tegra186_sdhci_ops,
 };
 
drivers/mmc/host/sdhci.c +5 -0
index df1c1d10a338..81f4fed11629 100644
@@ -270,6 +270,11 @@ enum sdhci_reset_reason {
 
 static void sdhci_reset_for_reason(struct sdhci_host *host, enum sdhci_reset_reason reason)
 {
+	if (host->quirks2 & SDHCI_QUIRK2_ISSUE_CMD_DAT_RESET_TOGETHER) {
+		sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
+		return;
+	}
+
 	switch (reason) {
 	case SDHCI_RESET_FOR_INIT:
 		sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
drivers/mmc/host/sdhci.h +2 -0
index b6f31a7d6152..605eaee805f7 100644
@@ -478,6 +478,8 @@ struct sdhci_host {
  * block count.
  */
 #define SDHCI_QUIRK2_USE_32BIT_BLK_CNT			(1<<18)
+/* Issue CMD and DATA reset together */
+#define SDHCI_QUIRK2_ISSUE_CMD_DAT_RESET_TOGETHER	(1<<19)
 
 	int irq;		/* Device IRQ */
 	void __iomem *ioaddr;	/* Mapped address */
Signature · 1 line
2.38.1
#7 lore raw
In reply to Thierry Reding

+ Stephen Rothwell

Quoted 14 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Hi,

This is an updated version of v12 from a few days ago:

    https://lore.kernel.org/all/[email protected]/

The only difference here is a fix for the included headers (bitops.h does not have all the definitions on all architectures, so we need bitfield.h instead) and an Acked-by from Robin on the new Tegra-specific helper.

Quoted 6 lines

It'd be great to see this go in for v6.2 so that the new helper is available for the next release and the other patches that I have prepared can be merged.

Ulf, given that Joerg has acked patch 1 and Robin has acked patch 2, I think the expectation is for you to pick up the whole set.

Applied for next, thanks!

Note that, it seems likely that we may encounter a merge conflict between the mmc and iommu tree, due to changes in include/linux/iommu.h. Although, if that's the case, I believe the conflict should be trivial to resolve, so let's try this and see how it goes.

Stephen, I added you here, just to let you know of what goes on.

Quoted 14 lines

Thanks,
Thierry

Prathamesh Shete (3):
mmc: sdhci-tegra: Separate Tegra194 and Tegra234 SoC data
mmc: sdhci-tegra: Add support to program MC stream ID
mmc: sdhci-tegra: Issue CMD and DAT resets together

Thierry Reding (3):
iommu: Add note about struct iommu_fwspec usage iommu/tegra: Add tegra_dev_iommu_get_stream_id() helper
mmc: sdhci-tegra: Sort includes alphabetically

Quoted 5 lines
 drivers/mmc/host/sdhci-tegra.c | 69 ++++++++++++++++++++++++++++------
 drivers/mmc/host/sdhci.c       |  5 +++
 drivers/mmc/host/sdhci.h       |  2 +
 include/linux/iommu.h          | 25 ++++++++++++
 4 files changed, 89 insertions(+), 12 deletions(-)

Kind regards
Uffe

#8 lore raw

Hi all,

Quoted 25 lines · On Wed, 7 Dec 2022 13:37:52 +0100 Ulf Hansson <[email protected]> wrote:
Quoted 14 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Hi,

This is an updated version of v12 from a few days ago:

    https://lore.kernel.org/all/[email protected]/

The only difference here is a fix for the included headers (bitops.h does not have all the definitions on all architectures, so we need bitfield.h instead) and an Acked-by from Robin on the new Tegra-specific helper.

Quoted 6 lines

It'd be great to see this go in for v6.2 so that the new helper is available for the next release and the other patches that I have prepared can be merged.

Ulf, given that Joerg has acked patch 1 and Robin has acked patch 2, I think the expectation is for you to pick up the whole set.

Applied for next, thanks!

Quoted 27 lines

Note that, it seems likely that we may encounter a merge conflict between the mmc and iommu tree, due to changes in include/linux/iommu.h. Although, if that's the case, I believe the conflict should be trivial to resolve, so let's try this and see how it goes.

Stephen, I added you here, just to let you know of what goes on.

Quoted 19 lines

Thanks,
Thierry

Prathamesh Shete (3):
mmc: sdhci-tegra: Separate Tegra194 and Tegra234 SoC data
mmc: sdhci-tegra: Add support to program MC stream ID
mmc: sdhci-tegra: Issue CMD and DAT resets together

Thierry Reding (3):
iommu: Add note about struct iommu_fwspec usage iommu/tegra: Add tegra_dev_iommu_get_stream_id() helper
mmc: sdhci-tegra: Sort includes alphabetically

 drivers/mmc/host/sdhci-tegra.c | 69 ++++++++++++++++++++++++++++------
 drivers/mmc/host/sdhci.c       |  5 +++
 drivers/mmc/host/sdhci.h       |  2 +
 include/linux/iommu.h          | 25 ++++++++++++
 4 files changed, 89 insertions(+), 12 deletions(-)  

All good. Thanks for the heads up.

BTW, it would be good if some of those long lines in comments were wrapped ...

Signature · 2 lines
Cheers,
Stephen Rothwell
#9 lore raw
Quoted 56 lines · Stephen Rothwell

Hi all,

Quoted 25 lines · On Wed, 7 Dec 2022 13:37:52 +0100 Ulf Hansson <[email protected]> wrote:
Quoted 14 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Hi,

This is an updated version of v12 from a few days ago:

    https://lore.kernel.org/all/[email protected]/

The only difference here is a fix for the included headers (bitops.h does not have all the definitions on all architectures, so we need bitfield.h instead) and an Acked-by from Robin on the new Tegra-specific helper.

Quoted 6 lines

It'd be great to see this go in for v6.2 so that the new helper is available for the next release and the other patches that I have prepared can be merged.

Ulf, given that Joerg has acked patch 1 and Robin has acked patch 2, I think the expectation is for you to pick up the whole set.

Applied for next, thanks!

Quoted 27 lines

Note that, it seems likely that we may encounter a merge conflict between the mmc and iommu tree, due to changes in include/linux/iommu.h. Although, if that's the case, I believe the conflict should be trivial to resolve, so let's try this and see how it goes.

Stephen, I added you here, just to let you know of what goes on.

Quoted 19 lines

Thanks,
Thierry

Prathamesh Shete (3):
mmc: sdhci-tegra: Separate Tegra194 and Tegra234 SoC data
mmc: sdhci-tegra: Add support to program MC stream ID
mmc: sdhci-tegra: Issue CMD and DAT resets together

Thierry Reding (3):
iommu: Add note about struct iommu_fwspec usage iommu/tegra: Add tegra_dev_iommu_get_stream_id() helper
mmc: sdhci-tegra: Sort includes alphabetically

 drivers/mmc/host/sdhci-tegra.c | 69 ++++++++++++++++++++++++++++------
 drivers/mmc/host/sdhci.c       |  5 +++
 drivers/mmc/host/sdhci.h       |  2 +
 include/linux/iommu.h          | 25 ++++++++++++
 4 files changed, 89 insertions(+), 12 deletions(-)  
Quoted 4 lines

All good. Thanks for the heads up.

BTW, it would be good if some of those long lines in comments were wrapped ...

Hm... looks like I misinterpreted the checkpatch.pl change from a while ago. I should probably switch back my editor settings if the preference is still 80 characters instead of the 100 enforced by checkpatch.

Thierry