diff options
Diffstat (limited to 'sound/pci/asihpi/asihpi.c')
-rw-r--r-- | sound/pci/asihpi/asihpi.c | 328 |
1 files changed, 142 insertions, 186 deletions
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c index f8ccc9677c6f..2ca6f4f85b41 100644 --- a/sound/pci/asihpi/asihpi.c +++ b/sound/pci/asihpi/asihpi.c | |||
@@ -42,10 +42,29 @@ | |||
42 | #include <sound/tlv.h> | 42 | #include <sound/tlv.h> |
43 | #include <sound/hwdep.h> | 43 | #include <sound/hwdep.h> |
44 | 44 | ||
45 | |||
45 | MODULE_LICENSE("GPL"); | 46 | MODULE_LICENSE("GPL"); |
46 | MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>"); | 47 | MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>"); |
47 | MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx"); | 48 | MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx"); |
48 | 49 | ||
50 | #if defined CONFIG_SND_DEBUG | ||
51 | /* copied from pcm_lib.c, hope later patch will make that version public | ||
52 | and this copy can be removed */ | ||
53 | static void pcm_debug_name(struct snd_pcm_substream *substream, | ||
54 | char *name, size_t len) | ||
55 | { | ||
56 | snprintf(name, len, "pcmC%dD%d%c:%d", | ||
57 | substream->pcm->card->number, | ||
58 | substream->pcm->device, | ||
59 | substream->stream ? 'c' : 'p', | ||
60 | substream->number); | ||
61 | } | ||
62 | #define DEBUG_NAME(substream, name) char name[16]; pcm_debug_name(substream, name, sizeof(name)) | ||
63 | #else | ||
64 | #define pcm_debug_name(s, n, l) do { } while (0) | ||
65 | #define DEBUG_NAME(name, substream) do { } while (0) | ||
66 | #endif | ||
67 | |||
49 | #if defined CONFIG_SND_DEBUG_VERBOSE | 68 | #if defined CONFIG_SND_DEBUG_VERBOSE |
50 | /** | 69 | /** |
51 | * snd_printddd - very verbose debug printk | 70 | * snd_printddd - very verbose debug printk |
@@ -58,7 +77,7 @@ MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx"); | |||
58 | #define snd_printddd(format, args...) \ | 77 | #define snd_printddd(format, args...) \ |
59 | __snd_printk(3, __FILE__, __LINE__, format, ##args) | 78 | __snd_printk(3, __FILE__, __LINE__, format, ##args) |
60 | #else | 79 | #else |
61 | #define snd_printddd(format, args...) do { } while (0) | 80 | #define snd_printddd(format, args...) do { } while (0) |
62 | #endif | 81 | #endif |
63 | 82 | ||
64 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */ | 83 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */ |
@@ -101,13 +120,6 @@ static int adapter_fs = DEFAULT_SAMPLERATE; | |||
101 | #define PERIOD_BYTES_MIN 2048 | 120 | #define PERIOD_BYTES_MIN 2048 |
102 | #define BUFFER_BYTES_MAX (512 * 1024) | 121 | #define BUFFER_BYTES_MAX (512 * 1024) |
103 | 122 | ||
104 | /* convert stream to character */ | ||
105 | #define SCHR(s) ((s == SNDRV_PCM_STREAM_PLAYBACK) ? 'P' : 'C') | ||
106 | |||
107 | /*#define TIMER_MILLISECONDS 20 | ||
108 | #define FORCE_TIMER_JIFFIES ((TIMER_MILLISECONDS * HZ + 999)/1000) | ||
109 | */ | ||
110 | |||
111 | #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7) | 123 | #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7) |
112 | 124 | ||
113 | struct clk_source { | 125 | struct clk_source { |
@@ -136,7 +148,7 @@ struct snd_card_asihpi { | |||
136 | u32 h_mixer; | 148 | u32 h_mixer; |
137 | struct clk_cache cc; | 149 | struct clk_cache cc; |
138 | 150 | ||
139 | u16 support_mmap; | 151 | u16 can_dma; |
140 | u16 support_grouping; | 152 | u16 support_grouping; |
141 | u16 support_mrx; | 153 | u16 support_mrx; |
142 | u16 update_interval_frames; | 154 | u16 update_interval_frames; |
@@ -155,6 +167,7 @@ struct snd_card_asihpi_pcm { | |||
155 | unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */ | 167 | unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */ |
156 | unsigned int pcm_buf_dma_ofs; /* DMA R/W offset in buffer */ | 168 | unsigned int pcm_buf_dma_ofs; /* DMA R/W offset in buffer */ |
157 | unsigned int pcm_buf_elapsed_dma_ofs; /* DMA R/W offset in buffer */ | 169 | unsigned int pcm_buf_elapsed_dma_ofs; /* DMA R/W offset in buffer */ |
170 | unsigned int drained_count; | ||
158 | struct snd_pcm_substream *substream; | 171 | struct snd_pcm_substream *substream; |
159 | u32 h_stream; | 172 | u32 h_stream; |
160 | struct hpi_format format; | 173 | struct hpi_format format; |
@@ -288,19 +301,26 @@ static u16 handle_error(u16 err, int line, char *filename) | |||
288 | #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__) | 301 | #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__) |
289 | 302 | ||
290 | /***************************** GENERAL PCM ****************/ | 303 | /***************************** GENERAL PCM ****************/ |
291 | static void print_hwparams(struct snd_pcm_hw_params *p) | 304 | |
305 | static void print_hwparams(struct snd_pcm_substream *substream, | ||
306 | struct snd_pcm_hw_params *p) | ||
292 | { | 307 | { |
293 | snd_printd("HWPARAMS \n"); | 308 | DEBUG_NAME(substream, name); |
294 | snd_printd("samplerate %d \n", params_rate(p)); | 309 | snd_printd("%s HWPARAMS\n", name); |
295 | snd_printd("Channels %d \n", params_channels(p)); | 310 | snd_printd(" samplerate %d Hz\n", params_rate(p)); |
296 | snd_printd("Format %d \n", params_format(p)); | 311 | snd_printd(" channels %d\n", params_channels(p)); |
297 | snd_printd("subformat %d \n", params_subformat(p)); | 312 | snd_printd(" format %d\n", params_format(p)); |
298 | snd_printd("Buffer bytes %d \n", params_buffer_bytes(p)); | 313 | snd_printd(" subformat %d\n", params_subformat(p)); |
299 | snd_printd("Period bytes %d \n", params_period_bytes(p)); | 314 | snd_printd(" buffer %d B\n", params_buffer_bytes(p)); |
300 | snd_printd("access %d \n", params_access(p)); | 315 | snd_printd(" period %d B\n", params_period_bytes(p)); |
301 | snd_printd("period_size %d \n", params_period_size(p)); | 316 | snd_printd(" access %d\n", params_access(p)); |
302 | snd_printd("periods %d \n", params_periods(p)); | 317 | snd_printd(" period_size %d\n", params_period_size(p)); |
303 | snd_printd("buffer_size %d \n", params_buffer_size(p)); | 318 | snd_printd(" periods %d\n", params_periods(p)); |
319 | snd_printd(" buffer_size %d\n", params_buffer_size(p)); | ||
320 | snd_printd(" %d B/s\n", params_rate(p) * | ||
321 | params_channels(p) * | ||
322 | snd_pcm_format_width(params_format(p)) / 8); | ||
323 | |||
304 | } | 324 | } |
305 | 325 | ||
306 | static snd_pcm_format_t hpi_to_alsa_formats[] = { | 326 | static snd_pcm_format_t hpi_to_alsa_formats[] = { |
@@ -451,7 +471,7 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream, | |||
451 | int width; | 471 | int width; |
452 | unsigned int bytes_per_sec; | 472 | unsigned int bytes_per_sec; |
453 | 473 | ||
454 | print_hwparams(params); | 474 | print_hwparams(substream, params); |
455 | err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); | 475 | err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
456 | if (err < 0) | 476 | if (err < 0) |
457 | return err; | 477 | return err; |
@@ -459,10 +479,6 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream, | |||
459 | if (err) | 479 | if (err) |
460 | return err; | 480 | return err; |
461 | 481 | ||
462 | snd_printdd("format %d, %d chans, %d_hz\n", | ||
463 | format, params_channels(params), | ||
464 | params_rate(params)); | ||
465 | |||
466 | hpi_handle_error(hpi_format_create(&dpcm->format, | 482 | hpi_handle_error(hpi_format_create(&dpcm->format, |
467 | params_channels(params), | 483 | params_channels(params), |
468 | format, params_rate(params), 0, 0)); | 484 | format, params_rate(params), 0, 0)); |
@@ -477,8 +493,7 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream, | |||
477 | } | 493 | } |
478 | 494 | ||
479 | dpcm->hpi_buffer_attached = 0; | 495 | dpcm->hpi_buffer_attached = 0; |
480 | if (card->support_mmap) { | 496 | if (card->can_dma) { |
481 | |||
482 | err = hpi_stream_host_buffer_attach(dpcm->h_stream, | 497 | err = hpi_stream_host_buffer_attach(dpcm->h_stream, |
483 | params_buffer_bytes(params), runtime->dma_addr); | 498 | params_buffer_bytes(params), runtime->dma_addr); |
484 | if (err == 0) { | 499 | if (err == 0) { |
@@ -509,8 +524,6 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream, | |||
509 | dpcm->bytes_per_sec = bytes_per_sec; | 524 | dpcm->bytes_per_sec = bytes_per_sec; |
510 | dpcm->buffer_bytes = params_buffer_bytes(params); | 525 | dpcm->buffer_bytes = params_buffer_bytes(params); |
511 | dpcm->period_bytes = params_period_bytes(params); | 526 | dpcm->period_bytes = params_period_bytes(params); |
512 | snd_printdd("buffer_bytes=%d, period_bytes=%d, bps=%d\n", | ||
513 | dpcm->buffer_bytes, dpcm->period_bytes, bytes_per_sec); | ||
514 | 527 | ||
515 | return 0; | 528 | return 0; |
516 | } | 529 | } |
@@ -564,9 +577,10 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream, | |||
564 | struct snd_card_asihpi *card = snd_pcm_substream_chip(substream); | 577 | struct snd_card_asihpi *card = snd_pcm_substream_chip(substream); |
565 | struct snd_pcm_substream *s; | 578 | struct snd_pcm_substream *s; |
566 | u16 e; | 579 | u16 e; |
580 | DEBUG_NAME(substream, name); | ||
581 | |||
582 | snd_printdd("%s trigger\n", name); | ||
567 | 583 | ||
568 | snd_printdd("%c%d trigger\n", | ||
569 | SCHR(substream->stream), substream->number); | ||
570 | switch (cmd) { | 584 | switch (cmd) { |
571 | case SNDRV_PCM_TRIGGER_START: | 585 | case SNDRV_PCM_TRIGGER_START: |
572 | snd_pcm_group_for_each_entry(s, substream) { | 586 | snd_pcm_group_for_each_entry(s, substream) { |
@@ -580,8 +594,8 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream, | |||
580 | if (substream->stream != s->stream) | 594 | if (substream->stream != s->stream) |
581 | continue; | 595 | continue; |
582 | 596 | ||
583 | if ((s->stream == SNDRV_PCM_STREAM_PLAYBACK) && | 597 | ds->drained_count = 0; |
584 | (card->support_mmap)) { | 598 | if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
585 | /* How do I know how much valid data is present | 599 | /* How do I know how much valid data is present |
586 | * in buffer? Must be at least one period! | 600 | * in buffer? Must be at least one period! |
587 | * Guessing 2 periods, but if | 601 | * Guessing 2 periods, but if |
@@ -599,9 +613,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream, | |||
599 | } | 613 | } |
600 | 614 | ||
601 | if (card->support_grouping) { | 615 | if (card->support_grouping) { |
602 | snd_printdd("\t%c%d group\n", | 616 | snd_printdd("%d group\n", s->number); |
603 | SCHR(s->stream), | ||
604 | s->number); | ||
605 | e = hpi_stream_group_add( | 617 | e = hpi_stream_group_add( |
606 | dpcm->h_stream, | 618 | dpcm->h_stream, |
607 | ds->h_stream); | 619 | ds->h_stream); |
@@ -618,7 +630,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream, | |||
618 | /* start the master stream */ | 630 | /* start the master stream */ |
619 | snd_card_asihpi_pcm_timer_start(substream); | 631 | snd_card_asihpi_pcm_timer_start(substream); |
620 | if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) || | 632 | if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) || |
621 | !card->support_mmap) | 633 | !card->can_dma) |
622 | hpi_handle_error(hpi_stream_start(dpcm->h_stream)); | 634 | hpi_handle_error(hpi_stream_start(dpcm->h_stream)); |
623 | break; | 635 | break; |
624 | 636 | ||
@@ -636,9 +648,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream, | |||
636 | s->runtime->status->state = SNDRV_PCM_STATE_SETUP; | 648 | s->runtime->status->state = SNDRV_PCM_STATE_SETUP; |
637 | 649 | ||
638 | if (card->support_grouping) { | 650 | if (card->support_grouping) { |
639 | snd_printdd("\t%c%d group\n", | 651 | snd_printdd("%d group\n", s->number); |
640 | SCHR(s->stream), | ||
641 | s->number); | ||
642 | snd_pcm_trigger_done(s, substream); | 652 | snd_pcm_trigger_done(s, substream); |
643 | } else | 653 | } else |
644 | break; | 654 | break; |
@@ -732,9 +742,9 @@ static void snd_card_asihpi_timer_function(unsigned long data) | |||
732 | int loops = 0; | 742 | int loops = 0; |
733 | u16 state; | 743 | u16 state; |
734 | u32 buffer_size, bytes_avail, samples_played, on_card_bytes; | 744 | u32 buffer_size, bytes_avail, samples_played, on_card_bytes; |
745 | DEBUG_NAME(substream, name); | ||
735 | 746 | ||
736 | snd_printdd("%c%d snd_card_asihpi_timer_function\n", | 747 | snd_printdd("%s snd_card_asihpi_timer_function\n", name); |
737 | SCHR(substream->stream), substream->number); | ||
738 | 748 | ||
739 | /* find minimum newdata and buffer pos in group */ | 749 | /* find minimum newdata and buffer pos in group */ |
740 | snd_pcm_group_for_each_entry(s, substream) { | 750 | snd_pcm_group_for_each_entry(s, substream) { |
@@ -756,6 +766,9 @@ static void snd_card_asihpi_timer_function(unsigned long data) | |||
756 | /* number of bytes in on-card buffer */ | 766 | /* number of bytes in on-card buffer */ |
757 | runtime->delay = on_card_bytes; | 767 | runtime->delay = on_card_bytes; |
758 | 768 | ||
769 | if (!card->can_dma) | ||
770 | on_card_bytes = bytes_avail; | ||
771 | |||
759 | if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 772 | if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
760 | pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail; | 773 | pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail; |
761 | if (state == HPI_STATE_STOPPED) { | 774 | if (state == HPI_STATE_STOPPED) { |
@@ -763,12 +776,18 @@ static void snd_card_asihpi_timer_function(unsigned long data) | |||
763 | (on_card_bytes < ds->pcm_buf_host_rw_ofs)) { | 776 | (on_card_bytes < ds->pcm_buf_host_rw_ofs)) { |
764 | hpi_handle_error(hpi_stream_start(ds->h_stream)); | 777 | hpi_handle_error(hpi_stream_start(ds->h_stream)); |
765 | snd_printdd("P%d start\n", s->number); | 778 | snd_printdd("P%d start\n", s->number); |
779 | ds->drained_count = 0; | ||
766 | } | 780 | } |
767 | } else if (state == HPI_STATE_DRAINED) { | 781 | } else if (state == HPI_STATE_DRAINED) { |
768 | snd_printd(KERN_WARNING "P%d drained\n", | 782 | snd_printd(KERN_WARNING "P%d drained\n", |
769 | s->number); | 783 | s->number); |
770 | /*snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN); | 784 | ds->drained_count++; |
771 | continue; */ | 785 | if (ds->drained_count > 2) { |
786 | snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN); | ||
787 | continue; | ||
788 | } | ||
789 | } else { | ||
790 | ds->drained_count = 0; | ||
772 | } | 791 | } |
773 | } else | 792 | } else |
774 | pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs; | 793 | pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs; |
@@ -786,16 +805,18 @@ static void snd_card_asihpi_timer_function(unsigned long data) | |||
786 | newdata); | 805 | newdata); |
787 | } | 806 | } |
788 | 807 | ||
789 | snd_printdd("hw_ptr x%04lX, appl_ptr x%04lX\n", | 808 | snd_printdd("hw_ptr 0x%04lX, appl_ptr 0x%04lX\n", |
790 | (unsigned long)frames_to_bytes(runtime, | 809 | (unsigned long)frames_to_bytes(runtime, |
791 | runtime->status->hw_ptr), | 810 | runtime->status->hw_ptr), |
792 | (unsigned long)frames_to_bytes(runtime, | 811 | (unsigned long)frames_to_bytes(runtime, |
793 | runtime->control->appl_ptr)); | 812 | runtime->control->appl_ptr)); |
794 | 813 | ||
795 | snd_printdd("%d %c%d S=%d, rw=%04X, dma=x%04X, left=x%04X," | 814 | snd_printdd("%d S=%d, " |
796 | " aux=x%04X space=x%04X\n", | 815 | "rw=0x%04X, dma=0x%04X, left=0x%04X, " |
797 | loops, SCHR(s->stream), s->number, | 816 | "aux=0x%04X space=0x%04X\n", |
798 | state, ds->pcm_buf_host_rw_ofs, pcm_buf_dma_ofs, (int)bytes_avail, | 817 | s->number, state, |
818 | ds->pcm_buf_host_rw_ofs, pcm_buf_dma_ofs, | ||
819 | (int)bytes_avail, | ||
799 | (int)on_card_bytes, buffer_size-bytes_avail); | 820 | (int)on_card_bytes, buffer_size-bytes_avail); |
800 | loops++; | 821 | loops++; |
801 | } | 822 | } |
@@ -814,7 +835,7 @@ static void snd_card_asihpi_timer_function(unsigned long data) | |||
814 | 835 | ||
815 | next_jiffies = max(next_jiffies, 1U); | 836 | next_jiffies = max(next_jiffies, 1U); |
816 | dpcm->timer.expires = jiffies + next_jiffies; | 837 | dpcm->timer.expires = jiffies + next_jiffies; |
817 | snd_printdd("jif %d buf pos x%04X newdata x%04X xfer x%04X\n", | 838 | snd_printdd("jif %d buf pos 0x%04X newdata 0x%04X xfer 0x%04X\n", |
818 | next_jiffies, pcm_buf_dma_ofs, newdata, xfercount); | 839 | next_jiffies, pcm_buf_dma_ofs, newdata, xfercount); |
819 | 840 | ||
820 | snd_pcm_group_for_each_entry(s, substream) { | 841 | snd_pcm_group_for_each_entry(s, substream) { |
@@ -826,30 +847,63 @@ static void snd_card_asihpi_timer_function(unsigned long data) | |||
826 | 847 | ||
827 | ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs; | 848 | ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs; |
828 | 849 | ||
829 | if (xfercount && (on_card_bytes <= ds->period_bytes)) { | 850 | if (xfercount && |
830 | if (card->support_mmap) { | 851 | /* Limit use of on card fifo for playback */ |
831 | if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 852 | ((on_card_bytes <= ds->period_bytes) || |
832 | snd_printddd("P%d write x%04x\n", | 853 | (s->stream == SNDRV_PCM_STREAM_CAPTURE))) |
854 | |||
855 | { | ||
856 | |||
857 | unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes; | ||
858 | unsigned int xfer1, xfer2; | ||
859 | char *pd = &s->runtime->dma_area[buf_ofs]; | ||
860 | |||
861 | if (card->can_dma) { /* buffer wrap is handled at lower level */ | ||
862 | xfer1 = xfercount; | ||
863 | xfer2 = 0; | ||
864 | } else { | ||
865 | xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs); | ||
866 | xfer2 = xfercount - xfer1; | ||
867 | } | ||
868 | |||
869 | if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
870 | snd_printddd("P%d write1 0x%04X 0x%04X\n", | ||
871 | s->number, xfer1, buf_ofs); | ||
872 | hpi_handle_error( | ||
873 | hpi_outstream_write_buf( | ||
874 | ds->h_stream, pd, xfer1, | ||
875 | &ds->format)); | ||
876 | |||
877 | if (xfer2) { | ||
878 | pd = s->runtime->dma_area; | ||
879 | |||
880 | snd_printddd("P%d write2 0x%04X 0x%04X\n", | ||
833 | s->number, | 881 | s->number, |
834 | ds->period_bytes); | 882 | xfercount - xfer1, buf_ofs); |
835 | hpi_handle_error( | 883 | hpi_handle_error( |
836 | hpi_outstream_write_buf( | 884 | hpi_outstream_write_buf( |
837 | ds->h_stream, | 885 | ds->h_stream, pd, |
838 | &s->runtime-> | 886 | xfercount - xfer1, |
839 | dma_area[0], | ||
840 | xfercount, | ||
841 | &ds->format)); | 887 | &ds->format)); |
842 | } else { | 888 | } |
843 | snd_printddd("C%d read x%04x\n", | 889 | } else { |
844 | s->number, | 890 | snd_printddd("C%d read1 0x%04x\n", |
845 | xfercount); | 891 | s->number, xfer1); |
892 | hpi_handle_error( | ||
893 | hpi_instream_read_buf( | ||
894 | ds->h_stream, | ||
895 | pd, xfer1)); | ||
896 | if (xfer2) { | ||
897 | pd = s->runtime->dma_area; | ||
898 | snd_printddd("C%d read2 0x%04x\n", | ||
899 | s->number, xfer2); | ||
846 | hpi_handle_error( | 900 | hpi_handle_error( |
847 | hpi_instream_read_buf( | 901 | hpi_instream_read_buf( |
848 | ds->h_stream, | 902 | ds->h_stream, |
849 | NULL, xfercount)); | 903 | pd, xfer2)); |
850 | } | 904 | } |
851 | ds->pcm_buf_host_rw_ofs = ds->pcm_buf_host_rw_ofs + xfercount; | 905 | } |
852 | } /* else R/W will be handled by read/write callbacks */ | 906 | ds->pcm_buf_host_rw_ofs = ds->pcm_buf_host_rw_ofs + xfercount; |
853 | ds->pcm_buf_elapsed_dma_ofs = pcm_buf_dma_ofs; | 907 | ds->pcm_buf_elapsed_dma_ofs = pcm_buf_dma_ofs; |
854 | snd_pcm_period_elapsed(s); | 908 | snd_pcm_period_elapsed(s); |
855 | } | 909 | } |
@@ -863,7 +917,7 @@ static void snd_card_asihpi_timer_function(unsigned long data) | |||
863 | static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream, | 917 | static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream, |
864 | unsigned int cmd, void *arg) | 918 | unsigned int cmd, void *arg) |
865 | { | 919 | { |
866 | snd_printdd(KERN_INFO "Playback ioctl %d\n", cmd); | 920 | snd_printddd(KERN_INFO "P%d ioctl %d\n", substream->number, cmd); |
867 | return snd_pcm_lib_ioctl(substream, cmd, arg); | 921 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
868 | } | 922 | } |
869 | 923 | ||
@@ -873,7 +927,7 @@ static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream * | |||
873 | struct snd_pcm_runtime *runtime = substream->runtime; | 927 | struct snd_pcm_runtime *runtime = substream->runtime; |
874 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; | 928 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
875 | 929 | ||
876 | snd_printdd("playback prepare %d\n", substream->number); | 930 | snd_printdd("P%d prepare\n", substream->number); |
877 | 931 | ||
878 | hpi_handle_error(hpi_outstream_reset(dpcm->h_stream)); | 932 | hpi_handle_error(hpi_outstream_reset(dpcm->h_stream)); |
879 | dpcm->pcm_buf_host_rw_ofs = 0; | 933 | dpcm->pcm_buf_host_rw_ofs = 0; |
@@ -890,7 +944,7 @@ snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream) | |||
890 | snd_pcm_uframes_t ptr; | 944 | snd_pcm_uframes_t ptr; |
891 | 945 | ||
892 | ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes); | 946 | ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes); |
893 | snd_printddd("playback_pointer=x%04lx\n", (unsigned long)ptr); | 947 | snd_printddd("P%d pointer = 0x%04lx\n", substream->number, (unsigned long)ptr); |
894 | return ptr; | 948 | return ptr; |
895 | } | 949 | } |
896 | 950 | ||
@@ -986,11 +1040,9 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream) | |||
986 | SNDRV_PCM_INFO_DOUBLE | | 1040 | SNDRV_PCM_INFO_DOUBLE | |
987 | SNDRV_PCM_INFO_BATCH | | 1041 | SNDRV_PCM_INFO_BATCH | |
988 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | 1042 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
989 | SNDRV_PCM_INFO_PAUSE; | 1043 | SNDRV_PCM_INFO_PAUSE | |
990 | 1044 | SNDRV_PCM_INFO_MMAP | | |
991 | if (card->support_mmap) | 1045 | SNDRV_PCM_INFO_MMAP_VALID; |
992 | snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_MMAP | | ||
993 | SNDRV_PCM_INFO_MMAP_VALID; | ||
994 | 1046 | ||
995 | if (card->support_grouping) | 1047 | if (card->support_grouping) |
996 | snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START; | 1048 | snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START; |
@@ -998,7 +1050,7 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream) | |||
998 | /* struct is copied, so can create initializer dynamically */ | 1050 | /* struct is copied, so can create initializer dynamically */ |
999 | runtime->hw = snd_card_asihpi_playback; | 1051 | runtime->hw = snd_card_asihpi_playback; |
1000 | 1052 | ||
1001 | if (card->support_mmap) | 1053 | if (card->can_dma) |
1002 | err = snd_pcm_hw_constraint_pow2(runtime, 0, | 1054 | err = snd_pcm_hw_constraint_pow2(runtime, 0, |
1003 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES); | 1055 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES); |
1004 | if (err < 0) | 1056 | if (err < 0) |
@@ -1028,58 +1080,6 @@ static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream) | |||
1028 | return 0; | 1080 | return 0; |
1029 | } | 1081 | } |
1030 | 1082 | ||
1031 | static int snd_card_asihpi_playback_copy(struct snd_pcm_substream *substream, | ||
1032 | int channel, | ||
1033 | snd_pcm_uframes_t pos, | ||
1034 | void __user *src, | ||
1035 | snd_pcm_uframes_t count) | ||
1036 | { | ||
1037 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
1038 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; | ||
1039 | unsigned int len; | ||
1040 | |||
1041 | len = frames_to_bytes(runtime, count); | ||
1042 | |||
1043 | if (copy_from_user(runtime->dma_area, src, len)) | ||
1044 | return -EFAULT; | ||
1045 | |||
1046 | snd_printddd("playback copy%d %u bytes\n", | ||
1047 | substream->number, len); | ||
1048 | |||
1049 | hpi_handle_error(hpi_outstream_write_buf(dpcm->h_stream, | ||
1050 | runtime->dma_area, len, &dpcm->format)); | ||
1051 | |||
1052 | dpcm->pcm_buf_host_rw_ofs += len; | ||
1053 | |||
1054 | return 0; | ||
1055 | } | ||
1056 | |||
1057 | static int snd_card_asihpi_playback_silence(struct snd_pcm_substream * | ||
1058 | substream, int channel, | ||
1059 | snd_pcm_uframes_t pos, | ||
1060 | snd_pcm_uframes_t count) | ||
1061 | { | ||
1062 | /* Usually writes silence to DMA buffer, which should be overwritten | ||
1063 | by real audio later. Our fifos cannot be overwritten, and are not | ||
1064 | free-running DMAs. Silence is output on fifo underflow. | ||
1065 | This callback is still required to allow the copy callback to be used. | ||
1066 | */ | ||
1067 | return 0; | ||
1068 | } | ||
1069 | |||
1070 | static struct snd_pcm_ops snd_card_asihpi_playback_ops = { | ||
1071 | .open = snd_card_asihpi_playback_open, | ||
1072 | .close = snd_card_asihpi_playback_close, | ||
1073 | .ioctl = snd_card_asihpi_playback_ioctl, | ||
1074 | .hw_params = snd_card_asihpi_pcm_hw_params, | ||
1075 | .hw_free = snd_card_asihpi_hw_free, | ||
1076 | .prepare = snd_card_asihpi_playback_prepare, | ||
1077 | .trigger = snd_card_asihpi_trigger, | ||
1078 | .pointer = snd_card_asihpi_playback_pointer, | ||
1079 | .copy = snd_card_asihpi_playback_copy, | ||
1080 | .silence = snd_card_asihpi_playback_silence, | ||
1081 | }; | ||
1082 | |||
1083 | static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = { | 1083 | static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = { |
1084 | .open = snd_card_asihpi_playback_open, | 1084 | .open = snd_card_asihpi_playback_open, |
1085 | .close = snd_card_asihpi_playback_close, | 1085 | .close = snd_card_asihpi_playback_close, |
@@ -1211,18 +1211,16 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream) | |||
1211 | snd_card_asihpi_capture_format(card, dpcm->h_stream, | 1211 | snd_card_asihpi_capture_format(card, dpcm->h_stream, |
1212 | &snd_card_asihpi_capture); | 1212 | &snd_card_asihpi_capture); |
1213 | snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture); | 1213 | snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture); |
1214 | snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED; | 1214 | snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED | |
1215 | 1215 | SNDRV_PCM_INFO_MMAP | | |
1216 | if (card->support_mmap) | 1216 | SNDRV_PCM_INFO_MMAP_VALID; |
1217 | snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_MMAP | | ||
1218 | SNDRV_PCM_INFO_MMAP_VALID; | ||
1219 | 1217 | ||
1220 | if (card->support_grouping) | 1218 | if (card->support_grouping) |
1221 | snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START; | 1219 | snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START; |
1222 | 1220 | ||
1223 | runtime->hw = snd_card_asihpi_capture; | 1221 | runtime->hw = snd_card_asihpi_capture; |
1224 | 1222 | ||
1225 | if (card->support_mmap) | 1223 | if (card->can_dma) |
1226 | err = snd_pcm_hw_constraint_pow2(runtime, 0, | 1224 | err = snd_pcm_hw_constraint_pow2(runtime, 0, |
1227 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES); | 1225 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES); |
1228 | if (err < 0) | 1226 | if (err < 0) |
@@ -1246,28 +1244,6 @@ static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream) | |||
1246 | return 0; | 1244 | return 0; |
1247 | } | 1245 | } |
1248 | 1246 | ||
1249 | static int snd_card_asihpi_capture_copy(struct snd_pcm_substream *substream, | ||
1250 | int channel, snd_pcm_uframes_t pos, | ||
1251 | void __user *dst, snd_pcm_uframes_t count) | ||
1252 | { | ||
1253 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
1254 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; | ||
1255 | u32 len; | ||
1256 | |||
1257 | len = frames_to_bytes(runtime, count); | ||
1258 | |||
1259 | snd_printddd("capture copy%d %d bytes\n", substream->number, len); | ||
1260 | hpi_handle_error(hpi_instream_read_buf(dpcm->h_stream, | ||
1261 | runtime->dma_area, len)); | ||
1262 | |||
1263 | dpcm->pcm_buf_host_rw_ofs = dpcm->pcm_buf_host_rw_ofs + len; | ||
1264 | |||
1265 | if (copy_to_user(dst, runtime->dma_area, len)) | ||
1266 | return -EFAULT; | ||
1267 | |||
1268 | return 0; | ||
1269 | } | ||
1270 | |||
1271 | static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = { | 1247 | static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = { |
1272 | .open = snd_card_asihpi_capture_open, | 1248 | .open = snd_card_asihpi_capture_open, |
1273 | .close = snd_card_asihpi_capture_close, | 1249 | .close = snd_card_asihpi_capture_close, |
@@ -1279,18 +1255,6 @@ static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = { | |||
1279 | .pointer = snd_card_asihpi_capture_pointer, | 1255 | .pointer = snd_card_asihpi_capture_pointer, |
1280 | }; | 1256 | }; |
1281 | 1257 | ||
1282 | static struct snd_pcm_ops snd_card_asihpi_capture_ops = { | ||
1283 | .open = snd_card_asihpi_capture_open, | ||
1284 | .close = snd_card_asihpi_capture_close, | ||
1285 | .ioctl = snd_card_asihpi_capture_ioctl, | ||
1286 | .hw_params = snd_card_asihpi_pcm_hw_params, | ||
1287 | .hw_free = snd_card_asihpi_hw_free, | ||
1288 | .prepare = snd_card_asihpi_capture_prepare, | ||
1289 | .trigger = snd_card_asihpi_trigger, | ||
1290 | .pointer = snd_card_asihpi_capture_pointer, | ||
1291 | .copy = snd_card_asihpi_capture_copy | ||
1292 | }; | ||
1293 | |||
1294 | static int __devinit snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, | 1258 | static int __devinit snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, |
1295 | int device, int substreams) | 1259 | int device, int substreams) |
1296 | { | 1260 | { |
@@ -1303,17 +1267,10 @@ static int __devinit snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, | |||
1303 | if (err < 0) | 1267 | if (err < 0) |
1304 | return err; | 1268 | return err; |
1305 | /* pointer to ops struct is stored, dont change ops afterwards! */ | 1269 | /* pointer to ops struct is stored, dont change ops afterwards! */ |
1306 | if (asihpi->support_mmap) { | ||
1307 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, | 1270 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
1308 | &snd_card_asihpi_playback_mmap_ops); | 1271 | &snd_card_asihpi_playback_mmap_ops); |
1309 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, | 1272 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
1310 | &snd_card_asihpi_capture_mmap_ops); | 1273 | &snd_card_asihpi_capture_mmap_ops); |
1311 | } else { | ||
1312 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, | ||
1313 | &snd_card_asihpi_playback_ops); | ||
1314 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, | ||
1315 | &snd_card_asihpi_capture_ops); | ||
1316 | } | ||
1317 | 1274 | ||
1318 | pcm->private_data = asihpi; | 1275 | pcm->private_data = asihpi; |
1319 | pcm->info_flags = 0; | 1276 | pcm->info_flags = 0; |
@@ -1413,14 +1370,16 @@ static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control, | |||
1413 | struct hpi_control *hpi_ctl, | 1370 | struct hpi_control *hpi_ctl, |
1414 | char *name) | 1371 | char *name) |
1415 | { | 1372 | { |
1416 | char *dir = ""; | 1373 | char *dir; |
1417 | memset(snd_control, 0, sizeof(*snd_control)); | 1374 | memset(snd_control, 0, sizeof(*snd_control)); |
1418 | snd_control->name = hpi_ctl->name; | 1375 | snd_control->name = hpi_ctl->name; |
1419 | snd_control->private_value = hpi_ctl->h_control; | 1376 | snd_control->private_value = hpi_ctl->h_control; |
1420 | snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER; | 1377 | snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
1421 | snd_control->index = 0; | 1378 | snd_control->index = 0; |
1422 | 1379 | ||
1423 | if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM) | 1380 | if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE) |
1381 | dir = ""; /* clock is neither capture nor playback */ | ||
1382 | else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM) | ||
1424 | dir = "Capture "; /* On or towards a PCM capture destination*/ | 1383 | dir = "Capture "; /* On or towards a PCM capture destination*/ |
1425 | else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) && | 1384 | else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) && |
1426 | (!hpi_ctl->dst_node_type)) | 1385 | (!hpi_ctl->dst_node_type)) |
@@ -1433,7 +1392,7 @@ static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control, | |||
1433 | dir = "Playback "; /* PCM Playback source, or output node */ | 1392 | dir = "Playback "; /* PCM Playback source, or output node */ |
1434 | 1393 | ||
1435 | if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type) | 1394 | if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type) |
1436 | sprintf(hpi_ctl->name, "%s%d %s%d %s%s", | 1395 | sprintf(hpi_ctl->name, "%s %d %s %d %s%s", |
1437 | asihpi_src_names[hpi_ctl->src_node_type], | 1396 | asihpi_src_names[hpi_ctl->src_node_type], |
1438 | hpi_ctl->src_node_index, | 1397 | hpi_ctl->src_node_index, |
1439 | asihpi_dst_names[hpi_ctl->dst_node_type], | 1398 | asihpi_dst_names[hpi_ctl->dst_node_type], |
@@ -2875,14 +2834,14 @@ static int __devinit snd_asihpi_probe(struct pci_dev *pci_dev, | |||
2875 | if (err) | 2834 | if (err) |
2876 | asihpi->update_interval_frames = 512; | 2835 | asihpi->update_interval_frames = 512; |
2877 | 2836 | ||
2878 | if (!asihpi->support_mmap) | 2837 | if (!asihpi->can_dma) |
2879 | asihpi->update_interval_frames *= 2; | 2838 | asihpi->update_interval_frames *= 2; |
2880 | 2839 | ||
2881 | hpi_handle_error(hpi_instream_open(asihpi->adapter_index, | 2840 | hpi_handle_error(hpi_instream_open(asihpi->adapter_index, |
2882 | 0, &h_stream)); | 2841 | 0, &h_stream)); |
2883 | 2842 | ||
2884 | err = hpi_instream_host_buffer_free(h_stream); | 2843 | err = hpi_instream_host_buffer_free(h_stream); |
2885 | asihpi->support_mmap = (!err); | 2844 | asihpi->can_dma = (!err); |
2886 | 2845 | ||
2887 | hpi_handle_error(hpi_instream_close(h_stream)); | 2846 | hpi_handle_error(hpi_instream_close(h_stream)); |
2888 | 2847 | ||
@@ -2894,8 +2853,8 @@ static int __devinit snd_asihpi_probe(struct pci_dev *pci_dev, | |||
2894 | asihpi->out_max_chans = 2; | 2853 | asihpi->out_max_chans = 2; |
2895 | } | 2854 | } |
2896 | 2855 | ||
2897 | snd_printk(KERN_INFO "supports mmap:%d grouping:%d mrx:%d\n", | 2856 | snd_printk(KERN_INFO "has dma:%d, grouping:%d, mrx:%d\n", |
2898 | asihpi->support_mmap, | 2857 | asihpi->can_dma, |
2899 | asihpi->support_grouping, | 2858 | asihpi->support_grouping, |
2900 | asihpi->support_mrx | 2859 | asihpi->support_mrx |
2901 | ); | 2860 | ); |
@@ -2925,10 +2884,7 @@ static int __devinit snd_asihpi_probe(struct pci_dev *pci_dev, | |||
2925 | by enable_hwdep module param*/ | 2884 | by enable_hwdep module param*/ |
2926 | snd_asihpi_hpi_new(asihpi, 0, NULL); | 2885 | snd_asihpi_hpi_new(asihpi, 0, NULL); |
2927 | 2886 | ||
2928 | if (asihpi->support_mmap) | 2887 | strcpy(card->driver, "ASIHPI"); |
2929 | strcpy(card->driver, "ASIHPI-MMAP"); | ||
2930 | else | ||
2931 | strcpy(card->driver, "ASIHPI"); | ||
2932 | 2888 | ||
2933 | sprintf(card->shortname, "AudioScience ASI%4X", asihpi->type); | 2889 | sprintf(card->shortname, "AudioScience ASI%4X", asihpi->type); |
2934 | sprintf(card->longname, "%s %i", | 2890 | sprintf(card->longname, "%s %i", |