Lines Matching +full:invert +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-or-later
28 for (i = 10000; i; i--) in snd_es1688_dsp_command()
33 dev_dbg(chip->card->dev, "%s: timeout (0x%x)\n", __func__, val); in snd_es1688_dsp_command()
41 for (i = 1000; i; i--) in snd_es1688_dsp_get_byte()
44 dev_dbg(chip->card->dev, "es1688 get byte failed: 0x%lx = 0x%x!!!\n", in snd_es1688_dsp_get_byte()
46 return -ENODEV; in snd_es1688_dsp_get_byte()
61 return -1; in snd_es1688_read()
63 return -1; in snd_es1688_read()
91 outb(3, ES1688P(chip, RESET)); /* valid only for ESS chips, SB -> 1 */ in snd_es1688_reset()
97 dev_dbg(chip->card->dev, "ess_reset at 0x%lx: failed!!!\n", in snd_es1688_reset()
98 chip->port); in snd_es1688_reset()
99 return -ENODEV; in snd_es1688_reset()
101 snd_es1688_dsp_command(chip, 0xc6); /* enable extended mode */ in snd_es1688_reset()
116 spin_lock_irqsave(&chip->reg_lock, flags); /* Some ESS1688 cards need this */ in snd_es1688_probe()
130 dev_dbg(chip->card->dev, "ESS: [0x%lx] reset failed... 0x%x\n", in snd_es1688_probe()
131 chip->port, inb(ES1688P(chip, READ))); in snd_es1688_probe()
132 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_probe()
133 return -ENODEV; in snd_es1688_probe()
137 for (i = 1000, major = minor = 0; i; i--) { in snd_es1688_probe()
147 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_probe()
149 dev_dbg(chip->card->dev, in snd_es1688_probe()
151 chip->port, major, minor); in snd_es1688_probe()
153 chip->version = (major << 8) | minor; in snd_es1688_probe()
154 if (!chip->version) in snd_es1688_probe()
155 return -ENODEV; /* probably SB */ in snd_es1688_probe()
157 switch (chip->version & 0xfff0) { in snd_es1688_probe()
159 dev_err(chip->card->dev, in snd_es1688_probe()
161 chip->port); in snd_es1688_probe()
162 return -ENODEV; in snd_es1688_probe()
166 dev_err(chip->card->dev, in snd_es1688_probe()
168 chip->port, chip->version); in snd_es1688_probe()
169 return -ENODEV; in snd_es1688_probe()
172 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_probe()
175 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_probe()
177 /* enable joystick, but disable OPL3 */ in snd_es1688_probe()
178 spin_lock_irqsave(&chip->mixer_lock, flags); in snd_es1688_probe()
180 spin_unlock_irqrestore(&chip->mixer_lock, flags); in snd_es1688_probe()
185 static int snd_es1688_init(struct snd_es1688 * chip, int enable) in snd_es1688_init() argument
187 static const int irqs[16] = {-1, -1, 0, -1, -1, 1, -1, 2, -1, 0, 3, -1, -1, -1, -1, -1}; in snd_es1688_init()
191 /* ok.. setup MPU-401 port and joystick and OPL3 */ in snd_es1688_init()
192 cfg = 0x01; /* enable joystick, but disable OPL3 */ in snd_es1688_init()
193 if (enable && chip->mpu_port >= 0x300 && chip->mpu_irq > 0 && chip->hardware != ES1688_HW_688) { in snd_es1688_init()
194 tmp = (chip->mpu_port & 0x0f0) >> 4; in snd_es1688_init()
196 switch (chip->mpu_irq) { in snd_es1688_init()
217 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_init()
219 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_init()
220 /* --- */ in snd_es1688_init()
221 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_init()
224 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_init()
225 if (enable) { in snd_es1688_init()
226 cfg = 0xf0; /* enable only DMA counter interrupt */ in snd_es1688_init()
227 irq_bits = irqs[chip->irq & 0x0f]; in snd_es1688_init()
229 dev_err(chip->card->dev, in snd_es1688_init()
231 chip->port, chip->irq); in snd_es1688_init()
236 return -EINVAL; in snd_es1688_init()
238 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_init()
240 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_init()
241 cfg = 0xf0; /* extended mode DMA enable */ in snd_es1688_init()
242 dma = chip->dma8; in snd_es1688_init()
244 dev_err(chip->card->dev, in snd_es1688_init()
246 chip->port, dma); in snd_es1688_init()
251 return -EINVAL; in snd_es1688_init()
257 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_init()
259 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_init()
261 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_init()
264 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_init()
266 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_init()
270 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_init()
300 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1688_set_rate()
303 if (runtime->rate_num == clocks[0].num) in snd_es1688_set_rate()
304 bits = 256 - runtime->rate_den; in snd_es1688_set_rate()
306 bits = 128 - runtime->rate_den; in snd_es1688_set_rate()
308 divider = 256 - 7160000*20/(8*82*runtime->rate); in snd_es1688_set_rate()
321 return -EINVAL; in snd_es1688_trigger()
323 spin_lock(&chip->reg_lock); in snd_es1688_trigger()
324 chip->trigger_value = value; in snd_es1688_trigger()
327 spin_unlock(&chip->reg_lock); in snd_es1688_trigger()
328 return -EINVAL; /* something is wrong */ in snd_es1688_trigger()
331 dev_dbg(chip->card->dev, "trigger: val = 0x%x, value = 0x%x\n", val, value); in snd_es1688_trigger()
332 dev_dbg(chip->card->dev, "trigger: pointer = 0x%x\n", in snd_es1688_trigger()
333 snd_dma_pointer(chip->dma8, chip->dma_size)); in snd_es1688_trigger()
336 spin_unlock(&chip->reg_lock); in snd_es1688_trigger()
344 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1688_playback_prepare()
348 chip->dma_size = size; in snd_es1688_playback_prepare()
349 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_playback_prepare()
353 snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->channels)); in snd_es1688_playback_prepare()
355 if (runtime->channels == 1) { in snd_es1688_playback_prepare()
356 if (snd_pcm_format_width(runtime->format) == 8) { in snd_es1688_playback_prepare()
368 if (snd_pcm_format_width(runtime->format) == 8) { in snd_es1688_playback_prepare()
383 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_playback_prepare()
384 /* --- */ in snd_es1688_playback_prepare()
385 count = -count; in snd_es1688_playback_prepare()
386 snd_dma_program(chip->dma8, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT); in snd_es1688_playback_prepare()
387 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_playback_prepare()
390 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_playback_prepare()
405 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1688_capture_prepare()
409 chip->dma_size = size; in snd_es1688_capture_prepare()
410 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_capture_prepare()
415 snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->channels)); in snd_es1688_capture_prepare()
417 if (runtime->channels == 1) { in snd_es1688_capture_prepare()
418 if (snd_pcm_format_width(runtime->format) == 8) { in snd_es1688_capture_prepare()
428 if (snd_pcm_format_width(runtime->format) == 8) { in snd_es1688_capture_prepare()
440 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_capture_prepare()
441 /* --- */ in snd_es1688_capture_prepare()
442 count = -count; in snd_es1688_capture_prepare()
443 snd_dma_program(chip->dma8, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT); in snd_es1688_capture_prepare()
444 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_capture_prepare()
447 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_capture_prepare()
462 if (chip->trigger_value == 0x05) /* ok.. playback is active */ in snd_es1688_interrupt()
463 snd_pcm_period_elapsed(chip->playback_substream); in snd_es1688_interrupt()
464 if (chip->trigger_value == 0x0f) /* ok.. capture is active */ in snd_es1688_interrupt()
465 snd_pcm_period_elapsed(chip->capture_substream); in snd_es1688_interrupt()
476 if (chip->trigger_value != 0x05) in snd_es1688_playback_pointer()
478 ptr = snd_dma_pointer(chip->dma8, chip->dma_size); in snd_es1688_playback_pointer()
479 return bytes_to_frames(substream->runtime, ptr); in snd_es1688_playback_pointer()
487 if (chip->trigger_value != 0x0f) in snd_es1688_capture_pointer()
489 ptr = snd_dma_pointer(chip->dma8, chip->dma_size); in snd_es1688_capture_pointer()
490 return bytes_to_frames(substream->runtime, ptr); in snd_es1688_capture_pointer()
540 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1688_playback_open()
542 if (chip->capture_substream != NULL) in snd_es1688_playback_open()
543 return -EAGAIN; in snd_es1688_playback_open()
544 chip->playback_substream = substream; in snd_es1688_playback_open()
545 runtime->hw = snd_es1688_playback; in snd_es1688_playback_open()
554 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1688_capture_open()
556 if (chip->playback_substream != NULL) in snd_es1688_capture_open()
557 return -EAGAIN; in snd_es1688_capture_open()
558 chip->capture_substream = substream; in snd_es1688_capture_open()
559 runtime->hw = snd_es1688_capture; in snd_es1688_capture_open()
569 chip->playback_substream = NULL; in snd_es1688_playback_close()
577 chip->capture_substream = NULL; in snd_es1688_capture_close()
583 if (chip->hardware != ES1688_HW_UNDEF) in snd_es1688_free()
585 release_and_free_resource(chip->res_port); in snd_es1688_free()
586 if (chip->irq >= 0) in snd_es1688_free()
587 free_irq(chip->irq, (void *) chip); in snd_es1688_free()
588 if (chip->dma8 >= 0) { in snd_es1688_free()
589 disable_dma(chip->dma8); in snd_es1688_free()
590 free_dma(chip->dma8); in snd_es1688_free()
597 struct snd_es1688 *chip = device->device_data; in snd_es1688_dev_free()
604 sprintf(tmp, "ES%s688 rev %i", chip->hardware == ES1688_HW_688 ? "" : "1", chip->version & 0x0f); in snd_es1688_chip_id()
624 return -ENOMEM; in snd_es1688_create()
625 chip->card = card; in snd_es1688_create()
626 chip->irq = -1; in snd_es1688_create()
627 chip->dma8 = -1; in snd_es1688_create()
628 chip->hardware = ES1688_HW_UNDEF; in snd_es1688_create()
630 chip->res_port = request_region(port + 4, 12, "ES1688"); in snd_es1688_create()
631 if (chip->res_port == NULL) { in snd_es1688_create()
632 dev_err(card->dev, "es1688: can't grab port 0x%lx\n", port + 4); in snd_es1688_create()
633 err = -EBUSY; in snd_es1688_create()
639 dev_err(card->dev, "es1688: can't grab IRQ %d\n", irq); in snd_es1688_create()
643 chip->irq = irq; in snd_es1688_create()
644 card->sync_irq = chip->irq; in snd_es1688_create()
648 dev_err(card->dev, "es1688: can't grab DMA8 %d\n", dma8); in snd_es1688_create()
651 chip->dma8 = dma8; in snd_es1688_create()
653 spin_lock_init(&chip->reg_lock); in snd_es1688_create()
654 spin_lock_init(&chip->mixer_lock); in snd_es1688_create()
655 chip->port = port; in snd_es1688_create()
659 chip->mpu_port = mpu_port; in snd_es1688_create()
660 chip->mpu_irq = mpu_irq; in snd_es1688_create()
661 chip->hardware = hardware; in snd_es1688_create()
707 pcm->private_data = chip; in snd_es1688_pcm()
708 pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX; in snd_es1688_pcm()
709 strcpy(pcm->name, snd_es1688_chip_id(chip)); in snd_es1688_pcm()
710 chip->pcm = pcm; in snd_es1688_pcm()
712 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, card->dev, in snd_es1688_pcm()
734 ucontrol->value.enumerated.item[0] = snd_es1688_mixer_read(chip, ES1688_REC_DEV) & 7; in snd_es1688_get_mux()
745 if (ucontrol->value.enumerated.item[0] > 8) in snd_es1688_put_mux()
746 return -EINVAL; in snd_es1688_put_mux()
747 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_put_mux()
749 nval = (ucontrol->value.enumerated.item[0] & 7) | (oval & ~15); in snd_es1688_put_mux()
753 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_put_mux()
757 #define ES1688_SINGLE(xname, xindex, reg, shift, mask, invert) \ argument
761 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
765 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_es1688_info_single()
767 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_es1688_info_single()
768 uinfo->count = 1; in snd_es1688_info_single()
769 uinfo->value.integer.min = 0; in snd_es1688_info_single()
770 uinfo->value.integer.max = mask; in snd_es1688_info_single()
778 int reg = kcontrol->private_value & 0xff; in snd_es1688_get_single()
779 int shift = (kcontrol->private_value >> 8) & 0xff; in snd_es1688_get_single()
780 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_es1688_get_single()
781 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_es1688_get_single() local
783 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_get_single()
784 ucontrol->value.integer.value[0] = (snd_es1688_mixer_read(chip, reg) >> shift) & mask; in snd_es1688_get_single()
785 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_get_single()
786 if (invert) in snd_es1688_get_single()
787 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; in snd_es1688_get_single()
795 int reg = kcontrol->private_value & 0xff; in snd_es1688_put_single()
796 int shift = (kcontrol->private_value >> 8) & 0xff; in snd_es1688_put_single()
797 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_es1688_put_single()
798 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_es1688_put_single() local
802 nval = (ucontrol->value.integer.value[0] & mask); in snd_es1688_put_single()
803 if (invert) in snd_es1688_put_single()
804 nval = mask - nval; in snd_es1688_put_single()
806 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_put_single()
812 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_put_single()
816 #define ES1688_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ argument
820 …reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
824 int mask = (kcontrol->private_value >> 24) & 0xff; in snd_es1688_info_double()
826 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_es1688_info_double()
827 uinfo->count = 2; in snd_es1688_info_double()
828 uinfo->value.integer.min = 0; in snd_es1688_info_double()
829 uinfo->value.integer.max = mask; in snd_es1688_info_double()
837 int left_reg = kcontrol->private_value & 0xff; in snd_es1688_get_double()
838 int right_reg = (kcontrol->private_value >> 8) & 0xff; in snd_es1688_get_double()
839 int shift_left = (kcontrol->private_value >> 16) & 0x07; in snd_es1688_get_double()
840 int shift_right = (kcontrol->private_value >> 19) & 0x07; in snd_es1688_get_double()
841 int mask = (kcontrol->private_value >> 24) & 0xff; in snd_es1688_get_double()
842 int invert = (kcontrol->private_value >> 22) & 1; in snd_es1688_get_double() local
845 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_get_double()
857 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_get_double()
858 ucontrol->value.integer.value[0] = (left >> shift_left) & mask; in snd_es1688_get_double()
859 ucontrol->value.integer.value[1] = (right >> shift_right) & mask; in snd_es1688_get_double()
860 if (invert) { in snd_es1688_get_double()
861 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; in snd_es1688_get_double()
862 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; in snd_es1688_get_double()
871 int left_reg = kcontrol->private_value & 0xff; in snd_es1688_put_double()
872 int right_reg = (kcontrol->private_value >> 8) & 0xff; in snd_es1688_put_double()
873 int shift_left = (kcontrol->private_value >> 16) & 0x07; in snd_es1688_put_double()
874 int shift_right = (kcontrol->private_value >> 19) & 0x07; in snd_es1688_put_double()
875 int mask = (kcontrol->private_value >> 24) & 0xff; in snd_es1688_put_double()
876 int invert = (kcontrol->private_value >> 22) & 1; in snd_es1688_put_double() local
880 val1 = ucontrol->value.integer.value[0] & mask; in snd_es1688_put_double()
881 val2 = ucontrol->value.integer.value[1] & mask; in snd_es1688_put_double()
882 if (invert) { in snd_es1688_put_double()
883 val1 = mask - val1; in snd_es1688_put_double()
884 val2 = mask - val2; in snd_es1688_put_double()
888 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1688_put_double()
926 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1688_put_double()
972 return -EINVAL; in snd_es1688_mixer()
974 strcpy(card->mixername, snd_es1688_chip_id(chip)); in snd_es1688_mixer()