Lines Matching +full:adc +full:- +full:tm

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Based on OSS code from Ladislav Michl <ladis@linux-mips.org>, which
12 #include <linux/dma-mapping.h>
24 #include <sound/pcm-indirect.h>
29 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
47 unsigned int ctrl; /* Current state of pbus->pbdma_ctrl */
84 struct hal2_codec adc; member
87 #define H2_INDIRECT_WAIT(regs) while (hal2_read(&regs->isr) & H2_ISR_TSTATUS);
106 struct hal2_ctl_regs *regs = hal2->ctl_regs; in hal2_i_read32()
108 hal2_write(H2_READ_ADDR(addr), &regs->iar); in hal2_i_read32()
110 ret = hal2_read(&regs->idr0) & 0xffff; in hal2_i_read32()
111 hal2_write(H2_READ_ADDR(addr) | 0x1, &regs->iar); in hal2_i_read32()
113 ret |= (hal2_read(&regs->idr0) & 0xffff) << 16; in hal2_i_read32()
119 struct hal2_ctl_regs *regs = hal2->ctl_regs; in hal2_i_write16()
121 hal2_write(val, &regs->idr0); in hal2_i_write16()
122 hal2_write(0, &regs->idr1); in hal2_i_write16()
123 hal2_write(0, &regs->idr2); in hal2_i_write16()
124 hal2_write(0, &regs->idr3); in hal2_i_write16()
125 hal2_write(H2_WRITE_ADDR(addr), &regs->iar); in hal2_i_write16()
131 struct hal2_ctl_regs *regs = hal2->ctl_regs; in hal2_i_write32()
133 hal2_write(val & 0xffff, &regs->idr0); in hal2_i_write32()
134 hal2_write(val >> 16, &regs->idr1); in hal2_i_write32()
135 hal2_write(0, &regs->idr2); in hal2_i_write32()
136 hal2_write(0, &regs->idr3); in hal2_i_write32()
137 hal2_write(H2_WRITE_ADDR(addr), &regs->iar); in hal2_i_write32()
143 struct hal2_ctl_regs *regs = hal2->ctl_regs; in hal2_i_setbit16()
145 hal2_write(H2_READ_ADDR(addr), &regs->iar); in hal2_i_setbit16()
147 hal2_write((hal2_read(&regs->idr0) & 0xffff) | bit, &regs->idr0); in hal2_i_setbit16()
148 hal2_write(0, &regs->idr1); in hal2_i_setbit16()
149 hal2_write(0, &regs->idr2); in hal2_i_setbit16()
150 hal2_write(0, &regs->idr3); in hal2_i_setbit16()
151 hal2_write(H2_WRITE_ADDR(addr), &regs->iar); in hal2_i_setbit16()
157 struct hal2_ctl_regs *regs = hal2->ctl_regs; in hal2_i_clearbit16()
159 hal2_write(H2_READ_ADDR(addr), &regs->iar); in hal2_i_clearbit16()
161 hal2_write((hal2_read(&regs->idr0) & 0xffff) & ~bit, &regs->idr0); in hal2_i_clearbit16()
162 hal2_write(0, &regs->idr1); in hal2_i_clearbit16()
163 hal2_write(0, &regs->idr2); in hal2_i_clearbit16()
164 hal2_write(0, &regs->idr3); in hal2_i_clearbit16()
165 hal2_write(H2_WRITE_ADDR(addr), &regs->iar); in hal2_i_clearbit16()
172 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in hal2_gain_info()
173 uinfo->count = 2; in hal2_gain_info()
174 uinfo->value.integer.min = 0; in hal2_gain_info()
175 switch ((int)kcontrol->private_value) { in hal2_gain_info()
177 uinfo->value.integer.max = 31; in hal2_gain_info()
180 uinfo->value.integer.max = 15; in hal2_gain_info()
193 switch ((int)kcontrol->private_value) { in hal2_gain_get()
200 l = 31 - ((tmp >> H2I_C2_L_ATT_SHIFT) & 31); in hal2_gain_get()
201 r = 31 - ((tmp >> H2I_C2_R_ATT_SHIFT) & 31); in hal2_gain_get()
210 return -EINVAL; in hal2_gain_get()
212 ucontrol->value.integer.value[0] = l; in hal2_gain_get()
213 ucontrol->value.integer.value[1] = r; in hal2_gain_get()
225 l = ucontrol->value.integer.value[0]; in hal2_gain_put()
226 r = ucontrol->value.integer.value[1]; in hal2_gain_put()
228 switch ((int)kcontrol->private_value) { in hal2_gain_put()
233 l = 31 - l; in hal2_gain_put()
234 r = 31 - r; in hal2_gain_put()
249 return -EINVAL; in hal2_gain_put()
281 /* mute ADC */ in hal2_mixer_create()
284 err = snd_ctl_add(hal2->card, in hal2_mixer_create()
289 err = snd_ctl_add(hal2->card, in hal2_mixer_create()
303 if (hal2->dac.pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_INT) { in hal2_interrupt()
304 snd_pcm_period_elapsed(hal2->dac.substream); in hal2_interrupt()
307 if (hal2->adc.pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_INT) { in hal2_interrupt()
308 snd_pcm_period_elapsed(hal2->adc.substream); in hal2_interrupt()
320 codec->master = 44100; in hal2_compute_rate()
323 codec->master = 48000; in hal2_compute_rate()
326 codec->inc = 4; in hal2_compute_rate()
327 codec->mod = mod; in hal2_compute_rate()
328 rate = 4 * codec->master / mod; in hal2_compute_rate()
335 unsigned int master = hal2->dac.master; in hal2_set_dac_rate()
336 int inc = hal2->dac.inc; in hal2_set_dac_rate()
337 int mod = hal2->dac.mod; in hal2_set_dac_rate()
341 ((0xffff & (inc - mod - 1)) << 16) | inc); in hal2_set_dac_rate()
346 unsigned int master = hal2->adc.master; in hal2_set_adc_rate()
347 int inc = hal2->adc.inc; in hal2_set_adc_rate()
348 int mod = hal2->adc.mod; in hal2_set_adc_rate()
352 ((0xffff & (inc - mod - 1)) << 16) | inc); in hal2_set_adc_rate()
358 struct hal2_pbus *pbus = &hal2->dac.pbus; in hal2_setup_dac()
365 sample_size = 2 * hal2->dac.voices; in hal2_setup_dac()
371 pbus->ctrl = HPC3_PDMACTRL_RT | HPC3_PDMACTRL_LD | in hal2_setup_dac()
374 pbus->pbus->pbdma_ctrl = HPC3_PDMACTRL_LD; in hal2_setup_dac()
381 hal2_i_setbit16(hal2, H2I_DMA_DRV, (1 << pbus->pbusnr)); in hal2_setup_dac()
383 hal2_i_write16(hal2, H2I_DAC_C1, (pbus->pbusnr << H2I_C1_DMA_SHIFT) in hal2_setup_dac()
385 | (hal2->dac.voices << H2I_C1_DATAT_SHIFT)); in hal2_setup_dac()
391 struct hal2_pbus *pbus = &hal2->adc.pbus; in hal2_setup_adc()
393 sample_size = 2 * hal2->adc.voices; in hal2_setup_adc()
397 pbus->ctrl = HPC3_PDMACTRL_RT | HPC3_PDMACTRL_RCV | HPC3_PDMACTRL_LD | in hal2_setup_adc()
399 pbus->pbus->pbdma_ctrl = HPC3_PDMACTRL_LD; in hal2_setup_adc()
406 hal2_i_setbit16(hal2, H2I_DMA_DRV, (1 << pbus->pbusnr)); in hal2_setup_adc()
408 hal2_i_write16(hal2, H2I_ADC_C1, (pbus->pbusnr << H2I_C1_DMA_SHIFT) in hal2_setup_adc()
410 | (hal2->adc.voices << H2I_C1_DATAT_SHIFT)); in hal2_setup_adc()
415 struct hal2_pbus *pbus = &hal2->dac.pbus; in hal2_start_dac()
417 pbus->pbus->pbdma_dptr = hal2->dac.desc_dma; in hal2_start_dac()
418 pbus->pbus->pbdma_ctrl = pbus->ctrl | HPC3_PDMACTRL_ACT; in hal2_start_dac()
425 struct hal2_pbus *pbus = &hal2->adc.pbus; in hal2_start_adc()
427 pbus->pbus->pbdma_dptr = hal2->adc.desc_dma; in hal2_start_adc()
428 pbus->pbus->pbdma_ctrl = pbus->ctrl | HPC3_PDMACTRL_ACT; in hal2_start_adc()
429 /* enable ADC */ in hal2_start_adc()
435 hal2->dac.pbus.pbus->pbdma_ctrl = HPC3_PDMACTRL_LD; in hal2_stop_dac()
441 hal2->adc.pbus.pbus->pbdma_ctrl = HPC3_PDMACTRL_LD; in hal2_stop_adc()
447 struct device *dev = hal2->card->dev; in hal2_alloc_dmabuf()
453 codec->buffer = dma_alloc_noncoherent(dev, H2_BUF_SIZE, &buffer_dma, in hal2_alloc_dmabuf()
455 if (!codec->buffer) in hal2_alloc_dmabuf()
456 return -ENOMEM; in hal2_alloc_dmabuf()
460 dma_free_noncoherent(dev, H2_BUF_SIZE, codec->buffer, buffer_dma, in hal2_alloc_dmabuf()
462 return -ENOMEM; in hal2_alloc_dmabuf()
464 codec->buffer_dma = buffer_dma; in hal2_alloc_dmabuf()
465 codec->desc_dma = desc_dma; in hal2_alloc_dmabuf()
466 codec->desc = desc; in hal2_alloc_dmabuf()
468 desc->desc.pbuf = buffer_dma + i * H2_BLOCK_SIZE; in hal2_alloc_dmabuf()
469 desc->desc.cntinfo = HPCDMA_XIE | H2_BLOCK_SIZE; in hal2_alloc_dmabuf()
470 desc->desc.pnext = (i == count - 1) ? in hal2_alloc_dmabuf()
474 dma_sync_single_for_device(dev, codec->desc_dma, in hal2_alloc_dmabuf()
477 codec->desc_count = count; in hal2_alloc_dmabuf()
484 struct device *dev = hal2->card->dev; in hal2_free_dmabuf()
486 dma_free_noncoherent(dev, codec->desc_count * sizeof(struct hal2_desc), in hal2_free_dmabuf()
487 codec->desc, codec->desc_dma, DMA_BIDIRECTIONAL); in hal2_free_dmabuf()
488 dma_free_noncoherent(dev, H2_BUF_SIZE, codec->buffer, codec->buffer_dma, in hal2_free_dmabuf()
513 struct snd_pcm_runtime *runtime = substream->runtime; in hal2_playback_open()
516 runtime->hw = hal2_pcm_hw; in hal2_playback_open()
517 return hal2_alloc_dmabuf(hal2, &hal2->dac, DMA_TO_DEVICE); in hal2_playback_open()
524 hal2_free_dmabuf(hal2, &hal2->dac, DMA_TO_DEVICE); in hal2_playback_close()
531 struct snd_pcm_runtime *runtime = substream->runtime; in hal2_playback_prepare()
532 struct hal2_codec *dac = &hal2->dac; in hal2_playback_prepare()
534 dac->voices = runtime->channels; in hal2_playback_prepare()
535 dac->sample_rate = hal2_compute_rate(dac, runtime->rate); in hal2_playback_prepare()
536 memset(&dac->pcm_indirect, 0, sizeof(dac->pcm_indirect)); in hal2_playback_prepare()
537 dac->pcm_indirect.hw_buffer_size = H2_BUF_SIZE; in hal2_playback_prepare()
538 dac->pcm_indirect.hw_queue_size = H2_BUF_SIZE / 2; in hal2_playback_prepare()
539 dac->pcm_indirect.hw_io = dac->buffer_dma; in hal2_playback_prepare()
540 dac->pcm_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); in hal2_playback_prepare()
541 dac->substream = substream; in hal2_playback_prepare()
558 return -EINVAL; in hal2_playback_trigger()
567 struct hal2_codec *dac = &hal2->dac; in hal2_playback_pointer()
569 return snd_pcm_indirect_playback_pointer(substream, &dac->pcm_indirect, in hal2_playback_pointer()
570 dac->pbus.pbus->pbdma_bptr); in hal2_playback_pointer()
577 unsigned char *buf = hal2->dac.buffer + rec->hw_data; in hal2_playback_transfer()
579 memcpy(buf, substream->runtime->dma_area + rec->sw_data, bytes); in hal2_playback_transfer()
580 dma_sync_single_for_device(hal2->card->dev, in hal2_playback_transfer()
581 hal2->dac.buffer_dma + rec->hw_data, bytes, in hal2_playback_transfer()
589 struct hal2_codec *dac = &hal2->dac; in hal2_playback_ack()
592 &dac->pcm_indirect, in hal2_playback_ack()
598 struct snd_pcm_runtime *runtime = substream->runtime; in hal2_capture_open()
601 runtime->hw = hal2_pcm_hw; in hal2_capture_open()
602 return hal2_alloc_dmabuf(hal2, &hal2->adc, DMA_FROM_DEVICE); in hal2_capture_open()
609 hal2_free_dmabuf(hal2, &hal2->adc, DMA_FROM_DEVICE); in hal2_capture_close()
616 struct snd_pcm_runtime *runtime = substream->runtime; in hal2_capture_prepare()
617 struct hal2_codec *adc = &hal2->adc; in hal2_capture_prepare() local
619 adc->voices = runtime->channels; in hal2_capture_prepare()
620 adc->sample_rate = hal2_compute_rate(adc, runtime->rate); in hal2_capture_prepare()
621 memset(&adc->pcm_indirect, 0, sizeof(adc->pcm_indirect)); in hal2_capture_prepare()
622 adc->pcm_indirect.hw_buffer_size = H2_BUF_SIZE; in hal2_capture_prepare()
623 adc->pcm_indirect.hw_queue_size = H2_BUF_SIZE / 2; in hal2_capture_prepare()
624 adc->pcm_indirect.hw_io = adc->buffer_dma; in hal2_capture_prepare()
625 adc->pcm_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); in hal2_capture_prepare()
626 adc->substream = substream; in hal2_capture_prepare()
643 return -EINVAL; in hal2_capture_trigger()
652 struct hal2_codec *adc = &hal2->adc; in hal2_capture_pointer() local
654 return snd_pcm_indirect_capture_pointer(substream, &adc->pcm_indirect, in hal2_capture_pointer()
655 adc->pbus.pbus->pbdma_bptr); in hal2_capture_pointer()
662 unsigned char *buf = hal2->adc.buffer + rec->hw_data; in hal2_capture_transfer()
664 dma_sync_single_for_cpu(hal2->card->dev, in hal2_capture_transfer()
665 hal2->adc.buffer_dma + rec->hw_data, bytes, in hal2_capture_transfer()
667 memcpy(substream->runtime->dma_area + rec->sw_data, buf, bytes); in hal2_capture_transfer()
673 struct hal2_codec *adc = &hal2->adc; in hal2_capture_ack() local
676 &adc->pcm_indirect, in hal2_capture_ack()
704 err = snd_pcm_new(hal2->card, "SGI HAL2 Audio", 0, 1, 1, &pcm); in hal2_pcm_create()
708 pcm->private_data = hal2; in hal2_pcm_create()
709 strcpy(pcm->name, "SGI HAL2"); in hal2_pcm_create()
724 struct snd_hal2 *hal2 = device->device_data; in hal2_dev_free()
738 codec->pbus.pbusnr = index; in hal2_init_codec()
739 codec->pbus.pbus = &hpc3->pbdma[index]; in hal2_init_codec()
748 hal2_write(0, &hal2->ctl_regs->isr); in hal2_detect()
752 &hal2->ctl_regs->isr); in hal2_detect()
756 rev = hal2_read(&hal2->ctl_regs->rev); in hal2_detect()
758 return -ENODEV; in hal2_detect()
778 return -ENOMEM; in hal2_create()
780 hal2->card = card; in hal2_create()
786 return -EAGAIN; in hal2_create()
789 hal2->ctl_regs = (struct hal2_ctl_regs *)hpc3->pbus_extregs[0]; in hal2_create()
790 hal2->aes_regs = (struct hal2_aes_regs *)hpc3->pbus_extregs[1]; in hal2_create()
791 hal2->vol_regs = (struct hal2_vol_regs *)hpc3->pbus_extregs[2]; in hal2_create()
792 hal2->syn_regs = (struct hal2_syn_regs *)hpc3->pbus_extregs[3]; in hal2_create()
796 return -ENODEV; in hal2_create()
799 hal2_init_codec(&hal2->dac, hpc3, 0); in hal2_create()
800 hal2_init_codec(&hal2->adc, hpc3, 1); in hal2_create()
805 * in D5. HAL2 is a 16-bit device which can accept both big and little in hal2_create()
823 * works in The Real World (TM) in hal2_create()
825 hpc3->pbus_dmacfg[hal2->dac.pbus.pbusnr][0] = 0x8208844; in hal2_create()
826 hpc3->pbus_dmacfg[hal2->adc.pbus.pbusnr][0] = 0x8208844; in hal2_create()
844 err = snd_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card); in hal2_probe()
865 strcpy(card->driver, "SGI HAL2 Audio"); in hal2_probe()
866 strcpy(card->shortname, "SGI HAL2 Audio"); in hal2_probe()
867 sprintf(card->longname, "%s irq %i", in hal2_probe()
868 card->shortname, in hal2_probe()