From patchwork Wed Feb 1 22:00:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 13125044 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 69AA8C05027 for ; Wed, 1 Feb 2023 22:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=8ZjX3sCKagcU8zXnhI71mi4Z2Z52PytqYwwlN+tFlyA=; b=Qhis5fdxrKMuyQ oQXF1TBvCfCVj5oJdIuTftXfFpyHEW3vbui7TovBPcGle3bKOJiZZJYx3JcIip4JXZLFYfNz/9+ma Ijewp+KzV3PkU9OdYj97Xjf7ViQdM5/YDtRuohCWQ8qeLNvU2cTKioReCqjzdIy9OEO1G9deAQuFi pTgyUHCwwfLO3SdkKwXh0WaUWafCwjktg39O/8b36KLLbEvSImfGhHoHL+6jkYAk6JnR/X0inQO3l pw7hqhKZoXSGGmKMU/1NaHOcQQrJ3pqtDm711cvV1+/CwtIxtDOwAWCOrAMhMJwQ7yOJAthHRIhF3 b1iq43D4StzdLGqdCByA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNL9U-00DisY-8h; Wed, 01 Feb 2023 22:00:24 +0000 Received: from mail-oi1-f182.google.com ([209.85.167.182]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNL9Q-00Diqs-Pu for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 22:00:22 +0000 Received: by mail-oi1-f182.google.com with SMTP id s124so16961513oif.1 for ; Wed, 01 Feb 2023 14:00:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1XkbBn50HbU84B9DuICUZoT4NR3IzYgz7CKBq7MuAxw=; b=ZamkBAgqs9mduARc3VTa359ktncFWTPDNSpjz0DstXQDKtcAQGPpn1VRJSSgB6FeTd DSSRR5yxV9tgIT0wMJLJclQ4AWlIqh2mSCkrtMQBHhHmXDCf1lREezPpm7fLv1mkkRv/ dwSaVxwGryCsbtHnmvbNkWxiti9QrIvwBI6mzl3ff/4O8gjeiMFJcDXG6ggsuW7dJ6ez y0Z76jNi2rPqSTDeYR77kebBWG3XZMwvhHnBuLXmOZzFT5vqWfYG/Bt5eHilR6hd4owU une+hXOl0AekpAYKhVbMqilneJEub/9uaweZjsIud8ulL1AKhqvnXNxif0DMuefhGhgB c7Qw== X-Gm-Message-State: AO0yUKX0W4dCHPi9F9WSIImCVnf78ydMGcgYdhCfk6WhBO/lJHo/PJ2/ gpMs1wkQaTkdYgH/6nizhw== X-Google-Smtp-Source: AK7set+jOLkoidQpkXezdpSyqHhfDQEIuM5uDLkeDa17UAn3sp+hbfiK31GUqWVbrvLf1BpYzxvwBg== X-Received: by 2002:a05:6808:ab7:b0:367:18a6:eb26 with SMTP id r23-20020a0568080ab700b0036718a6eb26mr1802405oij.42.1675288818506; Wed, 01 Feb 2023 14:00:18 -0800 (PST) Received: from robh_at_kernel.org (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id a186-20020acab1c3000000b00363760f96dcsm7308714oif.42.2023.02.01.14.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 14:00:17 -0800 (PST) Received: (nullmailer pid 247224 invoked by uid 1000); Wed, 01 Feb 2023 22:00:17 -0000 From: Rob Herring To: Kunihiko Hayashi , Masami Hiramatsu Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] bus: unifier-system-bus: Remove open coded "ranges" parsing Date: Wed, 1 Feb 2023 16:00:11 -0600 Message-Id: <20230201220011.247100-1-robh@kernel.org> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230201_140020_861651_FBBE1FD2 X-CRM114-Status: GOOD ( 15.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org "ranges" is a standard property and we have common helper functions for parsing it, so let's use them. Signed-off-by: Rob Herring Tested-by: Kunihiko Hayashi --- Compile tested only! --- drivers/bus/uniphier-system-bus.c | 54 +++++++------------------------ 1 file changed, 11 insertions(+), 43 deletions(-) diff --git a/drivers/bus/uniphier-system-bus.c b/drivers/bus/uniphier-system-bus.c index f70dedace20b..cb5c89ce7b86 100644 --- a/drivers/bus/uniphier-system-bus.c +++ b/drivers/bus/uniphier-system-bus.c @@ -176,10 +176,9 @@ static int uniphier_system_bus_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct uniphier_system_bus_priv *priv; - const __be32 *ranges; - u32 cells, addr, size; - u64 paddr; - int pna, bank, rlen, rone, ret; + struct of_range_parser parser; + struct of_range range; + int ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -191,48 +190,17 @@ static int uniphier_system_bus_probe(struct platform_device *pdev) priv->dev = dev; - pna = of_n_addr_cells(dev->of_node); - - ret = of_property_read_u32(dev->of_node, "#address-cells", &cells); - if (ret) { - dev_err(dev, "failed to get #address-cells\n"); - 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); - if (ret) { - dev_err(dev, "failed to get #size-cells\n"); + ret = of_range_parser_init(&parser, dev->of_node); + if (ret) 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) + for_each_of_range(&parser, &range) { + if (range.cpu_addr == OF_BAD_ADDR) return -EINVAL; - ranges += pna; - size = be32_to_cpup(ranges++); - - ret = uniphier_system_bus_add_bank(priv, bank, addr, - paddr, size); + ret = uniphier_system_bus_add_bank(priv, + upper_32_bits(range.bus_addr), + lower_32_bits(range.bus_addr), + range.cpu_addr, range.size); if (ret) return ret; }