Lines Matching +full:codec +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * --
11 * --
21 #include <linux/dma-mapping.h>
94 #define ALI_SCTRL_LINE_IN2 (1 << 9)
95 #define ALI_SCTRL_GPIO_IN2 (1 << 13)
96 #define ALI_SCTRL_LINE_OUT_EN (1 << 20)
97 #define ALI_SCTRL_GPIO_OUT_EN (1 << 23)
98 #define ALI_SCTRL_CODEC1_READY (1 << 24)
99 #define ALI_SCTRL_CODEC2_READY (1 << 25)
141 #define ALI_REG(codec, x) ((codec)->port + x) argument
172 unsigned int use :1,
173 pcm :1,
174 midi :1,
175 mode :1,
176 synth :1,
177 running :1;
180 struct snd_ali *codec; member
185 int count; /* runtime->period_size */
187 /* --- */
218 unsigned int hw_initialized :1;
219 unsigned int spdif_support :1;
266 static inline unsigned int snd_ali_5451_peek(struct snd_ali *codec, in snd_ali_5451_peek() argument
269 return (unsigned int)inl(ALI_REG(codec, port)); in snd_ali_5451_peek()
272 static inline void snd_ali_5451_poke(struct snd_ali *codec, in snd_ali_5451_poke() argument
276 outl((unsigned int)val, ALI_REG(codec, port)); in snd_ali_5451_poke()
279 static int snd_ali_codec_ready(struct snd_ali *codec, in snd_ali_codec_ready() argument
288 res = snd_ali_5451_peek(codec,port); in snd_ali_codec_ready()
293 schedule_timeout_uninterruptible(1); in snd_ali_codec_ready()
296 snd_ali_5451_poke(codec, port, res & ~0x8000); in snd_ali_codec_ready()
297 dev_dbg(codec->card->dev, "ali_codec_ready: codec is not ready.\n "); in snd_ali_codec_ready()
298 return -EIO; in snd_ali_codec_ready()
301 static int snd_ali_stimer_ready(struct snd_ali *codec) in snd_ali_stimer_ready() argument
306 dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER); in snd_ali_stimer_ready()
310 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); in snd_ali_stimer_ready()
315 schedule_timeout_uninterruptible(1); in snd_ali_stimer_ready()
318 dev_err(codec->card->dev, "ali_stimer_read: stimer is not ready.\n"); in snd_ali_stimer_ready()
319 return -EIO; in snd_ali_stimer_ready()
322 static void snd_ali_codec_poke(struct snd_ali *codec,int secondary, in snd_ali_codec_poke() argument
330 dev_err(codec->card->dev, in snd_ali_codec_poke()
335 port = codec->chregs.regs.ac97write; in snd_ali_codec_poke()
337 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_poke()
339 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_poke()
346 if (codec->revision == ALI_5451_V02) in snd_ali_codec_poke()
349 snd_ali_5451_poke(codec, port, dwVal); in snd_ali_codec_poke()
354 static unsigned short snd_ali_codec_peek(struct snd_ali *codec, in snd_ali_codec_peek() argument
362 dev_err(codec->card->dev, in snd_ali_codec_peek()
367 port = codec->chregs.regs.ac97read; in snd_ali_codec_peek()
369 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_peek()
371 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_peek()
379 snd_ali_5451_poke(codec, port, dwVal); in snd_ali_codec_peek()
381 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_codec_peek()
383 if (snd_ali_codec_ready(codec, port) < 0) in snd_ali_codec_peek()
386 return (snd_ali_5451_peek(codec, port) & 0xffff0000) >> 16; in snd_ali_codec_peek()
393 struct snd_ali *codec = ac97->private_data; in snd_ali_codec_write() local
395 dev_dbg(codec->card->dev, "codec_write: reg=%xh data=%xh.\n", reg, val); in snd_ali_codec_write()
398 ALI_REG(codec, ALI_AC97_GPIO)); in snd_ali_codec_write()
401 snd_ali_codec_poke(codec, ac97->num, reg, val); in snd_ali_codec_write()
409 struct snd_ali *codec = ac97->private_data; in snd_ali_codec_read() local
411 dev_dbg(codec->card->dev, "codec_read reg=%xh.\n", reg); in snd_ali_codec_read()
412 return snd_ali_codec_peek(codec, ac97->num, reg); in snd_ali_codec_read()
419 static int snd_ali_reset_5451(struct snd_ali *codec) in snd_ali_reset_5451() argument
425 pci_dev = codec->pci_m1533; in snd_ali_reset_5451()
435 pci_dev = codec->pci; in snd_ali_reset_5451()
444 while(wCount--) { in snd_ali_reset_5451()
445 wReg = snd_ali_codec_peek(codec, 0, AC97_POWERDOWN); in snd_ali_reset_5451()
451 /* non-fatal if you have a non PM capable codec */ in snd_ali_reset_5451()
452 /* dev_warn(codec->card->dev, "ali5451: reset time out\n"); */ in snd_ali_reset_5451()
460 static void snd_ali_enable_special_channel(struct snd_ali *codec, in snd_ali_enable_special_channel() argument
465 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_special_channel()
466 dwVal |= 1 << (channel & 0x0000001f); in snd_ali_enable_special_channel()
467 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_special_channel()
470 static void snd_ali_disable_special_channel(struct snd_ali *codec, in snd_ali_disable_special_channel() argument
475 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_special_channel()
476 dwVal &= ~(1 << (channel & 0x0000001f)); in snd_ali_disable_special_channel()
477 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_special_channel()
480 static void snd_ali_enable_address_interrupt(struct snd_ali *codec) in snd_ali_enable_address_interrupt() argument
484 gc = inl(ALI_REG(codec, ALI_GC_CIR)); in snd_ali_enable_address_interrupt()
487 outl( gc, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_enable_address_interrupt()
490 static void snd_ali_disable_address_interrupt(struct snd_ali *codec) in snd_ali_disable_address_interrupt() argument
494 gc = inl(ALI_REG(codec, ALI_GC_CIR)); in snd_ali_disable_address_interrupt()
497 outl(gc, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_disable_address_interrupt()
500 static void snd_ali_disable_voice_irq(struct snd_ali *codec, in snd_ali_disable_voice_irq() argument
504 struct snd_ali_channel_control *pchregs = &(codec->chregs); in snd_ali_disable_voice_irq()
506 dev_dbg(codec->card->dev, "disable_voice_irq channel=%d\n", channel); in snd_ali_disable_voice_irq()
508 mask = 1 << (channel & 0x1f); in snd_ali_disable_voice_irq()
509 pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten)); in snd_ali_disable_voice_irq()
510 pchregs->data.ainten &= ~mask; in snd_ali_disable_voice_irq()
511 outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten)); in snd_ali_disable_voice_irq()
514 static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel) in snd_ali_alloc_pcm_channel() argument
518 if (codec->synth.chcnt >= ALI_CHANNELS){ in snd_ali_alloc_pcm_channel()
519 dev_err(codec->card->dev, in snd_ali_alloc_pcm_channel()
521 return -1; in snd_ali_alloc_pcm_channel()
524 if (!(codec->synth.chmap & (1 << idx))) { in snd_ali_alloc_pcm_channel()
525 codec->synth.chmap |= 1 << idx; in snd_ali_alloc_pcm_channel()
526 codec->synth.chcnt++; in snd_ali_alloc_pcm_channel()
527 dev_dbg(codec->card->dev, "alloc_pcm_channel no. %d.\n", idx); in snd_ali_alloc_pcm_channel()
530 return -1; in snd_ali_alloc_pcm_channel()
533 static int snd_ali_find_free_channel(struct snd_ali * codec, int rec) in snd_ali_find_free_channel() argument
536 int result = -1; in snd_ali_find_free_channel()
538 dev_dbg(codec->card->dev, in snd_ali_find_free_channel()
543 if (codec->spdif_support && in snd_ali_find_free_channel()
544 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_find_free_channel()
550 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
554 dev_err(codec->card->dev, in snd_ali_find_free_channel()
556 return -1; in snd_ali_find_free_channel()
561 if (codec->spdif_support && in snd_ali_find_free_channel()
562 (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()
574 result = snd_ali_alloc_pcm_channel(codec, idx); in snd_ali_find_free_channel()
578 dev_err(codec->card->dev, "ali_find_free_channel: no free channels.\n"); in snd_ali_find_free_channel()
579 return -1; in snd_ali_find_free_channel()
582 static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel) in snd_ali_free_channel_pcm() argument
586 dev_dbg(codec->card->dev, "free_channel_pcm channel=%d\n", channel); in snd_ali_free_channel_pcm()
591 if (!(codec->synth.chmap & (1 << idx))) { in snd_ali_free_channel_pcm()
592 dev_err(codec->card->dev, in snd_ali_free_channel_pcm()
597 codec->synth.chmap &= ~(1 << idx); in snd_ali_free_channel_pcm()
598 codec->synth.chcnt--; in snd_ali_free_channel_pcm()
602 static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel) in snd_ali_stop_voice() argument
604 unsigned int mask = 1 << (channel & 0x1f); in snd_ali_stop_voice()
606 dev_dbg(codec->card->dev, "stop_voice: channel=%d\n", channel); in snd_ali_stop_voice()
607 outl(mask, ALI_REG(codec, codec->chregs.regs.stop)); in snd_ali_stop_voice()
614 static void snd_ali_delay(struct snd_ali *codec,int interval) in snd_ali_delay() argument
618 begintimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
619 currenttimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
622 if (snd_ali_stimer_ready(codec) < 0) in snd_ali_delay()
624 currenttimer = inl(ALI_REG(codec, ALI_STIMER)); in snd_ali_delay()
629 static void snd_ali_detect_spdif_rate(struct snd_ali *codec) in snd_ali_detect_spdif_rate() argument
635 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
637 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
641 snd_ali_delay(codec, 6); in snd_ali_detect_spdif_rate()
642 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); in snd_ali_detect_spdif_rate()
647 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n"); in snd_ali_detect_spdif_rate()
652 snd_ali_delay(codec, 6); in snd_ali_detect_spdif_rate()
653 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 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
670 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
672 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)) & 0xf0; in snd_ali_detect_spdif_rate()
673 outb(bval | 0x02, ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_detect_spdif_rate()
675 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
678 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); in snd_ali_detect_spdif_rate()
680 bval = inb(ALI_REG(codec,ALI_SPDIF_CS + 3)) & 0xf0; in snd_ali_detect_spdif_rate()
681 outb(bval | 0x03, ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_detect_spdif_rate()
685 static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali *codec) in snd_ali_get_spdif_in_rate() argument
690 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_get_spdif_in_rate()
693 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_get_spdif_in_rate()
695 snd_ali_detect_spdif_rate(codec); in snd_ali_get_spdif_in_rate()
697 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)); in snd_ali_get_spdif_in_rate()
702 case 1: dwRate = 48000; break; in snd_ali_get_spdif_in_rate()
710 static void snd_ali_enable_spdif_in(struct snd_ali *codec) in snd_ali_enable_spdif_in() argument
714 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_in()
716 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_in()
718 dwVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_in()
720 outb(dwVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_in()
722 snd_ali_enable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); in snd_ali_enable_spdif_in()
725 static void snd_ali_disable_spdif_in(struct snd_ali *codec) in snd_ali_disable_spdif_in() argument
729 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_in()
731 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_in()
733 snd_ali_disable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); in snd_ali_disable_spdif_in()
737 static void snd_ali_set_spdif_out_rate(struct snd_ali *codec, unsigned int rate) in snd_ali_set_spdif_out_rate() argument
748 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
749 bVal &= (unsigned char)(~(1<<6)); in snd_ali_set_spdif_out_rate()
752 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
753 outb(dwRate | 0x20, ALI_REG(codec, ALI_SPDIF_CS + 2)); in snd_ali_set_spdif_out_rate()
756 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_set_spdif_out_rate()
757 outw(rate | 0x10, ALI_REG(codec, ALI_SPDIF_CS + 2)); in snd_ali_set_spdif_out_rate()
760 static void snd_ali_enable_spdif_out(struct snd_ali *codec) in snd_ali_enable_spdif_out() argument
766 pci_dev = codec->pci_m1533; in snd_ali_enable_spdif_out()
781 bVal = inb(ALI_REG(codec, ALI_SCTRL)); in snd_ali_enable_spdif_out()
782 outb(bVal | ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); in snd_ali_enable_spdif_out()
784 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_out()
785 outb(bVal & ALI_SPDIF_OUT_CH_STATUS, ALI_REG(codec, ALI_SPDIF_CTRL)); in snd_ali_enable_spdif_out()
787 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_out()
789 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_out()
790 snd_ali_disable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_enable_spdif_out()
793 static void snd_ali_enable_spdif_chnout(struct snd_ali *codec) in snd_ali_enable_spdif_chnout() argument
797 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_chnout()
799 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_enable_spdif_chnout()
801 wVal = inw(ALI_REG(codec, ALI_SPDIF_CS)); in snd_ali_enable_spdif_chnout()
806 outw(wVal, ALI_REG(codec, ALI_SPDIF_CS)); in snd_ali_enable_spdif_chnout()
808 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_enable_spdif_chnout()
811 static void snd_ali_disable_spdif_chnout(struct snd_ali *codec) in snd_ali_disable_spdif_chnout() argument
815 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_chnout()
817 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_disable_spdif_chnout()
819 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); in snd_ali_disable_spdif_chnout()
822 static void snd_ali_disable_spdif_out(struct snd_ali *codec) in snd_ali_disable_spdif_out() argument
826 bVal = inb(ALI_REG(codec, ALI_SCTRL)); in snd_ali_disable_spdif_out()
827 outb(bVal & ~ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); in snd_ali_disable_spdif_out()
829 snd_ali_disable_spdif_chnout(codec); in snd_ali_disable_spdif_out()
832 static void snd_ali_update_ptr(struct snd_ali *codec, int channel) in snd_ali_update_ptr() argument
838 pchregs = &(codec->chregs); in snd_ali_update_ptr()
841 old = pchregs->data.aint; in snd_ali_update_ptr()
842 mask = 1U << (channel & 0x1f); in snd_ali_update_ptr()
847 pvoice = &codec->synth.voices[channel]; in snd_ali_update_ptr()
850 spin_lock(&codec->reg_lock); in snd_ali_update_ptr()
852 if (pvoice->pcm && pvoice->substream) { in snd_ali_update_ptr()
854 if (pvoice->running) { in snd_ali_update_ptr()
855 dev_dbg(codec->card->dev, in snd_ali_update_ptr()
857 inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)), in snd_ali_update_ptr()
858 (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask); in snd_ali_update_ptr()
859 spin_unlock(&codec->reg_lock); in snd_ali_update_ptr()
860 snd_pcm_period_elapsed(pvoice->substream); in snd_ali_update_ptr()
861 spin_lock(&codec->reg_lock); in snd_ali_update_ptr()
863 snd_ali_stop_voice(codec, channel); in snd_ali_update_ptr()
864 snd_ali_disable_voice_irq(codec, channel); in snd_ali_update_ptr()
866 } else if (codec->synth.voices[channel].synth) { in snd_ali_update_ptr()
868 } else if (codec->synth.voices[channel].midi) { in snd_ali_update_ptr()
872 snd_ali_stop_voice(codec, channel); in snd_ali_update_ptr()
873 snd_ali_disable_voice_irq(codec, channel); in snd_ali_update_ptr()
875 spin_unlock(&codec->reg_lock); in snd_ali_update_ptr()
876 outl(mask,ALI_REG(codec,pchregs->regs.aint)); in snd_ali_update_ptr()
877 pchregs->data.aint = old & (~mask); in snd_ali_update_ptr()
882 struct snd_ali *codec = dev_id; in snd_ali_card_interrupt() local
887 if (codec == NULL || !codec->hw_initialized) in snd_ali_card_interrupt()
890 audio_int = inl(ALI_REG(codec, ALI_MISCINT)); in snd_ali_card_interrupt()
894 pchregs = &(codec->chregs); in snd_ali_card_interrupt()
897 pchregs->data.aint = inl(ALI_REG(codec, pchregs->regs.aint)); in snd_ali_card_interrupt()
899 snd_ali_update_ptr(codec, channel); in snd_ali_card_interrupt()
902 ALI_REG(codec, ALI_MISCINT)); in snd_ali_card_interrupt()
908 static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec, in snd_ali_alloc_voice() argument
914 dev_dbg(codec->card->dev, "alloc_voice: type=%d rec=%d\n", type, rec); in snd_ali_alloc_voice()
916 spin_lock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
918 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : in snd_ali_alloc_voice()
919 snd_ali_find_free_channel(codec,rec); in snd_ali_alloc_voice()
921 dev_err(codec->card->dev, "ali_alloc_voice: err.\n"); in snd_ali_alloc_voice()
922 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
925 pvoice = &(codec->synth.voices[idx]); in snd_ali_alloc_voice()
926 pvoice->codec = codec; in snd_ali_alloc_voice()
927 pvoice->use = 1; in snd_ali_alloc_voice()
928 pvoice->pcm = 1; in snd_ali_alloc_voice()
929 pvoice->mode = rec; in snd_ali_alloc_voice()
930 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
933 spin_unlock_irq(&codec->voice_alloc); in snd_ali_alloc_voice()
938 static void snd_ali_free_voice(struct snd_ali * codec, in snd_ali_free_voice() argument
944 dev_dbg(codec->card->dev, "free_voice: channel=%d\n", pvoice->number); in snd_ali_free_voice()
945 if (!pvoice->use) in snd_ali_free_voice()
947 snd_ali_clear_voices(codec, pvoice->number, pvoice->number); in snd_ali_free_voice()
948 spin_lock_irq(&codec->voice_alloc); in snd_ali_free_voice()
949 private_free = pvoice->private_free; in snd_ali_free_voice()
950 private_data = pvoice->private_data; in snd_ali_free_voice()
951 pvoice->private_free = NULL; in snd_ali_free_voice()
952 pvoice->private_data = NULL; in snd_ali_free_voice()
953 if (pvoice->pcm) in snd_ali_free_voice()
954 snd_ali_free_channel_pcm(codec, pvoice->number); in snd_ali_free_voice()
955 pvoice->use = pvoice->pcm = pvoice->synth = 0; in snd_ali_free_voice()
956 pvoice->substream = NULL; in snd_ali_free_voice()
957 spin_unlock_irq(&codec->voice_alloc); in snd_ali_free_voice()
963 static void snd_ali_clear_voices(struct snd_ali *codec, in snd_ali_clear_voices() argument
970 snd_ali_stop_voice(codec, i); in snd_ali_clear_voices()
971 snd_ali_disable_voice_irq(codec, i); in snd_ali_clear_voices()
975 static void snd_ali_write_voice_regs(struct snd_ali *codec, in snd_ali_write_voice_regs() argument
990 outb((unsigned char)(Channel & 0x001f), ALI_REG(codec, ALI_GC_CIR)); in snd_ali_write_voice_regs()
993 ctlcmds[1] = LBA; in snd_ali_write_voice_regs()
1001 outb(Channel, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_write_voice_regs()
1003 outl(ctlcmds[0], ALI_REG(codec, ALI_CSO_ALPHA_FMS)); in snd_ali_write_voice_regs()
1004 outl(ctlcmds[1], ALI_REG(codec, ALI_LBA)); in snd_ali_write_voice_regs()
1005 outl(ctlcmds[2], ALI_REG(codec, ALI_ESO_DELTA)); in snd_ali_write_voice_regs()
1006 outl(ctlcmds[3], ALI_REG(codec, ALI_GVSEL_PAN_VOC_CTRL_EC)); in snd_ali_write_voice_regs()
1008 outl(0x30000000, ALI_REG(codec, ALI_EBUF1)); /* Still Mode */ in snd_ali_write_voice_regs()
1009 outl(0x30000000, ALI_REG(codec, ALI_EBUF2)); /* Still Mode */ in snd_ali_write_voice_regs()
1047 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ali_control_mode()
1050 CTRL default: 8-bit (unsigned) mono, loop mode enabled in snd_ali_control_mode()
1053 if (snd_pcm_format_width(runtime->format) == 16) in snd_ali_control_mode()
1054 CTRL |= 0x00000008; /* 16-bit data */ in snd_ali_control_mode()
1055 if (!snd_pcm_format_unsigned(runtime->format)) in snd_ali_control_mode()
1057 if (runtime->channels > 1) in snd_ali_control_mode()
1070 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_trigger() local
1080 do_start = 1; in snd_ali_trigger()
1087 return -EINVAL; in snd_ali_trigger()
1092 if ((struct snd_ali *) snd_pcm_substream_chip(s) == codec) { in snd_ali_trigger()
1093 pvoice = s->runtime->private_data; in snd_ali_trigger()
1094 evoice = pvoice->extra; in snd_ali_trigger()
1095 what |= 1 << (pvoice->number & 0x1f); in snd_ali_trigger()
1097 whati |= 1 << (pvoice->number & 0x1f); in snd_ali_trigger()
1099 whati |= 1 << (evoice->number & 0x1f); in snd_ali_trigger()
1100 what |= 1 << (evoice->number & 0x1f); in snd_ali_trigger()
1103 pvoice->running = 1; in snd_ali_trigger()
1105 evoice->running = 1; in snd_ali_trigger()
1107 pvoice->running = 0; in snd_ali_trigger()
1109 evoice->running = 0; in snd_ali_trigger()
1114 spin_lock(&codec->reg_lock); in snd_ali_trigger()
1116 outl(what, ALI_REG(codec, ALI_STOP)); in snd_ali_trigger()
1117 val = inl(ALI_REG(codec, ALI_AINTEN)); in snd_ali_trigger()
1122 outl(val, ALI_REG(codec, ALI_AINTEN)); in snd_ali_trigger()
1124 outl(what, ALI_REG(codec, ALI_START)); in snd_ali_trigger()
1125 dev_dbg(codec->card->dev, "trigger: what=%xh whati=%xh\n", what, whati); in snd_ali_trigger()
1126 spin_unlock(&codec->reg_lock); in snd_ali_trigger()
1134 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_hw_params() local
1135 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ali_playback_hw_params()
1136 struct snd_ali_voice *pvoice = runtime->private_data; in snd_ali_playback_hw_params()
1137 struct snd_ali_voice *evoice = pvoice->extra; in snd_ali_playback_hw_params()
1144 evoice = snd_ali_alloc_voice(codec, in snd_ali_playback_hw_params()
1146 0, -1); in snd_ali_playback_hw_params()
1148 return -ENOMEM; in snd_ali_playback_hw_params()
1149 pvoice->extra = evoice; in snd_ali_playback_hw_params()
1150 evoice->substream = substream; in snd_ali_playback_hw_params()
1154 snd_ali_free_voice(codec, evoice); in snd_ali_playback_hw_params()
1155 pvoice->extra = evoice = NULL; in snd_ali_playback_hw_params()
1164 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_hw_free() local
1165 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ali_playback_hw_free()
1166 struct snd_ali_voice *pvoice = runtime->private_data; in snd_ali_playback_hw_free()
1167 struct snd_ali_voice *evoice = pvoice ? pvoice->extra : NULL; in snd_ali_playback_hw_free()
1170 snd_ali_free_voice(codec, evoice); in snd_ali_playback_hw_free()
1171 pvoice->extra = NULL; in snd_ali_playback_hw_free()
1178 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_prepare() local
1179 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ali_playback_prepare()
1180 struct snd_ali_voice *pvoice = runtime->private_data; in snd_ali_playback_prepare()
1181 struct snd_ali_voice *evoice = pvoice->extra; in snd_ali_playback_prepare()
1192 dev_dbg(codec->card->dev, "playback_prepare ...\n"); in snd_ali_playback_prepare()
1194 spin_lock_irq(&codec->reg_lock); in snd_ali_playback_prepare()
1197 Delta = snd_ali_convert_rate(runtime->rate, 0); in snd_ali_playback_prepare()
1199 if (pvoice->number == ALI_SPDIF_IN_CHANNEL || in snd_ali_playback_prepare()
1200 pvoice->number == ALI_PCM_IN_CHANNEL) in snd_ali_playback_prepare()
1201 snd_ali_disable_special_channel(codec, pvoice->number); in snd_ali_playback_prepare()
1202 else if (codec->spdif_support && in snd_ali_playback_prepare()
1203 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & in snd_ali_playback_prepare()
1205 && pvoice->number == ALI_SPDIF_OUT_CHANNEL) { in snd_ali_playback_prepare()
1206 snd_ali_set_spdif_out_rate(codec, runtime->rate); in snd_ali_playback_prepare()
1211 LBA = runtime->dma_addr; in snd_ali_playback_prepare()
1214 pvoice->count = runtime->period_size; in snd_ali_playback_prepare()
1217 pvoice->eso = runtime->buffer_size; in snd_ali_playback_prepare()
1219 dev_dbg(codec->card->dev, "playback_prepare: eso=%xh count=%xh\n", in snd_ali_playback_prepare()
1220 pvoice->eso, pvoice->count); in snd_ali_playback_prepare()
1223 ESO = pvoice->eso -1; in snd_ali_playback_prepare()
1227 GVSEL = 1; in snd_ali_playback_prepare()
1231 dev_dbg(codec->card->dev, "playback_prepare:\n"); in snd_ali_playback_prepare()
1232 dev_dbg(codec->card->dev, in snd_ali_playback_prepare()
1234 pvoice->number,runtime->rate,Delta,GVSEL,PAN,CTRL); in snd_ali_playback_prepare()
1235 snd_ali_write_voice_regs(codec, in snd_ali_playback_prepare()
1236 pvoice->number, in snd_ali_playback_prepare()
1248 evoice->count = pvoice->count; in snd_ali_playback_prepare()
1249 evoice->eso = pvoice->count << 1; in snd_ali_playback_prepare()
1250 ESO = evoice->eso - 1; in snd_ali_playback_prepare()
1251 snd_ali_write_voice_regs(codec, in snd_ali_playback_prepare()
1252 evoice->number, in snd_ali_playback_prepare()
1264 spin_unlock_irq(&codec->reg_lock); in snd_ali_playback_prepare()
1271 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_prepare() local
1272 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ali_prepare()
1273 struct snd_ali_voice *pvoice = runtime->private_data; in snd_ali_prepare()
1284 spin_lock_irq(&codec->reg_lock); in snd_ali_prepare()
1286 dev_dbg(codec->card->dev, "ali_prepare...\n"); in snd_ali_prepare()
1288 snd_ali_enable_special_channel(codec,pvoice->number); in snd_ali_prepare()
1290 Delta = (pvoice->number == ALI_MODEM_IN_CHANNEL || in snd_ali_prepare()
1291 pvoice->number == ALI_MODEM_OUT_CHANNEL) ? in snd_ali_prepare()
1292 0x1000 : snd_ali_convert_rate(runtime->rate, pvoice->mode); in snd_ali_prepare()
1295 if (pvoice->number == ALI_SPDIF_IN_CHANNEL) { in snd_ali_prepare()
1299 spin_unlock_irq(&codec->reg_lock); in snd_ali_prepare()
1300 if (codec->revision != ALI_5451_V02) in snd_ali_prepare()
1301 return -1; in snd_ali_prepare()
1303 rate = snd_ali_get_spdif_in_rate(codec); in snd_ali_prepare()
1305 dev_warn(codec->card->dev, in snd_ali_prepare()
1309 spin_lock_irq(&codec->reg_lock); in snd_ali_prepare()
1310 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL)); in snd_ali_prepare()
1312 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL)); in snd_ali_prepare()
1313 dev_warn(codec->card->dev, in snd_ali_prepare()
1318 Delta = ((rate << 12) / runtime->rate) & 0x00ffff; in snd_ali_prepare()
1322 pvoice->eso = runtime->buffer_size; in snd_ali_prepare()
1325 pvoice->count = runtime->period_size; in snd_ali_prepare()
1328 LBA = runtime->dma_addr; in snd_ali_prepare()
1331 ESO = pvoice->eso - 1; in snd_ali_prepare()
1338 snd_ali_write_voice_regs( codec, in snd_ali_prepare()
1339 pvoice->number, in snd_ali_prepare()
1351 spin_unlock_irq(&codec->reg_lock); in snd_ali_prepare()
1360 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_playback_pointer() local
1361 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ali_playback_pointer()
1362 struct snd_ali_voice *pvoice = runtime->private_data; in snd_ali_playback_pointer()
1365 spin_lock(&codec->reg_lock); in snd_ali_playback_pointer()
1366 if (!pvoice->running) { in snd_ali_playback_pointer()
1367 spin_unlock(&codec->reg_lock); in snd_ali_playback_pointer()
1370 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_playback_pointer()
1371 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); in snd_ali_playback_pointer()
1372 spin_unlock(&codec->reg_lock); in snd_ali_playback_pointer()
1373 dev_dbg(codec->card->dev, "playback pointer returned cso=%xh.\n", cso); in snd_ali_playback_pointer()
1375 cso %= runtime->buffer_size; in snd_ali_playback_pointer()
1382 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_pointer() local
1383 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ali_pointer()
1384 struct snd_ali_voice *pvoice = runtime->private_data; in snd_ali_pointer()
1387 spin_lock(&codec->reg_lock); in snd_ali_pointer()
1388 if (!pvoice->running) { in snd_ali_pointer()
1389 spin_unlock(&codec->reg_lock); in snd_ali_pointer()
1392 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); in snd_ali_pointer()
1393 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); in snd_ali_pointer()
1394 spin_unlock(&codec->reg_lock); in snd_ali_pointer()
1396 cso %= runtime->buffer_size; in snd_ali_pointer()
1412 .channels_min = 1,
1417 .periods_min = 1,
1438 .channels_min = 1,
1443 .periods_min = 1,
1450 struct snd_ali_voice *pvoice = runtime->private_data; in snd_ali_pcm_free_substream()
1453 snd_ali_free_voice(pvoice->codec, pvoice); in snd_ali_pcm_free_substream()
1459 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_open() local
1460 struct snd_pcm_runtime *runtime = substream->runtime; in snd_ali_open()
1463 pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, rec, in snd_ali_open()
1466 return -EAGAIN; in snd_ali_open()
1468 pvoice->substream = substream; in snd_ali_open()
1469 runtime->private_data = pvoice; in snd_ali_open()
1470 runtime->private_free = snd_ali_pcm_free_substream; in snd_ali_open()
1472 runtime->hw = *phw; in snd_ali_open()
1481 return snd_ali_open(substream, 0, -1, &snd_ali_playback); in snd_ali_playback_open()
1486 return snd_ali_open(substream, 1, -1, &snd_ali_capture); in snd_ali_capture_open()
1496 struct snd_ali *codec = snd_pcm_substream_chip(substream); in snd_ali_close() local
1497 struct snd_ali_voice *pvoice = substream->runtime->private_data; in snd_ali_close()
1499 snd_ali_disable_special_channel(codec,pvoice->number); in snd_ali_close()
1530 unsigned int modem_num = chip->num_of_codecs - 1; in snd_ali_modem_hw_params()
1531 snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_RATE, in snd_ali_modem_hw_params()
1533 snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_LEVEL, 0); in snd_ali_modem_hw_params()
1549 .channels_min = 1,
1550 .channels_max = 1,
1554 .periods_min = 1,
1572 return snd_pcm_hw_constraint_list(substream->runtime, 0, in snd_ali_modem_open()
1583 return snd_ali_modem_open(substream, 1, ALI_MODEM_IN_CHANNEL); in snd_ali_modem_capture_open()
1617 struct snd_ali *codec = pcm->private_data; in snd_ali_pcm_free() local
1618 codec->pcm[pcm->device] = NULL; in snd_ali_pcm_free()
1622 static int snd_ali_pcm(struct snd_ali *codec, int device, in snd_ali_pcm() argument
1628 err = snd_pcm_new(codec->card, desc->name, device, in snd_ali_pcm()
1629 desc->playback_num, desc->capture_num, &pcm); in snd_ali_pcm()
1631 dev_err(codec->card->dev, in snd_ali_pcm()
1635 pcm->private_data = codec; in snd_ali_pcm()
1636 pcm->private_free = snd_ali_pcm_free; in snd_ali_pcm()
1637 if (desc->playback_ops) in snd_ali_pcm()
1639 desc->playback_ops); in snd_ali_pcm()
1640 if (desc->capture_ops) in snd_ali_pcm()
1642 desc->capture_ops); in snd_ali_pcm()
1645 &codec->pci->dev, 64*1024, 128*1024); in snd_ali_pcm()
1647 pcm->info_flags = 0; in snd_ali_pcm()
1648 pcm->dev_class = desc->class; in snd_ali_pcm()
1649 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; in snd_ali_pcm()
1650 strcpy(pcm->name, desc->name); in snd_ali_pcm()
1651 codec->pcm[0] = pcm; in snd_ali_pcm()
1658 .capture_num = 1,
1663 .playback_num = 1,
1664 .capture_num = 1,
1671 static int snd_ali_build_pcms(struct snd_ali *codec) in snd_ali_build_pcms() argument
1674 for (i = 0; i < codec->num_of_codecs && i < ARRAY_SIZE(ali_pcms); i++) { in snd_ali_build_pcms()
1675 err = snd_ali_pcm(codec, i, &ali_pcms[i]); in snd_ali_build_pcms()
1693 struct snd_ali *codec = kcontrol->private_data; in snd_ali5451_spdif_get() local
1696 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0; in snd_ali5451_spdif_get()
1698 spin_lock_irq(&codec->reg_lock); in snd_ali5451_spdif_get()
1699 switch (kcontrol->private_value) { in snd_ali5451_spdif_get()
1701 spdif_enable = (codec->spdif_mask & 0x02) ? 1 : 0; in snd_ali5451_spdif_get()
1703 case 1: in snd_ali5451_spdif_get()
1704 spdif_enable = ((codec->spdif_mask & 0x02) && in snd_ali5451_spdif_get()
1705 (codec->spdif_mask & 0x04)) ? 1 : 0; in snd_ali5451_spdif_get()
1708 spdif_enable = (codec->spdif_mask & 0x01) ? 1 : 0; in snd_ali5451_spdif_get()
1713 ucontrol->value.integer.value[0] = spdif_enable; in snd_ali5451_spdif_get()
1714 spin_unlock_irq(&codec->reg_lock); in snd_ali5451_spdif_get()
1721 struct snd_ali *codec = kcontrol->private_data; in snd_ali5451_spdif_put() local
1724 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0; in snd_ali5451_spdif_put()
1726 spin_lock_irq(&codec->reg_lock); in snd_ali5451_spdif_put()
1727 switch (kcontrol->private_value) { in snd_ali5451_spdif_put()
1729 change = (codec->spdif_mask & 0x02) ? 1 : 0; in snd_ali5451_spdif_put()
1733 codec->spdif_mask |= 0x02; in snd_ali5451_spdif_put()
1734 snd_ali_enable_spdif_out(codec); in snd_ali5451_spdif_put()
1736 codec->spdif_mask &= ~(0x02); in snd_ali5451_spdif_put()
1737 codec->spdif_mask &= ~(0x04); in snd_ali5451_spdif_put()
1738 snd_ali_disable_spdif_out(codec); in snd_ali5451_spdif_put()
1742 case 1: in snd_ali5451_spdif_put()
1743 change = (codec->spdif_mask & 0x04) ? 1 : 0; in snd_ali5451_spdif_put()
1745 if (change && (codec->spdif_mask & 0x02)) { in snd_ali5451_spdif_put()
1747 codec->spdif_mask |= 0x04; in snd_ali5451_spdif_put()
1748 snd_ali_enable_spdif_chnout(codec); in snd_ali5451_spdif_put()
1750 codec->spdif_mask &= ~(0x04); in snd_ali5451_spdif_put()
1751 snd_ali_disable_spdif_chnout(codec); in snd_ali5451_spdif_put()
1756 change = (codec->spdif_mask & 0x01) ? 1 : 0; in snd_ali5451_spdif_put()
1760 codec->spdif_mask |= 0x01; in snd_ali5451_spdif_put()
1761 snd_ali_enable_spdif_in(codec); in snd_ali5451_spdif_put()
1763 codec->spdif_mask &= ~(0x01); in snd_ali5451_spdif_put()
1764 snd_ali_disable_spdif_in(codec); in snd_ali5451_spdif_put()
1771 spin_unlock_irq(&codec->reg_lock); in snd_ali5451_spdif_put()
1781 ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("Channel Output ",NONE,SWITCH), 0, 1),
1786 static int snd_ali_mixer(struct snd_ali *codec) in snd_ali_mixer() argument
1796 err = snd_ac97_bus(codec->card, 0, &ops, codec, &codec->ac97_bus); in snd_ali_mixer()
1801 ac97.private_data = codec; in snd_ali_mixer()
1803 for (i = 0; i < codec->num_of_codecs; i++) { in snd_ali_mixer()
1805 err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i]); in snd_ali_mixer()
1807 dev_err(codec->card->dev, in snd_ali_mixer()
1811 codec->num_of_codecs = 1; in snd_ali_mixer()
1816 if (codec->spdif_support) { in snd_ali_mixer()
1818 err = snd_ctl_add(codec->card, in snd_ali_mixer()
1819 snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec)); in snd_ali_mixer()
1831 struct snd_ali *chip = card->private_data; in ali_suspend()
1835 im = chip->image; in ali_suspend()
1840 for (i = 0; i < chip->num_of_codecs; i++) in ali_suspend()
1841 snd_ac97_suspend(chip->ac97[i]); in ali_suspend()
1843 spin_lock_irq(&chip->reg_lock); in ali_suspend()
1845 im->regs[ALI_MISCINT >> 2] = inl(ALI_REG(chip, ALI_MISCINT)); in ali_suspend()
1846 /* im->regs[ALI_START >> 2] = inl(ALI_REG(chip, ALI_START)); */ in ali_suspend()
1847 im->regs[ALI_STOP >> 2] = inl(ALI_REG(chip, ALI_STOP)); in ali_suspend()
1855 im->regs[i] = inl(ALI_REG(chip, i*4)); in ali_suspend()
1861 im->channel_regs[i][j] = inl(ALI_REG(chip, j*4 + 0xe0)); in ali_suspend()
1867 spin_unlock_irq(&chip->reg_lock); in ali_suspend()
1874 struct snd_ali *chip = card->private_data; in ali_resume()
1878 im = chip->image; in ali_resume()
1882 spin_lock_irq(&chip->reg_lock); in ali_resume()
1887 outl(im->channel_regs[i][j], ALI_REG(chip, j*4 + 0xe0)); in ali_resume()
1894 outl(im->regs[i], ALI_REG(chip, i*4)); in ali_resume()
1898 outl(im->regs[ALI_START >> 2], ALI_REG(chip, ALI_START)); in ali_resume()
1900 outl(im->regs[ALI_MISCINT >> 2], ALI_REG(chip, ALI_MISCINT)); in ali_resume()
1902 spin_unlock_irq(&chip->reg_lock); in ali_resume()
1904 for (i = 0 ; i < chip->num_of_codecs; i++) in ali_resume()
1905 snd_ac97_resume(chip->ac97[i]); in ali_resume()
1919 struct snd_ali *codec = card->private_data; in snd_ali_free() local
1921 if (codec->hw_initialized) in snd_ali_free()
1922 snd_ali_disable_address_interrupt(codec); in snd_ali_free()
1923 pci_dev_put(codec->pci_m1533); in snd_ali_free()
1924 pci_dev_put(codec->pci_m7101); in snd_ali_free()
1927 static int snd_ali_chip_init(struct snd_ali *codec) in snd_ali_chip_init() argument
1933 dev_dbg(codec->card->dev, "chip initializing ...\n"); in snd_ali_chip_init()
1935 if (snd_ali_reset_5451(codec)) { in snd_ali_chip_init()
1936 dev_err(codec->card->dev, "ali_chip_init: reset 5451 error.\n"); in snd_ali_chip_init()
1937 return -1; in snd_ali_chip_init()
1940 if (codec->revision == ALI_5451_V02) { in snd_ali_chip_init()
1941 pci_dev = codec->pci_m1533; in snd_ali_chip_init()
1946 pci_dev = codec->pci_m7101; in snd_ali_chip_init()
1952 pci_read_config_dword(codec->pci, 0x44, &legacy); in snd_ali_chip_init()
1955 pci_write_config_dword(codec->pci, 0x44, legacy); in snd_ali_chip_init()
1957 outl(0x80000001, ALI_REG(codec, ALI_GLOBAL_CONTROL)); in snd_ali_chip_init()
1958 outl(0x00000000, ALI_REG(codec, ALI_AINTEN)); in snd_ali_chip_init()
1959 outl(0xffffffff, ALI_REG(codec, ALI_AINT)); in snd_ali_chip_init()
1960 outl(0x00000000, ALI_REG(codec, ALI_VOLUME)); in snd_ali_chip_init()
1961 outb(0x10, ALI_REG(codec, ALI_MPUR2)); in snd_ali_chip_init()
1963 codec->ac97_ext_id = snd_ali_codec_peek(codec, 0, AC97_EXTENDED_ID); in snd_ali_chip_init()
1964 codec->ac97_ext_status = snd_ali_codec_peek(codec, 0, in snd_ali_chip_init()
1966 if (codec->spdif_support) { in snd_ali_chip_init()
1967 snd_ali_enable_spdif_out(codec); in snd_ali_chip_init()
1968 codec->spdif_mask = 0x00000002; in snd_ali_chip_init()
1971 codec->num_of_codecs = 1; in snd_ali_chip_init()
1973 /* secondary codec - modem */ in snd_ali_chip_init()
1974 if (inl(ALI_REG(codec, ALI_SCTRL)) & ALI_SCTRL_CODEC2_READY) { in snd_ali_chip_init()
1975 codec->num_of_codecs++; in snd_ali_chip_init()
1976 outl(inl(ALI_REG(codec, ALI_SCTRL)) | in snd_ali_chip_init()
1979 ALI_REG(codec, ALI_SCTRL)); in snd_ali_chip_init()
1982 dev_dbg(codec->card->dev, "chip initialize succeed.\n"); in snd_ali_chip_init()
1991 struct snd_ali *codec = entry->private_data; in snd_ali_proc_read() local
1994 snd_iprintf(buf, "%02x: %08x\n", i, inl(ALI_REG(codec, i))); in snd_ali_proc_read()
1997 static void snd_ali_proc_init(struct snd_ali *codec) in snd_ali_proc_init() argument
1999 snd_card_ro_proc_new(codec->card, "ali5451", codec, snd_ali_proc_read); in snd_ali_proc_init()
2002 static int snd_ali_resources(struct snd_ali *codec) in snd_ali_resources() argument
2006 dev_dbg(codec->card->dev, "resources allocation ...\n"); in snd_ali_resources()
2007 err = pci_request_regions(codec->pci, "ALI 5451"); in snd_ali_resources()
2010 codec->port = pci_resource_start(codec->pci, 0); in snd_ali_resources()
2012 if (devm_request_irq(&codec->pci->dev, codec->pci->irq, in snd_ali_resources()
2014 IRQF_SHARED, KBUILD_MODNAME, codec)) { in snd_ali_resources()
2015 dev_err(codec->card->dev, "Unable to request irq.\n"); in snd_ali_resources()
2016 return -EBUSY; in snd_ali_resources()
2018 codec->irq = codec->pci->irq; in snd_ali_resources()
2019 codec->card->sync_irq = codec->irq; in snd_ali_resources()
2020 dev_dbg(codec->card->dev, "resources allocated.\n"); in snd_ali_resources()
2029 struct snd_ali *codec = card->private_data; in snd_ali_create() local
2033 dev_dbg(card->dev, "creating ...\n"); in snd_ali_create()
2040 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(31))) { in snd_ali_create()
2041 dev_err(card->dev, in snd_ali_create()
2043 return -ENXIO; in snd_ali_create()
2046 spin_lock_init(&codec->reg_lock); in snd_ali_create()
2047 spin_lock_init(&codec->voice_alloc); in snd_ali_create()
2049 codec->card = card; in snd_ali_create()
2050 codec->pci = pci; in snd_ali_create()
2051 codec->irq = -1; in snd_ali_create()
2052 codec->revision = pci->revision; in snd_ali_create()
2053 codec->spdif_support = spdif_support; in snd_ali_create()
2055 if (pcm_streams < 1) in snd_ali_create()
2056 pcm_streams = 1; in snd_ali_create()
2067 if (snd_ali_resources(codec)) in snd_ali_create()
2068 return -EBUSY; in snd_ali_create()
2069 card->private_free = snd_ali_free; in snd_ali_create()
2071 codec->synth.chmap = 0; in snd_ali_create()
2072 codec->synth.chcnt = 0; in snd_ali_create()
2073 codec->spdif_mask = 0; in snd_ali_create()
2074 codec->synth.synthcount = 0; in snd_ali_create()
2076 if (codec->revision == ALI_5451_V02) in snd_ali_create()
2077 codec->chregs.regs.ac97read = ALI_AC97_WRITE; in snd_ali_create()
2079 codec->chregs.regs.ac97read = ALI_AC97_READ; in snd_ali_create()
2080 codec->chregs.regs.ac97write = ALI_AC97_WRITE; in snd_ali_create()
2082 codec->chregs.regs.start = ALI_START; in snd_ali_create()
2083 codec->chregs.regs.stop = ALI_STOP; in snd_ali_create()
2084 codec->chregs.regs.aint = ALI_AINT; in snd_ali_create()
2085 codec->chregs.regs.ainten = ALI_AINTEN; in snd_ali_create()
2087 codec->chregs.data.start = 0x00; in snd_ali_create()
2088 codec->chregs.data.stop = 0x00; in snd_ali_create()
2089 codec->chregs.data.aint = 0x00; in snd_ali_create()
2090 codec->chregs.data.ainten = 0x00; in snd_ali_create()
2093 codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL); in snd_ali_create()
2094 if (!codec->pci_m1533) { in snd_ali_create()
2095 dev_err(card->dev, "cannot find ALi 1533 chip.\n"); in snd_ali_create()
2096 return -ENODEV; in snd_ali_create()
2099 codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL); in snd_ali_create()
2100 if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) { in snd_ali_create()
2101 dev_err(card->dev, "cannot find ALi 7101 chip.\n"); in snd_ali_create()
2102 return -ENODEV; in snd_ali_create()
2107 codec->synth.voices[i].number = i; in snd_ali_create()
2109 err = snd_ali_chip_init(codec); in snd_ali_create()
2111 dev_err(card->dev, "ali create: chip init error.\n"); in snd_ali_create()
2116 codec->image = devm_kmalloc(&pci->dev, sizeof(*codec->image), in snd_ali_create()
2118 if (!codec->image) in snd_ali_create()
2119 dev_warn(card->dev, "can't allocate apm buffer\n"); in snd_ali_create()
2122 snd_ali_enable_address_interrupt(codec); in snd_ali_create()
2123 codec->hw_initialized = 1; in snd_ali_create()
2131 struct snd_ali *codec; in __snd_ali_probe() local
2134 dev_dbg(&pci->dev, "probe ...\n"); in __snd_ali_probe()
2136 err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, in __snd_ali_probe()
2137 sizeof(*codec), &card); in __snd_ali_probe()
2140 codec = card->private_data; in __snd_ali_probe()
2146 dev_dbg(&pci->dev, "mixer building ...\n"); in __snd_ali_probe()
2147 err = snd_ali_mixer(codec); in __snd_ali_probe()
2151 dev_dbg(&pci->dev, "pcm building ...\n"); in __snd_ali_probe()
2152 err = snd_ali_build_pcms(codec); in __snd_ali_probe()
2156 snd_ali_proc_init(codec); in __snd_ali_probe()
2158 strcpy(card->driver, "ALI5451"); in __snd_ali_probe()
2159 strcpy(card->shortname, "ALI 5451"); in __snd_ali_probe()
2161 sprintf(card->longname, "%s at 0x%lx, irq %i", in __snd_ali_probe()
2162 card->shortname, codec->port, codec->irq); in __snd_ali_probe()
2164 dev_dbg(&pci->dev, "register card.\n"); in __snd_ali_probe()
2176 return snd_card_free_on_error(&pci->dev, __snd_ali_probe(pci, pci_id)); in snd_ali_probe()