vx_core.c 20 KB

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