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
@@ -1132,6 +1133,8 @@ static const struct uart_ops cdns_uart_ops = {
1132
1133
#endif
1133
1134
};
1134
1135
1136
+ static struct uart_driver cdns_uart_uart_driver ;
1137
+
1135
1138
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
1136
1139
/**
1137
1140
* 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)
1271
1274
1272
1275
return uart_set_options (port , co , baud , parity , bits , flow );
1273
1276
}
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
+ };
1274
1287
#endif /* CONFIG_SERIAL_XILINX_PS_UART_CONSOLE */
1275
1288
1276
1289
#ifdef CONFIG_PM_SLEEP
@@ -1402,6 +1415,9 @@ static const struct of_device_id cdns_uart_of_match[] = {
1402
1415
};
1403
1416
MODULE_DEVICE_TABLE (of , cdns_uart_of_match );
1404
1417
1418
+ /* Temporary variable for storing number of instances */
1419
+ static int instances ;
1420
+
1405
1421
/**
1406
1422
* cdns_uart_probe - Platform driver probe
1407
1423
* @pdev: Pointer to the platform device structure
@@ -1415,11 +1431,6 @@ static int cdns_uart_probe(struct platform_device *pdev)
1415
1431
struct resource * res ;
1416
1432
struct cdns_uart * cdns_uart_data ;
1417
1433
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
1423
1434
1424
1435
cdns_uart_data = devm_kzalloc (& pdev -> dev , sizeof (* cdns_uart_data ),
1425
1436
GFP_KERNEL );
@@ -1429,12 +1440,6 @@ static int cdns_uart_probe(struct platform_device *pdev)
1429
1440
if (!port )
1430
1441
return - ENOMEM ;
1431
1442
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
-
1438
1443
/* Look for a serialN alias */
1439
1444
id = of_alias_get_id (pdev -> dev .of_node , "serial" );
1440
1445
if (id < 0 )
@@ -1445,50 +1450,25 @@ static int cdns_uart_probe(struct platform_device *pdev)
1445
1450
return - ENODEV ;
1446
1451
}
1447
1452
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 ;
1461
1460
#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 ;
1476
1462
#endif
1477
1463
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
+ }
1482
1469
}
1483
1470
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 ;
1492
1472
1493
1473
match = of_match_node (cdns_uart_of_match , pdev -> dev .of_node );
1494
1474
if (match && match -> data ) {
@@ -1566,6 +1546,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
1566
1546
port -> ops = & cdns_uart_ops ;
1567
1547
port -> fifosize = CDNS_UART_FIFO_SIZE ;
1568
1548
port -> has_sysrq = IS_ENABLED (CONFIG_SERIAL_XILINX_PS_UART_CONSOLE );
1549
+ port -> line = id ;
1569
1550
1570
1551
/*
1571
1552
* Register the port.
@@ -1597,7 +1578,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
1597
1578
console_port = port ;
1598
1579
#endif
1599
1580
1600
- rc = uart_add_one_port (cdns_uart_uart_driver , port );
1581
+ rc = uart_add_one_port (& cdns_uart_uart_driver , port );
1601
1582
if (rc ) {
1602
1583
dev_err (& pdev -> dev ,
1603
1584
"uart_add_one_port() failed; err=%i\n" , rc );
@@ -1607,12 +1588,15 @@ static int cdns_uart_probe(struct platform_device *pdev)
1607
1588
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
1608
1589
/* This is not port which is used for console that's why clean it up */
1609
1590
if (console_port == port &&
1610
- !(cdns_uart_uart_driver -> cons -> flags & CON_ENABLED ))
1591
+ !(cdns_uart_uart_driver . cons -> flags & CON_ENABLED ))
1611
1592
console_port = NULL ;
1612
1593
#endif
1613
1594
1614
1595
cdns_uart_data -> cts_override = of_property_read_bool (pdev -> dev .of_node ,
1615
1596
"cts-override" );
1597
+
1598
+ instances ++ ;
1599
+
1616
1600
return 0 ;
1617
1601
1618
1602
err_out_pm_disable :
@@ -1628,8 +1612,8 @@ static int cdns_uart_probe(struct platform_device *pdev)
1628
1612
err_out_clk_dis_pclk :
1629
1613
clk_disable_unprepare (cdns_uart_data -> pclk );
1630
1614
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 );
1633
1617
return rc ;
1634
1618
}
1635
1619
@@ -1664,7 +1648,8 @@ static int cdns_uart_remove(struct platform_device *pdev)
1664
1648
console_port = NULL ;
1665
1649
#endif
1666
1650
1667
- uart_unregister_driver (cdns_uart_data -> cdns_uart_driver );
1651
+ if (!-- instances )
1652
+ uart_unregister_driver (cdns_uart_data -> cdns_uart_driver );
1668
1653
return rc ;
1669
1654
}
1670
1655
0 commit comments