Skip to content

Commit c4ae179

Browse files
robherringmpe
authored andcommitted
powerpc: fsl_rio: Use of_range_to_resource() for "ranges" parsing
"ranges" is a standard property with common parsing functions. Users shouldn't be implementing their own parsing of it. Refactor the FSL RapidIO "ranges" parsing to use of_range_to_resource() instead. One change is the original code would look for "#size-cells" and "#address-cells" in the parent node if not found in the port child nodes. That is non-standard behavior and not necessary AFAICT. In 2011 in commit 5498696 ("powerpc/85xx: Update SRIO device tree nodes") there was an ABI break. The upstream .dts files have been correct since at least that point. Signed-off-by: Rob Herring <[email protected]> [mpe: Remove now unused "cell" variable] Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected] "ranges" is a standard property with common parsing functions. Users shouldn't be implementing their own parsing of it. Refactor the FSL RapidIO "ranges" parsing to use of_range_to_resource() instead. One change is the original code would look for "#size-cells" and "#address-cells" in the parent node if not found in the port child nodes. That is non-standard behavior and not necessary AFAICT. In 2011 in commit 5498696 ("powerpc/85xx: Update SRIO device tree nodes") there was an ABI break. The upstream .dts files have been correct since at least that point. Signed-off-by: Rob Herring <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent 6f3bdbb commit c4ae179

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

arch/powerpc/sysdev/fsl_rio.c

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,13 @@ int fsl_rio_setup(struct platform_device *dev)
448448
struct rio_mport *port;
449449
struct rio_priv *priv;
450450
int rc = 0;
451-
const u32 *dt_range, *cell, *port_index;
451+
const u32 *dt_range, *port_index;
452452
u32 active_ports = 0;
453453
struct device_node *np, *rmu_node;
454454
int rlen;
455455
u32 ccsr;
456-
u64 range_start, range_size;
457-
int paw, aw, sw;
456+
u64 range_start;
457+
int aw;
458458
u32 i;
459459
static int tmp;
460460
struct device_node *rmu_np[MAX_MSG_UNIT_NUM] = {NULL};
@@ -569,39 +569,23 @@ int fsl_rio_setup(struct platform_device *dev)
569569

570570
/*set up ports node*/
571571
for_each_child_of_node(dev->dev.of_node, np) {
572+
struct resource res;
573+
572574
port_index = of_get_property(np, "cell-index", NULL);
573575
if (!port_index) {
574576
dev_err(&dev->dev, "Can't get %pOF property 'cell-index'\n",
575577
np);
576578
continue;
577579
}
578580

579-
dt_range = of_get_property(np, "ranges", &rlen);
580-
if (!dt_range) {
581+
if (of_range_to_resource(np, 0, &res)) {
581582
dev_err(&dev->dev, "Can't get %pOF property 'ranges'\n",
582583
np);
583584
continue;
584585
}
585586

586-
/* Get node address wide */
587-
cell = of_get_property(np, "#address-cells", NULL);
588-
if (cell)
589-
aw = *cell;
590-
else
591-
aw = of_n_addr_cells(np);
592-
/* Get node size wide */
593-
cell = of_get_property(np, "#size-cells", NULL);
594-
if (cell)
595-
sw = *cell;
596-
else
597-
sw = of_n_size_cells(np);
598-
/* Get parent address wide wide */
599-
paw = of_n_addr_cells(np);
600-
range_start = of_read_number(dt_range + aw, paw);
601-
range_size = of_read_number(dt_range + aw + paw, sw);
602-
603-
dev_info(&dev->dev, "%pOF: LAW start 0x%016llx, size 0x%016llx.\n",
604-
np, range_start, range_size);
587+
dev_info(&dev->dev, "%pOF: LAW %pR\n",
588+
np, &res);
605589

606590
port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
607591
if (!port)
@@ -624,9 +608,7 @@ int fsl_rio_setup(struct platform_device *dev)
624608
}
625609

626610
INIT_LIST_HEAD(&port->dbells);
627-
port->iores.start = range_start;
628-
port->iores.end = port->iores.start + range_size - 1;
629-
port->iores.flags = IORESOURCE_MEM;
611+
port->iores = res; /* struct copy */
630612
port->iores.name = "rio_io_win";
631613

632614
if (request_resource(&iomem_resource, &port->iores) < 0) {

0 commit comments

Comments
 (0)