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