sb16_csp.c 32 KB

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