From 2743c767ff581acdb3005ef9407dcbae24bf36ad Mon Sep 17 00:00:00 2001
From: Pratyush Yadav
Date: Tue, 19 Apr 2022 16:14:47 +0530
Subject: [PATCH] spi: cadence-qspi: allow parsing both "new" and "legacy"
partitions
In the "legacy" way, partitions are listed directly under the flash
node. In the "new" way, there is a partitions node under the flash node,
and the partitions are listed under that node. Allow parsing both styles
of partitions for finding the PHY pattern location.
Signed-off-by: Pratyush Yadav
---
drivers/spi/cadence_qspi.c | 48 ++++++++++++++++++++++++++++----------
1 file changed, 36 insertions(+), 12 deletions(-)
diff --git a/drivers/spi/cadence_qspi.c b/drivers/spi/cadence_qspi.c
index fbadf2a956..81dd80c389 100644
--- a/drivers/spi/cadence_qspi.c
+++ b/drivers/spi/cadence_qspi.c
@@ -911,12 +911,41 @@ static void cadence_spi_mem_do_calibration(struct spi_slave *spi,
ret);
}
+static int cadence_spi_ofdata_phy_pattern(struct cadence_spi_platdata *plat,
+ ofnode flash_node)
+{
+ ofnode subnode;
+ const char *label;
+ u32 start;
+
+ subnode = ofnode_find_subnode(flash_node, "partitions");
+ if (!ofnode_valid(subnode))
+ /*
+ * Maybe the node has legacy style partitions, listed directly
+ * under flash node.
+ */
+ subnode = ofnode_first_subnode(flash_node);
+ else
+ subnode = ofnode_first_subnode(subnode);
+
+ while (ofnode_valid(subnode)) {
+ label = ofnode_read_string(subnode, "label");
+ if (label && strcmp(label, "ospi.phypattern") == 0) {
+ if (!ofnode_read_u32_array(subnode, "reg", &start, 1))
+ return start;
+ break;
+ }
+ subnode = ofnode_next_subnode(subnode);
+ }
+
+ return -ENOENT;
+}
+
static int cadence_spi_ofdata_to_platdata(struct udevice *bus)
{
struct cadence_spi_platdata *plat = bus->platdata;
ofnode subnode;
- const char *label;
- u32 start;
+ int ret;
plat->regbase = (void *)devfdt_get_addr_index(bus, 0);
plat->ahbbase = (void *)devfdt_get_addr_size_index(bus, 1,
@@ -969,16 +998,11 @@ static int cadence_spi_ofdata_to_platdata(struct udevice *bus)
48);
/* Find the PHY tuning pattern partition. */
- subnode = ofnode_first_subnode(subnode);
- while (ofnode_valid(subnode)) {
- label = ofnode_read_string(subnode, "label");
- if (label && strcmp(label, "ospi.phypattern") == 0) {
- if (!ofnode_read_u32_array(subnode, "reg", &start, 1))
- plat->phy_pattern_start = start;
- break;
- }
- subnode = ofnode_next_subnode(subnode);
- }
+ ret = cadence_spi_ofdata_phy_pattern(plat, subnode);
+ if (ret < 0)
+ dev_dbg(plat->dev, "Unable to find PHY pattern partition\n");
+ else
+ plat->phy_pattern_start = ret;
debug("%s: regbase=%p ahbbase=%p max-frequency=%d page-size=%d\n",
__func__, plat->regbase, plat->ahbbase, plat->max_hz,