mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2024-12-29 09:12:07 +00:00
bus: uniphier-system-bus: Remove open coded "ranges" parsing
"ranges" is a standard property and we have common helper functions for parsing it, so let's use them. Tested-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com> Link: https://lore.kernel.org/r/20230206194503.1162108-1-robh@kernel.org Signed-off-by: Rob Herring <robh@kernel.org>
This commit is contained in:
parent
fe15c26ee2
commit
c12cc1bc7d
@ -176,10 +176,9 @@ static int uniphier_system_bus_probe(struct platform_device *pdev)
|
|||||||
{
|
{
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
struct uniphier_system_bus_priv *priv;
|
struct uniphier_system_bus_priv *priv;
|
||||||
const __be32 *ranges;
|
struct of_range_parser parser;
|
||||||
u32 cells, addr, size;
|
struct of_range range;
|
||||||
u64 paddr;
|
int ret;
|
||||||
int pna, bank, rlen, rone, ret;
|
|
||||||
|
|
||||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||||
if (!priv)
|
if (!priv)
|
||||||
@ -191,48 +190,17 @@ static int uniphier_system_bus_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
priv->dev = dev;
|
priv->dev = dev;
|
||||||
|
|
||||||
pna = of_n_addr_cells(dev->of_node);
|
ret = of_range_parser_init(&parser, dev->of_node);
|
||||||
|
if (ret)
|
||||||
ret = of_property_read_u32(dev->of_node, "#address-cells", &cells);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(dev, "failed to get #address-cells\n");
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
if (cells != 2) {
|
|
||||||
dev_err(dev, "#address-cells must be 2\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = of_property_read_u32(dev->of_node, "#size-cells", &cells);
|
for_each_of_range(&parser, &range) {
|
||||||
if (ret) {
|
if (range.cpu_addr == OF_BAD_ADDR)
|
||||||
dev_err(dev, "failed to get #size-cells\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (cells != 1) {
|
|
||||||
dev_err(dev, "#size-cells must be 1\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ranges = of_get_property(dev->of_node, "ranges", &rlen);
|
|
||||||
if (!ranges) {
|
|
||||||
dev_err(dev, "failed to get ranges property\n");
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
rlen /= sizeof(*ranges);
|
|
||||||
rone = pna + 2;
|
|
||||||
|
|
||||||
for (; rlen >= rone; rlen -= rone) {
|
|
||||||
bank = be32_to_cpup(ranges++);
|
|
||||||
addr = be32_to_cpup(ranges++);
|
|
||||||
paddr = of_translate_address(dev->of_node, ranges);
|
|
||||||
if (paddr == OF_BAD_ADDR)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
ranges += pna;
|
ret = uniphier_system_bus_add_bank(priv,
|
||||||
size = be32_to_cpup(ranges++);
|
upper_32_bits(range.bus_addr),
|
||||||
|
lower_32_bits(range.bus_addr),
|
||||||
ret = uniphier_system_bus_add_bank(priv, bank, addr,
|
range.cpu_addr, range.size);
|
||||||
paddr, size);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user