Lines Matching +full:conversion +full:- +full:start +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0-or-later
9 * Rewritted from card-es1938.c source.
26 * until you start doing insane things like FM emulation and surround
27 * encoding. The codecs are almost always AC-97 compliant codecs,
88 #include <linux/dma-mapping.h>
102 #include <media/drv-intf/tea575x.h>
115 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */
118 static int total_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1024 };
119 static int pcm_substreams_p[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4 };
120 static int pcm_substreams_c[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1 };
122 static int use_pm[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
123 static int enable_mpu[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
127 static int radio_nr[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
142 MODULE_PARM_DESC(clock, "Clock on " CARD_NAME " soundcard. (0 = auto-detect)");
144 MODULE_PARM_DESC(use_pm, "Toggle power-management. (0 = off, 1 = on, 2 = auto)");
296 /* APU Modes: reg 0x00, bit 4-7 */
300 #define ESM_APU_16BITLINEAR 0x01 /* 16-Bit Linear Sample Player */
301 #define ESM_APU_16BITSTEREO 0x02 /* 16-Bit Stereo Sample Player */
302 #define ESM_APU_8BITLINEAR 0x03 /* 8-Bit Linear Sample Player */
303 #define ESM_APU_8BITSTEREO 0x04 /* 8-Bit Stereo Sample Player */
304 #define ESM_APU_8BITDIFF 0x05 /* 8-Bit Differential Sample Playrer */
311 #define ESM_APU_16BITPINGPONG 0x0C /* 16-Bit Ping-Pong Sample Player */
348 #define ESM_APU_WAVE64K_PAGE_SHIFT 8 /* most 8bit of wave start offset */
351 /* reg 0x05 - wave start offset */
352 /* reg 0x06 - wave end offset */
353 /* reg 0x07 - wave loop length */
364 /* bit 0-7 amplitude dest? */
502 int do_pm; /* power-management enabled */
570 outw(reg, chip->io_port + ESM_INDEX);
571 outw(data, chip->io_port + ESM_DATA);
572 chip->maestro_map[reg] = data;
577 guard(spinlock_irqsave)(&chip->reg_lock);
585 outw(reg, chip->io_port + ESM_INDEX);
586 chip->maestro_map[reg] = inw(chip->io_port + ESM_DATA);
588 return chip->maestro_map[reg];
593 guard(spinlock_irqsave)(&chip->reg_lock);
602 while (timeout-- > 0) {
603 if (!(inb(chip->io_port + ESM_AC97_INDEX) & 1))
607 dev_dbg(chip->card->dev, "ac97 timeout\n");
615 while (timeout-- > 0) {
616 if (!(inb(chip->io_port + ESM_AC97_INDEX) & 1))
619 dev_dbg(chip->card->dev, "ac97 timeout\n");
625 struct es1968 *chip = ac97->private_data;
630 outw(val, chip->io_port + ESM_AC97_DATA);
632 outb(reg, chip->io_port + ESM_AC97_INDEX);
639 struct es1968 *chip = ac97->private_data;
643 outb(reg | 0x80, chip->io_port + ESM_AC97_INDEX);
647 data = inw(chip->io_port + ESM_AC97_DATA);
662 dev_dbg(chip->card->dev, "APU register select failed. (Timeout)\n");
674 dev_dbg(chip->card->dev, "APU register set probably failed (Timeout)!\n");
682 chip->apu_map[channel][reg] = data;
690 guard(spinlock_irqsave)(&chip->reg_lock);
705 guard(spinlock_irqsave)(&chip->reg_lock);
713 guard(spinlock_irqsave),(&chip->reg_lock);
714 outl(reg, chip->io_port + ASSP_INDEX);
715 outl(value, chip->io_port + ASSP_DATA);
720 guard(spinlock_irqsave)(&chip->reg_lock);
721 outl(reg, chip->io_port + ASSP_INDEX);
722 return inl(chip->io_port + ASSP_DATA);
729 guard(spinlock_irqsave)(&chip->reg_lock);
730 outw(reg, chip->io_port + WC_INDEX);
731 outw(value, chip->io_port + WC_DATA);
736 guard(spinlock_irqsave)(&chip->reg_lock);
737 outw(reg, chip->io_port + WC_INDEX);
738 return inw(chip->io_port + WC_DATA);
765 if (chip->bob_freq > (ESS_SYSCLK >> (prescale + 9)))
771 prescale--;
776 /* now fine-tune the divider for best match */
778 if (chip->bob_freq >
785 prescale--;
787 divide--;
799 chip->bobclient++;
800 if (chip->bobclient == 1) {
801 chip->bob_freq = freq;
803 } else if (chip->bob_freq < freq) {
805 chip->bob_freq = freq;
813 chip->bobclient--;
814 if (chip->bobclient <= 0)
816 else if (chip->bob_freq > ESM_BOB_FREQ) {
820 list_for_each_entry(es, &chip->substream_list, list) {
821 if (max_freq < es->bob_freq)
822 max_freq = es->bob_freq;
824 if (max_freq != chip->bob_freq) {
826 chip->bob_freq = max_freq;
837 int freq = runtime->rate * 4;
838 if (es->fmt & ESS_FMT_STEREO)
840 if (es->fmt & ESS_FMT_16BIT)
842 freq /= es->frag_size;
857 u32 rate = (freq << 16) / chip->clock;
871 offset = apu_get_register(chip, es->apu[0], 5);
873 offset -= es->base[0];
897 guard(spinlock)(&chip->reg_lock);
898 __apu_set_register(chip, es->apu[0], 5, es->base[0]);
899 snd_es1968_trigger_apu(chip, es->apu[0], es->apu_mode[0]);
900 if (es->mode == ESM_MODE_CAPTURE) {
901 __apu_set_register(chip, es->apu[2], 5, es->base[2]);
902 snd_es1968_trigger_apu(chip, es->apu[2], es->apu_mode[2]);
904 if (es->fmt & ESS_FMT_STEREO) {
905 __apu_set_register(chip, es->apu[1], 5, es->base[1]);
906 snd_es1968_trigger_apu(chip, es->apu[1], es->apu_mode[1]);
907 if (es->mode == ESM_MODE_CAPTURE) {
908 __apu_set_register(chip, es->apu[3], 5, es->base[3]);
909 snd_es1968_trigger_apu(chip, es->apu[3], es->apu_mode[3]);
916 guard(spinlock)(&chip->reg_lock);
917 snd_es1968_trigger_apu(chip, es->apu[0], 0);
918 snd_es1968_trigger_apu(chip, es->apu[1], 0);
919 if (es->mode == ESM_MODE_CAPTURE) {
920 snd_es1968_trigger_apu(chip, es->apu[2], 0);
921 snd_es1968_trigger_apu(chip, es->apu[3], 0);
929 u32 tmpval = (addr - 0x10) & 0xFFF8;
932 if (!(es->fmt & ESS_FMT_16BIT))
934 if (es->fmt & ESS_FMT_STEREO)
939 wave_set_register(chip, es->apu[channel] << 3, tmpval);
941 es->wc_map[channel] = tmpval;
954 size = es->dma_size >> es->wav_shift;
956 if (es->fmt & ESS_FMT_STEREO)
960 apu = es->apu[channel];
962 snd_es1968_program_wavecache(chip, es, channel, es->memory->buf.addr, 0);
965 pa = es->memory->buf.addr;
966 pa -= chip->dma.addr;
971 if (es->fmt & ESS_FMT_STEREO) {
975 if (es->fmt & ESS_FMT_16BIT)
981 es->base[channel] = pa & 0xFFFF;
1003 if (es->fmt & ESS_FMT_16BIT)
1004 es->apu_mode[channel] = ESM_APU_16BITLINEAR;
1006 es->apu_mode[channel] = ESM_APU_8BITLINEAR;
1008 if (es->fmt & ESS_FMT_STEREO) {
1013 and not the APU Regs 4-5. */
1016 es->apu_mode[channel] += 1; /* stereo */
1021 scoped_guard(spinlock_irqsave, &chip->reg_lock) {
1023 outw(1, chip->io_port + 0x04);
1025 outw(inw(chip->io_port + ESM_PORT_HOST_IRQ) | ESM_HIRQ_DSIE, chip->io_port + ESM_PORT_HOST_IRQ);
1028 freq = runtime->rate;
1036 if (!(es->fmt & ESS_FMT_16BIT) && !(es->fmt & ESS_FMT_STEREO))
1042 snd_es1968_apu_set_freq(chip, es->apu[0], freq);
1043 snd_es1968_apu_set_freq(chip, es->apu[1], freq);
1051 int i, apu = es->apu[channel];
1053 es->apu_mode[channel] = mode;
1059 pa -= chip->dma.addr;
1064 es->base[channel] = pa & 0xFFFF;
1065 pa |= 0x00400000; /* bit 22 -> System RAM */
1098 size = es->dma_size >> es->wav_shift;
1111 /* parallel in crap, see maestro reg 0xC [8-11] */
1113 es->mixbuf->buf.addr, ESM_MIXBUF_SIZE/4, /* in words */
1116 init_capture_apu(chip, es, 0, es->memory->buf.addr, size,
1117 ESM_APU_SRCONVERTOR, es->apu[2]);
1118 if (es->fmt & ESS_FMT_STEREO) {
1121 es->mixbuf->buf.addr + ESM_MIXBUF_SIZE/2,
1126 es->memory->buf.addr + size*2, size,
1127 ESM_APU_SRCONVERTOR, es->apu[3]);
1130 freq = runtime->rate;
1131 /* Sample Rate conversion APUs don't like 0x10000 for their rate */
1140 snd_es1968_apu_set_freq(chip, es->apu[0], freq);
1141 snd_es1968_apu_set_freq(chip, es->apu[1], freq);
1145 snd_es1968_apu_set_freq(chip, es->apu[2], freq);
1146 snd_es1968_apu_set_freq(chip, es->apu[3], freq);
1148 guard(spinlock_irqsave)(&chip->reg_lock);
1150 outw(1, chip->io_port + 0x04);
1152 outw(inw(chip->io_port + ESM_PORT_HOST_IRQ) | ESM_HIRQ_DSIE, chip->io_port + ESM_PORT_HOST_IRQ);
1162 struct snd_pcm_runtime *runtime = substream->runtime;
1163 struct esschan *es = runtime->private_data;
1165 es->dma_size = snd_pcm_lib_buffer_bytes(substream);
1166 es->frag_size = snd_pcm_lib_period_bytes(substream);
1168 es->wav_shift = 1; /* maestro handles always 16bit */
1169 es->fmt = 0;
1170 if (snd_pcm_format_width(runtime->format) == 16)
1171 es->fmt |= ESS_FMT_16BIT;
1172 if (runtime->channels > 1) {
1173 es->fmt |= ESS_FMT_STEREO;
1174 if (es->fmt & ESS_FMT_16BIT) /* 8bit is already word shifted */
1175 es->wav_shift++;
1177 es->bob_freq = snd_es1968_calc_bob_rate(chip, es, runtime);
1179 switch (es->mode) {
1194 struct esschan *es = substream->runtime->private_data;
1196 guard(spinlock)(&chip->substream_lock);
1200 if (es->running)
1202 snd_es1968_bob_inc(chip, es->bob_freq);
1203 es->count = 0;
1204 es->hwptr = 0;
1206 es->running = 1;
1210 if (! es->running)
1213 es->running = 0;
1223 struct esschan *es = substream->runtime->private_data;
1226 ptr = snd_es1968_get_dma_ptr(chip, es) << es->wav_shift;
1228 return bytes_to_frames(substream->runtime, ptr % es->dma_size);
1285 guard(mutex)(&chip->memory_mutex);
1286 list_for_each_entry(buf, &chip->buf_list, list) {
1287 if (buf->empty && buf->buf.bytes > max_size)
1288 max_size = buf->buf.bytes;
1301 guard(mutex)(&chip->memory_mutex);
1302 list_for_each_entry(buf, &chip->buf_list, list) {
1303 if (buf->empty && buf->buf.bytes >= size)
1309 if (buf->buf.bytes > size) {
1313 chunk->buf = buf->buf;
1314 chunk->buf.bytes -= size;
1315 chunk->buf.area += size;
1316 chunk->buf.addr += size;
1317 chunk->empty = 1;
1318 buf->buf.bytes = size;
1319 list_add(&chunk->list, &buf->list);
1321 buf->empty = 0;
1330 guard(mutex)(&chip->memory_mutex);
1331 buf->empty = 1;
1332 if (buf->list.prev != &chip->buf_list) {
1333 chunk = list_entry(buf->list.prev, struct esm_memory, list);
1334 if (chunk->empty) {
1335 chunk->buf.bytes += buf->buf.bytes;
1336 list_del(&buf->list);
1341 if (buf->list.next != &chip->buf_list) {
1342 chunk = list_entry(buf->list.next, struct esm_memory, list);
1343 if (chunk->empty) {
1344 buf->buf.bytes += chunk->buf.bytes;
1345 list_del(&chunk->list);
1355 if (! chip->dma.area)
1357 snd_dma_free_pages(&chip->dma);
1358 while ((p = chip->buf_list.next) != &chip->buf_list) {
1372 &chip->pci->dev,
1373 chip->total_bufsize, &chip->dma);
1374 if (err < 0 || ! chip->dma.area) {
1375 dev_err(chip->card->dev,
1377 chip->total_bufsize);
1378 return -ENOMEM;
1380 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) {
1381 snd_dma_free_pages(&chip->dma);
1382 dev_err(chip->card->dev, "DMA buffer beyond 256MB.\n");
1383 return -ENOMEM;
1386 INIT_LIST_HEAD(&chip->buf_list);
1391 return -ENOMEM;
1393 memset(chip->dma.area, 0, ESM_MEM_ALIGN);
1394 chunk->buf = chip->dma;
1395 chunk->buf.area += ESM_MEM_ALIGN;
1396 chunk->buf.addr += ESM_MEM_ALIGN;
1397 chunk->buf.bytes -= ESM_MEM_ALIGN;
1398 chunk->empty = 1;
1399 list_add(&chunk->list, &chip->buf_list);
1405 /* buffer is extracted from the pre-allocated memory chunk */
1410 struct snd_pcm_runtime *runtime = substream->runtime;
1411 struct esschan *chan = runtime->private_data;
1414 if (chan->memory) {
1415 if (chan->memory->buf.bytes >= size) {
1416 runtime->dma_bytes = size;
1419 snd_es1968_free_memory(chip, chan->memory);
1421 chan->memory = snd_es1968_new_memory(chip, size);
1422 if (chan->memory == NULL) {
1423 dev_dbg(chip->card->dev,
1425 return -ENOMEM;
1427 snd_pcm_set_runtime_buffer(substream, &chan->memory->buf);
1435 struct snd_pcm_runtime *runtime = substream->runtime;
1438 if (runtime->private_data == NULL)
1440 chan = runtime->private_data;
1441 if (chan->memory) {
1442 snd_es1968_free_memory(chip, chan->memory);
1443 chan->memory = NULL;
1457 if (chip->apu[apu] == ESM_APU_FREE &&
1458 chip->apu[apu + 1] == ESM_APU_FREE) {
1459 chip->apu[apu] = chip->apu[apu + 1] = type;
1463 return -EBUSY;
1471 chip->apu[apu] = chip->apu[apu + 1] = ESM_APU_FREE;
1482 struct snd_pcm_runtime *runtime = substream->runtime;
1494 return -ENOMEM;
1497 es->apu[0] = apu1;
1498 es->apu[1] = apu1 + 1;
1499 es->apu_mode[0] = 0;
1500 es->apu_mode[1] = 0;
1501 es->running = 0;
1502 es->substream = substream;
1503 es->mode = ESM_MODE_PLAY;
1505 runtime->private_data = es;
1506 runtime->hw = snd_es1968_playback;
1507 runtime->hw.buffer_bytes_max = runtime->hw.period_bytes_max =
1510 guard(spinlock_irq)(&chip->substream_lock);
1511 list_add(&es->list, &chip->substream_list);
1518 struct snd_pcm_runtime *runtime = substream->runtime;
1536 return -ENOMEM;
1539 es->apu[0] = apu1;
1540 es->apu[1] = apu1 + 1;
1541 es->apu[2] = apu2;
1542 es->apu[3] = apu2 + 1;
1543 es->apu_mode[0] = 0;
1544 es->apu_mode[1] = 0;
1545 es->apu_mode[2] = 0;
1546 es->apu_mode[3] = 0;
1547 es->running = 0;
1548 es->substream = substream;
1549 es->mode = ESM_MODE_CAPTURE;
1552 es->mixbuf = snd_es1968_new_memory(chip, ESM_MIXBUF_SIZE);
1553 if (!es->mixbuf) {
1557 return -ENOMEM;
1559 memset(es->mixbuf->buf.area, 0, ESM_MIXBUF_SIZE);
1561 runtime->private_data = es;
1562 runtime->hw = snd_es1968_capture;
1563 runtime->hw.buffer_bytes_max = runtime->hw.period_bytes_max =
1564 calc_available_memory_size(chip) - 1024; /* keep MIXBUF size */
1569 guard(spinlock_irq)(&chip->substream_lock);
1570 list_add(&es->list, &chip->substream_list);
1580 if (substream->runtime->private_data == NULL)
1582 es = substream->runtime->private_data;
1583 scoped_guard(spinlock_irq, &chip->substream_lock) {
1584 list_del(&es->list);
1586 snd_es1968_free_apu_pair(chip, es->apu[0]);
1597 if (substream->runtime->private_data == NULL)
1599 es = substream->runtime->private_data;
1600 scoped_guard(spinlock_irq, &chip->substream_lock) {
1601 list_del(&es->list);
1603 snd_es1968_free_memory(chip, es->mixbuf);
1604 snd_es1968_free_apu_pair(chip, es->apu[0]);
1605 snd_es1968_free_apu_pair(chip, es->apu[2]);
1645 if (chip->clock == 0)
1646 chip->clock = 48000; /* default clock value */
1651 dev_err(chip->card->dev, "Hmm, cannot find empty APU pair!?\n");
1656 dev_warn(chip->card->dev,
1657 "cannot allocate dma buffer - using default clock %d\n",
1658 chip->clock);
1663 memset(memory->buf.area, 0, CLOCK_MEASURE_BUFSIZE);
1665 wave_set_register(chip, apu << 3, (memory->buf.addr - 0x10) & 0xfff8);
1667 pa = (unsigned int)((memory->buf.addr - chip->dma.addr) >> 1);
1683 scoped_guard(spinlock_irq, &chip->reg_lock) {
1684 outw(1, chip->io_port + 0x04); /* clear WP interrupts */
1685 outw(inw(chip->io_port + ESM_PORT_HOST_IRQ) | ESM_HIRQ_DSIE, chip->io_port + ESM_PORT_HOST_IRQ); /* enable WP ints */
1688 snd_es1968_apu_set_freq(chip, apu, ((unsigned int)48000 << 16) / chip->clock); /* 48000 Hz */
1690 chip->in_measurement = 1;
1691 chip->measure_apu = apu;
1692 scoped_guard(spinlock_irq, &chip->reg_lock) {
1699 scoped_guard(spinlock_irq, &chip->reg_lock) {
1704 chip->in_measurement = 0;
1708 offset -= (pa & 0xffff);
1710 offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2);
1715 dev_err(chip->card->dev, "?? calculation error..\n");
1721 chip->clock = (chip->clock * offset) / 48000;
1723 dev_info(chip->card->dev, "clocking to %d\n", chip->clock);
1735 struct es1968 *esm = pcm->private_data;
1737 esm->pcm = NULL;
1752 wave_set_register(chip, 0x01FC, chip->dma.addr >> 12);
1753 wave_set_register(chip, 0x01FD, chip->dma.addr >> 12);
1754 wave_set_register(chip, 0x01FE, chip->dma.addr >> 12);
1755 wave_set_register(chip, 0x01FF, chip->dma.addr >> 12);
1757 err = snd_pcm_new(chip->card, "ESS Maestro", device,
1758 chip->playback_streams,
1759 chip->capture_streams, &pcm);
1763 pcm->private_data = chip;
1764 pcm->private_free = snd_es1968_pcm_free;
1769 pcm->info_flags = 0;
1771 strscpy(pcm->name, "ESS Maestro");
1773 chip->pcm = pcm;
1788 diff = (cp1 > cp2 ? cp1 - cp2 : cp2 - cp1);
1801 struct snd_pcm_substream *subs = es->substream;
1803 if (subs == NULL || !es->running)
1806 hwptr = snd_es1968_get_dma_ptr(chip, es) << es->wav_shift;
1807 hwptr %= es->dma_size;
1809 diff = (es->dma_size + hwptr - es->hwptr) % es->dma_size;
1811 es->hwptr = hwptr;
1812 es->count += diff;
1814 if (es->count > es->frag_size) {
1815 spin_unlock(&chip->substream_lock);
1817 spin_lock(&chip->substream_lock);
1818 es->count %= es->frag_size;
1824 generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7
1834 x = inb(chip->io_port + 0x1c) & 0xee;
1836 outb(0x88, chip->io_port + 0x1c);
1837 outb(0x88, chip->io_port + 0x1d);
1838 outb(0x88, chip->io_port + 0x1e);
1839 outb(0x88, chip->io_port + 0x1f);
1841 if (chip->in_suspend)
1845 if (! chip->master_switch || ! chip->master_volume)
1848 val = snd_ac97_read(chip->ac97, AC97_MASTER);
1857 val--;
1859 val -= 0x0100;
1869 if (snd_ac97_update(chip->ac97, AC97_MASTER, val))
1870 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
1871 &chip->master_volume->id);
1873 if (!chip->input_dev)
1885 /* counters increased by 1 -> volume up */
1889 /* counters decreased by 1 -> volume down */
1895 input_report_key(chip->input_dev, val, 1);
1896 input_sync(chip->input_dev);
1897 input_report_key(chip->input_dev, val, 0);
1898 input_sync(chip->input_dev);
1911 event = inb(chip->io_port + 0x1A);
1915 outw(inw(chip->io_port + 4) & 1, chip->io_port + 4);
1918 schedule_work(&chip->hwvol_work);
1921 outb(0xFF, chip->io_port + 0x1A);
1923 if ((event & ESM_MPU401_IRQ) && chip->rmidi) {
1924 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
1929 scoped_guard(spinlock, &chip->substream_lock) {
1930 list_for_each_entry(es, &chip->substream_list, list) {
1931 if (es->running) {
1933 if (es->fmt & ESS_FMT_STEREO)
1938 if (chip->in_measurement) {
1939 unsigned int curp = __apu_get_register(chip, chip->measure_apu, 5);
1940 if (curp < chip->measure_lastpos)
1941 chip->measure_count++;
1942 chip->measure_lastpos = curp;
1964 err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus);
1967 pbus->no_vra = 1; /* ES1968 doesn't need VRA */
1971 err = snd_ac97_mixer(pbus, &ac97, &chip->ac97);
1977 chip->master_switch = snd_ctl_find_id_mixer(chip->card,
1979 chip->master_volume = snd_ctl_find_id_mixer(chip->card,
1992 unsigned long ioaddr = chip->io_port;
2010 pci_read_config_word(chip->pci, 0x58, &w); /* something magical with gpio and bus arb. */
2011 pci_read_config_dword(chip->pci, PCI_SUBSYSTEM_VENDOR_ID, &vend);
2041 dev_info(chip->card->dev, "trying software reset\n");
2099 chip->io_port + ESM_PORT_HOST_IRQ);
2101 outw(0x0000, chip->io_port + ESM_PORT_HOST_IRQ);
2110 struct pci_dev *pci = chip->pci;
2112 unsigned long iobase = chip->io_port;
2233 /* Write 0 into the buffer area 0x1E0->1EF */
2238 * 0x1D0-0x1DF too.*/
2270 /* Wave cache control on - test off, sg off,
2303 if (chip->rmidi)
2305 outb(w, chip->io_port + 0x1A);
2306 outw(w, chip->io_port + ESM_PORT_HOST_IRQ);
2315 struct es1968 *chip = card->private_data;
2317 if (! chip->do_pm)
2320 chip->in_suspend = 1;
2321 cancel_work_sync(&chip->hwvol_work);
2323 snd_ac97_suspend(chip->ac97);
2331 struct es1968 *chip = card->private_data;
2334 if (! chip->do_pm)
2340 if (chip->dma.addr) {
2342 wave_set_register(chip, 0x01FC, chip->dma.addr >> 12);
2348 snd_ac97_resume(chip->ac97);
2350 list_for_each_entry(es, &chip->substream_list, list) {
2351 switch (es->mode) {
2353 snd_es1968_playback_setup(chip, es, es->substream->runtime);
2356 snd_es1968_capture_setup(chip, es, es->substream->runtime);
2361 /* start timer again */
2362 if (chip->bobclient)
2366 chip->in_suspend = 0;
2381 return -ENODEV;
2383 r = devm_request_region(&chip->pci->dev, JOYSTICK_ADDR, 8,
2386 return -EBUSY;
2388 chip->gameport = gp = gameport_allocate_port();
2390 dev_err(chip->card->dev,
2392 return -ENOMEM;
2395 pci_read_config_word(chip->pci, ESM_LEGACY_AUDIO_CONTROL, &val);
2396 pci_write_config_word(chip->pci, ESM_LEGACY_AUDIO_CONTROL, val | 0x04);
2399 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
2400 gameport_set_dev_parent(gp, &chip->pci->dev);
2401 gp->io = JOYSTICK_ADDR;
2410 if (chip->gameport) {
2411 gameport_unregister_port(chip->gameport);
2412 chip->gameport = NULL;
2416 static inline int snd_es1968_create_gameport(struct es1968 *chip, int dev) { return -ENOSYS; }
2426 input_dev = devm_input_allocate_device(&chip->pci->dev);
2428 return -ENOMEM;
2430 snprintf(chip->phys, sizeof(chip->phys), "pci-%s/input0",
2431 pci_name(chip->pci));
2433 input_dev->name = chip->card->driver;
2434 input_dev->phys = chip->phys;
2435 input_dev->id.bustype = BUS_PCI;
2436 input_dev->id.vendor = chip->pci->vendor;
2437 input_dev->id.product = chip->pci->device;
2438 input_dev->dev.parent = &chip->pci->dev;
2440 __set_bit(EV_KEY, input_dev->evbit);
2441 __set_bit(KEY_MUTE, input_dev->keybit);
2442 __set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
2443 __set_bit(KEY_VOLUMEUP, input_dev->keybit);
2449 chip->input_dev = input_dev;
2468 { .data = 6, .clk = 7, .wren = 8, .most = 9, .name = "SF64-PCE2" },
2473 (&snd_es1968_tea575x_gpios[(chip)->tea575x_tuner])
2478 struct es1968 *chip = tea->private_data;
2486 outw(val, chip->io_port + GPIO_DATA);
2491 struct es1968 *chip = tea->private_data;
2493 u16 val = inw(chip->io_port + GPIO_DATA);
2506 struct es1968 *chip = tea->private_data;
2507 unsigned long io = chip->io_port + GPIO_DATA;
2533 struct es1968 *chip = card->private_data;
2535 cancel_work_sync(&chip->hwvol_work);
2537 if (chip->io_port) {
2538 outw(1, chip->io_port + 0x04); /* clear WP interrupts */
2539 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */
2543 snd_tea575x_exit(&chip->tea);
2544 v4l2_device_unregister(&chip->v4l2_dev);
2563 { TYPE_MAESTRO2, 0x125d }, /* a PCI card, e.g. SF64-PCE2 */
2579 struct es1968 *chip = card->private_data;
2587 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) {
2588 dev_err(card->dev,
2590 return -ENXIO;
2594 chip->type = chip_type;
2595 spin_lock_init(&chip->reg_lock);
2596 spin_lock_init(&chip->substream_lock);
2597 INIT_LIST_HEAD(&chip->buf_list);
2598 INIT_LIST_HEAD(&chip->substream_list);
2599 mutex_init(&chip->memory_mutex);
2600 INIT_WORK(&chip->hwvol_work, es1968_update_hw_volume);
2601 chip->card = card;
2602 chip->pci = pci;
2603 chip->irq = -1;
2604 chip->total_bufsize = total_bufsize; /* in bytes */
2605 chip->playback_streams = play_streams;
2606 chip->capture_streams = capt_streams;
2611 chip->io_port = pci_resource_start(pci, 0);
2612 if (devm_request_irq(&pci->dev, pci->irq, snd_es1968_interrupt,
2614 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2615 return -EBUSY;
2617 chip->irq = pci->irq;
2618 card->sync_irq = chip->irq;
2619 card->private_free = snd_es1968_free;
2623 chip->maestro_map[i] = 0;
2627 chip->apu[i] = ESM_APU_FREE;
2633 /* disable power-management if not on the allowlist */
2635 pci_read_config_word(chip->pci, PCI_SUBSYSTEM_VENDOR_ID, &vend);
2637 if (chip->type == pm_allowlist[i].type &&
2645 dev_info(card->dev, "not attempting power management.\n");
2649 chip->do_pm = do_pm;
2654 /* don't play with GPIOs on laptops */
2655 if (chip->pci->subsystem_vendor != 0x125d)
2657 err = v4l2_device_register(&pci->dev, &chip->v4l2_dev);
2660 chip->tea.v4l2_dev = &chip->v4l2_dev;
2661 chip->tea.private_data = chip;
2662 chip->tea.radio_nr = radio_nr;
2663 chip->tea.ops = &snd_es1968_tea_ops;
2664 sprintf(chip->tea.bus_info, "PCI:%s", pci_name(pci));
2666 chip->tea575x_tuner = i;
2667 if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) {
2668 dev_info(card->dev, "detected TEA575x radio type %s\n",
2669 get_tea575x_gpio(chip)->name);
2670 strscpy(chip->tea.card, get_tea575x_gpio(chip)->name,
2671 sizeof(chip->tea.card));
2692 return -ENODEV;
2695 return -ENOENT;
2698 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2702 chip = card->private_data;
2712 pci_id->driver_data,
2718 switch (chip->type) {
2720 strscpy(card->driver, "ES1978");
2721 strscpy(card->shortname, "ESS ES1978 (Maestro 2E)");
2724 strscpy(card->driver, "ES1968");
2725 strscpy(card->shortname, "ESS ES1968 (Maestro 2)");
2728 strscpy(card->driver, "ESM1");
2729 strscpy(card->shortname, "ESS Maestro 1");
2744 pci_read_config_word(chip->pci, PCI_SUBSYSTEM_VENDOR_ID, &vend);
2746 if (chip->type == mpu_denylist[i].type &&
2755 chip->io_port + ESM_MPU401_PORT,
2758 -1, &chip->rmidi);
2760 dev_warn(card->dev, "skipping MPU-401 MIDI support..\n");
2768 dev_warn(card->dev,
2774 chip->clock = clock[dev];
2775 if (! chip->clock)
2778 sprintf(card->longname, "%s at 0x%lx, irq %i",
2779 card->shortname, chip->io_port, chip->irq);
2792 return snd_card_free_on_error(&pci->dev, __snd_es1968_probe(pci, pci_id));