forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/tty/serial/uartlite.c
....@@ -32,7 +32,7 @@
3232 * Register definitions
3333 *
3434 * For register details see datasheet:
35
- * http://www.xilinx.com/support/documentation/ip_documentation/opb_uartlite.pdf
35
+ * https://www.xilinx.com/support/documentation/ip_documentation/opb_uartlite.pdf
3636 */
3737
3838 #define ULITE_RX 0x00
....@@ -54,6 +54,11 @@
5454 #define ULITE_CONTROL_RST_TX 0x01
5555 #define ULITE_CONTROL_RST_RX 0x02
5656 #define ULITE_CONTROL_IE 0x10
57
+
58
+/* Static pointer to console port */
59
+#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
60
+static struct uart_port *console_port;
61
+#endif
5762
5863 struct uartlite_data {
5964 const struct uartlite_reg_ops *reg_ops;
....@@ -472,7 +477,7 @@
472477 static void ulite_console_write(struct console *co, const char *s,
473478 unsigned int count)
474479 {
475
- struct uart_port *port = &ulite_ports[co->index];
480
+ struct uart_port *port = console_port;
476481 unsigned long flags;
477482 unsigned int ier;
478483 int locked = 1;
....@@ -500,22 +505,22 @@
500505
501506 static int ulite_console_setup(struct console *co, char *options)
502507 {
503
- struct uart_port *port;
508
+ struct uart_port *port = NULL;
504509 int baud = 9600;
505510 int bits = 8;
506511 int parity = 'n';
507512 int flow = 'n';
508513
509
- if (co->index < 0 || co->index >= ULITE_NR_UARTS)
510
- return -EINVAL;
511
-
512
- port = &ulite_ports[co->index];
514
+ if (co->index >= 0 && co->index < ULITE_NR_UARTS)
515
+ port = ulite_ports + co->index;
513516
514517 /* Has the device been initialized yet? */
515
- if (!port->mapbase) {
518
+ if (!port || !port->mapbase) {
516519 pr_debug("console on ttyUL%i not present\n", co->index);
517520 return -ENODEV;
518521 }
522
+
523
+ console_port = port;
519524
520525 /* not initialized yet? */
521526 if (!port->membase) {
....@@ -540,14 +545,6 @@
540545 .index = -1, /* Specified on the cmdline (e.g. console=ttyUL0 ) */
541546 .data = &ulite_uart_driver,
542547 };
543
-
544
-static int __init ulite_console_init(void)
545
-{
546
- register_console(&ulite_console);
547
- return 0;
548
-}
549
-
550
-console_initcall(ulite_console_init);
551548
552549 static void early_uartlite_putc(struct uart_port *port, int c)
553550 {
....@@ -776,13 +773,26 @@
776773 pdata->clk = NULL;
777774 }
778775
779
- ret = clk_prepare(pdata->clk);
776
+ ret = clk_prepare_enable(pdata->clk);
780777 if (ret) {
781778 dev_err(&pdev->dev, "Failed to prepare clock\n");
782779 return ret;
783780 }
784781
785
- return ulite_assign(&pdev->dev, id, res->start, irq, pdata);
782
+ if (!ulite_uart_driver.state) {
783
+ dev_dbg(&pdev->dev, "uartlite: calling uart_register_driver()\n");
784
+ ret = uart_register_driver(&ulite_uart_driver);
785
+ if (ret < 0) {
786
+ dev_err(&pdev->dev, "Failed to register driver\n");
787
+ return ret;
788
+ }
789
+ }
790
+
791
+ ret = ulite_assign(&pdev->dev, id, res->start, irq, pdata);
792
+
793
+ clk_disable(pdata->clk);
794
+
795
+ return ret;
786796 }
787797
788798 static int ulite_remove(struct platform_device *pdev)
....@@ -813,25 +823,9 @@
813823
814824 static int __init ulite_init(void)
815825 {
816
- int ret;
817
-
818
- pr_debug("uartlite: calling uart_register_driver()\n");
819
- ret = uart_register_driver(&ulite_uart_driver);
820
- if (ret)
821
- goto err_uart;
822826
823827 pr_debug("uartlite: calling platform_driver_register()\n");
824
- ret = platform_driver_register(&ulite_platform_driver);
825
- if (ret)
826
- goto err_plat;
827
-
828
- return 0;
829
-
830
-err_plat:
831
- uart_unregister_driver(&ulite_uart_driver);
832
-err_uart:
833
- pr_err("registering uartlite driver failed: err=%i\n", ret);
834
- return ret;
828
+ return platform_driver_register(&ulite_platform_driver);
835829 }
836830
837831 static void __exit ulite_exit(void)