ALSA: firewire-motu: add proc node to show current statuc of clock and packet formats
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 22 Mar 2017 12:30:21 +0000 (21:30 +0900)
committerTakashi Iwai <tiwai@suse.de>
Tue, 28 Mar 2017 10:33:51 +0000 (12:33 +0200)
This commit adds a proc node for debugging purpose.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/firewire/motu/Makefile
sound/firewire/motu/motu-proc.c [new file with mode: 0644]
sound/firewire/motu/motu.c
sound/firewire/motu/motu.h

index 504a4f9dea6d47efdf26a5c1cb5bf6a2bc35b299..0eccbe215f5ea6e26dba32dfa89e3006c8b24875 100644 (file)
@@ -1,2 +1,3 @@
-snd-firewire-motu-objs := motu.o amdtp-motu.o motu-transaction.o motu-stream.o
+snd-firewire-motu-objs := motu.o amdtp-motu.o motu-transaction.o motu-stream.o \
+                         motu-proc.o
 obj-$(CONFIG_SND_FIREWIRE_MOTU) += snd-firewire-motu.o
diff --git a/sound/firewire/motu/motu-proc.c b/sound/firewire/motu/motu-proc.c
new file mode 100644 (file)
index 0000000..4edc064
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * motu-proc.c - a part of driver for MOTU FireWire series
+ *
+ * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
+ *
+ * Licensed under the terms of the GNU General Public License, version 2.
+ */
+
+#include "./motu.h"
+
+static const char *const clock_names[] = {
+       [SND_MOTU_CLOCK_SOURCE_INTERNAL] = "Internal",
+       [SND_MOTU_CLOCK_SOURCE_ADAT_ON_DSUB] = "ADAT on Dsub-9pin interface",
+       [SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT] = "ADAT on optical interface",
+       [SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A] = "ADAT on optical interface A",
+       [SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B] = "ADAT on optical interface B",
+       [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT] = "S/PDIF on optical interface",
+       [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A] = "S/PDIF on optical interface A",
+       [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B] = "S/PDIF on optical interface B",
+       [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX] = "S/PCIF on coaxial interface",
+       [SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR] = "AESEBU on XLR interface",
+       [SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC] = "Word clock on BNC interface",
+};
+
+static void proc_read_clock(struct snd_info_entry *entry,
+                           struct snd_info_buffer *buffer)
+{
+
+       struct snd_motu *motu = entry->private_data;
+       const struct snd_motu_protocol *const protocol = motu->spec->protocol;
+       unsigned int rate;
+       enum snd_motu_clock_source source;
+
+       if (protocol->get_clock_rate(motu, &rate) < 0)
+               return;
+       if (protocol->get_clock_source(motu, &source) < 0)
+               return;
+
+       snd_iprintf(buffer, "Rate:\t%d\n", rate);
+       snd_iprintf(buffer, "Source:\t%s\n", clock_names[source]);
+}
+
+static void proc_read_format(struct snd_info_entry *entry,
+                            struct snd_info_buffer *buffer)
+{
+       struct snd_motu *motu = entry->private_data;
+       const struct snd_motu_protocol *const protocol = motu->spec->protocol;
+       unsigned int mode;
+       struct snd_motu_packet_format *formats;
+       int i;
+
+       if (protocol->cache_packet_formats(motu) < 0)
+               return;
+
+       snd_iprintf(buffer, "tx:\tmsg\tfixed\tdiffered\n");
+       for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
+               mode = i >> 1;
+
+               formats = &motu->tx_packet_formats;
+               snd_iprintf(buffer,
+                           "%u:\t%u\t%u\t%u\n",
+                           snd_motu_clock_rates[i],
+                           formats->msg_chunks,
+                           formats->fixed_part_pcm_chunks[mode],
+                           formats->differed_part_pcm_chunks[mode]);
+       }
+
+       snd_iprintf(buffer, "rx:\tmsg\tfixed\tdiffered\n");
+       for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
+               mode = i >> 1;
+
+               formats = &motu->rx_packet_formats;
+               snd_iprintf(buffer,
+                           "%u:\t%u\t%u\t%u\n",
+                           snd_motu_clock_rates[i],
+                           formats->msg_chunks,
+                           formats->fixed_part_pcm_chunks[mode],
+                           formats->differed_part_pcm_chunks[mode]);
+       }
+}
+
+static void add_node(struct snd_motu *motu, struct snd_info_entry *root,
+                    const char *name,
+                    void (*op)(struct snd_info_entry *e,
+                               struct snd_info_buffer *b))
+{
+       struct snd_info_entry *entry;
+
+       entry = snd_info_create_card_entry(motu->card, name, root);
+       if (entry == NULL)
+               return;
+
+       snd_info_set_text_ops(entry, motu, op);
+       if (snd_info_register(entry) < 0)
+               snd_info_free_entry(entry);
+}
+
+void snd_motu_proc_init(struct snd_motu *motu)
+{
+       struct snd_info_entry *root;
+
+       /*
+        * All nodes are automatically removed at snd_card_disconnect(),
+        * by following to link list.
+        */
+       root = snd_info_create_card_entry(motu->card, "firewire",
+                                         motu->card->proc_root);
+       if (root == NULL)
+               return;
+       root->mode = S_IFDIR | S_IRUGO | S_IXUGO;
+       if (snd_info_register(root) < 0) {
+               snd_info_free_entry(root);
+               return;
+       }
+
+       add_node(motu, root, "clock", proc_read_clock);
+       add_node(motu, root, "format", proc_read_format);
+}
index 9d52238d898e24e1fcab5a60315e83abe30bde47..cbf4ed0f523468f15e208878e4831379a46425f7 100644 (file)
@@ -97,6 +97,8 @@ static void do_registration(struct work_struct *work)
        if (err < 0)
                goto error;
 
+       snd_motu_proc_init(motu);
+
        err = snd_card_register(motu->card);
        if (err < 0)
                goto error;
index 90d274167a4a3422aa7a0eb6e4b4493be0c54ef9..4d079d66cf7718e3f6cca2c3efd9eb571c34f754 100644 (file)
@@ -20,6 +20,7 @@
 #include <sound/control.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
+#include <sound/info.h>
 
 #include "../lib.h"
 #include "../amdtp-stream.h"
@@ -128,4 +129,6 @@ int snd_motu_stream_init_duplex(struct snd_motu *motu);
 void snd_motu_stream_destroy_duplex(struct snd_motu *motu);
 int snd_motu_stream_start_duplex(struct snd_motu *motu, unsigned int rate);
 void snd_motu_stream_stop_duplex(struct snd_motu *motu);
+
+void snd_motu_proc_init(struct snd_motu *motu);
 #endif