aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/Kconfig27
-rw-r--r--sound/pci/Makefile1
-rw-r--r--sound/pci/asihpi/asihpi.c328
-rw-r--r--sound/pci/asihpi/hpi6000.c39
-rw-r--r--sound/pci/asihpi/hpi6205.c95
-rw-r--r--sound/pci/asihpi/hpi_internal.h19
-rw-r--r--sound/pci/asihpi/hpicmn.c10
-rw-r--r--sound/pci/asihpi/hpicmn.h2
-rw-r--r--sound/pci/asihpi/hpifunc.c27
-rw-r--r--sound/pci/asihpi/hpimsgx.c31
-rw-r--r--sound/pci/asihpi/hpioctl.c63
-rw-r--r--sound/pci/au88x0/au8810.h2
-rw-r--r--sound/pci/au88x0/au8820.h2
-rw-r--r--sound/pci/au88x0/au8830.h2
-rw-r--r--sound/pci/au88x0/au88x0_pcm.c13
-rw-r--r--sound/pci/emu10k1/emufx.c5
-rw-r--r--sound/pci/emu10k1/emumixer.c10
-rw-r--r--sound/pci/es1968.c78
-rw-r--r--sound/pci/fm801.c371
-rw-r--r--sound/pci/intel8x0m.c4
-rw-r--r--sound/pci/lola/Makefile4
-rw-r--r--sound/pci/lola/lola.c791
-rw-r--r--sound/pci/lola/lola.h527
-rw-r--r--sound/pci/lola/lola_clock.c323
-rw-r--r--sound/pci/lola/lola_mixer.c839
-rw-r--r--sound/pci/lola/lola_pcm.c706
-rw-r--r--sound/pci/lola/lola_proc.c222
27 files changed, 3883 insertions, 658 deletions
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 389cd7931668..e90d103e177e 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -534,6 +534,14 @@ config SND_ES1968_INPUT
534 If you say N the buttons will directly control the master volume. 534 If you say N the buttons will directly control the master volume.
535 It is recommended to say Y. 535 It is recommended to say Y.
536 536
537config SND_ES1968_RADIO
538 bool "Enable TEA5757 radio tuner support for es1968"
539 depends on SND_ES1968
540 depends on VIDEO_V4L2=y || VIDEO_V4L2=SND_ES1968
541 help
542 Say Y here to include support for TEA5757 radio tuner integrated on
543 some MediaForte cards (e.g. SF64-PCE2).
544
537config SND_FM801 545config SND_FM801
538 tristate "ForteMedia FM801" 546 tristate "ForteMedia FM801"
539 select SND_OPL3_LIB 547 select SND_OPL3_LIB
@@ -552,13 +560,13 @@ config SND_FM801_TEA575X_BOOL
552 depends on VIDEO_V4L2=y || VIDEO_V4L2=SND_FM801 560 depends on VIDEO_V4L2=y || VIDEO_V4L2=SND_FM801
553 help 561 help
554 Say Y here to include support for soundcards based on the ForteMedia 562 Say Y here to include support for soundcards based on the ForteMedia
555 FM801 chip with a TEA5757 tuner connected to GPIO1-3 pins (Media 563 FM801 chip with a TEA5757 tuner (MediaForte SF256-PCS, SF256-PCP and
556 Forte SF256-PCS-02) into the snd-fm801 driver. 564 SF64-PCR) into the snd-fm801 driver.
557 565
558config SND_FM801_TEA575X 566config SND_TEA575X
559 tristate 567 tristate
560 depends on SND_FM801_TEA575X_BOOL 568 depends on SND_FM801_TEA575X_BOOL || SND_ES1968_RADIO
561 default SND_FM801 569 default SND_FM801 || SND_ES1968
562 570
563source "sound/pci/hda/Kconfig" 571source "sound/pci/hda/Kconfig"
564 572
@@ -658,6 +666,15 @@ config SND_KORG1212
658 To compile this driver as a module, choose M here: the module 666 To compile this driver as a module, choose M here: the module
659 will be called snd-korg1212. 667 will be called snd-korg1212.
660 668
669config SND_LOLA
670 tristate "Digigram Lola"
671 select SND_PCM
672 help
673 Say Y to include support for Digigram Lola boards.
674
675 To compile this driver as a module, choose M here: the module
676 will be called snd-lola.
677
661config SND_LX6464ES 678config SND_LX6464ES
662 tristate "Digigram LX6464ES" 679 tristate "Digigram LX6464ES"
663 select SND_PCM 680 select SND_PCM
diff --git a/sound/pci/Makefile b/sound/pci/Makefile
index 9cf4348ec137..54fe325e3aa5 100644
--- a/sound/pci/Makefile
+++ b/sound/pci/Makefile
@@ -64,6 +64,7 @@ obj-$(CONFIG_SND) += \
64 ca0106/ \ 64 ca0106/ \
65 cs46xx/ \ 65 cs46xx/ \
66 cs5535audio/ \ 66 cs5535audio/ \
67 lola/ \
67 lx6464es/ \ 68 lx6464es/ \
68 echoaudio/ \ 69 echoaudio/ \
69 emu10k1/ \ 70 emu10k1/ \
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
45MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
46MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>"); 47MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
47MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx"); 48MODULE_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
52and this copy can be removed */
53static 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
64static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */ 83static 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
113struct clk_source { 125struct 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 ****************/
291static void print_hwparams(struct snd_pcm_hw_params *p) 304
305static 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
306static snd_pcm_format_t hpi_to_alsa_formats[] = { 326static 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)
863static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream, 917static 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
1031static 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
1057static 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
1070static 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
1083static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = { 1083static 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
1249static 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
1271static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = { 1247static 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
1282static 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
1294static int __devinit snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, 1258static 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",
diff --git a/sound/pci/asihpi/hpi6000.c b/sound/pci/asihpi/hpi6000.c
index 8c8aac4c567e..df4aed5295dd 100644
--- a/sound/pci/asihpi/hpi6000.c
+++ b/sound/pci/asihpi/hpi6000.c
@@ -200,8 +200,8 @@ static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
200static void subsys_create_adapter(struct hpi_message *phm, 200static void subsys_create_adapter(struct hpi_message *phm,
201 struct hpi_response *phr); 201 struct hpi_response *phr);
202 202
203static void subsys_delete_adapter(struct hpi_message *phm, 203static void adapter_delete(struct hpi_adapter_obj *pao,
204 struct hpi_response *phr); 204 struct hpi_message *phm, struct hpi_response *phr);
205 205
206static void adapter_get_asserts(struct hpi_adapter_obj *pao, 206static void adapter_get_asserts(struct hpi_adapter_obj *pao,
207 struct hpi_message *phm, struct hpi_response *phr); 207 struct hpi_message *phm, struct hpi_response *phr);
@@ -222,9 +222,6 @@ static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
222 case HPI_SUBSYS_CREATE_ADAPTER: 222 case HPI_SUBSYS_CREATE_ADAPTER:
223 subsys_create_adapter(phm, phr); 223 subsys_create_adapter(phm, phr);
224 break; 224 break;
225 case HPI_SUBSYS_DELETE_ADAPTER:
226 subsys_delete_adapter(phm, phr);
227 break;
228 default: 225 default:
229 phr->error = HPI_ERROR_INVALID_FUNC; 226 phr->error = HPI_ERROR_INVALID_FUNC;
230 break; 227 break;
@@ -279,6 +276,10 @@ static void adapter_message(struct hpi_adapter_obj *pao,
279 adapter_get_asserts(pao, phm, phr); 276 adapter_get_asserts(pao, phm, phr);
280 break; 277 break;
281 278
279 case HPI_ADAPTER_DELETE:
280 adapter_delete(pao, phm, phr);
281 break;
282
282 default: 283 default:
283 hw_message(pao, phm, phr); 284 hw_message(pao, phm, phr);
284 break; 285 break;
@@ -333,26 +334,22 @@ void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
333{ 334{
334 struct hpi_adapter_obj *pao = NULL; 335 struct hpi_adapter_obj *pao = NULL;
335 336
336 /* subsytem messages get executed by every HPI. */
337 /* All other messages are ignored unless the adapter index matches */
338 /* an adapter in the HPI */
339 /*HPI_DEBUG_LOG(DEBUG, "O %d,F %x\n", phm->wObject, phm->wFunction); */
340
341 /* if Dsp has crashed then do not communicate with it any more */
342 if (phm->object != HPI_OBJ_SUBSYSTEM) { 337 if (phm->object != HPI_OBJ_SUBSYSTEM) {
343 pao = hpi_find_adapter(phm->adapter_index); 338 pao = hpi_find_adapter(phm->adapter_index);
344 if (!pao) { 339 if (!pao) {
345 HPI_DEBUG_LOG(DEBUG, 340 hpi_init_response(phr, phm->object, phm->function,
346 " %d,%d refused, for another HPI?\n", 341 HPI_ERROR_BAD_ADAPTER_NUMBER);
347 phm->object, phm->function); 342 HPI_DEBUG_LOG(DEBUG, "invalid adapter index: %d \n",
343 phm->adapter_index);
348 return; 344 return;
349 } 345 }
350 346
347 /* Don't even try to communicate with crashed DSP */
351 if (pao->dsp_crashed >= 10) { 348 if (pao->dsp_crashed >= 10) {
352 hpi_init_response(phr, phm->object, phm->function, 349 hpi_init_response(phr, phm->object, phm->function,
353 HPI_ERROR_DSP_HARDWARE); 350 HPI_ERROR_DSP_HARDWARE);
354 HPI_DEBUG_LOG(DEBUG, " %d,%d dsp crashed.\n", 351 HPI_DEBUG_LOG(DEBUG, "adapter %d dsp crashed\n",
355 phm->object, phm->function); 352 phm->adapter_index);
356 return; 353 return;
357 } 354 }
358 } 355 }
@@ -463,15 +460,9 @@ static void subsys_create_adapter(struct hpi_message *phm,
463 phr->error = 0; 460 phr->error = 0;
464} 461}
465 462
466static void subsys_delete_adapter(struct hpi_message *phm, 463static void adapter_delete(struct hpi_adapter_obj *pao,
467 struct hpi_response *phr) 464 struct hpi_message *phm, struct hpi_response *phr)
468{ 465{
469 struct hpi_adapter_obj *pao = NULL;
470
471 pao = hpi_find_adapter(phm->obj_index);
472 if (!pao)
473 return;
474
475 delete_adapter_obj(pao); 466 delete_adapter_obj(pao);
476 hpi_delete_adapter(pao); 467 hpi_delete_adapter(pao);
477 phr->error = 0; 468 phr->error = 0;
diff --git a/sound/pci/asihpi/hpi6205.c b/sound/pci/asihpi/hpi6205.c
index 22e9f08dea6d..9d5df54a6b46 100644
--- a/sound/pci/asihpi/hpi6205.c
+++ b/sound/pci/asihpi/hpi6205.c
@@ -152,8 +152,8 @@ static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
152 152
153static void subsys_create_adapter(struct hpi_message *phm, 153static void subsys_create_adapter(struct hpi_message *phm,
154 struct hpi_response *phr); 154 struct hpi_response *phr);
155static void subsys_delete_adapter(struct hpi_message *phm, 155static void adapter_delete(struct hpi_adapter_obj *pao,
156 struct hpi_response *phr); 156 struct hpi_message *phm, struct hpi_response *phr);
157 157
158static u16 create_adapter_obj(struct hpi_adapter_obj *pao, 158static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
159 u32 *pos_error_code); 159 u32 *pos_error_code);
@@ -223,15 +223,13 @@ static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index);
223 223
224/*****************************************************************************/ 224/*****************************************************************************/
225 225
226static void subsys_message(struct hpi_message *phm, struct hpi_response *phr) 226static void subsys_message(struct hpi_adapter_obj *pao,
227 struct hpi_message *phm, struct hpi_response *phr)
227{ 228{
228 switch (phm->function) { 229 switch (phm->function) {
229 case HPI_SUBSYS_CREATE_ADAPTER: 230 case HPI_SUBSYS_CREATE_ADAPTER:
230 subsys_create_adapter(phm, phr); 231 subsys_create_adapter(phm, phr);
231 break; 232 break;
232 case HPI_SUBSYS_DELETE_ADAPTER:
233 subsys_delete_adapter(phm, phr);
234 break;
235 default: 233 default:
236 phr->error = HPI_ERROR_INVALID_FUNC; 234 phr->error = HPI_ERROR_INVALID_FUNC;
237 break; 235 break;
@@ -279,6 +277,10 @@ static void adapter_message(struct hpi_adapter_obj *pao,
279 struct hpi_message *phm, struct hpi_response *phr) 277 struct hpi_message *phm, struct hpi_response *phr)
280{ 278{
281 switch (phm->function) { 279 switch (phm->function) {
280 case HPI_ADAPTER_DELETE:
281 adapter_delete(pao, phm, phr);
282 break;
283
282 default: 284 default:
283 hw_message(pao, phm, phr); 285 hw_message(pao, phm, phr);
284 break; 286 break;
@@ -371,36 +373,17 @@ static void instream_message(struct hpi_adapter_obj *pao,
371/** Entry point to this HPI backend 373/** Entry point to this HPI backend
372 * All calls to the HPI start here 374 * All calls to the HPI start here
373 */ 375 */
374void HPI_6205(struct hpi_message *phm, struct hpi_response *phr) 376void _HPI_6205(struct hpi_adapter_obj *pao, struct hpi_message *phm,
377 struct hpi_response *phr)
375{ 378{
376 struct hpi_adapter_obj *pao = NULL; 379 if (pao && (pao->dsp_crashed >= 10)
377 380 && (phm->function != HPI_ADAPTER_DEBUG_READ)) {
378 /* subsytem messages are processed by every HPI. 381 /* allow last resort debug read even after crash */
379 * All other messages are ignored unless the adapter index matches 382 hpi_init_response(phr, phm->object, phm->function,
380 * an adapter in the HPI 383 HPI_ERROR_DSP_HARDWARE);
381 */ 384 HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n", phm->object,
382 /* HPI_DEBUG_LOG(DEBUG, "HPI Obj=%d, Func=%d\n", phm->wObject, 385 phm->function);
383 phm->wFunction); */ 386 return;
384
385 /* if Dsp has crashed then do not communicate with it any more */
386 if (phm->object != HPI_OBJ_SUBSYSTEM) {
387 pao = hpi_find_adapter(phm->adapter_index);
388 if (!pao) {
389 HPI_DEBUG_LOG(DEBUG,
390 " %d,%d refused, for another HPI?\n",
391 phm->object, phm->function);
392 return;
393 }
394
395 if ((pao->dsp_crashed >= 10)
396 && (phm->function != HPI_ADAPTER_DEBUG_READ)) {
397 /* allow last resort debug read even after crash */
398 hpi_init_response(phr, phm->object, phm->function,
399 HPI_ERROR_DSP_HARDWARE);
400 HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n",
401 phm->object, phm->function);
402 return;
403 }
404 } 387 }
405 388
406 /* Init default response */ 389 /* Init default response */
@@ -412,7 +395,7 @@ void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
412 case HPI_TYPE_MESSAGE: 395 case HPI_TYPE_MESSAGE:
413 switch (phm->object) { 396 switch (phm->object) {
414 case HPI_OBJ_SUBSYSTEM: 397 case HPI_OBJ_SUBSYSTEM:
415 subsys_message(phm, phr); 398 subsys_message(pao, phm, phr);
416 break; 399 break;
417 400
418 case HPI_OBJ_ADAPTER: 401 case HPI_OBJ_ADAPTER:
@@ -444,6 +427,26 @@ void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
444 } 427 }
445} 428}
446 429
430void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
431{
432 struct hpi_adapter_obj *pao = NULL;
433
434 if (phm->object != HPI_OBJ_SUBSYSTEM) {
435 /* normal messages must have valid adapter index */
436 pao = hpi_find_adapter(phm->adapter_index);
437 } else {
438 /* subsys messages don't address an adapter */
439 _HPI_6205(NULL, phm, phr);
440 return;
441 }
442
443 if (pao)
444 _HPI_6205(pao, phm, phr);
445 else
446 hpi_init_response(phr, phm->object, phm->function,
447 HPI_ERROR_BAD_ADAPTER_NUMBER);
448}
449
447/*****************************************************************************/ 450/*****************************************************************************/
448/* SUBSYSTEM */ 451/* SUBSYSTEM */
449 452
@@ -491,13 +494,11 @@ static void subsys_create_adapter(struct hpi_message *phm,
491} 494}
492 495
493/** delete an adapter - required by WDM driver */ 496/** delete an adapter - required by WDM driver */
494static void subsys_delete_adapter(struct hpi_message *phm, 497static void adapter_delete(struct hpi_adapter_obj *pao,
495 struct hpi_response *phr) 498 struct hpi_message *phm, struct hpi_response *phr)
496{ 499{
497 struct hpi_adapter_obj *pao;
498 struct hpi_hw_obj *phw; 500 struct hpi_hw_obj *phw;
499 501
500 pao = hpi_find_adapter(phm->obj_index);
501 if (!pao) { 502 if (!pao) {
502 phr->error = HPI_ERROR_INVALID_OBJ_INDEX; 503 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
503 return; 504 return;
@@ -563,11 +564,12 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
563 } 564 }
564 565
565 err = adapter_boot_load_dsp(pao, pos_error_code); 566 err = adapter_boot_load_dsp(pao, pos_error_code);
566 if (err) 567 if (err) {
568 HPI_DEBUG_LOG(ERROR, "DSP code load failed\n");
567 /* no need to clean up as SubSysCreateAdapter */ 569 /* no need to clean up as SubSysCreateAdapter */
568 /* calls DeleteAdapter on error. */ 570 /* calls DeleteAdapter on error. */
569 return err; 571 return err;
570 572 }
571 HPI_DEBUG_LOG(INFO, "load DSP code OK\n"); 573 HPI_DEBUG_LOG(INFO, "load DSP code OK\n");
572 574
573 /* allow boot load even if mem alloc wont work */ 575 /* allow boot load even if mem alloc wont work */
@@ -604,6 +606,7 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
604 control_cache.number_of_controls, 606 control_cache.number_of_controls,
605 interface->control_cache.size_in_bytes, 607 interface->control_cache.size_in_bytes,
606 p_control_cache_virtual); 608 p_control_cache_virtual);
609
607 if (!phw->p_cache) 610 if (!phw->p_cache)
608 err = HPI_ERROR_MEMORY_ALLOC; 611 err = HPI_ERROR_MEMORY_ALLOC;
609 } 612 }
@@ -675,16 +678,14 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
675} 678}
676 679
677/** Free memory areas allocated by adapter 680/** Free memory areas allocated by adapter
678 * this routine is called from SubSysDeleteAdapter, 681 * this routine is called from AdapterDelete,
679 * and SubSysCreateAdapter if duplicate index 682 * and SubSysCreateAdapter if duplicate index
680*/ 683*/
681static void delete_adapter_obj(struct hpi_adapter_obj *pao) 684static void delete_adapter_obj(struct hpi_adapter_obj *pao)
682{ 685{
683 struct hpi_hw_obj *phw; 686 struct hpi_hw_obj *phw = pao->priv;
684 int i; 687 int i;
685 688
686 phw = pao->priv;
687
688 if (hpios_locked_mem_valid(&phw->h_control_cache)) { 689 if (hpios_locked_mem_valid(&phw->h_control_cache)) {
689 hpios_locked_mem_free(&phw->h_control_cache); 690 hpios_locked_mem_free(&phw->h_control_cache);
690 hpi_free_control_cache(phw->p_cache); 691 hpi_free_control_cache(phw->p_cache);
@@ -1275,6 +1276,7 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
1275 case HPI_ADAPTER_FAMILY_ASI(0x6300): 1276 case HPI_ADAPTER_FAMILY_ASI(0x6300):
1276 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6400); 1277 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6400);
1277 break; 1278 break;
1279 case HPI_ADAPTER_FAMILY_ASI(0x5500):
1278 case HPI_ADAPTER_FAMILY_ASI(0x5600): 1280 case HPI_ADAPTER_FAMILY_ASI(0x5600):
1279 case HPI_ADAPTER_FAMILY_ASI(0x6500): 1281 case HPI_ADAPTER_FAMILY_ASI(0x6500):
1280 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6600); 1282 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6600);
@@ -2059,7 +2061,6 @@ static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)
2059static void send_dsp_command(struct hpi_hw_obj *phw, int cmd) 2061static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)
2060{ 2062{
2061 struct bus_master_interface *interface = phw->p_interface_buffer; 2063 struct bus_master_interface *interface = phw->p_interface_buffer;
2062
2063 u32 r; 2064 u32 r;
2064 2065
2065 interface->host_cmd = cmd; 2066 interface->host_cmd = cmd;
diff --git a/sound/pci/asihpi/hpi_internal.h b/sound/pci/asihpi/hpi_internal.h
index 3b9fd115da36..bf5eced76bac 100644
--- a/sound/pci/asihpi/hpi_internal.h
+++ b/sound/pci/asihpi/hpi_internal.h
@@ -294,7 +294,7 @@ enum HPI_CONTROL_ATTRIBUTES {
294 294
295/* These defines are used to fill in protocol information for an Ethernet packet 295/* These defines are used to fill in protocol information for an Ethernet packet
296 sent using HMI on CS18102 */ 296 sent using HMI on CS18102 */
297/** ID supplied by Cirrius for ASI packets. */ 297/** ID supplied by Cirrus for ASI packets. */
298#define HPI_ETHERNET_PACKET_ID 0x85 298#define HPI_ETHERNET_PACKET_ID 0x85
299/** Simple packet - no special routing required */ 299/** Simple packet - no special routing required */
300#define HPI_ETHERNET_PACKET_V1 0x01 300#define HPI_ETHERNET_PACKET_V1 0x01
@@ -307,7 +307,7 @@ enum HPI_CONTROL_ATTRIBUTES {
307/** This packet must make its way to the host across the HPI interface */ 307/** This packet must make its way to the host across the HPI interface */
308#define HPI_ETHERNET_PACKET_HOSTED_VIA_HPI_V1 0x41 308#define HPI_ETHERNET_PACKET_HOSTED_VIA_HPI_V1 0x41
309 309
310#define HPI_ETHERNET_UDP_PORT (44600) /*!< UDP messaging port */ 310#define HPI_ETHERNET_UDP_PORT 44600 /**< HPI UDP service */
311 311
312/** Default network timeout in milli-seconds. */ 312/** Default network timeout in milli-seconds. */
313#define HPI_ETHERNET_TIMEOUT_MS 500 313#define HPI_ETHERNET_TIMEOUT_MS 500
@@ -397,14 +397,14 @@ enum HPI_FUNCTION_IDS {
397 HPI_SUBSYS_OPEN = HPI_FUNC_ID(SUBSYSTEM, 1), 397 HPI_SUBSYS_OPEN = HPI_FUNC_ID(SUBSYSTEM, 1),
398 HPI_SUBSYS_GET_VERSION = HPI_FUNC_ID(SUBSYSTEM, 2), 398 HPI_SUBSYS_GET_VERSION = HPI_FUNC_ID(SUBSYSTEM, 2),
399 HPI_SUBSYS_GET_INFO = HPI_FUNC_ID(SUBSYSTEM, 3), 399 HPI_SUBSYS_GET_INFO = HPI_FUNC_ID(SUBSYSTEM, 3),
400 HPI_SUBSYS_FIND_ADAPTERS = HPI_FUNC_ID(SUBSYSTEM, 4), 400 /* HPI_SUBSYS_FIND_ADAPTERS = HPI_FUNC_ID(SUBSYSTEM, 4), */
401 HPI_SUBSYS_CREATE_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 5), 401 HPI_SUBSYS_CREATE_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 5),
402 HPI_SUBSYS_CLOSE = HPI_FUNC_ID(SUBSYSTEM, 6), 402 HPI_SUBSYS_CLOSE = HPI_FUNC_ID(SUBSYSTEM, 6),
403 HPI_SUBSYS_DELETE_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 7), 403 /* HPI_SUBSYS_DELETE_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 7), */
404 HPI_SUBSYS_DRIVER_LOAD = HPI_FUNC_ID(SUBSYSTEM, 8), 404 HPI_SUBSYS_DRIVER_LOAD = HPI_FUNC_ID(SUBSYSTEM, 8),
405 HPI_SUBSYS_DRIVER_UNLOAD = HPI_FUNC_ID(SUBSYSTEM, 9), 405 HPI_SUBSYS_DRIVER_UNLOAD = HPI_FUNC_ID(SUBSYSTEM, 9),
406 HPI_SUBSYS_READ_PORT_8 = HPI_FUNC_ID(SUBSYSTEM, 10), 406 /* HPI_SUBSYS_READ_PORT_8 = HPI_FUNC_ID(SUBSYSTEM, 10), */
407 HPI_SUBSYS_WRITE_PORT_8 = HPI_FUNC_ID(SUBSYSTEM, 11), 407 /* HPI_SUBSYS_WRITE_PORT_8 = HPI_FUNC_ID(SUBSYSTEM, 11), */
408 HPI_SUBSYS_GET_NUM_ADAPTERS = HPI_FUNC_ID(SUBSYSTEM, 12), 408 HPI_SUBSYS_GET_NUM_ADAPTERS = HPI_FUNC_ID(SUBSYSTEM, 12),
409 HPI_SUBSYS_GET_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 13), 409 HPI_SUBSYS_GET_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 13),
410 HPI_SUBSYS_SET_NETWORK_INTERFACE = HPI_FUNC_ID(SUBSYSTEM, 14), 410 HPI_SUBSYS_SET_NETWORK_INTERFACE = HPI_FUNC_ID(SUBSYSTEM, 14),
@@ -433,7 +433,8 @@ enum HPI_FUNCTION_IDS {
433 HPI_ADAPTER_DEBUG_READ = HPI_FUNC_ID(ADAPTER, 18), 433 HPI_ADAPTER_DEBUG_READ = HPI_FUNC_ID(ADAPTER, 18),
434 HPI_ADAPTER_IRQ_QUERY_AND_CLEAR = HPI_FUNC_ID(ADAPTER, 19), 434 HPI_ADAPTER_IRQ_QUERY_AND_CLEAR = HPI_FUNC_ID(ADAPTER, 19),
435 HPI_ADAPTER_IRQ_CALLBACK = HPI_FUNC_ID(ADAPTER, 20), 435 HPI_ADAPTER_IRQ_CALLBACK = HPI_FUNC_ID(ADAPTER, 20),
436#define HPI_ADAPTER_FUNCTION_COUNT 20 436 HPI_ADAPTER_DELETE = HPI_FUNC_ID(ADAPTER, 21),
437#define HPI_ADAPTER_FUNCTION_COUNT 21
437 438
438 HPI_OSTREAM_OPEN = HPI_FUNC_ID(OSTREAM, 1), 439 HPI_OSTREAM_OPEN = HPI_FUNC_ID(OSTREAM, 1),
439 HPI_OSTREAM_CLOSE = HPI_FUNC_ID(OSTREAM, 2), 440 HPI_OSTREAM_CLOSE = HPI_FUNC_ID(OSTREAM, 2),
@@ -1561,8 +1562,6 @@ void hpi_send_recv(struct hpi_message *phm, struct hpi_response *phr);
1561u16 hpi_subsys_create_adapter(const struct hpi_resource *p_resource, 1562u16 hpi_subsys_create_adapter(const struct hpi_resource *p_resource,
1562 u16 *pw_adapter_index); 1563 u16 *pw_adapter_index);
1563 1564
1564u16 hpi_subsys_delete_adapter(u16 adapter_index);
1565
1566u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer, 1565u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,
1567 struct hpi_hostbuffer_status **pp_status); 1566 struct hpi_hostbuffer_status **pp_status);
1568 1567
@@ -1584,9 +1583,7 @@ void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR);
1584 1583
1585/*////////////////////////////////////////////////////////////////////////// */ 1584/*////////////////////////////////////////////////////////////////////////// */
1586/* declarations for individual HPI entry points */ 1585/* declarations for individual HPI entry points */
1587hpi_handler_func HPI_1000;
1588hpi_handler_func HPI_6000; 1586hpi_handler_func HPI_6000;
1589hpi_handler_func HPI_6205; 1587hpi_handler_func HPI_6205;
1590hpi_handler_func HPI_COMMON;
1591 1588
1592#endif /* _HPI_INTERNAL_H_ */ 1589#endif /* _HPI_INTERNAL_H_ */
diff --git a/sound/pci/asihpi/hpicmn.c b/sound/pci/asihpi/hpicmn.c
index 3e9c5c289764..b15a02e91f82 100644
--- a/sound/pci/asihpi/hpicmn.c
+++ b/sound/pci/asihpi/hpicmn.c
@@ -227,8 +227,9 @@ static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC)
227 if (info->control_type) { 227 if (info->control_type) {
228 pC->p_info[info->control_index] = info; 228 pC->p_info[info->control_index] = info;
229 cached++; 229 cached++;
230 } else /* dummy cache entry */ 230 } else { /* dummy cache entry */
231 pC->p_info[info->control_index] = NULL; 231 pC->p_info[info->control_index] = NULL;
232 }
232 233
233 byte_count += info->size_in32bit_words * 4; 234 byte_count += info->size_in32bit_words * 4;
234 235
@@ -298,7 +299,7 @@ struct pad_ofs_size {
298 unsigned int field_size; 299 unsigned int field_size;
299}; 300};
300 301
301static struct pad_ofs_size pad_desc[] = { 302static const struct pad_ofs_size pad_desc[] = {
302 HPICMN_PAD_OFS_AND_SIZE(c_channel), /* HPI_PAD_CHANNEL_NAME */ 303 HPICMN_PAD_OFS_AND_SIZE(c_channel), /* HPI_PAD_CHANNEL_NAME */
303 HPICMN_PAD_OFS_AND_SIZE(c_artist), /* HPI_PAD_ARTIST */ 304 HPICMN_PAD_OFS_AND_SIZE(c_artist), /* HPI_PAD_ARTIST */
304 HPICMN_PAD_OFS_AND_SIZE(c_title), /* HPI_PAD_TITLE */ 305 HPICMN_PAD_OFS_AND_SIZE(c_title), /* HPI_PAD_TITLE */
@@ -617,6 +618,10 @@ void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache,
617 } 618 }
618} 619}
619 620
621/** Allocate control cache.
622
623\return Cache pointer, or NULL if allocation fails.
624*/
620struct hpi_control_cache *hpi_alloc_control_cache(const u32 control_count, 625struct hpi_control_cache *hpi_alloc_control_cache(const u32 control_count,
621 const u32 size_in_bytes, u8 *p_dsp_control_buffer) 626 const u32 size_in_bytes, u8 *p_dsp_control_buffer)
622{ 627{
@@ -667,7 +672,6 @@ static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
667 phr->u.s.num_adapters = adapters.gw_num_adapters; 672 phr->u.s.num_adapters = adapters.gw_num_adapters;
668 break; 673 break;
669 case HPI_SUBSYS_CREATE_ADAPTER: 674 case HPI_SUBSYS_CREATE_ADAPTER:
670 case HPI_SUBSYS_DELETE_ADAPTER:
671 break; 675 break;
672 default: 676 default:
673 phr->error = HPI_ERROR_INVALID_FUNC; 677 phr->error = HPI_ERROR_INVALID_FUNC;
diff --git a/sound/pci/asihpi/hpicmn.h b/sound/pci/asihpi/hpicmn.h
index 590f0b69e655..d53cdf6e535f 100644
--- a/sound/pci/asihpi/hpicmn.h
+++ b/sound/pci/asihpi/hpicmn.h
@@ -60,3 +60,5 @@ void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *pC,
60 struct hpi_message *phm, struct hpi_response *phr); 60 struct hpi_message *phm, struct hpi_response *phr);
61 61
62u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr); 62u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr);
63
64hpi_handler_func HPI_COMMON;
diff --git a/sound/pci/asihpi/hpifunc.c b/sound/pci/asihpi/hpifunc.c
index c38fc9487560..7397b169b89f 100644
--- a/sound/pci/asihpi/hpifunc.c
+++ b/sound/pci/asihpi/hpifunc.c
@@ -105,33 +105,6 @@ u16 hpi_subsys_get_version_ex(u32 *pversion_ex)
105 return hr.error; 105 return hr.error;
106} 106}
107 107
108u16 hpi_subsys_create_adapter(const struct hpi_resource *p_resource,
109 u16 *pw_adapter_index)
110{
111 struct hpi_message hm;
112 struct hpi_response hr;
113
114 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
115 HPI_SUBSYS_CREATE_ADAPTER);
116 hm.u.s.resource = *p_resource;
117
118 hpi_send_recv(&hm, &hr);
119
120 *pw_adapter_index = hr.u.s.adapter_index;
121 return hr.error;
122}
123
124u16 hpi_subsys_delete_adapter(u16 adapter_index)
125{
126 struct hpi_message hm;
127 struct hpi_response hr;
128 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
129 HPI_SUBSYS_DELETE_ADAPTER);
130 hm.obj_index = adapter_index;
131 hpi_send_recv(&hm, &hr);
132 return hr.error;
133}
134
135u16 hpi_subsys_get_num_adapters(int *pn_num_adapters) 108u16 hpi_subsys_get_num_adapters(int *pn_num_adapters)
136{ 109{
137 struct hpi_message hm; 110 struct hpi_message hm;
diff --git a/sound/pci/asihpi/hpimsgx.c b/sound/pci/asihpi/hpimsgx.c
index 360028b9abf5..7352a5f7b4f7 100644
--- a/sound/pci/asihpi/hpimsgx.c
+++ b/sound/pci/asihpi/hpimsgx.c
@@ -211,24 +211,6 @@ static void subsys_message(struct hpi_message *phm, struct hpi_response *phr,
211 HPIMSGX__init(phm, phr); 211 HPIMSGX__init(phm, phr);
212 break; 212 break;
213 213
214 case HPI_SUBSYS_DELETE_ADAPTER:
215 HPIMSGX__cleanup(phm->obj_index, h_owner);
216 {
217 struct hpi_message hm;
218 struct hpi_response hr;
219 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
220 HPI_ADAPTER_CLOSE);
221 hm.adapter_index = phm->obj_index;
222 hw_entry_point(&hm, &hr);
223 }
224 if ((phm->obj_index < HPI_MAX_ADAPTERS)
225 && hpi_entry_points[phm->obj_index]) {
226 hpi_entry_points[phm->obj_index] (phm, phr);
227 hpi_entry_points[phm->obj_index] = NULL;
228 } else
229 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
230
231 break;
232 default: 214 default:
233 /* Must explicitly handle every subsys message in this switch */ 215 /* Must explicitly handle every subsys message in this switch */
234 hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function, 216 hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function,
@@ -247,6 +229,19 @@ static void adapter_message(struct hpi_message *phm, struct hpi_response *phr,
247 case HPI_ADAPTER_CLOSE: 229 case HPI_ADAPTER_CLOSE:
248 adapter_close(phm, phr); 230 adapter_close(phm, phr);
249 break; 231 break;
232 case HPI_ADAPTER_DELETE:
233 HPIMSGX__cleanup(phm->adapter_index, h_owner);
234 {
235 struct hpi_message hm;
236 struct hpi_response hr;
237 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
238 HPI_ADAPTER_CLOSE);
239 hm.adapter_index = phm->adapter_index;
240 hw_entry_point(&hm, &hr);
241 }
242 hw_entry_point(phm, phr);
243 break;
244
250 default: 245 default:
251 hw_entry_point(phm, phr); 246 hw_entry_point(phm, phr);
252 break; 247 break;
diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
index cd624f13ff8e..d8e7047512f8 100644
--- a/sound/pci/asihpi/hpioctl.c
+++ b/sound/pci/asihpi/hpioctl.c
@@ -25,6 +25,7 @@ Common Linux HPI ioctl and module probe/remove functions
25#include "hpidebug.h" 25#include "hpidebug.h"
26#include "hpimsgx.h" 26#include "hpimsgx.h"
27#include "hpioctl.h" 27#include "hpioctl.h"
28#include "hpicmn.h"
28 29
29#include <linux/fs.h> 30#include <linux/fs.h>
30#include <linux/slab.h> 31#include <linux/slab.h>
@@ -161,26 +162,24 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
161 goto out; 162 goto out;
162 } 163 }
163 164
164 pa = &adapters[hm->h.adapter_index]; 165 switch (hm->h.function) {
166 case HPI_SUBSYS_CREATE_ADAPTER:
167 case HPI_ADAPTER_DELETE:
168 /* Application must not use these functions! */
169 hr->h.size = sizeof(hr->h);
170 hr->h.error = HPI_ERROR_INVALID_OPERATION;
171 hr->h.function = hm->h.function;
172 uncopied_bytes = copy_to_user(puhr, hr, hr->h.size);
173 if (uncopied_bytes)
174 err = -EFAULT;
175 else
176 err = 0;
177 goto out;
178 }
179
165 hr->h.size = res_max_size; 180 hr->h.size = res_max_size;
166 if (hm->h.object == HPI_OBJ_SUBSYSTEM) { 181 if (hm->h.object == HPI_OBJ_SUBSYSTEM) {
167 switch (hm->h.function) { 182 hpi_send_recv_f(&hm->m0, &hr->r0, file);
168 case HPI_SUBSYS_CREATE_ADAPTER:
169 case HPI_SUBSYS_DELETE_ADAPTER:
170 /* Application must not use these functions! */
171 hr->h.size = sizeof(hr->h);
172 hr->h.error = HPI_ERROR_INVALID_OPERATION;
173 hr->h.function = hm->h.function;
174 uncopied_bytes = copy_to_user(puhr, hr, hr->h.size);
175 if (uncopied_bytes)
176 err = -EFAULT;
177 else
178 err = 0;
179 goto out;
180
181 default:
182 hpi_send_recv_f(&hm->m0, &hr->r0, file);
183 }
184 } else { 183 } else {
185 u16 __user *ptr = NULL; 184 u16 __user *ptr = NULL;
186 u32 size = 0; 185 u32 size = 0;
@@ -188,8 +187,9 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
188 /* -1=no data 0=read from user mem, 1=write to user mem */ 187 /* -1=no data 0=read from user mem, 1=write to user mem */
189 int wrflag = -1; 188 int wrflag = -1;
190 u32 adapter = hm->h.adapter_index; 189 u32 adapter = hm->h.adapter_index;
190 pa = &adapters[adapter];
191 191
192 if ((hm->h.adapter_index > HPI_MAX_ADAPTERS) || (!pa->type)) { 192 if ((adapter > HPI_MAX_ADAPTERS) || (!pa->type)) {
193 hpi_init_response(&hr->r0, HPI_OBJ_ADAPTER, 193 hpi_init_response(&hr->r0, HPI_OBJ_ADAPTER,
194 HPI_ADAPTER_OPEN, 194 HPI_ADAPTER_OPEN,
195 HPI_ERROR_BAD_ADAPTER_NUMBER); 195 HPI_ERROR_BAD_ADAPTER_NUMBER);
@@ -317,7 +317,7 @@ out:
317int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev, 317int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
318 const struct pci_device_id *pci_id) 318 const struct pci_device_id *pci_id)
319{ 319{
320 int err, idx, nm; 320 int idx, nm;
321 unsigned int memlen; 321 unsigned int memlen;
322 struct hpi_message hm; 322 struct hpi_message hm;
323 struct hpi_response hr; 323 struct hpi_response hr;
@@ -351,11 +351,8 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
351 nm = HPI_MAX_ADAPTER_MEM_SPACES; 351 nm = HPI_MAX_ADAPTER_MEM_SPACES;
352 352
353 for (idx = 0; idx < nm; idx++) { 353 for (idx = 0; idx < nm; idx++) {
354 HPI_DEBUG_LOG(INFO, "resource %d %s %08llx-%08llx %04llx\n", 354 HPI_DEBUG_LOG(INFO, "resource %d %pR\n", idx,
355 idx, pci_dev->resource[idx].name, 355 &pci_dev->resource[idx]);
356 (unsigned long long)pci_resource_start(pci_dev, idx),
357 (unsigned long long)pci_resource_end(pci_dev, idx),
358 (unsigned long long)pci_resource_flags(pci_dev, idx));
359 356
360 if (pci_resource_flags(pci_dev, idx) & IORESOURCE_MEM) { 357 if (pci_resource_flags(pci_dev, idx) & IORESOURCE_MEM) {
361 memlen = pci_resource_len(pci_dev, idx); 358 memlen = pci_resource_len(pci_dev, idx);
@@ -395,17 +392,20 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
395 392
396 adapter.index = hr.u.s.adapter_index; 393 adapter.index = hr.u.s.adapter_index;
397 adapter.type = hr.u.s.adapter_type; 394 adapter.type = hr.u.s.adapter_type;
395
396 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
397 HPI_ADAPTER_OPEN);
398 hm.adapter_index = adapter.index; 398 hm.adapter_index = adapter.index;
399 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
399 400
400 err = hpi_adapter_open(adapter.index); 401 if (hr.error)
401 if (err)
402 goto err; 402 goto err;
403 403
404 adapter.snd_card_asihpi = NULL; 404 adapter.snd_card_asihpi = NULL;
405 /* WARNING can't init mutex in 'adapter' 405 /* WARNING can't init mutex in 'adapter'
406 * and then copy it to adapters[] ?!?! 406 * and then copy it to adapters[] ?!?!
407 */ 407 */
408 adapters[hr.u.s.adapter_index] = adapter; 408 adapters[adapter.index] = adapter;
409 mutex_init(&adapters[adapter.index].mutex); 409 mutex_init(&adapters[adapter.index].mutex);
410 pci_set_drvdata(pci_dev, &adapters[adapter.index]); 410 pci_set_drvdata(pci_dev, &adapters[adapter.index]);
411 411
@@ -440,10 +440,9 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
440 struct hpi_adapter *pa; 440 struct hpi_adapter *pa;
441 pa = pci_get_drvdata(pci_dev); 441 pa = pci_get_drvdata(pci_dev);
442 442
443 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, 443 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
444 HPI_SUBSYS_DELETE_ADAPTER); 444 HPI_ADAPTER_DELETE);
445 hm.obj_index = pa->index; 445 hm.adapter_index = pa->index;
446 hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;
447 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL); 446 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
448 447
449 /* unmap PCI memory space, mapped during device init. */ 448 /* unmap PCI memory space, mapped during device init. */
diff --git a/sound/pci/au88x0/au8810.h b/sound/pci/au88x0/au8810.h
index 5d69c31fe3f4..79fbee3845eb 100644
--- a/sound/pci/au88x0/au8810.h
+++ b/sound/pci/au88x0/au8810.h
@@ -4,7 +4,7 @@
4 4
5#define CHIP_AU8810 5#define CHIP_AU8810
6 6
7#define CARD_NAME "Aureal Advantage 3D Sound Processor" 7#define CARD_NAME "Aureal Advantage"
8#define CARD_NAME_SHORT "au8810" 8#define CARD_NAME_SHORT "au8810"
9 9
10#define NR_ADB 0x10 10#define NR_ADB 0x10
diff --git a/sound/pci/au88x0/au8820.h b/sound/pci/au88x0/au8820.h
index abbe85e4f7a9..cafdb9668a34 100644
--- a/sound/pci/au88x0/au8820.h
+++ b/sound/pci/au88x0/au8820.h
@@ -11,7 +11,7 @@
11 11
12#define CHIP_AU8820 12#define CHIP_AU8820
13 13
14#define CARD_NAME "Aureal Vortex 3D Sound Processor" 14#define CARD_NAME "Aureal Vortex"
15#define CARD_NAME_SHORT "au8820" 15#define CARD_NAME_SHORT "au8820"
16 16
17/* Number of ADB and WT channels */ 17/* Number of ADB and WT channels */
diff --git a/sound/pci/au88x0/au8830.h b/sound/pci/au88x0/au8830.h
index 04ece1b1c218..999b29ab34ad 100644
--- a/sound/pci/au88x0/au8830.h
+++ b/sound/pci/au88x0/au8830.h
@@ -11,7 +11,7 @@
11 11
12#define CHIP_AU8830 12#define CHIP_AU8830
13 13
14#define CARD_NAME "Aureal Vortex 2 3D Sound Processor" 14#define CARD_NAME "Aureal Vortex 2"
15#define CARD_NAME_SHORT "au8830" 15#define CARD_NAME_SHORT "au8830"
16 16
17#define NR_ADB 0x20 17#define NR_ADB 0x20
diff --git a/sound/pci/au88x0/au88x0_pcm.c b/sound/pci/au88x0/au88x0_pcm.c
index 62e959120c44..c5f7ae46afef 100644
--- a/sound/pci/au88x0/au88x0_pcm.c
+++ b/sound/pci/au88x0/au88x0_pcm.c
@@ -426,11 +426,11 @@ static struct snd_pcm_ops snd_vortex_playback_ops = {
426*/ 426*/
427 427
428static char *vortex_pcm_prettyname[VORTEX_PCM_LAST] = { 428static char *vortex_pcm_prettyname[VORTEX_PCM_LAST] = {
429 "AU88x0 ADB", 429 CARD_NAME " ADB",
430 "AU88x0 SPDIF", 430 CARD_NAME " SPDIF",
431 "AU88x0 A3D", 431 CARD_NAME " A3D",
432 "AU88x0 WT", 432 CARD_NAME " WT",
433 "AU88x0 I2S", 433 CARD_NAME " I2S",
434}; 434};
435static char *vortex_pcm_name[VORTEX_PCM_LAST] = { 435static char *vortex_pcm_name[VORTEX_PCM_LAST] = {
436 "adb", 436 "adb",
@@ -527,7 +527,8 @@ static int __devinit snd_vortex_new_pcm(vortex_t *chip, int idx, int nr)
527 nr_capt, &pcm); 527 nr_capt, &pcm);
528 if (err < 0) 528 if (err < 0)
529 return err; 529 return err;
530 strcpy(pcm->name, vortex_pcm_name[idx]); 530 snprintf(pcm->name, sizeof(pcm->name),
531 "%s %s", CARD_NAME_SHORT, vortex_pcm_name[idx]);
531 chip->pcm[idx] = pcm; 532 chip->pcm[idx] = pcm;
532 // This is an evil hack, but it saves a lot of duplicated code. 533 // This is an evil hack, but it saves a lot of duplicated code.
533 VORTEX_PCM_TYPE(pcm) = idx; 534 VORTEX_PCM_TYPE(pcm) = idx;
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 7a9401462c1c..dae4050ede5c 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -303,6 +303,9 @@ static const u32 db_table[101] = {
303static const DECLARE_TLV_DB_SCALE(snd_emu10k1_db_scale1, -4000, 40, 1); 303static const DECLARE_TLV_DB_SCALE(snd_emu10k1_db_scale1, -4000, 40, 1);
304static const DECLARE_TLV_DB_LINEAR(snd_emu10k1_db_linear, TLV_DB_GAIN_MUTE, 0); 304static const DECLARE_TLV_DB_LINEAR(snd_emu10k1_db_linear, TLV_DB_GAIN_MUTE, 0);
305 305
306/* EMU10K1 bass/treble db gain */
307static const DECLARE_TLV_DB_SCALE(snd_emu10k1_bass_treble_db_scale, -1200, 60, 0);
308
306static const u32 onoff_table[2] = { 309static const u32 onoff_table[2] = {
307 0x00000000, 0x00000001 310 0x00000000, 0x00000001
308}; 311};
@@ -2163,6 +2166,7 @@ static int __devinit _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
2163 ctl->min = 0; 2166 ctl->min = 0;
2164 ctl->max = 40; 2167 ctl->max = 40;
2165 ctl->value[0] = ctl->value[1] = 20; 2168 ctl->value[0] = ctl->value[1] = 20;
2169 ctl->tlv = snd_emu10k1_bass_treble_db_scale;
2166 ctl->translation = EMU10K1_GPR_TRANSLATION_BASS; 2170 ctl->translation = EMU10K1_GPR_TRANSLATION_BASS;
2167 ctl = &controls[i + 1]; 2171 ctl = &controls[i + 1];
2168 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2172 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
@@ -2172,6 +2176,7 @@ static int __devinit _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
2172 ctl->min = 0; 2176 ctl->min = 0;
2173 ctl->max = 40; 2177 ctl->max = 40;
2174 ctl->value[0] = ctl->value[1] = 20; 2178 ctl->value[0] = ctl->value[1] = 20;
2179 ctl->tlv = snd_emu10k1_bass_treble_db_scale;
2175 ctl->translation = EMU10K1_GPR_TRANSLATION_TREBLE; 2180 ctl->translation = EMU10K1_GPR_TRANSLATION_TREBLE;
2176 2181
2177#define BASS_GPR 0x8c 2182#define BASS_GPR 0x8c
diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c
index 05afe06e353a..9d890a5aec5a 100644
--- a/sound/pci/emu10k1/emumixer.c
+++ b/sound/pci/emu10k1/emumixer.c
@@ -1729,8 +1729,6 @@ int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1729 "Master Mono Playback Volume", 1729 "Master Mono Playback Volume",
1730 "PCM Out Path & Mute", 1730 "PCM Out Path & Mute",
1731 "Mono Output Select", 1731 "Mono Output Select",
1732 "Front Playback Switch",
1733 "Front Playback Volume",
1734 "Surround Playback Switch", 1732 "Surround Playback Switch",
1735 "Surround Playback Volume", 1733 "Surround Playback Volume",
1736 "Center Playback Switch", 1734 "Center Playback Switch",
@@ -1879,6 +1877,8 @@ int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1879 emu->rear_ac97 = 1; 1877 emu->rear_ac97 = 1;
1880 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT); 1878 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
1881 snd_ac97_write_cache(emu->ac97, AC97_HEADPHONE, 0x0202); 1879 snd_ac97_write_cache(emu->ac97, AC97_HEADPHONE, 0x0202);
1880 remove_ctl(card,"Front Playback Volume");
1881 remove_ctl(card,"Front Playback Switch");
1882 } 1882 }
1883 /* remove unused AC97 controls */ 1883 /* remove unused AC97 controls */
1884 snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202); 1884 snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
@@ -1913,6 +1913,12 @@ int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1913 for (; *c; c += 2) 1913 for (; *c; c += 2)
1914 rename_ctl(card, c[0], c[1]); 1914 rename_ctl(card, c[0], c[1]);
1915 1915
1916 if (emu->card_capabilities->subsystem == 0x80401102) { /* SB Live! Platinum CT4760P */
1917 remove_ctl(card, "Center Playback Volume");
1918 remove_ctl(card, "LFE Playback Volume");
1919 remove_ctl(card, "Wave Center Playback Volume");
1920 remove_ctl(card, "Wave LFE Playback Volume");
1921 }
1916 if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */ 1922 if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */
1917 rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume"); 1923 rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
1918 rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume"); 1924 rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 7c17f45d876d..ab0a6156a704 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -112,6 +112,10 @@
112#include <sound/ac97_codec.h> 112#include <sound/ac97_codec.h>
113#include <sound/initval.h> 113#include <sound/initval.h>
114 114
115#ifdef CONFIG_SND_ES1968_RADIO
116#include <sound/tea575x-tuner.h>
117#endif
118
115#define CARD_NAME "ESS Maestro1/2" 119#define CARD_NAME "ESS Maestro1/2"
116#define DRIVER_NAME "ES1968" 120#define DRIVER_NAME "ES1968"
117 121
@@ -553,6 +557,10 @@ struct es1968 {
553 spinlock_t ac97_lock; 557 spinlock_t ac97_lock;
554 struct tasklet_struct hwvol_tq; 558 struct tasklet_struct hwvol_tq;
555#endif 559#endif
560
561#ifdef CONFIG_SND_ES1968_RADIO
562 struct snd_tea575x tea;
563#endif
556}; 564};
557 565
558static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id); 566static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id);
@@ -2571,6 +2579,63 @@ static int __devinit snd_es1968_input_register(struct es1968 *chip)
2571} 2579}
2572#endif /* CONFIG_SND_ES1968_INPUT */ 2580#endif /* CONFIG_SND_ES1968_INPUT */
2573 2581
2582#ifdef CONFIG_SND_ES1968_RADIO
2583#define GPIO_DATA 0x60
2584#define IO_MASK 4 /* mask register offset from GPIO_DATA
2585 bits 1=unmask write to given bit */
2586#define IO_DIR 8 /* direction register offset from GPIO_DATA
2587 bits 0/1=read/write direction */
2588/* mask bits for GPIO lines */
2589#define STR_DATA 0x0040 /* GPIO6 */
2590#define STR_CLK 0x0080 /* GPIO7 */
2591#define STR_WREN 0x0100 /* GPIO8 */
2592#define STR_MOST 0x0200 /* GPIO9 */
2593
2594static void snd_es1968_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
2595{
2596 struct es1968 *chip = tea->private_data;
2597 unsigned long io = chip->io_port + GPIO_DATA;
2598 u16 val = 0;
2599
2600 val |= (pins & TEA575X_DATA) ? STR_DATA : 0;
2601 val |= (pins & TEA575X_CLK) ? STR_CLK : 0;
2602 val |= (pins & TEA575X_WREN) ? STR_WREN : 0;
2603
2604 outw(val, io);
2605}
2606
2607static u8 snd_es1968_tea575x_get_pins(struct snd_tea575x *tea)
2608{
2609 struct es1968 *chip = tea->private_data;
2610 unsigned long io = chip->io_port + GPIO_DATA;
2611 u16 val = inw(io);
2612
2613 return (val & STR_DATA) ? TEA575X_DATA : 0 |
2614 (val & STR_MOST) ? TEA575X_MOST : 0;
2615}
2616
2617static void snd_es1968_tea575x_set_direction(struct snd_tea575x *tea, bool output)
2618{
2619 struct es1968 *chip = tea->private_data;
2620 unsigned long io = chip->io_port + GPIO_DATA;
2621 u16 odir = inw(io + IO_DIR);
2622
2623 if (output) {
2624 outw(~(STR_DATA | STR_CLK | STR_WREN), io + IO_MASK);
2625 outw(odir | STR_DATA | STR_CLK | STR_WREN, io + IO_DIR);
2626 } else {
2627 outw(~(STR_CLK | STR_WREN | STR_DATA | STR_MOST), io + IO_MASK);
2628 outw((odir & ~(STR_DATA | STR_MOST)) | STR_CLK | STR_WREN, io + IO_DIR);
2629 }
2630}
2631
2632static struct snd_tea575x_ops snd_es1968_tea_ops = {
2633 .set_pins = snd_es1968_tea575x_set_pins,
2634 .get_pins = snd_es1968_tea575x_get_pins,
2635 .set_direction = snd_es1968_tea575x_set_direction,
2636};
2637#endif
2638
2574static int snd_es1968_free(struct es1968 *chip) 2639static int snd_es1968_free(struct es1968 *chip)
2575{ 2640{
2576#ifdef CONFIG_SND_ES1968_INPUT 2641#ifdef CONFIG_SND_ES1968_INPUT
@@ -2585,6 +2650,10 @@ static int snd_es1968_free(struct es1968 *chip)
2585 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */ 2650 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */
2586 } 2651 }
2587 2652
2653#ifdef CONFIG_SND_ES1968_RADIO
2654 snd_tea575x_exit(&chip->tea);
2655#endif
2656
2588 if (chip->irq >= 0) 2657 if (chip->irq >= 0)
2589 free_irq(chip->irq, chip); 2658 free_irq(chip->irq, chip);
2590 snd_es1968_free_gameport(chip); 2659 snd_es1968_free_gameport(chip);
@@ -2723,6 +2792,15 @@ static int __devinit snd_es1968_create(struct snd_card *card,
2723 2792
2724 snd_card_set_dev(card, &pci->dev); 2793 snd_card_set_dev(card, &pci->dev);
2725 2794
2795#ifdef CONFIG_SND_ES1968_RADIO
2796 chip->tea.private_data = chip;
2797 chip->tea.ops = &snd_es1968_tea_ops;
2798 strlcpy(chip->tea.card, "SF64-PCE2", sizeof(chip->tea.card));
2799 sprintf(chip->tea.bus_info, "PCI:%s", pci_name(pci));
2800 if (!snd_tea575x_init(&chip->tea))
2801 printk(KERN_INFO "es1968: detected TEA575x radio\n");
2802#endif
2803
2726 *chip_ret = chip; 2804 *chip_ret = chip;
2727 2805
2728 return 0; 2806 return 0;
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index e1baad74ea4b..eacd4901a308 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -38,7 +38,6 @@
38 38
39#ifdef CONFIG_SND_FM801_TEA575X_BOOL 39#ifdef CONFIG_SND_FM801_TEA575X_BOOL
40#include <sound/tea575x-tuner.h> 40#include <sound/tea575x-tuner.h>
41#define TEA575X_RADIO 1
42#endif 41#endif
43 42
44MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 43MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
@@ -53,7 +52,7 @@ static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card *
53/* 52/*
54 * Enable TEA575x tuner 53 * Enable TEA575x tuner
55 * 1 = MediaForte 256-PCS 54 * 1 = MediaForte 256-PCS
56 * 2 = MediaForte 256-PCPR 55 * 2 = MediaForte 256-PCP
57 * 3 = MediaForte 64-PCR 56 * 3 = MediaForte 64-PCR
58 * 16 = setup tuner only (this is additional bit), i.e. SF64-PCR FM card 57 * 16 = setup tuner only (this is additional bit), i.e. SF64-PCR FM card
59 * High 16-bits are video (radio) device number + 1 58 * High 16-bits are video (radio) device number + 1
@@ -67,7 +66,7 @@ MODULE_PARM_DESC(id, "ID string for the FM801 soundcard.");
67module_param_array(enable, bool, NULL, 0444); 66module_param_array(enable, bool, NULL, 0444);
68MODULE_PARM_DESC(enable, "Enable FM801 soundcard."); 67MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
69module_param_array(tea575x_tuner, int, NULL, 0444); 68module_param_array(tea575x_tuner, int, NULL, 0444);
70MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (1 = SF256-PCS, 2=SF256-PCPR, 3=SF64-PCR, +16=tuner-only)."); 69MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (0 = auto, 1 = SF256-PCS, 2=SF256-PCP, 3=SF64-PCR, 8=disable, +16=tuner-only).");
71 70
72#define TUNER_ONLY (1<<4) 71#define TUNER_ONLY (1<<4)
73#define TUNER_TYPE_MASK (~TUNER_ONLY & 0xFFFF) 72#define TUNER_TYPE_MASK (~TUNER_ONLY & 0xFFFF)
@@ -196,7 +195,7 @@ struct fm801 {
196 spinlock_t reg_lock; 195 spinlock_t reg_lock;
197 struct snd_info_entry *proc_entry; 196 struct snd_info_entry *proc_entry;
198 197
199#ifdef TEA575X_RADIO 198#ifdef CONFIG_SND_FM801_TEA575X_BOOL
200 struct snd_tea575x tea; 199 struct snd_tea575x tea;
201#endif 200#endif
202 201
@@ -715,310 +714,89 @@ static int __devinit snd_fm801_pcm(struct fm801 *chip, int device, struct snd_pc
715 * TEA5757 radio 714 * TEA5757 radio
716 */ 715 */
717 716
718#ifdef TEA575X_RADIO 717#ifdef CONFIG_SND_FM801_TEA575X_BOOL
719
720/* 256PCS GPIO numbers */
721#define TEA_256PCS_DATA 1
722#define TEA_256PCS_WRITE_ENABLE 2 /* inverted */
723#define TEA_256PCS_BUS_CLOCK 3
724
725static void snd_fm801_tea575x_256pcs_write(struct snd_tea575x *tea, unsigned int val)
726{
727 struct fm801 *chip = tea->private_data;
728 unsigned short reg;
729 int i = 25;
730 718
731 spin_lock_irq(&chip->reg_lock); 719/* GPIO to TEA575x maps */
732 reg = inw(FM801_REG(chip, GPIO_CTRL)); 720struct snd_fm801_tea575x_gpio {
733 /* use GPIO lines and set write enable bit */ 721 u8 data, clk, wren, most;
734 reg |= FM801_GPIO_GS(TEA_256PCS_DATA) | 722 char *name;
735 FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE) | 723};
736 FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK);
737 /* all of lines are in the write direction */
738 /* clear data and clock lines */
739 reg &= ~(FM801_GPIO_GD(TEA_256PCS_DATA) |
740 FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE) |
741 FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK) |
742 FM801_GPIO_GP(TEA_256PCS_DATA) |
743 FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK) |
744 FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE));
745 outw(reg, FM801_REG(chip, GPIO_CTRL));
746 udelay(1);
747
748 while (i--) {
749 if (val & (1 << i))
750 reg |= FM801_GPIO_GP(TEA_256PCS_DATA);
751 else
752 reg &= ~FM801_GPIO_GP(TEA_256PCS_DATA);
753 outw(reg, FM801_REG(chip, GPIO_CTRL));
754 udelay(1);
755 reg |= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
756 outw(reg, FM801_REG(chip, GPIO_CTRL));
757 reg &= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
758 outw(reg, FM801_REG(chip, GPIO_CTRL));
759 udelay(1);
760 }
761 724
762 /* and reset the write enable bit */ 725static struct snd_fm801_tea575x_gpio snd_fm801_tea575x_gpios[] = {
763 reg |= FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE) | 726 { .data = 1, .clk = 3, .wren = 2, .most = 0, .name = "SF256-PCS" },
764 FM801_GPIO_GP(TEA_256PCS_DATA); 727 { .data = 1, .clk = 0, .wren = 2, .most = 3, .name = "SF256-PCP" },
765 outw(reg, FM801_REG(chip, GPIO_CTRL)); 728 { .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" },
766 spin_unlock_irq(&chip->reg_lock); 729};
767}
768 730
769static unsigned int snd_fm801_tea575x_256pcs_read(struct snd_tea575x *tea) 731static void snd_fm801_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
770{ 732{
771 struct fm801 *chip = tea->private_data; 733 struct fm801 *chip = tea->private_data;
772 unsigned short reg; 734 unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL));
773 unsigned int val = 0; 735 struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1];
774 int i;
775
776 spin_lock_irq(&chip->reg_lock);
777 reg = inw(FM801_REG(chip, GPIO_CTRL));
778 /* use GPIO lines, set data direction to input */
779 reg |= FM801_GPIO_GS(TEA_256PCS_DATA) |
780 FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE) |
781 FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK) |
782 FM801_GPIO_GD(TEA_256PCS_DATA) |
783 FM801_GPIO_GP(TEA_256PCS_DATA) |
784 FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE);
785 /* all of lines are in the write direction, except data */
786 /* clear data, write enable and clock lines */
787 reg &= ~(FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE) |
788 FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK) |
789 FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK));
790
791 for (i = 0; i < 24; i++) {
792 reg &= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
793 outw(reg, FM801_REG(chip, GPIO_CTRL));
794 udelay(1);
795 reg |= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
796 outw(reg, FM801_REG(chip, GPIO_CTRL));
797 udelay(1);
798 val <<= 1;
799 if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_256PCS_DATA))
800 val |= 1;
801 }
802 736
803 spin_unlock_irq(&chip->reg_lock); 737 reg &= ~(FM801_GPIO_GP(gpio.data) |
738 FM801_GPIO_GP(gpio.clk) |
739 FM801_GPIO_GP(gpio.wren));
804 740
805 return val; 741 reg |= (pins & TEA575X_DATA) ? FM801_GPIO_GP(gpio.data) : 0;
806} 742 reg |= (pins & TEA575X_CLK) ? FM801_GPIO_GP(gpio.clk) : 0;
743 /* WRITE_ENABLE is inverted */
744 reg |= (pins & TEA575X_WREN) ? 0 : FM801_GPIO_GP(gpio.wren);
807 745
808/* 256PCPR GPIO numbers */
809#define TEA_256PCPR_BUS_CLOCK 0
810#define TEA_256PCPR_DATA 1
811#define TEA_256PCPR_WRITE_ENABLE 2 /* inverted */
812
813static void snd_fm801_tea575x_256pcpr_write(struct snd_tea575x *tea, unsigned int val)
814{
815 struct fm801 *chip = tea->private_data;
816 unsigned short reg;
817 int i = 25;
818
819 spin_lock_irq(&chip->reg_lock);
820 reg = inw(FM801_REG(chip, GPIO_CTRL));
821 /* use GPIO lines and set write enable bit */
822 reg |= FM801_GPIO_GS(TEA_256PCPR_DATA) |
823 FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE) |
824 FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK);
825 /* all of lines are in the write direction */
826 /* clear data and clock lines */
827 reg &= ~(FM801_GPIO_GD(TEA_256PCPR_DATA) |
828 FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE) |
829 FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK) |
830 FM801_GPIO_GP(TEA_256PCPR_DATA) |
831 FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK) |
832 FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE));
833 outw(reg, FM801_REG(chip, GPIO_CTRL)); 746 outw(reg, FM801_REG(chip, GPIO_CTRL));
834 udelay(1);
835
836 while (i--) {
837 if (val & (1 << i))
838 reg |= FM801_GPIO_GP(TEA_256PCPR_DATA);
839 else
840 reg &= ~FM801_GPIO_GP(TEA_256PCPR_DATA);
841 outw(reg, FM801_REG(chip, GPIO_CTRL));
842 udelay(1);
843 reg |= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
844 outw(reg, FM801_REG(chip, GPIO_CTRL));
845 reg &= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
846 outw(reg, FM801_REG(chip, GPIO_CTRL));
847 udelay(1);
848 }
849
850 /* and reset the write enable bit */
851 reg |= FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE) |
852 FM801_GPIO_GP(TEA_256PCPR_DATA);
853 outw(reg, FM801_REG(chip, GPIO_CTRL));
854 spin_unlock_irq(&chip->reg_lock);
855} 747}
856 748
857static unsigned int snd_fm801_tea575x_256pcpr_read(struct snd_tea575x *tea) 749static u8 snd_fm801_tea575x_get_pins(struct snd_tea575x *tea)
858{ 750{
859 struct fm801 *chip = tea->private_data; 751 struct fm801 *chip = tea->private_data;
860 unsigned short reg; 752 unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL));
861 unsigned int val = 0; 753 struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1];
862 int i;
863
864 spin_lock_irq(&chip->reg_lock);
865 reg = inw(FM801_REG(chip, GPIO_CTRL));
866 /* use GPIO lines, set data direction to input */
867 reg |= FM801_GPIO_GS(TEA_256PCPR_DATA) |
868 FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE) |
869 FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK) |
870 FM801_GPIO_GD(TEA_256PCPR_DATA) |
871 FM801_GPIO_GP(TEA_256PCPR_DATA) |
872 FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE);
873 /* all of lines are in the write direction, except data */
874 /* clear data, write enable and clock lines */
875 reg &= ~(FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE) |
876 FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK) |
877 FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK));
878
879 for (i = 0; i < 24; i++) {
880 reg &= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
881 outw(reg, FM801_REG(chip, GPIO_CTRL));
882 udelay(1);
883 reg |= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
884 outw(reg, FM801_REG(chip, GPIO_CTRL));
885 udelay(1);
886 val <<= 1;
887 if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_256PCPR_DATA))
888 val |= 1;
889 }
890 754
891 spin_unlock_irq(&chip->reg_lock); 755 return (reg & FM801_GPIO_GP(gpio.data)) ? TEA575X_DATA : 0 |
892 756 (reg & FM801_GPIO_GP(gpio.most)) ? TEA575X_MOST : 0;
893 return val;
894} 757}
895 758
896/* 64PCR GPIO numbers */ 759static void snd_fm801_tea575x_set_direction(struct snd_tea575x *tea, bool output)
897#define TEA_64PCR_BUS_CLOCK 0
898#define TEA_64PCR_WRITE_ENABLE 1 /* inverted */
899#define TEA_64PCR_DATA 2
900
901static void snd_fm801_tea575x_64pcr_write(struct snd_tea575x *tea, unsigned int val)
902{ 760{
903 struct fm801 *chip = tea->private_data; 761 struct fm801 *chip = tea->private_data;
904 unsigned short reg; 762 unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL));
905 int i = 25; 763 struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1];
906 764
907 spin_lock_irq(&chip->reg_lock);
908 reg = inw(FM801_REG(chip, GPIO_CTRL));
909 /* use GPIO lines and set write enable bit */ 765 /* use GPIO lines and set write enable bit */
910 reg |= FM801_GPIO_GS(TEA_64PCR_DATA) | 766 reg |= FM801_GPIO_GS(gpio.data) |
911 FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE) | 767 FM801_GPIO_GS(gpio.wren) |
912 FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK); 768 FM801_GPIO_GS(gpio.clk) |
913 /* all of lines are in the write direction */ 769 FM801_GPIO_GS(gpio.most);
914 /* clear data and clock lines */ 770 if (output) {
915 reg &= ~(FM801_GPIO_GD(TEA_64PCR_DATA) | 771 /* all of lines are in the write direction */
916 FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE) | 772 /* clear data and clock lines */
917 FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK) | 773 reg &= ~(FM801_GPIO_GD(gpio.data) |
918 FM801_GPIO_GP(TEA_64PCR_DATA) | 774 FM801_GPIO_GD(gpio.wren) |
919 FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK) | 775 FM801_GPIO_GD(gpio.clk) |
920 FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE)); 776 FM801_GPIO_GP(gpio.data) |
921 outw(reg, FM801_REG(chip, GPIO_CTRL)); 777 FM801_GPIO_GP(gpio.clk) |
922 udelay(1); 778 FM801_GPIO_GP(gpio.wren));
923 779 } else {
924 while (i--) { 780 /* use GPIO lines, set data direction to input */
925 if (val & (1 << i)) 781 reg |= FM801_GPIO_GD(gpio.data) |
926 reg |= FM801_GPIO_GP(TEA_64PCR_DATA); 782 FM801_GPIO_GD(gpio.most) |
927 else 783 FM801_GPIO_GP(gpio.data) |
928 reg &= ~FM801_GPIO_GP(TEA_64PCR_DATA); 784 FM801_GPIO_GP(gpio.most) |
929 outw(reg, FM801_REG(chip, GPIO_CTRL)); 785 FM801_GPIO_GP(gpio.wren);
930 udelay(1); 786 /* all of lines are in the write direction, except data */
931 reg |= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK); 787 /* clear data, write enable and clock lines */
932 outw(reg, FM801_REG(chip, GPIO_CTRL)); 788 reg &= ~(FM801_GPIO_GD(gpio.wren) |
933 reg &= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK); 789 FM801_GPIO_GD(gpio.clk) |
934 outw(reg, FM801_REG(chip, GPIO_CTRL)); 790 FM801_GPIO_GP(gpio.clk));
935 udelay(1);
936 } 791 }
937 792
938 /* and reset the write enable bit */
939 reg |= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE) |
940 FM801_GPIO_GP(TEA_64PCR_DATA);
941 outw(reg, FM801_REG(chip, GPIO_CTRL)); 793 outw(reg, FM801_REG(chip, GPIO_CTRL));
942 spin_unlock_irq(&chip->reg_lock);
943}
944
945static unsigned int snd_fm801_tea575x_64pcr_read(struct snd_tea575x *tea)
946{
947 struct fm801 *chip = tea->private_data;
948 unsigned short reg;
949 unsigned int val = 0;
950 int i;
951
952 spin_lock_irq(&chip->reg_lock);
953 reg = inw(FM801_REG(chip, GPIO_CTRL));
954 /* use GPIO lines, set data direction to input */
955 reg |= FM801_GPIO_GS(TEA_64PCR_DATA) |
956 FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE) |
957 FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK) |
958 FM801_GPIO_GD(TEA_64PCR_DATA) |
959 FM801_GPIO_GP(TEA_64PCR_DATA) |
960 FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE);
961 /* all of lines are in the write direction, except data */
962 /* clear data, write enable and clock lines */
963 reg &= ~(FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE) |
964 FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK) |
965 FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK));
966
967 for (i = 0; i < 24; i++) {
968 reg &= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
969 outw(reg, FM801_REG(chip, GPIO_CTRL));
970 udelay(1);
971 reg |= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
972 outw(reg, FM801_REG(chip, GPIO_CTRL));
973 udelay(1);
974 val <<= 1;
975 if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_64PCR_DATA))
976 val |= 1;
977 }
978
979 spin_unlock_irq(&chip->reg_lock);
980
981 return val;
982} 794}
983 795
984static void snd_fm801_tea575x_64pcr_mute(struct snd_tea575x *tea, 796static struct snd_tea575x_ops snd_fm801_tea_ops = {
985 unsigned int mute) 797 .set_pins = snd_fm801_tea575x_set_pins,
986{ 798 .get_pins = snd_fm801_tea575x_get_pins,
987 struct fm801 *chip = tea->private_data; 799 .set_direction = snd_fm801_tea575x_set_direction,
988 unsigned short reg;
989
990 spin_lock_irq(&chip->reg_lock);
991
992 reg = inw(FM801_REG(chip, GPIO_CTRL));
993 if (mute)
994 /* 0xf800 (mute) */
995 reg &= ~FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE);
996 else
997 /* 0xf802 (unmute) */
998 reg |= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE);
999 outw(reg, FM801_REG(chip, GPIO_CTRL));
1000 udelay(1);
1001
1002 spin_unlock_irq(&chip->reg_lock);
1003}
1004
1005static struct snd_tea575x_ops snd_fm801_tea_ops[3] = {
1006 {
1007 /* 1 = MediaForte 256-PCS */
1008 .write = snd_fm801_tea575x_256pcs_write,
1009 .read = snd_fm801_tea575x_256pcs_read,
1010 },
1011 {
1012 /* 2 = MediaForte 256-PCPR */
1013 .write = snd_fm801_tea575x_256pcpr_write,
1014 .read = snd_fm801_tea575x_256pcpr_read,
1015 },
1016 {
1017 /* 3 = MediaForte 64-PCR */
1018 .write = snd_fm801_tea575x_64pcr_write,
1019 .read = snd_fm801_tea575x_64pcr_read,
1020 .mute = snd_fm801_tea575x_64pcr_mute,
1021 }
1022}; 800};
1023#endif 801#endif
1024 802
@@ -1371,7 +1149,7 @@ static int snd_fm801_free(struct fm801 *chip)
1371 outw(cmdw, FM801_REG(chip, IRQ_MASK)); 1149 outw(cmdw, FM801_REG(chip, IRQ_MASK));
1372 1150
1373 __end_hw: 1151 __end_hw:
1374#ifdef TEA575X_RADIO 1152#ifdef CONFIG_SND_FM801_TEA575X_BOOL
1375 snd_tea575x_exit(&chip->tea); 1153 snd_tea575x_exit(&chip->tea);
1376#endif 1154#endif
1377 if (chip->irq >= 0) 1155 if (chip->irq >= 0)
@@ -1450,16 +1228,25 @@ static int __devinit snd_fm801_create(struct snd_card *card,
1450 1228
1451 snd_card_set_dev(card, &pci->dev); 1229 snd_card_set_dev(card, &pci->dev);
1452 1230
1453#ifdef TEA575X_RADIO 1231#ifdef CONFIG_SND_FM801_TEA575X_BOOL
1232 chip->tea.private_data = chip;
1233 chip->tea.ops = &snd_fm801_tea_ops;
1234 sprintf(chip->tea.bus_info, "PCI:%s", pci_name(pci));
1454 if ((tea575x_tuner & TUNER_TYPE_MASK) > 0 && 1235 if ((tea575x_tuner & TUNER_TYPE_MASK) > 0 &&
1455 (tea575x_tuner & TUNER_TYPE_MASK) < 4) { 1236 (tea575x_tuner & TUNER_TYPE_MASK) < 4) {
1456 chip->tea.dev_nr = tea575x_tuner >> 16; 1237 if (snd_tea575x_init(&chip->tea))
1457 chip->tea.card = card; 1238 snd_printk(KERN_ERR "TEA575x radio not found\n");
1458 chip->tea.freq_fixup = 10700; 1239 } else if ((tea575x_tuner & TUNER_TYPE_MASK) == 0)
1459 chip->tea.private_data = chip; 1240 /* autodetect tuner connection */
1460 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & TUNER_TYPE_MASK) - 1]; 1241 for (tea575x_tuner = 1; tea575x_tuner <= 3; tea575x_tuner++) {
1461 snd_tea575x_init(&chip->tea); 1242 chip->tea575x_tuner = tea575x_tuner;
1462 } 1243 if (!snd_tea575x_init(&chip->tea)) {
1244 snd_printk(KERN_INFO "detected TEA575x radio type %s\n",
1245 snd_fm801_tea575x_gpios[tea575x_tuner - 1].name);
1246 break;
1247 }
1248 }
1249 strlcpy(chip->tea.card, snd_fm801_tea575x_gpios[(tea575x_tuner & TUNER_TYPE_MASK) - 1].name, sizeof(chip->tea.card));
1463#endif 1250#endif
1464 1251
1465 *rchip = chip; 1252 *rchip = chip;
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index 27709f0cd2a6..f3353b49c785 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -235,8 +235,8 @@ static DEFINE_PCI_DEVICE_TABLE(snd_intel8x0m_ids) = {
235 { PCI_VDEVICE(NVIDIA, 0x0069), DEVICE_NFORCE }, /* NFORCE2 */ 235 { PCI_VDEVICE(NVIDIA, 0x0069), DEVICE_NFORCE }, /* NFORCE2 */
236 { PCI_VDEVICE(NVIDIA, 0x0089), DEVICE_NFORCE }, /* NFORCE2s */ 236 { PCI_VDEVICE(NVIDIA, 0x0089), DEVICE_NFORCE }, /* NFORCE2s */
237 { PCI_VDEVICE(NVIDIA, 0x00d9), DEVICE_NFORCE }, /* NFORCE3 */ 237 { PCI_VDEVICE(NVIDIA, 0x00d9), DEVICE_NFORCE }, /* NFORCE3 */
238 { PCI_VDEVICE(AMD, 0x746e), DEVICE_INTEL }, /* AMD8111 */
238#if 0 239#if 0
239 { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
240 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */ 240 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
241#endif 241#endif
242 { 0, } 242 { 0, }
@@ -1261,9 +1261,9 @@ static struct shortname_table {
1261 { PCI_DEVICE_ID_NVIDIA_MCP2_MODEM, "NVidia nForce2" }, 1261 { PCI_DEVICE_ID_NVIDIA_MCP2_MODEM, "NVidia nForce2" },
1262 { PCI_DEVICE_ID_NVIDIA_MCP2S_MODEM, "NVidia nForce2s" }, 1262 { PCI_DEVICE_ID_NVIDIA_MCP2S_MODEM, "NVidia nForce2s" },
1263 { PCI_DEVICE_ID_NVIDIA_MCP3_MODEM, "NVidia nForce3" }, 1263 { PCI_DEVICE_ID_NVIDIA_MCP3_MODEM, "NVidia nForce3" },
1264 { 0x746e, "AMD AMD8111" },
1264#if 0 1265#if 0
1265 { 0x5455, "ALi M5455" }, 1266 { 0x5455, "ALi M5455" },
1266 { 0x746d, "AMD AMD8111" },
1267#endif 1267#endif
1268 { 0 }, 1268 { 0 },
1269}; 1269};
diff --git a/sound/pci/lola/Makefile b/sound/pci/lola/Makefile
new file mode 100644
index 000000000000..8178a2a59d00
--- /dev/null
+++ b/sound/pci/lola/Makefile
@@ -0,0 +1,4 @@
1snd-lola-y := lola.o lola_pcm.o lola_clock.o lola_mixer.o
2snd-lola-$(CONFIG_SND_DEBUG) += lola_proc.o
3
4obj-$(CONFIG_SND_LOLA) += snd-lola.o
diff --git a/sound/pci/lola/lola.c b/sound/pci/lola/lola.c
new file mode 100644
index 000000000000..34b24286d279
--- /dev/null
+++ b/sound/pci/lola/lola.c
@@ -0,0 +1,791 @@
1/*
2 * Support for Digigram Lola PCI-e boards
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/moduleparam.h>
24#include <linux/dma-mapping.h>
25#include <linux/delay.h>
26#include <linux/interrupt.h>
27#include <linux/slab.h>
28#include <linux/pci.h>
29#include <sound/core.h>
30#include <sound/control.h>
31#include <sound/pcm.h>
32#include <sound/initval.h>
33#include "lola.h"
34
35/* Standard options */
36static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
37static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
38static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
39
40module_param_array(index, int, NULL, 0444);
41MODULE_PARM_DESC(index, "Index value for Digigram Lola driver.");
42module_param_array(id, charp, NULL, 0444);
43MODULE_PARM_DESC(id, "ID string for Digigram Lola driver.");
44module_param_array(enable, bool, NULL, 0444);
45MODULE_PARM_DESC(enable, "Enable Digigram Lola driver.");
46
47/* Lola-specific options */
48
49/* for instance use always max granularity which is compatible
50 * with all sample rates
51 */
52static int granularity[SNDRV_CARDS] = {
53 [0 ... (SNDRV_CARDS - 1)] = LOLA_GRANULARITY_MAX
54};
55
56/* below a sample_rate of 16kHz the analogue audio quality is NOT excellent */
57static int sample_rate_min[SNDRV_CARDS] = {
58 [0 ... (SNDRV_CARDS - 1) ] = 16000
59};
60
61module_param_array(granularity, int, NULL, 0444);
62MODULE_PARM_DESC(granularity, "Granularity value");
63module_param_array(sample_rate_min, int, NULL, 0444);
64MODULE_PARM_DESC(sample_rate_min, "Minimal sample rate");
65
66/*
67 */
68
69MODULE_LICENSE("GPL");
70MODULE_SUPPORTED_DEVICE("{{Digigram, Lola}}");
71MODULE_DESCRIPTION("Digigram Lola driver");
72MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
73
74#ifdef CONFIG_SND_DEBUG_VERBOSE
75static int debug;
76module_param(debug, int, 0644);
77#define verbose_debug(fmt, args...) \
78 do { if (debug > 1) printk(KERN_DEBUG SFX fmt, ##args); } while (0)
79#else
80#define verbose_debug(fmt, args...)
81#endif
82
83/*
84 * pseudo-codec read/write via CORB/RIRB
85 */
86
87static int corb_send_verb(struct lola *chip, unsigned int nid,
88 unsigned int verb, unsigned int data,
89 unsigned int extdata)
90{
91 unsigned long flags;
92 int ret = -EIO;
93
94 chip->last_cmd_nid = nid;
95 chip->last_verb = verb;
96 chip->last_data = data;
97 chip->last_extdata = extdata;
98 data |= (nid << 20) | (verb << 8);
99
100 spin_lock_irqsave(&chip->reg_lock, flags);
101 if (chip->rirb.cmds < LOLA_CORB_ENTRIES - 1) {
102 unsigned int wp = chip->corb.wp + 1;
103 wp %= LOLA_CORB_ENTRIES;
104 chip->corb.wp = wp;
105 chip->corb.buf[wp * 2] = cpu_to_le32(data);
106 chip->corb.buf[wp * 2 + 1] = cpu_to_le32(extdata);
107 lola_writew(chip, BAR0, CORBWP, wp);
108 chip->rirb.cmds++;
109 smp_wmb();
110 ret = 0;
111 }
112 spin_unlock_irqrestore(&chip->reg_lock, flags);
113 return ret;
114}
115
116static void lola_queue_unsol_event(struct lola *chip, unsigned int res,
117 unsigned int res_ex)
118{
119 lola_update_ext_clock_freq(chip, res);
120}
121
122/* retrieve RIRB entry - called from interrupt handler */
123static void lola_update_rirb(struct lola *chip)
124{
125 unsigned int rp, wp;
126 u32 res, res_ex;
127
128 wp = lola_readw(chip, BAR0, RIRBWP);
129 if (wp == chip->rirb.wp)
130 return;
131 chip->rirb.wp = wp;
132
133 while (chip->rirb.rp != wp) {
134 chip->rirb.rp++;
135 chip->rirb.rp %= LOLA_CORB_ENTRIES;
136
137 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
138 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
139 res = le32_to_cpu(chip->rirb.buf[rp]);
140 if (res_ex & LOLA_RIRB_EX_UNSOL_EV)
141 lola_queue_unsol_event(chip, res, res_ex);
142 else if (chip->rirb.cmds) {
143 chip->res = res;
144 chip->res_ex = res_ex;
145 smp_wmb();
146 chip->rirb.cmds--;
147 }
148 }
149}
150
151static int rirb_get_response(struct lola *chip, unsigned int *val,
152 unsigned int *extval)
153{
154 unsigned long timeout;
155
156 again:
157 timeout = jiffies + msecs_to_jiffies(1000);
158 for (;;) {
159 if (chip->polling_mode) {
160 spin_lock_irq(&chip->reg_lock);
161 lola_update_rirb(chip);
162 spin_unlock_irq(&chip->reg_lock);
163 }
164 if (!chip->rirb.cmds) {
165 *val = chip->res;
166 if (extval)
167 *extval = chip->res_ex;
168 verbose_debug("get_response: %x, %x\n",
169 chip->res, chip->res_ex);
170 if (chip->res_ex & LOLA_RIRB_EX_ERROR) {
171 printk(KERN_WARNING SFX "RIRB ERROR: "
172 "NID=%x, verb=%x, data=%x, ext=%x\n",
173 chip->last_cmd_nid,
174 chip->last_verb, chip->last_data,
175 chip->last_extdata);
176 return -EIO;
177 }
178 return 0;
179 }
180 if (time_after(jiffies, timeout))
181 break;
182 udelay(20);
183 cond_resched();
184 }
185 printk(KERN_WARNING SFX "RIRB response error\n");
186 if (!chip->polling_mode) {
187 printk(KERN_WARNING SFX "switching to polling mode\n");
188 chip->polling_mode = 1;
189 goto again;
190 }
191 return -EIO;
192}
193
194/* aynchronous write of a codec verb with data */
195int lola_codec_write(struct lola *chip, unsigned int nid, unsigned int verb,
196 unsigned int data, unsigned int extdata)
197{
198 verbose_debug("codec_write NID=%x, verb=%x, data=%x, ext=%x\n",
199 nid, verb, data, extdata);
200 return corb_send_verb(chip, nid, verb, data, extdata);
201}
202
203/* write a codec verb with data and read the returned status */
204int lola_codec_read(struct lola *chip, unsigned int nid, unsigned int verb,
205 unsigned int data, unsigned int extdata,
206 unsigned int *val, unsigned int *extval)
207{
208 int err;
209
210 verbose_debug("codec_read NID=%x, verb=%x, data=%x, ext=%x\n",
211 nid, verb, data, extdata);
212 err = corb_send_verb(chip, nid, verb, data, extdata);
213 if (err < 0)
214 return err;
215 err = rirb_get_response(chip, val, extval);
216 return err;
217}
218
219/* flush all pending codec writes */
220int lola_codec_flush(struct lola *chip)
221{
222 unsigned int tmp;
223 return rirb_get_response(chip, &tmp, NULL);
224}
225
226/*
227 * interrupt handler
228 */
229static irqreturn_t lola_interrupt(int irq, void *dev_id)
230{
231 struct lola *chip = dev_id;
232 unsigned int notify_ins, notify_outs, error_ins, error_outs;
233 int handled = 0;
234 int i;
235
236 notify_ins = notify_outs = error_ins = error_outs = 0;
237 spin_lock(&chip->reg_lock);
238 for (;;) {
239 unsigned int status, in_sts, out_sts;
240 unsigned int reg;
241
242 status = lola_readl(chip, BAR1, DINTSTS);
243 if (!status || status == -1)
244 break;
245
246 in_sts = lola_readl(chip, BAR1, DIINTSTS);
247 out_sts = lola_readl(chip, BAR1, DOINTSTS);
248
249 /* clear Input Interrupts */
250 for (i = 0; in_sts && i < chip->pcm[CAPT].num_streams; i++) {
251 if (!(in_sts & (1 << i)))
252 continue;
253 in_sts &= ~(1 << i);
254 reg = lola_dsd_read(chip, i, STS);
255 if (reg & LOLA_DSD_STS_DESE) /* error */
256 error_ins |= (1 << i);
257 if (reg & LOLA_DSD_STS_BCIS) /* notify */
258 notify_ins |= (1 << i);
259 /* clear */
260 lola_dsd_write(chip, i, STS, reg);
261 }
262
263 /* clear Output Interrupts */
264 for (i = 0; out_sts && i < chip->pcm[PLAY].num_streams; i++) {
265 if (!(out_sts & (1 << i)))
266 continue;
267 out_sts &= ~(1 << i);
268 reg = lola_dsd_read(chip, i + MAX_STREAM_IN_COUNT, STS);
269 if (reg & LOLA_DSD_STS_DESE) /* error */
270 error_outs |= (1 << i);
271 if (reg & LOLA_DSD_STS_BCIS) /* notify */
272 notify_outs |= (1 << i);
273 lola_dsd_write(chip, i + MAX_STREAM_IN_COUNT, STS, reg);
274 }
275
276 if (status & LOLA_DINT_CTRL) {
277 unsigned char rbsts; /* ring status is byte access */
278 rbsts = lola_readb(chip, BAR0, RIRBSTS);
279 rbsts &= LOLA_RIRB_INT_MASK;
280 if (rbsts)
281 lola_writeb(chip, BAR0, RIRBSTS, rbsts);
282 rbsts = lola_readb(chip, BAR0, CORBSTS);
283 rbsts &= LOLA_CORB_INT_MASK;
284 if (rbsts)
285 lola_writeb(chip, BAR0, CORBSTS, rbsts);
286
287 lola_update_rirb(chip);
288 }
289
290 if (status & (LOLA_DINT_FIFOERR | LOLA_DINT_MUERR)) {
291 /* clear global fifo error interrupt */
292 lola_writel(chip, BAR1, DINTSTS,
293 (status & (LOLA_DINT_FIFOERR | LOLA_DINT_MUERR)));
294 }
295 handled = 1;
296 }
297 spin_unlock(&chip->reg_lock);
298
299 lola_pcm_update(chip, &chip->pcm[CAPT], notify_ins);
300 lola_pcm_update(chip, &chip->pcm[PLAY], notify_outs);
301
302 return IRQ_RETVAL(handled);
303}
304
305
306/*
307 * controller
308 */
309static int reset_controller(struct lola *chip)
310{
311 unsigned int gctl = lola_readl(chip, BAR0, GCTL);
312 unsigned long end_time;
313
314 if (gctl) {
315 /* to be sure */
316 lola_writel(chip, BAR1, BOARD_MODE, 0);
317 return 0;
318 }
319
320 chip->cold_reset = 1;
321 lola_writel(chip, BAR0, GCTL, LOLA_GCTL_RESET);
322 end_time = jiffies + msecs_to_jiffies(200);
323 do {
324 msleep(1);
325 gctl = lola_readl(chip, BAR0, GCTL);
326 if (gctl)
327 break;
328 } while (time_before(jiffies, end_time));
329 if (!gctl) {
330 printk(KERN_ERR SFX "cannot reset controller\n");
331 return -EIO;
332 }
333 return 0;
334}
335
336static void lola_irq_enable(struct lola *chip)
337{
338 unsigned int val;
339
340 /* enalbe all I/O streams */
341 val = (1 << chip->pcm[PLAY].num_streams) - 1;
342 lola_writel(chip, BAR1, DOINTCTL, val);
343 val = (1 << chip->pcm[CAPT].num_streams) - 1;
344 lola_writel(chip, BAR1, DIINTCTL, val);
345
346 /* enable global irqs */
347 val = LOLA_DINT_GLOBAL | LOLA_DINT_CTRL | LOLA_DINT_FIFOERR |
348 LOLA_DINT_MUERR;
349 lola_writel(chip, BAR1, DINTCTL, val);
350}
351
352static void lola_irq_disable(struct lola *chip)
353{
354 lola_writel(chip, BAR1, DINTCTL, 0);
355 lola_writel(chip, BAR1, DIINTCTL, 0);
356 lola_writel(chip, BAR1, DOINTCTL, 0);
357}
358
359static int setup_corb_rirb(struct lola *chip)
360{
361 int err;
362 unsigned char tmp;
363 unsigned long end_time;
364
365 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
366 snd_dma_pci_data(chip->pci),
367 PAGE_SIZE, &chip->rb);
368 if (err < 0)
369 return err;
370
371 chip->corb.addr = chip->rb.addr;
372 chip->corb.buf = (u32 *)chip->rb.area;
373 chip->rirb.addr = chip->rb.addr + 2048;
374 chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
375
376 /* disable ringbuffer DMAs */
377 lola_writeb(chip, BAR0, RIRBCTL, 0);
378 lola_writeb(chip, BAR0, CORBCTL, 0);
379
380 end_time = jiffies + msecs_to_jiffies(200);
381 do {
382 if (!lola_readb(chip, BAR0, RIRBCTL) &&
383 !lola_readb(chip, BAR0, CORBCTL))
384 break;
385 msleep(1);
386 } while (time_before(jiffies, end_time));
387
388 /* CORB set up */
389 lola_writel(chip, BAR0, CORBLBASE, (u32)chip->corb.addr);
390 lola_writel(chip, BAR0, CORBUBASE, upper_32_bits(chip->corb.addr));
391 /* set the corb size to 256 entries */
392 lola_writeb(chip, BAR0, CORBSIZE, 0x02);
393 /* set the corb write pointer to 0 */
394 lola_writew(chip, BAR0, CORBWP, 0);
395 /* reset the corb hw read pointer */
396 lola_writew(chip, BAR0, CORBRP, LOLA_RBRWP_CLR);
397 /* enable corb dma */
398 lola_writeb(chip, BAR0, CORBCTL, LOLA_RBCTL_DMA_EN);
399 /* clear flags if set */
400 tmp = lola_readb(chip, BAR0, CORBSTS) & LOLA_CORB_INT_MASK;
401 if (tmp)
402 lola_writeb(chip, BAR0, CORBSTS, tmp);
403 chip->corb.wp = 0;
404
405 /* RIRB set up */
406 lola_writel(chip, BAR0, RIRBLBASE, (u32)chip->rirb.addr);
407 lola_writel(chip, BAR0, RIRBUBASE, upper_32_bits(chip->rirb.addr));
408 /* set the rirb size to 256 entries */
409 lola_writeb(chip, BAR0, RIRBSIZE, 0x02);
410 /* reset the rirb hw write pointer */
411 lola_writew(chip, BAR0, RIRBWP, LOLA_RBRWP_CLR);
412 /* set N=1, get RIRB response interrupt for new entry */
413 lola_writew(chip, BAR0, RINTCNT, 1);
414 /* enable rirb dma and response irq */
415 lola_writeb(chip, BAR0, RIRBCTL, LOLA_RBCTL_DMA_EN | LOLA_RBCTL_IRQ_EN);
416 /* clear flags if set */
417 tmp = lola_readb(chip, BAR0, RIRBSTS) & LOLA_RIRB_INT_MASK;
418 if (tmp)
419 lola_writeb(chip, BAR0, RIRBSTS, tmp);
420 chip->rirb.rp = chip->rirb.cmds = 0;
421
422 return 0;
423}
424
425static void stop_corb_rirb(struct lola *chip)
426{
427 /* disable ringbuffer DMAs */
428 lola_writeb(chip, BAR0, RIRBCTL, 0);
429 lola_writeb(chip, BAR0, CORBCTL, 0);
430}
431
432static void lola_reset_setups(struct lola *chip)
433{
434 /* update the granularity */
435 lola_set_granularity(chip, chip->granularity, true);
436 /* update the sample clock */
437 lola_set_clock_index(chip, chip->clock.cur_index);
438 /* enable unsolicited events of the clock widget */
439 lola_enable_clock_events(chip);
440 /* update the analog gains */
441 lola_setup_all_analog_gains(chip, CAPT, false); /* input, update */
442 /* update SRC configuration if applicable */
443 lola_set_src_config(chip, chip->input_src_mask, false);
444 /* update the analog outputs */
445 lola_setup_all_analog_gains(chip, PLAY, false); /* output, update */
446}
447
448static int lola_parse_tree(struct lola *chip)
449{
450 unsigned int val;
451 int nid, err;
452
453 err = lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val);
454 if (err < 0) {
455 printk(KERN_ERR SFX "Can't read VENDOR_ID\n");
456 return err;
457 }
458 val >>= 16;
459 if (val != 0x1369) {
460 printk(KERN_ERR SFX "Unknown codec vendor 0x%x\n", val);
461 return -EINVAL;
462 }
463
464 err = lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
465 if (err < 0) {
466 printk(KERN_ERR SFX "Can't read FUNCTION_TYPE for 0x%x\n", nid);
467 return err;
468 }
469 if (val != 1) {
470 printk(KERN_ERR SFX "Unknown function type %d\n", val);
471 return -EINVAL;
472 }
473
474 err = lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val);
475 if (err < 0) {
476 printk(KERN_ERR SFX "Can't read SPECCAPS\n");
477 return err;
478 }
479 chip->lola_caps = val;
480 chip->pin[CAPT].num_pins = LOLA_AFG_INPUT_PIN_COUNT(chip->lola_caps);
481 chip->pin[PLAY].num_pins = LOLA_AFG_OUTPUT_PIN_COUNT(chip->lola_caps);
482 snd_printdd(SFX "speccaps=0x%x, pins in=%d, out=%d\n",
483 chip->lola_caps,
484 chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins);
485
486 if (chip->pin[CAPT].num_pins > MAX_AUDIO_INOUT_COUNT ||
487 chip->pin[PLAY].num_pins > MAX_AUDIO_INOUT_COUNT) {
488 printk(KERN_ERR SFX "Invalid Lola-spec caps 0x%x\n", val);
489 return -EINVAL;
490 }
491
492 nid = 0x02;
493 err = lola_init_pcm(chip, CAPT, &nid);
494 if (err < 0)
495 return err;
496 err = lola_init_pcm(chip, PLAY, &nid);
497 if (err < 0)
498 return err;
499
500 err = lola_init_pins(chip, CAPT, &nid);
501 if (err < 0)
502 return err;
503 err = lola_init_pins(chip, PLAY, &nid);
504 if (err < 0)
505 return err;
506
507 if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) {
508 err = lola_init_clock_widget(chip, nid);
509 if (err < 0)
510 return err;
511 nid++;
512 }
513 if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) {
514 err = lola_init_mixer_widget(chip, nid);
515 if (err < 0)
516 return err;
517 nid++;
518 }
519
520 /* enable unsolicited events of the clock widget */
521 err = lola_enable_clock_events(chip);
522 if (err < 0)
523 return err;
524
525 /* if last ResetController was not a ColdReset, we don't know
526 * the state of the card; initialize here again
527 */
528 if (!chip->cold_reset) {
529 lola_reset_setups(chip);
530 chip->cold_reset = 1;
531 } else {
532 /* set the granularity if it is not the default */
533 if (chip->granularity != LOLA_GRANULARITY_MIN)
534 lola_set_granularity(chip, chip->granularity, true);
535 }
536
537 return 0;
538}
539
540static void lola_stop_hw(struct lola *chip)
541{
542 stop_corb_rirb(chip);
543 lola_irq_disable(chip);
544}
545
546static void lola_free(struct lola *chip)
547{
548 if (chip->initialized)
549 lola_stop_hw(chip);
550 lola_free_pcm(chip);
551 lola_free_mixer(chip);
552 if (chip->irq >= 0)
553 free_irq(chip->irq, (void *)chip);
554 if (chip->bar[0].remap_addr)
555 iounmap(chip->bar[0].remap_addr);
556 if (chip->bar[1].remap_addr)
557 iounmap(chip->bar[1].remap_addr);
558 if (chip->rb.area)
559 snd_dma_free_pages(&chip->rb);
560 pci_release_regions(chip->pci);
561 pci_disable_device(chip->pci);
562 kfree(chip);
563}
564
565static int lola_dev_free(struct snd_device *device)
566{
567 lola_free(device->device_data);
568 return 0;
569}
570
571static int __devinit lola_create(struct snd_card *card, struct pci_dev *pci,
572 int dev, struct lola **rchip)
573{
574 struct lola *chip;
575 int err;
576 unsigned int dever;
577 static struct snd_device_ops ops = {
578 .dev_free = lola_dev_free,
579 };
580
581 *rchip = NULL;
582
583 err = pci_enable_device(pci);
584 if (err < 0)
585 return err;
586
587 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
588 if (!chip) {
589 snd_printk(KERN_ERR SFX "cannot allocate chip\n");
590 pci_disable_device(pci);
591 return -ENOMEM;
592 }
593
594 spin_lock_init(&chip->reg_lock);
595 mutex_init(&chip->open_mutex);
596 chip->card = card;
597 chip->pci = pci;
598 chip->irq = -1;
599
600 chip->granularity = granularity[dev];
601 switch (chip->granularity) {
602 case 8:
603 chip->sample_rate_max = 48000;
604 break;
605 case 16:
606 chip->sample_rate_max = 96000;
607 break;
608 case 32:
609 chip->sample_rate_max = 192000;
610 break;
611 default:
612 snd_printk(KERN_WARNING SFX
613 "Invalid granularity %d, reset to %d\n",
614 chip->granularity, LOLA_GRANULARITY_MAX);
615 chip->granularity = LOLA_GRANULARITY_MAX;
616 chip->sample_rate_max = 192000;
617 break;
618 }
619 chip->sample_rate_min = sample_rate_min[dev];
620 if (chip->sample_rate_min > chip->sample_rate_max) {
621 snd_printk(KERN_WARNING SFX
622 "Invalid sample_rate_min %d, reset to 16000\n",
623 chip->sample_rate_min);
624 chip->sample_rate_min = 16000;
625 }
626
627 err = pci_request_regions(pci, DRVNAME);
628 if (err < 0) {
629 kfree(chip);
630 pci_disable_device(pci);
631 return err;
632 }
633
634 chip->bar[0].addr = pci_resource_start(pci, 0);
635 chip->bar[0].remap_addr = pci_ioremap_bar(pci, 0);
636 chip->bar[1].addr = pci_resource_start(pci, 2);
637 chip->bar[1].remap_addr = pci_ioremap_bar(pci, 2);
638 if (!chip->bar[0].remap_addr || !chip->bar[1].remap_addr) {
639 snd_printk(KERN_ERR SFX "ioremap error\n");
640 err = -ENXIO;
641 goto errout;
642 }
643
644 pci_set_master(pci);
645
646 err = reset_controller(chip);
647 if (err < 0)
648 goto errout;
649
650 if (request_irq(pci->irq, lola_interrupt, IRQF_SHARED,
651 DRVNAME, chip)) {
652 printk(KERN_ERR SFX "unable to grab IRQ %d\n", pci->irq);
653 err = -EBUSY;
654 goto errout;
655 }
656 chip->irq = pci->irq;
657 synchronize_irq(chip->irq);
658
659 dever = lola_readl(chip, BAR1, DEVER);
660 chip->pcm[CAPT].num_streams = (dever >> 0) & 0x3ff;
661 chip->pcm[PLAY].num_streams = (dever >> 10) & 0x3ff;
662 chip->version = (dever >> 24) & 0xff;
663 snd_printdd(SFX "streams in=%d, out=%d, version=0x%x\n",
664 chip->pcm[CAPT].num_streams, chip->pcm[PLAY].num_streams,
665 chip->version);
666
667 /* Test LOLA_BAR1_DEVER */
668 if (chip->pcm[CAPT].num_streams > MAX_STREAM_IN_COUNT ||
669 chip->pcm[PLAY].num_streams > MAX_STREAM_OUT_COUNT ||
670 (!chip->pcm[CAPT].num_streams &&
671 !chip->pcm[PLAY].num_streams)) {
672 printk(KERN_ERR SFX "invalid DEVER = %x\n", dever);
673 err = -EINVAL;
674 goto errout;
675 }
676
677 err = setup_corb_rirb(chip);
678 if (err < 0)
679 goto errout;
680
681 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
682 if (err < 0) {
683 snd_printk(KERN_ERR SFX "Error creating device [card]!\n");
684 goto errout;
685 }
686
687 strcpy(card->driver, "Lola");
688 strlcpy(card->shortname, "Digigram Lola", sizeof(card->shortname));
689 snprintf(card->longname, sizeof(card->longname),
690 "%s at 0x%lx irq %i",
691 card->shortname, chip->bar[0].addr, chip->irq);
692 strcpy(card->mixername, card->shortname);
693
694 lola_irq_enable(chip);
695
696 chip->initialized = 1;
697 *rchip = chip;
698 return 0;
699
700 errout:
701 lola_free(chip);
702 return err;
703}
704
705static int __devinit lola_probe(struct pci_dev *pci,
706 const struct pci_device_id *pci_id)
707{
708 static int dev;
709 struct snd_card *card;
710 struct lola *chip;
711 int err;
712
713 if (dev >= SNDRV_CARDS)
714 return -ENODEV;
715 if (!enable[dev]) {
716 dev++;
717 return -ENOENT;
718 }
719
720 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
721 if (err < 0) {
722 snd_printk(KERN_ERR SFX "Error creating card!\n");
723 return err;
724 }
725
726 snd_card_set_dev(card, &pci->dev);
727
728 err = lola_create(card, pci, dev, &chip);
729 if (err < 0)
730 goto out_free;
731 card->private_data = chip;
732
733 err = lola_parse_tree(chip);
734 if (err < 0)
735 goto out_free;
736
737 err = lola_create_pcm(chip);
738 if (err < 0)
739 goto out_free;
740
741 err = lola_create_mixer(chip);
742 if (err < 0)
743 goto out_free;
744
745 lola_proc_debug_new(chip);
746
747 err = snd_card_register(card);
748 if (err < 0)
749 goto out_free;
750
751 pci_set_drvdata(pci, card);
752 dev++;
753 return err;
754out_free:
755 snd_card_free(card);
756 return err;
757}
758
759static void __devexit lola_remove(struct pci_dev *pci)
760{
761 snd_card_free(pci_get_drvdata(pci));
762 pci_set_drvdata(pci, NULL);
763}
764
765/* PCI IDs */
766static DEFINE_PCI_DEVICE_TABLE(lola_ids) = {
767 { PCI_VDEVICE(DIGIGRAM, 0x0001) },
768 { 0, }
769};
770MODULE_DEVICE_TABLE(pci, lola_ids);
771
772/* pci_driver definition */
773static struct pci_driver driver = {
774 .name = DRVNAME,
775 .id_table = lola_ids,
776 .probe = lola_probe,
777 .remove = __devexit_p(lola_remove),
778};
779
780static int __init alsa_card_lola_init(void)
781{
782 return pci_register_driver(&driver);
783}
784
785static void __exit alsa_card_lola_exit(void)
786{
787 pci_unregister_driver(&driver);
788}
789
790module_init(alsa_card_lola_init)
791module_exit(alsa_card_lola_exit)
diff --git a/sound/pci/lola/lola.h b/sound/pci/lola/lola.h
new file mode 100644
index 000000000000..d5708e29b16d
--- /dev/null
+++ b/sound/pci/lola/lola.h
@@ -0,0 +1,527 @@
1/*
2 * Support for Digigram Lola PCI-e boards
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#ifndef _LOLA_H
22#define _LOLA_H
23
24#define DRVNAME "snd-lola"
25#define SFX DRVNAME ": "
26
27/*
28 * Lola HD Audio Registers BAR0
29 */
30#define LOLA_BAR0_GCAP 0x00
31#define LOLA_BAR0_VMIN 0x02
32#define LOLA_BAR0_VMAJ 0x03
33#define LOLA_BAR0_OUTPAY 0x04
34#define LOLA_BAR0_INPAY 0x06
35#define LOLA_BAR0_GCTL 0x08
36#define LOLA_BAR0_WAKEEN 0x0c
37#define LOLA_BAR0_STATESTS 0x0e
38#define LOLA_BAR0_GSTS 0x10
39#define LOLA_BAR0_OUTSTRMPAY 0x18
40#define LOLA_BAR0_INSTRMPAY 0x1a
41#define LOLA_BAR0_INTCTL 0x20
42#define LOLA_BAR0_INTSTS 0x24
43#define LOLA_BAR0_WALCLK 0x30
44#define LOLA_BAR0_SSYNC 0x38
45
46#define LOLA_BAR0_CORBLBASE 0x40
47#define LOLA_BAR0_CORBUBASE 0x44
48#define LOLA_BAR0_CORBWP 0x48 /* no ULONG access */
49#define LOLA_BAR0_CORBRP 0x4a /* no ULONG access */
50#define LOLA_BAR0_CORBCTL 0x4c /* no ULONG access */
51#define LOLA_BAR0_CORBSTS 0x4d /* UCHAR access only */
52#define LOLA_BAR0_CORBSIZE 0x4e /* no ULONG access */
53
54#define LOLA_BAR0_RIRBLBASE 0x50
55#define LOLA_BAR0_RIRBUBASE 0x54
56#define LOLA_BAR0_RIRBWP 0x58
57#define LOLA_BAR0_RINTCNT 0x5a /* no ULONG access */
58#define LOLA_BAR0_RIRBCTL 0x5c
59#define LOLA_BAR0_RIRBSTS 0x5d /* UCHAR access only */
60#define LOLA_BAR0_RIRBSIZE 0x5e /* no ULONG access */
61
62#define LOLA_BAR0_ICW 0x60
63#define LOLA_BAR0_IRR 0x64
64#define LOLA_BAR0_ICS 0x68
65#define LOLA_BAR0_DPLBASE 0x70
66#define LOLA_BAR0_DPUBASE 0x74
67
68/* stream register offsets from stream base 0x80 */
69#define LOLA_BAR0_SD0_OFFSET 0x80
70#define LOLA_REG0_SD_CTL 0x00
71#define LOLA_REG0_SD_STS 0x03
72#define LOLA_REG0_SD_LPIB 0x04
73#define LOLA_REG0_SD_CBL 0x08
74#define LOLA_REG0_SD_LVI 0x0c
75#define LOLA_REG0_SD_FIFOW 0x0e
76#define LOLA_REG0_SD_FIFOSIZE 0x10
77#define LOLA_REG0_SD_FORMAT 0x12
78#define LOLA_REG0_SD_BDLPL 0x18
79#define LOLA_REG0_SD_BDLPU 0x1c
80
81/*
82 * Lola Digigram Registers BAR1
83 */
84#define LOLA_BAR1_FPGAVER 0x00
85#define LOLA_BAR1_DEVER 0x04
86#define LOLA_BAR1_UCBMV 0x08
87#define LOLA_BAR1_JTAG 0x0c
88#define LOLA_BAR1_UARTRX 0x10
89#define LOLA_BAR1_UARTTX 0x14
90#define LOLA_BAR1_UARTCR 0x18
91#define LOLA_BAR1_NVRAMVER 0x1c
92#define LOLA_BAR1_CTRLSPI 0x20
93#define LOLA_BAR1_DSPI 0x24
94#define LOLA_BAR1_AISPI 0x28
95#define LOLA_BAR1_GRAN 0x2c
96
97#define LOLA_BAR1_DINTCTL 0x80
98#define LOLA_BAR1_DIINTCTL 0x84
99#define LOLA_BAR1_DOINTCTL 0x88
100#define LOLA_BAR1_LRC 0x90
101#define LOLA_BAR1_DINTSTS 0x94
102#define LOLA_BAR1_DIINTSTS 0x98
103#define LOLA_BAR1_DOINTSTS 0x9c
104
105#define LOLA_BAR1_DSD0_OFFSET 0xa0
106#define LOLA_BAR1_DSD_SIZE 0x18
107
108#define LOLA_BAR1_DSDnSTS 0x00
109#define LOLA_BAR1_DSDnLPIB 0x04
110#define LOLA_BAR1_DSDnCTL 0x08
111#define LOLA_BAR1_DSDnLVI 0x0c
112#define LOLA_BAR1_DSDnBDPL 0x10
113#define LOLA_BAR1_DSDnBDPU 0x14
114
115#define LOLA_BAR1_SSYNC 0x03e8
116
117#define LOLA_BAR1_BOARD_CTRL 0x0f00
118#define LOLA_BAR1_BOARD_MODE 0x0f02
119
120#define LOLA_BAR1_SOURCE_GAIN_ENABLE 0x1000
121#define LOLA_BAR1_DEST00_MIX_GAIN_ENABLE 0x1004
122#define LOLA_BAR1_DEST31_MIX_GAIN_ENABLE 0x1080
123#define LOLA_BAR1_SOURCE00_01_GAIN 0x1084
124#define LOLA_BAR1_SOURCE30_31_GAIN 0x10c0
125#define LOLA_BAR1_SOURCE_GAIN(src) \
126 (LOLA_BAR1_SOURCE00_01_GAIN + (src) * 2)
127#define LOLA_BAR1_DEST00_MIX00_01_GAIN 0x10c4
128#define LOLA_BAR1_DEST00_MIX30_31_GAIN 0x1100
129#define LOLA_BAR1_DEST01_MIX00_01_GAIN 0x1104
130#define LOLA_BAR1_DEST01_MIX30_31_GAIN 0x1140
131#define LOLA_BAR1_DEST31_MIX00_01_GAIN 0x1884
132#define LOLA_BAR1_DEST31_MIX30_31_GAIN 0x18c0
133#define LOLA_BAR1_MIX_GAIN(dest, mix) \
134 (LOLA_BAR1_DEST00_MIX00_01_GAIN + (dest) * 0x40 + (mix) * 2)
135#define LOLA_BAR1_ANALOG_CLIP_IN 0x18c4
136#define LOLA_BAR1_PEAKMETERS_SOURCE00_01 0x18c8
137#define LOLA_BAR1_PEAKMETERS_SOURCE30_31 0x1904
138#define LOLA_BAR1_PEAKMETERS_SOURCE(src) \
139 (LOLA_BAR1_PEAKMETERS_SOURCE00_01 + (src) * 2)
140#define LOLA_BAR1_PEAKMETERS_DEST00_01 0x1908
141#define LOLA_BAR1_PEAKMETERS_DEST30_31 0x1944
142#define LOLA_BAR1_PEAKMETERS_DEST(dest) \
143 (LOLA_BAR1_PEAKMETERS_DEST00_01 + (dest) * 2)
144#define LOLA_BAR1_PEAKMETERS_AGC00_01 0x1948
145#define LOLA_BAR1_PEAKMETERS_AGC14_15 0x1964
146#define LOLA_BAR1_PEAKMETERS_AGC(x) \
147 (LOLA_BAR1_PEAKMETERS_AGC00_01 + (x) * 2)
148
149/* GCTL reset bit */
150#define LOLA_GCTL_RESET (1 << 0)
151/* GCTL unsolicited response enable bit */
152#define LOLA_GCTL_UREN (1 << 8)
153
154/* CORB/RIRB control, read/write pointer */
155#define LOLA_RBCTL_DMA_EN 0x02 /* enable DMA */
156#define LOLA_RBCTL_IRQ_EN 0x01 /* enable IRQ */
157#define LOLA_RBRWP_CLR 0x8000 /* read/write pointer clear */
158
159#define LOLA_RIRB_EX_UNSOL_EV 0x40000000
160#define LOLA_RIRB_EX_ERROR 0x80000000
161
162/* CORB int mask: CMEI[0] */
163#define LOLA_CORB_INT_CMEI 0x01
164#define LOLA_CORB_INT_MASK LOLA_CORB_INT_CMEI
165
166/* RIRB int mask: overrun[2], response[0] */
167#define LOLA_RIRB_INT_RESPONSE 0x01
168#define LOLA_RIRB_INT_OVERRUN 0x04
169#define LOLA_RIRB_INT_MASK (LOLA_RIRB_INT_RESPONSE | LOLA_RIRB_INT_OVERRUN)
170
171/* DINTCTL and DINTSTS */
172#define LOLA_DINT_GLOBAL 0x80000000 /* global interrupt enable bit */
173#define LOLA_DINT_CTRL 0x40000000 /* controller interrupt enable bit */
174#define LOLA_DINT_FIFOERR 0x20000000 /* global fifo error enable bit */
175#define LOLA_DINT_MUERR 0x10000000 /* global microcontroller underrun error */
176
177/* DSDnCTL bits */
178#define LOLA_DSD_CTL_SRST 0x01 /* stream reset bit */
179#define LOLA_DSD_CTL_SRUN 0x02 /* stream DMA start bit */
180#define LOLA_DSD_CTL_IOCE 0x04 /* interrupt on completion enable */
181#define LOLA_DSD_CTL_DEIE 0x10 /* descriptor error interrupt enable */
182#define LOLA_DSD_CTL_VLRCV 0x20 /* valid LRCountValue information in bits 8..31 */
183#define LOLA_LRC_MASK 0xffffff00
184
185/* DSDnSTS */
186#define LOLA_DSD_STS_BCIS 0x04 /* buffer completion interrupt status */
187#define LOLA_DSD_STS_DESE 0x10 /* descriptor error interrupt */
188#define LOLA_DSD_STS_FIFORDY 0x20 /* fifo ready */
189
190#define LOLA_CORB_ENTRIES 256
191
192#define MAX_STREAM_IN_COUNT 16
193#define MAX_STREAM_OUT_COUNT 16
194#define MAX_STREAM_COUNT 16
195#define MAX_PINS MAX_STREAM_COUNT
196#define MAX_STREAM_BUFFER_COUNT 16
197#define MAX_AUDIO_INOUT_COUNT 16
198
199#define LOLA_CLOCK_TYPE_INTERNAL 0
200#define LOLA_CLOCK_TYPE_AES 1
201#define LOLA_CLOCK_TYPE_AES_SYNC 2
202#define LOLA_CLOCK_TYPE_WORDCLOCK 3
203#define LOLA_CLOCK_TYPE_ETHERSOUND 4
204#define LOLA_CLOCK_TYPE_VIDEO 5
205
206#define LOLA_CLOCK_FORMAT_NONE 0
207#define LOLA_CLOCK_FORMAT_NTSC 1
208#define LOLA_CLOCK_FORMAT_PAL 2
209
210#define MAX_SAMPLE_CLOCK_COUNT 48
211
212/* parameters used with mixer widget's mixer capabilities */
213#define LOLA_PEAK_METER_CAN_AGC_MASK 1
214#define LOLA_PEAK_METER_CAN_ANALOG_CLIP_MASK 2
215
216struct lola_bar {
217 unsigned long addr;
218 void __iomem *remap_addr;
219};
220
221/* CORB/RIRB */
222struct lola_rb {
223 u32 *buf; /* CORB/RIRB buffer, 8 byte per each entry */
224 dma_addr_t addr; /* physical address of CORB/RIRB buffer */
225 unsigned short rp, wp; /* read/write pointers */
226 int cmds; /* number of pending requests */
227};
228
229/* Pin widget setup */
230struct lola_pin {
231 unsigned int nid;
232 bool is_analog;
233 unsigned int amp_mute;
234 unsigned int amp_step_size;
235 unsigned int amp_num_steps;
236 unsigned int amp_offset;
237 unsigned int max_level;
238 unsigned int config_default_reg;
239 unsigned int fixed_gain_list_len;
240 unsigned int cur_gain_step;
241};
242
243struct lola_pin_array {
244 unsigned int num_pins;
245 unsigned int num_analog_pins;
246 struct lola_pin pins[MAX_PINS];
247};
248
249/* Clock widget setup */
250struct lola_sample_clock {
251 unsigned int type;
252 unsigned int format;
253 unsigned int freq;
254};
255
256struct lola_clock_widget {
257 unsigned int nid;
258 unsigned int items;
259 unsigned int cur_index;
260 unsigned int cur_freq;
261 bool cur_valid;
262 struct lola_sample_clock sample_clock[MAX_SAMPLE_CLOCK_COUNT];
263 unsigned int idx_lookup[MAX_SAMPLE_CLOCK_COUNT];
264};
265
266#define LOLA_MIXER_DIM 32
267struct lola_mixer_array {
268 u32 src_gain_enable;
269 u32 dest_mix_gain_enable[LOLA_MIXER_DIM];
270 u16 src_gain[LOLA_MIXER_DIM];
271 u16 dest_mix_gain[LOLA_MIXER_DIM][LOLA_MIXER_DIM];
272};
273
274/* Mixer widget setup */
275struct lola_mixer_widget {
276 unsigned int nid;
277 unsigned int caps;
278 struct lola_mixer_array __user *array;
279 struct lola_mixer_array *array_saved;
280 unsigned int src_stream_outs;
281 unsigned int src_phys_ins;
282 unsigned int dest_stream_ins;
283 unsigned int dest_phys_outs;
284 unsigned int src_stream_out_ofs;
285 unsigned int dest_phys_out_ofs;
286 unsigned int src_mask;
287 unsigned int dest_mask;
288};
289
290/* Audio stream */
291struct lola_stream {
292 unsigned int nid; /* audio widget NID */
293 unsigned int index; /* array index */
294 unsigned int dsd; /* DSD index */
295 bool can_float;
296 struct snd_pcm_substream *substream; /* assigned PCM substream */
297 struct lola_stream *master; /* master stream (for multi-channel) */
298
299 /* buffer setup */
300 unsigned int bufsize;
301 unsigned int period_bytes;
302 unsigned int frags;
303
304 /* format + channel setup */
305 unsigned int format_verb;
306
307 /* flags */
308 unsigned int opened:1;
309 unsigned int prepared:1;
310 unsigned int paused:1;
311 unsigned int running:1;
312};
313
314#define PLAY SNDRV_PCM_STREAM_PLAYBACK
315#define CAPT SNDRV_PCM_STREAM_CAPTURE
316
317struct lola_pcm {
318 unsigned int num_streams;
319 struct snd_dma_buffer bdl; /* BDL buffer */
320 struct lola_stream streams[MAX_STREAM_COUNT];
321};
322
323/* card instance */
324struct lola {
325 struct snd_card *card;
326 struct pci_dev *pci;
327
328 /* pci resources */
329 struct lola_bar bar[2];
330 int irq;
331
332 /* locks */
333 spinlock_t reg_lock;
334 struct mutex open_mutex;
335
336 /* CORB/RIRB */
337 struct lola_rb corb;
338 struct lola_rb rirb;
339 unsigned int res, res_ex; /* last read values */
340 /* last command (for debugging) */
341 unsigned int last_cmd_nid, last_verb, last_data, last_extdata;
342
343 /* CORB/RIRB buffers */
344 struct snd_dma_buffer rb;
345
346 /* unsolicited events */
347 unsigned int last_unsol_res;
348
349 /* streams */
350 struct lola_pcm pcm[2];
351
352 /* input src */
353 unsigned int input_src_caps_mask;
354 unsigned int input_src_mask;
355
356 /* pins */
357 struct lola_pin_array pin[2];
358
359 /* clock */
360 struct lola_clock_widget clock;
361 int ref_count_rate;
362 unsigned int sample_rate;
363
364 /* mixer */
365 struct lola_mixer_widget mixer;
366
367 /* hw info */
368 unsigned int version;
369 unsigned int lola_caps;
370
371 /* parameters */
372 unsigned int granularity;
373 unsigned int sample_rate_min;
374 unsigned int sample_rate_max;
375
376 /* flags */
377 unsigned int initialized:1;
378 unsigned int cold_reset:1;
379 unsigned int polling_mode:1;
380
381 /* for debugging */
382 unsigned int debug_res;
383 unsigned int debug_res_ex;
384};
385
386#define BAR0 0
387#define BAR1 1
388
389/* Helper macros */
390#define lola_readl(chip, idx, name) \
391 readl((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
392#define lola_readw(chip, idx, name) \
393 readw((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
394#define lola_readb(chip, idx, name) \
395 readb((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
396#define lola_writel(chip, idx, name, val) \
397 writel((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
398#define lola_writew(chip, idx, name, val) \
399 writew((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
400#define lola_writeb(chip, idx, name, val) \
401 writeb((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
402
403#define lola_dsd_read(chip, dsd, name) \
404 readl((chip)->bar[BAR1].remap_addr + LOLA_BAR1_DSD0_OFFSET + \
405 (LOLA_BAR1_DSD_SIZE * (dsd)) + LOLA_BAR1_DSDn##name)
406#define lola_dsd_write(chip, dsd, name, val) \
407 writel((val), (chip)->bar[BAR1].remap_addr + LOLA_BAR1_DSD0_OFFSET + \
408 (LOLA_BAR1_DSD_SIZE * (dsd)) + LOLA_BAR1_DSDn##name)
409
410/* GET verbs HDAudio */
411#define LOLA_VERB_GET_STREAM_FORMAT 0xa00
412#define LOLA_VERB_GET_AMP_GAIN_MUTE 0xb00
413#define LOLA_VERB_PARAMETERS 0xf00
414#define LOLA_VERB_GET_POWER_STATE 0xf05
415#define LOLA_VERB_GET_CONV 0xf06
416#define LOLA_VERB_GET_UNSOLICITED_RESPONSE 0xf08
417#define LOLA_VERB_GET_DIGI_CONVERT_1 0xf0d
418#define LOLA_VERB_GET_CONFIG_DEFAULT 0xf1c
419#define LOLA_VERB_GET_SUBSYSTEM_ID 0xf20
420/* GET verbs Digigram */
421#define LOLA_VERB_GET_FIXED_GAIN 0xfc0
422#define LOLA_VERB_GET_GAIN_SELECT 0xfc1
423#define LOLA_VERB_GET_MAX_LEVEL 0xfc2
424#define LOLA_VERB_GET_CLOCK_LIST 0xfc3
425#define LOLA_VERB_GET_CLOCK_SELECT 0xfc4
426#define LOLA_VERB_GET_CLOCK_STATUS 0xfc5
427
428/* SET verbs HDAudio */
429#define LOLA_VERB_SET_STREAM_FORMAT 0x200
430#define LOLA_VERB_SET_AMP_GAIN_MUTE 0x300
431#define LOLA_VERB_SET_POWER_STATE 0x705
432#define LOLA_VERB_SET_CHANNEL_STREAMID 0x706
433#define LOLA_VERB_SET_UNSOLICITED_ENABLE 0x708
434#define LOLA_VERB_SET_DIGI_CONVERT_1 0x70d
435/* SET verbs Digigram */
436#define LOLA_VERB_SET_GAIN_SELECT 0xf81
437#define LOLA_VERB_SET_CLOCK_SELECT 0xf84
438#define LOLA_VERB_SET_GRANULARITY_STEPS 0xf86
439#define LOLA_VERB_SET_SOURCE_GAIN 0xf87
440#define LOLA_VERB_SET_MIX_GAIN 0xf88
441#define LOLA_VERB_SET_DESTINATION_GAIN 0xf89
442#define LOLA_VERB_SET_SRC 0xf8a
443
444/* Parameter IDs used with LOLA_VERB_PARAMETERS */
445#define LOLA_PAR_VENDOR_ID 0x00
446#define LOLA_PAR_FUNCTION_TYPE 0x05
447#define LOLA_PAR_AUDIO_WIDGET_CAP 0x09
448#define LOLA_PAR_PCM 0x0a
449#define LOLA_PAR_STREAM_FORMATS 0x0b
450#define LOLA_PAR_PIN_CAP 0x0c
451#define LOLA_PAR_AMP_IN_CAP 0x0d
452#define LOLA_PAR_CONNLIST_LEN 0x0e
453#define LOLA_PAR_POWER_STATE 0x0f
454#define LOLA_PAR_GPIO_CAP 0x11
455#define LOLA_PAR_AMP_OUT_CAP 0x12
456#define LOLA_PAR_SPECIFIC_CAPS 0x80
457#define LOLA_PAR_FIXED_GAIN_LIST 0x81
458
459/* extract results of LOLA_PAR_SPECIFIC_CAPS */
460#define LOLA_AFG_MIXER_WIDGET_PRESENT(res) ((res & (1 << 21)) != 0)
461#define LOLA_AFG_CLOCK_WIDGET_PRESENT(res) ((res & (1 << 20)) != 0)
462#define LOLA_AFG_INPUT_PIN_COUNT(res) ((res >> 10) & 0x2ff)
463#define LOLA_AFG_OUTPUT_PIN_COUNT(res) ((res) & 0x2ff)
464
465/* extract results of LOLA_PAR_AMP_IN_CAP / LOLA_PAR_AMP_OUT_CAP */
466#define LOLA_AMP_MUTE_CAPABLE(res) ((res & (1 << 31)) != 0)
467#define LOLA_AMP_STEP_SIZE(res) ((res >> 24) & 0x7f)
468#define LOLA_AMP_NUM_STEPS(res) ((res >> 12) & 0x3ff)
469#define LOLA_AMP_OFFSET(res) ((res) & 0x3ff)
470
471#define LOLA_GRANULARITY_MIN 8
472#define LOLA_GRANULARITY_MAX 32
473#define LOLA_GRANULARITY_STEP 8
474
475/* parameters used with unsolicited command/response */
476#define LOLA_UNSOLICITED_TAG_MASK 0x3f
477#define LOLA_UNSOLICITED_TAG 0x1a
478#define LOLA_UNSOLICITED_ENABLE 0x80
479#define LOLA_UNSOL_RESP_TAG_OFFSET 26
480
481/* count values in the Vendor Specific Mixer Widget's Audio Widget Capabilities */
482#define LOLA_MIXER_SRC_INPUT_PLAY_SEPARATION(res) ((res >> 2) & 0x1f)
483#define LOLA_MIXER_DEST_REC_OUTPUT_SEPATATION(res) ((res >> 7) & 0x1f)
484
485int lola_codec_write(struct lola *chip, unsigned int nid, unsigned int verb,
486 unsigned int data, unsigned int extdata);
487int lola_codec_read(struct lola *chip, unsigned int nid, unsigned int verb,
488 unsigned int data, unsigned int extdata,
489 unsigned int *val, unsigned int *extval);
490int lola_codec_flush(struct lola *chip);
491#define lola_read_param(chip, nid, param, val) \
492 lola_codec_read(chip, nid, LOLA_VERB_PARAMETERS, param, 0, val, NULL)
493
494/* PCM */
495int lola_create_pcm(struct lola *chip);
496void lola_free_pcm(struct lola *chip);
497int lola_init_pcm(struct lola *chip, int dir, int *nidp);
498void lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits);
499
500/* clock */
501int lola_init_clock_widget(struct lola *chip, int nid);
502int lola_set_granularity(struct lola *chip, unsigned int val, bool force);
503int lola_enable_clock_events(struct lola *chip);
504int lola_set_clock_index(struct lola *chip, unsigned int idx);
505int lola_set_clock(struct lola *chip, int idx);
506int lola_set_sample_rate(struct lola *chip, int rate);
507bool lola_update_ext_clock_freq(struct lola *chip, unsigned int val);
508unsigned int lola_sample_rate_convert(unsigned int coded);
509
510/* mixer */
511int lola_init_pins(struct lola *chip, int dir, int *nidp);
512int lola_init_mixer_widget(struct lola *chip, int nid);
513void lola_free_mixer(struct lola *chip);
514int lola_create_mixer(struct lola *chip);
515int lola_setup_all_analog_gains(struct lola *chip, int dir, bool mute);
516void lola_save_mixer(struct lola *chip);
517void lola_restore_mixer(struct lola *chip);
518int lola_set_src_config(struct lola *chip, unsigned int src_mask, bool update);
519
520/* proc */
521#ifdef CONFIG_SND_DEBUG
522void lola_proc_debug_new(struct lola *chip);
523#else
524#define lola_proc_debug_new(chip)
525#endif
526
527#endif /* _LOLA_H */
diff --git a/sound/pci/lola/lola_clock.c b/sound/pci/lola/lola_clock.c
new file mode 100644
index 000000000000..72f8ef0ac865
--- /dev/null
+++ b/sound/pci/lola/lola_clock.c
@@ -0,0 +1,323 @@
1/*
2 * Support for Digigram Lola PCI-e boards
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/delay.h>
24#include <sound/core.h>
25#include <sound/pcm.h>
26#include "lola.h"
27
28unsigned int lola_sample_rate_convert(unsigned int coded)
29{
30 unsigned int freq;
31
32 /* base frequency */
33 switch (coded & 0x3) {
34 case 0: freq = 48000; break;
35 case 1: freq = 44100; break;
36 case 2: freq = 32000; break;
37 default: return 0; /* error */
38 }
39
40 /* multiplier / devisor */
41 switch (coded & 0x1c) {
42 case (0 << 2): break;
43 case (4 << 2): break;
44 case (1 << 2): freq *= 2; break;
45 case (2 << 2): freq *= 4; break;
46 case (5 << 2): freq /= 2; break;
47 case (6 << 2): freq /= 4; break;
48 default: return 0; /* error */
49 }
50
51 /* ajustement */
52 switch (coded & 0x60) {
53 case (0 << 5): break;
54 case (1 << 5): freq = (freq * 999) / 1000; break;
55 case (2 << 5): freq = (freq * 1001) / 1000; break;
56 default: return 0; /* error */
57 }
58 return freq;
59}
60
61/*
62 * Granualrity
63 */
64
65#define LOLA_MAXFREQ_AT_GRANULARITY_MIN 48000
66#define LOLA_MAXFREQ_AT_GRANULARITY_BELOW_MAX 96000
67
68static bool check_gran_clock_compatibility(struct lola *chip,
69 unsigned int val,
70 unsigned int freq)
71{
72 if (!chip->granularity)
73 return true;
74
75 if (val < LOLA_GRANULARITY_MIN || val > LOLA_GRANULARITY_MAX ||
76 (val % LOLA_GRANULARITY_STEP) != 0)
77 return false;
78
79 if (val == LOLA_GRANULARITY_MIN) {
80 if (freq > LOLA_MAXFREQ_AT_GRANULARITY_MIN)
81 return false;
82 } else if (val < LOLA_GRANULARITY_MAX) {
83 if (freq > LOLA_MAXFREQ_AT_GRANULARITY_BELOW_MAX)
84 return false;
85 }
86 return true;
87}
88
89int lola_set_granularity(struct lola *chip, unsigned int val, bool force)
90{
91 int err;
92
93 if (!force) {
94 if (val == chip->granularity)
95 return 0;
96#if 0
97 /* change Gran only if there are no streams allocated ! */
98 if (chip->audio_in_alloc_mask || chip->audio_out_alloc_mask)
99 return -EBUSY;
100#endif
101 if (!check_gran_clock_compatibility(chip, val,
102 chip->clock.cur_freq))
103 return -EINVAL;
104 }
105
106 chip->granularity = val;
107 val /= LOLA_GRANULARITY_STEP;
108
109 /* audio function group */
110 err = lola_codec_write(chip, 1, LOLA_VERB_SET_GRANULARITY_STEPS,
111 val, 0);
112 if (err < 0)
113 return err;
114 /* this can be a very slow function !!! */
115 usleep_range(400 * val, 20000);
116 return lola_codec_flush(chip);
117}
118
119/*
120 * Clock widget handling
121 */
122
123int __devinit lola_init_clock_widget(struct lola *chip, int nid)
124{
125 unsigned int val;
126 int i, j, nitems, nb_verbs, idx, idx_list;
127 int err;
128
129 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
130 if (err < 0) {
131 printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid);
132 return err;
133 }
134
135 if ((val & 0xfff00000) != 0x01f00000) { /* test SubType and Type */
136 snd_printdd("No valid clock widget\n");
137 return 0;
138 }
139
140 chip->clock.nid = nid;
141 chip->clock.items = val & 0xff;
142 snd_printdd("clock_list nid=%x, entries=%d\n", nid,
143 chip->clock.items);
144 if (chip->clock.items > MAX_SAMPLE_CLOCK_COUNT) {
145 printk(KERN_ERR SFX "CLOCK_LIST too big: %d\n",
146 chip->clock.items);
147 return -EINVAL;
148 }
149
150 nitems = chip->clock.items;
151 nb_verbs = (nitems + 3) / 4;
152 idx = 0;
153 idx_list = 0;
154 for (i = 0; i < nb_verbs; i++) {
155 unsigned int res_ex;
156 unsigned short items[4];
157
158 err = lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST,
159 idx, 0, &val, &res_ex);
160 if (err < 0) {
161 printk(KERN_ERR SFX "Can't read CLOCK_LIST\n");
162 return -EINVAL;
163 }
164
165 items[0] = val & 0xfff;
166 items[1] = (val >> 16) & 0xfff;
167 items[2] = res_ex & 0xfff;
168 items[3] = (res_ex >> 16) & 0xfff;
169
170 for (j = 0; j < 4; j++) {
171 unsigned char type = items[j] >> 8;
172 unsigned int freq = items[j] & 0xff;
173 int format = LOLA_CLOCK_FORMAT_NONE;
174 bool add_clock = true;
175 if (type == LOLA_CLOCK_TYPE_INTERNAL) {
176 freq = lola_sample_rate_convert(freq);
177 if (freq < chip->sample_rate_min)
178 add_clock = false;
179 else if (freq == 48000) {
180 chip->clock.cur_index = idx_list;
181 chip->clock.cur_freq = 48000;
182 chip->clock.cur_valid = true;
183 }
184 } else if (type == LOLA_CLOCK_TYPE_VIDEO) {
185 freq = lola_sample_rate_convert(freq);
186 if (freq < chip->sample_rate_min)
187 add_clock = false;
188 /* video clock has a format (0:NTSC, 1:PAL)*/
189 if (items[j] & 0x80)
190 format = LOLA_CLOCK_FORMAT_NTSC;
191 else
192 format = LOLA_CLOCK_FORMAT_PAL;
193 }
194 if (add_clock) {
195 struct lola_sample_clock *sc;
196 sc = &chip->clock.sample_clock[idx_list];
197 sc->type = type;
198 sc->format = format;
199 sc->freq = freq;
200 /* keep the index used with the board */
201 chip->clock.idx_lookup[idx_list] = idx;
202 idx_list++;
203 } else {
204 chip->clock.items--;
205 }
206 if (++idx >= nitems)
207 break;
208 }
209 }
210 return 0;
211}
212
213/* enable unsolicited events of the clock widget */
214int lola_enable_clock_events(struct lola *chip)
215{
216 unsigned int res;
217 int err;
218
219 err = lola_codec_read(chip, chip->clock.nid,
220 LOLA_VERB_SET_UNSOLICITED_ENABLE,
221 LOLA_UNSOLICITED_ENABLE | LOLA_UNSOLICITED_TAG,
222 0, &res, NULL);
223 if (err < 0)
224 return err;
225 if (res) {
226 printk(KERN_WARNING SFX "error in enable_clock_events %d\n",
227 res);
228 return -EINVAL;
229 }
230 return 0;
231}
232
233int lola_set_clock_index(struct lola *chip, unsigned int idx)
234{
235 unsigned int res;
236 int err;
237
238 err = lola_codec_read(chip, chip->clock.nid,
239 LOLA_VERB_SET_CLOCK_SELECT,
240 chip->clock.idx_lookup[idx],
241 0, &res, NULL);
242 if (err < 0)
243 return err;
244 if (res) {
245 printk(KERN_WARNING SFX "error in set_clock %d\n", res);
246 return -EINVAL;
247 }
248 return 0;
249}
250
251bool lola_update_ext_clock_freq(struct lola *chip, unsigned int val)
252{
253 unsigned int tag;
254
255 /* the current EXTERNAL clock information gets updated by interrupt
256 * with an unsolicited response
257 */
258 if (!val)
259 return false;
260 tag = (val >> LOLA_UNSOL_RESP_TAG_OFFSET) & LOLA_UNSOLICITED_TAG_MASK;
261 if (tag != LOLA_UNSOLICITED_TAG)
262 return false;
263
264 /* only for current = external clocks */
265 if (chip->clock.sample_clock[chip->clock.cur_index].type !=
266 LOLA_CLOCK_TYPE_INTERNAL) {
267 chip->clock.cur_freq = lola_sample_rate_convert(val & 0x7f);
268 chip->clock.cur_valid = (val & 0x100) != 0;
269 }
270 return true;
271}
272
273int lola_set_clock(struct lola *chip, int idx)
274{
275 int freq = 0;
276 bool valid = false;
277
278 if (idx == chip->clock.cur_index) {
279 /* current clock is allowed */
280 freq = chip->clock.cur_freq;
281 valid = chip->clock.cur_valid;
282 } else if (chip->clock.sample_clock[idx].type ==
283 LOLA_CLOCK_TYPE_INTERNAL) {
284 /* internal clocks allowed */
285 freq = chip->clock.sample_clock[idx].freq;
286 valid = true;
287 }
288
289 if (!freq || !valid)
290 return -EINVAL;
291
292 if (!check_gran_clock_compatibility(chip, chip->granularity, freq))
293 return -EINVAL;
294
295 if (idx != chip->clock.cur_index) {
296 int err = lola_set_clock_index(chip, idx);
297 if (err < 0)
298 return err;
299 /* update new settings */
300 chip->clock.cur_index = idx;
301 chip->clock.cur_freq = freq;
302 chip->clock.cur_valid = true;
303 }
304 return 0;
305}
306
307int lola_set_sample_rate(struct lola *chip, int rate)
308{
309 int i;
310
311 if (chip->clock.cur_freq == rate && chip->clock.cur_valid)
312 return 0;
313 /* search for new dwClockIndex */
314 for (i = 0; i < chip->clock.items; i++) {
315 if (chip->clock.sample_clock[i].type == LOLA_CLOCK_TYPE_INTERNAL &&
316 chip->clock.sample_clock[i].freq == rate)
317 break;
318 }
319 if (i >= chip->clock.items)
320 return -EINVAL;
321 return lola_set_clock(chip, i);
322}
323
diff --git a/sound/pci/lola/lola_mixer.c b/sound/pci/lola/lola_mixer.c
new file mode 100644
index 000000000000..5d518f1a712c
--- /dev/null
+++ b/sound/pci/lola/lola_mixer.c
@@ -0,0 +1,839 @@
1/*
2 * Support for Digigram Lola PCI-e boards
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/vmalloc.h>
24#include <linux/io.h>
25#include <sound/core.h>
26#include <sound/control.h>
27#include <sound/pcm.h>
28#include <sound/tlv.h>
29#include "lola.h"
30
31static int __devinit lola_init_pin(struct lola *chip, struct lola_pin *pin,
32 int dir, int nid)
33{
34 unsigned int val;
35 int err;
36
37 pin->nid = nid;
38 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
39 if (err < 0) {
40 printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid);
41 return err;
42 }
43 val &= 0x00f00fff; /* test TYPE and bits 0..11 */
44 if (val == 0x00400200) /* Type = 4, Digital = 1 */
45 pin->is_analog = false;
46 else if (val == 0x0040000a && dir == CAPT) /* Dig=0, InAmp/ovrd */
47 pin->is_analog = true;
48 else if (val == 0x0040000c && dir == PLAY) /* Dig=0, OutAmp/ovrd */
49 pin->is_analog = true;
50 else {
51 printk(KERN_ERR SFX "Invalid wcaps 0x%x for 0x%x\n", val, nid);
52 return -EINVAL;
53 }
54
55 /* analog parameters only following, so continue in case of Digital pin
56 */
57 if (!pin->is_analog)
58 return 0;
59
60 if (dir == PLAY)
61 err = lola_read_param(chip, nid, LOLA_PAR_AMP_OUT_CAP, &val);
62 else
63 err = lola_read_param(chip, nid, LOLA_PAR_AMP_IN_CAP, &val);
64 if (err < 0) {
65 printk(KERN_ERR SFX "Can't read AMP-caps for 0x%x\n", nid);
66 return err;
67 }
68
69 pin->amp_mute = LOLA_AMP_MUTE_CAPABLE(val);
70 pin->amp_step_size = LOLA_AMP_STEP_SIZE(val);
71 pin->amp_num_steps = LOLA_AMP_NUM_STEPS(val);
72 if (pin->amp_num_steps) {
73 /* zero as mute state */
74 pin->amp_num_steps++;
75 pin->amp_step_size++;
76 }
77 pin->amp_offset = LOLA_AMP_OFFSET(val);
78
79 err = lola_codec_read(chip, nid, LOLA_VERB_GET_MAX_LEVEL, 0, 0, &val,
80 NULL);
81 if (err < 0) {
82 printk(KERN_ERR SFX "Can't get MAX_LEVEL 0x%x\n", nid);
83 return err;
84 }
85 pin->max_level = val & 0x3ff; /* 10 bits */
86
87 pin->config_default_reg = 0;
88 pin->fixed_gain_list_len = 0;
89 pin->cur_gain_step = 0;
90
91 return 0;
92}
93
94int __devinit lola_init_pins(struct lola *chip, int dir, int *nidp)
95{
96 int i, err, nid;
97 nid = *nidp;
98 for (i = 0; i < chip->pin[dir].num_pins; i++, nid++) {
99 err = lola_init_pin(chip, &chip->pin[dir].pins[i], dir, nid);
100 if (err < 0)
101 return err;
102 if (chip->pin[dir].pins[i].is_analog)
103 chip->pin[dir].num_analog_pins++;
104 }
105 *nidp = nid;
106 return 0;
107}
108
109void lola_free_mixer(struct lola *chip)
110{
111 if (chip->mixer.array_saved)
112 vfree(chip->mixer.array_saved);
113}
114
115int __devinit lola_init_mixer_widget(struct lola *chip, int nid)
116{
117 unsigned int val;
118 int err;
119
120 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
121 if (err < 0) {
122 printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid);
123 return err;
124 }
125
126 if ((val & 0xfff00000) != 0x02f00000) { /* test SubType and Type */
127 snd_printdd("No valid mixer widget\n");
128 return 0;
129 }
130
131 chip->mixer.nid = nid;
132 chip->mixer.caps = val;
133 chip->mixer.array = (struct lola_mixer_array __iomem *)
134 (chip->bar[BAR1].remap_addr + LOLA_BAR1_SOURCE_GAIN_ENABLE);
135
136 /* reserve memory to copy mixer data for sleep mode transitions */
137 chip->mixer.array_saved = vmalloc(sizeof(struct lola_mixer_array));
138
139 /* mixer matrix sources are physical input data and play streams */
140 chip->mixer.src_stream_outs = chip->pcm[PLAY].num_streams;
141 chip->mixer.src_phys_ins = chip->pin[CAPT].num_pins;
142
143 /* mixer matrix destinations are record streams and physical output */
144 chip->mixer.dest_stream_ins = chip->pcm[CAPT].num_streams;
145 chip->mixer.dest_phys_outs = chip->pin[PLAY].num_pins;
146
147 /* mixer matrix can have unused areas between PhysIn and
148 * Play or Record and PhysOut zones
149 */
150 chip->mixer.src_stream_out_ofs = chip->mixer.src_phys_ins +
151 LOLA_MIXER_SRC_INPUT_PLAY_SEPARATION(val);
152 chip->mixer.dest_phys_out_ofs = chip->mixer.dest_stream_ins +
153 LOLA_MIXER_DEST_REC_OUTPUT_SEPATATION(val);
154
155 /* example : MixerMatrix of LoLa881
156 * 0-------8------16-------8------16
157 * | | | | |
158 * | INPUT | | INPUT | |
159 * | -> |unused | -> |unused |
160 * | RECORD| | OUTPUT| |
161 * | | | | |
162 * 8--------------------------------
163 * | | | | |
164 * | | | | |
165 * |unused |unused |unused |unused |
166 * | | | | |
167 * | | | | |
168 * 16-------------------------------
169 * | | | | |
170 * | PLAY | | PLAY | |
171 * | -> |unused | -> |unused |
172 * | RECORD| | OUTPUT| |
173 * | | | | |
174 * 8--------------------------------
175 * | | | | |
176 * | | | | |
177 * |unused |unused |unused |unused |
178 * | | | | |
179 * | | | | |
180 * 16-------------------------------
181 */
182 if (chip->mixer.src_stream_out_ofs > MAX_AUDIO_INOUT_COUNT ||
183 chip->mixer.dest_phys_out_ofs > MAX_STREAM_IN_COUNT) {
184 printk(KERN_ERR SFX "Invalid mixer widget size\n");
185 return -EINVAL;
186 }
187
188 chip->mixer.src_mask = ((1U << chip->mixer.src_phys_ins) - 1) |
189 (((1U << chip->mixer.src_stream_outs) - 1)
190 << chip->mixer.src_stream_out_ofs);
191 chip->mixer.dest_mask = ((1U << chip->mixer.dest_stream_ins) - 1) |
192 (((1U << chip->mixer.dest_phys_outs) - 1)
193 << chip->mixer.dest_phys_out_ofs);
194
195 return 0;
196}
197
198static int lola_mixer_set_src_gain(struct lola *chip, unsigned int id,
199 unsigned short gain, bool on)
200{
201 unsigned int oldval, val;
202
203 if (!(chip->mixer.src_mask & (1 << id)))
204 return -EINVAL;
205 writew(gain, &chip->mixer.array->src_gain[id]);
206 oldval = val = readl(&chip->mixer.array->src_gain_enable);
207 if (on)
208 val |= (1 << id);
209 else
210 val &= ~(1 << id);
211 writel(val, &chip->mixer.array->src_gain_enable);
212 lola_codec_flush(chip);
213 /* inform micro-controller about the new source gain */
214 return lola_codec_write(chip, chip->mixer.nid,
215 LOLA_VERB_SET_SOURCE_GAIN, id, 0);
216}
217
218#if 0 /* not used */
219static int lola_mixer_set_src_gains(struct lola *chip, unsigned int mask,
220 unsigned short *gains)
221{
222 int i;
223
224 if ((chip->mixer.src_mask & mask) != mask)
225 return -EINVAL;
226 for (i = 0; i < LOLA_MIXER_DIM; i++) {
227 if (mask & (1 << i)) {
228 writew(*gains, &chip->mixer.array->src_gain[i]);
229 gains++;
230 }
231 }
232 writel(mask, &chip->mixer.array->src_gain_enable);
233 lola_codec_flush(chip);
234 if (chip->mixer.caps & LOLA_PEAK_METER_CAN_AGC_MASK) {
235 /* update for all srcs at once */
236 return lola_codec_write(chip, chip->mixer.nid,
237 LOLA_VERB_SET_SOURCE_GAIN, 0x80, 0);
238 }
239 /* update manually */
240 for (i = 0; i < LOLA_MIXER_DIM; i++) {
241 if (mask & (1 << i)) {
242 lola_codec_write(chip, chip->mixer.nid,
243 LOLA_VERB_SET_SOURCE_GAIN, i, 0);
244 }
245 }
246 return 0;
247}
248#endif /* not used */
249
250static int lola_mixer_set_mapping_gain(struct lola *chip,
251 unsigned int src, unsigned int dest,
252 unsigned short gain, bool on)
253{
254 unsigned int val;
255
256 if (!(chip->mixer.src_mask & (1 << src)) ||
257 !(chip->mixer.dest_mask & (1 << dest)))
258 return -EINVAL;
259 if (on)
260 writew(gain, &chip->mixer.array->dest_mix_gain[dest][src]);
261 val = readl(&chip->mixer.array->dest_mix_gain_enable[dest]);
262 if (on)
263 val |= (1 << src);
264 else
265 val &= ~(1 << src);
266 writel(val, &chip->mixer.array->dest_mix_gain_enable[dest]);
267 lola_codec_flush(chip);
268 return lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_MIX_GAIN,
269 src, dest);
270}
271
272static int lola_mixer_set_dest_gains(struct lola *chip, unsigned int id,
273 unsigned int mask, unsigned short *gains)
274{
275 int i;
276
277 if (!(chip->mixer.dest_mask & (1 << id)) ||
278 (chip->mixer.src_mask & mask) != mask)
279 return -EINVAL;
280 for (i = 0; i < LOLA_MIXER_DIM; i++) {
281 if (mask & (1 << i)) {
282 writew(*gains, &chip->mixer.array->dest_mix_gain[id][i]);
283 gains++;
284 }
285 }
286 writel(mask, &chip->mixer.array->dest_mix_gain_enable[id]);
287 lola_codec_flush(chip);
288 /* update for all dests at once */
289 return lola_codec_write(chip, chip->mixer.nid,
290 LOLA_VERB_SET_DESTINATION_GAIN, id, 0);
291}
292
293/*
294 */
295
296static int set_analog_volume(struct lola *chip, int dir,
297 unsigned int idx, unsigned int val,
298 bool external_call);
299
300int lola_setup_all_analog_gains(struct lola *chip, int dir, bool mute)
301{
302 struct lola_pin *pin;
303 int idx, max_idx;
304
305 pin = chip->pin[dir].pins;
306 max_idx = chip->pin[dir].num_pins;
307 for (idx = 0; idx < max_idx; idx++) {
308 if (pin[idx].is_analog) {
309 unsigned int val = mute ? 0 : pin[idx].cur_gain_step;
310 /* set volume and do not save the value */
311 set_analog_volume(chip, dir, idx, val, false);
312 }
313 }
314 return lola_codec_flush(chip);
315}
316
317void lola_save_mixer(struct lola *chip)
318{
319 /* mute analog output */
320 if (chip->mixer.array_saved) {
321 /* store contents of mixer array */
322 memcpy_fromio(chip->mixer.array_saved, chip->mixer.array,
323 sizeof(*chip->mixer.array));
324 }
325 lola_setup_all_analog_gains(chip, PLAY, true); /* output mute */
326}
327
328void lola_restore_mixer(struct lola *chip)
329{
330 int i;
331
332 /*lola_reset_setups(chip);*/
333 if (chip->mixer.array_saved) {
334 /* restore contents of mixer array */
335 memcpy_toio(chip->mixer.array, chip->mixer.array_saved,
336 sizeof(*chip->mixer.array));
337 /* inform micro-controller about all restored values
338 * and ignore return values
339 */
340 for (i = 0; i < chip->mixer.src_phys_ins; i++)
341 lola_codec_write(chip, chip->mixer.nid,
342 LOLA_VERB_SET_SOURCE_GAIN,
343 i, 0);
344 for (i = 0; i < chip->mixer.src_stream_outs; i++)
345 lola_codec_write(chip, chip->mixer.nid,
346 LOLA_VERB_SET_SOURCE_GAIN,
347 chip->mixer.src_stream_out_ofs + i, 0);
348 for (i = 0; i < chip->mixer.dest_stream_ins; i++)
349 lola_codec_write(chip, chip->mixer.nid,
350 LOLA_VERB_SET_DESTINATION_GAIN,
351 i, 0);
352 for (i = 0; i < chip->mixer.dest_phys_outs; i++)
353 lola_codec_write(chip, chip->mixer.nid,
354 LOLA_VERB_SET_DESTINATION_GAIN,
355 chip->mixer.dest_phys_out_ofs + i, 0);
356 lola_codec_flush(chip);
357 }
358}
359
360/*
361 */
362
363static int set_analog_volume(struct lola *chip, int dir,
364 unsigned int idx, unsigned int val,
365 bool external_call)
366{
367 struct lola_pin *pin;
368 int err;
369
370 if (idx >= chip->pin[dir].num_pins)
371 return -EINVAL;
372 pin = &chip->pin[dir].pins[idx];
373 if (!pin->is_analog || pin->amp_num_steps <= val)
374 return -EINVAL;
375 if (external_call && pin->cur_gain_step == val)
376 return 0;
377 if (external_call)
378 lola_codec_flush(chip);
379 err = lola_codec_write(chip, pin->nid,
380 LOLA_VERB_SET_AMP_GAIN_MUTE, val, 0);
381 if (err < 0)
382 return err;
383 if (external_call)
384 pin->cur_gain_step = val;
385 return 0;
386}
387
388int lola_set_src_config(struct lola *chip, unsigned int src_mask, bool update)
389{
390 int ret = 0;
391 int success = 0;
392 int n, err;
393
394 /* SRC can be activated and the dwInputSRCMask is valid? */
395 if ((chip->input_src_caps_mask & src_mask) != src_mask)
396 return -EINVAL;
397 /* handle all even Inputs - SRC is a stereo setting !!! */
398 for (n = 0; n < chip->pin[CAPT].num_pins; n += 2) {
399 unsigned int mask = 3U << n; /* handle the stereo case */
400 unsigned int new_src, src_state;
401 if (!(chip->input_src_caps_mask & mask))
402 continue;
403 /* if one IO needs SRC, both stereo IO will get SRC */
404 new_src = (src_mask & mask) != 0;
405 if (update) {
406 src_state = (chip->input_src_mask & mask) != 0;
407 if (src_state == new_src)
408 continue; /* nothing to change for this IO */
409 }
410 err = lola_codec_write(chip, chip->pcm[CAPT].streams[n].nid,
411 LOLA_VERB_SET_SRC, new_src, 0);
412 if (!err)
413 success++;
414 else
415 ret = err;
416 }
417 if (success)
418 ret = lola_codec_flush(chip);
419 if (!ret)
420 chip->input_src_mask = src_mask;
421 return ret;
422}
423
424/*
425 */
426static int init_mixer_values(struct lola *chip)
427{
428 int i;
429
430 /* all src on */
431 lola_set_src_config(chip, (1 << chip->pin[CAPT].num_pins) - 1, false);
432
433 /* clear all matrix */
434 memset_io(chip->mixer.array, 0, sizeof(*chip->mixer.array));
435 /* set src gain to 0dB */
436 for (i = 0; i < chip->mixer.src_phys_ins; i++)
437 lola_mixer_set_src_gain(chip, i, 336, true); /* 0dB */
438 for (i = 0; i < chip->mixer.src_stream_outs; i++)
439 lola_mixer_set_src_gain(chip,
440 i + chip->mixer.src_stream_out_ofs,
441 336, true); /* 0dB */
442 /* set 1:1 dest gain */
443 for (i = 0; i < chip->mixer.dest_stream_ins; i++) {
444 int src = i % chip->mixer.src_phys_ins;
445 lola_mixer_set_mapping_gain(chip, src, i, 336, true);
446 }
447 for (i = 0; i < chip->mixer.src_stream_outs; i++) {
448 int src = chip->mixer.src_stream_out_ofs + i;
449 int dst = chip->mixer.dest_phys_out_ofs +
450 i % chip->mixer.dest_phys_outs;
451 lola_mixer_set_mapping_gain(chip, src, dst, 336, true);
452 }
453 return 0;
454}
455
456/*
457 * analog mixer control element
458 */
459static int lola_analog_vol_info(struct snd_kcontrol *kcontrol,
460 struct snd_ctl_elem_info *uinfo)
461{
462 struct lola *chip = snd_kcontrol_chip(kcontrol);
463 int dir = kcontrol->private_value;
464
465 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
466 uinfo->count = chip->pin[dir].num_pins;
467 uinfo->value.integer.min = 0;
468 uinfo->value.integer.max = chip->pin[dir].pins[0].amp_num_steps;
469 return 0;
470}
471
472static int lola_analog_vol_get(struct snd_kcontrol *kcontrol,
473 struct snd_ctl_elem_value *ucontrol)
474{
475 struct lola *chip = snd_kcontrol_chip(kcontrol);
476 int dir = kcontrol->private_value;
477 int i;
478
479 for (i = 0; i < chip->pin[dir].num_pins; i++)
480 ucontrol->value.integer.value[i] =
481 chip->pin[dir].pins[i].cur_gain_step;
482 return 0;
483}
484
485static int lola_analog_vol_put(struct snd_kcontrol *kcontrol,
486 struct snd_ctl_elem_value *ucontrol)
487{
488 struct lola *chip = snd_kcontrol_chip(kcontrol);
489 int dir = kcontrol->private_value;
490 int i, err;
491
492 for (i = 0; i < chip->pin[dir].num_pins; i++) {
493 err = set_analog_volume(chip, dir, i,
494 ucontrol->value.integer.value[i],
495 true);
496 if (err < 0)
497 return err;
498 }
499 return 0;
500}
501
502static int lola_analog_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
503 unsigned int size, unsigned int __user *tlv)
504{
505 struct lola *chip = snd_kcontrol_chip(kcontrol);
506 int dir = kcontrol->private_value;
507 unsigned int val1, val2;
508 struct lola_pin *pin;
509
510 if (size < 4 * sizeof(unsigned int))
511 return -ENOMEM;
512 pin = &chip->pin[dir].pins[0];
513
514 val2 = pin->amp_step_size * 25;
515 val1 = -1 * (int)pin->amp_offset * (int)val2;
516#ifdef TLV_DB_SCALE_MUTE
517 val2 |= TLV_DB_SCALE_MUTE;
518#endif
519 if (put_user(SNDRV_CTL_TLVT_DB_SCALE, tlv))
520 return -EFAULT;
521 if (put_user(2 * sizeof(unsigned int), tlv + 1))
522 return -EFAULT;
523 if (put_user(val1, tlv + 2))
524 return -EFAULT;
525 if (put_user(val2, tlv + 3))
526 return -EFAULT;
527 return 0;
528}
529
530static struct snd_kcontrol_new lola_analog_mixer __devinitdata = {
531 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
532 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
533 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
534 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
535 .info = lola_analog_vol_info,
536 .get = lola_analog_vol_get,
537 .put = lola_analog_vol_put,
538 .tlv.c = lola_analog_vol_tlv,
539};
540
541static int __devinit create_analog_mixer(struct lola *chip, int dir, char *name)
542{
543 if (!chip->pin[dir].num_pins)
544 return 0;
545 /* no analog volumes on digital only adapters */
546 if (chip->pin[dir].num_pins != chip->pin[dir].num_analog_pins)
547 return 0;
548 lola_analog_mixer.name = name;
549 lola_analog_mixer.private_value = dir;
550 return snd_ctl_add(chip->card,
551 snd_ctl_new1(&lola_analog_mixer, chip));
552}
553
554/*
555 * Hardware sample rate converter on digital input
556 */
557static int lola_input_src_info(struct snd_kcontrol *kcontrol,
558 struct snd_ctl_elem_info *uinfo)
559{
560 struct lola *chip = snd_kcontrol_chip(kcontrol);
561
562 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
563 uinfo->count = chip->pin[CAPT].num_pins;
564 uinfo->value.integer.min = 0;
565 uinfo->value.integer.max = 1;
566 return 0;
567}
568
569static int lola_input_src_get(struct snd_kcontrol *kcontrol,
570 struct snd_ctl_elem_value *ucontrol)
571{
572 struct lola *chip = snd_kcontrol_chip(kcontrol);
573 int i;
574
575 for (i = 0; i < chip->pin[CAPT].num_pins; i++)
576 ucontrol->value.integer.value[i] =
577 !!(chip->input_src_mask & (1 << i));
578 return 0;
579}
580
581static int lola_input_src_put(struct snd_kcontrol *kcontrol,
582 struct snd_ctl_elem_value *ucontrol)
583{
584 struct lola *chip = snd_kcontrol_chip(kcontrol);
585 int i;
586 unsigned int mask;
587
588 mask = 0;
589 for (i = 0; i < chip->pin[CAPT].num_pins; i++)
590 if (ucontrol->value.integer.value[i])
591 mask |= 1 << i;
592 return lola_set_src_config(chip, mask, true);
593}
594
595static struct snd_kcontrol_new lola_input_src_mixer __devinitdata = {
596 .name = "Digital SRC Capture Switch",
597 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
598 .info = lola_input_src_info,
599 .get = lola_input_src_get,
600 .put = lola_input_src_put,
601};
602
603/*
604 * Lola16161 or Lola881 can have Hardware sample rate converters
605 * on its digital input pins
606 */
607static int __devinit create_input_src_mixer(struct lola *chip)
608{
609 if (!chip->input_src_caps_mask)
610 return 0;
611
612 return snd_ctl_add(chip->card,
613 snd_ctl_new1(&lola_input_src_mixer, chip));
614}
615
616/*
617 * src gain mixer
618 */
619static int lola_src_gain_info(struct snd_kcontrol *kcontrol,
620 struct snd_ctl_elem_info *uinfo)
621{
622 unsigned int count = (kcontrol->private_value >> 8) & 0xff;
623
624 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
625 uinfo->count = count;
626 uinfo->value.integer.min = 0;
627 uinfo->value.integer.max = 409;
628 return 0;
629}
630
631static int lola_src_gain_get(struct snd_kcontrol *kcontrol,
632 struct snd_ctl_elem_value *ucontrol)
633{
634 struct lola *chip = snd_kcontrol_chip(kcontrol);
635 unsigned int ofs = kcontrol->private_value & 0xff;
636 unsigned int count = (kcontrol->private_value >> 8) & 0xff;
637 unsigned int mask, i;
638
639 mask = readl(&chip->mixer.array->src_gain_enable);
640 for (i = 0; i < count; i++) {
641 unsigned int idx = ofs + i;
642 unsigned short val;
643 if (!(chip->mixer.src_mask & (1 << idx)))
644 return -EINVAL;
645 if (mask & (1 << idx))
646 val = readw(&chip->mixer.array->src_gain[idx]) + 1;
647 else
648 val = 0;
649 ucontrol->value.integer.value[i] = val;
650 }
651 return 0;
652}
653
654static int lola_src_gain_put(struct snd_kcontrol *kcontrol,
655 struct snd_ctl_elem_value *ucontrol)
656{
657 struct lola *chip = snd_kcontrol_chip(kcontrol);
658 unsigned int ofs = kcontrol->private_value & 0xff;
659 unsigned int count = (kcontrol->private_value >> 8) & 0xff;
660 int i, err;
661
662 for (i = 0; i < count; i++) {
663 unsigned int idx = ofs + i;
664 unsigned short val = ucontrol->value.integer.value[i];
665 if (val)
666 val--;
667 err = lola_mixer_set_src_gain(chip, idx, val, !!val);
668 if (err < 0)
669 return err;
670 }
671 return 0;
672}
673
674/* raw value: 0 = -84dB, 336 = 0dB, 408=18dB, incremented 1 for mute */
675static const DECLARE_TLV_DB_SCALE(lola_src_gain_tlv, -8425, 25, 1);
676
677static struct snd_kcontrol_new lola_src_gain_mixer __devinitdata = {
678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
679 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
680 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
681 .info = lola_src_gain_info,
682 .get = lola_src_gain_get,
683 .put = lola_src_gain_put,
684 .tlv.p = lola_src_gain_tlv,
685};
686
687static int __devinit create_src_gain_mixer(struct lola *chip,
688 int num, int ofs, char *name)
689{
690 lola_src_gain_mixer.name = name;
691 lola_src_gain_mixer.private_value = ofs + (num << 8);
692 return snd_ctl_add(chip->card,
693 snd_ctl_new1(&lola_src_gain_mixer, chip));
694}
695
696/*
697 * destination gain (matrix-like) mixer
698 */
699static int lola_dest_gain_info(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_info *uinfo)
701{
702 unsigned int src_num = (kcontrol->private_value >> 8) & 0xff;
703
704 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
705 uinfo->count = src_num;
706 uinfo->value.integer.min = 0;
707 uinfo->value.integer.max = 433;
708 return 0;
709}
710
711static int lola_dest_gain_get(struct snd_kcontrol *kcontrol,
712 struct snd_ctl_elem_value *ucontrol)
713{
714 struct lola *chip = snd_kcontrol_chip(kcontrol);
715 unsigned int src_ofs = kcontrol->private_value & 0xff;
716 unsigned int src_num = (kcontrol->private_value >> 8) & 0xff;
717 unsigned int dst_ofs = (kcontrol->private_value >> 16) & 0xff;
718 unsigned int dst, mask, i;
719
720 dst = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + dst_ofs;
721 mask = readl(&chip->mixer.array->dest_mix_gain_enable[dst]);
722 for (i = 0; i < src_num; i++) {
723 unsigned int src = src_ofs + i;
724 unsigned short val;
725 if (!(chip->mixer.src_mask & (1 << src)))
726 return -EINVAL;
727 if (mask & (1 << dst))
728 val = readw(&chip->mixer.array->dest_mix_gain[dst][src]) + 1;
729 else
730 val = 0;
731 ucontrol->value.integer.value[i] = val;
732 }
733 return 0;
734}
735
736static int lola_dest_gain_put(struct snd_kcontrol *kcontrol,
737 struct snd_ctl_elem_value *ucontrol)
738{
739 struct lola *chip = snd_kcontrol_chip(kcontrol);
740 unsigned int src_ofs = kcontrol->private_value & 0xff;
741 unsigned int src_num = (kcontrol->private_value >> 8) & 0xff;
742 unsigned int dst_ofs = (kcontrol->private_value >> 16) & 0xff;
743 unsigned int dst, mask;
744 unsigned short gains[MAX_STREAM_COUNT];
745 int i, num;
746
747 mask = 0;
748 num = 0;
749 for (i = 0; i < src_num; i++) {
750 unsigned short val = ucontrol->value.integer.value[i];
751 if (val) {
752 gains[num++] = val - 1;
753 mask |= 1 << i;
754 }
755 }
756 mask <<= src_ofs;
757 dst = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + dst_ofs;
758 return lola_mixer_set_dest_gains(chip, dst, mask, gains);
759}
760
761static const DECLARE_TLV_DB_SCALE(lola_dest_gain_tlv, -8425, 25, 1);
762
763static struct snd_kcontrol_new lola_dest_gain_mixer __devinitdata = {
764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
765 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
766 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
767 .info = lola_dest_gain_info,
768 .get = lola_dest_gain_get,
769 .put = lola_dest_gain_put,
770 .tlv.p = lola_dest_gain_tlv,
771};
772
773static int __devinit create_dest_gain_mixer(struct lola *chip,
774 int src_num, int src_ofs,
775 int num, int ofs, char *name)
776{
777 lola_dest_gain_mixer.count = num;
778 lola_dest_gain_mixer.name = name;
779 lola_dest_gain_mixer.private_value =
780 src_ofs + (src_num << 8) + (ofs << 16) + (num << 24);
781 return snd_ctl_add(chip->card,
782 snd_ctl_new1(&lola_dest_gain_mixer, chip));
783}
784
785/*
786 */
787int __devinit lola_create_mixer(struct lola *chip)
788{
789 int err;
790
791 err = create_analog_mixer(chip, PLAY, "Analog Playback Volume");
792 if (err < 0)
793 return err;
794 err = create_analog_mixer(chip, CAPT, "Analog Capture Volume");
795 if (err < 0)
796 return err;
797 err = create_input_src_mixer(chip);
798 if (err < 0)
799 return err;
800 err = create_src_gain_mixer(chip, chip->mixer.src_phys_ins, 0,
801 "Line Source Gain Volume");
802 if (err < 0)
803 return err;
804 err = create_src_gain_mixer(chip, chip->mixer.src_stream_outs,
805 chip->mixer.src_stream_out_ofs,
806 "Stream Source Gain Volume");
807 if (err < 0)
808 return err;
809 err = create_dest_gain_mixer(chip,
810 chip->mixer.src_phys_ins, 0,
811 chip->mixer.dest_stream_ins, 0,
812 "Line Capture Volume");
813 if (err < 0)
814 return err;
815 err = create_dest_gain_mixer(chip,
816 chip->mixer.src_stream_outs,
817 chip->mixer.src_stream_out_ofs,
818 chip->mixer.dest_stream_ins, 0,
819 "Stream-Loopback Capture Volume");
820 if (err < 0)
821 return err;
822 err = create_dest_gain_mixer(chip,
823 chip->mixer.src_phys_ins, 0,
824 chip->mixer.dest_phys_outs,
825 chip->mixer.dest_phys_out_ofs,
826 "Line-Loopback Playback Volume");
827 if (err < 0)
828 return err;
829 err = create_dest_gain_mixer(chip,
830 chip->mixer.src_stream_outs,
831 chip->mixer.src_stream_out_ofs,
832 chip->mixer.dest_phys_outs,
833 chip->mixer.dest_phys_out_ofs,
834 "Stream Playback Volume");
835 if (err < 0)
836 return err;
837
838 return init_mixer_values(chip);
839}
diff --git a/sound/pci/lola/lola_pcm.c b/sound/pci/lola/lola_pcm.c
new file mode 100644
index 000000000000..c44db68eecb5
--- /dev/null
+++ b/sound/pci/lola/lola_pcm.c
@@ -0,0 +1,706 @@
1/*
2 * Support for Digigram Lola PCI-e boards
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/dma-mapping.h>
24#include <linux/pci.h>
25#include <linux/delay.h>
26#include <sound/core.h>
27#include <sound/pcm.h>
28#include "lola.h"
29
30#define LOLA_MAX_BDL_ENTRIES 8
31#define LOLA_MAX_BUF_SIZE (1024*1024*1024)
32#define LOLA_BDL_ENTRY_SIZE (16 * 16)
33
34static struct lola_pcm *lola_get_pcm(struct snd_pcm_substream *substream)
35{
36 struct lola *chip = snd_pcm_substream_chip(substream);
37 return &chip->pcm[substream->stream];
38}
39
40static struct lola_stream *lola_get_stream(struct snd_pcm_substream *substream)
41{
42 struct lola_pcm *pcm = lola_get_pcm(substream);
43 unsigned int idx = substream->number;
44 return &pcm->streams[idx];
45}
46
47static unsigned int lola_get_lrc(struct lola *chip)
48{
49 return lola_readl(chip, BAR1, LRC);
50}
51
52static unsigned int lola_get_tstamp(struct lola *chip, bool quick_no_sync)
53{
54 unsigned int tstamp = lola_get_lrc(chip) >> 8;
55 if (chip->granularity) {
56 unsigned int wait_banks = quick_no_sync ? 0 : 8;
57 tstamp += (wait_banks + 1) * chip->granularity - 1;
58 tstamp -= tstamp % chip->granularity;
59 }
60 return tstamp << 8;
61}
62
63/* clear any pending interrupt status */
64static void lola_stream_clear_pending_irq(struct lola *chip,
65 struct lola_stream *str)
66{
67 unsigned int val = lola_dsd_read(chip, str->dsd, STS);
68 val &= LOLA_DSD_STS_DESE | LOLA_DSD_STS_BCIS;
69 if (val)
70 lola_dsd_write(chip, str->dsd, STS, val);
71}
72
73static void lola_stream_start(struct lola *chip, struct lola_stream *str,
74 unsigned int tstamp)
75{
76 lola_stream_clear_pending_irq(chip, str);
77 lola_dsd_write(chip, str->dsd, CTL,
78 LOLA_DSD_CTL_SRUN |
79 LOLA_DSD_CTL_IOCE |
80 LOLA_DSD_CTL_DEIE |
81 LOLA_DSD_CTL_VLRCV |
82 tstamp);
83}
84
85static void lola_stream_stop(struct lola *chip, struct lola_stream *str,
86 unsigned int tstamp)
87{
88 lola_dsd_write(chip, str->dsd, CTL,
89 LOLA_DSD_CTL_IOCE |
90 LOLA_DSD_CTL_DEIE |
91 LOLA_DSD_CTL_VLRCV |
92 tstamp);
93 lola_stream_clear_pending_irq(chip, str);
94}
95
96static void wait_for_srst_clear(struct lola *chip, struct lola_stream *str)
97{
98 unsigned long end_time = jiffies + msecs_to_jiffies(200);
99 while (time_before(jiffies, end_time)) {
100 unsigned int val;
101 val = lola_dsd_read(chip, str->dsd, CTL);
102 if (!(val & LOLA_DSD_CTL_SRST))
103 return;
104 msleep(1);
105 }
106 printk(KERN_WARNING SFX "SRST not clear (stream %d)\n", str->dsd);
107}
108
109static int lola_stream_wait_for_fifo(struct lola *chip,
110 struct lola_stream *str,
111 bool ready)
112{
113 unsigned int val = ready ? LOLA_DSD_STS_FIFORDY : 0;
114 unsigned long end_time = jiffies + msecs_to_jiffies(200);
115 while (time_before(jiffies, end_time)) {
116 unsigned int reg = lola_dsd_read(chip, str->dsd, STS);
117 if ((reg & LOLA_DSD_STS_FIFORDY) == val)
118 return 0;
119 msleep(1);
120 }
121 printk(KERN_WARNING SFX "FIFO not ready (stream %d)\n", str->dsd);
122 return -EIO;
123}
124
125/* sync for FIFO ready/empty for all linked streams;
126 * clear paused flag when FIFO gets ready again
127 */
128static int lola_sync_wait_for_fifo(struct lola *chip,
129 struct snd_pcm_substream *substream,
130 bool ready)
131{
132 unsigned int val = ready ? LOLA_DSD_STS_FIFORDY : 0;
133 unsigned long end_time = jiffies + msecs_to_jiffies(200);
134 struct snd_pcm_substream *s;
135 int pending = 0;
136
137 while (time_before(jiffies, end_time)) {
138 pending = 0;
139 snd_pcm_group_for_each_entry(s, substream) {
140 struct lola_stream *str;
141 if (s->pcm->card != substream->pcm->card)
142 continue;
143 str = lola_get_stream(s);
144 if (str->prepared && str->paused) {
145 unsigned int reg;
146 reg = lola_dsd_read(chip, str->dsd, STS);
147 if ((reg & LOLA_DSD_STS_FIFORDY) != val) {
148 pending = str->dsd + 1;
149 break;
150 }
151 if (ready)
152 str->paused = 0;
153 }
154 }
155 if (!pending)
156 return 0;
157 msleep(1);
158 }
159 printk(KERN_WARNING SFX "FIFO not ready (pending %d)\n", pending - 1);
160 return -EIO;
161}
162
163/* finish pause - prepare for a new resume */
164static void lola_sync_pause(struct lola *chip,
165 struct snd_pcm_substream *substream)
166{
167 struct snd_pcm_substream *s;
168
169 lola_sync_wait_for_fifo(chip, substream, false);
170 snd_pcm_group_for_each_entry(s, substream) {
171 struct lola_stream *str;
172 if (s->pcm->card != substream->pcm->card)
173 continue;
174 str = lola_get_stream(s);
175 if (str->paused && str->prepared)
176 lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRUN |
177 LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE);
178 }
179 lola_sync_wait_for_fifo(chip, substream, true);
180}
181
182static void lola_stream_reset(struct lola *chip, struct lola_stream *str)
183{
184 if (str->prepared) {
185 if (str->paused)
186 lola_sync_pause(chip, str->substream);
187 str->prepared = 0;
188 lola_dsd_write(chip, str->dsd, CTL,
189 LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE);
190 lola_stream_wait_for_fifo(chip, str, false);
191 lola_stream_clear_pending_irq(chip, str);
192 lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRST);
193 lola_dsd_write(chip, str->dsd, LVI, 0);
194 lola_dsd_write(chip, str->dsd, BDPU, 0);
195 lola_dsd_write(chip, str->dsd, BDPL, 0);
196 wait_for_srst_clear(chip, str);
197 }
198}
199
200static struct snd_pcm_hardware lola_pcm_hw = {
201 .info = (SNDRV_PCM_INFO_MMAP |
202 SNDRV_PCM_INFO_INTERLEAVED |
203 SNDRV_PCM_INFO_BLOCK_TRANSFER |
204 SNDRV_PCM_INFO_MMAP_VALID |
205 SNDRV_PCM_INFO_PAUSE),
206 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
207 SNDRV_PCM_FMTBIT_S24_LE |
208 SNDRV_PCM_FMTBIT_S32_LE |
209 SNDRV_PCM_FMTBIT_FLOAT_LE),
210 .rates = SNDRV_PCM_RATE_8000_192000,
211 .rate_min = 8000,
212 .rate_max = 192000,
213 .channels_min = 1,
214 .channels_max = 2,
215 .buffer_bytes_max = LOLA_MAX_BUF_SIZE,
216 .period_bytes_min = 128,
217 .period_bytes_max = LOLA_MAX_BUF_SIZE / 2,
218 .periods_min = 2,
219 .periods_max = LOLA_MAX_BDL_ENTRIES,
220 .fifo_size = 0,
221};
222
223static int lola_pcm_open(struct snd_pcm_substream *substream)
224{
225 struct lola *chip = snd_pcm_substream_chip(substream);
226 struct lola_pcm *pcm = lola_get_pcm(substream);
227 struct lola_stream *str = lola_get_stream(substream);
228 struct snd_pcm_runtime *runtime = substream->runtime;
229
230 mutex_lock(&chip->open_mutex);
231 if (str->opened) {
232 mutex_unlock(&chip->open_mutex);
233 return -EBUSY;
234 }
235 str->substream = substream;
236 str->master = NULL;
237 str->opened = 1;
238 runtime->hw = lola_pcm_hw;
239 runtime->hw.channels_max = pcm->num_streams - str->index;
240 if (chip->sample_rate) {
241 /* sample rate is locked */
242 runtime->hw.rate_min = chip->sample_rate;
243 runtime->hw.rate_max = chip->sample_rate;
244 } else {
245 runtime->hw.rate_min = chip->sample_rate_min;
246 runtime->hw.rate_max = chip->sample_rate_max;
247 }
248 chip->ref_count_rate++;
249 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
250 /* period size = multiple of chip->granularity (8, 16 or 32 frames)*/
251 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
252 chip->granularity);
253 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
254 chip->granularity);
255 mutex_unlock(&chip->open_mutex);
256 return 0;
257}
258
259static void lola_cleanup_slave_streams(struct lola_pcm *pcm,
260 struct lola_stream *str)
261{
262 int i;
263 for (i = str->index + 1; i < pcm->num_streams; i++) {
264 struct lola_stream *s = &pcm->streams[i];
265 if (s->master != str)
266 break;
267 s->master = NULL;
268 s->opened = 0;
269 }
270}
271
272static int lola_pcm_close(struct snd_pcm_substream *substream)
273{
274 struct lola *chip = snd_pcm_substream_chip(substream);
275 struct lola_stream *str = lola_get_stream(substream);
276
277 mutex_lock(&chip->open_mutex);
278 if (str->substream == substream) {
279 str->substream = NULL;
280 str->opened = 0;
281 }
282 if (--chip->ref_count_rate == 0) {
283 /* release sample rate */
284 chip->sample_rate = 0;
285 }
286 mutex_unlock(&chip->open_mutex);
287 return 0;
288}
289
290static int lola_pcm_hw_params(struct snd_pcm_substream *substream,
291 struct snd_pcm_hw_params *hw_params)
292{
293 struct lola_stream *str = lola_get_stream(substream);
294
295 str->bufsize = 0;
296 str->period_bytes = 0;
297 str->format_verb = 0;
298 return snd_pcm_lib_malloc_pages(substream,
299 params_buffer_bytes(hw_params));
300}
301
302static int lola_pcm_hw_free(struct snd_pcm_substream *substream)
303{
304 struct lola *chip = snd_pcm_substream_chip(substream);
305 struct lola_pcm *pcm = lola_get_pcm(substream);
306 struct lola_stream *str = lola_get_stream(substream);
307
308 mutex_lock(&chip->open_mutex);
309 lola_stream_reset(chip, str);
310 lola_cleanup_slave_streams(pcm, str);
311 mutex_unlock(&chip->open_mutex);
312 return snd_pcm_lib_free_pages(substream);
313}
314
315/*
316 * set up a BDL entry
317 */
318static int setup_bdle(struct snd_pcm_substream *substream,
319 struct lola_stream *str, u32 **bdlp,
320 int ofs, int size)
321{
322 u32 *bdl = *bdlp;
323
324 while (size > 0) {
325 dma_addr_t addr;
326 int chunk;
327
328 if (str->frags >= LOLA_MAX_BDL_ENTRIES)
329 return -EINVAL;
330
331 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
332 /* program the address field of the BDL entry */
333 bdl[0] = cpu_to_le32((u32)addr);
334 bdl[1] = cpu_to_le32(upper_32_bits(addr));
335 /* program the size field of the BDL entry */
336 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
337 bdl[2] = cpu_to_le32(chunk);
338 /* program the IOC to enable interrupt
339 * only when the whole fragment is processed
340 */
341 size -= chunk;
342 bdl[3] = size ? 0 : cpu_to_le32(0x01);
343 bdl += 4;
344 str->frags++;
345 ofs += chunk;
346 }
347 *bdlp = bdl;
348 return ofs;
349}
350
351/*
352 * set up BDL entries
353 */
354static int lola_setup_periods(struct lola *chip, struct lola_pcm *pcm,
355 struct snd_pcm_substream *substream,
356 struct lola_stream *str)
357{
358 u32 *bdl;
359 int i, ofs, periods, period_bytes;
360
361 period_bytes = str->period_bytes;
362 periods = str->bufsize / period_bytes;
363
364 /* program the initial BDL entries */
365 bdl = (u32 *)(pcm->bdl.area + LOLA_BDL_ENTRY_SIZE * str->index);
366 ofs = 0;
367 str->frags = 0;
368 for (i = 0; i < periods; i++) {
369 ofs = setup_bdle(substream, str, &bdl, ofs, period_bytes);
370 if (ofs < 0)
371 goto error;
372 }
373 return 0;
374
375 error:
376 snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n",
377 str->bufsize, period_bytes);
378 return -EINVAL;
379}
380
381static unsigned int lola_get_format_verb(struct snd_pcm_substream *substream)
382{
383 unsigned int verb;
384
385 switch (substream->runtime->format) {
386 case SNDRV_PCM_FORMAT_S16_LE:
387 verb = 0x00000000;
388 break;
389 case SNDRV_PCM_FORMAT_S24_LE:
390 verb = 0x00000200;
391 break;
392 case SNDRV_PCM_FORMAT_S32_LE:
393 verb = 0x00000300;
394 break;
395 case SNDRV_PCM_FORMAT_FLOAT_LE:
396 verb = 0x00001300;
397 break;
398 default:
399 return 0;
400 }
401 verb |= substream->runtime->channels;
402 return verb;
403}
404
405static int lola_set_stream_config(struct lola *chip,
406 struct lola_stream *str,
407 int channels)
408{
409 int i, err;
410 unsigned int verb, val;
411
412 /* set format info for all channels
413 * (with only one command for the first channel)
414 */
415 err = lola_codec_read(chip, str->nid, LOLA_VERB_SET_STREAM_FORMAT,
416 str->format_verb, 0, &val, NULL);
417 if (err < 0) {
418 printk(KERN_ERR SFX "Cannot set stream format 0x%x\n",
419 str->format_verb);
420 return err;
421 }
422
423 /* update stream - channel config */
424 for (i = 0; i < channels; i++) {
425 verb = (str->index << 6) | i;
426 err = lola_codec_read(chip, str[i].nid,
427 LOLA_VERB_SET_CHANNEL_STREAMID, 0, verb,
428 &val, NULL);
429 if (err < 0) {
430 printk(KERN_ERR SFX "Cannot set stream channel %d\n", i);
431 return err;
432 }
433 }
434 return 0;
435}
436
437/*
438 * set up the SD for streaming
439 */
440static int lola_setup_controller(struct lola *chip, struct lola_pcm *pcm,
441 struct lola_stream *str)
442{
443 dma_addr_t bdl;
444
445 if (str->prepared)
446 return -EINVAL;
447
448 /* set up BDL */
449 bdl = pcm->bdl.addr + LOLA_BDL_ENTRY_SIZE * str->index;
450 lola_dsd_write(chip, str->dsd, BDPL, (u32)bdl);
451 lola_dsd_write(chip, str->dsd, BDPU, upper_32_bits(bdl));
452 /* program the stream LVI (last valid index) of the BDL */
453 lola_dsd_write(chip, str->dsd, LVI, str->frags - 1);
454 lola_stream_clear_pending_irq(chip, str);
455
456 lola_dsd_write(chip, str->dsd, CTL,
457 LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE | LOLA_DSD_CTL_SRUN);
458
459 str->prepared = 1;
460
461 return lola_stream_wait_for_fifo(chip, str, true);
462}
463
464static int lola_pcm_prepare(struct snd_pcm_substream *substream)
465{
466 struct lola *chip = snd_pcm_substream_chip(substream);
467 struct lola_pcm *pcm = lola_get_pcm(substream);
468 struct lola_stream *str = lola_get_stream(substream);
469 struct snd_pcm_runtime *runtime = substream->runtime;
470 unsigned int bufsize, period_bytes, format_verb;
471 int i, err;
472
473 mutex_lock(&chip->open_mutex);
474 lola_stream_reset(chip, str);
475 lola_cleanup_slave_streams(pcm, str);
476 if (str->index + runtime->channels > pcm->num_streams) {
477 mutex_unlock(&chip->open_mutex);
478 return -EINVAL;
479 }
480 for (i = 1; i < runtime->channels; i++) {
481 str[i].master = str;
482 str[i].opened = 1;
483 }
484 mutex_unlock(&chip->open_mutex);
485
486 bufsize = snd_pcm_lib_buffer_bytes(substream);
487 period_bytes = snd_pcm_lib_period_bytes(substream);
488 format_verb = lola_get_format_verb(substream);
489
490 str->bufsize = bufsize;
491 str->period_bytes = period_bytes;
492 str->format_verb = format_verb;
493
494 err = lola_setup_periods(chip, pcm, substream, str);
495 if (err < 0)
496 return err;
497
498 err = lola_set_sample_rate(chip, runtime->rate);
499 if (err < 0)
500 return err;
501 chip->sample_rate = runtime->rate; /* sample rate gets locked */
502
503 err = lola_set_stream_config(chip, str, runtime->channels);
504 if (err < 0)
505 return err;
506
507 err = lola_setup_controller(chip, pcm, str);
508 if (err < 0) {
509 lola_stream_reset(chip, str);
510 return err;
511 }
512
513 return 0;
514}
515
516static int lola_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
517{
518 struct lola *chip = snd_pcm_substream_chip(substream);
519 struct lola_stream *str;
520 struct snd_pcm_substream *s;
521 unsigned int start;
522 unsigned int tstamp;
523 bool sync_streams;
524
525 switch (cmd) {
526 case SNDRV_PCM_TRIGGER_START:
527 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
528 case SNDRV_PCM_TRIGGER_RESUME:
529 start = 1;
530 break;
531 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
532 case SNDRV_PCM_TRIGGER_SUSPEND:
533 case SNDRV_PCM_TRIGGER_STOP:
534 start = 0;
535 break;
536 default:
537 return -EINVAL;
538 }
539
540 /*
541 * sample correct synchronization is only needed starting several
542 * streams. On stop or if only one stream do as quick as possible
543 */
544 sync_streams = (start && snd_pcm_stream_linked(substream));
545 tstamp = lola_get_tstamp(chip, !sync_streams);
546 spin_lock(&chip->reg_lock);
547 snd_pcm_group_for_each_entry(s, substream) {
548 if (s->pcm->card != substream->pcm->card)
549 continue;
550 str = lola_get_stream(s);
551 if (start)
552 lola_stream_start(chip, str, tstamp);
553 else
554 lola_stream_stop(chip, str, tstamp);
555 str->running = start;
556 str->paused = !start;
557 snd_pcm_trigger_done(s, substream);
558 }
559 spin_unlock(&chip->reg_lock);
560 return 0;
561}
562
563static snd_pcm_uframes_t lola_pcm_pointer(struct snd_pcm_substream *substream)
564{
565 struct lola *chip = snd_pcm_substream_chip(substream);
566 struct lola_stream *str = lola_get_stream(substream);
567 unsigned int pos = lola_dsd_read(chip, str->dsd, LPIB);
568
569 if (pos >= str->bufsize)
570 pos = 0;
571 return bytes_to_frames(substream->runtime, pos);
572}
573
574void lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits)
575{
576 int i;
577
578 for (i = 0; bits && i < pcm->num_streams; i++) {
579 if (bits & (1 << i)) {
580 struct lola_stream *str = &pcm->streams[i];
581 if (str->substream && str->running)
582 snd_pcm_period_elapsed(str->substream);
583 bits &= ~(1 << i);
584 }
585 }
586}
587
588static struct snd_pcm_ops lola_pcm_ops = {
589 .open = lola_pcm_open,
590 .close = lola_pcm_close,
591 .ioctl = snd_pcm_lib_ioctl,
592 .hw_params = lola_pcm_hw_params,
593 .hw_free = lola_pcm_hw_free,
594 .prepare = lola_pcm_prepare,
595 .trigger = lola_pcm_trigger,
596 .pointer = lola_pcm_pointer,
597 .page = snd_pcm_sgbuf_ops_page,
598};
599
600int __devinit lola_create_pcm(struct lola *chip)
601{
602 struct snd_pcm *pcm;
603 int i, err;
604
605 for (i = 0; i < 2; i++) {
606 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
607 snd_dma_pci_data(chip->pci),
608 PAGE_SIZE, &chip->pcm[i].bdl);
609 if (err < 0)
610 return err;
611 }
612
613 err = snd_pcm_new(chip->card, "Digigram Lola", 0,
614 chip->pcm[SNDRV_PCM_STREAM_PLAYBACK].num_streams,
615 chip->pcm[SNDRV_PCM_STREAM_CAPTURE].num_streams,
616 &pcm);
617 if (err < 0)
618 return err;
619 strlcpy(pcm->name, "Digigram Lola", sizeof(pcm->name));
620 pcm->private_data = chip;
621 for (i = 0; i < 2; i++) {
622 if (chip->pcm[i].num_streams)
623 snd_pcm_set_ops(pcm, i, &lola_pcm_ops);
624 }
625 /* buffer pre-allocation */
626 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
627 snd_dma_pci_data(chip->pci),
628 1024 * 64, 32 * 1024 * 1024);
629 return 0;
630}
631
632void lola_free_pcm(struct lola *chip)
633{
634 snd_dma_free_pages(&chip->pcm[0].bdl);
635 snd_dma_free_pages(&chip->pcm[1].bdl);
636}
637
638/*
639 */
640
641static int lola_init_stream(struct lola *chip, struct lola_stream *str,
642 int idx, int nid, int dir)
643{
644 unsigned int val;
645 int err;
646
647 str->nid = nid;
648 str->index = idx;
649 str->dsd = idx;
650 if (dir == PLAY)
651 str->dsd += MAX_STREAM_IN_COUNT;
652 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
653 if (err < 0) {
654 printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid);
655 return err;
656 }
657 if (dir == PLAY) {
658 /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1) */
659 if ((val & 0x00f00dff) != 0x00000010) {
660 printk(KERN_ERR SFX "Invalid wcaps 0x%x for 0x%x\n",
661 val, nid);
662 return -EINVAL;
663 }
664 } else {
665 /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1)
666 * (bug : ignore bit8: Conn list = 0/1)
667 */
668 if ((val & 0x00f00cff) != 0x00100010) {
669 printk(KERN_ERR SFX "Invalid wcaps 0x%x for 0x%x\n",
670 val, nid);
671 return -EINVAL;
672 }
673 /* test bit9:DIGITAL and bit12:SRC_PRESENT*/
674 if ((val & 0x00001200) == 0x00001200)
675 chip->input_src_caps_mask |= (1 << idx);
676 }
677
678 err = lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val);
679 if (err < 0) {
680 printk(KERN_ERR SFX "Can't read FORMATS 0x%x\n", nid);
681 return err;
682 }
683 val &= 3;
684 if (val == 3)
685 str->can_float = true;
686 if (!(val & 1)) {
687 printk(KERN_ERR SFX "Invalid formats 0x%x for 0x%x", val, nid);
688 return -EINVAL;
689 }
690 return 0;
691}
692
693int __devinit lola_init_pcm(struct lola *chip, int dir, int *nidp)
694{
695 struct lola_pcm *pcm = &chip->pcm[dir];
696 int i, nid, err;
697
698 nid = *nidp;
699 for (i = 0; i < pcm->num_streams; i++, nid++) {
700 err = lola_init_stream(chip, &pcm->streams[i], i, nid, dir);
701 if (err < 0)
702 return err;
703 }
704 *nidp = nid;
705 return 0;
706}
diff --git a/sound/pci/lola/lola_proc.c b/sound/pci/lola/lola_proc.c
new file mode 100644
index 000000000000..9d7daf897c9d
--- /dev/null
+++ b/sound/pci/lola/lola_proc.c
@@ -0,0 +1,222 @@
1/*
2 * Support for Digigram Lola PCI-e boards
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/io.h>
24#include <sound/core.h>
25#include <sound/info.h>
26#include <sound/pcm.h>
27#include "lola.h"
28
29static void print_audio_widget(struct snd_info_buffer *buffer,
30 struct lola *chip, int nid, const char *name)
31{
32 unsigned int val;
33
34 lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
35 snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
36 lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val);
37 snd_iprintf(buffer, " Formats: 0x%x\n", val);
38}
39
40static void print_pin_widget(struct snd_info_buffer *buffer,
41 struct lola *chip, int nid, unsigned int ampcap,
42 const char *name)
43{
44 unsigned int val;
45
46 lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
47 snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
48 if (val == 0x00400200)
49 return;
50 lola_read_param(chip, nid, ampcap, &val);
51 snd_iprintf(buffer, " Amp-Caps: 0x%x\n", val);
52 snd_iprintf(buffer, " mute=%d, step-size=%d, steps=%d, ofs=%d\n",
53 LOLA_AMP_MUTE_CAPABLE(val),
54 LOLA_AMP_STEP_SIZE(val),
55 LOLA_AMP_NUM_STEPS(val),
56 LOLA_AMP_OFFSET(val));
57 lola_codec_read(chip, nid, LOLA_VERB_GET_MAX_LEVEL, 0, 0, &val, NULL);
58 snd_iprintf(buffer, " Max-level: 0x%x\n", val);
59}
60
61static void print_clock_widget(struct snd_info_buffer *buffer,
62 struct lola *chip, int nid)
63{
64 int i, j, num_clocks;
65 unsigned int val;
66
67 lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
68 snd_iprintf(buffer, "Node 0x%02x [Clock] wcaps 0x%x\n", nid, val);
69 num_clocks = val & 0xff;
70 for (i = 0; i < num_clocks; i += 4) {
71 unsigned int res_ex;
72 unsigned short items[4];
73 const char *name;
74
75 lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST,
76 i, 0, &val, &res_ex);
77 items[0] = val & 0xfff;
78 items[1] = (val >> 16) & 0xfff;
79 items[2] = res_ex & 0xfff;
80 items[3] = (res_ex >> 16) & 0xfff;
81 for (j = 0; j < 4; j++) {
82 unsigned char type = items[j] >> 8;
83 unsigned int freq = items[j] & 0xff;
84 if (i + j >= num_clocks)
85 break;
86 if (type == LOLA_CLOCK_TYPE_INTERNAL) {
87 name = "Internal";
88 freq = lola_sample_rate_convert(freq);
89 } else if (type == LOLA_CLOCK_TYPE_VIDEO) {
90 name = "Video";
91 freq = lola_sample_rate_convert(freq);
92 } else {
93 name = "Other";
94 }
95 snd_iprintf(buffer, " Clock %d: Type %d:%s, freq=%d\n",
96 i + j, type, name, freq);
97 }
98 }
99}
100
101static void print_mixer_widget(struct snd_info_buffer *buffer,
102 struct lola *chip, int nid)
103{
104 unsigned int val;
105
106 lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
107 snd_iprintf(buffer, "Node 0x%02x [Mixer] wcaps 0x%x\n", nid, val);
108}
109
110static void lola_proc_codec_read(struct snd_info_entry *entry,
111 struct snd_info_buffer *buffer)
112{
113 struct lola *chip = entry->private_data;
114 unsigned int val;
115 int i, nid;
116
117 lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val);
118 snd_iprintf(buffer, "Vendor: 0x%08x\n", val);
119 lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
120 snd_iprintf(buffer, "Function Type: %d\n", val);
121 lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val);
122 snd_iprintf(buffer, "Specific-Caps: 0x%08x\n", val);
123 snd_iprintf(buffer, " Pins-In %d, Pins-Out %d\n",
124 chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins);
125 nid = 2;
126 for (i = 0; i < chip->pcm[CAPT].num_streams; i++, nid++)
127 print_audio_widget(buffer, chip, nid, "[Audio-In]");
128 for (i = 0; i < chip->pcm[PLAY].num_streams; i++, nid++)
129 print_audio_widget(buffer, chip, nid, "[Audio-Out]");
130 for (i = 0; i < chip->pin[CAPT].num_pins; i++, nid++)
131 print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_IN_CAP,
132 "[Pin-In]");
133 for (i = 0; i < chip->pin[PLAY].num_pins; i++, nid++)
134 print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_OUT_CAP,
135 "[Pin-Out]");
136 if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) {
137 print_clock_widget(buffer, chip, nid);
138 nid++;
139 }
140 if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) {
141 print_mixer_widget(buffer, chip, nid);
142 nid++;
143 }
144}
145
146/* direct codec access for debugging */
147static void lola_proc_codec_rw_write(struct snd_info_entry *entry,
148 struct snd_info_buffer *buffer)
149{
150 struct lola *chip = entry->private_data;
151 char line[64];
152 unsigned int id, verb, data, extdata;
153 while (!snd_info_get_line(buffer, line, sizeof(line))) {
154 if (sscanf(line, "%i %i %i %i", &id, &verb, &data, &extdata) != 4)
155 continue;
156 lola_codec_read(chip, id, verb, data, extdata,
157 &chip->debug_res,
158 &chip->debug_res_ex);
159 }
160}
161
162static void lola_proc_codec_rw_read(struct snd_info_entry *entry,
163 struct snd_info_buffer *buffer)
164{
165 struct lola *chip = entry->private_data;
166 snd_iprintf(buffer, "0x%x 0x%x\n", chip->debug_res, chip->debug_res_ex);
167}
168
169/*
170 * dump some registers
171 */
172static void lola_proc_regs_read(struct snd_info_entry *entry,
173 struct snd_info_buffer *buffer)
174{
175 struct lola *chip = entry->private_data;
176 int i;
177
178 for (i = 0; i < 0x40; i += 4) {
179 snd_iprintf(buffer, "BAR0 %02x: %08x\n", i,
180 readl(chip->bar[BAR0].remap_addr + i));
181 }
182 snd_iprintf(buffer, "\n");
183 for (i = 0; i < 0x30; i += 4) {
184 snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
185 readl(chip->bar[BAR1].remap_addr + i));
186 }
187 snd_iprintf(buffer, "\n");
188 for (i = 0x80; i < 0xa0; i += 4) {
189 snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
190 readl(chip->bar[BAR1].remap_addr + i));
191 }
192 snd_iprintf(buffer, "\n");
193 for (i = 0; i < 32; i++) {
194 snd_iprintf(buffer, "DSD %02x STS %08x\n", i,
195 lola_dsd_read(chip, i, STS));
196 snd_iprintf(buffer, "DSD %02x LPIB %08x\n", i,
197 lola_dsd_read(chip, i, LPIB));
198 snd_iprintf(buffer, "DSD %02x CTL %08x\n", i,
199 lola_dsd_read(chip, i, CTL));
200 snd_iprintf(buffer, "DSD %02x LVIL %08x\n", i,
201 lola_dsd_read(chip, i, LVI));
202 snd_iprintf(buffer, "DSD %02x BDPL %08x\n", i,
203 lola_dsd_read(chip, i, BDPL));
204 snd_iprintf(buffer, "DSD %02x BDPU %08x\n", i,
205 lola_dsd_read(chip, i, BDPU));
206 }
207}
208
209void __devinit lola_proc_debug_new(struct lola *chip)
210{
211 struct snd_info_entry *entry;
212
213 if (!snd_card_proc_new(chip->card, "codec", &entry))
214 snd_info_set_text_ops(entry, chip, lola_proc_codec_read);
215 if (!snd_card_proc_new(chip->card, "codec_rw", &entry)) {
216 snd_info_set_text_ops(entry, chip, lola_proc_codec_rw_read);
217 entry->mode |= S_IWUSR;
218 entry->c.text.write = lola_proc_codec_rw_write;
219 }
220 if (!snd_card_proc_new(chip->card, "regs", &entry))
221 snd_info_set_text_ops(entry, chip, lola_proc_regs_read);
222}