blob: f009cf7aa074ce1233f810c95708f2cd05c708b9 [file] [log] [blame]
Thomas Gleixnerda607e12019-05-29 16:57:59 -07001// SPDX-License-Identifier: GPL-2.0-only
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +09002/*
3 * motu-proc.c - a part of driver for MOTU FireWire series
4 *
5 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +09006 */
7
8#include "./motu.h"
9
10static const char *const clock_names[] = {
11 [SND_MOTU_CLOCK_SOURCE_INTERNAL] = "Internal",
12 [SND_MOTU_CLOCK_SOURCE_ADAT_ON_DSUB] = "ADAT on Dsub-9pin interface",
13 [SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT] = "ADAT on optical interface",
14 [SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A] = "ADAT on optical interface A",
15 [SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B] = "ADAT on optical interface B",
16 [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT] = "S/PDIF on optical interface",
17 [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A] = "S/PDIF on optical interface A",
18 [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B] = "S/PDIF on optical interface B",
Takashi Iwai09292492019-10-30 11:09:21 +010019 [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX] = "S/PDIF on coaxial interface",
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090020 [SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR] = "AESEBU on XLR interface",
21 [SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC] = "Word clock on BNC interface",
Takashi Sakamoto3f58f002019-10-30 17:06:41 +090022 [SND_MOTU_CLOCK_SOURCE_SPH] = "Source packet header",
Takashi Sakamoto1ef2ff92019-10-30 17:06:40 +090023 [SND_MOTU_CLOCK_SOURCE_UNKNOWN] = "Unknown",
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090024};
25
26static void proc_read_clock(struct snd_info_entry *entry,
27 struct snd_info_buffer *buffer)
28{
29
30 struct snd_motu *motu = entry->private_data;
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090031 unsigned int rate;
32 enum snd_motu_clock_source source;
33
Takashi Sakamotoff222b72020-05-19 20:16:31 +090034 if (snd_motu_protocol_get_clock_rate(motu, &rate) < 0)
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090035 return;
Takashi Sakamotoff222b72020-05-19 20:16:31 +090036 if (snd_motu_protocol_get_clock_source(motu, &source) < 0)
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090037 return;
38
39 snd_iprintf(buffer, "Rate:\t%d\n", rate);
40 snd_iprintf(buffer, "Source:\t%s\n", clock_names[source]);
41}
42
43static void proc_read_format(struct snd_info_entry *entry,
44 struct snd_info_buffer *buffer)
45{
46 struct snd_motu *motu = entry->private_data;
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090047 unsigned int mode;
48 struct snd_motu_packet_format *formats;
49 int i;
50
Takashi Sakamotoff222b72020-05-19 20:16:31 +090051 if (snd_motu_protocol_cache_packet_formats(motu) < 0)
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090052 return;
53
Takashi Sakamoto9883b382020-05-19 20:16:36 +090054 snd_iprintf(buffer, "tx:\tmsg\tfixed\ttotal\n");
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090055 for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
56 mode = i >> 1;
57
58 formats = &motu->tx_packet_formats;
59 snd_iprintf(buffer,
60 "%u:\t%u\t%u\t%u\n",
61 snd_motu_clock_rates[i],
62 formats->msg_chunks,
Takashi Sakamoto9883b382020-05-19 20:16:36 +090063 motu->spec->tx_fixed_pcm_chunks[mode],
64 formats->pcm_chunks[mode]);
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090065 }
66
Takashi Sakamoto9883b382020-05-19 20:16:36 +090067 snd_iprintf(buffer, "rx:\tmsg\tfixed\ttotal\n");
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090068 for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
69 mode = i >> 1;
70
71 formats = &motu->rx_packet_formats;
72 snd_iprintf(buffer,
73 "%u:\t%u\t%u\t%u\n",
74 snd_motu_clock_rates[i],
75 formats->msg_chunks,
Takashi Sakamoto9883b382020-05-19 20:16:36 +090076 motu->spec->rx_fixed_pcm_chunks[mode],
77 formats->pcm_chunks[mode]);
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090078 }
79}
80
81static void add_node(struct snd_motu *motu, struct snd_info_entry *root,
82 const char *name,
83 void (*op)(struct snd_info_entry *e,
84 struct snd_info_buffer *b))
85{
86 struct snd_info_entry *entry;
87
88 entry = snd_info_create_card_entry(motu->card, name, root);
Takashi Iwai0c298bd2019-02-05 12:34:12 +010089 if (entry)
90 snd_info_set_text_ops(entry, motu, op);
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090091}
92
93void snd_motu_proc_init(struct snd_motu *motu)
94{
95 struct snd_info_entry *root;
96
97 /*
98 * All nodes are automatically removed at snd_card_disconnect(),
99 * by following to link list.
100 */
101 root = snd_info_create_card_entry(motu->card, "firewire",
102 motu->card->proc_root);
103 if (root == NULL)
104 return;
Joe Perches6a73cf42018-05-23 12:20:59 -0700105 root->mode = S_IFDIR | 0555;
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +0900106
107 add_node(motu, root, "clock", proc_read_clock);
108 add_node(motu, root, "format", proc_read_format);
109}