2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Routines for control of ICS 2101 chip and "mixer" in GF1 chip
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.
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.
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
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>
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) }
39 static int snd_gf1_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
41 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
43 uinfo->value.integer.min = 0;
44 uinfo->value.integer.max = 1;
48 static int snd_gf1_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
50 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
51 int shift = kcontrol->private_value & 0xff;
52 int invert = (kcontrol->private_value >> 8) & 1;
54 ucontrol->value.integer.value[0] = (gus->mix_cntrl_reg >> shift) & 1;
56 ucontrol->value.integer.value[0] ^= 1;
60 static int snd_gf1_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
62 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
64 int shift = kcontrol->private_value & 0xff;
65 int invert = (kcontrol->private_value >> 8) & 1;
67 unsigned char oval, nval;
69 nval = ucontrol->value.integer.value[0] & 1;
73 spin_lock_irqsave(&gus->reg_lock, flags);
74 oval = gus->mix_cntrl_reg;
75 nval = (oval & ~(1 << shift)) | nval;
76 change = nval != oval;
77 outb(gus->mix_cntrl_reg = nval, GUSP(gus, MIXCNTRLREG));
78 outb(gus->gf1.active_voice = 0, GUSP(gus, GF1PAGE));
79 spin_unlock_irqrestore(&gus->reg_lock, flags);
83 #define ICS_DOUBLE(xname, xindex, addr) \
84 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
85 .info = snd_ics_info_double, \
86 .get = snd_ics_get_double, .put = snd_ics_put_double, \
87 .private_value = addr }
89 static int snd_ics_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
91 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
93 uinfo->value.integer.min = 0;
94 uinfo->value.integer.max = 127;
98 static int snd_ics_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
100 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
102 int addr = kcontrol->private_value & 0xff;
103 unsigned char left, right;
105 spin_lock_irqsave(&gus->reg_lock, flags);
106 left = gus->gf1.ics_regs[addr][0];
107 right = gus->gf1.ics_regs[addr][1];
108 spin_unlock_irqrestore(&gus->reg_lock, flags);
109 ucontrol->value.integer.value[0] = left & 127;
110 ucontrol->value.integer.value[1] = right & 127;
114 static int snd_ics_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
116 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
118 int addr = kcontrol->private_value & 0xff;
120 unsigned char val1, val2, oval1, oval2, tmp;
122 val1 = ucontrol->value.integer.value[0] & 127;
123 val2 = ucontrol->value.integer.value[1] & 127;
124 spin_lock_irqsave(&gus->reg_lock, flags);
125 oval1 = gus->gf1.ics_regs[addr][0];
126 oval2 = gus->gf1.ics_regs[addr][1];
127 change = val1 != oval1 || val2 != oval2;
128 gus->gf1.ics_regs[addr][0] = val1;
129 gus->gf1.ics_regs[addr][1] = val2;
130 if (gus->ics_flag && gus->ics_flipped &&
131 (addr == SNDRV_ICS_GF1_DEV || addr == SNDRV_ICS_MASTER_DEV)) {
137 outb(addr | 0, GUSP(gus, MIXCNTRLPORT));
138 outb(1, GUSP(gus, MIXDATAPORT));
139 outb(addr | 2, GUSP(gus, MIXCNTRLPORT));
140 outb((unsigned char) val1, GUSP(gus, MIXDATAPORT));
141 outb(addr | 1, GUSP(gus, MIXCNTRLPORT));
142 outb(2, GUSP(gus, MIXDATAPORT));
143 outb(addr | 3, GUSP(gus, MIXCNTRLPORT));
144 outb((unsigned char) val2, GUSP(gus, MIXDATAPORT));
145 spin_unlock_irqrestore(&gus->reg_lock, flags);
149 static struct snd_kcontrol_new snd_gf1_controls[] = {
150 GF1_SINGLE("Master Playback Switch", 0, 1, 1),
151 GF1_SINGLE("Line Switch", 0, 0, 1),
152 GF1_SINGLE("Mic Switch", 0, 2, 0)
155 static struct snd_kcontrol_new snd_ics_controls[] = {
156 GF1_SINGLE("Master Playback Switch", 0, 1, 1),
157 ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV),
158 ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV),
159 GF1_SINGLE("Line Switch", 0, 0, 1),
160 ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV),
161 GF1_SINGLE("Mic Switch", 0, 2, 0),
162 ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV),
163 ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV)
166 int snd_gf1_new_mixer(struct snd_gus_card * gus)
168 struct snd_card *card;
169 unsigned int idx, max;
172 snd_assert(gus != NULL, return -EINVAL);
174 snd_assert(card != NULL, return -EINVAL);
177 snd_component_add(card, "ICS2101");
178 if (card->mixername[0] == '\0') {
179 strcpy(card->mixername, gus->ics_flag ? "GF1,ICS2101" : "GF1");
182 strcat(card->mixername, ",ICS2101");
183 strcat(card->mixername, ",GF1");
186 if (!gus->ics_flag) {
187 max = gus->ess_flag ? 1 : ARRAY_SIZE(snd_gf1_controls);
188 for (idx = 0; idx < max; idx++) {
189 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_gf1_controls[idx], gus))) < 0)
193 for (idx = 0; idx < ARRAY_SIZE(snd_ics_controls); idx++) {
194 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ics_controls[idx], gus))) < 0)