| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Edgeport USB Serial Converter driver | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2000-2002 Inside Out Networks, All rights reserved. | 
|  | 5 | * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com> | 
|  | 6 | * | 
|  | 7 | *	This program is free software; you can redistribute it and/or modify | 
|  | 8 | *	it under the terms of the GNU General Public License as published by | 
|  | 9 | *	the Free Software Foundation; either version 2 of the License, or | 
|  | 10 | *	(at your option) any later version. | 
|  | 11 | * | 
|  | 12 | * Supports the following devices: | 
|  | 13 | *	EP/1 EP/2 EP/4 EP/21 EP/22 EP/221 EP/42 EP/421 WATCHPORT | 
|  | 14 | * | 
|  | 15 | * For questions or problems with this driver, contact Inside Out | 
|  | 16 | * Networks technical support, or Peter Berger <pberger@brimson.com>, | 
|  | 17 | * or Al Borchers <alborchers@steinerpoint.com>. | 
|  | 18 | * | 
|  | 19 | * Version history: | 
|  | 20 | * | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 21 | *	July 11, 2002 	Removed 4 port device structure since all TI UMP | 
|  | 22 | *			chips have only 2 ports | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | *			David Iacovelli (davidi@ionetworks.com) | 
|  | 24 | * | 
|  | 25 | */ | 
|  | 26 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/kernel.h> | 
|  | 28 | #include <linux/jiffies.h> | 
|  | 29 | #include <linux/errno.h> | 
|  | 30 | #include <linux/init.h> | 
|  | 31 | #include <linux/slab.h> | 
|  | 32 | #include <linux/tty.h> | 
|  | 33 | #include <linux/tty_driver.h> | 
|  | 34 | #include <linux/tty_flip.h> | 
|  | 35 | #include <linux/module.h> | 
|  | 36 | #include <linux/spinlock.h> | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 37 | #include <linux/mutex.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/serial.h> | 
|  | 39 | #include <linux/ioctl.h> | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 40 | #include <linux/firmware.h> | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 41 | #include <linux/uaccess.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/usb.h> | 
| Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 43 | #include <linux/usb/serial.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include "io_16654.h" | 
|  | 46 | #include "io_usbvend.h" | 
|  | 47 | #include "io_ti.h" | 
|  | 48 |  | 
|  | 49 | /* | 
|  | 50 | * Version Information | 
|  | 51 | */ | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 52 | #define DRIVER_VERSION "v0.7mode043006" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli" | 
|  | 54 | #define DRIVER_DESC "Edgeport USB Serial Driver" | 
|  | 55 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define EPROM_PAGE_SIZE		64 | 
|  | 57 |  | 
|  | 58 |  | 
|  | 59 | struct edgeport_uart_buf_desc { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 60 | __u32 count;		/* Number of bytes currently in buffer */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | }; | 
|  | 62 |  | 
|  | 63 | /* different hardware types */ | 
|  | 64 | #define HARDWARE_TYPE_930	0 | 
|  | 65 | #define HARDWARE_TYPE_TIUMP	1 | 
|  | 66 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 67 | /* IOCTL_PRIVATE_TI_GET_MODE Definitions */ | 
|  | 68 | #define	TI_MODE_CONFIGURING	0   /* Device has not entered start device */ | 
|  | 69 | #define	TI_MODE_BOOT		1   /* Staying in boot mode		   */ | 
|  | 70 | #define TI_MODE_DOWNLOAD	2   /* Made it to download mode		   */ | 
|  | 71 | #define TI_MODE_TRANSITIONING	3   /* Currently in boot mode but | 
|  | 72 | transitioning to download mode	   */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 |  | 
|  | 74 | /* read urb state */ | 
|  | 75 | #define EDGE_READ_URB_RUNNING	0 | 
|  | 76 | #define EDGE_READ_URB_STOPPING	1 | 
|  | 77 | #define EDGE_READ_URB_STOPPED	2 | 
|  | 78 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define EDGE_CLOSING_WAIT	4000	/* in .01 sec */ | 
|  | 80 |  | 
|  | 81 | #define EDGE_OUT_BUF_SIZE	1024 | 
|  | 82 |  | 
|  | 83 |  | 
|  | 84 | /* Product information read from the Edgeport */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 85 | struct product_info { | 
|  | 86 | int	TiMode;			/* Current TI Mode  */ | 
|  | 87 | __u8	hardware_type;		/* Type of hardware */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } __attribute__((packed)); | 
|  | 89 |  | 
|  | 90 | /* circular buffer */ | 
|  | 91 | struct edge_buf { | 
|  | 92 | unsigned int	buf_size; | 
|  | 93 | char		*buf_buf; | 
|  | 94 | char		*buf_get; | 
|  | 95 | char		*buf_put; | 
|  | 96 | }; | 
|  | 97 |  | 
|  | 98 | struct edgeport_port { | 
|  | 99 | __u16 uart_base; | 
|  | 100 | __u16 dma_address; | 
|  | 101 | __u8 shadow_msr; | 
|  | 102 | __u8 shadow_mcr; | 
|  | 103 | __u8 shadow_lsr; | 
|  | 104 | __u8 lsr_mask; | 
|  | 105 | __u32 ump_read_timeout;		/* Number of miliseconds the UMP will | 
|  | 106 | wait without data before completing | 
|  | 107 | a read short */ | 
|  | 108 | int baud_rate; | 
|  | 109 | int close_pending; | 
|  | 110 | int lsr_event; | 
|  | 111 | struct edgeport_uart_buf_desc tx; | 
|  | 112 | struct async_icount	icount; | 
|  | 113 | wait_queue_head_t	delta_msr_wait;	/* for handling sleeping while | 
|  | 114 | waiting for msr change to | 
|  | 115 | happen */ | 
|  | 116 | struct edgeport_serial	*edge_serial; | 
|  | 117 | struct usb_serial_port	*port; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 118 | __u8 bUartMode;		/* Port type, 0: RS232, etc. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | spinlock_t ep_lock; | 
|  | 120 | int ep_read_urb_state; | 
|  | 121 | int ep_write_urb_in_use; | 
|  | 122 | struct edge_buf *ep_out_buf; | 
|  | 123 | }; | 
|  | 124 |  | 
|  | 125 | struct edgeport_serial { | 
|  | 126 | struct product_info product_info; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 127 | u8 TI_I2C_Type;			/* Type of I2C in UMP */ | 
|  | 128 | u8 TiReadI2C;			/* Set to TRUE if we have read the | 
|  | 129 | I2c in Boot Mode */ | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 130 | struct mutex es_lock; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | int num_ports_open; | 
|  | 132 | struct usb_serial *serial; | 
|  | 133 | }; | 
|  | 134 |  | 
|  | 135 |  | 
|  | 136 | /* Devices that this driver supports */ | 
|  | 137 | static struct usb_device_id edgeport_1port_id_table [] = { | 
|  | 138 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) }, | 
|  | 139 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) }, | 
|  | 140 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) }, | 
|  | 141 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) }, | 
|  | 142 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) }, | 
|  | 143 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) }, | 
|  | 144 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) }, | 
|  | 145 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) }, | 
|  | 146 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) }, | 
|  | 147 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) }, | 
|  | 148 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) }, | 
|  | 149 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) }, | 
|  | 150 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) }, | 
|  | 151 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) }, | 
|  | 152 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) }, | 
|  | 153 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) }, | 
|  | 154 | { } | 
|  | 155 | }; | 
|  | 156 |  | 
|  | 157 | static struct usb_device_id edgeport_2port_id_table [] = { | 
|  | 158 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) }, | 
|  | 159 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) }, | 
|  | 160 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) }, | 
|  | 161 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) }, | 
|  | 162 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) }, | 
|  | 163 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) }, | 
|  | 164 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) }, | 
|  | 165 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) }, | 
|  | 166 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) }, | 
|  | 167 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) }, | 
|  | 168 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) }, | 
|  | 169 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) }, | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 170 | /* The 4, 8 and 16 port devices show up as multiple 2 port devices */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) }, | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 172 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) }, | 
|  | 173 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) }, | 
|  | 174 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) }, | 
|  | 175 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) }, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { } | 
|  | 177 | }; | 
|  | 178 |  | 
|  | 179 | /* Devices that this driver supports */ | 
|  | 180 | static struct usb_device_id id_table_combined [] = { | 
|  | 181 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) }, | 
|  | 182 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) }, | 
|  | 183 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) }, | 
|  | 184 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) }, | 
|  | 185 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) }, | 
|  | 186 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) }, | 
|  | 187 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) }, | 
|  | 188 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) }, | 
|  | 189 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) }, | 
|  | 190 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) }, | 
|  | 191 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) }, | 
|  | 192 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) }, | 
|  | 193 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) }, | 
|  | 194 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) }, | 
|  | 195 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) }, | 
|  | 196 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) }, | 
|  | 197 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) }, | 
|  | 198 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) }, | 
|  | 199 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) }, | 
|  | 200 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) }, | 
|  | 201 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) }, | 
|  | 202 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) }, | 
|  | 203 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) }, | 
|  | 204 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) }, | 
|  | 205 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) }, | 
|  | 206 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) }, | 
|  | 207 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) }, | 
|  | 208 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) }, | 
|  | 209 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) }, | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 210 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) }, | 
|  | 211 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) }, | 
|  | 212 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) }, | 
|  | 213 | { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) }, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { } | 
|  | 215 | }; | 
|  | 216 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 217 | MODULE_DEVICE_TABLE(usb, id_table_combined); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 |  | 
|  | 219 | static struct usb_driver io_driver = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | .name =		"io_ti", | 
|  | 221 | .probe =	usb_serial_probe, | 
|  | 222 | .disconnect =	usb_serial_disconnect, | 
|  | 223 | .id_table =	id_table_combined, | 
| Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 224 | .no_dynamic_id = 	1, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | }; | 
|  | 226 |  | 
|  | 227 |  | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 228 | static unsigned char OperationalMajorVersion; | 
|  | 229 | static unsigned char OperationalMinorVersion; | 
|  | 230 | static unsigned short OperationalBuildNumber; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 |  | 
|  | 232 | static int debug; | 
|  | 233 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | static int closing_wait = EDGE_CLOSING_WAIT; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 235 | static int ignore_cpu_rev; | 
|  | 236 | static int default_uart_mode;		/* RS232 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 238 | static void edge_tty_recv(struct device *dev, struct tty_struct *tty, | 
|  | 239 | unsigned char *data, int length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 |  | 
|  | 241 | static void stop_read(struct edgeport_port *edge_port); | 
|  | 242 | static int restart_read(struct edgeport_port *edge_port); | 
|  | 243 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 244 | static void edge_set_termios(struct tty_struct *tty, | 
|  | 245 | struct usb_serial_port *port, struct ktermios *old_termios); | 
|  | 246 | static void edge_send(struct tty_struct *tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 |  | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 248 | /* sysfs attributes */ | 
|  | 249 | static int edge_create_sysfs_attrs(struct usb_serial_port *port); | 
|  | 250 | static int edge_remove_sysfs_attrs(struct usb_serial_port *port); | 
|  | 251 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* circular buffer */ | 
|  | 253 | static struct edge_buf *edge_buf_alloc(unsigned int size); | 
|  | 254 | static void edge_buf_free(struct edge_buf *eb); | 
|  | 255 | static void edge_buf_clear(struct edge_buf *eb); | 
|  | 256 | static unsigned int edge_buf_data_avail(struct edge_buf *eb); | 
|  | 257 | static unsigned int edge_buf_space_avail(struct edge_buf *eb); | 
|  | 258 | static unsigned int edge_buf_put(struct edge_buf *eb, const char *buf, | 
|  | 259 | unsigned int count); | 
|  | 260 | static unsigned int edge_buf_get(struct edge_buf *eb, char *buf, | 
|  | 261 | unsigned int count); | 
|  | 262 |  | 
|  | 263 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 264 | static int ti_vread_sync(struct usb_device *dev, __u8 request, | 
|  | 265 | __u16 value, __u16 index, u8 *data, int size) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | { | 
|  | 267 | int status; | 
|  | 268 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 269 | status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request, | 
|  | 270 | (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN), | 
|  | 271 | value, index, data, size, 1000); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | if (status < 0) | 
|  | 273 | return status; | 
|  | 274 | if (status != size) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 275 | dbg("%s - wanted to write %d, but only wrote %d", | 
|  | 276 | __func__, size, status); | 
|  | 277 | return -ECOMM; | 
|  | 278 | } | 
|  | 279 | return 0; | 
|  | 280 | } | 
|  | 281 |  | 
|  | 282 | static int ti_vsend_sync(struct usb_device *dev, __u8 request, | 
|  | 283 | __u16 value, __u16 index, u8 *data, int size) | 
|  | 284 | { | 
|  | 285 | int status; | 
|  | 286 |  | 
|  | 287 | status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request, | 
|  | 288 | (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT), | 
|  | 289 | value, index, data, size, 1000); | 
|  | 290 | if (status < 0) | 
|  | 291 | return status; | 
|  | 292 | if (status != size) { | 
|  | 293 | dbg("%s - wanted to write %d, but only wrote %d", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 294 | __func__, size, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | return -ECOMM; | 
|  | 296 | } | 
|  | 297 | return 0; | 
|  | 298 | } | 
|  | 299 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 300 | static int send_cmd(struct usb_device *dev, __u8 command, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | __u8 moduleid, __u16 value, u8 *data, | 
|  | 302 | int size) | 
|  | 303 | { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 304 | return ti_vsend_sync(dev, command, value, moduleid, data, size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } | 
|  | 306 |  | 
|  | 307 | /* clear tx/rx buffers and fifo in TI UMP */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 308 | static int purge_port(struct usb_serial_port *port, __u16 mask) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { | 
|  | 310 | int port_number = port->number - port->serial->minor; | 
|  | 311 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 312 | dbg("%s - port %d, mask %x", __func__, port_number, mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 314 | return send_cmd(port->serial->dev, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | UMPC_PURGE_PORT, | 
|  | 316 | (__u8)(UMPM_UART1_PORT + port_number), | 
|  | 317 | mask, | 
|  | 318 | NULL, | 
|  | 319 | 0); | 
|  | 320 | } | 
|  | 321 |  | 
|  | 322 | /** | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 323 | * read_download_mem - Read edgeport memory from TI chip | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | * @dev: usb device pointer | 
|  | 325 | * @start_address: Device CPU address at which to read | 
|  | 326 | * @length: Length of above data | 
|  | 327 | * @address_type: Can read both XDATA and I2C | 
|  | 328 | * @buffer: pointer to input data buffer | 
|  | 329 | */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 330 | static int read_download_mem(struct usb_device *dev, int start_address, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | int length, __u8 address_type, __u8 *buffer) | 
|  | 332 | { | 
|  | 333 | int status = 0; | 
|  | 334 | __u8 read_length; | 
|  | 335 | __be16 be_start_address; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 336 |  | 
|  | 337 | dbg("%s - @ %x for %d", __func__, start_address, length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 |  | 
|  | 339 | /* Read in blocks of 64 bytes | 
|  | 340 | * (TI firmware can't handle more than 64 byte reads) | 
|  | 341 | */ | 
|  | 342 | while (length) { | 
|  | 343 | if (length > 64) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 344 | read_length = 64; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | else | 
|  | 346 | read_length = (__u8)length; | 
|  | 347 |  | 
|  | 348 | if (read_length > 1) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 349 | dbg("%s - @ %x for %d", __func__, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | start_address, read_length); | 
|  | 351 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 352 | be_start_address = cpu_to_be16(start_address); | 
|  | 353 | status = ti_vread_sync(dev, UMPC_MEMORY_READ, | 
|  | 354 | (__u16)address_type, | 
|  | 355 | (__force __u16)be_start_address, | 
|  | 356 | buffer, read_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 |  | 
|  | 358 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 359 | dbg("%s - ERROR %x", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return status; | 
|  | 361 | } | 
|  | 362 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 363 | if (read_length > 1) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 364 | usb_serial_debug_data(debug, &dev->dev, __func__, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | read_length, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 |  | 
|  | 367 | /* Update pointers/length */ | 
|  | 368 | start_address += read_length; | 
|  | 369 | buffer += read_length; | 
|  | 370 | length -= read_length; | 
|  | 371 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 372 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return status; | 
|  | 374 | } | 
|  | 375 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 376 | static int read_ram(struct usb_device *dev, int start_address, | 
|  | 377 | int length, __u8 *buffer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 379 | return read_download_mem(dev, start_address, length, | 
|  | 380 | DTK_ADDR_SPACE_XDATA, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } | 
|  | 382 |  | 
|  | 383 | /* Read edgeport memory to a given block */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 384 | static int read_boot_mem(struct edgeport_serial *serial, | 
|  | 385 | int start_address, int length, __u8 *buffer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { | 
|  | 387 | int status = 0; | 
|  | 388 | int i; | 
|  | 389 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 390 | for (i = 0; i < length; i++) { | 
|  | 391 | status = ti_vread_sync(serial->serial->dev, | 
|  | 392 | UMPC_MEMORY_READ, serial->TI_I2C_Type, | 
|  | 393 | (__u16)(start_address+i), &buffer[i], 0x01); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 395 | dbg("%s - ERROR %x", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | return status; | 
|  | 397 | } | 
|  | 398 | } | 
|  | 399 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 400 | dbg("%s - start_address = %x, length = %d", | 
|  | 401 | __func__, start_address, length); | 
|  | 402 | usb_serial_debug_data(debug, &serial->serial->dev->dev, | 
|  | 403 | __func__, length, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 |  | 
|  | 405 | serial->TiReadI2C = 1; | 
|  | 406 |  | 
|  | 407 | return status; | 
|  | 408 | } | 
|  | 409 |  | 
|  | 410 | /* Write given block to TI EPROM memory */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 411 | static int write_boot_mem(struct edgeport_serial *serial, | 
|  | 412 | int start_address, int length, __u8 *buffer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { | 
|  | 414 | int status = 0; | 
|  | 415 | int i; | 
|  | 416 | __u8 temp; | 
|  | 417 |  | 
|  | 418 | /* Must do a read before write */ | 
|  | 419 | if (!serial->TiReadI2C) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 420 | status = read_boot_mem(serial, 0, 1, &temp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | if (status) | 
|  | 422 | return status; | 
|  | 423 | } | 
|  | 424 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 425 | for (i = 0; i < length; ++i) { | 
|  | 426 | status = ti_vsend_sync(serial->serial->dev, | 
|  | 427 | UMPC_MEMORY_WRITE, buffer[i], | 
|  | 428 | (__u16)(i + start_address), NULL, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | if (status) | 
|  | 430 | return status; | 
|  | 431 | } | 
|  | 432 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 433 | dbg("%s - start_sddr = %x, length = %d", | 
|  | 434 | __func__, start_address, length); | 
|  | 435 | usb_serial_debug_data(debug, &serial->serial->dev->dev, | 
|  | 436 | __func__, length, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 |  | 
|  | 438 | return status; | 
|  | 439 | } | 
|  | 440 |  | 
|  | 441 |  | 
|  | 442 | /* Write edgeport I2C memory to TI chip	*/ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 443 | static int write_i2c_mem(struct edgeport_serial *serial, | 
|  | 444 | int start_address, int length, __u8 address_type, __u8 *buffer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { | 
|  | 446 | int status = 0; | 
|  | 447 | int write_length; | 
|  | 448 | __be16 be_start_address; | 
|  | 449 |  | 
|  | 450 | /* We can only send a maximum of 1 aligned byte page at a time */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 451 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | /* calulate the number of bytes left in the first page */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 453 | write_length = EPROM_PAGE_SIZE - | 
|  | 454 | (start_address & (EPROM_PAGE_SIZE - 1)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 |  | 
|  | 456 | if (write_length > length) | 
|  | 457 | write_length = length; | 
|  | 458 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 459 | dbg("%s - BytesInFirstPage Addr = %x, length = %d", | 
|  | 460 | __func__, start_address, write_length); | 
|  | 461 | usb_serial_debug_data(debug, &serial->serial->dev->dev, | 
|  | 462 | __func__, write_length, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 |  | 
|  | 464 | /* Write first page */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 465 | be_start_address = cpu_to_be16(start_address); | 
|  | 466 | status = ti_vsend_sync(serial->serial->dev, | 
|  | 467 | UMPC_MEMORY_WRITE, (__u16)address_type, | 
|  | 468 | (__force __u16)be_start_address, | 
|  | 469 | buffer,	write_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 471 | dbg("%s - ERROR %d", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | return status; | 
|  | 473 | } | 
|  | 474 |  | 
|  | 475 | length		-= write_length; | 
|  | 476 | start_address	+= write_length; | 
|  | 477 | buffer		+= write_length; | 
|  | 478 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 479 | /* We should be aligned now -- can write | 
|  | 480 | max page size bytes at a time */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | while (length) { | 
|  | 482 | if (length > EPROM_PAGE_SIZE) | 
|  | 483 | write_length = EPROM_PAGE_SIZE; | 
|  | 484 | else | 
|  | 485 | write_length = length; | 
|  | 486 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 487 | dbg("%s - Page Write Addr = %x, length = %d", | 
|  | 488 | __func__, start_address, write_length); | 
|  | 489 | usb_serial_debug_data(debug, &serial->serial->dev->dev, | 
|  | 490 | __func__, write_length, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 |  | 
|  | 492 | /* Write next page */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 493 | be_start_address = cpu_to_be16(start_address); | 
|  | 494 | status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE, | 
|  | 495 | (__u16)address_type, | 
|  | 496 | (__force __u16)be_start_address, | 
|  | 497 | buffer, write_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 499 | dev_err(&serial->serial->dev->dev, "%s - ERROR %d\n", | 
|  | 500 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | return status; | 
|  | 502 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 503 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | length		-= write_length; | 
|  | 505 | start_address	+= write_length; | 
|  | 506 | buffer		+= write_length; | 
|  | 507 | } | 
|  | 508 | return status; | 
|  | 509 | } | 
|  | 510 |  | 
|  | 511 | /* Examine the UMP DMA registers and LSR | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 512 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | * Check the MSBit of the X and Y DMA byte count registers. | 
|  | 514 | * A zero in this bit indicates that the TX DMA buffers are empty | 
|  | 515 | * then check the TX Empty bit in the UART. | 
|  | 516 | */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 517 | static int tx_active(struct edgeport_port *port) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { | 
|  | 519 | int status; | 
|  | 520 | struct out_endpoint_desc_block *oedb; | 
|  | 521 | __u8 *lsr; | 
|  | 522 | int bytes_left = 0; | 
|  | 523 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 524 | oedb = kmalloc(sizeof(*oedb), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | if (!oedb) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 526 | dev_err(&port->port->dev, "%s - out of memory\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | return -ENOMEM; | 
|  | 528 | } | 
|  | 529 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 530 | lsr = kmalloc(1, GFP_KERNEL);	/* Sigh, that's right, just one byte, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | as not all platforms can do DMA | 
|  | 532 | from stack */ | 
|  | 533 | if (!lsr) { | 
|  | 534 | kfree(oedb); | 
|  | 535 | return -ENOMEM; | 
|  | 536 | } | 
|  | 537 | /* Read the DMA Count Registers */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 538 | status = read_ram(port->port->serial->dev, port->dma_address, | 
|  | 539 | sizeof(*oedb), (void *)oedb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | if (status) | 
|  | 541 | goto exit_is_tx_active; | 
|  | 542 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 543 | dbg("%s - XByteCount    0x%X", __func__, oedb->XByteCount); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 |  | 
|  | 545 | /* and the LSR */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 546 | status = read_ram(port->port->serial->dev, | 
|  | 547 | port->uart_base + UMPMEM_OFFS_UART_LSR, 1, lsr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 |  | 
|  | 549 | if (status) | 
|  | 550 | goto exit_is_tx_active; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 551 | dbg("%s - LSR = 0x%X", __func__, *lsr); | 
|  | 552 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | /* If either buffer has data or we are transmitting then return TRUE */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 554 | if ((oedb->XByteCount & 0x80) != 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | bytes_left += 64; | 
|  | 556 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 557 | if ((*lsr & UMP_UART_LSR_TX_MASK) == 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | bytes_left += 1; | 
|  | 559 |  | 
|  | 560 | /* We return Not Active if we get any kind of error */ | 
|  | 561 | exit_is_tx_active: | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 562 | dbg("%s - return %d", __func__, bytes_left); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 |  | 
|  | 564 | kfree(lsr); | 
|  | 565 | kfree(oedb); | 
|  | 566 | return bytes_left; | 
|  | 567 | } | 
|  | 568 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 569 | static void chase_port(struct edgeport_port *port, unsigned long timeout, | 
|  | 570 | int flush) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { | 
|  | 572 | int baud_rate; | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 573 | struct tty_struct *tty = tty_port_tty_get(&port->port->port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | wait_queue_t wait; | 
|  | 575 | unsigned long flags; | 
|  | 576 |  | 
|  | 577 | if (!timeout) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 578 | timeout = (HZ * EDGE_CLOSING_WAIT)/100; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 |  | 
|  | 580 | /* wait for data to drain from the buffer */ | 
|  | 581 | spin_lock_irqsave(&port->ep_lock, flags); | 
|  | 582 | init_waitqueue_entry(&wait, current); | 
|  | 583 | add_wait_queue(&tty->write_wait, &wait); | 
|  | 584 | for (;;) { | 
|  | 585 | set_current_state(TASK_INTERRUPTIBLE); | 
|  | 586 | if (edge_buf_data_avail(port->ep_out_buf) == 0 | 
|  | 587 | || timeout == 0 || signal_pending(current) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 588 | || !usb_get_intfdata(port->port->serial->interface)) | 
|  | 589 | /* disconnect */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | break; | 
|  | 591 | spin_unlock_irqrestore(&port->ep_lock, flags); | 
|  | 592 | timeout = schedule_timeout(timeout); | 
|  | 593 | spin_lock_irqsave(&port->ep_lock, flags); | 
|  | 594 | } | 
|  | 595 | set_current_state(TASK_RUNNING); | 
|  | 596 | remove_wait_queue(&tty->write_wait, &wait); | 
|  | 597 | if (flush) | 
|  | 598 | edge_buf_clear(port->ep_out_buf); | 
|  | 599 | spin_unlock_irqrestore(&port->ep_lock, flags); | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 600 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 |  | 
|  | 602 | /* wait for data to drain from the device */ | 
|  | 603 | timeout += jiffies; | 
|  | 604 | while ((long)(jiffies - timeout) < 0 && !signal_pending(current) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 605 | && usb_get_intfdata(port->port->serial->interface)) { | 
|  | 606 | /* not disconnected */ | 
|  | 607 | if (!tx_active(port)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | break; | 
|  | 609 | msleep(10); | 
|  | 610 | } | 
|  | 611 |  | 
|  | 612 | /* disconnected */ | 
|  | 613 | if (!usb_get_intfdata(port->port->serial->interface)) | 
|  | 614 | return; | 
|  | 615 |  | 
|  | 616 | /* wait one more character time, based on baud rate */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 617 | /* (tx_active doesn't seem to wait for the last byte) */ | 
|  | 618 | baud_rate = port->baud_rate; | 
|  | 619 | if (baud_rate == 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | baud_rate = 50; | 
| Julia Lawall | dfa5ec7 | 2008-03-04 15:25:11 -0800 | [diff] [blame] | 621 | msleep(max(1, DIV_ROUND_UP(10000, baud_rate))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } | 
|  | 623 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 624 | static int choose_config(struct usb_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 626 | /* | 
|  | 627 | * There may be multiple configurations on this device, in which case | 
|  | 628 | * we would need to read and parse all of them to find out which one | 
|  | 629 | * we want. However, we just support one config at this point, | 
|  | 630 | * configuration # 1, which is Config Descriptor 0. | 
|  | 631 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 633 | dbg("%s - Number of Interfaces = %d", | 
|  | 634 | __func__, dev->config->desc.bNumInterfaces); | 
|  | 635 | dbg("%s - MAX Power            = %d", | 
|  | 636 | __func__, dev->config->desc.bMaxPower * 2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 |  | 
|  | 638 | if (dev->config->desc.bNumInterfaces != 1) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 639 | dev_err(&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", | 
|  | 640 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return -ENODEV; | 
|  | 642 | } | 
|  | 643 |  | 
|  | 644 | return 0; | 
|  | 645 | } | 
|  | 646 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 647 | static int read_rom(struct edgeport_serial *serial, | 
|  | 648 | int start_address, int length, __u8 *buffer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | { | 
|  | 650 | int status; | 
|  | 651 |  | 
|  | 652 | if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 653 | status = read_download_mem(serial->serial->dev, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | start_address, | 
|  | 655 | length, | 
|  | 656 | serial->TI_I2C_Type, | 
|  | 657 | buffer); | 
|  | 658 | } else { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 659 | status = read_boot_mem(serial, start_address, length, | 
|  | 660 | buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | return status; | 
|  | 663 | } | 
|  | 664 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 665 | static int write_rom(struct edgeport_serial *serial, int start_address, | 
|  | 666 | int length, __u8 *buffer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { | 
|  | 668 | if (serial->product_info.TiMode == TI_MODE_BOOT) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 669 | return write_boot_mem(serial, start_address, length, | 
|  | 670 | buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 |  | 
|  | 672 | if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 673 | return write_i2c_mem(serial, start_address, length, | 
|  | 674 | serial->TI_I2C_Type, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | return -EINVAL; | 
|  | 676 | } | 
|  | 677 |  | 
|  | 678 |  | 
|  | 679 |  | 
|  | 680 | /* Read a descriptor header from I2C based on type */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 681 | static int get_descriptor_addr(struct edgeport_serial *serial, | 
|  | 682 | int desc_type, struct ti_i2c_desc *rom_desc) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { | 
|  | 684 | int start_address; | 
|  | 685 | int status; | 
|  | 686 |  | 
|  | 687 | /* Search for requested descriptor in I2C */ | 
|  | 688 | start_address = 2; | 
|  | 689 | do { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 690 | status = read_rom(serial, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | start_address, | 
|  | 692 | sizeof(struct ti_i2c_desc), | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 693 | (__u8 *)rom_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | if (status) | 
|  | 695 | return 0; | 
|  | 696 |  | 
|  | 697 | if (rom_desc->Type == desc_type) | 
|  | 698 | return start_address; | 
|  | 699 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 700 | start_address = start_address + sizeof(struct ti_i2c_desc) | 
|  | 701 | + rom_desc->Size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 |  | 
|  | 703 | } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 704 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | return 0; | 
|  | 706 | } | 
|  | 707 |  | 
|  | 708 | /* Validate descriptor checksum */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 709 | static int valid_csum(struct ti_i2c_desc *rom_desc, __u8 *buffer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { | 
|  | 711 | __u16 i; | 
|  | 712 | __u8 cs = 0; | 
|  | 713 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 714 | for (i = 0; i < rom_desc->Size; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | cs = (__u8)(cs + buffer[i]); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 716 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (cs != rom_desc->CheckSum) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 718 | dbg("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | return -EINVAL; | 
|  | 720 | } | 
|  | 721 | return 0; | 
|  | 722 | } | 
|  | 723 |  | 
|  | 724 | /* Make sure that the I2C image is good */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 725 | static int check_i2c_image(struct edgeport_serial *serial) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | { | 
|  | 727 | struct device *dev = &serial->serial->dev->dev; | 
|  | 728 | int status = 0; | 
|  | 729 | struct ti_i2c_desc *rom_desc; | 
|  | 730 | int start_address = 2; | 
|  | 731 | __u8 *buffer; | 
|  | 732 | __u16 ttype; | 
|  | 733 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 734 | rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | if (!rom_desc) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 736 | dev_err(dev, "%s - out of memory\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return -ENOMEM; | 
|  | 738 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 739 | buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | if (!buffer) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 741 | dev_err(dev, "%s - out of memory when allocating buffer\n", | 
|  | 742 | __func__); | 
|  | 743 | kfree(rom_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | return -ENOMEM; | 
|  | 745 | } | 
|  | 746 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 747 | /* Read the first byte (Signature0) must be 0x52 or 0x10 */ | 
|  | 748 | status = read_rom(serial, 0, 1, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | if (status) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 750 | goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 |  | 
|  | 752 | if (*buffer != UMP5152 && *buffer != UMP3410) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 753 | dev_err(dev, "%s - invalid buffer signature\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | status = -ENODEV; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 755 | goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } | 
|  | 757 |  | 
|  | 758 | do { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 759 | /* Validate the I2C */ | 
|  | 760 | status = read_rom(serial, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | start_address, | 
|  | 762 | sizeof(struct ti_i2c_desc), | 
|  | 763 | (__u8 *)rom_desc); | 
|  | 764 | if (status) | 
|  | 765 | break; | 
|  | 766 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 767 | if ((start_address + sizeof(struct ti_i2c_desc) + | 
|  | 768 | rom_desc->Size) > TI_MAX_I2C_SIZE) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | status = -ENODEV; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 770 | dbg("%s - structure too big, erroring out.", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | break; | 
|  | 772 | } | 
|  | 773 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 774 | dbg("%s Type = 0x%x", __func__, rom_desc->Type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 776 | /* Skip type 2 record */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | ttype = rom_desc->Type & 0x0f; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 778 | if (ttype != I2C_DESC_TYPE_FIRMWARE_BASIC | 
|  | 779 | && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO) { | 
|  | 780 | /* Read the descriptor data */ | 
|  | 781 | status = read_rom(serial, start_address + | 
|  | 782 | sizeof(struct ti_i2c_desc), | 
|  | 783 | rom_desc->Size, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | if (status) | 
|  | 785 | break; | 
|  | 786 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 787 | status = valid_csum(rom_desc, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | if (status) | 
|  | 789 | break; | 
|  | 790 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 791 | start_address = start_address + sizeof(struct ti_i2c_desc) + | 
|  | 792 | rom_desc->Size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 794 | } while ((rom_desc->Type != I2C_DESC_TYPE_ION) && | 
|  | 795 | (start_address < TI_MAX_I2C_SIZE)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 797 | if ((rom_desc->Type != I2C_DESC_TYPE_ION) || | 
|  | 798 | (start_address > TI_MAX_I2C_SIZE)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | status = -ENODEV; | 
|  | 800 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 801 | out: | 
|  | 802 | kfree(buffer); | 
|  | 803 | kfree(rom_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | return status; | 
|  | 805 | } | 
|  | 806 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 807 | static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | { | 
|  | 809 | int status; | 
|  | 810 | int start_address; | 
|  | 811 | struct ti_i2c_desc *rom_desc; | 
|  | 812 | struct edge_ti_manuf_descriptor *desc; | 
|  | 813 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 814 | rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | if (!rom_desc) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 816 | dev_err(&serial->serial->dev->dev, "%s - out of memory\n", | 
|  | 817 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | return -ENOMEM; | 
|  | 819 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 820 | start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION, | 
|  | 821 | rom_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 |  | 
|  | 823 | if (!start_address) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 824 | dbg("%s - Edge Descriptor not found in I2C", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | status = -ENODEV; | 
|  | 826 | goto exit; | 
|  | 827 | } | 
|  | 828 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 829 | /* Read the descriptor data */ | 
|  | 830 | status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc), | 
|  | 831 | rom_desc->Size, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | if (status) | 
|  | 833 | goto exit; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 834 |  | 
|  | 835 | status = valid_csum(rom_desc, buffer); | 
|  | 836 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | desc = (struct edge_ti_manuf_descriptor *)buffer; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 838 | dbg("%s - IonConfig      0x%x", __func__, desc->IonConfig); | 
|  | 839 | dbg("%s - Version          %d", __func__, desc->Version); | 
|  | 840 | dbg("%s - Cpu/Board      0x%x", __func__, desc->CpuRev_BoardRev); | 
|  | 841 | dbg("%s - NumPorts         %d", __func__, desc->NumPorts); | 
|  | 842 | dbg("%s - NumVirtualPorts  %d", __func__, desc->NumVirtualPorts); | 
|  | 843 | dbg("%s - TotalPorts       %d", __func__, desc->TotalPorts); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 |  | 
|  | 845 | exit: | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 846 | kfree(rom_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | return status; | 
|  | 848 | } | 
|  | 849 |  | 
|  | 850 | /* Build firmware header used for firmware update */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 851 | static int build_i2c_fw_hdr(__u8 *header, struct device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | { | 
|  | 853 | __u8 *buffer; | 
|  | 854 | int buffer_size; | 
|  | 855 | int i; | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 856 | int err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | __u8 cs = 0; | 
|  | 858 | struct ti_i2c_desc *i2c_header; | 
|  | 859 | struct ti_i2c_image_header *img_header; | 
|  | 860 | struct ti_i2c_firmware_rec *firmware_rec; | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 861 | const struct firmware *fw; | 
|  | 862 | const char *fw_name = "edgeport/down3.bin"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 864 | /* In order to update the I2C firmware we must change the type 2 record | 
|  | 865 | * to type 0xF2.  This will force the UMP to come up in Boot Mode. | 
|  | 866 | * Then while in boot mode, the driver will download the latest | 
|  | 867 | * firmware (padded to 15.5k) into the UMP ram.  And finally when the | 
|  | 868 | * device comes back up in download mode the driver will cause the new | 
|  | 869 | * firmware to be copied from the UMP Ram to I2C and the firmware will | 
|  | 870 | * update the record type from 0xf2 to 0x02. | 
|  | 871 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 873 | /* Allocate a 15.5k buffer + 2 bytes for version number | 
|  | 874 | * (Firmware Record) */ | 
|  | 875 | buffer_size = (((1024 * 16) - 512 ) + | 
|  | 876 | sizeof(struct ti_i2c_firmware_rec)); | 
|  | 877 |  | 
|  | 878 | buffer = kmalloc(buffer_size, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | if (!buffer) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 880 | dev_err(dev, "%s - out of memory\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | return -ENOMEM; | 
|  | 882 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 883 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | // Set entire image of 0xffs | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 885 | memset(buffer, 0xff, buffer_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 |  | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 887 | err = request_firmware(&fw, fw_name, dev); | 
|  | 888 | if (err) { | 
|  | 889 | printk(KERN_ERR "Failed to load image \"%s\" err %d\n", | 
|  | 890 | fw_name, err); | 
|  | 891 | kfree(buffer); | 
|  | 892 | return err; | 
|  | 893 | } | 
|  | 894 |  | 
|  | 895 | /* Save Download Version Number */ | 
|  | 896 | OperationalMajorVersion = fw->data[0]; | 
|  | 897 | OperationalMinorVersion = fw->data[1]; | 
|  | 898 | OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8); | 
|  | 899 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 900 | /* Copy version number into firmware record */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | firmware_rec = (struct ti_i2c_firmware_rec *)buffer; | 
|  | 902 |  | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 903 | firmware_rec->Ver_Major	= OperationalMajorVersion; | 
|  | 904 | firmware_rec->Ver_Minor	= OperationalMinorVersion; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 906 | /* Pointer to fw_down memory image */ | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 907 | img_header = (struct ti_i2c_image_header *)&fw->data[4]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 909 | memcpy(buffer + sizeof(struct ti_i2c_firmware_rec), | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 910 | &fw->data[4 + sizeof(struct ti_i2c_image_header)], | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | le16_to_cpu(img_header->Length)); | 
|  | 912 |  | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 913 | release_firmware(fw); | 
|  | 914 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | for (i=0; i < buffer_size; i++) { | 
|  | 916 | cs = (__u8)(cs + buffer[i]); | 
|  | 917 | } | 
|  | 918 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 919 | kfree(buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 921 | /* Build new header */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | i2c_header =  (struct ti_i2c_desc *)header; | 
|  | 923 | firmware_rec =  (struct ti_i2c_firmware_rec*)i2c_header->Data; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 924 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | i2c_header->Type	= I2C_DESC_TYPE_FIRMWARE_BLANK; | 
|  | 926 | i2c_header->Size	= (__u16)buffer_size; | 
|  | 927 | i2c_header->CheckSum	= cs; | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 928 | firmware_rec->Ver_Major	= OperationalMajorVersion; | 
|  | 929 | firmware_rec->Ver_Minor	= OperationalMinorVersion; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 |  | 
|  | 931 | return 0; | 
|  | 932 | } | 
|  | 933 |  | 
|  | 934 | /* Try to figure out what type of I2c we have */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 935 | static int i2c_type_bootmode(struct edgeport_serial *serial) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | { | 
|  | 937 | int status; | 
|  | 938 | __u8 data; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 939 |  | 
|  | 940 | /* Try to read type 2 */ | 
|  | 941 | status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ, | 
|  | 942 | DTK_ADDR_SPACE_I2C_TYPE_II, 0, &data, 0x01); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | if (status) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 944 | dbg("%s - read 2 status error = %d", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | else | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 946 | dbg("%s - read 2 data = 0x%x", __func__, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | if ((!status) && (data == UMP5152 || data == UMP3410)) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 948 | dbg("%s - ROM_TYPE_II", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; | 
|  | 950 | return 0; | 
|  | 951 | } | 
|  | 952 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 953 | /* Try to read type 3 */ | 
|  | 954 | status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ, | 
|  | 955 | DTK_ADDR_SPACE_I2C_TYPE_III, 0,	&data, 0x01); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | if (status) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 957 | dbg("%s - read 3 status error = %d", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | else | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 959 | dbg("%s - read 2 data = 0x%x", __func__, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | if ((!status) && (data == UMP5152 || data == UMP3410)) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 961 | dbg("%s - ROM_TYPE_III", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III; | 
|  | 963 | return 0; | 
|  | 964 | } | 
|  | 965 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 966 | dbg("%s - Unknown", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; | 
|  | 968 | return -ENODEV; | 
|  | 969 | } | 
|  | 970 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 971 | static int bulk_xfer(struct usb_serial *serial, void *buffer, | 
|  | 972 | int length, int *num_sent) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { | 
|  | 974 | int status; | 
|  | 975 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 976 | status = usb_bulk_msg(serial->dev, | 
|  | 977 | usb_sndbulkpipe(serial->dev, | 
|  | 978 | serial->port[0]->bulk_out_endpointAddress), | 
|  | 979 | buffer, length, num_sent, 1000); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | return status; | 
|  | 981 | } | 
|  | 982 |  | 
|  | 983 | /* Download given firmware image to the device (IN BOOT MODE) */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 984 | static int download_code(struct edgeport_serial *serial, __u8 *image, | 
|  | 985 | int image_length) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | { | 
|  | 987 | int status = 0; | 
|  | 988 | int pos; | 
|  | 989 | int transfer; | 
|  | 990 | int done; | 
|  | 991 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 992 | /* Transfer firmware image */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | for (pos = 0; pos < image_length; ) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 994 | /* Read the next buffer from file */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | transfer = image_length - pos; | 
|  | 996 | if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE) | 
|  | 997 | transfer = EDGE_FW_BULK_MAX_PACKET_SIZE; | 
|  | 998 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 999 | /* Transfer data */ | 
|  | 1000 | status = bulk_xfer(serial->serial, &image[pos], | 
|  | 1001 | transfer, &done); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | if (status) | 
|  | 1003 | break; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1004 | /* Advance buffer pointer */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | pos += done; | 
|  | 1006 | } | 
|  | 1007 |  | 
|  | 1008 | return status; | 
|  | 1009 | } | 
|  | 1010 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1011 | /* FIXME!!! */ | 
|  | 1012 | static int config_boot_dev(struct usb_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | { | 
|  | 1014 | return 0; | 
|  | 1015 | } | 
|  | 1016 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1017 | static int ti_cpu_rev(struct edge_ti_manuf_descriptor *desc) | 
|  | 1018 | { | 
|  | 1019 | return TI_GET_CPU_REVISION(desc->CpuRev_BoardRev); | 
|  | 1020 | } | 
|  | 1021 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | /** | 
|  | 1023 | * DownloadTIFirmware - Download run-time operating firmware to the TI5052 | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1024 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | * This routine downloads the main operating code into the TI5052, using the | 
|  | 1026 | * boot code already burned into E2PROM or ROM. | 
|  | 1027 | */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1028 | static int download_fw(struct edgeport_serial *serial) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | { | 
|  | 1030 | struct device *dev = &serial->serial->dev->dev; | 
|  | 1031 | int status = 0; | 
|  | 1032 | int start_address; | 
|  | 1033 | struct edge_ti_manuf_descriptor *ti_manuf_desc; | 
|  | 1034 | struct usb_interface_descriptor *interface; | 
|  | 1035 | int download_cur_ver; | 
|  | 1036 | int download_new_ver; | 
|  | 1037 |  | 
|  | 1038 | /* This routine is entered by both the BOOT mode and the Download mode | 
|  | 1039 | * We can determine which code is running by the reading the config | 
|  | 1040 | * descriptor and if we have only one bulk pipe it is in boot mode | 
|  | 1041 | */ | 
|  | 1042 | serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP; | 
|  | 1043 |  | 
|  | 1044 | /* Default to type 2 i2c */ | 
|  | 1045 | serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; | 
|  | 1046 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1047 | status = choose_config(serial->serial->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | if (status) | 
|  | 1049 | return status; | 
|  | 1050 |  | 
|  | 1051 | interface = &serial->serial->interface->cur_altsetting->desc; | 
|  | 1052 | if (!interface) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1053 | dev_err(dev, "%s - no interface set, error!\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | return -ENODEV; | 
|  | 1055 | } | 
|  | 1056 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1057 | /* | 
|  | 1058 | * Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING | 
|  | 1059 | * if we have more than one endpoint we are definitely in download | 
|  | 1060 | * mode | 
|  | 1061 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | if (interface->bNumEndpoints > 1) | 
|  | 1063 | serial->product_info.TiMode = TI_MODE_DOWNLOAD; | 
|  | 1064 | else | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1065 | /* Otherwise we will remain in configuring mode */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | serial->product_info.TiMode = TI_MODE_CONFIGURING; | 
|  | 1067 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | /********************************************************************/ | 
|  | 1069 | /* Download Mode */ | 
|  | 1070 | /********************************************************************/ | 
|  | 1071 | if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) { | 
|  | 1072 | struct ti_i2c_desc *rom_desc; | 
|  | 1073 |  | 
| Andrew Morton | 9544e83 | 2008-02-04 23:57:50 -0800 | [diff] [blame] | 1074 | dbg("%s - RUNNING IN DOWNLOAD MODE", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1076 | status = check_i2c_image(serial); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | if (status) { | 
| Andrew Morton | 9544e83 | 2008-02-04 23:57:50 -0800 | [diff] [blame] | 1078 | dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | return status; | 
|  | 1080 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1081 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | /* Validate Hardware version number | 
|  | 1083 | * Read Manufacturing Descriptor from TI Based Edgeport | 
|  | 1084 | */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1085 | ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | if (!ti_manuf_desc) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1087 | dev_err(dev, "%s - out of memory.\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | return -ENOMEM; | 
|  | 1089 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1090 | status = get_manuf_info(serial, (__u8 *)ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1092 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | return status; | 
|  | 1094 | } | 
|  | 1095 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1096 | /* Check version number of ION descriptor */ | 
|  | 1097 | if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) { | 
|  | 1098 | dbg("%s - Wrong CPU Rev %d (Must be 2)", | 
|  | 1099 | __func__, ti_cpu_rev(ti_manuf_desc)); | 
|  | 1100 | kfree(ti_manuf_desc); | 
|  | 1101 | return -EINVAL; | 
|  | 1102 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1104 | rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | if (!rom_desc) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1106 | dev_err(dev, "%s - out of memory.\n", __func__); | 
|  | 1107 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | return -ENOMEM; | 
|  | 1109 | } | 
|  | 1110 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1111 | /* Search for type 2 record (firmware record) */ | 
|  | 1112 | start_address = get_descriptor_addr(serial, | 
|  | 1113 | I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc); | 
|  | 1114 | if (start_address != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | struct ti_i2c_firmware_rec *firmware_version; | 
|  | 1116 | __u8 record; | 
|  | 1117 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1118 | dbg("%s - Found Type FIRMWARE (Type 2) record", | 
|  | 1119 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1121 | firmware_version = kmalloc(sizeof(*firmware_version), | 
|  | 1122 | GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | if (!firmware_version) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1124 | dev_err(dev, "%s - out of memory.\n", __func__); | 
|  | 1125 | kfree(rom_desc); | 
|  | 1126 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | return -ENOMEM; | 
|  | 1128 | } | 
|  | 1129 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1130 | /* Validate version number | 
|  | 1131 | * Read the descriptor data | 
|  | 1132 | */ | 
|  | 1133 | status = read_rom(serial, start_address + | 
|  | 1134 | sizeof(struct ti_i2c_desc), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | sizeof(struct ti_i2c_firmware_rec), | 
|  | 1136 | (__u8 *)firmware_version); | 
|  | 1137 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1138 | kfree(firmware_version); | 
|  | 1139 | kfree(rom_desc); | 
|  | 1140 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | return status; | 
|  | 1142 | } | 
|  | 1143 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1144 | /* Check version number of download with current | 
|  | 1145 | version in I2c */ | 
|  | 1146 | download_cur_ver = (firmware_version->Ver_Major << 8) + | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | (firmware_version->Ver_Minor); | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 1148 | download_new_ver = (OperationalMajorVersion << 8) + | 
|  | 1149 | (OperationalMinorVersion); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1151 | dbg("%s - >> FW Versions Device %d.%d  Driver %d.%d", | 
|  | 1152 | __func__, | 
|  | 1153 | firmware_version->Ver_Major, | 
|  | 1154 | firmware_version->Ver_Minor, | 
|  | 1155 | OperationalMajorVersion, | 
|  | 1156 | OperationalMinorVersion); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1158 | /* Check if we have an old version in the I2C and | 
|  | 1159 | update if necessary */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | if (download_cur_ver != download_new_ver) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1161 | dbg("%s - Update I2C dld from %d.%d to %d.%d", | 
|  | 1162 | __func__, | 
|  | 1163 | firmware_version->Ver_Major, | 
|  | 1164 | firmware_version->Ver_Minor, | 
|  | 1165 | OperationalMajorVersion, | 
|  | 1166 | OperationalMinorVersion); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1168 | /* In order to update the I2C firmware we must | 
|  | 1169 | * change the type 2 record to type 0xF2. This | 
|  | 1170 | * will force the UMP to come up in Boot Mode. | 
|  | 1171 | * Then while in boot mode, the driver will | 
|  | 1172 | * download the latest firmware (padded to | 
|  | 1173 | * 15.5k) into the UMP ram. Finally when the | 
|  | 1174 | * device comes back up in download mode the | 
|  | 1175 | * driver will cause the new firmware to be | 
|  | 1176 | * copied from the UMP Ram to I2C and the | 
|  | 1177 | * firmware will update the record type from | 
|  | 1178 | * 0xf2 to 0x02. | 
|  | 1179 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | record = I2C_DESC_TYPE_FIRMWARE_BLANK; | 
|  | 1181 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1182 | /* Change the I2C Firmware record type to | 
|  | 1183 | 0xf2 to trigger an update */ | 
|  | 1184 | status = write_rom(serial, start_address, | 
|  | 1185 | sizeof(record),	&record); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1187 | kfree(firmware_version); | 
|  | 1188 | kfree(rom_desc); | 
|  | 1189 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | return status; | 
|  | 1191 | } | 
|  | 1192 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1193 | /* verify the write -- must do this in order | 
|  | 1194 | * for write to complete before we do the | 
|  | 1195 | * hardware reset | 
|  | 1196 | */ | 
|  | 1197 | status = read_rom(serial, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | start_address, | 
|  | 1199 | sizeof(record), | 
|  | 1200 | &record); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1202 | kfree(firmware_version); | 
|  | 1203 | kfree(rom_desc); | 
|  | 1204 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | return status; | 
|  | 1206 | } | 
|  | 1207 |  | 
|  | 1208 | if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1209 | dev_err(dev, | 
|  | 1210 | "%s - error resetting device\n", | 
|  | 1211 | __func__); | 
|  | 1212 | kfree(firmware_version); | 
|  | 1213 | kfree(rom_desc); | 
|  | 1214 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | return -ENODEV; | 
|  | 1216 | } | 
|  | 1217 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1218 | dbg("%s - HARDWARE RESET", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1220 | /* Reset UMP -- Back to BOOT MODE */ | 
|  | 1221 | status = ti_vsend_sync(serial->serial->dev, | 
|  | 1222 | UMPC_HARDWARE_RESET, | 
|  | 1223 | 0, 0, NULL, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1225 | dbg("%s - HARDWARE RESET return %d", | 
|  | 1226 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 |  | 
|  | 1228 | /* return an error on purpose. */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1229 | kfree(firmware_version); | 
|  | 1230 | kfree(rom_desc); | 
|  | 1231 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | return -ENODEV; | 
|  | 1233 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1234 | kfree(firmware_version); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1236 | /* Search for type 0xF2 record (firmware blank record) */ | 
|  | 1237 | else if ((start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) { | 
|  | 1238 | #define HEADER_SIZE	(sizeof(struct ti_i2c_desc) + \ | 
|  | 1239 | sizeof(struct ti_i2c_firmware_rec)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | __u8 *header; | 
|  | 1241 | __u8 *vheader; | 
|  | 1242 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1243 | header = kmalloc(HEADER_SIZE, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | if (!header) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1245 | dev_err(dev, "%s - out of memory.\n", __func__); | 
|  | 1246 | kfree(rom_desc); | 
|  | 1247 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | return -ENOMEM; | 
|  | 1249 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1251 | vheader = kmalloc(HEADER_SIZE, GFP_KERNEL); | 
|  | 1252 | if (!vheader) { | 
|  | 1253 | dev_err(dev, "%s - out of memory.\n", __func__); | 
|  | 1254 | kfree(header); | 
|  | 1255 | kfree(rom_desc); | 
|  | 1256 | kfree(ti_manuf_desc); | 
|  | 1257 | return -ENOMEM; | 
|  | 1258 | } | 
|  | 1259 |  | 
|  | 1260 | dbg("%s - Found Type BLANK FIRMWARE (Type F2) record", | 
|  | 1261 | __func__); | 
|  | 1262 |  | 
|  | 1263 | /* | 
|  | 1264 | * In order to update the I2C firmware we must change | 
|  | 1265 | * the type 2 record to type 0xF2. This will force the | 
|  | 1266 | * UMP to come up in Boot Mode.  Then while in boot | 
|  | 1267 | * mode, the driver will download the latest firmware | 
|  | 1268 | * (padded to 15.5k) into the UMP ram. Finally when the | 
|  | 1269 | * device comes back up in download mode the driver | 
|  | 1270 | * will cause the new firmware to be copied from the | 
|  | 1271 | * UMP Ram to I2C and the firmware will update the | 
|  | 1272 | * record type from 0xf2 to 0x02. | 
|  | 1273 | */ | 
|  | 1274 | status = build_i2c_fw_hdr(header, dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1276 | kfree(vheader); | 
|  | 1277 | kfree(header); | 
|  | 1278 | kfree(rom_desc); | 
|  | 1279 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | return status; | 
|  | 1281 | } | 
|  | 1282 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1283 | /* Update I2C with type 0xf2 record with correct | 
|  | 1284 | size and checksum */ | 
|  | 1285 | status = write_rom(serial, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | start_address, | 
|  | 1287 | HEADER_SIZE, | 
|  | 1288 | header); | 
|  | 1289 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1290 | kfree(vheader); | 
|  | 1291 | kfree(header); | 
|  | 1292 | kfree(rom_desc); | 
|  | 1293 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | return status; | 
|  | 1295 | } | 
|  | 1296 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1297 | /* verify the write -- must do this in order for | 
|  | 1298 | write to complete before we do the hardware reset */ | 
|  | 1299 | status = read_rom(serial, start_address, | 
|  | 1300 | HEADER_SIZE, vheader); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 |  | 
|  | 1302 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1303 | dbg("%s - can't read header back", __func__); | 
|  | 1304 | kfree(vheader); | 
|  | 1305 | kfree(header); | 
|  | 1306 | kfree(rom_desc); | 
|  | 1307 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | return status; | 
|  | 1309 | } | 
|  | 1310 | if (memcmp(vheader, header, HEADER_SIZE)) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1311 | dbg("%s - write download record failed", | 
|  | 1312 | __func__); | 
|  | 1313 | kfree(vheader); | 
|  | 1314 | kfree(header); | 
|  | 1315 | kfree(rom_desc); | 
|  | 1316 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | return status; | 
|  | 1318 | } | 
|  | 1319 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1320 | kfree(vheader); | 
|  | 1321 | kfree(header); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1323 | dbg("%s - Start firmware update", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1325 | /* Tell firmware to copy download image into I2C */ | 
|  | 1326 | status = ti_vsend_sync(serial->serial->dev, | 
|  | 1327 | UMPC_COPY_DNLD_TO_I2C, 0, 0, NULL, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1329 | dbg("%s - Update complete 0x%x", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1331 | dev_err(dev, | 
|  | 1332 | "%s - UMPC_COPY_DNLD_TO_I2C failed\n", | 
|  | 1333 | __func__); | 
|  | 1334 | kfree(rom_desc); | 
|  | 1335 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | return status; | 
|  | 1337 | } | 
|  | 1338 | } | 
|  | 1339 |  | 
|  | 1340 | // The device is running the download code | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1341 | kfree(rom_desc); | 
|  | 1342 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | return 0; | 
|  | 1344 | } | 
|  | 1345 |  | 
|  | 1346 | /********************************************************************/ | 
|  | 1347 | /* Boot Mode */ | 
|  | 1348 | /********************************************************************/ | 
| Andrew Morton | 9544e83 | 2008-02-04 23:57:50 -0800 | [diff] [blame] | 1349 | dbg("%s - RUNNING IN BOOT MODE", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1351 | /* Configure the TI device so we can use the BULK pipes for download */ | 
|  | 1352 | status = config_boot_dev(serial->serial->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | if (status) | 
|  | 1354 | return status; | 
|  | 1355 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1356 | if (le16_to_cpu(serial->serial->dev->descriptor.idVendor) | 
|  | 1357 | != USB_VENDOR_ID_ION) { | 
|  | 1358 | dbg("%s - VID = 0x%x", __func__, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | le16_to_cpu(serial->serial->dev->descriptor.idVendor)); | 
|  | 1360 | serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1361 | goto stayinbootmode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | } | 
|  | 1363 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1364 | /* We have an ION device (I2c Must be programmed) | 
|  | 1365 | Determine I2C image type */ | 
|  | 1366 | if (i2c_type_bootmode(serial)) | 
|  | 1367 | goto stayinbootmode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1369 | /* Check for ION Vendor ID and that the I2C is valid */ | 
|  | 1370 | if (!check_i2c_image(serial)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | struct ti_i2c_image_header *header; | 
|  | 1372 | int i; | 
|  | 1373 | __u8 cs = 0; | 
|  | 1374 | __u8 *buffer; | 
|  | 1375 | int buffer_size; | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 1376 | int err; | 
|  | 1377 | const struct firmware *fw; | 
|  | 1378 | const char *fw_name = "edgeport/down3.bin"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 |  | 
|  | 1380 | /* Validate Hardware version number | 
|  | 1381 | * Read Manufacturing Descriptor from TI Based Edgeport | 
|  | 1382 | */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1383 | ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | if (!ti_manuf_desc) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1385 | dev_err(dev, "%s - out of memory.\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | return -ENOMEM; | 
|  | 1387 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1388 | status = get_manuf_info(serial, (__u8 *)ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1390 | kfree(ti_manuf_desc); | 
|  | 1391 | goto stayinbootmode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | } | 
|  | 1393 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1394 | /* Check for version 2 */ | 
|  | 1395 | if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) { | 
|  | 1396 | dbg("%s - Wrong CPU Rev %d (Must be 2)", | 
|  | 1397 | __func__, ti_cpu_rev(ti_manuf_desc)); | 
|  | 1398 | kfree(ti_manuf_desc); | 
|  | 1399 | goto stayinbootmode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | } | 
|  | 1401 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1402 | kfree(ti_manuf_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | /* | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1405 | * In order to update the I2C firmware we must change the type | 
|  | 1406 | * 2 record to type 0xF2. This will force the UMP to come up | 
|  | 1407 | * in Boot Mode.  Then while in boot mode, the driver will | 
|  | 1408 | * download the latest firmware (padded to 15.5k) into the | 
|  | 1409 | * UMP ram. Finally when the device comes back up in download | 
|  | 1410 | * mode the driver will cause the new firmware to be copied | 
|  | 1411 | * from the UMP Ram to I2C and the firmware will update the | 
|  | 1412 | * record type from 0xf2 to 0x02. | 
|  | 1413 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | * Do we really have to copy the whole firmware image, | 
|  | 1415 | * or could we do this in place! | 
|  | 1416 | */ | 
|  | 1417 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1418 | /* Allocate a 15.5k buffer + 3 byte header */ | 
|  | 1419 | buffer_size = (((1024 * 16) - 512) + | 
|  | 1420 | sizeof(struct ti_i2c_image_header)); | 
|  | 1421 | buffer = kmalloc(buffer_size, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | if (!buffer) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1423 | dev_err(dev, "%s - out of memory\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | return -ENOMEM; | 
|  | 1425 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1426 |  | 
|  | 1427 | /* Initialize the buffer to 0xff (pad the buffer) */ | 
|  | 1428 | memset(buffer, 0xff, buffer_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 |  | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 1430 | err = request_firmware(&fw, fw_name, dev); | 
|  | 1431 | if (err) { | 
|  | 1432 | printk(KERN_ERR "Failed to load image \"%s\" err %d\n", | 
|  | 1433 | fw_name, err); | 
|  | 1434 | kfree(buffer); | 
|  | 1435 | return err; | 
|  | 1436 | } | 
|  | 1437 | memcpy(buffer, &fw->data[4], fw->size - 4); | 
|  | 1438 | release_firmware(fw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1440 | for (i = sizeof(struct ti_i2c_image_header); | 
|  | 1441 | i < buffer_size; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | cs = (__u8)(cs + buffer[i]); | 
|  | 1443 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1444 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | header = (struct ti_i2c_image_header *)buffer; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1446 |  | 
|  | 1447 | /* update length and checksum after padding */ | 
|  | 1448 | header->Length 	 = cpu_to_le16((__u16)(buffer_size - | 
|  | 1449 | sizeof(struct ti_i2c_image_header))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | header->CheckSum = cs; | 
|  | 1451 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1452 | /* Download the operational code  */ | 
|  | 1453 | dbg("%s - Downloading operational code image (TI UMP)", | 
|  | 1454 | __func__); | 
|  | 1455 | status = download_code(serial, buffer, buffer_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1457 | kfree(buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 |  | 
|  | 1459 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1460 | dbg("%s - Error downloading operational code image", | 
|  | 1461 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | return status; | 
|  | 1463 | } | 
|  | 1464 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1465 | /* Device will reboot */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | serial->product_info.TiMode = TI_MODE_TRANSITIONING; | 
|  | 1467 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1468 | dbg("%s - Download successful -- Device rebooting...", | 
|  | 1469 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 |  | 
|  | 1471 | /* return an error on purpose */ | 
|  | 1472 | return -ENODEV; | 
|  | 1473 | } | 
|  | 1474 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1475 | stayinbootmode: | 
|  | 1476 | /* Eprom is invalid or blank stay in boot mode */ | 
| Andrew Morton | 9544e83 | 2008-02-04 23:57:50 -0800 | [diff] [blame] | 1477 | dbg("%s - STAYING IN BOOT MODE", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | serial->product_info.TiMode = TI_MODE_BOOT; | 
|  | 1479 |  | 
|  | 1480 | return 0; | 
|  | 1481 | } | 
|  | 1482 |  | 
|  | 1483 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1484 | static int ti_do_config(struct edgeport_port *port, int feature, int on) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | { | 
|  | 1486 | int port_number = port->port->number - port->port->serial->minor; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1487 | on = !!on;	/* 1 or 0 not bitmask */ | 
|  | 1488 | return send_cmd(port->port->serial->dev, | 
|  | 1489 | feature, (__u8)(UMPM_UART1_PORT + port_number), | 
|  | 1490 | on, NULL, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | } | 
|  | 1492 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1494 | static int restore_mcr(struct edgeport_port *port, __u8 mcr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | { | 
|  | 1496 | int status = 0; | 
|  | 1497 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1498 | dbg("%s - %x", __func__, mcr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1500 | status = ti_do_config(port, UMPC_SET_CLR_DTR, mcr & MCR_DTR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | if (status) | 
|  | 1502 | return status; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1503 | status = ti_do_config(port, UMPC_SET_CLR_RTS, mcr & MCR_RTS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | if (status) | 
|  | 1505 | return status; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1506 | return ti_do_config(port, UMPC_SET_CLR_LOOPBACK, mcr & MCR_LOOPBACK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | } | 
|  | 1508 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | /* Convert TI LSR to standard UART flags */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1510 | static __u8 map_line_status(__u8 ti_lsr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | { | 
|  | 1512 | __u8 lsr = 0; | 
|  | 1513 |  | 
|  | 1514 | #define MAP_FLAG(flagUmp, flagUart)    \ | 
|  | 1515 | if (ti_lsr & flagUmp) \ | 
|  | 1516 | lsr |= flagUart; | 
|  | 1517 |  | 
|  | 1518 | MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR)	/* overrun */ | 
|  | 1519 | MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR)	/* parity error */ | 
|  | 1520 | MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR)	/* framing error */ | 
|  | 1521 | MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK)	/* break detected */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1522 | MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL)	/* rx data available */ | 
|  | 1523 | MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY)	/* tx hold reg empty */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 |  | 
|  | 1525 | #undef MAP_FLAG | 
|  | 1526 |  | 
|  | 1527 | return lsr; | 
|  | 1528 | } | 
|  | 1529 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1530 | static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | { | 
|  | 1532 | struct async_icount *icount; | 
|  | 1533 | struct tty_struct *tty; | 
|  | 1534 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1535 | dbg("%s - %02x", __func__, msr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1537 | if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | | 
|  | 1538 | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | icount = &edge_port->icount; | 
|  | 1540 |  | 
|  | 1541 | /* update input line counters */ | 
|  | 1542 | if (msr & EDGEPORT_MSR_DELTA_CTS) | 
|  | 1543 | icount->cts++; | 
|  | 1544 | if (msr & EDGEPORT_MSR_DELTA_DSR) | 
|  | 1545 | icount->dsr++; | 
|  | 1546 | if (msr & EDGEPORT_MSR_DELTA_CD) | 
|  | 1547 | icount->dcd++; | 
|  | 1548 | if (msr & EDGEPORT_MSR_DELTA_RI) | 
|  | 1549 | icount->rng++; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1550 | wake_up_interruptible(&edge_port->delta_msr_wait); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | } | 
|  | 1552 |  | 
|  | 1553 | /* Save the new modem status */ | 
|  | 1554 | edge_port->shadow_msr = msr & 0xf0; | 
|  | 1555 |  | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1556 | tty = tty_port_tty_get(&edge_port->port->port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | /* handle CTS flow control */ | 
|  | 1558 | if (tty && C_CRTSCTS(tty)) { | 
|  | 1559 | if (msr & EDGEPORT_MSR_CTS) { | 
|  | 1560 | tty->hw_stopped = 0; | 
|  | 1561 | tty_wakeup(tty); | 
|  | 1562 | } else { | 
|  | 1563 | tty->hw_stopped = 1; | 
|  | 1564 | } | 
|  | 1565 | } | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1566 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 |  | 
|  | 1568 | return; | 
|  | 1569 | } | 
|  | 1570 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1571 | static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data, | 
|  | 1572 | __u8 lsr, __u8 data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | { | 
|  | 1574 | struct async_icount *icount; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1575 | __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | | 
|  | 1576 | LSR_FRM_ERR | LSR_BREAK)); | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1577 | struct tty_struct *tty; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1579 | dbg("%s - %02x", __func__, new_lsr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 |  | 
|  | 1581 | edge_port->shadow_lsr = lsr; | 
|  | 1582 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1583 | if (new_lsr & LSR_BREAK) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | /* | 
|  | 1585 | * Parity and Framing errors only count if they | 
|  | 1586 | * occur exclusive of a break being received. | 
|  | 1587 | */ | 
|  | 1588 | new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 |  | 
|  | 1590 | /* Place LSR data byte into Rx buffer */ | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1591 | if (lsr_data) { | 
|  | 1592 | tty = tty_port_tty_get(&edge_port->port->port); | 
|  | 1593 | if (tty) { | 
|  | 1594 | edge_tty_recv(&edge_port->port->dev, tty, &data, 1); | 
|  | 1595 | tty_kref_put(tty); | 
|  | 1596 | } | 
|  | 1597 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 |  | 
|  | 1599 | /* update input line counters */ | 
|  | 1600 | icount = &edge_port->icount; | 
|  | 1601 | if (new_lsr & LSR_BREAK) | 
|  | 1602 | icount->brk++; | 
|  | 1603 | if (new_lsr & LSR_OVER_ERR) | 
|  | 1604 | icount->overrun++; | 
|  | 1605 | if (new_lsr & LSR_PAR_ERR) | 
|  | 1606 | icount->parity++; | 
|  | 1607 | if (new_lsr & LSR_FRM_ERR) | 
|  | 1608 | icount->frame++; | 
|  | 1609 | } | 
|  | 1610 |  | 
|  | 1611 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1612 | static void edge_interrupt_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | { | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1614 | struct edgeport_serial *edge_serial = urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | struct usb_serial_port *port; | 
|  | 1616 | struct edgeport_port *edge_port; | 
|  | 1617 | unsigned char *data = urb->transfer_buffer; | 
|  | 1618 | int length = urb->actual_length; | 
|  | 1619 | int port_number; | 
|  | 1620 | int function; | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1621 | int retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | __u8 lsr; | 
|  | 1623 | __u8 msr; | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1624 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1626 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 |  | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1628 | switch (status) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | case 0: | 
|  | 1630 | /* success */ | 
|  | 1631 | break; | 
|  | 1632 | case -ECONNRESET: | 
|  | 1633 | case -ENOENT: | 
|  | 1634 | case -ESHUTDOWN: | 
|  | 1635 | /* this urb is terminated, clean up */ | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1636 | dbg("%s - urb shutting down with status: %d", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1637 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | return; | 
|  | 1639 | default: | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1640 | dev_err(&urb->dev->dev, "%s - nonzero urb status received: " | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1641 | "%d\n", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | goto exit; | 
|  | 1643 | } | 
|  | 1644 |  | 
|  | 1645 | if (!length) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1646 | dbg("%s - no data in urb", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | goto exit; | 
|  | 1648 | } | 
|  | 1649 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1650 | usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, | 
|  | 1651 | __func__, length, data); | 
|  | 1652 |  | 
|  | 1653 | if (length != 2) { | 
|  | 1654 | dbg("%s - expecting packet of size 2, got %d", | 
|  | 1655 | __func__, length); | 
|  | 1656 | goto exit; | 
|  | 1657 | } | 
|  | 1658 |  | 
|  | 1659 | port_number = TIUMP_GET_PORT_FROM_CODE(data[0]); | 
|  | 1660 | function    = TIUMP_GET_FUNC_FROM_CODE(data[0]); | 
|  | 1661 | dbg("%s - port_number %d, function %d, info 0x%x", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1662 | __func__, port_number, function, data[1]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | port = edge_serial->serial->port[port_number]; | 
|  | 1664 | edge_port = usb_get_serial_port_data(port); | 
|  | 1665 | if (!edge_port) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1666 | dbg("%s - edge_port not found", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | return; | 
|  | 1668 | } | 
|  | 1669 | switch (function) { | 
|  | 1670 | case TIUMP_INTERRUPT_CODE_LSR: | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1671 | lsr = map_line_status(data[1]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | if (lsr & UMP_UART_LSR_DATA_MASK) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1673 | /* Save the LSR event for bulk read | 
|  | 1674 | completion routine */ | 
|  | 1675 | dbg("%s - LSR Event Port %u LSR Status = %02x", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1676 | __func__, port_number, lsr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | edge_port->lsr_event = 1; | 
|  | 1678 | edge_port->lsr_mask = lsr; | 
|  | 1679 | } else { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1680 | dbg("%s - ===== Port %d LSR Status = %02x ======", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1681 | __func__, port_number, lsr); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1682 | handle_new_lsr(edge_port, 0, lsr, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | } | 
|  | 1684 | break; | 
|  | 1685 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1686 | case TIUMP_INTERRUPT_CODE_MSR:	/* MSR */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | /* Copy MSR from UMP */ | 
|  | 1688 | msr = data[1]; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1689 | dbg("%s - ===== Port %u MSR Status = %02x ======\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1690 | __func__, port_number, msr); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1691 | handle_new_msr(edge_port, msr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | break; | 
|  | 1693 |  | 
|  | 1694 | default: | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1695 | dev_err(&urb->dev->dev, | 
|  | 1696 | "%s - Unknown Interrupt code from UMP %x\n", | 
|  | 1697 | __func__, data[1]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | break; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1699 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | } | 
|  | 1701 |  | 
|  | 1702 | exit: | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1703 | retval = usb_submit_urb(urb, GFP_ATOMIC); | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1704 | if (retval) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1705 | dev_err(&urb->dev->dev, | 
|  | 1706 | "%s - usb_submit_urb failed with result %d\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1707 | __func__, retval); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | } | 
|  | 1709 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1710 | static void edge_bulk_in_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | { | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1712 | struct edgeport_port *edge_port = urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | unsigned char *data = urb->transfer_buffer; | 
|  | 1714 | struct tty_struct *tty; | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1715 | int retval = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | int port_number; | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1717 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1719 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 |  | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1721 | switch (status) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | case 0: | 
|  | 1723 | /* success */ | 
|  | 1724 | break; | 
|  | 1725 | case -ECONNRESET: | 
|  | 1726 | case -ENOENT: | 
|  | 1727 | case -ESHUTDOWN: | 
|  | 1728 | /* this urb is terminated, clean up */ | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1729 | dbg("%s - urb shutting down with status: %d", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1730 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | return; | 
|  | 1732 | default: | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1733 | dev_err(&urb->dev->dev, | 
|  | 1734 | "%s - nonzero read bulk status received: %d\n", | 
|  | 1735 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } | 
|  | 1737 |  | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1738 | if (status == -EPIPE) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | goto exit; | 
|  | 1740 |  | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1741 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1742 | dev_err(&urb->dev->dev, "%s - stopping read!\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | return; | 
|  | 1744 | } | 
|  | 1745 |  | 
|  | 1746 | port_number = edge_port->port->number - edge_port->port->serial->minor; | 
|  | 1747 |  | 
|  | 1748 | if (edge_port->lsr_event) { | 
|  | 1749 | edge_port->lsr_event = 0; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1750 | dbg("%s ===== Port %u LSR Status = %02x, Data = %02x ======", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1751 | __func__, port_number, edge_port->lsr_mask, *data); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1752 | handle_new_lsr(edge_port, 1, edge_port->lsr_mask, *data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | /* Adjust buffer length/pointer */ | 
|  | 1754 | --urb->actual_length; | 
|  | 1755 | ++data; | 
|  | 1756 | } | 
|  | 1757 |  | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1758 | tty = tty_port_tty_get(&edge_port->port->port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | if (tty && urb->actual_length) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1760 | usb_serial_debug_data(debug, &edge_port->port->dev, | 
|  | 1761 | __func__, urb->actual_length, data); | 
|  | 1762 | if (edge_port->close_pending) | 
|  | 1763 | dbg("%s - close pending, dropping data on the floor", | 
|  | 1764 | __func__); | 
|  | 1765 | else | 
|  | 1766 | edge_tty_recv(&edge_port->port->dev, tty, data, | 
|  | 1767 | urb->actual_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | edge_port->icount.rx += urb->actual_length; | 
|  | 1769 | } | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1770 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 |  | 
|  | 1772 | exit: | 
|  | 1773 | /* continue read unless stopped */ | 
|  | 1774 | spin_lock(&edge_port->ep_lock); | 
|  | 1775 | if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING) { | 
|  | 1776 | urb->dev = edge_port->port->serial->dev; | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1777 | retval = usb_submit_urb(urb, GFP_ATOMIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | } else if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPING) { | 
|  | 1779 | edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPED; | 
|  | 1780 | } | 
|  | 1781 | spin_unlock(&edge_port->ep_lock); | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1782 | if (retval) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1783 | dev_err(&urb->dev->dev, | 
|  | 1784 | "%s - usb_submit_urb failed with result %d\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1785 | __func__, retval); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | } | 
|  | 1787 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1788 | static void edge_tty_recv(struct device *dev, struct tty_struct *tty, | 
|  | 1789 | unsigned char *data, int length) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1791 | int queued; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1793 | tty_buffer_request_room(tty, length); | 
|  | 1794 | queued = tty_insert_flip_string(tty, data, length); | 
|  | 1795 | if (queued < length) | 
|  | 1796 | dev_err(dev, "%s - dropping data, %d bytes lost\n", | 
|  | 1797 | __func__, length - queued); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | tty_flip_buffer_push(tty); | 
|  | 1799 | } | 
|  | 1800 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1801 | static void edge_bulk_out_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | { | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1803 | struct usb_serial_port *port = urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1805 | int status = urb->status; | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1806 | struct tty_struct *tty; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1808 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 |  | 
|  | 1810 | edge_port->ep_write_urb_in_use = 0; | 
|  | 1811 |  | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1812 | switch (status) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | case 0: | 
|  | 1814 | /* success */ | 
|  | 1815 | break; | 
|  | 1816 | case -ECONNRESET: | 
|  | 1817 | case -ENOENT: | 
|  | 1818 | case -ESHUTDOWN: | 
|  | 1819 | /* this urb is terminated, clean up */ | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1820 | dbg("%s - urb shutting down with status: %d", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1821 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | return; | 
|  | 1823 | default: | 
| Greg Kroah-Hartman | ee337c2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1824 | dev_err(&urb->dev->dev, "%s - nonzero write bulk status " | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1825 | "received: %d\n", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | } | 
|  | 1827 |  | 
|  | 1828 | /* send any buffered data */ | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1829 | tty = tty_port_tty_get(&port->port); | 
|  | 1830 | edge_send(tty); | 
|  | 1831 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | } | 
|  | 1833 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1834 | static int edge_open(struct tty_struct *tty, | 
|  | 1835 | struct usb_serial_port *port, struct file *filp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | { | 
|  | 1837 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 1838 | struct edgeport_serial *edge_serial; | 
|  | 1839 | struct usb_device *dev; | 
|  | 1840 | struct urb *urb; | 
|  | 1841 | int port_number; | 
|  | 1842 | int status; | 
|  | 1843 | u16 open_settings; | 
|  | 1844 | u8 transaction_timeout; | 
|  | 1845 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1846 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 |  | 
|  | 1848 | if (edge_port == NULL) | 
|  | 1849 | return -ENODEV; | 
|  | 1850 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | port_number = port->number - port->serial->minor; | 
|  | 1852 | switch (port_number) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1853 | case 0: | 
|  | 1854 | edge_port->uart_base = UMPMEM_BASE_UART1; | 
|  | 1855 | edge_port->dma_address = UMPD_OEDB1_ADDRESS; | 
|  | 1856 | break; | 
|  | 1857 | case 1: | 
|  | 1858 | edge_port->uart_base = UMPMEM_BASE_UART2; | 
|  | 1859 | edge_port->dma_address = UMPD_OEDB2_ADDRESS; | 
|  | 1860 | break; | 
|  | 1861 | default: | 
|  | 1862 | dev_err(&port->dev, "Unknown port number!!!\n"); | 
|  | 1863 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | } | 
|  | 1865 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1866 | dbg("%s - port_number = %d, uart_base = %04x, dma_address = %04x", | 
|  | 1867 | __func__, port_number, edge_port->uart_base, | 
|  | 1868 | edge_port->dma_address); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 |  | 
|  | 1870 | dev = port->serial->dev; | 
|  | 1871 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1872 | memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount)); | 
|  | 1873 | init_waitqueue_head(&edge_port->delta_msr_wait); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 |  | 
|  | 1875 | /* turn off loopback */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1876 | status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1878 | dev_err(&port->dev, | 
|  | 1879 | "%s - cannot send clear loopback command, %d\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1880 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | return status; | 
|  | 1882 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1883 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | /* set up the port settings */ | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1885 | if (tty) | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1886 | edge_set_termios(tty, port, tty->termios); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 |  | 
|  | 1888 | /* open up the port */ | 
|  | 1889 |  | 
|  | 1890 | /* milliseconds to timeout for DMA transfer */ | 
|  | 1891 | transaction_timeout = 2; | 
|  | 1892 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1893 | edge_port->ump_read_timeout = | 
|  | 1894 | max(20, ((transaction_timeout * 3) / 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1896 | /* milliseconds to timeout for DMA transfer */ | 
|  | 1897 | open_settings = (u8)(UMP_DMA_MODE_CONTINOUS | | 
|  | 1898 | UMP_PIPE_TRANS_TIMEOUT_ENA | | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | (transaction_timeout << 2)); | 
|  | 1900 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1901 | dbg("%s - Sending UMPC_OPEN_PORT", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 |  | 
|  | 1903 | /* Tell TI to open and start the port */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1904 | status = send_cmd(dev, UMPC_OPEN_PORT, | 
|  | 1905 | (u8)(UMPM_UART1_PORT + port_number), open_settings, NULL, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1907 | dev_err(&port->dev, "%s - cannot send open command, %d\n", | 
|  | 1908 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | return status; | 
|  | 1910 | } | 
|  | 1911 |  | 
|  | 1912 | /* Start the DMA? */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1913 | status = send_cmd(dev, UMPC_START_PORT, | 
|  | 1914 | (u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1916 | dev_err(&port->dev, "%s - cannot send start DMA command, %d\n", | 
|  | 1917 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | return status; | 
|  | 1919 | } | 
|  | 1920 |  | 
|  | 1921 | /* Clear TX and RX buffers in UMP */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1922 | status = purge_port(port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1924 | dev_err(&port->dev, | 
|  | 1925 | "%s - cannot send clear buffers command, %d\n", | 
|  | 1926 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | return status; | 
|  | 1928 | } | 
|  | 1929 |  | 
|  | 1930 | /* Read Initial MSR */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1931 | status = ti_vread_sync(dev, UMPC_READ_MSR, 0, | 
|  | 1932 | (__u16)(UMPM_UART1_PORT + port_number), | 
|  | 1933 | &edge_port->shadow_msr, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1935 | dev_err(&port->dev, "%s - cannot send read MSR command, %d\n", | 
|  | 1936 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | return status; | 
|  | 1938 | } | 
|  | 1939 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1940 | dbg("ShadowMSR 0x%X", edge_port->shadow_msr); | 
|  | 1941 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | /* Set Initial MCR */ | 
|  | 1943 | edge_port->shadow_mcr = MCR_RTS | MCR_DTR; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1944 | dbg("ShadowMCR 0x%X", edge_port->shadow_mcr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 |  | 
|  | 1946 | edge_serial = edge_port->edge_serial; | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 1947 | if (mutex_lock_interruptible(&edge_serial->es_lock)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | return -ERESTARTSYS; | 
|  | 1949 | if (edge_serial->num_ports_open == 0) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1950 | /* we are the first port to open, post the interrupt urb */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | urb = edge_serial->serial->port[0]->interrupt_in_urb; | 
|  | 1952 | if (!urb) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1953 | dev_err(&port->dev, | 
|  | 1954 | "%s - no interrupt urb present, exiting\n", | 
|  | 1955 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | status = -EINVAL; | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 1957 | goto release_es_lock; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | } | 
|  | 1959 | urb->complete = edge_interrupt_callback; | 
|  | 1960 | urb->context = edge_serial; | 
|  | 1961 | urb->dev = dev; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1962 | status = usb_submit_urb(urb, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1964 | dev_err(&port->dev, | 
|  | 1965 | "%s - usb_submit_urb failed with value %d\n", | 
|  | 1966 | __func__, status); | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 1967 | goto release_es_lock; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | } | 
|  | 1969 | } | 
|  | 1970 |  | 
|  | 1971 | /* | 
|  | 1972 | * reset the data toggle on the bulk endpoints to work around bug in | 
|  | 1973 | * host controllers where things get out of sync some times | 
|  | 1974 | */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1975 | usb_clear_halt(dev, port->write_urb->pipe); | 
|  | 1976 | usb_clear_halt(dev, port->read_urb->pipe); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 |  | 
|  | 1978 | /* start up our bulk read urb */ | 
|  | 1979 | urb = port->read_urb; | 
|  | 1980 | if (!urb) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1981 | dev_err(&port->dev, "%s - no read urb present, exiting\n", | 
|  | 1982 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | status = -EINVAL; | 
|  | 1984 | goto unlink_int_urb; | 
|  | 1985 | } | 
|  | 1986 | edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING; | 
|  | 1987 | urb->complete = edge_bulk_in_callback; | 
|  | 1988 | urb->context = edge_port; | 
|  | 1989 | urb->dev = dev; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1990 | status = usb_submit_urb(urb, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 1992 | dev_err(&port->dev, | 
|  | 1993 | "%s - read bulk usb_submit_urb failed with value %d\n", | 
|  | 1994 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | goto unlink_int_urb; | 
|  | 1996 | } | 
|  | 1997 |  | 
|  | 1998 | ++edge_serial->num_ports_open; | 
|  | 1999 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2000 | dbg("%s - exited", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 |  | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 2002 | goto release_es_lock; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 |  | 
|  | 2004 | unlink_int_urb: | 
|  | 2005 | if (edge_port->edge_serial->num_ports_open == 0) | 
|  | 2006 | usb_kill_urb(port->serial->port[0]->interrupt_in_urb); | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 2007 | release_es_lock: | 
|  | 2008 | mutex_unlock(&edge_serial->es_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | return status; | 
|  | 2010 | } | 
|  | 2011 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2012 | static void edge_close(struct tty_struct *tty, | 
|  | 2013 | struct usb_serial_port *port, struct file *filp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | { | 
|  | 2015 | struct edgeport_serial *edge_serial; | 
|  | 2016 | struct edgeport_port *edge_port; | 
|  | 2017 | int port_number; | 
|  | 2018 | int status; | 
|  | 2019 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2020 | dbg("%s - port %d", __func__, port->number); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2021 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | edge_serial = usb_get_serial_data(port->serial); | 
|  | 2023 | edge_port = usb_get_serial_port_data(port); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2024 | if (edge_serial == NULL || edge_port == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | return; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2026 |  | 
|  | 2027 | /* The bulkreadcompletion routine will check | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | * this flag and dump add read data */ | 
|  | 2029 | edge_port->close_pending = 1; | 
|  | 2030 |  | 
|  | 2031 | /* chase the port close and flush */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2032 | chase_port(edge_port, (HZ * closing_wait) / 100, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 |  | 
|  | 2034 | usb_kill_urb(port->read_urb); | 
|  | 2035 | usb_kill_urb(port->write_urb); | 
|  | 2036 | edge_port->ep_write_urb_in_use = 0; | 
|  | 2037 |  | 
|  | 2038 | /* assuming we can still talk to the device, | 
|  | 2039 | * send a close port command to it */ | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2040 | dbg("%s - send umpc_close_port", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | port_number = port->number - port->serial->minor; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2042 | status = send_cmd(port->serial->dev, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | UMPC_CLOSE_PORT, | 
|  | 2044 | (__u8)(UMPM_UART1_PORT + port_number), | 
|  | 2045 | 0, | 
|  | 2046 | NULL, | 
|  | 2047 | 0); | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 2048 | mutex_lock(&edge_serial->es_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | --edge_port->edge_serial->num_ports_open; | 
|  | 2050 | if (edge_port->edge_serial->num_ports_open <= 0) { | 
|  | 2051 | /* last port is now closed, let's shut down our interrupt urb */ | 
|  | 2052 | usb_kill_urb(port->serial->port[0]->interrupt_in_urb); | 
|  | 2053 | edge_port->edge_serial->num_ports_open = 0; | 
|  | 2054 | } | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 2055 | mutex_unlock(&edge_serial->es_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | edge_port->close_pending = 0; | 
|  | 2057 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2058 | dbg("%s - exited", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | } | 
|  | 2060 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2061 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, | 
|  | 2062 | const unsigned char *data, int count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | { | 
|  | 2064 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 2065 | unsigned long flags; | 
|  | 2066 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2067 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 |  | 
|  | 2069 | if (count == 0) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2070 | dbg("%s - write request of 0 bytes", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | return 0; | 
|  | 2072 | } | 
|  | 2073 |  | 
|  | 2074 | if (edge_port == NULL) | 
|  | 2075 | return -ENODEV; | 
|  | 2076 | if (edge_port->close_pending == 1) | 
|  | 2077 | return -ENODEV; | 
|  | 2078 |  | 
|  | 2079 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 
|  | 2080 | count = edge_buf_put(edge_port->ep_out_buf, data, count); | 
|  | 2081 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
|  | 2082 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2083 | edge_send(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 |  | 
|  | 2085 | return count; | 
|  | 2086 | } | 
|  | 2087 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2088 | static void edge_send(struct tty_struct *tty) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2090 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | int count, result; | 
|  | 2092 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | unsigned long flags; | 
|  | 2094 |  | 
|  | 2095 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2096 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 |  | 
|  | 2098 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 
|  | 2099 |  | 
|  | 2100 | if (edge_port->ep_write_urb_in_use) { | 
|  | 2101 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
|  | 2102 | return; | 
|  | 2103 | } | 
|  | 2104 |  | 
|  | 2105 | count = edge_buf_get(edge_port->ep_out_buf, | 
|  | 2106 | port->write_urb->transfer_buffer, | 
|  | 2107 | port->bulk_out_size); | 
|  | 2108 |  | 
|  | 2109 | if (count == 0) { | 
|  | 2110 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
|  | 2111 | return; | 
|  | 2112 | } | 
|  | 2113 |  | 
|  | 2114 | edge_port->ep_write_urb_in_use = 1; | 
|  | 2115 |  | 
|  | 2116 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
|  | 2117 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2118 | usb_serial_debug_data(debug, &port->dev, __func__, count, | 
|  | 2119 | port->write_urb->transfer_buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 |  | 
|  | 2121 | /* set up our urb */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2122 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | 
|  | 2123 | usb_sndbulkpipe(port->serial->dev, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | port->bulk_out_endpointAddress), | 
|  | 2125 | port->write_urb->transfer_buffer, count, | 
|  | 2126 | edge_bulk_out_callback, | 
|  | 2127 | port); | 
|  | 2128 |  | 
|  | 2129 | /* send the data out the bulk port */ | 
|  | 2130 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | 
|  | 2131 | if (result) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2132 | dev_err(&port->dev, | 
|  | 2133 | "%s - failed submitting write urb, error %d\n", | 
|  | 2134 | __func__, result); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | edge_port->ep_write_urb_in_use = 0; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2136 | /* TODO: reschedule edge_send */ | 
|  | 2137 | } else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | edge_port->icount.tx += count; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 |  | 
|  | 2140 | /* wakeup any process waiting for writes to complete */ | 
|  | 2141 | /* there is now more room in the buffer for new writes */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2142 | if (tty) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | tty_wakeup(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | } | 
|  | 2145 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2146 | static int edge_write_room(struct tty_struct *tty) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2148 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 2150 | int room = 0; | 
|  | 2151 | unsigned long flags; | 
|  | 2152 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2153 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 |  | 
|  | 2155 | if (edge_port == NULL) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2156 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | if (edge_port->close_pending == 1) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2158 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 |  | 
|  | 2160 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 
|  | 2161 | room = edge_buf_space_avail(edge_port->ep_out_buf); | 
|  | 2162 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
|  | 2163 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2164 | dbg("%s - returns %d", __func__, room); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | return room; | 
|  | 2166 | } | 
|  | 2167 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2168 | static int edge_chars_in_buffer(struct tty_struct *tty) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2170 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 2172 | int chars = 0; | 
|  | 2173 | unsigned long flags; | 
|  | 2174 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2175 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 |  | 
|  | 2177 | if (edge_port == NULL) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2178 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | if (edge_port->close_pending == 1) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2180 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 |  | 
|  | 2182 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 
|  | 2183 | chars = edge_buf_data_avail(edge_port->ep_out_buf); | 
|  | 2184 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
|  | 2185 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2186 | dbg("%s - returns %d", __func__, chars); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | return chars; | 
|  | 2188 | } | 
|  | 2189 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2190 | static void edge_throttle(struct tty_struct *tty) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2192 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | int status; | 
|  | 2195 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2196 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 |  | 
|  | 2198 | if (edge_port == NULL) | 
|  | 2199 | return; | 
|  | 2200 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | /* if we are implementing XON/XOFF, send the stop character */ | 
|  | 2202 | if (I_IXOFF(tty)) { | 
|  | 2203 | unsigned char stop_char = STOP_CHAR(tty); | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2204 | status = edge_write(tty, port, &stop_char, 1); | 
|  | 2205 | if (status <= 0) { | 
|  | 2206 | dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status); | 
|  | 2207 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | } | 
|  | 2209 |  | 
|  | 2210 | /* if we are implementing RTS/CTS, stop reads */ | 
|  | 2211 | /* and the Edgeport will clear the RTS line */ | 
|  | 2212 | if (C_CRTSCTS(tty)) | 
|  | 2213 | stop_read(edge_port); | 
|  | 2214 |  | 
|  | 2215 | } | 
|  | 2216 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2217 | static void edge_unthrottle(struct tty_struct *tty) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2219 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | int status; | 
|  | 2222 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2223 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 |  | 
|  | 2225 | if (edge_port == NULL) | 
|  | 2226 | return; | 
|  | 2227 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | /* if we are implementing XON/XOFF, send the start character */ | 
|  | 2229 | if (I_IXOFF(tty)) { | 
|  | 2230 | unsigned char start_char = START_CHAR(tty); | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2231 | status = edge_write(tty, port, &start_char, 1); | 
|  | 2232 | if (status <= 0) { | 
|  | 2233 | dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status); | 
|  | 2234 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | /* if we are implementing RTS/CTS, restart reads */ | 
|  | 2237 | /* are the Edgeport will assert the RTS line */ | 
|  | 2238 | if (C_CRTSCTS(tty)) { | 
|  | 2239 | status = restart_read(edge_port); | 
|  | 2240 | if (status) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2241 | dev_err(&port->dev, | 
|  | 2242 | "%s - read bulk usb_submit_urb failed: %d\n", | 
|  | 2243 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | } | 
|  | 2245 |  | 
|  | 2246 | } | 
|  | 2247 |  | 
|  | 2248 | static void stop_read(struct edgeport_port *edge_port) | 
|  | 2249 | { | 
|  | 2250 | unsigned long flags; | 
|  | 2251 |  | 
|  | 2252 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 
|  | 2253 |  | 
|  | 2254 | if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING) | 
|  | 2255 | edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPING; | 
|  | 2256 | edge_port->shadow_mcr &= ~MCR_RTS; | 
|  | 2257 |  | 
|  | 2258 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
|  | 2259 | } | 
|  | 2260 |  | 
|  | 2261 | static int restart_read(struct edgeport_port *edge_port) | 
|  | 2262 | { | 
|  | 2263 | struct urb *urb; | 
|  | 2264 | int status = 0; | 
|  | 2265 | unsigned long flags; | 
|  | 2266 |  | 
|  | 2267 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 
|  | 2268 |  | 
|  | 2269 | if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPED) { | 
|  | 2270 | urb = edge_port->port->read_urb; | 
|  | 2271 | urb->complete = edge_bulk_in_callback; | 
|  | 2272 | urb->context = edge_port; | 
|  | 2273 | urb->dev = edge_port->port->serial->dev; | 
| Oliver Neukum | efdff60 | 2007-06-05 10:50:48 +0200 | [diff] [blame] | 2274 | status = usb_submit_urb(urb, GFP_ATOMIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | } | 
|  | 2276 | edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING; | 
|  | 2277 | edge_port->shadow_mcr |= MCR_RTS; | 
|  | 2278 |  | 
|  | 2279 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
|  | 2280 |  | 
|  | 2281 | return status; | 
|  | 2282 | } | 
|  | 2283 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2284 | static void change_port_settings(struct tty_struct *tty, | 
|  | 2285 | struct edgeport_port *edge_port, struct ktermios *old_termios) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | { | 
|  | 2287 | struct ump_uart_config *config; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | int baud; | 
|  | 2289 | unsigned cflag; | 
|  | 2290 | int status; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2291 | int port_number = edge_port->port->number - | 
|  | 2292 | edge_port->port->serial->minor; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2294 | dbg("%s - port %d", __func__, edge_port->port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2296 | config = kmalloc (sizeof (*config), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | if (!config) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2298 | *tty->termios = *old_termios; | 
|  | 2299 | dev_err(&edge_port->port->dev, "%s - out of memory\n", | 
|  | 2300 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | return; | 
|  | 2302 | } | 
|  | 2303 |  | 
|  | 2304 | cflag = tty->termios->c_cflag; | 
|  | 2305 |  | 
|  | 2306 | config->wFlags = 0; | 
|  | 2307 |  | 
|  | 2308 | /* These flags must be set */ | 
|  | 2309 | config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT; | 
|  | 2310 | config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR; | 
|  | 2311 | config->bUartMode = (__u8)(edge_port->bUartMode); | 
|  | 2312 |  | 
|  | 2313 | switch (cflag & CSIZE) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2314 | case CS5: | 
|  | 2315 | config->bDataBits = UMP_UART_CHAR5BITS; | 
|  | 2316 | dbg("%s - data bits = 5", __func__); | 
|  | 2317 | break; | 
|  | 2318 | case CS6: | 
|  | 2319 | config->bDataBits = UMP_UART_CHAR6BITS; | 
|  | 2320 | dbg("%s - data bits = 6", __func__); | 
|  | 2321 | break; | 
|  | 2322 | case CS7: | 
|  | 2323 | config->bDataBits = UMP_UART_CHAR7BITS; | 
|  | 2324 | dbg("%s - data bits = 7", __func__); | 
|  | 2325 | break; | 
|  | 2326 | default: | 
|  | 2327 | case CS8: | 
|  | 2328 | config->bDataBits = UMP_UART_CHAR8BITS; | 
|  | 2329 | dbg("%s - data bits = 8", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | break; | 
|  | 2331 | } | 
|  | 2332 |  | 
|  | 2333 | if (cflag & PARENB) { | 
|  | 2334 | if (cflag & PARODD) { | 
|  | 2335 | config->wFlags |= UMP_MASK_UART_FLAGS_PARITY; | 
|  | 2336 | config->bParity = UMP_UART_ODDPARITY; | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2337 | dbg("%s - parity = odd", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | } else { | 
|  | 2339 | config->wFlags |= UMP_MASK_UART_FLAGS_PARITY; | 
|  | 2340 | config->bParity = UMP_UART_EVENPARITY; | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2341 | dbg("%s - parity = even", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | } | 
|  | 2343 | } else { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2344 | config->bParity = UMP_UART_NOPARITY; | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2345 | dbg("%s - parity = none", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | } | 
|  | 2347 |  | 
|  | 2348 | if (cflag & CSTOPB) { | 
|  | 2349 | config->bStopBits = UMP_UART_STOPBIT2; | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2350 | dbg("%s - stop bits = 2", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | } else { | 
|  | 2352 | config->bStopBits = UMP_UART_STOPBIT1; | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2353 | dbg("%s - stop bits = 1", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | } | 
|  | 2355 |  | 
|  | 2356 | /* figure out the flow control settings */ | 
|  | 2357 | if (cflag & CRTSCTS) { | 
|  | 2358 | config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW; | 
|  | 2359 | config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW; | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2360 | dbg("%s - RTS/CTS is enabled", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | } else { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2362 | dbg("%s - RTS/CTS is disabled", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | tty->hw_stopped = 0; | 
|  | 2364 | restart_read(edge_port); | 
|  | 2365 | } | 
|  | 2366 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2367 | /* if we are implementing XON/XOFF, set the start and stop | 
|  | 2368 | character in the device */ | 
|  | 2369 | config->cXon  = START_CHAR(tty); | 
|  | 2370 | config->cXoff = STOP_CHAR(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2372 | /* if we are implementing INBOUND XON/XOFF */ | 
|  | 2373 | if (I_IXOFF(tty)) { | 
|  | 2374 | config->wFlags |= UMP_MASK_UART_FLAGS_IN_X; | 
|  | 2375 | dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", | 
|  | 2376 | __func__, config->cXon, config->cXoff); | 
|  | 2377 | } else | 
|  | 2378 | dbg("%s - INBOUND XON/XOFF is disabled", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2380 | /* if we are implementing OUTBOUND XON/XOFF */ | 
|  | 2381 | if (I_IXON(tty)) { | 
|  | 2382 | config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X; | 
|  | 2383 | dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", | 
|  | 2384 | __func__, config->cXon, config->cXoff); | 
|  | 2385 | } else | 
|  | 2386 | dbg("%s - OUTBOUND XON/XOFF is disabled", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 |  | 
| Alan Cox | d5f5bcd | 2008-01-03 16:57:33 +0000 | [diff] [blame] | 2388 | tty->termios->c_cflag &= ~CMSPAR; | 
|  | 2389 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | /* Round the baud rate */ | 
|  | 2391 | baud = tty_get_baud_rate(tty); | 
|  | 2392 | if (!baud) { | 
|  | 2393 | /* pick a default, any default... */ | 
|  | 2394 | baud = 9600; | 
| Alan Cox | d5f5bcd | 2008-01-03 16:57:33 +0000 | [diff] [blame] | 2395 | } else | 
|  | 2396 | tty_encode_baud_rate(tty, baud, baud); | 
|  | 2397 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | edge_port->baud_rate = baud; | 
|  | 2399 | config->wBaudRate = (__u16)((461550L + baud/2) / baud); | 
|  | 2400 |  | 
| Alan Cox | d5f5bcd | 2008-01-03 16:57:33 +0000 | [diff] [blame] | 2401 | /* FIXME: Recompute actual baud from divisor here */ | 
|  | 2402 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2403 | dbg("%s - baud rate = %d, wBaudRate = %d", __func__, baud, | 
|  | 2404 | config->wBaudRate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2406 | dbg("wBaudRate:   %d", (int)(461550L / config->wBaudRate)); | 
|  | 2407 | dbg("wFlags:    0x%x", config->wFlags); | 
|  | 2408 | dbg("bDataBits:   %d", config->bDataBits); | 
|  | 2409 | dbg("bParity:     %d", config->bParity); | 
|  | 2410 | dbg("bStopBits:   %d", config->bStopBits); | 
|  | 2411 | dbg("cXon:        %d", config->cXon); | 
|  | 2412 | dbg("cXoff:       %d", config->cXoff); | 
|  | 2413 | dbg("bUartMode:   %d", config->bUartMode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 |  | 
|  | 2415 | /* move the word values into big endian mode */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2416 | cpu_to_be16s(&config->wFlags); | 
|  | 2417 | cpu_to_be16s(&config->wBaudRate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2419 | status = send_cmd(edge_port->port->serial->dev, UMPC_SET_CONFIG, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | (__u8)(UMPM_UART1_PORT + port_number), | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2421 | 0, (__u8 *)config, sizeof(*config)); | 
|  | 2422 | if (status) | 
|  | 2423 | dbg("%s - error %d when trying to write config to device", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2424 | __func__, status); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2425 | kfree(config); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | return; | 
|  | 2427 | } | 
|  | 2428 |  | 
| Alan Cox | 2e0ddd6 | 2008-07-22 11:12:33 +0100 | [diff] [blame] | 2429 | static void edge_set_termios(struct tty_struct *tty, | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2430 | struct usb_serial_port *port, struct ktermios *old_termios) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | { | 
|  | 2432 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2433 | unsigned int cflag; | 
|  | 2434 |  | 
|  | 2435 | cflag = tty->termios->c_cflag; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2437 | dbg("%s - clfag %08x iflag %08x", __func__, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | tty->termios->c_cflag, tty->termios->c_iflag); | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2439 | dbg("%s - old clfag %08x old iflag %08x", __func__, | 
| Alan Cox | d5f5bcd | 2008-01-03 16:57:33 +0000 | [diff] [blame] | 2440 | old_termios->c_cflag, old_termios->c_iflag); | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2441 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 |  | 
|  | 2443 | if (edge_port == NULL) | 
|  | 2444 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | /* change the port settings to the new ones specified */ | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2446 | change_port_settings(tty, edge_port, old_termios); | 
|  | 2447 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | } | 
|  | 2449 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2450 | static int edge_tiocmset(struct tty_struct *tty, struct file *file, | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2451 | unsigned int set, unsigned int clear) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2453 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 2455 | unsigned int mcr; | 
| Alan Cox | 3d71fe0 | 2008-02-20 21:38:32 +0000 | [diff] [blame] | 2456 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2458 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 |  | 
| Alan Cox | 3d71fe0 | 2008-02-20 21:38:32 +0000 | [diff] [blame] | 2460 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | mcr = edge_port->shadow_mcr; | 
|  | 2462 | if (set & TIOCM_RTS) | 
|  | 2463 | mcr |= MCR_RTS; | 
|  | 2464 | if (set & TIOCM_DTR) | 
|  | 2465 | mcr |= MCR_DTR; | 
|  | 2466 | if (set & TIOCM_LOOP) | 
|  | 2467 | mcr |= MCR_LOOPBACK; | 
|  | 2468 |  | 
|  | 2469 | if (clear & TIOCM_RTS) | 
|  | 2470 | mcr &= ~MCR_RTS; | 
|  | 2471 | if (clear & TIOCM_DTR) | 
|  | 2472 | mcr &= ~MCR_DTR; | 
|  | 2473 | if (clear & TIOCM_LOOP) | 
|  | 2474 | mcr &= ~MCR_LOOPBACK; | 
|  | 2475 |  | 
|  | 2476 | edge_port->shadow_mcr = mcr; | 
| Alan Cox | 3d71fe0 | 2008-02-20 21:38:32 +0000 | [diff] [blame] | 2477 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2479 | restore_mcr(edge_port, mcr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | return 0; | 
|  | 2481 | } | 
|  | 2482 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2483 | static int edge_tiocmget(struct tty_struct *tty, struct file *file) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2485 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 2487 | unsigned int result = 0; | 
|  | 2488 | unsigned int msr; | 
|  | 2489 | unsigned int mcr; | 
| Alan Cox | 3d71fe0 | 2008-02-20 21:38:32 +0000 | [diff] [blame] | 2490 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2492 | dbg("%s - port %d", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 |  | 
| Alan Cox | 3d71fe0 | 2008-02-20 21:38:32 +0000 | [diff] [blame] | 2494 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 
|  | 2495 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | msr = edge_port->shadow_msr; | 
|  | 2497 | mcr = edge_port->shadow_mcr; | 
|  | 2498 | result = ((mcr & MCR_DTR)	? TIOCM_DTR: 0)	  /* 0x002 */ | 
|  | 2499 | | ((mcr & MCR_RTS)	? TIOCM_RTS: 0)   /* 0x004 */ | 
|  | 2500 | | ((msr & EDGEPORT_MSR_CTS)	? TIOCM_CTS: 0)   /* 0x020 */ | 
|  | 2501 | | ((msr & EDGEPORT_MSR_CD)	? TIOCM_CAR: 0)   /* 0x040 */ | 
|  | 2502 | | ((msr & EDGEPORT_MSR_RI)	? TIOCM_RI:  0)   /* 0x080 */ | 
|  | 2503 | | ((msr & EDGEPORT_MSR_DSR)	? TIOCM_DSR: 0);  /* 0x100 */ | 
|  | 2504 |  | 
|  | 2505 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2506 | dbg("%s -- %x", __func__, result); | 
| Alan Cox | 3d71fe0 | 2008-02-20 21:38:32 +0000 | [diff] [blame] | 2507 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 |  | 
|  | 2509 | return result; | 
|  | 2510 | } | 
|  | 2511 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2512 | static int get_serial_info(struct edgeport_port *edge_port, | 
|  | 2513 | struct serial_struct __user *retinfo) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | { | 
|  | 2515 | struct serial_struct tmp; | 
|  | 2516 |  | 
|  | 2517 | if (!retinfo) | 
|  | 2518 | return -EFAULT; | 
|  | 2519 |  | 
|  | 2520 | memset(&tmp, 0, sizeof(tmp)); | 
|  | 2521 |  | 
|  | 2522 | tmp.type		= PORT_16550A; | 
|  | 2523 | tmp.line		= edge_port->port->serial->minor; | 
|  | 2524 | tmp.port		= edge_port->port->number; | 
|  | 2525 | tmp.irq			= 0; | 
|  | 2526 | tmp.flags		= ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; | 
|  | 2527 | tmp.xmit_fifo_size	= edge_port->port->bulk_out_size; | 
|  | 2528 | tmp.baud_base		= 9600; | 
|  | 2529 | tmp.close_delay		= 5*HZ; | 
|  | 2530 | tmp.closing_wait	= closing_wait; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 |  | 
|  | 2532 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) | 
|  | 2533 | return -EFAULT; | 
|  | 2534 | return 0; | 
|  | 2535 | } | 
|  | 2536 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2537 | static int edge_ioctl(struct tty_struct *tty, struct file *file, | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2538 | unsigned int cmd, unsigned long arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2540 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 2542 | struct async_icount cnow; | 
|  | 2543 | struct async_icount cprev; | 
|  | 2544 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2545 | dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 |  | 
|  | 2547 | switch (cmd) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2548 | case TIOCGSERIAL: | 
|  | 2549 | dbg("%s - (%d) TIOCGSERIAL", __func__, port->number); | 
|  | 2550 | return get_serial_info(edge_port, | 
|  | 2551 | (struct serial_struct __user *) arg); | 
|  | 2552 | case TIOCMIWAIT: | 
|  | 2553 | dbg("%s - (%d) TIOCMIWAIT", __func__, port->number); | 
|  | 2554 | cprev = edge_port->icount; | 
|  | 2555 | while (1) { | 
|  | 2556 | interruptible_sleep_on(&edge_port->delta_msr_wait); | 
|  | 2557 | /* see if a signal did it */ | 
|  | 2558 | if (signal_pending(current)) | 
|  | 2559 | return -ERESTARTSYS; | 
|  | 2560 | cnow = edge_port->icount; | 
|  | 2561 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && | 
|  | 2562 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) | 
|  | 2563 | return -EIO; /* no change => error */ | 
|  | 2564 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || | 
|  | 2565 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || | 
|  | 2566 | ((arg & TIOCM_CD)  && (cnow.dcd != cprev.dcd)) || | 
|  | 2567 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { | 
|  | 2568 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2570 | cprev = cnow; | 
|  | 2571 | } | 
|  | 2572 | /* not reached */ | 
|  | 2573 | break; | 
|  | 2574 | case TIOCGICOUNT: | 
|  | 2575 | dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, | 
|  | 2576 | port->number, edge_port->icount.rx, edge_port->icount.tx); | 
|  | 2577 | if (copy_to_user((void __user *)arg, &edge_port->icount, | 
|  | 2578 | sizeof(edge_port->icount))) | 
|  | 2579 | return -EFAULT; | 
|  | 2580 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | return -ENOIOCTLCMD; | 
|  | 2583 | } | 
|  | 2584 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2585 | static void edge_break(struct tty_struct *tty, int break_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2587 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 2589 | int status; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2590 | int bv = 0;	/* Off */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2592 | dbg("%s - state = %d", __func__, break_state); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 |  | 
|  | 2594 | /* chase the port close */ | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2595 | chase_port(edge_port, 0, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2597 | if (break_state == -1) | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2598 | bv = 1;	/* On */ | 
|  | 2599 | status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv); | 
|  | 2600 | if (status) | 
|  | 2601 | dbg("%s - error %d sending break set/clear command.", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2602 | __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | } | 
|  | 2604 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2605 | static int edge_startup(struct usb_serial *serial) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | { | 
|  | 2607 | struct edgeport_serial *edge_serial; | 
|  | 2608 | struct edgeport_port *edge_port; | 
|  | 2609 | struct usb_device *dev; | 
|  | 2610 | int status; | 
|  | 2611 | int i; | 
|  | 2612 |  | 
|  | 2613 | dev = serial->dev; | 
|  | 2614 |  | 
|  | 2615 | /* create our private serial structure */ | 
| Eric Sesterhenn | 80b6ca4 | 2006-02-27 21:29:43 +0100 | [diff] [blame] | 2616 | edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | if (edge_serial == NULL) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2618 | dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | return -ENOMEM; | 
|  | 2620 | } | 
| Matthias Kaehlcke | 241ca64 | 2007-12-04 16:15:40 +0100 | [diff] [blame] | 2621 | mutex_init(&edge_serial->es_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | edge_serial->serial = serial; | 
|  | 2623 | usb_set_serial_data(serial, edge_serial); | 
|  | 2624 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2625 | status = download_fw(edge_serial); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | if (status) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2627 | kfree(edge_serial); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | return status; | 
|  | 2629 | } | 
|  | 2630 |  | 
|  | 2631 | /* set up our port private structures */ | 
|  | 2632 | for (i = 0; i < serial->num_ports; ++i) { | 
| Eric Sesterhenn | 80b6ca4 | 2006-02-27 21:29:43 +0100 | [diff] [blame] | 2633 | edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | if (edge_port == NULL) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2635 | dev_err(&serial->dev->dev, "%s - Out of memory\n", | 
|  | 2636 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | goto cleanup; | 
|  | 2638 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | spin_lock_init(&edge_port->ep_lock); | 
|  | 2640 | edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE); | 
|  | 2641 | if (edge_port->ep_out_buf == NULL) { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2642 | dev_err(&serial->dev->dev, "%s - Out of memory\n", | 
|  | 2643 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | kfree(edge_port); | 
|  | 2645 | goto cleanup; | 
|  | 2646 | } | 
|  | 2647 | edge_port->port = serial->port[i]; | 
|  | 2648 | edge_port->edge_serial = edge_serial; | 
|  | 2649 | usb_set_serial_port_data(serial->port[i], edge_port); | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 2650 | edge_port->bUartMode = default_uart_mode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2652 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | return 0; | 
|  | 2654 |  | 
|  | 2655 | cleanup: | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2656 | for (--i; i >= 0; --i) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | edge_port = usb_get_serial_port_data(serial->port[i]); | 
|  | 2658 | edge_buf_free(edge_port->ep_out_buf); | 
|  | 2659 | kfree(edge_port); | 
|  | 2660 | usb_set_serial_port_data(serial->port[i], NULL); | 
|  | 2661 | } | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2662 | kfree(edge_serial); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | usb_set_serial_data(serial, NULL); | 
|  | 2664 | return -ENOMEM; | 
|  | 2665 | } | 
|  | 2666 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2667 | static void edge_shutdown(struct usb_serial *serial) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | { | 
|  | 2669 | int i; | 
|  | 2670 | struct edgeport_port *edge_port; | 
|  | 2671 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2672 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 |  | 
| Jesper Juhl | 0d46c00 | 2007-07-16 22:17:25 +0200 | [diff] [blame] | 2674 | for (i = 0; i < serial->num_ports; ++i) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | edge_port = usb_get_serial_port_data(serial->port[i]); | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 2676 | edge_remove_sysfs_attrs(edge_port->port); | 
| Jesper Juhl | 0d46c00 | 2007-07-16 22:17:25 +0200 | [diff] [blame] | 2677 | edge_buf_free(edge_port->ep_out_buf); | 
|  | 2678 | kfree(edge_port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | usb_set_serial_port_data(serial->port[i], NULL); | 
|  | 2680 | } | 
| Jesper Juhl | 0d46c00 | 2007-07-16 22:17:25 +0200 | [diff] [blame] | 2681 | kfree(usb_get_serial_data(serial)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | usb_set_serial_data(serial, NULL); | 
|  | 2683 | } | 
|  | 2684 |  | 
|  | 2685 |  | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 2686 | /* Sysfs Attributes */ | 
|  | 2687 |  | 
|  | 2688 | static ssize_t show_uart_mode(struct device *dev, | 
|  | 2689 | struct device_attribute *attr, char *buf) | 
|  | 2690 | { | 
|  | 2691 | struct usb_serial_port *port = to_usb_serial_port(dev); | 
|  | 2692 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 2693 |  | 
|  | 2694 | return sprintf(buf, "%d\n", edge_port->bUartMode); | 
|  | 2695 | } | 
|  | 2696 |  | 
|  | 2697 | static ssize_t store_uart_mode(struct device *dev, | 
|  | 2698 | struct device_attribute *attr, const char *valbuf, size_t count) | 
|  | 2699 | { | 
|  | 2700 | struct usb_serial_port *port = to_usb_serial_port(dev); | 
|  | 2701 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 
|  | 2702 | unsigned int v = simple_strtoul(valbuf, NULL, 0); | 
|  | 2703 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2704 | dbg("%s: setting uart_mode = %d", __func__, v); | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 2705 |  | 
|  | 2706 | if (v < 256) | 
|  | 2707 | edge_port->bUartMode = v; | 
|  | 2708 | else | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2709 | dev_err(dev, "%s - uart_mode %d is invalid\n", __func__, v); | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 2710 |  | 
|  | 2711 | return count; | 
|  | 2712 | } | 
|  | 2713 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2714 | static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode, | 
|  | 2715 | store_uart_mode); | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 2716 |  | 
|  | 2717 | static int edge_create_sysfs_attrs(struct usb_serial_port *port) | 
|  | 2718 | { | 
|  | 2719 | return device_create_file(&port->dev, &dev_attr_uart_mode); | 
|  | 2720 | } | 
|  | 2721 |  | 
|  | 2722 | static int edge_remove_sysfs_attrs(struct usb_serial_port *port) | 
|  | 2723 | { | 
|  | 2724 | device_remove_file(&port->dev, &dev_attr_uart_mode); | 
|  | 2725 | return 0; | 
|  | 2726 | } | 
|  | 2727 |  | 
|  | 2728 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | /* Circular Buffer */ | 
|  | 2730 |  | 
|  | 2731 | /* | 
|  | 2732 | * edge_buf_alloc | 
|  | 2733 | * | 
|  | 2734 | * Allocate a circular buffer and all associated memory. | 
|  | 2735 | */ | 
|  | 2736 |  | 
|  | 2737 | static struct edge_buf *edge_buf_alloc(unsigned int size) | 
|  | 2738 | { | 
|  | 2739 | struct edge_buf *eb; | 
|  | 2740 |  | 
|  | 2741 |  | 
|  | 2742 | if (size == 0) | 
|  | 2743 | return NULL; | 
|  | 2744 |  | 
| Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 2745 | eb = kmalloc(sizeof(struct edge_buf), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | if (eb == NULL) | 
|  | 2747 | return NULL; | 
|  | 2748 |  | 
|  | 2749 | eb->buf_buf = kmalloc(size, GFP_KERNEL); | 
|  | 2750 | if (eb->buf_buf == NULL) { | 
|  | 2751 | kfree(eb); | 
|  | 2752 | return NULL; | 
|  | 2753 | } | 
|  | 2754 |  | 
|  | 2755 | eb->buf_size = size; | 
|  | 2756 | eb->buf_get = eb->buf_put = eb->buf_buf; | 
|  | 2757 |  | 
|  | 2758 | return eb; | 
|  | 2759 | } | 
|  | 2760 |  | 
|  | 2761 |  | 
|  | 2762 | /* | 
|  | 2763 | * edge_buf_free | 
|  | 2764 | * | 
|  | 2765 | * Free the buffer and all associated memory. | 
|  | 2766 | */ | 
|  | 2767 |  | 
| Adrian Bunk | 3d48586 | 2005-11-20 23:56:11 +0100 | [diff] [blame] | 2768 | static void edge_buf_free(struct edge_buf *eb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | { | 
| Jesper Juhl | 1bc3c9e | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 2770 | if (eb) { | 
|  | 2771 | kfree(eb->buf_buf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | kfree(eb); | 
|  | 2773 | } | 
|  | 2774 | } | 
|  | 2775 |  | 
|  | 2776 |  | 
|  | 2777 | /* | 
|  | 2778 | * edge_buf_clear | 
|  | 2779 | * | 
|  | 2780 | * Clear out all data in the circular buffer. | 
|  | 2781 | */ | 
|  | 2782 |  | 
|  | 2783 | static void edge_buf_clear(struct edge_buf *eb) | 
|  | 2784 | { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2785 | if (eb != NULL) | 
|  | 2786 | eb->buf_get = eb->buf_put; | 
|  | 2787 | /* equivalent to a get of all data available */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | } | 
|  | 2789 |  | 
|  | 2790 |  | 
|  | 2791 | /* | 
|  | 2792 | * edge_buf_data_avail | 
|  | 2793 | * | 
|  | 2794 | * Return the number of bytes of data available in the circular | 
|  | 2795 | * buffer. | 
|  | 2796 | */ | 
|  | 2797 |  | 
|  | 2798 | static unsigned int edge_buf_data_avail(struct edge_buf *eb) | 
|  | 2799 | { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2800 | if (eb == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | return 0; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2802 | return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | } | 
|  | 2804 |  | 
|  | 2805 |  | 
|  | 2806 | /* | 
|  | 2807 | * edge_buf_space_avail | 
|  | 2808 | * | 
|  | 2809 | * Return the number of bytes of space available in the circular | 
|  | 2810 | * buffer. | 
|  | 2811 | */ | 
|  | 2812 |  | 
|  | 2813 | static unsigned int edge_buf_space_avail(struct edge_buf *eb) | 
|  | 2814 | { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2815 | if (eb == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | return 0; | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2817 | return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | } | 
|  | 2819 |  | 
|  | 2820 |  | 
|  | 2821 | /* | 
|  | 2822 | * edge_buf_put | 
|  | 2823 | * | 
|  | 2824 | * Copy data data from a user buffer and put it into the circular buffer. | 
|  | 2825 | * Restrict to the amount of space available. | 
|  | 2826 | * | 
|  | 2827 | * Return the number of bytes copied. | 
|  | 2828 | */ | 
|  | 2829 |  | 
|  | 2830 | static unsigned int edge_buf_put(struct edge_buf *eb, const char *buf, | 
|  | 2831 | unsigned int count) | 
|  | 2832 | { | 
|  | 2833 | unsigned int len; | 
|  | 2834 |  | 
|  | 2835 |  | 
|  | 2836 | if (eb == NULL) | 
|  | 2837 | return 0; | 
|  | 2838 |  | 
|  | 2839 | len  = edge_buf_space_avail(eb); | 
|  | 2840 | if (count > len) | 
|  | 2841 | count = len; | 
|  | 2842 |  | 
|  | 2843 | if (count == 0) | 
|  | 2844 | return 0; | 
|  | 2845 |  | 
|  | 2846 | len = eb->buf_buf + eb->buf_size - eb->buf_put; | 
|  | 2847 | if (count > len) { | 
|  | 2848 | memcpy(eb->buf_put, buf, len); | 
|  | 2849 | memcpy(eb->buf_buf, buf+len, count - len); | 
|  | 2850 | eb->buf_put = eb->buf_buf + count - len; | 
|  | 2851 | } else { | 
|  | 2852 | memcpy(eb->buf_put, buf, count); | 
|  | 2853 | if (count < len) | 
|  | 2854 | eb->buf_put += count; | 
|  | 2855 | else /* count == len */ | 
|  | 2856 | eb->buf_put = eb->buf_buf; | 
|  | 2857 | } | 
|  | 2858 |  | 
|  | 2859 | return count; | 
|  | 2860 | } | 
|  | 2861 |  | 
|  | 2862 |  | 
|  | 2863 | /* | 
|  | 2864 | * edge_buf_get | 
|  | 2865 | * | 
|  | 2866 | * Get data from the circular buffer and copy to the given buffer. | 
|  | 2867 | * Restrict to the amount of data available. | 
|  | 2868 | * | 
|  | 2869 | * Return the number of bytes copied. | 
|  | 2870 | */ | 
|  | 2871 |  | 
|  | 2872 | static unsigned int edge_buf_get(struct edge_buf *eb, char *buf, | 
|  | 2873 | unsigned int count) | 
|  | 2874 | { | 
|  | 2875 | unsigned int len; | 
|  | 2876 |  | 
|  | 2877 |  | 
|  | 2878 | if (eb == NULL) | 
|  | 2879 | return 0; | 
|  | 2880 |  | 
|  | 2881 | len = edge_buf_data_avail(eb); | 
|  | 2882 | if (count > len) | 
|  | 2883 | count = len; | 
|  | 2884 |  | 
|  | 2885 | if (count == 0) | 
|  | 2886 | return 0; | 
|  | 2887 |  | 
|  | 2888 | len = eb->buf_buf + eb->buf_size - eb->buf_get; | 
|  | 2889 | if (count > len) { | 
|  | 2890 | memcpy(buf, eb->buf_get, len); | 
|  | 2891 | memcpy(buf+len, eb->buf_buf, count - len); | 
|  | 2892 | eb->buf_get = eb->buf_buf + count - len; | 
|  | 2893 | } else { | 
|  | 2894 | memcpy(buf, eb->buf_get, count); | 
|  | 2895 | if (count < len) | 
|  | 2896 | eb->buf_get += count; | 
|  | 2897 | else /* count == len */ | 
|  | 2898 | eb->buf_get = eb->buf_buf; | 
|  | 2899 | } | 
|  | 2900 |  | 
|  | 2901 | return count; | 
|  | 2902 | } | 
|  | 2903 |  | 
|  | 2904 |  | 
| Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2905 | static struct usb_serial_driver edgeport_1port_device = { | 
| Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2906 | .driver = { | 
| Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2907 | .owner		= THIS_MODULE, | 
|  | 2908 | .name		= "edgeport_ti_1", | 
| Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2909 | }, | 
| Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2910 | .description		= "Edgeport TI 1 port adapter", | 
| Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 2911 | .usb_driver		= &io_driver, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | .id_table		= edgeport_1port_id_table, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | .num_ports		= 1, | 
|  | 2914 | .open			= edge_open, | 
|  | 2915 | .close			= edge_close, | 
|  | 2916 | .throttle		= edge_throttle, | 
|  | 2917 | .unthrottle		= edge_unthrottle, | 
|  | 2918 | .attach			= edge_startup, | 
|  | 2919 | .shutdown		= edge_shutdown, | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 2920 | .port_probe		= edge_create_sysfs_attrs, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | .ioctl			= edge_ioctl, | 
|  | 2922 | .set_termios		= edge_set_termios, | 
|  | 2923 | .tiocmget		= edge_tiocmget, | 
|  | 2924 | .tiocmset		= edge_tiocmset, | 
|  | 2925 | .write			= edge_write, | 
|  | 2926 | .write_room		= edge_write_room, | 
|  | 2927 | .chars_in_buffer	= edge_chars_in_buffer, | 
|  | 2928 | .break_ctl		= edge_break, | 
|  | 2929 | .read_int_callback	= edge_interrupt_callback, | 
|  | 2930 | .read_bulk_callback	= edge_bulk_in_callback, | 
|  | 2931 | .write_bulk_callback	= edge_bulk_out_callback, | 
|  | 2932 | }; | 
|  | 2933 |  | 
| Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2934 | static struct usb_serial_driver edgeport_2port_device = { | 
| Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2935 | .driver = { | 
| Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2936 | .owner		= THIS_MODULE, | 
|  | 2937 | .name		= "edgeport_ti_2", | 
| Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2938 | }, | 
| Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2939 | .description		= "Edgeport TI 2 port adapter", | 
| Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 2940 | .usb_driver		= &io_driver, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | .id_table		= edgeport_2port_id_table, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | .num_ports		= 2, | 
|  | 2943 | .open			= edge_open, | 
|  | 2944 | .close			= edge_close, | 
|  | 2945 | .throttle		= edge_throttle, | 
|  | 2946 | .unthrottle		= edge_unthrottle, | 
|  | 2947 | .attach			= edge_startup, | 
|  | 2948 | .shutdown		= edge_shutdown, | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 2949 | .port_probe		= edge_create_sysfs_attrs, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | .ioctl			= edge_ioctl, | 
|  | 2951 | .set_termios		= edge_set_termios, | 
|  | 2952 | .tiocmget		= edge_tiocmget, | 
|  | 2953 | .tiocmset		= edge_tiocmset, | 
|  | 2954 | .write			= edge_write, | 
|  | 2955 | .write_room		= edge_write_room, | 
|  | 2956 | .chars_in_buffer	= edge_chars_in_buffer, | 
|  | 2957 | .break_ctl		= edge_break, | 
|  | 2958 | .read_int_callback	= edge_interrupt_callback, | 
|  | 2959 | .read_bulk_callback	= edge_bulk_in_callback, | 
|  | 2960 | .write_bulk_callback	= edge_bulk_out_callback, | 
|  | 2961 | }; | 
|  | 2962 |  | 
|  | 2963 |  | 
|  | 2964 | static int __init edgeport_init(void) | 
|  | 2965 | { | 
|  | 2966 | int retval; | 
|  | 2967 | retval = usb_serial_register(&edgeport_1port_device); | 
|  | 2968 | if (retval) | 
|  | 2969 | goto failed_1port_device_register; | 
|  | 2970 | retval = usb_serial_register(&edgeport_2port_device); | 
|  | 2971 | if (retval) | 
|  | 2972 | goto failed_2port_device_register; | 
|  | 2973 | retval = usb_register(&io_driver); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2974 | if (retval) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | goto failed_usb_register; | 
| Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 2976 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" | 
|  | 2977 | DRIVER_DESC "\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | return 0; | 
|  | 2979 | failed_usb_register: | 
|  | 2980 | usb_serial_deregister(&edgeport_2port_device); | 
|  | 2981 | failed_2port_device_register: | 
|  | 2982 | usb_serial_deregister(&edgeport_1port_device); | 
|  | 2983 | failed_1port_device_register: | 
|  | 2984 | return retval; | 
|  | 2985 | } | 
|  | 2986 |  | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2987 | static void __exit edgeport_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | { | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 2989 | usb_deregister(&io_driver); | 
|  | 2990 | usb_serial_deregister(&edgeport_1port_device); | 
|  | 2991 | usb_serial_deregister(&edgeport_2port_device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | } | 
|  | 2993 |  | 
|  | 2994 | module_init(edgeport_init); | 
|  | 2995 | module_exit(edgeport_exit); | 
|  | 2996 |  | 
|  | 2997 | /* Module information */ | 
|  | 2998 | MODULE_AUTHOR(DRIVER_AUTHOR); | 
|  | 2999 | MODULE_DESCRIPTION(DRIVER_DESC); | 
|  | 3000 | MODULE_LICENSE("GPL"); | 
| Jaswinder Singh | d12b219 | 2008-07-04 23:06:09 +0530 | [diff] [blame] | 3001 | MODULE_FIRMWARE("edgeport/down3.bin"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 |  | 
|  | 3003 | module_param(debug, bool, S_IRUGO | S_IWUSR); | 
|  | 3004 | MODULE_PARM_DESC(debug, "Debug enabled or not"); | 
|  | 3005 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | module_param(closing_wait, int, S_IRUGO | S_IWUSR); | 
|  | 3007 | MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs"); | 
|  | 3008 |  | 
|  | 3009 | module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR); | 
| Alan Cox | 2742fd8 | 2008-04-29 14:45:15 +0100 | [diff] [blame] | 3010 | MODULE_PARM_DESC(ignore_cpu_rev, | 
|  | 3011 | "Ignore the cpu revision when connecting to a device"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 |  | 
| Martin K. Petersen | fc4cbd7 | 2007-05-22 15:57:04 -0400 | [diff] [blame] | 3013 | module_param(default_uart_mode, int, S_IRUGO | S_IWUSR); | 
|  | 3014 | MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ..."); |