2000-08-09 00:55:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 David Jones <dej@ox.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 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.
|
|
|
|
*/
|
|
|
|
|
2002-03-01 20:30:13 +00:00
|
|
|
/*
|
|
|
|
* Support for VT8233 added by Orion Hodson <oho@acm.org> and tested
|
|
|
|
* by Russell Davies <rd@zip.com.au>.
|
|
|
|
*/
|
|
|
|
|
2000-08-09 00:55:55 +00:00
|
|
|
#include <dev/sound/pcm/sound.h>
|
|
|
|
#include <dev/sound/pcm/ac97.h>
|
|
|
|
|
|
|
|
#include <pci/pcireg.h>
|
|
|
|
#include <pci/pcivar.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <dev/sound/pci/via82c686.h>
|
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
SND_DECLARE_FILE("$FreeBSD$");
|
|
|
|
|
2002-03-01 20:30:13 +00:00
|
|
|
#define VIA686A_PCI_ID 0x30581106
|
|
|
|
#define VIA8233_PCI_ID 0x30591106
|
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
#define NSEGS 4 /* Number of segments in SGD table */
|
2000-08-09 00:55:55 +00:00
|
|
|
|
|
|
|
#define SEGS_PER_CHAN (NSEGS/2)
|
|
|
|
|
2000-12-25 02:49:28 +00:00
|
|
|
#define TIMEOUT 50
|
2001-10-08 05:59:54 +00:00
|
|
|
#define VIA_DEFAULT_BUFSZ 0x1000
|
2000-12-25 02:49:28 +00:00
|
|
|
|
2000-08-09 00:55:55 +00:00
|
|
|
#undef DEB
|
|
|
|
#define DEB(x)
|
|
|
|
|
2000-12-25 02:49:28 +00:00
|
|
|
/* we rely on this struct being packed to 64 bits */
|
|
|
|
struct via_dma_op {
|
|
|
|
u_int32_t ptr;
|
|
|
|
u_int32_t flags;
|
|
|
|
#define VIA_DMAOP_EOL 0x80000000
|
|
|
|
#define VIA_DMAOP_FLAG 0x40000000
|
|
|
|
#define VIA_DMAOP_STOP 0x20000000
|
|
|
|
#define VIA_DMAOP_COUNT(x) ((x)&0x00FFFFFF)
|
|
|
|
};
|
|
|
|
|
2000-08-09 00:55:55 +00:00
|
|
|
struct via_info;
|
|
|
|
|
|
|
|
struct via_chinfo {
|
|
|
|
struct via_info *parent;
|
2001-03-24 23:10:29 +00:00
|
|
|
struct pcm_channel *channel;
|
|
|
|
struct snd_dbuf *buffer;
|
|
|
|
struct via_dma_op *sgd_table;
|
|
|
|
int dir, blksz;
|
2002-03-01 20:30:13 +00:00
|
|
|
|
|
|
|
int rbase; /* base register for channel */
|
2000-08-09 00:55:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct via_info {
|
|
|
|
bus_space_tag_t st;
|
|
|
|
bus_space_handle_t sh;
|
2001-03-25 21:43:24 +00:00
|
|
|
bus_dma_tag_t parent_dmat;
|
|
|
|
bus_dma_tag_t sgd_dmat;
|
2001-03-24 23:10:29 +00:00
|
|
|
bus_dmamap_t sgd_dmamap;
|
2000-08-09 00:55:55 +00:00
|
|
|
|
2000-09-09 19:21:04 +00:00
|
|
|
struct resource *reg, *irq;
|
|
|
|
int regid, irqid;
|
|
|
|
void *ih;
|
2001-03-24 23:10:29 +00:00
|
|
|
struct ac97_info *codec;
|
2000-09-09 19:21:04 +00:00
|
|
|
|
2001-10-08 05:59:54 +00:00
|
|
|
unsigned int bufsz;
|
|
|
|
|
2000-08-09 00:55:55 +00:00
|
|
|
struct via_chinfo pch, rch;
|
|
|
|
struct via_dma_op *sgd_table;
|
2001-03-25 21:43:24 +00:00
|
|
|
u_int16_t codec_caps;
|
2000-08-09 00:55:55 +00:00
|
|
|
};
|
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
static u_int32_t via_fmt[] = {
|
2000-08-20 22:18:56 +00:00
|
|
|
AFMT_U8,
|
|
|
|
AFMT_STEREO | AFMT_U8,
|
|
|
|
AFMT_S16_LE,
|
|
|
|
AFMT_STEREO | AFMT_S16_LE,
|
|
|
|
0
|
2000-08-09 00:55:55 +00:00
|
|
|
};
|
2001-03-24 23:10:29 +00:00
|
|
|
static struct pcmchan_caps via_vracaps = {4000, 48000, via_fmt, 0};
|
|
|
|
static struct pcmchan_caps via_caps = {48000, 48000, via_fmt, 0};
|
2000-08-09 00:55:55 +00:00
|
|
|
|
|
|
|
static u_int32_t
|
|
|
|
via_rd(struct via_info *via, int regno, int size)
|
|
|
|
{
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
return bus_space_read_1(via->st, via->sh, regno);
|
|
|
|
case 2:
|
|
|
|
return bus_space_read_2(via->st, via->sh, regno);
|
|
|
|
case 4:
|
|
|
|
return bus_space_read_4(via->st, via->sh, regno);
|
|
|
|
default:
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
via_wr(struct via_info *via, int regno, u_int32_t data, int size)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
bus_space_write_1(via->st, via->sh, regno, data);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
bus_space_write_2(via->st, via->sh, regno, data);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
bus_space_write_4(via->st, via->sh, regno, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
2000-08-09 00:55:55 +00:00
|
|
|
/* Codec interface */
|
2000-12-18 01:36:41 +00:00
|
|
|
|
|
|
|
static int
|
2000-08-09 00:55:55 +00:00
|
|
|
via_waitready_codec(struct via_info *via)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* poll until codec not busy */
|
|
|
|
for (i = 0; (i < TIMEOUT) &&
|
|
|
|
(via_rd(via, VIA_CODEC_CTL, 4) & VIA_CODEC_BUSY); i++)
|
|
|
|
DELAY(1);
|
|
|
|
if (i >= TIMEOUT) {
|
|
|
|
printf("via: codec busy\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static int
|
2000-08-09 00:55:55 +00:00
|
|
|
via_waitvalid_codec(struct via_info *via)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* poll until codec valid */
|
|
|
|
for (i = 0; (i < TIMEOUT) &&
|
|
|
|
!(via_rd(via, VIA_CODEC_CTL, 4) & VIA_CODEC_PRIVALID); i++)
|
|
|
|
DELAY(1);
|
|
|
|
if (i >= TIMEOUT) {
|
|
|
|
printf("via: codec invalid\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static int
|
|
|
|
via_write_codec(kobj_t obj, void *addr, int reg, u_int32_t val)
|
2000-08-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
struct via_info *via = addr;
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
if (via_waitready_codec(via)) return -1;
|
2000-08-09 00:55:55 +00:00
|
|
|
|
2002-03-01 20:30:13 +00:00
|
|
|
via_wr(via, VIA_CODEC_CTL,
|
|
|
|
VIA_CODEC_PRIVALID | VIA_CODEC_INDEX(reg) | val, 4);
|
2000-12-18 01:36:41 +00:00
|
|
|
|
|
|
|
return 0;
|
2000-08-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static int
|
|
|
|
via_read_codec(kobj_t obj, void *addr, int reg)
|
2000-08-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
struct via_info *via = addr;
|
|
|
|
|
|
|
|
if (via_waitready_codec(via))
|
2001-03-24 23:10:29 +00:00
|
|
|
return -1;
|
2000-08-09 00:55:55 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
via_wr(via, VIA_CODEC_CTL, VIA_CODEC_PRIVALID | VIA_CODEC_READ | VIA_CODEC_INDEX(reg),4);
|
2000-08-09 00:55:55 +00:00
|
|
|
|
|
|
|
if (via_waitready_codec(via))
|
2001-03-24 23:10:29 +00:00
|
|
|
return -1;
|
2000-08-09 00:55:55 +00:00
|
|
|
|
|
|
|
if (via_waitvalid_codec(via))
|
2001-03-24 23:10:29 +00:00
|
|
|
return -1;
|
2000-08-09 00:55:55 +00:00
|
|
|
|
|
|
|
return via_rd(via, VIA_CODEC_CTL, 2);
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static kobj_method_t via_ac97_methods[] = {
|
|
|
|
KOBJMETHOD(ac97_read, via_read_codec),
|
|
|
|
KOBJMETHOD(ac97_write, via_write_codec),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
AC97_DECLARE(via_ac97);
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2000-08-09 00:55:55 +00:00
|
|
|
|
|
|
|
static int
|
2001-03-24 23:10:29 +00:00
|
|
|
via_buildsgdt(struct via_chinfo *ch)
|
2000-08-09 00:55:55 +00:00
|
|
|
{
|
2001-03-24 23:10:29 +00:00
|
|
|
u_int32_t phys_addr, flag;
|
|
|
|
int i, segs, seg_size;
|
2000-08-09 00:55:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Build the scatter/gather DMA (SGD) table.
|
|
|
|
* There are four slots in the table: two for play, two for record.
|
|
|
|
* This creates two half-buffers, one of which is playing; the other
|
|
|
|
* is feeding.
|
|
|
|
*/
|
2001-03-24 23:10:29 +00:00
|
|
|
seg_size = ch->blksz;
|
|
|
|
segs = sndbuf_getsize(ch->buffer) / seg_size;
|
|
|
|
phys_addr = vtophys(sndbuf_getbuf(ch->buffer));
|
2000-08-09 00:55:55 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
for (i = 0; i < segs; i++) {
|
|
|
|
flag = (i == segs - 1)? VIA_DMAOP_EOL : VIA_DMAOP_FLAG;
|
|
|
|
ch->sgd_table[i].ptr = phys_addr + (i * seg_size);
|
|
|
|
ch->sgd_table[i].flags = flag | seg_size;
|
2000-08-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
/* channel interface */
|
|
|
|
static void *
|
2002-03-01 20:30:13 +00:00
|
|
|
viachan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b,
|
|
|
|
struct pcm_channel *c, int dir)
|
2001-03-24 23:10:29 +00:00
|
|
|
{
|
|
|
|
struct via_info *via = devinfo;
|
|
|
|
struct via_chinfo *ch = (dir == PCMDIR_PLAY)? &via->pch : &via->rch;
|
|
|
|
|
|
|
|
ch->parent = via;
|
|
|
|
ch->channel = c;
|
|
|
|
ch->buffer = b;
|
|
|
|
ch->dir = dir;
|
|
|
|
ch->sgd_table = &via->sgd_table[(dir == PCMDIR_PLAY)? 0 : SEGS_PER_CHAN];
|
|
|
|
if (ch->dir == PCMDIR_PLAY) {
|
2002-03-01 20:30:13 +00:00
|
|
|
ch->rbase = VIA_PLAY_BASE;
|
2001-03-24 23:10:29 +00:00
|
|
|
} else {
|
2002-03-01 20:30:13 +00:00
|
|
|
ch->rbase = VIA_REC_BASE;
|
2001-03-24 23:10:29 +00:00
|
|
|
}
|
|
|
|
|
2001-10-08 05:59:54 +00:00
|
|
|
if (sndbuf_alloc(ch->buffer, via->parent_dmat, via->bufsz) == -1)
|
2001-03-24 23:10:29 +00:00
|
|
|
return NULL;
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2000-08-09 00:55:55 +00:00
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
viachan_setformat(kobj_t obj, void *data, u_int32_t format)
|
2000-08-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
struct via_chinfo *ch = data;
|
|
|
|
struct via_info *via = ch->parent;
|
|
|
|
|
2002-03-01 20:30:13 +00:00
|
|
|
u_int32_t r = ch->rbase + VIA_RP_MODE;
|
|
|
|
u_int8_t v = via_rd(via, r, 1);
|
|
|
|
|
|
|
|
v &= ~(VIA_RPMODE_STEREO | VIA_RPMODE_16BIT);
|
2000-08-09 00:55:55 +00:00
|
|
|
if (format & AFMT_STEREO)
|
2002-03-01 20:30:13 +00:00
|
|
|
v |= VIA_RPMODE_STEREO;
|
2000-08-09 00:55:55 +00:00
|
|
|
if (format & AFMT_S16_LE)
|
2002-03-01 20:30:13 +00:00
|
|
|
v |= VIA_RPMODE_16BIT;
|
|
|
|
via_wr(via, r, v, 1);
|
2000-08-09 00:55:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
viachan_setspeed(kobj_t obj, void *data, u_int32_t speed)
|
2000-08-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
struct via_chinfo *ch = data;
|
|
|
|
struct via_info *via = ch->parent;
|
2001-03-24 23:10:29 +00:00
|
|
|
int reg;
|
2000-08-09 00:55:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic AC'97 defines a 48 kHz sample rate only. For other rates,
|
|
|
|
* upsampling is required.
|
|
|
|
*
|
|
|
|
* The VT82C686A does not perform upsampling, and neither do we.
|
|
|
|
* If the codec supports variable-rate audio (i.e. does the upsampling
|
|
|
|
* itself), then negotiate the rate with the codec. Otherwise,
|
|
|
|
* return 48 kHz cuz that's all you got.
|
|
|
|
*/
|
2001-03-24 23:10:29 +00:00
|
|
|
if (via->codec_caps & AC97_EXTCAP_VRA) {
|
|
|
|
reg = (ch->dir == PCMDIR_PLAY)? AC97_REGEXT_FDACRATE : AC97_REGEXT_LADCRATE;
|
|
|
|
return ac97_setrate(via->codec, reg, speed);
|
|
|
|
} else
|
|
|
|
return 48000;
|
2000-08-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
viachan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
|
2000-08-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
struct via_chinfo *ch = data;
|
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
ch->blksz = blocksize;
|
|
|
|
sndbuf_resize(ch->buffer, SEGS_PER_CHAN, ch->blksz);
|
|
|
|
|
|
|
|
return ch->blksz;
|
2000-08-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
viachan_trigger(kobj_t obj, void *data, int go)
|
2000-08-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
struct via_chinfo *ch = data;
|
|
|
|
struct via_info *via = ch->parent;
|
2002-03-01 20:30:13 +00:00
|
|
|
struct via_dma_op *ado = ch->sgd_table;
|
2001-03-24 23:10:29 +00:00
|
|
|
|
2002-03-01 20:30:13 +00:00
|
|
|
switch(go) {
|
|
|
|
case PCMTRIG_START:
|
2001-03-24 23:10:29 +00:00
|
|
|
via_buildsgdt(ch);
|
2002-03-01 20:30:13 +00:00
|
|
|
via_wr(via, ch->rbase + VIA_RP_DMAOPS_BASE, vtophys(ado), 4);
|
|
|
|
via_wr(via, ch->rbase + VIA_RP_CONTROL, VIA_RPCTRL_START, 1);
|
|
|
|
break;
|
|
|
|
case PCMTRIG_STOP:
|
|
|
|
case PCMTRIG_ABORT:
|
|
|
|
via_wr(via, ch->rbase + VIA_RP_CONTROL,
|
|
|
|
VIA_RPCTRL_TERMINATE, 1);
|
|
|
|
break;
|
|
|
|
}
|
2000-08-09 00:55:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-12-18 01:36:41 +00:00
|
|
|
viachan_getptr(kobj_t obj, void *data)
|
2000-08-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
struct via_chinfo *ch = data;
|
|
|
|
struct via_info *via = ch->parent;
|
|
|
|
struct via_dma_op *ado;
|
2001-03-24 23:10:29 +00:00
|
|
|
int ptr, base, base1, len, seg;
|
2000-08-09 00:55:55 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
ado = ch->sgd_table;
|
2002-03-01 20:30:13 +00:00
|
|
|
base1 = via_rd(via, ch->rbase + VIA_RP_DMAOPS_BASE, 4);
|
|
|
|
len = via_rd(via, ch->rbase + VIA_RP_DMAOPS_COUNT, 4);
|
|
|
|
base = via_rd(via, ch->rbase + VIA_RP_DMAOPS_BASE, 4);
|
2001-03-24 23:10:29 +00:00
|
|
|
if (base != base1) /* Avoid race hazard */
|
2002-03-01 20:30:13 +00:00
|
|
|
len = via_rd(via, ch->rbase + VIA_RP_DMAOPS_COUNT, 4);
|
2000-08-09 00:55:55 +00:00
|
|
|
|
2001-03-25 21:43:24 +00:00
|
|
|
DEB(printf("viachan_getptr: len / base = %x / %x\n", len, base));
|
2000-08-09 00:55:55 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
/* Base points to SGD segment to do, one past current */
|
2000-08-09 00:55:55 +00:00
|
|
|
|
2001-03-25 21:43:24 +00:00
|
|
|
/* Determine how many segments have been done */
|
|
|
|
seg = (base - vtophys(ado)) / sizeof(struct via_dma_op);
|
2001-03-24 23:10:29 +00:00
|
|
|
if (seg == 0)
|
|
|
|
seg = SEGS_PER_CHAN;
|
2000-08-09 00:55:55 +00:00
|
|
|
|
2001-03-25 21:43:24 +00:00
|
|
|
/* Now work out offset: seg less count */
|
2001-03-24 23:10:29 +00:00
|
|
|
ptr = (seg * sndbuf_getsize(ch->buffer) / SEGS_PER_CHAN) - len;
|
|
|
|
if (ch->dir == PCMDIR_REC) {
|
2000-08-09 00:55:55 +00:00
|
|
|
/* DMA appears to operate on memory 'lines' of 32 bytes */
|
|
|
|
/* so don't return any part line - it isn't in RAM yet */
|
|
|
|
ptr = ptr & ~0x1f;
|
2001-03-24 23:10:29 +00:00
|
|
|
}
|
|
|
|
|
2001-03-25 21:43:24 +00:00
|
|
|
DEB(printf("return ptr=%d\n", ptr));
|
|
|
|
return ptr;
|
2000-08-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
static struct pcmchan_caps *
|
2000-12-18 01:36:41 +00:00
|
|
|
viachan_getcaps(kobj_t obj, void *data)
|
2000-08-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
struct via_chinfo *ch = data;
|
2001-03-24 23:10:29 +00:00
|
|
|
struct via_info *via = ch->parent;
|
|
|
|
|
|
|
|
return (via->codec_caps & AC97_EXTCAP_VRA)? &via_vracaps : &via_caps;
|
2000-08-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
|
2002-03-01 20:30:13 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
static kobj_method_t viachan_methods[] = {
|
|
|
|
KOBJMETHOD(channel_init, viachan_init),
|
|
|
|
KOBJMETHOD(channel_setformat, viachan_setformat),
|
|
|
|
KOBJMETHOD(channel_setspeed, viachan_setspeed),
|
|
|
|
KOBJMETHOD(channel_setblocksize, viachan_setblocksize),
|
|
|
|
KOBJMETHOD(channel_trigger, viachan_trigger),
|
|
|
|
KOBJMETHOD(channel_getptr, viachan_getptr),
|
|
|
|
KOBJMETHOD(channel_getcaps, viachan_getcaps),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
CHANNEL_DECLARE(viachan);
|
|
|
|
|
2002-03-01 20:30:13 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* VT8233 Specific methods */
|
|
|
|
|
|
|
|
static void*
|
|
|
|
via8233chan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b,
|
|
|
|
struct pcm_channel *c, int dir)
|
|
|
|
{
|
|
|
|
struct via_info *via = devinfo;
|
|
|
|
struct via_chinfo *ch = viachan_init(obj, devinfo, b, c, dir);
|
|
|
|
|
|
|
|
/* Fix dxs volume - only need to do once (hopefully) */
|
|
|
|
if (ch) {
|
|
|
|
via_wr(via, ch->rbase + VIA8233_RP_DXS_LVOL, 0, 1);
|
|
|
|
via_wr(via, ch->rbase + VIA8233_RP_DXS_RVOL, 0, 1);
|
|
|
|
}
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
via8233chan_setspeed(kobj_t obj, void *data, u_int32_t speed)
|
|
|
|
{
|
|
|
|
struct via_chinfo *ch = data;
|
|
|
|
struct via_info *via = ch->parent;
|
|
|
|
|
|
|
|
u_int32_t r = ch->rbase + VIA8233_RP_RATEFMT;
|
|
|
|
u_int32_t v = via_rd(via, r, 4) & ~VIA8233_RATEFMT_48K;
|
|
|
|
|
|
|
|
/* Careful to avoid overflow (divide by 16) */
|
|
|
|
|
|
|
|
v |= VIA8233_RATEFMT_48K * (speed / 16) / (48000 / 16);
|
|
|
|
via_wr(via, r, v, 4);
|
|
|
|
|
|
|
|
/* Need to do ac97 thing like via686 */
|
|
|
|
return viachan_setspeed(obj, data, speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
via8233chan_setformat(kobj_t obj, void *data, u_int32_t format)
|
|
|
|
{
|
|
|
|
struct via_chinfo *ch = data;
|
|
|
|
struct via_info *via = ch->parent;
|
|
|
|
|
|
|
|
u_int32_t r = ch->rbase + VIA8233_RP_RATEFMT;
|
|
|
|
u_int32_t v = via_rd(via, r, 4);
|
|
|
|
|
|
|
|
v &= ~(VIA8233_RATEFMT_STEREO | VIA8233_RATEFMT_16BIT);
|
|
|
|
if (format & AFMT_STEREO)
|
|
|
|
v |= VIA8233_RATEFMT_STEREO;
|
|
|
|
if (format & AFMT_16BIT)
|
|
|
|
v |= VIA8233_RATEFMT_16BIT;
|
|
|
|
via_wr(via, r, v, 4);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
via8233chan_trigger(kobj_t obj, void* data, int go)
|
|
|
|
{
|
|
|
|
struct via_chinfo *ch = data;
|
|
|
|
struct via_info *via = ch->parent;
|
|
|
|
struct via_dma_op *ado = ch->sgd_table;
|
|
|
|
|
|
|
|
switch(go) {
|
|
|
|
case PCMTRIG_START:
|
|
|
|
via_buildsgdt(ch);
|
|
|
|
via_wr(via, ch->rbase + VIA_RP_DMAOPS_BASE, vtophys(ado), 4);
|
|
|
|
via_wr(via, ch->rbase + VIA_RP_CONTROL,
|
|
|
|
VIA_RPCTRL_START | VIA_RPCTRL_AUTOSTART |
|
|
|
|
VIA_RPCTRL_I_STOP | VIA_RPCTRL_I_EOL |
|
|
|
|
VIA_RPCTRL_I_FLAG, 1);
|
|
|
|
break;
|
|
|
|
case PCMTRIG_STOP:
|
|
|
|
case PCMTRIG_ABORT:
|
|
|
|
via_wr(via, ch->rbase + VIA_RP_CONTROL,
|
|
|
|
VIA_RPCTRL_TERMINATE, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static kobj_method_t via8233chan_methods[] = {
|
|
|
|
KOBJMETHOD(channel_init, via8233chan_init),
|
|
|
|
KOBJMETHOD(channel_setformat, via8233chan_setformat),
|
|
|
|
KOBJMETHOD(channel_setspeed, via8233chan_setspeed),
|
|
|
|
KOBJMETHOD(channel_setblocksize, viachan_setblocksize),
|
|
|
|
KOBJMETHOD(channel_trigger, via8233chan_trigger),
|
|
|
|
KOBJMETHOD(channel_getptr, viachan_getptr),
|
|
|
|
KOBJMETHOD(channel_getcaps, viachan_getcaps),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
CHANNEL_DECLARE(via8233chan);
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
2000-08-09 00:55:55 +00:00
|
|
|
static void
|
|
|
|
via_intr(void *p)
|
|
|
|
{
|
|
|
|
struct via_info *via = p;
|
|
|
|
|
2002-03-01 20:30:13 +00:00
|
|
|
if (via_rd(via, VIA_PLAY_BASE + VIA_RP_STAT, 1) & VIA_RPSTAT_INTR) {
|
|
|
|
via_wr(via, VIA_PLAY_BASE + VIA_RP_STAT, VIA_RPSTAT_INTR, 1);
|
2000-08-09 00:55:55 +00:00
|
|
|
chn_intr(via->pch.channel);
|
2002-03-01 20:30:13 +00:00
|
|
|
DEB(printf("intr play\n"));
|
2000-08-09 00:55:55 +00:00
|
|
|
}
|
2002-03-01 20:30:13 +00:00
|
|
|
if (via_rd(via, VIA_REC_BASE + VIA_RP_STAT, 1) & VIA_RPSTAT_INTR) {
|
|
|
|
via_wr(via, VIA_REC_BASE + VIA_RP_STAT, VIA_RPSTAT_INTR, 1);
|
2000-08-09 00:55:55 +00:00
|
|
|
chn_intr(via->rch.channel);
|
2002-03-01 20:30:13 +00:00
|
|
|
DEB(printf("intr rec\n"));
|
2000-08-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
/*
|
|
|
|
* Probe and attach the card
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
via_probe(device_t dev)
|
|
|
|
{
|
2002-03-01 20:30:13 +00:00
|
|
|
switch(pci_get_devid(dev)) {
|
|
|
|
case VIA686A_PCI_ID:
|
|
|
|
device_set_desc(dev, "VIA VT82C686A");
|
|
|
|
return 0;
|
|
|
|
case VIA8233_PCI_ID:
|
|
|
|
device_set_desc(dev, "VIA VT8233");
|
|
|
|
return 0;
|
2000-12-18 01:36:41 +00:00
|
|
|
}
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
static void
|
|
|
|
dma_cb(void *p, bus_dma_segment_t *bds, int a, int b)
|
2000-12-18 01:36:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
via_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct via_info *via = 0;
|
2001-03-25 21:43:24 +00:00
|
|
|
char status[SND_STATUSLEN];
|
|
|
|
u_int32_t data;
|
2000-12-18 01:36:41 +00:00
|
|
|
|
2001-06-21 19:45:59 +00:00
|
|
|
if ((via = malloc(sizeof *via, M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) {
|
2000-12-18 01:36:41 +00:00
|
|
|
device_printf(dev, "cannot allocate softc\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get resources */
|
|
|
|
data = pci_read_config(dev, PCIR_COMMAND, 2);
|
|
|
|
data |= (PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN);
|
|
|
|
pci_write_config(dev, PCIR_COMMAND, data, 2);
|
|
|
|
data = pci_read_config(dev, PCIR_COMMAND, 2);
|
|
|
|
|
|
|
|
pci_write_config(dev, VIA_PCICONF_MISC,
|
2002-03-01 20:30:13 +00:00
|
|
|
VIA_PCICONF_ACLINKENAB | VIA_PCICONF_ACSGD |
|
|
|
|
VIA_PCICONF_ACNOTRST | VIA_PCICONF_ACVSR, 1);
|
2000-12-18 01:36:41 +00:00
|
|
|
|
|
|
|
via->regid = PCIR_MAPS;
|
2002-03-01 20:30:13 +00:00
|
|
|
via->reg = bus_alloc_resource(dev, SYS_RES_IOPORT, &via->regid, 0, ~0,
|
|
|
|
1, RF_ACTIVE);
|
2000-12-18 01:36:41 +00:00
|
|
|
if (!via->reg) {
|
2000-12-25 02:21:16 +00:00
|
|
|
device_printf(dev, "cannot allocate bus resource.");
|
2000-12-18 01:36:41 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
via->st = rman_get_bustag(via->reg);
|
|
|
|
via->sh = rman_get_bushandle(via->reg);
|
|
|
|
|
2001-10-08 05:59:54 +00:00
|
|
|
via->bufsz = pcm_getbuffersize(dev, 4096, VIA_DEFAULT_BUFSZ, 65536);
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
via->irqid = 0;
|
2002-03-01 20:30:13 +00:00
|
|
|
via->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &via->irqid, 0, ~0, 1,
|
|
|
|
RF_ACTIVE | RF_SHAREABLE);
|
|
|
|
if (!via->irq ||
|
|
|
|
snd_setup_intr(dev, via->irq, 0, via_intr, via, &via->ih)) {
|
2000-12-18 01:36:41 +00:00
|
|
|
device_printf(dev, "unable to map interrupt\n");
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2002-03-01 20:30:13 +00:00
|
|
|
via_wr(via, VIA_PLAY_BASE + VIA_RP_MODE,
|
|
|
|
VIA_RPMODE_AUTOSTART|VIA_RPMODE_INTR_FLAG|VIA_RPMODE_INTR_EOL,
|
|
|
|
1);
|
|
|
|
via_wr(via, VIA_REC_BASE + VIA_RP_MODE,
|
|
|
|
VIA_RPMODE_AUTOSTART|VIA_RPMODE_INTR_FLAG|VIA_RPMODE_INTR_EOL,
|
|
|
|
1);
|
2000-12-18 01:36:41 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
via->codec = AC97_CREATE(dev, via, via_ac97);
|
|
|
|
if (!via->codec)
|
|
|
|
goto bad;
|
2000-12-18 01:36:41 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
mixer_init(dev, ac97_getmixerclass(), via->codec);
|
2000-12-18 01:36:41 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
via->codec_caps = ac97_getextcaps(via->codec);
|
2001-11-21 04:06:52 +00:00
|
|
|
ac97_setextmode(via->codec,
|
|
|
|
via->codec_caps & (AC97_EXTCAP_VRA | AC97_EXTCAP_VRM));
|
2000-12-18 01:36:41 +00:00
|
|
|
|
|
|
|
/* DMA tag for buffers */
|
|
|
|
if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0,
|
|
|
|
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
/*highaddr*/BUS_SPACE_MAXADDR,
|
|
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
2001-10-08 05:59:54 +00:00
|
|
|
/*maxsize*/via->bufsz, /*nsegments*/1, /*maxsegz*/0x3ffff,
|
2000-12-18 01:36:41 +00:00
|
|
|
/*flags*/0, &via->parent_dmat) != 0) {
|
|
|
|
device_printf(dev, "unable to create dma tag\n");
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DMA tag for SGD table. The 686 uses scatter/gather DMA and
|
|
|
|
* requires a list in memory of work to do. We need only 16 bytes
|
|
|
|
* for this list, and it is wasteful to allocate 16K.
|
|
|
|
*/
|
|
|
|
if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0,
|
|
|
|
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
/*highaddr*/BUS_SPACE_MAXADDR,
|
|
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
|
|
|
/*maxsize*/NSEGS * sizeof(struct via_dma_op),
|
|
|
|
/*nsegments*/1, /*maxsegz*/0x3ffff,
|
|
|
|
/*flags*/0, &via->sgd_dmat) != 0) {
|
|
|
|
device_printf(dev, "unable to create dma tag\n");
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
if (bus_dmamem_alloc(via->sgd_dmat, (void **)&via->sgd_table, BUS_DMA_NOWAIT, &via->sgd_dmamap) == -1)
|
|
|
|
goto bad;
|
|
|
|
if (bus_dmamap_load(via->sgd_dmat, via->sgd_dmamap, via->sgd_table, NSEGS * sizeof(struct via_dma_op), dma_cb, 0, 0))
|
|
|
|
goto bad;
|
2000-12-18 01:36:41 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld", rman_get_start(via->reg), rman_get_start(via->irq));
|
2000-12-18 01:36:41 +00:00
|
|
|
|
|
|
|
/* Register */
|
|
|
|
if (pcm_register(dev, via, 1, 1)) goto bad;
|
2002-03-01 20:30:13 +00:00
|
|
|
|
|
|
|
switch (pci_get_devid(dev)) {
|
|
|
|
case VIA686A_PCI_ID:
|
|
|
|
pcm_addchan(dev, PCMDIR_PLAY, &viachan_class, via);
|
|
|
|
pcm_addchan(dev, PCMDIR_REC, &viachan_class, via);
|
|
|
|
break;
|
|
|
|
case VIA8233_PCI_ID:
|
|
|
|
pcm_addchan(dev, PCMDIR_PLAY, &via8233chan_class, via);
|
|
|
|
pcm_addchan(dev, PCMDIR_REC, &via8233chan_class, via);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
pcm_setstatus(dev, status);
|
2002-03-01 20:30:13 +00:00
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
return 0;
|
|
|
|
bad:
|
2001-03-24 23:10:29 +00:00
|
|
|
if (via->codec) ac97_destroy(via->codec);
|
2000-12-18 01:36:41 +00:00
|
|
|
if (via->reg) bus_release_resource(dev, SYS_RES_IOPORT, via->regid, via->reg);
|
|
|
|
if (via->ih) bus_teardown_intr(dev, via->irq, via->ih);
|
|
|
|
if (via->irq) bus_release_resource(dev, SYS_RES_IRQ, via->irqid, via->irq);
|
|
|
|
if (via->parent_dmat) bus_dma_tag_destroy(via->parent_dmat);
|
2001-03-24 23:10:29 +00:00
|
|
|
if (via->sgd_dmamap) bus_dmamap_unload(via->sgd_dmat, via->sgd_dmamap);
|
2000-12-18 01:36:41 +00:00
|
|
|
if (via->sgd_dmat) bus_dma_tag_destroy(via->sgd_dmat);
|
|
|
|
if (via) free(via, M_DEVBUF);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
via_detach(device_t dev)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct via_info *via = 0;
|
|
|
|
|
|
|
|
r = pcm_unregister(dev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
via = pcm_getdevinfo(dev);
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, via->regid, via->reg);
|
|
|
|
bus_teardown_intr(dev, via->irq, via->ih);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, via->irqid, via->irq);
|
|
|
|
bus_dma_tag_destroy(via->parent_dmat);
|
2001-03-24 23:10:29 +00:00
|
|
|
bus_dmamap_unload(via->sgd_dmat, via->sgd_dmamap);
|
2000-12-18 01:36:41 +00:00
|
|
|
bus_dma_tag_destroy(via->sgd_dmat);
|
|
|
|
free(via, M_DEVBUF);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static device_method_t via_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, via_probe),
|
|
|
|
DEVMETHOD(device_attach, via_attach),
|
|
|
|
DEVMETHOD(device_detach, via_detach),
|
|
|
|
{ 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t via_driver = {
|
|
|
|
"pcm",
|
|
|
|
via_methods,
|
2001-08-23 11:30:52 +00:00
|
|
|
PCM_SOFTC_SIZE,
|
2000-12-18 01:36:41 +00:00
|
|
|
};
|
|
|
|
|
2001-10-24 21:38:08 +00:00
|
|
|
DRIVER_MODULE(snd_via82c686, pci, via_driver, pcm_devclass, 0, 0);
|
|
|
|
MODULE_DEPEND(snd_via82c686, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER);
|
|
|
|
MODULE_VERSION(snd_via82c686, 1);
|