1 From 7023dd1743aa6bb305fdce96e6e80eecc6e01f16 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Sat, 2 Apr 2022 14:49:56 +0200
4 Subject: [PATCH] clk: Introduce clk_hw_init_rate_request()
6 Some drivers (at91, imx, qcom) use __clk_determine_rate directly, and
7 thus will need to initialise a clk_rate_request structure.
9 However, drivers don't have access to the function that the core uses to
10 initialize that structure which could prove to be useful.
12 Let's create a function for clock providers that will initialize a
13 clk_rate_request for a given clk_hw pointer and a rate.
15 Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com> # imx8mp
16 Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> # exynos4210, meson g12b
17 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
19 drivers/clk/clk.c | 20 ++++++++++++++++++++
20 include/linux/clk-provider.h | 6 ++++++
21 2 files changed, 26 insertions(+)
23 --- a/drivers/clk/clk.c
24 +++ b/drivers/clk/clk.c
25 @@ -1395,6 +1395,26 @@ static void clk_core_init_rate_req(struc
30 + * clk_hw_init_rate_request - Initializes a clk_rate_request
31 + * @hw: the clk for which we want to submit a rate request
32 + * @req: the clk_rate_request structure we want to initialise
33 + * @rate: the rate which is to be requested
35 + * Initializes and fills a clk_rate_request structure to submit to
36 + * __clk_determine_rate or similar functions.
38 +void clk_hw_init_rate_request(struct clk_hw * const hw,
39 + struct clk_rate_request *req,
42 + if (WARN_ON(!hw || !req))
45 + clk_core_init_rate_req(hw->core, req, rate);
47 +EXPORT_SYMBOL_GPL(clk_hw_init_rate_request);
49 static bool clk_core_can_round(struct clk_core * const core)
51 return core->ops->determine_rate || core->ops->round_rate;
52 --- a/include/linux/clk-provider.h
53 +++ b/include/linux/clk-provider.h
54 @@ -42,6 +42,8 @@ struct dentry;
55 * struct clk_rate_request - Structure encoding the clk constraints that
56 * a clock user might require.
58 + * Should be initialized by calling clk_hw_init_rate_request().
60 * @rate: Requested clock rate. This field will be adjusted by
61 * clock drivers according to hardware capabilities.
62 * @min_rate: Minimum rate imposed by clk users.
63 @@ -60,6 +62,10 @@ struct clk_rate_request {
64 struct clk_hw *best_parent_hw;
67 +void clk_hw_init_rate_request(struct clk_hw * const hw,
68 + struct clk_rate_request *req,
69 + unsigned long rate);
72 * struct clk_duty - Struture encoding the duty cycle ratio of a clock