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. *info.codec_name = *p->codec_name;
  184. info.func_nr = p->func_nr;
  185. info.acc_format = p->acc_format;
  186. info.acc_channels = p->acc_channels;
  187. info.acc_width = p->acc_width;
  188. info.acc_rates = p->acc_rates;
  189. info.csp_mode = p->mode;
  190. info.run_channels = p->run_channels;
  191. info.run_width = p->run_width;
  192. info.version = p->version;
  193. info.state = p->running;
  194. if (copy_to_user((void __user *)arg, &info, sizeof(info)))
  195. err = -EFAULT;
  196. else
  197. err = 0;
  198. break;
  199. /* load CSP microcode */
  200. case SNDRV_SB_CSP_IOCTL_LOAD_CODE:
  201. err = (p->running & SNDRV_SB_CSP_ST_RUNNING ?
  202. -EBUSY : snd_sb_csp_riff_load(p, (struct snd_sb_csp_microcode __user *) arg));
  203. break;
  204. case SNDRV_SB_CSP_IOCTL_UNLOAD_CODE:
  205. err = (p->running & SNDRV_SB_CSP_ST_RUNNING ?
  206. -EBUSY : snd_sb_csp_unload(p));
  207. break;
  208. /* change CSP running state */
  209. case SNDRV_SB_CSP_IOCTL_START:
  210. if (copy_from_user(&start_info, (void __user *) arg, sizeof(start_info)))
  211. err = -EFAULT;
  212. else
  213. err = snd_sb_csp_start(p, start_info.sample_width, start_info.channels);
  214. break;
  215. case SNDRV_SB_CSP_IOCTL_STOP:
  216. err = snd_sb_csp_stop(p);
  217. break;
  218. case SNDRV_SB_CSP_IOCTL_PAUSE:
  219. err = snd_sb_csp_pause(p);
  220. break;
  221. case SNDRV_SB_CSP_IOCTL_RESTART:
  222. err = snd_sb_csp_restart(p);
  223. break;
  224. default:
  225. err = -ENOTTY;
  226. break;
  227. }
  228. return err;
  229. }
  230. /*
  231. * close the device
  232. */
  233. static int snd_sb_csp_release(struct snd_hwdep * hw, struct file *file)
  234. {
  235. struct snd_sb_csp *p = hw->private_data;
  236. return (snd_sb_csp_unuse(p));
  237. }
  238. /* ------------------------------ */
  239. /*
  240. * acquire device
  241. */
  242. static int snd_sb_csp_use(struct snd_sb_csp * p)
  243. {
  244. mutex_lock(&p->access_mutex);
  245. if (p->used) {
  246. mutex_unlock(&p->access_mutex);
  247. return -EAGAIN;
  248. }
  249. p->used++;
  250. mutex_unlock(&p->access_mutex);
  251. return 0;
  252. }
  253. /*
  254. * release device
  255. */
  256. static int snd_sb_csp_unuse(struct snd_sb_csp * p)
  257. {
  258. mutex_lock(&p->access_mutex);
  259. p->used--;
  260. mutex_unlock(&p->access_mutex);
  261. return 0;
  262. }
  263. /*
  264. * load microcode via ioctl:
  265. * code is user-space pointer
  266. */
  267. static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
  268. struct snd_sb_csp_microcode __user * mcode)
  269. {
  270. struct snd_sb_csp_mc_header info;
  271. unsigned char __user *data_ptr;
  272. unsigned char __user *data_end;
  273. unsigned short func_nr = 0;
  274. struct riff_header file_h, item_h, code_h;
  275. __u32 item_type;
  276. struct desc_header funcdesc_h;
  277. unsigned long flags;
  278. int err;
  279. if (copy_from_user(&info, mcode, sizeof(info)))
  280. return -EFAULT;
  281. data_ptr = mcode->data;
  282. if (copy_from_user(&file_h, data_ptr, sizeof(file_h)))
  283. return -EFAULT;
  284. if ((file_h.name != RIFF_HEADER) ||
  285. (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) {
  286. snd_printd("%s: Invalid RIFF header\n", __func__);
  287. return -EINVAL;
  288. }
  289. data_ptr += sizeof(file_h);
  290. data_end = data_ptr + le32_to_cpu(file_h.len);
  291. if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
  292. return -EFAULT;
  293. if (item_type != CSP__HEADER) {
  294. snd_printd("%s: Invalid RIFF file type\n", __func__);
  295. return -EINVAL;
  296. }
  297. data_ptr += sizeof (item_type);
  298. for (; data_ptr < data_end; data_ptr += le32_to_cpu(item_h.len)) {
  299. if (copy_from_user(&item_h, data_ptr, sizeof(item_h)))
  300. return -EFAULT;
  301. data_ptr += sizeof(item_h);
  302. if (item_h.name != LIST_HEADER)
  303. continue;
  304. if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
  305. return -EFAULT;
  306. switch (item_type) {
  307. case FUNC_HEADER:
  308. if (copy_from_user(&funcdesc_h, data_ptr + sizeof(item_type), sizeof(funcdesc_h)))
  309. return -EFAULT;
  310. func_nr = le16_to_cpu(funcdesc_h.func_nr);
  311. break;
  312. case CODE_HEADER:
  313. if (func_nr != info.func_req)
  314. break; /* not required function, try next */
  315. data_ptr += sizeof(item_type);
  316. /* destroy QSound mixer element */
  317. if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) {
  318. snd_sb_qsound_destroy(p);
  319. }
  320. /* Clear all flags */
  321. p->running = 0;
  322. p->mode = 0;
  323. /* load microcode blocks */
  324. for (;;) {
  325. if (data_ptr >= data_end)
  326. return -EINVAL;
  327. if (copy_from_user(&code_h, data_ptr, sizeof(code_h)))
  328. return -EFAULT;
  329. /* init microcode blocks */
  330. if (code_h.name != INIT_HEADER)
  331. break;
  332. data_ptr += sizeof(code_h);
  333. err = snd_sb_csp_load_user(p, data_ptr, le32_to_cpu(code_h.len),
  334. SNDRV_SB_CSP_LOAD_INITBLOCK);
  335. if (err)
  336. return err;
  337. data_ptr += le32_to_cpu(code_h.len);
  338. }
  339. /* main microcode block */
  340. if (copy_from_user(&code_h, data_ptr, sizeof(code_h)))
  341. return -EFAULT;
  342. if (code_h.name != MAIN_HEADER) {
  343. snd_printd("%s: Missing 'main' microcode\n", __func__);
  344. return -EINVAL;
  345. }
  346. data_ptr += sizeof(code_h);
  347. err = snd_sb_csp_load_user(p, data_ptr,
  348. le32_to_cpu(code_h.len), 0);
  349. if (err)
  350. return err;
  351. /* fill in codec header */
  352. strlcpy(p->codec_name, info.codec_name, sizeof(p->codec_name));
  353. p->func_nr = func_nr;
  354. p->mode = le16_to_cpu(funcdesc_h.flags_play_rec);
  355. switch (le16_to_cpu(funcdesc_h.VOC_type)) {
  356. case 0x0001: /* QSound decoder */
  357. if (le16_to_cpu(funcdesc_h.flags_play_rec) == SNDRV_SB_CSP_MODE_DSP_WRITE) {
  358. if (snd_sb_qsound_build(p) == 0)
  359. /* set QSound flag and clear all other mode flags */
  360. p->mode = SNDRV_SB_CSP_MODE_QSOUND;
  361. }
  362. p->acc_format = 0;
  363. break;
  364. case 0x0006: /* A Law codec */
  365. p->acc_format = SNDRV_PCM_FMTBIT_A_LAW;
  366. break;
  367. case 0x0007: /* Mu Law codec */
  368. p->acc_format = SNDRV_PCM_FMTBIT_MU_LAW;
  369. break;
  370. case 0x0011: /* what Creative thinks is IMA ADPCM codec */
  371. case 0x0200: /* Creative ADPCM codec */
  372. p->acc_format = SNDRV_PCM_FMTBIT_IMA_ADPCM;
  373. break;
  374. case 201: /* Text 2 Speech decoder */
  375. /* TODO: Text2Speech handling routines */
  376. p->acc_format = 0;
  377. break;
  378. case 0x0202: /* Fast Speech 8 codec */
  379. case 0x0203: /* Fast Speech 10 codec */
  380. p->acc_format = SNDRV_PCM_FMTBIT_SPECIAL;
  381. break;
  382. default: /* other codecs are unsupported */
  383. p->acc_format = p->acc_width = p->acc_rates = 0;
  384. p->mode = 0;
  385. snd_printd("%s: Unsupported CSP codec type: 0x%04x\n",
  386. __func__,
  387. le16_to_cpu(funcdesc_h.VOC_type));
  388. return -EINVAL;
  389. }
  390. p->acc_channels = le16_to_cpu(funcdesc_h.flags_stereo_mono);
  391. p->acc_width = le16_to_cpu(funcdesc_h.flags_16bit_8bit);
  392. p->acc_rates = le16_to_cpu(funcdesc_h.flags_rates);
  393. /* Decouple CSP from IRQ and DMAREQ lines */
  394. spin_lock_irqsave(&p->chip->reg_lock, flags);
  395. set_mode_register(p->chip, 0xfc);
  396. set_mode_register(p->chip, 0x00);
  397. spin_unlock_irqrestore(&p->chip->reg_lock, flags);
  398. /* finished loading successfully */
  399. p->running = SNDRV_SB_CSP_ST_LOADED; /* set LOADED flag */
  400. return 0;
  401. }
  402. }
  403. snd_printd("%s: Function #%d not found\n", __func__, info.func_req);
  404. return -EINVAL;
  405. }
  406. /*
  407. * unload CSP microcode
  408. */
  409. static int snd_sb_csp_unload(struct snd_sb_csp * p)
  410. {
  411. if (p->running & SNDRV_SB_CSP_ST_RUNNING)
  412. return -EBUSY;
  413. if (!(p->running & SNDRV_SB_CSP_ST_LOADED))
  414. return -ENXIO;
  415. /* clear supported formats */
  416. p->acc_format = 0;
  417. p->acc_channels = p->acc_width = p->acc_rates = 0;
  418. /* destroy QSound mixer element */
  419. if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) {
  420. snd_sb_qsound_destroy(p);
  421. }
  422. /* clear all flags */
  423. p->running = 0;
  424. p->mode = 0;
  425. return 0;
  426. }
  427. /*
  428. * send command sequence to DSP
  429. */
  430. static inline int command_seq(struct snd_sb *chip, const unsigned char *seq, int size)
  431. {
  432. int i;
  433. for (i = 0; i < size; i++) {
  434. if (!snd_sbdsp_command(chip, seq[i]))
  435. return -EIO;
  436. }
  437. return 0;
  438. }
  439. /*
  440. * set CSP codec parameter
  441. */
  442. static int set_codec_parameter(struct snd_sb *chip, unsigned char par, unsigned char val)
  443. {
  444. unsigned char dsp_cmd[3];
  445. dsp_cmd[0] = 0x05; /* CSP set codec parameter */
  446. dsp_cmd[1] = val; /* Parameter value */
  447. dsp_cmd[2] = par; /* Parameter */
  448. command_seq(chip, dsp_cmd, 3);
  449. snd_sbdsp_command(chip, 0x03); /* DSP read? */
  450. if (snd_sbdsp_get_byte(chip) != par)
  451. return -EIO;
  452. return 0;
  453. }
  454. /*
  455. * set CSP register
  456. */
  457. static int set_register(struct snd_sb *chip, unsigned char reg, unsigned char val)
  458. {
  459. unsigned char dsp_cmd[3];
  460. dsp_cmd[0] = 0x0e; /* CSP set register */
  461. dsp_cmd[1] = reg; /* CSP Register */
  462. dsp_cmd[2] = val; /* value */
  463. return command_seq(chip, dsp_cmd, 3);
  464. }
  465. /*
  466. * read CSP register
  467. * return < 0 -> error
  468. */
  469. static int read_register(struct snd_sb *chip, unsigned char reg)
  470. {
  471. unsigned char dsp_cmd[2];
  472. dsp_cmd[0] = 0x0f; /* CSP read register */
  473. dsp_cmd[1] = reg; /* CSP Register */
  474. command_seq(chip, dsp_cmd, 2);
  475. return snd_sbdsp_get_byte(chip); /* Read DSP value */
  476. }
  477. /*
  478. * set CSP mode register
  479. */
  480. static int set_mode_register(struct snd_sb *chip, unsigned char mode)
  481. {
  482. unsigned char dsp_cmd[2];
  483. dsp_cmd[0] = 0x04; /* CSP set mode register */
  484. dsp_cmd[1] = mode; /* mode */
  485. return command_seq(chip, dsp_cmd, 2);
  486. }
  487. /*
  488. * Detect CSP
  489. * return 0 if CSP exists.
  490. */
  491. static int csp_detect(struct snd_sb *chip, int *version)
  492. {
  493. unsigned char csp_test1, csp_test2;
  494. unsigned long flags;
  495. int result = -ENODEV;
  496. spin_lock_irqsave(&chip->reg_lock, flags);
  497. set_codec_parameter(chip, 0x00, 0x00);
  498. set_mode_register(chip, 0xfc); /* 0xfc = ?? */
  499. csp_test1 = read_register(chip, 0x83);
  500. set_register(chip, 0x83, ~csp_test1);
  501. csp_test2 = read_register(chip, 0x83);
  502. if (csp_test2 != (csp_test1 ^ 0xff))
  503. goto __fail;
  504. set_register(chip, 0x83, csp_test1);
  505. csp_test2 = read_register(chip, 0x83);
  506. if (csp_test2 != csp_test1)
  507. goto __fail;
  508. set_mode_register(chip, 0x00); /* 0x00 = ? */
  509. *version = get_version(chip);
  510. snd_sbdsp_reset(chip); /* reset DSP after getversion! */
  511. if (*version >= 0x10 && *version <= 0x1f)
  512. result = 0; /* valid version id */
  513. __fail:
  514. spin_unlock_irqrestore(&chip->reg_lock, flags);
  515. return result;
  516. }
  517. /*
  518. * get CSP version number
  519. */
  520. static int get_version(struct snd_sb *chip)
  521. {
  522. unsigned char dsp_cmd[2];
  523. dsp_cmd[0] = 0x08; /* SB_DSP_!something! */
  524. dsp_cmd[1] = 0x03; /* get chip version id? */
  525. command_seq(chip, dsp_cmd, 2);
  526. return (snd_sbdsp_get_byte(chip));
  527. }
  528. /*
  529. * check if the CSP version is valid
  530. */
  531. static int snd_sb_csp_check_version(struct snd_sb_csp * p)
  532. {
  533. if (p->version < 0x10 || p->version > 0x1f) {
  534. snd_printd("%s: Invalid CSP version: 0x%x\n", __func__, p->version);
  535. return 1;
  536. }
  537. return 0;
  538. }
  539. /*
  540. * download microcode to CSP (microcode should have one "main" block).
  541. */
  542. static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int size, int load_flags)
  543. {
  544. int status, i;
  545. int err;
  546. int result = -EIO;
  547. unsigned long flags;
  548. spin_lock_irqsave(&p->chip->reg_lock, flags);
  549. snd_sbdsp_command(p->chip, 0x01); /* CSP download command */
  550. if (snd_sbdsp_get_byte(p->chip)) {
  551. snd_printd("%s: Download command failed\n", __func__);
  552. goto __fail;
  553. }
  554. /* Send CSP low byte (size - 1) */
  555. snd_sbdsp_command(p->chip, (unsigned char)(size - 1));
  556. /* Send high byte */
  557. snd_sbdsp_command(p->chip, (unsigned char)((size - 1) >> 8));
  558. /* send microcode sequence */
  559. /* load from kernel space */
  560. while (size--) {
  561. if (!snd_sbdsp_command(p->chip, *buf++))
  562. goto __fail;
  563. }
  564. if (snd_sbdsp_get_byte(p->chip))
  565. goto __fail;
  566. if (load_flags & SNDRV_SB_CSP_LOAD_INITBLOCK) {
  567. i = 0;
  568. /* some codecs (FastSpeech) take some time to initialize */
  569. while (1) {
  570. snd_sbdsp_command(p->chip, 0x03);
  571. status = snd_sbdsp_get_byte(p->chip);
  572. if (status == 0x55 || ++i >= 10)
  573. break;
  574. udelay (10);
  575. }
  576. if (status != 0x55) {
  577. snd_printd("%s: Microcode initialization failed\n", __func__);
  578. goto __fail;
  579. }
  580. } else {
  581. /*
  582. * Read mixer register SB_DSP4_DMASETUP after loading 'main' code.
  583. * Start CSP chip if no 16bit DMA channel is set - some kind
  584. * of autorun or perhaps a bugfix?
  585. */
  586. spin_lock(&p->chip->mixer_lock);
  587. status = snd_sbmixer_read(p->chip, SB_DSP4_DMASETUP);
  588. spin_unlock(&p->chip->mixer_lock);
  589. if (!(status & (SB_DMASETUP_DMA7 | SB_DMASETUP_DMA6 | SB_DMASETUP_DMA5))) {
  590. err = (set_codec_parameter(p->chip, 0xaa, 0x00) ||
  591. set_codec_parameter(p->chip, 0xff, 0x00));
  592. snd_sbdsp_reset(p->chip); /* really! */
  593. if (err)
  594. goto __fail;
  595. set_mode_register(p->chip, 0xc0); /* c0 = STOP */
  596. set_mode_register(p->chip, 0x70); /* 70 = RUN */
  597. }
  598. }
  599. result = 0;
  600. __fail:
  601. spin_unlock_irqrestore(&p->chip->reg_lock, flags);
  602. return result;
  603. }
  604. static int snd_sb_csp_load_user(struct snd_sb_csp * p, const unsigned char __user *buf, int size, int load_flags)
  605. {
  606. int err;
  607. unsigned char *kbuf;
  608. kbuf = memdup_user(buf, size);
  609. if (IS_ERR(kbuf))
  610. return PTR_ERR(kbuf);
  611. err = snd_sb_csp_load(p, kbuf, size, load_flags);
  612. kfree(kbuf);
  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. if (snd_BUG_ON(!p))
  919. return -EINVAL;
  920. card = p->chip->card;
  921. p->qpos_left = p->qpos_right = SNDRV_SB_CSP_QSOUND_MAX_RIGHT / 2;
  922. p->qpos_changed = 0;
  923. spin_lock_init(&p->q_lock);
  924. if ((err = snd_ctl_add(card, p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p))) < 0)
  925. goto __error;
  926. if ((err = snd_ctl_add(card, p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p))) < 0)
  927. goto __error;
  928. return 0;
  929. __error:
  930. snd_sb_qsound_destroy(p);
  931. return err;
  932. }
  933. static void snd_sb_qsound_destroy(struct snd_sb_csp * p)
  934. {
  935. struct snd_card *card;
  936. unsigned long flags;
  937. if (snd_BUG_ON(!p))
  938. return;
  939. card = p->chip->card;
  940. down_write(&card->controls_rwsem);
  941. if (p->qsound_switch)
  942. snd_ctl_remove(card, p->qsound_switch);
  943. if (p->qsound_space)
  944. snd_ctl_remove(card, p->qsound_space);
  945. up_write(&card->controls_rwsem);
  946. /* cancel pending transfer of QSound parameters */
  947. spin_lock_irqsave (&p->q_lock, flags);
  948. p->qpos_changed = 0;
  949. spin_unlock_irqrestore (&p->q_lock, flags);
  950. }
  951. /*
  952. * Transfer qsound parameters to CSP,
  953. * function should be called from interrupt routine
  954. */
  955. static int snd_sb_csp_qsound_transfer(struct snd_sb_csp * p)
  956. {
  957. int err = -ENXIO;
  958. spin_lock(&p->q_lock);
  959. if (p->running & SNDRV_SB_CSP_ST_QSOUND) {
  960. set_codec_parameter(p->chip, 0xe0, 0x01);
  961. /* left channel */
  962. set_codec_parameter(p->chip, 0x00, p->qpos_left);
  963. set_codec_parameter(p->chip, 0x02, 0x00);
  964. /* right channel */
  965. set_codec_parameter(p->chip, 0x00, p->qpos_right);
  966. set_codec_parameter(p->chip, 0x03, 0x00);
  967. err = 0;
  968. }
  969. p->qpos_changed = 0;
  970. spin_unlock(&p->q_lock);
  971. return err;
  972. }
  973. /* ------------------------------ */
  974. /*
  975. * proc interface
  976. */
  977. static int init_proc_entry(struct snd_sb_csp * p, int device)
  978. {
  979. char name[16];
  980. struct snd_info_entry *entry;
  981. sprintf(name, "cspD%d", device);
  982. if (! snd_card_proc_new(p->chip->card, name, &entry))
  983. snd_info_set_text_ops(entry, p, info_read);
  984. return 0;
  985. }
  986. static void info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  987. {
  988. struct snd_sb_csp *p = entry->private_data;
  989. snd_iprintf(buffer, "Creative Signal Processor [v%d.%d]\n", (p->version >> 4), (p->version & 0x0f));
  990. snd_iprintf(buffer, "State: %cx%c%c%c\n", ((p->running & SNDRV_SB_CSP_ST_QSOUND) ? 'Q' : '-'),
  991. ((p->running & SNDRV_SB_CSP_ST_PAUSED) ? 'P' : '-'),
  992. ((p->running & SNDRV_SB_CSP_ST_RUNNING) ? 'R' : '-'),
  993. ((p->running & SNDRV_SB_CSP_ST_LOADED) ? 'L' : '-'));
  994. if (p->running & SNDRV_SB_CSP_ST_LOADED) {
  995. snd_iprintf(buffer, "Codec: %s [func #%d]\n", p->codec_name, p->func_nr);
  996. snd_iprintf(buffer, "Sample rates: ");
  997. if (p->acc_rates == SNDRV_SB_CSP_RATE_ALL) {
  998. snd_iprintf(buffer, "All\n");
  999. } else {
  1000. snd_iprintf(buffer, "%s%s%s%s\n",
  1001. ((p->acc_rates & SNDRV_SB_CSP_RATE_8000) ? "8000Hz " : ""),
  1002. ((p->acc_rates & SNDRV_SB_CSP_RATE_11025) ? "11025Hz " : ""),
  1003. ((p->acc_rates & SNDRV_SB_CSP_RATE_22050) ? "22050Hz " : ""),
  1004. ((p->acc_rates & SNDRV_SB_CSP_RATE_44100) ? "44100Hz" : ""));
  1005. }
  1006. if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) {
  1007. snd_iprintf(buffer, "QSound decoder %sabled\n",
  1008. p->q_enabled ? "en" : "dis");
  1009. } else {
  1010. snd_iprintf(buffer, "PCM format ID: 0x%x (%s/%s) [%s/%s] [%s/%s]\n",
  1011. p->acc_format,
  1012. ((p->acc_width & SNDRV_SB_CSP_SAMPLE_16BIT) ? "16bit" : "-"),
  1013. ((p->acc_width & SNDRV_SB_CSP_SAMPLE_8BIT) ? "8bit" : "-"),
  1014. ((p->acc_channels & SNDRV_SB_CSP_MONO) ? "mono" : "-"),
  1015. ((p->acc_channels & SNDRV_SB_CSP_STEREO) ? "stereo" : "-"),
  1016. ((p->mode & SNDRV_SB_CSP_MODE_DSP_WRITE) ? "playback" : "-"),
  1017. ((p->mode & SNDRV_SB_CSP_MODE_DSP_READ) ? "capture" : "-"));
  1018. }
  1019. }
  1020. if (p->running & SNDRV_SB_CSP_ST_AUTO) {
  1021. snd_iprintf(buffer, "Autoloaded Mu-Law, A-Law or Ima-ADPCM hardware codec\n");
  1022. }
  1023. if (p->running & SNDRV_SB_CSP_ST_RUNNING) {
  1024. snd_iprintf(buffer, "Processing %dbit %s PCM samples\n",
  1025. ((p->run_width & SNDRV_SB_CSP_SAMPLE_16BIT) ? 16 : 8),
  1026. ((p->run_channels & SNDRV_SB_CSP_MONO) ? "mono" : "stereo"));
  1027. }
  1028. if (p->running & SNDRV_SB_CSP_ST_QSOUND) {
  1029. snd_iprintf(buffer, "Qsound position: left = 0x%x, right = 0x%x\n",
  1030. p->qpos_left, p->qpos_right);
  1031. }
  1032. }
  1033. /* */
  1034. EXPORT_SYMBOL(snd_sb_csp_new);
  1035. /*
  1036. * INIT part
  1037. */
  1038. static int __init alsa_sb_csp_init(void)
  1039. {
  1040. return 0;
  1041. }
  1042. static void __exit alsa_sb_csp_exit(void)
  1043. {
  1044. }
  1045. module_init(alsa_sb_csp_init)
  1046. module_exit(alsa_sb_csp_exit)