Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp910372rdd; Wed, 10 Jan 2024 03:22:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhdoKmphVsLKogUkFWFpKv6wkMw+1K8qTAhRJtLBHsuSEHbL/2Xzzj4YsJeVdtSIJrzsIN X-Received: by 2002:a9d:6f99:0:b0:6dc:2da9:9177 with SMTP id h25-20020a9d6f99000000b006dc2da99177mr551818otq.28.1704885726575; Wed, 10 Jan 2024 03:22:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704885726; cv=none; d=google.com; s=arc-20160816; b=j9fE8uZgmGQ/6ffCUOxkXY7CPjvywBSNIe3Z6MS5AiTZKHDhF17oXj1z0H0xu7w/tA ztJ3ZyaZFyII8lcZcf4LMD18yj8WcYIGLTKzK/OgT2QgudldhjClrabPMTUmUlulf2jg BjCPqalTVSsN4W8LTESAeFggFpN82oJ6OHVeQfWihDxKeUF1qmxrUJO1s8CWB8zCS1Fk lBKAfYO565XNjMhcp+k3BLqVINjdNtOYgXskMWKE48CGv43UkrwMyWKIHfKYGO7XtLul ebftZ3cxRZ64RH0F/yrwmK5bl5k2BYycGaCv+rZUlgJElg+/4df2tvnWFooEKJNibYoM 93JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :dlp-filter:cms-type:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=5oVmRhw2DfUJW61C/c9zwKTKzkdVt14suKM8C/BBVEY=; fh=ZhBKaGK23i1dYZzdDnZxkhCTgEcBxr6bkJnMsyodX9o=; b=sHaDbQ6BjqvlgOPkfLeHksXoNRe9Kf+vLKC2bFRTeLNGwbab/ZUiZ7xyGYdA2G6urQ p+859+geCRxyLnSf/pg73MRfSaxvswrq3+Qcf9750RawwfhnR4LekYHYb5AVVLQUI9eo ndeZl/ATAOuNOJ9qzoKXEbQO1AMi8nmpcHwpjEIGvb2coRdJvX2ese+NDM+NF2pVLSvD 6YAv+aw/2ifPugfDvOyihkNbiAGZFptc1ZjxKN3Mj54WNl66DEcfNkTRqKXN85fcs1P1 Ja6r9gH8tREC/7KNF815Br4vw0bbznN19/vWj2CecsNt9Sy7bgQc6ERQTWla8W5hHkhN Ro4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=GorskU85; spf=pass (google.com: domain of linux-kernel+bounces-22060-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22060-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bo10-20020a056a02038a00b005cd811e2ffesi3761530pgb.18.2024.01.10.03.22.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 03:22:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22060-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=GorskU85; spf=pass (google.com: domain of linux-kernel+bounces-22060-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22060-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B72C5B25E15 for ; Wed, 10 Jan 2024 11:17:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C967447A60; Wed, 10 Jan 2024 11:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="GorskU85" Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (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 F188F4776E for ; Wed, 10 Jan 2024 11:17:19 +0000 (UTC) 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 Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20240110111718epoutp0329f742b7f37d9db838572a5e96b139d5~o_EXoLA-B1490714907epoutp03S for ; Wed, 10 Jan 2024 11:17:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20240110111718epoutp0329f742b7f37d9db838572a5e96b139d5~o_EXoLA-B1490714907epoutp03S DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1704885438; bh=5oVmRhw2DfUJW61C/c9zwKTKzkdVt14suKM8C/BBVEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GorskU85DYGrPGHrFSSOGGWqYfUVdu/wh2OYQ1kU1UQqP5VSpm3mV/kwdKurLxAuy OjvoiVYG6oe+58PITzAbzi0iAUPanX2EiP2mSIw+9lIiTlBdTcINVVZV0QVwDOiGB/ lnV+n+WmfBW5TLQiPFUfcs/IwgILPUIjwwEbGExA= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20240110111717epcas5p183dc719452830456683bf33f66b9b428~o_EWnxG_l3020330203epcas5p19; Wed, 10 Jan 2024 11:17:17 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.177]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4T94yM2zMwz4x9Pp; Wed, 10 Jan 2024 11:17:15 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 62.98.10009.BBC7E956; Wed, 10 Jan 2024 20:17:15 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20240110110156epcas5p36bac4093be0fa6eaa501d7eaed4d43d3~o929HlXk90210902109epcas5p33; Wed, 10 Jan 2024 11:01:56 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240110110156epsmtrp25c8f09c24cebfbf0b2aad59d9d9cacab~o929Gty2p2407724077epsmtrp25; Wed, 10 Jan 2024 11:01:56 +0000 (GMT) X-AuditID: b6c32a4a-261fd70000002719-b7-659e7cbba513 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 88.50.18939.4297E956; Wed, 10 Jan 2024 20:01:56 +0900 (KST) Received: from cheetah.sa.corp.samsungelectronics.net (unknown [107.109.115.53]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240110110153epsmtip1c77ed0ded73c66bdf11224772f4a851b~o926taL6P2247622476epsmtip1d; Wed, 10 Jan 2024 11:01:53 +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, Shradha Todi Subject: [PATCH v3 1/2] clk: Provide managed helper to get and enable bulk clocks Date: Wed, 10 Jan 2024 16:31:14 +0530 Message-Id: <20240110110115.56270-2-shradha.t@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240110110115.56270-1-shradha.t@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNJsWRmVeSWpSXmKPExsWy7bCmhu7umnmpBnMui1g8mLeNzWJJU4bF ii8z2S32vt7KbtHQ85vVYtPja6wWH3vusVpc3jWHzeLsvONsFjPO72OyODR1L6NFy58WFou1 R+6yW9xt6WS1uHjK1eL/nh3sFv+ubWSx6D1c6yDkcfnaRWaP9zda2T12zrrL7rFgU6nHplWd bB53ru1h83hyZTqTx+Yl9R59W1YxenzeJBfAFZVtk5GamJJapJCal5yfkpmXbqvkHRzvHG9q ZmCoa2hpYa6kkJeYm2qr5OIToOuWmQP0kZJCWWJOKVAoILG4WEnfzqYov7QkVSEjv7jEVim1 ICWnwKRArzgxt7g0L10vL7XEytDAwMgUqDAhO2P3hwusBT2yFScuL2NrYPwr3sXIySEhYCLx es47ti5GLg4hgd2MEp92LmaCcD4xSuxcvA3B6Vt0iaWLkQOs5eItGYj4TkaJWT1XGCGcViaJ o8e+sYPMZRPQkmj82sUMkhARWMwocWvHZlYQh1ngBFDV2W2MIFXCAsESnQ1/WUBsFgFViel9 e9hAVvAKWEk0H5aCOFBeYvWGA8wgNqeAtcTqxbPZQeZICGzhkDh2bBETRJGLxKy20ywQtrDE q+Nb2CFsKYnP7/ayQdjpEis3z2CGsHMkvm1eAtVrL3Hgyhyw15gFNCXW79KHCMtKTD21DqyE WYBPovf3E6hyXokd82BsZYkvf/dArZWUmHfsMiuE7SFxZMYzsBeFBPoYJfZ9M5zAKDcLYcMC RsZVjJKpBcW56anFpgVGeanl8Fh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W/9U7xMjEwXiIUYKDWUmEV+HznFQh3pTEyqrUovz4 otKc1OJDjNIcLErivMo5nSlCAumJJanZqakFqUUwWSYOTqkGJlNtpQlTHubf+aIudGTxX/uf twozHKecC7J87hwlpK3K5Xxvfan0r3Ncc3f9WGAf92Wl5duW1U/SXh0K3PQnsvpz/OeQzOTC 99v7QtaceH6zzz71XXjDzObvgs/75CKvZpUGnf/C5f3mZ+Ru+V3HJmZ/zNdzDjsi15Fd0Mxw aOknnejNFUfy/m5+xPVsfur6x18br3A5NO09Pv3Jp2c/W4v228xyS+a07wjbfP7KotZnv5TD nRfefb92pQa3arin5PrvQYfqV3qsutIZcYXZinEGo2rqK+ulzoldCTFvjnzUUMw7xlc2XWez T3tOr9DtVzlB0UkiW6OOrL0nK799Dq+Ttb3cWd8fE1qicnol2JRYijMSDbWYi4oTAdwxEfHx AgAA X-CMS-MailID: 20240110110156epcas5p36bac4093be0fa6eaa501d7eaed4d43d3 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240110110156epcas5p36bac4093be0fa6eaa501d7eaed4d43d3 References: <20240110110115.56270-1-shradha.t@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@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 --- drivers/clk/clk-devres.c | 41 ++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 25 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index 4fb4fd4b06bd..05b0ff4bc1d4 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -102,6 +102,7 @@ EXPORT_SYMBOL_GPL(devm_clk_get_optional_enabled); struct clk_bulk_devres { struct clk_bulk_data *clks; int num_clks; + void (*exit)(int num_clks, const struct clk_bulk_data *clks); }; static void devm_clk_bulk_release(struct device *dev, void *res) @@ -182,6 +183,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_enabled(struct device *dev, void *res) +{ + struct clk_bulk_devres *devres = res; + + if (devres->exit) + devres->exit(devres->num_clks, devres->clks); + + clk_bulk_put_all(devres->num_clks, devres->clks); +} + +int __must_check devm_clk_bulk_get_all_enabled(struct device *dev, + struct clk_bulk_data **clks, int *num_clks) +{ + struct clk_bulk_devres *devres; + int ret; + + devres = devres_alloc(devm_clk_bulk_release_all_enabled, + 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; + *num_clks = ret; + devres_add(dev, devres); + } else { + devres_free(devres); + return ret; + } + + ret = clk_bulk_prepare_enable(devres->num_clks, *clks); + if (!ret) + devres->exit = clk_bulk_disable_unprepare; + + return ret; +} +EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all_enabled); + 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..bf3e9bee5754 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -438,6 +438,24 @@ 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_enabled - managed get multiple clk consumers and + * enable all clk + * @dev: device for clock "consumer" + * @clks: pointer to the clk_bulk_data table of consumer + * @num_clks: out parameter to store the number of clk_bulk_data + * + * 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_enabled(struct device *dev, + struct clk_bulk_data **clks, int *num_clks); + /** * devm_clk_get - lookup and obtain a managed reference to a clock producer. * @dev: device for clock "consumer" @@ -960,6 +978,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_enabled(struct device *dev, + struct clk_bulk_data **clks, int *num_clks) +{ + + return 0; +} + static inline struct clk *devm_get_clk_from_child(struct device *dev, struct device_node *np, const char *con_id) { -- 2.17.1