summaryrefslogtreecommitdiffstats
path: root/sound/pci/ali5451
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2007-04-03 13:20:49 +0200
committerJaroslav Kysela <perex@suse.cz>2007-05-11 16:55:55 +0200
commitf9ab2b1c3ab5345f9003bf7ebc1eaa0f9b8cf99e (patch)
tree10645153733b7f71fe51a4485c9f997dd07a409f /sound/pci/ali5451
parent51354ae3b8fdbeaf96e23ddf787432a38eba31f5 (diff)
[ALSA] ali5451 - Code clean up, irq handler fix
- Clean up ali5451.c, following the standard coding style, unneeded codes reduced, and removal of redundant variable initializations. Hungarian notation isn't fixed yet ;) - Fix irq handler to return IRQ_NONE properly for shared irqs. Also check the hardware availability in irq handler to avoid possible initialization races at loading the driver. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/pci/ali5451')
-rw-r--r--sound/pci/ali5451/ali5451.c865
1 files changed, 420 insertions, 445 deletions
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index cd2fe374744c..e1ed59549c50 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -69,10 +69,10 @@ module_param(enable, bool, 0444);
* Debug part definitions
*/
-//#define ALI_DEBUG
+/* #define ALI_DEBUG */
#ifdef ALI_DEBUG
-#define snd_ali_printk(format, args...) printk(format, ##args);
+#define snd_ali_printk(format, args...) printk(KERN_DEBUG format, ##args);
#else
#define snd_ali_printk(format, args...)
#endif
@@ -105,10 +105,10 @@ module_param(enable, bool, 0444);
* Direct Registers
*/
-#define ALI_LEGACY_DMAR0 0x00 // ADR0
-#define ALI_LEGACY_DMAR4 0x04 // CNT0
-#define ALI_LEGACY_DMAR11 0x0b // MOD
-#define ALI_LEGACY_DMAR15 0x0f // MMR
+#define ALI_LEGACY_DMAR0 0x00 /* ADR0 */
+#define ALI_LEGACY_DMAR4 0x04 /* CNT0 */
+#define ALI_LEGACY_DMAR11 0x0b /* MOD */
+#define ALI_LEGACY_DMAR15 0x0f /* MMR */
#define ALI_MPUR0 0x20
#define ALI_MPUR1 0x21
#define ALI_MPUR2 0x22
@@ -175,7 +175,7 @@ struct snd_ali;
struct snd_ali_voice;
struct snd_ali_channel_control {
- // register data
+ /* register data */
struct REGDATA {
unsigned int start;
unsigned int stop;
@@ -183,7 +183,7 @@ struct snd_ali_channel_control {
unsigned int ainten;
} data;
- // register addresses
+ /* register addresses */
struct REGS {
unsigned int start;
unsigned int stop;
@@ -197,19 +197,18 @@ struct snd_ali_channel_control {
struct snd_ali_voice {
unsigned int number;
- unsigned int use: 1,
- pcm: 1,
- midi: 1,
- mode: 1,
- synth: 1;
+ unsigned int use :1,
+ pcm :1,
+ midi :1,
+ mode :1,
+ synth :1,
+ running :1;
/* PCM data */
struct snd_ali *codec;
struct snd_pcm_substream *substream;
struct snd_ali_voice *extra;
- unsigned int running: 1;
-
int eso; /* final ESO value for channel */
int count; /* runtime->period_size */
@@ -231,14 +230,12 @@ struct snd_alidev {
};
-#ifdef CONFIG_PM
#define ALI_GLOBAL_REGS 56
#define ALI_CHANNEL_REGS 8
struct snd_ali_image {
- unsigned long regs[ALI_GLOBAL_REGS];
- unsigned long channel_regs[ALI_CHANNELS][ALI_CHANNEL_REGS];
+ u32 regs[ALI_GLOBAL_REGS];
+ u32 channel_regs[ALI_CHANNELS][ALI_CHANNEL_REGS];
};
-#endif
struct snd_ali {
@@ -246,8 +243,8 @@ struct snd_ali {
unsigned long port;
unsigned char revision;
- unsigned int hw_initialized: 1;
- unsigned int spdif_support: 1;
+ unsigned int hw_initialized :1;
+ unsigned int spdif_support :1;
struct pci_dev *pci;
struct pci_dev *pci_m1533;
@@ -287,108 +284,28 @@ MODULE_DEVICE_TABLE(pci, snd_ali_ids);
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
- */
-
-#ifdef ALI_DEBUG
-
-static void ali_read_regs(struct snd_ali *codec, int channel)
-{
- int i,j;
- unsigned int dwVal;
-
- printk("channel %d registers map:\n", channel);
- outb((unsigned char)(channel & 0x001f), ALI_REG(codec,ALI_GC_CIR));
-
- printk(" ");
- for(j=0;j<8;j++)
- printk("%2.2x ", j*4);
- printk("\n");
-
- for (i=0; i<=0xf8/4;i++) {
- if(i%8 == 0)
- printk("%2.2x ", (i*4/0x10)*0x10);
- dwVal = inl(ALI_REG(codec,i*4));
- printk("%8.8x ", dwVal);
- if ((i+1)%8 == 0)
- printk("\n");
- }
- printk("\n");
-}
-static void ali_read_cfg(unsigned int vendor, unsigned deviceid)
-{
- unsigned int dwVal;
- struct pci_dev *pci_dev;
- int i,j;
-
- pci_dev = pci_get_device(vendor, deviceid, NULL);
- if (pci_dev == NULL)
- return ;
-
- printk("\nM%x PCI CFG\n", deviceid);
- printk(" ");
- for(j=0;j<8;j++)
- printk("%d ",j);
- printk("\n");
-
- for(i=0;i<8;i++) {
- printk("%d ",i);
- for(j=0;j<8;j++)
- {
- pci_read_config_dword(pci_dev, i*0x20+j*4, &dwVal);
- printk("%8.8x ", dwVal);
- }
- printk("\n");
- }
- pci_dev_put(pci_dev);
- }
-static void ali_read_ac97regs(struct snd_ali *codec, int secondary)
-{
- unsigned short i,j;
- unsigned short wVal;
-
- printk("\ncodec %d registers map:\n", secondary);
-
- printk(" ");
- for(j=0;j<8;j++)
- printk("%2.2x ",j*2);
- printk("\n");
-
- for (i=0; i<64;i++) {
- if(i%8 == 0)
- printk("%2.2x ", (i/8)*0x10);
- wVal = snd_ali_codec_peek(codec, secondary, i*2);
- printk("%4.4x ", wVal);
- if ((i+1)%8 == 0)
- printk("\n");
- }
- printk("\n");
-}
-
-#endif
+static void snd_ali_codec_poke(struct snd_ali *, int, unsigned short,
+ unsigned short);
/*
* AC97 ACCESS
*/
static inline unsigned int snd_ali_5451_peek(struct snd_ali *codec,
- unsigned int port )
+ unsigned int port)
{
return (unsigned int)inl(ALI_REG(codec, port));
}
-static inline void snd_ali_5451_poke( struct snd_ali *codec,
- unsigned int port,
- unsigned int val )
+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( struct snd_ali *codec,
- unsigned int port )
+static int snd_ali_codec_ready(struct snd_ali *codec,
+ unsigned int port)
{
unsigned long end_time;
unsigned int res;
@@ -396,7 +313,7 @@ static int snd_ali_codec_ready( struct snd_ali *codec,
end_time = jiffies + msecs_to_jiffies(250);
do {
res = snd_ali_5451_peek(codec,port);
- if (! (res & 0x8000))
+ if (!(res & 0x8000))
return 0;
schedule_timeout_uninterruptible(1);
} while (time_after_eq(end_time, jiffies));
@@ -425,11 +342,11 @@ static int snd_ali_stimer_ready(struct snd_ali *codec)
}
static void snd_ali_codec_poke(struct snd_ali *codec,int secondary,
- unsigned short reg,
- unsigned short val)
+ unsigned short reg,
+ unsigned short val)
{
- unsigned int dwVal = 0;
- unsigned int port = 0;
+ unsigned int dwVal;
+ unsigned int port;
if (reg >= 0x80) {
snd_printk(KERN_ERR "ali_codec_poke: reg(%xh) invalid.\n", reg);
@@ -445,20 +362,22 @@ static void snd_ali_codec_poke(struct snd_ali *codec,int secondary,
dwVal = (unsigned int) (reg & 0xff);
dwVal |= 0x8000 | (val << 16);
- if (secondary) dwVal |= 0x0080;
- if (codec->revision == ALI_5451_V02) dwVal |= 0x0100;
+ if (secondary)
+ dwVal |= 0x0080;
+ if (codec->revision == ALI_5451_V02)
+ dwVal |= 0x0100;
- snd_ali_5451_poke(codec,port,dwVal);
+ snd_ali_5451_poke(codec, port, dwVal);
return ;
}
-static unsigned short snd_ali_codec_peek( struct snd_ali *codec,
- int secondary,
- unsigned short reg)
+static unsigned short snd_ali_codec_peek(struct snd_ali *codec,
+ int secondary,
+ unsigned short reg)
{
- unsigned int dwVal = 0;
- unsigned int port = 0;
+ unsigned int dwVal;
+ unsigned int port;
if (reg >= 0x80) {
snd_printk(KERN_ERR "ali_codec_peek: reg(%xh) invalid.\n", reg);
@@ -474,7 +393,8 @@ static unsigned short snd_ali_codec_peek( struct snd_ali *codec,
dwVal = (unsigned int) (reg & 0xff);
dwVal |= 0x8000; /* bit 15*/
- if (secondary) dwVal |= 0x0080;
+ if (secondary)
+ dwVal |= 0x0080;
snd_ali_5451_poke(codec, port, dwVal);
@@ -483,7 +403,7 @@ static unsigned short snd_ali_codec_peek( struct snd_ali *codec,
if (snd_ali_codec_ready(codec, port) < 0)
return ~0;
- return (snd_ali_5451_peek(codec, port) & 0xffff0000)>>16;
+ return (snd_ali_5451_peek(codec, port) & 0xffff0000) >> 16;
}
static void snd_ali_codec_write(struct snd_ac97 *ac97,
@@ -493,9 +413,9 @@ static void snd_ali_codec_write(struct snd_ac97 *ac97,
struct snd_ali *codec = ac97->private_data;
snd_ali_printk("codec_write: reg=%xh data=%xh.\n", reg, val);
- if(reg == AC97_GPIO_STATUS) {
- outl((val << ALI_AC97_GPIO_DATA_SHIFT)|ALI_AC97_GPIO_ENABLE,
- ALI_REG(codec, ALI_AC97_GPIO));
+ 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);
@@ -503,12 +423,13 @@ static void snd_ali_codec_write(struct snd_ac97 *ac97,
}
-static unsigned short snd_ali_codec_read(struct snd_ac97 *ac97, unsigned short reg)
+static unsigned short snd_ali_codec_read(struct snd_ac97 *ac97,
+ unsigned short reg)
{
struct snd_ali *codec = ac97->private_data;
snd_ali_printk("codec_read reg=%xh.\n", reg);
- return (snd_ali_codec_peek(codec, ac97->num, reg));
+ return snd_ali_codec_peek(codec, ac97->num, reg);
}
/*
@@ -517,11 +438,12 @@ static unsigned short snd_ali_codec_read(struct snd_ac97 *ac97, unsigned short r
static int snd_ali_reset_5451(struct snd_ali *codec)
{
- struct pci_dev *pci_dev = NULL;
+ struct pci_dev *pci_dev;
unsigned short wCount, wReg;
unsigned int dwVal;
- if ((pci_dev = codec->pci_m1533) != NULL) {
+ pci_dev = codec->pci_m1533;
+ if (pci_dev) {
pci_read_config_dword(pci_dev, 0x7c, &dwVal);
pci_write_config_dword(pci_dev, 0x7c, dwVal | 0x08000000);
udelay(5000);
@@ -541,7 +463,7 @@ static int snd_ali_reset_5451(struct snd_ali *codec)
wCount = 200;
while(wCount--) {
wReg = snd_ali_codec_peek(codec, 0, AC97_POWERDOWN);
- if((wReg & 0x000f) == 0x000f)
+ if ((wReg & 0x000f) == 0x000f)
return 0;
udelay(5000);
}
@@ -555,8 +477,8 @@ static int snd_ali_reset_5451(struct snd_ali *codec)
static int snd_ali_reset_codec(struct snd_ali *codec)
{
- struct pci_dev *pci_dev = NULL;
- unsigned char bVal = 0;
+ struct pci_dev *pci_dev;
+ unsigned char bVal;
unsigned int dwVal;
unsigned short wCount, wReg;
@@ -579,9 +501,9 @@ static int snd_ali_reset_codec(struct snd_ali *codec)
udelay(15000);
wCount = 200;
- while(wCount--) {
+ while (wCount--) {
wReg = snd_ali_codec_read(codec->ac97, AC97_POWERDOWN);
- if((wReg & 0x000f) == 0x000f)
+ if ((wReg & 0x000f) == 0x000f)
return 0;
udelay(5000);
}
@@ -594,25 +516,27 @@ static int snd_ali_reset_codec(struct snd_ali *codec)
* ALI 5451 Controller
*/
-static void snd_ali_enable_special_channel(struct snd_ali *codec, unsigned int channel)
+static void snd_ali_enable_special_channel(struct snd_ali *codec,
+ unsigned int channel)
{
- unsigned long dwVal = 0;
+ unsigned long dwVal;
- dwVal = inl(ALI_REG(codec,ALI_GLOBAL_CONTROL));
+ dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL));
dwVal |= 1 << (channel & 0x0000001f);
- outl(dwVal, ALI_REG(codec,ALI_GLOBAL_CONTROL));
+ outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
}
-static void snd_ali_disable_special_channel(struct snd_ali *codec, unsigned int channel)
+static void snd_ali_disable_special_channel(struct snd_ali *codec,
+ unsigned int channel)
{
- unsigned long dwVal = 0;
+ unsigned long dwVal;
- dwVal = inl(ALI_REG(codec,ALI_GLOBAL_CONTROL));
+ dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL));
dwVal &= ~(1 << (channel & 0x0000001f));
- outl(dwVal, ALI_REG(codec,ALI_GLOBAL_CONTROL));
+ outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
}
-static void snd_ali_enable_address_interrupt(struct snd_ali * codec)
+static void snd_ali_enable_address_interrupt(struct snd_ali *codec)
{
unsigned int gc;
@@ -622,7 +546,7 @@ static void snd_ali_enable_address_interrupt(struct snd_ali * codec)
outl( gc, ALI_REG(codec, ALI_GC_CIR));
}
-static void snd_ali_disable_address_interrupt(struct snd_ali * codec)
+static void snd_ali_disable_address_interrupt(struct snd_ali *codec)
{
unsigned int gc;
@@ -632,8 +556,9 @@ static void snd_ali_disable_address_interrupt(struct snd_ali * codec)
outl(gc, ALI_REG(codec, ALI_GC_CIR));
}
-#if 0 // not used
-static void snd_ali_enable_voice_irq(struct snd_ali *codec, unsigned int channel)
+#if 0 /* not used */
+static void snd_ali_enable_voice_irq(struct snd_ali *codec,
+ unsigned int channel)
{
unsigned int mask;
struct snd_ali_channel_control *pchregs = &(codec->chregs);
@@ -641,13 +566,14 @@ static void snd_ali_enable_voice_irq(struct snd_ali *codec, unsigned int channel
snd_ali_printk("enable_voice_irq channel=%d\n",channel);
mask = 1 << (channel & 0x1f);
- pchregs->data.ainten = inl(ALI_REG(codec,pchregs->regs.ainten));
+ pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten));
pchregs->data.ainten |= mask;
- outl(pchregs->data.ainten,ALI_REG(codec,pchregs->regs.ainten));
+ outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten));
}
#endif
-static void snd_ali_disable_voice_irq(struct snd_ali *codec, unsigned int channel)
+static void snd_ali_disable_voice_irq(struct snd_ali *codec,
+ unsigned int channel)
{
unsigned int mask;
struct snd_ali_channel_control *pchregs = &(codec->chregs);
@@ -655,9 +581,9 @@ static void snd_ali_disable_voice_irq(struct snd_ali *codec, unsigned int channe
snd_ali_printk("disable_voice_irq channel=%d\n",channel);
mask = 1 << (channel & 0x1f);
- pchregs->data.ainten = inl(ALI_REG(codec,pchregs->regs.ainten));
+ pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten));
pchregs->data.ainten &= ~mask;
- outl(pchregs->data.ainten,ALI_REG(codec,pchregs->regs.ainten));
+ outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten));
}
static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel)
@@ -665,7 +591,8 @@ 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(KERN_ERR "ali_alloc_pcm_channel: no free channels.\n");
+ snd_printk(KERN_ERR
+ "ali_alloc_pcm_channel: no free channels.\n");
return -1;
}
@@ -685,35 +612,41 @@ static int snd_ali_find_free_channel(struct snd_ali * codec, int rec)
snd_ali_printk("find_free_channel: for %s\n",rec ? "rec" : "pcm");
- // recording
+ /* recording */
if (rec) {
if (codec->spdif_support &&
- (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & ALI_SPDIF_IN_SUPPORT))
+ (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) &
+ ALI_SPDIF_IN_SUPPORT))
idx = ALI_SPDIF_IN_CHANNEL;
else
idx = ALI_PCM_IN_CHANNEL;
- if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
+ result = snd_ali_alloc_pcm_channel(codec, idx);
+ if (result >= 0)
return result;
- } else {
- snd_printk(KERN_ERR "ali_find_free_channel: record channel is busy now.\n");
+ else {
+ snd_printk(KERN_ERR "ali_find_free_channel: "
+ "record channel is busy now.\n");
return -1;
}
}
- //playback...
+ /* playback... */
if (codec->spdif_support &&
- (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & ALI_SPDIF_OUT_CH_ENABLE)) {
+ (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) &
+ ALI_SPDIF_OUT_CH_ENABLE)) {
idx = ALI_SPDIF_OUT_CHANNEL;
- if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
+ result = snd_ali_alloc_pcm_channel(codec, idx);
+ if (result >= 0)
return result;
- } else {
- snd_printk(KERN_ERR "ali_find_free_channel: S/PDIF out channel is in busy now.\n");
- }
+ else
+ snd_printk(KERN_ERR "ali_find_free_channel: "
+ "S/PDIF out channel is in busy now.\n");
}
for (idx = 0; idx < ALI_CHANNELS; idx++) {
- if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0)
+ result = snd_ali_alloc_pcm_channel(codec, idx);
+ if (result >= 0)
return result;
}
snd_printk(KERN_ERR "ali_find_free_channel: no free channels.\n");
@@ -730,7 +663,8 @@ static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel)
return;
if (!(codec->synth.chmap & (1 << idx))) {
- snd_printk(KERN_ERR "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);
@@ -738,8 +672,8 @@ static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel)
}
}
-#if 0 // not used
-static void snd_ali_start_voice(struct snd_ali * codec, unsigned int channel)
+#if 0 /* not used */
+static void snd_ali_start_voice(struct snd_ali *codec, unsigned int channel)
{
unsigned int mask = 1 << (channel & 0x1f);
@@ -748,7 +682,7 @@ static void snd_ali_start_voice(struct snd_ali * codec, unsigned int channel)
}
#endif
-static void snd_ali_stop_voice(struct snd_ali * codec, unsigned int channel)
+static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel)
{
unsigned int mask = 1 << (channel & 0x1f);
@@ -768,26 +702,27 @@ static void snd_ali_delay(struct snd_ali *codec,int interval)
currenttimer = inl(ALI_REG(codec, ALI_STIMER));
while (currenttimer < begintimer + interval) {
- if(snd_ali_stimer_ready(codec) < 0)
+ if (snd_ali_stimer_ready(codec) < 0)
break;
currenttimer = inl(ALI_REG(codec, ALI_STIMER));
+ cpu_relax();
}
}
static void snd_ali_detect_spdif_rate(struct snd_ali *codec)
{
- u16 wval = 0;
+ u16 wval;
u16 count = 0;
- u8 bval = 0, R1 = 0, R2 = 0;
+ u8 bval, R1 = 0, R2;
- bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1));
+ bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1));
bval |= 0x1F;
- outb(bval,ALI_REG(codec,ALI_SPDIF_CTRL + 1));
+ outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL + 1));
- while (((R1 < 0x0B )||(R1 > 0x0E)) && (R1 != 0x12) && count <= 50000) {
+ while ((R1 < 0x0b || R1 > 0x0e) && R1 != 0x12 && count <= 50000) {
count ++;
snd_ali_delay(codec, 6);
- bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1));
+ bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1));
R1 = bval & 0x1F;
}
@@ -801,7 +736,10 @@ static void snd_ali_detect_spdif_rate(struct snd_ali *codec)
snd_ali_delay(codec, 6);
bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1));
R2 = bval & 0x1F;
- if (R2 != R1) R1 = R2; else break;
+ if (R2 != R1)
+ R1 = R2;
+ else
+ break;
}
if (count > 50000) {
@@ -810,42 +748,45 @@ static void snd_ali_detect_spdif_rate(struct snd_ali *codec)
}
if (R2 >= 0x0b && R2 <= 0x0e) {
- wval = inw(ALI_REG(codec,ALI_SPDIF_CTRL + 2));
- wval &= 0xE0F0;
- wval |= (u16)0x09 << 8 | (u16)0x05;
- outw(wval,ALI_REG(codec,ALI_SPDIF_CTRL + 2));
+ wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2));
+ wval &= 0xe0f0;
+ wval |= (0x09 << 8) | 0x05;
+ outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2));
- bval = inb(ALI_REG(codec,ALI_SPDIF_CS +3)) & 0xF0;
- outb(bval|0x02,ALI_REG(codec,ALI_SPDIF_CS + 3));
+ bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)) & 0xf0;
+ outb(bval | 0x02, ALI_REG(codec, ALI_SPDIF_CS + 3));
} else if (R2 == 0x12) {
- wval = inw(ALI_REG(codec,ALI_SPDIF_CTRL + 2));
- wval &= 0xE0F0;
- wval |= (u16)0x0E << 8 | (u16)0x08;
- outw(wval,ALI_REG(codec,ALI_SPDIF_CTRL + 2));
+ wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2));
+ wval &= 0xe0f0;
+ wval |= (0x0e << 8) | 0x08;
+ outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2));
- bval = inb(ALI_REG(codec,ALI_SPDIF_CS +3)) & 0xF0;
- outb(bval|0x03,ALI_REG(codec,ALI_SPDIF_CS + 3));
+ bval = inb(ALI_REG(codec,ALI_SPDIF_CS + 3)) & 0xf0;
+ outb(bval | 0x03, ALI_REG(codec, ALI_SPDIF_CS + 3));
}
}
static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali *codec)
{
- u32 dwRate = 0;
- u8 bval = 0;
+ u32 dwRate;
+ u8 bval;
- bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL));
- bval &= 0x7F;
+ bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
+ bval &= 0x7f;
bval |= 0x40;
- outb(bval, ALI_REG(codec,ALI_SPDIF_CTRL));
+ outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL));
snd_ali_detect_spdif_rate(codec);
- bval = inb(ALI_REG(codec,ALI_SPDIF_CS + 3));
- bval &= 0x0F;
+ bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3));
+ bval &= 0x0f;
- if (bval == 0) dwRate = 44100;
- if (bval == 1) dwRate = 48000;
- if (bval == 2) dwRate = 32000;
+ switch (bval) {
+ case 0: dwRate = 44100; break;
+ case 1: dwRate = 48000; break;
+ case 2: dwRate = 32000; break;
+ default: dwRate = 0; break;
+ }
return dwRate;
}
@@ -880,20 +821,22 @@ static void snd_ali_disable_spdif_in(struct snd_ali *codec)
static void snd_ali_set_spdif_out_rate(struct snd_ali *codec, unsigned int rate)
{
unsigned char bVal;
- unsigned int dwRate = 0;
+ unsigned int dwRate;
- if (rate == 32000) dwRate = 0x300;
- if (rate == 44100) dwRate = 0;
- if (rate == 48000) dwRate = 0x200;
+ switch (rate) {
+ case 32000: dwRate = 0x300; break;
+ case 48000: dwRate = 0x200; break;
+ default: dwRate = 0; break;
+ }
bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
bVal &= (unsigned char)(~(1<<6));
- bVal |= 0x80; //select right
+ bVal |= 0x80; /* select right */
outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL));
outb(dwRate | 0x20, ALI_REG(codec, ALI_SPDIF_CS + 2));
- bVal &= (~0x80); //select left
+ bVal &= ~0x80; /* select left */
outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL));
outw(rate | 0x10, ALI_REG(codec, ALI_SPDIF_CS + 2));
}
@@ -902,8 +845,7 @@ static void snd_ali_enable_spdif_out(struct snd_ali *codec)
{
unsigned short wVal;
unsigned char bVal;
-
- struct pci_dev *pci_dev = NULL;
+ struct pci_dev *pci_dev;
pci_dev = codec->pci_m1533;
if (pci_dev == NULL)
@@ -926,17 +868,15 @@ static void snd_ali_enable_spdif_out(struct snd_ali *codec)
bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
outb(bVal & ALI_SPDIF_OUT_CH_STATUS, ALI_REG(codec, ALI_SPDIF_CTRL));
- {
- wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
- wVal |= ALI_SPDIF_OUT_SEL_PCM;
- outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
- snd_ali_disable_special_channel(codec,ALI_SPDIF_OUT_CHANNEL);
- }
+ wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
+ wVal |= ALI_SPDIF_OUT_SEL_PCM;
+ outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
+ snd_ali_disable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL);
}
static void snd_ali_enable_spdif_chnout(struct snd_ali *codec)
{
- unsigned short wVal = 0;
+ unsigned short wVal;
wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
wVal &= ~ALI_SPDIF_OUT_SEL_PCM;
@@ -949,12 +889,13 @@ static void snd_ali_enable_spdif_chnout(struct snd_ali *codec)
wVal &= (~0x0002);
outw(wVal, ALI_REG(codec, ALI_SPDIF_CS));
*/
- snd_ali_enable_special_channel(codec,ALI_SPDIF_OUT_CHANNEL);
+ snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL);
}
static void snd_ali_disable_spdif_chnout(struct snd_ali *codec)
{
- unsigned short wVal = 0;
+ unsigned short wVal;
+
wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
wVal |= ALI_SPDIF_OUT_SEL_PCM;
outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
@@ -972,11 +913,11 @@ static void snd_ali_disable_spdif_out(struct snd_ali *codec)
snd_ali_disable_spdif_chnout(codec);
}
-static void snd_ali_update_ptr(struct snd_ali *codec,int channel)
+static void snd_ali_update_ptr(struct snd_ali *codec, int channel)
{
- struct snd_ali_voice *pvoice = NULL;
+ struct snd_ali_voice *pvoice;
struct snd_pcm_runtime *runtime;
- struct snd_ali_channel_control *pchregs = NULL;
+ struct snd_ali_channel_control *pchregs;
unsigned int old, mask;
#ifdef ALI_DEBUG
unsigned int temp, cspf;
@@ -984,9 +925,9 @@ static void snd_ali_update_ptr(struct snd_ali *codec,int channel)
pchregs = &(codec->chregs);
- // check if interrupt occurred for channel
+ /* check if interrupt occurred for channel */
old = pchregs->data.aint;
- mask = ((unsigned int) 1L) << (channel & 0x1f);
+ mask = 1U << (channel & 0x1f);
if (!(old & mask))
return;
@@ -1005,7 +946,8 @@ static void snd_ali_update_ptr(struct snd_ali *codec,int channel)
cspf = (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask;
#endif
if (pvoice->running) {
- snd_ali_printk("update_ptr: cso=%4.4x cspf=%d.\n",(u16)temp,cspf);
+ snd_ali_printk("update_ptr: cso=%4.4x cspf=%d.\n",
+ (u16)temp, cspf);
spin_unlock(&codec->reg_lock);
snd_pcm_period_elapsed(pvoice->substream);
spin_lock(&codec->reg_lock);
@@ -1027,49 +969,47 @@ static void snd_ali_update_ptr(struct snd_ali *codec,int channel)
pchregs->data.aint = old & (~mask);
}
-static void snd_ali_interrupt(struct snd_ali * codec)
+static irqreturn_t snd_ali_card_interrupt(int irq, void *dev_id)
{
+ struct snd_ali *codec = dev_id;
int channel;
unsigned int audio_int;
- struct snd_ali_channel_control *pchregs = NULL;
- pchregs = &(codec->chregs);
+ struct snd_ali_channel_control *pchregs;
+
+ if (codec == NULL || !codec->hw_initialized)
+ return IRQ_NONE;
audio_int = inl(ALI_REG(codec, ALI_MISCINT));
+ if (!audio_int)
+ return IRQ_NONE;
+
+ pchregs = &(codec->chregs);
if (audio_int & ADDRESS_IRQ) {
- // get interrupt status for all channels
- pchregs->data.aint = inl(ALI_REG(codec,pchregs->regs.aint));
- for (channel = 0; channel < ALI_CHANNELS; channel++) {
+ /* get interrupt status for all channels */
+ pchregs->data.aint = inl(ALI_REG(codec, pchregs->regs.aint));
+ for (channel = 0; channel < ALI_CHANNELS; channel++)
snd_ali_update_ptr(codec, channel);
- }
}
outl((TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW),
- ALI_REG(codec,ALI_MISCINT));
-}
-
-
-static irqreturn_t snd_ali_card_interrupt(int irq, void *dev_id)
-{
- struct snd_ali *codec = dev_id;
+ ALI_REG(codec, ALI_MISCINT));
- if (codec == NULL)
- return IRQ_NONE;
- snd_ali_interrupt(codec);
return IRQ_HANDLED;
}
-static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec, int type, int rec, int channel)
+static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec,
+ int type, int rec, int channel)
{
- struct snd_ali_voice *pvoice = NULL;
+ struct snd_ali_voice *pvoice;
int idx;
- snd_ali_printk("alloc_voice: type=%d rec=%d\n",type,rec);
+ snd_ali_printk("alloc_voice: type=%d rec=%d\n", type, rec);
spin_lock_irq(&codec->voice_alloc);
if (type == SNDRV_ALI_VOICE_TYPE_PCM) {
idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) :
snd_ali_find_free_channel(codec,rec);
- if(idx < 0) {
+ if (idx < 0) {
snd_printk(KERN_ERR "ali_alloc_voice: err.\n");
spin_unlock_irq(&codec->voice_alloc);
return NULL;
@@ -1087,7 +1027,8 @@ static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec, int typ
}
-static void snd_ali_free_voice(struct snd_ali * codec, struct snd_ali_voice *pvoice)
+static void snd_ali_free_voice(struct snd_ali * codec,
+ struct snd_ali_voice *pvoice)
{
void (*private_free)(void *);
void *private_data;
@@ -1101,9 +1042,8 @@ static void snd_ali_free_voice(struct snd_ali * codec, struct snd_ali_voice *pvo
private_data = pvoice->private_data;
pvoice->private_free = NULL;
pvoice->private_data = NULL;
- if (pvoice->pcm) {
+ if (pvoice->pcm)
snd_ali_free_channel_pcm(codec, pvoice->number);
- }
pvoice->use = pvoice->pcm = pvoice->synth = 0;
pvoice->substream = NULL;
spin_unlock_irq(&codec->voice_alloc);
@@ -1112,9 +1052,9 @@ static void snd_ali_free_voice(struct snd_ali * codec, struct snd_ali_voice *pvo
}
-static void snd_ali_clear_voices(struct snd_ali * codec,
- unsigned int v_min,
- unsigned int v_max)
+static void snd_ali_clear_voices(struct snd_ali *codec,
+ unsigned int v_min,
+ unsigned int v_max)
{
unsigned int i;
@@ -1124,7 +1064,7 @@ static void snd_ali_clear_voices(struct snd_ali * codec,
}
}
-static void snd_ali_write_voice_regs(struct snd_ali * codec,
+static void snd_ali_write_voice_regs(struct snd_ali *codec,
unsigned int Channel,
unsigned int LBA,
unsigned int CSO,
@@ -1139,7 +1079,7 @@ static void snd_ali_write_voice_regs(struct snd_ali * codec,
{
unsigned int ctlcmds[4];
- outb((unsigned char)(Channel & 0x001f),ALI_REG(codec,ALI_GC_CIR));
+ outb((unsigned char)(Channel & 0x001f), ALI_REG(codec, ALI_GC_CIR));
ctlcmds[0] = (CSO << 16) | (ALPHA_FMS & 0x0000ffff);
ctlcmds[1] = LBA;
@@ -1152,10 +1092,10 @@ static void snd_ali_write_voice_regs(struct snd_ali * codec,
outb(Channel, ALI_REG(codec, ALI_GC_CIR));
- outl(ctlcmds[0], ALI_REG(codec,ALI_CSO_ALPHA_FMS));
- outl(ctlcmds[1], ALI_REG(codec,ALI_LBA));
- outl(ctlcmds[2], ALI_REG(codec,ALI_ESO_DELTA));
- outl(ctlcmds[3], ALI_REG(codec,ALI_GVSEL_PAN_VOC_CTRL_EC));
+ outl(ctlcmds[0], ALI_REG(codec, ALI_CSO_ALPHA_FMS));
+ outl(ctlcmds[1], ALI_REG(codec, ALI_LBA));
+ outl(ctlcmds[2], ALI_REG(codec, ALI_ESO_DELTA));
+ outl(ctlcmds[3], ALI_REG(codec, ALI_GVSEL_PAN_VOC_CTRL_EC));
outl(0x30000000, ALI_REG(codec, ALI_EBUF1)); /* Still Mode */
outl(0x30000000, ALI_REG(codec, ALI_EBUF2)); /* Still Mode */
@@ -1165,8 +1105,10 @@ static unsigned int snd_ali_convert_rate(unsigned int rate, int rec)
{
unsigned int delta;
- if (rate < 4000) rate = 4000;
- if (rate > 48000) rate = 48000;
+ if (rate < 4000)
+ rate = 4000;
+ if (rate > 48000)
+ rate = 48000;
if (rec) {
if (rate == 44100)
@@ -1201,11 +1143,11 @@ static unsigned int snd_ali_control_mode(struct snd_pcm_substream *substream)
*/
CTRL = 0x00000001;
if (snd_pcm_format_width(runtime->format) == 16)
- CTRL |= 0x00000008; // 16-bit data
+ CTRL |= 0x00000008; /* 16-bit data */
if (!snd_pcm_format_unsigned(runtime->format))
- CTRL |= 0x00000002; // signed data
+ CTRL |= 0x00000002; /* signed data */
if (runtime->channels > 1)
- CTRL |= 0x00000004; // stereo data
+ CTRL |= 0x00000004; /* stereo data */
return CTRL;
}
@@ -1213,12 +1155,6 @@ static unsigned int snd_ali_control_mode(struct snd_pcm_substream *substream)
* PCM part
*/
-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(struct snd_pcm_substream *substream,
int cmd)
@@ -1226,17 +1162,19 @@ static int snd_ali_trigger(struct snd_pcm_substream *substream,
struct snd_ali *codec = snd_pcm_substream_chip(substream);
struct snd_pcm_substream *s;
unsigned int what, whati, capture_flag;
- struct snd_ali_voice *pvoice = NULL, *evoice = NULL;
+ struct snd_ali_voice *pvoice, *evoice;
unsigned int val;
int do_start;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
- do_start = 1; break;
+ do_start = 1;
+ break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
- do_start = 0; break;
+ do_start = 0;
+ break;
default:
return -EINVAL;
}
@@ -1247,9 +1185,9 @@ static int snd_ali_trigger(struct snd_pcm_substream *substream,
pvoice = s->runtime->private_data;
evoice = pvoice->extra;
what |= 1 << (pvoice->number & 0x1f);
- if (evoice == NULL) {
+ if (evoice == NULL)
whati |= 1 << (pvoice->number & 0x1f);
- } else {
+ else {
whati |= 1 << (evoice->number & 0x1f);
what |= 1 << (evoice->number & 0x1f);
}
@@ -1268,48 +1206,51 @@ static int snd_ali_trigger(struct snd_pcm_substream *substream,
}
}
spin_lock(&codec->reg_lock);
- if (! do_start) {
+ if (!do_start)
outl(what, ALI_REG(codec, ALI_STOP));
- }
val = inl(ALI_REG(codec, ALI_AINTEN));
- if (do_start) {
+ if (do_start)
val |= whati;
- } else {
+ else
val &= ~whati;
- }
outl(val, ALI_REG(codec, ALI_AINTEN));
- if (do_start) {
+ if (do_start)
outl(what, ALI_REG(codec, ALI_START));
- }
- snd_ali_printk("trigger: what=%xh whati=%xh\n",what,whati);
+ snd_ali_printk("trigger: what=%xh whati=%xh\n", what, whati);
spin_unlock(&codec->reg_lock);
return 0;
}
static int snd_ali_playback_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
+ struct snd_pcm_hw_params *hw_params)
{
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;
+
+ err = snd_pcm_lib_malloc_pages(substream,
+ params_buffer_bytes(hw_params));
+ if (err < 0)
+ return err;
/* voice management */
- 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, -1);
- if (evoice == NULL)
+ if (params_buffer_size(hw_params) / 2 !=
+ params_period_size(hw_params)) {
+ if (!evoice) {
+ evoice = snd_ali_alloc_voice(codec,
+ SNDRV_ALI_VOICE_TYPE_PCM,
+ 0, -1);
+ if (!evoice)
return -ENOMEM;
pvoice->extra = evoice;
evoice->substream = substream;
}
} else {
- if (evoice != NULL) {
+ if (!evoice) {
snd_ali_free_voice(codec, evoice);
pvoice->extra = evoice = NULL;
}
@@ -1326,7 +1267,7 @@ static int snd_ali_playback_hw_free(struct snd_pcm_substream *substream)
struct snd_ali_voice *evoice = pvoice ? pvoice->extra : NULL;
snd_pcm_lib_free_pages(substream);
- if (evoice != NULL) {
+ if (!evoice) {
snd_ali_free_voice(codec, evoice);
pvoice->extra = NULL;
}
@@ -1334,9 +1275,10 @@ static int snd_ali_playback_hw_free(struct snd_pcm_substream *substream)
}
static int snd_ali_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
+ struct snd_pcm_hw_params *hw_params)
{
- return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
+ return snd_pcm_lib_malloc_pages(substream,
+ params_buffer_bytes(hw_params));
}
static int snd_ali_hw_free(struct snd_pcm_substream *substream)
@@ -1367,12 +1309,13 @@ static int snd_ali_playback_prepare(struct snd_pcm_substream *substream)
/* set Delta (rate) value */
Delta = snd_ali_convert_rate(runtime->rate, 0);
- if