hda_proc.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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 <linux/init.h>
  24. #include <linux/slab.h>
  25. #include <sound/core.h>
  26. #include <linux/module.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. static int dump_coef = -1;
  30. module_param(dump_coef, int, 0644);
  31. MODULE_PARM_DESC(dump_coef, "Dump processing coefficients in codec proc file (-1=auto, 0=disable, 1=enable)");
  32. static char *bits_names(unsigned int bits, char *names[], int size)
  33. {
  34. int i, n;
  35. static char buf[128];
  36. for (i = 0, n = 0; i < size; i++) {
  37. if (bits & (1U<<i) && names[i])
  38. n += snprintf(buf + n, sizeof(buf) - n, " %s",
  39. names[i]);
  40. }
  41. buf[n] = '\0';
  42. return buf;
  43. }
  44. static const char *get_wid_type_name(unsigned int wid_value)
  45. {
  46. static char *names[16] = {
  47. [AC_WID_AUD_OUT] = "Audio Output",
  48. [AC_WID_AUD_IN] = "Audio Input",
  49. [AC_WID_AUD_MIX] = "Audio Mixer",
  50. [AC_WID_AUD_SEL] = "Audio Selector",
  51. [AC_WID_PIN] = "Pin Complex",
  52. [AC_WID_POWER] = "Power Widget",
  53. [AC_WID_VOL_KNB] = "Volume Knob Widget",
  54. [AC_WID_BEEP] = "Beep Generator Widget",
  55. [AC_WID_VENDOR] = "Vendor Defined Widget",
  56. };
  57. if (wid_value == -1)
  58. return "UNKNOWN Widget";
  59. wid_value &= 0xf;
  60. if (names[wid_value])
  61. return names[wid_value];
  62. else
  63. return "UNKNOWN Widget";
  64. }
  65. static void print_nid_array(struct snd_info_buffer *buffer,
  66. struct hda_codec *codec, hda_nid_t nid,
  67. struct snd_array *array)
  68. {
  69. int i;
  70. struct hda_nid_item *items = array->list, *item;
  71. struct snd_kcontrol *kctl;
  72. for (i = 0; i < array->used; i++) {
  73. item = &items[i];
  74. if (item->nid == nid) {
  75. kctl = item->kctl;
  76. snd_iprintf(buffer,
  77. " Control: name=\"%s\", index=%i, device=%i\n",
  78. kctl->id.name, kctl->id.index + item->index,
  79. kctl->id.device);
  80. if (item->flags & HDA_NID_ITEM_AMP)
  81. snd_iprintf(buffer,
  82. " ControlAmp: chs=%lu, dir=%s, "
  83. "idx=%lu, ofs=%lu\n",
  84. get_amp_channels(kctl),
  85. get_amp_direction(kctl) ? "Out" : "In",
  86. get_amp_index(kctl),
  87. get_amp_offset(kctl));
  88. }
  89. }
  90. }
  91. static void print_nid_pcms(struct snd_info_buffer *buffer,
  92. struct hda_codec *codec, hda_nid_t nid)
  93. {
  94. int type;
  95. struct hda_pcm *cpcm;
  96. list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
  97. for (type = 0; type < 2; type++) {
  98. if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
  99. continue;
  100. snd_iprintf(buffer, " Device: name=\"%s\", "
  101. "type=\"%s\", device=%i\n",
  102. cpcm->name,
  103. snd_hda_pcm_type_name[cpcm->pcm_type],
  104. cpcm->pcm->device);
  105. }
  106. }
  107. }
  108. static void print_amp_caps(struct snd_info_buffer *buffer,
  109. struct hda_codec *codec, hda_nid_t nid, int dir)
  110. {
  111. unsigned int caps;
  112. caps = snd_hda_param_read(codec, nid,
  113. dir == HDA_OUTPUT ?
  114. AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
  115. if (caps == -1 || caps == 0) {
  116. snd_iprintf(buffer, "N/A\n");
  117. return;
  118. }
  119. snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, "
  120. "mute=%x\n",
  121. caps & AC_AMPCAP_OFFSET,
  122. (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT,
  123. (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT,
  124. (caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT);
  125. }
  126. /* is this a stereo widget or a stereo-to-mono mix? */
  127. static bool is_stereo_amps(struct hda_codec *codec, hda_nid_t nid,
  128. int dir, unsigned int wcaps, int indices)
  129. {
  130. hda_nid_t conn;
  131. if (wcaps & AC_WCAP_STEREO)
  132. return true;
  133. /* check for a stereo-to-mono mix; it must be:
  134. * only a single connection, only for input, and only a mixer widget
  135. */
  136. if (indices != 1 || dir != HDA_INPUT ||
  137. get_wcaps_type(wcaps) != AC_WID_AUD_MIX)
  138. return false;
  139. if (snd_hda_get_raw_connections(codec, nid, &conn, 1) < 0)
  140. return false;
  141. /* the connection source is a stereo? */
  142. wcaps = snd_hda_param_read(codec, conn, AC_PAR_AUDIO_WIDGET_CAP);
  143. return !!(wcaps & AC_WCAP_STEREO);
  144. }
  145. static void print_amp_vals(struct snd_info_buffer *buffer,
  146. struct hda_codec *codec, hda_nid_t nid,
  147. int dir, unsigned int wcaps, int indices)
  148. {
  149. unsigned int val;
  150. bool stereo;
  151. int i;
  152. stereo = is_stereo_amps(codec, nid, dir, wcaps, indices);
  153. dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
  154. for (i = 0; i < indices; i++) {
  155. snd_iprintf(buffer, " [");
  156. val = snd_hda_codec_read(codec, nid, 0,
  157. AC_VERB_GET_AMP_GAIN_MUTE,
  158. AC_AMP_GET_LEFT | dir | i);
  159. snd_iprintf(buffer, "0x%02x", val);
  160. if (stereo) {
  161. val = snd_hda_codec_read(codec, nid, 0,
  162. AC_VERB_GET_AMP_GAIN_MUTE,
  163. AC_AMP_GET_RIGHT | dir | i);
  164. snd_iprintf(buffer, " 0x%02x", val);
  165. }
  166. snd_iprintf(buffer, "]");
  167. }
  168. snd_iprintf(buffer, "\n");
  169. }
  170. static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
  171. {
  172. static unsigned int rates[] = {
  173. 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
  174. 96000, 176400, 192000, 384000
  175. };
  176. int i;
  177. pcm &= AC_SUPPCM_RATES;
  178. snd_iprintf(buffer, " rates [0x%x]:", pcm);
  179. for (i = 0; i < ARRAY_SIZE(rates); i++)
  180. if (pcm & (1 << i))
  181. snd_iprintf(buffer, " %d", rates[i]);
  182. snd_iprintf(buffer, "\n");
  183. }
  184. static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
  185. {
  186. char buf[SND_PRINT_BITS_ADVISED_BUFSIZE];
  187. snd_iprintf(buffer, " bits [0x%x]:", (pcm >> 16) & 0xff);
  188. snd_print_pcm_bits(pcm, buf, sizeof(buf));
  189. snd_iprintf(buffer, "%s\n", buf);
  190. }
  191. static void print_pcm_formats(struct snd_info_buffer *buffer,
  192. unsigned int streams)
  193. {
  194. snd_iprintf(buffer, " formats [0x%x]:", streams & 0xf);
  195. if (streams & AC_SUPFMT_PCM)
  196. snd_iprintf(buffer, " PCM");
  197. if (streams & AC_SUPFMT_FLOAT32)
  198. snd_iprintf(buffer, " FLOAT");
  199. if (streams & AC_SUPFMT_AC3)
  200. snd_iprintf(buffer, " AC3");
  201. snd_iprintf(buffer, "\n");
  202. }
  203. static void print_pcm_caps(struct snd_info_buffer *buffer,
  204. struct hda_codec *codec, hda_nid_t nid)
  205. {
  206. unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM);
  207. unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
  208. if (pcm == -1 || stream == -1) {
  209. snd_iprintf(buffer, "N/A\n");
  210. return;
  211. }
  212. print_pcm_rates(buffer, pcm);
  213. print_pcm_bits(buffer, pcm);
  214. print_pcm_formats(buffer, stream);
  215. }
  216. static const char *get_jack_connection(u32 cfg)
  217. {
  218. static char *names[16] = {
  219. "Unknown", "1/8", "1/4", "ATAPI",
  220. "RCA", "Optical","Digital", "Analog",
  221. "DIN", "XLR", "RJ11", "Comb",
  222. NULL, NULL, NULL, "Other"
  223. };
  224. cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
  225. if (names[cfg])
  226. return names[cfg];
  227. else
  228. return "UNKNOWN";
  229. }
  230. static const char *get_jack_color(u32 cfg)
  231. {
  232. static char *names[16] = {
  233. "Unknown", "Black", "Grey", "Blue",
  234. "Green", "Red", "Orange", "Yellow",
  235. "Purple", "Pink", NULL, NULL,
  236. NULL, NULL, "White", "Other",
  237. };
  238. cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
  239. if (names[cfg])
  240. return names[cfg];
  241. else
  242. return "UNKNOWN";
  243. }
  244. static void print_pin_caps(struct snd_info_buffer *buffer,
  245. struct hda_codec *codec, hda_nid_t nid,
  246. int *supports_vref)
  247. {
  248. static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
  249. unsigned int caps, val;
  250. caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
  251. snd_iprintf(buffer, " Pincap 0x%08x:", caps);
  252. if (caps & AC_PINCAP_IN)
  253. snd_iprintf(buffer, " IN");
  254. if (caps & AC_PINCAP_OUT)
  255. snd_iprintf(buffer, " OUT");
  256. if (caps & AC_PINCAP_HP_DRV)
  257. snd_iprintf(buffer, " HP");
  258. if (caps & AC_PINCAP_EAPD)
  259. snd_iprintf(buffer, " EAPD");
  260. if (caps & AC_PINCAP_PRES_DETECT)
  261. snd_iprintf(buffer, " Detect");
  262. if (caps & AC_PINCAP_BALANCE)
  263. snd_iprintf(buffer, " Balanced");
  264. if (caps & AC_PINCAP_HDMI) {
  265. /* Realtek uses this bit as a different meaning */
  266. if ((codec->core.vendor_id >> 16) == 0x10ec)
  267. snd_iprintf(buffer, " R/L");
  268. else {
  269. if (caps & AC_PINCAP_HBR)
  270. snd_iprintf(buffer, " HBR");
  271. snd_iprintf(buffer, " HDMI");
  272. }
  273. }
  274. if (caps & AC_PINCAP_DP)
  275. snd_iprintf(buffer, " DP");
  276. if (caps & AC_PINCAP_TRIG_REQ)
  277. snd_iprintf(buffer, " Trigger");
  278. if (caps & AC_PINCAP_IMP_SENSE)
  279. snd_iprintf(buffer, " ImpSense");
  280. snd_iprintf(buffer, "\n");
  281. if (caps & AC_PINCAP_VREF) {
  282. unsigned int vref =
  283. (caps & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  284. snd_iprintf(buffer, " Vref caps:");
  285. if (vref & AC_PINCAP_VREF_HIZ)
  286. snd_iprintf(buffer, " HIZ");
  287. if (vref & AC_PINCAP_VREF_50)
  288. snd_iprintf(buffer, " 50");
  289. if (vref & AC_PINCAP_VREF_GRD)
  290. snd_iprintf(buffer, " GRD");
  291. if (vref & AC_PINCAP_VREF_80)
  292. snd_iprintf(buffer, " 80");
  293. if (vref & AC_PINCAP_VREF_100)
  294. snd_iprintf(buffer, " 100");
  295. snd_iprintf(buffer, "\n");
  296. *supports_vref = 1;
  297. } else
  298. *supports_vref = 0;
  299. if (caps & AC_PINCAP_EAPD) {
  300. val = snd_hda_codec_read(codec, nid, 0,
  301. AC_VERB_GET_EAPD_BTLENABLE, 0);
  302. snd_iprintf(buffer, " EAPD 0x%x:", val);
  303. if (val & AC_EAPDBTL_BALANCED)
  304. snd_iprintf(buffer, " BALANCED");
  305. if (val & AC_EAPDBTL_EAPD)
  306. snd_iprintf(buffer, " EAPD");
  307. if (val & AC_EAPDBTL_LR_SWAP)
  308. snd_iprintf(buffer, " R/L");
  309. snd_iprintf(buffer, "\n");
  310. }
  311. caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
  312. snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
  313. jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
  314. snd_hda_get_jack_type(caps),
  315. snd_hda_get_jack_connectivity(caps),
  316. snd_hda_get_jack_location(caps));
  317. snd_iprintf(buffer, " Conn = %s, Color = %s\n",
  318. get_jack_connection(caps),
  319. get_jack_color(caps));
  320. /* Default association and sequence values refer to default grouping
  321. * of pin complexes and their sequence within the group. This is used
  322. * for priority and resource allocation.
  323. */
  324. snd_iprintf(buffer, " DefAssociation = 0x%x, Sequence = 0x%x\n",
  325. (caps & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT,
  326. caps & AC_DEFCFG_SEQUENCE);
  327. if (((caps & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) &
  328. AC_DEFCFG_MISC_NO_PRESENCE) {
  329. /* Miscellaneous bit indicates external hardware does not
  330. * support presence detection even if the pin complex
  331. * indicates it is supported.
  332. */
  333. snd_iprintf(buffer, " Misc = NO_PRESENCE\n");
  334. }
  335. }
  336. static void print_pin_ctls(struct snd_info_buffer *buffer,
  337. struct hda_codec *codec, hda_nid_t nid,
  338. int supports_vref)
  339. {
  340. unsigned int pinctls;
  341. pinctls = snd_hda_codec_read(codec, nid, 0,
  342. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  343. snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
  344. if (pinctls & AC_PINCTL_IN_EN)
  345. snd_iprintf(buffer, " IN");
  346. if (pinctls & AC_PINCTL_OUT_EN)
  347. snd_iprintf(buffer, " OUT");
  348. if (pinctls & AC_PINCTL_HP_EN)
  349. snd_iprintf(buffer, " HP");
  350. if (supports_vref) {
  351. int vref = pinctls & AC_PINCTL_VREFEN;
  352. switch (vref) {
  353. case AC_PINCTL_VREF_HIZ:
  354. snd_iprintf(buffer, " VREF_HIZ");
  355. break;
  356. case AC_PINCTL_VREF_50:
  357. snd_iprintf(buffer, " VREF_50");
  358. break;
  359. case AC_PINCTL_VREF_GRD:
  360. snd_iprintf(buffer, " VREF_GRD");
  361. break;
  362. case AC_PINCTL_VREF_80:
  363. snd_iprintf(buffer, " VREF_80");
  364. break;
  365. case AC_PINCTL_VREF_100:
  366. snd_iprintf(buffer, " VREF_100");
  367. break;
  368. }
  369. }
  370. snd_iprintf(buffer, "\n");
  371. }
  372. static void print_vol_knob(struct snd_info_buffer *buffer,
  373. struct hda_codec *codec, hda_nid_t nid)
  374. {
  375. unsigned int cap = snd_hda_param_read(codec, nid,
  376. AC_PAR_VOL_KNB_CAP);
  377. snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ",
  378. (cap >> 7) & 1, cap & 0x7f);
  379. cap = snd_hda_codec_read(codec, nid, 0,
  380. AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
  381. snd_iprintf(buffer, "direct=%d, val=%d\n",
  382. (cap >> 7) & 1, cap & 0x7f);
  383. }
  384. static void print_audio_io(struct snd_info_buffer *buffer,
  385. struct hda_codec *codec, hda_nid_t nid,
  386. unsigned int wid_type)
  387. {
  388. int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
  389. snd_iprintf(buffer,
  390. " Converter: stream=%d, channel=%d\n",
  391. (conv & AC_CONV_STREAM) >> AC_CONV_STREAM_SHIFT,
  392. conv & AC_CONV_CHANNEL);
  393. if (wid_type == AC_WID_AUD_IN && (conv & AC_CONV_CHANNEL) == 0) {
  394. int sdi = snd_hda_codec_read(codec, nid, 0,
  395. AC_VERB_GET_SDI_SELECT, 0);
  396. snd_iprintf(buffer, " SDI-Select: %d\n",
  397. sdi & AC_SDI_SELECT);
  398. }
  399. }
  400. static void print_digital_conv(struct snd_info_buffer *buffer,
  401. struct hda_codec *codec, hda_nid_t nid)
  402. {
  403. unsigned int digi1 = snd_hda_codec_read(codec, nid, 0,
  404. AC_VERB_GET_DIGI_CONVERT_1, 0);
  405. unsigned char digi2 = digi1 >> 8;
  406. unsigned char digi3 = digi1 >> 16;
  407. snd_iprintf(buffer, " Digital:");
  408. if (digi1 & AC_DIG1_ENABLE)
  409. snd_iprintf(buffer, " Enabled");
  410. if (digi1 & AC_DIG1_V)
  411. snd_iprintf(buffer, " Validity");
  412. if (digi1 & AC_DIG1_VCFG)
  413. snd_iprintf(buffer, " ValidityCfg");
  414. if (digi1 & AC_DIG1_EMPHASIS)
  415. snd_iprintf(buffer, " Preemphasis");
  416. if (digi1 & AC_DIG1_COPYRIGHT)
  417. snd_iprintf(buffer, " Non-Copyright");
  418. if (digi1 & AC_DIG1_NONAUDIO)
  419. snd_iprintf(buffer, " Non-Audio");
  420. if (digi1 & AC_DIG1_PROFESSIONAL)
  421. snd_iprintf(buffer, " Pro");
  422. if (digi1 & AC_DIG1_LEVEL)
  423. snd_iprintf(buffer, " GenLevel");
  424. if (digi3 & AC_DIG3_KAE)
  425. snd_iprintf(buffer, " KAE");
  426. snd_iprintf(buffer, "\n");
  427. snd_iprintf(buffer, " Digital category: 0x%x\n",
  428. digi2 & AC_DIG2_CC);
  429. snd_iprintf(buffer, " IEC Coding Type: 0x%x\n",
  430. digi3 & AC_DIG3_ICT);
  431. }
  432. static const char *get_pwr_state(u32 state)
  433. {
  434. static const char * const buf[] = {
  435. "D0", "D1", "D2", "D3", "D3cold"
  436. };
  437. if (state < ARRAY_SIZE(buf))
  438. return buf[state];
  439. return "UNKNOWN";
  440. }
  441. static void print_power_state(struct snd_info_buffer *buffer,
  442. struct hda_codec *codec, hda_nid_t nid)
  443. {
  444. static char *names[] = {
  445. [ilog2(AC_PWRST_D0SUP)] = "D0",
  446. [ilog2(AC_PWRST_D1SUP)] = "D1",
  447. [ilog2(AC_PWRST_D2SUP)] = "D2",
  448. [ilog2(AC_PWRST_D3SUP)] = "D3",
  449. [ilog2(AC_PWRST_D3COLDSUP)] = "D3cold",
  450. [ilog2(AC_PWRST_S3D3COLDSUP)] = "S3D3cold",
  451. [ilog2(AC_PWRST_CLKSTOP)] = "CLKSTOP",
  452. [ilog2(AC_PWRST_EPSS)] = "EPSS",
  453. };
  454. int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE);
  455. int pwr = snd_hda_codec_read(codec, nid, 0,
  456. AC_VERB_GET_POWER_STATE, 0);
  457. if (sup != -1)
  458. snd_iprintf(buffer, " Power states: %s\n",
  459. bits_names(sup, names, ARRAY_SIZE(names)));
  460. snd_iprintf(buffer, " Power: setting=%s, actual=%s",
  461. get_pwr_state(pwr & AC_PWRST_SETTING),
  462. get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
  463. AC_PWRST_ACTUAL_SHIFT));
  464. if (pwr & AC_PWRST_ERROR)
  465. snd_iprintf(buffer, ", Error");
  466. if (pwr & AC_PWRST_CLK_STOP_OK)
  467. snd_iprintf(buffer, ", Clock-stop-OK");
  468. if (pwr & AC_PWRST_SETTING_RESET)
  469. snd_iprintf(buffer, ", Setting-reset");
  470. snd_iprintf(buffer, "\n");
  471. }
  472. static void print_unsol_cap(struct snd_info_buffer *buffer,
  473. struct hda_codec *codec, hda_nid_t nid)
  474. {
  475. int unsol = snd_hda_codec_read(codec, nid, 0,
  476. AC_VERB_GET_UNSOLICITED_RESPONSE, 0);
  477. snd_iprintf(buffer,
  478. " Unsolicited: tag=%02x, enabled=%d\n",
  479. unsol & AC_UNSOL_TAG,
  480. (unsol & AC_UNSOL_ENABLED) ? 1 : 0);
  481. }
  482. static inline bool can_dump_coef(struct hda_codec *codec)
  483. {
  484. switch (dump_coef) {
  485. case 0: return false;
  486. case 1: return true;
  487. default: return codec->dump_coef;
  488. }
  489. }
  490. static void print_proc_caps(struct snd_info_buffer *buffer,
  491. struct hda_codec *codec, hda_nid_t nid)
  492. {
  493. unsigned int i, ncoeff, oldindex;
  494. unsigned int proc_caps = snd_hda_param_read(codec, nid,
  495. AC_PAR_PROC_CAP);
  496. ncoeff = (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT;
  497. snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n",
  498. proc_caps & AC_PCAP_BENIGN, ncoeff);
  499. if (!can_dump_coef(codec))
  500. return;
  501. /* Note: This is racy - another process could run in parallel and change
  502. the coef index too. */
  503. oldindex = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_COEF_INDEX, 0);
  504. for (i = 0; i < ncoeff; i++) {
  505. unsigned int val;
  506. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, i);
  507. val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF,
  508. 0);
  509. snd_iprintf(buffer, " Coeff 0x%02x: 0x%04x\n", i, val);
  510. }
  511. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, oldindex);
  512. }
  513. static void print_conn_list(struct snd_info_buffer *buffer,
  514. struct hda_codec *codec, hda_nid_t nid,
  515. unsigned int wid_type, hda_nid_t *conn,
  516. int conn_len)
  517. {
  518. int c, curr = -1;
  519. const hda_nid_t *list;
  520. int cache_len;
  521. if (conn_len > 1 &&
  522. wid_type != AC_WID_AUD_MIX &&
  523. wid_type != AC_WID_VOL_KNB &&
  524. wid_type != AC_WID_POWER)
  525. curr = snd_hda_codec_read(codec, nid, 0,
  526. AC_VERB_GET_CONNECT_SEL, 0);
  527. snd_iprintf(buffer, " Connection: %d\n", conn_len);
  528. if (conn_len > 0) {
  529. snd_iprintf(buffer, " ");
  530. for (c = 0; c < conn_len; c++) {
  531. snd_iprintf(buffer, " 0x%02x", conn[c]);
  532. if (c == curr)
  533. snd_iprintf(buffer, "*");
  534. }
  535. snd_iprintf(buffer, "\n");
  536. }
  537. /* Get Cache connections info */
  538. cache_len = snd_hda_get_conn_list(codec, nid, &list);
  539. if (cache_len != conn_len
  540. || memcmp(list, conn, conn_len)) {
  541. snd_iprintf(buffer, " In-driver Connection: %d\n", cache_len);
  542. if (cache_len > 0) {
  543. snd_iprintf(buffer, " ");
  544. for (c = 0; c < cache_len; c++)
  545. snd_iprintf(buffer, " 0x%02x", list[c]);
  546. snd_iprintf(buffer, "\n");
  547. }
  548. }
  549. }
  550. static void print_gpio(struct snd_info_buffer *buffer,
  551. struct hda_codec *codec, hda_nid_t nid)
  552. {
  553. unsigned int gpio =
  554. snd_hda_param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP);
  555. unsigned int enable, direction, wake, unsol, sticky, data;
  556. int i, max;
  557. snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, "
  558. "unsolicited=%d, wake=%d\n",
  559. gpio & AC_GPIO_IO_COUNT,
  560. (gpio & AC_GPIO_O_COUNT) >> AC_GPIO_O_COUNT_SHIFT,
  561. (gpio & AC_GPIO_I_COUNT) >> AC_GPIO_I_COUNT_SHIFT,
  562. (gpio & AC_GPIO_UNSOLICITED) ? 1 : 0,
  563. (gpio & AC_GPIO_WAKE) ? 1 : 0);
  564. max = gpio & AC_GPIO_IO_COUNT;
  565. if (!max || max > 8)
  566. return;
  567. enable = snd_hda_codec_read(codec, nid, 0,
  568. AC_VERB_GET_GPIO_MASK, 0);
  569. direction = snd_hda_codec_read(codec, nid, 0,
  570. AC_VERB_GET_GPIO_DIRECTION, 0);
  571. wake = snd_hda_codec_read(codec, nid, 0,
  572. AC_VERB_GET_GPIO_WAKE_MASK, 0);
  573. unsol = snd_hda_codec_read(codec, nid, 0,
  574. AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK, 0);
  575. sticky = snd_hda_codec_read(codec, nid, 0,
  576. AC_VERB_GET_GPIO_STICKY_MASK, 0);
  577. data = snd_hda_codec_read(codec, nid, 0,
  578. AC_VERB_GET_GPIO_DATA, 0);
  579. for (i = 0; i < max; ++i)
  580. snd_iprintf(buffer,
  581. " IO[%d]: enable=%d, dir=%d, wake=%d, "
  582. "sticky=%d, data=%d, unsol=%d\n", i,
  583. (enable & (1<<i)) ? 1 : 0,
  584. (direction & (1<<i)) ? 1 : 0,
  585. (wake & (1<<i)) ? 1 : 0,
  586. (sticky & (1<<i)) ? 1 : 0,
  587. (data & (1<<i)) ? 1 : 0,
  588. (unsol & (1<<i)) ? 1 : 0);
  589. /* FIXME: add GPO and GPI pin information */
  590. print_nid_array(buffer, codec, nid, &codec->mixers);
  591. print_nid_array(buffer, codec, nid, &codec->nids);
  592. }
  593. static void print_device_list(struct snd_info_buffer *buffer,
  594. struct hda_codec *codec, hda_nid_t nid)
  595. {
  596. int i, curr = -1;
  597. u8 dev_list[AC_MAX_DEV_LIST_LEN];
  598. int devlist_len;
  599. devlist_len = snd_hda_get_devices(codec, nid, dev_list,
  600. AC_MAX_DEV_LIST_LEN);
  601. snd_iprintf(buffer, " Devices: %d\n", devlist_len);
  602. if (devlist_len <= 0)
  603. return;
  604. curr = snd_hda_codec_read(codec, nid, 0,
  605. AC_VERB_GET_DEVICE_SEL, 0);
  606. for (i = 0; i < devlist_len; i++) {
  607. if (i == curr)
  608. snd_iprintf(buffer, " *");
  609. else
  610. snd_iprintf(buffer, " ");
  611. snd_iprintf(buffer,
  612. "Dev %02d: PD = %d, ELDV = %d, IA = %d\n", i,
  613. !!(dev_list[i] & AC_DE_PD),
  614. !!(dev_list[i] & AC_DE_ELDV),
  615. !!(dev_list[i] & AC_DE_IA));
  616. }
  617. }
  618. static void print_codec_core_info(struct hdac_device *codec,
  619. struct snd_info_buffer *buffer)
  620. {
  621. snd_iprintf(buffer, "Codec: ");
  622. if (codec->vendor_name && codec->chip_name)
  623. snd_iprintf(buffer, "%s %s\n",
  624. codec->vendor_name, codec->chip_name);
  625. else
  626. snd_iprintf(buffer, "Not Set\n");
  627. snd_iprintf(buffer, "Address: %d\n", codec->addr);
  628. if (codec->afg)
  629. snd_iprintf(buffer, "AFG Function Id: 0x%x (unsol %u)\n",
  630. codec->afg_function_id, codec->afg_unsol);
  631. if (codec->mfg)
  632. snd_iprintf(buffer, "MFG Function Id: 0x%x (unsol %u)\n",
  633. codec->mfg_function_id, codec->mfg_unsol);
  634. snd_iprintf(buffer, "Vendor Id: 0x%08x\n", codec->vendor_id);
  635. snd_iprintf(buffer, "Subsystem Id: 0x%08x\n", codec->subsystem_id);
  636. snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
  637. if (codec->mfg)
  638. snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
  639. else
  640. snd_iprintf(buffer, "No Modem Function Group found\n");
  641. }
  642. static void print_codec_info(struct snd_info_entry *entry,
  643. struct snd_info_buffer *buffer)
  644. {
  645. struct hda_codec *codec = entry->private_data;
  646. hda_nid_t nid, fg;
  647. int i, nodes;
  648. print_codec_core_info(&codec->core, buffer);
  649. fg = codec->core.afg;
  650. if (!fg)
  651. return;
  652. snd_hda_power_up(codec);
  653. snd_iprintf(buffer, "Default PCM:\n");
  654. print_pcm_caps(buffer, codec, fg);
  655. snd_iprintf(buffer, "Default Amp-In caps: ");
  656. print_amp_caps(buffer, codec, fg, HDA_INPUT);
  657. snd_iprintf(buffer, "Default Amp-Out caps: ");
  658. print_amp_caps(buffer, codec, fg, HDA_OUTPUT);
  659. snd_iprintf(buffer, "State of AFG node 0x%02x:\n", fg);
  660. print_power_state(buffer, codec, fg);
  661. nodes = snd_hda_get_sub_nodes(codec, fg, &nid);
  662. if (! nid || nodes < 0) {
  663. snd_iprintf(buffer, "Invalid AFG subtree\n");
  664. snd_hda_power_down(codec);
  665. return;
  666. }
  667. print_gpio(buffer, codec, fg);
  668. if (codec->proc_widget_hook)
  669. codec->proc_widget_hook(buffer, codec, fg);
  670. for (i = 0; i < nodes; i++, nid++) {
  671. unsigned int wid_caps =
  672. snd_hda_param_read(codec, nid,
  673. AC_PAR_AUDIO_WIDGET_CAP);
  674. unsigned int wid_type = get_wcaps_type(wid_caps);
  675. hda_nid_t *conn = NULL;
  676. int conn_len = 0;
  677. snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
  678. get_wid_type_name(wid_type), wid_caps);
  679. if (wid_caps & AC_WCAP_STEREO) {
  680. unsigned int chans = get_wcaps_channels(wid_caps);
  681. if (chans == 2)
  682. snd_iprintf(buffer, " Stereo");
  683. else
  684. snd_iprintf(buffer, " %d-Channels", chans);
  685. } else
  686. snd_iprintf(buffer, " Mono");
  687. if (wid_caps & AC_WCAP_DIGITAL)
  688. snd_iprintf(buffer, " Digital");
  689. if (wid_caps & AC_WCAP_IN_AMP)
  690. snd_iprintf(buffer, " Amp-In");
  691. if (wid_caps & AC_WCAP_OUT_AMP)
  692. snd_iprintf(buffer, " Amp-Out");
  693. if (wid_caps & AC_WCAP_STRIPE)
  694. snd_iprintf(buffer, " Stripe");
  695. if (wid_caps & AC_WCAP_LR_SWAP)
  696. snd_iprintf(buffer, " R/L");
  697. if (wid_caps & AC_WCAP_CP_CAPS)
  698. snd_iprintf(buffer, " CP");
  699. snd_iprintf(buffer, "\n");
  700. print_nid_array(buffer, codec, nid, &codec->mixers);
  701. print_nid_array(buffer, codec, nid, &codec->nids);
  702. print_nid_pcms(buffer, codec, nid);
  703. /* volume knob is a special widget that always have connection
  704. * list
  705. */
  706. if (wid_type == AC_WID_VOL_KNB)
  707. wid_caps |= AC_WCAP_CONN_LIST;
  708. if (wid_caps & AC_WCAP_CONN_LIST) {
  709. conn_len = snd_hda_get_num_raw_conns(codec, nid);
  710. if (conn_len > 0) {
  711. conn = kmalloc(sizeof(hda_nid_t) * conn_len,
  712. GFP_KERNEL);
  713. if (!conn)
  714. return;
  715. if (snd_hda_get_raw_connections(codec, nid, conn,
  716. conn_len) < 0)
  717. conn_len = 0;
  718. }
  719. }
  720. if (wid_caps & AC_WCAP_IN_AMP) {
  721. snd_iprintf(buffer, " Amp-In caps: ");
  722. print_amp_caps(buffer, codec, nid, HDA_INPUT);
  723. snd_iprintf(buffer, " Amp-In vals: ");
  724. if (wid_type == AC_WID_PIN ||
  725. (codec->single_adc_amp &&
  726. wid_type == AC_WID_AUD_IN))
  727. print_amp_vals(buffer, codec, nid, HDA_INPUT,
  728. wid_caps, 1);
  729. else
  730. print_amp_vals(buffer, codec, nid, HDA_INPUT,
  731. wid_caps, conn_len);
  732. }
  733. if (wid_caps & AC_WCAP_OUT_AMP) {
  734. snd_iprintf(buffer, " Amp-Out caps: ");
  735. print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
  736. snd_iprintf(buffer, " Amp-Out vals: ");
  737. if (wid_type == AC_WID_PIN &&
  738. codec->pin_amp_workaround)
  739. print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
  740. wid_caps, conn_len);
  741. else
  742. print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
  743. wid_caps, 1);
  744. }
  745. switch (wid_type) {
  746. case AC_WID_PIN: {
  747. int supports_vref;
  748. print_pin_caps(buffer, codec, nid, &supports_vref);
  749. print_pin_ctls(buffer, codec, nid, supports_vref);
  750. break;
  751. }
  752. case AC_WID_VOL_KNB:
  753. print_vol_knob(buffer, codec, nid);
  754. break;
  755. case AC_WID_AUD_OUT:
  756. case AC_WID_AUD_IN:
  757. print_audio_io(buffer, codec, nid, wid_type);
  758. if (wid_caps & AC_WCAP_DIGITAL)
  759. print_digital_conv(buffer, codec, nid);
  760. if (wid_caps & AC_WCAP_FORMAT_OVRD) {
  761. snd_iprintf(buffer, " PCM:\n");
  762. print_pcm_caps(buffer, codec, nid);
  763. }
  764. break;
  765. }
  766. if (wid_caps & AC_WCAP_UNSOL_CAP)
  767. print_unsol_cap(buffer, codec, nid);
  768. if (wid_caps & AC_WCAP_POWER)
  769. print_power_state(buffer, codec, nid);
  770. if (wid_caps & AC_WCAP_DELAY)
  771. snd_iprintf(buffer, " Delay: %d samples\n",
  772. (wid_caps & AC_WCAP_DELAY) >>
  773. AC_WCAP_DELAY_SHIFT);
  774. if (wid_type == AC_WID_PIN && codec->dp_mst)
  775. print_device_list(buffer, codec, nid);
  776. if (wid_caps & AC_WCAP_CONN_LIST)
  777. print_conn_list(buffer, codec, nid, wid_type,
  778. conn, conn_len);
  779. if (wid_caps & AC_WCAP_PROC_WID)
  780. print_proc_caps(buffer, codec, nid);
  781. if (codec->proc_widget_hook)
  782. codec->proc_widget_hook(buffer, codec, nid);
  783. kfree(conn);
  784. }
  785. snd_hda_power_down(codec);
  786. }
  787. /*
  788. * create a proc read
  789. */
  790. int snd_hda_codec_proc_new(struct hda_codec *codec)
  791. {
  792. char name[32];
  793. struct snd_info_entry *entry;
  794. int err;
  795. snprintf(name, sizeof(name), "codec#%d", codec->core.addr);
  796. err = snd_card_proc_new(codec->card, name, &entry);
  797. if (err < 0)
  798. return err;
  799. snd_info_set_text_ops(entry, codec, print_codec_info);
  800. return 0;
  801. }