xref: /linux/sound/firewire/motu/motu-proc.c (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1da607e19SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
24638ec6eSTakashi Sakamoto /*
34638ec6eSTakashi Sakamoto  * motu-proc.c - a part of driver for MOTU FireWire series
44638ec6eSTakashi Sakamoto  *
54638ec6eSTakashi Sakamoto  * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
64638ec6eSTakashi Sakamoto  */
74638ec6eSTakashi Sakamoto 
84638ec6eSTakashi Sakamoto #include "./motu.h"
94638ec6eSTakashi Sakamoto 
104638ec6eSTakashi Sakamoto static const char *const clock_names[] = {
114638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_INTERNAL] = "Internal",
124638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_ADAT_ON_DSUB] = "ADAT on Dsub-9pin interface",
134638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT] = "ADAT on optical interface",
144638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A] = "ADAT on optical interface A",
154638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B] = "ADAT on optical interface B",
164638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT] = "S/PDIF on optical interface",
174638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A] = "S/PDIF on optical interface A",
184638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B] = "S/PDIF on optical interface B",
190929249eSTakashi Iwai 	[SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX] = "S/PDIF on coaxial interface",
204638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR] = "AESEBU on XLR interface",
214638ec6eSTakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC] = "Word clock on BNC interface",
223f58f004STakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_SPH] = "Source packet header",
231ef2ff94STakashi Sakamoto 	[SND_MOTU_CLOCK_SOURCE_UNKNOWN] = "Unknown",
244638ec6eSTakashi Sakamoto };
254638ec6eSTakashi Sakamoto 
proc_read_clock(struct snd_info_entry * entry,struct snd_info_buffer * buffer)264638ec6eSTakashi Sakamoto static void proc_read_clock(struct snd_info_entry *entry,
274638ec6eSTakashi Sakamoto 			    struct snd_info_buffer *buffer)
284638ec6eSTakashi Sakamoto {
294638ec6eSTakashi Sakamoto 
304638ec6eSTakashi Sakamoto 	struct snd_motu *motu = entry->private_data;
314638ec6eSTakashi Sakamoto 	unsigned int rate;
324638ec6eSTakashi Sakamoto 	enum snd_motu_clock_source source;
334638ec6eSTakashi Sakamoto 
34ff222b7eSTakashi Sakamoto 	if (snd_motu_protocol_get_clock_rate(motu, &rate) < 0)
354638ec6eSTakashi Sakamoto 		return;
36ff222b7eSTakashi Sakamoto 	if (snd_motu_protocol_get_clock_source(motu, &source) < 0)
374638ec6eSTakashi Sakamoto 		return;
384638ec6eSTakashi Sakamoto 
394638ec6eSTakashi Sakamoto 	snd_iprintf(buffer, "Rate:\t%d\n", rate);
404638ec6eSTakashi Sakamoto 	snd_iprintf(buffer, "Source:\t%s\n", clock_names[source]);
414638ec6eSTakashi Sakamoto }
424638ec6eSTakashi Sakamoto 
proc_read_format(struct snd_info_entry * entry,struct snd_info_buffer * buffer)434638ec6eSTakashi Sakamoto static void proc_read_format(struct snd_info_entry *entry,
444638ec6eSTakashi Sakamoto 			     struct snd_info_buffer *buffer)
454638ec6eSTakashi Sakamoto {
464638ec6eSTakashi Sakamoto 	struct snd_motu *motu = entry->private_data;
474638ec6eSTakashi Sakamoto 	unsigned int mode;
484638ec6eSTakashi Sakamoto 	struct snd_motu_packet_format *formats;
494638ec6eSTakashi Sakamoto 	int i;
504638ec6eSTakashi Sakamoto 
51ff222b7eSTakashi Sakamoto 	if (snd_motu_protocol_cache_packet_formats(motu) < 0)
524638ec6eSTakashi Sakamoto 		return;
534638ec6eSTakashi Sakamoto 
54*9883b385STakashi Sakamoto 	snd_iprintf(buffer, "tx:\tmsg\tfixed\ttotal\n");
554638ec6eSTakashi Sakamoto 	for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
564638ec6eSTakashi Sakamoto 		mode = i >> 1;
574638ec6eSTakashi Sakamoto 
584638ec6eSTakashi Sakamoto 		formats = &motu->tx_packet_formats;
594638ec6eSTakashi Sakamoto 		snd_iprintf(buffer,
604638ec6eSTakashi Sakamoto 			    "%u:\t%u\t%u\t%u\n",
614638ec6eSTakashi Sakamoto 			    snd_motu_clock_rates[i],
624638ec6eSTakashi Sakamoto 			    formats->msg_chunks,
63*9883b385STakashi Sakamoto 			    motu->spec->tx_fixed_pcm_chunks[mode],
64*9883b385STakashi Sakamoto 			    formats->pcm_chunks[mode]);
654638ec6eSTakashi Sakamoto 	}
664638ec6eSTakashi Sakamoto 
67*9883b385STakashi Sakamoto 	snd_iprintf(buffer, "rx:\tmsg\tfixed\ttotal\n");
684638ec6eSTakashi Sakamoto 	for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
694638ec6eSTakashi Sakamoto 		mode = i >> 1;
704638ec6eSTakashi Sakamoto 
714638ec6eSTakashi Sakamoto 		formats = &motu->rx_packet_formats;
724638ec6eSTakashi Sakamoto 		snd_iprintf(buffer,
734638ec6eSTakashi Sakamoto 			    "%u:\t%u\t%u\t%u\n",
744638ec6eSTakashi Sakamoto 			    snd_motu_clock_rates[i],
754638ec6eSTakashi Sakamoto 			    formats->msg_chunks,
76*9883b385STakashi Sakamoto 			    motu->spec->rx_fixed_pcm_chunks[mode],
77*9883b385STakashi Sakamoto 			    formats->pcm_chunks[mode]);
784638ec6eSTakashi Sakamoto 	}
794638ec6eSTakashi Sakamoto }
804638ec6eSTakashi Sakamoto 
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))814638ec6eSTakashi Sakamoto static void add_node(struct snd_motu *motu, struct snd_info_entry *root,
824638ec6eSTakashi Sakamoto 		     const char *name,
834638ec6eSTakashi Sakamoto 		     void (*op)(struct snd_info_entry *e,
844638ec6eSTakashi Sakamoto 				struct snd_info_buffer *b))
854638ec6eSTakashi Sakamoto {
864638ec6eSTakashi Sakamoto 	struct snd_info_entry *entry;
874638ec6eSTakashi Sakamoto 
884638ec6eSTakashi Sakamoto 	entry = snd_info_create_card_entry(motu->card, name, root);
890c298bdcSTakashi Iwai 	if (entry)
904638ec6eSTakashi Sakamoto 		snd_info_set_text_ops(entry, motu, op);
914638ec6eSTakashi Sakamoto }
924638ec6eSTakashi Sakamoto 
snd_motu_proc_init(struct snd_motu * motu)934638ec6eSTakashi Sakamoto void snd_motu_proc_init(struct snd_motu *motu)
944638ec6eSTakashi Sakamoto {
954638ec6eSTakashi Sakamoto 	struct snd_info_entry *root;
964638ec6eSTakashi Sakamoto 
974638ec6eSTakashi Sakamoto 	/*
984638ec6eSTakashi Sakamoto 	 * All nodes are automatically removed at snd_card_disconnect(),
994638ec6eSTakashi Sakamoto 	 * by following to link list.
1004638ec6eSTakashi Sakamoto 	 */
1014638ec6eSTakashi Sakamoto 	root = snd_info_create_card_entry(motu->card, "firewire",
1024638ec6eSTakashi Sakamoto 					  motu->card->proc_root);
1034638ec6eSTakashi Sakamoto 	if (root == NULL)
1044638ec6eSTakashi Sakamoto 		return;
1056a73cf46SJoe Perches 	root->mode = S_IFDIR | 0555;
1064638ec6eSTakashi Sakamoto 
1074638ec6eSTakashi Sakamoto 	add_node(motu, root, "clock", proc_read_clock);
1084638ec6eSTakashi Sakamoto 	add_node(motu, root, "format", proc_read_format);
1094638ec6eSTakashi Sakamoto }
110