Loading...
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 <linux/time.h>
23#include <linux/wait.h>
24#include <sound/core.h>
25#include <sound/control.h>
26#include <sound/gus.h>
27
28/*
29 *
30 */
31
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) }
37
38#define snd_gf1_info_single snd_ctl_boolean_mono_info
39
40static int snd_gf1_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
41{
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;
45
46 ucontrol->value.integer.value[0] = (gus->mix_cntrl_reg >> shift) & 1;
47 if (invert)
48 ucontrol->value.integer.value[0] ^= 1;
49 return 0;
50}
51
52static int snd_gf1_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
53{
54 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
55 unsigned long flags;
56 int shift = kcontrol->private_value & 0xff;
57 int invert = (kcontrol->private_value >> 8) & 1;
58 int change;
59 unsigned char oval, nval;
60
61 nval = ucontrol->value.integer.value[0] & 1;
62 if (invert)
63 nval ^= 1;
64 nval <<= shift;
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);
72 return change;
73}
74
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 }
80
81static int snd_ics_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
82{
83 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
84 uinfo->count = 2;
85 uinfo->value.integer.min = 0;
86 uinfo->value.integer.max = 127;
87 return 0;
88}
89
90static int snd_ics_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
91{
92 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
93 unsigned long flags;
94 int addr = kcontrol->private_value & 0xff;
95 unsigned char left, right;
96
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;
103 return 0;
104}
105
106static int snd_ics_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
107{
108 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
109 unsigned long flags;
110 int addr = kcontrol->private_value & 0xff;
111 int change;
112 unsigned char val1, val2, oval1, oval2, tmp;
113
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)) {
124 tmp = val1;
125 val1 = val2;
126 val2 = tmp;
127 }
128 addr <<= 3;
129 outb(addr | 0, GUSP(gus, MIXCNTRLPORT));
130 outb(1, GUSP(gus, MIXDATAPORT));
131 outb(addr | 2, GUSP(gus, MIXCNTRLPORT));
132 outb((unsigned char) val1, GUSP(gus, MIXDATAPORT));
133 outb(addr | 1, GUSP(gus, MIXCNTRLPORT));
134 outb(2, GUSP(gus, MIXDATAPORT));
135 outb(addr | 3, GUSP(gus, MIXCNTRLPORT));
136 outb((unsigned char) val2, GUSP(gus, MIXDATAPORT));
137 spin_unlock_irqrestore(&gus->reg_lock, flags);
138 return change;
139}
140
141static struct snd_kcontrol_new snd_gf1_controls[] = {
142GF1_SINGLE("Master Playback Switch", 0, 1, 1),
143GF1_SINGLE("Line Switch", 0, 0, 1),
144GF1_SINGLE("Mic Switch", 0, 2, 0)
145};
146
147static struct snd_kcontrol_new snd_ics_controls[] = {
148GF1_SINGLE("Master Playback Switch", 0, 1, 1),
149ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV),
150ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV),
151GF1_SINGLE("Line Switch", 0, 0, 1),
152ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV),
153GF1_SINGLE("Mic Switch", 0, 2, 0),
154ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV),
155ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV)
156};
157
158int snd_gf1_new_mixer(struct snd_gus_card * gus)
159{
160 struct snd_card *card;
161 unsigned int idx, max;
162 int err;
163
164 if (snd_BUG_ON(!gus))
165 return -EINVAL;
166 card = gus->card;
167 if (snd_BUG_ON(!card))
168 return -EINVAL;
169
170 if (gus->ics_flag)
171 snd_component_add(card, "ICS2101");
172 if (card->mixername[0] == '\0') {
173 strcpy(card->mixername, gus->ics_flag ? "GF1,ICS2101" : "GF1");
174 } else {
175 if (gus->ics_flag)
176 strcat(card->mixername, ",ICS2101");
177 strcat(card->mixername, ",GF1");
178 }
179
180 if (!gus->ics_flag) {
181 max = gus->ess_flag ? 1 : ARRAY_SIZE(snd_gf1_controls);
182 for (idx = 0; idx < max; idx++) {
183 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_gf1_controls[idx], gus))) < 0)
184 return err;
185 }
186 } else {
187 for (idx = 0; idx < ARRAY_SIZE(snd_ics_controls); idx++) {
188 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ics_controls[idx], gus))) < 0)
189 return err;
190 }
191 }
192 return 0;
193}
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 * Routines for control of ICS 2101 chip and "mixer" in GF1 chip
5 */
6
7#include <linux/time.h>
8#include <linux/wait.h>
9#include <sound/core.h>
10#include <sound/control.h>
11#include <sound/gus.h>
12
13/*
14 *
15 */
16
17#define GF1_SINGLE(xname, xindex, shift, invert) \
18{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
19 .info = snd_gf1_info_single, \
20 .get = snd_gf1_get_single, .put = snd_gf1_put_single, \
21 .private_value = shift | (invert << 8) }
22
23#define snd_gf1_info_single snd_ctl_boolean_mono_info
24
25static int snd_gf1_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
26{
27 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
28 int shift = kcontrol->private_value & 0xff;
29 int invert = (kcontrol->private_value >> 8) & 1;
30
31 ucontrol->value.integer.value[0] = (gus->mix_cntrl_reg >> shift) & 1;
32 if (invert)
33 ucontrol->value.integer.value[0] ^= 1;
34 return 0;
35}
36
37static int snd_gf1_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
38{
39 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
40 unsigned long flags;
41 int shift = kcontrol->private_value & 0xff;
42 int invert = (kcontrol->private_value >> 8) & 1;
43 int change;
44 unsigned char oval, nval;
45
46 nval = ucontrol->value.integer.value[0] & 1;
47 if (invert)
48 nval ^= 1;
49 nval <<= shift;
50 spin_lock_irqsave(&gus->reg_lock, flags);
51 oval = gus->mix_cntrl_reg;
52 nval = (oval & ~(1 << shift)) | nval;
53 change = nval != oval;
54 outb(gus->mix_cntrl_reg = nval, GUSP(gus, MIXCNTRLREG));
55 outb(gus->gf1.active_voice = 0, GUSP(gus, GF1PAGE));
56 spin_unlock_irqrestore(&gus->reg_lock, flags);
57 return change;
58}
59
60#define ICS_DOUBLE(xname, xindex, addr) \
61{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
62 .info = snd_ics_info_double, \
63 .get = snd_ics_get_double, .put = snd_ics_put_double, \
64 .private_value = addr }
65
66static int snd_ics_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
67{
68 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
69 uinfo->count = 2;
70 uinfo->value.integer.min = 0;
71 uinfo->value.integer.max = 127;
72 return 0;
73}
74
75static int snd_ics_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
76{
77 struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
78 unsigned long flags;
79 int addr = kcontrol->private_value & 0xff;
80 unsigned char left, right;
81
82 spin_lock_irqsave(&gus->reg_lock, flags);
83 left = gus->gf1.ics_regs[addr][0];
84 right = gus->gf1.ics_regs[addr][1];
85 spin_unlock_irqrestore(&gus->reg_lock, flags);
86 ucontrol->value.integer.value[0] = left & 127;
87 ucontrol->value.integer.value[1] = right & 127;
88 return 0;
89}
90
91static int snd_ics_put_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 int change;
97 unsigned char val1, val2, oval1, oval2;
98
99 val1 = ucontrol->value.integer.value[0] & 127;
100 val2 = ucontrol->value.integer.value[1] & 127;
101 spin_lock_irqsave(&gus->reg_lock, flags);
102 oval1 = gus->gf1.ics_regs[addr][0];
103 oval2 = gus->gf1.ics_regs[addr][1];
104 change = val1 != oval1 || val2 != oval2;
105 gus->gf1.ics_regs[addr][0] = val1;
106 gus->gf1.ics_regs[addr][1] = val2;
107 if (gus->ics_flag && gus->ics_flipped &&
108 (addr == SNDRV_ICS_GF1_DEV || addr == SNDRV_ICS_MASTER_DEV))
109 swap(val1, val2);
110 addr <<= 3;
111 outb(addr | 0, GUSP(gus, MIXCNTRLPORT));
112 outb(1, GUSP(gus, MIXDATAPORT));
113 outb(addr | 2, GUSP(gus, MIXCNTRLPORT));
114 outb((unsigned char) val1, GUSP(gus, MIXDATAPORT));
115 outb(addr | 1, GUSP(gus, MIXCNTRLPORT));
116 outb(2, GUSP(gus, MIXDATAPORT));
117 outb(addr | 3, GUSP(gus, MIXCNTRLPORT));
118 outb((unsigned char) val2, GUSP(gus, MIXDATAPORT));
119 spin_unlock_irqrestore(&gus->reg_lock, flags);
120 return change;
121}
122
123static const struct snd_kcontrol_new snd_gf1_controls[] = {
124GF1_SINGLE("Master Playback Switch", 0, 1, 1),
125GF1_SINGLE("Line Switch", 0, 0, 1),
126GF1_SINGLE("Mic Switch", 0, 2, 0)
127};
128
129static const struct snd_kcontrol_new snd_ics_controls[] = {
130GF1_SINGLE("Master Playback Switch", 0, 1, 1),
131ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV),
132ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV),
133GF1_SINGLE("Line Switch", 0, 0, 1),
134ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV),
135GF1_SINGLE("Mic Switch", 0, 2, 0),
136ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV),
137ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV)
138};
139
140int snd_gf1_new_mixer(struct snd_gus_card * gus)
141{
142 struct snd_card *card;
143 unsigned int idx, max;
144 int err;
145
146 if (snd_BUG_ON(!gus))
147 return -EINVAL;
148 card = gus->card;
149 if (snd_BUG_ON(!card))
150 return -EINVAL;
151
152 if (gus->ics_flag)
153 snd_component_add(card, "ICS2101");
154 if (card->mixername[0] == '\0') {
155 strcpy(card->mixername, gus->ics_flag ? "GF1,ICS2101" : "GF1");
156 } else {
157 if (gus->ics_flag)
158 strcat(card->mixername, ",ICS2101");
159 strcat(card->mixername, ",GF1");
160 }
161
162 if (!gus->ics_flag) {
163 max = gus->ess_flag ? 1 : ARRAY_SIZE(snd_gf1_controls);
164 for (idx = 0; idx < max; idx++) {
165 err = snd_ctl_add(card, snd_ctl_new1(&snd_gf1_controls[idx], gus));
166 if (err < 0)
167 return err;
168 }
169 } else {
170 for (idx = 0; idx < ARRAY_SIZE(snd_ics_controls); idx++) {
171 err = snd_ctl_add(card, snd_ctl_new1(&snd_ics_controls[idx], gus));
172 if (err < 0)
173 return err;
174 }
175 }
176 return 0;
177}