schedule_delayed_work
目的是解决spdif播放音频前800ms音频不出的问题。但是spdif信号锁定很差音响就会丢失前面的音频
diff --git a/soc/x2000/spdif/spdif_dma.c b/soc/x2000/spdif/spdif_dma.c
index cc923da..936ff4c 100644
--- a/soc/x2000/spdif/spdif_dma.c
+++ b/soc/x2000/spdif/spdif_dma.c
@@ -13,6 +13,7 @@
#include <linux/dmaengine.h>
#include <linux/hrtimer.h>
#include <linux/err.h>
+#include <linux/workqueue.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
@@ -64,8 +65,11 @@ struct spdif_dma_data {
int period_ns;
unsigned char hrtimer_state;
struct hrtimer hrtimer;
+ struct delayed_work delayed_work;
};
+DEFINE_SPINLOCK(spdif_dma_lock);
+
static inline void *m_dma_alloc_coherent(int size)
{
dma_addr_t dma_handle;
@@ -98,10 +102,13 @@ static enum hrtimer_restart spdif_hrtimer_callback(struct hrtimer *hrtimer)
return HRTIMER_RESTART;
}
+static void spdif_dma_start(struct work_struct *work);
+
static int spdif_dma_pcm_open(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct spdif_dma_data *spdif_dma;
+ printk("%s %d\n",__func__,__LINE__);
int ret = snd_soc_set_runtime_hwparams(substream, &spdif_pcm_hardware);
if (ret) {
@@ -134,6 +141,7 @@ static int spdif_dma_pcm_open(struct snd_pcm_substream *substream)
hrtimer_init(&spdif_dma->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
spdif_dma->hrtimer.function = spdif_hrtimer_callback;
spdif_dma->substream = substream;
+ INIT_DELAYED_WORK(&spdif_dma->delayed_work, spdif_dma_start);
runtime->private_data = spdif_dma;
@@ -321,24 +329,37 @@ static int spdif_dma_pcm_hw_free(struct snd_pcm_substream *substream)
return 0;
}
+static void spdif_dma_start(struct work_struct *work)
+{
+ printk("%s %d\n",__func__,__LINE__);
+ unsigned long flags;
+ spin_lock_irqsave(&spdif_dma_lock, flags);
+ struct delayed_work *delayed_work = container_of(work, struct delayed_work, work);
+ struct spdif_dma_data *spdif_dma = container_of(delayed_work, struct spdif_dma_data, delayed_work);
+ audio_dma_start(spdif_dma->dma_dev, spdif_dma->dma_desc);
+ if (spdif_dma->hrtimer_state == State_idle) {
+ hrtimer_forward_now(&spdif_dma->hrtimer,
+ ns_to_ktime(spdif_dma->period_ns));
+ hrtimer_start_expires(&spdif_dma->hrtimer, HRTIMER_MODE_ABS);
+ }
+
+ spdif_dma->hrtimer_state = State_running;
+ spin_unlock_irqrestore(&spdif_dma_lock, flags);
+}
+
static int spdif_dma_trigger(struct snd_pcm_substream *substream, int cmd)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct spdif_dma_data *spdif_dma = runtime->private_data;
int ret = 0;
+ printk("%s %d\n",__func__,__LINE__);
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- audio_dma_start(spdif_dma->dma_dev, spdif_dma->dma_desc);
- if (spdif_dma->hrtimer_state == State_idle) {
- hrtimer_forward_now(&spdif_dma->hrtimer,
- ns_to_ktime(spdif_dma->period_ns));
- hrtimer_start_expires(&spdif_dma->hrtimer, HRTIMER_MODE_ABS);
- }
-
- spdif_dma->hrtimer_state = State_running;
+ schedule_delayed_work(&spdif_dma->delayed_work, msecs_to_jiffies(500));
+ printk("%s %d\n",__func__,__LINE__);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
@@ -350,10 +371,10 @@ static int spdif_dma_trigger(struct snd_pcm_substream *substream, int cmd)
ret = -EINVAL;
break;
}
-
return ret;
}
+
static int debug = 0;
module_param(debug, int, 0644);