Skip to content

Commit 72d6819

Browse files
Michal Simekgregkh
authored andcommitted
Revert "serial: uartps: Change uart ID port allocation"
This reverts commit ae1cca3. With setting up NR_PORTS to 16 to be able to use serial2 and higher aliases and don't loose functionality which was intended by these changes. 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/a94931b65ce0089f76fb1fe6b446a08731bff754.1585905873.git.michal.simek@xilinx.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 91c9dfa commit 72d6819

File tree

1 file changed

+13
-98
lines changed

1 file changed

+13
-98
lines changed

drivers/tty/serial/xilinx_uartps.c

Lines changed: 13 additions & 98 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_NR_PORTS 16
3031
#define CDNS_UART_FIFO_SIZE 64 /* FIFO size */
3132
#define CDNS_UART_REGISTER_SPACE 0x1000
3233
#define TX_TIMEOUT 500000
@@ -1403,90 +1404,6 @@ static const struct of_device_id cdns_uart_of_match[] = {
14031404
};
14041405
MODULE_DEVICE_TABLE(of, cdns_uart_of_match);
14051406

1406-
/*
1407-
* Maximum number of instances without alias IDs but if there is alias
1408-
* which target "< MAX_UART_INSTANCES" range this ID can't be used.
1409-
*/
1410-
#define MAX_UART_INSTANCES 32
1411-
1412-
/* Stores static aliases list */
1413-
static DECLARE_BITMAP(alias_bitmap, MAX_UART_INSTANCES);
1414-
static int alias_bitmap_initialized;
1415-
1416-
/* Stores actual bitmap of allocated IDs with alias IDs together */
1417-
static DECLARE_BITMAP(bitmap, MAX_UART_INSTANCES);
1418-
/* Protect bitmap operations to have unique IDs */
1419-
static DEFINE_MUTEX(bitmap_lock);
1420-
1421-
static int cdns_get_id(struct platform_device *pdev)
1422-
{
1423-
int id, ret;
1424-
1425-
mutex_lock(&bitmap_lock);
1426-
1427-
/* Alias list is stable that's why get alias bitmap only once */
1428-
if (!alias_bitmap_initialized) {
1429-
ret = of_alias_get_alias_list(cdns_uart_of_match, "serial",
1430-
alias_bitmap, MAX_UART_INSTANCES);
1431-
if (ret && ret != -EOVERFLOW) {
1432-
mutex_unlock(&bitmap_lock);
1433-
return ret;
1434-
}
1435-
1436-
alias_bitmap_initialized++;
1437-
}
1438-
1439-
/* Make sure that alias ID is not taken by instance without alias */
1440-
bitmap_or(bitmap, bitmap, alias_bitmap, MAX_UART_INSTANCES);
1441-
1442-
dev_dbg(&pdev->dev, "Alias bitmap: %*pb\n",
1443-
MAX_UART_INSTANCES, bitmap);
1444-
1445-
/* Look for a serialN alias */
1446-
id = of_alias_get_id(pdev->dev.of_node, "serial");
1447-
if (id < 0) {
1448-
dev_warn(&pdev->dev,
1449-
"No serial alias passed. Using the first free id\n");
1450-
1451-
/*
1452-
* Start with id 0 and check if there is no serial0 alias
1453-
* which points to device which is compatible with this driver.
1454-
* If alias exists then try next free position.
1455-
*/
1456-
id = 0;
1457-
1458-
for (;;) {
1459-
dev_info(&pdev->dev, "Checking id %d\n", id);
1460-
id = find_next_zero_bit(bitmap, MAX_UART_INSTANCES, id);
1461-
1462-
/* No free empty instance */
1463-
if (id == MAX_UART_INSTANCES) {
1464-
dev_err(&pdev->dev, "No free ID\n");
1465-
mutex_unlock(&bitmap_lock);
1466-
return -EINVAL;
1467-
}
1468-
1469-
dev_dbg(&pdev->dev, "The empty id is %d\n", id);
1470-
/* Check if ID is empty */
1471-
if (!test_and_set_bit(id, bitmap)) {
1472-
/* Break the loop if bit is taken */
1473-
dev_dbg(&pdev->dev,
1474-
"Selected ID %d allocation passed\n",
1475-
id);
1476-
break;
1477-
}
1478-
dev_dbg(&pdev->dev,
1479-
"Selected ID %d allocation failed\n", id);
1480-
/* if taking bit fails then try next one */
1481-
id++;
1482-
}
1483-
}
1484-
1485-
mutex_unlock(&bitmap_lock);
1486-
1487-
return id;
1488-
}
1489-
14901407
/**
14911408
* cdns_uart_probe - Platform driver probe
14921409
* @pdev: Pointer to the platform device structure
@@ -1520,17 +1437,21 @@ static int cdns_uart_probe(struct platform_device *pdev)
15201437
if (!cdns_uart_uart_driver)
15211438
return -ENOMEM;
15221439

1523-
cdns_uart_data->id = cdns_get_id(pdev);
1440+
/* Look for a serialN alias */
1441+
cdns_uart_data->id = of_alias_get_id(pdev->dev.of_node, "serial");
15241442
if (cdns_uart_data->id < 0)
1525-
return cdns_uart_data->id;
1443+
cdns_uart_data->id = 0;
1444+
1445+
if (cdns_uart_data->id >= CDNS_UART_NR_PORTS) {
1446+
dev_err(&pdev->dev, "Cannot get uart_port structure\n");
1447+
return -ENODEV;
1448+
}
15261449

15271450
/* There is a need to use unique driver name */
15281451
driver_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s%d",
15291452
CDNS_UART_NAME, cdns_uart_data->id);
1530-
if (!driver_name) {
1531-
rc = -ENOMEM;
1532-
goto err_out_id;
1533-
}
1453+
if (!driver_name)
1454+
return -ENOMEM;
15341455

15351456
cdns_uart_uart_driver->owner = THIS_MODULE;
15361457
cdns_uart_uart_driver->driver_name = driver_name;
@@ -1559,7 +1480,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
15591480
rc = uart_register_driver(cdns_uart_uart_driver);
15601481
if (rc < 0) {
15611482
dev_err(&pdev->dev, "Failed to register driver\n");
1562-
goto err_out_id;
1483+
return rc;
15631484
}
15641485

15651486
cdns_uart_data->cdns_uart_driver = cdns_uart_uart_driver;
@@ -1710,10 +1631,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
17101631
clk_disable_unprepare(cdns_uart_data->pclk);
17111632
err_out_unregister_driver:
17121633
uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
1713-
err_out_id:
1714-
mutex_lock(&bitmap_lock);
1715-
clear_bit(cdns_uart_data->id, bitmap);
1716-
mutex_unlock(&bitmap_lock);
1634+
17171635
return rc;
17181636
}
17191637

@@ -1736,9 +1654,6 @@ static int cdns_uart_remove(struct platform_device *pdev)
17361654
#endif
17371655
rc = uart_remove_one_port(cdns_uart_data->cdns_uart_driver, port);
17381656
port->mapbase = 0;
1739-
mutex_lock(&bitmap_lock);
1740-
clear_bit(cdns_uart_data->id, bitmap);
1741-
mutex_unlock(&bitmap_lock);
17421657
clk_disable_unprepare(cdns_uart_data->uartclk);
17431658
clk_disable_unprepare(cdns_uart_data->pclk);
17441659
pm_runtime_disable(&pdev->dev);

0 commit comments

Comments
 (0)