2 * Driver for NeoMagic 256AV and 256ZX chipsets.
3 * Copyright (c) 2000 by Takashi Iwai <tiwai@suse.de>
5 * Based on nm256_audio.c OSS driver in linux kernel.
6 * The original author of OSS nm256 driver wishes to remain anonymous,
7 * so I just put my acknoledgment to him/her here.
8 * The original author's web page is found at
9 * http://www.uglx.org/sony.html
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <sound/driver.h>
29 #include <linux/delay.h>
30 #include <linux/interrupt.h>
31 #include <linux/init.h>
32 #include <linux/pci.h>
33 #include <linux/slab.h>
34 #include <linux/moduleparam.h>
35 #include <sound/core.h>
36 #include <sound/info.h>
37 #include <sound/control.h>
38 #include <sound/pcm.h>
39 #include <sound/ac97_codec.h>
40 #include <sound/initval.h>
42 #define CARD_NAME "NeoMagic 256AV/ZX"
43 #define DRIVER_NAME "NM256"
45 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
46 MODULE_DESCRIPTION("NeoMagic NM256AV/ZX");
47 MODULE_LICENSE("GPL");
48 MODULE_SUPPORTED_DEVICE("{{NeoMagic,NM256AV},"
49 "{NeoMagic,NM256ZX}}");
52 * some compile conditions.
55 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
56 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
57 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
58 static int playback_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 16};
59 static int capture_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 16};
60 static int force_ac97[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* disabled as default */
61 static int buffer_top[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* not specified */
62 static int use_cache[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* disabled */
63 static int vaio_hack[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* disabled */
64 static int reset_workaround[SNDRV_CARDS];
66 module_param_array(index, int, NULL, 0444);
67 MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
68 module_param_array(id, charp, NULL, 0444);
69 MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
70 module_param_array(enable, bool, NULL, 0444);
71 MODULE_PARM_DESC(enable, "Enable this soundcard.");
72 module_param_array(playback_bufsize, int, NULL, 0444);
73 MODULE_PARM_DESC(playback_bufsize, "DAC frame size in kB for " CARD_NAME " soundcard.");
74 module_param_array(capture_bufsize, int, NULL, 0444);
75 MODULE_PARM_DESC(capture_bufsize, "ADC frame size in kB for " CARD_NAME " soundcard.");
76 module_param_array(force_ac97, bool, NULL, 0444);
77 MODULE_PARM_DESC(force_ac97, "Force to use AC97 codec for " CARD_NAME " soundcard.");
78 module_param_array(buffer_top, int, NULL, 0444);
79 MODULE_PARM_DESC(buffer_top, "Set the top address of audio buffer for " CARD_NAME " soundcard.");
80 module_param_array(use_cache, bool, NULL, 0444);
81 MODULE_PARM_DESC(use_cache, "Enable the cache for coefficient table access.");
82 module_param_array(vaio_hack, bool, NULL, 0444);
83 MODULE_PARM_DESC(vaio_hack, "Enable workaround for Sony VAIO notebooks.");
84 module_param_array(reset_workaround, bool, NULL, 0444);
85 MODULE_PARM_DESC(reset_workaround, "Enable AC97 RESET workaround for some laptops.");
91 /* The BIOS signature. */
92 #define NM_SIGNATURE 0x4e4d0000
94 #define NM_SIG_MASK 0xffff0000
96 /* Size of the second memory area. */
97 #define NM_PORT2_SIZE 4096
99 /* The base offset of the mixer in the second memory area. */
100 #define NM_MIXER_OFFSET 0x600
102 /* The maximum size of a coefficient entry. */
103 #define NM_MAX_PLAYBACK_COEF_SIZE 0x5000
104 #define NM_MAX_RECORD_COEF_SIZE 0x1260
106 /* The interrupt register. */
107 #define NM_INT_REG 0xa04
109 #define NM_PLAYBACK_INT 0x40
110 #define NM_RECORD_INT 0x100
111 #define NM_MISC_INT_1 0x4000
112 #define NM_MISC_INT_2 0x1
113 #define NM_ACK_INT(chip, X) snd_nm256_writew(chip, NM_INT_REG, (X) << 1)
115 /* The AV's "mixer ready" status bit and location. */
116 #define NM_MIXER_STATUS_OFFSET 0xa04
117 #define NM_MIXER_READY_MASK 0x0800
118 #define NM_MIXER_PRESENCE 0xa06
119 #define NM_PRESENCE_MASK 0x0050
120 #define NM_PRESENCE_VALUE 0x0040
123 * For the ZX. It uses the same interrupt register, but it holds 32
124 * bits instead of 16.
126 #define NM2_PLAYBACK_INT 0x10000
127 #define NM2_RECORD_INT 0x80000
128 #define NM2_MISC_INT_1 0x8
129 #define NM2_MISC_INT_2 0x2
130 #define NM2_ACK_INT(chip, X) snd_nm256_writel(chip, NM_INT_REG, (X))
132 /* The ZX's "mixer ready" status bit and location. */
133 #define NM2_MIXER_STATUS_OFFSET 0xa06
134 #define NM2_MIXER_READY_MASK 0x0800
136 /* The playback registers start from here. */
137 #define NM_PLAYBACK_REG_OFFSET 0x0
138 /* The record registers start from here. */
139 #define NM_RECORD_REG_OFFSET 0x200
141 /* The rate register is located 2 bytes from the start of the register area. */
142 #define NM_RATE_REG_OFFSET 2
144 /* Mono/stereo flag, number of bits on playback, and rate mask. */
145 #define NM_RATE_STEREO 1
146 #define NM_RATE_BITS_16 2
147 #define NM_RATE_MASK 0xf0
149 /* Playback enable register. */
150 #define NM_PLAYBACK_ENABLE_REG (NM_PLAYBACK_REG_OFFSET + 0x1)
151 #define NM_PLAYBACK_ENABLE_FLAG 1
152 #define NM_PLAYBACK_ONESHOT 2
153 #define NM_PLAYBACK_FREERUN 4
155 /* Mutes the audio output. */
156 #define NM_AUDIO_MUTE_REG (NM_PLAYBACK_REG_OFFSET + 0x18)
157 #define NM_AUDIO_MUTE_LEFT 0x8000
158 #define NM_AUDIO_MUTE_RIGHT 0x0080
160 /* Recording enable register. */
161 #define NM_RECORD_ENABLE_REG (NM_RECORD_REG_OFFSET + 0)
162 #define NM_RECORD_ENABLE_FLAG 1
163 #define NM_RECORD_FREERUN 2
165 /* coefficient buffer pointer */
166 #define NM_COEFF_START_OFFSET 0x1c
167 #define NM_COEFF_END_OFFSET 0x20
169 /* DMA buffer offsets */
170 #define NM_RBUFFER_START (NM_RECORD_REG_OFFSET + 0x4)
171 #define NM_RBUFFER_END (NM_RECORD_REG_OFFSET + 0x10)
172 #define NM_RBUFFER_WMARK (NM_RECORD_REG_OFFSET + 0xc)
173 #define NM_RBUFFER_CURRP (NM_RECORD_REG_OFFSET + 0x8)
175 #define NM_PBUFFER_START (NM_PLAYBACK_REG_OFFSET + 0x4)
176 #define NM_PBUFFER_END (NM_PLAYBACK_REG_OFFSET + 0x14)
177 #define NM_PBUFFER_WMARK (NM_PLAYBACK_REG_OFFSET + 0xc)
178 #define NM_PBUFFER_CURRP (NM_PLAYBACK_REG_OFFSET + 0x8)
184 typedef struct snd_nm256 nm256_t;
185 typedef struct snd_nm256_stream nm256_stream_t;
187 struct snd_nm256_stream {
190 snd_pcm_substream_t *substream;
193 u32 buf; /* offset from chip->buffer */
194 int bufsize; /* buffer size in bytes */
195 void __iomem *bufptr; /* mapped pointer */
196 unsigned long bufptr_addr; /* physical address of the mapped pointer */
198 int dma_size; /* buffer size of the substream in bytes */
199 int period_size; /* period size in bytes */
200 int periods; /* # of periods */
201 int shift; /* bit shifts */
202 int cur_period; /* current period # */
210 void __iomem *cport; /* control port */
211 struct resource *res_cport; /* its resource */
212 unsigned long cport_addr; /* physical address */
214 void __iomem *buffer; /* buffer */
215 struct resource *res_buffer; /* its resource */
216 unsigned long buffer_addr; /* buffer phyiscal address */
218 u32 buffer_start; /* start offset from pci resource 0 */
219 u32 buffer_end; /* end offset */
220 u32 buffer_size; /* total buffer size */
222 u32 all_coeff_buf; /* coefficient buffer */
223 u32 coeff_buf[2]; /* coefficient buffer for each stream */
225 unsigned int coeffs_current: 1; /* coeff. table is loaded? */
226 unsigned int use_cache: 1; /* use one big coef. table */
227 unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */
229 int mixer_base; /* register offset of ac97 mixer */
230 int mixer_status_offset; /* offset of mixer status reg. */
231 int mixer_status_mask; /* bit mask to test the mixer status */
234 irqreturn_t (*interrupt)(int, void *, struct pt_regs *);
235 int badintrcount; /* counter to check bogus interrupts */
237 nm256_stream_t streams[2];
251 * include coefficient table
253 #include "nm256_coef.c"
260 #ifndef PCI_VENDOR_ID_NEOMAGIC
261 #define PCI_VENDOR_ID_NEOMEGIC 0x10c8
263 #ifndef PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO
264 #define PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO 0x8005
266 #ifndef PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO
267 #define PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO 0x8006
269 #ifndef PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO
270 #define PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO 0x8016
274 static struct pci_device_id snd_nm256_ids[] = {
275 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
276 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
277 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
281 MODULE_DEVICE_TABLE(pci, snd_nm256_ids);
289 snd_nm256_readb(nm256_t *chip, int offset)
291 return readb(chip->cport + offset);
295 snd_nm256_readw(nm256_t *chip, int offset)
297 return readw(chip->cport + offset);
301 snd_nm256_readl(nm256_t *chip, int offset)
303 return readl(chip->cport + offset);
307 snd_nm256_writeb(nm256_t *chip, int offset, u8 val)
309 writeb(val, chip->cport + offset);
313 snd_nm256_writew(nm256_t *chip, int offset, u16 val)
315 writew(val, chip->cport + offset);
319 snd_nm256_writel(nm256_t *chip, int offset, u32 val)
321 writel(val, chip->cport + offset);
325 snd_nm256_write_buffer(nm256_t *chip, void *src, int offset, int size)
327 offset -= chip->buffer_start;
328 #ifdef SNDRV_CONFIG_DEBUG
329 if (offset < 0 || offset >= chip->buffer_size) {
330 snd_printk("write_buffer invalid offset = %d size = %d\n", offset, size);
334 memcpy_toio(chip->buffer + offset, src, size);
338 * coefficient handlers -- what a magic!
342 snd_nm256_get_start_offset(int which)
346 offset += coefficient_sizes[which];
351 snd_nm256_load_one_coefficient(nm256_t *chip, int stream, u32 port, int which)
353 u32 coeff_buf = chip->coeff_buf[stream];
354 u16 offset = snd_nm256_get_start_offset(which);
355 u16 size = coefficient_sizes[which];
357 snd_nm256_write_buffer(chip, coefficients + offset, coeff_buf, size);
358 snd_nm256_writel(chip, port, coeff_buf);
359 /* ??? Record seems to behave differently than playback. */
360 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
362 snd_nm256_writel(chip, port + 4, coeff_buf + size);
366 snd_nm256_load_coefficient(nm256_t *chip, int stream, int number)
368 /* The enable register for the specified engine. */
369 u32 poffset = (stream == SNDRV_PCM_STREAM_CAPTURE ? NM_RECORD_ENABLE_REG : NM_PLAYBACK_ENABLE_REG);
370 u32 addr = NM_COEFF_START_OFFSET;
372 addr += (stream == SNDRV_PCM_STREAM_CAPTURE ? NM_RECORD_REG_OFFSET : NM_PLAYBACK_REG_OFFSET);
374 if (snd_nm256_readb(chip, poffset) & 1) {
375 snd_printd("NM256: Engine was enabled while loading coefficients!\n");
379 /* The recording engine uses coefficient values 8-15. */
381 if (stream == SNDRV_PCM_STREAM_CAPTURE)
384 if (! chip->use_cache) {
385 snd_nm256_load_one_coefficient(chip, stream, addr, number);
388 if (! chip->coeffs_current) {
389 snd_nm256_write_buffer(chip, coefficients, chip->all_coeff_buf,
390 NM_TOTAL_COEFF_COUNT * 4);
391 chip->coeffs_current = 1;
393 u32 base = chip->all_coeff_buf;
394 u32 offset = snd_nm256_get_start_offset(number);
395 u32 end_offset = offset + coefficient_sizes[number];
396 snd_nm256_writel(chip, addr, base + offset);
397 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
399 snd_nm256_writel(chip, addr + 4, base + end_offset);
404 /* The actual rates supported by the card. */
405 static unsigned int samplerates[8] = {
406 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000,
408 static snd_pcm_hw_constraint_list_t constraints_rates = {
409 .count = ARRAY_SIZE(samplerates),
415 * return the index of the target rate
418 snd_nm256_fixed_rate(unsigned int rate)
421 for (i = 0; i < ARRAY_SIZE(samplerates); i++) {
422 if (rate == samplerates[i])
430 * set sample rate and format
433 snd_nm256_set_format(nm256_t *chip, nm256_stream_t *s, snd_pcm_substream_t *substream)
435 snd_pcm_runtime_t *runtime = substream->runtime;
436 int rate_index = snd_nm256_fixed_rate(runtime->rate);
437 unsigned char ratebits = (rate_index << 4) & NM_RATE_MASK;
440 if (snd_pcm_format_width(runtime->format) == 16) {
441 ratebits |= NM_RATE_BITS_16;
444 if (runtime->channels > 1) {
445 ratebits |= NM_RATE_STEREO;
449 runtime->rate = samplerates[rate_index];
451 switch (substream->stream) {
452 case SNDRV_PCM_STREAM_PLAYBACK:
453 snd_nm256_load_coefficient(chip, 0, rate_index); /* 0 = playback */
454 snd_nm256_writeb(chip,
455 NM_PLAYBACK_REG_OFFSET + NM_RATE_REG_OFFSET,
458 case SNDRV_PCM_STREAM_CAPTURE:
459 snd_nm256_load_coefficient(chip, 1, rate_index); /* 1 = record */
460 snd_nm256_writeb(chip,
461 NM_RECORD_REG_OFFSET + NM_RATE_REG_OFFSET,
471 /* update the watermark (current period) */
472 static void snd_nm256_pcm_mark(nm256_t *chip, nm256_stream_t *s, int reg)
475 s->cur_period %= s->periods;
476 snd_nm256_writel(chip, reg, s->buf + s->cur_period * s->period_size);
479 #define snd_nm256_playback_mark(chip, s) snd_nm256_pcm_mark(chip, s, NM_PBUFFER_WMARK)
480 #define snd_nm256_capture_mark(chip, s) snd_nm256_pcm_mark(chip, s, NM_RBUFFER_WMARK)
483 snd_nm256_playback_start(nm256_t *chip, nm256_stream_t *s, snd_pcm_substream_t *substream)
485 /* program buffer pointers */
486 snd_nm256_writel(chip, NM_PBUFFER_START, s->buf);
487 snd_nm256_writel(chip, NM_PBUFFER_END, s->buf + s->dma_size - (1 << s->shift));
488 snd_nm256_writel(chip, NM_PBUFFER_CURRP, s->buf);
489 snd_nm256_playback_mark(chip, s);
491 /* Enable playback engine and interrupts. */
492 snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG,
493 NM_PLAYBACK_ENABLE_FLAG | NM_PLAYBACK_FREERUN);
494 /* Enable both channels. */
495 snd_nm256_writew(chip, NM_AUDIO_MUTE_REG, 0x0);
499 snd_nm256_capture_start(nm256_t *chip, nm256_stream_t *s, snd_pcm_substream_t *substream)
501 /* program buffer pointers */
502 snd_nm256_writel(chip, NM_RBUFFER_START, s->buf);
503 snd_nm256_writel(chip, NM_RBUFFER_END, s->buf + s->dma_size);
504 snd_nm256_writel(chip, NM_RBUFFER_CURRP, s->buf);
505 snd_nm256_capture_mark(chip, s);
507 /* Enable playback engine and interrupts. */
508 snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG,
509 NM_RECORD_ENABLE_FLAG | NM_RECORD_FREERUN);
512 /* Stop the play engine. */
514 snd_nm256_playback_stop(nm256_t *chip)
516 /* Shut off sound from both channels. */
517 snd_nm256_writew(chip, NM_AUDIO_MUTE_REG,
518 NM_AUDIO_MUTE_LEFT | NM_AUDIO_MUTE_RIGHT);
519 /* Disable play engine. */
520 snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG, 0);
524 snd_nm256_capture_stop(nm256_t *chip)
526 /* Disable recording engine. */
527 snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG, 0);
531 snd_nm256_playback_trigger(snd_pcm_substream_t *substream, int cmd)
533 nm256_t *chip = snd_pcm_substream_chip(substream);
534 nm256_stream_t *s = (nm256_stream_t*)substream->runtime->private_data;
537 snd_assert(s != NULL, return -ENXIO);
539 spin_lock(&chip->reg_lock);
541 case SNDRV_PCM_TRIGGER_START:
542 case SNDRV_PCM_TRIGGER_RESUME:
544 snd_nm256_playback_start(chip, s, substream);
548 case SNDRV_PCM_TRIGGER_STOP:
549 case SNDRV_PCM_TRIGGER_SUSPEND:
551 snd_nm256_playback_stop(chip);
559 spin_unlock(&chip->reg_lock);
564 snd_nm256_capture_trigger(snd_pcm_substream_t *substream, int cmd)
566 nm256_t *chip = snd_pcm_substream_chip(substream);
567 nm256_stream_t *s = (nm256_stream_t*)substream->runtime->private_data;
570 snd_assert(s != NULL, return -ENXIO);
572 spin_lock(&chip->reg_lock);
574 case SNDRV_PCM_TRIGGER_START:
575 case SNDRV_PCM_TRIGGER_RESUME:
577 snd_nm256_capture_start(chip, s, substream);
581 case SNDRV_PCM_TRIGGER_STOP:
582 case SNDRV_PCM_TRIGGER_SUSPEND:
584 snd_nm256_capture_stop(chip);
592 spin_unlock(&chip->reg_lock);
598 * prepare playback/capture channel
600 static int snd_nm256_pcm_prepare(snd_pcm_substream_t *substream)
602 nm256_t *chip = snd_pcm_substream_chip(substream);
603 snd_pcm_runtime_t *runtime = substream->runtime;
604 nm256_stream_t *s = (nm256_stream_t*)runtime->private_data;
606 snd_assert(s, return -ENXIO);
607 s->dma_size = frames_to_bytes(runtime, substream->runtime->buffer_size);
608 s->period_size = frames_to_bytes(runtime, substream->runtime->period_size);
609 s->periods = substream->runtime->periods;
612 spin_lock_irq(&chip->reg_lock);
614 snd_nm256_set_format(chip, s, substream);
615 spin_unlock_irq(&chip->reg_lock);
622 * get the current pointer
624 static snd_pcm_uframes_t
625 snd_nm256_playback_pointer(snd_pcm_substream_t * substream)
627 nm256_t *chip = snd_pcm_substream_chip(substream);
628 nm256_stream_t *s = (nm256_stream_t*)substream->runtime->private_data;
631 snd_assert(s, return 0);
632 curp = snd_nm256_readl(chip, NM_PBUFFER_CURRP) - (unsigned long)s->buf;
634 return bytes_to_frames(substream->runtime, curp);
637 static snd_pcm_uframes_t
638 snd_nm256_capture_pointer(snd_pcm_substream_t * substream)
640 nm256_t *chip = snd_pcm_substream_chip(substream);
641 nm256_stream_t *s = (nm256_stream_t*)substream->runtime->private_data;
644 snd_assert(s != NULL, return 0);
645 curp = snd_nm256_readl(chip, NM_RBUFFER_CURRP) - (unsigned long)s->buf;
647 return bytes_to_frames(substream->runtime, curp);
650 /* Remapped I/O space can be accessible as pointer on i386 */
651 /* This might be changed in the future */
654 * silence / copy for playback
657 snd_nm256_playback_silence(snd_pcm_substream_t *substream,
658 int channel, /* not used (interleaved data) */
659 snd_pcm_uframes_t pos,
660 snd_pcm_uframes_t count)
662 snd_pcm_runtime_t *runtime = substream->runtime;
663 nm256_stream_t *s = (nm256_stream_t*)runtime->private_data;
664 count = frames_to_bytes(runtime, count);
665 pos = frames_to_bytes(runtime, pos);
666 memset_io(s->bufptr + pos, 0, count);
671 snd_nm256_playback_copy(snd_pcm_substream_t *substream,
672 int channel, /* not used (interleaved data) */
673 snd_pcm_uframes_t pos,
675 snd_pcm_uframes_t count)
677 snd_pcm_runtime_t *runtime = substream->runtime;
678 nm256_stream_t *s = (nm256_stream_t*)runtime->private_data;
679 count = frames_to_bytes(runtime, count);
680 pos = frames_to_bytes(runtime, pos);
681 if (copy_from_user_toio(s->bufptr + pos, src, count))
690 snd_nm256_capture_copy(snd_pcm_substream_t *substream,
691 int channel, /* not used (interleaved data) */
692 snd_pcm_uframes_t pos,
694 snd_pcm_uframes_t count)
696 snd_pcm_runtime_t *runtime = substream->runtime;
697 nm256_stream_t *s = (nm256_stream_t*)runtime->private_data;
698 count = frames_to_bytes(runtime, count);
699 pos = frames_to_bytes(runtime, pos);
700 if (copy_to_user_fromio(dst, s->bufptr + pos, count))
705 #endif /* !__i386__ */
709 * update playback/capture watermarks
714 snd_nm256_playback_update(nm256_t *chip)
718 s = &chip->streams[SNDRV_PCM_STREAM_PLAYBACK];
719 if (s->running && s->substream) {
720 spin_unlock(&chip->reg_lock);
721 snd_pcm_period_elapsed(s->substream);
722 spin_lock(&chip->reg_lock);
723 snd_nm256_playback_mark(chip, s);
729 snd_nm256_capture_update(nm256_t *chip)
733 s = &chip->streams[SNDRV_PCM_STREAM_CAPTURE];
734 if (s->running && s->substream) {
735 spin_unlock(&chip->reg_lock);
736 snd_pcm_period_elapsed(s->substream);
737 spin_lock(&chip->reg_lock);
738 snd_nm256_capture_mark(chip, s);
745 static snd_pcm_hardware_t snd_nm256_playback =
747 .info = SNDRV_PCM_INFO_MMAP_IOMEM |SNDRV_PCM_INFO_MMAP_VALID |
748 SNDRV_PCM_INFO_INTERLEAVED |
749 /*SNDRV_PCM_INFO_PAUSE |*/
750 SNDRV_PCM_INFO_RESUME,
751 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
752 .rates = SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000,
759 .buffer_bytes_max = 128 * 1024,
760 .period_bytes_min = 256,
761 .period_bytes_max = 128 * 1024,
764 static snd_pcm_hardware_t snd_nm256_capture =
766 .info = SNDRV_PCM_INFO_MMAP_IOMEM | SNDRV_PCM_INFO_MMAP_VALID |
767 SNDRV_PCM_INFO_INTERLEAVED |
768 /*SNDRV_PCM_INFO_PAUSE |*/
769 SNDRV_PCM_INFO_RESUME,
770 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
771 .rates = SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000,
778 .buffer_bytes_max = 128 * 1024,
779 .period_bytes_min = 256,
780 .period_bytes_max = 128 * 1024,
784 /* set dma transfer size */
785 static int snd_nm256_pcm_hw_params(snd_pcm_substream_t *substream, snd_pcm_hw_params_t *hw_params)
787 /* area and addr are already set and unchanged */
788 substream->runtime->dma_bytes = params_buffer_bytes(hw_params);
795 static void snd_nm256_setup_stream(nm256_t *chip, nm256_stream_t *s,
796 snd_pcm_substream_t *substream,
797 snd_pcm_hardware_t *hw_ptr)
799 snd_pcm_runtime_t *runtime = substream->runtime;
802 runtime->hw = *hw_ptr;
803 runtime->hw.buffer_bytes_max = s->bufsize;
804 runtime->hw.period_bytes_max = s->bufsize / 2;
805 runtime->dma_area = (void*) s->bufptr;
806 runtime->dma_addr = s->bufptr_addr;
807 runtime->dma_bytes = s->bufsize;
808 runtime->private_data = s;
809 s->substream = substream;
811 snd_pcm_set_sync(substream);
812 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
817 snd_nm256_playback_open(snd_pcm_substream_t *substream)
819 nm256_t *chip = snd_pcm_substream_chip(substream);
821 snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK],
822 substream, &snd_nm256_playback);
827 snd_nm256_capture_open(snd_pcm_substream_t *substream)
829 nm256_t *chip = snd_pcm_substream_chip(substream);
831 snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_CAPTURE],
832 substream, &snd_nm256_capture);
837 * close - we don't have to do special..
840 snd_nm256_playback_close(snd_pcm_substream_t *substream)
847 snd_nm256_capture_close(snd_pcm_substream_t *substream)
853 * create a pcm instance
855 static snd_pcm_ops_t snd_nm256_playback_ops = {
856 .open = snd_nm256_playback_open,
857 .close = snd_nm256_playback_close,
858 .ioctl = snd_pcm_lib_ioctl,
859 .hw_params = snd_nm256_pcm_hw_params,
860 .prepare = snd_nm256_pcm_prepare,
861 .trigger = snd_nm256_playback_trigger,
862 .pointer = snd_nm256_playback_pointer,
864 .copy = snd_nm256_playback_copy,
865 .silence = snd_nm256_playback_silence,
867 .mmap = snd_pcm_lib_mmap_iomem,
870 static snd_pcm_ops_t snd_nm256_capture_ops = {
871 .open = snd_nm256_capture_open,
872 .close = snd_nm256_capture_close,
873 .ioctl = snd_pcm_lib_ioctl,
874 .hw_params = snd_nm256_pcm_hw_params,
875 .prepare = snd_nm256_pcm_prepare,
876 .trigger = snd_nm256_capture_trigger,
877 .pointer = snd_nm256_capture_pointer,
879 .copy = snd_nm256_capture_copy,
881 .mmap = snd_pcm_lib_mmap_iomem,
885 snd_nm256_pcm(nm256_t *chip, int device)
890 for (i = 0; i < 2; i++) {
891 nm256_stream_t *s = &chip->streams[i];
892 s->bufptr = chip->buffer + (s->buf - chip->buffer_start);
893 s->bufptr_addr = chip->buffer_addr + (s->buf - chip->buffer_start);
896 err = snd_pcm_new(chip->card, chip->card->driver, device,
901 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_nm256_playback_ops);
902 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_nm256_capture_ops);
904 pcm->private_data = chip;
913 * Initialize the hardware.
916 snd_nm256_init_chip(nm256_t *chip)
918 spin_lock_irq(&chip->reg_lock);
919 /* Reset everything. */
920 snd_nm256_writeb(chip, 0x0, 0x11);
921 snd_nm256_writew(chip, 0x214, 0);
923 //snd_nm256_playback_stop(chip);
924 //snd_nm256_capture_stop(chip);
925 spin_unlock_irq(&chip->reg_lock);
930 snd_nm256_intr_check(nm256_t *chip)
932 if (chip->badintrcount++ > 1000) {
934 * I'm not sure if the best thing is to stop the card from
935 * playing or just release the interrupt (after all, we're in
936 * a bad situation, so doing fancy stuff may not be such a good
939 * I worry about the card engine continuing to play noise
940 * over and over, however--that could become a very
941 * obnoxious problem. And we know that when this usually
942 * happens things are fairly safe, it just means the user's
943 * inserted a PCMCIA card and someone's spamming us with IRQ 9s.
945 if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running)
946 snd_nm256_playback_stop(chip);
947 if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running)
948 snd_nm256_capture_stop(chip);
949 chip->badintrcount = 0;
954 * Handle a potential interrupt for the device referred to by DEV_ID.
956 * I don't like the cut-n-paste job here either between the two routines,
957 * but there are sufficient differences between the two interrupt handlers
958 * that parameterizing it isn't all that great either. (Could use a macro,
959 * I suppose...yucky bleah.)
963 snd_nm256_interrupt(int irq, void *dev_id, struct pt_regs *dummy)
965 nm256_t *chip = dev_id;
969 status = snd_nm256_readw(chip, NM_INT_REG);
973 snd_nm256_intr_check(chip);
977 chip->badintrcount = 0;
979 /* Rather boring; check for individual interrupts and process them. */
981 spin_lock(&chip->reg_lock);
982 if (status & NM_PLAYBACK_INT) {
983 status &= ~NM_PLAYBACK_INT;
984 NM_ACK_INT(chip, NM_PLAYBACK_INT);
985 snd_nm256_playback_update(chip);
988 if (status & NM_RECORD_INT) {
989 status &= ~NM_RECORD_INT;
990 NM_ACK_INT(chip, NM_RECORD_INT);
991 snd_nm256_capture_update(chip);
994 if (status & NM_MISC_INT_1) {
995 status &= ~NM_MISC_INT_1;
996 NM_ACK_INT(chip, NM_MISC_INT_1);
997 snd_printd("NM256: Got misc interrupt #1\n");
998 snd_nm256_writew(chip, NM_INT_REG, 0x8000);
999 cbyte = snd_nm256_readb(chip, 0x400);
1000 snd_nm256_writeb(chip, 0x400, cbyte | 2);
1003 if (status & NM_MISC_INT_2) {
1004 status &= ~NM_MISC_INT_2;
1005 NM_ACK_INT(chip, NM_MISC_INT_2);
1006 snd_printd("NM256: Got misc interrupt #2\n");
1007 cbyte = snd_nm256_readb(chip, 0x400);
1008 snd_nm256_writeb(chip, 0x400, cbyte & ~2);
1011 /* Unknown interrupt. */
1013 snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n",
1016 NM_ACK_INT(chip, status);
1019 spin_unlock(&chip->reg_lock);
1024 * Handle a potential interrupt for the device referred to by DEV_ID.
1025 * This handler is for the 256ZX, and is very similar to the non-ZX
1030 snd_nm256_interrupt_zx(int irq, void *dev_id, struct pt_regs *dummy)
1032 nm256_t *chip = dev_id;
1036 status = snd_nm256_readl(chip, NM_INT_REG);
1040 snd_nm256_intr_check(chip);
1044 chip->badintrcount = 0;
1046 /* Rather boring; check for individual interrupts and process them. */
1048 spin_lock(&chip->reg_lock);
1049 if (status & NM2_PLAYBACK_INT) {
1050 status &= ~NM2_PLAYBACK_INT;
1051 NM2_ACK_INT(chip, NM2_PLAYBACK_INT);
1052 snd_nm256_playback_update(chip);
1055 if (status & NM2_RECORD_INT) {
1056 status &= ~NM2_RECORD_INT;
1057 NM2_ACK_INT(chip, NM2_RECORD_INT);
1058 snd_nm256_capture_update(chip);
1061 if (status & NM2_MISC_INT_1) {
1062 status &= ~NM2_MISC_INT_1;
1063 NM2_ACK_INT(chip, NM2_MISC_INT_1);
1064 snd_printd("NM256: Got misc interrupt #1\n");
1065 cbyte = snd_nm256_readb(chip, 0x400);
1066 snd_nm256_writeb(chip, 0x400, cbyte | 2);
1069 if (status & NM2_MISC_INT_2) {
1070 status &= ~NM2_MISC_INT_2;
1071 NM2_ACK_INT(chip, NM2_MISC_INT_2);
1072 snd_printd("NM256: Got misc interrupt #2\n");
1073 cbyte = snd_nm256_readb(chip, 0x400);
1074 snd_nm256_writeb(chip, 0x400, cbyte & ~2);
1077 /* Unknown interrupt. */
1079 snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n",
1082 NM2_ACK_INT(chip, status);
1085 spin_unlock(&chip->reg_lock);
1094 * Waits for the mixer to become ready to be written; returns a zero value
1098 snd_nm256_ac97_ready(nm256_t *chip)
1104 testaddr = chip->mixer_status_offset;
1105 testb = chip->mixer_status_mask;
1108 * Loop around waiting for the mixer to become ready.
1110 while (timeout-- > 0) {
1111 if ((snd_nm256_readw(chip, testaddr) & testb) == 0)
1120 static unsigned short
1121 snd_nm256_ac97_read(ac97_t *ac97, unsigned short reg)
1123 nm256_t *chip = ac97->private_data;
1129 if (! snd_nm256_ac97_ready(chip))
1131 res = snd_nm256_readw(chip, chip->mixer_base + reg);
1132 /* Magic delay. Bleah yucky. */
1140 snd_nm256_ac97_write(ac97_t *ac97,
1141 unsigned short reg, unsigned short val)
1143 nm256_t *chip = ac97->private_data;
1147 base = chip->mixer_base;
1149 snd_nm256_ac97_ready(chip);
1151 /* Wait for the write to take, too. */
1152 while (tries-- > 0) {
1153 snd_nm256_writew(chip, base + reg, val);
1154 msleep(1); /* a little delay here seems better.. */
1155 if (snd_nm256_ac97_ready(chip))
1158 snd_printd("nm256: ac97 codec not ready..\n");
1161 /* initialize the ac97 into a known state */
1163 snd_nm256_ac97_reset(ac97_t *ac97)
1165 nm256_t *chip = ac97->private_data;
1167 /* Reset the mixer. 'Tis magic! */
1168 snd_nm256_writeb(chip, 0x6c0, 1);
1169 if (! chip->reset_workaround) {
1170 /* Dell latitude LS will lock up by this */
1171 snd_nm256_writeb(chip, 0x6cc, 0x87);
1173 snd_nm256_writeb(chip, 0x6cc, 0x80);
1174 snd_nm256_writeb(chip, 0x6cc, 0x0);
1177 /* create an ac97 mixer interface */
1178 static int __devinit
1179 snd_nm256_mixer(nm256_t *chip)
1182 ac97_template_t ac97;
1184 static ac97_bus_ops_t ops = {
1185 .reset = snd_nm256_ac97_reset,
1186 .write = snd_nm256_ac97_write,
1187 .read = snd_nm256_ac97_read,
1189 /* looks like nm256 hangs up when unexpected registers are touched... */
1190 static int mixer_regs[] = {
1191 AC97_MASTER, AC97_HEADPHONE, AC97_MASTER_MONO,
1192 AC97_PC_BEEP, AC97_PHONE, AC97_MIC, AC97_LINE, AC97_CD,
1193 AC97_VIDEO, AC97_AUX, AC97_PCM, AC97_REC_SEL,
1194 AC97_REC_GAIN, AC97_GENERAL_PURPOSE, AC97_3D_CONTROL,
1196 AC97_VENDOR_ID1, AC97_VENDOR_ID2,
1200 if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
1203 memset(&ac97, 0, sizeof(ac97));
1204 ac97.scaps = AC97_SCAP_AUDIO; /* we support audio! */
1205 ac97.limited_regs = 1;
1206 for (i = 0; mixer_regs[i] >= 0; i++)
1207 set_bit(mixer_regs[i], ac97.reg_accessed);
1208 ac97.private_data = chip;
1209 err = snd_ac97_mixer(pbus, &ac97, &chip->ac97);
1212 if (! (chip->ac97->id & (0xf0000000))) {
1213 /* looks like an invalid id */
1214 sprintf(chip->card->mixername, "%s AC97", chip->card->driver);
1220 * See if the signature left by the NM256 BIOS is intact; if so, we use
1221 * the associated address as the end of our audio buffer in the video
1225 static int __devinit
1226 snd_nm256_peek_for_sig(nm256_t *chip)
1228 /* The signature is located 1K below the end of video RAM. */
1230 /* Default buffer end is 5120 bytes below the top of RAM. */
1231 unsigned long pointer_found = chip->buffer_end - 0x1400;
1234 temp = ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16);
1236 snd_printk("Unable to scan for card signature in video RAM\n");
1241 if ((sig & NM_SIG_MASK) == NM_SIGNATURE) {
1242 u32 pointer = readl(temp + 4);
1245 * If it's obviously invalid, don't use it
1247 if (pointer == 0xffffffff ||
1248 pointer < chip->buffer_size ||
1249 pointer > chip->buffer_end) {
1250 snd_printk("invalid signature found: 0x%x\n", pointer);
1254 pointer_found = pointer;
1255 printk(KERN_INFO "nm256: found card signature in video RAM: 0x%x\n", pointer);
1260 chip->buffer_end = pointer_found;
1267 * APM event handler, so the card is properly reinitialized after a power
1270 static int nm256_suspend(snd_card_t *card, pm_message_t state)
1272 nm256_t *chip = card->pm_private_data;
1274 snd_pcm_suspend_all(chip->pcm);
1275 snd_ac97_suspend(chip->ac97);
1276 chip->coeffs_current = 0;
1277 pci_disable_device(chip->pci);
1281 static int nm256_resume(snd_card_t *card)
1283 nm256_t *chip = card->pm_private_data;
1285 /* Perform a full reset on the hardware */
1286 pci_enable_device(chip->pci);
1287 snd_nm256_init_chip(chip);
1290 snd_ac97_resume(chip->ac97);
1294 #endif /* CONFIG_PM */
1296 static int snd_nm256_free(nm256_t *chip)
1298 if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running)
1299 snd_nm256_playback_stop(chip);
1300 if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running)
1301 snd_nm256_capture_stop(chip);
1304 synchronize_irq(chip->irq);
1307 iounmap(chip->cport);
1309 iounmap(chip->buffer);
1310 if (chip->res_cport) {
1311 release_resource(chip->res_cport);
1312 kfree_nocheck(chip->res_cport);
1314 if (chip->res_buffer) {
1315 release_resource(chip->res_buffer);
1316 kfree_nocheck(chip->res_buffer);
1319 free_irq(chip->irq, (void*)chip);
1321 pci_disable_device(chip->pci);
1326 static int snd_nm256_dev_free(snd_device_t *device)
1328 nm256_t *chip = device->device_data;
1329 return snd_nm256_free(chip);
1332 static int __devinit
1333 snd_nm256_create(snd_card_t *card, struct pci_dev *pci,
1334 int play_bufsize, int capt_bufsize,
1342 static snd_device_ops_t ops = {
1343 .dev_free = snd_nm256_dev_free,
1349 if ((err = pci_enable_device(pci)) < 0)
1352 chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
1354 pci_disable_device(pci);
1360 chip->use_cache = usecache;
1361 spin_lock_init(&chip->reg_lock);
1364 chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize = play_bufsize;
1365 chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize = capt_bufsize;
1368 * The NM256 has two memory ports. The first port is nothing
1369 * more than a chunk of video RAM, which is used as the I/O ring
1370 * buffer. The second port has the actual juicy stuff (like the
1371 * mixer and the playback engine control registers).
1374 chip->buffer_addr = pci_resource_start(pci, 0);
1375 chip->cport_addr = pci_resource_start(pci, 1);
1377 /* Init the memory port info. */
1378 /* remap control port (#2) */
1379 chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE,
1381 if (chip->res_cport == NULL) {
1382 snd_printk("memory region 0x%lx (size 0x%x) busy\n",
1383 chip->cport_addr, NM_PORT2_SIZE);
1387 chip->cport = ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE);
1388 if (chip->cport == NULL) {
1389 snd_printk("unable to map control port %lx\n", chip->cport_addr);
1394 if (!strcmp(card->driver, "NM256AV")) {
1395 /* Ok, try to see if this is a non-AC97 version of the hardware. */
1396 pval = snd_nm256_readw(chip, NM_MIXER_PRESENCE);
1397 if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {
1399 printk(KERN_ERR "nm256: no ac97 is found!\n");
1400 printk(KERN_ERR " force the driver to load by passing in the module parameter\n");
1401 printk(KERN_ERR " force_ac97=1\n");
1402 printk(KERN_ERR " or try sb16 or cs423x drivers instead.\n");
1407 chip->buffer_end = 2560 * 1024;
1408 chip->interrupt = snd_nm256_interrupt;
1409 chip->mixer_status_offset = NM_MIXER_STATUS_OFFSET;
1410 chip->mixer_status_mask = NM_MIXER_READY_MASK;
1412 /* Not sure if there is any relevant detect for the ZX or not. */
1413 if (snd_nm256_readb(chip, 0xa0b) != 0)
1414 chip->buffer_end = 6144 * 1024;
1416 chip->buffer_end = 4096 * 1024;
1418 chip->interrupt = snd_nm256_interrupt_zx;
1419 chip->mixer_status_offset = NM2_MIXER_STATUS_OFFSET;
1420 chip->mixer_status_mask = NM2_MIXER_READY_MASK;
1423 chip->buffer_size = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize + chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize;
1424 if (chip->use_cache)
1425 chip->buffer_size += NM_TOTAL_COEFF_COUNT * 4;
1427 chip->buffer_size += NM_MAX_PLAYBACK_COEF_SIZE + NM_MAX_RECORD_COEF_SIZE;
1429 if (buffertop >= chip->buffer_size && buffertop < chip->buffer_end)
1430 chip->buffer_end = buffertop;
1432 /* get buffer end pointer from signature */
1433 if ((err = snd_nm256_peek_for_sig(chip)) < 0)
1437 chip->buffer_start = chip->buffer_end - chip->buffer_size;
1438 chip->buffer_addr += chip->buffer_start;
1440 printk(KERN_INFO "nm256: Mapping port 1 from 0x%x - 0x%x\n",
1441 chip->buffer_start, chip->buffer_end);
1443 chip->res_buffer = request_mem_region(chip->buffer_addr,
1446 if (chip->res_buffer == NULL) {
1447 snd_printk("nm256: buffer 0x%lx (size 0x%x) busy\n",
1448 chip->buffer_addr, chip->buffer_size);
1452 chip->buffer = ioremap_nocache(chip->buffer_addr, chip->buffer_size);
1453 if (chip->buffer == NULL) {
1455 snd_printk("unable to map ring buffer at %lx\n", chip->buffer_addr);
1460 addr = chip->buffer_start;
1461 chip->streams[SNDRV_PCM_STREAM_PLAYBACK].buf = addr;
1462 addr += chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize;
1463 chip->streams[SNDRV_PCM_STREAM_CAPTURE].buf = addr;
1464 addr += chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize;
1465 if (chip->use_cache) {
1466 chip->all_coeff_buf = addr;
1468 chip->coeff_buf[SNDRV_PCM_STREAM_PLAYBACK] = addr;
1469 addr += NM_MAX_PLAYBACK_COEF_SIZE;
1470 chip->coeff_buf[SNDRV_PCM_STREAM_CAPTURE] = addr;
1473 /* acquire interrupt */
1474 if (request_irq(pci->irq, chip->interrupt, SA_INTERRUPT|SA_SHIRQ,
1475 card->driver, (void*)chip)) {
1477 snd_printk("unable to grab IRQ %d\n", pci->irq);
1480 chip->irq = pci->irq;
1482 /* Fixed setting. */
1483 chip->mixer_base = NM_MIXER_OFFSET;
1485 chip->coeffs_current = 0;
1487 snd_nm256_init_chip(chip);
1489 // pci_set_master(pci); /* needed? */
1491 snd_card_set_pm_callback(card, nm256_suspend, nm256_resume, chip);
1493 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0)
1496 snd_card_set_dev(card, &pci->dev);
1502 snd_nm256_free(chip);
1507 struct nm256_quirk {
1508 unsigned short vendor;
1509 unsigned short device;
1513 enum { NM_BLACKLISTED, NM_RESET_WORKAROUND };
1515 static struct nm256_quirk nm256_quirks[] __devinitdata = {
1516 /* HP omnibook 4150 has cs4232 codec internally */
1517 { .vendor = 0x103c, .device = 0x0007, .type = NM_BLACKLISTED },
1519 { .vendor = 0x104d, .device = 0x8041, .type = NM_RESET_WORKAROUND },
1520 /* Dell Latitude LS */
1521 { .vendor = 0x1028, .device = 0x0080, .type = NM_RESET_WORKAROUND },
1522 { } /* terminator */
1526 static int __devinit snd_nm256_probe(struct pci_dev *pci,
1527 const struct pci_device_id *pci_id)
1533 unsigned int xbuffer_top;
1534 struct nm256_quirk *q;
1535 u16 subsystem_vendor, subsystem_device;
1537 if (dev >= SNDRV_CARDS)
1544 pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
1545 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);
1547 for (q = nm256_quirks; q->vendor; q++) {
1548 if (q->vendor == subsystem_vendor && q->device == subsystem_device) {
1550 case NM_BLACKLISTED:
1551 printk(KERN_INFO "nm256: The device is blacklisted. Loading stopped\n");
1553 case NM_RESET_WORKAROUND:
1554 reset_workaround[dev] = 1;
1560 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1564 switch (pci->device) {
1565 case PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO:
1566 strcpy(card->driver, "NM256AV");
1568 case PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO:
1569 strcpy(card->driver, "NM256ZX");
1571 case PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO:
1572 strcpy(card->driver, "NM256XL+");
1575 snd_printk("invalid device id 0x%x\n", pci->device);
1576 snd_card_free(card);
1581 xbuffer_top = 0x25a800; /* this avoids conflicts with XFree86 server */
1583 xbuffer_top = buffer_top[dev];
1585 if (playback_bufsize[dev] < 4)
1586 playback_bufsize[dev] = 4;
1587 if (playback_bufsize[dev] > 128)
1588 playback_bufsize[dev] = 128;
1589 if (capture_bufsize[dev] < 4)
1590 capture_bufsize[dev] = 4;
1591 if (capture_bufsize[dev] > 128)
1592 capture_bufsize[dev] = 128;
1593 if ((err = snd_nm256_create(card, pci,
1594 playback_bufsize[dev] * 1024, /* in bytes */
1595 capture_bufsize[dev] * 1024, /* in bytes */
1600 snd_card_free(card);
1604 if (reset_workaround[dev]) {
1605 snd_printdd(KERN_INFO "nm256: reset_workaround activated\n");
1606 chip->reset_workaround = 1;
1609 if ((err = snd_nm256_pcm(chip, 0)) < 0 ||
1610 (err = snd_nm256_mixer(chip)) < 0) {
1611 snd_card_free(card);
1615 sprintf(card->shortname, "NeoMagic %s", card->driver);
1616 sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %d",
1618 chip->buffer_addr, chip->cport_addr, chip->irq);
1620 if ((err = snd_card_register(card)) < 0) {
1621 snd_card_free(card);
1625 pci_set_drvdata(pci, card);
1630 static void __devexit snd_nm256_remove(struct pci_dev *pci)
1632 snd_card_free(pci_get_drvdata(pci));
1633 pci_set_drvdata(pci, NULL);
1637 static struct pci_driver driver = {
1638 .name = "NeoMagic 256",
1639 .id_table = snd_nm256_ids,
1640 .probe = snd_nm256_probe,
1641 .remove = __devexit_p(snd_nm256_remove),
1642 SND_PCI_PM_CALLBACKS
1646 static int __init alsa_card_nm256_init(void)
1648 return pci_register_driver(&driver);
1651 static void __exit alsa_card_nm256_exit(void)
1653 pci_unregister_driver(&driver);
1656 module_init(alsa_card_nm256_init)
1657 module_exit(alsa_card_nm256_exit)