sb16_csp.c 33 KB

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