Lines Matching +full:- +full:33000
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 ad1816a.c - lowlevel code for Analog Devices AD1816A chip.
4 Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
24 for (timeout = 1000; timeout-- > 0; udelay(10)) in snd_ad1816a_busy_wait()
28 dev_warn(chip->card->dev, "chip busy.\n"); in snd_ad1816a_busy_wait()
29 return -EBUSY; in snd_ad1816a_busy_wait()
101 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_open()
103 if (chip->mode & mode) { in snd_ad1816a_open()
104 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_open()
105 return -EAGAIN; in snd_ad1816a_open()
127 chip->mode |= mode; in snd_ad1816a_open()
129 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_open()
137 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_close()
158 chip->mode &= ~mode; in snd_ad1816a_close()
159 if (!(chip->mode & AD1816A_MODE_OPEN)) in snd_ad1816a_close()
160 chip->mode = 0; in snd_ad1816a_close()
162 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_close()
174 spin_lock(&chip->lock); in snd_ad1816a_trigger()
186 spin_unlock(&chip->lock); in snd_ad1816a_trigger()
189 dev_warn(chip->card->dev, "invalid trigger mode 0x%x.\n", what); in snd_ad1816a_trigger()
190 error = -EINVAL; in snd_ad1816a_trigger()
214 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ad1816a_playback_prepare()
217 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_playback_prepare()
219 chip->p_dma_size = size = snd_pcm_lib_buffer_bytes(substream); in snd_ad1816a_playback_prepare()
223 snd_dma_program(chip->dma1, runtime->dma_addr, size, in snd_ad1816a_playback_prepare()
226 rate = runtime->rate; in snd_ad1816a_playback_prepare()
227 if (chip->clock_freq) in snd_ad1816a_playback_prepare()
228 rate = (rate * 33000) / chip->clock_freq; in snd_ad1816a_playback_prepare()
232 snd_ad1816a_get_format(chip, runtime->format, in snd_ad1816a_playback_prepare()
233 runtime->channels)); in snd_ad1816a_playback_prepare()
236 snd_pcm_lib_period_bytes(substream) / 4 - 1); in snd_ad1816a_playback_prepare()
238 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_playback_prepare()
246 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ad1816a_capture_prepare()
249 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_capture_prepare()
251 chip->c_dma_size = size = snd_pcm_lib_buffer_bytes(substream); in snd_ad1816a_capture_prepare()
255 snd_dma_program(chip->dma2, runtime->dma_addr, size, in snd_ad1816a_capture_prepare()
258 rate = runtime->rate; in snd_ad1816a_capture_prepare()
259 if (chip->clock_freq) in snd_ad1816a_capture_prepare()
260 rate = (rate * 33000) / chip->clock_freq; in snd_ad1816a_capture_prepare()
264 snd_ad1816a_get_format(chip, runtime->format, in snd_ad1816a_capture_prepare()
265 runtime->channels)); in snd_ad1816a_capture_prepare()
268 snd_pcm_lib_period_bytes(substream) / 4 - 1); in snd_ad1816a_capture_prepare()
270 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_capture_prepare()
279 if (!(chip->mode & AD1816A_MODE_PLAYBACK)) in snd_ad1816a_playback_pointer()
281 ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size); in snd_ad1816a_playback_pointer()
282 return bytes_to_frames(substream->runtime, ptr); in snd_ad1816a_playback_pointer()
289 if (!(chip->mode & AD1816A_MODE_CAPTURE)) in snd_ad1816a_capture_pointer()
291 ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size); in snd_ad1816a_capture_pointer()
292 return bytes_to_frames(substream->runtime, ptr); in snd_ad1816a_capture_pointer()
301 spin_lock(&chip->lock); in snd_ad1816a_interrupt()
303 spin_unlock(&chip->lock); in snd_ad1816a_interrupt()
305 if ((status & AD1816A_PLAYBACK_IRQ_PENDING) && chip->playback_substream) in snd_ad1816a_interrupt()
306 snd_pcm_period_elapsed(chip->playback_substream); in snd_ad1816a_interrupt()
308 if ((status & AD1816A_CAPTURE_IRQ_PENDING) && chip->capture_substream) in snd_ad1816a_interrupt()
309 snd_pcm_period_elapsed(chip->capture_substream); in snd_ad1816a_interrupt()
311 if ((status & AD1816A_TIMER_IRQ_PENDING) && chip->timer) in snd_ad1816a_interrupt()
312 snd_timer_interrupt(chip->timer, chip->timer->sticks); in snd_ad1816a_interrupt()
314 spin_lock(&chip->lock); in snd_ad1816a_interrupt()
316 spin_unlock(&chip->lock); in snd_ad1816a_interrupt()
386 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_timer_start()
391 timer->sticks & 0xffff); in snd_ad1816a_timer_start()
396 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_timer_start()
404 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_timer_stop()
409 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_timer_stop()
427 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ad1816a_playback_open()
433 runtime->hw = snd_ad1816a_playback; in snd_ad1816a_playback_open()
434 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max); in snd_ad1816a_playback_open()
435 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max); in snd_ad1816a_playback_open()
436 chip->playback_substream = substream; in snd_ad1816a_playback_open()
443 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ad1816a_capture_open()
449 runtime->hw = snd_ad1816a_capture; in snd_ad1816a_capture_open()
450 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max); in snd_ad1816a_capture_open()
451 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max); in snd_ad1816a_capture_open()
452 chip->capture_substream = substream; in snd_ad1816a_capture_open()
460 chip->playback_substream = NULL; in snd_ad1816a_playback_close()
469 chip->capture_substream = NULL; in snd_ad1816a_capture_close()
479 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_init()
492 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_init()
501 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_suspend()
503 chip->image[reg] = snd_ad1816a_read(chip, reg); in snd_ad1816a_suspend()
504 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_suspend()
513 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_resume()
515 snd_ad1816a_write(chip, reg, chip->image[reg]); in snd_ad1816a_resume()
516 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_resume()
524 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_probe()
526 switch (chip->version = snd_ad1816a_read(chip, AD1816A_VERSION_ID)) { in snd_ad1816a_probe()
528 chip->hardware = AD1816A_HW_AD1815; in snd_ad1816a_probe()
531 chip->hardware = AD1816A_HW_AD18MAX10; in snd_ad1816a_probe()
534 chip->hardware = AD1816A_HW_AD1816A; in snd_ad1816a_probe()
537 chip->hardware = AD1816A_HW_AUTO; in snd_ad1816a_probe()
540 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_probe()
546 switch (chip->hardware) { in snd_ad1816a_chip_id()
551 dev_warn(chip->card->dev, "Unknown chip version %d:%d.\n", in snd_ad1816a_chip_id()
552 chip->version, chip->hardware); in snd_ad1816a_chip_id()
553 return "AD1816A - unknown"; in snd_ad1816a_chip_id()
563 chip->irq = -1; in snd_ad1816a_create()
564 chip->dma1 = -1; in snd_ad1816a_create()
565 chip->dma2 = -1; in snd_ad1816a_create()
567 chip->res_port = devm_request_region(card->dev, port, 16, "AD1816A"); in snd_ad1816a_create()
568 if (!chip->res_port) { in snd_ad1816a_create()
569 dev_err(card->dev, "ad1816a: can't grab port 0x%lx\n", port); in snd_ad1816a_create()
570 return -EBUSY; in snd_ad1816a_create()
572 if (devm_request_irq(card->dev, irq, snd_ad1816a_interrupt, 0, in snd_ad1816a_create()
574 dev_err(card->dev, "ad1816a: can't grab IRQ %d\n", irq); in snd_ad1816a_create()
575 return -EBUSY; in snd_ad1816a_create()
577 chip->irq = irq; in snd_ad1816a_create()
578 card->sync_irq = chip->irq; in snd_ad1816a_create()
579 if (snd_devm_request_dma(card->dev, dma1, "AD1816A - 1")) { in snd_ad1816a_create()
580 dev_err(card->dev, "ad1816a: can't grab DMA1 %d\n", dma1); in snd_ad1816a_create()
581 return -EBUSY; in snd_ad1816a_create()
583 chip->dma1 = dma1; in snd_ad1816a_create()
584 if (snd_devm_request_dma(card->dev, dma2, "AD1816A - 2")) { in snd_ad1816a_create()
585 dev_err(card->dev, "ad1816a: can't grab DMA2 %d\n", dma2); in snd_ad1816a_create()
586 return -EBUSY; in snd_ad1816a_create()
588 chip->dma2 = dma2; in snd_ad1816a_create()
590 chip->card = card; in snd_ad1816a_create()
591 chip->port = port; in snd_ad1816a_create()
592 spin_lock_init(&chip->lock); in snd_ad1816a_create()
624 error = snd_pcm_new(chip->card, "AD1816A", device, 1, 1, &pcm); in snd_ad1816a_pcm()
631 pcm->private_data = chip; in snd_ad1816a_pcm()
632 pcm->info_flags = (chip->dma1 == chip->dma2 ) ? SNDRV_PCM_INFO_JOINT_DUPLEX : 0; in snd_ad1816a_pcm()
634 strcpy(pcm->name, snd_ad1816a_chip_id(chip)); in snd_ad1816a_pcm()
637 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, chip->card->dev, in snd_ad1816a_pcm()
638 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024); in snd_ad1816a_pcm()
640 chip->pcm = pcm; in snd_ad1816a_pcm()
652 tid.card = chip->card->number; in snd_ad1816a_timer()
655 error = snd_timer_new(chip->card, "AD1816A", &tid, &timer); in snd_ad1816a_timer()
658 strcpy(timer->name, snd_ad1816a_chip_id(chip)); in snd_ad1816a_timer()
659 timer->private_data = chip; in snd_ad1816a_timer()
660 chip->timer = timer; in snd_ad1816a_timer()
661 timer->hw = snd_ad1816a_timer_table; in snd_ad1816a_timer()
685 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_get_mux()
687 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_get_mux()
688 ucontrol->value.enumerated.item[0] = (val >> 12) & 7; in snd_ad1816a_get_mux()
689 ucontrol->value.enumerated.item[1] = (val >> 4) & 7; in snd_ad1816a_get_mux()
700 if (ucontrol->value.enumerated.item[0] > 6 || in snd_ad1816a_put_mux()
701 ucontrol->value.enumerated.item[1] > 6) in snd_ad1816a_put_mux()
702 return -EINVAL; in snd_ad1816a_put_mux()
703 val = (ucontrol->value.enumerated.item[0] << 12) | in snd_ad1816a_put_mux()
704 (ucontrol->value.enumerated.item[1] << 4); in snd_ad1816a_put_mux()
705 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_put_mux()
708 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_put_mux()
726 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_ad1816a_info_single()
728 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_ad1816a_info_single()
729 uinfo->count = 1; in snd_ad1816a_info_single()
730 uinfo->value.integer.min = 0; in snd_ad1816a_info_single()
731 uinfo->value.integer.max = mask; in snd_ad1816a_info_single()
739 int reg = kcontrol->private_value & 0xff; in snd_ad1816a_get_single()
740 int shift = (kcontrol->private_value >> 8) & 0xff; in snd_ad1816a_get_single()
741 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_ad1816a_get_single()
742 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_ad1816a_get_single()
744 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_get_single()
745 ucontrol->value.integer.value[0] = (snd_ad1816a_read(chip, reg) >> shift) & mask; in snd_ad1816a_get_single()
746 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_get_single()
748 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; in snd_ad1816a_get_single()
756 int reg = kcontrol->private_value & 0xff; in snd_ad1816a_put_single()
757 int shift = (kcontrol->private_value >> 8) & 0xff; in snd_ad1816a_put_single()
758 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_ad1816a_put_single()
759 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_ad1816a_put_single()
763 val = (ucontrol->value.integer.value[0] & mask); in snd_ad1816a_put_single()
765 val = mask - val; in snd_ad1816a_put_single()
767 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_put_single()
772 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_put_single()
791 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_ad1816a_info_double()
793 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_ad1816a_info_double()
794 uinfo->count = 2; in snd_ad1816a_info_double()
795 uinfo->value.integer.min = 0; in snd_ad1816a_info_double()
796 uinfo->value.integer.max = mask; in snd_ad1816a_info_double()
804 int reg = kcontrol->private_value & 0xff; in snd_ad1816a_get_double()
805 int shift_left = (kcontrol->private_value >> 8) & 0x0f; in snd_ad1816a_get_double()
806 int shift_right = (kcontrol->private_value >> 12) & 0x0f; in snd_ad1816a_get_double()
807 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_ad1816a_get_double()
808 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_ad1816a_get_double()
811 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_get_double()
813 ucontrol->value.integer.value[0] = (val >> shift_left) & mask; in snd_ad1816a_get_double()
814 ucontrol->value.integer.value[1] = (val >> shift_right) & mask; in snd_ad1816a_get_double()
815 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_get_double()
817 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; in snd_ad1816a_get_double()
818 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; in snd_ad1816a_get_double()
827 int reg = kcontrol->private_value & 0xff; in snd_ad1816a_put_double()
828 int shift_left = (kcontrol->private_value >> 8) & 0x0f; in snd_ad1816a_put_double()
829 int shift_right = (kcontrol->private_value >> 12) & 0x0f; in snd_ad1816a_put_double()
830 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_ad1816a_put_double()
831 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_ad1816a_put_double()
835 val1 = ucontrol->value.integer.value[0] & mask; in snd_ad1816a_put_double()
836 val2 = ucontrol->value.integer.value[1] & mask; in snd_ad1816a_put_double()
838 val1 = mask - val1; in snd_ad1816a_put_double()
839 val2 = mask - val2; in snd_ad1816a_put_double()
843 spin_lock_irqsave(&chip->lock, flags); in snd_ad1816a_put_double()
848 spin_unlock_irqrestore(&chip->lock, flags); in snd_ad1816a_put_double()
852 static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0);
853 static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
854 static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
855 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
900 AD1816A_SINGLE("3D Control - Switch", AD1816A_3D_PHAT_CTRL, 15, 1, 1),
901 AD1816A_SINGLE("3D Control - Level", AD1816A_3D_PHAT_CTRL, 0, 15, 0),
910 if (snd_BUG_ON(!chip || !chip->card)) in snd_ad1816a_mixer()
911 return -EINVAL; in snd_ad1816a_mixer()
913 card = chip->card; in snd_ad1816a_mixer()
915 strcpy(card->mixername, snd_ad1816a_chip_id(chip)); in snd_ad1816a_mixer()