hda_proc.c 25 KB

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