hda_proc.c 23 KB

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