~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/drivers/vx/vx_core.c

Version: ~ [ linux-5.11-rc3 ] ~ [ linux-5.10.7 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.89 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.167 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.215 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.251 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.251 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp