Lines Matching +full:ec +full:- +full:codec

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * --
11 * --
21 #include <linux/dma-mapping.h>
141 #define ALI_REG(codec, x) ((codec)->port + x)
180 struct snd_ali *codec;
185 int count; /* runtime->period_size */
187 /* --- */
264 static inline unsigned int snd_ali_5451_peek(struct snd_ali *codec,
267 return (unsigned int)inl(ALI_REG(codec, port));
270 static inline void snd_ali_5451_poke(struct snd_ali *codec,
274 outl((unsigned int)val, ALI_REG(codec, port));
277 static int snd_ali_codec_ready(struct snd_ali *codec,
286 res = snd_ali_5451_peek(codec,port);
294 snd_ali_5451_poke(codec, port, res & ~0x8000);
295 dev_dbg(codec->card->dev, "ali_codec_ready: codec is not ready.\n");
296 return -EIO;
299 static int snd_ali_stimer_ready(struct snd_ali *codec)
304 dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER);
308 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER);
316 dev_err(codec->card->dev, "ali_stimer_read: stimer is not ready.\n");
317 return -EIO;
320 static void snd_ali_codec_poke(struct snd_ali *codec,int secondary,
328 dev_err(codec->card->dev,
333 port = codec->chregs.regs.ac97write;
335 if (snd_ali_codec_ready(codec, port) < 0)
337 if (snd_ali_stimer_ready(codec) < 0)
344 if (codec->revision == ALI_5451_V02)
347 snd_ali_5451_poke(codec, port, dwVal);
352 static unsigned short snd_ali_codec_peek(struct snd_ali *codec,
360 dev_err(codec->card->dev,
365 port = codec->chregs.regs.ac97read;
367 if (snd_ali_codec_ready(codec, port) < 0)
369 if (snd_ali_stimer_ready(codec) < 0)
377 snd_ali_5451_poke(codec, port, dwVal);
379 if (snd_ali_stimer_ready(codec) < 0)
381 if (snd_ali_codec_ready(codec, port) < 0)
384 return (snd_ali_5451_peek(codec, port) & 0xffff0000) >> 16;
391 struct snd_ali *codec = ac97->private_data;
393 dev_dbg(codec->card->dev, "codec_write: reg=%xh data=%xh.\n", reg, val);
396 ALI_REG(codec, ALI_AC97_GPIO));
399 snd_ali_codec_poke(codec, ac97->num, reg, val);
407 struct snd_ali *codec = ac97->private_data;
409 dev_dbg(codec->card->dev, "codec_read reg=%xh.\n", reg);
410 return snd_ali_codec_peek(codec, ac97->num, reg);
417 static int snd_ali_reset_5451(struct snd_ali *codec)
423 pci_dev = codec->pci_m1533;
433 pci_dev = codec->pci;
442 while(wCount--) {
443 wReg = snd_ali_codec_peek(codec, 0, AC97_POWERDOWN);
449 /* non-fatal if you have a non PM capable codec */
450 /* dev_warn(codec->card->dev, "ali5451: reset time out\n"); */
458 static void snd_ali_enable_special_channel(struct snd_ali *codec,
463 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL));
465 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
468 static void snd_ali_disable_special_channel(struct snd_ali *codec,
473 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL));
475 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
478 static void snd_ali_enable_address_interrupt(struct snd_ali *codec)
482 gc = inl(ALI_REG(codec, ALI_GC_CIR));
485 outl( gc, ALI_REG(codec, ALI_GC_CIR));
488 static void snd_ali_disable_address_interrupt(struct snd_ali *codec)
492 gc = inl(ALI_REG(codec, ALI_GC_CIR));
495 outl(gc, ALI_REG(codec, ALI_GC_CIR));
498 static void snd_ali_disable_voice_irq(struct snd_ali *codec,
502 struct snd_ali_channel_control *pchregs = &(codec->chregs);
504 dev_dbg(codec->card->dev, "disable_voice_irq channel=%d\n", channel);
507 pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten));
508 pchregs->data.ainten &= ~mask;
509 outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten));
512 static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel)
516 if (codec->synth.chcnt >= ALI_CHANNELS){
517 dev_err(codec->card->dev,
519 return -1;
522 if (!(codec->synth.chmap & (1 << idx))) {
523 codec->synth.chmap |= 1 << idx;
524 codec->synth.chcnt++;
525 dev_dbg(codec->card->dev, "alloc_pcm_channel no. %d.\n", idx);
528 return -1;
531 static int snd_ali_find_free_channel(struct snd_ali * codec, int rec)
534 int result = -1;
536 dev_dbg(codec->card->dev,
541 if (codec->spdif_support &&
542 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) &
548 result = snd_ali_alloc_pcm_channel(codec, idx);
552 dev_err(codec->card->dev,
554 return -1;
559 if (codec->spdif_support &&
560 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) &
563 result = snd_ali_alloc_pcm_channel(codec, idx);
567 dev_err(codec->card->dev,
572 result = snd_ali_alloc_pcm_channel(codec, idx);
576 dev_err(codec->card->dev, "ali_find_free_channel: no free channels.\n");
577 return -1;
580 static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel)
584 dev_dbg(codec->card->dev, "free_channel_pcm channel=%d\n", channel);
589 if (!(codec->synth.chmap & (1 << idx))) {
590 dev_err(codec->card->dev,
595 codec->synth.chmap &= ~(1 << idx);
596 codec->synth.chcnt--;
600 static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel)
604 dev_dbg(codec->card->dev, "stop_voice: channel=%d\n", channel);
605 outl(mask, ALI_REG(codec, codec->chregs.regs.stop));
612 static void snd_ali_delay(struct snd_ali *codec,int interval)
616 begintimer = inl(ALI_REG(codec, ALI_STIMER));
617 currenttimer = inl(ALI_REG(codec, ALI_STIMER));
620 if (snd_ali_stimer_ready(codec) < 0)
622 currenttimer = inl(ALI_REG(codec, ALI_STIMER));
627 static void snd_ali_detect_spdif_rate(struct snd_ali *codec)
633 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1));
635 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL + 1));
639 snd_ali_delay(codec, 6);
640 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1));
645 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n");
650 snd_ali_delay(codec, 6);
651 bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1));
660 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n");
665 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2));
668 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2));
670 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)) & 0xf0;
671 outb(bval | 0x02, ALI_REG(codec, ALI_SPDIF_CS + 3));
673 wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2));
676 outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2));
678 bval = inb(ALI_REG(codec,ALI_SPDIF_CS + 3)) & 0xf0;
679 outb(bval | 0x03, ALI_REG(codec, ALI_SPDIF_CS + 3));
683 static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali *codec)
688 bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
691 outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL));
693 snd_ali_detect_spdif_rate(codec);
695 bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3));
708 static void snd_ali_enable_spdif_in(struct snd_ali *codec)
712 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL));
714 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
716 dwVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
718 outb(dwVal, ALI_REG(codec, ALI_SPDIF_CTRL));
720 snd_ali_enable_special_channel(codec, ALI_SPDIF_IN_CHANNEL);
723 static void snd_ali_disable_spdif_in(struct snd_ali *codec)
727 dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL));
729 outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
731 snd_ali_disable_special_channel(codec, ALI_SPDIF_IN_CHANNEL);
735 static void snd_ali_set_spdif_out_rate(struct snd_ali *codec, unsigned int rate)
746 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
750 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL));
751 outb(dwRate | 0x20, ALI_REG(codec, ALI_SPDIF_CS + 2));
754 outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL));
755 outw(rate | 0x10, ALI_REG(codec, ALI_SPDIF_CS + 2));
758 static void snd_ali_enable_spdif_out(struct snd_ali *codec)
764 pci_dev = codec->pci_m1533;
779 bVal = inb(ALI_REG(codec, ALI_SCTRL));
780 outb(bVal | ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL));
782 bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
783 outb(bVal & ALI_SPDIF_OUT_CH_STATUS, ALI_REG(codec, ALI_SPDIF_CTRL));
785 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
787 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
788 snd_ali_disable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL);
791 static void snd_ali_enable_spdif_chnout(struct snd_ali *codec)
795 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
797 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
799 wVal = inw(ALI_REG(codec, ALI_SPDIF_CS));
804 outw(wVal, ALI_REG(codec, ALI_SPDIF_CS));
806 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL);
809 static void snd_ali_disable_spdif_chnout(struct snd_ali *codec)
813 wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
815 outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
817 snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL);
820 static void snd_ali_disable_spdif_out(struct snd_ali *codec)
824 bVal = inb(ALI_REG(codec, ALI_SCTRL));
825 outb(bVal & ~ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL));
827 snd_ali_disable_spdif_chnout(codec);
830 static void snd_ali_update_ptr(struct snd_ali *codec, int channel)
836 pchregs = &(codec->chregs);
839 old = pchregs->data.aint;
845 pvoice = &codec->synth.voices[channel];
848 spin_lock(&codec->reg_lock);
850 if (pvoice->pcm && pvoice->substream) {
852 if (pvoice->running) {
853 dev_dbg(codec->card->dev,
855 inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)),
856 (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask);
857 spin_unlock(&codec->reg_lock);
858 snd_pcm_period_elapsed(pvoice->substream);
859 spin_lock(&codec->reg_lock);
861 snd_ali_stop_voice(codec, channel);
862 snd_ali_disable_voice_irq(codec, channel);
864 } else if (codec->synth.voices[channel].synth) {
866 } else if (codec->synth.voices[channel].midi) {
870 snd_ali_stop_voice(codec, channel);
871 snd_ali_disable_voice_irq(codec, channel);
873 spin_unlock(&codec->reg_lock);
874 outl(mask,ALI_REG(codec,pchregs->regs.aint));
875 pchregs->data.aint = old & (~mask);
880 struct snd_ali *codec = dev_id;
885 if (codec == NULL || !codec->hw_initialized)
888 audio_int = inl(ALI_REG(codec, ALI_MISCINT));
892 pchregs = &(codec->chregs);
895 pchregs->data.aint = inl(ALI_REG(codec, pchregs->regs.aint));
897 snd_ali_update_ptr(codec, channel);
900 ALI_REG(codec, ALI_MISCINT));
906 static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec,
912 dev_dbg(codec->card->dev, "alloc_voice: type=%d rec=%d\n", type, rec);
914 guard(spinlock_irq)(&codec->voice_alloc);
916 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) :
917 snd_ali_find_free_channel(codec,rec);
919 dev_err(codec->card->dev, "ali_alloc_voice: err.\n");
922 pvoice = &(codec->synth.voices[idx]);
923 pvoice->codec = codec;
924 pvoice->use = 1;
925 pvoice->pcm = 1;
926 pvoice->mode = rec;
933 static void snd_ali_free_voice(struct snd_ali * codec,
939 dev_dbg(codec->card->dev, "free_voice: channel=%d\n", pvoice->number);
940 if (!pvoice->use)
942 snd_ali_clear_voices(codec, pvoice->number, pvoice->number);
943 scoped_guard(spinlock_irq, &codec->voice_alloc) {
944 private_free = pvoice->private_free;
945 private_data = pvoice->private_data;
946 pvoice->private_free = NULL;
947 pvoice->private_data = NULL;
948 if (pvoice->pcm)
949 snd_ali_free_channel_pcm(codec, pvoice->number);
950 pvoice->use = pvoice->pcm = pvoice->synth = 0;
951 pvoice->substream = NULL;
958 static void snd_ali_clear_voices(struct snd_ali *codec,
965 snd_ali_stop_voice(codec, i);
966 snd_ali_disable_voice_irq(codec, i);
970 static void snd_ali_write_voice_regs(struct snd_ali *codec,
981 unsigned int EC)
985 outb((unsigned char)(Channel & 0x001f), ALI_REG(codec, ALI_GC_CIR));
994 (EC & 0x00000fff);
996 outb(Channel, ALI_REG(codec, ALI_GC_CIR));
998 outl(ctlcmds[0], ALI_REG(codec, ALI_CSO_ALPHA_FMS));
999 outl(ctlcmds[1], ALI_REG(codec, ALI_LBA));
1000 outl(ctlcmds[2], ALI_REG(codec, ALI_ESO_DELTA));
1001 outl(ctlcmds[3], ALI_REG(codec, ALI_GVSEL_PAN_VOC_CTRL_EC));
1003 outl(0x30000000, ALI_REG(codec, ALI_EBUF1)); /* Still Mode */
1004 outl(0x30000000, ALI_REG(codec, ALI_EBUF2)); /* Still Mode */
1042 struct snd_pcm_runtime *runtime = substream->runtime;
1045 CTRL default: 8-bit (unsigned) mono, loop mode enabled
1048 if (snd_pcm_format_width(runtime->format) == 16)
1049 CTRL |= 0x00000008; /* 16-bit data */
1050 if (!snd_pcm_format_unsigned(runtime->format))
1052 if (runtime->channels > 1)
1065 struct snd_ali *codec = snd_pcm_substream_chip(substream);
1082 return -EINVAL;
1087 if ((struct snd_ali *) snd_pcm_substream_chip(s) == codec) {
1088 pvoice = s->runtime->private_data;
1089 evoice = pvoice->extra;
1090 what |= 1 << (pvoice->number & 0x1f);
1092 whati |= 1 << (pvoice->number & 0x1f);
1094 whati |= 1 << (evoice->number & 0x1f);
1095 what |= 1 << (evoice->number & 0x1f);
1098 pvoice->running = 1;
1100 evoice->running = 1;
1102 pvoice->running = 0;
1104 evoice->running = 0;
1109 guard(spinlock)(&codec->reg_lock);
1111 outl(what, ALI_REG(codec, ALI_STOP));
1112 val = inl(ALI_REG(codec, ALI_AINTEN));
1117 outl(val, ALI_REG(codec, ALI_AINTEN));
1119 outl(what, ALI_REG(codec, ALI_START));
1120 dev_dbg(codec->card->dev, "trigger: what=%xh whati=%xh\n", what, whati);
1128 struct snd_ali *codec = snd_pcm_substream_chip(substream);
1129 struct snd_pcm_runtime *runtime = substream->runtime;
1130 struct snd_ali_voice *pvoice = runtime->private_data;
1131 struct snd_ali_voice *evoice = pvoice->extra;
1138 evoice = snd_ali_alloc_voice(codec,
1140 0, -1);
1142 return -ENOMEM;
1143 pvoice->extra = evoice;
1144 evoice->substream = substream;
1148 snd_ali_free_voice(codec, evoice);
1149 pvoice->extra = evoice = NULL;
1158 struct snd_ali *codec = snd_pcm_substream_chip(substream);
1159 struct snd_pcm_runtime *runtime = substream->runtime;
1160 struct snd_ali_voice *pvoice = runtime->private_data;
1161 struct snd_ali_voice *evoice = pvoice ? pvoice->extra : NULL;
1164 snd_ali_free_voice(codec, evoice);
1165 pvoice->extra = NULL;
1172 struct snd_ali *codec = snd_pcm_substream_chip(substream);
1173 struct snd_pcm_runtime *runtime = substream->runtime;
1174 struct snd_ali_voice *pvoice = runtime->private_data;
1175 struct snd_ali_voice *evoice = pvoice->extra;
1184 unsigned int EC;
1186 dev_dbg(codec->card->dev, "playback_prepare ...\n");
1188 guard(spinlock_irq)(&codec->reg_lock);
1191 Delta = snd_ali_convert_rate(runtime->rate, 0);
1193 if (pvoice->number == ALI_SPDIF_IN_CHANNEL ||
1194 pvoice->number == ALI_PCM_IN_CHANNEL)
1195 snd_ali_disable_special_channel(codec, pvoice->number);
1196 else if (codec->spdif_support &&
1197 (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) &
1199 && pvoice->number == ALI_SPDIF_OUT_CHANNEL) {
1200 snd_ali_set_spdif_out_rate(codec, runtime->rate);
1205 LBA = runtime->dma_addr;
1208 pvoice->count = runtime->period_size;
1211 pvoice->eso = runtime->buffer_size;
1213 dev_dbg(codec->card->dev, "playback_prepare: eso=%xh count=%xh\n",
1214 pvoice->eso, pvoice->count);
1217 ESO = pvoice->eso -1;
1224 EC = 0;
1225 dev_dbg(codec->card->dev, "playback_prepare:\n");
1226 dev_dbg(codec->card->dev,
1228 pvoice->number,runtime->rate,Delta,GVSEL,PAN,CTRL);
1229 snd_ali_write_voice_regs(codec,
1230 pvoice->number,
1240 EC);
1242 evoice->count = pvoice->count;
1243 evoice->eso = pvoice->count << 1;
1244 ESO = evoice->eso - 1;
1245 snd_ali_write_voice_regs(codec,
1246 evoice->number,
1256 EC);
1264 struct snd_ali *codec = snd_pcm_substream_chip(substream);
1265 struct snd_pcm_runtime *runtime = substream->runtime;
1266 struct snd_ali_voice *pvoice = runtime->private_data;
1274 unsigned int EC;
1277 spin_lock_irq(&codec->reg_lock);
1279 dev_dbg(codec->card->dev, "ali_prepare...\n");
1281 snd_ali_enable_special_channel(codec,pvoice->number);
1283 Delta = (pvoice->number == ALI_MODEM_IN_CHANNEL ||
1284 pvoice->number == ALI_MODEM_OUT_CHANNEL) ?
1285 0x1000 : snd_ali_convert_rate(runtime->rate, pvoice->mode);
1288 if (pvoice->number == ALI_SPDIF_IN_CHANNEL) {
1292 spin_unlock_irq(&codec->reg_lock);
1293 if (codec->revision != ALI_5451_V02)
1294 return -1;
1296 rate = snd_ali_get_spdif_in_rate(codec);
1298 dev_warn(codec->card->dev,
1302 spin_lock_irq(&codec->reg_lock);
1303 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL));
1305 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL));
1306 dev_warn(codec->card->dev,
1311 Delta = ((rate << 12) / runtime->rate) & 0x00ffff;
1315 pvoice->eso = runtime->buffer_size;
1318 pvoice->count = runtime->period_size;
1321 LBA = runtime->dma_addr;
1324 ESO = pvoice->eso - 1;
1329 EC = 0;
1331 snd_ali_write_voice_regs( codec,
1332 pvoice->number,
1342 EC);
1344 spin_unlock_irq(&codec->reg_lock);
1353 struct snd_ali *codec = snd_pcm_substream_chip(substream);
1354 struct snd_pcm_runtime *runtime = substream->runtime;
1355 struct snd_ali_voice *pvoice = runtime->private_data;
1358 guard(spinlock)(&codec->reg_lock);
1359 if (!pvoice->running)
1361 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR));
1362 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2));
1363 dev_dbg(codec->card->dev, "playback pointer returned cso=%xh.\n", cso);
1365 cso %= runtime->buffer_size;
1372 struct snd_ali *codec = snd_pcm_substream_chip(substream);
1373 struct snd_pcm_runtime *runtime = substream->runtime;
1374 struct snd_ali_voice *pvoice = runtime->private_data;
1377 guard(spinlock)(&codec->reg_lock);
1378 if (!pvoice->running)
1380 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR));
1381 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2));
1383 cso %= runtime->buffer_size;
1437 struct snd_ali_voice *pvoice = runtime->private_data;
1440 snd_ali_free_voice(pvoice->codec, pvoice);
1446 struct snd_ali *codec = snd_pcm_substream_chip(substream);
1447 struct snd_pcm_runtime *runtime = substream->runtime;
1450 pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, rec,
1453 return -EAGAIN;
1455 pvoice->substream = substream;
1456 runtime->private_data = pvoice;
1457 runtime->private_free = snd_ali_pcm_free_substream;
1459 runtime->hw = *phw;
1468 return snd_ali_open(substream, 0, -1, &snd_ali_playback);
1473 return snd_ali_open(substream, 1, -1, &snd_ali_capture);
1483 struct snd_ali *codec = snd_pcm_substream_chip(substream);
1484 struct snd_ali_voice *pvoice = substream->runtime->private_data;
1486 snd_ali_disable_special_channel(codec,pvoice->number);
1517 unsigned int modem_num = chip->num_of_codecs - 1;
1518 snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_RATE,
1520 snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_LEVEL, 0);
1559 return snd_pcm_hw_constraint_list(substream->runtime, 0,
1604 struct snd_ali *codec = pcm->private_data;
1605 codec->pcm[pcm->device] = NULL;
1609 static int snd_ali_pcm(struct snd_ali *codec, int device,
1615 err = snd_pcm_new(codec->card, desc->name, device,
1616 desc->playback_num, desc->capture_num, &pcm);
1618 dev_err(codec->card->dev,
1622 pcm->private_data = codec;
1623 pcm->private_free = snd_ali_pcm_free;
1624 if (desc->playback_ops)
1626 desc->playback_ops);
1627 if (desc->capture_ops)
1629 desc->capture_ops);
1632 &codec->pci->dev, 64*1024, 128*1024);
1634 pcm->info_flags = 0;
1635 pcm->dev_class = desc->class;
1636 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
1637 strscpy(pcm->name, desc->name);
1638 codec->pcm[0] = pcm;
1658 static int snd_ali_build_pcms(struct snd_ali *codec)
1661 for (i = 0; i < codec->num_of_codecs && i < ARRAY_SIZE(ali_pcms); i++) {
1662 err = snd_ali_pcm(codec, i, &ali_pcms[i]);
1680 struct snd_ali *codec = snd_kcontrol_chip(kcontrol);
1683 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0;
1685 guard(spinlock_irq)(&codec->reg_lock);
1686 switch (kcontrol->private_value) {
1688 spdif_enable = (codec->spdif_mask & 0x02) ? 1 : 0;
1691 spdif_enable = ((codec->spdif_mask & 0x02) &&
1692 (codec->spdif_mask & 0x04)) ? 1 : 0;
1695 spdif_enable = (codec->spdif_mask & 0x01) ? 1 : 0;
1700 ucontrol->value.integer.value[0] = spdif_enable;
1707 struct snd_ali *codec = snd_kcontrol_chip(kcontrol);
1710 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0;
1712 guard(spinlock_irq)(&codec->reg_lock);
1713 switch (kcontrol->private_value) {
1715 change = (codec->spdif_mask & 0x02) ? 1 : 0;
1719 codec->spdif_mask |= 0x02;
1720 snd_ali_enable_spdif_out(codec);
1722 codec->spdif_mask &= ~(0x02);
1723 codec->spdif_mask &= ~(0x04);
1724 snd_ali_disable_spdif_out(codec);
1729 change = (codec->spdif_mask & 0x04) ? 1 : 0;
1731 if (change && (codec->spdif_mask & 0x02)) {
1733 codec->spdif_mask |= 0x04;
1734 snd_ali_enable_spdif_chnout(codec);
1736 codec->spdif_mask &= ~(0x04);
1737 snd_ali_disable_spdif_chnout(codec);
1742 change = (codec->spdif_mask & 0x01) ? 1 : 0;
1746 codec->spdif_mask |= 0x01;
1747 snd_ali_enable_spdif_in(codec);
1749 codec->spdif_mask &= ~(0x01);
1750 snd_ali_disable_spdif_in(codec);
1771 static int snd_ali_mixer(struct snd_ali *codec)
1781 err = snd_ac97_bus(codec->card, 0, &ops, codec, &codec->ac97_bus);
1786 ac97.private_data = codec;
1788 for (i = 0; i < codec->num_of_codecs; i++) {
1790 err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i]);
1792 dev_err(codec->card->dev,
1796 codec->num_of_codecs = 1;
1801 if (codec->spdif_support) {
1803 err = snd_ctl_add(codec->card,
1804 snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec));
1815 struct snd_ali *chip = card->private_data;
1816 struct snd_ali_image *im = &chip->image;
1820 for (i = 0; i < chip->num_of_codecs; i++)
1821 snd_ac97_suspend(chip->ac97[i]);
1823 guard(spinlock_irq)(&chip->reg_lock);
1825 im->regs[ALI_MISCINT >> 2] = inl(ALI_REG(chip, ALI_MISCINT));
1826 /* im->regs[ALI_START >> 2] = inl(ALI_REG(chip, ALI_START)); */
1827 im->regs[ALI_STOP >> 2] = inl(ALI_REG(chip, ALI_STOP));
1835 im->regs[i] = inl(ALI_REG(chip, i*4));
1841 im->channel_regs[i][j] = inl(ALI_REG(chip, j*4 + 0xe0));
1853 struct snd_ali *chip = card->private_data;
1854 struct snd_ali_image *im = &chip->image;
1857 scoped_guard(spinlock_irq, &chip->reg_lock) {
1861 outl(im->channel_regs[i][j], ALI_REG(chip, j*4 + 0xe0));
1868 outl(im->regs[i], ALI_REG(chip, i*4));
1872 outl(im->regs[ALI_START >> 2], ALI_REG(chip, ALI_START));
1874 outl(im->regs[ALI_MISCINT >> 2], ALI_REG(chip, ALI_MISCINT));
1877 for (i = 0 ; i < chip->num_of_codecs; i++)
1878 snd_ac97_resume(chip->ac97[i]);
1888 struct snd_ali *codec = card->private_data;
1890 if (codec->hw_initialized)
1891 snd_ali_disable_address_interrupt(codec);
1892 pci_dev_put(codec->pci_m1533);
1893 pci_dev_put(codec->pci_m7101);
1896 static int snd_ali_chip_init(struct snd_ali *codec)
1902 dev_dbg(codec->card->dev, "chip initializing ...\n");
1904 if (snd_ali_reset_5451(codec)) {
1905 dev_err(codec->card->dev, "ali_chip_init: reset 5451 error.\n");
1906 return -1;
1909 if (codec->revision == ALI_5451_V02) {
1910 pci_dev = codec->pci_m1533;
1915 pci_dev = codec->pci_m7101;
1921 pci_read_config_dword(codec->pci, 0x44, &legacy);
1924 pci_write_config_dword(codec->pci, 0x44, legacy);
1926 outl(0x80000001, ALI_REG(codec, ALI_GLOBAL_CONTROL));
1927 outl(0x00000000, ALI_REG(codec, ALI_AINTEN));
1928 outl(0xffffffff, ALI_REG(codec, ALI_AINT));
1929 outl(0x00000000, ALI_REG(codec, ALI_VOLUME));
1930 outb(0x10, ALI_REG(codec, ALI_MPUR2));
1932 codec->ac97_ext_id = snd_ali_codec_peek(codec, 0, AC97_EXTENDED_ID);
1933 codec->ac97_ext_status = snd_ali_codec_peek(codec, 0,
1935 if (codec->spdif_support) {
1936 snd_ali_enable_spdif_out(codec);
1937 codec->spdif_mask = 0x00000002;
1940 codec->num_of_codecs = 1;
1942 /* secondary codec - modem */
1943 if (inl(ALI_REG(codec, ALI_SCTRL)) & ALI_SCTRL_CODEC2_READY) {
1944 codec->num_of_codecs++;
1945 outl(inl(ALI_REG(codec, ALI_SCTRL)) |
1948 ALI_REG(codec, ALI_SCTRL));
1951 dev_dbg(codec->card->dev, "chip initialize succeed.\n");
1960 struct snd_ali *codec = entry->private_data;
1963 snd_iprintf(buf, "%02x: %08x\n", i, inl(ALI_REG(codec, i)));
1966 static void snd_ali_proc_init(struct snd_ali *codec)
1968 snd_card_ro_proc_new(codec->card, "ali5451", codec, snd_ali_proc_read);
1971 static int snd_ali_resources(struct snd_ali *codec)
1975 dev_dbg(codec->card->dev, "resources allocation ...\n");
1976 err = pcim_request_all_regions(codec->pci, "ALI 5451");
1979 codec->port = pci_resource_start(codec->pci, 0);
1981 if (devm_request_irq(&codec->pci->dev, codec->pci->irq,
1983 IRQF_SHARED, KBUILD_MODNAME, codec)) {
1984 dev_err(codec->card->dev, "Unable to request irq.\n");
1985 return -EBUSY;
1987 codec->irq = codec->pci->irq;
1988 codec->card->sync_irq = codec->irq;
1989 dev_dbg(codec->card->dev, "resources allocated.\n");
1998 struct snd_ali *codec = card->private_data;
2002 dev_dbg(card->dev, "creating ...\n");
2009 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(31))) {
2010 dev_err(card->dev,
2012 return -ENXIO;
2015 spin_lock_init(&codec->reg_lock);
2016 spin_lock_init(&codec->voice_alloc);
2018 codec->card = card;
2019 codec->pci = pci;
2020 codec->irq = -1;
2021 codec->revision = pci->revision;
2022 codec->spdif_support = spdif_support;
2036 if (snd_ali_resources(codec))
2037 return -EBUSY;
2038 card->private_free = snd_ali_free;
2040 codec->synth.chmap = 0;
2041 codec->synth.chcnt = 0;
2042 codec->spdif_mask = 0;
2043 codec->synth.synthcount = 0;
2045 if (codec->revision == ALI_5451_V02)
2046 codec->chregs.regs.ac97read = ALI_AC97_WRITE;
2048 codec->chregs.regs.ac97read = ALI_AC97_READ;
2049 codec->chregs.regs.ac97write = ALI_AC97_WRITE;
2051 codec->chregs.regs.start = ALI_START;
2052 codec->chregs.regs.stop = ALI_STOP;
2053 codec->chregs.regs.aint = ALI_AINT;
2054 codec->chregs.regs.ainten = ALI_AINTEN;
2056 codec->chregs.data.start = 0x00;
2057 codec->chregs.data.stop = 0x00;
2058 codec->chregs.data.aint = 0x00;
2059 codec->chregs.data.ainten = 0x00;
2062 codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL);
2063 if (!codec->pci_m1533) {
2064 dev_err(card->dev, "cannot find ALi 1533 chip.\n");
2065 return -ENODEV;
2068 codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL);
2069 if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) {
2070 dev_err(card->dev, "cannot find ALi 7101 chip.\n");
2071 return -ENODEV;
2076 codec->synth.voices[i].number = i;
2078 err = snd_ali_chip_init(codec);
2080 dev_err(card->dev, "ali create: chip init error.\n");
2084 snd_ali_enable_address_interrupt(codec);
2085 codec->hw_initialized = 1;
2093 struct snd_ali *codec;
2096 dev_dbg(&pci->dev, "probe ...\n");
2098 err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE,
2099 sizeof(*codec), &card);
2102 codec = card->private_data;
2108 dev_dbg(&pci->dev, "mixer building ...\n");
2109 err = snd_ali_mixer(codec);
2113 dev_dbg(&pci->dev, "pcm building ...\n");
2114 err = snd_ali_build_pcms(codec);
2118 snd_ali_proc_init(codec);
2120 strscpy(card->driver, "ALI5451");
2121 strscpy(card->shortname, "ALI 5451");
2123 sprintf(card->longname, "%s at 0x%lx, irq %i",
2124 card->shortname, codec->port, codec->irq);
2126 dev_dbg(&pci->dev, "register card.\n");
2138 return snd_card_free_on_error(&pci->dev, __snd_ali_probe(pci, pci_id));