xref: /netbsd/sys/dev/ic/ad1848var.h (revision 33cb8414)
1 /*	$NetBSD: ad1848var.h,v 1.20 2020/02/29 05:51:11 isaki Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999, 2008 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Ken Hornstein and John Kohl.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*
32  * Copyright (c) 1994 John Brezak
33  * Copyright (c) 1991-1993 Regents of the University of California.
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. All advertising materials mentioning features or use of this software
45  *    must display the following acknowledgement:
46  *	This product includes software developed by the Computer Systems
47  *	Engineering Group at Lawrence Berkeley Laboratory.
48  * 4. Neither the name of the University nor of the Laboratory may be used
49  *    to endorse or promote products derived from this software without
50  *    specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62  * SUCH DAMAGE.
63  *
64  */
65 
66 
67 #define MUTE_LEFT       1
68 #define MUTE_RIGHT      2
69 #define MUTE_ALL	(MUTE_LEFT | MUTE_RIGHT)
70 #define MUTE_MONO       MUTE_ALL
71 
72 #define WAVE_MUTE0	1		/* force mute (overrides UNMUTE1) */
73 #define WAVE_UNMUTE1	2		/* unmute (overrides MUTE2) */
74 #define WAVE_MUTE2	4		/* weak mute */
75 #define WAVE_MUTE2_INIT	0		/* init and MUTE2 */
76 
77 /*
78  * Don't change this ordering without seriously looking around.
79  * These are indexes into mute[] array and into a register
80  * information array.
81  */
82 #define AD1848_AUX2_CHANNEL	0
83 #define AD1848_AUX1_CHANNEL	1
84 #define AD1848_DAC_CHANNEL	2
85 #define AD1848_LINE_CHANNEL	3
86 #define AD1848_MONO_CHANNEL	4
87 #define AD1848_OUT_CHANNEL	5
88 #define AD1848_MONITOR_CHANNEL	6 /* Doesn't seem to be on all later chips */
89 
90 #define	AD1848_NUM_CHANNELS	7
91 
92 struct ad1848_volume {
93 	u_char	left;
94 	u_char	right;
95 };
96 
97 struct ad1848_softc {
98 	device_t sc_dev;		/* base device */
99 	kmutex_t sc_lock;
100 	kmutex_t sc_intr_lock;
101 	bus_space_tag_t sc_iot;		/* tag */
102 	bus_space_handle_t sc_ioh;	/* handle */
103 
104 	int	(*sc_readreg)(struct ad1848_softc *, int);
105 	void	(*sc_writereg)(struct ad1848_softc *, int, int);
106 #define ADREAD(sc, index)		(*(sc)->sc_readreg)(sc, index)
107 #define ADWRITE(sc, index, data)	(*(sc)->sc_writereg)(sc, index, data)
108 
109 	void	*parent;
110 
111 	/* We keep track of these */
112 	struct ad1848_volume gains[AD1848_NUM_CHANNELS];
113 	struct ad1848_volume rec_gain;
114 
115 	int	rec_port;		/* recording port */
116 
117 	/* ad1848 */
118 	u_char	MCE_bit;
119 	char	mic_gain_on;		/* CS4231 only */
120 	char    mute[AD1848_NUM_CHANNELS];
121 
122 	const char	*chip_name;
123 	int	mode;
124 	int	is_ad1845;
125 
126 	u_int	precision;		/* 8/16 bits */
127 	int	channels;
128 
129 	u_char	speed_bits;
130 	u_char	format_bits;
131 	u_char	need_commit;
132 
133 	u_char	wave_mute_status;
134 	int	open_mode;
135 };
136 
137 /*
138  * Ad1848 registers.
139  */
140 #define MIC_IN_PORT	0
141 #define LINE_IN_PORT	1
142 #define AUX1_IN_PORT	2
143 #define DAC_IN_PORT	3
144 
145 #define AD1848_KIND_LVL		0
146 #define AD1848_KIND_MUTE	1
147 #define AD1848_KIND_RECORDGAIN	2
148 #define AD1848_KIND_MICGAIN	3
149 #define AD1848_KIND_RECORDSOURCE 4
150 
151 typedef struct ad1848_devmap {
152 	int  id;
153 	int  kind;
154 	int  dev;
155 } ad1848_devmap_t;
156 
157 #ifdef _KERNEL
158 
159 int	ad_read(struct ad1848_softc *, int);
160 int	ad_xread(struct ad1848_softc *, int);
161 void	ad_write(struct ad1848_softc *, int, int);
162 void	ad_xwrite(struct ad1848_softc *, int, int);
163 
164 void	ad1848_attach(struct ad1848_softc *);
165 void	ad1848_reset(struct ad1848_softc *);
166 int	ad1848_open(void *, int);
167 void	ad1848_close(void *);
168 
169 int	ad1848_mixer_get_port(struct ad1848_softc *, const ad1848_devmap_t *,
170 	    int, mixer_ctrl_t *);
171 int	ad1848_mixer_set_port(struct ad1848_softc *, const ad1848_devmap_t *,
172 	    int, mixer_ctrl_t *);
173 int	ad1848_set_speed(struct ad1848_softc *, u_int *);
174 void	ad1848_mute_wave_output(struct ad1848_softc *, int, int);
175 int	ad1848_query_format(void *, audio_format_query_t *);
176 int	ad1848_set_format(void *, int,
177 	    const audio_params_t *, const audio_params_t *,
178 	    audio_filter_reg_t *, audio_filter_reg_t *);
179 int	ad1848_commit_settings(void *);
180 int	ad1848_set_rec_port(struct ad1848_softc *, int);
181 int	ad1848_get_rec_port(struct ad1848_softc *);
182 int	ad1848_set_channel_gain(struct ad1848_softc *, int,
183 	    struct ad1848_volume *);
184 int	ad1848_get_device_gain(struct ad1848_softc *, int,
185 	    struct ad1848_volume *);
186 int	ad1848_set_rec_gain(struct ad1848_softc *, struct ad1848_volume *);
187 int	ad1848_get_rec_gain(struct ad1848_softc *, struct ad1848_volume *);
188 /* Note: The mic pre-MUX gain is not a variable gain, it's 20dB or 0dB */
189 int	ad1848_set_mic_gain(struct ad1848_softc *, struct ad1848_volume *);
190 int	ad1848_get_mic_gain(struct ad1848_softc *, struct ad1848_volume *);
191 void	ad1848_mute_channel(struct ad1848_softc *, int, int);
192 int	ad1848_to_vol(mixer_ctrl_t *, struct ad1848_volume *);
193 int	ad1848_from_vol(mixer_ctrl_t *, struct ad1848_volume *);
194 void	ad1848_init_locks(struct ad1848_softc *, int);
195 void	ad1848_destroy_locks(struct ad1848_softc *);
196 
197 int	ad1848_halt_output(void *);
198 int	ad1848_halt_input(void *);
199 void	ad1848_get_locks(void *, kmutex_t **, kmutex_t **);
200 
201 #ifdef AUDIO_DEBUG
202 void	ad1848_dump_regs(struct ad1848_softc *);
203 #endif
204 
205 #endif
206