Skip to content

Commit 18cc7ac

Browse files
Michal Simekgregkh
authored andcommitted
Revert "serial: uartps: Register own uart console and driver structures"
This reverts commit 024ca32. 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 <[email protected]> Signed-off-by: Michal Simek <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/1ee35667e36a8efddee381df5fe495ad65f4d15c.1585905873.git.michal.simek@xilinx.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 492cc08 commit 18cc7ac

File tree

1 file changed

+40
-55
lines changed

1 file changed

+40
-55
lines changed

drivers/tty/serial/xilinx_uartps.c

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define CDNS_UART_TTY_NAME "ttyPS"
2828
#define CDNS_UART_NAME "xuartps"
2929
#define CDNS_UART_MAJOR 0 /* use dynamic node allocation */
30+
#define CDNS_UART_MINOR 0 /* works best with devtmpfs */
3031
#define CDNS_UART_NR_PORTS 16
3132
#define CDNS_UART_FIFO_SIZE 64 /* FIFO size */
3233
#define CDNS_UART_REGISTER_SPACE 0x1000
@@ -1132,6 +1133,8 @@ static const struct uart_ops cdns_uart_ops = {
11321133
#endif
11331134
};
11341135

1136+
static struct uart_driver cdns_uart_uart_driver;
1137+
11351138
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
11361139
/**
11371140
* cdns_uart_console_putchar - write the character to the FIFO buffer
@@ -1271,6 +1274,16 @@ static int cdns_uart_console_setup(struct console *co, char *options)
12711274

12721275
return uart_set_options(port, co, baud, parity, bits, flow);
12731276
}
1277+
1278+
static struct console cdns_uart_console = {
1279+
.name = CDNS_UART_TTY_NAME,
1280+
.write = cdns_uart_console_write,
1281+
.device = uart_console_device,
1282+
.setup = cdns_uart_console_setup,
1283+
.flags = CON_PRINTBUFFER,
1284+
.index = -1, /* Specified on the cmdline (e.g. console=ttyPS ) */
1285+
.data = &cdns_uart_uart_driver,
1286+
};
12741287
#endif /* CONFIG_SERIAL_XILINX_PS_UART_CONSOLE */
12751288

12761289
#ifdef CONFIG_PM_SLEEP
@@ -1402,6 +1415,9 @@ static const struct of_device_id cdns_uart_of_match[] = {
14021415
};
14031416
MODULE_DEVICE_TABLE(of, cdns_uart_of_match);
14041417

1418+
/* Temporary variable for storing number of instances */
1419+
static int instances;
1420+
14051421
/**
14061422
* cdns_uart_probe - Platform driver probe
14071423
* @pdev: Pointer to the platform device structure
@@ -1415,11 +1431,6 @@ static int cdns_uart_probe(struct platform_device *pdev)
14151431
struct resource *res;
14161432
struct cdns_uart *cdns_uart_data;
14171433
const struct of_device_id *match;
1418-
struct uart_driver *cdns_uart_uart_driver;
1419-
char *driver_name;
1420-
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
1421-
struct console *cdns_uart_console;
1422-
#endif
14231434

14241435
cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data),
14251436
GFP_KERNEL);
@@ -1429,12 +1440,6 @@ static int cdns_uart_probe(struct platform_device *pdev)
14291440
if (!port)
14301441
return -ENOMEM;
14311442

1432-
cdns_uart_uart_driver = devm_kzalloc(&pdev->dev,
1433-
sizeof(*cdns_uart_uart_driver),
1434-
GFP_KERNEL);
1435-
if (!cdns_uart_uart_driver)
1436-
return -ENOMEM;
1437-
14381443
/* Look for a serialN alias */
14391444
id = of_alias_get_id(pdev->dev.of_node, "serial");
14401445
if (id < 0)
@@ -1445,50 +1450,25 @@ static int cdns_uart_probe(struct platform_device *pdev)
14451450
return -ENODEV;
14461451
}
14471452

1448-
/* There is a need to use unique driver name */
1449-
driver_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s%d",
1450-
CDNS_UART_NAME, id);
1451-
if (!driver_name)
1452-
return -ENOMEM;
1453-
1454-
cdns_uart_uart_driver->owner = THIS_MODULE;
1455-
cdns_uart_uart_driver->driver_name = driver_name;
1456-
cdns_uart_uart_driver->dev_name = CDNS_UART_TTY_NAME;
1457-
cdns_uart_uart_driver->major = CDNS_UART_MAJOR;
1458-
cdns_uart_uart_driver->minor = id;
1459-
cdns_uart_uart_driver->nr = 1;
1460-
1453+
if (!cdns_uart_uart_driver.state) {
1454+
cdns_uart_uart_driver.owner = THIS_MODULE;
1455+
cdns_uart_uart_driver.driver_name = CDNS_UART_NAME;
1456+
cdns_uart_uart_driver.dev_name = CDNS_UART_TTY_NAME;
1457+
cdns_uart_uart_driver.major = CDNS_UART_MAJOR;
1458+
cdns_uart_uart_driver.minor = CDNS_UART_MINOR;
1459+
cdns_uart_uart_driver.nr = CDNS_UART_NR_PORTS;
14611460
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
1462-
cdns_uart_console = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_console),
1463-
GFP_KERNEL);
1464-
if (!cdns_uart_console)
1465-
return -ENOMEM;
1466-
1467-
strncpy(cdns_uart_console->name, CDNS_UART_TTY_NAME,
1468-
sizeof(cdns_uart_console->name));
1469-
cdns_uart_console->index = id;
1470-
cdns_uart_console->write = cdns_uart_console_write;
1471-
cdns_uart_console->device = uart_console_device;
1472-
cdns_uart_console->setup = cdns_uart_console_setup;
1473-
cdns_uart_console->flags = CON_PRINTBUFFER;
1474-
cdns_uart_console->data = cdns_uart_uart_driver;
1475-
cdns_uart_uart_driver->cons = cdns_uart_console;
1461+
cdns_uart_uart_driver.cons = &cdns_uart_console;
14761462
#endif
14771463

1478-
rc = uart_register_driver(cdns_uart_uart_driver);
1479-
if (rc < 0) {
1480-
dev_err(&pdev->dev, "Failed to register driver\n");
1481-
return rc;
1464+
rc = uart_register_driver(&cdns_uart_uart_driver);
1465+
if (rc < 0) {
1466+
dev_err(&pdev->dev, "Failed to register driver\n");
1467+
return rc;
1468+
}
14821469
}
14831470

1484-
cdns_uart_data->cdns_uart_driver = cdns_uart_uart_driver;
1485-
1486-
/*
1487-
* Setting up proper name_base needs to be done after uart
1488-
* registration because tty_driver structure is not filled.
1489-
* name_base is 0 by default.
1490-
*/
1491-
cdns_uart_uart_driver->tty_driver->name_base = id;
1471+
cdns_uart_data->cdns_uart_driver = &cdns_uart_uart_driver;
14921472

14931473
match = of_match_node(cdns_uart_of_match, pdev->dev.of_node);
14941474
if (match && match->data) {
@@ -1566,6 +1546,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
15661546
port->ops = &cdns_uart_ops;
15671547
port->fifosize = CDNS_UART_FIFO_SIZE;
15681548
port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_XILINX_PS_UART_CONSOLE);
1549+
port->line = id;
15691550

15701551
/*
15711552
* Register the port.
@@ -1597,7 +1578,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
15971578
console_port = port;
15981579
#endif
15991580

1600-
rc = uart_add_one_port(cdns_uart_uart_driver, port);
1581+
rc = uart_add_one_port(&cdns_uart_uart_driver, port);
16011582
if (rc) {
16021583
dev_err(&pdev->dev,
16031584
"uart_add_one_port() failed; err=%i\n", rc);
@@ -1607,12 +1588,15 @@ static int cdns_uart_probe(struct platform_device *pdev)
16071588
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
16081589
/* This is not port which is used for console that's why clean it up */
16091590
if (console_port == port &&
1610-
!(cdns_uart_uart_driver->cons->flags & CON_ENABLED))
1591+
!(cdns_uart_uart_driver.cons->flags & CON_ENABLED))
16111592
console_port = NULL;
16121593
#endif
16131594

16141595
cdns_uart_data->cts_override = of_property_read_bool(pdev->dev.of_node,
16151596
"cts-override");
1597+
1598+
instances++;
1599+
16161600
return 0;
16171601

16181602
err_out_pm_disable:
@@ -1628,8 +1612,8 @@ static int cdns_uart_probe(struct platform_device *pdev)
16281612
err_out_clk_dis_pclk:
16291613
clk_disable_unprepare(cdns_uart_data->pclk);
16301614
err_out_unregister_driver:
1631-
uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
1632-
1615+
if (!instances)
1616+
uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
16331617
return rc;
16341618
}
16351619

@@ -1664,7 +1648,8 @@ static int cdns_uart_remove(struct platform_device *pdev)
16641648
console_port = NULL;
16651649
#endif
16661650

1667-
uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
1651+
if (!--instances)
1652+
uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
16681653
return rc;
16691654
}
16701655

0 commit comments

Comments
 (0)