2007-05-13 07:30:46 +04:00
|
|
|
/* $NetBSD: azalia.c,v 1.50 2007/05/13 03:30:47 kent Exp $ */
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2005 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by TAMURA Kent
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2005-06-19 11:42:39 +04:00
|
|
|
/*
|
2005-08-02 15:17:56 +04:00
|
|
|
* High Definition Audio Specification
|
|
|
|
* ftp://download.intel.com/standards/hdaudio/pdf/HDAudio_03.pdf
|
|
|
|
*
|
|
|
|
*
|
2005-06-19 11:42:39 +04:00
|
|
|
* TO DO:
|
2005-06-20 15:48:47 +04:00
|
|
|
* - power hook
|
2005-08-02 15:17:56 +04:00
|
|
|
* - multiple codecs (needed?)
|
|
|
|
* - multiple streams (needed?)
|
2005-06-19 11:42:39 +04:00
|
|
|
*/
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
#include <sys/cdefs.h>
|
2007-05-13 07:30:46 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: azalia.c,v 1.50 2007/05/13 03:30:47 kent Exp $");
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <dev/audio_if.h>
|
|
|
|
#include <dev/auconv.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
|
2005-09-28 17:06:49 +04:00
|
|
|
#include <dev/pci/azalia.h>
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* ICH6/ICH7 constant values
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* PCI registers */
|
|
|
|
#define ICH_PCI_HDBARL 0x10
|
|
|
|
#define ICH_PCI_HDBARU 0x14
|
|
|
|
#define ICH_PCI_HDCTL 0x40
|
|
|
|
#define ICH_PCI_HDCTL_CLKDETCLR 0x08
|
|
|
|
#define ICH_PCI_HDCTL_CLKDETEN 0x04
|
|
|
|
#define ICH_PCI_HDCTL_CLKDETINV 0x02
|
|
|
|
#define ICH_PCI_HDCTL_SIGNALMODE 0x01
|
|
|
|
|
|
|
|
/* internal types */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
bus_dmamap_t map;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *addr; /* kernel virtual address */
|
2005-06-18 14:43:46 +04:00
|
|
|
bus_dma_segment_t segments[1];
|
|
|
|
size_t size;
|
|
|
|
} azalia_dma_t;
|
|
|
|
#define AZALIA_DMA_DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
|
|
|
|
|
|
|
|
typedef struct {
|
2005-06-21 18:51:37 +04:00
|
|
|
struct azalia_t *az;
|
2005-06-18 14:43:46 +04:00
|
|
|
int regbase;
|
|
|
|
int number;
|
2005-06-21 18:51:37 +04:00
|
|
|
int dir; /* AUMODE_PLAY or AUMODE_RECORD */
|
2005-06-18 14:43:46 +04:00
|
|
|
uint32_t intr_bit;
|
|
|
|
azalia_dma_t bdlist;
|
|
|
|
azalia_dma_t buffer;
|
|
|
|
void (*intr)(void*);
|
|
|
|
void *intr_arg;
|
|
|
|
bus_addr_t dmaend, dmanext; /* XXX needed? */
|
|
|
|
} stream_t;
|
2005-06-21 18:51:37 +04:00
|
|
|
#define STR_READ_1(s, r) \
|
|
|
|
bus_space_read_1((s)->az->iot, (s)->az->ioh, (s)->regbase + HDA_SD_##r)
|
|
|
|
#define STR_READ_2(s, r) \
|
|
|
|
bus_space_read_2((s)->az->iot, (s)->az->ioh, (s)->regbase + HDA_SD_##r)
|
|
|
|
#define STR_READ_4(s, r) \
|
|
|
|
bus_space_read_4((s)->az->iot, (s)->az->ioh, (s)->regbase + HDA_SD_##r)
|
|
|
|
#define STR_WRITE_1(s, r, v) \
|
|
|
|
bus_space_write_1((s)->az->iot, (s)->az->ioh, (s)->regbase + HDA_SD_##r, v)
|
|
|
|
#define STR_WRITE_2(s, r, v) \
|
|
|
|
bus_space_write_2((s)->az->iot, (s)->az->ioh, (s)->regbase + HDA_SD_##r, v)
|
|
|
|
#define STR_WRITE_4(s, r, v) \
|
|
|
|
bus_space_write_4((s)->az->iot, (s)->az->ioh, (s)->regbase + HDA_SD_##r, v)
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
typedef struct azalia_t {
|
|
|
|
struct device dev;
|
|
|
|
struct device *audiodev;
|
|
|
|
|
2005-06-25 20:32:39 +04:00
|
|
|
pci_chipset_tag_t pc;
|
2005-06-18 14:43:46 +04:00
|
|
|
void *ih;
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
2005-06-25 20:32:39 +04:00
|
|
|
bus_size_t map_size;
|
2005-06-18 14:43:46 +04:00
|
|
|
bus_dma_tag_t dmat;
|
2006-07-13 07:57:40 +04:00
|
|
|
pcireg_t pciid;
|
2006-06-07 19:23:59 +04:00
|
|
|
uint32_t subid;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
codec_t codecs[15];
|
2005-09-26 21:30:04 +04:00
|
|
|
int ncodecs; /* number of codecs */
|
|
|
|
int codecno; /* index of the using codec */
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
azalia_dma_t corb_dma;
|
|
|
|
int corb_size;
|
|
|
|
azalia_dma_t rirb_dma;
|
|
|
|
int rirb_size;
|
|
|
|
int rirb_rp;
|
2006-06-25 09:05:51 +04:00
|
|
|
#define UNSOLQ_SIZE 256
|
|
|
|
rirb_entry_t *unsolq;
|
|
|
|
int unsolq_wp;
|
|
|
|
int unsolq_rp;
|
2007-02-22 01:59:35 +03:00
|
|
|
bool unsolq_kick;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
bool ok64;
|
2005-06-18 14:43:46 +04:00
|
|
|
int nistreams, nostreams, nbstreams;
|
|
|
|
stream_t pstream;
|
|
|
|
stream_t rstream;
|
|
|
|
} azalia_t;
|
|
|
|
#define XNAME(sc) ((sc)->dev.dv_xname)
|
|
|
|
#define AZ_READ_1(z, r) bus_space_read_1((z)->iot, (z)->ioh, HDA_##r)
|
|
|
|
#define AZ_READ_2(z, r) bus_space_read_2((z)->iot, (z)->ioh, HDA_##r)
|
|
|
|
#define AZ_READ_4(z, r) bus_space_read_4((z)->iot, (z)->ioh, HDA_##r)
|
|
|
|
#define AZ_WRITE_1(z, r, v) bus_space_write_1((z)->iot, (z)->ioh, HDA_##r, v)
|
|
|
|
#define AZ_WRITE_2(z, r, v) bus_space_write_2((z)->iot, (z)->ioh, HDA_##r, v)
|
|
|
|
#define AZ_WRITE_4(z, r, v) bus_space_write_4((z)->iot, (z)->ioh, HDA_##r, v)
|
|
|
|
|
|
|
|
|
|
|
|
/* prototypes */
|
|
|
|
static int azalia_pci_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void azalia_pci_attach(struct device *, struct device *, void *);
|
2005-06-25 20:32:39 +04:00
|
|
|
static int azalia_pci_activate(struct device *, enum devact);
|
2005-06-18 14:43:46 +04:00
|
|
|
static int azalia_pci_detach(struct device *, int);
|
|
|
|
static int azalia_intr(void *);
|
|
|
|
static int azalia_attach(azalia_t *);
|
|
|
|
static void azalia_attach_intr(struct device *);
|
|
|
|
static int azalia_init_corb(azalia_t *);
|
2005-06-25 20:32:39 +04:00
|
|
|
static int azalia_delete_corb(azalia_t *);
|
2005-06-18 14:43:46 +04:00
|
|
|
static int azalia_init_rirb(azalia_t *);
|
2005-06-25 20:32:39 +04:00
|
|
|
static int azalia_delete_rirb(azalia_t *);
|
2005-06-20 15:48:47 +04:00
|
|
|
static int azalia_set_command(const azalia_t *, nid_t, int, uint32_t,
|
|
|
|
uint32_t);
|
2005-06-18 14:43:46 +04:00
|
|
|
static int azalia_get_response(azalia_t *, uint32_t *);
|
2006-06-25 09:05:51 +04:00
|
|
|
static void azalia_rirb_kick_unsol_events(azalia_t *);
|
|
|
|
static void azalia_rirb_intr(azalia_t *);
|
2005-06-18 14:43:46 +04:00
|
|
|
static int azalia_alloc_dmamem(azalia_t *, size_t, size_t, azalia_dma_t *);
|
|
|
|
static int azalia_free_dmamem(const azalia_t *, azalia_dma_t*);
|
|
|
|
|
|
|
|
static int azalia_codec_init(codec_t *);
|
2005-06-25 20:32:39 +04:00
|
|
|
static int azalia_codec_delete(codec_t *);
|
|
|
|
static void azalia_codec_add_bits(codec_t *, int, uint32_t, int);
|
2005-06-20 15:48:47 +04:00
|
|
|
static void azalia_codec_add_format(codec_t *, int, int, int, uint32_t,
|
|
|
|
int32_t);
|
2005-06-18 14:43:46 +04:00
|
|
|
static int azalia_codec_comresp(const codec_t *, nid_t, uint32_t,
|
|
|
|
uint32_t, uint32_t *);
|
|
|
|
static int azalia_codec_connect_stream(codec_t *, int, uint16_t, int);
|
2006-06-25 17:41:58 +04:00
|
|
|
static int azalia_codec_disconnect_stream(codec_t *, int);
|
2005-06-18 14:43:46 +04:00
|
|
|
|
2007-03-11 17:34:04 +03:00
|
|
|
static int azalia_widget_init(widget_t *, const codec_t *, int, const char *);
|
|
|
|
static int azalia_widget_init_audio(widget_t *, const codec_t *, const char *);
|
2006-06-09 20:26:58 +04:00
|
|
|
static int azalia_widget_print_audio(const widget_t *, const char *, int);
|
2005-06-18 14:43:46 +04:00
|
|
|
static int azalia_widget_init_pin(widget_t *, const codec_t *);
|
2007-03-11 17:34:04 +03:00
|
|
|
static int azalia_widget_print_pin(const widget_t *, const char *);
|
|
|
|
static int azalia_widget_init_connection(widget_t *, const codec_t *, const char *);
|
2005-06-18 14:43:46 +04:00
|
|
|
|
2005-06-21 18:51:37 +04:00
|
|
|
static int azalia_stream_init(stream_t *, azalia_t *, int, int, int);
|
2005-06-25 20:32:39 +04:00
|
|
|
static int azalia_stream_delete(stream_t *, azalia_t *);
|
2005-06-21 18:51:37 +04:00
|
|
|
static int azalia_stream_reset(stream_t *);
|
|
|
|
static int azalia_stream_start(stream_t *, void *, void *, int,
|
|
|
|
void (*)(void *), void *, uint16_t);
|
|
|
|
static int azalia_stream_halt(stream_t *);
|
|
|
|
static int azalia_stream_intr(stream_t *, uint32_t);
|
|
|
|
|
2005-06-19 20:32:55 +04:00
|
|
|
static int azalia_open(void *, int);
|
|
|
|
static void azalia_close(void *);
|
2005-06-18 14:43:46 +04:00
|
|
|
static int azalia_query_encoding(void *, audio_encoding_t *);
|
|
|
|
static int azalia_set_params(void *, int, int, audio_params_t *,
|
|
|
|
audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
|
|
|
|
static int azalia_round_blocksize(void *, int, int, const audio_params_t *);
|
|
|
|
static int azalia_halt_output(void *);
|
|
|
|
static int azalia_halt_input(void *);
|
|
|
|
static int azalia_getdev(void *, struct audio_device *);
|
|
|
|
static int azalia_set_port(void *, mixer_ctrl_t *);
|
|
|
|
static int azalia_get_port(void *, mixer_ctrl_t *);
|
|
|
|
static int azalia_query_devinfo(void *, mixer_devinfo_t *);
|
|
|
|
static void *azalia_allocm(void *, int, size_t, struct malloc_type *, int);
|
|
|
|
static void azalia_freem(void *, void *, struct malloc_type *);
|
|
|
|
static size_t azalia_round_buffersize(void *, int, size_t);
|
|
|
|
static int azalia_get_props(void *);
|
|
|
|
static int azalia_trigger_output(void *, void *, void *, int,
|
|
|
|
void (*)(void *), void *, const audio_params_t *);
|
|
|
|
static int azalia_trigger_input(void *, void *, void *, int,
|
|
|
|
void (*)(void *), void *, const audio_params_t *);
|
|
|
|
|
|
|
|
static int azalia_params2fmt(const audio_params_t *, uint16_t *);
|
|
|
|
|
|
|
|
/* variables */
|
|
|
|
CFATTACH_DECL(azalia, sizeof(azalia_t),
|
2005-06-25 20:32:39 +04:00
|
|
|
azalia_pci_match, azalia_pci_attach, azalia_pci_detach, azalia_pci_activate);
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
static const struct audio_hw_if azalia_hw_if = {
|
2005-06-19 20:32:55 +04:00
|
|
|
azalia_open,
|
|
|
|
azalia_close,
|
2005-06-18 14:43:46 +04:00
|
|
|
NULL, /* drain */
|
|
|
|
azalia_query_encoding,
|
|
|
|
azalia_set_params,
|
|
|
|
azalia_round_blocksize,
|
|
|
|
NULL, /* commit_settings */
|
|
|
|
NULL, /* init_output */
|
|
|
|
NULL, /* init_input */
|
|
|
|
NULL, /* start_output */
|
|
|
|
NULL, /* satart_inpu */
|
|
|
|
azalia_halt_output,
|
|
|
|
azalia_halt_input,
|
|
|
|
NULL, /* speaker_ctl */
|
|
|
|
azalia_getdev,
|
|
|
|
NULL, /* setfd */
|
|
|
|
azalia_set_port,
|
|
|
|
azalia_get_port,
|
|
|
|
azalia_query_devinfo,
|
|
|
|
azalia_allocm,
|
|
|
|
azalia_freem,
|
|
|
|
azalia_round_buffersize,
|
|
|
|
NULL, /* mappage */
|
|
|
|
azalia_get_props,
|
|
|
|
azalia_trigger_output,
|
|
|
|
azalia_trigger_input,
|
|
|
|
NULL, /* dev_ioctl */
|
2006-08-28 04:04:21 +04:00
|
|
|
NULL, /* powerstate */
|
2005-06-18 14:43:46 +04:00
|
|
|
};
|
|
|
|
|
2005-06-19 11:42:39 +04:00
|
|
|
static const char *pin_colors[16] = {
|
|
|
|
"unknown", "black", "gray", "blue",
|
|
|
|
"green", "red", "orange", "yellow",
|
2005-06-19 16:34:36 +04:00
|
|
|
"purple", "pink", "col0a", "col0b",
|
|
|
|
"col0c", "col0d", "white", "other"};
|
2005-06-19 11:42:39 +04:00
|
|
|
#ifdef AZALIA_DEBUG
|
|
|
|
static const char *pin_devices[16] = {
|
|
|
|
"line-out", AudioNspeaker, AudioNheadphone, AudioNcd,
|
|
|
|
"SPDIF-out", "digital-out", "modem-line", "modem-handset",
|
|
|
|
"line-in", AudioNaux, AudioNmicrophone, "telephony",
|
2005-06-19 16:34:36 +04:00
|
|
|
"SPDIF-in", "digital-in", "dev0e", "other"};
|
2005-06-19 11:42:39 +04:00
|
|
|
#endif
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
/* ================================================================
|
|
|
|
* PCI functions
|
|
|
|
* ================================================================ */
|
|
|
|
|
2006-07-13 07:57:40 +04:00
|
|
|
#define PCI_ID_CODE0(v, p) PCI_ID_CODE(PCI_VENDOR_##v, PCI_PRODUCT_##v##_##p)
|
|
|
|
#define PCIID_MCP55 PCI_ID_CODE0(NVIDIA, MCP55_HDA)
|
2006-07-21 21:30:26 +04:00
|
|
|
#define PCIID_VT8237A PCI_ID_CODE0(VIATECH, VT8237A_HDA)
|
2006-07-13 07:57:40 +04:00
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
azalia_pci_match(struct device *parent, struct cfdata *match,
|
2006-10-12 05:30:41 +04:00
|
|
|
void *aux)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
struct pci_attach_args *pa;
|
|
|
|
|
|
|
|
pa = aux;
|
|
|
|
if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MULTIMEDIA
|
2007-05-13 07:30:46 +04:00
|
|
|
&& PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MULTIMEDIA_HDAUDIO)
|
2005-06-18 14:43:46 +04:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
azalia_pci_attach(struct device *parent, struct device *self,
|
2006-10-12 05:30:41 +04:00
|
|
|
void *aux)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
azalia_t *sc;
|
|
|
|
struct pci_attach_args *pa;
|
|
|
|
pcireg_t v;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
const char *intrrupt_str;
|
2005-06-20 15:48:47 +04:00
|
|
|
const char *name;
|
2006-06-28 02:02:14 +04:00
|
|
|
const char *vendor;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
sc = (azalia_t*)self;
|
|
|
|
pa = aux;
|
|
|
|
|
|
|
|
sc->dmat = pa->pa_dmat;
|
|
|
|
aprint_normal(": Generic High Definition Audio Controller\n");
|
2006-05-07 12:31:44 +04:00
|
|
|
|
|
|
|
v = pci_conf_read(pa->pa_pc, pa->pa_tag, ICH_PCI_HDBARL);
|
|
|
|
v &= PCI_MAPREG_TYPE_MASK | PCI_MAPREG_MEM_TYPE_MASK;
|
|
|
|
if (pci_mapreg_map(pa, ICH_PCI_HDBARL, v, 0,
|
2005-06-25 20:32:39 +04:00
|
|
|
&sc->iot, &sc->ioh, NULL, &sc->map_size)) {
|
2005-06-18 14:43:46 +04:00
|
|
|
aprint_error("%s: can't map device i/o space\n", XNAME(sc));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable bus mastering */
|
|
|
|
v = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
|
|
|
|
pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
|
|
|
|
v | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_BACKTOBACK_ENABLE);
|
|
|
|
|
|
|
|
/* interrupt */
|
|
|
|
if (pci_intr_map(pa, &ih)) {
|
|
|
|
aprint_error("%s: can't map interrupt\n", XNAME(sc));
|
|
|
|
return;
|
|
|
|
}
|
2005-06-25 20:32:39 +04:00
|
|
|
sc->pc = pa->pa_pc;
|
2005-06-18 14:43:46 +04:00
|
|
|
intrrupt_str = pci_intr_string(pa->pa_pc, ih);
|
|
|
|
sc->ih = pci_intr_establish(pa->pa_pc, ih, IPL_AUDIO, azalia_intr, sc);
|
|
|
|
if (sc->ih == NULL) {
|
|
|
|
aprint_error("%s: can't establish interrupt", XNAME(sc));
|
|
|
|
if (intrrupt_str != NULL)
|
|
|
|
aprint_error(" at %s", intrrupt_str);
|
|
|
|
aprint_error("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aprint_normal("%s: interrupting at %s\n", XNAME(sc), intrrupt_str);
|
|
|
|
|
2006-07-13 07:57:40 +04:00
|
|
|
sc->pciid = pa->pa_id;
|
2006-06-28 02:02:14 +04:00
|
|
|
vendor = pci_findvendor(pa->pa_id);
|
2005-06-20 15:48:47 +04:00
|
|
|
name = pci_findproduct(pa->pa_id);
|
2006-06-28 02:02:14 +04:00
|
|
|
if (vendor != NULL && name != NULL) {
|
|
|
|
aprint_normal("%s: host: %s %s (rev. %d)\n",
|
|
|
|
XNAME(sc), vendor, name, PCI_REVISION(pa->pa_class));
|
2005-06-20 15:48:47 +04:00
|
|
|
} else {
|
|
|
|
aprint_normal("%s: host: 0x%4.4x/0x%4.4x (rev. %d)\n",
|
|
|
|
XNAME(sc), PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id),
|
|
|
|
PCI_REVISION(pa->pa_class));
|
|
|
|
}
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
if (azalia_attach(sc)) {
|
|
|
|
aprint_error("%s: initialization failure\n", XNAME(sc));
|
2005-06-25 20:32:39 +04:00
|
|
|
azalia_pci_detach(self, 0);
|
2005-06-18 14:43:46 +04:00
|
|
|
return;
|
|
|
|
}
|
2006-06-07 19:23:59 +04:00
|
|
|
sc->subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
config_interrupts(self, azalia_attach_intr);
|
|
|
|
}
|
|
|
|
|
2005-06-25 20:32:39 +04:00
|
|
|
static int
|
|
|
|
azalia_pci_activate(struct device *self, enum devact act)
|
|
|
|
{
|
|
|
|
azalia_t *sc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
sc = (azalia_t*)self;
|
|
|
|
ret = 0;
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
if (sc->audiodev != NULL)
|
|
|
|
ret = config_deactivate(sc->audiodev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
static int
|
|
|
|
azalia_pci_detach(struct device *self, int flags)
|
|
|
|
{
|
|
|
|
azalia_t *az;
|
2005-06-25 20:32:39 +04:00
|
|
|
int i;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
2006-06-28 02:02:14 +04:00
|
|
|
DPRINTF(("%s\n", __func__));
|
2005-06-18 14:43:46 +04:00
|
|
|
az = (azalia_t*)self;
|
2005-06-25 20:32:39 +04:00
|
|
|
if (az->audiodev != NULL) {
|
|
|
|
config_detach(az->audiodev, flags);
|
|
|
|
az->audiodev = NULL;
|
|
|
|
}
|
2006-06-28 02:02:14 +04:00
|
|
|
|
|
|
|
DPRINTF(("%s: delete streams\n", __func__));
|
2005-06-25 20:32:39 +04:00
|
|
|
azalia_stream_delete(&az->rstream, az);
|
|
|
|
azalia_stream_delete(&az->pstream, az);
|
2006-06-28 02:02:14 +04:00
|
|
|
|
|
|
|
DPRINTF(("%s: delete codecs\n", __func__));
|
2005-06-25 20:32:39 +04:00
|
|
|
for (i = 0; i < az->ncodecs; i++) {
|
|
|
|
azalia_codec_delete(&az->codecs[i]);
|
|
|
|
}
|
|
|
|
az->ncodecs = 0;
|
2006-06-28 02:02:14 +04:00
|
|
|
|
|
|
|
DPRINTF(("%s: delete CORB and RIRB\n", __func__));
|
2005-06-25 20:32:39 +04:00
|
|
|
azalia_delete_corb(az);
|
|
|
|
azalia_delete_rirb(az);
|
2006-06-28 02:02:14 +04:00
|
|
|
|
|
|
|
DPRINTF(("%s: delete PCI resources\n", __func__));
|
2005-06-25 20:32:39 +04:00
|
|
|
if (az->ih != NULL) {
|
|
|
|
pci_intr_disestablish(az->pc, az->ih);
|
|
|
|
az->ih = NULL;
|
|
|
|
}
|
|
|
|
if (az->map_size != 0) {
|
|
|
|
bus_space_unmap(az->iot, az->ioh, az->map_size);
|
|
|
|
az->map_size = 0;
|
|
|
|
}
|
2005-06-18 14:43:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_intr(void *v)
|
|
|
|
{
|
|
|
|
azalia_t *az;
|
|
|
|
int ret;
|
|
|
|
uint32_t intsts;
|
|
|
|
uint8_t rirbsts;
|
|
|
|
|
|
|
|
az = v;
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
intsts = AZ_READ_4(az, INTSTS);
|
|
|
|
if (intsts == 0)
|
|
|
|
return ret;
|
|
|
|
|
2005-06-21 18:51:37 +04:00
|
|
|
ret += azalia_stream_intr(&az->pstream, intsts);
|
|
|
|
ret += azalia_stream_intr(&az->rstream, intsts);
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
rirbsts = AZ_READ_1(az, RIRBSTS);
|
|
|
|
if (rirbsts & (HDA_RIRBSTS_RIRBOIS | HDA_RIRBSTS_RINTFL)) {
|
|
|
|
if (rirbsts & HDA_RIRBSTS_RINTFL) {
|
2006-06-25 09:05:51 +04:00
|
|
|
azalia_rirb_intr(az);
|
2005-06-18 14:43:46 +04:00
|
|
|
} else {
|
2006-06-25 09:05:51 +04:00
|
|
|
/*printf("[Overflow!]");*/
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
AZ_WRITE_1(az, RIRBSTS,
|
|
|
|
rirbsts | HDA_RIRBSTS_RIRBOIS | HDA_RIRBSTS_RINTFL);
|
|
|
|
ret++;
|
|
|
|
}
|
2006-06-25 09:05:51 +04:00
|
|
|
|
2005-09-28 17:06:49 +04:00
|
|
|
return ret;
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ================================================================
|
|
|
|
* HDA controller functions
|
|
|
|
* ================================================================ */
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_attach(azalia_t *az)
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
uint32_t gctl;
|
|
|
|
uint16_t gcap;
|
|
|
|
uint16_t statests;
|
|
|
|
|
2005-06-20 15:48:47 +04:00
|
|
|
aprint_normal("%s: host: High Definition Audio rev. %d.%d\n",
|
2005-06-18 14:43:46 +04:00
|
|
|
XNAME(az), AZ_READ_1(az, VMAJ), AZ_READ_1(az, VMIN));
|
|
|
|
gcap = AZ_READ_2(az, GCAP);
|
|
|
|
az->nistreams = HDA_GCAP_ISS(gcap);
|
|
|
|
az->nostreams = HDA_GCAP_OSS(gcap);
|
|
|
|
az->nbstreams = HDA_GCAP_BSS(gcap);
|
2005-09-26 21:30:04 +04:00
|
|
|
az->ok64 = (gcap & HDA_GCAP_64OK) != 0;
|
2005-06-20 15:48:47 +04:00
|
|
|
DPRINTF(("%s: host: %d output, %d input, and %d bidi streams\n",
|
2005-06-18 14:43:46 +04:00
|
|
|
XNAME(az), az->nostreams, az->nistreams, az->nbstreams));
|
|
|
|
|
|
|
|
/* 4.2.2 Starting the High Definition Audio Controller */
|
|
|
|
DPRINTF(("%s: resetting\n", __func__));
|
|
|
|
gctl = AZ_READ_4(az, GCTL);
|
|
|
|
AZ_WRITE_4(az, GCTL, gctl & ~HDA_GCTL_CRST);
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
DELAY(10);
|
|
|
|
if ((AZ_READ_4(az, GCTL) & HDA_GCTL_CRST) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DPRINTF(("%s: reset counter = %d\n", __func__, i));
|
|
|
|
if (i <= 0) {
|
|
|
|
aprint_error("%s: reset failure\n", XNAME(az));
|
|
|
|
return ETIMEDOUT;
|
|
|
|
}
|
|
|
|
DELAY(1000);
|
|
|
|
gctl = AZ_READ_4(az, GCTL);
|
|
|
|
AZ_WRITE_4(az, GCTL, gctl | HDA_GCTL_CRST);
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
DELAY(10);
|
|
|
|
if (AZ_READ_4(az, GCTL) & HDA_GCTL_CRST)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DPRINTF(("%s: reset counter = %d\n", __func__, i));
|
|
|
|
if (i <= 0) {
|
|
|
|
aprint_error("%s: reset-exit failure\n", XNAME(az));
|
|
|
|
return ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2006-06-25 09:05:51 +04:00
|
|
|
/* enable unsolicited response */
|
|
|
|
gctl = AZ_READ_4(az, GCTL);
|
|
|
|
AZ_WRITE_4(az, GCTL, gctl | HDA_GCTL_UNSOL);
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
/* 4.3 Codec discovery */
|
|
|
|
DELAY(1000);
|
|
|
|
statests = AZ_READ_2(az, STATESTS);
|
|
|
|
for (i = 0, n = 0; i < 15; i++) {
|
|
|
|
if ((statests >> i) & 1) {
|
|
|
|
DPRINTF(("%s: found a codec at #%d\n", XNAME(az), i));
|
|
|
|
az->codecs[n].address = i;
|
|
|
|
az->codecs[n++].az = az;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
az->ncodecs = n;
|
|
|
|
if (az->ncodecs < 1) {
|
|
|
|
aprint_error("%s: No HD-Audio codecs\n", XNAME(az));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
azalia_attach_intr(struct device *self)
|
|
|
|
{
|
|
|
|
azalia_t *az;
|
2005-09-26 21:30:04 +04:00
|
|
|
int err, i, c;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
az = (azalia_t*)self;
|
|
|
|
|
|
|
|
AZ_WRITE_2(az, STATESTS, HDA_STATESTS_SDIWAKE);
|
|
|
|
AZ_WRITE_1(az, RIRBSTS, HDA_RIRBSTS_RINTFL | HDA_RIRBSTS_RIRBOIS);
|
|
|
|
AZ_WRITE_4(az, INTSTS, HDA_INTSTS_CIS | HDA_INTSTS_GIS);
|
|
|
|
AZ_WRITE_4(az, DPLBASE, 0);
|
|
|
|
AZ_WRITE_4(az, DPUBASE, 0);
|
|
|
|
|
|
|
|
/* 4.4.1 Command Outbound Ring Buffer */
|
2006-06-16 16:16:58 +04:00
|
|
|
if (azalia_init_corb(az))
|
|
|
|
goto err_exit;
|
2005-06-18 14:43:46 +04:00
|
|
|
/* 4.4.2 Response Inbound Ring Buffer */
|
2006-06-16 16:16:58 +04:00
|
|
|
if (azalia_init_rirb(az))
|
|
|
|
goto err_exit;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
AZ_WRITE_4(az, INTCTL,
|
|
|
|
AZ_READ_4(az, INTCTL) | HDA_INTCTL_CIE | HDA_INTCTL_GIE);
|
|
|
|
|
2005-09-26 21:30:04 +04:00
|
|
|
c = -1;
|
2005-06-18 14:43:46 +04:00
|
|
|
for (i = 0; i < az->ncodecs; i++) {
|
|
|
|
err = azalia_codec_init(&az->codecs[i]);
|
2005-09-26 21:30:04 +04:00
|
|
|
if (!err && c < 0)
|
|
|
|
c = i;
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
2005-09-26 21:30:04 +04:00
|
|
|
if (c < 0)
|
|
|
|
goto err_exit;
|
|
|
|
/* Use the first audio codec */
|
|
|
|
az->codecno = c;
|
|
|
|
DPRINTF(("%s: using the #%d codec\n", XNAME(az), az->codecno));
|
2005-06-18 14:43:46 +04:00
|
|
|
|
2006-06-25 17:41:58 +04:00
|
|
|
/* Use stream#1 and #2. Don't use stream#0. */
|
2005-06-21 18:51:37 +04:00
|
|
|
if (azalia_stream_init(&az->pstream, az, az->nistreams + 0,
|
|
|
|
1, AUMODE_PLAY))
|
2005-06-25 20:32:39 +04:00
|
|
|
goto err_exit;
|
2005-06-21 18:51:37 +04:00
|
|
|
if (azalia_stream_init(&az->rstream, az, 0, 2, AUMODE_RECORD))
|
2005-06-25 20:32:39 +04:00
|
|
|
goto err_exit;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
az->audiodev = audio_attach_mi(&azalia_hw_if, az, &az->dev);
|
|
|
|
return;
|
2005-06-25 20:32:39 +04:00
|
|
|
err_exit:
|
|
|
|
azalia_pci_detach(self, 0);
|
|
|
|
return;
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_init_corb(azalia_t *az)
|
|
|
|
{
|
|
|
|
int entries, err, i;
|
|
|
|
uint16_t corbrp, corbwp;
|
|
|
|
uint8_t corbsize, cap, corbctl;
|
|
|
|
|
|
|
|
/* stop the CORB */
|
|
|
|
corbctl = AZ_READ_1(az, CORBCTL);
|
|
|
|
if (corbctl & HDA_CORBCTL_CORBRUN) { /* running? */
|
|
|
|
AZ_WRITE_1(az, CORBCTL, corbctl & ~HDA_CORBCTL_CORBRUN);
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
DELAY(10);
|
|
|
|
corbctl = AZ_READ_1(az, CORBCTL);
|
|
|
|
if ((corbctl & HDA_CORBCTL_CORBRUN) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i <= 0) {
|
|
|
|
aprint_error("%s: CORB is running\n", XNAME(az));
|
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine CORB size */
|
|
|
|
corbsize = AZ_READ_1(az, CORBSIZE);
|
|
|
|
cap = corbsize & HDA_CORBSIZE_CORBSZCAP_MASK;
|
|
|
|
corbsize &= ~HDA_CORBSIZE_CORBSIZE_MASK;
|
|
|
|
if (cap & HDA_CORBSIZE_CORBSZCAP_256) {
|
|
|
|
entries = 256;
|
|
|
|
corbsize |= HDA_CORBSIZE_CORBSIZE_256;
|
|
|
|
} else if (cap & HDA_CORBSIZE_CORBSZCAP_16) {
|
|
|
|
entries = 16;
|
|
|
|
corbsize |= HDA_CORBSIZE_CORBSIZE_16;
|
|
|
|
} else if (cap & HDA_CORBSIZE_CORBSZCAP_2) {
|
|
|
|
entries = 2;
|
|
|
|
corbsize |= HDA_CORBSIZE_CORBSIZE_2;
|
|
|
|
} else {
|
|
|
|
aprint_error("%s: Invalid CORBSZCAP: 0x%2x\n", XNAME(az), cap);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = azalia_alloc_dmamem(az, entries * sizeof(corb_entry_t),
|
|
|
|
128, &az->corb_dma);
|
|
|
|
if (err) {
|
|
|
|
aprint_error("%s: can't allocate CORB buffer\n", XNAME(az));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
AZ_WRITE_4(az, CORBLBASE, (uint32_t)AZALIA_DMA_DMAADDR(&az->corb_dma));
|
|
|
|
AZ_WRITE_4(az, CORBUBASE, PTR_UPPER32(AZALIA_DMA_DMAADDR(&az->corb_dma)));
|
|
|
|
AZ_WRITE_1(az, CORBSIZE, corbsize);
|
|
|
|
az->corb_size = entries;
|
|
|
|
|
|
|
|
DPRINTF(("%s: CORB allocation succeeded.\n", __func__));
|
|
|
|
|
|
|
|
/* reset CORBRP */
|
|
|
|
corbrp = AZ_READ_2(az, CORBRP);
|
|
|
|
AZ_WRITE_2(az, CORBRP, corbrp | HDA_CORBRP_CORBRPRST);
|
|
|
|
AZ_WRITE_2(az, CORBRP, corbrp & ~HDA_CORBRP_CORBRPRST);
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
DELAY(10);
|
|
|
|
corbrp = AZ_READ_2(az, CORBRP);
|
|
|
|
if ((corbrp & HDA_CORBRP_CORBRPRST) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i <= 0) {
|
2006-07-21 21:30:26 +04:00
|
|
|
aprint_error("%s: CORBRP reset failure\n", XNAME(az));
|
2005-06-18 14:43:46 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
DPRINTF(("%s: CORBWP=%d; size=%d\n", __func__,
|
|
|
|
AZ_READ_2(az, CORBRP) & HDA_CORBRP_CORBRP, az->corb_size));
|
|
|
|
|
|
|
|
/* clear CORBWP */
|
|
|
|
corbwp = AZ_READ_2(az, CORBWP);
|
|
|
|
AZ_WRITE_2(az, CORBWP, corbwp & ~HDA_CORBWP_CORBWP);
|
|
|
|
|
|
|
|
/* Run! */
|
|
|
|
corbctl = AZ_READ_1(az, CORBCTL);
|
|
|
|
AZ_WRITE_1(az, CORBCTL, corbctl | HDA_CORBCTL_CORBRUN);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-25 20:32:39 +04:00
|
|
|
static int
|
|
|
|
azalia_delete_corb(azalia_t *az)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t corbctl;
|
|
|
|
|
|
|
|
if (az->corb_dma.addr == NULL)
|
|
|
|
return 0;
|
|
|
|
/* stop the CORB */
|
|
|
|
corbctl = AZ_READ_1(az, CORBCTL);
|
|
|
|
AZ_WRITE_1(az, CORBCTL, corbctl & ~HDA_CORBCTL_CORBRUN);
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
DELAY(10);
|
|
|
|
corbctl = AZ_READ_1(az, CORBCTL);
|
|
|
|
if ((corbctl & HDA_CORBCTL_CORBRUN) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
azalia_free_dmamem(az, &az->corb_dma);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
static int
|
|
|
|
azalia_init_rirb(azalia_t *az)
|
|
|
|
{
|
|
|
|
int entries, err, i;
|
|
|
|
uint16_t rirbwp;
|
|
|
|
uint8_t rirbsize, cap, rirbctl;
|
|
|
|
|
|
|
|
/* stop the RIRB */
|
|
|
|
rirbctl = AZ_READ_1(az, RIRBCTL);
|
|
|
|
if (rirbctl & HDA_RIRBCTL_RIRBDMAEN) { /* running? */
|
|
|
|
AZ_WRITE_1(az, RIRBCTL, rirbctl & ~HDA_RIRBCTL_RIRBDMAEN);
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
DELAY(10);
|
|
|
|
rirbctl = AZ_READ_1(az, RIRBCTL);
|
|
|
|
if ((rirbctl & HDA_RIRBCTL_RIRBDMAEN) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i <= 0) {
|
|
|
|
aprint_error("%s: RIRB is running\n", XNAME(az));
|
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine RIRB size */
|
|
|
|
rirbsize = AZ_READ_1(az, RIRBSIZE);
|
|
|
|
cap = rirbsize & HDA_RIRBSIZE_RIRBSZCAP_MASK;
|
|
|
|
rirbsize &= ~HDA_RIRBSIZE_RIRBSIZE_MASK;
|
|
|
|
if (cap & HDA_RIRBSIZE_RIRBSZCAP_256) {
|
|
|
|
entries = 256;
|
|
|
|
rirbsize |= HDA_RIRBSIZE_RIRBSIZE_256;
|
|
|
|
} else if (cap & HDA_RIRBSIZE_RIRBSZCAP_16) {
|
|
|
|
entries = 16;
|
|
|
|
rirbsize |= HDA_RIRBSIZE_RIRBSIZE_16;
|
|
|
|
} else if (cap & HDA_RIRBSIZE_RIRBSZCAP_2) {
|
|
|
|
entries = 2;
|
|
|
|
rirbsize |= HDA_RIRBSIZE_RIRBSIZE_2;
|
|
|
|
} else {
|
|
|
|
aprint_error("%s: Invalid RIRBSZCAP: 0x%2x\n", XNAME(az), cap);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = azalia_alloc_dmamem(az, entries * sizeof(rirb_entry_t),
|
|
|
|
128, &az->rirb_dma);
|
|
|
|
if (err) {
|
|
|
|
aprint_error("%s: can't allocate RIRB buffer\n", XNAME(az));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
AZ_WRITE_4(az, RIRBLBASE, (uint32_t)AZALIA_DMA_DMAADDR(&az->rirb_dma));
|
|
|
|
AZ_WRITE_4(az, RIRBUBASE, PTR_UPPER32(AZALIA_DMA_DMAADDR(&az->rirb_dma)));
|
|
|
|
AZ_WRITE_1(az, RIRBSIZE, rirbsize);
|
|
|
|
az->rirb_size = entries;
|
|
|
|
|
|
|
|
DPRINTF(("%s: RIRB allocation succeeded.\n", __func__));
|
|
|
|
|
2006-06-25 09:05:51 +04:00
|
|
|
/* setup the unsolicited response queue */
|
|
|
|
az->unsolq_rp = 0;
|
|
|
|
az->unsolq_wp = 0;
|
2006-06-25 10:34:08 +04:00
|
|
|
az->unsolq_kick = FALSE;
|
2006-06-25 09:05:51 +04:00
|
|
|
az->unsolq = malloc(sizeof(rirb_entry_t) * UNSOLQ_SIZE,
|
|
|
|
M_DEVBUF, M_ZERO | M_NOWAIT);
|
|
|
|
if (az->unsolq == NULL) {
|
|
|
|
aprint_error("%s: can't allocate unsolicited response queue.\n",
|
|
|
|
XNAME(az));
|
|
|
|
azalia_free_dmamem(az, &az->rirb_dma);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-09-24 07:42:41 +04:00
|
|
|
#if notyet
|
|
|
|
rirbctl = AZ_READ_1(az, RIRBCTL);
|
|
|
|
AZ_WRITE_1(az, RIRBCTL, rirbctl & ~HDA_RIRBCTL_RINTCTL);
|
|
|
|
#endif
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
/* reset the write pointer */
|
|
|
|
rirbwp = AZ_READ_2(az, RIRBWP);
|
|
|
|
AZ_WRITE_2(az, RIRBWP, rirbwp | HDA_RIRBWP_RIRBWPRST);
|
|
|
|
|
|
|
|
/* clear the read pointer */
|
|
|
|
az->rirb_rp = AZ_READ_2(az, RIRBWP) & HDA_RIRBWP_RIRBWP;
|
|
|
|
DPRINTF(("%s: RIRBRP=%d, size=%d\n", __func__, az->rirb_rp, az->rirb_size));
|
|
|
|
|
|
|
|
AZ_WRITE_2(az, RINTCNT, 1);
|
|
|
|
|
|
|
|
/* Run! */
|
|
|
|
rirbctl = AZ_READ_1(az, RIRBCTL);
|
|
|
|
AZ_WRITE_1(az, RIRBCTL, rirbctl | HDA_RIRBCTL_RIRBDMAEN | HDA_RIRBCTL_RINTCTL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-25 20:32:39 +04:00
|
|
|
static int
|
|
|
|
azalia_delete_rirb(azalia_t *az)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t rirbctl;
|
|
|
|
|
2006-06-25 09:05:51 +04:00
|
|
|
if (az->unsolq != NULL) {
|
|
|
|
free(az->unsolq, M_DEVBUF);
|
2006-06-28 02:02:14 +04:00
|
|
|
az->unsolq = NULL;
|
2006-06-25 09:05:51 +04:00
|
|
|
}
|
2005-06-25 20:32:39 +04:00
|
|
|
if (az->rirb_dma.addr == NULL)
|
|
|
|
return 0;
|
|
|
|
/* stop the RIRB */
|
|
|
|
rirbctl = AZ_READ_1(az, RIRBCTL);
|
|
|
|
AZ_WRITE_1(az, RIRBCTL, rirbctl & ~HDA_RIRBCTL_RIRBDMAEN);
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
DELAY(10);
|
|
|
|
rirbctl = AZ_READ_1(az, RIRBCTL);
|
|
|
|
if ((rirbctl & HDA_RIRBCTL_RIRBDMAEN) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
azalia_free_dmamem(az, &az->rirb_dma);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
static int
|
|
|
|
azalia_set_command(const azalia_t *az, int caddr, nid_t nid, uint32_t control,
|
|
|
|
uint32_t param)
|
|
|
|
{
|
|
|
|
corb_entry_t *corb;
|
2006-06-25 09:05:51 +04:00
|
|
|
int wp;
|
2005-06-18 14:43:46 +04:00
|
|
|
uint32_t verb;
|
|
|
|
uint16_t corbwp;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((AZ_READ_1(az, CORBCTL) & HDA_CORBCTL_CORBRUN) == 0) {
|
|
|
|
aprint_error("%s: CORB is not running.\n", XNAME(az));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
verb = (caddr << 28) | (nid << 20) | (control << 8) | param;
|
|
|
|
corbwp = AZ_READ_2(az, CORBWP);
|
|
|
|
wp = corbwp & HDA_CORBWP_CORBWP;
|
|
|
|
corb = (corb_entry_t*)az->corb_dma.addr;
|
|
|
|
if (++wp >= az->corb_size)
|
|
|
|
wp = 0;
|
|
|
|
corb[wp] = verb;
|
|
|
|
AZ_WRITE_2(az, CORBWP, (corbwp & ~HDA_CORBWP_CORBWP) | wp);
|
|
|
|
#if 0
|
|
|
|
DPRINTF(("%s: caddr=%d nid=%d control=0x%x param=0x%x verb=0x%8.8x wp=%d\n",
|
|
|
|
__func__, caddr, nid, control, param, verb, wp));
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_get_response(azalia_t *az, uint32_t *result)
|
|
|
|
{
|
|
|
|
const rirb_entry_t *rirb;
|
|
|
|
int i;
|
|
|
|
uint16_t wp;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((AZ_READ_1(az, RIRBCTL) & HDA_RIRBCTL_RIRBDMAEN) == 0) {
|
|
|
|
aprint_error("%s: RIRB is not running.\n", XNAME(az));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
wp = AZ_READ_2(az, RIRBWP) & HDA_RIRBWP_RIRBWP;
|
|
|
|
if (az->rirb_rp != wp)
|
|
|
|
break;
|
|
|
|
DELAY(10);
|
|
|
|
}
|
|
|
|
if (i <= 0) {
|
|
|
|
aprint_error("%s: RIRB time out\n", XNAME(az));
|
|
|
|
return ETIMEDOUT;
|
|
|
|
}
|
|
|
|
rirb = (rirb_entry_t*)az->rirb_dma.addr;
|
2005-07-31 10:48:15 +04:00
|
|
|
for (;;) {
|
|
|
|
if (++az->rirb_rp >= az->rirb_size)
|
|
|
|
az->rirb_rp = 0;
|
2006-06-25 09:05:51 +04:00
|
|
|
if (rirb[az->rirb_rp].resp_ex & RIRB_RESP_UNSOL) {
|
|
|
|
az->unsolq[az->unsolq_wp].resp = rirb[az->rirb_rp].resp;
|
|
|
|
az->unsolq[az->unsolq_wp++].resp_ex = rirb[az->rirb_rp].resp_ex;
|
|
|
|
az->unsolq_wp %= UNSOLQ_SIZE;
|
2005-07-31 10:48:15 +04:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
2005-06-18 14:43:46 +04:00
|
|
|
if (result != NULL)
|
|
|
|
*result = rirb[az->rirb_rp].resp;
|
2006-06-25 09:05:51 +04:00
|
|
|
azalia_rirb_kick_unsol_events(az);
|
2005-06-18 14:43:46 +04:00
|
|
|
#if 0
|
|
|
|
DPRINTF(("%s: rirbwp=%d rp=%d resp1=0x%8.8x resp2=0x%8.8x\n",
|
|
|
|
__func__, wp, az->rirb_rp, rirb[az->rirb_rp].resp,
|
|
|
|
rirb[az->rirb_rp].resp_ex));
|
|
|
|
for (i = 0; i < 16 /*az->rirb_size*/; i++) {
|
|
|
|
DPRINTF(("rirb[%d] 0x%8.8x:0x%8.8x ", i, rirb[i].resp, rirb[i].resp_ex));
|
|
|
|
if ((i % 2) == 1)
|
|
|
|
DPRINTF(("\n"));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-25 09:05:51 +04:00
|
|
|
static void
|
|
|
|
azalia_rirb_kick_unsol_events(azalia_t *az)
|
|
|
|
{
|
2006-06-25 10:34:08 +04:00
|
|
|
if (az->unsolq_kick)
|
|
|
|
return;
|
|
|
|
az->unsolq_kick = TRUE;
|
2006-06-25 09:05:51 +04:00
|
|
|
while (az->unsolq_rp != az->unsolq_wp) {
|
|
|
|
int i;
|
|
|
|
int tag;
|
|
|
|
codec_t *codec;
|
|
|
|
i = RIRB_RESP_CODEC(az->unsolq[az->unsolq_rp].resp_ex);
|
|
|
|
tag = RIRB_UNSOL_TAG(az->unsolq[az->unsolq_rp].resp);
|
|
|
|
codec = &az->codecs[i];
|
2006-06-25 10:37:20 +04:00
|
|
|
DPRINTF(("%s: codec#=%d tag=%d\n", __func__, i, tag));
|
2006-06-25 09:05:51 +04:00
|
|
|
az->unsolq_rp++;
|
|
|
|
az->unsolq_rp %= UNSOLQ_SIZE;
|
2006-06-25 10:34:08 +04:00
|
|
|
if (codec->unsol_event != NULL)
|
|
|
|
codec->unsol_event(codec, tag);
|
2006-06-25 09:05:51 +04:00
|
|
|
}
|
2006-06-25 10:34:08 +04:00
|
|
|
az->unsolq_kick = FALSE;
|
2006-06-25 09:05:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
azalia_rirb_intr(azalia_t *az)
|
|
|
|
{
|
|
|
|
const rirb_entry_t *rirb;
|
|
|
|
uint16_t wp;
|
|
|
|
|
|
|
|
wp = AZ_READ_2(az, RIRBWP) & HDA_RIRBWP_RIRBWP;
|
|
|
|
if (az->rirb_rp == wp)
|
|
|
|
return; /* interrupted but no data in RIRB */
|
|
|
|
rirb = (rirb_entry_t*)az->rirb_dma.addr;
|
|
|
|
while (az->rirb_rp != wp) {
|
|
|
|
if (++az->rirb_rp >= az->rirb_size)
|
|
|
|
az->rirb_rp = 0;
|
|
|
|
if (rirb[az->rirb_rp].resp_ex & RIRB_RESP_UNSOL) {
|
|
|
|
az->unsolq[az->unsolq_wp].resp = rirb[az->rirb_rp].resp;
|
|
|
|
az->unsolq[az->unsolq_wp++].resp_ex = rirb[az->rirb_rp].resp_ex;
|
|
|
|
az->unsolq_wp %= UNSOLQ_SIZE;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
azalia_rirb_kick_unsol_events(az);
|
|
|
|
}
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
static int
|
|
|
|
azalia_alloc_dmamem(azalia_t *az, size_t size, size_t align, azalia_dma_t *d)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int nsegs;
|
|
|
|
|
|
|
|
d->size = size;
|
|
|
|
err = bus_dmamem_alloc(az->dmat, size, align, 0, d->segments, 1,
|
|
|
|
&nsegs, BUS_DMA_NOWAIT);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (nsegs != 1)
|
|
|
|
goto free;
|
|
|
|
err = bus_dmamem_map(az->dmat, d->segments, 1, size,
|
|
|
|
&d->addr, BUS_DMA_NOWAIT | BUS_DMA_COHERENT | BUS_DMA_NOCACHE);
|
|
|
|
if (err)
|
|
|
|
goto free;
|
|
|
|
err = bus_dmamap_create(az->dmat, size, 1, size, 0,
|
|
|
|
BUS_DMA_NOWAIT, &d->map);
|
|
|
|
if (err)
|
|
|
|
goto unmap;
|
|
|
|
err = bus_dmamap_load(az->dmat, d->map, d->addr, size,
|
|
|
|
NULL, BUS_DMA_NOWAIT);
|
|
|
|
if (err)
|
|
|
|
goto destroy;
|
2005-09-26 21:30:04 +04:00
|
|
|
|
|
|
|
if (!az->ok64 && PTR_UPPER32(AZALIA_DMA_DMAADDR(d)) != 0) {
|
|
|
|
azalia_free_dmamem(az, d);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-06-18 14:43:46 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
destroy:
|
|
|
|
bus_dmamap_destroy(az->dmat, d->map);
|
|
|
|
unmap:
|
|
|
|
bus_dmamem_unmap(az->dmat, d->addr, size);
|
|
|
|
free:
|
|
|
|
bus_dmamem_free(az->dmat, d->segments, 1);
|
2005-06-25 20:32:39 +04:00
|
|
|
d->addr = NULL;
|
2005-06-18 14:43:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_free_dmamem(const azalia_t *az, azalia_dma_t* d)
|
|
|
|
{
|
2005-06-25 20:32:39 +04:00
|
|
|
if (d->addr == NULL)
|
|
|
|
return 0;
|
2005-06-18 14:43:46 +04:00
|
|
|
bus_dmamap_unload(az->dmat, d->map);
|
|
|
|
bus_dmamap_destroy(az->dmat, d->map);
|
|
|
|
bus_dmamem_unmap(az->dmat, d->addr, d->size);
|
|
|
|
bus_dmamem_free(az->dmat, d->segments, 1);
|
2005-06-25 20:32:39 +04:00
|
|
|
d->addr = NULL;
|
2005-06-18 14:43:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ================================================================
|
|
|
|
* HDA coodec functions
|
|
|
|
* ================================================================ */
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_codec_init(codec_t *this)
|
|
|
|
{
|
2007-03-11 17:34:04 +03:00
|
|
|
#define LEAD_LEN 100
|
|
|
|
char lead[LEAD_LEN];
|
2006-06-07 19:23:59 +04:00
|
|
|
uint32_t rev, id, result;
|
2005-06-25 20:32:39 +04:00
|
|
|
int err, addr, n, i;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
this->comresp = azalia_codec_comresp;
|
|
|
|
addr = this->address;
|
|
|
|
DPRINTF(("%s: information of codec[%d] follows:\n",
|
|
|
|
XNAME(this->az), addr));
|
2005-06-19 11:42:39 +04:00
|
|
|
/* codec vendor/device/revision */
|
|
|
|
err = this->comresp(this, CORB_NID_ROOT, CORB_GET_PARAMETER,
|
|
|
|
COP_REVISION_ID, &rev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-06-18 14:43:46 +04:00
|
|
|
err = this->comresp(this, CORB_NID_ROOT, CORB_GET_PARAMETER,
|
2006-06-07 19:23:59 +04:00
|
|
|
COP_VENDOR_ID, &id);
|
2005-06-18 14:43:46 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
2006-06-07 19:23:59 +04:00
|
|
|
this->vid = id;
|
|
|
|
this->subid = this->az->subid;
|
2006-06-25 11:36:33 +04:00
|
|
|
err = azalia_codec_init_vtbl(this);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-09-28 18:26:19 +04:00
|
|
|
|
2006-06-13 18:20:09 +04:00
|
|
|
aprint_normal("%s: codec[%d]: ", XNAME(this->az), addr);
|
2005-09-28 18:26:19 +04:00
|
|
|
if (this->name == NULL) {
|
2006-06-13 18:20:09 +04:00
|
|
|
aprint_normal("0x%4.4x/0x%4.4x (rev. %u.%u)\n",
|
|
|
|
id >> 16, id & 0xffff,
|
2005-09-28 18:26:19 +04:00
|
|
|
COP_RID_REVISION(rev), COP_RID_STEPPING(rev));
|
|
|
|
} else {
|
2006-06-13 18:20:09 +04:00
|
|
|
aprint_normal("%s (rev. %u.%u)\n", this->name,
|
2005-09-28 18:26:19 +04:00
|
|
|
COP_RID_REVISION(rev), COP_RID_STEPPING(rev));
|
|
|
|
}
|
2006-06-13 18:20:09 +04:00
|
|
|
aprint_normal("%s: codec[%d]: High Definition Audio rev. %u.%u\n",
|
|
|
|
XNAME(this->az), addr, COP_RID_MAJ(rev), COP_RID_MIN(rev));
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
/* identify function nodes */
|
|
|
|
err = this->comresp(this, CORB_NID_ROOT, CORB_GET_PARAMETER,
|
|
|
|
COP_SUBORDINATE_NODE_COUNT, &result);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
this->nfunctions = COP_NSUBNODES(result);
|
|
|
|
if (COP_NSUBNODES(result) <= 0) {
|
|
|
|
aprint_error("%s: No function groups\n", XNAME(this->az));
|
|
|
|
return -1;
|
|
|
|
}
|
2005-06-19 11:42:39 +04:00
|
|
|
/* iterate function nodes and find an audio function */
|
2005-06-18 14:43:46 +04:00
|
|
|
n = COP_START_NID(result);
|
|
|
|
DPRINTF(("%s: nidstart=%d #functions=%d\n",
|
|
|
|
__func__, n, this->nfunctions));
|
|
|
|
this->audiofunc = -1;
|
|
|
|
for (i = 0; i < this->nfunctions; i++) {
|
|
|
|
err = this->comresp(this, n + i, CORB_GET_PARAMETER,
|
|
|
|
COP_FUNCTION_GROUP_TYPE, &result);
|
|
|
|
if (err)
|
|
|
|
continue;
|
|
|
|
DPRINTF(("%s: FTYPE result = 0x%8.8x\n", __func__, result));
|
|
|
|
if (COP_FTYPE(result) == COP_FTYPE_AUDIO) {
|
|
|
|
this->audiofunc = n + i;
|
|
|
|
break; /* XXX multiple audio functions? */
|
2006-06-11 11:45:18 +04:00
|
|
|
} else if (COP_FTYPE(result) == COP_FTYPE_MODEM) {
|
2006-06-13 18:20:09 +04:00
|
|
|
aprint_normal("%s: codec[%d]: No support for modem function groups\n",
|
2006-06-11 11:45:18 +04:00
|
|
|
XNAME(this->az), addr);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this->audiofunc < 0) {
|
2006-06-13 18:20:09 +04:00
|
|
|
aprint_error("%s: codec[%d] has no audio function groups\n",
|
2005-06-18 14:43:46 +04:00
|
|
|
XNAME(this->az), addr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-07-31 10:48:15 +04:00
|
|
|
/* power the audio function */
|
|
|
|
this->comresp(this, this->audiofunc, CORB_SET_POWER_STATE, CORB_PS_D0, &result);
|
|
|
|
DELAY(100);
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
/* check widgets in the audio function */
|
|
|
|
err = this->comresp(this, this->audiofunc,
|
|
|
|
CORB_GET_PARAMETER, COP_SUBORDINATE_NODE_COUNT, &result);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
DPRINTF(("%s: There are %d widgets in the audio function.\n",
|
|
|
|
__func__, COP_NSUBNODES(result)));
|
2005-06-19 11:42:39 +04:00
|
|
|
this->wstart = COP_START_NID(result);
|
|
|
|
if (this->wstart < 2) {
|
2005-06-18 14:43:46 +04:00
|
|
|
aprint_error("%s: invalid node structure\n", XNAME(this->az));
|
|
|
|
return -1;
|
|
|
|
}
|
2005-06-19 11:42:39 +04:00
|
|
|
this->wend = this->wstart + COP_NSUBNODES(result);
|
|
|
|
this->w = malloc(sizeof(widget_t) * this->wend, M_DEVBUF,
|
|
|
|
M_ZERO | M_NOWAIT);
|
|
|
|
if (this->w == NULL) {
|
2005-06-18 14:43:46 +04:00
|
|
|
aprint_error("%s: out of memory\n", XNAME(this->az));
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
2005-08-02 15:17:56 +04:00
|
|
|
|
|
|
|
/* query the base parameters */
|
|
|
|
this->comresp(this, this->audiofunc, CORB_GET_PARAMETER,
|
|
|
|
COP_STREAM_FORMATS, &result);
|
|
|
|
this->w[this->audiofunc].d.audio.encodings = result;
|
|
|
|
this->comresp(this, this->audiofunc, CORB_GET_PARAMETER,
|
|
|
|
COP_PCM, &result);
|
|
|
|
this->w[this->audiofunc].d.audio.bits_rates = result;
|
|
|
|
this->comresp(this, this->audiofunc, CORB_GET_PARAMETER,
|
|
|
|
COP_INPUT_AMPCAP, &result);
|
|
|
|
this->w[this->audiofunc].inamp_cap = result;
|
|
|
|
this->comresp(this, this->audiofunc, CORB_GET_PARAMETER,
|
|
|
|
COP_OUTPUT_AMPCAP, &result);
|
|
|
|
this->w[this->audiofunc].outamp_cap = result;
|
2007-03-11 17:34:04 +03:00
|
|
|
lead[0] = 0;
|
2005-08-02 15:17:56 +04:00
|
|
|
#ifdef AZALIA_DEBUG
|
2007-03-11 17:34:04 +03:00
|
|
|
snprintf(lead, LEAD_LEN, "%s: ", XNAME(this->az));
|
|
|
|
azalia_widget_print_audio(&this->w[this->audiofunc], lead, -1);
|
2005-08-02 15:17:56 +04:00
|
|
|
result = this->w[this->audiofunc].inamp_cap;
|
2007-03-11 17:34:04 +03:00
|
|
|
DPRINTF(("%sinamp: mute=%u size=%u steps=%u offset=%u\n", lead,
|
2005-08-02 15:17:56 +04:00
|
|
|
(result & COP_AMPCAP_MUTE) != 0, COP_AMPCAP_STEPSIZE(result),
|
|
|
|
COP_AMPCAP_NUMSTEPS(result), COP_AMPCAP_OFFSET(result)));
|
|
|
|
result = this->w[this->audiofunc].outamp_cap;
|
2007-03-11 17:34:04 +03:00
|
|
|
DPRINTF(("%soutamp: mute=%u size=%u steps=%u offset=%u\n", lead,
|
2005-08-02 15:17:56 +04:00
|
|
|
(result & COP_AMPCAP_MUTE) != 0, COP_AMPCAP_STEPSIZE(result),
|
|
|
|
COP_AMPCAP_NUMSTEPS(result), COP_AMPCAP_OFFSET(result)));
|
|
|
|
#endif
|
|
|
|
|
2006-01-16 17:15:26 +03:00
|
|
|
strlcpy(this->w[CORB_NID_ROOT].name, "root",
|
|
|
|
sizeof(this->w[CORB_NID_ROOT].name));
|
|
|
|
strlcpy(this->w[this->audiofunc].name, "hdaudio",
|
|
|
|
sizeof(this->w[this->audiofunc].name));
|
2005-06-19 11:42:39 +04:00
|
|
|
FOR_EACH_WIDGET(this, i) {
|
2007-03-11 17:34:04 +03:00
|
|
|
err = azalia_widget_init(&this->w[i], this, i, lead);
|
2005-06-18 14:43:46 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
2007-02-05 16:52:26 +03:00
|
|
|
#if defined(AZALIA_DEBUG) && defined(AZALIA_DEBUG_DOT)
|
|
|
|
DPRINTF(("-------- Graphviz DOT starts\n"));
|
|
|
|
if (this->name == NULL) {
|
|
|
|
DPRINTF(("digraph \"0x%4.4x/0x%4.4x (rev. %u.%u)\" {\n",
|
|
|
|
id >> 16, id & 0xffff,
|
|
|
|
COP_RID_REVISION(rev), COP_RID_STEPPING(rev)));
|
|
|
|
} else {
|
|
|
|
DPRINTF(("digraph \"%s (rev. %u.%u)\" {\n", this->name,
|
|
|
|
COP_RID_REVISION(rev), COP_RID_STEPPING(rev)));
|
|
|
|
}
|
|
|
|
FOR_EACH_WIDGET(this, i) {
|
|
|
|
const widget_t *w;
|
|
|
|
int j;
|
|
|
|
w = &this->w[i];
|
|
|
|
switch (w->type) {
|
|
|
|
case COP_AWTYPE_AUDIO_OUTPUT:
|
|
|
|
DPRINTF((" %s [shape=box,style=filled,fillcolor=\""
|
|
|
|
"#88ff88\"];\n", w->name));
|
|
|
|
break;
|
|
|
|
case COP_AWTYPE_AUDIO_INPUT:
|
|
|
|
DPRINTF((" %s [shape=box,style=filled,fillcolor=\""
|
|
|
|
"#ff8888\"];\n", w->name));
|
|
|
|
break;
|
|
|
|
case COP_AWTYPE_AUDIO_MIXER:
|
|
|
|
DPRINTF((" %s [shape=invhouse];\n", w->name));
|
|
|
|
break;
|
|
|
|
case COP_AWTYPE_AUDIO_SELECTOR:
|
|
|
|
DPRINTF((" %s [shape=invtrapezium];\n", w->name));
|
|
|
|
break;
|
|
|
|
case COP_AWTYPE_PIN_COMPLEX:
|
|
|
|
DPRINTF((" %s [label=\"%s\\ndevice=%s\",style=filled",
|
|
|
|
w->name, w->name, pin_devices[w->d.pin.device]));
|
|
|
|
if (w->d.pin.cap & COP_PINCAP_OUTPUT &&
|
|
|
|
w->d.pin.cap & COP_PINCAP_INPUT)
|
|
|
|
DPRINTF((",shape=doublecircle,fillcolor=\""
|
|
|
|
"#ffff88\"];\n"));
|
|
|
|
else if (w->d.pin.cap & COP_PINCAP_OUTPUT)
|
|
|
|
DPRINTF((",shape=circle,fillcolor=\"#88ff88\"];\n"));
|
|
|
|
else
|
|
|
|
DPRINTF((",shape=circle,fillcolor=\"#ff8888\"];\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((w->widgetcap & COP_AWCAP_CONNLIST) == 0)
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < w->nconnections; j++) {
|
|
|
|
int src = w->connections[j];
|
|
|
|
if (!VALID_WIDGET_NID(src, this))
|
|
|
|
continue;
|
|
|
|
DPRINTF((" %s -> %s [sametail=%s];\n",
|
|
|
|
this->w[src].name, w->name, this->w[src].name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF((" {rank=min;"));
|
|
|
|
FOR_EACH_WIDGET(this, i) {
|
|
|
|
const widget_t *w;
|
|
|
|
w = &this->w[i];
|
|
|
|
switch (w->type) {
|
|
|
|
case COP_AWTYPE_AUDIO_OUTPUT:
|
|
|
|
case COP_AWTYPE_AUDIO_INPUT:
|
|
|
|
DPRINTF((" %s;", w->name));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DPRINTF(("}\n"));
|
|
|
|
|
|
|
|
DPRINTF((" {rank=max;"));
|
|
|
|
FOR_EACH_WIDGET(this, i) {
|
|
|
|
const widget_t *w;
|
|
|
|
w = &this->w[i];
|
|
|
|
switch (w->type) {
|
|
|
|
case COP_AWTYPE_PIN_COMPLEX:
|
|
|
|
DPRINTF((" %s;", w->name));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DPRINTF(("}\n"));
|
|
|
|
|
|
|
|
DPRINTF(("}\n"));
|
|
|
|
DPRINTF(("-------- Graphviz DOT ends\n"));
|
|
|
|
#endif /* AZALIA_DEBUG && AZALIA_DEBUG_DOT */
|
2005-06-18 14:43:46 +04:00
|
|
|
|
2005-09-28 18:26:19 +04:00
|
|
|
err = this->init_dacgroup(this);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
#ifdef AZALIA_DEBUG
|
2006-06-11 15:48:39 +04:00
|
|
|
for (i = 0; i < this->dacs.ngroups; i++) {
|
2005-09-28 18:26:19 +04:00
|
|
|
DPRINTF(("%s: dacgroup[%d]:", __func__, i));
|
2006-06-11 15:48:39 +04:00
|
|
|
for (n = 0; n < this->dacs.groups[i].nconv; n++) {
|
|
|
|
DPRINTF((" %2.2x", this->dacs.groups[i].conv[n]));
|
2005-09-28 18:26:19 +04:00
|
|
|
}
|
|
|
|
DPRINTF(("\n"));
|
|
|
|
}
|
|
|
|
#endif
|
2005-09-29 08:14:03 +04:00
|
|
|
|
2006-06-09 20:56:30 +04:00
|
|
|
/* set invalid values for azalia_codec_construct_format() to work */
|
2006-06-11 15:48:39 +04:00
|
|
|
this->dacs.cur = -1;
|
|
|
|
this->adcs.cur = -1;
|
2006-06-09 20:56:30 +04:00
|
|
|
err = azalia_codec_construct_format(this, 0, 0);
|
2005-06-25 20:32:39 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2006-06-07 19:23:59 +04:00
|
|
|
return this->mixer_init(this);
|
2005-06-25 20:32:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_codec_delete(codec_t *this)
|
|
|
|
{
|
2006-06-28 02:02:14 +04:00
|
|
|
if (this->mixer_delete != NULL)
|
|
|
|
this->mixer_delete(this);
|
2005-06-25 20:32:39 +04:00
|
|
|
if (this->formats != NULL) {
|
|
|
|
free(this->formats, M_DEVBUF);
|
|
|
|
this->formats = NULL;
|
|
|
|
}
|
|
|
|
auconv_delete_encodings(this->encodings);
|
|
|
|
this->encodings = NULL;
|
2006-06-25 11:36:33 +04:00
|
|
|
if (this->extra != NULL) {
|
|
|
|
free(this->extra, M_DEVBUF);
|
|
|
|
this->extra = NULL;
|
|
|
|
}
|
2005-06-25 20:32:39 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-07 19:23:59 +04:00
|
|
|
int
|
2006-06-09 20:56:30 +04:00
|
|
|
azalia_codec_construct_format(codec_t *this, int newdac, int newadc)
|
2005-06-19 20:32:55 +04:00
|
|
|
{
|
|
|
|
char flagbuf[FLAGBUFLEN];
|
|
|
|
const convgroup_t *group;
|
|
|
|
uint32_t bits_rates;
|
2006-06-09 20:56:30 +04:00
|
|
|
int prev_dac, prev_adc;
|
2007-03-10 19:39:37 +03:00
|
|
|
int variation;
|
2006-06-11 16:18:00 +04:00
|
|
|
int nbits, c, chan, i, err;
|
2005-06-25 20:32:39 +04:00
|
|
|
nid_t nid;
|
2005-06-19 20:32:55 +04:00
|
|
|
|
2006-06-11 15:48:39 +04:00
|
|
|
prev_dac = this->dacs.cur;
|
|
|
|
this->dacs.cur = newdac;
|
|
|
|
group = &this->dacs.groups[this->dacs.cur];
|
2005-06-19 20:32:55 +04:00
|
|
|
bits_rates = this->w[group->conv[0]].d.audio.bits_rates;
|
2005-06-18 14:43:46 +04:00
|
|
|
nbits = 0;
|
|
|
|
if (bits_rates & COP_PCM_B8)
|
|
|
|
nbits++;
|
|
|
|
if (bits_rates & COP_PCM_B16)
|
|
|
|
nbits++;
|
|
|
|
if (bits_rates & COP_PCM_B20)
|
|
|
|
nbits++;
|
|
|
|
if (bits_rates & COP_PCM_B24)
|
|
|
|
nbits++;
|
|
|
|
if (bits_rates & COP_PCM_B32)
|
|
|
|
nbits++;
|
|
|
|
if (nbits == 0) {
|
|
|
|
aprint_error("%s: invalid PCM format: 0x%8.8x\n",
|
|
|
|
XNAME(this->az), bits_rates);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-03-10 19:39:37 +03:00
|
|
|
variation = group->nconv * nbits;
|
2005-06-19 20:32:55 +04:00
|
|
|
|
2006-06-11 15:48:39 +04:00
|
|
|
prev_adc = this->adcs.cur;
|
|
|
|
this->adcs.cur = newadc;
|
|
|
|
group = &this->adcs.groups[this->adcs.cur];
|
|
|
|
bits_rates = this->w[group->conv[0]].d.audio.bits_rates;
|
2005-06-19 20:32:55 +04:00
|
|
|
nbits = 0;
|
|
|
|
if (bits_rates & COP_PCM_B8)
|
|
|
|
nbits++;
|
|
|
|
if (bits_rates & COP_PCM_B16)
|
|
|
|
nbits++;
|
|
|
|
if (bits_rates & COP_PCM_B20)
|
|
|
|
nbits++;
|
|
|
|
if (bits_rates & COP_PCM_B24)
|
|
|
|
nbits++;
|
|
|
|
if (bits_rates & COP_PCM_B32)
|
|
|
|
nbits++;
|
|
|
|
if (nbits == 0) {
|
|
|
|
aprint_error("%s: invalid PCM format: 0x%8.8x\n",
|
|
|
|
XNAME(this->az), bits_rates);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-03-10 19:39:37 +03:00
|
|
|
variation += group->nconv * nbits;
|
2005-06-19 20:32:55 +04:00
|
|
|
|
|
|
|
if (this->formats != NULL)
|
|
|
|
free(this->formats, M_DEVBUF);
|
|
|
|
this->nformats = 0;
|
2007-03-10 19:39:37 +03:00
|
|
|
this->formats = malloc(sizeof(struct audio_format) * variation,
|
|
|
|
M_DEVBUF, M_ZERO | M_NOWAIT);
|
2005-06-18 14:43:46 +04:00
|
|
|
if (this->formats == NULL) {
|
|
|
|
aprint_error("%s: out of memory in %s\n",
|
|
|
|
XNAME(this->az), __func__);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
2005-06-19 20:32:55 +04:00
|
|
|
|
2005-06-25 20:32:39 +04:00
|
|
|
/* register formats for playback */
|
2006-06-11 15:48:39 +04:00
|
|
|
group = &this->dacs.groups[this->dacs.cur];
|
2005-06-25 20:32:39 +04:00
|
|
|
chan = 0;
|
2006-06-11 16:18:00 +04:00
|
|
|
for (c = 0; c < group->nconv; c++) {
|
2006-06-15 20:08:13 +04:00
|
|
|
chan = 0;
|
|
|
|
bits_rates = ~0;
|
|
|
|
for (i = 0; i <= c; i++) {
|
|
|
|
nid = group->conv[i];
|
|
|
|
chan += WIDGET_CHANNELS(&this->w[nid]);
|
|
|
|
bits_rates &= this->w[nid].d.audio.bits_rates;
|
|
|
|
}
|
2005-06-25 20:32:39 +04:00
|
|
|
azalia_codec_add_bits(this, chan, bits_rates, AUMODE_PLAY);
|
|
|
|
}
|
|
|
|
/* print playback capability */
|
2006-06-11 15:48:39 +04:00
|
|
|
if (prev_dac != this->dacs.cur) {
|
2006-06-09 20:56:30 +04:00
|
|
|
snprintf(flagbuf, FLAGBUFLEN, "%s: playback: ", XNAME(this->az));
|
2006-06-15 20:08:13 +04:00
|
|
|
azalia_widget_print_audio(&this->w[group->conv[0]], flagbuf, chan);
|
2006-06-09 20:56:30 +04:00
|
|
|
}
|
2005-06-25 20:32:39 +04:00
|
|
|
|
|
|
|
/* register formats for recording */
|
2006-06-11 15:48:39 +04:00
|
|
|
group = &this->adcs.groups[this->adcs.cur];
|
2006-06-11 16:18:00 +04:00
|
|
|
for (c = 0; c < group->nconv; c++) {
|
2006-06-15 20:08:13 +04:00
|
|
|
chan = 0;
|
|
|
|
bits_rates = ~0;
|
|
|
|
for (i = 0; i <= c; i++) {
|
|
|
|
nid = group->conv[i];
|
|
|
|
chan += WIDGET_CHANNELS(&this->w[nid]);
|
|
|
|
bits_rates &= this->w[nid].d.audio.bits_rates;
|
|
|
|
}
|
2006-06-11 16:18:00 +04:00
|
|
|
azalia_codec_add_bits(this, chan, bits_rates, AUMODE_RECORD);
|
|
|
|
}
|
2005-06-25 20:32:39 +04:00
|
|
|
/* print recording capability */
|
2006-06-11 15:48:39 +04:00
|
|
|
if (prev_adc != this->adcs.cur) {
|
2006-06-09 20:56:30 +04:00
|
|
|
snprintf(flagbuf, FLAGBUFLEN, "%s: recording: ", XNAME(this->az));
|
2006-06-15 20:08:13 +04:00
|
|
|
azalia_widget_print_audio(&this->w[group->conv[0]], flagbuf, chan);
|
2006-06-09 20:56:30 +04:00
|
|
|
}
|
2005-06-19 20:32:55 +04:00
|
|
|
|
2007-03-10 19:39:37 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (this->nformats > variation) {
|
|
|
|
aprint_error("%s: Internal error: the format buffer is too small: "
|
|
|
|
"nformats=%d variation=%d\n", XNAME(this->az),
|
|
|
|
this->nformats, variation);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
err = auconv_create_encodings(this->formats, this->nformats,
|
|
|
|
&this->encodings);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-25 20:32:39 +04:00
|
|
|
static void
|
|
|
|
azalia_codec_add_bits(codec_t *this, int chan, uint32_t bits_rates, int mode)
|
|
|
|
{
|
|
|
|
if (bits_rates & COP_PCM_B8)
|
|
|
|
azalia_codec_add_format(this, chan, 8, 16, bits_rates, mode);
|
|
|
|
if (bits_rates & COP_PCM_B16)
|
|
|
|
azalia_codec_add_format(this, chan, 16, 16, bits_rates, mode);
|
|
|
|
if (bits_rates & COP_PCM_B20)
|
|
|
|
azalia_codec_add_format(this, chan, 20, 32, bits_rates, mode);
|
|
|
|
if (bits_rates & COP_PCM_B24)
|
|
|
|
azalia_codec_add_format(this, chan, 24, 32, bits_rates, mode);
|
|
|
|
if (bits_rates & COP_PCM_B32)
|
|
|
|
azalia_codec_add_format(this, chan, 32, 32, bits_rates, mode);
|
|
|
|
}
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
static void
|
2005-06-19 20:32:55 +04:00
|
|
|
azalia_codec_add_format(codec_t *this, int chan, int valid, int prec,
|
|
|
|
uint32_t rates, int32_t mode)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
struct audio_format *f;
|
|
|
|
|
|
|
|
f = &this->formats[this->nformats++];
|
2005-06-19 20:32:55 +04:00
|
|
|
f->mode = mode;
|
2005-06-18 14:43:46 +04:00
|
|
|
f->encoding = AUDIO_ENCODING_SLINEAR_LE;
|
|
|
|
if (valid == 8 && prec == 8)
|
|
|
|
f->encoding = AUDIO_ENCODING_ULINEAR_LE;
|
|
|
|
f->validbits = valid;
|
|
|
|
f->precision = prec;
|
|
|
|
f->channels = chan;
|
|
|
|
switch (chan) {
|
|
|
|
case 1:
|
|
|
|
f->channel_mask = AUFMT_MONAURAL;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
f->channel_mask = AUFMT_STEREO;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
f->channel_mask = AUFMT_SURROUND4;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
f->channel_mask = AUFMT_DOLBY_5_1;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
f->channel_mask = AUFMT_DOLBY_5_1
|
|
|
|
| AUFMT_SIDE_LEFT | AUFMT_SIDE_RIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
f->channel_mask = 0;
|
|
|
|
}
|
2007-03-10 19:39:37 +03:00
|
|
|
f->frequency_type = 0;
|
2005-06-18 14:43:46 +04:00
|
|
|
if (rates & COP_PCM_R80)
|
|
|
|
f->frequency[f->frequency_type++] = 8000;
|
|
|
|
if (rates & COP_PCM_R110)
|
|
|
|
f->frequency[f->frequency_type++] = 11025;
|
|
|
|
if (rates & COP_PCM_R160)
|
|
|
|
f->frequency[f->frequency_type++] = 16000;
|
|
|
|
if (rates & COP_PCM_R220)
|
|
|
|
f->frequency[f->frequency_type++] = 22050;
|
|
|
|
if (rates & COP_PCM_R320)
|
|
|
|
f->frequency[f->frequency_type++] = 32000;
|
|
|
|
if (rates & COP_PCM_R441)
|
|
|
|
f->frequency[f->frequency_type++] = 44100;
|
|
|
|
if (rates & COP_PCM_R480)
|
|
|
|
f->frequency[f->frequency_type++] = 48000;
|
|
|
|
if (rates & COP_PCM_R882)
|
|
|
|
f->frequency[f->frequency_type++] = 88200;
|
|
|
|
if (rates & COP_PCM_R960)
|
|
|
|
f->frequency[f->frequency_type++] = 96000;
|
|
|
|
if (rates & COP_PCM_R1764)
|
|
|
|
f->frequency[f->frequency_type++] = 176400;
|
|
|
|
if (rates & COP_PCM_R1920)
|
|
|
|
f->frequency[f->frequency_type++] = 192000;
|
|
|
|
if (rates & COP_PCM_R3840)
|
|
|
|
f->frequency[f->frequency_type++] = 384000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_codec_comresp(const codec_t *codec, nid_t nid, uint32_t control,
|
|
|
|
uint32_t param, uint32_t* result)
|
|
|
|
{
|
2006-06-25 09:05:51 +04:00
|
|
|
int err, s;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
2006-06-25 09:05:51 +04:00
|
|
|
s = splaudio();
|
2005-06-18 14:43:46 +04:00
|
|
|
err = azalia_set_command(codec->az, codec->address, nid, control, param);
|
|
|
|
if (err)
|
2006-06-25 09:05:51 +04:00
|
|
|
goto EXIT;
|
|
|
|
err = azalia_get_response(codec->az, result);
|
|
|
|
EXIT:
|
|
|
|
splx(s);
|
|
|
|
return err;
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_codec_connect_stream(codec_t *this, int dir, uint16_t fmt, int number)
|
|
|
|
{
|
2005-06-19 20:32:55 +04:00
|
|
|
const convgroup_t *group;
|
2006-06-25 17:41:58 +04:00
|
|
|
uint32_t v;
|
2005-06-19 20:32:55 +04:00
|
|
|
int i, err, startchan, nchan;
|
2005-06-18 14:43:46 +04:00
|
|
|
nid_t nid;
|
2007-02-22 01:59:35 +03:00
|
|
|
bool flag222;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
DPRINTF(("%s: fmt=0x%4.4x number=%d\n", __func__, fmt, number));
|
|
|
|
err = 0;
|
2006-06-11 15:48:39 +04:00
|
|
|
if (dir == AUMODE_RECORD)
|
|
|
|
group = &this->adcs.groups[this->adcs.cur];
|
|
|
|
else
|
|
|
|
group = &this->dacs.groups[this->dacs.cur];
|
2005-06-19 20:32:55 +04:00
|
|
|
flag222 = group->nconv >= 3 &&
|
2006-01-03 17:16:28 +03:00
|
|
|
(WIDGET_CHANNELS(&this->w[group->conv[0]]) == 2) &&
|
|
|
|
(WIDGET_CHANNELS(&this->w[group->conv[1]]) == 2) &&
|
|
|
|
(WIDGET_CHANNELS(&this->w[group->conv[2]]) == 2);
|
2005-06-19 20:32:55 +04:00
|
|
|
nchan = (fmt & HDA_SD_FMT_CHAN) + 1;
|
2005-06-18 14:43:46 +04:00
|
|
|
startchan = 0;
|
2005-06-19 20:32:55 +04:00
|
|
|
for (i = 0; i < group->nconv; i++) {
|
2007-05-08 08:35:37 +04:00
|
|
|
uint32_t stream_chan;
|
2005-06-19 20:32:55 +04:00
|
|
|
nid = group->conv[i];
|
|
|
|
|
|
|
|
/* surround and c/lfe handling */
|
|
|
|
if (nchan >= 6 && flag222 && i == 1) {
|
|
|
|
nid = group->conv[2];
|
|
|
|
} else if (nchan >= 6 && flag222 && i == 2) {
|
|
|
|
nid = group->conv[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
err = this->comresp(this, nid, CORB_SET_CONVERTER_FORMAT, fmt, NULL);
|
|
|
|
if (err)
|
|
|
|
goto exit;
|
2007-05-08 08:35:37 +04:00
|
|
|
stream_chan = (number << 4) | startchan;
|
|
|
|
if (startchan >= nchan)
|
|
|
|
stream_chan = 0; /* stream#0 */
|
2005-06-19 20:32:55 +04:00
|
|
|
err = this->comresp(this, nid, CORB_SET_CONVERTER_STREAM_CHANNEL,
|
2007-05-08 08:35:37 +04:00
|
|
|
stream_chan, NULL);
|
2005-06-19 20:32:55 +04:00
|
|
|
if (err)
|
|
|
|
goto exit;
|
2006-06-25 17:41:58 +04:00
|
|
|
if (this->w[nid].widgetcap & COP_AWCAP_DIGITAL) {
|
|
|
|
/* enable S/PDIF */
|
|
|
|
this->comresp(this, nid, CORB_GET_DIGITAL_CONTROL,
|
|
|
|
0, &v);
|
|
|
|
v = (v & 0xff) | CORB_DCC_DIGEN;
|
|
|
|
this->comresp(this, nid, CORB_SET_DIGITAL_CONTROL_L,
|
|
|
|
v, NULL);
|
|
|
|
}
|
2006-01-03 17:16:28 +03:00
|
|
|
startchan += WIDGET_CHANNELS(&this->w[nid]);
|
2005-06-19 20:32:55 +04:00
|
|
|
}
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
exit:
|
|
|
|
DPRINTF(("%s: leave with %d\n", __func__, err));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-06-25 17:41:58 +04:00
|
|
|
static int
|
|
|
|
azalia_codec_disconnect_stream(codec_t *this, int dir)
|
|
|
|
{
|
|
|
|
const convgroup_t *group;
|
|
|
|
uint32_t v;
|
|
|
|
int i;
|
|
|
|
nid_t nid;
|
|
|
|
|
|
|
|
if (dir == AUMODE_RECORD)
|
|
|
|
group = &this->adcs.groups[this->adcs.cur];
|
|
|
|
else
|
|
|
|
group = &this->dacs.groups[this->dacs.cur];
|
|
|
|
for (i = 0; i < group->nconv; i++) {
|
|
|
|
nid = group->conv[i];
|
|
|
|
this->comresp(this, nid, CORB_SET_CONVERTER_STREAM_CHANNEL,
|
|
|
|
0, NULL); /* stream#0 */
|
|
|
|
if (this->w[nid].widgetcap & COP_AWCAP_DIGITAL) {
|
|
|
|
/* disable S/PDIF */
|
|
|
|
this->comresp(this, nid, CORB_GET_DIGITAL_CONTROL, 0, &v);
|
|
|
|
v = (v & ~CORB_DCC_DIGEN) & 0xff;
|
|
|
|
this->comresp(this, nid, CORB_SET_DIGITAL_CONTROL_L, v, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
/* ================================================================
|
|
|
|
* HDA widget functions
|
|
|
|
* ================================================================ */
|
|
|
|
|
|
|
|
static int
|
2007-03-11 17:34:04 +03:00
|
|
|
azalia_widget_init(widget_t *this, const codec_t *codec,
|
|
|
|
nid_t nid, const char *lead)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
char flagbuf[FLAGBUFLEN];
|
|
|
|
uint32_t result;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = codec->comresp(codec, nid, CORB_GET_PARAMETER,
|
2005-06-19 11:42:39 +04:00
|
|
|
COP_AUDIO_WIDGET_CAP, &result);
|
2005-06-18 14:43:46 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
this->nid = nid;
|
|
|
|
this->widgetcap = result;
|
|
|
|
this->type = COP_AWCAP_TYPE(result);
|
2005-06-19 11:42:39 +04:00
|
|
|
bitmask_snprintf(this->widgetcap, "\20\014LRSWAP\013POWER\012DIGITAL"
|
2005-06-19 16:34:36 +04:00
|
|
|
"\011CONNLIST\010UNSOL\07PROC\06STRIPE\05FORMATOV\04AMPOV\03OUTAMP"
|
2005-06-18 14:43:46 +04:00
|
|
|
"\02INAMP\01STEREO", flagbuf, FLAGBUFLEN);
|
2005-06-19 11:42:39 +04:00
|
|
|
DPRINTF(("%s: ", XNAME(codec->az)));
|
2005-07-31 10:48:15 +04:00
|
|
|
if (this->widgetcap & COP_AWCAP_POWER) {
|
|
|
|
codec->comresp(codec, nid, CORB_SET_POWER_STATE, CORB_PS_D0, &result);
|
|
|
|
DELAY(100);
|
|
|
|
}
|
2005-06-18 14:43:46 +04:00
|
|
|
switch (this->type) {
|
|
|
|
case COP_AWTYPE_AUDIO_OUTPUT:
|
2005-06-19 11:42:39 +04:00
|
|
|
snprintf(this->name, sizeof(this->name), "dac%2.2x", nid);
|
|
|
|
DPRINTF(("%s wcap=%s\n", this->name, flagbuf));
|
2007-03-11 17:34:04 +03:00
|
|
|
azalia_widget_init_audio(this, codec, lead);
|
2005-06-18 14:43:46 +04:00
|
|
|
break;
|
|
|
|
case COP_AWTYPE_AUDIO_INPUT:
|
2005-06-19 11:42:39 +04:00
|
|
|
snprintf(this->name, sizeof(this->name), "adc%2.2x", nid);
|
|
|
|
DPRINTF(("%s wcap=%s\n", this->name, flagbuf));
|
2007-03-11 17:34:04 +03:00
|
|
|
azalia_widget_init_audio(this, codec, lead);
|
2005-06-18 14:43:46 +04:00
|
|
|
break;
|
|
|
|
case COP_AWTYPE_AUDIO_MIXER:
|
2005-06-19 11:42:39 +04:00
|
|
|
snprintf(this->name, sizeof(this->name), "mix%2.2x", nid);
|
|
|
|
DPRINTF(("%s wcap=%s\n", this->name, flagbuf));
|
2005-06-18 14:43:46 +04:00
|
|
|
break;
|
|
|
|
case COP_AWTYPE_AUDIO_SELECTOR:
|
2005-06-19 11:42:39 +04:00
|
|
|
snprintf(this->name, sizeof(this->name), "sel%2.2x", nid);
|
|
|
|
DPRINTF(("%s wcap=%s\n", this->name, flagbuf));
|
2005-06-18 14:43:46 +04:00
|
|
|
break;
|
|
|
|
case COP_AWTYPE_PIN_COMPLEX:
|
|
|
|
azalia_widget_init_pin(this, codec);
|
2005-06-19 11:42:39 +04:00
|
|
|
snprintf(this->name, sizeof(this->name), "%s%2.2x",
|
|
|
|
pin_colors[this->d.pin.color], nid);
|
|
|
|
DPRINTF(("%s wcap=%s\n", this->name, flagbuf));
|
2007-03-11 17:34:04 +03:00
|
|
|
azalia_widget_print_pin(this, lead);
|
2005-06-18 14:43:46 +04:00
|
|
|
break;
|
|
|
|
case COP_AWTYPE_POWER:
|
2005-06-19 11:42:39 +04:00
|
|
|
snprintf(this->name, sizeof(this->name), "pow%2.2x", nid);
|
|
|
|
DPRINTF(("%s wcap=%s\n", this->name, flagbuf));
|
2005-06-18 14:43:46 +04:00
|
|
|
break;
|
|
|
|
case COP_AWTYPE_VOLUME_KNOB:
|
2005-08-02 15:17:56 +04:00
|
|
|
snprintf(this->name, sizeof(this->name), "volume%2.2x", nid);
|
2005-06-19 11:42:39 +04:00
|
|
|
DPRINTF(("%s wcap=%s\n", this->name, flagbuf));
|
2005-08-02 15:17:56 +04:00
|
|
|
err = codec->comresp(codec, nid, CORB_GET_PARAMETER,
|
|
|
|
COP_VOLUME_KNOB_CAPABILITIES, &result);
|
|
|
|
if (!err) {
|
|
|
|
this->d.volume.cap = result;
|
2007-03-11 17:34:04 +03:00
|
|
|
DPRINTF(("%sdelta=%d steps=%d\n", lead,
|
2005-08-02 15:17:56 +04:00
|
|
|
!!(result & COP_VKCAP_DELTA),
|
|
|
|
COP_VKCAP_NUMSTEPS(result)));
|
|
|
|
}
|
2005-06-18 14:43:46 +04:00
|
|
|
break;
|
|
|
|
case COP_AWTYPE_BEEP_GENERATOR:
|
2005-06-19 11:42:39 +04:00
|
|
|
snprintf(this->name, sizeof(this->name), "beep%2.2x", nid);
|
|
|
|
DPRINTF(("%s wcap=%s\n", this->name, flagbuf));
|
2005-06-18 14:43:46 +04:00
|
|
|
break;
|
|
|
|
default:
|
2005-08-02 15:17:56 +04:00
|
|
|
snprintf(this->name, sizeof(this->name), "widget%2.2x", nid);
|
2005-06-19 11:42:39 +04:00
|
|
|
DPRINTF(("%s wcap=%s\n", this->name, flagbuf));
|
2005-06-18 14:43:46 +04:00
|
|
|
break;
|
|
|
|
}
|
2007-03-11 17:34:04 +03:00
|
|
|
azalia_widget_init_connection(this, codec, lead);
|
2005-06-19 11:42:39 +04:00
|
|
|
|
|
|
|
/* amplifier information */
|
|
|
|
if (this->widgetcap & COP_AWCAP_INAMP) {
|
2005-08-02 15:17:56 +04:00
|
|
|
if (this->widgetcap & COP_AWCAP_AMPOV)
|
|
|
|
codec->comresp(codec, nid, CORB_GET_PARAMETER,
|
|
|
|
COP_INPUT_AMPCAP, &this->inamp_cap);
|
|
|
|
else
|
|
|
|
this->inamp_cap = codec->w[codec->audiofunc].inamp_cap;
|
2007-03-11 17:34:04 +03:00
|
|
|
DPRINTF(("%sinamp: mute=%u size=%u steps=%u offset=%u\n",
|
|
|
|
lead, (this->inamp_cap & COP_AMPCAP_MUTE) != 0,
|
2005-06-19 11:42:39 +04:00
|
|
|
COP_AMPCAP_STEPSIZE(this->inamp_cap),
|
|
|
|
COP_AMPCAP_NUMSTEPS(this->inamp_cap),
|
|
|
|
COP_AMPCAP_OFFSET(this->inamp_cap)));
|
|
|
|
}
|
|
|
|
if (this->widgetcap & COP_AWCAP_OUTAMP) {
|
2005-08-02 15:17:56 +04:00
|
|
|
if (this->widgetcap & COP_AWCAP_AMPOV)
|
|
|
|
codec->comresp(codec, nid, CORB_GET_PARAMETER,
|
|
|
|
COP_OUTPUT_AMPCAP, &this->outamp_cap);
|
|
|
|
else
|
|
|
|
this->outamp_cap = codec->w[codec->audiofunc].outamp_cap;
|
2007-03-11 17:34:04 +03:00
|
|
|
DPRINTF(("%soutamp: mute=%u size=%u steps=%u offset=%u\n",
|
|
|
|
lead, (this->outamp_cap & COP_AMPCAP_MUTE) != 0,
|
2005-06-19 11:42:39 +04:00
|
|
|
COP_AMPCAP_STEPSIZE(this->outamp_cap),
|
|
|
|
COP_AMPCAP_NUMSTEPS(this->outamp_cap),
|
|
|
|
COP_AMPCAP_OFFSET(this->outamp_cap)));
|
|
|
|
}
|
2005-09-29 08:14:03 +04:00
|
|
|
if (codec->init_widget != NULL)
|
|
|
|
codec->init_widget(codec, this, nid);
|
2005-06-18 14:43:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-03-11 17:34:04 +03:00
|
|
|
azalia_widget_init_audio(widget_t *this, const codec_t *codec, const char *lead)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
uint32_t result;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* check audio format */
|
2005-08-02 15:17:56 +04:00
|
|
|
if (this->widgetcap & COP_AWCAP_FORMATOV) {
|
|
|
|
err = codec->comresp(codec, this->nid,
|
|
|
|
CORB_GET_PARAMETER, COP_STREAM_FORMATS, &result);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
this->d.audio.encodings = result;
|
2006-06-24 04:15:22 +04:00
|
|
|
if (result == 0) { /* quirk for CMI9880.
|
|
|
|
* This must not occuur usually... */
|
|
|
|
this->d.audio.encodings =
|
|
|
|
codec->w[codec->audiofunc].d.audio.encodings;
|
|
|
|
this->d.audio.bits_rates =
|
|
|
|
codec->w[codec->audiofunc].d.audio.bits_rates;
|
|
|
|
} else {
|
|
|
|
if ((result & COP_STREAM_FORMAT_PCM) == 0) {
|
|
|
|
aprint_error("%s: %s: No PCM support: %x\n",
|
|
|
|
XNAME(codec->az), this->name, result);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
err = codec->comresp(codec, this->nid, CORB_GET_PARAMETER,
|
|
|
|
COP_PCM, &result);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
this->d.audio.bits_rates = result;
|
2005-08-02 15:17:56 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this->d.audio.encodings =
|
|
|
|
codec->w[codec->audiofunc].d.audio.encodings;
|
|
|
|
this->d.audio.bits_rates =
|
|
|
|
codec->w[codec->audiofunc].d.audio.bits_rates;
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
#ifdef AZALIA_DEBUG
|
2007-03-11 17:34:04 +03:00
|
|
|
azalia_widget_print_audio(this, lead, -1);
|
2005-06-18 14:43:46 +04:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-09 20:26:58 +04:00
|
|
|
azalia_widget_print_audio(const widget_t *this, const char *lead, int channels)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
char flagbuf[FLAGBUFLEN];
|
|
|
|
|
|
|
|
bitmask_snprintf(this->d.audio.encodings, "\20\3AC3\2FLOAT32\1PCM",
|
|
|
|
flagbuf, FLAGBUFLEN);
|
2006-06-09 20:26:58 +04:00
|
|
|
if (channels < 0) {
|
|
|
|
aprint_normal("%sencodings=%s\n", lead, flagbuf);
|
|
|
|
} else if (this->widgetcap & COP_AWCAP_DIGITAL) {
|
|
|
|
aprint_normal("%smax channels=%d, DIGITAL, encodings=%s\n",
|
|
|
|
lead, channels, flagbuf);
|
|
|
|
} else {
|
|
|
|
aprint_normal("%smax channels=%d, encodings=%s\n",
|
|
|
|
lead, channels, flagbuf);
|
|
|
|
}
|
2005-06-18 14:43:46 +04:00
|
|
|
bitmask_snprintf(this->d.audio.bits_rates, "\20\x15""32bit\x14""24bit\x13""20bit"
|
|
|
|
"\x12""16bit\x11""8bit""\x0c""384kHz\x0b""192kHz\x0a""176.4kHz"
|
|
|
|
"\x09""96kHz\x08""88.2kHz\x07""48kHz\x06""44.1kHz\x05""32kHz\x04"
|
|
|
|
"22.05kHz\x03""16kHz\x02""11.025kHz\x01""8kHz",
|
|
|
|
flagbuf, FLAGBUFLEN);
|
2005-06-25 20:32:39 +04:00
|
|
|
aprint_normal("%sPCM formats=%s\n", lead, flagbuf);
|
2005-06-18 14:43:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_widget_init_pin(widget_t *this, const codec_t *codec)
|
|
|
|
{
|
|
|
|
uint32_t result;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = codec->comresp(codec, this->nid, CORB_GET_CONFIGURATION_DEFAULT,
|
|
|
|
0, &result);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
this->d.pin.config = result;
|
|
|
|
this->d.pin.sequence = CORB_CD_SEQUENCE(result);
|
|
|
|
this->d.pin.association = CORB_CD_ASSOCIATION(result);
|
|
|
|
this->d.pin.color = CORB_CD_COLOR(result);
|
2005-06-19 16:34:36 +04:00
|
|
|
this->d.pin.device = CORB_CD_DEVICE(result);
|
2005-06-19 11:42:39 +04:00
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
err = codec->comresp(codec, this->nid, CORB_GET_PARAMETER,
|
2005-06-19 11:42:39 +04:00
|
|
|
COP_PINCAP, &result);
|
2005-06-18 14:43:46 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
this->d.pin.cap = result;
|
2007-05-08 05:39:33 +04:00
|
|
|
|
|
|
|
/* input pin */
|
|
|
|
if ((this->d.pin.cap & COP_PINCAP_INPUT) &&
|
|
|
|
(this->d.pin.cap & COP_PINCAP_OUTPUT) == 0) {
|
|
|
|
err = codec->comresp(codec, this->nid,
|
|
|
|
CORB_GET_PIN_WIDGET_CONTROL, 0, &result);
|
|
|
|
if (err == 0) {
|
|
|
|
result &= ~CORB_PWC_OUTPUT;
|
|
|
|
result |= CORB_PWC_INPUT;
|
|
|
|
codec->comresp(codec, this->nid,
|
|
|
|
CORB_SET_PIN_WIDGET_CONTROL, result, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* output pin, or bidirectional pin */
|
|
|
|
if (this->d.pin.cap & COP_PINCAP_OUTPUT) {
|
|
|
|
err = codec->comresp(codec, this->nid,
|
|
|
|
CORB_GET_PIN_WIDGET_CONTROL, 0, &result);
|
|
|
|
if (err == 0) {
|
|
|
|
result &= ~CORB_PWC_INPUT;
|
|
|
|
result |= CORB_PWC_OUTPUT;
|
|
|
|
codec->comresp(codec, this->nid,
|
|
|
|
CORB_SET_PIN_WIDGET_CONTROL, result, NULL);
|
|
|
|
}
|
|
|
|
}
|
2005-06-19 11:42:39 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-03-11 17:34:04 +03:00
|
|
|
azalia_widget_print_pin(const widget_t *this, const char *lead)
|
2005-06-19 11:42:39 +04:00
|
|
|
{
|
|
|
|
char flagbuf[FLAGBUFLEN];
|
|
|
|
|
2007-03-11 17:34:04 +03:00
|
|
|
DPRINTF(("%spin config; device=%s color=%s assoc=%d seq=%d", lead,
|
2005-06-25 20:32:39 +04:00
|
|
|
pin_devices[this->d.pin.device], pin_colors[this->d.pin.color],
|
|
|
|
this->d.pin.association, this->d.pin.sequence));
|
|
|
|
bitmask_snprintf(this->d.pin.cap, "\20\021EAPD\07BALANCE\06INPUT"
|
|
|
|
"\05OUTPUT\04HEADPHONE\03PRESENCE\02TRIGGER\01IMPEDANCE",
|
|
|
|
flagbuf, FLAGBUFLEN);
|
2005-06-18 14:43:46 +04:00
|
|
|
DPRINTF((" cap=%s\n", flagbuf));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-03-11 17:34:04 +03:00
|
|
|
azalia_widget_init_connection(widget_t *this, const codec_t *codec,
|
|
|
|
const char *lead)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
uint32_t result;
|
|
|
|
int err;
|
2007-02-22 01:59:35 +03:00
|
|
|
bool longform;
|
2005-06-18 14:43:46 +04:00
|
|
|
int length, i;
|
|
|
|
|
|
|
|
this->selected = -1;
|
2005-06-19 16:34:36 +04:00
|
|
|
if ((this->widgetcap & COP_AWCAP_CONNLIST) == 0)
|
2005-06-18 14:43:46 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err = codec->comresp(codec, this->nid, CORB_GET_PARAMETER,
|
|
|
|
COP_CONNECTION_LIST_LENGTH, &result);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
longform = (result & COP_CLL_LONG) != 0;
|
|
|
|
length = COP_CLL_LENGTH(result);
|
|
|
|
if (length == 0)
|
|
|
|
return 0;
|
|
|
|
this->nconnections = length;
|
2006-01-16 17:15:26 +03:00
|
|
|
this->connections = malloc(sizeof(nid_t) * (length + 3),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
2005-06-18 14:43:46 +04:00
|
|
|
if (this->connections == NULL) {
|
|
|
|
aprint_error("%s: out of memory\n", XNAME(codec->az));
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
if (longform) {
|
2006-01-16 17:15:26 +03:00
|
|
|
for (i = 0; i < length;) {
|
2005-06-18 14:43:46 +04:00
|
|
|
err = codec->comresp(codec, this->nid,
|
|
|
|
CORB_GET_CONNECTION_LIST_ENTRY, i, &result);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2006-01-16 17:15:26 +03:00
|
|
|
this->connections[i++] = CORB_CLE_LONG_0(result);
|
|
|
|
this->connections[i++] = CORB_CLE_LONG_1(result);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
} else {
|
2006-01-16 17:15:26 +03:00
|
|
|
for (i = 0; i < length;) {
|
2005-06-18 14:43:46 +04:00
|
|
|
err = codec->comresp(codec, this->nid,
|
|
|
|
CORB_GET_CONNECTION_LIST_ENTRY, i, &result);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2006-01-16 17:15:26 +03:00
|
|
|
this->connections[i++] = CORB_CLE_SHORT_0(result);
|
|
|
|
this->connections[i++] = CORB_CLE_SHORT_1(result);
|
|
|
|
this->connections[i++] = CORB_CLE_SHORT_2(result);
|
|
|
|
this->connections[i++] = CORB_CLE_SHORT_3(result);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (length > 0) {
|
2007-03-11 17:34:04 +03:00
|
|
|
DPRINTF(("%sconnections=0x%x", lead, this->connections[0]));
|
2005-06-18 14:43:46 +04:00
|
|
|
for (i = 1; i < length; i++) {
|
|
|
|
DPRINTF((",0x%x", this->connections[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
err = codec->comresp(codec, this->nid,
|
|
|
|
CORB_GET_CONNECTION_SELECT_CONTROL, 0, &result);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
this->selected = CORB_CSC_INDEX(result);
|
|
|
|
DPRINTF(("; selected=0x%x\n", this->connections[result]));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-21 18:51:37 +04:00
|
|
|
/* ================================================================
|
|
|
|
* Stream functions
|
|
|
|
* ================================================================ */
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_stream_init(stream_t *this, azalia_t *az, int regindex, int strnum, int dir)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
this->az = az;
|
|
|
|
this->regbase = HDA_SD_BASE + regindex * HDA_SD_SIZE;
|
|
|
|
this->intr_bit = 1 << regindex;
|
|
|
|
this->number = strnum;
|
|
|
|
this->dir = dir;
|
|
|
|
|
|
|
|
/* setup BDL buffers */
|
|
|
|
err = azalia_alloc_dmamem(az, sizeof(bdlist_entry_t) * HDA_BDL_MAX,
|
|
|
|
128, &this->bdlist);
|
|
|
|
if (err) {
|
|
|
|
aprint_error("%s: can't allocate a BDL buffer\n", XNAME(az));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-25 20:32:39 +04:00
|
|
|
static int
|
|
|
|
azalia_stream_delete(stream_t *this, azalia_t *az)
|
|
|
|
{
|
|
|
|
if (this->bdlist.addr == NULL)
|
|
|
|
return 0;
|
|
|
|
azalia_free_dmamem(az, &this->bdlist);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-21 18:51:37 +04:00
|
|
|
static int
|
|
|
|
azalia_stream_reset(stream_t *this)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint16_t ctl;
|
|
|
|
|
|
|
|
ctl = STR_READ_2(this, CTL);
|
|
|
|
STR_WRITE_2(this, CTL, ctl | HDA_SD_CTL_SRST);
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
DELAY(10);
|
|
|
|
ctl = STR_READ_2(this, CTL);
|
|
|
|
if (ctl & HDA_SD_CTL_SRST)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i <= 0) {
|
|
|
|
aprint_error("%s: stream reset failure 1\n", XNAME(this->az));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
STR_WRITE_2(this, CTL, ctl & ~HDA_SD_CTL_SRST);
|
|
|
|
for (i = 5000; i >= 0; i--) {
|
|
|
|
DELAY(10);
|
|
|
|
ctl = STR_READ_2(this, CTL);
|
|
|
|
if ((ctl & HDA_SD_CTL_SRST) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i <= 0) {
|
|
|
|
aprint_error("%s: stream reset failure 2\n", XNAME(this->az));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_stream_start(stream_t *this, void *start, void *end, int blk,
|
|
|
|
void (*intr)(void *), void *arg, uint16_t fmt)
|
|
|
|
{
|
|
|
|
bdlist_entry_t *bdlist;
|
|
|
|
bus_addr_t dmaaddr;
|
|
|
|
int err, index;
|
|
|
|
uint16_t ctl;
|
|
|
|
uint8_t ctl2, intctl;
|
|
|
|
|
|
|
|
this->intr = intr;
|
|
|
|
this->intr_arg = arg;
|
|
|
|
|
|
|
|
err = azalia_stream_reset(this);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* setup BDL */
|
|
|
|
dmaaddr = AZALIA_DMA_DMAADDR(&this->buffer);
|
2007-03-04 08:59:00 +03:00
|
|
|
this->dmaend = dmaaddr + ((char *)end - (char *)start);
|
2005-06-21 18:51:37 +04:00
|
|
|
bdlist = (bdlist_entry_t*)this->bdlist.addr;
|
|
|
|
for (index = 0; index < HDA_BDL_MAX; index++) {
|
|
|
|
bdlist[index].low = dmaaddr;
|
|
|
|
bdlist[index].high = PTR_UPPER32(dmaaddr);
|
|
|
|
bdlist[index].length = blk;
|
|
|
|
bdlist[index].flags = BDLIST_ENTRY_IOC;
|
|
|
|
dmaaddr += blk;
|
|
|
|
if (dmaaddr >= this->dmaend) {
|
|
|
|
index++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* The BDL covers the whole of the buffer. */
|
|
|
|
this->dmanext = AZALIA_DMA_DMAADDR(&this->buffer);
|
|
|
|
|
|
|
|
dmaaddr = AZALIA_DMA_DMAADDR(&this->bdlist);
|
|
|
|
STR_WRITE_4(this, BDPL, dmaaddr);
|
|
|
|
STR_WRITE_4(this, BDPU, PTR_UPPER32(dmaaddr));
|
|
|
|
STR_WRITE_2(this, LVI, (index - 1) & HDA_SD_LVI_LVI);
|
|
|
|
ctl2 = STR_READ_1(this, CTL2);
|
|
|
|
STR_WRITE_1(this, CTL2,
|
|
|
|
(ctl2 & ~HDA_SD_CTL2_STRM) | (this->number << HDA_SD_CTL2_STRM_SHIFT));
|
2007-03-04 08:59:00 +03:00
|
|
|
STR_WRITE_4(this, CBL, ((char *)end - (char *)start));
|
2005-06-21 18:51:37 +04:00
|
|
|
|
|
|
|
STR_WRITE_2(this, FMT, fmt);
|
2005-06-25 20:32:39 +04:00
|
|
|
|
2005-09-26 21:30:04 +04:00
|
|
|
err = azalia_codec_connect_stream(&this->az->codecs[this->az->codecno],
|
|
|
|
this->dir, fmt, this->number);
|
2005-06-21 18:51:37 +04:00
|
|
|
if (err)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
intctl = AZ_READ_1(this->az, INTCTL);
|
|
|
|
intctl |= this->intr_bit;
|
|
|
|
AZ_WRITE_1(this->az, INTCTL, intctl);
|
|
|
|
|
|
|
|
ctl = STR_READ_2(this, CTL);
|
|
|
|
ctl |= ctl | HDA_SD_CTL_DEIE | HDA_SD_CTL_FEIE | HDA_SD_CTL_IOCE | HDA_SD_CTL_RUN;
|
|
|
|
STR_WRITE_2(this, CTL, ctl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_stream_halt(stream_t *this)
|
|
|
|
{
|
|
|
|
uint16_t ctl;
|
|
|
|
|
|
|
|
ctl = STR_READ_2(this, CTL);
|
|
|
|
ctl &= ~(HDA_SD_CTL_DEIE | HDA_SD_CTL_FEIE | HDA_SD_CTL_IOCE | HDA_SD_CTL_RUN);
|
|
|
|
STR_WRITE_2(this, CTL, ctl);
|
|
|
|
AZ_WRITE_1(this->az, INTCTL, AZ_READ_1(this->az, INTCTL) & ~this->intr_bit);
|
2006-06-25 17:41:58 +04:00
|
|
|
azalia_codec_disconnect_stream
|
|
|
|
(&this->az->codecs[this->az->codecno], this->dir);
|
2005-06-21 18:51:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_stream_intr(stream_t *this, uint32_t intsts)
|
|
|
|
{
|
|
|
|
if ((intsts & this->intr_bit) == 0)
|
|
|
|
return 0;
|
|
|
|
STR_WRITE_1(this, STS, HDA_SD_STS_DESE
|
|
|
|
| HDA_SD_STS_FIFOE | HDA_SD_STS_BCIS);
|
|
|
|
this->intr(this->intr_arg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
/* ================================================================
|
2005-06-20 15:48:47 +04:00
|
|
|
* MI audio entries
|
2005-06-18 14:43:46 +04:00
|
|
|
* ================================================================ */
|
|
|
|
|
2005-06-19 20:32:55 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
azalia_open(void *v, int flags)
|
2005-06-19 20:32:55 +04:00
|
|
|
{
|
|
|
|
azalia_t *az;
|
2006-06-07 19:23:59 +04:00
|
|
|
codec_t *codec;
|
2005-06-19 20:32:55 +04:00
|
|
|
|
2005-06-20 15:48:47 +04:00
|
|
|
DPRINTF(("%s: flags=0x%x\n", __func__, flags));
|
2005-06-19 20:32:55 +04:00
|
|
|
az = v;
|
2006-06-07 19:23:59 +04:00
|
|
|
codec = &az->codecs[az->codecno];
|
|
|
|
codec->running++;
|
2005-06-19 20:32:55 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
azalia_close(void *v)
|
|
|
|
{
|
|
|
|
azalia_t *az;
|
2006-06-07 19:23:59 +04:00
|
|
|
codec_t *codec;
|
2005-06-19 20:32:55 +04:00
|
|
|
|
2005-06-20 15:48:47 +04:00
|
|
|
DPRINTF(("%s\n", __func__));
|
2005-06-19 20:32:55 +04:00
|
|
|
az = v;
|
2006-06-07 19:23:59 +04:00
|
|
|
codec = &az->codecs[az->codecno];
|
|
|
|
codec->running--;
|
2005-06-19 20:32:55 +04:00
|
|
|
}
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
static int
|
|
|
|
azalia_query_encoding(void *v, audio_encoding_t *enc)
|
|
|
|
{
|
|
|
|
azalia_t *az;
|
|
|
|
codec_t *codec;
|
|
|
|
|
|
|
|
az = v;
|
2005-09-26 21:30:04 +04:00
|
|
|
codec = &az->codecs[az->codecno];
|
2005-06-18 14:43:46 +04:00
|
|
|
return auconv_query_encoding(codec->encodings, enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
azalia_set_params(void *v, int smode, int umode, audio_params_t *p,
|
2005-06-18 14:43:46 +04:00
|
|
|
audio_params_t *r, stream_filter_list_t *pfil, stream_filter_list_t *rfil)
|
|
|
|
{
|
|
|
|
azalia_t *az;
|
|
|
|
codec_t *codec;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
az = v;
|
2005-09-26 21:30:04 +04:00
|
|
|
codec = &az->codecs[az->codecno];
|
2005-06-18 14:43:46 +04:00
|
|
|
if (smode & AUMODE_RECORD && r != NULL) {
|
|
|
|
index = auconv_set_converter(codec->formats, codec->nformats,
|
|
|
|
AUMODE_RECORD, r, TRUE, rfil);
|
|
|
|
if (index < 0)
|
2005-06-21 18:51:37 +04:00
|
|
|
return EINVAL;
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
if (smode & AUMODE_PLAY && p != NULL) {
|
|
|
|
index = auconv_set_converter(codec->formats, codec->nformats,
|
|
|
|
AUMODE_PLAY, p, TRUE, pfil);
|
|
|
|
if (index < 0)
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-10-12 05:30:41 +04:00
|
|
|
azalia_round_blocksize(void *v, int blk, int mode,
|
2006-11-16 04:32:37 +03:00
|
|
|
const audio_params_t *param)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
azalia_t *az;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
blk &= ~0x7f; /* must be multiple of 128 */
|
|
|
|
if (blk <= 0)
|
|
|
|
blk = 128;
|
|
|
|
/* number of blocks must be <= HDA_BDL_MAX */
|
|
|
|
az = v;
|
|
|
|
size = mode == AUMODE_PLAY ? az->pstream.buffer.size : az->rstream.buffer.size;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (size <= 0) {
|
|
|
|
aprint_error("%s: size is 0", __func__);
|
|
|
|
return 256;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (size > HDA_BDL_MAX * blk) {
|
|
|
|
blk = size / HDA_BDL_MAX;
|
|
|
|
if (blk & 0x7f)
|
|
|
|
blk = (blk + 0x7f) & ~0x7f;
|
|
|
|
}
|
|
|
|
DPRINTF(("%s: resultant block size = %d\n", __func__, blk));
|
|
|
|
return blk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_halt_output(void *v)
|
|
|
|
{
|
|
|
|
azalia_t *az;
|
|
|
|
|
2005-06-19 11:42:39 +04:00
|
|
|
DPRINTF(("%s\n", __func__));
|
2005-06-18 14:43:46 +04:00
|
|
|
az = v;
|
2005-06-21 18:51:37 +04:00
|
|
|
return azalia_stream_halt(&az->pstream);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_halt_input(void *v)
|
|
|
|
{
|
2005-06-19 20:32:55 +04:00
|
|
|
azalia_t *az;
|
|
|
|
|
|
|
|
DPRINTF(("%s\n", __func__));
|
|
|
|
az = v;
|
2005-06-21 18:51:37 +04:00
|
|
|
return azalia_stream_halt(&az->rstream);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_getdev(void *v, struct audio_device *dev)
|
|
|
|
{
|
|
|
|
azalia_t *az;
|
|
|
|
|
|
|
|
az = v;
|
2005-06-19 11:42:39 +04:00
|
|
|
strlcpy(dev->name, "HD-Audio", MAX_AUDIO_DEV_LEN);
|
2005-06-18 14:43:46 +04:00
|
|
|
snprintf(dev->version, MAX_AUDIO_DEV_LEN,
|
|
|
|
"%d.%d", AZ_READ_1(az, VMAJ), AZ_READ_1(az, VMIN));
|
|
|
|
strlcpy(dev->config, XNAME(az), MAX_AUDIO_DEV_LEN);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_set_port(void *v, mixer_ctrl_t *mc)
|
|
|
|
{
|
2005-06-19 11:42:39 +04:00
|
|
|
azalia_t *az;
|
|
|
|
codec_t *co;
|
|
|
|
|
|
|
|
az = v;
|
2005-09-26 21:30:04 +04:00
|
|
|
co = &az->codecs[az->codecno];
|
2006-06-07 19:23:59 +04:00
|
|
|
return co->set_port(co, mc);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_get_port(void *v, mixer_ctrl_t *mc)
|
|
|
|
{
|
2005-06-19 11:42:39 +04:00
|
|
|
azalia_t *az;
|
|
|
|
codec_t *co;
|
|
|
|
|
|
|
|
az = v;
|
2005-09-26 21:30:04 +04:00
|
|
|
co = &az->codecs[az->codecno];
|
2006-06-07 19:23:59 +04:00
|
|
|
return co->get_port(co, mc);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_query_devinfo(void *v, mixer_devinfo_t *mdev)
|
|
|
|
{
|
2005-06-19 11:42:39 +04:00
|
|
|
azalia_t *az;
|
2006-06-07 19:23:59 +04:00
|
|
|
const codec_t *co;
|
2005-06-19 11:42:39 +04:00
|
|
|
|
|
|
|
az = v;
|
2005-09-26 21:30:04 +04:00
|
|
|
co = &az->codecs[az->codecno];
|
2005-06-19 11:42:39 +04:00
|
|
|
if (mdev->index >= co->nmixers)
|
|
|
|
return ENXIO;
|
|
|
|
*mdev = co->mixers[mdev->index].devinfo;
|
|
|
|
return 0;
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2006-11-16 04:32:37 +03:00
|
|
|
azalia_allocm(void *v, int dir, size_t size, struct malloc_type *pool,
|
|
|
|
int flags)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
azalia_t *az;
|
|
|
|
stream_t *stream;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
az = v;
|
|
|
|
stream = dir == AUMODE_PLAY ? &az->pstream : &az->rstream;
|
|
|
|
err = azalia_alloc_dmamem(az, size, 128, &stream->buffer);
|
|
|
|
if (err)
|
|
|
|
return NULL;
|
|
|
|
return stream->buffer.addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
azalia_freem(void *v, void *addr, struct malloc_type *pool)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
azalia_t *az;
|
|
|
|
stream_t *stream;
|
|
|
|
|
|
|
|
az = v;
|
|
|
|
if (addr == az->pstream.buffer.addr) {
|
|
|
|
stream = &az->pstream;
|
|
|
|
} else if (addr == az->rstream.buffer.addr) {
|
|
|
|
stream = &az->rstream;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
azalia_free_dmamem(az, &stream->buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
2006-11-16 04:32:37 +03:00
|
|
|
azalia_round_buffersize(void *v, int dir, size_t size)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
size &= ~0x7f; /* must be multiple of 128 */
|
|
|
|
if (size <= 0)
|
|
|
|
size = 128;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
azalia_get_props(void *v)
|
2005-06-18 14:43:46 +04:00
|
|
|
{
|
|
|
|
return AUDIO_PROP_INDEPENDENT | AUDIO_PROP_FULLDUPLEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_trigger_output(void *v, void *start, void *end, int blk,
|
|
|
|
void (*intr)(void *), void *arg, const audio_params_t *param)
|
|
|
|
{
|
|
|
|
azalia_t *az;
|
2005-06-21 18:51:37 +04:00
|
|
|
int err;
|
|
|
|
uint16_t fmt;
|
2005-06-18 14:43:46 +04:00
|
|
|
|
|
|
|
DPRINTF(("%s: this=%p start=%p end=%p blk=%d {enc=%u %uch %u/%ubit %uHz}\n",
|
|
|
|
__func__, v, start, end, blk, param->encoding, param->channels,
|
|
|
|
param->validbits, param->precision, param->sample_rate));
|
|
|
|
|
|
|
|
err = azalia_params2fmt(param, &fmt);
|
|
|
|
if (err)
|
|
|
|
return EINVAL;
|
|
|
|
|
2005-06-21 18:51:37 +04:00
|
|
|
az = v;
|
|
|
|
return azalia_stream_start(&az->pstream, start, end, blk, intr, arg, fmt);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
azalia_trigger_input(void *v, void *start, void *end, int blk,
|
|
|
|
void (*intr)(void *), void *arg, const audio_params_t *param)
|
|
|
|
{
|
2005-06-21 18:51:37 +04:00
|
|
|
azalia_t *az;
|
|
|
|
int err;
|
|
|
|
uint16_t fmt;
|
|
|
|
|
2005-06-18 14:43:46 +04:00
|
|
|
DPRINTF(("%s: this=%p start=%p end=%p blk=%d {enc=%u %uch %u/%ubit %uHz}\n",
|
|
|
|
__func__, v, start, end, blk, param->encoding, param->channels,
|
|
|
|
param->validbits, param->precision, param->sample_rate));
|
2005-06-21 18:51:37 +04:00
|
|
|
|
|
|
|
err = azalia_params2fmt(param, &fmt);
|
|
|
|
if (err)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
az = v;
|
|
|
|
return azalia_stream_start(&az->rstream, start, end, blk, intr, arg, fmt);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
|
|
|
* helpers for MI audio functions
|
|
|
|
* -------------------------------- */
|
|
|
|
static int
|
|
|
|
azalia_params2fmt(const audio_params_t *param, uint16_t *fmt)
|
|
|
|
{
|
|
|
|
uint16_t ret;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (param->channels > HDA_MAX_CHANNELS) {
|
2005-06-25 20:32:39 +04:00
|
|
|
aprint_error("%s: too many channels: %u\n", __func__,
|
|
|
|
param->channels);
|
2005-06-18 14:43:46 +04:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ret |= param->channels - 1;
|
|
|
|
|
|
|
|
switch (param->validbits) {
|
|
|
|
case 8:
|
|
|
|
ret |= HDA_SD_FMT_BITS_8_16;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
ret |= HDA_SD_FMT_BITS_16_16;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
ret |= HDA_SD_FMT_BITS_20_32;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
ret |= HDA_SD_FMT_BITS_24_32;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
ret |= HDA_SD_FMT_BITS_32_32;
|
|
|
|
break;
|
|
|
|
default:
|
2005-06-25 20:32:39 +04:00
|
|
|
aprint_error("%s: invalid validbits: %u\n", __func__,
|
|
|
|
param->validbits);
|
2005-06-18 14:43:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (param->sample_rate == 384000) {
|
2005-06-25 20:32:39 +04:00
|
|
|
aprint_error("%s: invalid sample_rate: %u\n", __func__,
|
|
|
|
param->sample_rate);
|
2005-06-18 14:43:46 +04:00
|
|
|
return EINVAL;
|
|
|
|
} else if (param->sample_rate == 192000) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_48 | HDA_SD_FMT_MULT_X4 | HDA_SD_FMT_DIV_BY1;
|
|
|
|
} else if (param->sample_rate == 176400) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_44 | HDA_SD_FMT_MULT_X4 | HDA_SD_FMT_DIV_BY1;
|
|
|
|
} else if (param->sample_rate == 96000) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_48 | HDA_SD_FMT_MULT_X2 | HDA_SD_FMT_DIV_BY1;
|
|
|
|
} else if (param->sample_rate == 88200) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_44 | HDA_SD_FMT_MULT_X2 | HDA_SD_FMT_DIV_BY1;
|
|
|
|
} else if (param->sample_rate == 48000) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_48 | HDA_SD_FMT_MULT_X1 | HDA_SD_FMT_DIV_BY1;
|
|
|
|
} else if (param->sample_rate == 44100) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_44 | HDA_SD_FMT_MULT_X1 | HDA_SD_FMT_DIV_BY1;
|
|
|
|
} else if (param->sample_rate == 32000) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_48 | HDA_SD_FMT_MULT_X2 | HDA_SD_FMT_DIV_BY3;
|
|
|
|
} else if (param->sample_rate == 22050) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_44 | HDA_SD_FMT_MULT_X1 | HDA_SD_FMT_DIV_BY2;
|
|
|
|
} else if (param->sample_rate == 16000) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_48 | HDA_SD_FMT_MULT_X1 | HDA_SD_FMT_DIV_BY3;
|
|
|
|
} else if (param->sample_rate == 11025) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_44 | HDA_SD_FMT_MULT_X1 | HDA_SD_FMT_DIV_BY4;
|
|
|
|
} else if (param->sample_rate == 8000) {
|
|
|
|
ret |= HDA_SD_FMT_BASE_48 | HDA_SD_FMT_MULT_X1 | HDA_SD_FMT_DIV_BY6;
|
|
|
|
} else {
|
2005-06-25 20:32:39 +04:00
|
|
|
aprint_error("%s: invalid sample_rate: %u\n", __func__,
|
|
|
|
param->sample_rate);
|
2005-06-18 14:43:46 +04:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
*fmt = ret;
|
|
|
|
return 0;
|
|
|
|
}
|