ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / drivers / opl4 / opl4_mixer.c
1 /*
2  * OPL4 mixer functions
3  * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include "opl4_local.h"
21 #include <sound/control.h>
22
23 #define chip_t opl4_t
24
25 static int snd_opl4_ctl_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
26 {
27         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
28         uinfo->count = 2;
29         uinfo->value.integer.min = 0;
30         uinfo->value.integer.max = 7;
31         return 0;
32 }
33
34 static int snd_opl4_ctl_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
35 {
36         opl4_t *opl4 = snd_kcontrol_chip(kcontrol);
37         u8 reg = kcontrol->private_value;
38         u8 value;
39
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);
43         return 0;
44 }
45
46 static int snd_opl4_ctl_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
47 {
48         opl4_t *opl4 = snd_kcontrol_chip(kcontrol);
49         u8 reg = kcontrol->private_value;
50         u8 value, old_value;
51
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;
57 }
58
59 static snd_kcontrol_new_t snd_opl4_controls[] = {
60         {
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
67         },
68         {
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
75         }
76 };
77
78 int snd_opl4_create_mixer(opl4_t *opl4)
79 {
80         snd_card_t *card = opl4->card;
81         int i, err;
82
83 #if 0   /* already set by the codec driver */
84         strcpy(card->mixername, "OPL4 Mixer");
85 #endif
86
87         for (i = 0; i < 2; ++i) {
88                 err = snd_ctl_add(card, snd_ctl_new1(&snd_opl4_controls[i], opl4));
89                 if (err < 0)
90                         return err;
91         }
92         return 0;
93 }