xref: /openbsd/sys/dev/isa/ad1848var.h (revision 274d7c50)
1 /*	$OpenBSD: ad1848var.h,v 1.15 2016/09/14 06:12:19 ratchov Exp $	*/
2 /*	$NetBSD: ad1848var.h,v 1.22 1998/01/19 22:18:26 augustss Exp $	*/
3 
4 /*
5  * Copyright (c) 1994 John Brezak
6  * Copyright (c) 1991-1993 Regents of the University of California.
7  * All rights reserved.
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 Computer Systems
20  *	Engineering Group at Lawrence Berkeley Laboratory.
21  * 4. Neither the name of the University nor of the Laboratory may be used
22  *    to endorse or promote products derived from this software without
23  *    specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  */
38 
39 #define AD1848_NPORT	4
40 #define	AD1848_TIMO	1000000
41 
42 struct ad1848_volume {
43 	u_char	left;
44 	u_char	right;
45 };
46 
47 struct ad1848_softc {
48 	struct	device sc_dev;		/* base device */
49 	struct	isadev sc_id;		/* ISA device */
50 	void	*sc_ih;			/* interrupt vectoring */
51 	bus_space_tag_t sc_iot;		/* tag */
52 	bus_space_handle_t sc_ioh;	/* handle */
53 	int	sc_iooffs;		/* offset from handle */
54 
55 	void	*parent;
56 	struct	device *sc_isa;		/* ISA bus's device */
57 
58 	char	sc_playrun;		/* running in continuous mode */
59 	char	sc_recrun;		/* running in continuous mode */
60 
61 	int	sc_irq;			/* interrupt */
62 	int	sc_drq;			/* DMA */
63 	int	sc_recdrq;		/* record/capture DMA */
64 
65 	int	sc_flags;
66 #define AD1848_FLAG_32REGS	0x01	/* newer chip (cs4231 compatible) */
67 
68 	/* We keep track of these */
69         struct ad1848_volume gains[6];
70 
71 	struct ad1848_volume rec_gain;
72 
73 	int	rec_port;		/* recording port */
74 
75 	/* ad1848 */
76 	u_char	MCE_bit;
77 	char	mic_gain_on;		/* CS4231 only */
78         char    mute[6];
79 
80 	char	*chip_name;
81 	int	mode;
82 
83 	u_int	precision;		/* 8/16 bits */
84 	int	channels;
85 
86 	u_char	speed_bits;
87 	u_char	format_bits;
88 	u_char	need_commit;
89 
90 	void	(*sc_pintr)(void *);	/* play dma completion intr handler */
91 	void	(*sc_rintr)(void *);	/* rec dma completion intr handler */
92 	void	*sc_parg;		/* play arg for sc_intr() */
93 	void	*sc_rarg;		/* rec arg for sc_intr() */
94 
95 	int	sc_iobase;
96 };
97 
98 #define MUTE_LEFT       1
99 #define MUTE_RIGHT      2
100 #define MUTE_ALL        (MUTE_LEFT | MUTE_RIGHT)
101 #define MUTE_MONO       MUTE_ALL
102 
103 /* Don't change this ordering without seriously looking around.
104    These are indexes into mute[] array and into a register information
105    array */
106 #define AD1848_AUX2_CHANNEL        0
107 #define AD1848_AUX1_CHANNEL        1
108 #define AD1848_DAC_CHANNEL         2
109 #define AD1848_LINE_CHANNEL        3
110 #define AD1848_MONO_CHANNEL        4
111 #define AD1848_MONITOR_CHANNEL     5    /* Doesn't seem to be on all later chips */
112 
113 /*
114  * Ad1848 ports
115  */
116 #define MIC_IN_PORT	0
117 #define LINE_IN_PORT	1
118 #define AUX1_IN_PORT	2
119 #define DAC_IN_PORT	3
120 
121 #ifdef _KERNEL
122 
123 #define AD1848_KIND_LVL   0
124 #define AD1848_KIND_MUTE  1
125 #define AD1848_KIND_RECORDGAIN 2
126 #define AD1848_KIND_MICGAIN 3
127 #define AD1848_KIND_RECORDSOURCE 4
128 
129 typedef struct ad1848_devmap {
130   int  id;
131   int  kind;
132   int  dev;
133 } ad1848_devmap_t;
134 
135 static __inline int ad1848_to_vol(mixer_ctrl_t *, struct ad1848_volume *);
136 static __inline int ad1848_from_vol(mixer_ctrl_t *, struct ad1848_volume *);
137 
138 static __inline int
139 ad1848_to_vol(cp, vol)
140 	mixer_ctrl_t *cp;
141 	struct ad1848_volume *vol;
142 {
143 	if (cp->un.value.num_channels == 1) {
144 		vol->left = vol->right = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
145 		return(1);
146 	}
147 	else if (cp->un.value.num_channels == 2) {
148 		vol->left  = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
149 		vol->right = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
150 		return(1);
151 	}
152 	return(0);
153 }
154 
155 static __inline int
156 ad1848_from_vol(cp, vol)
157 	mixer_ctrl_t *cp;
158 	struct ad1848_volume *vol;
159 {
160 	if (cp->un.value.num_channels == 1) {
161 		cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = vol->left;
162 		return(1);
163 	}
164 	else if (cp->un.value.num_channels == 2) {
165 		cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = vol->left;
166 		cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = vol->right;
167 		return(1);
168 	}
169 	return(0);
170 }
171 
172 
173 int     ad1848_mixer_get_port(struct ad1848_softc *, ad1848_devmap_t *, int cnt, mixer_ctrl_t *);
174 int     ad1848_mixer_set_port(struct ad1848_softc *, ad1848_devmap_t *, int, mixer_ctrl_t *);
175 int	ad1848_mapprobe(struct ad1848_softc *, int);
176 int	ad1848_probe(struct ad1848_softc *);
177 void	ad1848_unmap(struct ad1848_softc *);
178 void	ad1848_attach(struct ad1848_softc *);
179 
180 int	ad1848_open(void *, int);
181 void	ad1848_close(void *);
182 
183 void	ad1848_forceintr(struct ad1848_softc *);
184 
185 int	ad1848_set_params(void *, int, int, struct audio_params *, struct audio_params *);
186 
187 int	ad1848_round_blocksize(void *, int);
188 
189 int	ad1848_trigger_input(void *, void *, void *, int, void (*)(void *),
190 	void *, struct audio_params *);
191 int	ad1848_trigger_output(void *, void *, void *, int, void (*)(void *),
192 	void *, struct audio_params *);
193 
194 int	ad1848_commit_settings(void *);
195 
196 int	ad1848_halt_input(void *);
197 int	ad1848_halt_output(void *);
198 
199 int	ad1848_intr(void *);
200 
201 int	ad1848_set_rec_port(struct ad1848_softc *, int);
202 int	ad1848_get_rec_port(struct ad1848_softc *);
203 
204 int	ad1848_set_channel_gain(struct ad1848_softc *, int, struct ad1848_volume *);
205 int	ad1848_get_device_gain(struct ad1848_softc *, int, struct ad1848_volume *);
206 int	ad1848_set_rec_gain(struct ad1848_softc *, struct ad1848_volume *);
207 int	ad1848_get_rec_gain(struct ad1848_softc *, struct ad1848_volume *);
208 /* Note: The mic pre-MUX gain is not a variable gain, it's 20dB or 0dB */
209 int	ad1848_set_mic_gain(struct ad1848_softc *, struct ad1848_volume *);
210 int	ad1848_get_mic_gain(struct ad1848_softc *, struct ad1848_volume *);
211 void     ad1848_mute_channel(struct ad1848_softc *, int device, int mute);
212 
213 void   *ad1848_malloc(void *, int, size_t, int, int);
214 void	ad1848_free(void *, void *, int);
215 size_t	ad1848_round(void *, int, size_t);
216 
217 int	ad1848_get_props(void *);
218 
219 #endif
220