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,