Skip to content

Commit 8e76682

Browse files
committed
Merge tag 'clk-meson-v6.17-1' of https://github.com/BayLibre/clk-meson into clk-amlogic
Pull Amlogic clk driver updates from Jerome Brunet: - Use the auxiliary reset controller implementation in the Amlogic axg-audio, instead of implementing the reset controller in drivers/clk - Drop unnecessary clock controller headers for Amlogic drivers - Drop clock controller big regmap tables in the Amlogic drivers * tag 'clk-meson-v6.17-1' of https://github.com/BayLibre/clk-meson: clk: amlogic: s4: remove unused data clk: amlogic: drop clk_regmap tables clk: amlogic: get regmap with clk_regmap_init clk: amlogic: remove unnecessary headers clk: amlogic: axg-audio: use the auxiliary reset driver clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests clk: tests: Make clk_register_clk_parent_data_device_driver() common clk: add a clk_hw helpers to get the clock device or device_node
2 parents 19272b3 + 8a65268 commit 8e76682

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+874
-3120
lines changed

drivers/clk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ clk-test-y := clk_test.o \
1818
kunit_clk_assigned_rates_without_consumer.dtbo.o \
1919
kunit_clk_assigned_rates_zero.dtbo.o \
2020
kunit_clk_assigned_rates_zero_consumer.dtbo.o \
21+
kunit_clk_hw_get_dev_of_node.dtbo.o \
2122
kunit_clk_parent_data_test.dtbo.o
2223
obj-$(CONFIG_COMMON_CLK) += clk-divider.o
2324
obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o

drivers/clk/clk.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,18 @@ const char *clk_hw_get_name(const struct clk_hw *hw)
365365
}
366366
EXPORT_SYMBOL_GPL(clk_hw_get_name);
367367

368+
struct device *clk_hw_get_dev(const struct clk_hw *hw)
369+
{
370+
return hw->core->dev;
371+
}
372+
EXPORT_SYMBOL_GPL(clk_hw_get_dev);
373+
374+
struct device_node *clk_hw_get_of_node(const struct clk_hw *hw)
375+
{
376+
return hw->core->of_node;
377+
}
378+
EXPORT_SYMBOL_GPL(clk_hw_get_of_node);
379+
368380
struct clk_hw *__clk_get_hw(struct clk *clk)
369381
{
370382
return !clk ? NULL : clk->core->hw;

drivers/clk/clk_test.c

Lines changed: 186 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,49 +2794,49 @@ static struct kunit_suite clk_register_clk_parent_data_of_suite = {
27942794
};
27952795

27962796
/**
2797-
* struct clk_register_clk_parent_data_device_ctx - Context for clk_parent_data device tests
2798-
* @dev: device of clk under test
2799-
* @hw: clk_hw for clk under test
2797+
* struct platform_driver_dev_ctx - Context to stash platform device
2798+
* @dev: device under test
28002799
* @pdrv: driver to attach to find @dev
28012800
*/
2802-
struct clk_register_clk_parent_data_device_ctx {
2801+
struct platform_driver_dev_ctx {
28032802
struct device *dev;
2804-
struct clk_hw hw;
28052803
struct platform_driver pdrv;
28062804
};
28072805

2808-
static inline struct clk_register_clk_parent_data_device_ctx *
2809-
clk_register_clk_parent_data_driver_to_test_context(struct platform_device *pdev)
2806+
static inline struct platform_driver_dev_ctx *
2807+
pdev_to_platform_driver_dev_ctx(struct platform_device *pdev)
28102808
{
28112809
return container_of(to_platform_driver(pdev->dev.driver),
2812-
struct clk_register_clk_parent_data_device_ctx, pdrv);
2810+
struct platform_driver_dev_ctx, pdrv);
28132811
}
28142812

2815-
static int clk_register_clk_parent_data_device_probe(struct platform_device *pdev)
2813+
static int kunit_platform_driver_dev_probe(struct platform_device *pdev)
28162814
{
2817-
struct clk_register_clk_parent_data_device_ctx *ctx;
2815+
struct platform_driver_dev_ctx *ctx;
28182816

2819-
ctx = clk_register_clk_parent_data_driver_to_test_context(pdev);
2817+
ctx = pdev_to_platform_driver_dev_ctx(pdev);
28202818
ctx->dev = &pdev->dev;
28212819

28222820
return 0;
28232821
}
28242822

2825-
static void clk_register_clk_parent_data_device_driver(struct kunit *test)
2823+
static struct device *
2824+
kunit_of_platform_driver_dev(struct kunit *test, const struct of_device_id *match_table)
28262825
{
2827-
struct clk_register_clk_parent_data_device_ctx *ctx = test->priv;
2828-
static const struct of_device_id match_table[] = {
2829-
{ .compatible = "test,clk-parent-data" },
2830-
{ }
2831-
};
2826+
struct platform_driver_dev_ctx *ctx;
28322827

2833-
ctx->pdrv.probe = clk_register_clk_parent_data_device_probe;
2828+
ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
2829+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
2830+
2831+
ctx->pdrv.probe = kunit_platform_driver_dev_probe;
28342832
ctx->pdrv.driver.of_match_table = match_table;
28352833
ctx->pdrv.driver.name = __func__;
28362834
ctx->pdrv.driver.owner = THIS_MODULE;
28372835

28382836
KUNIT_ASSERT_EQ(test, 0, kunit_platform_driver_register(test, &ctx->pdrv));
28392837
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->dev);
2838+
2839+
return ctx->dev;
28402840
}
28412841

28422842
static const struct clk_register_clk_parent_data_test_case
@@ -2909,30 +2909,34 @@ KUNIT_ARRAY_PARAM(clk_register_clk_parent_data_device_test,
29092909
*/
29102910
static void clk_register_clk_parent_data_device_test(struct kunit *test)
29112911
{
2912-
struct clk_register_clk_parent_data_device_ctx *ctx;
2912+
struct device *dev;
2913+
struct clk_hw *hw;
29132914
const struct clk_register_clk_parent_data_test_case *test_param;
29142915
struct clk_hw *parent_hw;
29152916
struct clk_init_data init = { };
29162917
struct clk *expected_parent, *actual_parent;
2918+
static const struct of_device_id match_table[] = {
2919+
{ .compatible = "test,clk-parent-data" },
2920+
{ }
2921+
};
29172922

2918-
ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
2919-
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
2920-
test->priv = ctx;
2921-
2922-
clk_register_clk_parent_data_device_driver(test);
2923+
dev = kunit_of_platform_driver_dev(test, match_table);
29232924

2924-
expected_parent = clk_get_kunit(test, ctx->dev, "50");
2925+
expected_parent = clk_get_kunit(test, dev, "50");
29252926
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected_parent);
29262927

2928+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
2929+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
2930+
29272931
test_param = test->param_value;
29282932
init.parent_data = &test_param->pdata;
29292933
init.num_parents = 1;
29302934
init.name = "parent_data_device_test_clk";
29312935
init.ops = &clk_dummy_single_parent_ops;
2932-
ctx->hw.init = &init;
2933-
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, &ctx->hw));
2936+
hw->init = &init;
2937+
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, hw));
29342938

2935-
parent_hw = clk_hw_get_parent(&ctx->hw);
2939+
parent_hw = clk_hw_get_parent(hw);
29362940
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent_hw);
29372941

29382942
actual_parent = clk_hw_get_clk_kunit(test, parent_hw, __func__);
@@ -3016,18 +3020,19 @@ KUNIT_ARRAY_PARAM(clk_register_clk_parent_data_device_hw_test,
30163020
*/
30173021
static void clk_register_clk_parent_data_device_hw_test(struct kunit *test)
30183022
{
3019-
struct clk_register_clk_parent_data_device_ctx *ctx;
3023+
struct device *dev;
3024+
struct clk_hw *hw;
30203025
const struct clk_register_clk_parent_data_test_case *test_param;
30213026
struct clk_dummy_context *parent;
30223027
struct clk_hw *parent_hw;
30233028
struct clk_parent_data pdata = { };
30243029
struct clk_init_data init = { };
3030+
static const struct of_device_id match_table[] = {
3031+
{ .compatible = "test,clk-parent-data" },
3032+
{ }
3033+
};
30253034

3026-
ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
3027-
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
3028-
test->priv = ctx;
3029-
3030-
clk_register_clk_parent_data_device_driver(test);
3035+
dev = kunit_of_platform_driver_dev(test, match_table);
30313036

30323037
parent = kunit_kzalloc(test, sizeof(*parent), GFP_KERNEL);
30333038
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent);
@@ -3036,7 +3041,10 @@ static void clk_register_clk_parent_data_device_hw_test(struct kunit *test)
30363041
parent_hw->init = CLK_HW_INIT_NO_PARENT("parent-clk",
30373042
&clk_dummy_rate_ops, 0);
30383043

3039-
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, parent_hw));
3044+
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, parent_hw));
3045+
3046+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3047+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
30403048

30413049
test_param = test->param_value;
30423050
memcpy(&pdata, &test_param->pdata, sizeof(pdata));
@@ -3045,10 +3053,10 @@ static void clk_register_clk_parent_data_device_hw_test(struct kunit *test)
30453053
init.num_parents = 1;
30463054
init.ops = &clk_dummy_single_parent_ops;
30473055
init.name = "parent_data_device_hw_test_clk";
3048-
ctx->hw.init = &init;
3049-
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, &ctx->hw));
3056+
hw->init = &init;
3057+
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, hw));
30503058

3051-
KUNIT_EXPECT_PTR_EQ(test, parent_hw, clk_hw_get_parent(&ctx->hw));
3059+
KUNIT_EXPECT_PTR_EQ(test, parent_hw, clk_hw_get_parent(hw));
30523060
}
30533061

30543062
static struct kunit_case clk_register_clk_parent_data_device_test_cases[] = {
@@ -3395,8 +3403,148 @@ static struct kunit_suite clk_assigned_rates_suite = {
33953403
.init = clk_assigned_rates_test_init,
33963404
};
33973405

3406+
static const struct clk_init_data clk_hw_get_dev_of_node_init_data = {
3407+
.name = "clk_hw_get_dev_of_node",
3408+
.ops = &empty_clk_ops,
3409+
};
3410+
3411+
/*
3412+
* Test that a clk registered with a struct device returns the device from
3413+
* clk_hw_get_dev() and the node from clk_hw_get_of_node()
3414+
*/
3415+
static void clk_hw_register_dev_get_dev_returns_dev(struct kunit *test)
3416+
{
3417+
struct device *dev;
3418+
struct clk_hw *hw;
3419+
static const struct of_device_id match_table[] = {
3420+
{ .compatible = "test,clk-hw-get-dev-of-node" },
3421+
{ }
3422+
};
3423+
3424+
KUNIT_ASSERT_EQ(test, 0, of_overlay_apply_kunit(test, kunit_clk_hw_get_dev_of_node));
3425+
3426+
dev = kunit_of_platform_driver_dev(test, match_table);
3427+
3428+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3429+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3430+
3431+
hw->init = &clk_hw_get_dev_of_node_init_data;
3432+
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, hw));
3433+
3434+
KUNIT_EXPECT_PTR_EQ(test, dev, clk_hw_get_dev(hw));
3435+
KUNIT_EXPECT_PTR_EQ(test, dev_of_node(dev), clk_hw_get_of_node(hw));
3436+
}
3437+
3438+
/*
3439+
* Test that a clk registered with a struct device that's not associated with
3440+
* an OF node returns the device from clk_hw_get_dev() and NULL from
3441+
* clk_hw_get_of_node()
3442+
*/
3443+
static void clk_hw_register_dev_no_node_get_dev_returns_dev(struct kunit *test)
3444+
{
3445+
struct platform_device *pdev;
3446+
struct device *dev;
3447+
struct clk_hw *hw;
3448+
3449+
pdev = kunit_platform_device_alloc(test, "clk_hw_register_dev_no_node", -1);
3450+
KUNIT_ASSERT_NOT_NULL(test, pdev);
3451+
KUNIT_ASSERT_EQ(test, 0, kunit_platform_device_add(test, pdev));
3452+
dev = &pdev->dev;
3453+
3454+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3455+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3456+
3457+
hw->init = &clk_hw_get_dev_of_node_init_data;
3458+
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, hw));
3459+
3460+
KUNIT_EXPECT_PTR_EQ(test, dev, clk_hw_get_dev(hw));
3461+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_of_node(hw));
3462+
}
3463+
3464+
/*
3465+
* Test that a clk registered without a struct device returns NULL from
3466+
* clk_hw_get_dev()
3467+
*/
3468+
static void clk_hw_register_NULL_get_dev_of_node_returns_NULL(struct kunit *test)
3469+
{
3470+
struct clk_hw *hw;
3471+
3472+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3473+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3474+
3475+
hw->init = &clk_hw_get_dev_of_node_init_data;
3476+
3477+
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, NULL, hw));
3478+
3479+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_dev(hw));
3480+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_of_node(hw));
3481+
}
3482+
3483+
/*
3484+
* Test that a clk registered with an of_node returns the node from
3485+
* clk_hw_get_of_node() and NULL from clk_hw_get_dev()
3486+
*/
3487+
static void of_clk_hw_register_node_get_of_node_returns_node(struct kunit *test)
3488+
{
3489+
struct device_node *np;
3490+
struct clk_hw *hw;
3491+
3492+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3493+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3494+
3495+
KUNIT_ASSERT_EQ(test, 0, of_overlay_apply_kunit(test, kunit_clk_hw_get_dev_of_node));
3496+
3497+
np = of_find_compatible_node(NULL, NULL, "test,clk-hw-get-dev-of-node");
3498+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, np);
3499+
of_node_put_kunit(test, np);
3500+
3501+
hw->init = &clk_hw_get_dev_of_node_init_data;
3502+
KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, np, hw));
3503+
3504+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_dev(hw));
3505+
KUNIT_EXPECT_PTR_EQ(test, np, clk_hw_get_of_node(hw));
3506+
}
3507+
3508+
/*
3509+
* Test that a clk registered without an of_node returns the node from
3510+
* clk_hw_get_of_node() and clk_hw_get_dev()
3511+
*/
3512+
static void of_clk_hw_register_NULL_get_of_node_returns_NULL(struct kunit *test)
3513+
{
3514+
struct clk_hw *hw;
3515+
3516+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3517+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3518+
3519+
hw->init = &clk_hw_get_dev_of_node_init_data;
3520+
KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, NULL, hw));
3521+
3522+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_dev(hw));
3523+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_of_node(hw));
3524+
}
3525+
3526+
static struct kunit_case clk_hw_get_dev_of_node_test_cases[] = {
3527+
KUNIT_CASE(clk_hw_register_dev_get_dev_returns_dev),
3528+
KUNIT_CASE(clk_hw_register_dev_no_node_get_dev_returns_dev),
3529+
KUNIT_CASE(clk_hw_register_NULL_get_dev_of_node_returns_NULL),
3530+
KUNIT_CASE(of_clk_hw_register_node_get_of_node_returns_node),
3531+
KUNIT_CASE(of_clk_hw_register_NULL_get_of_node_returns_NULL),
3532+
{}
3533+
};
3534+
3535+
/*
3536+
* Test suite to verify clk_hw_get_dev() and clk_hw_get_of_node() when clk
3537+
* registered with clk_hw_register() and of_clk_hw_register()
3538+
*/
3539+
static struct kunit_suite clk_hw_get_dev_of_node_test_suite = {
3540+
.name = "clk_hw_get_dev_of_node_test_suite",
3541+
.test_cases = clk_hw_get_dev_of_node_test_cases,
3542+
};
3543+
3544+
33983545
kunit_test_suites(
33993546
&clk_assigned_rates_suite,
3547+
&clk_hw_get_dev_of_node_test_suite,
34003548
&clk_leaf_mux_set_rate_parent_test_suite,
34013549
&clk_test_suite,
34023550
&clk_multiple_parents_mux_test_suite,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/dts-v1/;
3+
/plugin/;
4+
5+
&{/} {
6+
kunit-clock-controller {
7+
compatible = "test,clk-hw-get-dev-of-node";
8+
#clock-cells = <0>;
9+
};
10+
};

drivers/clk/meson/Kconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ menu "Clock support for Amlogic platforms"
55
config COMMON_CLK_MESON_REGMAP
66
tristate
77
select REGMAP
8+
select MFD_SYSCON
89

910
config COMMON_CLK_MESON_DUALDIV
1011
tristate
@@ -106,7 +107,8 @@ config COMMON_CLK_AXG_AUDIO
106107
select COMMON_CLK_MESON_SCLK_DIV
107108
select COMMON_CLK_MESON_CLKC_UTILS
108109
select REGMAP_MMIO
109-
select RESET_CONTROLLER
110+
select AUXILIARY_BUS
111+
imply RESET_MESON_AUX
110112
help
111113
Support for the audio clock controller on AmLogic A113D devices,
112114
aka axg, Say Y if you want audio subsystem to work.

0 commit comments

Comments
 (0)