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 ---
51 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
71 #define AMD7930_DSR1 0x02UL /* D-channel Status Register 1 (R) */
72 #define AMD7930_DER 0x03UL /* D-channel Error Register (R) */
73 #define AMD7930_DCTB 0x04UL /* D-channel Transmit Buffer (W) */
74 #define AMD7930_DCRB AMD7930_DCTB /* D-channel Receive Buffer (R) */
75 #define AMD7930_BBTB 0x05UL /* Bb-channel Transmit Buffer (W) */
76 #define AMD7930_BBRB AMD7930_BBTB /* Bb-channel Receive Buffer (R) */
77 #define AMD7930_BCTB 0x06UL /* Bc-channel Transmit Buffer (W) */
78 #define AMD7930_BCRB AMD7930_BCTB /* Bc-channel Receive Buffer (R) */
79 #define AMD7930_DSR2 0x07UL /* D-channel Status Register 2 (R) */
100 #define AMR_IR_DTTHRSH 0x01 /* D-channel xmit threshold */
101 #define AMR_IR_DRTHRSH 0x02 /* D-channel recv threshold */
102 #define AMR_IR_DSRI 0x04 /* D-channel packet status */
103 #define AMR_IR_DERI 0x08 /* D-channel error */
104 #define AMR_IR_BBUF 0x10 /* B-channel data xfer */
106 #define AMR_IR_DSR2I 0x40 /* D-channel buffer status */
345 /* Idle the AMD7930 chip. The amd->lock is not held. */
350 spin_lock_irqsave(&amd->lock, flags); in amd7930_idle()
351 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); in amd7930_idle()
352 sbus_writeb(0, amd->regs + AMD7930_DR); in amd7930_idle()
353 spin_unlock_irqrestore(&amd->lock, flags); in amd7930_idle()
356 /* Enable chip interrupts. The amd->lock is not held. */
361 spin_lock_irqsave(&amd->lock, flags); in amd7930_enable_ints()
362 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); in amd7930_enable_ints()
363 sbus_writeb(AM_INIT_ACTIVE, amd->regs + AMD7930_DR); in amd7930_enable_ints()
364 spin_unlock_irqrestore(&amd->lock, flags); in amd7930_enable_ints()
367 /* Disable chip interrupts. The amd->lock is not held. */
372 spin_lock_irqsave(&amd->lock, flags); in amd7930_disable_ints()
373 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR); in amd7930_disable_ints()
374 sbus_writeb(AM_INIT_ACTIVE | AM_INIT_DISABLE_INTS, amd->regs + AMD7930_DR); in amd7930_disable_ints()
375 spin_unlock_irqrestore(&amd->lock, flags); in amd7930_disable_ints()
379 * The amd->lock is held and local interrupts are disabled.
383 struct amd7930_map *map = &amd->map; in __amd7930_write_map()
385 sbus_writeb(AMR_MAP_GX, amd->regs + AMD7930_CR); in __amd7930_write_map()
386 sbus_writeb(((map->gx >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
387 sbus_writeb(((map->gx >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
389 sbus_writeb(AMR_MAP_GR, amd->regs + AMD7930_CR); in __amd7930_write_map()
390 sbus_writeb(((map->gr >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
391 sbus_writeb(((map->gr >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
393 sbus_writeb(AMR_MAP_STGR, amd->regs + AMD7930_CR); in __amd7930_write_map()
394 sbus_writeb(((map->stgr >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
395 sbus_writeb(((map->stgr >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
397 sbus_writeb(AMR_MAP_GER, amd->regs + AMD7930_CR); in __amd7930_write_map()
398 sbus_writeb(((map->ger >> 0) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
399 sbus_writeb(((map->ger >> 8) & 0xff), amd->regs + AMD7930_DR); in __amd7930_write_map()
401 sbus_writeb(AMR_MAP_MMR1, amd->regs + AMD7930_CR); in __amd7930_write_map()
402 sbus_writeb(map->mmr1, amd->regs + AMD7930_DR); in __amd7930_write_map()
404 sbus_writeb(AMR_MAP_MMR2, amd->regs + AMD7930_CR); in __amd7930_write_map()
405 sbus_writeb(map->mmr2, amd->regs + AMD7930_DR); in __amd7930_write_map()
411 * -18 to 0dB in .16dB steps then 0 to 12dB in .08dB steps.
449 0x431f, /* 5. dB */
450 0x331f, /* 5.5 dB */
451 0x40dd, /* 6. dB */
452 0x11dd, /* 6.5 dB */
453 0x440f, /* 7. dB */
454 0x411f, /* 7.5 dB */
455 0x311f, /* 8. dB */
456 0x5520, /* 8.5 dB */
457 0x10dd, /* 9. dB */
458 0x4211, /* 9.5 dB */
459 0x410f, /* 10. dB */
460 0x111f, /* 10.5 dB */
461 0x600b, /* 11. dB */
462 0x00dd, /* 11.5 dB */
463 0x4210, /* 12. dB */
464 0x110f, /* 13. dB */
465 0x7200, /* 14. dB */
466 0x2110, /* 15. dB */
467 0x2200, /* 15.9 dB */
468 0x000b, /* 16.9 dB */
469 0x000f /* 18. dB */
473 * The amd->lock is held and local interrupts are disabled.
477 struct amd7930_map *map = &amd->map; in __amd7930_update_map()
480 map->gx = gx_coeff[amd->rgain]; in __amd7930_update_map()
481 map->stgr = gx_coeff[amd->mgain]; in __amd7930_update_map()
482 level = (amd->pgain * (256 + ARRAY_SIZE(ger_coeff))) >> 8; in __amd7930_update_map()
484 map->ger = ger_coeff[level - 256]; in __amd7930_update_map()
485 map->gr = gx_coeff[255]; in __amd7930_update_map()
487 map->ger = ger_coeff[0]; in __amd7930_update_map()
488 map->gr = gx_coeff[level]; in __amd7930_update_map()
499 spin_lock(&amd->lock); in snd_amd7930_interrupt()
503 ir = sbus_readb(amd->regs + AMD7930_IR); in snd_amd7930_interrupt()
507 if (amd->flags & AMD7930_FLAG_PLAYBACK) { in snd_amd7930_interrupt()
508 if (amd->p_left > 0) { in snd_amd7930_interrupt()
509 byte = *(amd->p_cur++); in snd_amd7930_interrupt()
510 amd->p_left--; in snd_amd7930_interrupt()
511 sbus_writeb(byte, amd->regs + AMD7930_BBTB); in snd_amd7930_interrupt()
512 if (amd->p_left == 0) in snd_amd7930_interrupt()
515 sbus_writeb(0, amd->regs + AMD7930_BBTB); in snd_amd7930_interrupt()
516 } else if (amd->flags & AMD7930_FLAG_CAPTURE) { in snd_amd7930_interrupt()
517 byte = sbus_readb(amd->regs + AMD7930_BBRB); in snd_amd7930_interrupt()
518 if (amd->c_left > 0) { in snd_amd7930_interrupt()
519 *(amd->c_cur++) = byte; in snd_amd7930_interrupt()
520 amd->c_left--; in snd_amd7930_interrupt()
521 if (amd->c_left == 0) in snd_amd7930_interrupt()
526 spin_unlock(&amd->lock); in snd_amd7930_interrupt()
529 snd_pcm_period_elapsed(amd->playback_substream); in snd_amd7930_interrupt()
531 snd_pcm_period_elapsed(amd->capture_substream); in snd_amd7930_interrupt()
536 static int snd_amd7930_trigger(struct snd_amd7930 *amd, unsigned int flag, int cmd) in snd_amd7930_trigger() argument
541 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_trigger()
542 if (cmd == SNDRV_PCM_TRIGGER_START) { in snd_amd7930_trigger()
543 if (!(amd->flags & flag)) { in snd_amd7930_trigger()
544 amd->flags |= flag; in snd_amd7930_trigger()
547 sbus_writeb(AMR_MUX_MCR4, amd->regs + AMD7930_CR); in snd_amd7930_trigger()
548 sbus_writeb(AM_MUX_MCR4_ENABLE_INTS, amd->regs + AMD7930_DR); in snd_amd7930_trigger()
550 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { in snd_amd7930_trigger()
551 if (amd->flags & flag) { in snd_amd7930_trigger()
552 amd->flags &= ~flag; in snd_amd7930_trigger()
555 sbus_writeb(AMR_MUX_MCR4, amd->regs + AMD7930_CR); in snd_amd7930_trigger()
556 sbus_writeb(0, amd->regs + AMD7930_DR); in snd_amd7930_trigger()
559 result = -EINVAL; in snd_amd7930_trigger()
561 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_trigger()
567 int cmd) in snd_amd7930_playback_trigger() argument
570 return snd_amd7930_trigger(amd, AMD7930_FLAG_PLAYBACK, cmd); in snd_amd7930_playback_trigger()
574 int cmd) in snd_amd7930_capture_trigger() argument
577 return snd_amd7930_trigger(amd, AMD7930_FLAG_CAPTURE, cmd); in snd_amd7930_capture_trigger()
583 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_playback_prepare()
588 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_playback_prepare()
590 amd->flags |= AMD7930_FLAG_PLAYBACK; in snd_amd7930_playback_prepare()
592 /* Setup the pseudo-dma transfer pointers. */ in snd_amd7930_playback_prepare()
593 amd->p_orig = amd->p_cur = runtime->dma_area; in snd_amd7930_playback_prepare()
594 amd->p_left = size; in snd_amd7930_playback_prepare()
597 new_mmr1 = amd->map.mmr1; in snd_amd7930_playback_prepare()
598 if (runtime->format == SNDRV_PCM_FORMAT_A_LAW) in snd_amd7930_playback_prepare()
602 if (new_mmr1 != amd->map.mmr1) { in snd_amd7930_playback_prepare()
603 amd->map.mmr1 = new_mmr1; in snd_amd7930_playback_prepare()
607 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_playback_prepare()
615 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_capture_prepare()
620 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_capture_prepare()
622 amd->flags |= AMD7930_FLAG_CAPTURE; in snd_amd7930_capture_prepare()
624 /* Setup the pseudo-dma transfer pointers. */ in snd_amd7930_capture_prepare()
625 amd->c_orig = amd->c_cur = runtime->dma_area; in snd_amd7930_capture_prepare()
626 amd->c_left = size; in snd_amd7930_capture_prepare()
629 new_mmr1 = amd->map.mmr1; in snd_amd7930_capture_prepare()
630 if (runtime->format == SNDRV_PCM_FORMAT_A_LAW) in snd_amd7930_capture_prepare()
634 if (new_mmr1 != amd->map.mmr1) { in snd_amd7930_capture_prepare()
635 amd->map.mmr1 = new_mmr1; in snd_amd7930_capture_prepare()
639 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_capture_prepare()
649 if (!(amd->flags & AMD7930_FLAG_PLAYBACK)) in snd_amd7930_playback_pointer()
651 ptr = amd->p_cur - amd->p_orig; in snd_amd7930_playback_pointer()
652 return bytes_to_frames(substream->runtime, ptr); in snd_amd7930_playback_pointer()
660 if (!(amd->flags & AMD7930_FLAG_CAPTURE)) in snd_amd7930_capture_pointer()
663 ptr = amd->c_cur - amd->c_orig; in snd_amd7930_capture_pointer()
664 return bytes_to_frames(substream->runtime, ptr); in snd_amd7930_capture_pointer()
691 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_playback_open()
693 amd->playback_substream = substream; in snd_amd7930_playback_open()
694 runtime->hw = snd_amd7930_pcm_hw; in snd_amd7930_playback_open()
701 struct snd_pcm_runtime *runtime = substream->runtime; in snd_amd7930_capture_open()
703 amd->capture_substream = substream; in snd_amd7930_capture_open()
704 runtime->hw = snd_amd7930_pcm_hw; in snd_amd7930_capture_open()
712 amd->playback_substream = NULL; in snd_amd7930_playback_close()
720 amd->capture_substream = NULL; in snd_amd7930_capture_close()
745 if ((err = snd_pcm_new(amd->card, in snd_amd7930_pcm()
755 pcm->private_data = amd; in snd_amd7930_pcm()
756 pcm->info_flags = 0; in snd_amd7930_pcm()
757 strcpy(pcm->name, amd->card->shortname); in snd_amd7930_pcm()
758 amd->pcm = pcm; in snd_amd7930_pcm()
772 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_amd7930_info_volume()
773 uinfo->count = 1; in snd_amd7930_info_volume()
774 uinfo->value.integer.min = 0; in snd_amd7930_info_volume()
775 uinfo->value.integer.max = 255; in snd_amd7930_info_volume()
783 int type = kctl->private_value; in snd_amd7930_get_volume()
788 swval = &amd->mgain; in snd_amd7930_get_volume()
791 swval = &amd->rgain; in snd_amd7930_get_volume()
795 swval = &amd->pgain; in snd_amd7930_get_volume()
799 ucontrol->value.integer.value[0] = *swval; in snd_amd7930_get_volume()
808 int type = kctl->private_value; in snd_amd7930_put_volume()
813 swval = &amd->mgain; in snd_amd7930_put_volume()
816 swval = &amd->rgain; in snd_amd7930_put_volume()
820 swval = &amd->pgain; in snd_amd7930_put_volume()
824 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_put_volume()
826 if (*swval != ucontrol->value.integer.value[0]) { in snd_amd7930_put_volume()
827 *swval = ucontrol->value.integer.value[0] & 0xff; in snd_amd7930_put_volume()
833 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_put_volume()
873 if (snd_BUG_ON(!amd || !amd->card)) in snd_amd7930_mixer()
874 return -EINVAL; in snd_amd7930_mixer()
876 card = amd->card; in snd_amd7930_mixer()
877 strcpy(card->mixername, card->shortname); in snd_amd7930_mixer()
890 struct platform_device *op = amd->op; in snd_amd7930_free()
894 if (amd->irq) in snd_amd7930_free()
895 free_irq(amd->irq, amd); in snd_amd7930_free()
897 if (amd->regs) in snd_amd7930_free()
898 of_iounmap(&op->resource[0], amd->regs, in snd_amd7930_free()
899 resource_size(&op->resource[0])); in snd_amd7930_free()
908 struct snd_amd7930 *amd = device->device_data; in snd_amd7930_dev_free()
929 return -ENOMEM; in snd_amd7930_create()
931 spin_lock_init(&amd->lock); in snd_amd7930_create()
932 amd->card = card; in snd_amd7930_create()
933 amd->op = op; in snd_amd7930_create()
935 amd->regs = of_ioremap(&op->resource[0], 0, in snd_amd7930_create()
936 resource_size(&op->resource[0]), "amd7930"); in snd_amd7930_create()
937 if (!amd->regs) { in snd_amd7930_create()
938 dev_err(card->dev, in snd_amd7930_create()
939 "amd7930-%d: Unable to map chip registers.\n", dev); in snd_amd7930_create()
941 return -EIO; in snd_amd7930_create()
948 dev_err(card->dev, "amd7930-%d: Unable to grab IRQ %d\n", in snd_amd7930_create()
951 return -EBUSY; in snd_amd7930_create()
953 amd->irq = irq; in snd_amd7930_create()
957 spin_lock_irqsave(&amd->lock, flags); in snd_amd7930_create()
959 amd->rgain = 128; in snd_amd7930_create()
960 amd->pgain = 200; in snd_amd7930_create()
961 amd->mgain = 0; in snd_amd7930_create()
963 memset(&amd->map, 0, sizeof(amd->map)); in snd_amd7930_create()
964 amd->map.mmr1 = (AM_MAP_MMR1_GX | AM_MAP_MMR1_GER | in snd_amd7930_create()
966 amd->map.mmr2 = (AM_MAP_MMR2_LS | AM_MAP_MMR2_AINB); in snd_amd7930_create()
971 sbus_writeb(AMR_MUX_MCR1, amd->regs + AMD7930_CR); in snd_amd7930_create()
973 amd->regs + AMD7930_DR); in snd_amd7930_create()
975 spin_unlock_irqrestore(&amd->lock, flags); in snd_amd7930_create()
990 struct resource *rp = &op->resource[0]; in amd7930_sbus_probe()
996 irq = op->archdata.irqs[0]; in amd7930_sbus_probe()
999 return -ENODEV; in amd7930_sbus_probe()
1002 return -ENOENT; in amd7930_sbus_probe()
1005 err = snd_card_new(&op->dev, index[dev_num], id[dev_num], in amd7930_sbus_probe()
1010 strcpy(card->driver, "AMD7930"); in amd7930_sbus_probe()
1011 strcpy(card->shortname, "Sun AMD7930"); in amd7930_sbus_probe()
1012 sprintf(card->longname, "%s at 0x%02lx:0x%08Lx, irq %d", in amd7930_sbus_probe()
1013 card->shortname, in amd7930_sbus_probe()
1014 rp->flags & 0xffL, in amd7930_sbus_probe()
1015 (unsigned long long)rp->start, in amd7930_sbus_probe()
1034 amd->next = amd7930_list; in amd7930_sbus_probe()
1072 struct snd_amd7930 *next = p->next; in amd7930_exit()
1074 snd_card_free(p->card); in amd7930_exit()