Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: Introduce clk_hw_init_rate_request()

clk-divider instantiates clk_rate_request internally for its round_rate
implementations to share the code with its determine_rate
implementations.

However, it's missing a few fields (min_rate, max_rate) that would be
initialized properly if it was using clk_core_init_rate_req().

Let's create the clk_hw_init_rate_request() function for clock providers
to be able to share the code to instation clk_rate_requests with the
framework. This will also be useful for some tests introduced in later
patches.

Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com> # imx8mp
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> # exynos4210, meson g12b
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20220816112530.1837489-17-maxime@cerno.tech
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Maxime Ripard and committed by
Stephen Boyd
c35e84b0 8cd9c39d

+36 -10
+10 -10
drivers/clk/clk-divider.c
··· 386 386 const struct clk_div_table *table, 387 387 u8 width, unsigned long flags) 388 388 { 389 - struct clk_rate_request req = { 390 - .rate = rate, 391 - .best_parent_rate = *prate, 392 - .best_parent_hw = parent, 393 - }; 389 + struct clk_rate_request req; 394 390 int ret; 391 + 392 + clk_hw_init_rate_request(hw, &req, rate); 393 + req.best_parent_rate = *prate; 394 + req.best_parent_hw = parent; 395 395 396 396 ret = divider_determine_rate(hw, &req, table, width, flags); 397 397 if (ret) ··· 408 408 const struct clk_div_table *table, u8 width, 409 409 unsigned long flags, unsigned int val) 410 410 { 411 - struct clk_rate_request req = { 412 - .rate = rate, 413 - .best_parent_rate = *prate, 414 - .best_parent_hw = parent, 415 - }; 411 + struct clk_rate_request req; 416 412 int ret; 413 + 414 + clk_hw_init_rate_request(hw, &req, rate); 415 + req.best_parent_rate = *prate; 416 + req.best_parent_hw = parent; 417 417 418 418 ret = divider_ro_determine_rate(hw, &req, table, width, flags, val); 419 419 if (ret)
+20
drivers/clk/clk.c
··· 1400 1400 } 1401 1401 } 1402 1402 1403 + /** 1404 + * clk_hw_init_rate_request - Initializes a clk_rate_request 1405 + * @hw: the clk for which we want to submit a rate request 1406 + * @req: the clk_rate_request structure we want to initialise 1407 + * @rate: the rate which is to be requested 1408 + * 1409 + * Initializes a clk_rate_request structure to submit to 1410 + * __clk_determine_rate() or similar functions. 1411 + */ 1412 + void clk_hw_init_rate_request(const struct clk_hw *hw, 1413 + struct clk_rate_request *req, 1414 + unsigned long rate) 1415 + { 1416 + if (WARN_ON(!hw || !req)) 1417 + return; 1418 + 1419 + clk_core_init_rate_req(hw->core, req, rate); 1420 + } 1421 + EXPORT_SYMBOL_GPL(clk_hw_init_rate_request); 1422 + 1403 1423 static bool clk_core_can_round(struct clk_core * const core) 1404 1424 { 1405 1425 return core->ops->determine_rate || core->ops->round_rate;
+6
include/linux/clk-provider.h
··· 42 42 * struct clk_rate_request - Structure encoding the clk constraints that 43 43 * a clock user might require. 44 44 * 45 + * Should be initialized by calling clk_hw_init_rate_request(). 46 + * 45 47 * @rate: Requested clock rate. This field will be adjusted by 46 48 * clock drivers according to hardware capabilities. 47 49 * @min_rate: Minimum rate imposed by clk users. ··· 61 59 unsigned long best_parent_rate; 62 60 struct clk_hw *best_parent_hw; 63 61 }; 62 + 63 + void clk_hw_init_rate_request(const struct clk_hw *hw, 64 + struct clk_rate_request *req, 65 + unsigned long rate); 64 66 65 67 /** 66 68 * struct clk_duty - Struture encoding the duty cycle ratio of a clock