Lines Matching full:uart
159 static inline void snd_uart16550_add_timer(struct snd_uart16550 *uart) in snd_uart16550_add_timer() argument
161 if (!uart->timer_running) { in snd_uart16550_add_timer()
163 mod_timer(&uart->buffer_timer, jiffies + (HZ + 255) / 256); in snd_uart16550_add_timer()
164 uart->timer_running = 1; in snd_uart16550_add_timer()
168 static inline void snd_uart16550_del_timer(struct snd_uart16550 *uart) in snd_uart16550_del_timer() argument
170 if (uart->timer_running) { in snd_uart16550_del_timer()
171 del_timer(&uart->buffer_timer); in snd_uart16550_del_timer()
172 uart->timer_running = 0; in snd_uart16550_del_timer()
177 static inline void snd_uart16550_buffer_output(struct snd_uart16550 *uart) in snd_uart16550_buffer_output() argument
179 unsigned short buff_out = uart->buff_out; in snd_uart16550_buffer_output()
180 if (uart->buff_in_count > 0) { in snd_uart16550_buffer_output()
181 outb(uart->tx_buff[buff_out], uart->base + UART_TX); in snd_uart16550_buffer_output()
182 uart->fifo_count++; in snd_uart16550_buffer_output()
185 uart->buff_out = buff_out; in snd_uart16550_buffer_output()
186 uart->buff_in_count--; in snd_uart16550_buffer_output()
194 static void snd_uart16550_io_loop(struct snd_uart16550 * uart) in snd_uart16550_io_loop() argument
200 substream = uart->prev_in; in snd_uart16550_io_loop()
203 while ((status = inb(uart->base + UART_LSR)) & UART_LSR_DR) { in snd_uart16550_io_loop()
205 c = inb(uart->base + UART_RX); in snd_uart16550_io_loop()
209 uart->rstatus = c; in snd_uart16550_io_loop()
212 if (uart->adaptor == SNDRV_SERIAL_GENERIC) { in snd_uart16550_io_loop()
213 if (uart->rstatus == 0xf5) { in snd_uart16550_io_loop()
219 uart->rstatus = 0; in snd_uart16550_io_loop()
220 } else if ((uart->filemode & SERIAL_MODE_INPUT_OPEN) in snd_uart16550_io_loop()
221 && uart->midi_input[substream]) in snd_uart16550_io_loop()
222 snd_rawmidi_receive(uart->midi_input[substream], in snd_uart16550_io_loop()
224 } else if ((uart->filemode & SERIAL_MODE_INPUT_OPEN) && in snd_uart16550_io_loop()
225 uart->midi_input[substream]) in snd_uart16550_io_loop()
226 snd_rawmidi_receive(uart->midi_input[substream], &c, 1); in snd_uart16550_io_loop()
231 uart->rmidi->name, uart->base); in snd_uart16550_io_loop()
235 uart->prev_in = substream; in snd_uart16550_io_loop()
241 uart->fifo_count = 0; in snd_uart16550_io_loop()
242 if (uart->adaptor == SNDRV_SERIAL_MS124W_SA in snd_uart16550_io_loop()
243 || uart->adaptor == SNDRV_SERIAL_GENERIC) { in snd_uart16550_io_loop()
245 status = inb(uart->base + UART_MSR); in snd_uart16550_io_loop()
246 while (uart->fifo_count == 0 && (status & UART_MSR_CTS) && in snd_uart16550_io_loop()
247 uart->buff_in_count > 0) { in snd_uart16550_io_loop()
248 snd_uart16550_buffer_output(uart); in snd_uart16550_io_loop()
249 status = inb(uart->base + UART_MSR); in snd_uart16550_io_loop()
253 while (uart->fifo_count < uart->fifo_limit /* Can we write ? */ in snd_uart16550_io_loop()
254 && uart->buff_in_count > 0) /* Do we want to? */ in snd_uart16550_io_loop()
255 snd_uart16550_buffer_output(uart); in snd_uart16550_io_loop()
257 if (uart->irq < 0 && uart->buff_in_count > 0) in snd_uart16550_io_loop()
258 snd_uart16550_add_timer(uart); in snd_uart16550_io_loop()
263 * After receiving a interrupt, it is important to indicate to the UART that
283 struct snd_uart16550 *uart; in snd_uart16550_interrupt() local
285 uart = dev_id; in snd_uart16550_interrupt()
286 spin_lock(&uart->open_lock); in snd_uart16550_interrupt()
287 if (uart->filemode == SERIAL_MODE_NOT_OPENED) { in snd_uart16550_interrupt()
288 spin_unlock(&uart->open_lock); in snd_uart16550_interrupt()
291 /* indicate to the UART that the interrupt has been serviced */ in snd_uart16550_interrupt()
292 inb(uart->base + UART_IIR); in snd_uart16550_interrupt()
293 snd_uart16550_io_loop(uart); in snd_uart16550_interrupt()
294 spin_unlock(&uart->open_lock); in snd_uart16550_interrupt()
302 struct snd_uart16550 *uart; in snd_uart16550_buffer_timer() local
304 uart = from_timer(uart, t, buffer_timer); in snd_uart16550_buffer_timer()
305 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_buffer_timer()
306 snd_uart16550_del_timer(uart); in snd_uart16550_buffer_timer()
307 snd_uart16550_io_loop(uart); in snd_uart16550_buffer_timer()
308 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_buffer_timer()
312 * this method probes, if an uart sits on given port
316 static int snd_uart16550_detect(struct snd_uart16550 *uart) in snd_uart16550_detect() argument
318 unsigned long io_base = uart->base; in snd_uart16550_detect()
322 /* Do some vague tests for the presence of the uart */ in snd_uart16550_detect()
327 uart->res_base = request_region(io_base, 8, "Serial MIDI"); in snd_uart16550_detect()
328 if (uart->res_base == NULL) { in snd_uart16550_detect()
333 /* uart detected unless one of the following tests should fail */ in snd_uart16550_detect()
359 static void snd_uart16550_do_open(struct snd_uart16550 * uart) in snd_uart16550_do_open() argument
364 uart->buff_in_count = 0; in snd_uart16550_do_open()
365 uart->buff_in = 0; in snd_uart16550_do_open()
366 uart->buff_out = 0; in snd_uart16550_do_open()
367 uart->fifo_limit = 1; in snd_uart16550_do_open()
368 uart->fifo_count = 0; in snd_uart16550_do_open()
369 uart->timer_running = 0; in snd_uart16550_do_open()
378 ,uart->base + UART_FCR); /* FIFO Control Register */ in snd_uart16550_do_open()
380 if ((inb(uart->base + UART_IIR) & 0xf0) == 0xc0) in snd_uart16550_do_open()
381 uart->fifo_limit = 16; in snd_uart16550_do_open()
382 if (uart->divisor != 0) { in snd_uart16550_do_open()
383 uart->old_line_ctrl_reg = inb(uart->base + UART_LCR); in snd_uart16550_do_open()
385 ,uart->base + UART_LCR); /* Line Control Register */ in snd_uart16550_do_open()
386 uart->old_divisor_lsb = inb(uart->base + UART_DLL); in snd_uart16550_do_open()
387 uart->old_divisor_msb = inb(uart->base + UART_DLM); in snd_uart16550_do_open()
389 outb(uart->divisor in snd_uart16550_do_open()
390 ,uart->base + UART_DLL); /* Divisor Latch Low */ in snd_uart16550_do_open()
392 ,uart->base + UART_DLM); /* Divisor Latch High */ in snd_uart16550_do_open()
400 ,uart->base + UART_LCR); /* Line Control Register */ in snd_uart16550_do_open()
402 switch (uart->adaptor) { in snd_uart16550_do_open()
409 ,uart->base + UART_MCR); /* Modem Control Register */ in snd_uart16550_do_open()
416 uart->base + UART_MCR); in snd_uart16550_do_open()
422 uart->base + UART_MCR); in snd_uart16550_do_open()
426 if (uart->irq < 0) { in snd_uart16550_do_open()
430 } else if (uart->adaptor == SNDRV_SERIAL_MS124W_SA) { in snd_uart16550_do_open()
434 } else if (uart->adaptor == SNDRV_SERIAL_GENERIC) { in snd_uart16550_do_open()
444 outb(byte, uart->base + UART_IER); /* Interrupt enable Register */ in snd_uart16550_do_open()
446 inb(uart->base + UART_LSR); /* Clear any pre-existing overrun indication */ in snd_uart16550_do_open()
447 inb(uart->base + UART_IIR); /* Clear any pre-existing transmit interrupt */ in snd_uart16550_do_open()
448 inb(uart->base + UART_RX); /* Clear any pre-existing receive interrupt */ in snd_uart16550_do_open()
451 static void snd_uart16550_do_close(struct snd_uart16550 * uart) in snd_uart16550_do_close() argument
453 if (uart->irq < 0) in snd_uart16550_do_close()
454 snd_uart16550_del_timer(uart); in snd_uart16550_do_close()
462 ,uart->base + UART_IER); /* Interrupt enable Register */ in snd_uart16550_do_close()
464 switch (uart->adaptor) { in snd_uart16550_do_close()
469 ,uart->base + UART_MCR); /* Modem Control Register */ in snd_uart16550_do_close()
476 uart->base + UART_MCR); in snd_uart16550_do_close()
482 uart->base + UART_MCR); in snd_uart16550_do_close()
486 inb(uart->base + UART_IIR); /* Clear any outstanding interrupts */ in snd_uart16550_do_close()
489 if (uart->divisor != 0) { in snd_uart16550_do_close()
491 ,uart->base + UART_LCR); /* Line Control Register */ in snd_uart16550_do_close()
492 outb(uart->old_divisor_lsb in snd_uart16550_do_close()
493 ,uart->base + UART_DLL); /* Divisor Latch Low */ in snd_uart16550_do_close()
494 outb(uart->old_divisor_msb in snd_uart16550_do_close()
495 ,uart->base + UART_DLM); /* Divisor Latch High */ in snd_uart16550_do_close()
497 outb(uart->old_line_ctrl_reg in snd_uart16550_do_close()
498 ,uart->base + UART_LCR); /* Line Control Register */ in snd_uart16550_do_close()
505 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_input_open() local
507 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_input_open()
508 if (uart->filemode == SERIAL_MODE_NOT_OPENED) in snd_uart16550_input_open()
509 snd_uart16550_do_open(uart); in snd_uart16550_input_open()
510 uart->filemode |= SERIAL_MODE_INPUT_OPEN; in snd_uart16550_input_open()
511 uart->midi_input[substream->number] = substream; in snd_uart16550_input_open()
512 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_input_open()
519 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_input_close() local
521 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_input_close()
522 uart->filemode &= ~SERIAL_MODE_INPUT_OPEN; in snd_uart16550_input_close()
523 uart->midi_input[substream->number] = NULL; in snd_uart16550_input_close()
524 if (uart->filemode == SERIAL_MODE_NOT_OPENED) in snd_uart16550_input_close()
525 snd_uart16550_do_close(uart); in snd_uart16550_input_close()
526 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_input_close()
534 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_input_trigger() local
536 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_input_trigger()
538 uart->filemode |= SERIAL_MODE_INPUT_TRIGGERED; in snd_uart16550_input_trigger()
540 uart->filemode &= ~SERIAL_MODE_INPUT_TRIGGERED; in snd_uart16550_input_trigger()
541 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_input_trigger()
547 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_output_open() local
549 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_output_open()
550 if (uart->filemode == SERIAL_MODE_NOT_OPENED) in snd_uart16550_output_open()
551 snd_uart16550_do_open(uart); in snd_uart16550_output_open()
552 uart->filemode |= SERIAL_MODE_OUTPUT_OPEN; in snd_uart16550_output_open()
553 uart->midi_output[substream->number] = substream; in snd_uart16550_output_open()
554 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_output_open()
561 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_output_close() local
563 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_output_close()
564 uart->filemode &= ~SERIAL_MODE_OUTPUT_OPEN; in snd_uart16550_output_close()
565 uart->midi_output[substream->number] = NULL; in snd_uart16550_output_close()
566 if (uart->filemode == SERIAL_MODE_NOT_OPENED) in snd_uart16550_output_close()
567 snd_uart16550_do_close(uart); in snd_uart16550_output_close()
568 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_output_close()
572 static inline int snd_uart16550_buffer_can_write(struct snd_uart16550 *uart, in snd_uart16550_buffer_can_write() argument
575 if (uart->buff_in_count + Num < TX_BUFF_SIZE) in snd_uart16550_buffer_can_write()
581 static inline int snd_uart16550_write_buffer(struct snd_uart16550 *uart, in snd_uart16550_write_buffer() argument
584 unsigned short buff_in = uart->buff_in; in snd_uart16550_write_buffer()
585 if (uart->buff_in_count < TX_BUFF_SIZE) { in snd_uart16550_write_buffer()
586 uart->tx_buff[buff_in] = byte; in snd_uart16550_write_buffer()
589 uart->buff_in = buff_in; in snd_uart16550_write_buffer()
590 uart->buff_in_count++; in snd_uart16550_write_buffer()
591 if (uart->irq < 0) /* polling mode */ in snd_uart16550_write_buffer()
592 snd_uart16550_add_timer(uart); in snd_uart16550_write_buffer()
598 static int snd_uart16550_output_byte(struct snd_uart16550 *uart, in snd_uart16550_output_byte() argument
602 if (uart->buff_in_count == 0 /* Buffer empty? */ in snd_uart16550_output_byte()
603 && ((uart->adaptor != SNDRV_SERIAL_MS124W_SA && in snd_uart16550_output_byte()
604 uart->adaptor != SNDRV_SERIAL_GENERIC) || in snd_uart16550_output_byte()
605 (uart->fifo_count == 0 /* FIFO empty? */ in snd_uart16550_output_byte()
606 && (inb(uart->base + UART_MSR) & UART_MSR_CTS)))) { /* CTS? */ in snd_uart16550_output_byte()
609 if ((inb(uart->base + UART_LSR) & UART_LSR_THRE) != 0) { in snd_uart16550_output_byte()
611 uart->fifo_count = 1; in snd_uart16550_output_byte()
612 outb(midi_byte, uart->base + UART_TX); in snd_uart16550_output_byte()
614 if (uart->fifo_count < uart->fifo_limit) { in snd_uart16550_output_byte()
615 uart->fifo_count++; in snd_uart16550_output_byte()
616 outb(midi_byte, uart->base + UART_TX); in snd_uart16550_output_byte()
620 snd_uart16550_write_buffer(uart, midi_byte); in snd_uart16550_output_byte()
624 if (!snd_uart16550_write_buffer(uart, midi_byte)) { in snd_uart16550_output_byte()
627 uart->rmidi->name, uart->base); in snd_uart16550_output_byte()
639 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_output_write() local
648 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_output_write()
650 if (uart->irq < 0) /* polling */ in snd_uart16550_output_write()
651 snd_uart16550_io_loop(uart); in snd_uart16550_output_write()
653 if (uart->adaptor == SNDRV_SERIAL_MS124W_MB) { in snd_uart16550_output_write()
657 if (uart->buff_in_count > TX_BUFF_SIZE - 2) in snd_uart16550_output_write()
671 snd_uart16550_output_byte(uart, substream, addr_byte); in snd_uart16550_output_write()
673 snd_uart16550_output_byte(uart, substream, midi_byte); in snd_uart16550_output_write()
681 (uart->adaptor == SNDRV_SERIAL_SOUNDCANVAS || in snd_uart16550_output_write()
682 uart->adaptor == SNDRV_SERIAL_GENERIC) && in snd_uart16550_output_write()
683 (uart->prev_out != substream->number || in snd_uart16550_output_write()
686 if (snd_uart16550_buffer_can_write(uart, 3)) { in snd_uart16550_output_write()
690 * in this uart, send the change part in snd_uart16550_output_write()
693 uart->prev_out = substream->number; in snd_uart16550_output_write()
695 snd_uart16550_output_byte(uart, substream, in snd_uart16550_output_write()
698 snd_uart16550_output_byte(uart, substream, in snd_uart16550_output_write()
699 uart->prev_out + 1); in snd_uart16550_output_write()
703 uart->adaptor == SNDRV_SERIAL_SOUNDCANVAS) in snd_uart16550_output_write()
704 snd_uart16550_output_byte(uart, substream, uart->prev_status[uart->prev_out]); in snd_uart16550_output_write()
705 } else if (!uart->drop_on_full) in snd_uart16550_output_write()
711 if (!snd_uart16550_output_byte(uart, substream, midi_byte) && in snd_uart16550_output_write()
712 !uart->drop_on_full ) in snd_uart16550_output_write()
716 uart->prev_status[uart->prev_out] = midi_byte; in snd_uart16550_output_write()
723 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_output_write()
730 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_output_trigger() local
732 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_output_trigger()
734 uart->filemode |= SERIAL_MODE_OUTPUT_TRIGGERED; in snd_uart16550_output_trigger()
736 uart->filemode &= ~SERIAL_MODE_OUTPUT_TRIGGERED; in snd_uart16550_output_trigger()
737 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_output_trigger()
756 static int snd_uart16550_free(struct snd_uart16550 *uart) in snd_uart16550_free() argument
758 if (uart->irq >= 0) in snd_uart16550_free()
759 free_irq(uart->irq, uart); in snd_uart16550_free()
760 release_and_free_resource(uart->res_base); in snd_uart16550_free()
761 kfree(uart); in snd_uart16550_free()
767 struct snd_uart16550 *uart = device->device_data; in snd_uart16550_dev_free() local
768 return snd_uart16550_free(uart); in snd_uart16550_dev_free()
783 struct snd_uart16550 *uart; in snd_uart16550_create() local
787 if ((uart = kzalloc(sizeof(*uart), GFP_KERNEL)) == NULL) in snd_uart16550_create()
789 uart->adaptor = adaptor; in snd_uart16550_create()
790 uart->card = card; in snd_uart16550_create()
791 spin_lock_init(&uart->open_lock); in snd_uart16550_create()
792 uart->irq = -1; in snd_uart16550_create()
793 uart->base = iobase; in snd_uart16550_create()
794 uart->drop_on_full = droponfull; in snd_uart16550_create()
796 if ((err = snd_uart16550_detect(uart)) <= 0) { in snd_uart16550_create()
797 printk(KERN_ERR "no UART detected at 0x%lx\n", iobase); in snd_uart16550_create()
798 snd_uart16550_free(uart); in snd_uart16550_create()
804 0, "Serial MIDI", uart)) { in snd_uart16550_create()
808 uart->irq = irq; in snd_uart16550_create()
811 uart->divisor = base / speed; in snd_uart16550_create()
812 uart->speed = base / (unsigned int)uart->divisor; in snd_uart16550_create()
813 uart->speed_base = base; in snd_uart16550_create()
814 uart->prev_out = -1; in snd_uart16550_create()
815 uart->prev_in = 0; in snd_uart16550_create()
816 uart->rstatus = 0; in snd_uart16550_create()
817 memset(uart->prev_status, 0x80, sizeof(unsigned char) * SNDRV_SERIAL_MAX_OUTS); in snd_uart16550_create()
818 timer_setup(&uart->buffer_timer, snd_uart16550_buffer_timer, 0); in snd_uart16550_create()
819 uart->timer_running = 0; in snd_uart16550_create()
822 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, uart, &ops)) < 0) { in snd_uart16550_create()
823 snd_uart16550_free(uart); in snd_uart16550_create()
827 switch (uart->adaptor) { in snd_uart16550_create()
832 outb(UART_MCR_RTS | (0&UART_MCR_DTR), uart->base + UART_MCR); in snd_uart16550_create()
837 outb(UART_MCR_RTS | UART_MCR_DTR, uart->base + UART_MCR); in snd_uart16550_create()
844 *ruart = uart; in snd_uart16550_create()
858 static int snd_uart16550_rmidi(struct snd_uart16550 *uart, int device, in snd_uart16550_rmidi() argument
865 err = snd_rawmidi_new(uart->card, "UART Serial MIDI", device, in snd_uart16550_rmidi()
879 rrawmidi->private_data = uart; in snd_uart16550_rmidi()
888 struct snd_uart16550 *uart; in snd_serial_probe() local
943 &uart)) < 0) in snd_serial_probe()
946 err = snd_uart16550_rmidi(uart, 0, outs[dev], ins[dev], &uart->rmidi); in snd_serial_probe()
952 adaptor_names[uart->adaptor], in snd_serial_probe()
953 uart->base, in snd_serial_probe()
954 uart->irq); in snd_serial_probe()