]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> | |
3 | * Routines for control of ICS 2101 chip and "mixer" in GF1 chip | |
4 | * | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
21 | ||
22 | #include <sound/driver.h> | |
23 | #include <linux/time.h> | |
24 | #include <linux/wait.h> | |
25 | #include <sound/core.h> | |
26 | #include <sound/control.h> | |
27 | #include <sound/gus.h> | |
28 | ||
29 | /* | |
30 | * | |
31 | */ | |
32 | ||
33 | #define GF1_SINGLE(xname, xindex, shift, invert) \ | |
34 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | |
35 | .info = snd_gf1_info_single, \ | |
36 | .get = snd_gf1_get_single, .put = snd_gf1_put_single, \ | |
37 | .private_value = shift | (invert << 8) } | |
38 | ||
39 | #define snd_gf1_info_single snd_ctl_boolean_mono_info | |
40 | ||
41 | static int snd_gf1_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
42 | { | |
43 | struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol); | |
44 | int shift = kcontrol->private_value & 0xff; | |
45 | int invert = (kcontrol->private_value >> 8) & 1; | |
46 | ||
47 | ucontrol->value.integer.value[0] = (gus->mix_cntrl_reg >> shift) & 1; | |
48 | if (invert) | |
49 | ucontrol->value.integer.value[0] ^= 1; | |
50 | return 0; | |
51 | } | |
52 | ||
53 | static int snd_gf1_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
54 | { | |
55 | struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol); | |
56 | unsigned long flags; | |
57 | int shift = kcontrol->private_value & 0xff; | |
58 | int invert = (kcontrol->private_value >> 8) & 1; | |
59 | int change; | |
60 | unsigned char oval, nval; | |
61 | ||
62 | nval = ucontrol->value.integer.value[0] & 1; | |
63 | if (invert) | |
64 | nval ^= 1; | |
65 | nval <<= shift; | |
66 | spin_lock_irqsave(&gus->reg_lock, flags); | |
67 | oval = gus->mix_cntrl_reg; | |
68 | nval = (oval & ~(1 << shift)) | nval; | |
69 | change = nval != oval; | |
70 | outb(gus->mix_cntrl_reg = nval, GUSP(gus, MIXCNTRLREG)); | |
71 | outb(gus->gf1.active_voice = 0, GUSP(gus, GF1PAGE)); | |
72 | spin_unlock_irqrestore(&gus->reg_lock, flags); | |
73 | return change; | |
74 | } | |
75 | ||
76 | #define ICS_DOUBLE(xname, xindex, addr) \ | |
77 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | |
78 | .info = snd_ics_info_double, \ | |
79 | .get = snd_ics_get_double, .put = snd_ics_put_double, \ | |
80 | .private_value = addr } | |
81 | ||
82 | static int snd_ics_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | |
83 | { | |
84 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
85 | uinfo->count = 2; | |
86 | uinfo->value.integer.min = 0; | |
87 | uinfo->value.integer.max = 127; | |
88 | return 0; | |
89 | } | |
90 | ||
91 | static int snd_ics_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
92 | { | |
93 | struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol); | |
94 | unsigned long flags; | |
95 | int addr = kcontrol->private_value & 0xff; | |
96 | unsigned char left, right; | |
97 | ||
98 | spin_lock_irqsave(&gus->reg_lock, flags); | |
99 | left = gus->gf1.ics_regs[addr][0]; | |
100 | right = gus->gf1.ics_regs[addr][1]; | |
101 | spin_unlock_irqrestore(&gus->reg_lock, flags); | |
102 | ucontrol->value.integer.value[0] = left & 127; | |
103 | ucontrol->value.integer.value[1] = right & 127; | |
104 | return 0; | |
105 | } | |
106 | ||
107 | static int snd_ics_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
108 | { | |
109 | struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol); | |
110 | unsigned long flags; | |
111 | int addr = kcontrol->private_value & 0xff; | |
112 | int change; | |
113 | unsigned char val1, val2, oval1, oval2, tmp; | |
114 | ||
115 | val1 = ucontrol->value.integer.value[0] & 127; | |
116 | val2 = ucontrol->value.integer.value[1] & 127; | |
117 | spin_lock_irqsave(&gus->reg_lock, flags); | |
118 | oval1 = gus->gf1.ics_regs[addr][0]; | |
119 | oval2 = gus->gf1.ics_regs[addr][1]; | |
120 | change = val1 != oval1 || val2 != oval2; | |
121 | gus->gf1.ics_regs[addr][0] = val1; | |
122 | gus->gf1.ics_regs[addr][1] = val2; | |
123 | if (gus->ics_flag && gus->ics_flipped && | |
124 | (addr == SNDRV_ICS_GF1_DEV || addr == SNDRV_ICS_MASTER_DEV)) { | |
125 | tmp = val1; | |
126 | val1 = val2; | |
127 | val2 = tmp; | |
128 | } | |
129 | addr <<= 3; | |
130 | outb(addr | 0, GUSP(gus, MIXCNTRLPORT)); | |
131 | outb(1, GUSP(gus, MIXDATAPORT)); | |
132 | outb(addr | 2, GUSP(gus, MIXCNTRLPORT)); | |
133 | outb((unsigned char) val1, GUSP(gus, MIXDATAPORT)); | |
134 | outb(addr | 1, GUSP(gus, MIXCNTRLPORT)); | |
135 | outb(2, GUSP(gus, MIXDATAPORT)); | |
136 | outb(addr | 3, GUSP(gus, MIXCNTRLPORT)); | |
137 | outb((unsigned char) val2, GUSP(gus, MIXDATAPORT)); | |
138 | spin_unlock_irqrestore(&gus->reg_lock, flags); | |
139 | return change; | |
140 | } | |
141 | ||
142 | static struct snd_kcontrol_new snd_gf1_controls[] = { | |
143 | GF1_SINGLE("Master Playback Switch", 0, 1, 1), | |
144 | GF1_SINGLE("Line Switch", 0, 0, 1), | |
145 | GF1_SINGLE("Mic Switch", 0, 2, 0) | |
146 | }; | |
147 | ||
148 | static struct snd_kcontrol_new snd_ics_controls[] = { | |
149 | GF1_SINGLE("Master Playback Switch", 0, 1, 1), | |
150 | ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV), | |
151 | ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV), | |
152 | GF1_SINGLE("Line Switch", 0, 0, 1), | |
153 | ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV), | |
154 | GF1_SINGLE("Mic Switch", 0, 2, 0), | |
155 | ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV), | |
156 | ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV) | |
157 | }; | |
158 | ||
159 | int snd_gf1_new_mixer(struct snd_gus_card * gus) | |
160 | { | |
161 | struct snd_card *card; | |
162 | unsigned int idx, max; | |
163 | int err; | |
164 | ||
165 | snd_assert(gus != NULL, return -EINVAL); | |
166 | card = gus->card; | |
167 | snd_assert(card != NULL, return -EINVAL); | |
168 | ||
169 | if (gus->ics_flag) | |
170 | snd_component_add(card, "ICS2101"); | |
171 | if (card->mixername[0] == '\0') { | |
172 | strcpy(card->mixername, gus->ics_flag ? "GF1,ICS2101" : "GF1"); | |
173 | } else { | |
174 | if (gus->ics_flag) | |
175 | strcat(card->mixername, ",ICS2101"); | |
176 | strcat(card->mixername, ",GF1"); | |
177 | } | |
178 | ||
179 | if (!gus->ics_flag) { | |
180 | max = gus->ess_flag ? 1 : ARRAY_SIZE(snd_gf1_controls); | |
181 | for (idx = 0; idx < max; idx++) { | |
182 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_gf1_controls[idx], gus))) < 0) | |
183 | return err; | |
184 | } | |
185 | } else { | |
186 | for (idx = 0; idx < ARRAY_SIZE(snd_ics_controls); idx++) { | |
187 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ics_controls[idx], gus))) < 0) | |
188 | return err; | |
189 | } | |
190 | } | |
191 | return 0; | |
192 | } |