sb16_csp.c 33 KB

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