2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
1999-11-22 06:07:49 +00:00
|
|
|
* Copyright (c) 1999 Seigo Tanimura
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1999-12-10 01:20:08 +00:00
|
|
|
* Portions of this source are based on cwcealdr.cpp and dhwiface.cpp in
|
|
|
|
* cwcealdr1.zip, the sample sources by Crystal Semiconductor.
|
|
|
|
* Copyright (c) 1996-1998 Crystal Semiconductor Corp.
|
|
|
|
*
|
1999-11-22 06:07:49 +00:00
|
|
|
* 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, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 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
|
|
|
|
|
1999-11-22 06:07:49 +00:00
|
|
|
#include <dev/sound/pcm/sound.h>
|
|
|
|
#include <dev/sound/pcm/ac97.h>
|
|
|
|
#include <dev/sound/chip.h>
|
|
|
|
#include <dev/sound/pci/csareg.h>
|
|
|
|
#include <dev/sound/pci/csavar.h>
|
|
|
|
|
2003-08-22 07:08:17 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
SND_DECLARE_FILE("$FreeBSD$");
|
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
/* Buffer size on dma transfer. Fixed for CS416x. */
|
|
|
|
#define CS461x_BUFFSIZE (4 * 1024)
|
|
|
|
|
|
|
|
#define GOF_PER_SEC 200
|
|
|
|
|
1999-11-22 06:07:49 +00:00
|
|
|
/* device private data */
|
|
|
|
struct csa_info;
|
|
|
|
|
|
|
|
struct csa_chinfo {
|
|
|
|
struct csa_info *parent;
|
2001-03-24 23:10:29 +00:00
|
|
|
struct pcm_channel *channel;
|
|
|
|
struct snd_dbuf *buffer;
|
1999-11-22 06:07:49 +00:00
|
|
|
int dir;
|
2001-05-30 22:38:31 +00:00
|
|
|
u_int32_t fmt, spd;
|
2000-01-03 05:26:12 +00:00
|
|
|
int dma;
|
1999-11-22 06:07:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct csa_info {
|
|
|
|
csa_res res; /* resource */
|
|
|
|
void *ih; /* Interrupt cookie */
|
|
|
|
bus_dma_tag_t parent_dmat; /* DMA tag */
|
2000-01-03 02:51:16 +00:00
|
|
|
struct csa_bridgeinfo *binfo; /* The state of the parent. */
|
2001-05-30 22:38:31 +00:00
|
|
|
struct csa_card *card;
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
int active;
|
1999-11-22 06:07:49 +00:00
|
|
|
/* Contents of board's registers */
|
|
|
|
u_long pfie;
|
|
|
|
u_long pctl;
|
|
|
|
u_long cctl;
|
|
|
|
struct csa_chinfo pch, rch;
|
2005-06-27 07:43:57 +00:00
|
|
|
u_int32_t ac97[CS461x_AC97_NUMBER_RESTORE_REGS];
|
|
|
|
u_int32_t ac97_powerdown;
|
|
|
|
u_int32_t ac97_general_purpose;
|
1999-11-22 06:07:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* prototypes */
|
|
|
|
static int csa_init(struct csa_info *);
|
|
|
|
static void csa_intr(void *);
|
|
|
|
static void csa_setplaysamplerate(csa_res *resp, u_long ulInRate);
|
|
|
|
static void csa_setcapturesamplerate(csa_res *resp, u_long ulOutRate);
|
|
|
|
static void csa_startplaydma(struct csa_info *csa);
|
|
|
|
static void csa_startcapturedma(struct csa_info *csa);
|
|
|
|
static void csa_stopplaydma(struct csa_info *csa);
|
|
|
|
static void csa_stopcapturedma(struct csa_info *csa);
|
|
|
|
static int csa_startdsp(csa_res *resp);
|
2005-06-27 07:43:57 +00:00
|
|
|
static int csa_stopdsp(csa_res *resp);
|
1999-11-22 06:07:49 +00:00
|
|
|
static int csa_allocres(struct csa_info *scp, device_t dev);
|
|
|
|
static void csa_releaseres(struct csa_info *scp, device_t dev);
|
2005-06-27 07:43:57 +00:00
|
|
|
static void csa_ac97_suspend(struct csa_info *csa);
|
|
|
|
static void csa_ac97_resume(struct csa_info *csa);
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2000-08-20 22:18:56 +00:00
|
|
|
static u_int32_t csa_playfmt[] = {
|
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_S8, 1, 0),
|
|
|
|
SND_FORMAT(AFMT_S8, 2, 0),
|
|
|
|
SND_FORMAT(AFMT_S16_LE, 1, 0),
|
|
|
|
SND_FORMAT(AFMT_S16_LE, 2, 0),
|
|
|
|
SND_FORMAT(AFMT_S16_BE, 1, 0),
|
|
|
|
SND_FORMAT(AFMT_S16_BE, 2, 0),
|
2000-08-20 22:18:56 +00:00
|
|
|
0
|
1999-11-22 06:07:49 +00:00
|
|
|
};
|
2001-03-24 23:10:29 +00:00
|
|
|
static struct pcmchan_caps csa_playcaps = {8000, 48000, csa_playfmt, 0};
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2000-08-20 22:18:56 +00:00
|
|
|
static u_int32_t csa_recfmt[] = {
|
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_S16_LE, 1, 0),
|
|
|
|
SND_FORMAT(AFMT_S16_LE, 2, 0),
|
2000-08-20 22:18:56 +00:00
|
|
|
0
|
1999-11-22 06:07:49 +00:00
|
|
|
};
|
2001-03-24 23:10:29 +00:00
|
|
|
static struct pcmchan_caps csa_reccaps = {11025, 48000, csa_recfmt, 0};
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int
|
|
|
|
csa_active(struct csa_info *csa, int run)
|
|
|
|
{
|
2005-06-27 07:43:57 +00:00
|
|
|
int old;
|
2001-05-30 22:38:31 +00:00
|
|
|
|
|
|
|
old = csa->active;
|
|
|
|
csa->active += run;
|
|
|
|
|
2005-06-27 07:43:57 +00:00
|
|
|
if ((csa->active > 1) || (csa->active < -1))
|
|
|
|
csa->active = 0;
|
|
|
|
if (csa->card->active)
|
|
|
|
return (csa->card->active(!(csa->active && old)));
|
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-11-22 06:07:49 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
2000-12-18 01:36:41 +00:00
|
|
|
/* ac97 codec */
|
1999-11-22 06:07:49 +00:00
|
|
|
|
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
csa_rdcd(kobj_t obj, void *devinfo, int regno)
|
1999-11-22 06:07:49 +00:00
|
|
|
{
|
2000-12-18 01:36:41 +00:00
|
|
|
u_int32_t data;
|
|
|
|
struct csa_info *csa = (struct csa_info *)devinfo;
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
csa_active(csa, 1);
|
2000-12-18 01:36:41 +00:00
|
|
|
if (csa_readcodec(&csa->res, regno + BA0_AC97_RESET, &data))
|
|
|
|
data = 0;
|
2001-05-30 22:38:31 +00:00
|
|
|
csa_active(csa, -1);
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
return data;
|
1999-11-22 06:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
csa_wrcd(kobj_t obj, void *devinfo, int regno, u_int32_t data)
|
1999-11-22 06:07:49 +00:00
|
|
|
{
|
2000-12-18 01:36:41 +00:00
|
|
|
struct csa_info *csa = (struct csa_info *)devinfo;
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
csa_active(csa, 1);
|
2000-12-18 01:36:41 +00:00
|
|
|
csa_writecodec(&csa->res, regno + BA0_AC97_RESET, data);
|
2001-05-30 22:38:31 +00:00
|
|
|
csa_active(csa, -1);
|
1999-11-22 06:07:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static kobj_method_t csa_ac97_methods[] = {
|
|
|
|
KOBJMETHOD(ac97_read, csa_rdcd),
|
|
|
|
KOBJMETHOD(ac97_write, csa_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(csa_ac97);
|
1999-11-22 06:07:49 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
csa_setplaysamplerate(csa_res *resp, u_long ulInRate)
|
|
|
|
{
|
|
|
|
u_long ulTemp1, ulTemp2;
|
|
|
|
u_long ulPhiIncr;
|
|
|
|
u_long ulCorrectionPerGOF, ulCorrectionPerSec;
|
|
|
|
u_long ulOutRate;
|
|
|
|
|
|
|
|
ulOutRate = 48000;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the values used to drive the actual sample rate conversion.
|
|
|
|
* The following formulas are being computed, using inline assembly
|
|
|
|
* since we need to use 64 bit arithmetic to compute the values:
|
|
|
|
*
|
|
|
|
* ulPhiIncr = floor((Fs,in * 2^26) / Fs,out)
|
|
|
|
* ulCorrectionPerGOF = floor((Fs,in * 2^26 - Fs,out * ulPhiIncr) /
|
|
|
|
* GOF_PER_SEC)
|
|
|
|
* ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -
|
|
|
|
* GOF_PER_SEC * ulCorrectionPerGOF
|
|
|
|
*
|
|
|
|
* i.e.
|
|
|
|
*
|
|
|
|
* ulPhiIncr:ulOther = dividend:remainder((Fs,in * 2^26) / Fs,out)
|
|
|
|
* ulCorrectionPerGOF:ulCorrectionPerSec =
|
|
|
|
* dividend:remainder(ulOther / GOF_PER_SEC)
|
|
|
|
*/
|
|
|
|
ulTemp1 = ulInRate << 16;
|
|
|
|
ulPhiIncr = ulTemp1 / ulOutRate;
|
|
|
|
ulTemp1 -= ulPhiIncr * ulOutRate;
|
|
|
|
ulTemp1 <<= 10;
|
|
|
|
ulPhiIncr <<= 10;
|
|
|
|
ulTemp2 = ulTemp1 / ulOutRate;
|
|
|
|
ulPhiIncr += ulTemp2;
|
|
|
|
ulTemp1 -= ulTemp2 * ulOutRate;
|
|
|
|
ulCorrectionPerGOF = ulTemp1 / GOF_PER_SEC;
|
|
|
|
ulTemp1 -= ulCorrectionPerGOF * GOF_PER_SEC;
|
|
|
|
ulCorrectionPerSec = ulTemp1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in the SampleRateConverter control block.
|
|
|
|
*/
|
|
|
|
csa_writemem(resp, BA1_PSRC, ((ulCorrectionPerSec << 16) & 0xFFFF0000) | (ulCorrectionPerGOF & 0xFFFF));
|
|
|
|
csa_writemem(resp, BA1_PPI, ulPhiIncr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
csa_setcapturesamplerate(csa_res *resp, u_long ulOutRate)
|
|
|
|
{
|
|
|
|
u_long ulPhiIncr, ulCoeffIncr, ulTemp1, ulTemp2;
|
|
|
|
u_long ulCorrectionPerGOF, ulCorrectionPerSec, ulInitialDelay;
|
|
|
|
u_long dwFrameGroupLength, dwCnt;
|
|
|
|
u_long ulInRate;
|
|
|
|
|
|
|
|
ulInRate = 48000;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can only decimate by up to a factor of 1/9th the hardware rate.
|
|
|
|
* Return an error if an attempt is made to stray outside that limit.
|
|
|
|
*/
|
|
|
|
if((ulOutRate * 9) < ulInRate)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can not capture at at rate greater than the Input Rate (48000).
|
|
|
|
* Return an error if an attempt is made to stray outside that limit.
|
|
|
|
*/
|
|
|
|
if(ulOutRate > ulInRate)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the values used to drive the actual sample rate conversion.
|
|
|
|
* The following formulas are being computed, using inline assembly
|
|
|
|
* since we need to use 64 bit arithmetic to compute the values:
|
|
|
|
*
|
|
|
|
* ulCoeffIncr = -floor((Fs,out * 2^23) / Fs,in)
|
|
|
|
* ulPhiIncr = floor((Fs,in * 2^26) / Fs,out)
|
|
|
|
* ulCorrectionPerGOF = floor((Fs,in * 2^26 - Fs,out * ulPhiIncr) /
|
|
|
|
* GOF_PER_SEC)
|
|
|
|
* ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -
|
|
|
|
* GOF_PER_SEC * ulCorrectionPerGOF
|
|
|
|
* ulInitialDelay = ceil((24 * Fs,in) / Fs,out)
|
|
|
|
*
|
|
|
|
* i.e.
|
|
|
|
*
|
|
|
|
* ulCoeffIncr = neg(dividend((Fs,out * 2^23) / Fs,in))
|
|
|
|
* ulPhiIncr:ulOther = dividend:remainder((Fs,in * 2^26) / Fs,out)
|
|
|
|
* ulCorrectionPerGOF:ulCorrectionPerSec =
|
|
|
|
* dividend:remainder(ulOther / GOF_PER_SEC)
|
|
|
|
* ulInitialDelay = dividend(((24 * Fs,in) + Fs,out - 1) / Fs,out)
|
|
|
|
*/
|
|
|
|
ulTemp1 = ulOutRate << 16;
|
|
|
|
ulCoeffIncr = ulTemp1 / ulInRate;
|
|
|
|
ulTemp1 -= ulCoeffIncr * ulInRate;
|
|
|
|
ulTemp1 <<= 7;
|
|
|
|
ulCoeffIncr <<= 7;
|
|
|
|
ulCoeffIncr += ulTemp1 / ulInRate;
|
|
|
|
ulCoeffIncr ^= 0xFFFFFFFF;
|
|
|
|
ulCoeffIncr++;
|
|
|
|
ulTemp1 = ulInRate << 16;
|
|
|
|
ulPhiIncr = ulTemp1 / ulOutRate;
|
|
|
|
ulTemp1 -= ulPhiIncr * ulOutRate;
|
|
|
|
ulTemp1 <<= 10;
|
|
|
|
ulPhiIncr <<= 10;
|
|
|
|
ulTemp2 = ulTemp1 / ulOutRate;
|
|
|
|
ulPhiIncr += ulTemp2;
|
|
|
|
ulTemp1 -= ulTemp2 * ulOutRate;
|
|
|
|
ulCorrectionPerGOF = ulTemp1 / GOF_PER_SEC;
|
|
|
|
ulTemp1 -= ulCorrectionPerGOF * GOF_PER_SEC;
|
|
|
|
ulCorrectionPerSec = ulTemp1;
|
|
|
|
ulInitialDelay = ((ulInRate * 24) + ulOutRate - 1) / ulOutRate;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in the VariDecimate control block.
|
|
|
|
*/
|
2000-01-18 17:13:43 +00:00
|
|
|
csa_writemem(resp, BA1_CSRC,
|
1999-11-22 06:07:49 +00:00
|
|
|
((ulCorrectionPerSec << 16) & 0xFFFF0000) | (ulCorrectionPerGOF & 0xFFFF));
|
|
|
|
csa_writemem(resp, BA1_CCI, ulCoeffIncr);
|
2000-01-18 17:13:43 +00:00
|
|
|
csa_writemem(resp, BA1_CD,
|
1999-11-22 06:07:49 +00:00
|
|
|
(((BA1_VARIDEC_BUF_1 + (ulInitialDelay << 2)) << 16) & 0xFFFF0000) | 0x80);
|
|
|
|
csa_writemem(resp, BA1_CPI, ulPhiIncr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out the frame group length for the write back task. Basically,
|
|
|
|
* this is just the factors of 24000 (2^6*3*5^3) that are not present in
|
|
|
|
* the output sample rate.
|
|
|
|
*/
|
|
|
|
dwFrameGroupLength = 1;
|
|
|
|
for(dwCnt = 2; dwCnt <= 64; dwCnt *= 2)
|
|
|
|
{
|
|
|
|
if(((ulOutRate / dwCnt) * dwCnt) !=
|
|
|
|
ulOutRate)
|
|
|
|
{
|
|
|
|
dwFrameGroupLength *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(((ulOutRate / 3) * 3) !=
|
|
|
|
ulOutRate)
|
|
|
|
{
|
|
|
|
dwFrameGroupLength *= 3;
|
|
|
|
}
|
|
|
|
for(dwCnt = 5; dwCnt <= 125; dwCnt *= 5)
|
|
|
|
{
|
|
|
|
if(((ulOutRate / dwCnt) * dwCnt) !=
|
|
|
|
ulOutRate)
|
|
|
|
{
|
|
|
|
dwFrameGroupLength *= 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in the WriteBack control block.
|
|
|
|
*/
|
|
|
|
csa_writemem(resp, BA1_CFG1, dwFrameGroupLength);
|
|
|
|
csa_writemem(resp, BA1_CFG2, (0x00800000 | dwFrameGroupLength));
|
|
|
|
csa_writemem(resp, BA1_CCST, 0x0000FFFF);
|
|
|
|
csa_writemem(resp, BA1_CSPB, ((65536 * ulOutRate) / 24000));
|
|
|
|
csa_writemem(resp, (BA1_CSPB + 4), 0x0000FFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
csa_startplaydma(struct csa_info *csa)
|
|
|
|
{
|
|
|
|
csa_res *resp;
|
|
|
|
u_long ul;
|
|
|
|
|
2000-01-03 05:26:12 +00:00
|
|
|
if (!csa->pch.dma) {
|
|
|
|
resp = &csa->res;
|
|
|
|
ul = csa_readmem(resp, BA1_PCTL);
|
|
|
|
ul &= 0x0000ffff;
|
|
|
|
csa_writemem(resp, BA1_PCTL, ul | csa->pctl);
|
|
|
|
csa_writemem(resp, BA1_PVOL, 0x80008000);
|
|
|
|
csa->pch.dma = 1;
|
|
|
|
}
|
1999-11-22 06:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
csa_startcapturedma(struct csa_info *csa)
|
|
|
|
{
|
|
|
|
csa_res *resp;
|
|
|
|
u_long ul;
|
|
|
|
|
2000-01-03 05:26:12 +00:00
|
|
|
if (!csa->rch.dma) {
|
|
|
|
resp = &csa->res;
|
|
|
|
ul = csa_readmem(resp, BA1_CCTL);
|
|
|
|
ul &= 0xffff0000;
|
|
|
|
csa_writemem(resp, BA1_CCTL, ul | csa->cctl);
|
|
|
|
csa_writemem(resp, BA1_CVOL, 0x80008000);
|
|
|
|
csa->rch.dma = 1;
|
|
|
|
}
|
1999-11-22 06:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
csa_stopplaydma(struct csa_info *csa)
|
|
|
|
{
|
|
|
|
csa_res *resp;
|
|
|
|
u_long ul;
|
|
|
|
|
2000-01-03 05:26:12 +00:00
|
|
|
if (csa->pch.dma) {
|
|
|
|
resp = &csa->res;
|
|
|
|
ul = csa_readmem(resp, BA1_PCTL);
|
|
|
|
csa->pctl = ul & 0xffff0000;
|
|
|
|
csa_writemem(resp, BA1_PCTL, ul & 0x0000ffff);
|
|
|
|
csa_writemem(resp, BA1_PVOL, 0xffffffff);
|
|
|
|
csa->pch.dma = 0;
|
2000-01-23 07:04:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The bitwise pointer of the serial FIFO in the DSP
|
|
|
|
* seems to make an error upon starting or stopping the
|
|
|
|
* DSP. Clear the FIFO and correct the pointer if we
|
|
|
|
* are not capturing.
|
|
|
|
*/
|
|
|
|
if (!csa->rch.dma) {
|
|
|
|
csa_clearserialfifos(resp);
|
|
|
|
csa_writeio(resp, BA0_SERBSP, 0);
|
|
|
|
}
|
2000-01-03 05:26:12 +00:00
|
|
|
}
|
1999-11-22 06:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
csa_stopcapturedma(struct csa_info *csa)
|
|
|
|
{
|
|
|
|
csa_res *resp;
|
|
|
|
u_long ul;
|
|
|
|
|
2000-01-03 05:26:12 +00:00
|
|
|
if (csa->rch.dma) {
|
|
|
|
resp = &csa->res;
|
|
|
|
ul = csa_readmem(resp, BA1_CCTL);
|
|
|
|
csa->cctl = ul & 0x0000ffff;
|
|
|
|
csa_writemem(resp, BA1_CCTL, ul & 0xffff0000);
|
|
|
|
csa_writemem(resp, BA1_CVOL, 0xffffffff);
|
|
|
|
csa->rch.dma = 0;
|
2000-01-23 07:04:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The bitwise pointer of the serial FIFO in the DSP
|
|
|
|
* seems to make an error upon starting or stopping the
|
|
|
|
* DSP. Clear the FIFO and correct the pointer if we
|
|
|
|
* are not playing.
|
|
|
|
*/
|
|
|
|
if (!csa->pch.dma) {
|
|
|
|
csa_clearserialfifos(resp);
|
|
|
|
csa_writeio(resp, BA0_SERBSP, 0);
|
|
|
|
}
|
2000-01-03 05:26:12 +00:00
|
|
|
}
|
1999-11-22 06:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
csa_startdsp(csa_res *resp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u_long ul;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the frame timer to reflect the number of cycles per frame.
|
|
|
|
*/
|
|
|
|
csa_writemem(resp, BA1_FRMT, 0xadf);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn on the run, run at frame, and DMA enable bits in the local copy of
|
|
|
|
* the SP control register.
|
|
|
|
*/
|
|
|
|
csa_writemem(resp, BA1_SPCR, SPCR_RUN | SPCR_RUNFR | SPCR_DRQEN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until the run at frame bit resets itself in the SP control
|
|
|
|
* register.
|
|
|
|
*/
|
|
|
|
ul = 0;
|
|
|
|
for (i = 0 ; i < 25 ; i++) {
|
|
|
|
/*
|
|
|
|
* Wait a little bit, so we don't issue PCI reads too frequently.
|
|
|
|
*/
|
2001-05-30 22:38:31 +00:00
|
|
|
DELAY(50);
|
1999-11-22 06:07:49 +00:00
|
|
|
/*
|
|
|
|
* Fetch the current value of the SP status register.
|
|
|
|
*/
|
|
|
|
ul = csa_readmem(resp, BA1_SPCR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the run at frame bit has reset, then stop waiting.
|
|
|
|
*/
|
|
|
|
if((ul & SPCR_RUNFR) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the run at frame bit never reset, then return an error.
|
|
|
|
*/
|
|
|
|
if((ul & SPCR_RUNFR) != 0)
|
|
|
|
return (EAGAIN);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-06-27 07:43:57 +00:00
|
|
|
static int
|
|
|
|
csa_stopdsp(csa_res *resp)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Turn off the run, run at frame, and DMA enable bits in
|
|
|
|
* the local copy of the SP control register.
|
|
|
|
*/
|
|
|
|
csa_writemem(resp, BA1_SPCR, 0);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
static int
|
|
|
|
csa_setupchan(struct csa_chinfo *ch)
|
|
|
|
{
|
|
|
|
struct csa_info *csa = ch->parent;
|
|
|
|
csa_res *resp = &csa->res;
|
|
|
|
u_long pdtc, tmp;
|
|
|
|
|
|
|
|
if (ch->dir == PCMDIR_PLAY) {
|
|
|
|
/* direction */
|
2003-02-20 17:31:12 +00:00
|
|
|
csa_writemem(resp, BA1_PBA, sndbuf_getbufaddr(ch->buffer));
|
2001-05-30 22:38:31 +00:00
|
|
|
|
|
|
|
/* format */
|
|
|
|
csa->pfie = csa_readmem(resp, BA1_PFIE) & ~0x0000f03f;
|
|
|
|
if (!(ch->fmt & AFMT_SIGNED))
|
|
|
|
csa->pfie |= 0x8000;
|
|
|
|
if (ch->fmt & AFMT_BIGENDIAN)
|
|
|
|
csa->pfie |= 0x4000;
|
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) < 2)
|
2001-05-30 22:38:31 +00:00
|
|
|
csa->pfie |= 0x2000;
|
|
|
|
if (ch->fmt & AFMT_8BIT)
|
|
|
|
csa->pfie |= 0x1000;
|
|
|
|
csa_writemem(resp, BA1_PFIE, csa->pfie);
|
|
|
|
|
|
|
|
tmp = 4;
|
|
|
|
if (ch->fmt & AFMT_16BIT)
|
|
|
|
tmp <<= 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)
|
2001-05-30 22:38:31 +00:00
|
|
|
tmp <<= 1;
|
|
|
|
tmp--;
|
|
|
|
|
|
|
|
pdtc = csa_readmem(resp, BA1_PDTC) & ~0x000001ff;
|
|
|
|
pdtc |= tmp;
|
|
|
|
csa_writemem(resp, BA1_PDTC, pdtc);
|
|
|
|
|
|
|
|
/* rate */
|
|
|
|
csa_setplaysamplerate(resp, ch->spd);
|
|
|
|
} else if (ch->dir == PCMDIR_REC) {
|
|
|
|
/* direction */
|
2003-02-20 17:31:12 +00:00
|
|
|
csa_writemem(resp, BA1_CBA, sndbuf_getbufaddr(ch->buffer));
|
2001-05-30 22:38:31 +00:00
|
|
|
|
|
|
|
/* format */
|
|
|
|
csa_writemem(resp, BA1_CIE, (csa_readmem(resp, BA1_CIE) & ~0x0000003f) | 0x00000001);
|
|
|
|
|
|
|
|
/* rate */
|
|
|
|
csa_setcapturesamplerate(resp, ch->spd);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* channel interface */
|
|
|
|
|
|
|
|
static void *
|
2001-03-24 23:10:29 +00:00
|
|
|
csachan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
|
2000-12-18 01:36:41 +00:00
|
|
|
{
|
|
|
|
struct csa_info *csa = devinfo;
|
|
|
|
struct csa_chinfo *ch = (dir == PCMDIR_PLAY)? &csa->pch : &csa->rch;
|
|
|
|
|
|
|
|
ch->parent = csa;
|
|
|
|
ch->channel = c;
|
|
|
|
ch->buffer = b;
|
2001-05-30 22:38:31 +00:00
|
|
|
ch->dir = dir;
|
2007-04-18 18:26:41 +00:00
|
|
|
if (sndbuf_alloc(ch->buffer, csa->parent_dmat, 0, CS461x_BUFFSIZE) != 0)
|
2004-10-13 05:45:16 +00:00
|
|
|
return NULL;
|
2000-12-18 01:36:41 +00:00
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
csachan_setformat(kobj_t obj, void *data, u_int32_t format)
|
|
|
|
{
|
|
|
|
struct csa_chinfo *ch = data;
|
|
|
|
|
|
|
|
ch->fmt = format;
|
|
|
|
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
|
|
|
csachan_setspeed(kobj_t obj, void *data, u_int32_t speed)
|
|
|
|
{
|
|
|
|
struct csa_chinfo *ch = data;
|
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
ch->spd = speed;
|
|
|
|
return ch->spd; /* XXX calc real speed */
|
2000-12-18 01:36:41 +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
|
|
|
csachan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
|
|
|
|
{
|
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
|
|
|
return CS461x_BUFFSIZE / 2;
|
2000-12-18 01:36:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
csachan_trigger(kobj_t obj, void *data, int go)
|
|
|
|
{
|
|
|
|
struct csa_chinfo *ch = data;
|
|
|
|
struct csa_info *csa = ch->parent;
|
|
|
|
|
2007-06-11 00:49:46 +00:00
|
|
|
if (!PCMTRIG_COMMON(go))
|
2000-12-18 01:36:41 +00:00
|
|
|
return 0;
|
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
if (go == PCMTRIG_START) {
|
|
|
|
csa_active(csa, 1);
|
|
|
|
csa_setupchan(ch);
|
|
|
|
if (ch->dir == PCMDIR_PLAY)
|
2000-12-18 01:36:41 +00:00
|
|
|
csa_startplaydma(csa);
|
|
|
|
else
|
|
|
|
csa_startcapturedma(csa);
|
2001-05-30 22:38:31 +00:00
|
|
|
} else {
|
|
|
|
if (ch->dir == PCMDIR_PLAY)
|
|
|
|
csa_stopplaydma(csa);
|
2000-12-18 01:36:41 +00:00
|
|
|
else
|
|
|
|
csa_stopcapturedma(csa);
|
2001-05-30 22:38:31 +00:00
|
|
|
csa_active(csa, -1);
|
2000-12-18 01:36:41 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
csachan_getptr(kobj_t obj, void *data)
|
1999-11-22 06:07:49 +00:00
|
|
|
{
|
|
|
|
struct csa_chinfo *ch = data;
|
|
|
|
struct csa_info *csa = ch->parent;
|
|
|
|
csa_res *resp;
|
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
|
|
|
u_int32_t ptr;
|
1999-11-22 06:07:49 +00:00
|
|
|
|
|
|
|
resp = &csa->res;
|
|
|
|
|
|
|
|
if (ch->dir == PCMDIR_PLAY) {
|
2003-02-20 17:31:12 +00:00
|
|
|
ptr = csa_readmem(resp, BA1_PBA) - sndbuf_getbufaddr(ch->buffer);
|
1999-11-22 06:07:49 +00:00
|
|
|
if ((ch->fmt & AFMT_U8) != 0 || (ch->fmt & AFMT_S8) != 0)
|
|
|
|
ptr >>= 1;
|
|
|
|
} else {
|
2003-02-20 17:31:12 +00:00
|
|
|
ptr = csa_readmem(resp, BA1_CBA) - sndbuf_getbufaddr(ch->buffer);
|
1999-11-22 06:07:49 +00:00
|
|
|
if ((ch->fmt & AFMT_U8) != 0 || (ch->fmt & AFMT_S8) != 0)
|
|
|
|
ptr >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ptr);
|
|
|
|
}
|
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
static struct pcmchan_caps *
|
2000-12-18 01:36:41 +00:00
|
|
|
csachan_getcaps(kobj_t obj, void *data)
|
1999-11-22 06:07:49 +00:00
|
|
|
{
|
|
|
|
struct csa_chinfo *ch = data;
|
|
|
|
return (ch->dir == PCMDIR_PLAY)? &csa_playcaps : &csa_reccaps;
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static kobj_method_t csachan_methods[] = {
|
|
|
|
KOBJMETHOD(channel_init, csachan_init),
|
|
|
|
KOBJMETHOD(channel_setformat, csachan_setformat),
|
|
|
|
KOBJMETHOD(channel_setspeed, csachan_setspeed),
|
|
|
|
KOBJMETHOD(channel_setblocksize, csachan_setblocksize),
|
|
|
|
KOBJMETHOD(channel_trigger, csachan_trigger),
|
|
|
|
KOBJMETHOD(channel_getptr, csachan_getptr),
|
|
|
|
KOBJMETHOD(channel_getcaps, csachan_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(csachan);
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
1999-11-22 06:07:49 +00:00
|
|
|
/* The interrupt handler */
|
|
|
|
static void
|
2001-05-30 22:38:31 +00:00
|
|
|
csa_intr(void *p)
|
1999-11-22 06:07:49 +00:00
|
|
|
{
|
|
|
|
struct csa_info *csa = p;
|
|
|
|
|
2000-01-03 02:51:16 +00:00
|
|
|
if ((csa->binfo->hisr & HISR_VC0) != 0)
|
1999-11-22 06:07:49 +00:00
|
|
|
chn_intr(csa->pch.channel);
|
2000-01-03 02:51:16 +00:00
|
|
|
if ((csa->binfo->hisr & HISR_VC1) != 0)
|
1999-11-22 06:07:49 +00:00
|
|
|
chn_intr(csa->rch.channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe and attach the card
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
csa_init(struct csa_info *csa)
|
|
|
|
{
|
|
|
|
csa_res *resp;
|
|
|
|
|
|
|
|
resp = &csa->res;
|
|
|
|
|
|
|
|
csa->pfie = 0;
|
|
|
|
csa_stopplaydma(csa);
|
|
|
|
csa_stopcapturedma(csa);
|
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
if (csa_startdsp(resp))
|
|
|
|
return (1);
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
/* Crank up the power on the DAC and ADC. */
|
1999-11-22 06:07:49 +00:00
|
|
|
csa_setplaysamplerate(resp, 8000);
|
|
|
|
csa_setcapturesamplerate(resp, 8000);
|
2005-09-11 14:15:05 +00:00
|
|
|
/* Set defaults */
|
|
|
|
csa_writeio(resp, BA0_EGPIODR, EGPIODR_GPOE0);
|
|
|
|
csa_writeio(resp, BA0_EGPIOPTR, EGPIOPTR_GPPT0);
|
|
|
|
/* Power up amplifier */
|
|
|
|
csa_writeio(resp, BA0_EGPIODR, csa_readio(resp, BA0_EGPIODR) |
|
|
|
|
EGPIODR_GPOE2);
|
|
|
|
csa_writeio(resp, BA0_EGPIOPTR, csa_readio(resp, BA0_EGPIOPTR) |
|
|
|
|
EGPIOPTR_GPPT2);
|
1999-11-22 06:07:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocates resources. */
|
|
|
|
static int
|
|
|
|
csa_allocres(struct csa_info *csa, device_t dev)
|
|
|
|
{
|
|
|
|
csa_res *resp;
|
|
|
|
|
|
|
|
resp = &csa->res;
|
|
|
|
if (resp->io == NULL) {
|
2004-03-17 17:50:55 +00:00
|
|
|
resp->io = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
|
|
|
&resp->io_rid, RF_ACTIVE);
|
1999-11-22 06:07:49 +00:00
|
|
|
if (resp->io == NULL)
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (resp->mem == NULL) {
|
2004-03-17 17:50:55 +00:00
|
|
|
resp->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
|
|
|
&resp->mem_rid, RF_ACTIVE);
|
1999-11-22 06:07:49 +00:00
|
|
|
if (resp->mem == NULL)
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (resp->irq == NULL) {
|
2004-03-17 17:50:55 +00:00
|
|
|
resp->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
|
|
|
|
&resp->irq_rid, RF_ACTIVE | RF_SHAREABLE);
|
1999-11-22 06:07:49 +00:00
|
|
|
if (resp->irq == NULL)
|
|
|
|
return (1);
|
|
|
|
}
|
2007-02-23 13:47:34 +00:00
|
|
|
if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(dev),
|
|
|
|
/*alignment*/CS461x_BUFFSIZE,
|
|
|
|
/*boundary*/CS461x_BUFFSIZE,
|
1999-11-22 06:07:49 +00:00
|
|
|
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
/*highaddr*/BUS_SPACE_MAXADDR,
|
|
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
|
|
|
/*maxsize*/CS461x_BUFFSIZE, /*nsegments*/1, /*maxsegz*/0x3ffff,
|
2003-07-01 15:52:06 +00:00
|
|
|
/*flags*/0, /*lockfunc*/busdma_lock_mutex,
|
|
|
|
/*lockarg*/&Giant, &csa->parent_dmat) != 0)
|
1999-11-22 06:07:49 +00:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Releases resources. */
|
|
|
|
static void
|
|
|
|
csa_releaseres(struct csa_info *csa, device_t dev)
|
|
|
|
{
|
|
|
|
csa_res *resp;
|
|
|
|
|
2006-02-05 17:33:18 +00:00
|
|
|
KASSERT(csa != NULL, ("called with bogus resource structure"));
|
|
|
|
|
1999-11-22 06:07:49 +00:00
|
|
|
resp = &csa->res;
|
|
|
|
if (resp->irq != NULL) {
|
2000-09-09 19:21:04 +00:00
|
|
|
if (csa->ih)
|
|
|
|
bus_teardown_intr(dev, resp->irq, csa->ih);
|
1999-11-22 06:07:49 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, resp->irq_rid, resp->irq);
|
|
|
|
resp->irq = NULL;
|
|
|
|
}
|
|
|
|
if (resp->io != NULL) {
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, resp->io_rid, resp->io);
|
|
|
|
resp->io = NULL;
|
|
|
|
}
|
|
|
|
if (resp->mem != NULL) {
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, resp->mem_rid, resp->mem);
|
|
|
|
resp->mem = NULL;
|
|
|
|
}
|
2000-09-09 19:21:04 +00:00
|
|
|
if (csa->parent_dmat != NULL) {
|
|
|
|
bus_dma_tag_destroy(csa->parent_dmat);
|
|
|
|
csa->parent_dmat = NULL;
|
|
|
|
}
|
2006-02-05 17:33:18 +00:00
|
|
|
|
|
|
|
free(csa, M_DEVBUF);
|
1999-11-22 06:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pcmcsa_probe(device_t dev)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
struct sndcard_func *func;
|
|
|
|
|
|
|
|
/* The parent device has already been probed. */
|
|
|
|
|
|
|
|
func = device_get_ivars(dev);
|
|
|
|
if (func == NULL || func->func != SCF_PCM)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
s = "CS461x PCM Audio";
|
|
|
|
|
|
|
|
device_set_desc(dev, s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pcmcsa_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct csa_info *csa;
|
|
|
|
csa_res *resp;
|
|
|
|
int unit;
|
|
|
|
char status[SND_STATUSLEN];
|
|
|
|
struct ac97_info *codec;
|
2000-01-03 02:51:16 +00:00
|
|
|
struct sndcard_func *func;
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2007-06-17 06:10:43 +00:00
|
|
|
csa = malloc(sizeof(*csa), M_DEVBUF, M_WAITOK | M_ZERO);
|
1999-11-22 06:07:49 +00:00
|
|
|
unit = device_get_unit(dev);
|
2000-01-03 02:51:16 +00:00
|
|
|
func = device_get_ivars(dev);
|
|
|
|
csa->binfo = func->varinfo;
|
2000-01-03 05:26:12 +00:00
|
|
|
/*
|
|
|
|
* Fake the status of DMA so that the initial value of
|
|
|
|
* PCTL and CCTL can be stored into csa->pctl and csa->cctl,
|
|
|
|
* respectively.
|
|
|
|
*/
|
|
|
|
csa->pch.dma = csa->rch.dma = 1;
|
2001-05-30 22:38:31 +00:00
|
|
|
csa->active = 0;
|
|
|
|
csa->card = csa->binfo->card;
|
1999-11-22 06:07:49 +00:00
|
|
|
|
|
|
|
/* Allocate the resources. */
|
|
|
|
resp = &csa->res;
|
2003-09-02 17:30:40 +00:00
|
|
|
resp->io_rid = PCIR_BAR(0);
|
|
|
|
resp->mem_rid = PCIR_BAR(1);
|
1999-11-22 06:07:49 +00:00
|
|
|
resp->irq_rid = 0;
|
|
|
|
if (csa_allocres(csa, dev)) {
|
|
|
|
csa_releaseres(csa, dev);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2001-05-30 22:38:31 +00:00
|
|
|
csa_active(csa, 1);
|
1999-11-22 06:07:49 +00:00
|
|
|
if (csa_init(csa)) {
|
|
|
|
csa_releaseres(csa, dev);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2000-12-18 01:36:41 +00:00
|
|
|
codec = AC97_CREATE(dev, csa, csa_ac97);
|
2000-09-09 19:21:04 +00:00
|
|
|
if (codec == NULL) {
|
|
|
|
csa_releaseres(csa, dev);
|
1999-11-22 06:07:49 +00:00
|
|
|
return (ENXIO);
|
2000-09-09 19:21:04 +00:00
|
|
|
}
|
2001-06-23 18:00:06 +00:00
|
|
|
if (csa->card->inv_eapd)
|
|
|
|
ac97_setflags(codec, AC97_F_EAPD_INV);
|
2000-12-18 01:36:41 +00:00
|
|
|
if (mixer_init(dev, ac97_getmixerclass(), codec) == -1) {
|
2000-09-09 19:21:04 +00:00
|
|
|
ac97_destroy(codec);
|
|
|
|
csa_releaseres(csa, dev);
|
2000-04-01 22:24:03 +00:00
|
|
|
return (ENXIO);
|
2000-09-09 19:21:04 +00:00
|
|
|
}
|
1999-11-22 06:07:49 +00:00
|
|
|
|
2004-03-06 15:52:42 +00:00
|
|
|
snprintf(status, SND_STATUSLEN, "at irq %ld %s",
|
|
|
|
rman_get_start(resp->irq),PCM_KLDSTRING(snd_csa));
|
1999-11-22 06:07:49 +00:00
|
|
|
|
|
|
|
/* Enable interrupt. */
|
2004-04-14 14:57:49 +00:00
|
|
|
if (snd_setup_intr(dev, resp->irq, 0, csa_intr, csa, &csa->ih)) {
|
2000-09-09 19:21:04 +00:00
|
|
|
ac97_destroy(codec);
|
1999-11-22 06:07:49 +00:00
|
|
|
csa_releaseres(csa, dev);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
csa_writemem(resp, BA1_PFIE, csa_readmem(resp, BA1_PFIE) & ~0x0000f03f);
|
|
|
|
csa_writemem(resp, BA1_CIE, (csa_readmem(resp, BA1_CIE) & ~0x0000003f) | 0x00000001);
|
2001-05-30 22:38:31 +00:00
|
|
|
csa_active(csa, -1);
|
1999-11-22 06:07:49 +00:00
|
|
|
|
|
|
|
if (pcm_register(dev, csa, 1, 1)) {
|
2000-09-09 19:21:04 +00:00
|
|
|
ac97_destroy(codec);
|
1999-11-22 06:07:49 +00:00
|
|
|
csa_releaseres(csa, dev);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2000-12-18 01:36:41 +00:00
|
|
|
pcm_addchan(dev, PCMDIR_REC, &csachan_class, csa);
|
|
|
|
pcm_addchan(dev, PCMDIR_PLAY, &csachan_class, csa);
|
1999-11-22 06:07:49 +00:00
|
|
|
pcm_setstatus(dev, status);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-09-09 19:21:04 +00:00
|
|
|
static int
|
|
|
|
pcmcsa_detach(device_t dev)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct csa_info *csa;
|
|
|
|
|
|
|
|
r = pcm_unregister(dev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
csa = pcm_getdevinfo(dev);
|
|
|
|
csa_releaseres(csa, dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-27 07:43:57 +00:00
|
|
|
static void
|
|
|
|
csa_ac97_suspend(struct csa_info *csa)
|
|
|
|
{
|
|
|
|
int count, i;
|
|
|
|
uint32_t tmp;
|
|
|
|
|
|
|
|
for (count = 0x2, i=0;
|
|
|
|
(count <= CS461x_AC97_HIGHESTREGTORESTORE) &&
|
|
|
|
(i < CS461x_AC97_NUMBER_RESTORE_REGS);
|
|
|
|
count += 2, i++)
|
|
|
|
csa_readcodec(&csa->res, BA0_AC97_RESET + count, &csa->ac97[i]);
|
|
|
|
|
|
|
|
/* mute the outputs */
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_MASTER_VOLUME, 0x8000);
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_HEADPHONE_VOLUME, 0x8000);
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_MASTER_VOLUME_MONO, 0x8000);
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_PCM_OUT_VOLUME, 0x8000);
|
|
|
|
/* save the registers that cause pops */
|
|
|
|
csa_readcodec(&csa->res, BA0_AC97_POWERDOWN, &csa->ac97_powerdown);
|
|
|
|
csa_readcodec(&csa->res, BA0_AC97_GENERAL_PURPOSE,
|
|
|
|
&csa->ac97_general_purpose);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* And power down everything on the AC97 codec. Well, for now,
|
|
|
|
* only power down the DAC/ADC and MIXER VREFON components.
|
|
|
|
* trouble with removing VREF.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* MIXVON */
|
|
|
|
csa_readcodec(&csa->res, BA0_AC97_POWERDOWN, &tmp);
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_POWERDOWN,
|
|
|
|
tmp | CS_AC97_POWER_CONTROL_MIXVON);
|
|
|
|
/* ADC */
|
|
|
|
csa_readcodec(&csa->res, BA0_AC97_POWERDOWN, &tmp);
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_POWERDOWN,
|
|
|
|
tmp | CS_AC97_POWER_CONTROL_ADC);
|
|
|
|
/* DAC */
|
|
|
|
csa_readcodec(&csa->res, BA0_AC97_POWERDOWN, &tmp);
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_POWERDOWN,
|
|
|
|
tmp | CS_AC97_POWER_CONTROL_DAC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
csa_ac97_resume(struct csa_info *csa)
|
|
|
|
{
|
|
|
|
int count, i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, we restore the state of the general purpose register. This
|
|
|
|
* contains the mic select (mic1 or mic2) and if we restore this after
|
|
|
|
* we restore the mic volume/boost state and mic2 was selected at
|
|
|
|
* suspend time, we will end up with a brief period of time where mic1
|
|
|
|
* is selected with the volume/boost settings for mic2, causing
|
|
|
|
* acoustic feedback. So we restore the general purpose register
|
|
|
|
* first, thereby getting the correct mic selected before we restore
|
|
|
|
* the mic volume/boost.
|
|
|
|
*/
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_GENERAL_PURPOSE,
|
|
|
|
csa->ac97_general_purpose);
|
|
|
|
/*
|
|
|
|
* Now, while the outputs are still muted, restore the state of power
|
|
|
|
* on the AC97 part.
|
|
|
|
*/
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_POWERDOWN, csa->ac97_powerdown);
|
|
|
|
/*
|
|
|
|
* Restore just the first set of registers, from register number
|
|
|
|
* 0x02 to the register number that ulHighestRegToRestore specifies.
|
|
|
|
*/
|
|
|
|
for (count = 0x2, i=0;
|
|
|
|
(count <= CS461x_AC97_HIGHESTREGTORESTORE) &&
|
|
|
|
(i < CS461x_AC97_NUMBER_RESTORE_REGS);
|
|
|
|
count += 2, i++)
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_RESET + count, csa->ac97[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pcmcsa_suspend(device_t dev)
|
|
|
|
{
|
|
|
|
struct csa_info *csa;
|
|
|
|
csa_res *resp;
|
|
|
|
|
|
|
|
csa = pcm_getdevinfo(dev);
|
|
|
|
resp = &csa->res;
|
|
|
|
|
|
|
|
csa_active(csa, 1);
|
|
|
|
|
|
|
|
/* playback interrupt disable */
|
|
|
|
csa_writemem(resp, BA1_PFIE,
|
|
|
|
(csa_readmem(resp, BA1_PFIE) & ~0x0000f03f) | 0x00000010);
|
|
|
|
/* capture interrupt disable */
|
|
|
|
csa_writemem(resp, BA1_CIE,
|
|
|
|
(csa_readmem(resp, BA1_CIE) & ~0x0000003f) | 0x00000011);
|
|
|
|
csa_stopplaydma(csa);
|
|
|
|
csa_stopcapturedma(csa);
|
|
|
|
|
|
|
|
csa_ac97_suspend(csa);
|
|
|
|
|
|
|
|
csa_resetdsp(resp);
|
|
|
|
|
|
|
|
csa_stopdsp(resp);
|
|
|
|
/*
|
|
|
|
* Power down the DAC and ADC. For now leave the other areas on.
|
|
|
|
*/
|
|
|
|
csa_writecodec(&csa->res, BA0_AC97_POWERDOWN, 0x300);
|
|
|
|
/*
|
|
|
|
* Power down the PLL.
|
|
|
|
*/
|
|
|
|
csa_writemem(resp, BA0_CLKCR1, 0);
|
|
|
|
/*
|
|
|
|
* Turn off the Processor by turning off the software clock
|
|
|
|
* enable flag in the clock control register.
|
|
|
|
*/
|
|
|
|
csa_writemem(resp, BA0_CLKCR1,
|
|
|
|
csa_readmem(resp, BA0_CLKCR1) & ~CLKCR1_SWCE);
|
|
|
|
|
|
|
|
csa_active(csa, -1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pcmcsa_resume(device_t dev)
|
|
|
|
{
|
|
|
|
struct csa_info *csa;
|
|
|
|
csa_res *resp;
|
|
|
|
|
|
|
|
csa = pcm_getdevinfo(dev);
|
|
|
|
resp = &csa->res;
|
|
|
|
|
|
|
|
csa_active(csa, 1);
|
|
|
|
|
|
|
|
/* cs_hardware_init */
|
|
|
|
csa_stopplaydma(csa);
|
|
|
|
csa_stopcapturedma(csa);
|
|
|
|
csa_ac97_resume(csa);
|
|
|
|
if (csa_startdsp(resp))
|
|
|
|
return (ENXIO);
|
|
|
|
/* Enable interrupts on the part. */
|
|
|
|
if ((csa_readio(resp, BA0_HISR) & HISR_INTENA) == 0)
|
|
|
|
csa_writeio(resp, BA0_HICR, HICR_IEV | HICR_CHGM);
|
|
|
|
/* playback interrupt enable */
|
|
|
|
csa_writemem(resp, BA1_PFIE, csa_readmem(resp, BA1_PFIE) & ~0x0000f03f);
|
|
|
|
/* capture interrupt enable */
|
|
|
|
csa_writemem(resp, BA1_CIE,
|
|
|
|
(csa_readmem(resp, BA1_CIE) & ~0x0000003f) | 0x00000001);
|
|
|
|
/* cs_restart_part */
|
|
|
|
csa_setupchan(&csa->pch);
|
|
|
|
csa_startplaydma(csa);
|
|
|
|
csa_setupchan(&csa->rch);
|
|
|
|
csa_startcapturedma(csa);
|
|
|
|
|
|
|
|
csa_active(csa, -1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-11-22 06:07:49 +00:00
|
|
|
static device_method_t pcmcsa_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe , pcmcsa_probe ),
|
|
|
|
DEVMETHOD(device_attach, pcmcsa_attach),
|
2000-09-09 19:21:04 +00:00
|
|
|
DEVMETHOD(device_detach, pcmcsa_detach),
|
2005-06-27 07:43:57 +00:00
|
|
|
DEVMETHOD(device_suspend, pcmcsa_suspend),
|
|
|
|
DEVMETHOD(device_resume, pcmcsa_resume),
|
1999-11-22 06:07:49 +00:00
|
|
|
|
|
|
|
{ 0, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t pcmcsa_driver = {
|
|
|
|
"pcm",
|
|
|
|
pcmcsa_methods,
|
2001-08-23 11:30:52 +00:00
|
|
|
PCM_SOFTC_SIZE,
|
1999-11-22 06:07:49 +00:00
|
|
|
};
|
|
|
|
|
2000-07-03 20:52:27 +00:00
|
|
|
DRIVER_MODULE(snd_csapcm, csa, pcmcsa_driver, pcm_devclass, 0, 0);
|
2004-07-16 04:00:08 +00:00
|
|
|
MODULE_DEPEND(snd_csapcm, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
|
2000-07-03 20:52:27 +00:00
|
|
|
MODULE_DEPEND(snd_csapcm, snd_csa, 1, 1, 1);
|
|
|
|
MODULE_VERSION(snd_csapcm, 1);
|