Home | History | Annotate | Line # | Download | only in isa
ymvar.h revision 1.12
      1 /*	$NetBSD: ymvar.h,v 1.12 2009/05/12 09:10:16 cegger Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999-2000, 2002 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by ITOH Yasufumi.
      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 /*
     33  * Copyright (c) 1994 John Brezak
     34  * Copyright (c) 1991-1993 Regents of the University of California.
     35  * All rights reserved.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  * 3. All advertising materials mentioning features or use of this software
     46  *    must display the following acknowledgement:
     47  *	This product includes software developed by the Computer Systems
     48  *	Engineering Group at Lawrence Berkeley Laboratory.
     49  * 4. Neither the name of the University nor of the Laboratory may be used
     50  *    to endorse or promote products derived from this software without
     51  *    specific prior written permission.
     52  *
     53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63  * SUCH DAMAGE.
     64  *
     65  */
     66 
     67 #include <sys/callout.h>
     68 
     69 /*
     70  *  Original code from OpenBSD.
     71  */
     72 
     73 /*
     74  * Mixer devices
     75  */
     76 #define YM_DAC_LVL		0	/* inputs.dac */
     77 #define YM_MIDI_LVL		1	/* inputs.midi */
     78 #define YM_CD_LVL		2	/* inputs.cd */
     79 #define YM_LINE_LVL		3	/* inputs.line */
     80 #define YM_SPEAKER_LVL		4	/* inputs.speaker */
     81 #define YM_MIC_LVL		5	/* inputs.mic */
     82 #define YM_MONITOR_LVL		6	/* monitor.monitor */
     83 #define YM_DAC_MUTE		7	/* inputs.dac.mute */
     84 #define YM_MIDI_MUTE		8	/* inputs.midi.mute */
     85 #define YM_CD_MUTE		9	/* inputs.cd.mute */
     86 #define YM_LINE_MUTE		10	/* inputs.line.mute */
     87 #define YM_SPEAKER_MUTE		11	/* inputs.speaker.mute */
     88 #define YM_MIC_MUTE		12	/* inputs.mic.mute */
     89 #define YM_MONITOR_MUTE		13	/* monitor.monitor.mute */
     90 
     91 #define YM_REC_LVL		14	/* record.record */
     92 #define YM_RECORD_SOURCE	15	/* record.record.source */
     93 
     94 #define YM_OUTPUT_LVL		16	/* outputs.master */
     95 #define YM_OUTPUT_MUTE		17	/* outputs.master.mute */
     96 
     97 #ifndef AUDIO_NO_POWER_CTL
     98 #define YM_PWR_MODE		18	/* power.save */
     99 #define YM_PWR_TIMEOUT		19	/* power.save.timeout */
    100 #endif
    101 
    102 /* Classes - don't change this without looking at mixer_classes array */
    103 #ifdef AUDIO_NO_POWER_CTL
    104 #define YM_CLASS_TOP		18
    105 #else
    106 #define YM_CLASS_TOP		20
    107 #endif
    108 #define YM_INPUT_CLASS		(YM_CLASS_TOP + 0)
    109 #define YM_RECORD_CLASS		(YM_CLASS_TOP + 1)
    110 #define YM_OUTPUT_CLASS		(YM_CLASS_TOP + 2)
    111 #define YM_MONITOR_CLASS	(YM_CLASS_TOP + 3)
    112 #ifdef AUDIO_NO_POWER_CTL
    113 #define YM_EQ_CLASS		(YM_CLASS_TOP + 4)
    114 #else
    115 #define YM_PWR_CLASS		(YM_CLASS_TOP + 4)
    116 #define YM_EQ_CLASS		(YM_CLASS_TOP + 5)
    117 #endif
    118 
    119 /* equalizer is SA3 only */
    120 #define YM_MASTER_EQMODE	(YM_EQ_CLASS+1)	/* equalization.mode */
    121 #define YM_MASTER_TREBLE	(YM_EQ_CLASS+2)	/* equalization.treble */
    122 #define YM_MASTER_BASS		(YM_EQ_CLASS+3)	/* equalization.bass */
    123 #define YM_MASTER_WIDE		(YM_EQ_CLASS+4)	/* equalization.surround */
    124 
    125 #define YM_MIXER_SA3_ONLY(m)	((m) >= YM_EQ_CLASS)
    126 
    127 /* XXX should be in <sys/audioio.h> */
    128 #define AudioNdesktop		"desktop"
    129 #define AudioNlaptop		"laptop"
    130 #define AudioNsubnote		"subnote"
    131 #define AudioNhifi		"hifi"
    132 
    133 #ifndef AUDIO_NO_POWER_CTL
    134 #define AudioCpower		"power"
    135 #define AudioNsave		"save"
    136 #define AudioNtimeout		"timeout"
    137 #define AudioNpowerdown		"powerdown"
    138 #define AudioNpowersave		"powersave"
    139 #define AudioNnosave		"nosave"
    140 #endif
    141 
    142 
    143 struct ym_softc {
    144 	struct	ad1848_isa_softc sc_ad1848;
    145 #define ym_irq		sc_ad1848.sc_irq
    146 #define ym_playdrq	sc_ad1848.sc_playdrq
    147 #define ym_recdrq	sc_ad1848.sc_recdrq
    148 
    149 	bus_space_tag_t sc_iot;		/* tag */
    150 	bus_space_handle_t sc_ioh;	/* handle */
    151 	isa_chipset_tag_t sc_ic;
    152 
    153 	bus_space_handle_t sc_controlioh;
    154 	bus_space_handle_t sc_opl_ioh;
    155 	bus_space_handle_t sc_sb_ioh;	/* only used to disable it */
    156 
    157 	struct callout sc_powerdown_ch;
    158 
    159 	int  master_mute, mic_mute;
    160 	struct ad1848_volume master_gain;
    161 	uint8_t mic_gain;
    162 
    163 	uint8_t sc_external_sources;	/* non-zero value prevents power down */
    164 
    165 	uint8_t sc_version;		/* hardware version */
    166 #define YM_IS_SA3(sc)	((sc)->sc_version > SA3_MISC_VER_711)
    167 
    168 	/* 3D encehamcement */
    169 	uint8_t sc_eqmode;
    170 	struct ad1848_volume sc_treble, sc_bass, sc_wide;
    171 	/*
    172 	 * The equalizer of OPL3-SA3 is ``flat'' if it is turned off.
    173 	 * For compatibility with other drivers, however, make it flat
    174 	 * if it is set at center (or smaller).
    175 	 */
    176 #define YM_EQ_REDUCE_BIT	1	/* use only 128 values from 256 */
    177 #define YM_EQ_FLAT_OFFSET	128	/* center */
    178 #define YM_EQ_EXPAND_VALUE(v)	\
    179     ((v) < YM_EQ_FLAT_OFFSET? 0 : ((v) - YM_EQ_FLAT_OFFSET) << YM_EQ_REDUCE_BIT)
    180 
    181 #define YM_3D_ON_MIN	((AUDIO_MAX_GAIN + 1) / (SA3_3D_BITS + 1))
    182 #define YM_EQ_ON_MIN	((YM_3D_ON_MIN >> YM_EQ_REDUCE_BIT) + YM_EQ_FLAT_OFFSET)
    183 
    184 #define YM_EQ_OFF(v)	((v)->left < YM_EQ_ON_MIN && (v)->right < YM_EQ_ON_MIN)
    185 #define YM_WIDE_OFF(v)	((v)->left < YM_3D_ON_MIN && (v)->right < YM_3D_ON_MIN)
    186 
    187 	device_t sc_audiodev;
    188 
    189 #if NMPU_YM > 0
    190 	bus_space_handle_t sc_mpu_ioh;
    191 	device_t sc_mpudev;
    192 #endif
    193 
    194 #ifndef AUDIO_NO_POWER_CTL
    195 	enum ym_pow_mode {
    196 		YM_POWER_POWERDOWN, YM_POWER_POWERSAVE, YM_POWER_NOSAVE
    197 	} sc_pow_mode;
    198 	int	sc_pow_timeout;
    199 
    200 	uint8_t sc_codec_scan[0x20];
    201 #define YM_SAVE_REG_MAX_SA3	SA3_HVOL_INTR_CNF
    202 #define YM_SAVE_REG_MAX_SA2	SA3_DMA_CNT_REC_HIGH
    203 	uint8_t sc_sa3_scan[YM_SAVE_REG_MAX_SA3 + 1];
    204 
    205 	uint16_t sc_on_blocks;
    206 	uint16_t sc_turning_off;
    207 
    208 	int	sc_in_power_ctl;
    209 #define YM_POWER_CTL_INUSE	1
    210 #define YM_POWER_CTL_WANTED	2
    211 #endif /* not AUDIO_NO_POWER_CTL */
    212 };
    213 
    214 #ifndef AUDIO_NO_POWER_CTL
    215 /* digital */
    216 #define YM_POWER_CODEC_P	SA3_DPWRDWN_WSS_P
    217 #define YM_POWER_CODEC_R	SA3_DPWRDWN_WSS_R
    218 #define YM_POWER_OPL3		SA3_DPWRDWN_FM
    219 #define YM_POWER_MPU401		SA3_DPWRDWN_MPU
    220 #define YM_POWER_JOYSTICK	SA3_DPWRDWN_JOY
    221 /* analog */
    222 #define YM_POWER_3D		(SA3_APWRDWN_WIDE << 8)
    223 #define YM_POWER_CODEC_DA	(SA3_APWRDWN_DA << 8)
    224 #define YM_POWER_CODEC_AD	(SA3_APWRDWN_AD << 8)
    225 #define YM_POWER_OPL3_DA	(SA3_APWRDWN_FMDAC << 8)
    226 /* pseudo */
    227 #define YM_POWER_CODEC_CTL	0x4000
    228 #define YM_POWER_EXT_SRC	0x8000
    229 #define YM_POWER_CODEC_PSEUDO	(YM_POWER_CODEC_CTL | YM_POWER_EXT_SRC)
    230 
    231 #define YM_POWER_CODEC_DIGITAL	\
    232 		(YM_POWER_CODEC_P | YM_POWER_CODEC_R | YM_POWER_CODEC_CTL)
    233 /* 3D enhance is passive */
    234 #define YM_POWER_ACTIVE		(0xffff & ~YM_POWER_3D)
    235 
    236 /* external input sources */
    237 #define YM_XS_CD	1
    238 #define YM_XS_LINE	2
    239 #define YM_XS_SPEAKER	4
    240 #define YM_XS_MIC	8
    241 
    242 #if YM_CD_MUTE + 1 != YM_LINE_MUTE || YM_CD_MUTE + 2 != YM_SPEAKER_MUTE || YM_CD_MUTE + 3 != YM_MIC_MUTE
    243  #error YM_CD_MUTE, YM_LINE_MUTE and YM_SPEAKER_MUTE should be contiguous
    244 #endif
    245 #define YM_MIXER_TO_XS(m)	(1 << ((m) - YM_CD_MUTE))
    246 
    247 #ifdef _KERNEL
    248 void	ym_power_ctl(struct ym_softc *, int, int);
    249 #endif
    250 #endif /* not AUDIO_NO_POWER_CTL */
    251 
    252 #ifdef _KERNEL
    253 void	ym_attach(struct ym_softc *);
    254 #endif
    255