Skip to content

Commit ef8e341

Browse files
robherringmpe
authored andcommitted
powerpc: mpc512x: Remove open coded "ranges" parsing
"ranges" is a standard property, and we have common helper functions for parsing it, so let's use the for_each_of_range() iterator. Signed-off-by: Rob Herring <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent be0f9ca commit ef8e341

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

arch/powerpc/platforms/512x/mpc512x_lpbfifo.c

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -373,50 +373,32 @@ static int get_cs_ranges(struct device *dev)
373373
{
374374
int ret = -ENODEV;
375375
struct device_node *lb_node;
376-
const u32 *addr_cells_p;
377-
const u32 *size_cells_p;
378-
int proplen;
379-
size_t i;
376+
size_t i = 0;
377+
struct of_range_parser parser;
378+
struct of_range range;
380379

381380
lb_node = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-localbus");
382381
if (!lb_node)
383382
return ret;
384383

385-
/*
386-
* The node defined as compatible with 'fsl,mpc5121-localbus'
387-
* should have two address cells and one size cell.
388-
* Every item of its ranges property should consist of:
389-
* - the first address cell which is the chipselect number;
390-
* - the second address cell which is the offset in the chipselect,
391-
* must be zero.
392-
* - CPU address of the beginning of an access window;
393-
* - the only size cell which is the size of an access window.
394-
*/
395-
addr_cells_p = of_get_property(lb_node, "#address-cells", NULL);
396-
size_cells_p = of_get_property(lb_node, "#size-cells", NULL);
397-
if (addr_cells_p == NULL || *addr_cells_p != 2 ||
398-
size_cells_p == NULL || *size_cells_p != 1) {
399-
goto end;
400-
}
401-
402-
proplen = of_property_count_u32_elems(lb_node, "ranges");
403-
if (proplen <= 0 || proplen % 4 != 0)
404-
goto end;
384+
of_range_parser_init(&parser, lb_node);
385+
lpbfifo.cs_n = of_range_count(&parser);
405386

406-
lpbfifo.cs_n = proplen / 4;
407387
lpbfifo.cs_ranges = devm_kcalloc(dev, lpbfifo.cs_n,
408388
sizeof(struct cs_range), GFP_KERNEL);
409389
if (!lpbfifo.cs_ranges)
410390
goto end;
411391

412-
if (of_property_read_u32_array(lb_node, "ranges",
413-
(u32 *)lpbfifo.cs_ranges, proplen) != 0) {
414-
goto end;
415-
}
416-
417-
for (i = 0; i < lpbfifo.cs_n; i++) {
418-
if (lpbfifo.cs_ranges[i].base != 0)
392+
for_each_of_range(&parser, &range) {
393+
u32 base = lower_32_bits(range.bus_addr);
394+
if (base)
419395
goto end;
396+
397+
lpbfifo.cs_ranges[i].csnum = upper_32_bits(range.bus_addr);
398+
lpbfifo.cs_ranges[i].base = base;
399+
lpbfifo.cs_ranges[i].addr = range.cpu_addr;
400+
lpbfifo.cs_ranges[i].size = range.size;
401+
i++;
420402
}
421403

422404
ret = 0;

0 commit comments

Comments
 (0)