diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2009-06-02 18:16:24 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-06-19 14:00:56 -0400 |
commit | ba49d59ac4b0748c8d7be9d7a9f637c50592e977 (patch) | |
tree | ef93e06add51b3dcad53548587787f583fbd87de | |
parent | 8ba911c793c526c394eeddbe66f675c58a922449 (diff) |
Staging: remove obsolete serqt_usb driver
Now that Bill rewrote the driver "properly", this old thing can be removed.
Cc: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/staging/Makefile | 1 | ||||
-rw-r--r-- | drivers/staging/serqt_usb/Kconfig | 9 | ||||
-rw-r--r-- | drivers/staging/serqt_usb/Makefile | 1 | ||||
-rw-r--r-- | drivers/staging/serqt_usb/TODO | 8 | ||||
-rw-r--r-- | drivers/staging/serqt_usb/serqt_usb.c | 2655 |
5 files changed, 0 insertions, 2674 deletions
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index b0e0c60c1332..6b07f4381023 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile | |||
@@ -40,7 +40,6 @@ obj-$(CONFIG_IDE_PHISON) += phison/ | |||
40 | obj-$(CONFIG_PLAN9AUTH) += p9auth/ | 40 | obj-$(CONFIG_PLAN9AUTH) += p9auth/ |
41 | obj-$(CONFIG_HECI) += heci/ | 41 | obj-$(CONFIG_HECI) += heci/ |
42 | obj-$(CONFIG_LINE6_USB) += line6/ | 42 | obj-$(CONFIG_LINE6_USB) += line6/ |
43 | obj-$(CONFIG_USB_SERIAL_QUATECH_ESU100) += serqt_usb/ | ||
44 | obj-$(CONFIG_USB_SERIAL_QUATECH2) += serqt_usb2/ | 43 | obj-$(CONFIG_USB_SERIAL_QUATECH2) += serqt_usb2/ |
45 | obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ | 44 | obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ |
46 | obj-$(CONFIG_VT6655) += vt6655/ | 45 | obj-$(CONFIG_VT6655) += vt6655/ |
diff --git a/drivers/staging/serqt_usb/Kconfig b/drivers/staging/serqt_usb/Kconfig deleted file mode 100644 index cc1af5df40d7..000000000000 --- a/drivers/staging/serqt_usb/Kconfig +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | config USB_SERIAL_QUATECH_ESU100 | ||
2 | tristate "USB Quatech ESU-100 8 Port Serial Driver" | ||
3 | depends on USB_SERIAL | ||
4 | help | ||
5 | Say Y here if you want to use the Quatech ESU-100 8 port usb to | ||
6 | serial adapter. | ||
7 | |||
8 | To compile this driver as a module, choose M here: the | ||
9 | module will be called serqt_usb. | ||
diff --git a/drivers/staging/serqt_usb/Makefile b/drivers/staging/serqt_usb/Makefile deleted file mode 100644 index 4fd1da275e8d..000000000000 --- a/drivers/staging/serqt_usb/Makefile +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | obj-$(CONFIG_USB_SERIAL_QUATECH_ESU100) += serqt_usb.o | ||
diff --git a/drivers/staging/serqt_usb/TODO b/drivers/staging/serqt_usb/TODO deleted file mode 100644 index 34ecca8992d2..000000000000 --- a/drivers/staging/serqt_usb/TODO +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | Things to do for this driver to get merged into the main portion of the | ||
2 | kernel: | ||
3 | - checkpatch cleanups | ||
4 | - sparse clean | ||
5 | - port to the usb-serial layer instead of doing it all on its | ||
6 | own. | ||
7 | |||
8 | Send patches to Greg Kroah-Hartman <greg@kroah.com> | ||
diff --git a/drivers/staging/serqt_usb/serqt_usb.c b/drivers/staging/serqt_usb/serqt_usb.c deleted file mode 100644 index 27f78bddad68..000000000000 --- a/drivers/staging/serqt_usb/serqt_usb.c +++ /dev/null | |||
@@ -1,2655 +0,0 @@ | |||
1 | /* | ||
2 | * This code was developed for the Quatech USB line for linux, it used | ||
3 | * much of the code developed by Greg Kroah-Hartman for USB serial devices | ||
4 | * | ||
5 | */ | ||
6 | |||
7 | #include <linux/sched.h> | ||
8 | #include <linux/slab.h> | ||
9 | #include <linux/tty.h> | ||
10 | #include <linux/tty_flip.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/usb.h> | ||
13 | #include <linux/wait.h> | ||
14 | #include <linux/types.h> | ||
15 | #include <linux/uaccess.h> | ||
16 | |||
17 | /* Use our own dbg macro */ | ||
18 | /* #define DEBUG_ON */ | ||
19 | /* #undef dbg */ | ||
20 | #ifdef DEBUG_ON | ||
21 | #define mydbg(const...) printk(const) | ||
22 | #else | ||
23 | #define mydbg(const...) | ||
24 | #endif | ||
25 | |||
26 | /* parity check flag */ | ||
27 | #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) | ||
28 | |||
29 | #define SERIAL_TTY_MAJOR 0 /* Nice legal number now */ | ||
30 | #define SERIAL_TTY_MINORS 255 /* loads of devices :) */ | ||
31 | #define MAX_NUM_PORTS 8 /* The maximum number of ports one device can grab at once */ | ||
32 | #define PREFUFF_LEVEL_CONSERVATIVE 128 | ||
33 | #define ATC_DISABLED 0x00 | ||
34 | |||
35 | #define RR_BITS 0x03 /* for clearing clock bits */ | ||
36 | #define DUPMODE_BITS 0xc0 | ||
37 | |||
38 | #define RS232_MODE 0x00 | ||
39 | #define RTSCTS_TO_CONNECTOR 0x40 | ||
40 | #define CLKS_X4 0x02 | ||
41 | |||
42 | #define LOOPMODE_BITS 0x41 /* LOOP1 = b6, LOOP0 = b0 (PORT B) */ | ||
43 | #define ALL_LOOPBACK 0x01 | ||
44 | #define MODEM_CTRL 0x40 | ||
45 | |||
46 | #define THISCHAR data[i] | ||
47 | #define NEXTCHAR data[i + 1] | ||
48 | #define THIRDCHAR data[i + 2] | ||
49 | #define FOURTHCHAR data[i + 3] | ||
50 | |||
51 | /* | ||
52 | * Useful defintions for port A, Port B and Port C | ||
53 | */ | ||
54 | #define FULLPWRBIT 0x00000080 | ||
55 | #define NEXT_BOARD_POWER_BIT 0x00000004 | ||
56 | |||
57 | #define SERIAL_LSR_OE 0x02 | ||
58 | #define SERIAL_LSR_PE 0x04 | ||
59 | #define SERIAL_LSR_FE 0x08 | ||
60 | #define SERIAL_LSR_BI 0x10 | ||
61 | |||
62 | #define SERIAL_LSR_TEMT 0x40 | ||
63 | |||
64 | #define DIV_LATCH_LS 0x00 | ||
65 | #define XMT_HOLD_REGISTER 0x00 | ||
66 | #define XVR_BUFFER_REGISTER 0x00 | ||
67 | #define DIV_LATCH_MS 0x01 | ||
68 | #define FIFO_CONTROL_REGISTER 0x02 | ||
69 | #define LINE_CONTROL_REGISTER 0x03 | ||
70 | #define MODEM_CONTROL_REGISTER 0x04 | ||
71 | #define LINE_STATUS_REGISTER 0x05 | ||
72 | #define MODEM_STATUS_REGISTER 0x06 | ||
73 | |||
74 | #define SERIAL_MCR_DTR 0x01 | ||
75 | #define SERIAL_MCR_RTS 0x02 | ||
76 | #define SERIAL_MCR_LOOP 0x10 | ||
77 | |||
78 | #define SERIAL_MSR_CTS 0x10 | ||
79 | #define SERIAL_MSR_CD 0x80 | ||
80 | #define SERIAL_MSR_RI 0x40 | ||
81 | #define SERIAL_MSR_DSR 0x20 | ||
82 | #define SERIAL_MSR_MASK 0xf0 | ||
83 | |||
84 | #define SERIAL_8_DATA 0x03 | ||
85 | #define SERIAL_7_DATA 0x02 | ||
86 | #define SERIAL_6_DATA 0x01 | ||
87 | #define SERIAL_5_DATA 0x00 | ||
88 | |||
89 | #define SERIAL_ODD_PARITY 0X08 | ||
90 | #define SERIAL_EVEN_PARITY 0X18 | ||
91 | #define SERIAL_TWO_STOPB 0x04 | ||
92 | #define SERIAL_ONE_STOPB 0x00 | ||
93 | |||
94 | #define MAX_BAUD_RATE 460800 | ||
95 | #define MAX_BAUD_REMAINDER 4608 | ||
96 | |||
97 | #define QT_SET_GET_DEVICE 0xc2 | ||
98 | #define QT_OPEN_CLOSE_CHANNEL 0xca | ||
99 | #define QT_GET_SET_PREBUF_TRIG_LVL 0xcc | ||
100 | #define QT_SET_ATF 0xcd | ||
101 | #define QT_GET_SET_REGISTER 0xc0 | ||
102 | #define QT_GET_SET_UART 0xc1 | ||
103 | #define QT_HW_FLOW_CONTROL_MASK 0xc5 | ||
104 | #define QT_SW_FLOW_CONTROL_MASK 0xc6 | ||
105 | #define QT_SW_FLOW_CONTROL_DISABLE 0xc7 | ||
106 | #define QT_BREAK_CONTROL 0xc8 | ||
107 | |||
108 | #define SERIALQT_PCI_IOC_MAGIC 'k' | ||
109 | #define SERIALQT_WRITE_QOPR _IOW(SERIALQT_PCI_IOC_MAGIC, 0, int) | ||
110 | #define SERIALQT_WRITE_QMCR _IOW(SERIALQT_PCI_IOC_MAGIC, 1, int) | ||
111 | #define SERIALQT_GET_NUMOF_UNITS _IOR(SERIALQT_PCI_IOC_MAGIC, 2, void *) | ||
112 | #define SERIALQT_GET_THIS_UNIT _IOR(SERIALQT_PCI_IOC_MAGIC, 3, void *) | ||
113 | #define SERIALQT_READ_QOPR _IOR(SERIALQT_PCI_IOC_MAGIC, 4, int) | ||
114 | #define SERIALQT_READ_QMCR _IOR(SERIALQT_PCI_IOC_MAGIC, 5, int) | ||
115 | #define SERIALQT_IS422_EXTENDED _IOR(SERIALQT_PCI_IOC_MAGIC, 6, int) /* returns successful if 422 extended */ | ||
116 | |||
117 | #define USBD_TRANSFER_DIRECTION_IN 0xc0 | ||
118 | #define USBD_TRANSFER_DIRECTION_OUT 0x40 | ||
119 | |||
120 | #define ATC_DISABLED 0x00 | ||
121 | #define ATC_RTS_ENABLED 0x02 | ||
122 | #define ATC_DTR_ENABLED 0x01 | ||
123 | |||
124 | #define RR_BITS 0x03 /* for clearing clock bits */ | ||
125 | #define DUPMODE_BITS 0xc0 | ||
126 | |||
127 | #define FULL_DUPLEX 0x00 | ||
128 | #define HALF_DUPLEX_RTS 0x40 | ||
129 | #define HALF_DUPLEX_DTR 0x80 | ||
130 | |||
131 | #define QMCR_FULL_DUPLEX 0x00 | ||
132 | #define QMCR_HALF_DUPLEX_RTS 0x02 | ||
133 | #define QMCR_HALF_DUPLEX_DTR 0x01 | ||
134 | #define QMCR_HALF_DUPLEX_MASK 0x03 | ||
135 | #define QMCR_CONNECTOR_MASK 0x1C | ||
136 | |||
137 | #define QMCR_RX_EN_MASK 0x20 | ||
138 | |||
139 | #define QMCR_ALL_LOOPBACK 0x10 | ||
140 | #define QMCR_MODEM_CONTROL 0X00 | ||
141 | |||
142 | #define SERIALQT_IOC_MAXNR 6 | ||
143 | |||
144 | struct usb_serial_port { | ||
145 | struct usb_serial *serial; /* pointer back to the owner of this port */ | ||
146 | struct tty_struct *tty; /* the coresponding tty for this port */ | ||
147 | unsigned char number; | ||
148 | char active; /* someone has this device open */ | ||
149 | |||
150 | unsigned char *interrupt_in_buffer; | ||
151 | struct urb *interrupt_in_urb; | ||
152 | __u8 interrupt_in_endpointAddress; | ||
153 | |||
154 | unsigned char *bulk_in_buffer; | ||
155 | unsigned char *xfer_to_tty_buffer; | ||
156 | struct urb *read_urb; | ||
157 | __u8 bulk_in_endpointAddress; | ||
158 | |||
159 | unsigned char *bulk_out_buffer; | ||
160 | int bulk_out_size; | ||
161 | struct urb *write_urb; | ||
162 | __u8 bulk_out_endpointAddress; | ||
163 | |||
164 | wait_queue_head_t write_wait; | ||
165 | wait_queue_head_t wait; | ||
166 | struct work_struct work; | ||
167 | |||
168 | int open_count; /* number of times this port has been opened */ | ||
169 | struct semaphore sem; /* locks this structure */ | ||
170 | |||
171 | __u8 shadowLCR; /* last LCR value received */ | ||
172 | __u8 shadowMCR; /* last MCR value received */ | ||
173 | __u8 shadowMSR; /* last MSR value received */ | ||
174 | __u8 shadowLSR; /* last LSR value received */ | ||
175 | int RxHolding; | ||
176 | char closePending; | ||
177 | int ReadBulkStopped; | ||
178 | |||
179 | void *private; /* data private to the specific port */ | ||
180 | }; | ||
181 | |||
182 | struct identity { | ||
183 | int index; | ||
184 | int n_identity; | ||
185 | }; | ||
186 | |||
187 | struct usb_serial { | ||
188 | struct usb_device *dev; | ||
189 | struct usb_interface *interface; /* the interface for this device */ | ||
190 | struct tty_driver *tty_driver; /* the tty_driver for this device */ | ||
191 | unsigned char minor; /* the starting minor number for this device */ | ||
192 | unsigned char num_ports; /* the number of ports this device has */ | ||
193 | char num_interrupt_in; /* number of interrupt in endpoints we have */ | ||
194 | char num_bulk_in; /* number of bulk in endpoints we have */ | ||
195 | char num_bulk_out; /* number of bulk out endpoints we have */ | ||
196 | unsigned char num_OpenCount; /* the number of ports this device has */ | ||
197 | |||
198 | __u16 vendor; /* vendor id of this device */ | ||
199 | __u16 product; /* product id of this device */ | ||
200 | struct usb_serial_port port[MAX_NUM_PORTS]; | ||
201 | |||
202 | void *private; /* data private to the specific driver */ | ||
203 | }; | ||
204 | |||
205 | static inline int port_paranoia_check(struct usb_serial_port *port, | ||
206 | const char *function) | ||
207 | { | ||
208 | if (!port) { | ||
209 | dbg("%s - port == NULL", function); | ||
210 | return -1; | ||
211 | } | ||
212 | if (!port->serial) { | ||
213 | dbg("%s - port->serial == NULL\n", function); | ||
214 | return -1; | ||
215 | } | ||
216 | if (!port->tty) { | ||
217 | dbg("%s - port->tty == NULL\n", function); | ||
218 | return -1; | ||
219 | } | ||
220 | |||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | /* Inline functions to check the sanity of a pointer that is passed to us */ | ||
225 | static inline int serial_paranoia_check(struct usb_serial *serial, | ||
226 | const char *function) | ||
227 | { | ||
228 | if (!serial) { | ||
229 | dbg("%s - serial == NULL\n", function); | ||
230 | return -1; | ||
231 | } | ||
232 | |||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | static inline struct usb_serial *get_usb_serial(struct usb_serial_port *port, | ||
237 | const char *function) | ||
238 | { | ||
239 | /* if no port was specified, or it fails a paranoia check */ | ||
240 | if (!port || | ||
241 | port_paranoia_check(port, function) || | ||
242 | serial_paranoia_check(port->serial, function)) { | ||
243 | /* then say that we dont have a valid usb_serial thing, which will | ||
244 | * end up genrating -ENODEV return values */ | ||
245 | return NULL; | ||
246 | } | ||
247 | |||
248 | return port->serial; | ||
249 | } | ||
250 | |||
251 | struct qt_get_device_data { | ||
252 | __u8 porta; | ||
253 | __u8 portb; | ||
254 | __u8 portc; | ||
255 | }; | ||
256 | |||
257 | struct qt_open_channel_data { | ||
258 | __u8 line_status; | ||
259 | __u8 modem_status; | ||
260 | }; | ||
261 | |||
262 | static void ProcessLineStatus(struct usb_serial_port *port, | ||
263 | unsigned char line_status); | ||
264 | static void ProcessModemStatus(struct usb_serial_port *port, | ||
265 | unsigned char modem_status); | ||
266 | static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data); | ||
267 | static struct usb_serial *get_free_serial(int num_ports, int *minor); | ||
268 | |||
269 | static int serqt_probe(struct usb_interface *interface, | ||
270 | const struct usb_device_id *id); | ||
271 | |||
272 | static void serqt_usb_disconnect(struct usb_interface *interface); | ||
273 | static int box_set_device(struct usb_serial *serial, | ||
274 | struct qt_get_device_data *pDeviceData); | ||
275 | static int box_get_device(struct usb_serial *serial, | ||
276 | struct qt_get_device_data *pDeviceData); | ||
277 | static int serial_open(struct tty_struct *tty, struct file *filp); | ||
278 | static void serial_close(struct tty_struct *tty, struct file *filp); | ||
279 | static int serial_write_room(struct tty_struct *tty); | ||
280 | static int serial_ioctl(struct tty_struct *tty, struct file *file, | ||
281 | unsigned int cmd, unsigned long arg); | ||
282 | static void serial_set_termios(struct tty_struct *tty, struct ktermios *old); | ||
283 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, | ||
284 | int count); | ||
285 | |||
286 | static void serial_throttle(struct tty_struct *tty); | ||
287 | static void serial_unthrottle(struct tty_struct *tty); | ||
288 | static int serial_break(struct tty_struct *tty, int break_state); | ||
289 | static int serial_chars_in_buffer(struct tty_struct *tty); | ||
290 | |||
291 | static int qt_open(struct tty_struct *tty, struct usb_serial_port *port, | ||
292 | struct file *filp); | ||
293 | static int BoxSetPrebufferLevel(struct usb_serial *serial); | ||
294 | |||
295 | static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode); | ||
296 | static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number, | ||
297 | unsigned short default_divisor, | ||
298 | unsigned char default_LCR); | ||
299 | |||
300 | static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, | ||
301 | __u16 OpenClose, | ||
302 | struct qt_open_channel_data *pDeviceData); | ||
303 | static void qt_close(struct tty_struct *tty, struct usb_serial_port *port, | ||
304 | struct file *filp); | ||
305 | static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number, | ||
306 | unsigned short Register_Num, __u8 *pValue); | ||
307 | static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number, | ||
308 | unsigned short Register_Num, unsigned short Value); | ||
309 | static void qt_write_bulk_callback(struct urb *urb); | ||
310 | static int qt_write(struct tty_struct *tty, struct usb_serial_port *port, | ||
311 | const unsigned char *buf, int count); | ||
312 | static void port_softint(struct work_struct *work); | ||
313 | static int qt_write_room(struct usb_serial_port *port); | ||
314 | static int qt_chars_in_buffer(struct usb_serial_port *port); | ||
315 | static int qt_ioctl(struct tty_struct *tty, struct usb_serial_port *port, | ||
316 | struct file *file, unsigned int cmd, unsigned long arg); | ||
317 | static void qt_set_termios(struct tty_struct *tty, | ||
318 | struct usb_serial_port *port, | ||
319 | struct ktermios *old_termios); | ||
320 | static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int index, | ||
321 | int bSet); | ||
322 | static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 index); | ||
323 | static int EmulateWriteQMCR_Reg(int index, unsigned uc_value); | ||
324 | static int EmulateReadQMCR_Reg(int index, unsigned *uc_value); | ||
325 | static struct usb_serial *find_the_box(unsigned int index); | ||
326 | static int ioctl_serial_usb(struct inode *innod, struct file *filp, unsigned int cmd, | ||
327 | unsigned long arg); | ||
328 | |||
329 | static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 Uart, | ||
330 | unsigned char stop_char, unsigned char start_char); | ||
331 | static void qt_read_bulk_callback(struct urb *urb); | ||
332 | |||
333 | static void port_sofrint(void *private); | ||
334 | |||
335 | static void return_serial(struct usb_serial *serial); | ||
336 | |||
337 | static int serial_tiocmset(struct tty_struct *tty, struct file *file, | ||
338 | unsigned int set, unsigned int clear); | ||
339 | static int serial_tiocmget(struct tty_struct *tty, struct file *file); | ||
340 | |||
341 | static int qt_tiocmset(struct tty_struct *tty, struct usb_serial_port *port, | ||
342 | struct file *file, unsigned int value); | ||
343 | |||
344 | static int qt_tiocmget(struct tty_struct *tty, struct usb_serial_port *port, | ||
345 | struct file *file); | ||
346 | |||
347 | /* Version Information */ | ||
348 | #define DRIVER_VERSION "v2.14" | ||
349 | #define DRIVER_AUTHOR "Tim Gobeli, Quatech, Inc" | ||
350 | #define DRIVER_DESC "Quatech USB to Serial Driver" | ||
351 | |||
352 | #define USB_VENDOR_ID_QUATECH 0x061d /* Quatech VID */ | ||
353 | #define DEVICE_ID_QUATECH_RS232_SINGLE_PORT 0xC020 /* SSU100 */ | ||
354 | #define DEVICE_ID_QUATECH_RS422_SINGLE_PORT 0xC030 /* SSU200 */ | ||
355 | #define DEVICE_ID_QUATECH_RS232_DUAL_PORT 0xC040 /* DSU100 */ | ||
356 | #define DEVICE_ID_QUATECH_RS422_DUAL_PORT 0xC050 /* DSU200 */ | ||
357 | #define DEVICE_ID_QUATECH_RS232_FOUR_PORT 0xC060 /* QSU100 */ | ||
358 | #define DEVICE_ID_QUATECH_RS422_FOUR_PORT 0xC070 /* QSU200 */ | ||
359 | #define DEVICE_ID_QUATECH_RS232_EIGHT_PORT_A 0xC080 /* ESU100A */ | ||
360 | #define DEVICE_ID_QUATECH_RS232_EIGHT_PORT_B 0xC081 /* ESU100B */ | ||
361 | #define DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A 0xC0A0 /* ESU200A */ | ||
362 | #define DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B 0xC0A1 /* ESU200B */ | ||
363 | #define DEVICE_ID_QUATECH_RS232_16_PORT_A 0xC090 /* HSU100A */ | ||
364 | #define DEVICE_ID_QUATECH_RS232_16_PORT_B 0xC091 /* HSU100B */ | ||
365 | #define DEVICE_ID_QUATECH_RS232_16_PORT_C 0xC092 /* HSU100C */ | ||
366 | #define DEVICE_ID_QUATECH_RS232_16_PORT_D 0xC093 /* HSU100D */ | ||
367 | #define DEVICE_ID_QUATECH_RS422_16_PORT_A 0xC0B0 /* HSU200A */ | ||
368 | #define DEVICE_ID_QUATECH_RS422_16_PORT_B 0xC0B1 /* HSU200B */ | ||
369 | #define DEVICE_ID_QUATECH_RS422_16_PORT_C 0xC0B2 /* HSU200C */ | ||
370 | #define DEVICE_ID_QUATECH_RS422_16_PORT_D 0xC0B3 /* HSU200D */ | ||
371 | |||
372 | /* table of Quatech devices */ | ||
373 | static struct usb_device_id serqt_table[] = { | ||
374 | {USB_DEVICE | ||
375 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_SINGLE_PORT)}, | ||
376 | {USB_DEVICE | ||
377 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_SINGLE_PORT)}, | ||
378 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_DUAL_PORT)}, | ||
379 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_DUAL_PORT)}, | ||
380 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_FOUR_PORT)}, | ||
381 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_FOUR_PORT)}, | ||
382 | {USB_DEVICE | ||
383 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_A)}, | ||
384 | {USB_DEVICE | ||
385 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_B)}, | ||
386 | {USB_DEVICE | ||
387 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A)}, | ||
388 | {USB_DEVICE | ||
389 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B)}, | ||
390 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_A)}, | ||
391 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_B)}, | ||
392 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_C)}, | ||
393 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_D)}, | ||
394 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_A)}, | ||
395 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_B)}, | ||
396 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_C)}, | ||
397 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_D)}, | ||
398 | {} /* Terminating entry */ | ||
399 | }; | ||
400 | |||
401 | MODULE_DEVICE_TABLE(usb, serqt_table); | ||
402 | |||
403 | static int major_number; | ||
404 | static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */ | ||
405 | |||
406 | /* table of Quatech 422devices */ | ||
407 | static unsigned int serqt_422_table[] = { | ||
408 | DEVICE_ID_QUATECH_RS422_SINGLE_PORT, | ||
409 | DEVICE_ID_QUATECH_RS422_DUAL_PORT, | ||
410 | DEVICE_ID_QUATECH_RS422_FOUR_PORT, | ||
411 | DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A, | ||
412 | DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B, | ||
413 | DEVICE_ID_QUATECH_RS422_16_PORT_A, | ||
414 | DEVICE_ID_QUATECH_RS422_16_PORT_B, | ||
415 | DEVICE_ID_QUATECH_RS422_16_PORT_C, | ||
416 | DEVICE_ID_QUATECH_RS422_16_PORT_D, | ||
417 | 0 /* terminate with zero */ | ||
418 | }; | ||
419 | |||
420 | /* usb specific object needed to register this driver with the usb subsystem */ | ||
421 | static struct usb_driver serqt_usb_driver = { | ||
422 | .name = "quatech-usb-serial", | ||
423 | .probe = serqt_probe, | ||
424 | .disconnect = serqt_usb_disconnect, | ||
425 | .id_table = serqt_table, | ||
426 | }; | ||
427 | |||
428 | static struct ktermios *serial_termios[SERIAL_TTY_MINORS]; | ||
429 | static struct ktermios *serial_termios_locked[SERIAL_TTY_MINORS]; | ||
430 | |||
431 | static const struct tty_operations serial_ops = { | ||
432 | .open = serial_open, | ||
433 | .close = serial_close, | ||
434 | .write = serial_write, | ||
435 | .write_room = serial_write_room, | ||
436 | .ioctl = serial_ioctl, | ||
437 | .set_termios = serial_set_termios, | ||
438 | .throttle = serial_throttle, | ||
439 | .unthrottle = serial_unthrottle, | ||
440 | .break_ctl = serial_break, | ||
441 | .chars_in_buffer = serial_chars_in_buffer, | ||
442 | .tiocmset = serial_tiocmset, | ||
443 | .tiocmget = serial_tiocmget, | ||
444 | }; | ||
445 | |||
446 | static struct tty_driver serial_tty_driver = { | ||
447 | .magic = TTY_DRIVER_MAGIC, | ||
448 | .driver_name = "Quatech usb-serial", | ||
449 | .name = "ttyQT_USB", | ||
450 | .major = SERIAL_TTY_MAJOR, | ||
451 | .minor_start = 0, | ||
452 | .num = SERIAL_TTY_MINORS, | ||
453 | .type = TTY_DRIVER_TYPE_SERIAL, | ||
454 | .subtype = SERIAL_TYPE_NORMAL, | ||
455 | .flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV, | ||
456 | |||
457 | .termios = serial_termios, | ||
458 | .termios_locked = serial_termios_locked, | ||
459 | .init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL, | ||
460 | |||
461 | .init_termios.c_iflag = ICRNL | IXON, | ||
462 | .init_termios.c_oflag = OPOST, | ||
463 | |||
464 | .init_termios.c_lflag = | ||
465 | ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN, | ||
466 | }; | ||
467 | |||
468 | /* fops for parent device */ | ||
469 | static const struct file_operations serialqt_usb_fops = { | ||
470 | .ioctl = ioctl_serial_usb, | ||
471 | }; | ||
472 | |||
473 | /** | ||
474 | * serqt_probe | ||
475 | * | ||
476 | * Called by the usb core when a new device is connected that it thinks | ||
477 | * this driver might be interested in. | ||
478 | * | ||
479 | */ | ||
480 | static int serqt_probe(struct usb_interface *interface, | ||
481 | const struct usb_device_id *id) | ||
482 | { | ||
483 | struct usb_device *dev = interface_to_usbdev(interface); | ||
484 | struct usb_serial *serial = NULL; | ||
485 | struct usb_serial_port *port; | ||
486 | struct usb_endpoint_descriptor *endpoint; | ||
487 | struct usb_endpoint_descriptor *interrupt_in_endpoint[MAX_NUM_PORTS]; | ||
488 | struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS]; | ||
489 | struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS]; | ||
490 | int minor; | ||
491 | int buffer_size; | ||
492 | int i; | ||
493 | struct usb_host_interface *iface_desc; | ||
494 | int num_interrupt_in = 0; | ||
495 | int num_bulk_in = 0; | ||
496 | int num_bulk_out = 0; | ||
497 | int num_ports; | ||
498 | struct qt_get_device_data DeviceData; | ||
499 | int status; | ||
500 | |||
501 | mydbg("In %s\n", __func__); | ||
502 | |||
503 | /* let's find the endpoints needed */ | ||
504 | /* check out the endpoints */ | ||
505 | iface_desc = interface->cur_altsetting;; | ||
506 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { | ||
507 | endpoint = &iface_desc->endpoint[i].desc; | ||
508 | |||
509 | if ((endpoint->bEndpointAddress & 0x80) && | ||
510 | ((endpoint->bmAttributes & 3) == 0x02)) { | ||
511 | /* we found a bulk in endpoint */ | ||
512 | mydbg("found bulk in"); | ||
513 | bulk_in_endpoint[num_bulk_in] = endpoint; | ||
514 | ++num_bulk_in; | ||
515 | } | ||
516 | |||
517 | if (((endpoint->bEndpointAddress & 0x80) == 0x00) && | ||
518 | ((endpoint->bmAttributes & 3) == 0x02)) { | ||
519 | /* we found a bulk out endpoint */ | ||
520 | mydbg("found bulk out\n"); | ||
521 | bulk_out_endpoint[num_bulk_out] = endpoint; | ||
522 | ++num_bulk_out; | ||
523 | } | ||
524 | |||
525 | if ((endpoint->bEndpointAddress & 0x80) && | ||
526 | ((endpoint->bmAttributes & 3) == 0x03)) { | ||
527 | /* we found a interrupt in endpoint */ | ||
528 | mydbg("found interrupt in\n"); | ||
529 | interrupt_in_endpoint[num_interrupt_in] = endpoint; | ||
530 | ++num_interrupt_in; | ||
531 | } | ||
532 | } | ||
533 | |||
534 | /* found all that we need */ | ||
535 | dev_info(&interface->dev, "Quatech converter detected\n"); | ||
536 | num_ports = num_bulk_out; | ||
537 | if (num_ports == 0) { | ||
538 | err("Quatech device with no bulk out, not allowed."); | ||
539 | return -ENODEV; | ||
540 | |||
541 | } | ||
542 | |||
543 | serial = get_free_serial(num_ports, &minor); | ||
544 | if (serial == NULL) { | ||
545 | err("No more free serial devices"); | ||
546 | return -ENODEV; | ||
547 | } | ||
548 | |||
549 | serial->dev = dev; | ||
550 | serial->interface = interface; | ||
551 | serial->minor = minor; | ||
552 | serial->num_ports = num_ports; | ||
553 | serial->num_bulk_in = num_bulk_in; | ||
554 | serial->num_bulk_out = num_bulk_out; | ||
555 | serial->num_interrupt_in = num_interrupt_in; | ||
556 | serial->vendor = dev->descriptor.idVendor; | ||
557 | serial->product = dev->descriptor.idProduct; | ||
558 | |||
559 | /* set up the endpoint information */ | ||
560 | for (i = 0; i < num_bulk_in; ++i) { | ||
561 | endpoint = bulk_in_endpoint[i]; | ||
562 | port = &serial->port[i]; | ||
563 | port->read_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
564 | if (!port->read_urb) { | ||
565 | err("No free urbs available"); | ||
566 | goto probe_error; | ||
567 | } | ||
568 | buffer_size = endpoint->wMaxPacketSize; | ||
569 | port->bulk_in_endpointAddress = endpoint->bEndpointAddress; | ||
570 | port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); | ||
571 | port->xfer_to_tty_buffer = kmalloc(buffer_size, GFP_KERNEL); | ||
572 | if (!port->bulk_in_buffer) { | ||
573 | err("Couldn't allocate bulk_in_buffer"); | ||
574 | goto probe_error; | ||
575 | } | ||
576 | usb_fill_bulk_urb(port->read_urb, dev, | ||
577 | usb_rcvbulkpipe(dev, | ||
578 | endpoint->bEndpointAddress), | ||
579 | port->bulk_in_buffer, buffer_size, | ||
580 | qt_read_bulk_callback, port); | ||
581 | } | ||
582 | |||
583 | for (i = 0; i < num_bulk_out; ++i) { | ||
584 | endpoint = bulk_out_endpoint[i]; | ||
585 | port = &serial->port[i]; | ||
586 | port->write_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
587 | if (!port->write_urb) { | ||
588 | err("No free urbs available"); | ||
589 | goto probe_error; | ||
590 | } | ||
591 | buffer_size = endpoint->wMaxPacketSize; | ||
592 | port->bulk_out_size = buffer_size; | ||
593 | port->bulk_out_endpointAddress = endpoint->bEndpointAddress; | ||
594 | port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); | ||
595 | if (!port->bulk_out_buffer) { | ||
596 | err("Couldn't allocate bulk_out_buffer"); | ||
597 | goto probe_error; | ||
598 | } | ||
599 | usb_fill_bulk_urb(port->write_urb, dev, | ||
600 | usb_sndbulkpipe(dev, | ||
601 | endpoint->bEndpointAddress), | ||
602 | port->bulk_out_buffer, buffer_size, | ||
603 | qt_write_bulk_callback, port); | ||
604 | |||
605 | } | ||
606 | |||
607 | /* For us numb of bulkin or out = number of ports */ | ||
608 | mydbg("%s - setting up %d port structures for this device\n", | ||
609 | __func__, num_bulk_in); | ||
610 | for (i = 0; i < num_bulk_in; ++i) { | ||
611 | port = &serial->port[i]; | ||
612 | port->number = i + serial->minor; | ||
613 | port->serial = serial; | ||
614 | |||
615 | INIT_WORK(&port->work, port_softint); | ||
616 | |||
617 | init_MUTEX(&port->sem); | ||
618 | |||
619 | } | ||
620 | status = box_get_device(serial, &DeviceData); | ||
621 | if (status < 0) { | ||
622 | mydbg(__FILE__ "box_get_device failed"); | ||
623 | goto probe_error; | ||
624 | } | ||
625 | |||
626 | mydbg(__FILE__ "DeviceData.portb = 0x%x", DeviceData.portb); | ||
627 | |||
628 | DeviceData.portb &= ~FULLPWRBIT; | ||
629 | mydbg(__FILE__ "Changing DeviceData.portb to 0x%x", DeviceData.portb); | ||
630 | |||
631 | status = box_set_device(serial, &DeviceData); | ||
632 | if (status < 0) { | ||
633 | mydbg(__FILE__ "box_set_device failed\n"); | ||
634 | goto probe_error; | ||
635 | } | ||
636 | |||
637 | /* initialize the devfs nodes for this device and let the user know what ports we are bound to */ | ||
638 | for (i = 0; i < serial->num_ports; ++i) { | ||
639 | dev_info(&interface->dev, | ||
640 | "Converter now attached to ttyUSB%d (or usb/tts/%d for devfs)", | ||
641 | serial->port[i].number, serial->port[i].number); | ||
642 | } | ||
643 | |||
644 | /* usb_serial_console_init (debug, minor); */ | ||
645 | |||
646 | /***********TAG add start next board here ****/ | ||
647 | status = box_get_device(serial, &DeviceData); | ||
648 | if (status < 0) { | ||
649 | mydbg(__FILE__ "box_get_device failed"); | ||
650 | goto probe_error; | ||
651 | } | ||
652 | /* | ||
653 | * and before we power up lets initialiaze parnent device stuff here before | ||
654 | * we set thmem via any other method such as the property pages | ||
655 | */ | ||
656 | switch (serial->product) { | ||
657 | case DEVICE_ID_QUATECH_RS232_SINGLE_PORT: | ||
658 | case DEVICE_ID_QUATECH_RS232_DUAL_PORT: | ||
659 | case DEVICE_ID_QUATECH_RS232_FOUR_PORT: | ||
660 | case DEVICE_ID_QUATECH_RS232_EIGHT_PORT_A: | ||
661 | case DEVICE_ID_QUATECH_RS232_EIGHT_PORT_B: | ||
662 | case DEVICE_ID_QUATECH_RS232_16_PORT_A: | ||
663 | case DEVICE_ID_QUATECH_RS232_16_PORT_B: | ||
664 | case DEVICE_ID_QUATECH_RS232_16_PORT_C: | ||
665 | case DEVICE_ID_QUATECH_RS232_16_PORT_D: | ||
666 | DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); | ||
667 | DeviceData.porta |= CLKS_X4; | ||
668 | DeviceData.portb &= ~(LOOPMODE_BITS); | ||
669 | DeviceData.portb |= RS232_MODE; | ||
670 | break; | ||
671 | |||
672 | case DEVICE_ID_QUATECH_RS422_SINGLE_PORT: | ||
673 | case DEVICE_ID_QUATECH_RS422_DUAL_PORT: | ||
674 | case DEVICE_ID_QUATECH_RS422_FOUR_PORT: | ||
675 | case DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A: | ||
676 | case DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B: | ||
677 | case DEVICE_ID_QUATECH_RS422_16_PORT_A: | ||
678 | case DEVICE_ID_QUATECH_RS422_16_PORT_B: | ||
679 | case DEVICE_ID_QUATECH_RS422_16_PORT_C: | ||
680 | case DEVICE_ID_QUATECH_RS422_16_PORT_D: | ||
681 | DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); | ||
682 | DeviceData.porta |= CLKS_X4; | ||
683 | DeviceData.portb &= ~(LOOPMODE_BITS); | ||
684 | DeviceData.portb |= ALL_LOOPBACK; | ||
685 | break; | ||
686 | default: | ||
687 | DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); | ||
688 | DeviceData.porta |= CLKS_X4; | ||
689 | DeviceData.portb &= ~(LOOPMODE_BITS); | ||
690 | DeviceData.portb |= RS232_MODE; | ||
691 | break; | ||
692 | |||
693 | } | ||
694 | status = BoxSetPrebufferLevel(serial); /* sets to default vaue */ | ||
695 | if (status < 0) { | ||
696 | mydbg(__FILE__ "BoxSetPrebufferLevel failed\n"); | ||
697 | goto probe_error; | ||
698 | } | ||
699 | |||
700 | status = BoxSetATC(serial, ATC_DISABLED); | ||
701 | if (status < 0) { | ||
702 | mydbg(__FILE__ "BoxSetATC failed\n"); | ||
703 | goto probe_error; | ||
704 | } | ||
705 | /**********************************************************/ | ||
706 | mydbg(__FILE__ "DeviceData.portb = 0x%x", DeviceData.portb); | ||
707 | |||
708 | DeviceData.portb |= NEXT_BOARD_POWER_BIT; | ||
709 | mydbg(__FILE__ "Changing DeviceData.portb to 0x%x", DeviceData.portb); | ||
710 | |||
711 | status = box_set_device(serial, &DeviceData); | ||
712 | if (status < 0) { | ||
713 | mydbg(__FILE__ "box_set_device failed\n"); | ||
714 | goto probe_error; | ||
715 | } | ||
716 | |||
717 | mydbg("Exit Success %s\n", __func__); | ||
718 | |||
719 | usb_set_intfdata(interface, serial); | ||
720 | return 0; | ||
721 | |||
722 | probe_error: | ||
723 | |||
724 | for (i = 0; i < num_bulk_in; ++i) { | ||
725 | port = &serial->port[i]; | ||
726 | usb_free_urb(port->read_urb); | ||
727 | kfree(port->bulk_in_buffer); | ||
728 | } | ||
729 | for (i = 0; i < num_bulk_out; ++i) { | ||
730 | port = &serial->port[i]; | ||
731 | usb_free_urb(port->write_urb); | ||
732 | kfree(port->bulk_out_buffer); | ||
733 | kfree(port->xfer_to_tty_buffer); | ||
734 | } | ||
735 | for (i = 0; i < num_interrupt_in; ++i) { | ||
736 | port = &serial->port[i]; | ||
737 | usb_free_urb(port->interrupt_in_urb); | ||
738 | kfree(port->interrupt_in_buffer); | ||
739 | } | ||
740 | |||
741 | /* return the minor range that this device had */ | ||
742 | return_serial(serial); | ||
743 | mydbg("Exit fail %s\n", __func__); | ||
744 | |||
745 | /* free up any memory that we allocated */ | ||
746 | kfree(serial); | ||
747 | return -EIO; | ||
748 | } | ||
749 | |||
750 | /* | ||
751 | * returns the serial_table array pointers that are taken | ||
752 | * up in consecutive positions for each port to a common usb_serial structure | ||
753 | * back to NULL | ||
754 | */ | ||
755 | static void return_serial(struct usb_serial *serial) | ||
756 | { | ||
757 | int i; | ||
758 | |||
759 | mydbg("%s\n", __func__); | ||
760 | |||
761 | if (serial == NULL) | ||
762 | return; | ||
763 | |||
764 | for (i = 0; i < serial->num_ports; ++i) | ||
765 | serial_table[serial->minor + i] = NULL; | ||
766 | |||
767 | return; | ||
768 | } | ||
769 | |||
770 | /* | ||
771 | * Finds the first locatio int the serial_table array where it can fit | ||
772 | * num_ports number of consecutive points to a common usb_serial | ||
773 | * structure,allocates a stucture points to it in all the structures, and | ||
774 | * returns the index to the first location in the array in the "minor" | ||
775 | * variable. | ||
776 | */ | ||
777 | static struct usb_serial *get_free_serial(int num_ports, int *minor) | ||
778 | { | ||
779 | struct usb_serial *serial = NULL; | ||
780 | int i, j; | ||
781 | int good_spot; | ||
782 | |||
783 | mydbg("%s %d\n", __func__, num_ports); | ||
784 | |||
785 | *minor = 0; | ||
786 | for (i = 0; i < SERIAL_TTY_MINORS; ++i) { | ||
787 | if (serial_table[i]) | ||
788 | continue; | ||
789 | |||
790 | good_spot = 1; | ||
791 | /* | ||
792 | * find a spot in the array where you can fit consecutive | ||
793 | * positions to put the pointers to the usb_serail allocated | ||
794 | * structure for all the minor numbers (ie. ports) | ||
795 | */ | ||
796 | for (j = 1; j <= num_ports - 1; ++j) | ||
797 | if (serial_table[i + j]) | ||
798 | good_spot = 0; | ||
799 | if (good_spot == 0) | ||
800 | continue; | ||
801 | |||
802 | serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL); | ||
803 | if (!serial) { | ||
804 | err("%s - Out of memory", __func__); | ||
805 | return NULL; | ||
806 | } | ||
807 | memset(serial, 0, sizeof(struct usb_serial)); | ||
808 | serial_table[i] = serial; | ||
809 | *minor = i; | ||
810 | mydbg("%s - minor base = %d\n", __func__, *minor); | ||
811 | |||
812 | /* | ||
813 | * copy in the pointer into the array starting a the *minor | ||
814 | * position minor is the index into the array. | ||
815 | */ | ||
816 | for (i = *minor + 1; | ||
817 | (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i) | ||
818 | serial_table[i] = serial; | ||
819 | return serial; | ||
820 | } | ||
821 | return NULL; | ||
822 | } | ||
823 | |||
824 | static int flip_that(struct tty_struct *tty, __u16 index, | ||
825 | struct usb_serial *serial) | ||
826 | { | ||
827 | tty_flip_buffer_push(tty); | ||
828 | tty_schedule_flip(tty); | ||
829 | return 0; | ||
830 | } | ||
831 | |||
832 | /* Handles processing and moving data to the tty layer */ | ||
833 | static void port_sofrint(void *private) | ||
834 | { | ||
835 | struct usb_serial_port *port = private; | ||
836 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
837 | struct tty_struct *tty = port->tty; | ||
838 | unsigned char *data = port->read_urb->transfer_buffer; | ||
839 | unsigned int index; | ||
840 | struct urb *urb = port->read_urb; | ||
841 | unsigned int RxCount = urb->actual_length; | ||
842 | int i, result; | ||
843 | int flag, flag_data; | ||
844 | |||
845 | /* index = MINOR(port->tty->device) - serial->minor; */ | ||
846 | index = tty->index - serial->minor; | ||
847 | |||
848 | mydbg("%s - port %d\n", __func__, port->number); | ||
849 | mydbg("%s - port->RxHolding = %d\n", __func__, port->RxHolding); | ||
850 | |||
851 | if (port_paranoia_check(port, __func__) != 0) { | ||
852 | mydbg("%s - port_paranoia_check, exiting\n", __func__); | ||
853 | port->ReadBulkStopped = 1; | ||
854 | return; | ||
855 | } | ||
856 | |||
857 | if (!serial) { | ||
858 | mydbg("%s - bad serial pointer, exiting\n", __func__); | ||
859 | return; | ||
860 | } | ||
861 | if (port->closePending == 1) { | ||
862 | /* Were closing , stop reading */ | ||
863 | mydbg("%s - (port->closepending == 1\n", __func__); | ||
864 | port->ReadBulkStopped = 1; | ||
865 | return; | ||
866 | } | ||
867 | |||
868 | /* | ||
869 | * RxHolding is asserted by throttle, if we assert it, we're not | ||
870 | * receiving any more characters and let the box handle the flow | ||
871 | * control | ||
872 | */ | ||
873 | if (port->RxHolding == 1) { | ||
874 | port->ReadBulkStopped = 1; | ||
875 | return; | ||
876 | } | ||
877 | |||
878 | if (urb->status) { | ||
879 | port->ReadBulkStopped = 1; | ||
880 | |||
881 | mydbg("%s - nonzero read bulk status received: %d\n", | ||
882 | __func__, urb->status); | ||
883 | return; | ||
884 | } | ||
885 | |||
886 | tty = port->tty; | ||
887 | mydbg("%s - port %d, tty =0x%p\n", __func__, port->number, tty); | ||
888 | |||
889 | if (tty && RxCount) { | ||
890 | flag_data = 0; | ||
891 | for (i = 0; i < RxCount; ++i) { | ||
892 | /* Look ahead code here */ | ||
893 | if ((i <= (RxCount - 3)) && (THISCHAR == 0x1b) | ||
894 | && (NEXTCHAR == 0x1b)) { | ||
895 | flag = 0; | ||
896 | switch (THIRDCHAR) { | ||
897 | case 0x00: | ||
898 | /* Line status change 4th byte must follow */ | ||
899 | if (i > (RxCount - 4)) { | ||
900 | mydbg("Illegal escape sequences in received data\n"); | ||
901 | break; | ||
902 | } | ||
903 | ProcessLineStatus(port, FOURTHCHAR); | ||
904 | i += 3; | ||
905 | flag = 1; | ||
906 | break; | ||
907 | |||
908 | case 0x01: | ||
909 | /* Modem status status change 4th byte must follow */ | ||
910 | mydbg("Modem status status. \n"); | ||
911 | if (i > (RxCount - 4)) { | ||
912 | mydbg | ||
913 | ("Illegal escape sequences in received data\n"); | ||
914 | break; | ||
915 | } | ||
916 | ProcessModemStatus(port, FOURTHCHAR); | ||
917 | i += 3; | ||
918 | flag = 1; | ||
919 | break; | ||
920 | case 0xff: | ||
921 | mydbg("No status sequence. \n"); | ||
922 | |||
923 | ProcessRxChar(port, THISCHAR); | ||
924 | ProcessRxChar(port, NEXTCHAR); | ||
925 | i += 2; | ||
926 | break; | ||
927 | } | ||
928 | if (flag == 1) | ||
929 | continue; | ||
930 | } | ||
931 | |||
932 | if (tty && urb->actual_length) { | ||
933 | tty_buffer_request_room(tty, 1); | ||
934 | tty_insert_flip_string(tty, (data + i), 1); | ||
935 | } | ||
936 | |||
937 | } | ||
938 | tty_flip_buffer_push(tty); | ||
939 | } | ||
940 | |||
941 | /* Continue trying to always read */ | ||
942 | usb_fill_bulk_urb(port->read_urb, serial->dev, | ||
943 | usb_rcvbulkpipe(serial->dev, | ||
944 | port->bulk_in_endpointAddress), | ||
945 | port->read_urb->transfer_buffer, | ||
946 | port->read_urb->transfer_buffer_length, | ||
947 | qt_read_bulk_callback, port); | ||
948 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | ||
949 | if (result) | ||
950 | mydbg("%s - failed resubmitting read urb, error %d", | ||
951 | __func__, result); | ||
952 | else { | ||
953 | if (tty && RxCount) | ||
954 | flip_that(tty, index, serial); | ||
955 | } | ||
956 | |||
957 | return; | ||
958 | |||
959 | } | ||
960 | |||
961 | static void qt_read_bulk_callback(struct urb *urb) | ||
962 | { | ||
963 | |||
964 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | ||
965 | |||
966 | if (urb->status) { | ||
967 | port->ReadBulkStopped = 1; | ||
968 | mydbg("%s - nonzero write bulk status received: %d\n", | ||
969 | __func__, urb->status); | ||
970 | return; | ||
971 | } | ||
972 | |||
973 | port_sofrint((void *)port); | ||
974 | schedule_work(&port->work); | ||
975 | } | ||
976 | |||
977 | static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data) | ||
978 | { | ||
979 | struct tty_struct *tty; | ||
980 | struct urb *urb = port->read_urb; | ||
981 | tty = port->tty; | ||
982 | /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ | ||
983 | |||
984 | if (tty && urb->actual_length) { | ||
985 | tty_buffer_request_room(tty, 1); | ||
986 | tty_insert_flip_string(tty, &Data, 1); | ||
987 | /* tty_flip_buffer_push(tty); */ | ||
988 | } | ||
989 | |||
990 | return; | ||
991 | } | ||
992 | |||
993 | static void ProcessLineStatus(struct usb_serial_port *port, | ||
994 | unsigned char line_status) | ||
995 | { | ||
996 | |||
997 | port->shadowLSR = | ||
998 | line_status & (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | | ||
999 | SERIAL_LSR_BI); | ||
1000 | return; | ||
1001 | } | ||
1002 | |||
1003 | static void ProcessModemStatus(struct usb_serial_port *port, | ||
1004 | unsigned char modem_status) | ||
1005 | { | ||
1006 | |||
1007 | port->shadowMSR = modem_status; | ||
1008 | wake_up_interruptible(&port->wait); | ||
1009 | return; | ||
1010 | } | ||
1011 | |||
1012 | static void serqt_usb_disconnect(struct usb_interface *interface) | ||
1013 | { | ||
1014 | struct usb_serial *serial = usb_get_intfdata(interface); | ||
1015 | /* struct device *dev = &interface->dev; */ | ||
1016 | struct usb_serial_port *port; | ||
1017 | int i; | ||
1018 | |||
1019 | mydbg("%s\n", __func__); | ||
1020 | if (serial) { | ||
1021 | |||
1022 | serial->dev = NULL; | ||
1023 | |||
1024 | for (i = 0; i < serial->num_ports; ++i) | ||
1025 | serial->port[i].open_count = 0; | ||
1026 | |||
1027 | for (i = 0; i < serial->num_bulk_in; ++i) { | ||
1028 | port = &serial->port[i]; | ||
1029 | usb_unlink_urb(port->read_urb); | ||
1030 | usb_free_urb(port->read_urb); | ||
1031 | kfree(port->bulk_in_buffer); | ||
1032 | } | ||
1033 | for (i = 0; i < serial->num_bulk_out; ++i) { | ||
1034 | port = &serial->port[i]; | ||
1035 | usb_unlink_urb(port->write_urb); | ||
1036 | usb_free_urb(port->write_urb); | ||
1037 | kfree(port->bulk_out_buffer); | ||
1038 | } | ||
1039 | for (i = 0; i < serial->num_interrupt_in; ++i) { | ||
1040 | port = &serial->port[i]; | ||
1041 | usb_unlink_urb(port->interrupt_in_urb); | ||
1042 | usb_free_urb(port->interrupt_in_urb); | ||
1043 | kfree(port->interrupt_in_buffer); | ||
1044 | } | ||
1045 | |||
1046 | /* return the minor range that this device had */ | ||
1047 | return_serial(serial); | ||
1048 | |||
1049 | /* free up any memory that we allocated */ | ||
1050 | kfree(serial); | ||
1051 | |||
1052 | } else { | ||
1053 | dev_info(&interface->dev, "device disconnected"); | ||
1054 | } | ||
1055 | |||
1056 | } | ||
1057 | |||
1058 | static struct usb_serial *get_serial_by_minor(unsigned int minor) | ||
1059 | { | ||
1060 | return serial_table[minor]; | ||
1061 | } | ||
1062 | |||
1063 | /***************************************************************************** | ||
1064 | * Driver tty interface functions | ||
1065 | *****************************************************************************/ | ||
1066 | static int serial_open(struct tty_struct *tty, struct file *filp) | ||
1067 | { | ||
1068 | struct usb_serial *serial; | ||
1069 | struct usb_serial_port *port; | ||
1070 | unsigned int portNumber; | ||
1071 | int retval = 0; | ||
1072 | |||
1073 | mydbg("%s\n", __func__); | ||
1074 | |||
1075 | /* initialize the pointer incase something fails */ | ||
1076 | tty->driver_data = NULL; | ||
1077 | |||
1078 | /* get the serial object associated with this tty pointer */ | ||
1079 | /* serial = get_serial_by_minor (MINOR(tty->device)); */ | ||
1080 | |||
1081 | /* get the serial object associated with this tty pointer */ | ||
1082 | serial = get_serial_by_minor(tty->index); | ||
1083 | |||
1084 | if (serial_paranoia_check(serial, __func__)) | ||
1085 | return -ENODEV; | ||
1086 | |||
1087 | /* set up our port structure making the tty driver remember our port object, and us it */ | ||
1088 | portNumber = tty->index - serial->minor; | ||
1089 | port = &serial->port[portNumber]; | ||
1090 | tty->driver_data = port; | ||
1091 | |||
1092 | down(&port->sem); | ||
1093 | port->tty = tty; | ||
1094 | |||
1095 | ++port->open_count; | ||
1096 | if (port->open_count == 1) { | ||
1097 | port->closePending = 0; | ||
1098 | mydbg("%s port->closepending = 0\n", __func__); | ||
1099 | |||
1100 | port->RxHolding = 0; | ||
1101 | mydbg("%s port->RxHolding = 0\n", __func__); | ||
1102 | |||
1103 | retval = qt_open(tty, port, filp); | ||
1104 | } | ||
1105 | |||
1106 | if (retval) | ||
1107 | port->open_count = 0; | ||
1108 | mydbg("%s returning port->closePending = %d\n", __func__, | ||
1109 | port->closePending); | ||
1110 | |||
1111 | up(&port->sem); | ||
1112 | return retval; | ||
1113 | } | ||
1114 | |||
1115 | /***************************************************************************** | ||
1116 | *device's specific driver functions | ||
1117 | *****************************************************************************/ | ||
1118 | static int qt_open(struct tty_struct *tty, struct usb_serial_port *port, | ||
1119 | struct file *filp) | ||
1120 | { | ||
1121 | struct usb_serial *serial = port->serial; | ||
1122 | int result = 0; | ||
1123 | unsigned int index; | ||
1124 | struct qt_get_device_data DeviceData; | ||
1125 | struct qt_open_channel_data ChannelData; | ||
1126 | unsigned short default_divisor = 0x30; /* gives 9600 baud rate */ | ||
1127 | unsigned char default_LCR = SERIAL_8_DATA; /* 8, none , 1 */ | ||
1128 | int status = 0; | ||
1129 | |||
1130 | if (port_paranoia_check(port, __func__)) | ||
1131 | return -ENODEV; | ||
1132 | |||
1133 | mydbg("%s - port %d\n", __func__, port->number); | ||
1134 | |||
1135 | index = tty->index - serial->minor; | ||
1136 | |||
1137 | status = box_get_device(serial, &DeviceData); | ||
1138 | if (status < 0) { | ||
1139 | mydbg(__FILE__ "box_get_device failed\n"); | ||
1140 | return status; | ||
1141 | } | ||
1142 | serial->num_OpenCount++; | ||
1143 | mydbg("%s serial->num_OpenCount = %d\n", __func__, | ||
1144 | serial->num_OpenCount); | ||
1145 | /* Open uart channel */ | ||
1146 | |||
1147 | /* Port specific setups */ | ||
1148 | status = BoxOPenCloseChannel(serial, index, 1, &ChannelData); | ||
1149 | if (status < 0) { | ||
1150 | mydbg(__FILE__ "BoxOPenCloseChannel failed\n"); | ||
1151 | return status; | ||
1152 | } | ||
1153 | mydbg(__FILE__ "BoxOPenCloseChannel completed.\n"); | ||
1154 | |||
1155 | port->shadowLSR = ChannelData.line_status & | ||
1156 | (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | SERIAL_LSR_BI); | ||
1157 | |||
1158 | port->shadowMSR = ChannelData.modem_status & | ||
1159 | (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD); | ||
1160 | |||
1161 | /* Set Baud rate to default and turn off (default)flow control here */ | ||
1162 | status = BoxSetUart(serial, index, default_divisor, default_LCR); | ||
1163 | if (status < 0) { | ||
1164 | mydbg(__FILE__ "BoxSetUart failed\n"); | ||
1165 | return status; | ||
1166 | } | ||
1167 | mydbg(__FILE__ "BoxSetUart completed.\n"); | ||
1168 | |||
1169 | /* Put this here to make it responsive to stty and defauls set by the tty layer */ | ||
1170 | qt_set_termios(tty, port, NULL); | ||
1171 | |||
1172 | /* Initialize the wait que head */ | ||
1173 | init_waitqueue_head(&(port->wait)); | ||
1174 | |||
1175 | /* if we have a bulk endpoint, start reading from it */ | ||
1176 | if (serial->num_bulk_in) { | ||
1177 | /* Start reading from the device */ | ||
1178 | usb_fill_bulk_urb(port->read_urb, serial->dev, | ||
1179 | usb_rcvbulkpipe(serial->dev, | ||
1180 | port-> | ||
1181 | bulk_in_endpointAddress), | ||
1182 | port->read_urb->transfer_buffer, | ||
1183 | port->read_urb->transfer_buffer_length, | ||
1184 | qt_read_bulk_callback, port); | ||
1185 | |||
1186 | port->ReadBulkStopped = 0; | ||
1187 | |||
1188 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | ||
1189 | |||
1190 | if (result) { | ||
1191 | err("%s - failed resubmitting read urb, error %d\n", | ||
1192 | __func__, result); | ||
1193 | port->ReadBulkStopped = 1; | ||
1194 | } | ||
1195 | |||
1196 | } | ||
1197 | |||
1198 | return result; | ||
1199 | } | ||
1200 | |||
1201 | static void serial_close(struct tty_struct *tty, struct file *filp) | ||
1202 | { | ||
1203 | struct usb_serial_port *port = | ||
1204 | tty->driver_data; | ||
1205 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1206 | |||
1207 | if (!serial) | ||
1208 | return; | ||
1209 | |||
1210 | down(&port->sem); | ||
1211 | |||
1212 | mydbg("%s - port %d\n", __func__, port->number); | ||
1213 | |||
1214 | /* if disconnect beat us to the punch here, there's nothing to do */ | ||
1215 | if (tty->driver_data) { | ||
1216 | if (!port->open_count) { | ||
1217 | mydbg("%s - port not opened\n", __func__); | ||
1218 | goto exit; | ||
1219 | } | ||
1220 | |||
1221 | --port->open_count; | ||
1222 | if (port->open_count <= 0) { | ||
1223 | port->closePending = 1; | ||
1224 | mydbg("%s - port->closePending = 1\n", __func__); | ||
1225 | |||
1226 | if (serial->dev) { | ||
1227 | qt_close(tty, port, filp); | ||
1228 | port->open_count = 0; | ||
1229 | } | ||
1230 | } | ||
1231 | |||
1232 | } | ||
1233 | |||
1234 | exit: | ||
1235 | up(&port->sem); | ||
1236 | |||
1237 | mydbg("%s - %d return\n", __func__, port->number); | ||
1238 | |||
1239 | } | ||
1240 | |||
1241 | static void qt_close(struct tty_struct *tty, struct usb_serial_port *port, | ||
1242 | struct file *filp) | ||
1243 | { | ||
1244 | unsigned long jift = jiffies + 10 * HZ; | ||
1245 | u8 lsr, mcr; | ||
1246 | struct usb_serial *serial = port->serial; | ||
1247 | int status; | ||
1248 | unsigned int index; | ||
1249 | |||
1250 | struct qt_open_channel_data ChannelData; | ||
1251 | status = 0; | ||
1252 | lsr = 0; | ||
1253 | |||
1254 | mydbg("%s - port %d\n", __func__, port->number); | ||
1255 | index = tty->index - serial->minor; | ||
1256 | |||
1257 | /* shutdown any bulk reads that might be going on */ | ||
1258 | if (serial->num_bulk_out) | ||
1259 | usb_unlink_urb(port->write_urb); | ||
1260 | if (serial->num_bulk_in) | ||
1261 | usb_unlink_urb(port->read_urb); | ||
1262 | |||
1263 | /* wait up to 30 seconds for transmitter to empty */ | ||
1264 | do { | ||
1265 | status = BoxGetRegister(serial, index, LINE_STATUS_REGISTER, &lsr); | ||
1266 | if (status < 0) { | ||
1267 | mydbg(__FILE__ "box_get_device failed\n"); | ||
1268 | break; | ||
1269 | } | ||
1270 | |||
1271 | if ((lsr & SERIAL_LSR_TEMT) | ||
1272 | && (port->ReadBulkStopped == 1)) | ||
1273 | break; | ||
1274 | schedule(); | ||
1275 | |||
1276 | } | ||
1277 | while (jiffies <= jift); | ||
1278 | |||
1279 | if (jiffies > jift) | ||
1280 | mydbg("%s - port %d timout of checking transmitter empty\n", | ||
1281 | __func__, port->number); | ||
1282 | else | ||
1283 | mydbg("%s - port %d checking transmitter empty succeded\n", | ||
1284 | __func__, port->number); | ||
1285 | |||
1286 | status = | ||
1287 | BoxGetRegister(serial, index, MODEM_CONTROL_REGISTER, | ||
1288 | &mcr); | ||
1289 | mydbg(__FILE__ "BoxGetRegister MCR = 0x%x.\n", mcr); | ||
1290 | |||
1291 | if (status >= 0) { | ||
1292 | mcr &= ~(SERIAL_MCR_DTR | SERIAL_MCR_RTS); | ||
1293 | /* status = BoxSetRegister(serial, index, MODEM_CONTROL_REGISTER, mcr); */ | ||
1294 | } | ||
1295 | |||
1296 | /* Close uart channel */ | ||
1297 | status = BoxOPenCloseChannel(serial, index, 0, &ChannelData); | ||
1298 | if (status < 0) | ||
1299 | mydbg("%s - port %d BoxOPenCloseChannel failed.\n", | ||
1300 | __func__, port->number); | ||
1301 | |||
1302 | serial->num_OpenCount--; | ||
1303 | |||
1304 | } | ||
1305 | |||
1306 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, | ||
1307 | int count) | ||
1308 | { | ||
1309 | struct usb_serial_port *port = tty->driver_data; | ||
1310 | struct usb_serial *serial; | ||
1311 | int retval = -EINVAL; | ||
1312 | unsigned int index; | ||
1313 | |||
1314 | serial = get_usb_serial(port, __func__); | ||
1315 | if (serial == NULL) | ||
1316 | return -ENODEV; | ||
1317 | /* This can happen if we get disconnected a */ | ||
1318 | if (port->open_count == 0) | ||
1319 | return -ENODEV; | ||
1320 | index = tty->index - serial->minor; | ||
1321 | |||
1322 | mydbg("%s - port %d, %d byte(s)\n", __func__, port->number, count); | ||
1323 | mydbg("%s - port->RxHolding = %d\n", __func__, port->RxHolding); | ||
1324 | |||
1325 | if (!port->open_count) { | ||
1326 | mydbg("%s - port not opened\n", __func__); | ||
1327 | goto exit; | ||
1328 | } | ||
1329 | |||
1330 | retval = qt_write(tty, port, buf, count); | ||
1331 | |||
1332 | exit: | ||
1333 | return retval; | ||
1334 | } | ||
1335 | |||
1336 | static int qt_write(struct tty_struct *tty, struct usb_serial_port *port, | ||
1337 | const unsigned char *buf, int count) | ||
1338 | { | ||
1339 | int result; | ||
1340 | unsigned int index; | ||
1341 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1342 | |||
1343 | if (serial == NULL) | ||
1344 | return -ENODEV; | ||
1345 | |||
1346 | mydbg("%s - port %d\n", __func__, port->number); | ||
1347 | |||
1348 | if (count == 0) { | ||
1349 | mydbg("%s - write request of 0 bytes\n", __func__); | ||
1350 | return 0; | ||
1351 | } | ||
1352 | |||
1353 | index = tty->index - serial->minor; | ||
1354 | /* only do something if we have a bulk out endpoint */ | ||
1355 | if (serial->num_bulk_out) { | ||
1356 | if (port->write_urb->status == -EINPROGRESS) { | ||
1357 | mydbg("%s - already writing\n", __func__); | ||
1358 | return 0; | ||
1359 | } | ||
1360 | |||
1361 | count = | ||
1362 | (count > port->bulk_out_size) ? port->bulk_out_size : count; | ||
1363 | memcpy(port->write_urb->transfer_buffer, buf, count); | ||
1364 | |||
1365 | /* usb_serial_debug_data(__FILE__, __func__, count, port->write_urb->transfer_buffer); */ | ||
1366 | |||
1367 | /* set up our urb */ | ||
1368 | |||
1369 | usb_fill_bulk_urb(port->write_urb, serial->dev, | ||
1370 | usb_sndbulkpipe(serial->dev, | ||
1371 | port-> | ||
1372 | bulk_out_endpointAddress), | ||
1373 | port->write_urb->transfer_buffer, count, | ||
1374 | qt_write_bulk_callback, port); | ||
1375 | |||
1376 | /* send the data out the bulk port */ | ||
1377 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | ||
1378 | if (result) | ||
1379 | mydbg("%s - failed submitting write urb, error %d\n", | ||
1380 | __func__, result); | ||
1381 | else | ||
1382 | result = count; | ||
1383 | |||
1384 | return result; | ||
1385 | } | ||
1386 | |||
1387 | /* no bulk out, so return 0 bytes written */ | ||
1388 | return 0; | ||
1389 | } | ||
1390 | |||
1391 | static void qt_write_bulk_callback(struct urb *urb) | ||
1392 | { | ||
1393 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | ||
1394 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1395 | |||
1396 | mydbg("%s - port %d\n", __func__, port->number); | ||
1397 | |||
1398 | if (!serial) { | ||
1399 | mydbg("%s - bad serial pointer, exiting\n", __func__); | ||
1400 | return; | ||
1401 | } | ||
1402 | |||
1403 | if (urb->status) { | ||
1404 | mydbg("%s - nonzero write bulk status received: %d\n", | ||
1405 | __func__, urb->status); | ||
1406 | return; | ||
1407 | } | ||
1408 | port_softint(&port->work); | ||
1409 | schedule_work(&port->work); | ||
1410 | |||
1411 | return; | ||
1412 | } | ||
1413 | |||
1414 | static void port_softint(struct work_struct *work) | ||
1415 | { | ||
1416 | struct usb_serial_port *port = | ||
1417 | container_of(work, struct usb_serial_port, work); | ||
1418 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1419 | struct tty_struct *tty; | ||
1420 | |||
1421 | mydbg("%s - port %d\n", __func__, port->number); | ||
1422 | |||
1423 | if (!serial) | ||
1424 | return; | ||
1425 | |||
1426 | tty = port->tty; | ||
1427 | if (!tty) | ||
1428 | return; | ||
1429 | #if 0 | ||
1430 | if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) | ||
1431 | && tty->ldisc.write_wakeup) { | ||
1432 | mydbg("%s - write wakeup call.\n", __func__); | ||
1433 | (tty->ldisc.write_wakeup) (tty); | ||
1434 | } | ||
1435 | #endif | ||
1436 | |||
1437 | wake_up_interruptible(&tty->write_wait); | ||
1438 | } | ||
1439 | static int serial_write_room(struct tty_struct *tty) | ||
1440 | { | ||
1441 | struct usb_serial_port *port = tty->driver_data; | ||
1442 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1443 | int retval = -EINVAL; | ||
1444 | |||
1445 | if (!serial) | ||
1446 | return -ENODEV; | ||
1447 | |||
1448 | down(&port->sem); | ||
1449 | |||
1450 | mydbg("%s - port %d\n", __func__, port->number); | ||
1451 | |||
1452 | if (!port->open_count) { | ||
1453 | mydbg("%s - port not open\n", __func__); | ||
1454 | goto exit; | ||
1455 | } | ||
1456 | |||
1457 | retval = qt_write_room(port); | ||
1458 | |||
1459 | exit: | ||
1460 | up(&port->sem); | ||
1461 | return retval; | ||
1462 | } | ||
1463 | static int qt_write_room(struct usb_serial_port *port) | ||
1464 | { | ||
1465 | struct usb_serial *serial = port->serial; | ||
1466 | int room = 0; | ||
1467 | if (port->closePending == 1) { | ||
1468 | mydbg("%s - port->closePending == 1\n", __func__); | ||
1469 | return -ENODEV; | ||
1470 | } | ||
1471 | |||
1472 | mydbg("%s - port %d\n", __func__, port->number); | ||
1473 | |||
1474 | if (serial->num_bulk_out) { | ||
1475 | if (port->write_urb->status != -EINPROGRESS) | ||
1476 | room = port->bulk_out_size; | ||
1477 | } | ||
1478 | |||
1479 | mydbg("%s - returns %d\n", __func__, room); | ||
1480 | return room; | ||
1481 | } | ||
1482 | static int serial_chars_in_buffer(struct tty_struct *tty) | ||
1483 | { | ||
1484 | struct usb_serial_port *port = tty->driver_data; | ||
1485 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1486 | int retval = -EINVAL; | ||
1487 | |||
1488 | if (!serial) | ||
1489 | return -ENODEV; | ||
1490 | |||
1491 | down(&port->sem); | ||
1492 | |||
1493 | mydbg("%s = port %d\n", __func__, port->number); | ||
1494 | |||
1495 | if (!port->open_count) { | ||
1496 | mydbg("%s - port not open\n", __func__); | ||
1497 | goto exit; | ||
1498 | } | ||
1499 | |||
1500 | retval = qt_chars_in_buffer(port); | ||
1501 | |||
1502 | exit: | ||
1503 | up(&port->sem); | ||
1504 | return retval; | ||
1505 | } | ||
1506 | |||
1507 | static int qt_chars_in_buffer(struct usb_serial_port *port) | ||
1508 | { | ||
1509 | struct usb_serial *serial = port->serial; | ||
1510 | int chars = 0; | ||
1511 | |||
1512 | mydbg("%s - port %d\n", __func__, port->number); | ||
1513 | |||
1514 | if (serial->num_bulk_out) { | ||
1515 | if (port->write_urb->status == -EINPROGRESS) | ||
1516 | chars = port->write_urb->transfer_buffer_length; | ||
1517 | } | ||
1518 | |||
1519 | mydbg("%s - returns %d\n", __func__, chars); | ||
1520 | return chars; | ||
1521 | } | ||
1522 | |||
1523 | static int serial_tiocmset(struct tty_struct *tty, struct file *file, | ||
1524 | unsigned int set, unsigned int clear) | ||
1525 | { | ||
1526 | |||
1527 | struct usb_serial_port *port = tty->driver_data; | ||
1528 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1529 | int retval = -ENODEV; | ||
1530 | unsigned int index; | ||
1531 | mydbg("In %s \n", __func__); | ||
1532 | |||
1533 | if (!serial) | ||
1534 | return -ENODEV; | ||
1535 | |||
1536 | index = tty->index - serial->minor; | ||
1537 | |||
1538 | down(&port->sem); | ||
1539 | |||
1540 | mydbg("%s - port %d \n", __func__, port->number); | ||
1541 | mydbg("%s - port->RxHolding = %d\n", __func__, port->RxHolding); | ||
1542 | |||
1543 | if (!port->open_count) { | ||
1544 | mydbg("%s - port not open\n", __func__); | ||
1545 | goto exit; | ||
1546 | } | ||
1547 | |||
1548 | retval = qt_tiocmset(tty, port, file, set); | ||
1549 | |||
1550 | exit: | ||
1551 | up(&port->sem); | ||
1552 | return retval; | ||
1553 | } | ||
1554 | |||
1555 | static int qt_tiocmset(struct tty_struct *tty, struct usb_serial_port *port, | ||
1556 | struct file *file, unsigned int value) | ||
1557 | { | ||
1558 | |||
1559 | u8 mcr; | ||
1560 | int status; | ||
1561 | unsigned int index; | ||
1562 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1563 | |||
1564 | if (serial == NULL) | ||
1565 | return -ENODEV; | ||
1566 | |||
1567 | mydbg("%s - port %d\n", __func__, port->number); | ||
1568 | |||
1569 | /**************************************************************************************/ | ||
1570 | /** TIOCMGET | ||
1571 | */ | ||
1572 | index = tty->index - serial->minor; | ||
1573 | status = | ||
1574 | BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, | ||
1575 | &mcr); | ||
1576 | if (status < 0) | ||
1577 | return -ESPIPE; | ||
1578 | |||
1579 | /* | ||
1580 | * Turn off the RTS and DTR and loopbcck and then only turn on what was | ||
1581 | * asked for | ||
1582 | */ | ||
1583 | mcr &= ~(SERIAL_MCR_RTS | SERIAL_MCR_DTR | SERIAL_MCR_LOOP); | ||
1584 | if (value & TIOCM_RTS) | ||
1585 | mcr |= SERIAL_MCR_RTS; | ||
1586 | if (value & TIOCM_DTR) | ||
1587 | mcr |= SERIAL_MCR_DTR; | ||
1588 | if (value & TIOCM_LOOP) | ||
1589 | mcr |= SERIAL_MCR_LOOP; | ||
1590 | |||
1591 | status = | ||
1592 | BoxSetRegister(port->serial, index, MODEM_CONTROL_REGISTER, | ||
1593 | mcr); | ||
1594 | if (status < 0) | ||
1595 | return -ESPIPE; | ||
1596 | else | ||
1597 | return 0; | ||
1598 | } | ||
1599 | |||
1600 | static int serial_tiocmget(struct tty_struct *tty, struct file *file) | ||
1601 | { | ||
1602 | |||
1603 | struct usb_serial_port *port = tty->driver_data; | ||
1604 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1605 | int retval = -ENODEV; | ||
1606 | unsigned int index; | ||
1607 | mydbg("In %s \n", __func__); | ||
1608 | |||
1609 | if (!serial) | ||
1610 | return -ENODEV; | ||
1611 | |||
1612 | index = tty->index - serial->minor; | ||
1613 | |||
1614 | down(&port->sem); | ||
1615 | |||
1616 | mydbg("%s - port %d\n", __func__, port->number); | ||
1617 | mydbg("%s - port->RxHolding = %d\n", __func__, port->RxHolding); | ||
1618 | |||
1619 | if (!port->open_count) { | ||
1620 | mydbg("%s - port not open\n", __func__); | ||
1621 | goto exit; | ||
1622 | } | ||
1623 | |||
1624 | retval = qt_tiocmget(tty, port, file); | ||
1625 | |||
1626 | exit: | ||
1627 | up(&port->sem); | ||
1628 | return retval; | ||
1629 | } | ||
1630 | |||
1631 | static int qt_tiocmget(struct tty_struct *tty, | ||
1632 | struct usb_serial_port *port, struct file *file) | ||
1633 | { | ||
1634 | |||
1635 | u8 mcr; | ||
1636 | u8 msr; | ||
1637 | unsigned int result = 0; | ||
1638 | int status; | ||
1639 | unsigned int index; | ||
1640 | |||
1641 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1642 | if (serial == NULL) | ||
1643 | return -ENODEV; | ||
1644 | |||
1645 | mydbg("%s - port %d, tty =0x%p\n", __func__, port->number, tty); | ||
1646 | |||
1647 | /**************************************************************************************/ | ||
1648 | /** TIOCMGET | ||
1649 | */ | ||
1650 | index = tty->index - serial->minor; | ||
1651 | status = | ||
1652 | BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, | ||
1653 | &mcr); | ||
1654 | if (status >= 0) { | ||
1655 | status = | ||
1656 | BoxGetRegister(port->serial, index, | ||
1657 | MODEM_STATUS_REGISTER, &msr); | ||
1658 | |||
1659 | } | ||
1660 | |||
1661 | if (status >= 0) { | ||
1662 | result = ((mcr & SERIAL_MCR_DTR) ? TIOCM_DTR : 0) | ||
1663 | /* DTR IS SET */ | ||
1664 | | ((mcr & SERIAL_MCR_RTS) ? TIOCM_RTS : 0) | ||
1665 | /* RTS IS SET */ | ||
1666 | | ((msr & SERIAL_MSR_CTS) ? TIOCM_CTS : 0) | ||
1667 | /* CTS is set */ | ||
1668 | | ((msr & SERIAL_MSR_CD) ? TIOCM_CAR : 0) | ||
1669 | /* Carrier detect is set */ | ||
1670 | | ((msr & SERIAL_MSR_RI) ? TIOCM_RI : 0) | ||
1671 | /* Ring indicator set */ | ||
1672 | | ((msr & SERIAL_MSR_DSR) ? TIOCM_DSR : 0); | ||
1673 | /* DSR is set */ | ||
1674 | return result; | ||
1675 | |||
1676 | } else | ||
1677 | return -ESPIPE; | ||
1678 | } | ||
1679 | |||
1680 | static int serial_ioctl(struct tty_struct *tty, struct file *file, | ||
1681 | unsigned int cmd, unsigned long arg) | ||
1682 | { | ||
1683 | |||
1684 | struct usb_serial_port *port = tty->driver_data; | ||
1685 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1686 | int retval = -ENODEV; | ||
1687 | unsigned int index; | ||
1688 | mydbg("In %s \n", __func__); | ||
1689 | |||
1690 | if (!serial) | ||
1691 | return -ENODEV; | ||
1692 | |||
1693 | index = tty->index - serial->minor; | ||
1694 | |||
1695 | down(&port->sem); | ||
1696 | |||
1697 | mydbg("%s - port %d, cmd 0x%.4x\n", __func__, port->number, cmd); | ||
1698 | mydbg("%s - port->RxHolding = %d\n", __func__, port->RxHolding); | ||
1699 | |||
1700 | if (!port->open_count) { | ||
1701 | mydbg("%s - port not open\n", __func__); | ||
1702 | goto exit; | ||
1703 | } | ||
1704 | |||
1705 | retval = qt_ioctl(tty, port, file, cmd, arg); | ||
1706 | |||
1707 | exit: | ||
1708 | up(&port->sem); | ||
1709 | return retval; | ||
1710 | } | ||
1711 | static int qt_ioctl(struct tty_struct *tty, struct usb_serial_port *port, | ||
1712 | struct file *file, unsigned int cmd, unsigned long arg) | ||
1713 | { | ||
1714 | __u8 mcr; | ||
1715 | __u8 msr; | ||
1716 | unsigned short prev_msr; | ||
1717 | unsigned int value, result = 0; | ||
1718 | int status; | ||
1719 | unsigned int index; | ||
1720 | |||
1721 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1722 | if (serial == NULL) | ||
1723 | return -ENODEV; | ||
1724 | |||
1725 | mydbg("%s - port %d, tty =0x%p\n", __func__, port->number, tty); | ||
1726 | |||
1727 | /* TIOCMGET */ | ||
1728 | index = tty->index - serial->minor; | ||
1729 | |||
1730 | if (cmd == TIOCMIWAIT) { | ||
1731 | DECLARE_WAITQUEUE(wait, current); | ||
1732 | prev_msr = port->shadowMSR & SERIAL_MSR_MASK; | ||
1733 | while (1) { | ||
1734 | add_wait_queue(&port->wait, &wait); | ||
1735 | set_current_state(TASK_INTERRUPTIBLE); | ||
1736 | schedule(); | ||
1737 | remove_wait_queue(&port->wait, &wait); | ||
1738 | /* see if a signal woke us up */ | ||
1739 | if (signal_pending(current)) | ||
1740 | return -ERESTARTSYS; | ||
1741 | msr = port->shadowMSR & SERIAL_MSR_MASK; | ||
1742 | if (msr == prev_msr) | ||
1743 | return -EIO; /* no change error */ | ||
1744 | |||
1745 | if ((arg & TIOCM_RNG | ||
1746 | && ((prev_msr & SERIAL_MSR_RI) == | ||
1747 | (msr & SERIAL_MSR_RI))) | ||
1748 | || (arg & TIOCM_DSR | ||
1749 | && ((prev_msr & SERIAL_MSR_DSR) == | ||
1750 | (msr & SERIAL_MSR_DSR))) | ||
1751 | || (arg & TIOCM_CD | ||
1752 | && ((prev_msr & SERIAL_MSR_CD) == | ||
1753 | (msr & SERIAL_MSR_CD))) | ||
1754 | || (arg & TIOCM_CTS | ||
1755 | && ((prev_msr & SERIAL_MSR_CTS) == | ||
1756 | (msr & SERIAL_MSR_CTS)))) { | ||
1757 | return 0; | ||
1758 | } | ||
1759 | |||
1760 | } | ||
1761 | |||
1762 | } | ||
1763 | mydbg("%s -No ioctl for that one. port = %d\n", __func__, | ||
1764 | port->number); | ||
1765 | |||
1766 | return -ENOIOCTLCMD; | ||
1767 | } | ||
1768 | |||
1769 | static void serial_set_termios(struct tty_struct *tty, struct ktermios *old) | ||
1770 | { | ||
1771 | struct usb_serial_port *port = | ||
1772 | tty->driver_data; | ||
1773 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
1774 | |||
1775 | if (!serial) | ||
1776 | return; | ||
1777 | |||
1778 | down(&port->sem); | ||
1779 | |||
1780 | mydbg("%s - port %d\n", __func__, port->number); | ||
1781 | |||
1782 | if (!port->open_count) { | ||
1783 | mydbg("%s - port not open\n", __func__); | ||
1784 | goto exit; | ||
1785 | } | ||
1786 | |||
1787 | /* pass on to the driver specific version of this function if it is available */ | ||
1788 | qt_set_termios(tty, port, old); | ||
1789 | |||
1790 | exit: | ||
1791 | up(&port->sem); | ||
1792 | } | ||
1793 | |||
1794 | static void qt_set_termios(struct tty_struct *tty, | ||
1795 | struct usb_serial_port *port, | ||
1796 | struct ktermios *old_termios) | ||
1797 | { | ||
1798 | unsigned int cflag; | ||
1799 | int baud, divisor, remainder; | ||
1800 | unsigned char new_LCR = 0; | ||
1801 | int status; | ||
1802 | struct usb_serial *serial; | ||
1803 | __u16 index; | ||
1804 | __u16 tmp, tmp2; | ||
1805 | |||
1806 | mydbg("%s - port %d\n", __func__, port->number); | ||
1807 | |||
1808 | tmp = port->tty->index; | ||
1809 | mydbg("%s - MINOR(port->tty->index) = %d\n", __func__, tmp); | ||
1810 | |||
1811 | serial = port->serial; | ||
1812 | tmp2 = serial->minor; | ||
1813 | mydbg("%s - serial->minor = %d\n", __func__, tmp2); | ||
1814 | |||
1815 | index = port->tty->index - serial->minor; | ||
1816 | |||
1817 | cflag = tty->termios->c_cflag; | ||
1818 | |||
1819 | mydbg("%s - 3\n", __func__); | ||
1820 | |||
1821 | switch (cflag) { | ||
1822 | case CS5: | ||
1823 | new_LCR |= SERIAL_5_DATA; | ||
1824 | break; | ||
1825 | case CS6: | ||
1826 | new_LCR |= SERIAL_6_DATA; | ||
1827 | break; | ||
1828 | case CS7: | ||
1829 | new_LCR |= SERIAL_7_DATA; | ||
1830 | break; | ||
1831 | default: | ||
1832 | case CS8: | ||
1833 | new_LCR |= SERIAL_8_DATA; | ||
1834 | break; | ||
1835 | } | ||
1836 | |||
1837 | /* Parity stuff */ | ||
1838 | if (cflag & PARENB) { | ||
1839 | if (cflag & PARODD) | ||
1840 | new_LCR |= SERIAL_ODD_PARITY; | ||
1841 | else | ||
1842 | new_LCR |= SERIAL_EVEN_PARITY; | ||
1843 | } | ||
1844 | if (cflag & CSTOPB) | ||
1845 | new_LCR |= SERIAL_TWO_STOPB; | ||
1846 | else | ||
1847 | new_LCR |= SERIAL_TWO_STOPB; | ||
1848 | |||
1849 | mydbg("%s - 4\n", __func__); | ||
1850 | /* Thats the LCR stuff, go ahead and set it */ | ||
1851 | baud = tty_get_baud_rate(tty); | ||
1852 | if (!baud) | ||
1853 | /* pick a default, any default... */ | ||
1854 | baud = 9600; | ||
1855 | |||
1856 | mydbg("%s - got baud = %d\n", __func__, baud); | ||
1857 | |||
1858 | divisor = MAX_BAUD_RATE / baud; | ||
1859 | remainder = MAX_BAUD_RATE % baud; | ||
1860 | /* Round to nearest divisor */ | ||
1861 | if (((remainder * 2) >= baud) && (baud != 110)) | ||
1862 | divisor++; | ||
1863 | |||
1864 | /* | ||
1865 | * Set Baud rate to default and turn off (default)flow control here | ||
1866 | */ | ||
1867 | status = BoxSetUart(serial, index, (unsigned short)divisor, new_LCR); | ||
1868 | if (status < 0) { | ||
1869 | mydbg(__FILE__ "BoxSetUart failed\n"); | ||
1870 | return; | ||
1871 | } | ||
1872 | |||
1873 | /* Now determine flow control */ | ||
1874 | if (cflag & CRTSCTS) { | ||
1875 | mydbg("%s - Enabling HW flow control port %d\n", __func__, | ||
1876 | port->number); | ||
1877 | |||
1878 | /* Enable RTS/CTS flow control */ | ||
1879 | status = BoxSetHW_FlowCtrl(serial, index, 1); | ||
1880 | |||
1881 | if (status < 0) { | ||
1882 | mydbg(__FILE__ "BoxSetHW_FlowCtrl failed\n"); | ||
1883 | return; | ||
1884 | } | ||
1885 | } else { | ||
1886 | /* Disable RTS/CTS flow control */ | ||
1887 | mydbg("%s - disabling HW flow control port %d\n", __func__, | ||
1888 | port->number); | ||
1889 | |||
1890 | status = BoxSetHW_FlowCtrl(serial, index, 0); | ||
1891 | if (status < 0) { | ||
1892 | mydbg(__FILE__ "BoxSetHW_FlowCtrl failed\n"); | ||
1893 | return; | ||
1894 | } | ||
1895 | |||
1896 | } | ||
1897 | |||
1898 | /* if we are implementing XON/XOFF, set the start and stop character in | ||
1899 | * the device */ | ||
1900 | if (I_IXOFF(tty) || I_IXON(tty)) { | ||
1901 | unsigned char stop_char = STOP_CHAR(tty); | ||
1902 | unsigned char start_char = START_CHAR(tty); | ||
1903 | status = | ||
1904 | BoxSetSW_FlowCtrl(serial, index, stop_char, | ||
1905 | start_char); | ||
1906 | if (status < 0) | ||
1907 | mydbg(__FILE__ "BoxSetSW_FlowCtrl (enabled) failed\n"); | ||
1908 | |||
1909 | } else { | ||
1910 | /* disable SW flow control */ | ||
1911 | status = BoxDisable_SW_FlowCtrl(serial, index); | ||
1912 | if (status < 0) | ||
1913 | mydbg(__FILE__ "BoxSetSW_FlowCtrl (diabling) failed\n"); | ||
1914 | |||
1915 | } | ||
1916 | tty->termios->c_cflag &= ~CMSPAR; | ||
1917 | /* FIXME: Error cases should be returning the actual bits changed only */ | ||
1918 | } | ||
1919 | |||
1920 | /**************************************************************************** | ||
1921 | * BoxGetRegister | ||
1922 | * issuse a GET_REGISTER vendor-spcific request on the default control pipe | ||
1923 | * If successful, fills in the pValue with the register value asked for | ||
1924 | ****************************************************************************/ | ||
1925 | static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number, | ||
1926 | unsigned short Register_Num, __u8 *pValue) | ||
1927 | { | ||
1928 | int result; | ||
1929 | __u16 current_length; | ||
1930 | |||
1931 | current_length = sizeof(struct qt_get_device_data); | ||
1932 | |||
1933 | result = | ||
1934 | usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | ||
1935 | QT_GET_SET_REGISTER, 0xC0, Register_Num, | ||
1936 | Uart_Number, (void *)pValue, sizeof(*pValue), 300); | ||
1937 | |||
1938 | return result; | ||
1939 | } | ||
1940 | |||
1941 | /**************************************************************************** | ||
1942 | * BoxSetRegister | ||
1943 | * issuse a GET_REGISTER vendor-spcific request on the default control pipe | ||
1944 | * If successful, fills in the pValue with the register value asked for | ||
1945 | ****************************************************************************/ | ||
1946 | static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number, | ||
1947 | unsigned short Register_Num, unsigned short Value) | ||
1948 | { | ||
1949 | int result; | ||
1950 | unsigned short RegAndByte; | ||
1951 | |||
1952 | RegAndByte = Value; | ||
1953 | RegAndByte = RegAndByte << 8; | ||
1954 | RegAndByte = RegAndByte + Register_Num; | ||
1955 | |||
1956 | /* | ||
1957 | result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
1958 | QT_GET_SET_REGISTER, 0xC0, Register_Num, | ||
1959 | Uart_Number, NULL, 0, 300); | ||
1960 | */ | ||
1961 | |||
1962 | result = | ||
1963 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
1964 | QT_GET_SET_REGISTER, 0x40, RegAndByte, Uart_Number, | ||
1965 | NULL, 0, 300); | ||
1966 | |||
1967 | return result; | ||
1968 | } | ||
1969 | |||
1970 | /** | ||
1971 | * box_get_device | ||
1972 | * Issue a GET_DEVICE vendor-specific request on the default control pipe If | ||
1973 | * successful, fills in the qt_get_device_data structure pointed to by | ||
1974 | * device_data, otherwise return a negative error number of the problem. | ||
1975 | */ | ||
1976 | static int box_get_device(struct usb_serial *serial, | ||
1977 | struct qt_get_device_data *device_data) | ||
1978 | { | ||
1979 | int result; | ||
1980 | __u16 current_length; | ||
1981 | unsigned char *transfer_buffer; | ||
1982 | |||
1983 | current_length = sizeof(struct qt_get_device_data); | ||
1984 | transfer_buffer = kmalloc(current_length, GFP_KERNEL); | ||
1985 | if (!transfer_buffer) | ||
1986 | return -ENOMEM; | ||
1987 | |||
1988 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | ||
1989 | QT_SET_GET_DEVICE, 0xc0, 0, 0, | ||
1990 | transfer_buffer, current_length, 300); | ||
1991 | if (result > 0) | ||
1992 | memcpy(device_data, transfer_buffer, current_length); | ||
1993 | kfree(transfer_buffer); | ||
1994 | |||
1995 | return result; | ||
1996 | } | ||
1997 | |||
1998 | /** | ||
1999 | * box_set_device | ||
2000 | * Issue a SET_DEVICE vendor-specific request on the default control pipe If | ||
2001 | * successful returns the number of bytes written, otherwise it returns a | ||
2002 | * negative error number of the problem. | ||
2003 | */ | ||
2004 | static int box_set_device(struct usb_serial *serial, | ||
2005 | struct qt_get_device_data *device_data) | ||
2006 | { | ||
2007 | int result; | ||
2008 | __u16 length; | ||
2009 | __u16 PortSettings; | ||
2010 | |||
2011 | PortSettings = ((__u16) (device_data->portb)); | ||
2012 | PortSettings = (PortSettings << 8); | ||
2013 | PortSettings += ((__u16) (device_data->porta)); | ||
2014 | |||
2015 | length = sizeof(struct qt_get_device_data); | ||
2016 | mydbg("%s - PortSettings = 0x%x\n", __func__, PortSettings); | ||
2017 | |||
2018 | result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2019 | QT_SET_GET_DEVICE, 0x40, PortSettings, | ||
2020 | 0, NULL, 0, 300); | ||
2021 | return result; | ||
2022 | } | ||
2023 | |||
2024 | /**************************************************************************** | ||
2025 | * BoxOPenCloseChannel | ||
2026 | * This funciotn notifies the device that the device driver wishes to open a particular UART channel. its | ||
2027 | * purpose is to allow the device driver and the device to synchronize state information. | ||
2028 | * OpenClose = 1 for open , 0 for close | ||
2029 | ****************************************************************************/ | ||
2030 | static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, | ||
2031 | __u16 OpenClose, | ||
2032 | struct qt_open_channel_data *pDeviceData) | ||
2033 | { | ||
2034 | int result; | ||
2035 | __u16 length; | ||
2036 | __u8 Direcion; | ||
2037 | unsigned int pipe; | ||
2038 | length = sizeof(struct qt_open_channel_data); | ||
2039 | |||
2040 | /* if opening... */ | ||
2041 | if (OpenClose == 1) { | ||
2042 | Direcion = USBD_TRANSFER_DIRECTION_IN; | ||
2043 | pipe = usb_rcvctrlpipe(serial->dev, 0); | ||
2044 | result = | ||
2045 | usb_control_msg(serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL, | ||
2046 | Direcion, OpenClose, Uart_Number, | ||
2047 | pDeviceData, length, 300); | ||
2048 | |||
2049 | } else { | ||
2050 | Direcion = USBD_TRANSFER_DIRECTION_OUT; | ||
2051 | pipe = usb_sndctrlpipe(serial->dev, 0); | ||
2052 | result = | ||
2053 | usb_control_msg(serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL, | ||
2054 | Direcion, OpenClose, Uart_Number, NULL, 0, | ||
2055 | 300); | ||
2056 | |||
2057 | } | ||
2058 | |||
2059 | return result; | ||
2060 | } | ||
2061 | |||
2062 | /**************************************************************************** | ||
2063 | * BoxSetPrebufferLevel | ||
2064 | TELLS BOX WHEN TO ASSERT FLOW CONTROL | ||
2065 | ****************************************************************************/ | ||
2066 | static int BoxSetPrebufferLevel(struct usb_serial *serial) | ||
2067 | { | ||
2068 | int result; | ||
2069 | __u16 buffer_length; | ||
2070 | |||
2071 | buffer_length = PREFUFF_LEVEL_CONSERVATIVE; | ||
2072 | result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2073 | QT_GET_SET_PREBUF_TRIG_LVL, 0x40, | ||
2074 | buffer_length, 0, NULL, 0, 300); | ||
2075 | return result; | ||
2076 | } | ||
2077 | |||
2078 | /**************************************************************************** | ||
2079 | * BoxSetATC | ||
2080 | TELLS BOX WHEN TO ASSERT automatic transmitter control | ||
2081 | ****************************************************************************/ | ||
2082 | static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode) | ||
2083 | { | ||
2084 | int result; | ||
2085 | __u16 buffer_length; | ||
2086 | |||
2087 | buffer_length = PREFUFF_LEVEL_CONSERVATIVE; | ||
2088 | |||
2089 | result = | ||
2090 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2091 | QT_SET_ATF, 0x40, n_Mode, 0, NULL, 0, 300); | ||
2092 | |||
2093 | return result; | ||
2094 | } | ||
2095 | |||
2096 | /**************************************************************************** | ||
2097 | * BoxSetUart | ||
2098 | * issuse a SET_UART vendor-spcific request on the default control pipe | ||
2099 | * If successful sets baud rate divisor and LCR value | ||
2100 | ****************************************************************************/ | ||
2101 | static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number, | ||
2102 | unsigned short default_divisor, unsigned char default_LCR) | ||
2103 | { | ||
2104 | int result; | ||
2105 | unsigned short UartNumandLCR; | ||
2106 | |||
2107 | UartNumandLCR = (default_LCR << 8) + Uart_Number; | ||
2108 | |||
2109 | result = | ||
2110 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2111 | QT_GET_SET_UART, 0x40, default_divisor, | ||
2112 | UartNumandLCR, NULL, 0, 300); | ||
2113 | |||
2114 | return result; | ||
2115 | } | ||
2116 | |||
2117 | static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int index, | ||
2118 | int bSet) | ||
2119 | { | ||
2120 | __u8 mcr = 0; | ||
2121 | __u8 msr = 0, MOUT_Value = 0; | ||
2122 | struct usb_serial_port *port; | ||
2123 | unsigned int status; | ||
2124 | |||
2125 | port = serial->port; | ||
2126 | |||
2127 | if (bSet == 1) { | ||
2128 | /* flow control, box will clear RTS line to prevent remote */ | ||
2129 | mcr = SERIAL_MCR_RTS; | ||
2130 | } /* device from xmitting more chars */ | ||
2131 | else { | ||
2132 | /* no flow control to remote device */ | ||
2133 | mcr = 0; | ||
2134 | |||
2135 | } | ||
2136 | MOUT_Value = mcr << 8; | ||
2137 | |||
2138 | if (bSet == 1) { | ||
2139 | /* flow control, box will inhibit xmit data if CTS line is | ||
2140 | * asserted */ | ||
2141 | msr = SERIAL_MSR_CTS; | ||
2142 | } else { | ||
2143 | /* Box will not inhimbe xmit data due to CTS line */ | ||
2144 | msr = 0; | ||
2145 | } | ||
2146 | MOUT_Value |= msr; | ||
2147 | |||
2148 | status = | ||
2149 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2150 | QT_HW_FLOW_CONTROL_MASK, 0x40, MOUT_Value, | ||
2151 | index, NULL, 0, 300); | ||
2152 | return status; | ||
2153 | |||
2154 | } | ||
2155 | |||
2156 | static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 index, | ||
2157 | unsigned char stop_char, unsigned char start_char) | ||
2158 | { | ||
2159 | __u16 nSWflowout; | ||
2160 | int result; | ||
2161 | |||
2162 | nSWflowout = start_char << 8; | ||
2163 | nSWflowout = (unsigned short)stop_char; | ||
2164 | |||
2165 | result = | ||
2166 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2167 | QT_SW_FLOW_CONTROL_MASK, 0x40, nSWflowout, | ||
2168 | index, NULL, 0, 300); | ||
2169 | return result; | ||
2170 | |||
2171 | } | ||
2172 | static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 index) | ||
2173 | { | ||
2174 | int result; | ||
2175 | |||
2176 | result = | ||
2177 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2178 | QT_SW_FLOW_CONTROL_DISABLE, 0x40, 0, index, | ||
2179 | NULL, 0, 300); | ||
2180 | return result; | ||
2181 | |||
2182 | } | ||
2183 | |||
2184 | static void serial_throttle(struct tty_struct *tty) | ||
2185 | { | ||
2186 | struct usb_serial_port *port = | ||
2187 | tty->driver_data; | ||
2188 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
2189 | mydbg("%s - port %d\n", __func__, port->number); | ||
2190 | |||
2191 | if (!serial) | ||
2192 | return; | ||
2193 | |||
2194 | down(&port->sem); | ||
2195 | |||
2196 | if (!port->open_count) { | ||
2197 | mydbg("%s - port not open\n", __func__); | ||
2198 | goto exit; | ||
2199 | } | ||
2200 | /* shut down any bulk reads that may be going on */ | ||
2201 | /* usb_unlink_urb (port->read_urb); */ | ||
2202 | /* pass on to the driver specific version of this function */ | ||
2203 | port->RxHolding = 1; | ||
2204 | mydbg("%s - port->RxHolding = 1\n", __func__); | ||
2205 | |||
2206 | exit: | ||
2207 | up(&port->sem); | ||
2208 | return; | ||
2209 | } | ||
2210 | |||
2211 | static void serial_unthrottle(struct tty_struct *tty) | ||
2212 | { | ||
2213 | struct usb_serial_port *port = | ||
2214 | tty->driver_data; | ||
2215 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
2216 | unsigned int result; | ||
2217 | |||
2218 | if (!serial) | ||
2219 | return; | ||
2220 | down(&port->sem); | ||
2221 | |||
2222 | mydbg("%s - port %d\n", __func__, port->number); | ||
2223 | |||
2224 | if (!port->open_count) { | ||
2225 | mydbg("%s - port not open\n", __func__); | ||
2226 | goto exit; | ||
2227 | } | ||
2228 | |||
2229 | if (port->RxHolding == 1) { | ||
2230 | mydbg("%s -port->RxHolding == 1\n", __func__); | ||
2231 | |||
2232 | port->RxHolding = 0; | ||
2233 | mydbg("%s - port->RxHolding = 0\n", __func__); | ||
2234 | |||
2235 | /* if we have a bulk endpoint, start it up */ | ||
2236 | if ((serial->num_bulk_in) && (port->ReadBulkStopped == 1)) { | ||
2237 | /* Start reading from the device */ | ||
2238 | usb_fill_bulk_urb(port->read_urb, serial->dev, | ||
2239 | usb_rcvbulkpipe(serial->dev, | ||
2240 | port-> | ||
2241 | bulk_in_endpointAddress), | ||
2242 | port->read_urb->transfer_buffer, | ||
2243 | port->read_urb-> | ||
2244 | transfer_buffer_length, | ||
2245 | qt_read_bulk_callback, port); | ||
2246 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | ||
2247 | if (result) | ||
2248 | err("%s - failed restarting read urb, error %d", | ||
2249 | __func__, result); | ||
2250 | } | ||
2251 | } | ||
2252 | exit: | ||
2253 | up(&port->sem); | ||
2254 | return; | ||
2255 | |||
2256 | } | ||
2257 | |||
2258 | static int serial_break(struct tty_struct *tty, int break_state) | ||
2259 | { | ||
2260 | struct usb_serial_port *port = tty->driver_data; | ||
2261 | struct usb_serial *serial = get_usb_serial(port, __func__); | ||
2262 | u16 index, onoff; | ||
2263 | unsigned int result; | ||
2264 | |||
2265 | index = tty->index - serial->minor; | ||
2266 | if (!serial) | ||
2267 | return -ENODEV; | ||
2268 | |||
2269 | if (break_state == -1) | ||
2270 | onoff = 1; | ||
2271 | else | ||
2272 | onoff = 0; | ||
2273 | |||
2274 | down(&port->sem); | ||
2275 | |||
2276 | mydbg("%s - port %d\n", __func__, port->number); | ||
2277 | |||
2278 | if (!port->open_count) { | ||
2279 | mydbg("%s - port not open\n", __func__); | ||
2280 | goto exit; | ||
2281 | } | ||
2282 | |||
2283 | result = | ||
2284 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2285 | QT_BREAK_CONTROL, 0x40, onoff, index, | ||
2286 | NULL, 0, 300); | ||
2287 | |||
2288 | exit: | ||
2289 | up(&port->sem); | ||
2290 | return 0; | ||
2291 | } | ||
2292 | |||
2293 | static int ioctl_serial_usb(struct inode *innod, struct file *filp, unsigned int cmd, | ||
2294 | unsigned long arg) | ||
2295 | { | ||
2296 | |||
2297 | unsigned err; | ||
2298 | unsigned ucOPR_NewValue, uc_Value; | ||
2299 | int *p_Num_of_adapters, counts, index, *p_QMCR_Value; | ||
2300 | struct identity *p_Identity_of; | ||
2301 | struct identity Identity_of; | ||
2302 | struct usb_serial *lastserial, *serial; | ||
2303 | |||
2304 | mydbg(KERN_DEBUG "ioctl_serial_usb cmd =\n"); | ||
2305 | if (_IOC_TYPE(cmd) != SERIALQT_PCI_IOC_MAGIC) | ||
2306 | return -ENOTTY; | ||
2307 | if (_IOC_NR(cmd) > SERIALQT_IOC_MAXNR) | ||
2308 | return -ENOTTY; | ||
2309 | mydbg(KERN_DEBUG "ioctl_serial_usb cmd = 0x%x\n", cmd); | ||
2310 | err = 0; | ||
2311 | switch (cmd) { | ||
2312 | |||
2313 | case SERIALQT_WRITE_QMCR: | ||
2314 | err = -ENOTTY; | ||
2315 | index = arg >> 16; | ||
2316 | counts = 0; | ||
2317 | |||
2318 | ucOPR_NewValue = arg; | ||
2319 | |||
2320 | err = EmulateWriteQMCR_Reg(index, ucOPR_NewValue); | ||
2321 | break; | ||
2322 | |||
2323 | case SERIALQT_READ_QMCR: | ||
2324 | err = -ENOTTY; | ||
2325 | p_QMCR_Value = (int *)arg; | ||
2326 | index = arg >> 16; | ||
2327 | counts = 0; | ||
2328 | |||
2329 | err = EmulateReadQMCR_Reg(index, &uc_Value); | ||
2330 | if (err == 0) | ||
2331 | err = put_user(uc_Value, p_QMCR_Value); | ||
2332 | break; | ||
2333 | |||
2334 | case SERIALQT_GET_NUMOF_UNITS: | ||
2335 | p_Num_of_adapters = (int *)arg; | ||
2336 | counts = 0; /* Initialize counts to zero */ | ||
2337 | /* struct usb_serial *lastserial = serial_table[0], *serial; */ | ||
2338 | lastserial = serial_table[0]; | ||
2339 | |||
2340 | mydbg(KERN_DEBUG "SERIALQT_GET_NUMOF_UNITS \n"); | ||
2341 | /* if first pointer is nonull, we at least have one box */ | ||
2342 | if (lastserial) | ||
2343 | counts = 1; /* we at least have one box */ | ||
2344 | |||
2345 | for (index = 1; index < SERIAL_TTY_MINORS; index++) { | ||
2346 | serial = serial_table[index]; | ||
2347 | if (serial) { | ||
2348 | if (serial != lastserial) { | ||
2349 | /* we had a change in the array, hence | ||
2350 | * another box is there */ | ||
2351 | lastserial = serial; | ||
2352 | counts++; | ||
2353 | } | ||
2354 | } else | ||
2355 | break; | ||
2356 | } | ||
2357 | |||
2358 | mydbg(KERN_DEBUG "ioctl_serial_usb writting counts = %d", | ||
2359 | counts); | ||
2360 | |||
2361 | err = put_user(counts, p_Num_of_adapters); | ||
2362 | |||
2363 | break; | ||
2364 | case SERIALQT_GET_THIS_UNIT: | ||
2365 | counts = 0; | ||
2366 | p_Identity_of = (struct identity *)arg; | ||
2367 | /* copy user structure to local variable */ | ||
2368 | get_user(Identity_of.index, &p_Identity_of->index); | ||
2369 | mydbg(KERN_DEBUG "SERIALQT_GET_THIS_UNIT Identity_of.index\n"); | ||
2370 | mydbg(KERN_DEBUG | ||
2371 | "SERIALQT_GET_THIS_UNIT Identity_of.index= 0x%x\n", | ||
2372 | Identity_of.index); | ||
2373 | |||
2374 | err = -ENOTTY; | ||
2375 | serial = find_the_box(Identity_of.index); | ||
2376 | if (serial) { | ||
2377 | err = | ||
2378 | put_user(serial->product, | ||
2379 | &p_Identity_of->n_identity); | ||
2380 | |||
2381 | } | ||
2382 | break; | ||
2383 | |||
2384 | case SERIALQT_IS422_EXTENDED: | ||
2385 | err = -ENOTTY; | ||
2386 | mydbg(KERN_DEBUG "SERIALQT_IS422_EXTENDED \n"); | ||
2387 | index = arg >> 16; | ||
2388 | |||
2389 | counts = 0; | ||
2390 | |||
2391 | mydbg(KERN_DEBUG | ||
2392 | "SERIALQT_IS422_EXTENDED, looking Identity_of.indext = 0x%x\n", | ||
2393 | index); | ||
2394 | serial = find_the_box(index); | ||
2395 | if (serial) { | ||
2396 | mydbg("%s index = 0x%x, serial = 0x%p\n", __func__, | ||
2397 | index, serial); | ||
2398 | for (counts = 0; serqt_422_table[counts] != 0; counts++) { | ||
2399 | |||
2400 | mydbg | ||
2401 | ("%s serial->product = = 0x%x, serqt_422_table[counts] = 0x%x\n", | ||
2402 | __func__, serial->product, | ||
2403 | serqt_422_table[counts]); | ||
2404 | if (serial->product == serqt_422_table[counts]) { | ||
2405 | err = 0; | ||
2406 | |||
2407 | mydbg | ||
2408 | ("%s found match for 422extended\n", | ||
2409 | __func__); | ||
2410 | break; | ||
2411 | } | ||
2412 | } | ||
2413 | } | ||
2414 | break; | ||
2415 | |||
2416 | default: | ||
2417 | err = -ENOTTY; | ||
2418 | } | ||
2419 | |||
2420 | mydbg("%s returning err = 0x%x\n", __func__, err); | ||
2421 | return err; | ||
2422 | } | ||
2423 | |||
2424 | static struct usb_serial *find_the_box(unsigned int index) | ||
2425 | { | ||
2426 | struct usb_serial *lastserial, *foundserial, *serial; | ||
2427 | int counts = 0, index2; | ||
2428 | lastserial = serial_table[0]; | ||
2429 | foundserial = NULL; | ||
2430 | for (index2 = 0; index2 < SERIAL_TTY_MINORS; index2++) { | ||
2431 | serial = serial_table[index2]; | ||
2432 | |||
2433 | mydbg("%s index = 0x%x, index2 = 0x%x, serial = 0x%p\n", | ||
2434 | __func__, index, index2, serial); | ||
2435 | |||
2436 | if (serial) { | ||
2437 | /* first see if this is the unit we'er looking for */ | ||
2438 | mydbg | ||
2439 | ("%s inside if(serial) counts = 0x%x , index = 0x%x\n", | ||
2440 | __func__, counts, index); | ||
2441 | if (counts == index) { | ||
2442 | /* we found the one we're looking for, copythe | ||
2443 | * product Id to user */ | ||
2444 | mydbg("%s we found the one we're looking for serial = 0x%p\n", | ||
2445 | __func__, serial); | ||
2446 | foundserial = serial; | ||
2447 | break; | ||
2448 | } | ||
2449 | |||
2450 | if (serial != lastserial) { | ||
2451 | /* when we have a change in the pointer */ | ||
2452 | lastserial = serial; | ||
2453 | counts++; | ||
2454 | } | ||
2455 | } else | ||
2456 | break; /* no matches */ | ||
2457 | } | ||
2458 | |||
2459 | mydbg("%s returning foundserial = 0x%p\n", __func__, foundserial); | ||
2460 | return foundserial; | ||
2461 | } | ||
2462 | |||
2463 | static int EmulateWriteQMCR_Reg(int index, unsigned uc_value) | ||
2464 | { | ||
2465 | |||
2466 | __u16 ATC_Mode = 0; | ||
2467 | struct usb_serial *serial; | ||
2468 | int status; | ||
2469 | struct qt_get_device_data DeviceData; | ||
2470 | unsigned uc_temp = 0; | ||
2471 | mydbg("Inside %s, uc_value = 0x%x\n", __func__, uc_value); | ||
2472 | |||
2473 | DeviceData.porta = 0; | ||
2474 | DeviceData.portb = 0; | ||
2475 | serial = find_the_box(index); | ||
2476 | /* Determine Duplex mode */ | ||
2477 | if (!(serial)) | ||
2478 | return -ENOTTY; | ||
2479 | status = box_get_device(serial, &DeviceData); | ||
2480 | if (status < 0) { | ||
2481 | mydbg(__FILE__ "box_set_device failed\n"); | ||
2482 | return status; | ||
2483 | } | ||
2484 | |||
2485 | uc_temp = uc_value & QMCR_HALF_DUPLEX_MASK; | ||
2486 | switch (uc_temp) { | ||
2487 | case QMCR_FULL_DUPLEX: | ||
2488 | DeviceData.porta &= ~DUPMODE_BITS; | ||
2489 | DeviceData.porta |= FULL_DUPLEX; | ||
2490 | ATC_Mode = ATC_DISABLED; | ||
2491 | break; | ||
2492 | case QMCR_HALF_DUPLEX_RTS: | ||
2493 | DeviceData.porta &= ~DUPMODE_BITS; | ||
2494 | DeviceData.porta |= HALF_DUPLEX_RTS; | ||
2495 | ATC_Mode = ATC_RTS_ENABLED; | ||
2496 | break; | ||
2497 | case QMCR_HALF_DUPLEX_DTR: | ||
2498 | DeviceData.porta &= ~DUPMODE_BITS; | ||
2499 | DeviceData.porta |= HALF_DUPLEX_DTR; | ||
2500 | ATC_Mode = ATC_DTR_ENABLED; | ||
2501 | break; | ||
2502 | default: | ||
2503 | break; | ||
2504 | } | ||
2505 | |||
2506 | uc_temp = uc_value & QMCR_CONNECTOR_MASK; | ||
2507 | switch (uc_temp) { | ||
2508 | case QMCR_MODEM_CONTROL: | ||
2509 | DeviceData.portb &= ~LOOPMODE_BITS; /* reset connection bits */ | ||
2510 | DeviceData.portb |= MODEM_CTRL; | ||
2511 | break; | ||
2512 | case QMCR_ALL_LOOPBACK: | ||
2513 | DeviceData.portb &= ~LOOPMODE_BITS; /* reset connection bits */ | ||
2514 | DeviceData.portb |= ALL_LOOPBACK; | ||
2515 | break; | ||
2516 | } | ||
2517 | |||
2518 | mydbg(__FILE__ "Calling box_set_device with failed\n"); | ||
2519 | status = box_set_device(serial, &DeviceData); | ||
2520 | if (status < 0) { | ||
2521 | mydbg(__FILE__ "box_set_device failed\n"); | ||
2522 | return status; | ||
2523 | } | ||
2524 | |||
2525 | /* This bit (otherwise unused) i'll used to detect whether ATC is | ||
2526 | * selected */ | ||
2527 | if (uc_value & QMCR_RX_EN_MASK) { | ||
2528 | |||
2529 | mydbg(__FILE__ | ||
2530 | "calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n", | ||
2531 | DeviceData.porta, DeviceData.portb); | ||
2532 | status = BoxSetATC(serial, ATC_Mode); | ||
2533 | if (status < 0) { | ||
2534 | mydbg(__FILE__ "BoxSetATC failed\n"); | ||
2535 | return status; | ||
2536 | } | ||
2537 | } else { | ||
2538 | |||
2539 | mydbg(__FILE__ | ||
2540 | "calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n", | ||
2541 | DeviceData.porta, DeviceData.portb); | ||
2542 | status = BoxSetATC(serial, ATC_DISABLED); | ||
2543 | if (status < 0) { | ||
2544 | mydbg(__FILE__ "BoxSetATC failed\n"); | ||
2545 | return status; | ||
2546 | } | ||
2547 | } | ||
2548 | |||
2549 | return 0; | ||
2550 | |||
2551 | } | ||
2552 | |||
2553 | static int EmulateReadQMCR_Reg(int index, unsigned *uc_value) | ||
2554 | { | ||
2555 | struct usb_serial *serial; | ||
2556 | int status; | ||
2557 | struct qt_get_device_data DeviceData; | ||
2558 | __u8 uc_temp; | ||
2559 | |||
2560 | *uc_value = 0; | ||
2561 | |||
2562 | serial = find_the_box(index); | ||
2563 | if (!(serial)) | ||
2564 | return -ENOTTY; | ||
2565 | |||
2566 | status = box_get_device(serial, &DeviceData); | ||
2567 | if (status < 0) { | ||
2568 | mydbg(__FILE__ "box_get_device failed\n"); | ||
2569 | return status; | ||
2570 | } | ||
2571 | uc_temp = DeviceData.porta & DUPMODE_BITS; | ||
2572 | switch (uc_temp) { | ||
2573 | case FULL_DUPLEX: | ||
2574 | *uc_value |= QMCR_FULL_DUPLEX; | ||
2575 | break; | ||
2576 | case HALF_DUPLEX_RTS: | ||
2577 | *uc_value |= QMCR_HALF_DUPLEX_RTS; | ||
2578 | break; | ||
2579 | case HALF_DUPLEX_DTR: | ||
2580 | *uc_value |= QMCR_HALF_DUPLEX_DTR; | ||
2581 | break; | ||
2582 | default: | ||
2583 | break; | ||
2584 | } | ||
2585 | |||
2586 | /* I use this for ATC control se */ | ||
2587 | uc_temp = DeviceData.portb & LOOPMODE_BITS; | ||
2588 | |||
2589 | switch (uc_temp) { | ||
2590 | case ALL_LOOPBACK: | ||
2591 | *uc_value |= QMCR_ALL_LOOPBACK; | ||
2592 | break; | ||
2593 | case MODEM_CTRL: | ||
2594 | *uc_value |= QMCR_MODEM_CONTROL; | ||
2595 | break; | ||
2596 | default: | ||
2597 | break; | ||
2598 | |||
2599 | } | ||
2600 | return 0; | ||
2601 | |||
2602 | } | ||
2603 | |||
2604 | static int __init serqt_usb_init(void) | ||
2605 | { | ||
2606 | int i, result; | ||
2607 | int status = 0; | ||
2608 | |||
2609 | mydbg("%s\n", __func__); | ||
2610 | tty_set_operations(&serial_tty_driver, &serial_ops); | ||
2611 | result = tty_register_driver(&serial_tty_driver); | ||
2612 | if (result) { | ||
2613 | mydbg("tty_register_driver failed error = 0x%x", result); | ||
2614 | return result; | ||
2615 | } | ||
2616 | |||
2617 | /* Initalize our global data */ | ||
2618 | for (i = 0; i < SERIAL_TTY_MINORS; ++i) | ||
2619 | serial_table[i] = NULL; | ||
2620 | |||
2621 | /* register this driver with the USB subsystem */ | ||
2622 | result = usb_register(&serqt_usb_driver); | ||
2623 | if (result < 0) { | ||
2624 | err("usb_register failed for the " __FILE__ | ||
2625 | " driver. Error number %d", result); | ||
2626 | return result; | ||
2627 | } | ||
2628 | status = 0; /* Dynamic assignment of major number */ | ||
2629 | major_number = | ||
2630 | register_chrdev(status, "SerialQT_USB", &serialqt_usb_fops); | ||
2631 | if (major_number < 0) { | ||
2632 | mydbg(KERN_DEBUG "No devices found \n\n"); | ||
2633 | return -EBUSY; | ||
2634 | } else | ||
2635 | mydbg(KERN_DEBUG "SerQT_USB major number assignment = %d \n\n", | ||
2636 | major_number); | ||
2637 | |||
2638 | printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION); | ||
2639 | return 0; | ||
2640 | } | ||
2641 | |||
2642 | static void __exit serqt_usb_exit(void) | ||
2643 | { | ||
2644 | /* deregister this driver with the USB subsystem */ | ||
2645 | usb_deregister(&serqt_usb_driver); | ||
2646 | tty_unregister_driver(&serial_tty_driver); | ||
2647 | unregister_chrdev(major_number, "SerialQT_USB"); | ||
2648 | } | ||
2649 | |||
2650 | module_init(serqt_usb_init); | ||
2651 | module_exit(serqt_usb_exit); | ||
2652 | |||
2653 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
2654 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
2655 | MODULE_LICENSE("GPL"); | ||