Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  Support for Digigram Lola PCI-e boards
0004  *
0005  *  Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
0006  */
0007 
0008 #include <linux/kernel.h>
0009 #include <linux/init.h>
0010 #include <linux/io.h>
0011 #include <sound/core.h>
0012 #include <sound/info.h>
0013 #include <sound/pcm.h>
0014 #include "lola.h"
0015 
0016 static void print_audio_widget(struct snd_info_buffer *buffer,
0017                    struct lola *chip, int nid, const char *name)
0018 {
0019     unsigned int val;
0020 
0021     lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
0022     snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
0023     lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val);
0024     snd_iprintf(buffer, "  Formats: 0x%x\n", val);
0025 }
0026 
0027 static void print_pin_widget(struct snd_info_buffer *buffer,
0028                  struct lola *chip, int nid, unsigned int ampcap,
0029                  const char *name)
0030 {
0031     unsigned int val;
0032 
0033     lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
0034     snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
0035     if (val == 0x00400200)
0036         return;
0037     lola_read_param(chip, nid, ampcap, &val);
0038     snd_iprintf(buffer, "  Amp-Caps: 0x%x\n", val);
0039     snd_iprintf(buffer, "    mute=%d, step-size=%d, steps=%d, ofs=%d\n",
0040             LOLA_AMP_MUTE_CAPABLE(val),
0041             LOLA_AMP_STEP_SIZE(val),
0042             LOLA_AMP_NUM_STEPS(val),
0043             LOLA_AMP_OFFSET(val));
0044     lola_codec_read(chip, nid, LOLA_VERB_GET_MAX_LEVEL, 0, 0, &val, NULL);
0045     snd_iprintf(buffer, "  Max-level: 0x%x\n", val);
0046 }
0047 
0048 static void print_clock_widget(struct snd_info_buffer *buffer,
0049                    struct lola *chip, int nid)
0050 {
0051     int i, j, num_clocks;
0052     unsigned int val;
0053 
0054     lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
0055     snd_iprintf(buffer, "Node 0x%02x [Clock] wcaps 0x%x\n", nid, val);
0056     num_clocks = val & 0xff;
0057     for (i = 0; i < num_clocks; i += 4) {
0058         unsigned int res_ex;
0059         unsigned short items[4];
0060         const char *name;
0061 
0062         lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST,
0063                 i, 0, &val, &res_ex);
0064         items[0] = val & 0xfff;
0065         items[1] = (val >> 16) & 0xfff;
0066         items[2] = res_ex & 0xfff;
0067         items[3] = (res_ex >> 16) & 0xfff;
0068         for (j = 0; j < 4; j++) {
0069             unsigned char type = items[j] >> 8;
0070             unsigned int freq = items[j] & 0xff;
0071             if (i + j >= num_clocks)
0072                 break;
0073             if (type == LOLA_CLOCK_TYPE_INTERNAL) {
0074                 name = "Internal";
0075                 freq = lola_sample_rate_convert(freq);
0076             } else if (type == LOLA_CLOCK_TYPE_VIDEO) {
0077                 name = "Video";
0078                 freq = lola_sample_rate_convert(freq);
0079             } else {
0080                 name = "Other";
0081             }
0082             snd_iprintf(buffer, "  Clock %d: Type %d:%s, freq=%d\n",
0083                     i + j, type, name, freq);
0084         }
0085     }
0086 }
0087 
0088 static void print_mixer_widget(struct snd_info_buffer *buffer,
0089                    struct lola *chip, int nid)
0090 {
0091     unsigned int val;
0092 
0093     lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
0094     snd_iprintf(buffer, "Node 0x%02x [Mixer] wcaps 0x%x\n", nid, val);
0095 }
0096 
0097 static void lola_proc_codec_read(struct snd_info_entry *entry,
0098                  struct snd_info_buffer *buffer)
0099 {
0100     struct lola *chip = entry->private_data;
0101     unsigned int val;
0102     int i, nid;
0103 
0104     lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val);
0105     snd_iprintf(buffer, "Vendor: 0x%08x\n", val);
0106     lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
0107     snd_iprintf(buffer, "Function Type: %d\n", val);
0108     lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val);
0109     snd_iprintf(buffer, "Specific-Caps: 0x%08x\n", val);
0110     snd_iprintf(buffer, "  Pins-In %d, Pins-Out %d\n",
0111             chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins);
0112     nid = 2;
0113     for (i = 0; i < chip->pcm[CAPT].num_streams; i++, nid++)
0114         print_audio_widget(buffer, chip, nid, "[Audio-In]");
0115     for (i = 0; i < chip->pcm[PLAY].num_streams; i++, nid++)
0116         print_audio_widget(buffer, chip, nid, "[Audio-Out]");
0117     for (i = 0; i < chip->pin[CAPT].num_pins; i++, nid++)
0118         print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_IN_CAP,
0119                  "[Pin-In]");
0120     for (i = 0; i < chip->pin[PLAY].num_pins; i++, nid++)
0121         print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_OUT_CAP,
0122                  "[Pin-Out]");
0123     if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) {
0124         print_clock_widget(buffer, chip, nid);
0125         nid++;
0126     }
0127     if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) {
0128         print_mixer_widget(buffer, chip, nid);
0129         nid++;
0130     }
0131 }
0132 
0133 /* direct codec access for debugging */
0134 static void lola_proc_codec_rw_write(struct snd_info_entry *entry,
0135                      struct snd_info_buffer *buffer)
0136 {
0137     struct lola *chip = entry->private_data;
0138     char line[64];
0139     unsigned int id, verb, data, extdata;
0140     while (!snd_info_get_line(buffer, line, sizeof(line))) {
0141         if (sscanf(line, "%u %u %u %u", &id, &verb, &data, &extdata) != 4)
0142             continue;
0143         lola_codec_read(chip, id, verb, data, extdata,
0144                 &chip->debug_res,
0145                 &chip->debug_res_ex);
0146     }
0147 }
0148 
0149 static void lola_proc_codec_rw_read(struct snd_info_entry *entry,
0150                     struct snd_info_buffer *buffer)
0151 {
0152     struct lola *chip = entry->private_data;
0153     snd_iprintf(buffer, "0x%x 0x%x\n", chip->debug_res, chip->debug_res_ex);
0154 }
0155 
0156 /*
0157  * dump some registers
0158  */
0159 static void lola_proc_regs_read(struct snd_info_entry *entry,
0160                 struct snd_info_buffer *buffer)
0161 {
0162     struct lola *chip = entry->private_data;
0163     int i;
0164 
0165     for (i = 0; i < 0x40; i += 4) {
0166         snd_iprintf(buffer, "BAR0 %02x: %08x\n", i,
0167                 readl(chip->bar[BAR0].remap_addr + i));
0168     }
0169     snd_iprintf(buffer, "\n");
0170     for (i = 0; i < 0x30; i += 4) {
0171         snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
0172                 readl(chip->bar[BAR1].remap_addr + i));
0173     }
0174     snd_iprintf(buffer, "\n");
0175     for (i = 0x80; i < 0xa0; i += 4) {
0176         snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
0177                 readl(chip->bar[BAR1].remap_addr + i));
0178     }
0179     snd_iprintf(buffer, "\n");
0180     for (i = 0; i < 32; i++) {
0181         snd_iprintf(buffer, "DSD %02x STS  %08x\n", i,
0182                 lola_dsd_read(chip, i, STS));
0183         snd_iprintf(buffer, "DSD %02x LPIB %08x\n", i,
0184                 lola_dsd_read(chip, i, LPIB));
0185         snd_iprintf(buffer, "DSD %02x CTL  %08x\n", i,
0186                 lola_dsd_read(chip, i, CTL));
0187         snd_iprintf(buffer, "DSD %02x LVIL %08x\n", i,
0188                 lola_dsd_read(chip, i, LVI));
0189         snd_iprintf(buffer, "DSD %02x BDPL %08x\n", i,
0190                 lola_dsd_read(chip, i, BDPL));
0191         snd_iprintf(buffer, "DSD %02x BDPU %08x\n", i,
0192                 lola_dsd_read(chip, i, BDPU));
0193     }
0194 }
0195 
0196 void lola_proc_debug_new(struct lola *chip)
0197 {
0198     snd_card_ro_proc_new(chip->card, "codec", chip, lola_proc_codec_read);
0199     snd_card_rw_proc_new(chip->card, "codec_rw", chip,
0200                  lola_proc_codec_rw_read,
0201                  lola_proc_codec_rw_write);
0202     snd_card_ro_proc_new(chip->card, "regs", chip, lola_proc_regs_read);
0203 }