]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
ALSA: pcm: support for period wakeup disabling
authorClemens Ladisch <clemens@ladisch.de>
Mon, 15 Nov 2010 09:46:23 +0000 (10:46 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 22 Nov 2010 07:13:16 +0000 (08:13 +0100)
This patch allows to disable period interrupts which are
not needed when the application relies on a system timer
to wake-up and refill the ring buffer. The behavior of
the driver is left unchanged, and interrupts are only
disabled if the application requests this configuration.
The behavior in case of underruns is slightly different,
instead of being detected during the period interrupts the
underruns are detected when the application calls
snd_pcm_update_avail, which in turns forces a refresh of the
hw pointer and shows the buffer is empty.

More specifically this patch makes a lot of sense when
PulseAudio relies on timer-based scheduling to access audio
devices such as HDAudio or Intel SST. Disabling interrupts
removes two unwanted wake-ups due to period elapsed events
in low-power playback modes. It also simplifies PulseAudio
voice modules used for speech calls.

To quote Lennart "This patch looks very interesting and
desirable. This is something have long been waiting for."

Support for this in hardware drivers is optional.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@intel.com>
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/asound.h
include/sound/pcm.h
sound/core/pcm_lib.c
sound/core/pcm_native.c

index a1803ecea34deb080faa168f9070783eee624f00..5d6074faa279adabd3f45c7adf792fa578913ebb 100644 (file)
@@ -259,6 +259,7 @@ typedef int __bitwise snd_pcm_subformat_t;
 #define SNDRV_PCM_INFO_HALF_DUPLEX     0x00100000      /* only half duplex */
 #define SNDRV_PCM_INFO_JOINT_DUPLEX    0x00200000      /* playback and capture stream are somewhat correlated */
 #define SNDRV_PCM_INFO_SYNC_START      0x00400000      /* pcm support some kind of sync go */
+#define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP        0x00800000      /* period wakeup can be disabled */
 #define SNDRV_PCM_INFO_FIFO_IN_FRAMES  0x80000000      /* internal kernel flag - FIFO size is in frames */
 
 typedef int __bitwise snd_pcm_state_t;
@@ -334,6 +335,8 @@ typedef int snd_pcm_hw_param_t;
 #define        SNDRV_PCM_HW_PARAM_LAST_INTERVAL        SNDRV_PCM_HW_PARAM_TICK_TIME
 
 #define SNDRV_PCM_HW_PARAMS_NORESAMPLE (1<<0)  /* avoid rate resampling */
+#define SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER      (1<<1)  /* export buffer */
+#define SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP   (1<<2)  /* disable period wakeups */
 
 struct snd_interval {
        unsigned int min, max;
index dfd9b76b185306a40fff57df94ad53ab83d2f966..e731f8d7193472e359323b4d0eda86428c340d61 100644 (file)
@@ -297,6 +297,7 @@ struct snd_pcm_runtime {
        unsigned int info;
        unsigned int rate_num;
        unsigned int rate_den;
+       unsigned int no_period_wakeup: 1;
 
        /* -- SW params -- */
        int tstamp_mode;                /* mmap timestamp is updated */
index b75db8e9cc0f36fff03d0ecf1884b23b3bad724b..bc57501c584affe54e44ae73a4e2b534bab6830b 100644 (file)
@@ -373,6 +373,11 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
                           (unsigned long)new_hw_ptr,
                           (unsigned long)runtime->hw_ptr_base);
        }
+
+       /* without period interrupts, there are no regular pointer updates */
+       if (runtime->no_period_wakeup)
+               goto no_delta_check;
+
        /* something must be really wrong */
        if (delta >= runtime->buffer_size + runtime->period_size) {
                hw_ptr_error(substream,
@@ -442,6 +447,7 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
                             (long)old_hw_ptr);
        }
 
+ no_delta_check:
        if (runtime->status->hw_ptr == new_hw_ptr)
                return 0;
 
index 8bc7cb3db33056abce9a03cec36a4266305aa12c..f91a439f675cd5fdf10404ed2bada575888e2797 100644 (file)
@@ -423,6 +423,9 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
        runtime->info = params->info;
        runtime->rate_num = params->rate_num;
        runtime->rate_den = params->rate_den;
+       runtime->no_period_wakeup =
+                       (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) &&
+                       (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP);
 
        bits = snd_pcm_format_physical_width(runtime->format);
        runtime->sample_bits = bits;