Prefetch inodes in readdir
[pohmelfs.git] / sound / isa / msnd / msnd_pinnacle_mixer.c
blob1de59d4414260a6c6a20b9454c112eb99d0f08e4
1 /***************************************************************************
2 msnd_pinnacle_mixer.c - description
3 -------------------
4 begin : Fre Jun 7 2002
5 copyright : (C) 2002 by karsten wiese
6 email : annabellesgarden@yahoo.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
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. *
15 * *
16 ***************************************************************************/
18 #include <linux/io.h>
19 #include <linux/export.h>
21 #include <sound/core.h>
22 #include <sound/control.h>
23 #include "msnd.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 char *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 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
65 uinfo->count = 1;
66 uinfo->value.enumerated.items = items;
67 if (uinfo->value.enumerated.item >= items)
68 uinfo->value.enumerated.item = items - 1;
69 strcpy(uinfo->value.enumerated.name,
70 texts[uinfo->value.enumerated.item]);
71 return 0;
74 static int snd_msndmix_get_mux(struct snd_kcontrol *kcontrol,
75 struct snd_ctl_elem_value *ucontrol)
77 struct snd_msnd *chip = snd_kcontrol_chip(kcontrol);
78 /* MSND_MASK_IMIX is the default */
79 ucontrol->value.enumerated.item[0] = 0;
81 if (chip->recsrc & MSND_MASK_SYNTH) {
82 ucontrol->value.enumerated.item[0] = 1;
83 } else if ((chip->recsrc & MSND_MASK_DIGITAL) &&
84 test_bit(F_HAVEDIGITAL, &chip->flags)) {
85 ucontrol->value.enumerated.item[0] = 2;
89 return 0;
92 static int snd_msndmix_set_mux(struct snd_msnd *chip, int val)
94 unsigned newrecsrc;
95 int change;
96 unsigned char msndbyte;
98 switch (val) {
99 case 0:
100 newrecsrc = MSND_MASK_IMIX;
101 msndbyte = HDEXAR_SET_ANA_IN;
102 break;
103 case 1:
104 newrecsrc = MSND_MASK_SYNTH;
105 msndbyte = HDEXAR_SET_SYNTH_IN;
106 break;
107 case 2:
108 newrecsrc = MSND_MASK_DIGITAL;
109 msndbyte = HDEXAR_SET_DAT_IN;
110 break;
111 default:
112 return -EINVAL;
114 change = newrecsrc != chip->recsrc;
115 if (change) {
116 change = 0;
117 if (!snd_msnd_send_word(chip, 0, 0, msndbyte))
118 if (!snd_msnd_send_dsp_cmd(chip, HDEX_AUX_REQ)) {
119 chip->recsrc = newrecsrc;
120 change = 1;
123 return change;
126 static int snd_msndmix_put_mux(struct snd_kcontrol *kcontrol,
127 struct snd_ctl_elem_value *ucontrol)
129 struct snd_msnd *msnd = snd_kcontrol_chip(kcontrol);
130 return snd_msndmix_set_mux(msnd, ucontrol->value.enumerated.item[0]);
134 static int snd_msndmix_volume_info(struct snd_kcontrol *kcontrol,
135 struct snd_ctl_elem_info *uinfo)
137 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
138 uinfo->count = 2;
139 uinfo->value.integer.min = 0;
140 uinfo->value.integer.max = 100;
141 return 0;
144 static int snd_msndmix_volume_get(struct snd_kcontrol *kcontrol,
145 struct snd_ctl_elem_value *ucontrol)
147 struct snd_msnd *msnd = snd_kcontrol_chip(kcontrol);
148 int addr = kcontrol->private_value;
149 unsigned long flags;
151 spin_lock_irqsave(&msnd->mixer_lock, flags);
152 ucontrol->value.integer.value[0] = msnd->left_levels[addr] * 100;
153 ucontrol->value.integer.value[0] /= 0xFFFF;
154 ucontrol->value.integer.value[1] = msnd->right_levels[addr] * 100;
155 ucontrol->value.integer.value[1] /= 0xFFFF;
156 spin_unlock_irqrestore(&msnd->mixer_lock, flags);
157 return 0;
160 #define update_volm(a, b) \
161 do { \
162 writew((dev->left_levels[a] >> 1) * \
163 readw(dev->SMA + SMA_wCurrMastVolLeft) / 0xffff, \
164 dev->SMA + SMA_##b##Left); \
165 writew((dev->right_levels[a] >> 1) * \
166 readw(dev->SMA + SMA_wCurrMastVolRight) / 0xffff, \
167 dev->SMA + SMA_##b##Right); \
168 } while (0);
170 #define update_potm(d, s, ar) \
171 do { \
172 writeb((dev->left_levels[d] >> 8) * \
173 readw(dev->SMA + SMA_wCurrMastVolLeft) / 0xffff, \
174 dev->SMA + SMA_##s##Left); \
175 writeb((dev->right_levels[d] >> 8) * \
176 readw(dev->SMA + SMA_wCurrMastVolRight) / 0xffff, \
177 dev->SMA + SMA_##s##Right); \
178 if (snd_msnd_send_word(dev, 0, 0, ar) == 0) \
179 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ); \
180 } while (0);
182 #define update_pot(d, s, ar) \
183 do { \
184 writeb(dev->left_levels[d] >> 8, \
185 dev->SMA + SMA_##s##Left); \
186 writeb(dev->right_levels[d] >> 8, \
187 dev->SMA + SMA_##s##Right); \
188 if (snd_msnd_send_word(dev, 0, 0, ar) == 0) \
189 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ); \
190 } while (0);
193 static int snd_msndmix_set(struct snd_msnd *dev, int d, int left, int right)
195 int bLeft, bRight;
196 int wLeft, wRight;
197 int updatemaster = 0;
199 if (d >= LEVEL_ENTRIES)
200 return -EINVAL;
202 bLeft = left * 0xff / 100;
203 wLeft = left * 0xffff / 100;
205 bRight = right * 0xff / 100;
206 wRight = right * 0xffff / 100;
208 dev->left_levels[d] = wLeft;
209 dev->right_levels[d] = wRight;
211 switch (d) {
212 /* master volume unscaled controls */
213 case MSND_MIXER_LINE: /* line pot control */
214 /* scaled by IMIX in digital mix */
215 writeb(bLeft, dev->SMA + SMA_bInPotPosLeft);
216 writeb(bRight, dev->SMA + SMA_bInPotPosRight);
217 if (snd_msnd_send_word(dev, 0, 0, HDEXAR_IN_SET_POTS) == 0)
218 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ);
219 break;
220 case MSND_MIXER_MIC: /* mic pot control */
221 if (dev->type == msndClassic)
222 return -EINVAL;
223 /* scaled by IMIX in digital mix */
224 writeb(bLeft, dev->SMA + SMA_bMicPotPosLeft);
225 writeb(bRight, dev->SMA + SMA_bMicPotPosRight);
226 if (snd_msnd_send_word(dev, 0, 0, HDEXAR_MIC_SET_POTS) == 0)
227 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ);
228 break;
229 case MSND_MIXER_VOLUME: /* master volume */
230 writew(wLeft, dev->SMA + SMA_wCurrMastVolLeft);
231 writew(wRight, dev->SMA + SMA_wCurrMastVolRight);
232 /* fall through */
234 case MSND_MIXER_AUX: /* aux pot control */
235 /* scaled by master volume */
236 /* fall through */
238 /* digital controls */
239 case MSND_MIXER_SYNTH: /* synth vol (dsp mix) */
240 case MSND_MIXER_PCM: /* pcm vol (dsp mix) */
241 case MSND_MIXER_IMIX: /* input monitor (dsp mix) */
242 /* scaled by master volume */
243 updatemaster = 1;
244 break;
246 default:
247 return -EINVAL;
250 if (updatemaster) {
251 /* update master volume scaled controls */
252 update_volm(MSND_MIXER_PCM, wCurrPlayVol);
253 update_volm(MSND_MIXER_IMIX, wCurrInVol);
254 if (dev->type == msndPinnacle)
255 update_volm(MSND_MIXER_SYNTH, wCurrMHdrVol);
256 update_potm(MSND_MIXER_AUX, bAuxPotPos, HDEXAR_AUX_SET_POTS);
259 return 0;
262 static int snd_msndmix_volume_put(struct snd_kcontrol *kcontrol,
263 struct snd_ctl_elem_value *ucontrol)
265 struct snd_msnd *msnd = snd_kcontrol_chip(kcontrol);
266 int change, addr = kcontrol->private_value;
267 int left, right;
268 unsigned long flags;
270 left = ucontrol->value.integer.value[0] % 101;
271 right = ucontrol->value.integer.value[1] % 101;
272 spin_lock_irqsave(&msnd->mixer_lock, flags);
273 change = msnd->left_levels[addr] != left
274 || msnd->right_levels[addr] != right;
275 snd_msndmix_set(msnd, addr, left, right);
276 spin_unlock_irqrestore(&msnd->mixer_lock, flags);
277 return change;
281 #define DUMMY_VOLUME(xname, xindex, addr) \
282 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
283 .info = snd_msndmix_volume_info, \
284 .get = snd_msndmix_volume_get, .put = snd_msndmix_volume_put, \
285 .private_value = addr }
288 static struct snd_kcontrol_new snd_msnd_controls[] = {
289 DUMMY_VOLUME("Master Volume", 0, MSND_MIXER_VOLUME),
290 DUMMY_VOLUME("PCM Volume", 0, MSND_MIXER_PCM),
291 DUMMY_VOLUME("Aux Volume", 0, MSND_MIXER_AUX),
292 DUMMY_VOLUME("Line Volume", 0, MSND_MIXER_LINE),
293 DUMMY_VOLUME("Mic Volume", 0, MSND_MIXER_MIC),
294 DUMMY_VOLUME("Monitor", 0, MSND_MIXER_IMIX),
296 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
297 .name = "Capture Source",
298 .info = snd_msndmix_info_mux,
299 .get = snd_msndmix_get_mux,
300 .put = snd_msndmix_put_mux,
305 int __devinit snd_msndmix_new(struct snd_card *card)
307 struct snd_msnd *chip = card->private_data;
308 unsigned int idx;
309 int err;
311 if (snd_BUG_ON(!chip))
312 return -EINVAL;
313 spin_lock_init(&chip->mixer_lock);
314 strcpy(card->mixername, "MSND Pinnacle Mixer");
316 for (idx = 0; idx < ARRAY_SIZE(snd_msnd_controls); idx++)
317 err = snd_ctl_add(card,
318 snd_ctl_new1(snd_msnd_controls + idx, chip));
319 if (err < 0)
320 return err;
322 return 0;
324 EXPORT_SYMBOL(snd_msndmix_new);
326 void snd_msndmix_setup(struct snd_msnd *dev)
328 update_pot(MSND_MIXER_LINE, bInPotPos, HDEXAR_IN_SET_POTS);
329 update_potm(MSND_MIXER_AUX, bAuxPotPos, HDEXAR_AUX_SET_POTS);
330 update_volm(MSND_MIXER_PCM, wCurrPlayVol);
331 update_volm(MSND_MIXER_IMIX, wCurrInVol);
332 if (dev->type == msndPinnacle) {
333 update_pot(MSND_MIXER_MIC, bMicPotPos, HDEXAR_MIC_SET_POTS);
334 update_volm(MSND_MIXER_SYNTH, wCurrMHdrVol);
337 EXPORT_SYMBOL(snd_msndmix_setup);
339 int snd_msndmix_force_recsrc(struct snd_msnd *dev, int recsrc)
341 dev->recsrc = -1;
342 return snd_msndmix_set_mux(dev, recsrc);
344 EXPORT_SYMBOL(snd_msndmix_force_recsrc);