ca0106_proc.c 14 KB

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