From patchwork Mon Apr 3 13:41:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 746453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vxYGd448nz9s7y for ; Mon, 3 Apr 2017 23:43:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=codeaurora.org header.i=@codeaurora.org header.b="PAnIV5ox"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="PAnIV5ox"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753352AbdDCNnY (ORCPT ); Mon, 3 Apr 2017 09:43:24 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:41778 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753249AbdDCNmV (ORCPT ); Mon, 3 Apr 2017 09:42:21 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9F5B160D72; Mon, 3 Apr 2017 13:42:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1491226940; bh=lZX2y5DO8xzLVhISReA0LdYORCc882i0I10Ux/DxSeI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PAnIV5oxa+sRKQQq9RMdVxyiJxRkWort5+Paz+HEa/18l/HIzs9jVi+2P8jyRkXJg wlqsRWJiHX0BXOVWy+fG6J1f0n4B7jOOag1ihChhRp+mLsk/xRZLlhLDTsEOwKS+32 hMvInZTq1NLHVcZ/2etMbTo2I1gXh9he/7kP0Ur0= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from blr-ubuntu-41.ap.qualcomm.com (unknown [202.46.23.61]) (using TLSv1.1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 6367A60DB0; Mon, 3 Apr 2017 13:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1491226940; bh=lZX2y5DO8xzLVhISReA0LdYORCc882i0I10Ux/DxSeI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PAnIV5oxa+sRKQQq9RMdVxyiJxRkWort5+Paz+HEa/18l/HIzs9jVi+2P8jyRkXJg wlqsRWJiHX0BXOVWy+fG6J1f0n4B7jOOag1ihChhRp+mLsk/xRZLlhLDTsEOwKS+32 hMvInZTq1NLHVcZ/2etMbTo2I1gXh9he/7kP0Ur0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 6367A60DB0 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org Cc: p.zabel@pengutronix.de, swarren@wwwdotorg.org, thierry.reding@gmail.com, balbi@kernel.org, Vivek Gautam Subject: [PATCH v2 1/4] reset: Add API to count number of reset available with device Date: Mon, 3 Apr 2017 19:11:59 +0530 Message-Id: <1491226922-20307-2-git-send-email-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491226922-20307-1-git-send-email-vivek.gautam@codeaurora.org> References: <1491226922-20307-1-git-send-email-vivek.gautam@codeaurora.org> Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Count number of reset phandles available with the device node to know the resets a given device has. Cc: Philipp Zabel Signed-off-by: Vivek Gautam --- Changes since v1: - Handling the error path by returning error code for failures and ENODEV for count equal to 0. - Moved the function to drivers instead of putting in the includes. drivers/reset/core.c | 22 ++++++++++++++++++++++ include/linux/reset.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index f1e5e65388bb..66db061165cb 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -455,3 +455,25 @@ int device_reset(struct device *dev) return ret; } EXPORT_SYMBOL_GPL(device_reset); + +/** + * of_reset_control_get_count - Count number of resets available with a device + * + * @node: device node that contains 'resets'. + * + * Returns positive reset count on success, or error number on failure and + * on count being zero. + */ +int of_reset_control_get_count(struct device_node *node) +{ + int count; + + count = of_count_phandle_with_args(node, "resets", "#reset-cells"); + if (count < 0) + return count; + if (count == 0) + return -ENODEV; + + return count; +} +EXPORT_SYMBOL_GPL(of_reset_control_get_count); diff --git a/include/linux/reset.h b/include/linux/reset.h index 96fb139bdd08..d89556412ccc 100644 --- a/include/linux/reset.h +++ b/include/linux/reset.h @@ -21,6 +21,7 @@ struct reset_control *__devm_reset_control_get(struct device *dev, bool optional); int __must_check device_reset(struct device *dev); +int of_reset_control_get_count(struct device_node *node); static inline int device_reset_optional(struct device *dev) { @@ -79,6 +80,11 @@ static inline struct reset_control *__devm_reset_control_get( return optional ? NULL : ERR_PTR(-ENOTSUPP); } +static inline int of_reset_control_get_count(struct device_node *node); +{ + return -ENOTSUPP; +} + #endif /* CONFIG_RESET_CONTROLLER */ /**