Lines Matching refs:port
118 struct uart_port port; member
126 static void stm32_stop_tx(struct uart_port *port);
128 static inline struct stm32_port *to_stm32_port(struct uart_port *port) in to_stm32_port() argument
130 return container_of(port, struct stm32_port, port); in to_stm32_port()
133 static void stm32_set_bits(struct uart_port *port, u32 reg, u32 bits) in stm32_set_bits() argument
137 val = readl_relaxed(port->membase + reg); in stm32_set_bits()
139 writel_relaxed(val, port->membase + reg); in stm32_set_bits()
142 static void stm32_clr_bits(struct uart_port *port, u32 reg, u32 bits) in stm32_clr_bits() argument
146 val = readl_relaxed(port->membase + reg); in stm32_clr_bits()
148 writel_relaxed(val, port->membase + reg); in stm32_clr_bits()
151 static void stm32_receive_chars(struct uart_port *port) in stm32_receive_chars() argument
153 struct tty_port *tport = &port->state->port; in stm32_receive_chars()
158 if (port->irq_wake) in stm32_receive_chars()
161 while ((sr = readl_relaxed(port->membase + USART_SR)) & USART_SR_RXNE) { in stm32_receive_chars()
163 c = readl_relaxed(port->membase + USART_DR); in stm32_receive_chars()
165 port->icount.rx++; in stm32_receive_chars()
169 port->icount.brk++; in stm32_receive_chars()
170 if (uart_handle_break(port)) in stm32_receive_chars()
173 port->icount.overrun++; in stm32_receive_chars()
175 port->icount.parity++; in stm32_receive_chars()
177 port->icount.frame++; in stm32_receive_chars()
180 sr &= port->read_status_mask; in stm32_receive_chars()
190 if (uart_handle_sysrq_char(port, c)) in stm32_receive_chars()
192 uart_insert_char(port, sr, USART_SR_ORE, c, flag); in stm32_receive_chars()
195 spin_unlock(&port->lock); in stm32_receive_chars()
197 spin_lock(&port->lock); in stm32_receive_chars()
200 static void stm32_transmit_chars(struct uart_port *port) in stm32_transmit_chars() argument
202 struct circ_buf *xmit = &port->state->xmit; in stm32_transmit_chars()
204 if (port->x_char) { in stm32_transmit_chars()
205 writel_relaxed(port->x_char, port->membase + USART_DR); in stm32_transmit_chars()
206 port->x_char = 0; in stm32_transmit_chars()
207 port->icount.tx++; in stm32_transmit_chars()
211 if (uart_tx_stopped(port)) { in stm32_transmit_chars()
212 stm32_stop_tx(port); in stm32_transmit_chars()
217 stm32_stop_tx(port); in stm32_transmit_chars()
221 writel_relaxed(xmit->buf[xmit->tail], port->membase + USART_DR); in stm32_transmit_chars()
223 port->icount.tx++; in stm32_transmit_chars()
226 uart_write_wakeup(port); in stm32_transmit_chars()
229 stm32_stop_tx(port); in stm32_transmit_chars()
234 struct uart_port *port = ptr; in stm32_interrupt() local
237 spin_lock(&port->lock); in stm32_interrupt()
239 sr = readl_relaxed(port->membase + USART_SR); in stm32_interrupt()
242 stm32_receive_chars(port); in stm32_interrupt()
245 stm32_transmit_chars(port); in stm32_interrupt()
247 spin_unlock(&port->lock); in stm32_interrupt()
252 static unsigned int stm32_tx_empty(struct uart_port *port) in stm32_tx_empty() argument
254 return readl_relaxed(port->membase + USART_SR) & USART_SR_TXE; in stm32_tx_empty()
257 static void stm32_set_mctrl(struct uart_port *port, unsigned int mctrl) in stm32_set_mctrl() argument
259 if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS)) in stm32_set_mctrl()
260 stm32_set_bits(port, USART_CR3, USART_CR3_RTSE); in stm32_set_mctrl()
262 stm32_clr_bits(port, USART_CR3, USART_CR3_RTSE); in stm32_set_mctrl()
265 static unsigned int stm32_get_mctrl(struct uart_port *port) in stm32_get_mctrl() argument
272 static void stm32_stop_tx(struct uart_port *port) in stm32_stop_tx() argument
274 stm32_clr_bits(port, USART_CR1, USART_CR1_TXEIE); in stm32_stop_tx()
278 static void stm32_start_tx(struct uart_port *port) in stm32_start_tx() argument
280 struct circ_buf *xmit = &port->state->xmit; in stm32_start_tx()
285 stm32_set_bits(port, USART_CR1, USART_CR1_TXEIE | USART_CR1_TE); in stm32_start_tx()
289 static void stm32_throttle(struct uart_port *port) in stm32_throttle() argument
293 spin_lock_irqsave(&port->lock, flags); in stm32_throttle()
294 stm32_clr_bits(port, USART_CR1, USART_CR1_RXNEIE); in stm32_throttle()
295 spin_unlock_irqrestore(&port->lock, flags); in stm32_throttle()
299 static void stm32_unthrottle(struct uart_port *port) in stm32_unthrottle() argument
303 spin_lock_irqsave(&port->lock, flags); in stm32_unthrottle()
304 stm32_set_bits(port, USART_CR1, USART_CR1_RXNEIE); in stm32_unthrottle()
305 spin_unlock_irqrestore(&port->lock, flags); in stm32_unthrottle()
309 static void stm32_stop_rx(struct uart_port *port) in stm32_stop_rx() argument
311 stm32_clr_bits(port, USART_CR1, USART_CR1_RXNEIE); in stm32_stop_rx()
315 static void stm32_break_ctl(struct uart_port *port, int break_state) in stm32_break_ctl() argument
319 static int stm32_startup(struct uart_port *port) in stm32_startup() argument
321 const char *name = to_platform_device(port->dev)->name; in stm32_startup()
325 ret = request_irq(port->irq, stm32_interrupt, 0, name, port); in stm32_startup()
330 stm32_set_bits(port, USART_CR1, val); in stm32_startup()
335 static void stm32_shutdown(struct uart_port *port) in stm32_shutdown() argument
340 stm32_set_bits(port, USART_CR1, val); in stm32_shutdown()
342 free_irq(port->irq, port); in stm32_shutdown()
345 static void stm32_set_termios(struct uart_port *port, struct ktermios *termios, in stm32_set_termios() argument
348 struct stm32_port *stm32_port = to_stm32_port(port); in stm32_set_termios()
358 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 8); in stm32_set_termios()
360 spin_lock_irqsave(&port->lock, flags); in stm32_set_termios()
363 writel_relaxed(0, port->membase + USART_CR1); in stm32_set_termios()
381 port->status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS); in stm32_set_termios()
383 port->status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; in stm32_set_termios()
387 usartdiv = DIV_ROUND_CLOSEST(port->uartclk, baud); in stm32_set_termios()
397 stm32_set_bits(port, USART_CR1, USART_CR1_OVER8); in stm32_set_termios()
400 stm32_clr_bits(port, USART_CR1, USART_CR1_OVER8); in stm32_set_termios()
405 writel_relaxed(mantissa | fraction, port->membase + USART_BRR); in stm32_set_termios()
407 uart_update_timeout(port, cflag, baud); in stm32_set_termios()
409 port->read_status_mask = USART_SR_ORE; in stm32_set_termios()
411 port->read_status_mask |= USART_SR_PE | USART_SR_FE; in stm32_set_termios()
413 port->read_status_mask |= USART_SR_LBD; in stm32_set_termios()
416 port->ignore_status_mask = 0; in stm32_set_termios()
418 port->ignore_status_mask = USART_SR_PE | USART_SR_FE; in stm32_set_termios()
420 port->ignore_status_mask |= USART_SR_LBD; in stm32_set_termios()
426 port->ignore_status_mask |= USART_SR_ORE; in stm32_set_termios()
431 port->ignore_status_mask |= USART_SR_DUMMY_RX; in stm32_set_termios()
433 writel_relaxed(cr3, port->membase + USART_CR3); in stm32_set_termios()
434 writel_relaxed(cr2, port->membase + USART_CR2); in stm32_set_termios()
435 writel_relaxed(cr1, port->membase + USART_CR1); in stm32_set_termios()
437 spin_unlock_irqrestore(&port->lock, flags); in stm32_set_termios()
440 static const char *stm32_type(struct uart_port *port) in stm32_type() argument
442 return (port->type == PORT_STM32) ? DRIVER_NAME : NULL; in stm32_type()
445 static void stm32_release_port(struct uart_port *port) in stm32_release_port() argument
449 static int stm32_request_port(struct uart_port *port) in stm32_request_port() argument
454 static void stm32_config_port(struct uart_port *port, int flags) in stm32_config_port() argument
457 port->type = PORT_STM32; in stm32_config_port()
461 stm32_verify_port(struct uart_port *port, struct serial_struct *ser) in stm32_verify_port() argument
467 static void stm32_pm(struct uart_port *port, unsigned int state, in stm32_pm() argument
470 struct stm32_port *stm32port = container_of(port, in stm32_pm()
471 struct stm32_port, port); in stm32_pm()
479 spin_lock_irqsave(&port->lock, flags); in stm32_pm()
480 stm32_clr_bits(port, USART_CR1, USART_CR1_UE); in stm32_pm()
481 spin_unlock_irqrestore(&port->lock, flags); in stm32_pm()
511 struct uart_port *port = &stm32port->port; in stm32_init_port() local
515 port->iotype = UPIO_MEM; in stm32_init_port()
516 port->flags = UPF_BOOT_AUTOCONF; in stm32_init_port()
517 port->ops = &stm32_uart_ops; in stm32_init_port()
518 port->dev = &pdev->dev; in stm32_init_port()
519 port->irq = platform_get_irq(pdev, 0); in stm32_init_port()
522 port->membase = devm_ioremap_resource(&pdev->dev, res); in stm32_init_port()
523 if (IS_ERR(port->membase)) in stm32_init_port()
524 return PTR_ERR(port->membase); in stm32_init_port()
525 port->mapbase = res->start; in stm32_init_port()
527 spin_lock_init(&port->lock); in stm32_init_port()
538 stm32port->port.uartclk = clk_get_rate(stm32port->clk); in stm32_init_port()
539 if (!stm32port->port.uartclk) in stm32_init_port()
564 stm32_ports[id].port.line = id; in stm32_of_get_stm32_port()
591 ret = uart_add_one_port(&stm32_usart_driver, &stm32port->port); in stm32_serial_probe()
595 platform_set_drvdata(pdev, &stm32port->port); in stm32_serial_probe()
602 struct uart_port *port = platform_get_drvdata(pdev); in stm32_serial_remove() local
604 return uart_remove_one_port(&stm32_usart_driver, port); in stm32_serial_remove()
609 static void stm32_console_putchar(struct uart_port *port, int ch) in stm32_console_putchar() argument
611 while (!(readl_relaxed(port->membase + USART_SR) & USART_SR_TXE)) in stm32_console_putchar()
614 writel_relaxed(ch, port->membase + USART_DR); in stm32_console_putchar()
619 struct uart_port *port = &stm32_ports[co->index].port; in stm32_console_write() local
625 if (port->sysrq) in stm32_console_write()
628 locked = spin_trylock(&port->lock); in stm32_console_write()
630 spin_lock(&port->lock); in stm32_console_write()
633 old_cr1 = readl_relaxed(port->membase + USART_CR1); in stm32_console_write()
635 writel_relaxed(new_cr1, port->membase + USART_CR1); in stm32_console_write()
637 uart_console_write(port, s, cnt, stm32_console_putchar); in stm32_console_write()
640 writel_relaxed(old_cr1, port->membase + USART_CR1); in stm32_console_write()
643 spin_unlock(&port->lock); in stm32_console_write()
666 if (stm32port->port.mapbase == 0 || stm32port->port.membase == NULL) in stm32_console_setup()
672 return uart_set_options(&stm32port->port, co, baud, parity, bits, flow); in stm32_console_setup()