diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2014-12-12 08:27:57 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2014-12-23 07:15:52 -0500 |
commit | 8d8e6d6005de1f2421b7846bfb50782b09cd63a7 (patch) | |
tree | 7a494cdd3c2c016cce812abcbfabfaa8e23dddb0 /drivers/media/pci/cx25821/cx25821-alsa.c | |
parent | 90ca8bef9082c2036a200dd2cd17924944cd339b (diff) |
[media] cx28521: drop videobuf abuse in cx25821-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/cx25821/cx25821-alsa.c')
-rw-r--r-- | drivers/media/pci/cx25821/cx25821-alsa.c | 107 |
1 files changed, 90 insertions, 17 deletions
diff --git a/drivers/media/pci/cx25821/cx25821-alsa.c b/drivers/media/pci/cx25821/cx25821-alsa.c index 27e6493622b6..24f964bcc53a 100644 --- a/drivers/media/pci/cx25821/cx25821-alsa.c +++ b/drivers/media/pci/cx25821/cx25821-alsa.c | |||
@@ -64,7 +64,10 @@ static int devno; | |||
64 | struct cx25821_audio_buffer { | 64 | struct cx25821_audio_buffer { |
65 | unsigned int bpl; | 65 | unsigned int bpl; |
66 | struct cx25821_riscmem risc; | 66 | struct cx25821_riscmem risc; |
67 | struct videobuf_dmabuf dma; | 67 | void *vaddr; |
68 | struct scatterlist *sglist; | ||
69 | int sglen; | ||
70 | int nr_pages; | ||
68 | }; | 71 | }; |
69 | 72 | ||
70 | struct cx25821_audio_dev { | 73 | struct cx25821_audio_dev { |
@@ -87,8 +90,6 @@ struct cx25821_audio_dev { | |||
87 | unsigned int period_size; | 90 | unsigned int period_size; |
88 | unsigned int num_periods; | 91 | unsigned int num_periods; |
89 | 92 | ||
90 | struct videobuf_dmabuf *dma_risc; | ||
91 | |||
92 | struct cx25821_audio_buffer *buf; | 93 | struct cx25821_audio_buffer *buf; |
93 | 94 | ||
94 | struct snd_pcm_substream *substream; | 95 | struct snd_pcm_substream *substream; |
@@ -142,6 +143,83 @@ MODULE_PARM_DESC(debug, "enable debug messages"); | |||
142 | 143 | ||
143 | #define PCI_MSK_AUD_EXT (1 << 4) | 144 | #define PCI_MSK_AUD_EXT (1 << 4) |
144 | #define PCI_MSK_AUD_INT (1 << 3) | 145 | #define PCI_MSK_AUD_INT (1 << 3) |
146 | |||
147 | static int cx25821_alsa_dma_init(struct cx25821_audio_dev *chip, int nr_pages) | ||
148 | { | ||
149 | struct cx25821_audio_buffer *buf = chip->buf; | ||
150 | struct page *pg; | ||
151 | int i; | ||
152 | |||
153 | buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT); | ||
154 | if (NULL == buf->vaddr) { | ||
155 | dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages); | ||
156 | return -ENOMEM; | ||
157 | } | ||
158 | |||
159 | dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n", | ||
160 | (unsigned long)buf->vaddr, | ||
161 | nr_pages << PAGE_SHIFT); | ||
162 | |||
163 | memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); | ||
164 | buf->nr_pages = nr_pages; | ||
165 | |||
166 | buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist)); | ||
167 | if (NULL == buf->sglist) | ||
168 | goto vzalloc_err; | ||
169 | |||
170 | sg_init_table(buf->sglist, buf->nr_pages); | ||
171 | for (i = 0; i < buf->nr_pages; i++) { | ||
172 | pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE); | ||
173 | if (NULL == pg) | ||
174 | goto vmalloc_to_page_err; | ||
175 | sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0); | ||
176 | } | ||
177 | return 0; | ||
178 | |||
179 | vmalloc_to_page_err: | ||
180 | vfree(buf->sglist); | ||
181 | buf->sglist = NULL; | ||
182 | vzalloc_err: | ||
183 | vfree(buf->vaddr); | ||
184 | buf->vaddr = NULL; | ||
185 | return -ENOMEM; | ||
186 | } | ||
187 | |||
188 | static int cx25821_alsa_dma_map(struct cx25821_audio_dev *dev) | ||
189 | { | ||
190 | struct cx25821_audio_buffer *buf = dev->buf; | ||
191 | |||
192 | buf->sglen = dma_map_sg(&dev->pci->dev, buf->sglist, | ||
193 | buf->nr_pages, PCI_DMA_FROMDEVICE); | ||
194 | |||
195 | if (0 == buf->sglen) { | ||
196 | pr_warn("%s: cx25821_alsa_map_sg failed\n", __func__); | ||
197 | return -ENOMEM; | ||
198 | } | ||
199 | return 0; | ||
200 | } | ||
201 | |||
202 | static int cx25821_alsa_dma_unmap(struct cx25821_audio_dev *dev) | ||
203 | { | ||
204 | struct cx25821_audio_buffer *buf = dev->buf; | ||
205 | |||
206 | if (!buf->sglen) | ||
207 | return 0; | ||
208 | |||
209 | dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen, PCI_DMA_FROMDEVICE); | ||
210 | buf->sglen = 0; | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | static int cx25821_alsa_dma_free(struct cx25821_audio_buffer *buf) | ||
215 | { | ||
216 | vfree(buf->sglist); | ||
217 | buf->sglist = NULL; | ||
218 | vfree(buf->vaddr); | ||
219 | buf->vaddr = NULL; | ||
220 | return 0; | ||
221 | } | ||
222 | |||
145 | /* | 223 | /* |
146 | * BOARD Specific: Sets audio DMA | 224 | * BOARD Specific: Sets audio DMA |
147 | */ | 225 | */ |
@@ -335,12 +413,12 @@ static int dsp_buffer_free(struct cx25821_audio_dev *chip) | |||
335 | BUG_ON(!chip->dma_size); | 413 | BUG_ON(!chip->dma_size); |
336 | 414 | ||
337 | dprintk(2, "Freeing buffer\n"); | 415 | dprintk(2, "Freeing buffer\n"); |
338 | videobuf_dma_unmap(&chip->pci->dev, chip->dma_risc); | 416 | cx25821_alsa_dma_unmap(chip); |
339 | videobuf_dma_free(chip->dma_risc); | 417 | cx25821_alsa_dma_free(chip->buf); |
340 | pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma); | 418 | pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma); |
341 | kfree(chip->buf); | 419 | kfree(chip->buf); |
342 | 420 | ||
343 | chip->dma_risc = NULL; | 421 | chip->buf = NULL; |
344 | chip->dma_size = 0; | 422 | chip->dma_size = 0; |
345 | 423 | ||
346 | return 0; | 424 | return 0; |
@@ -432,8 +510,6 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream, | |||
432 | struct snd_pcm_hw_params *hw_params) | 510 | struct snd_pcm_hw_params *hw_params) |
433 | { | 511 | { |
434 | struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream); | 512 | struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream); |
435 | struct videobuf_dmabuf *dma; | ||
436 | |||
437 | struct cx25821_audio_buffer *buf; | 513 | struct cx25821_audio_buffer *buf; |
438 | int ret; | 514 | int ret; |
439 | 515 | ||
@@ -457,19 +533,18 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream, | |||
457 | chip->period_size = AUDIO_LINE_SIZE; | 533 | chip->period_size = AUDIO_LINE_SIZE; |
458 | 534 | ||
459 | buf->bpl = chip->period_size; | 535 | buf->bpl = chip->period_size; |
536 | chip->buf = buf; | ||
460 | 537 | ||
461 | dma = &buf->dma; | 538 | ret = cx25821_alsa_dma_init(chip, |
462 | videobuf_dma_init(dma); | ||
463 | ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE, | ||
464 | (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT)); | 539 | (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT)); |
465 | if (ret < 0) | 540 | if (ret < 0) |
466 | goto error; | 541 | goto error; |
467 | 542 | ||
468 | ret = videobuf_dma_map(&chip->pci->dev, dma); | 543 | ret = cx25821_alsa_dma_map(chip); |
469 | if (ret < 0) | 544 | if (ret < 0) |
470 | goto error; | 545 | goto error; |
471 | 546 | ||
472 | ret = cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist, | 547 | ret = cx25821_risc_databuffer_audio(chip->pci, &buf->risc, buf->sglist, |
473 | chip->period_size, chip->num_periods, 1); | 548 | chip->period_size, chip->num_periods, 1); |
474 | if (ret < 0) { | 549 | if (ret < 0) { |
475 | pr_info("DEBUG: ERROR after cx25821_risc_databuffer_audio()\n"); | 550 | pr_info("DEBUG: ERROR after cx25821_risc_databuffer_audio()\n"); |
@@ -481,16 +556,14 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream, | |||
481 | buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); | 556 | buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
482 | buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ | 557 | buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ |
483 | 558 | ||
484 | chip->buf = buf; | 559 | substream->runtime->dma_area = chip->buf->vaddr; |
485 | chip->dma_risc = dma; | ||
486 | |||
487 | substream->runtime->dma_area = chip->dma_risc->vaddr; | ||
488 | substream->runtime->dma_bytes = chip->dma_size; | 560 | substream->runtime->dma_bytes = chip->dma_size; |
489 | substream->runtime->dma_addr = 0; | 561 | substream->runtime->dma_addr = 0; |
490 | 562 | ||
491 | return 0; | 563 | return 0; |
492 | 564 | ||
493 | error: | 565 | error: |
566 | chip->buf = NULL; | ||
494 | kfree(buf); | 567 | kfree(buf); |
495 | return ret; | 568 | return ret; |
496 | } | 569 | } |