ca0106_proc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /*
  2. * Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk>
  3. * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit
  4. * Version: 0.0.18
  5. *
  6. * FEATURES currently supported:
  7. * See ca0106_main.c for features.
  8. *
  9. * Changelog:
  10. * Support interrupts per period.
  11. * Removed noise from Center/LFE channel when in Analog mode.
  12. * Rename and remove mixer controls.
  13. * 0.0.6
  14. * Use separate card based DMA buffer for periods table list.
  15. * 0.0.7
  16. * Change remove and rename ctrls into lists.
  17. * 0.0.8
  18. * Try to fix capture sources.
  19. * 0.0.9
  20. * Fix AC3 output.
  21. * Enable S32_LE format support.
  22. * 0.0.10
  23. * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".)
  24. * 0.0.11
  25. * Add Model name recognition.
  26. * 0.0.12
  27. * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period.
  28. * Remove redundent "voice" handling.
  29. * 0.0.13
  30. * Single trigger call for multi channels.
  31. * 0.0.14
  32. * Set limits based on what the sound card hardware can do.
  33. * playback periods_min=2, periods_max=8
  34. * capture hw constraints require period_size = n * 64 bytes.
  35. * playback hw constraints require period_size = n * 64 bytes.
  36. * 0.0.15
  37. * Separate ca0106.c into separate functional .c files.
  38. * 0.0.16
  39. * Modified Copyright message.
  40. * 0.0.17
  41. * Add iec958 file in proc file system to show status of SPDIF in.
  42. * 0.0.18
  43. * Implement support for Line-in capture on SB Live 24bit.
  44. *
  45. * This code was initially based on code from ALSA's emu10k1x.c which is:
  46. * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
  47. *
  48. * This program is free software; you can redistribute it and/or modify
  49. * it under the terms of the GNU General Public License as published by
  50. * the Free Software Foundation; either version 2 of the License, or
  51. * (at your option) any later version.
  52. *
  53. * This program is distributed in the hope that it will be useful,
  54. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  55. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  56. * GNU General Public License for more details.
  57. *
  58. * You should have received a copy of the GNU General Public License
  59. * along with this program; if not, write to the Free Software
  60. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  61. *
  62. */
  63. #include <linux/delay.h>
  64. #include <linux/init.h>
  65. #include <linux/interrupt.h>
  66. #include <linux/moduleparam.h>
  67. #include <sound/core.h>
  68. #include <sound/initval.h>
  69. #include <sound/pcm.h>
  70. #include <sound/ac97_codec.h>
  71. #include <sound/info.h>
  72. #include <sound/asoundef.h>
  73. #include <asm/io.h>
  74. #include "ca0106.h"
  75. #ifdef CONFIG_PROC_FS
  76. struct snd_ca0106_category_str {
  77. int val;
  78. const char *name;
  79. };
  80. static struct snd_ca0106_category_str snd_ca0106_con_category[] = {
  81. { IEC958_AES1_CON_DAT, "DAT" },
  82. { IEC958_AES1_CON_VCR, "VCR" },
  83. { IEC958_AES1_CON_MICROPHONE, "microphone" },
  84. { IEC958_AES1_CON_SYNTHESIZER, "synthesizer" },
  85. { IEC958_AES1_CON_RATE_CONVERTER, "rate converter" },
  86. { IEC958_AES1_CON_MIXER, "mixer" },
  87. { IEC958_AES1_CON_SAMPLER, "sampler" },
  88. { IEC958_AES1_CON_PCM_CODER, "PCM coder" },
  89. { IEC958_AES1_CON_IEC908_CD, "CD" },
  90. { IEC958_AES1_CON_NON_IEC908_CD, "non-IEC908 CD" },
  91. { IEC958_AES1_CON_GENERAL, "general" },
  92. };
  93. static void snd_ca0106_proc_dump_iec958( struct snd_info_buffer *buffer, u32 value)
  94. {
  95. int i;
  96. u32 status[4];
  97. status[0] = value & 0xff;
  98. status[1] = (value >> 8) & 0xff;
  99. status[2] = (value >> 16) & 0xff;
  100. status[3] = (value >> 24) & 0xff;
  101. if (! (status[0] & IEC958_AES0_PROFESSIONAL)) {
  102. /* consumer */
  103. snd_iprintf(buffer, "Mode: consumer\n");
  104. snd_iprintf(buffer, "Data: ");
  105. if (!(status[0] & IEC958_AES0_NONAUDIO)) {
  106. snd_iprintf(buffer, "audio\n");
  107. } else {
  108. snd_iprintf(buffer, "non-audio\n");
  109. }
  110. snd_iprintf(buffer, "Rate: ");
  111. switch (status[3] & IEC958_AES3_CON_FS) {
  112. case IEC958_AES3_CON_FS_44100:
  113. snd_iprintf(buffer, "44100 Hz\n");
  114. break;
  115. case IEC958_AES3_CON_FS_48000:
  116. snd_iprintf(buffer, "48000 Hz\n");
  117. break;
  118. case IEC958_AES3_CON_FS_32000:
  119. snd_iprintf(buffer, "32000 Hz\n");
  120. break;
  121. default:
  122. snd_iprintf(buffer, "unknown\n");
  123. break;
  124. }
  125. snd_iprintf(buffer, "Copyright: ");
  126. if (status[0] & IEC958_AES0_CON_NOT_COPYRIGHT) {
  127. snd_iprintf(buffer, "permitted\n");
  128. } else {
  129. snd_iprintf(buffer, "protected\n");
  130. }
  131. snd_iprintf(buffer, "Emphasis: ");
  132. if ((status[0] & IEC958_AES0_CON_EMPHASIS) != IEC958_AES0_CON_EMPHASIS_5015) {
  133. snd_iprintf(buffer, "none\n");
  134. } else {
  135. snd_iprintf(buffer, "50/15us\n");
  136. }
  137. snd_iprintf(buffer, "Category: ");
  138. for (i = 0; i < ARRAY_SIZE(snd_ca0106_con_category); i++) {
  139. if ((status[1] & IEC958_AES1_CON_CATEGORY) == snd_ca0106_con_category[i].val) {
  140. snd_iprintf(buffer, "%s\n", snd_ca0106_con_category[i].name);
  141. break;
  142. }
  143. }
  144. if (i >= ARRAY_SIZE(snd_ca0106_con_category)) {
  145. snd_iprintf(buffer, "unknown 0x%x\n", status[1] & IEC958_AES1_CON_CATEGORY);
  146. }
  147. snd_iprintf(buffer, "Original: ");
  148. if (status[1] & IEC958_AES1_CON_ORIGINAL) {
  149. snd_iprintf(buffer, "original\n");
  150. } else {
  151. snd_iprintf(buffer, "1st generation\n");
  152. }
  153. snd_iprintf(buffer, "Clock: ");
  154. switch (status[3] & IEC958_AES3_CON_CLOCK) {
  155. case IEC958_AES3_CON_CLOCK_1000PPM:
  156. snd_iprintf(buffer, "1000 ppm\n");
  157. break;
  158. case IEC958_AES3_CON_CLOCK_50PPM:
  159. snd_iprintf(buffer, "50 ppm\n");
  160. break;
  161. case IEC958_AES3_CON_CLOCK_VARIABLE:
  162. snd_iprintf(buffer, "variable pitch\n");
  163. break;
  164. default:
  165. snd_iprintf(buffer, "unknown\n");
  166. break;
  167. }
  168. } else {
  169. snd_iprintf(buffer, "Mode: professional\n");
  170. snd_iprintf(buffer, "Data: ");
  171. if (!(status[0] & IEC958_AES0_NONAUDIO)) {
  172. snd_iprintf(buffer, "audio\n");
  173. } else {
  174. snd_iprintf(buffer, "non-audio\n");
  175. }
  176. snd_iprintf(buffer, "Rate: ");
  177. switch (status[0] & IEC958_AES0_PRO_FS) {
  178. case IEC958_AES0_PRO_FS_44100:
  179. snd_iprintf(buffer, "44100 Hz\n");
  180. break;
  181. case IEC958_AES0_PRO_FS_48000:
  182. snd_iprintf(buffer, "48000 Hz\n");
  183. break;
  184. case IEC958_AES0_PRO_FS_32000:
  185. snd_iprintf(buffer, "32000 Hz\n");
  186. break;
  187. default:
  188. snd_iprintf(buffer, "unknown\n");
  189. break;
  190. }
  191. snd_iprintf(buffer, "Rate Locked: ");
  192. if (status[0] & IEC958_AES0_PRO_FREQ_UNLOCKED)
  193. snd_iprintf(buffer, "no\n");
  194. else
  195. snd_iprintf(buffer, "yes\n");
  196. snd_iprintf(buffer, "Emphasis: ");
  197. switch (status[0] & IEC958_AES0_PRO_EMPHASIS) {
  198. case IEC958_AES0_PRO_EMPHASIS_CCITT:
  199. snd_iprintf(buffer, "CCITT J.17\n");
  200. break;
  201. case IEC958_AES0_PRO_EMPHASIS_NONE:
  202. snd_iprintf(buffer, "none\n");
  203. break;
  204. case IEC958_AES0_PRO_EMPHASIS_5015:
  205. snd_iprintf(buffer, "50/15us\n");
  206. break;
  207. case IEC958_AES0_PRO_EMPHASIS_NOTID:
  208. default:
  209. snd_iprintf(buffer, "unknown\n");
  210. break;
  211. }
  212. snd_iprintf(buffer, "Stereophonic: ");
  213. if ((status[1] & IEC958_AES1_PRO_MODE) == IEC958_AES1_PRO_MODE_STEREOPHONIC) {
  214. snd_iprintf(buffer, "stereo\n");
  215. } else {
  216. snd_iprintf(buffer, "not indicated\n");
  217. }
  218. snd_iprintf(buffer, "Userbits: ");
  219. switch (status[1] & IEC958_AES1_PRO_USERBITS) {
  220. case IEC958_AES1_PRO_USERBITS_192:
  221. snd_iprintf(buffer, "192bit\n");
  222. break;
  223. case IEC958_AES1_PRO_USERBITS_UDEF:
  224. snd_iprintf(buffer, "user-defined\n");
  225. break;
  226. default:
  227. snd_iprintf(buffer, "unknown\n");
  228. break;
  229. }
  230. snd_iprintf(buffer, "Sample Bits: ");
  231. switch (status[2] & IEC958_AES2_PRO_SBITS) {
  232. case IEC958_AES2_PRO_SBITS_20:
  233. snd_iprintf(buffer, "20 bit\n");
  234. break;
  235. case IEC958_AES2_PRO_SBITS_24:
  236. snd_iprintf(buffer, "24 bit\n");
  237. break;
  238. case IEC958_AES2_PRO_SBITS_UDEF:
  239. snd_iprintf(buffer, "user defined\n");
  240. break;
  241. default:
  242. snd_iprintf(buffer, "unknown\n");
  243. break;
  244. }
  245. snd_iprintf(buffer, "Word Length: ");
  246. switch (status[2] & IEC958_AES2_PRO_WORDLEN) {
  247. case IEC958_AES2_PRO_WORDLEN_22_18:
  248. snd_iprintf(buffer, "22 bit or 18 bit\n");
  249. break;
  250. case IEC958_AES2_PRO_WORDLEN_23_19:
  251. snd_iprintf(buffer, "23 bit or 19 bit\n");
  252. break;
  253. case IEC958_AES2_PRO_WORDLEN_24_20:
  254. snd_iprintf(buffer, "24 bit or 20 bit\n");
  255. break;
  256. case IEC958_AES2_PRO_WORDLEN_20_16:
  257. snd_iprintf(buffer, "20 bit or 16 bit\n");
  258. break;
  259. default:
  260. snd_iprintf(buffer, "unknown\n");
  261. break;
  262. }
  263. }
  264. }
  265. static void snd_ca0106_proc_iec958(struct snd_info_entry *entry,
  266. struct snd_info_buffer *buffer)
  267. {
  268. struct snd_ca0106 *emu = entry->private_data;
  269. u32 value;
  270. value = snd_ca0106_ptr_read(emu, SAMPLE_RATE_TRACKER_STATUS, 0);
  271. snd_iprintf(buffer, "Status: %s, %s, %s\n",
  272. (value & 0x100000) ? "Rate Locked" : "Not Rate Locked",
  273. (value & 0x200000) ? "SPDIF Locked" : "No SPDIF Lock",
  274. (value & 0x400000) ? "Audio Valid" : "No valid audio" );
  275. snd_iprintf(buffer, "Estimated sample rate: %u\n",
  276. ((value & 0xfffff) * 48000) / 0x8000 );
  277. if (value & 0x200000) {
  278. snd_iprintf(buffer, "IEC958/SPDIF input status:\n");
  279. value = snd_ca0106_ptr_read(emu, SPDIF_INPUT_STATUS, 0);
  280. snd_ca0106_proc_dump_iec958(buffer, value);
  281. }
  282. snd_iprintf(buffer, "\n");
  283. }
  284. static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry,
  285. struct snd_info_buffer *buffer)
  286. {
  287. struct snd_ca0106 *emu = entry->private_data;
  288. unsigned long flags;
  289. char line[64];
  290. u32 reg, val;
  291. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  292. if (sscanf(line, "%x %x", &reg, &val) != 2)
  293. continue;
  294. if (reg < 0x40 && val <= 0xffffffff) {
  295. spin_lock_irqsave(&emu->emu_lock, flags);
  296. outl(val, emu->port + (reg & 0xfffffffc));
  297. spin_unlock_irqrestore(&emu->emu_lock, flags);
  298. }
  299. }
  300. }
  301. static void snd_ca0106_proc_reg_read32(struct snd_info_entry *entry,
  302. struct snd_info_buffer *buffer)
  303. {
  304. struct snd_ca0106 *emu = entry->private_data;
  305. unsigned long value;
  306. unsigned long flags;
  307. int i;
  308. snd_iprintf(buffer, "Registers:\n\n");
  309. for(i = 0; i < 0x20; i+=4) {
  310. spin_lock_irqsave(&emu->emu_lock, flags);
  311. value = inl(emu->port + i);
  312. spin_unlock_irqrestore(&emu->emu_lock, flags);
  313. snd_iprintf(buffer, "Register %02X: %08lX\n", i, value);
  314. }
  315. }
  316. static void snd_ca0106_proc_reg_read16(struct snd_info_entry *entry,
  317. struct snd_info_buffer *buffer)
  318. {
  319. struct snd_ca0106 *emu = entry->private_data;
  320. unsigned int value;
  321. unsigned long flags;
  322. int i;
  323. snd_iprintf(buffer, "Registers:\n\n");
  324. for(i = 0; i < 0x20; i+=2) {
  325. spin_lock_irqsave(&emu->emu_lock, flags);
  326. value = inw(emu->port + i);
  327. spin_unlock_irqrestore(&emu->emu_lock, flags);
  328. snd_iprintf(buffer, "Register %02X: %04X\n", i, value);
  329. }
  330. }
  331. static void snd_ca0106_proc_reg_read8(struct snd_info_entry *entry,
  332. struct snd_info_buffer *buffer)
  333. {
  334. struct snd_ca0106 *emu = entry->private_data;
  335. unsigned int value;
  336. unsigned long flags;
  337. int i;
  338. snd_iprintf(buffer, "Registers:\n\n");
  339. for(i = 0; i < 0x20; i+=1) {
  340. spin_lock_irqsave(&emu->emu_lock, flags);
  341. value = inb(emu->port + i);
  342. spin_unlock_irqrestore(&emu->emu_lock, flags);
  343. snd_iprintf(buffer, "Register %02X: %02X\n", i, value);
  344. }
  345. }
  346. static void snd_ca0106_proc_reg_read1(struct snd_info_entry *entry,
  347. struct snd_info_buffer *buffer)
  348. {
  349. struct snd_ca0106 *emu = entry->private_data;
  350. unsigned long value;
  351. int i,j;
  352. snd_iprintf(buffer, "Registers\n");
  353. for(i = 0; i < 0x40; i++) {
  354. snd_iprintf(buffer, "%02X: ",i);
  355. for (j = 0; j < 4; j++) {
  356. value = snd_ca0106_ptr_read(emu, i, j);
  357. snd_iprintf(buffer, "%08lX ", value);
  358. }
  359. snd_iprintf(buffer, "\n");
  360. }
  361. }
  362. static void snd_ca0106_proc_reg_read2(struct snd_info_entry *entry,
  363. struct snd_info_buffer *buffer)
  364. {
  365. struct snd_ca0106 *emu = entry->private_data;
  366. unsigned long value;
  367. int i,j;
  368. snd_iprintf(buffer, "Registers\n");
  369. for(i = 0x40; i < 0x80; i++) {
  370. snd_iprintf(buffer, "%02X: ",i);
  371. for (j = 0; j < 4; j++) {
  372. value = snd_ca0106_ptr_read(emu, i, j);
  373. snd_iprintf(buffer, "%08lX ", value);
  374. }
  375. snd_iprintf(buffer, "\n");
  376. }
  377. }
  378. static void snd_ca0106_proc_reg_write(struct snd_info_entry *entry,
  379. struct snd_info_buffer *buffer)
  380. {
  381. struct snd_ca0106 *emu = entry->private_data;
  382. char line[64];
  383. unsigned int reg, channel_id , val;
  384. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  385. if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
  386. continue;
  387. if (reg < 0x80 && val <= 0xffffffff && channel_id <= 3)
  388. snd_ca0106_ptr_write(emu, reg, channel_id, val);
  389. }
  390. }
  391. static void snd_ca0106_proc_i2c_write(struct snd_info_entry *entry,
  392. struct snd_info_buffer *buffer)
  393. {
  394. struct snd_ca0106 *emu = entry->private_data;
  395. char line[64];
  396. unsigned int reg, val;
  397. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  398. if (sscanf(line, "%x %x", &reg, &val) != 2)
  399. continue;
  400. if ((reg <= 0x7f) || (val <= 0x1ff)) {
  401. snd_ca0106_i2c_write(emu, reg, val);
  402. }
  403. }
  404. }
  405. int __devinit snd_ca0106_proc_init(struct snd_ca0106 * emu)
  406. {
  407. struct snd_info_entry *entry;
  408. if(! snd_card_proc_new(emu->card, "iec958", &entry))
  409. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_iec958);
  410. if(! snd_card_proc_new(emu->card, "ca0106_reg32", &entry)) {
  411. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read32);
  412. entry->c.text.write = snd_ca0106_proc_reg_write32;
  413. entry->mode |= S_IWUSR;
  414. }
  415. if(! snd_card_proc_new(emu->card, "ca0106_reg16", &entry))
  416. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read16);
  417. if(! snd_card_proc_new(emu->card, "ca0106_reg8", &entry))
  418. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read8);
  419. if(! snd_card_proc_new(emu->card, "ca0106_regs1", &entry)) {
  420. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read1);
  421. entry->c.text.write = snd_ca0106_proc_reg_write;
  422. entry->mode |= S_IWUSR;
  423. }
  424. if(! snd_card_proc_new(emu->card, "ca0106_i2c", &entry)) {
  425. entry->c.text.write = snd_ca0106_proc_i2c_write;
  426. entry->private_data = emu;
  427. entry->mode |= S_IWUSR;
  428. }
  429. if(! snd_card_proc_new(emu->card, "ca0106_regs2", &entry))
  430. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read2);
  431. return 0;
  432. }
  433. #endif /* CONFIG_PROC_FS */