Repository navigation
add mmap support and some cleanups to bcm2835 ALSA driver - #286
Conversation
On driver probe a message showing that a card and its subdevices have been created is shown. Probably this message is not needed unless we have debug enabled on the driver. So, use the driver audio_info() debug macro instead of just printk(). Also is better to use dev_err() and pr_err() instead KERN_ERR. Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
The kernel completion interface is a simple synchronization mechanism that is preferable over semaphores to signal the occurence of an event. Semaphores are optimized for the non-contention case since in most situations they will be available. But the wait for completion is the opposite case since the code calling down will wait on most cases. So, is better to use the completion mechanism that has been developed for this exact use case instead of semaphores. Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
The bcm2835 driver uses a workqueue to defer PCM playback start and stop. Commands are passed to the function as magic numbers so is more readable to use macro constants. Also, while being there change the generic name "x" to "cmd" for the var used to pass the start/stop commands. Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Only PCM playback and stop are deferred using a workqueue on the ALSA bcm2835 driver. The actual writing of PCM samples is synchronous. This works well for the read/write transfer method since the snd_pcm_ops .copy function pointer runs on process context. But the snd_pcm_ops .ack function pointer used to implement direct read/write transfer using a memory-mapped I/O, runs with interrupts disabled. Since the Kernel to VideoCore interface driver has to be able to sleep, PCM write has to be deferred to in preparation to add mmap support to the driver. Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
ALSA supports two transfers methods for PCM playback: Read/Write transfer where samples are writtern to the device using standard read and write functions and Direct Read/Write transfers where samples can be written directly to a mapped memory area and the driver is signaled once this has been done. The bcm2835 driver only supported Read/Write transfer method so this patch adds mmap support to the driver. The ARM CPU is not able to directly address the audio device hardware buffer so audio samples are sent to the device using a message passing interface (vchiq). Since hardware buffers can't be directly mapped to user-space memory, an intermediate buffer (using the PCM indirect API) is needed to store the audio samples and push them to the device through videocore. Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
|
With original driver: Lots of complaints, but I hear the audio. With your patch and no audio output. Any idea why? (and why so many warnings). |
Works correctly without patch. I've had silence, squawks and a hang with the patch. |
|
weird, I tested with aplay, mpg123, jackd and this Gstreamer pipeline: all of them worked for me. I'll test with mplayer and espeak to see why you are having these issues. Btw, did you remove the /etc/asound.conf that is adding mmap emulation? You shouldn't use that plug-in since the driver now supports it (in fact it won't work when using). I'm using this asound.conf: But is works when trying with no asound at all too. |
|
When you said with your patch, you mean with the patch-set right? or are you testing each patch separately? These two patches should be applied together: Since the later won't work without the former. I tried to keep the changes separated to make it easier to review to you, maybe I should squash these two... |
|
I was using (I think) the default asound.conf: It was still largely working. mplayer worked with a wav file, but not mp3. mpg123 worked with mp3 file. I've just tried with your asound and it works in the two cases I'd reported as not working. I think we'll get some confusion with people updating kernel on a standard raspbian image (so using mmap_emul), but perhaps that the price of progress. We'll remove mmap_emul in next official image. (I'm testing the patch as a whole (286.diff). |
|
We can sort out asound.conf upon upgrade (for those updating via apt-get On 26 April 2013 17:25, popcornmix notifications@github.com wrote:
|
|
Yes, if you have mmap emulation on your asound.conf and the driver supports mmap then it will work as long as applications are only using ALSA read/write PCM transfer API (snd_pcm_{writei, readi}) but is not going to work if is using mmap direct r/w API calls (snd_pcm_mmap_{begin, commit, readi, writei}) You can see the difference with aplay: works but does not. I'm not familiarized with asound mmap emulation plug-in but I guess that when an application is trying to use the ALSA mmap API then the PCM is written twice: one by ALSA when snd_pcm_mmap_commit() is called and another time by libasound mmap emulation plug-in that breaks the buffer in many calls to snd_pcm_writei(). Anyway, as you said the solution is to remove mmap_emul. I don't know what option is better for raspbian, if an asound.conf without mmap emulation should be shipped or no asound.conf at all. But as @asb said, this can be sorted out for people updating via apt. |
|
Yes, new images, and apt-get upgrade users will have no problem. Thanks for the PR, it looks good. |
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
|
thanks a lot for feedback and testing! |
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
|
There's a report of a regression from this patch in espeak: |
|
Thanks for the notice. I'll take a look at this bug. Regards |
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
|
@martinezjavier |
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
add mmap support and some cleanups to bcm2835 ALSA driver
Hello,
This series contains the following improvements to the ALSA bcm2835 driver:
ad-hoc implementation using semaphores.
driver workqueue instead of using magic numbers.
not enabled. Also replace printk() usage by more suitable functions.
and fixes these open issues:
#158 "bcm2835 ALSA driver hardware mixing or mmap?"
raspberrypi/firmware#173 "ALSA is not supporting 16 bits signed audio"
#282 "ALSA boot messages"
The following changes since commit 07b8b7d:
Merge pull request #279 from P33M/rpi-3.6.y (2013-04-22 08:08:49 -0700)
are available in the git repository at:
git://github.com/martinezjavier/linux-rpi.git rpi-3.6.y-dev
Javier Martinez Canillas (5):
ALSA: bcm2835: show card and subdev creation msg only on debug
ALSA: bcm2835: use a completion instead of a semaphore for sync
ALSA: bcm2835: don't use magic numbers on audio start/stop workqueue
ALSA: bcm2835: defer bcm2835 PCM write using the workqueue
ALSA: bcm2835: add memory-mapped I/O mode for audio stream
sound/arm/bcm2835-pcm.c | 69 ++++++++++++++++++++++-------------
sound/arm/bcm2835-vchiq.c | 89 +++++++++++++++++++++++++++++++--------------
sound/arm/bcm2835.c | 34 +++++++++---------
sound/arm/bcm2835.h | 2 +
4 files changed, 124 insertions(+), 70 deletions(-)
Thanks a lot and best regards,
Javier