Lines Matching +full:adc +full:- +full:tm

1 // SPDX-License-Identifier: GPL-2.0-or-later
10 - spdif nonaudio consumer mode does not work (at least with my
11 Sony STR-DB830)
18 * split the code to several files. each low-level routine
25 * I also haven't done anything with the internal S/PDIF transmitter or the MPU-401
40 #include <linux/dma-mapping.h>
64 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
69 static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transceiver reset timeout value in msec */
79 MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
106 /* check whether the clock mode is spdif-in */
133 struct snd_ice1712 *ice = ac97->private_data;
134 int tm;
137 for (tm = 0; tm < 0x10000; tm++) {
149 for (tm = 0; tm < 0x10000; tm++)
157 struct snd_ice1712 *ice = ac97->private_data;
158 int tm;
161 for (tm = 0; tm < 0x10000; tm++) {
171 for (tm = 0; tm < 0x10000; tm++)
174 if (tm >= 0x10000) /* timeout */
187 struct snd_ice1712 *ice = ac97->private_data;
188 int tm;
191 for (tm = 0; tm < 0x10000; tm++) {
203 for (tm = 0; tm < 0x10000; tm++)
212 struct snd_ice1712 *ice = ac97->private_data;
213 int tm;
216 for (tm = 0; tm < 0x10000; tm++) {
226 for (tm = 0; tm < 0x10000; tm++)
229 if (tm >= 0x10000) /* timeout */
243 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
252 guard(spinlock_irq)(&ice->reg_lock);
255 if (ucontrol->value.integer.value[0])
276 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
292 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
303 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
314 * spdif_clock = 1 - IEC958 input, 0 - Envy24
322 snd_i2c_lock(ice->i2c);
323 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
324 snd_i2c_unlock(ice->i2c);
325 return -EIO;
327 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
328 snd_i2c_unlock(ice->i2c);
329 return -EIO;
338 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
339 res = -EIO;
344 snd_i2c_unlock(ice->i2c);
353 snd_cs8427_iec958_active(ice->cs8427, 1);
358 snd_cs8427_iec958_active(ice->cs8427, 0);
363 snd_cs8427_iec958_pcm(ice->cs8427, rate);
373 err = snd_cs8427_create(ice->i2c, addr,
374 (ice->cs8427_timeout * HZ) / 1000, &ice->cs8427);
376 dev_err(ice->card->dev, "CS8427 initialization failed\n");
379 ice->spdif.ops.open = open_cs8427;
380 ice->spdif.ops.close = close_cs8427;
381 ice->spdif.ops.setup_rate = setup_cs8427;
388 if (ice->cs8427)
393 for (i = 0; i < ice->akm_codecs; i++) {
394 if (ice->akm[i].ops.set_rate_val)
395 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
416 if (ice->rmidi[0])
417 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
424 if (ice->rmidi[1])
425 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data);
432 if (ice->playback_pro_substream)
433 snd_pcm_period_elapsed(ice->playback_pro_substream);
437 if (ice->capture_pro_substream)
438 snd_pcm_period_elapsed(ice->capture_pro_substream);
449 /* dev_dbg(ice->card->dev, "pbkstatus = 0x%x\n", pbkstatus); */
453 substream = ice->playback_con_substream_ds[idx];
461 if (ice->capture_con_substream)
462 snd_pcm_period_elapsed(ice->capture_con_substream);
466 if (ice->playback_con_substream)
467 snd_pcm_period_elapsed(ice->playback_con_substream);
476 * PCM part - consumer I/O
486 guard(spinlock)(&ice->reg_lock);
497 result = -EINVAL;
510 guard(spinlock)(&ice->reg_lock);
511 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
521 result = -EINVAL;
523 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
534 guard(spinlock)(&ice->reg_lock);
541 result = -EINVAL;
550 struct snd_pcm_runtime *runtime = substream->runtime;
553 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
554 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
556 if (snd_pcm_format_width(runtime->format) == 16)
558 if (runtime->channels == 2)
560 rate = (runtime->rate * 8192) / 375;
563 guard(spinlock_irq)(&ice->reg_lock);
564 outb(0, ice->ddma_port + 15);
565 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
566 outl(runtime->dma_addr, ice->ddma_port + 0);
567 outw(buf_size, ice->ddma_port + 4);
582 struct snd_pcm_runtime *runtime = substream->runtime;
585 period_size = snd_pcm_lib_period_bytes(substream) - 1;
587 if (snd_pcm_format_width(runtime->format) == 16)
589 if (runtime->channels == 2)
591 rate = (runtime->rate * 8192) / 375;
594 ice->playback_con_active_buf[substream->number] = 0;
595 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
596 chn = substream->number * 2;
597 guard(spinlock_irq)(&ice->reg_lock);
598 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
600 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
605 if (runtime->channels == 2) {
615 struct snd_pcm_runtime *runtime = substream->runtime;
619 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
620 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
622 if (snd_pcm_format_width(runtime->format) == 16)
624 if (runtime->channels == 2)
626 scoped_guard(spinlock_irq, &ice->reg_lock) {
627 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
633 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
640 struct snd_pcm_runtime *runtime = substream->runtime;
645 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
646 ptr = bytes_to_frames(substream->runtime, ptr);
647 if (ptr == runtime->buffer_size)
658 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
660 if (ice->playback_con_active_buf[substream->number])
664 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
665 ice->playback_con_virt_addr[substream->number];
666 ptr = bytes_to_frames(substream->runtime, ptr);
667 if (ptr == substream->runtime->buffer_size)
679 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
680 ptr = bytes_to_frames(substream->runtime, ptr);
681 if (ptr == substream->runtime->buffer_size)
744 struct snd_pcm_runtime *runtime = substream->runtime;
747 ice->playback_con_substream = substream;
748 runtime->hw = snd_ice1712_playback;
754 struct snd_pcm_runtime *runtime = substream->runtime;
758 ice->playback_con_substream_ds[substream->number] = substream;
759 runtime->hw = snd_ice1712_playback_ds;
760 guard(spinlock_irq)(&ice->reg_lock);
761 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
768 struct snd_pcm_runtime *runtime = substream->runtime;
771 ice->capture_con_substream = substream;
772 runtime->hw = snd_ice1712_capture;
773 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
774 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
775 runtime->hw.rate_min = 48000;
783 ice->playback_con_substream = NULL;
792 guard(spinlock_irq)(&ice->reg_lock);
793 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
795 ice->playback_con_substream_ds[substream->number] = NULL;
803 ice->capture_con_substream = NULL;
836 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
843 pcm->private_data = ice;
844 pcm->info_flags = 0;
845 strscpy(pcm->name, "ICE1712 consumer");
846 ice->pcm = pcm;
849 &ice->pci->dev, 64*1024, 64*1024);
851 dev_warn(ice->card->dev,
852 "Consumer PCM code does not work well at the moment --jk\n");
862 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
868 pcm->private_data = ice;
869 pcm->info_flags = 0;
870 strscpy(pcm->name, "ICE1712 consumer (DS)");
871 ice->pcm_ds = pcm;
874 &ice->pci->dev, 64*1024, 128*1024);
880 * PCM code - professional part (multitrack)
902 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
903 return -EINVAL;
906 guard(spinlock)(&ice->reg_lock);
923 if (s == ice->playback_pro_substream) {
926 } else if (s == ice->capture_pro_substream) {
931 guard(spinlock)(&ice->reg_lock);
941 return -EINVAL;
974 scoped_guard(spinlock_irqsave, &ice->reg_lock) {
986 ice->cur_rate = rate;
990 if (ice->gpio.set_pro_rate)
991 ice->gpio.set_pro_rate(ice, rate);
992 for (i = 0; i < ice->akm_codecs; i++) {
993 if (ice->akm[i].ops.set_rate_val)
994 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
996 if (ice->spdif.ops.setup_rate)
997 ice->spdif.ops.setup_rate(ice, rate);
1004 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1005 guard(spinlock_irq)(&ice->reg_lock);
1006 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1007 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1008 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1026 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1027 guard(spinlock_irq)(&ice->reg_lock);
1028 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1029 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1030 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1050 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1051 ptr = bytes_to_frames(substream->runtime, ptr);
1052 if (ptr == substream->runtime->buffer_size)
1064 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1065 ptr = bytes_to_frames(substream->runtime, ptr);
1066 if (ptr == substream->runtime->buffer_size)
1111 struct snd_pcm_runtime *runtime = substream->runtime;
1114 ice->playback_pro_substream = substream;
1115 runtime->hw = snd_ice1712_playback_pro;
1120 runtime->hw.rate_min = PRO_RATE_DEFAULT;
1121 runtime->hw.rate_max = PRO_RATE_DEFAULT;
1124 if (ice->spdif.ops.open)
1125 ice->spdif.ops.open(ice, substream);
1133 struct snd_pcm_runtime *runtime = substream->runtime;
1135 ice->capture_pro_substream = substream;
1136 runtime->hw = snd_ice1712_capture_pro;
1141 runtime->hw.rate_min = PRO_RATE_DEFAULT;
1142 runtime->hw.rate_max = PRO_RATE_DEFAULT;
1154 ice->playback_pro_substream = NULL;
1155 if (ice->spdif.ops.close)
1156 ice->spdif.ops.close(ice, substream);
1167 ice->capture_pro_substream = NULL;
1194 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1201 pcm->private_data = ice;
1202 pcm->info_flags = 0;
1203 strscpy(pcm->name, "ICE1712 multi");
1206 &ice->pci->dev, 256*1024, 256*1024);
1208 ice->pcm_pro = pcm;
1210 if (ice->cs8427) {
1212 err = snd_cs8427_iec958_build(ice->cs8427,
1213 pcm->streams[0].substream,
1214 pcm->streams[1].substream);
1228 unsigned int vol = ice->pro_volumes[index];
1231 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1232 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1242 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1243 kcontrol->private_value;
1245 guard(spinlock_irq)(&ice->reg_lock);
1246 ucontrol->value.integer.value[0] =
1247 !((ice->pro_volumes[priv_idx] >> 15) & 1);
1248 ucontrol->value.integer.value[1] =
1249 !((ice->pro_volumes[priv_idx] >> 31) & 1);
1256 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1257 kcontrol->private_value;
1260 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1261 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1262 guard(spinlock_irq)(&ice->reg_lock);
1263 nval |= ice->pro_volumes[priv_idx] & ~0x80008000;
1264 change = nval != ice->pro_volumes[priv_idx];
1265 ice->pro_volumes[priv_idx] = nval;
1272 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1273 uinfo->count = 2;
1274 uinfo->value.integer.min = 0;
1275 uinfo->value.integer.max = 96;
1282 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1283 kcontrol->private_value;
1285 guard(spinlock_irq)(&ice->reg_lock);
1286 ucontrol->value.integer.value[0] =
1287 (ice->pro_volumes[priv_idx] >> 0) & 127;
1288 ucontrol->value.integer.value[1] =
1289 (ice->pro_volumes[priv_idx] >> 16) & 127;
1296 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1297 kcontrol->private_value;
1300 nval = (ucontrol->value.integer.value[0] & 127) |
1301 ((ucontrol->value.integer.value[1] & 127) << 16);
1302 guard(spinlock_irq)(&ice->reg_lock);
1303 nval |= ice->pro_volumes[priv_idx] & ~0x007f007f;
1304 change = nval != ice->pro_volumes[priv_idx];
1305 ice->pro_volumes[priv_idx] = nval;
1310 static const DECLARE_TLV_DB_SCALE(db_scale_playback, -14400, 150, 0);
1379 struct snd_card *card = ice->card;
1383 /* multi-channel mixer */
1390 if (ice->num_total_adcs > 0) {
1392 tmp.count = ice->num_total_adcs;
1402 if (ice->num_total_adcs > 0) {
1404 tmp.count = ice->num_total_adcs;
1416 ice->pro_volumes[idx] = 0x80008000; /* mute */
1419 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1420 ice->pro_volumes[idx] = 0x80008000; /* mute */
1424 ice->pro_volumes[idx] = 0x80008000; /* mute */
1432 struct snd_ice1712 *ice = ac97->private_data;
1433 ice->ac97 = NULL;
1451 err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus);
1457 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1459 dev_warn(ice->card->dev,
1462 return snd_ctl_add(ice->card,
1468 if (!(ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1469 err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus);
1475 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1477 dev_warn(ice->card->dev,
1483 strcat(ice->card->mixername, "ICE1712 - multitrack");
1493 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1499 struct snd_ice1712 *ice = entry->private_data;
1502 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1505 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1506 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1507 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1508 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1509 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1510 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1511 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1512 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1513 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1514 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1518 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1520 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1522 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1523 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1524 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1538 snd_card_ro_proc_new(ice->card, "ice1712", ice, snd_ice1712_proc_read);
1548 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1549 uinfo->count = sizeof(struct snd_ice1712_eeprom);
1558 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1575 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1576 uinfo->count = 1;
1584 if (ice->spdif.ops.default_get)
1585 ice->spdif.ops.default_get(ice, ucontrol);
1593 if (ice->spdif.ops.default_put)
1594 return ice->spdif.ops.default_put(ice, ucontrol);
1611 if (ice->spdif.ops.default_get) {
1612 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1616 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1618 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1620 ucontrol->value.iec958.status[0] = 0xff;
1621 ucontrol->value.iec958.status[1] = 0xff;
1622 ucontrol->value.iec958.status[2] = 0xff;
1623 ucontrol->value.iec958.status[3] = 0xff;
1624 ucontrol->value.iec958.status[4] = 0xff;
1633 if (ice->spdif.ops.default_get) {
1634 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1638 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1640 ucontrol->value.iec958.status[0] = 0xff;
1641 ucontrol->value.iec958.status[1] = 0xff;
1642 ucontrol->value.iec958.status[2] = 0xff;
1643 ucontrol->value.iec958.status[3] = 0xff;
1644 ucontrol->value.iec958.status[4] = 0xff;
1671 if (ice->spdif.ops.stream_get)
1672 ice->spdif.ops.stream_get(ice, ucontrol);
1680 if (ice->spdif.ops.stream_put)
1681 return ice->spdif.ops.stream_put(ice, ucontrol);
1700 unsigned char mask = kcontrol->private_value & 0xff;
1701 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1704 ucontrol->value.integer.value[0] =
1714 unsigned char mask = kcontrol->private_value & 0xff;
1715 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1718 if (kcontrol->private_value & (1 << 31))
1719 return -EPERM;
1720 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1750 "IEC958 Input", /* 13: -- */
1764 guard(spinlock_irq)(&ice->reg_lock);
1766 ucontrol->value.enumerated.item[0] = 13;
1773 ucontrol->value.enumerated.item[0] = val;
1789 spin_lock_irq(&ice->reg_lock);
1791 if (ucontrol->value.enumerated.item[0] == 13) {
1794 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1795 spin_unlock_irq(&ice->reg_lock);
1797 spin_lock_irq(&ice->reg_lock);
1800 spin_unlock_irq(&ice->reg_lock);
1834 /* "IEC958 Input", 13: -- */
1853 ucontrol->value.enumerated.item[0] = val;
1868 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1887 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1897 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1898 guard(spinlock_irq)(&ice->reg_lock);
1917 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
1927 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1928 guard(spinlock_irq)(&ice->reg_lock);
1950 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
1951 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
1952 "IEC958 In L", "IEC958 In R", /* 9-10 */
1953 "Digital Mixer", /* 11 - optional */
1955 int num_items = snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
1963 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1966 scoped_guard(spinlock_irq, &ice->reg_lock) {
1975 ucontrol->value.enumerated.item[0] = 11;
1977 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
1979 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
1981 ucontrol->value.enumerated.item[0] = 0;
1990 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1994 if (ucontrol->value.enumerated.item[0] >= 11)
1996 else if (ucontrol->value.enumerated.item[0] >= 9)
1998 else if (ucontrol->value.enumerated.item[0] >= 1)
2003 scoped_guard(spinlock_irq, &ice->reg_lock) {
2015 scoped_guard(spinlock_irq, &ice->reg_lock) {
2019 nval = ucontrol->value.enumerated.item[0] - 1;
2023 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2039 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2045 ucontrol->value.enumerated.item[0] = 11;
2047 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2049 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2051 ucontrol->value.enumerated.item[0] = 0;
2060 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2064 guard(spinlock_irq)(&ice->reg_lock);
2066 if (ucontrol->value.enumerated.item[0] >= 11)
2068 else if (ucontrol->value.enumerated.item[0] >= 9)
2070 else if (ucontrol->value.enumerated.item[0] >= 1)
2079 nval = ucontrol->value.enumerated.item[0] - 1;
2083 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2114 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2115 uinfo->count = 1;
2116 uinfo->value.integer.min = 0;
2117 uinfo->value.integer.max = 255;
2126 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2136 guard(spinlock_irq)(&ice->reg_lock);
2137 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2138 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2153 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2154 uinfo->count = 22;
2155 uinfo->value.integer.min = 0;
2156 uinfo->value.integer.max = 255;
2166 guard(spinlock_irq)(&ice->reg_lock);
2169 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2204 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2216 ice->eeprom.subvendor = 0;
2218 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
2222 if (ice->eeprom.subvendor == 0 ||
2223 ice->eeprom.subvendor == (unsigned int)-1) {
2226 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
2227 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2228 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2229 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2230 dev_err(ice->card->dev,
2232 return -ENXIO;
2237 for (c = *tbl; c->subvendor; c++) {
2238 if (modelname && c->model && !strcmp(modelname, c->model)) {
2239 dev_info(ice->card->dev,
2240 "Using board model %s\n", c->name);
2241 ice->eeprom.subvendor = c->subvendor;
2242 } else if (c->subvendor != ice->eeprom.subvendor)
2244 if (!c->eeprom_size || !c->eeprom_data)
2247 dev_dbg(ice->card->dev, "using the defined eeprom..\n");
2248 ice->eeprom.version = 1;
2249 ice->eeprom.size = c->eeprom_size + 6;
2250 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2254 dev_warn(ice->card->dev, "No matching model found for ID 0x%x\n",
2255 ice->eeprom.subvendor);
2258 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2259 if (ice->eeprom.size < 6)
2260 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2261 else if (ice->eeprom.size > 32) {
2262 dev_err(ice->card->dev,
2263 "invalid EEPROM (size = %i)\n", ice->eeprom.size);
2264 return -EIO;
2266 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2267 if (ice->eeprom.version != 1) {
2268 dev_err(ice->card->dev, "invalid EEPROM version %i\n",
2269 ice->eeprom.version);
2270 /* return -EIO; */
2272 size = ice->eeprom.size - 6;
2274 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2277 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2278 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2279 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2292 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE &&
2293 !ice->dxr_enable)
2298 ice->eeprom.data[ICE_EEP1_CODEC] = 0x3a;
2299 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
2300 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2301 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2302 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2303 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24 &&
2304 ice->eeprom.subvendor != ICE1712_SUBDEVICE_STAUDIO_ADCIII) {
2305 ice->gpio.write_mask = ice->eeprom.gpiomask;
2306 ice->gpio.direction = ice->eeprom.gpiodir;
2308 ice->eeprom.gpiomask);
2310 ice->eeprom.gpiodir);
2312 ice->eeprom.gpiostate);
2314 ice->gpio.write_mask = 0xc0;
2315 ice->gpio.direction = 0xff;
2322 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2331 outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ?
2333 ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ?
2346 if (snd_BUG_ON(!ice->pcm_pro))
2347 return -EIO;
2349 kctl->id.device = ice->pcm_pro->device;
2350 err = snd_ctl_add(ice->card, kctl);
2354 kctl->id.device = ice->pcm_pro->device;
2355 err = snd_ctl_add(ice->card, kctl);
2359 kctl->id.device = ice->pcm_pro->device;
2360 err = snd_ctl_add(ice->card, kctl);
2364 kctl->id.device = ice->pcm_pro->device;
2365 err = snd_ctl_add(ice->card, kctl);
2368 ice->spdif.stream_ctl = kctl;
2377 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2380 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2383 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2387 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2390 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2394 if (ice->num_total_dacs > 0) {
2396 tmp.count = ice->num_total_dacs;
2397 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2402 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2406 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2409 return snd_ctl_add(ice->card,
2415 struct snd_ice1712 *ice = card->private_data;
2417 if (ice->card_info && ice->card_info->chip_exit)
2418 ice->card_info->chip_exit(ice);
2434 struct snd_ice1712 *ice = card->private_data;
2442 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) {
2443 dev_err(card->dev,
2445 return -ENXIO;
2448 ice->omni = omni ? 1 : 0;
2453 ice->cs8427_timeout = cs8427_timeout;
2454 ice->dxr_enable = dxr_enable;
2455 spin_lock_init(&ice->reg_lock);
2456 mutex_init(&ice->gpio_mutex);
2457 mutex_init(&ice->i2c_mutex);
2458 mutex_init(&ice->open_mutex);
2459 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2460 ice->gpio.get_mask = snd_ice1712_get_gpio_mask;
2461 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2462 ice->gpio.get_dir = snd_ice1712_get_gpio_dir;
2463 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2464 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2466 ice->spdif.cs8403_bits =
2467 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2470 ice->card = card;
2471 ice->pci = pci;
2472 ice->irq = -1;
2475 pci_write_config_word(ice->pci, 0x40, 0x807f);
2476 pci_write_config_word(ice->pci, 0x42, 0x0006);
2482 ice->port = pci_resource_start(pci, 0);
2483 ice->ddma_port = pci_resource_start(pci, 1);
2484 ice->dmapath_port = pci_resource_start(pci, 2);
2485 ice->profi_port = pci_resource_start(pci, 3);
2487 if (devm_request_irq(&pci->dev, pci->irq, snd_ice1712_interrupt,
2489 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2490 return -EIO;
2493 ice->irq = pci->irq;
2494 card->sync_irq = ice->irq;
2495 card->private_free = snd_ice1712_free;
2498 return -EIO;
2500 return -EIO;
2524 return -ENODEV;
2527 return -ENOENT;
2530 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2534 ice = card->private_data;
2536 strscpy(card->driver, "ICE1712");
2537 strscpy(card->shortname, "ICEnsemble ICE1712");
2545 for (c = *tbl; c->subvendor; c++) {
2546 if (c->subvendor == ice->eeprom.subvendor) {
2547 strscpy(card->shortname, c->name);
2548 if (c->driver) /* specific driver? */
2549 strscpy(card->driver, c->driver);
2550 if (c->chip_init) {
2551 err = c->chip_init(ice);
2555 ice->card_info = c;
2581 if (c->build_controls) {
2582 err = c->build_controls(ice);
2593 if (!c->no_mpu401) {
2596 c->mpu401_1_info_flags |
2598 -1, &ice->rmidi[0]);
2601 if (c->mpu401_1_name)
2603 snprintf(ice->rmidi[0]->name,
2604 sizeof(ice->rmidi[0]->name),
2605 "%s %d", c->mpu401_1_name, card->number);
2607 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) {
2611 c->mpu401_2_info_flags |
2613 -1, &ice->rmidi[1]);
2617 if (c->mpu401_2_name)
2619 snprintf(ice->rmidi[1]->name,
2620 sizeof(ice->rmidi[1]->name),
2621 "%s %d", c->mpu401_2_name,
2622 card->number);
2628 sprintf(card->longname, "%s at 0x%lx, irq %i",
2629 card->shortname, ice->port, ice->irq);
2643 struct snd_ice1712 *ice = card->private_data;
2645 if (!ice->pm_suspend_enabled)
2650 snd_ac97_suspend(ice->ac97);
2652 scoped_guard(spinlock_irq, &ice->reg_lock) {
2653 ice->pm_saved_is_spdif_master = is_spdif_master(ice);
2654 ice->pm_saved_spdif_ctrl = inw(ICEMT(ice, ROUTE_SPDOUT));
2655 ice->pm_saved_route = inw(ICEMT(ice, ROUTE_PSDOUT03));
2658 if (ice->pm_suspend)
2659 ice->pm_suspend(ice);
2666 struct snd_ice1712 *ice = card->private_data;
2669 if (!ice->pm_suspend_enabled)
2672 if (ice->cur_rate)
2673 rate = ice->cur_rate;
2679 return -EIO;
2682 ice->cur_rate = rate;
2684 if (ice->pm_resume)
2685 ice->pm_resume(ice);
2687 if (ice->pm_saved_is_spdif_master) {
2689 scoped_guard(spinlock_irq, &ice->reg_lock) {
2695 /* internal on-card clock */
2700 outw(ice->pm_saved_spdif_ctrl, ICEMT(ice, ROUTE_SPDOUT));
2701 outw(ice->pm_saved_route, ICEMT(ice, ROUTE_PSDOUT03));
2703 snd_ac97_resume(ice->ac97);