From: Adrian Pardini <pardo.bsso@gmail.com>
To: alsa-devel@alsa-project.org
Subject: [PATCH - usb: Headphone support for cm6206 2/2] usb: adds headphone source and mute controls to cm6206
Date: Tue, 20 Jul 2010 19:44:29 -0300 [thread overview]
Message-ID: <201007201944.29990.pardo.bsso@gmail.com> (raw)
In-Reply-To: <201007201942.28942.pardo.bsso@gmail.com>
Signed-off-by: Adrian Pardini <adrian.pardini@solar.org.ar>
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index c4cbbc0..c53842c 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -370,6 +370,112 @@ int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
0, 0, &buf, 4, 1000);
}
+static int snd_cm6206_headphone_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = kcontrol->private_value;
+ return 0;
+}
+
+static int snd_cm6206_headphone_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+ struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
+ struct usb_device *dev = mixer->chip->dev;
+
+ u16 reg2 = mixer->cm6206reg2;
+ u16 idx = kcontrol->private_value = ucontrol->value.integer.value[0];
+
+ reg2 = (u16)((((1<<7) | (idx<<5))<<8) | (reg2 & 0x1800));
+
+ snd_usb_cm106_write_int_reg(dev, 2, reg2);
+ mixer->cm6206reg2 = reg2;
+ return 0;
+}
+
+static int snd_cm6206_headphone_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = kcontrol->private_value & (1<<11);
+ ucontrol->value.integer.value[1] = kcontrol->private_value & (1<<12);
+ return 0;
+}
+
+
+
+static int snd_cm6206_headphone_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+ struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
+ struct usb_device *dev = mixer->chip->dev;
+
+ u16 reg2 = mixer->cm6206reg2;
+ u16 mute;
+
+ mute = ucontrol->value.integer.value[1] ? (1<<12) : 0;
+ mute |= ucontrol->value.integer.value[0] ? (1<<11) : 0;
+ kcontrol->private_value = mute;
+
+ reg2 = (u16)(mute | (reg2 & ~0x1800));
+
+ snd_usb_cm106_write_int_reg(dev, 2, reg2);
+ mixer->cm6206reg2 = reg2;
+ return 1;
+}
+
+static int snd_cm6206_headphone_source_info(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
+{
+ static const char *const names[] = {
+ "Side",
+ "Surround",
+ "Center",
+ "Front"
+ };
+
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+ uinfo->count = 1;
+ uinfo->value.enumerated.items = 4;
+ if (uinfo->value.enumerated.item > 3)
+ uinfo->value.enumerated.item = 3;
+ strcpy(uinfo->value.enumerated.name, names[uinfo->value.enumerated.item]);
+ return 0;
+}
+
+#define snd_cm6206_headphone_mute_info snd_ctl_boolean_stereo_info
+
+
+static struct snd_kcontrol_new cm6206_controls[] = {
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+ .name = "Headphone Source",
+ .info = snd_cm6206_headphone_source_info,
+ .get = snd_cm6206_headphone_source_get,
+ .put = snd_cm6206_headphone_source_put,
+ .private_value = 3
+ },
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+ .name = "Headphone",
+ .info = snd_cm6206_headphone_mute_info,
+ .get = snd_cm6206_headphone_mute_get,
+ .put = snd_cm6206_headphone_mute_put,
+ .private_value = 24
+ }
+};
+
+static int snd_cm6206_controls_create(struct usb_mixer_interface *mixer)
+{
+ int i, err;
+
+ for (i = 0; i < ARRAY_SIZE(cm6206_controls); ++i) {
+ err = snd_ctl_add(mixer->chip->card,
+ snd_ctl_new1(&cm6206_controls[i], mixer));
+ if (err < 0)
+ return err;
+ }
+ mixer->cm6206reg2 = 0xf800; /* Headphone source=front, no mute. */
+ return 0;
+}
+
int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
{
int err;
@@ -395,6 +501,12 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
return err;
}
+ if (mixer->chip->usb_id == USB_ID(0x0d8c, 0x0102)) {
+ err = snd_cm6206_controls_create(mixer);
+ if (err < 0)
+ return err;
+ }
+
return 0;
}
--
1.5.4.3
--
Adrian.
http://elesquinazotango.com.ar
http://www.noalcodigodescioli.blogspot.com/
next prev parent reply other threads:[~2010-07-20 22:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-20 22:42 [PATCH - usb: Headphone support for cm6206 1/2] usb: move snd_usb_cm106_write_int_reg to mixer_quirks.c Adrian Pardini
2010-07-20 22:44 ` Adrian Pardini [this message]
2010-07-30 12:31 ` [PATCH - usb: Headphone support for cm6206 2/2] usb: adds headphone source and mute controls to cm6206 Takashi Iwai
2010-07-30 14:51 ` Adrian Pardini
2010-07-30 15:08 ` Takashi Iwai
2010-07-30 12:24 ` [PATCH - usb: Headphone support for cm6206 1/2] usb: move snd_usb_cm106_write_int_reg to mixer_quirks.c Takashi Iwai
2010-07-30 14:39 ` Adrian Pardini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201007201944.29990.pardo.bsso@gmail.com \
--to=pardo.bsso@gmail.com \
--cc=alsa-devel@alsa-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.