sb16_csp.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. /*
  2. * Copyright (c) 1999 by Uros Bizjak <uros@kss-loka.si>
  3. * Takashi Iwai <tiwai@suse.de>
  4. *
  5. * SB16ASP/AWE32 CSP control
  6. *
  7. * CSP microcode loader:
  8. * alsa-tools/sb16_csp/
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <linux/delay.h>
  26. #include <linux/init.h>
  27. #include <linux/slab.h>
  28. #include <sound/core.h>
  29. #include <sound/control.h>
  30. #include <sound/info.h>
  31. #include <sound/sb16_csp.h>
  32. #include <sound/initval.h>
  33. MODULE_AUTHOR("Uros Bizjak <uros@kss-loka.si>");
  34. MODULE_DESCRIPTION("ALSA driver for SB16 Creative Signal Processor");
  35. MODULE_LICENSE("GPL");
  36. MODULE_FIRMWARE("sb16/mulaw_main.csp");
  37. MODULE_FIRMWARE("sb16/alaw_main.csp");
  38. MODULE_FIRMWARE("sb16/ima_adpcm_init.csp");
  39. MODULE_FIRMWARE("sb16/ima_adpcm_playback.csp");
  40. MODULE_FIRMWARE("sb16/ima_adpcm_capture.csp");
  41. #ifdef SNDRV_LITTLE_ENDIAN
  42. #define CSP_HDR_VALUE(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24))
  43. #else
  44. #define CSP_HDR_VALUE(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24))
  45. #endif
  46. #define RIFF_HEADER CSP_HDR_VALUE('R', 'I', 'F', 'F')
  47. #define CSP__HEADER CSP_HDR_VALUE('C', 'S', 'P', ' ')
  48. #define LIST_HEADER CSP_HDR_VALUE('L', 'I', 'S', 'T')
  49. #define FUNC_HEADER CSP_HDR_VALUE('f', 'u', 'n', 'c')
  50. #define CODE_HEADER CSP_HDR_VALUE('c', 'o', 'd', 'e')
  51. #define INIT_HEADER CSP_HDR_VALUE('i', 'n', 'i', 't')
  52. #define MAIN_HEADER CSP_HDR_VALUE('m', 'a', 'i', 'n')
  53. /*
  54. * RIFF data format
  55. */
  56. struct riff_header {
  57. __u32 name;
  58. __u32 len;
  59. };
  60. struct desc_header {
  61. struct riff_header info;
  62. __u16 func_nr;
  63. __u16 VOC_type;
  64. __u16 flags_play_rec;
  65. __u16 flags_16bit_8bit;
  66. __u16 flags_stereo_mono;
  67. __u16 flags_rates;
  68. };
  69. /*
  70. * prototypes
  71. */
  72. static void snd_sb_csp_free(struct snd_hwdep *hw);
  73. static int snd_sb_csp_open(struct snd_hwdep * hw, struct file *file);
  74. static int snd_sb_csp_ioctl(struct snd_hwdep * hw, struct file *file, unsigned int cmd, unsigned long arg);
  75. static int snd_sb_csp_release(struct snd_hwdep * hw, struct file *file);
  76. static int csp_detect(struct snd_sb *chip, int *version);
  77. static int set_codec_parameter(struct snd_sb *chip, unsigned char par, unsigned char val);
  78. static int set_register(struct snd_sb *chip, unsigned char reg, unsigned char val);
  79. static int read_register(struct snd_sb *chip, unsigned char reg);
  80. static int set_mode_register(struct snd_sb *chip, unsigned char mode);
  81. static int get_version(struct snd_sb *chip);
  82. static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
  83. struct snd_sb_csp_microcode __user * code);
  84. static int snd_sb_csp_unload(struct snd_sb_csp * p);
  85. static int snd_sb_csp_load_user(struct snd_sb_csp * p, const unsigned char __user *buf, int size, int load_flags);
  86. static int snd_sb_csp_autoload(struct snd_sb_csp * p, int pcm_sfmt, int play_rec_mode);
  87. static int snd_sb_csp_check_version(struct snd_sb_csp * p);
  88. static int snd_sb_csp_use(struct snd_sb_csp * p);
  89. static int snd_sb_csp_unuse(struct snd_sb_csp * p);
  90. static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channels);
  91. static int snd_sb_csp_stop(struct snd_sb_csp * p);
  92. static int snd_sb_csp_pause(struct snd_sb_csp * p);
  93. static int snd_sb_csp_restart(struct snd_sb_csp * p);
  94. static int snd_sb_qsound_build(struct snd_sb_csp * p);
  95. static void snd_sb_qsound_destroy(struct snd_sb_csp * p);
  96. static int snd_sb_csp_qsound_transfer(struct snd_sb_csp * p);
  97. static int init_proc_entry(struct snd_sb_csp * p, int device);
  98. static void info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer);
  99. /*
  100. * Detect CSP chip and create a new instance
  101. */
  102. int snd_sb_csp_new(struct snd_sb *chip, int device, struct snd_hwdep ** rhwdep)
  103. {
  104. struct snd_sb_csp *p;
  105. int uninitialized_var(version);
  106. int err;
  107. struct snd_hwdep *hw;
  108. if (rhwdep)
  109. *rhwdep = NULL;
  110. if (csp_detect(chip, &version))
  111. return -ENODEV;
  112. if ((err = snd_hwdep_new(chip->card, "SB16-CSP", device, &hw)) < 0)
  113. return err;
  114. if ((p = kzalloc(sizeof(*p), GFP_KERNEL)) == NULL) {
  115. snd_device_free(chip->card, hw);
  116. return -ENOMEM;
  117. }
  118. p->chip = chip;
  119. p->version = version;
  120. /* CSP operators */
  121. p->ops.csp_use = snd_sb_csp_use;
  122. p->ops.csp_unuse = snd_sb_csp_unuse;
  123. p->ops.csp_autoload = snd_sb_csp_autoload;
  124. p->ops.csp_start = snd_sb_csp_start;
  125. p->ops.csp_stop = snd_sb_csp_stop;
  126. p->ops.csp_qsound_transfer = snd_sb_csp_qsound_transfer;
  127. mutex_init(&p->access_mutex);
  128. sprintf(hw->name, "CSP v%d.%d", (version >> 4), (version & 0x0f));
  129. hw->iface = SNDRV_HWDEP_IFACE_SB16CSP;
  130. hw->private_data = p;
  131. hw->private_free = snd_sb_csp_free;
  132. /* operators - only write/ioctl */
  133. hw->ops.open = snd_sb_csp_open;
  134. hw->ops.ioctl = snd_sb_csp_ioctl;
  135. hw->ops.release = snd_sb_csp_release;
  136. /* create a proc entry */
  137. init_proc_entry(p, device);
  138. if (rhwdep)
  139. *rhwdep = hw;
  140. return 0;
  141. }
  142. /*
  143. * free_private for hwdep instance
  144. */
  145. static void snd_sb_csp_free(struct snd_hwdep *hwdep)
  146. {
  147. int i;
  148. struct snd_sb_csp *p = hwdep->private_data;
  149. if (p) {
  150. if (p->running & SNDRV_SB_CSP_ST_RUNNING)
  151. snd_sb_csp_stop(p);
  152. for (i = 0; i < ARRAY_SIZE(p->csp_programs); ++i)
  153. release_firmware(p->csp_programs[i]);
  154. kfree(p);
  155. }
  156. }
  157. /* ------------------------------ */
  158. /*
  159. * open the device exclusively
  160. */
  161. static int snd_sb_csp_open(struct snd_hwdep * hw, struct file *file)
  162. {
  163. struct snd_sb_csp *p = hw->private_data;
  164. return (snd_sb_csp_use(p));
  165. }
  166. /*
  167. * ioctl for hwdep device:
  168. */
  169. static int snd_sb_csp_ioctl(struct snd_hwdep * hw, struct file *file, unsigned int cmd, unsigned long arg)
  170. {
  171. struct snd_sb_csp *p = hw->private_data;
  172. struct snd_sb_csp_info info;
  173. struct snd_sb_csp_start start_info;
  174. int err;
  175. if (snd_BUG_ON(!p))
  176. return -EINVAL;
  177. if (snd_sb_csp_check_version(p))
  178. return -ENODEV;
  179. switch (cmd) {
  180. /* get information */
  181. case SNDRV_SB_CSP_IOCTL_INFO:
  182. *info.codec_name = *p->codec_name;
  183. info.func_nr = p->func_nr;
  184. info.acc_format = p->acc_format;
  185. info.acc_channels = p->acc_channels;
  186. info.acc_width = p->acc_width;
  187. info.acc_rates = p->acc_rates;
  188. info.csp_mode = p->mode;
  189. info.run_channels = p->run_channels;
  190. info.run_width = p->run_width;
  191. info.version = p->version;
  192. info.state = p->running;
  193. if (copy_to_user((void __user *)arg, &info, sizeof(info)))
  194. err = -EFAULT;
  195. else
  196. err = 0;
  197. break;
  198. /* load CSP microcode */
  199. case SNDRV_SB_CSP_IOCTL_LOAD_CODE:
  200. err = (p->running & SNDRV_SB_CSP_ST_RUNNING ?
  201. -EBUSY : snd_sb_csp_riff_load(p, (struct snd_sb_csp_microcode __user *) arg));
  202. break;
  203. case SNDRV_SB_CSP_IOCTL_UNLOAD_CODE:
  204. err = (p->running & SNDRV_SB_CSP_ST_RUNNING ?
  205. -EBUSY : snd_sb_csp_unload(p));
  206. break;
  207. /* change CSP running state */
  208. case SNDRV_SB_CSP_IOCTL_START:
  209. if (copy_from_user(&start_info, (void __user *) arg, sizeof(start_info)))
  210. err = -EFAULT;
  211. else
  212. err = snd_sb_csp_start(p, start_info.sample_width, start_info.channels);
  213. break;
  214. case SNDRV_SB_CSP_IOCTL_STOP:
  215. err = snd_sb_csp_stop(p);
  216. break;
  217. case SNDRV_SB_CSP_IOCTL_PAUSE:
  218. err = snd_sb_csp_pause(p);
  219. break;
  220. case SNDRV_SB_CSP_IOCTL_RESTART:
  221. err = snd_sb_csp_restart(p);
  222. break;
  223. default:
  224. err = -ENOTTY;
  225. break;
  226. }
  227. return err;
  228. }
  229. /*
  230. * close the device
  231. */
  232. static int snd_sb_csp_release(struct snd_hwdep * hw, struct file *file)
  233. {
  234. struct snd_sb_csp *p = hw->private_data;
  235. return (snd_sb_csp_unuse(p));
  236. }
  237. /* ------------------------------ */
  238. /*
  239. * acquire device
  240. */
  241. static int snd_sb_csp_use(struct snd_sb_csp * p)
  242. {
  243. mutex_lock(&p->access_mutex);
  244. if (p->used) {
  245. mutex_unlock(&p->access_mutex);
  246. return -EAGAIN;
  247. }
  248. p->used++;
  249. mutex_unlock(&p->access_mutex);
  250. return 0;
  251. }
  252. /*
  253. * release device
  254. */
  255. static int snd_sb_csp_unuse(struct snd_sb_csp * p)
  256. {
  257. mutex_lock(&p->access_mutex);
  258. p->used--;
  259. mutex_unlock(&p->access_mutex);
  260. return 0;
  261. }
  262. /*
  263. * load microcode via ioctl:
  264. * code is user-space pointer
  265. */
  266. static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
  267. struct snd_sb_csp_microcode __user * mcode)
  268. {
  269. struct snd_sb_csp_mc_header info;
  270. unsigned char __user *data_ptr;
  271. unsigned char __user *data_end;
  272. unsigned short func_nr = 0;
  273. struct riff_header file_h, item_h, code_h;
  274. __u32 item_type;
  275. struct desc_header funcdesc_h;
  276. unsigned long flags;
  277. int err;
  278. if (copy_from_user(&info, mcode, sizeof(info)))
  279. return -EFAULT;
  280. data_ptr = mcode->data;
  281. if (copy_from_user(&file_h, data_ptr, sizeof(file_h)))
  282. return -EFAULT;
  283. if ((file_h.name != RIFF_HEADER) ||
  284. (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) {
  285. snd_printd("%s: Invalid RIFF header\n", __func__);
  286. return -EINVAL;
  287. }
  288. data_ptr += sizeof(file_h);
  289. data_end = data_ptr + le32_to_cpu(file_h.len);
  290. if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
  291. return -EFAULT;
  292. if (item_type != CSP__HEADER) {
  293. snd_printd("%s: Invalid RIFF file type\n", __func__);
  294. return -EINVAL;
  295. }
  296. data_ptr += sizeof (item_type);
  297. for (; data_ptr < data_end; data_ptr += le32_to_cpu(item_h.len)) {
  298. if (copy_from_user(&item_h, data_ptr, sizeof(item_h)))
  299. return -EFAULT;
  300. data_ptr += sizeof(item_h);
  301. if (item_h.name != LIST_HEADER)
  302. continue;
  303. if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
  304. return -EFAULT;
  305. switch (item_type) {
  306. case FUNC_HEADER:
  307. if (copy_from_user(&funcdesc_h, data_ptr + sizeof(item_type), sizeof(funcdesc_h)))
  308. return -EFAULT;
  309. func_nr = le16_to_cpu(funcdesc_h.func_nr);
  310. break;
  311. case CODE_HEADER:
  312. if (func_nr != info.func_req)
  313. break; /* not required function, try next */
  314. data_ptr += sizeof(item_type);
  315. /* destroy QSound mixer element */
  316. if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) {
  317. snd_sb_qsound_destroy(p);
  318. }
  319. /* Clear all flags */
  320. p->running = 0;
  321. p->mode = 0;
  322. /* load microcode blocks */
  323. for (;;) {
  324. if (data_ptr >= data_end)
  325. return -EINVAL;
  326. if (copy_from_user(&code_h, data_ptr, sizeof(code_h)))
  327. return -EFAULT;
  328. /* init microcode blocks */
  329. if (code_h.name != INIT_HEADER)
  330. break;
  331. data_ptr += sizeof(code_h);
  332. err = snd_sb_csp_load_user(p, data_ptr, le32_to_cpu(code_h.len),
  333. SNDRV_SB_CSP_LOAD_INITBLOCK);
  334. if (err)
  335. return err;
  336. data_ptr += le32_to_cpu(code_h.len);
  337. }
  338. /* main microcode block */
  339. if (copy_from_user(&code_h, data_ptr, sizeof(code_h)))
  340. return -EFAULT;
  341. if (code_h.name != MAIN_HEADER) {
  342. snd_printd("%s: Missing 'main' microcode\n", __func__);
  343. return -EINVAL;
  344. }
  345. data_ptr += sizeof(code_h);
  346. err = snd_sb_csp_load_user(p, data_ptr,
  347. le32_to_cpu(code_h.len), 0);
  348. if (err)
  349. return err;
  350. /* fill in codec header */
  351. strlcpy(p->codec_name, info.codec_name, sizeof(p->codec_name));
  352. p->func_nr = func_nr;
  353. p->mode = le16_to_cpu(funcdesc_h.flags_play_rec);
  354. switch (le16_to_cpu(funcdesc_h.VOC_type)) {
  355. case 0x0001: /* QSound decoder */
  356. if (le16_to_cpu(funcdesc_h.flags_play_rec) == SNDRV_SB_CSP_MODE_DSP_WRITE) {
  357. if (snd_sb_qsound_build(p) == 0)
  358. /* set QSound flag and clear all other mode flags */
  359. p->mode = SNDRV_SB_CSP_MODE_QSOUND;
  360. }
  361. p->acc_format = 0;
  362. break;
  363. case 0x0006: /* A Law codec */
  364. p->acc_format = SNDRV_PCM_FMTBIT_A_LAW;
  365. break;
  366. case 0x0007: /* Mu Law codec */
  367. p->acc_format = SNDRV_PCM_FMTBIT_MU_LAW;
  368. break;
  369. case 0x0011: /* what Creative thinks is IMA ADPCM codec */
  370. case 0x0200: /* Creative ADPCM codec */
  371. p->acc_format = SNDRV_PCM_FMTBIT_IMA_ADPCM;
  372. break;
  373. case 201: /* Text 2 Speech decoder */
  374. /* TODO: Text2Speech handling routines */
  375. p->acc_format = 0;
  376. break;
  377. case 0x0202: /* Fast Speech 8 codec */
  378. case 0x0203: /* Fast Speech 10 codec */
  379. p->acc_format = SNDRV_PCM_FMTBIT_SPECIAL;
  380. break;
  381. default: /* other codecs are unsupported */
  382. p->acc_format = p->acc_width = p->acc_rates = 0;
  383. p->mode = 0;
  384. snd_printd("%s: Unsupported CSP codec type: 0x%04x\n",
  385. __func__,
  386. le16_to_cpu(funcdesc_h.VOC_type));
  387. return -EINVAL;
  388. }
  389. p->acc_channels = le16_to_cpu(funcdesc_h.flags_stereo_mono);
  390. p->acc_width = le16_to_cpu(funcdesc_h.flags_16bit_8bit);
  391. p->acc_rates = le16_to_cpu(funcdesc_h.flags_rates);
  392. /* Decouple CSP from IRQ and DMAREQ lines */
  393. spin_lock_irqsave(&p->chip->reg_lock, flags);
  394. set_mode_register(p->chip, 0xfc);
  395. set_mode_register(p->chip, 0x00);
  396. spin_unlock_irqrestore(&p->chip->reg_lock, flags);
  397. /* finished loading successfully */
  398. p->running = SNDRV_SB_CSP_ST_LOADED; /* set LOADED flag */
  399. return 0;
  400. }
  401. }
  402. snd_printd("%s: Function #%d not found\n", __func__, info.func_req);
  403. return -EINVAL;
  404. }
  405. /*
  406. * unload CSP microcode
  407. */
  408. static int snd_sb_csp_unload(struct snd_sb_csp * p)
  409. {
  410. if (p->running & SNDRV_SB_CSP_ST_RUNNING)
  411. return -EBUSY;
  412. if (!(p->running & SNDRV_SB_CSP_ST_LOADED))
  413. return -ENXIO;
  414. /* clear supported formats */
  415. p->acc_format = 0;
  416. p->acc_channels = p->acc_width = p->acc_rates = 0;
  417. /* destroy QSound mixer element */
  418. if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) {
  419. snd_sb_qsound_destroy(p);
  420. }
  421. /* clear all flags */
  422. p->running = 0;
  423. p->mode = 0;
  424. return 0;
  425. }
  426. /*
  427. * send command sequence to DSP
  428. */
  429. static inline int command_seq(struct snd_sb *chip, const unsigned char *seq, int size)
  430. {
  431. int i;
  432. for (i = 0; i < size; i++) {
  433. if (!snd_sbdsp_command(chip, seq[i]))
  434. return -EIO;
  435. }
  436. return 0;
  437. }
  438. /*
  439. * set CSP codec parameter
  440. */
  441. static int set_codec_parameter(struct snd_sb *chip, unsigned char par, unsigned char val)
  442. {
  443. unsigned char dsp_cmd[3];
  444. dsp_cmd[0] = 0x05; /* CSP set codec parameter */
  445. dsp_cmd[1] = val; /* Parameter value */
  446. dsp_cmd[2] = par; /* Parameter */
  447. command_seq(chip, dsp_cmd, 3);
  448. snd_sbdsp_command(chip, 0x03); /* DSP read? */
  449. if (snd_sbdsp_get_byte(chip) != par)
  450. return -EIO;
  451. return 0;
  452. }
  453. /*
  454. * set CSP register
  455. */
  456. static int set_register(struct snd_sb *chip, unsigned char reg, unsigned char val)
  457. {
  458. unsigned char dsp_cmd[3];
  459. dsp_cmd[0] = 0x0e; /* CSP set register */
  460. dsp_cmd[1] = reg; /* CSP Register */
  461. dsp_cmd[2] = val; /* value */
  462. return command_seq(chip, dsp_cmd, 3);
  463. }
  464. /*
  465. * read CSP register
  466. * return < 0 -> error
  467. */
  468. static int read_register(struct snd_sb *chip, unsigned char reg)
  469. {
  470. unsigned char dsp_cmd[2];
  471. dsp_cmd[0] = 0x0f; /* CSP read register */
  472. dsp_cmd[1] = reg; /* CSP Register */
  473. command_seq(chip, dsp_cmd, 2);
  474. return snd_sbdsp_get_byte(chip); /* Read DSP value */
  475. }
  476. /*
  477. * set CSP mode register
  478. */
  479. static int set_mode_register(struct snd_sb *chip, unsigned char mode)
  480. {
  481. unsigned char dsp_cmd[2];
  482. dsp_cmd[0] = 0x04; /* CSP set mode register */
  483. dsp_cmd[1] = mode; /* mode */
  484. return command_seq(chip, dsp_cmd, 2);
  485. }
  486. /*
  487. * Detect CSP
  488. * return 0 if CSP exists.
  489. */
  490. static int csp_detect(struct snd_sb *chip, int *version)
  491. {
  492. unsigned char csp_test1, csp_test2;
  493. unsigned long flags;
  494. int result = -ENODEV;
  495. spin_lock_irqsave(&chip->reg_lock, flags);
  496. set_codec_parameter(chip, 0x00, 0x00);
  497. set_mode_register(chip, 0xfc); /* 0xfc = ?? */
  498. csp_test1 = read_register(chip, 0x83);
  499. set_register(chip, 0x83, ~csp_test1);
  500. csp_test2 = read_register(chip, 0x83);
  501. if (csp_test2 != (csp_test1 ^ 0xff))
  502. goto __fail;
  503. set_register(chip, 0x83, csp_test1);
  504. csp_test2 = read_register(chip, 0x83);
  505. if (csp_test2 != csp_test1)
  506. goto __fail;
  507. set_mode_register(chip, 0x00); /* 0x00 = ? */
  508. *version = get_version(chip);
  509. snd_sbdsp_reset(chip); /* reset DSP after getversion! */
  510. if (*version >= 0x10 && *version <= 0x1f)
  511. result = 0; /* valid version id */
  512. __fail:
  513. spin_unlock_irqrestore(&chip->reg_lock, flags);
  514. return result;
  515. }
  516. /*
  517. * get CSP version number
  518. */
  519. static int get_version(struct snd_sb *chip)
  520. {
  521. unsigned char dsp_cmd[2];
  522. dsp_cmd[0] = 0x08; /* SB_DSP_!something! */
  523. dsp_cmd[1] = 0x03; /* get chip version id? */
  524. command_seq(chip, dsp_cmd, 2);
  525. return (snd_sbdsp_get_byte(chip));
  526. }
  527. /*
  528. * check if the CSP version is valid
  529. */
  530. static int snd_sb_csp_check_version(struct snd_sb_csp * p)
  531. {
  532. if (p->version < 0x10 || p->version > 0x1f) {
  533. snd_printd("%s: Invalid CSP version: 0x%x\n", __func__, p->version);
  534. return 1;
  535. }
  536. return 0;
  537. }
  538. /*
  539. * download microcode to CSP (microcode should have one "main" block).
  540. */
  541. static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int size, int load_flags)
  542. {
  543. int status, i;
  544. int err;
  545. int result = -EIO;
  546. unsigned long flags;
  547. spin_lock_irqsave(&p->chip->reg_lock, flags);
  548. snd_sbdsp_command(p->chip, 0x01); /* CSP download command */
  549. if (snd_sbdsp_get_byte(p->chip)) {
  550. snd_printd("%s: Download command failed\n", __func__);
  551. goto __fail;
  552. }
  553. /* Send CSP low byte (size - 1) */
  554. snd_sbdsp_command(p->chip, (unsigned char)(size - 1));
  555. /* Send high byte */
  556. snd_sbdsp_command(p->chip, (unsigned char)((size - 1) >> 8));
  557. /* send microcode sequence */
  558. /* load from kernel space */
  559. while (size--) {
  560. if (!snd_sbdsp_command(p->chip, *buf++))
  561. goto __fail;
  562. }
  563. if (snd_sbdsp_get_byte(p->chip))
  564. goto __fail;
  565. if (load_flags & SNDRV_SB_CSP_LOAD_INITBLOCK) {
  566. i = 0;
  567. /* some codecs (FastSpeech) take some time to initialize */
  568. while (1) {
  569. snd_sbdsp_command(p->chip, 0x03);
  570. status = snd_sbdsp_get_byte(p->chip);
  571. if (status == 0x55 || ++i >= 10)
  572. break;
  573. udelay (10);
  574. }
  575. if (status != 0x55) {
  576. snd_printd("%s: Microcode initialization failed\n", __func__);
  577. goto __fail;
  578. }
  579. } else {
  580. /*
  581. * Read mixer register SB_DSP4_DMASETUP after loading 'main' code.
  582. * Start CSP chip if no 16bit DMA channel is set - some kind
  583. * of autorun or perhaps a bugfix?
  584. */
  585. spin_lock(&p->chip->mixer_lock);
  586. status = snd_sbmixer_read(p->chip, SB_DSP4_DMASETUP);
  587. spin_unlock(&p->chip->mixer_lock);
  588. if (!(status & (SB_DMASETUP_DMA7 | SB_DMASETUP_DMA6 | SB_DMASETUP_DMA5))) {
  589. err = (set_codec_parameter(p->chip, 0xaa, 0x00) ||
  590. set_codec_parameter(p->chip, 0xff, 0x00));
  591. snd_sbdsp_reset(p->chip); /* really! */
  592. if (err)
  593. goto __fail;
  594. set_mode_register(p->chip, 0xc0); /* c0 = STOP */
  595. set_mode_register(p->chip, 0x70); /* 70 = RUN */
  596. }
  597. }
  598. result = 0;
  599. __fail:
  600. spin_unlock_irqrestore(&p->chip->reg_lock, flags);
  601. return result;
  602. }
  603. static int snd_sb_csp_load_user(struct snd_sb_csp * p, const unsigned char __user *buf, int size, int load_flags)
  604. {
  605. int err;
  606. unsigned char *kbuf;
  607. kbuf = memdup_user(buf, size);
  608. if (IS_ERR(kbuf))
  609. return PTR_ERR(kbuf);
  610. err = snd_sb_csp_load(p, kbuf, size, load_flags);
  611. kfree(kbuf);
  612. return err;
  613. }
  614. static int snd_sb_csp_firmware_load(struct snd_sb_csp *p, int index, int flags)
  615. {
  616. static const char *const names[] = {
  617. "sb16/mulaw_main.csp",
  618. "sb16/alaw_main.csp",
  619. "sb16/ima_adpcm_init.csp",
  620. "sb16/ima_adpcm_playback.csp",
  621. "sb16/ima_adpcm_capture.csp",
  622. };
  623. const struct firmware *program;
  624. BUILD_BUG_ON(ARRAY_SIZE(names) != CSP_PROGRAM_COUNT);
  625. program = p->csp_programs[index];
  626. if (!program) {
  627. int err = request_firmware(&program, names[index],
  628. p->chip->card->dev);
  629. if (err < 0)
  630. return err;
  631. p->csp_programs[index] = program;
  632. }
  633. return snd_sb_csp_load(p, program->data, program->size, flags);
  634. }
  635. /*
  636. * autoload hardware codec if necessary
  637. * return 0 if CSP is loaded and ready to run (p->running != 0)
  638. */
  639. static int snd_sb_csp_autoload(struct snd_sb_csp * p, int pcm_sfmt, int play_rec_mode)
  640. {
  641. unsigned long flags;
  642. int err = 0;
  643. /* if CSP is running or manually loaded then exit */
  644. if (p->running & (SNDRV_SB_CSP_ST_RUNNING | SNDRV_SB_CSP_ST_LOADED))
  645. return -EBUSY;
  646. /* autoload microcode only if requested hardware codec is not already loaded */
  647. if (((1 << pcm_sfmt) & p->acc_format) && (play_rec_mode & p->mode)) {
  648. p->running = SNDRV_SB_CSP_ST_AUTO;
  649. } else {
  650. switch (pcm_sfmt) {
  651. case SNDRV_PCM_FORMAT_MU_LAW:
  652. err = snd_sb_csp_firmware_load(p, CSP_PROGRAM_MULAW, 0);
  653. p->acc_format = SNDRV_PCM_FMTBIT_MU_LAW;
  654. p->mode = SNDRV_SB_CSP_MODE_DSP_READ | SNDRV_SB_CSP_MODE_DSP_WRITE;
  655. break;
  656. case SNDRV_PCM_FORMAT_A_LAW:
  657. err = snd_sb_csp_firmware_load(p, CSP_PROGRAM_ALAW, 0);
  658. p->acc_format = SNDRV_PCM_FMTBIT_A_LAW;
  659. p->mode = SNDRV_SB_CSP_MODE_DSP_READ | SNDRV_SB_CSP_MODE_DSP_WRITE;
  660. break;
  661. case SNDRV_PCM_FORMAT_IMA_ADPCM:
  662. err = snd_sb_csp_firmware_load(p, CSP_PROGRAM_ADPCM_INIT,
  663. SNDRV_SB_CSP_LOAD_INITBLOCK);
  664. if (err)
  665. break;
  666. if (play_rec_mode == SNDRV_SB_CSP_MODE_DSP_WRITE) {
  667. err = snd_sb_csp_firmware_load
  668. (p, CSP_PROGRAM_ADPCM_PLAYBACK, 0);
  669. p->mode = SNDRV_SB_CSP_MODE_DSP_WRITE;
  670. } else {
  671. err = snd_sb_csp_firmware_load
  672. (p, CSP_PROGRAM_ADPCM_CAPTURE, 0);
  673. p->mode = SNDRV_SB_CSP_MODE_DSP_READ;
  674. }
  675. p->acc_format = SNDRV_PCM_FMTBIT_IMA_ADPCM;
  676. break;
  677. default:
  678. /* Decouple CSP from IRQ and DMAREQ lines */
  679. if (p->running & SNDRV_SB_CSP_ST_AUTO) {
  680. spin_lock_irqsave(&p->chip->reg_lock, flags);
  681. set_mode_register(p->chip, 0xfc);
  682. set_mode_register(p->chip, 0x00);
  683. spin_unlock_irqrestore(&p->chip->reg_lock, flags);
  684. p->running = 0; /* clear autoloaded flag */
  685. }
  686. return -EINVAL;
  687. }
  688. if (err) {
  689. p->acc_format = 0;
  690. p->acc_channels = p->acc_width = p->acc_rates = 0;
  691. p->running = 0; /* clear autoloaded flag */
  692. p->mode = 0;
  693. return (err);
  694. } else {
  695. p->running = SNDRV_SB_CSP_ST_AUTO; /* set autoloaded flag */
  696. p->acc_width = SNDRV_SB_CSP_SAMPLE_16BIT; /* only 16 bit data */
  697. p->acc_channels = SNDRV_SB_CSP_MONO | SNDRV_SB_CSP_STEREO;
  698. p->acc_rates = SNDRV_SB_CSP_RATE_ALL; /* HW codecs accept all rates */
  699. }
  700. }
  701. return (p->running & SNDRV_SB_CSP_ST_AUTO) ? 0 : -ENXIO;
  702. }
  703. /*
  704. * start CSP
  705. */
  706. static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channels)
  707. {
  708. unsigned char s_type; /* sample type */
  709. unsigned char mixL, mixR;
  710. int result = -EIO;
  711. unsigned long flags;
  712. if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) {
  713. snd_printd("%s: Microcode not loaded\n", __func__);
  714. return -ENXIO;
  715. }
  716. if (p->running & SNDRV_SB_CSP_ST_RUNNING) {
  717. snd_printd("%s: CSP already running\n", __func__);
  718. return -EBUSY;
  719. }
  720. if (!(sample_width & p->acc_width)) {
  721. snd_printd("%s: Unsupported PCM sample width\n", __func__);
  722. return -EINVAL;
  723. }
  724. if (!(channels & p->acc_channels)) {
  725. snd_printd("%s: Invalid number of channels\n", __func__);
  726. return -EINVAL;
  727. }
  728. /* Mute PCM volume */
  729. spin_lock_irqsave(&p->chip->mixer_lock, flags);
  730. mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV);
  731. mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1);
  732. snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7);
  733. snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7);
  734. spin_lock(&p->chip->reg_lock);
  735. set_mode_register(p->chip, 0xc0); /* c0 = STOP */
  736. set_mode_register(p->chip, 0x70); /* 70 = RUN */
  737. s_type = 0x00;
  738. if (channels == SNDRV_SB_CSP_MONO)
  739. s_type = 0x11; /* 000n 000n (n = 1 if mono) */
  740. if (sample_width == SNDRV_SB_CSP_SAMPLE_8BIT)
  741. s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */
  742. if (set_codec_parameter(p->chip, 0x81, s_type)) {
  743. snd_printd("%s: Set sample type command failed\n", __func__);
  744. goto __fail;
  745. }
  746. if (set_codec_parameter(p->chip, 0x80, 0x00)) {
  747. snd_printd("%s: Codec start command failed\n", __func__);
  748. goto __fail;
  749. }
  750. p->run_width = sample_width;
  751. p->run_channels = channels;
  752. p->running |= SNDRV_SB_CSP_ST_RUNNING;
  753. if (p->mode & SNDRV_SB_CSP_MODE_QSOUND) {
  754. set_codec_parameter(p->chip, 0xe0, 0x01);
  755. /* enable QSound decoder */
  756. set_codec_parameter(p->chip, 0x00, 0xff);
  757. set_codec_parameter(p->chip, 0x01, 0xff);
  758. p->running |= SNDRV_SB_CSP_ST_QSOUND;
  759. /* set QSound startup value */
  760. snd_sb_csp_qsound_transfer(p);
  761. }
  762. result = 0;
  763. __fail:
  764. spin_unlock(&p->chip->reg_lock);
  765. /* restore PCM volume */
  766. snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL);
  767. snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR);
  768. spin_unlock_irqrestore(&p->chip->mixer_lock, flags);
  769. return result;
  770. }
  771. /*
  772. * stop CSP
  773. */
  774. static int snd_sb_csp_stop(struct snd_sb_csp * p)
  775. {
  776. int result;
  777. unsigned char mixL, mixR;
  778. unsigned long flags;
  779. if (!(p->running & SNDRV_SB_CSP_ST_RUNNING))
  780. return 0;
  781. /* Mute PCM volume */
  782. spin_lock_irqsave(&p->chip->mixer_lock, flags);
  783. mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV);
  784. mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1);
  785. snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7);
  786. snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7);
  787. spin_lock(&p->chip->reg_lock);
  788. if (p->running & SNDRV_SB_CSP_ST_QSOUND) {
  789. set_codec_parameter(p->chip, 0xe0, 0x01);
  790. /* disable QSound decoder */
  791. set_codec_parameter(p->chip, 0x00, 0x00);
  792. set_codec_parameter(p->chip, 0x01, 0x00);
  793. p->running &= ~SNDRV_SB_CSP_ST_QSOUND;
  794. }
  795. result = set_mode_register(p->chip, 0xc0); /* c0 = STOP */
  796. spin_unlock(&p->chip->reg_lock);
  797. /* restore PCM volume */
  798. snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL);
  799. snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR);
  800. spin_unlock_irqrestore(&p->chip->mixer_lock, flags);
  801. if (!(result))
  802. p->running &= ~(SNDRV_SB_CSP_ST_PAUSED | SNDRV_SB_CSP_ST_RUNNING);
  803. return result;
  804. }
  805. /*
  806. * pause CSP codec and hold DMA transfer
  807. */
  808. static int snd_sb_csp_pause(struct snd_sb_csp * p)
  809. {
  810. int result;
  811. unsigned long flags;
  812. if (!(p->running & SNDRV_SB_CSP_ST_RUNNING))
  813. return -EBUSY;
  814. spin_lock_irqsave(&p->chip->reg_lock, flags);
  815. result = set_codec_parameter(p->chip, 0x80, 0xff);
  816. spin_unlock_irqrestore(&p->chip->reg_lock, flags);
  817. if (!(result))
  818. p->running |= SNDRV_SB_CSP_ST_PAUSED;
  819. return result;
  820. }
  821. /*
  822. * restart CSP codec and resume DMA transfer
  823. */
  824. static int snd_sb_csp_restart(struct snd_sb_csp * p)
  825. {
  826. int result;
  827. unsigned long flags;
  828. if (!(p->running & SNDRV_SB_CSP_ST_PAUSED))
  829. return -EBUSY;
  830. spin_lock_irqsave(&p->chip->reg_lock, flags);
  831. result = set_codec_parameter(p->chip, 0x80, 0x00);
  832. spin_unlock_irqrestore(&p->chip->reg_lock, flags);
  833. if (!(result))
  834. p->running &= ~SNDRV_SB_CSP_ST_PAUSED;
  835. return result;
  836. }
  837. /* ------------------------------ */
  838. /*
  839. * QSound mixer control for PCM
  840. */
  841. #define snd_sb_qsound_switch_info snd_ctl_boolean_mono_info
  842. static int snd_sb_qsound_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  843. {
  844. struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol);
  845. ucontrol->value.integer.value[0] = p->q_enabled ? 1 : 0;
  846. return 0;
  847. }
  848. static int snd_sb_qsound_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  849. {
  850. struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol);
  851. unsigned long flags;
  852. int change;
  853. unsigned char nval;
  854. nval = ucontrol->value.integer.value[0] & 0x01;
  855. spin_lock_irqsave(&p->q_lock, flags);
  856. change = p->q_enabled != nval;
  857. p->q_enabled = nval;
  858. spin_unlock_irqrestore(&p->q_lock, flags);
  859. return change;
  860. }
  861. static int snd_sb_qsound_space_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  862. {
  863. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  864. uinfo->count = 2;
  865. uinfo->value.integer.min = 0;
  866. uinfo->value.integer.max = SNDRV_SB_CSP_QSOUND_MAX_RIGHT;
  867. return 0;
  868. }
  869. static int snd_sb_qsound_space_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  870. {
  871. struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol);
  872. unsigned long flags;
  873. spin_lock_irqsave(&p->q_lock, flags);
  874. ucontrol->value.integer.value[0] = p->qpos_left;
  875. ucontrol->value.integer.value[1] = p->qpos_right;
  876. spin_unlock_irqrestore(&p->q_lock, flags);
  877. return 0;
  878. }
  879. static int snd_sb_qsound_space_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  880. {
  881. struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol);
  882. unsigned long flags;
  883. int change;
  884. unsigned char nval1, nval2;
  885. nval1 = ucontrol->value.integer.value[0];
  886. if (nval1 > SNDRV_SB_CSP_QSOUND_MAX_RIGHT)
  887. nval1 = SNDRV_SB_CSP_QSOUND_MAX_RIGHT;
  888. nval2 = ucontrol->value.integer.value[1];
  889. if (nval2 > SNDRV_SB_CSP_QSOUND_MAX_RIGHT)
  890. nval2 = SNDRV_SB_CSP_QSOUND_MAX_RIGHT;
  891. spin_lock_irqsave(&p->q_lock, flags);
  892. change = p->qpos_left != nval1 || p->qpos_right != nval2;
  893. p->qpos_left = nval1;
  894. p->qpos_right = nval2;
  895. p->qpos_changed = change;
  896. spin_unlock_irqrestore(&p->q_lock, flags);
  897. return change;
  898. }
  899. static struct snd_kcontrol_new snd_sb_qsound_switch = {
  900. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  901. .name = "3D Control - Switch",
  902. .info = snd_sb_qsound_switch_info,
  903. .get = snd_sb_qsound_switch_get,
  904. .put = snd_sb_qsound_switch_put
  905. };
  906. static struct snd_kcontrol_new snd_sb_qsound_space = {
  907. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  908. .name = "3D Control - Space",
  909. .info = snd_sb_qsound_space_info,
  910. .get = snd_sb_qsound_space_get,
  911. .put = snd_sb_qsound_space_put
  912. };
  913. static int snd_sb_qsound_build(struct snd_sb_csp * p)
  914. {
  915. struct snd_card *card;
  916. int err;
  917. if (snd_BUG_ON(!p))
  918. return -EINVAL;
  919. card = p->chip->card;
  920. p->qpos_left = p->qpos_right = SNDRV_SB_CSP_QSOUND_MAX_RIGHT / 2;
  921. p->qpos_changed = 0;
  922. spin_lock_init(&p->q_lock);
  923. if ((err = snd_ctl_add(card, p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p))) < 0)
  924. goto __error;
  925. if ((err = snd_ctl_add(card, p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p))) < 0)
  926. goto __error;
  927. return 0;
  928. __error:
  929. snd_sb_qsound_destroy(p);
  930. return err;
  931. }
  932. static void snd_sb_qsound_destroy(struct snd_sb_csp * p)
  933. {
  934. struct snd_card *card;
  935. unsigned long flags;
  936. if (snd_BUG_ON(!p))
  937. return;
  938. card = p->chip->card;
  939. down_write(&card->controls_rwsem);
  940. if (p->qsound_switch)
  941. snd_ctl_remove(card, p->qsound_switch);
  942. if (p->qsound_space)
  943. snd_ctl_remove(card, p->qsound_space);
  944. up_write(&card->controls_rwsem);
  945. /* cancel pending transfer of QSound parameters */
  946. spin_lock_irqsave (&p->q_lock, flags);
  947. p->qpos_changed = 0;
  948. spin_unlock_irqrestore (&p->q_lock, flags);
  949. }
  950. /*
  951. * Transfer qsound parameters to CSP,
  952. * function should be called from interrupt routine
  953. */
  954. static int snd_sb_csp_qsound_transfer(struct snd_sb_csp * p)
  955. {
  956. int err = -ENXIO;
  957. spin_lock(&p->q_lock);
  958. if (p->running & SNDRV_SB_CSP_ST_QSOUND) {
  959. set_codec_parameter(p->chip, 0xe0, 0x01);
  960. /* left channel */
  961. set_codec_parameter(p->chip, 0x00, p->qpos_left);
  962. set_codec_parameter(p->chip, 0x02, 0x00);
  963. /* right channel */
  964. set_codec_parameter(p->chip, 0x00, p->qpos_right);
  965. set_codec_parameter(p->chip, 0x03, 0x00);
  966. err = 0;
  967. }
  968. p->qpos_changed = 0;
  969. spin_unlock(&p->q_lock);
  970. return err;
  971. }
  972. /* ------------------------------ */
  973. /*
  974. * proc interface
  975. */
  976. static int init_proc_entry(struct snd_sb_csp * p, int device)
  977. {
  978. char name[16];
  979. struct snd_info_entry *entry;
  980. sprintf(name, "cspD%d", device);
  981. if (! snd_card_proc_new(p->chip->card, name, &entry))
  982. snd_info_set_text_ops(entry, p, info_read);
  983. return 0;
  984. }
  985. static void info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  986. {
  987. struct snd_sb_csp *p = entry->private_data;
  988. snd_iprintf(buffer, "Creative Signal Processor [v%d.%d]\n", (p->version >> 4), (p->version & 0x0f));
  989. snd_iprintf(buffer, "State: %cx%c%c%c\n", ((p->running & SNDRV_SB_CSP_ST_QSOUND) ? 'Q' : '-'),
  990. ((p->running & SNDRV_SB_CSP_ST_PAUSED) ? 'P' : '-'),
  991. ((p->running & SNDRV_SB_CSP_ST_RUNNING) ? 'R' : '-'),
  992. ((p->running & SNDRV_SB_CSP_ST_LOADED) ? 'L' : '-'));
  993. if (p->running & SNDRV_SB_CSP_ST_LOADED) {
  994. snd_iprintf(buffer, "Codec: %s [func #%d]\n", p->codec_name, p->func_nr);
  995. snd_iprintf(buffer, "Sample rates: ");
  996. if (p->acc_rates == SNDRV_SB_CSP_RATE_ALL) {
  997. snd_iprintf(buffer, "All\n");
  998. } else {
  999. snd_iprintf(buffer, "%s%s%s%s\n",
  1000. ((p->acc_rates & SNDRV_SB_CSP_RATE_8000) ? "8000Hz " : ""),
  1001. ((p->acc_rates & SNDRV_SB_CSP_RATE_11025) ? "11025Hz " : ""),
  1002. ((p->acc_rates & SNDRV_SB_CSP_RATE_22050) ? "22050Hz " : ""),
  1003. ((p->acc_rates & SNDRV_SB_CSP_RATE_44100) ? "44100Hz" : ""));
  1004. }
  1005. if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) {
  1006. snd_iprintf(buffer, "QSound decoder %sabled\n",
  1007. p->q_enabled ? "en" : "dis");
  1008. } else {
  1009. snd_iprintf(buffer, "PCM format ID: 0x%x (%s/%s) [%s/%s] [%s/%s]\n",
  1010. p->acc_format,
  1011. ((p->acc_width & SNDRV_SB_CSP_SAMPLE_16BIT) ? "16bit" : "-"),
  1012. ((p->acc_width & SNDRV_SB_CSP_SAMPLE_8BIT) ? "8bit" : "-"),
  1013. ((p->acc_channels & SNDRV_SB_CSP_MONO) ? "mono" : "-"),
  1014. ((p->acc_channels & SNDRV_SB_CSP_STEREO) ? "stereo" : "-"),
  1015. ((p->mode & SNDRV_SB_CSP_MODE_DSP_WRITE) ? "playback" : "-"),
  1016. ((p->mode & SNDRV_SB_CSP_MODE_DSP_READ) ? "capture" : "-"));
  1017. }
  1018. }
  1019. if (p->running & SNDRV_SB_CSP_ST_AUTO) {
  1020. snd_iprintf(buffer, "Autoloaded Mu-Law, A-Law or Ima-ADPCM hardware codec\n");
  1021. }
  1022. if (p->running & SNDRV_SB_CSP_ST_RUNNING) {
  1023. snd_iprintf(buffer, "Processing %dbit %s PCM samples\n",
  1024. ((p->run_width & SNDRV_SB_CSP_SAMPLE_16BIT) ? 16 : 8),
  1025. ((p->run_channels & SNDRV_SB_CSP_MONO) ? "mono" : "stereo"));
  1026. }
  1027. if (p->running & SNDRV_SB_CSP_ST_QSOUND) {
  1028. snd_iprintf(buffer, "Qsound position: left = 0x%x, right = 0x%x\n",
  1029. p->qpos_left, p->qpos_right);
  1030. }
  1031. }
  1032. /* */
  1033. EXPORT_SYMBOL(snd_sb_csp_new);
  1034. /*
  1035. * INIT part
  1036. */
  1037. static int __init alsa_sb_csp_init(void)
  1038. {
  1039. return 0;
  1040. }
  1041. static void __exit alsa_sb_csp_exit(void)
  1042. {
  1043. }
  1044. module_init(alsa_sb_csp_init)
  1045. module_exit(alsa_sb_csp_exit)