1 /***************************************************************************
2 msnd_pinnacle_mixer.c - description
5 copyright : (C) 2002 by karsten wiese
6 email : annabellesgarden@yahoo.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
19 #include <linux/export.h>
21 #include <sound/core.h>
22 #include <sound/control.h>
24 #include "msnd_pinnacle.h"
27 #define MSND_MIXER_VOLUME 0
28 #define MSND_MIXER_PCM 1
29 #define MSND_MIXER_AUX 2 /* Input source 1 (aux1) */
30 #define MSND_MIXER_IMIX 3 /* Recording monitor */
31 #define MSND_MIXER_SYNTH 4
32 #define MSND_MIXER_SPEAKER 5
33 #define MSND_MIXER_LINE 6
34 #define MSND_MIXER_MIC 7
35 #define MSND_MIXER_RECLEV 11 /* Recording level */
36 #define MSND_MIXER_IGAIN 12 /* Input gain */
37 #define MSND_MIXER_OGAIN 13 /* Output gain */
38 #define MSND_MIXER_DIGITAL 17 /* Digital (input) 1 */
40 /* Device mask bits */
42 #define MSND_MASK_VOLUME (1 << MSND_MIXER_VOLUME)
43 #define MSND_MASK_SYNTH (1 << MSND_MIXER_SYNTH)
44 #define MSND_MASK_PCM (1 << MSND_MIXER_PCM)
45 #define MSND_MASK_SPEAKER (1 << MSND_MIXER_SPEAKER)
46 #define MSND_MASK_LINE (1 << MSND_MIXER_LINE)
47 #define MSND_MASK_MIC (1 << MSND_MIXER_MIC)
48 #define MSND_MASK_IMIX (1 << MSND_MIXER_IMIX)
49 #define MSND_MASK_RECLEV (1 << MSND_MIXER_RECLEV)
50 #define MSND_MASK_IGAIN (1 << MSND_MIXER_IGAIN)
51 #define MSND_MASK_OGAIN (1 << MSND_MIXER_OGAIN)
52 #define MSND_MASK_AUX (1 << MSND_MIXER_AUX)
53 #define MSND_MASK_DIGITAL (1 << MSND_MIXER_DIGITAL)
55 static int snd_msndmix_info_mux(struct snd_kcontrol
*kcontrol
,
56 struct snd_ctl_elem_info
*uinfo
)
58 static const char * const texts
[3] = {
59 "Analog", "MASS", "SPDIF",
61 struct snd_msnd
*chip
= snd_kcontrol_chip(kcontrol
);
62 unsigned items
= test_bit(F_HAVEDIGITAL
, &chip
->flags
) ? 3 : 2;
64 return snd_ctl_enum_info(uinfo
, 1, items
, texts
);
67 static int snd_msndmix_get_mux(struct snd_kcontrol
*kcontrol
,
68 struct snd_ctl_elem_value
*ucontrol
)
70 struct snd_msnd
*chip
= snd_kcontrol_chip(kcontrol
);
71 /* MSND_MASK_IMIX is the default */
72 ucontrol
->value
.enumerated
.item
[0] = 0;
74 if (chip
->recsrc
& MSND_MASK_SYNTH
) {
75 ucontrol
->value
.enumerated
.item
[0] = 1;
76 } else if ((chip
->recsrc
& MSND_MASK_DIGITAL
) &&
77 test_bit(F_HAVEDIGITAL
, &chip
->flags
)) {
78 ucontrol
->value
.enumerated
.item
[0] = 2;
85 static int snd_msndmix_set_mux(struct snd_msnd
*chip
, int val
)
89 unsigned char msndbyte
;
93 newrecsrc
= MSND_MASK_IMIX
;
94 msndbyte
= HDEXAR_SET_ANA_IN
;
97 newrecsrc
= MSND_MASK_SYNTH
;
98 msndbyte
= HDEXAR_SET_SYNTH_IN
;
101 newrecsrc
= MSND_MASK_DIGITAL
;
102 msndbyte
= HDEXAR_SET_DAT_IN
;
107 change
= newrecsrc
!= chip
->recsrc
;
110 if (!snd_msnd_send_word(chip
, 0, 0, msndbyte
))
111 if (!snd_msnd_send_dsp_cmd(chip
, HDEX_AUX_REQ
)) {
112 chip
->recsrc
= newrecsrc
;
119 static int snd_msndmix_put_mux(struct snd_kcontrol
*kcontrol
,
120 struct snd_ctl_elem_value
*ucontrol
)
122 struct snd_msnd
*msnd
= snd_kcontrol_chip(kcontrol
);
123 return snd_msndmix_set_mux(msnd
, ucontrol
->value
.enumerated
.item
[0]);
127 static int snd_msndmix_volume_info(struct snd_kcontrol
*kcontrol
,
128 struct snd_ctl_elem_info
*uinfo
)
130 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
132 uinfo
->value
.integer
.min
= 0;
133 uinfo
->value
.integer
.max
= 100;
137 static int snd_msndmix_volume_get(struct snd_kcontrol
*kcontrol
,
138 struct snd_ctl_elem_value
*ucontrol
)
140 struct snd_msnd
*msnd
= snd_kcontrol_chip(kcontrol
);
141 int addr
= kcontrol
->private_value
;
144 spin_lock_irqsave(&msnd
->mixer_lock
, flags
);
145 ucontrol
->value
.integer
.value
[0] = msnd
->left_levels
[addr
] * 100;
146 ucontrol
->value
.integer
.value
[0] /= 0xFFFF;
147 ucontrol
->value
.integer
.value
[1] = msnd
->right_levels
[addr
] * 100;
148 ucontrol
->value
.integer
.value
[1] /= 0xFFFF;
149 spin_unlock_irqrestore(&msnd
->mixer_lock
, flags
);
153 #define update_volm(a, b) \
155 writew((dev->left_levels[a] >> 1) * \
156 readw(dev->SMA + SMA_wCurrMastVolLeft) / 0xffff, \
157 dev->SMA + SMA_##b##Left); \
158 writew((dev->right_levels[a] >> 1) * \
159 readw(dev->SMA + SMA_wCurrMastVolRight) / 0xffff, \
160 dev->SMA + SMA_##b##Right); \
163 #define update_potm(d, s, ar) \
165 writeb((dev->left_levels[d] >> 8) * \
166 readw(dev->SMA + SMA_wCurrMastVolLeft) / 0xffff, \
167 dev->SMA + SMA_##s##Left); \
168 writeb((dev->right_levels[d] >> 8) * \
169 readw(dev->SMA + SMA_wCurrMastVolRight) / 0xffff, \
170 dev->SMA + SMA_##s##Right); \
171 if (snd_msnd_send_word(dev, 0, 0, ar) == 0) \
172 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ); \
175 #define update_pot(d, s, ar) \
177 writeb(dev->left_levels[d] >> 8, \
178 dev->SMA + SMA_##s##Left); \
179 writeb(dev->right_levels[d] >> 8, \
180 dev->SMA + SMA_##s##Right); \
181 if (snd_msnd_send_word(dev, 0, 0, ar) == 0) \
182 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ); \
186 static int snd_msndmix_set(struct snd_msnd
*dev
, int d
, int left
, int right
)
190 int updatemaster
= 0;
192 if (d
>= LEVEL_ENTRIES
)
195 bLeft
= left
* 0xff / 100;
196 wLeft
= left
* 0xffff / 100;
198 bRight
= right
* 0xff / 100;
199 wRight
= right
* 0xffff / 100;
201 dev
->left_levels
[d
] = wLeft
;
202 dev
->right_levels
[d
] = wRight
;
205 /* master volume unscaled controls */
206 case MSND_MIXER_LINE
: /* line pot control */
207 /* scaled by IMIX in digital mix */
208 writeb(bLeft
, dev
->SMA
+ SMA_bInPotPosLeft
);
209 writeb(bRight
, dev
->SMA
+ SMA_bInPotPosRight
);
210 if (snd_msnd_send_word(dev
, 0, 0, HDEXAR_IN_SET_POTS
) == 0)
211 snd_msnd_send_dsp_cmd(dev
, HDEX_AUX_REQ
);
213 case MSND_MIXER_MIC
: /* mic pot control */
214 if (dev
->type
== msndClassic
)
216 /* scaled by IMIX in digital mix */
217 writeb(bLeft
, dev
->SMA
+ SMA_bMicPotPosLeft
);
218 writeb(bRight
, dev
->SMA
+ SMA_bMicPotPosRight
);
219 if (snd_msnd_send_word(dev
, 0, 0, HDEXAR_MIC_SET_POTS
) == 0)
220 snd_msnd_send_dsp_cmd(dev
, HDEX_AUX_REQ
);
222 case MSND_MIXER_VOLUME
: /* master volume */
223 writew(wLeft
, dev
->SMA
+ SMA_wCurrMastVolLeft
);
224 writew(wRight
, dev
->SMA
+ SMA_wCurrMastVolRight
);
227 case MSND_MIXER_AUX
: /* aux pot control */
228 /* scaled by master volume */
231 /* digital controls */
232 case MSND_MIXER_SYNTH
: /* synth vol (dsp mix) */
233 case MSND_MIXER_PCM
: /* pcm vol (dsp mix) */
234 case MSND_MIXER_IMIX
: /* input monitor (dsp mix) */
235 /* scaled by master volume */
244 /* update master volume scaled controls */
245 update_volm(MSND_MIXER_PCM
, wCurrPlayVol
);
246 update_volm(MSND_MIXER_IMIX
, wCurrInVol
);
247 if (dev
->type
== msndPinnacle
)
248 update_volm(MSND_MIXER_SYNTH
, wCurrMHdrVol
);
249 update_potm(MSND_MIXER_AUX
, bAuxPotPos
, HDEXAR_AUX_SET_POTS
);
255 static int snd_msndmix_volume_put(struct snd_kcontrol
*kcontrol
,
256 struct snd_ctl_elem_value
*ucontrol
)
258 struct snd_msnd
*msnd
= snd_kcontrol_chip(kcontrol
);
259 int change
, addr
= kcontrol
->private_value
;
263 left
= ucontrol
->value
.integer
.value
[0] % 101;
264 right
= ucontrol
->value
.integer
.value
[1] % 101;
265 spin_lock_irqsave(&msnd
->mixer_lock
, flags
);
266 change
= msnd
->left_levels
[addr
] != left
267 || msnd
->right_levels
[addr
] != right
;
268 snd_msndmix_set(msnd
, addr
, left
, right
);
269 spin_unlock_irqrestore(&msnd
->mixer_lock
, flags
);
274 #define DUMMY_VOLUME(xname, xindex, addr) \
275 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
276 .info = snd_msndmix_volume_info, \
277 .get = snd_msndmix_volume_get, .put = snd_msndmix_volume_put, \
278 .private_value = addr }
281 static struct snd_kcontrol_new snd_msnd_controls
[] = {
282 DUMMY_VOLUME("Master Volume", 0, MSND_MIXER_VOLUME
),
283 DUMMY_VOLUME("PCM Volume", 0, MSND_MIXER_PCM
),
284 DUMMY_VOLUME("Aux Volume", 0, MSND_MIXER_AUX
),
285 DUMMY_VOLUME("Line Volume", 0, MSND_MIXER_LINE
),
286 DUMMY_VOLUME("Mic Volume", 0, MSND_MIXER_MIC
),
287 DUMMY_VOLUME("Monitor", 0, MSND_MIXER_IMIX
),
289 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
290 .name
= "Capture Source",
291 .info
= snd_msndmix_info_mux
,
292 .get
= snd_msndmix_get_mux
,
293 .put
= snd_msndmix_put_mux
,
298 int snd_msndmix_new(struct snd_card
*card
)
300 struct snd_msnd
*chip
= card
->private_data
;
304 if (snd_BUG_ON(!chip
))
306 spin_lock_init(&chip
->mixer_lock
);
307 strcpy(card
->mixername
, "MSND Pinnacle Mixer");
309 for (idx
= 0; idx
< ARRAY_SIZE(snd_msnd_controls
); idx
++) {
310 err
= snd_ctl_add(card
,
311 snd_ctl_new1(snd_msnd_controls
+ idx
, chip
));
318 EXPORT_SYMBOL(snd_msndmix_new
);
320 void snd_msndmix_setup(struct snd_msnd
*dev
)
322 update_pot(MSND_MIXER_LINE
, bInPotPos
, HDEXAR_IN_SET_POTS
);
323 update_potm(MSND_MIXER_AUX
, bAuxPotPos
, HDEXAR_AUX_SET_POTS
);
324 update_volm(MSND_MIXER_PCM
, wCurrPlayVol
);
325 update_volm(MSND_MIXER_IMIX
, wCurrInVol
);
326 if (dev
->type
== msndPinnacle
) {
327 update_pot(MSND_MIXER_MIC
, bMicPotPos
, HDEXAR_MIC_SET_POTS
);
328 update_volm(MSND_MIXER_SYNTH
, wCurrMHdrVol
);
331 EXPORT_SYMBOL(snd_msndmix_setup
);
333 int snd_msndmix_force_recsrc(struct snd_msnd
*dev
, int recsrc
)
336 return snd_msndmix_set_mux(dev
, recsrc
);
338 EXPORT_SYMBOL(snd_msndmix_force_recsrc
);