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