From patchwork Tue Feb 20 08:40:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shradha Todi X-Patchwork-Id: 774468 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 9B917664BA for ; Tue, 20 Feb 2024 11:21:27 +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=1708428089; cv=none; b=TbHuX2sVhplTbkRj+DBqXEvrjLviKa9kyny3iLnUtLAblT6aYDwQaJzpIRqMHliiMCP3boqvj3nA5ylumK/v3Y6e9Jzxfr2a0btd8tVxeAjsefuSyAndXsme9LMReGcEmhbTEcYnbyJ+AnvUq1Hj7mmhGowT4MVwLm7N0PgTLDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708428089; c=relaxed/simple; bh=OB9Ar1NlY5I15Pk9LqCt5ZPs1bwoDukWyfFACtz4y5k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:Content-Type: References; b=OVEuevvgept/I88DfGCEfoGhpWnyysccO3dC8w7XkikPZp2mINn96k2bru899uy28/CXcoNZIPrk6LzWlLi2QLaMPEu0D2G9NvzAtO5FTOT1s7WnaGldbHoDDGhaCfK/+c0g/oK5QO1SHdAGQp9miPmd2LR2RrxrpHZ9u4YG2lU= 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=bltpXq8T; 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="bltpXq8T" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20240220112125epoutp04da96386b3a369ffa8d39776725386c43~1jkrQk8YG2483524835epoutp04K for ; Tue, 20 Feb 2024 11:21:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20240220112125epoutp04da96386b3a369ffa8d39776725386c43~1jkrQk8YG2483524835epoutp04K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1708428085; bh=jvqK+xgmpuJsfH4tlmkfpfJUU2IQ6JvGvMe4vn39woo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bltpXq8TkaVHm7WBr50spV7EnsCIpZV4QRH8JBAtqQ2uolPv4KW1ze5dkelJVVSx8 WkavtzvH5fe5vfgNyGwnyiyOX6MeP4GwVAUS7+XoZI9w+mrRmAqHQbBlB4cPhsHv9x LK8ato2Y+XC1BcL1vDH3M7ZMASlXQsDaWJPmu8U8= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20240220112124epcas5p46dea8d0700649a32f10121ad57d9ea8a~1jkqSplB_0864008640epcas5p4D; Tue, 20 Feb 2024 11:21:24 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.176]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4TfH6B5Dlxz4x9Pp; Tue, 20 Feb 2024 11:21:22 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 42.F3.09672.23B84D56; Tue, 20 Feb 2024 20:21:22 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20240220084120epcas5p1e8980539667c3d9da20f49fc645d8f4c~1hY6LSPEX1617016170epcas5p1g; Tue, 20 Feb 2024 08:41:20 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240220084120epsmtrp29fe4a883c07fd71c9d95ce8b01da3ae9~1hY6KaaLR1209712097epsmtrp2S; Tue, 20 Feb 2024 08:41:20 +0000 (GMT) X-AuditID: b6c32a4b-60bfd700000025c8-f0-65d48b329a2e Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id E9.8B.07368.0B564D56; Tue, 20 Feb 2024 17:41:20 +0900 (KST) Received: from cheetah.sa.corp.samsungelectronics.net (unknown [107.109.115.53]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240220084118epsmtip1ddb341e7fee780d897731ff35c16f49b~1hY3kkhI_3013230132epsmtip1G; Tue, 20 Feb 2024 08:41:18 +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, gost.dev@samsung.com, Shradha Todi Subject: [PATCH v6 1/2] clk: Provide managed helper to get and enable bulk clocks Date: Tue, 20 Feb 2024 14:10:45 +0530 Message-Id: <20240220084046.23786-2-shradha.t@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240220084046.23786-1-shradha.t@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgF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OxbV6lntrnggF/B6U8zNabprQyfrC3SKnwgwTvwv9bt93Pi2GQ2PHq2IkSzuFvTJTD+ wf/6ZDW/KTrKrXs3t8yY+C7dcskx3QMfhDREz5nPd/zLx1/XLcw3q3lH+41FkeYXLpx1FVnh 8mz5/gCV4pzK6FapzPuGGR9vsqdlTMkwiZ4tWXg5bHdq2r3iqW9/JvcZzIv6G5THPU2JpTgj 0VCLuag4EQDPjVxx/gIAAA== X-CMS-MailID: 20240220084120epcas5p1e8980539667c3d9da20f49fc645d8f4c X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240220084120epcas5p1e8980539667c3d9da20f49fc645d8f4c References: <20240220084046.23786-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 Reviewed-by: Alim Akhtar Reviewed-by: Manivannan Sadhasivam Signed-off-by: Shradha Todi --- drivers/clk/clk-devres.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 22 ++++++++++++++++++++++ 2 files changed, 62 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..a8e6b045b848 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -438,6 +438,22 @@ 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 - Get and enable all clocks of the consumer (managed) + * @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 all clocks of the + * consumer and enables 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 +976,12 @@ 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) {