1 /*
2  * Copyright (c) 2023, Meta
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Public APIs for the Device Multiplexer driver
10  */
11 
12 #ifndef INCLUDE_ZEPHYR_DRIVERS_MISC_DEVMUX_H_
13 #define INCLUDE_ZEPHYR_DRIVERS_MISC_DEVMUX_H_
14 
15 #include <stdint.h>
16 
17 #include <zephyr/device.h>
18 #include <zephyr/kernel.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /**
25  * @brief Devmux Driver APIs
26  * @defgroup demux_interface Devmux Driver APIs
27  * @ingroup misc_interfaces
28  *
29  * @details
30  * Devmux operates as a device multiplexer, forwarding the characteristics of
31  * the selected device.
32  *
33  * ```
34  *            +----------+                            +----------+
35  *            |  devmux  |                            |  devmux  |
36  *            |          |                            |          |
37  * dev0       |          |                 dev0       |          |
38  * +---------->   \      |                 +---------->          |
39  *            |    \     |                            |          |
40  * dev1       |     \    |       dev0      dev1       |          |       dev2
41  * +---------->      O   +---------->      +---------->      O   +---------->
42  *            |          |                            |     /    |
43  * dev2       |          |                 dev2       |    /     |
44  * +---------->          |                 +---------->   /      |
45  *            |          |                            |          |
46  *            |          |                            |          |
47  *            |          |                            |          |
48  *            +-----^----+                            +-----^----+
49  *                  |                                       |
50  *   select == 0    |                       select == 2     |
51  *   +--------------+                       +---------------+
52  * ```
53  * @{
54  */
55 
56 /**
57  * @brief Get the current selection of a devmux device.
58  *
59  * Return the index of the currently selected device.
60  *
61  * @param dev the devmux device
62  * @return The index (>= 0) of the currently active multiplexed device on success
63  * @retval -EINVAL If @p dev is invalid
64  */
65 __syscall int devmux_select_get(const struct device *dev);
66 
67 /**
68  * @brief Set the selection of a devmux device.
69  *
70  * Select the device at @p index.
71  *
72  * @param[in] dev the devmux device
73  * @param index the index representing the desired selection
74  * @retval 0 On success
75  * @retval -EINVAL If @p dev is invalid
76  * @retval -ENODEV If the multiplexed device at @p index is not ready
77  */
78 __syscall int devmux_select_set(struct device *dev, size_t index);
79 
80 /**
81  * @}
82  */
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #include <zephyr/syscalls/devmux.h>
89 
90 #endif /* INCLUDE_ZEPHYR_DRIVERS_MISC_DEVMUX_H_ */
91