Module Name: src
Committed By: martin
Date: Sat Jun 20 16:15:45 UTC 2020
Modified Files:
src/usr.sbin/hdaudioctl [netbsd-7]: graph.c hdaudioctl.8 hdaudioctl.c
hdaudioctl.h
Log Message:
Pull up following revision(s) (requested by sborrill in ticket #1736):
usr.sbin/hdaudioctl/hdaudioctl.8: revision 1.7
usr.sbin/hdaudioctl/graph.c: revision 1.5
usr.sbin/hdaudioctl/hdaudioctl.c: revision 1.3
usr.sbin/hdaudioctl/hdaudioctl.c: revision 1.4
usr.sbin/hdaudioctl/hdaudioctl.h: revision 1.3
Add show subcommand that displays the codec configuration in
human-readable tabulated form
Nix trailing whitespace.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.24.1 src/usr.sbin/hdaudioctl/graph.c
cvs rdiff -u -r1.6 -r1.6.4.1 src/usr.sbin/hdaudioctl/hdaudioctl.8
cvs rdiff -u -r1.1 -r1.1.28.1 src/usr.sbin/hdaudioctl/hdaudioctl.c
cvs rdiff -u -r1.2 -r1.2.20.1 src/usr.sbin/hdaudioctl/hdaudioctl.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/hdaudioctl/graph.c
diff -u src/usr.sbin/hdaudioctl/graph.c:1.2 src/usr.sbin/hdaudioctl/graph.c:1.2.24.1
--- src/usr.sbin/hdaudioctl/graph.c:1.2 Tue Aug 10 13:52:13 2010
+++ src/usr.sbin/hdaudioctl/graph.c Sat Jun 20 16:15:45 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: graph.c,v 1.2 2010/08/10 13:52:13 joerg Exp $ */
+/* $NetBSD: graph.c,v 1.2.24.1 2020/06/20 16:15:45 martin Exp $ */
/*
* Copyright (c) 2009 Precedence Technologies Ltd <[email protected]>
@@ -45,13 +45,6 @@
#include "hdaudioctl.h"
-static const char *pin_devices[16] = {
- "Line Out", "Speaker", "HP Out", "CD",
- "SPDIF Out", "Digital Out", "Modem Line", "Modem Handset",
- "Line In", "AUX", "Mic In", "Telephony",
- "SPDIF In", "Digital In", "Reserved", "Other"
-};
-
int
hdaudioctl_graph(int fd, int argc, char *argv[])
{
Index: src/usr.sbin/hdaudioctl/hdaudioctl.8
diff -u src/usr.sbin/hdaudioctl/hdaudioctl.8:1.6 src/usr.sbin/hdaudioctl/hdaudioctl.8:1.6.4.1
--- src/usr.sbin/hdaudioctl/hdaudioctl.8:1.6 Tue Mar 18 18:20:46 2014
+++ src/usr.sbin/hdaudioctl/hdaudioctl.8 Sat Jun 20 16:15:45 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: hdaudioctl.8,v 1.6 2014/03/18 18:20:46 riastradh Exp $
+.\" $NetBSD: hdaudioctl.8,v 1.6.4.1 2020/06/20 16:15:45 martin Exp $
.\"
.\" Copyright (c) 2009 Precedence Technologies Ltd <[email protected]>
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd October 6, 2009
+.Dd June 12, 2020
.Dt HDAUDIOCTL 8
.Os
.Sh NAME
@@ -55,6 +55,8 @@ Valid commands are:
For each child codec of the chosen
.Xr hdaudio 4
device, display the nid, vendor, product, subsystem and device IDs.
+.It show
+Retrieve and display the current codec configuration in human-readable form.
.It get Ar codecid Ar nid
Retrieve and display the current codec configuration as a
.Xr proplib 3
Index: src/usr.sbin/hdaudioctl/hdaudioctl.c
diff -u src/usr.sbin/hdaudioctl/hdaudioctl.c:1.1 src/usr.sbin/hdaudioctl/hdaudioctl.c:1.1.28.1
--- src/usr.sbin/hdaudioctl/hdaudioctl.c:1.1 Sun Oct 11 08:57:54 2009
+++ src/usr.sbin/hdaudioctl/hdaudioctl.c Sat Jun 20 16:15:45 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hdaudioctl.c,v 1.1 2009/10/11 08:57:54 sborrill Exp $ */
+/* $NetBSD: hdaudioctl.c,v 1.1.28.1 2020/06/20 16:15:45 martin Exp $ */
/*
* Copyright (c) 2009 Precedence Technologies Ltd <[email protected]>
@@ -49,13 +49,54 @@
#define DEVPATH_HDAUDIO "/dev/hdaudio0"
+const char *pin_devices[16] = {
+ "Line out", "Speaker", "Headphones", "CD",
+ "SPDIF Out", "Digital Out", "Modem Line", "Modem Handset",
+ "Line In", "AUX", "Mic In", "Telephony",
+ "SPDIF In", "Digital In", "Reserved", "Other"
+};
+static const char *pin_jacks[16] = {
+ "Unknown", "1/8\"", "1/4\"", "ATAPI",
+ "RCA", "Optic", "Digital", "Analog",
+ "DIN", "XLR", "RJ-11", "Combo",
+ "0xC", "0xD", "0xE", "Other"
+};
+static const char *pin_connections[4] = {
+ "Jack", "None", "Fixed", "Both"
+};
+static const char *pin_colors[16] = {
+ "Unknown", "Black", "Grey", "Blue",
+ "Green", "Red", "Orange", "Yellow",
+ "Purple", "Pink", "Res. A", "Res. B",
+ "Res. C", "Res. D", "White", "Other"
+};
+static const char *pin_locations[64] = {
+ "0x00", "Rear", "Front", "Left",
+ "Right", "Top", "Bottom", "Rear-panel",
+ "Drive-bay", "0x09", "0x0a", "0x0b",
+ "0x0c", "0x0d", "0x0e", "0x0f",
+ "Internal", "0x11", "0x12", "0x13",
+ "0x14", "0x15", "0x16", "Riser",
+ "0x18", "Onboard", "0x1a", "0x1b",
+ "0x1c", "0x1d", "0x1e", "0x1f",
+ "External", "Ext-Rear", "Ext-Front", "Ext-Left",
+ "Ext-Right", "Ext-Top", "Ext-Bottom", "0x07",
+ "0x28", "0x29", "0x2a", "0x2b",
+ "0x2c", "0x2d", "0x2e", "0x2f",
+ "Other", "0x31", "0x32", "0x33",
+ "0x34", "0x35", "Other-Bott", "Lid-In",
+ "Lid-Out", "0x39", "0x3a", "0x3b",
+ "0x3c", "0x3d", "0x3e", "0x3f"
+};
+
void
usage(void)
{
const char *prog;
prog = getprogname();
-
+
fprintf(stderr, "usage: %s [-f dev] list\n", prog);
+ fprintf(stderr, " %s [-f dev] show <codecid> <nid>\n", prog);
fprintf(stderr, " %s [-f dev] get <codecid> <nid>\n", prog);
fprintf(stderr, " %s [-f dev] set <codecid> <nid> [plist]\n",
prog);
@@ -203,6 +244,78 @@ hdaudioctl_set(int fd, int argc, char *a
return 0;
}
+/* Based on page 178 onwards:
+ * https://www.intel.com/content/dam/www/public/us/en/documents/product-specifications/high-definition-audio-specification.pdf
+ * 31:30 = Port connectivity
+ * 29:24 = Location
+ * 23:20 = Default device
+ * 19:16 = Connection type
+ * 15:12 = Color
+ * 11:8 = Misc
+ * 7:4 = Default association
+ * 3:0 = Sequence
+ */
+
+static int
+hdaudioctl_show(int fd, int argc, char *argv[])
+{
+ prop_dictionary_t request, response, dict;
+ prop_array_t array;
+ prop_object_iterator_t iter;
+ prop_object_t obj;
+ uint16_t nid, codecid;
+ uint32_t config;
+ int error;
+ const char *device, *conn, *jack, *loc, *color;
+ if (argc != 2)
+ usage();
+
+ codecid = strtol(argv[0], NULL, 0);
+ nid = strtol(argv[1], NULL, 0);
+
+ request = prop_dictionary_create();
+ if (request == NULL) {
+ fprintf(stderr, "out of memory\n");
+ return ENOMEM;
+ }
+
+ prop_dictionary_set_uint16(request, "codecid", codecid);
+ prop_dictionary_set_uint16(request, "nid", nid);
+
+ error = prop_dictionary_sendrecv_ioctl(request, fd,
+ HDAUDIO_FGRP_GETCONFIG, &response);
+ if (error != 0) {
+ perror("HDAUDIO_FGRP_GETCONFIG failed");
+ return error;
+ }
+
+ array = prop_dictionary_get(response, "pin-config");
+ iter = prop_array_iterator(array);
+ prop_object_iterator_reset(iter);
+ printf("nid Data As Seq Device Conn Jack "
+ "Location Color Misc\n");
+ printf("================================================="
+ "=======================\n");
+ while ((obj = prop_object_iterator_next(iter)) != NULL) {
+ dict = (prop_dictionary_t)obj;
+ prop_dictionary_get_uint32(dict, "config", &config);
+ prop_dictionary_get_uint16(dict, "nid", &nid);
+ device = pin_devices[(config >> 20U) & 0xf];
+ conn = pin_connections[(config >> 30U) & 0x3];
+ jack = pin_jacks[(config >> 16) & 0xf];
+ loc = pin_locations[(config >> 24) & 0x3f];
+ color = pin_colors[(config >> 12) & 0xf];
+ printf("%3d %08X %2d %3d %-14s %-5s %-7s %-10s %-7s %4X\n",
+ nid, config, ((config >> 4U) & 0xf), (config & 0xf),
+ device, conn, jack, loc, color, ((config >> 8U) & 0xf));
+ }
+ prop_object_release(array);
+ prop_object_release(response);
+ prop_object_release(request);
+
+ return 0;
+}
+
int
main(int argc, char *argv[])
@@ -210,7 +323,7 @@ main(int argc, char *argv[])
int fd, error;
int ch;
const char *devpath = DEVPATH_HDAUDIO;
-
+
while ((ch = getopt(argc, argv, "f:h")) != -1) {
switch (ch) {
case 'f':
@@ -234,7 +347,7 @@ main(int argc, char *argv[])
strerror(errno));
return EXIT_FAILURE;
}
-
+
error = 0;
if (strcmp(argv[0], "list") == 0)
error = hdaudioctl_list(fd);
@@ -244,6 +357,8 @@ main(int argc, char *argv[])
error = hdaudioctl_set(fd, argc - 1, argv + 1);
else if (strcmp(argv[0], "graph") == 0)
error = hdaudioctl_graph(fd, argc - 1, argv + 1);
+ else if (strcmp(argv[0], "show") == 0)
+ error = hdaudioctl_show(fd, argc - 1, argv + 1);
else
usage();
Index: src/usr.sbin/hdaudioctl/hdaudioctl.h
diff -u src/usr.sbin/hdaudioctl/hdaudioctl.h:1.2 src/usr.sbin/hdaudioctl/hdaudioctl.h:1.2.20.1
--- src/usr.sbin/hdaudioctl/hdaudioctl.h:1.2 Wed Aug 31 13:32:37 2011
+++ src/usr.sbin/hdaudioctl/hdaudioctl.h Sat Jun 20 16:15:45 2020
@@ -1,2 +1,3 @@
extern int hdaudioctl_graph(int fd, int argc, char *argv[]);
__dead extern void usage(void);
+extern const char *pin_devices[];