firmware: scmi: sandbox test for SCMI clocks
[pandora-u-boot.git] / drivers / firmware / scmi / sandbox-scmi_devices.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2020, Linaro Limited
4  */
5
6 #include <common.h>
7 #include <clk.h>
8 #include <dm.h>
9 #include <malloc.h>
10 #include <asm/io.h>
11 #include <asm/scmi_test.h>
12 #include <dm/device_compat.h>
13
14 /*
15  * Simulate to some extent a SCMI exchange.
16  * This drivers gets SCMI resources and offers API function to the
17  * SCMI test sequence manipulate the resources, currently clocks.
18  */
19
20 #define SCMI_TEST_DEVICES_CLK_COUNT             3
21
22 /*
23  * struct sandbox_scmi_device_priv - Storage for device handles used by test
24  * @clk:                Array of clock instances used by tests
25  * @devices:            Resources exposed by sandbox_scmi_devices_ctx()
26  */
27 struct sandbox_scmi_device_priv {
28         struct clk clk[SCMI_TEST_DEVICES_CLK_COUNT];
29         struct sandbox_scmi_devices devices;
30 };
31
32 struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev)
33 {
34         struct sandbox_scmi_device_priv *priv = dev_get_priv(dev);
35
36         if (priv)
37                 return &priv->devices;
38
39         return NULL;
40 }
41
42 static int sandbox_scmi_devices_probe(struct udevice *dev)
43 {
44         struct sandbox_scmi_device_priv *priv = dev_get_priv(dev);
45         int ret;
46         size_t n;
47
48         priv->devices = (struct sandbox_scmi_devices){
49                 .clk = priv->clk,
50                 .clk_count = SCMI_TEST_DEVICES_CLK_COUNT,
51         };
52
53         for (n = 0; n < SCMI_TEST_DEVICES_CLK_COUNT; n++) {
54                 ret = clk_get_by_index(dev, n, priv->devices.clk + n);
55                 if (ret) {
56                         dev_err(dev, "%s: Failed on clk %zu\n", __func__, n);
57                         return ret;
58                 }
59         }
60
61         return 0;
62 }
63
64 static const struct udevice_id sandbox_scmi_devices_ids[] = {
65         { .compatible = "sandbox,scmi-devices" },
66         { }
67 };
68
69 U_BOOT_DRIVER(sandbox_scmi_devices) = {
70         .name = "sandbox-scmi_devices",
71         .id = UCLASS_MISC,
72         .of_match = sandbox_scmi_devices_ids,
73         .priv_auto_alloc_size = sizeof(struct sandbox_scmi_device_priv),
74         .probe = sandbox_scmi_devices_probe,
75 };