blob: 335da64506e09b22faf99ea391f1e1ab25a43989 [file] [log] [blame]
Takashi Sakamotoad9697b2014-04-25 22:45:17 +09001/*
2 * bebob_proc.c - a part of driver for BeBoB based devices
3 *
4 * Copyright (c) 2013-2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#include "./bebob.h"
10
11/* contents of information register */
12struct hw_info {
13 u64 manufacturer;
14 u32 protocol_ver;
15 u32 bld_ver;
16 u32 guid[2];
17 u32 model_id;
18 u32 model_rev;
19 u64 fw_date;
20 u64 fw_time;
21 u32 fw_id;
22 u32 fw_ver;
23 u32 base_addr;
24 u32 max_size;
25 u64 bld_date;
26 u64 bld_time;
27/* may not used in product
28 u64 dbg_date;
29 u64 dbg_time;
30 u32 dbg_id;
31 u32 dbg_version;
32*/
33} __packed;
34
35static void
36proc_read_hw_info(struct snd_info_entry *entry,
37 struct snd_info_buffer *buffer)
38{
39 struct snd_bebob *bebob = entry->private_data;
40 struct hw_info *info;
41
42 info = kzalloc(sizeof(struct hw_info), GFP_KERNEL);
43 if (info == NULL)
44 return;
45
46 if (snd_bebob_read_block(bebob->unit, 0,
47 info, sizeof(struct hw_info)) < 0)
48 goto end;
49
50 snd_iprintf(buffer, "Manufacturer:\t%.8s\n",
51 (char *)&info->manufacturer);
52 snd_iprintf(buffer, "Protocol Ver:\t%d\n", info->protocol_ver);
53 snd_iprintf(buffer, "Build Ver:\t%d\n", info->bld_ver);
54 snd_iprintf(buffer, "GUID:\t\t0x%.8X%.8X\n",
55 info->guid[0], info->guid[1]);
56 snd_iprintf(buffer, "Model ID:\t0x%02X\n", info->model_id);
57 snd_iprintf(buffer, "Model Rev:\t%d\n", info->model_rev);
58 snd_iprintf(buffer, "Firmware Date:\t%.8s\n", (char *)&info->fw_date);
59 snd_iprintf(buffer, "Firmware Time:\t%.8s\n", (char *)&info->fw_time);
60 snd_iprintf(buffer, "Firmware ID:\t0x%X\n", info->fw_id);
61 snd_iprintf(buffer, "Firmware Ver:\t%d\n", info->fw_ver);
62 snd_iprintf(buffer, "Base Addr:\t0x%X\n", info->base_addr);
63 snd_iprintf(buffer, "Max Size:\t%d\n", info->max_size);
64 snd_iprintf(buffer, "Loader Date:\t%.8s\n", (char *)&info->bld_date);
65 snd_iprintf(buffer, "Loader Time:\t%.8s\n", (char *)&info->bld_time);
66
67end:
68 kfree(info);
69}
70
71static void
Takashi Sakamoto1fc95222014-04-25 22:45:21 +090072proc_read_meters(struct snd_info_entry *entry,
73 struct snd_info_buffer *buffer)
74{
75 struct snd_bebob *bebob = entry->private_data;
76 struct snd_bebob_meter_spec *spec = bebob->spec->meter;
77 u32 *buf;
78 unsigned int i, c, channels, size;
79
80 if (spec == NULL)
81 return;
82
83 channels = spec->num * 2;
84 size = channels * sizeof(u32);
85 buf = kmalloc(size, GFP_KERNEL);
86 if (buf == NULL)
87 return;
88
89 if (spec->get(bebob, buf, size) < 0)
90 goto end;
91
92 for (i = 0, c = 1; i < channels; i++) {
93 snd_iprintf(buffer, "%s %d:\t%d\n",
94 spec->labels[i / 2], c++, buf[i]);
95 if ((i + 1 < channels - 1) &&
96 (strcmp(spec->labels[i / 2],
97 spec->labels[(i + 1) / 2]) != 0))
98 c = 1;
99 }
100end:
101 kfree(buf);
102}
103
104static void
Takashi Sakamotoad9697b2014-04-25 22:45:17 +0900105proc_read_formation(struct snd_info_entry *entry,
106 struct snd_info_buffer *buffer)
107{
108 struct snd_bebob *bebob = entry->private_data;
109 struct snd_bebob_stream_formation *formation;
110 unsigned int i;
111
112 snd_iprintf(buffer, "Output Stream from device:\n");
113 snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
114 formation = bebob->tx_stream_formations;
115 for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
116 snd_iprintf(buffer,
117 "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],
118 formation[i].pcm, formation[i].midi);
119 }
120
121 snd_iprintf(buffer, "Input Stream to device:\n");
122 snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
123 formation = bebob->rx_stream_formations;
124 for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
125 snd_iprintf(buffer,
126 "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],
127 formation[i].pcm, formation[i].midi);
128 }
129}
130
131static void
132proc_read_clock(struct snd_info_entry *entry,
133 struct snd_info_buffer *buffer)
134{
135 struct snd_bebob *bebob = entry->private_data;
Takashi Sakamoto1fc95222014-04-25 22:45:21 +0900136 struct snd_bebob_rate_spec *rate_spec = bebob->spec->rate;
137 struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
138 unsigned int rate, id;
Takashi Sakamotoad9697b2014-04-25 22:45:17 +0900139 bool internal;
140
Takashi Sakamoto1fc95222014-04-25 22:45:21 +0900141 if (rate_spec->get(bebob, &rate) >= 0)
Takashi Sakamotoad9697b2014-04-25 22:45:17 +0900142 snd_iprintf(buffer, "Sampling rate: %d\n", rate);
143
Takashi Sakamoto1fc95222014-04-25 22:45:21 +0900144 if (clk_spec) {
145 if (clk_spec->get(bebob, &id) >= 0)
146 snd_iprintf(buffer, "Clock Source: %s\n",
147 clk_spec->labels[id]);
148 } else {
149 if (snd_bebob_stream_check_internal_clock(bebob,
150 &internal) >= 0)
151 snd_iprintf(buffer, "Clock Source: %s (MSU-dest: %d)\n",
152 (internal) ? "Internal" : "External",
153 bebob->sync_input_plug);
154 }
Takashi Sakamotoad9697b2014-04-25 22:45:17 +0900155}
156
157static void
158add_node(struct snd_bebob *bebob, struct snd_info_entry *root, const char *name,
159 void (*op)(struct snd_info_entry *e, struct snd_info_buffer *b))
160{
161 struct snd_info_entry *entry;
162
163 entry = snd_info_create_card_entry(bebob->card, name, root);
164 if (entry == NULL)
165 return;
166
167 snd_info_set_text_ops(entry, bebob, op);
168 if (snd_info_register(entry) < 0)
169 snd_info_free_entry(entry);
170}
171
172void snd_bebob_proc_init(struct snd_bebob *bebob)
173{
174 struct snd_info_entry *root;
175
176 /*
177 * All nodes are automatically removed at snd_card_disconnect(),
178 * by following to link list.
179 */
180 root = snd_info_create_card_entry(bebob->card, "firewire",
181 bebob->card->proc_root);
182 if (root == NULL)
183 return;
184 root->mode = S_IFDIR | S_IRUGO | S_IXUGO;
185 if (snd_info_register(root) < 0) {
186 snd_info_free_entry(root);
187 return;
188 }
189
190 add_node(bebob, root, "clock", proc_read_clock);
191 add_node(bebob, root, "firmware", proc_read_hw_info);
192 add_node(bebob, root, "formation", proc_read_formation);
Takashi Sakamoto1fc95222014-04-25 22:45:21 +0900193
194 if (bebob->spec->meter != NULL)
195 add_node(bebob, root, "meter", proc_read_meters);
Takashi Sakamotoad9697b2014-04-25 22:45:17 +0900196}