forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/usb/cx231xx/cx231xx-audio.c
....@@ -1,19 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Conexant Cx231xx audio extension
34 *
45 * Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
56 * Based on em28xx driver
6
- *
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
177 */
188
199 #include "cx231xx.h"
....@@ -23,8 +13,6 @@
2313 #include <linux/spinlock.h>
2414 #include <linux/soundcard.h>
2515 #include <linux/slab.h>
26
-#include <linux/vmalloc.h>
27
-#include <linux/proc_fs.h>
2816 #include <linux/module.h>
2917 #include <sound/core.h>
3018 #include <sound/pcm.h>
....@@ -383,28 +371,6 @@
383371 return errCode;
384372 }
385373
386
-static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
387
- size_t size)
388
-{
389
- struct snd_pcm_runtime *runtime = subs->runtime;
390
- struct cx231xx *dev = snd_pcm_substream_chip(subs);
391
-
392
- dev_dbg(dev->dev, "Allocating vbuffer\n");
393
- if (runtime->dma_area) {
394
- if (runtime->dma_bytes > size)
395
- return 0;
396
-
397
- vfree(runtime->dma_area);
398
- }
399
- runtime->dma_area = vmalloc(size);
400
- if (!runtime->dma_area)
401
- return -ENOMEM;
402
-
403
- runtime->dma_bytes = size;
404
-
405
- return 0;
406
-}
407
-
408374 static const struct snd_pcm_hardware snd_cx231xx_hw_capture = {
409375 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
410376 SNDRV_PCM_INFO_MMAP |
....@@ -495,11 +461,6 @@
495461 }
496462
497463 dev->adev.users--;
498
- if (substream->runtime->dma_area) {
499
- dev_dbg(dev->dev, "freeing\n");
500
- vfree(substream->runtime->dma_area);
501
- substream->runtime->dma_area = NULL;
502
- }
503464 mutex_unlock(&dev->lock);
504465
505466 if (dev->adev.users == 0 && dev->adev.shutdown == 1) {
....@@ -512,44 +473,6 @@
512473 schedule_work(&dev->wq_trigger);
513474 }
514475 }
515
- return 0;
516
-}
517
-
518
-static int snd_cx231xx_hw_capture_params(struct snd_pcm_substream *substream,
519
- struct snd_pcm_hw_params *hw_params)
520
-{
521
- struct cx231xx *dev = snd_pcm_substream_chip(substream);
522
- int ret;
523
-
524
- dev_dbg(dev->dev, "Setting capture parameters\n");
525
-
526
- ret = snd_pcm_alloc_vmalloc_buffer(substream,
527
- params_buffer_bytes(hw_params));
528
-#if 0
529
- /* TODO: set up cx231xx audio chip to deliver the correct audio format,
530
- current default is 48000hz multiplexed => 96000hz mono
531
- which shouldn't matter since analogue TV only supports mono */
532
- unsigned int channels, rate, format;
533
-
534
- format = params_format(hw_params);
535
- rate = params_rate(hw_params);
536
- channels = params_channels(hw_params);
537
-#endif
538
-
539
- return ret;
540
-}
541
-
542
-static int snd_cx231xx_hw_capture_free(struct snd_pcm_substream *substream)
543
-{
544
- struct cx231xx *dev = snd_pcm_substream_chip(substream);
545
-
546
- dev_dbg(dev->dev, "Stop capture, if needed\n");
547
-
548
- if (atomic_read(&dev->stream_started) > 0) {
549
- atomic_set(&dev->stream_started, 0);
550
- schedule_work(&dev->wq_trigger);
551
- }
552
-
553476 return 0;
554477 }
555478
....@@ -625,24 +548,12 @@
625548 return hwptr_done;
626549 }
627550
628
-static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
629
- unsigned long offset)
630
-{
631
- void *pageptr = subs->runtime->dma_area + offset;
632
-
633
- return vmalloc_to_page(pageptr);
634
-}
635
-
636551 static const struct snd_pcm_ops snd_cx231xx_pcm_capture = {
637552 .open = snd_cx231xx_capture_open,
638553 .close = snd_cx231xx_pcm_close,
639
- .ioctl = snd_pcm_lib_ioctl,
640
- .hw_params = snd_cx231xx_hw_capture_params,
641
- .hw_free = snd_cx231xx_hw_capture_free,
642554 .prepare = snd_cx231xx_prepare,
643555 .trigger = snd_cx231xx_capture_trigger,
644556 .pointer = snd_cx231xx_capture_pointer,
645
- .page = snd_pcm_get_vmalloc_page,
646557 };
647558
648559 static int cx231xx_audio_init(struct cx231xx *dev)
....@@ -677,12 +588,13 @@
677588
678589 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
679590 &snd_cx231xx_pcm_capture);
591
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
680592 pcm->info_flags = 0;
681593 pcm->private_data = dev;
682
- strcpy(pcm->name, "Conexant cx231xx Capture");
683
- strcpy(card->driver, "Cx231xx-Audio");
684
- strcpy(card->shortname, "Cx231xx Audio");
685
- strcpy(card->longname, "Conexant cx231xx Audio");
594
+ strscpy(pcm->name, "Conexant cx231xx Capture", sizeof(pcm->name));
595
+ strscpy(card->driver, "Cx231xx-Audio", sizeof(card->driver));
596
+ strscpy(card->shortname, "Cx231xx Audio", sizeof(card->shortname));
597
+ strscpy(card->longname, "Conexant cx231xx Audio", sizeof(card->longname));
686598
687599 INIT_WORK(&dev->wq_trigger, audio_trigger);
688600