Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4716320ybl; Mon, 26 Aug 2019 14:54:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9e3VEeEdUU6DIhbE4pMTXqV1DJ8riMTOY3SQmjtvwoIQDFPp6OlmlaQ3z5I7s6bunvmxP X-Received: by 2002:a17:90a:e2ca:: with SMTP id fr10mr6099142pjb.72.1566856494816; Mon, 26 Aug 2019 14:54:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566856494; cv=none; d=google.com; s=arc-20160816; b=ReWJmq7pkeCmNxl2t85ZN9onaOd+17ucCUwu4LAJRS0HVMp9yOdvzqZSjZRzW3ypSX BiF3gwuJ95zIzyao4GS+ZasyL5uzp6FhLvtvnJuZWxSS8i6Wtr6GfZW19hztbdOeQKik nJWaZU1P2JKQvu5HcIPmV+yjVNCPP/UW2wy3XpurE0WgcVxIK+di268If4mg3ukVR3Er 5ErpUCPba3naIzgScWstBdkWauh/fxPXd8h65UL0pgnGbktX4BWadkUcgiOPrBEpum91 6vBjDoDiDPBPRKGWzxYgqX8AsKhT71Et06UQl1kXauChsbKKxdYfnY9mk9EhjCEu8JfN NxVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YBctqWZij04mDyEvoUUDMqa1wdO4iWVD5Aa44JkPhco=; b=wdPBM1uWHPLy71mSPe4NGqGLGAZy1KAFW9CbGc5Sc22FwHQIvdQJfjWpCtvBxBdDcp TDApHQB9LKHxK4qRwfr7s/+fkNKrjEUcWp4XyamThmuJHdBIQkPbTduaLBez/xmHTbc0 jqHOqNsLFPYASzjmem4bT5y0XeghCTdR4/Z29VRfzcAnrbYH378EbVr5E/DXY58UUfc3 uPhoTKuHKtd44hK7F86jkC7V9djpYPoNBy6MzmK9GDNVjLQ5Nss7tL6WJElgbXTPOh/x OL8FnL3YCeBwdeLVTxEOU1oJtaRRyxegRd2/SJ+reyT5NO4kuHAl7vMGX8p57mfSiNcy xynw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WUYTOWgH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l35si11091571plb.322.2019.08.26.14.54.39; Mon, 26 Aug 2019 14:54:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WUYTOWgH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727735AbfHZVUp (ORCPT + 99 others); Mon, 26 Aug 2019 17:20:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:37100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726760AbfHZVUo (ORCPT ); Mon, 26 Aug 2019 17:20:44 -0400 Received: from mail.kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5F9D620850; Mon, 26 Aug 2019 21:20:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566854443; bh=T0JD8qnI+1dYLW2ehX5/L9s6yP8c59bF7QrrvgHwOqk=; h=From:To:Cc:Subject:Date:From; b=WUYTOWgHppyB/BswRdS0DFRR1o3k9ofrSF27KtjH+NIJYMe5zaYJ54v5BbnrNfhdf kMNHH7En6RqGUfnK/ADf8ZI2CNOH4zjBjrGK3bmnRQAyDQ+6wrWwWJ2+8Kz+m4O/pZ jGsewM4Cc5vasiPUe7FruSKOwEmJLXlNg2muIa9Q= From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Phil Edworthy Subject: [PATCH v2] clk: Document of_parse_clkspec() some more Date: Mon, 26 Aug 2019 14:20:42 -0700 Message-Id: <20190826212042.48642-1-sboyd@kernel.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The return value of of_parse_clkspec() is peculiar. If the function is called with a NULL argument for 'name' it will return -ENOENT, but if it's called with a non-NULL argument for 'name' it will return -EINVAL. This peculiarity is documented by commit 5c56dfe63b6e ("clk: Add comment about __of_clk_get_by_name() error values"). Let's further document this function so that it's clear what the return value is and how to use the arguments to parse clk specifiers. Cc: Phil Edworthy Signed-off-by: Stephen Boyd --- drivers/clk/clk.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index c0990703ce54..5c6585eb35d4 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -4316,12 +4316,43 @@ void devm_of_clk_del_provider(struct device *dev) } EXPORT_SYMBOL(devm_of_clk_del_provider); -/* - * Beware the return values when np is valid, but no clock provider is found. - * If name == NULL, the function returns -ENOENT. - * If name != NULL, the function returns -EINVAL. This is because - * of_parse_phandle_with_args() is called even if of_property_match_string() - * returns an error. +/** + * of_parse_clkspec() - Parse a DT clock specifier for a given device node + * @np: device node to parse clock specifier from + * @index: index of phandle to parse clock out of. If index < 0, @name is used + * @name: clock name to find and parse. If name is NULL, the index is used + * @out_args: Result of parsing the clock specifier + * + * Parses a device node's "clocks" and "clock-names" properties to find the + * phandle and cells for the index or name that is desired. The resulting clock + * specifier is placed into @out_args, or an errno is returned when there's a + * parsing error. The @index argument is ignored if @name is non-NULL. + * + * Example: + * + * phandle1: clock-controller@1 { + * #clock-cells = <2>; + * } + * + * phandle2: clock-controller@2 { + * #clock-cells = <1>; + * } + * + * clock-consumer@3 { + * clocks = <&phandle1 1 2 &phandle2 3>; + * clock-names = "name1", "name2"; + * } + * + * To get a device_node for `clock-controller@2' node you may call this + * function a few different ways: + * + * of_parse_clkspec(clock-consumer@3, -1, "name2", &args); + * of_parse_clkspec(clock-consumer@3, 1, NULL, &args); + * of_parse_clkspec(clock-consumer@3, 1, "name2", &args); + * + * Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT + * if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in + * the "clock-names" property of @np. */ static int of_parse_clkspec(const struct device_node *np, int index, const char *name, struct of_phandle_args *out_args) -- Sent by a computer through tubes