2 * Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/time.h>
23 #include <linux/wait.h>
24 #include <sound/core.h>
25 #include <sound/control.h>
26 #include <sound/gus.h>
32 #define GF1_SINGLE(xname, xindex, shift, invert) \
33 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
34 .info = snd_gf1_info_single, \
35 .get = snd_gf1_get_single, .put = snd_gf1_put_single, \
36 .private_value = shift | (invert << 8) }
38 #define snd_gf1_info_single snd_ctl_boolean_mono_info
40 static int snd_gf1_get_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
42 struct snd_gus_card
*gus
= snd_kcontrol_chip(kcontrol
);
43 int shift
= kcontrol
->private_value
& 0xff;
44 int invert
= (kcontrol
->private_value
>> 8) & 1;
46 ucontrol
->value
.integer
.value
[0] = (gus
->mix_cntrl_reg
>> shift
) & 1;
48 ucontrol
->value
.integer
.value
[0] ^= 1;
52 static int snd_gf1_put_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
54 struct snd_gus_card
*gus
= snd_kcontrol_chip(kcontrol
);
56 int shift
= kcontrol
->private_value
& 0xff;
57 int invert
= (kcontrol
->private_value
>> 8) & 1;
59 unsigned char oval
, nval
;
61 nval
= ucontrol
->value
.integer
.value
[0] & 1;
65 spin_lock_irqsave(&gus
->reg_lock
, flags
);
66 oval
= gus
->mix_cntrl_reg
;
67 nval
= (oval
& ~(1 << shift
)) | nval
;
68 change
= nval
!= oval
;
69 outb(gus
->mix_cntrl_reg
= nval
, GUSP(gus
, MIXCNTRLREG
));
70 outb(gus
->gf1
.active_voice
= 0, GUSP(gus
, GF1PAGE
));
71 spin_unlock_irqrestore(&gus
->reg_lock
, flags
);
75 #define ICS_DOUBLE(xname, xindex, addr) \
76 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
77 .info = snd_ics_info_double, \
78 .get = snd_ics_get_double, .put = snd_ics_put_double, \
79 .private_value = addr }
81 static int snd_ics_info_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
83 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
85 uinfo
->value
.integer
.min
= 0;
86 uinfo
->value
.integer
.max
= 127;
90 static int snd_ics_get_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
92 struct snd_gus_card
*gus
= snd_kcontrol_chip(kcontrol
);
94 int addr
= kcontrol
->private_value
& 0xff;
95 unsigned char left
, right
;
97 spin_lock_irqsave(&gus
->reg_lock
, flags
);
98 left
= gus
->gf1
.ics_regs
[addr
][0];
99 right
= gus
->gf1
.ics_regs
[addr
][1];
100 spin_unlock_irqrestore(&gus
->reg_lock
, flags
);
101 ucontrol
->value
.integer
.value
[0] = left
& 127;
102 ucontrol
->value
.integer
.value
[1] = right
& 127;
106 static int snd_ics_put_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
108 struct snd_gus_card
*gus
= snd_kcontrol_chip(kcontrol
);
110 int addr
= kcontrol
->private_value
& 0xff;
112 unsigned char val1
, val2
, oval1
, oval2
;
114 val1
= ucontrol
->value
.integer
.value
[0] & 127;
115 val2
= ucontrol
->value
.integer
.value
[1] & 127;
116 spin_lock_irqsave(&gus
->reg_lock
, flags
);
117 oval1
= gus
->gf1
.ics_regs
[addr
][0];
118 oval2
= gus
->gf1
.ics_regs
[addr
][1];
119 change
= val1
!= oval1
|| val2
!= oval2
;
120 gus
->gf1
.ics_regs
[addr
][0] = val1
;
121 gus
->gf1
.ics_regs
[addr
][1] = val2
;
122 if (gus
->ics_flag
&& gus
->ics_flipped
&&
123 (addr
== SNDRV_ICS_GF1_DEV
|| addr
== SNDRV_ICS_MASTER_DEV
))
126 outb(addr
| 0, GUSP(gus
, MIXCNTRLPORT
));
127 outb(1, GUSP(gus
, MIXDATAPORT
));
128 outb(addr
| 2, GUSP(gus
, MIXCNTRLPORT
));
129 outb((unsigned char) val1
, GUSP(gus
, MIXDATAPORT
));
130 outb(addr
| 1, GUSP(gus
, MIXCNTRLPORT
));
131 outb(2, GUSP(gus
, MIXDATAPORT
));
132 outb(addr
| 3, GUSP(gus
, MIXCNTRLPORT
));
133 outb((unsigned char) val2
, GUSP(gus
, MIXDATAPORT
));
134 spin_unlock_irqrestore(&gus
->reg_lock
, flags
);
138 static struct snd_kcontrol_new snd_gf1_controls
[] = {
139 GF1_SINGLE("Master Playback Switch", 0, 1, 1),
140 GF1_SINGLE("Line Switch", 0, 0, 1),
141 GF1_SINGLE("Mic Switch", 0, 2, 0)
144 static struct snd_kcontrol_new snd_ics_controls
[] = {
145 GF1_SINGLE("Master Playback Switch", 0, 1, 1),
146 ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV
),
147 ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV
),
148 GF1_SINGLE("Line Switch", 0, 0, 1),
149 ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV
),
150 GF1_SINGLE("Mic Switch", 0, 2, 0),
151 ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV
),
152 ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV
)
155 int snd_gf1_new_mixer(struct snd_gus_card
* gus
)
157 struct snd_card
*card
;
158 unsigned int idx
, max
;
161 if (snd_BUG_ON(!gus
))
164 if (snd_BUG_ON(!card
))
168 snd_component_add(card
, "ICS2101");
169 if (card
->mixername
[0] == '\0') {
170 strcpy(card
->mixername
, gus
->ics_flag
? "GF1,ICS2101" : "GF1");
173 strcat(card
->mixername
, ",ICS2101");
174 strcat(card
->mixername
, ",GF1");
177 if (!gus
->ics_flag
) {
178 max
= gus
->ess_flag
? 1 : ARRAY_SIZE(snd_gf1_controls
);
179 for (idx
= 0; idx
< max
; idx
++) {
180 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_gf1_controls
[idx
], gus
))) < 0)
184 for (idx
= 0; idx
< ARRAY_SIZE(snd_ics_controls
); idx
++) {
185 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_ics_controls
[idx
], gus
))) < 0)