Lines Matching +full:cmd +full:- +full:db
1 // SPDX-License-Identifier: GPL-2.0-only
9 * --- Notes from Thomas's original driver ---
23 * which provide mono-channel audio at 8K samples per second via either
24 * 8-bit A-law or 8-bit mu-law encoding. Also, the chip features an
30 * --- End of notes from Thoamas's original driver ---
52 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
73 #define AMD7930_DSR1 0x02UL /* D-channel Status Register 1 (R) */
74 #define AMD7930_DER 0x03UL /* D-channel Error Register (R) */
75 #define AMD7930_DCTB 0x04UL /* D-channel Transmit Buffer (W) */
76 #define AMD7930_DCRB AMD7930_DCTB /* D-channel Receive Buffer (R) */
77 #define AMD7930_BBTB 0x05UL /* Bb-channel Transmit Buffer (W) */
78 #define AMD7930_BBRB AMD7930_BBTB /* Bb-channel Receive Buffer (R) */
79 #define AMD7930_BCTB 0x06UL /* Bc-channel Transmit Buffer (W) */
80 #define AMD7930_BCRB AMD7930_BCTB /* Bc-channel Receive Buffer (R) */
81 #define AMD7930_DSR2 0x07UL /* D-channel Status Register 2 (R) */
102 #define AMR_IR_DTTHRSH 0x01 /* D-channel xmit threshold */
103 #define AMR_IR_DRTHRSH 0x02 /* D-channel recv threshold */
104 #define AMR_IR_DSRI 0x04 /* D-channel packet status */
105 #define AMR_IR_DERI 0x08 /* D-channel error */
106 #define AMR_IR_BBUF 0x10 /* B-channel data xfer */
108 #define AMR_IR_DSR2I 0x40 /* D-channel buffer status */
347 /* Idle the AMD7930 chip. The amd->lock is not held. */
352 spin_lock_irqsave(&amd->lock, flags); in amd7930_idle()
353 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); in amd7930_idle()
354 sbus_writeb(0, amd->regs + AMD7930_DR); in amd7930_idle()
355 spin_unlock_irqrestore(&amd->lock, flags); in amd7930_idle()
358 /* Enable chip interrupts. The amd->lock is not held. */
363 spin_lock_irqsave(&amd->lock, flags); in amd7930_enable_ints()
364 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); in amd7930_enable_ints()
365 sbus_writeb(AM_INIT_ACTIVE, amd->regs + AMD7930_DR); in amd7930_enable_ints()
366 spin_unlock_irqrestore(&amd->lock, flags); in amd7930_enable_ints()
369 /* Disable chip interrupts. The amd->lock is not held. */
374 spin_lock_irqsave(&amd->lock, flags); in amd7930_disable_ints()
375 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); in amd7930_disable_ints()
376 sbus_writeb(AM_INIT_ACTIVE | AM_INIT_DISABLE_INTS, amd->regs + AMD7930_DR); in amd7930_disable_ints()
377 spin_unlock_irqrestore(&amd->lock, flags); in amd7930_disable_ints()
381 * The amd->lock is held and local interrupts are disabled.
385 struct amd7930_map *map = &amd->map; in __amd7930_write_map()
387 sbus_writeb(AMR_MAP_GX, amd->regs + AMD7930_CR); in __amd7930_write_map()
388 sbus_writeb(((map->gx >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
389 sbus_writeb(((map->gx >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
391 sbus_writeb(AMR_MAP_GR, amd->regs + AMD7930_CR); in __amd7930_write_map()
392 sbus_writeb(((map->gr >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
393 sbus_writeb(((map->gr >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
395 sbus_writeb(AMR_MAP_STGR, amd->regs + AMD7930_CR); in __amd7930_write_map()
396 sbus_writeb(((map->stgr >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
397 sbus_writeb(((map->stgr >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
399 sbus_writeb(AMR_MAP_GER, amd->regs + AMD7930_CR); in __amd7930_write_map()
400 sbus_writeb(((map->ger >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
401 sbus_writeb(((map->ger >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
403 sbus_writeb(AMR_MAP_MMR1, amd->regs + AMD7930_CR); in __amd7930_write_map()
404 sbus_writeb(map->mmr1, amd->regs + AMD7930_DR); in __amd7930_write_map()
406 sbus_writeb(AMR_MAP_MMR2, amd->regs + AMD7930_CR); in __amd7930_write_map()
407 sbus_writeb(map->mmr2, amd->regs + AMD7930_DR); in __amd7930_write_map()
413 * -18 to 0dB in .16dB steps then 0 to 12dB in .08dB steps.
451 0x431f, /* 5. dB */
452 0x331f, /* 5.5 dB */
453 0x40dd, /* 6. dB */
454 0x11dd, /* 6.5 dB */
455 0x440f, /* 7. dB */
456 0x411f, /* 7.5 dB */
457 0x311f, /* 8. dB */
458 0x5520, /* 8.5 dB */
459 0x10dd, /* 9. dB */
460 0x4211, /* 9.5 dB */
461 0x410f, /* 10. dB */
462 0x111f, /* 10.5 dB */
463 0x600b, /* 11. dB */
464 0x00dd, /* 11.5 dB */
465 0x4210, /* 12. dB */
466 0x110f, /* 13. dB */
467 0x7200, /* 14. dB */
468 0x2110, /* 15. dB */
469 0x2200, /* 15.9 dB */
470 0x000b, /* 16.9 dB */
471 0x000f /* 18. dB */
475 * The amd->lock is held and local interrupts are disabled.
479 struct amd7930_map *map = &amd->map; in __amd7930_update_map()
482 map->gx = gx_coeff[amd->rgain]; in __amd7930_update_map()
483 map->stgr = gx_coeff[amd->mgain]; in __amd7930_update_map()
484 level = (amd->pgain * (256 + ARRAY_SIZE(ger_coeff))) >> 8; in __amd7930_update_map()
486 map->ger = ger_coeff[level - 256]; in __amd7930_update_map()
487 map->gr = gx_coeff[255]; in __amd7930_update_map()
489 map->ger = ger_coeff[0]; in __amd7930_update_map()
490 map->gr = gx_coeff[level]; in __amd7930_update_map()
501 spin_lock(&amd->lock); in snd_amd7930_interrupt()
505 ir = sbus_readb(amd->regs + AMD7930_IR); in snd_amd7930_interrupt()
509 if (amd->flags & AMD7930_FLAG_PLAYBACK) { in snd_amd7930_interrupt()
510 if (amd->p_left > 0) { in snd_amd7930_interrupt()
511 byte = *(amd->p_cur++); in snd_amd7930_interrupt()
512 amd->p_left--; in snd_amd7930_interrupt()
513 sbus_writeb(byte, amd->regs + AMD7930_BBTB); in snd_amd7930_interrupt()
514 if (amd->p_left == 0) in snd_amd7930_interrupt()
517 sbus_writeb(0, amd->regs + AMD7930_BBTB); in snd_amd7930_interrupt()
518 } else if (amd->flags & AMD7930_FLAG_CAPTURE) { in snd_amd7930_interrupt()
519 byte = sbus_readb(amd->regs + AMD7930_BBRB); in snd_amd7930_interrupt()
520 if (amd->c_left > 0) { in snd_amd7930_interrupt()
521 *(amd->c_cur++) = byte; in snd_amd7930_interrupt()
522 amd->c_left--; in snd_amd7930_interrupt()
523 if (amd->c_left == 0) in snd_amd7930_interrupt()
528 spin_unlock(&amd->lock); in snd_amd7930_interrupt()
531 snd_pcm_period_elapsed(amd->playback_substream); in snd_amd7930_interrupt()
533 snd_pcm_period_elapsed(amd->capture_substream); in snd_amd7930_interrupt()
538 static int snd_amd7930_trigger(struct snd_amd7930 *amd, unsigned int flag, int cmd) in snd_amd7930_trigger() argument
543 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_trigger()
544 if (cmd == SNDRV_PCM_TRIGGER_START) { in snd_amd7930_trigger()
545 if (!(amd->flags & flag)) { in snd_amd7930_trigger()
546 amd->flags |= flag; in snd_amd7930_trigger()
549 sbus_writeb(AMR_MUX_MCR4, amd->regs + AMD7930_CR); in snd_amd7930_trigger()
550 sbus_writeb(AM_MUX_MCR4_ENABLE_INTS, amd->regs + AMD7930_DR); in snd_amd7930_trigger()
552 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { in snd_amd7930_trigger()
553 if (amd->flags & flag) { in snd_amd7930_trigger()
554 amd->flags &= ~flag; in snd_amd7930_trigger()
557 sbus_writeb(AMR_MUX_MCR4, amd->regs + AMD7930_CR); in snd_amd7930_trigger()
558 sbus_writeb(0, amd->regs + AMD7930_DR); in snd_amd7930_trigger()
561 result = -EINVAL; in snd_amd7930_trigger()
563 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_trigger()
569 int cmd) in snd_amd7930_playback_trigger() argument
572 return snd_amd7930_trigger(amd, AMD7930_FLAG_PLAYBACK, cmd); in snd_amd7930_playback_trigger()
576 int cmd) in snd_amd7930_capture_trigger() argument
579 return snd_amd7930_trigger(amd, AMD7930_FLAG_CAPTURE, cmd); in snd_amd7930_capture_trigger()
585 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_playback_prepare()
590 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_playback_prepare()
592 amd->flags |= AMD7930_FLAG_PLAYBACK; in snd_amd7930_playback_prepare()
594 /* Setup the pseudo-dma transfer pointers. */ in snd_amd7930_playback_prepare()
595 amd->p_orig = amd->p_cur = runtime->dma_area; in snd_amd7930_playback_prepare()
596 amd->p_left = size; in snd_amd7930_playback_prepare()
599 new_mmr1 = amd->map.mmr1; in snd_amd7930_playback_prepare()
600 if (runtime->format == SNDRV_PCM_FORMAT_A_LAW) in snd_amd7930_playback_prepare()
604 if (new_mmr1 != amd->map.mmr1) { in snd_amd7930_playback_prepare()
605 amd->map.mmr1 = new_mmr1; in snd_amd7930_playback_prepare()
609 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_playback_prepare()
617 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_capture_prepare()
622 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_capture_prepare()
624 amd->flags |= AMD7930_FLAG_CAPTURE; in snd_amd7930_capture_prepare()
626 /* Setup the pseudo-dma transfer pointers. */ in snd_amd7930_capture_prepare()
627 amd->c_orig = amd->c_cur = runtime->dma_area; in snd_amd7930_capture_prepare()
628 amd->c_left = size; in snd_amd7930_capture_prepare()
631 new_mmr1 = amd->map.mmr1; in snd_amd7930_capture_prepare()
632 if (runtime->format == SNDRV_PCM_FORMAT_A_LAW) in snd_amd7930_capture_prepare()
636 if (new_mmr1 != amd->map.mmr1) { in snd_amd7930_capture_prepare()
637 amd->map.mmr1 = new_mmr1; in snd_amd7930_capture_prepare()
641 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_capture_prepare()
651 if (!(amd->flags & AMD7930_FLAG_PLAYBACK)) in snd_amd7930_playback_pointer()
653 ptr = amd->p_cur - amd->p_orig; in snd_amd7930_playback_pointer()
654 return bytes_to_frames(substream->runtime, ptr); in snd_amd7930_playback_pointer()
662 if (!(amd->flags & AMD7930_FLAG_CAPTURE)) in snd_amd7930_capture_pointer()
665 ptr = amd->c_cur - amd->c_orig; in snd_amd7930_capture_pointer()
666 return bytes_to_frames(substream->runtime, ptr); in snd_amd7930_capture_pointer()
693 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_playback_open()
695 amd->playback_substream = substream; in snd_amd7930_playback_open()
696 runtime->hw = snd_amd7930_pcm_hw; in snd_amd7930_playback_open()
703 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_capture_open()
705 amd->capture_substream = substream; in snd_amd7930_capture_open()
706 runtime->hw = snd_amd7930_pcm_hw; in snd_amd7930_capture_open()
714 amd->playback_substream = NULL; in snd_amd7930_playback_close()
722 amd->capture_substream = NULL; in snd_amd7930_capture_close()
747 if ((err = snd_pcm_new(amd->card, in snd_amd7930_pcm()
757 pcm->private_data = amd; in snd_amd7930_pcm()
758 pcm->info_flags = 0; in snd_amd7930_pcm()
759 strcpy(pcm->name, amd->card->shortname); in snd_amd7930_pcm()
760 amd->pcm = pcm; in snd_amd7930_pcm()
774 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_amd7930_info_volume()
775 uinfo->count = 1; in snd_amd7930_info_volume()
776 uinfo->value.integer.min = 0; in snd_amd7930_info_volume()
777 uinfo->value.integer.max = 255; in snd_amd7930_info_volume()
785 int type = kctl->private_value; in snd_amd7930_get_volume()
790 swval = &amd->mgain; in snd_amd7930_get_volume()
793 swval = &amd->rgain; in snd_amd7930_get_volume()
797 swval = &amd->pgain; in snd_amd7930_get_volume()
801 ucontrol->value.integer.value[0] = *swval; in snd_amd7930_get_volume()
810 int type = kctl->private_value; in snd_amd7930_put_volume()
815 swval = &amd->mgain; in snd_amd7930_put_volume()
818 swval = &amd->rgain; in snd_amd7930_put_volume()
822 swval = &amd->pgain; in snd_amd7930_put_volume()
826 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_put_volume()
828 if (*swval != ucontrol->value.integer.value[0]) { in snd_amd7930_put_volume()
829 *swval = ucontrol->value.integer.value[0] & 0xff; in snd_amd7930_put_volume()
835 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_put_volume()
875 if (snd_BUG_ON(!amd || !amd->card)) in snd_amd7930_mixer()
876 return -EINVAL; in snd_amd7930_mixer()
878 card = amd->card; in snd_amd7930_mixer()
879 strcpy(card->mixername, card->shortname); in snd_amd7930_mixer()
892 struct platform_device *op = amd->op; in snd_amd7930_free()
896 if (amd->irq) in snd_amd7930_free()
897 free_irq(amd->irq, amd); in snd_amd7930_free()
899 if (amd->regs) in snd_amd7930_free()
900 of_iounmap(&op->resource[0], amd->regs, in snd_amd7930_free()
901 resource_size(&op->resource[0])); in snd_amd7930_free()
910 struct snd_amd7930 *amd = device->device_data; in snd_amd7930_dev_free()
931 return -ENOMEM; in snd_amd7930_create()
933 spin_lock_init(&amd->lock); in snd_amd7930_create()
934 amd->card = card; in snd_amd7930_create()
935 amd->op = op; in snd_amd7930_create()
937 amd->regs = of_ioremap(&op->resource[0], 0, in snd_amd7930_create()
938 resource_size(&op->resource[0]), "amd7930"); in snd_amd7930_create()
939 if (!amd->regs) { in snd_amd7930_create()
941 "amd7930-%d: Unable to map chip registers.\n", dev); in snd_amd7930_create()
943 return -EIO; in snd_amd7930_create()
950 snd_printk(KERN_ERR "amd7930-%d: Unable to grab IRQ %d\n", in snd_amd7930_create()
953 return -EBUSY; in snd_amd7930_create()
955 amd->irq = irq; in snd_amd7930_create()
959 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_create()
961 amd->rgain = 128; in snd_amd7930_create()
962 amd->pgain = 200; in snd_amd7930_create()
963 amd->mgain = 0; in snd_amd7930_create()
965 memset(&amd->map, 0, sizeof(amd->map)); in snd_amd7930_create()
966 amd->map.mmr1 = (AM_MAP_MMR1_GX | AM_MAP_MMR1_GER | in snd_amd7930_create()
968 amd->map.mmr2 = (AM_MAP_MMR2_LS | AM_MAP_MMR2_AINB); in snd_amd7930_create()
973 sbus_writeb(AMR_MUX_MCR1, amd->regs + AMD7930_CR); in snd_amd7930_create()
975 amd->regs + AMD7930_DR); in snd_amd7930_create()
977 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_create()
991 struct resource *rp = &op->resource[0]; in amd7930_sbus_probe()
997 irq = op->archdata.irqs[0]; in amd7930_sbus_probe()
1000 return -ENODEV; in amd7930_sbus_probe()
1003 return -ENOENT; in amd7930_sbus_probe()
1006 err = snd_card_new(&op->dev, index[dev_num], id[dev_num], in amd7930_sbus_probe()
1011 strcpy(card->driver, "AMD7930"); in amd7930_sbus_probe()
1012 strcpy(card->shortname, "Sun AMD7930"); in amd7930_sbus_probe()
1013 sprintf(card->longname, "%s at 0x%02lx:0x%08Lx, irq %d", in amd7930_sbus_probe()
1014 card->shortname, in amd7930_sbus_probe()
1015 rp->flags & 0xffL, in amd7930_sbus_probe()
1016 (unsigned long long)rp->start, in amd7930_sbus_probe()
1032 amd->next = amd7930_list; in amd7930_sbus_probe()
1070 struct snd_amd7930 *next = p->next; in amd7930_exit()
1072 snd_card_free(p->card); in amd7930_exit()