2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
3 * Routines for control of YMF724/740/744/754 chips
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/delay.h>
22 #include <linux/firmware.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/pci.h>
26 #include <linux/sched.h>
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <linux/mutex.h>
31 #include <sound/core.h>
32 #include <sound/control.h>
33 #include <sound/info.h>
34 #include <sound/tlv.h>
35 #include <sound/ymfpci.h>
36 #include <sound/asoundef.h>
37 #include <sound/mpu401.h>
40 #include <asm/byteorder.h>
46 static void snd_ymfpci_irq_wait(struct snd_ymfpci
*chip
);
48 static inline u8
snd_ymfpci_readb(struct snd_ymfpci
*chip
, u32 offset
)
50 return readb(chip
->reg_area_virt
+ offset
);
53 static inline void snd_ymfpci_writeb(struct snd_ymfpci
*chip
, u32 offset
, u8 val
)
55 writeb(val
, chip
->reg_area_virt
+ offset
);
58 static inline u16
snd_ymfpci_readw(struct snd_ymfpci
*chip
, u32 offset
)
60 return readw(chip
->reg_area_virt
+ offset
);
63 static inline void snd_ymfpci_writew(struct snd_ymfpci
*chip
, u32 offset
, u16 val
)
65 writew(val
, chip
->reg_area_virt
+ offset
);
68 static inline u32
snd_ymfpci_readl(struct snd_ymfpci
*chip
, u32 offset
)
70 return readl(chip
->reg_area_virt
+ offset
);
73 static inline void snd_ymfpci_writel(struct snd_ymfpci
*chip
, u32 offset
, u32 val
)
75 writel(val
, chip
->reg_area_virt
+ offset
);
78 static int snd_ymfpci_codec_ready(struct snd_ymfpci
*chip
, int secondary
)
80 unsigned long end_time
;
81 u32 reg
= secondary
? YDSXGR_SECSTATUSADR
: YDSXGR_PRISTATUSADR
;
83 end_time
= jiffies
+ msecs_to_jiffies(750);
85 if ((snd_ymfpci_readw(chip
, reg
) & 0x8000) == 0)
87 schedule_timeout_uninterruptible(1);
88 } while (time_before(jiffies
, end_time
));
89 snd_printk(KERN_ERR
"codec_ready: codec %i is not ready [0x%x]\n", secondary
, snd_ymfpci_readw(chip
, reg
));
93 static void snd_ymfpci_codec_write(struct snd_ac97
*ac97
, u16 reg
, u16 val
)
95 struct snd_ymfpci
*chip
= ac97
->private_data
;
98 snd_ymfpci_codec_ready(chip
, 0);
99 cmd
= ((YDSXG_AC97WRITECMD
| reg
) << 16) | val
;
100 snd_ymfpci_writel(chip
, YDSXGR_AC97CMDDATA
, cmd
);
103 static u16
snd_ymfpci_codec_read(struct snd_ac97
*ac97
, u16 reg
)
105 struct snd_ymfpci
*chip
= ac97
->private_data
;
107 if (snd_ymfpci_codec_ready(chip
, 0))
109 snd_ymfpci_writew(chip
, YDSXGR_AC97CMDADR
, YDSXG_AC97READCMD
| reg
);
110 if (snd_ymfpci_codec_ready(chip
, 0))
112 if (chip
->device_id
== PCI_DEVICE_ID_YAMAHA_744
&& chip
->rev
< 2) {
114 for (i
= 0; i
< 600; i
++)
115 snd_ymfpci_readw(chip
, YDSXGR_PRISTATUSDATA
);
117 return snd_ymfpci_readw(chip
, YDSXGR_PRISTATUSDATA
);
124 static u32
snd_ymfpci_calc_delta(u32 rate
)
127 case 8000: return 0x02aaab00;
128 case 11025: return 0x03accd00;
129 case 16000: return 0x05555500;
130 case 22050: return 0x07599a00;
131 case 32000: return 0x0aaaab00;
132 case 44100: return 0x0eb33300;
133 default: return ((rate
<< 16) / 375) << 5;
137 static u32 def_rate
[8] = {
138 100, 2000, 8000, 11025, 16000, 22050, 32000, 48000
141 static u32
snd_ymfpci_calc_lpfK(u32 rate
)
144 static u32 val
[8] = {
145 0x00570000, 0x06AA0000, 0x18B20000, 0x20930000,
146 0x2B9A0000, 0x35A10000, 0x3EAA0000, 0x40000000
150 return 0x40000000; /* FIXME: What's the right value? */
151 for (i
= 0; i
< 8; i
++)
152 if (rate
<= def_rate
[i
])
157 static u32
snd_ymfpci_calc_lpfQ(u32 rate
)
160 static u32 val
[8] = {
161 0x35280000, 0x34A70000, 0x32020000, 0x31770000,
162 0x31390000, 0x31C90000, 0x33D00000, 0x40000000
167 for (i
= 0; i
< 8; i
++)
168 if (rate
<= def_rate
[i
])
174 * Hardware start management
177 static void snd_ymfpci_hw_start(struct snd_ymfpci
*chip
)
181 spin_lock_irqsave(&chip
->reg_lock
, flags
);
182 if (chip
->start_count
++ > 0)
184 snd_ymfpci_writel(chip
, YDSXGR_MODE
,
185 snd_ymfpci_readl(chip
, YDSXGR_MODE
) | 3);
186 chip
->active_bank
= snd_ymfpci_readl(chip
, YDSXGR_CTRLSELECT
) & 1;
188 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
191 static void snd_ymfpci_hw_stop(struct snd_ymfpci
*chip
)
196 spin_lock_irqsave(&chip
->reg_lock
, flags
);
197 if (--chip
->start_count
> 0)
199 snd_ymfpci_writel(chip
, YDSXGR_MODE
,
200 snd_ymfpci_readl(chip
, YDSXGR_MODE
) & ~3);
201 while (timeout
-- > 0) {
202 if ((snd_ymfpci_readl(chip
, YDSXGR_STATUS
) & 2) == 0)
205 if (atomic_read(&chip
->interrupt_sleep_count
)) {
206 atomic_set(&chip
->interrupt_sleep_count
, 0);
207 wake_up(&chip
->interrupt_sleep
);
210 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
214 * Playback voice management
217 static int voice_alloc(struct snd_ymfpci
*chip
,
218 enum snd_ymfpci_voice_type type
, int pair
,
219 struct snd_ymfpci_voice
**rvoice
)
221 struct snd_ymfpci_voice
*voice
, *voice2
;
225 for (idx
= 0; idx
< YDSXG_PLAYBACK_VOICES
; idx
+= pair
? 2 : 1) {
226 voice
= &chip
->voices
[idx
];
227 voice2
= pair
? &chip
->voices
[idx
+1] : NULL
;
228 if (voice
->use
|| (voice2
&& voice2
->use
))
246 snd_ymfpci_hw_start(chip
);
248 snd_ymfpci_hw_start(chip
);
255 static int snd_ymfpci_voice_alloc(struct snd_ymfpci
*chip
,
256 enum snd_ymfpci_voice_type type
, int pair
,
257 struct snd_ymfpci_voice
**rvoice
)
262 if (snd_BUG_ON(!rvoice
))
264 if (snd_BUG_ON(pair
&& type
!= YMFPCI_PCM
))
267 spin_lock_irqsave(&chip
->voice_lock
, flags
);
269 result
= voice_alloc(chip
, type
, pair
, rvoice
);
270 if (result
== 0 || type
!= YMFPCI_PCM
)
272 /* TODO: synth/midi voice deallocation */
275 spin_unlock_irqrestore(&chip
->voice_lock
, flags
);
279 static int snd_ymfpci_voice_free(struct snd_ymfpci
*chip
, struct snd_ymfpci_voice
*pvoice
)
283 if (snd_BUG_ON(!pvoice
))
285 snd_ymfpci_hw_stop(chip
);
286 spin_lock_irqsave(&chip
->voice_lock
, flags
);
287 if (pvoice
->number
== chip
->src441_used
) {
288 chip
->src441_used
= -1;
289 pvoice
->ypcm
->use_441_slot
= 0;
291 pvoice
->use
= pvoice
->pcm
= pvoice
->synth
= pvoice
->midi
= 0;
293 pvoice
->interrupt
= NULL
;
294 spin_unlock_irqrestore(&chip
->voice_lock
, flags
);
302 static void snd_ymfpci_pcm_interrupt(struct snd_ymfpci
*chip
, struct snd_ymfpci_voice
*voice
)
304 struct snd_ymfpci_pcm
*ypcm
;
307 if ((ypcm
= voice
->ypcm
) == NULL
)
309 if (ypcm
->substream
== NULL
)
311 spin_lock(&chip
->reg_lock
);
313 pos
= le32_to_cpu(voice
->bank
[chip
->active_bank
].start
);
314 if (pos
< ypcm
->last_pos
)
315 delta
= pos
+ (ypcm
->buffer_size
- ypcm
->last_pos
);
317 delta
= pos
- ypcm
->last_pos
;
318 ypcm
->period_pos
+= delta
;
319 ypcm
->last_pos
= pos
;
320 if (ypcm
->period_pos
>= ypcm
->period_size
) {
323 "done - active_bank = 0x%x, start = 0x%x\n",
325 voice->bank[chip->active_bank].start);
327 ypcm
->period_pos
%= ypcm
->period_size
;
328 spin_unlock(&chip
->reg_lock
);
329 snd_pcm_period_elapsed(ypcm
->substream
);
330 spin_lock(&chip
->reg_lock
);
333 if (unlikely(ypcm
->update_pcm_vol
)) {
334 unsigned int subs
= ypcm
->substream
->number
;
335 unsigned int next_bank
= 1 - chip
->active_bank
;
336 struct snd_ymfpci_playback_bank
*bank
;
339 bank
= &voice
->bank
[next_bank
];
340 volume
= cpu_to_le32(chip
->pcm_mixer
[subs
].left
<< 15);
341 bank
->left_gain_end
= volume
;
342 if (ypcm
->output_rear
)
343 bank
->eff2_gain_end
= volume
;
345 bank
= &ypcm
->voices
[1]->bank
[next_bank
];
346 volume
= cpu_to_le32(chip
->pcm_mixer
[subs
].right
<< 15);
347 bank
->right_gain_end
= volume
;
348 if (ypcm
->output_rear
)
349 bank
->eff3_gain_end
= volume
;
350 ypcm
->update_pcm_vol
--;
353 spin_unlock(&chip
->reg_lock
);
356 static void snd_ymfpci_pcm_capture_interrupt(struct snd_pcm_substream
*substream
)
358 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
359 struct snd_ymfpci_pcm
*ypcm
= runtime
->private_data
;
360 struct snd_ymfpci
*chip
= ypcm
->chip
;
363 spin_lock(&chip
->reg_lock
);
365 pos
= le32_to_cpu(chip
->bank_capture
[ypcm
->capture_bank_number
][chip
->active_bank
]->start
) >> ypcm
->shift
;
366 if (pos
< ypcm
->last_pos
)
367 delta
= pos
+ (ypcm
->buffer_size
- ypcm
->last_pos
);
369 delta
= pos
- ypcm
->last_pos
;
370 ypcm
->period_pos
+= delta
;
371 ypcm
->last_pos
= pos
;
372 if (ypcm
->period_pos
>= ypcm
->period_size
) {
373 ypcm
->period_pos
%= ypcm
->period_size
;
376 "done - active_bank = 0x%x, start = 0x%x\n",
378 voice->bank[chip->active_bank].start);
380 spin_unlock(&chip
->reg_lock
);
381 snd_pcm_period_elapsed(substream
);
382 spin_lock(&chip
->reg_lock
);
385 spin_unlock(&chip
->reg_lock
);
388 static int snd_ymfpci_playback_trigger(struct snd_pcm_substream
*substream
,
391 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
392 struct snd_ymfpci_pcm
*ypcm
= substream
->runtime
->private_data
;
393 struct snd_kcontrol
*kctl
= NULL
;
396 spin_lock(&chip
->reg_lock
);
397 if (ypcm
->voices
[0] == NULL
) {
402 case SNDRV_PCM_TRIGGER_START
:
403 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
404 case SNDRV_PCM_TRIGGER_RESUME
:
405 chip
->ctrl_playback
[ypcm
->voices
[0]->number
+ 1] = cpu_to_le32(ypcm
->voices
[0]->bank_addr
);
406 if (ypcm
->voices
[1] != NULL
&& !ypcm
->use_441_slot
)
407 chip
->ctrl_playback
[ypcm
->voices
[1]->number
+ 1] = cpu_to_le32(ypcm
->voices
[1]->bank_addr
);
410 case SNDRV_PCM_TRIGGER_STOP
:
411 if (substream
->pcm
== chip
->pcm
&& !ypcm
->use_441_slot
) {
412 kctl
= chip
->pcm_mixer
[substream
->number
].ctl
;
413 kctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
416 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
417 case SNDRV_PCM_TRIGGER_SUSPEND
:
418 chip
->ctrl_playback
[ypcm
->voices
[0]->number
+ 1] = 0;
419 if (ypcm
->voices
[1] != NULL
&& !ypcm
->use_441_slot
)
420 chip
->ctrl_playback
[ypcm
->voices
[1]->number
+ 1] = 0;
428 spin_unlock(&chip
->reg_lock
);
430 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_INFO
, &kctl
->id
);
433 static int snd_ymfpci_capture_trigger(struct snd_pcm_substream
*substream
,
436 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
437 struct snd_ymfpci_pcm
*ypcm
= substream
->runtime
->private_data
;
441 spin_lock(&chip
->reg_lock
);
443 case SNDRV_PCM_TRIGGER_START
:
444 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
445 case SNDRV_PCM_TRIGGER_RESUME
:
446 tmp
= snd_ymfpci_readl(chip
, YDSXGR_MAPOFREC
) | (1 << ypcm
->capture_bank_number
);
447 snd_ymfpci_writel(chip
, YDSXGR_MAPOFREC
, tmp
);
450 case SNDRV_PCM_TRIGGER_STOP
:
451 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
452 case SNDRV_PCM_TRIGGER_SUSPEND
:
453 tmp
= snd_ymfpci_readl(chip
, YDSXGR_MAPOFREC
) & ~(1 << ypcm
->capture_bank_number
);
454 snd_ymfpci_writel(chip
, YDSXGR_MAPOFREC
, tmp
);
461 spin_unlock(&chip
->reg_lock
);
465 static int snd_ymfpci_pcm_voice_alloc(struct snd_ymfpci_pcm
*ypcm
, int voices
)
469 if (ypcm
->voices
[1] != NULL
&& voices
< 2) {
470 snd_ymfpci_voice_free(ypcm
->chip
, ypcm
->voices
[1]);
471 ypcm
->voices
[1] = NULL
;
473 if (voices
== 1 && ypcm
->voices
[0] != NULL
)
474 return 0; /* already allocated */
475 if (voices
== 2 && ypcm
->voices
[0] != NULL
&& ypcm
->voices
[1] != NULL
)
476 return 0; /* already allocated */
478 if (ypcm
->voices
[0] != NULL
&& ypcm
->voices
[1] == NULL
) {
479 snd_ymfpci_voice_free(ypcm
->chip
, ypcm
->voices
[0]);
480 ypcm
->voices
[0] = NULL
;
483 err
= snd_ymfpci_voice_alloc(ypcm
->chip
, YMFPCI_PCM
, voices
> 1, &ypcm
->voices
[0]);
486 ypcm
->voices
[0]->ypcm
= ypcm
;
487 ypcm
->voices
[0]->interrupt
= snd_ymfpci_pcm_interrupt
;
489 ypcm
->voices
[1] = &ypcm
->chip
->voices
[ypcm
->voices
[0]->number
+ 1];
490 ypcm
->voices
[1]->ypcm
= ypcm
;
495 static void snd_ymfpci_pcm_init_voice(struct snd_ymfpci_pcm
*ypcm
, unsigned int voiceidx
,
496 struct snd_pcm_runtime
*runtime
,
499 struct snd_ymfpci_voice
*voice
= ypcm
->voices
[voiceidx
];
501 u32 delta
= snd_ymfpci_calc_delta(runtime
->rate
);
502 u32 lpfQ
= snd_ymfpci_calc_lpfQ(runtime
->rate
);
503 u32 lpfK
= snd_ymfpci_calc_lpfK(runtime
->rate
);
504 struct snd_ymfpci_playback_bank
*bank
;
506 u32 vol_left
, vol_right
;
507 u8 use_left
, use_right
;
510 if (snd_BUG_ON(!voice
))
512 if (runtime
->channels
== 1) {
516 use_left
= (voiceidx
& 1) == 0;
517 use_right
= !use_left
;
519 if (has_pcm_volume
) {
520 vol_left
= cpu_to_le32(ypcm
->chip
->pcm_mixer
521 [ypcm
->substream
->number
].left
<< 15);
522 vol_right
= cpu_to_le32(ypcm
->chip
->pcm_mixer
523 [ypcm
->substream
->number
].right
<< 15);
525 vol_left
= cpu_to_le32(0x40000000);
526 vol_right
= cpu_to_le32(0x40000000);
528 spin_lock_irqsave(&ypcm
->chip
->voice_lock
, flags
);
529 format
= runtime
->channels
== 2 ? 0x00010000 : 0;
530 if (snd_pcm_format_width(runtime
->format
) == 8)
531 format
|= 0x80000000;
532 else if (ypcm
->chip
->device_id
== PCI_DEVICE_ID_YAMAHA_754
&&
533 runtime
->rate
== 44100 && runtime
->channels
== 2 &&
534 voiceidx
== 0 && (ypcm
->chip
->src441_used
== -1 ||
535 ypcm
->chip
->src441_used
== voice
->number
)) {
536 ypcm
->chip
->src441_used
= voice
->number
;
537 ypcm
->use_441_slot
= 1;
538 format
|= 0x10000000;
540 if (ypcm
->chip
->src441_used
== voice
->number
&&
541 (format
& 0x10000000) == 0) {
542 ypcm
->chip
->src441_used
= -1;
543 ypcm
->use_441_slot
= 0;
545 if (runtime
->channels
== 2 && (voiceidx
& 1) != 0)
547 spin_unlock_irqrestore(&ypcm
->chip
->voice_lock
, flags
);
548 for (nbank
= 0; nbank
< 2; nbank
++) {
549 bank
= &voice
->bank
[nbank
];
550 memset(bank
, 0, sizeof(*bank
));
551 bank
->format
= cpu_to_le32(format
);
552 bank
->base
= cpu_to_le32(runtime
->dma_addr
);
553 bank
->loop_end
= cpu_to_le32(ypcm
->buffer_size
);
554 bank
->lpfQ
= cpu_to_le32(lpfQ
);
556 bank
->delta_end
= cpu_to_le32(delta
);
558 bank
->lpfK_end
= cpu_to_le32(lpfK
);
560 bank
->eg_gain_end
= cpu_to_le32(0x40000000);
562 if (ypcm
->output_front
) {
565 bank
->left_gain_end
= vol_left
;
569 bank
->right_gain_end
= vol_right
;
572 if (ypcm
->output_rear
) {
573 if (!ypcm
->swap_rear
) {
576 bank
->eff2_gain_end
= vol_left
;
580 bank
->eff3_gain_end
= vol_right
;
583 /* The SPDIF out channels seem to be swapped, so we have
584 * to swap them here, too. The rear analog out channels
585 * will be wrong, but otherwise AC3 would not work.
589 bank
->eff3_gain_end
= vol_left
;
593 bank
->eff2_gain_end
= vol_right
;
600 static int __devinit
snd_ymfpci_ac3_init(struct snd_ymfpci
*chip
)
602 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(chip
->pci
),
603 4096, &chip
->ac3_tmp_base
) < 0)
606 chip
->bank_effect
[3][0]->base
=
607 chip
->bank_effect
[3][1]->base
= cpu_to_le32(chip
->ac3_tmp_base
.addr
);
608 chip
->bank_effect
[3][0]->loop_end
=
609 chip
->bank_effect
[3][1]->loop_end
= cpu_to_le32(1024);
610 chip
->bank_effect
[4][0]->base
=
611 chip
->bank_effect
[4][1]->base
= cpu_to_le32(chip
->ac3_tmp_base
.addr
+ 2048);
612 chip
->bank_effect
[4][0]->loop_end
=
613 chip
->bank_effect
[4][1]->loop_end
= cpu_to_le32(1024);
615 spin_lock_irq(&chip
->reg_lock
);
616 snd_ymfpci_writel(chip
, YDSXGR_MAPOFEFFECT
,
617 snd_ymfpci_readl(chip
, YDSXGR_MAPOFEFFECT
) | 3 << 3);
618 spin_unlock_irq(&chip
->reg_lock
);
622 static int snd_ymfpci_ac3_done(struct snd_ymfpci
*chip
)
624 spin_lock_irq(&chip
->reg_lock
);
625 snd_ymfpci_writel(chip
, YDSXGR_MAPOFEFFECT
,
626 snd_ymfpci_readl(chip
, YDSXGR_MAPOFEFFECT
) & ~(3 << 3));
627 spin_unlock_irq(&chip
->reg_lock
);
628 // snd_ymfpci_irq_wait(chip);
629 if (chip
->ac3_tmp_base
.area
) {
630 snd_dma_free_pages(&chip
->ac3_tmp_base
);
631 chip
->ac3_tmp_base
.area
= NULL
;
636 static int snd_ymfpci_playback_hw_params(struct snd_pcm_substream
*substream
,
637 struct snd_pcm_hw_params
*hw_params
)
639 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
640 struct snd_ymfpci_pcm
*ypcm
= runtime
->private_data
;
643 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
645 if ((err
= snd_ymfpci_pcm_voice_alloc(ypcm
, params_channels(hw_params
))) < 0)
650 static int snd_ymfpci_playback_hw_free(struct snd_pcm_substream
*substream
)
652 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
653 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
654 struct snd_ymfpci_pcm
*ypcm
;
656 if (runtime
->private_data
== NULL
)
658 ypcm
= runtime
->private_data
;
660 /* wait, until the PCI operations are not finished */
661 snd_ymfpci_irq_wait(chip
);
662 snd_pcm_lib_free_pages(substream
);
663 if (ypcm
->voices
[1]) {
664 snd_ymfpci_voice_free(chip
, ypcm
->voices
[1]);
665 ypcm
->voices
[1] = NULL
;
667 if (ypcm
->voices
[0]) {
668 snd_ymfpci_voice_free(chip
, ypcm
->voices
[0]);
669 ypcm
->voices
[0] = NULL
;
674 static int snd_ymfpci_playback_prepare(struct snd_pcm_substream
*substream
)
676 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
677 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
678 struct snd_ymfpci_pcm
*ypcm
= runtime
->private_data
;
679 struct snd_kcontrol
*kctl
;
682 ypcm
->period_size
= runtime
->period_size
;
683 ypcm
->buffer_size
= runtime
->buffer_size
;
684 ypcm
->period_pos
= 0;
686 for (nvoice
= 0; nvoice
< runtime
->channels
; nvoice
++)
687 snd_ymfpci_pcm_init_voice(ypcm
, nvoice
, runtime
,
688 substream
->pcm
== chip
->pcm
);
690 if (substream
->pcm
== chip
->pcm
&& !ypcm
->use_441_slot
) {
691 kctl
= chip
->pcm_mixer
[substream
->number
].ctl
;
692 kctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
693 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_INFO
, &kctl
->id
);
698 static int snd_ymfpci_capture_hw_params(struct snd_pcm_substream
*substream
,
699 struct snd_pcm_hw_params
*hw_params
)
701 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
704 static int snd_ymfpci_capture_hw_free(struct snd_pcm_substream
*substream
)
706 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
708 /* wait, until the PCI operations are not finished */
709 snd_ymfpci_irq_wait(chip
);
710 return snd_pcm_lib_free_pages(substream
);
713 static int snd_ymfpci_capture_prepare(struct snd_pcm_substream
*substream
)
715 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
716 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
717 struct snd_ymfpci_pcm
*ypcm
= runtime
->private_data
;
718 struct snd_ymfpci_capture_bank
* bank
;
722 ypcm
->period_size
= runtime
->period_size
;
723 ypcm
->buffer_size
= runtime
->buffer_size
;
724 ypcm
->period_pos
= 0;
727 rate
= ((48000 * 4096) / runtime
->rate
) - 1;
729 if (runtime
->channels
== 2) {
733 if (snd_pcm_format_width(runtime
->format
) == 8)
737 switch (ypcm
->capture_bank_number
) {
739 snd_ymfpci_writel(chip
, YDSXGR_RECFORMAT
, format
);
740 snd_ymfpci_writel(chip
, YDSXGR_RECSLOTSR
, rate
);
743 snd_ymfpci_writel(chip
, YDSXGR_ADCFORMAT
, format
);
744 snd_ymfpci_writel(chip
, YDSXGR_ADCSLOTSR
, rate
);
747 for (nbank
= 0; nbank
< 2; nbank
++) {
748 bank
= chip
->bank_capture
[ypcm
->capture_bank_number
][nbank
];
749 bank
->base
= cpu_to_le32(runtime
->dma_addr
);
750 bank
->loop_end
= cpu_to_le32(ypcm
->buffer_size
<< ypcm
->shift
);
752 bank
->num_of_loops
= 0;
757 static snd_pcm_uframes_t
snd_ymfpci_playback_pointer(struct snd_pcm_substream
*substream
)
759 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
760 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
761 struct snd_ymfpci_pcm
*ypcm
= runtime
->private_data
;
762 struct snd_ymfpci_voice
*voice
= ypcm
->voices
[0];
764 if (!(ypcm
->running
&& voice
))
766 return le32_to_cpu(voice
->bank
[chip
->active_bank
].start
);
769 static snd_pcm_uframes_t
snd_ymfpci_capture_pointer(struct snd_pcm_substream
*substream
)
771 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
772 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
773 struct snd_ymfpci_pcm
*ypcm
= runtime
->private_data
;
777 return le32_to_cpu(chip
->bank_capture
[ypcm
->capture_bank_number
][chip
->active_bank
]->start
) >> ypcm
->shift
;
780 static void snd_ymfpci_irq_wait(struct snd_ymfpci
*chip
)
785 while (loops
-- > 0) {
786 if ((snd_ymfpci_readl(chip
, YDSXGR_MODE
) & 3) == 0)
788 init_waitqueue_entry(&wait
, current
);
789 add_wait_queue(&chip
->interrupt_sleep
, &wait
);
790 atomic_inc(&chip
->interrupt_sleep_count
);
791 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
792 remove_wait_queue(&chip
->interrupt_sleep
, &wait
);
796 static irqreturn_t
snd_ymfpci_interrupt(int irq
, void *dev_id
)
798 struct snd_ymfpci
*chip
= dev_id
;
799 u32 status
, nvoice
, mode
;
800 struct snd_ymfpci_voice
*voice
;
802 status
= snd_ymfpci_readl(chip
, YDSXGR_STATUS
);
803 if (status
& 0x80000000) {
804 chip
->active_bank
= snd_ymfpci_readl(chip
, YDSXGR_CTRLSELECT
) & 1;
805 spin_lock(&chip
->voice_lock
);
806 for (nvoice
= 0; nvoice
< YDSXG_PLAYBACK_VOICES
; nvoice
++) {
807 voice
= &chip
->voices
[nvoice
];
808 if (voice
->interrupt
)
809 voice
->interrupt(chip
, voice
);
811 for (nvoice
= 0; nvoice
< YDSXG_CAPTURE_VOICES
; nvoice
++) {
812 if (chip
->capture_substream
[nvoice
])
813 snd_ymfpci_pcm_capture_interrupt(chip
->capture_substream
[nvoice
]);
816 for (nvoice
= 0; nvoice
< YDSXG_EFFECT_VOICES
; nvoice
++) {
817 if (chip
->effect_substream
[nvoice
])
818 snd_ymfpci_pcm_effect_interrupt(chip
->effect_substream
[nvoice
]);
821 spin_unlock(&chip
->voice_lock
);
822 spin_lock(&chip
->reg_lock
);
823 snd_ymfpci_writel(chip
, YDSXGR_STATUS
, 0x80000000);
824 mode
= snd_ymfpci_readl(chip
, YDSXGR_MODE
) | 2;
825 snd_ymfpci_writel(chip
, YDSXGR_MODE
, mode
);
826 spin_unlock(&chip
->reg_lock
);
828 if (atomic_read(&chip
->interrupt_sleep_count
)) {
829 atomic_set(&chip
->interrupt_sleep_count
, 0);
830 wake_up(&chip
->interrupt_sleep
);
834 status
= snd_ymfpci_readw(chip
, YDSXGR_INTFLAG
);
837 snd_timer_interrupt(chip
->timer
, chip
->timer_ticks
);
839 snd_ymfpci_writew(chip
, YDSXGR_INTFLAG
, status
);
842 snd_mpu401_uart_interrupt(irq
, chip
->rawmidi
->private_data
);
846 static struct snd_pcm_hardware snd_ymfpci_playback
=
848 .info
= (SNDRV_PCM_INFO_MMAP
|
849 SNDRV_PCM_INFO_MMAP_VALID
|
850 SNDRV_PCM_INFO_INTERLEAVED
|
851 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
852 SNDRV_PCM_INFO_PAUSE
|
853 SNDRV_PCM_INFO_RESUME
),
854 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
855 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
860 .buffer_bytes_max
= 256 * 1024, /* FIXME: enough? */
861 .period_bytes_min
= 64,
862 .period_bytes_max
= 256 * 1024, /* FIXME: enough? */
868 static struct snd_pcm_hardware snd_ymfpci_capture
=
870 .info
= (SNDRV_PCM_INFO_MMAP
|
871 SNDRV_PCM_INFO_MMAP_VALID
|
872 SNDRV_PCM_INFO_INTERLEAVED
|
873 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
874 SNDRV_PCM_INFO_PAUSE
|
875 SNDRV_PCM_INFO_RESUME
),
876 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
877 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
882 .buffer_bytes_max
= 256 * 1024, /* FIXME: enough? */
883 .period_bytes_min
= 64,
884 .period_bytes_max
= 256 * 1024, /* FIXME: enough? */
890 static void snd_ymfpci_pcm_free_substream(struct snd_pcm_runtime
*runtime
)
892 kfree(runtime
->private_data
);
895 static int snd_ymfpci_playback_open_1(struct snd_pcm_substream
*substream
)
897 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
898 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
899 struct snd_ymfpci_pcm
*ypcm
;
902 runtime
->hw
= snd_ymfpci_playback
;
903 /* FIXME? True value is 256/48 = 5.33333 ms */
904 err
= snd_pcm_hw_constraint_minmax(runtime
,
905 SNDRV_PCM_HW_PARAM_PERIOD_TIME
,
909 err
= snd_pcm_hw_rule_noresample(runtime
, 48000);
913 ypcm
= kzalloc(sizeof(*ypcm
), GFP_KERNEL
);
917 ypcm
->type
= PLAYBACK_VOICE
;
918 ypcm
->substream
= substream
;
919 runtime
->private_data
= ypcm
;
920 runtime
->private_free
= snd_ymfpci_pcm_free_substream
;
924 /* call with spinlock held */
925 static void ymfpci_open_extension(struct snd_ymfpci
*chip
)
927 if (! chip
->rear_opened
) {
928 if (! chip
->spdif_opened
) /* set AC3 */
929 snd_ymfpci_writel(chip
, YDSXGR_MODE
,
930 snd_ymfpci_readl(chip
, YDSXGR_MODE
) | (1 << 30));
931 /* enable second codec (4CHEN) */
932 snd_ymfpci_writew(chip
, YDSXGR_SECCONFIG
,
933 (snd_ymfpci_readw(chip
, YDSXGR_SECCONFIG
) & ~0x0330) | 0x0010);
937 /* call with spinlock held */
938 static void ymfpci_close_extension(struct snd_ymfpci
*chip
)
940 if (! chip
->rear_opened
) {
941 if (! chip
->spdif_opened
)
942 snd_ymfpci_writel(chip
, YDSXGR_MODE
,
943 snd_ymfpci_readl(chip
, YDSXGR_MODE
) & ~(1 << 30));
944 snd_ymfpci_writew(chip
, YDSXGR_SECCONFIG
,
945 (snd_ymfpci_readw(chip
, YDSXGR_SECCONFIG
) & ~0x0330) & ~0x0010);
949 static int snd_ymfpci_playback_open(struct snd_pcm_substream
*substream
)
951 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
952 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
953 struct snd_ymfpci_pcm
*ypcm
;
956 if ((err
= snd_ymfpci_playback_open_1(substream
)) < 0)
958 ypcm
= runtime
->private_data
;
959 ypcm
->output_front
= 1;
960 ypcm
->output_rear
= chip
->mode_dup4ch
? 1 : 0;
962 spin_lock_irq(&chip
->reg_lock
);
963 if (ypcm
->output_rear
) {
964 ymfpci_open_extension(chip
);
967 spin_unlock_irq(&chip
->reg_lock
);
971 static int snd_ymfpci_playback_spdif_open(struct snd_pcm_substream
*substream
)
973 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
974 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
975 struct snd_ymfpci_pcm
*ypcm
;
978 if ((err
= snd_ymfpci_playback_open_1(substream
)) < 0)
980 ypcm
= runtime
->private_data
;
981 ypcm
->output_front
= 0;
982 ypcm
->output_rear
= 1;
984 spin_lock_irq(&chip
->reg_lock
);
985 snd_ymfpci_writew(chip
, YDSXGR_SPDIFOUTCTRL
,
986 snd_ymfpci_readw(chip
, YDSXGR_SPDIFOUTCTRL
) | 2);
987 ymfpci_open_extension(chip
);
988 chip
->spdif_pcm_bits
= chip
->spdif_bits
;
989 snd_ymfpci_writew(chip
, YDSXGR_SPDIFOUTSTATUS
, chip
->spdif_pcm_bits
);
990 chip
->spdif_opened
++;
991 spin_unlock_irq(&chip
->reg_lock
);
993 chip
->spdif_pcm_ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
994 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
995 SNDRV_CTL_EVENT_MASK_INFO
, &chip
->spdif_pcm_ctl
->id
);
999 static int snd_ymfpci_playback_4ch_open(struct snd_pcm_substream
*substream
)
1001 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
1002 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1003 struct snd_ymfpci_pcm
*ypcm
;
1006 if ((err
= snd_ymfpci_playback_open_1(substream
)) < 0)
1008 ypcm
= runtime
->private_data
;
1009 ypcm
->output_front
= 0;
1010 ypcm
->output_rear
= 1;
1011 ypcm
->swap_rear
= 0;
1012 spin_lock_irq(&chip
->reg_lock
);
1013 ymfpci_open_extension(chip
);
1014 chip
->rear_opened
++;
1015 spin_unlock_irq(&chip
->reg_lock
);
1019 static int snd_ymfpci_capture_open(struct snd_pcm_substream
*substream
,
1020 u32 capture_bank_number
)
1022 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
1023 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1024 struct snd_ymfpci_pcm
*ypcm
;
1027 runtime
->hw
= snd_ymfpci_capture
;
1028 /* FIXME? True value is 256/48 = 5.33333 ms */
1029 err
= snd_pcm_hw_constraint_minmax(runtime
,
1030 SNDRV_PCM_HW_PARAM_PERIOD_TIME
,
1034 err
= snd_pcm_hw_rule_noresample(runtime
, 48000);
1038 ypcm
= kzalloc(sizeof(*ypcm
), GFP_KERNEL
);
1042 ypcm
->type
= capture_bank_number
+ CAPTURE_REC
;
1043 ypcm
->substream
= substream
;
1044 ypcm
->capture_bank_number
= capture_bank_number
;
1045 chip
->capture_substream
[capture_bank_number
] = substream
;
1046 runtime
->private_data
= ypcm
;
1047 runtime
->private_free
= snd_ymfpci_pcm_free_substream
;
1048 snd_ymfpci_hw_start(chip
);
1052 static int snd_ymfpci_capture_rec_open(struct snd_pcm_substream
*substream
)
1054 return snd_ymfpci_capture_open(substream
, 0);
1057 static int snd_ymfpci_capture_ac97_open(struct snd_pcm_substream
*substream
)
1059 return snd_ymfpci_capture_open(substream
, 1);
1062 static int snd_ymfpci_playback_close_1(struct snd_pcm_substream
*substream
)
1067 static int snd_ymfpci_playback_close(struct snd_pcm_substream
*substream
)
1069 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
1070 struct snd_ymfpci_pcm
*ypcm
= substream
->runtime
->private_data
;
1072 spin_lock_irq(&chip
->reg_lock
);
1073 if (ypcm
->output_rear
&& chip
->rear_opened
> 0) {
1074 chip
->rear_opened
--;
1075 ymfpci_close_extension(chip
);
1077 spin_unlock_irq(&chip
->reg_lock
);
1078 return snd_ymfpci_playback_close_1(substream
);
1081 static int snd_ymfpci_playback_spdif_close(struct snd_pcm_substream
*substream
)
1083 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
1085 spin_lock_irq(&chip
->reg_lock
);
1086 chip
->spdif_opened
= 0;
1087 ymfpci_close_extension(chip
);
1088 snd_ymfpci_writew(chip
, YDSXGR_SPDIFOUTCTRL
,
1089 snd_ymfpci_readw(chip
, YDSXGR_SPDIFOUTCTRL
) & ~2);
1090 snd_ymfpci_writew(chip
, YDSXGR_SPDIFOUTSTATUS
, chip
->spdif_bits
);
1091 spin_unlock_irq(&chip
->reg_lock
);
1092 chip
->spdif_pcm_ctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1093 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1094 SNDRV_CTL_EVENT_MASK_INFO
, &chip
->spdif_pcm_ctl
->id
);
1095 return snd_ymfpci_playback_close_1(substream
);
1098 static int snd_ymfpci_playback_4ch_close(struct snd_pcm_substream
*substream
)
1100 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
1102 spin_lock_irq(&chip
->reg_lock
);
1103 if (chip
->rear_opened
> 0) {
1104 chip
->rear_opened
--;
1105 ymfpci_close_extension(chip
);
1107 spin_unlock_irq(&chip
->reg_lock
);
1108 return snd_ymfpci_playback_close_1(substream
);
1111 static int snd_ymfpci_capture_close(struct snd_pcm_substream
*substream
)
1113 struct snd_ymfpci
*chip
= snd_pcm_substream_chip(substream
);
1114 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1115 struct snd_ymfpci_pcm
*ypcm
= runtime
->private_data
;
1118 chip
->capture_substream
[ypcm
->capture_bank_number
] = NULL
;
1119 snd_ymfpci_hw_stop(chip
);
1124 static struct snd_pcm_ops snd_ymfpci_playback_ops
= {
1125 .open
= snd_ymfpci_playback_open
,
1126 .close
= snd_ymfpci_playback_close
,
1127 .ioctl
= snd_pcm_lib_ioctl
,
1128 .hw_params
= snd_ymfpci_playback_hw_params
,
1129 .hw_free
= snd_ymfpci_playback_hw_free
,
1130 .prepare
= snd_ymfpci_playback_prepare
,
1131 .trigger
= snd_ymfpci_playback_trigger
,
1132 .pointer
= snd_ymfpci_playback_pointer
,
1135 static struct snd_pcm_ops snd_ymfpci_capture_rec_ops
= {
1136 .open
= snd_ymfpci_capture_rec_open
,
1137 .close
= snd_ymfpci_capture_close
,
1138 .ioctl
= snd_pcm_lib_ioctl
,
1139 .hw_params
= snd_ymfpci_capture_hw_params
,
1140 .hw_free
= snd_ymfpci_capture_hw_free
,
1141 .prepare
= snd_ymfpci_capture_prepare
,
1142 .trigger
= snd_ymfpci_capture_trigger
,
1143 .pointer
= snd_ymfpci_capture_pointer
,
1146 int __devinit
snd_ymfpci_pcm(struct snd_ymfpci
*chip
, int device
, struct snd_pcm
** rpcm
)
1148 struct snd_pcm
*pcm
;
1153 if ((err
= snd_pcm_new(chip
->card
, "YMFPCI", device
, 32, 1, &pcm
)) < 0)
1155 pcm
->private_data
= chip
;
1157 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ymfpci_playback_ops
);
1158 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_ymfpci_capture_rec_ops
);
1161 pcm
->info_flags
= 0;
1162 strcpy(pcm
->name
, "YMFPCI");
1165 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1166 snd_dma_pci_data(chip
->pci
), 64*1024, 256*1024);
1173 static struct snd_pcm_ops snd_ymfpci_capture_ac97_ops
= {
1174 .open
= snd_ymfpci_capture_ac97_open
,
1175 .close
= snd_ymfpci_capture_close
,
1176 .ioctl
= snd_pcm_lib_ioctl
,
1177 .hw_params
= snd_ymfpci_capture_hw_params
,
1178 .hw_free
= snd_ymfpci_capture_hw_free
,
1179 .prepare
= snd_ymfpci_capture_prepare
,
1180 .trigger
= snd_ymfpci_capture_trigger
,
1181 .pointer
= snd_ymfpci_capture_pointer
,
1184 int __devinit
snd_ymfpci_pcm2(struct snd_ymfpci
*chip
, int device
, struct snd_pcm
** rpcm
)
1186 struct snd_pcm
*pcm
;
1191 if ((err
= snd_pcm_new(chip
->card
, "YMFPCI - PCM2", device
, 0, 1, &pcm
)) < 0)
1193 pcm
->private_data
= chip
;
1195 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_ymfpci_capture_ac97_ops
);
1198 pcm
->info_flags
= 0;
1199 sprintf(pcm
->name
, "YMFPCI - %s",
1200 chip
->device_id
== PCI_DEVICE_ID_YAMAHA_754
? "Direct Recording" : "AC'97");
1203 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1204 snd_dma_pci_data(chip
->pci
), 64*1024, 256*1024);
1211 static struct snd_pcm_ops snd_ymfpci_playback_spdif_ops
= {
1212 .open
= snd_ymfpci_playback_spdif_open
,
1213 .close
= snd_ymfpci_playback_spdif_close
,
1214 .ioctl
= snd_pcm_lib_ioctl
,
1215 .hw_params
= snd_ymfpci_playback_hw_params
,
1216 .hw_free
= snd_ymfpci_playback_hw_free
,
1217 .prepare
= snd_ymfpci_playback_prepare
,
1218 .trigger
= snd_ymfpci_playback_trigger
,
1219 .pointer
= snd_ymfpci_playback_pointer
,
1222 int __devinit
snd_ymfpci_pcm_spdif(struct snd_ymfpci
*chip
, int device
, struct snd_pcm
** rpcm
)
1224 struct snd_pcm
*pcm
;
1229 if ((err
= snd_pcm_new(chip
->card
, "YMFPCI - IEC958", device
, 1, 0, &pcm
)) < 0)
1231 pcm
->private_data
= chip
;
1233 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ymfpci_playback_spdif_ops
);
1236 pcm
->info_flags
= 0;
1237 strcpy(pcm
->name
, "YMFPCI - IEC958");
1238 chip
->pcm_spdif
= pcm
;
1240 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1241 snd_dma_pci_data(chip
->pci
), 64*1024, 256*1024);
1248 static struct snd_pcm_ops snd_ymfpci_playback_4ch_ops
= {
1249 .open
= snd_ymfpci_playback_4ch_open
,
1250 .close
= snd_ymfpci_playback_4ch_close
,
1251 .ioctl
= snd_pcm_lib_ioctl
,
1252 .hw_params
= snd_ymfpci_playback_hw_params
,
1253 .hw_free
= snd_ymfpci_playback_hw_free
,
1254 .prepare
= snd_ymfpci_playback_prepare
,
1255 .trigger
= snd_ymfpci_playback_trigger
,
1256 .pointer
= snd_ymfpci_playback_pointer
,
1259 int __devinit
snd_ymfpci_pcm_4ch(struct snd_ymfpci
*chip
, int device
, struct snd_pcm
** rpcm
)
1261 struct snd_pcm
*pcm
;
1266 if ((err
= snd_pcm_new(chip
->card
, "YMFPCI - Rear", device
, 1, 0, &pcm
)) < 0)
1268 pcm
->private_data
= chip
;
1270 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ymfpci_playback_4ch_ops
);
1273 pcm
->info_flags
= 0;
1274 strcpy(pcm
->name
, "YMFPCI - Rear PCM");
1275 chip
->pcm_4ch
= pcm
;
1277 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1278 snd_dma_pci_data(chip
->pci
), 64*1024, 256*1024);
1285 static int snd_ymfpci_spdif_default_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1287 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1292 static int snd_ymfpci_spdif_default_get(struct snd_kcontrol
*kcontrol
,
1293 struct snd_ctl_elem_value
*ucontrol
)
1295 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1297 spin_lock_irq(&chip
->reg_lock
);
1298 ucontrol
->value
.iec958
.status
[0] = (chip
->spdif_bits
>> 0) & 0xff;
1299 ucontrol
->value
.iec958
.status
[1] = (chip
->spdif_bits
>> 8) & 0xff;
1300 ucontrol
->value
.iec958
.status
[3] = IEC958_AES3_CON_FS_48000
;
1301 spin_unlock_irq(&chip
->reg_lock
);
1305 static int snd_ymfpci_spdif_default_put(struct snd_kcontrol
*kcontrol
,
1306 struct snd_ctl_elem_value
*ucontrol
)
1308 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1312 val
= ((ucontrol
->value
.iec958
.status
[0] & 0x3e) << 0) |
1313 (ucontrol
->value
.iec958
.status
[1] << 8);
1314 spin_lock_irq(&chip
->reg_lock
);
1315 change
= chip
->spdif_bits
!= val
;
1316 chip
->spdif_bits
= val
;
1317 if ((snd_ymfpci_readw(chip
, YDSXGR_SPDIFOUTCTRL
) & 1) && chip
->pcm_spdif
== NULL
)
1318 snd_ymfpci_writew(chip
, YDSXGR_SPDIFOUTSTATUS
, chip
->spdif_bits
);
1319 spin_unlock_irq(&chip
->reg_lock
);
1323 static struct snd_kcontrol_new snd_ymfpci_spdif_default __devinitdata
=
1325 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1326 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
1327 .info
= snd_ymfpci_spdif_default_info
,
1328 .get
= snd_ymfpci_spdif_default_get
,
1329 .put
= snd_ymfpci_spdif_default_put
1332 static int snd_ymfpci_spdif_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1334 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1339 static int snd_ymfpci_spdif_mask_get(struct snd_kcontrol
*kcontrol
,
1340 struct snd_ctl_elem_value
*ucontrol
)
1342 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1344 spin_lock_irq(&chip
->reg_lock
);
1345 ucontrol
->value
.iec958
.status
[0] = 0x3e;
1346 ucontrol
->value
.iec958
.status
[1] = 0xff;
1347 spin_unlock_irq(&chip
->reg_lock
);
1351 static struct snd_kcontrol_new snd_ymfpci_spdif_mask __devinitdata
=
1353 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1354 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1355 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,CON_MASK
),
1356 .info
= snd_ymfpci_spdif_mask_info
,
1357 .get
= snd_ymfpci_spdif_mask_get
,
1360 static int snd_ymfpci_spdif_stream_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1362 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1367 static int snd_ymfpci_spdif_stream_get(struct snd_kcontrol
*kcontrol
,
1368 struct snd_ctl_elem_value
*ucontrol
)
1370 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1372 spin_lock_irq(&chip
->reg_lock
);
1373 ucontrol
->value
.iec958
.status
[0] = (chip
->spdif_pcm_bits
>> 0) & 0xff;
1374 ucontrol
->value
.iec958
.status
[1] = (chip
->spdif_pcm_bits
>> 8) & 0xff;
1375 ucontrol
->value
.iec958
.status
[3] = IEC958_AES3_CON_FS_48000
;
1376 spin_unlock_irq(&chip
->reg_lock
);
1380 static int snd_ymfpci_spdif_stream_put(struct snd_kcontrol
*kcontrol
,
1381 struct snd_ctl_elem_value
*ucontrol
)
1383 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1387 val
= ((ucontrol
->value
.iec958
.status
[0] & 0x3e) << 0) |
1388 (ucontrol
->value
.iec958
.status
[1] << 8);
1389 spin_lock_irq(&chip
->reg_lock
);
1390 change
= chip
->spdif_pcm_bits
!= val
;
1391 chip
->spdif_pcm_bits
= val
;
1392 if ((snd_ymfpci_readw(chip
, YDSXGR_SPDIFOUTCTRL
) & 2))
1393 snd_ymfpci_writew(chip
, YDSXGR_SPDIFOUTSTATUS
, chip
->spdif_pcm_bits
);
1394 spin_unlock_irq(&chip
->reg_lock
);
1398 static struct snd_kcontrol_new snd_ymfpci_spdif_stream __devinitdata
=
1400 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
1401 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1402 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
1403 .info
= snd_ymfpci_spdif_stream_info
,
1404 .get
= snd_ymfpci_spdif_stream_get
,
1405 .put
= snd_ymfpci_spdif_stream_put
1408 static int snd_ymfpci_drec_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*info
)
1410 static const char *const texts
[3] = {"AC'97", "IEC958", "ZV Port"};
1412 return snd_ctl_enum_info(info
, 1, 3, texts
);
1415 static int snd_ymfpci_drec_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*value
)
1417 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1420 spin_lock_irq(&chip
->reg_lock
);
1421 reg
= snd_ymfpci_readw(chip
, YDSXGR_GLOBALCTRL
);
1422 spin_unlock_irq(&chip
->reg_lock
);
1424 value
->value
.enumerated
.item
[0] = 0;
1426 value
->value
.enumerated
.item
[0] = 1 + ((reg
& 0x200) != 0);
1430 static int snd_ymfpci_drec_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*value
)
1432 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1435 spin_lock_irq(&chip
->reg_lock
);
1436 old_reg
= snd_ymfpci_readw(chip
, YDSXGR_GLOBALCTRL
);
1437 if (value
->value
.enumerated
.item
[0] == 0)
1438 reg
= old_reg
& ~0x100;
1440 reg
= (old_reg
& ~0x300) | 0x100 | ((value
->value
.enumerated
.item
[0] == 2) << 9);
1441 snd_ymfpci_writew(chip
, YDSXGR_GLOBALCTRL
, reg
);
1442 spin_unlock_irq(&chip
->reg_lock
);
1443 return reg
!= old_reg
;
1446 static struct snd_kcontrol_new snd_ymfpci_drec_source __devinitdata
= {
1447 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
1448 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1449 .name
= "Direct Recording Source",
1450 .info
= snd_ymfpci_drec_source_info
,
1451 .get
= snd_ymfpci_drec_source_get
,
1452 .put
= snd_ymfpci_drec_source_put
1459 #define YMFPCI_SINGLE(xname, xindex, reg, shift) \
1460 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1461 .info = snd_ymfpci_info_single, \
1462 .get = snd_ymfpci_get_single, .put = snd_ymfpci_put_single, \
1463 .private_value = ((reg) | ((shift) << 16)) }
1465 #define snd_ymfpci_info_single snd_ctl_boolean_mono_info
1467 static int snd_ymfpci_get_single(struct snd_kcontrol
*kcontrol
,
1468 struct snd_ctl_elem_value
*ucontrol
)
1470 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1471 int reg
= kcontrol
->private_value
& 0xffff;
1472 unsigned int shift
= (kcontrol
->private_value
>> 16) & 0xff;
1473 unsigned int mask
= 1;
1476 case YDSXGR_SPDIFOUTCTRL
: break;
1477 case YDSXGR_SPDIFINCTRL
: break;
1478 default: return -EINVAL
;
1480 ucontrol
->value
.integer
.value
[0] =
1481 (snd_ymfpci_readl(chip
, reg
) >> shift
) & mask
;
1485 static int snd_ymfpci_put_single(struct snd_kcontrol
*kcontrol
,
1486 struct snd_ctl_elem_value
*ucontrol
)
1488 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1489 int reg
= kcontrol
->private_value
& 0xffff;
1490 unsigned int shift
= (kcontrol
->private_value
>> 16) & 0xff;
1491 unsigned int mask
= 1;
1493 unsigned int val
, oval
;
1496 case YDSXGR_SPDIFOUTCTRL
: break;
1497 case YDSXGR_SPDIFINCTRL
: break;
1498 default: return -EINVAL
;
1500 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1502 spin_lock_irq(&chip
->reg_lock
);
1503 oval
= snd_ymfpci_readl(chip
, reg
);
1504 val
= (oval
& ~(mask
<< shift
)) | val
;
1505 change
= val
!= oval
;
1506 snd_ymfpci_writel(chip
, reg
, val
);
1507 spin_unlock_irq(&chip
->reg_lock
);
1511 static const DECLARE_TLV_DB_LINEAR(db_scale_native
, TLV_DB_GAIN_MUTE
, 0);
1513 #define YMFPCI_DOUBLE(xname, xindex, reg) \
1514 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1515 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
1516 .info = snd_ymfpci_info_double, \
1517 .get = snd_ymfpci_get_double, .put = snd_ymfpci_put_double, \
1518 .private_value = reg, \
1519 .tlv = { .p = db_scale_native } }
1521 static int snd_ymfpci_info_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1523 unsigned int reg
= kcontrol
->private_value
;
1525 if (reg
< 0x80 || reg
>= 0xc0)
1527 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1529 uinfo
->value
.integer
.min
= 0;
1530 uinfo
->value
.integer
.max
= 16383;
1534 static int snd_ymfpci_get_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1536 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1537 unsigned int reg
= kcontrol
->private_value
;
1538 unsigned int shift_left
= 0, shift_right
= 16, mask
= 16383;
1541 if (reg
< 0x80 || reg
>= 0xc0)
1543 spin_lock_irq(&chip
->reg_lock
);
1544 val
= snd_ymfpci_readl(chip
, reg
);
1545 spin_unlock_irq(&chip
->reg_lock
);
1546 ucontrol
->value
.integer
.value
[0] = (val
>> shift_left
) & mask
;
1547 ucontrol
->value
.integer
.value
[1] = (val
>> shift_right
) & mask
;
1551 static int snd_ymfpci_put_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1553 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1554 unsigned int reg
= kcontrol
->private_value
;
1555 unsigned int shift_left
= 0, shift_right
= 16, mask
= 16383;
1557 unsigned int val1
, val2
, oval
;
1559 if (reg
< 0x80 || reg
>= 0xc0)
1561 val1
= ucontrol
->value
.integer
.value
[0] & mask
;
1562 val2
= ucontrol
->value
.integer
.value
[1] & mask
;
1563 val1
<<= shift_left
;
1564 val2
<<= shift_right
;
1565 spin_lock_irq(&chip
->reg_lock
);
1566 oval
= snd_ymfpci_readl(chip
, reg
);
1567 val1
= (oval
& ~((mask
<< shift_left
) | (mask
<< shift_right
))) | val1
| val2
;
1568 change
= val1
!= oval
;
1569 snd_ymfpci_writel(chip
, reg
, val1
);
1570 spin_unlock_irq(&chip
->reg_lock
);
1574 static int snd_ymfpci_put_nativedacvol(struct snd_kcontrol
*kcontrol
,
1575 struct snd_ctl_elem_value
*ucontrol
)
1577 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1578 unsigned int reg
= YDSXGR_NATIVEDACOUTVOL
;
1579 unsigned int reg2
= YDSXGR_BUF441OUTVOL
;
1581 unsigned int value
, oval
;
1583 value
= ucontrol
->value
.integer
.value
[0] & 0x3fff;
1584 value
|= (ucontrol
->value
.integer
.value
[1] & 0x3fff) << 16;
1585 spin_lock_irq(&chip
->reg_lock
);
1586 oval
= snd_ymfpci_readl(chip
, reg
);
1587 change
= value
!= oval
;
1588 snd_ymfpci_writel(chip
, reg
, value
);
1589 snd_ymfpci_writel(chip
, reg2
, value
);
1590 spin_unlock_irq(&chip
->reg_lock
);
1597 #define snd_ymfpci_info_dup4ch snd_ctl_boolean_mono_info
1599 static int snd_ymfpci_get_dup4ch(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1601 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1602 ucontrol
->value
.integer
.value
[0] = chip
->mode_dup4ch
;
1606 static int snd_ymfpci_put_dup4ch(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1608 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1610 change
= (ucontrol
->value
.integer
.value
[0] != chip
->mode_dup4ch
);
1612 chip
->mode_dup4ch
= !!ucontrol
->value
.integer
.value
[0];
1617 static struct snd_kcontrol_new snd_ymfpci_controls
[] __devinitdata
= {
1619 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1620 .name
= "Wave Playback Volume",
1621 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1622 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1623 .info
= snd_ymfpci_info_double
,
1624 .get
= snd_ymfpci_get_double
,
1625 .put
= snd_ymfpci_put_nativedacvol
,
1626 .private_value
= YDSXGR_NATIVEDACOUTVOL
,
1627 .tlv
= { .p
= db_scale_native
},
1629 YMFPCI_DOUBLE("Wave Capture Volume", 0, YDSXGR_NATIVEDACLOOPVOL
),
1630 YMFPCI_DOUBLE("Digital Capture Volume", 0, YDSXGR_NATIVEDACINVOL
),
1631 YMFPCI_DOUBLE("Digital Capture Volume", 1, YDSXGR_NATIVEADCINVOL
),
1632 YMFPCI_DOUBLE("ADC Playback Volume", 0, YDSXGR_PRIADCOUTVOL
),
1633 YMFPCI_DOUBLE("ADC Capture Volume", 0, YDSXGR_PRIADCLOOPVOL
),
1634 YMFPCI_DOUBLE("ADC Playback Volume", 1, YDSXGR_SECADCOUTVOL
),
1635 YMFPCI_DOUBLE("ADC Capture Volume", 1, YDSXGR_SECADCLOOPVOL
),
1636 YMFPCI_DOUBLE("FM Legacy Playback Volume", 0, YDSXGR_LEGACYOUTVOL
),
1637 YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK
,VOLUME
), 0, YDSXGR_ZVOUTVOL
),
1638 YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE
,VOLUME
), 0, YDSXGR_ZVLOOPVOL
),
1639 YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK
,VOLUME
), 1, YDSXGR_SPDIFOUTVOL
),
1640 YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,VOLUME
), 1, YDSXGR_SPDIFLOOPVOL
),
1641 YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
), 0, YDSXGR_SPDIFOUTCTRL
, 0),
1642 YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), 0, YDSXGR_SPDIFINCTRL
, 0),
1643 YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("Loop",NONE
,NONE
), 0, YDSXGR_SPDIFINCTRL
, 4),
1645 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1646 .name
= "4ch Duplication",
1647 .info
= snd_ymfpci_info_dup4ch
,
1648 .get
= snd_ymfpci_get_dup4ch
,
1649 .put
= snd_ymfpci_put_dup4ch
,
1658 static int snd_ymfpci_get_gpio_out(struct snd_ymfpci
*chip
, int pin
)
1661 unsigned long flags
;
1663 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1664 reg
= snd_ymfpci_readw(chip
, YDSXGR_GPIOFUNCENABLE
);
1665 reg
&= ~(1 << (pin
+ 8));
1667 snd_ymfpci_writew(chip
, YDSXGR_GPIOFUNCENABLE
, reg
);
1668 /* set the level mode for input line */
1669 mode
= snd_ymfpci_readw(chip
, YDSXGR_GPIOTYPECONFIG
);
1670 mode
&= ~(3 << (pin
* 2));
1671 snd_ymfpci_writew(chip
, YDSXGR_GPIOTYPECONFIG
, mode
);
1672 snd_ymfpci_writew(chip
, YDSXGR_GPIOFUNCENABLE
, reg
| (1 << (pin
+ 8)));
1673 mode
= snd_ymfpci_readw(chip
, YDSXGR_GPIOINSTATUS
);
1674 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1675 return (mode
>> pin
) & 1;
1678 static int snd_ymfpci_set_gpio_out(struct snd_ymfpci
*chip
, int pin
, int enable
)
1681 unsigned long flags
;
1683 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1684 reg
= snd_ymfpci_readw(chip
, YDSXGR_GPIOFUNCENABLE
);
1686 reg
&= ~(1 << (pin
+ 8));
1687 snd_ymfpci_writew(chip
, YDSXGR_GPIOFUNCENABLE
, reg
);
1688 snd_ymfpci_writew(chip
, YDSXGR_GPIOOUTCTRL
, enable
<< pin
);
1689 snd_ymfpci_writew(chip
, YDSXGR_GPIOFUNCENABLE
, reg
| (1 << (pin
+ 8)));
1690 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1695 #define snd_ymfpci_gpio_sw_info snd_ctl_boolean_mono_info
1697 static int snd_ymfpci_gpio_sw_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1699 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1700 int pin
= (int)kcontrol
->private_value
;
1701 ucontrol
->value
.integer
.value
[0] = snd_ymfpci_get_gpio_out(chip
, pin
);
1705 static int snd_ymfpci_gpio_sw_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1707 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1708 int pin
= (int)kcontrol
->private_value
;
1710 if (snd_ymfpci_get_gpio_out(chip
, pin
) != ucontrol
->value
.integer
.value
[0]) {
1711 snd_ymfpci_set_gpio_out(chip
, pin
, !!ucontrol
->value
.integer
.value
[0]);
1712 ucontrol
->value
.integer
.value
[0] = snd_ymfpci_get_gpio_out(chip
, pin
);
1718 static struct snd_kcontrol_new snd_ymfpci_rear_shared __devinitdata
= {
1719 .name
= "Shared Rear/Line-In Switch",
1720 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1721 .info
= snd_ymfpci_gpio_sw_info
,
1722 .get
= snd_ymfpci_gpio_sw_get
,
1723 .put
= snd_ymfpci_gpio_sw_put
,
1731 static int snd_ymfpci_pcm_vol_info(struct snd_kcontrol
*kcontrol
,
1732 struct snd_ctl_elem_info
*uinfo
)
1734 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1736 uinfo
->value
.integer
.min
= 0;
1737 uinfo
->value
.integer
.max
= 0x8000;
1741 static int snd_ymfpci_pcm_vol_get(struct snd_kcontrol
*kcontrol
,
1742 struct snd_ctl_elem_value
*ucontrol
)
1744 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1745 unsigned int subs
= kcontrol
->id
.subdevice
;
1747 ucontrol
->value
.integer
.value
[0] = chip
->pcm_mixer
[subs
].left
;
1748 ucontrol
->value
.integer
.value
[1] = chip
->pcm_mixer
[subs
].right
;
1752 static int snd_ymfpci_pcm_vol_put(struct snd_kcontrol
*kcontrol
,
1753 struct snd_ctl_elem_value
*ucontrol
)
1755 struct snd_ymfpci
*chip
= snd_kcontrol_chip(kcontrol
);
1756 unsigned int subs
= kcontrol
->id
.subdevice
;
1757 struct snd_pcm_substream
*substream
;
1758 unsigned long flags
;
1760 if (ucontrol
->value
.integer
.value
[0] != chip
->pcm_mixer
[subs
].left
||
1761 ucontrol
->value
.integer
.value
[1] != chip
->pcm_mixer
[subs
].right
) {
1762 chip
->pcm_mixer
[subs
].left
= ucontrol
->value
.integer
.value
[0];
1763 chip
->pcm_mixer
[subs
].right
= ucontrol
->value
.integer
.value
[1];
1764 if (chip
->pcm_mixer
[subs
].left
> 0x8000)
1765 chip
->pcm_mixer
[subs
].left
= 0x8000;
1766 if (chip
->pcm_mixer
[subs
].right
> 0x8000)
1767 chip
->pcm_mixer
[subs
].right
= 0x8000;
1769 substream
= (struct snd_pcm_substream
*)kcontrol
->private_value
;
1770 spin_lock_irqsave(&chip
->voice_lock
, flags
);
1771 if (substream
->runtime
&& substream
->runtime
->private_data
) {
1772 struct snd_ymfpci_pcm
*ypcm
= substream
->runtime
->private_data
;
1773 if (!ypcm
->use_441_slot
)
1774 ypcm
->update_pcm_vol
= 2;
1776 spin_unlock_irqrestore(&chip
->voice_lock
, flags
);
1782 static struct snd_kcontrol_new snd_ymfpci_pcm_volume __devinitdata
= {
1783 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1784 .name
= "PCM Playback Volume",
1785 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1786 SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
1787 .info
= snd_ymfpci_pcm_vol_info
,
1788 .get
= snd_ymfpci_pcm_vol_get
,
1789 .put
= snd_ymfpci_pcm_vol_put
,
1797 static void snd_ymfpci_mixer_free_ac97_bus(struct snd_ac97_bus
*bus
)
1799 struct snd_ymfpci
*chip
= bus
->private_data
;
1800 chip
->ac97_bus
= NULL
;
1803 static void snd_ymfpci_mixer_free_ac97(struct snd_ac97
*ac97
)
1805 struct snd_ymfpci
*chip
= ac97
->private_data
;
1809 int __devinit
snd_ymfpci_mixer(struct snd_ymfpci
*chip
, int rear_switch
)
1811 struct snd_ac97_template ac97
;
1812 struct snd_kcontrol
*kctl
;
1813 struct snd_pcm_substream
*substream
;
1816 static struct snd_ac97_bus_ops ops
= {
1817 .write
= snd_ymfpci_codec_write
,
1818 .read
= snd_ymfpci_codec_read
,
1821 if ((err
= snd_ac97_bus(chip
->card
, 0, &ops
, chip
, &chip
->ac97_bus
)) < 0)
1823 chip
->ac97_bus
->private_free
= snd_ymfpci_mixer_free_ac97_bus
;
1824 chip
->ac97_bus
->no_vra
= 1; /* YMFPCI doesn't need VRA */
1826 memset(&ac97
, 0, sizeof(ac97
));
1827 ac97
.private_data
= chip
;
1828 ac97
.private_free
= snd_ymfpci_mixer_free_ac97
;
1829 if ((err
= snd_ac97_mixer(chip
->ac97_bus
, &ac97
, &chip
->ac97
)) < 0)
1833 snd_ac97_update_bits(chip
->ac97
, AC97_EXTENDED_STATUS
,
1834 AC97_EA_VRA
|AC97_EA_VRM
, 0);
1836 for (idx
= 0; idx
< ARRAY_SIZE(snd_ymfpci_controls
); idx
++) {
1837 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_ymfpci_controls
[idx
], chip
))) < 0)
1841 /* add S/PDIF control */
1842 if (snd_BUG_ON(!chip
->pcm_spdif
))
1844 if ((err
= snd_ctl_add(chip
->card
, kctl
= snd_ctl_new1(&snd_ymfpci_spdif_default
, chip
))) < 0)
1846 kctl
->id
.device
= chip
->pcm_spdif
->device
;
1847 if ((err
= snd_ctl_add(chip
->card
, kctl
= snd_ctl_new1(&snd_ymfpci_spdif_mask
, chip
))) < 0)
1849 kctl
->id
.device
= chip
->pcm_spdif
->device
;
1850 if ((err
= snd_ctl_add(chip
->card
, kctl
= snd_ctl_new1(&snd_ymfpci_spdif_stream
, chip
))) < 0)
1852 kctl
->id
.device
= chip
->pcm_spdif
->device
;
1853 chip
->spdif_pcm_ctl
= kctl
;
1855 /* direct recording source */
1856 if (chip
->device_id
== PCI_DEVICE_ID_YAMAHA_754
&&
1857 (err
= snd_ctl_add(chip
->card
, kctl
= snd_ctl_new1(&snd_ymfpci_drec_source
, chip
))) < 0)
1861 * shared rear/line-in
1864 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_ymfpci_rear_shared
, chip
))) < 0)
1868 /* per-voice volume */
1869 substream
= chip
->pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
;
1870 for (idx
= 0; idx
< 32; ++idx
) {
1871 kctl
= snd_ctl_new1(&snd_ymfpci_pcm_volume
, chip
);
1874 kctl
->id
.device
= chip
->pcm
->device
;
1875 kctl
->id
.subdevice
= idx
;
1876 kctl
->private_value
= (unsigned long)substream
;
1877 if ((err
= snd_ctl_add(chip
->card
, kctl
)) < 0)
1879 chip
->pcm_mixer
[idx
].left
= 0x8000;
1880 chip
->pcm_mixer
[idx
].right
= 0x8000;
1881 chip
->pcm_mixer
[idx
].ctl
= kctl
;
1882 substream
= substream
->next
;
1893 static int snd_ymfpci_timer_start(struct snd_timer
*timer
)
1895 struct snd_ymfpci
*chip
;
1896 unsigned long flags
;
1899 chip
= snd_timer_chip(timer
);
1900 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1901 if (timer
->sticks
> 1) {
1902 chip
->timer_ticks
= timer
->sticks
;
1903 count
= timer
->sticks
- 1;
1906 * Divisor 1 is not allowed; fake it by using divisor 2 and
1907 * counting two ticks for each interrupt.
1909 chip
->timer_ticks
= 2;
1912 snd_ymfpci_writew(chip
, YDSXGR_TIMERCOUNT
, count
);
1913 snd_ymfpci_writeb(chip
, YDSXGR_TIMERCTRL
, 0x03);
1914 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1918 static int snd_ymfpci_timer_stop(struct snd_timer
*timer
)
1920 struct snd_ymfpci
*chip
;
1921 unsigned long flags
;
1923 chip
= snd_timer_chip(timer
);
1924 spin_lock_irqsave(&chip
->reg_lock
, flags
);
1925 snd_ymfpci_writeb(chip
, YDSXGR_TIMERCTRL
, 0x00);
1926 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
1930 static int snd_ymfpci_timer_precise_resolution(struct snd_timer
*timer
,
1931 unsigned long *num
, unsigned long *den
)
1938 static struct snd_timer_hardware snd_ymfpci_timer_hw
= {
1939 .flags
= SNDRV_TIMER_HW_AUTO
,
1940 .resolution
= 10417, /* 1 / 96 kHz = 10.41666...us */
1942 .start
= snd_ymfpci_timer_start
,
1943 .stop
= snd_ymfpci_timer_stop
,
1944 .precise_resolution
= snd_ymfpci_timer_precise_resolution
,
1947 int __devinit
snd_ymfpci_timer(struct snd_ymfpci
*chip
, int device
)
1949 struct snd_timer
*timer
= NULL
;
1950 struct snd_timer_id tid
;
1953 tid
.dev_class
= SNDRV_TIMER_CLASS_CARD
;
1954 tid
.dev_sclass
= SNDRV_TIMER_SCLASS_NONE
;
1955 tid
.card
= chip
->card
->number
;
1956 tid
.device
= device
;
1958 if ((err
= snd_timer_new(chip
->card
, "YMFPCI", &tid
, &timer
)) >= 0) {
1959 strcpy(timer
->name
, "YMFPCI timer");
1960 timer
->private_data
= chip
;
1961 timer
->hw
= snd_ymfpci_timer_hw
;
1963 chip
->timer
= timer
;
1972 static void snd_ymfpci_proc_read(struct snd_info_entry
*entry
,
1973 struct snd_info_buffer
*buffer
)
1975 struct snd_ymfpci
*chip
= entry
->private_data
;
1978 snd_iprintf(buffer
, "YMFPCI\n\n");
1979 for (i
= 0; i
<= YDSXGR_WORKBASE
; i
+= 4)
1980 snd_iprintf(buffer
, "%04x: %04x\n", i
, snd_ymfpci_readl(chip
, i
));
1983 static int __devinit
snd_ymfpci_proc_init(struct snd_card
*card
, struct snd_ymfpci
*chip
)
1985 struct snd_info_entry
*entry
;
1987 if (! snd_card_proc_new(card
, "ymfpci", &entry
))
1988 snd_info_set_text_ops(entry
, chip
, snd_ymfpci_proc_read
);
1993 * initialization routines
1996 static void snd_ymfpci_aclink_reset(struct pci_dev
* pci
)
2000 pci_read_config_byte(pci
, PCIR_DSXG_CTRL
, &cmd
);
2001 #if 0 // force to reset
2004 pci_write_config_byte(pci
, PCIR_DSXG_CTRL
, cmd
& 0xfc);
2005 pci_write_config_byte(pci
, PCIR_DSXG_CTRL
, cmd
| 0x03);
2006 pci_write_config_byte(pci
, PCIR_DSXG_CTRL
, cmd
& 0xfc);
2007 pci_write_config_word(pci
, PCIR_DSXG_PWRCTRL1
, 0);
2008 pci_write_config_word(pci
, PCIR_DSXG_PWRCTRL2
, 0);
2014 static void snd_ymfpci_enable_dsp(struct snd_ymfpci
*chip
)
2016 snd_ymfpci_writel(chip
, YDSXGR_CONFIG
, 0x00000001);
2019 static void snd_ymfpci_disable_dsp(struct snd_ymfpci
*chip
)
2024 val
= snd_ymfpci_readl(chip
, YDSXGR_CONFIG
);
2026 snd_ymfpci_writel(chip
, YDSXGR_CONFIG
, 0x00000000);
2027 while (timeout
-- > 0) {
2028 val
= snd_ymfpci_readl(chip
, YDSXGR_STATUS
);
2029 if ((val
& 0x00000002) == 0)
2034 static int snd_ymfpci_request_firmware(struct snd_ymfpci
*chip
)
2039 err
= request_firmware(&chip
->dsp_microcode
, "yamaha/ds1_dsp.fw",
2042 if (chip
->dsp_microcode
->size
!= YDSXG_DSPLENGTH
) {
2043 snd_printk(KERN_ERR
"DSP microcode has wrong size\n");
2049 is_1e
= chip
->device_id
== PCI_DEVICE_ID_YAMAHA_724F
||
2050 chip
->device_id
== PCI_DEVICE_ID_YAMAHA_740C
||
2051 chip
->device_id
== PCI_DEVICE_ID_YAMAHA_744
||
2052 chip
->device_id
== PCI_DEVICE_ID_YAMAHA_754
;
2053 name
= is_1e
? "yamaha/ds1e_ctrl.fw" : "yamaha/ds1_ctrl.fw";
2054 err
= request_firmware(&chip
->controller_microcode
, name
,
2057 if (chip
->controller_microcode
->size
!= YDSXG_CTRLLENGTH
) {
2058 snd_printk(KERN_ERR
"controller microcode"
2059 " has wrong size\n");
2068 MODULE_FIRMWARE("yamaha/ds1_dsp.fw");
2069 MODULE_FIRMWARE("yamaha/ds1_ctrl.fw");
2070 MODULE_FIRMWARE("yamaha/ds1e_ctrl.fw");
2072 static void snd_ymfpci_download_image(struct snd_ymfpci
*chip
)
2078 snd_ymfpci_writel(chip
, YDSXGR_NATIVEDACOUTVOL
, 0x00000000);
2079 snd_ymfpci_disable_dsp(chip
);
2080 snd_ymfpci_writel(chip
, YDSXGR_MODE
, 0x00010000);
2081 snd_ymfpci_writel(chip
, YDSXGR_MODE
, 0x00000000);
2082 snd_ymfpci_writel(chip
, YDSXGR_MAPOFREC
, 0x00000000);
2083 snd_ymfpci_writel(chip
, YDSXGR_MAPOFEFFECT
, 0x00000000);
2084 snd_ymfpci_writel(chip
, YDSXGR_PLAYCTRLBASE
, 0x00000000);
2085 snd_ymfpci_writel(chip
, YDSXGR_RECCTRLBASE
, 0x00000000);
2086 snd_ymfpci_writel(chip
, YDSXGR_EFFCTRLBASE
, 0x00000000);
2087 ctrl
= snd_ymfpci_readw(chip
, YDSXGR_GLOBALCTRL
);
2088 snd_ymfpci_writew(chip
, YDSXGR_GLOBALCTRL
, ctrl
& ~0x0007);
2090 /* setup DSP instruction code */
2091 inst
= (const __le32
*)chip
->dsp_microcode
->data
;
2092 for (i
= 0; i
< YDSXG_DSPLENGTH
/ 4; i
++)
2093 snd_ymfpci_writel(chip
, YDSXGR_DSPINSTRAM
+ (i
<< 2),
2094 le32_to_cpu(inst
[i
]));
2096 /* setup control instruction code */
2097 inst
= (const __le32
*)chip
->controller_microcode
->data
;
2098 for (i
= 0; i
< YDSXG_CTRLLENGTH
/ 4; i
++)
2099 snd_ymfpci_writel(chip
, YDSXGR_CTRLINSTRAM
+ (i
<< 2),
2100 le32_to_cpu(inst
[i
]));
2102 snd_ymfpci_enable_dsp(chip
);
2105 static int __devinit
snd_ymfpci_memalloc(struct snd_ymfpci
*chip
)
2107 long size
, playback_ctrl_size
;
2108 int voice
, bank
, reg
;
2110 dma_addr_t ptr_addr
;
2112 playback_ctrl_size
= 4 + 4 * YDSXG_PLAYBACK_VOICES
;
2113 chip
->bank_size_playback
= snd_ymfpci_readl(chip
, YDSXGR_PLAYCTRLSIZE
) << 2;
2114 chip
->bank_size_capture
= snd_ymfpci_readl(chip
, YDSXGR_RECCTRLSIZE
) << 2;
2115 chip
->bank_size_effect
= snd_ymfpci_readl(chip
, YDSXGR_EFFCTRLSIZE
) << 2;
2116 chip
->work_size
= YDSXG_DEFAULT_WORK_SIZE
;
2118 size
= ALIGN(playback_ctrl_size
, 0x100) +
2119 ALIGN(chip
->bank_size_playback
* 2 * YDSXG_PLAYBACK_VOICES
, 0x100) +
2120 ALIGN(chip
->bank_size_capture
* 2 * YDSXG_CAPTURE_VOICES
, 0x100) +
2121 ALIGN(chip
->bank_size_effect
* 2 * YDSXG_EFFECT_VOICES
, 0x100) +
2123 /* work_ptr must be aligned to 256 bytes, but it's already
2124 covered with the kernel page allocation mechanism */
2125 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(chip
->pci
),
2126 size
, &chip
->work_ptr
) < 0)
2128 ptr
= chip
->work_ptr
.area
;
2129 ptr_addr
= chip
->work_ptr
.addr
;
2130 memset(ptr
, 0, size
); /* for sure */
2132 chip
->bank_base_playback
= ptr
;
2133 chip
->bank_base_playback_addr
= ptr_addr
;
2134 chip
->ctrl_playback
= (u32
*)ptr
;
2135 chip
->ctrl_playback
[0] = cpu_to_le32(YDSXG_PLAYBACK_VOICES
);
2136 ptr
+= ALIGN(playback_ctrl_size
, 0x100);
2137 ptr_addr
+= ALIGN(playback_ctrl_size
, 0x100);
2138 for (voice
= 0; voice
< YDSXG_PLAYBACK_VOICES
; voice
++) {
2139 chip
->voices
[voice
].number
= voice
;
2140 chip
->voices
[voice
].bank
= (struct snd_ymfpci_playback_bank
*)ptr
;
2141 chip
->voices
[voice
].bank_addr
= ptr_addr
;
2142 for (bank
= 0; bank
< 2; bank
++) {
2143 chip
->bank_playback
[voice
][bank
] = (struct snd_ymfpci_playback_bank
*)ptr
;
2144 ptr
+= chip
->bank_size_playback
;
2145 ptr_addr
+= chip
->bank_size_playback
;
2148 ptr
= (char *)ALIGN((unsigned long)ptr
, 0x100);
2149 ptr_addr
= ALIGN(ptr_addr
, 0x100);
2150 chip
->bank_base_capture
= ptr
;
2151 chip
->bank_base_capture_addr
= ptr_addr
;
2152 for (voice
= 0; voice
< YDSXG_CAPTURE_VOICES
; voice
++)
2153 for (bank
= 0; bank
< 2; bank
++) {
2154 chip
->bank_capture
[voice
][bank
] = (struct snd_ymfpci_capture_bank
*)ptr
;
2155 ptr
+= chip
->bank_size_capture
;
2156 ptr_addr
+= chip
->bank_size_capture
;
2158 ptr
= (char *)ALIGN((unsigned long)ptr
, 0x100);
2159 ptr_addr
= ALIGN(ptr_addr
, 0x100);
2160 chip
->bank_base_effect
= ptr
;
2161 chip
->bank_base_effect_addr
= ptr_addr
;
2162 for (voice
= 0; voice
< YDSXG_EFFECT_VOICES
; voice
++)
2163 for (bank
= 0; bank
< 2; bank
++) {
2164 chip
->bank_effect
[voice
][bank
] = (struct snd_ymfpci_effect_bank
*)ptr
;
2165 ptr
+= chip
->bank_size_effect
;
2166 ptr_addr
+= chip
->bank_size_effect
;
2168 ptr
= (char *)ALIGN((unsigned long)ptr
, 0x100);
2169 ptr_addr
= ALIGN(ptr_addr
, 0x100);
2170 chip
->work_base
= ptr
;
2171 chip
->work_base_addr
= ptr_addr
;
2173 snd_BUG_ON(ptr
+ chip
->work_size
!=
2174 chip
->work_ptr
.area
+ chip
->work_ptr
.bytes
);
2176 snd_ymfpci_writel(chip
, YDSXGR_PLAYCTRLBASE
, chip
->bank_base_playback_addr
);
2177 snd_ymfpci_writel(chip
, YDSXGR_RECCTRLBASE
, chip
->bank_base_capture_addr
);
2178 snd_ymfpci_writel(chip
, YDSXGR_EFFCTRLBASE
, chip
->bank_base_effect_addr
);
2179 snd_ymfpci_writel(chip
, YDSXGR_WORKBASE
, chip
->work_base_addr
);
2180 snd_ymfpci_writel(chip
, YDSXGR_WORKSIZE
, chip
->work_size
>> 2);
2182 /* S/PDIF output initialization */
2183 chip
->spdif_bits
= chip
->spdif_pcm_bits
= SNDRV_PCM_DEFAULT_CON_SPDIF
& 0xffff;
2184 snd_ymfpci_writew(chip
, YDSXGR_SPDIFOUTCTRL
, 0);
2185 snd_ymfpci_writew(chip
, YDSXGR_SPDIFOUTSTATUS
, chip
->spdif_bits
);
2187 /* S/PDIF input initialization */
2188 snd_ymfpci_writew(chip
, YDSXGR_SPDIFINCTRL
, 0);
2190 /* digital mixer setup */
2191 for (reg
= 0x80; reg
< 0xc0; reg
+= 4)
2192 snd_ymfpci_writel(chip
, reg
, 0);
2193 snd_ymfpci_writel(chip
, YDSXGR_NATIVEDACOUTVOL
, 0x3fff3fff);
2194 snd_ymfpci_writel(chip
, YDSXGR_BUF441OUTVOL
, 0x3fff3fff);
2195 snd_ymfpci_writel(chip
, YDSXGR_ZVOUTVOL
, 0x3fff3fff);
2196 snd_ymfpci_writel(chip
, YDSXGR_SPDIFOUTVOL
, 0x3fff3fff);
2197 snd_ymfpci_writel(chip
, YDSXGR_NATIVEADCINVOL
, 0x3fff3fff);
2198 snd_ymfpci_writel(chip
, YDSXGR_NATIVEDACINVOL
, 0x3fff3fff);
2199 snd_ymfpci_writel(chip
, YDSXGR_PRIADCLOOPVOL
, 0x3fff3fff);
2200 snd_ymfpci_writel(chip
, YDSXGR_LEGACYOUTVOL
, 0x3fff3fff);
2205 static int snd_ymfpci_free(struct snd_ymfpci
*chip
)
2209 if (snd_BUG_ON(!chip
))
2212 if (chip
->res_reg_area
) { /* don't touch busy hardware */
2213 snd_ymfpci_writel(chip
, YDSXGR_NATIVEDACOUTVOL
, 0);
2214 snd_ymfpci_writel(chip
, YDSXGR_BUF441OUTVOL
, 0);
2215 snd_ymfpci_writel(chip
, YDSXGR_LEGACYOUTVOL
, 0);
2216 snd_ymfpci_writel(chip
, YDSXGR_STATUS
, ~0);
2217 snd_ymfpci_disable_dsp(chip
);
2218 snd_ymfpci_writel(chip
, YDSXGR_PLAYCTRLBASE
, 0);
2219 snd_ymfpci_writel(chip
, YDSXGR_RECCTRLBASE
, 0);
2220 snd_ymfpci_writel(chip
, YDSXGR_EFFCTRLBASE
, 0);
2221 snd_ymfpci_writel(chip
, YDSXGR_WORKBASE
, 0);
2222 snd_ymfpci_writel(chip
, YDSXGR_WORKSIZE
, 0);
2223 ctrl
= snd_ymfpci_readw(chip
, YDSXGR_GLOBALCTRL
);
2224 snd_ymfpci_writew(chip
, YDSXGR_GLOBALCTRL
, ctrl
& ~0x0007);
2227 snd_ymfpci_ac3_done(chip
);
2229 /* Set PCI device to D3 state */
2231 /* FIXME: temporarily disabled, otherwise we cannot fire up
2232 * the chip again unless reboot. ACPI bug?
2234 pci_set_power_state(chip
->pci
, 3);
2238 vfree(chip
->saved_regs
);
2241 free_irq(chip
->irq
, chip
);
2242 release_and_free_resource(chip
->mpu_res
);
2243 release_and_free_resource(chip
->fm_res
);
2244 snd_ymfpci_free_gameport(chip
);
2245 if (chip
->reg_area_virt
)
2246 iounmap(chip
->reg_area_virt
);
2247 if (chip
->work_ptr
.area
)
2248 snd_dma_free_pages(&chip
->work_ptr
);
2250 release_and_free_resource(chip
->res_reg_area
);
2252 pci_write_config_word(chip
->pci
, 0x40, chip
->old_legacy_ctrl
);
2254 pci_disable_device(chip
->pci
);
2255 release_firmware(chip
->dsp_microcode
);
2256 release_firmware(chip
->controller_microcode
);
2261 static int snd_ymfpci_dev_free(struct snd_device
*device
)
2263 struct snd_ymfpci
*chip
= device
->device_data
;
2264 return snd_ymfpci_free(chip
);
2268 static int saved_regs_index
[] = {
2270 YDSXGR_SPDIFOUTCTRL
,
2271 YDSXGR_SPDIFOUTSTATUS
,
2274 YDSXGR_PRIADCLOOPVOL
,
2275 YDSXGR_NATIVEDACINVOL
,
2276 YDSXGR_NATIVEDACOUTVOL
,
2277 YDSXGR_BUF441OUTVOL
,
2278 YDSXGR_NATIVEADCINVOL
,
2279 YDSXGR_SPDIFLOOPVOL
,
2282 YDSXGR_LEGACYOUTVOL
,
2284 YDSXGR_PLAYCTRLBASE
,
2288 /* capture set up */
2295 #define YDSXGR_NUM_SAVED_REGS ARRAY_SIZE(saved_regs_index)
2297 int snd_ymfpci_suspend(struct pci_dev
*pci
, pm_message_t state
)
2299 struct snd_card
*card
= pci_get_drvdata(pci
);
2300 struct snd_ymfpci
*chip
= card
->private_data
;
2303 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
2304 snd_pcm_suspend_all(chip
->pcm
);
2305 snd_pcm_suspend_all(chip
->pcm2
);
2306 snd_pcm_suspend_all(chip
->pcm_spdif
);
2307 snd_pcm_suspend_all(chip
->pcm_4ch
);
2308 snd_ac97_suspend(chip
->ac97
);
2309 for (i
= 0; i
< YDSXGR_NUM_SAVED_REGS
; i
++)
2310 chip
->saved_regs
[i
] = snd_ymfpci_readl(chip
, saved_regs_index
[i
]);
2311 chip
->saved_ydsxgr_mode
= snd_ymfpci_readl(chip
, YDSXGR_MODE
);
2312 snd_ymfpci_writel(chip
, YDSXGR_NATIVEDACOUTVOL
, 0);
2313 snd_ymfpci_writel(chip
, YDSXGR_BUF441OUTVOL
, 0);
2314 snd_ymfpci_disable_dsp(chip
);
2315 pci_disable_device(pci
);
2316 pci_save_state(pci
);
2317 pci_set_power_state(pci
, pci_choose_state(pci
, state
));
2321 int snd_ymfpci_resume(struct pci_dev
*pci
)
2323 struct snd_card
*card
= pci_get_drvdata(pci
);
2324 struct snd_ymfpci
*chip
= card
->private_data
;
2327 pci_set_power_state(pci
, PCI_D0
);
2328 pci_restore_state(pci
);
2329 if (pci_enable_device(pci
) < 0) {
2330 printk(KERN_ERR
"ymfpci: pci_enable_device failed, "
2331 "disabling device\n");
2332 snd_card_disconnect(card
);
2335 pci_set_master(pci
);
2336 snd_ymfpci_aclink_reset(pci
);
2337 snd_ymfpci_codec_ready(chip
, 0);
2338 snd_ymfpci_download_image(chip
);
2341 for (i
= 0; i
< YDSXGR_NUM_SAVED_REGS
; i
++)
2342 snd_ymfpci_writel(chip
, saved_regs_index
[i
], chip
->saved_regs
[i
]);
2344 snd_ac97_resume(chip
->ac97
);
2346 /* start hw again */
2347 if (chip
->start_count
> 0) {
2348 spin_lock_irq(&chip
->reg_lock
);
2349 snd_ymfpci_writel(chip
, YDSXGR_MODE
, chip
->saved_ydsxgr_mode
);
2350 chip
->active_bank
= snd_ymfpci_readl(chip
, YDSXGR_CTRLSELECT
);
2351 spin_unlock_irq(&chip
->reg_lock
);
2353 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
2356 #endif /* CONFIG_PM */
2358 int __devinit
snd_ymfpci_create(struct snd_card
*card
,
2359 struct pci_dev
* pci
,
2360 unsigned short old_legacy_ctrl
,
2361 struct snd_ymfpci
** rchip
)
2363 struct snd_ymfpci
*chip
;
2365 static struct snd_device_ops ops
= {
2366 .dev_free
= snd_ymfpci_dev_free
,
2371 /* enable PCI device */
2372 if ((err
= pci_enable_device(pci
)) < 0)
2375 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
2377 pci_disable_device(pci
);
2380 chip
->old_legacy_ctrl
= old_legacy_ctrl
;
2381 spin_lock_init(&chip
->reg_lock
);
2382 spin_lock_init(&chip
->voice_lock
);
2383 init_waitqueue_head(&chip
->interrupt_sleep
);
2384 atomic_set(&chip
->interrupt_sleep_count
, 0);
2388 chip
->device_id
= pci
->device
;
2389 chip
->rev
= pci
->revision
;
2390 chip
->reg_area_phys
= pci_resource_start(pci
, 0);
2391 chip
->reg_area_virt
= ioremap_nocache(chip
->reg_area_phys
, 0x8000);
2392 pci_set_master(pci
);
2393 chip
->src441_used
= -1;
2395 if ((chip
->res_reg_area
= request_mem_region(chip
->reg_area_phys
, 0x8000, "YMFPCI")) == NULL
) {
2396 snd_printk(KERN_ERR
"unable to grab memory region 0x%lx-0x%lx\n", chip
->reg_area_phys
, chip
->reg_area_phys
+ 0x8000 - 1);
2397 snd_ymfpci_free(chip
);
2400 if (request_irq(pci
->irq
, snd_ymfpci_interrupt
, IRQF_SHARED
,
2401 KBUILD_MODNAME
, chip
)) {
2402 snd_printk(KERN_ERR
"unable to grab IRQ %d\n", pci
->irq
);
2403 snd_ymfpci_free(chip
);
2406 chip
->irq
= pci
->irq
;
2408 snd_ymfpci_aclink_reset(pci
);
2409 if (snd_ymfpci_codec_ready(chip
, 0) < 0) {
2410 snd_ymfpci_free(chip
);
2414 err
= snd_ymfpci_request_firmware(chip
);
2416 snd_printk(KERN_ERR
"firmware request failed: %d\n", err
);
2417 snd_ymfpci_free(chip
);
2420 snd_ymfpci_download_image(chip
);
2422 udelay(100); /* seems we need a delay after downloading image.. */
2424 if (snd_ymfpci_memalloc(chip
) < 0) {
2425 snd_ymfpci_free(chip
);
2429 if ((err
= snd_ymfpci_ac3_init(chip
)) < 0) {
2430 snd_ymfpci_free(chip
);
2435 chip
->saved_regs
= vmalloc(YDSXGR_NUM_SAVED_REGS
* sizeof(u32
));
2436 if (chip
->saved_regs
== NULL
) {
2437 snd_ymfpci_free(chip
);
2442 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
2443 snd_ymfpci_free(chip
);
2447 snd_ymfpci_proc_init(card
, chip
);
2449 snd_card_set_dev(card
, &pci
->dev
);