Lines Matching full:mux
10 #define pr_fmt(fmt) "mux-core: " fmt
18 #include <linux/mux/consumer.h>
19 #include <linux/mux/driver.h>
32 .name = "mux",
59 .name = "mux-chip",
64 * mux_chip_alloc() - Allocate a mux-chip.
65 * @dev: The parent device implementing the mux interface.
66 * @controllers: The number of mux controllers to allocate for this chip.
69 * After allocating the mux-chip with the desired number of mux controllers
70 * but before registering the chip, the mux driver is required to configure
71 * the number of valid mux states in the mux_chip->mux[N].states members and
72 * the desired idle state in the returned mux_chip->mux[N].idle_state members.
73 * The default idle state is MUX_IDLE_AS_IS. The mux driver also needs to
75 * before registering the mux-chip with mux_chip_register.
77 * Return: A pointer to the new mux-chip, or an ERR_PTR with a negative errno.
89 controllers * sizeof(*mux_chip->mux) + in mux_chip_alloc()
94 mux_chip->mux = (struct mux_control *)(mux_chip + 1); in mux_chip_alloc()
113 struct mux_control *mux = &mux_chip->mux[i]; in mux_chip_alloc() local
115 mux->chip = mux_chip; in mux_chip_alloc()
116 sema_init(&mux->lock, 1); in mux_chip_alloc()
117 mux->cached_state = MUX_CACHE_UNKNOWN; in mux_chip_alloc()
118 mux->idle_state = MUX_IDLE_AS_IS; in mux_chip_alloc()
127 static int mux_control_set(struct mux_control *mux, int state) in mux_control_set() argument
129 int ret = mux->chip->ops->set(mux, state); in mux_control_set()
131 mux->cached_state = ret < 0 ? MUX_CACHE_UNKNOWN : state; in mux_control_set()
137 * mux_chip_register() - Register a mux-chip, thus readying the controllers
139 * @mux_chip: The mux-chip to register.
141 * Do not retry registration of the same mux-chip on failure. You should
153 struct mux_control *mux = &mux_chip->mux[i]; in mux_chip_register() local
155 if (mux->idle_state == mux->cached_state) in mux_chip_register()
158 ret = mux_control_set(mux, mux->idle_state); in mux_chip_register()
174 * mux_chip_unregister() - Take the mux-chip off-line.
175 * @mux_chip: The mux-chip to unregister.
179 * on a mux-chip that has been registered before.
188 * mux_chip_free() - Free the mux-chip for good.
189 * @mux_chip: The mux-chip to free.
211 * @dev: The parent device implementing the mux interface.
212 * @controllers: The number of mux controllers to allocate for this chip.
217 * Return: A pointer to the new mux-chip, or an ERR_PTR with a negative errno.
251 * @dev: The parent device implementing the mux interface.
252 * @mux_chip: The mux-chip to register.
283 * @mux: The mux-control to query.
287 unsigned int mux_control_states(struct mux_control *mux) in mux_control_states() argument
289 return mux->states; in mux_control_states()
294 * The mux->lock must be down when calling this function.
296 static int __mux_control_select(struct mux_control *mux, int state) in __mux_control_select() argument
300 if (WARN_ON(state < 0 || state >= mux->states)) in __mux_control_select()
303 if (mux->cached_state == state) in __mux_control_select()
306 ret = mux_control_set(mux, state); in __mux_control_select()
310 /* The mux update failed, try to revert if appropriate... */ in __mux_control_select()
311 if (mux->idle_state != MUX_IDLE_AS_IS) in __mux_control_select()
312 mux_control_set(mux, mux->idle_state); in __mux_control_select()
319 * @mux: The mux-control to request a change of state from.
322 * On successfully selecting the mux-control state, it will be locked until
323 * there is a call to mux_control_deselect(). If the mux-control is already
328 * complete and the mux-control is free for others to use, but do not call
331 * Return: 0 when the mux-control state has the requested state or a negative
334 int mux_control_select(struct mux_control *mux, unsigned int state) in mux_control_select() argument
338 ret = down_killable(&mux->lock); in mux_control_select()
342 ret = __mux_control_select(mux, state); in mux_control_select()
345 up(&mux->lock); in mux_control_select()
353 * @mux: The mux-control to request a change of state from.
356 * On successfully selecting the mux-control state, it will be locked until
360 * complete and the mux-control is free for others to use, but do not call
363 * Return: 0 when the mux-control state has the requested state or a negative
364 * errno on error. Specifically -EBUSY if the mux-control is contended.
366 int mux_control_try_select(struct mux_control *mux, unsigned int state) in mux_control_try_select() argument
370 if (down_trylock(&mux->lock)) in mux_control_try_select()
373 ret = __mux_control_select(mux, state); in mux_control_try_select()
376 up(&mux->lock); in mux_control_try_select()
384 * @mux: The mux-control to deselect.
391 * occur if the mux has an idle state. Note that even if an error occurs, the
392 * mux-control is unlocked and is thus free for the next access.
394 int mux_control_deselect(struct mux_control *mux) in mux_control_deselect() argument
398 if (mux->idle_state != MUX_IDLE_AS_IS && in mux_control_deselect()
399 mux->idle_state != mux->cached_state) in mux_control_deselect()
400 ret = mux_control_set(mux, mux->idle_state); in mux_control_deselect()
402 up(&mux->lock); in mux_control_deselect()
419 * mux_control_get() - Get the mux-control for a device.
420 * @dev: The device that needs a mux-control.
421 * @mux_name: The name identifying the mux-control.
423 * Return: A pointer to the mux-control, or an ERR_PTR with a negative errno.
435 index = of_property_match_string(np, "mux-control-names", in mux_control_get()
438 dev_err(dev, "mux controller '%s' not found\n", in mux_control_get()
445 "mux-controls", "#mux-control-cells", in mux_control_get()
448 dev_err(dev, "%pOF: failed to get mux-control %s(%i)\n", in mux_control_get()
460 dev_err(dev, "%pOF: wrong #mux-control-cells for %pOF\n", in mux_control_get()
471 dev_err(dev, "%pOF: bad mux controller %u specified in %pOF\n", in mux_control_get()
477 return &mux_chip->mux[controller]; in mux_control_get()
482 * mux_control_put() - Put away the mux-control for good.
483 * @mux: The mux-control to put away.
487 void mux_control_put(struct mux_control *mux) in mux_control_put() argument
489 put_device(&mux->chip->dev); in mux_control_put()
495 struct mux_control *mux = *(struct mux_control **)res; in devm_mux_control_release() local
497 mux_control_put(mux); in devm_mux_control_release()
501 * devm_mux_control_get() - Get the mux-control for a device, with resource
503 * @dev: The device that needs a mux-control.
504 * @mux_name: The name identifying the mux-control.
506 * Return: Pointer to the mux-control, or an ERR_PTR with a negative errno.
511 struct mux_control **ptr, *mux; in devm_mux_control_get() local
517 mux = mux_control_get(dev, mux_name); in devm_mux_control_get()
518 if (IS_ERR(mux)) { in devm_mux_control_get()
520 return mux; in devm_mux_control_get()
523 *ptr = mux; in devm_mux_control_get()
526 return mux; in devm_mux_control_get()
532 * the non-modular case - that the subsystem is initialized when mux consumers
533 * and mux controllers start to use it.