hda_proc.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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. /* is this a stereo widget or a stereo-to-mono mix? */
  128. static bool is_stereo_amps(struct hda_codec *codec, hda_nid_t nid,
  129. int dir, unsigned int wcaps, int indices)
  130. {
  131. hda_nid_t conn;
  132. if (wcaps & AC_WCAP_STEREO)
  133. return true;
  134. /* check for a stereo-to-mono mix; it must be:
  135. * only a single connection, only for input, and only a mixer widget
  136. */
  137. if (indices != 1 || dir != HDA_INPUT ||
  138. get_wcaps_type(wcaps) != AC_WID_AUD_MIX)
  139. return false;
  140. if (snd_hda_get_raw_connections(codec, nid, &conn, 1) < 0)
  141. return false;
  142. /* the connection source is a stereo? */
  143. wcaps = snd_hda_param_read(codec, conn, AC_PAR_AUDIO_WIDGET_CAP);
  144. return !!(wcaps & AC_WCAP_STEREO);
  145. }
  146. static void print_amp_vals(struct snd_info_buffer *buffer,
  147. struct hda_codec *codec, hda_nid_t nid,
  148. int dir, unsigned int wcaps, int indices)
  149. {
  150. unsigned int val;
  151. bool stereo;
  152. int i;
  153. stereo = is_stereo_amps(codec, nid, dir, wcaps, indices);
  154. dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
  155. for (i = 0; i < indices; i++) {
  156. snd_iprintf(buffer, " [");
  157. val = snd_hda_codec_read(codec, nid, 0,
  158. AC_VERB_GET_AMP_GAIN_MUTE,
  159. AC_AMP_GET_LEFT | dir | i);
  160. snd_iprintf(buffer, "0x%02x", val);
  161. if (stereo) {
  162. val = snd_hda_codec_read(codec, nid, 0,
  163. AC_VERB_GET_AMP_GAIN_MUTE,
  164. AC_AMP_GET_RIGHT | dir | i);
  165. snd_iprintf(buffer, " 0x%02x", val);
  166. }
  167. snd_iprintf(buffer, "]");
  168. }
  169. snd_iprintf(buffer, "\n");
  170. }
  171. static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
  172. {
  173. static unsigned int rates[] = {
  174. 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
  175. 96000, 176400, 192000, 384000
  176. };
  177. int i;
  178. pcm &= AC_SUPPCM_RATES;
  179. snd_iprintf(buffer, " rates [0x%x]:", pcm);
  180. for (i = 0; i < ARRAY_SIZE(rates); i++)
  181. if (pcm & (1 << i))
  182. snd_iprintf(buffer, " %d", rates[i]);
  183. snd_iprintf(buffer, "\n");
  184. }
  185. static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
  186. {
  187. char buf[SND_PRINT_BITS_ADVISED_BUFSIZE];
  188. snd_iprintf(buffer, " bits [0x%x]:", (pcm >> 16) & 0xff);
  189. snd_print_pcm_bits(pcm, buf, sizeof(buf));
  190. snd_iprintf(buffer, "%s\n", buf);
  191. }
  192. static void print_pcm_formats(struct snd_info_buffer *buffer,
  193. unsigned int streams)
  194. {
  195. snd_iprintf(buffer, " formats [0x%x]:", streams & 0xf);
  196. if (streams & AC_SUPFMT_PCM)
  197. snd_iprintf(buffer, " PCM");
  198. if (streams & AC_SUPFMT_FLOAT32)
  199. snd_iprintf(buffer, " FLOAT");
  200. if (streams & AC_SUPFMT_AC3)
  201. snd_iprintf(buffer, " AC3");
  202. snd_iprintf(buffer, "\n");
  203. }
  204. static void print_pcm_caps(struct snd_info_buffer *buffer,
  205. struct hda_codec *codec, hda_nid_t nid)
  206. {
  207. unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM);
  208. unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
  209. if (pcm == -1 || stream == -1) {
  210. snd_iprintf(buffer, "N/A\n");
  211. return;
  212. }
  213. print_pcm_rates(buffer, pcm);
  214. print_pcm_bits(buffer, pcm);
  215. print_pcm_formats(buffer, stream);
  216. }
  217. static const char *get_jack_connection(u32 cfg)
  218. {
  219. static char *names[16] = {
  220. "Unknown", "1/8", "1/4", "ATAPI",
  221. "RCA", "Optical","Digital", "Analog",
  222. "DIN", "XLR", "RJ11", "Comb",
  223. NULL, NULL, NULL, "Other"
  224. };
  225. cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
  226. if (names[cfg])
  227. return names[cfg];
  228. else
  229. return "UNKNOWN";
  230. }
  231. static const char *get_jack_color(u32 cfg)
  232. {
  233. static char *names[16] = {
  234. "Unknown", "Black", "Grey", "Blue",
  235. "Green", "Red", "Orange", "Yellow",
  236. "Purple", "Pink", NULL, NULL,
  237. NULL, NULL, "White", "Other",
  238. };
  239. cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
  240. if (names[cfg])
  241. return names[cfg];
  242. else
  243. return "UNKNOWN";
  244. }
  245. static void print_pin_caps(struct snd_info_buffer *buffer,
  246. struct hda_codec *codec, hda_nid_t nid,
  247. int *supports_vref)
  248. {
  249. static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
  250. unsigned int caps, val;
  251. caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
  252. snd_iprintf(buffer, " Pincap 0x%08x:", caps);
  253. if (caps & AC_PINCAP_IN)
  254. snd_iprintf(buffer, " IN");
  255. if (caps & AC_PINCAP_OUT)
  256. snd_iprintf(buffer, " OUT");
  257. if (caps & AC_PINCAP_HP_DRV)
  258. snd_iprintf(buffer, " HP");
  259. if (caps & AC_PINCAP_EAPD)
  260. snd_iprintf(buffer, " EAPD");
  261. if (caps & AC_PINCAP_PRES_DETECT)
  262. snd_iprintf(buffer, " Detect");
  263. if (caps & AC_PINCAP_BALANCE)
  264. snd_iprintf(buffer, " Balanced");
  265. if (caps & AC_PINCAP_HDMI) {
  266. /* Realtek uses this bit as a different meaning */
  267. if ((codec->vendor_id >> 16) == 0x10ec)
  268. snd_iprintf(buffer, " R/L");
  269. else {
  270. if (caps & AC_PINCAP_HBR)
  271. snd_iprintf(buffer, " HBR");
  272. snd_iprintf(buffer, " HDMI");
  273. }
  274. }
  275. if (caps & AC_PINCAP_DP)
  276. snd_iprintf(buffer, " DP");
  277. if (caps & AC_PINCAP_TRIG_REQ)
  278. snd_iprintf(buffer, " Trigger");
  279. if (caps & AC_PINCAP_IMP_SENSE)
  280. snd_iprintf(buffer, " ImpSense");
  281. snd_iprintf(buffer, "\n");
  282. if (caps & AC_PINCAP_VREF) {
  283. unsigned int vref =
  284. (caps & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  285. snd_iprintf(buffer, " Vref caps:");
  286. if (vref & AC_PINCAP_VREF_HIZ)
  287. snd_iprintf(buffer, " HIZ");
  288. if (vref & AC_PINCAP_VREF_50)
  289. snd_iprintf(buffer, " 50");
  290. if (vref & AC_PINCAP_VREF_GRD)
  291. snd_iprintf(buffer, " GRD");
  292. if (vref & AC_PINCAP_VREF_80)
  293. snd_iprintf(buffer, " 80");
  294. if (vref & AC_PINCAP_VREF_100)
  295. snd_iprintf(buffer, " 100");
  296. snd_iprintf(buffer, "\n");
  297. *supports_vref = 1;
  298. } else
  299. *supports_vref = 0;
  300. if (caps & AC_PINCAP_EAPD) {
  301. val = snd_hda_codec_read(codec, nid, 0,
  302. AC_VERB_GET_EAPD_BTLENABLE, 0);
  303. snd_iprintf(buffer, " EAPD 0x%x:", val);
  304. if (val & AC_EAPDBTL_BALANCED)
  305. snd_iprintf(buffer, " BALANCED");
  306. if (val & AC_EAPDBTL_EAPD)
  307. snd_iprintf(buffer, " EAPD");
  308. if (val & AC_EAPDBTL_LR_SWAP)
  309. snd_iprintf(buffer, " R/L");
  310. snd_iprintf(buffer, "\n");
  311. }
  312. caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
  313. snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
  314. jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
  315. snd_hda_get_jack_type(caps),
  316. snd_hda_get_jack_connectivity(caps),
  317. snd_hda_get_jack_location(caps));
  318. snd_iprintf(buffer, " Conn = %s, Color = %s\n",
  319. get_jack_connection(caps),
  320. get_jack_color(caps));
  321. /* Default association and sequence values refer to default grouping
  322. * of pin complexes and their sequence within the group. This is used
  323. * for priority and resource allocation.
  324. */
  325. snd_iprintf(buffer, " DefAssociation = 0x%x, Sequence = 0x%x\n",
  326. (caps & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT,
  327. caps & AC_DEFCFG_SEQUENCE);
  328. if (((caps & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) &
  329. AC_DEFCFG_MISC_NO_PRESENCE) {
  330. /* Miscellaneous bit indicates external hardware does not
  331. * support presence detection even if the pin complex
  332. * indicates it is supported.
  333. */
  334. snd_iprintf(buffer, " Misc = NO_PRESENCE\n");
  335. }
  336. }
  337. static void print_pin_ctls(struct snd_info_buffer *buffer,
  338. struct hda_codec *codec, hda_nid_t nid,
  339. int supports_vref)
  340. {
  341. unsigned int pinctls;
  342. pinctls = snd_hda_codec_read(codec, nid, 0,
  343. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  344. snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
  345. if (pinctls & AC_PINCTL_IN_EN)
  346. snd_iprintf(buffer, " IN");
  347. if (pinctls & AC_PINCTL_OUT_EN)
  348. snd_iprintf(buffer, " OUT");
  349. if (pinctls & AC_PINCTL_HP_EN)
  350. snd_iprintf(buffer, " HP");
  351. if (supports_vref) {
  352. int vref = pinctls & AC_PINCTL_VREFEN;
  353. switch (vref) {
  354. case AC_PINCTL_VREF_HIZ:
  355. snd_iprintf(buffer, " VREF_HIZ");
  356. break;
  357. case AC_PINCTL_VREF_50:
  358. snd_iprintf(buffer, " VREF_50");
  359. break;
  360. case AC_PINCTL_VREF_GRD:
  361. snd_iprintf(buffer, " VREF_GRD");
  362. break;
  363. case AC_PINCTL_VREF_80:
  364. snd_iprintf(buffer, " VREF_80");
  365. break;
  366. case AC_PINCTL_VREF_100:
  367. snd_iprintf(buffer, " VREF_100");
  368. break;
  369. }
  370. }
  371. snd_iprintf(buffer, "\n");
  372. }
  373. static void print_vol_knob(struct snd_info_buffer *buffer,
  374. struct hda_codec *codec, hda_nid_t nid)
  375. {
  376. unsigned int cap = snd_hda_param_read(codec, nid,
  377. 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 = snd_hda_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 = snd_hda_param_read(codec, nid,
  496. AC_PAR_PROC_CAP);
  497. ncoeff = (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT;
  498. snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n",
  499. proc_caps & AC_PCAP_BENIGN, ncoeff);
  500. if (!can_dump_coef(codec))
  501. return;
  502. /* Note: This is racy - another process could run in parallel and change
  503. the coef index too. */
  504. oldindex = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_COEF_INDEX, 0);
  505. for (i = 0; i < ncoeff; i++) {
  506. unsigned int val;
  507. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, i);
  508. val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF,
  509. 0);
  510. snd_iprintf(buffer, " Coeff 0x%02x: 0x%04x\n", i, val);
  511. }
  512. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, oldindex);
  513. }
  514. static void print_conn_list(struct snd_info_buffer *buffer,
  515. struct hda_codec *codec, hda_nid_t nid,
  516. unsigned int wid_type, hda_nid_t *conn,
  517. int conn_len)
  518. {
  519. int c, curr = -1;
  520. const hda_nid_t *list;
  521. int cache_len;
  522. if (conn_len > 1 &&
  523. wid_type != AC_WID_AUD_MIX &&
  524. wid_type != AC_WID_VOL_KNB &&
  525. wid_type != AC_WID_POWER)
  526. curr = snd_hda_codec_read(codec, nid, 0,
  527. AC_VERB_GET_CONNECT_SEL, 0);
  528. snd_iprintf(buffer, " Connection: %d\n", conn_len);
  529. if (conn_len > 0) {
  530. snd_iprintf(buffer, " ");
  531. for (c = 0; c < conn_len; c++) {
  532. snd_iprintf(buffer, " 0x%02x", conn[c]);
  533. if (c == curr)
  534. snd_iprintf(buffer, "*");
  535. }
  536. snd_iprintf(buffer, "\n");
  537. }
  538. /* Get Cache connections info */
  539. cache_len = snd_hda_get_conn_list(codec, nid, &list);
  540. if (cache_len != conn_len
  541. || memcmp(list, conn, conn_len)) {
  542. snd_iprintf(buffer, " In-driver Connection: %d\n", cache_len);
  543. if (cache_len > 0) {
  544. snd_iprintf(buffer, " ");
  545. for (c = 0; c < cache_len; c++)
  546. snd_iprintf(buffer, " 0x%02x", list[c]);
  547. snd_iprintf(buffer, "\n");
  548. }
  549. }
  550. }
  551. static void print_gpio(struct snd_info_buffer *buffer,
  552. struct hda_codec *codec, hda_nid_t nid)
  553. {
  554. unsigned int gpio =
  555. snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
  556. unsigned int enable, direction, wake, unsol, sticky, data;
  557. int i, max;
  558. snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, "
  559. "unsolicited=%d, wake=%d\n",
  560. gpio & AC_GPIO_IO_COUNT,
  561. (gpio & AC_GPIO_O_COUNT) >> AC_GPIO_O_COUNT_SHIFT,
  562. (gpio & AC_GPIO_I_COUNT) >> AC_GPIO_I_COUNT_SHIFT,
  563. (gpio & AC_GPIO_UNSOLICITED) ? 1 : 0,
  564. (gpio & AC_GPIO_WAKE) ? 1 : 0);
  565. max = gpio & AC_GPIO_IO_COUNT;
  566. if (!max || max > 8)
  567. return;
  568. enable = snd_hda_codec_read(codec, nid, 0,
  569. AC_VERB_GET_GPIO_MASK, 0);
  570. direction = snd_hda_codec_read(codec, nid, 0,
  571. AC_VERB_GET_GPIO_DIRECTION, 0);
  572. wake = snd_hda_codec_read(codec, nid, 0,
  573. AC_VERB_GET_GPIO_WAKE_MASK, 0);
  574. unsol = snd_hda_codec_read(codec, nid, 0,
  575. AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK, 0);
  576. sticky = snd_hda_codec_read(codec, nid, 0,
  577. AC_VERB_GET_GPIO_STICKY_MASK, 0);
  578. data = snd_hda_codec_read(codec, nid, 0,
  579. AC_VERB_GET_GPIO_DATA, 0);
  580. for (i = 0; i < max; ++i)
  581. snd_iprintf(buffer,
  582. " IO[%d]: enable=%d, dir=%d, wake=%d, "
  583. "sticky=%d, data=%d, unsol=%d\n", i,
  584. (enable & (1<<i)) ? 1 : 0,
  585. (direction & (1<<i)) ? 1 : 0,
  586. (wake & (1<<i)) ? 1 : 0,
  587. (sticky & (1<<i)) ? 1 : 0,
  588. (data & (1<<i)) ? 1 : 0,
  589. (unsol & (1<<i)) ? 1 : 0);
  590. /* FIXME: add GPO and GPI pin information */
  591. print_nid_array(buffer, codec, nid, &codec->mixers);
  592. print_nid_array(buffer, codec, nid, &codec->nids);
  593. }
  594. static void print_device_list(struct snd_info_buffer *buffer,
  595. struct hda_codec *codec, hda_nid_t nid)
  596. {
  597. int i, curr = -1;
  598. u8 dev_list[AC_MAX_DEV_LIST_LEN];
  599. int devlist_len;
  600. devlist_len = snd_hda_get_devices(codec, nid, dev_list,
  601. AC_MAX_DEV_LIST_LEN);
  602. snd_iprintf(buffer, " Devices: %d\n", devlist_len);
  603. if (devlist_len <= 0)
  604. return;
  605. curr = snd_hda_codec_read(codec, nid, 0,
  606. AC_VERB_GET_DEVICE_SEL, 0);
  607. for (i = 0; i < devlist_len; i++) {
  608. if (i == curr)
  609. snd_iprintf(buffer, " *");
  610. else
  611. snd_iprintf(buffer, " ");
  612. snd_iprintf(buffer,
  613. "Dev %02d: PD = %d, ELDV = %d, IA = %d\n", i,
  614. !!(dev_list[i] & AC_DE_PD),
  615. !!(dev_list[i] & AC_DE_ELDV),
  616. !!(dev_list[i] & AC_DE_IA));
  617. }
  618. }
  619. static void print_codec_info(struct snd_info_entry *entry,
  620. struct snd_info_buffer *buffer)
  621. {
  622. struct hda_codec *codec = entry->private_data;
  623. hda_nid_t nid;
  624. int i, nodes;
  625. snd_iprintf(buffer, "Codec: ");
  626. if (codec->vendor_name && codec->chip_name)
  627. snd_iprintf(buffer, "%s %s\n",
  628. codec->vendor_name, codec->chip_name);
  629. else
  630. snd_iprintf(buffer, "Not Set\n");
  631. snd_iprintf(buffer, "Address: %d\n", codec->addr);
  632. if (codec->afg)
  633. snd_iprintf(buffer, "AFG Function Id: 0x%x (unsol %u)\n",
  634. codec->afg_function_id, codec->afg_unsol);
  635. if (codec->mfg)
  636. snd_iprintf(buffer, "MFG Function Id: 0x%x (unsol %u)\n",
  637. codec->mfg_function_id, codec->mfg_unsol);
  638. snd_iprintf(buffer, "Vendor Id: 0x%08x\n", codec->vendor_id);
  639. snd_iprintf(buffer, "Subsystem Id: 0x%08x\n", codec->subsystem_id);
  640. snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
  641. if (codec->mfg)
  642. snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
  643. else
  644. snd_iprintf(buffer, "No Modem Function Group found\n");
  645. if (! codec->afg)
  646. return;
  647. snd_hda_power_up(codec);
  648. snd_iprintf(buffer, "Default PCM:\n");
  649. print_pcm_caps(buffer, codec, codec->afg);
  650. snd_iprintf(buffer, "Default Amp-In caps: ");
  651. print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
  652. snd_iprintf(buffer, "Default Amp-Out caps: ");
  653. print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
  654. snd_iprintf(buffer, "State of AFG node 0x%02x:\n", codec->afg);
  655. print_power_state(buffer, codec, codec->afg);
  656. nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
  657. if (! nid || nodes < 0) {
  658. snd_iprintf(buffer, "Invalid AFG subtree\n");
  659. snd_hda_power_down(codec);
  660. return;
  661. }
  662. print_gpio(buffer, codec, codec->afg);
  663. if (codec->proc_widget_hook)
  664. codec->proc_widget_hook(buffer, codec, codec->afg);
  665. for (i = 0; i < nodes; i++, nid++) {
  666. unsigned int wid_caps =
  667. snd_hda_param_read(codec, nid,
  668. AC_PAR_AUDIO_WIDGET_CAP);
  669. unsigned int wid_type = get_wcaps_type(wid_caps);
  670. hda_nid_t *conn = NULL;
  671. int conn_len = 0;
  672. snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
  673. get_wid_type_name(wid_type), wid_caps);
  674. if (wid_caps & AC_WCAP_STEREO) {
  675. unsigned int chans = get_wcaps_channels(wid_caps);
  676. if (chans == 2)
  677. snd_iprintf(buffer, " Stereo");
  678. else
  679. snd_iprintf(buffer, " %d-Channels", chans);
  680. } else
  681. snd_iprintf(buffer, " Mono");
  682. if (wid_caps & AC_WCAP_DIGITAL)
  683. snd_iprintf(buffer, " Digital");
  684. if (wid_caps & AC_WCAP_IN_AMP)
  685. snd_iprintf(buffer, " Amp-In");
  686. if (wid_caps & AC_WCAP_OUT_AMP)
  687. snd_iprintf(buffer, " Amp-Out");
  688. if (wid_caps & AC_WCAP_STRIPE)
  689. snd_iprintf(buffer, " Stripe");
  690. if (wid_caps & AC_WCAP_LR_SWAP)
  691. snd_iprintf(buffer, " R/L");
  692. if (wid_caps & AC_WCAP_CP_CAPS)
  693. snd_iprintf(buffer, " CP");
  694. snd_iprintf(buffer, "\n");
  695. print_nid_array(buffer, codec, nid, &codec->mixers);
  696. print_nid_array(buffer, codec, nid, &codec->nids);
  697. print_nid_pcms(buffer, codec, nid);
  698. /* volume knob is a special widget that always have connection
  699. * list
  700. */
  701. if (wid_type == AC_WID_VOL_KNB)
  702. wid_caps |= AC_WCAP_CONN_LIST;
  703. if (wid_caps & AC_WCAP_CONN_LIST) {
  704. conn_len = snd_hda_get_num_raw_conns(codec, nid);
  705. if (conn_len > 0) {
  706. conn = kmalloc(sizeof(hda_nid_t) * conn_len,
  707. GFP_KERNEL);
  708. if (!conn)
  709. return;
  710. if (snd_hda_get_raw_connections(codec, nid, conn,
  711. conn_len) < 0)
  712. conn_len = 0;
  713. }
  714. }
  715. if (wid_caps & AC_WCAP_IN_AMP) {
  716. snd_iprintf(buffer, " Amp-In caps: ");
  717. print_amp_caps(buffer, codec, nid, HDA_INPUT);
  718. snd_iprintf(buffer, " Amp-In vals: ");
  719. if (wid_type == AC_WID_PIN ||
  720. (codec->single_adc_amp &&
  721. wid_type == AC_WID_AUD_IN))
  722. print_amp_vals(buffer, codec, nid, HDA_INPUT,
  723. wid_caps, 1);
  724. else
  725. print_amp_vals(buffer, codec, nid, HDA_INPUT,
  726. wid_caps, conn_len);
  727. }
  728. if (wid_caps & AC_WCAP_OUT_AMP) {
  729. snd_iprintf(buffer, " Amp-Out caps: ");
  730. print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
  731. snd_iprintf(buffer, " Amp-Out vals: ");
  732. if (wid_type == AC_WID_PIN &&
  733. codec->pin_amp_workaround)
  734. print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
  735. wid_caps, conn_len);
  736. else
  737. print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
  738. wid_caps, 1);
  739. }
  740. switch (wid_type) {
  741. case AC_WID_PIN: {
  742. int supports_vref;
  743. print_pin_caps(buffer, codec, nid, &supports_vref);
  744. print_pin_ctls(buffer, codec, nid, supports_vref);
  745. break;
  746. }
  747. case AC_WID_VOL_KNB:
  748. print_vol_knob(buffer, codec, nid);
  749. break;
  750. case AC_WID_AUD_OUT:
  751. case AC_WID_AUD_IN:
  752. print_audio_io(buffer, codec, nid, wid_type);
  753. if (wid_caps & AC_WCAP_DIGITAL)
  754. print_digital_conv(buffer, codec, nid);
  755. if (wid_caps & AC_WCAP_FORMAT_OVRD) {
  756. snd_iprintf(buffer, " PCM:\n");
  757. print_pcm_caps(buffer, codec, nid);
  758. }
  759. break;
  760. }
  761. if (wid_caps & AC_WCAP_UNSOL_CAP)
  762. print_unsol_cap(buffer, codec, nid);
  763. if (wid_caps & AC_WCAP_POWER)
  764. print_power_state(buffer, codec, nid);
  765. if (wid_caps & AC_WCAP_DELAY)
  766. snd_iprintf(buffer, " Delay: %d samples\n",
  767. (wid_caps & AC_WCAP_DELAY) >>
  768. AC_WCAP_DELAY_SHIFT);
  769. if (wid_type == AC_WID_PIN && codec->dp_mst)
  770. print_device_list(buffer, codec, nid);
  771. if (wid_caps & AC_WCAP_CONN_LIST)
  772. print_conn_list(buffer, codec, nid, wid_type,
  773. conn, conn_len);
  774. if (wid_caps & AC_WCAP_PROC_WID)
  775. print_proc_caps(buffer, codec, nid);
  776. if (codec->proc_widget_hook)
  777. codec->proc_widget_hook(buffer, codec, nid);
  778. kfree(conn);
  779. }
  780. snd_hda_power_down(codec);
  781. }
  782. /*
  783. * create a proc read
  784. */
  785. int snd_hda_codec_proc_new(struct hda_codec *codec)
  786. {
  787. char name[32];
  788. struct snd_info_entry *entry;
  789. int err;
  790. snprintf(name, sizeof(name), "codec#%d", codec->addr);
  791. err = snd_card_proc_new(codec->bus->card, name, &entry);
  792. if (err < 0)
  793. return err;
  794. snd_info_set_text_ops(entry, codec, print_codec_info);
  795. return 0;
  796. }