lola_proc.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Support for Digigram Lola PCI-e boards
  4. *
  5. * Copyright (c) 2011 Takashi Iwai <[email protected]>
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <linux/io.h>
  10. #include <sound/core.h>
  11. #include <sound/info.h>
  12. #include <sound/pcm.h>
  13. #include "lola.h"
  14. static void print_audio_widget(struct snd_info_buffer *buffer,
  15. struct lola *chip, int nid, const char *name)
  16. {
  17. unsigned int val;
  18. lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
  19. snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
  20. lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val);
  21. snd_iprintf(buffer, " Formats: 0x%x\n", val);
  22. }
  23. static void print_pin_widget(struct snd_info_buffer *buffer,
  24. struct lola *chip, int nid, unsigned int ampcap,
  25. const char *name)
  26. {
  27. unsigned int val;
  28. lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
  29. snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
  30. if (val == 0x00400200)
  31. return;
  32. lola_read_param(chip, nid, ampcap, &val);
  33. snd_iprintf(buffer, " Amp-Caps: 0x%x\n", val);
  34. snd_iprintf(buffer, " mute=%d, step-size=%d, steps=%d, ofs=%d\n",
  35. LOLA_AMP_MUTE_CAPABLE(val),
  36. LOLA_AMP_STEP_SIZE(val),
  37. LOLA_AMP_NUM_STEPS(val),
  38. LOLA_AMP_OFFSET(val));
  39. lola_codec_read(chip, nid, LOLA_VERB_GET_MAX_LEVEL, 0, 0, &val, NULL);
  40. snd_iprintf(buffer, " Max-level: 0x%x\n", val);
  41. }
  42. static void print_clock_widget(struct snd_info_buffer *buffer,
  43. struct lola *chip, int nid)
  44. {
  45. int i, j, num_clocks;
  46. unsigned int val;
  47. lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
  48. snd_iprintf(buffer, "Node 0x%02x [Clock] wcaps 0x%x\n", nid, val);
  49. num_clocks = val & 0xff;
  50. for (i = 0; i < num_clocks; i += 4) {
  51. unsigned int res_ex;
  52. unsigned short items[4];
  53. const char *name;
  54. lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST,
  55. i, 0, &val, &res_ex);
  56. items[0] = val & 0xfff;
  57. items[1] = (val >> 16) & 0xfff;
  58. items[2] = res_ex & 0xfff;
  59. items[3] = (res_ex >> 16) & 0xfff;
  60. for (j = 0; j < 4; j++) {
  61. unsigned char type = items[j] >> 8;
  62. unsigned int freq = items[j] & 0xff;
  63. if (i + j >= num_clocks)
  64. break;
  65. if (type == LOLA_CLOCK_TYPE_INTERNAL) {
  66. name = "Internal";
  67. freq = lola_sample_rate_convert(freq);
  68. } else if (type == LOLA_CLOCK_TYPE_VIDEO) {
  69. name = "Video";
  70. freq = lola_sample_rate_convert(freq);
  71. } else {
  72. name = "Other";
  73. }
  74. snd_iprintf(buffer, " Clock %d: Type %d:%s, freq=%d\n",
  75. i + j, type, name, freq);
  76. }
  77. }
  78. }
  79. static void print_mixer_widget(struct snd_info_buffer *buffer,
  80. struct lola *chip, int nid)
  81. {
  82. unsigned int val;
  83. lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
  84. snd_iprintf(buffer, "Node 0x%02x [Mixer] wcaps 0x%x\n", nid, val);
  85. }
  86. static void lola_proc_codec_read(struct snd_info_entry *entry,
  87. struct snd_info_buffer *buffer)
  88. {
  89. struct lola *chip = entry->private_data;
  90. unsigned int val;
  91. int i, nid;
  92. lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val);
  93. snd_iprintf(buffer, "Vendor: 0x%08x\n", val);
  94. lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
  95. snd_iprintf(buffer, "Function Type: %d\n", val);
  96. lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val);
  97. snd_iprintf(buffer, "Specific-Caps: 0x%08x\n", val);
  98. snd_iprintf(buffer, " Pins-In %d, Pins-Out %d\n",
  99. chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins);
  100. nid = 2;
  101. for (i = 0; i < chip->pcm[CAPT].num_streams; i++, nid++)
  102. print_audio_widget(buffer, chip, nid, "[Audio-In]");
  103. for (i = 0; i < chip->pcm[PLAY].num_streams; i++, nid++)
  104. print_audio_widget(buffer, chip, nid, "[Audio-Out]");
  105. for (i = 0; i < chip->pin[CAPT].num_pins; i++, nid++)
  106. print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_IN_CAP,
  107. "[Pin-In]");
  108. for (i = 0; i < chip->pin[PLAY].num_pins; i++, nid++)
  109. print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_OUT_CAP,
  110. "[Pin-Out]");
  111. if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) {
  112. print_clock_widget(buffer, chip, nid);
  113. nid++;
  114. }
  115. if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) {
  116. print_mixer_widget(buffer, chip, nid);
  117. nid++;
  118. }
  119. }
  120. /* direct codec access for debugging */
  121. static void lola_proc_codec_rw_write(struct snd_info_entry *entry,
  122. struct snd_info_buffer *buffer)
  123. {
  124. struct lola *chip = entry->private_data;
  125. char line[64];
  126. unsigned int id, verb, data, extdata;
  127. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  128. if (sscanf(line, "%u %u %u %u", &id, &verb, &data, &extdata) != 4)
  129. continue;
  130. lola_codec_read(chip, id, verb, data, extdata,
  131. &chip->debug_res,
  132. &chip->debug_res_ex);
  133. }
  134. }
  135. static void lola_proc_codec_rw_read(struct snd_info_entry *entry,
  136. struct snd_info_buffer *buffer)
  137. {
  138. struct lola *chip = entry->private_data;
  139. snd_iprintf(buffer, "0x%x 0x%x\n", chip->debug_res, chip->debug_res_ex);
  140. }
  141. /*
  142. * dump some registers
  143. */
  144. static void lola_proc_regs_read(struct snd_info_entry *entry,
  145. struct snd_info_buffer *buffer)
  146. {
  147. struct lola *chip = entry->private_data;
  148. int i;
  149. for (i = 0; i < 0x40; i += 4) {
  150. snd_iprintf(buffer, "BAR0 %02x: %08x\n", i,
  151. readl(chip->bar[BAR0].remap_addr + i));
  152. }
  153. snd_iprintf(buffer, "\n");
  154. for (i = 0; i < 0x30; i += 4) {
  155. snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
  156. readl(chip->bar[BAR1].remap_addr + i));
  157. }
  158. snd_iprintf(buffer, "\n");
  159. for (i = 0x80; i < 0xa0; i += 4) {
  160. snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
  161. readl(chip->bar[BAR1].remap_addr + i));
  162. }
  163. snd_iprintf(buffer, "\n");
  164. for (i = 0; i < 32; i++) {
  165. snd_iprintf(buffer, "DSD %02x STS %08x\n", i,
  166. lola_dsd_read(chip, i, STS));
  167. snd_iprintf(buffer, "DSD %02x LPIB %08x\n", i,
  168. lola_dsd_read(chip, i, LPIB));
  169. snd_iprintf(buffer, "DSD %02x CTL %08x\n", i,
  170. lola_dsd_read(chip, i, CTL));
  171. snd_iprintf(buffer, "DSD %02x LVIL %08x\n", i,
  172. lola_dsd_read(chip, i, LVI));
  173. snd_iprintf(buffer, "DSD %02x BDPL %08x\n", i,
  174. lola_dsd_read(chip, i, BDPL));
  175. snd_iprintf(buffer, "DSD %02x BDPU %08x\n", i,
  176. lola_dsd_read(chip, i, BDPU));
  177. }
  178. }
  179. void lola_proc_debug_new(struct lola *chip)
  180. {
  181. snd_card_ro_proc_new(chip->card, "codec", chip, lola_proc_codec_read);
  182. snd_card_rw_proc_new(chip->card, "codec_rw", chip,
  183. lola_proc_codec_rw_read,
  184. lola_proc_codec_rw_write);
  185. snd_card_ro_proc_new(chip->card, "regs", chip, lola_proc_regs_read);
  186. }