2 * Copyright (c) 2016, NVIDIA CORPORATION.
4 * SPDX-License-Identifier: GPL-2.0
12 struct sandbox_clk_test {
13 struct clk clks[SANDBOX_CLK_TEST_ID_COUNT];
16 static const char * const sandbox_clk_test_names[] = {
17 [SANDBOX_CLK_TEST_ID_FIXED] = "fixed",
18 [SANDBOX_CLK_TEST_ID_SPI] = "spi",
19 [SANDBOX_CLK_TEST_ID_I2C] = "i2c",
22 int sandbox_clk_test_get(struct udevice *dev)
24 struct sandbox_clk_test *sbct = dev_get_priv(dev);
27 for (i = 0; i < SANDBOX_CLK_TEST_ID_COUNT; i++) {
28 ret = clk_get_by_name(dev, sandbox_clk_test_names[i],
37 ulong sandbox_clk_test_get_rate(struct udevice *dev, int id)
39 struct sandbox_clk_test *sbct = dev_get_priv(dev);
41 if (id < 0 || id >= SANDBOX_CLK_TEST_ID_COUNT)
44 return clk_get_rate(&sbct->clks[id]);
47 ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate)
49 struct sandbox_clk_test *sbct = dev_get_priv(dev);
51 if (id < 0 || id >= SANDBOX_CLK_TEST_ID_COUNT)
54 return clk_set_rate(&sbct->clks[id], rate);
57 int sandbox_clk_test_enable(struct udevice *dev, int id)
59 struct sandbox_clk_test *sbct = dev_get_priv(dev);
61 if (id < 0 || id >= SANDBOX_CLK_TEST_ID_COUNT)
64 return clk_enable(&sbct->clks[id]);
67 int sandbox_clk_test_disable(struct udevice *dev, int id)
69 struct sandbox_clk_test *sbct = dev_get_priv(dev);
71 if (id < 0 || id >= SANDBOX_CLK_TEST_ID_COUNT)
74 return clk_disable(&sbct->clks[id]);
77 int sandbox_clk_test_free(struct udevice *dev)
79 struct sandbox_clk_test *sbct = dev_get_priv(dev);
82 for (i = 0; i < SANDBOX_CLK_TEST_ID_COUNT; i++) {
83 ret = clk_free(&sbct->clks[i]);
91 static const struct udevice_id sandbox_clk_test_ids[] = {
92 { .compatible = "sandbox,clk-test" },
96 U_BOOT_DRIVER(sandbox_clk_test) = {
97 .name = "sandbox_clk_test",
99 .of_match = sandbox_clk_test_ids,
100 .priv_auto_alloc_size = sizeof(struct sandbox_clk_test),