Lines Matching +full:dsr +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0+
15 #include <linux/platform_data/sa11x0-serial.h>
29 /* We've been assigned a range on the "Low-density serial ports" major */
45 #define UART_GET_UTCR0(sport) __raw_readl((sport)->port.membase + UTCR0)
46 #define UART_GET_UTCR1(sport) __raw_readl((sport)->port.membase + UTCR1)
47 #define UART_GET_UTCR2(sport) __raw_readl((sport)->port.membase + UTCR2)
48 #define UART_GET_UTCR3(sport) __raw_readl((sport)->port.membase + UTCR3)
49 #define UART_GET_UTSR0(sport) __raw_readl((sport)->port.membase + UTSR0)
50 #define UART_GET_UTSR1(sport) __raw_readl((sport)->port.membase + UTSR1)
51 #define UART_GET_CHAR(sport) __raw_readl((sport)->port.membase + UTDR)
53 #define UART_PUT_UTCR0(sport,v) __raw_writel((v),(sport)->port.membase + UTCR0)
54 #define UART_PUT_UTCR1(sport,v) __raw_writel((v),(sport)->port.membase + UTCR1)
55 #define UART_PUT_UTCR2(sport,v) __raw_writel((v),(sport)->port.membase + UTCR2)
56 #define UART_PUT_UTCR3(sport,v) __raw_writel((v),(sport)->port.membase + UTCR3)
57 #define UART_PUT_UTSR0(sport,v) __raw_writel((v),(sport)->port.membase + UTSR0)
58 #define UART_PUT_UTSR1(sport,v) __raw_writel((v),(sport)->port.membase + UTSR1)
59 #define UART_PUT_CHAR(sport,v) __raw_writel((v),(sport)->port.membase + UTDR)
78 struct mctrl_gpios *gpios; member
88 status = sport->port.ops->get_mctrl(&sport->port); in sa1100_mctrl_check()
89 changed = status ^ sport->old_status; in sa1100_mctrl_check()
94 sport->old_status = status; in sa1100_mctrl_check()
97 sport->port.icount.rng++; in sa1100_mctrl_check()
99 sport->port.icount.dsr++; in sa1100_mctrl_check()
101 uart_handle_dcd_change(&sport->port, status & TIOCM_CAR); in sa1100_mctrl_check()
103 uart_handle_cts_change(&sport->port, status & TIOCM_CTS); in sa1100_mctrl_check()
105 wake_up_interruptible(&sport->port.state->port.delta_msr_wait); in sa1100_mctrl_check()
109 * This is our per-port timeout handler, for checking the
117 if (sport->port.state) { in sa1100_timeout()
118 spin_lock_irqsave(&sport->port.lock, flags); in sa1100_timeout()
120 spin_unlock_irqrestore(&sport->port.lock, flags); in sa1100_timeout()
122 mod_timer(&sport->timer, jiffies + MCTRL_TIMEOUT); in sa1100_timeout()
137 sport->port.read_status_mask &= ~UTSR0_TO_SM(UTSR0_TFS); in sa1100_stop_tx()
150 sport->port.read_status_mask |= UTSR0_TO_SM(UTSR0_TFS); in sa1100_start_tx()
175 mod_timer(&sport->timer, jiffies); in sa1100_enable_ms()
177 mctrl_gpio_enable_ms(sport->gpios); in sa1100_enable_ms()
190 sport->port.icount.rx++; in sa1100_rx_chars()
200 sport->port.icount.parity++; in sa1100_rx_chars()
202 sport->port.icount.frame++; in sa1100_rx_chars()
204 sport->port.icount.overrun++; in sa1100_rx_chars()
206 status &= sport->port.read_status_mask; in sa1100_rx_chars()
213 sport->port.sysrq = 0; in sa1100_rx_chars()
216 if (uart_handle_sysrq_char(&sport->port, ch)) in sa1100_rx_chars()
219 uart_insert_char(&sport->port, status, UTSR1_TO_SM(UTSR1_ROR), ch, flg); in sa1100_rx_chars()
226 spin_unlock(&sport->port.lock); in sa1100_rx_chars()
227 tty_flip_buffer_push(&sport->port.state->port); in sa1100_rx_chars()
228 spin_lock(&sport->port.lock); in sa1100_rx_chars()
233 struct circ_buf *xmit = &sport->port.state->xmit; in sa1100_tx_chars()
235 if (sport->port.x_char) { in sa1100_tx_chars()
236 UART_PUT_CHAR(sport, sport->port.x_char); in sa1100_tx_chars()
237 sport->port.icount.tx++; in sa1100_tx_chars()
238 sport->port.x_char = 0; in sa1100_tx_chars()
248 if (uart_circ_empty(xmit) || uart_tx_stopped(&sport->port)) { in sa1100_tx_chars()
249 sa1100_stop_tx(&sport->port); in sa1100_tx_chars()
258 UART_PUT_CHAR(sport, xmit->buf[xmit->tail]); in sa1100_tx_chars()
259 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in sa1100_tx_chars()
260 sport->port.icount.tx++; in sa1100_tx_chars()
266 uart_write_wakeup(&sport->port); in sa1100_tx_chars()
269 sa1100_stop_tx(&sport->port); in sa1100_tx_chars()
277 spin_lock(&sport->port.lock); in sa1100_int()
279 status &= SM_TO_UTSR0(sport->port.read_status_mask) | ~UTSR0_TFS; in sa1100_int()
293 sport->port.icount.brk++; in sa1100_int()
296 uart_handle_break(&sport->port); in sa1100_int()
303 status &= SM_TO_UTSR0(sport->port.read_status_mask) | in sa1100_int()
306 spin_unlock(&sport->port.lock); in sa1100_int()
328 mctrl_gpio_get(sport->gpios, &ret); in sa1100_get_mctrl()
338 mctrl_gpio_set(sport->gpios, mctrl); in sa1100_set_mctrl()
351 spin_lock_irqsave(&sport->port.lock, flags); in sa1100_break_ctl()
353 if (break_state == -1) in sa1100_break_ctl()
358 spin_unlock_irqrestore(&sport->port.lock, flags); in sa1100_break_ctl()
370 retval = request_irq(sport->port.irq, sa1100_int, 0, in sa1100_startup()
371 "sa11x0-uart", sport); in sa1100_startup()
378 UART_PUT_UTSR0(sport, -1); in sa1100_startup()
384 spin_lock_irq(&sport->port.lock); in sa1100_startup()
385 sa1100_enable_ms(&sport->port); in sa1100_startup()
386 spin_unlock_irq(&sport->port.lock); in sa1100_startup()
399 del_timer_sync(&sport->timer); in sa1100_shutdown()
404 free_irq(sport->port.irq, sport); in sa1100_shutdown()
420 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; in sa1100_set_termios()
425 while ((termios->c_cflag & CSIZE) != CS7 && in sa1100_set_termios()
426 (termios->c_cflag & CSIZE) != CS8) { in sa1100_set_termios()
427 termios->c_cflag &= ~CSIZE; in sa1100_set_termios()
428 termios->c_cflag |= old_csize; in sa1100_set_termios()
432 if ((termios->c_cflag & CSIZE) == CS8) in sa1100_set_termios()
437 if (termios->c_cflag & CSTOPB) in sa1100_set_termios()
439 if (termios->c_cflag & PARENB) { in sa1100_set_termios()
441 if (!(termios->c_cflag & PARODD)) in sa1100_set_termios()
448 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); in sa1100_set_termios()
451 spin_lock_irqsave(&sport->port.lock, flags); in sa1100_set_termios()
453 sport->port.read_status_mask &= UTSR0_TO_SM(UTSR0_TFS); in sa1100_set_termios()
454 sport->port.read_status_mask |= UTSR1_TO_SM(UTSR1_ROR); in sa1100_set_termios()
455 if (termios->c_iflag & INPCK) in sa1100_set_termios()
456 sport->port.read_status_mask |= in sa1100_set_termios()
458 if (termios->c_iflag & (BRKINT | PARMRK)) in sa1100_set_termios()
459 sport->port.read_status_mask |= in sa1100_set_termios()
465 sport->port.ignore_status_mask = 0; in sa1100_set_termios()
466 if (termios->c_iflag & IGNPAR) in sa1100_set_termios()
467 sport->port.ignore_status_mask |= in sa1100_set_termios()
469 if (termios->c_iflag & IGNBRK) { in sa1100_set_termios()
470 sport->port.ignore_status_mask |= in sa1100_set_termios()
476 if (termios->c_iflag & IGNPAR) in sa1100_set_termios()
477 sport->port.ignore_status_mask |= in sa1100_set_termios()
481 del_timer_sync(&sport->timer); in sa1100_set_termios()
484 * Update the per-port timeout. in sa1100_set_termios()
486 uart_update_timeout(port, termios->c_cflag, baud); in sa1100_set_termios()
504 quot -= 1; in sa1100_set_termios()
508 UART_PUT_UTSR0(sport, -1); in sa1100_set_termios()
512 if (UART_ENABLE_MS(&sport->port, termios->c_cflag)) in sa1100_set_termios()
513 sa1100_enable_ms(&sport->port); in sa1100_set_termios()
515 spin_unlock_irqrestore(&sport->port.lock, flags); in sa1100_set_termios()
523 return sport->port.type == PORT_SA1100 ? "SA1100" : NULL; in sa1100_type()
534 release_mem_region(sport->port.mapbase, UART_PORT_SIZE); in sa1100_release_port()
545 return request_mem_region(sport->port.mapbase, UART_PORT_SIZE, in sa1100_request_port()
546 "sa11x0-uart") != NULL ? 0 : -EBUSY; in sa1100_request_port()
558 sa1100_request_port(&sport->port) == 0) in sa1100_config_port()
559 sport->port.type = PORT_SA1100; in sa1100_config_port()
574 if (ser->type != PORT_UNKNOWN && ser->type != PORT_SA1100) in sa1100_verify_port()
575 ret = -EINVAL; in sa1100_verify_port()
576 if (sport->port.irq != ser->irq) in sa1100_verify_port()
577 ret = -EINVAL; in sa1100_verify_port()
578 if (ser->io_type != SERIAL_IO_MEM) in sa1100_verify_port()
579 ret = -EINVAL; in sa1100_verify_port()
580 if (sport->port.uartclk / 16 != ser->baud_base) in sa1100_verify_port()
581 ret = -EINVAL; in sa1100_verify_port()
582 if ((void *)sport->port.mapbase != ser->iomem_base) in sa1100_verify_port()
583 ret = -EINVAL; in sa1100_verify_port()
584 if (sport->port.iobase != ser->port) in sa1100_verify_port()
585 ret = -EINVAL; in sa1100_verify_port()
586 if (ser->hub6 != 0) in sa1100_verify_port()
587 ret = -EINVAL; in sa1100_verify_port()
652 if (fns->get_mctrl) in sa1100_register_uart_fns()
653 sa1100_pops.get_mctrl = fns->get_mctrl; in sa1100_register_uart_fns()
654 if (fns->set_mctrl) in sa1100_register_uart_fns()
655 sa1100_pops.set_mctrl = fns->set_mctrl; in sa1100_register_uart_fns()
657 sa1100_pops.pm = fns->pm; in sa1100_register_uart_fns()
659 * FIXME: fns->set_wake is unused - this should be called from in sa1100_register_uart_fns()
716 struct sa1100_port *sport = &sa1100_ports[co->index]; in sa1100_console_write()
726 uart_console_write(&sport->port, s, count, sa1100_console_putchar); in sa1100_console_write()
770 *baud = sport->port.uartclk / (16 * (quot + 1)); in sa1100_console_get_options()
788 if (co->index == -1 || co->index >= NR_PORTS) in sa1100_console_setup()
789 co->index = 0; in sa1100_console_setup()
790 sport = &sa1100_ports[co->index]; in sa1100_console_setup()
797 return uart_set_options(&sport->port, co, baud, parity, bits, flow); in sa1100_console_setup()
807 .index = -1,
839 uart_suspend_port(&sa1100_reg, &sport->port); in sa1100_serial_suspend()
849 uart_resume_port(&sa1100_reg, &sport->port); in sa1100_serial_resume()
856 sport->port.dev = &dev->dev; in sa1100_serial_add_one_port()
857 sport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SA1100_CONSOLE); in sa1100_serial_add_one_port()
862 sport->gpios = mctrl_gpio_init_noauto(sport->port.dev, 0); in sa1100_serial_add_one_port()
863 if (IS_ERR(sport->gpios)) { in sa1100_serial_add_one_port()
864 int err = PTR_ERR(sport->gpios); in sa1100_serial_add_one_port()
866 dev_err(sport->port.dev, "failed to get mctrl gpios: %d\n", in sa1100_serial_add_one_port()
869 if (err == -EPROBE_DEFER) in sa1100_serial_add_one_port()
872 sport->gpios = NULL; in sa1100_serial_add_one_port()
877 return uart_add_one_port(&sa1100_reg, &sport->port); in sa1100_serial_add_one_port()
887 return -EINVAL; in sa1100_serial_probe()
890 if (sa1100_ports[i].port.mapbase == res->start) in sa1100_serial_probe()
893 return -ENODEV; in sa1100_serial_probe()
905 uart_remove_one_port(&sa1100_reg, &sport->port); in sa1100_serial_remove()
916 .name = "sa11x0-uart",
950 MODULE_ALIAS("platform:sa11x0-uart");