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_NR_PORTS 16
30
31
#define CDNS_UART_FIFO_SIZE 64 /* FIFO size */
31
32
#define CDNS_UART_REGISTER_SPACE 0x1000
32
33
#define TX_TIMEOUT 500000
@@ -1403,90 +1404,6 @@ static const struct of_device_id cdns_uart_of_match[] = {
1403
1404
};
1404
1405
MODULE_DEVICE_TABLE (of , cdns_uart_of_match );
1405
1406
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
-
1490
1407
/**
1491
1408
* cdns_uart_probe - Platform driver probe
1492
1409
* @pdev: Pointer to the platform device structure
@@ -1520,17 +1437,21 @@ static int cdns_uart_probe(struct platform_device *pdev)
1520
1437
if (!cdns_uart_uart_driver )
1521
1438
return - ENOMEM ;
1522
1439
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" );
1524
1442
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
+ }
1526
1449
1527
1450
/* There is a need to use unique driver name */
1528
1451
driver_name = devm_kasprintf (& pdev -> dev , GFP_KERNEL , "%s%d" ,
1529
1452
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 ;
1534
1455
1535
1456
cdns_uart_uart_driver -> owner = THIS_MODULE ;
1536
1457
cdns_uart_uart_driver -> driver_name = driver_name ;
@@ -1559,7 +1480,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
1559
1480
rc = uart_register_driver (cdns_uart_uart_driver );
1560
1481
if (rc < 0 ) {
1561
1482
dev_err (& pdev -> dev , "Failed to register driver\n" );
1562
- goto err_out_id ;
1483
+ return rc ;
1563
1484
}
1564
1485
1565
1486
cdns_uart_data -> cdns_uart_driver = cdns_uart_uart_driver ;
@@ -1710,10 +1631,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
1710
1631
clk_disable_unprepare (cdns_uart_data -> pclk );
1711
1632
err_out_unregister_driver :
1712
1633
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
+
1717
1635
return rc ;
1718
1636
}
1719
1637
@@ -1736,9 +1654,6 @@ static int cdns_uart_remove(struct platform_device *pdev)
1736
1654
#endif
1737
1655
rc = uart_remove_one_port (cdns_uart_data -> cdns_uart_driver , port );
1738
1656
port -> mapbase = 0 ;
1739
- mutex_lock (& bitmap_lock );
1740
- clear_bit (cdns_uart_data -> id , bitmap );
1741
- mutex_unlock (& bitmap_lock );
1742
1657
clk_disable_unprepare (cdns_uart_data -> uartclk );
1743
1658
clk_disable_unprepare (cdns_uart_data -> pclk );
1744
1659
pm_runtime_disable (& pdev -> dev );
0 commit comments