1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Based on the linux multiplexer framework
5 * Copyright (C) 2017 Axentia Technologies AB
6 * Author: Peter Rosin <peda@axentia.se>
8 * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
9 * Jean-Jacques Hiblot <jjhiblot@ti.com>
12 #ifndef _MUX_INTERNAL_H
13 #define _MUX_INTERNAL_H
15 /* See mux.h for background documentation. */
17 struct ofnode_phandle_args;
20 * struct mux_chip - Represents a chip holding mux controllers.
21 * @controllers: Number of mux controllers handled by the chip.
22 * @mux: Array of mux controllers that are handled.
24 * This a per-device uclass-private data.
27 unsigned int controllers;
28 struct mux_control *mux;
32 * struct mux_control_ops - Mux controller operations for a mux chip.
33 * @set: Set the state of the given mux controller.
35 struct mux_control_ops {
37 * set - Apply a state to a multiplexer control
39 * @mux: A multiplexer control
40 * @return 0 if OK, or a negative error code.
42 int (*set)(struct mux_control *mux, int state);
45 * of_xlate - Translate a client's device-tree (OF) multiplexer
48 * If this function pointer is set to NULL, the multiplexer core will
49 * use a default implementation, which assumes #mux-control-cells = <1>
50 * and that the DT cell contains a simple integer channel ID.
52 * @dev_mux: The multiplexer device. A single device may handle
53 * several multiplexer controls.
54 * @args: The multiplexer specifier values from device tree.
55 * @muxp: (out) A multiplexer control
56 * @return 0 if OK, or a negative error code.
58 int (*of_xlate)(struct mux_chip *dev_mux,
59 struct ofnode_phandle_args *args,
60 struct mux_control **muxp);
64 * struct mux_control - Represents a mux controller.
65 * @in_use: Whether the mux controller is in use or not.
66 * @dev: The client device.
67 * @cached_state: The current mux controller state, or -1 if none.
68 * @states: The number of mux controller states.
69 * @idle_state: The mux controller state to use when inactive, or one
70 * of MUX_IDLE_AS_IS and MUX_IDLE_DISCONNECT.
71 * @id: The index of the mux controller within the mux chip
74 * Mux drivers may only change @states and @idle_state, and may only do so
75 * between allocation and registration of the mux controller. Specifically,
76 * @cached_state is internal to the mux core and should never be written by
89 * mux_control_get_index() - Get the index of the given mux controller
90 * @mux: The mux-control to get the index for.
92 * Return: The index of the mux controller within the mux chip the mux
93 * controller is a part of.
95 static inline unsigned int mux_control_get_index(struct mux_control *mux)
101 * mux_alloc_controllers() - Allocate the given number of mux controllers.
102 * @dev: The client device.
103 * controllers: Number of controllers to allocate.
105 * Return: 0 of OK, -errno otherwise.
107 int mux_alloc_controllers(struct udevice *dev, unsigned int controllers);