NetBSD Problem Report #48495

From www@NetBSD.org  Sat Jan  4 00:12:53 2014
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "Postmaster NetBSD.org" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 8F464A6464
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  4 Jan 2014 00:12:53 +0000 (UTC)
Message-Id: <20140104001252.268BAA646D@mollari.NetBSD.org>
Date: Sat,  4 Jan 2014 00:12:52 +0000 (UTC)
From: nathanialsloss@yahoo.com.au
Reply-To: nathanialsloss@yahoo.com.au
To: gnats-bugs@NetBSD.org
Subject: no sysbeep on speakers on Panasonic Toughbook mk5 after hdaudio attach
X-Send-Pr-Version: www-1.0

>Number:         48495
>Category:       kern
>Synopsis:       no sysbeep on speakers on Panasonic Toughbook mk5 after hdaudio attach
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 04 00:15:00 +0000 2014
>Closed-Date:    Sun Sep 21 10:54:04 +0000 2014
>Last-Modified:  Sun Sep 21 10:54:04 +0000 2014
>Originator:     Nat Sloss
>Release:        NetBSD 6.1.1
>Organization:
>Environment:
NetBSD beast 6.1.1_PATCH NetBSD 6.1.1_PATCH (C3TEST) #0: Thu Jan  2 10:54:36 EST 2014  build@microrusty:/usr/src/sys/arch/i386/compile/obj/C3TEST i386
>Description:
Sysbeep can be heard on headphones but not through the speaker on a Panasonic Toughbook mk5.

The audio codec is a Realtek ALC231 which wrongly identifies as an ALC269.  After resetting the hdaudio device the mixer for the speakers (nid 0xf) mutes the input from the mixer that the analogue pc beep is attached to (nid 0xb and nid 0x1d respectively.)
>How-To-Repeat:
In a tty with headphones connected type:
printf "\007" (you will hear sysbeep)

Disconnect the headphones and repeat the command above and you wont hear sysbeep.
>Fix:
Apply this patch:

NB: This patch is a continuation of an earlier PR #45778 as I think that an analogue pc beep enable function is the best place for the code of analogue pc beep quirks.

Index: sys/dev/pci/hdaudio/hdafg.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/hdaudio/hdafg.c,v
retrieving revision 1.15.2.1
diff -u -r1.15.2.1 hdafg.c
--- sys/dev/pci/hdaudio/hdafg.c	17 Mar 2012 17:26:07 -0000	1.15.2.1
+++ sys/dev/pci/hdaudio/hdafg.c	3 Jan 2014 23:54:54 -0000
@@ -338,6 +338,7 @@
 					prop_dictionary_t);
 static int	hdafg_codec_info(void *, prop_dictionary_t,
 				       prop_dictionary_t);
+static void	hdafg_enable_analogue_beep(struct hdafg_softc *);

 CFATTACH_DECL2_NEW(
     hdafg,
@@ -3681,6 +3682,9 @@
 	if (1) hdafg_widget_pin_dump(sc);
 	hdafg_assoc_dump(sc);

+	hda_debug(sc, "enabling analogue beep\n");
+	hdafg_enable_analogue_beep(sc);
+
 	hda_debug(sc, "configuring encodings\n");
 	sc->sc_audiodev.ad_sc = sc;
 	hdafg_configure_encodings(sc);
@@ -4356,3 +4360,64 @@
 		return ENOTTY;
 	}
 }
+
+static void
+hdafg_enable_analogue_beep(struct hdafg_softc *sc)
+{
+	int nid;
+	uint32_t response;
+	
+	switch (sc->sc_vendor) {
+	    case HDA_VENDOR_SIGMATEL:
+		switch (sc->sc_product) {
+		    case 0x7632:	/* STAC9202 */
+		    case 0x7633:	/* STAC9202D */
+		    case 0x7690:	/* STAC9200 */
+		    case 0x7691:	/* STAC9200D */
+		    case 0x7698:	/* STAC9205 */
+		    case 0x76a0:	/* STAC9205 */
+		    case 0x76a1:	/* STAC9205D */
+		    case 0x76a2:	/* STAC9204 */
+		    case 0x76a3:	/* STAC9204D */
+
+#define AFG_GET_ANACTRL 0xFe0
+#define AFG_SET_ANACTRL 0x7e0
+#define AnalogBeepEn 0x20 		/* bit 5 = 1 */
+
+			nid = 0x01;
+
+			response = hdaudio_command(sc->sc_codec, nid,
+			    AFG_GET_ANACTRL, 0x00);
+			hda_delay(100);
+
+			response |= AnalogBeepEn;
+
+			hdaudio_command(sc->sc_codec, nid, AFG_SET_ANACTRL,
+			    response);
+			hda_delay(100);
+			break;
+
+		    default:
+			break;
+		}
+		break;
+	    case HDA_VENDOR_REALTEK:
+		switch (sc->sc_product) {
+		    case 0x0269:
+			/* The Panasonic Toughbook CF19 - Mk 5 uses a Realtek ALC231 that
+			 * identifies as an ALC269. This unmutes the PCBEEP on the speaker.
+			 */
+ 			nid = 0xf;
+                        response = hdaudio_command(sc->sc_codec, nid,
+                            CORB_SET_AMPLIFIER_GAIN_MUTE, 0x7100);
+                        hda_delay(100);
+                        break;
+
+                    default:
+                        break;
+                }
+
+	    default:
+		break;
+	}
+}

NB: This patch is my own work which I submit freely under the NetBSD license.

Regards,

Nat.

>Release-Note:

>Audit-Trail:
From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: "gnats-bugs" <gnats-bugs@netbsd.org>
Cc: 
Subject: Re: kern/48495
Date: Fri, 19 Sep 2014 23:45:47 +1000

 Hi,

 Here is a new revised patch for sysbeep on Toughbook cf19 mk 1 and mk 5
 computers and other computers using sigmatel and realtek hdaudio
 controllers:

 Index: src/sys/dev/pci/hdaudio/hdafg.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/pci/hdaudio/hdafg.c,v
 retrieving revision 1.21
 diff -u -r1.21 hdafg.c
 --- src/sys/dev/pci/hdaudio/hdafg.c	23 May 2014 13:57:04 -0000	1.21
 +++ src/sys/dev/pci/hdaudio/hdafg.c	19 Sep 2014 13:40:05 -0000
 @@ -338,6 +338,7 @@
  					prop_dictionary_t);
  static int	hdafg_codec_info(void *, prop_dictionary_t,
  				       prop_dictionary_t);
 +static void	hdafg_enable_analog_beep(struct hdafg_softc *);

  CFATTACH_DECL2_NEW(
      hdafg,
 @@ -3688,6 +3689,9 @@
  	if (1) hdafg_widget_pin_dump(sc);
  	hdafg_assoc_dump(sc);

 +	hda_debug(sc, "enabling analog beep\n");
 +	hdafg_enable_analog_beep(sc);
 +
  	hda_debug(sc, "configuring encodings\n");
  	sc->sc_audiodev.ad_sc = sc;
  	hdafg_configure_encodings(sc);
 @@ -4361,3 +4365,61 @@
  		return ENOTTY;
  	}
  }
 +
 +#define HDAFG_GET_ANACTRL 		0xFe0
 +#define HDAFG_SET_ANACTRL 		0x7e0
 +#define HDAFG_ANALOG_BEEP_EN		__BIT(5)
 +
 +static void
 +hdafg_enable_analog_beep(struct hdafg_softc *sc)
 +{
 +	int nid;
 +	uint32_t response;
 +	
 +	switch (sc->sc_vendor) {
 +	case HDA_VENDOR_SIGMATEL:
 +		switch (sc->sc_product) {
 +		case HDA_PRODUCT_STAC9200:
 +		case HDA_PRODUCT_STAC9200D:
 +		case HDA_PRODUCT_STAC9202:
 +		case HDA_PRODUCT_STAC9202D:
 +		case HDA_PRODUCT_STAC9204:
 +		case HDA_PRODUCT_STAC9204D:
 +		case HDA_PRODUCT_STAC9205:
 +		case HDA_PRODUCT_STAC9205_2:
 +		case HDA_PRODUCT_STAC9205D:
 +			nid = 0x01;
 +
 +			response = hdaudio_command(sc->sc_codec, nid,
 +			    HDAFG_GET_ANACTRL, 0x00);
 +			hda_delay(100);
 +
 +			response |= HDAFG_ANALOG_BEEP_EN;
 +
 +			hdaudio_command(sc->sc_codec, nid, HDAFG_SET_ANACTRL,
 +			    response);
 +			hda_delay(100);
 +			break;
 +		default:
 +			break;
 +		}
 +		break;
 +	case HDA_VENDOR_REALTEK:
 +		switch (sc->sc_product) {
 +		case HDA_PRODUCT_ALC269:
 +			/* The Panasonic Toughbook CF19 - Mk 5 uses a Realtek
 +			 * ALC231 that identifies as an ALC269.
 +			 * This unmutes the PCBEEP on the speaker.
 +			 */
 + 			nid = 0xf;
 +			response = hdaudio_command(sc->sc_codec, nid,
 +			    CORB_SET_AMPLIFIER_GAIN_MUTE, 0x7100);
 +			hda_delay(100);
 +			break;
 +		default:
 +			break;
 +		}
 +	default:
 +		break;
 +	}
 +}
 Index: src/sys/dev/pci/hdaudio/hdaudio_ids.h
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/pci/hdaudio/hdaudio_ids.h,v
 retrieving revision 1.3
 diff -u -r1.3 hdaudio_ids.h
 --- src/sys/dev/pci/hdaudio/hdaudio_ids.h	24 Oct 2011 22:20:59 -0000	1.3
 +++ src/sys/dev/pci/hdaudio/hdaudio_ids.h	19 Sep 2014 13:40:12 -0000
 @@ -43,6 +43,20 @@
  #define	HDA_VENDOR_INTEL		0x8086
  #define	HDA_VENDOR_SIGMATEL		0x8384

 +/* SigmaTel products */
 +#define	HDA_PRODUCT_STAC9200		0x7690
 +#define	HDA_PRODUCT_STAC9200D		0x7691
 +#define	HDA_PRODUCT_STAC9202		0x7632
 +#define	HDA_PRODUCT_STAC9202D		0x7633
 +#define	HDA_PRODUCT_STAC9204		0x76a2
 +#define	HDA_PRODUCT_STAC9204D		0x76a3
 +#define	HDA_PRODUCT_STAC9205		0x7698
 +#define	HDA_PRODUCT_STAC9205_2		0x76a0
 +#define	HDA_PRODUCT_STAC9205D		0x76a1
 +
 +/* Realtek Semiconductor products */
 +#define	HDA_PRODUCT_ALC269		0x0269
 +
  #define	HDA_PRODUCT_ANY			0xffff

  void	hdaudio_id2name(uint16_t, uint16_t, char *, size_t);

 Regards,

 Nat

From: "Nathanial Sloss" <nat@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/48495 CVS commit: src/sys/dev/pci/hdaudio
Date: Sun, 21 Sep 2014 10:41:23 +0000

 Module Name:	src
 Committed By:	nat
 Date:		Sun Sep 21 10:41:23 UTC 2014

 Modified Files:
 	src/sys/dev/pci/hdaudio: hdafg.c

 Log Message:
 Enable sysbeep(4) to be heard on speakers on Toughbook mk1 and mk5
 computers.  Also on computers with SigmaTel STAC 9200(D), 9202(D)
 9404(D), 9205(D) hdaudio controllers as well as Realtek ALC 231
 hdaudio controllers reporting as ALC 269.

 Addresses PR 45778.
 Addresses PR 48495.

 This commit was approved by christos@


 To generate a diff of this commit:
 cvs rdiff -u -r1.22 -r1.23 src/sys/dev/pci/hdaudio/hdafg.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: nat@NetBSD.org
State-Changed-When: Sun, 21 Sep 2014 10:54:04 +0000
State-Changed-Why:
Patch from PR applied.  Should be fixed now.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.