Lines Matching refs:chip

32 static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip);
34 static inline u8 snd_ymfpci_readb(struct snd_ymfpci *chip, u32 offset)
36 return readb(chip->reg_area_virt + offset);
39 static inline void snd_ymfpci_writeb(struct snd_ymfpci *chip, u32 offset, u8 val)
41 writeb(val, chip->reg_area_virt + offset);
44 static inline u16 snd_ymfpci_readw(struct snd_ymfpci *chip, u32 offset)
46 return readw(chip->reg_area_virt + offset);
49 static inline void snd_ymfpci_writew(struct snd_ymfpci *chip, u32 offset, u16 val)
51 writew(val, chip->reg_area_virt + offset);
54 static inline u32 snd_ymfpci_readl(struct snd_ymfpci *chip, u32 offset)
56 return readl(chip->reg_area_virt + offset);
59 static inline void snd_ymfpci_writel(struct snd_ymfpci *chip, u32 offset, u32 val)
61 writel(val, chip->reg_area_virt + offset);
64 static int snd_ymfpci_codec_ready(struct snd_ymfpci *chip, int secondary)
71 if ((snd_ymfpci_readw(chip, reg) & 0x8000) == 0)
75 dev_err(chip->card->dev,
77 secondary, snd_ymfpci_readw(chip, reg));
83 struct snd_ymfpci *chip = ac97->private_data;
86 snd_ymfpci_codec_ready(chip, 0);
88 snd_ymfpci_writel(chip, YDSXGR_AC97CMDDATA, cmd);
93 struct snd_ymfpci *chip = ac97->private_data;
95 if (snd_ymfpci_codec_ready(chip, 0))
97 snd_ymfpci_writew(chip, YDSXGR_AC97CMDADR, YDSXG_AC97READCMD | reg);
98 if (snd_ymfpci_codec_ready(chip, 0))
100 if (chip->device_id == PCI_DEVICE_ID_YAMAHA_744 && chip->rev < 2) {
103 snd_ymfpci_readw(chip, YDSXGR_PRISTATUSDATA);
105 return snd_ymfpci_readw(chip, YDSXGR_PRISTATUSDATA);
165 static void snd_ymfpci_hw_start(struct snd_ymfpci *chip)
169 spin_lock_irqsave(&chip->reg_lock, flags);
170 if (chip->start_count++ > 0)
172 snd_ymfpci_writel(chip, YDSXGR_MODE,
173 snd_ymfpci_readl(chip, YDSXGR_MODE) | 3);
174 chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT) & 1;
176 spin_unlock_irqrestore(&chip->reg_lock, flags);
179 static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
184 spin_lock_irqsave(&chip->reg_lock, flags);
185 if (--chip->start_count > 0)
187 snd_ymfpci_writel(chip, YDSXGR_MODE,
188 snd_ymfpci_readl(chip, YDSXGR_MODE) & ~3);
190 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
193 if (atomic_read(&chip->interrupt_sleep_count)) {
194 atomic_set(&chip->interrupt_sleep_count, 0);
195 wake_up(&chip->interrupt_sleep);
198 spin_unlock_irqrestore(&chip->reg_lock, flags);
205 static int voice_alloc(struct snd_ymfpci *chip,
214 voice = &chip->voices[idx];
215 voice2 = pair ? &chip->voices[idx+1] : NULL;
234 snd_ymfpci_hw_start(chip);
236 snd_ymfpci_hw_start(chip);
243 static int snd_ymfpci_voice_alloc(struct snd_ymfpci *chip,
255 spin_lock_irqsave(&chip->voice_lock, flags);
257 result = voice_alloc(chip, type, pair, rvoice);
263 spin_unlock_irqrestore(&chip->voice_lock, flags);
267 static int snd_ymfpci_voice_free(struct snd_ymfpci *chip, struct snd_ymfpci_voice *pvoice)
273 snd_ymfpci_hw_stop(chip);
274 spin_lock_irqsave(&chip->voice_lock, flags);
275 if (pvoice->number == chip->src441_used) {
276 chip->src441_used = -1;
282 spin_unlock_irqrestore(&chip->voice_lock, flags);
290 static void snd_ymfpci_pcm_interrupt(struct snd_ymfpci *chip, struct snd_ymfpci_voice *voice)
300 spin_lock(&chip->reg_lock);
302 pos = le32_to_cpu(voice->bank[chip->active_bank].start);
311 dev_dbg(chip->card->dev,
313 chip->active_bank,
314 voice->bank[chip->active_bank].start);
317 spin_unlock(&chip->reg_lock);
319 spin_lock(&chip->reg_lock);
324 unsigned int next_bank = 1 - chip->active_bank;
329 volume = cpu_to_le32(chip->pcm_mixer[subs].left << 15);
335 volume = cpu_to_le32(chip->pcm_mixer[subs].right << 15);
342 spin_unlock(&chip->reg_lock);
349 struct snd_ymfpci *chip = ypcm->chip;
352 spin_lock(&chip->reg_lock);
354 pos = le32_to_cpu(chip->bank_capture[ypcm->capture_bank_number][chip->active_bank]->start) >> ypcm->shift;
364 dev_dbg(chip->card->dev,
366 chip->active_bank,
367 voice->bank[chip->active_bank].start);
369 spin_unlock(&chip->reg_lock);
371 spin_lock(&chip->reg_lock);
374 spin_unlock(&chip->reg_lock);
380 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
385 spin_lock(&chip->reg_lock);
394 chip->ctrl_playback[ypcm->voices[0]->number + 1] = cpu_to_le32(ypcm->voices[0]->bank_addr);
396 chip->ctrl_playback[ypcm->voices[1]->number + 1] = cpu_to_le32(ypcm->voices[1]->bank_addr);
400 if (substream->pcm == chip->pcm && !ypcm->use_441_slot) {
401 kctl = chip->pcm_mixer[substream->number].ctl;
407 chip->ctrl_playback[ypcm->voices[0]->number + 1] = 0;
409 chip->ctrl_playback[ypcm->voices[1]->number + 1] = 0;
417 spin_unlock(&chip->reg_lock);
419 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id);
425 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
430 spin_lock(&chip->reg_lock);
435 tmp = snd_ymfpci_readl(chip, YDSXGR_MAPOFREC) | (1 << ypcm->capture_bank_number);
436 snd_ymfpci_writel(chip, YDSXGR_MAPOFREC, tmp);
442 tmp = snd_ymfpci_readl(chip, YDSXGR_MAPOFREC) & ~(1 << ypcm->capture_bank_number);
443 snd_ymfpci_writel(chip, YDSXGR_MAPOFREC, tmp);
450 spin_unlock(&chip->reg_lock);
459 snd_ymfpci_voice_free(ypcm->chip, ypcm->voices[1]);
468 snd_ymfpci_voice_free(ypcm->chip, ypcm->voices[0]);
472 err = snd_ymfpci_voice_alloc(ypcm->chip, YMFPCI_PCM, voices > 1, &ypcm->voices[0]);
478 ypcm->voices[1] = &ypcm->chip->voices[ypcm->voices[0]->number + 1];
509 vol_left = cpu_to_le32(ypcm->chip->pcm_mixer
511 vol_right = cpu_to_le32(ypcm->chip->pcm_mixer
517 spin_lock_irqsave(&ypcm->chip->voice_lock, flags);
521 else if (ypcm->chip->device_id == PCI_DEVICE_ID_YAMAHA_754 &&
523 voiceidx == 0 && (ypcm->chip->src441_used == -1 ||
524 ypcm->chip->src441_used == voice->number)) {
525 ypcm->chip->src441_used = voice->number;
529 if (ypcm->chip->src441_used == voice->number &&
531 ypcm->chip->src441_used = -1;
536 spin_unlock_irqrestore(&ypcm->chip->voice_lock, flags);
589 static int snd_ymfpci_ac3_init(struct snd_ymfpci *chip)
591 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
592 4096, &chip->ac3_tmp_base) < 0)
595 chip->bank_effect[3][0]->base =
596 chip->bank_effect[3][1]->base = cpu_to_le32(chip->ac3_tmp_base.addr);
597 chip->bank_effect[3][0]->loop_end =
598 chip->bank_effect[3][1]->loop_end = cpu_to_le32(1024);
599 chip->bank_effect[4][0]->base =
600 chip->bank_effect[4][1]->base = cpu_to_le32(chip->ac3_tmp_base.addr + 2048);
601 chip->bank_effect[4][0]->loop_end =
602 chip->bank_effect[4][1]->loop_end = cpu_to_le32(1024);
604 spin_lock_irq(&chip->reg_lock);
605 snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT,
606 snd_ymfpci_readl(chip, YDSXGR_MAPOFEFFECT) | 3 << 3);
607 spin_unlock_irq(&chip->reg_lock);
611 static int snd_ymfpci_ac3_done(struct snd_ymfpci *chip)
613 spin_lock_irq(&chip->reg_lock);
614 snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT,
615 snd_ymfpci_readl(chip, YDSXGR_MAPOFEFFECT) & ~(3 << 3));
616 spin_unlock_irq(&chip->reg_lock);
617 // snd_ymfpci_irq_wait(chip);
618 if (chip->ac3_tmp_base.area) {
619 snd_dma_free_pages(&chip->ac3_tmp_base);
620 chip->ac3_tmp_base.area = NULL;
640 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
649 snd_ymfpci_irq_wait(chip);
651 snd_ymfpci_voice_free(chip, ypcm->voices[1]);
655 snd_ymfpci_voice_free(chip, ypcm->voices[0]);
663 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
675 substream->pcm == chip->pcm);
677 if (substream->pcm == chip->pcm && !ypcm->use_441_slot) {
678 kctl = chip->pcm_mixer[substream->number].ctl;
680 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id);
687 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
690 snd_ymfpci_irq_wait(chip);
696 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
720 snd_ymfpci_writel(chip, YDSXGR_RECFORMAT, format);
721 snd_ymfpci_writel(chip, YDSXGR_RECSLOTSR, rate);
724 snd_ymfpci_writel(chip, YDSXGR_ADCFORMAT, format);
725 snd_ymfpci_writel(chip, YDSXGR_ADCSLOTSR, rate);
729 bank = chip->bank_capture[ypcm->capture_bank_number][nbank];
740 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
747 return le32_to_cpu(voice->bank[chip->active_bank].start);
752 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
758 return le32_to_cpu(chip->bank_capture[ypcm->capture_bank_number][chip->active_bank]->start) >> ypcm->shift;
761 static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
767 if ((snd_ymfpci_readl(chip, YDSXGR_MODE) & 3) == 0)
770 add_wait_queue(&chip->interrupt_sleep, &wait);
771 atomic_inc(&chip->interrupt_sleep_count);
773 remove_wait_queue(&chip->interrupt_sleep, &wait);
779 struct snd_ymfpci *chip = dev_id;
783 status = snd_ymfpci_readl(chip, YDSXGR_STATUS);
785 chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT) & 1;
786 spin_lock(&chip->voice_lock);
788 voice = &chip->voices[nvoice];
790 voice->interrupt(chip, voice);
793 if (chip->capture_substream[nvoice])
794 snd_ymfpci_pcm_capture_interrupt(chip->capture_substream[nvoice]);
798 if (chip->effect_substream[nvoice])
799 snd_ymfpci_pcm_effect_interrupt(chip->effect_substream[nvoice]);
802 spin_unlock(&chip->voice_lock);
803 spin_lock(&chip->reg_lock);
804 snd_ymfpci_writel(chip, YDSXGR_STATUS, 0x80000000);
805 mode = snd_ymfpci_readl(chip, YDSXGR_MODE) | 2;
806 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
807 spin_unlock(&chip->reg_lock);
809 if (atomic_read(&chip->interrupt_sleep_count)) {
810 atomic_set(&chip->interrupt_sleep_count, 0);
811 wake_up(&chip->interrupt_sleep);
815 status = snd_ymfpci_readw(chip, YDSXGR_INTFLAG);
817 if (chip->timer)
818 snd_timer_interrupt(chip->timer, chip->timer_ticks);
820 snd_ymfpci_writew(chip, YDSXGR_INTFLAG, status);
822 if (chip->rawmidi)
823 snd_mpu401_uart_interrupt(irq, chip->rawmidi->private_data);
878 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
897 ypcm->chip = chip;
906 static void ymfpci_open_extension(struct snd_ymfpci *chip)
908 if (! chip->rear_opened) {
909 if (! chip->spdif_opened) /* set AC3 */
910 snd_ymfpci_writel(chip, YDSXGR_MODE,
911 snd_ymfpci_readl(chip, YDSXGR_MODE) | (1 << 30));
913 snd_ymfpci_writew(chip, YDSXGR_SECCONFIG,
914 (snd_ymfpci_readw(chip, YDSXGR_SECCONFIG) & ~0x0330) | 0x0010);
919 static void ymfpci_close_extension(struct snd_ymfpci *chip)
921 if (! chip->rear_opened) {
922 if (! chip->spdif_opened)
923 snd_ymfpci_writel(chip, YDSXGR_MODE,
924 snd_ymfpci_readl(chip, YDSXGR_MODE) & ~(1 << 30));
925 snd_ymfpci_writew(chip, YDSXGR_SECCONFIG,
926 (snd_ymfpci_readw(chip, YDSXGR_SECCONFIG) & ~0x0330) & ~0x0010);
932 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
942 ypcm->output_rear = chip->mode_dup4ch ? 1 : 0;
944 spin_lock_irq(&chip->reg_lock);
946 ymfpci_open_extension(chip);
947 chip->rear_opened++;
949 spin_unlock_irq(&chip->reg_lock);
955 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
967 spin_lock_irq(&chip->reg_lock);
968 snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL,
969 snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) | 2);
970 ymfpci_open_extension(chip);
971 chip->spdif_pcm_bits = chip->spdif_bits;
972 snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits);
973 chip->spdif_opened++;
974 spin_unlock_irq(&chip->reg_lock);
976 chip->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
977 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
978 SNDRV_CTL_EVENT_MASK_INFO, &chip->spdif_pcm_ctl->id);
984 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
996 spin_lock_irq(&chip->reg_lock);
997 ymfpci_open_extension(chip);
998 chip->rear_opened++;
999 spin_unlock_irq(&chip->reg_lock);
1006 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
1025 ypcm->chip = chip;
1029 chip->capture_substream[capture_bank_number] = substream;
1032 snd_ymfpci_hw_start(chip);
1053 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
1056 spin_lock_irq(&chip->reg_lock);
1057 if (ypcm->output_rear && chip->rear_opened > 0) {
1058 chip->rear_opened--;
1059 ymfpci_close_extension(chip);
1061 spin_unlock_irq(&chip->reg_lock);
1067 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
1069 spin_lock_irq(&chip->reg_lock);
1070 chip->spdif_opened = 0;
1071 ymfpci_close_extension(chip);
1072 snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL,
1073 snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & ~2);
1074 snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits);
1075 spin_unlock_irq(&chip->reg_lock);
1076 chip->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1077 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
1078 SNDRV_CTL_EVENT_MASK_INFO, &chip->spdif_pcm_ctl->id);
1084 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
1086 spin_lock_irq(&chip->reg_lock);
1087 if (chip->rear_opened > 0) {
1088 chip->rear_opened--;
1089 ymfpci_close_extension(chip);
1091 spin_unlock_irq(&chip->reg_lock);
1097 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
1102 chip->capture_substream[ypcm->capture_bank_number] = NULL;
1103 snd_ymfpci_hw_stop(chip);
1127 int snd_ymfpci_pcm(struct snd_ymfpci *chip, int device)
1132 err = snd_pcm_new(chip->card, "YMFPCI", device, 32, 1, &pcm);
1135 pcm->private_data = chip;
1143 chip->pcm = pcm;
1146 &chip->pci->dev, 64*1024, 256*1024);
1161 int snd_ymfpci_pcm2(struct snd_ymfpci *chip, int device)
1166 err = snd_pcm_new(chip->card, "YMFPCI - PCM2", device, 0, 1, &pcm);
1169 pcm->private_data = chip;
1176 chip->device_id == PCI_DEVICE_ID_YAMAHA_754 ? "Direct Recording" : "AC'97");
1177 chip->pcm2 = pcm;
1180 &chip->pci->dev, 64*1024, 256*1024);
1195 int snd_ymfpci_pcm_spdif(struct snd_ymfpci *chip, int device)
1200 err = snd_pcm_new(chip->card, "YMFPCI - IEC958", device, 1, 0, &pcm);
1203 pcm->private_data = chip;
1210 chip->pcm_spdif = pcm;
1213 &chip->pci->dev, 64*1024, 256*1024);
1236 int snd_ymfpci_pcm_4ch(struct snd_ymfpci *chip, int device)
1241 err = snd_pcm_new(chip->card, "YMFPCI - Rear", device, 1, 0, &pcm);
1244 pcm->private_data = chip;
1251 chip->pcm_4ch = pcm;
1254 &chip->pci->dev, 64*1024, 256*1024);
1270 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1272 spin_lock_irq(&chip->reg_lock);
1273 ucontrol->value.iec958.status[0] = (chip->spdif_bits >> 0) & 0xff;
1274 ucontrol->value.iec958.status[1] = (chip->spdif_bits >> 8) & 0xff;
1276 spin_unlock_irq(&chip->reg_lock);
1283 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1289 spin_lock_irq(&chip->reg_lock);
1290 change = chip->spdif_bits != val;
1291 chip->spdif_bits = val;
1292 if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 1) && chip->pcm_spdif == NULL)
1293 snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits);
1294 spin_unlock_irq(&chip->reg_lock);
1317 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1319 spin_lock_irq(&chip->reg_lock);
1322 spin_unlock_irq(&chip->reg_lock);
1345 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1347 spin_lock_irq(&chip->reg_lock);
1348 ucontrol->value.iec958.status[0] = (chip->spdif_pcm_bits >> 0) & 0xff;
1349 ucontrol->value.iec958.status[1] = (chip->spdif_pcm_bits >> 8) & 0xff;
1351 spin_unlock_irq(&chip->reg_lock);
1358 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1364 spin_lock_irq(&chip->reg_lock);
1365 change = chip->spdif_pcm_bits != val;
1366 chip->spdif_pcm_bits = val;
1367 if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 2))
1368 snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits);
1369 spin_unlock_irq(&chip->reg_lock);
1392 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1395 spin_lock_irq(&chip->reg_lock);
1396 reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL);
1397 spin_unlock_irq(&chip->reg_lock);
1407 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1410 spin_lock_irq(&chip->reg_lock);
1411 old_reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL);
1416 snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, reg);
1417 spin_unlock_irq(&chip->reg_lock);
1445 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1456 (snd_ymfpci_readl(chip, reg) >> shift) & mask;
1463 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1477 spin_lock_irq(&chip->reg_lock);
1478 oval = snd_ymfpci_readl(chip, reg);
1481 snd_ymfpci_writel(chip, reg, val);
1482 spin_unlock_irq(&chip->reg_lock);
1511 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1518 spin_lock_irq(&chip->reg_lock);
1519 val = snd_ymfpci_readl(chip, reg);
1520 spin_unlock_irq(&chip->reg_lock);
1528 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1540 spin_lock_irq(&chip->reg_lock);
1541 oval = snd_ymfpci_readl(chip, reg);
1544 snd_ymfpci_writel(chip, reg, val1);
1545 spin_unlock_irq(&chip->reg_lock);
1552 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1560 spin_lock_irq(&chip->reg_lock);
1561 oval = snd_ymfpci_readl(chip, reg);
1563 snd_ymfpci_writel(chip, reg, value);
1564 snd_ymfpci_writel(chip, reg2, value);
1565 spin_unlock_irq(&chip->reg_lock);
1576 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1577 ucontrol->value.integer.value[0] = chip->mode_dup4ch;
1583 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1585 change = (ucontrol->value.integer.value[0] != chip->mode_dup4ch);
1587 chip->mode_dup4ch = !!ucontrol->value.integer.value[0];
1634 static int snd_ymfpci_get_gpio_out(struct snd_ymfpci *chip, int pin)
1639 spin_lock_irqsave(&chip->reg_lock, flags);
1640 reg = snd_ymfpci_readw(chip, YDSXGR_GPIOFUNCENABLE);
1643 snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg);
1645 mode = snd_ymfpci_readw(chip, YDSXGR_GPIOTYPECONFIG);
1647 snd_ymfpci_writew(chip, YDSXGR_GPIOTYPECONFIG, mode);
1648 snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg | (1 << (pin + 8)));
1649 mode = snd_ymfpci_readw(chip, YDSXGR_GPIOINSTATUS);
1650 spin_unlock_irqrestore(&chip->reg_lock, flags);
1654 static int snd_ymfpci_set_gpio_out(struct snd_ymfpci *chip, int pin, int enable)
1659 spin_lock_irqsave(&chip->reg_lock, flags);
1660 reg = snd_ymfpci_readw(chip, YDSXGR_GPIOFUNCENABLE);
1663 snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg);
1664 snd_ymfpci_writew(chip, YDSXGR_GPIOOUTCTRL, enable << pin);
1665 snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg | (1 << (pin + 8)));
1666 spin_unlock_irqrestore(&chip->reg_lock, flags);
1675 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1677 ucontrol->value.integer.value[0] = snd_ymfpci_get_gpio_out(chip, pin);
1683 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1686 if (snd_ymfpci_get_gpio_out(chip, pin) != ucontrol->value.integer.value[0]) {
1687 snd_ymfpci_set_gpio_out(chip, pin, !!ucontrol->value.integer.value[0]);
1688 ucontrol->value.integer.value[0] = snd_ymfpci_get_gpio_out(chip, pin);
1720 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1723 ucontrol->value.integer.value[0] = chip->pcm_mixer[subs].left;
1724 ucontrol->value.integer.value[1] = chip->pcm_mixer[subs].right;
1731 struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
1736 if (ucontrol->value.integer.value[0] != chip->pcm_mixer[subs].left ||
1737 ucontrol->value.integer.value[1] != chip->pcm_mixer[subs].right) {
1738 chip->pcm_mixer[subs].left = ucontrol->value.integer.value[0];
1739 chip->pcm_mixer[subs].right = ucontrol->value.integer.value[1];
1740 if (chip->pcm_mixer[subs].left > 0x8000)
1741 chip->pcm_mixer[subs].left = 0x8000;
1742 if (chip->pcm_mixer[subs].right > 0x8000)
1743 chip->pcm_mixer[subs].right = 0x8000;
1746 spin_lock_irqsave(&chip->voice_lock, flags);
1752 spin_unlock_irqrestore(&chip->voice_lock, flags);
1775 struct snd_ymfpci *chip = bus->private_data;
1776 chip->ac97_bus = NULL;
1781 struct snd_ymfpci *chip = ac97->private_data;
1782 chip->ac97 = NULL;
1785 int snd_ymfpci_mixer(struct snd_ymfpci *chip, int rear_switch)
1797 err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus);
1800 chip->ac97_bus->private_free = snd_ymfpci_mixer_free_ac97_bus;
1801 chip->ac97_bus->no_vra = 1; /* YMFPCI doesn't need VRA */
1804 ac97.private_data = chip;
1806 err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97);
1811 snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS,
1815 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_ymfpci_controls[idx], chip));
1819 if (chip->ac97->ext_id & AC97_EI_SDAC) {
1820 kctl = snd_ctl_new1(&snd_ymfpci_dup4ch, chip);
1821 err = snd_ctl_add(chip->card, kctl);
1827 if (snd_BUG_ON(!chip->pcm_spdif))
1829 kctl = snd_ctl_new1(&snd_ymfpci_spdif_default, chip);
1830 err = snd_ctl_add(chip->card, kctl);
1833 kctl->id.device = chip->pcm_spdif->device;
1834 kctl = snd_ctl_new1(&snd_ymfpci_spdif_mask, chip);
1835 err = snd_ctl_add(chip->card, kctl);
1838 kctl->id.device = chip->pcm_spdif->device;
1839 kctl = snd_ctl_new1(&snd_ymfpci_spdif_stream, chip);
1840 err = snd_ctl_add(chip->card, kctl);
1843 kctl->id.device = chip->pcm_spdif->device;
1844 chip->spdif_pcm_ctl = kctl;
1847 if (chip->device_id == PCI_DEVICE_ID_YAMAHA_754) {
1848 kctl = snd_ctl_new1(&snd_ymfpci_drec_source, chip);
1849 err = snd_ctl_add(chip->card, kctl);
1858 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_ymfpci_rear_shared, chip));
1864 substream = chip->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
1866 kctl = snd_ctl_new1(&snd_ymfpci_pcm_volume, chip);
1869 kctl->id.device = chip->pcm->device;
1872 err = snd_ctl_add(chip->card, kctl);
1875 chip->pcm_mixer[idx].left = 0x8000;
1876 chip->pcm_mixer[idx].right = 0x8000;
1877 chip->pcm_mixer[idx].ctl = kctl;
1891 struct snd_ymfpci *chip;
1895 chip = snd_timer_chip(timer);
1896 spin_lock_irqsave(&chip->reg_lock, flags);
1898 chip->timer_ticks = timer->sticks;
1905 chip->timer_ticks = 2;
1908 snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count);
1909 snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03);
1910 spin_unlock_irqrestore(&chip->reg_lock, flags);
1916 struct snd_ymfpci *chip;
1919 chip = snd_timer_chip(timer);
1920 spin_lock_irqsave(&chip->reg_lock, flags);
1921 snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x00);
1922 spin_unlock_irqrestore(&chip->reg_lock, flags);
1943 int snd_ymfpci_timer(struct snd_ymfpci *chip, int device)
1951 tid.card = chip->card->number;
1954 err = snd_timer_new(chip->card, "YMFPCI", &tid, &timer);
1957 timer->private_data = chip;
1960 chip->timer = timer;
1972 struct snd_ymfpci *chip = entry->private_data;
1977 snd_iprintf(buffer, "%04x: %04x\n", i, snd_ymfpci_readl(chip, i));
1980 static int snd_ymfpci_proc_init(struct snd_card *card, struct snd_ymfpci *chip)
1982 return snd_card_ro_proc_new(card, "ymfpci", chip, snd_ymfpci_proc_read);
2007 static void snd_ymfpci_enable_dsp(struct snd_ymfpci *chip)
2009 snd_ymfpci_writel(chip, YDSXGR_CONFIG, 0x00000001);
2012 static void snd_ymfpci_disable_dsp(struct snd_ymfpci *chip)
2017 val = snd_ymfpci_readl(chip, YDSXGR_CONFIG);
2019 snd_ymfpci_writel(chip, YDSXGR_CONFIG, 0x00000000);
2021 val = snd_ymfpci_readl(chip, YDSXGR_STATUS);
2027 static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip)
2032 err = request_firmware(&chip->dsp_microcode, "yamaha/ds1_dsp.fw",
2033 &chip->pci->dev);
2035 if (chip->dsp_microcode->size != YDSXG_DSPLENGTH) {
2036 dev_err(chip->card->dev,
2043 is_1e = chip->device_id == PCI_DEVICE_ID_YAMAHA_724F ||
2044 chip->device_id == PCI_DEVICE_ID_YAMAHA_740C ||
2045 chip->device_id == PCI_DEVICE_ID_YAMAHA_744 ||
2046 chip->device_id == PCI_DEVICE_ID_YAMAHA_754;
2048 err = request_firmware(&chip->controller_microcode, name,
2049 &chip->pci->dev);
2051 if (chip->controller_microcode->size != YDSXG_CTRLLENGTH) {
2052 dev_err(chip->card->dev,
2066 static void snd_ymfpci_download_image(struct snd_ymfpci *chip)
2072 snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0x00000000);
2073 snd_ymfpci_disable_dsp(chip);
2074 snd_ymfpci_writel(chip, YDSXGR_MODE, 0x00010000);
2075 snd_ymfpci_writel(chip, YDSXGR_MODE, 0x00000000);
2076 snd_ymfpci_writel(chip, YDSXGR_MAPOFREC, 0x00000000);
2077 snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT, 0x00000000);
2078 snd_ymfpci_writel(chip, YDSXGR_PLAYCTRLBASE, 0x00000000);
2079 snd_ymfpci_writel(chip, YDSXGR_RECCTRLBASE, 0x00000000);
2080 snd_ymfpci_writel(chip, YDSXGR_EFFCTRLBASE, 0x00000000);
2081 ctrl = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL);
2082 snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, ctrl & ~0x0007);
2085 inst = (const __le32 *)chip->dsp_microcode->data;
2087 snd_ymfpci_writel(chip, YDSXGR_DSPINSTRAM + (i << 2),
2091 inst = (const __le32 *)chip->controller_microcode->data;
2093 snd_ymfpci_writel(chip, YDSXGR_CTRLINSTRAM + (i << 2),
2096 snd_ymfpci_enable_dsp(chip);
2099 static int snd_ymfpci_memalloc(struct snd_ymfpci *chip)
2107 chip->bank_size_playback = snd_ymfpci_readl(chip, YDSXGR_PLAYCTRLSIZE) << 2;
2108 chip->bank_size_capture = snd_ymfpci_readl(chip, YDSXGR_RECCTRLSIZE) << 2;
2109 chip->bank_size_effect = snd_ymfpci_readl(chip, YDSXGR_EFFCTRLSIZE) << 2;
2110 chip->work_size = YDSXG_DEFAULT_WORK_SIZE;
2113 ALIGN(chip->bank_size_playback * 2 * YDSXG_PLAYBACK_VOICES, 0x100) +
2114 ALIGN(chip->bank_size_capture * 2 * YDSXG_CAPTURE_VOICES, 0x100) +
2115 ALIGN(chip->bank_size_effect * 2 * YDSXG_EFFECT_VOICES, 0x100) +
2116 chip->work_size;
2119 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
2120 size, &chip->work_ptr) < 0)
2122 ptr = chip->work_ptr.area;
2123 ptr_addr = chip->work_ptr.addr;
2126 chip->bank_base_playback = ptr;
2127 chip->bank_base_playback_addr = ptr_addr;
2128 chip->ctrl_playback = (__le32 *)ptr;
2129 chip->ctrl_playback[0] = cpu_to_le32(YDSXG_PLAYBACK_VOICES);
2133 chip->voices[voice].number = voice;
2134 chip->voices[voice].bank = (struct snd_ymfpci_playback_bank *)ptr;
2135 chip->voices[voice].bank_addr = ptr_addr;
2137 chip->bank_playback[voice][bank] = (struct snd_ymfpci_playback_bank *)ptr;
2138 ptr += chip->bank_size_playback;
2139 ptr_addr += chip->bank_size_playback;
2144 chip->bank_base_capture = ptr;
2145 chip->bank_base_capture_addr = ptr_addr;
2148 chip->bank_capture[voice][bank] = (struct snd_ymfpci_capture_bank *)ptr;
2149 ptr += chip->bank_size_capture;
2150 ptr_addr += chip->bank_size_capture;
2154 chip->bank_base_effect = ptr;
2155 chip->bank_base_effect_addr = ptr_addr;
2158 chip->bank_effect[voice][bank] = (struct snd_ymfpci_effect_bank *)ptr;
2159 ptr += chip->bank_size_effect;
2160 ptr_addr += chip->bank_size_effect;
2164 chip->work_base = ptr;
2165 chip->work_base_addr = ptr_addr;
2167 snd_BUG_ON(ptr + PAGE_ALIGN(chip->work_size) !=
2168 chip->work_ptr.area + chip->work_ptr.bytes);
2170 snd_ymfpci_writel(chip, YDSXGR_PLAYCTRLBASE, chip->bank_base_playback_addr);
2171 snd_ymfpci_writel(chip, YDSXGR_RECCTRLBASE, chip->bank_base_capture_addr);
2172 snd_ymfpci_writel(chip, YDSXGR_EFFCTRLBASE, chip->bank_base_effect_addr);
2173 snd_ymfpci_writel(chip, YDSXGR_WORKBASE, chip->work_base_addr);
2174 snd_ymfpci_writel(chip, YDSXGR_WORKSIZE, chip->work_size >> 2);
2177 chip->spdif_bits = chip->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF & 0xffff;
2178 snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL, 0);
2179 snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits);
2182 snd_ymfpci_writew(chip, YDSXGR_SPDIFINCTRL, 0);
2186 snd_ymfpci_writel(chip, reg, 0);
2187 snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0x3fff3fff);
2188 snd_ymfpci_writel(chip, YDSXGR_BUF441OUTVOL, 0x3fff3fff);
2189 snd_ymfpci_writel(chip, YDSXGR_ZVOUTVOL, 0x3fff3fff);
2190 snd_ymfpci_writel(chip, YDSXGR_SPDIFOUTVOL, 0x3fff3fff);
2191 snd_ymfpci_writel(chip, YDSXGR_NATIVEADCINVOL, 0x3fff3fff);
2192 snd_ymfpci_writel(chip, YDSXGR_NATIVEDACINVOL, 0x3fff3fff);
2193 snd_ymfpci_writel(chip, YDSXGR_PRIADCLOOPVOL, 0x3fff3fff);
2194 snd_ymfpci_writel(chip, YDSXGR_LEGACYOUTVOL, 0x3fff3fff);
2199 static int snd_ymfpci_free(struct snd_ymfpci *chip)
2203 if (snd_BUG_ON(!chip))
2206 if (chip->res_reg_area) { /* don't touch busy hardware */
2207 snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0);
2208 snd_ymfpci_writel(chip, YDSXGR_BUF441OUTVOL, 0);
2209 snd_ymfpci_writel(chip, YDSXGR_LEGACYOUTVOL, 0);
2210 snd_ymfpci_writel(chip, YDSXGR_STATUS, ~0);
2211 snd_ymfpci_disable_dsp(chip);
2212 snd_ymfpci_writel(chip, YDSXGR_PLAYCTRLBASE, 0);
2213 snd_ymfpci_writel(chip, YDSXGR_RECCTRLBASE, 0);
2214 snd_ymfpci_writel(chip, YDSXGR_EFFCTRLBASE, 0);
2215 snd_ymfpci_writel(chip, YDSXGR_WORKBASE, 0);
2216 snd_ymfpci_writel(chip, YDSXGR_WORKSIZE, 0);
2217 ctrl = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL);
2218 snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, ctrl & ~0x0007);
2221 snd_ymfpci_ac3_done(chip);
2226 * the chip again unless reboot. ACPI bug?
2228 pci_set_power_state(chip->pci, PCI_D3hot);
2232 kfree(chip->saved_regs);
2234 if (chip->irq >= 0)
2235 free_irq(chip->irq, chip);
2236 release_and_free_resource(chip->mpu_res);
2237 release_and_free_resource(chip->fm_res);
2238 snd_ymfpci_free_gameport(chip);
2239 iounmap(chip->reg_area_virt);
2240 if (chip->work_ptr.area)
2241 snd_dma_free_pages(&chip->work_ptr);
2243 release_and_free_resource(chip->res_reg_area);
2245 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl);
2247 pci_disable_device(chip->pci);
2248 release_firmware(chip->dsp_microcode);
2249 release_firmware(chip->controller_microcode);
2250 kfree(chip);
2256 struct snd_ymfpci *chip = device->device_data;
2257 return snd_ymfpci_free(chip);
2293 struct snd_ymfpci *chip = card->private_data;
2297 snd_ac97_suspend(chip->ac97);
2299 chip->saved_regs[i] = snd_ymfpci_readl(chip, saved_regs_index[i]);
2300 chip->saved_ydsxgr_mode = snd_ymfpci_readl(chip, YDSXGR_MODE);
2301 pci_read_config_word(chip->pci, PCIR_DSXG_LEGACY,
2302 &chip->saved_dsxg_legacy);
2303 pci_read_config_word(chip->pci, PCIR_DSXG_ELEGACY,
2304 &chip->saved_dsxg_elegacy);
2305 snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0);
2306 snd_ymfpci_writel(chip, YDSXGR_BUF441OUTVOL, 0);
2307 snd_ymfpci_disable_dsp(chip);
2315 struct snd_ymfpci *chip = card->private_data;
2319 snd_ymfpci_codec_ready(chip, 0);
2320 snd_ymfpci_download_image(chip);
2324 snd_ymfpci_writel(chip, saved_regs_index[i], chip->saved_regs[i]);
2326 snd_ac97_resume(chip->ac97);
2328 pci_write_config_word(chip->pci, PCIR_DSXG_LEGACY,
2329 chip->saved_dsxg_legacy);
2330 pci_write_config_word(chip->pci, PCIR_DSXG_ELEGACY,
2331 chip->saved_dsxg_elegacy);
2334 if (chip->start_count > 0) {
2335 spin_lock_irq(&chip->reg_lock);
2336 snd_ymfpci_writel(chip, YDSXGR_MODE, chip->saved_ydsxgr_mode);
2337 chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT);
2338 spin_unlock_irq(&chip->reg_lock);
2352 struct snd_ymfpci *chip;
2365 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
2366 if (chip == NULL) {
2370 chip->old_legacy_ctrl = old_legacy_ctrl;
2371 spin_lock_init(&chip->reg_lock);
2372 spin_lock_init(&chip->voice_lock);
2373 init_waitqueue_head(&chip->interrupt_sleep);
2374 atomic_set(&chip->interrupt_sleep_count, 0);
2375 chip->card = card;
2376 chip->pci = pci;
2377 chip->irq = -1;
2378 chip->device_id = pci->device;
2379 chip->rev = pci->revision;
2380 chip->reg_area_phys = pci_resource_start(pci, 0);
2381 chip->reg_area_virt = ioremap(chip->reg_area_phys, 0x8000);
2383 chip->src441_used = -1;
2385 chip->res_reg_area = request_mem_region(chip->reg_area_phys, 0x8000, "YMFPCI");
2386 if (!chip->res_reg_area) {
2387 dev_err(chip->card->dev,
2389 chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1);
2394 KBUILD_MODNAME, chip)) {
2395 dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq);
2399 chip->irq = pci->irq;
2400 card->sync_irq = chip->irq;
2403 if (snd_ymfpci_codec_ready(chip, 0) < 0) {
2408 err = snd_ymfpci_request_firmware(chip);
2410 dev_err(chip->card->dev, "firmware request failed: %d\n", err);
2413 snd_ymfpci_download_image(chip);
2417 if (snd_ymfpci_memalloc(chip) < 0) {
2422 err = snd_ymfpci_ac3_init(chip);
2427 chip->saved_regs = kmalloc_array(YDSXGR_NUM_SAVED_REGS, sizeof(u32),
2429 if (chip->saved_regs == NULL) {
2435 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
2439 snd_ymfpci_proc_init(card, chip);
2441 *rchip = chip;
2445 snd_ymfpci_free(chip);