1/*	$OpenBSD: ad1848var.h,v 1.17 2022/10/28 14:55:46 kn 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
42struct ad1848_volume {
43	u_char	left;
44	u_char	right;
45};
46
47struct 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
129typedef struct ad1848_devmap {
130  int  id;
131  int  kind;
132  int  dev;
133} ad1848_devmap_t;
134
135static __inline int ad1848_to_vol(mixer_ctrl_t *, struct ad1848_volume *);
136static __inline int ad1848_from_vol(mixer_ctrl_t *, struct ad1848_volume *);
137
138static __inline int
139ad1848_to_vol(mixer_ctrl_t *cp, struct ad1848_volume *vol)
140{
141	if (cp->un.value.num_channels == 1) {
142		vol->left = vol->right = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
143		return(1);
144	}
145	else if (cp->un.value.num_channels == 2) {
146		vol->left  = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
147		vol->right = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
148		return(1);
149	}
150	return(0);
151}
152
153static __inline int
154ad1848_from_vol(mixer_ctrl_t *cp, struct ad1848_volume *vol)
155{
156	if (cp->un.value.num_channels == 1) {
157		cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = vol->left;
158		return(1);
159	}
160	else if (cp->un.value.num_channels == 2) {
161		cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = vol->left;
162		cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = vol->right;
163		return(1);
164	}
165	return(0);
166}
167
168
169int     ad1848_mixer_get_port(struct ad1848_softc *, ad1848_devmap_t *, int cnt, mixer_ctrl_t *);
170int     ad1848_mixer_set_port(struct ad1848_softc *, ad1848_devmap_t *, int, mixer_ctrl_t *);
171int	ad1848_mapprobe(struct ad1848_softc *, int);
172int	ad1848_probe(struct ad1848_softc *);
173void	ad1848_unmap(struct ad1848_softc *);
174void	ad1848_attach(struct ad1848_softc *);
175
176int	ad1848_open(void *, int);
177void	ad1848_close(void *);
178
179void	ad1848_forceintr(struct ad1848_softc *);
180
181int	ad1848_set_params(void *, int, int, struct audio_params *, struct audio_params *);
182
183int	ad1848_round_blocksize(void *, int);
184
185int	ad1848_trigger_input(void *, void *, void *, int, void (*)(void *),
186	void *, struct audio_params *);
187int	ad1848_trigger_output(void *, void *, void *, int, void (*)(void *),
188	void *, struct audio_params *);
189
190int	ad1848_commit_settings(void *);
191
192int	ad1848_halt_input(void *);
193int	ad1848_halt_output(void *);
194
195int	ad1848_intr(void *);
196
197int	ad1848_set_rec_port(struct ad1848_softc *, int);
198int	ad1848_get_rec_port(struct ad1848_softc *);
199
200int	ad1848_set_channel_gain(struct ad1848_softc *, int, struct ad1848_volume *);
201int	ad1848_get_device_gain(struct ad1848_softc *, int, struct ad1848_volume *);
202int	ad1848_set_rec_gain(struct ad1848_softc *, struct ad1848_volume *);
203int	ad1848_get_rec_gain(struct ad1848_softc *, struct ad1848_volume *);
204/* Note: The mic pre-MUX gain is not a variable gain, it's 20dB or 0dB */
205int	ad1848_set_mic_gain(struct ad1848_softc *, struct ad1848_volume *);
206int	ad1848_get_mic_gain(struct ad1848_softc *, struct ad1848_volume *);
207void     ad1848_mute_channel(struct ad1848_softc *, int device, int mute);
208
209void   *ad1848_malloc(void *, int, size_t, int, int);
210void	ad1848_free(void *, void *, int);
211size_t	ad1848_round(void *, int, size_t);
212
213#endif
214