hda_proc.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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. /* always use noncached version */
  33. #define param_read(codec, nid, parm) \
  34. snd_hdac_read_parm_uncached(&(codec)->core, nid, parm)
  35. static char *bits_names(unsigned int bits, char *names[], int size)
  36. {
  37. int i, n;
  38. static char buf[128];
  39. for (i = 0, n = 0; i < size; i++) {
  40. if (bits & (1U<<i) && names[i])
  41. n += snprintf(buf + n, sizeof(buf) - n, " %s",
  42. names[i]);
  43. }
  44. buf[n] = '\0';
  45. return buf;
  46. }
  47. static const char *get_wid_type_name(unsigned int wid_value)
  48. {
  49. static char *names[16] = {
  50. [AC_WID_AUD_OUT] = "Audio Output",
  51. [AC_WID_AUD_IN] = "Audio Input",
  52. [AC_WID_AUD_MIX] = "Audio Mixer",
  53. [AC_WID_AUD_SEL] = "Audio Selector",
  54. [AC_WID_PIN] = "Pin Complex",
  55. [AC_WID_POWER] = "Power Widget",
  56. [AC_WID_VOL_KNB] = "Volume Knob Widget",
  57. [AC_WID_BEEP] = "Beep Generator Widget",
  58. [AC_WID_VENDOR] = "Vendor Defined Widget",
  59. };
  60. if (wid_value == -1)
  61. return "UNKNOWN Widget";
  62. wid_value &= 0xf;
  63. if (names[wid_value])
  64. return names[wid_value];
  65. else
  66. return "UNKNOWN Widget";
  67. }
  68. static void print_nid_array(struct snd_info_buffer *buffer,
  69. struct hda_codec *codec, hda_nid_t nid,
  70. struct snd_array *array)
  71. {
  72. int i;
  73. struct hda_nid_item *items = array->list, *item;
  74. struct snd_kcontrol *kctl;
  75. for (i = 0; i < array->used; i++) {
  76. item = &items[i];
  77. if (item->nid == nid) {
  78. kctl = item->kctl;
  79. snd_iprintf(buffer,
  80. " Control: name=\"%s\", index=%i, device=%i\n",
  81. kctl->id.name, kctl->id.index + item->index,
  82. kctl->id.device);
  83. if (item->flags & HDA_NID_ITEM_AMP)
  84. snd_iprintf(buffer,
  85. " ControlAmp: chs=%lu, dir=%s, "
  86. "idx=%lu, ofs=%lu\n",
  87. get_amp_channels(kctl),
  88. get_amp_direction(kctl) ? "Out" : "In",
  89. get_amp_index(kctl),
  90. get_amp_offset(kctl));
  91. }
  92. }
  93. }
  94. static void print_nid_pcms(struct snd_info_buffer *buffer,
  95. struct hda_codec *codec, hda_nid_t nid)
  96. {
  97. int type;
  98. struct hda_pcm *cpcm;
  99. list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
  100. for (type = 0; type < 2; type++) {
  101. if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
  102. continue;
  103. snd_iprintf(buffer, " Device: name=\"%s\", "
  104. "type=\"%s\", device=%i\n",
  105. cpcm->name,
  106. snd_hda_pcm_type_name[cpcm->pcm_type],
  107. cpcm->pcm->device);
  108. }
  109. }
  110. }
  111. static void print_amp_caps(struct snd_info_buffer *buffer,
  112. struct hda_codec *codec, hda_nid_t nid, int dir)
  113. {
  114. unsigned int caps;
  115. caps = param_read(codec, nid, dir == HDA_OUTPUT ?
  116. AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
  117. if (caps == -1 || caps == 0) {
  118. snd_iprintf(buffer, "N/A\n");
  119. return;
  120. }
  121. snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, "
  122. "mute=%x\n",
  123. caps & AC_AMPCAP_OFFSET,
  124. (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT,
  125. (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT,
  126. (caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT);
  127. }
  128. /* is this a stereo widget or a stereo-to-mono mix? */
  129. static bool is_stereo_amps(struct hda_codec *codec, hda_nid_t nid,
  130. int dir, unsigned int wcaps, int indices)
  131. {
  132. hda_nid_t conn;
  133. if (wcaps & AC_WCAP_STEREO)
  134. return true;
  135. /* check for a stereo-to-mono mix; it must be:
  136. * only a single connection, only for input, and only a mixer widget
  137. */
  138. if (indices != 1 || dir != HDA_INPUT ||
  139. get_wcaps_type(wcaps) != AC_WID_AUD_MIX)
  140. return false;
  141. if (snd_hda_get_raw_connections(codec, nid, &conn, 1) < 0)
  142. return false;
  143. /* the connection source is a stereo? */
  144. wcaps = snd_hda_param_read(codec, conn, AC_PAR_AUDIO_WIDGET_CAP);
  145. return !!(wcaps & AC_WCAP_STEREO);
  146. }
  147. static void print_amp_vals(struct snd_info_buffer *buffer,
  148. struct hda_codec *codec, hda_nid_t nid,
  149. int dir, unsigned int wcaps, int indices)
  150. {
  151. unsigned int val;
  152. bool stereo;
  153. int i;
  154. stereo = is_stereo_amps(codec, nid, dir, wcaps, indices);
  155. dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
  156. for (i = 0; i < indices; i++) {
  157. snd_iprintf(buffer, " [");
  158. val = snd_hda_codec_read(codec, nid, 0,
  159. AC_VERB_GET_AMP_GAIN_MUTE,
  160. AC_AMP_GET_LEFT | dir | i);
  161. snd_iprintf(buffer, "0x%02x", val);
  162. if (stereo) {
  163. val = snd_hda_codec_read(codec, nid, 0,
  164. AC_VERB_GET_AMP_GAIN_MUTE,
  165. AC_AMP_GET_RIGHT | dir | i);
  166. snd_iprintf(buffer, " 0x%02x", val);
  167. }
  168. snd_iprintf(buffer, "]");
  169. }
  170. snd_iprintf(buffer, "\n");
  171. }
  172. static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
  173. {
  174. static unsigned int rates[] = {
  175. 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
  176. 96000, 176400, 192000, 384000
  177. };
  178. int i;
  179. pcm &= AC_SUPPCM_RATES;
  180. snd_iprintf(buffer, " rates [0x%x]:", pcm);
  181. for (i = 0; i < ARRAY_SIZE(rates); i++)
  182. if (pcm & (1 << i))
  183. snd_iprintf(buffer, " %d", rates[i]);
  184. snd_iprintf(buffer, "\n");
  185. }
  186. static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
  187. {
  188. char buf[SND_PRINT_BITS_ADVISED_BUFSIZE];
  189. snd_iprintf(buffer, " bits [0x%x]:", (pcm >> 16) & 0xff);
  190. snd_print_pcm_bits(pcm, buf, sizeof(buf));
  191. snd_iprintf(buffer, "%s\n", buf);
  192. }
  193. static void print_pcm_formats(struct snd_info_buffer *buffer,
  194. unsigned int streams)
  195. {
  196. snd_iprintf(buffer, " formats [0x%x]:", streams & 0xf);
  197. if (streams & AC_SUPFMT_PCM)
  198. snd_iprintf(buffer, " PCM");
  199. if (streams & AC_SUPFMT_FLOAT32)
  200. snd_iprintf(buffer, " FLOAT");
  201. if (streams & AC_SUPFMT_AC3)
  202. snd_iprintf(buffer, " AC3");
  203. snd_iprintf(buffer, "\n");
  204. }
  205. static void print_pcm_caps(struct snd_info_buffer *buffer,
  206. struct hda_codec *codec, hda_nid_t nid)
  207. {
  208. unsigned int pcm = param_read(codec, nid, AC_PAR_PCM);
  209. unsigned int stream = param_read(codec, nid, AC_PAR_STREAM);
  210. if (pcm == -1 || stream == -1) {
  211. snd_iprintf(buffer, "N/A\n");
  212. return;
  213. }
  214. print_pcm_rates(buffer, pcm);
  215. print_pcm_bits(buffer, pcm);
  216. print_pcm_formats(buffer, stream);
  217. }
  218. static const char *get_jack_connection(u32 cfg)
  219. {
  220. static char *names[16] = {
  221. "Unknown", "1/8", "1/4", "ATAPI",
  222. "RCA", "Optical","Digital", "Analog",
  223. "DIN", "XLR", "RJ11", "Comb",
  224. NULL, NULL, NULL, "Other"
  225. };
  226. cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
  227. if (names[cfg])
  228. return names[cfg];
  229. else
  230. return "UNKNOWN";
  231. }
  232. static const char *get_jack_color(u32 cfg)
  233. {
  234. static char *names[16] = {
  235. "Unknown", "Black", "Grey", "Blue",
  236. "Green", "Red", "Orange", "Yellow",
  237. "Purple", "Pink", NULL, NULL,
  238. NULL, NULL, "White", "Other",
  239. };
  240. cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
  241. if (names[cfg])
  242. return names[cfg];
  243. else
  244. return "UNKNOWN";
  245. }
  246. static void print_pin_caps(struct snd_info_buffer *buffer,
  247. struct hda_codec *codec, hda_nid_t nid,
  248. int *supports_vref)
  249. {
  250. static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
  251. unsigned int caps, val;
  252. caps = param_read(codec, nid, AC_PAR_PIN_CAP);
  253. snd_iprintf(buffer, " Pincap 0x%08x:", caps);
  254. if (caps & AC_PINCAP_IN)
  255. snd_iprintf(buffer, " IN");
  256. if (caps & AC_PINCAP_OUT)
  257. snd_iprintf(buffer, " OUT");
  258. if (caps & AC_PINCAP_HP_DRV)
  259. snd_iprintf(buffer, " HP");
  260. if (caps & AC_PINCAP_EAPD)
  261. snd_iprintf(buffer, " EAPD");
  262. if (caps & AC_PINCAP_PRES_DETECT)
  263. snd_iprintf(buffer, " Detect");
  264. if (caps & AC_PINCAP_BALANCE)
  265. snd_iprintf(buffer, " Balanced");
  266. if (caps & AC_PINCAP_HDMI) {
  267. /* Realtek uses this bit as a different meaning */
  268. if ((codec->core.vendor_id >> 16) == 0x10ec)
  269. snd_iprintf(buffer, " R/L");
  270. else {
  271. if (caps & AC_PINCAP_HBR)
  272. snd_iprintf(buffer, " HBR");
  273. snd_iprintf(buffer, " HDMI");
  274. }
  275. }
  276. if (caps & AC_PINCAP_DP)
  277. snd_iprintf(buffer, " DP");
  278. if (caps & AC_PINCAP_TRIG_REQ)
  279. snd_iprintf(buffer, " Trigger");
  280. if (caps & AC_PINCAP_IMP_SENSE)
  281. snd_iprintf(buffer, " ImpSense");
  282. snd_iprintf(buffer, "\n");
  283. if (caps & AC_PINCAP_VREF) {
  284. unsigned int vref =
  285. (caps & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  286. snd_iprintf(buffer, " Vref caps:");
  287. if (vref & AC_PINCAP_VREF_HIZ)
  288. snd_iprintf(buffer, " HIZ");
  289. if (vref & AC_PINCAP_VREF_50)
  290. snd_iprintf(buffer, " 50");
  291. if (vref & AC_PINCAP_VREF_GRD)
  292. snd_iprintf(buffer, " GRD");
  293. if (vref & AC_PINCAP_VREF_80)
  294. snd_iprintf(buffer, " 80");
  295. if (vref & AC_PINCAP_VREF_100)
  296. snd_iprintf(buffer, " 100");
  297. snd_iprintf(buffer, "\n");
  298. *supports_vref = 1;
  299. } else
  300. *supports_vref = 0;
  301. if (caps & AC_PINCAP_EAPD) {
  302. val = snd_hda_codec_read(codec, nid, 0,
  303. AC_VERB_GET_EAPD_BTLENABLE, 0);
  304. snd_iprintf(buffer, " EAPD 0x%x:", val);
  305. if (val & AC_EAPDBTL_BALANCED)
  306. snd_iprintf(buffer, " BALANCED");
  307. if (val & AC_EAPDBTL_EAPD)
  308. snd_iprintf(buffer, " EAPD");
  309. if (val & AC_EAPDBTL_LR_SWAP)
  310. snd_iprintf(buffer, " R/L");
  311. snd_iprintf(buffer, "\n");
  312. }
  313. caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
  314. snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
  315. jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
  316. snd_hda_get_jack_type(caps),
  317. snd_hda_get_jack_connectivity(caps),
  318. snd_hda_get_jack_location(caps));
  319. snd_iprintf(buffer, " Conn = %s, Color = %s\n",
  320. get_jack_connection(caps),
  321. get_jack_color(caps));
  322. /* Default association and sequence values refer to default grouping
  323. * of pin complexes and their sequence within the group. This is used
  324. * for priority and resource allocation.
  325. */
  326. snd_iprintf(buffer, " DefAssociation = 0x%x, Sequence = 0x%x\n",
  327. (caps & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT,
  328. caps & AC_DEFCFG_SEQUENCE);
  329. if (((caps & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) &
  330. AC_DEFCFG_MISC_NO_PRESENCE) {
  331. /* Miscellaneous bit indicates external hardware does not
  332. * support presence detection even if the pin complex
  333. * indicates it is supported.
  334. */
  335. snd_iprintf(buffer, " Misc = NO_PRESENCE\n");
  336. }
  337. }
  338. static void print_pin_ctls(struct snd_info_buffer *buffer,
  339. struct hda_codec *codec, hda_nid_t nid,
  340. int supports_vref)
  341. {
  342. unsigned int pinctls;
  343. pinctls = snd_hda_codec_read(codec, nid, 0,
  344. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  345. snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
  346. if (pinctls & AC_PINCTL_IN_EN)
  347. snd_iprintf(buffer, " IN");
  348. if (pinctls & AC_PINCTL_OUT_EN)
  349. snd_iprintf(buffer, " OUT");
  350. if (pinctls & AC_PINCTL_HP_EN)
  351. snd_iprintf(buffer, " HP");
  352. if (supports_vref) {
  353. int vref = pinctls & AC_PINCTL_VREFEN;
  354. switch (vref) {
  355. case AC_PINCTL_VREF_HIZ:
  356. snd_iprintf(buffer, " VREF_HIZ");
  357. break;
  358. case AC_PINCTL_VREF_50:
  359. snd_iprintf(buffer, " VREF_50");
  360. break;
  361. case AC_PINCTL_VREF_GRD:
  362. snd_iprintf(buffer, " VREF_GRD");
  363. break;
  364. case AC_PINCTL_VREF_80:
  365. snd_iprintf(buffer, " VREF_80");
  366. break;
  367. case AC_PINCTL_VREF_100:
  368. snd_iprintf(buffer, " VREF_100");
  369. break;
  370. }
  371. }
  372. snd_iprintf(buffer, "\n");
  373. }
  374. static void print_vol_knob(struct snd_info_buffer *buffer,
  375. struct hda_codec *codec, hda_nid_t nid)
  376. {
  377. unsigned int cap = param_read(codec, nid, AC_PAR_VOL_KNB_CAP);
  378. snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ",
  379. (cap >> 7) & 1, cap & 0x7f);
  380. cap = snd_hda_codec_read(codec, nid, 0,
  381. AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
  382. snd_iprintf(buffer, "direct=%d, val=%d\n",
  383. (cap >> 7) & 1, cap & 0x7f);
  384. }
  385. static void print_audio_io(struct snd_info_buffer *buffer,
  386. struct hda_codec *codec, hda_nid_t nid,
  387. unsigned int wid_type)
  388. {
  389. int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
  390. snd_iprintf(buffer,
  391. " Converter: stream=%d, channel=%d\n",
  392. (conv & AC_CONV_STREAM) >> AC_CONV_STREAM_SHIFT,
  393. conv & AC_CONV_CHANNEL);
  394. if (wid_type == AC_WID_AUD_IN && (conv & AC_CONV_CHANNEL) == 0) {
  395. int sdi = snd_hda_codec_read(codec, nid, 0,
  396. AC_VERB_GET_SDI_SELECT, 0);
  397. snd_iprintf(buffer, " SDI-Select: %d\n",
  398. sdi & AC_SDI_SELECT);
  399. }
  400. }
  401. static void print_digital_conv(struct snd_info_buffer *buffer,
  402. struct hda_codec *codec, hda_nid_t nid)
  403. {
  404. unsigned int digi1 = snd_hda_codec_read(codec, nid, 0,
  405. AC_VERB_GET_DIGI_CONVERT_1, 0);
  406. unsigned char digi2 = digi1 >> 8;
  407. unsigned char digi3 = digi1 >> 16;
  408. snd_iprintf(buffer, " Digital:");
  409. if (digi1 & AC_DIG1_ENABLE)
  410. snd_iprintf(buffer, " Enabled");
  411. if (digi1 & AC_DIG1_V)
  412. snd_iprintf(buffer, " Validity");
  413. if (digi1 & AC_DIG1_VCFG)
  414. snd_iprintf(buffer, " ValidityCfg");
  415. if (digi1 & AC_DIG1_EMPHASIS)
  416. snd_iprintf(buffer, " Preemphasis");
  417. if (digi1 & AC_DIG1_COPYRIGHT)
  418. snd_iprintf(buffer, " Non-Copyright");
  419. if (digi1 & AC_DIG1_NONAUDIO)
  420. snd_iprintf(buffer, " Non-Audio");
  421. if (digi1 & AC_DIG1_PROFESSIONAL)
  422. snd_iprintf(buffer, " Pro");
  423. if (digi1 & AC_DIG1_LEVEL)
  424. snd_iprintf(buffer, " GenLevel");
  425. if (digi3 & AC_DIG3_KAE)
  426. snd_iprintf(buffer, " KAE");
  427. snd_iprintf(buffer, "\n");
  428. snd_iprintf(buffer, " Digital category: 0x%x\n",
  429. digi2 & AC_DIG2_CC);
  430. snd_iprintf(buffer, " IEC Coding Type: 0x%x\n",
  431. digi3 & AC_DIG3_ICT);
  432. }
  433. static const char *get_pwr_state(u32 state)
  434. {
  435. static const char * const buf[] = {
  436. "D0", "D1", "D2", "D3", "D3cold"
  437. };
  438. if (state < ARRAY_SIZE(buf))
  439. return buf[state];
  440. return "UNKNOWN";
  441. }
  442. static void print_power_state(struct snd_info_buffer *buffer,
  443. struct hda_codec *codec, hda_nid_t nid)
  444. {
  445. static char *names[] = {
  446. [ilog2(AC_PWRST_D0SUP)] = "D0",
  447. [ilog2(AC_PWRST_D1SUP)] = "D1",
  448. [ilog2(AC_PWRST_D2SUP)] = "D2",
  449. [ilog2(AC_PWRST_D3SUP)] = "D3",
  450. [ilog2(AC_PWRST_D3COLDSUP)] = "D3cold",
  451. [ilog2(AC_PWRST_S3D3COLDSUP)] = "S3D3cold",
  452. [ilog2(AC_PWRST_CLKSTOP)] = "CLKSTOP",
  453. [ilog2(AC_PWRST_EPSS)] = "EPSS",
  454. };
  455. int sup = param_read(codec, nid, AC_PAR_POWER_STATE);
  456. int pwr = snd_hda_codec_read(codec, nid, 0,
  457. AC_VERB_GET_POWER_STATE, 0);
  458. if (sup != -1)
  459. snd_iprintf(buffer, " Power states: %s\n",
  460. bits_names(sup, names, ARRAY_SIZE(names)));
  461. snd_iprintf(buffer, " Power: setting=%s, actual=%s",
  462. get_pwr_state(pwr & AC_PWRST_SETTING),
  463. get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
  464. AC_PWRST_ACTUAL_SHIFT));
  465. if (pwr & AC_PWRST_ERROR)
  466. snd_iprintf(buffer, ", Error");
  467. if (pwr & AC_PWRST_CLK_STOP_OK)
  468. snd_iprintf(buffer, ", Clock-stop-OK");
  469. if (pwr & AC_PWRST_SETTING_RESET)
  470. snd_iprintf(buffer, ", Setting-reset");
  471. snd_iprintf(buffer, "\n");
  472. }
  473. static void print_unsol_cap(struct snd_info_buffer *buffer,
  474. struct hda_codec *codec, hda_nid_t nid)
  475. {
  476. int unsol = snd_hda_codec_read(codec, nid, 0,
  477. AC_VERB_GET_UNSOLICITED_RESPONSE, 0);
  478. snd_iprintf(buffer,
  479. " Unsolicited: tag=%02x, enabled=%d\n",
  480. unsol & AC_UNSOL_TAG,
  481. (unsol & AC_UNSOL_ENABLED) ? 1 : 0);
  482. }
  483. static inline bool can_dump_coef(struct hda_codec *codec)
  484. {
  485. switch (dump_coef) {
  486. case 0: return false;
  487. case 1: return true;
  488. default: return codec->dump_coef;
  489. }
  490. }
  491. static void print_proc_caps(struct snd_info_buffer *buffer,
  492. struct hda_codec *codec, hda_nid_t nid)
  493. {
  494. unsigned int i, ncoeff, oldindex;
  495. unsigned int proc_caps = param_read(codec, nid, 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 >= 0 && (cache_len != conn_len ||
  540. memcmp(list, conn, conn_len) != 0)) {
  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. 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. param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
  673. unsigned int wid_type = get_wcaps_type(wid_caps);
  674. hda_nid_t *conn = NULL;
  675. int conn_len = 0;
  676. snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
  677. get_wid_type_name(wid_type), wid_caps);
  678. if (wid_caps & AC_WCAP_STEREO) {
  679. unsigned int chans = get_wcaps_channels(wid_caps);
  680. if (chans == 2)
  681. snd_iprintf(buffer, " Stereo");
  682. else
  683. snd_iprintf(buffer, " %d-Channels", chans);
  684. } else
  685. snd_iprintf(buffer, " Mono");
  686. if (wid_caps & AC_WCAP_DIGITAL)
  687. snd_iprintf(buffer, " Digital");
  688. if (wid_caps & AC_WCAP_IN_AMP)
  689. snd_iprintf(buffer, " Amp-In");
  690. if (wid_caps & AC_WCAP_OUT_AMP)
  691. snd_iprintf(buffer, " Amp-Out");
  692. if (wid_caps & AC_WCAP_STRIPE)
  693. snd_iprintf(buffer, " Stripe");
  694. if (wid_caps & AC_WCAP_LR_SWAP)
  695. snd_iprintf(buffer, " R/L");
  696. if (wid_caps & AC_WCAP_CP_CAPS)
  697. snd_iprintf(buffer, " CP");
  698. snd_iprintf(buffer, "\n");
  699. print_nid_array(buffer, codec, nid, &codec->mixers);
  700. print_nid_array(buffer, codec, nid, &codec->nids);
  701. print_nid_pcms(buffer, codec, nid);
  702. /* volume knob is a special widget that always have connection
  703. * list
  704. */
  705. if (wid_type == AC_WID_VOL_KNB)
  706. wid_caps |= AC_WCAP_CONN_LIST;
  707. if (wid_caps & AC_WCAP_CONN_LIST) {
  708. conn_len = snd_hda_get_num_raw_conns(codec, nid);
  709. if (conn_len > 0) {
  710. conn = kmalloc(sizeof(hda_nid_t) * conn_len,
  711. GFP_KERNEL);
  712. if (!conn)
  713. return;
  714. if (snd_hda_get_raw_connections(codec, nid, conn,
  715. conn_len) < 0)
  716. conn_len = 0;
  717. }
  718. }
  719. if (wid_caps & AC_WCAP_IN_AMP) {
  720. snd_iprintf(buffer, " Amp-In caps: ");
  721. print_amp_caps(buffer, codec, nid, HDA_INPUT);
  722. snd_iprintf(buffer, " Amp-In vals: ");
  723. if (wid_type == AC_WID_PIN ||
  724. (codec->single_adc_amp &&
  725. wid_type == AC_WID_AUD_IN))
  726. print_amp_vals(buffer, codec, nid, HDA_INPUT,
  727. wid_caps, 1);
  728. else
  729. print_amp_vals(buffer, codec, nid, HDA_INPUT,
  730. wid_caps, conn_len);
  731. }
  732. if (wid_caps & AC_WCAP_OUT_AMP) {
  733. snd_iprintf(buffer, " Amp-Out caps: ");
  734. print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
  735. snd_iprintf(buffer, " Amp-Out vals: ");
  736. if (wid_type == AC_WID_PIN &&
  737. codec->pin_amp_workaround)
  738. print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
  739. wid_caps, conn_len);
  740. else
  741. print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
  742. wid_caps, 1);
  743. }
  744. switch (wid_type) {
  745. case AC_WID_PIN: {
  746. int supports_vref;
  747. print_pin_caps(buffer, codec, nid, &supports_vref);
  748. print_pin_ctls(buffer, codec, nid, supports_vref);
  749. break;
  750. }
  751. case AC_WID_VOL_KNB:
  752. print_vol_knob(buffer, codec, nid);
  753. break;
  754. case AC_WID_AUD_OUT:
  755. case AC_WID_AUD_IN:
  756. print_audio_io(buffer, codec, nid, wid_type);
  757. if (wid_caps & AC_WCAP_DIGITAL)
  758. print_digital_conv(buffer, codec, nid);
  759. if (wid_caps & AC_WCAP_FORMAT_OVRD) {
  760. snd_iprintf(buffer, " PCM:\n");
  761. print_pcm_caps(buffer, codec, nid);
  762. }
  763. break;
  764. }
  765. if (wid_caps & AC_WCAP_UNSOL_CAP)
  766. print_unsol_cap(buffer, codec, nid);
  767. if (wid_caps & AC_WCAP_POWER)
  768. print_power_state(buffer, codec, nid);
  769. if (wid_caps & AC_WCAP_DELAY)
  770. snd_iprintf(buffer, " Delay: %d samples\n",
  771. (wid_caps & AC_WCAP_DELAY) >>
  772. AC_WCAP_DELAY_SHIFT);
  773. if (wid_type == AC_WID_PIN && codec->dp_mst)
  774. print_device_list(buffer, codec, nid);
  775. if (wid_caps & AC_WCAP_CONN_LIST)
  776. print_conn_list(buffer, codec, nid, wid_type,
  777. conn, conn_len);
  778. if (wid_caps & AC_WCAP_PROC_WID)
  779. print_proc_caps(buffer, codec, nid);
  780. if (codec->proc_widget_hook)
  781. codec->proc_widget_hook(buffer, codec, nid);
  782. kfree(conn);
  783. }
  784. snd_hda_power_down(codec);
  785. }
  786. /*
  787. * create a proc read
  788. */
  789. int snd_hda_codec_proc_new(struct hda_codec *codec)
  790. {
  791. char name[32];
  792. struct snd_info_entry *entry;
  793. int err;
  794. snprintf(name, sizeof(name), "codec#%d", codec->core.addr);
  795. err = snd_card_proc_new(codec->card, name, &entry);
  796. if (err < 0)
  797. return err;
  798. snd_info_set_text_ops(entry, codec, print_codec_info);
  799. return 0;
  800. }