All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] tm6000-alsa: Implement a routine to store data received from URB
       [not found] <cover.1275835609.git.mchehab@redhat.com>
@ 2010-06-06 14:53 ` Mauro Carvalho Chehab
  2010-06-06 14:53 ` [PATCH 1/2] tm6000-alsa: Fix several bugs at the driver initialization code Mauro Carvalho Chehab
  1 sibling, 0 replies; 2+ messages in thread
From: Mauro Carvalho Chehab @ 2010-06-06 14:53 UTC (permalink / raw)
  Cc: Linux Media Mailing List

Implements the fillbuf callback to store data received via URB
data transfers.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

diff --git a/drivers/staging/tm6000/tm6000-alsa.c b/drivers/staging/tm6000/tm6000-alsa.c
index fa19a41..d31b525 100644
--- a/drivers/staging/tm6000/tm6000-alsa.c
+++ b/drivers/staging/tm6000/tm6000-alsa.c
@@ -157,16 +157,16 @@ static struct snd_pcm_hardware snd_tm6000_digital_hw = {
 		SNDRV_PCM_INFO_MMAP_VALID,
 	.formats = SNDRV_PCM_FMTBIT_S16_LE,
 
-	.rates =		SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
-	.rate_min =		44100,
+	.rates =		SNDRV_PCM_RATE_48000,
+	.rate_min =		48000,
 	.rate_max =		48000,
 	.channels_min = 2,
 	.channels_max = 2,
-	.period_bytes_min = DEFAULT_FIFO_SIZE/4,
-	.period_bytes_max = DEFAULT_FIFO_SIZE/4,
+	.period_bytes_min = 62720,
+	.period_bytes_max = 62720,
 	.periods_min = 1,
 	.periods_max = 1024,
-	.buffer_bytes_max = (1024*1024),
+	.buffer_bytes_max = 62720 * 8,
 };
 
 /*
@@ -203,15 +203,45 @@ static int snd_tm6000_close(struct snd_pcm_substream *substream)
 
 static int tm6000_fillbuf(struct tm6000_core *core, char *buf, int size)
 {
-	int i;
+	struct snd_tm6000_card *chip = core->adev;
+	struct snd_pcm_substream *substream = chip->substream;
+	struct snd_pcm_runtime *runtime;
+	int period_elapsed = 0;
+	unsigned int stride, buf_pos;
 
-	/* Need to add a real code to copy audio buffer */
-	printk("Audio (%i bytes): ", size);
-	for (i = 0; i < size - 3; i +=4)
-		printk("(0x%04x, 0x%04x), ",
-			*(u16 *)(buf + i), *(u16 *)(buf + i + 2));
+	if (!size || !substream)
+		return -EINVAL;
 
-	printk("\n");
+	runtime = substream->runtime;
+	if (!runtime || !runtime->dma_area)
+		return -EINVAL;
+
+	buf_pos = chip->buf_pos;
+	stride = runtime->frame_bits >> 3;
+
+	dprintk(1, "Copying %d bytes at %p[%d] - buf size=%d x %d\n", size,
+		runtime->dma_area, buf_pos,
+		(unsigned int)runtime->buffer_size, stride);
+
+	if (buf_pos + size >= runtime->buffer_size * stride) {
+		unsigned int cnt = runtime->buffer_size * stride - buf_pos;
+		memcpy(runtime->dma_area + buf_pos, buf, cnt);
+		memcpy(runtime->dma_area, buf + cnt, size - cnt);
+	} else
+		memcpy(runtime->dma_area + buf_pos, buf, size);
+
+	chip->buf_pos += size;
+	if (chip->buf_pos >= runtime->buffer_size * stride)
+		chip->buf_pos -= runtime->buffer_size * stride;
+
+	chip->period_pos += size;
+	if (chip->period_pos >= runtime->period_size) {
+		chip->period_pos -= runtime->period_size;
+		period_elapsed = 1;
+	}
+
+	if (period_elapsed)
+		snd_pcm_period_elapsed(substream);
 
 	return 0;
 }
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 1/2] tm6000-alsa: Fix several bugs at the driver initialization code
       [not found] <cover.1275835609.git.mchehab@redhat.com>
  2010-06-06 14:53 ` [PATCH 2/2] tm6000-alsa: Implement a routine to store data received from URB Mauro Carvalho Chehab
@ 2010-06-06 14:53 ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 2+ messages in thread
From: Mauro Carvalho Chehab @ 2010-06-06 14:53 UTC (permalink / raw)
  Cc: Linux Media Mailing List

There are several missing things at the driver, preventing, for example,
the code to start/stop DMA to actually work. Fix them before implementing
a routine to store data at the audio buffers.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

diff --git a/drivers/staging/tm6000/tm6000-alsa.c b/drivers/staging/tm6000/tm6000-alsa.c
index e71579e..fa19a41 100644
--- a/drivers/staging/tm6000/tm6000-alsa.c
+++ b/drivers/staging/tm6000/tm6000-alsa.c
@@ -77,6 +77,8 @@ static int _tm6000_start_audio_dma(struct snd_tm6000_card *chip)
 	struct tm6000_core *core = chip->core;
 	int val;
 
+	dprintk(1, "Starting audio DMA\n");
+
 	/* Enables audio */
 	val = tm6000_get_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x0);
 	val |= 0x20;
@@ -236,7 +238,9 @@ static int snd_tm6000_hw_params(struct snd_pcm_substream *substream,
  */
 static int snd_tm6000_hw_free(struct snd_pcm_substream *substream)
 {
-	dsp_buffer_free(substream);
+	struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
+
+	_tm6000_stop_audio_dma(chip);
 
 	return 0;
 }
@@ -246,6 +250,11 @@ static int snd_tm6000_hw_free(struct snd_pcm_substream *substream)
  */
 static int snd_tm6000_prepare(struct snd_pcm_substream *substream)
 {
+	struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
+
+	chip->buf_pos = 0;
+	chip->period_pos = 0;
+
 	return 0;
 }
 
@@ -283,12 +292,8 @@ static int snd_tm6000_card_trigger(struct snd_pcm_substream *substream, int cmd)
 static snd_pcm_uframes_t snd_tm6000_pointer(struct snd_pcm_substream *substream)
 {
 	struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
-	struct snd_pcm_runtime *runtime = substream->runtime;
-	u16 count;
 
-	count = atomic_read(&chip->count);
-
-	return runtime->period_size * (count & (runtime->periods-1));
+	return chip->buf_pos;
 }
 
 /*
@@ -341,41 +346,43 @@ int tm6000_audio_init(struct tm6000_core *dev)
 		snd_printk(KERN_ERR "cannot create card instance %d\n", devnr);
 		return rc;
 	}
-
-	chip = kzalloc(sizeof(struct snd_tm6000_card), GFP_KERNEL);
-	if (!chip) {
-		rc = -ENOMEM;
-		goto error;
-	}
+	strcpy(card->driver, "tm6000-alsa");
+	strcpy(card->shortname, "TM5600/60x0");
+	sprintf(card->longname, "TM5600/60x0 Audio at bus %d device %d",
+		dev->udev->bus->busnum, dev->udev->devnum);
 
 	sprintf(component, "USB%04x:%04x",
 		le16_to_cpu(dev->udev->descriptor.idVendor),
 		le16_to_cpu(dev->udev->descriptor.idProduct));
 	snd_component_add(card, component);
+	snd_card_set_dev(card, &dev->udev->dev);
 
+	chip = kzalloc(sizeof(struct snd_tm6000_card), GFP_KERNEL);
+	if (!chip) {
+		rc = -ENOMEM;
+		goto error;
+	}
+
+	chip->core = dev;
+	chip->card = card;
+	dev->adev = chip;
 	spin_lock_init(&chip->reg_lock);
+
 	rc = snd_pcm_new(card, "TM6000 Audio", 0, 0, 1, &pcm);
 	if (rc < 0)
 		goto error;
 
-	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_tm6000_pcm_ops);
 	pcm->info_flags = 0;
-	pcm->private_data = dev;
+	pcm->private_data = chip;
 	strcpy(pcm->name, "Trident TM5600/60x0");
-	strcpy(card->driver, "tm6000-alsa");
-	strcpy(card->shortname, "TM5600/60x0");
-	sprintf(card->longname, "TM5600/60x0 Audio at bus %d device %d",
-		dev->udev->bus->busnum, dev->udev->devnum);
 
-	snd_card_set_dev(card, &dev->udev->dev);
+	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_tm6000_pcm_ops);
 
 	rc = snd_card_register(card);
 	if (rc < 0)
 		goto error;
 
-	chip->core = dev;
-	chip->card = card;
-	dev->adev = chip;
+	dprintk(1,"Registered audio driver for %s\n", card->longname);
 
 	return 0;
 
diff --git a/drivers/staging/tm6000/tm6000-core.c b/drivers/staging/tm6000/tm6000-core.c
index 626b85e..46b9ec5 100644
--- a/drivers/staging/tm6000/tm6000-core.c
+++ b/drivers/staging/tm6000/tm6000-core.c
@@ -677,10 +677,10 @@ int tm6000_register_extension(struct tm6000_ops *ops)
 	mutex_lock(&tm6000_extension_devlist_lock);
 	list_add_tail(&ops->next, &tm6000_extension_devlist);
 	list_for_each_entry(dev, &tm6000_devlist, devlist) {
-		if (dev)
-			ops->init(dev);
+		ops->init(dev);
+		printk(KERN_INFO "%s: Initialized (%s) extension\n",
+		       dev->name, ops->name);
 	}
-	printk(KERN_INFO "tm6000: Initialized (%s) extension\n", ops->name);
 	mutex_unlock(&tm6000_extension_devlist_lock);
 	mutex_unlock(&tm6000_devlist_mutex);
 	return 0;
diff --git a/drivers/staging/tm6000/tm6000.h b/drivers/staging/tm6000/tm6000.h
index db99959..89862a4 100644
--- a/drivers/staging/tm6000/tm6000.h
+++ b/drivers/staging/tm6000/tm6000.h
@@ -135,9 +135,12 @@ struct tm6000_dvb {
 struct snd_tm6000_card {
 	struct snd_card			*card;
 	spinlock_t			reg_lock;
-	atomic_t			count;
 	struct tm6000_core		*core;
 	struct snd_pcm_substream	*substream;
+
+	/* temporary data for buffer fill processing */
+	unsigned			buf_pos;
+	unsigned			period_pos;
 };
 
 struct tm6000_endpoint {
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-06-06 14:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1275835609.git.mchehab@redhat.com>
2010-06-06 14:53 ` [PATCH 2/2] tm6000-alsa: Implement a routine to store data received from URB Mauro Carvalho Chehab
2010-06-06 14:53 ` [PATCH 1/2] tm6000-alsa: Fix several bugs at the driver initialization code Mauro Carvalho Chehab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.