2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2003-09-07 16:28:03 +00:00
|
|
|
* Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
|
2000-01-09 08:14:11 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Derived from the public domain Linux driver
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHERIN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
Sound Mega-commit. Expect further cleanup until code freeze.
For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .
Summary of changes includes:
1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.
Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.
Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).
Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.
2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.
Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.
Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/
3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.
4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.
5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.
6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.
Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO
Manual page updates are on the way.
Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.
2009-06-07 19:12:08 +00:00
|
|
|
#ifdef HAVE_KERNEL_OPTION_HEADERS
|
|
|
|
#include "opt_snd.h"
|
|
|
|
#endif
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
#include <dev/sound/pcm/sound.h>
|
|
|
|
#include <dev/sound/pcm/ac97.h>
|
|
|
|
#include <dev/sound/pci/neomagic.h>
|
|
|
|
#include <dev/sound/pci/neomagic-coeff.h>
|
|
|
|
|
2003-08-22 07:08:17 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2000-01-09 08:14:11 +00:00
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
SND_DECLARE_FILE("$FreeBSD$");
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#define NM_BUFFSIZE 16384
|
|
|
|
|
|
|
|
#define NM256AV_PCI_ID 0x800510c8
|
|
|
|
#define NM256ZX_PCI_ID 0x800610c8
|
|
|
|
|
|
|
|
struct sc_info;
|
|
|
|
|
|
|
|
/* channel registers */
|
|
|
|
struct sc_chinfo {
|
2002-03-04 00:36:04 +00:00
|
|
|
int active, spd, dir, fmt;
|
|
|
|
u_int32_t blksize, wmark;
|
2001-03-24 23:10:29 +00:00
|
|
|
struct snd_dbuf *buffer;
|
|
|
|
struct pcm_channel *channel;
|
2000-01-09 08:14:11 +00:00
|
|
|
struct sc_info *parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* device private data */
|
|
|
|
struct sc_info {
|
|
|
|
device_t dev;
|
|
|
|
u_int32_t type;
|
|
|
|
|
|
|
|
struct resource *reg, *irq, *buf;
|
|
|
|
int regid, irqid, bufid;
|
|
|
|
void *ih;
|
|
|
|
|
|
|
|
u_int32_t ac97_base, ac97_status, ac97_busy;
|
|
|
|
u_int32_t buftop, pbuf, rbuf, cbuf, acbuf;
|
|
|
|
u_int32_t playint, recint, misc1int, misc2int;
|
|
|
|
u_int32_t irsz, badintr;
|
|
|
|
|
|
|
|
struct sc_chinfo pch, rch;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* stuff */
|
|
|
|
static int nm_loadcoeff(struct sc_info *sc, int dir, int num);
|
|
|
|
static int nm_setch(struct sc_chinfo *ch);
|
|
|
|
static int nm_init(struct sc_info *);
|
|
|
|
static void nm_intr(void *);
|
|
|
|
|
|
|
|
/* talk to the card */
|
|
|
|
static u_int32_t nm_rd(struct sc_info *, int, int);
|
|
|
|
static void nm_wr(struct sc_info *, int, u_int32_t, int);
|
|
|
|
static u_int32_t nm_rdbuf(struct sc_info *, int, int);
|
|
|
|
static void nm_wrbuf(struct sc_info *, int, u_int32_t, int);
|
|
|
|
|
2000-01-11 10:37:16 +00:00
|
|
|
static u_int32_t badcards[] = {
|
|
|
|
0x0007103c,
|
|
|
|
0x008f1028,
|
2000-08-09 18:51:27 +00:00
|
|
|
0x00dd1014,
|
2001-04-10 14:28:21 +00:00
|
|
|
0x8005110a,
|
2000-01-11 10:37:16 +00:00
|
|
|
};
|
|
|
|
#define NUM_BADCARDS (sizeof(badcards) / sizeof(u_int32_t))
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
/* The actual rates supported by the card. */
|
|
|
|
static int samplerates[9] = {
|
2000-01-11 10:37:16 +00:00
|
|
|
8000,
|
|
|
|
11025,
|
|
|
|
16000,
|
|
|
|
22050,
|
|
|
|
24000,
|
|
|
|
32000,
|
|
|
|
44100,
|
|
|
|
48000,
|
|
|
|
99999999
|
2000-01-09 08:14:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
2000-08-20 22:18:56 +00:00
|
|
|
static u_int32_t nm_fmt[] = {
|
Sound Mega-commit. Expect further cleanup until code freeze.
For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .
Summary of changes includes:
1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.
Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.
Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).
Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.
2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.
Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.
Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/
3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.
4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.
5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.
6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.
Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO
Manual page updates are on the way.
Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.
2009-06-07 19:12:08 +00:00
|
|
|
SND_FORMAT(AFMT_U8, 1, 0),
|
|
|
|
SND_FORMAT(AFMT_U8, 2, 0),
|
|
|
|
SND_FORMAT(AFMT_S16_LE, 1, 0),
|
|
|
|
SND_FORMAT(AFMT_S16_LE, 2, 0),
|
2000-08-20 22:18:56 +00:00
|
|
|
0
|
2000-01-09 08:14:11 +00:00
|
|
|
};
|
2001-03-24 23:10:29 +00:00
|
|
|
static struct pcmchan_caps nm_caps = {4000, 48000, nm_fmt, 0};
|
2000-01-09 08:14:11 +00:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* Hardware */
|
|
|
|
static u_int32_t
|
|
|
|
nm_rd(struct sc_info *sc, int regno, int size)
|
|
|
|
{
|
|
|
|
bus_space_tag_t st = rman_get_bustag(sc->reg);
|
|
|
|
bus_space_handle_t sh = rman_get_bushandle(sc->reg);
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
return bus_space_read_1(st, sh, regno);
|
|
|
|
case 2:
|
|
|
|
return bus_space_read_2(st, sh, regno);
|
|
|
|
case 4:
|
|
|
|
return bus_space_read_4(st, sh, regno);
|
|
|
|
default:
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nm_wr(struct sc_info *sc, int regno, u_int32_t data, int size)
|
|
|
|
{
|
|
|
|
bus_space_tag_t st = rman_get_bustag(sc->reg);
|
|
|
|
bus_space_handle_t sh = rman_get_bushandle(sc->reg);
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
bus_space_write_1(st, sh, regno, data);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
bus_space_write_2(st, sh, regno, data);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
bus_space_write_4(st, sh, regno, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static u_int32_t
|
|
|
|
nm_rdbuf(struct sc_info *sc, int regno, int size)
|
|
|
|
{
|
|
|
|
bus_space_tag_t st = rman_get_bustag(sc->buf);
|
|
|
|
bus_space_handle_t sh = rman_get_bushandle(sc->buf);
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
return bus_space_read_1(st, sh, regno);
|
|
|
|
case 2:
|
|
|
|
return bus_space_read_2(st, sh, regno);
|
|
|
|
case 4:
|
|
|
|
return bus_space_read_4(st, sh, regno);
|
|
|
|
default:
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nm_wrbuf(struct sc_info *sc, int regno, u_int32_t data, int size)
|
|
|
|
{
|
|
|
|
bus_space_tag_t st = rman_get_bustag(sc->buf);
|
|
|
|
bus_space_handle_t sh = rman_get_bushandle(sc->buf);
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
bus_space_write_1(st, sh, regno, data);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
bus_space_write_2(st, sh, regno, data);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
bus_space_write_4(st, sh, regno, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
2000-01-09 08:14:11 +00:00
|
|
|
/* ac97 codec */
|
|
|
|
static int
|
|
|
|
nm_waitcd(struct sc_info *sc)
|
|
|
|
{
|
|
|
|
int cnt = 10;
|
2002-03-04 00:36:04 +00:00
|
|
|
int fail = 1;
|
2000-01-09 08:14:11 +00:00
|
|
|
|
|
|
|
while (cnt-- > 0) {
|
2002-03-04 00:36:04 +00:00
|
|
|
if (nm_rd(sc, sc->ac97_status, 2) & sc->ac97_busy) {
|
2000-01-09 08:14:11 +00:00
|
|
|
DELAY(100);
|
2002-03-04 00:36:04 +00:00
|
|
|
} else {
|
|
|
|
fail = 0;
|
2000-01-09 08:14:11 +00:00
|
|
|
break;
|
2002-03-04 00:36:04 +00:00
|
|
|
}
|
2000-01-09 08:14:11 +00:00
|
|
|
}
|
2002-03-04 00:36:04 +00:00
|
|
|
return (fail);
|
2000-01-09 08:14:11 +00:00
|
|
|
}
|
|
|
|
|
2000-03-20 15:30:50 +00:00
|
|
|
static u_int32_t
|
2000-12-18 01:36:41 +00:00
|
|
|
nm_initcd(kobj_t obj, void *devinfo)
|
2000-03-20 15:30:50 +00:00
|
|
|
{
|
|
|
|
struct sc_info *sc = (struct sc_info *)devinfo;
|
|
|
|
|
|
|
|
nm_wr(sc, 0x6c0, 0x01, 1);
|
2005-09-11 17:30:27 +00:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* The following code-line may cause a hang for some chipsets, see
|
|
|
|
* PR 56617.
|
|
|
|
* In case of a bugreport without this line have a look at the PR and
|
|
|
|
* conditionize the code-line based upon the specific version of
|
|
|
|
* the chip.
|
|
|
|
*/
|
2000-03-20 15:30:50 +00:00
|
|
|
nm_wr(sc, 0x6cc, 0x87, 1);
|
2005-09-11 17:30:27 +00:00
|
|
|
#endif
|
2000-03-20 15:30:50 +00:00
|
|
|
nm_wr(sc, 0x6cc, 0x80, 1);
|
|
|
|
nm_wr(sc, 0x6cc, 0x00, 1);
|
2000-09-05 21:08:01 +00:00
|
|
|
return 1;
|
2000-03-20 15:30:50 +00:00
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static int
|
|
|
|
nm_rdcd(kobj_t obj, void *devinfo, int regno)
|
2000-01-09 08:14:11 +00:00
|
|
|
{
|
|
|
|
struct sc_info *sc = (struct sc_info *)devinfo;
|
|
|
|
u_int32_t x;
|
|
|
|
|
|
|
|
if (!nm_waitcd(sc)) {
|
|
|
|
x = nm_rd(sc, sc->ac97_base + regno, 2);
|
|
|
|
DELAY(1000);
|
|
|
|
return x;
|
|
|
|
} else {
|
|
|
|
device_printf(sc->dev, "ac97 codec not ready\n");
|
2000-12-18 01:36:41 +00:00
|
|
|
return -1;
|
2000-01-09 08:14:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static int
|
|
|
|
nm_wrcd(kobj_t obj, void *devinfo, int regno, u_int32_t data)
|
2000-01-09 08:14:11 +00:00
|
|
|
{
|
|
|
|
struct sc_info *sc = (struct sc_info *)devinfo;
|
|
|
|
int cnt = 3;
|
|
|
|
|
|
|
|
if (!nm_waitcd(sc)) {
|
|
|
|
while (cnt-- > 0) {
|
|
|
|
nm_wr(sc, sc->ac97_base + regno, data, 2);
|
|
|
|
if (!nm_waitcd(sc)) {
|
|
|
|
DELAY(1000);
|
2000-12-18 01:36:41 +00:00
|
|
|
return 0;
|
2000-01-09 08:14:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
device_printf(sc->dev, "ac97 codec not ready\n");
|
2000-12-18 01:36:41 +00:00
|
|
|
return -1;
|
2000-01-09 08:14:11 +00:00
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static kobj_method_t nm_ac97_methods[] = {
|
|
|
|
KOBJMETHOD(ac97_init, nm_initcd),
|
|
|
|
KOBJMETHOD(ac97_read, nm_rdcd),
|
|
|
|
KOBJMETHOD(ac97_write, nm_wrcd),
|
Sound Mega-commit. Expect further cleanup until code freeze.
For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .
Summary of changes includes:
1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.
Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.
Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).
Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.
2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.
Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.
Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/
3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.
4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.
5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.
6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.
Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO
Manual page updates are on the way.
Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.
2009-06-07 19:12:08 +00:00
|
|
|
KOBJMETHOD_END
|
2000-12-18 01:36:41 +00:00
|
|
|
};
|
|
|
|
AC97_DECLARE(nm_ac97);
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
static void
|
|
|
|
nm_ackint(struct sc_info *sc, u_int32_t num)
|
|
|
|
{
|
|
|
|
if (sc->type == NM256AV_PCI_ID) {
|
|
|
|
nm_wr(sc, NM_INT_REG, num << 1, 2);
|
|
|
|
} else if (sc->type == NM256ZX_PCI_ID) {
|
|
|
|
nm_wr(sc, NM_INT_REG, num, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nm_loadcoeff(struct sc_info *sc, int dir, int num)
|
|
|
|
{
|
|
|
|
int ofs, sz, i;
|
|
|
|
u_int32_t addr;
|
|
|
|
|
|
|
|
addr = (dir == PCMDIR_PLAY)? 0x01c : 0x21c;
|
|
|
|
if (dir == PCMDIR_REC)
|
|
|
|
num += 8;
|
|
|
|
sz = coefficientSizes[num];
|
|
|
|
ofs = 0;
|
|
|
|
while (num-- > 0)
|
|
|
|
ofs+= coefficientSizes[num];
|
|
|
|
for (i = 0; i < sz; i++)
|
|
|
|
nm_wrbuf(sc, sc->cbuf + i, coefficients[ofs + i], 1);
|
|
|
|
nm_wr(sc, addr, sc->cbuf, 4);
|
|
|
|
if (dir == PCMDIR_PLAY)
|
|
|
|
sz--;
|
|
|
|
nm_wr(sc, addr + 4, sc->cbuf + sz, 4);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nm_setch(struct sc_chinfo *ch)
|
|
|
|
{
|
|
|
|
struct sc_info *sc = ch->parent;
|
|
|
|
u_int32_t base;
|
|
|
|
u_int8_t x;
|
|
|
|
|
|
|
|
for (x = 0; x < 8; x++)
|
|
|
|
if (ch->spd < (samplerates[x] + samplerates[x + 1]) / 2)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (x == 8) return 1;
|
|
|
|
|
|
|
|
ch->spd = samplerates[x];
|
|
|
|
nm_loadcoeff(sc, ch->dir, x);
|
|
|
|
|
|
|
|
x <<= 4;
|
|
|
|
x &= NM_RATE_MASK;
|
|
|
|
if (ch->fmt & AFMT_16BIT) x |= NM_RATE_BITS_16;
|
Sound Mega-commit. Expect further cleanup until code freeze.
For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .
Summary of changes includes:
1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.
Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.
Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).
Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.
2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.
Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.
Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/
3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.
4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.
5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.
6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.
Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO
Manual page updates are on the way.
Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.
2009-06-07 19:12:08 +00:00
|
|
|
if (AFMT_CHANNEL(ch->fmt) > 1) x |= NM_RATE_STEREO;
|
2000-01-09 08:14:11 +00:00
|
|
|
|
|
|
|
base = (ch->dir == PCMDIR_PLAY)? NM_PLAYBACK_REG_OFFSET : NM_RECORD_REG_OFFSET;
|
|
|
|
nm_wr(sc, base + NM_RATE_REG_OFFSET, x, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* channel interface */
|
|
|
|
static void *
|
2001-03-24 23:10:29 +00:00
|
|
|
nmchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
|
2000-01-09 08:14:11 +00:00
|
|
|
{
|
|
|
|
struct sc_info *sc = devinfo;
|
|
|
|
struct sc_chinfo *ch;
|
|
|
|
u_int32_t chnbuf;
|
|
|
|
|
|
|
|
chnbuf = (dir == PCMDIR_PLAY)? sc->pbuf : sc->rbuf;
|
|
|
|
ch = (dir == PCMDIR_PLAY)? &sc->pch : &sc->rch;
|
2002-03-04 00:36:04 +00:00
|
|
|
ch->active = 0;
|
|
|
|
ch->blksize = 0;
|
|
|
|
ch->wmark = 0;
|
2000-01-09 08:14:11 +00:00
|
|
|
ch->buffer = b;
|
update code dealing with snd_dbuf objects to do so using a functional interface
modify chn_setblocksize() to pick a default soft-blocksize appropriate to the
sample rate and format in use. it will aim for a power of two size small
enough to generate block sizes of at most 20ms. it will also set the
hard-blocksize taking into account rate/format conversions in use.
update drivers to implement setblocksize correctly:
updated, tested: sb16, emu10k1, maestro, solo
updated, untested: ad1816, ess, mss, sb8, csa
not updated: ds1, es137x, fm801, neomagic, t4dwave, via82c686
i lack hardware to test: ad1816, csa, fm801, neomagic
others will be updated/tested in the next few days.
2000-12-23 03:16:13 +00:00
|
|
|
sndbuf_setup(ch->buffer, (u_int8_t *)rman_get_virtual(sc->buf) + chnbuf, NM_BUFFSIZE);
|
2000-01-13 06:00:57 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->dev, "%s buf %p\n", (dir == PCMDIR_PLAY)?
|
2001-03-24 23:10:29 +00:00
|
|
|
"play" : "rec", sndbuf_getbuf(ch->buffer));
|
2000-01-09 08:14:11 +00:00
|
|
|
ch->parent = sc;
|
|
|
|
ch->channel = c;
|
|
|
|
ch->dir = dir;
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2000-09-01 20:09:24 +00:00
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
nmchan_free(kobj_t obj, void *data)
|
2000-09-01 20:09:24 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
nmchan_setformat(kobj_t obj, void *data, u_int32_t format)
|
2000-01-09 08:14:11 +00:00
|
|
|
{
|
|
|
|
struct sc_chinfo *ch = data;
|
|
|
|
|
|
|
|
ch->fmt = format;
|
|
|
|
return nm_setch(ch);
|
|
|
|
}
|
|
|
|
|
Sound Mega-commit. Expect further cleanup until code freeze.
For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .
Summary of changes includes:
1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.
Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.
Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).
Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.
2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.
Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.
Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/
3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.
4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.
5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.
6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.
Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO
Manual page updates are on the way.
Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.
2009-06-07 19:12:08 +00:00
|
|
|
static u_int32_t
|
2000-12-18 01:36:41 +00:00
|
|
|
nmchan_setspeed(kobj_t obj, void *data, u_int32_t speed)
|
2000-01-09 08:14:11 +00:00
|
|
|
{
|
|
|
|
struct sc_chinfo *ch = data;
|
|
|
|
|
|
|
|
ch->spd = speed;
|
2000-01-10 01:59:12 +00:00
|
|
|
return nm_setch(ch)? 0 : ch->spd;
|
2000-01-09 08:14:11 +00:00
|
|
|
}
|
|
|
|
|
Sound Mega-commit. Expect further cleanup until code freeze.
For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .
Summary of changes includes:
1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.
Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.
Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).
Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.
2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.
Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.
Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/
3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.
4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.
5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.
6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.
Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO
Manual page updates are on the way.
Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.
2009-06-07 19:12:08 +00:00
|
|
|
static u_int32_t
|
2000-12-18 01:36:41 +00:00
|
|
|
nmchan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
|
2000-01-09 08:14:11 +00:00
|
|
|
{
|
2002-03-04 00:36:04 +00:00
|
|
|
struct sc_chinfo *ch = data;
|
|
|
|
|
|
|
|
ch->blksize = blocksize;
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
return blocksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
nmchan_trigger(kobj_t obj, void *data, int go)
|
2000-01-09 08:14:11 +00:00
|
|
|
{
|
|
|
|
struct sc_chinfo *ch = data;
|
|
|
|
struct sc_info *sc = ch->parent;
|
|
|
|
int ssz;
|
|
|
|
|
2007-06-11 00:49:46 +00:00
|
|
|
if (!PCMTRIG_COMMON(go))
|
2000-05-26 21:15:47 +00:00
|
|
|
return 0;
|
2000-01-09 08:14:11 +00:00
|
|
|
|
|
|
|
ssz = (ch->fmt & AFMT_16BIT)? 2 : 1;
|
Sound Mega-commit. Expect further cleanup until code freeze.
For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .
Summary of changes includes:
1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.
Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.
Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).
Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.
2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.
Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.
Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/
3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.
4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.
5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.
6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.
Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO
Manual page updates are on the way.
Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.
2009-06-07 19:12:08 +00:00
|
|
|
if (AFMT_CHANNEL(ch->fmt) > 1)
|
2000-01-09 08:14:11 +00:00
|
|
|
ssz <<= 1;
|
|
|
|
|
|
|
|
if (ch->dir == PCMDIR_PLAY) {
|
|
|
|
if (go == PCMTRIG_START) {
|
2002-03-04 00:36:04 +00:00
|
|
|
ch->active = 1;
|
|
|
|
ch->wmark = ch->blksize;
|
2000-01-09 08:14:11 +00:00
|
|
|
nm_wr(sc, NM_PBUFFER_START, sc->pbuf, 4);
|
|
|
|
nm_wr(sc, NM_PBUFFER_END, sc->pbuf + NM_BUFFSIZE - ssz, 4);
|
|
|
|
nm_wr(sc, NM_PBUFFER_CURRP, sc->pbuf, 4);
|
2002-03-04 00:36:04 +00:00
|
|
|
nm_wr(sc, NM_PBUFFER_WMARK, sc->pbuf + ch->wmark, 4);
|
2000-01-09 08:14:11 +00:00
|
|
|
nm_wr(sc, NM_PLAYBACK_ENABLE_REG, NM_PLAYBACK_FREERUN |
|
|
|
|
NM_PLAYBACK_ENABLE_FLAG, 1);
|
|
|
|
nm_wr(sc, NM_AUDIO_MUTE_REG, 0, 2);
|
|
|
|
} else {
|
2002-03-04 00:36:04 +00:00
|
|
|
ch->active = 0;
|
2000-01-09 08:14:11 +00:00
|
|
|
nm_wr(sc, NM_PLAYBACK_ENABLE_REG, 0, 1);
|
|
|
|
nm_wr(sc, NM_AUDIO_MUTE_REG, NM_AUDIO_MUTE_BOTH, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (go == PCMTRIG_START) {
|
2002-03-04 00:36:04 +00:00
|
|
|
ch->active = 1;
|
|
|
|
ch->wmark = ch->blksize;
|
2000-01-09 08:14:11 +00:00
|
|
|
nm_wr(sc, NM_RECORD_ENABLE_REG, NM_RECORD_FREERUN |
|
|
|
|
NM_RECORD_ENABLE_FLAG, 1);
|
|
|
|
nm_wr(sc, NM_RBUFFER_START, sc->rbuf, 4);
|
|
|
|
nm_wr(sc, NM_RBUFFER_END, sc->rbuf + NM_BUFFSIZE, 4);
|
|
|
|
nm_wr(sc, NM_RBUFFER_CURRP, sc->rbuf, 4);
|
2002-03-04 00:36:04 +00:00
|
|
|
nm_wr(sc, NM_RBUFFER_WMARK, sc->rbuf + ch->wmark, 4);
|
2000-01-09 08:14:11 +00:00
|
|
|
} else {
|
2002-03-04 00:36:04 +00:00
|
|
|
ch->active = 0;
|
2000-01-09 08:14:11 +00:00
|
|
|
nm_wr(sc, NM_RECORD_ENABLE_REG, 0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Sound Mega-commit. Expect further cleanup until code freeze.
For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .
Summary of changes includes:
1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.
Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.
Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).
Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.
2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.
Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.
Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/
3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.
4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.
5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.
6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.
Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO
Manual page updates are on the way.
Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.
2009-06-07 19:12:08 +00:00
|
|
|
static u_int32_t
|
2000-12-18 01:36:41 +00:00
|
|
|
nmchan_getptr(kobj_t obj, void *data)
|
2000-01-09 08:14:11 +00:00
|
|
|
{
|
|
|
|
struct sc_chinfo *ch = data;
|
|
|
|
struct sc_info *sc = ch->parent;
|
|
|
|
|
|
|
|
if (ch->dir == PCMDIR_PLAY)
|
|
|
|
return nm_rd(sc, NM_PBUFFER_CURRP, 4) - sc->pbuf;
|
|
|
|
else
|
|
|
|
return nm_rd(sc, NM_RBUFFER_CURRP, 4) - sc->rbuf;
|
|
|
|
}
|
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
static struct pcmchan_caps *
|
2000-12-18 01:36:41 +00:00
|
|
|
nmchan_getcaps(kobj_t obj, void *data)
|
2000-01-09 08:14:11 +00:00
|
|
|
{
|
|
|
|
return &nm_caps;
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static kobj_method_t nmchan_methods[] = {
|
|
|
|
KOBJMETHOD(channel_init, nmchan_init),
|
|
|
|
KOBJMETHOD(channel_free, nmchan_free),
|
|
|
|
KOBJMETHOD(channel_setformat, nmchan_setformat),
|
|
|
|
KOBJMETHOD(channel_setspeed, nmchan_setspeed),
|
|
|
|
KOBJMETHOD(channel_setblocksize, nmchan_setblocksize),
|
|
|
|
KOBJMETHOD(channel_trigger, nmchan_trigger),
|
|
|
|
KOBJMETHOD(channel_getptr, nmchan_getptr),
|
|
|
|
KOBJMETHOD(channel_getcaps, nmchan_getcaps),
|
Sound Mega-commit. Expect further cleanup until code freeze.
For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .
Summary of changes includes:
1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.
Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.
Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).
Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.
2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.
Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.
Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/
3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.
4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.
5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.
6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.
Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO
Manual page updates are on the way.
Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.
2009-06-07 19:12:08 +00:00
|
|
|
KOBJMETHOD_END
|
2000-12-18 01:36:41 +00:00
|
|
|
};
|
|
|
|
CHANNEL_DECLARE(nmchan);
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
/* The interrupt handler */
|
|
|
|
static void
|
|
|
|
nm_intr(void *p)
|
|
|
|
{
|
|
|
|
struct sc_info *sc = (struct sc_info *)p;
|
2000-08-09 18:51:27 +00:00
|
|
|
int status, x;
|
2000-01-09 08:14:11 +00:00
|
|
|
|
|
|
|
status = nm_rd(sc, NM_INT_REG, sc->irsz);
|
2000-08-09 18:51:27 +00:00
|
|
|
if (status == 0)
|
2000-01-09 08:14:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (status & sc->playint) {
|
|
|
|
status &= ~sc->playint;
|
2002-03-04 00:36:04 +00:00
|
|
|
sc->pch.wmark += sc->pch.blksize;
|
|
|
|
sc->pch.wmark %= NM_BUFFSIZE;
|
|
|
|
nm_wr(sc, NM_PBUFFER_WMARK, sc->pbuf + sc->pch.wmark, 4);
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
nm_ackint(sc, sc->playint);
|
|
|
|
chn_intr(sc->pch.channel);
|
|
|
|
}
|
|
|
|
if (status & sc->recint) {
|
|
|
|
status &= ~sc->recint;
|
2002-03-04 00:36:04 +00:00
|
|
|
sc->rch.wmark += sc->rch.blksize;
|
|
|
|
sc->rch.wmark %= NM_BUFFSIZE;
|
|
|
|
nm_wr(sc, NM_RBUFFER_WMARK, sc->rbuf + sc->rch.wmark, 4);
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
nm_ackint(sc, sc->recint);
|
|
|
|
chn_intr(sc->rch.channel);
|
|
|
|
}
|
|
|
|
if (status & sc->misc1int) {
|
|
|
|
status &= ~sc->misc1int;
|
|
|
|
nm_ackint(sc, sc->misc1int);
|
|
|
|
x = nm_rd(sc, 0x400, 1);
|
|
|
|
nm_wr(sc, 0x400, x | 2, 1);
|
|
|
|
device_printf(sc->dev, "misc int 1\n");
|
|
|
|
}
|
|
|
|
if (status & sc->misc2int) {
|
|
|
|
status &= ~sc->misc2int;
|
|
|
|
nm_ackint(sc, sc->misc2int);
|
|
|
|
x = nm_rd(sc, 0x400, 1);
|
|
|
|
nm_wr(sc, 0x400, x & ~2, 1);
|
|
|
|
device_printf(sc->dev, "misc int 2\n");
|
|
|
|
}
|
|
|
|
if (status) {
|
2000-08-09 18:51:27 +00:00
|
|
|
nm_ackint(sc, status);
|
2000-01-09 08:14:11 +00:00
|
|
|
device_printf(sc->dev, "unknown int\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe and attach the card
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
nm_init(struct sc_info *sc)
|
|
|
|
{
|
|
|
|
u_int32_t ofs, i;
|
|
|
|
|
|
|
|
if (sc->type == NM256AV_PCI_ID) {
|
|
|
|
sc->ac97_base = NM_MIXER_OFFSET;
|
|
|
|
sc->ac97_status = NM_MIXER_STATUS_OFFSET;
|
|
|
|
sc->ac97_busy = NM_MIXER_READY_MASK;
|
|
|
|
|
|
|
|
sc->buftop = 2560 * 1024;
|
|
|
|
|
|
|
|
sc->irsz = 2;
|
|
|
|
sc->playint = NM_PLAYBACK_INT;
|
|
|
|
sc->recint = NM_RECORD_INT;
|
|
|
|
sc->misc1int = NM_MISC_INT_1;
|
|
|
|
sc->misc2int = NM_MISC_INT_2;
|
|
|
|
} else if (sc->type == NM256ZX_PCI_ID) {
|
|
|
|
sc->ac97_base = NM_MIXER_OFFSET;
|
|
|
|
sc->ac97_status = NM2_MIXER_STATUS_OFFSET;
|
|
|
|
sc->ac97_busy = NM2_MIXER_READY_MASK;
|
|
|
|
|
|
|
|
sc->buftop = (nm_rd(sc, 0xa0b, 2)? 6144 : 4096) * 1024;
|
|
|
|
|
|
|
|
sc->irsz = 4;
|
|
|
|
sc->playint = NM2_PLAYBACK_INT;
|
|
|
|
sc->recint = NM2_RECORD_INT;
|
|
|
|
sc->misc1int = NM2_MISC_INT_1;
|
|
|
|
sc->misc2int = NM2_MISC_INT_2;
|
2000-01-10 06:19:20 +00:00
|
|
|
} else return -1;
|
2000-01-09 08:14:11 +00:00
|
|
|
sc->badintr = 0;
|
|
|
|
ofs = sc->buftop - 0x0400;
|
|
|
|
sc->buftop -= 0x1400;
|
|
|
|
|
2002-03-04 00:36:04 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->dev, "buftop is 0x%08x\n", sc->buftop);
|
2000-01-09 08:14:11 +00:00
|
|
|
if ((nm_rdbuf(sc, ofs, 4) & NM_SIG_MASK) == NM_SIGNATURE) {
|
|
|
|
i = nm_rdbuf(sc, ofs + 4, 4);
|
2002-03-04 00:36:04 +00:00
|
|
|
if (i != 0 && i != 0xffffffff) {
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->dev, "buftop is changed to 0x%08x\n", i);
|
2000-01-09 08:14:11 +00:00
|
|
|
sc->buftop = i;
|
2002-03-04 00:36:04 +00:00
|
|
|
}
|
2000-01-09 08:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->cbuf = sc->buftop - NM_MAX_COEFFICIENT;
|
|
|
|
sc->rbuf = sc->cbuf - NM_BUFFSIZE;
|
|
|
|
sc->pbuf = sc->rbuf - NM_BUFFSIZE;
|
|
|
|
sc->acbuf = sc->pbuf - (NM_TOTAL_COEFF_COUNT * 4);
|
|
|
|
|
|
|
|
nm_wr(sc, 0, 0x11, 1);
|
|
|
|
nm_wr(sc, NM_RECORD_ENABLE_REG, 0, 1);
|
|
|
|
nm_wr(sc, 0x214, 0, 2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nm_pci_probe(device_t dev)
|
|
|
|
{
|
2001-04-10 14:28:21 +00:00
|
|
|
struct sc_info *sc = NULL;
|
2000-01-09 08:14:11 +00:00
|
|
|
char *s = NULL;
|
2013-08-12 23:30:01 +00:00
|
|
|
u_int32_t subdev, i;
|
2000-01-09 08:14:11 +00:00
|
|
|
|
2000-01-11 10:37:16 +00:00
|
|
|
subdev = (pci_get_subdevice(dev) << 16) | pci_get_subvendor(dev);
|
2000-01-09 08:14:11 +00:00
|
|
|
switch (pci_get_devid(dev)) {
|
|
|
|
case NM256AV_PCI_ID:
|
2000-01-11 10:37:16 +00:00
|
|
|
i = 0;
|
|
|
|
while ((i < NUM_BADCARDS) && (badcards[i] != subdev))
|
|
|
|
i++;
|
2001-04-10 14:28:21 +00:00
|
|
|
|
|
|
|
/* Try to catch other non-ac97 cards */
|
|
|
|
|
|
|
|
if (i == NUM_BADCARDS) {
|
2001-06-21 19:45:59 +00:00
|
|
|
if (!(sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT | M_ZERO))) {
|
2001-04-10 14:28:21 +00:00
|
|
|
device_printf(dev, "cannot allocate softc\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
2003-09-02 17:30:40 +00:00
|
|
|
sc->regid = PCIR_BAR(1);
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
|
|
|
&sc->regid,
|
|
|
|
RF_ACTIVE);
|
2001-04-10 14:28:21 +00:00
|
|
|
|
|
|
|
if (!sc->reg) {
|
|
|
|
device_printf(dev, "unable to map register space\n");
|
|
|
|
free(sc, M_DEVBUF);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
2002-03-04 00:36:04 +00:00
|
|
|
/*
|
|
|
|
* My Panasonic CF-M2EV needs resetting device
|
|
|
|
* before checking mixer is present or not.
|
|
|
|
* t.ichinoseki@nifty.com.
|
|
|
|
*/
|
|
|
|
nm_wr(sc, 0, 0x11, 1); /* reset device */
|
2001-06-16 21:25:10 +00:00
|
|
|
if ((nm_rd(sc, NM_MIXER_PRESENCE, 2) &
|
2001-04-10 14:28:21 +00:00
|
|
|
NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {
|
|
|
|
i = 0; /* non-ac97 card, but not listed */
|
|
|
|
DEB(device_printf(dev, "subdev = 0x%x - badcard?\n",
|
|
|
|
subdev));
|
|
|
|
}
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, sc->regid,
|
|
|
|
sc->reg);
|
|
|
|
free(sc, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
2000-01-11 10:37:16 +00:00
|
|
|
if (i == NUM_BADCARDS)
|
|
|
|
s = "NeoMagic 256AV";
|
2000-01-13 06:00:57 +00:00
|
|
|
DEB(else)
|
|
|
|
DEB(device_printf(dev, "this is a non-ac97 NM256AV, not attaching\n"));
|
2001-04-10 14:28:21 +00:00
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NM256ZX_PCI_ID:
|
|
|
|
s = "NeoMagic 256ZX";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s) device_set_desc(dev, s);
|
|
|
|
return s? 0 : ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nm_pci_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct sc_info *sc;
|
2016-04-12 17:23:03 +00:00
|
|
|
struct ac97_info *codec = NULL;
|
2000-01-09 08:14:11 +00:00
|
|
|
char status[SND_STATUSLEN];
|
|
|
|
|
2007-06-17 06:10:43 +00:00
|
|
|
sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
|
2000-01-09 08:14:11 +00:00
|
|
|
sc->dev = dev;
|
|
|
|
sc->type = pci_get_devid(dev);
|
|
|
|
|
2013-08-12 23:30:01 +00:00
|
|
|
pci_enable_busmaster(dev);
|
2000-01-09 08:14:11 +00:00
|
|
|
|
2003-09-02 17:30:40 +00:00
|
|
|
sc->bufid = PCIR_BAR(0);
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->buf = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->bufid,
|
|
|
|
RF_ACTIVE);
|
2003-09-02 17:30:40 +00:00
|
|
|
sc->regid = PCIR_BAR(1);
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->regid,
|
|
|
|
RF_ACTIVE);
|
2000-01-09 08:14:11 +00:00
|
|
|
|
|
|
|
if (!sc->buf || !sc->reg) {
|
|
|
|
device_printf(dev, "unable to map register space\n");
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nm_init(sc) == -1) {
|
|
|
|
device_printf(dev, "unable to initialize the card\n");
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
codec = AC97_CREATE(dev, sc, nm_ac97);
|
2000-01-09 08:14:11 +00:00
|
|
|
if (codec == NULL) goto bad;
|
2000-12-18 01:36:41 +00:00
|
|
|
if (mixer_init(dev, ac97_getmixerclass(), codec) == -1) goto bad;
|
2000-01-09 08:14:11 +00:00
|
|
|
|
|
|
|
sc->irqid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqid,
|
|
|
|
RF_ACTIVE | RF_SHAREABLE);
|
2001-03-24 23:10:29 +00:00
|
|
|
if (!sc->irq || snd_setup_intr(dev, sc->irq, 0, nm_intr, sc, &sc->ih)) {
|
2000-01-09 08:14:11 +00:00
|
|
|
device_printf(dev, "unable to map interrupt\n");
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
snprintf(status, SND_STATUSLEN, "at memory 0x%jx, 0x%jx irq %jd %s",
|
2000-01-09 08:14:11 +00:00
|
|
|
rman_get_start(sc->buf), rman_get_start(sc->reg),
|
2004-03-06 15:52:42 +00:00
|
|
|
rman_get_start(sc->irq),PCM_KLDSTRING(snd_neomagic));
|
2000-01-09 08:14:11 +00:00
|
|
|
|
|
|
|
if (pcm_register(dev, sc, 1, 1)) goto bad;
|
2000-12-18 01:36:41 +00:00
|
|
|
pcm_addchan(dev, PCMDIR_REC, &nmchan_class, sc);
|
|
|
|
pcm_addchan(dev, PCMDIR_PLAY, &nmchan_class, sc);
|
2000-01-09 08:14:11 +00:00
|
|
|
pcm_setstatus(dev, status);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bad:
|
2000-09-09 19:21:04 +00:00
|
|
|
if (codec) ac97_destroy(codec);
|
2000-01-09 08:14:11 +00:00
|
|
|
if (sc->buf) bus_release_resource(dev, SYS_RES_MEMORY, sc->bufid, sc->buf);
|
|
|
|
if (sc->reg) bus_release_resource(dev, SYS_RES_MEMORY, sc->regid, sc->reg);
|
|
|
|
if (sc->ih) bus_teardown_intr(dev, sc->irq, sc->ih);
|
|
|
|
if (sc->irq) bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq);
|
|
|
|
free(sc, M_DEVBUF);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
2000-09-09 19:21:04 +00:00
|
|
|
static int
|
|
|
|
nm_pci_detach(device_t dev)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct sc_info *sc;
|
|
|
|
|
|
|
|
r = pcm_unregister(dev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
sc = pcm_getdevinfo(dev);
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, sc->bufid, sc->buf);
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, sc->regid, sc->reg);
|
|
|
|
bus_teardown_intr(dev, sc->irq, sc->ih);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq);
|
|
|
|
free(sc, M_DEVBUF);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-03-20 15:30:50 +00:00
|
|
|
static int
|
2002-03-04 00:36:04 +00:00
|
|
|
nm_pci_suspend(device_t dev)
|
2000-03-20 15:30:50 +00:00
|
|
|
{
|
|
|
|
struct sc_info *sc;
|
|
|
|
|
|
|
|
sc = pcm_getdevinfo(dev);
|
|
|
|
|
2002-03-04 00:36:04 +00:00
|
|
|
/* stop playing */
|
|
|
|
if (sc->pch.active) {
|
|
|
|
nm_wr(sc, NM_PLAYBACK_ENABLE_REG, 0, 1);
|
|
|
|
nm_wr(sc, NM_AUDIO_MUTE_REG, NM_AUDIO_MUTE_BOTH, 2);
|
2000-03-20 15:30:50 +00:00
|
|
|
}
|
2002-03-04 00:36:04 +00:00
|
|
|
/* stop recording */
|
|
|
|
if (sc->rch.active) {
|
|
|
|
nm_wr(sc, NM_RECORD_ENABLE_REG, 0, 1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nm_pci_resume(device_t dev)
|
|
|
|
{
|
|
|
|
struct sc_info *sc;
|
|
|
|
|
|
|
|
sc = pcm_getdevinfo(dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reinit audio device.
|
|
|
|
* Don't call nm_init(). It would change buftop if X ran or
|
|
|
|
* is running. This makes playing and recording buffer address
|
|
|
|
* shift but these buffers of channel layer are not changed.
|
|
|
|
* As a result of this inconsistency, periodic noise will be
|
|
|
|
* generated while playing.
|
|
|
|
*/
|
|
|
|
nm_wr(sc, 0, 0x11, 1);
|
|
|
|
nm_wr(sc, 0x214, 0, 2);
|
|
|
|
|
2000-03-20 15:30:50 +00:00
|
|
|
/* Reinit mixer */
|
2000-09-01 20:09:24 +00:00
|
|
|
if (mixer_reinit(dev) == -1) {
|
2000-03-20 15:30:50 +00:00
|
|
|
device_printf(dev, "unable to reinitialize the mixer\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
2002-03-04 00:36:04 +00:00
|
|
|
/* restart playing */
|
|
|
|
if (sc->pch.active) {
|
|
|
|
nm_wr(sc, NM_PLAYBACK_ENABLE_REG, NM_PLAYBACK_FREERUN |
|
|
|
|
NM_PLAYBACK_ENABLE_FLAG, 1);
|
|
|
|
nm_wr(sc, NM_AUDIO_MUTE_REG, 0, 2);
|
|
|
|
}
|
|
|
|
/* restart recording */
|
|
|
|
if (sc->rch.active) {
|
|
|
|
nm_wr(sc, NM_RECORD_ENABLE_REG, NM_RECORD_FREERUN |
|
|
|
|
NM_RECORD_ENABLE_FLAG, 1);
|
|
|
|
}
|
2000-03-20 15:30:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-09 08:14:11 +00:00
|
|
|
static device_method_t nm_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, nm_pci_probe),
|
|
|
|
DEVMETHOD(device_attach, nm_pci_attach),
|
2000-09-17 23:46:32 +00:00
|
|
|
DEVMETHOD(device_detach, nm_pci_detach),
|
2002-03-04 00:36:04 +00:00
|
|
|
DEVMETHOD(device_suspend, nm_pci_suspend),
|
2000-03-20 15:30:50 +00:00
|
|
|
DEVMETHOD(device_resume, nm_pci_resume),
|
2000-01-09 08:14:11 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t nm_driver = {
|
|
|
|
"pcm",
|
|
|
|
nm_methods,
|
2001-08-23 11:30:52 +00:00
|
|
|
PCM_SOFTC_SIZE,
|
2000-01-09 08:14:11 +00:00
|
|
|
};
|
|
|
|
|
2000-07-03 20:52:27 +00:00
|
|
|
DRIVER_MODULE(snd_neomagic, pci, nm_driver, pcm_devclass, 0, 0);
|
2004-07-16 04:00:08 +00:00
|
|
|
MODULE_DEPEND(snd_neomagic, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
|
2000-07-03 20:52:27 +00:00
|
|
|
MODULE_VERSION(snd_neomagic, 1);
|