audiovia823x.c revision 505c7a699305ccafcfecc1ab0e7d4a25e2bfd1c2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Purpose: Driver for the VIA8233/8235 AC97 audio controller
*/
/*
* This file is part of Open Sound System
*
* Copyright (C) 4Front Technologies 1996-2008.
*
* This software is released under CDDL 1.0 source license.
* See the COPYING file included in the main directory of this source
* distribution for the license terms and conditions.
*/
#include "audiovia823x.h"
static struct ddi_device_acc_attr dev_attr = {
};
static struct ddi_device_acc_attr buf_attr = {
};
static ddi_dma_attr_t dma_attr_sgd = {
DMA_ATTR_V0, /* version number */
0x00000000, /* low DMA address range */
0xffffffff, /* high DMA address range */
0x0000ffff, /* DMA counter register */
8, /* DMA address alignment */
0x3c, /* DMA burstsizes */
8, /* min effective DMA size */
0xffffffff, /* max DMA xfer size */
0x00000fff, /* segment boundary */
1, /* s/g length */
8, /* granularity of device */
0 /* Bus specific DMA flags */
};
static ddi_dma_attr_t dma_attr_buf = {
DMA_ATTR_V0, /* version number */
0x00000000, /* low DMA address range */
0xffffffff, /* high DMA address range */
0x0001fffe, /* DMA counter register */
4, /* DMA address alignment */
0x3c, /* DMA burstsizes */
4, /* min effective DMA size */
0x0001ffff, /* max DMA xfer size */
0x0001ffff, /* segment boundary */
1, /* s/g length */
4, /* granularity of device */
0 /* Bus specific DMA flags */
};
static int auvia_attach(dev_info_t *);
static int auvia_resume(dev_info_t *);
static int auvia_detach(auvia_devc_t *);
static int auvia_suspend(auvia_devc_t *);
static int auvia_open(void *, int, unsigned *, unsigned *, caddr_t *);
static void auvia_close(void *);
static int auvia_start(void *);
static void auvia_stop(void *);
static int auvia_format(void *);
static int auvia_channels(void *);
static int auvia_rate(void *);
static uint64_t auvia_count(void *);
static void auvia_sync(void *, unsigned);
static size_t auvia_qlen(void *);
static int auvia_alloc_port(auvia_devc_t *, int);
static void auvia_start_port(auvia_portc_t *);
static void auvia_stop_port(auvia_portc_t *);
static void auvia_update_port(auvia_portc_t *);
static void auvia_reset_input(auvia_portc_t *);
static void auvia_reset_output(auvia_portc_t *);
static void auvia_destroy(auvia_devc_t *);
static int auvia_setup_intrs(auvia_devc_t *);
static void auvia_hwinit(auvia_devc_t *);
static audio_engine_ops_t auvia_engine_ops = {
};
static uint16_t
{
int i;
drv_usecwait(100);
/* Check AC CODEC access time out */
for (i = 0; i < CODEC_TIMEOUT_COUNT; i++) {
/* if send command over, break */
break;
drv_usecwait(50);
}
if (i == CODEC_TIMEOUT_COUNT) {
goto failed;
}
/* Check if Index still ours? If yes, return data, else return FAIL */
return (val & CODEC_DATA);
}
return (0xffff);
}
static void
{
int i = 0;
drv_usecwait(100);
/* Check AC CODEC access time out */
for (i = 0; i < CODEC_TIMEOUT_COUNT; i++) {
/* if send command over, break */
break;
drv_usecwait(50);
}
}
static uint_t
{
unsigned intrs = 0;
return (DDI_INTR_UNCLAIMED);
}
if (gstat == 0) {
return (DDI_INTR_UNCLAIMED);
}
for (int i = 0; i < AUVIA_NUM_PORTC; i++) {
if ((status & STATUS_INTR) == 0) {
/* clear any other interrupts */
continue;
}
/*
* NB: The old code did some goofy things to update
* the last valid SGD. However, since we don't ever
* reach the last valid SGD (because we loop first), I
* don't believe we need to do that. It would appear
* that NetBSD does the same.
*/
/* port interrupt */
intrs |= (1U << i);
}
/* XXX: do we really need to do this? */
}
}
}
}
return (DDI_INTR_CLAIMED);
}
/*
* Audio routines
*/
int
{
*nfragsp = AUVIA_NUM_SGD;
return (0);
}
void
auvia_close(void *arg)
{
}
int
auvia_start(void *arg)
{
}
return (0);
}
void
auvia_stop(void *arg)
{
}
}
int
auvia_format(void *arg)
{
return (AUDIO_FORMAT_S16_LE);
}
int
auvia_channels(void *arg)
{
}
int
auvia_rate(void *arg)
{
return (48000);
}
void
{
}
auvia_qlen(void *arg)
{
return (0);
}
auvia_count(void *arg)
{
/*
* The residual is in bytes. We have to convert to frames,
* and then subtract it from the fragment size to get the
* number of frames processed. It is somewhat unfortunate thta
* this (the division) has to happen under the lock. If we
* restricted ourself to stereo out, this would be a simple
* shift.
*/
return (val);
}
/* private implementation bits */
void
{
return;
/*
* Start with autoinit and SGD flag
* interrupts enabled.
*/
}
void
{
return;
}
void
{
uint32_t n;
n = 0;
} else {
frag >>= 24;
frag &= 0xff;
} else {
}
}
}
void
{
return;
/* Select channel assignment - not valid for 8233A */
/*
* Undocumented slot mapping table:
*
* slot 3 = 1 (left)
* slot 4 = 2 (right)
* slot 6 = 5 (center)
* slot 9 = 6 (lfe)
* slot 7 = 3 (left rear)
* slot 8 = 4 (right rear)
*/
case 1:
break;
case 2:
break;
case 4:
break;
case 6:
(5 << 8) | (6 << 12) | (3 << 16) | (4 << 20);
break;
default:
cmap = 0;
break;
}
}
}
static void
{
return;
fmt |= RECFMT_48K;
}
}
int
{
int dir;
char *prop;
unsigned caps;
switch (num) {
case AUVIA_REC_SGD_NUM:
prop = "record-interrupts";
dir = DDI_DMA_READ;
break;
case AUVIA_PLAY_SGD_NUM:
prop = "play-interrupts";
dir = DDI_DMA_WRITE;
break;
default:
return (DDI_FAILURE);
}
/* make sure port is shut down */
/* figure out fragment configuration */
/* make sure the values are good */
}
/* first allocate up space for SGD list */
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
/* now buffers */
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
&count) != DDI_SUCCESS) {
return (DDI_FAILURE);
}
/* now wire descriptors up */
for (int i = 0; i < AUVIA_NUM_SGD; i++) {
if (i == (AUVIA_NUM_SGD - 1)) {
flags |= AUVIA_SGD_EOL;
}
}
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
int
{
int actual;
int rv;
"Can't alloc interrupt handle (rv %d actual %d)",
return (DDI_FAILURE);
}
(void) ddi_intr_free(ih[0]);
return (DDI_FAILURE);
}
DDI_SUCCESS) {
(void) ddi_intr_free(ih[0]);
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
void
{
}
}
for (int i = 0; i < AUVIA_NUM_PORTC; i++) {
if (!portc)
continue;
}
}
}
}
}
}
}
}
}
}
}
}
}
void
{
/* we want to disable all legacy */
val &= ~AUVIA_PCICFG_LEGACY;
/* enable AC'97 link and clear the reset bit */
/* disable SRC (we won't use it) */
val &= ~AUVIA_PCICFG_SRCEN;
/* enable the SGD engines */
drv_usecwait(10);
}
int
{
const char *version;
goto error;
}
goto error;
}
device != VIA_8233A_ID)) {
goto error;
}
version = "8233";
if (pci_revision == 0x50) {
version = "8235";
}
if (pci_revision == 0x60) {
version = "8237";
}
if ((device == VIA_8233A_ID) ||
version = "8233A";
}
goto error;
}
goto error;
}
goto error;
}
goto error;
}
goto error;
}
/* set up kernel statistics */
KSTAT_FLAG_PERSISTENT)) != NULL) {
}
goto error;
}
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
int
{
/* allow ac97 operations again */
for (int i = 0; i < AUVIA_NUM_PORTC; i++) {
/* reset the port */
} else {
}
}
return (DDI_SUCCESS);
}
int
{
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
int
{
for (int i = 0; i < AUVIA_NUM_PORTC; i++) {
}
return (DDI_SUCCESS);
}
static int auvia_ddi_quiesce(dev_info_t *);
static struct dev_ops auvia_dev_ops = {
DEVO_REV, /* rev */
0, /* refcnt */
NULL, /* getinfo */
nulldev, /* identify */
nulldev, /* probe */
auvia_ddi_attach, /* attach */
auvia_ddi_detach, /* detach */
nodev, /* reset */
NULL, /* cb_ops */
NULL, /* bus_ops */
NULL, /* power */
auvia_ddi_quiesce, /* quiesce */
};
static struct modldrv auvia_modldrv = {
&mod_driverops, /* drv_modops */
"Via 823x Audio", /* linkinfo */
&auvia_dev_ops, /* dev_ops */
};
static struct modlinkage modlinkage = {
{ &auvia_modldrv, NULL }
};
int
_init(void)
{
int rv;
}
return (rv);
}
int
_fini(void)
{
int rv;
}
return (rv);
}
int
{
}
int
{
switch (cmd) {
case DDI_ATTACH:
return (auvia_attach(dip));
case DDI_RESUME:
return (auvia_resume(dip));
default:
return (DDI_FAILURE);
}
}
int
{
switch (cmd) {
case DDI_DETACH:
return (auvia_detach(devc));
case DDI_SUSPEND:
return (auvia_suspend(devc));
default:
return (DDI_FAILURE);
}
}
int
{
for (int i = 0; i < AUVIA_NUM_PORTC; i++) {
}
return (DDI_SUCCESS);
}