2 * Driver for SiS7019 Audio Accelerator
4 * Copyright (C) 2004-2007, David Dillow
5 * Written by David Dillow <dave@thedillows.org>
6 * Inspired by the Trident 4D-WaveDX/NX driver.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/init.h>
25 #include <linux/pci.h>
26 #include <linux/time.h>
27 #include <linux/moduleparam.h>
28 #include <linux/interrupt.h>
29 #include <linux/delay.h>
30 #include <sound/core.h>
31 #include <sound/ac97_codec.h>
32 #include <sound/initval.h>
35 MODULE_AUTHOR("David Dillow <dave@thedillows.org>");
36 MODULE_DESCRIPTION("SiS7019");
37 MODULE_LICENSE("GPL");
38 MODULE_SUPPORTED_DEVICE("{{SiS,SiS7019 Audio Accelerator}}");
40 static int index
= SNDRV_DEFAULT_IDX1
; /* Index 0-MAX */
41 static char *id
= SNDRV_DEFAULT_STR1
; /* ID for this card */
42 static int enable
= 1;
43 static int codecs
= 1;
45 module_param(index
, int, 0444);
46 MODULE_PARM_DESC(index
, "Index value for SiS7019 Audio Accelerator.");
47 module_param(id
, charp
, 0444);
48 MODULE_PARM_DESC(id
, "ID string for SiS7019 Audio Accelerator.");
49 module_param(enable
, bool, 0444);
50 MODULE_PARM_DESC(enable
, "Enable SiS7019 Audio Accelerator.");
51 module_param(codecs
, int, 0444);
52 MODULE_PARM_DESC(codecs
, "Set bit to indicate that codec number is expected to be present (default 1)");
54 static struct pci_device_id snd_sis7019_ids
[] = {
55 { PCI_DEVICE(PCI_VENDOR_ID_SI
, 0x7019) },
59 MODULE_DEVICE_TABLE(pci
, snd_sis7019_ids
);
61 /* There are three timing modes for the voices.
63 * For both playback and capture, when the buffer is one or two periods long,
64 * we use the hardware's built-in Mid-Loop Interrupt and End-Loop Interrupt
65 * to let us know when the periods have ended.
67 * When performing playback with more than two periods per buffer, we set
68 * the "Stop Sample Offset" and tell the hardware to interrupt us when we
69 * reach it. We then update the offset and continue on until we are
70 * interrupted for the next period.
72 * Capture channels do not have a SSO, so we allocate a playback channel to
73 * use as a timer for the capture periods. We use the SSO on the playback
74 * channel to clock out virtual periods, and adjust the virtual period length
75 * to maintain synchronization. This algorithm came from the Trident driver.
77 * FIXME: It'd be nice to make use of some of the synth features in the
78 * hardware, but a woeful lack of documentation is a significant roadblock.
82 #define VOICE_IN_USE 1
83 #define VOICE_CAPTURE 2
84 #define VOICE_SSO_TIMING 4
85 #define VOICE_SYNC_TIMING 8
93 struct snd_pcm_substream
*substream
;
95 void __iomem
*ctrl_base
;
96 void __iomem
*wave_base
;
97 void __iomem
*sync_base
;
101 /* We need four pages to store our wave parameters during a suspend. If
102 * we're not doing power management, we still need to allocate a page
103 * for the silence buffer.
106 #define SIS_SUSPEND_PAGES 4
108 #define SIS_SUSPEND_PAGES 1
112 unsigned long ioport
;
113 void __iomem
*ioaddr
;
119 struct snd_card
*card
;
120 struct snd_ac97
*ac97
[3];
122 /* Protect against more than one thread hitting the AC97
123 * registers (in a more polite manner than pounding the hardware
126 struct mutex ac97_mutex
;
128 /* voice_lock protects allocation/freeing of the voice descriptions
130 spinlock_t voice_lock
;
132 struct voice voices
[64];
133 struct voice capture_voice
;
135 /* Allocate pages to store the internal wave state during
136 * suspends. When we're operating, this can be used as a silence
137 * buffer for a timing channel.
139 void *suspend_state
[SIS_SUSPEND_PAGES
];
142 dma_addr_t silence_dma_addr
;
145 /* These values are also used by the module param 'codecs' to indicate
146 * which codecs should be present.
148 #define SIS_PRIMARY_CODEC_PRESENT 0x0001
149 #define SIS_SECONDARY_CODEC_PRESENT 0x0002
150 #define SIS_TERTIARY_CODEC_PRESENT 0x0004
152 /* The HW offset parameters (Loop End, Stop Sample, End Sample) have a
153 * documented range of 8-0xfff8 samples. Given that they are 0-based,
154 * that places our period/buffer range at 9-0xfff9 samples. That makes the
155 * max buffer size 0xfff9 samples * 2 channels * 2 bytes per sample, and
156 * max samples / min samples gives us the max periods in a buffer.
158 * We'll add a constraint upon open that limits the period and buffer sample
159 * size to values that are legal for the hardware.
161 static struct snd_pcm_hardware sis_playback_hw_info
= {
162 .info
= (SNDRV_PCM_INFO_MMAP
|
163 SNDRV_PCM_INFO_MMAP_VALID
|
164 SNDRV_PCM_INFO_INTERLEAVED
|
165 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
166 SNDRV_PCM_INFO_SYNC_START
|
167 SNDRV_PCM_INFO_RESUME
),
168 .formats
= (SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U8
|
169 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
170 .rates
= SNDRV_PCM_RATE_8000_48000
| SNDRV_PCM_RATE_CONTINUOUS
,
175 .buffer_bytes_max
= (0xfff9 * 4),
176 .period_bytes_min
= 9,
177 .period_bytes_max
= (0xfff9 * 4),
179 .periods_max
= (0xfff9 / 9),
182 static struct snd_pcm_hardware sis_capture_hw_info
= {
183 .info
= (SNDRV_PCM_INFO_MMAP
|
184 SNDRV_PCM_INFO_MMAP_VALID
|
185 SNDRV_PCM_INFO_INTERLEAVED
|
186 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
187 SNDRV_PCM_INFO_SYNC_START
|
188 SNDRV_PCM_INFO_RESUME
),
189 .formats
= (SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U8
|
190 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_U16_LE
),
191 .rates
= SNDRV_PCM_RATE_48000
,
196 .buffer_bytes_max
= (0xfff9 * 4),
197 .period_bytes_min
= 9,
198 .period_bytes_max
= (0xfff9 * 4),
200 .periods_max
= (0xfff9 / 9),
203 static void sis_update_sso(struct voice
*voice
, u16 period
)
205 void __iomem
*base
= voice
->ctrl_base
;
207 voice
->sso
+= period
;
208 if (voice
->sso
>= voice
->buffer_size
)
209 voice
->sso
-= voice
->buffer_size
;
211 /* Enforce the documented hardware minimum offset */
215 /* The SSO is in the upper 16 bits of the register. */
216 writew(voice
->sso
& 0xffff, base
+ SIS_PLAY_DMA_SSO_ESO
+ 2);
219 static void sis_update_voice(struct voice
*voice
)
221 if (voice
->flags
& VOICE_SSO_TIMING
) {
222 sis_update_sso(voice
, voice
->period_size
);
223 } else if (voice
->flags
& VOICE_SYNC_TIMING
) {
226 /* If we've not hit the end of the virtual period, update
227 * our records and keep going.
229 if (voice
->vperiod
> voice
->period_size
) {
230 voice
->vperiod
-= voice
->period_size
;
231 if (voice
->vperiod
< voice
->period_size
)
232 sis_update_sso(voice
, voice
->vperiod
);
234 sis_update_sso(voice
, voice
->period_size
);
238 /* Calculate our relative offset between the target and
239 * the actual CSO value. Since we're operating in a loop,
240 * if the value is more than half way around, we can
241 * consider ourselves wrapped.
243 sync
= voice
->sync_cso
;
244 sync
-= readw(voice
->sync_base
+ SIS_CAPTURE_DMA_FORMAT_CSO
);
245 if (sync
> (voice
->sync_buffer_size
/ 2))
246 sync
-= voice
->sync_buffer_size
;
248 /* If sync is positive, then we interrupted too early, and
249 * we'll need to come back in a few samples and try again.
250 * There's a minimum wait, as it takes some time for the DMA
251 * engine to startup, etc...
256 sis_update_sso(voice
, sync
);
260 /* Ok, we interrupted right on time, or (hopefully) just
261 * a bit late. We'll adjst our next waiting period based
262 * on how close we got.
264 * We need to stay just behind the actual channel to ensure
265 * it really is past a period when we get our interrupt --
266 * otherwise we'll fall into the early code above and have
267 * a minimum wait time, which makes us quite late here,
268 * eating into the user's time to refresh the buffer, esp.
269 * if using small periods.
271 * If we're less than 9 samples behind, we're on target.
274 voice
->vperiod
= voice
->sync_period_size
+ 1;
276 voice
->vperiod
= voice
->sync_period_size
- 4;
278 if (voice
->vperiod
< voice
->buffer_size
) {
279 sis_update_sso(voice
, voice
->vperiod
);
282 sis_update_sso(voice
, voice
->period_size
);
284 sync
= voice
->sync_cso
+ voice
->sync_period_size
;
285 if (sync
>= voice
->sync_buffer_size
)
286 sync
-= voice
->sync_buffer_size
;
287 voice
->sync_cso
= sync
;
290 snd_pcm_period_elapsed(voice
->substream
);
293 static void sis_voice_irq(u32 status
, struct voice
*voice
)
301 sis_update_voice(voice
);
306 static irqreturn_t
sis_interrupt(int irq
, void *dev
)
308 struct sis7019
*sis
= dev
;
309 unsigned long io
= sis
->ioport
;
313 /* We only use the DMA interrupts, and we don't enable any other
314 * source of interrupts. But, it is possible to see an interupt
315 * status that didn't actually interrupt us, so eliminate anything
316 * we're not expecting to avoid falsely claiming an IRQ, and an
317 * ensuing endless loop.
319 intr
= inl(io
+ SIS_GISR
);
320 intr
&= SIS_GISR_AUDIO_PLAY_DMA_IRQ_STATUS
|
321 SIS_GISR_AUDIO_RECORD_DMA_IRQ_STATUS
;
326 status
= inl(io
+ SIS_PISR_A
);
328 sis_voice_irq(status
, sis
->voices
);
329 outl(status
, io
+ SIS_PISR_A
);
332 status
= inl(io
+ SIS_PISR_B
);
334 sis_voice_irq(status
, &sis
->voices
[32]);
335 outl(status
, io
+ SIS_PISR_B
);
338 status
= inl(io
+ SIS_RISR
);
340 voice
= &sis
->capture_voice
;
342 snd_pcm_period_elapsed(voice
->substream
);
344 outl(status
, io
+ SIS_RISR
);
347 outl(intr
, io
+ SIS_GISR
);
348 intr
= inl(io
+ SIS_GISR
);
349 intr
&= SIS_GISR_AUDIO_PLAY_DMA_IRQ_STATUS
|
350 SIS_GISR_AUDIO_RECORD_DMA_IRQ_STATUS
;
356 static u32
sis_rate_to_delta(unsigned int rate
)
360 /* This was copied from the trident driver, but it seems its gotten
361 * around a bit... nevertheless, it works well.
363 * We special case 44100 and 8000 since rounding with the equation
364 * does not give us an accurate enough value. For 11025 and 22050
365 * the equation gives us the best answer. All other frequencies will
366 * also use the equation. JDW
370 else if (rate
== 8000)
372 else if (rate
== 48000)
375 delta
= (((rate
<< 12) + 24000) / 48000) & 0x0000ffff;
379 static void __sis_map_silence(struct sis7019
*sis
)
381 /* Helper function: must hold sis->voice_lock on entry */
382 if (!sis
->silence_users
)
383 sis
->silence_dma_addr
= pci_map_single(sis
->pci
,
384 sis
->suspend_state
[0],
385 4096, PCI_DMA_TODEVICE
);
386 sis
->silence_users
++;
389 static void __sis_unmap_silence(struct sis7019
*sis
)
391 /* Helper function: must hold sis->voice_lock on entry */
392 sis
->silence_users
--;
393 if (!sis
->silence_users
)
394 pci_unmap_single(sis
->pci
, sis
->silence_dma_addr
, 4096,
398 static void sis_free_voice(struct sis7019
*sis
, struct voice
*voice
)
402 spin_lock_irqsave(&sis
->voice_lock
, flags
);
404 __sis_unmap_silence(sis
);
405 voice
->timing
->flags
&= ~(VOICE_IN_USE
| VOICE_SSO_TIMING
|
407 voice
->timing
= NULL
;
409 voice
->flags
&= ~(VOICE_IN_USE
| VOICE_SSO_TIMING
| VOICE_SYNC_TIMING
);
410 spin_unlock_irqrestore(&sis
->voice_lock
, flags
);
413 static struct voice
*__sis_alloc_playback_voice(struct sis7019
*sis
)
415 /* Must hold the voice_lock on entry */
419 for (i
= 0; i
< 64; i
++) {
420 voice
= &sis
->voices
[i
];
421 if (voice
->flags
& VOICE_IN_USE
)
423 voice
->flags
|= VOICE_IN_USE
;
432 static struct voice
*sis_alloc_playback_voice(struct sis7019
*sis
)
437 spin_lock_irqsave(&sis
->voice_lock
, flags
);
438 voice
= __sis_alloc_playback_voice(sis
);
439 spin_unlock_irqrestore(&sis
->voice_lock
, flags
);
444 static int sis_alloc_timing_voice(struct snd_pcm_substream
*substream
,
445 struct snd_pcm_hw_params
*hw_params
)
447 struct sis7019
*sis
= snd_pcm_substream_chip(substream
);
448 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
449 struct voice
*voice
= runtime
->private_data
;
450 unsigned int period_size
, buffer_size
;
454 /* If there are one or two periods per buffer, we don't need a
455 * timing voice, as we can use the capture channel's interrupts
456 * to clock out the periods.
458 period_size
= params_period_size(hw_params
);
459 buffer_size
= params_buffer_size(hw_params
);
460 needed
= (period_size
!= buffer_size
&&
461 period_size
!= (buffer_size
/ 2));
463 if (needed
&& !voice
->timing
) {
464 spin_lock_irqsave(&sis
->voice_lock
, flags
);
465 voice
->timing
= __sis_alloc_playback_voice(sis
);
467 __sis_map_silence(sis
);
468 spin_unlock_irqrestore(&sis
->voice_lock
, flags
);
471 voice
->timing
->substream
= substream
;
472 } else if (!needed
&& voice
->timing
) {
473 sis_free_voice(sis
, voice
);
474 voice
->timing
= NULL
;
480 static int sis_playback_open(struct snd_pcm_substream
*substream
)
482 struct sis7019
*sis
= snd_pcm_substream_chip(substream
);
483 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
486 voice
= sis_alloc_playback_voice(sis
);
490 voice
->substream
= substream
;
491 runtime
->private_data
= voice
;
492 runtime
->hw
= sis_playback_hw_info
;
493 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
495 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
497 snd_pcm_set_sync(substream
);
501 static int sis_substream_close(struct snd_pcm_substream
*substream
)
503 struct sis7019
*sis
= snd_pcm_substream_chip(substream
);
504 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
505 struct voice
*voice
= runtime
->private_data
;
507 sis_free_voice(sis
, voice
);
511 static int sis_playback_hw_params(struct snd_pcm_substream
*substream
,
512 struct snd_pcm_hw_params
*hw_params
)
514 return snd_pcm_lib_malloc_pages(substream
,
515 params_buffer_bytes(hw_params
));
518 static int sis_hw_free(struct snd_pcm_substream
*substream
)
520 return snd_pcm_lib_free_pages(substream
);
523 static int sis_pcm_playback_prepare(struct snd_pcm_substream
*substream
)
525 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
526 struct voice
*voice
= runtime
->private_data
;
527 void __iomem
*ctrl_base
= voice
->ctrl_base
;
528 void __iomem
*wave_base
= voice
->wave_base
;
529 u32 format
, dma_addr
, control
, sso_eso
, delta
, reg
;
532 /* We rely on the PCM core to ensure that the parameters for this
533 * substream do not change on us while we're programming the HW.
536 if (snd_pcm_format_width(runtime
->format
) == 8)
537 format
|= SIS_PLAY_DMA_FORMAT_8BIT
;
538 if (!snd_pcm_format_signed(runtime
->format
))
539 format
|= SIS_PLAY_DMA_FORMAT_UNSIGNED
;
540 if (runtime
->channels
== 1)
541 format
|= SIS_PLAY_DMA_FORMAT_MONO
;
543 /* The baseline setup is for a single period per buffer, and
544 * we add bells and whistles as needed from there.
546 dma_addr
= runtime
->dma_addr
;
547 leo
= runtime
->buffer_size
- 1;
548 control
= leo
| SIS_PLAY_DMA_LOOP
| SIS_PLAY_DMA_INTR_AT_LEO
;
551 if (runtime
->period_size
== (runtime
->buffer_size
/ 2)) {
552 control
|= SIS_PLAY_DMA_INTR_AT_MLP
;
553 } else if (runtime
->period_size
!= runtime
->buffer_size
) {
554 voice
->flags
|= VOICE_SSO_TIMING
;
555 voice
->sso
= runtime
->period_size
- 1;
556 voice
->period_size
= runtime
->period_size
;
557 voice
->buffer_size
= runtime
->buffer_size
;
559 control
&= ~SIS_PLAY_DMA_INTR_AT_LEO
;
560 control
|= SIS_PLAY_DMA_INTR_AT_SSO
;
561 sso_eso
|= (runtime
->period_size
- 1) << 16;
564 delta
= sis_rate_to_delta(runtime
->rate
);
566 /* Ok, we're ready to go, set up the channel.
568 writel(format
, ctrl_base
+ SIS_PLAY_DMA_FORMAT_CSO
);
569 writel(dma_addr
, ctrl_base
+ SIS_PLAY_DMA_BASE
);
570 writel(control
, ctrl_base
+ SIS_PLAY_DMA_CONTROL
);
571 writel(sso_eso
, ctrl_base
+ SIS_PLAY_DMA_SSO_ESO
);
573 for (reg
= 0; reg
< SIS_WAVE_SIZE
; reg
+= 4)
574 writel(0, wave_base
+ reg
);
576 writel(SIS_WAVE_GENERAL_WAVE_VOLUME
, wave_base
+ SIS_WAVE_GENERAL
);
577 writel(delta
<< 16, wave_base
+ SIS_WAVE_GENERAL_ARTICULATION
);
578 writel(SIS_WAVE_CHANNEL_CONTROL_FIRST_SAMPLE
|
579 SIS_WAVE_CHANNEL_CONTROL_AMP_ENABLE
|
580 SIS_WAVE_CHANNEL_CONTROL_INTERPOLATE_ENABLE
,
581 wave_base
+ SIS_WAVE_CHANNEL_CONTROL
);
583 /* Force PCI writes to post. */
589 static int sis_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
591 struct sis7019
*sis
= snd_pcm_substream_chip(substream
);
592 unsigned long io
= sis
->ioport
;
593 struct snd_pcm_substream
*s
;
598 u32 play
[2] = { 0, 0 };
600 /* No locks needed, as the PCM core will hold the locks on the
601 * substreams, and the HW will only start/stop the indicated voices
602 * without changing the state of the others.
605 case SNDRV_PCM_TRIGGER_START
:
606 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
607 case SNDRV_PCM_TRIGGER_RESUME
:
610 case SNDRV_PCM_TRIGGER_STOP
:
611 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
612 case SNDRV_PCM_TRIGGER_SUSPEND
:
619 snd_pcm_group_for_each_entry(s
, substream
) {
620 /* Make sure it is for us... */
621 chip
= snd_pcm_substream_chip(s
);
625 voice
= s
->runtime
->private_data
;
626 if (voice
->flags
& VOICE_CAPTURE
) {
627 record
|= 1 << voice
->num
;
628 voice
= voice
->timing
;
631 /* voice could be NULL if this a recording stream, and it
632 * doesn't have an external timing channel.
635 play
[voice
->num
/ 32] |= 1 << (voice
->num
& 0x1f);
637 snd_pcm_trigger_done(s
, substream
);
642 outl(record
, io
+ SIS_RECORD_START_REG
);
644 outl(play
[0], io
+ SIS_PLAY_START_A_REG
);
646 outl(play
[1], io
+ SIS_PLAY_START_B_REG
);
649 outl(record
, io
+ SIS_RECORD_STOP_REG
);
651 outl(play
[0], io
+ SIS_PLAY_STOP_A_REG
);
653 outl(play
[1], io
+ SIS_PLAY_STOP_B_REG
);
658 static snd_pcm_uframes_t
sis_pcm_pointer(struct snd_pcm_substream
*substream
)
660 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
661 struct voice
*voice
= runtime
->private_data
;
664 cso
= readl(voice
->ctrl_base
+ SIS_PLAY_DMA_FORMAT_CSO
);
669 static int sis_capture_open(struct snd_pcm_substream
*substream
)
671 struct sis7019
*sis
= snd_pcm_substream_chip(substream
);
672 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
673 struct voice
*voice
= &sis
->capture_voice
;
676 /* FIXME: The driver only supports recording from one channel
677 * at the moment, but it could support more.
679 spin_lock_irqsave(&sis
->voice_lock
, flags
);
680 if (voice
->flags
& VOICE_IN_USE
)
683 voice
->flags
|= VOICE_IN_USE
;
684 spin_unlock_irqrestore(&sis
->voice_lock
, flags
);
689 voice
->substream
= substream
;
690 runtime
->private_data
= voice
;
691 runtime
->hw
= sis_capture_hw_info
;
692 runtime
->hw
.rates
= sis
->ac97
[0]->rates
[AC97_RATES_ADC
];
693 snd_pcm_limit_hw_rates(runtime
);
694 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
696 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
698 snd_pcm_set_sync(substream
);
702 static int sis_capture_hw_params(struct snd_pcm_substream
*substream
,
703 struct snd_pcm_hw_params
*hw_params
)
705 struct sis7019
*sis
= snd_pcm_substream_chip(substream
);
708 rc
= snd_ac97_set_rate(sis
->ac97
[0], AC97_PCM_LR_ADC_RATE
,
709 params_rate(hw_params
));
713 rc
= snd_pcm_lib_malloc_pages(substream
,
714 params_buffer_bytes(hw_params
));
718 rc
= sis_alloc_timing_voice(substream
, hw_params
);
724 static void sis_prepare_timing_voice(struct voice
*voice
,
725 struct snd_pcm_substream
*substream
)
727 struct sis7019
*sis
= snd_pcm_substream_chip(substream
);
728 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
729 struct voice
*timing
= voice
->timing
;
730 void __iomem
*play_base
= timing
->ctrl_base
;
731 void __iomem
*wave_base
= timing
->wave_base
;
732 u16 buffer_size
, period_size
;
733 u32 format
, control
, sso_eso
, delta
;
734 u32 vperiod
, sso
, reg
;
736 /* Set our initial buffer and period as large as we can given a
737 * single page of silence.
739 buffer_size
= 4096 / runtime
->channels
;
740 buffer_size
/= snd_pcm_format_size(runtime
->format
, 1);
741 period_size
= buffer_size
;
743 /* Initially, we want to interrupt just a bit behind the end of
744 * the period we're clocking out. 10 samples seems to give a good
747 * We want to spread our interrupts throughout the virtual period,
748 * so that we don't end up with two interrupts back to back at the
749 * end -- this helps minimize the effects of any jitter. Adjust our
750 * clocking period size so that the last period is at least a fourth
753 * This is all moot if we don't need to use virtual periods.
755 vperiod
= runtime
->period_size
+ 10;
756 if (vperiod
> period_size
) {
757 u16 tail
= vperiod
% period_size
;
758 u16 quarter_period
= period_size
/ 4;
760 if (tail
&& tail
< quarter_period
) {
761 u16 loops
= vperiod
/ period_size
;
763 tail
= quarter_period
- tail
;
769 sso
= period_size
- 1;
771 /* The initial period will fit inside the buffer, so we
772 * don't need to use virtual periods -- disable them.
774 period_size
= runtime
->period_size
;
779 /* The interrupt handler implements the timing syncronization, so
782 timing
->flags
|= VOICE_SYNC_TIMING
;
783 timing
->sync_base
= voice
->ctrl_base
;
784 timing
->sync_cso
= runtime
->period_size
- 1;
785 timing
->sync_period_size
= runtime
->period_size
;
786 timing
->sync_buffer_size
= runtime
->buffer_size
;
787 timing
->period_size
= period_size
;
788 timing
->buffer_size
= buffer_size
;
790 timing
->vperiod
= vperiod
;
792 /* Using unsigned samples with the all-zero silence buffer
793 * forces the output to the lower rail, killing playback.
794 * So ignore unsigned vs signed -- it doesn't change the timing.
797 if (snd_pcm_format_width(runtime
->format
) == 8)
798 format
= SIS_CAPTURE_DMA_FORMAT_8BIT
;
799 if (runtime
->channels
== 1)
800 format
|= SIS_CAPTURE_DMA_FORMAT_MONO
;
802 control
= timing
->buffer_size
- 1;
803 control
|= SIS_PLAY_DMA_LOOP
| SIS_PLAY_DMA_INTR_AT_SSO
;
804 sso_eso
= timing
->buffer_size
- 1;
805 sso_eso
|= timing
->sso
<< 16;
807 delta
= sis_rate_to_delta(runtime
->rate
);
809 /* We've done the math, now configure the channel.
811 writel(format
, play_base
+ SIS_PLAY_DMA_FORMAT_CSO
);
812 writel(sis
->silence_dma_addr
, play_base
+ SIS_PLAY_DMA_BASE
);
813 writel(control
, play_base
+ SIS_PLAY_DMA_CONTROL
);
814 writel(sso_eso
, play_base
+ SIS_PLAY_DMA_SSO_ESO
);
816 for (reg
= 0; reg
< SIS_WAVE_SIZE
; reg
+= 4)
817 writel(0, wave_base
+ reg
);
819 writel(SIS_WAVE_GENERAL_WAVE_VOLUME
, wave_base
+ SIS_WAVE_GENERAL
);
820 writel(delta
<< 16, wave_base
+ SIS_WAVE_GENERAL_ARTICULATION
);
821 writel(SIS_WAVE_CHANNEL_CONTROL_FIRST_SAMPLE
|
822 SIS_WAVE_CHANNEL_CONTROL_AMP_ENABLE
|
823 SIS_WAVE_CHANNEL_CONTROL_INTERPOLATE_ENABLE
,
824 wave_base
+ SIS_WAVE_CHANNEL_CONTROL
);
827 static int sis_pcm_capture_prepare(struct snd_pcm_substream
*substream
)
829 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
830 struct voice
*voice
= runtime
->private_data
;
831 void __iomem
*rec_base
= voice
->ctrl_base
;
832 u32 format
, dma_addr
, control
;
835 /* We rely on the PCM core to ensure that the parameters for this
836 * substream do not change on us while we're programming the HW.
839 if (snd_pcm_format_width(runtime
->format
) == 8)
840 format
= SIS_CAPTURE_DMA_FORMAT_8BIT
;
841 if (!snd_pcm_format_signed(runtime
->format
))
842 format
|= SIS_CAPTURE_DMA_FORMAT_UNSIGNED
;
843 if (runtime
->channels
== 1)
844 format
|= SIS_CAPTURE_DMA_FORMAT_MONO
;
846 dma_addr
= runtime
->dma_addr
;
847 leo
= runtime
->buffer_size
- 1;
848 control
= leo
| SIS_CAPTURE_DMA_LOOP
;
850 /* If we've got more than two periods per buffer, then we have
851 * use a timing voice to clock out the periods. Otherwise, we can
852 * use the capture channel's interrupts.
855 sis_prepare_timing_voice(voice
, substream
);
857 control
|= SIS_CAPTURE_DMA_INTR_AT_LEO
;
858 if (runtime
->period_size
!= runtime
->buffer_size
)
859 control
|= SIS_CAPTURE_DMA_INTR_AT_MLP
;
862 writel(format
, rec_base
+ SIS_CAPTURE_DMA_FORMAT_CSO
);
863 writel(dma_addr
, rec_base
+ SIS_CAPTURE_DMA_BASE
);
864 writel(control
, rec_base
+ SIS_CAPTURE_DMA_CONTROL
);
866 /* Force the writes to post. */
872 static struct snd_pcm_ops sis_playback_ops
= {
873 .open
= sis_playback_open
,
874 .close
= sis_substream_close
,
875 .ioctl
= snd_pcm_lib_ioctl
,
876 .hw_params
= sis_playback_hw_params
,
877 .hw_free
= sis_hw_free
,
878 .prepare
= sis_pcm_playback_prepare
,
879 .trigger
= sis_pcm_trigger
,
880 .pointer
= sis_pcm_pointer
,
883 static struct snd_pcm_ops sis_capture_ops
= {
884 .open
= sis_capture_open
,
885 .close
= sis_substream_close
,
886 .ioctl
= snd_pcm_lib_ioctl
,
887 .hw_params
= sis_capture_hw_params
,
888 .hw_free
= sis_hw_free
,
889 .prepare
= sis_pcm_capture_prepare
,
890 .trigger
= sis_pcm_trigger
,
891 .pointer
= sis_pcm_pointer
,
894 static int __devinit
sis_pcm_create(struct sis7019
*sis
)
899 /* We have 64 voices, and the driver currently records from
900 * only one channel, though that could change in the future.
902 rc
= snd_pcm_new(sis
->card
, "SiS7019", 0, 64, 1, &pcm
);
906 pcm
->private_data
= sis
;
907 strcpy(pcm
->name
, "SiS7019");
910 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &sis_playback_ops
);
911 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &sis_capture_ops
);
913 /* Try to preallocate some memory, but it's not the end of the
914 * world if this fails.
916 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
917 snd_dma_pci_data(sis
->pci
), 64*1024, 128*1024);
922 static unsigned short sis_ac97_rw(struct sis7019
*sis
, int codec
, u32 cmd
)
924 unsigned long io
= sis
->ioport
;
925 unsigned short val
= 0xffff;
929 static const u16 codec_ready
[3] = {
930 SIS_AC97_STATUS_CODEC_READY
,
931 SIS_AC97_STATUS_CODEC2_READY
,
932 SIS_AC97_STATUS_CODEC3_READY
,
935 rdy
= codec_ready
[codec
];
938 /* Get the AC97 semaphore -- software first, so we don't spin
939 * pounding out IO reads on the hardware semaphore...
941 mutex_lock(&sis
->ac97_mutex
);
944 while ((inw(io
+ SIS_AC97_SEMA
) & SIS_AC97_SEMA_BUSY
) && --count
)
950 /* ... and wait for any outstanding commands to complete ...
954 status
= inw(io
+ SIS_AC97_STATUS
);
955 if ((status
& rdy
) && !(status
& SIS_AC97_STATUS_BUSY
))
964 /* ... before sending our command and waiting for it to finish ...
966 outl(cmd
, io
+ SIS_AC97_CMD
);
970 while ((inw(io
+ SIS_AC97_STATUS
) & SIS_AC97_STATUS_BUSY
) && --count
)
973 /* ... and reading the results (if any).
975 val
= inl(io
+ SIS_AC97_CMD
) >> 16;
978 outl(SIS_AC97_SEMA_RELEASE
, io
+ SIS_AC97_SEMA
);
980 mutex_unlock(&sis
->ac97_mutex
);
983 printk(KERN_ERR
"sis7019: ac97 codec %d timeout cmd 0x%08x\n",
990 static void sis_ac97_write(struct snd_ac97
*ac97
, unsigned short reg
,
993 static const u32 cmd
[3] = {
994 SIS_AC97_CMD_CODEC_WRITE
,
995 SIS_AC97_CMD_CODEC2_WRITE
,
996 SIS_AC97_CMD_CODEC3_WRITE
,
998 sis_ac97_rw(ac97
->private_data
, ac97
->num
,
999 (val
<< 16) | (reg
<< 8) | cmd
[ac97
->num
]);
1002 static unsigned short sis_ac97_read(struct snd_ac97
*ac97
, unsigned short reg
)
1004 static const u32 cmd
[3] = {
1005 SIS_AC97_CMD_CODEC_READ
,
1006 SIS_AC97_CMD_CODEC2_READ
,
1007 SIS_AC97_CMD_CODEC3_READ
,
1009 return sis_ac97_rw(ac97
->private_data
, ac97
->num
,
1010 (reg
<< 8) | cmd
[ac97
->num
]);
1013 static int __devinit
sis_mixer_create(struct sis7019
*sis
)
1015 struct snd_ac97_bus
*bus
;
1016 struct snd_ac97_template ac97
;
1017 static struct snd_ac97_bus_ops ops
= {
1018 .write
= sis_ac97_write
,
1019 .read
= sis_ac97_read
,
1023 memset(&ac97
, 0, sizeof(ac97
));
1024 ac97
.private_data
= sis
;
1026 rc
= snd_ac97_bus(sis
->card
, 0, &ops
, NULL
, &bus
);
1027 if (!rc
&& sis
->codecs_present
& SIS_PRIMARY_CODEC_PRESENT
)
1028 rc
= snd_ac97_mixer(bus
, &ac97
, &sis
->ac97
[0]);
1030 if (!rc
&& (sis
->codecs_present
& SIS_SECONDARY_CODEC_PRESENT
))
1031 rc
= snd_ac97_mixer(bus
, &ac97
, &sis
->ac97
[1]);
1033 if (!rc
&& (sis
->codecs_present
& SIS_TERTIARY_CODEC_PRESENT
))
1034 rc
= snd_ac97_mixer(bus
, &ac97
, &sis
->ac97
[2]);
1036 /* If we return an error here, then snd_card_free() should
1037 * free up any ac97 codecs that got created, as well as the bus.
1042 static void sis_free_suspend(struct sis7019
*sis
)
1046 for (i
= 0; i
< SIS_SUSPEND_PAGES
; i
++)
1047 kfree(sis
->suspend_state
[i
]);
1050 static int sis_chip_free(struct sis7019
*sis
)
1052 /* Reset the chip, and disable all interrputs.
1054 outl(SIS_GCR_SOFTWARE_RESET
, sis
->ioport
+ SIS_GCR
);
1056 outl(0, sis
->ioport
+ SIS_GCR
);
1057 outl(0, sis
->ioport
+ SIS_GIER
);
1059 /* Now, free everything we allocated.
1062 free_irq(sis
->irq
, sis
);
1065 iounmap(sis
->ioaddr
);
1067 pci_release_regions(sis
->pci
);
1068 pci_disable_device(sis
->pci
);
1070 sis_free_suspend(sis
);
1074 static int sis_dev_free(struct snd_device
*dev
)
1076 struct sis7019
*sis
= dev
->device_data
;
1077 return sis_chip_free(sis
);
1080 static int sis_chip_init(struct sis7019
*sis
)
1082 unsigned long io
= sis
->ioport
;
1083 void __iomem
*ioaddr
= sis
->ioaddr
;
1084 unsigned long timeout
;
1089 /* Reset the audio controller
1091 outl(SIS_GCR_SOFTWARE_RESET
, io
+ SIS_GCR
);
1093 outl(0, io
+ SIS_GCR
);
1095 /* Get the AC-link semaphore, and reset the codecs
1098 while ((inw(io
+ SIS_AC97_SEMA
) & SIS_AC97_SEMA_BUSY
) && --count
)
1104 outl(SIS_AC97_CMD_CODEC_COLD_RESET
, io
+ SIS_AC97_CMD
);
1108 while ((inw(io
+ SIS_AC97_STATUS
) & SIS_AC97_STATUS_BUSY
) && --count
)
1111 /* Command complete, we can let go of the semaphore now.
1113 outl(SIS_AC97_SEMA_RELEASE
, io
+ SIS_AC97_SEMA
);
1117 /* Now that we've finished the reset, find out what's attached.
1118 * There are some codec/board combinations that take an extremely
1119 * long time to come up. 350+ ms has been observed in the field,
1120 * so we'll give them up to 500ms.
1122 sis
->codecs_present
= 0;
1123 timeout
= msecs_to_jiffies(500) + jiffies
;
1124 while (time_before_eq(jiffies
, timeout
)) {
1125 status
= inl(io
+ SIS_AC97_STATUS
);
1126 if (status
& SIS_AC97_STATUS_CODEC_READY
)
1127 sis
->codecs_present
|= SIS_PRIMARY_CODEC_PRESENT
;
1128 if (status
& SIS_AC97_STATUS_CODEC2_READY
)
1129 sis
->codecs_present
|= SIS_SECONDARY_CODEC_PRESENT
;
1130 if (status
& SIS_AC97_STATUS_CODEC3_READY
)
1131 sis
->codecs_present
|= SIS_TERTIARY_CODEC_PRESENT
;
1133 if (sis
->codecs_present
== codecs
)
1139 /* All done, check for errors.
1141 if (!sis
->codecs_present
) {
1142 printk(KERN_ERR
"sis7019: could not find any codecs\n");
1146 if (sis
->codecs_present
!= codecs
) {
1147 printk(KERN_WARNING
"sis7019: missing codecs, found %0x, expected %0x\n",
1148 sis
->codecs_present
, codecs
);
1151 /* Let the hardware know that the audio driver is alive,
1152 * and enable PCM slots on the AC-link for L/R playback (3 & 4) and
1153 * record channels. We're going to want to use Variable Rate Audio
1154 * for recording, to avoid needlessly resampling from 48kHZ.
1156 outl(SIS_AC97_CONF_AUDIO_ALIVE
, io
+ SIS_AC97_CONF
);
1157 outl(SIS_AC97_CONF_AUDIO_ALIVE
| SIS_AC97_CONF_PCM_LR_ENABLE
|
1158 SIS_AC97_CONF_PCM_CAP_MIC_ENABLE
|
1159 SIS_AC97_CONF_PCM_CAP_LR_ENABLE
|
1160 SIS_AC97_CONF_CODEC_VRA_ENABLE
, io
+ SIS_AC97_CONF
);
1162 /* All AC97 PCM slots should be sourced from sub-mixer 0.
1164 outl(0, io
+ SIS_AC97_PSR
);
1166 /* There is only one valid DMA setup for a PCI environment.
1168 outl(SIS_DMA_CSR_PCI_SETTINGS
, io
+ SIS_DMA_CSR
);
1170 /* Reset the syncronization groups for all of the channels
1171 * to be asyncronous. If we start doing SPDIF or 5.1 sound, etc.
1172 * we'll need to change how we handle these. Until then, we just
1173 * assign sub-mixer 0 to all playback channels, and avoid any
1174 * attenuation on the audio.
1176 outl(0, io
+ SIS_PLAY_SYNC_GROUP_A
);
1177 outl(0, io
+ SIS_PLAY_SYNC_GROUP_B
);
1178 outl(0, io
+ SIS_PLAY_SYNC_GROUP_C
);
1179 outl(0, io
+ SIS_PLAY_SYNC_GROUP_D
);
1180 outl(0, io
+ SIS_MIXER_SYNC_GROUP
);
1182 for (i
= 0; i
< 64; i
++) {
1183 writel(i
, SIS_MIXER_START_ADDR(ioaddr
, i
));
1184 writel(SIS_MIXER_RIGHT_NO_ATTEN
| SIS_MIXER_LEFT_NO_ATTEN
|
1185 SIS_MIXER_DEST_0
, SIS_MIXER_ADDR(ioaddr
, i
));
1188 /* Don't attenuate any audio set for the wave amplifier.
1190 * FIXME: Maximum attenuation is set for the music amp, which will
1191 * need to change if we start using the synth engine.
1193 outl(0xffff0000, io
+ SIS_WEVCR
);
1195 /* Ensure that the wave engine is in normal operating mode.
1197 outl(0, io
+ SIS_WECCR
);
1199 /* Go ahead and enable the DMA interrupts. They won't go live
1200 * until we start a channel.
1202 outl(SIS_GIER_AUDIO_PLAY_DMA_IRQ_ENABLE
|
1203 SIS_GIER_AUDIO_RECORD_DMA_IRQ_ENABLE
, io
+ SIS_GIER
);
1209 static int sis_suspend(struct pci_dev
*pci
, pm_message_t state
)
1211 struct snd_card
*card
= pci_get_drvdata(pci
);
1212 struct sis7019
*sis
= card
->private_data
;
1213 void __iomem
*ioaddr
= sis
->ioaddr
;
1216 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
1217 snd_pcm_suspend_all(sis
->pcm
);
1218 if (sis
->codecs_present
& SIS_PRIMARY_CODEC_PRESENT
)
1219 snd_ac97_suspend(sis
->ac97
[0]);
1220 if (sis
->codecs_present
& SIS_SECONDARY_CODEC_PRESENT
)
1221 snd_ac97_suspend(sis
->ac97
[1]);
1222 if (sis
->codecs_present
& SIS_TERTIARY_CODEC_PRESENT
)
1223 snd_ac97_suspend(sis
->ac97
[2]);
1225 /* snd_pcm_suspend_all() stopped all channels, so we're quiescent.
1227 if (sis
->irq
>= 0) {
1228 free_irq(sis
->irq
, sis
);
1232 /* Save the internal state away
1234 for (i
= 0; i
< 4; i
++) {
1235 memcpy_fromio(sis
->suspend_state
[i
], ioaddr
, 4096);
1239 pci_disable_device(pci
);
1240 pci_save_state(pci
);
1241 pci_set_power_state(pci
, pci_choose_state(pci
, state
));
1245 static int sis_resume(struct pci_dev
*pci
)
1247 struct snd_card
*card
= pci_get_drvdata(pci
);
1248 struct sis7019
*sis
= card
->private_data
;
1249 void __iomem
*ioaddr
= sis
->ioaddr
;
1252 pci_set_power_state(pci
, PCI_D0
);
1253 pci_restore_state(pci
);
1255 if (pci_enable_device(pci
) < 0) {
1256 printk(KERN_ERR
"sis7019: unable to re-enable device\n");
1260 if (sis_chip_init(sis
)) {
1261 printk(KERN_ERR
"sis7019: unable to re-init controller\n");
1265 if (request_irq(pci
->irq
, sis_interrupt
, IRQF_DISABLED
|IRQF_SHARED
,
1266 card
->shortname
, sis
)) {
1267 printk(KERN_ERR
"sis7019: unable to regain IRQ %d\n", pci
->irq
);
1271 /* Restore saved state, then clear out the page we use for the
1274 for (i
= 0; i
< 4; i
++) {
1275 memcpy_toio(ioaddr
, sis
->suspend_state
[i
], 4096);
1279 memset(sis
->suspend_state
[0], 0, 4096);
1281 sis
->irq
= pci
->irq
;
1282 pci_set_master(pci
);
1284 if (sis
->codecs_present
& SIS_PRIMARY_CODEC_PRESENT
)
1285 snd_ac97_resume(sis
->ac97
[0]);
1286 if (sis
->codecs_present
& SIS_SECONDARY_CODEC_PRESENT
)
1287 snd_ac97_resume(sis
->ac97
[1]);
1288 if (sis
->codecs_present
& SIS_TERTIARY_CODEC_PRESENT
)
1289 snd_ac97_resume(sis
->ac97
[2]);
1291 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
1295 snd_card_disconnect(card
);
1298 #endif /* CONFIG_PM */
1300 static int sis_alloc_suspend(struct sis7019
*sis
)
1304 /* We need 16K to store the internal wave engine state during a
1305 * suspend, but we don't need it to be contiguous, so play nice
1306 * with the memory system. We'll also use this area for a silence
1309 for (i
= 0; i
< SIS_SUSPEND_PAGES
; i
++) {
1310 sis
->suspend_state
[i
] = kmalloc(4096, GFP_KERNEL
);
1311 if (!sis
->suspend_state
[i
])
1314 memset(sis
->suspend_state
[0], 0, 4096);
1319 static int __devinit
sis_chip_create(struct snd_card
*card
,
1320 struct pci_dev
*pci
)
1322 struct sis7019
*sis
= card
->private_data
;
1323 struct voice
*voice
;
1324 static struct snd_device_ops ops
= {
1325 .dev_free
= sis_dev_free
,
1330 rc
= pci_enable_device(pci
);
1334 if (pci_set_dma_mask(pci
, DMA_BIT_MASK(30)) < 0) {
1335 printk(KERN_ERR
"sis7019: architecture does not support "
1336 "30-bit PCI busmaster DMA");
1337 goto error_out_enabled
;
1340 memset(sis
, 0, sizeof(*sis
));
1341 mutex_init(&sis
->ac97_mutex
);
1342 spin_lock_init(&sis
->voice_lock
);
1346 sis
->ioport
= pci_resource_start(pci
, 0);
1348 rc
= pci_request_regions(pci
, "SiS7019");
1350 printk(KERN_ERR
"sis7019: unable request regions\n");
1351 goto error_out_enabled
;
1355 sis
->ioaddr
= ioremap_nocache(pci_resource_start(pci
, 1), 0x4000);
1357 printk(KERN_ERR
"sis7019: unable to remap MMIO, aborting\n");
1358 goto error_out_cleanup
;
1361 rc
= sis_alloc_suspend(sis
);
1363 printk(KERN_ERR
"sis7019: unable to allocate state storage\n");
1364 goto error_out_cleanup
;
1367 rc
= sis_chip_init(sis
);
1369 goto error_out_cleanup
;
1371 if (request_irq(pci
->irq
, sis_interrupt
, IRQF_DISABLED
|IRQF_SHARED
,
1372 card
->shortname
, sis
)) {
1373 printk(KERN_ERR
"unable to allocate irq %d\n", sis
->irq
);
1374 goto error_out_cleanup
;
1377 sis
->irq
= pci
->irq
;
1378 pci_set_master(pci
);
1380 for (i
= 0; i
< 64; i
++) {
1381 voice
= &sis
->voices
[i
];
1383 voice
->ctrl_base
= SIS_PLAY_DMA_ADDR(sis
->ioaddr
, i
);
1384 voice
->wave_base
= SIS_WAVE_ADDR(sis
->ioaddr
, i
);
1387 voice
= &sis
->capture_voice
;
1388 voice
->flags
= VOICE_CAPTURE
;
1389 voice
->num
= SIS_CAPTURE_CHAN_AC97_PCM_IN
;
1390 voice
->ctrl_base
= SIS_CAPTURE_DMA_ADDR(sis
->ioaddr
, voice
->num
);
1392 rc
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, sis
, &ops
);
1394 goto error_out_cleanup
;
1396 snd_card_set_dev(card
, &pci
->dev
);
1404 pci_disable_device(pci
);
1410 static int __devinit
snd_sis7019_probe(struct pci_dev
*pci
,
1411 const struct pci_device_id
*pci_id
)
1413 struct snd_card
*card
;
1414 struct sis7019
*sis
;
1421 /* The user can specify which codecs should be present so that we
1422 * can wait for them to show up if they are slow to recover from
1423 * the AC97 cold reset. We default to a single codec, the primary.
1425 * We assume that SIS_PRIMARY_*_PRESENT matches bits 0-2.
1427 codecs
&= SIS_PRIMARY_CODEC_PRESENT
| SIS_SECONDARY_CODEC_PRESENT
|
1428 SIS_TERTIARY_CODEC_PRESENT
;
1430 codecs
= SIS_PRIMARY_CODEC_PRESENT
;
1432 rc
= snd_card_create(index
, id
, THIS_MODULE
, sizeof(*sis
), &card
);
1436 strcpy(card
->driver
, "SiS7019");
1437 strcpy(card
->shortname
, "SiS7019");
1438 rc
= sis_chip_create(card
, pci
);
1440 goto card_error_out
;
1442 sis
= card
->private_data
;
1444 rc
= sis_mixer_create(sis
);
1446 goto card_error_out
;
1448 rc
= sis_pcm_create(sis
);
1450 goto card_error_out
;
1452 snprintf(card
->longname
, sizeof(card
->longname
),
1453 "%s Audio Accelerator with %s at 0x%lx, irq %d",
1454 card
->shortname
, snd_ac97_get_short_name(sis
->ac97
[0]),
1455 sis
->ioport
, sis
->irq
);
1457 rc
= snd_card_register(card
);
1459 goto card_error_out
;
1461 pci_set_drvdata(pci
, card
);
1465 snd_card_free(card
);
1471 static void __devexit
snd_sis7019_remove(struct pci_dev
*pci
)
1473 snd_card_free(pci_get_drvdata(pci
));
1474 pci_set_drvdata(pci
, NULL
);
1477 static struct pci_driver sis7019_driver
= {
1479 .id_table
= snd_sis7019_ids
,
1480 .probe
= snd_sis7019_probe
,
1481 .remove
= __devexit_p(snd_sis7019_remove
),
1484 .suspend
= sis_suspend
,
1485 .resume
= sis_resume
,
1489 static int __init
sis7019_init(void)
1491 return pci_register_driver(&sis7019_driver
);
1494 static void __exit
sis7019_exit(void)
1496 pci_unregister_driver(&sis7019_driver
);
1499 module_init(sis7019_init
);
1500 module_exit(sis7019_exit
);