Lines Matching +full:chip +full:- +full:to +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * The original author of OSS nm256 driver wishes to remain anonymous,
8 * so I just put my acknoledgment to him/her here.
60 MODULE_PARM_DESC(force_ac97, "Force to use AC97 codec for " CARD_NAME " soundcard.");
104 #define NM_ACK_INT(chip, X) snd_nm256_writew(chip, NM_INT_REG, (X) << 1) argument
121 #define NM2_ACK_INT(chip, X) snd_nm256_writel(chip, NM_INT_REG, (X)) argument
173 struct nm256 *chip; member
178 u32 buf; /* offset from chip->buffer */
210 unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */
211 …unsigned int reset_workaround_2: 1; /* Extended workaround for some other laptops to avoid freeze …
216 int mixer_status_mask; /* bit mask to test the mixer status */
221 int badintrcount; /* counter to check bogus interrupts */
262 snd_nm256_readb(struct nm256 *chip, int offset) in snd_nm256_readb() argument
264 return readb(chip->cport + offset); in snd_nm256_readb()
268 snd_nm256_readw(struct nm256 *chip, int offset) in snd_nm256_readw() argument
270 return readw(chip->cport + offset); in snd_nm256_readw()
274 snd_nm256_readl(struct nm256 *chip, int offset) in snd_nm256_readl() argument
276 return readl(chip->cport + offset); in snd_nm256_readl()
280 snd_nm256_writeb(struct nm256 *chip, int offset, u8 val) in snd_nm256_writeb() argument
282 writeb(val, chip->cport + offset); in snd_nm256_writeb()
286 snd_nm256_writew(struct nm256 *chip, int offset, u16 val) in snd_nm256_writew() argument
288 writew(val, chip->cport + offset); in snd_nm256_writew()
292 snd_nm256_writel(struct nm256 *chip, int offset, u32 val) in snd_nm256_writel() argument
294 writel(val, chip->cport + offset); in snd_nm256_writel()
298 snd_nm256_write_buffer(struct nm256 *chip, const void *src, int offset, int size) in snd_nm256_write_buffer() argument
300 offset -= chip->buffer_start; in snd_nm256_write_buffer()
302 if (offset < 0 || offset >= chip->buffer_size) { in snd_nm256_write_buffer()
303 dev_err(chip->card->dev, in snd_nm256_write_buffer()
309 memcpy_toio(chip->buffer + offset, src, size); in snd_nm256_write_buffer()
313 * coefficient handlers -- what a magic!
320 while (which-- > 0) in snd_nm256_get_start_offset()
326 snd_nm256_load_one_coefficient(struct nm256 *chip, int stream, u32 port, int which) in snd_nm256_load_one_coefficient() argument
328 u32 coeff_buf = chip->coeff_buf[stream]; in snd_nm256_load_one_coefficient()
332 snd_nm256_write_buffer(chip, coefficients + offset, coeff_buf, size); in snd_nm256_load_one_coefficient()
333 snd_nm256_writel(chip, port, coeff_buf); in snd_nm256_load_one_coefficient()
334 /* ??? Record seems to behave differently than playback. */ in snd_nm256_load_one_coefficient()
336 size--; in snd_nm256_load_one_coefficient()
337 snd_nm256_writel(chip, port + 4, coeff_buf + size); in snd_nm256_load_one_coefficient()
341 snd_nm256_load_coefficient(struct nm256 *chip, int stream, int number) in snd_nm256_load_coefficient() argument
351 if (snd_nm256_readb(chip, poffset) & 1) { in snd_nm256_load_coefficient()
352 dev_dbg(chip->card->dev, in snd_nm256_load_coefficient()
357 /* The recording engine uses coefficient values 8-15. */ in snd_nm256_load_coefficient()
362 if (! chip->use_cache) { in snd_nm256_load_coefficient()
363 snd_nm256_load_one_coefficient(chip, stream, addr, number); in snd_nm256_load_coefficient()
366 if (! chip->coeffs_current) { in snd_nm256_load_coefficient()
367 snd_nm256_write_buffer(chip, coefficients, chip->all_coeff_buf, in snd_nm256_load_coefficient()
369 chip->coeffs_current = 1; in snd_nm256_load_coefficient()
371 u32 base = chip->all_coeff_buf; in snd_nm256_load_coefficient()
374 snd_nm256_writel(chip, addr, base + offset); in snd_nm256_load_coefficient()
376 end_offset--; in snd_nm256_load_coefficient()
377 snd_nm256_writel(chip, addr + 4, base + end_offset); in snd_nm256_load_coefficient()
411 snd_nm256_set_format(struct nm256 *chip, struct nm256_stream *s, in snd_nm256_set_format() argument
414 struct snd_pcm_runtime *runtime = substream->runtime; in snd_nm256_set_format()
415 int rate_index = snd_nm256_fixed_rate(runtime->rate); in snd_nm256_set_format()
418 s->shift = 0; in snd_nm256_set_format()
419 if (snd_pcm_format_width(runtime->format) == 16) { in snd_nm256_set_format()
421 s->shift++; in snd_nm256_set_format()
423 if (runtime->channels > 1) { in snd_nm256_set_format()
425 s->shift++; in snd_nm256_set_format()
428 runtime->rate = samplerates[rate_index]; in snd_nm256_set_format()
430 switch (substream->stream) { in snd_nm256_set_format()
432 snd_nm256_load_coefficient(chip, 0, rate_index); /* 0 = playback */ in snd_nm256_set_format()
433 snd_nm256_writeb(chip, in snd_nm256_set_format()
438 snd_nm256_load_coefficient(chip, 1, rate_index); /* 1 = record */ in snd_nm256_set_format()
439 snd_nm256_writeb(chip, in snd_nm256_set_format()
447 static int snd_nm256_acquire_irq(struct nm256 *chip) in snd_nm256_acquire_irq() argument
449 mutex_lock(&chip->irq_mutex); in snd_nm256_acquire_irq()
450 if (chip->irq < 0) { in snd_nm256_acquire_irq()
451 if (request_irq(chip->pci->irq, chip->interrupt, IRQF_SHARED, in snd_nm256_acquire_irq()
452 KBUILD_MODNAME, chip)) { in snd_nm256_acquire_irq()
453 dev_err(chip->card->dev, in snd_nm256_acquire_irq()
454 "unable to grab IRQ %d\n", chip->pci->irq); in snd_nm256_acquire_irq()
455 mutex_unlock(&chip->irq_mutex); in snd_nm256_acquire_irq()
456 return -EBUSY; in snd_nm256_acquire_irq()
458 chip->irq = chip->pci->irq; in snd_nm256_acquire_irq()
459 chip->card->sync_irq = chip->irq; in snd_nm256_acquire_irq()
461 chip->irq_acks++; in snd_nm256_acquire_irq()
462 mutex_unlock(&chip->irq_mutex); in snd_nm256_acquire_irq()
467 static void snd_nm256_release_irq(struct nm256 *chip) in snd_nm256_release_irq() argument
469 mutex_lock(&chip->irq_mutex); in snd_nm256_release_irq()
470 if (chip->irq_acks > 0) in snd_nm256_release_irq()
471 chip->irq_acks--; in snd_nm256_release_irq()
472 if (chip->irq_acks == 0 && chip->irq >= 0) { in snd_nm256_release_irq()
473 free_irq(chip->irq, chip); in snd_nm256_release_irq()
474 chip->irq = -1; in snd_nm256_release_irq()
475 chip->card->sync_irq = -1; in snd_nm256_release_irq()
477 mutex_unlock(&chip->irq_mutex); in snd_nm256_release_irq()
485 static void snd_nm256_pcm_mark(struct nm256 *chip, struct nm256_stream *s, int reg) in snd_nm256_pcm_mark() argument
487 s->cur_period++; in snd_nm256_pcm_mark()
488 s->cur_period %= s->periods; in snd_nm256_pcm_mark()
489 snd_nm256_writel(chip, reg, s->buf + s->cur_period * s->period_size); in snd_nm256_pcm_mark()
492 #define snd_nm256_playback_mark(chip, s) snd_nm256_pcm_mark(chip, s, NM_PBUFFER_WMARK) argument
493 #define snd_nm256_capture_mark(chip, s) snd_nm256_pcm_mark(chip, s, NM_RBUFFER_WMARK) argument
496 snd_nm256_playback_start(struct nm256 *chip, struct nm256_stream *s, in snd_nm256_playback_start() argument
500 snd_nm256_writel(chip, NM_PBUFFER_START, s->buf); in snd_nm256_playback_start()
501 snd_nm256_writel(chip, NM_PBUFFER_END, s->buf + s->dma_size - (1 << s->shift)); in snd_nm256_playback_start()
502 snd_nm256_writel(chip, NM_PBUFFER_CURRP, s->buf); in snd_nm256_playback_start()
503 snd_nm256_playback_mark(chip, s); in snd_nm256_playback_start()
506 snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG, in snd_nm256_playback_start()
509 snd_nm256_writew(chip, NM_AUDIO_MUTE_REG, 0x0); in snd_nm256_playback_start()
513 snd_nm256_capture_start(struct nm256 *chip, struct nm256_stream *s, in snd_nm256_capture_start() argument
517 snd_nm256_writel(chip, NM_RBUFFER_START, s->buf); in snd_nm256_capture_start()
518 snd_nm256_writel(chip, NM_RBUFFER_END, s->buf + s->dma_size); in snd_nm256_capture_start()
519 snd_nm256_writel(chip, NM_RBUFFER_CURRP, s->buf); in snd_nm256_capture_start()
520 snd_nm256_capture_mark(chip, s); in snd_nm256_capture_start()
523 snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG, in snd_nm256_capture_start()
529 snd_nm256_playback_stop(struct nm256 *chip) in snd_nm256_playback_stop() argument
532 snd_nm256_writew(chip, NM_AUDIO_MUTE_REG, in snd_nm256_playback_stop()
535 snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG, 0); in snd_nm256_playback_stop()
539 snd_nm256_capture_stop(struct nm256 *chip) in snd_nm256_capture_stop() argument
542 snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG, 0); in snd_nm256_capture_stop()
548 struct nm256 *chip = snd_pcm_substream_chip(substream); in snd_nm256_playback_trigger() local
549 struct nm256_stream *s = substream->runtime->private_data; in snd_nm256_playback_trigger()
553 return -ENXIO; in snd_nm256_playback_trigger()
555 spin_lock(&chip->reg_lock); in snd_nm256_playback_trigger()
558 s->suspended = 0; in snd_nm256_playback_trigger()
561 if (! s->running) { in snd_nm256_playback_trigger()
562 snd_nm256_playback_start(chip, s, substream); in snd_nm256_playback_trigger()
563 s->running = 1; in snd_nm256_playback_trigger()
567 s->suspended = 1; in snd_nm256_playback_trigger()
570 if (s->running) { in snd_nm256_playback_trigger()
571 snd_nm256_playback_stop(chip); in snd_nm256_playback_trigger()
572 s->running = 0; in snd_nm256_playback_trigger()
576 err = -EINVAL; in snd_nm256_playback_trigger()
579 spin_unlock(&chip->reg_lock); in snd_nm256_playback_trigger()
586 struct nm256 *chip = snd_pcm_substream_chip(substream); in snd_nm256_capture_trigger() local
587 struct nm256_stream *s = substream->runtime->private_data; in snd_nm256_capture_trigger()
591 return -ENXIO; in snd_nm256_capture_trigger()
593 spin_lock(&chip->reg_lock); in snd_nm256_capture_trigger()
597 if (! s->running) { in snd_nm256_capture_trigger()
598 snd_nm256_capture_start(chip, s, substream); in snd_nm256_capture_trigger()
599 s->running = 1; in snd_nm256_capture_trigger()
604 if (s->running) { in snd_nm256_capture_trigger()
605 snd_nm256_capture_stop(chip); in snd_nm256_capture_trigger()
606 s->running = 0; in snd_nm256_capture_trigger()
610 err = -EINVAL; in snd_nm256_capture_trigger()
613 spin_unlock(&chip->reg_lock); in snd_nm256_capture_trigger()
623 struct nm256 *chip = snd_pcm_substream_chip(substream); in snd_nm256_pcm_prepare() local
624 struct snd_pcm_runtime *runtime = substream->runtime; in snd_nm256_pcm_prepare()
625 struct nm256_stream *s = runtime->private_data; in snd_nm256_pcm_prepare()
628 return -ENXIO; in snd_nm256_pcm_prepare()
629 s->dma_size = frames_to_bytes(runtime, substream->runtime->buffer_size); in snd_nm256_pcm_prepare()
630 s->period_size = frames_to_bytes(runtime, substream->runtime->period_size); in snd_nm256_pcm_prepare()
631 s->periods = substream->runtime->periods; in snd_nm256_pcm_prepare()
632 s->cur_period = 0; in snd_nm256_pcm_prepare()
634 spin_lock_irq(&chip->reg_lock); in snd_nm256_pcm_prepare()
635 s->running = 0; in snd_nm256_pcm_prepare()
636 snd_nm256_set_format(chip, s, substream); in snd_nm256_pcm_prepare()
637 spin_unlock_irq(&chip->reg_lock); in snd_nm256_pcm_prepare()
649 struct nm256 *chip = snd_pcm_substream_chip(substream); in snd_nm256_playback_pointer() local
650 struct nm256_stream *s = substream->runtime->private_data; in snd_nm256_playback_pointer()
655 curp = snd_nm256_readl(chip, NM_PBUFFER_CURRP) - (unsigned long)s->buf; in snd_nm256_playback_pointer()
656 curp %= s->dma_size; in snd_nm256_playback_pointer()
657 return bytes_to_frames(substream->runtime, curp); in snd_nm256_playback_pointer()
663 struct nm256 *chip = snd_pcm_substream_chip(substream); in snd_nm256_capture_pointer() local
664 struct nm256_stream *s = substream->runtime->private_data; in snd_nm256_capture_pointer()
669 curp = snd_nm256_readl(chip, NM_RBUFFER_CURRP) - (unsigned long)s->buf; in snd_nm256_capture_pointer()
670 curp %= s->dma_size; in snd_nm256_capture_pointer()
671 return bytes_to_frames(substream->runtime, curp); in snd_nm256_capture_pointer()
684 struct snd_pcm_runtime *runtime = substream->runtime; in snd_nm256_playback_silence()
685 struct nm256_stream *s = runtime->private_data; in snd_nm256_playback_silence()
687 memset_io(s->bufptr + pos, 0, count); in snd_nm256_playback_silence()
696 struct snd_pcm_runtime *runtime = substream->runtime; in snd_nm256_playback_copy()
697 struct nm256_stream *s = runtime->private_data; in snd_nm256_playback_copy()
699 return copy_from_iter_toio(s->bufptr + pos, src, count); in snd_nm256_playback_copy()
703 * copy to user
710 struct snd_pcm_runtime *runtime = substream->runtime; in snd_nm256_capture_copy()
711 struct nm256_stream *s = runtime->private_data; in snd_nm256_capture_copy()
713 return copy_to_iter_fromio(dst, s->bufptr + pos, count); in snd_nm256_capture_copy()
725 snd_nm256_playback_update(struct nm256 *chip) in snd_nm256_playback_update() argument
729 s = &chip->streams[SNDRV_PCM_STREAM_PLAYBACK]; in snd_nm256_playback_update()
730 if (s->running && s->substream) { in snd_nm256_playback_update()
731 spin_unlock(&chip->reg_lock); in snd_nm256_playback_update()
732 snd_pcm_period_elapsed(s->substream); in snd_nm256_playback_update()
733 spin_lock(&chip->reg_lock); in snd_nm256_playback_update()
734 snd_nm256_playback_mark(chip, s); in snd_nm256_playback_update()
740 snd_nm256_capture_update(struct nm256 *chip) in snd_nm256_capture_update() argument
744 s = &chip->streams[SNDRV_PCM_STREAM_CAPTURE]; in snd_nm256_capture_update()
745 if (s->running && s->substream) { in snd_nm256_capture_update()
746 spin_unlock(&chip->reg_lock); in snd_nm256_capture_update()
747 snd_pcm_period_elapsed(s->substream); in snd_nm256_capture_update()
748 spin_lock(&chip->reg_lock); in snd_nm256_capture_update()
749 snd_nm256_capture_mark(chip, s); in snd_nm256_capture_update()
800 substream->runtime->dma_bytes = params_buffer_bytes(hw_params); in snd_nm256_pcm_hw_params()
807 static void snd_nm256_setup_stream(struct nm256 *chip, struct nm256_stream *s, in snd_nm256_setup_stream() argument
811 struct snd_pcm_runtime *runtime = substream->runtime; in snd_nm256_setup_stream()
813 s->running = 0; in snd_nm256_setup_stream()
814 runtime->hw = *hw_ptr; in snd_nm256_setup_stream()
815 runtime->hw.buffer_bytes_max = s->bufsize; in snd_nm256_setup_stream()
816 runtime->hw.period_bytes_max = s->bufsize / 2; in snd_nm256_setup_stream()
817 runtime->dma_area = (void __force *) s->bufptr; in snd_nm256_setup_stream()
818 runtime->dma_addr = s->bufptr_addr; in snd_nm256_setup_stream()
819 runtime->dma_bytes = s->bufsize; in snd_nm256_setup_stream()
820 runtime->private_data = s; in snd_nm256_setup_stream()
821 s->substream = substream; in snd_nm256_setup_stream()
830 struct nm256 *chip = snd_pcm_substream_chip(substream); in snd_nm256_playback_open() local
832 if (snd_nm256_acquire_irq(chip) < 0) in snd_nm256_playback_open()
833 return -EBUSY; in snd_nm256_playback_open()
834 snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK], in snd_nm256_playback_open()
842 struct nm256 *chip = snd_pcm_substream_chip(substream); in snd_nm256_capture_open() local
844 if (snd_nm256_acquire_irq(chip) < 0) in snd_nm256_capture_open()
845 return -EBUSY; in snd_nm256_capture_open()
846 snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_CAPTURE], in snd_nm256_capture_open()
852 * close - we don't have to do special..
857 struct nm256 *chip = snd_pcm_substream_chip(substream); in snd_nm256_playback_close() local
859 snd_nm256_release_irq(chip); in snd_nm256_playback_close()
867 struct nm256 *chip = snd_pcm_substream_chip(substream); in snd_nm256_capture_close() local
869 snd_nm256_release_irq(chip); in snd_nm256_capture_close()
904 snd_nm256_pcm(struct nm256 *chip, int device) in snd_nm256_pcm() argument
910 struct nm256_stream *s = &chip->streams[i]; in snd_nm256_pcm()
911 s->bufptr = chip->buffer + (s->buf - chip->buffer_start); in snd_nm256_pcm()
912 s->bufptr_addr = chip->buffer_addr + (s->buf - chip->buffer_start); in snd_nm256_pcm()
915 err = snd_pcm_new(chip->card, chip->card->driver, device, in snd_nm256_pcm()
923 pcm->private_data = chip; in snd_nm256_pcm()
924 pcm->info_flags = 0; in snd_nm256_pcm()
925 chip->pcm = pcm; in snd_nm256_pcm()
935 snd_nm256_init_chip(struct nm256 *chip) in snd_nm256_init_chip() argument
938 snd_nm256_writeb(chip, 0x0, 0x11); in snd_nm256_init_chip()
939 snd_nm256_writew(chip, 0x214, 0); in snd_nm256_init_chip()
941 //snd_nm256_playback_stop(chip); in snd_nm256_init_chip()
942 //snd_nm256_capture_stop(chip); in snd_nm256_init_chip()
947 snd_nm256_intr_check(struct nm256 *chip) in snd_nm256_intr_check() argument
949 if (chip->badintrcount++ > 1000) { in snd_nm256_intr_check()
951 * I'm not sure if the best thing is to stop the card from in snd_nm256_intr_check()
956 * I worry about the card engine continuing to play noise in snd_nm256_intr_check()
957 * over and over, however--that could become a very in snd_nm256_intr_check()
962 if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running) in snd_nm256_intr_check()
963 snd_nm256_playback_stop(chip); in snd_nm256_intr_check()
964 if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running) in snd_nm256_intr_check()
965 snd_nm256_capture_stop(chip); in snd_nm256_intr_check()
966 chip->badintrcount = 0; in snd_nm256_intr_check()
973 * Handle a potential interrupt for the device referred to by DEV_ID.
975 * I don't like the cut-n-paste job here either between the two routines,
984 struct nm256 *chip = dev_id; in snd_nm256_interrupt() local
988 status = snd_nm256_readw(chip, NM_INT_REG); in snd_nm256_interrupt()
992 return snd_nm256_intr_check(chip); in snd_nm256_interrupt()
994 chip->badintrcount = 0; in snd_nm256_interrupt()
998 spin_lock(&chip->reg_lock); in snd_nm256_interrupt()
1001 NM_ACK_INT(chip, NM_PLAYBACK_INT); in snd_nm256_interrupt()
1002 snd_nm256_playback_update(chip); in snd_nm256_interrupt()
1007 NM_ACK_INT(chip, NM_RECORD_INT); in snd_nm256_interrupt()
1008 snd_nm256_capture_update(chip); in snd_nm256_interrupt()
1013 NM_ACK_INT(chip, NM_MISC_INT_1); in snd_nm256_interrupt()
1014 dev_dbg(chip->card->dev, "NM256: Got misc interrupt #1\n"); in snd_nm256_interrupt()
1015 snd_nm256_writew(chip, NM_INT_REG, 0x8000); in snd_nm256_interrupt()
1016 cbyte = snd_nm256_readb(chip, 0x400); in snd_nm256_interrupt()
1017 snd_nm256_writeb(chip, 0x400, cbyte | 2); in snd_nm256_interrupt()
1022 NM_ACK_INT(chip, NM_MISC_INT_2); in snd_nm256_interrupt()
1023 dev_dbg(chip->card->dev, "NM256: Got misc interrupt #2\n"); in snd_nm256_interrupt()
1024 cbyte = snd_nm256_readb(chip, 0x400); in snd_nm256_interrupt()
1025 snd_nm256_writeb(chip, 0x400, cbyte & ~2); in snd_nm256_interrupt()
1030 dev_dbg(chip->card->dev, in snd_nm256_interrupt()
1034 NM_ACK_INT(chip, status); in snd_nm256_interrupt()
1037 spin_unlock(&chip->reg_lock); in snd_nm256_interrupt()
1042 * Handle a potential interrupt for the device referred to by DEV_ID.
1043 * This handler is for the 256ZX, and is very similar to the non-ZX
1050 struct nm256 *chip = dev_id; in snd_nm256_interrupt_zx() local
1054 status = snd_nm256_readl(chip, NM_INT_REG); in snd_nm256_interrupt_zx()
1058 return snd_nm256_intr_check(chip); in snd_nm256_interrupt_zx()
1060 chip->badintrcount = 0; in snd_nm256_interrupt_zx()
1064 spin_lock(&chip->reg_lock); in snd_nm256_interrupt_zx()
1067 NM2_ACK_INT(chip, NM2_PLAYBACK_INT); in snd_nm256_interrupt_zx()
1068 snd_nm256_playback_update(chip); in snd_nm256_interrupt_zx()
1073 NM2_ACK_INT(chip, NM2_RECORD_INT); in snd_nm256_interrupt_zx()
1074 snd_nm256_capture_update(chip); in snd_nm256_interrupt_zx()
1079 NM2_ACK_INT(chip, NM2_MISC_INT_1); in snd_nm256_interrupt_zx()
1080 dev_dbg(chip->card->dev, "NM256: Got misc interrupt #1\n"); in snd_nm256_interrupt_zx()
1081 cbyte = snd_nm256_readb(chip, 0x400); in snd_nm256_interrupt_zx()
1082 snd_nm256_writeb(chip, 0x400, cbyte | 2); in snd_nm256_interrupt_zx()
1087 NM2_ACK_INT(chip, NM2_MISC_INT_2); in snd_nm256_interrupt_zx()
1088 dev_dbg(chip->card->dev, "NM256: Got misc interrupt #2\n"); in snd_nm256_interrupt_zx()
1089 cbyte = snd_nm256_readb(chip, 0x400); in snd_nm256_interrupt_zx()
1090 snd_nm256_writeb(chip, 0x400, cbyte & ~2); in snd_nm256_interrupt_zx()
1095 dev_dbg(chip->card->dev, in snd_nm256_interrupt_zx()
1099 NM2_ACK_INT(chip, status); in snd_nm256_interrupt_zx()
1102 spin_unlock(&chip->reg_lock); in snd_nm256_interrupt_zx()
1111 * Waits for the mixer to become ready to be written; returns a zero value
1115 snd_nm256_ac97_ready(struct nm256 *chip) in snd_nm256_ac97_ready() argument
1121 testaddr = chip->mixer_status_offset; in snd_nm256_ac97_ready()
1122 testb = chip->mixer_status_mask; in snd_nm256_ac97_ready()
1125 * Loop around waiting for the mixer to become ready. in snd_nm256_ac97_ready()
1127 while (timeout-- > 0) { in snd_nm256_ac97_ready()
1128 if ((snd_nm256_readw(chip, testaddr) & testb) == 0) in snd_nm256_ac97_ready()
1136 * Initial register values to be written to the AC97 mixer.
1137 * While most of these are identical to the reset values, we do this
1138 * so that we have most of the register contents cached--this avoids
1139 * reading from the mixer directly (which seems to be problematic,
1140 * probably due to ignorance).
1175 return -1; in nm256_ac97_idx()
1180 * thus we're treating it as a write-only mixer and cache the
1186 struct nm256 *chip = ac97->private_data; in snd_nm256_ac97_read() local
1191 return chip->ac97_regs[idx]; in snd_nm256_ac97_read()
1200 struct nm256 *chip = ac97->private_data; in snd_nm256_ac97_write() local
1208 base = chip->mixer_base; in snd_nm256_ac97_write()
1210 snd_nm256_ac97_ready(chip); in snd_nm256_ac97_write()
1212 /* Wait for the write to take, too. */ in snd_nm256_ac97_write()
1213 while (tries-- > 0) { in snd_nm256_ac97_write()
1214 snd_nm256_writew(chip, base + reg, val); in snd_nm256_ac97_write()
1216 if (snd_nm256_ac97_ready(chip)) { in snd_nm256_ac97_write()
1218 chip->ac97_regs[idx] = val; in snd_nm256_ac97_write()
1222 dev_dbg(chip->card->dev, "nm256: ac97 codec not ready..\n"); in snd_nm256_ac97_write()
1246 struct nm256 *chip = ac97->private_data; in snd_nm256_ac97_reset() local
1249 snd_nm256_writeb(chip, 0x6c0, 1); in snd_nm256_ac97_reset()
1250 if (! chip->reset_workaround) { in snd_nm256_ac97_reset()
1252 snd_nm256_writeb(chip, 0x6cc, 0x87); in snd_nm256_ac97_reset()
1254 if (! chip->reset_workaround_2) { in snd_nm256_ac97_reset()
1256 snd_nm256_writeb(chip, 0x6cc, 0x80); in snd_nm256_ac97_reset()
1257 snd_nm256_writeb(chip, 0x6cc, 0x0); in snd_nm256_ac97_reset()
1259 if (! chip->in_resume) { in snd_nm256_ac97_reset()
1262 /* preload the cache, so as to avoid even a single in snd_nm256_ac97_reset()
1273 snd_nm256_mixer(struct nm256 *chip) in snd_nm256_mixer() argument
1284 chip->ac97_regs = devm_kcalloc(chip->card->dev, in snd_nm256_mixer()
1287 if (! chip->ac97_regs) in snd_nm256_mixer()
1288 return -ENOMEM; in snd_nm256_mixer()
1290 err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus); in snd_nm256_mixer()
1296 ac97.private_data = chip; in snd_nm256_mixer()
1298 pbus->no_vra = 1; in snd_nm256_mixer()
1299 err = snd_ac97_mixer(pbus, &ac97, &chip->ac97); in snd_nm256_mixer()
1302 if (! (chip->ac97->id & (0xf0000000))) { in snd_nm256_mixer()
1304 sprintf(chip->card->mixername, "%s AC97", chip->card->driver); in snd_nm256_mixer()
1316 snd_nm256_peek_for_sig(struct nm256 *chip) in snd_nm256_peek_for_sig() argument
1321 unsigned long pointer_found = chip->buffer_end - 0x1400; in snd_nm256_peek_for_sig()
1324 temp = ioremap(chip->buffer_addr + chip->buffer_end - 0x400, 16); in snd_nm256_peek_for_sig()
1326 dev_err(chip->card->dev, in snd_nm256_peek_for_sig()
1327 "Unable to scan for card signature in video RAM\n"); in snd_nm256_peek_for_sig()
1328 return -EBUSY; in snd_nm256_peek_for_sig()
1339 pointer < chip->buffer_size || in snd_nm256_peek_for_sig()
1340 pointer > chip->buffer_end) { in snd_nm256_peek_for_sig()
1341 dev_err(chip->card->dev, in snd_nm256_peek_for_sig()
1344 return -ENODEV; in snd_nm256_peek_for_sig()
1347 dev_info(chip->card->dev, in snd_nm256_peek_for_sig()
1354 chip->buffer_end = pointer_found; in snd_nm256_peek_for_sig()
1366 struct nm256 *chip = card->private_data; in nm256_suspend() local
1369 snd_ac97_suspend(chip->ac97); in nm256_suspend()
1370 chip->coeffs_current = 0; in nm256_suspend()
1377 struct nm256 *chip = card->private_data; in nm256_resume() local
1381 chip->in_resume = 1; in nm256_resume()
1383 snd_nm256_init_chip(chip); in nm256_resume()
1386 snd_ac97_resume(chip->ac97); in nm256_resume()
1389 struct nm256_stream *s = &chip->streams[i]; in nm256_resume()
1390 if (s->substream && s->suspended) { in nm256_resume()
1391 spin_lock_irq(&chip->reg_lock); in nm256_resume()
1392 snd_nm256_set_format(chip, s, s->substream); in nm256_resume()
1393 spin_unlock_irq(&chip->reg_lock); in nm256_resume()
1398 chip->in_resume = 0; in nm256_resume()
1406 struct nm256 *chip = card->private_data; in snd_nm256_free() local
1408 if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running) in snd_nm256_free()
1409 snd_nm256_playback_stop(chip); in snd_nm256_free()
1410 if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running) in snd_nm256_free()
1411 snd_nm256_capture_stop(chip); in snd_nm256_free()
1417 struct nm256 *chip = card->private_data; in snd_nm256_create() local
1425 chip->card = card; in snd_nm256_create()
1426 chip->pci = pci; in snd_nm256_create()
1427 chip->use_cache = use_cache; in snd_nm256_create()
1428 spin_lock_init(&chip->reg_lock); in snd_nm256_create()
1429 chip->irq = -1; in snd_nm256_create()
1430 mutex_init(&chip->irq_mutex); in snd_nm256_create()
1433 chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize = playback_bufsize * 1024; in snd_nm256_create()
1434 chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize = capture_bufsize * 1024; in snd_nm256_create()
1443 chip->buffer_addr = pci_resource_start(pci, 0); in snd_nm256_create()
1444 chip->cport_addr = pci_resource_start(pci, 1); in snd_nm256_create()
1446 err = pci_request_regions(pci, card->driver); in snd_nm256_create()
1452 chip->cport = devm_ioremap(&pci->dev, chip->cport_addr, NM_PORT2_SIZE); in snd_nm256_create()
1453 if (!chip->cport) { in snd_nm256_create()
1454 dev_err(card->dev, "unable to map control port %lx\n", in snd_nm256_create()
1455 chip->cport_addr); in snd_nm256_create()
1456 return -ENOMEM; in snd_nm256_create()
1459 if (!strcmp(card->driver, "NM256AV")) { in snd_nm256_create()
1460 /* Ok, try to see if this is a non-AC97 version of the hardware. */ in snd_nm256_create()
1461 pval = snd_nm256_readw(chip, NM_MIXER_PRESENCE); in snd_nm256_create()
1464 dev_err(card->dev, in snd_nm256_create()
1466 dev_err(card->dev, in snd_nm256_create()
1467 "force the driver to load by passing in the module parameter\n"); in snd_nm256_create()
1468 dev_err(card->dev, in snd_nm256_create()
1470 dev_err(card->dev, in snd_nm256_create()
1472 return -ENXIO; in snd_nm256_create()
1475 chip->buffer_end = 2560 * 1024; in snd_nm256_create()
1476 chip->interrupt = snd_nm256_interrupt; in snd_nm256_create()
1477 chip->mixer_status_offset = NM_MIXER_STATUS_OFFSET; in snd_nm256_create()
1478 chip->mixer_status_mask = NM_MIXER_READY_MASK; in snd_nm256_create()
1481 if (snd_nm256_readb(chip, 0xa0b) != 0) in snd_nm256_create()
1482 chip->buffer_end = 6144 * 1024; in snd_nm256_create()
1484 chip->buffer_end = 4096 * 1024; in snd_nm256_create()
1486 chip->interrupt = snd_nm256_interrupt_zx; in snd_nm256_create()
1487 chip->mixer_status_offset = NM2_MIXER_STATUS_OFFSET; in snd_nm256_create()
1488 chip->mixer_status_mask = NM2_MIXER_READY_MASK; in snd_nm256_create()
1491 chip->buffer_size = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize + in snd_nm256_create()
1492 chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize; in snd_nm256_create()
1493 if (chip->use_cache) in snd_nm256_create()
1494 chip->buffer_size += NM_TOTAL_COEFF_COUNT * 4; in snd_nm256_create()
1496 chip->buffer_size += NM_MAX_PLAYBACK_COEF_SIZE + NM_MAX_RECORD_COEF_SIZE; in snd_nm256_create()
1498 if (buffer_top >= chip->buffer_size && buffer_top < chip->buffer_end) in snd_nm256_create()
1499 chip->buffer_end = buffer_top; in snd_nm256_create()
1502 err = snd_nm256_peek_for_sig(chip); in snd_nm256_create()
1507 chip->buffer_start = chip->buffer_end - chip->buffer_size; in snd_nm256_create()
1508 chip->buffer_addr += chip->buffer_start; in snd_nm256_create()
1510 dev_info(card->dev, "Mapping port 1 from 0x%x - 0x%x\n", in snd_nm256_create()
1511 chip->buffer_start, chip->buffer_end); in snd_nm256_create()
1513 chip->buffer = devm_ioremap(&pci->dev, chip->buffer_addr, in snd_nm256_create()
1514 chip->buffer_size); in snd_nm256_create()
1515 if (!chip->buffer) { in snd_nm256_create()
1516 dev_err(card->dev, "unable to map ring buffer at %lx\n", in snd_nm256_create()
1517 chip->buffer_addr); in snd_nm256_create()
1518 return -ENOMEM; in snd_nm256_create()
1522 addr = chip->buffer_start; in snd_nm256_create()
1523 chip->streams[SNDRV_PCM_STREAM_PLAYBACK].buf = addr; in snd_nm256_create()
1524 addr += chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize; in snd_nm256_create()
1525 chip->streams[SNDRV_PCM_STREAM_CAPTURE].buf = addr; in snd_nm256_create()
1526 addr += chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize; in snd_nm256_create()
1527 if (chip->use_cache) { in snd_nm256_create()
1528 chip->all_coeff_buf = addr; in snd_nm256_create()
1530 chip->coeff_buf[SNDRV_PCM_STREAM_PLAYBACK] = addr; in snd_nm256_create()
1532 chip->coeff_buf[SNDRV_PCM_STREAM_CAPTURE] = addr; in snd_nm256_create()
1536 chip->mixer_base = NM_MIXER_OFFSET; in snd_nm256_create()
1538 chip->coeffs_current = 0; in snd_nm256_create()
1540 snd_nm256_init_chip(chip); in snd_nm256_create()
1552 /* Reset workarounds to avoid lock-ups */
1553 SND_PCI_QUIRK(0x104d, 0x8041, "Sony PCG-F305", NM_RESET_WORKAROUND),
1564 struct nm256 *chip; in snd_nm256_probe() local
1570 dev_dbg(&pci->dev, "Enabled quirk for %s.\n", in snd_nm256_probe()
1572 switch (q->value) { in snd_nm256_probe()
1574 dev_info(&pci->dev, in snd_nm256_probe()
1576 return -ENODEV; in snd_nm256_probe()
1586 err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, in snd_nm256_probe()
1587 sizeof(*chip), &card); in snd_nm256_probe()
1590 chip = card->private_data; in snd_nm256_probe()
1592 switch (pci->device) { in snd_nm256_probe()
1594 strcpy(card->driver, "NM256AV"); in snd_nm256_probe()
1597 strcpy(card->driver, "NM256ZX"); in snd_nm256_probe()
1600 strcpy(card->driver, "NM256XL+"); in snd_nm256_probe()
1603 dev_err(&pci->dev, "invalid device id 0x%x\n", pci->device); in snd_nm256_probe()
1604 return -EINVAL; in snd_nm256_probe()
1623 dev_dbg(&pci->dev, "reset_workaround activated\n"); in snd_nm256_probe()
1624 chip->reset_workaround = 1; in snd_nm256_probe()
1628 dev_dbg(&pci->dev, "reset_workaround_2 activated\n"); in snd_nm256_probe()
1629 chip->reset_workaround_2 = 1; in snd_nm256_probe()
1632 err = snd_nm256_pcm(chip, 0); in snd_nm256_probe()
1635 err = snd_nm256_mixer(chip); in snd_nm256_probe()
1639 sprintf(card->shortname, "NeoMagic %s", card->driver); in snd_nm256_probe()
1640 sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %d", in snd_nm256_probe()
1641 card->shortname, in snd_nm256_probe()
1642 chip->buffer_addr, chip->cport_addr, chip->irq); in snd_nm256_probe()
1647 card->private_free = snd_nm256_free; in snd_nm256_probe()