hda_proc.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * Generic proc interface
  5. *
  6. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  7. *
  8. *
  9. * This driver is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This driver is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <sound/driver.h>
  24. #include <linux/init.h>
  25. #include <linux/pci.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. static const char *get_wid_type_name(unsigned int wid_value)
  29. {
  30. static char *names[16] = {
  31. [AC_WID_AUD_OUT] = "Audio Output",
  32. [AC_WID_AUD_IN] = "Audio Input",
  33. [AC_WID_AUD_MIX] = "Audio Mixer",
  34. [AC_WID_AUD_SEL] = "Audio Selector",
  35. [AC_WID_PIN] = "Pin Complex",
  36. [AC_WID_POWER] = "Power Widget",
  37. [AC_WID_VOL_KNB] = "Volume Knob Widget",
  38. [AC_WID_BEEP] = "Beep Generator Widget",
  39. [AC_WID_VENDOR] = "Vendor Defined Widget",
  40. };
  41. wid_value &= 0xf;
  42. if (names[wid_value])
  43. return names[wid_value];
  44. else
  45. return "UNKOWN Widget";
  46. }
  47. static void print_amp_caps(snd_info_buffer_t *buffer,
  48. struct hda_codec *codec, hda_nid_t nid, int dir)
  49. {
  50. unsigned int caps;
  51. if (dir == HDA_OUTPUT)
  52. caps = snd_hda_param_read(codec, nid, AC_PAR_AMP_OUT_CAP);
  53. else
  54. caps = snd_hda_param_read(codec, nid, AC_PAR_AMP_IN_CAP);
  55. if (caps == -1 || caps == 0) {
  56. snd_iprintf(buffer, "N/A\n");
  57. return;
  58. }
  59. snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, mute=%x\n",
  60. caps & AC_AMPCAP_OFFSET,
  61. (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT,
  62. (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT,
  63. (caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT);
  64. }
  65. static void print_amp_vals(snd_info_buffer_t *buffer,
  66. struct hda_codec *codec, hda_nid_t nid,
  67. int dir, int stereo)
  68. {
  69. unsigned int val;
  70. if (stereo) {
  71. val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_AMP_GAIN_MUTE,
  72. AC_AMP_GET_LEFT |
  73. (dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT :
  74. AC_AMP_GET_INPUT));
  75. snd_iprintf(buffer, "0x%02x ", val);
  76. }
  77. val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_AMP_GAIN_MUTE,
  78. AC_AMP_GET_RIGHT |
  79. (dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT :
  80. AC_AMP_GET_INPUT));
  81. snd_iprintf(buffer, "0x%02x\n", val);
  82. }
  83. static void print_pcm_caps(snd_info_buffer_t *buffer,
  84. struct hda_codec *codec, hda_nid_t nid)
  85. {
  86. unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM);
  87. unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
  88. if (pcm == -1 || stream == -1) {
  89. snd_iprintf(buffer, "N/A\n");
  90. return;
  91. }
  92. snd_iprintf(buffer, "rates 0x%03x, bits 0x%02x, types 0x%x\n",
  93. pcm & AC_SUPPCM_RATES, (pcm >> 16) & 0xff, stream & 0xf);
  94. }
  95. static const char *get_jack_location(u32 cfg)
  96. {
  97. static char *bases[7] = {
  98. "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom",
  99. };
  100. static unsigned char specials_idx[] = {
  101. 0x07, 0x08,
  102. 0x17, 0x18, 0x19,
  103. 0x37, 0x38
  104. };
  105. static char *specials[] = {
  106. "Rear Panel", "Drive Bar",
  107. "Riser", "HDMI", "ATAPI",
  108. "Mobile-In", "Mobile-Out"
  109. };
  110. int i;
  111. cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT;
  112. if ((cfg & 0x0f) < 7)
  113. return bases[cfg & 0x0f];
  114. for (i = 0; i < ARRAY_SIZE(specials_idx); i++) {
  115. if (cfg == specials_idx[i])
  116. return specials[i];
  117. }
  118. return "UNKNOWN";
  119. }
  120. static const char *get_jack_connection(u32 cfg)
  121. {
  122. static char *names[16] = {
  123. "Unknown", "1/8", "1/4", "ATAPI",
  124. "RCA", "Optical","Digital", "Analog",
  125. "DIN", "XLR", "RJ11", "Comb",
  126. NULL, NULL, NULL, "Other"
  127. };
  128. cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
  129. if (names[cfg])
  130. return names[cfg];
  131. else
  132. return "UNKNOWN";
  133. }
  134. static const char *get_jack_color(u32 cfg)
  135. {
  136. static char *names[16] = {
  137. "Unknown", "Black", "Grey", "Blue",
  138. "Green", "Red", "Orange", "Yellow",
  139. "Purple", "Pink", NULL, NULL,
  140. NULL, NULL, "White", "Other",
  141. };
  142. cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
  143. if (names[cfg])
  144. return names[cfg];
  145. else
  146. return "UNKNOWN";
  147. }
  148. static void print_pin_caps(snd_info_buffer_t *buffer,
  149. struct hda_codec *codec, hda_nid_t nid)
  150. {
  151. static char *jack_types[16] = {
  152. "Line Out", "Speaker", "HP Out", "CD",
  153. "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand",
  154. "Line In", "Aux", "Mic", "Telephony",
  155. "SPDIF In", "Digitial In", "Reserved", "Other"
  156. };
  157. static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
  158. unsigned int caps;
  159. caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
  160. snd_iprintf(buffer, " Pincap 0x08%x:", caps);
  161. if (caps & AC_PINCAP_IN)
  162. snd_iprintf(buffer, " IN");
  163. if (caps & AC_PINCAP_OUT)
  164. snd_iprintf(buffer, " OUT");
  165. if (caps & AC_PINCAP_HP_DRV)
  166. snd_iprintf(buffer, " HP");
  167. snd_iprintf(buffer, "\n");
  168. caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
  169. snd_iprintf(buffer, " Pin Default 0x%08x: %s at %s %s\n", caps,
  170. jack_types[(caps & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT],
  171. jack_locations[(caps >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3],
  172. get_jack_location(caps));
  173. snd_iprintf(buffer, " Conn = %s, Color = %s\n",
  174. get_jack_connection(caps),
  175. get_jack_color(caps));
  176. }
  177. static void print_codec_info(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
  178. {
  179. struct hda_codec *codec = entry->private_data;
  180. char buf[32];
  181. hda_nid_t nid;
  182. int i, nodes;
  183. snd_hda_get_codec_name(codec, buf, sizeof(buf));
  184. snd_iprintf(buffer, "Codec: %s\n", buf);
  185. snd_iprintf(buffer, "Address: %d\n", codec->addr);
  186. snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id);
  187. snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id);
  188. snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
  189. snd_iprintf(buffer, "Default PCM: ");
  190. print_pcm_caps(buffer, codec, codec->afg);
  191. snd_iprintf(buffer, "Default Amp-In caps: ");
  192. print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
  193. snd_iprintf(buffer, "Default Amp-Out caps: ");
  194. print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
  195. nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
  196. if (! nid || nodes < 0) {
  197. snd_iprintf(buffer, "Invalid AFG subtree\n");
  198. return;
  199. }
  200. for (i = 0; i < nodes; i++, nid++) {
  201. unsigned int wid_caps = snd_hda_param_read(codec, nid,
  202. AC_PAR_AUDIO_WIDGET_CAP);
  203. unsigned int wid_type = (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  204. snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
  205. get_wid_type_name(wid_type), wid_caps);
  206. if (wid_caps & AC_WCAP_STEREO)
  207. snd_iprintf(buffer, " Stereo");
  208. else
  209. snd_iprintf(buffer, " Mono");
  210. if (wid_caps & AC_WCAP_DIGITAL)
  211. snd_iprintf(buffer, " Digital");
  212. if (wid_caps & AC_WCAP_IN_AMP)
  213. snd_iprintf(buffer, " Amp-In");
  214. if (wid_caps & AC_WCAP_OUT_AMP)
  215. snd_iprintf(buffer, " Amp-Out");
  216. snd_iprintf(buffer, "\n");
  217. if (wid_caps & AC_WCAP_IN_AMP) {
  218. snd_iprintf(buffer, " Amp-In caps: ");
  219. print_amp_caps(buffer, codec, nid, HDA_INPUT);
  220. snd_iprintf(buffer, " Amp-In vals: ");
  221. print_amp_vals(buffer, codec, nid, HDA_INPUT,
  222. wid_caps & AC_WCAP_STEREO);
  223. }
  224. if (wid_caps & AC_WCAP_OUT_AMP) {
  225. snd_iprintf(buffer, " Amp-Out caps: ");
  226. print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
  227. snd_iprintf(buffer, " Amp-Out vals: ");
  228. print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
  229. wid_caps & AC_WCAP_STEREO);
  230. }
  231. if (wid_type == AC_WID_PIN) {
  232. unsigned int pinctls;
  233. print_pin_caps(buffer, codec, nid);
  234. pinctls = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  235. snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
  236. if (pinctls & AC_PINCTL_IN_EN)
  237. snd_iprintf(buffer, " IN");
  238. if (pinctls & AC_PINCTL_OUT_EN)
  239. snd_iprintf(buffer, " OUT");
  240. if (pinctls & AC_PINCTL_HP_EN)
  241. snd_iprintf(buffer, " HP");
  242. snd_iprintf(buffer, "\n");
  243. }
  244. if ((wid_type == AC_WID_AUD_OUT || wid_type == AC_WID_AUD_IN) &&
  245. (wid_caps & AC_WCAP_FORMAT_OVRD)) {
  246. snd_iprintf(buffer, " PCM: ");
  247. print_pcm_caps(buffer, codec, nid);
  248. }
  249. if (wid_caps & AC_WCAP_CONN_LIST) {
  250. hda_nid_t conn[HDA_MAX_CONNECTIONS];
  251. int c, conn_len;
  252. conn_len = snd_hda_get_connections(codec, nid, conn,
  253. HDA_MAX_CONNECTIONS);
  254. snd_iprintf(buffer, " Connection: %d\n", conn_len);
  255. snd_iprintf(buffer, " ");
  256. for (c = 0; c < conn_len; c++)
  257. snd_iprintf(buffer, " 0x%02x", conn[c]);
  258. snd_iprintf(buffer, "\n");
  259. }
  260. }
  261. }
  262. /*
  263. * create a proc read
  264. */
  265. int snd_hda_codec_proc_new(struct hda_codec *codec)
  266. {
  267. char name[32];
  268. snd_info_entry_t *entry;
  269. int err;
  270. snprintf(name, sizeof(name), "codec#%d", codec->addr);
  271. err = snd_card_proc_new(codec->bus->card, name, &entry);
  272. if (err < 0)
  273. return err;
  274. snd_info_set_text_ops(entry, codec, 32 * 1024, print_codec_info);
  275. return 0;
  276. }