Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
0004  *  Routines for control of ICS 2101 chip and "mixer" in GF1 chip
0005  */
0006 
0007 #include <linux/time.h>
0008 #include <linux/wait.h>
0009 #include <sound/core.h>
0010 #include <sound/control.h>
0011 #include <sound/gus.h>
0012 
0013 /*
0014  *
0015  */
0016 
0017 #define GF1_SINGLE(xname, xindex, shift, invert) \
0018 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
0019   .info = snd_gf1_info_single, \
0020   .get = snd_gf1_get_single, .put = snd_gf1_put_single, \
0021   .private_value = shift | (invert << 8) }
0022 
0023 #define snd_gf1_info_single snd_ctl_boolean_mono_info
0024 
0025 static int snd_gf1_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0026 {
0027     struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
0028     int shift = kcontrol->private_value & 0xff;
0029     int invert = (kcontrol->private_value >> 8) & 1;
0030     
0031     ucontrol->value.integer.value[0] = (gus->mix_cntrl_reg >> shift) & 1;
0032     if (invert)
0033         ucontrol->value.integer.value[0] ^= 1;
0034     return 0;
0035 }
0036 
0037 static int snd_gf1_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0038 {
0039     struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
0040     unsigned long flags;
0041     int shift = kcontrol->private_value & 0xff;
0042     int invert = (kcontrol->private_value >> 8) & 1;
0043     int change;
0044     unsigned char oval, nval;
0045     
0046     nval = ucontrol->value.integer.value[0] & 1;
0047     if (invert)
0048         nval ^= 1;
0049     nval <<= shift;
0050     spin_lock_irqsave(&gus->reg_lock, flags);
0051     oval = gus->mix_cntrl_reg;
0052     nval = (oval & ~(1 << shift)) | nval;
0053     change = nval != oval;
0054     outb(gus->mix_cntrl_reg = nval, GUSP(gus, MIXCNTRLREG));
0055     outb(gus->gf1.active_voice = 0, GUSP(gus, GF1PAGE));
0056     spin_unlock_irqrestore(&gus->reg_lock, flags);
0057     return change;
0058 }
0059 
0060 #define ICS_DOUBLE(xname, xindex, addr) \
0061 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
0062   .info = snd_ics_info_double, \
0063   .get = snd_ics_get_double, .put = snd_ics_put_double, \
0064   .private_value = addr }
0065 
0066 static int snd_ics_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
0067 {
0068     uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
0069     uinfo->count = 2;
0070     uinfo->value.integer.min = 0;
0071     uinfo->value.integer.max = 127;
0072     return 0;
0073 }
0074 
0075 static int snd_ics_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0076 {
0077     struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
0078     unsigned long flags;
0079     int addr = kcontrol->private_value & 0xff;
0080     unsigned char left, right;
0081     
0082     spin_lock_irqsave(&gus->reg_lock, flags);
0083     left = gus->gf1.ics_regs[addr][0];
0084     right = gus->gf1.ics_regs[addr][1];
0085     spin_unlock_irqrestore(&gus->reg_lock, flags);
0086     ucontrol->value.integer.value[0] = left & 127;
0087     ucontrol->value.integer.value[1] = right & 127;
0088     return 0;
0089 }
0090 
0091 static int snd_ics_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0092 {
0093     struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
0094     unsigned long flags;
0095     int addr = kcontrol->private_value & 0xff;
0096     int change;
0097     unsigned char val1, val2, oval1, oval2;
0098     
0099     val1 = ucontrol->value.integer.value[0] & 127;
0100     val2 = ucontrol->value.integer.value[1] & 127;
0101     spin_lock_irqsave(&gus->reg_lock, flags);
0102     oval1 = gus->gf1.ics_regs[addr][0];
0103     oval2 = gus->gf1.ics_regs[addr][1];
0104     change = val1 != oval1 || val2 != oval2;
0105     gus->gf1.ics_regs[addr][0] = val1;
0106     gus->gf1.ics_regs[addr][1] = val2;
0107     if (gus->ics_flag && gus->ics_flipped &&
0108         (addr == SNDRV_ICS_GF1_DEV || addr == SNDRV_ICS_MASTER_DEV))
0109         swap(val1, val2);
0110     addr <<= 3;
0111     outb(addr | 0, GUSP(gus, MIXCNTRLPORT));
0112     outb(1, GUSP(gus, MIXDATAPORT));
0113     outb(addr | 2, GUSP(gus, MIXCNTRLPORT));
0114     outb((unsigned char) val1, GUSP(gus, MIXDATAPORT));
0115     outb(addr | 1, GUSP(gus, MIXCNTRLPORT));
0116     outb(2, GUSP(gus, MIXDATAPORT));
0117     outb(addr | 3, GUSP(gus, MIXCNTRLPORT));
0118     outb((unsigned char) val2, GUSP(gus, MIXDATAPORT));
0119     spin_unlock_irqrestore(&gus->reg_lock, flags);
0120     return change;
0121 }
0122 
0123 static const struct snd_kcontrol_new snd_gf1_controls[] = {
0124 GF1_SINGLE("Master Playback Switch", 0, 1, 1),
0125 GF1_SINGLE("Line Switch", 0, 0, 1),
0126 GF1_SINGLE("Mic Switch", 0, 2, 0)
0127 };
0128 
0129 static const struct snd_kcontrol_new snd_ics_controls[] = {
0130 GF1_SINGLE("Master Playback Switch", 0, 1, 1),
0131 ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV),
0132 ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV),
0133 GF1_SINGLE("Line Switch", 0, 0, 1),
0134 ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV),
0135 GF1_SINGLE("Mic Switch", 0, 2, 0),
0136 ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV),
0137 ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV)
0138 };
0139 
0140 int snd_gf1_new_mixer(struct snd_gus_card * gus)
0141 {
0142     struct snd_card *card;
0143     unsigned int idx, max;
0144     int err;
0145 
0146     if (snd_BUG_ON(!gus))
0147         return -EINVAL;
0148     card = gus->card;
0149     if (snd_BUG_ON(!card))
0150         return -EINVAL;
0151 
0152     if (gus->ics_flag)
0153         snd_component_add(card, "ICS2101");
0154     if (card->mixername[0] == '\0') {
0155         strcpy(card->mixername, gus->ics_flag ? "GF1,ICS2101" : "GF1");
0156     } else {
0157         if (gus->ics_flag)
0158             strcat(card->mixername, ",ICS2101");
0159         strcat(card->mixername, ",GF1");
0160     }
0161 
0162     if (!gus->ics_flag) {
0163         max = gus->ess_flag ? 1 : ARRAY_SIZE(snd_gf1_controls);
0164         for (idx = 0; idx < max; idx++) {
0165             err = snd_ctl_add(card, snd_ctl_new1(&snd_gf1_controls[idx], gus));
0166             if (err < 0)
0167                 return err;
0168         }
0169     } else {
0170         for (idx = 0; idx < ARRAY_SIZE(snd_ics_controls); idx++) {
0171             err = snd_ctl_add(card, snd_ctl_new1(&snd_ics_controls[idx], gus));
0172             if (err < 0)
0173                 return err;
0174         }
0175     }
0176     return 0;
0177 }