Lines Matching refs:codec

156 #define ALI_REG(codec, x) ((codec)->port + x)  argument
195 struct snd_ali *codec; member
281 static inline unsigned int snd_ali_5451_peek(struct snd_ali *codec, in snd_ali_5451_peek() argument
284 return (unsigned int)inl(ALI_REG(codec, port)); in snd_ali_5451_peek()
287 static inline void snd_ali_5451_poke(struct snd_ali *codec, in snd_ali_5451_poke() argument
291 outl((unsigned int)val, ALI_REG(codec, port)); in snd_ali_5451_poke()
294 static int snd_ali_codec_ready(struct snd_ali *codec, in snd_ali_codec_ready() argument
303 res = snd_ali_5451_peek(codec,port); in snd_ali_codec_ready()
311 snd_ali_5451_poke(codec, port, res & ~0x8000); in snd_ali_codec_ready()
312 dev_dbg(codec->card->dev, "ali_codec_ready: codec is not ready.\n "); in snd_ali_codec_ready()
316 static int snd_ali_stimer_ready(struct snd_ali *codec) in snd_ali_stimer_ready() argument
321 dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER); in snd_ali_stimer_ready()
325 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); in snd_ali_stimer_ready()
333 dev_err(codec->card->dev, "ali_stimer_read: stimer is not ready.\n"); in snd_ali_stimer_ready()
337 static void snd_ali_codec_poke(struct snd_ali *codec,int secondary, in snd_ali_codec_poke() argument
345 dev_err(codec->card->dev, in snd_ali_codec_poke()
350 port = codec->chregs.regs.ac97write; in snd_ali_codec_poke()
352 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_poke()
354 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_poke()
361 if (codec->revision == ALI_5451_V02) in snd_ali_codec_poke()
364 snd_ali_5451_poke(codec, port, dwVal); in snd_ali_codec_poke()
369 static unsigned short snd_ali_codec_peek(struct snd_ali *codec, in snd_ali_codec_peek() argument
377 dev_err(codec->card->dev, in snd_ali_codec_peek()
382 port = codec->chregs.regs.ac97read; in snd_ali_codec_peek()
384 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_peek()
386 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_peek()
394 snd_ali_5451_poke(codec, port, dwVal); in snd_ali_codec_peek()
396 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_peek()
398 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_peek()
401 return (snd_ali_5451_peek(codec, port) & 0xffff0000) >> 16; in snd_ali_codec_peek()
408 struct snd_ali *codec = ac97->private_data; in snd_ali_codec_write() local
410 dev_dbg(codec->card->dev, "codec_write: reg=%xh data=%xh.\n", reg, val); in snd_ali_codec_write()
413 ALI_REG(codec, ALI_AC97_GPIO)); in snd_ali_codec_write()
416 snd_ali_codec_poke(codec, ac97->num, reg, val); in snd_ali_codec_write()
424 struct snd_ali *codec = ac97->private_data; in snd_ali_codec_read() local
426 dev_dbg(codec->card->dev, "codec_read reg=%xh.\n", reg); in snd_ali_codec_read()
427 return snd_ali_codec_peek(codec, ac97->num, reg); in snd_ali_codec_read()
434 static int snd_ali_reset_5451(struct snd_ali *codec) in snd_ali_reset_5451() argument
440 pci_dev = codec->pci_m1533; in snd_ali_reset_5451()
450 pci_dev = codec->pci; in snd_ali_reset_5451()
460 wReg = snd_ali_codec_peek(codec, 0, AC97_POWERDOWN); in snd_ali_reset_5451()
475 static void snd_ali_enable_special_channel(struct snd_ali *codec, in snd_ali_enable_special_channel() argument
480 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_special_channel()
482 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_special_channel()
485 static void snd_ali_disable_special_channel(struct snd_ali *codec, in snd_ali_disable_special_channel() argument
490 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_special_channel()
492 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_special_channel()
495 static void snd_ali_enable_address_interrupt(struct snd_ali *codec) in snd_ali_enable_address_interrupt() argument
499 gc = inl(ALI_REG(codec, ALI_GC_CIR)); in snd_ali_enable_address_interrupt()
502 outl( gc, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_enable_address_interrupt()
505 static void snd_ali_disable_address_interrupt(struct snd_ali *codec) in snd_ali_disable_address_interrupt() argument
509 gc = inl(ALI_REG(codec, ALI_GC_CIR)); in snd_ali_disable_address_interrupt()
512 outl(gc, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_disable_address_interrupt()
515 static void snd_ali_disable_voice_irq(struct snd_ali *codec, in snd_ali_disable_voice_irq() argument
519 struct snd_ali_channel_control *pchregs = &(codec->chregs); in snd_ali_disable_voice_irq()
521 dev_dbg(codec->card->dev, "disable_voice_irq channel=%d\n", channel); in snd_ali_disable_voice_irq()
524 pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten)); in snd_ali_disable_voice_irq()
526 outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten)); in snd_ali_disable_voice_irq()
529 static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel) in snd_ali_alloc_pcm_channel() argument
533 if (codec->synth.chcnt >= ALI_CHANNELS){ in snd_ali_alloc_pcm_channel()
534 dev_err(codec->card->dev, in snd_ali_alloc_pcm_channel()
539 if (!(codec->synth.chmap & (1 << idx))) { in snd_ali_alloc_pcm_channel()
540 codec->synth.chmap |= 1 << idx; in snd_ali_alloc_pcm_channel()
541 codec->synth.chcnt++; in snd_ali_alloc_pcm_channel()
542 dev_dbg(codec->card->dev, "alloc_pcm_channel no. %d.\n", idx); in snd_ali_alloc_pcm_channel()
548 static int snd_ali_find_free_channel(struct snd_ali * codec, int rec) in snd_ali_find_free_channel() argument
553 dev_dbg(codec->card->dev, in snd_ali_find_free_channel()
558 if (codec->spdif_support && in snd_ali_find_free_channel()
559 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_find_free_channel()
565 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
569 dev_err(codec->card->dev, in snd_ali_find_free_channel()
576 if (codec->spdif_support && in snd_ali_find_free_channel()
577 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_find_free_channel()
580 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
584 dev_err(codec->card->dev, in snd_ali_find_free_channel()
589 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
593 dev_err(codec->card->dev, "ali_find_free_channel: no free channels.\n"); in snd_ali_find_free_channel()
597 static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel) in snd_ali_free_channel_pcm() argument
601 dev_dbg(codec->card->dev, "free_channel_pcm channel=%d\n", channel); in snd_ali_free_channel_pcm()
606 if (!(codec->synth.chmap & (1 << idx))) { in snd_ali_free_channel_pcm()
607 dev_err(codec->card->dev, in snd_ali_free_channel_pcm()
612 codec->synth.chmap &= ~(1 << idx); in snd_ali_free_channel_pcm()
613 codec->synth.chcnt--; in snd_ali_free_channel_pcm()
617 static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel) in snd_ali_stop_voice() argument
621 dev_dbg(codec->card->dev, "stop_voice: channel=%d\n", channel); in snd_ali_stop_voice()
622 outl(mask, ALI_REG(codec, codec->chregs.regs.stop)); in snd_ali_stop_voice()
629 static void snd_ali_delay(struct snd_ali *codec,int interval) in snd_ali_delay() argument
633 begintimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
634 currenttimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
637 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_delay()
639 currenttimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
644 static void snd_ali_detect_spdif_rate(struct snd_ali *codec) in snd_ali_detect_spdif_rate() argument
650 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
652 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
656 snd_ali_delay(codec, 6); in snd_ali_detect_spdif_rate()
657 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
662 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n"); in snd_ali_detect_spdif_rate()
667 snd_ali_delay(codec, 6); in snd_ali_detect_spdif_rate()
668 bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
677 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n"); in snd_ali_detect_spdif_rate()
682 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
685 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
687 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)) & 0xf0; in snd_ali_detect_spdif_rate()
688 outb(bval | 0x02, ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_detect_spdif_rate()
690 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
693 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
695 bval = inb(ALI_REG(codec,ALI_SPDIF_CS + 3)) & 0xf0; in snd_ali_detect_spdif_rate()
696 outb(bval | 0x03, ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_detect_spdif_rate()
700 static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali *codec) in snd_ali_get_spdif_in_rate() argument
705 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_get_spdif_in_rate()
708 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_get_spdif_in_rate()
710 snd_ali_detect_spdif_rate(codec); in snd_ali_get_spdif_in_rate()
712 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_get_spdif_in_rate()
725 static void snd_ali_enable_spdif_in(struct snd_ali *codec) in snd_ali_enable_spdif_in() argument
729 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_in()
731 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_in()
733 dwVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_in()
735 outb(dwVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_in()
737 snd_ali_enable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); in snd_ali_enable_spdif_in()
740 static void snd_ali_disable_spdif_in(struct snd_ali *codec) in snd_ali_disable_spdif_in() argument
744 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_in()
746 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_in()
748 snd_ali_disable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); in snd_ali_disable_spdif_in()
752 static void snd_ali_set_spdif_out_rate(struct snd_ali *codec, unsigned int rate) in snd_ali_set_spdif_out_rate() argument
763 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
767 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
768 outb(dwRate | 0x20, ALI_REG(codec, ALI_SPDIF_CS + 2)); in snd_ali_set_spdif_out_rate()
771 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
772 outw(rate | 0x10, ALI_REG(codec, ALI_SPDIF_CS + 2)); in snd_ali_set_spdif_out_rate()
775 static void snd_ali_enable_spdif_out(struct snd_ali *codec) in snd_ali_enable_spdif_out() argument
781 pci_dev = codec->pci_m1533; in snd_ali_enable_spdif_out()
796 bVal = inb(ALI_REG(codec, ALI_SCTRL)); in snd_ali_enable_spdif_out()
797 outb(bVal | ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); in snd_ali_enable_spdif_out()
799 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_out()
800 outb(bVal & ALI_SPDIF_OUT_CH_STATUS, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_out()
802 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_out()
804 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_out()
805 snd_ali_disable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_enable_spdif_out()
808 static void snd_ali_enable_spdif_chnout(struct snd_ali *codec) in snd_ali_enable_spdif_chnout() argument
812 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_chnout()
814 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_chnout()
823 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_enable_spdif_chnout()
826 static void snd_ali_disable_spdif_chnout(struct snd_ali *codec) in snd_ali_disable_spdif_chnout() argument
830 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_chnout()
832 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_chnout()
834 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_disable_spdif_chnout()
837 static void snd_ali_disable_spdif_out(struct snd_ali *codec) in snd_ali_disable_spdif_out() argument
841 bVal = inb(ALI_REG(codec, ALI_SCTRL)); in snd_ali_disable_spdif_out()
842 outb(bVal & ~ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); in snd_ali_disable_spdif_out()
844 snd_ali_disable_spdif_chnout(codec); in snd_ali_disable_spdif_out()
847 static void snd_ali_update_ptr(struct snd_ali *codec, int channel) in snd_ali_update_ptr() argument
853 pchregs = &(codec->chregs); in snd_ali_update_ptr()
862 pvoice = &codec->synth.voices[channel]; in snd_ali_update_ptr()
865 spin_lock(&codec->reg_lock); in snd_ali_update_ptr()
870 dev_dbg(codec->card->dev, in snd_ali_update_ptr()
872 inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)), in snd_ali_update_ptr()
873 (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask); in snd_ali_update_ptr()
874 spin_unlock(&codec->reg_lock); in snd_ali_update_ptr()
876 spin_lock(&codec->reg_lock); in snd_ali_update_ptr()
878 snd_ali_stop_voice(codec, channel); in snd_ali_update_ptr()
879 snd_ali_disable_voice_irq(codec, channel); in snd_ali_update_ptr()
881 } else if (codec->synth.voices[channel].synth) { in snd_ali_update_ptr()
883 } else if (codec->synth.voices[channel].midi) { in snd_ali_update_ptr()
887 snd_ali_stop_voice(codec, channel); in snd_ali_update_ptr()
888 snd_ali_disable_voice_irq(codec, channel); in snd_ali_update_ptr()
890 spin_unlock(&codec->reg_lock); in snd_ali_update_ptr()
891 outl(mask,ALI_REG(codec,pchregs->regs.aint)); in snd_ali_update_ptr()
897 struct snd_ali *codec = dev_id; in snd_ali_card_interrupt() local
902 if (codec == NULL || !codec->hw_initialized) in snd_ali_card_interrupt()
905 audio_int = inl(ALI_REG(codec, ALI_MISCINT)); in snd_ali_card_interrupt()
909 pchregs = &(codec->chregs); in snd_ali_card_interrupt()
912 pchregs->data.aint = inl(ALI_REG(codec, pchregs->regs.aint)); in snd_ali_card_interrupt()
914 snd_ali_update_ptr(codec, channel); in snd_ali_card_interrupt()
917 ALI_REG(codec, ALI_MISCINT)); in snd_ali_card_interrupt()
923 static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec, in snd_ali_alloc_voice() argument
929 dev_dbg(codec->card->dev, "alloc_voice: type=%d rec=%d\n", type, rec); in snd_ali_alloc_voice()
931 spin_lock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
933 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : in snd_ali_alloc_voice()
934 snd_ali_find_free_channel(codec,rec); in snd_ali_alloc_voice()
936 dev_err(codec->card->dev, "ali_alloc_voice: err.\n"); in snd_ali_alloc_voice()
937 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
940 pvoice = &(codec->synth.voices[idx]); in snd_ali_alloc_voice()
941 pvoice->codec = codec; in snd_ali_alloc_voice()
945 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
948 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
953 static void snd_ali_free_voice(struct snd_ali * codec, in snd_ali_free_voice() argument
959 dev_dbg(codec->card->dev, "free_voice: channel=%d\n", pvoice->number); in snd_ali_free_voice()
962 snd_ali_clear_voices(codec, pvoice->number, pvoice->number); in snd_ali_free_voice()
963 spin_lock_irq(&codec->voice_alloc); in snd_ali_free_voice()
969 snd_ali_free_channel_pcm(codec, pvoice->number); in snd_ali_free_voice()
972 spin_unlock_irq(&codec->voice_alloc); in snd_ali_free_voice()
978 static void snd_ali_clear_voices(struct snd_ali *codec, in snd_ali_clear_voices() argument
985 snd_ali_stop_voice(codec, i); in snd_ali_clear_voices()
986 snd_ali_disable_voice_irq(codec, i); in snd_ali_clear_voices()
990 static void snd_ali_write_voice_regs(struct snd_ali *codec, in snd_ali_write_voice_regs() argument
1005 outb((unsigned char)(Channel & 0x001f), ALI_REG(codec, ALI_GC_CIR)); in snd_ali_write_voice_regs()
1016 outb(Channel, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_write_voice_regs()
1018 outl(ctlcmds[0], ALI_REG(codec, ALI_CSO_ALPHA_FMS)); in snd_ali_write_voice_regs()
1019 outl(ctlcmds[1], ALI_REG(codec, ALI_LBA)); in snd_ali_write_voice_regs()
1020 outl(ctlcmds[2], ALI_REG(codec, ALI_ESO_DELTA)); in snd_ali_write_voice_regs()
1021 outl(ctlcmds[3], ALI_REG(codec, ALI_GVSEL_PAN_VOC_CTRL_EC)); in snd_ali_write_voice_regs()
1023 outl(0x30000000, ALI_REG(codec, ALI_EBUF1)); /* Still Mode */ in snd_ali_write_voice_regs()
1024 outl(0x30000000, ALI_REG(codec, ALI_EBUF2)); /* Still Mode */ in snd_ali_write_voice_regs()
1085 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_trigger() local
1107 if ((struct snd_ali *) snd_pcm_substream_chip(s) == codec) { in snd_ali_trigger()
1131 spin_lock(&codec->reg_lock); in snd_ali_trigger()
1133 outl(what, ALI_REG(codec, ALI_STOP)); in snd_ali_trigger()
1134 val = inl(ALI_REG(codec, ALI_AINTEN)); in snd_ali_trigger()
1139 outl(val, ALI_REG(codec, ALI_AINTEN)); in snd_ali_trigger()
1141 outl(what, ALI_REG(codec, ALI_START)); in snd_ali_trigger()
1142 dev_dbg(codec->card->dev, "trigger: what=%xh whati=%xh\n", what, whati); in snd_ali_trigger()
1143 spin_unlock(&codec->reg_lock); in snd_ali_trigger()
1151 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_hw_params() local
1167 evoice = snd_ali_alloc_voice(codec, in snd_ali_playback_hw_params()
1177 snd_ali_free_voice(codec, evoice); in snd_ali_playback_hw_params()
1187 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_hw_free() local
1194 snd_ali_free_voice(codec, evoice); in snd_ali_playback_hw_free()
1214 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_prepare() local
1228 dev_dbg(codec->card->dev, "playback_prepare ...\n"); in snd_ali_playback_prepare()
1230 spin_lock_irq(&codec->reg_lock); in snd_ali_playback_prepare()
1237 snd_ali_disable_special_channel(codec, pvoice->number); in snd_ali_playback_prepare()
1238 else if (codec->spdif_support && in snd_ali_playback_prepare()
1239 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_playback_prepare()
1242 snd_ali_set_spdif_out_rate(codec, runtime->rate); in snd_ali_playback_prepare()
1255 dev_dbg(codec->card->dev, "playback_prepare: eso=%xh count=%xh\n", in snd_ali_playback_prepare()
1267 dev_dbg(codec->card->dev, "playback_prepare:\n"); in snd_ali_playback_prepare()
1268 dev_dbg(codec->card->dev, in snd_ali_playback_prepare()
1271 snd_ali_write_voice_regs(codec, in snd_ali_playback_prepare()
1287 snd_ali_write_voice_regs(codec, in snd_ali_playback_prepare()
1300 spin_unlock_irq(&codec->reg_lock); in snd_ali_playback_prepare()
1307 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_prepare() local
1320 spin_lock_irq(&codec->reg_lock); in snd_ali_prepare()
1322 dev_dbg(codec->card->dev, "ali_prepare...\n"); in snd_ali_prepare()
1324 snd_ali_enable_special_channel(codec,pvoice->number); in snd_ali_prepare()
1335 spin_unlock_irq(&codec->reg_lock); in snd_ali_prepare()
1336 if (codec->revision != ALI_5451_V02) in snd_ali_prepare()
1339 rate = snd_ali_get_spdif_in_rate(codec); in snd_ali_prepare()
1341 dev_warn(codec->card->dev, in snd_ali_prepare()
1345 spin_lock_irq(&codec->reg_lock); in snd_ali_prepare()
1346 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL)); in snd_ali_prepare()
1348 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL)); in snd_ali_prepare()
1349 dev_warn(codec->card->dev, in snd_ali_prepare()
1374 snd_ali_write_voice_regs( codec, in snd_ali_prepare()
1387 spin_unlock_irq(&codec->reg_lock); in snd_ali_prepare()
1396 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_pointer() local
1401 spin_lock(&codec->reg_lock); in snd_ali_playback_pointer()
1403 spin_unlock(&codec->reg_lock); in snd_ali_playback_pointer()
1406 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_playback_pointer()
1407 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); in snd_ali_playback_pointer()
1408 spin_unlock(&codec->reg_lock); in snd_ali_playback_pointer()
1409 dev_dbg(codec->card->dev, "playback pointer returned cso=%xh.\n", cso); in snd_ali_playback_pointer()
1417 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_pointer() local
1422 spin_lock(&codec->reg_lock); in snd_ali_pointer()
1424 spin_unlock(&codec->reg_lock); in snd_ali_pointer()
1427 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_pointer()
1428 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); in snd_ali_pointer()
1429 spin_unlock(&codec->reg_lock); in snd_ali_pointer()
1485 struct snd_ali *codec; in snd_ali_pcm_free_substream() local
1488 codec = pvoice->codec; in snd_ali_pcm_free_substream()
1489 snd_ali_free_voice(pvoice->codec, pvoice); in snd_ali_pcm_free_substream()
1496 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_open() local
1500 pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, rec, in snd_ali_open()
1533 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_close() local
1536 snd_ali_disable_special_channel(codec,pvoice->number); in snd_ali_close()
1662 struct snd_ali *codec = pcm->private_data; in snd_ali_pcm_free() local
1663 codec->pcm[pcm->device] = NULL; in snd_ali_pcm_free()
1667 static int snd_ali_pcm(struct snd_ali *codec, int device, in snd_ali_pcm() argument
1673 err = snd_pcm_new(codec->card, desc->name, device, in snd_ali_pcm()
1676 dev_err(codec->card->dev, in snd_ali_pcm()
1680 pcm->private_data = codec; in snd_ali_pcm()
1690 snd_dma_pci_data(codec->pci), in snd_ali_pcm()
1697 codec->pcm[0] = pcm; in snd_ali_pcm()
1717 static int snd_ali_build_pcms(struct snd_ali *codec) in snd_ali_build_pcms() argument
1720 for (i = 0; i < codec->num_of_codecs && i < ARRAY_SIZE(ali_pcms); i++) { in snd_ali_build_pcms()
1721 err = snd_ali_pcm(codec, i, &ali_pcms[i]); in snd_ali_build_pcms()
1739 struct snd_ali *codec = kcontrol->private_data; in snd_ali5451_spdif_get() local
1744 spin_lock_irq(&codec->reg_lock); in snd_ali5451_spdif_get()
1747 spdif_enable = (codec->spdif_mask & 0x02) ? 1 : 0; in snd_ali5451_spdif_get()
1750 spdif_enable = ((codec->spdif_mask & 0x02) && in snd_ali5451_spdif_get()
1751 (codec->spdif_mask & 0x04)) ? 1 : 0; in snd_ali5451_spdif_get()
1754 spdif_enable = (codec->spdif_mask & 0x01) ? 1 : 0; in snd_ali5451_spdif_get()
1760 spin_unlock_irq(&codec->reg_lock); in snd_ali5451_spdif_get()
1767 struct snd_ali *codec = kcontrol->private_data; in snd_ali5451_spdif_put() local
1772 spin_lock_irq(&codec->reg_lock); in snd_ali5451_spdif_put()
1775 change = (codec->spdif_mask & 0x02) ? 1 : 0; in snd_ali5451_spdif_put()
1779 codec->spdif_mask |= 0x02; in snd_ali5451_spdif_put()
1780 snd_ali_enable_spdif_out(codec); in snd_ali5451_spdif_put()
1782 codec->spdif_mask &= ~(0x02); in snd_ali5451_spdif_put()
1783 codec->spdif_mask &= ~(0x04); in snd_ali5451_spdif_put()
1784 snd_ali_disable_spdif_out(codec); in snd_ali5451_spdif_put()
1789 change = (codec->spdif_mask & 0x04) ? 1 : 0; in snd_ali5451_spdif_put()
1791 if (change && (codec->spdif_mask & 0x02)) { in snd_ali5451_spdif_put()
1793 codec->spdif_mask |= 0x04; in snd_ali5451_spdif_put()
1794 snd_ali_enable_spdif_chnout(codec); in snd_ali5451_spdif_put()
1796 codec->spdif_mask &= ~(0x04); in snd_ali5451_spdif_put()
1797 snd_ali_disable_spdif_chnout(codec); in snd_ali5451_spdif_put()
1802 change = (codec->spdif_mask & 0x01) ? 1 : 0; in snd_ali5451_spdif_put()
1806 codec->spdif_mask |= 0x01; in snd_ali5451_spdif_put()
1807 snd_ali_enable_spdif_in(codec); in snd_ali5451_spdif_put()
1809 codec->spdif_mask &= ~(0x01); in snd_ali5451_spdif_put()
1810 snd_ali_disable_spdif_in(codec); in snd_ali5451_spdif_put()
1817 spin_unlock_irq(&codec->reg_lock); in snd_ali5451_spdif_put()
1832 static int snd_ali_mixer(struct snd_ali *codec) in snd_ali_mixer() argument
1842 err = snd_ac97_bus(codec->card, 0, &ops, codec, &codec->ac97_bus); in snd_ali_mixer()
1847 ac97.private_data = codec; in snd_ali_mixer()
1849 for (i = 0; i < codec->num_of_codecs; i++) { in snd_ali_mixer()
1851 err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i]); in snd_ali_mixer()
1853 dev_err(codec->card->dev, in snd_ali_mixer()
1857 codec->num_of_codecs = 1; in snd_ali_mixer()
1862 if (codec->spdif_support) { in snd_ali_mixer()
1864 err = snd_ctl_add(codec->card, in snd_ali_mixer()
1865 snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec)); in snd_ali_mixer()
1965 static int snd_ali_free(struct snd_ali * codec) in snd_ali_free() argument
1967 if (codec->hw_initialized) in snd_ali_free()
1968 snd_ali_disable_address_interrupt(codec); in snd_ali_free()
1969 if (codec->irq >= 0) in snd_ali_free()
1970 free_irq(codec->irq, codec); in snd_ali_free()
1971 if (codec->port) in snd_ali_free()
1972 pci_release_regions(codec->pci); in snd_ali_free()
1973 pci_disable_device(codec->pci); in snd_ali_free()
1975 kfree(codec->image); in snd_ali_free()
1977 pci_dev_put(codec->pci_m1533); in snd_ali_free()
1978 pci_dev_put(codec->pci_m7101); in snd_ali_free()
1979 kfree(codec); in snd_ali_free()
1983 static int snd_ali_chip_init(struct snd_ali *codec) in snd_ali_chip_init() argument
1989 dev_dbg(codec->card->dev, "chip initializing ...\n"); in snd_ali_chip_init()
1991 if (snd_ali_reset_5451(codec)) { in snd_ali_chip_init()
1992 dev_err(codec->card->dev, "ali_chip_init: reset 5451 error.\n"); in snd_ali_chip_init()
1996 if (codec->revision == ALI_5451_V02) { in snd_ali_chip_init()
1997 pci_dev = codec->pci_m1533; in snd_ali_chip_init()
2002 pci_dev = codec->pci_m7101; in snd_ali_chip_init()
2008 pci_read_config_dword(codec->pci, 0x44, &legacy); in snd_ali_chip_init()
2011 pci_write_config_dword(codec->pci, 0x44, legacy); in snd_ali_chip_init()
2013 outl(0x80000001, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_chip_init()
2014 outl(0x00000000, ALI_REG(codec, ALI_AINTEN)); in snd_ali_chip_init()
2015 outl(0xffffffff, ALI_REG(codec, ALI_AINT)); in snd_ali_chip_init()
2016 outl(0x00000000, ALI_REG(codec, ALI_VOLUME)); in snd_ali_chip_init()
2017 outb(0x10, ALI_REG(codec, ALI_MPUR2)); in snd_ali_chip_init()
2019 codec->ac97_ext_id = snd_ali_codec_peek(codec, 0, AC97_EXTENDED_ID); in snd_ali_chip_init()
2020 codec->ac97_ext_status = snd_ali_codec_peek(codec, 0, in snd_ali_chip_init()
2022 if (codec->spdif_support) { in snd_ali_chip_init()
2023 snd_ali_enable_spdif_out(codec); in snd_ali_chip_init()
2024 codec->spdif_mask = 0x00000002; in snd_ali_chip_init()
2027 codec->num_of_codecs = 1; in snd_ali_chip_init()
2030 if (inl(ALI_REG(codec, ALI_SCTRL)) & ALI_SCTRL_CODEC2_READY) { in snd_ali_chip_init()
2031 codec->num_of_codecs++; in snd_ali_chip_init()
2032 outl(inl(ALI_REG(codec, ALI_SCTRL)) | in snd_ali_chip_init()
2035 ALI_REG(codec, ALI_SCTRL)); in snd_ali_chip_init()
2038 dev_dbg(codec->card->dev, "chip initialize succeed.\n"); in snd_ali_chip_init()
2047 struct snd_ali *codec = entry->private_data; in snd_ali_proc_read() local
2050 snd_iprintf(buf, "%02x: %08x\n", i, inl(ALI_REG(codec, i))); in snd_ali_proc_read()
2053 static void snd_ali_proc_init(struct snd_ali *codec) in snd_ali_proc_init() argument
2056 if (!snd_card_proc_new(codec->card, "ali5451", &entry)) in snd_ali_proc_init()
2057 snd_info_set_text_ops(entry, codec, snd_ali_proc_read); in snd_ali_proc_init()
2060 static int snd_ali_resources(struct snd_ali *codec) in snd_ali_resources() argument
2064 dev_dbg(codec->card->dev, "resources allocation ...\n"); in snd_ali_resources()
2065 err = pci_request_regions(codec->pci, "ALI 5451"); in snd_ali_resources()
2068 codec->port = pci_resource_start(codec->pci, 0); in snd_ali_resources()
2070 if (request_irq(codec->pci->irq, snd_ali_card_interrupt, in snd_ali_resources()
2071 IRQF_SHARED, KBUILD_MODNAME, codec)) { in snd_ali_resources()
2072 dev_err(codec->card->dev, "Unable to request irq.\n"); in snd_ali_resources()
2075 codec->irq = codec->pci->irq; in snd_ali_resources()
2076 dev_dbg(codec->card->dev, "resources allocated.\n"); in snd_ali_resources()
2081 struct snd_ali *codec = device->device_data; in snd_ali_dev_free() local
2082 snd_ali_free(codec); in snd_ali_dev_free()
2092 struct snd_ali *codec; in snd_ali_create() local
2116 codec = kzalloc(sizeof(*codec), GFP_KERNEL); in snd_ali_create()
2117 if (!codec) { in snd_ali_create()
2122 spin_lock_init(&codec->reg_lock); in snd_ali_create()
2123 spin_lock_init(&codec->voice_alloc); in snd_ali_create()
2125 codec->card = card; in snd_ali_create()
2126 codec->pci = pci; in snd_ali_create()
2127 codec->irq = -1; in snd_ali_create()
2128 codec->revision = pci->revision; in snd_ali_create()
2129 codec->spdif_support = spdif_support; in snd_ali_create()
2144 if (snd_ali_resources(codec)) { in snd_ali_create()
2145 snd_ali_free(codec); in snd_ali_create()
2151 codec->synth.chmap = 0; in snd_ali_create()
2152 codec->synth.chcnt = 0; in snd_ali_create()
2153 codec->spdif_mask = 0; in snd_ali_create()
2154 codec->synth.synthcount = 0; in snd_ali_create()
2156 if (codec->revision == ALI_5451_V02) in snd_ali_create()
2157 codec->chregs.regs.ac97read = ALI_AC97_WRITE; in snd_ali_create()
2159 codec->chregs.regs.ac97read = ALI_AC97_READ; in snd_ali_create()
2160 codec->chregs.regs.ac97write = ALI_AC97_WRITE; in snd_ali_create()
2162 codec->chregs.regs.start = ALI_START; in snd_ali_create()
2163 codec->chregs.regs.stop = ALI_STOP; in snd_ali_create()
2164 codec->chregs.regs.aint = ALI_AINT; in snd_ali_create()
2165 codec->chregs.regs.ainten = ALI_AINTEN; in snd_ali_create()
2167 codec->chregs.data.start = 0x00; in snd_ali_create()
2168 codec->chregs.data.stop = 0x00; in snd_ali_create()
2169 codec->chregs.data.aint = 0x00; in snd_ali_create()
2170 codec->chregs.data.ainten = 0x00; in snd_ali_create()
2173 codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL); in snd_ali_create()
2174 if (!codec->pci_m1533) { in snd_ali_create()
2176 snd_ali_free(codec); in snd_ali_create()
2180 codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL); in snd_ali_create()
2181 if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) { in snd_ali_create()
2183 snd_ali_free(codec); in snd_ali_create()
2188 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops); in snd_ali_create()
2190 snd_ali_free(codec); in snd_ali_create()
2196 codec->synth.voices[i].number = i; in snd_ali_create()
2198 err = snd_ali_chip_init(codec); in snd_ali_create()
2205 codec->image = kmalloc(sizeof(*codec->image), GFP_KERNEL); in snd_ali_create()
2206 if (!codec->image) in snd_ali_create()
2210 snd_ali_enable_address_interrupt(codec); in snd_ali_create()
2211 codec->hw_initialized = 1; in snd_ali_create()
2213 *r_ali = codec; in snd_ali_create()
2222 struct snd_ali *codec; in snd_ali_probe() local
2231 err = snd_ali_create(card, pci, pcm_channels, spdif, &codec); in snd_ali_probe()
2234 card->private_data = codec; in snd_ali_probe()
2237 err = snd_ali_mixer(codec); in snd_ali_probe()
2242 err = snd_ali_build_pcms(codec); in snd_ali_probe()
2246 snd_ali_proc_init(codec); in snd_ali_probe()
2252 card->shortname, codec->port, codec->irq); in snd_ali_probe()