xref: /haiku/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
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 "multi_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 
61 #define VERSION "Version alpha 2, Copyright (c) 2003 Jérôme Duval, compiled on " ## __DATE__ ## " " ## __TIME__
62 #define DRIVER_NAME "auvia"
63 #define FRIENDLY_NAME "Auvia"
64 #define FRIENDLY_NAME_686 FRIENDLY_NAME" 82C686"
65 #define FRIENDLY_NAME_8233C FRIENDLY_NAME" 8233C"
66 #define FRIENDLY_NAME_8233 FRIENDLY_NAME" 8233"
67 #define FRIENDLY_NAME_8233A FRIENDLY_NAME" 8233A"
68 #define FRIENDLY_NAME_8235 FRIENDLY_NAME" 8235"
69 #define AUTHOR "Jérôme Duval"
70 
71 #define VIA_TABLE_SIZE	255
72 
73 #define	AUVIA_USE_PLAY		(1 << 0)
74 #define	AUVIA_USE_RECORD	(1 << 1)
75 #define AUVIA_STATE_STARTED	(1 << 0)
76 
77 /*
78  * Auvia memory managment
79  */
80 
81 typedef struct _auvia_mem {
82 	LIST_ENTRY(_auvia_mem) next;
83 	void	*log_base;
84 	void	*phy_base;
85 	area_id area;
86 	size_t	size;
87 } auvia_mem;
88 
89 /*
90  * Streams
91  */
92 
93 typedef struct _auvia_stream {
94 	struct _auvia_dev 	*card;
95 	uint8        		use;
96 	uint8        		state;
97 	uint8        		b16;
98 	uint32       		sample_rate;
99 	uint8				channels;
100 	uint32 				bufframes;
101 	uint8 				bufcount;
102 
103 	uint32				base;
104 
105 	LIST_ENTRY(_auvia_stream)	next;
106 
107 	void            	(*inth) (void *);
108 	void           		*inthparam;
109 
110 	void	*dmaops_log_base;
111 	void	*dmaops_phy_base;
112 	area_id dmaops_area;
113 
114 	auvia_mem *buffer;
115 	uint16       blksize;	/* in samples */
116 	uint16       trigblk;	/* blk on which to trigger inth */
117 	uint16       blkmod;	/* Modulo value to wrap trigblk */
118 
119 	/* multi_audio */
120 	volatile int64	frames_count;	// for play or record
121 	volatile bigtime_t real_time;	// for play or record
122 	volatile int32	buffer_cycle;	// for play or record
123 	int32 first_channel;
124 	bool update_needed;
125 } auvia_stream;
126 
127 /*
128  * Devices
129  */
130 
131 typedef struct _auvia_dev {
132 	char		name[DEVNAME];	/* used for resources */
133 	pci_info	info;
134 	device_config config;
135 
136 	void	*ptb_log_base;
137 	void	*ptb_phy_base;
138 	area_id ptb_area;
139 
140 	sem_id buffer_ready_sem;
141 
142 	uint32			interrupt_mask;
143 
144 	LIST_HEAD(, _auvia_stream) streams;
145 
146 	LIST_HEAD(, _auvia_mem) mems;
147 
148 	auvia_stream	*pstream;
149 	auvia_stream	*rstream;
150 
151 	/* multi_audio */
152 	multi_dev	multi;
153 } auvia_dev;
154 
155 extern int32 num_cards;
156 extern auvia_dev cards[NUM_CARDS];
157 
158 status_t auvia_stream_set_audioparms(auvia_stream *stream, uint8 channels,
159 			     uint8 b16, uint32 sample_rate);
160 status_t auvia_stream_commit_parms(auvia_stream *stream);
161 status_t auvia_stream_get_nth_buffer(auvia_stream *stream, uint8 chan, uint8 buf,
162 					char** buffer, size_t *stride);
163 void auvia_stream_start(auvia_stream *stream, void (*inth) (void *), void *inthparam);
164 void auvia_stream_halt(auvia_stream *stream);
165 auvia_stream *auvia_stream_new(auvia_dev *card, uint8 use, uint32 bufframes, uint8 bufcount);
166 void auvia_stream_delete(auvia_stream *stream);
167 
168 #endif /* _DEV_PCI_AUVIA_H_ */
169