Lines Matching full:codec
142 #define ALI_REG(codec, x) ((codec)->port + x) argument
181 struct snd_ali *codec; member
267 static inline unsigned int snd_ali_5451_peek(struct snd_ali *codec, in snd_ali_5451_peek() argument
270 return (unsigned int)inl(ALI_REG(codec, port)); in snd_ali_5451_peek()
273 static inline void snd_ali_5451_poke(struct snd_ali *codec, in snd_ali_5451_poke() argument
277 outl((unsigned int)val, ALI_REG(codec, port)); in snd_ali_5451_poke()
280 static int snd_ali_codec_ready(struct snd_ali *codec, in snd_ali_codec_ready() argument
289 res = snd_ali_5451_peek(codec,port); in snd_ali_codec_ready()
297 snd_ali_5451_poke(codec, port, res & ~0x8000); in snd_ali_codec_ready()
298 dev_dbg(codec->card->dev, "ali_codec_ready: codec is not ready.\n "); in snd_ali_codec_ready()
302 static int snd_ali_stimer_ready(struct snd_ali *codec) in snd_ali_stimer_ready() argument
307 dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER); in snd_ali_stimer_ready()
311 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); in snd_ali_stimer_ready()
319 dev_err(codec->card->dev, "ali_stimer_read: stimer is not ready.\n"); in snd_ali_stimer_ready()
323 static void snd_ali_codec_poke(struct snd_ali *codec,int secondary, in snd_ali_codec_poke() argument
331 dev_err(codec->card->dev, in snd_ali_codec_poke()
336 port = codec->chregs.regs.ac97write; in snd_ali_codec_poke()
338 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_poke()
340 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_poke()
347 if (codec->revision == ALI_5451_V02) in snd_ali_codec_poke()
350 snd_ali_5451_poke(codec, port, dwVal); in snd_ali_codec_poke()
355 static unsigned short snd_ali_codec_peek(struct snd_ali *codec, in snd_ali_codec_peek() argument
363 dev_err(codec->card->dev, in snd_ali_codec_peek()
368 port = codec->chregs.regs.ac97read; in snd_ali_codec_peek()
370 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_peek()
372 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_peek()
380 snd_ali_5451_poke(codec, port, dwVal); in snd_ali_codec_peek()
382 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_peek()
384 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_peek()
387 return (snd_ali_5451_peek(codec, port) & 0xffff0000) >> 16; in snd_ali_codec_peek()
394 struct snd_ali *codec = ac97->private_data; in snd_ali_codec_write() local
396 dev_dbg(codec->card->dev, "codec_write: reg=%xh data=%xh.\n", reg, val); in snd_ali_codec_write()
399 ALI_REG(codec, ALI_AC97_GPIO)); in snd_ali_codec_write()
402 snd_ali_codec_poke(codec, ac97->num, reg, val); in snd_ali_codec_write()
410 struct snd_ali *codec = ac97->private_data; in snd_ali_codec_read() local
412 dev_dbg(codec->card->dev, "codec_read reg=%xh.\n", reg); in snd_ali_codec_read()
413 return snd_ali_codec_peek(codec, ac97->num, reg); in snd_ali_codec_read()
420 static int snd_ali_reset_5451(struct snd_ali *codec) in snd_ali_reset_5451() argument
426 pci_dev = codec->pci_m1533; in snd_ali_reset_5451()
436 pci_dev = codec->pci; in snd_ali_reset_5451()
446 wReg = snd_ali_codec_peek(codec, 0, AC97_POWERDOWN); in snd_ali_reset_5451()
452 /* non-fatal if you have a non PM capable codec */ in snd_ali_reset_5451()
453 /* dev_warn(codec->card->dev, "ali5451: reset time out\n"); */ in snd_ali_reset_5451()
461 static void snd_ali_enable_special_channel(struct snd_ali *codec, in snd_ali_enable_special_channel() argument
466 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_special_channel()
468 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_special_channel()
471 static void snd_ali_disable_special_channel(struct snd_ali *codec, in snd_ali_disable_special_channel() argument
476 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_special_channel()
478 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_special_channel()
481 static void snd_ali_enable_address_interrupt(struct snd_ali *codec) in snd_ali_enable_address_interrupt() argument
485 gc = inl(ALI_REG(codec, ALI_GC_CIR)); in snd_ali_enable_address_interrupt()
488 outl( gc, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_enable_address_interrupt()
491 static void snd_ali_disable_address_interrupt(struct snd_ali *codec) in snd_ali_disable_address_interrupt() argument
495 gc = inl(ALI_REG(codec, ALI_GC_CIR)); in snd_ali_disable_address_interrupt()
498 outl(gc, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_disable_address_interrupt()
501 static void snd_ali_disable_voice_irq(struct snd_ali *codec, in snd_ali_disable_voice_irq() argument
505 struct snd_ali_channel_control *pchregs = &(codec->chregs); in snd_ali_disable_voice_irq()
507 dev_dbg(codec->card->dev, "disable_voice_irq channel=%d\n", channel); in snd_ali_disable_voice_irq()
510 pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten)); in snd_ali_disable_voice_irq()
512 outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten)); in snd_ali_disable_voice_irq()
515 static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel) in snd_ali_alloc_pcm_channel() argument
519 if (codec->synth.chcnt >= ALI_CHANNELS){ in snd_ali_alloc_pcm_channel()
520 dev_err(codec->card->dev, in snd_ali_alloc_pcm_channel()
525 if (!(codec->synth.chmap & (1 << idx))) { in snd_ali_alloc_pcm_channel()
526 codec->synth.chmap |= 1 << idx; in snd_ali_alloc_pcm_channel()
527 codec->synth.chcnt++; in snd_ali_alloc_pcm_channel()
528 dev_dbg(codec->card->dev, "alloc_pcm_channel no. %d.\n", idx); in snd_ali_alloc_pcm_channel()
534 static int snd_ali_find_free_channel(struct snd_ali * codec, int rec) in snd_ali_find_free_channel() argument
539 dev_dbg(codec->card->dev, in snd_ali_find_free_channel()
544 if (codec->spdif_support && in snd_ali_find_free_channel()
545 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_find_free_channel()
551 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
555 dev_err(codec->card->dev, in snd_ali_find_free_channel()
562 if (codec->spdif_support && in snd_ali_find_free_channel()
563 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_find_free_channel()
566 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
570 dev_err(codec->card->dev, in snd_ali_find_free_channel()
575 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
579 dev_err(codec->card->dev, "ali_find_free_channel: no free channels.\n"); in snd_ali_find_free_channel()
583 static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel) in snd_ali_free_channel_pcm() argument
587 dev_dbg(codec->card->dev, "free_channel_pcm channel=%d\n", channel); in snd_ali_free_channel_pcm()
592 if (!(codec->synth.chmap & (1 << idx))) { in snd_ali_free_channel_pcm()
593 dev_err(codec->card->dev, in snd_ali_free_channel_pcm()
598 codec->synth.chmap &= ~(1 << idx); in snd_ali_free_channel_pcm()
599 codec->synth.chcnt--; in snd_ali_free_channel_pcm()
603 static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel) in snd_ali_stop_voice() argument
607 dev_dbg(codec->card->dev, "stop_voice: channel=%d\n", channel); in snd_ali_stop_voice()
608 outl(mask, ALI_REG(codec, codec->chregs.regs.stop)); in snd_ali_stop_voice()
615 static void snd_ali_delay(struct snd_ali *codec,int interval) in snd_ali_delay() argument
619 begintimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
620 currenttimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
623 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_delay()
625 currenttimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
630 static void snd_ali_detect_spdif_rate(struct snd_ali *codec) in snd_ali_detect_spdif_rate() argument
636 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
638 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
642 snd_ali_delay(codec, 6); in snd_ali_detect_spdif_rate()
643 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
648 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n"); in snd_ali_detect_spdif_rate()
653 snd_ali_delay(codec, 6); in snd_ali_detect_spdif_rate()
654 bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
663 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n"); in snd_ali_detect_spdif_rate()
668 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
671 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
673 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)) & 0xf0; in snd_ali_detect_spdif_rate()
674 outb(bval | 0x02, ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_detect_spdif_rate()
676 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
679 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
681 bval = inb(ALI_REG(codec,ALI_SPDIF_CS + 3)) & 0xf0; in snd_ali_detect_spdif_rate()
682 outb(bval | 0x03, ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_detect_spdif_rate()
686 static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali *codec) in snd_ali_get_spdif_in_rate() argument
691 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_get_spdif_in_rate()
694 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_get_spdif_in_rate()
696 snd_ali_detect_spdif_rate(codec); in snd_ali_get_spdif_in_rate()
698 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_get_spdif_in_rate()
711 static void snd_ali_enable_spdif_in(struct snd_ali *codec) in snd_ali_enable_spdif_in() argument
715 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_in()
717 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_in()
719 dwVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_in()
721 outb(dwVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_in()
723 snd_ali_enable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); in snd_ali_enable_spdif_in()
726 static void snd_ali_disable_spdif_in(struct snd_ali *codec) in snd_ali_disable_spdif_in() argument
730 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_in()
732 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_in()
734 snd_ali_disable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); in snd_ali_disable_spdif_in()
738 static void snd_ali_set_spdif_out_rate(struct snd_ali *codec, unsigned int rate) in snd_ali_set_spdif_out_rate() argument
749 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
753 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
754 outb(dwRate | 0x20, ALI_REG(codec, ALI_SPDIF_CS + 2)); in snd_ali_set_spdif_out_rate()
757 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
758 outw(rate | 0x10, ALI_REG(codec, ALI_SPDIF_CS + 2)); in snd_ali_set_spdif_out_rate()
761 static void snd_ali_enable_spdif_out(struct snd_ali *codec) in snd_ali_enable_spdif_out() argument
767 pci_dev = codec->pci_m1533; in snd_ali_enable_spdif_out()
782 bVal = inb(ALI_REG(codec, ALI_SCTRL)); in snd_ali_enable_spdif_out()
783 outb(bVal | ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); in snd_ali_enable_spdif_out()
785 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_out()
786 outb(bVal & ALI_SPDIF_OUT_CH_STATUS, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_out()
788 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_out()
790 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_out()
791 snd_ali_disable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_enable_spdif_out()
794 static void snd_ali_enable_spdif_chnout(struct snd_ali *codec) in snd_ali_enable_spdif_chnout() argument
798 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_chnout()
800 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_chnout()
802 wVal = inw(ALI_REG(codec, ALI_SPDIF_CS)); in snd_ali_enable_spdif_chnout()
807 outw(wVal, ALI_REG(codec, ALI_SPDIF_CS)); in snd_ali_enable_spdif_chnout()
809 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_enable_spdif_chnout()
812 static void snd_ali_disable_spdif_chnout(struct snd_ali *codec) in snd_ali_disable_spdif_chnout() argument
816 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_chnout()
818 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_chnout()
820 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_disable_spdif_chnout()
823 static void snd_ali_disable_spdif_out(struct snd_ali *codec) in snd_ali_disable_spdif_out() argument
827 bVal = inb(ALI_REG(codec, ALI_SCTRL)); in snd_ali_disable_spdif_out()
828 outb(bVal & ~ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); in snd_ali_disable_spdif_out()
830 snd_ali_disable_spdif_chnout(codec); in snd_ali_disable_spdif_out()
833 static void snd_ali_update_ptr(struct snd_ali *codec, int channel) in snd_ali_update_ptr() argument
839 pchregs = &(codec->chregs); in snd_ali_update_ptr()
848 pvoice = &codec->synth.voices[channel]; in snd_ali_update_ptr()
851 spin_lock(&codec->reg_lock); in snd_ali_update_ptr()
856 dev_dbg(codec->card->dev, in snd_ali_update_ptr()
858 inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)), in snd_ali_update_ptr()
859 (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask); in snd_ali_update_ptr()
860 spin_unlock(&codec->reg_lock); in snd_ali_update_ptr()
862 spin_lock(&codec->reg_lock); in snd_ali_update_ptr()
864 snd_ali_stop_voice(codec, channel); in snd_ali_update_ptr()
865 snd_ali_disable_voice_irq(codec, channel); in snd_ali_update_ptr()
867 } else if (codec->synth.voices[channel].synth) { in snd_ali_update_ptr()
869 } else if (codec->synth.voices[channel].midi) { in snd_ali_update_ptr()
873 snd_ali_stop_voice(codec, channel); in snd_ali_update_ptr()
874 snd_ali_disable_voice_irq(codec, channel); in snd_ali_update_ptr()
876 spin_unlock(&codec->reg_lock); in snd_ali_update_ptr()
877 outl(mask,ALI_REG(codec,pchregs->regs.aint)); in snd_ali_update_ptr()
883 struct snd_ali *codec = dev_id; in snd_ali_card_interrupt() local
888 if (codec == NULL || !codec->hw_initialized) in snd_ali_card_interrupt()
891 audio_int = inl(ALI_REG(codec, ALI_MISCINT)); in snd_ali_card_interrupt()
895 pchregs = &(codec->chregs); in snd_ali_card_interrupt()
898 pchregs->data.aint = inl(ALI_REG(codec, pchregs->regs.aint)); in snd_ali_card_interrupt()
900 snd_ali_update_ptr(codec, channel); in snd_ali_card_interrupt()
903 ALI_REG(codec, ALI_MISCINT)); in snd_ali_card_interrupt()
909 static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec, in snd_ali_alloc_voice() argument
915 dev_dbg(codec->card->dev, "alloc_voice: type=%d rec=%d\n", type, rec); in snd_ali_alloc_voice()
917 spin_lock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
919 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : in snd_ali_alloc_voice()
920 snd_ali_find_free_channel(codec,rec); in snd_ali_alloc_voice()
922 dev_err(codec->card->dev, "ali_alloc_voice: err.\n"); in snd_ali_alloc_voice()
923 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
926 pvoice = &(codec->synth.voices[idx]); in snd_ali_alloc_voice()
927 pvoice->codec = codec; in snd_ali_alloc_voice()
931 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
934 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
939 static void snd_ali_free_voice(struct snd_ali * codec, in snd_ali_free_voice() argument
945 dev_dbg(codec->card->dev, "free_voice: channel=%d\n", pvoice->number); in snd_ali_free_voice()
948 snd_ali_clear_voices(codec, pvoice->number, pvoice->number); in snd_ali_free_voice()
949 spin_lock_irq(&codec->voice_alloc); in snd_ali_free_voice()
955 snd_ali_free_channel_pcm(codec, pvoice->number); in snd_ali_free_voice()
958 spin_unlock_irq(&codec->voice_alloc); in snd_ali_free_voice()
964 static void snd_ali_clear_voices(struct snd_ali *codec, in snd_ali_clear_voices() argument
971 snd_ali_stop_voice(codec, i); in snd_ali_clear_voices()
972 snd_ali_disable_voice_irq(codec, i); in snd_ali_clear_voices()
976 static void snd_ali_write_voice_regs(struct snd_ali *codec, in snd_ali_write_voice_regs() argument
991 outb((unsigned char)(Channel & 0x001f), ALI_REG(codec, ALI_GC_CIR)); in snd_ali_write_voice_regs()
1002 outb(Channel, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_write_voice_regs()
1004 outl(ctlcmds[0], ALI_REG(codec, ALI_CSO_ALPHA_FMS)); in snd_ali_write_voice_regs()
1005 outl(ctlcmds[1], ALI_REG(codec, ALI_LBA)); in snd_ali_write_voice_regs()
1006 outl(ctlcmds[2], ALI_REG(codec, ALI_ESO_DELTA)); in snd_ali_write_voice_regs()
1007 outl(ctlcmds[3], ALI_REG(codec, ALI_GVSEL_PAN_VOC_CTRL_EC)); in snd_ali_write_voice_regs()
1009 outl(0x30000000, ALI_REG(codec, ALI_EBUF1)); /* Still Mode */ in snd_ali_write_voice_regs()
1010 outl(0x30000000, ALI_REG(codec, ALI_EBUF2)); /* Still Mode */ in snd_ali_write_voice_regs()
1071 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_trigger() local
1093 if ((struct snd_ali *) snd_pcm_substream_chip(s) == codec) { in snd_ali_trigger()
1117 spin_lock(&codec->reg_lock); in snd_ali_trigger()
1119 outl(what, ALI_REG(codec, ALI_STOP)); in snd_ali_trigger()
1120 val = inl(ALI_REG(codec, ALI_AINTEN)); in snd_ali_trigger()
1125 outl(val, ALI_REG(codec, ALI_AINTEN)); in snd_ali_trigger()
1127 outl(what, ALI_REG(codec, ALI_START)); in snd_ali_trigger()
1128 dev_dbg(codec->card->dev, "trigger: what=%xh whati=%xh\n", what, whati); in snd_ali_trigger()
1129 spin_unlock(&codec->reg_lock); in snd_ali_trigger()
1137 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_hw_params() local
1153 evoice = snd_ali_alloc_voice(codec, in snd_ali_playback_hw_params()
1163 snd_ali_free_voice(codec, evoice); in snd_ali_playback_hw_params()
1173 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_hw_free() local
1180 snd_ali_free_voice(codec, evoice); in snd_ali_playback_hw_free()
1200 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_prepare() local
1214 dev_dbg(codec->card->dev, "playback_prepare ...\n"); in snd_ali_playback_prepare()
1216 spin_lock_irq(&codec->reg_lock); in snd_ali_playback_prepare()
1223 snd_ali_disable_special_channel(codec, pvoice->number); in snd_ali_playback_prepare()
1224 else if (codec->spdif_support && in snd_ali_playback_prepare()
1225 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_playback_prepare()
1228 snd_ali_set_spdif_out_rate(codec, runtime->rate); in snd_ali_playback_prepare()
1241 dev_dbg(codec->card->dev, "playback_prepare: eso=%xh count=%xh\n", in snd_ali_playback_prepare()
1253 dev_dbg(codec->card->dev, "playback_prepare:\n"); in snd_ali_playback_prepare()
1254 dev_dbg(codec->card->dev, in snd_ali_playback_prepare()
1257 snd_ali_write_voice_regs(codec, in snd_ali_playback_prepare()
1273 snd_ali_write_voice_regs(codec, in snd_ali_playback_prepare()
1286 spin_unlock_irq(&codec->reg_lock); in snd_ali_playback_prepare()
1293 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_prepare() local
1306 spin_lock_irq(&codec->reg_lock); in snd_ali_prepare()
1308 dev_dbg(codec->card->dev, "ali_prepare...\n"); in snd_ali_prepare()
1310 snd_ali_enable_special_channel(codec,pvoice->number); in snd_ali_prepare()
1321 spin_unlock_irq(&codec->reg_lock); in snd_ali_prepare()
1322 if (codec->revision != ALI_5451_V02) in snd_ali_prepare()
1325 rate = snd_ali_get_spdif_in_rate(codec); in snd_ali_prepare()
1327 dev_warn(codec->card->dev, in snd_ali_prepare()
1331 spin_lock_irq(&codec->reg_lock); in snd_ali_prepare()
1332 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL)); in snd_ali_prepare()
1334 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL)); in snd_ali_prepare()
1335 dev_warn(codec->card->dev, in snd_ali_prepare()
1360 snd_ali_write_voice_regs( codec, in snd_ali_prepare()
1373 spin_unlock_irq(&codec->reg_lock); in snd_ali_prepare()
1382 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_pointer() local
1387 spin_lock(&codec->reg_lock); in snd_ali_playback_pointer()
1389 spin_unlock(&codec->reg_lock); in snd_ali_playback_pointer()
1392 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_playback_pointer()
1393 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); in snd_ali_playback_pointer()
1394 spin_unlock(&codec->reg_lock); in snd_ali_playback_pointer()
1395 dev_dbg(codec->card->dev, "playback pointer returned cso=%xh.\n", cso); in snd_ali_playback_pointer()
1404 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_pointer() local
1409 spin_lock(&codec->reg_lock); in snd_ali_pointer()
1411 spin_unlock(&codec->reg_lock); in snd_ali_pointer()
1414 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_pointer()
1415 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); in snd_ali_pointer()
1416 spin_unlock(&codec->reg_lock); in snd_ali_pointer()
1475 snd_ali_free_voice(pvoice->codec, pvoice); in snd_ali_pcm_free_substream()
1481 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_open() local
1485 pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, rec, in snd_ali_open()
1518 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_close() local
1521 snd_ali_disable_special_channel(codec,pvoice->number); in snd_ali_close()
1647 struct snd_ali *codec = pcm->private_data; in snd_ali_pcm_free() local
1648 codec->pcm[pcm->device] = NULL; in snd_ali_pcm_free()
1652 static int snd_ali_pcm(struct snd_ali *codec, int device, in snd_ali_pcm() argument
1658 err = snd_pcm_new(codec->card, desc->name, device, in snd_ali_pcm()
1661 dev_err(codec->card->dev, in snd_ali_pcm()
1665 pcm->private_data = codec; in snd_ali_pcm()
1675 snd_dma_pci_data(codec->pci), in snd_ali_pcm()
1682 codec->pcm[0] = pcm; in snd_ali_pcm()
1702 static int snd_ali_build_pcms(struct snd_ali *codec) in snd_ali_build_pcms() argument
1705 for (i = 0; i < codec->num_of_codecs && i < ARRAY_SIZE(ali_pcms); i++) { in snd_ali_build_pcms()
1706 err = snd_ali_pcm(codec, i, &ali_pcms[i]); in snd_ali_build_pcms()
1724 struct snd_ali *codec = kcontrol->private_data; in snd_ali5451_spdif_get() local
1729 spin_lock_irq(&codec->reg_lock); in snd_ali5451_spdif_get()
1732 spdif_enable = (codec->spdif_mask & 0x02) ? 1 : 0; in snd_ali5451_spdif_get()
1735 spdif_enable = ((codec->spdif_mask & 0x02) && in snd_ali5451_spdif_get()
1736 (codec->spdif_mask & 0x04)) ? 1 : 0; in snd_ali5451_spdif_get()
1739 spdif_enable = (codec->spdif_mask & 0x01) ? 1 : 0; in snd_ali5451_spdif_get()
1745 spin_unlock_irq(&codec->reg_lock); in snd_ali5451_spdif_get()
1752 struct snd_ali *codec = kcontrol->private_data; in snd_ali5451_spdif_put() local
1757 spin_lock_irq(&codec->reg_lock); in snd_ali5451_spdif_put()
1760 change = (codec->spdif_mask & 0x02) ? 1 : 0; in snd_ali5451_spdif_put()
1764 codec->spdif_mask |= 0x02; in snd_ali5451_spdif_put()
1765 snd_ali_enable_spdif_out(codec); in snd_ali5451_spdif_put()
1767 codec->spdif_mask &= ~(0x02); in snd_ali5451_spdif_put()
1768 codec->spdif_mask &= ~(0x04); in snd_ali5451_spdif_put()
1769 snd_ali_disable_spdif_out(codec); in snd_ali5451_spdif_put()
1774 change = (codec->spdif_mask & 0x04) ? 1 : 0; in snd_ali5451_spdif_put()
1776 if (change && (codec->spdif_mask & 0x02)) { in snd_ali5451_spdif_put()
1778 codec->spdif_mask |= 0x04; in snd_ali5451_spdif_put()
1779 snd_ali_enable_spdif_chnout(codec); in snd_ali5451_spdif_put()
1781 codec->spdif_mask &= ~(0x04); in snd_ali5451_spdif_put()
1782 snd_ali_disable_spdif_chnout(codec); in snd_ali5451_spdif_put()
1787 change = (codec->spdif_mask & 0x01) ? 1 : 0; in snd_ali5451_spdif_put()
1791 codec->spdif_mask |= 0x01; in snd_ali5451_spdif_put()
1792 snd_ali_enable_spdif_in(codec); in snd_ali5451_spdif_put()
1794 codec->spdif_mask &= ~(0x01); in snd_ali5451_spdif_put()
1795 snd_ali_disable_spdif_in(codec); in snd_ali5451_spdif_put()
1802 spin_unlock_irq(&codec->reg_lock); in snd_ali5451_spdif_put()
1817 static int snd_ali_mixer(struct snd_ali *codec) in snd_ali_mixer() argument
1827 err = snd_ac97_bus(codec->card, 0, &ops, codec, &codec->ac97_bus); in snd_ali_mixer()
1832 ac97.private_data = codec; in snd_ali_mixer()
1834 for (i = 0; i < codec->num_of_codecs; i++) { in snd_ali_mixer()
1836 err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i]); in snd_ali_mixer()
1838 dev_err(codec->card->dev, in snd_ali_mixer()
1842 codec->num_of_codecs = 1; in snd_ali_mixer()
1847 if (codec->spdif_support) { in snd_ali_mixer()
1849 err = snd_ctl_add(codec->card, in snd_ali_mixer()
1850 snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec)); in snd_ali_mixer()
1948 static int snd_ali_free(struct snd_ali * codec) in snd_ali_free() argument
1950 if (codec->hw_initialized) in snd_ali_free()
1951 snd_ali_disable_address_interrupt(codec); in snd_ali_free()
1952 if (codec->irq >= 0) in snd_ali_free()
1953 free_irq(codec->irq, codec); in snd_ali_free()
1954 if (codec->port) in snd_ali_free()
1955 pci_release_regions(codec->pci); in snd_ali_free()
1956 pci_disable_device(codec->pci); in snd_ali_free()
1958 kfree(codec->image); in snd_ali_free()
1960 pci_dev_put(codec->pci_m1533); in snd_ali_free()
1961 pci_dev_put(codec->pci_m7101); in snd_ali_free()
1962 kfree(codec); in snd_ali_free()
1966 static int snd_ali_chip_init(struct snd_ali *codec) in snd_ali_chip_init() argument
1972 dev_dbg(codec->card->dev, "chip initializing ...\n"); in snd_ali_chip_init()
1974 if (snd_ali_reset_5451(codec)) { in snd_ali_chip_init()
1975 dev_err(codec->card->dev, "ali_chip_init: reset 5451 error.\n"); in snd_ali_chip_init()
1979 if (codec->revision == ALI_5451_V02) { in snd_ali_chip_init()
1980 pci_dev = codec->pci_m1533; in snd_ali_chip_init()
1985 pci_dev = codec->pci_m7101; in snd_ali_chip_init()
1991 pci_read_config_dword(codec->pci, 0x44, &legacy); in snd_ali_chip_init()
1994 pci_write_config_dword(codec->pci, 0x44, legacy); in snd_ali_chip_init()
1996 outl(0x80000001, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_chip_init()
1997 outl(0x00000000, ALI_REG(codec, ALI_AINTEN)); in snd_ali_chip_init()
1998 outl(0xffffffff, ALI_REG(codec, ALI_AINT)); in snd_ali_chip_init()
1999 outl(0x00000000, ALI_REG(codec, ALI_VOLUME)); in snd_ali_chip_init()
2000 outb(0x10, ALI_REG(codec, ALI_MPUR2)); in snd_ali_chip_init()
2002 codec->ac97_ext_id = snd_ali_codec_peek(codec, 0, AC97_EXTENDED_ID); in snd_ali_chip_init()
2003 codec->ac97_ext_status = snd_ali_codec_peek(codec, 0, in snd_ali_chip_init()
2005 if (codec->spdif_support) { in snd_ali_chip_init()
2006 snd_ali_enable_spdif_out(codec); in snd_ali_chip_init()
2007 codec->spdif_mask = 0x00000002; in snd_ali_chip_init()
2010 codec->num_of_codecs = 1; in snd_ali_chip_init()
2012 /* secondary codec - modem */ in snd_ali_chip_init()
2013 if (inl(ALI_REG(codec, ALI_SCTRL)) & ALI_SCTRL_CODEC2_READY) { in snd_ali_chip_init()
2014 codec->num_of_codecs++; in snd_ali_chip_init()
2015 outl(inl(ALI_REG(codec, ALI_SCTRL)) | in snd_ali_chip_init()
2018 ALI_REG(codec, ALI_SCTRL)); in snd_ali_chip_init()
2021 dev_dbg(codec->card->dev, "chip initialize succeed.\n"); in snd_ali_chip_init()
2030 struct snd_ali *codec = entry->private_data; in snd_ali_proc_read() local
2033 snd_iprintf(buf, "%02x: %08x\n", i, inl(ALI_REG(codec, i))); in snd_ali_proc_read()
2036 static void snd_ali_proc_init(struct snd_ali *codec) in snd_ali_proc_init() argument
2038 snd_card_ro_proc_new(codec->card, "ali5451", codec, snd_ali_proc_read); in snd_ali_proc_init()
2041 static int snd_ali_resources(struct snd_ali *codec) in snd_ali_resources() argument
2045 dev_dbg(codec->card->dev, "resources allocation ...\n"); in snd_ali_resources()
2046 err = pci_request_regions(codec->pci, "ALI 5451"); in snd_ali_resources()
2049 codec->port = pci_resource_start(codec->pci, 0); in snd_ali_resources()
2051 if (request_irq(codec->pci->irq, snd_ali_card_interrupt, in snd_ali_resources()
2052 IRQF_SHARED, KBUILD_MODNAME, codec)) { in snd_ali_resources()
2053 dev_err(codec->card->dev, "Unable to request irq.\n"); in snd_ali_resources()
2056 codec->irq = codec->pci->irq; in snd_ali_resources()
2057 dev_dbg(codec->card->dev, "resources allocated.\n"); in snd_ali_resources()
2062 struct snd_ali *codec = device->device_data; in snd_ali_dev_free() local
2063 snd_ali_free(codec); in snd_ali_dev_free()
2073 struct snd_ali *codec; in snd_ali_create() local
2097 codec = kzalloc(sizeof(*codec), GFP_KERNEL); in snd_ali_create()
2098 if (!codec) { in snd_ali_create()
2103 spin_lock_init(&codec->reg_lock); in snd_ali_create()
2104 spin_lock_init(&codec->voice_alloc); in snd_ali_create()
2106 codec->card = card; in snd_ali_create()
2107 codec->pci = pci; in snd_ali_create()
2108 codec->irq = -1; in snd_ali_create()
2109 codec->revision = pci->revision; in snd_ali_create()
2110 codec->spdif_support = spdif_support; in snd_ali_create()
2125 if (snd_ali_resources(codec)) { in snd_ali_create()
2126 snd_ali_free(codec); in snd_ali_create()
2132 codec->synth.chmap = 0; in snd_ali_create()
2133 codec->synth.chcnt = 0; in snd_ali_create()
2134 codec->spdif_mask = 0; in snd_ali_create()
2135 codec->synth.synthcount = 0; in snd_ali_create()
2137 if (codec->revision == ALI_5451_V02) in snd_ali_create()
2138 codec->chregs.regs.ac97read = ALI_AC97_WRITE; in snd_ali_create()
2140 codec->chregs.regs.ac97read = ALI_AC97_READ; in snd_ali_create()
2141 codec->chregs.regs.ac97write = ALI_AC97_WRITE; in snd_ali_create()
2143 codec->chregs.regs.start = ALI_START; in snd_ali_create()
2144 codec->chregs.regs.stop = ALI_STOP; in snd_ali_create()
2145 codec->chregs.regs.aint = ALI_AINT; in snd_ali_create()
2146 codec->chregs.regs.ainten = ALI_AINTEN; in snd_ali_create()
2148 codec->chregs.data.start = 0x00; in snd_ali_create()
2149 codec->chregs.data.stop = 0x00; in snd_ali_create()
2150 codec->chregs.data.aint = 0x00; in snd_ali_create()
2151 codec->chregs.data.ainten = 0x00; in snd_ali_create()
2154 codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL); in snd_ali_create()
2155 if (!codec->pci_m1533) { in snd_ali_create()
2157 snd_ali_free(codec); in snd_ali_create()
2161 codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL); in snd_ali_create()
2162 if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) { in snd_ali_create()
2164 snd_ali_free(codec); in snd_ali_create()
2169 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops); in snd_ali_create()
2171 snd_ali_free(codec); in snd_ali_create()
2177 codec->synth.voices[i].number = i; in snd_ali_create()
2179 err = snd_ali_chip_init(codec); in snd_ali_create()
2186 codec->image = kmalloc(sizeof(*codec->image), GFP_KERNEL); in snd_ali_create()
2187 if (!codec->image) in snd_ali_create()
2191 snd_ali_enable_address_interrupt(codec); in snd_ali_create()
2192 codec->hw_initialized = 1; in snd_ali_create()
2194 *r_ali = codec; in snd_ali_create()
2203 struct snd_ali *codec; in snd_ali_probe() local
2212 err = snd_ali_create(card, pci, pcm_channels, spdif, &codec); in snd_ali_probe()
2215 card->private_data = codec; in snd_ali_probe()
2218 err = snd_ali_mixer(codec); in snd_ali_probe()
2223 err = snd_ali_build_pcms(codec); in snd_ali_probe()
2227 snd_ali_proc_init(codec); in snd_ali_probe()
2233 card->shortname, codec->port, codec->irq); in snd_ali_probe()