| .. | .. |
|---|
| 9 | 9 | |
|---|
| 10 | 10 | #include <linux/init.h> |
|---|
| 11 | 11 | #include <linux/kernel.h> |
|---|
| 12 | | -#include <linux/vmalloc.h> |
|---|
| 13 | 12 | #include <linux/delay.h> |
|---|
| 14 | 13 | |
|---|
| 15 | 14 | #include <media/v4l2-device.h> |
|---|
| .. | .. |
|---|
| 238 | 237 | return 0; |
|---|
| 239 | 238 | } |
|---|
| 240 | 239 | |
|---|
| 241 | | -static int snd_cobalt_pcm_ioctl(struct snd_pcm_substream *substream, |
|---|
| 242 | | - unsigned int cmd, void *arg) |
|---|
| 243 | | -{ |
|---|
| 244 | | - return snd_pcm_lib_ioctl(substream, cmd, arg); |
|---|
| 245 | | -} |
|---|
| 246 | | - |
|---|
| 247 | | - |
|---|
| 248 | | -static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, |
|---|
| 249 | | - size_t size) |
|---|
| 250 | | -{ |
|---|
| 251 | | - struct snd_pcm_runtime *runtime = subs->runtime; |
|---|
| 252 | | - |
|---|
| 253 | | - dprintk("Allocating vbuffer\n"); |
|---|
| 254 | | - if (runtime->dma_area) { |
|---|
| 255 | | - if (runtime->dma_bytes > size) |
|---|
| 256 | | - return 0; |
|---|
| 257 | | - |
|---|
| 258 | | - vfree(runtime->dma_area); |
|---|
| 259 | | - } |
|---|
| 260 | | - runtime->dma_area = vmalloc(size); |
|---|
| 261 | | - if (!runtime->dma_area) |
|---|
| 262 | | - return -ENOMEM; |
|---|
| 263 | | - |
|---|
| 264 | | - runtime->dma_bytes = size; |
|---|
| 265 | | - |
|---|
| 266 | | - return 0; |
|---|
| 267 | | -} |
|---|
| 268 | | - |
|---|
| 269 | | -static int snd_cobalt_pcm_hw_params(struct snd_pcm_substream *substream, |
|---|
| 270 | | - struct snd_pcm_hw_params *params) |
|---|
| 271 | | -{ |
|---|
| 272 | | - dprintk("%s called\n", __func__); |
|---|
| 273 | | - |
|---|
| 274 | | - return snd_pcm_alloc_vmalloc_buffer(substream, |
|---|
| 275 | | - params_buffer_bytes(params)); |
|---|
| 276 | | -} |
|---|
| 277 | | - |
|---|
| 278 | | -static int snd_cobalt_pcm_hw_free(struct snd_pcm_substream *substream) |
|---|
| 279 | | -{ |
|---|
| 280 | | - if (substream->runtime->dma_area) { |
|---|
| 281 | | - dprintk("freeing pcm capture region\n"); |
|---|
| 282 | | - vfree(substream->runtime->dma_area); |
|---|
| 283 | | - substream->runtime->dma_area = NULL; |
|---|
| 284 | | - } |
|---|
| 285 | | - |
|---|
| 286 | | - return 0; |
|---|
| 287 | | -} |
|---|
| 288 | | - |
|---|
| 289 | 240 | static int snd_cobalt_pcm_prepare(struct snd_pcm_substream *substream) |
|---|
| 290 | 241 | { |
|---|
| 291 | 242 | struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream); |
|---|
| .. | .. |
|---|
| 490 | 441 | substream->runtime->buffer_size; |
|---|
| 491 | 442 | } |
|---|
| 492 | 443 | |
|---|
| 493 | | -static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs, |
|---|
| 494 | | - unsigned long offset) |
|---|
| 495 | | -{ |
|---|
| 496 | | - void *pageptr = subs->runtime->dma_area + offset; |
|---|
| 497 | | - |
|---|
| 498 | | - return vmalloc_to_page(pageptr); |
|---|
| 499 | | -} |
|---|
| 500 | | - |
|---|
| 501 | 444 | static const struct snd_pcm_ops snd_cobalt_pcm_capture_ops = { |
|---|
| 502 | 445 | .open = snd_cobalt_pcm_capture_open, |
|---|
| 503 | 446 | .close = snd_cobalt_pcm_capture_close, |
|---|
| 504 | | - .ioctl = snd_cobalt_pcm_ioctl, |
|---|
| 505 | | - .hw_params = snd_cobalt_pcm_hw_params, |
|---|
| 506 | | - .hw_free = snd_cobalt_pcm_hw_free, |
|---|
| 507 | 447 | .prepare = snd_cobalt_pcm_prepare, |
|---|
| 508 | 448 | .trigger = snd_cobalt_pcm_trigger, |
|---|
| 509 | 449 | .pointer = snd_cobalt_pcm_pointer, |
|---|
| 510 | | - .page = snd_pcm_get_vmalloc_page, |
|---|
| 511 | 450 | }; |
|---|
| 512 | 451 | |
|---|
| 513 | 452 | static const struct snd_pcm_ops snd_cobalt_pcm_playback_ops = { |
|---|
| 514 | 453 | .open = snd_cobalt_pcm_playback_open, |
|---|
| 515 | 454 | .close = snd_cobalt_pcm_playback_close, |
|---|
| 516 | | - .ioctl = snd_cobalt_pcm_ioctl, |
|---|
| 517 | | - .hw_params = snd_cobalt_pcm_hw_params, |
|---|
| 518 | | - .hw_free = snd_cobalt_pcm_hw_free, |
|---|
| 519 | 455 | .prepare = snd_cobalt_pcm_pb_prepare, |
|---|
| 520 | 456 | .trigger = snd_cobalt_pcm_pb_trigger, |
|---|
| 521 | 457 | .pointer = snd_cobalt_pcm_pb_pointer, |
|---|
| 522 | | - .page = snd_pcm_get_vmalloc_page, |
|---|
| 523 | 458 | }; |
|---|
| 524 | 459 | |
|---|
| 525 | 460 | int snd_cobalt_pcm_create(struct snd_cobalt_card *cobsc) |
|---|
| .. | .. |
|---|
| 555 | 490 | |
|---|
| 556 | 491 | snd_pcm_set_ops(sp, SNDRV_PCM_STREAM_CAPTURE, |
|---|
| 557 | 492 | &snd_cobalt_pcm_capture_ops); |
|---|
| 493 | + snd_pcm_set_managed_buffer_all(sp, SNDRV_DMA_TYPE_VMALLOC, |
|---|
| 494 | + NULL, 0, 0); |
|---|
| 558 | 495 | sp->info_flags = 0; |
|---|
| 559 | 496 | sp->private_data = cobsc; |
|---|
| 560 | | - strlcpy(sp->name, "cobalt", sizeof(sp->name)); |
|---|
| 497 | + strscpy(sp->name, "cobalt", sizeof(sp->name)); |
|---|
| 561 | 498 | } else { |
|---|
| 562 | 499 | cobalt_s_bit_sysctrl(cobalt, |
|---|
| 563 | 500 | COBALT_SYS_CTRL_AUDIO_OPP_RESETN_BIT, 0); |
|---|
| .. | .. |
|---|
| 579 | 516 | |
|---|
| 580 | 517 | snd_pcm_set_ops(sp, SNDRV_PCM_STREAM_PLAYBACK, |
|---|
| 581 | 518 | &snd_cobalt_pcm_playback_ops); |
|---|
| 519 | + snd_pcm_set_managed_buffer_all(sp, SNDRV_DMA_TYPE_VMALLOC, |
|---|
| 520 | + NULL, 0, 0); |
|---|
| 582 | 521 | sp->info_flags = 0; |
|---|
| 583 | 522 | sp->private_data = cobsc; |
|---|
| 584 | | - strlcpy(sp->name, "cobalt", sizeof(sp->name)); |
|---|
| 523 | + strscpy(sp->name, "cobalt", sizeof(sp->name)); |
|---|
| 585 | 524 | } |
|---|
| 586 | 525 | |
|---|
| 587 | 526 | return 0; |
|---|