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. */
349 guard(spinlock_irqsave)(&amd->lock);
350 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR);
351 sbus_writeb(0, amd->regs + AMD7930_DR);
354 /* Enable chip interrupts. The amd->lock is not held. */
357 guard(spinlock_irqsave)(&amd->lock);
358 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR);
359 sbus_writeb(AM_INIT_ACTIVE, amd->regs + AMD7930_DR);
362 /* Disable chip interrupts. The amd->lock is not held. */
365 guard(spinlock_irqsave)(&amd->lock);
366 sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR);
367 sbus_writeb(AM_INIT_ACTIVE | AM_INIT_DISABLE_INTS, amd->regs + AMD7930_DR);
371 * The amd->lock is held and local interrupts are disabled.
375 struct amd7930_map *map = &amd->map;
377 sbus_writeb(AMR_MAP_GX, amd->regs + AMD7930_CR);
378 sbus_writeb(((map->gx >> 0) & 0xff), amd->regs + AMD7930_DR);
379 sbus_writeb(((map->gx >> 8) & 0xff), amd->regs + AMD7930_DR);
381 sbus_writeb(AMR_MAP_GR, amd->regs + AMD7930_CR);
382 sbus_writeb(((map->gr >> 0) & 0xff), amd->regs + AMD7930_DR);
383 sbus_writeb(((map->gr >> 8) & 0xff), amd->regs + AMD7930_DR);
385 sbus_writeb(AMR_MAP_STGR, amd->regs + AMD7930_CR);
386 sbus_writeb(((map->stgr >> 0) & 0xff), amd->regs + AMD7930_DR);
387 sbus_writeb(((map->stgr >> 8) & 0xff), amd->regs + AMD7930_DR);
389 sbus_writeb(AMR_MAP_GER, amd->regs + AMD7930_CR);
390 sbus_writeb(((map->ger >> 0) & 0xff), amd->regs + AMD7930_DR);
391 sbus_writeb(((map->ger >> 8) & 0xff), amd->regs + AMD7930_DR);
393 sbus_writeb(AMR_MAP_MMR1, amd->regs + AMD7930_CR);
394 sbus_writeb(map->mmr1, amd->regs + AMD7930_DR);
396 sbus_writeb(AMR_MAP_MMR2, amd->regs + AMD7930_CR);
397 sbus_writeb(map->mmr2, amd->regs + AMD7930_DR);
403 * -18 to 0dB in .16dB steps then 0 to 12dB in .08dB steps.
441 0x431f, /* 5. dB */
442 0x331f, /* 5.5 dB */
443 0x40dd, /* 6. dB */
444 0x11dd, /* 6.5 dB */
445 0x440f, /* 7. dB */
446 0x411f, /* 7.5 dB */
447 0x311f, /* 8. dB */
448 0x5520, /* 8.5 dB */
449 0x10dd, /* 9. dB */
450 0x4211, /* 9.5 dB */
451 0x410f, /* 10. dB */
452 0x111f, /* 10.5 dB */
453 0x600b, /* 11. dB */
454 0x00dd, /* 11.5 dB */
455 0x4210, /* 12. dB */
456 0x110f, /* 13. dB */
457 0x7200, /* 14. dB */
458 0x2110, /* 15. dB */
459 0x2200, /* 15.9 dB */
460 0x000b, /* 16.9 dB */
461 0x000f /* 18. dB */
465 * The amd->lock is held and local interrupts are disabled.
469 struct amd7930_map *map = &amd->map;
472 map->gx = gx_coeff[amd->rgain];
473 map->stgr = gx_coeff[amd->mgain];
474 level = (amd->pgain * (256 + ARRAY_SIZE(ger_coeff))) >> 8;
476 map->ger = ger_coeff[level - 256];
477 map->gr = gx_coeff[255];
479 map->ger = ger_coeff[0];
480 map->gr = gx_coeff[level];
491 scoped_guard(spinlock, &amd->lock) {
494 ir = sbus_readb(amd->regs + AMD7930_IR);
498 if (amd->flags & AMD7930_FLAG_PLAYBACK) {
499 if (amd->p_left > 0) {
500 byte = *(amd->p_cur++);
501 amd->p_left--;
502 sbus_writeb(byte, amd->regs + AMD7930_BBTB);
503 if (amd->p_left == 0)
506 sbus_writeb(0, amd->regs + AMD7930_BBTB);
507 } else if (amd->flags & AMD7930_FLAG_CAPTURE) {
508 byte = sbus_readb(amd->regs + AMD7930_BBRB);
509 if (amd->c_left > 0) {
510 *(amd->c_cur++) = byte;
511 amd->c_left--;
512 if (amd->c_left == 0)
520 snd_pcm_period_elapsed(amd->playback_substream);
522 snd_pcm_period_elapsed(amd->capture_substream);
527 static int snd_amd7930_trigger(struct snd_amd7930 *amd, unsigned int flag, int cmd)
531 guard(spinlock_irqsave)(&amd->lock);
532 if (cmd == SNDRV_PCM_TRIGGER_START) {
533 if (!(amd->flags & flag)) {
534 amd->flags |= flag;
537 sbus_writeb(AMR_MUX_MCR4, amd->regs + AMD7930_CR);
538 sbus_writeb(AM_MUX_MCR4_ENABLE_INTS, amd->regs + AMD7930_DR);
540 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
541 if (amd->flags & flag) {
542 amd->flags &= ~flag;
545 sbus_writeb(AMR_MUX_MCR4, amd->regs + AMD7930_CR);
546 sbus_writeb(0, amd->regs + AMD7930_DR);
549 result = -EINVAL;
556 int cmd)
559 return snd_amd7930_trigger(amd, AMD7930_FLAG_PLAYBACK, cmd);
563 int cmd)
566 return snd_amd7930_trigger(amd, AMD7930_FLAG_CAPTURE, cmd);
572 struct snd_pcm_runtime *runtime = substream->runtime;
576 guard(spinlock_irqsave)(&amd->lock);
578 amd->flags |= AMD7930_FLAG_PLAYBACK;
580 /* Setup the pseudo-dma transfer pointers. */
581 amd->p_orig = amd->p_cur = runtime->dma_area;
582 amd->p_left = size;
585 new_mmr1 = amd->map.mmr1;
586 if (runtime->format == SNDRV_PCM_FORMAT_A_LAW)
590 if (new_mmr1 != amd->map.mmr1) {
591 amd->map.mmr1 = new_mmr1;
601 struct snd_pcm_runtime *runtime = substream->runtime;
605 guard(spinlock_irqsave)(&amd->lock);
607 amd->flags |= AMD7930_FLAG_CAPTURE;
609 /* Setup the pseudo-dma transfer pointers. */
610 amd->c_orig = amd->c_cur = runtime->dma_area;
611 amd->c_left = size;
614 new_mmr1 = amd->map.mmr1;
615 if (runtime->format == SNDRV_PCM_FORMAT_A_LAW)
619 if (new_mmr1 != amd->map.mmr1) {
620 amd->map.mmr1 = new_mmr1;
632 if (!(amd->flags & AMD7930_FLAG_PLAYBACK))
634 ptr = amd->p_cur - amd->p_orig;
635 return bytes_to_frames(substream->runtime, ptr);
643 if (!(amd->flags & AMD7930_FLAG_CAPTURE))
646 ptr = amd->c_cur - amd->c_orig;
647 return bytes_to_frames(substream->runtime, ptr);
674 struct snd_pcm_runtime *runtime = substream->runtime;
676 amd->playback_substream = substream;
677 runtime->hw = snd_amd7930_pcm_hw;
684 struct snd_pcm_runtime *runtime = substream->runtime;
686 amd->capture_substream = substream;
687 runtime->hw = snd_amd7930_pcm_hw;
695 amd->playback_substream = NULL;
703 amd->capture_substream = NULL;
728 if ((err = snd_pcm_new(amd->card,
738 pcm->private_data = amd;
739 pcm->info_flags = 0;
740 strscpy(pcm->name, amd->card->shortname);
741 amd->pcm = pcm;
755 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
756 uinfo->count = 1;
757 uinfo->value.integer.min = 0;
758 uinfo->value.integer.max = 255;
766 int type = kctl->private_value;
771 swval = &amd->mgain;
774 swval = &amd->rgain;
778 swval = &amd->pgain;
782 ucontrol->value.integer.value[0] = *swval;
790 int type = kctl->private_value;
795 swval = &amd->mgain;
798 swval = &amd->rgain;
802 swval = &amd->pgain;
806 guard(spinlock_irqsave)(&amd->lock);
808 if (*swval != ucontrol->value.integer.value[0]) {
809 *swval = ucontrol->value.integer.value[0] & 0xff;
853 if (snd_BUG_ON(!amd || !amd->card))
854 return -EINVAL;
856 card = amd->card;
857 strscpy(card->mixername, card->shortname);
870 struct platform_device *op = amd->op;
874 if (amd->irq)
875 free_irq(amd->irq, amd);
877 if (amd->regs)
878 of_iounmap(&op->resource[0], amd->regs,
879 resource_size(&op->resource[0]));
888 struct snd_amd7930 *amd = device->device_data;
908 return -ENOMEM;
910 spin_lock_init(&amd->lock);
911 amd->card = card;
912 amd->op = op;
914 amd->regs = of_ioremap(&op->resource[0], 0,
915 resource_size(&op->resource[0]), "amd7930");
916 if (!amd->regs) {
917 dev_err(card->dev,
918 "amd7930-%d: Unable to map chip registers.\n", dev);
920 return -EIO;
927 dev_err(card->dev, "amd7930-%d: Unable to grab IRQ %d\n",
930 return -EBUSY;
932 amd->irq = irq;
936 scoped_guard(spinlock_irqsave, &amd->lock) {
937 amd->rgain = 128;
938 amd->pgain = 200;
939 amd->mgain = 0;
941 memset(&amd->map, 0, sizeof(amd->map));
942 amd->map.mmr1 = (AM_MAP_MMR1_GX | AM_MAP_MMR1_GER |
944 amd->map.mmr2 = (AM_MAP_MMR2_LS | AM_MAP_MMR2_AINB);
949 sbus_writeb(AMR_MUX_MCR1, amd->regs + AMD7930_CR);
951 amd->regs + AMD7930_DR);
967 struct resource *rp = &op->resource[0];
973 irq = op->archdata.irqs[0];
976 return -ENODEV;
979 return -ENOENT;
982 err = snd_card_new(&op->dev, index[dev_num], id[dev_num],
987 strscpy(card->driver, "AMD7930");
988 strscpy(card->shortname, "Sun AMD7930");
989 sprintf(card->longname, "%s at 0x%02lx:0x%08Lx, irq %d",
990 card->shortname,
991 rp->flags & 0xffL,
992 (unsigned long long)rp->start,
1011 amd->next = amd7930_list;
1049 struct snd_amd7930 *next = p->next;
1051 snd_card_free(p->card);