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