Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
device_runtime.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Intel Corporation.
3 * Copyright (c) 2021 Nordic Semiconductor ASA
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13
14#ifndef ZEPHYR_INCLUDE_PM_DEVICE_RUNTIME_H_
15#define ZEPHYR_INCLUDE_PM_DEVICE_RUNTIME_H_
16
17#include <zephyr/device.h>
18#include <zephyr/kernel.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
32
33#if defined(CONFIG_PM_DEVICE_RUNTIME) || defined(__DOXYGEN__)
46
63int pm_device_runtime_enable(const struct device *dev);
64
77int pm_device_runtime_disable(const struct device *dev);
78
101int pm_device_runtime_get(const struct device *dev);
102
122int pm_device_runtime_put(const struct device *dev);
123
148int pm_device_runtime_put_async(const struct device *dev, k_timeout_t delay);
149
162bool pm_device_runtime_is_enabled(const struct device *dev);
163
174int pm_device_runtime_usage(const struct device *dev);
175
176#else
177
178static inline int pm_device_runtime_auto_enable(const struct device *dev)
179{
180 ARG_UNUSED(dev);
181 return 0;
182}
183
184static inline int pm_device_runtime_enable(const struct device *dev)
185{
186 ARG_UNUSED(dev);
187 return 0;
188}
189
190static inline int pm_device_runtime_disable(const struct device *dev)
191{
192 ARG_UNUSED(dev);
193 return 0;
194}
195
196static inline int pm_device_runtime_get(const struct device *dev)
197{
198 ARG_UNUSED(dev);
199 return 0;
200}
201
202static inline int pm_device_runtime_put(const struct device *dev)
203{
204 ARG_UNUSED(dev);
205 return 0;
206}
207
208static inline int pm_device_runtime_put_async(const struct device *dev,
209 k_timeout_t delay)
210{
211 ARG_UNUSED(dev);
212 ARG_UNUSED(delay);
213 return 0;
214}
215
216static inline bool pm_device_runtime_is_enabled(const struct device *dev)
217{
218 ARG_UNUSED(dev);
219 return false;
220}
221
222static inline int pm_device_runtime_usage(const struct device *dev)
223{
224 ARG_UNUSED(dev);
225 return -ENOSYS;
226}
227
228#endif
229
240#define LOG_DBG_PM_DEVICE_RUNTIME_GET(dev, ...) \
241 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
242 (LOG_DBG("Failed to resume %s", (dev) ? (dev)->name : "(null)")), \
243 (LOG_DBG("Failed to resume %s (%d)", (dev) ? (dev)->name : "(null)", \
244 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
245
256#define LOG_WRN_PM_DEVICE_RUNTIME_GET(dev, ...) \
257 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
258 (LOG_WRN("Failed to resume %s", (dev) ? (dev)->name : "(null)")), \
259 (LOG_WRN("Failed to resume %s (%d)", (dev) ? (dev)->name : "(null)", \
260 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
261
272#define LOG_ERR_PM_DEVICE_RUNTIME_GET(dev, ...) \
273 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
274 (LOG_ERR("Failed to resume %s", (dev) ? (dev)->name : "(null)")), \
275 (LOG_ERR("Failed to resume %s (%d)", (dev) ? (dev)->name : "(null)", \
276 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
277
288#define LOG_DBG_PM_DEVICE_RUNTIME_PUT(dev, ...) \
289 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
290 (LOG_DBG("Failed to suspend %s", (dev) ? (dev)->name : "(null)")), \
291 (LOG_DBG("Failed to suspend %s (%d)", (dev) ? (dev)->name : "(null)", \
292 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
293
304#define LOG_WRN_PM_DEVICE_RUNTIME_PUT(dev, ...) \
305 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
306 (LOG_WRN("Failed to suspend %s", (dev) ? (dev)->name : "(null)")), \
307 (LOG_WRN("Failed to suspend %s (%d)", (dev) ? (dev)->name : "(null)", \
308 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
309
320#define LOG_ERR_PM_DEVICE_RUNTIME_PUT(dev, ...) \
321 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
322 (LOG_ERR("Failed to suspend %s", (dev) ? (dev)->name : "(null)")), \
323 (LOG_ERR("Failed to suspend %s (%d)", (dev) ? (dev)->name : "(null)", \
324 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
325
337#define LOG_INST_DBG_PM_DEVICE_RUNTIME_GET(_log_inst, dev, ...) \
338 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
339 (LOG_INST_DBG(_log_inst, "Failed to resume %s", \
340 (dev) ? (dev)->name : "(null)")), \
341 (LOG_INST_DBG(_log_inst, "Failed to resume %s (%d)", \
342 (dev) ? (dev)->name : "(null)", \
343 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
344
356#define LOG_INST_WRN_PM_DEVICE_RUNTIME_GET(_log_inst, dev, ...) \
357 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
358 (LOG_INST_WRN(_log_inst, "Failed to resume %s", \
359 (dev) ? (dev)->name : "(null)")), \
360 (LOG_INST_WRN(_log_inst, "Failed to resume %s (%d)", \
361 (dev) ? (dev)->name : "(null)", \
362 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
363
375#define LOG_INST_ERR_PM_DEVICE_RUNTIME_GET(_log_inst, dev, ...) \
376 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
377 (LOG_INST_ERR(_log_inst, "Failed to resume %s", \
378 (dev) ? (dev)->name : "(null)")), \
379 (LOG_INST_ERR(_log_inst, "Failed to resume %s (%d)", \
380 (dev) ? (dev)->name : "(null)", \
381 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
382
394#define LOG_INST_DBG_PM_DEVICE_RUNTIME_PUT(_log_inst, dev, ...) \
395 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
396 (LOG_INST_DBG(_log_inst, "Failed to suspend %s", \
397 (dev) ? (dev)->name : "(null)")), \
398 (LOG_INST_DBG(_log_inst, "Failed to suspend %s (%d)", \
399 (dev) ? (dev)->name : "(null)", \
400 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
401
413#define LOG_INST_WRN_PM_DEVICE_RUNTIME_PUT(_log_inst, dev, ...) \
414 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
415 (LOG_INST_WRN(_log_inst, "Failed to suspend %s", \
416 (dev) ? (dev)->name : "(null)")), \
417 (LOG_INST_WRN(_log_inst, "Failed to suspend %s (%d)", \
418 (dev) ? (dev)->name : "(null)", \
419 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
420
432#define LOG_INST_ERR_PM_DEVICE_RUNTIME_PUT(_log_inst, dev, ...) \
433 COND_CODE_1(IS_EQ(NUM_VA_ARGS(__VA_ARGS__), 0), \
434 (LOG_INST_ERR(_log_inst, "Failed to suspend %s", \
435 (dev) ? (dev)->name : "(null)")), \
436 (LOG_INST_ERR(_log_inst, "Failed to suspend %s (%d)", \
437 (dev) ? (dev)->name : "(null)", \
438 GET_ARGS_FIRST_N(1, __VA_ARGS__))))
439
441
442#ifdef __cplusplus
443}
444#endif
445
446#endif /* ZEPHYR_INCLUDE_PM_DEVICE_RUNTIME_H_ */
int pm_device_runtime_get(const struct device *dev)
Resume a device based on usage count.
bool pm_device_runtime_is_enabled(const struct device *dev)
Check if device runtime is enabled for a given device.
int pm_device_runtime_put(const struct device *dev)
Suspend a device based on usage count.
int pm_device_runtime_put_async(const struct device *dev, k_timeout_t delay)
Suspend a device based on usage count (asynchronously).
int pm_device_runtime_disable(const struct device *dev)
Disable device runtime PM.
int pm_device_runtime_enable(const struct device *dev)
Enable device runtime PM.
int pm_device_runtime_usage(const struct device *dev)
Return the current device usage counter.
int pm_device_runtime_auto_enable(const struct device *dev)
Automatically enable device runtime based on devicetree properties.
#define ENOSYS
Function not implemented.
Definition errno.h:83
Public kernel APIs.
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Kernel timeout type.
Definition clock.h:65