1 /*
2 * Copyright (c) 2018 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/pm/device.h>
8 #include <zephyr/pm/device_runtime.h>
9 #include <zephyr/sys/printk.h>
10 #include "dummy_parent.h"
11
12 static uint32_t store_value;
13
dummy_transfer(const struct device * dev,uint32_t cmd,uint32_t * val)14 static int dummy_transfer(const struct device *dev, uint32_t cmd,
15 uint32_t *val)
16 {
17 if (cmd == DUMMY_PARENT_WR) {
18 store_value = *val;
19 } else {
20 *val = store_value;
21 }
22
23 return 0;
24 }
25
dummy_parent_pm_action(const struct device * dev,enum pm_device_action action)26 static int dummy_parent_pm_action(const struct device *dev,
27 enum pm_device_action action)
28 {
29 switch (action) {
30 case PM_DEVICE_ACTION_RESUME:
31 printk("parent resuming..\n");
32 break;
33 case PM_DEVICE_ACTION_SUSPEND:
34 printk("parent suspending..\n");
35 break;
36 default:
37 return -ENOTSUP;
38 }
39
40 return 0;
41 }
42
43 static const struct dummy_parent_api funcs = {
44 .transfer = dummy_transfer,
45 };
46
dummy_parent_init(const struct device * dev)47 int dummy_parent_init(const struct device *dev)
48 {
49 return pm_device_runtime_enable(dev);
50 }
51
52 PM_DEVICE_DEFINE(dummy_parent, dummy_parent_pm_action);
53
54 DEVICE_DEFINE(dummy_parent, DUMMY_PARENT_NAME, &dummy_parent_init,
55 PM_DEVICE_GET(dummy_parent), NULL, NULL, POST_KERNEL,
56 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &funcs);
57