3 * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "opl4_local.h"
21 #include <sound/control.h>
25 static int snd_opl4_ctl_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
27 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
29 uinfo->value.integer.min = 0;
30 uinfo->value.integer.max = 7;
34 static int snd_opl4_ctl_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
36 opl4_t *opl4 = snd_kcontrol_chip(kcontrol);
37 u8 reg = kcontrol->private_value;
40 value = snd_opl4_read(opl4, reg);
41 ucontrol->value.integer.value[0] = 7 - (value & 7);
42 ucontrol->value.integer.value[1] = 7 - ((value >> 3) & 7);
46 static int snd_opl4_ctl_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
48 opl4_t *opl4 = snd_kcontrol_chip(kcontrol);
49 u8 reg = kcontrol->private_value;
52 value = (7 - (ucontrol->value.integer.value[0] & 7)) |
53 ((7 - (ucontrol->value.integer.value[1] & 7)) << 3);
54 old_value = snd_opl4_read(opl4, reg);
55 snd_opl4_write(opl4, reg, value);
56 return value != old_value;
59 static snd_kcontrol_new_t snd_opl4_controls[] = {
61 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
62 .name = "FM Playback Volume",
63 .info = snd_opl4_ctl_info,
64 .get = snd_opl4_ctl_get,
65 .put = snd_opl4_ctl_put,
66 .private_value = OPL4_REG_MIX_CONTROL_FM
69 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
70 .name = "Wavetable Playback Volume",
71 .info = snd_opl4_ctl_info,
72 .get = snd_opl4_ctl_get,
73 .put = snd_opl4_ctl_put,
74 .private_value = OPL4_REG_MIX_CONTROL_PCM
78 int snd_opl4_create_mixer(opl4_t *opl4)
80 snd_card_t *card = opl4->card;
83 #if 0 /* already set by the codec driver */
84 strcpy(card->mixername, "OPL4 Mixer");
87 for (i = 0; i < 2; ++i) {
88 err = snd_ctl_add(card, snd_ctl_new1(&snd_opl4_controls[i], opl4));