vx_core.c 21 KB

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