xref: /openbmc/linux/sound/firewire/motu/motu-proc.c (revision f8e17c17)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * motu-proc.c - a part of driver for MOTU FireWire series
4  *
5  * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6  */
7 
8 #include "./motu.h"
9 
10 static 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",
19 	[SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX] = "S/PDIF on coaxial interface",
20 	[SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR] = "AESEBU on XLR interface",
21 	[SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC] = "Word clock on BNC interface",
22 	[SND_MOTU_CLOCK_SOURCE_SPH] = "Source packet header",
23 	[SND_MOTU_CLOCK_SOURCE_UNKNOWN] = "Unknown",
24 };
25 
26 static 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;
31 	const struct snd_motu_protocol *const protocol = motu->spec->protocol;
32 	unsigned int rate;
33 	enum snd_motu_clock_source source;
34 
35 	if (protocol->get_clock_rate(motu, &rate) < 0)
36 		return;
37 	if (protocol->get_clock_source(motu, &source) < 0)
38 		return;
39 
40 	snd_iprintf(buffer, "Rate:\t%d\n", rate);
41 	snd_iprintf(buffer, "Source:\t%s\n", clock_names[source]);
42 }
43 
44 static void proc_read_format(struct snd_info_entry *entry,
45 			     struct snd_info_buffer *buffer)
46 {
47 	struct snd_motu *motu = entry->private_data;
48 	const struct snd_motu_protocol *const protocol = motu->spec->protocol;
49 	unsigned int mode;
50 	struct snd_motu_packet_format *formats;
51 	int i;
52 
53 	if (protocol->cache_packet_formats(motu) < 0)
54 		return;
55 
56 	snd_iprintf(buffer, "tx:\tmsg\tfixed\tdiffered\n");
57 	for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
58 		mode = i >> 1;
59 
60 		formats = &motu->tx_packet_formats;
61 		snd_iprintf(buffer,
62 			    "%u:\t%u\t%u\t%u\n",
63 			    snd_motu_clock_rates[i],
64 			    formats->msg_chunks,
65 			    formats->fixed_part_pcm_chunks[mode],
66 			    formats->differed_part_pcm_chunks[mode]);
67 	}
68 
69 	snd_iprintf(buffer, "rx:\tmsg\tfixed\tdiffered\n");
70 	for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
71 		mode = i >> 1;
72 
73 		formats = &motu->rx_packet_formats;
74 		snd_iprintf(buffer,
75 			    "%u:\t%u\t%u\t%u\n",
76 			    snd_motu_clock_rates[i],
77 			    formats->msg_chunks,
78 			    formats->fixed_part_pcm_chunks[mode],
79 			    formats->differed_part_pcm_chunks[mode]);
80 	}
81 }
82 
83 static void add_node(struct snd_motu *motu, struct snd_info_entry *root,
84 		     const char *name,
85 		     void (*op)(struct snd_info_entry *e,
86 				struct snd_info_buffer *b))
87 {
88 	struct snd_info_entry *entry;
89 
90 	entry = snd_info_create_card_entry(motu->card, name, root);
91 	if (entry)
92 		snd_info_set_text_ops(entry, motu, op);
93 }
94 
95 void snd_motu_proc_init(struct snd_motu *motu)
96 {
97 	struct snd_info_entry *root;
98 
99 	/*
100 	 * All nodes are automatically removed at snd_card_disconnect(),
101 	 * by following to link list.
102 	 */
103 	root = snd_info_create_card_entry(motu->card, "firewire",
104 					  motu->card->proc_root);
105 	if (root == NULL)
106 		return;
107 	root->mode = S_IFDIR | 0555;
108 
109 	add_node(motu, root, "clock", proc_read_clock);
110 	add_node(motu, root, "format", proc_read_format);
111 }
112