1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * digi00x-proc.c - a part of driver for Digidesign Digi 002/003 family
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (c) 2014-2015 Takashi Sakamoto
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include "digi00x.h"
9*4882a593Smuzhiyun
get_optical_iface_mode(struct snd_dg00x * dg00x,enum snd_dg00x_optical_mode * mode)10*4882a593Smuzhiyun static int get_optical_iface_mode(struct snd_dg00x *dg00x,
11*4882a593Smuzhiyun enum snd_dg00x_optical_mode *mode)
12*4882a593Smuzhiyun {
13*4882a593Smuzhiyun __be32 data;
14*4882a593Smuzhiyun int err;
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun err = snd_fw_transaction(dg00x->unit, TCODE_READ_QUADLET_REQUEST,
17*4882a593Smuzhiyun DG00X_ADDR_BASE + DG00X_OFFSET_OPT_IFACE_MODE,
18*4882a593Smuzhiyun &data, sizeof(data), 0);
19*4882a593Smuzhiyun if (err >= 0)
20*4882a593Smuzhiyun *mode = be32_to_cpu(data) & 0x01;
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun return err;
23*4882a593Smuzhiyun }
24*4882a593Smuzhiyun
proc_read_clock(struct snd_info_entry * entry,struct snd_info_buffer * buf)25*4882a593Smuzhiyun static void proc_read_clock(struct snd_info_entry *entry,
26*4882a593Smuzhiyun struct snd_info_buffer *buf)
27*4882a593Smuzhiyun {
28*4882a593Smuzhiyun static const char *const source_name[] = {
29*4882a593Smuzhiyun [SND_DG00X_CLOCK_INTERNAL] = "internal",
30*4882a593Smuzhiyun [SND_DG00X_CLOCK_SPDIF] = "s/pdif",
31*4882a593Smuzhiyun [SND_DG00X_CLOCK_ADAT] = "adat",
32*4882a593Smuzhiyun [SND_DG00X_CLOCK_WORD] = "word clock",
33*4882a593Smuzhiyun };
34*4882a593Smuzhiyun static const char *const optical_name[] = {
35*4882a593Smuzhiyun [SND_DG00X_OPT_IFACE_MODE_ADAT] = "adat",
36*4882a593Smuzhiyun [SND_DG00X_OPT_IFACE_MODE_SPDIF] = "s/pdif",
37*4882a593Smuzhiyun };
38*4882a593Smuzhiyun struct snd_dg00x *dg00x = entry->private_data;
39*4882a593Smuzhiyun enum snd_dg00x_optical_mode mode;
40*4882a593Smuzhiyun unsigned int rate;
41*4882a593Smuzhiyun enum snd_dg00x_clock clock;
42*4882a593Smuzhiyun bool detect;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun if (get_optical_iface_mode(dg00x, &mode) < 0)
45*4882a593Smuzhiyun return;
46*4882a593Smuzhiyun if (snd_dg00x_stream_get_local_rate(dg00x, &rate) < 0)
47*4882a593Smuzhiyun return;
48*4882a593Smuzhiyun if (snd_dg00x_stream_get_clock(dg00x, &clock) < 0)
49*4882a593Smuzhiyun return;
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun snd_iprintf(buf, "Optical mode: %s\n", optical_name[mode]);
52*4882a593Smuzhiyun snd_iprintf(buf, "Sampling Rate: %d\n", rate);
53*4882a593Smuzhiyun snd_iprintf(buf, "Clock Source: %s\n", source_name[clock]);
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun if (clock == SND_DG00X_CLOCK_INTERNAL)
56*4882a593Smuzhiyun return;
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun if (snd_dg00x_stream_check_external_clock(dg00x, &detect) < 0)
59*4882a593Smuzhiyun return;
60*4882a593Smuzhiyun snd_iprintf(buf, "External source: %s\n", detect ? "detected" : "not");
61*4882a593Smuzhiyun if (!detect)
62*4882a593Smuzhiyun return;
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun if (snd_dg00x_stream_get_external_rate(dg00x, &rate) >= 0)
65*4882a593Smuzhiyun snd_iprintf(buf, "External sampling rate: %d\n", rate);
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun
snd_dg00x_proc_init(struct snd_dg00x * dg00x)68*4882a593Smuzhiyun void snd_dg00x_proc_init(struct snd_dg00x *dg00x)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun struct snd_info_entry *root, *entry;
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun /*
73*4882a593Smuzhiyun * All nodes are automatically removed at snd_card_disconnect(),
74*4882a593Smuzhiyun * by following to link list.
75*4882a593Smuzhiyun */
76*4882a593Smuzhiyun root = snd_info_create_card_entry(dg00x->card, "firewire",
77*4882a593Smuzhiyun dg00x->card->proc_root);
78*4882a593Smuzhiyun if (root == NULL)
79*4882a593Smuzhiyun return;
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun root->mode = S_IFDIR | 0555;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun entry = snd_info_create_card_entry(dg00x->card, "clock", root);
84*4882a593Smuzhiyun if (entry)
85*4882a593Smuzhiyun snd_info_set_text_ops(entry, dg00x, proc_read_clock);
86*4882a593Smuzhiyun }
87