vx_core.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Driver for Digigram VX soundcards
  4. *
  5. * Hardware core part
  6. *
  7. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  8. */
  9. #include <linux/delay.h>
  10. #include <linux/slab.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. #include <linux/firmware.h>
  15. #include <linux/module.h>
  16. #include <linux/io.h>
  17. #include <sound/core.h>
  18. #include <sound/pcm.h>
  19. #include <sound/asoundef.h>
  20. #include <sound/info.h>
  21. #include <sound/vx_core.h>
  22. #include "vx_cmd.h"
  23. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  24. MODULE_DESCRIPTION("Common routines for Digigram VX drivers");
  25. MODULE_LICENSE("GPL");
  26. /*
  27. * vx_check_reg_bit - wait for the specified bit is set/reset on a register
  28. * @reg: register to check
  29. * @mask: bit mask
  30. * @bit: resultant bit to be checked
  31. * @time: time-out of loop in msec
  32. *
  33. * returns zero if a bit matches, or a negative error code.
  34. */
  35. int snd_vx_check_reg_bit(struct vx_core *chip, int reg, int mask, int bit, int time)
  36. {
  37. unsigned long end_time = jiffies + (time * HZ + 999) / 1000;
  38. static const char * const reg_names[VX_REG_MAX] = {
  39. "ICR", "CVR", "ISR", "IVR", "RXH", "RXM", "RXL",
  40. "DMA", "CDSP", "RFREQ", "RUER/V2", "DATA", "MEMIRQ",
  41. "ACQ", "BIT0", "BIT1", "MIC0", "MIC1", "MIC2",
  42. "MIC3", "INTCSR", "CNTRL", "GPIOC",
  43. "LOFREQ", "HIFREQ", "CSUER", "RUER"
  44. };
  45. do {
  46. if ((snd_vx_inb(chip, reg) & mask) == bit)
  47. return 0;
  48. //msleep(10);
  49. } while (time_after_eq(end_time, jiffies));
  50. dev_dbg(chip->card->dev,
  51. "vx_check_reg_bit: timeout, reg=%s, mask=0x%x, val=0x%x\n",
  52. reg_names[reg], mask, snd_vx_inb(chip, reg));
  53. return -EIO;
  54. }
  55. EXPORT_SYMBOL(snd_vx_check_reg_bit);
  56. /*
  57. * vx_send_irq_dsp - set command irq bit
  58. * @num: the requested IRQ type, IRQ_XXX
  59. *
  60. * this triggers the specified IRQ request
  61. * returns 0 if successful, or a negative error code.
  62. *
  63. */
  64. static int vx_send_irq_dsp(struct vx_core *chip, int num)
  65. {
  66. int nirq;
  67. /* wait for Hc = 0 */
  68. if (snd_vx_check_reg_bit(chip, VX_CVR, CVR_HC, 0, 200) < 0)
  69. return -EIO;
  70. nirq = num;
  71. if (vx_has_new_dsp(chip))
  72. nirq += VXP_IRQ_OFFSET;
  73. vx_outb(chip, CVR, (nirq >> 1) | CVR_HC);
  74. return 0;
  75. }
  76. /*
  77. * vx_reset_chk - reset CHK bit on ISR
  78. *
  79. * returns 0 if successful, or a negative error code.
  80. */
  81. static int vx_reset_chk(struct vx_core *chip)
  82. {
  83. /* Reset irq CHK */
  84. if (vx_send_irq_dsp(chip, IRQ_RESET_CHK) < 0)
  85. return -EIO;
  86. /* Wait until CHK = 0 */
  87. if (vx_check_isr(chip, ISR_CHK, 0, 200) < 0)
  88. return -EIO;
  89. return 0;
  90. }
  91. /*
  92. * vx_transfer_end - terminate message transfer
  93. * @cmd: IRQ message to send (IRQ_MESS_XXX_END)
  94. *
  95. * returns 0 if successful, or a negative error code.
  96. * the error code can be VX-specific, retrieved via vx_get_error().
  97. * NB: call with mutex held!
  98. */
  99. static int vx_transfer_end(struct vx_core *chip, int cmd)
  100. {
  101. int err;
  102. err = vx_reset_chk(chip);
  103. if (err < 0)
  104. return err;
  105. /* irq MESS_READ/WRITE_END */
  106. err = vx_send_irq_dsp(chip, cmd);
  107. if (err < 0)
  108. return err;
  109. /* Wait CHK = 1 */
  110. err = vx_wait_isr_bit(chip, ISR_CHK);
  111. if (err < 0)
  112. return err;
  113. /* If error, Read RX */
  114. err = vx_inb(chip, ISR);
  115. if (err & ISR_ERR) {
  116. err = vx_wait_for_rx_full(chip);
  117. if (err < 0) {
  118. dev_dbg(chip->card->dev,
  119. "transfer_end: error in rx_full\n");
  120. return err;
  121. }
  122. err = vx_inb(chip, RXH) << 16;
  123. err |= vx_inb(chip, RXM) << 8;
  124. err |= vx_inb(chip, RXL);
  125. dev_dbg(chip->card->dev, "transfer_end: error = 0x%x\n", err);
  126. return -(VX_ERR_MASK | err);
  127. }
  128. return 0;
  129. }
  130. /*
  131. * vx_read_status - return the status rmh
  132. * @rmh: rmh record to store the status
  133. *
  134. * returns 0 if successful, or a negative error code.
  135. * the error code can be VX-specific, retrieved via vx_get_error().
  136. * NB: call with mutex held!
  137. */
  138. static int vx_read_status(struct vx_core *chip, struct vx_rmh *rmh)
  139. {
  140. int i, err, val, size;
  141. /* no read necessary? */
  142. if (rmh->DspStat == RMH_SSIZE_FIXED && rmh->LgStat == 0)
  143. return 0;
  144. /* Wait for RX full (with timeout protection)
  145. * The first word of status is in RX
  146. */
  147. err = vx_wait_for_rx_full(chip);
  148. if (err < 0)
  149. return err;
  150. /* Read RX */
  151. val = vx_inb(chip, RXH) << 16;
  152. val |= vx_inb(chip, RXM) << 8;
  153. val |= vx_inb(chip, RXL);
  154. /* If status given by DSP, let's decode its size */
  155. switch (rmh->DspStat) {
  156. case RMH_SSIZE_ARG:
  157. size = val & 0xff;
  158. rmh->Stat[0] = val & 0xffff00;
  159. rmh->LgStat = size + 1;
  160. break;
  161. case RMH_SSIZE_MASK:
  162. /* Let's count the arg numbers from a mask */
  163. rmh->Stat[0] = val;
  164. size = 0;
  165. while (val) {
  166. if (val & 0x01)
  167. size++;
  168. val >>= 1;
  169. }
  170. rmh->LgStat = size + 1;
  171. break;
  172. default:
  173. /* else retrieve the status length given by the driver */
  174. size = rmh->LgStat;
  175. rmh->Stat[0] = val; /* Val is the status 1st word */
  176. size--; /* hence adjust remaining length */
  177. break;
  178. }
  179. if (size < 1)
  180. return 0;
  181. if (snd_BUG_ON(size >= SIZE_MAX_STATUS))
  182. return -EINVAL;
  183. for (i = 1; i <= size; i++) {
  184. /* trigger an irq MESS_WRITE_NEXT */
  185. err = vx_send_irq_dsp(chip, IRQ_MESS_WRITE_NEXT);
  186. if (err < 0)
  187. return err;
  188. /* Wait for RX full (with timeout protection) */
  189. err = vx_wait_for_rx_full(chip);
  190. if (err < 0)
  191. return err;
  192. rmh->Stat[i] = vx_inb(chip, RXH) << 16;
  193. rmh->Stat[i] |= vx_inb(chip, RXM) << 8;
  194. rmh->Stat[i] |= vx_inb(chip, RXL);
  195. }
  196. return vx_transfer_end(chip, IRQ_MESS_WRITE_END);
  197. }
  198. #define MASK_MORE_THAN_1_WORD_COMMAND 0x00008000
  199. #define MASK_1_WORD_COMMAND 0x00ff7fff
  200. /*
  201. * vx_send_msg_nolock - send a DSP message and read back the status
  202. * @rmh: the rmh record to send and receive
  203. *
  204. * returns 0 if successful, or a negative error code.
  205. * the error code can be VX-specific, retrieved via vx_get_error().
  206. *
  207. * this function doesn't call mutex lock at all.
  208. */
  209. int vx_send_msg_nolock(struct vx_core *chip, struct vx_rmh *rmh)
  210. {
  211. int i, err;
  212. if (chip->chip_status & VX_STAT_IS_STALE)
  213. return -EBUSY;
  214. err = vx_reset_chk(chip);
  215. if (err < 0) {
  216. dev_dbg(chip->card->dev, "vx_send_msg: vx_reset_chk error\n");
  217. return err;
  218. }
  219. /* Check bit M is set according to length of the command */
  220. if (rmh->LgCmd > 1)
  221. rmh->Cmd[0] |= MASK_MORE_THAN_1_WORD_COMMAND;
  222. else
  223. rmh->Cmd[0] &= MASK_1_WORD_COMMAND;
  224. /* Wait for TX empty */
  225. err = vx_wait_isr_bit(chip, ISR_TX_EMPTY);
  226. if (err < 0) {
  227. dev_dbg(chip->card->dev, "vx_send_msg: wait tx empty error\n");
  228. return err;
  229. }
  230. /* Write Cmd[0] */
  231. vx_outb(chip, TXH, (rmh->Cmd[0] >> 16) & 0xff);
  232. vx_outb(chip, TXM, (rmh->Cmd[0] >> 8) & 0xff);
  233. vx_outb(chip, TXL, rmh->Cmd[0] & 0xff);
  234. /* Trigger irq MESSAGE */
  235. err = vx_send_irq_dsp(chip, IRQ_MESSAGE);
  236. if (err < 0) {
  237. dev_dbg(chip->card->dev,
  238. "vx_send_msg: send IRQ_MESSAGE error\n");
  239. return err;
  240. }
  241. /* Wait for CHK = 1 */
  242. err = vx_wait_isr_bit(chip, ISR_CHK);
  243. if (err < 0)
  244. return err;
  245. /* If error, get error value from RX */
  246. if (vx_inb(chip, ISR) & ISR_ERR) {
  247. err = vx_wait_for_rx_full(chip);
  248. if (err < 0) {
  249. dev_dbg(chip->card->dev,
  250. "vx_send_msg: rx_full read error\n");
  251. return err;
  252. }
  253. err = vx_inb(chip, RXH) << 16;
  254. err |= vx_inb(chip, RXM) << 8;
  255. err |= vx_inb(chip, RXL);
  256. dev_dbg(chip->card->dev,
  257. "msg got error = 0x%x at cmd[0]\n", err);
  258. err = -(VX_ERR_MASK | err);
  259. return err;
  260. }
  261. /* Send the other words */
  262. if (rmh->LgCmd > 1) {
  263. for (i = 1; i < rmh->LgCmd; i++) {
  264. /* Wait for TX ready */
  265. err = vx_wait_isr_bit(chip, ISR_TX_READY);
  266. if (err < 0) {
  267. dev_dbg(chip->card->dev,
  268. "vx_send_msg: tx_ready error\n");
  269. return err;
  270. }
  271. /* Write Cmd[i] */
  272. vx_outb(chip, TXH, (rmh->Cmd[i] >> 16) & 0xff);
  273. vx_outb(chip, TXM, (rmh->Cmd[i] >> 8) & 0xff);
  274. vx_outb(chip, TXL, rmh->Cmd[i] & 0xff);
  275. /* Trigger irq MESS_READ_NEXT */
  276. err = vx_send_irq_dsp(chip, IRQ_MESS_READ_NEXT);
  277. if (err < 0) {
  278. dev_dbg(chip->card->dev,
  279. "vx_send_msg: IRQ_READ_NEXT error\n");
  280. return err;
  281. }
  282. }
  283. /* Wait for TX empty */
  284. err = vx_wait_isr_bit(chip, ISR_TX_READY);
  285. if (err < 0) {
  286. dev_dbg(chip->card->dev,
  287. "vx_send_msg: TX_READY error\n");
  288. return err;
  289. }
  290. /* End of transfer */
  291. err = vx_transfer_end(chip, IRQ_MESS_READ_END);
  292. if (err < 0)
  293. return err;
  294. }
  295. return vx_read_status(chip, rmh);
  296. }
  297. /*
  298. * vx_send_msg - send a DSP message with mutex
  299. * @rmh: the rmh record to send and receive
  300. *
  301. * returns 0 if successful, or a negative error code.
  302. * see vx_send_msg_nolock().
  303. */
  304. int vx_send_msg(struct vx_core *chip, struct vx_rmh *rmh)
  305. {
  306. int err;
  307. mutex_lock(&chip->lock);
  308. err = vx_send_msg_nolock(chip, rmh);
  309. mutex_unlock(&chip->lock);
  310. return err;
  311. }
  312. /*
  313. * vx_send_rih_nolock - send an RIH to xilinx
  314. * @cmd: the command to send
  315. *
  316. * returns 0 if successful, or a negative error code.
  317. * the error code can be VX-specific, retrieved via vx_get_error().
  318. *
  319. * this function doesn't call mutex at all.
  320. *
  321. * unlike RMH, no command is sent to DSP.
  322. */
  323. int vx_send_rih_nolock(struct vx_core *chip, int cmd)
  324. {
  325. int err;
  326. if (chip->chip_status & VX_STAT_IS_STALE)
  327. return -EBUSY;
  328. err = vx_reset_chk(chip);
  329. if (err < 0)
  330. return err;
  331. /* send the IRQ */
  332. err = vx_send_irq_dsp(chip, cmd);
  333. if (err < 0)
  334. return err;
  335. /* Wait CHK = 1 */
  336. err = vx_wait_isr_bit(chip, ISR_CHK);
  337. if (err < 0)
  338. return err;
  339. /* If error, read RX */
  340. if (vx_inb(chip, ISR) & ISR_ERR) {
  341. err = vx_wait_for_rx_full(chip);
  342. if (err < 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_load_boot_image - 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. dev_err(chip->card->dev, "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. dev_err(chip->card->dev, "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. /* We must prevent any application using this DSP
  447. * and block any further request until the application
  448. * either unregisters or reloads the DSP
  449. */
  450. if (events & FATAL_DSP_ERROR) {
  451. dev_err(chip->card->dev, "vx_core: fatal DSP error!!\n");
  452. return IRQ_HANDLED;
  453. }
  454. /* The start on time code conditions are filled (ie the time code
  455. * received by the board is equal to one of those given to it).
  456. */
  457. if (events & TIME_CODE_EVENT_PENDING) {
  458. ; /* so far, nothing to do yet */
  459. }
  460. /* The frequency has changed on the board (UER mode). */
  461. if (events & FREQUENCY_CHANGE_EVENT_PENDING)
  462. vx_change_frequency(chip);
  463. /* update the pcm streams */
  464. vx_pcm_update_intr(chip, events);
  465. return IRQ_HANDLED;
  466. }
  467. EXPORT_SYMBOL(snd_vx_threaded_irq_handler);
  468. /**
  469. * snd_vx_irq_handler - interrupt handler
  470. * @irq: irq number
  471. * @dev: VX core instance
  472. */
  473. irqreturn_t snd_vx_irq_handler(int irq, void *dev)
  474. {
  475. struct vx_core *chip = dev;
  476. if (! (chip->chip_status & VX_STAT_CHIP_INIT) ||
  477. (chip->chip_status & VX_STAT_IS_STALE))
  478. return IRQ_NONE;
  479. if (! vx_test_and_ack(chip))
  480. return IRQ_WAKE_THREAD;
  481. return IRQ_NONE;
  482. }
  483. EXPORT_SYMBOL(snd_vx_irq_handler);
  484. /*
  485. */
  486. static void vx_reset_board(struct vx_core *chip, int cold_reset)
  487. {
  488. if (snd_BUG_ON(!chip->ops->reset_board))
  489. return;
  490. /* current source, later sync'ed with target */
  491. chip->audio_source = VX_AUDIO_SRC_LINE;
  492. if (cold_reset) {
  493. chip->audio_source_target = chip->audio_source;
  494. chip->clock_source = INTERNAL_QUARTZ;
  495. chip->clock_mode = VX_CLOCK_MODE_AUTO;
  496. chip->freq = 48000;
  497. chip->uer_detected = VX_UER_MODE_NOT_PRESENT;
  498. chip->uer_bits = SNDRV_PCM_DEFAULT_CON_SPDIF;
  499. }
  500. chip->ops->reset_board(chip, cold_reset);
  501. vx_reset_codec(chip, cold_reset);
  502. vx_set_internal_clock(chip, chip->freq);
  503. /* Reset the DSP */
  504. vx_reset_dsp(chip);
  505. if (vx_is_pcmcia(chip)) {
  506. /* Acknowledge any pending IRQ and reset the MEMIRQ flag. */
  507. vx_test_and_ack(chip);
  508. vx_validate_irq(chip, 1);
  509. }
  510. /* init CBits */
  511. vx_set_iec958_status(chip, chip->uer_bits);
  512. }
  513. /*
  514. * proc interface
  515. */
  516. static void vx_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  517. {
  518. struct vx_core *chip = entry->private_data;
  519. static const char * const audio_src_vxp[] = { "Line", "Mic", "Digital" };
  520. static const char * const audio_src_vx2[] = { "Analog", "Analog", "Digital" };
  521. static const char * const clock_mode[] = { "Auto", "Internal", "External" };
  522. static const char * const clock_src[] = { "Internal", "External" };
  523. static const char * const uer_type[] = { "Consumer", "Professional", "Not Present" };
  524. snd_iprintf(buffer, "%s\n", chip->card->longname);
  525. snd_iprintf(buffer, "Xilinx Firmware: %s\n",
  526. (chip->chip_status & VX_STAT_XILINX_LOADED) ? "Loaded" : "No");
  527. snd_iprintf(buffer, "Device Initialized: %s\n",
  528. (chip->chip_status & VX_STAT_DEVICE_INIT) ? "Yes" : "No");
  529. snd_iprintf(buffer, "DSP audio info:");
  530. if (chip->audio_info & VX_AUDIO_INFO_REAL_TIME)
  531. snd_iprintf(buffer, " realtime");
  532. if (chip->audio_info & VX_AUDIO_INFO_OFFLINE)
  533. snd_iprintf(buffer, " offline");
  534. if (chip->audio_info & VX_AUDIO_INFO_MPEG1)
  535. snd_iprintf(buffer, " mpeg1");
  536. if (chip->audio_info & VX_AUDIO_INFO_MPEG2)
  537. snd_iprintf(buffer, " mpeg2");
  538. if (chip->audio_info & VX_AUDIO_INFO_LINEAR_8)
  539. snd_iprintf(buffer, " linear8");
  540. if (chip->audio_info & VX_AUDIO_INFO_LINEAR_16)
  541. snd_iprintf(buffer, " linear16");
  542. if (chip->audio_info & VX_AUDIO_INFO_LINEAR_24)
  543. snd_iprintf(buffer, " linear24");
  544. snd_iprintf(buffer, "\n");
  545. snd_iprintf(buffer, "Input Source: %s\n", vx_is_pcmcia(chip) ?
  546. audio_src_vxp[chip->audio_source] :
  547. audio_src_vx2[chip->audio_source]);
  548. snd_iprintf(buffer, "Clock Mode: %s\n", clock_mode[chip->clock_mode]);
  549. snd_iprintf(buffer, "Clock Source: %s\n", clock_src[chip->clock_source]);
  550. snd_iprintf(buffer, "Frequency: %d\n", chip->freq);
  551. snd_iprintf(buffer, "Detected Frequency: %d\n", chip->freq_detected);
  552. snd_iprintf(buffer, "Detected UER type: %s\n", uer_type[chip->uer_detected]);
  553. snd_iprintf(buffer, "Min/Max/Cur IBL: %d/%d/%d (granularity=%d)\n",
  554. chip->ibl.min_size, chip->ibl.max_size, chip->ibl.size,
  555. chip->ibl.granularity);
  556. }
  557. static void vx_proc_init(struct vx_core *chip)
  558. {
  559. snd_card_ro_proc_new(chip->card, "vx-status", chip, vx_proc_read);
  560. }
  561. /**
  562. * snd_vx_dsp_boot - load the DSP boot
  563. * @chip: VX core instance
  564. * @boot: firmware data
  565. */
  566. int snd_vx_dsp_boot(struct vx_core *chip, const struct firmware *boot)
  567. {
  568. int err;
  569. int cold_reset = !(chip->chip_status & VX_STAT_DEVICE_INIT);
  570. vx_reset_board(chip, cold_reset);
  571. vx_validate_irq(chip, 0);
  572. err = snd_vx_load_boot_image(chip, boot);
  573. if (err < 0)
  574. return err;
  575. msleep(10);
  576. return 0;
  577. }
  578. EXPORT_SYMBOL(snd_vx_dsp_boot);
  579. /**
  580. * snd_vx_dsp_load - load the DSP image
  581. * @chip: VX core instance
  582. * @dsp: firmware data
  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. err = vx_wait_isr_bit(chip, ISR_TX_EMPTY);
  598. if (err < 0) {
  599. dev_err(chip->card->dev,
  600. "dsp loading error at position %d\n", i);
  601. return err;
  602. }
  603. cptr = image;
  604. csum ^= *cptr;
  605. csum = (csum >> 24) | (csum << 8);
  606. vx_outb(chip, TXH, *cptr++);
  607. csum ^= *cptr;
  608. csum = (csum >> 24) | (csum << 8);
  609. vx_outb(chip, TXM, *cptr++);
  610. csum ^= *cptr;
  611. csum = (csum >> 24) | (csum << 8);
  612. vx_outb(chip, TXL, *cptr++);
  613. }
  614. msleep(200);
  615. err = vx_wait_isr_bit(chip, ISR_CHK);
  616. if (err < 0)
  617. return err;
  618. vx_toggle_dac_mute(chip, 0);
  619. vx_test_and_ack(chip);
  620. vx_validate_irq(chip, 1);
  621. return 0;
  622. }
  623. EXPORT_SYMBOL(snd_vx_dsp_load);
  624. #ifdef CONFIG_PM
  625. /*
  626. * suspend
  627. */
  628. int snd_vx_suspend(struct vx_core *chip)
  629. {
  630. snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
  631. chip->chip_status |= VX_STAT_IN_SUSPEND;
  632. return 0;
  633. }
  634. EXPORT_SYMBOL(snd_vx_suspend);
  635. /*
  636. * resume
  637. */
  638. int snd_vx_resume(struct vx_core *chip)
  639. {
  640. int i, err;
  641. chip->chip_status &= ~VX_STAT_CHIP_INIT;
  642. for (i = 0; i < 4; i++) {
  643. if (! chip->firmware[i])
  644. continue;
  645. err = chip->ops->load_dsp(chip, i, chip->firmware[i]);
  646. if (err < 0) {
  647. dev_err(chip->card->dev,
  648. "vx: firmware resume error at DSP %d\n", i);
  649. return -EIO;
  650. }
  651. }
  652. chip->chip_status |= VX_STAT_CHIP_INIT;
  653. chip->chip_status &= ~VX_STAT_IN_SUSPEND;
  654. snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
  655. return 0;
  656. }
  657. EXPORT_SYMBOL(snd_vx_resume);
  658. #endif
  659. static void snd_vx_release(struct device *dev, void *data)
  660. {
  661. snd_vx_free_firmware(data);
  662. }
  663. /**
  664. * snd_vx_create - constructor for struct vx_core
  665. * @card: card instance
  666. * @hw: hardware specific record
  667. * @ops: VX ops pointer
  668. * @extra_size: extra byte size to allocate appending to chip
  669. *
  670. * this function allocates the instance and prepare for the hardware
  671. * initialization.
  672. *
  673. * The object is managed via devres, and will be automatically released.
  674. *
  675. * return the instance pointer if successful, NULL in error.
  676. */
  677. struct vx_core *snd_vx_create(struct snd_card *card,
  678. const struct snd_vx_hardware *hw,
  679. const struct snd_vx_ops *ops,
  680. int extra_size)
  681. {
  682. struct vx_core *chip;
  683. if (snd_BUG_ON(!card || !hw || !ops))
  684. return NULL;
  685. chip = devres_alloc(snd_vx_release, sizeof(*chip) + extra_size,
  686. GFP_KERNEL);
  687. if (!chip)
  688. return NULL;
  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);