ac97_proc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * Universal interface for Audio Codec '97
  4. *
  5. * For more details look to AC '97 component specification revision 2.2
  6. * by Intel Corporation (http://developer.intel.com).
  7. *
  8. *
  9. * This program 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 program 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. */
  24. #include <linux/mutex.h>
  25. #include <sound/core.h>
  26. #include <sound/ac97_codec.h>
  27. #include <sound/asoundef.h>
  28. #include "ac97_local.h"
  29. #include "ac97_id.h"
  30. /*
  31. * proc interface
  32. */
  33. static void snd_ac97_proc_read_functions(struct snd_ac97 *ac97, struct snd_info_buffer *buffer)
  34. {
  35. int header = 0, function;
  36. unsigned short info, sense_info;
  37. static const char *function_names[12] = {
  38. "Master Out", "AUX Out", "Center/LFE Out", "SPDIF Out",
  39. "Phone In", "Mic 1", "Mic 2", "Line In", "CD In", "Video In",
  40. "Aux In", "Mono Out"
  41. };
  42. static const char *locations[8] = {
  43. "Rear I/O Panel", "Front Panel", "Motherboard", "Dock/External",
  44. "reserved", "reserved", "reserved", "NC/unused"
  45. };
  46. for (function = 0; function < 12; ++function) {
  47. snd_ac97_write(ac97, AC97_FUNC_SELECT, function << 1);
  48. info = snd_ac97_read(ac97, AC97_FUNC_INFO);
  49. if (!(info & 0x0001))
  50. continue;
  51. if (!header) {
  52. snd_iprintf(buffer, "\n Gain Inverted Buffer delay Location\n");
  53. header = 1;
  54. }
  55. sense_info = snd_ac97_read(ac97, AC97_SENSE_INFO);
  56. snd_iprintf(buffer, "%-17s: %3d.%d dBV %c %2d/fs %s\n",
  57. function_names[function],
  58. (info & 0x8000 ? -1 : 1) * ((info & 0x7000) >> 12) * 3 / 2,
  59. ((info & 0x0800) >> 11) * 5,
  60. info & 0x0400 ? 'X' : '-',
  61. (info & 0x03e0) >> 5,
  62. locations[sense_info >> 13]);
  63. }
  64. }
  65. static const char *snd_ac97_stereo_enhancements[] =
  66. {
  67. /* 0 */ "No 3D Stereo Enhancement",
  68. /* 1 */ "Analog Devices Phat Stereo",
  69. /* 2 */ "Creative Stereo Enhancement",
  70. /* 3 */ "National Semi 3D Stereo Enhancement",
  71. /* 4 */ "YAMAHA Ymersion",
  72. /* 5 */ "BBE 3D Stereo Enhancement",
  73. /* 6 */ "Crystal Semi 3D Stereo Enhancement",
  74. /* 7 */ "Qsound QXpander",
  75. /* 8 */ "Spatializer 3D Stereo Enhancement",
  76. /* 9 */ "SRS 3D Stereo Enhancement",
  77. /* 10 */ "Platform Tech 3D Stereo Enhancement",
  78. /* 11 */ "AKM 3D Audio",
  79. /* 12 */ "Aureal Stereo Enhancement",
  80. /* 13 */ "Aztech 3D Enhancement",
  81. /* 14 */ "Binaura 3D Audio Enhancement",
  82. /* 15 */ "ESS Technology Stereo Enhancement",
  83. /* 16 */ "Harman International VMAx",
  84. /* 17 */ "Nvidea/IC Ensemble/KS Waves 3D Stereo Enhancement",
  85. /* 18 */ "Philips Incredible Sound",
  86. /* 19 */ "Texas Instruments 3D Stereo Enhancement",
  87. /* 20 */ "VLSI Technology 3D Stereo Enhancement",
  88. /* 21 */ "TriTech 3D Stereo Enhancement",
  89. /* 22 */ "Realtek 3D Stereo Enhancement",
  90. /* 23 */ "Samsung 3D Stereo Enhancement",
  91. /* 24 */ "Wolfson Microelectronics 3D Enhancement",
  92. /* 25 */ "Delta Integration 3D Enhancement",
  93. /* 26 */ "SigmaTel 3D Enhancement",
  94. /* 27 */ "IC Ensemble/KS Waves",
  95. /* 28 */ "Rockwell 3D Stereo Enhancement",
  96. /* 29 */ "Reserved 29",
  97. /* 30 */ "Reserved 30",
  98. /* 31 */ "Reserved 31"
  99. };
  100. static void snd_ac97_proc_read_main(struct snd_ac97 *ac97, struct snd_info_buffer *buffer, int subidx)
  101. {
  102. char name[64];
  103. unsigned short val, tmp, ext, mext;
  104. static const char *spdif_slots[4] = { " SPDIF=3/4", " SPDIF=7/8", " SPDIF=6/9", " SPDIF=10/11" };
  105. static const char *spdif_rates[4] = { " Rate=44.1kHz", " Rate=res", " Rate=48kHz", " Rate=32kHz" };
  106. static const char *spdif_rates_cs4205[4] = { " Rate=48kHz", " Rate=44.1kHz", " Rate=res", " Rate=res" };
  107. static const char *double_rate_slots[4] = { "10/11", "7/8", "reserved", "reserved" };
  108. snd_ac97_get_name(NULL, ac97->id, name, 0);
  109. snd_iprintf(buffer, "%d-%d/%d: %s\n\n", ac97->addr, ac97->num, subidx, name);
  110. if ((ac97->scaps & AC97_SCAP_AUDIO) == 0)
  111. goto __modem;
  112. snd_iprintf(buffer, "PCI Subsys Vendor: 0x%04x\n",
  113. ac97->subsystem_vendor);
  114. snd_iprintf(buffer, "PCI Subsys Device: 0x%04x\n\n",
  115. ac97->subsystem_device);
  116. snd_iprintf(buffer, "Flags: %x\n", ac97->flags);
  117. if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) {
  118. val = snd_ac97_read(ac97, AC97_INT_PAGING);
  119. snd_ac97_update_bits(ac97, AC97_INT_PAGING,
  120. AC97_PAGE_MASK, AC97_PAGE_1);
  121. tmp = snd_ac97_read(ac97, AC97_CODEC_CLASS_REV);
  122. snd_iprintf(buffer, "Revision : 0x%02x\n", tmp & 0xff);
  123. snd_iprintf(buffer, "Compat. Class : 0x%02x\n", (tmp >> 8) & 0x1f);
  124. snd_iprintf(buffer, "Subsys. Vendor ID: 0x%04x\n",
  125. snd_ac97_read(ac97, AC97_PCI_SVID));
  126. snd_iprintf(buffer, "Subsys. ID : 0x%04x\n\n",
  127. snd_ac97_read(ac97, AC97_PCI_SID));
  128. snd_ac97_update_bits(ac97, AC97_INT_PAGING,
  129. AC97_PAGE_MASK, val & AC97_PAGE_MASK);
  130. }
  131. // val = snd_ac97_read(ac97, AC97_RESET);
  132. val = ac97->caps;
  133. snd_iprintf(buffer, "Capabilities :%s%s%s%s%s%s\n",
  134. val & AC97_BC_DEDICATED_MIC ? " -dedicated MIC PCM IN channel-" : "",
  135. val & AC97_BC_RESERVED1 ? " -reserved1-" : "",
  136. val & AC97_BC_BASS_TREBLE ? " -bass & treble-" : "",
  137. val & AC97_BC_SIM_STEREO ? " -simulated stereo-" : "",
  138. val & AC97_BC_HEADPHONE ? " -headphone out-" : "",
  139. val & AC97_BC_LOUDNESS ? " -loudness-" : "");
  140. tmp = ac97->caps & AC97_BC_DAC_MASK;
  141. snd_iprintf(buffer, "DAC resolution : %s%s%s%s\n",
  142. tmp == AC97_BC_16BIT_DAC ? "16-bit" : "",
  143. tmp == AC97_BC_18BIT_DAC ? "18-bit" : "",
  144. tmp == AC97_BC_20BIT_DAC ? "20-bit" : "",
  145. tmp == AC97_BC_DAC_MASK ? "???" : "");
  146. tmp = ac97->caps & AC97_BC_ADC_MASK;
  147. snd_iprintf(buffer, "ADC resolution : %s%s%s%s\n",
  148. tmp == AC97_BC_16BIT_ADC ? "16-bit" : "",
  149. tmp == AC97_BC_18BIT_ADC ? "18-bit" : "",
  150. tmp == AC97_BC_20BIT_ADC ? "20-bit" : "",
  151. tmp == AC97_BC_ADC_MASK ? "???" : "");
  152. snd_iprintf(buffer, "3D enhancement : %s\n",
  153. snd_ac97_stereo_enhancements[(val >> 10) & 0x1f]);
  154. snd_iprintf(buffer, "\nCurrent setup\n");
  155. val = snd_ac97_read(ac97, AC97_MIC);
  156. snd_iprintf(buffer, "Mic gain : %s [%s]\n", val & 0x0040 ? "+20dB" : "+0dB", ac97->regs[AC97_MIC] & 0x0040 ? "+20dB" : "+0dB");
  157. val = snd_ac97_read(ac97, AC97_GENERAL_PURPOSE);
  158. snd_iprintf(buffer, "POP path : %s 3D\n"
  159. "Sim. stereo : %s\n"
  160. "3D enhancement : %s\n"
  161. "Loudness : %s\n"
  162. "Mono output : %s\n"
  163. "Mic select : %s\n"
  164. "ADC/DAC loopback : %s\n",
  165. val & 0x8000 ? "post" : "pre",
  166. val & 0x4000 ? "on" : "off",
  167. val & 0x2000 ? "on" : "off",
  168. val & 0x1000 ? "on" : "off",
  169. val & 0x0200 ? "Mic" : "MIX",
  170. val & 0x0100 ? "Mic2" : "Mic1",
  171. val & 0x0080 ? "on" : "off");
  172. if (ac97->ext_id & AC97_EI_DRA)
  173. snd_iprintf(buffer, "Double rate slots: %s\n",
  174. double_rate_slots[(val >> 10) & 3]);
  175. ext = snd_ac97_read(ac97, AC97_EXTENDED_ID);
  176. if (ext == 0)
  177. goto __modem;
  178. snd_iprintf(buffer, "Extended ID : codec=%i rev=%i%s%s%s%s DSA=%i%s%s%s%s\n",
  179. (ext & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT,
  180. (ext & AC97_EI_REV_MASK) >> AC97_EI_REV_SHIFT,
  181. ext & AC97_EI_AMAP ? " AMAP" : "",
  182. ext & AC97_EI_LDAC ? " LDAC" : "",
  183. ext & AC97_EI_SDAC ? " SDAC" : "",
  184. ext & AC97_EI_CDAC ? " CDAC" : "",
  185. (ext & AC97_EI_DACS_SLOT_MASK) >> AC97_EI_DACS_SLOT_SHIFT,
  186. ext & AC97_EI_VRM ? " VRM" : "",
  187. ext & AC97_EI_SPDIF ? " SPDIF" : "",
  188. ext & AC97_EI_DRA ? " DRA" : "",
  189. ext & AC97_EI_VRA ? " VRA" : "");
  190. val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
  191. snd_iprintf(buffer, "Extended status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
  192. val & AC97_EA_PRL ? " PRL" : "",
  193. val & AC97_EA_PRK ? " PRK" : "",
  194. val & AC97_EA_PRJ ? " PRJ" : "",
  195. val & AC97_EA_PRI ? " PRI" : "",
  196. val & AC97_EA_SPCV ? " SPCV" : "",
  197. val & AC97_EA_MDAC ? " MADC" : "",
  198. val & AC97_EA_LDAC ? " LDAC" : "",
  199. val & AC97_EA_SDAC ? " SDAC" : "",
  200. val & AC97_EA_CDAC ? " CDAC" : "",
  201. ext & AC97_EI_SPDIF ? spdif_slots[(val & AC97_EA_SPSA_SLOT_MASK) >> AC97_EA_SPSA_SLOT_SHIFT] : "",
  202. val & AC97_EA_VRM ? " VRM" : "",
  203. val & AC97_EA_SPDIF ? " SPDIF" : "",
  204. val & AC97_EA_DRA ? " DRA" : "",
  205. val & AC97_EA_VRA ? " VRA" : "");
  206. if (ext & AC97_EI_VRA) { /* VRA */
  207. val = snd_ac97_read(ac97, AC97_PCM_FRONT_DAC_RATE);
  208. snd_iprintf(buffer, "PCM front DAC : %iHz\n", val);
  209. if (ext & AC97_EI_SDAC) {
  210. val = snd_ac97_read(ac97, AC97_PCM_SURR_DAC_RATE);
  211. snd_iprintf(buffer, "PCM Surr DAC : %iHz\n", val);
  212. }
  213. if (ext & AC97_EI_LDAC) {
  214. val = snd_ac97_read(ac97, AC97_PCM_LFE_DAC_RATE);
  215. snd_iprintf(buffer, "PCM LFE DAC : %iHz\n", val);
  216. }
  217. val = snd_ac97_read(ac97, AC97_PCM_LR_ADC_RATE);
  218. snd_iprintf(buffer, "PCM ADC : %iHz\n", val);
  219. }
  220. if (ext & AC97_EI_VRM) {
  221. val = snd_ac97_read(ac97, AC97_PCM_MIC_ADC_RATE);
  222. snd_iprintf(buffer, "PCM MIC ADC : %iHz\n", val);
  223. }
  224. if ((ext & AC97_EI_SPDIF) || (ac97->flags & AC97_CS_SPDIF) ||
  225. (ac97->id == AC97_ID_YMF743)) {
  226. if (ac97->flags & AC97_CS_SPDIF)
  227. val = snd_ac97_read(ac97, AC97_CSR_SPDIF);
  228. else if (ac97->id == AC97_ID_YMF743) {
  229. val = snd_ac97_read(ac97, AC97_YMF7X3_DIT_CTRL);
  230. val = 0x2000 | (val & 0xff00) >> 4 | (val & 0x38) >> 2;
  231. } else
  232. val = snd_ac97_read(ac97, AC97_SPDIF);
  233. snd_iprintf(buffer, "SPDIF Control :%s%s%s%s Category=0x%x Generation=%i%s%s%s\n",
  234. val & AC97_SC_PRO ? " PRO" : " Consumer",
  235. val & AC97_SC_NAUDIO ? " Non-audio" : " PCM",
  236. val & AC97_SC_COPY ? "" : " Copyright",
  237. val & AC97_SC_PRE ? " Preemph50/15" : "",
  238. (val & AC97_SC_CC_MASK) >> AC97_SC_CC_SHIFT,
  239. (val & AC97_SC_L) >> 11,
  240. (ac97->flags & AC97_CS_SPDIF) ?
  241. spdif_rates_cs4205[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT] :
  242. spdif_rates[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT],
  243. (ac97->flags & AC97_CS_SPDIF) ?
  244. (val & AC97_SC_DRS ? " Validity" : "") :
  245. (val & AC97_SC_DRS ? " DRS" : ""),
  246. (ac97->flags & AC97_CS_SPDIF) ?
  247. (val & AC97_SC_V ? " Enabled" : "") :
  248. (val & AC97_SC_V ? " Validity" : ""));
  249. /* ALC650 specific*/
  250. if ((ac97->id & 0xfffffff0) == 0x414c4720 &&
  251. (snd_ac97_read(ac97, AC97_ALC650_CLOCK) & 0x01)) {
  252. val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2);
  253. if (val & AC97_ALC650_CLOCK_LOCK) {
  254. val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS1);
  255. snd_iprintf(buffer, "SPDIF In Status :%s%s%s%s Category=0x%x Generation=%i",
  256. val & AC97_ALC650_PRO ? " PRO" : " Consumer",
  257. val & AC97_ALC650_NAUDIO ? " Non-audio" : " PCM",
  258. val & AC97_ALC650_COPY ? "" : " Copyright",
  259. val & AC97_ALC650_PRE ? " Preemph50/15" : "",
  260. (val & AC97_ALC650_CC_MASK) >> AC97_ALC650_CC_SHIFT,
  261. (val & AC97_ALC650_L) >> 15);
  262. val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2);
  263. snd_iprintf(buffer, "%s Accuracy=%i%s%s\n",
  264. spdif_rates[(val & AC97_ALC650_SPSR_MASK) >> AC97_ALC650_SPSR_SHIFT],
  265. (val & AC97_ALC650_CLOCK_ACCURACY) >> AC97_ALC650_CLOCK_SHIFT,
  266. (val & AC97_ALC650_CLOCK_LOCK ? " Locked" : " Unlocked"),
  267. (val & AC97_ALC650_V ? " Validity?" : ""));
  268. } else {
  269. snd_iprintf(buffer, "SPDIF In Status : Not Locked\n");
  270. }
  271. }
  272. }
  273. if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) {
  274. val = snd_ac97_read(ac97, AC97_INT_PAGING);
  275. snd_ac97_update_bits(ac97, AC97_INT_PAGING,
  276. AC97_PAGE_MASK, AC97_PAGE_1);
  277. snd_ac97_proc_read_functions(ac97, buffer);
  278. snd_ac97_update_bits(ac97, AC97_INT_PAGING,
  279. AC97_PAGE_MASK, val & AC97_PAGE_MASK);
  280. }
  281. __modem:
  282. mext = snd_ac97_read(ac97, AC97_EXTENDED_MID);
  283. if (mext == 0)
  284. return;
  285. snd_iprintf(buffer, "Extended modem ID: codec=%i%s%s%s%s%s\n",
  286. (mext & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT,
  287. mext & AC97_MEI_CID2 ? " CID2" : "",
  288. mext & AC97_MEI_CID1 ? " CID1" : "",
  289. mext & AC97_MEI_HANDSET ? " HSET" : "",
  290. mext & AC97_MEI_LINE2 ? " LIN2" : "",
  291. mext & AC97_MEI_LINE1 ? " LIN1" : "");
  292. val = snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS);
  293. snd_iprintf(buffer, "Modem status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
  294. val & AC97_MEA_GPIO ? " GPIO" : "",
  295. val & AC97_MEA_MREF ? " MREF" : "",
  296. val & AC97_MEA_ADC1 ? " ADC1" : "",
  297. val & AC97_MEA_DAC1 ? " DAC1" : "",
  298. val & AC97_MEA_ADC2 ? " ADC2" : "",
  299. val & AC97_MEA_DAC2 ? " DAC2" : "",
  300. val & AC97_MEA_HADC ? " HADC" : "",
  301. val & AC97_MEA_HDAC ? " HDAC" : "",
  302. val & AC97_MEA_PRA ? " PRA(GPIO)" : "",
  303. val & AC97_MEA_PRB ? " PRB(res)" : "",
  304. val & AC97_MEA_PRC ? " PRC(ADC1)" : "",
  305. val & AC97_MEA_PRD ? " PRD(DAC1)" : "",
  306. val & AC97_MEA_PRE ? " PRE(ADC2)" : "",
  307. val & AC97_MEA_PRF ? " PRF(DAC2)" : "",
  308. val & AC97_MEA_PRG ? " PRG(HADC)" : "",
  309. val & AC97_MEA_PRH ? " PRH(HDAC)" : "");
  310. if (mext & AC97_MEI_LINE1) {
  311. val = snd_ac97_read(ac97, AC97_LINE1_RATE);
  312. snd_iprintf(buffer, "Line1 rate : %iHz\n", val);
  313. }
  314. if (mext & AC97_MEI_LINE2) {
  315. val = snd_ac97_read(ac97, AC97_LINE2_RATE);
  316. snd_iprintf(buffer, "Line2 rate : %iHz\n", val);
  317. }
  318. if (mext & AC97_MEI_HANDSET) {
  319. val = snd_ac97_read(ac97, AC97_HANDSET_RATE);
  320. snd_iprintf(buffer, "Headset rate : %iHz\n", val);
  321. }
  322. }
  323. static void snd_ac97_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  324. {
  325. struct snd_ac97 *ac97 = entry->private_data;
  326. mutex_lock(&ac97->page_mutex);
  327. if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86
  328. int idx;
  329. for (idx = 0; idx < 3; idx++)
  330. if (ac97->spec.ad18xx.id[idx]) {
  331. /* select single codec */
  332. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
  333. ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]);
  334. snd_ac97_proc_read_main(ac97, buffer, idx);
  335. snd_iprintf(buffer, "\n\n");
  336. }
  337. /* select all codecs */
  338. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
  339. snd_iprintf(buffer, "\nAD18XX configuration\n");
  340. snd_iprintf(buffer, "Unchained : 0x%04x,0x%04x,0x%04x\n",
  341. ac97->spec.ad18xx.unchained[0],
  342. ac97->spec.ad18xx.unchained[1],
  343. ac97->spec.ad18xx.unchained[2]);
  344. snd_iprintf(buffer, "Chained : 0x%04x,0x%04x,0x%04x\n",
  345. ac97->spec.ad18xx.chained[0],
  346. ac97->spec.ad18xx.chained[1],
  347. ac97->spec.ad18xx.chained[2]);
  348. } else {
  349. snd_ac97_proc_read_main(ac97, buffer, 0);
  350. }
  351. mutex_unlock(&ac97->page_mutex);
  352. }
  353. #ifdef CONFIG_SND_DEBUG
  354. /* direct register write for debugging */
  355. static void snd_ac97_proc_regs_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  356. {
  357. struct snd_ac97 *ac97 = entry->private_data;
  358. char line[64];
  359. unsigned int reg, val;
  360. mutex_lock(&ac97->page_mutex);
  361. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  362. if (sscanf(line, "%x %x", &reg, &val) != 2)
  363. continue;
  364. /* register must be even */
  365. if (reg < 0x80 && (reg & 1) == 0 && val <= 0xffff)
  366. snd_ac97_write_cache(ac97, reg, val);
  367. }
  368. mutex_unlock(&ac97->page_mutex);
  369. }
  370. #endif
  371. static void snd_ac97_proc_regs_read_main(struct snd_ac97 *ac97, struct snd_info_buffer *buffer, int subidx)
  372. {
  373. int reg, val;
  374. for (reg = 0; reg < 0x80; reg += 2) {
  375. val = snd_ac97_read(ac97, reg);
  376. snd_iprintf(buffer, "%i:%02x = %04x\n", subidx, reg, val);
  377. }
  378. }
  379. static void snd_ac97_proc_regs_read(struct snd_info_entry *entry,
  380. struct snd_info_buffer *buffer)
  381. {
  382. struct snd_ac97 *ac97 = entry->private_data;
  383. mutex_lock(&ac97->page_mutex);
  384. if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86
  385. int idx;
  386. for (idx = 0; idx < 3; idx++)
  387. if (ac97->spec.ad18xx.id[idx]) {
  388. /* select single codec */
  389. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
  390. ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]);
  391. snd_ac97_proc_regs_read_main(ac97, buffer, idx);
  392. }
  393. /* select all codecs */
  394. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
  395. } else {
  396. snd_ac97_proc_regs_read_main(ac97, buffer, 0);
  397. }
  398. mutex_unlock(&ac97->page_mutex);
  399. }
  400. void snd_ac97_proc_init(struct snd_ac97 * ac97)
  401. {
  402. struct snd_info_entry *entry;
  403. char name[32];
  404. const char *prefix;
  405. if (ac97->bus->proc == NULL)
  406. return;
  407. prefix = ac97_is_audio(ac97) ? "ac97" : "mc97";
  408. sprintf(name, "%s#%d-%d", prefix, ac97->addr, ac97->num);
  409. if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) {
  410. snd_info_set_text_ops(entry, ac97, snd_ac97_proc_read);
  411. if (snd_info_register(entry) < 0) {
  412. snd_info_free_entry(entry);
  413. entry = NULL;
  414. }
  415. }
  416. ac97->proc = entry;
  417. sprintf(name, "%s#%d-%d+regs", prefix, ac97->addr, ac97->num);
  418. if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) {
  419. snd_info_set_text_ops(entry, ac97, snd_ac97_proc_regs_read);
  420. #ifdef CONFIG_SND_DEBUG
  421. entry->mode |= S_IWUSR;
  422. entry->c.text.write = snd_ac97_proc_regs_write;
  423. #endif
  424. if (snd_info_register(entry) < 0) {
  425. snd_info_free_entry(entry);
  426. entry = NULL;
  427. }
  428. }
  429. ac97->proc_regs = entry;
  430. }
  431. void snd_ac97_proc_done(struct snd_ac97 * ac97)
  432. {
  433. snd_info_free_entry(ac97->proc_regs);
  434. ac97->proc_regs = NULL;
  435. snd_info_free_entry(ac97->proc);
  436. ac97->proc = NULL;
  437. }
  438. void snd_ac97_bus_proc_init(struct snd_ac97_bus * bus)
  439. {
  440. struct snd_info_entry *entry;
  441. char name[32];
  442. sprintf(name, "codec97#%d", bus->num);
  443. if ((entry = snd_info_create_card_entry(bus->card, name, bus->card->proc_root)) != NULL) {
  444. entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  445. if (snd_info_register(entry) < 0) {
  446. snd_info_free_entry(entry);
  447. entry = NULL;
  448. }
  449. }
  450. bus->proc = entry;
  451. }
  452. void snd_ac97_bus_proc_done(struct snd_ac97_bus * bus)
  453. {
  454. snd_info_free_entry(bus->proc);
  455. bus->proc = NULL;
  456. }