From patchwork Mon Jun 5 09:42:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrice CHOTARD X-Patchwork-Id: 771168 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3wh91G4gNKz9s2P for ; Mon, 5 Jun 2017 19:45:54 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 74EDBC21C62; Mon, 5 Jun 2017 09:44:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id F2001C21C5F; Mon, 5 Jun 2017 09:42:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 40660C21C47; Mon, 5 Jun 2017 09:42:38 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [62.209.51.94]) by lists.denx.de (Postfix) with ESMTPS id E11CBC21C2B for ; Mon, 5 Jun 2017 09:42:34 +0000 (UTC) Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v559cvEk015850; Mon, 5 Jun 2017 11:42:34 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 2aujjvhewk-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 05 Jun 2017 11:42:34 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6BA2B34; Mon, 5 Jun 2017 09:42:33 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag6node3.st.com [10.75.127.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 511131422; Mon, 5 Jun 2017 09:42:33 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG6NODE3.st.com (10.75.127.18) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Mon, 5 Jun 2017 11:42:32 +0200 From: To: Marek Vasut , , Date: Mon, 5 Jun 2017 11:42:04 +0200 Message-ID: <1496655731-2251-5-git-send-email-patrice.chotard@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1496655731-2251-1-git-send-email-patrice.chotard@st.com> References: <1496655731-2251-1-git-send-email-patrice.chotard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG6NODE1.st.com (10.75.127.16) To SFHDAG6NODE3.st.com (10.75.127.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-05_03:, , signatures=0 Cc: christophe.kerello@st.com Subject: [U-Boot] [PATCH v6 04/11] clk: add clk_count() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Patrice Chotard Add clk_count() method to be able to get the number of clocks contained into a clock property. This will allow to allocate the right amount of memory in order to keep clock reference. These clock reference can be used later on error path or in .remove callback to release these clocks. Signed-off-by: Patrice Chotard Reviewed-by: Simon Glass --- v6: _ replace clk_get_by_index() by dev_read_phandle_with_args() in clk_count() v5: _ none v4: _ add clk_count() method drivers/clk/clk-uclass.c | 13 +++++++++++++ include/clk.h | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 83b6328..38d5f80 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -95,8 +95,21 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) return clk_request(dev_clk, clk); } + # endif /* OF_PLATDATA */ +int clk_count(struct udevice *dev) +{ + int count; + struct ofnode_phandle_args args; + + for (count = 0; ; count++) { + if (dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0, + count, &args)) + return count; + } +} + int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk) { int index; diff --git a/include/clk.h b/include/clk.h index 5a5c2ff..801920c 100644 --- a/include/clk.h +++ b/include/clk.h @@ -98,6 +98,18 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk); * @return 0 if OK, or a negative error code. */ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk); + +/** + * clk_count - Get clock count contained in the "clocks" property. + * + * This returns the count of clock found into the "clocks" property. This + * allows to allocate the right amount of memory to keep clock reference. + * + * @dev: The client device. + * @return number of clocks found. + */ +int clk_count(struct udevice *dev); + #else static inline int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)