Lines Matching +full:modem +full:- +full:control +full:- +full:line +full:- +full:ports
1 // SPDX-License-Identifier: GPL-2.0-or-later
12 * Added support for the Midiator MS-124T and for the MS-124W in
17 * More documentation can be found in serial-u16550.txt.
39 #define SNDRV_SERIAL_MS124T 1 /* Midiator MS-124T */
40 #define SNDRV_SERIAL_MS124W_SA 2 /* Midiator MS-124W in S/A mode */
41 #define SNDRV_SERIAL_MS124W_MB 3 /* Midiator MS-124W in M/B mode */
46 "MS-124T",
47 "MS-124W S/A",
48 "MS-124W M/B",
53 #define SNDRV_SERIAL_DROPBUFF 1 /* Non-blocking discard operation */
55 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
60 static int speed[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 38400}; /* 9600,19200,38400,57600,1152…
61 static int base[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 115200}; /* baud base */
62 static int outs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; /* 1 to 16 */
63 static int ins[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; /* 1 to 16 */
64 static int adaptor[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = SNDRV_SERIAL_SOUNDCANVAS};
65 static bool droponfull[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS -1)] = SNDRV_SERIAL_NORMALBUFF };
86 MODULE_PARM_DESC(droponfull, "Flag to enable drop-on-full buffer mode");
91 /*#define SNDRV_SERIAL_MS124W_MB_NOCOMBO 1*/ /* Address outs as 0-3 instead of bitmap */
97 #define TX_BUFF_MASK (TX_BUFF_SIZE - 1)
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()
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()
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()
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()
213 substream = c - 1; 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()
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()
255 if (uart->irq < 0 && uart->buff_in_count > 0) in snd_uart16550_io_loop()
260 * ---------------------------
277 * interrupts at all. (Possibly tied to an internal pull-up on CTS?)
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()
292 spin_unlock(&uart->open_lock); in snd_uart16550_interrupt()
303 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_buffer_timer()
306 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_buffer_timer()
316 unsigned long io_base = uart->base; in snd_uart16550_detect()
322 return -ENODEV; /* Not configured */ 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()
328 return -EBUSY; in snd_uart16550_detect()
333 /* 8 data-bits, 1 stop-bit, parity off, DLAB = 0 */ in snd_uart16550_detect()
334 outb(UART_LCR_WLEN8, io_base + UART_LCR); /* Line Control Register */ in snd_uart16550_detect()
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()
372 | UART_FCR_TRIGGER_4 /* Set FIFO trigger at 4-bytes */ in snd_uart16550_do_open()
373 /* NOTE: interrupt generated after T=(time)4-bytes 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()
394 outb(UART_LCR_WLEN8 /* 8 data-bits */ in snd_uart16550_do_open()
395 | 0 /* 1 stop-bit */ 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()
402 outb(UART_MCR_RTS /* Set Request-To-Send line active */ in snd_uart16550_do_open()
403 | UART_MCR_DTR /* Set Data-Terminal-Ready line active */ in snd_uart16550_do_open()
404 | UART_MCR_OUT2 /* Set OUT2 - not always required, but when in snd_uart16550_do_open()
407 ,uart->base + UART_MCR); /* Modem Control Register */ in snd_uart16550_do_open()
411 /* MS-124W can draw power from RTS and DTR if they in snd_uart16550_do_open()
414 uart->base + UART_MCR); in snd_uart16550_do_open()
417 /* MS-124T can draw power from RTS and/or DTR (preferably 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()
430 | UART_IER_MSI /* Enable Modem status interrupt */ in snd_uart16550_do_open()
432 } else if (uart->adaptor == SNDRV_SERIAL_GENERIC) { in snd_uart16550_do_open()
434 | UART_IER_MSI /* Enable Modem status interrupt */ 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()
451 if (uart->irq < 0) in snd_uart16550_do_close()
454 /* NOTE: may need to disable interrupts before de-registering out handler. 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()
464 outb((0 & UART_MCR_RTS) /* Deactivate Request-To-Send line */ in snd_uart16550_do_close()
465 |(0 & UART_MCR_DTR) /* Deactivate Data-Terminal-Ready line */ in snd_uart16550_do_close()
467 ,uart->base + UART_MCR); /* Modem Control Register */ in snd_uart16550_do_close()
471 /* MS-124W can draw power from RTS and DTR if they in snd_uart16550_do_close()
474 uart->base + UART_MCR); in snd_uart16550_do_close()
477 /* MS-124T can draw power from RTS and/or DTR (preferably 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()
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()
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()
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()
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()
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()
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()
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()
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()
566 spin_unlock_irqrestore(&uart->open_lock, flags); in snd_uart16550_output_close()
573 if (uart->buff_in_count + Num < TX_BUFF_SIZE) in snd_uart16550_buffer_can_write()
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()
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()
606 /* Tx Buffer Empty - try to write immediately */ 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()
616 /* Cannot write (buffer empty) - 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()
646 spin_lock_irqsave(&uart->open_lock, flags); in snd_uart16550_output_write()
648 if (uart->irq < 0) /* polling */ 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()
660 /* select exactly one of the four ports */ in snd_uart16550_output_write()
661 addr_byte = (1 << (substream->number + 4)) | 0x08; in snd_uart16550_output_write()
663 /* select any combination of the four ports */ in snd_uart16550_output_write()
664 addr_byte = (substream->number << 4) | 0x08; 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()
691 uart->prev_out = substream->number; 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()
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()
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()
767 uart = devm_kzalloc(card->dev, sizeof(*uart), GFP_KERNEL); in snd_uart16550_create()
769 return -ENOMEM; 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()
779 dev_err(card->dev, "no UART detected at 0x%lx\n", iobase); in snd_uart16550_create()
780 return -ENODEV; in snd_uart16550_create()
784 if (devm_request_irq(card->dev, irq, snd_uart16550_interrupt, in snd_uart16550_create()
786 dev_warn(card->dev, 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()
805 /* MS-124W can draw power from RTS and DTR if they in snd_uart16550_create()
807 outb(UART_MCR_RTS | (0&UART_MCR_DTR), uart->base + UART_MCR); in snd_uart16550_create()
810 /* MS-124T can draw power from RTS and/or DTR (preferably in snd_uart16550_create()
812 outb(UART_MCR_RTS | UART_MCR_DTR, uart->base + UART_MCR); in snd_uart16550_create()
828 list_for_each_entry(substream, &stream->substreams, list) { in snd_uart16550_substreams()
829 sprintf(substream->name, "Serial MIDI %d", substream->number + 1); in snd_uart16550_substreams()
840 err = snd_rawmidi_new(uart->card, "UART Serial MIDI", device, in snd_uart16550_rmidi()
848 strcpy(rrawmidi->name, "Serial MIDI"); in snd_uart16550_rmidi()
849 snd_uart16550_substreams(&rrawmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]); in snd_uart16550_rmidi()
850 snd_uart16550_substreams(&rrawmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]); in snd_uart16550_rmidi()
851 rrawmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | in snd_uart16550_rmidi()
854 rrawmidi->private_data = uart; in snd_uart16550_rmidi()
865 int dev = devptr->id; in snd_serial_probe()
883 dev_err(&devptr->dev, in snd_serial_probe()
884 "Adaptor type is out of range 0-%d (%d)\n", in snd_serial_probe()
886 return -ENODEV; in snd_serial_probe()
890 dev_err(&devptr->dev, in snd_serial_probe()
891 "Count of outputs is out of range 1-%d (%d)\n", in snd_serial_probe()
893 return -ENODEV; in snd_serial_probe()
897 dev_err(&devptr->dev, in snd_serial_probe()
898 "Count of inputs is out of range 1-%d (%d)\n", in snd_serial_probe()
900 return -ENODEV; in snd_serial_probe()
903 err = snd_devm_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE, in snd_serial_probe()
908 strcpy(card->driver, "Serial"); in snd_serial_probe()
909 strcpy(card->shortname, "Serial MIDI (UART16550A)"); in snd_serial_probe()
917 err = snd_uart16550_rmidi(uart, 0, outs[dev], ins[dev], &uart->rmidi); in snd_serial_probe()
921 sprintf(card->longname, "%s [%s] at %#lx, irq %d", in snd_serial_probe()
922 card->shortname, 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()
982 return -ENODEV; in alsa_card_serial_init()