Lines Matching +full:31 +full:- +full:1024

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))
28 dev_warn(chip->card->dev, "chip busy.\n");
29 return -EBUSY;
99 guard(spinlock_irqsave)(&chip->lock);
101 if (chip->mode & mode)
102 return -EAGAIN;
123 chip->mode |= mode;
130 guard(spinlock_irqsave)(&chip->lock);
151 chip->mode &= ~mode;
152 if (!(chip->mode & AD1816A_MODE_OPEN))
153 chip->mode = 0;
165 scoped_guard(spinlock, &chip->lock) {
180 dev_warn(chip->card->dev, "invalid trigger mode 0x%x.\n", what);
181 error = -EINVAL;
204 struct snd_pcm_runtime *runtime = substream->runtime;
207 guard(spinlock_irqsave)(&chip->lock);
209 chip->p_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
213 snd_dma_program(chip->dma1, runtime->dma_addr, size,
216 rate = runtime->rate;
217 if (chip->clock_freq)
218 rate = (rate * 33000) / chip->clock_freq;
222 snd_ad1816a_get_format(chip, runtime->format,
223 runtime->channels));
226 snd_pcm_lib_period_bytes(substream) / 4 - 1);
233 struct snd_pcm_runtime *runtime = substream->runtime;
236 guard(spinlock_irqsave)(&chip->lock);
238 chip->c_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
242 snd_dma_program(chip->dma2, runtime->dma_addr, size,
245 rate = runtime->rate;
246 if (chip->clock_freq)
247 rate = (rate * 33000) / chip->clock_freq;
251 snd_ad1816a_get_format(chip, runtime->format,
252 runtime->channels));
255 snd_pcm_lib_period_bytes(substream) / 4 - 1);
264 if (!(chip->mode & AD1816A_MODE_PLAYBACK))
266 ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
267 return bytes_to_frames(substream->runtime, ptr);
274 if (!(chip->mode & AD1816A_MODE_CAPTURE))
276 ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
277 return bytes_to_frames(substream->runtime, ptr);
286 scoped_guard(spinlock, &chip->lock) {
290 if ((status & AD1816A_PLAYBACK_IRQ_PENDING) && chip->playback_substream)
291 snd_pcm_period_elapsed(chip->playback_substream);
293 if ((status & AD1816A_CAPTURE_IRQ_PENDING) && chip->capture_substream)
294 snd_pcm_period_elapsed(chip->capture_substream);
296 if ((status & AD1816A_TIMER_IRQ_PENDING) && chip->timer)
297 snd_timer_interrupt(chip->timer, chip->timer->sticks);
299 scoped_guard(spinlock, &chip->lock) {
317 .buffer_bytes_max = (128*1024),
319 .period_bytes_max = (128*1024),
321 .periods_max = 1024,
336 .buffer_bytes_max = (128*1024),
338 .period_bytes_max = (128*1024),
340 .periods_max = 1024,
371 guard(spinlock_irqsave)(&chip->lock);
376 timer->sticks & 0xffff);
388 guard(spinlock_irqsave)(&chip->lock);
408 struct snd_pcm_runtime *runtime = substream->runtime;
414 runtime->hw = snd_ad1816a_playback;
415 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
416 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
417 chip->playback_substream = substream;
424 struct snd_pcm_runtime *runtime = substream->runtime;
430 runtime->hw = snd_ad1816a_capture;
431 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
432 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
433 chip->capture_substream = substream;
441 chip->playback_substream = NULL;
450 chip->capture_substream = NULL;
458 guard(spinlock_irqsave)(&chip->lock);
477 guard(spinlock_irqsave)(&chip->lock);
479 chip->image[reg] = snd_ad1816a_read(chip, reg);
487 guard(spinlock_irqsave)(&chip->lock);
489 snd_ad1816a_write(chip, reg, chip->image[reg]);
495 guard(spinlock_irqsave)(&chip->lock);
497 switch (chip->version = snd_ad1816a_read(chip, AD1816A_VERSION_ID)) {
499 chip->hardware = AD1816A_HW_AD1815;
502 chip->hardware = AD1816A_HW_AD18MAX10;
505 chip->hardware = AD1816A_HW_AD1816A;
508 chip->hardware = AD1816A_HW_AUTO;
515 switch (chip->hardware) {
520 dev_warn(chip->card->dev, "Unknown chip version %d:%d.\n",
521 chip->version, chip->hardware);
522 return "AD1816A - unknown";
532 chip->irq = -1;
533 chip->dma1 = -1;
534 chip->dma2 = -1;
536 chip->res_port = devm_request_region(card->dev, port, 16, "AD1816A");
537 if (!chip->res_port) {
538 dev_err(card->dev, "ad1816a: can't grab port 0x%lx\n", port);
539 return -EBUSY;
541 if (devm_request_irq(card->dev, irq, snd_ad1816a_interrupt, 0,
543 dev_err(card->dev, "ad1816a: can't grab IRQ %d\n", irq);
544 return -EBUSY;
546 chip->irq = irq;
547 card->sync_irq = chip->irq;
548 if (snd_devm_request_dma(card->dev, dma1, "AD1816A - 1")) {
549 dev_err(card->dev, "ad1816a: can't grab DMA1 %d\n", dma1);
550 return -EBUSY;
552 chip->dma1 = dma1;
553 if (snd_devm_request_dma(card->dev, dma2, "AD1816A - 2")) {
554 dev_err(card->dev, "ad1816a: can't grab DMA2 %d\n", dma2);
555 return -EBUSY;
557 chip->dma2 = dma2;
559 chip->card = card;
560 chip->port = port;
561 spin_lock_init(&chip->lock);
593 error = snd_pcm_new(chip->card, "AD1816A", device, 1, 1, &pcm);
600 pcm->private_data = chip;
601 pcm->info_flags = (chip->dma1 == chip->dma2 ) ? SNDRV_PCM_INFO_JOINT_DUPLEX : 0;
603 strscpy(pcm->name, snd_ad1816a_chip_id(chip));
606 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, chip->card->dev,
607 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
609 chip->pcm = pcm;
621 tid.card = chip->card->number;
624 error = snd_timer_new(chip->card, "AD1816A", &tid, &timer);
627 strscpy(timer->name, snd_ad1816a_chip_id(chip));
628 timer->private_data = chip;
629 chip->timer = timer;
630 timer->hw = snd_ad1816a_timer_table;
653 guard(spinlock_irqsave)(&chip->lock);
655 ucontrol->value.enumerated.item[0] = (val >> 12) & 7;
656 ucontrol->value.enumerated.item[1] = (val >> 4) & 7;
666 if (ucontrol->value.enumerated.item[0] > 6 ||
667 ucontrol->value.enumerated.item[1] > 6)
668 return -EINVAL;
669 val = (ucontrol->value.enumerated.item[0] << 12) |
670 (ucontrol->value.enumerated.item[1] << 4);
671 guard(spinlock_irqsave)(&chip->lock);
691 int mask = (kcontrol->private_value >> 16) & 0xff;
693 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
694 uinfo->count = 1;
695 uinfo->value.integer.min = 0;
696 uinfo->value.integer.max = mask;
703 int reg = kcontrol->private_value & 0xff;
704 int shift = (kcontrol->private_value >> 8) & 0xff;
705 int mask = (kcontrol->private_value >> 16) & 0xff;
706 int invert = (kcontrol->private_value >> 24) & 0xff;
708 guard(spinlock_irqsave)(&chip->lock);
709 ucontrol->value.integer.value[0] = (snd_ad1816a_read(chip, reg) >> shift) & mask;
711 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
718 int reg = kcontrol->private_value & 0xff;
719 int shift = (kcontrol->private_value >> 8) & 0xff;
720 int mask = (kcontrol->private_value >> 16) & 0xff;
721 int invert = (kcontrol->private_value >> 24) & 0xff;
725 val = (ucontrol->value.integer.value[0] & mask);
727 val = mask - val;
729 guard(spinlock_irqsave)(&chip->lock);
752 int mask = (kcontrol->private_value >> 16) & 0xff;
754 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
755 uinfo->count = 2;
756 uinfo->value.integer.min = 0;
757 uinfo->value.integer.max = mask;
764 int reg = kcontrol->private_value & 0xff;
765 int shift_left = (kcontrol->private_value >> 8) & 0x0f;
766 int shift_right = (kcontrol->private_value >> 12) & 0x0f;
767 int mask = (kcontrol->private_value >> 16) & 0xff;
768 int invert = (kcontrol->private_value >> 24) & 0xff;
771 guard(spinlock_irqsave)(&chip->lock);
773 ucontrol->value.integer.value[0] = (val >> shift_left) & mask;
774 ucontrol->value.integer.value[1] = (val >> shift_right) & mask;
776 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
777 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
785 int reg = kcontrol->private_value & 0xff;
786 int shift_left = (kcontrol->private_value >> 8) & 0x0f;
787 int shift_right = (kcontrol->private_value >> 12) & 0x0f;
788 int mask = (kcontrol->private_value >> 16) & 0xff;
789 int invert = (kcontrol->private_value >> 24) & 0xff;
793 val1 = ucontrol->value.integer.value[0] & mask;
794 val2 = ucontrol->value.integer.value[1] & mask;
796 val1 = mask - val1;
797 val2 = mask - val2;
801 guard(spinlock_irqsave)(&chip->lock);
809 static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0);
810 static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
811 static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
812 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
817 AD1816A_DOUBLE_TLV("Master Playback Volume", AD1816A_MASTER_ATT, 8, 0, 31, 1,
823 AD1816A_DOUBLE_TLV("Line Playback Volume", AD1816A_LINE_GAIN_ATT, 8, 0, 31, 1,
826 AD1816A_DOUBLE_TLV("CD Playback Volume", AD1816A_CD_GAIN_ATT, 8, 0, 31, 1,
829 AD1816A_DOUBLE_TLV("Synth Playback Volume", AD1816A_SYNTH_GAIN_ATT, 8, 0, 31, 1,
835 AD1816A_SINGLE_TLV("Mic Playback Volume", AD1816A_MIC_GAIN_ATT, 8, 31, 1,
839 AD1816A_DOUBLE_TLV("Video Playback Volume", AD1816A_VID_GAIN_ATT, 8, 0, 31, 1,
845 AD1816A_SINGLE_TLV("Phone Playback Volume", AD1816A_PHONE_OUT_ATT, 0, 31, 1,
857 AD1816A_SINGLE("3D Control - Switch", AD1816A_3D_PHAT_CTRL, 15, 1, 1),
858 AD1816A_SINGLE("3D Control - Level", AD1816A_3D_PHAT_CTRL, 0, 15, 0),
867 if (snd_BUG_ON(!chip || !chip->card))
868 return -EINVAL;
870 card = chip->card;
872 strscpy(card->mixername, snd_ad1816a_chip_id(chip));