hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/mips/hal2.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for A2 audio system used in SGI machines
34 * Copyright (c) 2008 Thomas Bogendoerfer <tsbogend@alpha.fanken.de>
45 *
56 * Based on OSS code from Ladislav Michl <ladis@linux-mips.org>, which
67 * was based on code from Ulf Carlsson
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 version 2 as
10
- * published by the Free Software Foundation.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, write to the Free Software
19
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
- *
218 */
229 #include <linux/kernel.h>
2310 #include <linux/init.h>
....@@ -454,22 +441,24 @@
454441 hal2->adc.pbus.pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
455442 }
456443
457
-static int hal2_alloc_dmabuf(struct hal2_codec *codec)
444
+static int hal2_alloc_dmabuf(struct snd_hal2 *hal2, struct hal2_codec *codec,
445
+ enum dma_data_direction buffer_dir)
458446 {
447
+ struct device *dev = hal2->card->dev;
459448 struct hal2_desc *desc;
460449 dma_addr_t desc_dma, buffer_dma;
461450 int count = H2_BUF_SIZE / H2_BLOCK_SIZE;
462451 int i;
463452
464
- codec->buffer = dma_alloc_attrs(NULL, H2_BUF_SIZE, &buffer_dma,
465
- GFP_KERNEL, DMA_ATTR_NON_CONSISTENT);
453
+ codec->buffer = dma_alloc_noncoherent(dev, H2_BUF_SIZE, &buffer_dma,
454
+ buffer_dir, GFP_KERNEL);
466455 if (!codec->buffer)
467456 return -ENOMEM;
468
- desc = dma_alloc_attrs(NULL, count * sizeof(struct hal2_desc),
469
- &desc_dma, GFP_KERNEL, DMA_ATTR_NON_CONSISTENT);
457
+ desc = dma_alloc_noncoherent(dev, count * sizeof(struct hal2_desc),
458
+ &desc_dma, DMA_BIDIRECTIONAL, GFP_KERNEL);
470459 if (!desc) {
471
- dma_free_attrs(NULL, H2_BUF_SIZE, codec->buffer, buffer_dma,
472
- DMA_ATTR_NON_CONSISTENT);
460
+ dma_free_noncoherent(dev, H2_BUF_SIZE, codec->buffer, buffer_dma,
461
+ buffer_dir);
473462 return -ENOMEM;
474463 }
475464 codec->buffer_dma = buffer_dma;
....@@ -482,25 +471,30 @@
482471 desc_dma : desc_dma + (i + 1) * sizeof(struct hal2_desc);
483472 desc++;
484473 }
485
- dma_cache_sync(NULL, codec->desc, count * sizeof(struct hal2_desc),
486
- DMA_TO_DEVICE);
474
+ dma_sync_single_for_device(dev, codec->desc_dma,
475
+ count * sizeof(struct hal2_desc),
476
+ DMA_BIDIRECTIONAL);
487477 codec->desc_count = count;
488478 return 0;
489479 }
490480
491
-static void hal2_free_dmabuf(struct hal2_codec *codec)
481
+static void hal2_free_dmabuf(struct snd_hal2 *hal2, struct hal2_codec *codec,
482
+ enum dma_data_direction buffer_dir)
492483 {
493
- dma_free_attrs(NULL, codec->desc_count * sizeof(struct hal2_desc),
494
- codec->desc, codec->desc_dma, DMA_ATTR_NON_CONSISTENT);
495
- dma_free_attrs(NULL, H2_BUF_SIZE, codec->buffer, codec->buffer_dma,
496
- DMA_ATTR_NON_CONSISTENT);
484
+ struct device *dev = hal2->card->dev;
485
+
486
+ dma_free_noncoherent(dev, codec->desc_count * sizeof(struct hal2_desc),
487
+ codec->desc, codec->desc_dma, DMA_BIDIRECTIONAL);
488
+ dma_free_noncoherent(dev, H2_BUF_SIZE, codec->buffer, codec->buffer_dma,
489
+ buffer_dir);
497490 }
498491
499492 static const struct snd_pcm_hardware hal2_pcm_hw = {
500493 .info = (SNDRV_PCM_INFO_MMAP |
501494 SNDRV_PCM_INFO_MMAP_VALID |
502495 SNDRV_PCM_INFO_INTERLEAVED |
503
- SNDRV_PCM_INFO_BLOCK_TRANSFER),
496
+ SNDRV_PCM_INFO_BLOCK_TRANSFER |
497
+ SNDRV_PCM_INFO_SYNC_APPLPTR),
504498 .formats = SNDRV_PCM_FMTBIT_S16_BE,
505499 .rates = SNDRV_PCM_RATE_8000_48000,
506500 .rate_min = 8000,
....@@ -514,42 +508,20 @@
514508 .periods_max = 1024,
515509 };
516510
517
-static int hal2_pcm_hw_params(struct snd_pcm_substream *substream,
518
- struct snd_pcm_hw_params *params)
519
-{
520
- int err;
521
-
522
- err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
523
- if (err < 0)
524
- return err;
525
-
526
- return 0;
527
-}
528
-
529
-static int hal2_pcm_hw_free(struct snd_pcm_substream *substream)
530
-{
531
- return snd_pcm_lib_free_pages(substream);
532
-}
533
-
534511 static int hal2_playback_open(struct snd_pcm_substream *substream)
535512 {
536513 struct snd_pcm_runtime *runtime = substream->runtime;
537514 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
538
- int err;
539515
540516 runtime->hw = hal2_pcm_hw;
541
-
542
- err = hal2_alloc_dmabuf(&hal2->dac);
543
- if (err)
544
- return err;
545
- return 0;
517
+ return hal2_alloc_dmabuf(hal2, &hal2->dac, DMA_TO_DEVICE);
546518 }
547519
548520 static int hal2_playback_close(struct snd_pcm_substream *substream)
549521 {
550522 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
551523
552
- hal2_free_dmabuf(&hal2->dac);
524
+ hal2_free_dmabuf(hal2, &hal2->dac, DMA_TO_DEVICE);
553525 return 0;
554526 }
555527
....@@ -563,6 +535,8 @@
563535 dac->sample_rate = hal2_compute_rate(dac, runtime->rate);
564536 memset(&dac->pcm_indirect, 0, sizeof(dac->pcm_indirect));
565537 dac->pcm_indirect.hw_buffer_size = H2_BUF_SIZE;
538
+ dac->pcm_indirect.hw_queue_size = H2_BUF_SIZE / 2;
539
+ dac->pcm_indirect.hw_io = dac->buffer_dma;
566540 dac->pcm_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
567541 dac->substream = substream;
568542 hal2_setup_dac(hal2);
....@@ -575,9 +549,6 @@
575549
576550 switch (cmd) {
577551 case SNDRV_PCM_TRIGGER_START:
578
- hal2->dac.pcm_indirect.hw_io = hal2->dac.buffer_dma;
579
- hal2->dac.pcm_indirect.hw_data = 0;
580
- substream->ops->ack(substream);
581552 hal2_start_dac(hal2);
582553 break;
583554 case SNDRV_PCM_TRIGGER_STOP:
....@@ -606,7 +577,9 @@
606577 unsigned char *buf = hal2->dac.buffer + rec->hw_data;
607578
608579 memcpy(buf, substream->runtime->dma_area + rec->sw_data, bytes);
609
- dma_cache_sync(NULL, buf, bytes, DMA_TO_DEVICE);
580
+ dma_sync_single_for_device(hal2->card->dev,
581
+ hal2->dac.buffer_dma + rec->hw_data, bytes,
582
+ DMA_TO_DEVICE);
610583
611584 }
612585
....@@ -615,7 +588,6 @@
615588 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
616589 struct hal2_codec *dac = &hal2->dac;
617590
618
- dac->pcm_indirect.hw_queue_size = H2_BUF_SIZE / 2;
619591 return snd_pcm_indirect_playback_transfer(substream,
620592 &dac->pcm_indirect,
621593 hal2_playback_transfer);
....@@ -625,22 +597,16 @@
625597 {
626598 struct snd_pcm_runtime *runtime = substream->runtime;
627599 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
628
- struct hal2_codec *adc = &hal2->adc;
629
- int err;
630600
631601 runtime->hw = hal2_pcm_hw;
632
-
633
- err = hal2_alloc_dmabuf(adc);
634
- if (err)
635
- return err;
636
- return 0;
602
+ return hal2_alloc_dmabuf(hal2, &hal2->adc, DMA_FROM_DEVICE);
637603 }
638604
639605 static int hal2_capture_close(struct snd_pcm_substream *substream)
640606 {
641607 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
642608
643
- hal2_free_dmabuf(&hal2->adc);
609
+ hal2_free_dmabuf(hal2, &hal2->adc, DMA_FROM_DEVICE);
644610 return 0;
645611 }
646612
....@@ -655,6 +621,7 @@
655621 memset(&adc->pcm_indirect, 0, sizeof(adc->pcm_indirect));
656622 adc->pcm_indirect.hw_buffer_size = H2_BUF_SIZE;
657623 adc->pcm_indirect.hw_queue_size = H2_BUF_SIZE / 2;
624
+ adc->pcm_indirect.hw_io = adc->buffer_dma;
658625 adc->pcm_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
659626 adc->substream = substream;
660627 hal2_setup_adc(hal2);
....@@ -667,9 +634,6 @@
667634
668635 switch (cmd) {
669636 case SNDRV_PCM_TRIGGER_START:
670
- hal2->adc.pcm_indirect.hw_io = hal2->adc.buffer_dma;
671
- hal2->adc.pcm_indirect.hw_data = 0;
672
- printk(KERN_DEBUG "buffer_dma %x\n", hal2->adc.buffer_dma);
673637 hal2_start_adc(hal2);
674638 break;
675639 case SNDRV_PCM_TRIGGER_STOP:
....@@ -697,7 +661,9 @@
697661 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
698662 unsigned char *buf = hal2->adc.buffer + rec->hw_data;
699663
700
- dma_cache_sync(NULL, buf, bytes, DMA_FROM_DEVICE);
664
+ dma_sync_single_for_cpu(hal2->card->dev,
665
+ hal2->adc.buffer_dma + rec->hw_data, bytes,
666
+ DMA_FROM_DEVICE);
701667 memcpy(substream->runtime->dma_area + rec->sw_data, buf, bytes);
702668 }
703669
....@@ -714,9 +680,6 @@
714680 static const struct snd_pcm_ops hal2_playback_ops = {
715681 .open = hal2_playback_open,
716682 .close = hal2_playback_close,
717
- .ioctl = snd_pcm_lib_ioctl,
718
- .hw_params = hal2_pcm_hw_params,
719
- .hw_free = hal2_pcm_hw_free,
720683 .prepare = hal2_playback_prepare,
721684 .trigger = hal2_playback_trigger,
722685 .pointer = hal2_playback_pointer,
....@@ -726,9 +689,6 @@
726689 static const struct snd_pcm_ops hal2_capture_ops = {
727690 .open = hal2_capture_open,
728691 .close = hal2_capture_close,
729
- .ioctl = snd_pcm_lib_ioctl,
730
- .hw_params = hal2_pcm_hw_params,
731
- .hw_free = hal2_pcm_hw_free,
732692 .prepare = hal2_capture_prepare,
733693 .trigger = hal2_capture_trigger,
734694 .pointer = hal2_capture_pointer,
....@@ -753,9 +713,8 @@
753713 &hal2_playback_ops);
754714 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
755715 &hal2_capture_ops);
756
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
757
- snd_dma_continuous_data(GFP_KERNEL),
758
- 0, 1024 * 1024);
716
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
717
+ NULL, 0, 1024 * 1024);
759718
760719 return 0;
761720 }
....@@ -769,7 +728,7 @@
769728 return 0;
770729 }
771730
772
-static struct snd_device_ops hal2_ops = {
731
+static const struct snd_device_ops hal2_ops = {
773732 .dev_free = hal2_dev_free,
774733 };
775734