Lines Matching full:codec
141 #define ALI_REG(codec, x) ((codec)->port + x) argument
180 struct snd_ali *codec; member
264 static inline unsigned int snd_ali_5451_peek(struct snd_ali *codec, in snd_ali_5451_peek() argument
267 return (unsigned int)inl(ALI_REG(codec, port)); in snd_ali_5451_peek()
270 static inline void snd_ali_5451_poke(struct snd_ali *codec, in snd_ali_5451_poke() argument
274 outl((unsigned int)val, ALI_REG(codec, port)); in snd_ali_5451_poke()
277 static int snd_ali_codec_ready(struct snd_ali *codec, in snd_ali_codec_ready() argument
286 res = snd_ali_5451_peek(codec,port); in snd_ali_codec_ready()
294 snd_ali_5451_poke(codec, port, res & ~0x8000); in snd_ali_codec_ready()
295 dev_dbg(codec->card->dev, "ali_codec_ready: codec is not ready.\n"); in snd_ali_codec_ready()
299 static int snd_ali_stimer_ready(struct snd_ali *codec) in snd_ali_stimer_ready() argument
304 dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER); in snd_ali_stimer_ready()
308 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); in snd_ali_stimer_ready()
316 dev_err(codec->card->dev, "ali_stimer_read: stimer is not ready.\n"); in snd_ali_stimer_ready()
320 static void snd_ali_codec_poke(struct snd_ali *codec,int secondary, in snd_ali_codec_poke() argument
328 dev_err(codec->card->dev, in snd_ali_codec_poke()
333 port = codec->chregs.regs.ac97write; in snd_ali_codec_poke()
335 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_poke()
337 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_poke()
344 if (codec->revision == ALI_5451_V02) in snd_ali_codec_poke()
347 snd_ali_5451_poke(codec, port, dwVal); in snd_ali_codec_poke()
352 static unsigned short snd_ali_codec_peek(struct snd_ali *codec, in snd_ali_codec_peek() argument
360 dev_err(codec->card->dev, in snd_ali_codec_peek()
365 port = codec->chregs.regs.ac97read; in snd_ali_codec_peek()
367 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_peek()
369 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_peek()
377 snd_ali_5451_poke(codec, port, dwVal); in snd_ali_codec_peek()
379 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_peek()
381 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_peek()
384 return (snd_ali_5451_peek(codec, port) & 0xffff0000) >> 16; in snd_ali_codec_peek()
391 struct snd_ali *codec = ac97->private_data; in snd_ali_codec_write() local
393 dev_dbg(codec->card->dev, "codec_write: reg=%xh data=%xh.\n", reg, val); in snd_ali_codec_write()
396 ALI_REG(codec, ALI_AC97_GPIO)); in snd_ali_codec_write()
399 snd_ali_codec_poke(codec, ac97->num, reg, val); in snd_ali_codec_write()
407 struct snd_ali *codec = ac97->private_data; in snd_ali_codec_read() local
409 dev_dbg(codec->card->dev, "codec_read reg=%xh.\n", reg); in snd_ali_codec_read()
410 return snd_ali_codec_peek(codec, ac97->num, reg); in snd_ali_codec_read()
417 static int snd_ali_reset_5451(struct snd_ali *codec) in snd_ali_reset_5451() argument
423 pci_dev = codec->pci_m1533; in snd_ali_reset_5451()
433 pci_dev = codec->pci; in snd_ali_reset_5451()
443 wReg = snd_ali_codec_peek(codec, 0, AC97_POWERDOWN); in snd_ali_reset_5451()
449 /* non-fatal if you have a non PM capable codec */ in snd_ali_reset_5451()
450 /* dev_warn(codec->card->dev, "ali5451: reset time out\n"); */ in snd_ali_reset_5451()
458 static void snd_ali_enable_special_channel(struct snd_ali *codec, in snd_ali_enable_special_channel() argument
463 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_special_channel()
465 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_special_channel()
468 static void snd_ali_disable_special_channel(struct snd_ali *codec, in snd_ali_disable_special_channel() argument
473 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_special_channel()
475 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_special_channel()
478 static void snd_ali_enable_address_interrupt(struct snd_ali *codec) in snd_ali_enable_address_interrupt() argument
482 gc = inl(ALI_REG(codec, ALI_GC_CIR)); in snd_ali_enable_address_interrupt()
485 outl( gc, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_enable_address_interrupt()
488 static void snd_ali_disable_address_interrupt(struct snd_ali *codec) in snd_ali_disable_address_interrupt() argument
492 gc = inl(ALI_REG(codec, ALI_GC_CIR)); in snd_ali_disable_address_interrupt()
495 outl(gc, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_disable_address_interrupt()
498 static void snd_ali_disable_voice_irq(struct snd_ali *codec, in snd_ali_disable_voice_irq() argument
502 struct snd_ali_channel_control *pchregs = &(codec->chregs); in snd_ali_disable_voice_irq()
504 dev_dbg(codec->card->dev, "disable_voice_irq channel=%d\n", channel); in snd_ali_disable_voice_irq()
507 pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten)); in snd_ali_disable_voice_irq()
509 outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten)); in snd_ali_disable_voice_irq()
512 static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel) in snd_ali_alloc_pcm_channel() argument
516 if (codec->synth.chcnt >= ALI_CHANNELS){ in snd_ali_alloc_pcm_channel()
517 dev_err(codec->card->dev, in snd_ali_alloc_pcm_channel()
522 if (!(codec->synth.chmap & (1 << idx))) { in snd_ali_alloc_pcm_channel()
523 codec->synth.chmap |= 1 << idx; in snd_ali_alloc_pcm_channel()
524 codec->synth.chcnt++; in snd_ali_alloc_pcm_channel()
525 dev_dbg(codec->card->dev, "alloc_pcm_channel no. %d.\n", idx); in snd_ali_alloc_pcm_channel()
531 static int snd_ali_find_free_channel(struct snd_ali * codec, int rec) in snd_ali_find_free_channel() argument
536 dev_dbg(codec->card->dev, in snd_ali_find_free_channel()
541 if (codec->spdif_support && in snd_ali_find_free_channel()
542 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_find_free_channel()
548 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
552 dev_err(codec->card->dev, in snd_ali_find_free_channel()
559 if (codec->spdif_support && in snd_ali_find_free_channel()
560 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_find_free_channel()
563 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
567 dev_err(codec->card->dev, in snd_ali_find_free_channel()
572 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
576 dev_err(codec->card->dev, "ali_find_free_channel: no free channels.\n"); in snd_ali_find_free_channel()
580 static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel) in snd_ali_free_channel_pcm() argument
584 dev_dbg(codec->card->dev, "free_channel_pcm channel=%d\n", channel); in snd_ali_free_channel_pcm()
589 if (!(codec->synth.chmap & (1 << idx))) { in snd_ali_free_channel_pcm()
590 dev_err(codec->card->dev, in snd_ali_free_channel_pcm()
595 codec->synth.chmap &= ~(1 << idx); in snd_ali_free_channel_pcm()
596 codec->synth.chcnt--; in snd_ali_free_channel_pcm()
600 static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel) in snd_ali_stop_voice() argument
604 dev_dbg(codec->card->dev, "stop_voice: channel=%d\n", channel); in snd_ali_stop_voice()
605 outl(mask, ALI_REG(codec, codec->chregs.regs.stop)); in snd_ali_stop_voice()
612 static void snd_ali_delay(struct snd_ali *codec,int interval) in snd_ali_delay() argument
616 begintimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
617 currenttimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
620 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_delay()
622 currenttimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
627 static void snd_ali_detect_spdif_rate(struct snd_ali *codec) in snd_ali_detect_spdif_rate() argument
633 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
635 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
639 snd_ali_delay(codec, 6); in snd_ali_detect_spdif_rate()
640 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
645 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n"); in snd_ali_detect_spdif_rate()
650 snd_ali_delay(codec, 6); in snd_ali_detect_spdif_rate()
651 bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
660 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n"); in snd_ali_detect_spdif_rate()
665 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
668 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
670 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)) & 0xf0; in snd_ali_detect_spdif_rate()
671 outb(bval | 0x02, ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_detect_spdif_rate()
673 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
676 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
678 bval = inb(ALI_REG(codec,ALI_SPDIF_CS + 3)) & 0xf0; in snd_ali_detect_spdif_rate()
679 outb(bval | 0x03, ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_detect_spdif_rate()
683 static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali *codec) in snd_ali_get_spdif_in_rate() argument
688 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_get_spdif_in_rate()
691 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_get_spdif_in_rate()
693 snd_ali_detect_spdif_rate(codec); in snd_ali_get_spdif_in_rate()
695 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_get_spdif_in_rate()
708 static void snd_ali_enable_spdif_in(struct snd_ali *codec) in snd_ali_enable_spdif_in() argument
712 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_in()
714 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_in()
716 dwVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_in()
718 outb(dwVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_in()
720 snd_ali_enable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); in snd_ali_enable_spdif_in()
723 static void snd_ali_disable_spdif_in(struct snd_ali *codec) in snd_ali_disable_spdif_in() argument
727 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_in()
729 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_in()
731 snd_ali_disable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); in snd_ali_disable_spdif_in()
735 static void snd_ali_set_spdif_out_rate(struct snd_ali *codec, unsigned int rate) in snd_ali_set_spdif_out_rate() argument
746 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
750 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
751 outb(dwRate | 0x20, ALI_REG(codec, ALI_SPDIF_CS + 2)); in snd_ali_set_spdif_out_rate()
754 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
755 outw(rate | 0x10, ALI_REG(codec, ALI_SPDIF_CS + 2)); in snd_ali_set_spdif_out_rate()
758 static void snd_ali_enable_spdif_out(struct snd_ali *codec) in snd_ali_enable_spdif_out() argument
764 pci_dev = codec->pci_m1533; in snd_ali_enable_spdif_out()
779 bVal = inb(ALI_REG(codec, ALI_SCTRL)); in snd_ali_enable_spdif_out()
780 outb(bVal | ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); in snd_ali_enable_spdif_out()
782 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_out()
783 outb(bVal & ALI_SPDIF_OUT_CH_STATUS, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_out()
785 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_out()
787 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_out()
788 snd_ali_disable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_enable_spdif_out()
791 static void snd_ali_enable_spdif_chnout(struct snd_ali *codec) in snd_ali_enable_spdif_chnout() argument
795 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_chnout()
797 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_chnout()
799 wVal = inw(ALI_REG(codec, ALI_SPDIF_CS)); in snd_ali_enable_spdif_chnout()
804 outw(wVal, ALI_REG(codec, ALI_SPDIF_CS)); in snd_ali_enable_spdif_chnout()
806 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_enable_spdif_chnout()
809 static void snd_ali_disable_spdif_chnout(struct snd_ali *codec) in snd_ali_disable_spdif_chnout() argument
813 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_chnout()
815 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_chnout()
817 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_disable_spdif_chnout()
820 static void snd_ali_disable_spdif_out(struct snd_ali *codec) in snd_ali_disable_spdif_out() argument
824 bVal = inb(ALI_REG(codec, ALI_SCTRL)); in snd_ali_disable_spdif_out()
825 outb(bVal & ~ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); in snd_ali_disable_spdif_out()
827 snd_ali_disable_spdif_chnout(codec); in snd_ali_disable_spdif_out()
830 static void snd_ali_update_ptr(struct snd_ali *codec, int channel) in snd_ali_update_ptr() argument
836 pchregs = &(codec->chregs); in snd_ali_update_ptr()
845 pvoice = &codec->synth.voices[channel]; in snd_ali_update_ptr()
848 spin_lock(&codec->reg_lock); in snd_ali_update_ptr()
853 dev_dbg(codec->card->dev, in snd_ali_update_ptr()
855 inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)), in snd_ali_update_ptr()
856 (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask); in snd_ali_update_ptr()
857 spin_unlock(&codec->reg_lock); in snd_ali_update_ptr()
859 spin_lock(&codec->reg_lock); in snd_ali_update_ptr()
861 snd_ali_stop_voice(codec, channel); in snd_ali_update_ptr()
862 snd_ali_disable_voice_irq(codec, channel); in snd_ali_update_ptr()
864 } else if (codec->synth.voices[channel].synth) { in snd_ali_update_ptr()
866 } else if (codec->synth.voices[channel].midi) { in snd_ali_update_ptr()
870 snd_ali_stop_voice(codec, channel); in snd_ali_update_ptr()
871 snd_ali_disable_voice_irq(codec, channel); in snd_ali_update_ptr()
873 spin_unlock(&codec->reg_lock); in snd_ali_update_ptr()
874 outl(mask,ALI_REG(codec,pchregs->regs.aint)); in snd_ali_update_ptr()
880 struct snd_ali *codec = dev_id; in snd_ali_card_interrupt() local
885 if (codec == NULL || !codec->hw_initialized) in snd_ali_card_interrupt()
888 audio_int = inl(ALI_REG(codec, ALI_MISCINT)); in snd_ali_card_interrupt()
892 pchregs = &(codec->chregs); in snd_ali_card_interrupt()
895 pchregs->data.aint = inl(ALI_REG(codec, pchregs->regs.aint)); in snd_ali_card_interrupt()
897 snd_ali_update_ptr(codec, channel); in snd_ali_card_interrupt()
900 ALI_REG(codec, ALI_MISCINT)); in snd_ali_card_interrupt()
906 static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec, in snd_ali_alloc_voice() argument
912 dev_dbg(codec->card->dev, "alloc_voice: type=%d rec=%d\n", type, rec); in snd_ali_alloc_voice()
914 spin_lock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
916 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : in snd_ali_alloc_voice()
917 snd_ali_find_free_channel(codec,rec); in snd_ali_alloc_voice()
919 dev_err(codec->card->dev, "ali_alloc_voice: err.\n"); in snd_ali_alloc_voice()
920 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
923 pvoice = &(codec->synth.voices[idx]); in snd_ali_alloc_voice()
924 pvoice->codec = codec; in snd_ali_alloc_voice()
928 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
931 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
936 static void snd_ali_free_voice(struct snd_ali * codec, in snd_ali_free_voice() argument
942 dev_dbg(codec->card->dev, "free_voice: channel=%d\n", pvoice->number); in snd_ali_free_voice()
945 snd_ali_clear_voices(codec, pvoice->number, pvoice->number); in snd_ali_free_voice()
946 spin_lock_irq(&codec->voice_alloc); in snd_ali_free_voice()
952 snd_ali_free_channel_pcm(codec, pvoice->number); in snd_ali_free_voice()
955 spin_unlock_irq(&codec->voice_alloc); in snd_ali_free_voice()
961 static void snd_ali_clear_voices(struct snd_ali *codec, in snd_ali_clear_voices() argument
968 snd_ali_stop_voice(codec, i); in snd_ali_clear_voices()
969 snd_ali_disable_voice_irq(codec, i); in snd_ali_clear_voices()
973 static void snd_ali_write_voice_regs(struct snd_ali *codec, in snd_ali_write_voice_regs() argument
988 outb((unsigned char)(Channel & 0x001f), ALI_REG(codec, ALI_GC_CIR)); in snd_ali_write_voice_regs()
999 outb(Channel, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_write_voice_regs()
1001 outl(ctlcmds[0], ALI_REG(codec, ALI_CSO_ALPHA_FMS)); in snd_ali_write_voice_regs()
1002 outl(ctlcmds[1], ALI_REG(codec, ALI_LBA)); in snd_ali_write_voice_regs()
1003 outl(ctlcmds[2], ALI_REG(codec, ALI_ESO_DELTA)); in snd_ali_write_voice_regs()
1004 outl(ctlcmds[3], ALI_REG(codec, ALI_GVSEL_PAN_VOC_CTRL_EC)); in snd_ali_write_voice_regs()
1006 outl(0x30000000, ALI_REG(codec, ALI_EBUF1)); /* Still Mode */ in snd_ali_write_voice_regs()
1007 outl(0x30000000, ALI_REG(codec, ALI_EBUF2)); /* Still Mode */ in snd_ali_write_voice_regs()
1068 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_trigger() local
1090 if ((struct snd_ali *) snd_pcm_substream_chip(s) == codec) { in snd_ali_trigger()
1112 spin_lock(&codec->reg_lock); in snd_ali_trigger()
1114 outl(what, ALI_REG(codec, ALI_STOP)); in snd_ali_trigger()
1115 val = inl(ALI_REG(codec, ALI_AINTEN)); in snd_ali_trigger()
1120 outl(val, ALI_REG(codec, ALI_AINTEN)); in snd_ali_trigger()
1122 outl(what, ALI_REG(codec, ALI_START)); in snd_ali_trigger()
1123 dev_dbg(codec->card->dev, "trigger: what=%xh whati=%xh\n", what, whati); in snd_ali_trigger()
1124 spin_unlock(&codec->reg_lock); in snd_ali_trigger()
1132 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_hw_params() local
1142 evoice = snd_ali_alloc_voice(codec, in snd_ali_playback_hw_params()
1152 snd_ali_free_voice(codec, evoice); in snd_ali_playback_hw_params()
1162 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_hw_free() local
1168 snd_ali_free_voice(codec, evoice); in snd_ali_playback_hw_free()
1176 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_prepare() local
1190 dev_dbg(codec->card->dev, "playback_prepare ...\n"); in snd_ali_playback_prepare()
1192 spin_lock_irq(&codec->reg_lock); in snd_ali_playback_prepare()
1199 snd_ali_disable_special_channel(codec, pvoice->number); in snd_ali_playback_prepare()
1200 else if (codec->spdif_support && in snd_ali_playback_prepare()
1201 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_playback_prepare()
1204 snd_ali_set_spdif_out_rate(codec, runtime->rate); in snd_ali_playback_prepare()
1217 dev_dbg(codec->card->dev, "playback_prepare: eso=%xh count=%xh\n", in snd_ali_playback_prepare()
1229 dev_dbg(codec->card->dev, "playback_prepare:\n"); in snd_ali_playback_prepare()
1230 dev_dbg(codec->card->dev, in snd_ali_playback_prepare()
1233 snd_ali_write_voice_regs(codec, in snd_ali_playback_prepare()
1249 snd_ali_write_voice_regs(codec, in snd_ali_playback_prepare()
1262 spin_unlock_irq(&codec->reg_lock); in snd_ali_playback_prepare()
1269 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_prepare() local
1282 spin_lock_irq(&codec->reg_lock); in snd_ali_prepare()
1284 dev_dbg(codec->card->dev, "ali_prepare...\n"); in snd_ali_prepare()
1286 snd_ali_enable_special_channel(codec,pvoice->number); in snd_ali_prepare()
1297 spin_unlock_irq(&codec->reg_lock); in snd_ali_prepare()
1298 if (codec->revision != ALI_5451_V02) in snd_ali_prepare()
1301 rate = snd_ali_get_spdif_in_rate(codec); in snd_ali_prepare()
1303 dev_warn(codec->card->dev, in snd_ali_prepare()
1307 spin_lock_irq(&codec->reg_lock); in snd_ali_prepare()
1308 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL)); in snd_ali_prepare()
1310 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL)); in snd_ali_prepare()
1311 dev_warn(codec->card->dev, in snd_ali_prepare()
1336 snd_ali_write_voice_regs( codec, in snd_ali_prepare()
1349 spin_unlock_irq(&codec->reg_lock); in snd_ali_prepare()
1358 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_pointer() local
1363 spin_lock(&codec->reg_lock); in snd_ali_playback_pointer()
1365 spin_unlock(&codec->reg_lock); in snd_ali_playback_pointer()
1368 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_playback_pointer()
1369 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); in snd_ali_playback_pointer()
1370 spin_unlock(&codec->reg_lock); in snd_ali_playback_pointer()
1371 dev_dbg(codec->card->dev, "playback pointer returned cso=%xh.\n", cso); in snd_ali_playback_pointer()
1380 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_pointer() local
1385 spin_lock(&codec->reg_lock); in snd_ali_pointer()
1387 spin_unlock(&codec->reg_lock); in snd_ali_pointer()
1390 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_pointer()
1391 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); in snd_ali_pointer()
1392 spin_unlock(&codec->reg_lock); in snd_ali_pointer()
1451 snd_ali_free_voice(pvoice->codec, pvoice); in snd_ali_pcm_free_substream()
1457 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_open() local
1461 pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, rec, in snd_ali_open()
1494 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_close() local
1497 snd_ali_disable_special_channel(codec,pvoice->number); in snd_ali_close()
1615 struct snd_ali *codec = pcm->private_data; in snd_ali_pcm_free() local
1616 codec->pcm[pcm->device] = NULL; in snd_ali_pcm_free()
1620 static int snd_ali_pcm(struct snd_ali *codec, int device, in snd_ali_pcm() argument
1626 err = snd_pcm_new(codec->card, desc->name, device, in snd_ali_pcm()
1629 dev_err(codec->card->dev, in snd_ali_pcm()
1633 pcm->private_data = codec; in snd_ali_pcm()
1643 &codec->pci->dev, 64*1024, 128*1024); in snd_ali_pcm()
1649 codec->pcm[0] = pcm; in snd_ali_pcm()
1669 static int snd_ali_build_pcms(struct snd_ali *codec) in snd_ali_build_pcms() argument
1672 for (i = 0; i < codec->num_of_codecs && i < ARRAY_SIZE(ali_pcms); i++) { in snd_ali_build_pcms()
1673 err = snd_ali_pcm(codec, i, &ali_pcms[i]); in snd_ali_build_pcms()
1691 struct snd_ali *codec = kcontrol->private_data; in snd_ali5451_spdif_get() local
1696 spin_lock_irq(&codec->reg_lock); in snd_ali5451_spdif_get()
1699 spdif_enable = (codec->spdif_mask & 0x02) ? 1 : 0; in snd_ali5451_spdif_get()
1702 spdif_enable = ((codec->spdif_mask & 0x02) && in snd_ali5451_spdif_get()
1703 (codec->spdif_mask & 0x04)) ? 1 : 0; in snd_ali5451_spdif_get()
1706 spdif_enable = (codec->spdif_mask & 0x01) ? 1 : 0; in snd_ali5451_spdif_get()
1712 spin_unlock_irq(&codec->reg_lock); in snd_ali5451_spdif_get()
1719 struct snd_ali *codec = kcontrol->private_data; in snd_ali5451_spdif_put() local
1724 spin_lock_irq(&codec->reg_lock); in snd_ali5451_spdif_put()
1727 change = (codec->spdif_mask & 0x02) ? 1 : 0; in snd_ali5451_spdif_put()
1731 codec->spdif_mask |= 0x02; in snd_ali5451_spdif_put()
1732 snd_ali_enable_spdif_out(codec); in snd_ali5451_spdif_put()
1734 codec->spdif_mask &= ~(0x02); in snd_ali5451_spdif_put()
1735 codec->spdif_mask &= ~(0x04); in snd_ali5451_spdif_put()
1736 snd_ali_disable_spdif_out(codec); in snd_ali5451_spdif_put()
1741 change = (codec->spdif_mask & 0x04) ? 1 : 0; in snd_ali5451_spdif_put()
1743 if (change && (codec->spdif_mask & 0x02)) { in snd_ali5451_spdif_put()
1745 codec->spdif_mask |= 0x04; in snd_ali5451_spdif_put()
1746 snd_ali_enable_spdif_chnout(codec); in snd_ali5451_spdif_put()
1748 codec->spdif_mask &= ~(0x04); in snd_ali5451_spdif_put()
1749 snd_ali_disable_spdif_chnout(codec); in snd_ali5451_spdif_put()
1754 change = (codec->spdif_mask & 0x01) ? 1 : 0; in snd_ali5451_spdif_put()
1758 codec->spdif_mask |= 0x01; in snd_ali5451_spdif_put()
1759 snd_ali_enable_spdif_in(codec); in snd_ali5451_spdif_put()
1761 codec->spdif_mask &= ~(0x01); in snd_ali5451_spdif_put()
1762 snd_ali_disable_spdif_in(codec); in snd_ali5451_spdif_put()
1769 spin_unlock_irq(&codec->reg_lock); in snd_ali5451_spdif_put()
1784 static int snd_ali_mixer(struct snd_ali *codec) in snd_ali_mixer() argument
1794 err = snd_ac97_bus(codec->card, 0, &ops, codec, &codec->ac97_bus); in snd_ali_mixer()
1799 ac97.private_data = codec; in snd_ali_mixer()
1801 for (i = 0; i < codec->num_of_codecs; i++) { in snd_ali_mixer()
1803 err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i]); in snd_ali_mixer()
1805 dev_err(codec->card->dev, in snd_ali_mixer()
1809 codec->num_of_codecs = 1; in snd_ali_mixer()
1814 if (codec->spdif_support) { in snd_ali_mixer()
1816 err = snd_ctl_add(codec->card, in snd_ali_mixer()
1817 snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec)); in snd_ali_mixer()
1904 struct snd_ali *codec = card->private_data; in snd_ali_free() local
1906 if (codec->hw_initialized) in snd_ali_free()
1907 snd_ali_disable_address_interrupt(codec); in snd_ali_free()
1908 pci_dev_put(codec->pci_m1533); in snd_ali_free()
1909 pci_dev_put(codec->pci_m7101); in snd_ali_free()
1912 static int snd_ali_chip_init(struct snd_ali *codec) in snd_ali_chip_init() argument
1918 dev_dbg(codec->card->dev, "chip initializing ...\n"); in snd_ali_chip_init()
1920 if (snd_ali_reset_5451(codec)) { in snd_ali_chip_init()
1921 dev_err(codec->card->dev, "ali_chip_init: reset 5451 error.\n"); in snd_ali_chip_init()
1925 if (codec->revision == ALI_5451_V02) { in snd_ali_chip_init()
1926 pci_dev = codec->pci_m1533; in snd_ali_chip_init()
1931 pci_dev = codec->pci_m7101; in snd_ali_chip_init()
1937 pci_read_config_dword(codec->pci, 0x44, &legacy); in snd_ali_chip_init()
1940 pci_write_config_dword(codec->pci, 0x44, legacy); in snd_ali_chip_init()
1942 outl(0x80000001, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_chip_init()
1943 outl(0x00000000, ALI_REG(codec, ALI_AINTEN)); in snd_ali_chip_init()
1944 outl(0xffffffff, ALI_REG(codec, ALI_AINT)); in snd_ali_chip_init()
1945 outl(0x00000000, ALI_REG(codec, ALI_VOLUME)); in snd_ali_chip_init()
1946 outb(0x10, ALI_REG(codec, ALI_MPUR2)); in snd_ali_chip_init()
1948 codec->ac97_ext_id = snd_ali_codec_peek(codec, 0, AC97_EXTENDED_ID); in snd_ali_chip_init()
1949 codec->ac97_ext_status = snd_ali_codec_peek(codec, 0, in snd_ali_chip_init()
1951 if (codec->spdif_support) { in snd_ali_chip_init()
1952 snd_ali_enable_spdif_out(codec); in snd_ali_chip_init()
1953 codec->spdif_mask = 0x00000002; in snd_ali_chip_init()
1956 codec->num_of_codecs = 1; in snd_ali_chip_init()
1958 /* secondary codec - modem */ in snd_ali_chip_init()
1959 if (inl(ALI_REG(codec, ALI_SCTRL)) & ALI_SCTRL_CODEC2_READY) { in snd_ali_chip_init()
1960 codec->num_of_codecs++; in snd_ali_chip_init()
1961 outl(inl(ALI_REG(codec, ALI_SCTRL)) | in snd_ali_chip_init()
1964 ALI_REG(codec, ALI_SCTRL)); in snd_ali_chip_init()
1967 dev_dbg(codec->card->dev, "chip initialize succeed.\n"); in snd_ali_chip_init()
1976 struct snd_ali *codec = entry->private_data; in snd_ali_proc_read() local
1979 snd_iprintf(buf, "%02x: %08x\n", i, inl(ALI_REG(codec, i))); in snd_ali_proc_read()
1982 static void snd_ali_proc_init(struct snd_ali *codec) in snd_ali_proc_init() argument
1984 snd_card_ro_proc_new(codec->card, "ali5451", codec, snd_ali_proc_read); in snd_ali_proc_init()
1987 static int snd_ali_resources(struct snd_ali *codec) in snd_ali_resources() argument
1991 dev_dbg(codec->card->dev, "resources allocation ...\n"); in snd_ali_resources()
1992 err = pci_request_regions(codec->pci, "ALI 5451"); in snd_ali_resources()
1995 codec->port = pci_resource_start(codec->pci, 0); in snd_ali_resources()
1997 if (devm_request_irq(&codec->pci->dev, codec->pci->irq, in snd_ali_resources()
1999 IRQF_SHARED, KBUILD_MODNAME, codec)) { in snd_ali_resources()
2000 dev_err(codec->card->dev, "Unable to request irq.\n"); in snd_ali_resources()
2003 codec->irq = codec->pci->irq; in snd_ali_resources()
2004 codec->card->sync_irq = codec->irq; in snd_ali_resources()
2005 dev_dbg(codec->card->dev, "resources allocated.\n"); in snd_ali_resources()
2014 struct snd_ali *codec = card->private_data; in snd_ali_create() local
2031 spin_lock_init(&codec->reg_lock); in snd_ali_create()
2032 spin_lock_init(&codec->voice_alloc); in snd_ali_create()
2034 codec->card = card; in snd_ali_create()
2035 codec->pci = pci; in snd_ali_create()
2036 codec->irq = -1; in snd_ali_create()
2037 codec->revision = pci->revision; in snd_ali_create()
2038 codec->spdif_support = spdif_support; in snd_ali_create()
2052 if (snd_ali_resources(codec)) in snd_ali_create()
2056 codec->synth.chmap = 0; in snd_ali_create()
2057 codec->synth.chcnt = 0; in snd_ali_create()
2058 codec->spdif_mask = 0; in snd_ali_create()
2059 codec->synth.synthcount = 0; in snd_ali_create()
2061 if (codec->revision == ALI_5451_V02) in snd_ali_create()
2062 codec->chregs.regs.ac97read = ALI_AC97_WRITE; in snd_ali_create()
2064 codec->chregs.regs.ac97read = ALI_AC97_READ; in snd_ali_create()
2065 codec->chregs.regs.ac97write = ALI_AC97_WRITE; in snd_ali_create()
2067 codec->chregs.regs.start = ALI_START; in snd_ali_create()
2068 codec->chregs.regs.stop = ALI_STOP; in snd_ali_create()
2069 codec->chregs.regs.aint = ALI_AINT; in snd_ali_create()
2070 codec->chregs.regs.ainten = ALI_AINTEN; in snd_ali_create()
2072 codec->chregs.data.start = 0x00; in snd_ali_create()
2073 codec->chregs.data.stop = 0x00; in snd_ali_create()
2074 codec->chregs.data.aint = 0x00; in snd_ali_create()
2075 codec->chregs.data.ainten = 0x00; in snd_ali_create()
2078 codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL); in snd_ali_create()
2079 if (!codec->pci_m1533) { in snd_ali_create()
2084 codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL); in snd_ali_create()
2085 if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) { in snd_ali_create()
2092 codec->synth.voices[i].number = i; in snd_ali_create()
2094 err = snd_ali_chip_init(codec); in snd_ali_create()
2100 snd_ali_enable_address_interrupt(codec); in snd_ali_create()
2101 codec->hw_initialized = 1; in snd_ali_create()
2109 struct snd_ali *codec; in __snd_ali_probe() local
2115 sizeof(*codec), &card); in __snd_ali_probe()
2118 codec = card->private_data; in __snd_ali_probe()
2125 err = snd_ali_mixer(codec); in __snd_ali_probe()
2130 err = snd_ali_build_pcms(codec); in __snd_ali_probe()
2134 snd_ali_proc_init(codec); in __snd_ali_probe()
2140 card->shortname, codec->port, codec->irq); in __snd_ali_probe()