ca0106_proc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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 initally 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 <sound/driver.h>
  64. #include <linux/delay.h>
  65. #include <linux/init.h>
  66. #include <linux/interrupt.h>
  67. #include <linux/pci.h>
  68. #include <linux/slab.h>
  69. #include <linux/moduleparam.h>
  70. #include <sound/core.h>
  71. #include <sound/initval.h>
  72. #include <sound/pcm.h>
  73. #include <sound/ac97_codec.h>
  74. #include <sound/info.h>
  75. #include <sound/asoundef.h>
  76. #include "ca0106.h"
  77. #ifdef CONFIG_PROC_FS
  78. struct snd_ca0106_category_str {
  79. int val;
  80. const char *name;
  81. };
  82. static struct snd_ca0106_category_str snd_ca0106_con_category[] = {
  83. { IEC958_AES1_CON_DAT, "DAT" },
  84. { IEC958_AES1_CON_VCR, "VCR" },
  85. { IEC958_AES1_CON_MICROPHONE, "microphone" },
  86. { IEC958_AES1_CON_SYNTHESIZER, "synthesizer" },
  87. { IEC958_AES1_CON_RATE_CONVERTER, "rate converter" },
  88. { IEC958_AES1_CON_MIXER, "mixer" },
  89. { IEC958_AES1_CON_SAMPLER, "sampler" },
  90. { IEC958_AES1_CON_PCM_CODER, "PCM coder" },
  91. { IEC958_AES1_CON_IEC908_CD, "CD" },
  92. { IEC958_AES1_CON_NON_IEC908_CD, "non-IEC908 CD" },
  93. { IEC958_AES1_CON_GENERAL, "general" },
  94. };
  95. static void snd_ca0106_proc_dump_iec958( struct snd_info_buffer *buffer, u32 value)
  96. {
  97. int i;
  98. u32 status[4];
  99. status[0] = value & 0xff;
  100. status[1] = (value >> 8) & 0xff;
  101. status[2] = (value >> 16) & 0xff;
  102. status[3] = (value >> 24) & 0xff;
  103. if (! (status[0] & IEC958_AES0_PROFESSIONAL)) {
  104. /* consumer */
  105. snd_iprintf(buffer, "Mode: consumer\n");
  106. snd_iprintf(buffer, "Data: ");
  107. if (!(status[0] & IEC958_AES0_NONAUDIO)) {
  108. snd_iprintf(buffer, "audio\n");
  109. } else {
  110. snd_iprintf(buffer, "non-audio\n");
  111. }
  112. snd_iprintf(buffer, "Rate: ");
  113. switch (status[3] & IEC958_AES3_CON_FS) {
  114. case IEC958_AES3_CON_FS_44100:
  115. snd_iprintf(buffer, "44100 Hz\n");
  116. break;
  117. case IEC958_AES3_CON_FS_48000:
  118. snd_iprintf(buffer, "48000 Hz\n");
  119. break;
  120. case IEC958_AES3_CON_FS_32000:
  121. snd_iprintf(buffer, "32000 Hz\n");
  122. break;
  123. default:
  124. snd_iprintf(buffer, "unknown\n");
  125. break;
  126. }
  127. snd_iprintf(buffer, "Copyright: ");
  128. if (status[0] & IEC958_AES0_CON_NOT_COPYRIGHT) {
  129. snd_iprintf(buffer, "permitted\n");
  130. } else {
  131. snd_iprintf(buffer, "protected\n");
  132. }
  133. snd_iprintf(buffer, "Emphasis: ");
  134. if ((status[0] & IEC958_AES0_CON_EMPHASIS) != IEC958_AES0_CON_EMPHASIS_5015) {
  135. snd_iprintf(buffer, "none\n");
  136. } else {
  137. snd_iprintf(buffer, "50/15us\n");
  138. }
  139. snd_iprintf(buffer, "Category: ");
  140. for (i = 0; i < ARRAY_SIZE(snd_ca0106_con_category); i++) {
  141. if ((status[1] & IEC958_AES1_CON_CATEGORY) == snd_ca0106_con_category[i].val) {
  142. snd_iprintf(buffer, "%s\n", snd_ca0106_con_category[i].name);
  143. break;
  144. }
  145. }
  146. if (i >= ARRAY_SIZE(snd_ca0106_con_category)) {
  147. snd_iprintf(buffer, "unknown 0x%x\n", status[1] & IEC958_AES1_CON_CATEGORY);
  148. }
  149. snd_iprintf(buffer, "Original: ");
  150. if (status[1] & IEC958_AES1_CON_ORIGINAL) {
  151. snd_iprintf(buffer, "original\n");
  152. } else {
  153. snd_iprintf(buffer, "1st generation\n");
  154. }
  155. snd_iprintf(buffer, "Clock: ");
  156. switch (status[3] & IEC958_AES3_CON_CLOCK) {
  157. case IEC958_AES3_CON_CLOCK_1000PPM:
  158. snd_iprintf(buffer, "1000 ppm\n");
  159. break;
  160. case IEC958_AES3_CON_CLOCK_50PPM:
  161. snd_iprintf(buffer, "50 ppm\n");
  162. break;
  163. case IEC958_AES3_CON_CLOCK_VARIABLE:
  164. snd_iprintf(buffer, "variable pitch\n");
  165. break;
  166. default:
  167. snd_iprintf(buffer, "unknown\n");
  168. break;
  169. }
  170. } else {
  171. snd_iprintf(buffer, "Mode: professional\n");
  172. snd_iprintf(buffer, "Data: ");
  173. if (!(status[0] & IEC958_AES0_NONAUDIO)) {
  174. snd_iprintf(buffer, "audio\n");
  175. } else {
  176. snd_iprintf(buffer, "non-audio\n");
  177. }
  178. snd_iprintf(buffer, "Rate: ");
  179. switch (status[0] & IEC958_AES0_PRO_FS) {
  180. case IEC958_AES0_PRO_FS_44100:
  181. snd_iprintf(buffer, "44100 Hz\n");
  182. break;
  183. case IEC958_AES0_PRO_FS_48000:
  184. snd_iprintf(buffer, "48000 Hz\n");
  185. break;
  186. case IEC958_AES0_PRO_FS_32000:
  187. snd_iprintf(buffer, "32000 Hz\n");
  188. break;
  189. default:
  190. snd_iprintf(buffer, "unknown\n");
  191. break;
  192. }
  193. snd_iprintf(buffer, "Rate Locked: ");
  194. if (status[0] & IEC958_AES0_PRO_FREQ_UNLOCKED)
  195. snd_iprintf(buffer, "no\n");
  196. else
  197. snd_iprintf(buffer, "yes\n");
  198. snd_iprintf(buffer, "Emphasis: ");
  199. switch (status[0] & IEC958_AES0_PRO_EMPHASIS) {
  200. case IEC958_AES0_PRO_EMPHASIS_CCITT:
  201. snd_iprintf(buffer, "CCITT J.17\n");
  202. break;
  203. case IEC958_AES0_PRO_EMPHASIS_NONE:
  204. snd_iprintf(buffer, "none\n");
  205. break;
  206. case IEC958_AES0_PRO_EMPHASIS_5015:
  207. snd_iprintf(buffer, "50/15us\n");
  208. break;
  209. case IEC958_AES0_PRO_EMPHASIS_NOTID:
  210. default:
  211. snd_iprintf(buffer, "unknown\n");
  212. break;
  213. }
  214. snd_iprintf(buffer, "Stereophonic: ");
  215. if ((status[1] & IEC958_AES1_PRO_MODE) == IEC958_AES1_PRO_MODE_STEREOPHONIC) {
  216. snd_iprintf(buffer, "stereo\n");
  217. } else {
  218. snd_iprintf(buffer, "not indicated\n");
  219. }
  220. snd_iprintf(buffer, "Userbits: ");
  221. switch (status[1] & IEC958_AES1_PRO_USERBITS) {
  222. case IEC958_AES1_PRO_USERBITS_192:
  223. snd_iprintf(buffer, "192bit\n");
  224. break;
  225. case IEC958_AES1_PRO_USERBITS_UDEF:
  226. snd_iprintf(buffer, "user-defined\n");
  227. break;
  228. default:
  229. snd_iprintf(buffer, "unkown\n");
  230. break;
  231. }
  232. snd_iprintf(buffer, "Sample Bits: ");
  233. switch (status[2] & IEC958_AES2_PRO_SBITS) {
  234. case IEC958_AES2_PRO_SBITS_20:
  235. snd_iprintf(buffer, "20 bit\n");
  236. break;
  237. case IEC958_AES2_PRO_SBITS_24:
  238. snd_iprintf(buffer, "24 bit\n");
  239. break;
  240. case IEC958_AES2_PRO_SBITS_UDEF:
  241. snd_iprintf(buffer, "user defined\n");
  242. break;
  243. default:
  244. snd_iprintf(buffer, "unknown\n");
  245. break;
  246. }
  247. snd_iprintf(buffer, "Word Length: ");
  248. switch (status[2] & IEC958_AES2_PRO_WORDLEN) {
  249. case IEC958_AES2_PRO_WORDLEN_22_18:
  250. snd_iprintf(buffer, "22 bit or 18 bit\n");
  251. break;
  252. case IEC958_AES2_PRO_WORDLEN_23_19:
  253. snd_iprintf(buffer, "23 bit or 19 bit\n");
  254. break;
  255. case IEC958_AES2_PRO_WORDLEN_24_20:
  256. snd_iprintf(buffer, "24 bit or 20 bit\n");
  257. break;
  258. case IEC958_AES2_PRO_WORDLEN_20_16:
  259. snd_iprintf(buffer, "20 bit or 16 bit\n");
  260. break;
  261. default:
  262. snd_iprintf(buffer, "unknown\n");
  263. break;
  264. }
  265. }
  266. }
  267. static void snd_ca0106_proc_iec958(struct snd_info_entry *entry,
  268. struct snd_info_buffer *buffer)
  269. {
  270. struct snd_ca0106 *emu = entry->private_data;
  271. u32 value;
  272. value = snd_ca0106_ptr_read(emu, SAMPLE_RATE_TRACKER_STATUS, 0);
  273. snd_iprintf(buffer, "Status: %s, %s, %s\n",
  274. (value & 0x100000) ? "Rate Locked" : "Not Rate Locked",
  275. (value & 0x200000) ? "SPDIF Locked" : "No SPDIF Lock",
  276. (value & 0x400000) ? "Audio Valid" : "No valid audio" );
  277. snd_iprintf(buffer, "Estimated sample rate: %u\n",
  278. ((value & 0xfffff) * 48000) / 0x8000 );
  279. if (value & 0x200000) {
  280. snd_iprintf(buffer, "IEC958/SPDIF input status:\n");
  281. value = snd_ca0106_ptr_read(emu, SPDIF_INPUT_STATUS, 0);
  282. snd_ca0106_proc_dump_iec958(buffer, value);
  283. }
  284. snd_iprintf(buffer, "\n");
  285. }
  286. static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry,
  287. struct snd_info_buffer *buffer)
  288. {
  289. struct snd_ca0106 *emu = entry->private_data;
  290. unsigned long flags;
  291. char line[64];
  292. u32 reg, val;
  293. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  294. if (sscanf(line, "%x %x", &reg, &val) != 2)
  295. continue;
  296. if ((reg < 0x40) && (reg >=0) && (val <= 0xffffffff) ) {
  297. spin_lock_irqsave(&emu->emu_lock, flags);
  298. outl(val, emu->port + (reg & 0xfffffffc));
  299. spin_unlock_irqrestore(&emu->emu_lock, flags);
  300. }
  301. }
  302. }
  303. static void snd_ca0106_proc_reg_read32(struct snd_info_entry *entry,
  304. struct snd_info_buffer *buffer)
  305. {
  306. struct snd_ca0106 *emu = entry->private_data;
  307. unsigned long value;
  308. unsigned long flags;
  309. int i;
  310. snd_iprintf(buffer, "Registers:\n\n");
  311. for(i = 0; i < 0x20; i+=4) {
  312. spin_lock_irqsave(&emu->emu_lock, flags);
  313. value = inl(emu->port + i);
  314. spin_unlock_irqrestore(&emu->emu_lock, flags);
  315. snd_iprintf(buffer, "Register %02X: %08lX\n", i, value);
  316. }
  317. }
  318. static void snd_ca0106_proc_reg_read16(struct snd_info_entry *entry,
  319. struct snd_info_buffer *buffer)
  320. {
  321. struct snd_ca0106 *emu = entry->private_data;
  322. unsigned int value;
  323. unsigned long flags;
  324. int i;
  325. snd_iprintf(buffer, "Registers:\n\n");
  326. for(i = 0; i < 0x20; i+=2) {
  327. spin_lock_irqsave(&emu->emu_lock, flags);
  328. value = inw(emu->port + i);
  329. spin_unlock_irqrestore(&emu->emu_lock, flags);
  330. snd_iprintf(buffer, "Register %02X: %04X\n", i, value);
  331. }
  332. }
  333. static void snd_ca0106_proc_reg_read8(struct snd_info_entry *entry,
  334. struct snd_info_buffer *buffer)
  335. {
  336. struct snd_ca0106 *emu = entry->private_data;
  337. unsigned int value;
  338. unsigned long flags;
  339. int i;
  340. snd_iprintf(buffer, "Registers:\n\n");
  341. for(i = 0; i < 0x20; i+=1) {
  342. spin_lock_irqsave(&emu->emu_lock, flags);
  343. value = inb(emu->port + i);
  344. spin_unlock_irqrestore(&emu->emu_lock, flags);
  345. snd_iprintf(buffer, "Register %02X: %02X\n", i, value);
  346. }
  347. }
  348. static void snd_ca0106_proc_reg_read1(struct snd_info_entry *entry,
  349. struct snd_info_buffer *buffer)
  350. {
  351. struct snd_ca0106 *emu = entry->private_data;
  352. unsigned long value;
  353. int i,j;
  354. snd_iprintf(buffer, "Registers\n");
  355. for(i = 0; i < 0x40; i++) {
  356. snd_iprintf(buffer, "%02X: ",i);
  357. for (j = 0; j < 4; j++) {
  358. value = snd_ca0106_ptr_read(emu, i, j);
  359. snd_iprintf(buffer, "%08lX ", value);
  360. }
  361. snd_iprintf(buffer, "\n");
  362. }
  363. }
  364. static void snd_ca0106_proc_reg_read2(struct snd_info_entry *entry,
  365. struct snd_info_buffer *buffer)
  366. {
  367. struct snd_ca0106 *emu = entry->private_data;
  368. unsigned long value;
  369. int i,j;
  370. snd_iprintf(buffer, "Registers\n");
  371. for(i = 0x40; i < 0x80; i++) {
  372. snd_iprintf(buffer, "%02X: ",i);
  373. for (j = 0; j < 4; j++) {
  374. value = snd_ca0106_ptr_read(emu, i, j);
  375. snd_iprintf(buffer, "%08lX ", value);
  376. }
  377. snd_iprintf(buffer, "\n");
  378. }
  379. }
  380. static void snd_ca0106_proc_reg_write(struct snd_info_entry *entry,
  381. struct snd_info_buffer *buffer)
  382. {
  383. struct snd_ca0106 *emu = entry->private_data;
  384. char line[64];
  385. unsigned int reg, channel_id , val;
  386. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  387. if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
  388. continue;
  389. if ((reg < 0x80) && (reg >=0) && (val <= 0xffffffff) && (channel_id >=0) && (channel_id <= 3) )
  390. snd_ca0106_ptr_write(emu, reg, channel_id, val);
  391. }
  392. }
  393. static void snd_ca0106_proc_i2c_write(struct snd_info_entry *entry,
  394. struct snd_info_buffer *buffer)
  395. {
  396. struct snd_ca0106 *emu = entry->private_data;
  397. char line[64];
  398. unsigned int reg, val;
  399. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  400. if (sscanf(line, "%x %x", &reg, &val) != 2)
  401. continue;
  402. if ((reg <= 0x7f) || (val <= 0x1ff)) {
  403. snd_ca0106_i2c_write(emu, reg, val);
  404. }
  405. }
  406. }
  407. int __devinit snd_ca0106_proc_init(struct snd_ca0106 * emu)
  408. {
  409. struct snd_info_entry *entry;
  410. if(! snd_card_proc_new(emu->card, "iec958", &entry))
  411. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_iec958);
  412. if(! snd_card_proc_new(emu->card, "ca0106_reg32", &entry)) {
  413. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read32);
  414. entry->c.text.write = snd_ca0106_proc_reg_write32;
  415. entry->mode |= S_IWUSR;
  416. }
  417. if(! snd_card_proc_new(emu->card, "ca0106_reg16", &entry))
  418. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read16);
  419. if(! snd_card_proc_new(emu->card, "ca0106_reg8", &entry))
  420. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read8);
  421. if(! snd_card_proc_new(emu->card, "ca0106_regs1", &entry)) {
  422. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read1);
  423. entry->c.text.write = snd_ca0106_proc_reg_write;
  424. entry->mode |= S_IWUSR;
  425. // entry->private_data = emu;
  426. }
  427. if(! snd_card_proc_new(emu->card, "ca0106_i2c", &entry)) {
  428. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_i2c_write);
  429. entry->c.text.write = snd_ca0106_proc_i2c_write;
  430. entry->mode |= S_IWUSR;
  431. // entry->private_data = emu;
  432. }
  433. if(! snd_card_proc_new(emu->card, "ca0106_regs2", &entry))
  434. snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read2);
  435. return 0;
  436. }
  437. #endif /* CONFIG_PROC_FS */