Lines Matching refs:s
432 static void wrcodec(struct es1370_state *s, unsigned char idx, unsigned char data) in wrcodec() argument
438 if (!(inl(s->io+ES1370_REG_STATUS) & STAT_CSTAT)) { in wrcodec()
439 outw((((unsigned short)idx)<<8)|data, s->io+ES1370_REG_CODEC); in wrcodec()
449 static inline void stop_adc(struct es1370_state *s) in stop_adc() argument
453 spin_lock_irqsave(&s->lock, flags); in stop_adc()
454 s->ctrl &= ~CTRL_ADC_EN; in stop_adc()
455 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in stop_adc()
456 spin_unlock_irqrestore(&s->lock, flags); in stop_adc()
459 static inline void stop_dac1(struct es1370_state *s) in stop_dac1() argument
463 spin_lock_irqsave(&s->lock, flags); in stop_dac1()
464 s->ctrl &= ~CTRL_DAC1_EN; in stop_dac1()
465 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in stop_dac1()
466 spin_unlock_irqrestore(&s->lock, flags); in stop_dac1()
469 static inline void stop_dac2(struct es1370_state *s) in stop_dac2() argument
473 spin_lock_irqsave(&s->lock, flags); in stop_dac2()
474 s->ctrl &= ~CTRL_DAC2_EN; in stop_dac2()
475 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in stop_dac2()
476 spin_unlock_irqrestore(&s->lock, flags); in stop_dac2()
479 static void start_dac1(struct es1370_state *s) in start_dac1() argument
484 spin_lock_irqsave(&s->lock, flags); in start_dac1()
485 if (!(s->ctrl & CTRL_DAC1_EN) && (s->dma_dac1.mapped || s->dma_dac1.count > 0) in start_dac1()
486 && s->dma_dac1.ready) { in start_dac1()
487 s->ctrl |= CTRL_DAC1_EN; in start_dac1()
488 s->sctrl = (s->sctrl & ~(SCTRL_P1LOOPSEL | SCTRL_P1PAUSE | SCTRL_P1SCTRLD)) | SCTRL_P1INTEN; in start_dac1()
489 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in start_dac1()
490 fragremain = ((- s->dma_dac1.hwptr) & (s->dma_dac1.fragsize-1)); in start_dac1()
491 fshift = sample_shift[(s->sctrl & SCTRL_P1FMT) >> SCTRL_SH_P1FMT]; in start_dac1()
493 fragremain = s->dma_dac1.fragsize; in start_dac1()
494 outl((fragremain >> fshift) - 1, s->io+ES1370_REG_DAC1_SCOUNT); in start_dac1()
495 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in start_dac1()
496 outl((s->dma_dac1.fragsize >> fshift) - 1, s->io+ES1370_REG_DAC1_SCOUNT); in start_dac1()
498 spin_unlock_irqrestore(&s->lock, flags); in start_dac1()
501 static void start_dac2(struct es1370_state *s) in start_dac2() argument
506 spin_lock_irqsave(&s->lock, flags); in start_dac2()
507 if (!(s->ctrl & CTRL_DAC2_EN) && (s->dma_dac2.mapped || s->dma_dac2.count > 0) in start_dac2()
508 && s->dma_dac2.ready) { in start_dac2()
509 s->ctrl |= CTRL_DAC2_EN; in start_dac2()
510 s->sctrl = (s->sctrl & ~(SCTRL_P2LOOPSEL | SCTRL_P2PAUSE | SCTRL_P2DACSEN | in start_dac2()
512 (((s->sctrl & SCTRL_P2FMT) ? 2 : 1) << SCTRL_SH_P2ENDINC) | in start_dac2()
514 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in start_dac2()
515 fragremain = ((- s->dma_dac2.hwptr) & (s->dma_dac2.fragsize-1)); in start_dac2()
516 fshift = sample_shift[(s->sctrl & SCTRL_P2FMT) >> SCTRL_SH_P2FMT]; in start_dac2()
518 fragremain = s->dma_dac2.fragsize; in start_dac2()
519 outl((fragremain >> fshift) - 1, s->io+ES1370_REG_DAC2_SCOUNT); in start_dac2()
520 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in start_dac2()
521 outl((s->dma_dac2.fragsize >> fshift) - 1, s->io+ES1370_REG_DAC2_SCOUNT); in start_dac2()
523 spin_unlock_irqrestore(&s->lock, flags); in start_dac2()
526 static void start_adc(struct es1370_state *s) in start_adc() argument
531 spin_lock_irqsave(&s->lock, flags); in start_adc()
532 …if (!(s->ctrl & CTRL_ADC_EN) && (s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasi… in start_adc()
533 && s->dma_adc.ready) { in start_adc()
534 s->ctrl |= CTRL_ADC_EN; in start_adc()
535 s->sctrl = (s->sctrl & ~SCTRL_R1LOOPSEL) | SCTRL_R1INTEN; in start_adc()
536 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in start_adc()
537 fragremain = ((- s->dma_adc.hwptr) & (s->dma_adc.fragsize-1)); in start_adc()
538 fshift = sample_shift[(s->sctrl & SCTRL_R1FMT) >> SCTRL_SH_R1FMT]; in start_adc()
540 fragremain = s->dma_adc.fragsize; in start_adc()
541 outl((fragremain >> fshift) - 1, s->io+ES1370_REG_ADC_SCOUNT); in start_adc()
542 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in start_adc()
543 outl((s->dma_adc.fragsize >> fshift) - 1, s->io+ES1370_REG_ADC_SCOUNT); in start_adc()
545 spin_unlock_irqrestore(&s->lock, flags); in start_adc()
553 static inline void dealloc_dmabuf(struct es1370_state *s, struct dmabuf *db) in dealloc_dmabuf() argument
562 pci_free_consistent(s->dev, PAGE_SIZE << db->buforder, db->rawbuf, db->dmaaddr); in dealloc_dmabuf()
568 static int prog_dmabuf(struct es1370_state *s, struct dmabuf *db, unsigned rate, unsigned fmt, unsi… in prog_dmabuf() argument
579 if ((db->rawbuf = pci_alloc_consistent(s->dev, PAGE_SIZE << order, &db->dmaaddr))) in prog_dmabuf()
613 outl((reg >> 8) & 15, s->io+ES1370_REG_MEMPAGE); in prog_dmabuf()
614 outl(db->dmaaddr, s->io+(reg & 0xff)); in prog_dmabuf()
615 outl((db->dmasize >> 2)-1, s->io+((reg + 4) & 0xff)); in prog_dmabuf()
621 static inline int prog_dmabuf_adc(struct es1370_state *s) in prog_dmabuf_adc() argument
623 stop_adc(s); in prog_dmabuf_adc()
624 return prog_dmabuf(s, &s->dma_adc, DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV), in prog_dmabuf_adc()
625 (s->sctrl >> SCTRL_SH_R1FMT) & ES1370_FMT_MASK, ES1370_REG_ADC_FRAMEADR); in prog_dmabuf_adc()
628 static inline int prog_dmabuf_dac2(struct es1370_state *s) in prog_dmabuf_dac2() argument
630 stop_dac2(s); in prog_dmabuf_dac2()
631 return prog_dmabuf(s, &s->dma_dac2, DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV), in prog_dmabuf_dac2()
632 (s->sctrl >> SCTRL_SH_P2FMT) & ES1370_FMT_MASK, ES1370_REG_DAC2_FRAMEADR); in prog_dmabuf_dac2()
635 static inline int prog_dmabuf_dac1(struct es1370_state *s) in prog_dmabuf_dac1() argument
637 stop_dac1(s); in prog_dmabuf_dac1()
638 return prog_dmabuf(s, &s->dma_dac1, dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL], in prog_dmabuf_dac1()
639 (s->sctrl >> SCTRL_SH_P1FMT) & ES1370_FMT_MASK, ES1370_REG_DAC1_FRAMEADR); in prog_dmabuf_dac1()
642 static inline unsigned get_hwptr(struct es1370_state *s, struct dmabuf *db, unsigned reg) in get_hwptr() argument
646 outl((reg >> 8) & 15, s->io+ES1370_REG_MEMPAGE); in get_hwptr()
647 hwptr = (inl(s->io+(reg & 0xff)) >> 14) & 0x3fffc; in get_hwptr()
665 static void es1370_update_ptr(struct es1370_state *s) in es1370_update_ptr() argument
670 if (s->ctrl & CTRL_ADC_EN) { in es1370_update_ptr()
671 diff = get_hwptr(s, &s->dma_adc, ES1370_REG_ADC_FRAMECNT); in es1370_update_ptr()
672 s->dma_adc.total_bytes += diff; in es1370_update_ptr()
673 s->dma_adc.count += diff; in es1370_update_ptr()
674 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize) in es1370_update_ptr()
675 wake_up(&s->dma_adc.wait); in es1370_update_ptr()
676 if (!s->dma_adc.mapped) { in es1370_update_ptr()
677 if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) { in es1370_update_ptr()
678 s->ctrl &= ~CTRL_ADC_EN; in es1370_update_ptr()
679 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_update_ptr()
680 s->dma_adc.error++; in es1370_update_ptr()
685 if (s->ctrl & CTRL_DAC1_EN) { in es1370_update_ptr()
686 diff = get_hwptr(s, &s->dma_dac1, ES1370_REG_DAC1_FRAMECNT); in es1370_update_ptr()
687 s->dma_dac1.total_bytes += diff; in es1370_update_ptr()
688 if (s->dma_dac1.mapped) { in es1370_update_ptr()
689 s->dma_dac1.count += diff; in es1370_update_ptr()
690 if (s->dma_dac1.count >= (signed)s->dma_dac1.fragsize) in es1370_update_ptr()
691 wake_up(&s->dma_dac1.wait); in es1370_update_ptr()
693 s->dma_dac1.count -= diff; in es1370_update_ptr()
694 if (s->dma_dac1.count <= 0) { in es1370_update_ptr()
695 s->ctrl &= ~CTRL_DAC1_EN; in es1370_update_ptr()
696 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_update_ptr()
697 s->dma_dac1.error++; in es1370_update_ptr()
698 } else if (s->dma_dac1.count <= (signed)s->dma_dac1.fragsize && !s->dma_dac1.endcleared) { in es1370_update_ptr()
699 clear_advance(s->dma_dac1.rawbuf, s->dma_dac1.dmasize, s->dma_dac1.swptr, in es1370_update_ptr()
700 s->dma_dac1.fragsize, (s->sctrl & SCTRL_P1SEB) ? 0 : 0x80); in es1370_update_ptr()
701 s->dma_dac1.endcleared = 1; in es1370_update_ptr()
703 if (s->dma_dac1.count + (signed)s->dma_dac1.fragsize <= (signed)s->dma_dac1.dmasize) in es1370_update_ptr()
704 wake_up(&s->dma_dac1.wait); in es1370_update_ptr()
708 if (s->ctrl & CTRL_DAC2_EN) { in es1370_update_ptr()
709 diff = get_hwptr(s, &s->dma_dac2, ES1370_REG_DAC2_FRAMECNT); in es1370_update_ptr()
710 s->dma_dac2.total_bytes += diff; in es1370_update_ptr()
711 if (s->dma_dac2.mapped) { in es1370_update_ptr()
712 s->dma_dac2.count += diff; in es1370_update_ptr()
713 if (s->dma_dac2.count >= (signed)s->dma_dac2.fragsize) in es1370_update_ptr()
714 wake_up(&s->dma_dac2.wait); in es1370_update_ptr()
716 s->dma_dac2.count -= diff; in es1370_update_ptr()
717 if (s->dma_dac2.count <= 0) { in es1370_update_ptr()
718 s->ctrl &= ~CTRL_DAC2_EN; in es1370_update_ptr()
719 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_update_ptr()
720 s->dma_dac2.error++; in es1370_update_ptr()
721 } else if (s->dma_dac2.count <= (signed)s->dma_dac2.fragsize && !s->dma_dac2.endcleared) { in es1370_update_ptr()
722 clear_advance(s->dma_dac2.rawbuf, s->dma_dac2.dmasize, s->dma_dac2.swptr, in es1370_update_ptr()
723 s->dma_dac2.fragsize, (s->sctrl & SCTRL_P2SEB) ? 0 : 0x80); in es1370_update_ptr()
724 s->dma_dac2.endcleared = 1; in es1370_update_ptr()
726 if (s->dma_dac2.count + (signed)s->dma_dac2.fragsize <= (signed)s->dma_dac2.dmasize) in es1370_update_ptr()
727 wake_up(&s->dma_dac2.wait); in es1370_update_ptr()
733 static void es1370_handle_midi(struct es1370_state *s) in es1370_handle_midi() argument
738 if (!(s->ctrl & CTRL_UART_EN)) in es1370_handle_midi()
741 while (inb(s->io+ES1370_REG_UART_STATUS) & USTAT_RXRDY) { in es1370_handle_midi()
742 ch = inb(s->io+ES1370_REG_UART_DATA); in es1370_handle_midi()
743 if (s->midi.icnt < MIDIINBUF) { in es1370_handle_midi()
744 s->midi.ibuf[s->midi.iwr] = ch; in es1370_handle_midi()
745 s->midi.iwr = (s->midi.iwr + 1) % MIDIINBUF; in es1370_handle_midi()
746 s->midi.icnt++; in es1370_handle_midi()
751 wake_up(&s->midi.iwait); in es1370_handle_midi()
753 while ((inb(s->io+ES1370_REG_UART_STATUS) & USTAT_TXRDY) && s->midi.ocnt > 0) { in es1370_handle_midi()
754 outb(s->midi.obuf[s->midi.ord], s->io+ES1370_REG_UART_DATA); in es1370_handle_midi()
755 s->midi.ord = (s->midi.ord + 1) % MIDIOUTBUF; in es1370_handle_midi()
756 s->midi.ocnt--; in es1370_handle_midi()
757 if (s->midi.ocnt < MIDIOUTBUF-16) in es1370_handle_midi()
761 wake_up(&s->midi.owait); in es1370_handle_midi()
762 …outb((s->midi.ocnt > 0) ? UCTRL_RXINTEN | UCTRL_ENA_TXINT : UCTRL_RXINTEN, s->io+ES1370_REG_UART_C… in es1370_handle_midi()
767 struct es1370_state *s = (struct es1370_state *)dev_id; in es1370_interrupt() local
771 intsrc = inl(s->io+ES1370_REG_STATUS); in es1370_interrupt()
774 spin_lock(&s->lock); in es1370_interrupt()
776 sctl = s->sctrl; in es1370_interrupt()
783 outl(sctl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_interrupt()
784 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_interrupt()
785 es1370_update_ptr(s); in es1370_interrupt()
786 es1370_handle_midi(s); in es1370_interrupt()
787 spin_unlock(&s->lock); in es1370_interrupt()
794 #define VALIDATE_STATE(s) \ argument
796 if (!(s) || (s)->magic != ES1370_MAGIC) { \
824 static void set_recsrc(struct es1370_state *s, unsigned int val) in set_recsrc() argument
837 s->mix.recsrc = val; in set_recsrc()
838 wrcodec(s, 0x12, j & 0xd5); in set_recsrc()
839 wrcodec(s, 0x13, j & 0xaa); in set_recsrc()
840 wrcodec(s, 0x14, (j >> 8) & 0x17); in set_recsrc()
841 wrcodec(s, 0x15, (j >> 8) & 0x0f); in set_recsrc()
843 if (!s->mix.imix) { in set_recsrc()
846 wrcodec(s, 0x10, i); in set_recsrc()
847 wrcodec(s, 0x11, i >> 8); in set_recsrc()
850 static int mixer_ioctl(struct es1370_state *s, unsigned int cmd, unsigned long arg) in mixer_ioctl() argument
856 VALIDATE_STATE(s); in mixer_ioctl()
862 s->mix.micpreamp = !!val; in mixer_ioctl()
863 wrcodec(s, 0x19, s->mix.micpreamp); in mixer_ioctl()
865 return put_user(s->mix.micpreamp, (int *)arg); in mixer_ioctl()
872 spin_lock_irqsave(&s->lock, flags); in mixer_ioctl()
874 s->ctrl |= CTRL_XCTL0; in mixer_ioctl()
876 s->ctrl &= ~CTRL_XCTL0; in mixer_ioctl()
877 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in mixer_ioctl()
878 spin_unlock_irqrestore(&s->lock, flags); in mixer_ioctl()
880 return put_user((s->ctrl & CTRL_XCTL0) ? 1 : 0, (int *)arg); in mixer_ioctl()
887 spin_lock_irqsave(&s->lock, flags); in mixer_ioctl()
889 s->ctrl |= CTRL_XCTL1; in mixer_ioctl()
891 s->ctrl &= ~CTRL_XCTL1; in mixer_ioctl()
892 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in mixer_ioctl()
893 spin_unlock_irqrestore(&s->lock, flags); in mixer_ioctl()
895 return put_user((s->ctrl & CTRL_XCTL1) ? 1 : 0, (int *)arg); in mixer_ioctl()
901 info.modify_counter = s->mix.modcnt; in mixer_ioctl()
921 return put_user(s->mix.recsrc, (int *)arg); in mixer_ioctl()
946 return put_user(s->mix.imix, (int *)arg); in mixer_ioctl()
952 return put_user(s->mix.vol[mixtable[i].volidx], (int *)arg); in mixer_ioctl()
957 s->mix.modcnt++; in mixer_ioctl()
961 if (get_user(s->mix.imix, (int *)arg)) in mixer_ioctl()
963 set_recsrc(s, s->mix.recsrc); in mixer_ioctl()
969 set_recsrc(s, val); in mixer_ioctl()
999 wrcodec(s, mixtable[i].right, rr); in mixer_ioctl()
1019 wrcodec(s, mixtable[i].left, rl); in mixer_ioctl()
1021 s->mix.vol[mixtable[i].volidx] = ((unsigned int)r << 8) | l; in mixer_ioctl()
1023 s->mix.vol[mixtable[i].volidx] = val; in mixer_ioctl()
1025 return put_user(s->mix.vol[mixtable[i].volidx], (int *)arg); in mixer_ioctl()
1035 struct es1370_state *s; in es1370_open_mixdev() local
1040 s = list_entry(list, struct es1370_state, devs); in es1370_open_mixdev()
1041 if (s->dev_mixer == minor) in es1370_open_mixdev()
1044 VALIDATE_STATE(s); in es1370_open_mixdev()
1045 file->private_data = s; in es1370_open_mixdev()
1051 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_release_mixdev() local
1053 VALIDATE_STATE(s); in es1370_release_mixdev()
1072 static int drain_dac1(struct es1370_state *s, int nonblock) in drain_dac1() argument
1078 if (s->dma_dac1.mapped || !s->dma_dac1.ready) in drain_dac1()
1080 add_wait_queue(&s->dma_dac1.wait, &wait); in drain_dac1()
1083 spin_lock_irqsave(&s->lock, flags); in drain_dac1()
1084 count = s->dma_dac1.count; in drain_dac1()
1085 spin_unlock_irqrestore(&s->lock, flags); in drain_dac1()
1091 remove_wait_queue(&s->dma_dac1.wait, &wait); in drain_dac1()
1095 tmo = 3 * HZ * (count + s->dma_dac1.fragsize) / 2 in drain_dac1()
1096 / dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL]; in drain_dac1()
1097 tmo >>= sample_shift[(s->sctrl & SCTRL_P1FMT) >> SCTRL_SH_P1FMT]; in drain_dac1()
1101 remove_wait_queue(&s->dma_dac1.wait, &wait); in drain_dac1()
1108 static int drain_dac2(struct es1370_state *s, int nonblock) in drain_dac2() argument
1114 if (s->dma_dac2.mapped || !s->dma_dac2.ready) in drain_dac2()
1116 add_wait_queue(&s->dma_dac2.wait, &wait); in drain_dac2()
1119 spin_lock_irqsave(&s->lock, flags); in drain_dac2()
1120 count = s->dma_dac2.count; in drain_dac2()
1121 spin_unlock_irqrestore(&s->lock, flags); in drain_dac2()
1127 remove_wait_queue(&s->dma_dac2.wait, &wait); in drain_dac2()
1131 tmo = 3 * HZ * (count + s->dma_dac2.fragsize) / 2 in drain_dac2()
1132 / DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV); in drain_dac2()
1133 tmo >>= sample_shift[(s->sctrl & SCTRL_P2FMT) >> SCTRL_SH_P2FMT]; in drain_dac2()
1137 remove_wait_queue(&s->dma_dac2.wait, &wait); in drain_dac2()
1148 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_read() local
1155 VALIDATE_STATE(s); in es1370_read()
1158 if (s->dma_adc.mapped) in es1370_read()
1162 down(&s->sem); in es1370_read()
1163 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s))) in es1370_read()
1166 add_wait_queue(&s->dma_adc.wait, &wait); in es1370_read()
1168 spin_lock_irqsave(&s->lock, flags); in es1370_read()
1169 swptr = s->dma_adc.swptr; in es1370_read()
1170 cnt = s->dma_adc.dmasize-swptr; in es1370_read()
1171 if (s->dma_adc.count < cnt) in es1370_read()
1172 cnt = s->dma_adc.count; in es1370_read()
1175 spin_unlock_irqrestore(&s->lock, flags); in es1370_read()
1179 if (s->dma_adc.enabled) in es1370_read()
1180 start_adc(s); in es1370_read()
1186 up(&s->sem); in es1370_read()
1193 down(&s->sem); in es1370_read()
1194 if (s->dma_adc.mapped) in es1370_read()
1201 if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) { in es1370_read()
1206 swptr = (swptr + cnt) % s->dma_adc.dmasize; in es1370_read()
1207 spin_lock_irqsave(&s->lock, flags); in es1370_read()
1208 s->dma_adc.swptr = swptr; in es1370_read()
1209 s->dma_adc.count -= cnt; in es1370_read()
1210 spin_unlock_irqrestore(&s->lock, flags); in es1370_read()
1214 if (s->dma_adc.enabled) in es1370_read()
1215 start_adc(s); in es1370_read()
1218 up(&s->sem); in es1370_read()
1219 remove_wait_queue(&s->dma_adc.wait, &wait); in es1370_read()
1226 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_write() local
1233 VALIDATE_STATE(s); in es1370_write()
1236 if (s->dma_dac2.mapped) in es1370_write()
1240 down(&s->sem); in es1370_write()
1241 if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s))) in es1370_write()
1244 add_wait_queue(&s->dma_dac2.wait, &wait); in es1370_write()
1246 spin_lock_irqsave(&s->lock, flags); in es1370_write()
1247 if (s->dma_dac2.count < 0) { in es1370_write()
1248 s->dma_dac2.count = 0; in es1370_write()
1249 s->dma_dac2.swptr = s->dma_dac2.hwptr; in es1370_write()
1251 swptr = s->dma_dac2.swptr; in es1370_write()
1252 cnt = s->dma_dac2.dmasize-swptr; in es1370_write()
1253 if (s->dma_dac2.count + cnt > s->dma_dac2.dmasize) in es1370_write()
1254 cnt = s->dma_dac2.dmasize - s->dma_dac2.count; in es1370_write()
1257 spin_unlock_irqrestore(&s->lock, flags); in es1370_write()
1261 if (s->dma_dac2.enabled) in es1370_write()
1262 start_dac2(s); in es1370_write()
1268 up(&s->sem); in es1370_write()
1275 down(&s->sem); in es1370_write()
1276 if (s->dma_dac2.mapped) in es1370_write()
1283 if (copy_from_user(s->dma_dac2.rawbuf + swptr, buffer, cnt)) { in es1370_write()
1288 swptr = (swptr + cnt) % s->dma_dac2.dmasize; in es1370_write()
1289 spin_lock_irqsave(&s->lock, flags); in es1370_write()
1290 s->dma_dac2.swptr = swptr; in es1370_write()
1291 s->dma_dac2.count += cnt; in es1370_write()
1292 s->dma_dac2.endcleared = 0; in es1370_write()
1293 spin_unlock_irqrestore(&s->lock, flags); in es1370_write()
1297 if (s->dma_dac2.enabled) in es1370_write()
1298 start_dac2(s); in es1370_write()
1301 up(&s->sem); in es1370_write()
1302 remove_wait_queue(&s->dma_dac2.wait, &wait); in es1370_write()
1310 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_poll() local
1314 VALIDATE_STATE(s); in es1370_poll()
1316 if (!s->dma_dac2.ready && prog_dmabuf_dac2(s)) in es1370_poll()
1318 poll_wait(file, &s->dma_dac2.wait, wait); in es1370_poll()
1321 if (!s->dma_adc.ready && prog_dmabuf_adc(s)) in es1370_poll()
1323 poll_wait(file, &s->dma_adc.wait, wait); in es1370_poll()
1325 spin_lock_irqsave(&s->lock, flags); in es1370_poll()
1326 es1370_update_ptr(s); in es1370_poll()
1328 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize) in es1370_poll()
1332 if (s->dma_dac2.mapped) { in es1370_poll()
1333 if (s->dma_dac2.count >= (signed)s->dma_dac2.fragsize) in es1370_poll()
1336 if ((signed)s->dma_dac2.dmasize >= s->dma_dac2.count + (signed)s->dma_dac2.fragsize) in es1370_poll()
1340 spin_unlock_irqrestore(&s->lock, flags); in es1370_poll()
1346 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_mmap() local
1351 VALIDATE_STATE(s); in es1370_mmap()
1353 down(&s->sem); in es1370_mmap()
1355 if ((ret = prog_dmabuf_dac2(s)) != 0) { in es1370_mmap()
1358 db = &s->dma_dac2; in es1370_mmap()
1360 if ((ret = prog_dmabuf_adc(s)) != 0) { in es1370_mmap()
1363 db = &s->dma_adc; in es1370_mmap()
1383 up(&s->sem); in es1370_mmap()
1390 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_ioctl() local
1397 VALIDATE_STATE(s); in es1370_ioctl()
1398 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac2.mapped) || in es1370_ioctl()
1399 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped); in es1370_ioctl()
1406 return drain_dac2(s, 0/*file->f_flags & O_NONBLOCK*/); in es1370_ioctl()
1417 stop_dac2(s); in es1370_ioctl()
1419 s->dma_dac2.swptr = s->dma_dac2.hwptr = s->dma_dac2.count = s->dma_dac2.total_bytes = 0; in es1370_ioctl()
1422 stop_adc(s); in es1370_ioctl()
1424 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0; in es1370_ioctl()
1432 if (s->open_mode & (~file->f_mode) & (FMODE_READ|FMODE_WRITE)) in es1370_ioctl()
1438 stop_adc(s); in es1370_ioctl()
1439 stop_dac2(s); in es1370_ioctl()
1440 s->dma_adc.ready = s->dma_dac2.ready = 0; in es1370_ioctl()
1441 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1442 s->ctrl = (s->ctrl & ~CTRL_PCLKDIV) | (DAC2_SRTODIV(val) << CTRL_SH_PCLKDIV); in es1370_ioctl()
1443 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_ioctl()
1444 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1446 return put_user(DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV), (int *)arg); in es1370_ioctl()
1452 stop_adc(s); in es1370_ioctl()
1453 s->dma_adc.ready = 0; in es1370_ioctl()
1454 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1456 s->sctrl |= SCTRL_R1SMB; in es1370_ioctl()
1458 s->sctrl &= ~SCTRL_R1SMB; in es1370_ioctl()
1459 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_ioctl()
1460 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1463 stop_dac2(s); in es1370_ioctl()
1464 s->dma_dac2.ready = 0; in es1370_ioctl()
1465 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1467 s->sctrl |= SCTRL_P2SMB; in es1370_ioctl()
1469 s->sctrl &= ~SCTRL_P2SMB; in es1370_ioctl()
1470 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_ioctl()
1471 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1480 stop_adc(s); in es1370_ioctl()
1481 s->dma_adc.ready = 0; in es1370_ioctl()
1482 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1484 s->sctrl |= SCTRL_R1SMB; in es1370_ioctl()
1486 s->sctrl &= ~SCTRL_R1SMB; in es1370_ioctl()
1487 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_ioctl()
1488 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1491 stop_dac2(s); in es1370_ioctl()
1492 s->dma_dac2.ready = 0; in es1370_ioctl()
1493 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1495 s->sctrl |= SCTRL_P2SMB; in es1370_ioctl()
1497 s->sctrl &= ~SCTRL_P2SMB; in es1370_ioctl()
1498 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_ioctl()
1499 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1502 …return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SMB : SCTRL_P2SMB)) ? 2 : 1, (i… in es1370_ioctl()
1512 stop_adc(s); in es1370_ioctl()
1513 s->dma_adc.ready = 0; in es1370_ioctl()
1514 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1516 s->sctrl |= SCTRL_R1SEB; in es1370_ioctl()
1518 s->sctrl &= ~SCTRL_R1SEB; in es1370_ioctl()
1519 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_ioctl()
1520 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1523 stop_dac2(s); in es1370_ioctl()
1524 s->dma_dac2.ready = 0; in es1370_ioctl()
1525 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1527 s->sctrl |= SCTRL_P2SEB; in es1370_ioctl()
1529 s->sctrl &= ~SCTRL_P2SEB; in es1370_ioctl()
1530 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_ioctl()
1531 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1534 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SEB : SCTRL_P2SEB)) ? in es1370_ioctl()
1542 if (file->f_mode & FMODE_READ && s->ctrl & CTRL_ADC_EN) in es1370_ioctl()
1544 if (file->f_mode & FMODE_WRITE && s->ctrl & CTRL_DAC2_EN) in es1370_ioctl()
1553 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s))) in es1370_ioctl()
1555 s->dma_adc.enabled = 1; in es1370_ioctl()
1556 start_adc(s); in es1370_ioctl()
1558 s->dma_adc.enabled = 0; in es1370_ioctl()
1559 stop_adc(s); in es1370_ioctl()
1564 if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s))) in es1370_ioctl()
1566 s->dma_dac2.enabled = 1; in es1370_ioctl()
1567 start_dac2(s); in es1370_ioctl()
1569 s->dma_dac2.enabled = 0; in es1370_ioctl()
1570 stop_dac2(s); in es1370_ioctl()
1578 if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0) in es1370_ioctl()
1580 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1581 es1370_update_ptr(s); in es1370_ioctl()
1582 abinfo.fragsize = s->dma_dac2.fragsize; in es1370_ioctl()
1583 count = s->dma_dac2.count; in es1370_ioctl()
1586 abinfo.bytes = s->dma_dac2.dmasize - count; in es1370_ioctl()
1587 abinfo.fragstotal = s->dma_dac2.numfrag; in es1370_ioctl()
1588 abinfo.fragments = abinfo.bytes >> s->dma_dac2.fragshift; in es1370_ioctl()
1589 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1595 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0) in es1370_ioctl()
1597 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1598 es1370_update_ptr(s); in es1370_ioctl()
1599 abinfo.fragsize = s->dma_adc.fragsize; in es1370_ioctl()
1600 count = s->dma_adc.count; in es1370_ioctl()
1604 abinfo.fragstotal = s->dma_adc.numfrag; in es1370_ioctl()
1605 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift; in es1370_ioctl()
1606 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1616 if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0) in es1370_ioctl()
1618 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1619 es1370_update_ptr(s); in es1370_ioctl()
1620 count = s->dma_dac2.count; in es1370_ioctl()
1621 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1629 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0) in es1370_ioctl()
1631 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1632 es1370_update_ptr(s); in es1370_ioctl()
1633 cinfo.bytes = s->dma_adc.total_bytes; in es1370_ioctl()
1634 count = s->dma_adc.count; in es1370_ioctl()
1637 cinfo.blocks = count >> s->dma_adc.fragshift; in es1370_ioctl()
1638 cinfo.ptr = s->dma_adc.hwptr; in es1370_ioctl()
1639 if (s->dma_adc.mapped) in es1370_ioctl()
1640 s->dma_adc.count &= s->dma_adc.fragsize-1; in es1370_ioctl()
1641 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1647 if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0) in es1370_ioctl()
1649 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl()
1650 es1370_update_ptr(s); in es1370_ioctl()
1651 cinfo.bytes = s->dma_dac2.total_bytes; in es1370_ioctl()
1652 count = s->dma_dac2.count; in es1370_ioctl()
1655 cinfo.blocks = count >> s->dma_dac2.fragshift; in es1370_ioctl()
1656 cinfo.ptr = s->dma_dac2.hwptr; in es1370_ioctl()
1657 if (s->dma_dac2.mapped) in es1370_ioctl()
1658 s->dma_dac2.count &= s->dma_dac2.fragsize-1; in es1370_ioctl()
1659 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl()
1664 if ((val = prog_dmabuf_dac2(s))) in es1370_ioctl()
1666 return put_user(s->dma_dac2.fragsize, (int *)arg); in es1370_ioctl()
1668 if ((val = prog_dmabuf_adc(s))) in es1370_ioctl()
1670 return put_user(s->dma_adc.fragsize, (int *)arg); in es1370_ioctl()
1676 s->dma_adc.ossfragshift = val & 0xffff; in es1370_ioctl()
1677 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff; in es1370_ioctl()
1678 if (s->dma_adc.ossfragshift < 4) in es1370_ioctl()
1679 s->dma_adc.ossfragshift = 4; in es1370_ioctl()
1680 if (s->dma_adc.ossfragshift > 15) in es1370_ioctl()
1681 s->dma_adc.ossfragshift = 15; in es1370_ioctl()
1682 if (s->dma_adc.ossmaxfrags < 4) in es1370_ioctl()
1683 s->dma_adc.ossmaxfrags = 4; in es1370_ioctl()
1686 s->dma_dac2.ossfragshift = val & 0xffff; in es1370_ioctl()
1687 s->dma_dac2.ossmaxfrags = (val >> 16) & 0xffff; in es1370_ioctl()
1688 if (s->dma_dac2.ossfragshift < 4) in es1370_ioctl()
1689 s->dma_dac2.ossfragshift = 4; in es1370_ioctl()
1690 if (s->dma_dac2.ossfragshift > 15) in es1370_ioctl()
1691 s->dma_dac2.ossfragshift = 15; in es1370_ioctl()
1692 if (s->dma_dac2.ossmaxfrags < 4) in es1370_ioctl()
1693 s->dma_dac2.ossmaxfrags = 4; in es1370_ioctl()
1698 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) || in es1370_ioctl()
1699 (file->f_mode & FMODE_WRITE && s->dma_dac2.subdivision)) in es1370_ioctl()
1706 s->dma_adc.subdivision = val; in es1370_ioctl()
1708 s->dma_dac2.subdivision = val; in es1370_ioctl()
1712 return put_user(DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV), (int *)arg); in es1370_ioctl()
1715 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SMB : SCTRL_P2SMB)) ? in es1370_ioctl()
1719 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SEB : SCTRL_P2SEB)) ? in es1370_ioctl()
1728 return mixer_ioctl(s, cmd, arg); in es1370_ioctl()
1737 struct es1370_state *s; in es1370_open() local
1742 s = list_entry(list, struct es1370_state, devs); in es1370_open()
1743 if (!((s->dev_audio ^ minor) & ~0xf)) in es1370_open()
1746 VALIDATE_STATE(s); in es1370_open()
1747 file->private_data = s; in es1370_open()
1749 down(&s->open_sem); in es1370_open()
1750 while (s->open_mode & file->f_mode) { in es1370_open()
1752 up(&s->open_sem); in es1370_open()
1755 add_wait_queue(&s->open_wait, &wait); in es1370_open()
1757 up(&s->open_sem); in es1370_open()
1759 remove_wait_queue(&s->open_wait, &wait); in es1370_open()
1763 down(&s->open_sem); in es1370_open()
1765 spin_lock_irqsave(&s->lock, flags); in es1370_open()
1766 if (!(s->open_mode & (FMODE_READ|FMODE_WRITE))) in es1370_open()
1767 s->ctrl = (s->ctrl & ~CTRL_PCLKDIV) | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV); in es1370_open()
1769 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0; in es1370_open()
1770 s->dma_adc.enabled = 1; in es1370_open()
1771 s->sctrl &= ~SCTRL_R1FMT; in es1370_open()
1773 s->sctrl |= ES1370_FMT_S16_MONO << SCTRL_SH_R1FMT; in es1370_open()
1775 s->sctrl |= ES1370_FMT_U8_MONO << SCTRL_SH_R1FMT; in es1370_open()
1778 s->dma_dac2.ossfragshift = s->dma_dac2.ossmaxfrags = s->dma_dac2.subdivision = 0; in es1370_open()
1779 s->dma_dac2.enabled = 1; in es1370_open()
1780 s->sctrl &= ~SCTRL_P2FMT; in es1370_open()
1782 s->sctrl |= ES1370_FMT_S16_MONO << SCTRL_SH_P2FMT; in es1370_open()
1784 s->sctrl |= ES1370_FMT_U8_MONO << SCTRL_SH_P2FMT; in es1370_open()
1786 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_open()
1787 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_open()
1788 spin_unlock_irqrestore(&s->lock, flags); in es1370_open()
1789 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE); in es1370_open()
1790 up(&s->open_sem); in es1370_open()
1791 init_MUTEX(&s->sem); in es1370_open()
1797 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_release() local
1799 VALIDATE_STATE(s); in es1370_release()
1802 drain_dac2(s, file->f_flags & O_NONBLOCK); in es1370_release()
1803 down(&s->open_sem); in es1370_release()
1805 stop_dac2(s); in es1370_release()
1807 dealloc_dmabuf(s, &s->dma_dac2); in es1370_release()
1810 stop_adc(s); in es1370_release()
1811 dealloc_dmabuf(s, &s->dma_adc); in es1370_release()
1813 s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE)); in es1370_release()
1814 wake_up(&s->open_wait); in es1370_release()
1815 up(&s->open_sem); in es1370_release()
1836 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_write_dac() local
1843 VALIDATE_STATE(s); in es1370_write_dac()
1846 if (s->dma_dac1.mapped) in es1370_write_dac()
1848 if (!s->dma_dac1.ready && (ret = prog_dmabuf_dac1(s))) in es1370_write_dac()
1852 add_wait_queue(&s->dma_dac1.wait, &wait); in es1370_write_dac()
1854 spin_lock_irqsave(&s->lock, flags); in es1370_write_dac()
1855 if (s->dma_dac1.count < 0) { in es1370_write_dac()
1856 s->dma_dac1.count = 0; in es1370_write_dac()
1857 s->dma_dac1.swptr = s->dma_dac1.hwptr; in es1370_write_dac()
1859 swptr = s->dma_dac1.swptr; in es1370_write_dac()
1860 cnt = s->dma_dac1.dmasize-swptr; in es1370_write_dac()
1861 if (s->dma_dac1.count + cnt > s->dma_dac1.dmasize) in es1370_write_dac()
1862 cnt = s->dma_dac1.dmasize - s->dma_dac1.count; in es1370_write_dac()
1865 spin_unlock_irqrestore(&s->lock, flags); in es1370_write_dac()
1869 if (s->dma_dac1.enabled) in es1370_write_dac()
1870 start_dac1(s); in es1370_write_dac()
1884 if (copy_from_user(s->dma_dac1.rawbuf + swptr, buffer, cnt)) { in es1370_write_dac()
1889 swptr = (swptr + cnt) % s->dma_dac1.dmasize; in es1370_write_dac()
1890 spin_lock_irqsave(&s->lock, flags); in es1370_write_dac()
1891 s->dma_dac1.swptr = swptr; in es1370_write_dac()
1892 s->dma_dac1.count += cnt; in es1370_write_dac()
1893 s->dma_dac1.endcleared = 0; in es1370_write_dac()
1894 spin_unlock_irqrestore(&s->lock, flags); in es1370_write_dac()
1898 if (s->dma_dac1.enabled) in es1370_write_dac()
1899 start_dac1(s); in es1370_write_dac()
1901 remove_wait_queue(&s->dma_dac1.wait, &wait); in es1370_write_dac()
1909 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_poll_dac() local
1913 VALIDATE_STATE(s); in es1370_poll_dac()
1914 if (!s->dma_dac1.ready && prog_dmabuf_dac1(s)) in es1370_poll_dac()
1916 poll_wait(file, &s->dma_dac1.wait, wait); in es1370_poll_dac()
1917 spin_lock_irqsave(&s->lock, flags); in es1370_poll_dac()
1918 es1370_update_ptr(s); in es1370_poll_dac()
1919 if (s->dma_dac1.mapped) { in es1370_poll_dac()
1920 if (s->dma_dac1.count >= (signed)s->dma_dac1.fragsize) in es1370_poll_dac()
1923 if ((signed)s->dma_dac1.dmasize >= s->dma_dac1.count + (signed)s->dma_dac1.fragsize) in es1370_poll_dac()
1926 spin_unlock_irqrestore(&s->lock, flags); in es1370_poll_dac()
1932 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_mmap_dac() local
1936 VALIDATE_STATE(s); in es1370_mmap_dac()
1940 if ((ret = prog_dmabuf_dac1(s)) != 0) in es1370_mmap_dac()
1946 if (size > (PAGE_SIZE << s->dma_dac1.buforder)) in es1370_mmap_dac()
1949 if (remap_page_range(vma->vm_start, virt_to_phys(s->dma_dac1.rawbuf), size, vma->vm_page_prot)) in es1370_mmap_dac()
1951 s->dma_dac1.mapped = 1; in es1370_mmap_dac()
1960 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_ioctl_dac() local
1968 VALIDATE_STATE(s); in es1370_ioctl_dac()
1974 return drain_dac1(s, 0/*file->f_flags & O_NONBLOCK*/); in es1370_ioctl_dac()
1983 stop_dac1(s); in es1370_ioctl_dac()
1985 s->dma_dac1.swptr = s->dma_dac1.hwptr = s->dma_dac1.count = s->dma_dac1.total_bytes = 0; in es1370_ioctl_dac()
1992 stop_dac1(s); in es1370_ioctl_dac()
1993 s->dma_dac1.ready = 0; in es1370_ioctl_dac()
1997 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl_dac()
1998 s->ctrl = (s->ctrl & ~CTRL_WTSRSEL) | (ctrl << CTRL_SH_WTSRSEL); in es1370_ioctl_dac()
1999 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_ioctl_dac()
2000 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl_dac()
2002 return put_user(dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL], (int *)arg); in es1370_ioctl_dac()
2007 stop_dac1(s); in es1370_ioctl_dac()
2008 s->dma_dac1.ready = 0; in es1370_ioctl_dac()
2009 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl_dac()
2011 s->sctrl |= SCTRL_P1SMB; in es1370_ioctl_dac()
2013 s->sctrl &= ~SCTRL_P1SMB; in es1370_ioctl_dac()
2014 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_ioctl_dac()
2015 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl_dac()
2022 if (s->dma_dac1.mapped) in es1370_ioctl_dac()
2024 stop_dac1(s); in es1370_ioctl_dac()
2025 s->dma_dac1.ready = 0; in es1370_ioctl_dac()
2026 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl_dac()
2028 s->sctrl |= SCTRL_P1SMB; in es1370_ioctl_dac()
2030 s->sctrl &= ~SCTRL_P1SMB; in es1370_ioctl_dac()
2031 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_ioctl_dac()
2032 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl_dac()
2034 return put_user((s->sctrl & SCTRL_P1SMB) ? 2 : 1, (int *)arg); in es1370_ioctl_dac()
2043 stop_dac1(s); in es1370_ioctl_dac()
2044 s->dma_dac1.ready = 0; in es1370_ioctl_dac()
2045 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl_dac()
2047 s->sctrl |= SCTRL_P1SEB; in es1370_ioctl_dac()
2049 s->sctrl &= ~SCTRL_P1SEB; in es1370_ioctl_dac()
2050 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_ioctl_dac()
2051 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl_dac()
2053 return put_user((s->sctrl & SCTRL_P1SEB) ? AFMT_S16_LE : AFMT_U8, (int *)arg); in es1370_ioctl_dac()
2059 return put_user((s->ctrl & CTRL_DAC1_EN) ? PCM_ENABLE_OUTPUT : 0, (int *)arg); in es1370_ioctl_dac()
2065 if (!s->dma_dac1.ready && (ret = prog_dmabuf_dac1(s))) in es1370_ioctl_dac()
2067 s->dma_dac1.enabled = 1; in es1370_ioctl_dac()
2068 start_dac1(s); in es1370_ioctl_dac()
2070 s->dma_dac1.enabled = 0; in es1370_ioctl_dac()
2071 stop_dac1(s); in es1370_ioctl_dac()
2076 if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0) in es1370_ioctl_dac()
2078 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl_dac()
2079 es1370_update_ptr(s); in es1370_ioctl_dac()
2080 abinfo.fragsize = s->dma_dac1.fragsize; in es1370_ioctl_dac()
2081 count = s->dma_dac1.count; in es1370_ioctl_dac()
2084 abinfo.bytes = s->dma_dac1.dmasize - count; in es1370_ioctl_dac()
2085 abinfo.fragstotal = s->dma_dac1.numfrag; in es1370_ioctl_dac()
2086 abinfo.fragments = abinfo.bytes >> s->dma_dac1.fragshift; in es1370_ioctl_dac()
2087 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl_dac()
2095 if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0) in es1370_ioctl_dac()
2097 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl_dac()
2098 es1370_update_ptr(s); in es1370_ioctl_dac()
2099 count = s->dma_dac1.count; in es1370_ioctl_dac()
2100 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl_dac()
2106 if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0) in es1370_ioctl_dac()
2108 spin_lock_irqsave(&s->lock, flags); in es1370_ioctl_dac()
2109 es1370_update_ptr(s); in es1370_ioctl_dac()
2110 cinfo.bytes = s->dma_dac1.total_bytes; in es1370_ioctl_dac()
2111 count = s->dma_dac1.count; in es1370_ioctl_dac()
2114 cinfo.blocks = count >> s->dma_dac1.fragshift; in es1370_ioctl_dac()
2115 cinfo.ptr = s->dma_dac1.hwptr; in es1370_ioctl_dac()
2116 if (s->dma_dac1.mapped) in es1370_ioctl_dac()
2117 s->dma_dac1.count &= s->dma_dac1.fragsize-1; in es1370_ioctl_dac()
2118 spin_unlock_irqrestore(&s->lock, flags); in es1370_ioctl_dac()
2122 if ((val = prog_dmabuf_dac1(s))) in es1370_ioctl_dac()
2124 return put_user(s->dma_dac1.fragsize, (int *)arg); in es1370_ioctl_dac()
2129 s->dma_dac1.ossfragshift = val & 0xffff; in es1370_ioctl_dac()
2130 s->dma_dac1.ossmaxfrags = (val >> 16) & 0xffff; in es1370_ioctl_dac()
2131 if (s->dma_dac1.ossfragshift < 4) in es1370_ioctl_dac()
2132 s->dma_dac1.ossfragshift = 4; in es1370_ioctl_dac()
2133 if (s->dma_dac1.ossfragshift > 15) in es1370_ioctl_dac()
2134 s->dma_dac1.ossfragshift = 15; in es1370_ioctl_dac()
2135 if (s->dma_dac1.ossmaxfrags < 4) in es1370_ioctl_dac()
2136 s->dma_dac1.ossmaxfrags = 4; in es1370_ioctl_dac()
2140 if (s->dma_dac1.subdivision) in es1370_ioctl_dac()
2146 s->dma_dac1.subdivision = val; in es1370_ioctl_dac()
2150 return put_user(dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL], (int *)arg); in es1370_ioctl_dac()
2153 return put_user((s->sctrl & SCTRL_P1SMB) ? 2 : 1, (int *)arg); in es1370_ioctl_dac()
2156 return put_user((s->sctrl & SCTRL_P1SEB) ? 16 : 8, (int *)arg); in es1370_ioctl_dac()
2164 return mixer_ioctl(s, cmd, arg); in es1370_ioctl_dac()
2173 struct es1370_state *s; in es1370_open_dac() local
2178 s = list_entry(list, struct es1370_state, devs); in es1370_open_dac()
2179 if (!((s->dev_dac ^ minor) & ~0xf)) in es1370_open_dac()
2182 VALIDATE_STATE(s); in es1370_open_dac()
2190 file->private_data = s; in es1370_open_dac()
2192 down(&s->open_sem); in es1370_open_dac()
2193 while (s->open_mode & FMODE_DAC) { in es1370_open_dac()
2195 up(&s->open_sem); in es1370_open_dac()
2198 add_wait_queue(&s->open_wait, &wait); in es1370_open_dac()
2200 up(&s->open_sem); in es1370_open_dac()
2202 remove_wait_queue(&s->open_wait, &wait); in es1370_open_dac()
2206 down(&s->open_sem); in es1370_open_dac()
2208 s->dma_dac1.ossfragshift = s->dma_dac1.ossmaxfrags = s->dma_dac1.subdivision = 0; in es1370_open_dac()
2209 s->dma_dac1.enabled = 1; in es1370_open_dac()
2210 spin_lock_irqsave(&s->lock, flags); in es1370_open_dac()
2211 s->ctrl = (s->ctrl & ~CTRL_WTSRSEL) | (1 << CTRL_SH_WTSRSEL); in es1370_open_dac()
2212 s->sctrl &= ~SCTRL_P1FMT; in es1370_open_dac()
2214 s->sctrl |= ES1370_FMT_S16_MONO << SCTRL_SH_P1FMT; in es1370_open_dac()
2216 s->sctrl |= ES1370_FMT_U8_MONO << SCTRL_SH_P1FMT; in es1370_open_dac()
2217 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_open_dac()
2218 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_open_dac()
2219 spin_unlock_irqrestore(&s->lock, flags); in es1370_open_dac()
2220 s->open_mode |= FMODE_DAC; in es1370_open_dac()
2221 up(&s->open_sem); in es1370_open_dac()
2227 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_release_dac() local
2229 VALIDATE_STATE(s); in es1370_release_dac()
2231 drain_dac1(s, file->f_flags & O_NONBLOCK); in es1370_release_dac()
2232 down(&s->open_sem); in es1370_release_dac()
2233 stop_dac1(s); in es1370_release_dac()
2234 dealloc_dmabuf(s, &s->dma_dac1); in es1370_release_dac()
2235 s->open_mode &= ~FMODE_DAC; in es1370_release_dac()
2236 wake_up(&s->open_wait); in es1370_release_dac()
2237 up(&s->open_sem); in es1370_release_dac()
2257 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_midi_read() local
2264 VALIDATE_STATE(s); in es1370_midi_read()
2272 add_wait_queue(&s->midi.iwait, &wait); in es1370_midi_read()
2274 spin_lock_irqsave(&s->lock, flags); in es1370_midi_read()
2275 ptr = s->midi.ird; in es1370_midi_read()
2277 if (s->midi.icnt < cnt) in es1370_midi_read()
2278 cnt = s->midi.icnt; in es1370_midi_read()
2281 spin_unlock_irqrestore(&s->lock, flags); in es1370_midi_read()
2298 if (copy_to_user(buffer, s->midi.ibuf + ptr, cnt)) { in es1370_midi_read()
2304 spin_lock_irqsave(&s->lock, flags); in es1370_midi_read()
2305 s->midi.ird = ptr; in es1370_midi_read()
2306 s->midi.icnt -= cnt; in es1370_midi_read()
2307 spin_unlock_irqrestore(&s->lock, flags); in es1370_midi_read()
2314 remove_wait_queue(&s->midi.iwait, &wait); in es1370_midi_read()
2320 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_midi_write() local
2327 VALIDATE_STATE(s); in es1370_midi_write()
2335 add_wait_queue(&s->midi.owait, &wait); in es1370_midi_write()
2337 spin_lock_irqsave(&s->lock, flags); in es1370_midi_write()
2338 ptr = s->midi.owr; in es1370_midi_write()
2340 if (s->midi.ocnt + cnt > MIDIOUTBUF) in es1370_midi_write()
2341 cnt = MIDIOUTBUF - s->midi.ocnt; in es1370_midi_write()
2344 es1370_handle_midi(s); in es1370_midi_write()
2346 spin_unlock_irqrestore(&s->lock, flags); in es1370_midi_write()
2363 if (copy_from_user(s->midi.obuf + ptr, buffer, cnt)) { in es1370_midi_write()
2369 spin_lock_irqsave(&s->lock, flags); in es1370_midi_write()
2370 s->midi.owr = ptr; in es1370_midi_write()
2371 s->midi.ocnt += cnt; in es1370_midi_write()
2372 spin_unlock_irqrestore(&s->lock, flags); in es1370_midi_write()
2376 spin_lock_irqsave(&s->lock, flags); in es1370_midi_write()
2377 es1370_handle_midi(s); in es1370_midi_write()
2378 spin_unlock_irqrestore(&s->lock, flags); in es1370_midi_write()
2381 remove_wait_queue(&s->midi.owait, &wait); in es1370_midi_write()
2388 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_midi_poll() local
2392 VALIDATE_STATE(s); in es1370_midi_poll()
2394 poll_wait(file, &s->midi.owait, wait); in es1370_midi_poll()
2396 poll_wait(file, &s->midi.iwait, wait); in es1370_midi_poll()
2397 spin_lock_irqsave(&s->lock, flags); in es1370_midi_poll()
2399 if (s->midi.icnt > 0) in es1370_midi_poll()
2403 if (s->midi.ocnt < MIDIOUTBUF) in es1370_midi_poll()
2406 spin_unlock_irqrestore(&s->lock, flags); in es1370_midi_poll()
2416 struct es1370_state *s; in es1370_midi_open() local
2421 s = list_entry(list, struct es1370_state, devs); in es1370_midi_open()
2422 if (s->dev_midi == minor) in es1370_midi_open()
2425 VALIDATE_STATE(s); in es1370_midi_open()
2426 file->private_data = s; in es1370_midi_open()
2428 down(&s->open_sem); in es1370_midi_open()
2429 while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) { in es1370_midi_open()
2431 up(&s->open_sem); in es1370_midi_open()
2434 add_wait_queue(&s->open_wait, &wait); in es1370_midi_open()
2436 up(&s->open_sem); in es1370_midi_open()
2438 remove_wait_queue(&s->open_wait, &wait); in es1370_midi_open()
2442 down(&s->open_sem); in es1370_midi_open()
2444 spin_lock_irqsave(&s->lock, flags); in es1370_midi_open()
2445 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) { in es1370_midi_open()
2446 s->midi.ird = s->midi.iwr = s->midi.icnt = 0; in es1370_midi_open()
2447 s->midi.ord = s->midi.owr = s->midi.ocnt = 0; in es1370_midi_open()
2448 outb(UCTRL_CNTRL_SWR, s->io+ES1370_REG_UART_CONTROL); in es1370_midi_open()
2449 outb(0, s->io+ES1370_REG_UART_CONTROL); in es1370_midi_open()
2450 outb(0, s->io+ES1370_REG_UART_TEST); in es1370_midi_open()
2453 s->midi.ird = s->midi.iwr = s->midi.icnt = 0; in es1370_midi_open()
2456 s->midi.ord = s->midi.owr = s->midi.ocnt = 0; in es1370_midi_open()
2458 s->ctrl |= CTRL_UART_EN; in es1370_midi_open()
2459 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_midi_open()
2460 es1370_handle_midi(s); in es1370_midi_open()
2461 spin_unlock_irqrestore(&s->lock, flags); in es1370_midi_open()
2462 s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE); in es1370_midi_open()
2463 up(&s->open_sem); in es1370_midi_open()
2469 struct es1370_state *s = (struct es1370_state *)file->private_data; in es1370_midi_release() local
2474 VALIDATE_STATE(s); in es1370_midi_release()
2478 add_wait_queue(&s->midi.owait, &wait); in es1370_midi_release()
2481 spin_lock_irqsave(&s->lock, flags); in es1370_midi_release()
2482 count = s->midi.ocnt; in es1370_midi_release()
2483 spin_unlock_irqrestore(&s->lock, flags); in es1370_midi_release()
2494 remove_wait_queue(&s->midi.owait, &wait); in es1370_midi_release()
2497 down(&s->open_sem); in es1370_midi_release()
2498 s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE)); in es1370_midi_release()
2499 spin_lock_irqsave(&s->lock, flags); in es1370_midi_release()
2500 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) { in es1370_midi_release()
2501 s->ctrl &= ~CTRL_UART_EN; in es1370_midi_release()
2502 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_midi_release()
2504 spin_unlock_irqrestore(&s->lock, flags); in es1370_midi_release()
2505 wake_up(&s->open_wait); in es1370_midi_release()
2506 up(&s->open_sem); in es1370_midi_release()
2564 struct es1370_state *s; in es1370_probe() local
2587 if (!(s = kmalloc(sizeof(struct es1370_state), GFP_KERNEL))) { in es1370_probe()
2591 memset(s, 0, sizeof(struct es1370_state)); in es1370_probe()
2592 init_waitqueue_head(&s->dma_adc.wait); in es1370_probe()
2593 init_waitqueue_head(&s->dma_dac1.wait); in es1370_probe()
2594 init_waitqueue_head(&s->dma_dac2.wait); in es1370_probe()
2595 init_waitqueue_head(&s->open_wait); in es1370_probe()
2596 init_waitqueue_head(&s->midi.iwait); in es1370_probe()
2597 init_waitqueue_head(&s->midi.owait); in es1370_probe()
2598 init_MUTEX(&s->open_sem); in es1370_probe()
2599 spin_lock_init(&s->lock); in es1370_probe()
2600 s->magic = ES1370_MAGIC; in es1370_probe()
2601 s->dev = pcidev; in es1370_probe()
2602 s->io = pci_resource_start(pcidev, 0); in es1370_probe()
2603 s->irq = pcidev->irq; in es1370_probe()
2604 if (!request_region(s->io, ES1370_EXTENT, "es1370")) { in es1370_probe()
2605 printk(KERN_ERR "es1370: io ports %#lx-%#lx in use\n", s->io, s->io+ES1370_EXTENT-1); in es1370_probe()
2609 if ((ret=request_irq(s->irq, es1370_interrupt, SA_SHIRQ, "es1370",s))) { in es1370_probe()
2610 printk(KERN_ERR "es1370: irq %u in use\n", s->irq); in es1370_probe()
2617 s->ctrl = CTRL_CDC_EN | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV) | (1 << CTRL_SH_WTSRSEL); in es1370_probe()
2618 s->gameport.io = 0; in es1370_probe()
2623 s->ctrl |= CTRL_JYSTK_EN; in es1370_probe()
2624 s->gameport.io = 0x200; in es1370_probe()
2628 s->ctrl |= CTRL_XCTL0; in es1370_probe()
2630 s->ctrl |= CTRL_XCTL1; in es1370_probe()
2631 s->sctrl = 0; in es1370_probe()
2634 s->io, s->irq, (s->ctrl & CTRL_JYSTK_EN) ? "on" : "off", in es1370_probe()
2635 (s->ctrl & CTRL_XCTL0) ? "out" : "in", in es1370_probe()
2636 (s->ctrl & CTRL_XCTL1) ? "1" : "0"); in es1370_probe()
2638 if ((s->dev_audio = register_sound_dsp(&es1370_audio_fops, -1)) < 0) { in es1370_probe()
2639 ret = s->dev_audio; in es1370_probe()
2642 if ((s->dev_mixer = register_sound_mixer(&es1370_mixer_fops, -1)) < 0) { in es1370_probe()
2643 ret = s->dev_mixer; in es1370_probe()
2646 if ((s->dev_dac = register_sound_dsp(&es1370_dac_fops, -1)) < 0) { in es1370_probe()
2647 ret = s->dev_dac; in es1370_probe()
2650 if ((s->dev_midi = register_sound_midi(&es1370_midi_fops, -1)) < 0) { in es1370_probe()
2651 ret = s->dev_midi; in es1370_probe()
2655 outl(s->ctrl, s->io+ES1370_REG_CONTROL); in es1370_probe()
2656 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL); in es1370_probe()
2658 outl((ES1370_REG_PHANTOM_FRAMEADR >> 8) & 15, s->io+ES1370_REG_MEMPAGE); in es1370_probe()
2659 outl(virt_to_bus(bugbuf), s->io+(ES1370_REG_PHANTOM_FRAMEADR & 0xff)); in es1370_probe()
2660 outl(0, s->io+(ES1370_REG_PHANTOM_FRAMECNT & 0xff)); in es1370_probe()
2662 wrcodec(s, 0x16, 3); /* no RST, PD */ in es1370_probe()
2663 …wrcodec(s, 0x17, 0); /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off the LRCLK2 PLL; program… in es1370_probe()
2664 wrcodec(s, 0x18, 0); /* recording source is mixer */ in es1370_probe()
2665 wrcodec(s, 0x19, s->mix.micpreamp = 1); /* turn on MIC preamp */ in es1370_probe()
2666 s->mix.imix = 1; in es1370_probe()
2670 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val); in es1370_probe()
2673 mixer_ioctl(s, initvol[i].mixch, (unsigned long)&val); in es1370_probe()
2677 if(s->gameport.io) in es1370_probe()
2678 gameport_register_port(&s->gameport); in es1370_probe()
2681 pci_set_drvdata(pcidev, s); in es1370_probe()
2683 list_add_tail(&s->devs, &devs); in es1370_probe()
2690 unregister_sound_dsp(s->dev_dac); in es1370_probe()
2692 unregister_sound_mixer(s->dev_mixer); in es1370_probe()
2694 unregister_sound_dsp(s->dev_audio); in es1370_probe()
2697 free_irq(s->irq, s); in es1370_probe()
2698 if (s->gameport.io) in es1370_probe()
2699 release_region(s->gameport.io, JOY_EXTENT); in es1370_probe()
2701 release_region(s->io, ES1370_EXTENT); in es1370_probe()
2703 kfree(s); in es1370_probe()
2709 struct es1370_state *s = pci_get_drvdata(dev); in es1370_remove() local
2711 if (!s) in es1370_remove()
2713 list_del(&s->devs); in es1370_remove()
2714 outl(CTRL_SERR_DIS | (1 << CTRL_SH_WTSRSEL), s->io+ES1370_REG_CONTROL); /* switch everything off */ in es1370_remove()
2715 outl(0, s->io+ES1370_REG_SERIAL_CONTROL); /* clear serial interrupts */ in es1370_remove()
2717 free_irq(s->irq, s); in es1370_remove()
2718 if (s->gameport.io) { in es1370_remove()
2719 gameport_unregister_port(&s->gameport); in es1370_remove()
2720 release_region(s->gameport.io, JOY_EXTENT); in es1370_remove()
2722 release_region(s->io, ES1370_EXTENT); in es1370_remove()
2723 unregister_sound_dsp(s->dev_audio); in es1370_remove()
2724 unregister_sound_mixer(s->dev_mixer); in es1370_remove()
2725 unregister_sound_dsp(s->dev_dac); in es1370_remove()
2726 unregister_sound_midi(s->dev_midi); in es1370_remove()
2727 kfree(s); in es1370_remove()