Lines Matching +full:port +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0+
38 #define UARTDR_FRMERR (1 << 8)
39 #define UARTDR_PARERR (1 << 9)
40 #define UARTDR_OVERR (1 << 10)
42 #define UBRLCR_BAUD_MASK ((1 << 12) - 1)
43 #define UBRLCR_BREAK (1 << 12)
44 #define UBRLCR_PRTEN (1 << 13)
45 #define UBRLCR_EVENPRT (1 << 14)
46 #define UBRLCR_XSTOP (1 << 15)
47 #define UBRLCR_FIFOEN (1 << 16)
49 #define UBRLCR_WRDLEN6 (1 << 17)
55 struct uart_port port; member
71 static void uart_clps711x_stop_tx(struct uart_port *port) in uart_clps711x_stop_tx() argument
73 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_stop_tx()
75 if (s->tx_enabled) { in uart_clps711x_stop_tx()
76 disable_irq(port->irq); in uart_clps711x_stop_tx()
77 s->tx_enabled = 0; in uart_clps711x_stop_tx()
81 static void uart_clps711x_start_tx(struct uart_port *port) in uart_clps711x_start_tx() argument
83 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_start_tx()
85 if (!s->tx_enabled) { in uart_clps711x_start_tx()
86 s->tx_enabled = 1; in uart_clps711x_start_tx()
87 enable_irq(port->irq); in uart_clps711x_start_tx()
93 struct uart_port *port = dev_id; in uart_clps711x_int_rx() local
94 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_int_rx()
101 regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); in uart_clps711x_int_rx()
105 ch = readw(port->membase + UARTDR_OFFSET); in uart_clps711x_int_rx()
109 port->icount.rx++; in uart_clps711x_int_rx()
114 port->icount.parity++; in uart_clps711x_int_rx()
116 port->icount.frame++; in uart_clps711x_int_rx()
118 port->icount.overrun++; in uart_clps711x_int_rx()
120 status &= port->read_status_mask; in uart_clps711x_int_rx()
130 if (uart_handle_sysrq_char(port, ch)) in uart_clps711x_int_rx()
133 if (status & port->ignore_status_mask) in uart_clps711x_int_rx()
136 uart_insert_char(port, status, UARTDR_OVERR, ch, flg); in uart_clps711x_int_rx()
139 tty_flip_buffer_push(&port->state->port); in uart_clps711x_int_rx()
146 struct uart_port *port = dev_id; in uart_clps711x_int_tx() local
147 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_int_tx()
148 struct circ_buf *xmit = &port->state->xmit; in uart_clps711x_int_tx()
150 if (port->x_char) { in uart_clps711x_int_tx()
151 writew(port->x_char, port->membase + UARTDR_OFFSET); in uart_clps711x_int_tx()
152 port->icount.tx++; in uart_clps711x_int_tx()
153 port->x_char = 0; in uart_clps711x_int_tx()
157 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { in uart_clps711x_int_tx()
158 if (s->tx_enabled) { in uart_clps711x_int_tx()
159 disable_irq_nosync(port->irq); in uart_clps711x_int_tx()
160 s->tx_enabled = 0; in uart_clps711x_int_tx()
168 writew(xmit->buf[xmit->tail], port->membase + UARTDR_OFFSET); in uart_clps711x_int_tx()
169 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in uart_clps711x_int_tx()
170 port->icount.tx++; in uart_clps711x_int_tx()
172 regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); in uart_clps711x_int_tx()
178 uart_write_wakeup(port); in uart_clps711x_int_tx()
183 static unsigned int uart_clps711x_tx_empty(struct uart_port *port) in uart_clps711x_tx_empty() argument
185 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_tx_empty()
188 regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); in uart_clps711x_tx_empty()
193 static unsigned int uart_clps711x_get_mctrl(struct uart_port *port) in uart_clps711x_get_mctrl() argument
196 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_get_mctrl()
198 return mctrl_gpio_get(s->gpios, &result); in uart_clps711x_get_mctrl()
201 static void uart_clps711x_set_mctrl(struct uart_port *port, unsigned int mctrl) in uart_clps711x_set_mctrl() argument
203 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_set_mctrl()
205 mctrl_gpio_set(s->gpios, mctrl); in uart_clps711x_set_mctrl()
208 static void uart_clps711x_break_ctl(struct uart_port *port, int break_state) in uart_clps711x_break_ctl() argument
212 ubrlcr = readl(port->membase + UBRLCR_OFFSET); in uart_clps711x_break_ctl()
217 writel(ubrlcr, port->membase + UBRLCR_OFFSET); in uart_clps711x_break_ctl()
220 static void uart_clps711x_set_ldisc(struct uart_port *port, in uart_clps711x_set_ldisc() argument
223 if (!port->line) { in uart_clps711x_set_ldisc()
224 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_set_ldisc()
226 regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON1_SIREN, in uart_clps711x_set_ldisc()
227 (termios->c_line == N_IRDA) ? SYSCON1_SIREN : 0); in uart_clps711x_set_ldisc()
231 static int uart_clps711x_startup(struct uart_port *port) in uart_clps711x_startup() argument
233 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_startup()
236 writel(readl(port->membase + UBRLCR_OFFSET) & ~UBRLCR_BREAK, in uart_clps711x_startup()
237 port->membase + UBRLCR_OFFSET); in uart_clps711x_startup()
239 /* Enable the port */ in uart_clps711x_startup()
240 return regmap_update_bits(s->syscon, SYSCON_OFFSET, in uart_clps711x_startup()
244 static void uart_clps711x_shutdown(struct uart_port *port) in uart_clps711x_shutdown() argument
246 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_shutdown()
248 /* Disable the port */ in uart_clps711x_shutdown()
249 regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON_UARTEN, 0); in uart_clps711x_shutdown()
252 static void uart_clps711x_set_termios(struct uart_port *port, in uart_clps711x_set_termios() argument
260 termios->c_cflag &= ~CMSPAR; in uart_clps711x_set_termios()
261 termios->c_iflag &= ~(BRKINT | IGNBRK); in uart_clps711x_set_termios()
264 baud = uart_get_baud_rate(port, termios, old, port->uartclk / 4096, in uart_clps711x_set_termios()
265 port->uartclk / 16); in uart_clps711x_set_termios()
266 quot = uart_get_divisor(port, baud); in uart_clps711x_set_termios()
268 switch (termios->c_cflag & CSIZE) { in uart_clps711x_set_termios()
284 if (termios->c_cflag & CSTOPB) in uart_clps711x_set_termios()
287 if (termios->c_cflag & PARENB) { in uart_clps711x_set_termios()
289 if (!(termios->c_cflag & PARODD)) in uart_clps711x_set_termios()
297 port->read_status_mask = UARTDR_OVERR; in uart_clps711x_set_termios()
298 if (termios->c_iflag & INPCK) in uart_clps711x_set_termios()
299 port->read_status_mask |= UARTDR_PARERR | UARTDR_FRMERR; in uart_clps711x_set_termios()
302 port->ignore_status_mask = 0; in uart_clps711x_set_termios()
303 if (!(termios->c_cflag & CREAD)) in uart_clps711x_set_termios()
304 port->ignore_status_mask |= UARTDR_OVERR | UARTDR_PARERR | in uart_clps711x_set_termios()
307 uart_update_timeout(port, termios->c_cflag, baud); in uart_clps711x_set_termios()
309 writel(ubrlcr | (quot - 1), port->membase + UBRLCR_OFFSET); in uart_clps711x_set_termios()
312 static const char *uart_clps711x_type(struct uart_port *port) in uart_clps711x_type() argument
314 return (port->type == PORT_CLPS711X) ? "CLPS711X" : NULL; in uart_clps711x_type()
317 static void uart_clps711x_config_port(struct uart_port *port, int flags) in uart_clps711x_config_port() argument
320 port->type = PORT_CLPS711X; in uart_clps711x_config_port()
323 static void uart_clps711x_nop_void(struct uart_port *port) in uart_clps711x_nop_void() argument
327 static int uart_clps711x_nop_int(struct uart_port *port) in uart_clps711x_nop_int() argument
351 static void uart_clps711x_console_putchar(struct uart_port *port, int ch) in uart_clps711x_console_putchar() argument
353 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_console_putchar()
358 regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); in uart_clps711x_console_putchar()
361 writew(ch, port->membase + UARTDR_OFFSET); in uart_clps711x_console_putchar()
367 struct uart_port *port = clps711x_uart.state[co->index].uart_port; in uart_clps711x_console_write() local
368 struct clps711x_port *s = dev_get_drvdata(port->dev); in uart_clps711x_console_write()
371 uart_console_write(port, c, n, uart_clps711x_console_putchar); in uart_clps711x_console_write()
375 regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); in uart_clps711x_console_write()
382 int ret, index = co->index; in uart_clps711x_console_setup()
384 struct uart_port *port; in uart_clps711x_console_setup() local
389 return -EINVAL; in uart_clps711x_console_setup()
391 port = clps711x_uart.state[index].uart_port; in uart_clps711x_console_setup()
392 if (!port) in uart_clps711x_console_setup()
393 return -ENODEV; in uart_clps711x_console_setup()
395 s = dev_get_drvdata(port->dev); in uart_clps711x_console_setup()
400 regmap_read(s->syscon, SYSCON_OFFSET, &syscon); in uart_clps711x_console_setup()
402 ubrlcr = readl(port->membase + UBRLCR_OFFSET); in uart_clps711x_console_setup()
415 baud = port->uartclk / (16 * (quot + 1)); in uart_clps711x_console_setup()
420 ret = uart_set_options(port, co, baud, parity, bits, flow); in uart_clps711x_console_setup()
424 return regmap_update_bits(s->syscon, SYSCON_OFFSET, in uart_clps711x_console_setup()
434 .index = -1,
440 struct device_node *np = pdev->dev.of_node; in uart_clps711x_probe()
446 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); in uart_clps711x_probe()
448 return -ENOMEM; in uart_clps711x_probe()
450 uart_clk = devm_clk_get(&pdev->dev, NULL); in uart_clps711x_probe()
455 s->port.membase = devm_ioremap_resource(&pdev->dev, res); in uart_clps711x_probe()
456 if (IS_ERR(s->port.membase)) in uart_clps711x_probe()
457 return PTR_ERR(s->port.membase); in uart_clps711x_probe()
462 s->port.irq = irq; in uart_clps711x_probe()
464 s->rx_irq = platform_get_irq(pdev, 1); in uart_clps711x_probe()
465 if (s->rx_irq < 0) in uart_clps711x_probe()
466 return s->rx_irq; in uart_clps711x_probe()
468 s->syscon = syscon_regmap_lookup_by_phandle(np, "syscon"); in uart_clps711x_probe()
469 if (IS_ERR(s->syscon)) in uart_clps711x_probe()
470 return PTR_ERR(s->syscon); in uart_clps711x_probe()
472 s->port.line = of_alias_get_id(np, "serial"); in uart_clps711x_probe()
473 s->port.dev = &pdev->dev; in uart_clps711x_probe()
474 s->port.iotype = UPIO_MEM32; in uart_clps711x_probe()
475 s->port.mapbase = res->start; in uart_clps711x_probe()
476 s->port.type = PORT_CLPS711X; in uart_clps711x_probe()
477 s->port.fifosize = 16; in uart_clps711x_probe()
478 s->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_CLPS711X_CONSOLE); in uart_clps711x_probe()
479 s->port.flags = UPF_SKIP_TEST | UPF_FIXED_TYPE; in uart_clps711x_probe()
480 s->port.uartclk = clk_get_rate(uart_clk); in uart_clps711x_probe()
481 s->port.ops = &uart_clps711x_ops; in uart_clps711x_probe()
485 s->gpios = mctrl_gpio_init_noauto(&pdev->dev, 0); in uart_clps711x_probe()
486 if (IS_ERR(s->gpios)) in uart_clps711x_probe()
487 return PTR_ERR(s->gpios); in uart_clps711x_probe()
489 ret = uart_add_one_port(&clps711x_uart, &s->port); in uart_clps711x_probe()
493 /* Disable port */ in uart_clps711x_probe()
494 if (!uart_console(&s->port)) in uart_clps711x_probe()
495 regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON_UARTEN, 0); in uart_clps711x_probe()
497 s->tx_enabled = 1; in uart_clps711x_probe()
499 ret = devm_request_irq(&pdev->dev, s->port.irq, uart_clps711x_int_tx, 0, in uart_clps711x_probe()
500 dev_name(&pdev->dev), &s->port); in uart_clps711x_probe()
502 uart_remove_one_port(&clps711x_uart, &s->port); in uart_clps711x_probe()
506 ret = devm_request_irq(&pdev->dev, s->rx_irq, uart_clps711x_int_rx, 0, in uart_clps711x_probe()
507 dev_name(&pdev->dev), &s->port); in uart_clps711x_probe()
509 uart_remove_one_port(&clps711x_uart, &s->port); in uart_clps711x_probe()
518 return uart_remove_one_port(&clps711x_uart, &s->port); in uart_clps711x_remove()
522 { .compatible = "cirrus,ep7209-uart", },
529 .name = "clps711x-uart",