audiovia97.c revision f9ead4a57883f3ef04ef20d83cc47987d98c0687
/*
* 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 VIA VT82C686A AC97 audio controller
*/
/*
*
* Copyright (C) 4Front Technologies 1996-2009.
*/
#include "audiovia97.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 */
0xfffffffe, /* DMA counter register */
4, /* DMA address alignment */
0x3c, /* DMA burstsizes */
4, /* min effective DMA size */
0xffffffff, /* max DMA xfer size */
0xffffffff, /* segment boundary */
1, /* s/g length */
4, /* granularity of device */
0 /* Bus specific DMA flags */
};
static int via97_attach(dev_info_t *);
static int via97_resume(dev_info_t *);
static int via97_detach(via97_devc_t *);
static int via97_suspend(via97_devc_t *);
static int via97_open(void *, int, unsigned *, unsigned *, caddr_t *);
static void via97_close(void *);
static int via97_start(void *);
static void via97_stop(void *);
static int via97_format(void *);
static int via97_channels(void *);
static int via97_rate(void *);
static uint64_t via97_count(void *);
static void via97_sync(void *, unsigned);
static int via97_alloc_port(via97_devc_t *, int);
static void via97_start_port(via97_portc_t *);
static void via97_stop_port(via97_portc_t *);
static void via97_update_port(via97_portc_t *);
static void via97_reset_port(via97_portc_t *);
static void via97_destroy(via97_devc_t *);
static int via97_setup_intrs(via97_devc_t *);
static void via97_hwinit(via97_devc_t *);
static audio_engine_ops_t via97_engine_ops = {
NULL,
NULL,
};
static uint16_t
{
/* Index has only 7 bits */
if (index > 0x7F)
return (0xffff);
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) {
return (0xffff);
}
/* Check if Index still ours? If yes, return data, else return FAIL */
return ((int)tmp & CODEC_DATA);
}
return (0xffff);
}
static void
{
int value = 0;
unsigned 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
{
int status;
return (B_FALSE);
return (B_TRUE);
}
static uint_t
{
int status;
return (B_FALSE);
return (B_TRUE);
}
static uint_t
{
return (DDI_INTR_UNCLAIMED);
}
return (DDI_INTR_UNCLAIMED);
}
}
return (DDI_INTR_CLAIMED);
}
/*
* Audio routines
*/
int
{
*nfragsp = VIA97_NUM_SGD;
return (0);
}
void
via97_close(void *arg)
{
}
int
via97_start(void *arg)
{
}
return (0);
}
void
via97_stop(void *arg)
{
}
}
int
via97_format(void *arg)
{
return (AUDIO_FORMAT_S16_LE);
}
int
via97_channels(void *arg)
{
return (2);
}
int
via97_rate(void *arg)
{
return (48000);
}
void
{
}
via97_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. Note that we have 16 bit
* stereo frames.
*/
return (val);
}
/* private implementation bits */
void
{
return;
}
void
{
return;
}
void
{
/*
* Unfortunately the controller seems to raise interrupt about 32 bytes before
* the DMA pointer moves to a new fragment. This means that the bytes value
* returned will be bogus during few samples before
* the pointer wraps back to the beginning of buffer.
*/
uint32_t n;
n = 0;
} else {
frag =
1;
} else {
}
}
}
void
{
return;
/* Set autostart at EOL, interrupt on FLAG, stereo, 16 bits */
0x81 | /* Set autostart at EOL, interrupt on FLAG */
0x20 | /* 16 bits */
0x10); /* Stereo */
}
int
{
int dir;
char *prop;
unsigned caps;
switch (num) {
case VIA97_REC_SGD_NUM:
prop = "record-interrupts";
dir = DDI_DMA_READ;
break;
case VIA97_PLAY_SGD_NUM:
prop = "play-interrupts";
dir = DDI_DMA_WRITE;
break;
default:
return (DDI_FAILURE);
}
/* 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 < VIA97_NUM_SGD; i++) {
if (i == (VIA97_NUM_SGD - 1)) {
}
}
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 < VIA97_NUM_PORTC; i++) {
if (!portc)
continue;
}
}
}
}
}
}
}
}
}
}
}
}
}
void
{
/* Enable codec, etc */
drv_usecwait(10);
drv_usecwait(10);
/* disable FM io */
/* Enable interrupt on FLAG and on EOL */
}
int
{
goto error;
}
goto error;
}
if (vendor != VIA_VENDOR_ID ||
device != VIA_82C686) {
goto error;
}
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 < VIA97_NUM_PORTC; i++) {
/* reset the port */
} else {
}
}
return (DDI_SUCCESS);
}
int
{
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
int
{
for (int i = 0; i < VIA97_NUM_PORTC; i++) {
}
return (DDI_SUCCESS);
}
static int via97_ddi_quiesce(dev_info_t *);
static struct dev_ops via97_dev_ops = {
DEVO_REV, /* rev */
0, /* refcnt */
NULL, /* getinfo */
nulldev, /* identify */
nulldev, /* probe */
via97_ddi_attach, /* attach */
via97_ddi_detach, /* detach */
nodev, /* reset */
NULL, /* cb_ops */
NULL, /* bus_ops */
NULL, /* power */
via97_ddi_quiesce, /* quiesce */
};
static struct modldrv via97_modldrv = {
&mod_driverops, /* drv_modops */
"Via 82C686 Audio", /* linkinfo */
&via97_dev_ops, /* dev_ops */
};
static struct modlinkage modlinkage = {
{ &via97_modldrv, NULL }
};
int
_init(void)
{
int rv;
}
return (rv);
}
int
_fini(void)
{
int rv;
}
return (rv);
}
int
{
}
int
{
switch (cmd) {
case DDI_ATTACH:
return (via97_attach(dip));
case DDI_RESUME:
return (via97_resume(dip));
default:
return (DDI_FAILURE);
}
}
int
{
switch (cmd) {
case DDI_DETACH:
return (via97_detach(devc));
case DDI_SUSPEND:
return (via97_suspend(devc));
default:
return (DDI_FAILURE);
}
}
int
{
for (int i = 0; i < VIA97_NUM_PORTC; i++) {
}
/*
* Turn off the hardware
*/
return (DDI_SUCCESS);
}