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

clk: tests: Make clk_register_clk_parent_data_device_driver() common

Rename clk_register_clk_parent_data_device_driver() to
kunit_of_platform_driver_dev() and have it return a struct device
pointer while accepting a match table. This will be useful to
find the device associated with an OF node for more tests than
only the clk_parent_data tests.

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
[sboyd@kernel.org: Split out from next patch, carry SoB and
authorship, rename API, return device pointer]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Jerome Brunet and committed by
Stephen Boyd
b06ba1c3 5f4081d6

+46 -38
+46 -38
drivers/clk/clk_test.c
··· 2794 2794 }; 2795 2795 2796 2796 /** 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 2800 2799 * @pdrv: driver to attach to find @dev 2801 2800 */ 2802 - struct clk_register_clk_parent_data_device_ctx { 2801 + struct platform_driver_dev_ctx { 2803 2802 struct device *dev; 2804 - struct clk_hw hw; 2805 2803 struct platform_driver pdrv; 2806 2804 }; 2807 2805 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) 2810 2808 { 2811 2809 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); 2813 2811 } 2814 2812 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) 2816 2814 { 2817 - struct clk_register_clk_parent_data_device_ctx *ctx; 2815 + struct platform_driver_dev_ctx *ctx; 2818 2816 2819 - ctx = clk_register_clk_parent_data_driver_to_test_context(pdev); 2817 + ctx = pdev_to_platform_driver_dev_ctx(pdev); 2820 2818 ctx->dev = &pdev->dev; 2821 2819 2822 2820 return 0; 2823 2821 } 2824 2822 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) 2826 2825 { 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; 2832 2827 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; 2834 2832 ctx->pdrv.driver.of_match_table = match_table; 2835 2833 ctx->pdrv.driver.name = __func__; 2836 2834 ctx->pdrv.driver.owner = THIS_MODULE; 2837 2835 2838 2836 KUNIT_ASSERT_EQ(test, 0, kunit_platform_driver_register(test, &ctx->pdrv)); 2839 2837 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->dev); 2838 + 2839 + return ctx->dev; 2840 2840 } 2841 2841 2842 2842 static const struct clk_register_clk_parent_data_test_case ··· 2909 2909 */ 2910 2910 static void clk_register_clk_parent_data_device_test(struct kunit *test) 2911 2911 { 2912 - struct clk_register_clk_parent_data_device_ctx *ctx; 2912 + struct device *dev; 2913 + struct clk_hw *hw; 2913 2914 const struct clk_register_clk_parent_data_test_case *test_param; 2914 2915 struct clk_hw *parent_hw; 2915 2916 struct clk_init_data init = { }; 2916 2917 struct clk *expected_parent, *actual_parent; 2918 + static const struct of_device_id match_table[] = { 2919 + { .compatible = "test,clk-parent-data" }, 2920 + { } 2921 + }; 2917 2922 2918 - ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); 2919 - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); 2920 - test->priv = ctx; 2923 + dev = kunit_of_platform_driver_dev(test, match_table); 2921 2924 2922 - clk_register_clk_parent_data_device_driver(test); 2923 - 2924 - expected_parent = clk_get_kunit(test, ctx->dev, "50"); 2925 + expected_parent = clk_get_kunit(test, dev, "50"); 2925 2926 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected_parent); 2927 + 2928 + hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL); 2929 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw); 2926 2930 2927 2931 test_param = test->param_value; 2928 2932 init.parent_data = &test_param->pdata; 2929 2933 init.num_parents = 1; 2930 2934 init.name = "parent_data_device_test_clk"; 2931 2935 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)); 2934 2938 2935 - parent_hw = clk_hw_get_parent(&ctx->hw); 2939 + parent_hw = clk_hw_get_parent(hw); 2936 2940 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent_hw); 2937 2941 2938 2942 actual_parent = clk_hw_get_clk_kunit(test, parent_hw, __func__); ··· 3020 3016 */ 3021 3017 static void clk_register_clk_parent_data_device_hw_test(struct kunit *test) 3022 3018 { 3023 - struct clk_register_clk_parent_data_device_ctx *ctx; 3019 + struct device *dev; 3020 + struct clk_hw *hw; 3024 3021 const struct clk_register_clk_parent_data_test_case *test_param; 3025 3022 struct clk_dummy_context *parent; 3026 3023 struct clk_hw *parent_hw; 3027 3024 struct clk_parent_data pdata = { }; 3028 3025 struct clk_init_data init = { }; 3026 + static const struct of_device_id match_table[] = { 3027 + { .compatible = "test,clk-parent-data" }, 3028 + { } 3029 + }; 3029 3030 3030 - ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); 3031 - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); 3032 - test->priv = ctx; 3033 - 3034 - clk_register_clk_parent_data_device_driver(test); 3031 + dev = kunit_of_platform_driver_dev(test, match_table); 3035 3032 3036 3033 parent = kunit_kzalloc(test, sizeof(*parent), GFP_KERNEL); 3037 3034 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); ··· 3041 3036 parent_hw->init = CLK_HW_INIT_NO_PARENT("parent-clk", 3042 3037 &clk_dummy_rate_ops, 0); 3043 3038 3044 - KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, parent_hw)); 3039 + KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, parent_hw)); 3040 + 3041 + hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL); 3042 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw); 3045 3043 3046 3044 test_param = test->param_value; 3047 3045 memcpy(&pdata, &test_param->pdata, sizeof(pdata)); ··· 3053 3045 init.num_parents = 1; 3054 3046 init.ops = &clk_dummy_single_parent_ops; 3055 3047 init.name = "parent_data_device_hw_test_clk"; 3056 - ctx->hw.init = &init; 3057 - KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, &ctx->hw)); 3048 + hw->init = &init; 3049 + KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, hw)); 3058 3050 3059 - KUNIT_EXPECT_PTR_EQ(test, parent_hw, clk_hw_get_parent(&ctx->hw)); 3051 + KUNIT_EXPECT_PTR_EQ(test, parent_hw, clk_hw_get_parent(hw)); 3060 3052 } 3061 3053 3062 3054 static struct kunit_case clk_register_clk_parent_data_device_test_cases[] = {