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 <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 #define snd_gf1_info_single snd_ctl_boolean_mono_info
41 static int snd_gf1_get_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
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;
47 ucontrol
->value
.integer
.value
[0] = (gus
->mix_cntrl_reg
>> shift
) & 1;
49 ucontrol
->value
.integer
.value
[0] ^= 1;
53 static int snd_gf1_put_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
55 struct snd_gus_card
*gus
= snd_kcontrol_chip(kcontrol
);
57 int shift
= kcontrol
->private_value
& 0xff;
58 int invert
= (kcontrol
->private_value
>> 8) & 1;
60 unsigned char oval
, nval
;
62 nval
= ucontrol
->value
.integer
.value
[0] & 1;
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
);
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 }
82 static int snd_ics_info_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
84 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
86 uinfo
->value
.integer
.min
= 0;
87 uinfo
->value
.integer
.max
= 127;
91 static int snd_ics_get_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
93 struct snd_gus_card
*gus
= snd_kcontrol_chip(kcontrol
);
95 int addr
= kcontrol
->private_value
& 0xff;
96 unsigned char left
, right
;
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;
107 static int snd_ics_put_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
109 struct snd_gus_card
*gus
= snd_kcontrol_chip(kcontrol
);
111 int addr
= kcontrol
->private_value
& 0xff;
113 unsigned char val1
, val2
, oval1
, oval2
, tmp
;
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
)) {
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
);
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)
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
)
159 int snd_gf1_new_mixer(struct snd_gus_card
* gus
)
161 struct snd_card
*card
;
162 unsigned int idx
, max
;
165 snd_assert(gus
!= NULL
, return -EINVAL
);
167 snd_assert(card
!= NULL
, return -EINVAL
);
170 snd_component_add(card
, "ICS2101");
171 if (card
->mixername
[0] == '\0') {
172 strcpy(card
->mixername
, gus
->ics_flag
? "GF1,ICS2101" : "GF1");
175 strcat(card
->mixername
, ",ICS2101");
176 strcat(card
->mixername
, ",GF1");
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)
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)