lola_proc.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Support for Digigram Lola PCI-e boards
  3. *
  4. * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc., 59
  18. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/io.h>
  23. #include <sound/core.h>
  24. #include <sound/info.h>
  25. #include <sound/pcm.h>
  26. #include "lola.h"
  27. static void print_audio_widget(struct snd_info_buffer *buffer,
  28. struct lola *chip, int nid, const char *name)
  29. {
  30. unsigned int val;
  31. lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
  32. snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
  33. lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val);
  34. snd_iprintf(buffer, " Formats: 0x%x\n", val);
  35. }
  36. static void print_pin_widget(struct snd_info_buffer *buffer,
  37. struct lola *chip, int nid, unsigned int ampcap,
  38. const char *name)
  39. {
  40. unsigned int val;
  41. lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
  42. snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
  43. if (val == 0x00400200)
  44. return;
  45. lola_read_param(chip, nid, ampcap, &val);
  46. snd_iprintf(buffer, " Amp-Caps: 0x%x\n", val);
  47. snd_iprintf(buffer, " mute=%d, step-size=%d, steps=%d, ofs=%d\n",
  48. LOLA_AMP_MUTE_CAPABLE(val),
  49. LOLA_AMP_STEP_SIZE(val),
  50. LOLA_AMP_NUM_STEPS(val),
  51. LOLA_AMP_OFFSET(val));
  52. lola_codec_read(chip, nid, LOLA_VERB_GET_MAX_LEVEL, 0, 0, &val, NULL);
  53. snd_iprintf(buffer, " Max-level: 0x%x\n", val);
  54. }
  55. static void print_clock_widget(struct snd_info_buffer *buffer,
  56. struct lola *chip, int nid)
  57. {
  58. int i, j, num_clocks;
  59. unsigned int val;
  60. lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
  61. snd_iprintf(buffer, "Node 0x%02x [Clock] wcaps 0x%x\n", nid, val);
  62. num_clocks = val & 0xff;
  63. for (i = 0; i < num_clocks; i += 4) {
  64. unsigned int res_ex;
  65. unsigned short items[4];
  66. const char *name;
  67. lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST,
  68. i, 0, &val, &res_ex);
  69. items[0] = val & 0xfff;
  70. items[1] = (val >> 16) & 0xfff;
  71. items[2] = res_ex & 0xfff;
  72. items[3] = (res_ex >> 16) & 0xfff;
  73. for (j = 0; j < 4; j++) {
  74. unsigned char type = items[j] >> 8;
  75. unsigned int freq = items[j] & 0xff;
  76. if (i + j >= num_clocks)
  77. break;
  78. if (type == LOLA_CLOCK_TYPE_INTERNAL) {
  79. name = "Internal";
  80. freq = lola_sample_rate_convert(freq);
  81. } else if (type == LOLA_CLOCK_TYPE_VIDEO) {
  82. name = "Video";
  83. freq = lola_sample_rate_convert(freq);
  84. } else {
  85. name = "Other";
  86. }
  87. snd_iprintf(buffer, " Clock %d: Type %d:%s, freq=%d\n",
  88. i + j, type, name, freq);
  89. }
  90. }
  91. }
  92. static void print_mixer_widget(struct snd_info_buffer *buffer,
  93. struct lola *chip, int nid)
  94. {
  95. unsigned int val;
  96. lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
  97. snd_iprintf(buffer, "Node 0x%02x [Mixer] wcaps 0x%x\n", nid, val);
  98. }
  99. static void lola_proc_codec_read(struct snd_info_entry *entry,
  100. struct snd_info_buffer *buffer)
  101. {
  102. struct lola *chip = entry->private_data;
  103. unsigned int val;
  104. int i, nid;
  105. lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val);
  106. snd_iprintf(buffer, "Vendor: 0x%08x\n", val);
  107. lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
  108. snd_iprintf(buffer, "Function Type: %d\n", val);
  109. lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val);
  110. snd_iprintf(buffer, "Specific-Caps: 0x%08x\n", val);
  111. snd_iprintf(buffer, " Pins-In %d, Pins-Out %d\n",
  112. chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins);
  113. nid = 2;
  114. for (i = 0; i < chip->pcm[CAPT].num_streams; i++, nid++)
  115. print_audio_widget(buffer, chip, nid, "[Audio-In]");
  116. for (i = 0; i < chip->pcm[PLAY].num_streams; i++, nid++)
  117. print_audio_widget(buffer, chip, nid, "[Audio-Out]");
  118. for (i = 0; i < chip->pin[CAPT].num_pins; i++, nid++)
  119. print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_IN_CAP,
  120. "[Pin-In]");
  121. for (i = 0; i < chip->pin[PLAY].num_pins; i++, nid++)
  122. print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_OUT_CAP,
  123. "[Pin-Out]");
  124. if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) {
  125. print_clock_widget(buffer, chip, nid);
  126. nid++;
  127. }
  128. if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) {
  129. print_mixer_widget(buffer, chip, nid);
  130. nid++;
  131. }
  132. }
  133. /* direct codec access for debugging */
  134. static void lola_proc_codec_rw_write(struct snd_info_entry *entry,
  135. struct snd_info_buffer *buffer)
  136. {
  137. struct lola *chip = entry->private_data;
  138. char line[64];
  139. unsigned int id, verb, data, extdata;
  140. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  141. if (sscanf(line, "%i %i %i %i", &id, &verb, &data, &extdata) != 4)
  142. continue;
  143. lola_codec_read(chip, id, verb, data, extdata,
  144. &chip->debug_res,
  145. &chip->debug_res_ex);
  146. }
  147. }
  148. static void lola_proc_codec_rw_read(struct snd_info_entry *entry,
  149. struct snd_info_buffer *buffer)
  150. {
  151. struct lola *chip = entry->private_data;
  152. snd_iprintf(buffer, "0x%x 0x%x\n", chip->debug_res, chip->debug_res_ex);
  153. }
  154. /*
  155. * dump some registers
  156. */
  157. static void lola_proc_regs_read(struct snd_info_entry *entry,
  158. struct snd_info_buffer *buffer)
  159. {
  160. struct lola *chip = entry->private_data;
  161. int i;
  162. for (i = 0; i < 0x40; i += 4) {
  163. snd_iprintf(buffer, "BAR0 %02x: %08x\n", i,
  164. readl(chip->bar[BAR0].remap_addr + i));
  165. }
  166. snd_iprintf(buffer, "\n");
  167. for (i = 0; i < 0x30; i += 4) {
  168. snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
  169. readl(chip->bar[BAR1].remap_addr + i));
  170. }
  171. snd_iprintf(buffer, "\n");
  172. for (i = 0x80; i < 0xa0; i += 4) {
  173. snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
  174. readl(chip->bar[BAR1].remap_addr + i));
  175. }
  176. snd_iprintf(buffer, "\n");
  177. for (i = 0; i < 32; i++) {
  178. snd_iprintf(buffer, "DSD %02x STS %08x\n", i,
  179. lola_dsd_read(chip, i, STS));
  180. snd_iprintf(buffer, "DSD %02x LPIB %08x\n", i,
  181. lola_dsd_read(chip, i, LPIB));
  182. snd_iprintf(buffer, "DSD %02x CTL %08x\n", i,
  183. lola_dsd_read(chip, i, CTL));
  184. snd_iprintf(buffer, "DSD %02x LVIL %08x\n", i,
  185. lola_dsd_read(chip, i, LVI));
  186. snd_iprintf(buffer, "DSD %02x BDPL %08x\n", i,
  187. lola_dsd_read(chip, i, BDPL));
  188. snd_iprintf(buffer, "DSD %02x BDPU %08x\n", i,
  189. lola_dsd_read(chip, i, BDPU));
  190. }
  191. }
  192. void __devinit lola_proc_debug_new(struct lola *chip)
  193. {
  194. struct snd_info_entry *entry;
  195. if (!snd_card_proc_new(chip->card, "codec", &entry))
  196. snd_info_set_text_ops(entry, chip, lola_proc_codec_read);
  197. if (!snd_card_proc_new(chip->card, "codec_rw", &entry)) {
  198. snd_info_set_text_ops(entry, chip, lola_proc_codec_rw_read);
  199. entry->mode |= S_IWUSR;
  200. entry->c.text.write = lola_proc_codec_rw_write;
  201. }
  202. if (!snd_card_proc_new(chip->card, "regs", &entry))
  203. snd_info_set_text_ops(entry, chip, lola_proc_regs_read);
  204. }