1/*
2 * Auvia BeOS Driver for Via VT82xx Southbridge audio
3 *
4 * Copyright (c) 2003, Jerome Duval (jerome.duval@free.fr)
5
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Tyler C. Sarna
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *	This product includes software developed by the NetBSD
20 *	Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 *    contributors may be used to endorse or promote products derived
23 *    from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _DEV_PCI_AUVIA_H_
39#define _DEV_PCI_AUVIA_H_
40
41#include <Drivers.h>
42#include <SupportDefs.h>
43#include <OS.h>
44#include <PCI.h>
45#include "auviareg.h"
46#include "config.h"
47#include "queue.h"
48#include "hmulti_audio.h"
49#include "multi.h"
50
51#define VIATECH_VENDOR_ID	0x1106	/* Via Technologies */
52#define VIATECH_82C686_AC97_DEVICE_ID	0x3058	/* Via Technologies VT82C686 AC97 */
53#define VIATECH_8233_AC97_DEVICE_ID		0x3059	/* Via Technologies VT8233 AC97 */
54
55#define VIATECH_8233_AC97_REV_8233_10	0x10	/* rev 10 */
56#define VIATECH_8233_AC97_REV_8233C		0x20
57#define VIATECH_8233_AC97_REV_8233		0x30
58#define VIATECH_8233_AC97_REV_8233A		0x40
59#define VIATECH_8233_AC97_REV_8235		0x50
60#define VIATECH_8233_AC97_REV_8237		0x60	//this is the 5.1 Card in the new Athlon64 boards
61
62#define VERSION "Version alpha 2, Copyright (c) 2003 J��r��me Duval, compiled on " __DATE__ " " __TIME__
63#define DRIVER_NAME "auvia"
64#define FRIENDLY_NAME "Auvia"
65#define FRIENDLY_NAME_686 FRIENDLY_NAME" 82C686"
66#define FRIENDLY_NAME_8233C FRIENDLY_NAME" 8233C"
67#define FRIENDLY_NAME_8233 FRIENDLY_NAME" 8233"
68#define FRIENDLY_NAME_8233A FRIENDLY_NAME" 8233A"
69#define FRIENDLY_NAME_8235 FRIENDLY_NAME" 8235"
70#define FRIENDLY_NAME_8237 FRIENDLY_NAME" 8237"
71#define AUTHOR "J��r��me Duval"
72
73#define VIA_TABLE_SIZE	255
74
75#define	AUVIA_USE_PLAY		(1 << 0)
76#define	AUVIA_USE_RECORD	(1 << 1)
77#define AUVIA_STATE_STARTED	(1 << 0)
78
79/*
80 * Auvia memory managment
81 */
82
83typedef struct _auvia_mem {
84	LIST_ENTRY(_auvia_mem) next;
85	void*		log_base;
86	phys_addr_t	phy_base;
87	area_id		area;
88	size_t		size;
89} auvia_mem;
90
91/*
92 * Streams
93 */
94
95typedef struct _auvia_stream {
96	struct _auvia_dev	*card;
97	uint8				use;
98	uint8				state;
99	uint8				b16;
100	uint32				sample_rate;
101	uint8				channels;
102	uint32				bufframes;
103	uint8				bufcount;
104
105	uint32				base;
106
107	LIST_ENTRY(_auvia_stream)	next;
108
109	void				(*inth) (void *);
110	void				*inthparam;
111
112	void*				dmaops_log_base;
113	phys_addr_t			dmaops_phy_base;
114	area_id				dmaops_area;
115
116	auvia_mem*			buffer;
117	uint16				blksize;	/* in samples */
118	uint16				trigblk;	/* blk on which to trigger inth */
119	uint16				blkmod;	/* Modulo value to wrap trigblk */
120
121	/* multi_audio */
122	volatile int64		frames_count;	// for play or record
123	volatile bigtime_t	real_time;	// for play or record
124	volatile int32		buffer_cycle;	// for play or record
125	int32				first_channel;
126	bool				update_needed;
127} auvia_stream;
128
129/*
130 * Devices
131 */
132
133typedef struct _auvia_dev {
134	char		name[DEVNAME];	/* used for resources */
135	pci_info	info;
136	device_config config;
137
138	void	*ptb_log_base;
139	void	*ptb_phy_base;
140	area_id ptb_area;
141
142	sem_id buffer_ready_sem;
143
144	uint32			interrupt_mask;
145
146	LIST_HEAD(, _auvia_stream) streams;
147
148	LIST_HEAD(, _auvia_mem) mems;
149
150	auvia_stream	*pstream;
151	auvia_stream	*rstream;
152
153	/* multi_audio */
154	multi_dev	multi;
155} auvia_dev;
156
157extern int32 num_cards;
158extern auvia_dev cards[NUM_CARDS];
159
160status_t auvia_stream_set_audioparms(auvia_stream *stream, uint8 channels,
161			     uint8 b16, uint32 sample_rate);
162status_t auvia_stream_commit_parms(auvia_stream *stream);
163status_t auvia_stream_get_nth_buffer(auvia_stream *stream, uint8 chan, uint8 buf,
164					char** buffer, size_t *stride);
165void auvia_stream_start(auvia_stream *stream, void (*inth) (void *), void *inthparam);
166void auvia_stream_halt(auvia_stream *stream);
167auvia_stream *auvia_stream_new(auvia_dev *card, uint8 use, uint32 bufframes, uint8 bufcount);
168void auvia_stream_delete(auvia_stream *stream);
169
170#endif /* _DEV_PCI_AUVIA_H_ */
171