Lines Matching +full:adc +full:- +full:joystick

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).");
62 MODULE_PARM_DESC(joystick_port, "Joystick port address.");
82 #define CM_ASFC_MASK 0x00001C00 /* channel 0 (ADC?) sampling frequency */
86 #define CM_SPDFLOOP 0x00000080 /* ext. SPDIIF/IN -> OUT loopback */
92 #define CM_JYSTK_EN 0x00000002 /* legacy joystick */
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 */
359 #define CM_ADC48K44K 0x10000000 /* ADC parameters group, 0: 44k, 1: 48k */
362 #define CM_ADC2SPDIF 0x00080000 /* ADC output to SPDIF/OUT */
363 #define CM_SHAREADC 0x00040000 /* DAC in ADC as Center/LFE */
364 #define CM_REALTCMP 0x00020000 /* monitor the CMPL/CMPR of ADC */
416 u8 running; /* dac/adc running? */
450 struct snd_pcm *pcm; /* DAC/ADC PCM */
478 struct cmipci_pcm channel[2]; /* ch0 - DAC, ch1 - ADC or 2nd DAC */
499 outl(data, cm->iobase + cmd); in snd_cmipci_write()
504 return inl(cm->iobase + cmd); in snd_cmipci_read()
510 outw(data, cm->iobase + cmd); in snd_cmipci_write_w()
515 return inw(cm->iobase + cmd); in snd_cmipci_read_w()
521 outb(data, cm->iobase + cmd); in snd_cmipci_write_b()
526 return inb(cm->iobase + cmd); in snd_cmipci_read_b()
533 val = oval = inl(cm->iobase + cmd); in snd_cmipci_set_bit()
537 outl(val, cm->iobase + cmd); in snd_cmipci_set_bit()
544 val = oval = inl(cm->iobase + cmd); in snd_cmipci_clear_bit()
548 outl(val, cm->iobase + cmd); in snd_cmipci_clear_bit()
556 val = oval = inb(cm->iobase + cmd); in snd_cmipci_set_bit_b()
560 outb(val, cm->iobase + cmd); in snd_cmipci_set_bit_b()
567 val = oval = inb(cm->iobase + cmd); in snd_cmipci_clear_bit_b()
571 outb(val, cm->iobase + cmd); in snd_cmipci_clear_bit_b()
601 * does it this way .. maybe not. Never get any information from C-Media about
611 *n = -1; in snd_cmipci_pll_rmn()
621 delta = rate - xr; in snd_cmipci_pll_rmn()
623 delta = xr - rate; in snd_cmipci_pll_rmn()
631 *m = xm - 2; in snd_cmipci_pll_rmn()
632 *n = xn - 2; in snd_cmipci_pll_rmn()
637 return (*n > -1); in snd_cmipci_pll_rmn()
642 * are mapped onto the 8 ADC/DAC sampling frequency which can be chosen
669 mutex_lock(&cm->open_mutex); in snd_cmipci_playback2_hw_params()
670 if (cm->opened[CM_CH_PLAY]) { in snd_cmipci_playback2_hw_params()
671 mutex_unlock(&cm->open_mutex); in snd_cmipci_playback2_hw_params()
672 return -EBUSY; in snd_cmipci_playback2_hw_params()
675 cm->opened[CM_CH_PLAY] = CM_OPEN_PLAYBACK_MULTI; in snd_cmipci_playback2_hw_params()
676 mutex_unlock(&cm->open_mutex); in snd_cmipci_playback2_hw_params()
683 int reset = CM_RST_CH0 << (cm->channel[ch].ch); in snd_cmipci_ch_reset()
684 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset); in snd_cmipci_ch_reset()
685 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset); in snd_cmipci_ch_reset()
713 if (!cm->can_multi_ch || !rec->ch) in set_dac_channels()
714 return -EINVAL; in set_dac_channels()
715 if (rec->fmt != 0x03) /* stereo 16bit only */ in set_dac_channels()
716 return -EINVAL; in set_dac_channels()
719 if (cm->can_multi_ch) { in set_dac_channels()
720 spin_lock_irq(&cm->reg_lock); in set_dac_channels()
743 spin_unlock_irq(&cm->reg_lock); in set_dac_channels()
751 * channel to be used must have been set in rec->ch.
758 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_pcm_prepare()
760 rec->fmt = 0; in snd_cmipci_pcm_prepare()
761 rec->shift = 0; in snd_cmipci_pcm_prepare()
762 if (snd_pcm_format_width(runtime->format) >= 16) { in snd_cmipci_pcm_prepare()
763 rec->fmt |= 0x02; in snd_cmipci_pcm_prepare()
764 if (snd_pcm_format_width(runtime->format) > 16) in snd_cmipci_pcm_prepare()
765 rec->shift++; /* 24/32bit */ in snd_cmipci_pcm_prepare()
767 if (runtime->channels > 1) in snd_cmipci_pcm_prepare()
768 rec->fmt |= 0x01; in snd_cmipci_pcm_prepare()
769 if (rec->is_dac && set_dac_channels(cm, rec, runtime->channels) < 0) { in snd_cmipci_pcm_prepare()
770 dev_dbg(cm->card->dev, "cannot set dac channels\n"); in snd_cmipci_pcm_prepare()
771 return -EINVAL; in snd_cmipci_pcm_prepare()
774 rec->offset = runtime->dma_addr; in snd_cmipci_pcm_prepare()
776 rec->dma_size = runtime->buffer_size << rec->shift; in snd_cmipci_pcm_prepare()
777 period_size = runtime->period_size << rec->shift; in snd_cmipci_pcm_prepare()
778 if (runtime->channels > 2) { in snd_cmipci_pcm_prepare()
779 /* multi-channels */ in snd_cmipci_pcm_prepare()
780 rec->dma_size = (rec->dma_size * runtime->channels) / 2; in snd_cmipci_pcm_prepare()
781 period_size = (period_size * runtime->channels) / 2; in snd_cmipci_pcm_prepare()
784 spin_lock_irq(&cm->reg_lock); in snd_cmipci_pcm_prepare()
787 reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1; in snd_cmipci_pcm_prepare()
788 snd_cmipci_write(cm, reg, rec->offset); in snd_cmipci_pcm_prepare()
790 reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2; in snd_cmipci_pcm_prepare()
791 snd_cmipci_write_w(cm, reg, rec->dma_size - 1); in snd_cmipci_pcm_prepare()
792 snd_cmipci_write_w(cm, reg + 2, period_size - 1); in snd_cmipci_pcm_prepare()
794 /* set adc/dac flag */ in snd_cmipci_pcm_prepare()
795 val = rec->ch ? CM_CHADC1 : CM_CHADC0; in snd_cmipci_pcm_prepare()
796 if (rec->is_dac) in snd_cmipci_pcm_prepare()
797 cm->ctrl &= ~val; in snd_cmipci_pcm_prepare()
799 cm->ctrl |= val; in snd_cmipci_pcm_prepare()
800 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_pcm_prepare()
801 /* dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl); */ in snd_cmipci_pcm_prepare()
806 if (runtime->rate > 48000) in snd_cmipci_pcm_prepare()
807 switch (runtime->rate) { in snd_cmipci_pcm_prepare()
814 freq = snd_cmipci_rate_freq(runtime->rate); in snd_cmipci_pcm_prepare()
816 if (rec->ch) { in snd_cmipci_pcm_prepare()
824 dev_dbg(cm->card->dev, "functrl1 = %08x\n", val); in snd_cmipci_pcm_prepare()
828 if (rec->ch) { in snd_cmipci_pcm_prepare()
830 val |= rec->fmt << CM_CH1FMT_SHIFT; in snd_cmipci_pcm_prepare()
833 val |= rec->fmt << CM_CH0FMT_SHIFT; in snd_cmipci_pcm_prepare()
835 if (cm->can_96k) { in snd_cmipci_pcm_prepare()
836 val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2)); in snd_cmipci_pcm_prepare()
837 val |= freq_ext << (rec->ch * 2); in snd_cmipci_pcm_prepare()
840 dev_dbg(cm->card->dev, "chformat = %08x\n", val); in snd_cmipci_pcm_prepare()
842 if (!rec->is_dac && cm->chip_version) { in snd_cmipci_pcm_prepare()
843 if (runtime->rate > 44100) in snd_cmipci_pcm_prepare()
849 rec->running = 0; in snd_cmipci_pcm_prepare()
850 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_pcm_prepare()
864 inthld = CM_CH0_INT_EN << rec->ch; in snd_cmipci_pcm_trigger()
865 chen = CM_CHEN0 << rec->ch; in snd_cmipci_pcm_trigger()
866 reset = CM_RST_CH0 << rec->ch; in snd_cmipci_pcm_trigger()
867 pause = CM_PAUSE0 << rec->ch; in snd_cmipci_pcm_trigger()
869 spin_lock(&cm->reg_lock); in snd_cmipci_pcm_trigger()
872 rec->running = 1; in snd_cmipci_pcm_trigger()
875 cm->ctrl |= chen; in snd_cmipci_pcm_trigger()
877 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_pcm_trigger()
878 dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl); in snd_cmipci_pcm_trigger()
881 rec->running = 0; in snd_cmipci_pcm_trigger()
885 cm->ctrl &= ~chen; in snd_cmipci_pcm_trigger()
886 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset); in snd_cmipci_pcm_trigger()
887 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset); in snd_cmipci_pcm_trigger()
888 rec->needs_silencing = rec->is_dac; in snd_cmipci_pcm_trigger()
892 cm->ctrl |= pause; in snd_cmipci_pcm_trigger()
893 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_pcm_trigger()
897 cm->ctrl &= ~pause; in snd_cmipci_pcm_trigger()
898 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_pcm_trigger()
901 result = -EINVAL; in snd_cmipci_pcm_trigger()
904 spin_unlock(&cm->reg_lock); in snd_cmipci_pcm_trigger()
917 if (!rec->running) in snd_cmipci_pcm_pointer()
920 reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2; in snd_cmipci_pcm_pointer()
923 if (rem < rec->dma_size) in snd_cmipci_pcm_pointer()
926 dev_err(cm->card->dev, "invalid PCM pointer: %#x\n", rem); in snd_cmipci_pcm_pointer()
929 ptr = (rec->dma_size - (rem + 1)) >> rec->shift; in snd_cmipci_pcm_pointer()
931 reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1; in snd_cmipci_pcm_pointer()
932 ptr = snd_cmipci_read(cm, reg) - rec->offset; in snd_cmipci_pcm_pointer()
933 ptr = bytes_to_frames(substream->runtime, ptr); in snd_cmipci_pcm_pointer()
935 if (substream->runtime->channels > 2) in snd_cmipci_pcm_pointer()
936 ptr = (ptr * 2) / substream->runtime->channels; in snd_cmipci_pcm_pointer()
948 return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_PLAY], cmd); in snd_cmipci_playback_trigger()
954 return snd_cmipci_pcm_pointer(cm, &cm->channel[CM_CH_PLAY], substream); in snd_cmipci_playback_pointer()
967 return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_CAPT], cmd); in snd_cmipci_capture_trigger()
973 return snd_cmipci_pcm_pointer(cm, &cm->channel[CM_CH_CAPT], substream); in snd_cmipci_capture_pointer()
984 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_cmipci_spdif_default_info()
985 uinfo->count = 1; in snd_cmipci_spdif_default_info()
995 spin_lock_irq(&chip->reg_lock); in snd_cmipci_spdif_default_get()
997 ucontrol->value.iec958.status[i] = (chip->dig_status >> (i * 8)) & 0xff; in snd_cmipci_spdif_default_get()
998 spin_unlock_irq(&chip->reg_lock); in snd_cmipci_spdif_default_get()
1010 spin_lock_irq(&chip->reg_lock); in snd_cmipci_spdif_default_put()
1012 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8); in snd_cmipci_spdif_default_put()
1013 change = val != chip->dig_status; in snd_cmipci_spdif_default_put()
1014 chip->dig_status = val; in snd_cmipci_spdif_default_put()
1015 spin_unlock_irq(&chip->reg_lock); in snd_cmipci_spdif_default_put()
1031 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_cmipci_spdif_mask_info()
1032 uinfo->count = 1; in snd_cmipci_spdif_mask_info()
1039 ucontrol->value.iec958.status[0] = 0xff; in snd_cmipci_spdif_mask_get()
1040 ucontrol->value.iec958.status[1] = 0xff; in snd_cmipci_spdif_mask_get()
1041 ucontrol->value.iec958.status[2] = 0xff; in snd_cmipci_spdif_mask_get()
1042 ucontrol->value.iec958.status[3] = 0xff; in snd_cmipci_spdif_mask_get()
1058 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_cmipci_spdif_stream_info()
1059 uinfo->count = 1; in snd_cmipci_spdif_stream_info()
1069 spin_lock_irq(&chip->reg_lock); in snd_cmipci_spdif_stream_get()
1071 ucontrol->value.iec958.status[i] = (chip->dig_pcm_status >> (i * 8)) & 0xff; in snd_cmipci_spdif_stream_get()
1072 spin_unlock_irq(&chip->reg_lock); in snd_cmipci_spdif_stream_get()
1084 spin_lock_irq(&chip->reg_lock); in snd_cmipci_spdif_stream_put()
1086 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8); in snd_cmipci_spdif_stream_put()
1087 change = val != chip->dig_pcm_status; in snd_cmipci_spdif_stream_put()
1088 chip->dig_pcm_status = val; in snd_cmipci_spdif_stream_put()
1089 spin_unlock_irq(&chip->reg_lock); in snd_cmipci_spdif_stream_put()
1109 if (! cm->mixer_insensitive) { in save_mixer_state()
1115 return -ENOMEM; in save_mixer_state()
1117 struct snd_kcontrol *ctl = cm->mixer_res_ctl[i]; in save_mixer_state()
1121 ctl->get(ctl, val); in save_mixer_state()
1122 cm->mixer_res_status[i] = val->value.integer.value[0]; in save_mixer_state()
1123 val->value.integer.value[0] = cm_saved_mixer[i].toggle_on; in save_mixer_state()
1125 if (cm->mixer_res_status[i] != val->value.integer.value[0]) { in save_mixer_state()
1126 ctl->put(ctl, val); /* toggle */ in save_mixer_state()
1129 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; in save_mixer_state()
1130 snd_ctl_notify(cm->card, event, &ctl->id); in save_mixer_state()
1134 cm->mixer_insensitive = 1; in save_mixer_state()
1143 if (cm->mixer_insensitive) { in restore_mixer_state()
1150 cm->mixer_insensitive = 0; /* at first clear this; in restore_mixer_state()
1153 struct snd_kcontrol *ctl = cm->mixer_res_ctl[i]; in restore_mixer_state()
1158 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; in restore_mixer_state()
1159 ctl->get(ctl, val); in restore_mixer_state()
1161 if (val->value.integer.value[0] != cm->mixer_res_status[i]) { in restore_mixer_state()
1162 val->value.integer.value[0] = cm->mixer_res_status[i]; in restore_mixer_state()
1163 ctl->put(ctl, val); in restore_mixer_state()
1166 snd_ctl_notify(cm->card, event, &ctl->id); in restore_mixer_state()
1182 if (cm->can_ac3_hw) { in setup_ac3()
1191 if (cm->chip_version == 33) { in setup_ac3()
1204 if (cm->can_ac3_hw) { in setup_ac3()
1206 if (snd_pcm_format_width(subs->runtime->format) > 16) { in setup_ac3()
1225 rate = subs->runtime->rate; in setup_spdif_playback()
1233 spin_lock_irq(&cm->reg_lock); in setup_spdif_playback()
1234 cm->spdif_playback_avail = up; in setup_spdif_playback()
1239 if (cm->spdif_playback_enabled) in setup_spdif_playback()
1259 spin_unlock_irq(&cm->reg_lock); in setup_spdif_playback()
1268 /* playback - enable spdif only on the certain condition */
1272 int rate = substream->runtime->rate; in snd_cmipci_playback_prepare()
1276 substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE && in snd_cmipci_playback_prepare()
1277 substream->runtime->channels == 2); in snd_cmipci_playback_prepare()
1278 if (do_spdif && cm->can_ac3_hw) in snd_cmipci_playback_prepare()
1279 do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO; in snd_cmipci_playback_prepare()
1283 return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_PLAY], substream); in snd_cmipci_playback_prepare()
1286 /* playback (via device #2) - enable spdif always */
1292 if (cm->can_ac3_hw) in snd_cmipci_playback_spdif_prepare()
1293 do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO; in snd_cmipci_playback_spdif_prepare()
1299 return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_PLAY], substream); in snd_cmipci_playback_spdif_prepare()
1312 struct snd_pcm_runtime *runtime = rec->substream->runtime; in snd_cmipci_silence_hack()
1315 if (rec->needs_silencing && runtime && runtime->dma_area) { in snd_cmipci_silence_hack()
1317 memset(runtime->dma_area, 0, PAGE_SIZE); in snd_cmipci_silence_hack()
1318 reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2; in snd_cmipci_silence_hack()
1319 val = ((PAGE_SIZE / 4) - 1) | (((PAGE_SIZE / 4) / 2 - 1) << 16); in snd_cmipci_silence_hack()
1323 if (runtime->channels > 2) in snd_cmipci_silence_hack()
1325 spin_lock_irq(&cm->reg_lock); in snd_cmipci_silence_hack()
1327 val &= ~(CM_ASFC_MASK << (rec->ch * 3)); in snd_cmipci_silence_hack()
1328 val |= (4 << CM_ASFC_SHIFT) << (rec->ch * 3); in snd_cmipci_silence_hack()
1331 val &= ~(CM_CH0FMT_MASK << (rec->ch * 2)); in snd_cmipci_silence_hack()
1332 val |= (3 << CM_CH0FMT_SHIFT) << (rec->ch * 2); in snd_cmipci_silence_hack()
1333 if (cm->can_96k) in snd_cmipci_silence_hack()
1334 val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2)); in snd_cmipci_silence_hack()
1338 cm->ctrl |= CM_CHEN0 << rec->ch; in snd_cmipci_silence_hack()
1339 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); in snd_cmipci_silence_hack()
1340 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_silence_hack()
1345 spin_lock_irq(&cm->reg_lock); in snd_cmipci_silence_hack()
1346 cm->ctrl &= ~(CM_CHEN0 << rec->ch); in snd_cmipci_silence_hack()
1347 val = CM_RST_CH0 << rec->ch; in snd_cmipci_silence_hack()
1348 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | val); in snd_cmipci_silence_hack()
1349 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~val); in snd_cmipci_silence_hack()
1350 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_silence_hack()
1352 rec->needs_silencing = 0; in snd_cmipci_silence_hack()
1361 snd_cmipci_silence_hack(cm, &cm->channel[0]); in snd_cmipci_playback_hw_free()
1368 snd_cmipci_silence_hack(cm, &cm->channel[1]); in snd_cmipci_playback2_hw_free()
1376 return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_CAPT], substream); in snd_cmipci_capture_prepare()
1384 spin_lock_irq(&cm->reg_lock); in snd_cmipci_capture_spdif_prepare()
1386 if (cm->can_96k) { in snd_cmipci_capture_spdif_prepare()
1387 if (substream->runtime->rate > 48000) in snd_cmipci_capture_spdif_prepare()
1392 if (snd_pcm_format_width(substream->runtime->format) > 16) in snd_cmipci_capture_spdif_prepare()
1397 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_capture_spdif_prepare()
1399 return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_CAPT], substream); in snd_cmipci_capture_spdif_prepare()
1406 spin_lock_irq(&cm->reg_lock); in snd_cmipci_capture_spdif_hw_free()
1409 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_capture_spdif_hw_free()
1429 spin_lock(&cm->reg_lock); in snd_cmipci_interrupt()
1436 spin_unlock(&cm->reg_lock); in snd_cmipci_interrupt()
1438 if (cm->rmidi && (status & CM_UARTINT)) in snd_cmipci_interrupt()
1439 snd_mpu401_uart_interrupt(irq, cm->rmidi->private_data); in snd_cmipci_interrupt()
1441 if (cm->pcm) { in snd_cmipci_interrupt()
1442 if ((status & CM_CHINT0) && cm->channel[0].running) in snd_cmipci_interrupt()
1443 snd_pcm_period_elapsed(cm->channel[0].substream); in snd_cmipci_interrupt()
1444 if ((status & CM_CHINT1) && cm->channel[1].running) in snd_cmipci_interrupt()
1445 snd_pcm_period_elapsed(cm->channel[1].substream); in snd_cmipci_interrupt()
1494 /* playback on channel B - stereo 16bit only? */
1595 mutex_lock(&cm->open_mutex); in open_device_check()
1596 if (cm->opened[ch]) { in open_device_check()
1597 mutex_unlock(&cm->open_mutex); in open_device_check()
1598 return -EBUSY; in open_device_check()
1600 cm->opened[ch] = mode; in open_device_check()
1601 cm->channel[ch].substream = subs; in open_device_check()
1604 cm->channel[ch].is_dac = 0; in open_device_check()
1605 spin_lock_irq(&cm->reg_lock); in open_device_check()
1607 spin_unlock_irq(&cm->reg_lock); in open_device_check()
1609 mutex_unlock(&cm->open_mutex); in open_device_check()
1617 mutex_lock(&cm->open_mutex); in close_device_check()
1618 if (cm->opened[ch] == mode) { in close_device_check()
1619 if (cm->channel[ch].substream) { in close_device_check()
1621 cm->channel[ch].running = 0; in close_device_check()
1622 cm->channel[ch].substream = NULL; in close_device_check()
1624 cm->opened[ch] = 0; in close_device_check()
1625 if (! cm->channel[ch].is_dac) { in close_device_check()
1627 cm->channel[ch].is_dac = 1; in close_device_check()
1628 spin_lock_irq(&cm->reg_lock); in close_device_check()
1630 spin_unlock_irq(&cm->reg_lock); in close_device_check()
1633 mutex_unlock(&cm->open_mutex); in close_device_check()
1642 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_playback_open()
1648 runtime->hw = snd_cmipci_playback; in snd_cmipci_playback_open()
1649 if (cm->chip_version == 68) { in snd_cmipci_playback_open()
1650 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_playback_open()
1652 runtime->hw.rate_max = 96000; in snd_cmipci_playback_open()
1653 } else if (cm->chip_version == 55) { in snd_cmipci_playback_open()
1658 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; in snd_cmipci_playback_open()
1659 runtime->hw.rate_max = 128000; in snd_cmipci_playback_open()
1662 cm->dig_pcm_status = cm->dig_status; in snd_cmipci_playback_open()
1669 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_capture_open()
1675 runtime->hw = snd_cmipci_capture; in snd_cmipci_capture_open()
1676 if (cm->chip_version == 68) { // 8768 only supports 44k/48k recording in snd_cmipci_capture_open()
1677 runtime->hw.rate_min = 41000; in snd_cmipci_capture_open()
1678 runtime->hw.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; in snd_cmipci_capture_open()
1679 } else if (cm->chip_version == 55) { in snd_cmipci_capture_open()
1684 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; in snd_cmipci_capture_open()
1685 runtime->hw.rate_max = 128000; in snd_cmipci_capture_open()
1694 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_playback2_open()
1701 runtime->hw = snd_cmipci_playback2; in snd_cmipci_playback2_open()
1702 mutex_lock(&cm->open_mutex); in snd_cmipci_playback2_open()
1703 if (! cm->opened[CM_CH_PLAY]) { in snd_cmipci_playback2_open()
1704 if (cm->can_multi_ch) { in snd_cmipci_playback2_open()
1705 runtime->hw.channels_max = cm->max_channels; in snd_cmipci_playback2_open()
1706 if (cm->max_channels == 4) in snd_cmipci_playback2_open()
1708 else if (cm->max_channels == 6) in snd_cmipci_playback2_open()
1710 else if (cm->max_channels == 8) in snd_cmipci_playback2_open()
1714 mutex_unlock(&cm->open_mutex); in snd_cmipci_playback2_open()
1715 if (cm->chip_version == 68) { in snd_cmipci_playback2_open()
1716 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_playback2_open()
1718 runtime->hw.rate_max = 96000; in snd_cmipci_playback2_open()
1719 } else if (cm->chip_version == 55) { in snd_cmipci_playback2_open()
1724 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; in snd_cmipci_playback2_open()
1725 runtime->hw.rate_max = 128000; in snd_cmipci_playback2_open()
1734 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_playback_spdif_open()
1741 if (cm->can_ac3_hw) { in snd_cmipci_playback_spdif_open()
1742 runtime->hw = snd_cmipci_playback_spdif; in snd_cmipci_playback_spdif_open()
1743 if (cm->chip_version >= 37) { in snd_cmipci_playback_spdif_open()
1744 runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE; in snd_cmipci_playback_spdif_open()
1747 if (cm->can_96k) { in snd_cmipci_playback_spdif_open()
1748 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_playback_spdif_open()
1750 runtime->hw.rate_max = 96000; in snd_cmipci_playback_spdif_open()
1753 runtime->hw = snd_cmipci_playback_iec958_subframe; in snd_cmipci_playback_spdif_open()
1756 cm->dig_pcm_status = cm->dig_status; in snd_cmipci_playback_spdif_open()
1763 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cmipci_capture_spdif_open()
1770 runtime->hw = snd_cmipci_capture_spdif; in snd_cmipci_capture_spdif_open()
1771 if (cm->can_96k && !(cm->chip_version == 68)) { in snd_cmipci_capture_spdif_open()
1772 runtime->hw.rates |= SNDRV_PCM_RATE_88200 | in snd_cmipci_capture_spdif_open()
1774 runtime->hw.rate_max = 96000; in snd_cmipci_capture_spdif_open()
1878 err = snd_pcm_new(cm->card, cm->card->driver, device, 1, 1, &pcm); in snd_cmipci_pcm_new()
1885 pcm->private_data = cm; in snd_cmipci_pcm_new()
1886 pcm->info_flags = 0; in snd_cmipci_pcm_new()
1887 strcpy(pcm->name, "C-Media PCI DAC/ADC"); in snd_cmipci_pcm_new()
1888 cm->pcm = pcm; in snd_cmipci_pcm_new()
1891 &cm->pci->dev, 64*1024, 128*1024); in snd_cmipci_pcm_new()
1901 err = snd_pcm_new(cm->card, cm->card->driver, device, 1, 0, &pcm); in snd_cmipci_pcm2_new()
1907 pcm->private_data = cm; in snd_cmipci_pcm2_new()
1908 pcm->info_flags = 0; in snd_cmipci_pcm2_new()
1909 strcpy(pcm->name, "C-Media PCI 2nd DAC"); in snd_cmipci_pcm2_new()
1910 cm->pcm2 = pcm; in snd_cmipci_pcm2_new()
1913 &cm->pci->dev, 64*1024, 128*1024); in snd_cmipci_pcm2_new()
1923 err = snd_pcm_new(cm->card, cm->card->driver, device, 1, 1, &pcm); in snd_cmipci_pcm_spdif_new()
1930 pcm->private_data = cm; in snd_cmipci_pcm_spdif_new()
1931 pcm->info_flags = 0; in snd_cmipci_pcm_spdif_new()
1932 strcpy(pcm->name, "C-Media PCI IEC958"); in snd_cmipci_pcm_spdif_new()
1933 cm->pcm_spdif = pcm; in snd_cmipci_pcm_spdif_new()
1936 &cm->pci->dev, 64*1024, 128*1024); in snd_cmipci_pcm_spdif_new()
1939 snd_pcm_alt_chmaps, cm->max_channels, 0, in snd_cmipci_pcm_spdif_new()
1949 * - CM8338/8738 has a compatible mixer interface with SB16, but
1951 * - Access to native registers:
1952 * - A 3D switch
1953 * - Output mute switches
1958 outb(idx, s->iobase + CM_REG_SB16_ADDR); in snd_cmipci_mixer_write()
1959 outb(data, s->iobase + CM_REG_SB16_DATA); in snd_cmipci_mixer_write()
1966 outb(idx, s->iobase + CM_REG_SB16_ADDR); in snd_cmipci_mixer_read()
1967 v = inb(s->iobase + CM_REG_SB16_DATA); in snd_cmipci_mixer_read()
1999 r->left_reg = val & 0xff; in cmipci_sb_reg_decode()
2000 r->right_reg = (val >> 8) & 0xff; in cmipci_sb_reg_decode()
2001 r->left_shift = (val >> 16) & 0x07; in cmipci_sb_reg_decode()
2002 r->right_shift = (val >> 19) & 0x07; in cmipci_sb_reg_decode()
2003 r->invert = (val >> 22) & 1; in cmipci_sb_reg_decode()
2004 r->stereo = (val >> 23) & 1; in cmipci_sb_reg_decode()
2005 r->mask = (val >> 24) & 0xff; in cmipci_sb_reg_decode()
2013 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_info_volume()
2014 uinfo->type = reg.mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_cmipci_info_volume()
2015 uinfo->count = reg.stereo + 1; in snd_cmipci_info_volume()
2016 uinfo->value.integer.min = 0; in snd_cmipci_info_volume()
2017 uinfo->value.integer.max = reg.mask; in snd_cmipci_info_volume()
2028 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_get_volume()
2029 spin_lock_irq(&cm->reg_lock); in snd_cmipci_get_volume()
2032 val = reg.mask - val; in snd_cmipci_get_volume()
2033 ucontrol->value.integer.value[0] = val; in snd_cmipci_get_volume()
2037 val = reg.mask - val; in snd_cmipci_get_volume()
2038 ucontrol->value.integer.value[1] = val; in snd_cmipci_get_volume()
2040 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_get_volume()
2052 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_put_volume()
2053 left = ucontrol->value.integer.value[0] & reg.mask; in snd_cmipci_put_volume()
2055 left = reg.mask - left; in snd_cmipci_put_volume()
2058 right = ucontrol->value.integer.value[1] & reg.mask; in snd_cmipci_put_volume()
2060 right = reg.mask - right; in snd_cmipci_put_volume()
2064 spin_lock_irq(&cm->reg_lock); in snd_cmipci_put_volume()
2079 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_put_volume()
2084 * input route (left,right) -> (left,right)
2096 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; in snd_cmipci_info_input_sw()
2097 uinfo->count = 4; in snd_cmipci_info_input_sw()
2098 uinfo->value.integer.min = 0; in snd_cmipci_info_input_sw()
2099 uinfo->value.integer.max = 1; in snd_cmipci_info_input_sw()
2110 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_get_input_sw()
2111 spin_lock_irq(&cm->reg_lock); in snd_cmipci_get_input_sw()
2114 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_get_input_sw()
2115 ucontrol->value.integer.value[0] = (val1 >> reg.left_shift) & 1; in snd_cmipci_get_input_sw()
2116 ucontrol->value.integer.value[1] = (val2 >> reg.left_shift) & 1; in snd_cmipci_get_input_sw()
2117 ucontrol->value.integer.value[2] = (val1 >> reg.right_shift) & 1; in snd_cmipci_get_input_sw()
2118 ucontrol->value.integer.value[3] = (val2 >> reg.right_shift) & 1; in snd_cmipci_get_input_sw()
2130 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_put_input_sw()
2131 spin_lock_irq(&cm->reg_lock); in snd_cmipci_put_input_sw()
2136 val1 |= (ucontrol->value.integer.value[0] & 1) << reg.left_shift; in snd_cmipci_put_input_sw()
2137 val2 |= (ucontrol->value.integer.value[1] & 1) << reg.left_shift; in snd_cmipci_put_input_sw()
2138 val1 |= (ucontrol->value.integer.value[2] & 1) << reg.right_shift; in snd_cmipci_put_input_sw()
2139 val2 |= (ucontrol->value.integer.value[3] & 1) << reg.right_shift; in snd_cmipci_put_input_sw()
2143 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_put_input_sw()
2184 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_info_native_mixer()
2185 uinfo->type = reg.mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_cmipci_info_native_mixer()
2186 uinfo->count = reg.stereo + 1; in snd_cmipci_info_native_mixer()
2187 uinfo->value.integer.min = 0; in snd_cmipci_info_native_mixer()
2188 uinfo->value.integer.max = reg.mask; in snd_cmipci_info_native_mixer()
2200 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_get_native_mixer()
2201 spin_lock_irq(&cm->reg_lock); in snd_cmipci_get_native_mixer()
2202 oreg = inb(cm->iobase + reg.left_reg); in snd_cmipci_get_native_mixer()
2205 val = reg.mask - val; in snd_cmipci_get_native_mixer()
2206 ucontrol->value.integer.value[0] = val; in snd_cmipci_get_native_mixer()
2210 val = reg.mask - val; in snd_cmipci_get_native_mixer()
2211 ucontrol->value.integer.value[1] = val; in snd_cmipci_get_native_mixer()
2213 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_get_native_mixer()
2224 cmipci_sb_reg_decode(&reg, kcontrol->private_value); in snd_cmipci_put_native_mixer()
2225 spin_lock_irq(&cm->reg_lock); in snd_cmipci_put_native_mixer()
2226 oreg = inb(cm->iobase + reg.left_reg); in snd_cmipci_put_native_mixer()
2227 val = ucontrol->value.integer.value[0] & reg.mask; in snd_cmipci_put_native_mixer()
2229 val = reg.mask - val; in snd_cmipci_put_native_mixer()
2233 val = ucontrol->value.integer.value[1] & reg.mask; in snd_cmipci_put_native_mixer()
2235 val = reg.mask - val; in snd_cmipci_put_native_mixer()
2239 outb(nreg, cm->iobase + reg.left_reg); in snd_cmipci_put_native_mixer()
2240 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_put_native_mixer()
2245 * special case - check mixer sensitivity
2258 if (cm->mixer_insensitive) { in snd_cmipci_put_native_mixer_sensitive()
2268 CMIPCI_MIXER_SW_MONO("3D Control - Switch", CM_REG_MIXER1, CM_X3DEN_SHIFT, 0),
2314 * non-audio operation?
2327 spin_lock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_get()
2328 if (args->ac3_sensitive && cm->mixer_insensitive) { in _snd_cmipci_uswitch_get()
2329 ucontrol->value.integer.value[0] = 0; in _snd_cmipci_uswitch_get()
2330 spin_unlock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_get()
2333 if (args->is_byte) in _snd_cmipci_uswitch_get()
2334 val = inb(cm->iobase + args->reg); in _snd_cmipci_uswitch_get()
2336 val = snd_cmipci_read(cm, args->reg); in _snd_cmipci_uswitch_get()
2337 ucontrol->value.integer.value[0] = ((val & args->mask) == args->mask_on) ? 1 : 0; in _snd_cmipci_uswitch_get()
2338 spin_unlock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_get()
2346 args = (struct cmipci_switch_args *)kcontrol->private_value; in snd_cmipci_uswitch_get()
2348 return -EINVAL; in snd_cmipci_uswitch_get()
2360 spin_lock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_put()
2361 if (args->ac3_sensitive && cm->mixer_insensitive) { in _snd_cmipci_uswitch_put()
2363 spin_unlock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_put()
2366 if (args->is_byte) in _snd_cmipci_uswitch_put()
2367 val = inb(cm->iobase + args->reg); in _snd_cmipci_uswitch_put()
2369 val = snd_cmipci_read(cm, args->reg); in _snd_cmipci_uswitch_put()
2370 change = (val & args->mask) != (ucontrol->value.integer.value[0] ? in _snd_cmipci_uswitch_put()
2371 args->mask_on : (args->mask & ~args->mask_on)); in _snd_cmipci_uswitch_put()
2373 val &= ~args->mask; in _snd_cmipci_uswitch_put()
2374 if (ucontrol->value.integer.value[0]) in _snd_cmipci_uswitch_put()
2375 val |= args->mask_on; in _snd_cmipci_uswitch_put()
2377 val |= (args->mask & ~args->mask_on); in _snd_cmipci_uswitch_put()
2378 if (args->is_byte) in _snd_cmipci_uswitch_put()
2379 outb((unsigned char)val, cm->iobase + args->reg); in _snd_cmipci_uswitch_put()
2381 snd_cmipci_write(cm, args->reg, val); in _snd_cmipci_uswitch_put()
2383 spin_unlock_irq(&cm->reg_lock); in _snd_cmipci_uswitch_put()
2391 args = (struct cmipci_switch_args *)kcontrol->private_value; in snd_cmipci_uswitch_put()
2393 return -EINVAL; in snd_cmipci_uswitch_put()
2435 // DEFINE_BIT_SWITCH_ARG(joystick, CM_REG_FUNCTRL1, CM_JYSTK_EN, 0, 0); /* now module option */
2472 if (ucontrol->value.integer.value[0]) { in snd_cmipci_spdout_enable_put()
2473 if (chip->spdif_playback_avail) in snd_cmipci_spdout_enable_put()
2476 if (chip->spdif_playback_avail) in snd_cmipci_spdout_enable_put()
2480 chip->spdif_playback_enabled = ucontrol->value.integer.value[0]; in snd_cmipci_spdout_enable_put()
2490 "Line-In", "Rear Output", "Bass Output" in snd_cmipci_line_in_mode_info()
2494 cm->chip_version >= 39 ? 3 : 2, texts); in snd_cmipci_line_in_mode_info()
2500 if (cm->chip_version >= 39) { in get_line_in_mode()
2516 spin_lock_irq(&cm->reg_lock); in snd_cmipci_line_in_mode_get()
2517 ucontrol->value.enumerated.item[0] = get_line_in_mode(cm); in snd_cmipci_line_in_mode_get()
2518 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_line_in_mode_get()
2528 spin_lock_irq(&cm->reg_lock); in snd_cmipci_line_in_mode_put()
2529 if (ucontrol->value.enumerated.item[0] == 2) in snd_cmipci_line_in_mode_put()
2533 if (ucontrol->value.enumerated.item[0] == 1) in snd_cmipci_line_in_mode_put()
2537 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_line_in_mode_put()
2544 static const char *const texts[2] = { "Mic-In", "Center/LFE Output" }; in snd_cmipci_mic_in_mode_info()
2554 spin_lock_irq(&cm->reg_lock); in snd_cmipci_mic_in_mode_get()
2555 ucontrol->value.enumerated.item[0] = in snd_cmipci_mic_in_mode_get()
2557 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_mic_in_mode_get()
2567 spin_lock_irq(&cm->reg_lock); in snd_cmipci_mic_in_mode_put()
2568 if (ucontrol->value.enumerated.item[0]) in snd_cmipci_mic_in_mode_put()
2572 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_mic_in_mode_put()
2580 .name = "Line-In Mode",
2588 /* for non-multichannel chips */
2626 .name = "Mic-In Mode",
2647 if (snd_BUG_ON(!cm || !cm->card)) in snd_cmipci_mixer_new()
2648 return -EINVAL; in snd_cmipci_mixer_new()
2650 card = cm->card; in snd_cmipci_mixer_new()
2652 strcpy(card->mixername, "CMedia PCI"); in snd_cmipci_mixer_new()
2654 spin_lock_irq(&cm->reg_lock); in snd_cmipci_mixer_new()
2656 spin_unlock_irq(&cm->reg_lock); in snd_cmipci_mixer_new()
2659 if (cm->chip_version == 68) { // 8768 has no PCM volume in snd_cmipci_mixer_new()
2672 err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm)); in snd_cmipci_mixer_new()
2676 if (! cm->can_multi_ch) { in snd_cmipci_mixer_new()
2677 err = snd_ctl_add(cm->card, snd_ctl_new1(&snd_cmipci_nomulti_switch, cm)); in snd_cmipci_mixer_new()
2681 if (cm->device == PCI_DEVICE_ID_CMEDIA_CM8738 || in snd_cmipci_mixer_new()
2682 cm->device == PCI_DEVICE_ID_CMEDIA_CM8738B) { in snd_cmipci_mixer_new()
2685 err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm)); in snd_cmipci_mixer_new()
2689 if (cm->can_ac3_hw) { in snd_cmipci_mixer_new()
2691 kctl->id.device = pcm_spdif_device; in snd_cmipci_mixer_new()
2696 kctl->id.device = pcm_spdif_device; in snd_cmipci_mixer_new()
2701 kctl->id.device = pcm_spdif_device; in snd_cmipci_mixer_new()
2706 if (cm->chip_version <= 37) { in snd_cmipci_mixer_new()
2709 err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm)); in snd_cmipci_mixer_new()
2715 if (cm->chip_version >= 39) { in snd_cmipci_mixer_new()
2718 err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm)); in snd_cmipci_mixer_new()
2729 if (cm->chip_version < 39) { in snd_cmipci_mixer_new()
2730 err = snd_ctl_add(cm->card, in snd_cmipci_mixer_new()
2738 ctl = snd_ctl_find_id_mixer(cm->card, cm_saved_mixer[idx].name); in snd_cmipci_mixer_new()
2740 cm->mixer_res_ctl[idx] = ctl; in snd_cmipci_mixer_new()
2754 struct cmipci *cm = entry->private_data; in snd_cmipci_proc_read()
2757 snd_iprintf(buffer, "%s\n", cm->card->longname); in snd_cmipci_proc_read()
2761 v = inb(cm->iobase + i); in snd_cmipci_proc_read()
2771 snd_card_ro_proc_new(cm->card, "cmipci", cm, snd_cmipci_proc_read); in snd_cmipci_proc_init()
2792 /* check reg 0Ch, bit 24-31 */ in query_chip()
2795 /* check reg 08h, bit 24-28 */ in query_chip()
2799 cm->chip_version = 33; in query_chip()
2800 if (cm->do_soft_ac3) in query_chip()
2801 cm->can_ac3_sw = 1; in query_chip()
2803 cm->can_ac3_hw = 1; in query_chip()
2806 cm->chip_version = 37; in query_chip()
2807 cm->can_ac3_hw = 1; in query_chip()
2810 cm->chip_version = 39; in query_chip()
2811 cm->can_ac3_hw = 1; in query_chip()
2814 cm->max_channels = 2; in query_chip()
2817 cm->chip_version = 39; in query_chip()
2819 cm->max_channels = 6; in query_chip()
2821 cm->max_channels = 4; in query_chip()
2823 cm->chip_version = 68; in query_chip()
2824 cm->max_channels = 8; in query_chip()
2825 cm->can_96k = 1; in query_chip()
2827 cm->chip_version = 55; in query_chip()
2828 cm->max_channels = 6; in query_chip()
2829 cm->can_96k = 1; in query_chip()
2831 cm->can_ac3_hw = 1; in query_chip()
2832 cm->can_multi_ch = 1; in query_chip()
2845 return -ENODEV; in snd_cmipci_create_gameport()
2847 if (joystick_port[dev] == 1) { /* auto-detect */ in snd_cmipci_create_gameport()
2850 r = devm_request_region(&cm->pci->dev, io_port, 1, in snd_cmipci_create_gameport()
2857 r = devm_request_region(&cm->pci->dev, io_port, 1, in snd_cmipci_create_gameport()
2862 dev_warn(cm->card->dev, "cannot reserve joystick ports\n"); in snd_cmipci_create_gameport()
2863 return -EBUSY; in snd_cmipci_create_gameport()
2866 cm->gameport = gp = gameport_allocate_port(); in snd_cmipci_create_gameport()
2868 dev_err(cm->card->dev, "cannot allocate memory for gameport\n"); in snd_cmipci_create_gameport()
2869 return -ENOMEM; in snd_cmipci_create_gameport()
2871 gameport_set_name(gp, "C-Media Gameport"); in snd_cmipci_create_gameport()
2872 gameport_set_phys(gp, "pci%s/gameport0", pci_name(cm->pci)); in snd_cmipci_create_gameport()
2873 gameport_set_dev_parent(gp, &cm->pci->dev); in snd_cmipci_create_gameport()
2874 gp->io = io_port; in snd_cmipci_create_gameport()
2878 gameport_register_port(cm->gameport); in snd_cmipci_create_gameport()
2885 if (cm->gameport) { in snd_cmipci_free_gameport()
2886 gameport_unregister_port(cm->gameport); in snd_cmipci_free_gameport()
2887 cm->gameport = NULL; in snd_cmipci_free_gameport()
2893 static inline int snd_cmipci_create_gameport(struct cmipci *cm, int dev) { return -ENOSYS; } in snd_cmipci_create_gameport()
2899 struct cmipci *cm = card->private_data; in snd_cmipci_free()
2925 if (cm->chip_version >= 39) { in snd_cmipci_create_fm()
2927 iosynth = cm->iobase + CM_REG_FM_PCI; in snd_cmipci_create_fm()
2928 err = snd_opl3_create(cm->card, iosynth, iosynth + 2, in snd_cmipci_create_fm()
2931 err = -EIO; in snd_cmipci_create_fm()
2949 if (snd_opl3_create(cm->card, iosynth, iosynth + 2, in snd_cmipci_create_fm()
2951 dev_err(cm->card->dev, in snd_cmipci_create_fm()
2959 dev_err(cm->card->dev, "cannot create OPL3 hwdep\n"); in snd_cmipci_create_fm()
2973 struct cmipci *cm = card->private_data; in snd_cmipci_create()
2989 spin_lock_init(&cm->reg_lock); in snd_cmipci_create()
2990 mutex_init(&cm->open_mutex); in snd_cmipci_create()
2991 cm->device = pci->device; in snd_cmipci_create()
2992 cm->card = card; in snd_cmipci_create()
2993 cm->pci = pci; in snd_cmipci_create()
2994 cm->irq = -1; in snd_cmipci_create()
2995 cm->channel[0].ch = 0; in snd_cmipci_create()
2996 cm->channel[1].ch = 1; in snd_cmipci_create()
2997 cm->channel[0].is_dac = cm->channel[1].is_dac = 1; /* dual DAC mode */ in snd_cmipci_create()
2999 err = pci_request_regions(pci, card->driver); in snd_cmipci_create()
3002 cm->iobase = pci_resource_start(pci, 0); in snd_cmipci_create()
3004 if (devm_request_irq(&pci->dev, pci->irq, snd_cmipci_interrupt, in snd_cmipci_create()
3006 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); in snd_cmipci_create()
3007 return -EBUSY; in snd_cmipci_create()
3009 cm->irq = pci->irq; in snd_cmipci_create()
3010 card->sync_irq = cm->irq; in snd_cmipci_create()
3011 card->private_free = snd_cmipci_free; in snd_cmipci_create()
3013 pci_set_master(cm->pci); in snd_cmipci_create()
3019 cm->chip_version = 0; in snd_cmipci_create()
3020 cm->max_channels = 2; in snd_cmipci_create()
3021 cm->do_soft_ac3 = soft_ac3[dev]; in snd_cmipci_create()
3023 if (pci->device != PCI_DEVICE_ID_CMEDIA_CM8338A && in snd_cmipci_create()
3024 pci->device != PCI_DEVICE_ID_CMEDIA_CM8338B) in snd_cmipci_create()
3026 /* added -MCx suffix for chip supporting multi-channels */ in snd_cmipci_create()
3027 if (cm->can_multi_ch) in snd_cmipci_create()
3028 sprintf(cm->card->driver + strlen(cm->card->driver), in snd_cmipci_create()
3029 "-MC%d", cm->max_channels); in snd_cmipci_create()
3030 else if (cm->can_ac3_sw) in snd_cmipci_create()
3031 strcpy(cm->card->driver + strlen(cm->card->driver), "-SWIEC"); in snd_cmipci_create()
3033 cm->dig_status = SNDRV_PCM_DEFAULT_CON_SPDIF; in snd_cmipci_create()
3034 cm->dig_pcm_status = SNDRV_PCM_DEFAULT_CON_SPDIF; in snd_cmipci_create()
3037 cm->ctrl = CM_CHADC0; /* default FUNCNTRL0 */ in snd_cmipci_create()
3039 cm->ctrl = CM_CHADC1; /* default FUNCNTRL0 */ in snd_cmipci_create()
3058 if (cm->chip_version) { in snd_cmipci_create()
3066 switch (pci->device) { in snd_cmipci_create()
3076 if (cm->chip_version < 68) { in snd_cmipci_create()
3077 val = pci->device < 0x110 ? 8338 : 8738; in snd_cmipci_create()
3087 switch ((pci->subsystem_vendor << 16) | in snd_cmipci_create()
3088 pci->subsystem_device) { in snd_cmipci_create()
3103 sprintf(card->shortname, "C-Media CMI%d", val); in snd_cmipci_create()
3104 if (cm->chip_version < 68) in snd_cmipci_create()
3106 " (model %d)", cm->chip_version); in snd_cmipci_create()
3109 scnprintf(card->longname, sizeof(card->longname), in snd_cmipci_create()
3111 card->shortname, modelstr, cm->iobase, cm->irq); in snd_cmipci_create()
3113 if (cm->chip_version >= 39) { in snd_cmipci_create()
3117 iomidi = cm->iobase + CM_REG_MPU_PCI; in snd_cmipci_create()
3137 dev_err(cm->card->dev, in snd_cmipci_create()
3138 "cannot enable MPU-401 port at %#lx\n", in snd_cmipci_create()
3147 if (cm->chip_version < 68) { in snd_cmipci_create()
3168 if (cm->can_ac3_hw || cm->can_ac3_sw) { in snd_cmipci_create()
3186 -1, &cm->rmidi); in snd_cmipci_create()
3188 dev_err(cm->card->dev, in snd_cmipci_create()
3197 * (Re-)Enable external switch spdo_48k in snd_cmipci_create()
3221 return -ENODEV; in snd_cmipci_probe()
3224 return -ENOENT; in snd_cmipci_probe()
3227 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, in snd_cmipci_probe()
3232 switch (pci->device) { in snd_cmipci_probe()
3235 strcpy(card->driver, "CMI8738"); in snd_cmipci_probe()
3239 strcpy(card->driver, "CMI8338"); in snd_cmipci_probe()
3242 strcpy(card->driver, "CMIPCI"); in snd_cmipci_probe()
3289 struct cmipci *cm = card->private_data; in snd_cmipci_suspend()
3296 cm->saved_regs[i] = snd_cmipci_read(cm, saved_regs[i]); in snd_cmipci_suspend()
3298 cm->saved_mixers[i] = snd_cmipci_mixer_read(cm, saved_mixers[i]); in snd_cmipci_suspend()
3308 struct cmipci *cm = card->private_data; in snd_cmipci_resume()
3319 snd_cmipci_write(cm, saved_regs[i], cm->saved_regs[i]); in snd_cmipci_resume()
3321 snd_cmipci_mixer_write(cm, saved_mixers[i], cm->saved_mixers[i]); in snd_cmipci_resume()