From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C188C07E9B for ; Mon, 12 Jul 2021 06:20:54 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A390761184 for ; Mon, 12 Jul 2021 06:20:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A390761184 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0230082C5C; Mon, 12 Jul 2021 08:20:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="VLCP0uGS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6141682C50; Mon, 12 Jul 2021 08:20:37 +0200 (CEST) Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3F26182C03 for ; Mon, 12 Jul 2021 08:20:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kishon@ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 16C6KWER047472; Mon, 12 Jul 2021 01:20:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1626070832; bh=hFmHwpMNedrGfbLhZd6Or10fhV4GuCz5ji6euTUsB/o=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=VLCP0uGSnYV2ftcRm2NWDFOKh7WN6HYH8mOEARCvM64YdDffoLGyTX+V7EcW2iS8J +h/fYJxMdc2Y4NHZ0VGSVJGn3qfZ0l6LzqqGQaTeQ5OzcsJI0wlGb1OstlywY/FY9H Qh3ymj4lO76MsmfdLo4BUNQYvsFFCTbss/82H5iE= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 16C6KWxX108768 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Jul 2021 01:20:32 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 12 Jul 2021 01:20:31 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2 via Frontend Transport; Mon, 12 Jul 2021 01:20:32 -0500 Received: from a0393678-ssd.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 16C6KQhI019216; Mon, 12 Jul 2021 01:20:29 -0500 From: Kishon Vijay Abraham I To: Lokesh Vutla , Simon Glass CC: Kishon Vijay Abraham I , Aswath Govindraju , Pratyush Yadav , Subject: [PATCH v4 01/21] drivers: reset: Add devm_to_reset() to return dummy "struct reset_ctl" Date: Mon, 12 Jul 2021 11:50:05 +0530 Message-ID: <20210712062025.14518-2-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210712062025.14518-1-kishon@ti.com> References: <20210712062025.14518-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Add devm_to_reset() to return dummy "struct reset_ctl", useful for invoking reset APIs which doesn't have a valid "struct reset_ctl". Suggested-by: Simon Glass Signed-off-by: Kishon Vijay Abraham I --- drivers/reset/reset-uclass.c | 16 ++++++++++++++++ drivers/reset/sandbox-reset-test.c | 4 +++- include/reset.h | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c index 8caa616ed9..9f2eeb4fe4 100644 --- a/drivers/reset/reset-uclass.c +++ b/drivers/reset/reset-uclass.c @@ -15,6 +15,8 @@ #include #include +static struct reset_ctl devm_no_reset; + static inline struct reset_ops *reset_dev_ops(struct udevice *dev) { return (struct reset_ops *)dev->driver->ops; @@ -256,6 +258,20 @@ int reset_release_all(struct reset_ctl *reset_ctl, int count) return 0; } +int devm_to_reset(struct reset_ctl *in, struct reset_ctl **outp) +{ + if (IS_ERR_OR_NULL(in)) { + *outp = &devm_no_reset; + if (!in) + return -ENOENT; + else + return PTR_ERR(in); + } + *outp = in; + + return 0; +} + static void devm_reset_release(struct udevice *dev, void *res) { reset_free(res); diff --git a/drivers/reset/sandbox-reset-test.c b/drivers/reset/sandbox-reset-test.c index 51b79810c8..4389bde5e7 100644 --- a/drivers/reset/sandbox-reset-test.c +++ b/drivers/reset/sandbox-reset-test.c @@ -32,13 +32,15 @@ int sandbox_reset_test_get_devm(struct udevice *dev) { struct sandbox_reset_test *sbrt = dev_get_priv(dev); struct reset_ctl *r; + int ret; r = devm_reset_control_get(dev, "not-a-valid-reset-ctl"); if (!IS_ERR(r)) return -EINVAL; r = devm_reset_control_get_optional(dev, "not-a-valid-reset-ctl"); - if (r) + ret = devm_to_reset(r, &r); + if (reset_valid(r)) return -EINVAL; sbrt->ctlp = devm_reset_control_get(dev, "test"); diff --git a/include/reset.h b/include/reset.h index cde2c4b4a8..21affc1455 100644 --- a/include/reset.h +++ b/include/reset.h @@ -341,6 +341,18 @@ int reset_status(struct reset_ctl *reset_ctl); */ int reset_release_all(struct reset_ctl *reset_ctl, int count); +/** + * devm_to_reset - Provide a dummy reset_ctl for invalid reset_ctl + * + * Provide a dummy reset_ctl for invalid reset_ctl or give the same + * input reset_ctl + * + * @in: Input reset_ctl returned by devm_reset_control_get() + * @outp: Dummy reset_ctl for invalid reset_ctl or Input reset_ctl + * @return 0 if OK, or a negative error code. + */ +int devm_to_reset(struct reset_ctl *in, struct reset_ctl **outp); + /** * reset_release_bulk - Assert/Free an array of previously requested reset * signals in a reset control bulk struct. @@ -456,6 +468,11 @@ static inline int reset_release_bulk(struct reset_ctl_bulk *bulk) { return 0; } + +static inline int devm_to_reset(struct reset_ctl *in, struct reset_ctl **outp) +{ + return 0; +} #endif /** -- 2.17.1