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 */
72 #define AMD7930_DSR1 0x02UL /* D-channel Status Register 1 (R) */
73 #define AMD7930_DER 0x03UL /* D-channel Error Register (R) */
74 #define AMD7930_DCTB 0x04UL /* D-channel Transmit Buffer (W) */
75 #define AMD7930_DCRB AMD7930_DCTB /* D-channel Receive Buffer (R) */
76 #define AMD7930_BBTB 0x05UL /* Bb-channel Transmit Buffer (W) */
77 #define AMD7930_BBRB AMD7930_BBTB /* Bb-channel Receive Buffer (R) */
78 #define AMD7930_BCTB 0x06UL /* Bc-channel Transmit Buffer (W) */
79 #define AMD7930_BCRB AMD7930_BCTB /* Bc-channel Receive Buffer (R) */
80 #define AMD7930_DSR2 0x07UL /* D-channel Status Register 2 (R) */
101 #define AMR_IR_DTTHRSH 0x01 /* D-channel xmit threshold */
102 #define AMR_IR_DRTHRSH 0x02 /* D-channel recv threshold */
103 #define AMR_IR_DSRI 0x04 /* D-channel packet status */
104 #define AMR_IR_DERI 0x08 /* D-channel error */
105 #define AMR_IR_BBUF 0x10 /* B-channel data xfer */
107 #define AMR_IR_DSR2I 0x40 /* D-channel buffer status */
346 /* Idle the AMD7930 chip. The amd->lock is not held. */
351 spin_lock_irqsave(&amd->lock, flags); in amd7930_idle()
352 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); in amd7930_idle()
353 sbus_writeb(0, amd->regs + AMD7930_DR); in amd7930_idle()
354 spin_unlock_irqrestore(&amd->lock, flags); in amd7930_idle()
357 /* Enable chip interrupts. The amd->lock is not held. */
362 spin_lock_irqsave(&amd->lock, flags); in amd7930_enable_ints()
363 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); in amd7930_enable_ints()
364 sbus_writeb(AM_INIT_ACTIVE, amd->regs + AMD7930_DR); in amd7930_enable_ints()
365 spin_unlock_irqrestore(&amd->lock, flags); in amd7930_enable_ints()
368 /* Disable chip interrupts. The amd->lock is not held. */
373 spin_lock_irqsave(&amd->lock, flags); in amd7930_disable_ints()
374 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); in amd7930_disable_ints()
375 sbus_writeb(AM_INIT_ACTIVE | AM_INIT_DISABLE_INTS, amd->regs + AMD7930_DR); in amd7930_disable_ints()
376 spin_unlock_irqrestore(&amd->lock, flags); in amd7930_disable_ints()
380 * The amd->lock is held and local interrupts are disabled.
384 struct amd7930_map *map = &amd->map; in __amd7930_write_map()
386 sbus_writeb(AMR_MAP_GX, amd->regs + AMD7930_CR); in __amd7930_write_map()
387 sbus_writeb(((map->gx >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
388 sbus_writeb(((map->gx >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
390 sbus_writeb(AMR_MAP_GR, amd->regs + AMD7930_CR); in __amd7930_write_map()
391 sbus_writeb(((map->gr >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
392 sbus_writeb(((map->gr >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
394 sbus_writeb(AMR_MAP_STGR, amd->regs + AMD7930_CR); in __amd7930_write_map()
395 sbus_writeb(((map->stgr >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
396 sbus_writeb(((map->stgr >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
398 sbus_writeb(AMR_MAP_GER, amd->regs + AMD7930_CR); in __amd7930_write_map()
399 sbus_writeb(((map->ger >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
400 sbus_writeb(((map->ger >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
402 sbus_writeb(AMR_MAP_MMR1, amd->regs + AMD7930_CR); in __amd7930_write_map()
403 sbus_writeb(map->mmr1, amd->regs + AMD7930_DR); in __amd7930_write_map()
405 sbus_writeb(AMR_MAP_MMR2, amd->regs + AMD7930_CR); in __amd7930_write_map()
406 sbus_writeb(map->mmr2, amd->regs + AMD7930_DR); in __amd7930_write_map()
412 * -18 to 0dB in .16dB steps then 0 to 12dB in .08dB steps.
450 0x431f, /* 5. dB */
451 0x331f, /* 5.5 dB */
452 0x40dd, /* 6. dB */
453 0x11dd, /* 6.5 dB */
454 0x440f, /* 7. dB */
455 0x411f, /* 7.5 dB */
456 0x311f, /* 8. dB */
457 0x5520, /* 8.5 dB */
458 0x10dd, /* 9. dB */
459 0x4211, /* 9.5 dB */
460 0x410f, /* 10. dB */
461 0x111f, /* 10.5 dB */
462 0x600b, /* 11. dB */
463 0x00dd, /* 11.5 dB */
464 0x4210, /* 12. dB */
465 0x110f, /* 13. dB */
466 0x7200, /* 14. dB */
467 0x2110, /* 15. dB */
468 0x2200, /* 15.9 dB */
469 0x000b, /* 16.9 dB */
470 0x000f /* 18. dB */
474 * The amd->lock is held and local interrupts are disabled.
478 struct amd7930_map *map = &amd->map; in __amd7930_update_map()
481 map->gx = gx_coeff[amd->rgain]; in __amd7930_update_map()
482 map->stgr = gx_coeff[amd->mgain]; in __amd7930_update_map()
483 level = (amd->pgain * (256 + ARRAY_SIZE(ger_coeff))) >> 8; in __amd7930_update_map()
485 map->ger = ger_coeff[level - 256]; in __amd7930_update_map()
486 map->gr = gx_coeff[255]; in __amd7930_update_map()
488 map->ger = ger_coeff[0]; in __amd7930_update_map()
489 map->gr = gx_coeff[level]; in __amd7930_update_map()
500 spin_lock(&amd->lock); in snd_amd7930_interrupt()
504 ir = sbus_readb(amd->regs + AMD7930_IR); in snd_amd7930_interrupt()
508 if (amd->flags & AMD7930_FLAG_PLAYBACK) { in snd_amd7930_interrupt()
509 if (amd->p_left > 0) { in snd_amd7930_interrupt()
510 byte = *(amd->p_cur++); in snd_amd7930_interrupt()
511 amd->p_left--; in snd_amd7930_interrupt()
512 sbus_writeb(byte, amd->regs + AMD7930_BBTB); in snd_amd7930_interrupt()
513 if (amd->p_left == 0) in snd_amd7930_interrupt()
516 sbus_writeb(0, amd->regs + AMD7930_BBTB); in snd_amd7930_interrupt()
517 } else if (amd->flags & AMD7930_FLAG_CAPTURE) { in snd_amd7930_interrupt()
518 byte = sbus_readb(amd->regs + AMD7930_BBRB); in snd_amd7930_interrupt()
519 if (amd->c_left > 0) { in snd_amd7930_interrupt()
520 *(amd->c_cur++) = byte; in snd_amd7930_interrupt()
521 amd->c_left--; in snd_amd7930_interrupt()
522 if (amd->c_left == 0) in snd_amd7930_interrupt()
527 spin_unlock(&amd->lock); in snd_amd7930_interrupt()
530 snd_pcm_period_elapsed(amd->playback_substream); in snd_amd7930_interrupt()
532 snd_pcm_period_elapsed(amd->capture_substream); in snd_amd7930_interrupt()
537 static int snd_amd7930_trigger(struct snd_amd7930 *amd, unsigned int flag, int cmd) in snd_amd7930_trigger() argument
542 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_trigger()
543 if (cmd == SNDRV_PCM_TRIGGER_START) { in snd_amd7930_trigger()
544 if (!(amd->flags & flag)) { in snd_amd7930_trigger()
545 amd->flags |= flag; in snd_amd7930_trigger()
548 sbus_writeb(AMR_MUX_MCR4, amd->regs + AMD7930_CR); in snd_amd7930_trigger()
549 sbus_writeb(AM_MUX_MCR4_ENABLE_INTS, amd->regs + AMD7930_DR); in snd_amd7930_trigger()
551 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { in snd_amd7930_trigger()
552 if (amd->flags & flag) { in snd_amd7930_trigger()
553 amd->flags &= ~flag; in snd_amd7930_trigger()
556 sbus_writeb(AMR_MUX_MCR4, amd->regs + AMD7930_CR); in snd_amd7930_trigger()
557 sbus_writeb(0, amd->regs + AMD7930_DR); in snd_amd7930_trigger()
560 result = -EINVAL; in snd_amd7930_trigger()
562 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_trigger()
568 int cmd) in snd_amd7930_playback_trigger() argument
571 return snd_amd7930_trigger(amd, AMD7930_FLAG_PLAYBACK, cmd); in snd_amd7930_playback_trigger()
575 int cmd) in snd_amd7930_capture_trigger() argument
578 return snd_amd7930_trigger(amd, AMD7930_FLAG_CAPTURE, cmd); in snd_amd7930_capture_trigger()
584 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_playback_prepare()
589 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_playback_prepare()
591 amd->flags |= AMD7930_FLAG_PLAYBACK; in snd_amd7930_playback_prepare()
593 /* Setup the pseudo-dma transfer pointers. */ in snd_amd7930_playback_prepare()
594 amd->p_orig = amd->p_cur = runtime->dma_area; in snd_amd7930_playback_prepare()
595 amd->p_left = size; in snd_amd7930_playback_prepare()
598 new_mmr1 = amd->map.mmr1; in snd_amd7930_playback_prepare()
599 if (runtime->format == SNDRV_PCM_FORMAT_A_LAW) in snd_amd7930_playback_prepare()
603 if (new_mmr1 != amd->map.mmr1) { in snd_amd7930_playback_prepare()
604 amd->map.mmr1 = new_mmr1; in snd_amd7930_playback_prepare()
608 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_playback_prepare()
616 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_capture_prepare()
621 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_capture_prepare()
623 amd->flags |= AMD7930_FLAG_CAPTURE; in snd_amd7930_capture_prepare()
625 /* Setup the pseudo-dma transfer pointers. */ in snd_amd7930_capture_prepare()
626 amd->c_orig = amd->c_cur = runtime->dma_area; in snd_amd7930_capture_prepare()
627 amd->c_left = size; in snd_amd7930_capture_prepare()
630 new_mmr1 = amd->map.mmr1; in snd_amd7930_capture_prepare()
631 if (runtime->format == SNDRV_PCM_FORMAT_A_LAW) in snd_amd7930_capture_prepare()
635 if (new_mmr1 != amd->map.mmr1) { in snd_amd7930_capture_prepare()
636 amd->map.mmr1 = new_mmr1; in snd_amd7930_capture_prepare()
640 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_capture_prepare()
650 if (!(amd->flags & AMD7930_FLAG_PLAYBACK)) in snd_amd7930_playback_pointer()
652 ptr = amd->p_cur - amd->p_orig; in snd_amd7930_playback_pointer()
653 return bytes_to_frames(substream->runtime, ptr); in snd_amd7930_playback_pointer()
661 if (!(amd->flags & AMD7930_FLAG_CAPTURE)) in snd_amd7930_capture_pointer()
664 ptr = amd->c_cur - amd->c_orig; in snd_amd7930_capture_pointer()
665 return bytes_to_frames(substream->runtime, ptr); in snd_amd7930_capture_pointer()
692 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_playback_open()
694 amd->playback_substream = substream; in snd_amd7930_playback_open()
695 runtime->hw = snd_amd7930_pcm_hw; in snd_amd7930_playback_open()
702 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_capture_open()
704 amd->capture_substream = substream; in snd_amd7930_capture_open()
705 runtime->hw = snd_amd7930_pcm_hw; in snd_amd7930_capture_open()
713 amd->playback_substream = NULL; in snd_amd7930_playback_close()
721 amd->capture_substream = NULL; in snd_amd7930_capture_close()
746 if ((err = snd_pcm_new(amd->card, in snd_amd7930_pcm()
756 pcm->private_data = amd; in snd_amd7930_pcm()
757 pcm->info_flags = 0; in snd_amd7930_pcm()
758 strcpy(pcm->name, amd->card->shortname); in snd_amd7930_pcm()
759 amd->pcm = pcm; in snd_amd7930_pcm()
773 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_amd7930_info_volume()
774 uinfo->count = 1; in snd_amd7930_info_volume()
775 uinfo->value.integer.min = 0; in snd_amd7930_info_volume()
776 uinfo->value.integer.max = 255; in snd_amd7930_info_volume()
784 int type = kctl->private_value; in snd_amd7930_get_volume()
789 swval = &amd->mgain; in snd_amd7930_get_volume()
792 swval = &amd->rgain; in snd_amd7930_get_volume()
796 swval = &amd->pgain; in snd_amd7930_get_volume()
800 ucontrol->value.integer.value[0] = *swval; in snd_amd7930_get_volume()
809 int type = kctl->private_value; in snd_amd7930_put_volume()
814 swval = &amd->mgain; in snd_amd7930_put_volume()
817 swval = &amd->rgain; in snd_amd7930_put_volume()
821 swval = &amd->pgain; in snd_amd7930_put_volume()
825 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_put_volume()
827 if (*swval != ucontrol->value.integer.value[0]) { in snd_amd7930_put_volume()
828 *swval = ucontrol->value.integer.value[0] & 0xff; in snd_amd7930_put_volume()
834 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_put_volume()
874 if (snd_BUG_ON(!amd || !amd->card)) in snd_amd7930_mixer()
875 return -EINVAL; in snd_amd7930_mixer()
877 card = amd->card; in snd_amd7930_mixer()
878 strcpy(card->mixername, card->shortname); in snd_amd7930_mixer()
891 struct platform_device *op = amd->op; in snd_amd7930_free()
895 if (amd->irq) in snd_amd7930_free()
896 free_irq(amd->irq, amd); in snd_amd7930_free()
898 if (amd->regs) in snd_amd7930_free()
899 of_iounmap(&op->resource[0], amd->regs, in snd_amd7930_free()
900 resource_size(&op->resource[0])); in snd_amd7930_free()
909 struct snd_amd7930 *amd = device->device_data; in snd_amd7930_dev_free()
930 return -ENOMEM; in snd_amd7930_create()
932 spin_lock_init(&amd->lock); in snd_amd7930_create()
933 amd->card = card; in snd_amd7930_create()
934 amd->op = op; in snd_amd7930_create()
936 amd->regs = of_ioremap(&op->resource[0], 0, in snd_amd7930_create()
937 resource_size(&op->resource[0]), "amd7930"); in snd_amd7930_create()
938 if (!amd->regs) { in snd_amd7930_create()
940 "amd7930-%d: Unable to map chip registers.\n", dev); in snd_amd7930_create()
942 return -EIO; in snd_amd7930_create()
949 snd_printk(KERN_ERR "amd7930-%d: Unable to grab IRQ %d\n", in snd_amd7930_create()
952 return -EBUSY; in snd_amd7930_create()
954 amd->irq = irq; in snd_amd7930_create()
958 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_create()
960 amd->rgain = 128; in snd_amd7930_create()
961 amd->pgain = 200; in snd_amd7930_create()
962 amd->mgain = 0; in snd_amd7930_create()
964 memset(&amd->map, 0, sizeof(amd->map)); in snd_amd7930_create()
965 amd->map.mmr1 = (AM_MAP_MMR1_GX | AM_MAP_MMR1_GER | in snd_amd7930_create()
967 amd->map.mmr2 = (AM_MAP_MMR2_LS | AM_MAP_MMR2_AINB); in snd_amd7930_create()
972 sbus_writeb(AMR_MUX_MCR1, amd->regs + AMD7930_CR); in snd_amd7930_create()
974 amd->regs + AMD7930_DR); in snd_amd7930_create()
976 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()
1035 amd->next = amd7930_list; in amd7930_sbus_probe()
1073 struct snd_amd7930 *next = p->next; in amd7930_exit()
1075 snd_card_free(p->card); in amd7930_exit()