hda_proc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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 <sound/core.h>
  26. #include "hda_codec.h"
  27. #include "hda_local.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 "UNKNOWN Widget";
  46. }
  47. static void print_amp_caps(struct snd_info_buffer *buffer,
  48. struct hda_codec *codec, hda_nid_t nid, int dir)
  49. {
  50. unsigned int caps;
  51. caps = snd_hda_param_read(codec, nid,
  52. dir == HDA_OUTPUT ?
  53. AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
  54. if (caps == -1 || caps == 0) {
  55. snd_iprintf(buffer, "N/A\n");
  56. return;
  57. }
  58. snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, "
  59. "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(struct snd_info_buffer *buffer,
  66. struct hda_codec *codec, hda_nid_t nid,
  67. int dir, int stereo, int indices)
  68. {
  69. unsigned int val;
  70. int i;
  71. dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
  72. for (i = 0; i < indices; i++) {
  73. snd_iprintf(buffer, " [");
  74. if (stereo) {
  75. val = snd_hda_codec_read(codec, nid, 0,
  76. AC_VERB_GET_AMP_GAIN_MUTE,
  77. AC_AMP_GET_LEFT | dir | i);
  78. snd_iprintf(buffer, "0x%02x ", val);
  79. }
  80. val = snd_hda_codec_read(codec, nid, 0,
  81. AC_VERB_GET_AMP_GAIN_MUTE,
  82. AC_AMP_GET_RIGHT | dir | i);
  83. snd_iprintf(buffer, "0x%02x]", val);
  84. }
  85. snd_iprintf(buffer, "\n");
  86. }
  87. static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
  88. {
  89. static unsigned int rates[] = {
  90. 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
  91. 96000, 176400, 192000, 384000
  92. };
  93. int i;
  94. pcm &= AC_SUPPCM_RATES;
  95. snd_iprintf(buffer, " rates [0x%x]:", pcm);
  96. for (i = 0; i < ARRAY_SIZE(rates); i++)
  97. if (pcm & (1 << i))
  98. snd_iprintf(buffer, " %d", rates[i]);
  99. snd_iprintf(buffer, "\n");
  100. }
  101. static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
  102. {
  103. static unsigned int bits[] = { 8, 16, 20, 24, 32 };
  104. int i;
  105. pcm = (pcm >> 16) & 0xff;
  106. snd_iprintf(buffer, " bits [0x%x]:", pcm);
  107. for (i = 0; i < ARRAY_SIZE(bits); i++)
  108. if (pcm & (1 << i))
  109. snd_iprintf(buffer, " %d", bits[i]);
  110. snd_iprintf(buffer, "\n");
  111. }
  112. static void print_pcm_formats(struct snd_info_buffer *buffer,
  113. unsigned int streams)
  114. {
  115. snd_iprintf(buffer, " formats [0x%x]:", streams & 0xf);
  116. if (streams & AC_SUPFMT_PCM)
  117. snd_iprintf(buffer, " PCM");
  118. if (streams & AC_SUPFMT_FLOAT32)
  119. snd_iprintf(buffer, " FLOAT");
  120. if (streams & AC_SUPFMT_AC3)
  121. snd_iprintf(buffer, " AC3");
  122. snd_iprintf(buffer, "\n");
  123. }
  124. static void print_pcm_caps(struct snd_info_buffer *buffer,
  125. struct hda_codec *codec, hda_nid_t nid)
  126. {
  127. unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM);
  128. unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
  129. if (pcm == -1 || stream == -1) {
  130. snd_iprintf(buffer, "N/A\n");
  131. return;
  132. }
  133. print_pcm_rates(buffer, pcm);
  134. print_pcm_bits(buffer, pcm);
  135. print_pcm_formats(buffer, stream);
  136. }
  137. static const char *get_jack_location(u32 cfg)
  138. {
  139. static char *bases[7] = {
  140. "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom",
  141. };
  142. static unsigned char specials_idx[] = {
  143. 0x07, 0x08,
  144. 0x17, 0x18, 0x19,
  145. 0x37, 0x38
  146. };
  147. static char *specials[] = {
  148. "Rear Panel", "Drive Bar",
  149. "Riser", "HDMI", "ATAPI",
  150. "Mobile-In", "Mobile-Out"
  151. };
  152. int i;
  153. cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT;
  154. if ((cfg & 0x0f) < 7)
  155. return bases[cfg & 0x0f];
  156. for (i = 0; i < ARRAY_SIZE(specials_idx); i++) {
  157. if (cfg == specials_idx[i])
  158. return specials[i];
  159. }
  160. return "UNKNOWN";
  161. }
  162. static const char *get_jack_connection(u32 cfg)
  163. {
  164. static char *names[16] = {
  165. "Unknown", "1/8", "1/4", "ATAPI",
  166. "RCA", "Optical","Digital", "Analog",
  167. "DIN", "XLR", "RJ11", "Comb",
  168. NULL, NULL, NULL, "Other"
  169. };
  170. cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
  171. if (names[cfg])
  172. return names[cfg];
  173. else
  174. return "UNKNOWN";
  175. }
  176. static const char *get_jack_color(u32 cfg)
  177. {
  178. static char *names[16] = {
  179. "Unknown", "Black", "Grey", "Blue",
  180. "Green", "Red", "Orange", "Yellow",
  181. "Purple", "Pink", NULL, NULL,
  182. NULL, NULL, "White", "Other",
  183. };
  184. cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
  185. if (names[cfg])
  186. return names[cfg];
  187. else
  188. return "UNKNOWN";
  189. }
  190. static void print_pin_caps(struct snd_info_buffer *buffer,
  191. struct hda_codec *codec, hda_nid_t nid)
  192. {
  193. static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
  194. static char *jack_types[16] = {
  195. "Line Out", "Speaker", "HP Out", "CD",
  196. "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand",
  197. "Line In", "Aux", "Mic", "Telephony",
  198. "SPDIF In", "Digitial In", "Reserved", "Other"
  199. };
  200. static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
  201. unsigned int caps;
  202. caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
  203. snd_iprintf(buffer, " Pincap 0x08%x:", caps);
  204. if (caps & AC_PINCAP_IN)
  205. snd_iprintf(buffer, " IN");
  206. if (caps & AC_PINCAP_OUT)
  207. snd_iprintf(buffer, " OUT");
  208. if (caps & AC_PINCAP_HP_DRV)
  209. snd_iprintf(buffer, " HP");
  210. if (caps & AC_PINCAP_EAPD)
  211. snd_iprintf(buffer, " EAPD");
  212. if (caps & AC_PINCAP_PRES_DETECT)
  213. snd_iprintf(buffer, " Detect");
  214. snd_iprintf(buffer, "\n");
  215. caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
  216. snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
  217. jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
  218. jack_types[(caps & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT],
  219. jack_locations[(caps >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3],
  220. get_jack_location(caps));
  221. snd_iprintf(buffer, " Conn = %s, Color = %s\n",
  222. get_jack_connection(caps),
  223. get_jack_color(caps));
  224. }
  225. static void print_codec_info(struct snd_info_entry *entry,
  226. struct snd_info_buffer *buffer)
  227. {
  228. struct hda_codec *codec = entry->private_data;
  229. char buf[32];
  230. hda_nid_t nid;
  231. int i, nodes;
  232. snd_hda_get_codec_name(codec, buf, sizeof(buf));
  233. snd_iprintf(buffer, "Codec: %s\n", buf);
  234. snd_iprintf(buffer, "Address: %d\n", codec->addr);
  235. snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id);
  236. snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id);
  237. snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
  238. if (codec->mfg)
  239. snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
  240. else
  241. snd_iprintf(buffer, "No Modem Function Group found\n");
  242. if (! codec->afg)
  243. return;
  244. snd_hda_power_up(codec);
  245. snd_iprintf(buffer, "Default PCM:\n");
  246. print_pcm_caps(buffer, codec, codec->afg);
  247. snd_iprintf(buffer, "Default Amp-In caps: ");
  248. print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
  249. snd_iprintf(buffer, "Default Amp-Out caps: ");
  250. print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
  251. nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
  252. if (! nid || nodes < 0) {
  253. snd_iprintf(buffer, "Invalid AFG subtree\n");
  254. snd_hda_power_down(codec);
  255. return;
  256. }
  257. for (i = 0; i < nodes; i++, nid++) {
  258. unsigned int wid_caps =
  259. snd_hda_param_read(codec, nid,
  260. AC_PAR_AUDIO_WIDGET_CAP);
  261. unsigned int wid_type =
  262. (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  263. int conn_len = 0;
  264. hda_nid_t conn[HDA_MAX_CONNECTIONS];
  265. snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
  266. get_wid_type_name(wid_type), wid_caps);
  267. if (wid_caps & AC_WCAP_STEREO)
  268. snd_iprintf(buffer, " Stereo");
  269. else
  270. snd_iprintf(buffer, " Mono");
  271. if (wid_caps & AC_WCAP_DIGITAL)
  272. snd_iprintf(buffer, " Digital");
  273. if (wid_caps & AC_WCAP_IN_AMP)
  274. snd_iprintf(buffer, " Amp-In");
  275. if (wid_caps & AC_WCAP_OUT_AMP)
  276. snd_iprintf(buffer, " Amp-Out");
  277. snd_iprintf(buffer, "\n");
  278. if (wid_caps & AC_WCAP_CONN_LIST)
  279. conn_len = snd_hda_get_connections(codec, nid, conn,
  280. HDA_MAX_CONNECTIONS);
  281. if (wid_caps & AC_WCAP_IN_AMP) {
  282. snd_iprintf(buffer, " Amp-In caps: ");
  283. print_amp_caps(buffer, codec, nid, HDA_INPUT);
  284. snd_iprintf(buffer, " Amp-In vals: ");
  285. print_amp_vals(buffer, codec, nid, HDA_INPUT,
  286. wid_caps & AC_WCAP_STEREO, conn_len);
  287. }
  288. if (wid_caps & AC_WCAP_OUT_AMP) {
  289. snd_iprintf(buffer, " Amp-Out caps: ");
  290. print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
  291. snd_iprintf(buffer, " Amp-Out vals: ");
  292. print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
  293. wid_caps & AC_WCAP_STEREO, 1);
  294. }
  295. if (wid_type == AC_WID_PIN) {
  296. unsigned int pinctls;
  297. print_pin_caps(buffer, codec, nid);
  298. pinctls = snd_hda_codec_read(codec, nid, 0,
  299. AC_VERB_GET_PIN_WIDGET_CONTROL,
  300. 0);
  301. snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
  302. if (pinctls & AC_PINCTL_IN_EN)
  303. snd_iprintf(buffer, " IN");
  304. if (pinctls & AC_PINCTL_OUT_EN)
  305. snd_iprintf(buffer, " OUT");
  306. if (pinctls & AC_PINCTL_HP_EN)
  307. snd_iprintf(buffer, " HP");
  308. snd_iprintf(buffer, "\n");
  309. }
  310. if ((wid_type == AC_WID_AUD_OUT || wid_type == AC_WID_AUD_IN) &&
  311. (wid_caps & AC_WCAP_FORMAT_OVRD)) {
  312. snd_iprintf(buffer, " PCM:\n");
  313. print_pcm_caps(buffer, codec, nid);
  314. }
  315. if (wid_caps & AC_WCAP_POWER)
  316. snd_iprintf(buffer, " Power: 0x%x\n",
  317. snd_hda_codec_read(codec, nid, 0,
  318. AC_VERB_GET_POWER_STATE,
  319. 0));
  320. if (wid_caps & AC_WCAP_CONN_LIST) {
  321. int c, curr = -1;
  322. if (conn_len > 1 && wid_type != AC_WID_AUD_MIX)
  323. curr = snd_hda_codec_read(codec, nid, 0,
  324. AC_VERB_GET_CONNECT_SEL, 0);
  325. snd_iprintf(buffer, " Connection: %d\n", conn_len);
  326. snd_iprintf(buffer, " ");
  327. for (c = 0; c < conn_len; c++) {
  328. snd_iprintf(buffer, " 0x%02x", conn[c]);
  329. if (c == curr)
  330. snd_iprintf(buffer, "*");
  331. }
  332. snd_iprintf(buffer, "\n");
  333. }
  334. }
  335. snd_hda_power_down(codec);
  336. }
  337. /*
  338. * create a proc read
  339. */
  340. int snd_hda_codec_proc_new(struct hda_codec *codec)
  341. {
  342. char name[32];
  343. struct snd_info_entry *entry;
  344. int err;
  345. snprintf(name, sizeof(name), "codec#%d", codec->addr);
  346. err = snd_card_proc_new(codec->bus->card, name, &entry);
  347. if (err < 0)
  348. return err;
  349. snd_info_set_text_ops(entry, codec, print_codec_info);
  350. return 0;
  351. }