linux/sound/drivers/opl4/opl4_mixer.c
<<
>>
Prefs
   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
  23static int snd_opl4_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  24{
  25        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  26        uinfo->count = 2;
  27        uinfo->value.integer.min = 0;
  28        uinfo->value.integer.max = 7;
  29        return 0;
  30}
  31
  32static int snd_opl4_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  33{
  34        struct snd_opl4 *opl4 = snd_kcontrol_chip(kcontrol);
  35        unsigned long flags;
  36        u8 reg = kcontrol->private_value;
  37        u8 value;
  38
  39        spin_lock_irqsave(&opl4->reg_lock, flags);
  40        value = snd_opl4_read(opl4, reg);
  41        spin_unlock_irqrestore(&opl4->reg_lock, flags);
  42        ucontrol->value.integer.value[0] = 7 - (value & 7);
  43        ucontrol->value.integer.value[1] = 7 - ((value >> 3) & 7);
  44        return 0;
  45}
  46
  47static int snd_opl4_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  48{
  49        struct snd_opl4 *opl4 = snd_kcontrol_chip(kcontrol);
  50        unsigned long flags;
  51        u8 reg = kcontrol->private_value;
  52        u8 value, old_value;
  53
  54        value = (7 - (ucontrol->value.integer.value[0] & 7)) |
  55                ((7 - (ucontrol->value.integer.value[1] & 7)) << 3);
  56        spin_lock_irqsave(&opl4->reg_lock, flags);
  57        old_value = snd_opl4_read(opl4, reg);
  58        snd_opl4_write(opl4, reg, value);
  59        spin_unlock_irqrestore(&opl4->reg_lock, flags);
  60        return value != old_value;
  61}
  62
  63static struct snd_kcontrol_new snd_opl4_controls[] = {
  64        {
  65                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  66                .name = "FM Playback Volume",
  67                .info = snd_opl4_ctl_info,
  68                .get = snd_opl4_ctl_get,
  69                .put = snd_opl4_ctl_put,
  70                .private_value = OPL4_REG_MIX_CONTROL_FM
  71        },
  72        {
  73                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  74                .name = "Wavetable Playback Volume",
  75                .info = snd_opl4_ctl_info,
  76                .get = snd_opl4_ctl_get,
  77                .put = snd_opl4_ctl_put,
  78                .private_value = OPL4_REG_MIX_CONTROL_PCM
  79        }
  80};
  81
  82int snd_opl4_create_mixer(struct snd_opl4 *opl4)
  83{
  84        struct snd_card *card = opl4->card;
  85        int i, err;
  86
  87        strcat(card->mixername, ",OPL4");
  88
  89        for (i = 0; i < 2; ++i) {
  90                err = snd_ctl_add(card, snd_ctl_new1(&snd_opl4_controls[i], opl4));
  91                if (err < 0)
  92                        return err;
  93        }
  94        return 0;
  95}
  96