c31ca4f42a581513ceab7c8ef945816ff8052be3
[firefly-linux-kernel-4.4.55.git] / sound / firewire / bebob / bebob_proc.c
1 /*
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 */
12 struct 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
35 static void
36 proc_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
67 end:
68         kfree(info);
69 }
70
71 static void
72 proc_read_formation(struct snd_info_entry *entry,
73                 struct snd_info_buffer *buffer)
74 {
75         struct snd_bebob *bebob = entry->private_data;
76         struct snd_bebob_stream_formation *formation;
77         unsigned int i;
78
79         snd_iprintf(buffer, "Output Stream from device:\n");
80         snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
81         formation = bebob->tx_stream_formations;
82         for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
83                 snd_iprintf(buffer,
84                             "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],
85                             formation[i].pcm, formation[i].midi);
86         }
87
88         snd_iprintf(buffer, "Input Stream to device:\n");
89         snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
90         formation = bebob->rx_stream_formations;
91         for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
92                 snd_iprintf(buffer,
93                             "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],
94                             formation[i].pcm, formation[i].midi);
95         }
96 }
97
98 static void
99 proc_read_clock(struct snd_info_entry *entry,
100                 struct snd_info_buffer *buffer)
101 {
102         struct snd_bebob *bebob = entry->private_data;
103         unsigned int rate;
104         bool internal;
105
106         if (snd_bebob_stream_get_rate(bebob, &rate) >= 0)
107                 snd_iprintf(buffer, "Sampling rate: %d\n", rate);
108
109         if (snd_bebob_stream_check_internal_clock(bebob, &internal) >= 0)
110                 snd_iprintf(buffer, "Clock Source: %s (MSU-dest: %d)",
111                             (internal) ? "Internal" : "External",
112                             bebob->sync_input_plug);
113 }
114
115 static void
116 add_node(struct snd_bebob *bebob, struct snd_info_entry *root, const char *name,
117          void (*op)(struct snd_info_entry *e, struct snd_info_buffer *b))
118 {
119         struct snd_info_entry *entry;
120
121         entry = snd_info_create_card_entry(bebob->card, name, root);
122         if (entry == NULL)
123                 return;
124
125         snd_info_set_text_ops(entry, bebob, op);
126         if (snd_info_register(entry) < 0)
127                 snd_info_free_entry(entry);
128 }
129
130 void snd_bebob_proc_init(struct snd_bebob *bebob)
131 {
132         struct snd_info_entry *root;
133
134         /*
135          * All nodes are automatically removed at snd_card_disconnect(),
136          * by following to link list.
137          */
138         root = snd_info_create_card_entry(bebob->card, "firewire",
139                                           bebob->card->proc_root);
140         if (root == NULL)
141                 return;
142         root->mode = S_IFDIR | S_IRUGO | S_IXUGO;
143         if (snd_info_register(root) < 0) {
144                 snd_info_free_entry(root);
145                 return;
146         }
147
148         add_node(bebob, root, "clock", proc_read_clock);
149         add_node(bebob, root, "firmware", proc_read_hw_info);
150         add_node(bebob, root, "formation", proc_read_formation);
151 }