Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * digi00x-proc.c - a part of driver for Digidesign Digi 002/003 family
0004  *
0005  * Copyright (c) 2014-2015 Takashi Sakamoto
0006  */
0007 
0008 #include "digi00x.h"
0009 
0010 static int get_optical_iface_mode(struct snd_dg00x *dg00x,
0011                   enum snd_dg00x_optical_mode *mode)
0012 {
0013     __be32 data;
0014     int err;
0015 
0016     err = snd_fw_transaction(dg00x->unit, TCODE_READ_QUADLET_REQUEST,
0017                  DG00X_ADDR_BASE + DG00X_OFFSET_OPT_IFACE_MODE,
0018                  &data, sizeof(data), 0);
0019     if (err >= 0)
0020         *mode = be32_to_cpu(data) & 0x01;
0021 
0022     return err;
0023 }
0024 
0025 static void proc_read_clock(struct snd_info_entry *entry,
0026                 struct snd_info_buffer *buf)
0027 {
0028     static const char *const source_name[] = {
0029         [SND_DG00X_CLOCK_INTERNAL] = "internal",
0030         [SND_DG00X_CLOCK_SPDIF] = "s/pdif",
0031         [SND_DG00X_CLOCK_ADAT] = "adat",
0032         [SND_DG00X_CLOCK_WORD] = "word clock",
0033     };
0034     static const char *const optical_name[] = {
0035         [SND_DG00X_OPT_IFACE_MODE_ADAT] = "adat",
0036         [SND_DG00X_OPT_IFACE_MODE_SPDIF] = "s/pdif",
0037     };
0038     struct snd_dg00x *dg00x = entry->private_data;
0039     enum snd_dg00x_optical_mode mode;
0040     unsigned int rate;
0041     enum snd_dg00x_clock clock;
0042     bool detect;
0043 
0044     if (get_optical_iface_mode(dg00x, &mode) < 0)
0045         return;
0046     if (snd_dg00x_stream_get_local_rate(dg00x, &rate) < 0)
0047         return;
0048     if (snd_dg00x_stream_get_clock(dg00x, &clock) < 0)
0049         return;
0050 
0051     snd_iprintf(buf, "Optical mode: %s\n", optical_name[mode]);
0052     snd_iprintf(buf, "Sampling Rate: %d\n", rate);
0053     snd_iprintf(buf, "Clock Source: %s\n", source_name[clock]);
0054 
0055     if (clock == SND_DG00X_CLOCK_INTERNAL)
0056         return;
0057 
0058     if (snd_dg00x_stream_check_external_clock(dg00x, &detect) < 0)
0059         return;
0060     snd_iprintf(buf, "External source: %s\n", detect ? "detected" : "not");
0061     if (!detect)
0062         return;
0063 
0064     if (snd_dg00x_stream_get_external_rate(dg00x, &rate) >= 0)
0065         snd_iprintf(buf, "External sampling rate: %d\n", rate);
0066 }
0067 
0068 void snd_dg00x_proc_init(struct snd_dg00x *dg00x)
0069 {
0070     struct snd_info_entry *root, *entry;
0071 
0072     /*
0073      * All nodes are automatically removed at snd_card_disconnect(),
0074      * by following to link list.
0075      */
0076     root = snd_info_create_card_entry(dg00x->card, "firewire",
0077                       dg00x->card->proc_root);
0078     if (root == NULL)
0079         return;
0080 
0081     root->mode = S_IFDIR | 0555;
0082 
0083     entry = snd_info_create_card_entry(dg00x->card, "clock", root);
0084     if (entry)
0085         snd_info_set_text_ops(entry, dg00x, proc_read_clock);
0086 }