Skip to content

Commit 9c746e5

Browse files
Sam Protsenkokrzk
authored andcommitted
clk: samsung: Keep CPU clock chip specific data in a dedicated struct
Keep chip specific data in the data structure, don't mix it with code. It makes it easier to add more chip specific data further. Having all chip specific data in the table eliminates possible code bloat when adding more rate handlers for new chips, and also makes it possible to keep some other chip related data in that array. No functional change. Signed-off-by: Sam Protsenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Krzysztof Kozlowski <[email protected]>
1 parent 6d7d203 commit 9c746e5

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

drivers/clk/samsung/clk-cpu.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ struct exynos_cpuclk;
4343
typedef int (*exynos_rate_change_fn_t)(struct clk_notifier_data *ndata,
4444
struct exynos_cpuclk *cpuclk);
4545

46+
/**
47+
* struct exynos_cpuclk_chip - Chip specific data for CPU clock
48+
* @pre_rate_cb: callback to run before CPU clock rate change
49+
* @post_rate_cb: callback to run after CPU clock rate change
50+
*/
51+
struct exynos_cpuclk_chip {
52+
exynos_rate_change_fn_t pre_rate_cb;
53+
exynos_rate_change_fn_t post_rate_cb;
54+
};
55+
4656
/**
4757
* struct exynos_cpuclk - information about clock supplied to a CPU core
4858
* @hw: handle between CCF and CPU clock
@@ -55,8 +65,7 @@ typedef int (*exynos_rate_change_fn_t)(struct clk_notifier_data *ndata,
5565
* @clk_nb: clock notifier registered for changes in clock speed of the
5666
* primary parent clock
5767
* @flags: configuration flags for the CPU clock
58-
* @pre_rate_cb: callback to run before CPU clock rate change
59-
* @post_rate_cb: callback to run after CPU clock rate change
68+
* @chip: chip-specific data for the CPU clock
6069
*
6170
* This structure holds information required for programming the CPU clock for
6271
* various clock speeds.
@@ -70,9 +79,7 @@ struct exynos_cpuclk {
7079
const unsigned long num_cfgs;
7180
struct notifier_block clk_nb;
7281
unsigned long flags;
73-
74-
exynos_rate_change_fn_t pre_rate_cb;
75-
exynos_rate_change_fn_t post_rate_cb;
82+
const struct exynos_cpuclk_chip *chip;
7683
};
7784

7885
/* ---- Common code --------------------------------------------------------- */
@@ -420,13 +427,24 @@ static int exynos_cpuclk_notifier_cb(struct notifier_block *nb,
420427
cpuclk = container_of(nb, struct exynos_cpuclk, clk_nb);
421428

422429
if (event == PRE_RATE_CHANGE)
423-
err = cpuclk->pre_rate_cb(ndata, cpuclk);
430+
err = cpuclk->chip->pre_rate_cb(ndata, cpuclk);
424431
else if (event == POST_RATE_CHANGE)
425-
err = cpuclk->post_rate_cb(ndata, cpuclk);
432+
err = cpuclk->chip->post_rate_cb(ndata, cpuclk);
426433

427434
return notifier_from_errno(err);
428435
}
429436

437+
static const struct exynos_cpuclk_chip exynos_clkcpu_chips[] = {
438+
[CPUCLK_LAYOUT_E4210] = {
439+
.pre_rate_cb = exynos_cpuclk_pre_rate_change,
440+
.post_rate_cb = exynos_cpuclk_post_rate_change,
441+
},
442+
[CPUCLK_LAYOUT_E5433] = {
443+
.pre_rate_cb = exynos5433_cpuclk_pre_rate_change,
444+
.post_rate_cb = exynos5433_cpuclk_post_rate_change,
445+
},
446+
};
447+
430448
/* helper function to register a CPU clock */
431449
static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx,
432450
const struct samsung_cpu_clock *clk_data)
@@ -465,13 +483,7 @@ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx,
465483
cpuclk->lock = &ctx->lock;
466484
cpuclk->flags = clk_data->flags;
467485
cpuclk->clk_nb.notifier_call = exynos_cpuclk_notifier_cb;
468-
if (clk_data->reg_layout == CPUCLK_LAYOUT_E5433) {
469-
cpuclk->pre_rate_cb = exynos5433_cpuclk_pre_rate_change;
470-
cpuclk->post_rate_cb = exynos5433_cpuclk_post_rate_change;
471-
} else {
472-
cpuclk->pre_rate_cb = exynos_cpuclk_pre_rate_change;
473-
cpuclk->post_rate_cb = exynos_cpuclk_post_rate_change;
474-
}
486+
cpuclk->chip = &exynos_clkcpu_chips[clk_data->reg_layout];
475487

476488
ret = clk_notifier_register(parent->clk, &cpuclk->clk_nb);
477489
if (ret) {

0 commit comments

Comments
 (0)