mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vadym Kochan <vadym.kochan@plvision.eu>
To: Hu Ziji <huziji@marvell.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Vadym Kochan <vadym.kochan@plvision.eu>,
	linux-mmc@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Elad Nachman <enachman@marvell.com>
Subject: [PATCH 2/3] mmc: sdhci-xenon: Try to fix 2G address limitation on AC5 SoC
Date: Sat,  6 Aug 2022 11:58:13 +0300	[thread overview]
Message-ID: <20220806085818.9873-3-vadym.kochan@plvision.eu> (raw)
In-Reply-To: <20220806085818.9873-1-vadym.kochan@plvision.eu>

There is a limitation on AC5 SoC that Xenon SDHC can address only
first 2GB of memory. Turning to the SDMA mode to use the bounce_buffer
causes ext_csd recognition to fail on init.

Using of swiotlb=force also does not help as it is allocated at the
end of the memory.

So it was decided to use reserved-memory as a bounce buffer in case
if the board has more than 2G of memory, or turn on the PIO
mode if such memory region does not exist in the device-tree.

It was tested that this approach is 1.5 times faster than PIO.

Signed-off-by: Vadym Kochan <vadym.kochan@plvision.eu>
---
 drivers/mmc/host/sdhci-xenon.c | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/drivers/mmc/host/sdhci-xenon.c b/drivers/mmc/host/sdhci-xenon.c
index 08e838400b52..fbbd1a045002 100644
--- a/drivers/mmc/host/sdhci-xenon.c
+++ b/drivers/mmc/host/sdhci-xenon.c
@@ -14,8 +14,10 @@
 #include <linux/acpi.h>
 #include <linux/delay.h>
 #include <linux/ktime.h>
+#include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
 
@@ -486,6 +488,31 @@ static void xenon_sdhc_unprepare(struct sdhci_host *host)
 	xenon_disable_sdhc(host, sdhc_id);
 }
 
+static int xenon_ac5_probe(struct sdhci_host *host)
+{
+	struct device *dev = mmc_dev(host->mmc);
+	struct sysinfo si;
+	int err;
+
+	si_meminfo(&si);
+
+	if ((si.totalram * si.mem_unit) > SZ_2G) {
+		struct device_node *dma_bounce_np;
+
+		dma_bounce_np = of_parse_phandle(dev->of_node,
+						 "marvell,ac5-sdhci-dma-bounce-pool", 0);
+		err = of_reserved_mem_device_init_by_idx(dev, dma_bounce_np, 0);
+		of_node_put(dma_bounce_np);
+		if (err) {
+			dev_warn(dev, "Disabling DMA because of 2GB DMA access limit and missing DMA bounce region\n");
+			host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
+			host->quirks |= SDHCI_QUIRK_BROKEN_DMA;
+		}
+	}
+
+	return 0;
+}
+
 static int xenon_probe(struct platform_device *pdev)
 {
 	struct sdhci_pltfm_host *pltfm_host;
@@ -531,6 +558,12 @@ static int xenon_probe(struct platform_device *pdev)
 			if (err)
 				goto err_clk;
 		}
+
+		if (of_device_is_compatible(dev->of_node, "marvell,ac5-sdhci")) {
+			err = xenon_ac5_probe(host);
+			if (err)
+				goto err_clk_axi;
+		}
 	}
 
 	err = mmc_of_parse(host->mmc);
@@ -570,6 +603,7 @@ static int xenon_probe(struct platform_device *pdev)
 	pm_runtime_put_noidle(&pdev->dev);
 	xenon_sdhc_unprepare(host);
 err_clk_axi:
+	of_reserved_mem_device_release(&pdev->dev);
 	clk_disable_unprepare(priv->axi_clk);
 err_clk:
 	clk_disable_unprepare(pltfm_host->clk);
@@ -591,6 +625,7 @@ static int xenon_remove(struct platform_device *pdev)
 	sdhci_remove_host(host, 0);
 
 	xenon_sdhc_unprepare(host);
+	of_reserved_mem_device_release(&pdev->dev);
 	clk_disable_unprepare(priv->axi_clk);
 	clk_disable_unprepare(pltfm_host->clk);
 
@@ -682,6 +717,7 @@ static const struct of_device_id sdhci_xenon_dt_ids[] = {
 	{ .compatible = "marvell,armada-ap807-sdhci", .data = (void *)XENON_AP807},
 	{ .compatible = "marvell,armada-cp110-sdhci", .data =  (void *)XENON_CP110},
 	{ .compatible = "marvell,armada-3700-sdhci", .data =  (void *)XENON_A3700},
+	{ .compatible = "marvell,ac5-sdhci", .data = (void *)XENON_AP806},
 	{}
 };
 MODULE_DEVICE_TABLE(of, sdhci_xenon_dt_ids);
-- 
2.17.1


  parent reply	other threads:[~2022-08-06  8:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-06  8:58 [PATCH 0/3] mmc: xenon-sdhci: " Vadym Kochan
2022-08-06  8:58 ` [PATCH 1/3] dt-bindings: mmc: xenon: Add compatible string for Xenon SDHCI " Vadym Kochan
2022-08-08  9:18   ` Krzysztof Kozlowski
2022-08-06  8:58 ` Vadym Kochan [this message]
2022-08-08  9:20   ` [PATCH 2/3] mmc: sdhci-xenon: Try to fix 2G address limitation " Krzysztof Kozlowski
2022-08-06  8:58 ` [PATCH 3/3] arm64: dts: marvell: Add DTSI to fix Xenon SDHCI 2G " Vadym Kochan
2022-08-08  9:21   ` Krzysztof Kozlowski

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=20220806085818.9873-3-vadym.kochan@plvision.eu \
    --to=vadym.kochan@plvision.eu \
    --cc=adrian.hunter@intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=enachman@marvell.com \
    --cc=huziji@marvell.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=robh+dt@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

all inboxes | Powered by JetHome®