Lines Matching refs:port

36 	struct uart_port port;
146 static inline struct asc_port *to_asc_port(struct uart_port *port)
148 return container_of(port, struct asc_port, port);
151 static inline u32 asc_in(struct uart_port *port, u32 offset)
154 return readl_relaxed(port->membase + offset);
156 return readl(port->membase + offset);
160 static inline void asc_out(struct uart_port *port, u32 offset, u32 value)
163 writel_relaxed(value, port->membase + offset);
165 writel(value, port->membase + offset);
173 static inline void asc_disable_tx_interrupts(struct uart_port *port)
175 u32 intenable = asc_in(port, ASC_INTEN) & ~ASC_INTEN_THE;
176 asc_out(port, ASC_INTEN, intenable);
177 (void)asc_in(port, ASC_INTEN); /* Defeat bus write posting */
180 static inline void asc_enable_tx_interrupts(struct uart_port *port)
182 u32 intenable = asc_in(port, ASC_INTEN) | ASC_INTEN_THE;
183 asc_out(port, ASC_INTEN, intenable);
186 static inline void asc_disable_rx_interrupts(struct uart_port *port)
188 u32 intenable = asc_in(port, ASC_INTEN) & ~ASC_INTEN_RBE;
189 asc_out(port, ASC_INTEN, intenable);
190 (void)asc_in(port, ASC_INTEN); /* Defeat bus write posting */
193 static inline void asc_enable_rx_interrupts(struct uart_port *port)
195 u32 intenable = asc_in(port, ASC_INTEN) | ASC_INTEN_RBE;
196 asc_out(port, ASC_INTEN, intenable);
199 static inline u32 asc_txfifo_is_empty(struct uart_port *port)
201 return asc_in(port, ASC_STA) & ASC_STA_TE;
204 static inline u32 asc_txfifo_is_half_empty(struct uart_port *port)
206 return asc_in(port, ASC_STA) & ASC_STA_THE;
209 static inline const char *asc_port_name(struct uart_port *port)
211 return to_platform_device(port->dev)->name;
218 * generic serial port.
221 static inline unsigned asc_hw_txroom(struct uart_port *port)
223 u32 status = asc_in(port, ASC_STA);
226 return port->fifosize / 2;
238 static void asc_transmit_chars(struct uart_port *port)
242 uart_port_tx_limited(port, ch, asc_hw_txroom(port),
244 asc_out(port, ASC_TXBUF, ch),
248 static void asc_receive_chars(struct uart_port *port)
250 struct tty_port *tport = &port->state->port;
261 mode = asc_in(port, ASC_CTL) & ASC_CTL_MODE_MSK;
265 if (irqd_is_wakeup_set(irq_get_irq_data(port->irq)))
268 while ((status = asc_in(port, ASC_STA)) & ASC_STA_RBF) {
269 c = asc_in(port, ASC_RXBUF) | ASC_RXBUF_DUMMY_RX;
271 port->icount.rx++;
278 port->icount.brk++;
279 if (uart_handle_break(port))
283 port->icount.frame++;
286 port->icount.parity++;
293 port->icount.overrun++;
297 c &= port->read_status_mask;
307 if (uart_handle_sysrq_char(port, c & 0xff))
310 uart_insert_char(port, c, ASC_RXBUF_DUMMY_OE, c & 0xff, flag);
319 struct uart_port *port = ptr;
322 spin_lock(&port->lock);
324 status = asc_in(port, ASC_STA);
328 asc_receive_chars(port);
332 (asc_in(port, ASC_INTEN) & ASC_INTEN_THE)) {
334 asc_transmit_chars(port);
337 spin_unlock(&port->lock);
348 static unsigned int asc_tx_empty(struct uart_port *port)
350 return asc_txfifo_is_empty(port) ? TIOCSER_TEMT : 0;
353 static void asc_set_mctrl(struct uart_port *port, unsigned int mctrl)
355 struct asc_port *ascport = to_asc_port(port);
372 if (asc_in(port, ASC_CTL) & ASC_CTL_CTSENABLE)
378 static unsigned int asc_get_mctrl(struct uart_port *port)
388 static void asc_start_tx(struct uart_port *port)
390 struct circ_buf *xmit = &port->state->xmit;
393 asc_enable_tx_interrupts(port);
397 static void asc_stop_tx(struct uart_port *port)
399 asc_disable_tx_interrupts(port);
403 static void asc_stop_rx(struct uart_port *port)
405 asc_disable_rx_interrupts(port);
409 static void asc_break_ctl(struct uart_port *port, int break_state)
415 * Enable port for reception.
417 static int asc_startup(struct uart_port *port)
419 if (request_irq(port->irq, asc_interrupt, 0,
420 asc_port_name(port), port)) {
421 dev_err(port->dev, "cannot allocate irq.\n");
425 asc_transmit_chars(port);
426 asc_enable_rx_interrupts(port);
431 static void asc_shutdown(struct uart_port *port)
433 asc_disable_tx_interrupts(port);
434 asc_disable_rx_interrupts(port);
435 free_irq(port->irq, port);
438 static void asc_pm(struct uart_port *port, unsigned int state,
441 struct asc_port *ascport = to_asc_port(port);
453 * the port spinlock held.
455 spin_lock_irqsave(&port->lock, flags);
456 ctl = asc_in(port, ASC_CTL) & ~ASC_CTL_RUN;
457 asc_out(port, ASC_CTL, ctl);
458 spin_unlock_irqrestore(&port->lock, flags);
464 static void asc_set_termios(struct uart_port *port, struct ktermios *termios,
467 struct asc_port *ascport = to_asc_port(port);
478 port->uartclk = clk_get_rate(ascport->clk);
480 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
483 spin_lock_irqsave(&port->lock, flags);
486 ctrl_val = asc_in(port, ASC_CTL);
488 /* stop serial port and reset value */
489 asc_out(port, ASC_CTL, (ctrl_val & ~ASC_CTL_RUN));
493 asc_out(port, ASC_TXRESET, 1);
494 asc_out(port, ASC_RXRESET, 1);
521 devm_gpiod_put(port->dev, ascport->rts);
533 gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW);
536 port->dev->of_node->name);
543 asc_out(port, ASC_BAUDRATE, (port->uartclk / (16 * baud)));
556 do_div(dividend, port->uartclk / 16);
557 asc_out(port, ASC_BAUDRATE, dividend);
561 uart_update_timeout(port, cflag, baud);
563 ascport->port.read_status_mask = ASC_RXBUF_DUMMY_OE;
565 ascport->port.read_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE;
567 ascport->port.read_status_mask |= ASC_RXBUF_DUMMY_BE;
572 ascport->port.ignore_status_mask = 0;
574 ascport->port.ignore_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE;
576 ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_BE;
582 ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_OE;
589 ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_RX;
592 asc_out(port, ASC_TIMEOUT, 20);
594 /* write final value and enable port */
595 asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN));
597 spin_unlock_irqrestore(&port->lock, flags);
600 static const char *asc_type(struct uart_port *port)
602 return (port->type == PORT_ASC) ? DRIVER_NAME : NULL;
605 static void asc_release_port(struct uart_port *port)
609 static int asc_request_port(struct uart_port *port)
615 * Called when the port is opened, and UPF_BOOT_AUTOCONF flag is set
618 static void asc_config_port(struct uart_port *port, int flags)
621 port->type = PORT_ASC;
625 asc_verify_port(struct uart_port *port, struct serial_struct *ser)
637 static int asc_get_poll_char(struct uart_port *port)
639 if (!(asc_in(port, ASC_STA) & ASC_STA_RBF))
642 return asc_in(port, ASC_RXBUF);
645 static void asc_put_poll_char(struct uart_port *port, unsigned char c)
647 while (!asc_txfifo_is_half_empty(port))
649 asc_out(port, ASC_TXBUF, c);
682 struct uart_port *port = &ascport->port;
686 port->iotype = UPIO_MEM;
687 port->flags = UPF_BOOT_AUTOCONF;
688 port->ops = &asc_uart_ops;
689 port->fifosize = ASC_FIFO_SIZE;
690 port->dev = &pdev->dev;
691 port->irq = platform_get_irq(pdev, 0);
692 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ST_ASC_CONSOLE);
694 port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
695 if (IS_ERR(port->membase))
696 return PTR_ERR(port->membase);
697 port->mapbase = res->start;
699 spin_lock_init(&port->lock);
709 ascport->port.uartclk = clk_get_rate(ascport->clk);
710 WARN_ON(ascport->port.uartclk == 0);
759 asc_ports[id].port.line = id;
787 ret = uart_add_one_port(&asc_uart_driver, &ascport->port);
791 platform_set_drvdata(pdev, &ascport->port);
798 struct uart_port *port = platform_get_drvdata(pdev);
800 uart_remove_one_port(&asc_uart_driver, port);
808 struct uart_port *port = dev_get_drvdata(dev);
810 return uart_suspend_port(&asc_uart_driver, port);
815 struct uart_port *port = dev_get_drvdata(dev);
817 return uart_resume_port(&asc_uart_driver, port);
825 static void asc_console_putchar(struct uart_port *port, unsigned char ch)
830 while (--timeout && !asc_txfifo_is_half_empty(port))
833 asc_out(port, ASC_TXBUF, ch);
837 * Print a string to the serial port trying not to disturb
838 * any possible real use of the port...
843 struct uart_port *port = &asc_ports[co->index].port;
849 if (port->sysrq)
852 locked = spin_trylock_irqsave(&port->lock, flags);
854 spin_lock_irqsave(&port->lock, flags);
860 intenable = asc_in(port, ASC_INTEN);
861 asc_out(port, ASC_INTEN, 0);
862 (void)asc_in(port, ASC_INTEN); /* Defeat bus write posting */
864 uart_console_write(port, s, count, asc_console_putchar);
866 while (--timeout && !asc_txfifo_is_empty(port))
869 asc_out(port, ASC_INTEN, intenable);
872 spin_unlock_irqrestore(&port->lock, flags);
891 * this to be called during the uart port registration when the
892 * driver gets probed and the port should be mapped at that point.
894 if (ascport->port.mapbase == 0 || ascport->port.membase == NULL)
900 return uart_set_options(&ascport->port, co, baud, parity, bits, flow);
973 MODULE_DESCRIPTION("STMicroelectronics ASC serial port driver");