diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2014-08-29 04:25:30 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2014-11-03 05:21:55 -0500 |
commit | b2c75abde0debfb824f72845c3ed77d4b66798a0 (patch) | |
tree | a62c4616cd08edf3ba4987355097ab016e41d31c /drivers/media/pci | |
parent | 6f11adc6a5e3378aeb13d9a19c427cbec05805be (diff) |
[media] cx88: drop videobuf abuse in cx88-alsa
The alsa driver uses videobuf low-level functions that are not
available in vb2, so replace them by driver-specific functions.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/pci')
-rw-r--r-- | drivers/media/pci/cx88/cx88-alsa.c | 107 |
1 files changed, 89 insertions, 18 deletions
diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c index a72579a9f67f..73021a22de1b 100644 --- a/drivers/media/pci/cx88/cx88-alsa.c +++ b/drivers/media/pci/cx88/cx88-alsa.c | |||
@@ -62,7 +62,10 @@ | |||
62 | struct cx88_audio_buffer { | 62 | struct cx88_audio_buffer { |
63 | unsigned int bpl; | 63 | unsigned int bpl; |
64 | struct btcx_riscmem risc; | 64 | struct btcx_riscmem risc; |
65 | struct videobuf_dmabuf dma; | 65 | void *vaddr; |
66 | struct scatterlist *sglist; | ||
67 | int sglen; | ||
68 | int nr_pages; | ||
66 | }; | 69 | }; |
67 | 70 | ||
68 | struct cx88_audio_dev { | 71 | struct cx88_audio_dev { |
@@ -84,8 +87,6 @@ struct cx88_audio_dev { | |||
84 | unsigned int period_size; | 87 | unsigned int period_size; |
85 | unsigned int num_periods; | 88 | unsigned int num_periods; |
86 | 89 | ||
87 | struct videobuf_dmabuf *dma_risc; | ||
88 | |||
89 | struct cx88_audio_buffer *buf; | 90 | struct cx88_audio_buffer *buf; |
90 | 91 | ||
91 | struct snd_pcm_substream *substream; | 92 | struct snd_pcm_substream *substream; |
@@ -290,19 +291,94 @@ static irqreturn_t cx8801_irq(int irq, void *dev_id) | |||
290 | return IRQ_RETVAL(handled); | 291 | return IRQ_RETVAL(handled); |
291 | } | 292 | } |
292 | 293 | ||
294 | static int cx88_alsa_dma_init(struct cx88_audio_dev *chip, int nr_pages) | ||
295 | { | ||
296 | struct cx88_audio_buffer *buf = chip->buf; | ||
297 | struct page *pg; | ||
298 | int i; | ||
299 | |||
300 | buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT); | ||
301 | if (NULL == buf->vaddr) { | ||
302 | dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages); | ||
303 | return -ENOMEM; | ||
304 | } | ||
305 | |||
306 | dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n", | ||
307 | (unsigned long)buf->vaddr, | ||
308 | nr_pages << PAGE_SHIFT); | ||
309 | |||
310 | memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); | ||
311 | buf->nr_pages = nr_pages; | ||
312 | |||
313 | buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist)); | ||
314 | if (NULL == buf->sglist) | ||
315 | goto vzalloc_err; | ||
316 | |||
317 | sg_init_table(buf->sglist, buf->nr_pages); | ||
318 | for (i = 0; i < buf->nr_pages; i++) { | ||
319 | pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE); | ||
320 | if (NULL == pg) | ||
321 | goto vmalloc_to_page_err; | ||
322 | sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0); | ||
323 | } | ||
324 | return 0; | ||
325 | |||
326 | vmalloc_to_page_err: | ||
327 | vfree(buf->sglist); | ||
328 | buf->sglist = NULL; | ||
329 | vzalloc_err: | ||
330 | vfree(buf->vaddr); | ||
331 | buf->vaddr = NULL; | ||
332 | return -ENOMEM; | ||
333 | } | ||
334 | |||
335 | static int cx88_alsa_dma_map(struct cx88_audio_dev *dev) | ||
336 | { | ||
337 | struct cx88_audio_buffer *buf = dev->buf; | ||
338 | |||
339 | buf->sglen = dma_map_sg(&dev->pci->dev, buf->sglist, | ||
340 | buf->nr_pages, PCI_DMA_FROMDEVICE); | ||
341 | |||
342 | if (0 == buf->sglen) { | ||
343 | pr_warn("%s: cx88_alsa_map_sg failed\n", __func__); | ||
344 | return -ENOMEM; | ||
345 | } | ||
346 | return 0; | ||
347 | } | ||
348 | |||
349 | static int cx88_alsa_dma_unmap(struct cx88_audio_dev *dev) | ||
350 | { | ||
351 | struct cx88_audio_buffer *buf = dev->buf; | ||
352 | |||
353 | if (!buf->sglen) | ||
354 | return 0; | ||
355 | |||
356 | dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen, PCI_DMA_FROMDEVICE); | ||
357 | buf->sglen = 0; | ||
358 | return 0; | ||
359 | } | ||
360 | |||
361 | static int cx88_alsa_dma_free(struct cx88_audio_buffer *buf) | ||
362 | { | ||
363 | vfree(buf->sglist); | ||
364 | buf->sglist = NULL; | ||
365 | vfree(buf->vaddr); | ||
366 | buf->vaddr = NULL; | ||
367 | return 0; | ||
368 | } | ||
369 | |||
293 | 370 | ||
294 | static int dsp_buffer_free(snd_cx88_card_t *chip) | 371 | static int dsp_buffer_free(snd_cx88_card_t *chip) |
295 | { | 372 | { |
296 | BUG_ON(!chip->dma_size); | 373 | BUG_ON(!chip->dma_size); |
297 | 374 | ||
298 | dprintk(2,"Freeing buffer\n"); | 375 | dprintk(2,"Freeing buffer\n"); |
299 | videobuf_dma_unmap(&chip->pci->dev, chip->dma_risc); | 376 | cx88_alsa_dma_unmap(chip); |
300 | videobuf_dma_free(chip->dma_risc); | 377 | cx88_alsa_dma_free(chip->buf); |
301 | btcx_riscmem_free(chip->pci,&chip->buf->risc); | 378 | btcx_riscmem_free(chip->pci, &chip->buf->risc); |
302 | kfree(chip->buf); | 379 | kfree(chip->buf); |
303 | 380 | ||
304 | chip->dma_risc = NULL; | 381 | chip->buf = NULL; |
305 | chip->dma_size = 0; | ||
306 | 382 | ||
307 | return 0; | 383 | return 0; |
308 | } | 384 | } |
@@ -387,7 +463,6 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream, | |||
387 | struct snd_pcm_hw_params * hw_params) | 463 | struct snd_pcm_hw_params * hw_params) |
388 | { | 464 | { |
389 | snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); | 465 | snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); |
390 | struct videobuf_dmabuf *dma; | ||
391 | 466 | ||
392 | struct cx88_audio_buffer *buf; | 467 | struct cx88_audio_buffer *buf; |
393 | int ret; | 468 | int ret; |
@@ -408,20 +483,19 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream, | |||
408 | if (NULL == buf) | 483 | if (NULL == buf) |
409 | return -ENOMEM; | 484 | return -ENOMEM; |
410 | 485 | ||
486 | chip->buf = buf; | ||
411 | buf->bpl = chip->period_size; | 487 | buf->bpl = chip->period_size; |
412 | 488 | ||
413 | dma = &buf->dma; | 489 | ret = cx88_alsa_dma_init(chip, |
414 | videobuf_dma_init(dma); | ||
415 | ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE, | ||
416 | (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT)); | 490 | (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT)); |
417 | if (ret < 0) | 491 | if (ret < 0) |
418 | goto error; | 492 | goto error; |
419 | 493 | ||
420 | ret = videobuf_dma_map(&chip->pci->dev, dma); | 494 | ret = cx88_alsa_dma_map(chip); |
421 | if (ret < 0) | 495 | if (ret < 0) |
422 | goto error; | 496 | goto error; |
423 | 497 | ||
424 | ret = cx88_risc_databuffer(chip->pci, &buf->risc, dma->sglist, | 498 | ret = cx88_risc_databuffer(chip->pci, &buf->risc, buf->sglist, |
425 | chip->period_size, chip->num_periods, 1); | 499 | chip->period_size, chip->num_periods, 1); |
426 | if (ret < 0) | 500 | if (ret < 0) |
427 | goto error; | 501 | goto error; |
@@ -430,10 +504,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream, | |||
430 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC); | 504 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC); |
431 | buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); | 505 | buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
432 | 506 | ||
433 | chip->buf = buf; | 507 | substream->runtime->dma_area = chip->buf->vaddr; |
434 | chip->dma_risc = dma; | ||
435 | |||
436 | substream->runtime->dma_area = chip->dma_risc->vaddr; | ||
437 | substream->runtime->dma_bytes = chip->dma_size; | 508 | substream->runtime->dma_bytes = chip->dma_size; |
438 | substream->runtime->dma_addr = 0; | 509 | substream->runtime->dma_addr = 0; |
439 | return 0; | 510 | return 0; |