X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Fali5451%2Fali5451.c;h=74668398eac5da125b790cf5fe3cf5d7325f9ab0;hb=16c70f8c1b54b61c3b951b6fb220df250fe09b32;hp=d149409f2b8db5ab4ae91dc56a477bd70936e0c9;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c index d149409f2..74668398e 100644 --- a/sound/pci/ali5451/ali5451.c +++ b/sound/pci/ali5451/ali5451.c @@ -25,8 +25,6 @@ * */ -#define __SNDRV_OSS_COMPAT__ - #include #include #include @@ -34,41 +32,38 @@ #include #include #include +#include +#include #include #include #include #include #include -#define SNDRV_GET_ID #include MODULE_AUTHOR("Matt Wu "); MODULE_DESCRIPTION("ALI M5451"); MODULE_LICENSE("GPL"); -MODULE_CLASSES("{sound}"); -MODULE_DEVICES("{{ALI,M5451,pci},{ALI,M5451}}"); +MODULE_SUPPORTED_DEVICE("{{ALI,M5451,pci},{ALI,M5451}}"); -static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ -static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ -static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; -static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 32}; -static int spdif[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; +static int index = SNDRV_DEFAULT_IDX1; /* Index */ +static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ +static int pcm_channels = 32; +static int spdif; -MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param(index, int, 0444); MODULE_PARM_DESC(index, "Index value for ALI M5451 PCI Audio."); -MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); -MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s"); +module_param(id, charp, 0444); MODULE_PARM_DESC(id, "ID string for ALI M5451 PCI Audio."); -MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); -MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); -MODULE_PARM_DESC(enable, "Enable ALI 5451 PCI Audio."); -MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); -MODULE_PARM(pcm_channels, "1-" __MODULE_STRING(SNDRV_CARDS) "l"); +module_param(pcm_channels, int, 0444); MODULE_PARM_DESC(pcm_channels, "PCM Channels"); -MODULE_PARM_SYNTAX(pcm_channels, SNDRV_ENABLED ",default:32,allows:{{1,32}}"); -MODULE_PARM(spdif, "1-" __MODULE_STRING(SNDRV_CARDS) "l"); +module_param(spdif, bool, 0444); MODULE_PARM_DESC(spdif, "Support SPDIF I/O"); -MODULE_PARM_SYNTAX(spdif, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC); + +/* just for backward compatibility */ +static int enable; +module_param(enable, bool, 0444); + /* * Debug part definitions @@ -86,15 +81,7 @@ MODULE_PARM_SYNTAX(spdif, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC); * Constants definition */ -#ifndef PCI_VENDOR_ID_ALI -#define PCI_VENDOR_ID_ALI 0x10b9 -#endif - -#ifndef PCI_DEVICE_ID_ALI_5451 -#define PCI_DEVICE_ID_ALI_5451 0x5451 -#endif - -#define DEVICE_ID_ALI5451 ((PCI_VENDOR_ID_ALI<<16)|PCI_DEVICE_ID_ALI_5451) +#define DEVICE_ID_ALI5451 ((PCI_VENDOR_ID_AL<<16)|PCI_DEVICE_ID_AL_M5451) #define ALI_CHANNELS 32 @@ -106,6 +93,8 @@ MODULE_PARM_SYNTAX(spdif, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC); #define ALI_LEF_CHANNEL 23 #define ALI_SURR_LEFT_CHANNEL 26 #define ALI_SURR_RIGHT_CHANNEL 25 +#define ALI_MODEM_IN_CHANNEL 21 +#define ALI_MODEM_OUT_CHANNEL 20 #define SNDRV_ALI_VOICE_TYPE_PCM 01 #define SNDRV_ALI_VOICE_TYPE_OTH 02 @@ -130,7 +119,15 @@ MODULE_PARM_SYNTAX(spdif, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC); #define ALI_SCTRL 0x48 #define ALI_SPDIF_OUT_ENABLE 0x20 +#define ALI_SCTRL_LINE_IN2 (1 << 9) +#define ALI_SCTRL_GPIO_IN2 (1 << 13) +#define ALI_SCTRL_LINE_OUT_EN (1 << 20) +#define ALI_SCTRL_GPIO_OUT_EN (1 << 23) +#define ALI_SCTRL_CODEC1_READY (1 << 24) +#define ALI_SCTRL_CODEC2_READY (1 << 25) #define ALI_AC97_GPIO 0x4c +#define ALI_AC97_GPIO_ENABLE 0x8000 +#define ALI_AC97_GPIO_DATA_SHIFT 16 #define ALI_SPDIF_CS 0x70 #define ALI_SPDIF_CTRL 0x74 #define ALI_SPDIF_IN_FUNC_ENABLE 0x02 @@ -151,6 +148,7 @@ MODULE_PARM_SYNTAX(spdif, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC); #define TARGET_REACHED 0x00008000 #define MIXER_OVERFLOW 0x00000800 #define MIXER_UNDERFLOW 0x00000400 + #define GPIO_IRQ 0x01000000 #define ALI_SBBL_SBCL 0xc0 #define ALI_SBCTRL_SBE2R_SBDD 0xc4 #define ALI_STIMER 0xc8 @@ -170,11 +168,13 @@ MODULE_PARM_SYNTAX(spdif, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC); #define ALI_REG(codec, x) ((codec)->port + x) -typedef struct snd_stru_ali ali_t; -typedef struct snd_ali_stru_voice snd_ali_voice_t; -#define chip_t ali_t +#define MAX_CODECS 2 + -typedef struct snd_ali_channel_control { +struct snd_ali; +struct snd_ali_voice; + +struct snd_ali_channel_control { // register data struct REGDATA { unsigned int start; @@ -193,22 +193,22 @@ typedef struct snd_ali_channel_control { unsigned int ac97write; } regs; -} snd_ali_channel_control_t; +}; -struct snd_ali_stru_voice { +struct snd_ali_voice { unsigned int number; - int use: 1, + unsigned int use: 1, pcm: 1, midi: 1, mode: 1, synth: 1; /* PCM data */ - ali_t *codec; - snd_pcm_substream_t *substream; - snd_ali_voice_t *extra; + struct snd_ali *codec; + struct snd_pcm_substream *substream; + struct snd_ali_voice *extra; - int running: 1; + unsigned int running: 1; int eso; /* final ESO value for channel */ int count; /* runtime->period_size */ @@ -220,44 +220,43 @@ struct snd_ali_stru_voice { }; -typedef struct snd_stru_alidev { +struct snd_alidev { - snd_ali_voice_t voices[ALI_CHANNELS]; + struct snd_ali_voice voices[ALI_CHANNELS]; unsigned int chcnt; /* num of opened channels */ unsigned int chmap; /* bitmap for opened channels */ unsigned int synthcount; -} alidev_t; +}; #ifdef CONFIG_PM #define ALI_GLOBAL_REGS 56 #define ALI_CHANNEL_REGS 8 -typedef struct snd_ali_image { +struct snd_ali_image { unsigned long regs[ALI_GLOBAL_REGS]; unsigned long channel_regs[ALI_CHANNELS][ALI_CHANNEL_REGS]; -} ali_image_t; +}; #endif -struct snd_stru_ali { +struct snd_ali { unsigned long irq; unsigned long port; unsigned char revision; unsigned int hw_initialized: 1; unsigned int spdif_support: 1; - struct resource *res_port; struct pci_dev *pci; struct pci_dev *pci_m1533; struct pci_dev *pci_m7101; - snd_card_t *card; - snd_pcm_t *pcm; - alidev_t synth; - snd_ali_channel_control_t chregs; + struct snd_card *card; + struct snd_pcm *pcm[MAX_CODECS]; + struct snd_alidev synth; + struct snd_ali_channel_control chregs; /* S/PDIF Mask */ unsigned int spdif_mask; @@ -265,8 +264,10 @@ struct snd_stru_ali { unsigned int spurious_irq_count; unsigned int spurious_irq_max_delta; - ac97_bus_t *ac97_bus; - ac97_t *ac97; + unsigned int num_of_codecs; + + struct snd_ac97_bus *ac97_bus; + struct snd_ac97 *ac97[MAX_CODECS]; unsigned short ac97_ext_id; unsigned short ac97_ext_status; @@ -274,19 +275,19 @@ struct snd_stru_ali { spinlock_t voice_alloc; #ifdef CONFIG_PM - ali_image_t *image; + struct snd_ali_image *image; #endif }; static struct pci_device_id snd_ali_ids[] = { - {0x10b9, 0x5451, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, + {PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5451), 0, 0, 0}, {0, } }; MODULE_DEVICE_TABLE(pci, snd_ali_ids); -static void snd_ali_clear_voices(ali_t *, unsigned int, unsigned int); -static unsigned short snd_ali_codec_peek(ali_t *, int, unsigned short); -static void snd_ali_codec_poke(ali_t *, int, unsigned short, unsigned short); +static void snd_ali_clear_voices(struct snd_ali *, unsigned int, unsigned int); +static unsigned short snd_ali_codec_peek(struct snd_ali *, int, unsigned short); +static void snd_ali_codec_poke(struct snd_ali *, int, unsigned short, unsigned short); /* * Debug Part @@ -294,7 +295,7 @@ static void snd_ali_codec_poke(ali_t *, int, unsigned short, unsigned short); #ifdef ALI_DEBUG -static void ali_read_regs(ali_t *codec, int channel) +static void ali_read_regs(struct snd_ali *codec, int channel) { int i,j; unsigned int dwVal; @@ -320,13 +321,12 @@ static void ali_read_regs(ali_t *codec, int channel) static void ali_read_cfg(unsigned int vendor, unsigned deviceid) { unsigned int dwVal; - struct pci_dev *pci_dev = NULL; + struct pci_dev *pci_dev; int i,j; - - pci_dev = pci_find_device(vendor, deviceid, pci_dev); - if (pci_dev == NULL) - return ; + pci_dev = pci_get_device(vendor, deviceid, NULL); + if (pci_dev == NULL) + return ; printk("\nM%x PCI CFG\n", deviceid); printk(" "); @@ -343,8 +343,9 @@ static void ali_read_cfg(unsigned int vendor, unsigned deviceid) } printk("\n"); } + pci_dev_put(pci_dev); } -static void ali_read_ac97regs(ali_t *codec, int secondary) +static void ali_read_ac97regs(struct snd_ali *codec, int secondary) { unsigned short i,j; unsigned short wVal; @@ -373,42 +374,38 @@ static void ali_read_ac97regs(ali_t *codec, int secondary) * AC97 ACCESS */ -static inline unsigned int snd_ali_5451_peek(ali_t *codec, +static inline unsigned int snd_ali_5451_peek(struct snd_ali *codec, unsigned int port ) { return (unsigned int)inl(ALI_REG(codec, port)); } -static inline void snd_ali_5451_poke( ali_t *codec, +static inline void snd_ali_5451_poke( struct snd_ali *codec, unsigned int port, unsigned int val ) { outl((unsigned int)val, ALI_REG(codec, port)); } -static int snd_ali_codec_ready( ali_t *codec, - unsigned int port, - int sched ) +static int snd_ali_codec_ready( struct snd_ali *codec, + unsigned int port ) { unsigned long end_time; unsigned int res; - end_time = jiffies + 10 * (HZ >> 2); + end_time = jiffies + msecs_to_jiffies(250); do { res = snd_ali_5451_peek(codec,port); if (! (res & 0x8000)) return 0; - if (sched) { - set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(1); - } + schedule_timeout_uninterruptible(1); } while (time_after_eq(end_time, jiffies)); snd_ali_5451_poke(codec, port, res & ~0x8000); snd_printdd("ali_codec_ready: codec is not ready.\n "); return -EIO; } -static int snd_ali_stimer_ready(ali_t *codec, int sched) +static int snd_ali_stimer_ready(struct snd_ali *codec) { unsigned long end_time; unsigned long dwChk1,dwChk2; @@ -416,21 +413,18 @@ static int snd_ali_stimer_ready(ali_t *codec, int sched) dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER); dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); - end_time = jiffies + 10 * (HZ >> 2); + end_time = jiffies + msecs_to_jiffies(250); do { dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); if (dwChk2 != dwChk1) return 0; - if (sched) { - set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(1); - } + schedule_timeout_uninterruptible(1); } while (time_after_eq(end_time, jiffies)); - snd_printk("ali_stimer_read: stimer is not ready.\n"); + snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n"); return -EIO; } -static void snd_ali_codec_poke(ali_t *codec,int secondary, +static void snd_ali_codec_poke(struct snd_ali *codec,int secondary, unsigned short reg, unsigned short val) { @@ -438,15 +432,15 @@ static void snd_ali_codec_poke(ali_t *codec,int secondary, unsigned int port = 0; if (reg >= 0x80) { - snd_printk("ali_codec_poke: reg(%xh) invalid.\n", reg); + snd_printk(KERN_ERR "ali_codec_poke: reg(%xh) invalid.\n", reg); return; } port = codec->chregs.regs.ac97write; - if (snd_ali_codec_ready(codec, port, 0) < 0) + if (snd_ali_codec_ready(codec, port) < 0) return; - if (snd_ali_stimer_ready(codec, 0) < 0) + if (snd_ali_stimer_ready(codec) < 0) return; dwVal = (unsigned int) (reg & 0xff); @@ -459,7 +453,7 @@ static void snd_ali_codec_poke(ali_t *codec,int secondary, return ; } -static unsigned short snd_ali_codec_peek( ali_t *codec, +static unsigned short snd_ali_codec_peek( struct snd_ali *codec, int secondary, unsigned short reg) { @@ -467,15 +461,15 @@ static unsigned short snd_ali_codec_peek( ali_t *codec, unsigned int port = 0; if (reg >= 0x80) { - snd_printk("ali_codec_peek: reg(%xh) invalid.\n", reg); + snd_printk(KERN_ERR "ali_codec_peek: reg(%xh) invalid.\n", reg); return ~0; } port = codec->chregs.regs.ac97read; - if (snd_ali_codec_ready(codec, port, 0) < 0) + if (snd_ali_codec_ready(codec, port) < 0) return ~0; - if (snd_ali_stimer_ready(codec, 0) < 0) + if (snd_ali_stimer_ready(codec) < 0) return ~0; dwVal = (unsigned int) (reg & 0xff); @@ -484,39 +478,44 @@ static unsigned short snd_ali_codec_peek( ali_t *codec, snd_ali_5451_poke(codec, port, dwVal); - if (snd_ali_stimer_ready(codec, 0) < 0) + if (snd_ali_stimer_ready(codec) < 0) return ~0; - if (snd_ali_codec_ready(codec, port, 0) < 0) + if (snd_ali_codec_ready(codec, port) < 0) return ~0; return (snd_ali_5451_peek(codec, port) & 0xffff0000)>>16; } -static void snd_ali_codec_write(ac97_t *ac97, +static void snd_ali_codec_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val ) { - ali_t *codec = snd_magic_cast(ali_t, ac97->private_data, return); + struct snd_ali *codec = ac97->private_data; snd_ali_printk("codec_write: reg=%xh data=%xh.\n", reg, val); - snd_ali_codec_poke(codec, 0, reg, val); + if(reg == AC97_GPIO_STATUS) { + outl((val << ALI_AC97_GPIO_DATA_SHIFT)|ALI_AC97_GPIO_ENABLE, + ALI_REG(codec, ALI_AC97_GPIO)); + return; + } + snd_ali_codec_poke(codec, ac97->num, reg, val); return ; } -static unsigned short snd_ali_codec_read(ac97_t *ac97, unsigned short reg) +static unsigned short snd_ali_codec_read(struct snd_ac97 *ac97, unsigned short reg) { - ali_t *codec = snd_magic_cast(ali_t, ac97->private_data, return -ENXIO); + struct snd_ali *codec = ac97->private_data; snd_ali_printk("codec_read reg=%xh.\n", reg); - return (snd_ali_codec_peek(codec, 0, reg)); + return (snd_ali_codec_peek(codec, ac97->num, reg)); } /* * AC97 Reset */ -static int snd_ali_reset_5451(ali_t *codec) +static int snd_ali_reset_5451(struct snd_ali *codec) { struct pci_dev *pci_dev = NULL; unsigned short wCount, wReg; @@ -554,7 +553,7 @@ static int snd_ali_reset_5451(ali_t *codec) #ifdef CODEC_RESET -static int snd_ali_reset_codec(ali_t *codec) +static int snd_ali_reset_codec(struct snd_ali *codec) { struct pci_dev *pci_dev = NULL; unsigned char bVal = 0; @@ -595,7 +594,7 @@ static int snd_ali_reset_codec(ali_t *codec) * ALI 5451 Controller */ -static void snd_ali_enable_special_channel(ali_t *codec, unsigned int channel) +static void snd_ali_enable_special_channel(struct snd_ali *codec, unsigned int channel) { unsigned long dwVal = 0; @@ -604,7 +603,7 @@ static void snd_ali_enable_special_channel(ali_t *codec, unsigned int channel) outl(dwVal, ALI_REG(codec,ALI_GLOBAL_CONTROL)); } -static void snd_ali_disable_special_channel(ali_t *codec, unsigned int channel) +static void snd_ali_disable_special_channel(struct snd_ali *codec, unsigned int channel) { unsigned long dwVal = 0; @@ -613,7 +612,7 @@ static void snd_ali_disable_special_channel(ali_t *codec, unsigned int channel) outl(dwVal, ALI_REG(codec,ALI_GLOBAL_CONTROL)); } -static void snd_ali_enable_address_interrupt(ali_t * codec) +static void snd_ali_enable_address_interrupt(struct snd_ali * codec) { unsigned int gc; @@ -623,7 +622,7 @@ static void snd_ali_enable_address_interrupt(ali_t * codec) outl( gc, ALI_REG(codec, ALI_GC_CIR)); } -static void snd_ali_disable_address_interrupt(ali_t * codec) +static void snd_ali_disable_address_interrupt(struct snd_ali * codec) { unsigned int gc; @@ -634,10 +633,10 @@ static void snd_ali_disable_address_interrupt(ali_t * codec) } #if 0 // not used -static void snd_ali_enable_voice_irq(ali_t *codec, unsigned int channel) +static void snd_ali_enable_voice_irq(struct snd_ali *codec, unsigned int channel) { unsigned int mask; - snd_ali_channel_control_t *pchregs = &(codec->chregs); + struct snd_ali_channel_control *pchregs = &(codec->chregs); snd_ali_printk("enable_voice_irq channel=%d\n",channel); @@ -648,10 +647,10 @@ static void snd_ali_enable_voice_irq(ali_t *codec, unsigned int channel) } #endif -static void snd_ali_disable_voice_irq(ali_t *codec, unsigned int channel) +static void snd_ali_disable_voice_irq(struct snd_ali *codec, unsigned int channel) { unsigned int mask; - snd_ali_channel_control_t *pchregs = &(codec->chregs); + struct snd_ali_channel_control *pchregs = &(codec->chregs); snd_ali_printk("disable_voice_irq channel=%d\n",channel); @@ -661,12 +660,12 @@ static void snd_ali_disable_voice_irq(ali_t *codec, unsigned int channel) outl(pchregs->data.ainten,ALI_REG(codec,pchregs->regs.ainten)); } -static int snd_ali_alloc_pcm_channel(ali_t *codec, int channel) +static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel) { unsigned int idx = channel & 0x1f; if (codec->synth.chcnt >= ALI_CHANNELS){ - snd_printk("ali_alloc_pcm_channel: no free channels.\n"); + snd_printk(KERN_ERR "ali_alloc_pcm_channel: no free channels.\n"); return -1; } @@ -679,7 +678,7 @@ static int snd_ali_alloc_pcm_channel(ali_t *codec, int channel) return -1; } -static int snd_ali_find_free_channel(ali_t * codec, int rec) +static int snd_ali_find_free_channel(struct snd_ali * codec, int rec) { int idx; int result = -1; @@ -697,7 +696,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec) if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) { return result; } else { - snd_printk("ali_find_free_channel: record channel is busy now.\n"); + snd_printk(KERN_ERR "ali_find_free_channel: record channel is busy now.\n"); return -1; } } @@ -709,7 +708,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec) if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) { return result; } else { - snd_printk("ali_find_free_channel: S/PDIF out channel is in busy now.\n"); + snd_printk(KERN_ERR "ali_find_free_channel: S/PDIF out channel is in busy now.\n"); } } @@ -717,11 +716,11 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec) if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) return result; } - snd_printk("ali_find_free_channel: no free channels.\n"); + snd_printk(KERN_ERR "ali_find_free_channel: no free channels.\n"); return -1; } -static void snd_ali_free_channel_pcm(ali_t *codec, int channel) +static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel) { unsigned int idx = channel & 0x0000001f; @@ -731,7 +730,7 @@ static void snd_ali_free_channel_pcm(ali_t *codec, int channel) return; if (!(codec->synth.chmap & (1 << idx))) { - snd_printk("ali_free_channel_pcm: channel %d is not in use.\n",channel); + snd_printk(KERN_ERR "ali_free_channel_pcm: channel %d is not in use.\n",channel); return; } else { codec->synth.chmap &= ~(1 << idx); @@ -740,7 +739,7 @@ static void snd_ali_free_channel_pcm(ali_t *codec, int channel) } #if 0 // not used -static void snd_ali_start_voice(ali_t * codec, unsigned int channel) +static void snd_ali_start_voice(struct snd_ali * codec, unsigned int channel) { unsigned int mask = 1 << (channel & 0x1f); @@ -749,7 +748,7 @@ static void snd_ali_start_voice(ali_t * codec, unsigned int channel) } #endif -static void snd_ali_stop_voice(ali_t * codec, unsigned int channel) +static void snd_ali_stop_voice(struct snd_ali * codec, unsigned int channel) { unsigned int mask = 1 << (channel & 0x1f); @@ -761,7 +760,7 @@ static void snd_ali_stop_voice(ali_t * codec, unsigned int channel) * S/PDIF Part */ -static void snd_ali_delay(ali_t *codec,int interval) +static void snd_ali_delay(struct snd_ali *codec,int interval) { unsigned long begintimer,currenttimer; @@ -769,13 +768,13 @@ static void snd_ali_delay(ali_t *codec,int interval) currenttimer = inl(ALI_REG(codec, ALI_STIMER)); while (currenttimer < begintimer + interval) { - if(snd_ali_stimer_ready(codec, 1) < 0) + if(snd_ali_stimer_ready(codec) < 0) break; currenttimer = inl(ALI_REG(codec, ALI_STIMER)); } } -static void snd_ali_detect_spdif_rate(ali_t *codec) +static void snd_ali_detect_spdif_rate(struct snd_ali *codec) { u16 wval = 0; u16 count = 0; @@ -793,7 +792,7 @@ static void snd_ali_detect_spdif_rate(ali_t *codec) } if (count > 50000) { - snd_printk("ali_detect_spdif_rate: timeout!\n"); + snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n"); return; } @@ -806,7 +805,7 @@ static void snd_ali_detect_spdif_rate(ali_t *codec) } if (count > 50000) { - snd_printk("ali_detect_spdif_rate: timeout!\n"); + snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n"); return; } @@ -829,7 +828,7 @@ static void snd_ali_detect_spdif_rate(ali_t *codec) } } -static unsigned int snd_ali_get_spdif_in_rate(ali_t *codec) +static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali *codec) { u32 dwRate = 0; u8 bval = 0; @@ -851,7 +850,7 @@ static unsigned int snd_ali_get_spdif_in_rate(ali_t *codec) return dwRate; } -static void snd_ali_enable_spdif_in(ali_t *codec) +static void snd_ali_enable_spdif_in(struct snd_ali *codec) { unsigned int dwVal; @@ -866,7 +865,7 @@ static void snd_ali_enable_spdif_in(ali_t *codec) snd_ali_enable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); } -static void snd_ali_disable_spdif_in(ali_t *codec) +static void snd_ali_disable_spdif_in(struct snd_ali *codec) { unsigned int dwVal; @@ -878,7 +877,7 @@ static void snd_ali_disable_spdif_in(ali_t *codec) } -static void snd_ali_set_spdif_out_rate(ali_t *codec, unsigned int rate) +static void snd_ali_set_spdif_out_rate(struct snd_ali *codec, unsigned int rate) { unsigned char bVal; unsigned int dwRate = 0; @@ -899,7 +898,7 @@ static void snd_ali_set_spdif_out_rate(ali_t *codec, unsigned int rate) outw(rate | 0x10, ALI_REG(codec, ALI_SPDIF_CS + 2)); } -static void snd_ali_enable_spdif_out(ali_t *codec) +static void snd_ali_enable_spdif_out(struct snd_ali *codec) { unsigned short wVal; unsigned char bVal; @@ -935,7 +934,7 @@ static void snd_ali_enable_spdif_out(ali_t *codec) } } -static void snd_ali_enable_spdif_chnout(ali_t *codec) +static void snd_ali_enable_spdif_chnout(struct snd_ali *codec) { unsigned short wVal = 0; @@ -953,7 +952,7 @@ static void snd_ali_enable_spdif_chnout(ali_t *codec) snd_ali_enable_special_channel(codec,ALI_SPDIF_OUT_CHANNEL); } -static void snd_ali_disable_spdif_chnout(ali_t *codec) +static void snd_ali_disable_spdif_chnout(struct snd_ali *codec) { unsigned short wVal = 0; wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); @@ -963,7 +962,7 @@ static void snd_ali_disable_spdif_chnout(ali_t *codec) snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); } -static void snd_ali_disable_spdif_out(ali_t *codec) +static void snd_ali_disable_spdif_out(struct snd_ali *codec) { unsigned char bVal; @@ -973,11 +972,11 @@ static void snd_ali_disable_spdif_out(ali_t *codec) snd_ali_disable_spdif_chnout(codec); } -static void snd_ali_update_ptr(ali_t *codec,int channel) +static void snd_ali_update_ptr(struct snd_ali *codec,int channel) { - snd_ali_voice_t *pvoice = NULL; - snd_pcm_runtime_t *runtime; - snd_ali_channel_control_t *pchregs = NULL; + struct snd_ali_voice *pvoice = NULL; + struct snd_pcm_runtime *runtime; + struct snd_ali_channel_control *pchregs = NULL; unsigned int old, mask; #ifdef ALI_DEBUG unsigned int temp, cspf; @@ -1028,11 +1027,11 @@ static void snd_ali_update_ptr(ali_t *codec,int channel) pchregs->data.aint = old & (~mask); } -static void snd_ali_interrupt(ali_t * codec) +static void snd_ali_interrupt(struct snd_ali * codec) { int channel; unsigned int audio_int; - snd_ali_channel_control_t *pchregs = NULL; + struct snd_ali_channel_control *pchregs = NULL; pchregs = &(codec->chregs); audio_int = inl(ALI_REG(codec, ALI_MISCINT)); @@ -1052,7 +1051,7 @@ static irqreturn_t snd_ali_card_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - ali_t *codec = snd_magic_cast(ali_t, dev_id, return IRQ_NONE); + struct snd_ali *codec = dev_id; if (codec == NULL) return IRQ_NONE; @@ -1061,37 +1060,37 @@ static irqreturn_t snd_ali_card_interrupt(int irq, } -static snd_ali_voice_t *snd_ali_alloc_voice(ali_t * codec, int type, int rec) +static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec, int type, int rec, int channel) { - snd_ali_voice_t *pvoice = NULL; - unsigned long flags; + struct snd_ali_voice *pvoice = NULL; int idx; snd_ali_printk("alloc_voice: type=%d rec=%d\n",type,rec); - spin_lock_irqsave(&codec->voice_alloc, flags); + spin_lock_irq(&codec->voice_alloc); if (type == SNDRV_ALI_VOICE_TYPE_PCM) { - idx = snd_ali_find_free_channel(codec,rec); + idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : + snd_ali_find_free_channel(codec,rec); if(idx < 0) { - snd_printk("ali_alloc_voice: err.\n"); - spin_unlock_irqrestore(&codec->voice_alloc, flags); + snd_printk(KERN_ERR "ali_alloc_voice: err.\n"); + spin_unlock_irq(&codec->voice_alloc); return NULL; } pvoice = &(codec->synth.voices[idx]); + pvoice->codec = codec; pvoice->use = 1; pvoice->pcm = 1; pvoice->mode = rec; - spin_unlock_irqrestore(&codec->voice_alloc, flags); + spin_unlock_irq(&codec->voice_alloc); return pvoice; } - spin_unlock_irqrestore(&codec->voice_alloc, flags); + spin_unlock_irq(&codec->voice_alloc); return NULL; } -static void snd_ali_free_voice(ali_t * codec, snd_ali_voice_t *pvoice) +static void snd_ali_free_voice(struct snd_ali * codec, struct snd_ali_voice *pvoice) { - unsigned long flags; void (*private_free)(void *); void *private_data; @@ -1099,7 +1098,7 @@ static void snd_ali_free_voice(ali_t * codec, snd_ali_voice_t *pvoice) if (pvoice == NULL || !pvoice->use) return; snd_ali_clear_voices(codec, pvoice->number, pvoice->number); - spin_lock_irqsave(&codec->voice_alloc, flags); + spin_lock_irq(&codec->voice_alloc); private_free = pvoice->private_free; private_data = pvoice->private_data; pvoice->private_free = NULL; @@ -1109,13 +1108,13 @@ static void snd_ali_free_voice(ali_t * codec, snd_ali_voice_t *pvoice) } pvoice->use = pvoice->pcm = pvoice->synth = 0; pvoice->substream = NULL; - spin_unlock_irqrestore(&codec->voice_alloc, flags); + spin_unlock_irq(&codec->voice_alloc); if (private_free) private_free(private_data); } -static void snd_ali_clear_voices(ali_t * codec, +static void snd_ali_clear_voices(struct snd_ali * codec, unsigned int v_min, unsigned int v_max) { @@ -1127,7 +1126,7 @@ static void snd_ali_clear_voices(ali_t * codec, } } -static void snd_ali_write_voice_regs(ali_t * codec, +static void snd_ali_write_voice_regs(struct snd_ali * codec, unsigned int Channel, unsigned int LBA, unsigned int CSO, @@ -1194,10 +1193,10 @@ static unsigned int snd_ali_convert_rate(unsigned int rate, int rec) return delta; } -static unsigned int snd_ali_control_mode(snd_pcm_substream_t *substream) +static unsigned int snd_ali_control_mode(struct snd_pcm_substream *substream) { unsigned int CTRL; - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_pcm_runtime *runtime = substream->runtime; /* set ctrl mode CTRL default: 8-bit (unsigned) mono, loop mode enabled @@ -1216,21 +1215,21 @@ static unsigned int snd_ali_control_mode(snd_pcm_substream_t *substream) * PCM part */ -static int snd_ali_ioctl(snd_pcm_substream_t * substream, +static int snd_ali_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { return snd_pcm_lib_ioctl(substream, cmd, arg); } -static int snd_ali_trigger(snd_pcm_substream_t *substream, +static int snd_ali_trigger(struct snd_pcm_substream *substream, int cmd) { - ali_t *codec = snd_pcm_substream_chip(substream); + struct snd_ali *codec = snd_pcm_substream_chip(substream); struct list_head *pos; - snd_pcm_substream_t *s; + struct snd_pcm_substream *s; unsigned int what, whati, capture_flag; - snd_ali_voice_t *pvoice = NULL, *evoice = NULL; + struct snd_ali_voice *pvoice = NULL, *evoice = NULL; unsigned int val; int do_start; @@ -1248,8 +1247,8 @@ static int snd_ali_trigger(snd_pcm_substream_t *substream, what = whati = capture_flag = 0; snd_pcm_group_for_each(pos, substream) { s = snd_pcm_group_substream_entry(pos); - if ((ali_t *) _snd_pcm_chip(s->pcm) == codec) { - pvoice = (snd_ali_voice_t *) s->runtime->private_data; + if ((struct snd_ali *) snd_pcm_substream_chip(s) == codec) { + pvoice = s->runtime->private_data; evoice = pvoice->extra; what |= 1 << (pvoice->number & 0x1f); if (evoice == NULL) { @@ -1292,13 +1291,13 @@ static int snd_ali_trigger(snd_pcm_substream_t *substream, return 0; } -static int snd_ali_playback_hw_params(snd_pcm_substream_t * substream, - snd_pcm_hw_params_t * hw_params) +static int snd_ali_playback_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { - ali_t *codec = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data; - snd_ali_voice_t *evoice = pvoice->extra; + struct snd_ali *codec = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ali_voice *pvoice = runtime->private_data; + struct snd_ali_voice *evoice = pvoice->extra; int err; err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); if (err < 0) return err; @@ -1307,7 +1306,7 @@ static int snd_ali_playback_hw_params(snd_pcm_substream_t * substream, if (params_buffer_size(hw_params)/2 != params_period_size(hw_params)) { if (evoice == NULL) { - evoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, 0); + evoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, 0, -1); if (evoice == NULL) return -ENOMEM; pvoice->extra = evoice; @@ -1323,12 +1322,12 @@ static int snd_ali_playback_hw_params(snd_pcm_substream_t * substream, return 0; } -static int snd_ali_playback_hw_free(snd_pcm_substream_t * substream) +static int snd_ali_playback_hw_free(struct snd_pcm_substream *substream) { - ali_t *codec = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data; - snd_ali_voice_t *evoice = pvoice ? pvoice->extra : NULL; + struct snd_ali *codec = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ali_voice *pvoice = runtime->private_data; + struct snd_ali_voice *evoice = pvoice ? pvoice->extra : NULL; snd_pcm_lib_free_pages(substream); if (evoice != NULL) { @@ -1338,24 +1337,23 @@ static int snd_ali_playback_hw_free(snd_pcm_substream_t * substream) return 0; } -static int snd_ali_capture_hw_params(snd_pcm_substream_t * substream, - snd_pcm_hw_params_t * hw_params) +static int snd_ali_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); } -static int snd_ali_capture_hw_free(snd_pcm_substream_t * substream) +static int snd_ali_hw_free(struct snd_pcm_substream *substream) { return snd_pcm_lib_free_pages(substream); } -static int snd_ali_playback_prepare(snd_pcm_substream_t * substream) +static int snd_ali_playback_prepare(struct snd_pcm_substream *substream) { - ali_t *codec = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data; - snd_ali_voice_t *evoice = pvoice->extra; - unsigned long flags; + struct snd_ali *codec = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ali_voice *pvoice = runtime->private_data; + struct snd_ali_voice *evoice = pvoice->extra; unsigned int LBA; unsigned int Delta; @@ -1368,7 +1366,7 @@ static int snd_ali_playback_prepare(snd_pcm_substream_t * substream) snd_ali_printk("playback_prepare ...\n"); - spin_lock_irqsave(&codec->reg_lock, flags); + spin_lock_irq(&codec->reg_lock); /* set Delta (rate) value */ Delta = snd_ali_convert_rate(runtime->rate, 0); @@ -1433,17 +1431,16 @@ static int snd_ali_playback_prepare(snd_pcm_substream_t * substream) CTRL, EC); } - spin_unlock_irqrestore(&codec->reg_lock, flags); + spin_unlock_irq(&codec->reg_lock); return 0; } -static int snd_ali_capture_prepare(snd_pcm_substream_t * substream) +static int snd_ali_prepare(struct snd_pcm_substream *substream) { - ali_t *codec = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data; - unsigned long flags; + struct snd_ali *codec = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ali_voice *pvoice = runtime->private_data; unsigned int LBA; unsigned int Delta; unsigned int ESO; @@ -1454,32 +1451,35 @@ static int snd_ali_capture_prepare(snd_pcm_substream_t * substream) unsigned int EC; u8 bValue; - spin_lock_irqsave(&codec->reg_lock, flags); + spin_lock_irq(&codec->reg_lock); - snd_ali_printk("capture_prepare...\n"); + snd_ali_printk("ali_prepare...\n"); snd_ali_enable_special_channel(codec,pvoice->number); - Delta = snd_ali_convert_rate(runtime->rate, 1); + Delta = (pvoice->number == ALI_MODEM_IN_CHANNEL || + pvoice->number == ALI_MODEM_OUT_CHANNEL) ? + 0x1000 : snd_ali_convert_rate(runtime->rate, pvoice->mode); // Prepare capture intr channel if (pvoice->number == ALI_SPDIF_IN_CHANNEL) { unsigned int rate; - if (codec->revision != ALI_5451_V02) { - spin_unlock_irqrestore(&codec->reg_lock, flags); + spin_unlock_irq(&codec->reg_lock); + if (codec->revision != ALI_5451_V02) return -1; - } + rate = snd_ali_get_spdif_in_rate(codec); if (rate == 0) { - snd_printk("ali_capture_preapre: spdif rate detect err!\n"); + snd_printk(KERN_WARNING "ali_capture_preapre: spdif rate detect err!\n"); rate = 48000; } + spin_lock_irq(&codec->reg_lock); bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL)); if (bValue & 0x10) { outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL)); - printk("clear SPDIF parity error flag.\n"); + printk(KERN_WARNING "clear SPDIF parity error flag.\n"); } if (rate != 48000) @@ -1517,55 +1517,53 @@ static int snd_ali_capture_prepare(snd_pcm_substream_t * substream) EC); - spin_unlock_irqrestore(&codec->reg_lock, flags); + spin_unlock_irq(&codec->reg_lock); return 0; } -static snd_pcm_uframes_t snd_ali_playback_pointer(snd_pcm_substream_t *substream) +static snd_pcm_uframes_t snd_ali_playback_pointer(struct snd_pcm_substream *substream) { - ali_t *codec = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data; + struct snd_ali *codec = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ali_voice *pvoice = runtime->private_data; unsigned int cso; - unsigned long flags; - spin_lock_irqsave(&codec->reg_lock, flags); + spin_lock(&codec->reg_lock); if (!pvoice->running) { - spin_unlock_irqrestore(&codec->reg_lock, flags); + spin_unlock(&codec->reg_lock); return 0; } outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); - spin_unlock_irqrestore(&codec->reg_lock, flags); + spin_unlock(&codec->reg_lock); snd_ali_printk("playback pointer returned cso=%xh.\n", cso); return cso; } -static snd_pcm_uframes_t snd_ali_capture_pointer(snd_pcm_substream_t *substream) +static snd_pcm_uframes_t snd_ali_pointer(struct snd_pcm_substream *substream) { - ali_t *codec = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data; + struct snd_ali *codec = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ali_voice *pvoice = runtime->private_data; unsigned int cso; - unsigned long flags; - spin_lock_irqsave(&codec->reg_lock, flags); + spin_lock(&codec->reg_lock); if (!pvoice->running) { - spin_unlock_irqrestore(&codec->reg_lock, flags); + spin_unlock_irq(&codec->reg_lock); return 0; } outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); - spin_unlock_irqrestore(&codec->reg_lock, flags); + spin_unlock(&codec->reg_lock); return cso; } -static snd_pcm_hardware_t snd_ali_playback = +static struct snd_pcm_hardware snd_ali_playback = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | @@ -1591,7 +1589,7 @@ static snd_pcm_hardware_t snd_ali_playback = * Capture support device description */ -static snd_pcm_hardware_t snd_ali_capture = +static struct snd_pcm_hardware snd_ali_capture = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | @@ -1613,90 +1611,64 @@ static snd_pcm_hardware_t snd_ali_capture = .fifo_size = 0, }; -static void snd_ali_pcm_free_substream(snd_pcm_runtime_t *runtime) +static void snd_ali_pcm_free_substream(struct snd_pcm_runtime *runtime) { - unsigned long flags; - snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data; - ali_t *codec; + struct snd_ali_voice *pvoice = runtime->private_data; + struct snd_ali *codec; if (pvoice) { codec = pvoice->codec; - spin_lock_irqsave(&codec->reg_lock, flags); snd_ali_free_voice(pvoice->codec, pvoice); - spin_unlock_irqrestore(&codec->reg_lock, flags); } } -static int snd_ali_playback_open(snd_pcm_substream_t * substream) +static int snd_ali_open(struct snd_pcm_substream *substream, int rec, int channel, + struct snd_pcm_hardware *phw) { - ali_t *codec = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - snd_ali_voice_t *pvoice; - unsigned long flags = 0; + struct snd_ali *codec = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ali_voice *pvoice; - spin_lock_irqsave(&codec->reg_lock, flags); - pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, 0); - if (pvoice == NULL) { - spin_unlock_irqrestore(&codec->reg_lock, flags); + pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, rec, channel); + if (pvoice == NULL) return -EAGAIN; - } - pvoice->codec = codec; - spin_unlock_irqrestore(&codec->reg_lock, flags); pvoice->substream = substream; runtime->private_data = pvoice; runtime->private_free = snd_ali_pcm_free_substream; - runtime->hw = snd_ali_playback; + runtime->hw = *phw; snd_pcm_set_sync(substream); snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024); return 0; } - -static int snd_ali_capture_open(snd_pcm_substream_t * substream) +static int snd_ali_playback_open(struct snd_pcm_substream *substream) { - ali_t *codec = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - snd_ali_voice_t *pvoice; - unsigned long flags; - - spin_lock_irqsave(&codec->reg_lock, flags); - pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, 1); - if (pvoice == NULL) { - spin_unlock_irqrestore(&codec->reg_lock, flags); - return -EAGAIN; - } - pvoice->codec = codec; - spin_unlock_irqrestore(&codec->reg_lock, flags); - - pvoice->substream = substream; - runtime->private_data = pvoice; - runtime->private_free = snd_ali_pcm_free_substream; - runtime->hw = snd_ali_capture; - snd_pcm_set_sync(substream); - snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024); - return 0; + return snd_ali_open(substream, 0, -1, &snd_ali_playback); } +static int snd_ali_capture_open(struct snd_pcm_substream *substream) +{ + return snd_ali_open(substream, 1, -1, &snd_ali_capture); +} -static int snd_ali_playback_close(snd_pcm_substream_t * substream) +static int snd_ali_playback_close(struct snd_pcm_substream *substream) { return 0; } -static int snd_ali_capture_close(snd_pcm_substream_t * substream) +static int snd_ali_close(struct snd_pcm_substream *substream) { - ali_t *codec = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data; + struct snd_ali *codec = snd_pcm_substream_chip(substream); + struct snd_ali_voice *pvoice = substream->runtime->private_data; snd_ali_disable_special_channel(codec,pvoice->number); return 0; } -static snd_pcm_ops_t snd_ali_playback_ops = { +static struct snd_pcm_ops snd_ali_playback_ops = { .open = snd_ali_playback_open, .close = snd_ali_playback_close, .ioctl = snd_ali_ioctl, @@ -1707,58 +1679,167 @@ static snd_pcm_ops_t snd_ali_playback_ops = { .pointer = snd_ali_playback_pointer, }; -static snd_pcm_ops_t snd_ali_capture_ops = { +static struct snd_pcm_ops snd_ali_capture_ops = { .open = snd_ali_capture_open, - .close = snd_ali_capture_close, + .close = snd_ali_close, .ioctl = snd_ali_ioctl, - .hw_params = snd_ali_capture_hw_params, - .hw_free = snd_ali_capture_hw_free, - .prepare = snd_ali_capture_prepare, + .hw_params = snd_ali_hw_params, + .hw_free = snd_ali_hw_free, + .prepare = snd_ali_prepare, + .trigger = snd_ali_trigger, + .pointer = snd_ali_pointer, +}; + +/* + * Modem PCM + */ + +static int snd_ali_modem_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) +{ + struct snd_ali *chip = snd_pcm_substream_chip(substream); + unsigned int modem_num = chip->num_of_codecs - 1; + snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_RATE, params_rate(hw_params)); + snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_LEVEL, 0); + return snd_ali_hw_params(substream, hw_params); +} + +static struct snd_pcm_hardware snd_ali_modem = +{ + .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_BLOCK_TRANSFER | + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_RESUME | + SNDRV_PCM_INFO_SYNC_START), + .formats = SNDRV_PCM_FMTBIT_S16_LE, + .rates = SNDRV_PCM_RATE_KNOT|SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000, + .rate_min = 8000, + .rate_max = 16000, + .channels_min = 1, + .channels_max = 1, + .buffer_bytes_max = (256*1024), + .period_bytes_min = 64, + .period_bytes_max = (256*1024), + .periods_min = 1, + .periods_max = 1024, + .fifo_size = 0, +}; + +static int snd_ali_modem_open(struct snd_pcm_substream *substream, int rec, int channel) +{ + static unsigned int rates [] = {8000,9600,12000,16000}; + static struct snd_pcm_hw_constraint_list hw_constraint_rates = { + .count = ARRAY_SIZE(rates), + .list = rates, + .mask = 0, + }; + int err = snd_ali_open(substream, rec, channel, &snd_ali_modem); + if (err) + return err; + return snd_pcm_hw_constraint_list(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, &hw_constraint_rates); +} + +static int snd_ali_modem_playback_open(struct snd_pcm_substream *substream) +{ + return snd_ali_modem_open(substream, 0, ALI_MODEM_OUT_CHANNEL); +} + +static int snd_ali_modem_capture_open(struct snd_pcm_substream *substream) +{ + return snd_ali_modem_open(substream, 1, ALI_MODEM_IN_CHANNEL); +} + +static struct snd_pcm_ops snd_ali_modem_playback_ops = { + .open = snd_ali_modem_playback_open, + .close = snd_ali_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = snd_ali_modem_hw_params, + .hw_free = snd_ali_hw_free, + .prepare = snd_ali_prepare, .trigger = snd_ali_trigger, - .pointer = snd_ali_capture_pointer, + .pointer = snd_ali_pointer, +}; + +static struct snd_pcm_ops snd_ali_modem_capture_ops = { + .open = snd_ali_modem_capture_open, + .close = snd_ali_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = snd_ali_modem_hw_params, + .hw_free = snd_ali_hw_free, + .prepare = snd_ali_prepare, + .trigger = snd_ali_trigger, + .pointer = snd_ali_pointer, +}; + + +struct ali_pcm_description { + char *name; + unsigned int playback_num; + unsigned int capture_num; + struct snd_pcm_ops *playback_ops; + struct snd_pcm_ops *capture_ops; + unsigned short class; }; -static void snd_ali_pcm_free(snd_pcm_t *pcm) +static void snd_ali_pcm_free(struct snd_pcm *pcm) { - ali_t *codec = snd_magic_cast(ali_t, pcm->private_data, return); - codec->pcm = NULL; + struct snd_ali *codec = pcm->private_data; + codec->pcm[pcm->device] = NULL; } -static int __devinit snd_ali_pcm(ali_t * codec, int device, snd_pcm_t ** rpcm) + +static int __devinit snd_ali_pcm(struct snd_ali * codec, int device, struct ali_pcm_description *desc) { - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; - if (rpcm) *rpcm = NULL; - err = snd_pcm_new(codec->card, "ALI 5451", device, ALI_CHANNELS, 1, &pcm); + err = snd_pcm_new(codec->card, desc->name, device, + desc->playback_num, desc->capture_num, &pcm); if (err < 0) { - snd_printk("snd_ali_pcm: err called snd_pcm_new.\n"); + snd_printk(KERN_ERR "snd_ali_pcm: err called snd_pcm_new.\n"); return err; } pcm->private_data = codec; pcm->private_free = snd_ali_pcm_free; - pcm->info_flags = 0; - snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ali_playback_ops); - snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ali_capture_ops); + if (desc->playback_ops) + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, desc->playback_ops); + if (desc->capture_ops) + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, desc->capture_ops); snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(codec->pci), 64*1024, 128*1024); pcm->info_flags = 0; + pcm->dev_class = desc->class; pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; - strcpy(pcm->name, "ALI 5451"); - codec->pcm = pcm; - if (rpcm) *rpcm = pcm; + strcpy(pcm->name, desc->name); + codec->pcm[0] = pcm; return 0; } +static struct ali_pcm_description ali_pcms[] = { + { "ALI 5451", ALI_CHANNELS, 1, &snd_ali_playback_ops, &snd_ali_capture_ops }, + { "ALI 5451 modem", 1, 1, &snd_ali_modem_playback_ops, &snd_ali_modem_capture_ops, SNDRV_PCM_CLASS_MODEM } +}; + +static int __devinit snd_ali_build_pcms(struct snd_ali *codec) +{ + int i, err; + for(i = 0 ; i < codec->num_of_codecs && i < ARRAY_SIZE(ali_pcms) ; i++) + if((err = snd_ali_pcm(codec, i, &ali_pcms[i])) < 0) + return err; + return 0; +} + + #define ALI5451_SPDIF(xname, xindex, value) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ .info = snd_ali5451_spdif_info, .get = snd_ali5451_spdif_get, \ .put = snd_ali5451_spdif_put, .private_value = value} -static int snd_ali5451_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) +static int snd_ali5451_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; @@ -1767,15 +1848,14 @@ static int snd_ali5451_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t return 0; } -static int snd_ali5451_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_ali5451_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - unsigned long flags; - ali_t *codec = snd_magic_cast(ali_t, kcontrol->private_data, -ENXIO); + struct snd_ali *codec = kcontrol->private_data; unsigned int enable; enable = ucontrol->value.integer.value[0] ? 1 : 0; - spin_lock_irqsave(&codec->reg_lock, flags); + spin_lock_irq(&codec->reg_lock); switch(kcontrol->private_value) { case 0: enable = (codec->spdif_mask & 0x02) ? 1 : 0; @@ -1790,19 +1870,18 @@ static int snd_ali5451_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t break; } ucontrol->value.integer.value[0] = enable; - spin_unlock_irqrestore(&codec->reg_lock, flags); + spin_unlock_irq(&codec->reg_lock); return 0; } -static int snd_ali5451_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - unsigned long flags; - ali_t *codec = snd_magic_cast(ali_t, kcontrol->private_data, -ENXIO); + struct snd_ali *codec = kcontrol->private_data; unsigned int change = 0, enable = 0; enable = ucontrol->value.integer.value[0] ? 1 : 0; - spin_lock_irqsave(&codec->reg_lock, flags); + spin_lock_irq(&codec->reg_lock); switch (kcontrol->private_value) { case 0: change = (codec->spdif_mask & 0x02) ? 1 : 0; @@ -1847,55 +1926,62 @@ static int snd_ali5451_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t default: break; } - spin_unlock_irqrestore(&codec->reg_lock, flags); + spin_unlock_irq(&codec->reg_lock); return change; } -static snd_kcontrol_new_t snd_ali5451_mixer_spdif[] __devinitdata = { +static struct snd_kcontrol_new snd_ali5451_mixer_spdif[] __devinitdata = { /* spdif aplayback switch */ /* FIXME: "IEC958 Playback Switch" may conflict with one on ac97_codec */ - ALI5451_SPDIF("IEC958 Output switch", 0, 0), + ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), 0, 0), /* spdif out to spdif channel */ - ALI5451_SPDIF("IEC958 Channel Output Switch", 0, 1), + ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("Channel Output ",NONE,SWITCH), 0, 1), /* spdif in from spdif channel */ ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, 2) }; -static void snd_ali_mixer_free_ac97_bus(ac97_bus_t *bus) +static void snd_ali_mixer_free_ac97_bus(struct snd_ac97_bus *bus) { - ali_t *codec = snd_magic_cast(ali_t, bus->private_data, return); + struct snd_ali *codec = bus->private_data; codec->ac97_bus = NULL; } -static void snd_ali_mixer_free_ac97(ac97_t *ac97) +static void snd_ali_mixer_free_ac97(struct snd_ac97 *ac97) { - ali_t *codec = snd_magic_cast(ali_t, ac97->private_data, return); - codec->ac97 = NULL; + struct snd_ali *codec = ac97->private_data; + codec->ac97[ac97->num] = NULL; } -static int __devinit snd_ali_mixer(ali_t * codec) +static int __devinit snd_ali_mixer(struct snd_ali * codec) { - ac97_bus_t bus; - ac97_t ac97; + struct snd_ac97_template ac97; unsigned int idx; - int err; + int i, err; + static struct snd_ac97_bus_ops ops = { + .write = snd_ali_codec_write, + .read = snd_ali_codec_read, + }; - memset(&bus, 0, sizeof(bus)); - bus.write = snd_ali_codec_write; - bus.read = snd_ali_codec_read; - bus.private_data = codec; - bus.private_free = snd_ali_mixer_free_ac97_bus; - if ((err = snd_ac97_bus(codec->card, &bus, &codec->ac97_bus)) < 0) + if ((err = snd_ac97_bus(codec->card, 0, &ops, codec, &codec->ac97_bus)) < 0) return err; + codec->ac97_bus->private_free = snd_ali_mixer_free_ac97_bus; memset(&ac97, 0, sizeof(ac97)); ac97.private_data = codec; ac97.private_free = snd_ali_mixer_free_ac97; - if ((err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97)) < 0) { - snd_printk("ali mixer creating error.\n"); - return err; + + for ( i = 0 ; i < codec->num_of_codecs ; i++) { + ac97.num = i; + if ((err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i])) < 0) { + snd_printk(KERN_ERR "ali mixer %d creating error.\n", i); + if(i == 0) + return err; + codec->num_of_codecs = 1; + break; + } } + if (codec->spdif_support) { for(idx = 0; idx < ARRAY_SIZE(snd_ali5451_mixer_spdif); idx++) { err=snd_ctl_add(codec->card, snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec)); @@ -1906,14 +1992,22 @@ static int __devinit snd_ali_mixer(ali_t * codec) } #ifdef CONFIG_PM -static void ali_suspend(ali_t *chip) +static int ali_suspend(struct pci_dev *pci, pm_message_t state) { - ali_image_t *im; + struct snd_card *card = pci_get_drvdata(pci); + struct snd_ali *chip = card->private_data; + struct snd_ali_image *im; int i, j; im = chip->image; if (! im) - return; + return 0; + + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); + for(i = 0 ; i < chip->num_of_codecs ; i++) { + snd_pcm_suspend_all(chip->pcm[i]); + snd_ac97_suspend(chip->ac97[i]); + } spin_lock_irq(&chip->reg_lock); @@ -1940,18 +2034,24 @@ static void ali_suspend(ali_t *chip) outl(0xffffffff, ALI_REG(chip, ALI_STOP)); spin_unlock_irq(&chip->reg_lock); + pci_disable_device(pci); + pci_save_state(pci); + return 0; } -static void ali_resume(ali_t *chip) +static int ali_resume(struct pci_dev *pci) { - ali_image_t *im; + struct snd_card *card = pci_get_drvdata(pci); + struct snd_ali *chip = card->private_data; + struct snd_ali_image *im; int i, j; im = chip->image; if (! im) - return; + return 0; - pci_enable_device(chip->pci); + pci_restore_state(pci); + pci_enable_device(pci); spin_lock_irq(&chip->reg_lock); @@ -1967,32 +2067,22 @@ static void ali_resume(ali_t *chip) outl(im->regs[i], ALI_REG(chip, i*4)); } - snd_ac97_resume(chip->ac97); - // start HW channel outl(im->regs[ALI_START >> 2], ALI_REG(chip, ALI_START)); // restore IRQ enable bits outl(im->regs[ALI_MISCINT >> 2], ALI_REG(chip, ALI_MISCINT)); spin_unlock_irq(&chip->reg_lock); - return; -} -static int snd_ali_suspend(struct pci_dev *dev, u32 state) -{ - ali_t *chip = snd_magic_cast(ali_t, pci_get_drvdata(dev), return -ENXIO); - ali_suspend(chip); - return 0; -} -static int snd_ali_resume(struct pci_dev *dev) -{ - ali_t *chip = snd_magic_cast(ali_t, pci_get_drvdata(dev), return -ENXIO); - ali_resume(chip); + for(i = 0 ; i < chip->num_of_codecs ; i++) + snd_ac97_resume(chip->ac97[i]); + + snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } #endif /* CONFIG_PM */ -static int snd_ali_free(ali_t * codec) +static int snd_ali_free(struct snd_ali * codec) { if (codec->hw_initialized) snd_ali_disable_address_interrupt(codec); @@ -2000,19 +2090,19 @@ static int snd_ali_free(ali_t * codec) synchronize_irq(codec->irq); free_irq(codec->irq, (void *)codec); } - if (codec->res_port) { - release_resource(codec->res_port); - kfree_nocheck(codec->res_port); - } + if (codec->port) + pci_release_regions(codec->pci); + pci_disable_device(codec->pci); #ifdef CONFIG_PM - if (codec->image) - kfree(codec->image); + kfree(codec->image); #endif - snd_magic_kfree(codec); + pci_dev_put(codec->pci_m1533); + pci_dev_put(codec->pci_m7101); + kfree(codec); return 0; } -static int snd_ali_chip_init(ali_t *codec) +static int snd_ali_chip_init(struct snd_ali *codec) { unsigned int legacy; unsigned char temp; @@ -2021,7 +2111,7 @@ static int snd_ali_chip_init(ali_t *codec) snd_ali_printk("chip initializing ... \n"); if (snd_ali_reset_5451(codec)) { - snd_printk("ali_chip_init: reset 5451 error.\n"); + snd_printk(KERN_ERR "ali_chip_init: reset 5451 error.\n"); return -1; } @@ -2055,48 +2145,72 @@ static int snd_ali_chip_init(ali_t *codec) codec->spdif_mask = 0x00000002; } + codec->num_of_codecs = 1; + + /* secondary codec - modem */ + if (inl(ALI_REG(codec, ALI_SCTRL)) & ALI_SCTRL_CODEC2_READY) { + codec->num_of_codecs++; + outl(inl(ALI_REG(codec, ALI_SCTRL)) | + (ALI_SCTRL_LINE_IN2|ALI_SCTRL_GPIO_IN2|ALI_SCTRL_LINE_OUT_EN), + ALI_REG(codec, ALI_SCTRL)); + } + snd_ali_printk("chip initialize succeed.\n"); return 0; } -static int __devinit snd_ali_resources(ali_t *codec) +/* proc for register dump */ +static void snd_ali_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buf) +{ + struct snd_ali *codec = entry->private_data; + int i; + for(i = 0 ; i < 256 ; i+= 4) + snd_iprintf(buf, "%02x: %08x\n", i, inl(ALI_REG(codec, i))); +} + +static void __devinit snd_ali_proc_init(struct snd_ali *codec) +{ + struct snd_info_entry *entry; + if(!snd_card_proc_new(codec->card, "ali5451", &entry)) + snd_info_set_text_ops(entry, codec, snd_ali_proc_read); +} + +static int __devinit snd_ali_resources(struct snd_ali *codec) { + int err; + snd_ali_printk("resouces allocation ...\n"); - if ((codec->res_port = request_region(codec->port, 0x100, "ALI 5451")) == NULL) { - snd_printk("Unalbe to request io ports.\n"); - return -EBUSY; - } + if ((err = pci_request_regions(codec->pci, "ALI 5451")) < 0) + return err; + codec->port = pci_resource_start(codec->pci, 0); - if (request_irq(codec->pci->irq, snd_ali_card_interrupt, SA_INTERRUPT|SA_SHIRQ, "ALI 5451", (void *)codec)) { - snd_printk("Unable to request irq.\n"); + if (request_irq(codec->pci->irq, snd_ali_card_interrupt, IRQF_DISABLED|IRQF_SHARED, "ALI 5451", (void *)codec)) { + snd_printk(KERN_ERR "Unable to request irq.\n"); return -EBUSY; } codec->irq = codec->pci->irq; snd_ali_printk("resouces allocated.\n"); return 0; } -static int snd_ali_dev_free(snd_device_t *device) +static int snd_ali_dev_free(struct snd_device *device) { - ali_t *codec=snd_magic_cast(ali_t, device->device_data, return -ENXIO); + struct snd_ali *codec=device->device_data; snd_ali_free(codec); return 0; } -static int __devinit snd_ali_create(snd_card_t * card, +static int __devinit snd_ali_create(struct snd_card *card, struct pci_dev *pci, int pcm_streams, int spdif_support, - ali_t ** r_ali) + struct snd_ali ** r_ali) { - ali_t *codec; + struct snd_ali *codec; int i, err; - unsigned short cmdw = 0; - struct pci_dev *pci_dev = NULL; - static snd_device_ops_t ops = { - (snd_dev_free_t *)snd_ali_dev_free, - NULL, - NULL + unsigned short cmdw; + static struct snd_device_ops ops = { + .dev_free = snd_ali_dev_free, }; *r_ali = NULL; @@ -2107,14 +2221,17 @@ static int __devinit snd_ali_create(snd_card_t * card, if ((err = pci_enable_device(pci)) < 0) return err; /* check, if we can restrict PCI DMA transfers to 31 bits */ - if (pci_set_dma_mask(pci, 0x7fffffff) < 0 || - pci_set_consistent_dma_mask(pci, 0x7fffffff) < 0) { - snd_printk("architecture does not support 31bit PCI busmaster DMA\n"); + if (pci_set_dma_mask(pci, DMA_31BIT_MASK) < 0 || + pci_set_consistent_dma_mask(pci, DMA_31BIT_MASK) < 0) { + snd_printk(KERN_ERR "architecture does not support 31bit PCI busmaster DMA\n"); + pci_disable_device(pci); return -ENXIO; } - if ((codec = snd_magic_kcalloc(ali_t, 0, GFP_KERNEL)) == NULL) + if ((codec = kzalloc(sizeof(*codec), GFP_KERNEL)) == NULL) { + pci_disable_device(pci); return -ENOMEM; + } spin_lock_init(&codec->reg_lock); spin_lock_init(&codec->voice_alloc); @@ -2122,7 +2239,6 @@ static int __devinit snd_ali_create(snd_card_t * card, codec->card = card; codec->pci = pci; codec->irq = -1; - codec->port = pci_resource_start(pci, 0); pci_read_config_byte(pci, PCI_REVISION_ID, &codec->revision); codec->spdif_support = spdif_support; @@ -2168,16 +2284,14 @@ static int __devinit snd_ali_create(snd_card_t * card, codec->chregs.data.ainten = 0x00; /* M1533: southbridge */ - pci_dev = pci_find_device(0x10b9, 0x1533, NULL); - codec->pci_m1533 = pci_dev; + codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL); if (! codec->pci_m1533) { snd_printk(KERN_ERR "ali5451: cannot find ALi 1533 chip.\n"); snd_ali_free(codec); return -ENODEV; } /* M7101: power management */ - pci_dev = pci_find_device(0x10b9, 0x7101, NULL); - codec->pci_m7101 = pci_dev; + codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL); if (! codec->pci_m7101 && codec->revision == ALI_5451_V02) { snd_printk(KERN_ERR "ali5451: cannot find ALi 7101 chip.\n"); snd_ali_free(codec); @@ -2196,14 +2310,14 @@ static int __devinit snd_ali_create(snd_card_t * card, } if ((err = snd_ali_chip_init(codec)) < 0) { - snd_printk("ali create: chip init error.\n"); + snd_printk(KERN_ERR "ali create: chip init error.\n"); return err; } #ifdef CONFIG_PM codec->image = kmalloc(sizeof(*codec->image), GFP_KERNEL); if (! codec->image) - snd_printk("can't allocate apm buffer\n"); + snd_printk(KERN_WARNING "can't allocate apm buffer\n"); #endif snd_ali_enable_address_interrupt(codec); @@ -2217,28 +2331,21 @@ static int __devinit snd_ali_create(snd_card_t * card, static int __devinit snd_ali_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { - static int dev; - snd_card_t *card; - ali_t *codec; + struct snd_card *card; + struct snd_ali *codec; int err; snd_ali_printk("probe ...\n"); - if (dev >= SNDRV_CARDS) - return -ENODEV; - if (!enable[dev]) { - dev++; - return -ENOENT; - } - - card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); + card = snd_card_new(index, id, THIS_MODULE, 0); if (card == NULL) return -ENOMEM; - if ((err = snd_ali_create(card, pci, pcm_channels[dev], spdif[dev], &codec)) < 0) { + if ((err = snd_ali_create(card, pci, pcm_channels, spdif, &codec)) < 0) { snd_card_free(card); return err; } + card->private_data = codec; snd_ali_printk("mixer building ...\n"); if ((err = snd_ali_mixer(codec)) < 0) { @@ -2247,11 +2354,13 @@ static int __devinit snd_ali_probe(struct pci_dev *pci, } snd_ali_printk("pcm building ...\n"); - if ((err = snd_ali_pcm(codec, 0, NULL)) < 0) { + if ((err = snd_ali_build_pcms(codec)) < 0) { snd_card_free(card); return err; } + snd_ali_proc_init(codec); + strcpy(card->driver, "ALI5451"); strcpy(card->shortname, "ALI 5451"); @@ -2263,16 +2372,13 @@ static int __devinit snd_ali_probe(struct pci_dev *pci, snd_card_free(card); return err; } - pci_set_drvdata(pci, codec); - dev++; + pci_set_drvdata(pci, card); return 0; } static void __devexit snd_ali_remove(struct pci_dev *pci) { - ali_t *chip = snd_magic_cast(ali_t, pci_get_drvdata(pci), return); - if (chip) - snd_card_free(chip->card); + snd_card_free(pci_get_drvdata(pci)); pci_set_drvdata(pci, NULL); } @@ -2282,22 +2388,14 @@ static struct pci_driver driver = { .probe = snd_ali_probe, .remove = __devexit_p(snd_ali_remove), #ifdef CONFIG_PM - .suspend = snd_ali_suspend, - .resume = snd_ali_resume, + .suspend = ali_suspend, + .resume = ali_resume, #endif }; static int __init alsa_card_ali_init(void) { - int err; - - if ((err = pci_module_init(&driver)) < 0) { -#ifdef MODULE - printk(KERN_ERR "ALi pci audio not found or device busy.\n"); -#endif - return err; - } - return 0; + return pci_register_driver(&driver); } static void __exit alsa_card_ali_exit(void) @@ -2307,25 +2405,3 @@ static void __exit alsa_card_ali_exit(void) module_init(alsa_card_ali_init) module_exit(alsa_card_ali_exit) - -#ifndef MODULE - -/* format is: snd-ali5451=enable,index,id,pcm_channels */ - -static int __init alsa_card_ali_setup(char *str) -{ - static unsigned __initdata nr_dev = 0; - - if (nr_dev >= SNDRV_CARDS) - return 0; - (void)(get_option(&str,&enable[nr_dev]) == 2 && - get_option(&str,&index[nr_dev]) == 2 && - get_id(&str,&id[nr_dev]) == 2 && - get_option(&str,&pcm_channels[nr_dev]) == 2); - nr_dev++; - return 1; -} - -__setup("snd-ali5451=", alsa_card_ali_setup); - -#endif /* ifndef */