sb16_csp.c 33 KB

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