From patchwork Fri Jan 27 11:15:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 49225 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp778869wrn; Fri, 27 Jan 2023 03:22:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXvx6fNqVK1qcaWQcbWOWZSco0lrOCcKX8Hm9sHma/cj7FpvxfdRqSAHthuszQe6lL/qti96 X-Received: by 2002:a05:6a21:6d90:b0:b6:9f9f:4ba7 with SMTP id wl16-20020a056a216d9000b000b69f9f4ba7mr50586230pzb.47.1674818549392; Fri, 27 Jan 2023 03:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674818549; cv=none; d=google.com; s=arc-20160816; b=iB1wMUnMEn6BQzwx5IJUFm9N8TSAB13R+7/nVyrpeuHNJRzRfTlJby9qkFPzryaC0T F7kdAEVQLLl5THoq42/is5/e1g/iNiqIQUfksA/u1AUyHBOxYX+sZ+nahq6GrHpbGCds 1Iw5qj/INCeO6vzOiataurGcQiydmLzeV4kpmaxqzxYVr7bcVCQuckaeQNj7rg+ncctg sLIryHtNpZidXX/1j2tLV2Uf1t5lEq1NxNO97zgw0eCzvePmwyQE+F8bF1kXFkgQ7r4/ pfDM0xRa3C3gcK0KLdPNwpvLB8vsHzVwpp8M3pOImqazs8FpygZuDP/t4nyHGaIgA2i6 OUqQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bZk++rAGilP0se2vyyYc9G9oc9KF7qnie14AIpwjJ4k=; b=LfDtxsy9gKvnwhF38eVnTW9jH1qNxZceP+c5K9bMnvqoAqfXO7QlEv6Cs94qhqWtBF aJx2e5xMToV7HKLhMmafzMYZahg+0AxQFF0l5tArQHYNbOL7GUOzg34K80PaZ47Qpb22 QUax9yRP9bY6QA+/CyMR5nx3rBMBjSy6171pobDVblBef7BvkU6Sv+0jTsgcw0cx4Gsu Alk5xxke4uB08YXt3hba3roRKCSTGzKw9AW75qRzGlL73JzjDm8Z2WeDth3xO+K/YvWD A8pmU0M/0EqPkyd65nk8ctkHTsGayflB+gQ3AaT8fXheK9eVVMTEWKdCE6e7d0w1cBVC +bkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mH55wi35; 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=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i184-20020a6387c1000000b00477b463b049si4012277pge.491.2023.01.27.03.22.16; Fri, 27 Jan 2023 03:22:29 -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; dkim=pass header.i=@linaro.org header.s=google header.b=mH55wi35; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231990AbjA0LSH (ORCPT + 99 others); Fri, 27 Jan 2023 06:18:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231683AbjA0LSA (ORCPT ); Fri, 27 Jan 2023 06:18:00 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E0FA1287F for ; Fri, 27 Jan 2023 03:17:52 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id n7so4667577wrx.5 for ; Fri, 27 Jan 2023 03:17:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bZk++rAGilP0se2vyyYc9G9oc9KF7qnie14AIpwjJ4k=; b=mH55wi35SGoIcZosh++cTF0urwF1ISiGMPK+u5pVhn0ZP+8/mXMQ4553H5Xq+rDlnD Q0Q9/4IgRPYC4GEYvRk5127ZvR7qVaYONYG7qCpiq13Silz5Rx/fgSNPGzLq2QECnpZ2 +3VBnVquC5hIX5otJ31sYDAz8Dh6QQc16zAS88ut9nr7lMdz1TMFruQCpMAyaYme1Hhj 2yklV773O7HtDjyNCubCQ2X891uP1r/eTu1NdMbjdLXFZF+beGrIRejXNMcPA2M0NVN8 07awVLrveihnfUwpzYMX7eFoYmPt2Y3sSlw/liYBFuvUP20/2d71c2wlKMY2caBWJteH uFcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bZk++rAGilP0se2vyyYc9G9oc9KF7qnie14AIpwjJ4k=; b=X8CNyUf0erOgtLXkZ3tSqccsfFOs6I3tgSiNkzjNKRyjrePhjoZqMFM+oH+0Bis+zW wPjb54v6j2Fev9tKwdvZLbBHUk8zg4xIFcwYosqCern0vvsE4DceTNhRtLiAlBc6Ybp7 I5HYAEM2Z9BZKAvUxJTEBaC6/yYLwhARDh00BNH22/Gm27GtCZYw9wrlq4PfpYLzttub zGNHf420c0OOEBueUOJgC8d8V/hy/QtjKOupd9kuyHFwcm+2RWI/vcN7EcirMBui9YQO BDopca4SGVZ6DG3Q+KU9A+iA7ykGnnq+hEoWqZCFAkS7aSCRll8TF55dVUFlfsLnNYld PDkA== X-Gm-Message-State: AO0yUKUXBNDvebpfHhmi2HS1giO857Z6E24QEMDQtTAIUYMwxcfrLSZ/ NmK7WKvbyI+I56OFX78Xa6rx6Q== X-Received: by 2002:adf:8b48:0:b0:2bf:d6f9:23d6 with SMTP id v8-20020adf8b48000000b002bfd6f923d6mr653061wra.45.1674818272559; Fri, 27 Jan 2023 03:17:52 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id c13-20020adffb0d000000b002bfd190fd60sm1843314wrr.108.2023.01.27.03.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 03:17:52 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Michael Walle , Rob Herring , Srinivas Kandagatla Subject: [PATCH 09/37] of: base: add of_parse_phandle_with_optional_args() Date: Fri, 27 Jan 2023 11:15:37 +0000 Message-Id: <20230127111605.25958-10-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230127111605.25958-1-srinivas.kandagatla@linaro.org> References: <20230127111605.25958-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1756174535351056796?= X-GMAIL-MSGID: =?utf-8?q?1756174535351056796?= From: Michael Walle Add a new variant of the of_parse_phandle_with_args() which treats the cells name as optional. If it's missing, it is assumed that the phandle has no arguments. Up until now, a nvmem node didn't have any arguments, so all the device trees haven't any '#*-cells' property. But there is a need for an additional argument for the phandle, for which we need a '#*-cells' property. Therefore, we need to support nvmem nodes with and without this property. Signed-off-by: Michael Walle Reviewed-by: Rob Herring Signed-off-by: Srinivas Kandagatla --- include/linux/of.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index 8b9f94386dc3..98c252d2d851 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1008,6 +1008,31 @@ static inline int of_parse_phandle_with_fixed_args(const struct device_node *np, index, out_args); } +/** + * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list + * @np: pointer to a device tree node containing a list + * @list_name: property name that contains a list + * @cells_name: property name that specifies phandles' arguments count + * @index: index of a phandle to parse out + * @out_args: optional pointer to output arguments structure (will be filled) + * + * Same as of_parse_phandle_with_args() except that if the cells_name property + * is not found, cell_count of 0 is assumed. + * + * This is used to useful, if you have a phandle which didn't have arguments + * before and thus doesn't have a '#*-cells' property but is now migrated to + * having arguments while retaining backwards compatibility. + */ +static inline int of_parse_phandle_with_optional_args(const struct device_node *np, + const char *list_name, + const char *cells_name, + int index, + struct of_phandle_args *out_args) +{ + return __of_parse_phandle_with_args(np, list_name, cells_name, + 0, index, out_args); +} + /** * of_property_count_u8_elems - Count the number of u8 elements in a property *