1 /*
2 * Copyright (c) 2021 Google, LLC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /**
8 * @file
9 * @brief Stub driver to measure the footprint impact of power management
10 *
11 */
12 #include <zephyr/device.h>
13 #include <zephyr/pm/device.h>
14 #include <zephyr/pm/device_runtime.h>
15
16 #define DUMMY_PM_DRIVER_NAME "dummy_pm_driver"
17 #define DUMMY_DRIVER_NAME "dummy_driver"
18
dummy_device_pm_action(const struct device * dev,enum pm_device_action action)19 static int dummy_device_pm_action(const struct device *dev,
20 enum pm_device_action action)
21 {
22 return 0;
23 }
24
25 /* Define a driver with and without power management enabled */
26 PM_DEVICE_DEFINE(dummy_pm_driver, dummy_device_pm_action);
27
28 DEVICE_DEFINE(dummy_pm_driver, DUMMY_PM_DRIVER_NAME, NULL,
29 PM_DEVICE_GET(dummy_pm_driver), NULL, NULL, POST_KERNEL,
30 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
31
32 DEVICE_DEFINE(dummy_driver, DUMMY_DRIVER_NAME, NULL, NULL, NULL, NULL,
33 POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
34
run_pm_device(void)35 void run_pm_device(void)
36 {
37 const struct device *dev;
38 enum pm_device_state pm_state;
39
40 /* Get the PM state from a device with PM support */
41 dev = device_get_binding(DUMMY_PM_DRIVER_NAME);
42 if (pm_device_state_get(dev, &pm_state)) {
43 printk("\n PM device get state failed\n");
44 return;
45 }
46
47 if (pm_device_runtime_get(dev)) {
48 printk("\n PM device runtime get failed\n");
49 return;
50 }
51
52 if (pm_device_runtime_put(dev)) {
53 printk("\n PM device runtime put failed\n");
54 return;
55 }
56
57 /* Get the PM state from a device without PM support */
58 dev = device_get_binding(DUMMY_DRIVER_NAME);
59 if (pm_device_state_get(dev, &pm_state) != ENOSYS) {
60 printk("\n PM device get state did not fail\n");
61 return;
62 }
63 }
64