Re: [PATCH v5 5/6] ASoC: codecs: wcd938x: add mux control support for hp audio mux

From: Srinivas Kandagatla
Date: Tue Mar 25 2025 - 17:40:14 EST


Thanks Peter,

On 25/03/2025 20:13, Peter Rosin wrote:
Hi!

2025-03-25 at 19:04, Srinivas Kandagatla wrote:
I wish we could be taken care in mux-core or even in the deselect api

It is not easily done. A mux is a shared resource. How can the mux core
know if it is consumer A or consumer B that deselects the mux if both
ignore failures when calling select? Mux select is backed by a semaphore
and there is no guarantee that a consumer selects/deselects from the
same thread or anything like that. The onus is on the consumer to get
this right and only deselect when select is successful.

Should deselect fail if there was no previous mux selected?


I believe the documentation is clear on this topic: "do not call
mux_control_deselect() if mux_control_select() fails".

True, the documentation is pretty clear about this behavior.

One thing can be done from the mux core, and that is to provide a new
API where consumers get a mux that is exclusive so that the consumer
can call select/deselect without involving a lock in the core. There
need not even be a requirement to call deselect between selects in that
case. Such an API is what many consumers want, I think, but it is of
course not really compatible with the existing API, which is totally
focused on the need to share a mux among multiple consumers.

exclusive apis would simplify the consumer side of code for sure.

And, of course, someone has to do it.

Yes, I can give it a go and see how it will turn out.

--srini

Cheers,
Peter