Lines Matching refs:uart
157 static inline void snd_uart16550_add_timer(struct snd_uart16550 *uart) in snd_uart16550_add_timer() argument
159 if (!uart->timer_running) { in snd_uart16550_add_timer()
161 mod_timer(&uart->buffer_timer, jiffies + (HZ + 255) / 256); in snd_uart16550_add_timer()
162 uart->timer_running = 1; in snd_uart16550_add_timer()
166 static inline void snd_uart16550_del_timer(struct snd_uart16550 *uart) in snd_uart16550_del_timer() argument
168 if (uart->timer_running) { in snd_uart16550_del_timer()
169 del_timer(&uart->buffer_timer); in snd_uart16550_del_timer()
170 uart->timer_running = 0; in snd_uart16550_del_timer()
175 static inline void snd_uart16550_buffer_output(struct snd_uart16550 *uart) in snd_uart16550_buffer_output() argument
177 unsigned short buff_out = uart->buff_out; in snd_uart16550_buffer_output()
178 if (uart->buff_in_count > 0) { in snd_uart16550_buffer_output()
179 outb(uart->tx_buff[buff_out], uart->base + UART_TX); in snd_uart16550_buffer_output()
180 uart->fifo_count++; in snd_uart16550_buffer_output()
183 uart->buff_out = buff_out; in snd_uart16550_buffer_output()
184 uart->buff_in_count--; in snd_uart16550_buffer_output()
192 static void snd_uart16550_io_loop(struct snd_uart16550 * uart) in snd_uart16550_io_loop() argument
198 substream = uart->prev_in; in snd_uart16550_io_loop()
201 while ((status = inb(uart->base + UART_LSR)) & UART_LSR_DR) { in snd_uart16550_io_loop()
203 c = inb(uart->base + UART_RX); in snd_uart16550_io_loop()
207 uart->rstatus = c; in snd_uart16550_io_loop()
210 if (uart->adaptor == SNDRV_SERIAL_GENERIC) { in snd_uart16550_io_loop()
211 if (uart->rstatus == 0xf5) { in snd_uart16550_io_loop()
217 uart->rstatus = 0; in snd_uart16550_io_loop()
218 } else if ((uart->filemode & SERIAL_MODE_INPUT_OPEN) in snd_uart16550_io_loop()
219 && uart->midi_input[substream]) in snd_uart16550_io_loop()
220 snd_rawmidi_receive(uart->midi_input[substream], in snd_uart16550_io_loop()
222 } else if ((uart->filemode & SERIAL_MODE_INPUT_OPEN) && in snd_uart16550_io_loop()
223 uart->midi_input[substream]) in snd_uart16550_io_loop()
224 snd_rawmidi_receive(uart->midi_input[substream], &c, 1); in snd_uart16550_io_loop()
227 dev_warn(uart->card->dev, in snd_uart16550_io_loop()
229 uart->rmidi->name, uart->base); in snd_uart16550_io_loop()
233 uart->prev_in = substream; in snd_uart16550_io_loop()
239 uart->fifo_count = 0; in snd_uart16550_io_loop()
240 if (uart->adaptor == SNDRV_SERIAL_MS124W_SA in snd_uart16550_io_loop()
241 || uart->adaptor == SNDRV_SERIAL_GENERIC) { in snd_uart16550_io_loop()
243 status = inb(uart->base + UART_MSR); in snd_uart16550_io_loop()
244 while (uart->fifo_count == 0 && (status & UART_MSR_CTS) && in snd_uart16550_io_loop()
245 uart->buff_in_count > 0) { in snd_uart16550_io_loop()
246 snd_uart16550_buffer_output(uart); in snd_uart16550_io_loop()
247 status = inb(uart->base + UART_MSR); in snd_uart16550_io_loop()
251 while (uart->fifo_count < uart->fifo_limit /* Can we write ? */ in snd_uart16550_io_loop()
252 && uart->buff_in_count > 0) /* Do we want to? */ in snd_uart16550_io_loop()
253 snd_uart16550_buffer_output(uart); in snd_uart16550_io_loop()
255 if (uart->irq < 0 && uart->buff_in_count > 0) in snd_uart16550_io_loop()
256 snd_uart16550_add_timer(uart); in snd_uart16550_io_loop()
281 struct snd_uart16550 *uart; in snd_uart16550_interrupt() local
283 uart = dev_id; in snd_uart16550_interrupt()
284 spin_lock(&uart->open_lock); in snd_uart16550_interrupt()
285 if (uart->filemode == SERIAL_MODE_NOT_OPENED) { in snd_uart16550_interrupt()
286 spin_unlock(&uart->open_lock); in snd_uart16550_interrupt()
290 inb(uart->base + UART_IIR); in snd_uart16550_interrupt()
291 snd_uart16550_io_loop(uart); in snd_uart16550_interrupt()
292 spin_unlock(&uart->open_lock); in snd_uart16550_interrupt()
300 struct snd_uart16550 *uart; in snd_uart16550_buffer_timer() local
302 uart = from_timer(uart, t, buffer_timer); in snd_uart16550_buffer_timer()
303 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_buffer_timer()
304 snd_uart16550_del_timer(uart); in snd_uart16550_buffer_timer()
305 snd_uart16550_io_loop(uart); in snd_uart16550_buffer_timer()
306 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_buffer_timer()
314 static int snd_uart16550_detect(struct snd_uart16550 *uart) in snd_uart16550_detect() argument
316 unsigned long io_base = uart->base; in snd_uart16550_detect()
325 if (!devm_request_region(uart->card->dev, io_base, 8, "Serial MIDI")) { in snd_uart16550_detect()
326 dev_err(uart->card->dev, in snd_uart16550_detect()
357 static void snd_uart16550_do_open(struct snd_uart16550 * uart) in snd_uart16550_do_open() argument
362 uart->buff_in_count = 0; in snd_uart16550_do_open()
363 uart->buff_in = 0; in snd_uart16550_do_open()
364 uart->buff_out = 0; in snd_uart16550_do_open()
365 uart->fifo_limit = 1; in snd_uart16550_do_open()
366 uart->fifo_count = 0; in snd_uart16550_do_open()
367 uart->timer_running = 0; in snd_uart16550_do_open()
376 ,uart->base + UART_FCR); /* FIFO Control Register */ in snd_uart16550_do_open()
378 if ((inb(uart->base + UART_IIR) & 0xf0) == 0xc0) in snd_uart16550_do_open()
379 uart->fifo_limit = 16; in snd_uart16550_do_open()
380 if (uart->divisor != 0) { in snd_uart16550_do_open()
381 uart->old_line_ctrl_reg = inb(uart->base + UART_LCR); in snd_uart16550_do_open()
383 ,uart->base + UART_LCR); /* Line Control Register */ in snd_uart16550_do_open()
384 uart->old_divisor_lsb = inb(uart->base + UART_DLL); in snd_uart16550_do_open()
385 uart->old_divisor_msb = inb(uart->base + UART_DLM); in snd_uart16550_do_open()
387 outb(uart->divisor in snd_uart16550_do_open()
388 ,uart->base + UART_DLL); /* Divisor Latch Low */ in snd_uart16550_do_open()
390 ,uart->base + UART_DLM); /* Divisor Latch High */ in snd_uart16550_do_open()
398 ,uart->base + UART_LCR); /* Line Control Register */ in snd_uart16550_do_open()
400 switch (uart->adaptor) { in snd_uart16550_do_open()
407 ,uart->base + UART_MCR); /* Modem Control Register */ in snd_uart16550_do_open()
414 uart->base + UART_MCR); in snd_uart16550_do_open()
420 uart->base + UART_MCR); in snd_uart16550_do_open()
424 if (uart->irq < 0) { in snd_uart16550_do_open()
428 } else if (uart->adaptor == SNDRV_SERIAL_MS124W_SA) { in snd_uart16550_do_open()
432 } else if (uart->adaptor == SNDRV_SERIAL_GENERIC) { in snd_uart16550_do_open()
442 outb(byte, uart->base + UART_IER); /* Interrupt enable Register */ in snd_uart16550_do_open()
444 inb(uart->base + UART_LSR); /* Clear any pre-existing overrun indication */ in snd_uart16550_do_open()
445 inb(uart->base + UART_IIR); /* Clear any pre-existing transmit interrupt */ in snd_uart16550_do_open()
446 inb(uart->base + UART_RX); /* Clear any pre-existing receive interrupt */ in snd_uart16550_do_open()
449 static void snd_uart16550_do_close(struct snd_uart16550 * uart) in snd_uart16550_do_close() argument
451 if (uart->irq < 0) in snd_uart16550_do_close()
452 snd_uart16550_del_timer(uart); in snd_uart16550_do_close()
460 ,uart->base + UART_IER); /* Interrupt enable Register */ in snd_uart16550_do_close()
462 switch (uart->adaptor) { in snd_uart16550_do_close()
467 ,uart->base + UART_MCR); /* Modem Control Register */ in snd_uart16550_do_close()
474 uart->base + UART_MCR); in snd_uart16550_do_close()
480 uart->base + UART_MCR); in snd_uart16550_do_close()
484 inb(uart->base + UART_IIR); /* Clear any outstanding interrupts */ in snd_uart16550_do_close()
487 if (uart->divisor != 0) { in snd_uart16550_do_close()
489 ,uart->base + UART_LCR); /* Line Control Register */ in snd_uart16550_do_close()
490 outb(uart->old_divisor_lsb in snd_uart16550_do_close()
491 ,uart->base + UART_DLL); /* Divisor Latch Low */ in snd_uart16550_do_close()
492 outb(uart->old_divisor_msb in snd_uart16550_do_close()
493 ,uart->base + UART_DLM); /* Divisor Latch High */ in snd_uart16550_do_close()
495 outb(uart->old_line_ctrl_reg in snd_uart16550_do_close()
496 ,uart->base + UART_LCR); /* Line Control Register */ in snd_uart16550_do_close()
503 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_input_open() local
505 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_input_open()
506 if (uart->filemode == SERIAL_MODE_NOT_OPENED) in snd_uart16550_input_open()
507 snd_uart16550_do_open(uart); in snd_uart16550_input_open()
508 uart->filemode |= SERIAL_MODE_INPUT_OPEN; in snd_uart16550_input_open()
509 uart->midi_input[substream->number] = substream; in snd_uart16550_input_open()
510 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_input_open()
517 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_input_close() local
519 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_input_close()
520 uart->filemode &= ~SERIAL_MODE_INPUT_OPEN; in snd_uart16550_input_close()
521 uart->midi_input[substream->number] = NULL; in snd_uart16550_input_close()
522 if (uart->filemode == SERIAL_MODE_NOT_OPENED) in snd_uart16550_input_close()
523 snd_uart16550_do_close(uart); in snd_uart16550_input_close()
524 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_input_close()
532 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_input_trigger() local
534 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_input_trigger()
536 uart->filemode |= SERIAL_MODE_INPUT_TRIGGERED; in snd_uart16550_input_trigger()
538 uart->filemode &= ~SERIAL_MODE_INPUT_TRIGGERED; in snd_uart16550_input_trigger()
539 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_input_trigger()
545 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_output_open() local
547 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_output_open()
548 if (uart->filemode == SERIAL_MODE_NOT_OPENED) in snd_uart16550_output_open()
549 snd_uart16550_do_open(uart); in snd_uart16550_output_open()
550 uart->filemode |= SERIAL_MODE_OUTPUT_OPEN; in snd_uart16550_output_open()
551 uart->midi_output[substream->number] = substream; in snd_uart16550_output_open()
552 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_output_open()
559 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_output_close() local
561 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_output_close()
562 uart->filemode &= ~SERIAL_MODE_OUTPUT_OPEN; in snd_uart16550_output_close()
563 uart->midi_output[substream->number] = NULL; in snd_uart16550_output_close()
564 if (uart->filemode == SERIAL_MODE_NOT_OPENED) in snd_uart16550_output_close()
565 snd_uart16550_do_close(uart); in snd_uart16550_output_close()
566 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_output_close()
570 static inline int snd_uart16550_buffer_can_write(struct snd_uart16550 *uart, in snd_uart16550_buffer_can_write() argument
573 if (uart->buff_in_count + Num < TX_BUFF_SIZE) in snd_uart16550_buffer_can_write()
579 static inline int snd_uart16550_write_buffer(struct snd_uart16550 *uart, in snd_uart16550_write_buffer() argument
582 unsigned short buff_in = uart->buff_in; in snd_uart16550_write_buffer()
583 if (uart->buff_in_count < TX_BUFF_SIZE) { in snd_uart16550_write_buffer()
584 uart->tx_buff[buff_in] = byte; in snd_uart16550_write_buffer()
587 uart->buff_in = buff_in; in snd_uart16550_write_buffer()
588 uart->buff_in_count++; in snd_uart16550_write_buffer()
589 if (uart->irq < 0) /* polling mode */ in snd_uart16550_write_buffer()
590 snd_uart16550_add_timer(uart); in snd_uart16550_write_buffer()
596 static int snd_uart16550_output_byte(struct snd_uart16550 *uart, in snd_uart16550_output_byte() argument
600 if (uart->buff_in_count == 0 /* Buffer empty? */ in snd_uart16550_output_byte()
601 && ((uart->adaptor != SNDRV_SERIAL_MS124W_SA && in snd_uart16550_output_byte()
602 uart->adaptor != SNDRV_SERIAL_GENERIC) || in snd_uart16550_output_byte()
603 (uart->fifo_count == 0 /* FIFO empty? */ in snd_uart16550_output_byte()
604 && (inb(uart->base + UART_MSR) & UART_MSR_CTS)))) { /* CTS? */ in snd_uart16550_output_byte()
607 if ((inb(uart->base + UART_LSR) & UART_LSR_THRE) != 0) { in snd_uart16550_output_byte()
609 uart->fifo_count = 1; in snd_uart16550_output_byte()
610 outb(midi_byte, uart->base + UART_TX); in snd_uart16550_output_byte()
612 if (uart->fifo_count < uart->fifo_limit) { in snd_uart16550_output_byte()
613 uart->fifo_count++; in snd_uart16550_output_byte()
614 outb(midi_byte, uart->base + UART_TX); in snd_uart16550_output_byte()
618 snd_uart16550_write_buffer(uart, midi_byte); in snd_uart16550_output_byte()
622 if (!snd_uart16550_write_buffer(uart, midi_byte)) { in snd_uart16550_output_byte()
623 dev_warn(uart->card->dev, in snd_uart16550_output_byte()
625 uart->rmidi->name, uart->base); in snd_uart16550_output_byte()
637 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_output_write() local
646 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_output_write()
648 if (uart->irq < 0) /* polling */ in snd_uart16550_output_write()
649 snd_uart16550_io_loop(uart); in snd_uart16550_output_write()
651 if (uart->adaptor == SNDRV_SERIAL_MS124W_MB) { in snd_uart16550_output_write()
655 if (uart->buff_in_count > TX_BUFF_SIZE - 2) in snd_uart16550_output_write()
669 snd_uart16550_output_byte(uart, substream, addr_byte); in snd_uart16550_output_write()
671 snd_uart16550_output_byte(uart, substream, midi_byte); in snd_uart16550_output_write()
679 (uart->adaptor == SNDRV_SERIAL_SOUNDCANVAS || in snd_uart16550_output_write()
680 uart->adaptor == SNDRV_SERIAL_GENERIC) && in snd_uart16550_output_write()
681 (uart->prev_out != substream->number || in snd_uart16550_output_write()
684 if (snd_uart16550_buffer_can_write(uart, 3)) { in snd_uart16550_output_write()
691 uart->prev_out = substream->number; in snd_uart16550_output_write()
693 snd_uart16550_output_byte(uart, substream, in snd_uart16550_output_write()
696 snd_uart16550_output_byte(uart, substream, in snd_uart16550_output_write()
697 uart->prev_out + 1); in snd_uart16550_output_write()
701 uart->adaptor == SNDRV_SERIAL_SOUNDCANVAS) in snd_uart16550_output_write()
702 snd_uart16550_output_byte(uart, substream, uart->prev_status[uart->prev_out]); in snd_uart16550_output_write()
703 } else if (!uart->drop_on_full) in snd_uart16550_output_write()
709 if (!snd_uart16550_output_byte(uart, substream, midi_byte) && in snd_uart16550_output_write()
710 !uart->drop_on_full ) in snd_uart16550_output_write()
714 uart->prev_status[uart->prev_out] = midi_byte; in snd_uart16550_output_write()
721 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_output_write()
728 struct snd_uart16550 *uart = substream->rmidi->private_data; in snd_uart16550_output_trigger() local
730 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_output_trigger()
732 uart->filemode |= SERIAL_MODE_OUTPUT_TRIGGERED; in snd_uart16550_output_trigger()
734 uart->filemode &= ~SERIAL_MODE_OUTPUT_TRIGGERED; in snd_uart16550_output_trigger()
735 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_output_trigger()
763 struct snd_uart16550 *uart; in snd_uart16550_create() local
767 uart = devm_kzalloc(card->dev, sizeof(*uart), GFP_KERNEL); in snd_uart16550_create()
768 if (!uart) in snd_uart16550_create()
770 uart->adaptor = adaptor; in snd_uart16550_create()
771 uart->card = card; in snd_uart16550_create()
772 spin_lock_init(&uart->open_lock); in snd_uart16550_create()
773 uart->irq = -1; in snd_uart16550_create()
774 uart->base = iobase; in snd_uart16550_create()
775 uart->drop_on_full = droponfull; in snd_uart16550_create()
777 err = snd_uart16550_detect(uart); in snd_uart16550_create()
785 0, "Serial MIDI", uart)) { in snd_uart16550_create()
789 uart->irq = irq; in snd_uart16550_create()
792 uart->divisor = base / speed; in snd_uart16550_create()
793 uart->speed = base / (unsigned int)uart->divisor; in snd_uart16550_create()
794 uart->speed_base = base; in snd_uart16550_create()
795 uart->prev_out = -1; in snd_uart16550_create()
796 uart->prev_in = 0; in snd_uart16550_create()
797 uart->rstatus = 0; in snd_uart16550_create()
798 memset(uart->prev_status, 0x80, sizeof(unsigned char) * SNDRV_SERIAL_MAX_OUTS); in snd_uart16550_create()
799 timer_setup(&uart->buffer_timer, snd_uart16550_buffer_timer, 0); in snd_uart16550_create()
800 uart->timer_running = 0; in snd_uart16550_create()
802 switch (uart->adaptor) { in snd_uart16550_create()
807 outb(UART_MCR_RTS | (0&UART_MCR_DTR), uart->base + UART_MCR); in snd_uart16550_create()
812 outb(UART_MCR_RTS | UART_MCR_DTR, uart->base + UART_MCR); in snd_uart16550_create()
819 *ruart = uart; in snd_uart16550_create()
833 static int snd_uart16550_rmidi(struct snd_uart16550 *uart, int device, in snd_uart16550_rmidi() argument
840 err = snd_rawmidi_new(uart->card, "UART Serial MIDI", device, in snd_uart16550_rmidi()
854 rrawmidi->private_data = uart; in snd_uart16550_rmidi()
863 struct snd_uart16550 *uart; in snd_serial_probe() local
913 &uart); in snd_serial_probe()
917 err = snd_uart16550_rmidi(uart, 0, outs[dev], ins[dev], &uart->rmidi); in snd_serial_probe()
923 adaptor_names[uart->adaptor], in snd_serial_probe()
924 uart->base, in snd_serial_probe()
925 uart->irq); in snd_serial_probe()