forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-20 e636c8d336489bf3eed5878299e6cc045bbad077
kernel/drivers/staging/greybus/uart.c
....@@ -28,8 +28,8 @@
2828 #include <linux/kfifo.h>
2929 #include <linux/workqueue.h>
3030 #include <linux/completion.h>
31
+#include <linux/greybus.h>
3132
32
-#include "greybus.h"
3333 #include "gbphy.h"
3434
3535 #define GB_NUM_MINORS 16 /* 16 is more than enough */
....@@ -39,14 +39,6 @@
3939 #define GB_UART_WRITE_ROOM_MARGIN 1 /* leave some space in fifo */
4040 #define GB_UART_FIRMWARE_CREDITS 4096
4141 #define GB_UART_CREDIT_WAIT_TIMEOUT_MSEC 10000
42
-
43
-struct gb_tty_line_coding {
44
- __le32 rate;
45
- __u8 format;
46
- __u8 parity;
47
- __u8 data_bits;
48
- __u8 flow_control;
49
-};
5042
5143 struct gb_tty {
5244 struct gbphy_device *gbphy_dev;
....@@ -66,7 +58,7 @@
6658 struct mutex mutex;
6759 u8 ctrlin; /* input control lines */
6860 u8 ctrlout; /* output control lines */
69
- struct gb_tty_line_coding line_coding;
61
+ struct gb_uart_set_line_coding_request line_coding;
7062 struct work_struct tx_work;
7163 struct kfifo write_fifo;
7264 bool close_pending;
....@@ -288,12 +280,9 @@
288280
289281 static int send_line_coding(struct gb_tty *tty)
290282 {
291
- struct gb_uart_set_line_coding_request request;
292
-
293
- memcpy(&request, &tty->line_coding,
294
- sizeof(tty->line_coding));
295283 return gb_operation_sync(tty->connection, GB_UART_TYPE_SET_LINE_CODING,
296
- &request, sizeof(request), NULL, 0);
284
+ &tty->line_coding, sizeof(tty->line_coding),
285
+ NULL, 0);
297286 }
298287
299288 static int send_control(struct gb_tty *gb_tty, u8 control)
....@@ -493,9 +482,9 @@
493482 static void gb_tty_set_termios(struct tty_struct *tty,
494483 struct ktermios *termios_old)
495484 {
485
+ struct gb_uart_set_line_coding_request newline;
496486 struct gb_tty *gb_tty = tty->driver_data;
497487 struct ktermios *termios = &tty->termios;
498
- struct gb_tty_line_coding newline;
499488 u8 newctrl = gb_tty->ctrlout;
500489
501490 newline.rate = cpu_to_le32(tty_get_baud_rate(tty));
....@@ -616,40 +605,36 @@
616605 }
617606 }
618607
619
-static int get_serial_info(struct gb_tty *gb_tty,
620
- struct serial_struct __user *info)
608
+static int get_serial_info(struct tty_struct *tty,
609
+ struct serial_struct *ss)
621610 {
622
- struct serial_struct tmp;
611
+ struct gb_tty *gb_tty = tty->driver_data;
623612
624
- memset(&tmp, 0, sizeof(tmp));
625
- tmp.type = PORT_16550A;
626
- tmp.line = gb_tty->minor;
627
- tmp.xmit_fifo_size = 16;
628
- tmp.baud_base = 9600;
629
- tmp.close_delay = gb_tty->port.close_delay / 10;
630
- tmp.closing_wait =
613
+ ss->type = PORT_16550A;
614
+ ss->line = gb_tty->minor;
615
+ ss->xmit_fifo_size = 16;
616
+ ss->baud_base = 9600;
617
+ ss->close_delay = jiffies_to_msecs(gb_tty->port.close_delay) / 10;
618
+ ss->closing_wait =
631619 gb_tty->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
632
- ASYNC_CLOSING_WAIT_NONE : gb_tty->port.closing_wait / 10;
620
+ ASYNC_CLOSING_WAIT_NONE :
621
+ jiffies_to_msecs(gb_tty->port.closing_wait) / 10;
633622
634
- if (copy_to_user(info, &tmp, sizeof(tmp)))
635
- return -EFAULT;
636623 return 0;
637624 }
638625
639
-static int set_serial_info(struct gb_tty *gb_tty,
640
- struct serial_struct __user *newinfo)
626
+static int set_serial_info(struct tty_struct *tty,
627
+ struct serial_struct *ss)
641628 {
642
- struct serial_struct new_serial;
629
+ struct gb_tty *gb_tty = tty->driver_data;
643630 unsigned int closing_wait;
644631 unsigned int close_delay;
645632 int retval = 0;
646633
647
- if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
648
- return -EFAULT;
649
-
650
- close_delay = new_serial.close_delay * 10;
651
- closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
652
- ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
634
+ close_delay = msecs_to_jiffies(ss->close_delay * 10);
635
+ closing_wait = ss->closing_wait == ASYNC_CLOSING_WAIT_NONE ?
636
+ ASYNC_CLOSING_WAIT_NONE :
637
+ msecs_to_jiffies(ss->closing_wait * 10);
653638
654639 mutex_lock(&gb_tty->port.mutex);
655640 if (!capable(CAP_SYS_ADMIN)) {
....@@ -726,12 +711,6 @@
726711 struct gb_tty *gb_tty = tty->driver_data;
727712
728713 switch (cmd) {
729
- case TIOCGSERIAL:
730
- return get_serial_info(gb_tty,
731
- (struct serial_struct __user *)arg);
732
- case TIOCSSERIAL:
733
- return set_serial_info(gb_tty,
734
- (struct serial_struct __user *)arg);
735714 case TIOCMIWAIT:
736715 return wait_serial_change(gb_tty, arg);
737716 }
....@@ -827,6 +806,8 @@
827806 .tiocmget = gb_tty_tiocmget,
828807 .tiocmset = gb_tty_tiocmset,
829808 .get_icount = gb_tty_get_icount,
809
+ .set_serial = set_serial_info,
810
+ .get_serial = get_serial_info,
830811 };
831812
832813 static const struct tty_port_operations gb_port_ops = {