Lines Matching defs:uart
173 static inline void snd_uart16550_add_timer(struct snd_uart16550 *uart)
175 if (!uart->timer_running) {
177 uart->buffer_timer.expires = jiffies + (HZ+255)/256;
178 uart->timer_running = 1;
179 add_timer(&uart->buffer_timer);
183 static inline void snd_uart16550_del_timer(struct snd_uart16550 *uart)
185 if (uart->timer_running) {
186 del_timer(&uart->buffer_timer);
187 uart->timer_running = 0;
192 static inline void snd_uart16550_buffer_output(struct snd_uart16550 *uart)
194 unsigned short buff_out = uart->buff_out;
195 if (uart->buff_in_count > 0) {
196 outb(uart->tx_buff[buff_out], uart->base + UART_TX);
197 uart->fifo_count++;
200 uart->buff_out = buff_out;
201 uart->buff_in_count--;
209 static void snd_uart16550_io_loop(struct snd_uart16550 * uart)
215 substream = uart->prev_in;
218 while ((status = inb(uart->base + UART_LSR)) & UART_LSR_DR) {
220 c = inb(uart->base + UART_RX);
224 uart->rstatus = c;
227 if (uart->adaptor == SNDRV_SERIAL_GENERIC) {
228 if (uart->rstatus == 0xf5) {
234 uart->rstatus = 0;
235 } else if ((uart->filemode & SERIAL_MODE_INPUT_OPEN)
236 && uart->midi_input[substream])
237 snd_rawmidi_receive(uart->midi_input[substream],
239 } else if ((uart->filemode & SERIAL_MODE_INPUT_OPEN) &&
240 uart->midi_input[substream])
241 snd_rawmidi_receive(uart->midi_input[substream], &c, 1);
246 uart->rmidi->name, uart->base);
250 uart->prev_in = substream;
256 uart->fifo_count = 0;
257 if (uart->adaptor == SNDRV_SERIAL_MS124W_SA
258 || uart->adaptor == SNDRV_SERIAL_GENERIC) {
260 status = inb(uart->base + UART_MSR);
261 while (uart->fifo_count == 0 && (status & UART_MSR_CTS) &&
262 uart->buff_in_count > 0) {
263 snd_uart16550_buffer_output(uart);
264 status = inb(uart->base + UART_MSR);
268 while (uart->fifo_count < uart->fifo_limit /* Can we write ? */
269 && uart->buff_in_count > 0) /* Do we want to? */
270 snd_uart16550_buffer_output(uart);
272 if (uart->irq < 0 && uart->buff_in_count > 0)
273 snd_uart16550_add_timer(uart);
298 struct snd_uart16550 *uart;
300 uart = dev_id;
301 spin_lock(&uart->open_lock);
302 if (uart->filemode == SERIAL_MODE_NOT_OPENED) {
303 spin_unlock(&uart->open_lock);
307 inb(uart->base + UART_IIR);
308 snd_uart16550_io_loop(uart);
309 spin_unlock(&uart->open_lock);
317 struct snd_uart16550 *uart;
319 uart = (struct snd_uart16550 *)data;
320 spin_lock_irqsave(&uart->open_lock, flags);
321 snd_uart16550_del_timer(uart);
322 snd_uart16550_io_loop(uart);
323 spin_unlock_irqrestore(&uart->open_lock, flags);
327 * this method probes, if an uart sits on given port
331 static int __devinit snd_uart16550_detect(struct snd_uart16550 *uart)
333 unsigned long io_base = uart->base;
337 /* Do some vague tests for the presence of the uart */
342 uart->res_base = request_region(io_base, 8, "Serial MIDI");
343 if (uart->res_base == NULL) {
348 /* uart detected unless one of the following tests should fail */
374 static void snd_uart16550_do_open(struct snd_uart16550 * uart)
379 uart->buff_in_count = 0;
380 uart->buff_in = 0;
381 uart->buff_out = 0;
382 uart->fifo_limit = 1;
383 uart->fifo_count = 0;
384 uart->timer_running = 0;
393 ,uart->base + UART_FCR); /* FIFO Control Register */
395 if ((inb(uart->base + UART_IIR) & 0xf0) == 0xc0)
396 uart->fifo_limit = 16;
397 if (uart->divisor != 0) {
398 uart->old_line_ctrl_reg = inb(uart->base + UART_LCR);
400 ,uart->base + UART_LCR); /* Line Control Register */
401 uart->old_divisor_lsb = inb(uart->base + UART_DLL);
402 uart->old_divisor_msb = inb(uart->base + UART_DLM);
404 outb(uart->divisor
405 ,uart->base + UART_DLL); /* Divisor Latch Low */
407 ,uart->base + UART_DLM); /* Divisor Latch High */
415 ,uart->base + UART_LCR); /* Line Control Register */
417 switch (uart->adaptor) {
424 ,uart->base + UART_MCR); /* Modem Control Register */
431 uart->base + UART_MCR);
437 uart->base + UART_MCR);
441 if (uart->irq < 0) {
445 } else if (uart->adaptor == SNDRV_SERIAL_MS124W_SA) {
449 } else if (uart->adaptor == SNDRV_SERIAL_GENERIC) {
459 outb(byte, uart->base + UART_IER); /* Interrupt enable Register */
461 inb(uart->base + UART_LSR); /* Clear any pre-existing overrun indication */
462 inb(uart->base + UART_IIR); /* Clear any pre-existing transmit interrupt */
463 inb(uart->base + UART_RX); /* Clear any pre-existing receive interrupt */
466 static void snd_uart16550_do_close(struct snd_uart16550 * uart)
468 if (uart->irq < 0)
469 snd_uart16550_del_timer(uart);
477 ,uart->base + UART_IER); /* Interrupt enable Register */
479 switch (uart->adaptor) {
484 ,uart->base + UART_MCR); /* Modem Control Register */
491 uart->base + UART_MCR);
497 uart->base + UART_MCR);
501 inb(uart->base + UART_IIR); /* Clear any outstanding interrupts */
504 if (uart->divisor != 0) {
506 ,uart->base + UART_LCR); /* Line Control Register */
507 outb(uart->old_divisor_lsb
508 ,uart->base + UART_DLL); /* Divisor Latch Low */
509 outb(uart->old_divisor_msb
510 ,uart->base + UART_DLM); /* Divisor Latch High */
512 outb(uart->old_line_ctrl_reg
513 ,uart->base + UART_LCR); /* Line Control Register */
520 struct snd_uart16550 *uart = substream->rmidi->private_data;
522 spin_lock_irqsave(&uart->open_lock, flags);
523 if (uart->filemode == SERIAL_MODE_NOT_OPENED)
524 snd_uart16550_do_open(uart);
525 uart->filemode |= SERIAL_MODE_INPUT_OPEN;
526 uart->midi_input[substream->number] = substream;
527 spin_unlock_irqrestore(&uart->open_lock, flags);
534 struct snd_uart16550 *uart = substream->rmidi->private_data;
536 spin_lock_irqsave(&uart->open_lock, flags);
537 uart->filemode &= ~SERIAL_MODE_INPUT_OPEN;
538 uart->midi_input[substream->number] = NULL;
539 if (uart->filemode == SERIAL_MODE_NOT_OPENED)
540 snd_uart16550_do_close(uart);
541 spin_unlock_irqrestore(&uart->open_lock, flags);
549 struct snd_uart16550 *uart = substream->rmidi->private_data;
551 spin_lock_irqsave(&uart->open_lock, flags);
553 uart->filemode |= SERIAL_MODE_INPUT_TRIGGERED;
555 uart->filemode &= ~SERIAL_MODE_INPUT_TRIGGERED;
556 spin_unlock_irqrestore(&uart->open_lock, flags);
562 struct snd_uart16550 *uart = substream->rmidi->private_data;
564 spin_lock_irqsave(&uart->open_lock, flags);
565 if (uart->filemode == SERIAL_MODE_NOT_OPENED)
566 snd_uart16550_do_open(uart);
567 uart->filemode |= SERIAL_MODE_OUTPUT_OPEN;
568 uart->midi_output[substream->number] = substream;
569 spin_unlock_irqrestore(&uart->open_lock, flags);
576 struct snd_uart16550 *uart = substream->rmidi->private_data;
578 spin_lock_irqsave(&uart->open_lock, flags);
579 uart->filemode &= ~SERIAL_MODE_OUTPUT_OPEN;
580 uart->midi_output[substream->number] = NULL;
581 if (uart->filemode == SERIAL_MODE_NOT_OPENED)
582 snd_uart16550_do_close(uart);
583 spin_unlock_irqrestore(&uart->open_lock, flags);
587 static inline int snd_uart16550_buffer_can_write(struct snd_uart16550 *uart,
590 if (uart->buff_in_count + Num < TX_BUFF_SIZE)
596 static inline int snd_uart16550_write_buffer(struct snd_uart16550 *uart,
599 unsigned short buff_in = uart->buff_in;
600 if (uart->buff_in_count < TX_BUFF_SIZE) {
601 uart->tx_buff[buff_in] = byte;
604 uart->buff_in = buff_in;
605 uart->buff_in_count++;
606 if (uart->irq < 0) /* polling mode */
607 snd_uart16550_add_timer(uart);
613 static int snd_uart16550_output_byte(struct snd_uart16550 *uart,
617 if (uart->buff_in_count == 0 /* Buffer empty? */
618 && ((uart->adaptor != SNDRV_SERIAL_MS124W_SA &&
619 uart->adaptor != SNDRV_SERIAL_GENERIC) ||
620 (uart->fifo_count == 0 /* FIFO empty? */
621 && (inb(uart->base + UART_MSR) & UART_MSR_CTS)))) { /* CTS? */
624 if ((inb(uart->base + UART_LSR) & UART_LSR_THRE) != 0) {
626 uart->fifo_count = 1;
627 outb(midi_byte, uart->base + UART_TX);
629 if (uart->fifo_count < uart->fifo_limit) {
630 uart->fifo_count++;
631 outb(midi_byte, uart->base + UART_TX);
635 snd_uart16550_write_buffer(uart, midi_byte);
639 if (!snd_uart16550_write_buffer(uart, midi_byte)) {
642 uart->rmidi->name, uart->base);
654 struct snd_uart16550 *uart = substream->rmidi->private_data;
663 spin_lock_irqsave(&uart->open_lock, flags);
665 if (uart->irq < 0) /* polling */
666 snd_uart16550_io_loop(uart);
668 if (uart->adaptor == SNDRV_SERIAL_MS124W_MB) {
672 if (uart->buff_in_count > TX_BUFF_SIZE - 2)
686 snd_uart16550_output_byte(uart, substream, addr_byte);
688 snd_uart16550_output_byte(uart, substream, midi_byte);
696 (uart->adaptor == SNDRV_SERIAL_SOUNDCANVAS ||
697 uart->adaptor == SNDRV_SERIAL_GENERIC) &&
698 (uart->prev_out != substream->number ||
701 if (snd_uart16550_buffer_can_write(uart, 3)) {
705 * in this uart, send the change part
708 uart->prev_out = substream->number;
710 snd_uart16550_output_byte(uart, substream,
713 snd_uart16550_output_byte(uart, substream,
714 uart->prev_out + 1);
718 uart->adaptor == SNDRV_SERIAL_SOUNDCANVAS)
719 snd_uart16550_output_byte(uart, substream, uart->prev_status[uart->prev_out]);
720 } else if (!uart->drop_on_full)
726 if (!snd_uart16550_output_byte(uart, substream, midi_byte) &&
727 !uart->drop_on_full )
731 uart->prev_status[uart->prev_out] = midi_byte;
738 spin_unlock_irqrestore(&uart->open_lock, flags);
745 struct snd_uart16550 *uart = substream->rmidi->private_data;
747 spin_lock_irqsave(&uart->open_lock, flags);
749 uart->filemode |= SERIAL_MODE_OUTPUT_TRIGGERED;
751 uart->filemode &= ~SERIAL_MODE_OUTPUT_TRIGGERED;
752 spin_unlock_irqrestore(&uart->open_lock, flags);
771 static int snd_uart16550_free(struct snd_uart16550 *uart)
773 if (uart->irq >= 0)
774 free_irq(uart->irq, uart);
775 release_and_free_resource(uart->res_base);
776 kfree(uart);
782 struct snd_uart16550 *uart = device->device_data;
783 return snd_uart16550_free(uart);
798 struct snd_uart16550 *uart;
802 if ((uart = kzalloc(sizeof(*uart), GFP_KERNEL)) == NULL)
804 uart->adaptor = adaptor;
805 uart->card = card;
806 spin_lock_init(&uart->open_lock);
807 uart->irq = -1;
808 uart->base = iobase;
809 uart->drop_on_full = droponfull;
811 if ((err = snd_uart16550_detect(uart)) <= 0) {
813 snd_uart16550_free(uart);
819 IRQF_DISABLED, "Serial MIDI", uart)) {
823 uart->irq = irq;
826 uart->divisor = base / speed;
827 uart->speed = base / (unsigned int)uart->divisor;
828 uart->speed_base = base;
829 uart->prev_out = -1;
830 uart->prev_in = 0;
831 uart->rstatus = 0;
832 memset(uart->prev_status, 0x80, sizeof(unsigned char) * SNDRV_SERIAL_MAX_OUTS);
833 init_timer(&uart->buffer_timer);
834 uart->buffer_timer.function = snd_uart16550_buffer_timer;
835 uart->buffer_timer.data = (unsigned long)uart;
836 uart->timer_running = 0;
839 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, uart, &ops)) < 0) {
840 snd_uart16550_free(uart);
844 switch (uart->adaptor) {
849 outb(UART_MCR_RTS | (0&UART_MCR_DTR), uart->base + UART_MCR);
854 outb(UART_MCR_RTS | UART_MCR_DTR, uart->base + UART_MCR);
861 *ruart = uart;
875 static int __devinit snd_uart16550_rmidi(struct snd_uart16550 *uart, int device,
882 err = snd_rawmidi_new(uart->card, "UART Serial MIDI", device,
896 rrawmidi->private_data = uart;
905 struct snd_uart16550 *uart;
959 &uart)) < 0)
962 err = snd_uart16550_rmidi(uart, 0, outs[dev], ins[dev], &uart->rmidi);
968 adaptor_names[uart->adaptor],
969 uart->base,
970 uart->irq);