2 * Matt Wu <Matt_Wu@acersoftech.com.cn>
4 * Routines for control of ALi pci audio M5451
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public Lcodecnse as published by
14 * the Free Software Foundation; either version 2 of the Lcodecnse, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public Lcodecnse for more details.
22 * You should have received a copy of the GNU General Public Lcodecnse
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <linux/delay.h>
30 #include <linux/interrupt.h>
31 #include <linux/init.h>
32 #include <linux/pci.h>
33 #include <linux/slab.h>
34 #include <linux/module.h>
35 #include <linux/dma-mapping.h>
36 #include <sound/core.h>
37 #include <sound/pcm.h>
38 #include <sound/info.h>
39 #include <sound/ac97_codec.h>
40 #include <sound/mpu401.h>
41 #include <sound/initval.h>
43 MODULE_AUTHOR("Matt Wu <Matt_Wu@acersoftech.com.cn>");
44 MODULE_DESCRIPTION("ALI M5451");
45 MODULE_LICENSE("GPL");
46 MODULE_SUPPORTED_DEVICE("{{ALI,M5451,pci},{ALI,M5451}}");
48 static int index
= SNDRV_DEFAULT_IDX1
; /* Index */
49 static char *id
= SNDRV_DEFAULT_STR1
; /* ID for this card */
50 static int pcm_channels
= 32;
53 module_param(index
, int, 0444);
54 MODULE_PARM_DESC(index
, "Index value for ALI M5451 PCI Audio.");
55 module_param(id
, charp
, 0444);
56 MODULE_PARM_DESC(id
, "ID string for ALI M5451 PCI Audio.");
57 module_param(pcm_channels
, int, 0444);
58 MODULE_PARM_DESC(pcm_channels
, "PCM Channels");
59 module_param(spdif
, bool, 0444);
60 MODULE_PARM_DESC(spdif
, "Support SPDIF I/O");
62 /* just for backward compatibility */
64 module_param(enable
, bool, 0444);
68 * Constants definition
71 #define DEVICE_ID_ALI5451 ((PCI_VENDOR_ID_AL<<16)|PCI_DEVICE_ID_AL_M5451)
74 #define ALI_CHANNELS 32
76 #define ALI_PCM_IN_CHANNEL 31
77 #define ALI_SPDIF_IN_CHANNEL 19
78 #define ALI_SPDIF_OUT_CHANNEL 15
79 #define ALI_CENTER_CHANNEL 24
80 #define ALI_LEF_CHANNEL 23
81 #define ALI_SURR_LEFT_CHANNEL 26
82 #define ALI_SURR_RIGHT_CHANNEL 25
83 #define ALI_MODEM_IN_CHANNEL 21
84 #define ALI_MODEM_OUT_CHANNEL 20
86 #define SNDRV_ALI_VOICE_TYPE_PCM 01
87 #define SNDRV_ALI_VOICE_TYPE_OTH 02
89 #define ALI_5451_V02 0x02
95 #define ALI_LEGACY_DMAR0 0x00 /* ADR0 */
96 #define ALI_LEGACY_DMAR4 0x04 /* CNT0 */
97 #define ALI_LEGACY_DMAR11 0x0b /* MOD */
98 #define ALI_LEGACY_DMAR15 0x0f /* MMR */
99 #define ALI_MPUR0 0x20
100 #define ALI_MPUR1 0x21
101 #define ALI_MPUR2 0x22
102 #define ALI_MPUR3 0x23
104 #define ALI_AC97_WRITE 0x40
105 #define ALI_AC97_READ 0x44
107 #define ALI_SCTRL 0x48
108 #define ALI_SPDIF_OUT_ENABLE 0x20
109 #define ALI_SCTRL_LINE_IN2 (1 << 9)
110 #define ALI_SCTRL_GPIO_IN2 (1 << 13)
111 #define ALI_SCTRL_LINE_OUT_EN (1 << 20)
112 #define ALI_SCTRL_GPIO_OUT_EN (1 << 23)
113 #define ALI_SCTRL_CODEC1_READY (1 << 24)
114 #define ALI_SCTRL_CODEC2_READY (1 << 25)
115 #define ALI_AC97_GPIO 0x4c
116 #define ALI_AC97_GPIO_ENABLE 0x8000
117 #define ALI_AC97_GPIO_DATA_SHIFT 16
118 #define ALI_SPDIF_CS 0x70
119 #define ALI_SPDIF_CTRL 0x74
120 #define ALI_SPDIF_IN_FUNC_ENABLE 0x02
121 #define ALI_SPDIF_IN_CH_STATUS 0x40
122 #define ALI_SPDIF_OUT_CH_STATUS 0xbf
123 #define ALI_START 0x80
124 #define ALI_STOP 0x84
125 #define ALI_CSPF 0x90
126 #define ALI_AINT 0x98
127 #define ALI_GC_CIR 0xa0
128 #define ENDLP_IE 0x00001000
129 #define MIDLP_IE 0x00002000
130 #define ALI_AINTEN 0xa4
131 #define ALI_VOLUME 0xa8
132 #define ALI_SBDELTA_DELTA_R 0xac
133 #define ALI_MISCINT 0xb0
134 #define ADDRESS_IRQ 0x00000020
135 #define TARGET_REACHED 0x00008000
136 #define MIXER_OVERFLOW 0x00000800
137 #define MIXER_UNDERFLOW 0x00000400
138 #define GPIO_IRQ 0x01000000
139 #define ALI_SBBL_SBCL 0xc0
140 #define ALI_SBCTRL_SBE2R_SBDD 0xc4
141 #define ALI_STIMER 0xc8
142 #define ALI_GLOBAL_CONTROL 0xd4
143 #define ALI_SPDIF_OUT_SEL_PCM 0x00000400 /* bit 10 */
144 #define ALI_SPDIF_IN_SUPPORT 0x00000800 /* bit 11 */
145 #define ALI_SPDIF_OUT_CH_ENABLE 0x00008000 /* bit 15 */
146 #define ALI_SPDIF_IN_CH_ENABLE 0x00080000 /* bit 19 */
147 #define ALI_PCM_IN_ENABLE 0x80000000 /* bit 31 */
149 #define ALI_CSO_ALPHA_FMS 0xe0
151 #define ALI_ESO_DELTA 0xe8
152 #define ALI_GVSEL_PAN_VOC_CTRL_EC 0xf0
153 #define ALI_EBUF1 0xf4
154 #define ALI_EBUF2 0xf8
156 #define ALI_REG(codec, x) ((codec)->port + x)
162 struct snd_ali_voice
;
164 struct snd_ali_channel_control
{
173 /* register addresses */
179 unsigned int ac97read
;
180 unsigned int ac97write
;
185 struct snd_ali_voice
{
195 struct snd_ali
*codec
;
196 struct snd_pcm_substream
*substream
;
197 struct snd_ali_voice
*extra
;
199 int eso
; /* final ESO value for channel */
200 int count
; /* runtime->period_size */
205 void (*private_free
)(void *private_data
);
211 struct snd_ali_voice voices
[ALI_CHANNELS
];
213 unsigned int chcnt
; /* num of opened channels */
214 unsigned int chmap
; /* bitmap for opened channels */
215 unsigned int synthcount
;
220 #define ALI_GLOBAL_REGS 56
221 #define ALI_CHANNEL_REGS 8
222 struct snd_ali_image
{
223 u32 regs
[ALI_GLOBAL_REGS
];
224 u32 channel_regs
[ALI_CHANNELS
][ALI_CHANNEL_REGS
];
231 unsigned char revision
;
233 unsigned int hw_initialized
:1;
234 unsigned int spdif_support
:1;
237 struct pci_dev
*pci_m1533
;
238 struct pci_dev
*pci_m7101
;
240 struct snd_card
*card
;
241 struct snd_pcm
*pcm
[MAX_CODECS
];
242 struct snd_alidev synth
;
243 struct snd_ali_channel_control chregs
;
246 unsigned int spdif_mask
;
248 unsigned int spurious_irq_count
;
249 unsigned int spurious_irq_max_delta
;
251 unsigned int num_of_codecs
;
253 struct snd_ac97_bus
*ac97_bus
;
254 struct snd_ac97
*ac97
[MAX_CODECS
];
255 unsigned short ac97_ext_id
;
256 unsigned short ac97_ext_status
;
259 spinlock_t voice_alloc
;
261 #ifdef CONFIG_PM_SLEEP
262 struct snd_ali_image
*image
;
266 static const struct pci_device_id snd_ali_ids
[] = {
267 {PCI_DEVICE(PCI_VENDOR_ID_AL
, PCI_DEVICE_ID_AL_M5451
), 0, 0, 0},
270 MODULE_DEVICE_TABLE(pci
, snd_ali_ids
);
272 static void snd_ali_clear_voices(struct snd_ali
*, unsigned int, unsigned int);
273 static unsigned short snd_ali_codec_peek(struct snd_ali
*, int, unsigned short);
274 static void snd_ali_codec_poke(struct snd_ali
*, int, unsigned short,
281 static inline unsigned int snd_ali_5451_peek(struct snd_ali
*codec
,
284 return (unsigned int)inl(ALI_REG(codec
, port
));
287 static inline void snd_ali_5451_poke(struct snd_ali
*codec
,
291 outl((unsigned int)val
, ALI_REG(codec
, port
));
294 static int snd_ali_codec_ready(struct snd_ali
*codec
,
297 unsigned long end_time
;
300 end_time
= jiffies
+ msecs_to_jiffies(250);
303 res
= snd_ali_5451_peek(codec
,port
);
306 if (!time_after_eq(end_time
, jiffies
))
308 schedule_timeout_uninterruptible(1);
311 snd_ali_5451_poke(codec
, port
, res
& ~0x8000);
312 dev_dbg(codec
->card
->dev
, "ali_codec_ready: codec is not ready.\n ");
316 static int snd_ali_stimer_ready(struct snd_ali
*codec
)
318 unsigned long end_time
;
319 unsigned long dwChk1
,dwChk2
;
321 dwChk1
= snd_ali_5451_peek(codec
, ALI_STIMER
);
322 end_time
= jiffies
+ msecs_to_jiffies(250);
325 dwChk2
= snd_ali_5451_peek(codec
, ALI_STIMER
);
326 if (dwChk2
!= dwChk1
)
328 if (!time_after_eq(end_time
, jiffies
))
330 schedule_timeout_uninterruptible(1);
333 dev_err(codec
->card
->dev
, "ali_stimer_read: stimer is not ready.\n");
337 static void snd_ali_codec_poke(struct snd_ali
*codec
,int secondary
,
345 dev_err(codec
->card
->dev
,
346 "ali_codec_poke: reg(%xh) invalid.\n", reg
);
350 port
= codec
->chregs
.regs
.ac97write
;
352 if (snd_ali_codec_ready(codec
, port
) < 0)
354 if (snd_ali_stimer_ready(codec
) < 0)
357 dwVal
= (unsigned int) (reg
& 0xff);
358 dwVal
|= 0x8000 | (val
<< 16);
361 if (codec
->revision
== ALI_5451_V02
)
364 snd_ali_5451_poke(codec
, port
, dwVal
);
369 static unsigned short snd_ali_codec_peek(struct snd_ali
*codec
,
377 dev_err(codec
->card
->dev
,
378 "ali_codec_peek: reg(%xh) invalid.\n", reg
);
382 port
= codec
->chregs
.regs
.ac97read
;
384 if (snd_ali_codec_ready(codec
, port
) < 0)
386 if (snd_ali_stimer_ready(codec
) < 0)
389 dwVal
= (unsigned int) (reg
& 0xff);
390 dwVal
|= 0x8000; /* bit 15*/
394 snd_ali_5451_poke(codec
, port
, dwVal
);
396 if (snd_ali_stimer_ready(codec
) < 0)
398 if (snd_ali_codec_ready(codec
, port
) < 0)
401 return (snd_ali_5451_peek(codec
, port
) & 0xffff0000) >> 16;
404 static void snd_ali_codec_write(struct snd_ac97
*ac97
,
408 struct snd_ali
*codec
= ac97
->private_data
;
410 dev_dbg(codec
->card
->dev
, "codec_write: reg=%xh data=%xh.\n", reg
, val
);
411 if (reg
== AC97_GPIO_STATUS
) {
412 outl((val
<< ALI_AC97_GPIO_DATA_SHIFT
) | ALI_AC97_GPIO_ENABLE
,
413 ALI_REG(codec
, ALI_AC97_GPIO
));
416 snd_ali_codec_poke(codec
, ac97
->num
, reg
, val
);
421 static unsigned short snd_ali_codec_read(struct snd_ac97
*ac97
,
424 struct snd_ali
*codec
= ac97
->private_data
;
426 dev_dbg(codec
->card
->dev
, "codec_read reg=%xh.\n", reg
);
427 return snd_ali_codec_peek(codec
, ac97
->num
, reg
);
434 static int snd_ali_reset_5451(struct snd_ali
*codec
)
436 struct pci_dev
*pci_dev
;
437 unsigned short wCount
, wReg
;
440 pci_dev
= codec
->pci_m1533
;
442 pci_read_config_dword(pci_dev
, 0x7c, &dwVal
);
443 pci_write_config_dword(pci_dev
, 0x7c, dwVal
| 0x08000000);
445 pci_read_config_dword(pci_dev
, 0x7c, &dwVal
);
446 pci_write_config_dword(pci_dev
, 0x7c, dwVal
& 0xf7ffffff);
450 pci_dev
= codec
->pci
;
451 pci_read_config_dword(pci_dev
, 0x44, &dwVal
);
452 pci_write_config_dword(pci_dev
, 0x44, dwVal
| 0x000c0000);
454 pci_read_config_dword(pci_dev
, 0x44, &dwVal
);
455 pci_write_config_dword(pci_dev
, 0x44, dwVal
& 0xfffbffff);
460 wReg
= snd_ali_codec_peek(codec
, 0, AC97_POWERDOWN
);
461 if ((wReg
& 0x000f) == 0x000f)
466 /* non-fatal if you have a non PM capable codec */
467 /* dev_warn(codec->card->dev, "ali5451: reset time out\n"); */
472 * ALI 5451 Controller
475 static void snd_ali_enable_special_channel(struct snd_ali
*codec
,
476 unsigned int channel
)
480 dwVal
= inl(ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
481 dwVal
|= 1 << (channel
& 0x0000001f);
482 outl(dwVal
, ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
485 static void snd_ali_disable_special_channel(struct snd_ali
*codec
,
486 unsigned int channel
)
490 dwVal
= inl(ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
491 dwVal
&= ~(1 << (channel
& 0x0000001f));
492 outl(dwVal
, ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
495 static void snd_ali_enable_address_interrupt(struct snd_ali
*codec
)
499 gc
= inl(ALI_REG(codec
, ALI_GC_CIR
));
502 outl( gc
, ALI_REG(codec
, ALI_GC_CIR
));
505 static void snd_ali_disable_address_interrupt(struct snd_ali
*codec
)
509 gc
= inl(ALI_REG(codec
, ALI_GC_CIR
));
512 outl(gc
, ALI_REG(codec
, ALI_GC_CIR
));
515 static void snd_ali_disable_voice_irq(struct snd_ali
*codec
,
516 unsigned int channel
)
519 struct snd_ali_channel_control
*pchregs
= &(codec
->chregs
);
521 dev_dbg(codec
->card
->dev
, "disable_voice_irq channel=%d\n", channel
);
523 mask
= 1 << (channel
& 0x1f);
524 pchregs
->data
.ainten
= inl(ALI_REG(codec
, pchregs
->regs
.ainten
));
525 pchregs
->data
.ainten
&= ~mask
;
526 outl(pchregs
->data
.ainten
, ALI_REG(codec
, pchregs
->regs
.ainten
));
529 static int snd_ali_alloc_pcm_channel(struct snd_ali
*codec
, int channel
)
531 unsigned int idx
= channel
& 0x1f;
533 if (codec
->synth
.chcnt
>= ALI_CHANNELS
){
534 dev_err(codec
->card
->dev
,
535 "ali_alloc_pcm_channel: no free channels.\n");
539 if (!(codec
->synth
.chmap
& (1 << idx
))) {
540 codec
->synth
.chmap
|= 1 << idx
;
541 codec
->synth
.chcnt
++;
542 dev_dbg(codec
->card
->dev
, "alloc_pcm_channel no. %d.\n", idx
);
548 static int snd_ali_find_free_channel(struct snd_ali
* codec
, int rec
)
553 dev_dbg(codec
->card
->dev
,
554 "find_free_channel: for %s\n", rec
? "rec" : "pcm");
558 if (codec
->spdif_support
&&
559 (inl(ALI_REG(codec
, ALI_GLOBAL_CONTROL
)) &
560 ALI_SPDIF_IN_SUPPORT
))
561 idx
= ALI_SPDIF_IN_CHANNEL
;
563 idx
= ALI_PCM_IN_CHANNEL
;
565 result
= snd_ali_alloc_pcm_channel(codec
, idx
);
569 dev_err(codec
->card
->dev
,
570 "ali_find_free_channel: record channel is busy now.\n");
576 if (codec
->spdif_support
&&
577 (inl(ALI_REG(codec
, ALI_GLOBAL_CONTROL
)) &
578 ALI_SPDIF_OUT_CH_ENABLE
)) {
579 idx
= ALI_SPDIF_OUT_CHANNEL
;
580 result
= snd_ali_alloc_pcm_channel(codec
, idx
);
584 dev_err(codec
->card
->dev
,
585 "ali_find_free_channel: S/PDIF out channel is in busy now.\n");
588 for (idx
= 0; idx
< ALI_CHANNELS
; idx
++) {
589 result
= snd_ali_alloc_pcm_channel(codec
, idx
);
593 dev_err(codec
->card
->dev
, "ali_find_free_channel: no free channels.\n");
597 static void snd_ali_free_channel_pcm(struct snd_ali
*codec
, int channel
)
599 unsigned int idx
= channel
& 0x0000001f;
601 dev_dbg(codec
->card
->dev
, "free_channel_pcm channel=%d\n", channel
);
603 if (channel
< 0 || channel
>= ALI_CHANNELS
)
606 if (!(codec
->synth
.chmap
& (1 << idx
))) {
607 dev_err(codec
->card
->dev
,
608 "ali_free_channel_pcm: channel %d is not in use.\n",
612 codec
->synth
.chmap
&= ~(1 << idx
);
613 codec
->synth
.chcnt
--;
617 static void snd_ali_stop_voice(struct snd_ali
*codec
, unsigned int channel
)
619 unsigned int mask
= 1 << (channel
& 0x1f);
621 dev_dbg(codec
->card
->dev
, "stop_voice: channel=%d\n", channel
);
622 outl(mask
, ALI_REG(codec
, codec
->chregs
.regs
.stop
));
629 static void snd_ali_delay(struct snd_ali
*codec
,int interval
)
631 unsigned long begintimer
,currenttimer
;
633 begintimer
= inl(ALI_REG(codec
, ALI_STIMER
));
634 currenttimer
= inl(ALI_REG(codec
, ALI_STIMER
));
636 while (currenttimer
< begintimer
+ interval
) {
637 if (snd_ali_stimer_ready(codec
) < 0)
639 currenttimer
= inl(ALI_REG(codec
, ALI_STIMER
));
644 static void snd_ali_detect_spdif_rate(struct snd_ali
*codec
)
650 bval
= inb(ALI_REG(codec
, ALI_SPDIF_CTRL
+ 1));
652 outb(bval
, ALI_REG(codec
, ALI_SPDIF_CTRL
+ 1));
654 while ((R1
< 0x0b || R1
> 0x0e) && R1
!= 0x12 && count
<= 50000) {
656 snd_ali_delay(codec
, 6);
657 bval
= inb(ALI_REG(codec
, ALI_SPDIF_CTRL
+ 1));
662 dev_err(codec
->card
->dev
, "ali_detect_spdif_rate: timeout!\n");
666 for (count
= 0; count
<= 50000; count
++) {
667 snd_ali_delay(codec
, 6);
668 bval
= inb(ALI_REG(codec
,ALI_SPDIF_CTRL
+ 1));
677 dev_err(codec
->card
->dev
, "ali_detect_spdif_rate: timeout!\n");
681 if (R2
>= 0x0b && R2
<= 0x0e) {
682 wval
= inw(ALI_REG(codec
, ALI_SPDIF_CTRL
+ 2));
684 wval
|= (0x09 << 8) | 0x05;
685 outw(wval
, ALI_REG(codec
, ALI_SPDIF_CTRL
+ 2));
687 bval
= inb(ALI_REG(codec
, ALI_SPDIF_CS
+ 3)) & 0xf0;
688 outb(bval
| 0x02, ALI_REG(codec
, ALI_SPDIF_CS
+ 3));
689 } else if (R2
== 0x12) {
690 wval
= inw(ALI_REG(codec
, ALI_SPDIF_CTRL
+ 2));
692 wval
|= (0x0e << 8) | 0x08;
693 outw(wval
, ALI_REG(codec
, ALI_SPDIF_CTRL
+ 2));
695 bval
= inb(ALI_REG(codec
,ALI_SPDIF_CS
+ 3)) & 0xf0;
696 outb(bval
| 0x03, ALI_REG(codec
, ALI_SPDIF_CS
+ 3));
700 static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali
*codec
)
705 bval
= inb(ALI_REG(codec
, ALI_SPDIF_CTRL
));
708 outb(bval
, ALI_REG(codec
, ALI_SPDIF_CTRL
));
710 snd_ali_detect_spdif_rate(codec
);
712 bval
= inb(ALI_REG(codec
, ALI_SPDIF_CS
+ 3));
716 case 0: dwRate
= 44100; break;
717 case 1: dwRate
= 48000; break;
718 case 2: dwRate
= 32000; break;
719 default: dwRate
= 0; break;
725 static void snd_ali_enable_spdif_in(struct snd_ali
*codec
)
729 dwVal
= inl(ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
730 dwVal
|= ALI_SPDIF_IN_SUPPORT
;
731 outl(dwVal
, ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
733 dwVal
= inb(ALI_REG(codec
, ALI_SPDIF_CTRL
));
735 outb(dwVal
, ALI_REG(codec
, ALI_SPDIF_CTRL
));
737 snd_ali_enable_special_channel(codec
, ALI_SPDIF_IN_CHANNEL
);
740 static void snd_ali_disable_spdif_in(struct snd_ali
*codec
)
744 dwVal
= inl(ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
745 dwVal
&= ~ALI_SPDIF_IN_SUPPORT
;
746 outl(dwVal
, ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
748 snd_ali_disable_special_channel(codec
, ALI_SPDIF_IN_CHANNEL
);
752 static void snd_ali_set_spdif_out_rate(struct snd_ali
*codec
, unsigned int rate
)
758 case 32000: dwRate
= 0x300; break;
759 case 48000: dwRate
= 0x200; break;
760 default: dwRate
= 0; break;
763 bVal
= inb(ALI_REG(codec
, ALI_SPDIF_CTRL
));
764 bVal
&= (unsigned char)(~(1<<6));
766 bVal
|= 0x80; /* select right */
767 outb(bVal
, ALI_REG(codec
, ALI_SPDIF_CTRL
));
768 outb(dwRate
| 0x20, ALI_REG(codec
, ALI_SPDIF_CS
+ 2));
770 bVal
&= ~0x80; /* select left */
771 outb(bVal
, ALI_REG(codec
, ALI_SPDIF_CTRL
));
772 outw(rate
| 0x10, ALI_REG(codec
, ALI_SPDIF_CS
+ 2));
775 static void snd_ali_enable_spdif_out(struct snd_ali
*codec
)
779 struct pci_dev
*pci_dev
;
781 pci_dev
= codec
->pci_m1533
;
784 pci_read_config_byte(pci_dev
, 0x61, &bVal
);
786 pci_write_config_byte(pci_dev
, 0x61, bVal
);
787 pci_read_config_byte(pci_dev
, 0x7d, &bVal
);
789 pci_write_config_byte(pci_dev
, 0x7d, bVal
);
791 pci_read_config_byte(pci_dev
, 0x7e, &bVal
);
794 pci_write_config_byte(pci_dev
, 0x7e, bVal
);
796 bVal
= inb(ALI_REG(codec
, ALI_SCTRL
));
797 outb(bVal
| ALI_SPDIF_OUT_ENABLE
, ALI_REG(codec
, ALI_SCTRL
));
799 bVal
= inb(ALI_REG(codec
, ALI_SPDIF_CTRL
));
800 outb(bVal
& ALI_SPDIF_OUT_CH_STATUS
, ALI_REG(codec
, ALI_SPDIF_CTRL
));
802 wVal
= inw(ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
803 wVal
|= ALI_SPDIF_OUT_SEL_PCM
;
804 outw(wVal
, ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
805 snd_ali_disable_special_channel(codec
, ALI_SPDIF_OUT_CHANNEL
);
808 static void snd_ali_enable_spdif_chnout(struct snd_ali
*codec
)
812 wVal
= inw(ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
813 wVal
&= ~ALI_SPDIF_OUT_SEL_PCM
;
814 outw(wVal
, ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
816 wVal = inw(ALI_REG(codec, ALI_SPDIF_CS));
817 if (flag & ALI_SPDIF_OUT_NON_PCM)
821 outw(wVal, ALI_REG(codec, ALI_SPDIF_CS));
823 snd_ali_enable_special_channel(codec
, ALI_SPDIF_OUT_CHANNEL
);
826 static void snd_ali_disable_spdif_chnout(struct snd_ali
*codec
)
830 wVal
= inw(ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
831 wVal
|= ALI_SPDIF_OUT_SEL_PCM
;
832 outw(wVal
, ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
834 snd_ali_enable_special_channel(codec
, ALI_SPDIF_OUT_CHANNEL
);
837 static void snd_ali_disable_spdif_out(struct snd_ali
*codec
)
841 bVal
= inb(ALI_REG(codec
, ALI_SCTRL
));
842 outb(bVal
& ~ALI_SPDIF_OUT_ENABLE
, ALI_REG(codec
, ALI_SCTRL
));
844 snd_ali_disable_spdif_chnout(codec
);
847 static void snd_ali_update_ptr(struct snd_ali
*codec
, int channel
)
849 struct snd_ali_voice
*pvoice
;
850 struct snd_ali_channel_control
*pchregs
;
851 unsigned int old
, mask
;
853 pchregs
= &(codec
->chregs
);
855 /* check if interrupt occurred for channel */
856 old
= pchregs
->data
.aint
;
857 mask
= 1U << (channel
& 0x1f);
862 pvoice
= &codec
->synth
.voices
[channel
];
865 spin_lock(&codec
->reg_lock
);
867 if (pvoice
->pcm
&& pvoice
->substream
) {
869 if (pvoice
->running
) {
870 dev_dbg(codec
->card
->dev
,
871 "update_ptr: cso=%4.4x cspf=%d.\n",
872 inw(ALI_REG(codec
, ALI_CSO_ALPHA_FMS
+ 2)),
873 (inl(ALI_REG(codec
, ALI_CSPF
)) & mask
) == mask
);
874 spin_unlock(&codec
->reg_lock
);
875 snd_pcm_period_elapsed(pvoice
->substream
);
876 spin_lock(&codec
->reg_lock
);
878 snd_ali_stop_voice(codec
, channel
);
879 snd_ali_disable_voice_irq(codec
, channel
);
881 } else if (codec
->synth
.voices
[channel
].synth
) {
882 /* synth interrupt */
883 } else if (codec
->synth
.voices
[channel
].midi
) {
886 /* unknown interrupt */
887 snd_ali_stop_voice(codec
, channel
);
888 snd_ali_disable_voice_irq(codec
, channel
);
890 spin_unlock(&codec
->reg_lock
);
891 outl(mask
,ALI_REG(codec
,pchregs
->regs
.aint
));
892 pchregs
->data
.aint
= old
& (~mask
);
895 static irqreturn_t
snd_ali_card_interrupt(int irq
, void *dev_id
)
897 struct snd_ali
*codec
= dev_id
;
899 unsigned int audio_int
;
900 struct snd_ali_channel_control
*pchregs
;
902 if (codec
== NULL
|| !codec
->hw_initialized
)
905 audio_int
= inl(ALI_REG(codec
, ALI_MISCINT
));
909 pchregs
= &(codec
->chregs
);
910 if (audio_int
& ADDRESS_IRQ
) {
911 /* get interrupt status for all channels */
912 pchregs
->data
.aint
= inl(ALI_REG(codec
, pchregs
->regs
.aint
));
913 for (channel
= 0; channel
< ALI_CHANNELS
; channel
++)
914 snd_ali_update_ptr(codec
, channel
);
916 outl((TARGET_REACHED
| MIXER_OVERFLOW
| MIXER_UNDERFLOW
),
917 ALI_REG(codec
, ALI_MISCINT
));
923 static struct snd_ali_voice
*snd_ali_alloc_voice(struct snd_ali
* codec
,
924 int type
, int rec
, int channel
)
926 struct snd_ali_voice
*pvoice
;
929 dev_dbg(codec
->card
->dev
, "alloc_voice: type=%d rec=%d\n", type
, rec
);
931 spin_lock_irq(&codec
->voice_alloc
);
932 if (type
== SNDRV_ALI_VOICE_TYPE_PCM
) {
933 idx
= channel
> 0 ? snd_ali_alloc_pcm_channel(codec
, channel
) :
934 snd_ali_find_free_channel(codec
,rec
);
936 dev_err(codec
->card
->dev
, "ali_alloc_voice: err.\n");
937 spin_unlock_irq(&codec
->voice_alloc
);
940 pvoice
= &(codec
->synth
.voices
[idx
]);
941 pvoice
->codec
= codec
;
945 spin_unlock_irq(&codec
->voice_alloc
);
948 spin_unlock_irq(&codec
->voice_alloc
);
953 static void snd_ali_free_voice(struct snd_ali
* codec
,
954 struct snd_ali_voice
*pvoice
)
956 void (*private_free
)(void *);
959 dev_dbg(codec
->card
->dev
, "free_voice: channel=%d\n", pvoice
->number
);
962 snd_ali_clear_voices(codec
, pvoice
->number
, pvoice
->number
);
963 spin_lock_irq(&codec
->voice_alloc
);
964 private_free
= pvoice
->private_free
;
965 private_data
= pvoice
->private_data
;
966 pvoice
->private_free
= NULL
;
967 pvoice
->private_data
= NULL
;
969 snd_ali_free_channel_pcm(codec
, pvoice
->number
);
970 pvoice
->use
= pvoice
->pcm
= pvoice
->synth
= 0;
971 pvoice
->substream
= NULL
;
972 spin_unlock_irq(&codec
->voice_alloc
);
974 private_free(private_data
);
978 static void snd_ali_clear_voices(struct snd_ali
*codec
,
984 for (i
= v_min
; i
<= v_max
; i
++) {
985 snd_ali_stop_voice(codec
, i
);
986 snd_ali_disable_voice_irq(codec
, i
);
990 static void snd_ali_write_voice_regs(struct snd_ali
*codec
,
991 unsigned int Channel
,
996 unsigned int ALPHA_FMS
,
1003 unsigned int ctlcmds
[4];
1005 outb((unsigned char)(Channel
& 0x001f), ALI_REG(codec
, ALI_GC_CIR
));
1007 ctlcmds
[0] = (CSO
<< 16) | (ALPHA_FMS
& 0x0000ffff);
1009 ctlcmds
[2] = (ESO
<< 16) | (DELTA
& 0x0ffff);
1010 ctlcmds
[3] = (GVSEL
<< 31) |
1011 ((PAN
& 0x0000007f) << 24) |
1012 ((VOL
& 0x000000ff) << 16) |
1013 ((CTRL
& 0x0000000f) << 12) |
1016 outb(Channel
, ALI_REG(codec
, ALI_GC_CIR
));
1018 outl(ctlcmds
[0], ALI_REG(codec
, ALI_CSO_ALPHA_FMS
));
1019 outl(ctlcmds
[1], ALI_REG(codec
, ALI_LBA
));
1020 outl(ctlcmds
[2], ALI_REG(codec
, ALI_ESO_DELTA
));
1021 outl(ctlcmds
[3], ALI_REG(codec
, ALI_GVSEL_PAN_VOC_CTRL_EC
));
1023 outl(0x30000000, ALI_REG(codec
, ALI_EBUF1
)); /* Still Mode */
1024 outl(0x30000000, ALI_REG(codec
, ALI_EBUF2
)); /* Still Mode */
1027 static unsigned int snd_ali_convert_rate(unsigned int rate
, int rec
)
1039 else if (rate
== 8000)
1041 else if (rate
== 48000)
1044 delta
= ((48000 << 12) / rate
) & 0x0000ffff;
1048 else if (rate
== 8000)
1050 else if (rate
== 48000)
1053 delta
= (((rate
<< 12) + rate
) / 48000) & 0x0000ffff;
1059 static unsigned int snd_ali_control_mode(struct snd_pcm_substream
*substream
)
1062 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1065 CTRL default: 8-bit (unsigned) mono, loop mode enabled
1068 if (snd_pcm_format_width(runtime
->format
) == 16)
1069 CTRL
|= 0x00000008; /* 16-bit data */
1070 if (!snd_pcm_format_unsigned(runtime
->format
))
1071 CTRL
|= 0x00000002; /* signed data */
1072 if (runtime
->channels
> 1)
1073 CTRL
|= 0x00000004; /* stereo data */
1081 static int snd_ali_trigger(struct snd_pcm_substream
*substream
,
1085 struct snd_ali
*codec
= snd_pcm_substream_chip(substream
);
1086 struct snd_pcm_substream
*s
;
1087 unsigned int what
, whati
, capture_flag
;
1088 struct snd_ali_voice
*pvoice
, *evoice
;
1093 case SNDRV_PCM_TRIGGER_START
:
1094 case SNDRV_PCM_TRIGGER_RESUME
:
1097 case SNDRV_PCM_TRIGGER_STOP
:
1098 case SNDRV_PCM_TRIGGER_SUSPEND
:
1105 what
= whati
= capture_flag
= 0;
1106 snd_pcm_group_for_each_entry(s
, substream
) {
1107 if ((struct snd_ali
*) snd_pcm_substream_chip(s
) == codec
) {
1108 pvoice
= s
->runtime
->private_data
;
1109 evoice
= pvoice
->extra
;
1110 what
|= 1 << (pvoice
->number
& 0x1f);
1112 whati
|= 1 << (pvoice
->number
& 0x1f);
1114 whati
|= 1 << (evoice
->number
& 0x1f);
1115 what
|= 1 << (evoice
->number
& 0x1f);
1118 pvoice
->running
= 1;
1120 evoice
->running
= 1;
1122 pvoice
->running
= 0;
1124 evoice
->running
= 0;
1126 snd_pcm_trigger_done(s
, substream
);
1131 spin_lock(&codec
->reg_lock
);
1133 outl(what
, ALI_REG(codec
, ALI_STOP
));
1134 val
= inl(ALI_REG(codec
, ALI_AINTEN
));
1139 outl(val
, ALI_REG(codec
, ALI_AINTEN
));
1141 outl(what
, ALI_REG(codec
, ALI_START
));
1142 dev_dbg(codec
->card
->dev
, "trigger: what=%xh whati=%xh\n", what
, whati
);
1143 spin_unlock(&codec
->reg_lock
);
1148 static int snd_ali_playback_hw_params(struct snd_pcm_substream
*substream
,
1149 struct snd_pcm_hw_params
*hw_params
)
1151 struct snd_ali
*codec
= snd_pcm_substream_chip(substream
);
1152 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1153 struct snd_ali_voice
*pvoice
= runtime
->private_data
;
1154 struct snd_ali_voice
*evoice
= pvoice
->extra
;
1157 err
= snd_pcm_lib_malloc_pages(substream
,
1158 params_buffer_bytes(hw_params
));
1162 /* voice management */
1164 if (params_buffer_size(hw_params
) / 2 !=
1165 params_period_size(hw_params
)) {
1167 evoice
= snd_ali_alloc_voice(codec
,
1168 SNDRV_ALI_VOICE_TYPE_PCM
,
1172 pvoice
->extra
= evoice
;
1173 evoice
->substream
= substream
;
1177 snd_ali_free_voice(codec
, evoice
);
1178 pvoice
->extra
= evoice
= NULL
;
1185 static int snd_ali_playback_hw_free(struct snd_pcm_substream
*substream
)
1187 struct snd_ali
*codec
= snd_pcm_substream_chip(substream
);
1188 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1189 struct snd_ali_voice
*pvoice
= runtime
->private_data
;
1190 struct snd_ali_voice
*evoice
= pvoice
? pvoice
->extra
: NULL
;
1192 snd_pcm_lib_free_pages(substream
);
1194 snd_ali_free_voice(codec
, evoice
);
1195 pvoice
->extra
= NULL
;
1200 static int snd_ali_hw_params(struct snd_pcm_substream
*substream
,
1201 struct snd_pcm_hw_params
*hw_params
)
1203 return snd_pcm_lib_malloc_pages(substream
,
1204 params_buffer_bytes(hw_params
));
1207 static int snd_ali_hw_free(struct snd_pcm_substream
*substream
)
1209 return snd_pcm_lib_free_pages(substream
);
1212 static int snd_ali_playback_prepare(struct snd_pcm_substream
*substream
)
1214 struct snd_ali
*codec
= snd_pcm_substream_chip(substream
);
1215 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1216 struct snd_ali_voice
*pvoice
= runtime
->private_data
;
1217 struct snd_ali_voice
*evoice
= pvoice
->extra
;
1228 dev_dbg(codec
->card
->dev
, "playback_prepare ...\n");
1230 spin_lock_irq(&codec
->reg_lock
);
1232 /* set Delta (rate) value */
1233 Delta
= snd_ali_convert_rate(runtime
->rate
, 0);
1235 if (pvoice
->number
== ALI_SPDIF_IN_CHANNEL
||
1236 pvoice
->number
== ALI_PCM_IN_CHANNEL
)
1237 snd_ali_disable_special_channel(codec
, pvoice
->number
);
1238 else if (codec
->spdif_support
&&
1239 (inl(ALI_REG(codec
, ALI_GLOBAL_CONTROL
)) &
1240 ALI_SPDIF_OUT_CH_ENABLE
)
1241 && pvoice
->number
== ALI_SPDIF_OUT_CHANNEL
) {
1242 snd_ali_set_spdif_out_rate(codec
, runtime
->rate
);
1246 /* set Loop Back Address */
1247 LBA
= runtime
->dma_addr
;
1249 /* set interrupt count size */
1250 pvoice
->count
= runtime
->period_size
;
1252 /* set target ESO for channel */
1253 pvoice
->eso
= runtime
->buffer_size
;
1255 dev_dbg(codec
->card
->dev
, "playback_prepare: eso=%xh count=%xh\n",
1256 pvoice
->eso
, pvoice
->count
);
1258 /* set ESO to capture first MIDLP interrupt */
1259 ESO
= pvoice
->eso
-1;
1261 CTRL
= snd_ali_control_mode(substream
);
1267 dev_dbg(codec
->card
->dev
, "playback_prepare:\n");
1268 dev_dbg(codec
->card
->dev
,
1269 "ch=%d, Rate=%d Delta=%xh,GVSEL=%xh,PAN=%xh,CTRL=%xh\n",
1270 pvoice
->number
,runtime
->rate
,Delta
,GVSEL
,PAN
,CTRL
);
1271 snd_ali_write_voice_regs(codec
,
1284 evoice
->count
= pvoice
->count
;
1285 evoice
->eso
= pvoice
->count
<< 1;
1286 ESO
= evoice
->eso
- 1;
1287 snd_ali_write_voice_regs(codec
,
1300 spin_unlock_irq(&codec
->reg_lock
);
1305 static int snd_ali_prepare(struct snd_pcm_substream
*substream
)
1307 struct snd_ali
*codec
= snd_pcm_substream_chip(substream
);
1308 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1309 struct snd_ali_voice
*pvoice
= runtime
->private_data
;
1320 spin_lock_irq(&codec
->reg_lock
);
1322 dev_dbg(codec
->card
->dev
, "ali_prepare...\n");
1324 snd_ali_enable_special_channel(codec
,pvoice
->number
);
1326 Delta
= (pvoice
->number
== ALI_MODEM_IN_CHANNEL
||
1327 pvoice
->number
== ALI_MODEM_OUT_CHANNEL
) ?
1328 0x1000 : snd_ali_convert_rate(runtime
->rate
, pvoice
->mode
);
1330 /* Prepare capture intr channel */
1331 if (pvoice
->number
== ALI_SPDIF_IN_CHANNEL
) {
1335 spin_unlock_irq(&codec
->reg_lock
);
1336 if (codec
->revision
!= ALI_5451_V02
)
1339 rate
= snd_ali_get_spdif_in_rate(codec
);
1341 dev_warn(codec
->card
->dev
,
1342 "ali_capture_prepare: spdif rate detect err!\n");
1345 spin_lock_irq(&codec
->reg_lock
);
1346 bValue
= inb(ALI_REG(codec
,ALI_SPDIF_CTRL
));
1347 if (bValue
& 0x10) {
1348 outb(bValue
,ALI_REG(codec
,ALI_SPDIF_CTRL
));
1349 dev_warn(codec
->card
->dev
,
1350 "clear SPDIF parity error flag.\n");
1354 Delta
= ((rate
<< 12) / runtime
->rate
) & 0x00ffff;
1357 /* set target ESO for channel */
1358 pvoice
->eso
= runtime
->buffer_size
;
1360 /* set interrupt count size */
1361 pvoice
->count
= runtime
->period_size
;
1363 /* set Loop Back Address */
1364 LBA
= runtime
->dma_addr
;
1366 /* set ESO to capture first MIDLP interrupt */
1367 ESO
= pvoice
->eso
- 1;
1368 CTRL
= snd_ali_control_mode(substream
);
1374 snd_ali_write_voice_regs( codec
,
1387 spin_unlock_irq(&codec
->reg_lock
);
1393 static snd_pcm_uframes_t
1394 snd_ali_playback_pointer(struct snd_pcm_substream
*substream
)
1396 struct snd_ali
*codec
= snd_pcm_substream_chip(substream
);
1397 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1398 struct snd_ali_voice
*pvoice
= runtime
->private_data
;
1401 spin_lock(&codec
->reg_lock
);
1402 if (!pvoice
->running
) {
1403 spin_unlock(&codec
->reg_lock
);
1406 outb(pvoice
->number
, ALI_REG(codec
, ALI_GC_CIR
));
1407 cso
= inw(ALI_REG(codec
, ALI_CSO_ALPHA_FMS
+ 2));
1408 spin_unlock(&codec
->reg_lock
);
1409 dev_dbg(codec
->card
->dev
, "playback pointer returned cso=%xh.\n", cso
);
1411 cso
%= runtime
->buffer_size
;
1416 static snd_pcm_uframes_t
snd_ali_pointer(struct snd_pcm_substream
*substream
)
1418 struct snd_ali
*codec
= snd_pcm_substream_chip(substream
);
1419 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1420 struct snd_ali_voice
*pvoice
= runtime
->private_data
;
1423 spin_lock(&codec
->reg_lock
);
1424 if (!pvoice
->running
) {
1425 spin_unlock(&codec
->reg_lock
);
1428 outb(pvoice
->number
, ALI_REG(codec
, ALI_GC_CIR
));
1429 cso
= inw(ALI_REG(codec
, ALI_CSO_ALPHA_FMS
+ 2));
1430 spin_unlock(&codec
->reg_lock
);
1432 cso
%= runtime
->buffer_size
;
1436 static struct snd_pcm_hardware snd_ali_playback
=
1438 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1439 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1440 SNDRV_PCM_INFO_MMAP_VALID
|
1441 SNDRV_PCM_INFO_RESUME
|
1442 SNDRV_PCM_INFO_SYNC_START
),
1443 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1444 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1445 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1450 .buffer_bytes_max
= (256*1024),
1451 .period_bytes_min
= 64,
1452 .period_bytes_max
= (256*1024),
1454 .periods_max
= 1024,
1459 * Capture support device description
1462 static struct snd_pcm_hardware snd_ali_capture
=
1464 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1465 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1466 SNDRV_PCM_INFO_MMAP_VALID
|
1467 SNDRV_PCM_INFO_RESUME
|
1468 SNDRV_PCM_INFO_SYNC_START
),
1469 .formats
= (SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
|
1470 SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U16_LE
),
1471 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1476 .buffer_bytes_max
= (128*1024),
1477 .period_bytes_min
= 64,
1478 .period_bytes_max
= (128*1024),
1480 .periods_max
= 1024,
1484 static void snd_ali_pcm_free_substream(struct snd_pcm_runtime
*runtime
)
1486 struct snd_ali_voice
*pvoice
= runtime
->private_data
;
1489 snd_ali_free_voice(pvoice
->codec
, pvoice
);
1492 static int snd_ali_open(struct snd_pcm_substream
*substream
, int rec
,
1493 int channel
, struct snd_pcm_hardware
*phw
)
1495 struct snd_ali
*codec
= snd_pcm_substream_chip(substream
);
1496 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1497 struct snd_ali_voice
*pvoice
;
1499 pvoice
= snd_ali_alloc_voice(codec
, SNDRV_ALI_VOICE_TYPE_PCM
, rec
,
1504 pvoice
->substream
= substream
;
1505 runtime
->private_data
= pvoice
;
1506 runtime
->private_free
= snd_ali_pcm_free_substream
;
1509 snd_pcm_set_sync(substream
);
1510 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1515 static int snd_ali_playback_open(struct snd_pcm_substream
*substream
)
1517 return snd_ali_open(substream
, 0, -1, &snd_ali_playback
);
1520 static int snd_ali_capture_open(struct snd_pcm_substream
*substream
)
1522 return snd_ali_open(substream
, 1, -1, &snd_ali_capture
);
1525 static int snd_ali_playback_close(struct snd_pcm_substream
*substream
)
1530 static int snd_ali_close(struct snd_pcm_substream
*substream
)
1532 struct snd_ali
*codec
= snd_pcm_substream_chip(substream
);
1533 struct snd_ali_voice
*pvoice
= substream
->runtime
->private_data
;
1535 snd_ali_disable_special_channel(codec
,pvoice
->number
);
1540 static const struct snd_pcm_ops snd_ali_playback_ops
= {
1541 .open
= snd_ali_playback_open
,
1542 .close
= snd_ali_playback_close
,
1543 .ioctl
= snd_pcm_lib_ioctl
,
1544 .hw_params
= snd_ali_playback_hw_params
,
1545 .hw_free
= snd_ali_playback_hw_free
,
1546 .prepare
= snd_ali_playback_prepare
,
1547 .trigger
= snd_ali_trigger
,
1548 .pointer
= snd_ali_playback_pointer
,
1551 static const struct snd_pcm_ops snd_ali_capture_ops
= {
1552 .open
= snd_ali_capture_open
,
1553 .close
= snd_ali_close
,
1554 .ioctl
= snd_pcm_lib_ioctl
,
1555 .hw_params
= snd_ali_hw_params
,
1556 .hw_free
= snd_ali_hw_free
,
1557 .prepare
= snd_ali_prepare
,
1558 .trigger
= snd_ali_trigger
,
1559 .pointer
= snd_ali_pointer
,
1566 static int snd_ali_modem_hw_params(struct snd_pcm_substream
*substream
,
1567 struct snd_pcm_hw_params
*hw_params
)
1569 struct snd_ali
*chip
= snd_pcm_substream_chip(substream
);
1570 unsigned int modem_num
= chip
->num_of_codecs
- 1;
1571 snd_ac97_write(chip
->ac97
[modem_num
], AC97_LINE1_RATE
,
1572 params_rate(hw_params
));
1573 snd_ac97_write(chip
->ac97
[modem_num
], AC97_LINE1_LEVEL
, 0);
1574 return snd_ali_hw_params(substream
, hw_params
);
1577 static struct snd_pcm_hardware snd_ali_modem
=
1579 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1580 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1581 SNDRV_PCM_INFO_MMAP_VALID
|
1582 SNDRV_PCM_INFO_RESUME
|
1583 SNDRV_PCM_INFO_SYNC_START
),
1584 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1585 .rates
= (SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000
|
1586 SNDRV_PCM_RATE_16000
),
1591 .buffer_bytes_max
= (256*1024),
1592 .period_bytes_min
= 64,
1593 .period_bytes_max
= (256*1024),
1595 .periods_max
= 1024,
1599 static int snd_ali_modem_open(struct snd_pcm_substream
*substream
, int rec
,
1602 static const unsigned int rates
[] = {8000, 9600, 12000, 16000};
1603 static const struct snd_pcm_hw_constraint_list hw_constraint_rates
= {
1604 .count
= ARRAY_SIZE(rates
),
1608 int err
= snd_ali_open(substream
, rec
, channel
, &snd_ali_modem
);
1612 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
1613 SNDRV_PCM_HW_PARAM_RATE
, &hw_constraint_rates
);
1616 static int snd_ali_modem_playback_open(struct snd_pcm_substream
*substream
)
1618 return snd_ali_modem_open(substream
, 0, ALI_MODEM_OUT_CHANNEL
);
1621 static int snd_ali_modem_capture_open(struct snd_pcm_substream
*substream
)
1623 return snd_ali_modem_open(substream
, 1, ALI_MODEM_IN_CHANNEL
);
1626 static const struct snd_pcm_ops snd_ali_modem_playback_ops
= {
1627 .open
= snd_ali_modem_playback_open
,
1628 .close
= snd_ali_close
,
1629 .ioctl
= snd_pcm_lib_ioctl
,
1630 .hw_params
= snd_ali_modem_hw_params
,
1631 .hw_free
= snd_ali_hw_free
,
1632 .prepare
= snd_ali_prepare
,
1633 .trigger
= snd_ali_trigger
,
1634 .pointer
= snd_ali_pointer
,
1637 static const struct snd_pcm_ops snd_ali_modem_capture_ops
= {
1638 .open
= snd_ali_modem_capture_open
,
1639 .close
= snd_ali_close
,
1640 .ioctl
= snd_pcm_lib_ioctl
,
1641 .hw_params
= snd_ali_modem_hw_params
,
1642 .hw_free
= snd_ali_hw_free
,
1643 .prepare
= snd_ali_prepare
,
1644 .trigger
= snd_ali_trigger
,
1645 .pointer
= snd_ali_pointer
,
1649 struct ali_pcm_description
{
1651 unsigned int playback_num
;
1652 unsigned int capture_num
;
1653 const struct snd_pcm_ops
*playback_ops
;
1654 const struct snd_pcm_ops
*capture_ops
;
1655 unsigned short class;
1659 static void snd_ali_pcm_free(struct snd_pcm
*pcm
)
1661 struct snd_ali
*codec
= pcm
->private_data
;
1662 codec
->pcm
[pcm
->device
] = NULL
;
1666 static int snd_ali_pcm(struct snd_ali
*codec
, int device
,
1667 struct ali_pcm_description
*desc
)
1669 struct snd_pcm
*pcm
;
1672 err
= snd_pcm_new(codec
->card
, desc
->name
, device
,
1673 desc
->playback_num
, desc
->capture_num
, &pcm
);
1675 dev_err(codec
->card
->dev
,
1676 "snd_ali_pcm: err called snd_pcm_new.\n");
1679 pcm
->private_data
= codec
;
1680 pcm
->private_free
= snd_ali_pcm_free
;
1681 if (desc
->playback_ops
)
1682 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1683 desc
->playback_ops
);
1684 if (desc
->capture_ops
)
1685 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1688 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1689 snd_dma_pci_data(codec
->pci
),
1692 pcm
->info_flags
= 0;
1693 pcm
->dev_class
= desc
->class;
1694 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1695 strcpy(pcm
->name
, desc
->name
);
1696 codec
->pcm
[0] = pcm
;
1700 static struct ali_pcm_description ali_pcms
[] = {
1701 { .name
= "ALI 5451",
1702 .playback_num
= ALI_CHANNELS
,
1704 .playback_ops
= &snd_ali_playback_ops
,
1705 .capture_ops
= &snd_ali_capture_ops
1707 { .name
= "ALI 5451 modem",
1710 .playback_ops
= &snd_ali_modem_playback_ops
,
1711 .capture_ops
= &snd_ali_modem_capture_ops
,
1712 .class = SNDRV_PCM_CLASS_MODEM
1716 static int snd_ali_build_pcms(struct snd_ali
*codec
)
1719 for (i
= 0; i
< codec
->num_of_codecs
&& i
< ARRAY_SIZE(ali_pcms
); i
++) {
1720 err
= snd_ali_pcm(codec
, i
, &ali_pcms
[i
]);
1728 #define ALI5451_SPDIF(xname, xindex, value) \
1729 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
1730 .info = snd_ali5451_spdif_info, .get = snd_ali5451_spdif_get, \
1731 .put = snd_ali5451_spdif_put, .private_value = value}
1733 #define snd_ali5451_spdif_info snd_ctl_boolean_mono_info
1735 static int snd_ali5451_spdif_get(struct snd_kcontrol
*kcontrol
,
1736 struct snd_ctl_elem_value
*ucontrol
)
1738 struct snd_ali
*codec
= kcontrol
->private_data
;
1739 unsigned int spdif_enable
;
1741 spdif_enable
= ucontrol
->value
.integer
.value
[0] ? 1 : 0;
1743 spin_lock_irq(&codec
->reg_lock
);
1744 switch (kcontrol
->private_value
) {
1746 spdif_enable
= (codec
->spdif_mask
& 0x02) ? 1 : 0;
1749 spdif_enable
= ((codec
->spdif_mask
& 0x02) &&
1750 (codec
->spdif_mask
& 0x04)) ? 1 : 0;
1753 spdif_enable
= (codec
->spdif_mask
& 0x01) ? 1 : 0;
1758 ucontrol
->value
.integer
.value
[0] = spdif_enable
;
1759 spin_unlock_irq(&codec
->reg_lock
);
1763 static int snd_ali5451_spdif_put(struct snd_kcontrol
*kcontrol
,
1764 struct snd_ctl_elem_value
*ucontrol
)
1766 struct snd_ali
*codec
= kcontrol
->private_data
;
1767 unsigned int change
= 0, spdif_enable
= 0;
1769 spdif_enable
= ucontrol
->value
.integer
.value
[0] ? 1 : 0;
1771 spin_lock_irq(&codec
->reg_lock
);
1772 switch (kcontrol
->private_value
) {
1774 change
= (codec
->spdif_mask
& 0x02) ? 1 : 0;
1775 change
= change
^ spdif_enable
;
1778 codec
->spdif_mask
|= 0x02;
1779 snd_ali_enable_spdif_out(codec
);
1781 codec
->spdif_mask
&= ~(0x02);
1782 codec
->spdif_mask
&= ~(0x04);
1783 snd_ali_disable_spdif_out(codec
);
1788 change
= (codec
->spdif_mask
& 0x04) ? 1 : 0;
1789 change
= change
^ spdif_enable
;
1790 if (change
&& (codec
->spdif_mask
& 0x02)) {
1792 codec
->spdif_mask
|= 0x04;
1793 snd_ali_enable_spdif_chnout(codec
);
1795 codec
->spdif_mask
&= ~(0x04);
1796 snd_ali_disable_spdif_chnout(codec
);
1801 change
= (codec
->spdif_mask
& 0x01) ? 1 : 0;
1802 change
= change
^ spdif_enable
;
1805 codec
->spdif_mask
|= 0x01;
1806 snd_ali_enable_spdif_in(codec
);
1808 codec
->spdif_mask
&= ~(0x01);
1809 snd_ali_disable_spdif_in(codec
);
1816 spin_unlock_irq(&codec
->reg_lock
);
1821 static struct snd_kcontrol_new snd_ali5451_mixer_spdif
[] = {
1822 /* spdif aplayback switch */
1823 /* FIXME: "IEC958 Playback Switch" may conflict with one on ac97_codec */
1824 ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("Output ",NONE
,SWITCH
), 0, 0),
1825 /* spdif out to spdif channel */
1826 ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("Channel Output ",NONE
,SWITCH
), 0, 1),
1827 /* spdif in from spdif channel */
1828 ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), 0, 2)
1831 static int snd_ali_mixer(struct snd_ali
*codec
)
1833 struct snd_ac97_template ac97
;
1836 static struct snd_ac97_bus_ops ops
= {
1837 .write
= snd_ali_codec_write
,
1838 .read
= snd_ali_codec_read
,
1841 err
= snd_ac97_bus(codec
->card
, 0, &ops
, codec
, &codec
->ac97_bus
);
1845 memset(&ac97
, 0, sizeof(ac97
));
1846 ac97
.private_data
= codec
;
1848 for (i
= 0; i
< codec
->num_of_codecs
; i
++) {
1850 err
= snd_ac97_mixer(codec
->ac97_bus
, &ac97
, &codec
->ac97
[i
]);
1852 dev_err(codec
->card
->dev
,
1853 "ali mixer %d creating error.\n", i
);
1856 codec
->num_of_codecs
= 1;
1861 if (codec
->spdif_support
) {
1862 for (idx
= 0; idx
< ARRAY_SIZE(snd_ali5451_mixer_spdif
); idx
++) {
1863 err
= snd_ctl_add(codec
->card
,
1864 snd_ctl_new1(&snd_ali5451_mixer_spdif
[idx
], codec
));
1872 #ifdef CONFIG_PM_SLEEP
1873 static int ali_suspend(struct device
*dev
)
1875 struct snd_card
*card
= dev_get_drvdata(dev
);
1876 struct snd_ali
*chip
= card
->private_data
;
1877 struct snd_ali_image
*im
;
1884 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
1885 for (i
= 0; i
< chip
->num_of_codecs
; i
++) {
1886 snd_pcm_suspend_all(chip
->pcm
[i
]);
1887 snd_ac97_suspend(chip
->ac97
[i
]);
1890 spin_lock_irq(&chip
->reg_lock
);
1892 im
->regs
[ALI_MISCINT
>> 2] = inl(ALI_REG(chip
, ALI_MISCINT
));
1893 /* im->regs[ALI_START >> 2] = inl(ALI_REG(chip, ALI_START)); */
1894 im
->regs
[ALI_STOP
>> 2] = inl(ALI_REG(chip
, ALI_STOP
));
1896 /* disable all IRQ bits */
1897 outl(0, ALI_REG(chip
, ALI_MISCINT
));
1899 for (i
= 0; i
< ALI_GLOBAL_REGS
; i
++) {
1900 if ((i
*4 == ALI_MISCINT
) || (i
*4 == ALI_STOP
))
1902 im
->regs
[i
] = inl(ALI_REG(chip
, i
*4));
1905 for (i
= 0; i
< ALI_CHANNELS
; i
++) {
1906 outb(i
, ALI_REG(chip
, ALI_GC_CIR
));
1907 for (j
= 0; j
< ALI_CHANNEL_REGS
; j
++)
1908 im
->channel_regs
[i
][j
] = inl(ALI_REG(chip
, j
*4 + 0xe0));
1911 /* stop all HW channel */
1912 outl(0xffffffff, ALI_REG(chip
, ALI_STOP
));
1914 spin_unlock_irq(&chip
->reg_lock
);
1918 static int ali_resume(struct device
*dev
)
1920 struct snd_card
*card
= dev_get_drvdata(dev
);
1921 struct snd_ali
*chip
= card
->private_data
;
1922 struct snd_ali_image
*im
;
1929 spin_lock_irq(&chip
->reg_lock
);
1931 for (i
= 0; i
< ALI_CHANNELS
; i
++) {
1932 outb(i
, ALI_REG(chip
, ALI_GC_CIR
));
1933 for (j
= 0; j
< ALI_CHANNEL_REGS
; j
++)
1934 outl(im
->channel_regs
[i
][j
], ALI_REG(chip
, j
*4 + 0xe0));
1937 for (i
= 0; i
< ALI_GLOBAL_REGS
; i
++) {
1938 if ((i
*4 == ALI_MISCINT
) || (i
*4 == ALI_STOP
) ||
1941 outl(im
->regs
[i
], ALI_REG(chip
, i
*4));
1944 /* start HW channel */
1945 outl(im
->regs
[ALI_START
>> 2], ALI_REG(chip
, ALI_START
));
1946 /* restore IRQ enable bits */
1947 outl(im
->regs
[ALI_MISCINT
>> 2], ALI_REG(chip
, ALI_MISCINT
));
1949 spin_unlock_irq(&chip
->reg_lock
);
1951 for (i
= 0 ; i
< chip
->num_of_codecs
; i
++)
1952 snd_ac97_resume(chip
->ac97
[i
]);
1954 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
1958 static SIMPLE_DEV_PM_OPS(ali_pm
, ali_suspend
, ali_resume
);
1959 #define ALI_PM_OPS &ali_pm
1961 #define ALI_PM_OPS NULL
1962 #endif /* CONFIG_PM_SLEEP */
1964 static int snd_ali_free(struct snd_ali
* codec
)
1966 if (codec
->hw_initialized
)
1967 snd_ali_disable_address_interrupt(codec
);
1968 if (codec
->irq
>= 0)
1969 free_irq(codec
->irq
, codec
);
1971 pci_release_regions(codec
->pci
);
1972 pci_disable_device(codec
->pci
);
1973 #ifdef CONFIG_PM_SLEEP
1974 kfree(codec
->image
);
1976 pci_dev_put(codec
->pci_m1533
);
1977 pci_dev_put(codec
->pci_m7101
);
1982 static int snd_ali_chip_init(struct snd_ali
*codec
)
1984 unsigned int legacy
;
1986 struct pci_dev
*pci_dev
;
1988 dev_dbg(codec
->card
->dev
, "chip initializing ...\n");
1990 if (snd_ali_reset_5451(codec
)) {
1991 dev_err(codec
->card
->dev
, "ali_chip_init: reset 5451 error.\n");
1995 if (codec
->revision
== ALI_5451_V02
) {
1996 pci_dev
= codec
->pci_m1533
;
1997 pci_read_config_byte(pci_dev
, 0x59, &temp
);
1999 pci_write_config_byte(pci_dev
, 0x59, temp
);
2001 pci_dev
= codec
->pci_m7101
;
2002 pci_read_config_byte(pci_dev
, 0xb8, &temp
);
2004 pci_write_config_byte(pci_dev
, 0xB8, temp
);
2007 pci_read_config_dword(codec
->pci
, 0x44, &legacy
);
2008 legacy
&= 0xff00ff00;
2009 legacy
|= 0x000800aa;
2010 pci_write_config_dword(codec
->pci
, 0x44, legacy
);
2012 outl(0x80000001, ALI_REG(codec
, ALI_GLOBAL_CONTROL
));
2013 outl(0x00000000, ALI_REG(codec
, ALI_AINTEN
));
2014 outl(0xffffffff, ALI_REG(codec
, ALI_AINT
));
2015 outl(0x00000000, ALI_REG(codec
, ALI_VOLUME
));
2016 outb(0x10, ALI_REG(codec
, ALI_MPUR2
));
2018 codec
->ac97_ext_id
= snd_ali_codec_peek(codec
, 0, AC97_EXTENDED_ID
);
2019 codec
->ac97_ext_status
= snd_ali_codec_peek(codec
, 0,
2020 AC97_EXTENDED_STATUS
);
2021 if (codec
->spdif_support
) {
2022 snd_ali_enable_spdif_out(codec
);
2023 codec
->spdif_mask
= 0x00000002;
2026 codec
->num_of_codecs
= 1;
2028 /* secondary codec - modem */
2029 if (inl(ALI_REG(codec
, ALI_SCTRL
)) & ALI_SCTRL_CODEC2_READY
) {
2030 codec
->num_of_codecs
++;
2031 outl(inl(ALI_REG(codec
, ALI_SCTRL
)) |
2032 (ALI_SCTRL_LINE_IN2
| ALI_SCTRL_GPIO_IN2
|
2033 ALI_SCTRL_LINE_OUT_EN
),
2034 ALI_REG(codec
, ALI_SCTRL
));
2037 dev_dbg(codec
->card
->dev
, "chip initialize succeed.\n");
2042 /* proc for register dump */
2043 static void snd_ali_proc_read(struct snd_info_entry
*entry
,
2044 struct snd_info_buffer
*buf
)
2046 struct snd_ali
*codec
= entry
->private_data
;
2048 for (i
= 0; i
< 256 ; i
+= 4)
2049 snd_iprintf(buf
, "%02x: %08x\n", i
, inl(ALI_REG(codec
, i
)));
2052 static void snd_ali_proc_init(struct snd_ali
*codec
)
2054 struct snd_info_entry
*entry
;
2055 if (!snd_card_proc_new(codec
->card
, "ali5451", &entry
))
2056 snd_info_set_text_ops(entry
, codec
, snd_ali_proc_read
);
2059 static int snd_ali_resources(struct snd_ali
*codec
)
2063 dev_dbg(codec
->card
->dev
, "resources allocation ...\n");
2064 err
= pci_request_regions(codec
->pci
, "ALI 5451");
2067 codec
->port
= pci_resource_start(codec
->pci
, 0);
2069 if (request_irq(codec
->pci
->irq
, snd_ali_card_interrupt
,
2070 IRQF_SHARED
, KBUILD_MODNAME
, codec
)) {
2071 dev_err(codec
->card
->dev
, "Unable to request irq.\n");
2074 codec
->irq
= codec
->pci
->irq
;
2075 dev_dbg(codec
->card
->dev
, "resources allocated.\n");
2078 static int snd_ali_dev_free(struct snd_device
*device
)
2080 struct snd_ali
*codec
= device
->device_data
;
2081 snd_ali_free(codec
);
2085 static int snd_ali_create(struct snd_card
*card
,
2086 struct pci_dev
*pci
,
2089 struct snd_ali
**r_ali
)
2091 struct snd_ali
*codec
;
2093 unsigned short cmdw
;
2094 static struct snd_device_ops ops
= {
2095 .dev_free
= snd_ali_dev_free
,
2100 dev_dbg(card
->dev
, "creating ...\n");
2102 /* enable PCI device */
2103 err
= pci_enable_device(pci
);
2106 /* check, if we can restrict PCI DMA transfers to 31 bits */
2107 if (dma_set_mask(&pci
->dev
, DMA_BIT_MASK(31)) < 0 ||
2108 dma_set_coherent_mask(&pci
->dev
, DMA_BIT_MASK(31)) < 0) {
2110 "architecture does not support 31bit PCI busmaster DMA\n");
2111 pci_disable_device(pci
);
2115 codec
= kzalloc(sizeof(*codec
), GFP_KERNEL
);
2117 pci_disable_device(pci
);
2121 spin_lock_init(&codec
->reg_lock
);
2122 spin_lock_init(&codec
->voice_alloc
);
2127 codec
->revision
= pci
->revision
;
2128 codec
->spdif_support
= spdif_support
;
2130 if (pcm_streams
< 1)
2132 if (pcm_streams
> 32)
2135 pci_set_master(pci
);
2136 pci_read_config_word(pci
, PCI_COMMAND
, &cmdw
);
2137 if ((cmdw
& PCI_COMMAND_IO
) != PCI_COMMAND_IO
) {
2138 cmdw
|= PCI_COMMAND_IO
;
2139 pci_write_config_word(pci
, PCI_COMMAND
, cmdw
);
2141 pci_set_master(pci
);
2143 if (snd_ali_resources(codec
)) {
2144 snd_ali_free(codec
);
2148 synchronize_irq(pci
->irq
);
2150 codec
->synth
.chmap
= 0;
2151 codec
->synth
.chcnt
= 0;
2152 codec
->spdif_mask
= 0;
2153 codec
->synth
.synthcount
= 0;
2155 if (codec
->revision
== ALI_5451_V02
)
2156 codec
->chregs
.regs
.ac97read
= ALI_AC97_WRITE
;
2158 codec
->chregs
.regs
.ac97read
= ALI_AC97_READ
;
2159 codec
->chregs
.regs
.ac97write
= ALI_AC97_WRITE
;
2161 codec
->chregs
.regs
.start
= ALI_START
;
2162 codec
->chregs
.regs
.stop
= ALI_STOP
;
2163 codec
->chregs
.regs
.aint
= ALI_AINT
;
2164 codec
->chregs
.regs
.ainten
= ALI_AINTEN
;
2166 codec
->chregs
.data
.start
= 0x00;
2167 codec
->chregs
.data
.stop
= 0x00;
2168 codec
->chregs
.data
.aint
= 0x00;
2169 codec
->chregs
.data
.ainten
= 0x00;
2171 /* M1533: southbridge */
2172 codec
->pci_m1533
= pci_get_device(0x10b9, 0x1533, NULL
);
2173 if (!codec
->pci_m1533
) {
2174 dev_err(card
->dev
, "cannot find ALi 1533 chip.\n");
2175 snd_ali_free(codec
);
2178 /* M7101: power management */
2179 codec
->pci_m7101
= pci_get_device(0x10b9, 0x7101, NULL
);
2180 if (!codec
->pci_m7101
&& codec
->revision
== ALI_5451_V02
) {
2181 dev_err(card
->dev
, "cannot find ALi 7101 chip.\n");
2182 snd_ali_free(codec
);
2186 dev_dbg(card
->dev
, "snd_device_new is called.\n");
2187 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, codec
, &ops
);
2189 snd_ali_free(codec
);
2193 /* initialise synth voices*/
2194 for (i
= 0; i
< ALI_CHANNELS
; i
++)
2195 codec
->synth
.voices
[i
].number
= i
;
2197 err
= snd_ali_chip_init(codec
);
2199 dev_err(card
->dev
, "ali create: chip init error.\n");
2203 #ifdef CONFIG_PM_SLEEP
2204 codec
->image
= kmalloc(sizeof(*codec
->image
), GFP_KERNEL
);
2206 dev_warn(card
->dev
, "can't allocate apm buffer\n");
2209 snd_ali_enable_address_interrupt(codec
);
2210 codec
->hw_initialized
= 1;
2213 dev_dbg(card
->dev
, "created.\n");
2217 static int snd_ali_probe(struct pci_dev
*pci
,
2218 const struct pci_device_id
*pci_id
)
2220 struct snd_card
*card
;
2221 struct snd_ali
*codec
;
2224 dev_dbg(&pci
->dev
, "probe ...\n");
2226 err
= snd_card_new(&pci
->dev
, index
, id
, THIS_MODULE
, 0, &card
);
2230 err
= snd_ali_create(card
, pci
, pcm_channels
, spdif
, &codec
);
2233 card
->private_data
= codec
;
2235 dev_dbg(&pci
->dev
, "mixer building ...\n");
2236 err
= snd_ali_mixer(codec
);
2240 dev_dbg(&pci
->dev
, "pcm building ...\n");
2241 err
= snd_ali_build_pcms(codec
);
2245 snd_ali_proc_init(codec
);
2247 strcpy(card
->driver
, "ALI5451");
2248 strcpy(card
->shortname
, "ALI 5451");
2250 sprintf(card
->longname
, "%s at 0x%lx, irq %i",
2251 card
->shortname
, codec
->port
, codec
->irq
);
2253 dev_dbg(&pci
->dev
, "register card.\n");
2254 err
= snd_card_register(card
);
2258 pci_set_drvdata(pci
, card
);
2262 snd_card_free(card
);
2266 static void snd_ali_remove(struct pci_dev
*pci
)
2268 snd_card_free(pci_get_drvdata(pci
));
2271 static struct pci_driver ali5451_driver
= {
2272 .name
= KBUILD_MODNAME
,
2273 .id_table
= snd_ali_ids
,
2274 .probe
= snd_ali_probe
,
2275 .remove
= snd_ali_remove
,
2281 module_pci_driver(ali5451_driver
);