提交 33ea25c1 编写于 作者: T Takashi Iwai 提交者: Jaroslav Kysela

[ALSA] au1x00 - Code clean up

Modules: MIPS AU1x00 driver

Clean up snd-au1x00 driver code:

- Remove global variables
- Remove old compatibility codes
- Fix DMA-link allocation/release functions in hw_params and hw_free
  callbacks (they may be called multiple times)
- Fix spinlocks
Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 6560c349
...@@ -50,12 +50,7 @@ ...@@ -50,12 +50,7 @@
MODULE_AUTHOR("Charles Eidsness <charles@cooper-street.com>"); MODULE_AUTHOR("Charles Eidsness <charles@cooper-street.com>");
MODULE_DESCRIPTION("Au1000 AC'97 ALSA Driver"); MODULE_DESCRIPTION("Au1000 AC'97 ALSA Driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
MODULE_SUPPORTED_DEVICE("{{AMD,Au1000 AC'97}}"); MODULE_SUPPORTED_DEVICE("{{AMD,Au1000 AC'97}}");
#else
MODULE_CLASSES("{sound}");
MODULE_DEVICES("{{AMD,Au1000 AC'97}}");
#endif
#define PLAYBACK 0 #define PLAYBACK 0
#define CAPTURE 1 #define CAPTURE 1
...@@ -68,8 +63,6 @@ MODULE_DEVICES("{{AMD,Au1000 AC'97}}"); ...@@ -68,8 +63,6 @@ MODULE_DEVICES("{{AMD,Au1000 AC'97}}");
#define READ_WAIT 2 #define READ_WAIT 2
#define RW_DONE 3 #define RW_DONE 3
DECLARE_WAIT_QUEUE_HEAD(ac97_command_wq);
typedef struct au1000_period au1000_period_t; typedef struct au1000_period au1000_period_t;
struct au1000_period struct au1000_period
{ {
...@@ -94,7 +87,8 @@ struct audio_stream { ...@@ -94,7 +87,8 @@ struct audio_stream {
int dma; int dma;
spinlock_t dma_lock; spinlock_t dma_lock;
au1000_period_t * buffer; au1000_period_t * buffer;
unsigned long period_size; unsigned int period_size;
unsigned int periods;
}; };
typedef struct snd_card_au1000 { typedef struct snd_card_au1000 {
...@@ -109,11 +103,9 @@ typedef struct snd_card_au1000 { ...@@ -109,11 +103,9 @@ typedef struct snd_card_au1000 {
audio_stream_t *stream[2]; /* playback & capture */ audio_stream_t *stream[2]; /* playback & capture */
} au1000_t; } au1000_t;
static au1000_t *au1000 = NULL;
/*--------------------------- Local Functions --------------------------------*/ /*--------------------------- Local Functions --------------------------------*/
static void static void
au1000_set_ac97_xmit_slots(long xmit_slots) au1000_set_ac97_xmit_slots(au1000_t *au1000, long xmit_slots)
{ {
u32 volatile ac97_config; u32 volatile ac97_config;
...@@ -126,7 +118,7 @@ au1000_set_ac97_xmit_slots(long xmit_slots) ...@@ -126,7 +118,7 @@ au1000_set_ac97_xmit_slots(long xmit_slots)
} }
static void static void
au1000_set_ac97_recv_slots(long recv_slots) au1000_set_ac97_recv_slots(au1000_t *au1000, long recv_slots)
{ {
u32 volatile ac97_config; u32 volatile ac97_config;
...@@ -140,61 +132,76 @@ au1000_set_ac97_recv_slots(long recv_slots) ...@@ -140,61 +132,76 @@ au1000_set_ac97_recv_slots(long recv_slots)
static void static void
au1000_dma_stop(audio_stream_t *stream) au1000_release_dma_link(audio_stream_t *stream)
{ {
unsigned long flags;
au1000_period_t * pointer; au1000_period_t * pointer;
au1000_period_t * pointer_next; au1000_period_t * pointer_next;
if (stream->buffer != NULL) { stream->period_size = 0;
spin_lock_irqsave(&stream->dma_lock, flags); stream->periods = 0;
disable_dma(stream->dma);
spin_unlock_irqrestore(&stream->dma_lock, flags);
pointer = stream->buffer; pointer = stream->buffer;
pointer_next = stream->buffer->next; if (! pointer)
return;
do { do {
pointer_next = pointer->next;
kfree(pointer); kfree(pointer);
pointer = pointer_next; pointer = pointer_next;
pointer_next = pointer->next;
} while (pointer != stream->buffer); } while (pointer != stream->buffer);
stream->buffer = NULL; stream->buffer = NULL;
}
} }
static void static int
au1000_dma_start(audio_stream_t *stream) au1000_setup_dma_link(audio_stream_t *stream, unsigned int period_bytes,
unsigned int periods)
{ {
snd_pcm_substream_t *substream = stream->substream; snd_pcm_substream_t *substream = stream->substream;
snd_pcm_runtime_t *runtime = substream->runtime; snd_pcm_runtime_t *runtime = substream->runtime;
unsigned long dma_start;
unsigned long flags, dma_start;
int i; int i;
au1000_period_t * pointer;
if (stream->buffer == NULL) {
dma_start = virt_to_phys(runtime->dma_area); dma_start = virt_to_phys(runtime->dma_area);
stream->period_size = frames_to_bytes(runtime, if (stream->period_size == period_bytes &&
runtime->period_size); stream->periods == periods)
return 0; /* not changed */
au1000_release_dma_link(stream);
stream->period_size = period_bytes;
stream->periods = periods;
stream->buffer = kmalloc(sizeof(au1000_period_t), GFP_KERNEL); stream->buffer = kmalloc(sizeof(au1000_period_t), GFP_KERNEL);
if (! stream->buffer)
return -ENOMEM;
pointer = stream->buffer; pointer = stream->buffer;
for (i = 0 ; i < runtime->periods ; i++) { for (i = 0; i < periods; i++) {
pointer->start = (u32)(dma_start + pointer->start = (u32)(dma_start + (i * period_bytes));
(i * stream->period_size)); pointer->relative_end = (u32) (((i+1) * period_bytes) - 0x1);
pointer->relative_end = (u32) if (i < periods - 1) {
(((i+1) * stream->period_size) - 0x1); pointer->next = kmalloc(sizeof(struct au1000_period), GFP_KERNEL);
if ( i < runtime->periods - 1) { if (! pointer->next) {
pointer->next = kmalloc(sizeof(au1000_period_t) au1000_release_dma_link(stream);
, GFP_KERNEL); return -ENOMEM;
}
pointer = pointer->next; pointer = pointer->next;
} }
} }
pointer->next = stream->buffer; pointer->next = stream->buffer;
return 0;
}
static void
au1000_dma_stop(audio_stream_t *stream)
{
snd_assert(stream->buffer, return);
disable_dma(stream->dma);
}
static void
au1000_dma_start(audio_stream_t *stream)
{
snd_assert(stream->buffer, return);
spin_lock_irqsave(&stream->dma_lock, flags);
init_dma(stream->dma); init_dma(stream->dma);
if (get_dma_active_buffer(stream->dma) == 0) { if (get_dma_active_buffer(stream->dma) == 0) {
clear_dma_done0(stream->dma); clear_dma_done0(stream->dma);
...@@ -211,8 +218,6 @@ au1000_dma_start(audio_stream_t *stream) ...@@ -211,8 +218,6 @@ au1000_dma_start(audio_stream_t *stream)
} }
enable_dma_buffers(stream->dma); enable_dma_buffers(stream->dma);
start_dma(stream->dma); start_dma(stream->dma);
spin_unlock_irqrestore(&stream->dma_lock, flags);
}
} }
static irqreturn_t static irqreturn_t
...@@ -238,11 +243,9 @@ au1000_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs) ...@@ -238,11 +243,9 @@ au1000_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
enable_dma_buffer1(stream->dma); enable_dma_buffer1(stream->dma);
break; break;
case (DMA_D0 | DMA_D1): case (DMA_D0 | DMA_D1):
spin_unlock(&stream->dma_lock);
printk(KERN_ERR "DMA %d missed interrupt.\n",stream->dma); printk(KERN_ERR "DMA %d missed interrupt.\n",stream->dma);
au1000_dma_stop(stream); au1000_dma_stop(stream);
au1000_dma_start(stream); au1000_dma_start(stream);
spin_lock(&stream->dma_lock);
break; break;
case (~DMA_D0 & ~DMA_D1): case (~DMA_D0 & ~DMA_D1):
printk(KERN_ERR "DMA %d empty irq.\n",stream->dma); printk(KERN_ERR "DMA %d empty irq.\n",stream->dma);
...@@ -261,7 +264,7 @@ static snd_pcm_hw_constraint_list_t hw_constraints_rates = { ...@@ -261,7 +264,7 @@ static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
.mask = 0, .mask = 0,
}; };
static snd_pcm_hardware_t snd_au1000 = static snd_pcm_hardware_t snd_au1000_hw =
{ {
.info = (SNDRV_PCM_INFO_INTERLEAVED | \ .info = (SNDRV_PCM_INFO_INTERLEAVED | \
SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID), SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
...@@ -283,10 +286,12 @@ static snd_pcm_hardware_t snd_au1000 = ...@@ -283,10 +286,12 @@ static snd_pcm_hardware_t snd_au1000 =
static int static int
snd_au1000_playback_open(snd_pcm_substream_t * substream) snd_au1000_playback_open(snd_pcm_substream_t * substream)
{ {
au1000_t *au1000 = substream->pcm->private_data;
au1000->stream[PLAYBACK]->substream = substream; au1000->stream[PLAYBACK]->substream = substream;
au1000->stream[PLAYBACK]->buffer = NULL; au1000->stream[PLAYBACK]->buffer = NULL;
substream->private_data = au1000->stream[PLAYBACK]; substream->private_data = au1000->stream[PLAYBACK];
substream->runtime->hw = snd_au1000; substream->runtime->hw = snd_au1000_hw;
return (snd_pcm_hw_constraint_list(substream->runtime, 0, return (snd_pcm_hw_constraint_list(substream->runtime, 0,
SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates) < 0); SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates) < 0);
} }
...@@ -294,10 +299,12 @@ snd_au1000_playback_open(snd_pcm_substream_t * substream) ...@@ -294,10 +299,12 @@ snd_au1000_playback_open(snd_pcm_substream_t * substream)
static int static int
snd_au1000_capture_open(snd_pcm_substream_t * substream) snd_au1000_capture_open(snd_pcm_substream_t * substream)
{ {
au1000_t *au1000 = substream->pcm->private_data;
au1000->stream[CAPTURE]->substream = substream; au1000->stream[CAPTURE]->substream = substream;
au1000->stream[CAPTURE]->buffer = NULL; au1000->stream[CAPTURE]->buffer = NULL;
substream->private_data = au1000->stream[CAPTURE]; substream->private_data = au1000->stream[CAPTURE];
substream->runtime->hw = snd_au1000; substream->runtime->hw = snd_au1000_hw;
return (snd_pcm_hw_constraint_list(substream->runtime, 0, return (snd_pcm_hw_constraint_list(substream->runtime, 0,
SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates) < 0); SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates) < 0);
...@@ -306,6 +313,8 @@ snd_au1000_capture_open(snd_pcm_substream_t * substream) ...@@ -306,6 +313,8 @@ snd_au1000_capture_open(snd_pcm_substream_t * substream)
static int static int
snd_au1000_playback_close(snd_pcm_substream_t * substream) snd_au1000_playback_close(snd_pcm_substream_t * substream)
{ {
au1000_t *au1000 = substream->pcm->private_data;
au1000->stream[PLAYBACK]->substream = NULL; au1000->stream[PLAYBACK]->substream = NULL;
return 0; return 0;
} }
...@@ -313,6 +322,8 @@ snd_au1000_playback_close(snd_pcm_substream_t * substream) ...@@ -313,6 +322,8 @@ snd_au1000_playback_close(snd_pcm_substream_t * substream)
static int static int
snd_au1000_capture_close(snd_pcm_substream_t * substream) snd_au1000_capture_close(snd_pcm_substream_t * substream)
{ {
au1000_t *au1000 = substream->pcm->private_data;
au1000->stream[CAPTURE]->substream = NULL; au1000->stream[CAPTURE]->substream = NULL;
return 0; return 0;
} }
...@@ -321,25 +332,36 @@ static int ...@@ -321,25 +332,36 @@ static int
snd_au1000_hw_params(snd_pcm_substream_t * substream, snd_au1000_hw_params(snd_pcm_substream_t * substream,
snd_pcm_hw_params_t * hw_params) snd_pcm_hw_params_t * hw_params)
{ {
return snd_pcm_lib_malloc_pages(substream, audio_stream_t *stream = substream->private_data;
int err;
err = snd_pcm_lib_malloc_pages(substream,
params_buffer_bytes(hw_params)); params_buffer_bytes(hw_params));
if (err < 0)
return err;
return au1000_setup_dma_link(stream,
params_period_bytes(hw_params),
params_periods(hw_params));
} }
static int static int
snd_au1000_hw_free(snd_pcm_substream_t * substream) snd_au1000_hw_free(snd_pcm_substream_t * substream)
{ {
audio_stream_t *stream = substream->private_data;
au1000_release_dma_link(stream);
return snd_pcm_lib_free_pages(substream); return snd_pcm_lib_free_pages(substream);
} }
static int static int
snd_au1000_playback_prepare(snd_pcm_substream_t * substream) snd_au1000_playback_prepare(snd_pcm_substream_t * substream)
{ {
au1000_t *au1000 = substream->pcm->private_data;
snd_pcm_runtime_t *runtime = substream->runtime; snd_pcm_runtime_t *runtime = substream->runtime;
if (runtime->channels == 1 ) if (runtime->channels == 1)
au1000_set_ac97_xmit_slots(AC97_SLOT_4); au1000_set_ac97_xmit_slots(au1000, AC97_SLOT_4);
else else
au1000_set_ac97_xmit_slots(AC97_SLOT_3 | AC97_SLOT_4); au1000_set_ac97_xmit_slots(au1000, AC97_SLOT_3 | AC97_SLOT_4);
snd_ac97_set_rate(au1000->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); snd_ac97_set_rate(au1000->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
return 0; return 0;
} }
...@@ -347,12 +369,13 @@ snd_au1000_playback_prepare(snd_pcm_substream_t * substream) ...@@ -347,12 +369,13 @@ snd_au1000_playback_prepare(snd_pcm_substream_t * substream)
static int static int
snd_au1000_capture_prepare(snd_pcm_substream_t * substream) snd_au1000_capture_prepare(snd_pcm_substream_t * substream)
{ {
au1000_t *au1000 = substream->pcm->private_data;
snd_pcm_runtime_t *runtime = substream->runtime; snd_pcm_runtime_t *runtime = substream->runtime;
if (runtime->channels == 1 ) if (runtime->channels == 1)
au1000_set_ac97_recv_slots(AC97_SLOT_4); au1000_set_ac97_recv_slots(au1000, AC97_SLOT_4);
else else
au1000_set_ac97_recv_slots(AC97_SLOT_3 | AC97_SLOT_4); au1000_set_ac97_recv_slots(au1000, AC97_SLOT_3 | AC97_SLOT_4);
snd_ac97_set_rate(au1000->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); snd_ac97_set_rate(au1000->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
return 0; return 0;
} }
...@@ -363,6 +386,7 @@ snd_au1000_trigger(snd_pcm_substream_t * substream, int cmd) ...@@ -363,6 +386,7 @@ snd_au1000_trigger(snd_pcm_substream_t * substream, int cmd)
audio_stream_t *stream = substream->private_data; audio_stream_t *stream = substream->private_data;
int err = 0; int err = 0;
spin_lock(&stream->dma_lock);
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
au1000_dma_start(stream); au1000_dma_start(stream);
...@@ -374,6 +398,7 @@ snd_au1000_trigger(snd_pcm_substream_t * substream, int cmd) ...@@ -374,6 +398,7 @@ snd_au1000_trigger(snd_pcm_substream_t * substream, int cmd)
err = -EINVAL; err = -EINVAL;
break; break;
} }
spin_unlock(&stream->dma_lock);
return err; return err;
} }
...@@ -382,12 +407,11 @@ snd_au1000_pointer(snd_pcm_substream_t * substream) ...@@ -382,12 +407,11 @@ snd_au1000_pointer(snd_pcm_substream_t * substream)
{ {
audio_stream_t *stream = substream->private_data; audio_stream_t *stream = substream->private_data;
snd_pcm_runtime_t *runtime = substream->runtime; snd_pcm_runtime_t *runtime = substream->runtime;
unsigned long flags;
long location; long location;
spin_lock_irqsave(&stream->dma_lock, flags); spin_lock(&stream->dma_lock);
location = get_dma_residue(stream->dma); location = get_dma_residue(stream->dma);
spin_unlock_irqrestore(&stream->dma_lock, flags); spin_unlock(&stream->dma_lock);
location = stream->buffer->relative_end - location; location = stream->buffer->relative_end - location;
if (location == -1) if (location == -1)
location = 0; location = 0;
...@@ -438,6 +462,9 @@ snd_au1000_pcm_new(void) ...@@ -438,6 +462,9 @@ snd_au1000_pcm_new(void)
pcm->info_flags = 0; pcm->info_flags = 0;
strcpy(pcm->name, "Au1000 AC97 PCM"); strcpy(pcm->name, "Au1000 AC97 PCM");
spin_lock_init(&au1000->stream[PLAYBACK]->dma_lock);
spin_lock_init(&au1000->stream[CAPTURE]->dma_lock);
flags = claim_dma_lock(); flags = claim_dma_lock();
if ((au1000->stream[PLAYBACK]->dma = request_au1000_dma(DMA_ID_AC97C_TX, if ((au1000->stream[PLAYBACK]->dma = request_au1000_dma(DMA_ID_AC97C_TX,
"AC97 TX", au1000_dma_interrupt, SA_INTERRUPT, "AC97 TX", au1000_dma_interrupt, SA_INTERRUPT,
...@@ -457,8 +484,6 @@ snd_au1000_pcm_new(void) ...@@ -457,8 +484,6 @@ snd_au1000_pcm_new(void)
set_dma_mode(au1000->stream[CAPTURE]->dma, set_dma_mode(au1000->stream[CAPTURE]->dma,
get_dma_mode(au1000->stream[CAPTURE]->dma) & ~DMA_NC); get_dma_mode(au1000->stream[CAPTURE]->dma) & ~DMA_NC);
release_dma_lock(flags); release_dma_lock(flags);
spin_lock_init(&au1000->stream[PLAYBACK]->dma_lock);
spin_lock_init(&au1000->stream[CAPTURE]->dma_lock);
au1000->pcm = pcm; au1000->pcm = pcm;
return 0; return 0;
} }
...@@ -469,9 +494,11 @@ snd_au1000_pcm_new(void) ...@@ -469,9 +494,11 @@ snd_au1000_pcm_new(void)
static unsigned short static unsigned short
snd_au1000_ac97_read(ac97_t *ac97, unsigned short reg) snd_au1000_ac97_read(ac97_t *ac97, unsigned short reg)
{ {
au1000_t *au1000 = ac97->private_data;
u32 volatile cmd; u32 volatile cmd;
u16 volatile data; u16 volatile data;
int i; int i;
spin_lock(&au1000->ac97_lock); spin_lock(&au1000->ac97_lock);
/* would rather use the interupt than this polling but it works and I can't /* would rather use the interupt than this polling but it works and I can't
get the interupt driven case to work efficiently */ get the interupt driven case to work efficiently */
...@@ -505,8 +532,10 @@ get the interupt driven case to work efficiently */ ...@@ -505,8 +532,10 @@ get the interupt driven case to work efficiently */
static void static void
snd_au1000_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short val) snd_au1000_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short val)
{ {
au1000_t *au1000 = ac97->private_data;
u32 cmd; u32 cmd;
int i; int i;
spin_lock(&au1000->ac97_lock); spin_lock(&au1000->ac97_lock);
/* would rather use the interupt than this polling but it works and I can't /* would rather use the interupt than this polling but it works and I can't
get the interupt driven case to work efficiently */ get the interupt driven case to work efficiently */
...@@ -522,28 +551,13 @@ get the interupt driven case to work efficiently */ ...@@ -522,28 +551,13 @@ get the interupt driven case to work efficiently */
au1000->ac97_ioport->cmd = cmd; au1000->ac97_ioport->cmd = cmd;
spin_unlock(&au1000->ac97_lock); spin_unlock(&au1000->ac97_lock);
} }
static void
snd_au1000_ac97_free(ac97_t *ac97)
{
au1000->ac97 = NULL;
}
static int __devinit static int __devinit
snd_au1000_ac97_new(void) snd_au1000_ac97_new(au1000_t *au1000)
{ {
int err; int err;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
ac97_bus_t *pbus;
ac97_template_t ac97;
static ac97_bus_ops_t ops = {
.write = snd_au1000_ac97_write,
.read = snd_au1000_ac97_read,
};
#else
ac97_bus_t bus, *pbus; ac97_bus_t bus, *pbus;
ac97_t ac97; ac97_t ac97;
#endif
if ((au1000->ac97_res_port = request_region(AC97C_CONFIG, if ((au1000->ac97_res_port = request_region(AC97C_CONFIG,
sizeof(au1000_ac97_reg_t), "Au1x00 AC97")) == NULL) { sizeof(au1000_ac97_reg_t), "Au1x00 AC97")) == NULL) {
...@@ -554,8 +568,6 @@ snd_au1000_ac97_new(void) ...@@ -554,8 +568,6 @@ snd_au1000_ac97_new(void)
spin_lock_init(&au1000->ac97_lock); spin_lock_init(&au1000->ac97_lock);
spin_lock(&au1000->ac97_lock);
/* configure pins for AC'97 /* configure pins for AC'97
TODO: move to board_setup.c */ TODO: move to board_setup.c */
au_writel(au_readl(SYS_PINFUNC) & ~0x02, SYS_PINFUNC); au_writel(au_readl(SYS_PINFUNC) & ~0x02, SYS_PINFUNC);
...@@ -572,26 +584,16 @@ snd_au1000_ac97_new(void) ...@@ -572,26 +584,16 @@ snd_au1000_ac97_new(void)
au1000->ac97_ioport->config = 0x0; au1000->ac97_ioport->config = 0x0;
mdelay(5); mdelay(5);
spin_unlock(&au1000->ac97_lock);
/* Initialise AC97 middle-layer */ /* Initialise AC97 middle-layer */
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
if ((err = snd_ac97_bus(au1000->card, 0, &ops, au1000, &pbus)) < 0) if ((err = snd_ac97_bus(au1000->card, 0, &ops, au1000, &pbus)) < 0)
return err; return err;
#else
memset(&bus, 0, sizeof(bus));
bus.write = snd_au1000_ac97_write;
bus.read = snd_au1000_ac97_read;
if ((err = snd_ac97_bus(au1000->card, &bus, &pbus)) < 0)
return err;
#endif
memset(&ac97, 0, sizeof(ac97)); memset(&ac97, 0, sizeof(ac97));
ac97.private_data = au1000; ac97.private_data = au1000;
ac97.private_free = snd_au1000_ac97_free;
if ((err = snd_ac97_mixer(pbus, &ac97, &au1000->ac97)) < 0) if ((err = snd_ac97_mixer(pbus, &ac97, &au1000->ac97)) < 0)
return err; return err;
return 0;
return 0;
} }
/*------------------------------ Setup / Destroy ----------------------------*/ /*------------------------------ Setup / Destroy ----------------------------*/
...@@ -599,6 +601,7 @@ snd_au1000_ac97_new(void) ...@@ -599,6 +601,7 @@ snd_au1000_ac97_new(void)
void void
snd_au1000_free(snd_card_t *card) snd_au1000_free(snd_card_t *card)
{ {
au1000_t *au1000 = card->private_data;
if (au1000->ac97_res_port) { if (au1000->ac97_res_port) {
/* put internal AC97 block into reset */ /* put internal AC97 block into reset */
...@@ -614,73 +617,70 @@ snd_au1000_free(snd_card_t *card) ...@@ -614,73 +617,70 @@ snd_au1000_free(snd_card_t *card)
free_au1000_dma(au1000->stream[CAPTURE]->dma); free_au1000_dma(au1000->stream[CAPTURE]->dma);
kfree(au1000->stream[PLAYBACK]); kfree(au1000->stream[PLAYBACK]);
au1000->stream[PLAYBACK] = NULL;
kfree(au1000->stream[CAPTURE]); kfree(au1000->stream[CAPTURE]);
au1000->stream[CAPTURE] = NULL;
kfree(au1000);
au1000 = NULL;
} }
static snd_card_t *au1000_card;
static int __init static int __init
au1000_init(void) au1000_init(void)
{ {
int err; int err;
snd_card_t *card;
au1000_t *au1000;
au1000 = kmalloc(sizeof(au1000_t), GFP_KERNEL); card = snd_card_new(-1, "AC97", THIS_MODULE, sizeof(au1000_t));
if (au1000 == NULL) if (card == NULL)
return -ENOMEM;
au1000->stream[PLAYBACK] = kmalloc(sizeof(audio_stream_t), GFP_KERNEL);
if (au1000->stream[PLAYBACK] == NULL)
return -ENOMEM;
au1000->stream[CAPTURE] = kmalloc(sizeof(audio_stream_t), GFP_KERNEL);
if (au1000->stream[CAPTURE] == NULL)
return -ENOMEM; return -ENOMEM;
card->private_free = snd_au1000_free;
au1000 = card->private_data;
/* so that snd_au1000_free will work as intended */ /* so that snd_au1000_free will work as intended */
au1000->card = card;
au1000->stream[PLAYBACK]->dma = -1; au1000->stream[PLAYBACK]->dma = -1;
au1000->stream[CAPTURE]->dma = -1; au1000->stream[CAPTURE]->dma = -1;
au1000->ac97_res_port = NULL; au1000->ac97_res_port = NULL;
au1000->stream[PLAYBACK] = kmalloc(sizeof(audio_stream_t), GFP_KERNEL);
au1000->card = snd_card_new(-1, "AC97", THIS_MODULE, sizeof(au1000_t)); au1000->stream[CAPTURE] = kmalloc(sizeof(audio_stream_t), GFP_KERNEL);
if (au1000->card == NULL) { if (au1000->stream[PLAYBACK] == NULL ||
snd_au1000_free(au1000->card); au1000->stream[CAPTURE] == NULL) {
snd_card_free(card);
return -ENOMEM; return -ENOMEM;
} }
au1000->card->private_data = (au1000_t *)au1000; if ((err = snd_au1000_ac97_new(au1000)) < 0 ) {
au1000->card->private_free = snd_au1000_free; snd_card_free(card);
if ((err = snd_au1000_ac97_new()) < 0 ) {
snd_card_free(au1000->card);
return err; return err;
} }
if ((err = snd_au1000_pcm_new()) < 0) { if ((err = snd_au1000_pcm_new(au1000)) < 0) {
snd_card_free(au1000->card); snd_card_free(card);
return err; return err;
} }
strcpy(au1000->card->driver, "AMD-Au1000-AC97"); strcpy(card->driver, "Au1000-AC97");
strcpy(au1000->card->shortname, "Au1000-AC97"); strcpy(card->shortname, "AMD Au1000-AC97");
sprintf(au1000->card->longname, "AMD Au1000--AC97 ALSA Driver"); sprintf(card->longname, "AMD Au1000--AC97 ALSA Driver");
if ((err = snd_card_set_generic_dev(au1000->card)) < 0) { if ((err = snd_card_set_generic_dev(card)) < 0) {
snd_card_free(au1000->card); snd_card_free(card);
return err; return err;
} }
if ((err = snd_card_register(au1000->card)) < 0) { if ((err = snd_card_register(card)) < 0) {
snd_card_free(au1000->card); snd_card_free(card);
return err; return err;
} }
printk( KERN_INFO "ALSA AC97: Driver Initialized\n" ); printk( KERN_INFO "ALSA AC97: Driver Initialized\n" );
au1000_card = card;
return 0; return 0;
} }
static void __exit au1000_exit(void) static void __exit au1000_exit(void)
{ {
snd_card_free(au1000->card); snd_card_free(au1000_card);
} }
module_init(au1000_init); module_init(au1000_init);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册