Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "tty: serial: Add UART driver for Cortina-Access platform"

This reverts commit b61c8bf4694b5115766849378dcb8787ff54e65e. It never
made it to a public mailing list and still needs some work based on the
review comments. So revert it for now.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/r/CAMuHMdXA9-ajoAza2JAW5879ECieMm1dbBbKHgJhDa7=3kWu3w@mail.gmail.com
Cc: Jason Li <jason.li@cortina-access.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

-823
-5
MAINTAINERS
··· 4680 4680 W: http://www.fi.muni.cz/~kas/cosa/ 4681 4681 F: drivers/net/wan/cosa* 4682 4682 4683 - CORTINA-ACCESS SERIAL CONSOLE DRIVER 4684 - M: Jason Li <jason.li@cortina-access.com> 4685 - S: Supported 4686 - F: drivers/tty/serial/serial_cortina-access.c 4687 - 4688 4683 COUNTER SUBSYSTEM 4689 4684 M: William Breathitt Gray <vilhelm.gray@gmail.com> 4690 4685 L: linux-iio@vger.kernel.org
-19
drivers/tty/serial/Kconfig
··· 1561 1561 and warnings and which allows logins in single user mode). 1562 1562 Otherwise, say 'N'. 1563 1563 1564 - config SERIAL_CORTINA_ACCESS 1565 - tristate "Cortina-Access serial port support" 1566 - select SERIAL_CORE 1567 - help 1568 - This driver is for Cortina-Access SoC's UART. If you have a machine 1569 - based on the Cortina-Access SoC and wish to use the serial port, 1570 - say 'Y' here. Otherwise, say 'N'. 1571 - 1572 - config SERIAL_CORTINA_ACCESS_CONSOLE 1573 - bool "Console on Cortina-ACCESS serial port" 1574 - depends on SERIAL_CORTINA_ACCESS=y 1575 - select SERIAL_CORE_CONSOLE 1576 - select SERIAL_EARLYCON 1577 - help 1578 - Say 'Y' here if you wish to use Cortina-Access UART as the system 1579 - console. (the system console is the device which receives all kernel 1580 - messages and warnings and which allows logins in single user mode) 1581 - /dev/ttyS* is default device node. 1582 - 1583 1564 endmenu 1584 1565 1585 1566 config SERIAL_MCTRL_GPIO
-1
drivers/tty/serial/Makefile
··· 87 87 obj-$(CONFIG_SERIAL_MILBEAUT_USIO) += milbeaut_usio.o 88 88 obj-$(CONFIG_SERIAL_SIFIVE) += sifive.o 89 89 obj-$(CONFIG_SERIAL_LITEUART) += liteuart.o 90 - obj-$(CONFIG_SERIAL_CORTINA_ACCESS) += serial_cortina-access.o 91 90 92 91 # GPIOLIB helpers for modem control lines 93 92 obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
-798
drivers/tty/serial/serial_cortina-access.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * UART driver for Cortina-Access Soc platform 4 - * Copyright (C) 2021 Cortina-Access Inc. 5 - */ 6 - #include <linux/module.h> 7 - #include <linux/tty.h> 8 - #include <linux/tty_flip.h> 9 - #include <linux/serial.h> 10 - #include <linux/sysrq.h> 11 - #include <linux/console.h> 12 - #include <linux/serial_core.h> 13 - #include <linux/delay.h> 14 - #include <linux/clk.h> 15 - #include <linux/io.h> 16 - #include <linux/of.h> 17 - #include <linux/of_device.h> 18 - #include <linux/of_address.h> 19 - #include <linux/of_irq.h> 20 - 21 - /*************************************** 22 - * UART Related registers 23 - ****************************************/ 24 - /* register definitions */ 25 - #define CFG 0x00 26 - #define FC 0x04 27 - #define RX_SAMPLE 0x08 28 - #define RT_TUNE 0x0C 29 - #define TX_DAT 0x10 30 - #define RX_DAT 0x14 31 - #define INFO 0x18 32 - #define IE 0x1C 33 - #define INT 0x24 34 - #define STATUS 0x2C 35 - 36 - /* CFG */ 37 - #define CFG_STOP_2BIT BIT(2) 38 - #define CFG_PARITY_EVEN BIT(3) 39 - #define CFG_PARITY_EN BIT(4) 40 - #define CFG_TX_EN BIT(5) 41 - #define CFG_RX_EN BIT(6) 42 - #define CFG_UART_EN BIT(7) 43 - #define CFG_BAUD_SART_SHIFT 8 44 - 45 - /* INFO */ 46 - #define INFO_TX_EMPTY BIT(3) 47 - #define INFO_TX_FULL BIT(2) 48 - #define INFO_RX_EMPTY BIT(1) 49 - #define INFO_RX_FULL BIT(0) 50 - 51 - /* Interrupt */ 52 - #define RX_BREAK BIT(7) 53 - #define RX_FIFO_NONEMPTYE BIT(6) 54 - #define TX_FIFO_EMPTYE BIT(5) 55 - #define RX_FIFO_UNDERRUNE BIT(4) 56 - #define RX_FIFO_OVERRUNE BIT(3) 57 - #define RX_PARITY_ERRE BIT(2) 58 - #define RX_STOP_ERRE BIT(1) 59 - #define TX_FIFO_OVERRUNE BIT(0) 60 - 61 - #define TX_TIMEOUT 5000 62 - #define UART_NR 4 63 - #define CA_UART_NAME_LEN 32 64 - struct cortina_uart_port { 65 - struct uart_port uart; 66 - char name[CA_UART_NAME_LEN]; 67 - char has_bi; 68 - unsigned int may_wakeup; 69 - }; 70 - 71 - static struct cortina_uart_port *cortina_uart_ports; 72 - 73 - static irqreturn_t cortina_uart_interrupt(int irq, void *dev_id); 74 - 75 - /* Return uart_port pointer base on index */ 76 - struct cortina_uart_port *cortina_uart_get_port(unsigned int index) 77 - { 78 - struct cortina_uart_port *pca_port = cortina_uart_ports; 79 - 80 - if (index >= UART_NR) { 81 - /* return 1st element if invalid index */ 82 - index = 0; 83 - } 84 - 85 - pca_port += index; 86 - 87 - return pca_port; 88 - } 89 - 90 - /* uart_ops functions */ 91 - static unsigned int cortina_uart_tx_empty(struct uart_port *port) 92 - { 93 - /* Return 0 on FIXO condition, TIOCSER_TEMT otherwise */ 94 - return (readl(port->membase + INFO) & INFO_TX_EMPTY) ? TIOCSER_TEMT : 0; 95 - } 96 - 97 - static void cortina_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) 98 - { 99 - /* 100 - * Even if we do not support configuring the modem control lines, this 101 - * function must be proided to the serial core. 102 - * port->ops->set_mctrl() be called in uart_configure_port() 103 - */ 104 - } 105 - 106 - static unsigned int cortina_uart_get_mctrl(struct uart_port *port) 107 - { 108 - /* Unimplemented signals asserted, per Documentation/serial/driver */ 109 - return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; 110 - } 111 - 112 - static void cortina_uart_stop_tx(struct uart_port *port) 113 - { 114 - /* Turn off Tx interrupts. The port lock is held at this point */ 115 - unsigned int reg_v; 116 - 117 - reg_v = readl(port->membase + IE); 118 - writel(reg_v & ~TX_FIFO_EMPTYE, port->membase + IE); 119 - } 120 - 121 - static inline void cortina_transmit_buffer(struct uart_port *port) 122 - { 123 - struct circ_buf *xmit = &port->state->xmit; 124 - 125 - if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 126 - cortina_uart_stop_tx(port); 127 - return; 128 - } 129 - 130 - do { 131 - /* send xmit->buf[xmit->tail] out the port here */ 132 - writel(xmit->buf[xmit->tail], port->membase + TX_DAT); 133 - xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 134 - port->icount.tx++; 135 - if ((readl(port->membase + INFO) & INFO_TX_FULL)) 136 - break; 137 - } while (!uart_circ_empty(xmit)); 138 - 139 - if (uart_circ_empty(xmit)) 140 - cortina_uart_stop_tx(port); 141 - } 142 - 143 - static void cortina_uart_start_tx(struct uart_port *port) 144 - { 145 - /* Turn on Tx interrupts. The port lock is held at this point */ 146 - unsigned int reg_v; 147 - 148 - reg_v = readl(port->membase + IE); 149 - writel((reg_v | TX_FIFO_EMPTYE), port->membase + IE); 150 - 151 - reg_v = readl(port->membase + CFG); 152 - writel(reg_v | CFG_TX_EN, port->membase + CFG); 153 - 154 - if (readl(port->membase + INFO) & INFO_TX_EMPTY) 155 - cortina_transmit_buffer(port); 156 - } 157 - 158 - static void cortina_uart_stop_rx(struct uart_port *port) 159 - { 160 - /* Turn off Rx interrupts. The port lock is held at this point */ 161 - unsigned int reg_v; 162 - 163 - reg_v = readl(port->membase + IE); 164 - writel(reg_v & ~RX_FIFO_NONEMPTYE, port->membase + IE); 165 - } 166 - 167 - static void cortina_uart_enable_ms(struct uart_port *port) 168 - { 169 - /* Nope, you really can't hope to attach a modem to this */ 170 - } 171 - 172 - static int cortina_uart_startup(struct uart_port *port) 173 - { 174 - unsigned int reg_v; 175 - int retval; 176 - unsigned long flags; 177 - 178 - /* Disable interrupt */ 179 - writel(0, port->membase + IE); 180 - 181 - retval = 182 - request_irq(port->irq, cortina_uart_interrupt, 0, "cortina_uart", 183 - port); 184 - if (retval) 185 - return retval; 186 - 187 - spin_lock_irqsave(&port->lock, flags); 188 - 189 - reg_v = readl(port->membase + CFG); 190 - reg_v |= (CFG_UART_EN | CFG_TX_EN | CFG_RX_EN | 0x3 /* 8-bits data */); 191 - writel(reg_v, port->membase + CFG); 192 - reg_v = readl(port->membase + IE); 193 - writel(reg_v | RX_FIFO_NONEMPTYE | TX_FIFO_EMPTYE, port->membase + IE); 194 - 195 - spin_unlock_irqrestore(&port->lock, flags); 196 - return 0; 197 - } 198 - 199 - static void cortina_uart_shutdown(struct uart_port *port) 200 - { 201 - cortina_uart_stop_tx(port); 202 - cortina_uart_stop_rx(port); 203 - free_irq(port->irq, port); 204 - } 205 - 206 - static void cortina_uart_set_termios(struct uart_port *port, 207 - struct ktermios *termios, 208 - struct ktermios *old) 209 - { 210 - unsigned long flags; 211 - int baud; 212 - unsigned int reg_v, sample_freq = 0; 213 - 214 - baud = uart_get_baud_rate(port, termios, old, 0, 230400); 215 - reg_v = readl(port->membase + CFG); 216 - /* mask off the baud settings */ 217 - reg_v &= 0xff; 218 - reg_v |= (port->uartclk / baud) << CFG_BAUD_SART_SHIFT; 219 - 220 - /* Sampling rate should be half of baud count */ 221 - sample_freq = (reg_v >> CFG_BAUD_SART_SHIFT) / 2; 222 - 223 - /* See include/uapi/asm-generic/termbits.h for CSIZE definition */ 224 - /* mask off the data width */ 225 - reg_v &= 0xfffffffc; 226 - switch (termios->c_cflag & CSIZE) { 227 - case CS5: 228 - reg_v |= 0x0; 229 - break; 230 - case CS6: 231 - reg_v |= 0x1; 232 - break; 233 - case CS7: 234 - reg_v |= 0x2; 235 - break; 236 - case CS8: 237 - default: 238 - reg_v |= 0x3; 239 - break; 240 - } 241 - 242 - /* mask off Stop bits */ 243 - reg_v &= ~(CFG_STOP_2BIT); 244 - if (termios->c_cflag & CSTOPB) 245 - reg_v |= CFG_STOP_2BIT; 246 - 247 - /* Parity */ 248 - reg_v &= ~(CFG_PARITY_EN); 249 - reg_v |= CFG_PARITY_EVEN; 250 - if (termios->c_cflag & PARENB) { 251 - reg_v |= CFG_PARITY_EN; 252 - if (termios->c_cflag & PARODD) 253 - reg_v &= ~(CFG_PARITY_EVEN); 254 - } 255 - 256 - spin_lock_irqsave(&port->lock, flags); 257 - writel(reg_v, port->membase + CFG); 258 - writel(sample_freq, port->membase + RX_SAMPLE); 259 - spin_unlock_irqrestore(&port->lock, flags); 260 - } 261 - 262 - static const char *cortina_uart_type(struct uart_port *port) 263 - { 264 - return container_of(port, struct cortina_uart_port, uart)->name; 265 - } 266 - 267 - static void cortina_uart_config_port(struct uart_port *port, int flags) 268 - { 269 - /* 270 - * Driver core for serial ports forces a non-zero value for port type. 271 - * Write an arbitrary value here to accommodate the serial core driver, 272 - * as ID part of UAPI is redundant. 273 - */ 274 - port->type = 1; 275 - } 276 - 277 - static int cortina_uart_verify_port(struct uart_port *port, 278 - struct serial_struct *ser) 279 - { 280 - if (ser->type != PORT_UNKNOWN && ser->type != 1) 281 - return -EINVAL; 282 - return 0; 283 - } 284 - 285 - static void cortina_access_power(struct uart_port *port, unsigned int state, 286 - unsigned int oldstate) 287 - { 288 - unsigned int reg_v; 289 - 290 - /* Read Config register */ 291 - reg_v = readl(port->membase + CFG); 292 - switch (state) { 293 - case UART_PM_STATE_ON: 294 - reg_v |= CFG_UART_EN; 295 - break; 296 - case UART_PM_STATE_OFF: 297 - reg_v &= ~CFG_UART_EN; 298 - break; 299 - default: 300 - pr_err("cortina-access serial: Unknown PM state %d\n", state); 301 - } 302 - writel(reg_v, port->membase + CFG); 303 - } 304 - 305 - #ifdef CONFIG_CONSOLE_POLL 306 - static int cortina_poll_get_char(struct uart_port *port) 307 - { 308 - unsigned int rx; 309 - 310 - if (readl(port->membase + INFO) & INFO_RX_EMPTY) 311 - return NO_POLL_CHAR; 312 - 313 - rx = readl(port->membase + RX_DAT); 314 - 315 - return rx; 316 - } 317 - 318 - static void cortina_poll_put_char(struct uart_port *port, unsigned char c) 319 - { 320 - unsigned long time_out; 321 - 322 - time_out = jiffies + usecs_to_jiffies(TX_TIMEOUT); 323 - 324 - while (time_before(jiffies, time_out) && 325 - (readl(port->membase + INFO) & INFO_TX_FULL)) 326 - cpu_relax(); 327 - 328 - /* Give up if FIFO stuck! */ 329 - if ((readl(port->membase + INFO) & INFO_TX_FULL)) 330 - return; 331 - 332 - writel(c, port->membase + TX_DAT); 333 - } 334 - 335 - #endif 336 - 337 - static const struct uart_ops cortina_uart_ops = { 338 - .tx_empty = cortina_uart_tx_empty, 339 - .set_mctrl = cortina_uart_set_mctrl, 340 - .get_mctrl = cortina_uart_get_mctrl, 341 - .stop_tx = cortina_uart_stop_tx, 342 - .start_tx = cortina_uart_start_tx, 343 - .stop_rx = cortina_uart_stop_rx, 344 - .enable_ms = cortina_uart_enable_ms, 345 - .startup = cortina_uart_startup, 346 - .shutdown = cortina_uart_shutdown, 347 - .set_termios = cortina_uart_set_termios, 348 - .type = cortina_uart_type, 349 - .config_port = cortina_uart_config_port, 350 - .verify_port = cortina_uart_verify_port, 351 - .pm = cortina_access_power, 352 - #ifdef CONFIG_CONSOLE_POLL 353 - .poll_get_char = cortina_poll_get_char, 354 - .poll_put_char = cortina_poll_put_char, 355 - #endif 356 - }; 357 - 358 - static inline void cortina_uart_interrupt_rx_chars(struct uart_port *port, 359 - unsigned long status) 360 - { 361 - struct tty_port *ttyport = &port->state->port; 362 - unsigned int ch; 363 - unsigned int rx, flg; 364 - struct cortina_uart_port *pca_port; 365 - 366 - rx = readl(port->membase + INFO); 367 - if (INFO_RX_EMPTY & rx) 368 - return; 369 - 370 - if (status & RX_FIFO_OVERRUNE) 371 - port->icount.overrun++; 372 - 373 - pca_port = cortina_uart_get_port(port->line); 374 - 375 - /* Read the character while FIFO is not empty */ 376 - do { 377 - flg = TTY_NORMAL; 378 - port->icount.rx++; 379 - ch = readl(port->membase + RX_DAT); 380 - if (status & RX_PARITY_ERRE) { 381 - port->icount.parity++; 382 - flg = TTY_PARITY; 383 - } 384 - 385 - if (pca_port->has_bi) { 386 - /* If BI supported ? */ 387 - if (status & RX_BREAK) { 388 - port->icount.brk++; 389 - if (uart_handle_break(port)) 390 - goto ignore; 391 - } 392 - } else { 393 - /* Treat stop err as BI */ 394 - if (status & RX_STOP_ERRE) { 395 - port->icount.brk++; 396 - if (uart_handle_break(port)) 397 - goto ignore; 398 - } 399 - } 400 - if (!(ch & 0x100)) /* RX char is not valid */ 401 - goto ignore; 402 - 403 - if (uart_handle_sysrq_char(port, (unsigned char)ch)) 404 - goto ignore; 405 - 406 - tty_insert_flip_char(ttyport, ch, flg); 407 - ignore: 408 - rx = readl(port->membase + INFO); 409 - } while (!(INFO_RX_EMPTY & rx)); 410 - 411 - spin_unlock(&port->lock); 412 - tty_flip_buffer_push(ttyport); 413 - spin_lock(&port->lock); 414 - } 415 - 416 - static inline void cortina_uart_interrupt_tx_chars(struct uart_port *port) 417 - { 418 - struct circ_buf *xmit = &port->state->xmit; 419 - 420 - /* Process out of band chars */ 421 - if (port->x_char) { 422 - /* Send next char */ 423 - writel(port->x_char, port->membase + TX_DAT); 424 - goto done; 425 - } 426 - 427 - /* Nothing to do ? */ 428 - if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 429 - cortina_uart_stop_tx(port); 430 - goto done; 431 - } 432 - 433 - cortina_transmit_buffer(port); 434 - 435 - /* Wake up */ 436 - if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 437 - uart_write_wakeup(port); 438 - 439 - /* Maybe we're done after all */ 440 - if (uart_circ_empty(xmit)) 441 - cortina_uart_stop_tx(port); 442 - 443 - done: 444 - return; 445 - } 446 - 447 - irqreturn_t cortina_uart_interrupt(int irq, void *dev_id) 448 - { 449 - struct uart_port *port = (struct uart_port *)dev_id; 450 - unsigned int irq_status; 451 - 452 - spin_lock(&port->lock); 453 - 454 - /* Clear interrupt! */ 455 - irq_status = readl(port->membase + INT); 456 - writel(irq_status, port->membase + INT); 457 - 458 - /* Process any Rx chars first */ 459 - cortina_uart_interrupt_rx_chars(port, irq_status); 460 - /* Then use any Tx space */ 461 - cortina_uart_interrupt_tx_chars(port); 462 - 463 - spin_unlock(&port->lock); 464 - 465 - return IRQ_HANDLED; 466 - } 467 - 468 - #ifdef CONFIG_SERIAL_CORTINA_ACCESS_CONSOLE 469 - void cortina_console_write(struct console *co, const char *s, 470 - unsigned int count) 471 - { 472 - struct uart_port *port; 473 - struct cortina_uart_port *pca_port; 474 - unsigned int i, previous; 475 - unsigned long flags; 476 - int locked; 477 - 478 - pca_port = cortina_uart_get_port(co->index); 479 - port = &pca_port->uart; 480 - 481 - local_irq_save(flags); 482 - if (port->sysrq) { 483 - locked = 0; 484 - } else if (oops_in_progress) { 485 - locked = spin_trylock(&port->lock); 486 - } else { 487 - spin_lock(&port->lock); 488 - locked = 1; 489 - } 490 - 491 - /* Save current state */ 492 - previous = readl(port->membase + IE); 493 - /* Disable Tx interrupts so this all goes out in one go */ 494 - cortina_uart_stop_tx(port); 495 - 496 - /* Write all the chars */ 497 - for (i = 0; i < count; i++) { 498 - /* Wait the TX buffer to be empty, which can't take forever */ 499 - while (!(readl(port->membase + INFO) & INFO_TX_EMPTY)) 500 - cpu_relax(); 501 - 502 - /* Send the char */ 503 - writel(*s, port->membase + TX_DAT); 504 - 505 - /* CR/LF stuff */ 506 - if (*s++ == '\n') { 507 - /* Wait the TX buffer to be empty */ 508 - while (!(readl(port->membase + INFO) & INFO_TX_EMPTY)) 509 - cpu_relax(); 510 - writel('\r', port->membase + TX_DAT); 511 - } 512 - } 513 - 514 - writel(previous, port->membase + IE); /* Put it all back */ 515 - 516 - if (locked) 517 - spin_unlock(&port->lock); 518 - local_irq_restore(flags); 519 - } 520 - 521 - static int __init cortina_console_setup(struct console *co, char *options) 522 - { 523 - struct uart_port *port; 524 - struct cortina_uart_port *pca_port; 525 - int baud = 115200; 526 - int bits = 8; 527 - int parity = 'n'; 528 - int flow = 'n'; 529 - 530 - if (co->index < 0 || co->index >= UART_NR) 531 - return -ENODEV; 532 - 533 - pca_port = cortina_uart_get_port(co->index); 534 - port = &pca_port->uart; 535 - 536 - /* This isn't going to do much, but it might change the baud rate. */ 537 - if (options) 538 - uart_parse_options(options, &baud, &parity, &bits, &flow); 539 - 540 - return uart_set_options(port, co, baud, parity, bits, flow); 541 - } 542 - 543 - static struct uart_driver cortina_uart_driver; 544 - 545 - static struct console cortina_console = { 546 - .name = "ttyS", 547 - .write = cortina_console_write, 548 - .device = uart_console_device, 549 - .setup = cortina_console_setup, 550 - .flags = CON_PRINTBUFFER, 551 - .index = -1, /* Only possible option. */ 552 - .data = &cortina_uart_driver, 553 - }; 554 - #define CORTINA_CONSOLE (&cortina_console) 555 - 556 - /* Support EARLYCON */ 557 - static void cortina_putc(struct uart_port *port, int c) 558 - { 559 - unsigned int tmout; 560 - 561 - /* No jiffie at early boot stage! 562 - * Wait up to 5ms for the character to be sent. 563 - */ 564 - tmout = TX_TIMEOUT; 565 - while (--tmout) { 566 - if (!(readl(port->membase + INFO) & INFO_TX_FULL)) 567 - break; 568 - udelay(1); 569 - } 570 - 571 - /* Give up if FIFO stuck! */ 572 - while ((readl(port->membase + INFO) & INFO_TX_FULL)) 573 - return; 574 - 575 - /* Send the char */ 576 - writel(c, port->membase + TX_DAT); 577 - } 578 - 579 - static void cortina_early_write(struct console *con, const char *s, 580 - unsigned int n) 581 - { 582 - struct earlycon_device *dev = con->data; 583 - 584 - uart_console_write(&dev->port, s, n, cortina_putc); 585 - } 586 - 587 - static int __init cortina_early_console_setup(struct earlycon_device *device, 588 - const char *opt) 589 - { 590 - if (!device->port.membase) 591 - return -ENODEV; 592 - 593 - device->con->write = cortina_early_write; 594 - return 0; 595 - } 596 - 597 - EARLYCON_DECLARE(serial, cortina_early_console_setup); 598 - OF_EARLYCON_DECLARE(serial, "cortina-access,serial", cortina_early_console_setup); 599 - #else 600 - #define CORTINA_CONSOLE NULL 601 - #endif 602 - 603 - static struct uart_driver cortina_uart_driver = { 604 - .owner = THIS_MODULE, 605 - .driver_name = "cortina-access_uart", 606 - .dev_name = "ttyS", 607 - .major = TTY_MAJOR, 608 - .minor = 64, 609 - .nr = UART_NR, 610 - .cons = CORTINA_CONSOLE, 611 - }; 612 - 613 - /* Match table for of_platform binding */ 614 - static const struct of_device_id cortina_uart_of_match[] = { 615 - {.compatible = "cortina-access,serial",}, 616 - {} 617 - }; 618 - MODULE_DEVICE_TABLE(of, cortina_uart_of_match); 619 - 620 - static int serial_cortina_probe(struct platform_device *pdev) 621 - { 622 - int ret; 623 - void __iomem *base; 624 - struct cortina_uart_port *port; 625 - const struct of_device_id *match; 626 - 627 - /* assign DT node pointer */ 628 - struct device_node *np = pdev->dev.of_node; 629 - struct resource mem_resource; 630 - u32 of_clock_frequency; 631 - struct clk *pclk_info; 632 - int uart_idx; 633 - 634 - /* search DT for a match */ 635 - match = of_match_device(cortina_uart_of_match, &pdev->dev); 636 - if (!match) 637 - return -EINVAL; 638 - 639 - if (cortina_uart_ports == NULL) 640 - cortina_uart_ports = kzalloc(UART_NR * sizeof(struct cortina_uart_port), 641 - GFP_KERNEL); 642 - 643 - port = cortina_uart_ports; 644 - for (uart_idx = 0; uart_idx < UART_NR; ++uart_idx) { 645 - /* Find first empty slot */ 646 - if (strlen(port->name) == 0) 647 - break; 648 - port++; 649 - } 650 - 651 - if (uart_idx >= UART_NR) 652 - return -EINVAL; 653 - 654 - snprintf(port->name, sizeof(port->name), "Cortina-Access UART%d", uart_idx); 655 - 656 - /* Retrieve HW base address */ 657 - ret = of_address_to_resource(np, 0, &mem_resource); 658 - if (ret) { 659 - dev_warn(&pdev->dev, "invalid address %d\n", ret); 660 - return ret; 661 - } 662 - 663 - base = devm_ioremap(&pdev->dev, mem_resource.start, 664 - resource_size(&mem_resource)); 665 - if (!base) { 666 - devm_kfree(&pdev->dev, port); 667 - return -ENOMEM; 668 - } 669 - 670 - /* assign reg base and irq from DT */ 671 - port->uart.irq = irq_of_parse_and_map(np, 0); 672 - port->uart.membase = base; 673 - port->uart.mapbase = mem_resource.start; 674 - port->uart.ops = &cortina_uart_ops; 675 - port->uart.dev = &pdev->dev; 676 - port->uart.line = uart_idx; 677 - port->uart.has_sysrq = IS_ENABLED(CONFIG_SERIAL_CORTINA_ACCESS_CONSOLE); 678 - 679 - /* get clock-freqency tuple from DT and store value */ 680 - if (of_property_read_u32(np, "clock-frequency", &of_clock_frequency)) { 681 - /* If we are here, it means DT node did not contain 682 - * clock-frequency tuple. Therefore, instead try to get 683 - * clk rate through the clk driver that DT has stated 684 - * we are consuming. 685 - */ 686 - pclk_info = clk_get(&pdev->dev, NULL); 687 - if (IS_ERR(pclk_info)) { 688 - dev_warn(&pdev->dev, 689 - "clk or clock-frequency not defined\n"); 690 - return PTR_ERR(pclk_info); 691 - } 692 - 693 - clk_prepare_enable(pclk_info); 694 - of_clock_frequency = clk_get_rate(pclk_info); 695 - } 696 - port->uart.uartclk = of_clock_frequency; 697 - 698 - if (of_property_read_bool(np, "wakeup-source")) 699 - port->may_wakeup = true; 700 - if (of_property_read_bool(np, "break-indicator")) 701 - port->has_bi = true; 702 - 703 - port->uart.type = PORT_UNKNOWN; 704 - 705 - if (port->may_wakeup) 706 - device_init_wakeup(&pdev->dev, true); 707 - 708 - ret = uart_add_one_port(&cortina_uart_driver, &port->uart); 709 - if (ret) 710 - return ret; 711 - 712 - platform_set_drvdata(pdev, port); 713 - 714 - return 0; 715 - } 716 - 717 - static int serial_cortina_remove(struct platform_device *pdev) 718 - { 719 - struct uart_port *port = platform_get_drvdata(pdev); 720 - struct cortina_uart_port *pca_port; 721 - 722 - if (port) { 723 - pca_port = cortina_uart_get_port(port->line); 724 - memset(pca_port->name, 0, CA_UART_NAME_LEN); 725 - uart_remove_one_port(&cortina_uart_driver, port); 726 - } 727 - 728 - platform_set_drvdata(pdev, NULL); 729 - return 0; 730 - } 731 - 732 - #ifdef CONFIG_PM 733 - static int serial_cortina_suspend(struct platform_device *pdev, 734 - pm_message_t state) 735 - { 736 - struct cortina_uart_port *p = 737 - (struct cortina_uart_port *)pdev->dev.driver_data; 738 - 739 - uart_suspend_port(&cortina_uart_driver, &p->uart); 740 - 741 - return 0; 742 - } 743 - 744 - static int serial_cortina_resume(struct platform_device *pdev) 745 - { 746 - struct cortina_uart_port *p = 747 - (struct cortina_uart_port *)pdev->dev.driver_data; 748 - 749 - uart_resume_port(&cortina_uart_driver, &p->uart); 750 - 751 - return 0; 752 - } 753 - #else 754 - #define serial_cortina_suspend NULL 755 - #define serial_cortina_resume NULL 756 - #endif 757 - 758 - static struct platform_driver serial_cortina_driver = { 759 - .probe = serial_cortina_probe, 760 - .remove = serial_cortina_remove, 761 - #ifdef CONFIG_PM 762 - .suspend = serial_cortina_suspend, 763 - .resume = serial_cortina_resume, 764 - #endif 765 - .driver = { 766 - .name = "cortina-access_serial", 767 - .owner = THIS_MODULE, 768 - .of_match_table = cortina_uart_of_match, 769 - }, 770 - }; 771 - 772 - static int __init cortina_uart_init(void) 773 - { 774 - int ret; 775 - 776 - ret = uart_register_driver(&cortina_uart_driver); 777 - if (ret) 778 - return ret; 779 - 780 - ret = platform_driver_register(&serial_cortina_driver); 781 - if (ret) 782 - uart_unregister_driver(&cortina_uart_driver); 783 - 784 - return ret; 785 - } 786 - 787 - static void __exit cortina_uart_exit(void) 788 - { 789 - platform_driver_unregister(&serial_cortina_driver); 790 - uart_unregister_driver(&cortina_uart_driver); 791 - } 792 - 793 - module_init(cortina_uart_init); 794 - module_exit(cortina_uart_exit); 795 - 796 - MODULE_AUTHOR("Cortina-Access Inc."); 797 - MODULE_DESCRIPTION(" Cortina-Access UART driver"); 798 - MODULE_LICENSE("GPL");