From patchwork Wed Mar 25 07:01:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "W. Trevor King" X-Patchwork-Id: 6088861 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 88F329F350 for ; Wed, 25 Mar 2015 07:03:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B9DE20268 for ; Wed, 25 Mar 2015 07:03:35 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 8CE4820251 for ; Wed, 25 Mar 2015 07:03:33 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 2C6E22619F0; Wed, 25 Mar 2015 08:03:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id B352B2604B8; Wed, 25 Mar 2015 08:03:23 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0D2F62604C5; Wed, 25 Mar 2015 08:03:22 +0100 (CET) Received: from resqmta-po-01v.sys.comcast.net (resqmta-po-01v.sys.comcast.net [96.114.154.160]) by alsa0.perex.cz (Postfix) with ESMTP id 49D7D2604B4 for ; Wed, 25 Mar 2015 08:03:16 +0100 (CET) Received: from resomta-po-03v.sys.comcast.net ([96.114.154.227]) by resqmta-po-01v.sys.comcast.net with comcast id 7j3F1q0014ueUHc01j3FfR; Wed, 25 Mar 2015 07:03:15 +0000 Received: from odin.tremily.us ([67.168.81.176]) by resomta-po-03v.sys.comcast.net with comcast id 7j1D1q00C3oF5yT01j1EjP; Wed, 25 Mar 2015 07:01:14 +0000 Received: by odin.tremily.us (Postfix, from userid 1000) id 7A47316E9237; Wed, 25 Mar 2015 00:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tremily.us; s=odin; t=1427266873; bh=QrozsVPI8Q+j4xbGWYhrYmIpJm2Q5DbZzhPs7MWfnOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kHfIAnheXiOs4E30eB6ZqGS89HxazQ6HZVuaa25vZ1cy8Pf7ckPkPzLbd/+nQkqNK COiHUzF0lTiYjpGLwK7P5BspdOW1c6DA/II+T06Jh1LYI3TpOOJ7MsOgWWy1h8HbA1 /FA001pya20V6zbBClpgvQQaXLqETnCegWNjRJ2s= From: "W. Trevor King" To: alsa-devel@alsa-project.org Date: Wed, 25 Mar 2015 00:01:04 -0700 Message-Id: <492ac5c1f00a4e07b44835f87fd5f05e8c4e6253.1427266376.git.wking@tremily.us> X-Mailer: git-send-email 2.0.5 In-Reply-To: References: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1427266995; bh=zvn4dTQ6G2phmhqb0wlQs5myrhhXh/1EjQvomK10Ve8=; h=Received:Received:Received:From:To:Subject:Date:Message-Id: MIME-Version:Content-Type; b=EgzVfgr2xkVSP3oxyjnrW7kaY/NHSodqB8XjYhSuMJ9lzFY4PgekfSi3YMSMvZpnx OqgeHQi0an2RypibCsEV3Ev50YhToR+WrxsB7Ezvuqj1zxf3OxvwXpAXQAsLuzmIUZ PPdOB6piwKHs5ABcO/LZ3K2UwdCF/16ow6zOkt+yTxJfbGIZMx4SPQjzg2nFzqTUh3 P2Wc+miu7QECqZ4o1rVcl0E/jzAUBnl93mLBpHMLsalbxX4CrYGLCF9CEYd3avVQEM 1RGmsV4MwB0Mn5n+3rpoBL85G50s0hY4y7M1HlCOFdsX/J9c4/ZylQg9GepwcJKOpY kSI0cukYHRMlQ== Cc: Takashi Iwai , Raymond Yau , "W. Trevor King" Subject: [alsa-devel] [PATCH] ALSA: hda/via - Add beep controls to VIA codecs X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP My codec has a beep-generating node: $ cat /proc/asound/card1/codec#0 Codec: VIA VT1802 ... Vendor Id: 0x11068446 Subsystem Id: 0x15587410 Revision Id: 0x100000 ... Node 0x22 [Beep Generator Widget] wcaps 0x70040c: Mono Amp-Out Amp-Out caps: ofs=0x0a, nsteps=0x12, stepsize=0x05, mute=1 Amp-Out vals: [0x0a] Power states: D0 D1 D2 D3 Power: setting=D0, actual=D0 ... But I was missing the: Control: name=... entries that I need to manage this widget from alsamixer. With this patch (based on the similar Mono Amp-Out handling in patch_conexant.c), I get a new: input: HDA Digital PCBeep as /devices/pci0000:00/0000:00:1b.0/sound/card1/hdaudioC1D0/input15 entry in dmesg and controls to manage that beep: $ cat /proc/asound/card1/codec#0 | grep -A5 Beep Node 0x22 [Beep Generator Widget] wcaps 0x70040c: Mono Amp-Out Control: name="Beep Playback Volume", index=0, device=0 ControlAmp: chs=1, dir=Out, idx=0, ofs=0 Control: name="Beep Playback Switch", index=0, device=0 ControlAmp: chs=1, dir=Out, idx=0, ofs=0 Amp-Out caps: ofs=0x0a, nsteps=0x12, stepsize=0x05, mute=1 Amp-Out vals: [0x12] Power states: D0 D1 D2 D3 Power: setting=D0, actual=D0 Signed-off-by: W. Trevor King --- On Sun, Mar 22, 2015 at 09:27:24PM +0800, Raymond Yau wrote: > Why beep generator cannot automically found by auto parser ? > … > end_nid = codec->start_nid + codec->num_nodes; > for (nid = codec->start_nid; nid < end_nid; nid++) { > unsigned int wid_caps = get_wcaps(codec, nid); > unsigned int wid_type = get_wcaps_type(wid_caps); > if (wid_type == AC_WID_BEEP) > spec->gen.beep_nid = nid; > } This is pretty much what patch_conexant.c's cx_auto_parse_beep() does, so I've just shifted that code over here to handle beeps in VIA codecs. It works on my VT1802, but I don't have any other VIA codecs around to check that it works on all of the VIA codecs (Takashi pointed out that they can be buggy [1]). Do I need to shift the auto_parse_beep() check into the VT1802-specific portion of patch_vt2002P(), or can I leave it here in the generic via_parse_auto_config()? Alternatively, we could wedge it into via_new_spec(), which would give the per-codec patches time to clear spec->gen.beep_nid for broken codecs before via_parse_auto_config() calls snd_hda_gen_parse_auto_config() which consumes beep_nid. Cheers, Trevor [1]: id:s5hpp813vva.wl-tiwai@suse.de http://thread.gmane.org/gmane.linux.alsa.devel/135819/focus=135823 sound/pci/hda/patch_via.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 3de6d3d..e4919f8 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -109,6 +109,8 @@ struct via_spec { int hp_work_active; int vt1708_jack_detect; + unsigned int beep_amp; + void (*set_widgets_power_state)(struct hda_codec *codec); unsigned int dac_stream_tag[4]; }; @@ -355,6 +357,59 @@ static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = { {} /* terminator */ }; +#ifdef CONFIG_SND_HDA_INPUT_BEEP +static inline void set_beep_amp(struct via_spec *spec, hda_nid_t nid, + int idx, int dir) +{ + spec->gen.beep_nid = nid; + spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir); +} +/* additional beep mixers; the actual parameters are overwritten at build */ +static const struct snd_kcontrol_new cxt_beep_mixer[] = { + HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), + HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), + { } /* end */ +}; + +/* create beep controls if needed */ +static int add_beep_ctls(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + int err; + + if (spec->beep_amp) { + const struct snd_kcontrol_new *knew; + for (knew = cxt_beep_mixer; knew->name; knew++) { + struct snd_kcontrol *kctl; + kctl = snd_ctl_new1(knew, codec); + if (!kctl) + return -ENOMEM; + kctl->private_value = spec->beep_amp; + err = snd_hda_ctl_add(codec, 0, kctl); + if (err < 0) + return err; + } + } + return 0; +} + +static void auto_parse_beep(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + hda_nid_t nid, end_nid; + + end_nid = codec->start_nid + codec->num_nodes; + for (nid = codec->start_nid; nid < end_nid; nid++) + if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { + set_beep_amp(spec, nid, 0, HDA_OUTPUT); + break; + } +} +#else +#define set_beep_amp(spec, nid, idx, dir) /* NOP */ +#define add_beep_ctls(codec) 0 +#define auto_parse_beep(codec) +#endif /* check AA path's mute status */ static bool is_aa_path_mute(struct hda_codec *codec) @@ -441,6 +496,10 @@ static int via_build_controls(struct hda_codec *codec) if (err < 0) return err; + err = add_beep_ctls(codec); + if (err < 0) + return err; + if (spec->set_widgets_power_state) spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum; @@ -631,6 +690,8 @@ static int via_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; + auto_parse_beep(codec); + err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); if (err < 0) return err;