Lines Matching defs:hal2

27 #include "hal2.h"
103 static u32 hal2_i_read32(struct snd_hal2 *hal2, u16 addr)
106 struct hal2_ctl_regs *regs = hal2->ctl_regs;
117 static void hal2_i_write16(struct snd_hal2 *hal2, u16 addr, u16 val)
119 struct hal2_ctl_regs *regs = hal2->ctl_regs;
129 static void hal2_i_write32(struct snd_hal2 *hal2, u16 addr, u32 val)
131 struct hal2_ctl_regs *regs = hal2->ctl_regs;
141 static void hal2_i_setbit16(struct snd_hal2 *hal2, u16 addr, u16 bit)
143 struct hal2_ctl_regs *regs = hal2->ctl_regs;
155 static void hal2_i_clearbit16(struct snd_hal2 *hal2, u16 addr, u16 bit)
157 struct hal2_ctl_regs *regs = hal2->ctl_regs;
189 struct snd_hal2 *hal2 = snd_kcontrol_chip(kcontrol);
195 tmp = hal2_i_read32(hal2, H2I_DAC_C2);
205 tmp = hal2_i_read32(hal2, H2I_ADC_C2);
221 struct snd_hal2 *hal2 = snd_kcontrol_chip(kcontrol);
230 old = hal2_i_read32(hal2, H2I_DAC_C2);
239 hal2_i_write32(hal2, H2I_DAC_C2, new);
242 old = hal2_i_read32(hal2, H2I_ADC_C2);
246 hal2_i_write32(hal2, H2I_ADC_C2, new);
274 static int hal2_mixer_create(struct snd_hal2 *hal2)
279 hal2_i_write32(hal2, H2I_DAC_C2,
282 hal2_i_write32(hal2, H2I_ADC_C2, 0);
284 err = snd_ctl_add(hal2->card,
285 snd_ctl_new1(&hal2_ctrl_headphone, hal2));
289 err = snd_ctl_add(hal2->card,
290 snd_ctl_new1(&hal2_ctrl_mic, hal2));
299 struct snd_hal2 *hal2 = dev_id;
303 if (hal2->dac.pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_INT) {
304 snd_pcm_period_elapsed(hal2->dac.substream);
307 if (hal2->adc.pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_INT) {
308 snd_pcm_period_elapsed(hal2->adc.substream);
333 static void hal2_set_dac_rate(struct snd_hal2 *hal2)
335 unsigned int master = hal2->dac.master;
336 int inc = hal2->dac.inc;
337 int mod = hal2->dac.mod;
339 hal2_i_write16(hal2, H2I_BRES1_C1, (master == 44100) ? 1 : 0);
340 hal2_i_write32(hal2, H2I_BRES1_C2,
344 static void hal2_set_adc_rate(struct snd_hal2 *hal2)
346 unsigned int master = hal2->adc.master;
347 int inc = hal2->adc.inc;
348 int mod = hal2->adc.mod;
350 hal2_i_write16(hal2, H2I_BRES2_C1, (master == 44100) ? 1 : 0);
351 hal2_i_write32(hal2, H2I_BRES2_C2,
355 static void hal2_setup_dac(struct snd_hal2 *hal2)
358 struct hal2_pbus *pbus = &hal2->dac.pbus;
365 sample_size = 2 * hal2->dac.voices;
375 hal2_i_clearbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECTX);
377 hal2_set_dac_rate(hal2);
379 hal2_i_clearbit16(hal2, H2I_DMA_END, H2I_DMA_END_CODECTX);
381 hal2_i_setbit16(hal2, H2I_DMA_DRV, (1 << pbus->pbusnr));
383 hal2_i_write16(hal2, H2I_DAC_C1, (pbus->pbusnr << H2I_C1_DMA_SHIFT)
385 | (hal2->dac.voices << H2I_C1_DATAT_SHIFT));
388 static void hal2_setup_adc(struct snd_hal2 *hal2)
391 struct hal2_pbus *pbus = &hal2->adc.pbus;
393 sample_size = 2 * hal2->adc.voices;
400 hal2_i_clearbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECR);
402 hal2_set_adc_rate(hal2);
404 hal2_i_clearbit16(hal2, H2I_DMA_END, H2I_DMA_END_CODECR);
406 hal2_i_setbit16(hal2, H2I_DMA_DRV, (1 << pbus->pbusnr));
408 hal2_i_write16(hal2, H2I_ADC_C1, (pbus->pbusnr << H2I_C1_DMA_SHIFT)
410 | (hal2->adc.voices << H2I_C1_DATAT_SHIFT));
413 static void hal2_start_dac(struct snd_hal2 *hal2)
415 struct hal2_pbus *pbus = &hal2->dac.pbus;
417 pbus->pbus->pbdma_dptr = hal2->dac.desc_dma;
420 hal2_i_setbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECTX);
423 static void hal2_start_adc(struct snd_hal2 *hal2)
425 struct hal2_pbus *pbus = &hal2->adc.pbus;
427 pbus->pbus->pbdma_dptr = hal2->adc.desc_dma;
430 hal2_i_setbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECR);
433 static inline void hal2_stop_dac(struct snd_hal2 *hal2)
435 hal2->dac.pbus.pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
439 static inline void hal2_stop_adc(struct snd_hal2 *hal2)
441 hal2->adc.pbus.pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
444 static int hal2_alloc_dmabuf(struct snd_hal2 *hal2, struct hal2_codec *codec,
447 struct device *dev = hal2->card->dev;
481 static void hal2_free_dmabuf(struct snd_hal2 *hal2, struct hal2_codec *codec,
484 struct device *dev = hal2->card->dev;
514 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
517 return hal2_alloc_dmabuf(hal2, &hal2->dac, DMA_TO_DEVICE);
522 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
524 hal2_free_dmabuf(hal2, &hal2->dac, DMA_TO_DEVICE);
530 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
532 struct hal2_codec *dac = &hal2->dac;
542 hal2_setup_dac(hal2);
548 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
552 hal2_start_dac(hal2);
555 hal2_stop_dac(hal2);
566 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
567 struct hal2_codec *dac = &hal2->dac;
576 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
577 unsigned char *buf = hal2->dac.buffer + rec->hw_data;
580 dma_sync_single_for_device(hal2->card->dev,
581 hal2->dac.buffer_dma + rec->hw_data, bytes,
588 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
589 struct hal2_codec *dac = &hal2->dac;
599 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
602 return hal2_alloc_dmabuf(hal2, &hal2->adc, DMA_FROM_DEVICE);
607 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
609 hal2_free_dmabuf(hal2, &hal2->adc, DMA_FROM_DEVICE);
615 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
617 struct hal2_codec *adc = &hal2->adc;
627 hal2_setup_adc(hal2);
633 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
637 hal2_start_adc(hal2);
640 hal2_stop_adc(hal2);
651 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
652 struct hal2_codec *adc = &hal2->adc;
661 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
662 unsigned char *buf = hal2->adc.buffer + rec->hw_data;
664 dma_sync_single_for_cpu(hal2->card->dev,
665 hal2->adc.buffer_dma + rec->hw_data, bytes,
672 struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
673 struct hal2_codec *adc = &hal2->adc;
698 static int hal2_pcm_create(struct snd_hal2 *hal2)
704 err = snd_pcm_new(hal2->card, "SGI HAL2 Audio", 0, 1, 1, &pcm);
708 pcm->private_data = hal2;
724 struct snd_hal2 *hal2 = device->device_data;
726 free_irq(SGI_HPCDMA_IRQ, hal2);
727 kfree(hal2);
742 static int hal2_detect(struct snd_hal2 *hal2)
748 hal2_write(0, &hal2->ctl_regs->isr);
752 &hal2->ctl_regs->isr);
755 hal2_i_write16(hal2, H2I_RELAY_C, H2I_RELAY_C_STATE);
756 rev = hal2_read(&hal2->ctl_regs->rev);
772 struct snd_hal2 *hal2;
776 hal2 = kzalloc(sizeof(*hal2), GFP_KERNEL);
777 if (!hal2)
780 hal2->card = card;
783 "SGI HAL2", hal2)) {
785 kfree(hal2);
789 hal2->ctl_regs = (struct hal2_ctl_regs *)hpc3->pbus_extregs[0];
790 hal2->aes_regs = (struct hal2_aes_regs *)hpc3->pbus_extregs[1];
791 hal2->vol_regs = (struct hal2_vol_regs *)hpc3->pbus_extregs[2];
792 hal2->syn_regs = (struct hal2_syn_regs *)hpc3->pbus_extregs[3];
794 if (hal2_detect(hal2) < 0) {
795 kfree(hal2);
799 hal2_init_codec(&hal2->dac, hpc3, 0);
800 hal2_init_codec(&hal2->adc, hpc3, 1);
825 hpc3->pbus_dmacfg[hal2->dac.pbus.pbusnr][0] = 0x8208844;
826 hpc3->pbus_dmacfg[hal2->adc.pbus.pbusnr][0] = 0x8208844;
828 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, hal2, &hal2_ops);
830 free_irq(SGI_HPCDMA_IRQ, hal2);
831 kfree(hal2);
834 *rchip = hal2;