Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
mux.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11
12#ifndef ZEPHYR_INCLUDE_DRIVERS_MUX_H_
13#define ZEPHYR_INCLUDE_DRIVERS_MUX_H_
14
31
32#include <errno.h>
33#include <stddef.h>
34
35#include <zephyr/types.h>
36#include <zephyr/device.h>
37#include <zephyr/devicetree.h>
39#include <zephyr/sys/util.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
56 size_t len;
57};
58
66struct mux_state {
68 const struct mux_control *control;
71};
72
74
75#define Z_MUX_CTRL_DEFINE_BY_IDX(node_id, idx) \
76 static const uint32_t Z_MUX_CTRL_CELLS_NAME(node_id, idx)[] = { \
77 COND_CODE_1(IS_EQ(Z_MUX_PHA_NUM_CELLS(node_id, mux_controls, idx), 0), \
78 (0), \
79 (DT_FOREACH_PHA_CELL_BY_IDX_SEP(node_id, mux_controls, idx, \
80 Z_MUX_CELL_VAL, (,)))) \
81 }; \
82 static const struct mux_control Z_MUX_CTRL_OBJ_NAME(node_id, idx) = { \
83 .cells = Z_MUX_CTRL_CELLS_NAME(node_id, idx), \
84 .len = Z_MUX_PHA_NUM_CELLS(node_id, mux_controls, idx), \
85 }
86
87#define Z_MUX_STATE_DEFINE_BY_IDX(node_id, idx) \
88 static const uint32_t Z_MUX_STATE_CELLS_NAME(node_id, idx)[] = { \
89 COND_CODE_1(IS_EQ(Z_MUX_PHA_NUM_CELLS(node_id, mux_states, idx), 1), \
90 (0), \
91 (Z_MUX_STATE_ADDRESSING_CELLS(node_id, idx))) \
92 }; \
93 static const struct mux_control Z_MUX_STATE_CTRL_NAME(node_id, idx) = { \
94 .cells = Z_MUX_STATE_CELLS_NAME(node_id, idx), \
95 .len = Z_MUX_PHA_NUM_CELLS(node_id, mux_states, idx) - 1, \
96 }; \
97 static const struct mux_state Z_MUX_STATE_OBJ_NAME(node_id, idx) = { \
98 .control = &Z_MUX_STATE_CTRL_NAME(node_id, idx), \
99 .state = Z_MUX_STATE_LAST_CELL(node_id, idx), \
100 }
101
103
139#define MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX(node_id, idx) Z_MUX_CTRL_DEFINE_BY_IDX(node_id, idx)
140
158#define MUX_CONTROL_DT_SPEC_DEFINE(node_id) MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX(node_id, 0)
159
185#define MUX_CONTROL_DT_SPEC_DEFINE_BY_NAME(node_id, name) \
186 MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX(node_id, \
187 DT_PHA_ELEM_IDX_BY_NAME(node_id, mux_controls, name))
188
226#define MUX_STATE_DT_SPEC_DEFINE_BY_IDX(node_id, idx) Z_MUX_STATE_DEFINE_BY_IDX(node_id, idx)
227
245#define MUX_STATE_DT_SPEC_DEFINE(node_id) MUX_STATE_DT_SPEC_DEFINE_BY_IDX(node_id, 0)
246
271#define MUX_STATE_DT_SPEC_DEFINE_BY_NAME(node_id, name) \
272 MUX_STATE_DT_SPEC_DEFINE_BY_IDX(node_id, \
273 DT_PHA_ELEM_IDX_BY_NAME(node_id, mux_states, name))
274
276
277typedef int (*mux_control_set_fn)(const struct device *dev,
278 const struct mux_control *control,
280
281typedef int (*mux_state_get_fn)(const struct device *dev,
282 const struct mux_control *control,
283 uint32_t *state);
284
285typedef int (*mux_control_disconnect_fn)(const struct device *dev,
286 const struct mux_control *control);
287
289
293__subsystem struct mux_control_driver_api {
295 mux_control_set_fn set;
297 mux_state_get_fn get_state;
299 mux_control_disconnect_fn disconnect;
300};
301
314__syscall int mux_control_set(const struct device *dev,
315 const struct mux_control *control,
317
318static inline int z_impl_mux_control_set(const struct device *dev,
319 const struct mux_control *control,
321{
322 const struct mux_control_driver_api *api = DEVICE_API_GET(mux_control, dev);
323
324 return api->set(dev, control, state);
325}
326
339__syscall int mux_state_apply(const struct device *dev,
340 const struct mux_state *mstate);
341
342static inline int z_impl_mux_state_apply(const struct device *dev,
343 const struct mux_state *mstate)
344{
345 const struct mux_control_driver_api *api = DEVICE_API_GET(mux_control, dev);
346
347 return api->set(dev, mstate->control, mstate->state);
348}
349
365__syscall int mux_state_get(const struct device *dev,
366 const struct mux_control *control,
367 uint32_t *state);
368
369static inline int z_impl_mux_state_get(const struct device *dev,
370 const struct mux_control *control,
372{
373 const struct mux_control_driver_api *api = DEVICE_API_GET(mux_control, dev);
374
375 if (api->get_state == NULL) {
376 return -ENOSYS;
377 }
378
379 return api->get_state(dev, control, state);
380}
381
412__syscall int mux_control_disconnect(const struct device *dev,
413 const struct mux_control *control);
414
415static inline int z_impl_mux_control_disconnect(const struct device *dev,
416 const struct mux_control *control)
417{
418 const struct mux_control_driver_api *api = DEVICE_API_GET(mux_control, dev);
419
420 if (api->disconnect == NULL) {
421 return -ENOSYS;
422 }
423
424 return api->disconnect(dev, control);
425}
426
427#ifdef __cplusplus
428}
429#endif
430
432
433#include <zephyr/syscalls/mux.h>
434
435#endif /* ZEPHYR_INCLUDE_DRIVERS_MUX_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
MUX Devicetree macro public API header file.
Devicetree main header.
System error numbers.
int mux_control_disconnect(const struct device *dev, const struct mux_control *control)
Physically disconnect a MUX control line.
int mux_state_get(const struct device *dev, const struct mux_control *control, uint32_t *state)
Read back the current state of a MUX control line.
int mux_control_set(const struct device *dev, const struct mux_control *control, uint32_t state)
Drive a MUX control line to the given state.
int mux_state_apply(const struct device *dev, const struct mux_state *mstate)
Apply a devicetree-defined default state to a MUX control line.
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define NULL
Definition iar_missing_defs.h:20
state
Definition parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
MUX controller driver API.
Definition mux.h:293
mux_state_get_fn get_state
@driver_ops_optional Read back the current state of a MUX control line.
Definition mux.h:297
mux_control_set_fn set
@driver_ops_mandatory Drive a MUX control line to the given state.
Definition mux.h:295
mux_control_disconnect_fn disconnect
@driver_ops_optional Physically disconnect a MUX control line.
Definition mux.h:299
Addressing-only specifier for a single MUX control line.
Definition mux.h:52
const uint32_t * cells
Pointer to the addressing cells from the devicetree specifier.
Definition mux.h:54
size_t len
Number of addressing cells (matches #mux-control-cells).
Definition mux.h:56
Addressing + default state pair for a MUX control line.
Definition mux.h:66
const struct mux_control * control
Addressing portion (points to a statically-defined mux_control).
Definition mux.h:68
uint32_t state
Default state value taken from the trailing cell of the specifier.
Definition mux.h:70
Misc utilities.