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

Revert "serial: uartps: Register own uart console and driver structures"

This reverts commit 024ca329bfb9a948f76eaff3243e21b7e70182f2.

As Johan says, this driver needs a lot more work and these changes are
only going in the wrong direction:
https://lkml.kernel.org/r/20190523091839.GC568@localhost

Reported-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/1ee35667e36a8efddee381df5fe495ad65f4d15c.1585905873.git.michal.simek@xilinx.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Michal Simek and committed by
Greg Kroah-Hartman
18cc7ac8 492cc08b

+40 -55
+40 -55
drivers/tty/serial/xilinx_uartps.c
··· 27 27 #define CDNS_UART_TTY_NAME "ttyPS" 28 28 #define CDNS_UART_NAME "xuartps" 29 29 #define CDNS_UART_MAJOR 0 /* use dynamic node allocation */ 30 + #define CDNS_UART_MINOR 0 /* works best with devtmpfs */ 30 31 #define CDNS_UART_NR_PORTS 16 31 32 #define CDNS_UART_FIFO_SIZE 64 /* FIFO size */ 32 33 #define CDNS_UART_REGISTER_SPACE 0x1000 ··· 1133 1132 #endif 1134 1133 }; 1135 1134 1135 + static struct uart_driver cdns_uart_uart_driver; 1136 + 1136 1137 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE 1137 1138 /** 1138 1139 * cdns_uart_console_putchar - write the character to the FIFO buffer ··· 1274 1271 1275 1272 return uart_set_options(port, co, baud, parity, bits, flow); 1276 1273 } 1274 + 1275 + static struct console cdns_uart_console = { 1276 + .name = CDNS_UART_TTY_NAME, 1277 + .write = cdns_uart_console_write, 1278 + .device = uart_console_device, 1279 + .setup = cdns_uart_console_setup, 1280 + .flags = CON_PRINTBUFFER, 1281 + .index = -1, /* Specified on the cmdline (e.g. console=ttyPS ) */ 1282 + .data = &cdns_uart_uart_driver, 1283 + }; 1277 1284 #endif /* CONFIG_SERIAL_XILINX_PS_UART_CONSOLE */ 1278 1285 1279 1286 #ifdef CONFIG_PM_SLEEP ··· 1415 1402 }; 1416 1403 MODULE_DEVICE_TABLE(of, cdns_uart_of_match); 1417 1404 1405 + /* Temporary variable for storing number of instances */ 1406 + static int instances; 1407 + 1418 1408 /** 1419 1409 * cdns_uart_probe - Platform driver probe 1420 1410 * @pdev: Pointer to the platform device structure ··· 1431 1415 struct resource *res; 1432 1416 struct cdns_uart *cdns_uart_data; 1433 1417 const struct of_device_id *match; 1434 - struct uart_driver *cdns_uart_uart_driver; 1435 - char *driver_name; 1436 - #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE 1437 - struct console *cdns_uart_console; 1438 - #endif 1439 1418 1440 1419 cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data), 1441 1420 GFP_KERNEL); ··· 1438 1427 return -ENOMEM; 1439 1428 port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); 1440 1429 if (!port) 1441 - return -ENOMEM; 1442 - 1443 - cdns_uart_uart_driver = devm_kzalloc(&pdev->dev, 1444 - sizeof(*cdns_uart_uart_driver), 1445 - GFP_KERNEL); 1446 - if (!cdns_uart_uart_driver) 1447 1430 return -ENOMEM; 1448 1431 1449 1432 /* Look for a serialN alias */ ··· 1450 1445 return -ENODEV; 1451 1446 } 1452 1447 1453 - /* There is a need to use unique driver name */ 1454 - driver_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s%d", 1455 - CDNS_UART_NAME, id); 1456 - if (!driver_name) 1457 - return -ENOMEM; 1458 - 1459 - cdns_uart_uart_driver->owner = THIS_MODULE; 1460 - cdns_uart_uart_driver->driver_name = driver_name; 1461 - cdns_uart_uart_driver->dev_name = CDNS_UART_TTY_NAME; 1462 - cdns_uart_uart_driver->major = CDNS_UART_MAJOR; 1463 - cdns_uart_uart_driver->minor = id; 1464 - cdns_uart_uart_driver->nr = 1; 1465 - 1448 + if (!cdns_uart_uart_driver.state) { 1449 + cdns_uart_uart_driver.owner = THIS_MODULE; 1450 + cdns_uart_uart_driver.driver_name = CDNS_UART_NAME; 1451 + cdns_uart_uart_driver.dev_name = CDNS_UART_TTY_NAME; 1452 + cdns_uart_uart_driver.major = CDNS_UART_MAJOR; 1453 + cdns_uart_uart_driver.minor = CDNS_UART_MINOR; 1454 + cdns_uart_uart_driver.nr = CDNS_UART_NR_PORTS; 1466 1455 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE 1467 - cdns_uart_console = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_console), 1468 - GFP_KERNEL); 1469 - if (!cdns_uart_console) 1470 - return -ENOMEM; 1471 - 1472 - strncpy(cdns_uart_console->name, CDNS_UART_TTY_NAME, 1473 - sizeof(cdns_uart_console->name)); 1474 - cdns_uart_console->index = id; 1475 - cdns_uart_console->write = cdns_uart_console_write; 1476 - cdns_uart_console->device = uart_console_device; 1477 - cdns_uart_console->setup = cdns_uart_console_setup; 1478 - cdns_uart_console->flags = CON_PRINTBUFFER; 1479 - cdns_uart_console->data = cdns_uart_uart_driver; 1480 - cdns_uart_uart_driver->cons = cdns_uart_console; 1456 + cdns_uart_uart_driver.cons = &cdns_uart_console; 1481 1457 #endif 1482 1458 1483 - rc = uart_register_driver(cdns_uart_uart_driver); 1484 - if (rc < 0) { 1485 - dev_err(&pdev->dev, "Failed to register driver\n"); 1486 - return rc; 1459 + rc = uart_register_driver(&cdns_uart_uart_driver); 1460 + if (rc < 0) { 1461 + dev_err(&pdev->dev, "Failed to register driver\n"); 1462 + return rc; 1463 + } 1487 1464 } 1488 1465 1489 - cdns_uart_data->cdns_uart_driver = cdns_uart_uart_driver; 1490 - 1491 - /* 1492 - * Setting up proper name_base needs to be done after uart 1493 - * registration because tty_driver structure is not filled. 1494 - * name_base is 0 by default. 1495 - */ 1496 - cdns_uart_uart_driver->tty_driver->name_base = id; 1466 + cdns_uart_data->cdns_uart_driver = &cdns_uart_uart_driver; 1497 1467 1498 1468 match = of_match_node(cdns_uart_of_match, pdev->dev.of_node); 1499 1469 if (match && match->data) { ··· 1546 1566 port->ops = &cdns_uart_ops; 1547 1567 port->fifosize = CDNS_UART_FIFO_SIZE; 1548 1568 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_XILINX_PS_UART_CONSOLE); 1569 + port->line = id; 1549 1570 1550 1571 /* 1551 1572 * Register the port. ··· 1578 1597 console_port = port; 1579 1598 #endif 1580 1599 1581 - rc = uart_add_one_port(cdns_uart_uart_driver, port); 1600 + rc = uart_add_one_port(&cdns_uart_uart_driver, port); 1582 1601 if (rc) { 1583 1602 dev_err(&pdev->dev, 1584 1603 "uart_add_one_port() failed; err=%i\n", rc); ··· 1588 1607 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE 1589 1608 /* This is not port which is used for console that's why clean it up */ 1590 1609 if (console_port == port && 1591 - !(cdns_uart_uart_driver->cons->flags & CON_ENABLED)) 1610 + !(cdns_uart_uart_driver.cons->flags & CON_ENABLED)) 1592 1611 console_port = NULL; 1593 1612 #endif 1594 1613 1595 1614 cdns_uart_data->cts_override = of_property_read_bool(pdev->dev.of_node, 1596 1615 "cts-override"); 1616 + 1617 + instances++; 1618 + 1597 1619 return 0; 1598 1620 1599 1621 err_out_pm_disable: ··· 1612 1628 err_out_clk_dis_pclk: 1613 1629 clk_disable_unprepare(cdns_uart_data->pclk); 1614 1630 err_out_unregister_driver: 1615 - uart_unregister_driver(cdns_uart_data->cdns_uart_driver); 1616 - 1631 + if (!instances) 1632 + uart_unregister_driver(cdns_uart_data->cdns_uart_driver); 1617 1633 return rc; 1618 1634 } 1619 1635 ··· 1648 1664 console_port = NULL; 1649 1665 #endif 1650 1666 1651 - uart_unregister_driver(cdns_uart_data->cdns_uart_driver); 1667 + if (!--instances) 1668 + uart_unregister_driver(cdns_uart_data->cdns_uart_driver); 1652 1669 return rc; 1653 1670 } 1654 1671