vx_core.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. /*
  2. * Driver for Digigram VX soundcards
  3. *
  4. * Hardware core part
  5. *
  6. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/delay.h>
  23. #include <linux/slab.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/init.h>
  26. #include <linux/device.h>
  27. #include <linux/firmware.h>
  28. #include <linux/module.h>
  29. #include <linux/io.h>
  30. #include <sound/core.h>
  31. #include <sound/pcm.h>
  32. #include <sound/asoundef.h>
  33. #include <sound/info.h>
  34. #include <sound/vx_core.h>
  35. #include "vx_cmd.h"
  36. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  37. MODULE_DESCRIPTION("Common routines for Digigram VX drivers");
  38. MODULE_LICENSE("GPL");
  39. /*
  40. * vx_check_reg_bit - wait for the specified bit is set/reset on a register
  41. * @reg: register to check
  42. * @mask: bit mask
  43. * @bit: resultant bit to be checked
  44. * @time: time-out of loop in msec
  45. *
  46. * returns zero if a bit matches, or a negative error code.
  47. */
  48. int snd_vx_check_reg_bit(struct vx_core *chip, int reg, int mask, int bit, int time)
  49. {
  50. unsigned long end_time = jiffies + (time * HZ + 999) / 1000;
  51. static char *reg_names[VX_REG_MAX] = {
  52. "ICR", "CVR", "ISR", "IVR", "RXH", "RXM", "RXL",
  53. "DMA", "CDSP", "RFREQ", "RUER/V2", "DATA", "MEMIRQ",
  54. "ACQ", "BIT0", "BIT1", "MIC0", "MIC1", "MIC2",
  55. "MIC3", "INTCSR", "CNTRL", "GPIOC",
  56. "LOFREQ", "HIFREQ", "CSUER", "RUER"
  57. };
  58. do {
  59. if ((snd_vx_inb(chip, reg) & mask) == bit)
  60. return 0;
  61. //msleep(10);
  62. } while (time_after_eq(end_time, jiffies));
  63. snd_printd(KERN_DEBUG "vx_check_reg_bit: timeout, reg=%s, mask=0x%x, val=0x%x\n", reg_names[reg], mask, snd_vx_inb(chip, reg));
  64. return -EIO;
  65. }
  66. EXPORT_SYMBOL(snd_vx_check_reg_bit);
  67. /*
  68. * vx_send_irq_dsp - set command irq bit
  69. * @num: the requested IRQ type, IRQ_XXX
  70. *
  71. * this triggers the specified IRQ request
  72. * returns 0 if successful, or a negative error code.
  73. *
  74. */
  75. static int vx_send_irq_dsp(struct vx_core *chip, int num)
  76. {
  77. int nirq;
  78. /* wait for Hc = 0 */
  79. if (snd_vx_check_reg_bit(chip, VX_CVR, CVR_HC, 0, 200) < 0)
  80. return -EIO;
  81. nirq = num;
  82. if (vx_has_new_dsp(chip))
  83. nirq += VXP_IRQ_OFFSET;
  84. vx_outb(chip, CVR, (nirq >> 1) | CVR_HC);
  85. return 0;
  86. }
  87. /*
  88. * vx_reset_chk - reset CHK bit on ISR
  89. *
  90. * returns 0 if successful, or a negative error code.
  91. */
  92. static int vx_reset_chk(struct vx_core *chip)
  93. {
  94. /* Reset irq CHK */
  95. if (vx_send_irq_dsp(chip, IRQ_RESET_CHK) < 0)
  96. return -EIO;
  97. /* Wait until CHK = 0 */
  98. if (vx_check_isr(chip, ISR_CHK, 0, 200) < 0)
  99. return -EIO;
  100. return 0;
  101. }
  102. /*
  103. * vx_transfer_end - terminate message transfer
  104. * @cmd: IRQ message to send (IRQ_MESS_XXX_END)
  105. *
  106. * returns 0 if successful, or a negative error code.
  107. * the error code can be VX-specific, retrieved via vx_get_error().
  108. * NB: call with mutex held!
  109. */
  110. static int vx_transfer_end(struct vx_core *chip, int cmd)
  111. {
  112. int err;
  113. if ((err = vx_reset_chk(chip)) < 0)
  114. return err;
  115. /* irq MESS_READ/WRITE_END */
  116. if ((err = vx_send_irq_dsp(chip, cmd)) < 0)
  117. return err;
  118. /* Wait CHK = 1 */
  119. if ((err = vx_wait_isr_bit(chip, ISR_CHK)) < 0)
  120. return err;
  121. /* If error, Read RX */
  122. if ((err = vx_inb(chip, ISR)) & ISR_ERR) {
  123. if ((err = vx_wait_for_rx_full(chip)) < 0) {
  124. snd_printd(KERN_DEBUG "transfer_end: error in rx_full\n");
  125. return err;
  126. }
  127. err = vx_inb(chip, RXH) << 16;
  128. err |= vx_inb(chip, RXM) << 8;
  129. err |= vx_inb(chip, RXL);
  130. snd_printd(KERN_DEBUG "transfer_end: error = 0x%x\n", err);
  131. return -(VX_ERR_MASK | err);
  132. }
  133. return 0;
  134. }
  135. /*
  136. * vx_read_status - return the status rmh
  137. * @rmh: rmh record to store the status
  138. *
  139. * returns 0 if successful, or a negative error code.
  140. * the error code can be VX-specific, retrieved via vx_get_error().
  141. * NB: call with mutex held!
  142. */
  143. static int vx_read_status(struct vx_core *chip, struct vx_rmh *rmh)
  144. {
  145. int i, err, val, size;
  146. /* no read necessary? */
  147. if (rmh->DspStat == RMH_SSIZE_FIXED && rmh->LgStat == 0)
  148. return 0;
  149. /* Wait for RX full (with timeout protection)
  150. * The first word of status is in RX
  151. */
  152. err = vx_wait_for_rx_full(chip);
  153. if (err < 0)
  154. return err;
  155. /* Read RX */
  156. val = vx_inb(chip, RXH) << 16;
  157. val |= vx_inb(chip, RXM) << 8;
  158. val |= vx_inb(chip, RXL);
  159. /* If status given by DSP, let's decode its size */
  160. switch (rmh->DspStat) {
  161. case RMH_SSIZE_ARG:
  162. size = val & 0xff;
  163. rmh->Stat[0] = val & 0xffff00;
  164. rmh->LgStat = size + 1;
  165. break;
  166. case RMH_SSIZE_MASK:
  167. /* Let's count the arg numbers from a mask */
  168. rmh->Stat[0] = val;
  169. size = 0;
  170. while (val) {
  171. if (val & 0x01)
  172. size++;
  173. val >>= 1;
  174. }
  175. rmh->LgStat = size + 1;
  176. break;
  177. default:
  178. /* else retrieve the status length given by the driver */
  179. size = rmh->LgStat;
  180. rmh->Stat[0] = val; /* Val is the status 1st word */
  181. size--; /* hence adjust remaining length */
  182. break;
  183. }
  184. if (size < 1)
  185. return 0;
  186. if (snd_BUG_ON(size >= SIZE_MAX_STATUS))
  187. return -EINVAL;
  188. for (i = 1; i <= size; i++) {
  189. /* trigger an irq MESS_WRITE_NEXT */
  190. err = vx_send_irq_dsp(chip, IRQ_MESS_WRITE_NEXT);
  191. if (err < 0)
  192. return err;
  193. /* Wait for RX full (with timeout protection) */
  194. err = vx_wait_for_rx_full(chip);
  195. if (err < 0)
  196. return err;
  197. rmh->Stat[i] = vx_inb(chip, RXH) << 16;
  198. rmh->Stat[i] |= vx_inb(chip, RXM) << 8;
  199. rmh->Stat[i] |= vx_inb(chip, RXL);
  200. }
  201. return vx_transfer_end(chip, IRQ_MESS_WRITE_END);
  202. }
  203. #define MASK_MORE_THAN_1_WORD_COMMAND 0x00008000
  204. #define MASK_1_WORD_COMMAND 0x00ff7fff
  205. /*
  206. * vx_send_msg_nolock - send a DSP message and read back the status
  207. * @rmh: the rmh record to send and receive
  208. *
  209. * returns 0 if successful, or a negative error code.
  210. * the error code can be VX-specific, retrieved via vx_get_error().
  211. *
  212. * this function doesn't call mutex lock at all.
  213. */
  214. int vx_send_msg_nolock(struct vx_core *chip, struct vx_rmh *rmh)
  215. {
  216. int i, err;
  217. if (chip->chip_status & VX_STAT_IS_STALE)
  218. return -EBUSY;
  219. if ((err = vx_reset_chk(chip)) < 0) {
  220. snd_printd(KERN_DEBUG "vx_send_msg: vx_reset_chk error\n");
  221. return err;
  222. }
  223. #if 0
  224. printk(KERN_DEBUG "rmh: cmd = 0x%06x, length = %d, stype = %d\n",
  225. rmh->Cmd[0], rmh->LgCmd, rmh->DspStat);
  226. if (rmh->LgCmd > 1) {
  227. printk(KERN_DEBUG " ");
  228. for (i = 1; i < rmh->LgCmd; i++)
  229. printk("0x%06x ", rmh->Cmd[i]);
  230. printk("\n");
  231. }
  232. #endif
  233. /* Check bit M is set according to length of the command */
  234. if (rmh->LgCmd > 1)
  235. rmh->Cmd[0] |= MASK_MORE_THAN_1_WORD_COMMAND;
  236. else
  237. rmh->Cmd[0] &= MASK_1_WORD_COMMAND;
  238. /* Wait for TX empty */
  239. if ((err = vx_wait_isr_bit(chip, ISR_TX_EMPTY)) < 0) {
  240. snd_printd(KERN_DEBUG "vx_send_msg: wait tx empty error\n");
  241. return err;
  242. }
  243. /* Write Cmd[0] */
  244. vx_outb(chip, TXH, (rmh->Cmd[0] >> 16) & 0xff);
  245. vx_outb(chip, TXM, (rmh->Cmd[0] >> 8) & 0xff);
  246. vx_outb(chip, TXL, rmh->Cmd[0] & 0xff);
  247. /* Trigger irq MESSAGE */
  248. if ((err = vx_send_irq_dsp(chip, IRQ_MESSAGE)) < 0) {
  249. snd_printd(KERN_DEBUG "vx_send_msg: send IRQ_MESSAGE error\n");
  250. return err;
  251. }
  252. /* Wait for CHK = 1 */
  253. if ((err = vx_wait_isr_bit(chip, ISR_CHK)) < 0)
  254. return err;
  255. /* If error, get error value from RX */
  256. if (vx_inb(chip, ISR) & ISR_ERR) {
  257. if ((err = vx_wait_for_rx_full(chip)) < 0) {
  258. snd_printd(KERN_DEBUG "vx_send_msg: rx_full read error\n");
  259. return err;
  260. }
  261. err = vx_inb(chip, RXH) << 16;
  262. err |= vx_inb(chip, RXM) << 8;
  263. err |= vx_inb(chip, RXL);
  264. snd_printd(KERN_DEBUG "msg got error = 0x%x at cmd[0]\n", err);
  265. err = -(VX_ERR_MASK | err);
  266. return err;
  267. }
  268. /* Send the other words */
  269. if (rmh->LgCmd > 1) {
  270. for (i = 1; i < rmh->LgCmd; i++) {
  271. /* Wait for TX ready */
  272. if ((err = vx_wait_isr_bit(chip, ISR_TX_READY)) < 0) {
  273. snd_printd(KERN_DEBUG "vx_send_msg: tx_ready error\n");
  274. return err;
  275. }
  276. /* Write Cmd[i] */
  277. vx_outb(chip, TXH, (rmh->Cmd[i] >> 16) & 0xff);
  278. vx_outb(chip, TXM, (rmh->Cmd[i] >> 8) & 0xff);
  279. vx_outb(chip, TXL, rmh->Cmd[i] & 0xff);
  280. /* Trigger irq MESS_READ_NEXT */
  281. if ((err = vx_send_irq_dsp(chip, IRQ_MESS_READ_NEXT)) < 0) {
  282. snd_printd(KERN_DEBUG "vx_send_msg: IRQ_READ_NEXT error\n");
  283. return err;
  284. }
  285. }
  286. /* Wait for TX empty */
  287. if ((err = vx_wait_isr_bit(chip, ISR_TX_READY)) < 0) {
  288. snd_printd(KERN_DEBUG "vx_send_msg: TX_READY error\n");
  289. return err;
  290. }
  291. /* End of transfer */
  292. err = vx_transfer_end(chip, IRQ_MESS_READ_END);
  293. if (err < 0)
  294. return err;
  295. }
  296. return vx_read_status(chip, rmh);
  297. }
  298. /*
  299. * vx_send_msg - send a DSP message with mutex
  300. * @rmh: the rmh record to send and receive
  301. *
  302. * returns 0 if successful, or a negative error code.
  303. * see vx_send_msg_nolock().
  304. */
  305. int vx_send_msg(struct vx_core *chip, struct vx_rmh *rmh)
  306. {
  307. int err;
  308. mutex_lock(&chip->lock);
  309. err = vx_send_msg_nolock(chip, rmh);
  310. mutex_unlock(&chip->lock);
  311. return err;
  312. }
  313. /*
  314. * vx_send_rih_nolock - send an RIH to xilinx
  315. * @cmd: the command to send
  316. *
  317. * returns 0 if successful, or a negative error code.
  318. * the error code can be VX-specific, retrieved via vx_get_error().
  319. *
  320. * this function doesn't call mutex at all.
  321. *
  322. * unlike RMH, no command is sent to DSP.
  323. */
  324. int vx_send_rih_nolock(struct vx_core *chip, int cmd)
  325. {
  326. int err;
  327. if (chip->chip_status & VX_STAT_IS_STALE)
  328. return -EBUSY;
  329. #if 0
  330. printk(KERN_DEBUG "send_rih: cmd = 0x%x\n", cmd);
  331. #endif
  332. if ((err = vx_reset_chk(chip)) < 0)
  333. return err;
  334. /* send the IRQ */
  335. if ((err = vx_send_irq_dsp(chip, cmd)) < 0)
  336. return err;
  337. /* Wait CHK = 1 */
  338. if ((err = vx_wait_isr_bit(chip, ISR_CHK)) < 0)
  339. return err;
  340. /* If error, read RX */
  341. if (vx_inb(chip, ISR) & ISR_ERR) {
  342. if ((err = vx_wait_for_rx_full(chip)) < 0)
  343. return err;
  344. err = vx_inb(chip, RXH) << 16;
  345. err |= vx_inb(chip, RXM) << 8;
  346. err |= vx_inb(chip, RXL);
  347. return -(VX_ERR_MASK | err);
  348. }
  349. return 0;
  350. }
  351. /*
  352. * vx_send_rih - send an RIH with mutex
  353. * @cmd: the command to send
  354. *
  355. * see vx_send_rih_nolock().
  356. */
  357. int vx_send_rih(struct vx_core *chip, int cmd)
  358. {
  359. int err;
  360. mutex_lock(&chip->lock);
  361. err = vx_send_rih_nolock(chip, cmd);
  362. mutex_unlock(&chip->lock);
  363. return err;
  364. }
  365. #define END_OF_RESET_WAIT_TIME 500 /* us */
  366. /**
  367. * snd_vx_boot_xilinx - boot up the xilinx interface
  368. * @chip: VX core instance
  369. * @boot: the boot record to load
  370. */
  371. int snd_vx_load_boot_image(struct vx_core *chip, const struct firmware *boot)
  372. {
  373. unsigned int i;
  374. int no_fillup = vx_has_new_dsp(chip);
  375. /* check the length of boot image */
  376. if (boot->size <= 0)
  377. return -EINVAL;
  378. if (boot->size % 3)
  379. return -EINVAL;
  380. #if 0
  381. {
  382. /* more strict check */
  383. unsigned int c = ((u32)boot->data[0] << 16) | ((u32)boot->data[1] << 8) | boot->data[2];
  384. if (boot->size != (c + 2) * 3)
  385. return -EINVAL;
  386. }
  387. #endif
  388. /* reset dsp */
  389. vx_reset_dsp(chip);
  390. udelay(END_OF_RESET_WAIT_TIME); /* another wait? */
  391. /* download boot strap */
  392. for (i = 0; i < 0x600; i += 3) {
  393. if (i >= boot->size) {
  394. if (no_fillup)
  395. break;
  396. if (vx_wait_isr_bit(chip, ISR_TX_EMPTY) < 0) {
  397. snd_printk(KERN_ERR "dsp boot failed at %d\n", i);
  398. return -EIO;
  399. }
  400. vx_outb(chip, TXH, 0);
  401. vx_outb(chip, TXM, 0);
  402. vx_outb(chip, TXL, 0);
  403. } else {
  404. const unsigned char *image = boot->data + i;
  405. if (vx_wait_isr_bit(chip, ISR_TX_EMPTY) < 0) {
  406. snd_printk(KERN_ERR "dsp boot failed at %d\n", i);
  407. return -EIO;
  408. }
  409. vx_outb(chip, TXH, image[0]);
  410. vx_outb(chip, TXM, image[1]);
  411. vx_outb(chip, TXL, image[2]);
  412. }
  413. }
  414. return 0;
  415. }
  416. EXPORT_SYMBOL(snd_vx_load_boot_image);
  417. /*
  418. * vx_test_irq_src - query the source of interrupts
  419. *
  420. * called from irq handler only
  421. */
  422. static int vx_test_irq_src(struct vx_core *chip, unsigned int *ret)
  423. {
  424. int err;
  425. vx_init_rmh(&chip->irq_rmh, CMD_TEST_IT);
  426. mutex_lock(&chip->lock);
  427. err = vx_send_msg_nolock(chip, &chip->irq_rmh);
  428. if (err < 0)
  429. *ret = 0;
  430. else
  431. *ret = chip->irq_rmh.Stat[0];
  432. mutex_unlock(&chip->lock);
  433. return err;
  434. }
  435. /*
  436. * snd_vx_threaded_irq_handler - threaded irq handler
  437. */
  438. irqreturn_t snd_vx_threaded_irq_handler(int irq, void *dev)
  439. {
  440. struct vx_core *chip = dev;
  441. unsigned int events;
  442. if (chip->chip_status & VX_STAT_IS_STALE)
  443. return IRQ_HANDLED;
  444. if (vx_test_irq_src(chip, &events) < 0)
  445. return IRQ_HANDLED;
  446. #if 0
  447. if (events & 0x000800)
  448. printk(KERN_ERR "DSP Stream underrun ! IRQ events = 0x%x\n", events);
  449. #endif
  450. // printk(KERN_DEBUG "IRQ events = 0x%x\n", events);
  451. /* We must prevent any application using this DSP
  452. * and block any further request until the application
  453. * either unregisters or reloads the DSP
  454. */
  455. if (events & FATAL_DSP_ERROR) {
  456. snd_printk(KERN_ERR "vx_core: fatal DSP error!!\n");
  457. return IRQ_HANDLED;
  458. }
  459. /* The start on time code conditions are filled (ie the time code
  460. * received by the board is equal to one of those given to it).
  461. */
  462. if (events & TIME_CODE_EVENT_PENDING)
  463. ; /* so far, nothing to do yet */
  464. /* The frequency has changed on the board (UER mode). */
  465. if (events & FREQUENCY_CHANGE_EVENT_PENDING)
  466. vx_change_frequency(chip);
  467. /* update the pcm streams */
  468. vx_pcm_update_intr(chip, events);
  469. return IRQ_HANDLED;
  470. }
  471. EXPORT_SYMBOL(snd_vx_threaded_irq_handler);
  472. /**
  473. * snd_vx_irq_handler - interrupt handler
  474. * @irq: irq number
  475. * @dev: VX core instance
  476. */
  477. irqreturn_t snd_vx_irq_handler(int irq, void *dev)
  478. {
  479. struct vx_core *chip = dev;
  480. if (! (chip->chip_status & VX_STAT_CHIP_INIT) ||
  481. (chip->chip_status & VX_STAT_IS_STALE))
  482. return IRQ_NONE;
  483. if (! vx_test_and_ack(chip))
  484. return IRQ_WAKE_THREAD;
  485. return IRQ_NONE;
  486. }
  487. EXPORT_SYMBOL(snd_vx_irq_handler);
  488. /*
  489. */
  490. static void vx_reset_board(struct vx_core *chip, int cold_reset)
  491. {
  492. if (snd_BUG_ON(!chip->ops->reset_board))
  493. return;
  494. /* current source, later sync'ed with target */
  495. chip->audio_source = VX_AUDIO_SRC_LINE;
  496. if (cold_reset) {
  497. chip->audio_source_target = chip->audio_source;
  498. chip->clock_source = INTERNAL_QUARTZ;
  499. chip->clock_mode = VX_CLOCK_MODE_AUTO;
  500. chip->freq = 48000;
  501. chip->uer_detected = VX_UER_MODE_NOT_PRESENT;
  502. chip->uer_bits = SNDRV_PCM_DEFAULT_CON_SPDIF;
  503. }
  504. chip->ops->reset_board(chip, cold_reset);
  505. vx_reset_codec(chip, cold_reset);
  506. vx_set_internal_clock(chip, chip->freq);
  507. /* Reset the DSP */
  508. vx_reset_dsp(chip);
  509. if (vx_is_pcmcia(chip)) {
  510. /* Acknowledge any pending IRQ and reset the MEMIRQ flag. */
  511. vx_test_and_ack(chip);
  512. vx_validate_irq(chip, 1);
  513. }
  514. /* init CBits */
  515. vx_set_iec958_status(chip, chip->uer_bits);
  516. }
  517. /*
  518. * proc interface
  519. */
  520. static void vx_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  521. {
  522. struct vx_core *chip = entry->private_data;
  523. static char *audio_src_vxp[] = { "Line", "Mic", "Digital" };
  524. static char *audio_src_vx2[] = { "Analog", "Analog", "Digital" };
  525. static char *clock_mode[] = { "Auto", "Internal", "External" };
  526. static char *clock_src[] = { "Internal", "External" };
  527. static char *uer_type[] = { "Consumer", "Professional", "Not Present" };
  528. snd_iprintf(buffer, "%s\n", chip->card->longname);
  529. snd_iprintf(buffer, "Xilinx Firmware: %s\n",
  530. chip->chip_status & VX_STAT_XILINX_LOADED ? "Loaded" : "No");
  531. snd_iprintf(buffer, "Device Initialized: %s\n",
  532. chip->chip_status & VX_STAT_DEVICE_INIT ? "Yes" : "No");
  533. snd_iprintf(buffer, "DSP audio info:");
  534. if (chip->audio_info & VX_AUDIO_INFO_REAL_TIME)
  535. snd_iprintf(buffer, " realtime");
  536. if (chip->audio_info & VX_AUDIO_INFO_OFFLINE)
  537. snd_iprintf(buffer, " offline");
  538. if (chip->audio_info & VX_AUDIO_INFO_MPEG1)
  539. snd_iprintf(buffer, " mpeg1");
  540. if (chip->audio_info & VX_AUDIO_INFO_MPEG2)
  541. snd_iprintf(buffer, " mpeg2");
  542. if (chip->audio_info & VX_AUDIO_INFO_LINEAR_8)
  543. snd_iprintf(buffer, " linear8");
  544. if (chip->audio_info & VX_AUDIO_INFO_LINEAR_16)
  545. snd_iprintf(buffer, " linear16");
  546. if (chip->audio_info & VX_AUDIO_INFO_LINEAR_24)
  547. snd_iprintf(buffer, " linear24");
  548. snd_iprintf(buffer, "\n");
  549. snd_iprintf(buffer, "Input Source: %s\n", vx_is_pcmcia(chip) ?
  550. audio_src_vxp[chip->audio_source] :
  551. audio_src_vx2[chip->audio_source]);
  552. snd_iprintf(buffer, "Clock Mode: %s\n", clock_mode[chip->clock_mode]);
  553. snd_iprintf(buffer, "Clock Source: %s\n", clock_src[chip->clock_source]);
  554. snd_iprintf(buffer, "Frequency: %d\n", chip->freq);
  555. snd_iprintf(buffer, "Detected Frequency: %d\n", chip->freq_detected);
  556. snd_iprintf(buffer, "Detected UER type: %s\n", uer_type[chip->uer_detected]);
  557. snd_iprintf(buffer, "Min/Max/Cur IBL: %d/%d/%d (granularity=%d)\n",
  558. chip->ibl.min_size, chip->ibl.max_size, chip->ibl.size,
  559. chip->ibl.granularity);
  560. }
  561. static void vx_proc_init(struct vx_core *chip)
  562. {
  563. struct snd_info_entry *entry;
  564. if (! snd_card_proc_new(chip->card, "vx-status", &entry))
  565. snd_info_set_text_ops(entry, chip, vx_proc_read);
  566. }
  567. /**
  568. * snd_vx_dsp_boot - load the DSP boot
  569. * @chip: VX core instance
  570. * @boot: firmware data
  571. */
  572. int snd_vx_dsp_boot(struct vx_core *chip, const struct firmware *boot)
  573. {
  574. int err;
  575. int cold_reset = !(chip->chip_status & VX_STAT_DEVICE_INIT);
  576. vx_reset_board(chip, cold_reset);
  577. vx_validate_irq(chip, 0);
  578. if ((err = snd_vx_load_boot_image(chip, boot)) < 0)
  579. return err;
  580. msleep(10);
  581. return 0;
  582. }
  583. EXPORT_SYMBOL(snd_vx_dsp_boot);
  584. /**
  585. * snd_vx_dsp_load - load the DSP image
  586. * @chip: VX core instance
  587. * @dsp: firmware data
  588. */
  589. int snd_vx_dsp_load(struct vx_core *chip, const struct firmware *dsp)
  590. {
  591. unsigned int i;
  592. int err;
  593. unsigned int csum = 0;
  594. const unsigned char *image, *cptr;
  595. if (dsp->size % 3)
  596. return -EINVAL;
  597. vx_toggle_dac_mute(chip, 1);
  598. /* Transfert data buffer from PC to DSP */
  599. for (i = 0; i < dsp->size; i += 3) {
  600. image = dsp->data + i;
  601. /* Wait DSP ready for a new read */
  602. if ((err = vx_wait_isr_bit(chip, ISR_TX_EMPTY)) < 0) {
  603. printk(KERN_ERR
  604. "dsp loading error at position %d\n", i);
  605. return err;
  606. }
  607. cptr = image;
  608. csum ^= *cptr;
  609. csum = (csum >> 24) | (csum << 8);
  610. vx_outb(chip, TXH, *cptr++);
  611. csum ^= *cptr;
  612. csum = (csum >> 24) | (csum << 8);
  613. vx_outb(chip, TXM, *cptr++);
  614. csum ^= *cptr;
  615. csum = (csum >> 24) | (csum << 8);
  616. vx_outb(chip, TXL, *cptr++);
  617. }
  618. snd_printdd(KERN_DEBUG "checksum = 0x%08x\n", csum);
  619. msleep(200);
  620. if ((err = vx_wait_isr_bit(chip, ISR_CHK)) < 0)
  621. return err;
  622. vx_toggle_dac_mute(chip, 0);
  623. vx_test_and_ack(chip);
  624. vx_validate_irq(chip, 1);
  625. return 0;
  626. }
  627. EXPORT_SYMBOL(snd_vx_dsp_load);
  628. #ifdef CONFIG_PM
  629. /*
  630. * suspend
  631. */
  632. int snd_vx_suspend(struct vx_core *chip)
  633. {
  634. unsigned int i;
  635. snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
  636. chip->chip_status |= VX_STAT_IN_SUSPEND;
  637. for (i = 0; i < chip->hw->num_codecs; i++)
  638. snd_pcm_suspend_all(chip->pcm[i]);
  639. return 0;
  640. }
  641. EXPORT_SYMBOL(snd_vx_suspend);
  642. /*
  643. * resume
  644. */
  645. int snd_vx_resume(struct vx_core *chip)
  646. {
  647. int i, err;
  648. chip->chip_status &= ~VX_STAT_CHIP_INIT;
  649. for (i = 0; i < 4; i++) {
  650. if (! chip->firmware[i])
  651. continue;
  652. err = chip->ops->load_dsp(chip, i, chip->firmware[i]);
  653. if (err < 0) {
  654. snd_printk(KERN_ERR "vx: firmware resume error at DSP %d\n", i);
  655. return -EIO;
  656. }
  657. }
  658. chip->chip_status |= VX_STAT_CHIP_INIT;
  659. chip->chip_status &= ~VX_STAT_IN_SUSPEND;
  660. snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
  661. return 0;
  662. }
  663. EXPORT_SYMBOL(snd_vx_resume);
  664. #endif
  665. /**
  666. * snd_vx_create - constructor for struct vx_core
  667. * @card: card instance
  668. * @hw: hardware specific record
  669. * @ops: VX ops pointer
  670. * @extra_size: extra byte size to allocate appending to chip
  671. *
  672. * this function allocates the instance and prepare for the hardware
  673. * initialization.
  674. *
  675. * return the instance pointer if successful, NULL in error.
  676. */
  677. struct vx_core *snd_vx_create(struct snd_card *card, struct snd_vx_hardware *hw,
  678. struct snd_vx_ops *ops,
  679. int extra_size)
  680. {
  681. struct vx_core *chip;
  682. if (snd_BUG_ON(!card || !hw || !ops))
  683. return NULL;
  684. chip = kzalloc(sizeof(*chip) + extra_size, GFP_KERNEL);
  685. if (! chip) {
  686. snd_printk(KERN_ERR "vx_core: no memory\n");
  687. return NULL;
  688. }
  689. mutex_init(&chip->lock);
  690. chip->irq = -1;
  691. chip->hw = hw;
  692. chip->type = hw->type;
  693. chip->ops = ops;
  694. mutex_init(&chip->mixer_mutex);
  695. chip->card = card;
  696. card->private_data = chip;
  697. strcpy(card->driver, hw->name);
  698. sprintf(card->shortname, "Digigram %s", hw->name);
  699. vx_proc_init(chip);
  700. return chip;
  701. }
  702. EXPORT_SYMBOL(snd_vx_create);
  703. /*
  704. * module entries
  705. */
  706. static int __init alsa_vx_core_init(void)
  707. {
  708. return 0;
  709. }
  710. static void __exit alsa_vx_core_exit(void)
  711. {
  712. }
  713. module_init(alsa_vx_core_init)
  714. module_exit(alsa_vx_core_exit)