1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Based on the linux multiplexer framework
5 * At its core, a multiplexer (or mux), also known as a data selector, is a
6 * device that selects between several analog or digital input signals and
7 * forwards it to a single output line. This notion can be extended to work
8 * with buses, like a I2C bus multiplexer for example.
10 * Copyright (C) 2017 Axentia Technologies AB
11 * Author: Peter Rosin <peda@axentia.se>
13 * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
14 * Jean-Jacques Hiblot <jjhiblot@ti.com>
20 #include <linux/errno.h>
21 #include <linux/types.h>
26 #if CONFIG_IS_ENABLED(MULTIPLEXER)
28 * mux_control_states() - Query the number of multiplexer states.
29 * @mux: The mux-control to query.
31 * Return: The number of multiplexer states.
33 unsigned int mux_control_states(struct mux_control *mux);
36 * mux_control_select() - Select the given multiplexer state.
37 * @mux: The mux-control to request a change of state from.
38 * @state: The new requested state.
40 * On successfully selecting the mux-control state, it will be locked until
41 * there is a call to mux_control_deselect(). If the mux-control is already
42 * selected when mux_control_select() is called, the function will indicate
45 * Therefore, make sure to call mux_control_deselect() when the operation is
46 * complete and the mux-control is free for others to use, but do not call
47 * mux_control_deselect() if mux_control_select() fails.
49 * Return: 0 when the mux-control state has the requested state or a negative
52 int __must_check mux_control_select(struct mux_control *mux,
54 #define mux_control_try_select(mux, state) mux_control_select(mux, state)
57 * mux_control_deselect() - Deselect the previously selected multiplexer state.
58 * @mux: The mux-control to deselect.
60 * It is required that a single call is made to mux_control_deselect() for
61 * each and every successful call made to either of mux_control_select() or
62 * mux_control_try_select().
64 * Return: 0 on success and a negative errno on error. An error can only
65 * occur if the mux has an idle state. Note that even if an error occurs, the
66 * mux-control is unlocked and is thus free for the next access.
68 int mux_control_deselect(struct mux_control *mux);
71 * mux_get_by_index() = Get a mux by integer index.
72 * @dev: The client device.
73 * @index: The index of the mux to get.
74 * @mux: A pointer to the 'mux_control' struct to initialize.
76 * This looks up and initializes a mux. The index is relative to the client
79 * Return: 0 if OK, or a negative error code.
81 int mux_get_by_index(struct udevice *dev, int index, struct mux_control **mux);
84 * mux_control_get() - Get the mux-control for a device.
85 * @dev: The device that needs a mux-control.
86 * @mux_name: The name identifying the mux-control.
87 * @mux: A pointer to the mux-control pointer.
89 * Return: 0 of OK, or a negative error code.
91 int mux_control_get(struct udevice *dev, const char *name,
92 struct mux_control **mux);
95 * mux_control_put() - Put away the mux-control for good.
96 * @mux: The mux-control to put away.
98 * mux_control_put() reverses the effects of mux_control_get().
100 void mux_control_put(struct mux_control *mux);
103 * devm_mux_control_get() - Get the mux-control for a device, with resource
105 * @dev: The device that needs a mux-control.
106 * @mux_name: The name identifying the mux-control.
108 * Return: Pointer to the mux-control, or an ERR_PTR with a negative errno.
110 struct mux_control *devm_mux_control_get(struct udevice *dev,
111 const char *mux_name);
113 * dm_mux_init() - Initialize the multiplexer controls to their default state.
115 * Return: 0 if OK, -errno otherwise.
117 int dm_mux_init(void);
120 unsigned int mux_control_states(struct mux_control *mux)
125 int __must_check mux_control_select(struct mux_control *mux,
131 #define mux_control_try_select(mux, state) mux_control_select(mux, state)
133 int mux_control_deselect(struct mux_control *mux)
138 struct mux_control *mux_control_get(struct udevice *dev, const char *mux_name)
143 void mux_control_put(struct mux_control *mux)
147 struct mux_control *devm_mux_control_get(struct udevice *dev,
148 const char *mux_name)
153 int dm_mux_init(void)