From patchwork Wed Jan 24 10:38:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shradha Todi X-Patchwork-Id: 13529037 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DAE35B217 for ; Wed, 24 Jan 2024 11:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096873; cv=none; b=uk3keTkvYmsqoeznahlwT/NxOX1rhAQTebxyRRBZpd32LmQ+NOzqZIeL2ROJShKl6QLRcU/ltVsHZt0MXGn57a7u5HsRJgTQl09vLD40VGrR5wGzFvGKPpZ6Mvdn1iWBcZTYz2rIVGwS75I5LbcjHQsDhSK0AJwhC1lXVosKk+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096873; c=relaxed/simple; bh=Q2Lv21q+LPYK+1GamQvuvIuUxtbkeVPHvD2B7RxGgdg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:Content-Type: References; b=CA+/OPeD07TDZ1rQeW9xgWNJzpnmnyESYk3ymnRNOzN1/fK/ffEiJpnvxCzkoCfEt8ths+cL6cLLb+JKnDIiDVVMwu5JuGj0PvVJfJTesVTmGMw9bDazG0bahbs6M8Kc4Mji0Hy7r2YIUk9PqCgyI98rqxDE0/upSD3UpYummUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=Zx3Sgs3f; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="Zx3Sgs3f" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20240124114749epoutp042df4362584346ca1dbb15807abec1bee~tRhBGrSON0877508775epoutp04j for ; Wed, 24 Jan 2024 11:47:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20240124114749epoutp042df4362584346ca1dbb15807abec1bee~tRhBGrSON0877508775epoutp04j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1706096869; bh=O+tABnUnHrJhacFqwRIfEaygao34+wSqrWI/LqRW9yA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zx3Sgs3fErkJhtj11/K5XGyPlpx6jR8LJwuioedMyAO7bYVEEPuS1P+gh+lgMiZ3T NVt7o7SzJhjecNLlLGUcf6RYbX26Y1P24pHsT3dXplzrQqLd7vNhsdlYo+hBCDT/Qo XsFRrgq0j2iSeyNF42e/wN2qeKvn8PEopgdN1FX8= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20240124114748epcas5p19c19c7a52bd78878d3be50572c99e215~tRhAKg7AO0246702467epcas5p1C; Wed, 24 Jan 2024 11:47:48 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.181]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4TKhz65RwRz4x9Px; Wed, 24 Jan 2024 11:47:46 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id F5.35.09634.2E8F0B56; Wed, 24 Jan 2024 20:47:46 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20240124103855epcas5p27400bd95df42f36b9547a4e28aa26f5d~tQk2i396z2401024010epcas5p21; Wed, 24 Jan 2024 10:38:55 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240124103855epsmtrp2a7f6b1794ef3de4fae42c9c2e1221ff7~tQk2h0d2j2380723807epsmtrp2P; Wed, 24 Jan 2024 10:38:55 +0000 (GMT) X-AuditID: b6c32a49-159fd700000025a2-69-65b0f8e2a0ec Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 3F.2E.07368.EB8E0B56; Wed, 24 Jan 2024 19:38:54 +0900 (KST) Received: from cheetah.sa.corp.samsungelectronics.net (unknown [107.109.115.53]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240124103852epsmtip251e8ba5a9680c4140a2a0264c5f62669~tQk0CbMz_0276602766epsmtip2a; Wed, 24 Jan 2024 10:38:52 +0000 (GMT) From: Shradha Todi To: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Cc: mturquette@baylibre.com, sboyd@kernel.org, jingoohan1@gmail.com, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, krzysztof.kozlowski@linaro.org, alim.akhtar@samsung.com, linux@armlinux.org.uk, m.szyprowski@samsung.com, manivannan.sadhasivam@linaro.org, pankaj.dubey@samsung.com, Shradha Todi Subject: [PATCH v4 1/2] clk: Provide managed helper to get and enable bulk clocks Date: Wed, 24 Jan 2024 16:08:37 +0530 Message-Id: <20240124103838.32478-2-shradha.t@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240124103838.32478-1-shradha.t@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIJ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FIZnuw+a7co4cOFD5HLxHy/UnLiuaih5t5iVlb+cfaLJvf9Qe2eP5iRF5Qdakte+iJpuOVHN 6Bqx2Uqg10NFUyM1q55Dc6nVyvZbLkwLKrNWrDBbv+6EK+e/krhV3gKPBG+ufz/XS+LSzYq0 omO3JW5pym7XrbgaFF3yP4ZDY0kmw6PZDg3xEve6xQpeKu5vFTqYYef14oHVnCYlluKMREMt 5qLiRABSbpLx/AIAAA== X-CMS-MailID: 20240124103855epcas5p27400bd95df42f36b9547a4e28aa26f5d X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240124103855epcas5p27400bd95df42f36b9547a4e28aa26f5d References: <20240124103838.32478-1-shradha.t@samsung.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Provide a managed devm_clk_bulk* wrapper to get and enable all bulk clocks in order to simplify drivers that keeps all clocks enabled for the time of driver operation. Suggested-by: Marek Szyprowski Signed-off-by: Shradha Todi Reviewed-by: Alim Akhtar --- drivers/clk/clk-devres.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 24 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index 4fb4fd4b06bd..cbbd2cc339c3 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -182,6 +182,46 @@ int __must_check devm_clk_bulk_get_all(struct device *dev, } EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all); +static void devm_clk_bulk_release_all_enable(struct device *dev, void *res) +{ + struct clk_bulk_devres *devres = res; + + clk_bulk_disable_unprepare(devres->num_clks, devres->clks); + clk_bulk_put_all(devres->num_clks, devres->clks); +} + +int __must_check devm_clk_bulk_get_all_enable(struct device *dev, + struct clk_bulk_data **clks) +{ + struct clk_bulk_devres *devres; + int ret; + + devres = devres_alloc(devm_clk_bulk_release_all_enable, + sizeof(*devres), GFP_KERNEL); + if (!devres) + return -ENOMEM; + + ret = clk_bulk_get_all(dev, &devres->clks); + if (ret > 0) { + *clks = devres->clks; + devres->num_clks = ret; + } else { + devres_free(devres); + return ret; + } + + ret = clk_bulk_prepare_enable(devres->num_clks, *clks); + if (!ret) { + devres_add(dev, devres); + } else { + clk_bulk_put_all(devres->num_clks, devres->clks); + devres_free(devres); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all_enable); + static int devm_clk_match(struct device *dev, void *res, void *data) { struct clk **c = res; diff --git a/include/linux/clk.h b/include/linux/clk.h index 1ef013324237..a005e709b7bd 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -438,6 +438,23 @@ int __must_check devm_clk_bulk_get_optional(struct device *dev, int num_clks, int __must_check devm_clk_bulk_get_all(struct device *dev, struct clk_bulk_data **clks); +/** + * devm_clk_bulk_get_all_enable - managed get multiple clk consumers and + * enable all clks + * @dev: device for clock "consumer" + * @clks: pointer to the clk_bulk_data table of consumer + * + * Returns success (0) or negative errno. + * + * This helper function allows drivers to get several clk + * consumers and enable all of them in one operation with management. + * The clks will automatically be disabled and freed when the device + * is unbound. + */ + +int __must_check devm_clk_bulk_get_all_enable(struct device *dev, + struct clk_bulk_data **clks); + /** * devm_clk_get - lookup and obtain a managed reference to a clock producer. * @dev: device for clock "consumer" @@ -960,6 +977,13 @@ static inline int __must_check devm_clk_bulk_get_all(struct device *dev, return 0; } +static inline int __must_check devm_clk_bulk_get_all_enable(struct device *dev, + struct clk_bulk_data **clks) +{ + + return 0; +} + static inline struct clk *devm_get_clk_from_child(struct device *dev, struct device_node *np, const char *con_id) {