| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ALSA PCM device for the |
|---|
| 3 | 4 | * ALSA interface to ivtv PCM capture streams |
|---|
| .. | .. |
|---|
| 6 | 7 | * Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com> |
|---|
| 7 | 8 | * |
|---|
| 8 | 9 | * Portions of this work were sponsored by ONELAN Limited for the cx18 driver |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 12 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | | - * (at your option) any later version. |
|---|
| 14 | | - * |
|---|
| 15 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | | - * GNU General Public License for more details. |
|---|
| 19 | 10 | */ |
|---|
| 20 | 11 | |
|---|
| 21 | 12 | #include "ivtv-driver.h" |
|---|
| .. | .. |
|---|
| 24 | 15 | #include "ivtv-fileops.h" |
|---|
| 25 | 16 | #include "ivtv-alsa.h" |
|---|
| 26 | 17 | #include "ivtv-alsa-pcm.h" |
|---|
| 27 | | - |
|---|
| 28 | | -#include <linux/vmalloc.h> |
|---|
| 29 | 18 | |
|---|
| 30 | 19 | #include <sound/core.h> |
|---|
| 31 | 20 | #include <sound/pcm.h> |
|---|
| .. | .. |
|---|
| 215 | 204 | return 0; |
|---|
| 216 | 205 | } |
|---|
| 217 | 206 | |
|---|
| 218 | | -static int snd_ivtv_pcm_ioctl(struct snd_pcm_substream *substream, |
|---|
| 219 | | - unsigned int cmd, void *arg) |
|---|
| 220 | | -{ |
|---|
| 221 | | - struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream); |
|---|
| 222 | | - int ret; |
|---|
| 223 | | - |
|---|
| 224 | | - snd_ivtv_lock(itvsc); |
|---|
| 225 | | - ret = snd_pcm_lib_ioctl(substream, cmd, arg); |
|---|
| 226 | | - snd_ivtv_unlock(itvsc); |
|---|
| 227 | | - return ret; |
|---|
| 228 | | -} |
|---|
| 229 | | - |
|---|
| 230 | | - |
|---|
| 231 | | -static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, |
|---|
| 232 | | - size_t size) |
|---|
| 233 | | -{ |
|---|
| 234 | | - struct snd_pcm_runtime *runtime = subs->runtime; |
|---|
| 235 | | - |
|---|
| 236 | | - dprintk("Allocating vbuffer\n"); |
|---|
| 237 | | - if (runtime->dma_area) { |
|---|
| 238 | | - if (runtime->dma_bytes > size) |
|---|
| 239 | | - return 0; |
|---|
| 240 | | - |
|---|
| 241 | | - vfree(runtime->dma_area); |
|---|
| 242 | | - } |
|---|
| 243 | | - runtime->dma_area = vmalloc(size); |
|---|
| 244 | | - if (!runtime->dma_area) |
|---|
| 245 | | - return -ENOMEM; |
|---|
| 246 | | - |
|---|
| 247 | | - runtime->dma_bytes = size; |
|---|
| 248 | | - |
|---|
| 249 | | - return 0; |
|---|
| 250 | | -} |
|---|
| 251 | | - |
|---|
| 252 | | -static int snd_ivtv_pcm_hw_params(struct snd_pcm_substream *substream, |
|---|
| 253 | | - struct snd_pcm_hw_params *params) |
|---|
| 254 | | -{ |
|---|
| 255 | | - dprintk("%s called\n", __func__); |
|---|
| 256 | | - |
|---|
| 257 | | - return snd_pcm_alloc_vmalloc_buffer(substream, |
|---|
| 258 | | - params_buffer_bytes(params)); |
|---|
| 259 | | -} |
|---|
| 260 | | - |
|---|
| 261 | | -static int snd_ivtv_pcm_hw_free(struct snd_pcm_substream *substream) |
|---|
| 262 | | -{ |
|---|
| 263 | | - struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream); |
|---|
| 264 | | - unsigned long flags; |
|---|
| 265 | | - unsigned char *dma_area = NULL; |
|---|
| 266 | | - |
|---|
| 267 | | - spin_lock_irqsave(&itvsc->slock, flags); |
|---|
| 268 | | - if (substream->runtime->dma_area) { |
|---|
| 269 | | - dprintk("freeing pcm capture region\n"); |
|---|
| 270 | | - dma_area = substream->runtime->dma_area; |
|---|
| 271 | | - substream->runtime->dma_area = NULL; |
|---|
| 272 | | - } |
|---|
| 273 | | - spin_unlock_irqrestore(&itvsc->slock, flags); |
|---|
| 274 | | - vfree(dma_area); |
|---|
| 275 | | - |
|---|
| 276 | | - return 0; |
|---|
| 277 | | -} |
|---|
| 278 | | - |
|---|
| 279 | 207 | static int snd_ivtv_pcm_prepare(struct snd_pcm_substream *substream) |
|---|
| 280 | 208 | { |
|---|
| 281 | 209 | struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream); |
|---|
| .. | .. |
|---|
| 305 | 233 | return hwptr_done; |
|---|
| 306 | 234 | } |
|---|
| 307 | 235 | |
|---|
| 308 | | -static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs, |
|---|
| 309 | | - unsigned long offset) |
|---|
| 310 | | -{ |
|---|
| 311 | | - void *pageptr = subs->runtime->dma_area + offset; |
|---|
| 312 | | - |
|---|
| 313 | | - return vmalloc_to_page(pageptr); |
|---|
| 314 | | -} |
|---|
| 315 | | - |
|---|
| 316 | 236 | static const struct snd_pcm_ops snd_ivtv_pcm_capture_ops = { |
|---|
| 317 | 237 | .open = snd_ivtv_pcm_capture_open, |
|---|
| 318 | 238 | .close = snd_ivtv_pcm_capture_close, |
|---|
| 319 | | - .ioctl = snd_ivtv_pcm_ioctl, |
|---|
| 320 | | - .hw_params = snd_ivtv_pcm_hw_params, |
|---|
| 321 | | - .hw_free = snd_ivtv_pcm_hw_free, |
|---|
| 322 | 239 | .prepare = snd_ivtv_pcm_prepare, |
|---|
| 323 | 240 | .trigger = snd_ivtv_pcm_trigger, |
|---|
| 324 | 241 | .pointer = snd_ivtv_pcm_pointer, |
|---|
| 325 | | - .page = snd_pcm_get_vmalloc_page, |
|---|
| 326 | 242 | }; |
|---|
| 327 | 243 | |
|---|
| 328 | 244 | int snd_ivtv_pcm_create(struct snd_ivtv_card *itvsc) |
|---|
| .. | .. |
|---|
| 348 | 264 | |
|---|
| 349 | 265 | snd_pcm_set_ops(sp, SNDRV_PCM_STREAM_CAPTURE, |
|---|
| 350 | 266 | &snd_ivtv_pcm_capture_ops); |
|---|
| 267 | + snd_pcm_set_managed_buffer_all(sp, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0); |
|---|
| 351 | 268 | sp->info_flags = 0; |
|---|
| 352 | 269 | sp->private_data = itvsc; |
|---|
| 353 | | - strlcpy(sp->name, itv->card_name, sizeof(sp->name)); |
|---|
| 270 | + strscpy(sp->name, itv->card_name, sizeof(sp->name)); |
|---|
| 354 | 271 | |
|---|
| 355 | 272 | return 0; |
|---|
| 356 | 273 | |
|---|