Re: [PATCH v2 04/14] staging: most: sound: introduce new sound adapter management

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fr, 2019-03-29 at 13:46 +0300, Dan Carpenter wrote:
> External E-Mail
> 
> 
> On Thu, Mar 28, 2019 at 02:17:32PM +0100, Christian Gromm wrote:
> > 
> > +static int audio_create_sound_card(void)
> > +{
> > +	int ret;
> > +	struct sound_adapter *adpt;
> > +
> > +	list_for_each_entry(adpt, &adpt_list, list) {
> > +		if (!adpt->registered)
> > +			goto adpt_alloc;
> > +	}
> > +	return -ENODEV;
> > +adpt_alloc:
> > +	ret = snd_card_register(adpt->card);
> > +	if (ret < 0) {
> > +		release_adapter(adpt);
> > +		return ret;
> > +	}
> > +	adpt->registered = true;
> > +	return ret;
>         ^^^^^^^^^^
> 
> 	return 0;
> 
> > 
> > +}
> This function is just strange to me...  We add a bunch of adapters to
> "adpt_list" in audio_probe_channel().  Each adapter has it's own
> adpt->card.  But here we just take the first unregistered adapter and
> register it as our card.
> 
Unfortunately, I am not an ASCII artist, otherwise I would have put
some flowcharts in here to make things clear.
But in principle, it is like this:

A channel of a device which is intended to carry audio data,
will be represented as a PCM device on a sound card. So, if
I want my sound card

 --> mkdir /sys/kernel/config/most_sound/mycard 

to have a capture device and a playback device, I would
link two channels (one rx and on tx) and hook them on the card by
creating a directory in the card's directory.

 --> mkdir /sys/kernel/config/most_sound/mycard/pcm_capture
 --> mkdir
/sys/kernel/config/most_sound/mycard/pcm_playback		​
Then I would go ahead and configure the attributes inside and
finally activate the links:

 --> echo 1 > /sys/kernel/config/most_sound/mycard/pcm_playback/create_link

and

 --> echo 1 > /sys/kernel/config/most_sound/mycard/pcm_capture/create_link


The first time a link is being activated, the probe function gets
called and if no adapter has yet been created, one is created now
and the PCM device is added. By the time the second call happens,
we already have an adapter that is _not_ registered with ALSA.
Hence, we skip allocating another adapter and use the one we got
to add the next PCM device.

Once I have all PCM devices set up, I would do

 --> echo 1 > /sys/kernel/config/most_sound/mycard/create_card
 
And now, the "strange" audio_create_sound_card function is
called to register the adapter with ALSA. If everything is fine,
the adpt->registered flag is set and from now on I would be able
to create a second sound card on the system. An only now a new
adapter would be allocated in the probe function, because we
can't find one in our list that is waiting to get registered
with ALSA.

Unless I do the create_card thing, all channels would be added
to the same adapter and I would end up with a sound card that
has "a bunch" of PCM devices.

Hope I kind of could get the picture across.

thanks,
Chris



> regards,
> dan carpenter
> _______________________________________________
> devel mailing list
> devel@xxxxxxxxxxxxxxxxxxxxxx
> http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-de
> vel
> 
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux