| .. | .. |
|---|
| 28 | 28 | #include <linux/kfifo.h> |
|---|
| 29 | 29 | #include <linux/workqueue.h> |
|---|
| 30 | 30 | #include <linux/completion.h> |
|---|
| 31 | +#include <linux/greybus.h> |
|---|
| 31 | 32 | |
|---|
| 32 | | -#include "greybus.h" |
|---|
| 33 | 33 | #include "gbphy.h" |
|---|
| 34 | 34 | |
|---|
| 35 | 35 | #define GB_NUM_MINORS 16 /* 16 is more than enough */ |
|---|
| .. | .. |
|---|
| 39 | 39 | #define GB_UART_WRITE_ROOM_MARGIN 1 /* leave some space in fifo */ |
|---|
| 40 | 40 | #define GB_UART_FIRMWARE_CREDITS 4096 |
|---|
| 41 | 41 | #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 | | -}; |
|---|
| 50 | 42 | |
|---|
| 51 | 43 | struct gb_tty { |
|---|
| 52 | 44 | struct gbphy_device *gbphy_dev; |
|---|
| .. | .. |
|---|
| 66 | 58 | struct mutex mutex; |
|---|
| 67 | 59 | u8 ctrlin; /* input control lines */ |
|---|
| 68 | 60 | u8 ctrlout; /* output control lines */ |
|---|
| 69 | | - struct gb_tty_line_coding line_coding; |
|---|
| 61 | + struct gb_uart_set_line_coding_request line_coding; |
|---|
| 70 | 62 | struct work_struct tx_work; |
|---|
| 71 | 63 | struct kfifo write_fifo; |
|---|
| 72 | 64 | bool close_pending; |
|---|
| .. | .. |
|---|
| 288 | 280 | |
|---|
| 289 | 281 | static int send_line_coding(struct gb_tty *tty) |
|---|
| 290 | 282 | { |
|---|
| 291 | | - struct gb_uart_set_line_coding_request request; |
|---|
| 292 | | - |
|---|
| 293 | | - memcpy(&request, &tty->line_coding, |
|---|
| 294 | | - sizeof(tty->line_coding)); |
|---|
| 295 | 283 | 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); |
|---|
| 297 | 286 | } |
|---|
| 298 | 287 | |
|---|
| 299 | 288 | static int send_control(struct gb_tty *gb_tty, u8 control) |
|---|
| .. | .. |
|---|
| 493 | 482 | static void gb_tty_set_termios(struct tty_struct *tty, |
|---|
| 494 | 483 | struct ktermios *termios_old) |
|---|
| 495 | 484 | { |
|---|
| 485 | + struct gb_uart_set_line_coding_request newline; |
|---|
| 496 | 486 | struct gb_tty *gb_tty = tty->driver_data; |
|---|
| 497 | 487 | struct ktermios *termios = &tty->termios; |
|---|
| 498 | | - struct gb_tty_line_coding newline; |
|---|
| 499 | 488 | u8 newctrl = gb_tty->ctrlout; |
|---|
| 500 | 489 | |
|---|
| 501 | 490 | newline.rate = cpu_to_le32(tty_get_baud_rate(tty)); |
|---|
| .. | .. |
|---|
| 616 | 605 | } |
|---|
| 617 | 606 | } |
|---|
| 618 | 607 | |
|---|
| 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) |
|---|
| 621 | 610 | { |
|---|
| 622 | | - struct serial_struct tmp; |
|---|
| 611 | + struct gb_tty *gb_tty = tty->driver_data; |
|---|
| 623 | 612 | |
|---|
| 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 = |
|---|
| 631 | 619 | 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; |
|---|
| 633 | 622 | |
|---|
| 634 | | - if (copy_to_user(info, &tmp, sizeof(tmp))) |
|---|
| 635 | | - return -EFAULT; |
|---|
| 636 | 623 | return 0; |
|---|
| 637 | 624 | } |
|---|
| 638 | 625 | |
|---|
| 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) |
|---|
| 641 | 628 | { |
|---|
| 642 | | - struct serial_struct new_serial; |
|---|
| 629 | + struct gb_tty *gb_tty = tty->driver_data; |
|---|
| 643 | 630 | unsigned int closing_wait; |
|---|
| 644 | 631 | unsigned int close_delay; |
|---|
| 645 | 632 | int retval = 0; |
|---|
| 646 | 633 | |
|---|
| 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); |
|---|
| 653 | 638 | |
|---|
| 654 | 639 | mutex_lock(&gb_tty->port.mutex); |
|---|
| 655 | 640 | if (!capable(CAP_SYS_ADMIN)) { |
|---|
| .. | .. |
|---|
| 726 | 711 | struct gb_tty *gb_tty = tty->driver_data; |
|---|
| 727 | 712 | |
|---|
| 728 | 713 | 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); |
|---|
| 735 | 714 | case TIOCMIWAIT: |
|---|
| 736 | 715 | return wait_serial_change(gb_tty, arg); |
|---|
| 737 | 716 | } |
|---|
| .. | .. |
|---|
| 827 | 806 | .tiocmget = gb_tty_tiocmget, |
|---|
| 828 | 807 | .tiocmset = gb_tty_tiocmset, |
|---|
| 829 | 808 | .get_icount = gb_tty_get_icount, |
|---|
| 809 | + .set_serial = set_serial_info, |
|---|
| 810 | + .get_serial = get_serial_info, |
|---|
| 830 | 811 | }; |
|---|
| 831 | 812 | |
|---|
| 832 | 813 | static const struct tty_port_operations gb_port_ops = { |
|---|