2007-09-02 04:48:52 +04:00
|
|
|
/* $NetBSD: auich.c,v 1.118 2007/09/02 00:48:52 xtraeme Exp $ */
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
/*-
|
2005-03-12 01:29:16 +03:00
|
|
|
* Copyright (c) 2000, 2004, 2005 The NetBSD Foundation, Inc.
|
2000-11-28 08:12:29 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2004-10-31 23:15:16 +03:00
|
|
|
* by Jason R. Thorpe and by Charles M. Hannum.
|
2000-11-28 08:12:29 +03: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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 Michael Shalayeff
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 HIS RELATIVES 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 MIND, 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.
|
|
|
|
*
|
|
|
|
* from OpenBSD: ich.c,v 1.3 2000/08/11 06:17:18 mickey Exp
|
|
|
|
*/
|
|
|
|
|
2002-08-07 14:31:09 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 Katsurajima Naoto <raven@katsurajima.seya.yokohama.jp>
|
|
|
|
* Copyright (c) 2001 Cameron Grant <cg@freebsd.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2005-02-27 03:26:58 +03:00
|
|
|
* auich_calibrate() was from FreeBSD: ich.c,v 1.22 2002/06/27 22:36:01 scottl Exp
|
2002-08-07 14:31:09 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-08-07 20:12:57 +04:00
|
|
|
/* #define AUICH_DEBUG */
|
2000-11-28 08:12:29 +03:00
|
|
|
/*
|
|
|
|
* AC'97 audio found on Intel 810/820/440MX chipsets.
|
|
|
|
* http://developer.intel.com/design/chipsets/datashts/290655.htm
|
|
|
|
* http://developer.intel.com/design/chipsets/manuals/298028.htm
|
2002-08-07 14:31:09 +04:00
|
|
|
* ICH3:http://www.intel.com/design/chipsets/datashts/290716.htm
|
|
|
|
* ICH4:http://www.intel.com/design/chipsets/datashts/290744.htm
|
2003-09-28 17:37:19 +04:00
|
|
|
* ICH5:http://www.intel.com/design/chipsets/datashts/252516.htm
|
2003-10-30 22:30:26 +03:00
|
|
|
* AMD8111:
|
|
|
|
* http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24674.pdf
|
|
|
|
* http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25720.pdf
|
2000-11-28 08:12:29 +03:00
|
|
|
*
|
|
|
|
* TODO:
|
2002-10-11 08:11:28 +04:00
|
|
|
* - Add support for the dedicated microphone input.
|
2003-01-21 19:05:21 +03:00
|
|
|
*
|
|
|
|
* NOTE:
|
|
|
|
* - The 440MX B-stepping at running 100MHz has a hardware erratum.
|
|
|
|
* It causes PCI master abort and hangups until cold reboot.
|
|
|
|
* http://www.intel.com/design/chipsets/specupdt/245051.htm
|
2000-11-28 08:12:29 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 10:48:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-09-02 04:48:52 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: auich.c,v 1.118 2007/09/02 00:48:52 xtraeme Exp $");
|
2001-11-13 10:48:40 +03:00
|
|
|
|
2000-11-28 08:12:29 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/proc.h>
|
2004-10-27 17:26:43 +04:00
|
|
|
#include <sys/sysctl.h>
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h> /* for PAGE_SIZE */
|
|
|
|
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/auichreg.h>
|
|
|
|
|
|
|
|
#include <sys/audioio.h>
|
|
|
|
#include <dev/audio_if.h>
|
|
|
|
#include <dev/mulaw.h>
|
|
|
|
#include <dev/auconv.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
2000-11-28 19:57:16 +03:00
|
|
|
#include <dev/ic/ac97reg.h>
|
2000-11-28 08:12:29 +03:00
|
|
|
#include <dev/ic/ac97var.h>
|
|
|
|
|
|
|
|
struct auich_dma {
|
|
|
|
bus_dmamap_t map;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *addr;
|
2000-11-28 08:12:29 +03:00
|
|
|
bus_dma_segment_t segs[1];
|
|
|
|
int nsegs;
|
|
|
|
size_t size;
|
|
|
|
struct auich_dma *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
|
|
|
|
#define KERNADDR(p) ((void *)((p)->addr))
|
|
|
|
|
|
|
|
struct auich_cdata {
|
|
|
|
struct auich_dmalist ic_dmalist_pcmo[ICH_DMALIST_MAX];
|
|
|
|
struct auich_dmalist ic_dmalist_pcmi[ICH_DMALIST_MAX];
|
|
|
|
struct auich_dmalist ic_dmalist_mici[ICH_DMALIST_MAX];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ICH_CDOFF(x) offsetof(struct auich_cdata, x)
|
|
|
|
#define ICH_PCMO_OFF(x) ICH_CDOFF(ic_dmalist_pcmo[(x)])
|
|
|
|
#define ICH_PCMI_OFF(x) ICH_CDOFF(ic_dmalist_pcmi[(x)])
|
|
|
|
#define ICH_MICI_OFF(x) ICH_CDOFF(ic_dmalist_mici[(x)])
|
|
|
|
|
|
|
|
struct auich_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
void *sc_ih;
|
|
|
|
|
2004-10-27 17:26:43 +04:00
|
|
|
struct device *sc_audiodev;
|
2000-11-28 08:12:29 +03:00
|
|
|
audio_device_t sc_audev;
|
|
|
|
|
2004-11-17 18:19:30 +03:00
|
|
|
pci_chipset_tag_t sc_pc;
|
|
|
|
pcitag_t sc_pt;
|
2000-11-28 08:12:29 +03:00
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t mix_ioh;
|
2004-11-17 18:19:30 +03:00
|
|
|
bus_size_t mix_size;
|
2000-11-28 08:12:29 +03:00
|
|
|
bus_space_handle_t aud_ioh;
|
2004-11-17 18:19:30 +03:00
|
|
|
bus_size_t aud_size;
|
2000-11-28 08:12:29 +03:00
|
|
|
bus_dma_tag_t dmat;
|
2006-03-07 18:18:59 +03:00
|
|
|
pci_intr_handle_t intrh;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
struct ac97_codec_if *codec_if;
|
|
|
|
struct ac97_host_if host_if;
|
2005-04-11 15:20:45 +04:00
|
|
|
int sc_codecnum;
|
|
|
|
int sc_codectype;
|
2006-04-16 11:40:00 +04:00
|
|
|
enum ac97_host_flags sc_codecflags;
|
2007-02-22 01:59:35 +03:00
|
|
|
bool sc_spdif;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
/* DMA scatter-gather lists. */
|
|
|
|
bus_dmamap_t sc_cddmamap;
|
|
|
|
#define sc_cddma sc_cddmamap->dm_segs[0].ds_addr
|
|
|
|
|
|
|
|
struct auich_cdata *sc_cdata;
|
|
|
|
|
2004-11-01 09:25:35 +03:00
|
|
|
struct auich_ring {
|
|
|
|
int qptr;
|
|
|
|
struct auich_dmalist *dmalist;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
uint32_t start, p, end;
|
2004-11-01 09:25:35 +03:00
|
|
|
int blksize;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2004-11-01 09:25:35 +03:00
|
|
|
void (*intr)(void *);
|
|
|
|
void *arg;
|
|
|
|
} pcmo, pcmi, mici;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
struct auich_dma *sc_dmas;
|
|
|
|
|
2002-08-07 14:31:09 +04:00
|
|
|
/* SiS 7012 hack */
|
2004-10-31 22:28:31 +03:00
|
|
|
int sc_sample_shift;
|
2002-08-07 14:31:09 +04:00
|
|
|
int sc_sts_reg;
|
2003-01-28 05:09:34 +03:00
|
|
|
/* 440MX workaround */
|
|
|
|
int sc_dmamap_flags;
|
2002-02-02 14:13:44 +03:00
|
|
|
|
|
|
|
/* Power Management */
|
|
|
|
void *sc_powerhook;
|
|
|
|
int sc_suspend;
|
2006-03-07 18:18:59 +03:00
|
|
|
int sc_powerstate;
|
2005-01-27 00:53:42 +03:00
|
|
|
struct pci_conf_state sc_pciconf;
|
2004-10-27 17:26:43 +04:00
|
|
|
|
|
|
|
/* sysctl */
|
|
|
|
struct sysctllog *sc_log;
|
|
|
|
uint32_t sc_ac97_clock;
|
|
|
|
int sc_ac97_clock_mib;
|
2004-11-13 18:00:48 +03:00
|
|
|
|
2005-04-04 23:41:50 +04:00
|
|
|
int sc_modem_offset;
|
|
|
|
|
|
|
|
#define AUICH_AUDIO_NFORMATS 3
|
|
|
|
#define AUICH_MODEM_NFORMATS 1
|
|
|
|
struct audio_format sc_audio_formats[AUICH_AUDIO_NFORMATS];
|
|
|
|
struct audio_format sc_modem_formats[AUICH_MODEM_NFORMATS];
|
2004-11-13 18:00:48 +03:00
|
|
|
struct audio_encoding_set *sc_encodings;
|
2006-07-28 11:41:39 +04:00
|
|
|
struct audio_encoding_set *sc_spdif_encodings;
|
2000-11-28 08:12:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Debug */
|
2004-08-07 20:12:57 +04:00
|
|
|
#ifdef AUICH_DEBUG
|
2000-11-28 08:12:29 +03:00
|
|
|
#define DPRINTF(l,x) do { if (auich_debug & (l)) printf x; } while(0)
|
|
|
|
int auich_debug = 0xfffe;
|
|
|
|
#define ICH_DEBUG_CODECIO 0x0001
|
|
|
|
#define ICH_DEBUG_DMA 0x0002
|
2004-08-07 20:12:57 +04:00
|
|
|
#define ICH_DEBUG_INTR 0x0004
|
2000-11-28 08:12:29 +03:00
|
|
|
#else
|
|
|
|
#define DPRINTF(x,y) /* nothing */
|
|
|
|
#endif
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int auich_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void auich_attach(struct device *, struct device *, void *);
|
2004-11-17 18:19:30 +03:00
|
|
|
static int auich_detach(struct device *, int);
|
|
|
|
static int auich_activate(struct device *, enum devact);
|
2004-11-17 18:14:38 +03:00
|
|
|
static int auich_intr(void *);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2002-10-01 00:37:04 +04:00
|
|
|
CFATTACH_DECL(auich, sizeof(struct auich_softc),
|
2004-11-17 18:19:30 +03:00
|
|
|
auich_match, auich_attach, auich_detach, auich_activate);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2006-07-28 11:41:39 +04:00
|
|
|
static int auich_open(void *, int);
|
|
|
|
static void auich_close(void *);
|
2004-11-17 18:14:38 +03:00
|
|
|
static int auich_query_encoding(void *, struct audio_encoding *);
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
static int auich_set_params(void *, int, int, audio_params_t *,
|
|
|
|
audio_params_t *, stream_filter_list_t *,
|
|
|
|
stream_filter_list_t *);
|
|
|
|
static int auich_round_blocksize(void *, int, int, const audio_params_t *);
|
2005-03-12 01:29:16 +03:00
|
|
|
static void auich_halt_pipe(struct auich_softc *, int);
|
2004-11-17 18:14:38 +03:00
|
|
|
static int auich_halt_output(void *);
|
|
|
|
static int auich_halt_input(void *);
|
|
|
|
static int auich_getdev(void *, struct audio_device *);
|
|
|
|
static int auich_set_port(void *, mixer_ctrl_t *);
|
|
|
|
static int auich_get_port(void *, mixer_ctrl_t *);
|
|
|
|
static int auich_query_devinfo(void *, mixer_devinfo_t *);
|
|
|
|
static void *auich_allocm(void *, int, size_t, struct malloc_type *, int);
|
|
|
|
static void auich_freem(void *, void *, struct malloc_type *);
|
|
|
|
static size_t auich_round_buffersize(void *, int, size_t);
|
|
|
|
static paddr_t auich_mappage(void *, void *, off_t, int);
|
|
|
|
static int auich_get_props(void *);
|
2005-03-12 01:29:16 +03:00
|
|
|
static void auich_trigger_pipe(struct auich_softc *, int, struct auich_ring *);
|
|
|
|
static void auich_intr_pipe(struct auich_softc *, int, struct auich_ring *);
|
2004-11-17 18:14:38 +03:00
|
|
|
static int auich_trigger_output(void *, void *, void *, int,
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
void (*)(void *), void *, const audio_params_t *);
|
2004-11-17 18:14:38 +03:00
|
|
|
static int auich_trigger_input(void *, void *, void *, int,
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
void (*)(void *), void *, const audio_params_t *);
|
2006-03-07 18:18:59 +03:00
|
|
|
static int auich_powerstate(void *, int);
|
2004-11-17 18:14:38 +03:00
|
|
|
|
|
|
|
static int auich_alloc_cdata(struct auich_softc *);
|
|
|
|
|
|
|
|
static int auich_allocmem(struct auich_softc *, size_t, size_t,
|
|
|
|
struct auich_dma *);
|
|
|
|
static int auich_freemem(struct auich_softc *, struct auich_dma *);
|
|
|
|
|
|
|
|
static void auich_powerhook(int, void *);
|
|
|
|
static int auich_set_rate(struct auich_softc *, int, u_long);
|
2004-10-27 17:26:43 +04:00
|
|
|
static int auich_sysctl_verify(SYSCTLFN_ARGS);
|
2004-11-17 18:14:38 +03:00
|
|
|
static void auich_finish_attach(struct device *);
|
|
|
|
static void auich_calibrate(struct auich_softc *);
|
2005-04-12 21:30:51 +04:00
|
|
|
static void auich_clear_cas(struct auich_softc *);
|
2002-04-11 14:54:23 +04:00
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int auich_attach_codec(void *, struct ac97_codec_if *);
|
2005-01-15 18:19:51 +03:00
|
|
|
static int auich_read_codec(void *, uint8_t, uint16_t *);
|
|
|
|
static int auich_write_codec(void *, uint8_t, uint16_t);
|
2004-11-17 18:14:38 +03:00
|
|
|
static int auich_reset_codec(void *);
|
2006-04-16 11:40:00 +04:00
|
|
|
static enum ac97_host_flags auich_flags_codec(void *);
|
2007-02-22 01:59:35 +03:00
|
|
|
static void auich_spdif_event(void *, bool);
|
2002-02-02 14:13:44 +03:00
|
|
|
|
2005-06-28 04:28:41 +04:00
|
|
|
static const struct audio_hw_if auich_hw_if = {
|
2006-07-28 11:41:39 +04:00
|
|
|
auich_open,
|
|
|
|
auich_close,
|
2000-11-28 08:12:29 +03:00
|
|
|
NULL, /* drain */
|
|
|
|
auich_query_encoding,
|
|
|
|
auich_set_params,
|
|
|
|
auich_round_blocksize,
|
|
|
|
NULL, /* commit_setting */
|
|
|
|
NULL, /* init_output */
|
|
|
|
NULL, /* init_input */
|
|
|
|
NULL, /* start_output */
|
|
|
|
NULL, /* start_input */
|
|
|
|
auich_halt_output,
|
|
|
|
auich_halt_input,
|
|
|
|
NULL, /* speaker_ctl */
|
|
|
|
auich_getdev,
|
|
|
|
NULL, /* getfd */
|
|
|
|
auich_set_port,
|
|
|
|
auich_get_port,
|
|
|
|
auich_query_devinfo,
|
|
|
|
auich_allocm,
|
|
|
|
auich_freem,
|
|
|
|
auich_round_buffersize,
|
|
|
|
auich_mappage,
|
|
|
|
auich_get_props,
|
|
|
|
auich_trigger_output,
|
|
|
|
auich_trigger_input,
|
2001-10-03 04:04:47 +04:00
|
|
|
NULL, /* dev_ioctl */
|
2006-03-07 18:18:59 +03:00
|
|
|
auich_powerstate,
|
2000-11-28 08:12:29 +03:00
|
|
|
};
|
|
|
|
|
2005-04-04 23:41:50 +04:00
|
|
|
#define AUICH_FORMATS_1CH 0
|
2004-11-13 18:00:48 +03:00
|
|
|
#define AUICH_FORMATS_4CH 1
|
|
|
|
#define AUICH_FORMATS_6CH 2
|
2005-04-04 23:41:50 +04:00
|
|
|
static const struct audio_format auich_audio_formats[AUICH_AUDIO_NFORMATS] = {
|
2004-11-13 18:00:48 +03:00
|
|
|
{NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
|
|
|
|
2, AUFMT_STEREO, 0, {8000, 48000}},
|
|
|
|
{NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
|
|
|
|
4, AUFMT_SURROUND4, 0, {8000, 48000}},
|
|
|
|
{NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
|
|
|
|
6, AUFMT_DOLBY_5_1, 0, {8000, 48000}},
|
|
|
|
};
|
|
|
|
|
2006-07-28 11:41:39 +04:00
|
|
|
#define AUICH_SPDIF_NFORMATS 1
|
|
|
|
static const struct audio_format auich_spdif_formats[AUICH_SPDIF_NFORMATS] = {
|
|
|
|
{NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
|
|
|
|
2, AUFMT_STEREO, 1, {48000}},
|
|
|
|
};
|
|
|
|
|
2005-04-04 23:41:50 +04:00
|
|
|
static const struct audio_format auich_modem_formats[AUICH_MODEM_NFORMATS] = {
|
|
|
|
{NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
|
|
|
|
1, AUFMT_MONAURAL, 0, {8000, 16000}},
|
|
|
|
};
|
|
|
|
|
2004-11-11 06:06:21 +03:00
|
|
|
#define PCI_ID_CODE0(v, p) PCI_ID_CODE(PCI_VENDOR_##v, PCI_PRODUCT_##v##_##p)
|
|
|
|
#define PCIID_ICH PCI_ID_CODE0(INTEL, 82801AA_ACA)
|
|
|
|
#define PCIID_ICH0 PCI_ID_CODE0(INTEL, 82801AB_ACA)
|
|
|
|
#define PCIID_ICH2 PCI_ID_CODE0(INTEL, 82801BA_ACA)
|
|
|
|
#define PCIID_440MX PCI_ID_CODE0(INTEL, 82440MX_ACA)
|
|
|
|
#define PCIID_ICH3 PCI_ID_CODE0(INTEL, 82801CA_AC)
|
|
|
|
#define PCIID_ICH4 PCI_ID_CODE0(INTEL, 82801DB_AC)
|
|
|
|
#define PCIID_ICH5 PCI_ID_CODE0(INTEL, 82801EB_AC)
|
|
|
|
#define PCIID_ICH6 PCI_ID_CODE0(INTEL, 82801FB_AC)
|
2005-12-02 22:47:52 +03:00
|
|
|
#define PCIID_ICH7 PCI_ID_CODE0(INTEL, 82801G_ACA)
|
2005-12-04 15:27:49 +03:00
|
|
|
#define PCIID_I6300ESB PCI_ID_CODE0(INTEL, 6300ESB_ACA)
|
2004-11-11 06:06:21 +03:00
|
|
|
#define PCIID_SIS7012 PCI_ID_CODE0(SIS, 7012_AC)
|
|
|
|
#define PCIID_NFORCE PCI_ID_CODE0(NVIDIA, NFORCE_MCP_AC)
|
|
|
|
#define PCIID_NFORCE2 PCI_ID_CODE0(NVIDIA, NFORCE2_MCPT_AC)
|
2005-01-28 00:49:29 +03:00
|
|
|
#define PCIID_NFORCE2_400 PCI_ID_CODE0(NVIDIA, NFORCE2_400_MCPT_AC)
|
2004-11-11 06:06:21 +03:00
|
|
|
#define PCIID_NFORCE3 PCI_ID_CODE0(NVIDIA, NFORCE3_MCPT_AC)
|
|
|
|
#define PCIID_NFORCE3_250 PCI_ID_CODE0(NVIDIA, NFORCE3_250_MCPT_AC)
|
2005-01-27 16:35:05 +03:00
|
|
|
#define PCIID_NFORCE4 PCI_ID_CODE0(NVIDIA, NFORCE4_AC)
|
2006-08-03 07:01:39 +04:00
|
|
|
#define PCIID_NFORCE430 PCI_ID_CODE0(NVIDIA, NFORCE430_AC)
|
2004-11-11 06:06:21 +03:00
|
|
|
#define PCIID_AMD768 PCI_ID_CODE0(AMD, PBC768_AC)
|
|
|
|
#define PCIID_AMD8111 PCI_ID_CODE0(AMD, PBC8111_AC)
|
|
|
|
|
2005-04-08 16:50:00 +04:00
|
|
|
#define PCIID_ICH3MODEM PCI_ID_CODE0(INTEL, 82801CA_MOD)
|
2005-04-04 23:41:50 +04:00
|
|
|
#define PCIID_ICH4MODEM PCI_ID_CODE0(INTEL, 82801DB_MOD)
|
2007-09-02 04:48:52 +04:00
|
|
|
#define PCIID_ICH6MODEM PCI_ID_CODE0(INTEL, 82801FB_ACM)
|
2005-04-04 23:41:50 +04:00
|
|
|
|
|
|
|
struct auich_devtype {
|
2004-11-11 06:06:21 +03:00
|
|
|
pcireg_t id;
|
|
|
|
const char *name;
|
|
|
|
const char *shortname; /* must be less than 11 characters */
|
2005-04-04 23:41:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct auich_devtype auich_audio_devices[] = {
|
2004-11-11 06:06:21 +03:00
|
|
|
{ PCIID_ICH, "i82801AA (ICH) AC-97 Audio", "ICH" },
|
2004-11-13 18:00:48 +03:00
|
|
|
{ PCIID_ICH0, "i82801AB (ICH0) AC-97 Audio", "ICH0" },
|
|
|
|
{ PCIID_ICH2, "i82801BA (ICH2) AC-97 Audio", "ICH2" },
|
|
|
|
{ PCIID_440MX, "i82440MX AC-97 Audio", "440MX" },
|
|
|
|
{ PCIID_ICH3, "i82801CA (ICH3) AC-97 Audio", "ICH3" },
|
|
|
|
{ PCIID_ICH4, "i82801DB/DBM (ICH4/ICH4M) AC-97 Audio", "ICH4" },
|
|
|
|
{ PCIID_ICH5, "i82801EB (ICH5) AC-97 Audio", "ICH5" },
|
|
|
|
{ PCIID_ICH6, "i82801FB (ICH6) AC-97 Audio", "ICH6" },
|
2005-12-02 22:47:52 +03:00
|
|
|
{ PCIID_ICH7, "i82801GB/GR (ICH7) AC-97 Audio", "ICH7" },
|
2005-12-04 15:27:49 +03:00
|
|
|
{ PCIID_I6300ESB, "Intel 6300ESB AC-97 Audio", "I6300ESB" },
|
2004-11-13 18:00:48 +03:00
|
|
|
{ PCIID_SIS7012, "SiS 7012 AC-97 Audio", "SiS7012" },
|
2004-11-11 06:06:21 +03:00
|
|
|
{ PCIID_NFORCE, "nForce MCP AC-97 Audio", "nForce" },
|
|
|
|
{ PCIID_NFORCE2, "nForce2 MCP-T AC-97 Audio", "nForce2" },
|
2005-01-28 00:49:29 +03:00
|
|
|
{ PCIID_NFORCE2_400, "nForce2 400 MCP-T AC-97 Audio", "nForce2" },
|
2004-11-11 06:06:21 +03:00
|
|
|
{ PCIID_NFORCE3, "nForce3 MCP-T AC-97 Audio", "nForce3" },
|
2004-11-13 18:00:48 +03:00
|
|
|
{ PCIID_NFORCE3_250, "nForce3 250 MCP-T AC-97 Audio", "nForce3" },
|
2005-01-27 16:35:05 +03:00
|
|
|
{ PCIID_NFORCE4, "nForce4 AC-97 Audio", "nForce4" },
|
2006-08-03 07:01:39 +04:00
|
|
|
{ PCIID_NFORCE430, "nForce430 (MCP51) AC-97 Audio", "nForce430" },
|
2004-11-11 06:06:21 +03:00
|
|
|
{ PCIID_AMD768, "AMD768 AC-97 Audio", "AMD768" },
|
|
|
|
{ PCIID_AMD8111,"AMD8111 AC-97 Audio", "AMD8111" },
|
|
|
|
{ 0, NULL, NULL },
|
2000-11-28 08:12:29 +03:00
|
|
|
};
|
|
|
|
|
2005-04-04 23:41:50 +04:00
|
|
|
static const struct auich_devtype auich_modem_devices[] = {
|
|
|
|
#ifdef AUICH_ATTACH_MODEM
|
2005-04-11 15:20:45 +04:00
|
|
|
{ PCIID_ICH3MODEM, "i82801CA (ICH3) AC-97 Modem", "ICH3MODEM" },
|
2005-04-04 23:41:50 +04:00
|
|
|
{ PCIID_ICH4MODEM, "i82801DB (ICH4) AC-97 Modem", "ICH4MODEM" },
|
2007-09-02 04:48:52 +04:00
|
|
|
{ PCIID_ICH6MODEM, "i82801FB (ICH6) AC-97 Modem", "ICH6MODEM" },
|
2005-04-04 23:41:50 +04:00
|
|
|
#endif
|
|
|
|
{ 0, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
2000-11-28 08:12:29 +03:00
|
|
|
static const struct auich_devtype *
|
2005-04-04 23:41:50 +04:00
|
|
|
auich_lookup(struct pci_attach_args *pa, const struct auich_devtype *auich_devices)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
|
|
|
const struct auich_devtype *d;
|
|
|
|
|
|
|
|
for (d = auich_devices; d->name != NULL; d++) {
|
2004-11-11 06:06:21 +03:00
|
|
|
if (pa->pa_id == d->id)
|
2005-01-15 18:19:51 +03:00
|
|
|
return d;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return NULL;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
auich_match(struct device *parent, struct cfdata *match,
|
2006-10-12 05:30:41 +04:00
|
|
|
void *aux)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct pci_attach_args *pa;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
pa = aux;
|
2005-04-04 23:41:50 +04:00
|
|
|
if (auich_lookup(pa, auich_audio_devices) != NULL)
|
|
|
|
return 1;
|
|
|
|
if (auich_lookup(pa, auich_modem_devices) != NULL)
|
2005-01-15 18:19:51 +03:00
|
|
|
return 1;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
auich_attach(struct device *parent, struct device *self, void *aux)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
|
|
|
struct pci_attach_args *pa;
|
2006-04-16 11:40:00 +04:00
|
|
|
pcireg_t v, subdev;
|
2000-11-28 08:12:29 +03:00
|
|
|
const char *intrstr;
|
|
|
|
const struct auich_devtype *d;
|
2005-06-20 06:49:18 +04:00
|
|
|
const struct sysctlnode *node, *node_ac97clock;
|
2004-11-13 18:00:48 +03:00
|
|
|
int err, node_mib, i;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = (struct auich_softc *)self;
|
|
|
|
pa = aux;
|
2003-01-31 03:07:39 +03:00
|
|
|
|
2005-04-11 15:20:45 +04:00
|
|
|
if ((d = auich_lookup(pa, auich_modem_devices)) != NULL) {
|
2005-04-04 23:41:50 +04:00
|
|
|
sc->sc_modem_offset = 0x10;
|
2005-04-11 15:20:45 +04:00
|
|
|
sc->sc_codectype = AC97_CODEC_TYPE_MODEM;
|
|
|
|
} else if ((d = auich_lookup(pa, auich_audio_devices)) != NULL) {
|
2005-04-04 23:41:50 +04:00
|
|
|
sc->sc_modem_offset = 0;
|
2005-04-11 15:20:45 +04:00
|
|
|
sc->sc_codectype = AC97_CODEC_TYPE_AUDIO;
|
|
|
|
} else
|
2000-11-28 08:12:29 +03:00
|
|
|
panic("auich_attach: impossible");
|
|
|
|
|
2005-04-11 15:20:45 +04:00
|
|
|
if (sc->sc_codectype == AC97_CODEC_TYPE_AUDIO)
|
2005-04-04 23:41:50 +04:00
|
|
|
aprint_naive(": Audio controller\n");
|
|
|
|
else
|
|
|
|
aprint_naive(": Modem controller\n");
|
|
|
|
|
2003-01-21 19:05:21 +03:00
|
|
|
sc->sc_pc = pa->pa_pc;
|
|
|
|
sc->sc_pt = pa->pa_tag;
|
2003-01-31 03:07:39 +03:00
|
|
|
|
|
|
|
aprint_normal(": %s\n", d->name);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-04-04 23:41:50 +04:00
|
|
|
if (d->id == PCIID_ICH4 || d->id == PCIID_ICH5 || d->id == PCIID_ICH6
|
2005-12-04 15:27:49 +03:00
|
|
|
|| d->id == PCIID_ICH7 || d->id == PCIID_I6300ESB
|
|
|
|
|| d->id == PCIID_ICH4MODEM) {
|
2003-11-22 11:49:41 +03:00
|
|
|
/*
|
2005-12-04 15:27:49 +03:00
|
|
|
* Use native mode for Intel 6300ESB and ICH4/ICH5/ICH6/ICH7
|
2003-11-22 11:49:41 +03:00
|
|
|
*/
|
|
|
|
if (pci_mapreg_map(pa, ICH_MMBAR, PCI_MAPREG_TYPE_MEM, 0,
|
2004-11-17 18:19:30 +03:00
|
|
|
&sc->iot, &sc->mix_ioh, NULL, &sc->mix_size)) {
|
2003-12-28 15:31:30 +03:00
|
|
|
v = pci_conf_read(pa->pa_pc, pa->pa_tag, ICH_CFG);
|
|
|
|
pci_conf_write(pa->pa_pc, pa->pa_tag, ICH_CFG,
|
|
|
|
v | ICH_CFG_IOSE);
|
|
|
|
if (pci_mapreg_map(pa, ICH_NAMBAR, PCI_MAPREG_TYPE_IO,
|
|
|
|
0, &sc->iot, &sc->mix_ioh, NULL,
|
2004-11-17 18:19:30 +03:00
|
|
|
&sc->mix_size)) {
|
2004-01-13 17:42:50 +03:00
|
|
|
aprint_error("%s: can't map codec i/o space\n",
|
2003-12-28 15:31:30 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
2003-11-22 11:49:41 +03:00
|
|
|
}
|
|
|
|
if (pci_mapreg_map(pa, ICH_MBBAR, PCI_MAPREG_TYPE_MEM, 0,
|
2004-11-17 18:19:30 +03:00
|
|
|
&sc->iot, &sc->aud_ioh, NULL, &sc->aud_size)) {
|
2003-12-28 15:31:30 +03:00
|
|
|
v = pci_conf_read(pa->pa_pc, pa->pa_tag, ICH_CFG);
|
|
|
|
pci_conf_write(pa->pa_pc, pa->pa_tag, ICH_CFG,
|
|
|
|
v | ICH_CFG_IOSE);
|
|
|
|
if (pci_mapreg_map(pa, ICH_NABMBAR, PCI_MAPREG_TYPE_IO,
|
|
|
|
0, &sc->iot, &sc->aud_ioh, NULL,
|
2004-11-17 18:19:30 +03:00
|
|
|
&sc->aud_size)) {
|
2004-01-13 17:42:50 +03:00
|
|
|
aprint_error("%s: can't map device i/o space\n",
|
2003-12-28 15:31:30 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
2003-11-22 11:49:41 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pci_mapreg_map(pa, ICH_NAMBAR, PCI_MAPREG_TYPE_IO, 0,
|
2004-11-17 18:19:30 +03:00
|
|
|
&sc->iot, &sc->mix_ioh, NULL, &sc->mix_size)) {
|
2003-11-22 11:49:41 +03:00
|
|
|
aprint_error("%s: can't map codec i/o space\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pci_mapreg_map(pa, ICH_NABMBAR, PCI_MAPREG_TYPE_IO, 0,
|
2004-11-17 18:19:30 +03:00
|
|
|
&sc->iot, &sc->aud_ioh, NULL, &sc->aud_size)) {
|
2003-11-22 11:49:41 +03:00
|
|
|
aprint_error("%s: can't map device i/o space\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
sc->dmat = pa->pa_dmat;
|
|
|
|
|
|
|
|
/* enable bus mastering */
|
2003-10-30 22:30:26 +03:00
|
|
|
v = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
|
2000-11-28 08:12:29 +03:00
|
|
|
pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
|
2004-10-31 08:50:58 +03:00
|
|
|
v | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_BACKTOBACK_ENABLE);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
/* Map and establish the interrupt. */
|
2006-03-07 18:18:59 +03:00
|
|
|
if (pci_intr_map(pa, &sc->intrh)) {
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_error("%s: can't map interrupt\n", sc->sc_dev.dv_xname);
|
2000-11-28 08:12:29 +03:00
|
|
|
return;
|
|
|
|
}
|
2006-03-07 18:18:59 +03:00
|
|
|
intrstr = pci_intr_string(pa->pa_pc, sc->intrh);
|
|
|
|
sc->sc_ih = pci_intr_establish(pa->pa_pc, sc->intrh, IPL_AUDIO,
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_intr, sc);
|
|
|
|
if (sc->sc_ih == NULL) {
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_error("%s: can't establish interrupt",
|
|
|
|
sc->sc_dev.dv_xname);
|
2000-11-28 08:12:29 +03:00
|
|
|
if (intrstr != NULL)
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_normal(" at %s", intrstr);
|
|
|
|
aprint_normal("\n");
|
2000-11-28 08:12:29 +03:00
|
|
|
return;
|
|
|
|
}
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2003-10-23 21:14:54 +04:00
|
|
|
snprintf(sc->sc_audev.name, MAX_AUDIO_DEV_LEN, "%s AC97", d->shortname);
|
|
|
|
snprintf(sc->sc_audev.version, MAX_AUDIO_DEV_LEN,
|
|
|
|
"0x%02x", PCI_REVISION(pa->pa_class));
|
|
|
|
strlcpy(sc->sc_audev.config, sc->sc_dev.dv_xname, MAX_AUDIO_DEV_LEN);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2002-08-07 14:31:09 +04:00
|
|
|
/* SiS 7012 needs special handling */
|
2004-11-11 06:06:21 +03:00
|
|
|
if (d->id == PCIID_SIS7012) {
|
2002-08-07 14:31:09 +04:00
|
|
|
sc->sc_sts_reg = ICH_PICB;
|
2004-10-31 22:28:31 +03:00
|
|
|
sc->sc_sample_shift = 0;
|
2004-12-11 20:48:56 +03:00
|
|
|
/* Un-mute output. From Linux. */
|
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh, ICH_SIS_NV_CTL,
|
|
|
|
bus_space_read_4(sc->iot, sc->aud_ioh, ICH_SIS_NV_CTL) |
|
|
|
|
ICH_SIS_CTL_UNMUTE);
|
2002-08-07 14:31:09 +04:00
|
|
|
} else {
|
|
|
|
sc->sc_sts_reg = ICH_STS;
|
2004-10-31 22:28:31 +03:00
|
|
|
sc->sc_sample_shift = 1;
|
2002-08-07 14:31:09 +04:00
|
|
|
}
|
2003-06-13 09:13:42 +04:00
|
|
|
|
2003-01-28 05:09:34 +03:00
|
|
|
/* Workaround for a 440MX B-stepping erratum */
|
|
|
|
sc->sc_dmamap_flags = BUS_DMA_COHERENT;
|
2004-11-11 06:06:21 +03:00
|
|
|
if (d->id == PCIID_440MX) {
|
2003-01-28 05:09:34 +03:00
|
|
|
sc->sc_dmamap_flags |= BUS_DMA_NOCACHE;
|
|
|
|
printf("%s: DMA bug workaround enabled\n", sc->sc_dev.dv_xname);
|
|
|
|
}
|
2002-08-07 14:31:09 +04:00
|
|
|
|
2000-11-28 08:12:29 +03:00
|
|
|
/* Set up DMA lists. */
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->pcmo.qptr = sc->pcmi.qptr = sc->mici.qptr = 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_alloc_cdata(sc);
|
|
|
|
|
|
|
|
DPRINTF(ICH_DEBUG_DMA, ("auich_attach: lists %p %p %p\n",
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->pcmo.dmalist, sc->pcmi.dmalist, sc->mici.dmalist));
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-04-11 15:20:45 +04:00
|
|
|
/* Modem codecs are always the secondary codec on ICH */
|
|
|
|
sc->sc_codecnum = sc->sc_codectype == AC97_CODEC_TYPE_MODEM ? 1 : 0;
|
2005-04-04 23:41:50 +04:00
|
|
|
|
2000-11-28 08:12:29 +03:00
|
|
|
sc->host_if.arg = sc;
|
|
|
|
sc->host_if.attach = auich_attach_codec;
|
|
|
|
sc->host_if.read = auich_read_codec;
|
|
|
|
sc->host_if.write = auich_write_codec;
|
|
|
|
sc->host_if.reset = auich_reset_codec;
|
2006-04-16 11:40:00 +04:00
|
|
|
sc->host_if.flags = auich_flags_codec;
|
2006-07-28 11:41:39 +04:00
|
|
|
sc->host_if.spdif_event = auich_spdif_event;
|
2006-04-16 11:40:00 +04:00
|
|
|
|
|
|
|
subdev = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
|
|
|
|
switch (subdev) {
|
|
|
|
case 0x202f161f: /* Gateway 7326GZ */
|
|
|
|
case 0x203a161f: /* Gateway 4028GZ */
|
|
|
|
case 0x204c161f: /* Kvazar-Micro Senator 3592XT */
|
|
|
|
case 0x8144104d: /* Sony VAIO PCG-TR* */
|
|
|
|
case 0x8197104d: /* Sony S1XP */
|
2006-04-17 03:07:16 +04:00
|
|
|
case 0x81c0104d: /* Sony VAIO type T */
|
|
|
|
case 0x81c5104d: /* Sony VAIO VGN-B1XP */
|
2006-04-16 11:40:00 +04:00
|
|
|
sc->sc_codecflags = AC97_HOST_INVERTED_EAMP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sc->sc_codecflags = 0;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-04-11 15:20:45 +04:00
|
|
|
if (ac97_attach_type(&sc->host_if, self, sc->sc_codectype) != 0)
|
2000-11-28 08:12:29 +03:00
|
|
|
return;
|
2006-07-28 11:41:39 +04:00
|
|
|
sc->codec_if->vtbl->unlock(sc->codec_if);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2004-11-13 18:00:48 +03:00
|
|
|
/* setup audio_format */
|
2005-04-11 15:20:45 +04:00
|
|
|
if (sc->sc_codectype == AC97_CODEC_TYPE_AUDIO) {
|
2005-04-04 23:41:50 +04:00
|
|
|
memcpy(sc->sc_audio_formats, auich_audio_formats, sizeof(auich_audio_formats));
|
|
|
|
if (!AC97_IS_4CH(sc->codec_if))
|
|
|
|
AUFMT_INVALIDATE(&sc->sc_audio_formats[AUICH_FORMATS_4CH]);
|
|
|
|
if (!AC97_IS_6CH(sc->codec_if))
|
|
|
|
AUFMT_INVALIDATE(&sc->sc_audio_formats[AUICH_FORMATS_6CH]);
|
|
|
|
if (AC97_IS_FIXED_RATE(sc->codec_if)) {
|
|
|
|
for (i = 0; i < AUICH_AUDIO_NFORMATS; i++) {
|
|
|
|
sc->sc_audio_formats[i].frequency_type = 1;
|
|
|
|
sc->sc_audio_formats[i].frequency[0] = 48000;
|
|
|
|
}
|
2004-11-13 18:00:48 +03:00
|
|
|
}
|
2005-04-04 23:41:50 +04:00
|
|
|
if (0 != auconv_create_encodings(sc->sc_audio_formats, AUICH_AUDIO_NFORMATS,
|
|
|
|
&sc->sc_encodings))
|
|
|
|
return;
|
2006-07-28 11:41:39 +04:00
|
|
|
if (0 != auconv_create_encodings(auich_spdif_formats, AUICH_SPDIF_NFORMATS,
|
|
|
|
&sc->sc_spdif_encodings))
|
|
|
|
return;
|
2005-04-04 23:41:50 +04:00
|
|
|
} else {
|
|
|
|
memcpy(sc->sc_modem_formats, auich_modem_formats, sizeof(auich_modem_formats));
|
|
|
|
if (0 != auconv_create_encodings(sc->sc_modem_formats, AUICH_MODEM_NFORMATS,
|
|
|
|
&sc->sc_encodings))
|
|
|
|
return;
|
2004-11-13 18:00:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-02 14:13:44 +03:00
|
|
|
/* Watch for power change */
|
|
|
|
sc->sc_suspend = PWR_RESUME;
|
2006-09-24 07:53:07 +04:00
|
|
|
sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
|
|
|
|
auich_powerhook, sc);
|
2002-10-11 08:11:28 +04:00
|
|
|
|
2003-10-02 11:41:53 +04:00
|
|
|
config_interrupts(self, auich_finish_attach);
|
2004-10-27 17:26:43 +04:00
|
|
|
|
|
|
|
/* sysctl setup */
|
2005-04-11 15:20:45 +04:00
|
|
|
if (AC97_IS_FIXED_RATE(sc->codec_if) &&
|
|
|
|
sc->sc_codectype == AC97_CODEC_TYPE_AUDIO)
|
2004-10-27 17:26:43 +04:00
|
|
|
return;
|
2005-04-04 23:41:50 +04:00
|
|
|
|
2004-10-27 17:26:43 +04:00
|
|
|
err = sysctl_createv(&sc->sc_log, 0, NULL, NULL, 0,
|
|
|
|
CTLTYPE_NODE, "hw", NULL, NULL, 0, NULL, 0,
|
|
|
|
CTL_HW, CTL_EOL);
|
|
|
|
if (err != 0)
|
|
|
|
goto sysctl_err;
|
|
|
|
err = sysctl_createv(&sc->sc_log, 0, NULL, &node, 0,
|
|
|
|
CTLTYPE_NODE, sc->sc_dev.dv_xname, NULL, NULL, 0,
|
|
|
|
NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
|
|
|
|
if (err != 0)
|
|
|
|
goto sysctl_err;
|
|
|
|
node_mib = node->sysctl_num;
|
2005-04-04 23:41:50 +04:00
|
|
|
|
|
|
|
if (!AC97_IS_FIXED_RATE(sc->codec_if)) {
|
|
|
|
/* passing the sc address instead of &sc->sc_ac97_clock */
|
|
|
|
err = sysctl_createv(&sc->sc_log, 0, NULL, &node_ac97clock,
|
|
|
|
CTLFLAG_READWRITE,
|
|
|
|
CTLTYPE_INT, "ac97rate",
|
|
|
|
SYSCTL_DESCR("AC'97 codec link rate"),
|
|
|
|
auich_sysctl_verify, 0, sc, 0,
|
|
|
|
CTL_HW, node_mib, CTL_CREATE, CTL_EOL);
|
|
|
|
if (err != 0)
|
|
|
|
goto sysctl_err;
|
|
|
|
sc->sc_ac97_clock_mib = node_ac97clock->sysctl_num;
|
|
|
|
}
|
2004-10-27 17:26:43 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
sysctl_err:
|
|
|
|
printf("%s: failed to add sysctl nodes. (%d)\n",
|
|
|
|
sc->sc_dev.dv_xname, err);
|
|
|
|
return; /* failure of sysctl is not fatal. */
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:19:30 +03:00
|
|
|
static int
|
|
|
|
auich_activate(struct device *self, enum devact act)
|
|
|
|
{
|
|
|
|
struct auich_softc *sc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
sc = (struct auich_softc *)self;
|
|
|
|
ret = 0;
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
if (sc->sc_audiodev != NULL)
|
|
|
|
ret = config_deactivate(sc->sc_audiodev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2004-10-27 17:26:43 +04:00
|
|
|
auich_detach(struct device *self, int flags)
|
|
|
|
{
|
|
|
|
struct auich_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct auich_softc *)self;
|
2004-11-17 18:19:30 +03:00
|
|
|
|
2004-10-27 17:26:43 +04:00
|
|
|
/* audio */
|
|
|
|
if (sc->sc_audiodev != NULL)
|
|
|
|
config_detach(sc->sc_audiodev, flags);
|
2004-11-17 18:19:30 +03:00
|
|
|
|
|
|
|
/* sysctl */
|
|
|
|
sysctl_teardown(&sc->sc_log);
|
|
|
|
|
|
|
|
/* audio_encoding_set */
|
|
|
|
auconv_delete_encodings(sc->sc_encodings);
|
2006-07-28 11:41:39 +04:00
|
|
|
auconv_delete_encodings(sc->sc_spdif_encodings);
|
2004-11-17 18:19:30 +03:00
|
|
|
|
|
|
|
/* ac97 */
|
|
|
|
if (sc->codec_if != NULL)
|
|
|
|
sc->codec_if->vtbl->detach(sc->codec_if);
|
|
|
|
|
|
|
|
/* PCI */
|
|
|
|
if (sc->sc_ih != NULL)
|
|
|
|
pci_intr_disestablish(sc->sc_pc, sc->sc_ih);
|
|
|
|
if (sc->mix_size != 0)
|
|
|
|
bus_space_unmap(sc->iot, sc->mix_ioh, sc->mix_size);
|
|
|
|
if (sc->aud_size != 0)
|
|
|
|
bus_space_unmap(sc->iot, sc->aud_ioh, sc->aud_size);
|
2004-10-27 17:26:43 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
auich_sysctl_verify(SYSCTLFN_ARGS)
|
|
|
|
{
|
|
|
|
int error, tmp;
|
|
|
|
struct sysctlnode node;
|
|
|
|
struct auich_softc *sc;
|
|
|
|
|
|
|
|
node = *rnode;
|
|
|
|
sc = rnode->sysctl_data;
|
|
|
|
if (node.sysctl_num == sc->sc_ac97_clock_mib) {
|
2005-04-04 23:41:50 +04:00
|
|
|
tmp = sc->sc_ac97_clock;
|
|
|
|
node.sysctl_data = &tmp;
|
|
|
|
error = sysctl_lookup(SYSCTLFN_CALL(&node));
|
|
|
|
if (error || newp == NULL)
|
|
|
|
return error;
|
|
|
|
|
2004-10-27 17:26:43 +04:00
|
|
|
if (tmp < 48000 || tmp > 96000)
|
|
|
|
return EINVAL;
|
|
|
|
sc->sc_ac97_clock = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2003-10-02 11:41:53 +04:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static void
|
2003-10-02 11:41:53 +04:00
|
|
|
auich_finish_attach(struct device *self)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2003-10-02 11:41:53 +04:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = (void *)self;
|
2004-11-10 07:20:26 +03:00
|
|
|
if (!AC97_IS_FIXED_RATE(sc->codec_if))
|
2003-10-02 11:41:53 +04:00
|
|
|
auich_calibrate(sc);
|
|
|
|
|
2004-10-27 17:26:43 +04:00
|
|
|
sc->sc_audiodev = audio_attach_mi(&auich_hw_if, sc, &sc->sc_dev);
|
2006-03-07 18:18:59 +03:00
|
|
|
|
2006-04-27 16:21:39 +04:00
|
|
|
#if notyet
|
2006-03-07 18:18:59 +03:00
|
|
|
auich_powerhook(PWR_SUSPEND, sc);
|
2006-04-27 16:21:39 +04:00
|
|
|
#endif
|
2006-03-07 18:18:59 +03:00
|
|
|
|
|
|
|
return;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2002-03-21 12:17:20 +03:00
|
|
|
#define ICH_CODECIO_INTERVAL 10
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2005-01-15 18:19:51 +03:00
|
|
|
auich_read_codec(void *v, uint8_t reg, uint16_t *val)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
int i;
|
2002-03-21 12:17:20 +03:00
|
|
|
uint32_t status;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
/* wait for an access semaphore */
|
2002-03-21 12:17:20 +03:00
|
|
|
for (i = ICH_SEMATIMO / ICH_CODECIO_INTERVAL; i-- &&
|
2005-04-04 23:41:50 +04:00
|
|
|
bus_space_read_1(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_CAS + sc->sc_modem_offset) & 1;
|
2002-03-21 12:17:20 +03:00
|
|
|
DELAY(ICH_CODECIO_INTERVAL));
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
if (i > 0) {
|
2005-04-11 15:20:45 +04:00
|
|
|
*val = bus_space_read_2(sc->iot, sc->mix_ioh,
|
|
|
|
reg + (sc->sc_codecnum * ICH_CODEC_OFFSET));
|
2000-11-28 08:12:29 +03:00
|
|
|
DPRINTF(ICH_DEBUG_CODECIO,
|
|
|
|
("auich_read_codec(%x, %x)\n", reg, *val));
|
2005-04-04 23:41:50 +04:00
|
|
|
status = bus_space_read_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset);
|
2002-03-21 12:17:20 +03:00
|
|
|
if (status & ICH_RCS) {
|
2005-04-04 23:41:50 +04:00
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset,
|
2002-03-21 12:17:20 +03:00
|
|
|
status & ~(ICH_SRI|ICH_PRI|ICH_GSCI));
|
|
|
|
*val = 0xffff;
|
2004-11-10 20:17:14 +03:00
|
|
|
DPRINTF(ICH_DEBUG_CODECIO,
|
|
|
|
("%s: read_codec error\n", sc->sc_dev.dv_xname));
|
2005-04-12 21:30:51 +04:00
|
|
|
if (reg == AC97_REG_GPIO_STATUS)
|
|
|
|
auich_clear_cas(sc);
|
2004-11-10 20:17:14 +03:00
|
|
|
return -1;
|
2002-03-21 12:17:20 +03:00
|
|
|
}
|
2005-04-12 21:30:51 +04:00
|
|
|
if (reg == AC97_REG_GPIO_STATUS)
|
|
|
|
auich_clear_cas(sc);
|
2000-11-28 08:12:29 +03:00
|
|
|
return 0;
|
|
|
|
} else {
|
2005-04-04 23:41:50 +04:00
|
|
|
aprint_normal("%s: read_codec timeout\n", sc->sc_dev.dv_xname);
|
2005-04-12 21:30:51 +04:00
|
|
|
if (reg == AC97_REG_GPIO_STATUS)
|
|
|
|
auich_clear_cas(sc);
|
2000-11-28 08:12:29 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2005-01-15 18:19:51 +03:00
|
|
|
auich_write_codec(void *v, uint8_t reg, uint16_t val)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
DPRINTF(ICH_DEBUG_CODECIO, ("auich_write_codec(%x, %x)\n", reg, val));
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
/* wait for an access semaphore */
|
2002-03-21 12:17:20 +03:00
|
|
|
for (i = ICH_SEMATIMO / ICH_CODECIO_INTERVAL; i-- &&
|
2005-04-04 23:41:50 +04:00
|
|
|
bus_space_read_1(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_CAS + sc->sc_modem_offset) & 1;
|
2002-03-21 12:17:20 +03:00
|
|
|
DELAY(ICH_CODECIO_INTERVAL));
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
if (i > 0) {
|
2005-04-11 15:20:45 +04:00
|
|
|
bus_space_write_2(sc->iot, sc->mix_ioh,
|
|
|
|
reg + (sc->sc_codecnum * ICH_CODEC_OFFSET), val);
|
2000-11-28 08:12:29 +03:00
|
|
|
return 0;
|
|
|
|
} else {
|
2005-04-04 23:41:50 +04:00
|
|
|
aprint_normal("%s: write_codec timeout\n", sc->sc_dev.dv_xname);
|
2000-11-28 08:12:29 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_attach_codec(void *v, struct ac97_codec_if *cif)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
sc->codec_if = cif;
|
2005-04-04 23:41:50 +04:00
|
|
|
|
2000-11-28 08:12:29 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_reset_codec(void *v)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2002-03-21 12:17:20 +03:00
|
|
|
int i;
|
2003-10-23 21:05:26 +04:00
|
|
|
uint32_t control, status;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2005-04-04 23:41:50 +04:00
|
|
|
control = bus_space_read_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GCTRL + sc->sc_modem_offset);
|
2005-04-12 21:30:51 +04:00
|
|
|
if (sc->sc_codectype == AC97_CODEC_TYPE_AUDIO) {
|
2005-04-08 03:21:10 +04:00
|
|
|
control &= ~(ICH_ACLSO | ICH_PCM246_MASK);
|
2005-04-12 21:30:51 +04:00
|
|
|
} else {
|
2005-04-08 03:21:10 +04:00
|
|
|
control &= ~ICH_ACLSO;
|
2005-04-12 21:30:51 +04:00
|
|
|
control |= ICH_GIE;
|
|
|
|
}
|
2002-08-07 14:31:09 +04:00
|
|
|
control |= (control & ICH_CRESET) ? ICH_WRESET : ICH_CRESET;
|
2005-04-04 23:41:50 +04:00
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GCTRL + sc->sc_modem_offset, control);
|
2002-03-21 12:17:20 +03:00
|
|
|
|
2003-10-23 21:05:26 +04:00
|
|
|
for (i = 500000; i >= 0; i--) {
|
2005-04-04 23:41:50 +04:00
|
|
|
status = bus_space_read_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset);
|
2003-10-24 08:06:44 +04:00
|
|
|
if (status & (ICH_PCR | ICH_SCR | ICH_S2CR))
|
2003-10-23 21:05:26 +04:00
|
|
|
break;
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
if (i <= 0) {
|
2003-10-24 08:06:44 +04:00
|
|
|
printf("%s: auich_reset_codec: time out\n", sc->sc_dev.dv_xname);
|
2004-09-22 16:20:24 +04:00
|
|
|
return ETIMEDOUT;
|
|
|
|
}
|
2006-04-14 17:02:57 +04:00
|
|
|
#ifdef AUICH_DEBUG
|
2004-09-22 16:20:24 +04:00
|
|
|
if (status & ICH_SCR)
|
|
|
|
printf("%s: The 2nd codec is ready.\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
if (status & ICH_S2CR)
|
|
|
|
printf("%s: The 3rd codec is ready.\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
2004-01-03 17:11:36 +03:00
|
|
|
#endif
|
2004-09-22 16:20:24 +04:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2006-04-16 11:40:00 +04:00
|
|
|
static enum ac97_host_flags
|
|
|
|
auich_flags_codec(void *v)
|
|
|
|
{
|
|
|
|
struct auich_softc *sc = v;
|
|
|
|
return sc->sc_codecflags;
|
|
|
|
}
|
|
|
|
|
2006-07-28 11:41:39 +04:00
|
|
|
static void
|
2007-02-22 01:59:35 +03:00
|
|
|
auich_spdif_event(void *addr, bool flag)
|
2006-07-28 11:41:39 +04:00
|
|
|
{
|
|
|
|
struct auich_softc *sc;
|
|
|
|
|
|
|
|
sc = addr;
|
|
|
|
sc->sc_spdif = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
auich_open(void *addr, int flags)
|
2006-07-28 11:41:39 +04:00
|
|
|
{
|
|
|
|
struct auich_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct auich_softc *)addr;
|
|
|
|
sc->codec_if->vtbl->lock(sc->codec_if);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
auich_close(void *addr)
|
|
|
|
{
|
|
|
|
struct auich_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct auich_softc *)addr;
|
|
|
|
sc->codec_if->vtbl->unlock(sc->codec_if);
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_query_encoding(void *v, struct audio_encoding *aep)
|
|
|
|
{
|
2004-11-13 18:00:48 +03:00
|
|
|
struct auich_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct auich_softc *)v;
|
2006-07-28 11:41:39 +04:00
|
|
|
return auconv_query_encoding(
|
|
|
|
sc->sc_spdif ? sc->sc_spdif_encodings : sc->sc_encodings, aep);
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2003-01-15 07:49:35 +03:00
|
|
|
auich_set_rate(struct auich_softc *sc, int mode, u_long srate)
|
2002-04-11 14:54:23 +04:00
|
|
|
{
|
2003-09-28 17:37:19 +04:00
|
|
|
int ret;
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
u_int ratetmp;
|
2002-04-11 14:54:23 +04:00
|
|
|
|
2004-10-27 17:26:43 +04:00
|
|
|
sc->codec_if->vtbl->set_clock(sc->codec_if, sc->sc_ac97_clock);
|
2003-01-15 07:49:35 +03:00
|
|
|
ratetmp = srate;
|
2003-09-28 17:37:19 +04:00
|
|
|
if (mode == AUMODE_RECORD)
|
|
|
|
return sc->codec_if->vtbl->set_rate(sc->codec_if,
|
|
|
|
AC97_REG_PCM_LR_ADC_RATE, &ratetmp);
|
|
|
|
ret = sc->codec_if->vtbl->set_rate(sc->codec_if,
|
|
|
|
AC97_REG_PCM_FRONT_DAC_RATE, &ratetmp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ratetmp = srate;
|
|
|
|
ret = sc->codec_if->vtbl->set_rate(sc->codec_if,
|
|
|
|
AC97_REG_PCM_SURR_DAC_RATE, &ratetmp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ratetmp = srate;
|
|
|
|
ret = sc->codec_if->vtbl->set_rate(sc->codec_if,
|
|
|
|
AC97_REG_PCM_LFE_DAC_RATE, &ratetmp);
|
|
|
|
return ret;
|
2002-04-11 14:54:23 +04:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
auich_set_params(void *v, int setmode, int usemode,
|
2006-10-12 05:30:41 +04:00
|
|
|
audio_params_t *play, audio_params_t *rec, stream_filter_list_t *pfil,
|
|
|
|
stream_filter_list_t *rfil)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
audio_params_t *p;
|
|
|
|
stream_filter_list_t *fil;
|
2004-11-13 18:00:48 +03:00
|
|
|
int mode, index;
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
uint32_t control;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
for (mode = AUMODE_RECORD; mode != -1;
|
|
|
|
mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
|
|
|
|
if ((setmode & mode) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
p = mode == AUMODE_PLAY ? play : rec;
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
fil = mode == AUMODE_PLAY ? pfil : rfil;
|
2000-11-28 08:12:29 +03:00
|
|
|
if (p == NULL)
|
|
|
|
continue;
|
|
|
|
|
2005-04-11 15:20:45 +04:00
|
|
|
if (sc->sc_codectype == AC97_CODEC_TYPE_AUDIO) {
|
2005-04-04 23:41:50 +04:00
|
|
|
if (p->sample_rate < 8000 ||
|
|
|
|
p->sample_rate > 48000)
|
|
|
|
return EINVAL;
|
|
|
|
|
2006-07-28 11:41:39 +04:00
|
|
|
if (sc->sc_spdif)
|
|
|
|
index = auconv_set_converter(sc->sc_audio_formats,
|
|
|
|
AUICH_AUDIO_NFORMATS, mode, p, TRUE, fil);
|
|
|
|
else
|
|
|
|
index = auconv_set_converter(auich_spdif_formats,
|
|
|
|
AUICH_SPDIF_NFORMATS, mode, p, TRUE, fil);
|
2005-04-04 23:41:50 +04:00
|
|
|
} else {
|
|
|
|
if (p->sample_rate != 8000 && p->sample_rate != 16000)
|
|
|
|
return EINVAL;
|
2006-07-28 11:41:39 +04:00
|
|
|
index = auconv_set_converter(sc->sc_modem_formats,
|
|
|
|
AUICH_MODEM_NFORMATS, mode, p, TRUE, fil);
|
2005-04-04 23:41:50 +04:00
|
|
|
}
|
2004-11-13 18:00:48 +03:00
|
|
|
if (index < 0)
|
|
|
|
return EINVAL;
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
if (fil->req_size > 0)
|
|
|
|
p = &fil->filters[0].param;
|
|
|
|
/* p represents HW encoding */
|
2005-04-11 15:20:45 +04:00
|
|
|
if (sc->sc_codectype == AC97_CODEC_TYPE_AUDIO) {
|
2005-04-04 23:41:50 +04:00
|
|
|
if (sc->sc_audio_formats[index].frequency_type != 1
|
|
|
|
&& auich_set_rate(sc, mode, p->sample_rate))
|
|
|
|
return EINVAL;
|
|
|
|
} else {
|
|
|
|
if (sc->sc_modem_formats[index].frequency_type != 1
|
|
|
|
&& auich_set_rate(sc, mode, p->sample_rate))
|
|
|
|
return EINVAL;
|
2005-04-08 03:21:10 +04:00
|
|
|
auich_write_codec(sc, AC97_REG_LINE1_RATE,
|
|
|
|
p->sample_rate);
|
|
|
|
auich_write_codec(sc, AC97_REG_LINE1_LEVEL, 0);
|
2005-04-04 23:41:50 +04:00
|
|
|
}
|
2005-04-11 15:20:45 +04:00
|
|
|
if (mode == AUMODE_PLAY &&
|
|
|
|
sc->sc_codectype == AC97_CODEC_TYPE_AUDIO) {
|
2005-04-04 23:41:50 +04:00
|
|
|
control = bus_space_read_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GCTRL + sc->sc_modem_offset);
|
2005-04-08 03:21:10 +04:00
|
|
|
control &= ~ICH_PCM246_MASK;
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
if (p->channels == 4) {
|
2003-09-28 17:37:19 +04:00
|
|
|
control |= ICH_PCM4;
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
} else if (p->channels == 6) {
|
2003-09-28 17:37:19 +04:00
|
|
|
control |= ICH_PCM6;
|
|
|
|
}
|
2005-04-04 23:41:50 +04:00
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GCTRL + sc->sc_modem_offset, control);
|
2003-09-28 17:37:19 +04:00
|
|
|
}
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
auich_round_blocksize(void *v, int blk, int mode,
|
|
|
|
const audio_params_t *param)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return blk & ~0x3f; /* keep good alignment */
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
static void
|
|
|
|
auich_halt_pipe(struct auich_softc *sc, int pipe)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint32_t status;
|
|
|
|
|
|
|
|
bus_space_write_1(sc->iot, sc->aud_ioh, pipe + ICH_CTRL, 0);
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
|
|
status = bus_space_read_4(sc->iot, sc->aud_ioh, pipe + ICH_STS);
|
|
|
|
if (status & ICH_DCH)
|
|
|
|
break;
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
bus_space_write_1(sc->iot, sc->aud_ioh, pipe + ICH_CTRL, ICH_RR);
|
|
|
|
|
2005-08-22 05:15:12 +04:00
|
|
|
#if AUICH_DEBUG
|
2005-03-12 01:29:16 +03:00
|
|
|
if (i > 0)
|
|
|
|
printf("auich_halt_pipe: halt took %d cycles\n", i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_halt_output(void *v)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
DPRINTF(ICH_DEBUG_DMA, ("%s: halt_output\n", sc->sc_dev.dv_xname));
|
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
auich_halt_pipe(sc, ICH_PCMO);
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->pcmo.intr = NULL;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_halt_input(void *v)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2005-03-12 01:29:16 +03:00
|
|
|
DPRINTF(ICH_DEBUG_DMA, ("%s: halt_input\n", sc->sc_dev.dv_xname));
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
auich_halt_pipe(sc, ICH_PCMI);
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->pcmi.intr = NULL;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_getdev(void *v, struct audio_device *adp)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
*adp = sc->sc_audev;
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_set_port(void *v, mixer_ctrl_t *cp)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
|
|
|
return sc->codec_if->vtbl->mixer_set_port(sc->codec_if, cp);
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_get_port(void *v, mixer_ctrl_t *cp)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
|
|
|
return sc->codec_if->vtbl->mixer_get_port(sc->codec_if, cp);
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_query_devinfo(void *v, mixer_devinfo_t *dp)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
|
|
|
return sc->codec_if->vtbl->query_devinfo(sc->codec_if, dp);
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static void *
|
2006-11-16 04:32:37 +03:00
|
|
|
auich_allocm(void *v, int direction, size_t size,
|
2006-10-12 05:30:41 +04:00
|
|
|
struct malloc_type *pool, int flags)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
struct auich_dma *p;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (size > (ICH_DMALIST_MAX * ICH_DMASEG_MAX))
|
2005-01-15 18:19:51 +03:00
|
|
|
return NULL;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2002-01-12 19:17:05 +03:00
|
|
|
p = malloc(sizeof(*p), pool, flags|M_ZERO);
|
2000-11-28 08:12:29 +03:00
|
|
|
if (p == NULL)
|
2005-01-15 18:19:51 +03:00
|
|
|
return NULL;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
error = auich_allocmem(sc, size, 0, p);
|
|
|
|
if (error) {
|
|
|
|
free(p, pool);
|
2005-01-15 18:19:51 +03:00
|
|
|
return NULL;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
p->next = sc->sc_dmas;
|
|
|
|
sc->sc_dmas = p;
|
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return KERNADDR(p);
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static void
|
2003-02-01 09:23:35 +03:00
|
|
|
auich_freem(void *v, void *ptr, struct malloc_type *pool)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
struct auich_dma *p, **pp;
|
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->next) {
|
|
|
|
if (KERNADDR(p) == ptr) {
|
|
|
|
auich_freemem(sc, p);
|
|
|
|
*pp = p->next;
|
|
|
|
free(p, pool);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static size_t
|
2006-11-16 04:32:37 +03:00
|
|
|
auich_round_buffersize(void *v, int direction, size_t size)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
if (size > (ICH_DMALIST_MAX * ICH_DMASEG_MAX))
|
|
|
|
size = ICH_DMALIST_MAX * ICH_DMASEG_MAX;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static paddr_t
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_mappage(void *v, void *mem, off_t off, int prot)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
struct auich_dma *p;
|
|
|
|
|
|
|
|
if (off < 0)
|
2005-01-15 18:19:51 +03:00
|
|
|
return -1;
|
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
for (p = sc->sc_dmas; p && KERNADDR(p) != mem; p = p->next)
|
2005-01-15 18:19:51 +03:00
|
|
|
continue;
|
2000-11-28 08:12:29 +03:00
|
|
|
if (!p)
|
2005-01-15 18:19:51 +03:00
|
|
|
return -1;
|
|
|
|
return bus_dmamem_mmap(sc->dmat, p->segs, p->nsegs,
|
|
|
|
off, prot, BUS_DMA_WAITOK);
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_get_props(void *v)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2002-10-08 14:25:45 +04:00
|
|
|
int props;
|
|
|
|
|
|
|
|
props = AUDIO_PROP_INDEPENDENT | AUDIO_PROP_FULLDUPLEX;
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2002-10-08 14:25:45 +04:00
|
|
|
/*
|
|
|
|
* Even if the codec is fixed-rate, set_param() succeeds for any sample
|
|
|
|
* rate because of aurateconv. Applications can't know what rate the
|
|
|
|
* device can process in the case of mmap().
|
|
|
|
*/
|
2005-04-11 15:20:45 +04:00
|
|
|
if (!AC97_IS_FIXED_RATE(sc->codec_if) ||
|
|
|
|
sc->sc_codectype == AC97_CODEC_TYPE_MODEM)
|
2002-10-08 14:25:45 +04:00
|
|
|
props |= AUDIO_PROP_MMAP;
|
|
|
|
return props;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_intr(void *v)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
|
|
|
int ret, gsts;
|
2003-01-21 19:05:21 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
int csts;
|
|
|
|
#endif
|
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
|
|
|
ret = 0;
|
2003-01-21 19:05:21 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
csts = pci_conf_read(sc->sc_pc, sc->sc_pt, PCI_COMMAND_STATUS_REG);
|
|
|
|
if (csts & PCI_STATUS_MASTER_ABORT) {
|
|
|
|
printf("auich_intr: PCI master abort\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-04 23:41:50 +04:00
|
|
|
gsts = bus_space_read_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset);
|
2004-08-07 20:12:57 +04:00
|
|
|
DPRINTF(ICH_DEBUG_INTR, ("auich_intr: gsts=0x%x\n", gsts));
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-04-11 15:20:45 +04:00
|
|
|
if ((sc->sc_codectype == AC97_CODEC_TYPE_AUDIO && gsts & ICH_POINT) ||
|
|
|
|
(sc->sc_codectype == AC97_CODEC_TYPE_MODEM && gsts & ICH_MOINT)) {
|
2004-11-01 09:25:35 +03:00
|
|
|
int sts;
|
|
|
|
|
2004-08-07 20:12:57 +04:00
|
|
|
sts = bus_space_read_2(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_PCMO + sc->sc_sts_reg);
|
|
|
|
DPRINTF(ICH_DEBUG_INTR,
|
2000-11-28 08:12:29 +03:00
|
|
|
("auich_intr: osts=0x%x\n", sts));
|
|
|
|
|
2004-11-01 09:25:35 +03:00
|
|
|
if (sts & ICH_FIFOE)
|
|
|
|
printf("%s: fifo underrun\n", sc->sc_dev.dv_xname);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
if (sts & ICH_BCIS)
|
|
|
|
auich_intr_pipe(sc, ICH_PCMO, &sc->pcmo);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
/* int ack */
|
2004-08-07 20:12:57 +04:00
|
|
|
bus_space_write_2(sc->iot, sc->aud_ioh, ICH_PCMO +
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->sc_sts_reg, sts & (ICH_BCIS | ICH_FIFOE));
|
2005-04-11 15:20:45 +04:00
|
|
|
if (sc->sc_codectype == AC97_CODEC_TYPE_AUDIO)
|
2005-04-04 23:41:50 +04:00
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset, ICH_POINT);
|
|
|
|
else
|
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset, ICH_MOINT);
|
2000-11-28 08:12:29 +03:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
2005-04-11 15:20:45 +04:00
|
|
|
if ((sc->sc_codectype == AC97_CODEC_TYPE_AUDIO && gsts & ICH_PIINT) ||
|
|
|
|
(sc->sc_codectype == AC97_CODEC_TYPE_MODEM && gsts & ICH_MIINT)) {
|
2004-11-01 09:25:35 +03:00
|
|
|
int sts;
|
|
|
|
|
2004-08-07 20:12:57 +04:00
|
|
|
sts = bus_space_read_2(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_PCMI + sc->sc_sts_reg);
|
|
|
|
DPRINTF(ICH_DEBUG_INTR,
|
2000-11-28 08:12:29 +03:00
|
|
|
("auich_intr: ists=0x%x\n", sts));
|
|
|
|
|
2004-11-01 09:25:35 +03:00
|
|
|
if (sts & ICH_FIFOE)
|
|
|
|
printf("%s: fifo overrun\n", sc->sc_dev.dv_xname);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
if (sts & ICH_BCIS)
|
|
|
|
auich_intr_pipe(sc, ICH_PCMI, &sc->pcmi);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
/* int ack */
|
2004-08-07 20:12:57 +04:00
|
|
|
bus_space_write_2(sc->iot, sc->aud_ioh, ICH_PCMI +
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->sc_sts_reg, sts & (ICH_BCIS | ICH_FIFOE));
|
2005-04-11 15:20:45 +04:00
|
|
|
if (sc->sc_codectype == AC97_CODEC_TYPE_AUDIO)
|
2005-04-04 23:41:50 +04:00
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset, ICH_PIINT);
|
|
|
|
else
|
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset, ICH_MIINT);
|
2000-11-28 08:12:29 +03:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
2005-04-11 15:20:45 +04:00
|
|
|
if (sc->sc_codectype == AC97_CODEC_TYPE_AUDIO && gsts & ICH_MINT) {
|
2004-11-01 09:25:35 +03:00
|
|
|
int sts;
|
|
|
|
|
2004-08-07 20:12:57 +04:00
|
|
|
sts = bus_space_read_2(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_MICI + sc->sc_sts_reg);
|
|
|
|
DPRINTF(ICH_DEBUG_INTR,
|
2000-11-28 08:12:29 +03:00
|
|
|
("auich_intr: ists=0x%x\n", sts));
|
2004-11-01 09:25:35 +03:00
|
|
|
|
2000-11-28 08:12:29 +03:00
|
|
|
if (sts & ICH_FIFOE)
|
|
|
|
printf("%s: fifo overrun\n", sc->sc_dev.dv_xname);
|
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
if (sts & ICH_BCIS)
|
|
|
|
auich_intr_pipe(sc, ICH_MICI, &sc->mici);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
/* int ack */
|
|
|
|
bus_space_write_2(sc->iot, sc->aud_ioh, ICH_MICI +
|
|
|
|
sc->sc_sts_reg, sts & (ICH_BCIS | ICH_FIFOE));
|
2005-04-04 23:41:50 +04:00
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset, ICH_MINT);
|
2005-03-12 01:29:16 +03:00
|
|
|
ret++;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2005-04-12 21:30:51 +04:00
|
|
|
#ifdef AUICH_MODEM_DEBUG
|
|
|
|
if (sc->sc_codectype == AC97_CODEC_TYPE_MODEM && gsts & ICH_GSCI) {
|
|
|
|
printf("%s: gsts=0x%x\n", sc->sc_dev.dv_xname, gsts);
|
|
|
|
/* int ack */
|
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_GSTS + sc->sc_modem_offset, ICH_GSCI);
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-11-28 08:12:29 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
static void
|
|
|
|
auich_trigger_pipe(struct auich_softc *sc, int pipe, struct auich_ring *ring)
|
|
|
|
{
|
|
|
|
int blksize, qptr;
|
|
|
|
struct auich_dmalist *q;
|
|
|
|
|
|
|
|
blksize = ring->blksize;
|
|
|
|
|
|
|
|
for (qptr = 0; qptr < ICH_DMALIST_MAX; qptr++) {
|
|
|
|
q = &ring->dmalist[qptr];
|
|
|
|
q->base = ring->p;
|
|
|
|
q->len = (blksize >> sc->sc_sample_shift) | ICH_DMAF_IOC;
|
|
|
|
|
|
|
|
ring->p += blksize;
|
|
|
|
if (ring->p >= ring->end)
|
|
|
|
ring->p = ring->start;
|
|
|
|
}
|
|
|
|
ring->qptr = 0;
|
|
|
|
|
|
|
|
bus_space_write_1(sc->iot, sc->aud_ioh, pipe + ICH_LVI,
|
|
|
|
(qptr - 1) & ICH_LVI_MASK);
|
|
|
|
bus_space_write_1(sc->iot, sc->aud_ioh, pipe + ICH_CTRL,
|
|
|
|
ICH_IOCE | ICH_FEIE | ICH_RPBM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
auich_intr_pipe(struct auich_softc *sc, int pipe, struct auich_ring *ring)
|
|
|
|
{
|
|
|
|
int blksize, qptr, nqptr;
|
|
|
|
struct auich_dmalist *q;
|
|
|
|
|
|
|
|
blksize = ring->blksize;
|
|
|
|
qptr = ring->qptr;
|
|
|
|
nqptr = bus_space_read_1(sc->iot, sc->aud_ioh, pipe + ICH_CIV);
|
|
|
|
|
|
|
|
while (qptr != nqptr) {
|
|
|
|
q = &ring->dmalist[qptr];
|
|
|
|
q->base = ring->p;
|
|
|
|
q->len = (blksize >> sc->sc_sample_shift) | ICH_DMAF_IOC;
|
|
|
|
|
|
|
|
DPRINTF(ICH_DEBUG_INTR,
|
|
|
|
("auich_intr: %p, %p = %x @ 0x%x\n",
|
|
|
|
&ring->dmalist[qptr], q, q->len, q->base));
|
|
|
|
|
|
|
|
ring->p += blksize;
|
|
|
|
if (ring->p >= ring->end)
|
|
|
|
ring->p = ring->start;
|
|
|
|
|
|
|
|
qptr = (qptr + 1) & ICH_LVI_MASK;
|
|
|
|
if (ring->intr)
|
|
|
|
ring->intr(ring->arg);
|
|
|
|
}
|
|
|
|
ring->qptr = qptr;
|
|
|
|
|
|
|
|
bus_space_write_1(sc->iot, sc->aud_ioh, pipe + ICH_LVI,
|
|
|
|
(qptr - 1) & ICH_LVI_MASK);
|
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_trigger_output(void *v, void *start, void *end, int blksize,
|
2006-11-16 04:32:37 +03:00
|
|
|
void (*intr)(void *), void *arg, const audio_params_t *param)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
struct auich_dma *p;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
DPRINTF(ICH_DEBUG_DMA,
|
|
|
|
("auich_trigger_output(%p, %p, %d, %p, %p, %p)\n",
|
|
|
|
start, end, blksize, intr, arg, param));
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
|
2005-01-15 18:19:51 +03:00
|
|
|
continue;
|
2000-11-28 08:12:29 +03:00
|
|
|
if (!p) {
|
|
|
|
printf("auich_trigger_output: bad addr %p\n", start);
|
2005-01-15 18:19:51 +03:00
|
|
|
return EINVAL;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
size = (size_t)((char *)end - (char *)start);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
sc->pcmo.intr = intr;
|
|
|
|
sc->pcmo.arg = arg;
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->pcmo.start = DMAADDR(p);
|
|
|
|
sc->pcmo.p = sc->pcmo.start;
|
|
|
|
sc->pcmo.end = sc->pcmo.start + size;
|
|
|
|
sc->pcmo.blksize = blksize;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh, ICH_PCMO + ICH_BDBAR,
|
|
|
|
sc->sc_cddma + ICH_PCMO_OFF(0));
|
2005-03-12 01:29:16 +03:00
|
|
|
auich_trigger_pipe(sc, ICH_PCMO, &sc->pcmo);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
auich_trigger_input(void *v, void *start, void *end, int blksize,
|
2006-11-16 04:32:37 +03:00
|
|
|
void (*intr)(void *), void *arg, const audio_params_t *param)
|
2000-11-28 08:12:29 +03:00
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2000-11-28 08:12:29 +03:00
|
|
|
struct auich_dma *p;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
DPRINTF(ICH_DEBUG_DMA,
|
|
|
|
("auich_trigger_input(%p, %p, %d, %p, %p, %p)\n",
|
|
|
|
start, end, blksize, intr, arg, param));
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = v;
|
2003-01-21 19:05:21 +03:00
|
|
|
|
2000-11-28 08:12:29 +03:00
|
|
|
for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
|
2005-01-15 18:19:51 +03:00
|
|
|
continue;
|
2000-11-28 08:12:29 +03:00
|
|
|
if (!p) {
|
|
|
|
printf("auich_trigger_input: bad addr %p\n", start);
|
2005-01-15 18:19:51 +03:00
|
|
|
return EINVAL;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
size = (size_t)((char *)end - (char *)start);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-03-12 01:29:16 +03:00
|
|
|
sc->pcmi.intr = intr;
|
|
|
|
sc->pcmi.arg = arg;
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->pcmi.start = DMAADDR(p);
|
|
|
|
sc->pcmi.p = sc->pcmi.start;
|
|
|
|
sc->pcmi.end = sc->pcmi.start + size;
|
|
|
|
sc->pcmi.blksize = blksize;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_BDBAR,
|
|
|
|
sc->sc_cddma + ICH_PCMI_OFF(0));
|
2005-03-12 01:29:16 +03:00
|
|
|
auich_trigger_pipe(sc, ICH_PCMI, &sc->pcmi);
|
2000-11-28 08:12:29 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2006-03-07 18:18:59 +03:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
auich_powerstate(void *v, int state)
|
2006-03-07 18:18:59 +03:00
|
|
|
{
|
2006-04-27 16:21:39 +04:00
|
|
|
#if notyet
|
2006-03-07 18:18:59 +03:00
|
|
|
struct auich_softc *sc;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
sc = (struct auich_softc *)v;
|
|
|
|
rv = 0;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case AUDIOPOWER_OFF:
|
|
|
|
auich_powerhook(PWR_SUSPEND, sc);
|
|
|
|
break;
|
|
|
|
case AUDIOPOWER_ON:
|
|
|
|
auich_powerhook(PWR_RESUME, sc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
aprint_error("%s: unknown power state %d\n",
|
|
|
|
sc->sc_dev.dv_xname, state);
|
|
|
|
rv = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2006-04-27 16:21:39 +04:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2006-03-07 18:18:59 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_allocmem(struct auich_softc *sc, size_t size, size_t align,
|
|
|
|
struct auich_dma *p)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
p->size = size;
|
|
|
|
error = bus_dmamem_alloc(sc->dmat, p->size, align, 0,
|
|
|
|
p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
|
|
|
|
&p->nsegs, BUS_DMA_NOWAIT);
|
|
|
|
if (error)
|
2005-01-15 18:19:51 +03:00
|
|
|
return error;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
error = bus_dmamem_map(sc->dmat, p->segs, p->nsegs, p->size,
|
2003-01-28 05:09:34 +03:00
|
|
|
&p->addr, BUS_DMA_NOWAIT|sc->sc_dmamap_flags);
|
2000-11-28 08:12:29 +03:00
|
|
|
if (error)
|
|
|
|
goto free;
|
|
|
|
|
|
|
|
error = bus_dmamap_create(sc->dmat, p->size, 1, p->size,
|
|
|
|
0, BUS_DMA_NOWAIT, &p->map);
|
|
|
|
if (error)
|
|
|
|
goto unmap;
|
|
|
|
|
|
|
|
error = bus_dmamap_load(sc->dmat, p->map, p->addr, p->size, NULL,
|
|
|
|
BUS_DMA_NOWAIT);
|
|
|
|
if (error)
|
|
|
|
goto destroy;
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
destroy:
|
|
|
|
bus_dmamap_destroy(sc->dmat, p->map);
|
|
|
|
unmap:
|
|
|
|
bus_dmamem_unmap(sc->dmat, p->addr, p->size);
|
|
|
|
free:
|
|
|
|
bus_dmamem_free(sc->dmat, p->segs, p->nsegs);
|
2005-01-15 18:19:51 +03:00
|
|
|
return error;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_freemem(struct auich_softc *sc, struct auich_dma *p)
|
|
|
|
{
|
|
|
|
|
|
|
|
bus_dmamap_unload(sc->dmat, p->map);
|
|
|
|
bus_dmamap_destroy(sc->dmat, p->map);
|
|
|
|
bus_dmamem_unmap(sc->dmat, p->addr, p->size);
|
|
|
|
bus_dmamem_free(sc->dmat, p->segs, p->nsegs);
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static int
|
2000-11-28 08:12:29 +03:00
|
|
|
auich_alloc_cdata(struct auich_softc *sc)
|
|
|
|
{
|
|
|
|
bus_dma_segment_t seg;
|
|
|
|
int error, rseg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the control data structure, and create and load the
|
|
|
|
* DMA map for it.
|
|
|
|
*/
|
|
|
|
if ((error = bus_dmamem_alloc(sc->dmat,
|
|
|
|
sizeof(struct auich_cdata),
|
|
|
|
PAGE_SIZE, 0, &seg, 1, &rseg, 0)) != 0) {
|
|
|
|
printf("%s: unable to allocate control data, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
goto fail_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamem_map(sc->dmat, &seg, rseg,
|
|
|
|
sizeof(struct auich_cdata),
|
2007-03-04 08:59:00 +03:00
|
|
|
(void **) &sc->sc_cdata,
|
2003-01-28 05:09:34 +03:00
|
|
|
sc->sc_dmamap_flags)) != 0) {
|
2000-11-28 08:12:29 +03:00
|
|
|
printf("%s: unable to map control data, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
goto fail_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamap_create(sc->dmat, sizeof(struct auich_cdata), 1,
|
|
|
|
sizeof(struct auich_cdata), 0, 0,
|
|
|
|
&sc->sc_cddmamap)) != 0) {
|
|
|
|
printf("%s: unable to create control data DMA map, "
|
|
|
|
"error = %d\n", sc->sc_dev.dv_xname, error);
|
|
|
|
goto fail_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamap_load(sc->dmat, sc->sc_cddmamap,
|
|
|
|
sc->sc_cdata, sizeof(struct auich_cdata),
|
|
|
|
NULL, 0)) != 0) {
|
|
|
|
printf("%s: unable tp load control data DMA map, "
|
|
|
|
"error = %d\n", sc->sc_dev.dv_xname, error);
|
|
|
|
goto fail_3;
|
|
|
|
}
|
|
|
|
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->pcmo.dmalist = sc->sc_cdata->ic_dmalist_pcmo;
|
|
|
|
sc->pcmi.dmalist = sc->sc_cdata->ic_dmalist_pcmi;
|
|
|
|
sc->mici.dmalist = sc->sc_cdata->ic_dmalist_mici;
|
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
return 0;
|
2000-11-28 08:12:29 +03:00
|
|
|
|
|
|
|
fail_3:
|
|
|
|
bus_dmamap_destroy(sc->dmat, sc->sc_cddmamap);
|
|
|
|
fail_2:
|
2007-03-04 08:59:00 +03:00
|
|
|
bus_dmamem_unmap(sc->dmat, (void *) sc->sc_cdata,
|
2000-11-28 08:12:29 +03:00
|
|
|
sizeof(struct auich_cdata));
|
|
|
|
fail_1:
|
|
|
|
bus_dmamem_free(sc->dmat, &seg, rseg);
|
|
|
|
fail_0:
|
2005-01-15 18:19:51 +03:00
|
|
|
return error;
|
2000-11-28 08:12:29 +03:00
|
|
|
}
|
2002-02-02 14:13:44 +03:00
|
|
|
|
2004-11-17 18:14:38 +03:00
|
|
|
static void
|
2002-02-02 14:13:44 +03:00
|
|
|
auich_powerhook(int why, void *addr)
|
|
|
|
{
|
2005-01-15 18:19:51 +03:00
|
|
|
struct auich_softc *sc;
|
2002-02-02 14:13:44 +03:00
|
|
|
|
2005-01-15 18:19:51 +03:00
|
|
|
sc = (struct auich_softc *)addr;
|
2002-02-02 14:13:44 +03:00
|
|
|
switch (why) {
|
|
|
|
case PWR_SUSPEND:
|
|
|
|
case PWR_STANDBY:
|
|
|
|
/* Power down */
|
|
|
|
DPRINTF(1, ("%s: power down\n", sc->sc_dev.dv_xname));
|
2006-03-08 02:16:20 +03:00
|
|
|
|
|
|
|
/* if we're already asleep, don't try to sleep again */
|
|
|
|
if (sc->sc_suspend == PWR_SUSPEND ||
|
|
|
|
sc->sc_suspend == PWR_STANDBY)
|
|
|
|
break;
|
2002-02-02 14:13:44 +03:00
|
|
|
sc->sc_suspend = why;
|
2006-03-07 18:18:59 +03:00
|
|
|
|
|
|
|
DELAY(1000);
|
2005-01-27 00:53:42 +03:00
|
|
|
pci_conf_capture(sc->sc_pc, sc->sc_pt, &sc->sc_pciconf);
|
2006-03-07 18:18:59 +03:00
|
|
|
|
|
|
|
if (sc->sc_ih != NULL)
|
|
|
|
pci_intr_disestablish(sc->sc_pc, sc->sc_ih);
|
|
|
|
|
2002-02-02 14:13:44 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PWR_RESUME:
|
|
|
|
/* Wake up */
|
|
|
|
DPRINTF(1, ("%s: power resume\n", sc->sc_dev.dv_xname));
|
|
|
|
if (sc->sc_suspend == PWR_RESUME) {
|
|
|
|
printf("%s: resume without suspend.\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
sc->sc_suspend = why;
|
|
|
|
return;
|
|
|
|
}
|
2006-03-07 18:18:59 +03:00
|
|
|
|
|
|
|
sc->sc_ih = pci_intr_establish(sc->sc_pc, sc->intrh, IPL_AUDIO,
|
|
|
|
auich_intr, sc);
|
|
|
|
if (sc->sc_ih == NULL) {
|
|
|
|
aprint_error("%s: can't establish interrupt",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
/* XXX jmcneill what should we do here? */
|
|
|
|
return;
|
|
|
|
}
|
2005-01-27 00:53:42 +03:00
|
|
|
pci_conf_restore(sc->sc_pc, sc->sc_pt, &sc->sc_pciconf);
|
2002-02-02 14:13:44 +03:00
|
|
|
sc->sc_suspend = why;
|
|
|
|
auich_reset_codec(sc);
|
|
|
|
DELAY(1000);
|
|
|
|
(sc->codec_if->vtbl->restore_ports)(sc->codec_if);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PWR_SOFTSUSPEND:
|
|
|
|
case PWR_SOFTSTANDBY:
|
|
|
|
case PWR_SOFTRESUME:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-08-07 14:31:09 +04:00
|
|
|
|
2004-08-07 20:12:57 +04:00
|
|
|
/*
|
|
|
|
* Calibrate card (some boards are overclocked and need scaling)
|
|
|
|
*/
|
2004-11-17 18:14:38 +03:00
|
|
|
static void
|
2003-10-02 11:41:53 +04:00
|
|
|
auich_calibrate(struct auich_softc *sc)
|
2002-08-07 14:31:09 +04:00
|
|
|
{
|
|
|
|
struct timeval t1, t2;
|
2003-10-31 11:15:53 +03:00
|
|
|
uint8_t ociv, nciv;
|
|
|
|
uint64_t wait_us;
|
|
|
|
uint32_t actual_48k_rate, bytes, ac97rate;
|
2002-08-07 14:31:09 +04:00
|
|
|
void *temp_buffer;
|
|
|
|
struct auich_dma *p;
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
u_int rate;
|
2002-08-07 14:31:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab audio from input for fixed interval and compare how
|
|
|
|
* much we actually get with what we expect. Interval needs
|
|
|
|
* to be sufficiently short that no interrupts are
|
|
|
|
* generated.
|
|
|
|
*/
|
|
|
|
|
2003-11-06 10:13:33 +03:00
|
|
|
/* Force the codec to a known state first. */
|
|
|
|
sc->codec_if->vtbl->set_clock(sc->codec_if, 48000);
|
2004-11-10 17:14:09 +03:00
|
|
|
rate = sc->sc_ac97_clock = 48000;
|
2003-11-06 10:13:33 +03:00
|
|
|
sc->codec_if->vtbl->set_rate(sc->codec_if, AC97_REG_PCM_LR_ADC_RATE,
|
|
|
|
&rate);
|
|
|
|
|
2002-08-07 14:31:09 +04:00
|
|
|
/* Setup a buffer */
|
2003-10-31 11:15:53 +03:00
|
|
|
bytes = 64000;
|
2002-08-07 14:31:09 +04:00
|
|
|
temp_buffer = auich_allocm(sc, AUMODE_RECORD, bytes, M_DEVBUF, M_WAITOK);
|
2003-11-06 10:13:33 +03:00
|
|
|
|
2002-08-07 14:31:09 +04:00
|
|
|
for (p = sc->sc_dmas; p && KERNADDR(p) != temp_buffer; p = p->next)
|
2005-01-15 18:19:51 +03:00
|
|
|
continue;
|
2002-08-07 14:31:09 +04:00
|
|
|
if (p == NULL) {
|
|
|
|
printf("auich_calibrate: bad address %p\n", temp_buffer);
|
2002-10-11 08:11:28 +04:00
|
|
|
return;
|
2002-08-07 14:31:09 +04:00
|
|
|
}
|
2004-11-01 09:25:35 +03:00
|
|
|
sc->pcmi.dmalist[0].base = DMAADDR(p);
|
|
|
|
sc->pcmi.dmalist[0].len = (bytes >> sc->sc_sample_shift);
|
2002-08-07 14:31:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* our data format is stereo, 16 bit so each sample is 4 bytes.
|
|
|
|
* assuming we get 48000 samples per second, we get 192000 bytes/sec.
|
|
|
|
* we're going to start recording with interrupts disabled and measure
|
|
|
|
* the time taken for one block to complete. we know the block size,
|
|
|
|
* we know the time in microseconds, we calculate the sample rate:
|
|
|
|
*
|
|
|
|
* actual_rate [bps] = bytes / (time [s] * 4)
|
|
|
|
* actual_rate [bps] = (bytes * 1000000) / (time [us] * 4)
|
|
|
|
* actual_rate [Hz] = (bytes * 250000) / time [us]
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* prepare */
|
|
|
|
ociv = bus_space_read_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_CIV);
|
|
|
|
bus_space_write_4(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_BDBAR,
|
|
|
|
sc->sc_cddma + ICH_PCMI_OFF(0));
|
|
|
|
bus_space_write_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_LVI,
|
|
|
|
(0 - 1) & ICH_LVI_MASK);
|
|
|
|
|
|
|
|
/* start */
|
|
|
|
microtime(&t1);
|
|
|
|
bus_space_write_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_CTRL, ICH_RPBM);
|
|
|
|
|
|
|
|
/* wait */
|
2003-10-29 01:56:19 +03:00
|
|
|
nciv = ociv;
|
2003-10-02 11:41:53 +04:00
|
|
|
do {
|
2002-08-07 14:31:09 +04:00
|
|
|
microtime(&t2);
|
|
|
|
if (t2.tv_sec - t1.tv_sec > 1)
|
|
|
|
break;
|
|
|
|
nciv = bus_space_read_1(sc->iot, sc->aud_ioh,
|
|
|
|
ICH_PCMI + ICH_CIV);
|
2003-10-02 11:41:53 +04:00
|
|
|
} while (nciv == ociv);
|
2003-10-31 11:15:53 +03:00
|
|
|
microtime(&t2);
|
2002-08-07 14:31:09 +04:00
|
|
|
|
|
|
|
/* stop */
|
|
|
|
bus_space_write_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_CTRL, 0);
|
|
|
|
|
|
|
|
/* reset */
|
|
|
|
DELAY(100);
|
|
|
|
bus_space_write_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_CTRL, ICH_RR);
|
|
|
|
|
|
|
|
/* turn time delta into us */
|
|
|
|
wait_us = ((t2.tv_sec - t1.tv_sec) * 1000000) + t2.tv_usec - t1.tv_usec;
|
|
|
|
|
|
|
|
auich_freem(sc, temp_buffer, M_DEVBUF);
|
|
|
|
|
|
|
|
if (nciv == ociv) {
|
2003-10-31 11:15:53 +03:00
|
|
|
printf("%s: ac97 link rate calibration timed out after %"
|
|
|
|
PRIu64 " us\n", sc->sc_dev.dv_xname, wait_us);
|
2002-10-11 08:11:28 +04:00
|
|
|
return;
|
2002-08-07 14:31:09 +04:00
|
|
|
}
|
|
|
|
|
2003-10-31 11:15:53 +03:00
|
|
|
actual_48k_rate = (bytes * UINT64_C(250000)) / wait_us;
|
2002-08-07 14:31:09 +04:00
|
|
|
|
2003-10-31 11:15:53 +03:00
|
|
|
if (actual_48k_rate < 50000)
|
2002-10-11 08:11:28 +04:00
|
|
|
ac97rate = 48000;
|
|
|
|
else
|
2003-10-31 11:15:53 +03:00
|
|
|
ac97rate = ((actual_48k_rate + 500) / 1000) * 1000;
|
2002-08-07 14:31:09 +04:00
|
|
|
|
2002-10-11 08:11:28 +04:00
|
|
|
printf("%s: measured ac97 link rate at %d Hz",
|
|
|
|
sc->sc_dev.dv_xname, actual_48k_rate);
|
|
|
|
if (ac97rate != actual_48k_rate)
|
|
|
|
printf(", will use %d Hz", ac97rate);
|
|
|
|
printf("\n");
|
2002-08-07 14:31:09 +04:00
|
|
|
|
2004-10-27 17:26:43 +04:00
|
|
|
sc->sc_ac97_clock = ac97rate;
|
2002-08-07 14:31:09 +04:00
|
|
|
}
|
2005-04-12 21:30:51 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
auich_clear_cas(struct auich_softc *sc)
|
|
|
|
{
|
|
|
|
/* Clear the codec access semaphore */
|
|
|
|
(void)bus_space_read_2(sc->iot, sc->mix_ioh,
|
|
|
|
AC97_REG_RESET * (sc->sc_codecnum * ICH_CODEC_OFFSET));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|