Lines Matching +full:cm +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for C-Media CMI8338 and 8738 PCI soundcards.
31 MODULE_DESCRIPTION("C-Media CMI8x38 PCI");
38 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
41 static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1};
42 static long fm_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
43 static bool soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
49 MODULE_PARM_DESC(index, "Index value for C-Media PCI soundcard.");
51 MODULE_PARM_DESC(id, "ID string for C-Media PCI soundcard.");
53 MODULE_PARM_DESC(enable, "Enable C-Media PCI soundcard.");
55 MODULE_PARM_DESC(mpu_port, "MPU-401 port.");
59 MODULE_PARM_DESC(soft_ac3, "Software-conversion of raw SPDIF packets (model 033 only).");
86 #define CM_SPDFLOOP 0x00000080 /* ext. SPDIIF/IN -> OUT loopback */
105 #define CM_SPD24SEL39 0x00200000 /* 24-bit spdif: model 039 */
176 #define CM_NXCHG 0x80000000 /* don't map base reg dword->sample */
195 #define CM_DAC2SPDO 0x00200000 /* enable wave+fm_midi -> SPDIF/OUT */
203 #define CM_CENTR2LIN 0x00004000 /* line-in as center out */
204 #define CM_BASE2LIN 0x00002000 /* line-in as bass out */
220 #define CM_SPDFLOOPI 0x00100000 /* int. SPDIF-OUT -> int. IN */
274 #define CM_REAR2LIN 0x20 /* lin-in -> rear line out */
284 #define CM_CDPLAY 0x01 /* enable SPDIF/IN PCM -> DAC */
296 #define CM_VADMIC_MASK 0x0e /* mic gain level (0-3) << 1 */
316 * For CMI-8338 (0x28 - 0x2b) .. is this valid for CMI-8738
322 * MPU401 pci port index address 0x40 - 0x4f (CMI-8738 spec ver. 0.6)
327 * FM pci port index address 0x50 - 0x5f (CMI-8738 spec ver. 0.6)
332 * access from SB-mixer port
335 #define CM_VPHONE_MASK 0xe0 /* Phone volume control (0-3) << 5 */
339 #define CM_RLOOPREN 0x04 /* Rec. R-channel enable */
340 #define CM_RLOOPLEN 0x02 /* Rec. L-channel enable */
344 * CMI-8338 spec ver 0.5 (this is not valid for CMI-8738):
345 * the 8 registers 0xf8 - 0xff are used for programming m/n counter by the PLL
355 #define CM_REG_CH1_FRAME1 0x88 /* 0-15: count of samples at bus master; buffer size */
356 #define CM_REG_CH1_FRAME2 0x8C /* 16-31: count of samples at codec; fragment size */
428 const char *name; /* switch to toggle */ member
478 struct cmipci_pcm channel[2]; /* ch0 - DAC, ch1 - ADC or 2nd DAC */
495 static inline void snd_cmipci_write(struct cmipci *cm, unsigned int cmd, unsigned int data) in snd_cmipci_write() argument
497 outl(data, cm->iobase + cmd); in snd_cmipci_write()
500 static inline unsigned int snd_cmipci_read(struct cmipci *cm, unsigned int cmd) in snd_cmipci_read() argument
502 return inl(cm->iobase + cmd); in snd_cmipci_read()
506 static inline void snd_cmipci_write_w(struct cmipci *cm, unsigned int cmd, unsigned short data) in snd_cmipci_write_w() argument
508 outw(data, cm->iobase + cmd); in snd_cmipci_write_w()
511 static inline unsigned short snd_cmipci_read_w(struct cmipci *cm, unsigned int cmd) in snd_cmipci_read_w() argument
513 return inw(cm->iobase + cmd); in snd_cmipci_read_w()
517 static inline void snd_cmipci_write_b(struct cmipci *cm, unsigned int cmd, unsigned char data) in snd_cmipci_write_b() argument
519 outb(data, cm->iobase + cmd); in snd_cmipci_write_b()
522 static inline unsigned char snd_cmipci_read_b(struct cmipci *cm, unsigned int cmd) in snd_cmipci_read_b() argument
524 return inb(cm->iobase + cmd); in snd_cmipci_read_b()
528 static int snd_cmipci_set_bit(struct cmipci *cm, unsigned int cmd, unsigned int flag) in snd_cmipci_set_bit() argument
531 val = oval = inl(cm->iobase + cmd); in snd_cmipci_set_bit()
535 outl(val, cm->iobase + cmd); in snd_cmipci_set_bit()
539 static int snd_cmipci_clear_bit(struct cmipci *cm, unsigned int cmd, unsigned int flag) in snd_cmipci_clear_bit() argument
542 val = oval = inl(cm->iobase + cmd); in snd_cmipci_clear_bit()
546 outl(val, cm->iobase + cmd); in snd_cmipci_clear_bit()
551 static int snd_cmipci_set_bit_b(struct cmipci *cm, unsigned int cmd, unsigned char flag) in snd_cmipci_set_bit_b() argument
554 val = oval = inb(cm->iobase + cmd); in snd_cmipci_set_bit_b()
558 outb(val, cm->iobase + cmd); in snd_cmipci_set_bit_b()
562 static int snd_cmipci_clear_bit_b(struct cmipci *cm, unsigned int cmd, unsigned char flag) in snd_cmipci_clear_bit_b() argument
565 val = oval = inb(cm->iobase + cmd); in snd_cmipci_clear_bit_b()
569 outb(val, cm->iobase + cmd); in snd_cmipci_clear_bit_b()
599 * does it this way .. maybe not. Never get any information from C-Media about
609 *n = -1; in snd_cmipci_pll_rmn()
619 delta = rate - xr; in snd_cmipci_pll_rmn()
621 delta = xr - rate; in snd_cmipci_pll_rmn()
629 *m = xm - 2; in snd_cmipci_pll_rmn()
630 *n = xn - 2; in snd_cmipci_pll_rmn()
635 return (*n > -1); in snd_cmipci_pll_rmn()
644 static void snd_cmipci_set_pll(struct cmipci *cm, unsigned int rate, unsigned int slot) in snd_cmipci_set_pll() argument
655 snd_cmipci_write_b(cm, reg, rate>>8); in snd_cmipci_set_pll()
656 snd_cmipci_write_b(cm, reg, rate&0xff); in snd_cmipci_set_pll()
665 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback2_hw_params() local
667 mutex_lock(&cm->open_mutex); in snd_cmipci_playback2_hw_params()
668 if (cm->opened[CM_CH_PLAY]) { in snd_cmipci_playback2_hw_params()
669 mutex_unlock(&cm->open_mutex); in snd_cmipci_playback2_hw_params()
670 return -EBUSY; in snd_cmipci_playback2_hw_params()
673 cm->opened[CM_CH_PLAY] = CM_OPEN_PLAYBACK_MULTI; in snd_cmipci_playback2_hw_params()
674 mutex_unlock(&cm->open_mutex); in snd_cmipci_playback2_hw_params()
679 static void snd_cmipci_ch_reset(struct cmipci *cm, int ch) in snd_cmipci_ch_reset() argument
681 int reset = CM_RST_CH0 << (cm->channel[ch].ch); in snd_cmipci_ch_reset()
682 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset); in snd_cmipci_ch_reset()
683 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset); in snd_cmipci_ch_reset()
708 static int set_dac_channels(struct cmipci *cm, struct cmipci_pcm *rec, int channels) in set_dac_channels() argument
711 if (!cm->can_multi_ch || !rec->ch) in set_dac_channels()
712 return -EINVAL; in set_dac_channels()
713 if (rec->fmt != 0x03) /* stereo 16bit only */ in set_dac_channels()
714 return -EINVAL; in set_dac_channels()
717 if (cm->can_multi_ch) { in set_dac_channels()
718 spin_lock_irq(&cm->reg_lock); in set_dac_channels()
720 snd_cmipci_set_bit(cm, CM_REG_LEGACY_CTRL, CM_NXCHG); in set_dac_channels()
721 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_XCHGDAC); in set_dac_channels()
723 snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_NXCHG); in set_dac_channels()
724 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_XCHGDAC); in set_dac_channels()
727 snd_cmipci_set_bit(cm, CM_REG_EXT_MISC, CM_CHB3D8C); in set_dac_channels()
729 snd_cmipci_clear_bit(cm, CM_REG_EXT_MISC, CM_CHB3D8C); in set_dac_channels()
731 snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_CHB3D5C); in set_dac_channels()
732 snd_cmipci_set_bit(cm, CM_REG_LEGACY_CTRL, CM_CHB3D6C); in set_dac_channels()
734 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_CHB3D5C); in set_dac_channels()
735 snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_CHB3D6C); in set_dac_channels()
738 snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_CHB3D); in set_dac_channels()
740 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_CHB3D); in set_dac_channels()
741 spin_unlock_irq(&cm->reg_lock); in set_dac_channels()
749 * channel to be used must have been set in rec->ch.
751 static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec, in snd_cmipci_pcm_prepare() argument
756 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_pcm_prepare()
758 rec->fmt = 0; in snd_cmipci_pcm_prepare()
759 rec->shift = 0; in snd_cmipci_pcm_prepare()
760 if (snd_pcm_format_width(runtime->format) >= 16) { in snd_cmipci_pcm_prepare()
761 rec->fmt |= 0x02; in snd_cmipci_pcm_prepare()
762 if (snd_pcm_format_width(runtime->format) > 16) in snd_cmipci_pcm_prepare()
763 rec->shift++; /* 24/32bit */ in snd_cmipci_pcm_prepare()
765 if (runtime->channels > 1) in snd_cmipci_pcm_prepare()
766 rec->fmt |= 0x01; in snd_cmipci_pcm_prepare()
767 if (rec->is_dac && set_dac_channels(cm, rec, runtime->channels) < 0) { in snd_cmipci_pcm_prepare()
768 dev_dbg(cm->card->dev, "cannot set dac channels\n"); in snd_cmipci_pcm_prepare()
769 return -EINVAL; in snd_cmipci_pcm_prepare()
772 rec->offset = runtime->dma_addr; in snd_cmipci_pcm_prepare()
774 rec->dma_size = runtime->buffer_size << rec->shift; in snd_cmipci_pcm_prepare()
775 period_size = runtime->period_size << rec->shift; in snd_cmipci_pcm_prepare()
776 if (runtime->channels > 2) { in snd_cmipci_pcm_prepare()
777 /* multi-channels */ in snd_cmipci_pcm_prepare()
778 rec->dma_size = (rec->dma_size * runtime->channels) / 2; in snd_cmipci_pcm_prepare()
779 period_size = (period_size * runtime->channels) / 2; in snd_cmipci_pcm_prepare()
782 spin_lock_irq(&cm->reg_lock); in snd_cmipci_pcm_prepare()
785 reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1; in snd_cmipci_pcm_prepare()
786 snd_cmipci_write(cm, reg, rec->offset); in snd_cmipci_pcm_prepare()
788 reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2; in snd_cmipci_pcm_prepare()
789 snd_cmipci_write_w(cm, reg, rec->dma_size - 1); in snd_cmipci_pcm_prepare()
790 snd_cmipci_write_w(cm, reg + 2, period_size - 1); in snd_cmipci_pcm_prepare()
793 val = rec->ch ? CM_CHADC1 : CM_CHADC0; in snd_cmipci_pcm_prepare()
794 if (rec->is_dac) in snd_cmipci_pcm_prepare()
795 cm->ctrl &= ~val; in snd_cmipci_pcm_prepare()
797 cm->ctrl |= val; in snd_cmipci_pcm_prepare()
798 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_pcm_prepare()
799 /* dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl); */ in snd_cmipci_pcm_prepare()
804 if (runtime->rate > 48000) in snd_cmipci_pcm_prepare()
805 switch (runtime->rate) { in snd_cmipci_pcm_prepare()
812 freq = snd_cmipci_rate_freq(runtime->rate); in snd_cmipci_pcm_prepare()
813 val = snd_cmipci_read(cm, CM_REG_FUNCTRL1); in snd_cmipci_pcm_prepare()
814 if (rec->ch) { in snd_cmipci_pcm_prepare()
821 snd_cmipci_write(cm, CM_REG_FUNCTRL1, val); in snd_cmipci_pcm_prepare()
822 dev_dbg(cm->card->dev, "functrl1 = %08x\n", val); in snd_cmipci_pcm_prepare()
825 val = snd_cmipci_read(cm, CM_REG_CHFORMAT); in snd_cmipci_pcm_prepare()
826 if (rec->ch) { in snd_cmipci_pcm_prepare()
828 val |= rec->fmt << CM_CH1FMT_SHIFT; in snd_cmipci_pcm_prepare()
831 val |= rec->fmt << CM_CH0FMT_SHIFT; in snd_cmipci_pcm_prepare()
833 if (cm->can_96k) { in snd_cmipci_pcm_prepare()
834 val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2)); in snd_cmipci_pcm_prepare()
835 val |= freq_ext << (rec->ch * 2); in snd_cmipci_pcm_prepare()
837 snd_cmipci_write(cm, CM_REG_CHFORMAT, val); in snd_cmipci_pcm_prepare()
838 dev_dbg(cm->card->dev, "chformat = %08x\n", val); in snd_cmipci_pcm_prepare()
840 if (!rec->is_dac && cm->chip_version) { in snd_cmipci_pcm_prepare()
841 if (runtime->rate > 44100) in snd_cmipci_pcm_prepare()
842 snd_cmipci_set_bit(cm, CM_REG_EXT_MISC, CM_ADC48K44K); in snd_cmipci_pcm_prepare()
844 snd_cmipci_clear_bit(cm, CM_REG_EXT_MISC, CM_ADC48K44K); in snd_cmipci_pcm_prepare()
847 rec->running = 0; in snd_cmipci_pcm_prepare()
848 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_pcm_prepare()
856 static int snd_cmipci_pcm_trigger(struct cmipci *cm, struct cmipci_pcm *rec, in snd_cmipci_pcm_trigger() argument
862 inthld = CM_CH0_INT_EN << rec->ch; in snd_cmipci_pcm_trigger()
863 chen = CM_CHEN0 << rec->ch; in snd_cmipci_pcm_trigger()
864 reset = CM_RST_CH0 << rec->ch; in snd_cmipci_pcm_trigger()
865 pause = CM_PAUSE0 << rec->ch; in snd_cmipci_pcm_trigger()
867 spin_lock(&cm->reg_lock); in snd_cmipci_pcm_trigger()
870 rec->running = 1; in snd_cmipci_pcm_trigger()
872 snd_cmipci_set_bit(cm, CM_REG_INT_HLDCLR, inthld); in snd_cmipci_pcm_trigger()
873 cm->ctrl |= chen; in snd_cmipci_pcm_trigger()
875 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_pcm_trigger()
876 dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl); in snd_cmipci_pcm_trigger()
879 rec->running = 0; in snd_cmipci_pcm_trigger()
881 snd_cmipci_clear_bit(cm, CM_REG_INT_HLDCLR, inthld); in snd_cmipci_pcm_trigger()
883 cm->ctrl &= ~chen; in snd_cmipci_pcm_trigger()
884 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset); in snd_cmipci_pcm_trigger()
885 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset); in snd_cmipci_pcm_trigger()
886 rec->needs_silencing = rec->is_dac; in snd_cmipci_pcm_trigger()
890 cm->ctrl |= pause; in snd_cmipci_pcm_trigger()
891 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_pcm_trigger()
895 cm->ctrl &= ~pause; in snd_cmipci_pcm_trigger()
896 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_pcm_trigger()
899 result = -EINVAL; in snd_cmipci_pcm_trigger()
902 spin_unlock(&cm->reg_lock); in snd_cmipci_pcm_trigger()
909 static snd_pcm_uframes_t snd_cmipci_pcm_pointer(struct cmipci *cm, struct cmipci_pcm *rec, in snd_cmipci_pcm_pointer() argument
915 if (!rec->running) in snd_cmipci_pcm_pointer()
918 reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2; in snd_cmipci_pcm_pointer()
920 rem = snd_cmipci_read_w(cm, reg); in snd_cmipci_pcm_pointer()
921 if (rem < rec->dma_size) in snd_cmipci_pcm_pointer()
924 dev_err(cm->card->dev, "invalid PCM pointer: %#x\n", rem); in snd_cmipci_pcm_pointer()
927 ptr = (rec->dma_size - (rem + 1)) >> rec->shift; in snd_cmipci_pcm_pointer()
929 reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1; in snd_cmipci_pcm_pointer()
930 ptr = snd_cmipci_read(cm, reg) - rec->offset; in snd_cmipci_pcm_pointer()
931 ptr = bytes_to_frames(substream->runtime, ptr); in snd_cmipci_pcm_pointer()
933 if (substream->runtime->channels > 2) in snd_cmipci_pcm_pointer()
934 ptr = (ptr * 2) / substream->runtime->channels; in snd_cmipci_pcm_pointer()
945 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback_trigger() local
946 return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_PLAY], cmd); in snd_cmipci_playback_trigger()
951 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback_pointer() local
952 return snd_cmipci_pcm_pointer(cm, &cm->channel[CM_CH_PLAY], substream); in snd_cmipci_playback_pointer()
964 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_capture_trigger() local
965 return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_CAPT], cmd); in snd_cmipci_capture_trigger()
970 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_capture_pointer() local
971 return snd_cmipci_pcm_pointer(cm, &cm->channel[CM_CH_CAPT], substream); in snd_cmipci_capture_pointer()
982 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_cmipci_spdif_default_info()
983 uinfo->count = 1; in snd_cmipci_spdif_default_info()
993 spin_lock_irq(&chip->reg_lock); in snd_cmipci_spdif_default_get()
995 ucontrol->value.iec958.status[i] = (chip->dig_status >> (i * 8)) & 0xff; in snd_cmipci_spdif_default_get()
996 spin_unlock_irq(&chip->reg_lock); in snd_cmipci_spdif_default_get()
1008 spin_lock_irq(&chip->reg_lock); in snd_cmipci_spdif_default_put()
1010 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8); in snd_cmipci_spdif_default_put()
1011 change = val != chip->dig_status; in snd_cmipci_spdif_default_put()
1012 chip->dig_status = val; in snd_cmipci_spdif_default_put()
1013 spin_unlock_irq(&chip->reg_lock); in snd_cmipci_spdif_default_put()
1020 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1029 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_cmipci_spdif_mask_info()
1030 uinfo->count = 1; in snd_cmipci_spdif_mask_info()
1037 ucontrol->value.iec958.status[0] = 0xff; in snd_cmipci_spdif_mask_get()
1038 ucontrol->value.iec958.status[1] = 0xff; in snd_cmipci_spdif_mask_get()
1039 ucontrol->value.iec958.status[2] = 0xff; in snd_cmipci_spdif_mask_get()
1040 ucontrol->value.iec958.status[3] = 0xff; in snd_cmipci_spdif_mask_get()
1048 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1056 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_cmipci_spdif_stream_info()
1057 uinfo->count = 1; in snd_cmipci_spdif_stream_info()
1067 spin_lock_irq(&chip->reg_lock); in snd_cmipci_spdif_stream_get()
1069 ucontrol->value.iec958.status[i] = (chip->dig_pcm_status >> (i * 8)) & 0xff; in snd_cmipci_spdif_stream_get()
1070 spin_unlock_irq(&chip->reg_lock); in snd_cmipci_spdif_stream_get()
1082 spin_lock_irq(&chip->reg_lock); in snd_cmipci_spdif_stream_put()
1084 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8); in snd_cmipci_spdif_stream_put()
1085 change = val != chip->dig_pcm_status; in snd_cmipci_spdif_stream_put()
1086 chip->dig_pcm_status = val; in snd_cmipci_spdif_stream_put()
1087 spin_unlock_irq(&chip->reg_lock); in snd_cmipci_spdif_stream_put()
1095 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
1105 static int save_mixer_state(struct cmipci *cm) in save_mixer_state() argument
1107 if (! cm->mixer_insensitive) { in save_mixer_state()
1113 return -ENOMEM; in save_mixer_state()
1115 struct snd_kcontrol *ctl = cm->mixer_res_ctl[i]; in save_mixer_state()
1119 ctl->get(ctl, val); in save_mixer_state()
1120 cm->mixer_res_status[i] = val->value.integer.value[0]; in save_mixer_state()
1121 val->value.integer.value[0] = cm_saved_mixer[i].toggle_on; in save_mixer_state()
1123 if (cm->mixer_res_status[i] != val->value.integer.value[0]) { in save_mixer_state()
1124 ctl->put(ctl, val); /* toggle */ in save_mixer_state()
1127 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; in save_mixer_state()
1128 snd_ctl_notify(cm->card, event, &ctl->id); in save_mixer_state()
1132 cm->mixer_insensitive = 1; in save_mixer_state()
1139 static void restore_mixer_state(struct cmipci *cm) in restore_mixer_state() argument
1141 if (cm->mixer_insensitive) { in restore_mixer_state()
1148 cm->mixer_insensitive = 0; /* at first clear this; in restore_mixer_state()
1151 struct snd_kcontrol *ctl = cm->mixer_res_ctl[i]; in restore_mixer_state()
1156 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; in restore_mixer_state()
1157 ctl->get(ctl, val); in restore_mixer_state()
1159 if (val->value.integer.value[0] != cm->mixer_res_status[i]) { in restore_mixer_state()
1160 val->value.integer.value[0] = cm->mixer_res_status[i]; in restore_mixer_state()
1161 ctl->put(ctl, val); in restore_mixer_state()
1164 snd_ctl_notify(cm->card, event, &ctl->id); in restore_mixer_state()
1172 static void setup_ac3(struct cmipci *cm, struct snd_pcm_substream *subs, int do_ac3, int rate) in setup_ac3() argument
1176 snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_AC3EN1); in setup_ac3()
1178 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_AC3EN2); in setup_ac3()
1180 if (cm->can_ac3_hw) { in setup_ac3()
1183 snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_SPD24SEL); in setup_ac3()
1184 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); in setup_ac3()
1187 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); in setup_ac3()
1189 if (cm->chip_version == 33) { in setup_ac3()
1191 snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_PLAYBACK_SRATE_176K); in setup_ac3()
1193 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_PLAYBACK_SRATE_176K); in setup_ac3()
1199 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_AC3EN1); in setup_ac3()
1200 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_AC3EN2); in setup_ac3()
1202 if (cm->can_ac3_hw) { in setup_ac3()
1204 if (snd_pcm_format_width(subs->runtime->format) > 16) { in setup_ac3()
1205 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); in setup_ac3()
1206 snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_SPD24SEL); in setup_ac3()
1208 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); in setup_ac3()
1209 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_SPD24SEL); in setup_ac3()
1212 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); in setup_ac3()
1213 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_SPD24SEL); in setup_ac3()
1214 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_PLAYBACK_SRATE_176K); in setup_ac3()
1219 static int setup_spdif_playback(struct cmipci *cm, struct snd_pcm_substream *subs, int up, int do_a… in setup_spdif_playback() argument
1223 rate = subs->runtime->rate; in setup_spdif_playback()
1226 err = save_mixer_state(cm); in setup_spdif_playback()
1231 spin_lock_irq(&cm->reg_lock); in setup_spdif_playback()
1232 cm->spdif_playback_avail = up; in setup_spdif_playback()
1235 /* snd_cmipci_set_bit(cm, CM_REG_LEGACY_CTRL, CM_ENSPDOUT); */ in setup_spdif_playback()
1236 /* snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_SPDO2DAC); */ in setup_spdif_playback()
1237 if (cm->spdif_playback_enabled) in setup_spdif_playback()
1238 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_PLAYBACK_SPDF); in setup_spdif_playback()
1239 setup_ac3(cm, subs, do_ac3, rate); in setup_spdif_playback()
1242 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPDIF48K | CM_SPDF_AC97); in setup_spdif_playback()
1244 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPDIF48K | CM_SPDF_AC97); in setup_spdif_playback()
1246 snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); in setup_spdif_playback()
1248 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); in setup_spdif_playback()
1251 /* snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_ENSPDOUT); */ in setup_spdif_playback()
1252 /* snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_SPDO2DAC); */ in setup_spdif_playback()
1253 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); in setup_spdif_playback()
1254 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_PLAYBACK_SPDF); in setup_spdif_playback()
1255 setup_ac3(cm, subs, 0, 0); in setup_spdif_playback()
1257 spin_unlock_irq(&cm->reg_lock); in setup_spdif_playback()
1266 /* playback - enable spdif only on the certain condition */
1269 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback_prepare() local
1270 int rate = substream->runtime->rate; in snd_cmipci_playback_prepare()
1274 substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE && in snd_cmipci_playback_prepare()
1275 substream->runtime->channels == 2); in snd_cmipci_playback_prepare()
1276 if (do_spdif && cm->can_ac3_hw) in snd_cmipci_playback_prepare()
1277 do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO; in snd_cmipci_playback_prepare()
1278 err = setup_spdif_playback(cm, substream, do_spdif, do_ac3); in snd_cmipci_playback_prepare()
1281 return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_PLAY], substream); in snd_cmipci_playback_prepare()
1284 /* playback (via device #2) - enable spdif always */
1287 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback_spdif_prepare() local
1290 if (cm->can_ac3_hw) in snd_cmipci_playback_spdif_prepare()
1291 do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO; in snd_cmipci_playback_spdif_prepare()
1294 err = setup_spdif_playback(cm, substream, 1, do_ac3); in snd_cmipci_playback_spdif_prepare()
1297 return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_PLAY], substream); in snd_cmipci_playback_spdif_prepare()
1308 static void snd_cmipci_silence_hack(struct cmipci *cm, struct cmipci_pcm *rec) in snd_cmipci_silence_hack() argument
1310 struct snd_pcm_runtime *runtime = rec->substream->runtime; in snd_cmipci_silence_hack()
1313 if (rec->needs_silencing && runtime && runtime->dma_area) { in snd_cmipci_silence_hack()
1315 memset(runtime->dma_area, 0, PAGE_SIZE); in snd_cmipci_silence_hack()
1316 reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2; in snd_cmipci_silence_hack()
1317 val = ((PAGE_SIZE / 4) - 1) | (((PAGE_SIZE / 4) / 2 - 1) << 16); in snd_cmipci_silence_hack()
1318 snd_cmipci_write(cm, reg, val); in snd_cmipci_silence_hack()
1321 if (runtime->channels > 2) in snd_cmipci_silence_hack()
1322 set_dac_channels(cm, rec, 2); in snd_cmipci_silence_hack()
1323 spin_lock_irq(&cm->reg_lock); in snd_cmipci_silence_hack()
1324 val = snd_cmipci_read(cm, CM_REG_FUNCTRL1); in snd_cmipci_silence_hack()
1325 val &= ~(CM_ASFC_MASK << (rec->ch * 3)); in snd_cmipci_silence_hack()
1326 val |= (4 << CM_ASFC_SHIFT) << (rec->ch * 3); in snd_cmipci_silence_hack()
1327 snd_cmipci_write(cm, CM_REG_FUNCTRL1, val); in snd_cmipci_silence_hack()
1328 val = snd_cmipci_read(cm, CM_REG_CHFORMAT); in snd_cmipci_silence_hack()
1329 val &= ~(CM_CH0FMT_MASK << (rec->ch * 2)); in snd_cmipci_silence_hack()
1330 val |= (3 << CM_CH0FMT_SHIFT) << (rec->ch * 2); in snd_cmipci_silence_hack()
1331 if (cm->can_96k) in snd_cmipci_silence_hack()
1332 val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2)); in snd_cmipci_silence_hack()
1333 snd_cmipci_write(cm, CM_REG_CHFORMAT, val); in snd_cmipci_silence_hack()
1336 cm->ctrl |= CM_CHEN0 << rec->ch; in snd_cmipci_silence_hack()
1337 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_silence_hack()
1338 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_silence_hack()
1343 spin_lock_irq(&cm->reg_lock); in snd_cmipci_silence_hack()
1344 cm->ctrl &= ~(CM_CHEN0 << rec->ch); in snd_cmipci_silence_hack()
1345 val = CM_RST_CH0 << rec->ch; in snd_cmipci_silence_hack()
1346 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | val); in snd_cmipci_silence_hack()
1347 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~val); in snd_cmipci_silence_hack()
1348 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_silence_hack()
1350 rec->needs_silencing = 0; in snd_cmipci_silence_hack()
1356 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback_hw_free() local
1357 setup_spdif_playback(cm, substream, 0, 0); in snd_cmipci_playback_hw_free()
1358 restore_mixer_state(cm); in snd_cmipci_playback_hw_free()
1359 snd_cmipci_silence_hack(cm, &cm->channel[0]); in snd_cmipci_playback_hw_free()
1365 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback2_hw_free() local
1366 snd_cmipci_silence_hack(cm, &cm->channel[1]); in snd_cmipci_playback2_hw_free()
1373 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_capture_prepare() local
1374 return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_CAPT], substream); in snd_cmipci_capture_prepare()
1380 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_capture_spdif_prepare() local
1382 spin_lock_irq(&cm->reg_lock); in snd_cmipci_capture_spdif_prepare()
1383 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF); in snd_cmipci_capture_spdif_prepare()
1384 if (cm->can_96k) { in snd_cmipci_capture_spdif_prepare()
1385 if (substream->runtime->rate > 48000) in snd_cmipci_capture_spdif_prepare()
1386 snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); in snd_cmipci_capture_spdif_prepare()
1388 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); in snd_cmipci_capture_spdif_prepare()
1390 if (snd_pcm_format_width(substream->runtime->format) > 16) in snd_cmipci_capture_spdif_prepare()
1391 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); in snd_cmipci_capture_spdif_prepare()
1393 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); in snd_cmipci_capture_spdif_prepare()
1395 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_capture_spdif_prepare()
1397 return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_CAPT], substream); in snd_cmipci_capture_spdif_prepare()
1402 struct cmipci *cm = snd_pcm_substream_chip(subs); in snd_cmipci_capture_spdif_hw_free() local
1404 spin_lock_irq(&cm->reg_lock); in snd_cmipci_capture_spdif_hw_free()
1405 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF); in snd_cmipci_capture_spdif_hw_free()
1406 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); in snd_cmipci_capture_spdif_hw_free()
1407 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_capture_spdif_hw_free()
1418 struct cmipci *cm = dev_id; in snd_cmipci_interrupt() local
1422 status = snd_cmipci_read(cm, CM_REG_INT_STATUS); in snd_cmipci_interrupt()
1427 spin_lock(&cm->reg_lock); in snd_cmipci_interrupt()
1432 snd_cmipci_clear_bit(cm, CM_REG_INT_HLDCLR, mask); in snd_cmipci_interrupt()
1433 snd_cmipci_set_bit(cm, CM_REG_INT_HLDCLR, mask); in snd_cmipci_interrupt()
1434 spin_unlock(&cm->reg_lock); in snd_cmipci_interrupt()
1436 if (cm->rmidi && (status & CM_UARTINT)) in snd_cmipci_interrupt()
1437 snd_mpu401_uart_interrupt(irq, cm->rmidi->private_data); in snd_cmipci_interrupt()
1439 if (cm->pcm) { in snd_cmipci_interrupt()
1440 if ((status & CM_CHINT0) && cm->channel[0].running) in snd_cmipci_interrupt()
1441 snd_pcm_period_elapsed(cm->channel[0].substream); in snd_cmipci_interrupt()
1442 if ((status & CM_CHINT1) && cm->channel[1].running) in snd_cmipci_interrupt()
1443 snd_pcm_period_elapsed(cm->channel[1].substream); in snd_cmipci_interrupt()
1492 /* playback on channel B - stereo 16bit only? */
1576 static int open_device_check(struct cmipci *cm, int mode, struct snd_pcm_substream *subs) in open_device_check() argument
1585 mutex_lock(&cm->open_mutex); in open_device_check()
1586 if (cm->opened[ch]) { in open_device_check()
1587 mutex_unlock(&cm->open_mutex); in open_device_check()
1588 return -EBUSY; in open_device_check()
1590 cm->opened[ch] = mode; in open_device_check()
1591 cm->channel[ch].substream = subs; in open_device_check()
1594 cm->channel[ch].is_dac = 0; in open_device_check()
1595 spin_lock_irq(&cm->reg_lock); in open_device_check()
1596 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_ENDBDAC); in open_device_check()
1597 spin_unlock_irq(&cm->reg_lock); in open_device_check()
1599 mutex_unlock(&cm->open_mutex); in open_device_check()
1603 static void close_device_check(struct cmipci *cm, int mode) in close_device_check() argument
1607 mutex_lock(&cm->open_mutex); in close_device_check()
1608 if (cm->opened[ch] == mode) { in close_device_check()
1609 if (cm->channel[ch].substream) { in close_device_check()
1610 snd_cmipci_ch_reset(cm, ch); in close_device_check()
1611 cm->channel[ch].running = 0; in close_device_check()
1612 cm->channel[ch].substream = NULL; in close_device_check()
1614 cm->opened[ch] = 0; in close_device_check()
1615 if (! cm->channel[ch].is_dac) { in close_device_check()
1617 cm->channel[ch].is_dac = 1; in close_device_check()
1618 spin_lock_irq(&cm->reg_lock); in close_device_check()
1619 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_ENDBDAC); in close_device_check()
1620 spin_unlock_irq(&cm->reg_lock); in close_device_check()
1623 mutex_unlock(&cm->open_mutex); in close_device_check()
1631 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback_open() local
1632 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_playback_open()
1635 err = open_device_check(cm, CM_OPEN_PLAYBACK, substream); in snd_cmipci_playback_open()
1638 runtime->hw = snd_cmipci_playback; in snd_cmipci_playback_open()
1639 if (cm->chip_version == 68) { in snd_cmipci_playback_open()
1640 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_playback_open()
1642 runtime->hw.rate_max = 96000; in snd_cmipci_playback_open()
1643 } else if (cm->chip_version == 55) { in snd_cmipci_playback_open()
1644 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_playback_open()
1647 runtime->hw.rate_max = 128000; in snd_cmipci_playback_open()
1650 cm->dig_pcm_status = cm->dig_status; in snd_cmipci_playback_open()
1656 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_capture_open() local
1657 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_capture_open()
1660 err = open_device_check(cm, CM_OPEN_CAPTURE, substream); in snd_cmipci_capture_open()
1663 runtime->hw = snd_cmipci_capture; in snd_cmipci_capture_open()
1664 if (cm->chip_version == 68) { // 8768 only supports 44k/48k recording in snd_cmipci_capture_open()
1665 runtime->hw.rate_min = 41000; in snd_cmipci_capture_open()
1666 runtime->hw.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; in snd_cmipci_capture_open()
1667 } else if (cm->chip_version == 55) { in snd_cmipci_capture_open()
1668 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_capture_open()
1671 runtime->hw.rate_max = 128000; in snd_cmipci_capture_open()
1679 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback2_open() local
1680 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_playback2_open()
1684 err = open_device_check(cm, CM_OPEN_PLAYBACK2, substream); in snd_cmipci_playback2_open()
1687 runtime->hw = snd_cmipci_playback2; in snd_cmipci_playback2_open()
1688 mutex_lock(&cm->open_mutex); in snd_cmipci_playback2_open()
1689 if (! cm->opened[CM_CH_PLAY]) { in snd_cmipci_playback2_open()
1690 if (cm->can_multi_ch) { in snd_cmipci_playback2_open()
1691 runtime->hw.channels_max = cm->max_channels; in snd_cmipci_playback2_open()
1692 if (cm->max_channels == 4) in snd_cmipci_playback2_open()
1694 else if (cm->max_channels == 6) in snd_cmipci_playback2_open()
1696 else if (cm->max_channels == 8) in snd_cmipci_playback2_open()
1700 mutex_unlock(&cm->open_mutex); in snd_cmipci_playback2_open()
1701 if (cm->chip_version == 68) { in snd_cmipci_playback2_open()
1702 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_playback2_open()
1704 runtime->hw.rate_max = 96000; in snd_cmipci_playback2_open()
1705 } else if (cm->chip_version == 55) { in snd_cmipci_playback2_open()
1706 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_playback2_open()
1709 runtime->hw.rate_max = 128000; in snd_cmipci_playback2_open()
1717 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback_spdif_open() local
1718 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_playback_spdif_open()
1722 err = open_device_check(cm, CM_OPEN_SPDIF_PLAYBACK, substream); in snd_cmipci_playback_spdif_open()
1725 if (cm->can_ac3_hw) { in snd_cmipci_playback_spdif_open()
1726 runtime->hw = snd_cmipci_playback_spdif; in snd_cmipci_playback_spdif_open()
1727 if (cm->chip_version >= 37) { in snd_cmipci_playback_spdif_open()
1728 runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE; in snd_cmipci_playback_spdif_open()
1731 if (cm->can_96k) { in snd_cmipci_playback_spdif_open()
1732 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_playback_spdif_open()
1734 runtime->hw.rate_max = 96000; in snd_cmipci_playback_spdif_open()
1737 runtime->hw = snd_cmipci_playback_iec958_subframe; in snd_cmipci_playback_spdif_open()
1740 cm->dig_pcm_status = cm->dig_status; in snd_cmipci_playback_spdif_open()
1746 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_capture_spdif_open() local
1747 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_capture_spdif_open()
1751 err = open_device_check(cm, CM_OPEN_SPDIF_CAPTURE, substream); in snd_cmipci_capture_spdif_open()
1754 runtime->hw = snd_cmipci_capture_spdif; in snd_cmipci_capture_spdif_open()
1755 if (cm->can_96k && !(cm->chip_version == 68)) { in snd_cmipci_capture_spdif_open()
1756 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_capture_spdif_open()
1758 runtime->hw.rate_max = 96000; in snd_cmipci_capture_spdif_open()
1770 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback_close() local
1771 close_device_check(cm, CM_OPEN_PLAYBACK); in snd_cmipci_playback_close()
1777 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_capture_close() local
1778 close_device_check(cm, CM_OPEN_CAPTURE); in snd_cmipci_capture_close()
1784 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback2_close() local
1785 close_device_check(cm, CM_OPEN_PLAYBACK2); in snd_cmipci_playback2_close()
1786 close_device_check(cm, CM_OPEN_PLAYBACK_MULTI); in snd_cmipci_playback2_close()
1792 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_playback_spdif_close() local
1793 close_device_check(cm, CM_OPEN_SPDIF_PLAYBACK); in snd_cmipci_playback_spdif_close()
1799 struct cmipci *cm = snd_pcm_substream_chip(substream); in snd_cmipci_capture_spdif_close() local
1800 close_device_check(cm, CM_OPEN_SPDIF_CAPTURE); in snd_cmipci_capture_spdif_close()
1857 static int snd_cmipci_pcm_new(struct cmipci *cm, int device) in snd_cmipci_pcm_new() argument
1862 err = snd_pcm_new(cm->card, cm->card->driver, device, 1, 1, &pcm); in snd_cmipci_pcm_new()
1869 pcm->private_data = cm; in snd_cmipci_pcm_new()
1870 pcm->info_flags = 0; in snd_cmipci_pcm_new()
1871 strcpy(pcm->name, "C-Media PCI DAC/ADC"); in snd_cmipci_pcm_new()
1872 cm->pcm = pcm; in snd_cmipci_pcm_new()
1875 &cm->pci->dev, 64*1024, 128*1024); in snd_cmipci_pcm_new()
1880 static int snd_cmipci_pcm2_new(struct cmipci *cm, int device) in snd_cmipci_pcm2_new() argument
1885 err = snd_pcm_new(cm->card, cm->card->driver, device, 1, 0, &pcm); in snd_cmipci_pcm2_new()
1891 pcm->private_data = cm; in snd_cmipci_pcm2_new()
1892 pcm->info_flags = 0; in snd_cmipci_pcm2_new()
1893 strcpy(pcm->name, "C-Media PCI 2nd DAC"); in snd_cmipci_pcm2_new()
1894 cm->pcm2 = pcm; in snd_cmipci_pcm2_new()
1897 &cm->pci->dev, 64*1024, 128*1024); in snd_cmipci_pcm2_new()
1902 static int snd_cmipci_pcm_spdif_new(struct cmipci *cm, int device) in snd_cmipci_pcm_spdif_new() argument
1907 err = snd_pcm_new(cm->card, cm->card->driver, device, 1, 1, &pcm); in snd_cmipci_pcm_spdif_new()
1914 pcm->private_data = cm; in snd_cmipci_pcm_spdif_new()
1915 pcm->info_flags = 0; in snd_cmipci_pcm_spdif_new()
1916 strcpy(pcm->name, "C-Media PCI IEC958"); in snd_cmipci_pcm_spdif_new()
1917 cm->pcm_spdif = pcm; in snd_cmipci_pcm_spdif_new()
1920 &cm->pci->dev, 64*1024, 128*1024); in snd_cmipci_pcm_spdif_new()
1923 snd_pcm_alt_chmaps, cm->max_channels, 0, in snd_cmipci_pcm_spdif_new()
1933 * - CM8338/8738 has a compatible mixer interface with SB16, but
1935 * - Access to native registers:
1936 * - A 3D switch
1937 * - Output mute switches
1942 outb(idx, s->iobase + CM_REG_SB16_ADDR); in snd_cmipci_mixer_write()
1943 outb(data, s->iobase + CM_REG_SB16_DATA); in snd_cmipci_mixer_write()
1950 outb(idx, s->iobase + CM_REG_SB16_ADDR); in snd_cmipci_mixer_read()
1951 v = inb(s->iobase + CM_REG_SB16_DATA); in snd_cmipci_mixer_read()
1970 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1983 r->left_reg = val & 0xff; in cmipci_sb_reg_decode()
1984 r->right_reg = (val >> 8) & 0xff; in cmipci_sb_reg_decode()
1985 r->left_shift = (val >> 16) & 0x07; in cmipci_sb_reg_decode()
1986 r->right_shift = (val >> 19) & 0x07; in cmipci_sb_reg_decode()
1987 r->invert = (val >> 22) & 1; in cmipci_sb_reg_decode()
1988 r->stereo = (val >> 23) & 1; in cmipci_sb_reg_decode()
1989 r->mask = (val >> 24) & 0xff; in cmipci_sb_reg_decode()
1997 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_info_volume()
1998 uinfo->type = reg.mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_cmipci_info_volume()
1999 uinfo->count = reg.stereo + 1; in snd_cmipci_info_volume()
2000 uinfo->value.integer.min = 0; in snd_cmipci_info_volume()
2001 uinfo->value.integer.max = reg.mask; in snd_cmipci_info_volume()
2008 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_get_volume() local
2012 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_get_volume()
2013 spin_lock_irq(&cm->reg_lock); in snd_cmipci_get_volume()
2014 val = (snd_cmipci_mixer_read(cm, reg.left_reg) >> reg.left_shift) & reg.mask; in snd_cmipci_get_volume()
2016 val = reg.mask - val; in snd_cmipci_get_volume()
2017 ucontrol->value.integer.value[0] = val; in snd_cmipci_get_volume()
2019 val = (snd_cmipci_mixer_read(cm, reg.right_reg) >> reg.right_shift) & reg.mask; in snd_cmipci_get_volume()
2021 val = reg.mask - val; in snd_cmipci_get_volume()
2022 ucontrol->value.integer.value[1] = val; in snd_cmipci_get_volume()
2024 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_get_volume()
2031 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_put_volume() local
2036 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_put_volume()
2037 left = ucontrol->value.integer.value[0] & reg.mask; in snd_cmipci_put_volume()
2039 left = reg.mask - left; in snd_cmipci_put_volume()
2042 right = ucontrol->value.integer.value[1] & reg.mask; in snd_cmipci_put_volume()
2044 right = reg.mask - right; in snd_cmipci_put_volume()
2048 spin_lock_irq(&cm->reg_lock); in snd_cmipci_put_volume()
2049 oleft = snd_cmipci_mixer_read(cm, reg.left_reg); in snd_cmipci_put_volume()
2054 snd_cmipci_mixer_write(cm, reg.left_reg, left); in snd_cmipci_put_volume()
2055 oright = snd_cmipci_mixer_read(cm, reg.right_reg); in snd_cmipci_put_volume()
2060 snd_cmipci_mixer_write(cm, reg.right_reg, right); in snd_cmipci_put_volume()
2062 snd_cmipci_mixer_write(cm, reg.left_reg, left); in snd_cmipci_put_volume()
2063 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_put_volume()
2068 * input route (left,right) -> (left,right)
2071 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2080 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; in snd_cmipci_info_input_sw()
2081 uinfo->count = 4; in snd_cmipci_info_input_sw()
2082 uinfo->value.integer.min = 0; in snd_cmipci_info_input_sw()
2083 uinfo->value.integer.max = 1; in snd_cmipci_info_input_sw()
2090 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_get_input_sw() local
2094 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_get_input_sw()
2095 spin_lock_irq(&cm->reg_lock); in snd_cmipci_get_input_sw()
2096 val1 = snd_cmipci_mixer_read(cm, reg.left_reg); in snd_cmipci_get_input_sw()
2097 val2 = snd_cmipci_mixer_read(cm, reg.right_reg); in snd_cmipci_get_input_sw()
2098 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_get_input_sw()
2099 ucontrol->value.integer.value[0] = (val1 >> reg.left_shift) & 1; in snd_cmipci_get_input_sw()
2100 ucontrol->value.integer.value[1] = (val2 >> reg.left_shift) & 1; in snd_cmipci_get_input_sw()
2101 ucontrol->value.integer.value[2] = (val1 >> reg.right_shift) & 1; in snd_cmipci_get_input_sw()
2102 ucontrol->value.integer.value[3] = (val2 >> reg.right_shift) & 1; in snd_cmipci_get_input_sw()
2109 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_put_input_sw() local
2114 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_put_input_sw()
2115 spin_lock_irq(&cm->reg_lock); in snd_cmipci_put_input_sw()
2116 oval1 = snd_cmipci_mixer_read(cm, reg.left_reg); in snd_cmipci_put_input_sw()
2117 oval2 = snd_cmipci_mixer_read(cm, reg.right_reg); in snd_cmipci_put_input_sw()
2120 val1 |= (ucontrol->value.integer.value[0] & 1) << reg.left_shift; in snd_cmipci_put_input_sw()
2121 val2 |= (ucontrol->value.integer.value[1] & 1) << reg.left_shift; in snd_cmipci_put_input_sw()
2122 val1 |= (ucontrol->value.integer.value[2] & 1) << reg.right_shift; in snd_cmipci_put_input_sw()
2123 val2 |= (ucontrol->value.integer.value[3] & 1) << reg.right_shift; in snd_cmipci_put_input_sw()
2125 snd_cmipci_mixer_write(cm, reg.left_reg, val1); in snd_cmipci_put_input_sw()
2126 snd_cmipci_mixer_write(cm, reg.right_reg, val2); in snd_cmipci_put_input_sw()
2127 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_put_input_sw()
2136 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2143 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2150 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2157 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2168 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_info_native_mixer()
2169 uinfo->type = reg.mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_cmipci_info_native_mixer()
2170 uinfo->count = reg.stereo + 1; in snd_cmipci_info_native_mixer()
2171 uinfo->value.integer.min = 0; in snd_cmipci_info_native_mixer()
2172 uinfo->value.integer.max = reg.mask; in snd_cmipci_info_native_mixer()
2180 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_get_native_mixer() local
2184 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_get_native_mixer()
2185 spin_lock_irq(&cm->reg_lock); in snd_cmipci_get_native_mixer()
2186 oreg = inb(cm->iobase + reg.left_reg); in snd_cmipci_get_native_mixer()
2189 val = reg.mask - val; in snd_cmipci_get_native_mixer()
2190 ucontrol->value.integer.value[0] = val; in snd_cmipci_get_native_mixer()
2194 val = reg.mask - val; in snd_cmipci_get_native_mixer()
2195 ucontrol->value.integer.value[1] = val; in snd_cmipci_get_native_mixer()
2197 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_get_native_mixer()
2204 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_put_native_mixer() local
2208 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_put_native_mixer()
2209 spin_lock_irq(&cm->reg_lock); in snd_cmipci_put_native_mixer()
2210 oreg = inb(cm->iobase + reg.left_reg); in snd_cmipci_put_native_mixer()
2211 val = ucontrol->value.integer.value[0] & reg.mask; in snd_cmipci_put_native_mixer()
2213 val = reg.mask - val; in snd_cmipci_put_native_mixer()
2217 val = ucontrol->value.integer.value[1] & reg.mask; in snd_cmipci_put_native_mixer()
2219 val = reg.mask - val; in snd_cmipci_put_native_mixer()
2223 outb(nreg, cm->iobase + reg.left_reg); in snd_cmipci_put_native_mixer()
2224 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_put_native_mixer()
2229 * special case - check mixer sensitivity
2234 //struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_get_native_mixer_sensitive()
2241 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_put_native_mixer_sensitive() local
2242 if (cm->mixer_insensitive) { in snd_cmipci_put_native_mixer_sensitive()
2252 CMIPCI_MIXER_SW_MONO("3D Control - Switch", CM_REG_MIXER1, CM_X3DEN_SHIFT, 0),
2257 .name = "PCM Playback Switch",
2298 * non-audio operation?
2309 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in _snd_cmipci_uswitch_get() local
2311 spin_lock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_get()
2312 if (args->ac3_sensitive && cm->mixer_insensitive) { in _snd_cmipci_uswitch_get()
2313 ucontrol->value.integer.value[0] = 0; in _snd_cmipci_uswitch_get()
2314 spin_unlock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_get()
2317 if (args->is_byte) in _snd_cmipci_uswitch_get()
2318 val = inb(cm->iobase + args->reg); in _snd_cmipci_uswitch_get()
2320 val = snd_cmipci_read(cm, args->reg); in _snd_cmipci_uswitch_get()
2321 ucontrol->value.integer.value[0] = ((val & args->mask) == args->mask_on) ? 1 : 0; in _snd_cmipci_uswitch_get()
2322 spin_unlock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_get()
2330 args = (struct cmipci_switch_args *)kcontrol->private_value; in snd_cmipci_uswitch_get()
2332 return -EINVAL; in snd_cmipci_uswitch_get()
2342 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in _snd_cmipci_uswitch_put() local
2344 spin_lock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_put()
2345 if (args->ac3_sensitive && cm->mixer_insensitive) { in _snd_cmipci_uswitch_put()
2347 spin_unlock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_put()
2350 if (args->is_byte) in _snd_cmipci_uswitch_put()
2351 val = inb(cm->iobase + args->reg); in _snd_cmipci_uswitch_put()
2353 val = snd_cmipci_read(cm, args->reg); in _snd_cmipci_uswitch_put()
2354 change = (val & args->mask) != (ucontrol->value.integer.value[0] ? in _snd_cmipci_uswitch_put()
2355 args->mask_on : (args->mask & ~args->mask_on)); in _snd_cmipci_uswitch_put()
2357 val &= ~args->mask; in _snd_cmipci_uswitch_put()
2358 if (ucontrol->value.integer.value[0]) in _snd_cmipci_uswitch_put()
2359 val |= args->mask_on; in _snd_cmipci_uswitch_put()
2361 val |= (args->mask & ~args->mask_on); in _snd_cmipci_uswitch_put()
2362 if (args->is_byte) in _snd_cmipci_uswitch_put()
2363 outb((unsigned char)val, cm->iobase + args->reg); in _snd_cmipci_uswitch_put()
2365 snd_cmipci_write(cm, args->reg, val); in _snd_cmipci_uswitch_put()
2367 spin_unlock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_put()
2375 args = (struct cmipci_switch_args *)kcontrol->private_value; in snd_cmipci_uswitch_put()
2377 return -EINVAL; in snd_cmipci_uswitch_put()
2423 { .name = sname, \
2456 if (ucontrol->value.integer.value[0]) { in snd_cmipci_spdout_enable_put()
2457 if (chip->spdif_playback_avail) in snd_cmipci_spdout_enable_put()
2460 if (chip->spdif_playback_avail) in snd_cmipci_spdout_enable_put()
2464 chip->spdif_playback_enabled = ucontrol->value.integer.value[0]; in snd_cmipci_spdout_enable_put()
2472 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_line_in_mode_info() local
2474 "Line-In", "Rear Output", "Bass Output" in snd_cmipci_line_in_mode_info()
2478 cm->chip_version >= 39 ? 3 : 2, texts); in snd_cmipci_line_in_mode_info()
2481 static inline unsigned int get_line_in_mode(struct cmipci *cm) in get_line_in_mode() argument
2484 if (cm->chip_version >= 39) { in get_line_in_mode()
2485 val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL); in get_line_in_mode()
2489 val = snd_cmipci_read_b(cm, CM_REG_MIXER1); in get_line_in_mode()
2498 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_line_in_mode_get() local
2500 spin_lock_irq(&cm->reg_lock); in snd_cmipci_line_in_mode_get()
2501 ucontrol->value.enumerated.item[0] = get_line_in_mode(cm); in snd_cmipci_line_in_mode_get()
2502 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_line_in_mode_get()
2509 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_line_in_mode_put() local
2512 spin_lock_irq(&cm->reg_lock); in snd_cmipci_line_in_mode_put()
2513 if (ucontrol->value.enumerated.item[0] == 2) in snd_cmipci_line_in_mode_put()
2514 change = snd_cmipci_set_bit(cm, CM_REG_LEGACY_CTRL, CM_CENTR2LIN | CM_BASE2LIN); in snd_cmipci_line_in_mode_put()
2516 change = snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_CENTR2LIN | CM_BASE2LIN); in snd_cmipci_line_in_mode_put()
2517 if (ucontrol->value.enumerated.item[0] == 1) in snd_cmipci_line_in_mode_put()
2518 change |= snd_cmipci_set_bit_b(cm, CM_REG_MIXER1, CM_REAR2LIN); in snd_cmipci_line_in_mode_put()
2520 change |= snd_cmipci_clear_bit_b(cm, CM_REG_MIXER1, CM_REAR2LIN); in snd_cmipci_line_in_mode_put()
2521 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_line_in_mode_put()
2528 static const char *const texts[2] = { "Mic-In", "Center/LFE Output" }; in snd_cmipci_mic_in_mode_info()
2536 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_mic_in_mode_get() local
2538 spin_lock_irq(&cm->reg_lock); in snd_cmipci_mic_in_mode_get()
2539 ucontrol->value.enumerated.item[0] = in snd_cmipci_mic_in_mode_get()
2540 (snd_cmipci_read_b(cm, CM_REG_MISC) & CM_SPDIF_INVERSE) ? 1 : 0; in snd_cmipci_mic_in_mode_get()
2541 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_mic_in_mode_get()
2548 struct cmipci *cm = snd_kcontrol_chip(kcontrol); in snd_cmipci_mic_in_mode_put() local
2551 spin_lock_irq(&cm->reg_lock); in snd_cmipci_mic_in_mode_put()
2552 if (ucontrol->value.enumerated.item[0]) in snd_cmipci_mic_in_mode_put()
2553 change = snd_cmipci_set_bit_b(cm, CM_REG_MISC, CM_SPDIF_INVERSE); in snd_cmipci_mic_in_mode_put()
2555 change = snd_cmipci_clear_bit_b(cm, CM_REG_MISC, CM_SPDIF_INVERSE); in snd_cmipci_mic_in_mode_put()
2556 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_mic_in_mode_put()
2564 .name = "Line-In Mode",
2572 /* for non-multichannel chips */
2584 { .name = "IEC958 Output Switch",
2610 .name = "Mic-In Mode",
2623 static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device) in snd_cmipci_mixer_new() argument
2631 if (snd_BUG_ON(!cm || !cm->card)) in snd_cmipci_mixer_new()
2632 return -EINVAL; in snd_cmipci_mixer_new()
2634 card = cm->card; in snd_cmipci_mixer_new()
2636 strcpy(card->mixername, "CMedia PCI"); in snd_cmipci_mixer_new()
2638 spin_lock_irq(&cm->reg_lock); in snd_cmipci_mixer_new()
2639 snd_cmipci_mixer_write(cm, 0x00, 0x00); /* mixer reset */ in snd_cmipci_mixer_new()
2640 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_mixer_new()
2643 if (cm->chip_version == 68) { // 8768 has no PCM volume in snd_cmipci_mixer_new()
2644 if (!strcmp(snd_cmipci_mixers[idx].name, in snd_cmipci_mixer_new()
2648 err = snd_ctl_add(card, snd_ctl_new1(&snd_cmipci_mixers[idx], cm)); in snd_cmipci_mixer_new()
2656 err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm)); in snd_cmipci_mixer_new()
2660 if (! cm->can_multi_ch) { in snd_cmipci_mixer_new()
2661 err = snd_ctl_add(cm->card, snd_ctl_new1(&snd_cmipci_nomulti_switch, cm)); in snd_cmipci_mixer_new()
2665 if (cm->device == PCI_DEVICE_ID_CMEDIA_CM8738 || in snd_cmipci_mixer_new()
2666 cm->device == PCI_DEVICE_ID_CMEDIA_CM8738B) { in snd_cmipci_mixer_new()
2669 err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm)); in snd_cmipci_mixer_new()
2673 if (cm->can_ac3_hw) { in snd_cmipci_mixer_new()
2674 kctl = snd_ctl_new1(&snd_cmipci_spdif_default, cm); in snd_cmipci_mixer_new()
2675 kctl->id.device = pcm_spdif_device; in snd_cmipci_mixer_new()
2679 kctl = snd_ctl_new1(&snd_cmipci_spdif_mask, cm); in snd_cmipci_mixer_new()
2680 kctl->id.device = pcm_spdif_device; in snd_cmipci_mixer_new()
2684 kctl = snd_ctl_new1(&snd_cmipci_spdif_stream, cm); in snd_cmipci_mixer_new()
2685 kctl->id.device = pcm_spdif_device; in snd_cmipci_mixer_new()
2690 if (cm->chip_version <= 37) { in snd_cmipci_mixer_new()
2693 err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm)); in snd_cmipci_mixer_new()
2699 if (cm->chip_version >= 39) { in snd_cmipci_mixer_new()
2702 err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm)); in snd_cmipci_mixer_new()
2713 if (cm->chip_version < 39) { in snd_cmipci_mixer_new()
2714 err = snd_ctl_add(cm->card, in snd_cmipci_mixer_new()
2715 snd_ctl_new1(&snd_cmipci_modem_switch, cm)); in snd_cmipci_mixer_new()
2722 ctl = snd_ctl_find_id_mixer(cm->card, cm_saved_mixer[idx].name); in snd_cmipci_mixer_new()
2724 cm->mixer_res_ctl[idx] = ctl; in snd_cmipci_mixer_new()
2738 struct cmipci *cm = entry->private_data; in snd_cmipci_proc_read() local
2741 snd_iprintf(buffer, "%s\n", cm->card->longname); in snd_cmipci_proc_read()
2745 v = inb(cm->iobase + i); in snd_cmipci_proc_read()
2753 static void snd_cmipci_proc_init(struct cmipci *cm) in snd_cmipci_proc_init() argument
2755 snd_card_ro_proc_new(cm->card, "cmipci", cm, snd_cmipci_proc_read); in snd_cmipci_proc_init()
2770 * driver name is modified according to the chip model
2772 static void query_chip(struct cmipci *cm) in query_chip() argument
2776 /* check reg 0Ch, bit 24-31 */ in query_chip()
2777 detect = snd_cmipci_read(cm, CM_REG_INT_HLDCLR) & CM_CHIP_MASK2; in query_chip()
2779 /* check reg 08h, bit 24-28 */ in query_chip()
2780 detect = snd_cmipci_read(cm, CM_REG_CHFORMAT) & CM_CHIP_MASK1; in query_chip()
2783 cm->chip_version = 33; in query_chip()
2784 if (cm->do_soft_ac3) in query_chip()
2785 cm->can_ac3_sw = 1; in query_chip()
2787 cm->can_ac3_hw = 1; in query_chip()
2790 cm->chip_version = 37; in query_chip()
2791 cm->can_ac3_hw = 1; in query_chip()
2794 cm->chip_version = 39; in query_chip()
2795 cm->can_ac3_hw = 1; in query_chip()
2798 cm->max_channels = 2; in query_chip()
2801 cm->chip_version = 39; in query_chip()
2803 cm->max_channels = 6; in query_chip()
2805 cm->max_channels = 4; in query_chip()
2807 cm->chip_version = 68; in query_chip()
2808 cm->max_channels = 8; in query_chip()
2809 cm->can_96k = 1; in query_chip()
2811 cm->chip_version = 55; in query_chip()
2812 cm->max_channels = 6; in query_chip()
2813 cm->can_96k = 1; in query_chip()
2815 cm->can_ac3_hw = 1; in query_chip()
2816 cm->can_multi_ch = 1; in query_chip()
2821 static int snd_cmipci_create_gameport(struct cmipci *cm, int dev) in snd_cmipci_create_gameport() argument
2829 return -ENODEV; in snd_cmipci_create_gameport()
2831 if (joystick_port[dev] == 1) { /* auto-detect */ in snd_cmipci_create_gameport()
2834 r = devm_request_region(&cm->pci->dev, io_port, 1, in snd_cmipci_create_gameport()
2841 r = devm_request_region(&cm->pci->dev, io_port, 1, in snd_cmipci_create_gameport()
2846 dev_warn(cm->card->dev, "cannot reserve joystick ports\n"); in snd_cmipci_create_gameport()
2847 return -EBUSY; in snd_cmipci_create_gameport()
2850 cm->gameport = gp = gameport_allocate_port(); in snd_cmipci_create_gameport()
2852 dev_err(cm->card->dev, "cannot allocate memory for gameport\n"); in snd_cmipci_create_gameport()
2853 return -ENOMEM; in snd_cmipci_create_gameport()
2855 gameport_set_name(gp, "C-Media Gameport"); in snd_cmipci_create_gameport()
2856 gameport_set_phys(gp, "pci%s/gameport0", pci_name(cm->pci)); in snd_cmipci_create_gameport()
2857 gameport_set_dev_parent(gp, &cm->pci->dev); in snd_cmipci_create_gameport()
2858 gp->io = io_port; in snd_cmipci_create_gameport()
2860 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN); in snd_cmipci_create_gameport()
2862 gameport_register_port(cm->gameport); in snd_cmipci_create_gameport()
2867 static void snd_cmipci_free_gameport(struct cmipci *cm) in snd_cmipci_free_gameport() argument
2869 if (cm->gameport) { in snd_cmipci_free_gameport()
2870 gameport_unregister_port(cm->gameport); in snd_cmipci_free_gameport()
2871 cm->gameport = NULL; in snd_cmipci_free_gameport()
2873 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN); in snd_cmipci_free_gameport()
2877 static inline int snd_cmipci_create_gameport(struct cmipci *cm, int dev) { return -ENOSYS; } in snd_cmipci_create_gameport() argument
2878 static inline void snd_cmipci_free_gameport(struct cmipci *cm) { } in snd_cmipci_free_gameport() argument
2883 struct cmipci *cm = card->private_data; in snd_cmipci_free() local
2885 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN); in snd_cmipci_free()
2886 snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_ENSPDOUT); in snd_cmipci_free()
2887 snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0); /* disable ints */ in snd_cmipci_free()
2888 snd_cmipci_ch_reset(cm, CM_CH_PLAY); in snd_cmipci_free()
2889 snd_cmipci_ch_reset(cm, CM_CH_CAPT); in snd_cmipci_free()
2890 snd_cmipci_write(cm, CM_REG_FUNCTRL0, 0); /* disable channels */ in snd_cmipci_free()
2891 snd_cmipci_write(cm, CM_REG_FUNCTRL1, 0); in snd_cmipci_free()
2894 snd_cmipci_mixer_write(cm, 0, 0); in snd_cmipci_free()
2896 snd_cmipci_free_gameport(cm); in snd_cmipci_free()
2899 static int snd_cmipci_create_fm(struct cmipci *cm, long fm_port) in snd_cmipci_create_fm() argument
2909 if (cm->chip_version >= 39) { in snd_cmipci_create_fm()
2911 iosynth = cm->iobase + CM_REG_FM_PCI; in snd_cmipci_create_fm()
2912 err = snd_opl3_create(cm->card, iosynth, iosynth + 2, in snd_cmipci_create_fm()
2915 err = -EIO; in snd_cmipci_create_fm()
2919 val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK; in snd_cmipci_create_fm()
2929 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val); in snd_cmipci_create_fm()
2931 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN); in snd_cmipci_create_fm()
2933 if (snd_opl3_create(cm->card, iosynth, iosynth + 2, in snd_cmipci_create_fm()
2935 dev_err(cm->card->dev, in snd_cmipci_create_fm()
2943 dev_err(cm->card->dev, "cannot create OPL3 hwdep\n"); in snd_cmipci_create_fm()
2949 snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_FMSEL_MASK); in snd_cmipci_create_fm()
2950 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN); in snd_cmipci_create_fm()
2957 struct cmipci *cm = card->private_data; in snd_cmipci_create() local
2973 spin_lock_init(&cm->reg_lock); in snd_cmipci_create()
2974 mutex_init(&cm->open_mutex); in snd_cmipci_create()
2975 cm->device = pci->device; in snd_cmipci_create()
2976 cm->card = card; in snd_cmipci_create()
2977 cm->pci = pci; in snd_cmipci_create()
2978 cm->irq = -1; in snd_cmipci_create()
2979 cm->channel[0].ch = 0; in snd_cmipci_create()
2980 cm->channel[1].ch = 1; in snd_cmipci_create()
2981 cm->channel[0].is_dac = cm->channel[1].is_dac = 1; /* dual DAC mode */ in snd_cmipci_create()
2983 err = pci_request_regions(pci, card->driver); in snd_cmipci_create()
2986 cm->iobase = pci_resource_start(pci, 0); in snd_cmipci_create()
2988 if (devm_request_irq(&pci->dev, pci->irq, snd_cmipci_interrupt, in snd_cmipci_create()
2989 IRQF_SHARED, KBUILD_MODNAME, cm)) { in snd_cmipci_create()
2990 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); in snd_cmipci_create()
2991 return -EBUSY; in snd_cmipci_create()
2993 cm->irq = pci->irq; in snd_cmipci_create()
2994 card->sync_irq = cm->irq; in snd_cmipci_create()
2995 card->private_free = snd_cmipci_free; in snd_cmipci_create()
2997 pci_set_master(cm->pci); in snd_cmipci_create()
3003 cm->chip_version = 0; in snd_cmipci_create()
3004 cm->max_channels = 2; in snd_cmipci_create()
3005 cm->do_soft_ac3 = soft_ac3[dev]; in snd_cmipci_create()
3007 if (pci->device != PCI_DEVICE_ID_CMEDIA_CM8338A && in snd_cmipci_create()
3008 pci->device != PCI_DEVICE_ID_CMEDIA_CM8338B) in snd_cmipci_create()
3009 query_chip(cm); in snd_cmipci_create()
3010 /* added -MCx suffix for chip supporting multi-channels */ in snd_cmipci_create()
3011 if (cm->can_multi_ch) in snd_cmipci_create()
3012 sprintf(cm->card->driver + strlen(cm->card->driver), in snd_cmipci_create()
3013 "-MC%d", cm->max_channels); in snd_cmipci_create()
3014 else if (cm->can_ac3_sw) in snd_cmipci_create()
3015 strcpy(cm->card->driver + strlen(cm->card->driver), "-SWIEC"); in snd_cmipci_create()
3017 cm->dig_status = SNDRV_PCM_DEFAULT_CON_SPDIF; in snd_cmipci_create()
3018 cm->dig_pcm_status = SNDRV_PCM_DEFAULT_CON_SPDIF; in snd_cmipci_create()
3021 cm->ctrl = CM_CHADC0; /* default FUNCNTRL0 */ in snd_cmipci_create()
3023 cm->ctrl = CM_CHADC1; /* default FUNCNTRL0 */ in snd_cmipci_create()
3027 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_RESET); in snd_cmipci_create()
3028 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_RESET); in snd_cmipci_create()
3029 snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0); /* disable ints */ in snd_cmipci_create()
3030 snd_cmipci_ch_reset(cm, CM_CH_PLAY); in snd_cmipci_create()
3031 snd_cmipci_ch_reset(cm, CM_CH_CAPT); in snd_cmipci_create()
3032 snd_cmipci_write(cm, CM_REG_FUNCTRL0, 0); /* disable channels */ in snd_cmipci_create()
3033 snd_cmipci_write(cm, CM_REG_FUNCTRL1, 0); in snd_cmipci_create()
3035 snd_cmipci_write(cm, CM_REG_CHFORMAT, 0); in snd_cmipci_create()
3036 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_ENDBDAC|CM_N4SPK3D); in snd_cmipci_create()
3038 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_XCHGDAC); in snd_cmipci_create()
3040 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_XCHGDAC); in snd_cmipci_create()
3042 if (cm->chip_version) { in snd_cmipci_create()
3043 snd_cmipci_write_b(cm, CM_REG_EXT_MISC, 0x20); /* magic */ in snd_cmipci_create()
3044 snd_cmipci_write_b(cm, CM_REG_EXT_MISC + 1, 0x09); /* more magic */ in snd_cmipci_create()
3047 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_BREQ); in snd_cmipci_create()
3050 switch (pci->device) { in snd_cmipci_create()
3054 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_TXVX); in snd_cmipci_create()
3060 if (cm->chip_version < 68) { in snd_cmipci_create()
3061 val = pci->device < 0x110 ? 8338 : 8738; in snd_cmipci_create()
3063 switch (snd_cmipci_read_b(cm, CM_REG_INT_HLDCLR + 3) & 0x03) { in snd_cmipci_create()
3071 switch ((pci->subsystem_vendor << 16) | in snd_cmipci_create()
3072 pci->subsystem_device) { in snd_cmipci_create()
3087 sprintf(card->shortname, "C-Media CMI%d", val); in snd_cmipci_create()
3088 if (cm->chip_version < 68) in snd_cmipci_create()
3090 " (model %d)", cm->chip_version); in snd_cmipci_create()
3093 scnprintf(card->longname, sizeof(card->longname), in snd_cmipci_create()
3095 card->shortname, modelstr, cm->iobase, cm->irq); in snd_cmipci_create()
3097 if (cm->chip_version >= 39) { in snd_cmipci_create()
3098 val = snd_cmipci_read_b(cm, CM_REG_MPU_PCI + 1); in snd_cmipci_create()
3101 iomidi = cm->iobase + CM_REG_MPU_PCI; in snd_cmipci_create()
3117 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val); in snd_cmipci_create()
3119 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN); in snd_cmipci_create()
3121 dev_err(cm->card->dev, in snd_cmipci_create()
3122 "cannot enable MPU-401 port at %#lx\n", in snd_cmipci_create()
3124 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, in snd_cmipci_create()
3131 if (cm->chip_version < 68) { in snd_cmipci_create()
3132 err = snd_cmipci_create_fm(cm, fm_port[dev]); in snd_cmipci_create()
3138 snd_cmipci_mixer_write(cm, 0, 0); in snd_cmipci_create()
3140 snd_cmipci_proc_init(cm); in snd_cmipci_create()
3144 err = snd_cmipci_pcm_new(cm, pcm_index); in snd_cmipci_create()
3148 err = snd_cmipci_pcm2_new(cm, pcm_index); in snd_cmipci_create()
3152 if (cm->can_ac3_hw || cm->can_ac3_sw) { in snd_cmipci_create()
3154 err = snd_cmipci_pcm_spdif_new(cm, pcm_index); in snd_cmipci_create()
3160 err = snd_cmipci_mixer_new(cm, pcm_spdif_index); in snd_cmipci_create()
3170 -1, &cm->rmidi); in snd_cmipci_create()
3172 dev_err(cm->card->dev, in snd_cmipci_create()
3178 snd_cmipci_set_pll(cm, rates[val], val); in snd_cmipci_create()
3181 * (Re-)Enable external switch spdo_48k in snd_cmipci_create()
3183 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPDIF48K|CM_SPDF_AC97); in snd_cmipci_create()
3186 if (snd_cmipci_create_gameport(cm, dev) < 0) in snd_cmipci_create()
3187 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN); in snd_cmipci_create()
3205 return -ENODEV; in snd_cmipci_probe()
3208 return -ENOENT; in snd_cmipci_probe()
3211 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, in snd_cmipci_probe()
3216 switch (pci->device) { in snd_cmipci_probe()
3219 strcpy(card->driver, "CMI8738"); in snd_cmipci_probe()
3223 strcpy(card->driver, "CMI8338"); in snd_cmipci_probe()
3226 strcpy(card->driver, "CMIPCI"); in snd_cmipci_probe()
3272 struct cmipci *cm = card->private_data; in snd_cmipci_suspend() local
3279 cm->saved_regs[i] = snd_cmipci_read(cm, saved_regs[i]); in snd_cmipci_suspend()
3281 cm->saved_mixers[i] = snd_cmipci_mixer_read(cm, saved_mixers[i]); in snd_cmipci_suspend()
3284 snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0); in snd_cmipci_suspend()
3291 struct cmipci *cm = card->private_data; in snd_cmipci_resume() local
3295 snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0); in snd_cmipci_resume()
3296 snd_cmipci_ch_reset(cm, CM_CH_PLAY); in snd_cmipci_resume()
3297 snd_cmipci_ch_reset(cm, CM_CH_CAPT); in snd_cmipci_resume()
3298 snd_cmipci_mixer_write(cm, 0, 0); in snd_cmipci_resume()
3302 snd_cmipci_write(cm, saved_regs[i], cm->saved_regs[i]); in snd_cmipci_resume()
3304 snd_cmipci_mixer_write(cm, saved_mixers[i], cm->saved_mixers[i]); in snd_cmipci_resume()
3313 .name = KBUILD_MODNAME,