ac97_proc.c 18 KB

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