sb16_csp.c 32 KB

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