1 /*
2 * Copyright 2024 Google LLC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <stdio.h>
8 #include <zephyr/device.h>
9 #include <zephyr/pm/device.h>
10 #include <zephyr/pm/device_runtime.h>
11 #include <zephyr/shell/shell.h>
12 #include <zephyr/shell/shell_dummy.h>
13
14 #ifdef CONFIG_PM_DEVICE
dummy_device_pm_action(const struct device * dev,enum pm_device_action action)15 static int dummy_device_pm_action(const struct device *dev,
16 enum pm_device_action action)
17 {
18 return 0;
19 }
20
21 PM_DEVICE_DEFINE(dummy_pm_driver_1, dummy_device_pm_action);
22 PM_DEVICE_DEFINE(dummy_pm_driver_2, dummy_device_pm_action);
23 PM_DEVICE_DEFINE(dummy_pm_driver_3, dummy_device_pm_action);
24 PM_DEVICE_DEFINE(dummy_pm_driver_4, dummy_device_pm_action);
25 #endif
26
27 DEVICE_DEFINE(device_0, "device@0", NULL, NULL,
28 NULL, NULL,
29 POST_KERNEL, 0, NULL);
30
31 DEVICE_DEFINE(device_1, "device@1", NULL, PM_DEVICE_GET(dummy_pm_driver_1),
32 NULL, NULL,
33 POST_KERNEL, 1, NULL);
34
35 DEVICE_DEFINE(device_2, "device@2", NULL, PM_DEVICE_GET(dummy_pm_driver_2),
36 NULL, NULL,
37 POST_KERNEL, 2, NULL);
38
39 DEVICE_DEFINE(device_3, "device@3", NULL, PM_DEVICE_GET(dummy_pm_driver_3),
40 NULL, NULL,
41 POST_KERNEL, 3, NULL);
42
43 DEVICE_DEFINE(device_4, "device@4", NULL, PM_DEVICE_GET(dummy_pm_driver_4),
44 NULL, NULL,
45 POST_KERNEL, 4, NULL);
46
47 #ifdef CONFIG_PM_DEVICE
48 static const struct device *d2 = &DEVICE_NAME_GET(device_2);
49 #endif
50 static const struct device *d3 = &DEVICE_NAME_GET(device_3);
51 static const struct device *d4 = &DEVICE_NAME_GET(device_4);
52
main(void)53 int main(void)
54 {
55 const struct shell *sh = shell_backend_dummy_get_ptr();
56 const char *buf;
57 int err;
58 size_t size;
59
60 /* Let the shell backend initialize. */
61 k_usleep(10);
62
63 #ifdef CONFIG_PM_DEVICE
64 pm_device_action_run(d2, PM_DEVICE_ACTION_SUSPEND);
65 #endif
66
67 pm_device_runtime_enable(d3);
68 pm_device_runtime_enable(d4);
69 pm_device_runtime_get(d4);
70
71 shell_backend_dummy_clear_output(sh);
72
73 err = shell_execute_cmd(sh, "device list");
74 if (err) {
75 printf("Failed to execute the shell command: %d.\n",
76 err);
77 }
78
79 buf = shell_backend_dummy_get_output(sh, &size);
80 printf("%s\n", buf);
81
82 return 0;
83 }
84