diff options
Diffstat (limited to 'drivers/usb/serial/ti_usb_3410_5052.c')
-rw-r--r-- | drivers/usb/serial/ti_usb_3410_5052.c | 203 |
1 files changed, 101 insertions, 102 deletions
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index a26a629dfc4f..48831a755fc1 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c | |||
@@ -70,6 +70,7 @@ | |||
70 | 70 | ||
71 | #include <linux/kernel.h> | 71 | #include <linux/kernel.h> |
72 | #include <linux/errno.h> | 72 | #include <linux/errno.h> |
73 | #include <linux/firmware.h> | ||
73 | #include <linux/init.h> | 74 | #include <linux/init.h> |
74 | #include <linux/slab.h> | 75 | #include <linux/slab.h> |
75 | #include <linux/tty.h> | 76 | #include <linux/tty.h> |
@@ -149,21 +150,23 @@ struct ti_device { | |||
149 | 150 | ||
150 | static int ti_startup(struct usb_serial *serial); | 151 | static int ti_startup(struct usb_serial *serial); |
151 | static void ti_shutdown(struct usb_serial *serial); | 152 | static void ti_shutdown(struct usb_serial *serial); |
152 | static int ti_open(struct usb_serial_port *port, struct file *file); | 153 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port, |
153 | static void ti_close(struct usb_serial_port *port, struct file *file); | 154 | struct file *file); |
154 | static int ti_write(struct usb_serial_port *port, const unsigned char *data, | 155 | static void ti_close(struct tty_struct *tty, struct usb_serial_port *port, |
155 | int count); | 156 | struct file *file); |
156 | static int ti_write_room(struct usb_serial_port *port); | 157 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, |
157 | static int ti_chars_in_buffer(struct usb_serial_port *port); | 158 | const unsigned char *data, int count); |
158 | static void ti_throttle(struct usb_serial_port *port); | 159 | static int ti_write_room(struct tty_struct *tty); |
159 | static void ti_unthrottle(struct usb_serial_port *port); | 160 | static int ti_chars_in_buffer(struct tty_struct *tty); |
160 | static int ti_ioctl(struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg); | 161 | static void ti_throttle(struct tty_struct *tty); |
161 | static void ti_set_termios(struct usb_serial_port *port, | 162 | static void ti_unthrottle(struct tty_struct *tty); |
163 | static int ti_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg); | ||
164 | static void ti_set_termios(struct tty_struct *tty, struct usb_serial_port *port, | ||
162 | struct ktermios *old_termios); | 165 | struct ktermios *old_termios); |
163 | static int ti_tiocmget(struct usb_serial_port *port, struct file *file); | 166 | static int ti_tiocmget(struct tty_struct *tty, struct file *file); |
164 | static int ti_tiocmset(struct usb_serial_port *port, struct file *file, | 167 | static int ti_tiocmset(struct tty_struct *tty, struct file *file, |
165 | unsigned int set, unsigned int clear); | 168 | unsigned int set, unsigned int clear); |
166 | static void ti_break(struct usb_serial_port *port, int break_state); | 169 | static void ti_break(struct tty_struct *tty, int break_state); |
167 | static void ti_interrupt_callback(struct urb *urb); | 170 | static void ti_interrupt_callback(struct urb *urb); |
168 | static void ti_bulk_in_callback(struct urb *urb); | 171 | static void ti_bulk_in_callback(struct urb *urb); |
169 | static void ti_bulk_out_callback(struct urb *urb); | 172 | static void ti_bulk_out_callback(struct urb *urb); |
@@ -192,8 +195,7 @@ static int ti_command_in_sync(struct ti_device *tdev, __u8 command, | |||
192 | static int ti_write_byte(struct ti_device *tdev, unsigned long addr, | 195 | static int ti_write_byte(struct ti_device *tdev, unsigned long addr, |
193 | __u8 mask, __u8 byte); | 196 | __u8 mask, __u8 byte); |
194 | 197 | ||
195 | static int ti_download_firmware(struct ti_device *tdev, char *fw_name); | 198 | static int ti_download_firmware(struct ti_device *tdev, int type); |
196 | |||
197 | 199 | ||
198 | /* circular buffer */ | 200 | /* circular buffer */ |
199 | static struct circ_buf *ti_buf_alloc(void); | 201 | static struct circ_buf *ti_buf_alloc(void); |
@@ -430,11 +432,10 @@ static int ti_startup(struct usb_serial *serial) | |||
430 | 432 | ||
431 | /* if we have only 1 configuration, download firmware */ | 433 | /* if we have only 1 configuration, download firmware */ |
432 | if (dev->descriptor.bNumConfigurations == 1) { | 434 | if (dev->descriptor.bNumConfigurations == 1) { |
433 | |||
434 | if (tdev->td_is_3410) | 435 | if (tdev->td_is_3410) |
435 | status = ti_download_firmware(tdev, "ti_3410.fw"); | 436 | status = ti_download_firmware(tdev, 3410); |
436 | else | 437 | else |
437 | status = ti_download_firmware(tdev, "ti_5052.fw"); | 438 | status = ti_download_firmware(tdev, 5052); |
438 | if (status) | 439 | if (status) |
439 | goto free_tdev; | 440 | goto free_tdev; |
440 | 441 | ||
@@ -519,7 +520,8 @@ static void ti_shutdown(struct usb_serial *serial) | |||
519 | } | 520 | } |
520 | 521 | ||
521 | 522 | ||
522 | static int ti_open(struct usb_serial_port *port, struct file *file) | 523 | static int ti_open(struct tty_struct *tty, |
524 | struct usb_serial_port *port, struct file *file) | ||
523 | { | 525 | { |
524 | struct ti_port *tport = usb_get_serial_port_data(port); | 526 | struct ti_port *tport = usb_get_serial_port_data(port); |
525 | struct ti_device *tdev; | 527 | struct ti_device *tdev; |
@@ -543,9 +545,9 @@ static int ti_open(struct usb_serial_port *port, struct file *file) | |||
543 | if (mutex_lock_interruptible(&tdev->td_open_close_lock)) | 545 | if (mutex_lock_interruptible(&tdev->td_open_close_lock)) |
544 | return -ERESTARTSYS; | 546 | return -ERESTARTSYS; |
545 | 547 | ||
546 | if (port->tty) | 548 | if (tty) |
547 | port->tty->low_latency = | 549 | tty->low_latency = |
548 | (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0; | 550 | (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
549 | 551 | ||
550 | port_number = port->number - port->serial->minor; | 552 | port_number = port->number - port->serial->minor; |
551 | 553 | ||
@@ -573,7 +575,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file) | |||
573 | } | 575 | } |
574 | } | 576 | } |
575 | 577 | ||
576 | ti_set_termios(port, port->tty->termios); | 578 | if (tty) |
579 | ti_set_termios(tty, port, tty->termios); | ||
577 | 580 | ||
578 | dbg("%s - sending TI_OPEN_PORT", __func__); | 581 | dbg("%s - sending TI_OPEN_PORT", __func__); |
579 | status = ti_command_out_sync(tdev, TI_OPEN_PORT, | 582 | status = ti_command_out_sync(tdev, TI_OPEN_PORT, |
@@ -610,7 +613,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file) | |||
610 | usb_clear_halt(dev, port->write_urb->pipe); | 613 | usb_clear_halt(dev, port->write_urb->pipe); |
611 | usb_clear_halt(dev, port->read_urb->pipe); | 614 | usb_clear_halt(dev, port->read_urb->pipe); |
612 | 615 | ||
613 | ti_set_termios(port, port->tty->termios); | 616 | if (tty) |
617 | ti_set_termios(tty, port, tty->termios); | ||
614 | 618 | ||
615 | dbg("%s - sending TI_OPEN_PORT (2)", __func__); | 619 | dbg("%s - sending TI_OPEN_PORT (2)", __func__); |
616 | status = ti_command_out_sync(tdev, TI_OPEN_PORT, | 620 | status = ti_command_out_sync(tdev, TI_OPEN_PORT, |
@@ -661,7 +665,8 @@ release_lock: | |||
661 | } | 665 | } |
662 | 666 | ||
663 | 667 | ||
664 | static void ti_close(struct usb_serial_port *port, struct file *file) | 668 | static void ti_close(struct tty_struct *tty, struct usb_serial_port *port, |
669 | struct file *file) | ||
665 | { | 670 | { |
666 | struct ti_device *tdev; | 671 | struct ti_device *tdev; |
667 | struct ti_port *tport; | 672 | struct ti_port *tport; |
@@ -707,8 +712,8 @@ static void ti_close(struct usb_serial_port *port, struct file *file) | |||
707 | } | 712 | } |
708 | 713 | ||
709 | 714 | ||
710 | static int ti_write(struct usb_serial_port *port, const unsigned char *data, | 715 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, |
711 | int count) | 716 | const unsigned char *data, int count) |
712 | { | 717 | { |
713 | struct ti_port *tport = usb_get_serial_port_data(port); | 718 | struct ti_port *tport = usb_get_serial_port_data(port); |
714 | unsigned long flags; | 719 | unsigned long flags; |
@@ -733,8 +738,9 @@ static int ti_write(struct usb_serial_port *port, const unsigned char *data, | |||
733 | } | 738 | } |
734 | 739 | ||
735 | 740 | ||
736 | static int ti_write_room(struct usb_serial_port *port) | 741 | static int ti_write_room(struct tty_struct *tty) |
737 | { | 742 | { |
743 | struct usb_serial_port *port = tty->driver_data; | ||
738 | struct ti_port *tport = usb_get_serial_port_data(port); | 744 | struct ti_port *tport = usb_get_serial_port_data(port); |
739 | int room = 0; | 745 | int room = 0; |
740 | unsigned long flags; | 746 | unsigned long flags; |
@@ -753,8 +759,9 @@ static int ti_write_room(struct usb_serial_port *port) | |||
753 | } | 759 | } |
754 | 760 | ||
755 | 761 | ||
756 | static int ti_chars_in_buffer(struct usb_serial_port *port) | 762 | static int ti_chars_in_buffer(struct tty_struct *tty) |
757 | { | 763 | { |
764 | struct usb_serial_port *port = tty->driver_data; | ||
758 | struct ti_port *tport = usb_get_serial_port_data(port); | 765 | struct ti_port *tport = usb_get_serial_port_data(port); |
759 | int chars = 0; | 766 | int chars = 0; |
760 | unsigned long flags; | 767 | unsigned long flags; |
@@ -773,32 +780,26 @@ static int ti_chars_in_buffer(struct usb_serial_port *port) | |||
773 | } | 780 | } |
774 | 781 | ||
775 | 782 | ||
776 | static void ti_throttle(struct usb_serial_port *port) | 783 | static void ti_throttle(struct tty_struct *tty) |
777 | { | 784 | { |
785 | struct usb_serial_port *port = tty->driver_data; | ||
778 | struct ti_port *tport = usb_get_serial_port_data(port); | 786 | struct ti_port *tport = usb_get_serial_port_data(port); |
779 | struct tty_struct *tty; | ||
780 | 787 | ||
781 | dbg("%s - port %d", __func__, port->number); | 788 | dbg("%s - port %d", __func__, port->number); |
782 | 789 | ||
783 | if (tport == NULL) | 790 | if (tport == NULL) |
784 | return; | 791 | return; |
785 | 792 | ||
786 | tty = port->tty; | ||
787 | if (!tty) { | ||
788 | dbg("%s - no tty", __func__); | ||
789 | return; | ||
790 | } | ||
791 | |||
792 | if (I_IXOFF(tty) || C_CRTSCTS(tty)) | 793 | if (I_IXOFF(tty) || C_CRTSCTS(tty)) |
793 | ti_stop_read(tport, tty); | 794 | ti_stop_read(tport, tty); |
794 | 795 | ||
795 | } | 796 | } |
796 | 797 | ||
797 | 798 | ||
798 | static void ti_unthrottle(struct usb_serial_port *port) | 799 | static void ti_unthrottle(struct tty_struct *tty) |
799 | { | 800 | { |
801 | struct usb_serial_port *port = tty->driver_data; | ||
800 | struct ti_port *tport = usb_get_serial_port_data(port); | 802 | struct ti_port *tport = usb_get_serial_port_data(port); |
801 | struct tty_struct *tty; | ||
802 | int status; | 803 | int status; |
803 | 804 | ||
804 | dbg("%s - port %d", __func__, port->number); | 805 | dbg("%s - port %d", __func__, port->number); |
@@ -806,12 +807,6 @@ static void ti_unthrottle(struct usb_serial_port *port) | |||
806 | if (tport == NULL) | 807 | if (tport == NULL) |
807 | return; | 808 | return; |
808 | 809 | ||
809 | tty = port->tty; | ||
810 | if (!tty) { | ||
811 | dbg("%s - no tty", __func__); | ||
812 | return; | ||
813 | } | ||
814 | |||
815 | if (I_IXOFF(tty) || C_CRTSCTS(tty)) { | 810 | if (I_IXOFF(tty) || C_CRTSCTS(tty)) { |
816 | status = ti_restart_read(tport, tty); | 811 | status = ti_restart_read(tport, tty); |
817 | if (status) | 812 | if (status) |
@@ -820,9 +815,10 @@ static void ti_unthrottle(struct usb_serial_port *port) | |||
820 | } | 815 | } |
821 | 816 | ||
822 | 817 | ||
823 | static int ti_ioctl(struct usb_serial_port *port, struct file *file, | 818 | static int ti_ioctl(struct tty_struct *tty, struct file *file, |
824 | unsigned int cmd, unsigned long arg) | 819 | unsigned int cmd, unsigned long arg) |
825 | { | 820 | { |
821 | struct usb_serial_port *port = tty->driver_data; | ||
826 | struct ti_port *tport = usb_get_serial_port_data(port); | 822 | struct ti_port *tport = usb_get_serial_port_data(port); |
827 | struct async_icount cnow; | 823 | struct async_icount cnow; |
828 | struct async_icount cprev; | 824 | struct async_icount cprev; |
@@ -875,11 +871,10 @@ static int ti_ioctl(struct usb_serial_port *port, struct file *file, | |||
875 | } | 871 | } |
876 | 872 | ||
877 | 873 | ||
878 | static void ti_set_termios(struct usb_serial_port *port, | 874 | static void ti_set_termios(struct tty_struct *tty, |
879 | struct ktermios *old_termios) | 875 | struct usb_serial_port *port, struct ktermios *old_termios) |
880 | { | 876 | { |
881 | struct ti_port *tport = usb_get_serial_port_data(port); | 877 | struct ti_port *tport = usb_get_serial_port_data(port); |
882 | struct tty_struct *tty = port->tty; | ||
883 | struct ti_uart_config *config; | 878 | struct ti_uart_config *config; |
884 | tcflag_t cflag,iflag; | 879 | tcflag_t cflag,iflag; |
885 | int baud; | 880 | int baud; |
@@ -1008,8 +1003,9 @@ static void ti_set_termios(struct usb_serial_port *port, | |||
1008 | } | 1003 | } |
1009 | 1004 | ||
1010 | 1005 | ||
1011 | static int ti_tiocmget(struct usb_serial_port *port, struct file *file) | 1006 | static int ti_tiocmget(struct tty_struct *tty, struct file *file) |
1012 | { | 1007 | { |
1008 | struct usb_serial_port *port = tty->driver_data; | ||
1013 | struct ti_port *tport = usb_get_serial_port_data(port); | 1009 | struct ti_port *tport = usb_get_serial_port_data(port); |
1014 | unsigned int result; | 1010 | unsigned int result; |
1015 | unsigned int msr; | 1011 | unsigned int msr; |
@@ -1040,9 +1036,10 @@ static int ti_tiocmget(struct usb_serial_port *port, struct file *file) | |||
1040 | } | 1036 | } |
1041 | 1037 | ||
1042 | 1038 | ||
1043 | static int ti_tiocmset(struct usb_serial_port *port, struct file *file, | 1039 | static int ti_tiocmset(struct tty_struct *tty, struct file *file, |
1044 | unsigned int set, unsigned int clear) | 1040 | unsigned int set, unsigned int clear) |
1045 | { | 1041 | { |
1042 | struct usb_serial_port *port = tty->driver_data; | ||
1046 | struct ti_port *tport = usb_get_serial_port_data(port); | 1043 | struct ti_port *tport = usb_get_serial_port_data(port); |
1047 | unsigned int mcr; | 1044 | unsigned int mcr; |
1048 | unsigned long flags; | 1045 | unsigned long flags; |
@@ -1074,8 +1071,9 @@ static int ti_tiocmset(struct usb_serial_port *port, struct file *file, | |||
1074 | } | 1071 | } |
1075 | 1072 | ||
1076 | 1073 | ||
1077 | static void ti_break(struct usb_serial_port *port, int break_state) | 1074 | static void ti_break(struct tty_struct *tty, int break_state) |
1078 | { | 1075 | { |
1076 | struct usb_serial_port *port = tty->driver_data; | ||
1079 | struct ti_port *tport = usb_get_serial_port_data(port); | 1077 | struct ti_port *tport = usb_get_serial_port_data(port); |
1080 | int status; | 1078 | int status; |
1081 | 1079 | ||
@@ -1213,14 +1211,14 @@ static void ti_bulk_in_callback(struct urb *urb) | |||
1213 | return; | 1211 | return; |
1214 | } | 1212 | } |
1215 | 1213 | ||
1216 | if (port->tty && urb->actual_length) { | 1214 | if (port->port.tty && urb->actual_length) { |
1217 | usb_serial_debug_data(debug, dev, __func__, | 1215 | usb_serial_debug_data(debug, dev, __func__, |
1218 | urb->actual_length, urb->transfer_buffer); | 1216 | urb->actual_length, urb->transfer_buffer); |
1219 | 1217 | ||
1220 | if (!tport->tp_is_open) | 1218 | if (!tport->tp_is_open) |
1221 | dbg("%s - port closed, dropping data", __func__); | 1219 | dbg("%s - port closed, dropping data", __func__); |
1222 | else | 1220 | else |
1223 | ti_recv(&urb->dev->dev, port->tty, urb->transfer_buffer, | 1221 | ti_recv(&urb->dev->dev, port->port.tty, urb->transfer_buffer, |
1224 | urb->actual_length); | 1222 | urb->actual_length); |
1225 | 1223 | ||
1226 | spin_lock(&tport->tp_lock); | 1224 | spin_lock(&tport->tp_lock); |
@@ -1302,7 +1300,7 @@ static void ti_send(struct ti_port *tport) | |||
1302 | { | 1300 | { |
1303 | int count, result; | 1301 | int count, result; |
1304 | struct usb_serial_port *port = tport->tp_port; | 1302 | struct usb_serial_port *port = tport->tp_port; |
1305 | struct tty_struct *tty = port->tty; | 1303 | struct tty_struct *tty = port->port.tty; /* FIXME */ |
1306 | unsigned long flags; | 1304 | unsigned long flags; |
1307 | 1305 | ||
1308 | 1306 | ||
@@ -1442,8 +1440,9 @@ static int ti_set_serial_info(struct ti_port *tport, | |||
1442 | return -EFAULT; | 1440 | return -EFAULT; |
1443 | 1441 | ||
1444 | tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS; | 1442 | tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS; |
1445 | if (port->tty) | 1443 | /* FIXME */ |
1446 | port->tty->low_latency = | 1444 | if (port->port.tty) |
1445 | port->port.tty->low_latency = | ||
1447 | (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0; | 1446 | (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
1448 | tport->tp_closing_wait = new_serial.closing_wait; | 1447 | tport->tp_closing_wait = new_serial.closing_wait; |
1449 | 1448 | ||
@@ -1477,7 +1476,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr) | |||
1477 | tport->tp_msr = msr & TI_MSR_MASK; | 1476 | tport->tp_msr = msr & TI_MSR_MASK; |
1478 | 1477 | ||
1479 | /* handle CTS flow control */ | 1478 | /* handle CTS flow control */ |
1480 | tty = tport->tp_port->tty; | 1479 | tty = tport->tp_port->port.tty; |
1481 | if (tty && C_CRTSCTS(tty)) { | 1480 | if (tty && C_CRTSCTS(tty)) { |
1482 | if (msr & TI_MSR_CTS) { | 1481 | if (msr & TI_MSR_CTS) { |
1483 | tty->hw_stopped = 0; | 1482 | tty->hw_stopped = 0; |
@@ -1655,65 +1654,65 @@ static int ti_write_byte(struct ti_device *tdev, unsigned long addr, | |||
1655 | return status; | 1654 | return status; |
1656 | } | 1655 | } |
1657 | 1656 | ||
1658 | 1657 | static int ti_do_download(struct usb_device *dev, int pipe, | |
1659 | static int ti_download_firmware(struct ti_device *tdev, | 1658 | u8 *buffer, int size) |
1660 | char *fw_name) | ||
1661 | { | 1659 | { |
1662 | const struct firmware *fw; | ||
1663 | int status = 0; | ||
1664 | int buffer_size; | ||
1665 | int pos; | 1660 | int pos; |
1666 | int len; | 1661 | u8 cs = 0; |
1667 | int done; | 1662 | int done; |
1668 | __u8 cs = 0; | ||
1669 | __u8 *buffer; | ||
1670 | struct usb_device *dev = tdev->td_serial->dev; | ||
1671 | struct ti_firmware_header *header; | 1663 | struct ti_firmware_header *header; |
1672 | unsigned int pipe = usb_sndbulkpipe(dev, | 1664 | int status; |
1673 | tdev->td_serial->port[0]->bulk_out_endpointAddress); | 1665 | int len; |
1674 | 1666 | ||
1675 | buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header); | 1667 | for(pos = sizeof(struct ti_firmware_header); pos < size; pos++) |
1676 | |||
1677 | if (request_firmware(&fw, fw_name, &dev->dev)) { | ||
1678 | dev_err(&dev->dev, "%s - failed to load firmware \"%s\"\n", | ||
1679 | __func__, fw_name); | ||
1680 | return -ENOENT; | ||
1681 | } | ||
1682 | if (fw->size > buffer_size) { | ||
1683 | dev_err(&dev->dev, "%s - firmware \"%s\" is too large\n", | ||
1684 | __func__, fw_name); | ||
1685 | release_firmware(fw); | ||
1686 | return -EINVAL; | ||
1687 | } | ||
1688 | |||
1689 | buffer = kmalloc(buffer_size, GFP_KERNEL); | ||
1690 | if (!buffer) { | ||
1691 | dev_err(&dev->dev, "%s - out of memory\n", __func__); | ||
1692 | release_firmware(fw); | ||
1693 | return -ENOMEM; | ||
1694 | } | ||
1695 | |||
1696 | memcpy(buffer, fw->data, fw->size); | ||
1697 | memset(buffer+fw->size, 0xff, buffer_size-fw->size); | ||
1698 | |||
1699 | for(pos = sizeof(struct ti_firmware_header); pos < buffer_size; pos++) | ||
1700 | cs = (__u8)(cs + buffer[pos]); | 1668 | cs = (__u8)(cs + buffer[pos]); |
1701 | 1669 | ||
1702 | header = (struct ti_firmware_header *)buffer; | 1670 | header = (struct ti_firmware_header *)buffer; |
1703 | header->wLength = cpu_to_le16((__u16)(buffer_size - sizeof(struct ti_firmware_header))); | 1671 | header->wLength = cpu_to_le16((__u16)(size |
1672 | - sizeof(struct ti_firmware_header))); | ||
1704 | header->bCheckSum = cs; | 1673 | header->bCheckSum = cs; |
1705 | 1674 | ||
1706 | dbg("%s - downloading firmware", __func__); | 1675 | dbg("%s - downloading firmware", __func__); |
1707 | for (pos = 0; pos < buffer_size; pos += done) { | 1676 | for (pos = 0; pos < size; pos += done) { |
1708 | len = min(buffer_size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE); | 1677 | len = min(size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE); |
1709 | status = usb_bulk_msg(dev, pipe, buffer+pos, len, &done, 1000); | 1678 | status = usb_bulk_msg(dev, pipe, buffer + pos, len, |
1679 | &done, 1000); | ||
1710 | if (status) | 1680 | if (status) |
1711 | break; | 1681 | break; |
1712 | } | 1682 | } |
1683 | return status; | ||
1684 | } | ||
1713 | 1685 | ||
1714 | kfree(buffer); | 1686 | static int ti_download_firmware(struct ti_device *tdev, int type) |
1715 | release_firmware(fw); | 1687 | { |
1688 | int status = -ENOMEM; | ||
1689 | int buffer_size; | ||
1690 | __u8 *buffer; | ||
1691 | struct usb_device *dev = tdev->td_serial->dev; | ||
1692 | unsigned int pipe = usb_sndbulkpipe(dev, | ||
1693 | tdev->td_serial->port[0]->bulk_out_endpointAddress); | ||
1694 | const struct firmware *fw_p; | ||
1695 | char buf[32]; | ||
1696 | sprintf(buf, "ti_usb-%d.bin", type); | ||
1716 | 1697 | ||
1698 | if (request_firmware(&fw_p, buf, &dev->dev)) { | ||
1699 | dev_err(&dev->dev, "%s - firmware not found\n", __func__); | ||
1700 | return -ENOENT; | ||
1701 | } | ||
1702 | if (fw_p->size > TI_FIRMWARE_BUF_SIZE) { | ||
1703 | dev_err(&dev->dev, "%s - firmware too large\n", __func__); | ||
1704 | return -ENOENT; | ||
1705 | } | ||
1706 | |||
1707 | buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header); | ||
1708 | buffer = kmalloc(buffer_size, GFP_KERNEL); | ||
1709 | if (buffer) { | ||
1710 | memcpy(buffer, fw_p->data, fw_p->size); | ||
1711 | memset(buffer + fw_p->size, 0xff, buffer_size - fw_p->size); | ||
1712 | ti_do_download(dev, pipe, buffer, fw_p->size); | ||
1713 | kfree(buffer); | ||
1714 | } | ||
1715 | release_firmware(fw_p); | ||
1717 | if (status) { | 1716 | if (status) { |
1718 | dev_err(&dev->dev, "%s - error downloading firmware, %d\n", __func__, status); | 1717 | dev_err(&dev->dev, "%s - error downloading firmware, %d\n", __func__, status); |
1719 | return status; | 1718 | return status; |