audiovia823x.h revision 9484:fbd5ddc28e96
192108Sphk/*
292108Sphk * CDDL HEADER START
392108Sphk *
492108Sphk * The contents of this file are subject to the terms of the
592108Sphk * Common Development and Distribution License (the "License").
692108Sphk * You may not use this file except in compliance with the License.
792108Sphk *
892108Sphk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
992108Sphk * or http://www.opensolaris.org/os/licensing.
1092108Sphk * See the License for the specific language governing permissions
1192108Sphk * and limitations under the License.
1292108Sphk *
1392108Sphk * When distributing Covered Code, include this CDDL HEADER in each
1492108Sphk * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1592108Sphk * If applicable, add the following below this CDDL HEADER, with the
1692108Sphk * fields enclosed by brackets "[]" replaced with your own identifying
1792108Sphk * information: Portions Copyright [yyyy] [name of copyright owner]
1892108Sphk *
1992108Sphk * CDDL HEADER END
2092108Sphk */
2192108Sphk
2292108Sphk/*
2392108Sphk * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2492108Sphk * Use is subject to license terms.
2592108Sphk */
2692108Sphk
2792108Sphk/*
2892108Sphk * Purpose: Definitions for the via8233 driver
2992108Sphk */
3092108Sphk/*
3192108Sphk * This file is part of Open Sound System
3292108Sphk *
3392108Sphk * Copyright (C) 4Front Technologies 1996-2008.
3492108Sphk *
3592108Sphk * This software is released under CDDL 1.0 source license.
3692108Sphk * See the COPYING file included in the main directory of this source
3792108Sphk * distribution for the license terms and conditions.
3895276Sphk */
3995276Sphk#ifndef	AUDIOVIA823X_H
4095276Sphk#define	AUDIOVIA823X_H
4192108Sphk
4292108Sphk#define	AUVIA_NAME		"audiovia823x"
4392108Sphk
4492108Sphk#define	VIA_VENDOR_ID		0x1106
4595323Sphk#define	VIA_8233_ID		0x3059
46219950Smav#define	VIA_8233A_ID		0x7059
47115473Sphk
4892108Sphk/* pci configuration registers */
4993248Sphk#define	AUVIA_PCICFG		0x40		/* Via chip specific cfg reg */
5092108Sphk#define	AUVIA_PCICFG_LEGACY	0x00ff0000	/* legacy enables mask */
5192108Sphk#define	AUVIA_PCICFG_ACLINKEN	0x00008000	/* AC'97 link enable */
5292108Sphk#define	AUVIA_PCICFG_NRST	0x00004000	/* inverse of AC'97 reset */
53110541Sphk#define	AUVIA_PCICFG_ACSYNC	0x00002000	/* AC'97 sync */
5492108Sphk#define	AUVIA_PCICFG_SRCEN	0x00000800	/* sample rate converter en */
5592108Sphk#define	AUVIA_PCICFG_SGDEN	0x00000400	/* SGD enable */
5692108Sphk#define	AUVIA_PCICFG_FMEN	0x00000200 	/* FM synth enable (legacy) */
57112709Sphk#define	AUVIA_PCICFG_SBEN	0x00000100	/* SB compat enable (legacy) */
58106518Sphk#define	AUVIA_PCICFG_PRIVALID	0x00000001	/* primary codec ready */
5992108Sphk
60106518Sphk#define	AUVIA_PLAY_SGD_NUM	1
61115624Sphk#define	AUVIA_REC_SGD_NUM	0
62112709Sphk#define	AUVIA_NUM_PORTC		2
63112709Sphk#define	AUVIA_NUM_SGD		16	/* number of fragments */
64113876Sphk
65115473Sphk#define	AUVIA_MAX_INTRS		256
66115473Sphk#define	AUVIA_MIN_INTRS		24
67119660Sphk#define	AUVIA_INTRS		175
68138732Sphk
6992108Sphk#define	AUVIA_SGD_EOL		0x80000000
7092108Sphk#define	AUVIA_SGD_FLAG		0x40000000
7192108Sphk
7292108Sphk#define	CODEC_TIMEOUT_COUNT		500
7392108Sphk
7493250Sphk#define	REG_PLAYBASE		0x40	/* Multichannel SGD */
7592108Sphk#define	REG_RECBASE		0x60
7692108Sphk#define	REG_CODEC		0x80	/* Access AC97 Codec */
7792108Sphk#define	REG_GSTAT		0x84	/* Global status */
78223089Sgibbs
79237518Sken/* REG_CODEC */
80107953Sphk#define	CODEC_IN_CMD		0x01000000	/* busy in sending */
8192108Sphk#define	CODEC_STA_VALID		0x02000000	/* 1:status data is valid */
82238213Strasz#define	CODEC_RD		0x00800000	/* Read CODEC status */
8392108Sphk#define	CODEC_WR		0x00000000	/* Write CODEC status */
8492108Sphk#define	CODEC_INDEX		0x007F0000	/* Index of command register */
8593248Sphk#define	CODEC_DATA		0x0000FFFF	/* AC97 status register data */
8693248Sphk
8793248Sphk/* registers that are offsets relative to a port */
8893248Sphk#define	OFF_STATUS		0x00
89106518Sphk#define	OFF_CTRL		0x01
9092108Sphk#define	OFF_PLAYFMT		0x02
9193248Sphk#define	OFF_RECFIFO		0x02
92107953Sphk#define	OFF_DMA			0x04
93133312Sphk#define	OFF_CHANNELS		0x08
94224147Spjd#define	OFF_RECFMT		0x08
9592108Sphk#define	OFF_COUNT		0x0C
96106518Sphk
97115624Sphk/* bits for above offsets */
98115473Sphk#define	STATUS_INTR		0x3
99115473Sphk
100112709Sphk#define	CTRL_START		0x80
10193776Sphk#define	CTRL_TERMINATE		0x40
102149757Sphk#define	CTRL_AUTOSTART		0x20
103133312Sphk#define	CTRL_MULTICHORDER	0x10	/* SGD 0x40 only, Center/LFE order */
104133312Sphk#define	CTRL_FLAG		0x01
105133312Sphk
106223089Sgibbs#define	PLAYFMT_16BIT		0x80
107133312Sphk#define	PLAYFMT_STEREO		0x20	/* Num channels (1-6), upper nybble */
108133312Sphk#define	PLAYFMT_6CH		0x60
109133312Sphk#define	PLAYFMT_4CH		0x40
110133312Sphk
111237545Sken#define	RECFIFO_ENABLE		0x40
112238213Strasz
113238559Sken#define	RECFMT_48K		0x00ffffff
114238533Strasz#define	RECFMT_STEREO		0x00100000
115133312Sphk#define	RECFMT_16BIT		0x00200000
116115468Sphk
117115468Sphk
11893248Sphktypedef struct {
11992108Sphk	unsigned int phaddr;
12092108Sphk	unsigned int flags;
12192108Sphk} SGD_entry;
122133312Sphk
123138732Sphktypedef struct auvia_portc auvia_portc_t;
124138732Sphktypedef struct auvia_devc auvia_devc_t;
125133312Sphk
12692108Sphkstruct auvia_portc {
12793248Sphk	auvia_devc_t		*devc;
12892108Sphk	audio_engine_t		*engine;
12992108Sphk	caddr_t			base;		/* base for registers */
13092108Sphk	boolean_t		started;
13193248Sphk	int			nchan;
13292108Sphk
13392108Sphk	ddi_dma_handle_t	sgd_dmah;	/* dma for descriptors */
13492108Sphk	ddi_acc_handle_t	sgd_acch;
13592108Sphk	uint32_t		sgd_paddr;
13692108Sphk	caddr_t			sgd_kaddr;
13792108Sphk
13892108Sphk	ddi_dma_handle_t	buf_dmah;	/* dma for buffers */
139223089Sgibbs	ddi_acc_handle_t	buf_acch;
14092108Sphk	uint32_t		buf_paddr;
14193776Sphk	caddr_t			buf_kaddr;
14293776Sphk	size_t			buf_size;
143119660Sphk	int			syncdir;
144237545Sken
145238213Strasz	unsigned		intrs;
146238559Sken	unsigned		fragfr;
147238533Strasz	unsigned		fragsz;
14892108Sphk	unsigned		cur_frag;
14992108Sphk	unsigned		resid;
15092108Sphk
151195195Strasz	uint64_t		count;
15292108Sphk
15392108Sphk	/* helper functions */
15492108Sphk	void			(*reset)(auvia_portc_t *);
15592108Sphk};
15692108Sphk
15792108Sphk
15892108Sphkstruct auvia_devc {
15992108Sphk	dev_info_t		*dip;
16092108Sphk	audio_dev_t		*adev;
16192108Sphk	ac97_t			*ac97;
16292108Sphk	kstat_t			*ksp;
16392108Sphk	boolean_t		suspended;
16492108Sphk
16592108Sphk	char			*chip_name;
16692108Sphk	int			chip_type;
16792108Sphk#define	CHIP_8233		0
16892108Sphk#define	CHIP_8233A		1
16992108Sphk
17092108Sphk	/* registers */
17192108Sphk	ddi_acc_handle_t	pcih;
17292108Sphk	ddi_acc_handle_t	regsh;
17392108Sphk	caddr_t			base;
17492108Sphk
17592108Sphk	kmutex_t		mutex;		/* For normal locking */
17692108Sphk	kmutex_t		low_mutex;	/* For low level routines */
177238886Smav	ddi_intr_handle_t	ih;
178238886Smav	auvia_portc_t		*portc[AUVIA_NUM_PORTC];
179238886Smav};
180260385Sscottl
181260385Sscottl#define	AUVIA_KIOP(X)	((kstat_intr_t *)(X->ksp->ks_data))
182112370Sphk
183112026Sphk#define	INL(devc, reg)		ddi_get32(devc->regsh, (void *)(reg))
184125743Sphk
185125743Sphk#define	INB(devc, reg)		ddi_get8(devc->regsh, (void *)(reg))
186125743Sphk
187125743Sphk#define	OUTL(devc, reg, val)	ddi_put32(devc->regsh, (void *)(reg), (val))
18892108Sphk
18992108Sphk#define	OUTB(devc, reg, val)	ddi_put8(devc->regsh, (void *)(reg), (val))
19092108Sphk
19192108Sphk#endif /* AUDIOVIA823X_H */
19292108Sphk