Lines Matching +full:mono +full:- +full:channel

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for ESS Solo-1 (ES1938, ES1946, ES1969) soundcard
7 * Abramo Bagnara <abramo@alsa-project.org>,
18 - Capture data is written unaligned starting from dma_base + 1 so I need to
20 - After several cycle of the following:
21 while : ; do arecord -d1 -f cd -t raw | aplay -f cd ; done
25 - Sometimes the interrupt handler is invoked wrongly during playback.
31 hdparm -t -T /dev/hda
42 #include <linux/dma-mapping.h>
53 MODULE_DESCRIPTION("ESS Solo-1");
60 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
65 MODULE_PARM_DESC(index, "Index value for ESS Solo-1 soundcard.");
67 MODULE_PARM_DESC(id, "ID string for ESS Solo-1 soundcard.");
69 MODULE_PARM_DESC(enable, "Enable ESS Solo-1 soundcard.");
71 #define SLIO_REG(chip, x) ((chip)->io_port + ESSIO_REG_##x)
73 #define SLDM_REG(chip, x) ((chip)->ddma_port + ESSDM_REG_##x)
75 #define SLSB_REG(chip, x) ((chip)->sb_port + ESSSB_REG_##x)
225 { PCI_VDEVICE(ESS, 0x1969), 0, }, /* Solo-1 */
235 /* -----------------------------------------------------------------
237 * -----------------------------------------------------------------*/
240 guard(spinlock_irqsave)(&chip->mixer_lock);
243 dev_dbg(chip->card->dev, "Mixer reg %02x set to %02x\n", reg, val);
246 /* -----------------------------------------------------------------
248 * -----------------------------------------------------------------*/
253 guard(spinlock_irqsave)(&chip->mixer_lock);
256 dev_dbg(chip->card->dev, "Mixer reg %02x now is %02x\n", reg, data);
260 /* -----------------------------------------------------------------
262 * -----------------------------------------------------------------*/
268 guard(spinlock_irqsave)(&chip->mixer_lock);
275 dev_dbg(chip->card->dev,
282 /* -----------------------------------------------------------------
284 * -----------------------------------------------------------------*/
296 dev_err(chip->card->dev,
300 /* -----------------------------------------------------------------
302 * -----------------------------------------------------------------*/
307 for (i = GET_LOOP_TIMEOUT; i; i--) {
312 dev_err(chip->card->dev, "get_byte timeout: status 0x02%x\n", v);
313 return -ENODEV;
316 /* -----------------------------------------------------------------
318 * -----------------------------------------------------------------*/
321 guard(spinlock_irqsave)(&chip->reg_lock);
324 dev_dbg(chip->card->dev, "Reg %02x set to %02x\n", reg, val);
327 /* -----------------------------------------------------------------
329 * -----------------------------------------------------------------*/
334 guard(spinlock_irqsave)(&chip->reg_lock);
338 dev_dbg(chip->card->dev, "Reg %02x now is %02x\n", reg, val);
342 /* -----------------------------------------------------------------
344 * -----------------------------------------------------------------*/
350 guard(spinlock_irqsave)(&chip->reg_lock);
359 dev_dbg(chip->card->dev, "Reg %02x was %02x, set to %02x\n",
365 /* --------------------------------------------------------------------
367 * --------------------------------------------------------------------*/
381 dev_err(chip->card->dev, "ESS Solo-1 reset failed\n");
391 2nd channel DAC asynchronous */
393 /* enable/select DMA channel and IRQ channel */
404 /* --------------------------------------------------------------------
406 * --------------------------------------------------------------------*/
439 struct snd_pcm_runtime *runtime = substream->runtime;
440 if (runtime->rate_num == clocks[0].num)
441 bits = 128 - runtime->rate_den;
443 bits = 256 - runtime->rate_den;
446 div0 = 256 - 7160000*20/(8*82*runtime->rate);
457 /* --------------------------------------------------------------------
459 * --------------------------------------------------------------------*/
464 outl(chip->dma2_start, SLIO_REG(chip, AUDIO2DMAADDR));
466 outw(chip->dma2_size, SLIO_REG(chip, AUDIO2DMACOUNT));
478 outl(chip->dma1_start, SLDM_REG(chip, DMAADDR));
479 outw(chip->dma1_size - 1, SLDM_REG(chip, DMACOUNT));
493 outl(chip->dma1_start, SLDM_REG(chip, DMAADDR));
494 chip->last_capture_dmaaddr = chip->dma1_start;
495 outw(chip->dma1_size - 1, SLDM_REG(chip, DMACOUNT));
500 /* ----------------------------------------------------------------------
514 chip->active |= ADC1;
519 chip->active &= ~ADC1;
522 return -EINVAL;
540 /* This two stage init gives the FIFO -> DAC connection time to
542 * no swapping of stereo channels. Report a bug if otherwise :-) */
544 chip->active |= DAC2;
550 chip->active &= ~DAC2;
553 return -EINVAL;
567 chip->active |= DAC1;
572 chip->active &= ~DAC1;
575 return -EINVAL;
584 switch (substream->number) {
591 return -EINVAL;
594 /* --------------------------------------------------------------------
595 * First channel for Extended Mode Audio 1 ADC Operation
596 * --------------------------------------------------------------------*/
600 struct snd_pcm_runtime *runtime = substream->runtime;
601 int u, is8, mono;
605 chip->dma1_size = size;
606 chip->dma1_start = runtime->dma_addr;
608 mono = (runtime->channels > 1) ? 0 : 1;
609 is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
610 u = snd_pcm_format_unsigned(runtime->format);
612 chip->dma1_shift = 2 - mono - is8;
617 snd_es1938_bits(chip, ESS_CMD_ANALOGCONTROL, 0x03, (mono ? 2 : 1));
622 count = 0x10000 - count;
631 (mono ? 0x40 : 0x08));
642 /* ------------------------------------------------------------------------------
643 * Second Audio channel DAC Operation
644 * ------------------------------------------------------------------------------*/
648 struct snd_pcm_runtime *runtime = substream->runtime;
649 int u, is8, mono;
653 chip->dma2_size = size;
654 chip->dma2_start = runtime->dma_addr;
656 mono = (runtime->channels > 1) ? 0 : 1;
657 is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
658 u = snd_pcm_format_unsigned(runtime->format);
660 chip->dma2_shift = 2 - mono - is8;
668 count = 0x10000 - count;
674 (mono ? 0 : 2) | (is8 ? 0 : 1));
685 struct snd_pcm_runtime *runtime = substream->runtime;
686 int u, is8, mono;
690 chip->dma1_size = size;
691 chip->dma1_start = runtime->dma_addr;
693 mono = (runtime->channels > 1) ? 0 : 1;
694 is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
695 u = snd_pcm_format_unsigned(runtime->format);
697 chip->dma1_shift = 2 - mono - is8;
699 count = 0x10000 - count;
704 snd_es1938_bits(chip, ESS_CMD_ANALOGCONTROL, 0x03, (mono ? 2 : 1));
715 0x90 | (mono ? 0x40 : 0x08) |
726 switch (substream->number) {
733 return -EINVAL;
739 - is the current DMA address in the valid DMA range ?
740 - is the sum of DMA address and DMA counter pointing to the last DMA byte ?
750 /* This stuff is *needed*, don't ask why - AB */
754 ptr = chip->dma1_size - 1 - new;
761 diff = chip->dma1_start + chip->dma1_size - ptr - count;
763 if (diff > 3 || ptr < chip->dma1_start
764 || ptr >= chip->dma1_start+chip->dma1_size)
765 ptr = chip->last_capture_dmaaddr; /* bad, use last saved */
767 chip->last_capture_dmaaddr = ptr; /* good, remember it */
769 ptr -= chip->dma1_start;
771 return ptr >> chip->dma1_shift;
779 ptr = chip->dma2_size - inw(SLIO_REG(chip, AUDIO2DMACOUNT));
781 ptr = inl(SLIO_REG(chip, AUDIO2DMAADDR)) - chip->dma2_start;
783 return ptr >> chip->dma2_shift;
792 /* This stuff is *needed*, don't ask why - AB */
796 ptr = chip->dma1_size - 1 - new;
798 ptr = inl(SLDM_REG(chip, DMAADDR)) - chip->dma1_start;
800 return ptr >> chip->dma1_shift;
805 switch (substream->number) {
812 return -EINVAL;
816 int channel, unsigned long pos,
819 struct snd_pcm_runtime *runtime = substream->runtime;
822 if (snd_BUG_ON(pos + count > chip->dma1_size))
823 return -EINVAL;
824 if (pos + count < chip->dma1_size) {
825 if (copy_to_iter(runtime->dma_area + pos + 1, count, dst) != count)
826 return -EFAULT;
828 if (copy_to_iter(runtime->dma_area + pos + 1, count - 1, dst) != count - 1)
829 return -EFAULT;
830 if (copy_to_iter(runtime->dma_area, 1, dst) != 1)
831 return -EFAULT;
836 /* ----------------------------------------------------------------------
838 * ----------------------------------------------------------------------*/
858 /* -----------------------------------------------------------------------
860 * -----------------------------------------------------------------------*/
884 struct snd_pcm_runtime *runtime = substream->runtime;
886 if (chip->playback2_substream)
887 return -EAGAIN;
888 chip->capture_substream = substream;
889 runtime->hw = snd_es1938_capture;
899 struct snd_pcm_runtime *runtime = substream->runtime;
901 switch (substream->number) {
903 chip->playback1_substream = substream;
906 if (chip->capture_substream)
907 return -EAGAIN;
908 chip->playback2_substream = substream;
912 return -EINVAL;
914 runtime->hw = snd_es1938_playback;
925 chip->capture_substream = NULL;
933 switch (substream->number) {
935 chip->playback1_substream = NULL;
938 chip->playback2_substream = NULL;
942 return -EINVAL;
969 err = snd_pcm_new(chip->card, "es-1938-1946", device, 2, 1, &pcm);
975 pcm->private_data = chip;
976 pcm->info_flags = 0;
977 strscpy(pcm->name, "ESS Solo-1");
980 &chip->pci->dev, 64*1024, 64*1024);
982 chip->pcm = pcm;
986 /* -------------------------------------------------------------------
1006 ucontrol->value.enumerated.item[0] = snd_es1938_mixer_read(chip, 0x1c) & 0x07;
1014 unsigned char val = ucontrol->value.enumerated.item[0];
1017 return -EINVAL;
1028 ucontrol->value.integer.value[0] = !!(val & 8);
1038 nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04;
1051 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1052 uinfo->count = 2;
1053 uinfo->value.integer.min = 0;
1054 uinfo->value.integer.max = 63;
1062 ucontrol->value.integer.value[0] = snd_es1938_mixer_read(chip, 0x61) & 0x3f;
1063 ucontrol->value.integer.value[1] = snd_es1938_mixer_read(chip, 0x63) & 0x3f;
1073 ucontrol->value.integer.value[0] = !(snd_es1938_mixer_read(chip, 0x61) & 0x40);
1074 ucontrol->value.integer.value[1] = !(snd_es1938_mixer_read(chip, 0x63) & 0x40);
1081 chip->master_volume = NULL;
1082 chip->master_switch = NULL;
1083 chip->hw_volume = NULL;
1084 chip->hw_switch = NULL;
1121 int mask = (kcontrol->private_value >> 16) & 0xff;
1123 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1124 uinfo->count = 1;
1125 uinfo->value.integer.min = 0;
1126 uinfo->value.integer.max = mask;
1134 int reg = kcontrol->private_value & 0xff;
1135 int shift = (kcontrol->private_value >> 8) & 0xff;
1136 int mask = (kcontrol->private_value >> 16) & 0xff;
1137 int invert = (kcontrol->private_value >> 24) & 0xff;
1141 ucontrol->value.integer.value[0] = (val >> shift) & mask;
1143 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1151 int reg = kcontrol->private_value & 0xff;
1152 int shift = (kcontrol->private_value >> 8) & 0xff;
1153 int mask = (kcontrol->private_value >> 16) & 0xff;
1154 int invert = (kcontrol->private_value >> 24) & 0xff;
1157 val = (ucontrol->value.integer.value[0] & mask);
1159 val = mask - val;
1182 int mask = (kcontrol->private_value >> 24) & 0xff;
1184 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1185 uinfo->count = 2;
1186 uinfo->value.integer.min = 0;
1187 uinfo->value.integer.max = mask;
1195 int left_reg = kcontrol->private_value & 0xff;
1196 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1197 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1198 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1199 int mask = (kcontrol->private_value >> 24) & 0xff;
1200 int invert = (kcontrol->private_value >> 22) & 1;
1208 ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
1209 ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
1211 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1212 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1221 int left_reg = kcontrol->private_value & 0xff;
1222 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1223 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1224 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1225 int mask = (kcontrol->private_value >> 24) & 0xff;
1226 int invert = (kcontrol->private_value >> 22) & 1;
1230 val1 = ucontrol->value.integer.value[0] & mask;
1231 val2 = ucontrol->value.integer.value[1] & mask;
1233 val1 = mask - val1;
1234 val2 = mask - val2;
1254 0, 54, TLV_DB_SCALE_ITEM(-3600, 50, 1),
1255 54, 63, TLV_DB_SCALE_ITEM(-900, 100, 0),
1259 0, 8, TLV_DB_SCALE_ITEM(-3300, 300, 1),
1260 8, 15, TLV_DB_SCALE_ITEM(-900, 150, 0),
1264 0, 8, TLV_DB_SCALE_ITEM(-3450, 300, 1),
1265 8, 15, TLV_DB_SCALE_ITEM(-1050, 150, 0),
1269 0, 8, TLV_DB_SCALE_ITEM(-2400, 300, 1),
1274 0, 8, TLV_DB_SCALE_ITEM(-3150, 300, 1),
1275 8, 15, TLV_DB_SCALE_ITEM(-750, 150, 0),
1306 ES1938_DOUBLE_TLV("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0,
1324 ES1938_DOUBLE_TLV("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0,
1334 ES1938_DOUBLE_TLV("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0,
1344 ES1938_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1347 .name = "3D Control - Switch",
1356 /* ---------------------------------------------------------------------------- */
1357 /* ---------------------------------------------------------------------------- */
1360 * initialize the chip - used by resume callback, too
1370 pci_set_master(chip->pci);
1373 pci_write_config_word(chip->pci, SL_PCI_LEGACYCONTROL, 0x805f);
1376 pci_write_config_word(chip->pci, SL_PCI_DDMACONTROL, chip->ddma_port | 1);
1379 pci_write_config_dword(chip->pci, SL_PCI_CONFIG, 0);
1403 struct es1938 *chip = card->private_data;
1409 /* save mixer-related registers */
1410 for (s = saved_regs, d = chip->saved_regs; *s; s++, d++)
1414 if (chip->irq >= 0) {
1415 free_irq(chip->irq, chip);
1416 chip->irq = -1;
1417 card->sync_irq = -1;
1426 struct es1938 *chip = card->private_data;
1430 if (request_irq(pci->irq, snd_es1938_interrupt,
1433 pci->irq);
1435 return -EIO;
1437 chip->irq = pci->irq;
1438 card->sync_irq = chip->irq;
1441 /* restore mixer-related registers */
1442 for (s = saved_regs, d = chip->saved_regs; *s; s++, d++) {
1460 chip->gameport = gp = gameport_allocate_port();
1462 dev_err(chip->card->dev,
1464 return -ENOMEM;
1468 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
1469 gameport_set_dev_parent(gp, &chip->pci->dev);
1470 gp->io = chip->game_port;
1479 if (chip->gameport) {
1480 gameport_unregister_port(chip->gameport);
1481 chip->gameport = NULL;
1485 static inline int snd_es1938_create_gameport(struct es1938 *chip) { return -ENOSYS; }
1491 struct es1938 *chip = card->private_data;
1495 if (chip->rmidi)
1500 if (chip->irq >= 0)
1501 free_irq(chip->irq, chip);
1507 struct es1938 *chip = card->private_data;
1515 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) {
1516 dev_err(card->dev,
1518 return -ENXIO;
1521 spin_lock_init(&chip->reg_lock);
1522 spin_lock_init(&chip->mixer_lock);
1523 chip->card = card;
1524 chip->pci = pci;
1525 chip->irq = -1;
1526 err = pcim_request_all_regions(pci, "ESS Solo-1");
1529 chip->io_port = pci_resource_start(pci, 0);
1530 chip->sb_port = pci_resource_start(pci, 1);
1531 chip->vc_port = pci_resource_start(pci, 2);
1532 chip->mpu_port = pci_resource_start(pci, 3);
1533 chip->game_port = pci_resource_start(pci, 4);
1534 /* still use non-managed irq handler as it's re-acquired at PM resume */
1535 if (request_irq(pci->irq, snd_es1938_interrupt, IRQF_SHARED,
1537 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1538 return -EBUSY;
1540 chip->irq = pci->irq;
1541 card->sync_irq = chip->irq;
1542 card->private_free = snd_es1938_free;
1543 dev_dbg(card->dev,
1545 chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port);
1547 chip->ddma_port = chip->vc_port + 0x00; /* fix from Thomas Sailer */
1553 /* --------------------------------------------------------------------
1555 * -------------------------------------------------------------------- */
1565 dev_dbg(chip->card->dev,
1566 "Es1938debug - interrupt status: =0x%x\n", status);
1572 dev_dbg(chip->card->dev,
1573 "Es1938debug - AUDIO channel 1 interrupt\n");
1574 dev_dbg(chip->card->dev,
1575 "Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n",
1577 dev_dbg(chip->card->dev,
1578 "Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n",
1580 dev_dbg(chip->card->dev,
1581 "Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n",
1587 if (chip->active & ADC1)
1588 snd_pcm_period_elapsed(chip->capture_substream);
1589 else if (chip->active & DAC1)
1590 snd_pcm_period_elapsed(chip->playback2_substream);
1596 dev_dbg(chip->card->dev,
1597 "Es1938debug - AUDIO channel 2 interrupt\n");
1598 dev_dbg(chip->card->dev,
1599 "Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n",
1601 dev_dbg(chip->card->dev,
1602 "Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n",
1609 if (chip->active & DAC2)
1610 snd_pcm_period_elapsed(chip->playback1_substream);
1617 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id);
1618 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id);
1620 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
1621 &chip->master_switch->id);
1622 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
1623 &chip->master_volume->id);
1632 // replacing the last 0 by 0x40 works for ESS-Solo1, but just doing nothing works as well!
1633 // andreas@flying-snail.de
1635 if (chip->rmidi) {
1637 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
1651 card = chip->card;
1653 strscpy(card->mixername, "ESS Solo-1");
1660 chip->master_volume = kctl;
1661 kctl->private_free = snd_es1938_hwv_free;
1664 chip->master_switch = kctl;
1665 kctl->private_free = snd_es1938_hwv_free;
1668 chip->hw_volume = kctl;
1669 kctl->private_free = snd_es1938_hwv_free;
1672 chip->hw_switch = kctl;
1673 kctl->private_free = snd_es1938_hwv_free;
1694 return -ENODEV;
1697 return -ENOENT;
1700 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1704 chip = card->private_data;
1709 return -ENODEV;
1715 strscpy(card->driver, "ES1938");
1716 strscpy(card->shortname, "ESS ES1938 (Solo-1)");
1717 sprintf(card->longname, "%s rev %i, irq %i",
1718 card->shortname,
1719 chip->revision,
1720 chip->irq);
1732 dev_err(card->dev, "OPL3 not detected at 0x%lx\n",
1743 chip->mpu_port,
1745 -1, &chip->rmidi) < 0) {
1746 dev_err(card->dev, "unable to initialize MPU-401\n");
1748 // this line is vital for MIDI interrupt handling on ess-solo1
1749 // andreas@flying-snail.de
1767 return snd_card_free_on_error(&pci->dev, __snd_es1938_probe(pci, pci_id));