From patchwork Mon Feb 6 19:45:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 53479 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2431221wrn; Mon, 6 Feb 2023 11:59:40 -0800 (PST) X-Google-Smtp-Source: AK7set/eG5/GEOjirLEsEjem7qkrn3dU15y4GXOMETMy0SatgGLcHv/VCY+B0BhSQ5Zs5NDUIKxP X-Received: by 2002:a50:875d:0:b0:4aa:b454:4634 with SMTP id 29-20020a50875d000000b004aab4544634mr849111edv.29.1675713580225; Mon, 06 Feb 2023 11:59:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675713580; cv=none; d=google.com; s=arc-20160816; b=MgLoCR0ob5H+FZag+Ad9EFUg5orOsye9hRiEMUIWWgEAdbjGcCz2z/s2QSPbjauGE3 9+PEalro6WLBwoZLjTD3GgbhQNb+RcBOaoIG7kSY4UeL/3pUz3VYnijKaU+BQkP4SIg+ wO+S6hLP9r7NP5/PVQwVYL7JsvfbZ9qgwcuFIMxTUGCCI6D7ncC2vN1FSDwJ3lLu2rr4 VgMB5hNkQ1cQiRx3R2lXFZdirguZ1eVxY31gbZuAyw7Tv5oocl8YgNEmqlYBNJ4zauAM 5M+FFc+gD0h0l+ZGwe1uzXWOyWYAsJG5wGFRmoBP2HSrJLZ0gRi+RmwL65LDfYfX4lZK CwzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=F4DTh2z1rpPRJ/teaflCZt687gPrck3bGUNfCgC0QoI=; b=bamgDKzs5Fk7oBMoCa0D9xq0Lzfp5DdiTtx1gzct5Xge7Qq3Sg/ntyUthVQwxJyRUD NFmsfbMIIMIKgM+Y7tS8Kb5AOv39fE9qlcmYVcBauvQAg9Dto/dHZV4IbWhHqgD+Lx4O q0mjIAvwiDa62WTO0QQ/LKqFHJ1G2CfTJomW3/UWff0211sweAsFDY62Ve0w+XdOxZoZ 5ghnD1kYvM7VZaWR/NjjxXogVkCZDKPGDVqNle+GF3Ovm2zdaGMgDNCx+t84Lm97Xv96 5xxfS5ufSAHe1wnOx7eOTYxqxBFmwCflb5d4ZB2PXT+xAjfWEzEfu1Iz77yWRBdBL54X 2BtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cn28-20020a0564020cbc00b004a0d634cd0asi12238086edb.237.2023.02.06.11.59.16; Mon, 06 Feb 2023 11:59:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbjBFTqJ (ORCPT + 99 others); Mon, 6 Feb 2023 14:46:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjBFTqH (ORCPT ); Mon, 6 Feb 2023 14:46:07 -0500 Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DB281164F for ; Mon, 6 Feb 2023 11:46:06 -0800 (PST) Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-163bd802238so16510787fac.1 for ; Mon, 06 Feb 2023 11:46:06 -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=F4DTh2z1rpPRJ/teaflCZt687gPrck3bGUNfCgC0QoI=; b=Gehv3KAmCPDlOO+E738oe3GNLu6K3kWVTJC9nvcYAA+z2qZsA1hDcQ6M+XBl1xHmPd n56P4jIHRk1K54JUj9BmWZdrrqq/K7ml01yUbLjDAaTIKBD/VTRx0Ulvp7jV7c0FdNtl kGh+GKJid1arzEqckFE44Wr+C8IuXR+kkzSwcWHbzbAK/hHAf48p0TDy5/ehb7lI6/K+ KcVSZYr820r/YR+mbyyZHcZBRRcH8b3Q5UCf12IO9ij39uL4hw9FndweQ2Omwh8yR0ys SjWd4GhXchqfbgXsaJ8DVg0oatkixLt5Da3qt6kF5oeXTpXL/my4PfzHW7IavmQib9+R WL7g== X-Gm-Message-State: AO0yUKVacNdN++U2+SSqEqCUqW3uB/bL7ShTd8lZzSgH47oOt/Hlj1Ry sVYtnm0U9PsCUfsR3Lmx1g== X-Received: by 2002:a05:6871:6a9:b0:15e:cfce:fcb9 with SMTP id l41-20020a05687106a900b0015ecfcefcb9mr11802215oao.34.1675712765745; Mon, 06 Feb 2023 11:46:05 -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 h5-20020a056870538500b0015f9cc16ef7sm4487247oan.46.2023.02.06.11.46.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 11:46:05 -0800 (PST) Received: (nullmailer pid 1173026 invoked by uid 1000); Mon, 06 Feb 2023 19:46:04 -0000 From: Rob Herring To: Kunihiko Hayashi , Masami Hiramatsu Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] bus: uniphier-system-bus: Remove open coded "ranges" parsing Date: Mon, 6 Feb 2023 13:45:04 -0600 Message-Id: <20230206194503.1162108-1-robh@kernel.org> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757113043207853860?= X-GMAIL-MSGID: =?utf-8?q?1757113043207853860?= "ranges" is a standard property and we have common helper functions for parsing it, so let's use them. Tested-by: Kunihiko Hayashi Signed-off-by: Rob Herring --- Compile tested only! v2: - Fix subject: s/unifier/uniphier/ --- 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; }